clif.c 319 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LI3CENCE in the main folder
  3. #define DUMP_UNKNOWN_PACKET 0
  4. #define DUMP_ALL_PACKETS 0
  5. #include "../common/cbasetypes.h"
  6. #include "../common/socket.h"
  7. #include "../common/timer.h"
  8. #include "../common/malloc.h"
  9. #include "../common/version.h"
  10. #include "../common/nullpo.h"
  11. #include "../common/showmsg.h"
  12. #include "../common/strlib.h"
  13. #include "map.h"
  14. #include "chrif.h"
  15. #include "pc.h"
  16. #include "status.h"
  17. #include "npc.h"
  18. #include "itemdb.h"
  19. #include "chat.h"
  20. #include "trade.h"
  21. #include "storage.h"
  22. #include "script.h"
  23. #include "skill.h"
  24. #include "atcommand.h"
  25. #include "charcommand.h"
  26. #include "intif.h"
  27. #include "battle.h"
  28. #include "mob.h"
  29. #include "party.h"
  30. #include "unit.h"
  31. #include "guild.h"
  32. #include "vending.h"
  33. #include "pet.h"
  34. #include "mercenary.h" //[orn]
  35. #include "log.h"
  36. #include "irc.h"
  37. #include "clif.h"
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include <stdarg.h>
  42. #include <time.h>
  43. struct Clif_Config {
  44. int packet_db_ver; //Preferred packet version.
  45. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  46. } clif_config;
  47. struct packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
  48. //Converts item type in case of pet eggs.
  49. #define itemtype(a) (a == IT_PETEGG)?IT_WEAPON:a
  50. #define WBUFPOS(p,pos,x,y,dir) \
  51. do { \
  52. uint8 *__p = (p); \
  53. __p+=(pos); \
  54. __p[0] = (uint8)((x)>>2); \
  55. __p[1] = (uint8)(((x)<<6) | (((y)>>4)&0x3f)); \
  56. __p[2] = (uint8)(((y)<<4) | ((dir)&0xf)); \
  57. } while(0)
  58. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  59. #define WBUFPOS2(p,pos,x0,y0,x1,y1,sx0,sy0) \
  60. do { \
  61. uint8 *__p = (p); \
  62. __p+=(pos); \
  63. __p[0]=(uint8)((x0)>>2); \
  64. __p[1]=(uint8)(((x0)<<6) | (((y0)>>4)&0x3f)); \
  65. __p[2]=(uint8)(((y0)<<4) | (((x1)>>6)&0x0f)); \
  66. __p[3]=(uint8)(((x1)<<2) | (((y1)>>8)&0x03)); \
  67. __p[4]=(uint8)(y1); \
  68. __p[5]=(uint8)(((sx0)<<4) | ((sy0)&0x0f)); \
  69. } while(0)
  70. #define WFIFOPOS(fd,pos,x,y,dir) WBUFPOS(WFIFOP(fd,pos),0,x,y,dir)
  71. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1,sx0,sy0) WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1,sx0,sy0)
  72. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  73. #define clif_setlevel(lv) (lv<battle_config.max_lv?lv:battle_config.max_lv-(lv<battle_config.aura_lv?1:0));
  74. //Removed sd->npc_shopid because there is no packet sent from the client when you cancel a buy!
  75. //Quick check to know if the player shouldn't be "busy" with something else to deny action requests. [Skotlex]
  76. #define clif_cant_act(sd) (sd->npc_id || sd->vender_id || sd->chatID || sd->sc.opt1 || sd->state.trading || sd->state.storage_flag)
  77. // Checks if SD is in a trade/shop (where messing with the inventory can cause problems/exploits)
  78. #define clif_trading(sd) (sd->npc_id || sd->vender_id || sd->state.trading )
  79. //To idenfity disguised characters.
  80. #define disguised(bl) (bl->type==BL_PC && ((TBL_PC*)bl)->disguise)
  81. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex\]
  82. #define mes_len_check(mes, len, max) if (len > max) { mes[max-1] = '\0'; len = max; } else mes[len-1] = '\0';
  83. static char map_ip_str[128];
  84. static uint32 map_ip;
  85. static uint32 bind_ip = INADDR_ANY;
  86. static uint16 map_port = 5121;
  87. int map_fd;
  88. //These two will be used to verify the incoming player's validity.
  89. //It helps identify their client packet version correctly. [Skotlex]
  90. static int max_account_id = DEFAULT_MAX_ACCOUNT_ID;
  91. static int max_char_id = DEFAULT_MAX_CHAR_ID;
  92. int clif_parse (int fd);
  93. static void clif_hpmeter_single(int fd, struct map_session_data *sd);
  94. /*==========================================
  95. * map鯖のip設定
  96. *------------------------------------------*/
  97. int clif_setip(const char* ip)
  98. {
  99. char ip_str[16];
  100. map_ip = host2ip(ip);
  101. if (!map_ip) {
  102. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  103. return 0;
  104. }
  105. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  106. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  107. return 1;
  108. }
  109. void clif_setbindip(const char* ip)
  110. {
  111. char ip_str[16];
  112. bind_ip = host2ip(ip);
  113. if (bind_ip) {
  114. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  115. } else {
  116. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  117. }
  118. }
  119. /*==========================================
  120. * map鯖のport設定
  121. *------------------------------------------*/
  122. void clif_setport(uint16 port)
  123. {
  124. map_port = port;
  125. }
  126. /*==========================================
  127. * map鯖のip読み出し
  128. *------------------------------------------*/
  129. uint32 clif_getip(void)
  130. {
  131. return map_ip;
  132. }
  133. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  134. uint32 clif_refresh_ip(void)
  135. {
  136. uint32 new_ip;
  137. new_ip = host2ip(map_ip_str);
  138. if (new_ip && new_ip != map_ip) {
  139. map_ip = new_ip;
  140. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  141. return map_ip;
  142. }
  143. return 0;
  144. }
  145. /*==========================================
  146. * map鯖のport読み出し
  147. *------------------------------------------*/
  148. uint16 clif_getport(void)
  149. {
  150. return map_port;
  151. }
  152. /*==========================================
  153. * Counts connected players.
  154. *------------------------------------------*/
  155. int clif_countusers(void)
  156. {
  157. int users = 0, i;
  158. struct map_session_data *sd;
  159. for(i = 0; i < fd_max; i++) {
  160. if (session[i] && session[i]->func_parse == clif_parse &&
  161. (sd = (struct map_session_data*)session[i]->session_data) &&
  162. sd->state.auth && !(battle_config.hide_GM_session && pc_isGM(sd)))
  163. users++;
  164. }
  165. return users;
  166. }
  167. /*==========================================
  168. * 全てのclientに対してfunc()実行
  169. *------------------------------------------*/
  170. int clif_foreachclient(int (*func)(struct map_session_data*, va_list),...) //recoded by sasuke, bug when player count gets higher [Kevin]
  171. {
  172. int i;
  173. va_list ap;
  174. struct map_session_data *sd;
  175. va_start(ap,func);
  176. for(i = 0; i < fd_max; i++) {
  177. if ( session[i] && session[i]->func_parse == clif_parse) {
  178. sd = (struct map_session_data*)session[i]->session_data;
  179. if ( sd && sd->state.auth && !sd->state.waitingdisconnect )
  180. func(sd, ap);
  181. }
  182. }
  183. va_end(ap);
  184. return 0;
  185. }
  186. /*==========================================
  187. * clif_sendでAREA*指定時用
  188. *------------------------------------------*/
  189. int clif_send_sub(struct block_list *bl, va_list ap)
  190. {
  191. struct block_list *src_bl;
  192. struct map_session_data *sd;
  193. unsigned char *buf;
  194. int len, type, fd;
  195. nullpo_retr(0, bl);
  196. nullpo_retr(0, ap);
  197. nullpo_retr(0, sd = (struct map_session_data *)bl);
  198. fd = sd->fd;
  199. if (!fd) //Don't send to disconnected clients.
  200. return 0;
  201. buf = va_arg(ap,unsigned char*);
  202. len = va_arg(ap,int);
  203. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  204. type = va_arg(ap,int);
  205. switch(type)
  206. {
  207. case AREA_WOS:
  208. if (bl == src_bl)
  209. return 0;
  210. break;
  211. case AREA_WOC:
  212. if (sd->chatID || bl == src_bl)
  213. return 0;
  214. break;
  215. case AREA_WOSC:
  216. {
  217. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  218. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  219. return 0;
  220. }
  221. break;
  222. }
  223. if (session[fd] != NULL) {
  224. WFIFOHEAD(fd, len);
  225. if (WFIFOP(fd,0) == buf) {
  226. printf("WARNING: Invalid use of clif_send function\n");
  227. printf(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  228. printf(" Please correct your code.\n");
  229. // don't send to not move the pointer of the packet for next sessions in the loop
  230. WFIFOSET(fd,0);//## TODO is this ok?
  231. } else {
  232. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  233. memcpy(WFIFOP(fd,0), buf, len);
  234. WFIFOSET(fd,len);
  235. }
  236. }
  237. }
  238. return 0;
  239. }
  240. /*==========================================
  241. *
  242. *------------------------------------------*/
  243. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  244. {
  245. int i;
  246. struct map_session_data *sd = NULL;
  247. struct party_data *p = NULL;
  248. struct guild *g = NULL;
  249. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  250. if (type != ALL_CLIENT &&
  251. type != CHAT_MAINCHAT) {
  252. nullpo_retr(0, bl);
  253. if (bl->type == BL_PC) {
  254. sd = (struct map_session_data *)bl;
  255. }
  256. }
  257. switch(type) {
  258. case ALL_CLIENT: //All player clients.
  259. for (i = 0; i < fd_max; i++) {
  260. if (session[i] && session[i]->func_parse == clif_parse &&
  261. (sd = (struct map_session_data *)session[i]->session_data) != NULL&&
  262. sd->state.auth) {
  263. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  264. WFIFOHEAD(i, len);
  265. memcpy(WFIFOP(i,0), buf, len);
  266. WFIFOSET(i,len);
  267. }
  268. }
  269. }
  270. break;
  271. case ALL_SAMEMAP: //All players on the same map
  272. for(i = 0; i < fd_max; i++) {
  273. if (session[i] && session[i]->func_parse == clif_parse &&
  274. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  275. sd->state.auth && sd->bl.m == bl->m) {
  276. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  277. WFIFOHEAD(i,len);
  278. memcpy(WFIFOP(i,0), buf, len);
  279. WFIFOSET(i,len);
  280. }
  281. }
  282. }
  283. break;
  284. case AREA:
  285. case AREA_WOSC:
  286. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  287. clif_send (buf, len, bl, SELF);
  288. case AREA_WOC:
  289. case AREA_WOS:
  290. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  291. BL_PC, buf, len, bl, type);
  292. break;
  293. case AREA_CHAT_WOC:
  294. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  295. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  296. break;
  297. case CHAT:
  298. case CHAT_WOS:
  299. {
  300. struct chat_data *cd;
  301. if (sd) {
  302. cd = (struct chat_data*)map_id2bl(sd->chatID);
  303. } else if (bl->type == BL_CHAT) {
  304. cd = (struct chat_data*)bl;
  305. } else break;
  306. if (cd == NULL)
  307. break;
  308. for(i = 0; i < cd->users; i++) {
  309. if (type == CHAT_WOS && cd->usersd[i] == sd)
  310. continue;
  311. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  312. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  313. {
  314. WFIFOHEAD(fd,len);
  315. memcpy(WFIFOP(fd,0), buf, len);
  316. WFIFOSET(fd,len);
  317. }
  318. }
  319. }
  320. }
  321. break;
  322. case CHAT_MAINCHAT: //[LuzZza]
  323. for(i=1; i<fd_max; i++) {
  324. if (session[i] && session[i]->func_parse == clif_parse &&
  325. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  326. sd->state.mainchat && (fd=sd->fd))
  327. {
  328. WFIFOHEAD(fd,len);
  329. memcpy(WFIFOP(fd,0), buf, len);
  330. WFIFOSET(fd, len);
  331. }
  332. }
  333. break;
  334. case PARTY_AREA:
  335. case PARTY_AREA_WOS:
  336. x0 = bl->x - AREA_SIZE;
  337. y0 = bl->y - AREA_SIZE;
  338. x1 = bl->x + AREA_SIZE;
  339. y1 = bl->y + AREA_SIZE;
  340. case PARTY:
  341. case PARTY_WOS:
  342. case PARTY_SAMEMAP:
  343. case PARTY_SAMEMAP_WOS:
  344. if (sd && sd->status.party_id)
  345. p = party_search(sd->status.party_id);
  346. if (p) {
  347. for(i=0;i<MAX_PARTY;i++){
  348. if ((sd = p->data[i].sd) == NULL)
  349. continue;
  350. if (!(fd=sd->fd) || session[fd] == NULL || sd->state.auth == 0
  351. || session[fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  352. continue;
  353. if (sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS))
  354. continue;
  355. if (type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m)
  356. continue;
  357. if ((type == PARTY_AREA || type == PARTY_AREA_WOS) &&
  358. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  359. continue;
  360. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  361. WFIFOHEAD(fd,len);
  362. memcpy(WFIFOP(fd,0), buf, len);
  363. WFIFOSET(fd,len);
  364. }
  365. }
  366. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  367. break;
  368. for (i = 1; i < fd_max; i++){ // partyspy [Syrus22]
  369. if (session[i] && session[i]->func_parse == clif_parse &&
  370. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  371. sd->state.auth && (fd=sd->fd) && sd->partyspy == p->party.party_id)
  372. {
  373. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  374. WFIFOHEAD(fd,len);
  375. memcpy(WFIFOP(fd,0), buf, len);
  376. WFIFOSET(fd,len);
  377. }
  378. }
  379. }
  380. }
  381. break;
  382. case DUEL:
  383. case DUEL_WOS:
  384. if (!sd || !sd->duel_group) break; //Invalid usage.
  385. x0 = sd->duel_group; //Here we use x0 to store the duel group. [Skotlex]
  386. for (i = 0; i < fd_max; i++) {
  387. if (session[i] && session[i]->func_parse == clif_parse &&
  388. (sd = (struct map_session_data *)session[i]->session_data) != NULL &&
  389. sd->state.auth && sd->duel_group == x0) {
  390. if (type == DUEL_WOS && bl->id == sd->bl.id)
  391. continue;
  392. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) {
  393. WFIFOHEAD(i, len);
  394. memcpy(WFIFOP(i,0), buf, len);
  395. WFIFOSET(i,len);
  396. }
  397. }
  398. }
  399. break;
  400. case SELF:
  401. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  402. WFIFOHEAD(fd,len);
  403. memcpy(WFIFOP(fd,0), buf, len);
  404. WFIFOSET(fd,len);
  405. }
  406. break;
  407. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  408. case GUILD_AREA:
  409. case GUILD_AREA_WOS:
  410. x0 = bl->x - AREA_SIZE;
  411. y0 = bl->y - AREA_SIZE;
  412. x1 = bl->x + AREA_SIZE;
  413. y1 = bl->y + AREA_SIZE;
  414. case GUILD_SAMEMAP:
  415. case GUILD_SAMEMAP_WOS:
  416. case GUILD:
  417. case GUILD_WOS:
  418. if (sd && sd->status.guild_id)
  419. g = guild_search(sd->status.guild_id);
  420. if (g) {
  421. for(i = 0; i < g->max_member; i++) {
  422. if ((sd = g->member[i].sd) != NULL) {
  423. if (!(fd=sd->fd) || session[fd] == NULL || sd->state.auth == 0
  424. || session[fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  425. continue;
  426. if (sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS))
  427. continue;
  428. if (type != GUILD && type != GUILD_WOS && sd->bl.m != bl->m)
  429. continue;
  430. if ((type == GUILD_AREA || type == GUILD_AREA_WOS) &&
  431. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  432. continue;
  433. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  434. WFIFOHEAD(fd,len);
  435. memcpy(WFIFOP(fd,0), buf, len);
  436. WFIFOSET(fd,len);
  437. }
  438. }
  439. }
  440. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  441. break;
  442. for (i = 1; i < fd_max; i++){ // guildspy [Syrus22]
  443. if (session[i] && session[i]->func_parse == clif_parse &&
  444. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  445. sd->state.auth && (fd=sd->fd) && sd->guildspy == g->guild_id) {
  446. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  447. WFIFOHEAD(fd,len);
  448. memcpy(WFIFOP(fd,0), buf, len);
  449. WFIFOSET(fd,len);
  450. }
  451. }
  452. }
  453. }
  454. break;
  455. default:
  456. if (battle_config.error_log)
  457. ShowError("clif_send: Unrecognized type %d\n",type);
  458. return -1;
  459. }
  460. return 0;
  461. }
  462. //
  463. // パケット作って送信
  464. //
  465. /*==========================================
  466. *
  467. *------------------------------------------*/
  468. int clif_authok(struct map_session_data *sd)
  469. {
  470. int fd;
  471. if (!sd->fd)
  472. return 0;
  473. fd = sd->fd;
  474. WFIFOHEAD(fd, packet_len(0x73));
  475. WFIFOW(fd, 0) = 0x73;
  476. WFIFOL(fd, 2) = gettick();
  477. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  478. WFIFOB(fd, 9) = 5; // ignored
  479. WFIFOB(fd,10) = 5; // ignored
  480. WFIFOSET(fd,packet_len(0x73));
  481. return 0;
  482. }
  483. /*==========================================
  484. * Authentication failed/disconnect client.
  485. *------------------------------------------
  486. * The client closes it's socket and displays a message according to type:
  487. * 1 - server closed -> MsgStringTable[4]
  488. * 2 - ID already logged in -> MsgStringTable[5]
  489. * 3 - timeout/too much lag -> MsgStringTable[241]
  490. * 4 - server full -> MsgStringTable[264]
  491. * 5 - underaged -> MsgStringTable[305]
  492. * 9 - too many connections from this ip -> MsgStringTable[529]
  493. * 10 - payed time has ended -> MsgStringTable[530]
  494. * 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  495. * other - disconnected -> MsgStringTable[3]
  496. */
  497. int clif_authfail_fd(int fd, int type)
  498. {
  499. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  500. return 0;
  501. WFIFOHEAD(fd, packet_len(0x81));
  502. WFIFOW(fd,0) = 0x81;
  503. WFIFOB(fd,2) = type;
  504. WFIFOSET(fd,packet_len(0x81));
  505. clif_setwaitclose(fd);
  506. return 0;
  507. }
  508. /*==========================================
  509. * Used to know which is the max valid account/char id [Skotlex]
  510. *------------------------------------------*/
  511. void clif_updatemaxid(int account_id, int char_id)
  512. {
  513. max_account_id = account_id;
  514. max_char_id = char_id;
  515. }
  516. /*==========================================
  517. *
  518. *------------------------------------------*/
  519. int clif_charselectok(int id)
  520. {
  521. struct map_session_data *sd;
  522. int fd;
  523. if ((sd = map_id2sd(id)) == NULL)
  524. return 1;
  525. if (!sd->fd)
  526. return 1;
  527. fd = sd->fd;
  528. WFIFOHEAD(fd, packet_len(0xb3));
  529. WFIFOW(fd,0) = 0xb3;
  530. WFIFOB(fd,2) = 1;
  531. WFIFOSET(fd,packet_len(0xb3));
  532. return 0;
  533. }
  534. /*==========================================
  535. * Makes an item appear on the ground
  536. * 009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  537. *------------------------------------------*/
  538. int clif_dropflooritem(struct flooritem_data* fitem)
  539. {
  540. uint8 buf[17];
  541. int view;
  542. nullpo_retr(0, fitem);
  543. if (fitem->item_data.nameid <= 0)
  544. return 0;
  545. WBUFW(buf, 0) = 0x9e;
  546. WBUFL(buf, 2) = fitem->bl.id;
  547. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  548. WBUFB(buf, 8) = fitem->item_data.identify;
  549. WBUFW(buf, 9) = fitem->bl.x;
  550. WBUFW(buf,11) = fitem->bl.y;
  551. WBUFB(buf,13) = fitem->subx;
  552. WBUFB(buf,14) = fitem->suby;
  553. WBUFW(buf,15) = fitem->item_data.amount;
  554. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  555. return 0;
  556. }
  557. /*==========================================
  558. *
  559. *------------------------------------------*/
  560. int clif_clearflooritem(struct flooritem_data *fitem, int fd)
  561. {
  562. unsigned char buf[16];
  563. nullpo_retr(0, fitem);
  564. WBUFW(buf,0) = 0xa1;
  565. WBUFL(buf,2) = fitem->bl.id;
  566. if (fd == 0) {
  567. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  568. } else {
  569. WFIFOHEAD(fd,packet_len(0xa1));
  570. memcpy(WFIFOP(fd,0), buf, 6);
  571. WFIFOSET(fd,packet_len(0xa1));
  572. }
  573. return 0;
  574. }
  575. /*==========================================
  576. * make a unit (char, npc, mob, homun) disappear to one client
  577. * id : the id of the unit
  578. * type: 0 - moved out of sight
  579. * 1 - died
  580. * 2 - logged out
  581. * 3 - teleported / winged away
  582. * fd : the target client
  583. *------------------------------------------*/
  584. int clif_clearunit_single(int id, uint8 type, int fd)
  585. {
  586. WFIFOHEAD(fd, packet_len(0x80));
  587. WFIFOW(fd,0) = 0x80;
  588. WFIFOL(fd,2) = id;
  589. WFIFOB(fd,6) = type;
  590. WFIFOSET(fd, packet_len(0x80));
  591. return 0;
  592. }
  593. /*==========================================
  594. * make a unit (char, npc, mob, homun) disappear to all clients in area
  595. * type: 0 - moved out of sight
  596. * 1 - died
  597. * 2 - logged out
  598. * 3 - teleported / winged away
  599. *------------------------------------------*/
  600. int clif_clearunit_area(struct block_list* bl, uint8 type)
  601. {
  602. unsigned char buf[16];
  603. nullpo_retr(0, bl);
  604. WBUFW(buf,0) = 0x80;
  605. WBUFL(buf,2) = bl->id;
  606. WBUFB(buf,6) = type;
  607. clif_send(buf, packet_len(0x80), bl, type == 1 ? AREA : AREA_WOS);
  608. if(disguised(bl)) {
  609. WBUFL(buf,2) = -bl->id;
  610. clif_send(buf, packet_len(0x80), bl, SELF);
  611. }
  612. return 0;
  613. }
  614. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, int data)
  615. {
  616. struct block_list *bl = (struct block_list *)id;
  617. clif_clearunit_area(bl, 0);
  618. aFree(bl);
  619. return 0;
  620. }
  621. int clif_clearunit_delayed(struct block_list* bl, unsigned int tick)
  622. {
  623. struct block_list *tbl;
  624. tbl = aMalloc(sizeof (struct block_list));
  625. memcpy (tbl, bl, sizeof (struct block_list));
  626. add_timer(tick, clif_clearunit_delayed_sub, (int)tbl, 0);
  627. return 0;
  628. }
  629. void clif_get_weapon_view(TBL_PC* sd, unsigned short *rhand, unsigned short *lhand)
  630. {
  631. #if PACKETVER > 3
  632. struct item_data *id;
  633. #endif
  634. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  635. {
  636. *rhand = *lhand = 0;
  637. return;
  638. }
  639. #if PACKETVER < 4
  640. *rhand = sd->status.weapon;
  641. *lhand = sd->status.shield;
  642. #else
  643. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  644. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  645. {
  646. id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  647. if (id->view_id > 0)
  648. *rhand = id->view_id;
  649. else
  650. *rhand = id->nameid;
  651. } else
  652. *rhand = 0;
  653. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  654. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  655. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  656. {
  657. id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  658. if (id->view_id > 0)
  659. *lhand = id->view_id;
  660. else
  661. *lhand = id->nameid;
  662. } else
  663. *lhand = 0;
  664. #endif
  665. }
  666. /*==========================================
  667. *
  668. *------------------------------------------*/
  669. static int clif_set0078(struct block_list* bl, unsigned char* buf)
  670. {
  671. struct status_change* sc;
  672. struct view_data* vd;
  673. int guild_id, emblem_id, dir, lv;
  674. nullpo_retr(0, bl);
  675. sc = status_get_sc(bl);
  676. vd = status_get_viewdata(bl);
  677. guild_id = status_get_guild_id(bl);
  678. emblem_id = status_get_emblem_id(bl);
  679. dir = unit_getdir(bl);
  680. lv = status_get_lv(bl);
  681. if(pcdb_checkid(vd->class_))
  682. {
  683. struct map_session_data* sd;
  684. BL_CAST(BL_PC, bl, sd);
  685. #if PACKETVER > 6
  686. memset(buf,0,packet_len(0x22a));
  687. WBUFW(buf,0)=0x22a;
  688. WBUFL(buf,2)=bl->id;
  689. WBUFW(buf,6)=status_get_speed(bl);
  690. if (sc) {
  691. WBUFW(buf,8)=sc->opt1;
  692. WBUFW(buf,10)=sc->opt2;
  693. WBUFL(buf,12)=sc->option;
  694. WBUFL(buf,44)=sc->opt3;
  695. }
  696. WBUFW(buf,16)=vd->class_;
  697. WBUFW(buf,18)=vd->hair_style;
  698. WBUFW(buf,20)=vd->weapon;
  699. WBUFW(buf,22)=vd->shield;
  700. WBUFW(buf,24)=vd->head_bottom;
  701. WBUFW(buf,26)=vd->head_top;
  702. WBUFW(buf,28)=vd->head_mid;
  703. WBUFW(buf,30)=vd->hair_color;
  704. WBUFW(buf,32)=vd->cloth_color;
  705. WBUFW(buf,34)=sd?sd->head_dir:0;
  706. WBUFL(buf,36)=guild_id;
  707. WBUFW(buf,40)=emblem_id;
  708. if (sd) {
  709. WBUFW(buf,42)=sd->status.manner;
  710. WBUFB(buf,48)=sd->status.karma;
  711. }
  712. WBUFB(buf,49)=vd->sex;
  713. WBUFPOS(buf,50,bl->x,bl->y,dir);
  714. WBUFB(buf,53)=5;
  715. WBUFB(buf,54)=5;
  716. WBUFB(buf,55)=vd->dead_sit;
  717. WBUFW(buf,56)=clif_setlevel(lv);
  718. return packet_len(0x22a);
  719. #elif PACKETVER > 3
  720. memset(buf,0,packet_len(0x1d8));
  721. WBUFW(buf,0)=0x1d8;
  722. WBUFL(buf,2)=bl->id;
  723. WBUFW(buf,6)=status_get_speed(bl);
  724. if (sc) {
  725. WBUFW(buf,8)=sc->opt1;
  726. WBUFW(buf,10)=sc->opt2;
  727. WBUFW(buf,12)=sc->option;
  728. WBUFW(buf,42)=sc->opt3;
  729. }
  730. WBUFW(buf,14)=vd->class_;
  731. WBUFW(buf,16)=vd->hair_style;
  732. WBUFW(buf,18)=vd->weapon;
  733. WBUFW(buf,20)=vd->shield;
  734. WBUFW(buf,22)=vd->head_bottom;
  735. WBUFW(buf,24)=vd->head_top;
  736. WBUFW(buf,26)=vd->head_mid;
  737. WBUFW(buf,28)=vd->hair_color;
  738. WBUFW(buf,30)=vd->cloth_color;
  739. WBUFW(buf,32)=sd?sd->head_dir:0;
  740. WBUFL(buf,34)=guild_id;
  741. WBUFW(buf,38)=emblem_id;
  742. if (sd) {
  743. WBUFW(buf,40)=sd->status.manner;
  744. WBUFB(buf,44)=sd->status.karma;
  745. }
  746. WBUFB(buf,45)=vd->sex;
  747. WBUFPOS(buf,46,bl->x,bl->y,dir);
  748. WBUFB(buf,49)=5;
  749. WBUFB(buf,50)=5;
  750. WBUFB(buf,51)=vd->dead_sit;
  751. WBUFW(buf,52)=clif_setlevel(lv);
  752. return packet_len(0x1d8);
  753. #else
  754. memset(buf,0,packet_len(0x78));
  755. WBUFW(buf,0)=0x78;
  756. WBUFL(buf,2)=bl->id;
  757. WBUFW(buf,6)=status_get_speed(bl);
  758. if (sc) {
  759. WBUFW(buf,8)=sc->opt1;
  760. WBUFW(buf,10)=sc->opt2;
  761. WBUFW(buf,12)=sc->option;
  762. WBUFW(buf,42)=sc->opt3;
  763. }
  764. WBUFW(buf,14)=vd->class_;
  765. WBUFW(buf,16)=vd->hair_style;
  766. WBUFW(buf,18)=vd->weapon;
  767. WBUFW(buf,20)=vd->head_bottom;
  768. WBUFW(buf,22)=vd->shield;
  769. WBUFW(buf,24)=vd->head_top;
  770. WBUFW(buf,26)=vd->head_mid;
  771. WBUFW(buf,28)=vd->hair_color;
  772. WBUFW(buf,30)=vd->cloth_color;
  773. WBUFW(buf,32)=sd?sd->head_dir:0;
  774. WBUFL(buf,34)=guild_id;
  775. WBUFL(buf,38)=emblem_id;
  776. if (sd)
  777. WBUFB(buf,44)=sd->status.karma;
  778. WBUFB(buf,45)=vd->sex;
  779. WBUFPOS(buf,46,bl->x,bl->y,dir);
  780. WBUFB(buf,49)=5;
  781. WBUFB(buf,50)=5;
  782. WBUFB(buf,51)=vd->dead_sit;
  783. WBUFW(buf,52)=clif_setlevel(lv);
  784. return packet_len(0x78);
  785. #endif
  786. }
  787. //Non-player sprites need just a few fields filled.
  788. memset(buf,0,packet_len(0x78));
  789. WBUFW(buf,0)=0x78;
  790. WBUFL(buf,2)=bl->id;
  791. WBUFW(buf,6)=status_get_speed(bl);
  792. if (sc) {
  793. WBUFW(buf,8)=sc->opt1;
  794. WBUFW(buf,10)=sc->opt2;
  795. WBUFW(buf,12)=sc->option;
  796. WBUFW(buf,42)=sc->opt3;
  797. }
  798. WBUFW(buf,14)=vd->class_;
  799. WBUFW(buf,16)=vd->hair_style; //Required for pets.
  800. //18W: Weapon
  801. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  802. if (bl->type == BL_NPC && vd->class_ == FLAG_CLASS)
  803. { //The hell, why flags work like this?
  804. WBUFL(buf,22)=emblem_id;
  805. WBUFL(buf,26)=guild_id;
  806. }
  807. //22W: shield
  808. //24W: Head top
  809. //26W: Head mid
  810. //28W: Hair color
  811. //30W: Clothes color
  812. WBUFW(buf,32)=dir;
  813. WBUFL(buf,34)=guild_id;
  814. WBUFL(buf,38)=emblem_id;
  815. //42W: Manner
  816. //44B: Karma
  817. //45B: Sex
  818. WBUFPOS(buf,46,bl->x,bl->y,dir);
  819. //WBUFB(buf,49)=5;
  820. //WBUFB(buf,50)=5;
  821. //51B: Sit/Stand
  822. WBUFW(buf,52)=clif_setlevel(lv);
  823. return packet_len(0x78);
  824. }
  825. /*==========================================
  826. *
  827. *------------------------------------------*/
  828. static int clif_set007b(struct block_list *bl, struct view_data *vd, struct unit_data *ud, unsigned char *buf)
  829. {
  830. struct status_change *sc;
  831. int guild_id, emblem_id, lv;
  832. nullpo_retr(0, bl);
  833. sc = status_get_sc(bl);
  834. guild_id = status_get_guild_id(bl);
  835. emblem_id = status_get_emblem_id(bl);
  836. lv = status_get_lv(bl);
  837. if(pcdb_checkid(vd->class_))
  838. {
  839. struct map_session_data* sd;
  840. BL_CAST(BL_PC, bl, sd);
  841. #if PACKETVER > 6
  842. memset(buf,0,packet_len(0x22c));
  843. WBUFW(buf,0)=0x22c;
  844. WBUFL(buf,2)=bl->id;
  845. WBUFW(buf,6)=status_get_speed(bl);
  846. if (sc) {
  847. WBUFW(buf,8)= sc->opt1;
  848. WBUFW(buf,10)= sc->opt2;
  849. WBUFL(buf,12)= sc->option;
  850. WBUFL(buf,48)= sc->opt3;
  851. }
  852. WBUFW(buf,16)=vd->class_;
  853. WBUFW(buf,18)=vd->hair_style;
  854. WBUFW(buf,20)=vd->weapon;
  855. WBUFW(buf,22)=vd->shield;
  856. WBUFW(buf,24)=vd->head_bottom;
  857. WBUFL(buf,26)=gettick();
  858. WBUFW(buf,30)=vd->head_top;
  859. WBUFW(buf,32)=vd->head_mid;
  860. WBUFW(buf,34)=vd->hair_color;
  861. WBUFW(buf,36)=vd->cloth_color;
  862. WBUFW(buf,38)=sd?sd->head_dir:0;
  863. WBUFL(buf,40)=guild_id;
  864. WBUFW(buf,44)=emblem_id;
  865. if (sd) {
  866. WBUFW(buf,46)=sd->status.manner;
  867. WBUFB(buf,52)=sd->status.karma;
  868. }
  869. WBUFB(buf,53)=vd->sex;
  870. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  871. WBUFB(buf,60)=0;
  872. WBUFB(buf,61)=0;
  873. WBUFW(buf,62)=clif_setlevel(lv);
  874. return packet_len(0x22c);
  875. #elif PACKETVER > 3
  876. memset(buf,0,packet_len(0x1da));
  877. WBUFW(buf,0)=0x1da;
  878. WBUFL(buf,2)=bl->id;
  879. WBUFW(buf,6)=status_get_speed(bl);
  880. if (sc) {
  881. WBUFW(buf,8)=sc->opt1;
  882. WBUFW(buf,10)=sc->opt2;
  883. WBUFW(buf,12)=sc->option;
  884. WBUFW(buf,46)=sc->opt3;
  885. }
  886. WBUFW(buf,14)=vd->class_;
  887. WBUFW(buf,16)=vd->hair_style;
  888. WBUFW(buf,18)=vd->weapon;
  889. WBUFW(buf,20)=vd->shield;
  890. WBUFW(buf,22)=vd->head_bottom;
  891. WBUFL(buf,24)=gettick();
  892. WBUFW(buf,28)=vd->head_top;
  893. WBUFW(buf,30)=vd->head_mid;
  894. WBUFW(buf,32)=vd->hair_color;
  895. WBUFW(buf,34)=vd->cloth_color;
  896. WBUFW(buf,36)=sd?sd->head_dir:0;
  897. WBUFL(buf,38)=guild_id;
  898. WBUFW(buf,42)=emblem_id;
  899. if (sd) {
  900. WBUFW(buf,44)=sd->status.manner;
  901. WBUFB(buf,48)=sd->status.karma;
  902. }
  903. WBUFB(buf,49)=vd->sex;
  904. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  905. WBUFB(buf,56)=5;
  906. WBUFB(buf,57)=5;
  907. WBUFW(buf,58)=clif_setlevel(lv);
  908. return packet_len(0x1da);
  909. #else
  910. memset(buf,0,packet_len(0x7b));
  911. WBUFW(buf,0)=0x7b;
  912. WBUFL(buf,2)=bl->id;
  913. WBUFW(buf,6)=status_get_speed(bl);
  914. if (sc) {
  915. WBUFW(buf,8)=sc->opt1;
  916. WBUFW(buf,10)=sc->opt2;
  917. WBUFW(buf,12)=sc->option;
  918. WBUFW(buf,46)=sc->opt3;
  919. }
  920. WBUFW(buf,14)=vd->class_;
  921. WBUFW(buf,16)=vd->hair_style;
  922. WBUFW(buf,18)=vd->weapon;
  923. WBUFW(buf,20)=vd->head_bottom;
  924. WBUFL(buf,22)=gettick();
  925. WBUFW(buf,26)=vd->shield;
  926. WBUFW(buf,28)=vd->head_top;
  927. WBUFW(buf,30)=vd->head_mid;
  928. WBUFW(buf,32)=vd->hair_color;
  929. WBUFW(buf,34)=vd->cloth_color;
  930. WBUFW(buf,36)=sd?sd->head_dir:0;
  931. WBUFL(buf,38)=guild_id;
  932. WBUFL(buf,42)=emblem_id;
  933. if (sd)
  934. WBUFB(buf,48)=sd->status.karma;
  935. WBUFB(buf,49)=vd->sex;
  936. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  937. WBUFB(buf,56)=5;
  938. WBUFB(buf,57)=5;
  939. WBUFW(buf,58)=clif_setlevel(lv);
  940. return packet_len(0x7b);
  941. #endif
  942. }
  943. //Non-player sprites only require a few fields.
  944. #if PACKETVER > 6
  945. memset(buf,0,packet_len(0x22c));
  946. WBUFW(buf,0)=0x22c;
  947. WBUFL(buf,2)=bl->id;
  948. WBUFW(buf,6)=status_get_speed(bl);
  949. if (sc) {
  950. WBUFW(buf,8)=sc->opt1;
  951. WBUFW(buf,10)=sc->opt2;
  952. WBUFL(buf,12)=sc->option;
  953. WBUFL(buf,48)=sc->opt3;
  954. }
  955. WBUFW(buf,16)=vd->class_;
  956. WBUFW(buf,18)=vd->hair_style; //For pets
  957. WBUFW(buf,24)=vd->head_bottom; //Pet armor
  958. WBUFL(buf,26)=gettick();
  959. WBUFW(buf,38)=unit_getdir(bl);
  960. WBUFL(buf,40)=guild_id;
  961. WBUFL(buf,44)=emblem_id;
  962. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  963. WBUFB(buf,60)=0;
  964. WBUFB(buf,61)=0;
  965. WBUFW(buf,62)=clif_setlevel(lv);
  966. return packet_len(0x22c);
  967. #else
  968. memset(buf,0,packet_len(0x7b));
  969. WBUFW(buf,0)=0x7b;
  970. WBUFL(buf,2)=bl->id;
  971. WBUFW(buf,6)=status_get_speed(bl);
  972. if (sc) {
  973. WBUFW(buf,8)=sc->opt1;
  974. WBUFW(buf,10)=sc->opt2;
  975. WBUFW(buf,12)=sc->option;
  976. WBUFW(buf,46)=sc->opt3;
  977. }
  978. WBUFW(buf,14)=vd->class_;
  979. WBUFW(buf,16)=vd->hair_style; //For pets
  980. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  981. WBUFL(buf,22)=gettick();
  982. WBUFW(buf,36)=unit_getdir(bl);
  983. WBUFL(buf,38)=guild_id;
  984. WBUFL(buf,42)=emblem_id;
  985. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  986. WBUFB(buf,56)=5;
  987. WBUFB(buf,57)=5;
  988. WBUFW(buf,58)=clif_setlevel(lv);
  989. return packet_len(0x7b);
  990. #endif
  991. }
  992. //Modifies the buffer for disguise characters and sends it to self.
  993. //Flag = 0: change id to negative, buf will have disguise data.
  994. //Flag = 1: change id to positive, class and option to make your own char invisible.
  995. //Luckily, the offsets that need to be changed are the same in packets 0x78, 0x7b, 0x1d8 and 0x1da
  996. //But no longer holds true for those packet of PACKETVER 7.
  997. static void clif_setdisguise(struct map_session_data *sd, unsigned char *buf,int len, int flag)
  998. {
  999. if (flag) {
  1000. #if PACKETVER > 6
  1001. switch (WBUFW(buf,0)) {
  1002. case 0x22c:
  1003. case 0x22b:
  1004. case 0x22a:
  1005. WBUFL(buf,12)=OPTION_INVISIBLE;
  1006. WBUFW(buf,16)=sd->status.class_;
  1007. break;
  1008. default:
  1009. #endif
  1010. WBUFL(buf,2)=sd->bl.id;
  1011. WBUFW(buf,12)=OPTION_INVISIBLE;
  1012. WBUFW(buf,14)=sd->status.class_;
  1013. #if PACKETVER > 6
  1014. break;
  1015. }
  1016. #endif
  1017. } else {
  1018. WBUFL(buf,2)=-sd->bl.id;
  1019. }
  1020. clif_send(buf, len, &sd->bl, SELF);
  1021. }
  1022. /*==========================================
  1023. * クラスチェンジ typeはMobの場合は1で他は0?
  1024. *------------------------------------------*/
  1025. int clif_class_change(struct block_list *bl,int class_,int type)
  1026. {
  1027. unsigned char buf[16];
  1028. nullpo_retr(0, bl);
  1029. if(!pcdb_checkid(class_)) {
  1030. WBUFW(buf,0)=0x1b0;
  1031. WBUFL(buf,2)=bl->id;
  1032. WBUFB(buf,6)=type;
  1033. WBUFL(buf,7)=class_;
  1034. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1035. }
  1036. return 0;
  1037. }
  1038. /*==========================================
  1039. *
  1040. *------------------------------------------*/
  1041. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1042. {
  1043. WFIFOHEAD(fd, packet_len(0x1e1));
  1044. WFIFOW(fd,0)=0x1e1;
  1045. WFIFOL(fd,2)=sd->bl.id;
  1046. WFIFOW(fd,6)=sd->spiritball;
  1047. WFIFOSET(fd, packet_len(0x1e1));
  1048. }
  1049. /*==========================================
  1050. *
  1051. *------------------------------------------*/
  1052. static int clif_set0192(int fd, int m, int x, int y, int type)
  1053. {
  1054. char map_name[MAP_NAME_LENGTH_EXT];
  1055. sprintf(map_name, "%s.gat", map[m].name);
  1056. WFIFOHEAD(fd, packet_len(0x192));
  1057. WFIFOW(fd,0) = 0x192;
  1058. WFIFOW(fd,2) = x;
  1059. WFIFOW(fd,4) = y;
  1060. WFIFOW(fd,6) = type;
  1061. memcpy(WFIFOP(fd,8),map_name,MAP_NAME_LENGTH_EXT);
  1062. WFIFOSET(fd,packet_len(0x192));
  1063. return 0;
  1064. }
  1065. // new and improved weather display [Valaris]
  1066. static void clif_weather_sub(int fd, int id, int type)
  1067. {
  1068. WFIFOHEAD(fd, packet_len(0x1f3));
  1069. WFIFOW(fd,0) = 0x1f3;
  1070. WFIFOL(fd,2) = id;
  1071. WFIFOL(fd,6) = type;
  1072. WFIFOSET(fd,packet_len(0x1f3));
  1073. }
  1074. /*==========================================
  1075. *
  1076. *------------------------------------------*/
  1077. static void clif_weather_check(struct map_session_data *sd)
  1078. {
  1079. int m = sd->bl.m, fd = sd->fd;
  1080. if (map[m].flag.snow
  1081. || map[m].flag.clouds
  1082. || map[m].flag.fog
  1083. || map[m].flag.fireworks
  1084. || map[m].flag.sakura
  1085. || map[m].flag.leaves
  1086. || map[m].flag.rain
  1087. || map[m].flag.clouds2)
  1088. {
  1089. if (map[m].flag.snow)
  1090. clif_weather_sub(fd, sd->bl.id, 162);
  1091. if (map[m].flag.clouds)
  1092. clif_weather_sub(fd, sd->bl.id, 233);
  1093. if (map[m].flag.clouds2)
  1094. clif_weather_sub(fd, sd->bl.id, 516);
  1095. if (map[m].flag.fog)
  1096. clif_weather_sub(fd, sd->bl.id, 515);
  1097. if (map[m].flag.fireworks) {
  1098. clif_weather_sub(fd, sd->bl.id, 297);
  1099. clif_weather_sub(fd, sd->bl.id, 299);
  1100. clif_weather_sub(fd, sd->bl.id, 301);
  1101. }
  1102. if (map[m].flag.sakura)
  1103. clif_weather_sub(fd, sd->bl.id, 163);
  1104. if (map[m].flag.leaves)
  1105. clif_weather_sub(fd, sd->bl.id, 333);
  1106. if (map[m].flag.rain)
  1107. clif_weather_sub(fd, sd->bl.id, 161);
  1108. }
  1109. }
  1110. int clif_weather(int m)
  1111. {
  1112. int i;
  1113. struct map_session_data *sd=NULL;
  1114. for(i = 0; i < fd_max; i++) {
  1115. if (session[i] && session[i]->func_parse == clif_parse &&
  1116. (sd = session[i]->session_data) != NULL &&
  1117. sd->state.auth && sd->bl.m == m) {
  1118. clif_weather_check(sd);
  1119. }
  1120. }
  1121. return 0;
  1122. }
  1123. int clif_spawn(struct block_list *bl)
  1124. {
  1125. unsigned char buf[128];
  1126. struct view_data *vd;
  1127. nullpo_retr(0, bl);
  1128. vd = status_get_viewdata(bl);
  1129. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1130. return 0;
  1131. if (pcdb_checkid(vd->class_))
  1132. { //Player spawn packet.
  1133. clif_set0078(bl, buf);
  1134. switch(WBUFW(buf,0))
  1135. {
  1136. case 0x78: //Convert to 0x79
  1137. WBUFW(buf, 0) = 0x79;
  1138. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1139. clif_send(buf, packet_len(0x79), bl, AREA_WOS);
  1140. if (disguised(bl))
  1141. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x79), 0);
  1142. break;
  1143. #if PACKETVER > 3
  1144. case 0x1d8: //Convert to 0x1d9
  1145. WBUFW(buf, 0) = 0x1d9;
  1146. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1147. clif_send(buf, packet_len(0x1d9), bl, AREA_WOS);
  1148. if (disguised(bl))
  1149. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x1d9), 0);
  1150. break;
  1151. #endif
  1152. #if PACKETVER > 6
  1153. case 0x22a: //Convert to 0x22b
  1154. WBUFW(buf, 0) = 0x22b;
  1155. WBUFW(buf,55) = WBUFW(buf,56); //Lv is placed on offset 56
  1156. clif_send(buf, packet_len(0x22b), bl, AREA_WOS);
  1157. if (disguised(bl))
  1158. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x22b), 0);
  1159. break;
  1160. #endif
  1161. }
  1162. } else { //Mob spawn packet.
  1163. struct status_change *sc = status_get_sc(bl);
  1164. memset(buf,0,sizeof(buf));
  1165. WBUFW(buf,0)=0x7c;
  1166. WBUFL(buf,2)=bl->id;
  1167. WBUFW(buf,6)=status_get_speed(bl);
  1168. if (sc) {
  1169. WBUFW(buf,8)=sc->opt1;
  1170. WBUFW(buf,10)=sc->opt2;
  1171. WBUFW(buf,12)=sc->option;
  1172. }
  1173. WBUFW(buf,20)=vd->class_;
  1174. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  1175. clif_send(buf,packet_len(0x7c),bl,AREA_WOS);
  1176. if (disguised(bl)) {
  1177. WBUFL(buf,2)=-bl->id;
  1178. clif_send(buf,packet_len(0x7c),bl,SELF);
  1179. }
  1180. }
  1181. if (vd->cloth_color)
  1182. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1183. switch (bl->type)
  1184. {
  1185. case BL_PC:
  1186. {
  1187. TBL_PC *sd = ((TBL_PC*)bl);
  1188. if (sd->spiritball > 0)
  1189. clif_spiritball(sd);
  1190. if(sd->state.size==2) // tiny/big players [Valaris]
  1191. clif_specialeffect(bl,423,AREA);
  1192. else if(sd->state.size==1)
  1193. clif_specialeffect(bl,421,AREA);
  1194. }
  1195. break;
  1196. case BL_MOB:
  1197. {
  1198. TBL_MOB *md = ((TBL_MOB*)bl);
  1199. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1200. clif_specialeffect(&md->bl,423,AREA);
  1201. else if(md->special_state.size==1)
  1202. clif_specialeffect(&md->bl,421,AREA);
  1203. }
  1204. break;
  1205. case BL_PET:
  1206. {
  1207. unsigned char buf[64];
  1208. int len = clif_set0078(bl, buf);
  1209. clif_send(buf, len, bl, AREA_WOS);
  1210. }
  1211. break;
  1212. }
  1213. return 0;
  1214. }
  1215. //[orn]
  1216. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1217. {
  1218. struct status_data *status;
  1219. unsigned char buf[128];
  1220. nullpo_retr(0, hd);
  1221. status = &hd->battle_status;
  1222. memset(buf,0,packet_len(0x22e));
  1223. WBUFW(buf,0)=0x22e;
  1224. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1225. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1226. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1227. WBUFW(buf,27)=hd->homunculus.level;
  1228. WBUFW(buf,29)=hd->homunculus.hunger;
  1229. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1230. WBUFW(buf,33)=0; // equip id
  1231. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, SHRT_MAX);
  1232. WBUFW(buf,37)=cap_value(status->matk_max, 0, SHRT_MAX);
  1233. WBUFW(buf,39)=status->hit;
  1234. if (battle_config.hom_setting&0x10)
  1235. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1236. else
  1237. WBUFW(buf,41)=status->cri/10;
  1238. WBUFW(buf,43)=status->def + status->vit ;
  1239. WBUFW(buf,45)=status->mdef;
  1240. WBUFW(buf,47)=status->flee;
  1241. WBUFW(buf,49)=(flag)?0:status->amotion;
  1242. if (status->max_hp > SHRT_MAX) {
  1243. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1244. WBUFW(buf,53) = 100;
  1245. } else {
  1246. WBUFW(buf,51)=status->hp;
  1247. WBUFW(buf,53)=status->max_hp;
  1248. }
  1249. if (status->max_sp > SHRT_MAX) {
  1250. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1251. WBUFW(buf,57) = 100;
  1252. } else {
  1253. WBUFW(buf,55)=status->sp;
  1254. WBUFW(buf,57)=status->max_sp;
  1255. }
  1256. WBUFL(buf,59)=hd->homunculus.exp;
  1257. WBUFL(buf,63)=hd->exp_next;
  1258. WBUFW(buf,67)=hd->homunculus.skillpts;
  1259. WBUFW(buf,69)=1; // FIXME: Attackable? When exactly is a homun not attackable? [Skotlex]
  1260. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1261. return 0;
  1262. }
  1263. void clif_send_homdata(struct map_session_data *sd, int type, int param)
  1264. { //[orn]
  1265. int fd = sd->fd;
  1266. WFIFOHEAD(fd, packet_len(0x230));
  1267. nullpo_retv(sd->hd);
  1268. WFIFOW(fd,0)=0x230;
  1269. WFIFOW(fd,2)=type;
  1270. WFIFOL(fd,4)=sd->hd->bl.id;
  1271. WFIFOL(fd,8)=param;
  1272. WFIFOSET(fd,packet_len(0x230));
  1273. return;
  1274. }
  1275. int clif_homskillinfoblock(struct map_session_data *sd)
  1276. { //[orn]
  1277. struct homun_data *hd;
  1278. int fd = sd->fd;
  1279. int i,j,len=4,id;
  1280. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1281. hd = sd->hd;
  1282. if ( !hd )
  1283. return 0 ;
  1284. WFIFOW(fd,0)=0x235;
  1285. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1286. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1287. j = id - HM_SKILLBASE - 1 ;
  1288. WFIFOW(fd,len ) = id ;
  1289. WFIFOW(fd,len+2) = skill_get_inf(id) ;
  1290. WFIFOW(fd,len+4) = 0 ;
  1291. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv ;
  1292. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv) ;
  1293. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv) ;
  1294. strncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH) ;
  1295. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1296. len+=37;
  1297. }
  1298. }
  1299. WFIFOW(fd,2)=len;
  1300. WFIFOSET(fd,len);
  1301. return 0;
  1302. }
  1303. void clif_homskillup(struct map_session_data *sd, int skill_num)
  1304. { //[orn]
  1305. struct homun_data *hd;
  1306. int fd=sd->fd, skillid;
  1307. WFIFOHEAD(fd, packet_len(0x239));
  1308. nullpo_retv(sd);
  1309. skillid = skill_num - HM_SKILLBASE - 1;
  1310. hd=sd->hd;
  1311. WFIFOW(fd,0) = 0x239;
  1312. WFIFOW(fd,2) = skill_num;
  1313. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1314. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1315. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1316. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1317. WFIFOSET(fd,packet_len(0x239));
  1318. return;
  1319. }
  1320. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1321. {
  1322. int fd=sd->fd;
  1323. WFIFOHEAD(fd,packet_len(0x22f));
  1324. WFIFOW(fd,0)=0x22f;
  1325. WFIFOB(fd,2)=fail;
  1326. WFIFOW(fd,3)=foodid;
  1327. WFIFOSET(fd,packet_len(0x22f));
  1328. return 0;
  1329. }
  1330. /*==========================================
  1331. *
  1332. *------------------------------------------*/
  1333. int clif_walkok(struct map_session_data *sd)
  1334. {
  1335. int fd=sd->fd;
  1336. WFIFOHEAD(fd, packet_len(0x87));
  1337. WFIFOW(fd,0)=0x87;
  1338. WFIFOL(fd,2)=gettick();
  1339. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1340. WFIFOSET(fd,packet_len(0x87));
  1341. return 0;
  1342. }
  1343. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1344. {
  1345. unsigned char buf[256];
  1346. int len;
  1347. len = clif_set007b(bl,vd,ud,buf);
  1348. clif_send(buf,len,bl,AREA_WOS);
  1349. if (disguised(bl))
  1350. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  1351. if(vd->cloth_color)
  1352. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1353. switch(bl->type)
  1354. {
  1355. case BL_PC:
  1356. {
  1357. TBL_PC *sd = ((TBL_PC*)bl);
  1358. // clif_movepc(sd);
  1359. if(sd->state.size==2) // tiny/big players [Valaris]
  1360. clif_specialeffect(&sd->bl,423,AREA);
  1361. else if(sd->state.size==1)
  1362. clif_specialeffect(&sd->bl,421,AREA);
  1363. }
  1364. break;
  1365. case BL_MOB:
  1366. {
  1367. TBL_MOB *md = ((TBL_MOB*)bl);
  1368. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1369. clif_specialeffect(&md->bl,423,AREA);
  1370. else if(md->special_state.size==1)
  1371. clif_specialeffect(&md->bl,421,AREA);
  1372. }
  1373. break;
  1374. }
  1375. return;
  1376. }
  1377. /// Move the unit (does nothing if the client has no info about the unit)
  1378. /// Note: unit must not be self
  1379. void clif_move(struct unit_data *ud)
  1380. {
  1381. unsigned char buf[16];
  1382. struct view_data* vd;
  1383. struct block_list* bl = ud->bl;
  1384. vd = status_get_viewdata(bl);
  1385. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1386. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1387. if (ud->state.speed_changed) {
  1388. // Since we don't know how to update the speed of other objects,
  1389. // use the old walk packet to update the data.
  1390. ud->state.speed_changed = 0;
  1391. clif_move2(bl, vd, ud);
  1392. return;
  1393. }
  1394. WBUFW(buf,0)=0x86;
  1395. WBUFL(buf,2)=bl->id;
  1396. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1397. WBUFL(buf,12)=gettick();
  1398. clif_send(buf, 16, bl, AREA_WOS);
  1399. if (disguised(bl))
  1400. clif_setdisguise((TBL_PC*)bl, buf, 16, 0);
  1401. }
  1402. /*==========================================
  1403. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1404. *------------------------------------------*/
  1405. static int clif_delayquit(int tid, unsigned int tick, int id, int data)
  1406. {
  1407. struct map_session_data *sd = NULL;
  1408. //Remove player from map server
  1409. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1410. map_quit(sd);
  1411. return 0;
  1412. }
  1413. /*==========================================
  1414. *
  1415. *------------------------------------------*/
  1416. void clif_quitsave(int fd,struct map_session_data *sd)
  1417. {
  1418. if (sd->state.waitingdisconnect || //Was already waiting to be disconnected.
  1419. !battle_config.prevent_logout ||
  1420. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1421. map_quit(sd);
  1422. else if (sd->fd)
  1423. { //Disassociate session from player (session is deleted after this function was called)
  1424. //And set a timer to make him quit later.
  1425. session[sd->fd]->session_data = NULL;
  1426. sd->fd = 0;
  1427. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1428. }
  1429. }
  1430. /*==========================================
  1431. *
  1432. *------------------------------------------*/
  1433. static int clif_waitclose(int tid, unsigned int tick, int id, int data)
  1434. {
  1435. if (session[id] && session[id]->func_parse == clif_parse) //Avoid disconnecting non-players, as pointed out by End of Exam [Skotlex]
  1436. set_eof(id);
  1437. return 0;
  1438. }
  1439. /*==========================================
  1440. *
  1441. *------------------------------------------*/
  1442. void clif_setwaitclose(int fd)
  1443. {
  1444. struct map_session_data *sd;
  1445. // if player is not already in the game (double connection probably)
  1446. if ((sd = (struct map_session_data*)session[fd]->session_data) == NULL) {
  1447. // limited timer, just to send information.
  1448. add_timer(gettick() + 1000, clif_waitclose, fd, 0);
  1449. } else
  1450. add_timer(gettick() + 5000, clif_waitclose, fd, 0);
  1451. }
  1452. /*==========================================
  1453. *
  1454. *------------------------------------------*/
  1455. int clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1456. {
  1457. int fd;
  1458. char map_name[MAP_NAME_LENGTH_EXT];
  1459. nullpo_retr(0, sd);
  1460. fd = sd->fd;
  1461. sprintf(map_name, "%s.gat", mapindex_id2name(map));
  1462. WFIFOHEAD(fd, packet_len(0x91));
  1463. WFIFOW(fd,0) = 0x91;
  1464. memcpy(WFIFOP(fd,2), map_name, MAP_NAME_LENGTH_EXT);
  1465. WFIFOW(fd,18) = x;
  1466. WFIFOW(fd,20) = y;
  1467. WFIFOSET(fd, packet_len(0x91));
  1468. return 0;
  1469. }
  1470. /*==========================================
  1471. * Tells the client to connect to another map-server
  1472. *------------------------------------------*/
  1473. int clif_changemapserver(struct map_session_data* sd, const char* mapname, int x, int y, uint32 ip, uint16 port)
  1474. {
  1475. int fd;
  1476. nullpo_retr(0, sd);
  1477. fd = sd->fd;
  1478. WFIFOHEAD(fd, packet_len(0x92));
  1479. WFIFOW(fd,0) = 0x92;
  1480. //Better not trust the null-terminator is there. [Skotlex]
  1481. memcpy(WFIFOP(fd,2), mapname, MAP_NAME_LENGTH_EXT);
  1482. WFIFOB(fd,17) = 0; //Null terminator for mapname
  1483. WFIFOW(fd,18) = x;
  1484. WFIFOW(fd,20) = y;
  1485. WFIFOL(fd,22) = htonl(ip);
  1486. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1487. WFIFOSET(fd, packet_len(0x92));
  1488. return 0;
  1489. }
  1490. int clif_blown(struct block_list *bl)
  1491. {
  1492. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1493. // return clif_fixpos(bl);
  1494. return clif_slide(bl, bl->x, bl->y);
  1495. }
  1496. /*==========================================
  1497. *
  1498. *------------------------------------------*/
  1499. int clif_fixpos(struct block_list *bl)
  1500. {
  1501. unsigned char buf[16];
  1502. nullpo_retr(0, bl);
  1503. WBUFW(buf,0)=0x88;
  1504. WBUFL(buf,2)=bl->id;
  1505. WBUFW(buf,6)=bl->x;
  1506. WBUFW(buf,8)=bl->y;
  1507. clif_send(buf, packet_len(0x88), bl, AREA);
  1508. if (disguised(bl)) {
  1509. WBUFL(buf,2)=-bl->id;
  1510. clif_send(buf, packet_len(0x88), bl, SELF);
  1511. }
  1512. return 0;
  1513. }
  1514. /*==========================================
  1515. *
  1516. *------------------------------------------*/
  1517. int clif_npcbuysell(struct map_session_data* sd, int id)
  1518. {
  1519. int fd;
  1520. nullpo_retr(0, sd);
  1521. fd=sd->fd;
  1522. WFIFOHEAD(fd, packet_len(0xc4));
  1523. WFIFOW(fd,0)=0xc4;
  1524. WFIFOL(fd,2)=id;
  1525. WFIFOSET(fd,packet_len(0xc4));
  1526. return 0;
  1527. }
  1528. /*==========================================
  1529. *
  1530. *------------------------------------------*/
  1531. int clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1532. {
  1533. struct item_data *id;
  1534. int fd,i,val;
  1535. nullpo_retr(0, sd);
  1536. nullpo_retr(0, nd);
  1537. fd=sd->fd;
  1538. WFIFOHEAD(fd, 200 * 11 + 4);
  1539. WFIFOW(fd,0)=0xc6;
  1540. for(i=0;nd->u.shop_item[i].nameid > 0;i++){
  1541. id = itemdb_search(nd->u.shop_item[i].nameid);
  1542. val=nd->u.shop_item[i].value;
  1543. WFIFOL(fd,4+i*11)=val;
  1544. if (!id->flag.value_notdc)
  1545. val=pc_modifybuyvalue(sd,val);
  1546. WFIFOL(fd,8+i*11)=val;
  1547. WFIFOB(fd,12+i*11)=itemtype(id->type);
  1548. if (id->view_id > 0)
  1549. WFIFOW(fd,13+i*11)=id->view_id;
  1550. else
  1551. WFIFOW(fd,13+i*11)=nd->u.shop_item[i].nameid;
  1552. }
  1553. WFIFOW(fd,2)=i*11+4;
  1554. WFIFOSET(fd,WFIFOW(fd,2));
  1555. return 0;
  1556. }
  1557. /*==========================================
  1558. *
  1559. *------------------------------------------*/
  1560. int clif_selllist(struct map_session_data *sd)
  1561. {
  1562. int fd,i,c=0,val;
  1563. nullpo_retr(0, sd);
  1564. fd=sd->fd;
  1565. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1566. WFIFOW(fd,0)=0xc7;
  1567. for(i=0;i<MAX_INVENTORY;i++) {
  1568. if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
  1569. if (!itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)))
  1570. continue;
  1571. val=sd->inventory_data[i]->value_sell;
  1572. if (val < 0)
  1573. continue;
  1574. WFIFOW(fd,4+c*10)=i+2;
  1575. WFIFOL(fd,6+c*10)=val;
  1576. if (!sd->inventory_data[i]->flag.value_notoc)
  1577. val=pc_modifysellvalue(sd,val);
  1578. WFIFOL(fd,10+c*10)=val;
  1579. c++;
  1580. }
  1581. }
  1582. WFIFOW(fd,2)=c*10+4;
  1583. WFIFOSET(fd,WFIFOW(fd,2));
  1584. return 0;
  1585. }
  1586. /*==========================================
  1587. *
  1588. *------------------------------------------*/
  1589. int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1590. {
  1591. int fd = sd->fd;
  1592. int slen = strlen(mes) + 9;
  1593. WFIFOHEAD(fd, slen);
  1594. WFIFOW(fd,0)=0xb4;
  1595. WFIFOW(fd,2)=slen;
  1596. WFIFOL(fd,4)=npcid;
  1597. strcpy((char*)WFIFOP(fd,8),mes);
  1598. WFIFOSET(fd,WFIFOW(fd,2));
  1599. return 0;
  1600. }
  1601. /*==========================================
  1602. *
  1603. *------------------------------------------*/
  1604. int clif_scriptnext(struct map_session_data *sd,int npcid)
  1605. {
  1606. int fd;
  1607. nullpo_retr(0, sd);
  1608. fd=sd->fd;
  1609. WFIFOHEAD(fd, packet_len(0xb5));
  1610. WFIFOW(fd,0)=0xb5;
  1611. WFIFOL(fd,2)=npcid;
  1612. WFIFOSET(fd,packet_len(0xb5));
  1613. return 0;
  1614. }
  1615. /*==========================================
  1616. *
  1617. *------------------------------------------*/
  1618. int clif_scriptclose(struct map_session_data *sd, int npcid)
  1619. {
  1620. int fd;
  1621. nullpo_retr(0, sd);
  1622. fd=sd->fd;
  1623. WFIFOHEAD(fd, packet_len(0xb6));
  1624. WFIFOW(fd,0)=0xb6;
  1625. WFIFOL(fd,2)=npcid;
  1626. WFIFOSET(fd,packet_len(0xb6));
  1627. return 0;
  1628. }
  1629. /*==========================================
  1630. *
  1631. *------------------------------------------*/
  1632. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1633. {
  1634. int fd = sd->fd;
  1635. WFIFOHEAD(fd, packet_len(0x78));
  1636. sd->state.using_fake_npc = 1;
  1637. memset(WFIFOP(fd,0), 0, packet_len(0x78));
  1638. WFIFOW(fd,0)=0x78;
  1639. WFIFOL(fd,2)=npcid;
  1640. WFIFOW(fd,14)=111;
  1641. WFIFOPOS(fd,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1642. WFIFOB(fd,49)=5;
  1643. WFIFOB(fd,50)=5;
  1644. WFIFOSET(fd, packet_len(0x78));
  1645. return;
  1646. }
  1647. /*==========================================
  1648. *
  1649. *------------------------------------------*/
  1650. int clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1651. {
  1652. int fd = sd->fd;
  1653. int slen = strlen(mes) + 8;
  1654. struct block_list *bl = NULL;
  1655. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1656. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1657. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1658. clif_sendfakenpc(sd, npcid);
  1659. WFIFOHEAD(fd, slen);
  1660. WFIFOW(fd,0)=0xb7;
  1661. WFIFOW(fd,2)=slen;
  1662. WFIFOL(fd,4)=npcid;
  1663. strcpy((char*)WFIFOP(fd,8),mes);
  1664. WFIFOSET(fd,WFIFOW(fd,2));
  1665. return 0;
  1666. }
  1667. /*==========================================
  1668. *
  1669. *------------------------------------------*/
  1670. int clif_scriptinput(struct map_session_data *sd, int npcid)
  1671. {
  1672. int fd;
  1673. struct block_list *bl = NULL;
  1674. nullpo_retr(0, sd);
  1675. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1676. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1677. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1678. clif_sendfakenpc(sd, npcid);
  1679. fd=sd->fd;
  1680. WFIFOHEAD(fd, packet_len(0x142));
  1681. WFIFOW(fd,0)=0x142;
  1682. WFIFOL(fd,2)=npcid;
  1683. WFIFOSET(fd,packet_len(0x142));
  1684. return 0;
  1685. }
  1686. /*==========================================
  1687. *
  1688. *------------------------------------------*/
  1689. int clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1690. {
  1691. int fd;
  1692. struct block_list *bl = NULL;
  1693. nullpo_retr(0, sd);
  1694. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1695. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1696. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1697. clif_sendfakenpc(sd, npcid);
  1698. fd=sd->fd;
  1699. WFIFOHEAD(fd, packet_len(0x1d4));
  1700. WFIFOW(fd,0)=0x1d4;
  1701. WFIFOL(fd,2)=npcid;
  1702. WFIFOSET(fd,packet_len(0x1d4));
  1703. return 0;
  1704. }
  1705. /// npc_id is ignored in the client
  1706. /// type=2 : Remove viewpoint
  1707. /// type=other : Show viewpoint
  1708. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1709. {
  1710. int fd;
  1711. nullpo_retr(0, sd);
  1712. fd=sd->fd;
  1713. WFIFOHEAD(fd, packet_len(0x144));
  1714. WFIFOW(fd,0)=0x144;
  1715. WFIFOL(fd,2)=npc_id;
  1716. WFIFOL(fd,6)=type;
  1717. WFIFOL(fd,10)=x;
  1718. WFIFOL(fd,14)=y;
  1719. WFIFOB(fd,18)=id;
  1720. WFIFOL(fd,19)=color;
  1721. WFIFOSET(fd,packet_len(0x144));
  1722. return 0;
  1723. }
  1724. /*==========================================
  1725. *
  1726. *------------------------------------------*/
  1727. int clif_cutin(struct map_session_data* sd, const char* image, int type)
  1728. {
  1729. int fd;
  1730. nullpo_retr(0, sd);
  1731. fd=sd->fd;
  1732. WFIFOHEAD(fd, packet_len(0x1b3));
  1733. WFIFOW(fd,0)=0x1b3;
  1734. strncpy((char*)WFIFOP(fd,2),image,64);
  1735. WFIFOB(fd,66)=type;
  1736. WFIFOSET(fd,packet_len(0x1b3));
  1737. return 0;
  1738. }
  1739. /*==========================================
  1740. * Fills in card data from the given item and into the buffer. [Skotlex]
  1741. *------------------------------------------*/
  1742. static void clif_addcards(unsigned char* buf, struct item* item)
  1743. {
  1744. int i=0,j;
  1745. if (item == NULL) { //Blank data
  1746. WBUFW(buf,0)=0;
  1747. WBUFW(buf,2)=0;
  1748. WBUFW(buf,4)=0;
  1749. WBUFW(buf,6)=0;
  1750. return;
  1751. }
  1752. if(item->card[0]==CARD0_PET) { //pet eggs
  1753. WBUFW(buf,0)=0;
  1754. WBUFW(buf,2)=0;
  1755. WBUFW(buf,4)=0;
  1756. WBUFW(buf,6)=item->card[3]; //Pet renamed flag.
  1757. return;
  1758. }
  1759. if(item->card[0]==CARD0_FORGE || item->card[0]==CARD0_CREATE) { //Forged/created items
  1760. WBUFW(buf,0)=item->card[0];
  1761. WBUFW(buf,2)=item->card[1];
  1762. WBUFW(buf,4)=item->card[2];
  1763. WBUFW(buf,6)=item->card[3];
  1764. return;
  1765. }
  1766. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1767. if (MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4)
  1768. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1769. //Normal items.
  1770. if (item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1771. WBUFW(buf,0)=j;
  1772. else
  1773. WBUFW(buf,0)= item->card[i];
  1774. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1775. WBUFW(buf,2)=j;
  1776. else
  1777. WBUFW(buf,2)=item->card[i];
  1778. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1779. WBUFW(buf,4)=j;
  1780. else
  1781. WBUFW(buf,4)=item->card[i];
  1782. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1783. WBUFW(buf,6)=j;
  1784. else
  1785. WBUFW(buf,6)=item->card[i];
  1786. }
  1787. /*==========================================
  1788. *
  1789. *------------------------------------------*/
  1790. int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1791. {
  1792. int fd;
  1793. nullpo_retr(0, sd);
  1794. fd = sd->fd;
  1795. if (!session_isActive(fd)) //Sasuke-
  1796. return 0;
  1797. WFIFOHEAD(fd,packet_len(0xa0));
  1798. if(fail) {
  1799. WFIFOW(fd,0)=0xa0;
  1800. WFIFOW(fd,2)=n+2;
  1801. WFIFOW(fd,4)=amount;
  1802. WFIFOW(fd,6)=0;
  1803. WFIFOB(fd,8)=0;
  1804. WFIFOB(fd,9)=0;
  1805. WFIFOB(fd,10)=0;
  1806. WFIFOW(fd,11)=0;
  1807. WFIFOW(fd,13)=0;
  1808. WFIFOW(fd,15)=0;
  1809. WFIFOW(fd,17)=0;
  1810. WFIFOW(fd,19)=0;
  1811. WFIFOB(fd,21)=0;
  1812. WFIFOB(fd,22)=fail;
  1813. } else {
  1814. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1815. return 1;
  1816. WFIFOW(fd,0)=0xa0;
  1817. WFIFOW(fd,2)=n+2;
  1818. WFIFOW(fd,4)=amount;
  1819. if (sd->inventory_data[n]->view_id > 0)
  1820. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1821. else
  1822. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1823. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1824. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1825. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1826. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1827. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1828. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1829. WFIFOB(fd,22)=fail;
  1830. }
  1831. WFIFOSET(fd,packet_len(0xa0));
  1832. return 0;
  1833. }
  1834. /*==========================================
  1835. *
  1836. *------------------------------------------*/
  1837. int clif_delitem(struct map_session_data *sd,int n,int amount)
  1838. {
  1839. int fd;
  1840. nullpo_retr(0, sd);
  1841. fd=sd->fd;
  1842. WFIFOHEAD(fd, packet_len(0xaf));
  1843. WFIFOW(fd,0)=0xaf;
  1844. WFIFOW(fd,2)=n+2;
  1845. WFIFOW(fd,4)=amount;
  1846. WFIFOSET(fd,packet_len(0xaf));
  1847. return 0;
  1848. }
  1849. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1850. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1851. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1852. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1853. {
  1854. if (id->view_id > 0)
  1855. WBUFW(buf,n)=id->view_id;
  1856. else
  1857. WBUFW(buf,n)=i->nameid;
  1858. WBUFB(buf,n+2)=itemtype(id->type);
  1859. WBUFB(buf,n+3)=i->identify;
  1860. if (equip >= 0) { //Equippable item
  1861. WBUFW(buf,n+4)=equip;
  1862. WBUFW(buf,n+6)=i->equip;
  1863. WBUFB(buf,n+8)=i->attribute;
  1864. WBUFB(buf,n+9)=i->refine;
  1865. } else { //Stackable item.
  1866. WBUFW(buf,n+4)=i->amount;
  1867. if (equip == -2 && id->equip == EQP_AMMO)
  1868. WBUFW(buf,n+6)=EQP_AMMO;
  1869. else
  1870. WBUFW(buf,n+6)=0;
  1871. }
  1872. }
  1873. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1874. void clif_inventorylist(struct map_session_data *sd)
  1875. {
  1876. int i,n,ne,fd = sd->fd,arrow=-1;
  1877. unsigned char *buf;
  1878. unsigned char bufe[MAX_INVENTORY*20+4];
  1879. #if PACKETVER < 5
  1880. const int s = 10; //Entry size.
  1881. #else
  1882. const int s = 18;
  1883. #endif
  1884. WFIFOHEAD(fd, MAX_INVENTORY * s + 4);
  1885. buf = WFIFOP(fd,0);
  1886. for(i=0,n=0,ne=0;i<MAX_INVENTORY;i++){
  1887. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1888. continue;
  1889. if(!itemdb_isstackable2(sd->inventory_data[i]))
  1890. { //Non-stackable (Equippable)
  1891. WBUFW(bufe,ne*20+4)=i+2;
  1892. clif_item_sub(bufe, ne*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1893. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.inventory[i]);
  1894. ne++;
  1895. } else { //Stackable.
  1896. WBUFW(buf,n*s+4)=i+2;
  1897. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1898. if (sd->inventory_data[i]->equip == EQP_AMMO &&
  1899. sd->status.inventory[i].equip)
  1900. arrow=i;
  1901. #if PACKETVER >= 5
  1902. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1903. #endif
  1904. n++;
  1905. }
  1906. }
  1907. if (n) {
  1908. #if PACKETVER < 5
  1909. WBUFW(buf,0)=0xa3;
  1910. #else
  1911. WBUFW(buf,0)=0x1ee;
  1912. #endif
  1913. WBUFW(buf,2)=4+n*s;
  1914. WFIFOSET(fd,WFIFOW(fd,2));
  1915. }
  1916. if(arrow >= 0)
  1917. clif_arrowequip(sd,arrow);
  1918. if(ne){
  1919. WBUFW(bufe,0)=0xa4;
  1920. WBUFW(bufe,2)=4+ne*20;
  1921. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1922. }
  1923. }
  1924. //Required when items break/get-repaired. Only sends equippable item list.
  1925. void clif_equiplist(struct map_session_data *sd)
  1926. {
  1927. int i,n,fd = sd->fd;
  1928. unsigned char *buf;
  1929. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  1930. buf = WFIFOP(fd,0);
  1931. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1932. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1933. continue;
  1934. if(itemdb_isstackable2(sd->inventory_data[i]))
  1935. continue;
  1936. //Equippable
  1937. WBUFW(buf,n*20+4)=i+2;
  1938. clif_item_sub(buf, n*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1939. clif_addcards(WBUFP(buf, n*20+16), &sd->status.inventory[i]);
  1940. n++;
  1941. }
  1942. if (n) {
  1943. WBUFW(buf,0)=0xa4;
  1944. WBUFW(buf,2)=4+n*20;
  1945. WFIFOSET(fd,WFIFOW(fd,2));
  1946. }
  1947. }
  1948. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1949. void clif_storagelist(struct map_session_data *sd,struct storage *stor)
  1950. {
  1951. struct item_data *id;
  1952. int i,n,ne,fd=sd->fd;
  1953. unsigned char *buf;
  1954. unsigned char bufe[MAX_STORAGE*20+4];
  1955. #if PACKETVER < 5
  1956. const int s = 10; //Entry size.
  1957. #else
  1958. const int s = 18;
  1959. #endif
  1960. WFIFOHEAD(fd,MAX_STORAGE * s + 4);
  1961. buf = WFIFOP(fd,0);
  1962. for(i=0,n=0,ne=0;i<MAX_STORAGE;i++){
  1963. if(stor->storage_[i].nameid<=0)
  1964. continue;
  1965. id = itemdb_search(stor->storage_[i].nameid);
  1966. if(!itemdb_isstackable2(id))
  1967. { //Equippable
  1968. WBUFW(bufe,ne*20+4)=i+1;
  1969. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  1970. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  1971. ne++;
  1972. } else { //Stackable
  1973. WBUFW(buf,n*s+4)=i+1;
  1974. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  1975. #if PACKETVER >= 5
  1976. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  1977. #endif
  1978. n++;
  1979. }
  1980. }
  1981. if(n){
  1982. #if PACKETVER < 5
  1983. WBUFW(buf,0)=0xa5;
  1984. #else
  1985. WBUFW(buf,0)=0x1f0;
  1986. #endif
  1987. WBUFW(buf,2)=4+n*s;
  1988. WFIFOSET(fd,WFIFOW(fd,2));
  1989. }
  1990. if(ne){
  1991. WBUFW(bufe,0)=0xa6;
  1992. WBUFW(bufe,2)=4+ne*20;
  1993. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1994. }
  1995. }
  1996. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1997. void clif_guildstoragelist(struct map_session_data *sd,struct guild_storage *stor)
  1998. {
  1999. struct item_data *id;
  2000. int i,n,ne,fd=sd->fd;
  2001. unsigned char *buf;
  2002. unsigned char bufe[MAX_GUILD_STORAGE*20+4];
  2003. #if PACKETVER < 5
  2004. const int s = 10; //Entry size.
  2005. #else
  2006. const int s = 18;
  2007. #endif
  2008. WFIFOHEAD(fd,MAX_GUILD_STORAGE * s + 4);
  2009. buf = WFIFOP(fd,0);
  2010. for(i=0,n=0,ne=0;i<MAX_GUILD_STORAGE;i++){
  2011. if(stor->storage_[i].nameid<=0)
  2012. continue;
  2013. id = itemdb_search(stor->storage_[i].nameid);
  2014. if(!itemdb_isstackable2(id))
  2015. { //Equippable
  2016. WBUFW(bufe,ne*20+4)=i+1;
  2017. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  2018. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  2019. ne++;
  2020. } else { //Stackable
  2021. WBUFW(buf,n*s+4)=i+1;
  2022. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  2023. #if PACKETVER >= 5
  2024. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  2025. #endif
  2026. n++;
  2027. }
  2028. }
  2029. if(n){
  2030. #if PACKETVER < 5
  2031. WBUFW(buf,0)=0xa5;
  2032. #else
  2033. WBUFW(buf,0)=0x1f0;
  2034. #endif
  2035. WBUFW(buf,2)=4+n*s;
  2036. WFIFOSET(fd,WFIFOW(fd,2));
  2037. }
  2038. if(ne){
  2039. WBUFW(bufe,0)=0xa6;
  2040. WBUFW(bufe,2)=4+ne*20;
  2041. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2042. }
  2043. }
  2044. void clif_cartlist(struct map_session_data *sd)
  2045. {
  2046. struct item_data *id;
  2047. int i,n,ne,fd=sd->fd;
  2048. unsigned char *buf;
  2049. unsigned char bufe[MAX_CART*20+4];
  2050. #if PACKETVER < 5
  2051. const int s = 10; //Entry size.
  2052. #else
  2053. const int s = 18;
  2054. #endif
  2055. WFIFOHEAD(fd, MAX_CART * s + 4);
  2056. buf = WFIFOP(fd,0);
  2057. for(i=0,n=0,ne=0;i<MAX_CART;i++){
  2058. if(sd->status.cart[i].nameid<=0)
  2059. continue;
  2060. id = itemdb_search(sd->status.cart[i].nameid);
  2061. if(!itemdb_isstackable2(id))
  2062. { //Equippable
  2063. WBUFW(bufe,ne*20+4)=i+2;
  2064. clif_item_sub(bufe, ne*20+6, &sd->status.cart[i], id, id->equip);
  2065. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.cart[i]);
  2066. ne++;
  2067. } else { //Stackable
  2068. WBUFW(buf,n*s+4)=i+2;
  2069. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  2070. #if PACKETVER >= 5
  2071. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  2072. #endif
  2073. n++;
  2074. }
  2075. }
  2076. if(n){
  2077. #if PACKETVER < 5
  2078. WBUFW(buf,0)=0x123;
  2079. #else
  2080. WBUFW(buf,0)=0x1ef;
  2081. #endif
  2082. WBUFW(buf,2)=4+n*s;
  2083. WFIFOSET(fd,WFIFOW(fd,2));
  2084. }
  2085. if(ne){
  2086. WBUFW(bufe,0)=0x122;
  2087. WBUFW(bufe,2)=4+ne*20;
  2088. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2089. }
  2090. return;
  2091. }
  2092. /// Client behaviour:
  2093. /// Closes the cart storage and removes all it's items from memory.
  2094. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2095. void clif_clearcart(int fd)
  2096. {
  2097. WFIFOHEAD(fd, packet_len(0x12b));
  2098. WFIFOW(fd,0) = 0x12b;
  2099. }
  2100. // Guild XY locators [Valaris]
  2101. int clif_guild_xy(struct map_session_data *sd)
  2102. {
  2103. unsigned char buf[10];
  2104. nullpo_retr(0, sd);
  2105. WBUFW(buf,0)=0x1eb;
  2106. WBUFL(buf,2)=sd->status.account_id;
  2107. WBUFW(buf,6)=sd->bl.x;
  2108. WBUFW(buf,8)=sd->bl.y;
  2109. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2110. return 0;
  2111. }
  2112. /*==========================================
  2113. * Sends x/y dot to a single fd. [Skotlex]
  2114. *------------------------------------------*/
  2115. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  2116. {
  2117. WFIFOHEAD(fd,packet_len(0x1eb));
  2118. WFIFOW(fd,0)=0x1eb;
  2119. WFIFOL(fd,2)=sd->status.account_id;
  2120. WFIFOW(fd,6)=sd->bl.x;
  2121. WFIFOW(fd,8)=sd->bl.y;
  2122. WFIFOSET(fd,packet_len(0x1eb));
  2123. return 0;
  2124. }
  2125. // Guild XY locators [Valaris]
  2126. int clif_guild_xy_remove(struct map_session_data *sd)
  2127. {
  2128. unsigned char buf[10];
  2129. nullpo_retr(0, sd);
  2130. WBUFW(buf,0)=0x1eb;
  2131. WBUFL(buf,2)=sd->status.account_id;
  2132. WBUFW(buf,6)=-1;
  2133. WBUFW(buf,8)=-1;
  2134. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2135. return 0;
  2136. }
  2137. /*==========================================
  2138. * ステータスを送りつける
  2139. * 表示専用数字はこの中で計算して送る
  2140. *------------------------------------------*/
  2141. int clif_updatestatus(struct map_session_data *sd,int type)
  2142. {
  2143. int fd,len=8;
  2144. nullpo_retr(0, sd);
  2145. fd=sd->fd;
  2146. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2147. return 0;
  2148. WFIFOHEAD(fd, 14);
  2149. WFIFOW(fd,0)=0xb0;
  2150. WFIFOW(fd,2)=type;
  2151. switch(type){
  2152. // 00b0
  2153. case SP_WEIGHT:
  2154. pc_updateweightstatus(sd);
  2155. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2156. WFIFOW(fd,2)=type;
  2157. WFIFOL(fd,4)=sd->weight;
  2158. break;
  2159. case SP_MAXWEIGHT:
  2160. WFIFOL(fd,4)=sd->max_weight;
  2161. break;
  2162. case SP_SPEED:
  2163. WFIFOL(fd,4)=sd->battle_status.speed;
  2164. break;
  2165. case SP_BASELEVEL:
  2166. WFIFOL(fd,4)=sd->status.base_level;
  2167. break;
  2168. case SP_JOBLEVEL:
  2169. WFIFOL(fd,4)=sd->status.job_level;
  2170. break;
  2171. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2172. WFIFOL(fd,4)=sd->status.karma;
  2173. break;
  2174. case SP_MANNER:
  2175. WFIFOL(fd,4)=sd->status.manner;
  2176. clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
  2177. break;
  2178. case SP_STATUSPOINT:
  2179. WFIFOL(fd,4)=sd->status.status_point;
  2180. break;
  2181. case SP_SKILLPOINT:
  2182. WFIFOL(fd,4)=sd->status.skill_point;
  2183. break;
  2184. case SP_HIT:
  2185. WFIFOL(fd,4)=sd->battle_status.hit;
  2186. break;
  2187. case SP_FLEE1:
  2188. WFIFOL(fd,4)=sd->battle_status.flee;
  2189. break;
  2190. case SP_FLEE2:
  2191. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2192. break;
  2193. case SP_MAXHP:
  2194. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2195. break;
  2196. case SP_MAXSP:
  2197. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2198. break;
  2199. case SP_HP:
  2200. WFIFOL(fd,4)=sd->battle_status.hp;
  2201. if (battle_config.disp_hpmeter)
  2202. clif_hpmeter(sd);
  2203. if (!battle_config.party_hp_mode && sd->status.party_id)
  2204. clif_party_hp(sd);
  2205. break;
  2206. case SP_SP:
  2207. WFIFOL(fd,4)=sd->battle_status.sp;
  2208. break;
  2209. case SP_ASPD:
  2210. WFIFOL(fd,4)=sd->battle_status.amotion;
  2211. break;
  2212. case SP_ATK1:
  2213. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw->atk;
  2214. break;
  2215. case SP_DEF1:
  2216. WFIFOL(fd,4)=sd->battle_status.def;
  2217. break;
  2218. case SP_MDEF1:
  2219. WFIFOL(fd,4)=sd->battle_status.mdef;
  2220. break;
  2221. case SP_ATK2:
  2222. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw->atk2;
  2223. break;
  2224. case SP_DEF2:
  2225. WFIFOL(fd,4)=sd->battle_status.def2;
  2226. break;
  2227. case SP_MDEF2:
  2228. //negative check (in case you have something like Berserk active)
  2229. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2230. if (len < 0) len = 0;
  2231. WFIFOL(fd,4)= len;
  2232. len = 8;
  2233. break;
  2234. case SP_CRITICAL:
  2235. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2236. break;
  2237. case SP_MATK1:
  2238. WFIFOL(fd,4)=sd->battle_status.matk_max;
  2239. break;
  2240. case SP_MATK2:
  2241. WFIFOL(fd,4)=sd->battle_status.matk_min;
  2242. break;
  2243. case SP_ZENY:
  2244. WFIFOW(fd,0)=0xb1;
  2245. WFIFOL(fd,4)=sd->status.zeny;
  2246. break;
  2247. case SP_BASEEXP:
  2248. WFIFOW(fd,0)=0xb1;
  2249. WFIFOL(fd,4)=sd->status.base_exp;
  2250. break;
  2251. case SP_JOBEXP:
  2252. WFIFOW(fd,0)=0xb1;
  2253. WFIFOL(fd,4)=sd->status.job_exp;
  2254. break;
  2255. case SP_NEXTBASEEXP:
  2256. WFIFOW(fd,0)=0xb1;
  2257. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2258. break;
  2259. case SP_NEXTJOBEXP:
  2260. WFIFOW(fd,0)=0xb1;
  2261. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2262. break;
  2263. // 00be 終了
  2264. case SP_USTR:
  2265. case SP_UAGI:
  2266. case SP_UVIT:
  2267. case SP_UINT:
  2268. case SP_UDEX:
  2269. case SP_ULUK:
  2270. WFIFOW(fd,0)=0xbe;
  2271. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2272. len=5;
  2273. break;
  2274. // 013a 終了
  2275. case SP_ATTACKRANGE:
  2276. WFIFOW(fd,0)=0x13a;
  2277. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2278. len=4;
  2279. break;
  2280. // 0141 終了
  2281. case SP_STR:
  2282. WFIFOW(fd,0)=0x141;
  2283. WFIFOL(fd,2)=type;
  2284. WFIFOL(fd,6)=sd->status.str;
  2285. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2286. len=14;
  2287. break;
  2288. case SP_AGI:
  2289. WFIFOW(fd,0)=0x141;
  2290. WFIFOL(fd,2)=type;
  2291. WFIFOL(fd,6)=sd->status.agi;
  2292. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2293. len=14;
  2294. break;
  2295. case SP_VIT:
  2296. WFIFOW(fd,0)=0x141;
  2297. WFIFOL(fd,2)=type;
  2298. WFIFOL(fd,6)=sd->status.vit;
  2299. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2300. len=14;
  2301. break;
  2302. case SP_INT:
  2303. WFIFOW(fd,0)=0x141;
  2304. WFIFOL(fd,2)=type;
  2305. WFIFOL(fd,6)=sd->status.int_;
  2306. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2307. len=14;
  2308. break;
  2309. case SP_DEX:
  2310. WFIFOW(fd,0)=0x141;
  2311. WFIFOL(fd,2)=type;
  2312. WFIFOL(fd,6)=sd->status.dex;
  2313. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2314. len=14;
  2315. break;
  2316. case SP_LUK:
  2317. WFIFOW(fd,0)=0x141;
  2318. WFIFOL(fd,2)=type;
  2319. WFIFOL(fd,6)=sd->status.luk;
  2320. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2321. len=14;
  2322. break;
  2323. case SP_CARTINFO:
  2324. WFIFOW(fd,0)=0x121;
  2325. WFIFOW(fd,2)=sd->cart_num;
  2326. WFIFOW(fd,4)=MAX_CART;
  2327. WFIFOL(fd,6)=sd->cart_weight;
  2328. WFIFOL(fd,10)=battle_config.max_cart_weight;
  2329. len=14;
  2330. break;
  2331. default:
  2332. if(battle_config.error_log)
  2333. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2334. return 1;
  2335. }
  2336. WFIFOSET(fd,len);
  2337. return 0;
  2338. }
  2339. int clif_changestatus(struct block_list *bl,int type,int val)
  2340. {
  2341. unsigned char buf[12];
  2342. struct map_session_data *sd = NULL;
  2343. nullpo_retr(0, bl);
  2344. if(bl->type == BL_PC)
  2345. sd = (struct map_session_data *)bl;
  2346. if(sd){
  2347. WBUFW(buf,0)=0x1ab;
  2348. WBUFL(buf,2)=bl->id;
  2349. WBUFW(buf,6)=type;
  2350. switch(type){
  2351. case SP_MANNER:
  2352. WBUFL(buf,8)=val;
  2353. break;
  2354. default:
  2355. if(battle_config.error_log)
  2356. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2357. return 1;
  2358. }
  2359. clif_send(buf,packet_len(0x1ab),bl,AREA_WOS);
  2360. }
  2361. return 0;
  2362. }
  2363. /*==========================================
  2364. *
  2365. *------------------------------------------*/
  2366. int clif_changelook(struct block_list *bl,int type,int val)
  2367. {
  2368. unsigned char buf[32];
  2369. struct map_session_data *sd = NULL;
  2370. struct view_data *vd;
  2371. vd = status_get_viewdata(bl);
  2372. nullpo_retr(0, vd);
  2373. BL_CAST(BL_PC, bl, sd);
  2374. switch(type) {
  2375. case LOOK_WEAPON:
  2376. if (sd)
  2377. {
  2378. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2379. val = vd->weapon;
  2380. }
  2381. else vd->weapon = val;
  2382. break;
  2383. case LOOK_SHIELD:
  2384. if (sd)
  2385. {
  2386. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2387. val = vd->shield;
  2388. }
  2389. else vd->shield = val;
  2390. break;
  2391. case LOOK_BASE:
  2392. vd->class_ = val;
  2393. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS)
  2394. vd->weapon = vd->shield = 0;
  2395. if (vd->cloth_color && (
  2396. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2397. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette)
  2398. ))
  2399. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2400. break;
  2401. case LOOK_HAIR:
  2402. vd->hair_style = val;
  2403. break;
  2404. case LOOK_HEAD_BOTTOM:
  2405. vd->head_bottom = val;
  2406. break;
  2407. case LOOK_HEAD_TOP:
  2408. vd->head_top = val;
  2409. break;
  2410. case LOOK_HEAD_MID:
  2411. vd->head_mid = val;
  2412. break;
  2413. case LOOK_HAIR_COLOR:
  2414. vd->hair_color = val;
  2415. break;
  2416. case LOOK_CLOTHES_COLOR:
  2417. if (val && (
  2418. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2419. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette)
  2420. ))
  2421. val = 0;
  2422. vd->cloth_color = val;
  2423. break;
  2424. case LOOK_SHOES:
  2425. #if PACKETVER > 3
  2426. if (sd) {
  2427. int n;
  2428. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2429. if(sd->inventory_data[n]->view_id > 0)
  2430. val = sd->inventory_data[n]->view_id;
  2431. else
  2432. val = sd->status.inventory[n].nameid;
  2433. }
  2434. val = 0;
  2435. }
  2436. #endif
  2437. //Shoes? No packet uses this....
  2438. break;
  2439. }
  2440. #if PACKETVER < 4
  2441. WBUFW(buf,0)=0xc3;
  2442. WBUFL(buf,2)=bl->id;
  2443. WBUFB(buf,6)=type;
  2444. WBUFB(buf,7)=val;
  2445. clif_send(buf,packet_len(0xc3),bl,AREA);
  2446. #else
  2447. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2448. WBUFW(buf,0)=0x1d7;
  2449. WBUFL(buf,2)=bl->id;
  2450. WBUFB(buf,6)=LOOK_WEAPON;
  2451. WBUFW(buf,7)=vd->weapon;
  2452. WBUFW(buf,9)=vd->shield;
  2453. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2454. }
  2455. else
  2456. {
  2457. WBUFW(buf,0)=0x1d7;
  2458. WBUFL(buf,2)=bl->id;
  2459. WBUFB(buf,6)=type;
  2460. WBUFW(buf,7)=val;
  2461. WBUFW(buf,9)=0;
  2462. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2463. }
  2464. #endif
  2465. return 0;
  2466. }
  2467. //Sends a change-base-look packet required for traps as they are triggered.
  2468. void clif_changetraplook(struct block_list *bl,int val)
  2469. {
  2470. unsigned char buf[32];
  2471. #if PACKETVER < 4
  2472. WBUFW(buf,0)=0xc3;
  2473. WBUFL(buf,2)=bl->id;
  2474. WBUFB(buf,6)=LOOK_BASE;
  2475. WBUFB(buf,7)=val;
  2476. clif_send(buf,packet_len(0xc3),bl,AREA);
  2477. #else
  2478. WBUFW(buf,0)=0x1d7;
  2479. WBUFL(buf,2)=bl->id;
  2480. WBUFB(buf,6)=LOOK_BASE;
  2481. WBUFW(buf,7)=val;
  2482. WBUFW(buf,9)=0;
  2483. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2484. #endif
  2485. }
  2486. //For the stupid cloth-dye bug. Resends the given view data
  2487. //to the area specified by bl.
  2488. void clif_refreshlook(struct block_list *bl,int id,int type,int val,int area)
  2489. {
  2490. unsigned char buf[32];
  2491. #if PACKETVER < 4
  2492. WBUFW(buf,0)=0xc3;
  2493. WBUFL(buf,2)=id;
  2494. WBUFB(buf,6)=type;
  2495. WBUFB(buf,7)=val;
  2496. clif_send(buf,packet_len(0xc3),bl,area);
  2497. #else
  2498. WBUFW(buf,0)=0x1d7;
  2499. WBUFL(buf,2)=id;
  2500. WBUFB(buf,6)=type;
  2501. WBUFW(buf,7)=val;
  2502. WBUFW(buf,9)=0;
  2503. clif_send(buf,packet_len(0x1d7),bl,area);
  2504. #endif
  2505. return;
  2506. }
  2507. /*==========================================
  2508. *
  2509. *------------------------------------------*/
  2510. int clif_initialstatus(struct map_session_data *sd)
  2511. {
  2512. int fd;
  2513. unsigned char *buf;
  2514. nullpo_retr(0, sd);
  2515. fd=sd->fd;
  2516. WFIFOHEAD(fd,packet_len(0xbd));
  2517. buf=WFIFOP(fd,0);
  2518. WBUFW(buf,0)=0xbd;
  2519. WBUFW(buf,2)=(sd->status.status_point > SHRT_MAX)? SHRT_MAX:sd->status.status_point;
  2520. WBUFB(buf,4)=(sd->status.str > UCHAR_MAX)? UCHAR_MAX:sd->status.str;
  2521. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2522. WBUFB(buf,6)=(sd->status.agi > UCHAR_MAX)? UCHAR_MAX:sd->status.agi;
  2523. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2524. WBUFB(buf,8)=(sd->status.vit > UCHAR_MAX)? UCHAR_MAX:sd->status.vit;
  2525. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2526. WBUFB(buf,10)=(sd->status.int_ > UCHAR_MAX)? UCHAR_MAX:sd->status.int_;
  2527. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2528. WBUFB(buf,12)=(sd->status.dex > UCHAR_MAX)? UCHAR_MAX:sd->status.dex;
  2529. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2530. WBUFB(buf,14)=(sd->status.luk > UCHAR_MAX)? UCHAR_MAX:sd->status.luk;
  2531. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2532. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw->atk;
  2533. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw->atk2; //atk bonus
  2534. WBUFW(buf,20) = sd->battle_status.matk_max;
  2535. WBUFW(buf,22) = sd->battle_status.matk_min;
  2536. WBUFW(buf,24) = sd->battle_status.def; // def
  2537. WBUFW(buf,26) = sd->battle_status.def2;
  2538. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2539. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2540. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2541. WBUFW(buf,30) = fd;
  2542. fd = sd->fd;
  2543. WBUFW(buf,32) = sd->battle_status.hit;
  2544. WBUFW(buf,34) = sd->battle_status.flee;
  2545. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2546. WBUFW(buf,38) = sd->battle_status.cri/10;
  2547. WBUFW(buf,40) = sd->status.karma;
  2548. WBUFW(buf,42) = sd->status.manner;
  2549. WFIFOSET(fd,packet_len(0xbd));
  2550. clif_updatestatus(sd,SP_STR);
  2551. clif_updatestatus(sd,SP_AGI);
  2552. clif_updatestatus(sd,SP_VIT);
  2553. clif_updatestatus(sd,SP_INT);
  2554. clif_updatestatus(sd,SP_DEX);
  2555. clif_updatestatus(sd,SP_LUK);
  2556. clif_updatestatus(sd,SP_ATTACKRANGE);
  2557. clif_updatestatus(sd,SP_ASPD);
  2558. return 0;
  2559. }
  2560. /*==========================================
  2561. *矢装備
  2562. *------------------------------------------*/
  2563. int clif_arrowequip(struct map_session_data *sd,int val)
  2564. {
  2565. int fd;
  2566. nullpo_retr(0, sd);
  2567. pc_stop_attack(sd); // [Valaris]
  2568. fd=sd->fd;
  2569. WFIFOHEAD(fd, packet_len(0x013c));
  2570. WFIFOW(fd,0)=0x013c;
  2571. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2572. WFIFOSET(fd,packet_len(0x013c));
  2573. return 0;
  2574. }
  2575. /// Ammunition action message.
  2576. /// type=0 : MsgStringTable[242]="Please equip the proper ammunition first."
  2577. /// type=1 : MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2578. /// type=2 : MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2579. /// type=3 : assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2580. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2581. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2582. int clif_arrow_fail(struct map_session_data *sd,int type)
  2583. {
  2584. int fd;
  2585. nullpo_retr(0, sd);
  2586. fd=sd->fd;
  2587. WFIFOHEAD(fd, packet_len(0x013b));
  2588. WFIFOW(fd,0)=0x013b;
  2589. WFIFOW(fd,2)=type;
  2590. WFIFOSET(fd,packet_len(0x013b));
  2591. return 0;
  2592. }
  2593. /*==========================================
  2594. * 作成可能 矢リスト送信
  2595. *------------------------------------------*/
  2596. int clif_arrow_create_list(struct map_session_data *sd)
  2597. {
  2598. int i, c, j;
  2599. int fd;
  2600. nullpo_retr(0, sd);
  2601. fd = sd->fd;
  2602. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2603. WFIFOW(fd,0) = 0x1ad;
  2604. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2605. if (skill_arrow_db[i].nameid > 0 &&
  2606. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2607. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2608. {
  2609. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2610. WFIFOW(fd,c*2+4) = j;
  2611. else
  2612. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2613. c++;
  2614. }
  2615. }
  2616. WFIFOW(fd,2) = c*2+4;
  2617. WFIFOSET(fd, WFIFOW(fd,2));
  2618. if (c > 0) {
  2619. sd->menuskill_id = AC_MAKINGARROW;
  2620. sd->menuskill_lv = c;
  2621. }
  2622. return 0;
  2623. }
  2624. /*==========================================
  2625. *
  2626. *------------------------------------------*/
  2627. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2628. {
  2629. int fd;
  2630. nullpo_retr(0, sd);
  2631. fd=sd->fd;
  2632. WFIFOHEAD(fd,packet_len(0xbc));
  2633. WFIFOW(fd,0)=0xbc;
  2634. WFIFOW(fd,2)=type;
  2635. WFIFOB(fd,4)=ok;
  2636. WFIFOB(fd,5)=val;
  2637. WFIFOSET(fd,packet_len(0xbc));
  2638. return 0;
  2639. }
  2640. /*==========================================
  2641. *
  2642. *------------------------------------------*/
  2643. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2644. {
  2645. int fd;
  2646. nullpo_retr(0, sd);
  2647. fd=sd->fd;
  2648. WFIFOHEAD(fd,packet_len(0xaa));
  2649. WFIFOW(fd,0)=0xaa;
  2650. WFIFOW(fd,2)=n+2;
  2651. WFIFOW(fd,4)=pos;
  2652. WFIFOB(fd,6)=ok;
  2653. WFIFOSET(fd,packet_len(0xaa));
  2654. return 0;
  2655. }
  2656. /*==========================================
  2657. *
  2658. *------------------------------------------*/
  2659. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2660. {
  2661. int fd;
  2662. nullpo_retr(0, sd);
  2663. fd=sd->fd;
  2664. WFIFOHEAD(fd,packet_len(0xac));
  2665. WFIFOW(fd,0)=0xac;
  2666. WFIFOW(fd,2)=n+2;
  2667. WFIFOW(fd,4)=pos;
  2668. WFIFOB(fd,6)=ok;
  2669. WFIFOSET(fd,packet_len(0xac));
  2670. return 0;
  2671. }
  2672. /*==========================================
  2673. *
  2674. *------------------------------------------*/
  2675. int clif_misceffect(struct block_list* bl,int type)
  2676. {
  2677. unsigned char buf[32];
  2678. nullpo_retr(0, bl);
  2679. WBUFW(buf,0) = 0x19b;
  2680. WBUFL(buf,2) = bl->id;
  2681. WBUFL(buf,6) = type;
  2682. clif_send(buf,packet_len(0x19b),bl,AREA);
  2683. return 0;
  2684. }
  2685. int clif_misceffect2(struct block_list *bl, int type)
  2686. {
  2687. unsigned char buf[24];
  2688. nullpo_retr(0, bl);
  2689. memset(buf, 0, packet_len(0x1f3));
  2690. WBUFW(buf,0) = 0x1f3;
  2691. WBUFL(buf,2) = bl->id;
  2692. WBUFL(buf,6) = type;
  2693. clif_send(buf, packet_len(0x1f3), bl, AREA);
  2694. return 0;
  2695. }
  2696. /*==========================================
  2697. * 表示オプション変更
  2698. *------------------------------------------*/
  2699. int clif_changeoption(struct block_list* bl)
  2700. {
  2701. unsigned char buf[32];
  2702. struct status_change *sc;
  2703. nullpo_retr(0, bl);
  2704. sc = status_get_sc(bl);
  2705. if (!sc) return 0; //How can an option change if there's no sc?
  2706. #if PACKETVER > 6
  2707. WBUFW(buf,0) = 0x229;
  2708. WBUFL(buf,2) = bl->id;
  2709. WBUFW(buf,6) = sc->opt1;
  2710. WBUFW(buf,8) = sc->opt2;
  2711. WBUFL(buf,10) = sc->option;
  2712. WBUFB(buf,14) = 0; // PK???
  2713. if(disguised(bl)) {
  2714. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2715. WBUFL(buf,2) = -bl->id;
  2716. clif_send(buf,packet_len(0x229),bl,SELF);
  2717. WBUFL(buf,2) = bl->id;
  2718. WBUFL(buf,10) = OPTION_INVISIBLE;
  2719. clif_send(buf,packet_len(0x229),bl,SELF);
  2720. } else
  2721. clif_send(buf,packet_len(0x229),bl,AREA);
  2722. #else
  2723. WBUFW(buf,0) = 0x119;
  2724. WBUFL(buf,2) = bl->id;
  2725. WBUFW(buf,6) = sc->opt1;
  2726. WBUFW(buf,8) = sc->opt2;
  2727. WBUFW(buf,10) = sc->option;
  2728. WBUFB(buf,12) = 0; // ??
  2729. if(disguised(bl)) {
  2730. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2731. WBUFL(buf,2) = -bl->id;
  2732. clif_send(buf,packet_len(0x119),bl,SELF);
  2733. WBUFL(buf,2) = bl->id;
  2734. WBUFW(buf,10) = OPTION_INVISIBLE;
  2735. clif_send(buf,packet_len(0x119),bl,SELF);
  2736. } else
  2737. clif_send(buf,packet_len(0x119),bl,AREA);
  2738. #endif
  2739. return 0;
  2740. }
  2741. int clif_changeoption2(struct block_list* bl)
  2742. {
  2743. unsigned char buf[20];
  2744. struct status_change *sc;
  2745. sc = status_get_sc(bl);
  2746. if (!sc) return 0; //How can an option change if there's no sc?
  2747. WBUFW(buf,0) = 0x28a;
  2748. WBUFL(buf,2) = bl->id;
  2749. WBUFL(buf,6) = sc->option;
  2750. WBUFL(buf,10) = clif_setlevel(status_get_lv(bl));
  2751. WBUFL(buf,14) = sc->opt3;
  2752. if(disguised(bl)) {
  2753. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  2754. WBUFL(buf,2) = -bl->id;
  2755. clif_send(buf,packet_len(0x28a),bl,SELF);
  2756. WBUFL(buf,2) = bl->id;
  2757. WBUFL(buf,6) = OPTION_INVISIBLE;
  2758. clif_send(buf,packet_len(0x28a),bl,SELF);
  2759. } else
  2760. clif_send(buf,packet_len(0x28a),bl,AREA);
  2761. return 0;
  2762. }
  2763. /*==========================================
  2764. *
  2765. *------------------------------------------*/
  2766. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2767. {
  2768. nullpo_retr(0, sd);
  2769. if(!ok) {
  2770. int fd=sd->fd;
  2771. WFIFOHEAD(fd,packet_len(0xa8));
  2772. WFIFOW(fd,0)=0xa8;
  2773. WFIFOW(fd,2)=index+2;
  2774. WFIFOW(fd,4)=amount;
  2775. WFIFOB(fd,6)=ok;
  2776. WFIFOSET(fd,packet_len(0xa8));
  2777. }
  2778. else {
  2779. #if PACKETVER < 3
  2780. int fd=sd->fd;
  2781. WFIFOHEAD(fd,packet_len(0xa8));
  2782. WFIFOW(fd,0)=0xa8;
  2783. WFIFOW(fd,2)=index+2;
  2784. WFIFOW(fd,4)=amount;
  2785. WFIFOB(fd,6)=ok;
  2786. WFIFOSET(fd,packet_len(0xa8));
  2787. #else
  2788. unsigned char buf[32];
  2789. WBUFW(buf,0)=0x1c8;
  2790. WBUFW(buf,2)=index+2;
  2791. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2792. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2793. else
  2794. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2795. WBUFL(buf,6)=sd->bl.id;
  2796. WBUFW(buf,10)=amount;
  2797. WBUFB(buf,12)=ok;
  2798. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2799. #endif
  2800. }
  2801. return 0;
  2802. }
  2803. /*==========================================
  2804. *
  2805. *------------------------------------------*/
  2806. int clif_createchat(struct map_session_data *sd,int fail)
  2807. {
  2808. int fd;
  2809. nullpo_retr(0, sd);
  2810. fd=sd->fd;
  2811. WFIFOHEAD(fd,packet_len(0xd6));
  2812. WFIFOW(fd,0)=0xd6;
  2813. WFIFOB(fd,2)=fail;
  2814. WFIFOSET(fd,packet_len(0xd6));
  2815. return 0;
  2816. }
  2817. /*==========================================
  2818. *
  2819. *------------------------------------------*/
  2820. int clif_dispchat(struct chat_data *cd,int fd)
  2821. {
  2822. unsigned char buf[128]; // 最大title(60バイト)+17
  2823. if(cd==NULL || *cd->owner==NULL)
  2824. return 1;
  2825. WBUFW(buf,0)=0xd7;
  2826. WBUFW(buf,2)=strlen((const char*)cd->title)+17;
  2827. WBUFL(buf,4)=(*cd->owner)->id;
  2828. WBUFL(buf,8)=cd->bl.id;
  2829. WBUFW(buf,12)=cd->limit;
  2830. WBUFW(buf,14)=cd->users;
  2831. WBUFB(buf,16)=cd->pub;
  2832. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  2833. if(fd){
  2834. WFIFOHEAD(fd, WBUFW(buf,2));
  2835. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2836. WFIFOSET(fd,WBUFW(buf,2));
  2837. } else {
  2838. clif_send(buf,WBUFW(buf,2),*cd->owner,AREA_WOSC);
  2839. }
  2840. return 0;
  2841. }
  2842. /*==========================================
  2843. * chatの状態変更成功
  2844. * 外部の人用と命令コード(d7->df)が違うだけ
  2845. *------------------------------------------*/
  2846. int clif_changechatstatus(struct chat_data *cd)
  2847. {
  2848. unsigned char buf[128]; // 最大title(60バイト)+17
  2849. if(cd==NULL || cd->usersd[0]==NULL)
  2850. return 1;
  2851. WBUFW(buf,0)=0xdf;
  2852. WBUFW(buf,2)=strlen((char*)cd->title)+17;
  2853. WBUFL(buf,4)=cd->usersd[0]->bl.id;
  2854. WBUFL(buf,8)=cd->bl.id;
  2855. WBUFW(buf,12)=cd->limit;
  2856. WBUFW(buf,14)=cd->users;
  2857. WBUFB(buf,16)=cd->pub;
  2858. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  2859. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2860. return 0;
  2861. }
  2862. /*==========================================
  2863. *
  2864. *------------------------------------------*/
  2865. int clif_clearchat(struct chat_data *cd,int fd)
  2866. {
  2867. unsigned char buf[32];
  2868. nullpo_retr(0, cd);
  2869. WBUFW(buf,0)=0xd8;
  2870. WBUFL(buf,2)=cd->bl.id;
  2871. if(fd){
  2872. WFIFOHEAD(fd,packet_len(0xd8));
  2873. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2874. WFIFOSET(fd,packet_len(0xd8));
  2875. } else {
  2876. clif_send(buf,packet_len(0xd8),*cd->owner,AREA_WOSC);
  2877. }
  2878. return 0;
  2879. }
  2880. /*==========================================
  2881. *
  2882. *------------------------------------------*/
  2883. int clif_joinchatfail(struct map_session_data *sd,int fail)
  2884. {
  2885. int fd;
  2886. nullpo_retr(0, sd);
  2887. fd=sd->fd;
  2888. WFIFOHEAD(fd,packet_len(0xda));
  2889. WFIFOW(fd,0)=0xda;
  2890. WFIFOB(fd,2)=fail;
  2891. WFIFOSET(fd,packet_len(0xda));
  2892. return 0;
  2893. }
  2894. /*==========================================
  2895. *
  2896. *------------------------------------------*/
  2897. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2898. {
  2899. int fd;
  2900. int i;
  2901. nullpo_retr(0, sd);
  2902. nullpo_retr(0, cd);
  2903. fd = sd->fd;
  2904. if (!session_isActive(fd))
  2905. return 0;
  2906. WFIFOHEAD(fd, 8 + (28*cd->users));
  2907. WFIFOW(fd, 0) = 0xdb;
  2908. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2909. WFIFOL(fd, 4) = cd->bl.id;
  2910. for (i = 0; i < cd->users; i++) {
  2911. WFIFOL(fd, 8+i*28) = (i!=0) || ((*cd->owner)->type == BL_NPC);
  2912. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2913. }
  2914. WFIFOSET(fd, WFIFOW(fd, 2));
  2915. return 0;
  2916. }
  2917. /*==========================================
  2918. *
  2919. *------------------------------------------*/
  2920. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2921. {
  2922. unsigned char buf[32];
  2923. nullpo_retr(0, sd);
  2924. nullpo_retr(0, cd);
  2925. WBUFW(buf, 0) = 0x0dc;
  2926. WBUFW(buf, 2) = cd->users;
  2927. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2928. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  2929. return 0;
  2930. }
  2931. /*==========================================
  2932. *
  2933. *------------------------------------------*/
  2934. int clif_changechatowner(struct chat_data* cd,struct map_session_data *sd)
  2935. {
  2936. unsigned char buf[64];
  2937. nullpo_retr(0, sd);
  2938. nullpo_retr(0, cd);
  2939. WBUFW(buf, 0) = 0xe1;
  2940. WBUFL(buf, 2) = 1;
  2941. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2942. WBUFW(buf,30) = 0xe1;
  2943. WBUFL(buf,32) = 0;
  2944. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2945. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  2946. return 0;
  2947. }
  2948. /*==========================================
  2949. *
  2950. *------------------------------------------*/
  2951. int clif_leavechat(struct chat_data* cd,struct map_session_data *sd)
  2952. {
  2953. unsigned char buf[32];
  2954. nullpo_retr(0, sd);
  2955. nullpo_retr(0, cd);
  2956. WBUFW(buf, 0) = 0xdd;
  2957. WBUFW(buf, 2) = cd->users-1;
  2958. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2959. WBUFB(buf,28) = 0;
  2960. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  2961. return 0;
  2962. }
  2963. /*==========================================
  2964. * 取り引き要請受け
  2965. *------------------------------------------*/
  2966. int clif_traderequest(struct map_session_data* sd, const char* name)
  2967. {
  2968. int fd;
  2969. nullpo_retr(0, sd);
  2970. fd=sd->fd;
  2971. WFIFOHEAD(fd,packet_len(0xe5));
  2972. WFIFOW(fd,0)=0xe5;
  2973. strcpy((char*)WFIFOP(fd,2),name);
  2974. WFIFOSET(fd,packet_len(0xe5));
  2975. return 0;
  2976. }
  2977. /*==========================================
  2978. * 取り引き要求応答
  2979. *------------------------------------------*/
  2980. int clif_tradestart(struct map_session_data *sd,int type)
  2981. {
  2982. int fd;
  2983. nullpo_retr(0, sd);
  2984. fd=sd->fd;
  2985. WFIFOHEAD(fd,packet_len(0xe7));
  2986. WFIFOW(fd,0)=0xe7;
  2987. WFIFOB(fd,2)=type;
  2988. WFIFOSET(fd,packet_len(0xe7));
  2989. return 0;
  2990. }
  2991. /*==========================================
  2992. * 相手方からのアイテム追加
  2993. *------------------------------------------*/
  2994. int clif_tradeadditem(struct map_session_data *sd,struct map_session_data *tsd,int index,int amount)
  2995. {
  2996. int fd;
  2997. nullpo_retr(0, sd);
  2998. nullpo_retr(0, tsd);
  2999. fd=tsd->fd;
  3000. WFIFOHEAD(fd,packet_len(0xe9));
  3001. WFIFOW(fd,0)=0xe9;
  3002. WFIFOL(fd,2)=amount;
  3003. if(index==0){
  3004. WFIFOW(fd,6) = 0; // type id
  3005. WFIFOB(fd,8) = 0; //identify flag
  3006. WFIFOB(fd,9) = 0; // attribute
  3007. WFIFOB(fd,10)= 0; //refine
  3008. WFIFOW(fd,11)= 0; //card (4w)
  3009. WFIFOW(fd,13)= 0; //card (4w)
  3010. WFIFOW(fd,15)= 0; //card (4w)
  3011. WFIFOW(fd,17)= 0; //card (4w)
  3012. }
  3013. else{
  3014. index-=2; //index fix
  3015. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3016. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  3017. else
  3018. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  3019. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  3020. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  3021. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  3022. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  3023. }
  3024. WFIFOSET(fd,packet_len(0xe9));
  3025. return 0;
  3026. }
  3027. /*==========================================
  3028. * アイテム追加成功/失敗
  3029. *------------------------------------------*/
  3030. int clif_tradeitemok(struct map_session_data *sd,int index,int fail)
  3031. {
  3032. int fd;
  3033. nullpo_retr(0, sd);
  3034. fd=sd->fd;
  3035. WFIFOHEAD(fd,packet_len(0xea));
  3036. WFIFOW(fd,0)=0xea;
  3037. WFIFOW(fd,2)=index;
  3038. WFIFOB(fd,4)=fail;
  3039. WFIFOSET(fd,packet_len(0xea));
  3040. return 0;
  3041. }
  3042. /*==========================================
  3043. * 取り引きok押し
  3044. *------------------------------------------*/
  3045. int clif_tradedeal_lock(struct map_session_data *sd,int fail)
  3046. {
  3047. int fd;
  3048. nullpo_retr(0, sd);
  3049. fd=sd->fd;
  3050. WFIFOHEAD(fd,packet_len(0xec));
  3051. WFIFOW(fd,0)=0xec;
  3052. WFIFOB(fd,2)=fail; // 0=you 1=the other person
  3053. WFIFOSET(fd,packet_len(0xec));
  3054. return 0;
  3055. }
  3056. /*==========================================
  3057. * 取り引きがキャンセルされました
  3058. *------------------------------------------*/
  3059. int clif_tradecancelled(struct map_session_data *sd)
  3060. {
  3061. int fd;
  3062. nullpo_retr(0, sd);
  3063. fd=sd->fd;
  3064. WFIFOHEAD(fd,packet_len(0xee));
  3065. WFIFOW(fd,0)=0xee;
  3066. WFIFOSET(fd,packet_len(0xee));
  3067. return 0;
  3068. }
  3069. /*==========================================
  3070. * 取り引き完了
  3071. *------------------------------------------*/
  3072. int clif_tradecompleted(struct map_session_data *sd,int fail)
  3073. {
  3074. int fd;
  3075. nullpo_retr(0, sd);
  3076. fd=sd->fd;
  3077. WFIFOHEAD(fd,packet_len(0xf0));
  3078. WFIFOW(fd,0)=0xf0;
  3079. WFIFOB(fd,2)=fail;
  3080. WFIFOSET(fd,packet_len(0xf0));
  3081. return 0;
  3082. }
  3083. /*==========================================
  3084. * カプラ倉庫のアイテム数を更新
  3085. *------------------------------------------*/
  3086. int clif_updatestorageamount(struct map_session_data *sd,struct storage *stor)
  3087. {
  3088. int fd;
  3089. nullpo_retr(0, sd);
  3090. nullpo_retr(0, stor);
  3091. fd=sd->fd;
  3092. WFIFOHEAD(fd,packet_len(0xf2));
  3093. WFIFOW(fd,0) = 0xf2; // update storage amount
  3094. WFIFOW(fd,2) = stor->storage_amount; //items
  3095. WFIFOW(fd,4) = MAX_STORAGE; //items max
  3096. WFIFOSET(fd,packet_len(0xf2));
  3097. return 0;
  3098. }
  3099. /*==========================================
  3100. * カプラ倉庫にアイテムを追加する
  3101. *------------------------------------------*/
  3102. int clif_storageitemadded(struct map_session_data *sd,struct storage *stor,int index,int amount)
  3103. {
  3104. int view,fd;
  3105. nullpo_retr(0, sd);
  3106. nullpo_retr(0, stor);
  3107. fd=sd->fd;
  3108. WFIFOHEAD(fd,packet_len(0xf4));
  3109. WFIFOW(fd,0) =0xf4; // Storage item added
  3110. WFIFOW(fd,2) =index+1; // index
  3111. WFIFOL(fd,4) =amount; // amount
  3112. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3113. WFIFOW(fd,8) =view;
  3114. else
  3115. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3116. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3117. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3118. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3119. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3120. WFIFOSET(fd,packet_len(0xf4));
  3121. return 0;
  3122. }
  3123. /*==========================================
  3124. *
  3125. *------------------------------------------*/
  3126. int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor)
  3127. {
  3128. int fd;
  3129. nullpo_retr(0, sd);
  3130. nullpo_retr(0, stor);
  3131. fd=sd->fd;
  3132. WFIFOHEAD(fd,packet_len(0xf2));
  3133. WFIFOW(fd,0) = 0xf2; // update storage amount
  3134. WFIFOW(fd,2) = stor->storage_amount; //items
  3135. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  3136. WFIFOSET(fd,packet_len(0xf2));
  3137. return 0;
  3138. }
  3139. /*==========================================
  3140. *
  3141. *------------------------------------------*/
  3142. int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount)
  3143. {
  3144. int view,fd;
  3145. nullpo_retr(0, sd);
  3146. nullpo_retr(0, stor);
  3147. fd=sd->fd;
  3148. WFIFOHEAD(fd,packet_len(0xf4));
  3149. WFIFOW(fd,0) =0xf4; // Storage item added
  3150. WFIFOW(fd,2) =index+1; // index
  3151. WFIFOL(fd,4) =amount; // amount
  3152. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3153. WFIFOW(fd,8) =view;
  3154. else
  3155. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3156. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3157. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3158. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3159. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3160. WFIFOSET(fd,packet_len(0xf4));
  3161. return 0;
  3162. }
  3163. /*==========================================
  3164. * カプラ倉庫からアイテムを取り去る
  3165. *------------------------------------------*/
  3166. int clif_storageitemremoved(struct map_session_data *sd,int index,int amount)
  3167. {
  3168. int fd;
  3169. nullpo_retr(0, sd);
  3170. fd=sd->fd;
  3171. WFIFOHEAD(fd,packet_len(0xf6));
  3172. WFIFOW(fd,0)=0xf6; // Storage item removed
  3173. WFIFOW(fd,2)=index+1;
  3174. WFIFOL(fd,4)=amount;
  3175. WFIFOSET(fd,packet_len(0xf6));
  3176. return 0;
  3177. }
  3178. /*==========================================
  3179. * カプラ倉庫を閉じる
  3180. *------------------------------------------*/
  3181. int clif_storageclose(struct map_session_data *sd)
  3182. {
  3183. int fd;
  3184. nullpo_retr(0, sd);
  3185. fd=sd->fd;
  3186. WFIFOHEAD(fd,packet_len(0xf8));
  3187. WFIFOW(fd,0)=0xf8; // Storage Closed
  3188. WFIFOSET(fd,packet_len(0xf8));
  3189. return 0;
  3190. }
  3191. //
  3192. // callback系 ?
  3193. //
  3194. /*==========================================
  3195. * PC表示
  3196. *------------------------------------------*/
  3197. void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3198. {
  3199. int len;
  3200. if(dstsd->chatID){
  3201. struct chat_data *cd;
  3202. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  3203. if(cd && cd->usersd[0]==dstsd)
  3204. clif_dispchat(cd,sd->fd);
  3205. }
  3206. if(dstsd->vender_id)
  3207. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3208. if(dstsd->spiritball > 0)
  3209. clif_spiritball_single(sd->fd, dstsd);
  3210. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3211. (battle_config.disp_hpmeter && (len = pc_isGM(sd)) >= battle_config.disp_hpmeter && len >= pc_isGM(dstsd))
  3212. )
  3213. clif_hpmeter_single(sd->fd, dstsd);
  3214. if(dstsd->status.manner < 0)
  3215. clif_changestatus(&dstsd->bl,SP_MANNER,dstsd->status.manner);
  3216. // pvp circle for duel [LuzZza]
  3217. /*
  3218. if(dstsd->duel_group)
  3219. clif_specialeffect(&dstsd->bl, 159, 4);
  3220. */
  3221. }
  3222. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3223. {
  3224. struct unit_data *ud;
  3225. struct view_data *vd;
  3226. int len, fd = sd->fd;
  3227. vd = status_get_viewdata(bl);
  3228. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3229. return;
  3230. ud = unit_bl2ud(bl);
  3231. if (ud && ud->walktimer != -1)
  3232. {
  3233. #if PACKETVER > 6
  3234. WFIFOHEAD(fd, packet_len(0x22c));
  3235. #elif PACKETVER > 3
  3236. WFIFOHEAD(fd, packet_len(0x1da));
  3237. #else
  3238. WFIFOHEAD(fd, packet_len(0x7b));
  3239. #endif
  3240. len = clif_set007b(bl,vd,ud,WFIFOP(fd,0));
  3241. WFIFOSET(fd,len);
  3242. } else {
  3243. #if PACKETVER > 6
  3244. WFIFOHEAD(fd,packet_len(0x22a));
  3245. #elif PACKETVER > 3
  3246. WFIFOHEAD(fd,packet_len(0x1d8));
  3247. #else
  3248. WFIFOHEAD(fd,packet_len(0x78));
  3249. #endif
  3250. len = clif_set0078(bl,WFIFOP(fd,0));
  3251. WFIFOSET(fd,len);
  3252. }
  3253. if (vd->cloth_color)
  3254. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3255. switch (bl->type)
  3256. { // FIXME: 'AREA' causes unneccessary spam since this should be 1:1 communication
  3257. case BL_PC:
  3258. {
  3259. TBL_PC* tsd = (TBL_PC*)bl;
  3260. clif_getareachar_pc(sd, tsd);
  3261. if(tsd->state.size==2) // tiny/big players [Valaris]
  3262. clif_specialeffect(bl,423,AREA);
  3263. else if(tsd->state.size==1)
  3264. clif_specialeffect(bl,421,AREA);
  3265. }
  3266. break;
  3267. case BL_NPC:
  3268. {
  3269. if(((TBL_NPC*)bl)->chat_id)
  3270. clif_dispchat((struct chat_data*)map_id2bl(((TBL_NPC*)bl)->chat_id),sd->fd);
  3271. }
  3272. break;
  3273. case BL_MOB:
  3274. {
  3275. TBL_MOB* md = (TBL_MOB*)bl;
  3276. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3277. clif_specialeffect(bl,423,AREA);
  3278. else if(md->special_state.size==1)
  3279. clif_specialeffect(bl,421,AREA);
  3280. }
  3281. break;
  3282. case BL_PET:
  3283. {
  3284. unsigned char buf[64];
  3285. int len = clif_set0078(bl, buf);
  3286. clif_send(buf, len, &sd->bl, SELF);
  3287. }
  3288. break;
  3289. }
  3290. }
  3291. //Modifies the type of damage according to status changes [Skotlex]
  3292. #define clif_calc_delay(type,delay) (type==1||type==4||type==0x0a)?type:(delay==0?9:type)
  3293. /*==========================================
  3294. * Estimates walk delay based on the damage criteria. [Skotlex]
  3295. *------------------------------------------*/
  3296. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3297. {
  3298. if (type == 4 || type == 9 || damage <=0)
  3299. return 0;
  3300. if (bl->type == BL_PC) {
  3301. if (battle_config.pc_walk_delay_rate != 100)
  3302. delay = delay*battle_config.pc_walk_delay_rate/100;
  3303. } else
  3304. if (battle_config.walk_delay_rate != 100)
  3305. delay = delay*battle_config.walk_delay_rate/100;
  3306. if (div_ > 1) //Multi-hit skills mean higher delays.
  3307. delay += battle_config.multihit_delay*(div_-1);
  3308. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3309. }
  3310. /*==========================================
  3311. * 通常攻撃エフェクト&ダメージ
  3312. *------------------------------------------*/
  3313. int clif_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int type,int damage2)
  3314. {
  3315. unsigned char buf[256];
  3316. struct status_change *sc;
  3317. nullpo_retr(0, src);
  3318. nullpo_retr(0, dst);
  3319. type = clif_calc_delay(type, ddelay); //Type defaults to 0 for normal attacks.
  3320. sc = status_get_sc(dst);
  3321. if(sc && sc->count) {
  3322. if(sc->data[SC_HALLUCINATION].timer != -1) {
  3323. if(damage > 0)
  3324. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3325. if(damage2 > 0)
  3326. damage2 = damage2*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3327. }
  3328. }
  3329. WBUFW(buf,0)=0x8a;
  3330. WBUFL(buf,2)=src->id;
  3331. WBUFL(buf,6)=dst->id;
  3332. WBUFL(buf,10)=tick;
  3333. WBUFL(buf,14)=sdelay;
  3334. WBUFL(buf,18)=ddelay;
  3335. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3336. WBUFW(buf,22)=damage?div:0;
  3337. WBUFW(buf,27)=damage2?div:0;
  3338. } else {
  3339. WBUFW(buf,22)=(damage > SHRT_MAX)?SHRT_MAX:damage;
  3340. WBUFW(buf,27)=damage2;
  3341. }
  3342. WBUFW(buf,24)=div;
  3343. WBUFB(buf,26)=type;
  3344. clif_send(buf,packet_len(0x8a),src,AREA);
  3345. if(disguised(src)) {
  3346. WBUFL(buf,2)=-src->id;
  3347. if(damage > 0)
  3348. WBUFW(buf,22)=-1;
  3349. if(damage2 > 0)
  3350. WBUFW(buf,27)=-1;
  3351. clif_send(buf,packet_len(0x8a),src,SELF);
  3352. }
  3353. if (disguised(dst)) {
  3354. WBUFL(buf,6)=-dst->id;
  3355. if (disguised(src))
  3356. WBUFL(buf,2)=src->id;
  3357. else {
  3358. if(damage > 0)
  3359. WBUFW(buf,22)=-1;
  3360. if(damage2 > 0)
  3361. WBUFW(buf,27)=-1;
  3362. }
  3363. clif_send(buf,packet_len(0x8a),dst,SELF);
  3364. }
  3365. //Return adjusted can't walk delay for further processing.
  3366. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3367. }
  3368. /*==========================================
  3369. *
  3370. *------------------------------------------*/
  3371. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3372. {
  3373. int view,fd;
  3374. fd=sd->fd;
  3375. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3376. WFIFOHEAD(fd,packet_len(0x9d));
  3377. WFIFOW(fd,0)=0x9d;
  3378. WFIFOL(fd,2)=fitem->bl.id;
  3379. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3380. WFIFOW(fd,6)=view;
  3381. else
  3382. WFIFOW(fd,6)=fitem->item_data.nameid;
  3383. WFIFOB(fd,8)=fitem->item_data.identify;
  3384. WFIFOW(fd,9)=fitem->bl.x;
  3385. WFIFOW(fd,11)=fitem->bl.y;
  3386. WFIFOW(fd,13)=fitem->item_data.amount;
  3387. WFIFOB(fd,15)=fitem->subx;
  3388. WFIFOB(fd,16)=fitem->suby;
  3389. WFIFOSET(fd,packet_len(0x9d));
  3390. }
  3391. /*==========================================
  3392. * 場所スキルエフェクトが視界に入る
  3393. *------------------------------------------*/
  3394. int clif_getareachar_skillunit(struct map_session_data *sd,struct skill_unit *unit)
  3395. {
  3396. int fd;
  3397. struct block_list *bl;
  3398. fd=sd->fd;
  3399. bl=map_id2bl(unit->group->src_id);
  3400. #if PACKETVER >= 3
  3401. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3402. WFIFOHEAD(fd,packet_len(0x1c9));
  3403. memset(WFIFOP(fd,0),0,packet_len(0x1c9));
  3404. WFIFOW(fd, 0)=0x1c9;
  3405. WFIFOL(fd, 2)=unit->bl.id;
  3406. WFIFOL(fd, 6)=unit->group->src_id;
  3407. WFIFOW(fd,10)=unit->bl.x;
  3408. WFIFOW(fd,12)=unit->bl.y; // might be typo? [Lance]
  3409. WFIFOB(fd,14)=unit->group->unit_id;
  3410. WFIFOB(fd,15)=1;
  3411. WFIFOB(fd,16)=1;
  3412. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3413. WFIFOSET(fd,packet_len(0x1c9));
  3414. return 0;
  3415. }
  3416. #endif
  3417. WFIFOHEAD(fd,packet_len(0x11f));
  3418. memset(WFIFOP(fd,0),0,packet_len(0x11f));
  3419. WFIFOW(fd, 0)=0x11f;
  3420. WFIFOL(fd, 2)=unit->bl.id;
  3421. WFIFOL(fd, 6)=unit->group->src_id;
  3422. WFIFOW(fd,10)=unit->bl.x;
  3423. WFIFOW(fd,12)=unit->bl.y;
  3424. //Use invisible unit id for traps.
  3425. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3426. WFIFOB(fd,14)=UNT_ATTACK_SKILLS;
  3427. else
  3428. WFIFOB(fd,14)=unit->group->unit_id;
  3429. WFIFOB(fd,15)=0;
  3430. WFIFOSET(fd,packet_len(0x11f));
  3431. if(unit->group->skill_id == WZ_ICEWALL)
  3432. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3433. return 0;
  3434. /* Previous implementation guess of packet 0x1c9, who can understand what all those fields are for? [Skotlex]
  3435. WFIFOHEAD(fd,packet_len(0x1c9));
  3436. memset(WFIFOP(fd,0),0,packet_len(0x1c9));
  3437. WFIFOW(fd, 0)=0x1c9;
  3438. WFIFOL(fd, 2)=unit->bl.id;
  3439. WFIFOL(fd, 6)=unit->group->src_id;
  3440. WFIFOW(fd,10)=unit->bl.x;
  3441. WFIFOW(fd,12)=unit->bl.y;
  3442. WFIFOB(fd,14)=unit->group->unit_id;
  3443. WFIFOB(fd,15)=1;
  3444. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3445. WFIFOB(fd,16)=1;
  3446. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3447. } else {
  3448. WFIFOL(fd,15+1)=0; //1-4調べた限り固定
  3449. WFIFOL(fd,15+5)=0; //5-8調べた限り固定
  3450. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  3451. WFIFOL(fd,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  3452. WFIFOL(fd,15+17)=0x004f37dd; //17-20調べた限り固定
  3453. WFIFOL(fd,15+21)=0x0012f674; //21-24調べた限り固定
  3454. WFIFOL(fd,15+25)=0x0012f664; //25-28調べた限り固定
  3455. WFIFOL(fd,15+29)=0x0012f654; //29-32調べた限り固定
  3456. WFIFOL(fd,15+33)=0x77527bbc; //33-36調べた限り固定
  3457. //37-39
  3458. WFIFOB(fd,15+40)=0x2d; //40調べた限り固定
  3459. WFIFOL(fd,15+41)=0; //41-44調べた限り0固定
  3460. WFIFOL(fd,15+45)=0; //45-48調べた限り0固定
  3461. WFIFOL(fd,15+49)=0; //49-52調べた限り0固定
  3462. WFIFOL(fd,15+53)=0x0048d919; //53-56調べた限り固定
  3463. WFIFOL(fd,15+57)=0x0000003e; //57-60調べた限り固定
  3464. WFIFOL(fd,15+61)=0x0012f66c; //61-64調べた限り固定
  3465. //65-68
  3466. //69-72
  3467. if(bl) WFIFOL(fd,15+73)=bl->y; //73-76術者のY座標
  3468. WFIFOL(fd,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  3469. WFIFOB(fd,15+81)=0xaa; //81終端文字0xaa
  3470. }
  3471. WFIFOSET(fd,packet_len(0x1c9));
  3472. #endif
  3473. if(unit->group->skill_id == WZ_ICEWALL)
  3474. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3475. return 0;
  3476. */
  3477. }
  3478. /*==========================================
  3479. * 場所スキルエフェクトが視界から消える
  3480. *------------------------------------------*/
  3481. int clif_clearchar_skillunit(struct skill_unit *unit,int fd)
  3482. {
  3483. nullpo_retr(0, unit);
  3484. WFIFOHEAD(fd,packet_len(0x120));
  3485. WFIFOW(fd, 0)=0x120;
  3486. WFIFOL(fd, 2)=unit->bl.id;
  3487. WFIFOSET(fd,packet_len(0x120));
  3488. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3489. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2);
  3490. return 0;
  3491. }
  3492. /*==========================================
  3493. * Unknown... trap related?
  3494. * Only affects units with class [139,153] client-side
  3495. *------------------------------------------*/
  3496. int clif_01ac(struct block_list *bl)
  3497. {
  3498. unsigned char buf[32];
  3499. nullpo_retr(0, bl);
  3500. WBUFW(buf, 0) = 0x1ac;
  3501. WBUFL(buf, 2) = bl->id;
  3502. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3503. return 0;
  3504. }
  3505. /*==========================================
  3506. *
  3507. *------------------------------------------*/
  3508. int clif_getareachar(struct block_list* bl,va_list ap)
  3509. {
  3510. struct map_session_data *sd;
  3511. nullpo_retr(0, bl);
  3512. nullpo_retr(0, ap);
  3513. sd=va_arg(ap,struct map_session_data*);
  3514. if (sd == NULL || !sd->fd || session[sd->fd] == NULL)
  3515. return 0;
  3516. switch(bl->type){
  3517. case BL_ITEM:
  3518. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3519. break;
  3520. case BL_SKILL:
  3521. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3522. break;
  3523. default:
  3524. if(&sd->bl == bl)
  3525. break;
  3526. clif_getareachar_unit(sd,bl);
  3527. break;
  3528. }
  3529. return 0;
  3530. }
  3531. /*==========================================
  3532. * tbl has gone out of view-size of bl
  3533. *------------------------------------------*/
  3534. int clif_outsight(struct block_list *bl,va_list ap)
  3535. {
  3536. struct block_list *tbl;
  3537. struct view_data *vd;
  3538. TBL_PC *sd, *tsd;
  3539. tbl=va_arg(ap,struct block_list*);
  3540. if(bl == tbl) return 0;
  3541. BL_CAST(BL_PC, bl, sd);
  3542. BL_CAST(BL_PC, tbl, tsd);
  3543. if (tsd && tsd->fd)
  3544. { //tsd has lost sight of the bl object.
  3545. switch(bl->type){
  3546. case BL_PC:
  3547. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS)
  3548. clif_clearunit_single(bl->id,0,tsd->fd);
  3549. if(sd->chatID){
  3550. struct chat_data *cd;
  3551. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3552. if(cd->usersd[0]==sd)
  3553. clif_dispchat(cd,tsd->fd);
  3554. }
  3555. if(sd->vender_id)
  3556. clif_closevendingboard(bl,tsd->fd);
  3557. break;
  3558. case BL_ITEM:
  3559. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3560. break;
  3561. case BL_SKILL:
  3562. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3563. break;
  3564. default:
  3565. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3566. clif_clearunit_single(bl->id,0,tsd->fd);
  3567. break;
  3568. }
  3569. }
  3570. if (sd && sd->fd)
  3571. { //sd is watching tbl go out of view.
  3572. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3573. clif_clearunit_single(tbl->id,0,sd->fd);
  3574. }
  3575. return 0;
  3576. }
  3577. /*==========================================
  3578. * tbl has come into view of bl
  3579. *------------------------------------------*/
  3580. int clif_insight(struct block_list *bl,va_list ap)
  3581. {
  3582. struct block_list *tbl;
  3583. TBL_PC *sd, *tsd;
  3584. tbl=va_arg(ap,struct block_list*);
  3585. if (bl == tbl) return 0;
  3586. BL_CAST(BL_PC, bl, sd);
  3587. BL_CAST(BL_PC, tbl, tsd);
  3588. if (tsd && tsd->fd)
  3589. { //Tell tsd that bl entered into his view
  3590. switch(bl->type){
  3591. case BL_ITEM:
  3592. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3593. break;
  3594. case BL_SKILL:
  3595. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3596. break;
  3597. default:
  3598. clif_getareachar_unit(tsd,bl);
  3599. break;
  3600. }
  3601. }
  3602. if (sd && sd->fd)
  3603. { //Tell sd that tbl walked into his view
  3604. clif_getareachar_unit(sd,tbl);
  3605. }
  3606. return 0;
  3607. }
  3608. /*==========================================
  3609. *
  3610. *------------------------------------------*/
  3611. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3612. {
  3613. int fd,id;
  3614. nullpo_retr(0, sd);
  3615. fd=sd->fd;
  3616. if( (id=sd->status.skill[skillid].id) <= 0 )
  3617. return 0;
  3618. WFIFOHEAD(fd,packet_len(0x147));
  3619. WFIFOW(fd,0)=0x147;
  3620. WFIFOW(fd,2) = id;
  3621. if(type < 0)
  3622. WFIFOW(fd,4) = skill_get_inf(id);
  3623. else
  3624. WFIFOW(fd,4) = type;
  3625. WFIFOW(fd,6) = 0;
  3626. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3627. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3628. if(range < 0)
  3629. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3630. WFIFOW(fd,12)= range;
  3631. strncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3632. if(sd->status.skill[skillid].flag ==0)
  3633. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3634. else
  3635. WFIFOB(fd,38) = 0;
  3636. WFIFOSET(fd,packet_len(0x147));
  3637. return 0;
  3638. }
  3639. /*==========================================
  3640. * スキルリストを送信する
  3641. *------------------------------------------*/
  3642. int clif_skillinfoblock(struct map_session_data *sd)
  3643. {
  3644. int fd;
  3645. int i,c,len,id;
  3646. nullpo_retr(0, sd);
  3647. fd=sd->fd;
  3648. if (!fd) return 0;
  3649. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3650. WFIFOW(fd,0) = 0x10f;
  3651. for ( i = 0, c = 0, len = 4; i < MAX_SKILL; i++)
  3652. {
  3653. if( (id = sd->status.skill[i].id) != 0 )
  3654. {
  3655. WFIFOW(fd,len) = id;
  3656. WFIFOW(fd,len+2) = skill_get_inf(id);
  3657. WFIFOW(fd,len+4) = 0;
  3658. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3659. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3660. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3661. strncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3662. if(sd->status.skill[i].flag == 0)
  3663. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3664. else
  3665. WFIFOB(fd,len+36) = 0;
  3666. len += 37;
  3667. c++;
  3668. }
  3669. }
  3670. WFIFOW(fd,2)=len;
  3671. WFIFOSET(fd,len);
  3672. return 1;
  3673. }
  3674. /*==========================================
  3675. * スキル割り振り通知
  3676. *------------------------------------------*/
  3677. int clif_skillup(struct map_session_data *sd,int skill_num)
  3678. {
  3679. int fd;
  3680. nullpo_retr(0, sd);
  3681. fd=sd->fd;
  3682. WFIFOHEAD(fd,packet_len(0x10e));
  3683. WFIFOW(fd,0) = 0x10e;
  3684. WFIFOW(fd,2) = skill_num;
  3685. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3686. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3687. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3688. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3689. WFIFOSET(fd,packet_len(0x10e));
  3690. return 0;
  3691. }
  3692. /*==========================================
  3693. * スキル詠唱エフェクトを送信する
  3694. *------------------------------------------*/
  3695. int clif_skillcasting(struct block_list* bl,
  3696. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int pl, int casttime)
  3697. {
  3698. unsigned char buf[32];
  3699. WBUFW(buf,0) = 0x13e;
  3700. WBUFL(buf,2) = src_id;
  3701. WBUFL(buf,6) = dst_id;
  3702. WBUFW(buf,10) = dst_x;
  3703. WBUFW(buf,12) = dst_y;
  3704. WBUFW(buf,14) = skill_num;
  3705. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3706. WBUFL(buf,20) = casttime;
  3707. clif_send(buf,packet_len(0x13e), bl, AREA);
  3708. if (disguised(bl)) {
  3709. WBUFL(buf,2) = -src_id;
  3710. WBUFL(buf,20) = 0;
  3711. clif_send(buf,packet_len(0x13e), bl, SELF);
  3712. }
  3713. return 0;
  3714. }
  3715. /*==========================================
  3716. *
  3717. *------------------------------------------*/
  3718. int clif_skillcastcancel(struct block_list* bl)
  3719. {
  3720. unsigned char buf[16];
  3721. nullpo_retr(0, bl);
  3722. WBUFW(buf,0) = 0x1b9;
  3723. WBUFL(buf,2) = bl->id;
  3724. clif_send(buf,packet_len(0x1b9), bl, AREA);
  3725. return 0;
  3726. }
  3727. /// only when type==0:
  3728. /// if(skill_id==NV_BASIC)
  3729. /// btype==0 "skill failed" MsgStringTable[159]
  3730. /// btype==1 "no emotions" MsgStringTable[160]
  3731. /// btype==2 "no sit" MsgStringTable[161]
  3732. /// btype==3 "no chat" MsgStringTable[162]
  3733. /// btype==4 "no party" MsgStringTable[163]
  3734. /// btype==5 "no shout" MsgStringTable[164]
  3735. /// btype==6 "no PKing" MsgStringTable[165]
  3736. /// btype==7 "no alligning" MsgStringTable[383]
  3737. /// btype>=8: ignored
  3738. /// if(skill_id==AL_WARP) "not enough skill level" MsgStringTable[214]
  3739. /// if(skill_id==TF_STEAL) "steal failed" MsgStringTable[205]
  3740. /// if(skill_id==TF_POISON) "envenom failed" MsgStringTable[207]
  3741. /// otherwise "skill failed" MsgStringTable[204]
  3742. /// btype irrelevant
  3743. /// type==1 "insufficient SP" MsgStringTable[202]
  3744. /// type==2 "insufficient HP" MsgStringTable[203]
  3745. /// type==3 "insufficient materials" MsgStringTable[808]
  3746. /// type==4 "there is a delay after using a skill" MsgStringTable[219]
  3747. /// type==5 "insufficient zeny" MsgStringTable[233]
  3748. /// type==6 "wrong weapon" MsgStringTable[239]
  3749. /// type==7 "red jemstone needed" MsgStringTable[246]
  3750. /// type==8 "blue jemstone needed" MsgStringTable[247]
  3751. /// type==9 "overweight" MsgStringTable[580]
  3752. /// type==10 "skill failed" MsgStringTable[285]
  3753. /// type>=11 ignored
  3754. ///
  3755. /// if(success!=0) doesn't display any of the previous messages
  3756. /// Note: when this packet is received an unknown flag is always set to 0,
  3757. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  3758. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3759. {
  3760. int fd;
  3761. if (!sd) { //Since this is the most common nullpo....
  3762. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3763. return 0;
  3764. }
  3765. fd=sd->fd;
  3766. if (!fd) return 0;
  3767. if(battle_config.display_skill_fail&1)
  3768. return 0; //Disable all skill failed messages
  3769. if(type==0x4 && !sd->state.showdelay)
  3770. return 0; //Disable delay failed messages
  3771. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3772. return 0;
  3773. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3774. return 0;
  3775. WFIFOHEAD(fd,packet_len(0x110));
  3776. WFIFOW(fd,0) = 0x110;
  3777. WFIFOW(fd,2) = skill_id;
  3778. WFIFOL(fd,4) = btype;
  3779. WFIFOB(fd,8) = 0;// success?
  3780. WFIFOB(fd,9) = type;
  3781. WFIFOSET(fd,packet_len(0x110));
  3782. return 1;
  3783. }
  3784. /*==========================================
  3785. * スキル攻撃エフェクト&ダメージ
  3786. *------------------------------------------*/
  3787. int clif_skill_damage(struct block_list *src,struct block_list *dst,
  3788. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3789. {
  3790. unsigned char buf[64];
  3791. struct status_change *sc;
  3792. nullpo_retr(0, src);
  3793. nullpo_retr(0, dst);
  3794. type = (type>0)?type:skill_get_hit(skill_id);
  3795. type = clif_calc_delay(type, ddelay);
  3796. sc = status_get_sc(dst);
  3797. if(sc && sc->count) {
  3798. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  3799. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3800. }
  3801. #if PACKETVER < 3
  3802. WBUFW(buf,0)=0x114;
  3803. WBUFW(buf,2)=skill_id;
  3804. WBUFL(buf,4)=src->id;
  3805. WBUFL(buf,8)=dst->id;
  3806. WBUFL(buf,12)=tick;
  3807. WBUFL(buf,16)=sdelay;
  3808. WBUFL(buf,20)=ddelay;
  3809. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3810. WBUFW(buf,24)=damage?div:0;
  3811. } else {
  3812. WBUFW(buf,24)=damage;
  3813. }
  3814. WBUFW(buf,26)=skill_lv;
  3815. WBUFW(buf,28)=div;
  3816. WBUFB(buf,30)=type;
  3817. clif_send(buf,packet_len(0x114),src,AREA);
  3818. if(disguised(src)) {
  3819. WBUFL(buf,4)=-src->id;
  3820. if(damage > 0)
  3821. WBUFW(buf,24)=-1;
  3822. clif_send(buf,packet_len(0x114),src,SELF);
  3823. }
  3824. if (disguised(dst)) {
  3825. WBUFL(buf,8)=-dst->id;
  3826. if (disguised(src))
  3827. WBUFL(buf,4)=src->id;
  3828. else if(damage > 0)
  3829. WBUFW(buf,24)=-1;
  3830. clif_send(buf,packet_len(0x114),dst,SELF);
  3831. }
  3832. #else
  3833. WBUFW(buf,0)=0x1de;
  3834. WBUFW(buf,2)=skill_id;
  3835. WBUFL(buf,4)=src->id;
  3836. WBUFL(buf,8)=dst->id;
  3837. WBUFL(buf,12)=tick;
  3838. WBUFL(buf,16)=sdelay;
  3839. WBUFL(buf,20)=ddelay;
  3840. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3841. WBUFL(buf,24)=damage?div:0;
  3842. } else {
  3843. WBUFL(buf,24)=damage;
  3844. }
  3845. WBUFW(buf,28)=skill_lv;
  3846. WBUFW(buf,30)=div;
  3847. WBUFB(buf,32)=type;
  3848. clif_send(buf,packet_len(0x1de),src,AREA);
  3849. if(disguised(src)) {
  3850. WBUFL(buf,4)=-src->id;
  3851. if(damage > 0)
  3852. WBUFL(buf,24)=-1;
  3853. clif_send(buf,packet_len(0x1de),src,SELF);
  3854. }
  3855. if (disguised(dst)) {
  3856. WBUFL(buf,8)=-dst->id;
  3857. if (disguised(src))
  3858. WBUFL(buf,4)=src->id;
  3859. else if(damage > 0)
  3860. WBUFL(buf,24)=-1;
  3861. clif_send(buf,packet_len(0x1de),dst,SELF);
  3862. }
  3863. #endif
  3864. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3865. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3866. }
  3867. /*==========================================
  3868. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3869. *------------------------------------------*/
  3870. int clif_skill_damage2(struct block_list *src,struct block_list *dst,
  3871. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3872. {
  3873. unsigned char buf[64];
  3874. struct status_change *sc;
  3875. nullpo_retr(0, src);
  3876. nullpo_retr(0, dst);
  3877. type = (type>0)?type:skill_get_hit(skill_id);
  3878. type = clif_calc_delay(type, ddelay);
  3879. sc = status_get_sc(dst);
  3880. if(sc && sc->count) {
  3881. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  3882. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3883. }
  3884. WBUFW(buf,0)=0x115;
  3885. WBUFW(buf,2)=skill_id;
  3886. WBUFL(buf,4)=src->id;
  3887. WBUFL(buf,8)=dst->id;
  3888. WBUFL(buf,12)=tick;
  3889. WBUFL(buf,16)=sdelay;
  3890. WBUFL(buf,20)=ddelay;
  3891. WBUFW(buf,24)=dst->x;
  3892. WBUFW(buf,26)=dst->y;
  3893. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3894. WBUFW(buf,28)=damage?div:0;
  3895. } else {
  3896. WBUFW(buf,28)=damage;
  3897. }
  3898. WBUFW(buf,30)=skill_lv;
  3899. WBUFW(buf,32)=div;
  3900. WBUFB(buf,34)=type;
  3901. clif_send(buf,packet_len(0x115),src,AREA);
  3902. if(disguised(src)) {
  3903. WBUFL(buf,4)=-src->id;
  3904. if(damage > 0)
  3905. WBUFW(buf,28)=-1;
  3906. clif_send(buf,packet_len(0x115),src,SELF);
  3907. }
  3908. if (disguised(dst)) {
  3909. WBUFL(buf,8)=-dst->id;
  3910. if (disguised(src))
  3911. WBUFL(buf,4)=src->id;
  3912. else if(damage > 0)
  3913. WBUFW(buf,28)=-1;
  3914. clif_send(buf,packet_len(0x115),dst,SELF);
  3915. }
  3916. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3917. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3918. }
  3919. /*==========================================
  3920. * 支援/回復スキルエフェクト
  3921. *------------------------------------------*/
  3922. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_id,int heal,int fail)
  3923. {
  3924. unsigned char buf[32];
  3925. nullpo_retr(0, dst);
  3926. WBUFW(buf,0)=0x11a;
  3927. WBUFW(buf,2)=skill_id;
  3928. WBUFW(buf,4)=(heal > SHRT_MAX)? SHRT_MAX:heal;
  3929. WBUFL(buf,6)=dst->id;
  3930. WBUFL(buf,10)=src?src->id:0;
  3931. WBUFB(buf,14)=fail;
  3932. clif_send(buf,packet_len(0x11a),dst,AREA);
  3933. if (disguised(dst)) {
  3934. WBUFL(buf,6)=-dst->id;
  3935. clif_send(buf,packet_len(0x115),dst,SELF);
  3936. }
  3937. if(src && disguised(src)) {
  3938. WBUFL(buf,10)=-src->id;
  3939. if (disguised(dst))
  3940. WBUFL(buf,6)=dst->id;
  3941. clif_send(buf,packet_len(0x115),src,SELF);
  3942. }
  3943. return fail;
  3944. }
  3945. /*==========================================
  3946. * 場所スキルエフェクト
  3947. *------------------------------------------*/
  3948. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  3949. {
  3950. unsigned char buf[32];
  3951. nullpo_retr(0, src);
  3952. WBUFW(buf,0)=0x117;
  3953. WBUFW(buf,2)=skill_id;
  3954. WBUFL(buf,4)=src->id;
  3955. WBUFW(buf,8)=val;
  3956. WBUFW(buf,10)=x;
  3957. WBUFW(buf,12)=y;
  3958. WBUFL(buf,14)=tick;
  3959. clif_send(buf,packet_len(0x117),src,AREA);
  3960. if(disguised(src)) {
  3961. WBUFL(buf,4)=-src->id;
  3962. clif_send(buf,packet_len(0x117),src,SELF);
  3963. }
  3964. return 0;
  3965. }
  3966. /*==========================================
  3967. * 場所スキルエフェクト表示
  3968. *------------------------------------------*/
  3969. int clif_skill_setunit(struct skill_unit *unit)
  3970. {
  3971. unsigned char buf[128];
  3972. struct block_list *bl;
  3973. nullpo_retr(0, unit);
  3974. bl=map_id2bl(unit->group->src_id);
  3975. // These are invisible client-side, but are necessary because
  3976. // otherwise the client will not know who caused the attack.
  3977. // if (unit->group->unit_id == UNT_ATTACK_SKILLS)
  3978. // return 0;
  3979. #if PACKETVER >= 3
  3980. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3981. memset(WBUFP(buf, 0),0,packet_len(0x1c9));
  3982. WBUFW(buf, 0)=0x1c9;
  3983. WBUFL(buf, 2)=unit->bl.id;
  3984. WBUFL(buf, 6)=unit->group->src_id;
  3985. WBUFW(buf,10)=unit->bl.x;
  3986. WBUFW(buf,12)=unit->bl.y;
  3987. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE) {
  3988. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  3989. } else {
  3990. WBUFB(buf,14)=unit->group->unit_id;
  3991. }
  3992. WBUFB(buf,15)=1;
  3993. WBUFB(buf,16)=1;
  3994. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  3995. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  3996. return 0;
  3997. }
  3998. #endif
  3999. memset(WBUFP(buf, 0),0,packet_len(0x11f));
  4000. WBUFW(buf, 0)=0x11f;
  4001. WBUFL(buf, 2)=unit->bl.id;
  4002. WBUFL(buf, 6)=unit->group->src_id;
  4003. WBUFW(buf,10)=unit->bl.x;
  4004. WBUFW(buf,12)=unit->bl.y;
  4005. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE) {
  4006. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4007. } else {
  4008. WBUFB(buf,14)=unit->group->unit_id;
  4009. }
  4010. WBUFB(buf,15)=0;
  4011. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4012. return 0;
  4013. /* Previous mysterious implementation noone really understands. [Skotlex]
  4014. memset(WBUFP(buf, 0),0,packet_len(0x1c9));
  4015. WBUFW(buf, 0)=0x1c9;
  4016. WBUFL(buf, 2)=unit->bl.id;
  4017. WBUFL(buf, 6)=unit->group->src_id;
  4018. WBUFW(buf,10)=unit->bl.x;
  4019. WBUFW(buf,12)=unit->bl.y;
  4020. WBUFB(buf,14)=unit->group->unit_id;
  4021. WBUFB(buf,15)=1;
  4022. if(unit->group->unit_id==0xb0) { // Graffiti [Valaris]
  4023. WBUFB(buf,16)=1;
  4024. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4025. } else {
  4026. WBUFL(buf,15+1)=0; //1-4調べた限り固定
  4027. WBUFL(buf,15+5)=0; //5-8調べた限り固定
  4028. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  4029. WBUFL(buf,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  4030. WBUFL(buf,15+17)=0x004f37dd; //17-20調べた限り固定(0x1b2で0x004fdbddだった)
  4031. WBUFL(buf,15+21)=0x0012f674; //21-24調べた限り固定
  4032. WBUFL(buf,15+25)=0x0012f664; //25-28調べた限り固定
  4033. WBUFL(buf,15+29)=0x0012f654; //29-32調べた限り固定
  4034. WBUFL(buf,15+33)=0x77527bbc; //33-36調べた限り固定
  4035. //37-39
  4036. WBUFB(buf,15+40)=0x2d; //40調べた限り固定
  4037. WBUFL(buf,15+41)=0; //41-44調べた限り0固定
  4038. WBUFL(buf,15+45)=0; //45-48調べた限り0固定
  4039. WBUFL(buf,15+49)=0; //49-52調べた限り0固定
  4040. WBUFL(buf,15+53)=0x0048d919; //53-56調べた限り固定(0x01b2で0x00495119だった)
  4041. WBUFL(buf,15+57)=0x0000003e; //57-60調べた限り固定
  4042. WBUFL(buf,15+61)=0x0012f66c; //61-64調べた限り固定
  4043. //65-68
  4044. //69-72
  4045. if(bl) WBUFL(buf,15+73)=bl->y; //73-76術者のY座標
  4046. WBUFL(buf,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  4047. WBUFB(buf,15+81)=0xaa; //81終端文字0xaa
  4048. }
  4049. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4050. #endif
  4051. return 0;
  4052. */
  4053. }
  4054. /*==========================================
  4055. * 場所スキルエフェクト削除
  4056. *------------------------------------------*/
  4057. int clif_skill_delunit(struct skill_unit *unit)
  4058. {
  4059. unsigned char buf[16];
  4060. nullpo_retr(0, unit);
  4061. WBUFW(buf, 0)=0x120;
  4062. WBUFL(buf, 2)=unit->bl.id;
  4063. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4064. return 0;
  4065. }
  4066. /*==========================================
  4067. * ワープ場所選択
  4068. *------------------------------------------*/
  4069. int clif_skill_warppoint(struct map_session_data *sd,int skill_num,int skill_lv,
  4070. const char *map1,const char *map2,const char *map3,const char *map4)
  4071. {
  4072. int fd;
  4073. nullpo_retr(0, sd);
  4074. fd=sd->fd;
  4075. WFIFOHEAD(fd,packet_len(0x11c));
  4076. WFIFOW(fd,0)=0x11c;
  4077. WFIFOW(fd,2)=skill_num;
  4078. strncpy((char*)WFIFOP(fd, 4),map1,MAP_NAME_LENGTH_EXT);
  4079. strncpy((char*)WFIFOP(fd,20),map2,MAP_NAME_LENGTH_EXT);
  4080. strncpy((char*)WFIFOP(fd,36),map3,MAP_NAME_LENGTH_EXT);
  4081. strncpy((char*)WFIFOP(fd,52),map4,MAP_NAME_LENGTH_EXT);
  4082. WFIFOSET(fd,packet_len(0x11c));
  4083. sd->menuskill_id = skill_num;
  4084. if (skill_num == AL_WARP)
  4085. sd->menuskill_lv = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4086. else
  4087. sd->menuskill_lv = skill_lv;
  4088. return 0;
  4089. }
  4090. /*==========================================
  4091. * メモ応答
  4092. *------------------------------------------*/
  4093. int clif_skill_memo(struct map_session_data *sd,int flag)
  4094. {
  4095. int fd;
  4096. nullpo_retr(0, sd);
  4097. fd=sd->fd;
  4098. WFIFOHEAD(fd,packet_len(0x11e));
  4099. WFIFOW(fd,0)=0x11e;
  4100. WFIFOB(fd,2)=flag;
  4101. WFIFOSET(fd,packet_len(0x11e));
  4102. return 0;
  4103. }
  4104. int clif_skill_teleportmessage(struct map_session_data *sd,int flag)
  4105. {
  4106. int fd;
  4107. nullpo_retr(0, sd);
  4108. fd=sd->fd;
  4109. WFIFOHEAD(fd,packet_len(0x189));
  4110. WFIFOW(fd,0)=0x189;
  4111. WFIFOW(fd,2)=flag;
  4112. WFIFOSET(fd,packet_len(0x189));
  4113. return 0;
  4114. }
  4115. /*==========================================
  4116. * モンスター情報
  4117. *------------------------------------------*/
  4118. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4119. {
  4120. struct status_data *status;
  4121. unsigned char buf[64];
  4122. int i;//, fix;
  4123. nullpo_retr(0, sd);
  4124. nullpo_retr(0, dst);
  4125. if(dst->type!=BL_MOB )
  4126. return 0;
  4127. status = status_get_status_data(dst);
  4128. WBUFW(buf, 0)=0x18c;
  4129. WBUFW(buf, 2)=status_get_class(dst);
  4130. WBUFW(buf, 4)=status_get_lv(dst);
  4131. WBUFW(buf, 6)=status->size;
  4132. WBUFL(buf, 8)=status->hp;
  4133. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4134. +(battle_config.estimation_type&2?status->def2:0);
  4135. WBUFW(buf,14)=status->race;
  4136. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4137. +(battle_config.estimation_type&2?status->mdef2:0);
  4138. WBUFW(buf,18)= status->def_ele;
  4139. for(i=0;i<9;i++)
  4140. WBUFB(buf,20+i)= (unsigned char)battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv);
  4141. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4142. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4143. clif_send(buf,packet_len(0x18c),&sd->bl,
  4144. sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4145. return 0;
  4146. }
  4147. /*==========================================
  4148. * アイテム合成可能リスト
  4149. *------------------------------------------*/
  4150. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  4151. {
  4152. int i,c,view,fd;
  4153. nullpo_retr(0, sd);
  4154. if(sd->menuskill_id == AM_PHARMACY)
  4155. return 0; //Avoid resending the menu twice or more times...
  4156. fd=sd->fd;
  4157. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4158. WFIFOW(fd, 0)=0x18d;
  4159. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4160. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4161. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4162. WFIFOW(fd,c*8+ 4)= view;
  4163. else
  4164. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4165. WFIFOW(fd,c*8+ 6)= 0x0012;
  4166. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  4167. c++;
  4168. }
  4169. }
  4170. WFIFOW(fd, 2)=c*8+8;
  4171. WFIFOSET(fd,WFIFOW(fd,2));
  4172. if(c > 0) {
  4173. sd->menuskill_id = AM_PHARMACY;
  4174. sd->menuskill_lv = trigger;
  4175. return 1;
  4176. }
  4177. return 0;
  4178. }
  4179. /*==========================================
  4180. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  4181. *------------------------------------------*/
  4182. int clif_status_load(struct block_list *bl,int type, int flag)
  4183. {
  4184. int fd;
  4185. if (type == SI_BLANK) //It shows nothing on the client...
  4186. return 0;
  4187. if (bl->type != BL_PC)
  4188. return 0;
  4189. fd = ((struct map_session_data*)bl)->fd;
  4190. WFIFOHEAD(fd,packet_len(0x196));
  4191. WFIFOW(fd,0)=0x0196;
  4192. WFIFOW(fd,2)=type;
  4193. WFIFOL(fd,4)=bl->id;
  4194. WFIFOB(fd,8)=flag; //Status start
  4195. WFIFOSET(fd, packet_len(0x196));
  4196. return 0;
  4197. }
  4198. /*==========================================
  4199. * 状態異常アイコン/メッセージ表示
  4200. *------------------------------------------*/
  4201. int clif_status_change(struct block_list *bl,int type,int flag)
  4202. {
  4203. unsigned char buf[16];
  4204. if (type == SI_BLANK) //It shows nothing on the client...
  4205. return 0;
  4206. nullpo_retr(0, bl);
  4207. WBUFW(buf,0)=0x0196;
  4208. WBUFW(buf,2)=type;
  4209. WBUFL(buf,4)=bl->id;
  4210. WBUFB(buf,8)=flag;
  4211. clif_send(buf,packet_len(0x196),bl,AREA);
  4212. return 0;
  4213. }
  4214. /*==========================================
  4215. * Send message (modified by [Yor])
  4216. *------------------------------------------*/
  4217. int clif_displaymessage(const int fd, const char* mes)
  4218. {
  4219. // invalid pointer?
  4220. nullpo_retr(-1, mes);
  4221. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4222. if (fd == 0)
  4223. return 0;
  4224. else {
  4225. int len_mes = strlen(mes);
  4226. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4227. WFIFOHEAD(fd, 5 + len_mes);
  4228. WFIFOW(fd,0) = 0x8e;
  4229. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  4230. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  4231. WFIFOSET(fd, 5 + len_mes);
  4232. }
  4233. }
  4234. return 0;
  4235. }
  4236. /*==========================================
  4237. * 天の声を送信する
  4238. *------------------------------------------*/
  4239. int clif_GMmessage(struct block_list* bl, const char* mes, int len, int flag)
  4240. {
  4241. unsigned char *buf;
  4242. int lp;
  4243. lp = (flag & 0x10) ? 8 : 4;
  4244. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  4245. WBUFW(buf,0) = 0x9a;
  4246. WBUFW(buf,2) = len + lp;
  4247. WBUFL(buf,4) = 0x65756c62; //"blue":
  4248. memcpy(WBUFP(buf,lp), mes, len);
  4249. flag &= 0x07;
  4250. clif_send(buf, WBUFW(buf,2), bl,
  4251. (flag == 1) ? ALL_SAMEMAP :
  4252. (flag == 2) ? AREA :
  4253. (flag == 3) ? SELF :
  4254. ALL_CLIENT);
  4255. if(buf) aFree(buf);
  4256. if(use_irc && irc_announce_flag && !flag)
  4257. irc_announce(mes);
  4258. return 0;
  4259. }
  4260. /*==========================================
  4261. * グローバルメッセージ
  4262. *------------------------------------------*/
  4263. void clif_GlobalMessage(struct block_list* bl, const char* message)
  4264. {
  4265. char buf[100];
  4266. int len;
  4267. nullpo_retv(bl);
  4268. if(!message)
  4269. return;
  4270. len = strlen(message)+1;
  4271. WBUFW(buf,0)=0x8d;
  4272. WBUFW(buf,2)=len+8;
  4273. WBUFL(buf,4)=bl->id;
  4274. strncpy((char *) WBUFP(buf,8),message,len);
  4275. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4276. }
  4277. /*==========================================
  4278. * Send main chat message [LuzZza]
  4279. *------------------------------------------*/
  4280. void clif_MainChatMessage(const char* message)
  4281. {
  4282. char buf[200];
  4283. int len;
  4284. if(!message)
  4285. return;
  4286. len = strlen(message)+1;
  4287. if (len+8 > sizeof(buf)) {
  4288. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4289. len = sizeof(buf)-8;
  4290. }
  4291. WBUFW(buf,0)=0x8d;
  4292. WBUFW(buf,2)=len+8;
  4293. WBUFL(buf,4)=0;
  4294. strncpy((char *) WBUFP(buf,8),message,len);
  4295. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4296. }
  4297. /*==========================================
  4298. * Does an announce message in the given color.
  4299. *------------------------------------------*/
  4300. int clif_announce(struct block_list* bl, const char* mes, int len, unsigned long color, int flag)
  4301. {
  4302. unsigned char *buf;
  4303. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4304. WBUFW(buf,0) = 0x1c3;
  4305. WBUFW(buf,2) = len + 16;
  4306. WBUFL(buf,4) = color;
  4307. WBUFW(buf,8) = 0x190; //Font style? Type?
  4308. WBUFW(buf,10) = 0x0c; //12? Font size?
  4309. WBUFL(buf,12) = 0; //Unknown!
  4310. memcpy(WBUFP(buf,16), mes, len);
  4311. flag &= 0x07;
  4312. clif_send(buf, WBUFW(buf,2), bl,
  4313. (flag == 1) ? ALL_SAMEMAP :
  4314. (flag == 2) ? AREA :
  4315. (flag == 3) ? SELF :
  4316. ALL_CLIENT);
  4317. if(buf) aFree(buf);
  4318. return 0;
  4319. }
  4320. /*==========================================
  4321. * HPSP回復エフェクトを送信する
  4322. *------------------------------------------*/
  4323. int clif_heal(int fd,int type,int val)
  4324. {
  4325. WFIFOHEAD(fd,packet_len(0x13d));
  4326. WFIFOW(fd,0)=0x13d;
  4327. WFIFOW(fd,2)=type;
  4328. WFIFOW(fd,4)=cap_value(val,0,SHRT_MAX);
  4329. WFIFOSET(fd,packet_len(0x13d));
  4330. return 0;
  4331. }
  4332. /*==========================================
  4333. * 復活する
  4334. *------------------------------------------*/
  4335. int clif_resurrection(struct block_list *bl,int type)
  4336. {
  4337. unsigned char buf[16];
  4338. nullpo_retr(0, bl);
  4339. WBUFW(buf,0)=0x148;
  4340. WBUFL(buf,2)=bl->id;
  4341. WBUFW(buf,6)=type;
  4342. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4343. if (disguised(bl))
  4344. clif_spawn(bl);
  4345. return 0;
  4346. }
  4347. /*==========================================
  4348. * PVP実装?(仮)
  4349. *------------------------------------------*/
  4350. int clif_set0199(int fd,int type)
  4351. {
  4352. WFIFOHEAD(fd,packet_len(0x199));
  4353. WFIFOW(fd,0)=0x199;
  4354. WFIFOW(fd,2)=type;
  4355. WFIFOSET(fd,packet_len(0x199));
  4356. return 0;
  4357. }
  4358. /*==========================================
  4359. * PVP実装?(仮)
  4360. *------------------------------------------*/
  4361. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4362. {
  4363. int fd = sd->fd;
  4364. if(type == 2) {
  4365. WFIFOHEAD(fd,packet_len(0x19a));
  4366. WFIFOW(fd,0) = 0x19a;
  4367. WFIFOL(fd,2) = sd->bl.id;
  4368. WFIFOL(fd,6) = pvprank;
  4369. WFIFOL(fd,10) = pvpnum;
  4370. WFIFOSET(fd,packet_len(0x19a));
  4371. } else {
  4372. unsigned char buf[32];
  4373. WBUFW(buf,0) = 0x19a;
  4374. WBUFL(buf,2) = sd->bl.id;
  4375. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4376. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4377. else
  4378. WBUFL(buf,6) = pvprank;
  4379. WBUFL(buf,10) = pvpnum;
  4380. if(sd->sc.option&OPTION_INVISIBLE)
  4381. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4382. else if(!type)
  4383. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4384. else
  4385. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4386. }
  4387. return 0;
  4388. }
  4389. /*==========================================
  4390. *
  4391. *------------------------------------------*/
  4392. int clif_send0199(int map,int type)
  4393. {
  4394. struct block_list bl;
  4395. unsigned char buf[16];
  4396. bl.id = 0;
  4397. bl.type = BL_NUL;
  4398. bl.m = map;
  4399. WBUFW(buf,0)=0x199;
  4400. WBUFW(buf,2)=type;
  4401. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4402. return 0;
  4403. }
  4404. /*==========================================
  4405. * 精錬エフェクトを送信する
  4406. *------------------------------------------*/
  4407. void clif_refine(int fd, int fail, int index, int val)
  4408. {
  4409. WFIFOHEAD(fd,packet_len(0x188));
  4410. WFIFOW(fd,0)=0x188;
  4411. WFIFOW(fd,2)=fail;
  4412. WFIFOW(fd,4)=index+2;
  4413. WFIFOW(fd,6)=val;
  4414. WFIFOSET(fd,packet_len(0x188));
  4415. }
  4416. /// result=0: "weapon upgrated: %s" MsgStringTable[911] in rgb(0,255,255)
  4417. /// result=1: "weapon upgrated: %s" MsgStringTable[912] in rgb(0,205,205)
  4418. /// result=2: "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4419. /// result=3: "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4420. void clif_upgrademessage(int fd, int result, int item_id)
  4421. {
  4422. WFIFOHEAD(fd,packet_len(0x223));
  4423. WFIFOW(fd,0)=0x223;
  4424. WFIFOL(fd,2)=result;
  4425. WFIFOW(fd,6)=item_id;
  4426. WFIFOSET(fd,packet_len(0x223));
  4427. }
  4428. /*==========================================
  4429. * Wisp/page is transmitted to the destination player
  4430. *------------------------------------------*/
  4431. int clif_wis_message(int fd, const char* nick, const char* mes, int mes_len) // R 0097 <len>.w <nick>.24B <message>.?B
  4432. {
  4433. // printf("clif_wis_message(%d, %s, %s)\n", fd, nick, mes);
  4434. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4435. WFIFOW(fd,0) = 0x97;
  4436. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4437. memcpy(WFIFOP(fd,4), nick, NAME_LENGTH);
  4438. memcpy(WFIFOP(fd,28), mes, mes_len);
  4439. WFIFOSET(fd,WFIFOW(fd,2));
  4440. return 0;
  4441. }
  4442. /*==========================================
  4443. * Inform the player about the result of his whisper action
  4444. * R 0098 <type>.B
  4445. * 0: success to send wisper
  4446. * 1: target character is not loged in
  4447. * 2: ignored by target
  4448. * 3: everyone ignored by target
  4449. *------------------------------------------*/
  4450. int clif_wis_end(int fd, int flag)
  4451. {
  4452. WFIFOHEAD(fd,packet_len(0x98));
  4453. WFIFOW(fd,0) = 0x98;
  4454. WFIFOW(fd,2) = flag;
  4455. WFIFOSET(fd,packet_len(0x98));
  4456. return 0;
  4457. }
  4458. /*==========================================
  4459. * キャラID名前引き結果を送信する
  4460. *------------------------------------------*/
  4461. int clif_solved_charname(struct map_session_data *sd,int char_id)
  4462. {
  4463. char *p= map_charid2nick(char_id);
  4464. int fd;
  4465. nullpo_retr(0, sd);
  4466. fd=sd->fd;
  4467. if(p!=NULL){
  4468. WFIFOHEAD(fd,packet_len(0x194));
  4469. WFIFOW(fd,0)=0x194;
  4470. WFIFOL(fd,2)=char_id;
  4471. memcpy(WFIFOP(fd,6), p, NAME_LENGTH);
  4472. WFIFOSET(fd,packet_len(0x194));
  4473. }else{
  4474. map_reqchariddb(sd,char_id);
  4475. chrif_searchcharid(char_id);
  4476. }
  4477. return 0;
  4478. }
  4479. /*==========================================
  4480. * カードの挿入可能リストを返す
  4481. *------------------------------------------*/
  4482. int clif_use_card(struct map_session_data *sd,int idx)
  4483. {
  4484. int i,c,ep;
  4485. int fd=sd->fd;
  4486. nullpo_retr(0, sd);
  4487. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4488. return 0;
  4489. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4490. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4491. ep=sd->inventory_data[idx]->equip;
  4492. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4493. WFIFOW(fd,0)=0x017b;
  4494. for(i=c=0;i<MAX_INVENTORY;i++){
  4495. int j;
  4496. if(sd->inventory_data[i] == NULL)
  4497. continue;
  4498. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4499. continue;
  4500. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4501. continue;
  4502. if(sd->status.inventory[i].identify==0 ) //Not identified
  4503. continue;
  4504. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4505. continue;
  4506. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_HAND_L) //Shield card won't go on left weapon.
  4507. continue;
  4508. for(j=0;j<sd->inventory_data[i]->slot;j++){
  4509. if( sd->status.inventory[i].card[j]==0 )
  4510. break;
  4511. }
  4512. if(j==sd->inventory_data[i]->slot) // No room
  4513. continue;
  4514. WFIFOW(fd,4+c*2)=i+2;
  4515. c++;
  4516. }
  4517. WFIFOW(fd,2)=4+c*2;
  4518. WFIFOSET(fd,WFIFOW(fd,2));
  4519. return 0;
  4520. }
  4521. /*==========================================
  4522. * カードの挿入終了
  4523. *------------------------------------------*/
  4524. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4525. {
  4526. int fd;
  4527. nullpo_retr(0, sd);
  4528. fd=sd->fd;
  4529. WFIFOHEAD(fd,packet_len(0x17d));
  4530. WFIFOW(fd,0)=0x17d;
  4531. WFIFOW(fd,2)=idx_equip+2;
  4532. WFIFOW(fd,4)=idx_card+2;
  4533. WFIFOB(fd,6)=flag;
  4534. WFIFOSET(fd,packet_len(0x17d));
  4535. return 0;
  4536. }
  4537. /*==========================================
  4538. * 鑑定可能アイテムリスト送信
  4539. *------------------------------------------*/
  4540. int clif_item_identify_list(struct map_session_data *sd)
  4541. {
  4542. int i,c;
  4543. int fd;
  4544. nullpo_retr(0, sd);
  4545. fd=sd->fd;
  4546. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4547. WFIFOW(fd,0)=0x177;
  4548. for(i=c=0;i<MAX_INVENTORY;i++){
  4549. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4550. WFIFOW(fd,c*2+4)=i+2;
  4551. c++;
  4552. }
  4553. }
  4554. if(c > 0) {
  4555. WFIFOW(fd,2)=c*2+4;
  4556. WFIFOSET(fd,WFIFOW(fd,2));
  4557. sd->menuskill_id = MC_IDENTIFY;
  4558. sd->menuskill_lv = c;
  4559. }
  4560. return 0;
  4561. }
  4562. /*==========================================
  4563. * 鑑定結果
  4564. *------------------------------------------*/
  4565. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4566. {
  4567. int fd;
  4568. nullpo_retr(0, sd);
  4569. fd=sd->fd;
  4570. WFIFOHEAD(fd,packet_len(0x179));
  4571. WFIFOW(fd, 0)=0x179;
  4572. WFIFOW(fd, 2)=idx+2;
  4573. WFIFOB(fd, 4)=flag;
  4574. WFIFOSET(fd,packet_len(0x179));
  4575. return 0;
  4576. }
  4577. /*==========================================
  4578. * 修理可能アイテムリスト送信
  4579. *------------------------------------------*/
  4580. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4581. {
  4582. int i,c;
  4583. int fd;
  4584. int nameid;
  4585. nullpo_retr(0, sd);
  4586. nullpo_retr(0, dstsd);
  4587. fd=sd->fd;
  4588. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4589. WFIFOW(fd,0)=0x1fc;
  4590. for(i=c=0;i<MAX_INVENTORY;i++){
  4591. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4592. WFIFOW(fd,c*13+4) = i;
  4593. WFIFOW(fd,c*13+6) = nameid;
  4594. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4595. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4596. WFIFOB(fd,c*13+16)= c;
  4597. c++;
  4598. }
  4599. }
  4600. if(c > 0) {
  4601. WFIFOW(fd,2)=c*13+4;
  4602. WFIFOSET(fd,WFIFOW(fd,2));
  4603. sd->menuskill_id = BS_REPAIRWEAPON;
  4604. sd->menuskill_lv = dstsd->bl.id;
  4605. }else
  4606. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4607. return 0;
  4608. }
  4609. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4610. {
  4611. int view,fd;
  4612. nullpo_retr(0, sd);
  4613. fd=sd->fd;
  4614. WFIFOHEAD(fd,packet_len(0x1fe));
  4615. WFIFOW(fd, 0)=0x1fe;
  4616. if((view = itemdb_viewid(nameid)) > 0)
  4617. WFIFOW(fd, 2)=view;
  4618. else
  4619. WFIFOW(fd, 2)=nameid;
  4620. WFIFOB(fd, 4)=flag;
  4621. WFIFOSET(fd,packet_len(0x1fe));
  4622. return 0;
  4623. }
  4624. /*==========================================
  4625. * Weapon Refining - Taken from jAthena
  4626. *------------------------------------------*/
  4627. int clif_item_refine_list(struct map_session_data *sd)
  4628. {
  4629. int i,c;
  4630. int fd;
  4631. int skilllv;
  4632. int wlv;
  4633. int refine_item[5];
  4634. nullpo_retr(0, sd);
  4635. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4636. fd=sd->fd;
  4637. refine_item[0] = -1;
  4638. refine_item[1] = pc_search_inventory(sd,1010);
  4639. refine_item[2] = pc_search_inventory(sd,1011);
  4640. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4641. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4642. WFIFOW(fd,0)=0x221;
  4643. for(i=c=0;i<MAX_INVENTORY;i++){
  4644. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4645. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4646. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4647. WFIFOW(fd,c*13+ 4)=i+2;
  4648. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4649. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4650. WFIFOW(fd,c*13+10)=0;
  4651. WFIFOB(fd,c*13+12)=c;
  4652. c++;
  4653. }
  4654. }
  4655. WFIFOW(fd,2)=c*13+4;
  4656. WFIFOSET(fd,WFIFOW(fd,2));
  4657. if (c > 0) {
  4658. sd->menuskill_id = WS_WEAPONREFINE;
  4659. sd->menuskill_lv = skilllv;
  4660. }
  4661. return 0;
  4662. }
  4663. /*==========================================
  4664. * アイテムによる一時的なスキル効果
  4665. *------------------------------------------*/
  4666. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  4667. {
  4668. int fd;
  4669. nullpo_retr(0, sd);
  4670. fd=sd->fd;
  4671. WFIFOHEAD(fd,packet_len(0x147));
  4672. WFIFOW(fd, 0)=0x147;
  4673. WFIFOW(fd, 2)=skillid;
  4674. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4675. WFIFOW(fd, 6)=0;
  4676. WFIFOW(fd, 8)=skilllv;
  4677. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4678. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4679. strncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  4680. WFIFOB(fd,38)=0;
  4681. WFIFOSET(fd,packet_len(0x147));
  4682. return 0;
  4683. }
  4684. /*==========================================
  4685. * カートにアイテム追加
  4686. *------------------------------------------*/
  4687. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4688. {
  4689. int view,fd;
  4690. unsigned char *buf;
  4691. nullpo_retr(0, sd);
  4692. fd=sd->fd;
  4693. WFIFOHEAD(fd,packet_len(0x124));
  4694. buf=WFIFOP(fd,0);
  4695. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4696. return 1;
  4697. WBUFW(buf,0)=0x124;
  4698. WBUFW(buf,2)=n+2;
  4699. WBUFL(buf,4)=amount;
  4700. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4701. WBUFW(buf,8)=view;
  4702. else
  4703. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4704. WBUFB(buf,10)=sd->status.cart[n].identify;
  4705. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4706. WBUFB(buf,12)=sd->status.cart[n].refine;
  4707. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4708. WFIFOSET(fd,packet_len(0x124));
  4709. return 0;
  4710. }
  4711. /*==========================================
  4712. * カートからアイテム削除
  4713. *------------------------------------------*/
  4714. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4715. {
  4716. int fd;
  4717. nullpo_retr(0, sd);
  4718. fd=sd->fd;
  4719. WFIFOHEAD(fd,packet_len(0x125));
  4720. WFIFOW(fd,0)=0x125;
  4721. WFIFOW(fd,2)=n+2;
  4722. WFIFOL(fd,4)=amount;
  4723. WFIFOSET(fd,packet_len(0x125));
  4724. return 0;
  4725. }
  4726. /*==========================================
  4727. * 露店開設
  4728. *------------------------------------------*/
  4729. int clif_openvendingreq(struct map_session_data *sd,int num)
  4730. {
  4731. int fd;
  4732. nullpo_retr(0, sd);
  4733. fd=sd->fd;
  4734. WFIFOHEAD(fd,packet_len(0x12d));
  4735. WFIFOW(fd,0)=0x12d;
  4736. WFIFOW(fd,2)=num;
  4737. WFIFOSET(fd,packet_len(0x12d));
  4738. return 0;
  4739. }
  4740. /*==========================================
  4741. * 露店看板表示
  4742. *------------------------------------------*/
  4743. int clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  4744. {
  4745. unsigned char buf[128];
  4746. nullpo_retr(0, bl);
  4747. WBUFW(buf,0)=0x131;
  4748. WBUFL(buf,2)=bl->id;
  4749. strncpy((char*)WBUFP(buf,6),message,80);
  4750. if(fd){
  4751. WFIFOHEAD(fd,packet_len(0x131));
  4752. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  4753. WFIFOSET(fd,packet_len(0x131));
  4754. }else{
  4755. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  4756. }
  4757. return 0;
  4758. }
  4759. /*==========================================
  4760. * 露店看板消去
  4761. *------------------------------------------*/
  4762. int clif_closevendingboard(struct block_list* bl,int fd)
  4763. {
  4764. unsigned char buf[16];
  4765. nullpo_retr(0, bl);
  4766. WBUFW(buf,0)=0x132;
  4767. WBUFL(buf,2)=bl->id;
  4768. if(fd){
  4769. WFIFOHEAD(fd,packet_len(0x132));
  4770. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  4771. WFIFOSET(fd,packet_len(0x132));
  4772. }else{
  4773. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  4774. }
  4775. return 0;
  4776. }
  4777. /*==========================================
  4778. * 露店アイテムリスト
  4779. *------------------------------------------*/
  4780. int clif_vendinglist(struct map_session_data *sd,int id,struct vending *vending)
  4781. {
  4782. struct item_data *data;
  4783. int i,n,index,fd;
  4784. struct map_session_data *vsd;
  4785. unsigned char *buf;
  4786. nullpo_retr(0, sd);
  4787. nullpo_retr(0, vending);
  4788. nullpo_retr(0, vsd=map_id2sd(id));
  4789. fd=sd->fd;
  4790. WFIFOHEAD(fd, 8+vsd->vend_num*22);
  4791. buf = WFIFOP(fd,0);
  4792. for(i=0,n=0;i<vsd->vend_num;i++){
  4793. if(vending[i].amount<=0)
  4794. continue;
  4795. WBUFL(buf,8+n*22)=vending[i].value;
  4796. WBUFW(buf,12+n*22)=vending[i].amount;
  4797. WBUFW(buf,14+n*22)=(index=vending[i].index)+2;
  4798. if(vsd->status.cart[index].nameid <= 0 || vsd->status.cart[index].amount <= 0)
  4799. continue;
  4800. data = itemdb_search(vsd->status.cart[index].nameid);
  4801. WBUFB(buf,16+n*22)=itemtype(data->type);
  4802. if(data->view_id > 0)
  4803. WBUFW(buf,17+n*22)=data->view_id;
  4804. else
  4805. WBUFW(buf,17+n*22)=vsd->status.cart[index].nameid;
  4806. WBUFB(buf,19+n*22)=vsd->status.cart[index].identify;
  4807. WBUFB(buf,20+n*22)=vsd->status.cart[index].attribute;
  4808. WBUFB(buf,21+n*22)=vsd->status.cart[index].refine;
  4809. clif_addcards(WBUFP(buf, 22+n*22), &vsd->status.cart[index]);
  4810. n++;
  4811. }
  4812. if(n > 0){
  4813. WBUFW(buf,0)=0x133;
  4814. WBUFW(buf,2)=8+n*22;
  4815. WBUFL(buf,4)=id;
  4816. WFIFOSET(fd,WFIFOW(fd,2));
  4817. }
  4818. return 0;
  4819. }
  4820. /*==========================================
  4821. * 露店アイテム購入失敗
  4822. *------------------------------------------*/
  4823. int clif_buyvending(struct map_session_data *sd,int index,int amount,int fail)
  4824. {
  4825. int fd;
  4826. nullpo_retr(0, sd);
  4827. fd=sd->fd;
  4828. WFIFOHEAD(fd,packet_len(0x135));
  4829. WFIFOW(fd,0)=0x135;
  4830. WFIFOW(fd,2)=index+2;
  4831. WFIFOW(fd,4)=amount;
  4832. WFIFOB(fd,6)=fail;
  4833. WFIFOSET(fd,packet_len(0x135));
  4834. return 0;
  4835. }
  4836. /*==========================================
  4837. * 露店開設成功
  4838. *------------------------------------------*/
  4839. int clif_openvending(struct map_session_data *sd,int id,struct vending *vending)
  4840. {
  4841. struct item_data *data;
  4842. int i,n,index,fd;
  4843. unsigned char *buf;
  4844. nullpo_retr(0, sd);
  4845. fd=sd->fd;
  4846. WFIFOHEAD(fd, 8+sd->vend_num*22);
  4847. buf = WFIFOP(fd,0);
  4848. for(i = 0, n = 0; i < sd->vend_num; i++) {
  4849. if (sd->vend_num > 2+pc_checkskill(sd,MC_VENDING)) return 0;
  4850. WBUFL(buf,8+n*22)=vending[i].value;
  4851. WBUFW(buf,12+n*22)=(index=vending[i].index)+2;
  4852. WBUFW(buf,14+n*22)=vending[i].amount;
  4853. if(sd->status.cart[index].nameid <= 0 || sd->status.cart[index].amount <= 0 || !sd->status.cart[index].identify ||
  4854. sd->status.cart[index].attribute==1) // Prevent unidentified and broken items from being sold [Valaris]
  4855. continue;
  4856. data = itemdb_search(sd->status.cart[index].nameid);
  4857. WBUFB(buf,16+n*22)=itemtype(data->type);
  4858. if(data->view_id > 0)
  4859. WBUFW(buf,17+n*22)=data->view_id;
  4860. else
  4861. WBUFW(buf,17+n*22)=sd->status.cart[index].nameid;
  4862. WBUFB(buf,19+n*22)=sd->status.cart[index].identify;
  4863. WBUFB(buf,20+n*22)=sd->status.cart[index].attribute;
  4864. WBUFB(buf,21+n*22)=sd->status.cart[index].refine;
  4865. clif_addcards(WBUFP(buf, 22+n*22), &sd->status.cart[index]);
  4866. n++;
  4867. }
  4868. if(n > 0) {
  4869. WBUFW(buf,0)=0x136;
  4870. WBUFW(buf,2)=8+n*22;
  4871. WBUFL(buf,4)=id;
  4872. WFIFOSET(fd,WFIFOW(fd,2));
  4873. }
  4874. return n;
  4875. }
  4876. /*==========================================
  4877. * 露店アイテム販売報告
  4878. *------------------------------------------*/
  4879. int clif_vendingreport(struct map_session_data *sd,int index,int amount)
  4880. {
  4881. int fd;
  4882. nullpo_retr(0, sd);
  4883. fd=sd->fd;
  4884. WFIFOHEAD(fd,packet_len(0x137));
  4885. WFIFOW(fd,0)=0x137;
  4886. WFIFOW(fd,2)=index+2;
  4887. WFIFOW(fd,4)=amount;
  4888. WFIFOSET(fd,packet_len(0x137));
  4889. return 0;
  4890. }
  4891. /*==========================================
  4892. * パーティ作成完了
  4893. *------------------------------------------*/
  4894. int clif_party_created(struct map_session_data *sd,int flag)
  4895. {
  4896. int fd;
  4897. nullpo_retr(0, sd);
  4898. fd=sd->fd;
  4899. WFIFOHEAD(fd,packet_len(0xfa));
  4900. WFIFOW(fd,0)=0xfa;
  4901. WFIFOB(fd,2)=flag;
  4902. WFIFOSET(fd,packet_len(0xfa));
  4903. return 0;
  4904. }
  4905. int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  4906. {
  4907. unsigned char buf[96];
  4908. char map_name[MAP_NAME_LENGTH_EXT];
  4909. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  4910. int i;
  4911. for (i=0; i<MAX_PARTY && !p->data[i].sd; i++);
  4912. if (i >= MAX_PARTY) return 0; //Should never happen...
  4913. sd = p->data[i].sd;
  4914. }
  4915. snprintf(map_name, MAP_NAME_LENGTH_EXT, "%s.gat", mapindex_id2name(sd->mapindex));
  4916. WBUFW(buf,0)=0x1e9;
  4917. WBUFL(buf,2)= sd->status.account_id;
  4918. WBUFL(buf,6)= 0; //Apparently setting this to 1 makes you adoptable.
  4919. WBUFW(buf,10)=sd->bl.x;
  4920. WBUFW(buf,12)=sd->bl.y;
  4921. WBUFB(buf,14)=0; //Unconfirmed byte, could be online/offline.
  4922. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  4923. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  4924. memcpy(WBUFP(buf,63), map_name, MAP_NAME_LENGTH_EXT);
  4925. WBUFB(buf,79) = (p->party.item&1)?1:0;
  4926. WBUFB(buf,80) = (p->party.item&2)?1:0;
  4927. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  4928. return 1;
  4929. }
  4930. /*==========================================
  4931. * Sends party information
  4932. * R 00fb <len>.w <party name>.24B {<ID>.l <nick>.24B <map name>.16B <leader>.B <offline>.B}.46B*
  4933. *------------------------------------------*/
  4934. int clif_party_info(struct party_data* p, struct map_session_data *sd)
  4935. {
  4936. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  4937. struct map_session_data* party_sd = NULL;
  4938. int i, c;
  4939. nullpo_retr(0, p);
  4940. WBUFW(buf,0) = 0xfb;
  4941. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  4942. for(i = 0, c = 0; i < MAX_PARTY; i++)
  4943. {
  4944. struct party_member* m = &p->party.member[i];
  4945. char map_name[MAP_NAME_LENGTH_EXT];
  4946. if(!m->account_id) continue;
  4947. if(party_sd == NULL) party_sd = p->data[i].sd;
  4948. snprintf(map_name, MAP_NAME_LENGTH_EXT, "%s.gat", mapindex_id2name(m->map));
  4949. WBUFL(buf,28+c*46) = m->account_id;
  4950. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  4951. memcpy(WBUFP(buf,28+c*46+28), map_name, MAP_NAME_LENGTH_EXT);
  4952. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  4953. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  4954. c++;
  4955. }
  4956. WBUFW(buf,2) = 28+c*46;
  4957. if(sd) { // send only to self
  4958. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  4959. } else if (party_sd) { // send to whole party
  4960. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  4961. }
  4962. return 0;
  4963. }
  4964. /*==========================================
  4965. * パーティ勧誘
  4966. *------------------------------------------*/
  4967. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  4968. {
  4969. int fd;
  4970. struct party_data *p;
  4971. nullpo_retr(0, sd);
  4972. nullpo_retr(0, tsd);
  4973. fd=tsd->fd;
  4974. if( (p=party_search(sd->status.party_id))==NULL )
  4975. return 0;
  4976. WFIFOHEAD(fd,packet_len(0xfe));
  4977. WFIFOW(fd,0)=0xfe;
  4978. WFIFOL(fd,2)=sd->status.account_id;
  4979. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  4980. WFIFOSET(fd,packet_len(0xfe));
  4981. return 0;
  4982. }
  4983. /*==========================================
  4984. * Party invitation result. Flag values are:
  4985. * 0 -> char is already in a party
  4986. * 1 -> party invite was rejected
  4987. * 2 -> party invite was accepted
  4988. * 3 -> party is full
  4989. * 4 -> char of the same account already joined the party
  4990. *------------------------------------------*/
  4991. int clif_party_inviteack(struct map_session_data* sd, const char* nick, int flag)
  4992. {
  4993. int fd;
  4994. nullpo_retr(0, sd);
  4995. fd=sd->fd;
  4996. WFIFOHEAD(fd,packet_len(0xfd));
  4997. WFIFOW(fd,0)=0xfd;
  4998. memcpy(WFIFOP(fd,2),nick,NAME_LENGTH);
  4999. WFIFOB(fd,26)=flag;
  5000. WFIFOSET(fd,packet_len(0xfd));
  5001. return 0;
  5002. }
  5003. /*==========================================
  5004. * パーティ設定送信
  5005. * flag & 0x001=exp変更ミス
  5006. * 0x010=item変更ミス
  5007. * 0x100=一人にのみ送信
  5008. *------------------------------------------*/
  5009. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5010. {
  5011. unsigned char buf[16];
  5012. nullpo_retr(0, p);
  5013. if(!sd && flag==0){
  5014. int i;
  5015. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5016. if (i < MAX_PARTY)
  5017. sd = p->data[i].sd;
  5018. }
  5019. if(!sd) return 0;
  5020. WBUFW(buf,0)=0x101;
  5021. // WBUFL(buf,2) // that's how the client reads it, still need to check it's uses [FlavioJS]
  5022. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  5023. WBUFW(buf,4)=0;
  5024. if(flag==0)
  5025. clif_send(buf,packet_len(0x101),&sd->bl,PARTY);
  5026. else
  5027. clif_send(buf,packet_len(0x101),&sd->bl,SELF);
  5028. return 0;
  5029. }
  5030. /*==========================================
  5031. * パーティ脱退(脱退前に呼ぶこと)
  5032. *------------------------------------------*/
  5033. int clif_party_leaved(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  5034. {
  5035. unsigned char buf[64];
  5036. int i;
  5037. nullpo_retr(0, p);
  5038. if(!sd && (flag&0xf0)==0)
  5039. {
  5040. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5041. if (i < MAX_PARTY)
  5042. sd = p->data[i].sd;
  5043. }
  5044. if(!sd) return 0;
  5045. WBUFW(buf,0)=0x105;
  5046. WBUFL(buf,2)=account_id;
  5047. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5048. WBUFB(buf,30)=flag&0x0f;
  5049. if((flag&0xf0)==0)
  5050. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  5051. else
  5052. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  5053. return 0;
  5054. }
  5055. /*==========================================
  5056. * パーティメッセージ送信
  5057. *------------------------------------------*/
  5058. int clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  5059. {
  5060. struct map_session_data *sd;
  5061. int i;
  5062. nullpo_retr(0, p);
  5063. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  5064. if(i < MAX_PARTY){
  5065. unsigned char buf[1024];
  5066. sd = p->data[i].sd;
  5067. WBUFW(buf,0)=0x109;
  5068. WBUFW(buf,2)=len+8;
  5069. WBUFL(buf,4)=account_id;
  5070. memcpy(WBUFP(buf,8),mes,len);
  5071. clif_send(buf,len+8,&sd->bl,PARTY);
  5072. }
  5073. return 0;
  5074. }
  5075. /*==========================================
  5076. * パーティ座標通知
  5077. *------------------------------------------*/
  5078. int clif_party_xy(struct map_session_data *sd)
  5079. {
  5080. unsigned char buf[16];
  5081. nullpo_retr(0, sd);
  5082. WBUFW(buf,0)=0x107;
  5083. WBUFL(buf,2)=sd->status.account_id;
  5084. WBUFW(buf,6)=sd->bl.x;
  5085. WBUFW(buf,8)=sd->bl.y;
  5086. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  5087. return 0;
  5088. }
  5089. /*==========================================
  5090. * Sends x/y dot to a single fd. [Skotlex]
  5091. *------------------------------------------*/
  5092. int clif_party_xy_single(int fd, struct map_session_data *sd)
  5093. {
  5094. WFIFOHEAD(fd,packet_len(0x107));
  5095. WFIFOW(fd,0)=0x107;
  5096. WFIFOL(fd,2)=sd->status.account_id;
  5097. WFIFOW(fd,6)=sd->bl.x;
  5098. WFIFOW(fd,8)=sd->bl.y;
  5099. WFIFOSET(fd,packet_len(0x107));
  5100. return 0;
  5101. }
  5102. /*==========================================
  5103. * パーティHP通知
  5104. *------------------------------------------*/
  5105. int clif_party_hp(struct map_session_data *sd)
  5106. {
  5107. unsigned char buf[16];
  5108. nullpo_retr(0, sd);
  5109. WBUFW(buf,0)=0x106;
  5110. WBUFL(buf,2)=sd->status.account_id;
  5111. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5112. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5113. WBUFW(buf,8) = 100;
  5114. } else {
  5115. WBUFW(buf,6) = sd->battle_status.hp;
  5116. WBUFW(buf,8) = sd->battle_status.max_hp;
  5117. }
  5118. clif_send(buf,packet_len(0x106),&sd->bl,PARTY_AREA_WOS);
  5119. return 0;
  5120. }
  5121. /*==========================================
  5122. * Sends HP bar to a single fd. [Skotlex]
  5123. *------------------------------------------*/
  5124. static void clif_hpmeter_single(int fd, struct map_session_data *sd)
  5125. {
  5126. WFIFOHEAD(fd,packet_len(0x106));
  5127. WFIFOW(fd,0) = 0x106;
  5128. WFIFOL(fd,2) = sd->status.account_id;
  5129. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5130. WFIFOW(fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5131. WFIFOW(fd,8) = 100;
  5132. } else {
  5133. WFIFOW(fd,6) = sd->battle_status.hp;
  5134. WFIFOW(fd,8) = sd->battle_status.max_hp;
  5135. }
  5136. WFIFOSET (fd, packet_len(0x106));
  5137. }
  5138. /*==========================================
  5139. * GMへ場所とHP通知
  5140. *------------------------------------------*/
  5141. int clif_hpmeter(struct map_session_data *sd)
  5142. {
  5143. struct map_session_data *sd2;
  5144. unsigned char buf[16];
  5145. int i, x0, y0, x1, y1;
  5146. int level;
  5147. nullpo_retr(0, sd);
  5148. x0 = sd->bl.x - AREA_SIZE;
  5149. y0 = sd->bl.y - AREA_SIZE;
  5150. x1 = sd->bl.x + AREA_SIZE;
  5151. y1 = sd->bl.y + AREA_SIZE;
  5152. WBUFW(buf,0) = 0x106;
  5153. WBUFL(buf,2) = sd->status.account_id;
  5154. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5155. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5156. WBUFW(buf,8) = 100;
  5157. } else {
  5158. WBUFW(buf,6) = sd->battle_status.hp;
  5159. WBUFW(buf,8) = sd->battle_status.max_hp;
  5160. }
  5161. for (i = 0; i < fd_max; i++) {
  5162. if (session[i] && session[i]->func_parse == clif_parse &&
  5163. (sd2 = (struct map_session_data*)session[i]->session_data) &&
  5164. sd != sd2 && sd2->state.auth) {
  5165. if (sd2->bl.m != sd->bl.m ||
  5166. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  5167. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  5168. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  5169. level < pc_isGM(sd))
  5170. continue;
  5171. WFIFOHEAD (i, packet_len(0x106));
  5172. memcpy (WFIFOP(i,0), buf, packet_len(0x106));
  5173. WFIFOSET (i, packet_len(0x106));
  5174. }
  5175. }
  5176. return 0;
  5177. }
  5178. /*==========================================
  5179. * パーティ場所移動(未使用)
  5180. *------------------------------------------*/
  5181. int clif_party_move(struct party *p,struct map_session_data *sd,int online)
  5182. {
  5183. unsigned char buf[128];
  5184. char map_name[MAP_NAME_LENGTH_EXT];
  5185. nullpo_retr(0, sd);
  5186. nullpo_retr(0, p);
  5187. snprintf(map_name, MAP_NAME_LENGTH_EXT, "%s.gat", map[sd->bl.m].name);
  5188. WBUFW(buf, 0)=0x104;
  5189. WBUFL(buf, 2)=sd->status.account_id;
  5190. WBUFL(buf, 6)=0;
  5191. WBUFW(buf,10)=sd->bl.x;
  5192. WBUFW(buf,12)=sd->bl.y;
  5193. WBUFB(buf,14)=!online;
  5194. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  5195. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  5196. memcpy(WBUFP(buf,63),map_name, MAP_NAME_LENGTH_EXT);
  5197. clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
  5198. return 0;
  5199. }
  5200. /*==========================================
  5201. * 攻撃するために移動が必要
  5202. *------------------------------------------*/
  5203. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5204. {
  5205. int fd;
  5206. nullpo_retr(0, sd);
  5207. nullpo_retr(0, bl);
  5208. fd=sd->fd;
  5209. WFIFOHEAD(fd,packet_len(0x139));
  5210. WFIFOW(fd, 0)=0x139;
  5211. WFIFOL(fd, 2)=bl->id;
  5212. WFIFOW(fd, 6)=bl->x;
  5213. WFIFOW(fd, 8)=bl->y;
  5214. WFIFOW(fd,10)=sd->bl.x;
  5215. WFIFOW(fd,12)=sd->bl.y;
  5216. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5217. WFIFOSET(fd,packet_len(0x139));
  5218. return 0;
  5219. }
  5220. /*==========================================
  5221. * 製造エフェクト
  5222. *------------------------------------------*/
  5223. int clif_produceeffect(struct map_session_data *sd,int flag,int nameid)
  5224. {
  5225. int view,fd;
  5226. nullpo_retr(0, sd);
  5227. fd=sd->fd;
  5228. // 名前の登録と送信を先にしておく
  5229. if( map_charid2nick(sd->status.char_id)==NULL )
  5230. map_addchariddb(sd->status.char_id,sd->status.name);
  5231. clif_solved_charname(sd,sd->status.char_id);
  5232. WFIFOHEAD(fd,packet_len(0x18f));
  5233. WFIFOW(fd, 0)=0x18f;
  5234. WFIFOW(fd, 2)=flag;
  5235. if((view = itemdb_viewid(nameid)) > 0)
  5236. WFIFOW(fd, 4)=view;
  5237. else
  5238. WFIFOW(fd, 4)=nameid;
  5239. WFIFOSET(fd,packet_len(0x18f));
  5240. return 0;
  5241. }
  5242. // pet
  5243. int clif_catch_process(struct map_session_data *sd)
  5244. {
  5245. int fd;
  5246. nullpo_retr(0, sd);
  5247. fd=sd->fd;
  5248. WFIFOHEAD(fd,packet_len(0x19e));
  5249. WFIFOW(fd,0)=0x19e;
  5250. WFIFOSET(fd,packet_len(0x19e));
  5251. sd->menuskill_id = SA_TAMINGMONSTER;
  5252. if (sd->ud.skillid == SA_TAMINGMONSTER)
  5253. sd->menuskill_lv = 0; //Free catch
  5254. else
  5255. sd->menuskill_lv = sd->itemid; //Consume catch
  5256. return 0;
  5257. }
  5258. int clif_pet_roulette(struct map_session_data *sd,int data)
  5259. {
  5260. int fd;
  5261. nullpo_retr(0, sd);
  5262. fd=sd->fd;
  5263. WFIFOHEAD(fd,packet_len(0x1a0));
  5264. WFIFOW(fd,0)=0x1a0;
  5265. WFIFOB(fd,2)=data;
  5266. WFIFOSET(fd,packet_len(0x1a0));
  5267. return 0;
  5268. }
  5269. /*==========================================
  5270. * pet卵リスト作成
  5271. *------------------------------------------*/
  5272. int clif_sendegg(struct map_session_data *sd)
  5273. {
  5274. //R 01a6 <len>.w <index>.w*
  5275. int i,n=0,fd;
  5276. nullpo_retr(0, sd);
  5277. fd=sd->fd;
  5278. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5279. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5280. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5281. return 0;
  5282. }
  5283. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5284. WFIFOW(fd,0)=0x1a6;
  5285. if(sd->status.pet_id <= 0) {
  5286. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5287. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5288. sd->inventory_data[i]->type!=IT_PETEGG ||
  5289. sd->status.inventory[i].amount<=0)
  5290. continue;
  5291. WFIFOW(fd,n*2+4)=i+2;
  5292. n++;
  5293. }
  5294. }
  5295. WFIFOW(fd,2)=4+n*2;
  5296. WFIFOSET(fd,WFIFOW(fd,2));
  5297. sd->menuskill_id = SA_TAMINGMONSTER;
  5298. sd->menuskill_lv = -1;
  5299. return 0;
  5300. }
  5301. /*==========================================
  5302. * Sends a specific pet data update.
  5303. * type = 0 -> param = 0 (initial data)
  5304. * type = 1 -> param = intimacy value
  5305. * type = 2 -> param = hungry value
  5306. * type = 3 -> param = accessory id
  5307. * type = 4 -> param = performance number (1-3:normal, 4:special)
  5308. * type = 5 -> param = hairstyle number
  5309. *------------------------------------------*/
  5310. int clif_send_petdata(struct map_session_data* sd, int type, int param)
  5311. {
  5312. int fd;
  5313. nullpo_retr(0, sd);
  5314. nullpo_retr(0, sd->pd);
  5315. fd = sd->fd;
  5316. WFIFOHEAD(fd,packet_len(0x1a4));
  5317. WFIFOW(fd,0) = 0x1a4;
  5318. WFIFOB(fd,2) = type;
  5319. WFIFOL(fd,3) = sd->pd->bl.id;
  5320. WFIFOL(fd,7) = param;
  5321. WFIFOSET(fd,packet_len(0x1a4));
  5322. return 0;
  5323. }
  5324. int clif_send_petdata_area(struct pet_data* pd, int type, int param)
  5325. {
  5326. uint8 buf[16];
  5327. nullpo_retr(0, pd);
  5328. WBUFW(buf,0) = 0x1a4;
  5329. WBUFB(buf,2) = type;
  5330. WBUFL(buf,3) = pd->bl.id;
  5331. WBUFL(buf,7) = param;
  5332. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5333. return 0;
  5334. }
  5335. int clif_send_petstatus(struct map_session_data *sd)
  5336. {
  5337. int fd;
  5338. struct s_pet *pet;
  5339. nullpo_retr(0, sd);
  5340. nullpo_retr(0, sd->pd);
  5341. fd=sd->fd;
  5342. pet = &sd->pd->pet;
  5343. WFIFOHEAD(fd,packet_len(0x1a2));
  5344. WFIFOW(fd,0)=0x1a2;
  5345. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5346. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5347. WFIFOW(fd,27)=pet->level;
  5348. WFIFOW(fd,29)=pet->hungry;
  5349. WFIFOW(fd,31)=pet->intimate;
  5350. WFIFOW(fd,33)=pet->equip;
  5351. WFIFOSET(fd,packet_len(0x1a2));
  5352. return 0;
  5353. }
  5354. /*==========================================
  5355. *
  5356. *------------------------------------------*/
  5357. int clif_pet_emotion(struct pet_data *pd,int param)
  5358. {
  5359. unsigned char buf[16];
  5360. nullpo_retr(0, pd);
  5361. memset(buf,0,packet_len(0x1aa));
  5362. WBUFW(buf,0)=0x1aa;
  5363. WBUFL(buf,2)=pd->bl.id;
  5364. if(param >= 100 && pd->petDB->talk_convert_class) {
  5365. if(pd->petDB->talk_convert_class < 0)
  5366. return 0;
  5367. else if(pd->petDB->talk_convert_class > 0) {
  5368. param -= (pd->pet.class_ - 100)*100;
  5369. param += (pd->petDB->talk_convert_class - 100)*100;
  5370. }
  5371. }
  5372. WBUFL(buf,6)=param;
  5373. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5374. return 0;
  5375. }
  5376. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5377. {
  5378. int fd;
  5379. nullpo_retr(0, sd);
  5380. fd=sd->fd;
  5381. WFIFOHEAD(fd,packet_len(0x1a3));
  5382. WFIFOW(fd,0)=0x1a3;
  5383. WFIFOB(fd,2)=fail;
  5384. WFIFOW(fd,3)=foodid;
  5385. WFIFOSET(fd,packet_len(0x1a3));
  5386. return 0;
  5387. }
  5388. /*==========================================
  5389. * オートスペル リスト送信
  5390. *------------------------------------------*/
  5391. int clif_autospell(struct map_session_data *sd,int skilllv)
  5392. {
  5393. int fd;
  5394. nullpo_retr(0, sd);
  5395. fd=sd->fd;
  5396. WFIFOHEAD(fd,packet_len(0x1cd));
  5397. WFIFOW(fd, 0)=0x1cd;
  5398. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5399. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5400. else
  5401. WFIFOL(fd,2)= 0x00000000;
  5402. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5403. WFIFOL(fd,6)= MG_COLDBOLT;
  5404. else
  5405. WFIFOL(fd,6)= 0x00000000;
  5406. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5407. WFIFOL(fd,10)= MG_FIREBOLT;
  5408. else
  5409. WFIFOL(fd,10)= 0x00000000;
  5410. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5411. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5412. else
  5413. WFIFOL(fd,14)= 0x00000000;
  5414. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5415. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5416. else
  5417. WFIFOL(fd,18)= 0x00000000;
  5418. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5419. WFIFOL(fd,22)= MG_FIREBALL;
  5420. else
  5421. WFIFOL(fd,22)= 0x00000000;
  5422. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5423. WFIFOL(fd,26)= MG_FROSTDIVER;
  5424. else
  5425. WFIFOL(fd,26)= 0x00000000;
  5426. WFIFOSET(fd,packet_len(0x1cd));
  5427. sd->menuskill_id = SA_AUTOSPELL;
  5428. sd->menuskill_lv = skilllv;
  5429. return 0;
  5430. }
  5431. /*==========================================
  5432. * ディボーションの青い糸
  5433. *------------------------------------------*/
  5434. int clif_devotion(struct map_session_data *sd)
  5435. {
  5436. unsigned char buf[56];
  5437. int i,n;
  5438. nullpo_retr(0, sd);
  5439. WBUFW(buf,0)=0x1cf;
  5440. WBUFL(buf,2)=sd->bl.id;
  5441. for(i=0,n=0;i<5;i++) {
  5442. if (!sd->devotion[i])
  5443. continue;
  5444. WBUFL(buf,6+4*n)=sd->devotion[i];
  5445. n++;
  5446. }
  5447. for(;n<5;n++)
  5448. WBUFL(buf,6+4*n)=0;
  5449. WBUFB(buf,26)=8;
  5450. WBUFB(buf,27)=0;
  5451. clif_send(buf,packet_len(0x1cf),&sd->bl,AREA);
  5452. return 0;
  5453. }
  5454. int clif_marionette(struct block_list *src, struct block_list *target)
  5455. {
  5456. unsigned char buf[56];
  5457. int n;
  5458. WBUFW(buf,0)=0x1cf;
  5459. WBUFL(buf,2)=src->id;
  5460. for(n=0;n<5;n++)
  5461. WBUFL(buf,6+4*n)=0;
  5462. if (target) //The target goes on the second slot.
  5463. WBUFL(buf,6+4) = target->id;
  5464. WBUFB(buf,26)=8;
  5465. WBUFB(buf,27)=0;
  5466. clif_send(buf,packet_len(0x1cf),src,AREA);
  5467. return 0;
  5468. }
  5469. /*==========================================
  5470. * 氣球
  5471. *------------------------------------------*/
  5472. int clif_spiritball(struct map_session_data *sd)
  5473. {
  5474. unsigned char buf[16];
  5475. nullpo_retr(0, sd);
  5476. WBUFW(buf,0)=0x1d0;
  5477. WBUFL(buf,2)=sd->bl.id;
  5478. WBUFW(buf,6)=sd->spiritball;
  5479. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5480. return 0;
  5481. }
  5482. /*==========================================
  5483. *
  5484. *------------------------------------------*/
  5485. int clif_combo_delay(struct block_list *bl,int wait)
  5486. {
  5487. unsigned char buf[32];
  5488. nullpo_retr(0, bl);
  5489. WBUFW(buf,0)=0x1d2;
  5490. WBUFL(buf,2)=bl->id;
  5491. WBUFL(buf,6)=wait;
  5492. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5493. return 0;
  5494. }
  5495. /*==========================================
  5496. *白刃取り
  5497. *------------------------------------------*/
  5498. int clif_bladestop(struct block_list *src,struct block_list *dst,
  5499. int _bool)
  5500. {
  5501. unsigned char buf[32];
  5502. nullpo_retr(0, src);
  5503. nullpo_retr(0, dst);
  5504. WBUFW(buf,0)=0x1d1;
  5505. WBUFL(buf,2)=src->id;
  5506. WBUFL(buf,6)=dst->id;
  5507. WBUFL(buf,10)=_bool;
  5508. clif_send(buf,packet_len(0x1d1),src,AREA);
  5509. return 0;
  5510. }
  5511. /*==========================================
  5512. *
  5513. *------------------------------------------*/
  5514. int clif_changemapcell(int m,int x,int y,int cell_type,int type)
  5515. {
  5516. struct block_list bl;
  5517. unsigned char buf[32];
  5518. char map_name[MAP_NAME_LENGTH_EXT];
  5519. snprintf(map_name, MAP_NAME_LENGTH_EXT, "%s.gat", map[m].name);
  5520. bl.type = BL_NUL;
  5521. bl.m = m;
  5522. bl.x = x;
  5523. bl.y = y;
  5524. WBUFW(buf,0) = 0x192;
  5525. WBUFW(buf,2) = x;
  5526. WBUFW(buf,4) = y;
  5527. WBUFW(buf,6) = cell_type;
  5528. memcpy(WBUFP(buf,8),map_name,MAP_NAME_LENGTH_EXT);
  5529. if(!type)
  5530. clif_send(buf,packet_len(0x192),&bl,AREA);
  5531. else
  5532. clif_send(buf,packet_len(0x192),&bl,ALL_SAMEMAP);
  5533. return 0;
  5534. }
  5535. /*==========================================
  5536. * MVPエフェクト
  5537. *------------------------------------------*/
  5538. int clif_mvp_effect(struct map_session_data *sd)
  5539. {
  5540. unsigned char buf[16];
  5541. nullpo_retr(0, sd);
  5542. WBUFW(buf,0)=0x10c;
  5543. WBUFL(buf,2)=sd->bl.id;
  5544. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5545. return 0;
  5546. }
  5547. /*==========================================
  5548. * MVPアイテム所得
  5549. *------------------------------------------*/
  5550. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5551. {
  5552. int view,fd;
  5553. nullpo_retr(0, sd);
  5554. fd=sd->fd;
  5555. WFIFOHEAD(fd,packet_len(0x10a));
  5556. WFIFOW(fd,0)=0x10a;
  5557. if((view = itemdb_viewid(nameid)) > 0)
  5558. WFIFOW(fd,2)=view;
  5559. else
  5560. WFIFOW(fd,2)=nameid;
  5561. WFIFOSET(fd,packet_len(0x10a));
  5562. return 0;
  5563. }
  5564. /*==========================================
  5565. * MVP経験値所得
  5566. *------------------------------------------*/
  5567. int clif_mvp_exp(struct map_session_data *sd,unsigned long exp)
  5568. {
  5569. int fd;
  5570. nullpo_retr(0, sd);
  5571. fd=sd->fd;
  5572. WFIFOHEAD(fd,packet_len(0x10b));
  5573. WFIFOW(fd,0)=0x10b;
  5574. WFIFOL(fd,2)=exp;
  5575. WFIFOSET(fd,packet_len(0x10b));
  5576. return 0;
  5577. }
  5578. /*==========================================
  5579. * ギルド作成可否通知
  5580. *------------------------------------------*/
  5581. int clif_guild_created(struct map_session_data *sd,int flag)
  5582. {
  5583. int fd;
  5584. nullpo_retr(0, sd);
  5585. fd=sd->fd;
  5586. WFIFOHEAD(fd,packet_len(0x167));
  5587. WFIFOW(fd,0)=0x167;
  5588. WFIFOB(fd,2)=flag;
  5589. WFIFOSET(fd,packet_len(0x167));
  5590. return 0;
  5591. }
  5592. /*==========================================
  5593. * ギルド所属通知
  5594. *------------------------------------------*/
  5595. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  5596. {
  5597. int ps,fd;
  5598. nullpo_retr(0, sd);
  5599. nullpo_retr(0, g);
  5600. fd=sd->fd;
  5601. ps=guild_getposition(sd,g);
  5602. WFIFOHEAD(fd,packet_len(0x16c));
  5603. memset(WFIFOP(fd,0),0,packet_len(0x16c));
  5604. WFIFOW(fd,0)=0x16c;
  5605. WFIFOL(fd,2)=g->guild_id;
  5606. WFIFOL(fd,6)=g->emblem_id;
  5607. WFIFOL(fd,10)=g->position[ps].mode;
  5608. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5609. WFIFOSET(fd,packet_len(0x16c));
  5610. return 0;
  5611. }
  5612. /*==========================================
  5613. * ギルドメンバログイン通知
  5614. *------------------------------------------*/
  5615. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5616. {
  5617. unsigned char buf[64];
  5618. nullpo_retr(0, g);
  5619. WBUFW(buf, 0)=0x16d;
  5620. WBUFL(buf, 2)=g->member[idx].account_id;
  5621. WBUFL(buf, 6)=g->member[idx].char_id;
  5622. WBUFL(buf,10)=flag;
  5623. if(g->member[idx].sd==NULL){
  5624. struct map_session_data *sd=guild_getavailablesd(g);
  5625. if(sd!=NULL)
  5626. clif_send(buf,packet_len(0x16d),&sd->bl,GUILD);
  5627. }else
  5628. clif_send(buf,packet_len(0x16d),&g->member[idx].sd->bl,GUILD_WOS);
  5629. return 0;
  5630. }
  5631. // Function `clif_guild_memberlogin_notice` sends info about
  5632. // logins and logouts of a guild member to the rest members.
  5633. // But at the 1st time (after a player login or map changing)
  5634. // the client won't show the message.
  5635. // So I suggest use this function for sending "first-time-info"
  5636. // to some player on entering the game or changing location.
  5637. // At next time the client would always show the message.
  5638. // The function sends all the statuses in the single packet
  5639. // to economize traffic. [LuzZza]
  5640. int clif_guild_send_onlineinfo(struct map_session_data *sd)
  5641. {
  5642. struct guild *g;
  5643. unsigned char buf[14*128];
  5644. int i, count=0, p_len;
  5645. nullpo_retr(0, sd);
  5646. p_len = packet_len(0x16d);
  5647. if(!(g = guild_search(sd->status.guild_id)))
  5648. return 0;
  5649. for(i=0; i<g->max_member; i++) {
  5650. if(g->member[i].account_id > 0 &&
  5651. g->member[i].account_id != sd->status.account_id) {
  5652. WBUFW(buf,count*p_len) = 0x16d;
  5653. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5654. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5655. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5656. count++;
  5657. }
  5658. }
  5659. clif_send(buf, p_len*count, &sd->bl, SELF);
  5660. return 0;
  5661. }
  5662. /*==========================================
  5663. * ギルドマスター通知(14dへの応答)
  5664. *------------------------------------------*/
  5665. int clif_guild_masterormember(struct map_session_data *sd)
  5666. {
  5667. int fd;
  5668. nullpo_retr(0, sd);
  5669. fd=sd->fd;
  5670. WFIFOHEAD(fd,packet_len(0x14e));
  5671. WFIFOW(fd,0) = 0x14e;
  5672. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  5673. WFIFOSET(fd,packet_len(0x14e));
  5674. return 0;
  5675. }
  5676. /*==========================================
  5677. * Basic Info (Territories [Valaris])
  5678. *------------------------------------------*/
  5679. int clif_guild_basicinfo(struct map_session_data *sd)
  5680. {
  5681. int fd,i,t;
  5682. struct guild *g;
  5683. struct guild_castle *gc=NULL;
  5684. nullpo_retr(0, sd);
  5685. fd=sd->fd;
  5686. g=guild_search(sd->status.guild_id);
  5687. if(g==NULL)
  5688. return 0;
  5689. WFIFOHEAD(fd,packet_len(0x1b6));
  5690. WFIFOW(fd, 0)=0x1b6;//0x150;
  5691. WFIFOL(fd, 2)=g->guild_id;
  5692. WFIFOL(fd, 6)=g->guild_lv;
  5693. WFIFOL(fd,10)=g->connect_member;
  5694. WFIFOL(fd,14)=g->max_member;
  5695. WFIFOL(fd,18)=g->average_lv;
  5696. WFIFOL(fd,22)=g->exp;
  5697. WFIFOL(fd,26)=g->next_exp;
  5698. WFIFOL(fd,30)=0; // Tax Points
  5699. WFIFOL(fd,34)=0; // Tendency: (left) Vulgar [-100,100] Famed (right)
  5700. WFIFOL(fd,38)=0; // Tendency: (down) Wicked [-100,100] Righteous (up)
  5701. WFIFOL(fd,42)=g->emblem_id;
  5702. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5703. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5704. for(i = 0, t = 0; i < MAX_GUILDCASTLE; i++)
  5705. {
  5706. gc = guild_castle_search(i);
  5707. if(gc && g->guild_id == gc->guild_id)
  5708. t++;
  5709. }
  5710. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20); // "'N' castles"
  5711. WFIFOSET(fd,packet_len(WFIFOW(fd,0)));
  5712. return 0;
  5713. }
  5714. /*==========================================
  5715. * ギルド同盟/敵対情報
  5716. *------------------------------------------*/
  5717. int clif_guild_allianceinfo(struct map_session_data *sd)
  5718. {
  5719. int fd,i,c;
  5720. struct guild *g;
  5721. nullpo_retr(0, sd);
  5722. fd=sd->fd;
  5723. g=guild_search(sd->status.guild_id);
  5724. if(g==NULL)
  5725. return 0;
  5726. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5727. WFIFOW(fd, 0)=0x14c;
  5728. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5729. struct guild_alliance *a=&g->alliance[i];
  5730. if(a->guild_id>0){
  5731. WFIFOL(fd,c*32+4)=a->opposition;
  5732. WFIFOL(fd,c*32+8)=a->guild_id;
  5733. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5734. c++;
  5735. }
  5736. }
  5737. WFIFOW(fd, 2)=c*32+4;
  5738. WFIFOSET(fd,WFIFOW(fd,2));
  5739. return 0;
  5740. }
  5741. /*==========================================
  5742. * ギルドメンバーリスト
  5743. *------------------------------------------*/
  5744. int clif_guild_memberlist(struct map_session_data *sd)
  5745. {
  5746. int fd;
  5747. int i,c;
  5748. struct guild *g;
  5749. nullpo_retr(0, sd);
  5750. fd=sd->fd;
  5751. if (!fd)
  5752. return 0;
  5753. g=guild_search(sd->status.guild_id);
  5754. if(g==NULL)
  5755. return 0;
  5756. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5757. WFIFOW(fd, 0)=0x154;
  5758. for(i=0,c=0;i<g->max_member;i++){
  5759. struct guild_member *m=&g->member[i];
  5760. if(m->account_id==0)
  5761. continue;
  5762. WFIFOL(fd,c*104+ 4)=m->account_id;
  5763. WFIFOL(fd,c*104+ 8)=m->char_id;
  5764. WFIFOW(fd,c*104+12)=m->hair;
  5765. WFIFOW(fd,c*104+14)=m->hair_color;
  5766. WFIFOW(fd,c*104+16)=m->gender;
  5767. WFIFOW(fd,c*104+18)=m->class_;
  5768. WFIFOW(fd,c*104+20)=m->lv;
  5769. WFIFOL(fd,c*104+22)=m->exp;
  5770. WFIFOL(fd,c*104+26)=m->online;
  5771. WFIFOL(fd,c*104+30)=m->position;
  5772. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5773. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5774. c++;
  5775. }
  5776. WFIFOW(fd, 2)=c*104+4;
  5777. WFIFOSET(fd,WFIFOW(fd,2));
  5778. return 0;
  5779. }
  5780. /*==========================================
  5781. * ギルド役職名リスト
  5782. *------------------------------------------*/
  5783. int clif_guild_positionnamelist(struct map_session_data *sd)
  5784. {
  5785. int i,fd;
  5786. struct guild *g;
  5787. nullpo_retr(0, sd);
  5788. fd=sd->fd;
  5789. g=guild_search(sd->status.guild_id);
  5790. if(g==NULL)
  5791. return 0;
  5792. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5793. WFIFOW(fd, 0)=0x166;
  5794. for(i=0;i<MAX_GUILDPOSITION;i++){
  5795. WFIFOL(fd,i*28+4)=i;
  5796. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5797. }
  5798. WFIFOW(fd,2)=i*28+4;
  5799. WFIFOSET(fd,WFIFOW(fd,2));
  5800. return 0;
  5801. }
  5802. /*==========================================
  5803. * ギルド役職情報リスト
  5804. *------------------------------------------*/
  5805. int clif_guild_positioninfolist(struct map_session_data *sd)
  5806. {
  5807. int i,fd;
  5808. struct guild *g;
  5809. nullpo_retr(0, sd);
  5810. fd=sd->fd;
  5811. g=guild_search(sd->status.guild_id);
  5812. if(g==NULL)
  5813. return 0;
  5814. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5815. WFIFOW(fd, 0)=0x160;
  5816. for(i=0;i<MAX_GUILDPOSITION;i++){
  5817. struct guild_position *p=&g->position[i];
  5818. WFIFOL(fd,i*16+ 4)=i;
  5819. WFIFOL(fd,i*16+ 8)=p->mode;
  5820. WFIFOL(fd,i*16+12)=i;
  5821. WFIFOL(fd,i*16+16)=p->exp_mode;
  5822. }
  5823. WFIFOW(fd, 2)=i*16+4;
  5824. WFIFOSET(fd,WFIFOW(fd,2));
  5825. return 0;
  5826. }
  5827. /*==========================================
  5828. * ギルド役職変更通知
  5829. *------------------------------------------*/
  5830. int clif_guild_positionchanged(struct guild *g,int idx)
  5831. {
  5832. struct map_session_data *sd;
  5833. unsigned char buf[128];
  5834. nullpo_retr(0, g);
  5835. WBUFW(buf, 0)=0x174;
  5836. WBUFW(buf, 2)=44;
  5837. WBUFL(buf, 4)=idx;
  5838. WBUFL(buf, 8)=g->position[idx].mode;
  5839. WBUFL(buf,12)=idx;
  5840. WBUFL(buf,16)=g->position[idx].exp_mode;
  5841. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  5842. if( (sd=guild_getavailablesd(g))!=NULL )
  5843. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5844. return 0;
  5845. }
  5846. /*==========================================
  5847. * ギルドメンバ変更通知
  5848. *------------------------------------------*/
  5849. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  5850. {
  5851. struct map_session_data *sd;
  5852. unsigned char buf[64];
  5853. nullpo_retr(0, g);
  5854. WBUFW(buf, 0)=0x156;
  5855. WBUFW(buf, 2)=16;
  5856. WBUFL(buf, 4)=g->member[idx].account_id;
  5857. WBUFL(buf, 8)=g->member[idx].char_id;
  5858. WBUFL(buf,12)=g->member[idx].position;
  5859. if( (sd=guild_getavailablesd(g))!=NULL )
  5860. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5861. return 0;
  5862. }
  5863. /*==========================================
  5864. * ギルドエンブレム送信
  5865. *------------------------------------------*/
  5866. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  5867. {
  5868. int fd;
  5869. nullpo_retr(0, sd);
  5870. nullpo_retr(0, g);
  5871. fd=sd->fd;
  5872. if(g->emblem_len<=0)
  5873. return 0;
  5874. WFIFOHEAD(fd,g->emblem_len+12);
  5875. WFIFOW(fd,0)=0x152;
  5876. WFIFOW(fd,2)=g->emblem_len+12;
  5877. WFIFOL(fd,4)=g->guild_id;
  5878. WFIFOL(fd,8)=g->emblem_id;
  5879. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  5880. WFIFOSET(fd,WFIFOW(fd,2));
  5881. return 0;
  5882. }
  5883. /*==========================================
  5884. * ギルドスキル送信
  5885. *------------------------------------------*/
  5886. int clif_guild_skillinfo(struct map_session_data *sd)
  5887. {
  5888. int fd;
  5889. int i,id,c,up=1;
  5890. struct guild *g;
  5891. nullpo_retr(0, sd);
  5892. fd=sd->fd;
  5893. g=guild_search(sd->status.guild_id);
  5894. if(g==NULL)
  5895. return 0;
  5896. WFIFOHEAD(fd, MAX_GUILDSKILL * 37 + 6);
  5897. WFIFOW(fd,0)=0x0162;
  5898. WFIFOW(fd,4)=g->skill_point;
  5899. for(i=c=0;i<MAX_GUILDSKILL;i++){
  5900. if(g->skill[i].id>0 && guild_check_skill_require(g,g->skill[i].id)){
  5901. WFIFOW(fd,c*37+ 6) = id = g->skill[i].id;
  5902. WFIFOW(fd,c*37+ 8) = skill_get_inf(id);
  5903. WFIFOW(fd,c*37+10) = 0;
  5904. WFIFOW(fd,c*37+12) = g->skill[i].lv;
  5905. WFIFOW(fd,c*37+14) = skill_get_sp(id,g->skill[i].lv);
  5906. WFIFOW(fd,c*37+16) = skill_get_range(id,g->skill[i].lv);
  5907. strncpy((char*)WFIFOP(fd,c*37+18), skill_get_name(id), NAME_LENGTH);
  5908. if(g->skill[i].lv < guild_skill_get_max(id) && (sd == g->member[0].sd))
  5909. up = 1;
  5910. else
  5911. up = 0;
  5912. WFIFOB(fd,c*37+42)= up;
  5913. c++;
  5914. }
  5915. }
  5916. WFIFOW(fd,2)=c*37+6;
  5917. WFIFOSET(fd,WFIFOW(fd,2));
  5918. return 0;
  5919. }
  5920. /*==========================================
  5921. * Sends guild notice to client
  5922. * R 016f <str1z>.60B <str2z>.120B
  5923. *------------------------------------------*/
  5924. int clif_guild_notice(struct map_session_data *sd,struct guild *g)
  5925. {
  5926. int fd;
  5927. nullpo_retr(0, sd);
  5928. nullpo_retr(0, g);
  5929. fd = sd->fd;
  5930. if ( !session_isActive(fd) ) //null pointer right here [Kevin]
  5931. return 0;
  5932. if (fd <= 0)
  5933. return 0;
  5934. if(*g->mes1==0 && *g->mes2==0)
  5935. return 0;
  5936. WFIFOHEAD(fd,packet_len(0x16f));
  5937. WFIFOW(fd,0)=0x16f;
  5938. memcpy(WFIFOP(fd,2),g->mes1,60);
  5939. memcpy(WFIFOP(fd,62),g->mes2,120);
  5940. WFIFOSET(fd,packet_len(0x16f));
  5941. return 0;
  5942. }
  5943. /*==========================================
  5944. * ギルドメンバ勧誘
  5945. *------------------------------------------*/
  5946. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  5947. {
  5948. int fd;
  5949. nullpo_retr(0, sd);
  5950. nullpo_retr(0, g);
  5951. fd=sd->fd;
  5952. WFIFOHEAD(fd,packet_len(0x16a));
  5953. WFIFOW(fd,0)=0x16a;
  5954. WFIFOL(fd,2)=g->guild_id;
  5955. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  5956. WFIFOSET(fd,packet_len(0x16a));
  5957. return 0;
  5958. }
  5959. /*==========================================
  5960. * ギルドメンバ勧誘結果
  5961. *------------------------------------------*/
  5962. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  5963. {
  5964. int fd;
  5965. nullpo_retr(0, sd);
  5966. fd=sd->fd;
  5967. WFIFOHEAD(fd,packet_len(0x169));
  5968. WFIFOW(fd,0)=0x169;
  5969. WFIFOB(fd,2)=flag;
  5970. WFIFOSET(fd,packet_len(0x169));
  5971. return 0;
  5972. }
  5973. /*==========================================
  5974. * ギルドメンバ脱退通知
  5975. *------------------------------------------*/
  5976. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  5977. {
  5978. unsigned char buf[128];
  5979. nullpo_retr(0, sd);
  5980. WBUFW(buf, 0)=0x15a;
  5981. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5982. memcpy(WBUFP(buf,26),mes,40);
  5983. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD);
  5984. return 0;
  5985. }
  5986. /*==========================================
  5987. * ギルドメンバ追放通知
  5988. *------------------------------------------*/
  5989. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,
  5990. int account_id)
  5991. {
  5992. unsigned char buf[128];
  5993. nullpo_retr(0, sd);
  5994. WBUFW(buf, 0)=0x15c;
  5995. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5996. memcpy(WBUFP(buf,26),mes,40);
  5997. memcpy(WBUFP(buf,66),"dummy",NAME_LENGTH);
  5998. clif_send(buf,packet_len(0x15c),&sd->bl,GUILD);
  5999. return 0;
  6000. }
  6001. /*==========================================
  6002. * ギルド追放メンバリスト
  6003. *------------------------------------------*/
  6004. int clif_guild_expulsionlist(struct map_session_data *sd)
  6005. {
  6006. int fd;
  6007. int i,c;
  6008. struct guild *g;
  6009. nullpo_retr(0, sd);
  6010. fd=sd->fd;
  6011. g=guild_search(sd->status.guild_id);
  6012. if(g==NULL)
  6013. return 0;
  6014. WFIFOHEAD(fd,MAX_GUILDEXPULSION * 88 + 4);
  6015. WFIFOW(fd,0)=0x163;
  6016. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  6017. struct guild_expulsion *e=&g->expulsion[i];
  6018. if(e->account_id>0){
  6019. memcpy(WFIFOP(fd,c*88+ 4),e->name,NAME_LENGTH);
  6020. memcpy(WFIFOP(fd,c*88+28),e->acc,24);
  6021. memcpy(WFIFOP(fd,c*88+52),e->mes,44);
  6022. c++;
  6023. }
  6024. }
  6025. WFIFOW(fd,2)=c*88+4;
  6026. WFIFOSET(fd,WFIFOW(fd,2));
  6027. return 0;
  6028. }
  6029. /*==========================================
  6030. * ギルド会話
  6031. *------------------------------------------*/
  6032. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6033. {
  6034. struct map_session_data *sd;
  6035. unsigned char *buf;
  6036. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  6037. WBUFW(buf, 0) = 0x17f;
  6038. WBUFW(buf, 2) = len + 4;
  6039. memcpy(WBUFP(buf,4), mes, len);
  6040. if ((sd = guild_getavailablesd(g)) != NULL)
  6041. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  6042. if(buf) aFree(buf);
  6043. return 0;
  6044. }
  6045. /*==========================================
  6046. * ギルドスキル割り振り通知
  6047. *------------------------------------------*/
  6048. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  6049. {
  6050. int fd;
  6051. nullpo_retr(0, sd);
  6052. fd=sd->fd;
  6053. WFIFOHEAD(fd,11);
  6054. WFIFOW(fd,0) = 0x10e;
  6055. WFIFOW(fd,2) = skill_num;
  6056. WFIFOW(fd,4) = lv;
  6057. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  6058. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  6059. WFIFOB(fd,10) = 1;
  6060. WFIFOSET(fd,11);
  6061. return 0;
  6062. }
  6063. /*==========================================
  6064. * ギルド同盟要請
  6065. *------------------------------------------*/
  6066. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6067. {
  6068. int fd;
  6069. nullpo_retr(0, sd);
  6070. fd=sd->fd;
  6071. WFIFOHEAD(fd,packet_len(0x171));
  6072. WFIFOW(fd,0)=0x171;
  6073. WFIFOL(fd,2)=account_id;
  6074. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6075. WFIFOSET(fd,packet_len(0x171));
  6076. return 0;
  6077. }
  6078. /*==========================================
  6079. * Reply to alliance request.
  6080. * Flag values are:
  6081. * 0: Already allied.
  6082. * 1: You rejected the offer.
  6083. * 2: You accepted the offer.
  6084. * 3: They have too any alliances
  6085. * 4: You have too many alliances.
  6086. *------------------------------------------*/
  6087. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  6088. {
  6089. int fd;
  6090. nullpo_retr(0, sd);
  6091. fd=sd->fd;
  6092. WFIFOHEAD(fd,packet_len(0x173));
  6093. WFIFOW(fd,0)=0x173;
  6094. WFIFOL(fd,2)=flag;
  6095. WFIFOSET(fd,packet_len(0x173));
  6096. return 0;
  6097. }
  6098. /*==========================================
  6099. * ギルド関係解消通知
  6100. *------------------------------------------*/
  6101. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6102. {
  6103. int fd;
  6104. nullpo_retr(0, sd);
  6105. fd = sd->fd;
  6106. if (fd <= 0)
  6107. return 0;
  6108. WFIFOHEAD(fd,packet_len(0x184));
  6109. WFIFOW(fd,0)=0x184;
  6110. WFIFOL(fd,2)=guild_id;
  6111. WFIFOL(fd,6)=flag;
  6112. WFIFOSET(fd,packet_len(0x184));
  6113. return 0;
  6114. }
  6115. /*==========================================
  6116. * ギルド敵対結果
  6117. *------------------------------------------*/
  6118. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6119. {
  6120. int fd;
  6121. nullpo_retr(0, sd);
  6122. fd=sd->fd;
  6123. WFIFOHEAD(fd,packet_len(0x181));
  6124. WFIFOW(fd,0)=0x181;
  6125. WFIFOB(fd,2)=flag;
  6126. WFIFOSET(fd,packet_len(0x181));
  6127. return 0;
  6128. }
  6129. /*==========================================
  6130. * ギルド関係追加
  6131. *------------------------------------------*/
  6132. /*int clif_guild_allianceadded(struct guild *g,int idx)
  6133. {
  6134. unsigned char buf[64];
  6135. WBUFW(fd,0)=0x185;
  6136. WBUFL(fd,2)=g->alliance[idx].opposition;
  6137. WBUFL(fd,6)=g->alliance[idx].guild_id;
  6138. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  6139. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  6140. return 0;
  6141. }*/
  6142. /*==========================================
  6143. * ギルド解散通知
  6144. *------------------------------------------*/
  6145. int clif_guild_broken(struct map_session_data *sd,int flag)
  6146. {
  6147. int fd;
  6148. nullpo_retr(0, sd);
  6149. fd=sd->fd;
  6150. WFIFOHEAD(fd,packet_len(0x15e));
  6151. WFIFOW(fd,0)=0x15e;
  6152. WFIFOL(fd,2)=flag;
  6153. WFIFOSET(fd,packet_len(0x15e));
  6154. return 0;
  6155. }
  6156. /*==========================================
  6157. * エモーション
  6158. *------------------------------------------*/
  6159. void clif_emotion(struct block_list *bl,int type)
  6160. {
  6161. unsigned char buf[8];
  6162. nullpo_retv(bl);
  6163. WBUFW(buf,0)=0xc0;
  6164. WBUFL(buf,2)=bl->id;
  6165. WBUFB(buf,6)=type;
  6166. clif_send(buf,packet_len(0xc0),bl,AREA);
  6167. }
  6168. /*==========================================
  6169. * トーキーボックス
  6170. *------------------------------------------*/
  6171. void clif_talkiebox(struct block_list* bl, const char* talkie)
  6172. {
  6173. unsigned char buf[86];
  6174. nullpo_retv(bl);
  6175. WBUFW(buf,0)=0x191;
  6176. WBUFL(buf,2)=bl->id;
  6177. memcpy(WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6178. clif_send(buf,packet_len(0x191),bl,AREA);
  6179. }
  6180. /*==========================================
  6181. * 結婚エフェクト
  6182. *------------------------------------------*/
  6183. void clif_wedding_effect(struct block_list *bl)
  6184. {
  6185. unsigned char buf[6];
  6186. nullpo_retv(bl);
  6187. WBUFW(buf,0) = 0x1ea;
  6188. WBUFL(buf,2) = bl->id;
  6189. clif_send(buf, packet_len(0x1ea), bl, AREA);
  6190. }
  6191. /*==========================================
  6192. * あなたに逢いたい使用時名前叫び
  6193. *------------------------------------------
  6194. void clif_callpartner(struct map_session_data *sd)
  6195. {
  6196. unsigned char buf[26];
  6197. char *p;
  6198. nullpo_retv(sd);
  6199. if(sd->status.partner_id){
  6200. WBUFW(buf,0)=0x1e6;
  6201. p = map_charid2nick(sd->status.partner_id);
  6202. if(p){
  6203. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6204. }else{
  6205. map_reqchariddb(sd,sd->status.partner_id);
  6206. chrif_searchcharid(sd->status.partner_id);
  6207. WBUFB(buf,2) = 0;
  6208. }
  6209. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  6210. }
  6211. return;
  6212. }
  6213. */
  6214. /*==========================================
  6215. * Adopt baby [Celest]
  6216. *------------------------------------------*/
  6217. void clif_adopt_process(struct map_session_data *sd)
  6218. {
  6219. int fd;
  6220. nullpo_retv(sd);
  6221. fd=sd->fd;
  6222. WFIFOHEAD(fd,packet_len(0x1f8));
  6223. WFIFOW(fd,0)=0x1f8;
  6224. WFIFOSET(fd,packet_len(0x1f8));
  6225. }
  6226. /*==========================================
  6227. * Marry [DracoRPG]
  6228. *------------------------------------------*/
  6229. void clif_marriage_process(struct map_session_data *sd)
  6230. {
  6231. int fd;
  6232. nullpo_retv(sd);
  6233. fd=sd->fd;
  6234. WFIFOHEAD(fd,packet_len(0x1e4));
  6235. WFIFOW(fd,0)=0x1e4;
  6236. WFIFOSET(fd,packet_len(0x1e4));
  6237. }
  6238. /*==========================================
  6239. * Notice of divorce
  6240. *------------------------------------------*/
  6241. void clif_divorced(struct map_session_data* sd, const char* name)
  6242. {
  6243. int fd;
  6244. nullpo_retv(sd);
  6245. fd=sd->fd;
  6246. WFIFOHEAD(fd,packet_len(0x205));
  6247. WFIFOW(fd,0)=0x205;
  6248. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6249. WFIFOSET(fd, packet_len(0x205));
  6250. }
  6251. /*==========================================
  6252. *
  6253. *------------------------------------------*/
  6254. void clif_parse_ReqAdopt(int fd, struct map_session_data *sd)
  6255. {
  6256. nullpo_retv(sd);
  6257. WFIFOHEAD(fd,packet_len(0x1f6));
  6258. WFIFOW(fd,0)=0x1f6;
  6259. WFIFOSET(fd, packet_len(0x1f6));
  6260. }
  6261. /*==========================================
  6262. *
  6263. *------------------------------------------*/
  6264. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd)
  6265. {
  6266. nullpo_retv(sd);
  6267. WFIFOHEAD(fd,packet_len(0x1e2));
  6268. WFIFOW(fd,0)=0x1e2;
  6269. WFIFOSET(fd, packet_len(0x1e2));
  6270. }
  6271. /*==========================================
  6272. * inform target(s) that `sd` is sitting
  6273. *------------------------------------------*/
  6274. void clif_sitting(struct map_session_data* sd, enum send_target target)
  6275. {
  6276. unsigned char buf[32];
  6277. nullpo_retv(sd);
  6278. WBUFW(buf, 0) = 0x8a;
  6279. WBUFL(buf, 2) = sd->bl.id;
  6280. WBUFB(buf,26) = 2;
  6281. clif_send(buf, packet_len(0x8a), &sd->bl, target);
  6282. }
  6283. /*==========================================
  6284. * inform target(s) that `sd` is standing
  6285. *------------------------------------------*/
  6286. void clif_standing(struct map_session_data* sd, enum send_target target)
  6287. {
  6288. unsigned char buf[32];
  6289. nullpo_retv(sd);
  6290. WBUFW(buf, 0) = 0x8a;
  6291. WBUFL(buf, 2) = sd->bl.id;
  6292. WBUFB(buf,26) = 3;
  6293. clif_send(buf, packet_len(0x8a), &sd->bl, target);
  6294. }
  6295. /*==========================================
  6296. *
  6297. *------------------------------------------*/
  6298. int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  6299. {
  6300. int fd;
  6301. nullpo_retr(0, sd);
  6302. fd = sd->fd;
  6303. if (!fd || !len) return 0; //Disconnected player.
  6304. WFIFOHEAD(fd, len+5);
  6305. WFIFOW(fd, 0) = 0x17f;
  6306. WFIFOW(fd, 2) = len + 5;
  6307. memcpy(WFIFOP(fd,4), mes, len);
  6308. WFIFOSET(fd, WFIFOW(fd,2));
  6309. return 1;
  6310. }
  6311. /*==========================================
  6312. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6313. *------------------------------------------*/
  6314. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  6315. {
  6316. unsigned char buf[1024];
  6317. if (!len) return;
  6318. WBUFW(buf, 0) = 0x17f;
  6319. WBUFW(buf, 2) = len + 5;
  6320. memcpy(WBUFP(buf,4), mes, len);
  6321. clif_send(buf, WBUFW(buf,2), src, target);
  6322. return;
  6323. }
  6324. /*==========================================
  6325. *
  6326. *------------------------------------------*/
  6327. int clif_GM_kickack(struct map_session_data *sd, int id)
  6328. {
  6329. int fd;
  6330. nullpo_retr(0, sd);
  6331. fd = sd->fd;
  6332. WFIFOHEAD(fd,packet_len(0xcd));
  6333. WFIFOW(fd,0) = 0xcd;
  6334. WFIFOL(fd,2) = id;
  6335. WFIFOSET(fd, packet_len(0xcd));
  6336. return 0;
  6337. }
  6338. void clif_parse_QuitGame(int fd,struct map_session_data *sd);
  6339. int clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd,int type)
  6340. {
  6341. int fd = tsd->fd;
  6342. WFIFOHEAD(fd,packet_len(0x18b));
  6343. if(type)
  6344. clif_GM_kickack(sd,tsd->status.account_id);
  6345. if (!fd) {
  6346. map_quit(tsd);
  6347. return 0;
  6348. }
  6349. WFIFOW(fd,0) = 0x18b;
  6350. WFIFOW(fd,2) = 0;
  6351. WFIFOSET(fd,packet_len(0x18b));
  6352. clif_setwaitclose(fd);
  6353. return 0;
  6354. }
  6355. int clif_GM_silence(struct map_session_data *sd, struct map_session_data *tsd, int type)
  6356. {
  6357. int fd;
  6358. nullpo_retr(0, sd);
  6359. nullpo_retr(0, tsd);
  6360. fd = tsd->fd;
  6361. if (fd <= 0)
  6362. return 0;
  6363. WFIFOHEAD(fd,packet_len(0x14b));
  6364. WFIFOW(fd,0) = 0x14b;
  6365. WFIFOB(fd,2) = 0;
  6366. memcpy(WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6367. WFIFOSET(fd, packet_len(0x14b));
  6368. return 0;
  6369. }
  6370. /*==========================================
  6371. *
  6372. *------------------------------------------*/
  6373. int clif_timedout(struct map_session_data *sd)
  6374. {
  6375. nullpo_retr(0, sd);
  6376. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' timed out.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id);
  6377. clif_authfail_fd(sd->fd,3); // Even if player is not on we still send anyway
  6378. clif_setwaitclose(sd->fd); // Set session to EOF
  6379. return 0;
  6380. }
  6381. /*==========================================
  6382. * Wis拒否許可応答
  6383. *------------------------------------------*/
  6384. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6385. {
  6386. int fd;
  6387. nullpo_retr(0, sd);
  6388. fd=sd->fd;
  6389. WFIFOHEAD(fd,packet_len(0xd1));
  6390. WFIFOW(fd,0)=0xd1;
  6391. WFIFOB(fd,2)=type;
  6392. WFIFOB(fd,3)=flag;
  6393. WFIFOSET(fd,packet_len(0xd1));
  6394. return 0;
  6395. }
  6396. /*==========================================
  6397. * Wis全拒否許可応答
  6398. *------------------------------------------*/
  6399. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6400. {
  6401. int fd;
  6402. nullpo_retr(0, sd);
  6403. fd=sd->fd;
  6404. WFIFOHEAD(fd,packet_len(0xd2));
  6405. WFIFOW(fd,0)=0xd2;
  6406. WFIFOB(fd,2)=type;
  6407. WFIFOB(fd,3)=flag;
  6408. WFIFOSET(fd,packet_len(0xd2));
  6409. return 0;
  6410. }
  6411. /*==========================================
  6412. * サウンドエフェクト
  6413. *------------------------------------------*/
  6414. void clif_soundeffect(struct map_session_data *sd,struct block_list *bl,const char *name,int type)
  6415. {
  6416. int fd;
  6417. nullpo_retv(sd);
  6418. nullpo_retv(bl);
  6419. fd=sd->fd;
  6420. WFIFOHEAD(fd,packet_len(0x1d3));
  6421. WFIFOW(fd,0)=0x1d3;
  6422. memcpy(WFIFOP(fd,2),name,NAME_LENGTH);
  6423. WFIFOB(fd,26)=type;
  6424. WFIFOL(fd,27)=0;
  6425. WFIFOL(fd,31)=bl->id;
  6426. WFIFOSET(fd,packet_len(0x1d3));
  6427. return;
  6428. }
  6429. int clif_soundeffectall(struct block_list *bl, const char *name, int type, int coverage)
  6430. {
  6431. unsigned char buf[40];
  6432. memset(buf, 0, packet_len(0x1d3));
  6433. if(coverage < 0 || coverage > 22){
  6434. ShowError("clif_soundeffectall: undefined coverage.\n");
  6435. return 0;
  6436. }
  6437. nullpo_retr(0, bl);
  6438. WBUFW(buf,0)=0x1d3;
  6439. memcpy(WBUFP(buf,2), name, NAME_LENGTH);
  6440. WBUFB(buf,26)=type;
  6441. WBUFL(buf,27)=0;
  6442. WBUFL(buf,31)=bl->id;
  6443. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6444. return 0;
  6445. }
  6446. // displaying special effects (npcs, weather, etc) [Valaris]
  6447. int clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6448. {
  6449. unsigned char buf[24];
  6450. nullpo_retr(0, bl);
  6451. memset(buf, 0, packet_len(0x1f3));
  6452. WBUFW(buf,0) = 0x1f3;
  6453. WBUFL(buf,2) = bl->id;
  6454. WBUFL(buf,6) = type;
  6455. clif_send(buf, packet_len(0x1f3), bl, target);
  6456. if (disguised(bl)) {
  6457. WBUFL(buf,2) = -bl->id;
  6458. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6459. }
  6460. return 0;
  6461. }
  6462. // refresh the client's screen, getting rid of any effects
  6463. int clif_refresh(struct map_session_data *sd)
  6464. {
  6465. nullpo_retr(-1, sd);
  6466. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6467. clif_inventorylist(sd);
  6468. if(pc_iscarton(sd)){
  6469. clif_cartlist(sd);
  6470. clif_updatestatus(sd,SP_CARTINFO);
  6471. }
  6472. clif_updatestatus(sd,SP_MAXWEIGHT);
  6473. clif_updatestatus(sd,SP_WEIGHT);
  6474. clif_updatestatus(sd,SP_STR);
  6475. clif_updatestatus(sd,SP_AGI);
  6476. clif_updatestatus(sd,SP_VIT);
  6477. clif_updatestatus(sd,SP_INT);
  6478. clif_updatestatus(sd,SP_DEX);
  6479. clif_updatestatus(sd,SP_LUK);
  6480. if (sd->spiritball)
  6481. clif_spiritball_single(sd->fd, sd);
  6482. if (sd->vd.cloth_color)
  6483. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6484. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6485. clif_weather_check(sd);
  6486. return 0;
  6487. }
  6488. // updates the object's (bl) name on client
  6489. int clif_charnameack (int fd, struct block_list *bl)
  6490. {
  6491. unsigned char buf[103];
  6492. int cmd = 0x95;
  6493. nullpo_retr(0, bl);
  6494. WBUFW(buf,0) = cmd;
  6495. WBUFL(buf,2) = bl->id;
  6496. switch(bl->type) {
  6497. case BL_PC:
  6498. {
  6499. struct map_session_data *ssd = (struct map_session_data *)bl;
  6500. struct party_data *p = NULL;
  6501. struct guild *g = NULL;
  6502. //Requesting your own "shadow" name. [Skotlex]
  6503. if (ssd->fd == fd && ssd->disguise)
  6504. WBUFL(buf,2) = -bl->id;
  6505. if (strlen(ssd->fakename)>1) {
  6506. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6507. break;
  6508. }
  6509. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6510. if (ssd->status.party_id > 0)
  6511. p = party_search(ssd->status.party_id);
  6512. if (ssd->status.guild_id > 0)
  6513. g = guild_search(ssd->status.guild_id);
  6514. if (p == NULL && g == NULL)
  6515. break;
  6516. WBUFW(buf, 0) = cmd = 0x195;
  6517. if (p)
  6518. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6519. else
  6520. WBUFB(buf,30) = 0;
  6521. if (g)
  6522. {
  6523. int i, ps = -1;
  6524. for(i = 0; i < g->max_member; i++) {
  6525. if (g->member[i].account_id == ssd->status.account_id &&
  6526. g->member[i].char_id == ssd->status.char_id )
  6527. {
  6528. ps = g->member[i].position;
  6529. break;
  6530. }
  6531. }
  6532. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6533. {
  6534. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6535. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6536. } else { //Assume no guild.
  6537. WBUFB(buf,54) = 0;
  6538. WBUFB(buf,78) = 0;
  6539. }
  6540. } else {
  6541. WBUFB(buf,54) = 0;
  6542. WBUFB(buf,78) = 0;
  6543. }
  6544. }
  6545. break;
  6546. //[blackhole89]
  6547. case BL_HOM:
  6548. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6549. break;
  6550. case BL_PET:
  6551. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6552. break;
  6553. case BL_NPC:
  6554. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6555. break;
  6556. case BL_MOB:
  6557. {
  6558. struct mob_data *md = (struct mob_data *)bl;
  6559. nullpo_retr(0, md);
  6560. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6561. if (md->guardian_data && md->guardian_data->guild_id) {
  6562. WBUFW(buf, 0) = cmd = 0x195;
  6563. WBUFB(buf,30) = 0;
  6564. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6565. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6566. } else if (battle_config.show_mob_info) {
  6567. char mobhp[50], *str_p = mobhp;
  6568. WBUFW(buf, 0) = cmd = 0x195;
  6569. if (battle_config.show_mob_info&4)
  6570. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6571. if (battle_config.show_mob_info&1)
  6572. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6573. if (battle_config.show_mob_info&2)
  6574. str_p += sprintf(str_p, "HP: %d%% | ",
  6575. md->status.max_hp > 10000?
  6576. md->status.hp/(md->status.max_hp/100):
  6577. 100*md->status.hp/md->status.max_hp);
  6578. //Even thought mobhp ain't a name, we send it as one so the client
  6579. //can parse it. [Skotlex]
  6580. if (str_p != mobhp) {
  6581. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6582. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6583. WBUFB(buf,54) = 0;
  6584. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6585. }
  6586. }
  6587. }
  6588. break;
  6589. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6590. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6591. // break;
  6592. return 0;
  6593. default:
  6594. if (battle_config.error_log)
  6595. ShowError("clif_parse_GetCharNameRequest : bad type %d(%d)\n", bl->type, bl->id);
  6596. return 0;
  6597. }
  6598. // if no receipient specified just update nearby clients
  6599. if (fd == 0)
  6600. clif_send(buf, packet_len(cmd), bl, AREA);
  6601. else {
  6602. WFIFOHEAD(fd, packet_len(cmd));
  6603. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  6604. WFIFOSET(fd, packet_len(cmd));
  6605. }
  6606. return 0;
  6607. }
  6608. //Used to update when a char leaves a party/guild. [Skotlex]
  6609. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6610. int clif_charnameupdate (struct map_session_data *ssd)
  6611. {
  6612. unsigned char buf[103];
  6613. int cmd = 0x195;
  6614. struct party_data *p = NULL;
  6615. struct guild *g = NULL;
  6616. nullpo_retr(0, ssd);
  6617. if (strlen(ssd->fakename)>1)
  6618. return 0; //No need to update as the party/guild was not displayed anyway.
  6619. WBUFW(buf,0) = cmd;
  6620. WBUFL(buf,2) = ssd->bl.id;
  6621. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6622. if (ssd->status.party_id > 0)
  6623. p = party_search(ssd->status.party_id);
  6624. if (ssd->status.guild_id > 0)
  6625. g = guild_search(ssd->status.guild_id);
  6626. if (p)
  6627. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6628. else
  6629. WBUFB(buf,30) = 0;
  6630. if (g)
  6631. {
  6632. int i, ps = -1;
  6633. for(i = 0; i < g->max_member; i++) {
  6634. if (g->member[i].account_id == ssd->status.account_id &&
  6635. g->member[i].char_id == ssd->status.char_id )
  6636. {
  6637. ps = g->member[i].position;
  6638. break;
  6639. }
  6640. }
  6641. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6642. {
  6643. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6644. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6645. } else { //Assume no guild.
  6646. WBUFB(buf,54) = 0;
  6647. WBUFB(buf,78) = 0;
  6648. }
  6649. } else {
  6650. WBUFB(buf,54) = 0;
  6651. WBUFB(buf,78) = 0;
  6652. }
  6653. // Update nearby clients
  6654. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  6655. return 0;
  6656. }
  6657. int clif_slide(struct block_list *bl, int x, int y){
  6658. unsigned char buf[10];
  6659. nullpo_retr(0, bl);
  6660. WBUFW(buf, 0) = 0x01ff;
  6661. WBUFL(buf, 2) = bl->id;
  6662. WBUFW(buf, 6) = x;
  6663. WBUFW(buf, 8) = y;
  6664. clif_send(buf, packet_len(0x1ff), bl, AREA);
  6665. return 0;
  6666. }
  6667. /*------------------------------------------
  6668. * @me command by lordalfa, rewritten implementation by Skotlex
  6669. *------------------------------------------*/
  6670. int clif_disp_overhead(struct map_session_data *sd, const char* mes)
  6671. {
  6672. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  6673. int len_mes = strlen(mes)+1; //Account for \0
  6674. if (len_mes + 8 >= 256) {
  6675. if (battle_config.error_log)
  6676. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6677. len_mes = 247; //Trunk it to avoid problems.
  6678. }
  6679. // send message to others
  6680. WBUFW(buf,0) = 0x8d;
  6681. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6682. WBUFL(buf,4) = sd->bl.id;
  6683. memcpy(WBUFP(buf,8), mes, len_mes);
  6684. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6685. // send back message to the speaker
  6686. WBUFW(buf,0) = 0x8e;
  6687. WBUFW(buf, 2) = len_mes + 4;
  6688. memcpy(WBUFP(buf,4), mes, len_mes);
  6689. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6690. return 0;
  6691. }
  6692. /*==========================
  6693. * Minimap fix [Kevin]
  6694. * Remove dot from minimap
  6695. *--------------------------*/
  6696. int clif_party_xy_remove(struct map_session_data *sd)
  6697. {
  6698. unsigned char buf[16];
  6699. nullpo_retr(0, sd);
  6700. WBUFW(buf,0)=0x107;
  6701. WBUFL(buf,2)=sd->status.account_id;
  6702. WBUFW(buf,6)=-1;
  6703. WBUFW(buf,8)=-1;
  6704. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6705. return 0;
  6706. }
  6707. //Displays gospel-buff information (thanks to Rayce):
  6708. //Type determines message based on this table:
  6709. /*
  6710. 0x15 End all negative status
  6711. 0x16 Immunity to all status
  6712. 0x17 MaxHP +100%
  6713. 0x18 MaxSP +100%
  6714. 0x19 All stats +20
  6715. 0x1c Enchant weapon with Holy element
  6716. 0x1d Enchant armor with Holy element
  6717. 0x1e DEF +25%
  6718. 0x1f ATK +100%
  6719. 0x20 HIT/Flee +50
  6720. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  6721. */
  6722. void clif_gospel_info(struct map_session_data *sd, int type)
  6723. {
  6724. int fd=sd->fd;
  6725. WFIFOHEAD(fd,packet_len(0x215));
  6726. WFIFOW(fd,0)=0x215;
  6727. WFIFOL(fd,2)=type;
  6728. WFIFOSET(fd, packet_len(0x215));
  6729. }
  6730. /*==========================================
  6731. * Info about Star Glaldiator save map [Komurka]
  6732. * type: 1: Information, 0: Map registered
  6733. *------------------------------------------*/
  6734. void clif_feel_info(struct map_session_data *sd, unsigned char feel_level, unsigned char type)
  6735. {
  6736. int fd=sd->fd;
  6737. char map_name[MAP_NAME_LENGTH_EXT];
  6738. snprintf(map_name, MAP_NAME_LENGTH_EXT, "%s.gat", mapindex_id2name(sd->feel_map[feel_level].index));
  6739. WFIFOHEAD(fd,packet_len(0x20e));
  6740. WFIFOW(fd,0)=0x20e;
  6741. memcpy(WFIFOP(fd,2),map_name, MAP_NAME_LENGTH_EXT);
  6742. WFIFOL(fd,26)=sd->bl.id;
  6743. WFIFOB(fd,30)=feel_level;
  6744. WFIFOB(fd,31)=type?1:0;
  6745. WFIFOSET(fd, packet_len(0x20e));
  6746. }
  6747. /*==========================================
  6748. * Info about Star Glaldiator hate mob [Komurka]
  6749. * type: 1: Register mob, 0: Information.
  6750. *------------------------------------------*/
  6751. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  6752. {
  6753. int fd=sd->fd;
  6754. WFIFOHEAD(fd,packet_len(0x20e));
  6755. WFIFOW(fd,0)=0x20e;
  6756. if (pcdb_checkid(class_))
  6757. strncpy((char*)WFIFOP(fd,2),job_name(class_), NAME_LENGTH);
  6758. else if (mobdb_checkid(class_))
  6759. strncpy((char*)WFIFOP(fd,2),mob_db(class_)->jname, NAME_LENGTH);
  6760. else //Really shouldn't happen...
  6761. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  6762. WFIFOL(fd,26)=sd->bl.id;
  6763. WFIFOB(fd,30)=hate_level;
  6764. WFIFOB(fd,31)=type?10:11; //Register/Info
  6765. WFIFOSET(fd, packet_len(0x20e));
  6766. }
  6767. /*==========================================
  6768. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6769. *------------------------------------------*/
  6770. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  6771. {
  6772. int fd=sd->fd;
  6773. WFIFOHEAD(fd,packet_len(0x20e));
  6774. WFIFOW(fd,0)=0x20e;
  6775. strncpy((char*)WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6776. WFIFOL(fd,26)=mob_id;
  6777. WFIFOB(fd,30)=progress; //Message to display
  6778. WFIFOB(fd,31)=20;
  6779. WFIFOSET(fd, packet_len(0x20e));
  6780. }
  6781. /*==========================================
  6782. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  6783. *------------------------------------------*/
  6784. void clif_feel_hate_reset(struct map_session_data *sd)
  6785. {
  6786. int fd=sd->fd;
  6787. WFIFOHEAD(fd,packet_len(0x20e));
  6788. WFIFOW(fd,0)=0x20e;
  6789. memset(WFIFOP(fd,2), 0, NAME_LENGTH); //Blank name as all was reset.
  6790. WFIFOL(fd,26)=sd->bl.id;
  6791. WFIFOB(fd,30)=0; //Feel/hate level: irrelevant
  6792. WFIFOB(fd,31)=30;
  6793. WFIFOSET(fd, packet_len(0x20e));
  6794. }
  6795. // ---------------------
  6796. // clif_guess_PacketVer
  6797. // ---------------------
  6798. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  6799. // error codes:
  6800. // 0 - Success
  6801. // 1 - Unknown packet_ver
  6802. // 2 - Invalid account_id
  6803. // 3 - Invalid char_id
  6804. // 4 - Invalid login_id1 (reserved)
  6805. // 5 - Invalid client_tick (reserved)
  6806. // 6 - Invalid sex
  6807. // Only the first 'invalid' error that appears is used.
  6808. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  6809. {
  6810. static int err = 1;
  6811. static int packet_ver = -1;
  6812. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  6813. if (get_previous)
  6814. {//For quick reruns, since the normal code flow is to fetch this once to identify the packet version, then again in the wanttoconnect function. [Skotlex]
  6815. if( error )
  6816. *error = err;
  6817. return packet_ver;
  6818. }
  6819. //By default, start searching on the default one.
  6820. err = 1;
  6821. packet_ver = clif_config.packet_db_ver;
  6822. cmd = RFIFOW(fd,0);
  6823. packet_len = RFIFOREST(fd);
  6824. #define SET_ERROR(n) \
  6825. if( err == 1 )\
  6826. err = n;\
  6827. //define SET_ERROR
  6828. #define CHECK_PACKET_VER() \
  6829. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  6830. ;/* not wanttoconnection or wrong length */\
  6831. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > max_account_id )\
  6832. { SET_ERROR(2); }/* invalid account_id */\
  6833. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 || value > max_char_id )\
  6834. { SET_ERROR(3); }/* invalid char_id */\
  6835. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  6836. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  6837. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  6838. { SET_ERROR(6); }/* invalid sex */\
  6839. else\
  6840. {\
  6841. err = 0;\
  6842. if( error )\
  6843. *error = 0;\
  6844. return packet_ver;\
  6845. }\
  6846. //define CHECK_PACKET_VER
  6847. CHECK_PACKET_VER();//Default packet version found.
  6848. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  6849. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  6850. CHECK_PACKET_VER();
  6851. }
  6852. if( error )
  6853. *error = err;
  6854. packet_ver = -1;
  6855. return -1;
  6856. #undef SET_ERROR
  6857. #undef CHECK_PACKET_VER
  6858. }
  6859. // ------------
  6860. // clif_parse_*
  6861. // ------------
  6862. // パケット読み取って色々操作
  6863. /*==========================================
  6864. *
  6865. *------------------------------------------*/
  6866. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  6867. {
  6868. int cmd, account_id, char_id, login_id1, sex;
  6869. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  6870. int packet_ver; // 5: old, 6: 7july04, 7: 13july04, 8: 26july04, 9: 9aug04/16aug04/17aug04, 10: 6sept04, 11: 21sept04, 12: 18oct04, 13: 25oct04 (by [Yor])
  6871. if (sd) {
  6872. if (battle_config.error_log)
  6873. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)?\n");
  6874. return;
  6875. }
  6876. // Only valid packet version get here
  6877. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  6878. cmd = RFIFOW(fd,0);
  6879. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  6880. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  6881. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  6882. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  6883. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  6884. if( packet_ver < 5 || // reject really old client versions
  6885. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  6886. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  6887. {// packet version rejected
  6888. WFIFOHEAD(fd,packet_len(0x6a));
  6889. WFIFOW(fd,0) = 0x6a;
  6890. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  6891. WFIFOSET(fd,packet_len(0x6a));
  6892. clif_setwaitclose(fd);
  6893. return;
  6894. } else
  6895. {// packet version accepted
  6896. struct block_list* bl;
  6897. if( (bl=map_id2bl(account_id)) != NULL && bl->type != BL_PC )
  6898. {// non-player object already has that id
  6899. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  6900. WFIFOHEAD(fd,packet_len(0x6a));
  6901. WFIFOW(fd,0) = 0x6a;
  6902. WFIFOB(fd,2) = 3; // Rejected by server
  6903. WFIFOSET(fd,packet_len(0x6a));
  6904. clif_setwaitclose(fd);
  6905. return;
  6906. }
  6907. }
  6908. CREATE(sd, TBL_PC, 1);
  6909. sd->fd = fd;
  6910. sd->packet_ver = packet_ver;
  6911. session[fd]->session_data = sd;
  6912. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  6913. WFIFOHEAD(fd,4);
  6914. WFIFOL(fd,0) = sd->bl.id;
  6915. WFIFOSET(fd,4);
  6916. chrif_authreq(sd);
  6917. return;
  6918. }
  6919. /*==========================================
  6920. * 007d クライアント側マップ読み込み完了
  6921. * map侵入時に必要なデータを全て送りつける
  6922. *------------------------------------------*/
  6923. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  6924. {
  6925. if(sd->bl.prev != NULL)
  6926. return;
  6927. if (!sd->state.auth)
  6928. { //Character loading is not complete yet!
  6929. //Let pc_reg_received reinvoke this when ready.
  6930. sd->state.connect_new = 0;
  6931. return;
  6932. }
  6933. if (sd->state.rewarp)
  6934. { //Rewarp player.
  6935. sd->state.rewarp = 0;
  6936. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  6937. return;
  6938. }
  6939. // look
  6940. #if PACKETVER < 4
  6941. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  6942. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  6943. #else
  6944. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  6945. #endif
  6946. if(sd->vd.cloth_color)
  6947. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6948. // item
  6949. pc_checkitem(sd);
  6950. clif_inventorylist(sd);
  6951. // cart
  6952. if(pc_iscarton(sd)) {
  6953. clif_cartlist(sd);
  6954. clif_updatestatus(sd,SP_CARTINFO);
  6955. }
  6956. // weight max, now
  6957. clif_updatestatus(sd,SP_MAXWEIGHT);
  6958. clif_updatestatus(sd,SP_WEIGHT);
  6959. // Party
  6960. if(sd->status.party_id) {
  6961. party_send_movemap(sd);
  6962. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  6963. }
  6964. // guild
  6965. if(sd->status.guild_id)
  6966. guild_send_memberinfoshort(sd,1);
  6967. if(battle_config.pc_invincible_time > 0) {
  6968. if(map_flag_gvg(sd->bl.m))
  6969. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  6970. else
  6971. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  6972. }
  6973. map_addblock(&sd->bl); // ブロック登録
  6974. clif_spawn(&sd->bl); // spawn
  6975. if(map[sd->bl.m].flag.pvp) {
  6976. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  6977. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  6978. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  6979. sd->pvp_rank = 0;
  6980. sd->pvp_lastusers = 0;
  6981. sd->pvp_point = 5;
  6982. sd->pvp_won = 0;
  6983. sd->pvp_lost = 0;
  6984. }
  6985. clif_set0199(fd,1);
  6986. } else
  6987. // set flag, if it's a duel [LuzZza]
  6988. if(sd->duel_group)
  6989. clif_set0199(fd,1);
  6990. if (map[sd->bl.m].flag.gvg_dungeon)
  6991. {
  6992. clif_set0199(fd,1); //TODO: Figure out the real packet to send here.
  6993. if (!sd->pvp_point)
  6994. {
  6995. sd->pvp_point = 5; //Need to die twice to be warped out.
  6996. sd->pvp_won = 0;
  6997. sd->pvp_lost = 0;
  6998. }
  6999. }
  7000. if(map_flag_gvg(sd->bl.m))
  7001. clif_set0199(fd,3);
  7002. map_foreachinarea(clif_getareachar, sd->bl.m,
  7003. sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE,
  7004. BL_ALL, sd);
  7005. // pet
  7006. if(sd->pd) {
  7007. map_addblock(&sd->pd->bl);
  7008. clif_spawn(&sd->pd->bl);
  7009. clif_send_petdata(sd,0,0);
  7010. clif_send_petdata(sd,5,battle_config.pet_hair_style);
  7011. clif_send_petstatus(sd);
  7012. // skill_unit_move(&sd->pd->bl,gettick(),1);
  7013. }
  7014. //homunculus [blackhole89]
  7015. if(merc_is_hom_active(sd->hd)) {
  7016. map_addblock(&sd->hd->bl);
  7017. clif_spawn(&sd->hd->bl);
  7018. clif_hominfo(sd,sd->hd,1);
  7019. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  7020. clif_send_homdata(sd,0,0);
  7021. clif_homskillinfoblock(sd);
  7022. if (battle_config.hom_setting&0x8)
  7023. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  7024. if (!(battle_config.hom_setting&0x2))
  7025. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  7026. }
  7027. if(sd->state.connect_new) {
  7028. int lv;
  7029. sd->state.connect_new = 0;
  7030. clif_skillinfoblock(sd);
  7031. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7032. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7033. clif_updatestatus(sd,SP_SKILLPOINT);
  7034. clif_initialstatus(sd);
  7035. if (sd->sc.option&OPTION_FALCON)
  7036. clif_status_load(&sd->bl, SI_FALCON, 1);
  7037. if (sd->sc.option&OPTION_RIDING)
  7038. clif_status_load(&sd->bl, SI_RIDING, 1);
  7039. if(sd->status.manner < 0)
  7040. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7041. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7042. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7043. if(sd->bl.m == sd->feel_map[0].m
  7044. || sd->bl.m == sd->feel_map[1].m
  7045. || sd->bl.m == sd->feel_map[2].m)
  7046. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7047. }
  7048. if(sd->pd && sd->pd->pet.intimate > 900)
  7049. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7050. if(merc_is_hom_active(sd->hd))
  7051. merc_hom_init_timers(sd->hd);
  7052. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7053. {
  7054. sd->state.night = 1;
  7055. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7056. }
  7057. // Notify everyone that this char logged in [Skotlex].
  7058. clif_foreachclient(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  7059. //Login Event
  7060. npc_script_event(sd, NPCE_LOGIN);
  7061. } else {
  7062. //For some reason the client "loses" these on map-change.
  7063. clif_updatestatus(sd,SP_STR);
  7064. clif_updatestatus(sd,SP_AGI);
  7065. clif_updatestatus(sd,SP_VIT);
  7066. clif_updatestatus(sd,SP_INT);
  7067. clif_updatestatus(sd,SP_DEX);
  7068. clif_updatestatus(sd,SP_LUK);
  7069. sd->state.using_fake_npc = 0;
  7070. //New 'night' effect by dynamix [Skotlex]
  7071. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7072. { //Display night.
  7073. if (!sd->state.night) {
  7074. sd->state.night = 1;
  7075. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7076. }
  7077. } else if (sd->state.night) { //Clear night display.
  7078. sd->state.night = 0;
  7079. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7080. }
  7081. if(sd->npc_id)
  7082. npc_event_dequeue(sd);
  7083. }
  7084. // Lance
  7085. if(sd->state.event_loadmap && map[sd->bl.m].flag.loadevent){
  7086. pc_setregstr(sd, add_str("@maploaded$"), map[sd->bl.m].name);
  7087. npc_script_event(sd, NPCE_LOADMAP);
  7088. }
  7089. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7090. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7091. if (sd->sc.opt2) //Client loses these on warp.
  7092. clif_changeoption(&sd->bl);
  7093. clif_weather_check(sd);
  7094. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7095. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7096. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7097. else
  7098. sd->areanpc_id = 0;
  7099. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  7100. if(pc_isdead(sd))
  7101. clif_clearunit_area(&sd->bl, 1);
  7102. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  7103. // else
  7104. // clif_changed_dir(&sd->bl, SELF);
  7105. // Trigger skill effects if you appear standing on them
  7106. if(!battle_config.pc_invincible_time)
  7107. skill_unit_move(&sd->bl,gettick(),1);
  7108. }
  7109. /*==========================================
  7110. *
  7111. *------------------------------------------*/
  7112. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  7113. {
  7114. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7115. WFIFOHEAD(fd, packet_len(0x7f));
  7116. WFIFOW(fd,0)=0x7f;
  7117. WFIFOL(fd,2)=gettick();
  7118. WFIFOSET(fd,packet_len(0x7f));
  7119. // removed until the socket problems are fixed. [FlavioJS]
  7120. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  7121. return;
  7122. }
  7123. /*==========================================
  7124. *
  7125. *------------------------------------------*/
  7126. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  7127. {
  7128. int x, y;
  7129. int cmd;
  7130. if (pc_isdead(sd)) {
  7131. clif_clearunit_area(&sd->bl, 1);
  7132. return;
  7133. }
  7134. if (sd->sc.opt1 && sd->sc.opt1 == OPT1_STONEWAIT)
  7135. ; //You CAN walk on this OPT1 value.
  7136. else if (clif_cant_act(sd))
  7137. return;
  7138. if(sd->sc.count && sd->sc.data[SC_RUN].timer != -1)
  7139. return;
  7140. pc_delinvincibletimer(sd);
  7141. cmd = RFIFOW(fd,0);
  7142. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7143. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7144. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7145. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7146. //Set last idle time... [Skotlex]
  7147. sd->idletime = last_tick;
  7148. unit_walktoxy(&sd->bl, x, y, 4);
  7149. }
  7150. /*==========================================
  7151. *
  7152. *------------------------------------------*/
  7153. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  7154. {
  7155. WFIFOHEAD(fd,packet_len(0x18b));
  7156. WFIFOW(fd,0) = 0x18b;
  7157. /* Rovert's prevent logout option fixed [Valaris] */
  7158. if (sd->sc.data[SC_CLOAKING].timer==-1 && sd->sc.data[SC_HIDING].timer==-1 &&
  7159. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7160. ) {
  7161. clif_setwaitclose(fd);
  7162. WFIFOW(fd,2)=0;
  7163. } else {
  7164. WFIFOW(fd,2)=1;
  7165. }
  7166. WFIFOSET(fd,packet_len(0x18b));
  7167. }
  7168. /*==========================================
  7169. *
  7170. *------------------------------------------*/
  7171. void check_fake_id(int fd, struct map_session_data *sd, int target_id)
  7172. {
  7173. // if player asks for the fake player (only bot and modified client can see a hiden player)
  7174. /* if (target_id == server_char_id) {
  7175. char message_to_gm[strlen(msg_txt(536)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7176. sprintf(message_to_gm, msg_txt(536), sd->status.name, sd->status.account_id); // Character '%s' (account: %d) try to use a bot (it tries to detect a fake player).
  7177. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7178. // if we block people
  7179. if (battle_config.ban_bot < 0) {
  7180. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7181. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7182. // message about the ban
  7183. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7184. // if we ban people
  7185. } else if (battle_config.ban_bot > 0) {
  7186. chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, 0, battle_config.ban_bot, 0); // type: 2 - ban (year, month, day, hour, minute, second)
  7187. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7188. // message about the ban
  7189. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7190. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7191. // message about the ban
  7192. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7193. }
  7194. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7195. // send this info cause the bot ask until get an answer, damn spam
  7196. memset(WPACKETP(0), 0, packet_len(0x95));
  7197. WPACKETW(0) = 0x95;
  7198. WPACKETL(2) = server_char_id;
  7199. strncpy(WPACKETP(6), sd->status.name, 24);
  7200. SENDPACKET(fd, packet_len(0x95));
  7201. // take fake player out of screen
  7202. WPACKETW(0) = 0x80;
  7203. WPACKETL(2) = server_char_id;
  7204. WPACKETB(6) = 0;
  7205. SENDPACKET(fd, packet_len(0x80));
  7206. // take fake mob out of screen
  7207. WPACKETW(0) = 0x80;
  7208. WPACKETL(2) = server_fake_mob_id;
  7209. WPACKETB(6) = 0;
  7210. SENDPACKET(fd, packet_len(0x80));
  7211. }
  7212. // if player asks for the fake mob (only bot and modified client can see a hiden mob)
  7213. if (target_id == server_fake_mob_id) {
  7214. int fake_mob;
  7215. char message_to_gm[strlen(msg_txt(537)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7216. sprintf(message_to_gm, msg_txt(537), sd->status.name, sd->status.account_id); // Character '%s' (account: %d) try to use a bot (it tries to detect a fake mob).
  7217. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7218. // if we block people
  7219. if (battle_config.ban_bot < 0) {
  7220. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7221. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7222. // message about the ban
  7223. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7224. // if we ban people
  7225. } else if (battle_config.ban_bot > 0) {
  7226. chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, 0, battle_config.ban_bot, 0); // type: 2 - ban (year, month, day, hour, minute, second)
  7227. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7228. // message about the ban
  7229. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7230. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7231. // message about the ban
  7232. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7233. }
  7234. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7235. // send this info cause the bot ask until get an answer, damn spam
  7236. memset(WPACKETP(0), 0, packet_len(0x95));
  7237. WPACKETW(0) = 0x95;
  7238. WPACKETL(2) = server_fake_mob_id;
  7239. fake_mob = fake_mob_list[(sd->bl.m + sd->fd + sd->status.char_id) % (sizeof(fake_mob_list) / sizeof(fake_mob_list[0]))]; // never same mob
  7240. if (!mobdb_checkid(fake_mob))
  7241. fake_mob = 1002; // poring (default)
  7242. strncpy(WPACKETP(6), mob_db[fake_mob].name, 24);
  7243. SENDPACKET(fd, packet_len(0x95));
  7244. // take fake mob out of screen
  7245. WPACKETW(0) = 0x80;
  7246. WPACKETL(2) = server_fake_mob_id;
  7247. WPACKETB(6) = 0;
  7248. SENDPACKET(fd, packet_len(0x80));
  7249. // take fake player out of screen
  7250. WPACKETW(0) = 0x80;
  7251. WPACKETL(2) = server_char_id;
  7252. WPACKETB(6) = 0;
  7253. SENDPACKET(fd, packet_len(0x80));
  7254. }
  7255. */
  7256. return;
  7257. }
  7258. /*==========================================
  7259. *
  7260. *------------------------------------------*/
  7261. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  7262. {
  7263. int account_id;
  7264. struct block_list* bl;
  7265. struct status_change *sc;
  7266. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7267. if(account_id<0 && -account_id == sd->bl.id) // for disguises [Valaris]
  7268. account_id= sd->bl.id;
  7269. bl = map_id2bl(account_id);
  7270. //Is this possible? Lagged clients could request names of already gone mobs/players. [Skotlex]
  7271. if (!bl) return;
  7272. sc = status_get_sc(bl);
  7273. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  7274. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  7275. pc_isGM(sd) < battle_config.hack_info_GM_level
  7276. ) {
  7277. //GM characters (with client side GM enabled are able to see invisible stuff) [Lance]
  7278. //Asked name of invisible player, this shouldn't be possible!
  7279. //Possible bot? Thanks to veider and qspirit
  7280. //FIXME: Still isn't perfected as clients keep asking for this on legitimate situations.
  7281. char gm_msg[256];
  7282. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requested the name of an invisible target.", sd->status.name, sd->status.account_id);
  7283. ShowWarning(gm_msg);
  7284. // information is sended to all online GM
  7285. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7286. return;
  7287. }
  7288. clif_charnameack(fd, bl);
  7289. }
  7290. /*==========================================
  7291. * Validates and processes global messages
  7292. * S 008c/00f3 <packet len>.w <strz>.?B
  7293. *------------------------------------------*/
  7294. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  7295. {
  7296. char* message;
  7297. unsigned int packetlen, messagelen, namelen;
  7298. packetlen = RFIFOW(fd,2);
  7299. if (packetlen > RFIFOREST(fd)) { // there has to be enough data to read
  7300. ShowWarning("clif_parse_GlobalMessage: Received malformed packet from player '%s' (length is incorrect)!", sd->status.name);
  7301. return;
  7302. }
  7303. if (packetlen < 4 + 1) { // 4-byte header and at least an empty string is expected
  7304. ShowWarning("clif_parse_GlobalMessage: Received malformed packet from player '%s' (no message data)!", sd->status.name);
  7305. return;
  7306. }
  7307. message = (char*)RFIFOP(fd,4);
  7308. messagelen = packetlen - 4; // let's trust the client here, nothing can go wrong and it saves us one strlen()
  7309. if (messagelen > CHAT_SIZE) { // messages mustn't be too long
  7310. int i;
  7311. // special case here - allow some more freedom for frost joke & dazzler
  7312. // TODO:? You could use a state flag when FrostJoke/Scream is used, and unset it once the skill triggers. [Skotlex]
  7313. for(i = 0; i < MAX_SKILLTIMERSKILL && sd->ud.skilltimerskill[i] &&
  7314. sd->ud.skilltimerskill[i]->skill_id != BA_FROSTJOKE &&
  7315. sd->ud.skilltimerskill[i]->skill_id != DC_SCREAM; i++);
  7316. if (i == MAX_SKILLTIMERSKILL || !sd->ud.skilltimerskill[i]) { // normal message, too long
  7317. ShowWarning("clif_parse_GlobalMessage: Player '%s' sent a message too long ('%.*s')!", sd->status.name, CHAT_SIZE, message);
  7318. return;
  7319. }
  7320. if (messagelen > 255) { // frost joke/dazzler, but still too long
  7321. ShowWarning("clif_parse_GlobalMessage: Player '%s' sent a message too long ('%.*s')!", sd->status.name, 255, message);
  7322. return;
  7323. }
  7324. }
  7325. if (message[messagelen-1] != '\0') { // message must be zero-terminated
  7326. ShowWarning("clif_parse_GlobalMessage: Player '%s' sent an unterminated string!", sd->status.name);
  7327. return;
  7328. }
  7329. namelen = strnlen(sd->status.name, NAME_LENGTH - 1);
  7330. if (strncmp(message, sd->status.name, namelen) || // the name has to match the speaker's name
  7331. message[namelen] != ' ' || message[namelen+1] != ':' || message[namelen+2] != ' ') // completely, not just the prefix
  7332. {
  7333. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  7334. clif_setwaitclose(fd); // Just kick them out to correct it.
  7335. ShowWarning("clif_parse_GlobalMessage: Player '%.*s' sent a message using an incorrect name ('%s')! Forcing a relog...", namelen, sd->status.name, message);
  7336. return;
  7337. }
  7338. if (is_atcommand(fd, sd, message) != AtCommand_None ||
  7339. is_charcommand(fd, sd, message) != CharCommand_None)
  7340. return;
  7341. if (sd->sc.count &&
  7342. (sd->sc.data[SC_BERSERK].timer != -1 ||
  7343. (sd->sc.data[SC_NOCHAT].timer != -1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)))
  7344. return;
  7345. if (battle_config.min_chat_delay)
  7346. { //[Skotlex]
  7347. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7348. return;
  7349. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7350. }
  7351. // send message to others
  7352. WFIFOHEAD(fd, messagelen + 8);
  7353. WFIFOW(fd,0) = 0x8d;
  7354. WFIFOW(fd,2) = messagelen + 8;
  7355. WFIFOL(fd,4) = sd->bl.id;
  7356. memcpy(WFIFOP(fd,8), message, messagelen);
  7357. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7358. // send back message to the speaker
  7359. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), packetlen);
  7360. WFIFOW(fd,0) = 0x8e;
  7361. WFIFOSET(fd, WFIFOW(fd,2));
  7362. #ifdef PCRE_SUPPORT
  7363. // trigger listening mobs/npcs
  7364. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, message, strlen(message), &sd->bl);
  7365. map_foreachinrange(mob_chat_sub, &sd->bl, AREA_SIZE, BL_MOB, message, strlen(message), &sd->bl);
  7366. #endif
  7367. // check for special supernovice phrase
  7368. if ((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE) {
  7369. int next = pc_nextbaseexp(sd);
  7370. if (next > 0 && (sd->status.base_exp * 1000 / next)% 100 == 0) { // 0%, 10%, 20%, ...
  7371. switch (sd->state.snovice_call_flag) {
  7372. case 0:
  7373. if (strstr(message, msg_txt(504))) // "Guardian Angel, can you hear my voice? ^^;"
  7374. sd->state.snovice_call_flag++;
  7375. break;
  7376. case 1: {
  7377. char buf[256];
  7378. sprintf(buf, msg_txt(505), sd->status.name);
  7379. if (strstr(message, buf)) // "My name is %s, and I'm a Super Novice~"
  7380. sd->state.snovice_call_flag++;
  7381. }
  7382. break;
  7383. case 2:
  7384. if (strstr(message, msg_txt(506))) // "Please help me~ T.T"
  7385. sd->state.snovice_call_flag++;
  7386. break;
  7387. case 3:
  7388. if (skillnotok(MO_EXPLOSIONSPIRITS,sd))
  7389. break; //Do not override the noskill mapflag. [Skotlex]
  7390. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7391. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  7392. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7393. sd->state.snovice_call_flag = 0;
  7394. break;
  7395. }
  7396. }
  7397. }
  7398. // Chat logging type 'O' / Global Chat
  7399. if( log_config.chat&1 && !(agit_flag && log_config.chat&32) )
  7400. log_chat("O", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7401. return;
  7402. }
  7403. int clif_message(struct block_list *bl, const char* msg)
  7404. {
  7405. unsigned short msg_len = strlen(msg) + 1;
  7406. unsigned char buf[256];
  7407. nullpo_retr(0, bl);
  7408. WBUFW(buf, 0) = 0x8d;
  7409. WBUFW(buf, 2) = msg_len + 8;
  7410. WBUFL(buf, 4) = bl->id;
  7411. memcpy(WBUFP(buf, 8), msg, msg_len);
  7412. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC); // by Gengar
  7413. return 0;
  7414. }
  7415. /*==========================================
  7416. * /mm /mapmove (as @rura GM command)
  7417. *------------------------------------------*/
  7418. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  7419. {
  7420. char output[MAP_NAME_LENGTH_EXT+15]; // Max length of a short: ' -6XXXX' -> 7 digits
  7421. char message[MAP_NAME_LENGTH_EXT+15+5]; // "/mm "+output
  7422. char *map_name;
  7423. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7424. return;
  7425. if(pc_isGM(sd) < get_atcommand_level(AtCommand_MapMove))
  7426. return;
  7427. map_name = (char*)RFIFOP(fd,2);
  7428. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  7429. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7430. atcommand_rura(fd, sd, "@rura", output);
  7431. if(log_config.gm && get_atcommand_level(AtCommand_MapMove) >= log_config.gm)
  7432. {
  7433. sprintf(message, "/mm %s", output);
  7434. log_atcommand(sd, message);
  7435. }
  7436. return;
  7437. }
  7438. /*==========================================
  7439. *
  7440. *------------------------------------------*/
  7441. void clif_changed_dir(struct block_list *bl, int type)
  7442. {
  7443. unsigned char buf[64];
  7444. WBUFW(buf,0) = 0x9c;
  7445. WBUFL(buf,2) = bl->id;
  7446. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7447. WBUFB(buf,8) = unit_getdir(bl);
  7448. clif_send(buf, packet_len(0x9c), bl, type);
  7449. if (disguised(bl)) {
  7450. WBUFL(buf,2) = -bl->id;
  7451. WBUFW(buf,6) = 0;
  7452. clif_send(buf, packet_len(0x9c), bl, SELF);
  7453. }
  7454. return;
  7455. }
  7456. /*==========================================
  7457. *
  7458. *------------------------------------------*/
  7459. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  7460. {
  7461. unsigned char headdir, dir;
  7462. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7463. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7464. pc_setdir(sd, dir, headdir);
  7465. clif_changed_dir(&sd->bl, AREA_WOS);
  7466. return;
  7467. }
  7468. /*==========================================
  7469. *
  7470. *------------------------------------------*/
  7471. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  7472. {
  7473. unsigned char buf[64];
  7474. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7475. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7476. clif_skill_fail(sd, 1, 0, 1);
  7477. return;
  7478. }
  7479. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7480. if (sd->emotionlasttime >= time(NULL)) {
  7481. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7482. clif_skill_fail(sd, 1, 0, 1);
  7483. return;
  7484. }
  7485. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7486. WBUFW(buf,0) = 0xc0;
  7487. WBUFL(buf,2) = sd->bl.id;
  7488. WBUFB(buf,6) = RFIFOB(fd,2);
  7489. clif_send(buf, packet_len(0xc0), &sd->bl, AREA);
  7490. } else
  7491. clif_skill_fail(sd, 1, 0, 1);
  7492. }
  7493. /*==========================================
  7494. *
  7495. *------------------------------------------*/
  7496. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  7497. {
  7498. WFIFOHEAD(fd,packet_len(0xc2));
  7499. WFIFOW(fd,0) = 0xc2;
  7500. WFIFOL(fd,2) = map_getusers();
  7501. WFIFOSET(fd,packet_len(0xc2));
  7502. }
  7503. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7504. {
  7505. if (pc_isdead(sd)) {
  7506. clif_clearunit_area(&sd->bl, 1);
  7507. return;
  7508. }
  7509. if (sd->sc.count &&
  7510. (sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  7511. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  7512. sd->sc.data[SC_BLADESTOP].timer != -1))
  7513. return;
  7514. pc_stop_walking(sd, 1);
  7515. pc_stop_attack(sd);
  7516. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7517. target_id = sd->bl.id;
  7518. switch(action_type)
  7519. {
  7520. case 0x00: // once attack
  7521. case 0x07: // continuous attack
  7522. if (clif_cant_act(sd) || sd->sc.option&OPTION_HIDE)
  7523. return;
  7524. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  7525. return;
  7526. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7527. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7528. clif_skill_fail(sd, 1, 4, 0);
  7529. return;
  7530. }
  7531. }
  7532. pc_delinvincibletimer(sd);
  7533. sd->idletime = last_tick;
  7534. unit_attack(&sd->bl, target_id, action_type != 0);
  7535. break;
  7536. case 0x02: // sitdown
  7537. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7538. clif_skill_fail(sd, 1, 0, 2);
  7539. break;
  7540. }
  7541. if(pc_issit(sd)) {
  7542. //Bugged client? Just refresh them.
  7543. clif_sitting(sd, SELF);
  7544. return;
  7545. }
  7546. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7547. break;
  7548. if (sd->sc.count && (
  7549. sd->sc.data[SC_DANCING].timer != -1 ||
  7550. (sd->sc.data[SC_GRAVITATION].timer != -1 && sd->sc.data[SC_GRAVITATION].val3 == BCT_SELF)
  7551. )) //No sitting during these states neither.
  7552. break;
  7553. pc_setsit(sd);
  7554. skill_sit(sd, 1);
  7555. clif_sitting(sd, AREA);
  7556. break;
  7557. case 0x03: // standup
  7558. if (!pc_issit(sd)) {
  7559. //Bugged client? Just refresh them.
  7560. clif_standing(sd, SELF);
  7561. return;
  7562. }
  7563. pc_setstand(sd);
  7564. skill_sit(sd, 0);
  7565. clif_standing(sd, AREA);
  7566. break;
  7567. }
  7568. }
  7569. /*==========================================
  7570. *
  7571. *------------------------------------------*/
  7572. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  7573. {
  7574. clif_parse_ActionRequest_sub(sd,
  7575. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7576. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7577. gettick()
  7578. );
  7579. }
  7580. /*==========================================
  7581. *
  7582. *------------------------------------------*/
  7583. void clif_parse_Restart(int fd, struct map_session_data *sd)
  7584. {
  7585. switch(RFIFOB(fd,2)) {
  7586. case 0x00:
  7587. if (!pc_isdead(sd))
  7588. break;
  7589. pc_setstand(sd);
  7590. pc_setrestartvalue(sd, 3);
  7591. if (pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, 2))
  7592. clif_resurrection(&sd->bl, 1); //If warping fails, send a normal stand up packet.
  7593. break;
  7594. case 0x01:
  7595. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7596. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7597. { //Send to char-server for character selection.
  7598. chrif_charselectreq(sd, session[fd]->client_addr);
  7599. } else {
  7600. WFIFOHEAD(fd,packet_len(0x18b));
  7601. WFIFOW(fd,0)=0x18b;
  7602. WFIFOW(fd,2)=1;
  7603. WFIFOSET(fd,packet_len(0x018b));
  7604. }
  7605. break;
  7606. }
  7607. }
  7608. /*==========================================
  7609. * Transmission of a wisp (S 0096 <len>.w <nick>.24B <message>.?B)
  7610. *------------------------------------------*/
  7611. void clif_parse_Wis(int fd, struct map_session_data *sd)
  7612. {
  7613. char *command, *msg;
  7614. struct map_session_data *dstsd;
  7615. int i=0;
  7616. struct npc_data *npc;
  7617. char split_data[10][50];
  7618. char target[NAME_LENGTH+1];
  7619. char output[256];
  7620. unsigned int len;
  7621. len = RFIFOW(fd,2); //Packet length
  7622. if (len < 28)
  7623. { //Invalid packet, specified size is less than minimum! [Skotlex]
  7624. ShowWarning("Hack on Whisper: %s (AID/CID: %d:%d)!\n", sd->status.name, sd->status.account_id, sd->status.char_id);
  7625. clif_setwaitclose(fd);
  7626. return;
  7627. }
  7628. if (len == 28) return; //Not sure if client really lets you send a blank line.
  7629. len-=28; //Message length
  7630. // 24+3+(RFIFOW(fd,2)-28)+1 <- last 1 is '\0'
  7631. command = (char*)aMallocA((NAME_LENGTH+4+len) * sizeof(char));
  7632. //No need for out of memory checks, malloc.c aborts the map when that happens.
  7633. msg = command;
  7634. msg+= sprintf(command, "%s : ", sd->status.name);
  7635. memcpy(msg, RFIFOP(fd, 28), len);
  7636. mes_len_check(msg, len, CHATBOX_SIZE);
  7637. if ((is_charcommand(fd, sd, command) != CharCommand_None) ||
  7638. (is_atcommand(fd, sd, command) != AtCommand_None)) {
  7639. aFree(command);
  7640. return;
  7641. }
  7642. if (sd->sc.count &&
  7643. (sd->sc.data[SC_BERSERK].timer!=-1 ||
  7644. (sd->sc.data[SC_NOCHAT].timer != -1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT))) {
  7645. aFree(command);
  7646. return;
  7647. }
  7648. if (battle_config.min_chat_delay)
  7649. { //[Skotlex]
  7650. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  7651. aFree(command);
  7652. return;
  7653. }
  7654. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7655. }
  7656. memcpy(&target,RFIFOP(fd, 4),NAME_LENGTH);
  7657. target[NAME_LENGTH]='\0';
  7658. // Chat logging type 'W' / Whisper
  7659. if( log_config.chat&2 && !(agit_flag && log_config.chat&32) )
  7660. log_chat("W", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, msg);
  7661. //-------------------------------------------------------//
  7662. // Lordalfa - Paperboy - To whisper NPC commands //
  7663. //-------------------------------------------------------//
  7664. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) >4)) {
  7665. char *str= target+4; //Skip the NPC: string part.
  7666. if ((npc = npc_name2id(str)))
  7667. {
  7668. char *split;
  7669. str = msg;
  7670. for( i=0; i < 10; ++i )
  7671. {// Splits the message using '#' as separators
  7672. split = strchr(str,'#');
  7673. if( split == NULL )
  7674. { // use the remaining string
  7675. strncpy(split_data[i], str, sizeof(split_data[0])/sizeof(char));
  7676. split_data[i][sizeof(split_data[0])/sizeof(char)-1] = '\0';
  7677. for( ++i; i < 10; ++i )
  7678. split_data[i][0] = '\0';
  7679. break;
  7680. }
  7681. *split = '\0';
  7682. strncpy(split_data[i], str, sizeof(split_data[0])/sizeof(char));
  7683. split_data[i][sizeof(split_data[0])/sizeof(char)-1] = '\0';
  7684. str = split+1;
  7685. }
  7686. for (i=0;i<10;i++)
  7687. {
  7688. sprintf(output, "@whispervar%d$", i);
  7689. set_var(sd,output,(char *) split_data[i]);
  7690. }
  7691. sprintf(output, "%s::OnWhisperGlobal", npc->name);
  7692. npc_event(sd,output,0); // Calls the NPC label
  7693. aFree(command);
  7694. return;
  7695. }
  7696. }
  7697. // Main chat [LuzZza]
  7698. if(strcmpi(target, main_chat_nick) == 0) {
  7699. if(!sd->state.mainchat)
  7700. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7701. else {
  7702. snprintf(output, sizeof(output)/sizeof(char), msg_txt(386), sd->status.name, msg);
  7703. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7704. }
  7705. aFree(command);
  7706. return;
  7707. }
  7708. // searching destination character
  7709. dstsd = map_nick2sd(target);
  7710. // player is not on this map-server
  7711. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7712. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7713. // and if we ask for 'Test', we must not contact 'test' player
  7714. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7715. if (dstsd == NULL ||
  7716. strcmp(dstsd->status.name, target) != 0)
  7717. { // send message to inter-server
  7718. intif_wis_message(sd, target, msg, len);
  7719. aFree(command);
  7720. return;
  7721. }
  7722. // player is on this map-server
  7723. if (dstsd->fd == fd) {
  7724. // if you send to your self, don't send anything to others
  7725. // but, normally, it's impossible!
  7726. clif_wis_message(fd, wisp_server_name,
  7727. "You can not page yourself. Sorry.",
  7728. strlen("You can not page yourself. Sorry.") + 1);
  7729. aFree(command);
  7730. return;
  7731. }
  7732. // otherwise, send message and answer immediately
  7733. if (dstsd->state.ignoreAll) {
  7734. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7735. clif_wis_end(fd, 1); // 1: target character is not loged in
  7736. else
  7737. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7738. aFree(command);
  7739. return;
  7740. }
  7741. // if player ignore the source character
  7742. for(i = 0; i < MAX_IGNORE_LIST &&
  7743. dstsd->ignore[i].name[0] != '\0' &&
  7744. strcmp(dstsd->ignore[i].name, sd->status.name) != 0
  7745. ; i++);
  7746. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  7747. { //Ignored
  7748. clif_wis_end(fd, 2); // 2: ignored by target
  7749. aFree(command);
  7750. return;
  7751. }
  7752. // if source player not found in ignore list
  7753. if(dstsd->away_message[0] != '\0') { // Send away automessage [LuzZza]
  7754. //(Automessage has been sent)
  7755. sprintf(output, "%s %s", msg, msg_txt(543));
  7756. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  7757. clif_wis_end(fd, 0); // 0: success to send wisper
  7758. if(dstsd->state.autotrade)
  7759. //"Away [AT] - \"%s\""
  7760. sprintf(output, msg_txt(544), dstsd->away_message);
  7761. else
  7762. //"Away - \"%s\""
  7763. sprintf(output, msg_txt(545), dstsd->away_message);
  7764. aFree(command);
  7765. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  7766. return;
  7767. }
  7768. // Normal message
  7769. clif_wis_message(dstsd->fd, sd->status.name, msg, len);
  7770. clif_wis_end(fd, 0); // 0: success to send wisper
  7771. aFree(command);
  7772. return;
  7773. }
  7774. /*==========================================
  7775. * /b
  7776. *------------------------------------------*/
  7777. void clif_parse_GMmessage(int fd, struct map_session_data *sd)
  7778. {
  7779. char* mes;
  7780. int size, lv;
  7781. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7782. return;
  7783. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_Broadcast)))
  7784. return;
  7785. size = RFIFOW(fd,2)-4;
  7786. mes = (char*)RFIFOP(fd,4);
  7787. mes_len_check(mes, size, CHAT_SIZE);
  7788. intif_GMmessage(mes, size, 0);
  7789. if(log_config.gm && lv >= log_config.gm) {
  7790. char message[CHAT_SIZE+4];
  7791. sprintf(message, "/b %s", mes);
  7792. log_atcommand(sd, message);
  7793. }
  7794. }
  7795. /*==========================================
  7796. *
  7797. *------------------------------------------*/
  7798. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  7799. {
  7800. struct flooritem_data *fitem;
  7801. int map_object_id;
  7802. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7803. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  7804. do {
  7805. if (pc_isdead(sd)) {
  7806. clif_clearunit_area(&sd->bl, 1);
  7807. break;
  7808. }
  7809. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  7810. break;
  7811. if (clif_cant_act(sd))
  7812. break;
  7813. //Disable cloaking/chasewalking characters from looting [Skotlex]
  7814. if(pc_iscloaking(sd) || pc_ischasewalk(sd))
  7815. break;
  7816. if(sd->sc.count && (
  7817. sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  7818. sd->sc.data[SC_BLADESTOP].timer != -1 ||
  7819. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOITEM))
  7820. )
  7821. break;
  7822. if (!pc_takeitem(sd, fitem))
  7823. break;
  7824. return;
  7825. } while (0);
  7826. // Client REQUIRES a fail packet or you can no longer pick items.
  7827. clif_additem(sd,0,0,6);
  7828. }
  7829. /*==========================================
  7830. *
  7831. *------------------------------------------*/
  7832. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  7833. {
  7834. int item_index, item_amount;
  7835. if (pc_isdead(sd)) {
  7836. clif_clearunit_area(&sd->bl, 1);
  7837. return;
  7838. }
  7839. if (clif_cant_act(sd))
  7840. return;
  7841. if (sd->sc.count && (
  7842. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  7843. sd->sc.data[SC_BLADESTOP].timer != -1 ||
  7844. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOITEM)
  7845. ))
  7846. return;
  7847. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7848. item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7849. if (!pc_dropitem(sd, item_index, item_amount))
  7850. //Because the client does not likes being ignored.
  7851. clif_delitem(sd, item_index,0);
  7852. }
  7853. /*==========================================
  7854. *
  7855. *------------------------------------------*/
  7856. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  7857. {
  7858. int n;
  7859. if (pc_isdead(sd)) {
  7860. clif_clearunit_area(&sd->bl, 1);
  7861. return;
  7862. }
  7863. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  7864. return;
  7865. //This flag enables you to use items while in an NPC. [Skotlex]
  7866. if (sd->npc_id) {
  7867. if (sd->npc_id != sd->npc_item_flag)
  7868. return;
  7869. } else
  7870. if (clif_trading(sd))
  7871. return;
  7872. pc_delinvincibletimer(sd);
  7873. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  7874. sd->idletime = last_tick;
  7875. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7876. if(n <0 || n >= MAX_INVENTORY)
  7877. return;
  7878. if (!pc_useitem(sd,n))
  7879. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  7880. }
  7881. /*==========================================
  7882. *
  7883. *------------------------------------------*/
  7884. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  7885. {
  7886. int index;
  7887. if(pc_isdead(sd)) {
  7888. clif_clearunit_area(&sd->bl,1);
  7889. return;
  7890. }
  7891. index = RFIFOW(fd,2)-2;
  7892. if (index < 0 || index >= MAX_INVENTORY)
  7893. return; //Out of bounds check.
  7894. if(sd->npc_id) {
  7895. if (sd->npc_id != sd->npc_item_flag)
  7896. return;
  7897. } else if (sd->state.storage_flag || sd->sc.opt1)
  7898. ; //You can equip/unequip stuff while storage is open/under status changes
  7899. else if (clif_cant_act(sd))
  7900. return;
  7901. if(sd->sc.data[SC_BLADESTOP].timer!=-1 || sd->sc.data[SC_BERSERK].timer!=-1 )
  7902. return;
  7903. if(!sd->status.inventory[index].identify) {
  7904. clif_equipitemack(sd,index,0,0); // fail
  7905. return;
  7906. }
  7907. if(!sd->inventory_data[index])
  7908. return;
  7909. if(sd->inventory_data[index]->type == IT_PETARMOR){
  7910. pet_equipitem(sd,index);
  7911. return;
  7912. }
  7913. //Client doesn't send the position for ammo.
  7914. if(sd->inventory_data[index]->type == IT_AMMO)
  7915. pc_equipitem(sd,index,EQP_AMMO);
  7916. else
  7917. pc_equipitem(sd,index,RFIFOW(fd,4));
  7918. }
  7919. /*==========================================
  7920. *
  7921. *------------------------------------------*/
  7922. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  7923. {
  7924. int index;
  7925. if(pc_isdead(sd)) {
  7926. clif_clearunit_area(&sd->bl,1);
  7927. return;
  7928. }
  7929. if (sd->state.storage_flag)
  7930. ; //You can equip/unequip stuff while storage is open.
  7931. else if (clif_cant_act(sd))
  7932. return;
  7933. index = RFIFOW(fd,2)-2;
  7934. pc_unequipitem(sd,index,1);
  7935. }
  7936. /*==========================================
  7937. *
  7938. *------------------------------------------*/
  7939. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  7940. {
  7941. struct block_list *bl;
  7942. if(pc_isdead(sd)) {
  7943. clif_clearunit_area(&sd->bl,1);
  7944. return;
  7945. }
  7946. if (clif_cant_act(sd))
  7947. return;
  7948. bl = map_id2bl(RFIFOL(fd,2));
  7949. if (!bl) return;
  7950. switch (bl->type) {
  7951. case BL_MOB:
  7952. if (!((TBL_MOB *)bl)->nd || !mob_script_callback((TBL_MOB *)bl, &sd->bl, CALLBACK_NPCCLICK))
  7953. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7954. break;
  7955. case BL_PC:
  7956. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7957. break;
  7958. case BL_NPC:
  7959. npc_click(sd,(TBL_NPC*)bl);
  7960. break;
  7961. }
  7962. return;
  7963. }
  7964. /*==========================================
  7965. *
  7966. *------------------------------------------*/
  7967. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  7968. {
  7969. if (sd->state.trading)
  7970. return;
  7971. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  7972. }
  7973. /*==========================================
  7974. *
  7975. *------------------------------------------*/
  7976. void clif_parse_NpcBuyListSend(int fd,struct map_session_data *sd)
  7977. {
  7978. int fail=0,n;
  7979. unsigned short *item_list;
  7980. n = (RFIFOW(fd,2)-4) /4;
  7981. item_list = (unsigned short*)RFIFOP(fd,4);
  7982. if (sd->state.trading|| !sd->npc_shopid)
  7983. fail = 1;
  7984. else
  7985. fail = npc_buylist(sd,n,item_list);
  7986. sd->npc_shopid = 0; //Clear shop data.
  7987. WFIFOHEAD(fd,packet_len(0xca));
  7988. WFIFOW(fd,0)=0xca;
  7989. WFIFOB(fd,2)=fail;
  7990. WFIFOSET(fd,packet_len(0xca));
  7991. }
  7992. /*==========================================
  7993. *
  7994. *------------------------------------------*/
  7995. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  7996. {
  7997. int fail=0,n;
  7998. unsigned short *item_list;
  7999. n = (RFIFOW(fd,2)-4) /4;
  8000. item_list = (unsigned short*)RFIFOP(fd,4);
  8001. if (sd->state.trading || !sd->npc_shopid)
  8002. fail = 1;
  8003. else
  8004. fail = npc_selllist(sd,n,item_list);
  8005. sd->npc_shopid = 0; //Clear shop data.
  8006. WFIFOHEAD(fd,packet_len(0xcb));
  8007. WFIFOW(fd,0)=0xcb;
  8008. WFIFOB(fd,2)=fail;
  8009. WFIFOSET(fd,packet_len(0xcb));
  8010. }
  8011. /*==========================================
  8012. *
  8013. *------------------------------------------*/
  8014. void clif_parse_CreateChatRoom(int fd,struct map_session_data *sd)
  8015. {
  8016. if (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOROOM)
  8017. return;
  8018. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 4){
  8019. chat_createchat(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8020. } else
  8021. clif_skill_fail(sd,1,0,3);
  8022. }
  8023. /*==========================================
  8024. *
  8025. *------------------------------------------*/
  8026. void clif_parse_ChatAddMember(int fd,struct map_session_data *sd)
  8027. {
  8028. chat_joinchat(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8029. }
  8030. /*==========================================
  8031. *
  8032. *------------------------------------------*/
  8033. void clif_parse_ChatRoomStatusChange(int fd,struct map_session_data *sd)
  8034. {
  8035. chat_changechatstatus(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8036. }
  8037. /*==========================================
  8038. *
  8039. *------------------------------------------*/
  8040. void clif_parse_ChangeChatOwner(int fd,struct map_session_data *sd)
  8041. {
  8042. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8043. }
  8044. /*==========================================
  8045. *
  8046. *------------------------------------------*/
  8047. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8048. {
  8049. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8050. }
  8051. /*==========================================
  8052. *
  8053. *------------------------------------------*/
  8054. void clif_parse_ChatLeave(int fd,struct map_session_data *sd)
  8055. {
  8056. chat_leavechat(sd);
  8057. }
  8058. //Handles notifying asker and rejecter of what has just ocurred.
  8059. //Type is used to determine the correct msg_txt to use:
  8060. //0:
  8061. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  8062. {
  8063. char *msg, output[256];
  8064. // Your request has been rejected by autoreject option.
  8065. msg = msg_txt(392);
  8066. clif_disp_onlyself(src, msg, strlen(msg));
  8067. //Notice that a request was rejected.
  8068. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  8069. clif_disp_onlyself(target, output, strlen(output));
  8070. }
  8071. /*==========================================
  8072. * 取引要請を相手に送る
  8073. *------------------------------------------*/
  8074. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8075. {
  8076. struct map_session_data *t_sd;
  8077. t_sd = map_id2sd(RFIFOL(fd,2));
  8078. if(!sd->chatID && clif_cant_act(sd))
  8079. return; //You can trade while in a chatroom.
  8080. // @noask [LuzZza]
  8081. if(t_sd && t_sd->state.noask) {
  8082. clif_noask_sub(sd, t_sd, 0);
  8083. return;
  8084. }
  8085. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 1){
  8086. trade_traderequest(sd,t_sd);
  8087. } else
  8088. clif_skill_fail(sd,1,0,0);
  8089. }
  8090. /*==========================================
  8091. * 取引要請
  8092. *------------------------------------------*/
  8093. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8094. {
  8095. trade_tradeack(sd,RFIFOB(fd,2));
  8096. }
  8097. /*==========================================
  8098. * アイテム追加
  8099. *------------------------------------------*/
  8100. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8101. {
  8102. trade_tradeadditem(sd,RFIFOW(fd,2),RFIFOL(fd,4));
  8103. }
  8104. /*==========================================
  8105. * アイテム追加完了(ok押し)
  8106. *------------------------------------------*/
  8107. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8108. {
  8109. trade_tradeok(sd);
  8110. }
  8111. /*==========================================
  8112. * 取引キャンセル
  8113. *------------------------------------------*/
  8114. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8115. {
  8116. trade_tradecancel(sd);
  8117. }
  8118. /*==========================================
  8119. * 取引許諾(trade押し)
  8120. *------------------------------------------*/
  8121. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8122. {
  8123. trade_tradecommit(sd);
  8124. }
  8125. /*==========================================
  8126. *
  8127. *------------------------------------------*/
  8128. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8129. {
  8130. pc_stop_attack(sd);
  8131. }
  8132. /*==========================================
  8133. * カートへアイテムを移す
  8134. *------------------------------------------*/
  8135. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8136. {
  8137. if (clif_trading(sd))
  8138. return;
  8139. if (!pc_iscarton(sd))
  8140. return;
  8141. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8142. }
  8143. /*==========================================
  8144. * カートからアイテムを出す
  8145. *------------------------------------------*/
  8146. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8147. {
  8148. if (!pc_iscarton(sd))
  8149. return;
  8150. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8151. }
  8152. /*==========================================
  8153. * 付属品(鷹,ペコ,カート)をはずす
  8154. *------------------------------------------*/
  8155. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8156. {
  8157. //Can only remove Cart/Riding/Falcon.
  8158. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  8159. }
  8160. /*==========================================
  8161. * チェンジカート
  8162. *------------------------------------------*/
  8163. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8164. {
  8165. int type;
  8166. type = (int)RFIFOW(fd,2);
  8167. if( (type == 5 && sd->status.base_level <= 90) ||
  8168. (type == 4 && sd->status.base_level <= 80) ||
  8169. (type == 3 && sd->status.base_level <= 65) ||
  8170. (type == 2 && sd->status.base_level <= 40) ||
  8171. pc_setcart(sd,type) )
  8172. {
  8173. LOG_SUSPICIOUS(sd,"clif_parse_ChangeCart");
  8174. }
  8175. }
  8176. /*==========================================
  8177. * ステータスアップ
  8178. *------------------------------------------*/
  8179. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8180. {
  8181. pc_statusup(sd,RFIFOW(fd,2));
  8182. }
  8183. /*==========================================
  8184. * スキルレベルアップ
  8185. *------------------------------------------*/
  8186. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8187. {
  8188. pc_skillup(sd,RFIFOW(fd,2));
  8189. }
  8190. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, int skillnum, int skilllv, int target_id)
  8191. {
  8192. int lv;
  8193. if (!hd)
  8194. return;
  8195. if (skillnotok_hom(skillnum, hd)) //[orn]
  8196. return;
  8197. if (hd->bl.id != target_id &&
  8198. skill_get_inf(skillnum)&INF_SELF_SKILL)
  8199. target_id = hd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8200. if (hd->ud.skilltimer != -1) {
  8201. if (skillnum != SA_CASTCANCEL)
  8202. return;
  8203. } else if (DIFF_TICK(tick, hd->ud.canact_tick) < 0)
  8204. return;
  8205. lv = merc_hom_checkskill(hd, skillnum);
  8206. if (skilllv > lv)
  8207. skilllv = lv;
  8208. if (skilllv)
  8209. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  8210. }
  8211. /*==========================================
  8212. * スキル使用(ID指定)
  8213. *------------------------------------------*/
  8214. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  8215. {
  8216. int skillnum, skilllv, tmp, target_id;
  8217. unsigned int tick = gettick();
  8218. if (clif_cant_act(sd))
  8219. return;
  8220. if (pc_issit(sd))
  8221. return;
  8222. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8223. if (skilllv < 1) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8224. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8225. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8226. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8227. sd->idletime = last_tick;
  8228. tmp = skill_get_inf(skillnum);
  8229. if (tmp&INF_GROUND_SKILL || !tmp)
  8230. return; //Using a ground/passive skill on a target? WRONG.
  8231. if (skillnum >= HM_SKILLBASE && skillnum <= HM_SKILLBASE+MAX_HOMUNSKILL) {
  8232. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  8233. return;
  8234. }
  8235. if (skillnotok(skillnum, sd))
  8236. return;
  8237. if (sd->bl.id != target_id && !sd->state.skill_flag && tmp&INF_SELF_SKILL)
  8238. target_id = sd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8239. if (sd->ud.skilltimer != -1) {
  8240. if (skillnum != SA_CASTCANCEL)
  8241. return;
  8242. } else if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8243. clif_skill_fail(sd, skillnum, 4, 0);
  8244. return;
  8245. }
  8246. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8247. return;
  8248. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8249. target_id = sd->bl.id;
  8250. if(sd->menuskill_id)
  8251. {
  8252. if (sd->menuskill_id == SA_TAMINGMONSTER)
  8253. sd->menuskill_id = sd->menuskill_lv = 0; //Cancel pet capture.
  8254. else
  8255. if (sd->menuskill_id != SA_AUTOSPELL)
  8256. return; //Can't use skills while a menu is open.
  8257. }
  8258. if (sd->skillitem == skillnum) {
  8259. if (skilllv != sd->skillitemlv)
  8260. skilllv = sd->skillitemlv;
  8261. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8262. return;
  8263. }
  8264. sd->skillitem = sd->skillitemlv = 0;
  8265. if (skillnum == MO_EXTREMITYFIST) {
  8266. if ((sd->sc.data[SC_COMBO].timer == -1 ||
  8267. (sd->sc.data[SC_COMBO].val1 != MO_COMBOFINISH &&
  8268. sd->sc.data[SC_COMBO].val1 != CH_TIGERFIST &&
  8269. sd->sc.data[SC_COMBO].val1 != CH_CHAINCRUSH))) {
  8270. if (!sd->state.skill_flag ) {
  8271. sd->state.skill_flag = 1;
  8272. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8273. return;
  8274. } else if (sd->bl.id == target_id) {
  8275. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8276. return;
  8277. }
  8278. }
  8279. }
  8280. if (skillnum == TK_JUMPKICK) {
  8281. if (sd->sc.data[SC_COMBO].timer == -1 ||
  8282. sd->sc.data[SC_COMBO].val1 != TK_JUMPKICK) {
  8283. if (!sd->state.skill_flag ) {
  8284. sd->state.skill_flag = 1;
  8285. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8286. return;
  8287. } else if (sd->bl.id == target_id) {
  8288. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8289. return;
  8290. }
  8291. }
  8292. }
  8293. if (skillnum >= GD_SKILLBASE) {
  8294. if (sd->state.gmaster_flag)
  8295. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8296. else
  8297. skilllv = 0;
  8298. } else {
  8299. tmp = pc_checkskill(sd, skillnum);
  8300. if (skilllv > tmp)
  8301. skilllv = tmp;
  8302. }
  8303. pc_delinvincibletimer(sd);
  8304. if (skilllv)
  8305. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8306. if (sd->state.skill_flag)
  8307. sd->state.skill_flag = 0;
  8308. }
  8309. /*==========================================
  8310. * スキル使用(場所指定)
  8311. *------------------------------------------*/
  8312. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, int skilllv, int skillnum, int x, int y, int skillmoreinfo)
  8313. {
  8314. int lv;
  8315. unsigned int tick = gettick();
  8316. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8317. sd->idletime = last_tick;
  8318. if (skillnotok(skillnum, sd))
  8319. return;
  8320. if (!(skill_get_inf(skillnum)&INF_GROUND_SKILL))
  8321. return; //Using a target skill on the ground? WRONG.
  8322. if (skillmoreinfo != -1) {
  8323. if (pc_issit(sd)) {
  8324. clif_skill_fail(sd, skillnum, 0, 0);
  8325. return;
  8326. }
  8327. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  8328. memcpy(sd->message, RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8329. sd->message[MESSAGE_SIZE-1] = '\0'; //Overflow protection [Skotlex]
  8330. }
  8331. if (sd->ud.skilltimer != -1)
  8332. return;
  8333. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0)
  8334. {
  8335. clif_skill_fail(sd, skillnum, 4, 0);
  8336. return;
  8337. }
  8338. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8339. return;
  8340. if(sd->menuskill_id)
  8341. {
  8342. if (sd->menuskill_id == SA_TAMINGMONSTER)
  8343. sd->menuskill_id = sd->menuskill_lv = 0; //Cancel pet capture.
  8344. else
  8345. if (sd->menuskill_id != SA_AUTOSPELL)
  8346. return; //Can't use skills while a menu is open.
  8347. }
  8348. pc_delinvincibletimer(sd);
  8349. if (sd->skillitem == skillnum) {
  8350. if (skilllv != sd->skillitemlv)
  8351. skilllv = sd->skillitemlv;
  8352. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8353. } else {
  8354. sd->skillitem = sd->skillitemlv = 0;
  8355. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8356. if (skilllv > lv)
  8357. skilllv = lv;
  8358. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8359. }
  8360. }
  8361. }
  8362. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  8363. {
  8364. if (clif_cant_act(sd))
  8365. return;
  8366. if (pc_issit(sd))
  8367. return;
  8368. clif_parse_UseSkillToPosSub(fd, sd,
  8369. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8370. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8371. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8372. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8373. -1 //Skill more info.
  8374. );
  8375. }
  8376. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  8377. {
  8378. if (clif_cant_act(sd))
  8379. return;
  8380. if (pc_issit(sd))
  8381. return;
  8382. clif_parse_UseSkillToPosSub(fd, sd,
  8383. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8384. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8385. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8386. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8387. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8388. );
  8389. }
  8390. /*==========================================
  8391. * スキル使用(map指定)
  8392. *------------------------------------------*/
  8393. void clif_parse_UseSkillMap(int fd,struct map_session_data *sd)
  8394. {
  8395. int skill_num;
  8396. skill_num = RFIFOW(fd,2);
  8397. if(skill_num != sd->menuskill_id)
  8398. return;
  8399. if (clif_cant_act(sd))
  8400. {
  8401. sd->menuskill_id = sd->menuskill_lv = 0;
  8402. return;
  8403. }
  8404. pc_delinvincibletimer(sd);
  8405. skill_castend_map(sd,skill_num,(char*)RFIFOP(fd,4));
  8406. }
  8407. /*==========================================
  8408. * メモ要求
  8409. *------------------------------------------*/
  8410. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8411. {
  8412. if (!pc_isdead(sd))
  8413. pc_memo(sd,-1);
  8414. }
  8415. /*==========================================
  8416. * アイテム合成
  8417. *------------------------------------------*/
  8418. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8419. {
  8420. if (sd->menuskill_id != AM_PHARMACY)
  8421. return;
  8422. if (clif_trading(sd)) {
  8423. //Make it fail to avoid shop exploits where you sell something different than you see.
  8424. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8425. sd->menuskill_lv = sd->menuskill_id = 0;
  8426. return;
  8427. }
  8428. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8429. sd->menuskill_lv = sd->menuskill_id = 0;
  8430. }
  8431. /*==========================================
  8432. * 武器修理
  8433. *------------------------------------------*/
  8434. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8435. {
  8436. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8437. return;
  8438. if (clif_trading(sd)) {
  8439. //Make it fail to avoid shop exploits where you sell something different than you see.
  8440. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8441. sd->menuskill_lv = sd->menuskill_id = 0;
  8442. return;
  8443. }
  8444. skill_repairweapon(sd,RFIFOW(fd,2));
  8445. sd->menuskill_lv = sd->menuskill_id = 0;
  8446. }
  8447. /*==========================================
  8448. *
  8449. *------------------------------------------*/
  8450. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  8451. {
  8452. int idx;
  8453. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8454. return;
  8455. if (clif_trading(sd)) {
  8456. //Make it fail to avoid shop exploits where you sell something different than you see.
  8457. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8458. sd->menuskill_lv = sd->menuskill_id = 0;
  8459. return;
  8460. }
  8461. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8462. skill_weaponrefine(sd, idx-2);
  8463. sd->menuskill_lv = sd->menuskill_id = 0;
  8464. }
  8465. /*==========================================
  8466. *
  8467. *------------------------------------------*/
  8468. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8469. {
  8470. uint8 select;
  8471. select = RFIFOB(fd,6);
  8472. if((select > sd->npc_menu && select != 0xff) || !select){
  8473. ShowWarning("Hack on NPC Select Menu: %s (AID: %d)!\n",sd->status.name,sd->bl.id);
  8474. clif_GM_kick(sd,sd,0);
  8475. } else {
  8476. sd->npc_menu=select;
  8477. npc_scriptcont(sd,RFIFOL(fd,2));
  8478. }
  8479. }
  8480. /*==========================================
  8481. *
  8482. *------------------------------------------*/
  8483. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8484. {
  8485. npc_scriptcont(sd,RFIFOL(fd,2));
  8486. }
  8487. /*==========================================
  8488. *
  8489. *------------------------------------------*/
  8490. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8491. {
  8492. sd->npc_amount=(int)RFIFOL(fd,6);
  8493. npc_scriptcont(sd,RFIFOL(fd,2));
  8494. }
  8495. /*==========================================
  8496. *
  8497. *------------------------------------------*/
  8498. void clif_parse_NpcStringInput(int fd,struct map_session_data *sd)
  8499. {
  8500. short message_len;
  8501. message_len = RFIFOW(fd,2)-7;
  8502. if(message_len < 1)
  8503. return; //Blank message?
  8504. if(message_len >= sizeof(sd->npc_str)){
  8505. ShowWarning("clif: input string too long !\n");
  8506. message_len = sizeof(sd->npc_str);
  8507. }
  8508. // Exploit prevention if crafted packets (without null) is being sent. [Lance]
  8509. memcpy(sd->npc_str,RFIFOP(fd,8),message_len);
  8510. sd->npc_str[message_len-1]=0;
  8511. npc_scriptcont(sd,RFIFOL(fd,4));
  8512. }
  8513. /*==========================================
  8514. *
  8515. *------------------------------------------*/
  8516. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8517. {
  8518. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8519. return;
  8520. npc_scriptcont(sd,RFIFOL(fd,2));
  8521. }
  8522. /*==========================================
  8523. * アイテム鑑定
  8524. *------------------------------------------*/
  8525. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8526. {
  8527. if (sd->menuskill_id != MC_IDENTIFY)
  8528. return;
  8529. skill_identify(sd,RFIFOW(fd,2)-2);
  8530. sd->menuskill_lv = sd->menuskill_id = 0;
  8531. }
  8532. /*==========================================
  8533. * 矢作成
  8534. *------------------------------------------*/
  8535. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8536. {
  8537. if (sd->menuskill_id != AC_MAKINGARROW)
  8538. return;
  8539. if (clif_trading(sd)) {
  8540. //Make it fail to avoid shop exploits where you sell something different than you see.
  8541. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8542. sd->menuskill_lv = sd->menuskill_id = 0;
  8543. return;
  8544. }
  8545. skill_arrow_create(sd,RFIFOW(fd,2));
  8546. sd->menuskill_lv = sd->menuskill_id = 0;
  8547. }
  8548. /*==========================================
  8549. * オートスペル受信
  8550. *------------------------------------------*/
  8551. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8552. {
  8553. if (sd->menuskill_id != SA_AUTOSPELL)
  8554. return;
  8555. skill_autospell(sd,RFIFOW(fd,2));
  8556. sd->menuskill_lv = sd->menuskill_id = 0;
  8557. }
  8558. /*==========================================
  8559. * カード使用
  8560. *------------------------------------------*/
  8561. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8562. {
  8563. if (sd->state.trading != 0)
  8564. return;
  8565. clif_use_card(sd,RFIFOW(fd,2)-2);
  8566. }
  8567. /*==========================================
  8568. * カード挿入装備選択
  8569. *------------------------------------------*/
  8570. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8571. {
  8572. if (sd->state.trading != 0)
  8573. return;
  8574. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8575. }
  8576. /*==========================================
  8577. * 0193 キャラID名前引き
  8578. *------------------------------------------*/
  8579. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  8580. {
  8581. int char_id;
  8582. char_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8583. clif_solved_charname(sd, char_id);
  8584. }
  8585. /*==========================================
  8586. * 0197 /resetskill /resetstate
  8587. *------------------------------------------*/
  8588. void clif_parse_ResetChar(int fd, struct map_session_data *sd)
  8589. {
  8590. if (battle_config.atc_gmonly && !pc_isGM(sd))
  8591. return;
  8592. if (pc_isGM(sd) < get_atcommand_level(AtCommand_ResetState))
  8593. return;
  8594. if (RFIFOW(fd,2))
  8595. pc_resetskill(sd,1);
  8596. else
  8597. pc_resetstate(sd);
  8598. if(log_config.gm && get_atcommand_level(AtCommand_ResetState >= log_config.gm))
  8599. log_atcommand(sd, RFIFOW(fd,2) ? "/resetskill" : "/resetstate");
  8600. }
  8601. /*==========================================
  8602. * 019c /lb等
  8603. *------------------------------------------*/
  8604. void clif_parse_LGMmessage(int fd, struct map_session_data *sd)
  8605. {
  8606. unsigned char buf[CHAT_SIZE+4];
  8607. char *mes;
  8608. int len, lv;
  8609. if (battle_config.atc_gmonly && !pc_isGM(sd))
  8610. return;
  8611. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_LocalBroadcast)))
  8612. return;
  8613. len = RFIFOW(fd,2) - 4;
  8614. mes = (char*)RFIFOP(fd,4);
  8615. mes_len_check(mes, len, CHAT_SIZE);
  8616. WBUFW(buf,0) = 0x9a;
  8617. WBUFW(buf,2) = len+4;
  8618. memcpy(WBUFP(buf,4), mes, len);
  8619. clif_send(buf, WBUFW(buf,2), &sd->bl, ALL_SAMEMAP);
  8620. if(log_config.gm && lv >= log_config.gm) {
  8621. char message[CHAT_SIZE+5];
  8622. sprintf(message, "/lb %s", mes);
  8623. log_atcommand(sd, message);
  8624. }
  8625. }
  8626. /*==========================================
  8627. * カプラ倉庫へ入れる
  8628. *------------------------------------------*/
  8629. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  8630. {
  8631. int item_index, item_amount;
  8632. if (clif_trading(sd))
  8633. return;
  8634. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8635. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8636. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  8637. return;
  8638. if (sd->state.storage_flag == 1)
  8639. storage_storageadd(sd, item_index, item_amount);
  8640. else if (sd->state.storage_flag == 2)
  8641. storage_guild_storageadd(sd, item_index, item_amount);
  8642. }
  8643. /*==========================================
  8644. * カプラ倉庫から出す
  8645. *------------------------------------------*/
  8646. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  8647. {
  8648. int item_index, item_amount;
  8649. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8650. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8651. if (sd->state.storage_flag == 1)
  8652. storage_storageget(sd, item_index, item_amount);
  8653. else if(sd->state.storage_flag == 2)
  8654. storage_guild_storageget(sd, item_index, item_amount);
  8655. }
  8656. /*==========================================
  8657. * カプラ倉庫へカートから入れる
  8658. *------------------------------------------*/
  8659. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  8660. {
  8661. if(sd->vender_id)
  8662. return;
  8663. if (!pc_iscarton(sd))
  8664. return;
  8665. if (sd->state.storage_flag == 1)
  8666. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8667. else if (sd->state.storage_flag == 2)
  8668. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8669. }
  8670. /*==========================================
  8671. * カプラ倉庫から出す
  8672. *------------------------------------------*/
  8673. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  8674. {
  8675. if (sd->vender_id)
  8676. return;
  8677. if (!pc_iscarton(sd))
  8678. return;
  8679. if (sd->state.storage_flag == 1)
  8680. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8681. else if (sd->state.storage_flag == 2)
  8682. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8683. }
  8684. /*==========================================
  8685. * カプラ倉庫を閉じる
  8686. *------------------------------------------*/
  8687. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  8688. {
  8689. if (sd->state.storage_flag == 1)
  8690. storage_storageclose(sd);
  8691. else if (sd->state.storage_flag == 2)
  8692. storage_guild_storageclose(sd);
  8693. }
  8694. /*==========================================
  8695. * Kafra storage protection password system
  8696. *------------------------------------------*/
  8697. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  8698. {
  8699. //TODO
  8700. }
  8701. /*==========================================
  8702. * パーティを作る
  8703. *------------------------------------------*/
  8704. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  8705. {
  8706. if(map[sd->bl.m].flag.partylock)
  8707. { //Guild locked.
  8708. clif_displaymessage(fd, msg_txt(227));
  8709. return;
  8710. }
  8711. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7) {
  8712. party_create(sd,(char*)RFIFOP(fd,2),0,0);
  8713. } else
  8714. clif_skill_fail(sd,1,0,4);
  8715. }
  8716. /*==========================================
  8717. * パーティを作る
  8718. *------------------------------------------*/
  8719. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  8720. {
  8721. if(map[sd->bl.m].flag.partylock)
  8722. { //Guild locked.
  8723. clif_displaymessage(fd, msg_txt(227));
  8724. return;
  8725. }
  8726. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7)
  8727. party_create(sd,(char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27));
  8728. else
  8729. clif_skill_fail(sd,1,0,4);
  8730. }
  8731. /*==========================================
  8732. * パーティに勧誘
  8733. *------------------------------------------*/
  8734. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  8735. {
  8736. struct map_session_data *t_sd;
  8737. if(map[sd->bl.m].flag.partylock)
  8738. { //Guild locked.
  8739. clif_displaymessage(fd, msg_txt(227));
  8740. return;
  8741. }
  8742. t_sd = map_id2sd(RFIFOL(fd,2));
  8743. // @noask [LuzZza]
  8744. if(t_sd && t_sd->state.noask) {
  8745. clif_noask_sub(sd, t_sd, 1);
  8746. return;
  8747. }
  8748. party_invite(sd, t_sd);
  8749. }
  8750. /*==========================================
  8751. * パーティ勧誘返答
  8752. *------------------------------------------*/
  8753. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  8754. {
  8755. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  8756. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8757. } else {
  8758. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8759. clif_skill_fail(sd,1,0,4);
  8760. }
  8761. }
  8762. /*==========================================
  8763. * パーティ脱退要求
  8764. *------------------------------------------*/
  8765. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  8766. {
  8767. if(map[sd->bl.m].flag.partylock)
  8768. { //Guild locked.
  8769. clif_displaymessage(fd, msg_txt(227));
  8770. return;
  8771. }
  8772. party_leave(sd);
  8773. }
  8774. /*==========================================
  8775. * パーティ除名要求
  8776. *------------------------------------------*/
  8777. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  8778. {
  8779. if(map[sd->bl.m].flag.partylock)
  8780. { //Guild locked.
  8781. clif_displaymessage(fd, msg_txt(227));
  8782. return;
  8783. }
  8784. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8785. }
  8786. /*==========================================
  8787. * パーティ設定変更要求
  8788. *------------------------------------------*/
  8789. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  8790. {
  8791. struct party_data *p;
  8792. if(!sd->status.party_id)
  8793. return;
  8794. p = party_search(sd->status.party_id);
  8795. if (!p) return;
  8796. //The client no longer can change the item-field, therefore it always
  8797. //comes as zero. Here, resend the item data as it is.
  8798. // party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  8799. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  8800. }
  8801. /*==========================================
  8802. * パーティメッセージ送信要求
  8803. *------------------------------------------*/
  8804. void clif_parse_PartyMessage(int fd, struct map_session_data *sd)
  8805. {
  8806. char *mes;
  8807. int len;
  8808. len = RFIFOW(fd,2) - 4;
  8809. mes = (char*)RFIFOP(fd,4);
  8810. mes_len_check(mes, len, CHAT_SIZE);
  8811. if (is_charcommand(fd, sd, mes) != CharCommand_None ||
  8812. is_atcommand(fd, sd, mes) != AtCommand_None)
  8813. return;
  8814. if (sd->sc.count && (
  8815. sd->sc.data[SC_BERSERK].timer!=-1 ||
  8816. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)
  8817. ))
  8818. return;
  8819. if (battle_config.min_chat_delay)
  8820. { //[Skotlex]
  8821. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8822. return;
  8823. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8824. }
  8825. party_send_message(sd, mes, len);
  8826. }
  8827. /*==========================================
  8828. * 露店閉鎖
  8829. *------------------------------------------*/
  8830. void clif_parse_CloseVending(int fd, struct map_session_data *sd)
  8831. {
  8832. vending_closevending(sd);
  8833. }
  8834. /*==========================================
  8835. * 露店アイテムリスト要求
  8836. *------------------------------------------*/
  8837. void clif_parse_VendingListReq(int fd, struct map_session_data *sd)
  8838. {
  8839. vending_vendinglistreq(sd,RFIFOL(fd,2));
  8840. if(sd->npc_id)
  8841. npc_event_dequeue(sd);
  8842. }
  8843. /*==========================================
  8844. * 露店アイテム購入
  8845. *------------------------------------------*/
  8846. void clif_parse_PurchaseReq(int fd, struct map_session_data *sd)
  8847. {
  8848. vending_purchasereq(sd, RFIFOW(fd,2), RFIFOL(fd,4), RFIFOP(fd,8));
  8849. }
  8850. /*==========================================
  8851. * 露店開設
  8852. *------------------------------------------*/
  8853. void clif_parse_OpenVending(int fd,struct map_session_data *sd)
  8854. {
  8855. if (clif_trading(sd))
  8856. return;
  8857. if (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOROOM)
  8858. return;
  8859. vending_openvending(sd, RFIFOW(fd,2), (char*)RFIFOP(fd,4), RFIFOB(fd,84), RFIFOP(fd,85));
  8860. }
  8861. /*==========================================
  8862. * ギルドを作る
  8863. *------------------------------------------*/
  8864. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  8865. {
  8866. if(map[sd->bl.m].flag.guildlock)
  8867. { //Guild locked.
  8868. clif_displaymessage(fd, msg_txt(228));
  8869. return;
  8870. }
  8871. guild_create(sd, (char*)RFIFOP(fd,6));
  8872. }
  8873. /*==========================================
  8874. * ギルドマスターかどうか確認
  8875. *------------------------------------------*/
  8876. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  8877. {
  8878. clif_guild_masterormember(sd);
  8879. }
  8880. /*==========================================
  8881. * ギルド情報要求
  8882. *------------------------------------------*/
  8883. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  8884. {
  8885. if (!sd->status.guild_id)
  8886. return;
  8887. switch(RFIFOL(fd,2)){
  8888. case 0: // ギルド基本情報、同盟敵対情報
  8889. clif_guild_basicinfo(sd);
  8890. clif_guild_allianceinfo(sd);
  8891. break;
  8892. case 1: // メンバーリスト、役職名リスト
  8893. clif_guild_positionnamelist(sd);
  8894. clif_guild_memberlist(sd);
  8895. break;
  8896. case 2: // 役職名リスト、役職情報リスト
  8897. clif_guild_positionnamelist(sd);
  8898. clif_guild_positioninfolist(sd);
  8899. break;
  8900. case 3: // スキルリスト
  8901. clif_guild_skillinfo(sd);
  8902. break;
  8903. case 4: // 追放リスト
  8904. clif_guild_expulsionlist(sd);
  8905. break;
  8906. default:
  8907. if (battle_config.error_log)
  8908. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  8909. break;
  8910. }
  8911. }
  8912. /*==========================================
  8913. * ギルド役職変更
  8914. *------------------------------------------*/
  8915. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  8916. {
  8917. int i;
  8918. if(!sd->state.gmaster_flag)
  8919. return;
  8920. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  8921. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  8922. }
  8923. }
  8924. /*==========================================
  8925. * ギルドメンバ役職変更
  8926. *------------------------------------------*/
  8927. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  8928. {
  8929. int i;
  8930. if(!sd->state.gmaster_flag)
  8931. return;
  8932. for(i=4;i<RFIFOW(fd,2);i+=12){
  8933. guild_change_memberposition(sd->status.guild_id,
  8934. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  8935. }
  8936. }
  8937. /*==========================================
  8938. * ギルドエンブレム要求
  8939. *------------------------------------------*/
  8940. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  8941. {
  8942. struct guild* g = guild_search(RFIFOL(fd,2));
  8943. if(g!=NULL)
  8944. clif_guild_emblem(sd,g);
  8945. }
  8946. /*==========================================
  8947. * ギルドエンブレム変更
  8948. *------------------------------------------*/
  8949. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  8950. {
  8951. if(!sd->state.gmaster_flag)
  8952. return;
  8953. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  8954. }
  8955. /*==========================================
  8956. * ギルド告知変更
  8957. *------------------------------------------*/
  8958. void clif_parse_GuildChangeNotice(int fd,struct map_session_data *sd)
  8959. {
  8960. if(!sd->state.gmaster_flag)
  8961. return;
  8962. // compensate for the client's double marker bug (in both strings)
  8963. if ((RFIFOB(fd, 6) == '|') && (RFIFOB(fd, 6+3) == '|')) {
  8964. memmove(RFIFOP(fd, 6+3), RFIFOP(fd, 6+6), 60-6); memset(RFIFOP(fd, 60-3), 0x00, 3); // drop the duplicate marker
  8965. }
  8966. if ((RFIFOB(fd, 66) == '|') && (RFIFOB(fd, 66+3) == '|')) {
  8967. memmove(RFIFOP(fd, 66+3), RFIFOP(fd, 66+6), 180-6); memset(RFIFOP(fd, 180-3), 0x00, 3); // drop the duplicate marker
  8968. }
  8969. // compensate for the client's adding of an extra space at the end of the message
  8970. if (RFIFOB(fd, 66) == '|') {
  8971. memset(RFIFOP(fd, 66 + strnlen((char*)RFIFOP(fd, 66), 120)-1), 0x00, 1); // delete extra space at the end
  8972. }
  8973. guild_change_notice(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6),(char*)RFIFOP(fd,66));
  8974. }
  8975. /*==========================================
  8976. * ギルド勧誘
  8977. *------------------------------------------*/
  8978. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  8979. {
  8980. struct map_session_data *t_sd;
  8981. if(map[sd->bl.m].flag.guildlock)
  8982. { //Guild locked.
  8983. clif_displaymessage(fd, msg_txt(228));
  8984. return;
  8985. }
  8986. t_sd = map_id2sd(RFIFOL(fd,2));
  8987. // @noask [LuzZza]
  8988. if(t_sd && t_sd->state.noask) {
  8989. clif_noask_sub(sd, t_sd, 2);
  8990. return;
  8991. }
  8992. guild_invite(sd,t_sd);
  8993. }
  8994. /*==========================================
  8995. * ギルド勧誘返信
  8996. *------------------------------------------*/
  8997. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  8998. {
  8999. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9000. }
  9001. /*==========================================
  9002. * ギルド脱退
  9003. *------------------------------------------*/
  9004. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  9005. {
  9006. if(map[sd->bl.m].flag.guildlock)
  9007. { //Guild locked.
  9008. clif_displaymessage(fd, msg_txt(228));
  9009. return;
  9010. }
  9011. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9012. }
  9013. /*==========================================
  9014. * ギルド追放
  9015. *------------------------------------------*/
  9016. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  9017. {
  9018. if(map[sd->bl.m].flag.guildlock)
  9019. { //Guild locked.
  9020. clif_displaymessage(fd, msg_txt(228));
  9021. return;
  9022. }
  9023. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9024. }
  9025. /*==========================================
  9026. * ギルド会話
  9027. *------------------------------------------*/
  9028. void clif_parse_GuildMessage(int fd,struct map_session_data *sd)
  9029. {
  9030. char *mes;
  9031. int len;
  9032. len = RFIFOW(fd,2) - 4;
  9033. mes = (char*)RFIFOP(fd,4);
  9034. mes_len_check(mes, len, CHAT_SIZE);
  9035. if (is_charcommand(fd, sd, mes) != CharCommand_None ||
  9036. is_atcommand(fd, sd, mes) != AtCommand_None)
  9037. return;
  9038. if (sd->sc.count && (
  9039. sd->sc.data[SC_BERSERK].timer!=-1 ||
  9040. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)
  9041. ))
  9042. return;
  9043. if (battle_config.min_chat_delay)
  9044. { //[Skotlex]
  9045. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9046. return;
  9047. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9048. }
  9049. guild_send_message(sd, mes, len);
  9050. }
  9051. /*==========================================
  9052. * ギルド同盟要求
  9053. *------------------------------------------*/
  9054. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  9055. {
  9056. struct map_session_data *t_sd;
  9057. if(!sd->state.gmaster_flag)
  9058. return;
  9059. if(map[sd->bl.m].flag.guildlock)
  9060. { //Guild locked.
  9061. clif_displaymessage(fd, msg_txt(228));
  9062. return;
  9063. }
  9064. t_sd = map_id2sd(RFIFOL(fd,2));
  9065. // @noask [LuzZza]
  9066. if(t_sd && t_sd->state.noask) {
  9067. clif_noask_sub(sd, t_sd, 3);
  9068. return;
  9069. }
  9070. guild_reqalliance(sd,t_sd);
  9071. }
  9072. /*==========================================
  9073. * ギルド同盟要求返信
  9074. *------------------------------------------*/
  9075. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  9076. {
  9077. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9078. }
  9079. /*==========================================
  9080. * ギルド関係解消
  9081. *------------------------------------------*/
  9082. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  9083. {
  9084. if(!sd->state.gmaster_flag)
  9085. return;
  9086. if(map[sd->bl.m].flag.guildlock)
  9087. { //Guild locked.
  9088. clif_displaymessage(fd, msg_txt(228));
  9089. return;
  9090. }
  9091. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9092. }
  9093. /*==========================================
  9094. * ギルド敵対
  9095. *------------------------------------------*/
  9096. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  9097. {
  9098. struct map_session_data *t_sd;
  9099. if(!sd->state.gmaster_flag)
  9100. return;
  9101. if(map[sd->bl.m].flag.guildlock)
  9102. { //Guild locked.
  9103. clif_displaymessage(fd, msg_txt(228));
  9104. return;
  9105. }
  9106. t_sd = map_id2sd(RFIFOL(fd,2));
  9107. // @noask [LuzZza]
  9108. if(t_sd && t_sd->state.noask) {
  9109. clif_noask_sub(sd, t_sd, 4);
  9110. return;
  9111. }
  9112. guild_opposition(sd,t_sd);
  9113. }
  9114. /*==========================================
  9115. * ギルド解散
  9116. *------------------------------------------*/
  9117. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  9118. {
  9119. if(map[sd->bl.m].flag.guildlock)
  9120. { //Guild locked.
  9121. clif_displaymessage(fd, msg_txt(228));
  9122. return;
  9123. }
  9124. guild_break(sd,(char*)RFIFOP(fd,2));
  9125. }
  9126. // pet
  9127. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  9128. {
  9129. pet_menu(sd,RFIFOB(fd,2));
  9130. }
  9131. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  9132. {
  9133. pet_catch_process2(sd,RFIFOL(fd,2));
  9134. }
  9135. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  9136. {
  9137. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_lv != -1)
  9138. return;
  9139. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9140. sd->menuskill_lv = sd->menuskill_id = 0;
  9141. }
  9142. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  9143. {
  9144. if(sd->pd)
  9145. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9146. }
  9147. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  9148. {
  9149. pet_change_name(sd,(char*)RFIFOP(fd,2));
  9150. }
  9151. // Kick (right click menu for GM "(name) force to quit")
  9152. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  9153. {
  9154. struct block_list *target;
  9155. int tid,lv;
  9156. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9157. return;
  9158. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_Kick)))
  9159. return;
  9160. tid = RFIFOL(fd,2);
  9161. target = map_id2bl(tid);
  9162. if (!target) {
  9163. clif_GM_kickack(sd, 0);
  9164. return;
  9165. }
  9166. switch (target->type) {
  9167. case BL_PC:
  9168. {
  9169. struct map_session_data *tsd = (struct map_session_data *)target;
  9170. if (pc_isGM(sd) <= pc_isGM(tsd)) {
  9171. clif_GM_kickack(sd, 0);
  9172. return;
  9173. }
  9174. clif_GM_kick(sd, tsd, 1);
  9175. if(log_config.gm && lv >= log_config.gm) {
  9176. char message[NAME_LENGTH+6];
  9177. sprintf(message, "/kick %d", tsd->status.char_id);
  9178. log_atcommand(sd, message);
  9179. }
  9180. break;
  9181. }
  9182. case BL_MOB:
  9183. status_percent_damage(&sd->bl, target, 100, 0);
  9184. if(log_config.gm && lv >= log_config.gm) {
  9185. char message[NAME_LENGTH+16];
  9186. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9187. log_atcommand(sd, message);
  9188. }
  9189. break;
  9190. default:
  9191. clif_GM_kickack(sd, 0);
  9192. }
  9193. }
  9194. /*==========================================
  9195. * /shift
  9196. *------------------------------------------*/
  9197. void clif_parse_Shift(int fd, struct map_session_data *sd)
  9198. {
  9199. char *player_name;
  9200. int lv;
  9201. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9202. return;
  9203. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_JumpTo)))
  9204. return;
  9205. player_name = (char*)RFIFOP(fd,2);
  9206. player_name[NAME_LENGTH-1] = '\0';
  9207. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9208. if(log_config.gm && lv >= log_config.gm) {
  9209. char message[NAME_LENGTH+7];
  9210. sprintf(message, "/shift %s", player_name);
  9211. log_atcommand(sd, message);
  9212. }
  9213. return;
  9214. }
  9215. /*==========================================
  9216. * /recall
  9217. *------------------------------------------*/
  9218. void clif_parse_Recall(int fd, struct map_session_data *sd)
  9219. {
  9220. char *player_name;
  9221. int lv;
  9222. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9223. return;
  9224. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_Recall)))
  9225. return;
  9226. player_name = (char*)RFIFOP(fd,2);
  9227. player_name[NAME_LENGTH-1] = '\0';
  9228. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9229. if(log_config.gm && lv >= log_config.gm) {
  9230. char message[NAME_LENGTH+8];
  9231. sprintf(message, "/recall %s", player_name);
  9232. log_atcommand(sd, message);
  9233. }
  9234. return;
  9235. }
  9236. /*==========================================
  9237. * /monster /item
  9238. *------------------------------------------*/
  9239. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  9240. {
  9241. char *monster_item_name;
  9242. char message[NAME_LENGTH+10]; //For logging.
  9243. int level;
  9244. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9245. return;
  9246. monster_item_name = (char*)RFIFOP(fd,2);
  9247. monster_item_name[NAME_LENGTH-1] = '\0';
  9248. if (mobdb_searchname(monster_item_name)) {
  9249. if (pc_isGM(sd) < (level=get_atcommand_level(AtCommand_Spawn)))
  9250. return;
  9251. atcommand_monster(fd, sd, "@spawn", monster_item_name); // as @spawn
  9252. if(log_config.gm && level >= log_config.gm)
  9253. { //Log action. [Skotlex]
  9254. snprintf(message, sizeof(message)-1, "@spawn %s", monster_item_name);
  9255. log_atcommand(sd, message);
  9256. }
  9257. return;
  9258. }
  9259. if (itemdb_searchname(monster_item_name) == NULL)
  9260. return;
  9261. if (pc_isGM(sd) < (level = get_atcommand_level(AtCommand_Item)))
  9262. return;
  9263. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9264. if(log_config.gm && level >= log_config.gm)
  9265. { //Log action. [Skotlex]
  9266. sprintf(message, "@item %s", monster_item_name);
  9267. log_atcommand(sd, message);
  9268. }
  9269. }
  9270. /*==========================================
  9271. * /hide
  9272. *------------------------------------------*/
  9273. void clif_parse_GMHide(int fd, struct map_session_data *sd)
  9274. {
  9275. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9276. return;
  9277. if (pc_isGM(sd) < get_atcommand_level(AtCommand_Hide))
  9278. return;
  9279. if (sd->sc.option & OPTION_INVISIBLE) {
  9280. sd->sc.option &= ~OPTION_INVISIBLE;
  9281. if (sd->disguise)
  9282. status_set_viewdata(&sd->bl, sd->disguise);
  9283. else
  9284. status_set_viewdata(&sd->bl, sd->status.class_);
  9285. clif_displaymessage(fd, "Invisible: Off.");
  9286. } else {
  9287. sd->sc.option |= OPTION_INVISIBLE;
  9288. sd->vd.class_ = INVISIBLE_CLASS;
  9289. clif_displaymessage(fd, "Invisible: On.");
  9290. if(log_config.gm && get_atcommand_level(AtCommand_Hide) >= log_config.gm)
  9291. log_atcommand(sd, "/hide");
  9292. }
  9293. clif_changeoption(&sd->bl);
  9294. }
  9295. /*==========================================
  9296. * GMによるチャット禁止時間付与
  9297. *------------------------------------------*/
  9298. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9299. {
  9300. int type, limit, level;
  9301. struct block_list *bl;
  9302. struct map_session_data *dstsd;
  9303. bl = map_id2bl(RFIFOL(fd,2));
  9304. if (!bl || bl->type != BL_PC)
  9305. return;
  9306. dstsd =(struct map_session_data *)bl;
  9307. type = RFIFOB(fd,6);
  9308. limit = RFIFOW(fd,7);
  9309. if (type == 0)
  9310. limit = 0 - limit;
  9311. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  9312. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  9313. if (type == 2/* && sd->bl.id != dstsd->bl.id*/)
  9314. return;
  9315. if (
  9316. ((level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(AtCommand_Mute))
  9317. || (type == 2 && !level)) {
  9318. clif_GM_silence(sd, dstsd, ((type == 2) ? 1 : type));
  9319. dstsd->status.manner -= limit;
  9320. if(dstsd->status.manner < 0)
  9321. sc_start(bl,SC_NOCHAT,100,0,0);
  9322. else
  9323. {
  9324. dstsd->status.manner = 0;
  9325. status_change_end(bl,SC_NOCHAT,-1);
  9326. }
  9327. }
  9328. return;
  9329. }
  9330. /*==========================================
  9331. * GMによるチャット禁止時間参照(?)
  9332. *------------------------------------------*/
  9333. void clif_parse_GMReqNoChatCount(int fd, struct map_session_data *sd)
  9334. {
  9335. int tid;
  9336. tid = RFIFOL(fd,2);
  9337. WFIFOHEAD(fd,packet_len(0x1e0));
  9338. WFIFOW(fd,0) = 0x1e0;
  9339. WFIFOL(fd,2) = tid;
  9340. sprintf((char*)WFIFOP(fd,6),"%d",tid);
  9341. WFIFOSET(fd, packet_len(0x1e0));
  9342. return;
  9343. }
  9344. static int pstrcmp(const void *a, const void *b)
  9345. {
  9346. char *name1 = (char *)a;
  9347. char *name2 = (char *)b;
  9348. if (name1[0] && name2[0])
  9349. return strcmp(name1, name2);
  9350. //Since names are sorted in ascending order, send blank entries to the bottom.
  9351. if (name1[0])
  9352. return -1;
  9353. if (name2[0])
  9354. return 1;
  9355. return 0;
  9356. }
  9357. void clif_parse_PMIgnore(int fd, struct map_session_data *sd)
  9358. {
  9359. char output[512];
  9360. char *nick; // S 00cf <nick>.24B <type>.B: 00 (/ex nick) deny speech from nick, 01 (/in nick) allow speech from nick
  9361. int i;
  9362. memset(output, '\0', sizeof(output));
  9363. nick = (char*)RFIFOP(fd,2); // speed up
  9364. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name have at maximum 23 characters
  9365. WFIFOHEAD(fd,packet_len(0xd1));
  9366. WFIFOW(fd,0) = 0x0d1; // R 00d1 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9367. WFIFOB(fd,2) = RFIFOB(fd,26);
  9368. // deny action (we add nick only if it's not already exist
  9369. if (RFIFOB(fd,26) == 0) { // Add block
  9370. for(i = 0; i < MAX_IGNORE_LIST &&
  9371. sd->ignore[i].name[0] != '\0' &&
  9372. strcmp(sd->ignore[i].name, nick) != 0
  9373. ; i++);
  9374. if (i == MAX_IGNORE_LIST) { //Full List
  9375. WFIFOB(fd,3) = 1; // fail
  9376. WFIFOSET(fd, packet_len(0x0d1));
  9377. if (strcmp(wisp_server_name, nick) == 0)
  9378. { // to found possible bot users who automaticaly ignore people.
  9379. sprintf(output, "Character '%s' (account: %d) has tried to block wisps from '%s' (wisp name of the server). Bot user?", sd->status.name, sd->status.account_id, wisp_server_name);
  9380. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9381. }
  9382. return;
  9383. }
  9384. if(sd->ignore[i].name[0] != '\0')
  9385. { //Name already exists.
  9386. WFIFOB(fd,3) = 0; // Aegis reports success.
  9387. WFIFOSET(fd, packet_len(0x0d1));
  9388. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9389. sprintf(output, "Character '%s' (account: %d) has tried AGAIN to block wisps from '%s' (wisp name of the server). Bot user?", sd->status.name, sd->status.account_id, wisp_server_name);
  9390. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9391. }
  9392. return;
  9393. }
  9394. //Insert in position i
  9395. memcpy(sd->ignore[i].name, nick, NAME_LENGTH);
  9396. WFIFOB(fd,3) = 0; // success
  9397. WFIFOSET(fd, packet_len(0x0d1));
  9398. if (strcmp(wisp_server_name, nick) == 0)
  9399. { // to found possible bot users who automaticaly ignore people.
  9400. sprintf(output, "Character '%s' (account: %d) has tried to block wisps from '%s' (wisp name of the server). Bot user?", sd->status.name, sd->status.account_id, wisp_server_name);
  9401. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9402. // send something to be inform and force bot to ignore twice... If GM receiving block + block again, it's a bot :)
  9403. clif_wis_message(fd, wisp_server_name,
  9404. "Adding me in your ignore list will not block my wisps.",
  9405. strlen("Adding me in your ignore list will not block my wisps.") + 1);
  9406. }
  9407. //Sort the ignore list.
  9408. qsort (sd->ignore[0].name, MAX_IGNORE_LIST, sizeof(sd->ignore[0].name), pstrcmp);
  9409. return;
  9410. }
  9411. //Remove name
  9412. for(i = 0; i < MAX_IGNORE_LIST &&
  9413. sd->ignore[i].name[0] != '\0' &&
  9414. strcmp(sd->ignore[i].name, nick) != 0
  9415. ; i++);
  9416. if (i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0')
  9417. { //Not found
  9418. WFIFOB(fd,3) = 1; // fail
  9419. WFIFOSET(fd, packet_len(0x0d1));
  9420. return;
  9421. }
  9422. //Move everything one place down to overwrite removed entry.
  9423. memmove(sd->ignore[i].name, sd->ignore[i+1].name,
  9424. (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  9425. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  9426. // success
  9427. WFIFOB(fd,3) = 0;
  9428. WFIFOSET(fd, packet_len(0x0d1));
  9429. // for debug only
  9430. // for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++) /
  9431. // ShowDebug("Ignored player: '%s'\n", sd->ignore[i].name);
  9432. return;
  9433. }
  9434. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  9435. {
  9436. //printf("Ignore all: state: %d\n", RFIFOB(fd,2));
  9437. // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9438. // S 00d0 <type>len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech
  9439. WFIFOHEAD(fd,packet_len(0xd2));
  9440. WFIFOW(fd,0) = 0x0d2;
  9441. WFIFOB(fd,2) = RFIFOB(fd,2);
  9442. if (RFIFOB(fd,2) == 0) { //Deny all
  9443. if (sd->state.ignoreAll) {
  9444. WFIFOB(fd,3) = 1; // fail
  9445. WFIFOSET(fd, packet_len(0x0d2));
  9446. return;
  9447. }
  9448. sd->state.ignoreAll = 1;
  9449. WFIFOB(fd,3) = 0; // success
  9450. WFIFOSET(fd, packet_len(0x0d2));
  9451. return;
  9452. }
  9453. //Unblock everyone
  9454. if (!sd->state.ignoreAll) {
  9455. if (sd->ignore[0].name[0] != '\0')
  9456. { //Wipe the ignore list.
  9457. memset(sd->ignore, 0, sizeof(sd->ignore));
  9458. WFIFOB(fd,3) = 0;
  9459. WFIFOSET(fd, packet_len(0x0d2));
  9460. return;
  9461. }
  9462. WFIFOB(fd,3) = 1; // fail
  9463. WFIFOSET(fd, packet_len(0x0d2));
  9464. return;
  9465. }
  9466. sd->state.ignoreAll = 0;
  9467. WFIFOB(fd,3) = 0; // success
  9468. WFIFOSET(fd, packet_len(0x0d2));
  9469. return;
  9470. }
  9471. /*==========================================
  9472. * Wis拒否リスト
  9473. *------------------------------------------*/
  9474. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9475. {
  9476. int i;
  9477. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  9478. WFIFOW(fd,0) = 0xd4;
  9479. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9480. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  9481. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  9482. WFIFOSET(fd, WFIFOW(fd,2));
  9483. return;
  9484. }
  9485. /*==========================================
  9486. * スパノビの/doridoriによるSPR2倍
  9487. *------------------------------------------*/
  9488. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  9489. {
  9490. if (sd->state.doridori) return;
  9491. switch (sd->class_&MAPID_UPPERMASK)
  9492. {
  9493. case MAPID_SOUL_LINKER:
  9494. case MAPID_STAR_GLADIATOR:
  9495. case MAPID_TAEKWON:
  9496. if (!sd->state.rest)
  9497. break;
  9498. case MAPID_SUPER_NOVICE:
  9499. sd->state.doridori=1;
  9500. break;
  9501. }
  9502. return;
  9503. }
  9504. /*==========================================
  9505. * スパノビの爆裂波動
  9506. *------------------------------------------*/
  9507. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9508. {
  9509. if(sd){
  9510. int nextbaseexp=pc_nextbaseexp(sd);
  9511. if (battle_config.etc_log){
  9512. if(nextbaseexp != 0)
  9513. ShowInfo("SuperNovice explosionspirits!! %d %d %d %d\n",sd->bl.id,sd->status.class_,sd->status.base_exp,(int)((double)1000*sd->status.base_exp/nextbaseexp));
  9514. else
  9515. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9516. }
  9517. if((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE && sd->status.base_exp > 0 && nextbaseexp > 0 && (int)((double)1000*sd->status.base_exp/nextbaseexp)%100==0){
  9518. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9519. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  9520. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9521. }
  9522. }
  9523. return;
  9524. }
  9525. // random notes:
  9526. // 0x214: monster/player info ?
  9527. /*==========================================
  9528. * Friends List
  9529. *------------------------------------------*/
  9530. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9531. { //Toggles a single friend online/offline [Skotlex]
  9532. int i, fd = sd->fd;
  9533. //Seek friend.
  9534. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9535. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9536. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9537. return; //Not found
  9538. WFIFOHEAD(fd,packet_len(0x206));
  9539. WFIFOW(fd, 0) = 0x206;
  9540. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  9541. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  9542. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9543. WFIFOSET(fd, packet_len(0x206));
  9544. }
  9545. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9546. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9547. {
  9548. int account_id, char_id, online;
  9549. account_id = va_arg(ap, int);
  9550. char_id = va_arg(ap, int);
  9551. online = va_arg(ap, int);
  9552. clif_friendslist_toggle(sd, account_id, char_id, online);
  9553. return 0;
  9554. }
  9555. //For sending the whole friends list.
  9556. void clif_friendslist_send(struct map_session_data *sd)
  9557. {
  9558. int i = 0, n, fd = sd->fd;
  9559. // Send friends list
  9560. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  9561. WFIFOW(fd, 0) = 0x201;
  9562. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9563. {
  9564. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9565. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9566. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9567. }
  9568. if (i) {
  9569. WFIFOW(fd,2) = 4 + 32 * i;
  9570. WFIFOSET(fd, WFIFOW(fd,2));
  9571. }
  9572. for (n = 0; n < i; n++)
  9573. { //Sending the online players
  9574. if (map_charid2sd(sd->status.friends[n].char_id))
  9575. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9576. }
  9577. }
  9578. /// Reply for add friend request: (success => type 0)
  9579. /// type=0 : MsgStringTable[821]="You have become friends with (%s)."
  9580. /// type=1 : MsgStringTable[822]="(%s) does not want to be friends with you."
  9581. /// type=2 : MsgStringTable[819]="Your Friend List is full."
  9582. /// type=3 : MsgStringTable[820]="(%s)'s Friend List is full."
  9583. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9584. {
  9585. int fd;
  9586. nullpo_retv(sd);
  9587. fd = sd->fd;
  9588. WFIFOHEAD(fd,packet_len(0x209));
  9589. WFIFOW(fd,0) = 0x209;
  9590. WFIFOW(fd,2) = type;
  9591. if (f_sd)
  9592. {
  9593. WFIFOW(fd,4) = f_sd->status.account_id;
  9594. WFIFOW(fd,8) = f_sd->status.char_id;
  9595. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9596. }
  9597. WFIFOSET(fd, packet_len(0x209));
  9598. }
  9599. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  9600. {
  9601. struct map_session_data *f_sd;
  9602. int i, f_fd;
  9603. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9604. // Friend doesn't exist (no player with this name)
  9605. if (f_sd == NULL) {
  9606. clif_displaymessage(fd, msg_txt(3));
  9607. return;
  9608. }
  9609. // @noask [LuzZza]
  9610. if(f_sd->state.noask) {
  9611. clif_noask_sub(sd, f_sd, 5);
  9612. return;
  9613. }
  9614. // Friend already exists
  9615. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9616. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9617. clif_displaymessage(fd, "Friend already exists.");
  9618. return;
  9619. }
  9620. }
  9621. if (i == MAX_FRIENDS) {
  9622. //No space, list full.
  9623. clif_friendslist_reqack(sd, f_sd, 2);
  9624. return;
  9625. }
  9626. f_fd = f_sd->fd;
  9627. WFIFOHEAD(f_fd,packet_len(0x207));
  9628. WFIFOW(f_fd,0) = 0x207;
  9629. WFIFOL(f_fd,2) = sd->status.account_id;
  9630. WFIFOL(f_fd,6) = sd->status.char_id;
  9631. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9632. WFIFOSET(f_fd, packet_len(0x207));
  9633. return;
  9634. }
  9635. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  9636. {
  9637. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9638. struct map_session_data *f_sd;
  9639. int char_id, account_id;
  9640. char reply;
  9641. account_id = RFIFOL(fd,2);
  9642. char_id = RFIFOL(fd,6);
  9643. reply = RFIFOB(fd,10);
  9644. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9645. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9646. if (f_sd == NULL)
  9647. return;
  9648. if (reply == 0)
  9649. clif_friendslist_reqack(f_sd, sd, 1);
  9650. else {
  9651. int i;
  9652. // Find an empty slot
  9653. for (i = 0; i < MAX_FRIENDS; i++)
  9654. if (f_sd->status.friends[i].char_id == 0)
  9655. break;
  9656. if (i == MAX_FRIENDS) {
  9657. clif_friendslist_reqack(f_sd, sd, 2);
  9658. return;
  9659. }
  9660. f_sd->status.friends[i].account_id = sd->status.account_id;
  9661. f_sd->status.friends[i].char_id = sd->status.char_id;
  9662. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9663. clif_friendslist_reqack(f_sd, sd, 0);
  9664. if (battle_config.friend_auto_add) {
  9665. // Also add f_sd to sd's friendlist.
  9666. for (i = 0; i < MAX_FRIENDS; i++) {
  9667. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  9668. return; //No need to add anything.
  9669. if (sd->status.friends[i].char_id == 0)
  9670. break;
  9671. }
  9672. if (i == MAX_FRIENDS) {
  9673. clif_friendslist_reqack(sd, f_sd, 2);
  9674. return;
  9675. }
  9676. sd->status.friends[i].account_id = f_sd->status.account_id;
  9677. sd->status.friends[i].char_id = f_sd->status.char_id;
  9678. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  9679. clif_friendslist_reqack(sd, f_sd, 0);
  9680. }
  9681. }
  9682. return;
  9683. }
  9684. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  9685. {
  9686. // 0x203 </o> <ID to be removed W 4B>
  9687. int account_id, char_id;
  9688. int i, j;
  9689. account_id = RFIFOL(fd,2);
  9690. char_id = RFIFOL(fd,6);
  9691. // Search friend
  9692. for (i = 0; i < MAX_FRIENDS &&
  9693. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9694. if (i == MAX_FRIENDS) {
  9695. clif_displaymessage(fd, "Name not found in list.");
  9696. return;
  9697. }
  9698. // move all chars down
  9699. for(j = i + 1; j < MAX_FRIENDS; j++)
  9700. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9701. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9702. clif_displaymessage(fd, "Friend removed");
  9703. WFIFOHEAD(fd,packet_len(0x20a));
  9704. WFIFOW(fd,0) = 0x20a;
  9705. WFIFOL(fd,2) = account_id;
  9706. WFIFOL(fd,6) = char_id;
  9707. WFIFOSET(fd, packet_len(0x20a));
  9708. // clif_friendslist_send(sd); //This is not needed anymore.
  9709. return;
  9710. }
  9711. /*==========================================
  9712. * /killall
  9713. *------------------------------------------*/
  9714. void clif_parse_GMKillAll(int fd,struct map_session_data *sd)
  9715. {
  9716. char message[50];
  9717. strncpy(message,sd->status.name, NAME_LENGTH);
  9718. is_atcommand(fd, sd, strcat(message," : @kickall"));
  9719. return;
  9720. }
  9721. /*==========================================
  9722. * /pvpinfo
  9723. *------------------------------------------*/
  9724. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  9725. {
  9726. WFIFOHEAD(fd,packet_len(0x210));
  9727. WFIFOW(fd,0) = 0x210;
  9728. //WFIFOL(fd,2) = 0; // not sure what for yet
  9729. //WFIFOL(fd,6) = 0;
  9730. WFIFOL(fd,10) = sd->pvp_won; // times won
  9731. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  9732. WFIFOL(fd,18) = sd->pvp_point;
  9733. WFIFOSET(fd, packet_len(0x210));
  9734. return;
  9735. }
  9736. /*==========================================
  9737. * /blacksmith
  9738. *------------------------------------------*/
  9739. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  9740. {
  9741. int i;
  9742. char *name;
  9743. WFIFOHEAD(fd,packet_len(0x219));
  9744. WFIFOW(fd,0) = 0x219;
  9745. //Packet size limits this list to 10 elements. [Skotlex]
  9746. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9747. if (smith_fame_list[i].id > 0) {
  9748. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  9749. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  9750. {
  9751. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  9752. } else
  9753. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  9754. } else
  9755. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  9756. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  9757. }
  9758. for(;i < 10; i++) { //In case the MAX is less than 10.
  9759. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  9760. WFIFOL(fd, 242 + i * 4) = 0;
  9761. }
  9762. WFIFOSET(fd, packet_len(0x219));
  9763. }
  9764. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  9765. {
  9766. int fd = sd->fd;
  9767. WFIFOHEAD(fd,packet_len(0x21b));
  9768. WFIFOW(fd,0) = 0x21b;
  9769. WFIFOL(fd,2) = points;
  9770. WFIFOL(fd,6) = sd->status.fame;
  9771. WFIFOSET(fd, packet_len(0x21b));
  9772. return 0;
  9773. }
  9774. /*==========================================
  9775. * /alchemist
  9776. *------------------------------------------*/
  9777. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  9778. {
  9779. int i;
  9780. char *name;
  9781. WFIFOHEAD(fd,packet_len(0x21a));
  9782. WFIFOW(fd,0) = 0x21a;
  9783. //Packet size limits this list to 10 elements. [Skotlex]
  9784. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9785. if (chemist_fame_list[i].id > 0) {
  9786. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  9787. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  9788. {
  9789. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9790. } else
  9791. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  9792. } else
  9793. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9794. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  9795. }
  9796. for(;i < 10; i++) { //In case the MAX is less than 10.
  9797. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9798. WFIFOL(fd, 242 + i * 4) = 0;
  9799. }
  9800. WFIFOSET(fd, packet_len(0x21a));
  9801. }
  9802. int clif_fame_alchemist(struct map_session_data *sd, int points)
  9803. {
  9804. int fd = sd->fd;
  9805. WFIFOHEAD(fd,packet_len(0x21c));
  9806. WFIFOW(fd,0) = 0x21c;
  9807. WFIFOL(fd,2) = points;
  9808. WFIFOL(fd,6) = sd->status.fame;
  9809. WFIFOSET(fd, packet_len(0x21c));
  9810. return 0;
  9811. }
  9812. /*==========================================
  9813. * /taekwon
  9814. *------------------------------------------*/
  9815. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  9816. {
  9817. int i;
  9818. char *name;
  9819. WFIFOHEAD(fd,packet_len(0x226));
  9820. WFIFOW(fd,0) = 0x226;
  9821. //Packet size limits this list to 10 elements. [Skotlex]
  9822. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9823. if (taekwon_fame_list[i].id > 0) {
  9824. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  9825. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  9826. {
  9827. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9828. } else
  9829. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  9830. } else
  9831. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9832. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  9833. }
  9834. for(;i < 10; i++) { //In case the MAX is less than 10.
  9835. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9836. WFIFOL(fd, 242 + i * 4) = 0;
  9837. }
  9838. WFIFOSET(fd, packet_len(0x226));
  9839. }
  9840. int clif_fame_taekwon(struct map_session_data *sd, int points)
  9841. {
  9842. int fd = sd->fd;
  9843. WFIFOHEAD(fd,packet_len(0x224));
  9844. WFIFOW(fd,0) = 0x224;
  9845. WFIFOL(fd,2) = points;
  9846. WFIFOL(fd,6) = sd->status.fame;
  9847. WFIFOSET(fd, packet_len(0x224));
  9848. return 0;
  9849. }
  9850. /*==========================================
  9851. * PK Ranking table?
  9852. *------------------------------------------*/
  9853. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  9854. {
  9855. int i;
  9856. WFIFOHEAD(fd,packet_len(0x238));
  9857. WFIFOW(fd,0) = 0x238;
  9858. for(i=0;i<10;i++){
  9859. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  9860. WFIFOL(fd,i*4+242) = 0;
  9861. }
  9862. WFIFOSET(fd, packet_len(0x238));
  9863. return;
  9864. }
  9865. /*==========================================
  9866. * SG Feel save OK [Komurka]
  9867. *------------------------------------------*/
  9868. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  9869. {
  9870. char feel_var[3][NAME_LENGTH] = {"PC_FEEL_SUN","PC_FEEL_MOON","PC_FEEL_STAR"};
  9871. int i;
  9872. if (sd->menuskill_id != SG_FEEL)
  9873. return;
  9874. i = sd->menuskill_lv-1;
  9875. if (i<0 || i > 2) return; //Bug?
  9876. sd->feel_map[i].index = map[sd->bl.m].index;
  9877. sd->feel_map[i].m = sd->bl.m;
  9878. pc_setglobalreg(sd,feel_var[i],map[sd->bl.m].index);
  9879. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  9880. // clif_misceffect2(&sd->bl, 0x1b0);
  9881. // clif_misceffect2(&sd->bl, 0x21f);
  9882. clif_feel_info(sd, i, 0);
  9883. sd->menuskill_lv = sd->menuskill_id = 0;
  9884. }
  9885. /*==========================================
  9886. * Question about Star Glaldiator save map [Komurka]
  9887. *------------------------------------------*/
  9888. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv)
  9889. {
  9890. WFIFOHEAD(fd,packet_len(0x253));
  9891. WFIFOW(fd,0)=0x253;
  9892. WFIFOSET(fd, packet_len(0x253));
  9893. sd->menuskill_id=SG_FEEL;
  9894. sd->menuskill_lv=skilllv;
  9895. }
  9896. void clif_parse_AdoptRequest(int fd,struct map_session_data *sd)
  9897. {
  9898. //TODO: add somewhere the adopt code, checks for exploits, etc, etc.
  9899. //Missing packets are the client's reply packets to the adopt request one.
  9900. //[Skotlex]
  9901. int account_id;
  9902. struct map_session_data *sd2;
  9903. account_id = RFIFOL(fd,2);
  9904. sd2 = map_id2sd(account_id);
  9905. if(sd2 && sd2->fd && sd2 != sd && sd2->status.party_id == sd->status.party_id) { //FIXME: No checks whatsoever are in place yet!
  9906. fd = sd2->fd;
  9907. WFIFOHEAD(fd,packet_len(0x1f9));
  9908. WFIFOW(fd,0)=0x1f9;
  9909. WFIFOSET(fd, packet_len(0x1f9));
  9910. }
  9911. }
  9912. /*==========================================
  9913. * Homunculus packets
  9914. *------------------------------------------*/
  9915. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  9916. {
  9917. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  9918. }
  9919. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  9920. { //[orn]
  9921. nullpo_retv(sd);
  9922. if(!merc_is_hom_active(sd->hd))
  9923. return;
  9924. unit_walktoxy(&sd->hd->bl, sd->bl.x,sd->bl.y-1, 4);
  9925. }
  9926. void clif_parse_HomMoveTo(int fd,struct map_session_data *sd)
  9927. { //[orn]
  9928. int x,y,cmd;
  9929. nullpo_retv(sd);
  9930. if(!merc_is_hom_active(sd->hd))
  9931. return;
  9932. cmd = RFIFOW(fd,0);
  9933. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  9934. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  9935. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  9936. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  9937. unit_walktoxy(&(sd->hd->bl),x,y,4);
  9938. }
  9939. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  9940. { //[orn]
  9941. if(!merc_is_hom_active(sd->hd))
  9942. return;
  9943. unit_attack(&sd->hd->bl,RFIFOL(fd,6),0) ;
  9944. }
  9945. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  9946. { //[orn]
  9947. int cmd;
  9948. cmd = RFIFOW(fd,0);
  9949. if(!merc_is_hom_active(sd->hd))
  9950. return;
  9951. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  9952. }
  9953. /*==========================================
  9954. * パケットデバッグ
  9955. *------------------------------------------*/
  9956. void clif_parse_debug(int fd,struct map_session_data *sd)
  9957. {
  9958. int i, cmd, len;
  9959. cmd = RFIFOW(fd,0);
  9960. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  9961. ShowDebug("packet debug 0x%4X\n",cmd);
  9962. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  9963. for(i=0;i<len;i++){
  9964. if((i&15)==0)
  9965. printf("\n%04X ",i);
  9966. printf("%02X ",RFIFOB(fd,i));
  9967. }
  9968. printf("\n");
  9969. }
  9970. /*==========================================
  9971. * クライアントからのパケット解析
  9972. * socket.cのdo_parsepacketから呼び出される
  9973. *------------------------------------------*/
  9974. int clif_parse(int fd)
  9975. {
  9976. int packet_len = 0, cmd, packet_ver, err, dump = 0;
  9977. TBL_PC *sd;
  9978. sd = (TBL_PC *)session[fd]->session_data;
  9979. if (session[fd]->eof) {
  9980. if (sd) {
  9981. if (sd->state.autotrade) {
  9982. //Disassociate character from the socket connection.
  9983. session[fd]->session_data = NULL;
  9984. sd->fd = 0;
  9985. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n",
  9986. (pc_isGM(sd))?"GM ":"",sd->status.name);
  9987. } else
  9988. if (sd->state.auth) {
  9989. // Player logout display [Valaris]
  9990. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n",
  9991. (pc_isGM(sd))?"GM ":"",sd->status.name);
  9992. clif_quitsave(fd, sd);
  9993. } else {
  9994. ShowInfo("Player AID:%d/CID:%d (not authenticated) logged off.\n",
  9995. sd->bl.id, sd->status.char_id);
  9996. map_quit(sd);
  9997. }
  9998. } else {
  9999. uint32 ip = session[fd]->client_addr;
  10000. ShowInfo("Closed connection from '"CL_WHITE"%d.%d.%d.%d"CL_RESET"'.\n", CONVIP(ip));
  10001. }
  10002. do_close(fd);
  10003. return 0;
  10004. }
  10005. if (RFIFOREST(fd) < 2)
  10006. return 0;
  10007. // printf("clif_parse: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
  10008. cmd = RFIFOW(fd,0);
  10009. // get packet version before to parse
  10010. packet_ver = 0;
  10011. if (sd) {
  10012. packet_ver = sd->packet_ver;
  10013. if (packet_ver < 0 || packet_ver > MAX_PACKET_VER) { // This should never happen unless we have some corrupted memory issues :X [Skotlex]
  10014. ShowWarning("clif_parse: Disconnecting session #%d (AID:%d/CID:%d) for having invalid packet_ver=%d.", fd, sd->status.account_id, sd->status.char_id, packet_ver);
  10015. set_eof(fd);
  10016. return 0;
  10017. }
  10018. } else {
  10019. // check authentification packet to know packet version
  10020. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  10021. if( err )
  10022. {// failed to identify packet version
  10023. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  10024. err == 1 ? "" :
  10025. err == 2 ? ", possibly for having an invalid account_id" :
  10026. err == 3 ? ", possibly for having an invalid char_id." :
  10027. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  10028. err == 4 ? ", possibly for having an invalid login_id1." :
  10029. err == 5 ? ", possibly for having an invalid client_tick." :
  10030. */
  10031. err == 6 ? ", possibly for having an invalid sex." :
  10032. ". ERROR invalid error code"));
  10033. WFIFOHEAD(fd,packet_len(0x6a));
  10034. WFIFOW(fd,0) = 0x6a;
  10035. WFIFOB(fd,2) = 3; // Rejected from Server
  10036. WFIFOSET(fd,packet_len(0x6a));
  10037. RFIFOSKIP(fd, RFIFOREST(fd));
  10038. clif_setwaitclose(fd);
  10039. return 0;
  10040. }
  10041. }
  10042. // ゲーム用以外パケットか、認証を終える前に0072以外が来たら、切断する
  10043. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) { // if packet is not inside these values: session is incorrect?? or auth packet is unknown
  10044. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  10045. set_eof(fd);
  10046. return 0;
  10047. }
  10048. // パケット長を計算
  10049. packet_len = packet_db[packet_ver][cmd].len;
  10050. if (packet_len == -1) {
  10051. if (RFIFOREST(fd) < 4)
  10052. return 0; // 可変長パケットで長さの所までデータが来てない
  10053. packet_len = RFIFOW(fd,2);
  10054. if (packet_len < 4 || packet_len > 32768) {
  10055. ShowWarning("clif_parse: Packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  10056. set_eof(fd);
  10057. return 0;
  10058. }
  10059. }
  10060. if ((int)RFIFOREST(fd) < packet_len)
  10061. return 0; // まだ1パケット分データが揃ってない
  10062. #if DUMP_ALL_PACKETS
  10063. {
  10064. int i;
  10065. FILE *fp;
  10066. char packet_txt[256] = "save/packet.txt";
  10067. time_t now;
  10068. dump = 1;
  10069. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10070. ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
  10071. return 1;
  10072. } else {
  10073. time(&now);
  10074. if (sd && sd->state.auth) {
  10075. if (sd->status.name != NULL)
  10076. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent packet:\n",
  10077. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10078. else
  10079. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10080. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10081. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10082. fprintf(fp, "\tsession #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10083. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10084. for(i = 0; i < packet_len; i++) {
  10085. if ((i & 15) == 0)
  10086. fprintf(fp, "\n\t%04X ", i);
  10087. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10088. }
  10089. fprintf(fp, "\n\n");
  10090. fclose(fp);
  10091. }
  10092. }
  10093. #endif
  10094. if (sd && sd->state.waitingdisconnect == 1) {
  10095. // 切断待ちの場合パケットを処理しない
  10096. } else if (packet_db[packet_ver][cmd].func) {
  10097. if (sd && sd->bl.prev == NULL &&
  10098. packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck)
  10099. ; //Only valid packet when player is not on a map is the finish-loading packet.
  10100. else
  10101. if (sd
  10102. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  10103. || packet_db[packet_ver][cmd].func == clif_parse_debug
  10104. ) //Only execute the function when there's an sd (except for debug/wanttoconnect packets)
  10105. packet_db[packet_ver][cmd].func(fd, sd);
  10106. }
  10107. #if DUMP_UNKNOWN_PACKET
  10108. else if (battle_config.error_log)
  10109. {
  10110. int i;
  10111. FILE *fp;
  10112. char packet_txt[256] = "save/packet.txt";
  10113. time_t now;
  10114. dump = 1;
  10115. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10116. ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
  10117. return 1;
  10118. } else {
  10119. time(&now);
  10120. if (sd && sd->state.auth) {
  10121. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  10122. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10123. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10124. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10125. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10126. for(i = 0; i < packet_len; i++) {
  10127. if ((i & 15) == 0)
  10128. fprintf(fp, "\n\t%04X ", i);
  10129. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10130. }
  10131. fprintf(fp, "\n\n");
  10132. fclose(fp);
  10133. }
  10134. }
  10135. #endif
  10136. if (dump) {
  10137. int i;
  10138. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10139. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10140. for(i = 0; i < packet_len; i++) {
  10141. if ((i & 15) == 0)
  10142. printf("\n%04X ",i);
  10143. printf("%02X ", RFIFOB(fd,i));
  10144. }
  10145. printf("\n");
  10146. if (sd && sd->state.auth) {
  10147. if (sd->status.name != NULL)
  10148. printf("\nAccount ID %d, character ID %d, player name %s.\n",
  10149. sd->status.account_id, sd->status.char_id, sd->status.name);
  10150. else
  10151. printf("\nAccount ID %d.\n", sd->bl.id);
  10152. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10153. printf("\nAccount ID %d.\n", sd->bl.id);
  10154. }
  10155. RFIFOSKIP(fd, packet_len);
  10156. return 0;
  10157. }
  10158. /*==========================================
  10159. * パケットデータベース読み込み
  10160. *------------------------------------------*/
  10161. static int packetdb_readdb(void)
  10162. {
  10163. FILE *fp;
  10164. char line[1024];
  10165. int ln=0;
  10166. int cmd,i,j,k,packet_ver;
  10167. int max_cmd=-1;
  10168. int skip_ver = 0;
  10169. int warned = 0;
  10170. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  10171. int packet_len_table[0x290] = {
  10172. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10176. //#0x0040
  10177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10179. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  10180. #if PACKETVER < 2
  10181. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  10182. #else // 78-7b 亀島以降 lv99エフェクト用
  10183. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  10184. #endif
  10185. //#0x0080
  10186. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  10187. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  10188. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  10189. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  10190. //#0x00C0
  10191. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  10192. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  10193. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  10194. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  10195. //#0x0100
  10196. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  10197. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  10198. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  10199. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  10200. //#0x0140
  10201. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  10202. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  10203. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  10204. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  10205. //#0x0180
  10206. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  10207. #if PACKETVER < 1
  10208. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10209. #else // 196 comodo以降 状態表示アイコン用
  10210. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10211. #endif
  10212. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  10213. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  10214. //#0x01C0, Set 0x1d5=-1
  10215. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  10216. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  10217. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  10218. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  10219. //#0x0200
  10220. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  10221. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282,10, 10, -1, -1, 66,
  10222. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  10223. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1,-1, 4, 2,
  10224. //#0x0240
  10225. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8,12, 4, 10,
  10226. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4,-1, 4, 0,
  10227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10229. //#0x0280
  10230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0
  10231. };
  10232. struct {
  10233. void (*func)(int, struct map_session_data *);
  10234. char *name;
  10235. } clif_parse_func[]={
  10236. {clif_parse_WantToConnection,"wanttoconnection"},
  10237. {clif_parse_LoadEndAck,"loadendack"},
  10238. {clif_parse_TickSend,"ticksend"},
  10239. {clif_parse_WalkToXY,"walktoxy"},
  10240. {clif_parse_QuitGame,"quitgame"},
  10241. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  10242. {clif_parse_GlobalMessage,"globalmessage"},
  10243. {clif_parse_MapMove,"mapmove"},
  10244. {clif_parse_ChangeDir,"changedir"},
  10245. {clif_parse_Emotion,"emotion"},
  10246. {clif_parse_HowManyConnections,"howmanyconnections"},
  10247. {clif_parse_ActionRequest,"actionrequest"},
  10248. {clif_parse_Restart,"restart"},
  10249. {clif_parse_Wis,"wis"},
  10250. {clif_parse_GMmessage,"gmmessage"},
  10251. {clif_parse_TakeItem,"takeitem"},
  10252. {clif_parse_DropItem,"dropitem"},
  10253. {clif_parse_UseItem,"useitem"},
  10254. {clif_parse_EquipItem,"equipitem"},
  10255. {clif_parse_UnequipItem,"unequipitem"},
  10256. {clif_parse_NpcClicked,"npcclicked"},
  10257. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  10258. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  10259. {clif_parse_NpcSellListSend,"npcselllistsend"},
  10260. {clif_parse_CreateChatRoom,"createchatroom"},
  10261. {clif_parse_ChatAddMember,"chataddmember"},
  10262. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  10263. {clif_parse_ChangeChatOwner,"changechatowner"},
  10264. {clif_parse_KickFromChat,"kickfromchat"},
  10265. {clif_parse_ChatLeave,"chatleave"},
  10266. {clif_parse_TradeRequest,"traderequest"},
  10267. {clif_parse_TradeAck,"tradeack"},
  10268. {clif_parse_TradeAddItem,"tradeadditem"},
  10269. {clif_parse_TradeOk,"tradeok"},
  10270. {clif_parse_TradeCancel,"tradecancel"},
  10271. {clif_parse_TradeCommit,"tradecommit"},
  10272. {clif_parse_StopAttack,"stopattack"},
  10273. {clif_parse_PutItemToCart,"putitemtocart"},
  10274. {clif_parse_GetItemFromCart,"getitemfromcart"},
  10275. {clif_parse_RemoveOption,"removeoption"},
  10276. {clif_parse_ChangeCart,"changecart"},
  10277. {clif_parse_StatusUp,"statusup"},
  10278. {clif_parse_SkillUp,"skillup"},
  10279. {clif_parse_UseSkillToId,"useskilltoid"},
  10280. {clif_parse_UseSkillToPos,"useskilltopos"},
  10281. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  10282. {clif_parse_UseSkillMap,"useskillmap"},
  10283. {clif_parse_RequestMemo,"requestmemo"},
  10284. {clif_parse_ProduceMix,"producemix"},
  10285. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  10286. {clif_parse_NpcNextClicked,"npcnextclicked"},
  10287. {clif_parse_NpcAmountInput,"npcamountinput"},
  10288. {clif_parse_NpcStringInput,"npcstringinput"},
  10289. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  10290. {clif_parse_ItemIdentify,"itemidentify"},
  10291. {clif_parse_SelectArrow,"selectarrow"},
  10292. {clif_parse_AutoSpell,"autospell"},
  10293. {clif_parse_UseCard,"usecard"},
  10294. {clif_parse_InsertCard,"insertcard"},
  10295. {clif_parse_RepairItem,"repairitem"},
  10296. {clif_parse_WeaponRefine,"weaponrefine"},
  10297. {clif_parse_SolveCharName,"solvecharname"},
  10298. {clif_parse_ResetChar,"resetchar"},
  10299. {clif_parse_LGMmessage,"lgmmessage"},
  10300. {clif_parse_MoveToKafra,"movetokafra"},
  10301. {clif_parse_MoveFromKafra,"movefromkafra"},
  10302. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  10303. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  10304. {clif_parse_CloseKafra,"closekafra"},
  10305. {clif_parse_CreateParty,"createparty"},
  10306. {clif_parse_CreateParty2,"createparty2"},
  10307. {clif_parse_PartyInvite,"partyinvite"},
  10308. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  10309. {clif_parse_LeaveParty,"leaveparty"},
  10310. {clif_parse_RemovePartyMember,"removepartymember"},
  10311. {clif_parse_PartyChangeOption,"partychangeoption"},
  10312. {clif_parse_PartyMessage,"partymessage"},
  10313. {clif_parse_CloseVending,"closevending"},
  10314. {clif_parse_VendingListReq,"vendinglistreq"},
  10315. {clif_parse_PurchaseReq,"purchasereq"},
  10316. {clif_parse_OpenVending,"openvending"},
  10317. {clif_parse_CreateGuild,"createguild"},
  10318. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  10319. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  10320. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  10321. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  10322. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  10323. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  10324. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  10325. {clif_parse_GuildInvite,"guildinvite"},
  10326. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  10327. {clif_parse_GuildLeave,"guildleave"},
  10328. {clif_parse_GuildExpulsion,"guildexplusion"},
  10329. {clif_parse_GuildMessage,"guildmessage"},
  10330. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  10331. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  10332. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  10333. {clif_parse_GuildOpposition,"guildopposition"},
  10334. {clif_parse_GuildBreak,"guildbreak"},
  10335. {clif_parse_PetMenu,"petmenu"},
  10336. {clif_parse_CatchPet,"catchpet"},
  10337. {clif_parse_SelectEgg,"selectegg"},
  10338. {clif_parse_SendEmotion,"sendemotion"},
  10339. {clif_parse_ChangePetName,"changepetname"},
  10340. {clif_parse_GMKick,"gmkick"},
  10341. {clif_parse_GMHide,"gmhide"},
  10342. {clif_parse_GMReqNoChat,"gmreqnochat"},
  10343. {clif_parse_GMReqNoChatCount,"gmreqnochatcount"},
  10344. {clif_parse_NoviceDoriDori,"sndoridori"},
  10345. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  10346. {clif_parse_PMIgnore,"wisexin"},
  10347. {clif_parse_PMIgnoreList,"wisexlist"},
  10348. {clif_parse_PMIgnoreAll,"wisall"},
  10349. {clif_parse_FriendsListAdd,"friendslistadd"},
  10350. {clif_parse_FriendsListRemove,"friendslistremove"},
  10351. {clif_parse_FriendsListReply,"friendslistreply"},
  10352. {clif_parse_GMKillAll,"killall"},
  10353. {clif_parse_Recall,"summon"},
  10354. {clif_parse_GM_Monster_Item,"itemmonster"},
  10355. {clif_parse_Shift,"shift"},
  10356. {clif_parse_Blacksmith,"blacksmith"},
  10357. {clif_parse_Alchemist,"alchemist"},
  10358. {clif_parse_Taekwon,"taekwon"},
  10359. {clif_parse_RankingPk,"rankingpk"},
  10360. {clif_parse_FeelSaveOk,"feelsaveok"},
  10361. {clif_parse_AdoptRequest,"adopt"},
  10362. {clif_parse_debug,"debug"},
  10363. //[blackhole89] //[orn]
  10364. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  10365. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  10366. {clif_parse_HomMoveTo,"hommoveto"},
  10367. {clif_parse_HomAttack,"homattack"},
  10368. {clif_parse_HomMenu,"hommenu"},
  10369. {clif_parse_StoragePassword,"storagepassword"},
  10370. {NULL,NULL}
  10371. };
  10372. // Set server packet lengths - packet_db[SERVER]
  10373. memset(packet_db,0,sizeof(packet_db));
  10374. for( i = 0; i < sizeof(packet_len_table)/sizeof(packet_len_table[0]); ++i )
  10375. packet_len(i) = packet_len_table[i];
  10376. sprintf(line, "%s/packet_db.txt", db_path);
  10377. if( (fp=fopen(line,"r"))==NULL ){
  10378. ShowFatalError("can't read %s\n", line);
  10379. exit(1);
  10380. }
  10381. clif_config.packet_db_ver = MAX_PACKET_VER;
  10382. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  10383. while( fgets(line, sizeof(line), fp) )
  10384. {
  10385. ln++;
  10386. if(line[0]=='/' && line[1]=='/')
  10387. continue;
  10388. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  10389. {
  10390. if(strcmpi(w1,"packet_ver")==0) {
  10391. int prev_ver = packet_ver;
  10392. skip_ver = 0;
  10393. packet_ver = atoi(w2);
  10394. if ( packet_ver > MAX_PACKET_VER )
  10395. { //Check to avoid overflowing. [Skotlex]
  10396. if( (warned&1) == 0 )
  10397. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  10398. warned &= 1;
  10399. skip_ver = 1;
  10400. }
  10401. else if( packet_ver < 0 )
  10402. {
  10403. if( (warned&2) == 0 )
  10404. ShowWarning("Negative packet versions are not supported.\n");
  10405. warned &= 2;
  10406. skip_ver = 1;
  10407. }
  10408. else if( packet_ver == SERVER )
  10409. {
  10410. if( (warned&4) == 0 )
  10411. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  10412. warned &= 4;
  10413. skip_ver = 1;
  10414. }
  10415. if( skip_ver )
  10416. {
  10417. ShowWarning("Skipping packet version %d.\n", packet_ver);
  10418. packet_ver = prev_ver;
  10419. continue;
  10420. }
  10421. // copy from previous version into new version and continue
  10422. // - indicating all following packets should be read into the newer version
  10423. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  10424. continue;
  10425. } else if(strcmpi(w1,"packet_db_ver")==0) {
  10426. //This is the preferred version.
  10427. if(strcmpi(w2,"default")==0)
  10428. clif_config.packet_db_ver = MAX_PACKET_VER;
  10429. else {
  10430. // to manually set the packet DB version
  10431. clif_config.packet_db_ver = atoi(w2);
  10432. // check for invalid version
  10433. if (clif_config.packet_db_ver > MAX_PACKET_VER ||
  10434. clif_config.packet_db_ver < 0)
  10435. clif_config.packet_db_ver = MAX_PACKET_VER;
  10436. }
  10437. continue;
  10438. }
  10439. }
  10440. if( skip_ver != 0 )
  10441. continue; // Skipping current packet version
  10442. memset(str,0,sizeof(str));
  10443. for(j=0,p=line;j<4 && p; ++j)
  10444. {
  10445. str[j]=p;
  10446. p=strchr(p,',');
  10447. if(p) *p++=0;
  10448. }
  10449. if(str[0]==NULL)
  10450. continue;
  10451. cmd=strtol(str[0],(char **)NULL,0);
  10452. if(max_cmd < cmd)
  10453. max_cmd = cmd;
  10454. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  10455. continue;
  10456. if(str[1]==NULL){
  10457. ShowError("packet_db: packet len error\n");
  10458. continue;
  10459. }
  10460. k = atoi(str[1]);
  10461. packet_db[packet_ver][cmd].len = k;
  10462. if(str[2]==NULL){
  10463. packet_db[packet_ver][cmd].func = NULL;
  10464. ln++;
  10465. continue;
  10466. }
  10467. for(j=0;j<sizeof(clif_parse_func)/sizeof(clif_parse_func[0]);j++){
  10468. if(clif_parse_func[j].name != NULL &&
  10469. strcmp(str[2],clif_parse_func[j].name)==0)
  10470. {
  10471. if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func)
  10472. { //If we are updating a function, we need to zero up the previous one. [Skotlex]
  10473. for(i=0;i<=MAX_PACKET_DB;i++){
  10474. if (packet_db[packet_ver][i].func == clif_parse_func[j].func)
  10475. {
  10476. memset(&packet_db[packet_ver][i], 0, sizeof(struct packet_db));
  10477. break;
  10478. }
  10479. }
  10480. }
  10481. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  10482. break;
  10483. }
  10484. }
  10485. // set the identifying cmd for the packet_db version
  10486. if (strcmp(str[2],"wanttoconnection")==0)
  10487. clif_config.connect_cmd[packet_ver] = cmd;
  10488. if(str[3]==NULL){
  10489. ShowError("packet_db: packet error\n");
  10490. exit(1);
  10491. }
  10492. for(j=0,p2=str[3];p2;j++){
  10493. str2[j]=p2;
  10494. p2=strchr(p2,':');
  10495. if(p2) *p2++=0;
  10496. k = atoi(str2[j]);
  10497. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  10498. packet_db[packet_ver][cmd].pos[j] = k;
  10499. }
  10500. }
  10501. fclose(fp);
  10502. if(max_cmd > MAX_PACKET_DB)
  10503. {
  10504. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  10505. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  10506. }
  10507. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  10508. { //Locate the nearest version that we still support. [Skotlex]
  10509. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  10510. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  10511. }
  10512. ShowStatus("Done reading packet database from '"CL_WHITE"%s"CL_RESET"'. Using default packet version: "CL_WHITE"%d"CL_RESET".\n", "packet_db.txt", clif_config.packet_db_ver);
  10513. return 0;
  10514. }
  10515. /*==========================================
  10516. *
  10517. *------------------------------------------*/
  10518. int do_init_clif(void)
  10519. {
  10520. clif_config.packet_db_ver = -1; // the main packet version of the DB
  10521. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  10522. memset(packet_db,0,sizeof(packet_db));
  10523. //Using the packet_db file is the only way to set up packets now [Skotlex]
  10524. packetdb_readdb();
  10525. set_defaultparse(clif_parse);
  10526. if (!make_listen_bind(bind_ip,map_port)) {
  10527. ShowFatalError("can't bind game port\n");
  10528. exit(1);
  10529. }
  10530. add_timer_func_list(clif_waitclose, "clif_waitclose");
  10531. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  10532. add_timer_func_list(clif_delayquit, "clif_delayquit");
  10533. return 0;
  10534. }