clif.c 334 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #define DUMP_UNKNOWN_PACKET 0
  4. #define DUMP_ALL_PACKETS 0
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdarg.h>
  10. #ifdef __WIN32
  11. #define __USE_W32_SOCKETS
  12. #include <windows.h>
  13. #else
  14. #include <unistd.h>
  15. #include <sys/types.h>
  16. #include <sys/socket.h>
  17. #include <netinet/in.h>
  18. #include <arpa/inet.h>
  19. #endif
  20. #include <time.h>
  21. #include "../common/socket.h"
  22. #include "../common/timer.h"
  23. #include "../common/malloc.h"
  24. #include "../common/version.h"
  25. #include "../common/nullpo.h"
  26. #include "../common/showmsg.h"
  27. #include "map.h"
  28. #include "chrif.h"
  29. #include "clif.h"
  30. #include "pc.h"
  31. #include "status.h"
  32. #include "npc.h"
  33. #include "itemdb.h"
  34. #include "chat.h"
  35. #include "trade.h"
  36. #include "storage.h"
  37. #include "script.h"
  38. #include "skill.h"
  39. #include "atcommand.h"
  40. #include "charcommand.h"
  41. #include "intif.h"
  42. #include "battle.h"
  43. #include "mob.h"
  44. #include "party.h"
  45. #include "guild.h"
  46. #include "vending.h"
  47. #include "pet.h"
  48. #include "log.h"
  49. #include "irc.h"
  50. struct Clif_Config {
  51. int packet_db_ver; //Preferred packet version.
  52. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  53. } clif_config;
  54. struct packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB];
  55. static const int packet_len_table[MAX_PACKET_DB] = {
  56. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  57. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  58. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  59. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  60. //#0x0040
  61. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  62. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  63. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  64. #if PACKETVER < 2
  65. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  66. #else // 78-7b 亀島以降 lv99エフェクト用
  67. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  68. #endif
  69. //#0x0080
  70. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  71. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  72. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  73. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  74. //#0x00C0
  75. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  76. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  77. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  78. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  79. //#0x0100
  80. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  81. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  82. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  83. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  84. //#0x0140
  85. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  86. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  87. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  88. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  89. //#0x0180
  90. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  91. #if PACKETVER < 1
  92. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  93. #else // 196 comodo以降 状態表示アイコン用
  94. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  95. #endif
  96. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  97. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  98. //#0x01C0, Set 0x1d5=-1
  99. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  100. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  101. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  102. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  103. //#0x200
  104. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  105. 22, 0, 26, 26, 42, -1, -1, 2, 2,282,282,10, 10, -1, -1, 66,
  106. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 69, 5,
  107. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1,-1, 4, 2,
  108. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8,12, 4, 10,
  109. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4,-1, 4
  110. };
  111. // local define
  112. enum {
  113. ALL_CLIENT,
  114. ALL_SAMEMAP,
  115. AREA,
  116. AREA_WOS,
  117. AREA_WOC,
  118. AREA_WOSC,
  119. AREA_CHAT_WOC,
  120. CHAT,
  121. CHAT_WOS,
  122. CHAT_MAINCHAT,
  123. PARTY,
  124. PARTY_WOS,
  125. PARTY_SAMEMAP,
  126. PARTY_SAMEMAP_WOS,
  127. PARTY_AREA,
  128. PARTY_AREA_WOS,
  129. GUILD,
  130. GUILD_WOS,
  131. GUILD_SAMEMAP, // [Valaris]
  132. GUILD_SAMEMAP_WOS,
  133. GUILD_AREA,
  134. GUILD_AREA_WOS, // end additions [Valaris]
  135. SELF
  136. };
  137. //Converts item type in case of pet eggs.
  138. #define itemtype(a) (a == 7)?4:a
  139. #define WBUFPOS(p,pos,x,y) { unsigned char *__p = (p); __p+=(pos); __p[0] = (x)>>2; __p[1] = ((x)<<6) | (((y)>>4)&0x3f); __p[2] = (y)<<4; }
  140. #define WBUFPOS2(p,pos,x0,y0,x1,y1) { unsigned char *__p = (p); __p+=(pos); __p[0] = (unsigned char)((x0)>>2); __p[1] = (unsigned char)(((x0)<<6) | (((y0)>>4)&0x3f)); __p[2] = (unsigned char)(((y0)<<4) | (((x1)>>6)&0x0f)); __p[3]=(unsigned char)(((x1)<<2) | (((y1)>>8)&0x03)); __p[4]=(unsigned char)(y1); }
  141. #define WFIFOPOS(fd,pos,x,y) { WBUFPOS (WFIFOP(fd,pos),0,x,y); }
  142. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1) { WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1); }
  143. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  144. #define clif_setlevel(lv) (lv<battle_config.max_lv?lv:battle_config.max_lv-(lv<battle_config.aura_lv?1:0));
  145. static char map_ip_str[16];
  146. static in_addr_t map_ip;
  147. static in_addr_t bind_ip = INADDR_ANY;
  148. static int map_port = 5121;
  149. int map_fd;
  150. char talkie_mes[MESSAGE_SIZE];
  151. //These two will be used to verify the incoming player's validity.
  152. //It helps identify their client packet version correctly. [Skotlex]
  153. static int max_account_id = DEFAULT_MAX_ACCOUNT_ID;
  154. static int max_char_id = DEFAULT_MAX_CHAR_ID;
  155. int clif_parse (int fd);
  156. static void clif_hpmeter_single(int fd, struct map_session_data *sd);
  157. /*==========================================
  158. * map鯖のip設定
  159. *------------------------------------------
  160. */
  161. void clif_setip(char *ip)
  162. {
  163. memcpy(map_ip_str, ip, 16);
  164. map_ip = inet_addr(map_ip_str);
  165. }
  166. void clif_setbindip(char *ip)
  167. {
  168. bind_ip = inet_addr(ip);
  169. }
  170. /*==========================================
  171. * map鯖のport設定
  172. *------------------------------------------
  173. */
  174. void clif_setport(int port)
  175. {
  176. map_port = port;
  177. }
  178. /*==========================================
  179. * map鯖のip読み出し
  180. *------------------------------------------
  181. */
  182. in_addr_t clif_getip(void)
  183. {
  184. return map_ip;
  185. }
  186. /*==========================================
  187. * map鯖のport読み出し
  188. *------------------------------------------
  189. */
  190. int clif_getport(void)
  191. {
  192. return map_port;
  193. }
  194. /*==========================================
  195. * Counts connected players.
  196. *------------------------------------------
  197. */
  198. int clif_countusers(void)
  199. {
  200. int users = 0, i;
  201. struct map_session_data *sd;
  202. for(i = 0; i < fd_max; i++) {
  203. if (session[i] && (sd = (struct map_session_data*)session[i]->session_data) && sd->state.auth &&
  204. !(battle_config.hide_GM_session && pc_isGM(sd)))
  205. users++;
  206. }
  207. return users;
  208. }
  209. /*==========================================
  210. * 全てのclientに対してfunc()実行
  211. *------------------------------------------
  212. */
  213. int clif_foreachclient(int (*func)(struct map_session_data*, va_list),...) //recoded by sasuke, bug when player count gets higher [Kevin]
  214. {
  215. int i;
  216. va_list ap;
  217. struct map_session_data *sd;
  218. va_start(ap,func);
  219. for(i = 0; i < fd_max; i++) {
  220. if ( session[i] ) {
  221. sd = (struct map_session_data*)session[i]->session_data;
  222. if ( sd && session[i]->func_parse == clif_parse &&
  223. sd->state.auth && !sd->state.waitingdisconnect )
  224. func(sd, ap);
  225. }
  226. }
  227. va_end(ap);
  228. return 0;
  229. }
  230. /*==========================================
  231. * clif_sendでAREA*指定時用
  232. *------------------------------------------
  233. */
  234. int clif_send_sub(struct block_list *bl, va_list ap)
  235. {
  236. struct block_list *src_bl;
  237. struct map_session_data *sd;
  238. unsigned char *buf;
  239. int len, type;
  240. nullpo_retr(0, bl);
  241. nullpo_retr(0, ap);
  242. nullpo_retr(0, sd = (struct map_session_data *)bl);
  243. if (!sd->fd) //Avoid attempting to send to disconnected chars (may prevent buffer overrun errors?) [Skotlex]
  244. return 0;
  245. buf = va_arg(ap,unsigned char*);
  246. len = va_arg(ap,int);
  247. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  248. type = va_arg(ap,int);
  249. switch(type) {
  250. case AREA_WOS:
  251. if (bl == src_bl)
  252. return 0;
  253. break;
  254. case AREA_WOC:
  255. if (sd->chatID || bl == src_bl)
  256. return 0;
  257. break;
  258. case AREA_WOSC:
  259. {
  260. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  261. if ((ssd != 0) && (src_bl->type == BL_PC) && (sd->chatID != 0) && (sd->chatID == ssd->chatID))
  262. return 0;
  263. }
  264. break;
  265. }
  266. if (session[sd->fd] != NULL) {
  267. WFIFOHEAD(sd->fd, len);
  268. if (WFIFOP(sd->fd,0) == buf) {
  269. printf("WARNING: Invalid use of clif_send function\n");
  270. printf(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  271. printf(" Please correct your code.\n");
  272. // don't send to not move the pointer of the packet for next sessions in the loop
  273. } else {
  274. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  275. memcpy(WFIFOP(sd->fd,0), buf, len);
  276. //Check if hidden, better to modify the char's buffer than the
  277. //given buffer to prevent intravision affecting the packet as
  278. //it's being received by everyone. [Skotlex]
  279. if ((sd->special_state.intravision || sd->sc.data[SC_INTRAVISION].timer != -1 ) && bl != src_bl) {
  280. struct status_change *sc = status_get_sc(src_bl);
  281. if(sc && (sc->option)&(OPTION_HIDE|OPTION_CLOAK))
  282. { //optionの修正
  283. switch(((unsigned short*)buf)[0])
  284. {
  285. case 0x119:
  286. WFIFOW(sd->fd,10) &= ~(OPTION_HIDE|OPTION_CLOAK);
  287. break;
  288. #if PACKETVER < 4
  289. case 0x78:
  290. #else
  291. case 0x1da:
  292. #endif
  293. case 0x7b:
  294. case 0x7c:
  295. case 0x1d8:
  296. WFIFOW(sd->fd,12) &=~(OPTION_HIDE|OPTION_CLOAK);
  297. break;
  298. }
  299. }
  300. }
  301. WFIFOSET(sd->fd,len);
  302. }
  303. }
  304. }
  305. return 0;
  306. }
  307. /*==========================================
  308. *
  309. *------------------------------------------
  310. */
  311. int clif_send (unsigned char *buf, int len, struct block_list *bl, int type) {
  312. int i;
  313. struct map_session_data *sd = NULL;
  314. struct party *p = NULL;
  315. struct guild *g = NULL;
  316. int x0 = 0, x1 = 0, y0 = 0, y1 = 0;
  317. if (type != ALL_CLIENT &&
  318. type != CHAT_MAINCHAT) {
  319. nullpo_retr(0, bl);
  320. if (bl->type == BL_PC) {
  321. sd = (struct map_session_data *)bl;
  322. }
  323. }
  324. switch(type) {
  325. case ALL_CLIENT: // 全クライアントに送信
  326. for (i = 0; i < fd_max; i++) {
  327. if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) != NULL && sd->state.auth) {
  328. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  329. WFIFOHEAD(i, len);
  330. memcpy(WFIFOP(i,0), buf, len);
  331. WFIFOSET(i,len);
  332. }
  333. }
  334. }
  335. break;
  336. case ALL_SAMEMAP: // 同じマップの全クライアントに送信
  337. for(i = 0; i < fd_max; i++) {
  338. if (session[i] && (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  339. sd->state.auth && sd->bl.m == bl->m) {
  340. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  341. WFIFOHEAD(i,len);
  342. memcpy(WFIFOP(i,0), buf, len);
  343. WFIFOSET(i,len);
  344. }
  345. }
  346. }
  347. break;
  348. case AREA:
  349. case AREA_WOS:
  350. case AREA_WOC:
  351. case AREA_WOSC:
  352. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  353. BL_PC, buf, len, bl, type);
  354. break;
  355. case AREA_CHAT_WOC:
  356. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  357. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  358. break;
  359. case CHAT:
  360. case CHAT_WOS:
  361. {
  362. struct chat_data *cd;
  363. if (sd) {
  364. cd = (struct chat_data*)map_id2bl(sd->chatID);
  365. } else if (bl->type == BL_CHAT) {
  366. cd = (struct chat_data*)bl;
  367. } else break;
  368. if (cd == NULL)
  369. break;
  370. for(i = 0; i < cd->users; i++) {
  371. if (type == CHAT_WOS && cd->usersd[i] == sd)
  372. continue;
  373. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  374. if (cd->usersd[i]->fd >0 && session[cd->usersd[i]->fd]) // Added check to see if session exists [PoW]
  375. {
  376. WFIFOHEAD(cd->usersd[i]->fd,len);
  377. memcpy(WFIFOP(cd->usersd[i]->fd,0), buf, len);
  378. WFIFOSET(cd->usersd[i]->fd,len);
  379. }
  380. }
  381. }
  382. }
  383. break;
  384. case CHAT_MAINCHAT: //[LuzZza]
  385. for(i=1; i<fd_max; i++) {
  386. if(session[i] && (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  387. sd->state.mainchat && sd->fd) {
  388. WFIFOHEAD(sd->fd, len);
  389. memcpy(WFIFOP(sd->fd,0), buf, len);
  390. WFIFOSET(sd->fd, len);
  391. }
  392. }
  393. break;
  394. case PARTY_AREA: // 同じ画面内の全パーティーメンバに送信
  395. case PARTY_AREA_WOS: // 自分以外の同じ画面内の全パーティーメンバに送信
  396. x0 = bl->x - AREA_SIZE;
  397. y0 = bl->y - AREA_SIZE;
  398. x1 = bl->x + AREA_SIZE;
  399. y1 = bl->y + AREA_SIZE;
  400. case PARTY: // 全パーティーメンバに送信
  401. case PARTY_WOS: // 自分以外の全パーティーメンバに送信
  402. case PARTY_SAMEMAP: // 同じマップの全パーティーメンバに送信
  403. case PARTY_SAMEMAP_WOS: // 自分以外の同じマップの全パーティーメンバに送信
  404. if (sd && sd->status.party_id)
  405. p = party_search(sd->status.party_id);
  406. if (p) {
  407. for(i=0;i<MAX_PARTY;i++){
  408. if ((sd = p->member[i].sd) != NULL) {
  409. if (!sd->fd || session[sd->fd] == NULL || sd->state.auth == 0
  410. || session[sd->fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  411. continue;
  412. if (sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS))
  413. continue;
  414. if (type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m) // マップチェック
  415. continue;
  416. if ((type == PARTY_AREA || type == PARTY_AREA_WOS) &&
  417. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  418. continue;
  419. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  420. WFIFOHEAD(sd->fd,len);
  421. memcpy(WFIFOP(sd->fd,0), buf, len);
  422. WFIFOSET(sd->fd,len);
  423. }
  424. }
  425. }
  426. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  427. break;
  428. for (i = 1; i < fd_max; i++){ // partyspy [Syrus22]
  429. if (session[i] && (sd = (struct map_session_data*)session[i]->session_data) != NULL && sd->state.auth && sd->fd && sd->partyspy) {
  430. if (sd->partyspy == p->party_id) {
  431. if (sd->fd && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  432. WFIFOHEAD(sd->fd,len);
  433. memcpy(WFIFOP(sd->fd,0), buf, len);
  434. WFIFOSET(sd->fd,len);
  435. }
  436. }
  437. }
  438. }
  439. }
  440. break;
  441. case SELF:
  442. if (sd && sd->fd && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  443. WFIFOHEAD(sd->fd,len);
  444. memcpy(WFIFOP(sd->fd,0), buf, len);
  445. WFIFOSET(sd->fd,len);
  446. }
  447. break;
  448. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  449. case GUILD_AREA:
  450. case GUILD_AREA_WOS:
  451. x0 = bl->x - AREA_SIZE;
  452. y0 = bl->y - AREA_SIZE;
  453. x1 = bl->x + AREA_SIZE;
  454. y1 = bl->y + AREA_SIZE;
  455. case GUILD_SAMEMAP:
  456. case GUILD_SAMEMAP_WOS:
  457. case GUILD:
  458. case GUILD_WOS:
  459. if (sd && sd->status.guild_id)
  460. g = guild_search(sd->status.guild_id);
  461. if (g) {
  462. for(i = 0; i < g->max_member; i++) {
  463. if ((sd = g->member[i].sd) != NULL) {
  464. if (!sd->fd || session[sd->fd] == NULL || sd->state.auth == 0
  465. || session[sd->fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  466. continue;
  467. if (sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS))
  468. continue;
  469. if (type != GUILD && type != GUILD_WOS && sd->bl.m != bl->m)
  470. continue;
  471. if ((type == GUILD_AREA || type == GUILD_AREA_WOS) &&
  472. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  473. continue;
  474. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  475. WFIFOHEAD(sd->fd,len);
  476. memcpy(WFIFOP(sd->fd,0), buf, len);
  477. WFIFOSET(sd->fd,len);
  478. }
  479. }
  480. }
  481. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  482. break;
  483. for (i = 1; i < fd_max; i++){ // guildspy [Syrus22]
  484. if (session[i] && (sd = (struct map_session_data*)session[i]->session_data) != NULL && sd->state.auth && sd->fd && sd->guildspy) {
  485. if (sd->guildspy == g->guild_id) {
  486. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  487. WFIFOHEAD(sd->fd,len);
  488. memcpy(WFIFOP(sd->fd,0), buf, len);
  489. WFIFOSET(sd->fd,len);
  490. }
  491. }
  492. }
  493. }
  494. }
  495. break;
  496. /* End [Valaris] */
  497. default:
  498. if (battle_config.error_log)
  499. ShowError("clif_send: Unrecognized type %d\n",type);
  500. return -1;
  501. }
  502. return 0;
  503. }
  504. //
  505. // パケット作って送信
  506. //
  507. /*==========================================
  508. *
  509. *------------------------------------------
  510. */
  511. int clif_authok(struct map_session_data *sd) {
  512. int fd;
  513. if (!sd->fd)
  514. return 0;
  515. fd = sd->fd;
  516. WFIFOHEAD(fd, packet_len_table[0x73]);
  517. WFIFOW(fd, 0) = 0x73;
  518. WFIFOL(fd, 2) = gettick();
  519. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y);
  520. WFIFOB(fd, 9) = 5;
  521. WFIFOB(fd,10) = 5;
  522. WFIFOSET(fd,packet_len_table[0x73]);
  523. return 0;
  524. }
  525. /*==========================================
  526. *
  527. *------------------------------------------
  528. */
  529. int clif_authfail_fd(int fd, int type) {
  530. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  531. return 0;
  532. WFIFOHEAD(fd, packet_len_table[0x81]);
  533. WFIFOW(fd,0) = 0x81;
  534. WFIFOB(fd,2) = type;
  535. WFIFOSET(fd,packet_len_table[0x81]);
  536. clif_setwaitclose(fd);
  537. return 0;
  538. }
  539. /*==========================================
  540. * Used to know which is the max valid account/char id [Skotlex]
  541. *------------------------------------------
  542. */
  543. void clif_updatemaxid(int account_id, int char_id)
  544. {
  545. max_account_id = account_id;
  546. max_char_id = char_id;
  547. }
  548. /*==========================================
  549. *
  550. *------------------------------------------
  551. */
  552. int clif_charselectok(int id) {
  553. struct map_session_data *sd;
  554. int fd;
  555. if ((sd = map_id2sd(id)) == NULL)
  556. return 1;
  557. if (!sd->fd)
  558. return 1;
  559. fd = sd->fd;
  560. WFIFOHEAD(fd, packet_len_table[0xb3]);
  561. WFIFOW(fd,0) = 0xb3;
  562. WFIFOB(fd,2) = 1;
  563. WFIFOSET(fd,packet_len_table[0xb3]);
  564. return 0;
  565. }
  566. /*==========================================
  567. *
  568. *------------------------------------------
  569. */
  570. static int clif_set009e(struct flooritem_data *fitem,unsigned char *buf) {
  571. int view;
  572. nullpo_retr(0, fitem);
  573. //009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  574. WBUFW(buf, 0) = 0x9e;
  575. WBUFL(buf, 2) = fitem->bl.id;
  576. if ((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  577. WBUFW(buf, 6) = view;
  578. else
  579. WBUFW(buf, 6) = fitem->item_data.nameid;
  580. WBUFB(buf, 8) = fitem->item_data.identify;
  581. WBUFW(buf, 9) = fitem->bl.x;
  582. WBUFW(buf,11) = fitem->bl.y;
  583. WBUFB(buf,13) = fitem->subx;
  584. WBUFB(buf,14) = fitem->suby;
  585. WBUFW(buf,15) = fitem->item_data.amount;
  586. return packet_len_table[0x9e];
  587. }
  588. /*==========================================
  589. *
  590. *------------------------------------------
  591. */
  592. int clif_dropflooritem(struct flooritem_data *fitem) {
  593. unsigned char buf[64];
  594. nullpo_retr(0, fitem);
  595. if (fitem->item_data.nameid <= 0)
  596. return 0;
  597. clif_set009e(fitem, buf);
  598. clif_send(buf, packet_len_table[0x9e], &fitem->bl, AREA);
  599. return 0;
  600. }
  601. /*==========================================
  602. *
  603. *------------------------------------------
  604. */
  605. int clif_clearflooritem(struct flooritem_data *fitem, int fd) {
  606. unsigned char buf[16];
  607. nullpo_retr(0, fitem);
  608. WBUFW(buf,0) = 0xa1;
  609. WBUFL(buf,2) = fitem->bl.id;
  610. if (fd == 0) {
  611. clif_send(buf, packet_len_table[0xa1], &fitem->bl, AREA);
  612. } else {
  613. WFIFOHEAD(fd,packet_len_table[0xa1]);
  614. memcpy(WFIFOP(fd,0), buf, 6);
  615. WFIFOSET(fd,packet_len_table[0xa1]);
  616. }
  617. return 0;
  618. }
  619. /*==========================================
  620. *
  621. *------------------------------------------
  622. */
  623. int clif_clearchar(struct block_list *bl, int type) {
  624. unsigned char buf[16];
  625. nullpo_retr(0, bl);
  626. WBUFW(buf,0) = 0x80;
  627. WBUFL(buf,2) = bl->id;
  628. WBUFB(buf,6) = type;
  629. clif_send(buf, packet_len_table[0x80], bl, type == 1 ? AREA : AREA_WOS);
  630. if(bl->type==BL_PC && ((struct map_session_data *)bl)->disguise) {
  631. WBUFL(buf,2) = -bl->id;
  632. clif_send(buf, packet_len_table[0x80], bl, AREA);
  633. }
  634. return 0;
  635. }
  636. static int clif_clearchar_delay_sub(int tid, unsigned int tick, int id, int data) {
  637. struct block_list *bl = (struct block_list *)id;
  638. clif_clearchar(bl,data);
  639. aFree(bl);
  640. return 0;
  641. }
  642. int clif_clearchar_delay(unsigned int tick, struct block_list *bl, int type) {
  643. struct block_list *tbl;
  644. tbl = aCalloc(1, sizeof (struct block_list));
  645. memcpy (tbl, bl, sizeof (struct block_list));
  646. add_timer(tick, clif_clearchar_delay_sub, (int)tbl, type);
  647. return 0;
  648. }
  649. /*==========================================
  650. *
  651. *------------------------------------------
  652. */
  653. int clif_clearchar_id(int id, int type, int fd) {
  654. unsigned char buf[16];
  655. WBUFW(buf,0) = 0x80;
  656. WBUFL(buf,2) = id;
  657. WBUFB(buf,6) = type;
  658. WFIFOHEAD(fd, packet_len_table[0x80]);
  659. memcpy(WFIFOP(fd,0), buf, 7);
  660. WFIFOSET(fd, packet_len_table[0x80]);
  661. return 0;
  662. }
  663. //Small define to specify the weapon view sprite, makes code easier to read down below... [Skotlex]
  664. #define clif_weapon_viewid(sd, n) ((sd->equip_index[n] >= 0 && sd->inventory_data[sd->equip_index[n]])?(\
  665. (sd->inventory_data[sd->equip_index[n]]->view_id > 0)?sd->inventory_data[sd->equip_index[n]]->view_id: \
  666. sd->status.inventory[sd->equip_index[n]].nameid):0)
  667. #define clif_deadsit(sd) (((sd)->sc.count && (sd)->sc.data[SC_TRICKDEAD].timer != -1)?1:sd->state.dead_sit)
  668. /*==========================================
  669. *
  670. *------------------------------------------
  671. */
  672. static int clif_set0078(struct map_session_data *sd, unsigned char *buf) {
  673. int sdoption;
  674. nullpo_retr(0, sd);
  675. // Disable showing Falcon when player is hide [LuzZza]
  676. if(sd->disguise)
  677. sdoption = OPTION_INVISIBLE;
  678. else {
  679. sdoption = sd->sc.option;
  680. if(sdoption&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE))
  681. sdoption &= ~OPTION_FALCON;
  682. }
  683. #if PACKETVER < 4
  684. memset(buf,0,packet_len_table[0x78]);
  685. WBUFW(buf,0)=0x78;
  686. WBUFL(buf,2)=sd->bl.id;
  687. WBUFW(buf,6)=sd->speed;
  688. WBUFW(buf,8)=sd->sc.opt1;
  689. WBUFW(buf,10)=sd->sc.opt2;
  690. WBUFW(buf,12)=sdoption;
  691. WBUFW(buf,14)=sd->view_class;
  692. WBUFW(buf,16)=sd->status.hair;
  693. if (sd->view_class != JOB_WEDDING && sd->view_class !=JOB_XMAS)
  694. WBUFW(buf,18) = sd->status.weapon;
  695. else
  696. WBUFW(buf,18)=0;
  697. WBUFW(buf,20)=sd->status.head_bottom;
  698. WBUFW(buf,22)=sd->status.shield;
  699. WBUFW(buf,24)=sd->status.head_top;
  700. WBUFW(buf,26)=sd->status.head_mid;
  701. WBUFW(buf,28)=sd->status.hair_color;
  702. WBUFW(buf,30)=sd->status.clothes_color;
  703. WBUFW(buf,32)=sd->head_dir;
  704. WBUFL(buf,34)=sd->status.guild_id;
  705. WBUFL(buf,38)=sd->guild_emblem_id;
  706. WBUFW(buf,42)=sd->status.manner;
  707. WBUFB(buf,44)=sd->status.karma;
  708. WBUFB(buf,45)=sd->sex;
  709. WBUFPOS(buf,46,sd->bl.x,sd->bl.y);
  710. WBUFB(buf,48)|=sd->dir&0x0f;
  711. WBUFB(buf,49)=5;
  712. WBUFB(buf,50)=5;
  713. WBUFB(buf,51)=clif_deadsit(sd);
  714. WBUFW(buf,52)=clif_setlevel(sd->status.base_level);
  715. return packet_len_table[0x78];
  716. #else
  717. memset(buf,0,packet_len_table[0x1d8]);
  718. WBUFW(buf,0)=0x1d8;
  719. WBUFL(buf,2)=sd->bl.id;
  720. WBUFW(buf,6)=sd->speed;
  721. WBUFW(buf,8)=sd->sc.opt1;
  722. WBUFW(buf,10)=sd->sc.opt2;
  723. WBUFW(buf,12)=sdoption;
  724. WBUFW(buf,14)=sd->view_class;
  725. WBUFW(buf,16)=sd->status.hair;
  726. if (sd->view_class != JOB_WEDDING && sd->view_class !=JOB_XMAS)
  727. WBUFW(buf,18) = clif_weapon_viewid(sd,9);
  728. else
  729. WBUFW(buf,18) = 0;
  730. if (sd->equip_index[8] != sd->equip_index[9] && sd->view_class != JOB_WEDDING && sd->view_class != JOB_XMAS)
  731. WBUFW(buf,20) = clif_weapon_viewid(sd,8);
  732. else
  733. WBUFW(buf,20) = 0;
  734. WBUFW(buf,22)=sd->status.head_bottom;
  735. WBUFW(buf,24)=sd->status.head_top;
  736. WBUFW(buf,26)=sd->status.head_mid;
  737. WBUFW(buf,28)=sd->status.hair_color;
  738. WBUFW(buf,30)=sd->status.clothes_color;
  739. WBUFW(buf,32)=sd->head_dir;
  740. WBUFL(buf,34)=sd->status.guild_id;
  741. WBUFW(buf,38)=sd->guild_emblem_id;
  742. WBUFW(buf,40)=sd->status.manner;
  743. WBUFW(buf,42)=sd->sc.opt3;
  744. WBUFB(buf,44)=sd->status.karma;
  745. WBUFB(buf,45)=sd->sex;
  746. WBUFPOS(buf,46,sd->bl.x,sd->bl.y);
  747. WBUFB(buf,48)|=sd->dir & 0x0f;
  748. WBUFB(buf,49)=5;
  749. WBUFB(buf,50)=5;
  750. WBUFB(buf,51)=clif_deadsit(sd);
  751. WBUFW(buf,52)=clif_setlevel(sd->status.base_level);
  752. return packet_len_table[0x1d8];
  753. #endif
  754. }
  755. // non-moving function for disguises [Valaris]
  756. static int clif_dis0078(struct map_session_data *sd, unsigned char *buf) {
  757. nullpo_retr(0, sd);
  758. memset(buf,0,packet_len_table[0x78]);
  759. WBUFW(buf,0)=0x78;
  760. WBUFL(buf,2)=-sd->bl.id;
  761. WBUFW(buf,6)=sd->speed;
  762. WBUFW(buf,8)=0;
  763. WBUFW(buf,10)=0;
  764. WBUFW(buf,12)=sd->sc.option;
  765. WBUFW(buf,14)=sd->disguise;
  766. //WBUFL(buf,34)=sd->status.guild_id;
  767. //WBUFL(buf,38)=sd->guild_emblem_id;
  768. WBUFW(buf,42)=0;
  769. WBUFB(buf,44)=0;
  770. WBUFPOS(buf,46,sd->bl.x,sd->bl.y);
  771. WBUFB(buf,48)|=sd->dir&0x0f;
  772. WBUFB(buf,49)=5;
  773. WBUFB(buf,50)=5;
  774. WBUFB(buf,51)=clif_deadsit(sd);
  775. WBUFW(buf,52)=0;
  776. return packet_len_table[0x78];
  777. }
  778. /*==========================================
  779. *
  780. *------------------------------------------
  781. */
  782. static int clif_set007b(struct map_session_data *sd,unsigned char *buf) {
  783. int sdoption;
  784. nullpo_retr(0, sd);
  785. // Disable showing Falcon when player is hide [LuzZza]
  786. if(sd->disguise)
  787. sdoption = OPTION_INVISIBLE;
  788. else {
  789. sdoption = sd->sc.option;
  790. if(sdoption&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE))
  791. sdoption &= ~OPTION_FALCON;
  792. }
  793. #if PACKETVER < 4
  794. memset(buf,0,packet_len_table[0x7b]);
  795. WBUFW(buf,0)=0x7b;
  796. WBUFL(buf,2)=sd->bl.id;
  797. WBUFW(buf,6)=sd->speed;
  798. WBUFW(buf,8)=sd->sc.opt1;
  799. WBUFW(buf,10)=sd->sc.opt2;
  800. WBUFW(buf,12)=sdoption;
  801. WBUFW(buf,14)=sd->view_class;
  802. WBUFW(buf,16)=sd->status.hair;
  803. if(sd->view_class != JOB_WEDDING && sd->view_class != JOB_XMAS)
  804. WBUFW(buf,18)=sd->status.weapon;
  805. else
  806. WBUFW(buf,18)=0;
  807. WBUFW(buf,20)=sd->status.head_bottom;
  808. WBUFL(buf,22)=gettick();
  809. WBUFW(buf,26)=sd->status.shield;
  810. WBUFW(buf,28)=sd->status.head_top;
  811. WBUFW(buf,30)=sd->status.head_mid;
  812. WBUFW(buf,32)=sd->status.hair_color;
  813. WBUFW(buf,34)=sd->status.clothes_color;
  814. WBUFW(buf,36)=sd->head_dir;
  815. WBUFL(buf,38)=sd->status.guild_id;
  816. WBUFL(buf,42)=sd->guild_emblem_id;
  817. WBUFW(buf,46)=sd->sc.opt3;
  818. WBUFB(buf,48)=sd->status.karma;
  819. WBUFB(buf,49)=sd->sex;
  820. WBUFPOS2(buf,50,sd->bl.x,sd->bl.y,sd->to_x,sd->to_y);
  821. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  822. WBUFB(buf,56)=5;
  823. WBUFB(buf,57)=5;
  824. WBUFW(buf,58)=clif_setlevel(sd->status.base_level);
  825. return packet_len_table[0x7b];
  826. #else
  827. memset(buf,0,packet_len_table[0x1da]);
  828. WBUFW(buf,0)=0x1da;
  829. WBUFL(buf,2)=sd->bl.id;
  830. WBUFW(buf,6)=sd->speed;
  831. WBUFW(buf,8)=sd->sc.opt1;
  832. WBUFW(buf,10)=sd->sc.opt2;
  833. WBUFW(buf,12)=sdoption;
  834. WBUFW(buf,14)=sd->view_class;
  835. WBUFW(buf,16)=sd->status.hair;
  836. if(sd->view_class != JOB_WEDDING && sd->view_class != JOB_XMAS)
  837. WBUFW(buf,18)= clif_weapon_viewid(sd, 9);
  838. else
  839. WBUFW(buf,18)=0;
  840. if(sd->equip_index[8] != sd->equip_index[9] && sd->view_class != JOB_WEDDING && sd->view_class != JOB_XMAS)
  841. WBUFW(buf,20)= clif_weapon_viewid(sd, 8);
  842. else
  843. WBUFW(buf,20)=0;
  844. WBUFW(buf,22)=sd->status.head_bottom;
  845. WBUFL(buf,24)=gettick();
  846. WBUFW(buf,28)=sd->status.head_top;
  847. WBUFW(buf,30)=sd->status.head_mid;
  848. WBUFW(buf,32)=sd->status.hair_color;
  849. WBUFW(buf,34)=sd->status.clothes_color;
  850. WBUFW(buf,36)=sd->head_dir;
  851. WBUFL(buf,38)=sd->status.guild_id;
  852. WBUFW(buf,42)=sd->guild_emblem_id;
  853. WBUFW(buf,44)=sd->status.manner;
  854. WBUFW(buf,46)=sd->sc.opt3;
  855. WBUFB(buf,48)=sd->status.karma;
  856. WBUFB(buf,49)=sd->sex;
  857. WBUFPOS2(buf,50,sd->bl.x,sd->bl.y,sd->to_x,sd->to_y);
  858. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  859. WBUFB(buf,56)=5;
  860. WBUFB(buf,57)=5;
  861. WBUFW(buf,58)=clif_setlevel(sd->status.base_level);
  862. return packet_len_table[0x1da];
  863. #endif
  864. }
  865. // moving function for disguises [Valaris]
  866. static int clif_dis007b(struct map_session_data *sd,unsigned char *buf) {
  867. nullpo_retr(0, sd);
  868. memset(buf,0,packet_len_table[0x7b]);
  869. WBUFW(buf,0)=0x7b;
  870. WBUFL(buf,2)=-sd->bl.id;
  871. WBUFW(buf,6)=sd->speed;
  872. WBUFW(buf,8)=0;
  873. WBUFW(buf,10)=0;
  874. WBUFW(buf,12)=sd->sc.option;
  875. WBUFW(buf,14)=sd->disguise;
  876. WBUFL(buf,22)=gettick();
  877. //WBUFL(buf,38)=sd->status.guild_id;
  878. //WBUFL(buf,42)=sd->guild_emblem_id;
  879. WBUFPOS2(buf,50,sd->bl.x,sd->bl.y,sd->to_x,sd->to_y);
  880. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  881. WBUFB(buf,56)=5;
  882. WBUFB(buf,57)=5;
  883. WBUFW(buf,58)=0;
  884. return packet_len_table[0x7b];
  885. }
  886. /*==========================================
  887. * クラスチェンジ typeはMobの場合は1で他は0?
  888. *------------------------------------------
  889. */
  890. int clif_class_change(struct block_list *bl,int class_,int type)
  891. {
  892. unsigned char buf[16];
  893. nullpo_retr(0, bl);
  894. if(class_ >= MAX_PC_CLASS) {
  895. WBUFW(buf,0)=0x1b0;
  896. WBUFL(buf,2)=bl->id;
  897. WBUFB(buf,6)=type;
  898. WBUFL(buf,7)=class_;
  899. clif_send(buf,packet_len_table[0x1b0],bl,AREA);
  900. }
  901. return 0;
  902. }
  903. /*==========================================
  904. *
  905. *------------------------------------------
  906. */
  907. int clif_mob_class_change(struct mob_data *md, int class_) {
  908. unsigned char buf[16];
  909. int view = mob_get_viewclass(class_);
  910. nullpo_retr(0, md);
  911. if(view >= MAX_PC_CLASS) {
  912. WBUFW(buf,0)=0x1b0;
  913. WBUFL(buf,2)=md->bl.id;
  914. WBUFB(buf,6)=1;
  915. WBUFL(buf,7)=view;
  916. clif_send(buf,packet_len_table[0x1b0],&md->bl,AREA);
  917. }
  918. return 0;
  919. }
  920. // mob equipment [Valaris]
  921. int clif_mob_equip(struct mob_data *md, int nameid) {
  922. unsigned char buf[16];
  923. nullpo_retr(0, md);
  924. memset(buf,0,packet_len_table[0x1a4]);
  925. WBUFW(buf,0)=0x1a4;
  926. WBUFB(buf,2)=3;
  927. WBUFL(buf,3)=md->bl.id;
  928. WBUFL(buf,7)=nameid;
  929. clif_send(buf,packet_len_table[0x1a4],&md->bl,AREA);
  930. return 0;
  931. }
  932. /*==========================================
  933. * MOB表示1
  934. *------------------------------------------
  935. */
  936. static int clif_mob0078(struct mob_data *md, unsigned char *buf)
  937. {
  938. int level, view_class;
  939. nullpo_retr(0, md);
  940. level=status_get_lv(&md->bl);
  941. view_class = mob_get_viewclass(md->class_);
  942. if(pcdb_checkid(view_class)) {
  943. #if PACKETVER < 4
  944. memset(buf,0,packet_len_table[0x78]);
  945. WBUFW(buf,0)=0x78;
  946. WBUFL(buf,2)=md->bl.id;
  947. WBUFW(buf,6)=status_get_speed(&md->bl);
  948. WBUFW(buf,8)=md->sc.opt1;
  949. WBUFW(buf,10)=md->sc.opt2;
  950. WBUFW(buf,12)=md->sc.option;
  951. WBUFW(buf,14)=view_class;
  952. WBUFW(buf,16)=mob_get_hair(md->class_);
  953. WBUFW(buf,18)=mob_get_weapon(md->class_);
  954. WBUFW(buf,20)=mob_get_head_buttom(md->class_);
  955. WBUFW(buf,22)=mob_get_shield(md->class_);
  956. WBUFW(buf,24)=mob_get_head_top(md->class_);
  957. WBUFW(buf,26)=mob_get_head_mid(md->class_);
  958. WBUFW(buf,28)=mob_get_hair_color(md->class_);
  959. WBUFW(buf,30)=mob_get_clothes_color(md->class_);
  960. WBUFW(buf,32)|=md->dir&0x0f; // head direction
  961. if (md->guardian_data && md->guardian_data->guild_id) { // Added guardian emblems [Valaris]
  962. WBUFL(buf,34)=md->guardian_data->guild_id;
  963. WBUFL(buf,38)=md->guardian_data->emblem_id;
  964. }
  965. WBUFW(buf,42)=md->sc.opt3;
  966. WBUFB(buf,44)=0; // karma
  967. WBUFB(buf,45)=mob_get_sex(md->class_);
  968. WBUFPOS(buf,46,md->bl.x,md->bl.y);
  969. WBUFB(buf,48)|=md->dir&0x0f;
  970. WBUFB(buf,49)=5;
  971. WBUFB(buf,50)=5;
  972. WBUFB(buf,51)=0; // dead or sit state
  973. WBUFW(buf,52)=clif_setlevel(level);
  974. return packet_len_table[0x78];
  975. #else
  976. // Use 0x1d8 packet for monsters with player sprites [Valaris]
  977. memset(buf,0,packet_len_table[0x1d8]);
  978. WBUFW(buf,0)=0x1d8;
  979. WBUFL(buf,2)=md->bl.id;
  980. WBUFW(buf,6)=status_get_speed(&md->bl);
  981. WBUFW(buf,8)=md->sc.opt1;
  982. WBUFW(buf,10)=md->sc.opt2;
  983. WBUFW(buf,12)=md->sc.option;
  984. WBUFW(buf,14)=view_class;
  985. WBUFW(buf,16)=mob_get_hair(md->class_);
  986. WBUFW(buf,18)=mob_get_weapon(md->class_);
  987. WBUFW(buf,20)=mob_get_shield(md->class_);
  988. WBUFW(buf,22)=mob_get_head_buttom(md->class_);
  989. WBUFW(buf,24)=mob_get_head_top(md->class_);
  990. WBUFW(buf,26)=mob_get_head_mid(md->class_);
  991. WBUFW(buf,28)=mob_get_hair_color(md->class_);
  992. WBUFW(buf,30)=mob_get_clothes_color(md->class_);
  993. WBUFW(buf,32)|=md->dir&0x0f; // head direction
  994. WBUFL(buf,34)=0; // guild id
  995. WBUFW(buf,38)=0; // emblem id
  996. WBUFW(buf,40)=0; // manner
  997. WBUFW(buf,42)=md->sc.opt3;
  998. WBUFB(buf,44)=0; // karma
  999. WBUFB(buf,45)=mob_get_sex(md->class_);
  1000. WBUFPOS(buf,46,md->bl.x,md->bl.y);
  1001. WBUFB(buf,48)|=md->dir&0x0f;
  1002. WBUFB(buf,49)=5;
  1003. WBUFB(buf,50)=5;
  1004. WBUFB(buf,51)=0; // dead or sit state
  1005. WBUFW(buf,52)=clif_setlevel(level);
  1006. return packet_len_table[0x1d8];
  1007. #endif
  1008. } else {
  1009. // Use 0x78 packet for monsters sprites [Valaris]
  1010. memset(buf,0,packet_len_table[0x78]);
  1011. WBUFW(buf,0)=0x78;
  1012. WBUFL(buf,2)=md->bl.id;
  1013. WBUFW(buf,6)=status_get_speed(&md->bl);
  1014. WBUFW(buf,8)=md->sc.opt1;
  1015. WBUFW(buf,10)=md->sc.opt2;
  1016. WBUFW(buf,12)=md->sc.option;
  1017. WBUFW(buf,14)=view_class;
  1018. if (md->guardian_data && md->guardian_data->guild_id) { // Added guardian emblems [Valaris]
  1019. WBUFL(buf,34)=md->guardian_data->guild_id;
  1020. WBUFL(buf,38)=md->guardian_data->emblem_id;
  1021. } // End addition
  1022. WBUFPOS(buf,46,md->bl.x,md->bl.y);
  1023. WBUFB(buf,48)|=md->dir&0x0f;
  1024. WBUFB(buf,49)=5;
  1025. WBUFB(buf,50)=5;
  1026. WBUFW(buf,52)=clif_setlevel(level);
  1027. return packet_len_table[0x78];
  1028. }
  1029. }
  1030. /*==========================================
  1031. * MOB表示2
  1032. *------------------------------------------
  1033. */
  1034. static int clif_mob007b(struct mob_data *md, unsigned char *buf) {
  1035. int level, view_class;
  1036. nullpo_retr(0, md);
  1037. level=status_get_lv(&md->bl);
  1038. view_class = mob_get_viewclass(md->class_);
  1039. if(pcdb_checkid(view_class)) {
  1040. #if PACKETVER < 4
  1041. memset(buf,0,packet_len_table[0x7b]);
  1042. WBUFW(buf,0)=0x7b;
  1043. WBUFL(buf,2)=md->bl.id;
  1044. WBUFW(buf,6)=status_get_speed(&md->bl);
  1045. WBUFW(buf,8)=md->sc.opt1;
  1046. WBUFW(buf,10)=md->sc.opt2;
  1047. WBUFW(buf,12)=md->sc.option;
  1048. WBUFW(buf,14)=view_class;
  1049. WBUFW(buf,16)=mob_get_hair(md->class_);
  1050. WBUFW(buf,18)=mob_get_weapon(md->class_);
  1051. WBUFW(buf,20)=mob_get_head_buttom(md->class_);
  1052. WBUFL(buf,22)=gettick();
  1053. WBUFW(buf,26)=mob_get_shield(md->class_);
  1054. WBUFW(buf,28)=mob_get_head_top(md->class_);
  1055. WBUFW(buf,30)=mob_get_head_mid(md->class_);
  1056. WBUFW(buf,32)=mob_get_hair_color(md->class_);
  1057. WBUFW(buf,34)=mob_get_clothes_color(md->class_);
  1058. WBUFW(buf,36)=md->dir&0x0f; // head direction
  1059. if (md->guardian_data && md->guardian_data->guild_id) { // Added guardian emblems [Valaris]
  1060. WBUFL(buf,38)=md->guardian_data->guild_id;
  1061. WBUFL(buf,42)=md->guardian_data->emblem_id;
  1062. }
  1063. WBUFW(buf,46)=md->sc.opt3;
  1064. WBUFB(buf,48)=0; // karma
  1065. WBUFB(buf,49)=mob_get_sex(md->class_);
  1066. WBUFPOS2(buf,50,md->bl.x,md->bl.y,md->to_x,md->to_y);
  1067. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1068. WBUFB(buf,56)=5;
  1069. WBUFB(buf,57)=5;
  1070. WBUFW(buf,58)=clif_setlevel(level);
  1071. return packet_len_table[0x7b];
  1072. #else
  1073. // Use 0x1da packet for monsters with player sprites [Valaris]
  1074. memset(buf,0,packet_len_table[0x1da]);
  1075. WBUFW(buf,0)=0x1da;
  1076. WBUFL(buf,2)=md->bl.id;
  1077. WBUFW(buf,6)=status_get_speed(&md->bl);
  1078. WBUFW(buf,8)=md->sc.opt1;
  1079. WBUFW(buf,10)=md->sc.opt2;
  1080. WBUFW(buf,12)=md->sc.option;
  1081. WBUFW(buf,14)=view_class;
  1082. WBUFW(buf,16)=mob_get_hair(md->class_);
  1083. WBUFW(buf,18)=mob_get_weapon(md->class_);
  1084. WBUFW(buf,20)=mob_get_shield(md->class_);
  1085. WBUFW(buf,22)=mob_get_head_buttom(md->class_);
  1086. WBUFL(buf,24)=gettick();
  1087. WBUFW(buf,28)=mob_get_head_top(md->class_);
  1088. WBUFW(buf,30)=mob_get_head_mid(md->class_);
  1089. WBUFW(buf,32)=mob_get_hair_color(md->class_);
  1090. WBUFW(buf,34)=mob_get_clothes_color(md->class_);
  1091. WBUFW(buf,36)=md->dir&0x0f; // head direction
  1092. if (md->guardian_data && md->guardian_data->guild_id) { // Added guardian emblems [Valaris]
  1093. WBUFL(buf,38)=md->guardian_data->guild_id;
  1094. WBUFW(buf,42)=md->guardian_data->emblem_id;
  1095. }
  1096. WBUFW(buf,44)=0; // manner
  1097. WBUFW(buf,46)=md->sc.opt3;
  1098. WBUFB(buf,48)=0; // karma
  1099. WBUFB(buf,49)=mob_get_sex(md->class_);
  1100. WBUFPOS2(buf,50,md->bl.x,md->bl.y,md->to_x,md->to_y);
  1101. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1102. WBUFB(buf,56)=5;
  1103. WBUFB(buf,57)=5;
  1104. WBUFW(buf,58)=clif_setlevel(level);
  1105. return packet_len_table[0x1da];
  1106. #endif
  1107. } else {
  1108. // Use 0x7b packet for monsters sprites [Valaris]
  1109. memset(buf,0,packet_len_table[0x7b]);
  1110. WBUFW(buf,0)=0x7b;
  1111. WBUFL(buf,2)=md->bl.id;
  1112. WBUFW(buf,6)=status_get_speed(&md->bl);
  1113. WBUFW(buf,8)=md->sc.opt1;
  1114. WBUFW(buf,10)=md->sc.opt2;
  1115. WBUFW(buf,12)=md->sc.option;
  1116. WBUFW(buf,14)=view_class;
  1117. WBUFL(buf,22)=gettick();
  1118. if (md->guardian_data && md->guardian_data->guild_id) { // Added guardian emblems [Valaris]
  1119. WBUFL(buf,38)=md->guardian_data->guild_id;
  1120. WBUFL(buf,42)=md->guardian_data->emblem_id;
  1121. } // End addition
  1122. WBUFPOS2(buf,50,md->bl.x,md->bl.y,md->to_x,md->to_y);
  1123. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1124. WBUFB(buf,56)=5;
  1125. WBUFB(buf,57)=5;
  1126. level = status_get_lv(&md->bl);
  1127. WBUFW(buf,58)=clif_setlevel(level);
  1128. return packet_len_table[0x7b];
  1129. }
  1130. }
  1131. /*==========================================
  1132. *
  1133. *------------------------------------------
  1134. */
  1135. static int clif_npc0078(struct npc_data *nd, unsigned char *buf) {
  1136. struct guild *g=NULL;
  1137. int view_class;
  1138. nullpo_retr(0, nd);
  1139. memset(buf,0,packet_len_table[0x78]);
  1140. if (nd->class_ == 722 && nd->u.scr.guild_id > 0)
  1141. g=guild_search(nd->u.scr.guild_id);
  1142. if(mobdb_checkid(nd->class_) &&
  1143. pcdb_checkid((view_class = mob_get_viewclass(nd->class_)))) {
  1144. //Disguised player sprite
  1145. #if PACKETVER < 4
  1146. memset(buf,0,packet_len_table[0x78]);
  1147. WBUFW(buf,0)=0x78;
  1148. WBUFL(buf,2)=nd->bl.id;
  1149. WBUFW(buf,6)=nd->speed;
  1150. WBUFW(buf,8)=nd->sc.opt1;
  1151. WBUFW(buf,10)=nd->sc.opt2;
  1152. WBUFW(buf,12)=nd->sc.option;
  1153. WBUFW(buf,14)=view_class;
  1154. WBUFW(buf,16)=mob_get_hair(nd->class_);
  1155. WBUFW(buf,18)=mob_get_weapon(nd->class_);
  1156. WBUFW(buf,20)=mob_get_head_buttom(nd->class_);
  1157. WBUFW(buf,22)=mob_get_shield(nd->class_);
  1158. WBUFW(buf,24)=mob_get_head_top(nd->class_);
  1159. WBUFW(buf,26)=mob_get_head_mid(nd->class_);
  1160. WBUFW(buf,28)=mob_get_hair_color(nd->class_);
  1161. WBUFW(buf,30)=mob_get_clothes_color(nd->class_);
  1162. WBUFW(buf,32)|=nd->dir&0x0f; // head direction
  1163. if (g) {
  1164. WBUFL(buf,34)=g->guild_id;
  1165. WBUFL(buf,38)=g->emblem_id;
  1166. }
  1167. WBUFW(buf,42)=nd->sc.opt3;
  1168. WBUFB(buf,44)=0; // karma
  1169. WBUFB(buf,45)=mob_get_sex(nd->class_);
  1170. WBUFPOS(buf,46,nd->bl.x,nd->bl.y);
  1171. WBUFB(buf,48)|=nd->dir&0x0f;
  1172. WBUFB(buf,49)=5;
  1173. WBUFB(buf,50)=5;
  1174. WBUFB(buf,51)=0; // dead or sit state
  1175. WBUFW(buf,52)=50; // No level info.
  1176. return packet_len_table[0x78];
  1177. #else
  1178. // Use 0x1d8 packet for monsters with player sprites [Valaris]
  1179. memset(buf,0,packet_len_table[0x1d8]);
  1180. WBUFW(buf,0)=0x1d8;
  1181. WBUFL(buf,2)=nd->bl.id;
  1182. WBUFW(buf,6)=nd->speed;
  1183. WBUFW(buf,8)=nd->sc.opt1;
  1184. WBUFW(buf,10)=nd->sc.opt2;
  1185. WBUFW(buf,12)=nd->sc.option;
  1186. WBUFW(buf,14)=view_class;
  1187. WBUFW(buf,16)=mob_get_hair(nd->class_);
  1188. WBUFW(buf,18)=mob_get_weapon(nd->class_);
  1189. WBUFW(buf,20)=mob_get_shield(nd->class_);
  1190. WBUFW(buf,22)=mob_get_head_buttom(nd->class_);
  1191. WBUFW(buf,24)=mob_get_head_top(nd->class_);
  1192. WBUFW(buf,26)=mob_get_head_mid(nd->class_);
  1193. WBUFW(buf,28)=mob_get_hair_color(nd->class_);
  1194. WBUFW(buf,30)=mob_get_clothes_color(nd->class_);
  1195. WBUFW(buf,32)|=nd->dir&0x0f; // head direction
  1196. WBUFL(buf,34)=0; // guild id
  1197. WBUFW(buf,38)=0; // emblem id
  1198. WBUFW(buf,40)=0; // manner
  1199. WBUFW(buf,42)=nd->sc.opt3;
  1200. WBUFB(buf,44)=0; // karma
  1201. WBUFB(buf,45)=mob_get_sex(nd->class_);
  1202. WBUFPOS(buf,46,nd->bl.x,nd->bl.y);
  1203. WBUFB(buf,48)|=nd->dir&0x0f;
  1204. WBUFB(buf,49)=5;
  1205. WBUFB(buf,50)=5;
  1206. WBUFB(buf,51)=0; // dead or sit state
  1207. WBUFW(buf,52)=50; //No level data.
  1208. return packet_len_table[0x1d8];
  1209. #endif
  1210. }
  1211. WBUFW(buf,0)=0x78;
  1212. WBUFL(buf,2)=nd->bl.id;
  1213. WBUFW(buf,6)=nd->speed;
  1214. WBUFW(buf,14)=nd->class_;
  1215. if (g) {
  1216. WBUFL(buf,22)=g->emblem_id;
  1217. WBUFL(buf,26)=g->guild_id;
  1218. // pc packet says the actual location of these are, but they are not. Why the discordance? [Skotlex]
  1219. // WBUFL(buf,34)=g->emblem_id;
  1220. // WBUFL(buf,38)=g->guild_id;
  1221. }
  1222. WBUFPOS(buf,46,nd->bl.x,nd->bl.y);
  1223. WBUFB(buf,48)|=nd->dir&0x0f;
  1224. WBUFB(buf,49)=5;
  1225. WBUFB(buf,50)=5;
  1226. return packet_len_table[0x78];
  1227. }
  1228. // NPC Walking [Valaris]
  1229. static int clif_npc007b(struct npc_data *nd, unsigned char *buf) {
  1230. struct guild *g=NULL;
  1231. int view_class;
  1232. nullpo_retr(0, nd);
  1233. memset(buf,0,packet_len_table[0x7b]);
  1234. if (nd->class_ == 722 && nd->u.scr.guild_id > 0)
  1235. g=guild_search(nd->u.scr.guild_id);
  1236. if(mobdb_checkid(nd->class_) &&
  1237. pcdb_checkid((view_class = mob_get_viewclass(nd->class_)))) {
  1238. //Disguised player sprite
  1239. #if PACKETVER < 4
  1240. memset(buf,0,packet_len_table[0x7b]);
  1241. WBUFW(buf,0)=0x7b;
  1242. WBUFL(buf,2)=nd->bl.id;
  1243. WBUFW(buf,6)=nd->speed;
  1244. WBUFW(buf,8)=nd->sc.opt1;
  1245. WBUFW(buf,10)=nd->sc.opt2;
  1246. WBUFW(buf,12)=nd->sc.option;
  1247. WBUFW(buf,14)=view_class;
  1248. WBUFW(buf,16)=mob_get_hair(nd->class_);
  1249. WBUFW(buf,18)=mob_get_weapon(nd->class_);
  1250. WBUFW(buf,20)=mob_get_head_buttom(nd->class_);
  1251. WBUFL(buf,22)=gettick();
  1252. WBUFW(buf,26)=mob_get_shield(nd->class_);
  1253. WBUFW(buf,28)=mob_get_head_top(nd->class_);
  1254. WBUFW(buf,30)=mob_get_head_mid(nd->class_);
  1255. WBUFW(buf,32)=mob_get_hair_color(nd->class_);
  1256. WBUFW(buf,34)=mob_get_clothes_color(nd->class_);
  1257. WBUFW(buf,36)=nd->dir&0x0f; // head direction
  1258. if (g) {
  1259. WBUFL(buf,38)=g->guild_id;
  1260. WBUFL(buf,42)=g->emblem_id;
  1261. }
  1262. WBUFW(buf,46)=nd->sc.opt3;
  1263. WBUFB(buf,48)=0; // karma
  1264. WBUFB(buf,49)=mob_get_sex(nd->class_);
  1265. WBUFPOS2(buf,50,nd->bl.x,nd->bl.y,nd->to_x,nd->to_y);
  1266. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1267. WBUFB(buf,56)=5;
  1268. WBUFB(buf,57)=5;
  1269. WBUFW(buf,58)=50; //Ehm.. no level data.
  1270. return packet_len_table[0x7b];
  1271. #else
  1272. // Use 0x1da packet for monsters with player sprites [Valaris]
  1273. memset(buf,0,packet_len_table[0x1da]);
  1274. WBUFW(buf,0)=0x1da;
  1275. WBUFL(buf,2)=nd->bl.id;
  1276. WBUFW(buf,6)=nd->speed;
  1277. WBUFW(buf,8)=nd->sc.opt1;
  1278. WBUFW(buf,10)=nd->sc.opt2;
  1279. WBUFW(buf,12)=nd->sc.option;
  1280. WBUFW(buf,14)=view_class;
  1281. WBUFW(buf,16)=mob_get_hair(nd->class_);
  1282. WBUFW(buf,18)=mob_get_weapon(nd->class_);
  1283. WBUFW(buf,20)=mob_get_shield(nd->class_);
  1284. WBUFW(buf,22)=mob_get_head_buttom(nd->class_);
  1285. WBUFL(buf,24)=gettick();
  1286. WBUFW(buf,28)=mob_get_head_top(nd->class_);
  1287. WBUFW(buf,30)=mob_get_head_mid(nd->class_);
  1288. WBUFW(buf,32)=mob_get_hair_color(nd->class_);
  1289. WBUFW(buf,34)=mob_get_clothes_color(nd->class_);
  1290. WBUFW(buf,36)=nd->dir&0x0f; // head direction
  1291. if (g) {
  1292. WBUFL(buf,38)=g->guild_id;
  1293. WBUFW(buf,42)=g->emblem_id;
  1294. }
  1295. WBUFW(buf,44)=0; // manner
  1296. WBUFW(buf,46)=nd->sc.opt3;
  1297. WBUFB(buf,48)=0; // karma
  1298. WBUFB(buf,49)=mob_get_sex(nd->class_);
  1299. WBUFPOS2(buf,50,nd->bl.x,nd->bl.y,nd->to_x,nd->to_y);
  1300. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1301. WBUFB(buf,56)=5;
  1302. WBUFB(buf,57)=5;
  1303. WBUFW(buf,58)=50; //No level data.
  1304. return packet_len_table[0x1da];
  1305. #endif
  1306. }
  1307. WBUFW(buf,0)=0x7b;
  1308. WBUFL(buf,2)=nd->bl.id;
  1309. WBUFW(buf,6)=nd->speed;
  1310. WBUFW(buf,14)=nd->class_;
  1311. if (g) {
  1312. WBUFL(buf,22)=g->emblem_id;
  1313. WBUFL(buf,26)=g->guild_id;
  1314. // pc packet says the actual location of these are, but they are not. Why the discordance? [Skotlex]
  1315. // WBUFL(buf,38)=g->emblem_id;
  1316. // WBUFL(buf,42)=g->guild_id;
  1317. }
  1318. WBUFL(buf,22)=gettick();
  1319. WBUFPOS2(buf,50,nd->bl.x,nd->bl.y,nd->to_x,nd->to_y);
  1320. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1321. WBUFB(buf,56)=5;
  1322. WBUFB(buf,57)=5;
  1323. return packet_len_table[0x7b];
  1324. }
  1325. /*==========================================
  1326. *
  1327. *------------------------------------------
  1328. */
  1329. static int clif_pet0078(struct pet_data *pd, unsigned char *buf) {
  1330. int view_class,level;
  1331. nullpo_retr(0, pd);
  1332. level = status_get_lv(&pd->bl);
  1333. view_class = mob_get_viewclass(pd->class_);
  1334. if(pcdb_checkid(view_class)) {
  1335. #if PACKETVER < 4
  1336. memset(buf,0,packet_len_table[0x78]);
  1337. WBUFW(buf,0)=0x78;
  1338. WBUFL(buf,2)=pd->bl.id;
  1339. WBUFW(buf,6)=pd->speed;
  1340. WBUFW(buf,8)= 0; //opt1
  1341. WBUFW(buf,10)= 0; //opt2
  1342. WBUFW(buf,12)=pd->db->option;
  1343. WBUFW(buf,14)=view_class;
  1344. WBUFW(buf,16)=mob_get_hair(pd->class_);
  1345. WBUFW(buf,18)=mob_get_weapon(pd->class_);
  1346. WBUFW(buf,20)=mob_get_head_buttom(pd->class_);
  1347. WBUFW(buf,22)=mob_get_shield(pd->class_);
  1348. WBUFW(buf,24)=mob_get_head_top(pd->class_);
  1349. WBUFW(buf,26)=mob_get_head_mid(pd->class_);
  1350. WBUFW(buf,28)=mob_get_hair_color(pd->class_);
  1351. WBUFW(buf,30)=mob_get_clothes_color(pd->class_);
  1352. WBUFW(buf,32)|=pd->dir&0x0f; // head direction
  1353. WBUFL(buf,34)=0; //Guild id
  1354. WBUFL(buf,38)=0; //Guild emblem
  1355. WBUFW(buf,42)=0; //opt3;
  1356. WBUFB(buf,44)=0; // karma
  1357. WBUFB(buf,45)=mob_get_sex(pd->class_);
  1358. WBUFPOS(buf,46,pd->bl.x,pd->bl.y);
  1359. WBUFB(buf,48)|=pd->dir&0x0f;
  1360. WBUFB(buf,49)=5;
  1361. WBUFB(buf,50)=5;
  1362. WBUFB(buf,51)=0; // dead or sit state
  1363. WBUFW(buf,52)=clif_setlevel(level);
  1364. return packet_len_table[0x78];
  1365. #else
  1366. // Use 0x1d8 packet for pets with player sprites [Valaris]
  1367. memset(buf,0,packet_len_table[0x1d8]);
  1368. WBUFW(buf,0)=0x1d8;
  1369. WBUFL(buf,2)=pd->bl.id;
  1370. WBUFW(buf,6)=pd->speed;
  1371. WBUFW(buf,8)=0; // opt1
  1372. WBUFW(buf,10)=0; // opt2
  1373. WBUFW(buf,12)=pd->db->option;
  1374. WBUFW(buf,14)=view_class;
  1375. WBUFW(buf,16)=mob_get_hair(pd->class_);
  1376. WBUFW(buf,18)=mob_get_weapon(pd->class_);
  1377. WBUFW(buf,20)=mob_get_shield(pd->class_);
  1378. WBUFW(buf,22)=mob_get_head_buttom(pd->class_);
  1379. WBUFW(buf,24)=mob_get_head_top(pd->class_);
  1380. WBUFW(buf,26)=mob_get_head_mid(pd->class_);
  1381. WBUFW(buf,28)=mob_get_hair_color(pd->class_);
  1382. WBUFW(buf,30)=mob_get_clothes_color(pd->class_);
  1383. WBUFW(buf,32)|=pd->dir&0x0f; // head direction
  1384. WBUFL(buf,34)=0; // guild id
  1385. WBUFW(buf,38)=0; // emblem id
  1386. WBUFW(buf,40)=0; // manner
  1387. WBUFW(buf,42)=0; // opt3
  1388. WBUFB(buf,44)=0; // karma
  1389. WBUFB(buf,45)=mob_get_sex(pd->class_);
  1390. WBUFPOS(buf,46,pd->bl.x,pd->bl.y);
  1391. WBUFB(buf,48)|=pd->dir&0x0f;
  1392. WBUFB(buf,49)=5;
  1393. WBUFB(buf,50)=5;
  1394. WBUFB(buf,51)=0; // dead or sit state
  1395. WBUFW(buf,52)=clif_setlevel(level);
  1396. return packet_len_table[0x1d8];
  1397. #endif
  1398. } else {
  1399. memset(buf,0,packet_len_table[0x78]);
  1400. WBUFW(buf,0)=0x78;
  1401. WBUFL(buf,2)=pd->bl.id;
  1402. WBUFW(buf,6)=pd->speed;
  1403. WBUFW(buf,14)=view_class;
  1404. WBUFW(buf,16)=battle_config.pet_hair_style;
  1405. if((view_class = itemdb_viewid(pd->equip)) > 0)
  1406. WBUFW(buf,20)=view_class;
  1407. else
  1408. WBUFW(buf,20)=pd->equip;
  1409. WBUFPOS(buf,46,pd->bl.x,pd->bl.y);
  1410. WBUFB(buf,48)|=pd->dir&0x0f;
  1411. WBUFB(buf,49)=0;
  1412. WBUFB(buf,50)=0;
  1413. WBUFW(buf,52)=clif_setlevel(level);
  1414. return packet_len_table[0x78];
  1415. }
  1416. }
  1417. /*==========================================
  1418. *
  1419. *------------------------------------------
  1420. */
  1421. static int clif_pet007b(struct pet_data *pd, unsigned char *buf) {
  1422. int view_class,level;
  1423. nullpo_retr(0, pd);
  1424. level = status_get_lv(&pd->bl);
  1425. view_class = mob_get_viewclass(pd->class_);
  1426. if(pcdb_checkid(view_class)) {
  1427. #if PACKETVER < 4
  1428. memset(buf,0,packet_len_table[0x7b]);
  1429. WBUFW(buf,0)=0x7b;
  1430. WBUFL(buf,2)=pd->bl.id;
  1431. WBUFW(buf,6)=pd->speed;
  1432. WBUFW(buf,8)= 0; //opt1;
  1433. WBUFW(buf,10)= 0; //opt2;
  1434. WBUFW(buf,12)=pd->db->option;
  1435. WBUFW(buf,14)=view_class;
  1436. WBUFW(buf,16)=mob_get_hair(pd->class_);
  1437. WBUFW(buf,18)=mob_get_weapon(pd->class_);
  1438. WBUFW(buf,20)=mob_get_head_buttom(pd->class_);
  1439. WBUFL(buf,22)=gettick();
  1440. WBUFW(buf,26)=mob_get_shield(pd->class_);
  1441. WBUFW(buf,28)=mob_get_head_top(pd->class_);
  1442. WBUFW(buf,30)=mob_get_head_mid(pd->class_);
  1443. WBUFW(buf,32)=mob_get_hair_color(pd->class_);
  1444. WBUFW(buf,34)=mob_get_clothes_color(pd->class_);
  1445. WBUFW(buf,36)=pd->dir&0x0f; // head direction
  1446. WBUFL(buf,38)=0; // guild id
  1447. WBUFL(buf,42)=0; // emblem id
  1448. WBUFW(buf,46)=0; // opt3;
  1449. WBUFB(buf,48)=0; // karma
  1450. WBUFB(buf,49)=mob_get_sex(pd->class_);
  1451. WBUFPOS2(buf,50,pd->bl.x,pd->bl.y,pd->to_x,pd->to_y);
  1452. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1453. WBUFB(buf,56)=0; //0? These are always five for mobs and pets, /hmm [Skotlex]
  1454. WBUFB(buf,57)=0;
  1455. WBUFW(buf,58)=clif_setlevel(level);
  1456. return packet_len_table[0x7b];
  1457. #else
  1458. // Use 0x1da packet for monsters with player sprites [Valaris]
  1459. memset(buf,0,packet_len_table[0x1da]);
  1460. WBUFW(buf,0)=0x1da;
  1461. WBUFL(buf,2)=pd->bl.id;
  1462. WBUFW(buf,6)=pd->speed;
  1463. WBUFW(buf,8)=0; // opt1
  1464. WBUFW(buf,10)=0; // opt2
  1465. WBUFW(buf,12)=pd->db->option;
  1466. WBUFW(buf,14)=view_class;
  1467. WBUFW(buf,16)=mob_get_hair(pd->class_);
  1468. WBUFW(buf,18)=mob_get_weapon(pd->class_);
  1469. WBUFW(buf,20)=mob_get_shield(pd->class_);
  1470. WBUFW(buf,22)=mob_get_head_buttom(pd->class_);
  1471. WBUFL(buf,24)=gettick();
  1472. WBUFW(buf,28)=mob_get_head_top(pd->class_);
  1473. WBUFW(buf,30)=mob_get_head_mid(pd->class_);
  1474. WBUFW(buf,32)=mob_get_hair_color(pd->class_);
  1475. WBUFW(buf,34)=mob_get_clothes_color(pd->class_);
  1476. WBUFW(buf,36)=pd->dir&0x0f; // head direction
  1477. WBUFL(buf,38)=0; // guild id
  1478. WBUFW(buf,42)=0; // emblem id
  1479. WBUFW(buf,44)=0; // manner
  1480. WBUFW(buf,46)=0; // opt3
  1481. WBUFB(buf,48)=0; // karma
  1482. WBUFB(buf,49)=mob_get_sex(pd->class_);
  1483. WBUFPOS2(buf,50,pd->bl.x,pd->bl.y,pd->to_x,pd->to_y);
  1484. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1485. WBUFB(buf,56)=0;
  1486. WBUFB(buf,57)=0;
  1487. WBUFW(buf,58)=clif_setlevel(level);
  1488. return packet_len_table[0x1da];
  1489. #endif
  1490. } else {
  1491. // Use 0x7b packet for pets sprites [Valaris]
  1492. memset(buf,0,packet_len_table[0x7b]);
  1493. WBUFW(buf,0)=0x7b;
  1494. WBUFL(buf,2)=pd->bl.id;
  1495. WBUFW(buf,6)=pd->speed;
  1496. WBUFW(buf,14)=view_class;
  1497. WBUFW(buf,16)=battle_config.pet_hair_style;
  1498. if ((view_class = itemdb_viewid(pd->equip)) > 0)
  1499. WBUFW(buf,20)=view_class;
  1500. else
  1501. WBUFW(buf,20)=pd->equip;
  1502. WBUFL(buf,22)=gettick();
  1503. WBUFPOS2(buf,50,pd->bl.x,pd->bl.y,pd->to_x,pd->to_y);
  1504. WBUFB(buf,55)=0x88; // Deals with acceleration in directions. [Valaris]
  1505. WBUFB(buf,56)=0;
  1506. WBUFB(buf,57)=0;
  1507. WBUFW(buf,58)=clif_setlevel(level);
  1508. return packet_len_table[0x7b];
  1509. }
  1510. }
  1511. /*==========================================
  1512. *
  1513. *------------------------------------------
  1514. */
  1515. static int clif_set01e1(struct map_session_data *sd, unsigned char *buf) {
  1516. nullpo_retr(0, sd);
  1517. WBUFW(buf,0)=0x1e1;
  1518. WBUFL(buf,2)=sd->bl.id;
  1519. WBUFW(buf,6)=sd->spiritball;
  1520. return packet_len_table[0x1e1];
  1521. }
  1522. /*==========================================
  1523. *
  1524. *------------------------------------------
  1525. */
  1526. static int clif_set0192(int fd, int m, int x, int y, int type) {
  1527. WFIFOHEAD(fd, packet_len_table[0x192]);
  1528. WFIFOW(fd,0) = 0x192;
  1529. WFIFOW(fd,2) = x;
  1530. WFIFOW(fd,4) = y;
  1531. WFIFOW(fd,6) = type;
  1532. memcpy(WFIFOP(fd,8),map[m].name,MAP_NAME_LENGTH);
  1533. WFIFOSET(fd,packet_len_table[0x192]);
  1534. return 0;
  1535. }
  1536. // new and improved weather display [Valaris]
  1537. int clif_weather_sub(int fd, int type) {
  1538. WFIFOHEAD(fd, packet_len_table[0x1f3]);
  1539. WFIFOW(fd,0) = 0x1f3;
  1540. WFIFOL(fd,2) = -10;
  1541. WFIFOL(fd,6) = type;
  1542. WFIFOSET(fd,packet_len_table[0x1f3]);
  1543. return 0;
  1544. }
  1545. int clif_weather(int m) {
  1546. int i;
  1547. struct map_session_data *sd=NULL;
  1548. for(i = 0; i < fd_max; i++) {
  1549. if (session[i] && (sd = session[i]->session_data) != NULL && sd->state.auth && sd->bl.m == m) {
  1550. WFIFOHEAD(sd->fd, packet_len_table[0x80]);
  1551. WFIFOW(sd->fd,0) = 0x80;
  1552. WFIFOL(sd->fd,2) = -10;
  1553. WFIFOB(sd->fd,6) = 0;
  1554. WFIFOSET(sd->fd,packet_len_table[0x80]);
  1555. if (map[sd->bl.m].flag.snow || map[sd->bl.m].flag.clouds || map[sd->bl.m].flag.fog || map[sd->bl.m].flag.fireworks ||
  1556. map[sd->bl.m].flag.sakura || map[sd->bl.m].flag.leaves || map[sd->bl.m].flag.rain || map[sd->bl.m].flag.clouds2) {
  1557. WFIFOHEAD(sd->fd, packet_len_table[0x7c]);
  1558. WFIFOW(sd->fd,0)=0x7c;
  1559. WFIFOL(sd->fd,2)=-10;
  1560. WFIFOW(sd->fd,6)=0;
  1561. WFIFOW(sd->fd,8)=0;
  1562. WFIFOW(sd->fd,10)=0;
  1563. WFIFOW(sd->fd,12)=OPTION_INVISIBLE;
  1564. WFIFOW(sd->fd,20)=100;
  1565. WFIFOPOS(sd->fd,36,sd->bl.x,sd->bl.y);
  1566. WFIFOSET(sd->fd,packet_len_table[0x7c]);
  1567. if (map[sd->bl.m].flag.snow)
  1568. clif_weather_sub(sd->fd, 162);
  1569. if (map[sd->bl.m].flag.clouds)
  1570. clif_weather_sub(sd->fd, 233);
  1571. if (map[sd->bl.m].flag.clouds2)
  1572. clif_weather_sub(sd->fd, 516);
  1573. if (map[sd->bl.m].flag.fog)
  1574. clif_weather_sub(sd->fd, 515);
  1575. if (map[sd->bl.m].flag.fireworks) {
  1576. clif_weather_sub(sd->fd, 297);
  1577. clif_weather_sub(sd->fd, 299);
  1578. clif_weather_sub(sd->fd, 301);
  1579. }
  1580. if (map[sd->bl.m].flag.sakura)
  1581. clif_weather_sub(sd->fd, 163);
  1582. if (map[sd->bl.m].flag.leaves)
  1583. clif_weather_sub(sd->fd, 333);
  1584. if (map[sd->bl.m].flag.rain)
  1585. clif_weather_sub(sd->fd, 161);
  1586. }
  1587. }
  1588. }
  1589. return 0;
  1590. }
  1591. /*==========================================
  1592. *
  1593. *------------------------------------------
  1594. */
  1595. int clif_spawnpc(struct map_session_data *sd) {
  1596. unsigned char buf[128];
  1597. nullpo_retr(0, sd);
  1598. clif_set0078(sd, buf);
  1599. #if PACKETVER < 4
  1600. WBUFW(buf, 0) = 0x79;
  1601. WBUFW(buf,51) = clif_setlevel(sd->status.base_level);
  1602. clif_send(buf, packet_len_table[0x79], &sd->bl, AREA_WOS);
  1603. #else
  1604. WBUFW(buf, 0) = 0x1d9;
  1605. WBUFW(buf,51) = clif_setlevel(sd->status.base_level);
  1606. clif_send(buf, packet_len_table[0x1d9], &sd->bl, AREA_WOS);
  1607. #endif
  1608. if(sd->disguise > 0) {
  1609. int len;
  1610. memset(buf,0,packet_len_table[0x7c]);
  1611. WBUFW(buf,0)=0x7c;
  1612. WBUFL(buf,2)=-sd->bl.id;
  1613. WBUFW(buf,6)=sd->speed;
  1614. WBUFW(buf,12)=sd->sc.option;
  1615. WBUFW(buf,20)=sd->disguise;
  1616. WBUFPOS(buf,36,sd->bl.x,sd->bl.y);
  1617. clif_send(buf,packet_len_table[0x7c],&sd->bl,AREA);
  1618. len = clif_dis0078(sd,buf);
  1619. clif_send(buf,len,&sd->bl,AREA);
  1620. }
  1621. if (sd->spiritball > 0)
  1622. clif_spiritball(sd);
  1623. if (sd->status.guild_id > 0) { // force display of guild emblem [Valaris]
  1624. struct guild *g = guild_search(sd->status.guild_id);
  1625. if (g)
  1626. clif_guild_emblem(sd,g);
  1627. } // end addition [Valaris]
  1628. if (map[sd->bl.m].flag.snow || map[sd->bl.m].flag.clouds || map[sd->bl.m].flag.fog || map[sd->bl.m].flag.fireworks ||
  1629. map[sd->bl.m].flag.sakura || map[sd->bl.m].flag.leaves || map[sd->bl.m].flag.rain || map[sd->bl.m].flag.clouds2) {
  1630. WFIFOHEAD(sd->fd, packet_len_table[0x7c]);
  1631. WFIFOW(sd->fd,0)=0x7c;
  1632. WFIFOL(sd->fd,2)=-10;
  1633. WFIFOW(sd->fd,6)=0;
  1634. WFIFOW(sd->fd,8)=0;
  1635. WFIFOW(sd->fd,10)=0;
  1636. WFIFOW(sd->fd,12)=OPTION_INVISIBLE;
  1637. WFIFOW(sd->fd,20)=100;
  1638. WFIFOPOS(sd->fd,36,sd->bl.x,sd->bl.y);
  1639. WFIFOSET(sd->fd,packet_len_table[0x7c]);
  1640. if (map[sd->bl.m].flag.snow)
  1641. clif_weather_sub(sd->fd, 162);
  1642. if (map[sd->bl.m].flag.clouds)
  1643. clif_weather_sub(sd->fd, 233);
  1644. if (map[sd->bl.m].flag.clouds2)
  1645. clif_weather_sub(sd->fd, 516);
  1646. if (map[sd->bl.m].flag.fog)
  1647. clif_weather_sub(sd->fd, 515);
  1648. if (map[sd->bl.m].flag.fireworks) {
  1649. clif_weather_sub(sd->fd, 297);
  1650. clif_weather_sub(sd->fd, 299);
  1651. clif_weather_sub(sd->fd, 301);
  1652. }
  1653. if (map[sd->bl.m].flag.sakura)
  1654. clif_weather_sub(sd->fd, 163);
  1655. if (map[sd->bl.m].flag.leaves)
  1656. clif_weather_sub(sd->fd, 333);
  1657. if (map[sd->bl.m].flag.rain)
  1658. clif_weather_sub(sd->fd, 161);
  1659. }
  1660. //New 'night' effect by dynamix [Skotlex]
  1661. if (night_flag && map[sd->bl.m].flag.nightenabled)
  1662. { //Display night.
  1663. if (sd->state.night) //It must be resent because otherwise players get this annoying aura...
  1664. clif_status_load(&sd->bl, SI_NIGHT, 0);
  1665. else
  1666. sd->state.night = 1;
  1667. clif_status_load(&sd->bl, SI_NIGHT, 1);
  1668. } else if (sd->state.night) { //Clear night display.
  1669. clif_status_load(&sd->bl, SI_NIGHT, 0);
  1670. sd->state.night = 0;
  1671. }
  1672. if(sd->state.size==2) // tiny/big players [Valaris]
  1673. clif_specialeffect(&sd->bl,423,0);
  1674. else if(sd->state.size==1)
  1675. clif_specialeffect(&sd->bl,421,0);
  1676. return 0;
  1677. }
  1678. /*==========================================
  1679. *
  1680. *------------------------------------------
  1681. */
  1682. int clif_spawnnpc(struct npc_data *nd)
  1683. {
  1684. unsigned char buf[64];
  1685. int len;
  1686. nullpo_retr(0, nd);
  1687. if(nd->class_ < 0 || nd->flag&1 || nd->class_ == INVISIBLE_CLASS)
  1688. return 0;
  1689. if(!mobdb_checkid(nd->class_) ||
  1690. !pcdb_checkid(mob_get_viewclass(nd->class_))) {
  1691. //Normal npcs.
  1692. memset(buf,0,packet_len_table[0x7c]);
  1693. WBUFW(buf,0)=0x7c;
  1694. WBUFL(buf,2)=nd->bl.id;
  1695. WBUFW(buf,6)=nd->speed;
  1696. WBUFW(buf,20)=nd->class_;
  1697. WBUFPOS(buf,36,nd->bl.x,nd->bl.y);
  1698. clif_send(buf,packet_len_table[0x7c],&nd->bl,AREA);
  1699. }
  1700. len = clif_npc0078(nd,buf);
  1701. clif_send(buf,len,&nd->bl,AREA);
  1702. return 0;
  1703. }
  1704. /*==========================================
  1705. *
  1706. *------------------------------------------
  1707. */
  1708. int clif_spawnmob(struct mob_data *md)
  1709. {
  1710. unsigned char buf[64];
  1711. int len;
  1712. int viewclass = mob_get_viewclass(md->class_);
  1713. if (!pcdb_checkid(viewclass)) {
  1714. memset(buf,0,packet_len_table[0x7c]);
  1715. WBUFW(buf,0)=0x7c;
  1716. WBUFL(buf,2)=md->bl.id;
  1717. WBUFW(buf,6)=md->speed;
  1718. WBUFW(buf,8)=md->sc.opt1;
  1719. WBUFW(buf,10)=md->sc.opt2;
  1720. WBUFW(buf,12)=md->sc.option;
  1721. WBUFW(buf,20)=viewclass;
  1722. WBUFPOS(buf,36,md->bl.x,md->bl.y);
  1723. clif_send(buf,packet_len_table[0x7c],&md->bl,AREA);
  1724. }
  1725. len = clif_mob0078(md,buf);
  1726. clif_send(buf,len,&md->bl,AREA);
  1727. if(battle_config.save_clothcolor && pcdb_checkid(viewclass) && mob_get_clothes_color(md->class_) > 0) // [Valaris]
  1728. clif_changelook(&md->bl, LOOK_CLOTHES_COLOR, mob_get_clothes_color(md->class_));
  1729. if (mob_get_equip(md->class_) > 0) // mob equipment [Valaris]
  1730. clif_mob_equip(md,mob_get_equip(md->class_));
  1731. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1732. clif_specialeffect(&md->bl,423,0);
  1733. else if(md->special_state.size==1)
  1734. clif_specialeffect(&md->bl,421,0);
  1735. return 0;
  1736. }
  1737. // pet
  1738. /*==========================================
  1739. *
  1740. *------------------------------------------
  1741. */
  1742. int clif_spawnpet(struct pet_data *pd)
  1743. {
  1744. unsigned char buf[64];
  1745. int len;
  1746. int viewclass = mob_get_viewclass(pd->class_);
  1747. if (!pcdb_checkid(viewclass)) {
  1748. memset(buf,0,packet_len_table[0x7c]);
  1749. WBUFW(buf,0)=0x7c;
  1750. WBUFL(buf,2)=pd->bl.id;
  1751. WBUFW(buf,6)=pd->speed;
  1752. WBUFW(buf,20)=viewclass;
  1753. WBUFPOS(buf,36,pd->bl.x,pd->bl.y);
  1754. clif_send(buf,packet_len_table[0x7c],&pd->bl,AREA);
  1755. }
  1756. len = clif_pet0078(pd,buf);
  1757. clif_send(buf,len,&pd->bl,AREA);
  1758. return 0;
  1759. }
  1760. /*==========================================
  1761. *
  1762. *------------------------------------------
  1763. */
  1764. int clif_movepet(struct pet_data *pd) {
  1765. unsigned char buf[256];
  1766. int len;
  1767. nullpo_retr(0, pd);
  1768. len = clif_pet007b(pd,buf);
  1769. clif_send(buf,len,&pd->bl,AREA);
  1770. return 0;
  1771. }
  1772. /*==========================================
  1773. * npc walking [Valaris]
  1774. *------------------------------------------
  1775. */
  1776. int clif_movenpc(struct npc_data *nd) {
  1777. unsigned char buf[256];
  1778. int len;
  1779. nullpo_retr(0, nd);
  1780. len = clif_npc007b(nd,buf);
  1781. clif_send(buf,len,&nd->bl,AREA);
  1782. return 0;
  1783. }
  1784. /*==========================================
  1785. *
  1786. *------------------------------------------
  1787. */
  1788. int clif_servertick(struct map_session_data *sd)
  1789. {
  1790. int fd;
  1791. nullpo_retr(0, sd);
  1792. fd=sd->fd;
  1793. WFIFOHEAD(fd, packet_len_table[0x7f]);
  1794. WFIFOW(fd,0)=0x7f;
  1795. WFIFOL(fd,2)=sd->server_tick;
  1796. WFIFOSET(fd,packet_len_table[0x7f]);
  1797. return 0;
  1798. }
  1799. /*==========================================
  1800. *
  1801. *------------------------------------------
  1802. */
  1803. int clif_walkok(struct map_session_data *sd)
  1804. {
  1805. int fd;
  1806. nullpo_retr(0, sd);
  1807. fd=sd->fd;
  1808. WFIFOHEAD(fd, packet_len_table[0x87]);
  1809. WFIFOW(fd,0)=0x87;
  1810. WFIFOL(fd,2)=gettick();
  1811. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->to_x,sd->to_y);
  1812. WFIFOB(fd,11)=0x88;
  1813. WFIFOSET(fd,packet_len_table[0x87]);
  1814. return 0;
  1815. }
  1816. /*==========================================
  1817. *
  1818. *------------------------------------------
  1819. */
  1820. int clif_movechar(struct map_session_data *sd) {
  1821. int fd;
  1822. int len;
  1823. unsigned char buf[256];
  1824. nullpo_retr(0, sd);
  1825. fd = sd->fd;
  1826. len = clif_set007b(sd, buf);
  1827. clif_send(buf, len, &sd->bl, AREA_WOS);
  1828. if (map[sd->bl.m].flag.snow || map[sd->bl.m].flag.clouds || map[sd->bl.m].flag.fog || map[sd->bl.m].flag.fireworks ||
  1829. map[sd->bl.m].flag.sakura || map[sd->bl.m].flag.leaves || map[sd->bl.m].flag.rain || map[sd->bl.m].flag.clouds2) {
  1830. memset(buf,0,packet_len_table[0x7b]);
  1831. WBUFW(buf,0)=0x7b;
  1832. WBUFL(buf,2)=-10;
  1833. WBUFW(buf,6)=sd->speed;
  1834. WBUFW(buf,8)=0;
  1835. WBUFW(buf,10)=0;
  1836. WBUFW(buf,12)=OPTION_INVISIBLE;
  1837. WBUFW(buf,14)=100;
  1838. WBUFL(buf,22)=gettick();
  1839. WBUFPOS2(buf,50,sd->bl.x,sd->bl.y,sd->to_x,sd->to_y);
  1840. WBUFB(buf,56)=5;
  1841. WBUFB(buf,57)=5;
  1842. clif_send(buf, len, &sd->bl, SELF);
  1843. }
  1844. if(sd->disguise) {
  1845. memset(buf,0,packet_len_table[0x7b]);
  1846. len = clif_dis007b(sd, buf);
  1847. clif_send(buf, len, &sd->bl, AREA);
  1848. return 0;
  1849. }
  1850. //Stupid client that needs this resent every time someone walks :X
  1851. if(battle_config.save_clothcolor && sd->status.clothes_color > 0 && ((sd->view_class != JOB_WEDDING && sd->view_class !=JOB_XMAS) ||
  1852. (sd->view_class==JOB_WEDDING && !battle_config.wedding_ignorepalette) || (sd->view_class==JOB_XMAS && !battle_config.xmas_ignorepalette)))
  1853. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->status.clothes_color);
  1854. if(sd->state.size==2) // tiny/big players [Valaris]
  1855. clif_specialeffect(&sd->bl,423,0);
  1856. else if(sd->state.size==1)
  1857. clif_specialeffect(&sd->bl,421,0);
  1858. return 0;
  1859. }
  1860. /*==========================================
  1861. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1862. *------------------------------------------
  1863. */
  1864. static int clif_delayquit(int tid, unsigned int tick, int id, int data) {
  1865. struct map_session_data *sd = NULL;
  1866. if (chrif_isconnect())
  1867. { //Remove player from map server
  1868. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1869. map_quit(sd);
  1870. } else //Save later.
  1871. add_timer(tick + 10000, clif_delayquit, id, 0);
  1872. return 0;
  1873. }
  1874. /*==========================================
  1875. *
  1876. *------------------------------------------
  1877. */
  1878. void clif_quitsave(int fd,struct map_session_data *sd)
  1879. {
  1880. if (chrif_isconnect() && (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout))
  1881. map_quit(sd);
  1882. else if (sd->fd)
  1883. { //Disassociate session from player (session is deleted after this function was called)
  1884. //And set a timer to delete this player later.
  1885. session[fd]->session_data = NULL;
  1886. sd->fd = 0;
  1887. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1888. }
  1889. }
  1890. /*==========================================
  1891. *
  1892. *------------------------------------------
  1893. */
  1894. static int clif_waitclose(int tid, unsigned int tick, int id, int data) {
  1895. if (session[id] && session[id]->func_parse == clif_parse) //Avoid disconnecting non-players, as pointed out by End of Exam [Skotlex]
  1896. session[id]->eof = 1;
  1897. return 0;
  1898. }
  1899. /*==========================================
  1900. *
  1901. *------------------------------------------
  1902. */
  1903. void clif_setwaitclose(int fd) {
  1904. struct map_session_data *sd;
  1905. // if player is not already in the game (double connection probably)
  1906. if ((sd = (struct map_session_data*)session[fd]->session_data) == NULL) {
  1907. // limited timer, just to send information.
  1908. add_timer(gettick() + 1000, clif_waitclose, fd, 0);
  1909. } else
  1910. add_timer(gettick() + 5000, clif_waitclose, fd, 0);
  1911. }
  1912. /*==========================================
  1913. *
  1914. *------------------------------------------
  1915. */
  1916. int clif_changemap(struct map_session_data *sd, short map, int x, int y) {
  1917. int fd;
  1918. nullpo_retr(0, sd);
  1919. fd = sd->fd;
  1920. WFIFOHEAD(fd, packet_len_table[0x91]);
  1921. WFIFOW(fd,0) = 0x91;
  1922. memcpy(WFIFOP(fd,2), mapindex_id2name(map), MAP_NAME_LENGTH);
  1923. WFIFOW(fd,18) = x;
  1924. WFIFOW(fd,20) = y;
  1925. WFIFOSET(fd, packet_len_table[0x91]);
  1926. if(pc_isdead(sd)) // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  1927. clif_clearchar_area(&sd->bl,1);
  1928. return 0;
  1929. }
  1930. /*==========================================
  1931. *
  1932. *------------------------------------------
  1933. */
  1934. int clif_changemapserver(struct map_session_data *sd, char *mapname, int x, int y, int ip, int port) {
  1935. int fd;
  1936. nullpo_retr(0, sd);
  1937. fd = sd->fd;
  1938. WFIFOHEAD(fd, packet_len_table[0x92]);
  1939. WFIFOW(fd,0) = 0x92;
  1940. //Better not trust the null-terminator is there. [Skotlex]
  1941. memcpy(WFIFOP(fd,2), mapname, MAP_NAME_LENGTH);
  1942. WFIFOB(fd,17) = 0; //Null terminator for mapname
  1943. WFIFOW(fd,18) = x;
  1944. WFIFOW(fd,20) = y;
  1945. WFIFOL(fd,22) = ip;
  1946. WFIFOW(fd,26) = port;
  1947. WFIFOSET(fd, packet_len_table[0x92]);
  1948. return 0;
  1949. }
  1950. int clif_blown(struct block_list *bl) {
  1951. //Previous Aegis versions simply used clif_fixpos, but it seems clif_slide works better on current clients.
  1952. // return clif_fixpos(bl);
  1953. return clif_slide(bl, bl->x, bl->y);
  1954. }
  1955. /*==========================================
  1956. *
  1957. *------------------------------------------
  1958. */
  1959. int clif_fixpos(struct block_list *bl) {
  1960. unsigned char buf[16];
  1961. nullpo_retr(0, bl);
  1962. WBUFW(buf,0)=0x88;
  1963. if (bl->type ==BL_PC && ((struct map_session_data *)bl)->disguise)
  1964. WBUFL(buf,2)=-bl->id;
  1965. else
  1966. WBUFL(buf,2)=bl->id;
  1967. WBUFW(buf,6)=bl->x;
  1968. WBUFW(buf,8)=bl->y;
  1969. clif_send(buf, packet_len_table[0x88], bl, AREA);
  1970. return 0;
  1971. }
  1972. /*==========================================
  1973. *
  1974. *------------------------------------------
  1975. */
  1976. int clif_npcbuysell(struct map_session_data* sd, int id) {
  1977. int fd;
  1978. nullpo_retr(0, sd);
  1979. fd=sd->fd;
  1980. WFIFOHEAD(fd, packet_len_table[0xc4]);
  1981. WFIFOW(fd,0)=0xc4;
  1982. WFIFOL(fd,2)=id;
  1983. WFIFOSET(fd,packet_len_table[0xc4]);
  1984. return 0;
  1985. }
  1986. /*==========================================
  1987. *
  1988. *------------------------------------------
  1989. */
  1990. int clif_buylist(struct map_session_data *sd, struct npc_data *nd) {
  1991. struct item_data *id;
  1992. int fd,i,val;
  1993. nullpo_retr(0, sd);
  1994. nullpo_retr(0, nd);
  1995. fd=sd->fd;
  1996. WFIFOHEAD(fd, 200 * 11 + 4);
  1997. WFIFOW(fd,0)=0xc6;
  1998. for(i=0;nd->u.shop_item[i].nameid > 0;i++){
  1999. id = itemdb_search(nd->u.shop_item[i].nameid);
  2000. val=nd->u.shop_item[i].value;
  2001. WFIFOL(fd,4+i*11)=val;
  2002. if (!id->flag.value_notdc)
  2003. val=pc_modifybuyvalue(sd,val);
  2004. WFIFOL(fd,8+i*11)=val;
  2005. WFIFOB(fd,12+i*11)=itemtype(id->type);
  2006. if (id->view_id > 0)
  2007. WFIFOW(fd,13+i*11)=id->view_id;
  2008. else
  2009. WFIFOW(fd,13+i*11)=nd->u.shop_item[i].nameid;
  2010. }
  2011. WFIFOW(fd,2)=i*11+4;
  2012. WFIFOSET(fd,WFIFOW(fd,2));
  2013. return 0;
  2014. }
  2015. /*==========================================
  2016. *
  2017. *------------------------------------------
  2018. */
  2019. int clif_selllist(struct map_session_data *sd) {
  2020. int fd,i,c=0,val;
  2021. nullpo_retr(0, sd);
  2022. fd=sd->fd;
  2023. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  2024. WFIFOW(fd,0)=0xc7;
  2025. for(i=0;i<MAX_INVENTORY;i++) {
  2026. if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
  2027. if (!itemdb_cansell(sd->status.inventory[i].nameid, pc_isGM(sd)))
  2028. continue;
  2029. val=sd->inventory_data[i]->value_sell;
  2030. if (val < 0)
  2031. continue;
  2032. WFIFOW(fd,4+c*10)=i+2;
  2033. WFIFOL(fd,6+c*10)=val;
  2034. if (!sd->inventory_data[i]->flag.value_notoc)
  2035. val=pc_modifysellvalue(sd,val);
  2036. WFIFOL(fd,10+c*10)=val;
  2037. c++;
  2038. }
  2039. }
  2040. WFIFOW(fd,2)=c*10+4;
  2041. WFIFOSET(fd,WFIFOW(fd,2));
  2042. return 0;
  2043. }
  2044. /*==========================================
  2045. *
  2046. *------------------------------------------
  2047. */
  2048. int clif_scriptmes(struct map_session_data *sd, int npcid, char *mes) {
  2049. int fd;
  2050. int slen = strlen(mes) + 9;
  2051. WFIFOHEAD(fd, slen);
  2052. nullpo_retr(0, sd);
  2053. fd=sd->fd;
  2054. WFIFOW(fd,0)=0xb4;
  2055. WFIFOW(fd,2)=slen;
  2056. WFIFOL(fd,4)=npcid;
  2057. strcpy((char*)WFIFOP(fd,8),mes);
  2058. WFIFOSET(fd,WFIFOW(fd,2));
  2059. return 0;
  2060. }
  2061. /*==========================================
  2062. *
  2063. *------------------------------------------
  2064. */
  2065. int clif_scriptnext(struct map_session_data *sd,int npcid) {
  2066. int fd;
  2067. nullpo_retr(0, sd);
  2068. fd=sd->fd;
  2069. WFIFOHEAD(fd, packet_len_table[0xb5]);
  2070. WFIFOW(fd,0)=0xb5;
  2071. WFIFOL(fd,2)=npcid;
  2072. WFIFOSET(fd,packet_len_table[0xb5]);
  2073. return 0;
  2074. }
  2075. /*==========================================
  2076. *
  2077. *------------------------------------------
  2078. */
  2079. int clif_scriptclose(struct map_session_data *sd, int npcid) {
  2080. int fd;
  2081. nullpo_retr(0, sd);
  2082. fd=sd->fd;
  2083. WFIFOHEAD(fd, packet_len_table[0xb6]);
  2084. WFIFOW(fd,0)=0xb6;
  2085. WFIFOL(fd,2)=npcid;
  2086. WFIFOSET(fd,packet_len_table[0xb6]);
  2087. return 0;
  2088. }
  2089. /*==========================================
  2090. *
  2091. *------------------------------------------
  2092. */
  2093. int clif_scriptmenu(struct map_session_data *sd, int npcid, char *mes) {
  2094. int fd;
  2095. int slen = strlen(mes) + 8;
  2096. WFIFOHEAD(fd, slen);
  2097. nullpo_retr(0, sd);
  2098. fd=sd->fd;
  2099. WFIFOW(fd,0)=0xb7;
  2100. WFIFOW(fd,2)=slen;
  2101. WFIFOL(fd,4)=npcid;
  2102. strcpy((char*)WFIFOP(fd,8),mes);
  2103. WFIFOSET(fd,WFIFOW(fd,2));
  2104. return 0;
  2105. }
  2106. /*==========================================
  2107. *
  2108. *------------------------------------------
  2109. */
  2110. int clif_scriptinput(struct map_session_data *sd, int npcid) {
  2111. int fd;
  2112. nullpo_retr(0, sd);
  2113. fd=sd->fd;
  2114. WFIFOHEAD(fd, packet_len_table[0x142]);
  2115. WFIFOW(fd,0)=0x142;
  2116. WFIFOL(fd,2)=npcid;
  2117. WFIFOSET(fd,packet_len_table[0x142]);
  2118. return 0;
  2119. }
  2120. /*==========================================
  2121. *
  2122. *------------------------------------------
  2123. */
  2124. int clif_scriptinputstr(struct map_session_data *sd, int npcid) {
  2125. int fd;
  2126. nullpo_retr(0, sd);
  2127. fd=sd->fd;
  2128. WFIFOHEAD(fd, packet_len_table[0x1d4]);
  2129. WFIFOW(fd,0)=0x1d4;
  2130. WFIFOL(fd,2)=npcid;
  2131. WFIFOSET(fd,packet_len_table[0x1d4]);
  2132. return 0;
  2133. }
  2134. /*==========================================
  2135. *
  2136. *------------------------------------------
  2137. */
  2138. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color) {
  2139. int fd;
  2140. nullpo_retr(0, sd);
  2141. fd=sd->fd;
  2142. WFIFOHEAD(fd, packet_len_table[0x144]);
  2143. WFIFOW(fd,0)=0x144;
  2144. WFIFOL(fd,2)=npc_id;
  2145. WFIFOL(fd,6)=type;
  2146. WFIFOL(fd,10)=x;
  2147. WFIFOL(fd,14)=y;
  2148. WFIFOB(fd,18)=id;
  2149. WFIFOL(fd,19)=color;
  2150. WFIFOSET(fd,packet_len_table[0x144]);
  2151. return 0;
  2152. }
  2153. /*==========================================
  2154. *
  2155. *------------------------------------------
  2156. */
  2157. int clif_cutin(struct map_session_data *sd, char *image, int type) {
  2158. int fd;
  2159. nullpo_retr(0, sd);
  2160. fd=sd->fd;
  2161. WFIFOHEAD(fd, packet_len_table[0x1b3]);
  2162. WFIFOW(fd,0)=0x1b3;
  2163. strncpy((char*)WFIFOP(fd,2),image,64);
  2164. WFIFOB(fd,66)=type;
  2165. WFIFOSET(fd,packet_len_table[0x1b3]);
  2166. return 0;
  2167. }
  2168. /*==========================================
  2169. * Fills in card data from the given item and into the buffer. [Skotlex]
  2170. *------------------------------------------
  2171. */
  2172. static void clif_addcards(unsigned char* buf, struct item* item)
  2173. {
  2174. int i=0,j;
  2175. if (item == NULL) { //Blank data
  2176. WBUFW(buf,0)=0;
  2177. WBUFW(buf,2)=0;
  2178. WBUFW(buf,4)=0;
  2179. WBUFW(buf,6)=0;
  2180. return;
  2181. }
  2182. if(item->card[0]==(short)0xff00) { //pet eggs
  2183. WBUFW(buf,0)=0;
  2184. WBUFW(buf,2)=0;
  2185. WBUFW(buf,4)=0;
  2186. WBUFW(buf,6)=item->card[3]; //Pet renamed flag.
  2187. return;
  2188. }
  2189. if(item->card[0]==0x00ff || item->card[0]==0x00fe) { //Forged/created items
  2190. WBUFW(buf,0)=item->card[0];
  2191. WBUFW(buf,2)=item->card[1];
  2192. WBUFW(buf,4)=item->card[2];
  2193. WBUFW(buf,6)=item->card[3];
  2194. return;
  2195. }
  2196. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2197. if (MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4)
  2198. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  2199. //Normal items.
  2200. if (item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  2201. WBUFW(buf,0)=j;
  2202. else
  2203. WBUFW(buf,0)= item->card[i];
  2204. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  2205. WBUFW(buf,2)=j;
  2206. else
  2207. WBUFW(buf,2)=item->card[i];
  2208. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  2209. WBUFW(buf,4)=j;
  2210. else
  2211. WBUFW(buf,4)=item->card[i];
  2212. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  2213. WBUFW(buf,6)=j;
  2214. else
  2215. WBUFW(buf,6)=item->card[i];
  2216. }
  2217. /*==========================================
  2218. *
  2219. *------------------------------------------
  2220. */
  2221. int clif_additem(struct map_session_data *sd, int n, int amount, int fail) {
  2222. int fd;
  2223. unsigned char *buf;
  2224. nullpo_retr(0, sd);
  2225. fd = sd->fd;
  2226. if (!session_isActive(fd)) //Sasuke-
  2227. return 0;
  2228. WFIFOHEAD(fd,packet_len_table[0xa0]);
  2229. buf = WFIFOP(fd,0);
  2230. if(fail) {
  2231. WBUFW(buf,0)=0xa0;
  2232. WBUFW(buf,2)=n+2;
  2233. WBUFW(buf,4)=amount;
  2234. WBUFW(buf,6)=0;
  2235. WBUFB(buf,8)=0;
  2236. WBUFB(buf,9)=0;
  2237. WBUFB(buf,10)=0;
  2238. WBUFW(buf,11)=0;
  2239. WBUFW(buf,13)=0;
  2240. WBUFW(buf,15)=0;
  2241. WBUFW(buf,17)=0;
  2242. WBUFW(buf,19)=0;
  2243. WBUFB(buf,21)=0;
  2244. WBUFB(buf,22)=fail;
  2245. } else {
  2246. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  2247. return 1;
  2248. WBUFW(buf,0)=0xa0;
  2249. WBUFW(buf,2)=n+2;
  2250. WBUFW(buf,4)=amount;
  2251. if (sd->inventory_data[n]->view_id > 0)
  2252. WBUFW(buf,6)=sd->inventory_data[n]->view_id;
  2253. else
  2254. WBUFW(buf,6)=sd->status.inventory[n].nameid;
  2255. WBUFB(buf,8)=sd->status.inventory[n].identify;
  2256. WBUFB(buf,9)=sd->status.inventory[n].attribute;
  2257. WBUFB(buf,10)=sd->status.inventory[n].refine;
  2258. clif_addcards(WBUFP(buf,11), &sd->status.inventory[n]);
  2259. WBUFW(buf,19)=pc_equippoint(sd,n);
  2260. WBUFB(buf,21)=itemtype(sd->inventory_data[n]->type);
  2261. WBUFB(buf,22)=fail;
  2262. }
  2263. WFIFOSET(fd,packet_len_table[0xa0]);
  2264. return 0;
  2265. }
  2266. /*==========================================
  2267. *
  2268. *------------------------------------------
  2269. */
  2270. int clif_delitem(struct map_session_data *sd,int n,int amount)
  2271. {
  2272. int fd;
  2273. nullpo_retr(0, sd);
  2274. fd=sd->fd;
  2275. WFIFOHEAD(fd, packet_len_table[0xaf]);
  2276. WFIFOW(fd,0)=0xaf;
  2277. WFIFOW(fd,2)=n+2;
  2278. WFIFOW(fd,4)=amount;
  2279. WFIFOSET(fd,packet_len_table[0xaf]);
  2280. return 0;
  2281. }
  2282. /*==========================================
  2283. *
  2284. *------------------------------------------
  2285. */
  2286. int clif_itemlist(struct map_session_data *sd)
  2287. {
  2288. int i,n,fd,arrow=-1;
  2289. unsigned char *buf;
  2290. nullpo_retr(0, sd);
  2291. fd=sd->fd;
  2292. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  2293. buf = WFIFOP(fd,0);
  2294. #if PACKETVER < 5
  2295. WBUFW(buf,0)=0xa3;
  2296. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2297. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL || itemdb_isequip2(sd->inventory_data[i]))
  2298. continue;
  2299. WBUFW(buf,n*10+4)=i+2;
  2300. if (sd->inventory_data[i]->view_id > 0)
  2301. WBUFW(buf,n*10+6)=sd->inventory_data[i]->view_id;
  2302. else
  2303. WBUFW(buf,n*10+6)=sd->status.inventory[i].nameid;
  2304. WBUFB(buf,n*10+8)=itemtype(sd->inventory_data[i]->type);
  2305. WBUFB(buf,n*10+9)=sd->status.inventory[i].identify;
  2306. WBUFW(buf,n*10+10)=sd->status.inventory[i].amount;
  2307. if (sd->inventory_data[i]->equip == 0x8000) {
  2308. WBUFW(buf,n*10+12)=0x8000;
  2309. if (sd->status.inventory[i].equip)
  2310. arrow=i; // ついでに矢装備チェック
  2311. } else
  2312. WBUFW(buf,n*10+12)=0;
  2313. n++;
  2314. }
  2315. if (n) {
  2316. WBUFW(buf,2)=4+n*10;
  2317. WFIFOSET(fd,WFIFOW(fd,2));
  2318. }
  2319. #else
  2320. WBUFW(buf,0)=0x1ee;
  2321. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2322. if(sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL || itemdb_isequip2(sd->inventory_data[i]))
  2323. continue;
  2324. WBUFW(buf,n*18+4)=i+2;
  2325. if(sd->inventory_data[i]->view_id > 0)
  2326. WBUFW(buf,n*18+6)=sd->inventory_data[i]->view_id;
  2327. else
  2328. WBUFW(buf,n*18+6)=sd->status.inventory[i].nameid;
  2329. WBUFB(buf,n*18+8)=itemtype(sd->inventory_data[i]->type);
  2330. WBUFB(buf,n*18+9)=sd->status.inventory[i].identify;
  2331. WBUFW(buf,n*18+10)=sd->status.inventory[i].amount;
  2332. if (sd->inventory_data[i]->equip == 0x8000) {
  2333. WBUFW(buf,n*18+12)=0x8000;
  2334. if(sd->status.inventory[i].equip)
  2335. arrow=i; // ついでに矢装備チェック
  2336. } else
  2337. WBUFW(buf,n*18+12)=0;
  2338. clif_addcards(WBUFP(buf, n*18+14), &sd->status.inventory[i]);
  2339. n++;
  2340. }
  2341. if (n) {
  2342. WBUFW(buf,2)=4+n*18;
  2343. WFIFOSET(fd,WFIFOW(fd,2));
  2344. }
  2345. #endif
  2346. if(arrow >= 0)
  2347. clif_arrowequip(sd,arrow);
  2348. return 0;
  2349. }
  2350. /*==========================================
  2351. *
  2352. *------------------------------------------
  2353. */
  2354. int clif_equiplist(struct map_session_data *sd)
  2355. {
  2356. int i,n,fd;
  2357. nullpo_retr(0, sd);
  2358. fd=sd->fd;
  2359. if (!session_isActive(fd))
  2360. return 0;
  2361. WFIFOHEAD(fd, 4 + MAX_INVENTORY * 20);
  2362. WFIFOW(fd,0)=0xa4;
  2363. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2364. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL || !itemdb_isequip2(sd->inventory_data[i]))
  2365. continue;
  2366. WFIFOW(fd,n*20+4)=i+2;
  2367. if(sd->inventory_data[i]->view_id > 0)
  2368. WFIFOW(fd,n*20+6)=sd->inventory_data[i]->view_id;
  2369. else
  2370. WFIFOW(fd,n*20+6)=sd->status.inventory[i].nameid;
  2371. WFIFOB(fd,n*20+8)=itemtype(sd->inventory_data[i]->type);
  2372. WFIFOB(fd,n*20+9)=sd->status.inventory[i].identify;
  2373. WFIFOW(fd,n*20+10)=pc_equippoint(sd,i);
  2374. WFIFOW(fd,n*20+12)=sd->status.inventory[i].equip;
  2375. WFIFOB(fd,n*20+14)=sd->status.inventory[i].attribute;
  2376. WFIFOB(fd,n*20+15)=sd->status.inventory[i].refine;
  2377. clif_addcards(WFIFOP(fd, n*20+16), &sd->status.inventory[i]);
  2378. n++;
  2379. }
  2380. if(n){
  2381. WFIFOW(fd,2)=4+n*20;
  2382. WFIFOSET(fd,WFIFOW(fd,2));
  2383. }
  2384. return 0;
  2385. }
  2386. /*==========================================
  2387. * カプラさんに預けてある消耗品&収集品リスト
  2388. *------------------------------------------
  2389. */
  2390. int clif_storageitemlist(struct map_session_data *sd,struct storage *stor)
  2391. {
  2392. struct item_data *id;
  2393. int i,n,fd;
  2394. unsigned char *buf;
  2395. nullpo_retr(0, sd);
  2396. nullpo_retr(0, stor);
  2397. fd=sd->fd;
  2398. WFIFOHEAD(fd,MAX_STORAGE * 18 + 4);
  2399. buf = WFIFOP(fd,0);
  2400. #if PACKETVER < 5
  2401. WBUFW(buf,0)=0xa5;
  2402. for(i=0,n=0;i<MAX_STORAGE;i++){
  2403. if(stor->storage_[i].nameid<=0)
  2404. continue;
  2405. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2406. if(itemdb_isequip2(id))
  2407. continue;
  2408. WBUFW(buf,n*10+4)=i+1;
  2409. if(id->view_id > 0)
  2410. WBUFW(buf,n*10+6)=id->view_id;
  2411. else
  2412. WBUFW(buf,n*10+6)=stor->storage_[i].nameid;
  2413. WBUFB(buf,n*10+8)=itemtype(id->type);
  2414. WBUFB(buf,n*10+9)=stor->storage_[i].identify;
  2415. WBUFW(buf,n*10+10)=stor->storage_[i].amount;
  2416. WBUFW(buf,n*10+12)=0;
  2417. n++;
  2418. }
  2419. if(n){
  2420. WBUFW(buf,2)=4+n*10;
  2421. WFIFOSET(fd,WFIFOW(fd,2));
  2422. }
  2423. #else
  2424. WBUFW(buf,0)=0x1f0;
  2425. for(i=0,n=0;i<MAX_STORAGE;i++){
  2426. if(stor->storage_[i].nameid<=0)
  2427. continue;
  2428. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2429. if(itemdb_isequip2(id))
  2430. continue;
  2431. WBUFW(buf,n*18+4)=i+1;
  2432. if(id->view_id > 0)
  2433. WBUFW(buf,n*18+6)=id->view_id;
  2434. else
  2435. WBUFW(buf,n*18+6)=stor->storage_[i].nameid;
  2436. WBUFB(buf,n*18+8)=itemtype(id->type);
  2437. WBUFB(buf,n*18+9)=stor->storage_[i].identify;
  2438. WBUFW(buf,n*18+10)=stor->storage_[i].amount;
  2439. WBUFW(buf,n*18+12)=0;
  2440. clif_addcards(WBUFP(buf,n*18+14), &stor->storage_[i]);
  2441. n++;
  2442. }
  2443. if(n){
  2444. WBUFW(buf,2)=4+n*18;
  2445. WFIFOSET(fd,WFIFOW(fd,2));
  2446. }
  2447. #endif
  2448. return 0;
  2449. }
  2450. /*==========================================
  2451. * カプラさんに預けてある装備リスト
  2452. *------------------------------------------
  2453. */
  2454. int clif_storageequiplist(struct map_session_data *sd,struct storage *stor)
  2455. {
  2456. struct item_data *id;
  2457. int i,n,fd;
  2458. unsigned char *buf;
  2459. nullpo_retr(0, sd);
  2460. nullpo_retr(0, stor);
  2461. fd=sd->fd;
  2462. WFIFOHEAD(fd,MAX_STORAGE * 20 + 4);
  2463. buf = WFIFOP(fd,0);
  2464. WBUFW(buf,0)=0xa6;
  2465. for(i=0,n=0;i<MAX_STORAGE;i++){
  2466. if(stor->storage_[i].nameid<=0)
  2467. continue;
  2468. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2469. if(!itemdb_isequip2(id))
  2470. continue;
  2471. WBUFW(buf,n*20+4)=i+1;
  2472. if(id->view_id > 0)
  2473. WBUFW(buf,n*20+6)=id->view_id;
  2474. else
  2475. WBUFW(buf,n*20+6)=stor->storage_[i].nameid;
  2476. WBUFB(buf,n*20+8)=itemtype(id->type);
  2477. WBUFB(buf,n*20+9)=stor->storage_[i].identify;
  2478. WBUFW(buf,n*20+10)=id->equip;
  2479. WBUFW(buf,n*20+12)=stor->storage_[i].equip;
  2480. WBUFB(buf,n*20+14)=stor->storage_[i].attribute;
  2481. WBUFB(buf,n*20+15)=stor->storage_[i].refine;
  2482. clif_addcards(WBUFP(buf, n*20+16), &stor->storage_[i]);
  2483. n++;
  2484. }
  2485. if(n){
  2486. WBUFW(buf,2)=4+n*20;
  2487. WFIFOSET(fd,WFIFOW(fd,2));
  2488. }
  2489. return 0;
  2490. }
  2491. /*==========================================
  2492. *
  2493. *------------------------------------------
  2494. */
  2495. int clif_guildstorageitemlist(struct map_session_data *sd,struct guild_storage *stor)
  2496. {
  2497. struct item_data *id;
  2498. int i,n,fd;
  2499. unsigned char *buf;
  2500. nullpo_retr(0, sd);
  2501. nullpo_retr(0, stor);
  2502. fd=sd->fd;
  2503. WFIFOHEAD(fd, MAX_GUILD_STORAGE * 18 + 4);
  2504. buf=WFIFOP(fd,0);
  2505. #if PACKETVER < 5
  2506. WBUFW(buf,0)=0xa5;
  2507. for(i=0,n=0;i<MAX_GUILD_STORAGE;i++){
  2508. if(stor->storage_[i].nameid<=0)
  2509. continue;
  2510. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2511. if(itemdb_isequip2(id))
  2512. continue;
  2513. WBUFW(buf,n*10+4)=i+1;
  2514. if(id->view_id > 0)
  2515. WBUFW(buf,n*10+6)=id->view_id;
  2516. else
  2517. WBUFW(buf,n*10+6)=stor->storage_[i].nameid;
  2518. WBUFB(buf,n*10+8)=itemtype(id->type);
  2519. WBUFB(buf,n*10+9)=stor->storage_[i].identify;
  2520. WBUFW(buf,n*10+10)=stor->storage_[i].amount;
  2521. WBUFW(buf,n*10+12)=0;
  2522. n++;
  2523. }
  2524. if(n){
  2525. WBUFW(buf,2)=4+n*10;
  2526. WFIFOSET(fd,WFIFOW(fd,2));
  2527. }
  2528. #else
  2529. WBUFW(buf,0)=0x1f0;
  2530. for(i=0,n=0;i<MAX_GUILD_STORAGE;i++){
  2531. if(stor->storage_[i].nameid<=0)
  2532. continue;
  2533. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2534. if(itemdb_isequip2(id))
  2535. continue;
  2536. WBUFW(buf,n*18+4)=i+1;
  2537. if(id->view_id > 0)
  2538. WBUFW(buf,n*18+6)=id->view_id;
  2539. else
  2540. WBUFW(buf,n*18+6)=stor->storage_[i].nameid;
  2541. WBUFB(buf,n*18+8)=itemtype(id->type);
  2542. WBUFB(buf,n*18+9)=stor->storage_[i].identify;
  2543. WBUFW(buf,n*18+10)=stor->storage_[i].amount;
  2544. WBUFW(buf,n*18+12)=0;
  2545. clif_addcards(WBUFP(buf,n*18+14), &stor->storage_[i]);
  2546. n++;
  2547. }
  2548. if(n){
  2549. WBUFW(buf,2)=4+n*18;
  2550. WFIFOSET(fd,WFIFOW(fd,2));
  2551. }
  2552. #endif
  2553. return 0;
  2554. }
  2555. /*==========================================
  2556. *
  2557. *------------------------------------------
  2558. */
  2559. int clif_guildstorageequiplist(struct map_session_data *sd,struct guild_storage *stor)
  2560. {
  2561. struct item_data *id;
  2562. int i,n,fd;
  2563. unsigned char *buf;
  2564. nullpo_retr(0, sd);
  2565. fd=sd->fd;
  2566. WFIFOHEAD(fd, MAX_GUILD_STORAGE * 20 + 4);
  2567. buf=WFIFOP(fd,0);
  2568. WBUFW(buf,0)=0xa6;
  2569. for(i=0,n=0;i<MAX_GUILD_STORAGE;i++){
  2570. if(stor->storage_[i].nameid<=0)
  2571. continue;
  2572. nullpo_retr(0, id = itemdb_search(stor->storage_[i].nameid));
  2573. if(!itemdb_isequip2(id))
  2574. continue;
  2575. WBUFW(buf,n*20+4)=i+1;
  2576. if(id->view_id > 0)
  2577. WBUFW(buf,n*20+6)=id->view_id;
  2578. else
  2579. WBUFW(buf,n*20+6)=stor->storage_[i].nameid;
  2580. WBUFB(buf,n*20+8)=itemtype(id->type);
  2581. WBUFB(buf,n*20+9)=stor->storage_[i].identify;
  2582. WBUFW(buf,n*20+10)=id->equip;
  2583. WBUFW(buf,n*20+12)=stor->storage_[i].equip;
  2584. WBUFB(buf,n*20+14)=stor->storage_[i].attribute;
  2585. WBUFB(buf,n*20+15)=stor->storage_[i].refine;
  2586. clif_addcards(WBUFP(buf, n*20+16), &stor->storage_[i]);
  2587. n++;
  2588. }
  2589. if(n){
  2590. WBUFW(buf,2)=4+n*20;
  2591. WFIFOSET(fd,WFIFOW(fd,2));
  2592. }
  2593. return 0;
  2594. }
  2595. // Guild XY locators [Valaris]
  2596. int clif_guild_xy(struct map_session_data *sd)
  2597. {
  2598. unsigned char buf[10];
  2599. nullpo_retr(0, sd);
  2600. WBUFW(buf,0)=0x1eb;
  2601. WBUFL(buf,2)=sd->status.account_id;
  2602. WBUFW(buf,6)=sd->bl.x;
  2603. WBUFW(buf,8)=sd->bl.y;
  2604. clif_send(buf,packet_len_table[0x1eb],&sd->bl,GUILD_SAMEMAP_WOS);
  2605. return 0;
  2606. }
  2607. // Guild XY locators [Valaris]
  2608. int clif_guild_xy_remove(struct map_session_data *sd)
  2609. {
  2610. unsigned char buf[10];
  2611. nullpo_retr(0, sd);
  2612. WBUFW(buf,0)=0x1eb;
  2613. WBUFL(buf,2)=sd->status.account_id;
  2614. WBUFW(buf,6)=-1;
  2615. WBUFW(buf,8)=-1;
  2616. clif_send(buf,packet_len_table[0x1eb],&sd->bl,GUILD_SAMEMAP_WOS);
  2617. return 0;
  2618. }
  2619. /*==========================================
  2620. * ステータスを送りつける
  2621. * 表示専用数字はこの中で計算して送る
  2622. *------------------------------------------
  2623. */
  2624. int clif_updatestatus(struct map_session_data *sd,int type)
  2625. {
  2626. int fd,len=8;
  2627. nullpo_retr(0, sd);
  2628. fd=sd->fd;
  2629. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2630. return 0;
  2631. WFIFOHEAD(fd, 14);
  2632. WFIFOW(fd,0)=0xb0;
  2633. WFIFOW(fd,2)=type;
  2634. switch(type){
  2635. // 00b0
  2636. case SP_WEIGHT:
  2637. pc_checkweighticon(sd);
  2638. WFIFOW(fd,0)=0xb0;
  2639. WFIFOW(fd,2)=type; //Added this packet back, Temp fix to the slow motion [Lupus]
  2640. WFIFOL(fd,4)=sd->weight;
  2641. break;
  2642. case SP_MAXWEIGHT:
  2643. WFIFOL(fd,4)=sd->max_weight;
  2644. break;
  2645. case SP_SPEED:
  2646. WFIFOL(fd,4)=sd->speed;
  2647. break;
  2648. case SP_BASELEVEL:
  2649. WFIFOL(fd,4)=sd->status.base_level;
  2650. break;
  2651. case SP_JOBLEVEL:
  2652. WFIFOL(fd,4)=sd->status.job_level;
  2653. break;
  2654. case SP_MANNER:
  2655. WFIFOL(fd,4)=sd->status.manner;
  2656. clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
  2657. break;
  2658. case SP_STATUSPOINT:
  2659. WFIFOL(fd,4)=sd->status.status_point;
  2660. break;
  2661. case SP_SKILLPOINT:
  2662. WFIFOL(fd,4)=sd->status.skill_point;
  2663. break;
  2664. case SP_HIT:
  2665. WFIFOL(fd,4)=sd->hit;
  2666. break;
  2667. case SP_FLEE1:
  2668. WFIFOL(fd,4)=sd->flee;
  2669. break;
  2670. case SP_FLEE2:
  2671. WFIFOL(fd,4)=sd->flee2/10;
  2672. break;
  2673. case SP_MAXHP:
  2674. WFIFOL(fd,4)=sd->status.max_hp;
  2675. break;
  2676. case SP_MAXSP:
  2677. WFIFOL(fd,4)=sd->status.max_sp;
  2678. break;
  2679. case SP_HP:
  2680. WFIFOL(fd,4)=sd->status.hp;
  2681. if (sd->status.party_id)
  2682. clif_party_hp(sd);
  2683. if (battle_config.disp_hpmeter)
  2684. clif_hpmeter(sd);
  2685. break;
  2686. case SP_SP:
  2687. WFIFOL(fd,4)=sd->status.sp;
  2688. break;
  2689. case SP_ASPD:
  2690. WFIFOL(fd,4)=sd->aspd;
  2691. break;
  2692. case SP_ATK1:
  2693. WFIFOL(fd,4)=sd->base_atk+sd->right_weapon.watk;
  2694. break;
  2695. case SP_DEF1:
  2696. WFIFOL(fd,4)=sd->def;
  2697. break;
  2698. case SP_MDEF1:
  2699. WFIFOL(fd,4)=sd->mdef;
  2700. break;
  2701. case SP_ATK2:
  2702. WFIFOL(fd,4)=sd->right_weapon.watk2;
  2703. break;
  2704. case SP_DEF2:
  2705. WFIFOL(fd,4)=sd->def2;
  2706. break;
  2707. case SP_MDEF2:
  2708. WFIFOL(fd,4)=sd->mdef2;
  2709. break;
  2710. case SP_CRITICAL:
  2711. WFIFOL(fd,4)=sd->critical/10;
  2712. break;
  2713. case SP_MATK1:
  2714. WFIFOL(fd,4)=sd->matk1;
  2715. break;
  2716. case SP_MATK2:
  2717. WFIFOL(fd,4)=sd->matk2;
  2718. break;
  2719. case SP_ZENY:
  2720. WFIFOW(fd,0)=0xb1;
  2721. if(sd->status.zeny < 0)
  2722. sd->status.zeny = 0;
  2723. WFIFOL(fd,4)=sd->status.zeny;
  2724. break;
  2725. case SP_BASEEXP:
  2726. WFIFOW(fd,0)=0xb1;
  2727. WFIFOL(fd,4)=sd->status.base_exp;
  2728. break;
  2729. case SP_JOBEXP:
  2730. WFIFOW(fd,0)=0xb1;
  2731. WFIFOL(fd,4)=sd->status.job_exp;
  2732. break;
  2733. case SP_NEXTBASEEXP:
  2734. WFIFOW(fd,0)=0xb1;
  2735. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2736. break;
  2737. case SP_NEXTJOBEXP:
  2738. WFIFOW(fd,0)=0xb1;
  2739. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2740. break;
  2741. // 00be 終了
  2742. case SP_USTR:
  2743. case SP_UAGI:
  2744. case SP_UVIT:
  2745. case SP_UINT:
  2746. case SP_UDEX:
  2747. case SP_ULUK:
  2748. WFIFOW(fd,0)=0xbe;
  2749. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2750. len=5;
  2751. break;
  2752. // 013a 終了
  2753. case SP_ATTACKRANGE:
  2754. WFIFOW(fd,0)=0x13a;
  2755. WFIFOW(fd,2)=sd->attackrange;
  2756. len=4;
  2757. break;
  2758. // 0141 終了
  2759. case SP_STR:
  2760. WFIFOW(fd,0)=0x141;
  2761. WFIFOL(fd,2)=type;
  2762. WFIFOL(fd,6)=sd->status.str;
  2763. WFIFOL(fd,10)=sd->paramb[0] + sd->parame[0];
  2764. len=14;
  2765. break;
  2766. case SP_AGI:
  2767. WFIFOW(fd,0)=0x141;
  2768. WFIFOL(fd,2)=type;
  2769. WFIFOL(fd,6)=sd->status.agi;
  2770. WFIFOL(fd,10)=sd->paramb[1] + sd->parame[1];
  2771. len=14;
  2772. break;
  2773. case SP_VIT:
  2774. WFIFOW(fd,0)=0x141;
  2775. WFIFOL(fd,2)=type;
  2776. WFIFOL(fd,6)=sd->status.vit;
  2777. WFIFOL(fd,10)=sd->paramb[2] + sd->parame[2];
  2778. len=14;
  2779. break;
  2780. case SP_INT:
  2781. WFIFOW(fd,0)=0x141;
  2782. WFIFOL(fd,2)=type;
  2783. WFIFOL(fd,6)=sd->status.int_;
  2784. WFIFOL(fd,10)=sd->paramb[3] + sd->parame[3];
  2785. len=14;
  2786. break;
  2787. case SP_DEX:
  2788. WFIFOW(fd,0)=0x141;
  2789. WFIFOL(fd,2)=type;
  2790. WFIFOL(fd,6)=sd->status.dex;
  2791. WFIFOL(fd,10)=sd->paramb[4] + sd->parame[4];
  2792. len=14;
  2793. break;
  2794. case SP_LUK:
  2795. WFIFOW(fd,0)=0x141;
  2796. WFIFOL(fd,2)=type;
  2797. WFIFOL(fd,6)=sd->status.luk;
  2798. WFIFOL(fd,10)=sd->paramb[5] + sd->parame[5];
  2799. len=14;
  2800. break;
  2801. case SP_CARTINFO:
  2802. WFIFOW(fd,0)=0x121;
  2803. WFIFOW(fd,2)=sd->cart_num;
  2804. WFIFOW(fd,4)=sd->cart_max_num;
  2805. WFIFOL(fd,6)=sd->cart_weight;
  2806. WFIFOL(fd,10)=sd->cart_max_weight;
  2807. len=14;
  2808. break;
  2809. default:
  2810. if(battle_config.error_log)
  2811. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2812. return 1;
  2813. }
  2814. WFIFOSET(fd,len);
  2815. return 0;
  2816. }
  2817. int clif_changestatus(struct block_list *bl,int type,int val)
  2818. {
  2819. unsigned char buf[12];
  2820. struct map_session_data *sd = NULL;
  2821. nullpo_retr(0, bl);
  2822. if(bl->type == BL_PC)
  2823. sd = (struct map_session_data *)bl;
  2824. //printf("clif_changestatus id:%d type:%d val:%d\n",bl->id,type,val);
  2825. if(sd){
  2826. WBUFW(buf,0)=0x1ab;
  2827. WBUFL(buf,2)=bl->id;
  2828. WBUFW(buf,6)=type;
  2829. switch(type){
  2830. case SP_MANNER:
  2831. WBUFL(buf,8)=val;
  2832. break;
  2833. default:
  2834. if(battle_config.error_log)
  2835. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2836. return 1;
  2837. }
  2838. clif_send(buf,packet_len_table[0x1ab],bl,AREA_WOS);
  2839. }
  2840. return 0;
  2841. }
  2842. /*==========================================
  2843. *
  2844. *------------------------------------------
  2845. */
  2846. int clif_changelook(struct block_list *bl,int type,int val)
  2847. {
  2848. unsigned char buf[32];
  2849. struct map_session_data *sd = NULL;
  2850. nullpo_retr(0, bl);
  2851. if(bl->type == BL_PC)
  2852. sd = (struct map_session_data *)bl;
  2853. #if PACKETVER < 4
  2854. if(sd && (type == LOOK_WEAPON || type == LOOK_SHIELD) && (sd->view_class == JOB_WEDDING || sd->view_class == JOB_XMAS))
  2855. val =0;
  2856. WBUFW(buf,0)=0xc3;
  2857. WBUFL(buf,2)=bl->id;
  2858. WBUFB(buf,6)=type;
  2859. WBUFB(buf,7)=val;
  2860. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2861. #else
  2862. if(sd && (type == LOOK_WEAPON || type == LOOK_SHIELD || type == LOOK_SHOES)) {
  2863. WBUFW(buf,0)=0x1d7;
  2864. WBUFL(buf,2)=bl->id;
  2865. if(type == LOOK_SHOES) {
  2866. WBUFB(buf,6)=9;
  2867. if(sd->equip_index[2] >= 0 && sd->inventory_data[sd->equip_index[2]]) {
  2868. if(sd->inventory_data[sd->equip_index[2]]->view_id > 0)
  2869. WBUFW(buf,7)=sd->inventory_data[sd->equip_index[2]]->view_id;
  2870. else
  2871. WBUFW(buf,7)=sd->status.inventory[sd->equip_index[2]].nameid;
  2872. } else
  2873. WBUFW(buf,7)=0;
  2874. WBUFW(buf,9)=0;
  2875. }
  2876. else {
  2877. WBUFB(buf,6)=2;
  2878. if(sd->equip_index[9] >= 0 && sd->inventory_data[sd->equip_index[9]] && sd->view_class != JOB_WEDDING && sd->view_class != JOB_XMAS) {
  2879. if(sd->inventory_data[sd->equip_index[9]]->view_id > 0)
  2880. WBUFW(buf,7)=sd->inventory_data[sd->equip_index[9]]->view_id;
  2881. else
  2882. WBUFW(buf,7)=sd->status.inventory[sd->equip_index[9]].nameid;
  2883. } else
  2884. WBUFW(buf,7)=0;
  2885. if(sd->equip_index[8] >= 0 && sd->equip_index[8] != sd->equip_index[9] && sd->inventory_data[sd->equip_index[8]] &&
  2886. sd->view_class != JOB_WEDDING && sd->view_class != JOB_XMAS) {
  2887. if(sd->inventory_data[sd->equip_index[8]]->view_id > 0)
  2888. WBUFW(buf,9)=sd->inventory_data[sd->equip_index[8]]->view_id;
  2889. else
  2890. WBUFW(buf,9)=sd->status.inventory[sd->equip_index[8]].nameid;
  2891. } else
  2892. WBUFW(buf,9)=0;
  2893. }
  2894. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2895. }
  2896. else if(sd && (type == LOOK_BASE) && (val > 255))
  2897. {
  2898. WBUFW(buf,0)=0x1d7;
  2899. WBUFL(buf,2)=bl->id;
  2900. WBUFB(buf,6)=type;
  2901. WBUFW(buf,7)=val;
  2902. WBUFW(buf,9)=0;
  2903. clif_send(buf,packet_len_table[0x1d7],bl,AREA);
  2904. } else {
  2905. WBUFW(buf,0)=0xc3;
  2906. WBUFL(buf,2)=bl->id;
  2907. WBUFB(buf,6)=type;
  2908. WBUFB(buf,7)=val;
  2909. clif_send(buf,packet_len_table[0xc3],bl,AREA);
  2910. }
  2911. #endif
  2912. return 0;
  2913. }
  2914. /*==========================================
  2915. *
  2916. *------------------------------------------
  2917. */
  2918. int clif_initialstatus(struct map_session_data *sd)
  2919. {
  2920. int fd;
  2921. unsigned char *buf;
  2922. nullpo_retr(0, sd);
  2923. fd=sd->fd;
  2924. WFIFOHEAD(fd,packet_len_table[0xbd]);
  2925. buf=WFIFOP(fd,0);
  2926. WBUFW(buf,0)=0xbd;
  2927. WBUFW(buf,2)=sd->status.status_point;
  2928. WBUFB(buf,4)=(sd->status.str > 255)? 255:sd->status.str;
  2929. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2930. WBUFB(buf,6)=(sd->status.agi > 255)? 255:sd->status.agi;
  2931. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2932. WBUFB(buf,8)=(sd->status.vit > 255)? 255:sd->status.vit;
  2933. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2934. WBUFB(buf,10)=(sd->status.int_ > 255)? 255:sd->status.int_;
  2935. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2936. WBUFB(buf,12)=(sd->status.dex > 255)? 255:sd->status.dex;
  2937. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2938. WBUFB(buf,14)=(sd->status.luk > 255)? 255:sd->status.luk;
  2939. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2940. WBUFW(buf,16) = sd->base_atk + sd->right_weapon.watk;
  2941. WBUFW(buf,18) = sd->right_weapon.watk2; //atk bonus
  2942. WBUFW(buf,20) = sd->matk1;
  2943. WBUFW(buf,22) = sd->matk2;
  2944. WBUFW(buf,24) = sd->def; // def
  2945. WBUFW(buf,26) = sd->def2;
  2946. WBUFW(buf,28) = sd->mdef; // mdef
  2947. WBUFW(buf,30) = sd->mdef2;
  2948. WBUFW(buf,32) = sd->hit;
  2949. WBUFW(buf,34) = sd->flee;
  2950. WBUFW(buf,36) = sd->flee2/10;
  2951. WBUFW(buf,38) = sd->critical/10;
  2952. WBUFW(buf,40) = sd->status.karma;
  2953. WBUFW(buf,42) = sd->status.manner;
  2954. WFIFOSET(fd,packet_len_table[0xbd]);
  2955. clif_updatestatus(sd,SP_STR);
  2956. clif_updatestatus(sd,SP_AGI);
  2957. clif_updatestatus(sd,SP_VIT);
  2958. clif_updatestatus(sd,SP_INT);
  2959. clif_updatestatus(sd,SP_DEX);
  2960. clif_updatestatus(sd,SP_LUK);
  2961. clif_updatestatus(sd,SP_ATTACKRANGE);
  2962. clif_updatestatus(sd,SP_ASPD);
  2963. return 0;
  2964. }
  2965. /*==========================================
  2966. *矢装備
  2967. *------------------------------------------
  2968. */
  2969. int clif_arrowequip(struct map_session_data *sd,int val)
  2970. {
  2971. int fd;
  2972. nullpo_retr(0, sd);
  2973. if(sd->attacktarget && sd->attacktarget > 0) // [Valaris]
  2974. sd->attacktarget = 0;
  2975. fd=sd->fd;
  2976. WFIFOHEAD(fd, packet_len_table[0x013c]);
  2977. WFIFOW(fd,0)=0x013c;
  2978. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2979. WFIFOSET(fd,packet_len_table[0x013c]);
  2980. return 0;
  2981. }
  2982. /*==========================================
  2983. *
  2984. *------------------------------------------
  2985. */
  2986. int clif_arrow_fail(struct map_session_data *sd,int type)
  2987. {
  2988. int fd;
  2989. nullpo_retr(0, sd);
  2990. fd=sd->fd;
  2991. WFIFOHEAD(fd, packet_len_table[0x013b]);
  2992. WFIFOW(fd,0)=0x013b;
  2993. WFIFOW(fd,2)=type;
  2994. WFIFOSET(fd,packet_len_table[0x013b]);
  2995. return 0;
  2996. }
  2997. /*==========================================
  2998. * 作成可能 矢リスト送信
  2999. *------------------------------------------
  3000. */
  3001. int clif_arrow_create_list(struct map_session_data *sd)
  3002. {
  3003. int i, c, j;
  3004. int fd;
  3005. nullpo_retr(0, sd);
  3006. fd = sd->fd;
  3007. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  3008. WFIFOW(fd,0) = 0x1ad;
  3009. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  3010. if (skill_arrow_db[i].nameid > 0 &&
  3011. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  3012. !sd->status.inventory[j].equip)
  3013. {
  3014. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  3015. WFIFOW(fd,c*2+4) = j;
  3016. else
  3017. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  3018. c++;
  3019. }
  3020. }
  3021. WFIFOW(fd,2) = c*2+4;
  3022. WFIFOSET(fd, WFIFOW(fd,2));
  3023. if (c > 0) sd->state.produce_flag = 1;
  3024. return 0;
  3025. }
  3026. /*==========================================
  3027. *
  3028. *------------------------------------------
  3029. */
  3030. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  3031. {
  3032. int fd;
  3033. nullpo_retr(0, sd);
  3034. fd=sd->fd;
  3035. WFIFOHEAD(fd,packet_len_table[0xbc]);
  3036. WFIFOW(fd,0)=0xbc;
  3037. WFIFOW(fd,2)=type;
  3038. WFIFOB(fd,4)=ok;
  3039. WFIFOB(fd,5)=val;
  3040. WFIFOSET(fd,packet_len_table[0xbc]);
  3041. return 0;
  3042. }
  3043. /*==========================================
  3044. *
  3045. *------------------------------------------
  3046. */
  3047. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3048. {
  3049. int fd;
  3050. nullpo_retr(0, sd);
  3051. fd=sd->fd;
  3052. WFIFOHEAD(fd,packet_len_table[0xaa]);
  3053. WFIFOW(fd,0)=0xaa;
  3054. WFIFOW(fd,2)=n+2;
  3055. WFIFOW(fd,4)=pos;
  3056. WFIFOB(fd,6)=ok;
  3057. WFIFOSET(fd,packet_len_table[0xaa]);
  3058. return 0;
  3059. }
  3060. /*==========================================
  3061. *
  3062. *------------------------------------------
  3063. */
  3064. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3065. {
  3066. int fd;
  3067. nullpo_retr(0, sd);
  3068. fd=sd->fd;
  3069. WFIFOHEAD(fd,packet_len_table[0xac]);
  3070. WFIFOW(fd,0)=0xac;
  3071. WFIFOW(fd,2)=n+2;
  3072. WFIFOW(fd,4)=pos;
  3073. WFIFOB(fd,6)=ok;
  3074. WFIFOSET(fd,packet_len_table[0xac]);
  3075. return 0;
  3076. }
  3077. /*==========================================
  3078. *
  3079. *------------------------------------------
  3080. */
  3081. int clif_misceffect(struct block_list* bl,int type)
  3082. {
  3083. unsigned char buf[32];
  3084. nullpo_retr(0, bl);
  3085. WBUFW(buf,0) = 0x19b;
  3086. WBUFL(buf,2) = bl->id;
  3087. WBUFL(buf,6) = type;
  3088. clif_send(buf,packet_len_table[0x19b],bl,AREA);
  3089. return 0;
  3090. }
  3091. int clif_misceffect2(struct block_list *bl, int type) {
  3092. unsigned char buf[24];
  3093. nullpo_retr(0, bl);
  3094. memset(buf, 0, packet_len_table[0x1f3]);
  3095. WBUFW(buf,0) = 0x1f3;
  3096. WBUFL(buf,2) = bl->id;
  3097. WBUFL(buf,6) = type;
  3098. clif_send(buf, packet_len_table[0x1f3], bl, AREA);
  3099. return 0;
  3100. }
  3101. /*==========================================
  3102. * 表示オプション変更
  3103. *------------------------------------------
  3104. */
  3105. int clif_changeoption(struct block_list* bl)
  3106. {
  3107. unsigned char buf[32];
  3108. struct status_change *sc;
  3109. nullpo_retr(0, bl);
  3110. sc = status_get_sc(bl);
  3111. WBUFW(buf,0) = 0x119;
  3112. if(bl->type==BL_PC && ((struct map_session_data *)bl)->disguise) {
  3113. WBUFL(buf,2) = bl->id;
  3114. WBUFW(buf,6) = 0;
  3115. WBUFW(buf,8) = 0;
  3116. WBUFW(buf,10) = OPTION_INVISIBLE;
  3117. WBUFB(buf,12) = 0;
  3118. clif_send(buf,packet_len_table[0x119],bl,AREA);
  3119. WBUFL(buf,2) = -bl->id;
  3120. WBUFW(buf,6) = 0;
  3121. WBUFW(buf,8) = 0;
  3122. WBUFW(buf,10) = sc?sc->option:0;
  3123. WBUFB(buf,12) = 0;
  3124. clif_send(buf,packet_len_table[0x119],bl,AREA);
  3125. } else {
  3126. WBUFL(buf,2) = bl->id;
  3127. WBUFW(buf,6) = sc?sc->opt1:0;
  3128. WBUFW(buf,8) = sc?sc->opt2:0;
  3129. WBUFW(buf,10) = sc?sc->option:0;
  3130. WBUFB(buf,12) = 0; // ??
  3131. clif_send(buf,packet_len_table[0x119],bl,AREA);
  3132. }
  3133. return 0;
  3134. }
  3135. /*==========================================
  3136. *
  3137. *------------------------------------------
  3138. */
  3139. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  3140. {
  3141. nullpo_retr(0, sd);
  3142. if(!ok) {
  3143. int fd=sd->fd;
  3144. WFIFOHEAD(fd,packet_len_table[0xa8]);
  3145. WFIFOW(fd,0)=0xa8;
  3146. WFIFOW(fd,2)=index+2;
  3147. WFIFOW(fd,4)=amount;
  3148. WFIFOB(fd,6)=ok;
  3149. WFIFOSET(fd,packet_len_table[0xa8]);
  3150. }
  3151. else {
  3152. #if PACKETVER < 3
  3153. int fd=sd->fd;
  3154. WFIFOHEAD(fd,packet_len_table[0xa8]);
  3155. WFIFOW(fd,0)=0xa8;
  3156. WFIFOW(fd,2)=index+2;
  3157. WFIFOW(fd,4)=amount;
  3158. WFIFOB(fd,6)=ok;
  3159. WFIFOSET(fd,packet_len_table[0xa8]);
  3160. #else
  3161. unsigned char buf[32];
  3162. WBUFW(buf,0)=0x1c8;
  3163. WBUFW(buf,2)=index+2;
  3164. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3165. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3166. else
  3167. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  3168. WBUFL(buf,6)=sd->bl.id;
  3169. WBUFW(buf,10)=amount;
  3170. WBUFB(buf,12)=ok;
  3171. clif_send(buf,packet_len_table[0x1c8],&sd->bl,AREA);
  3172. #endif
  3173. }
  3174. return 0;
  3175. }
  3176. /*==========================================
  3177. *
  3178. *------------------------------------------
  3179. */
  3180. int clif_createchat(struct map_session_data *sd,int fail)
  3181. {
  3182. int fd;
  3183. nullpo_retr(0, sd);
  3184. fd=sd->fd;
  3185. WFIFOHEAD(fd,packet_len_table[0xd6]);
  3186. WFIFOW(fd,0)=0xd6;
  3187. WFIFOB(fd,2)=fail;
  3188. WFIFOSET(fd,packet_len_table[0xd6]);
  3189. return 0;
  3190. }
  3191. /*==========================================
  3192. *
  3193. *------------------------------------------
  3194. */
  3195. int clif_dispchat(struct chat_data *cd,int fd)
  3196. {
  3197. unsigned char buf[128]; // 最大title(60バイト)+17
  3198. if(cd==NULL || *cd->owner==NULL)
  3199. return 1;
  3200. WBUFW(buf,0)=0xd7;
  3201. WBUFW(buf,2)=strlen((const char*)cd->title)+17;
  3202. WBUFL(buf,4)=(*cd->owner)->id;
  3203. WBUFL(buf,8)=cd->bl.id;
  3204. WBUFW(buf,12)=cd->limit;
  3205. WBUFW(buf,14)=cd->users;
  3206. WBUFB(buf,16)=cd->pub;
  3207. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  3208. if(fd){
  3209. WFIFOHEAD(fd, WBUFW(buf,2));
  3210. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3211. WFIFOSET(fd,WBUFW(buf,2));
  3212. } else {
  3213. clif_send(buf,WBUFW(buf,2),*cd->owner,AREA_WOSC);
  3214. }
  3215. return 0;
  3216. }
  3217. /*==========================================
  3218. * chatの状態変更成功
  3219. * 外部の人用と命令コード(d7->df)が違うだけ
  3220. *------------------------------------------
  3221. */
  3222. int clif_changechatstatus(struct chat_data *cd)
  3223. {
  3224. unsigned char buf[128]; // 最大title(60バイト)+17
  3225. if(cd==NULL || cd->usersd[0]==NULL)
  3226. return 1;
  3227. WBUFW(buf,0)=0xdf;
  3228. WBUFW(buf,2)=strlen((char*)cd->title)+17;
  3229. WBUFL(buf,4)=cd->usersd[0]->bl.id;
  3230. WBUFL(buf,8)=cd->bl.id;
  3231. WBUFW(buf,12)=cd->limit;
  3232. WBUFW(buf,14)=cd->users;
  3233. WBUFB(buf,16)=cd->pub;
  3234. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  3235. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  3236. return 0;
  3237. }
  3238. /*==========================================
  3239. *
  3240. *------------------------------------------
  3241. */
  3242. int clif_clearchat(struct chat_data *cd,int fd)
  3243. {
  3244. unsigned char buf[32];
  3245. nullpo_retr(0, cd);
  3246. WBUFW(buf,0)=0xd8;
  3247. WBUFL(buf,2)=cd->bl.id;
  3248. if(fd){
  3249. WFIFOHEAD(fd,packet_len_table[0xd8]);
  3250. memcpy(WFIFOP(fd,0),buf,packet_len_table[0xd8]);
  3251. WFIFOSET(fd,packet_len_table[0xd8]);
  3252. } else {
  3253. clif_send(buf,packet_len_table[0xd8],*cd->owner,AREA_WOSC);
  3254. }
  3255. return 0;
  3256. }
  3257. /*==========================================
  3258. *
  3259. *------------------------------------------
  3260. */
  3261. int clif_joinchatfail(struct map_session_data *sd,int fail)
  3262. {
  3263. int fd;
  3264. nullpo_retr(0, sd);
  3265. fd=sd->fd;
  3266. WFIFOHEAD(fd,packet_len_table[0xda]);
  3267. WFIFOW(fd,0)=0xda;
  3268. WFIFOB(fd,2)=fail;
  3269. WFIFOSET(fd,packet_len_table[0xda]);
  3270. return 0;
  3271. }
  3272. /*==========================================
  3273. *
  3274. *------------------------------------------
  3275. */
  3276. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3277. {
  3278. int fd;
  3279. int i;
  3280. nullpo_retr(0, sd);
  3281. nullpo_retr(0, cd);
  3282. fd = sd->fd;
  3283. if (!session_isActive(fd))
  3284. return 0;
  3285. WFIFOHEAD(fd, 8 + (28*cd->users));
  3286. WFIFOW(fd, 0) = 0xdb;
  3287. WFIFOW(fd, 2) = 8 + (28*cd->users);
  3288. WFIFOL(fd, 4) = cd->bl.id;
  3289. for (i = 0; i < cd->users; i++) {
  3290. WFIFOL(fd, 8+i*28) = (i!=0) || ((*cd->owner)->type == BL_NPC);
  3291. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3292. }
  3293. WFIFOSET(fd, WFIFOW(fd, 2));
  3294. return 0;
  3295. }
  3296. /*==========================================
  3297. *
  3298. *------------------------------------------
  3299. */
  3300. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3301. {
  3302. unsigned char buf[32];
  3303. nullpo_retr(0, sd);
  3304. nullpo_retr(0, cd);
  3305. WBUFW(buf, 0) = 0x0dc;
  3306. WBUFW(buf, 2) = cd->users;
  3307. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  3308. clif_send(buf,packet_len_table[0xdc],&sd->bl,CHAT_WOS);
  3309. return 0;
  3310. }
  3311. /*==========================================
  3312. *
  3313. *------------------------------------------
  3314. */
  3315. int clif_changechatowner(struct chat_data* cd,struct map_session_data *sd)
  3316. {
  3317. unsigned char buf[64];
  3318. nullpo_retr(0, sd);
  3319. nullpo_retr(0, cd);
  3320. WBUFW(buf, 0) = 0xe1;
  3321. WBUFL(buf, 2) = 1;
  3322. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3323. WBUFW(buf,30) = 0xe1;
  3324. WBUFL(buf,32) = 0;
  3325. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  3326. clif_send(buf,packet_len_table[0xe1]*2,&sd->bl,CHAT);
  3327. return 0;
  3328. }
  3329. /*==========================================
  3330. *
  3331. *------------------------------------------
  3332. */
  3333. int clif_leavechat(struct chat_data* cd,struct map_session_data *sd)
  3334. {
  3335. unsigned char buf[32];
  3336. nullpo_retr(0, sd);
  3337. nullpo_retr(0, cd);
  3338. WBUFW(buf, 0) = 0xdd;
  3339. WBUFW(buf, 2) = cd->users-1;
  3340. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  3341. WBUFB(buf,28) = 0;
  3342. clif_send(buf,packet_len_table[0xdd],&sd->bl,CHAT);
  3343. return 0;
  3344. }
  3345. /*==========================================
  3346. * 取り引き要請受け
  3347. *------------------------------------------
  3348. */
  3349. int clif_traderequest(struct map_session_data *sd,char *name)
  3350. {
  3351. int fd;
  3352. nullpo_retr(0, sd);
  3353. fd=sd->fd;
  3354. WFIFOHEAD(fd,packet_len_table[0xe5]);
  3355. WFIFOW(fd,0)=0xe5;
  3356. strcpy((char*)WFIFOP(fd,2),name);
  3357. WFIFOSET(fd,packet_len_table[0xe5]);
  3358. return 0;
  3359. }
  3360. /*==========================================
  3361. * 取り引き要求応答
  3362. *------------------------------------------
  3363. */
  3364. int clif_tradestart(struct map_session_data *sd,int type)
  3365. {
  3366. int fd;
  3367. nullpo_retr(0, sd);
  3368. fd=sd->fd;
  3369. WFIFOHEAD(fd,packet_len_table[0xe7]);
  3370. WFIFOW(fd,0)=0xe7;
  3371. WFIFOB(fd,2)=type;
  3372. WFIFOSET(fd,packet_len_table[0xe7]);
  3373. return 0;
  3374. }
  3375. /*==========================================
  3376. * 相手方からのアイテム追加
  3377. *------------------------------------------
  3378. */
  3379. int clif_tradeadditem(struct map_session_data *sd,struct map_session_data *tsd,int index,int amount)
  3380. {
  3381. int fd;
  3382. nullpo_retr(0, sd);
  3383. nullpo_retr(0, tsd);
  3384. fd=tsd->fd;
  3385. WFIFOHEAD(fd,packet_len_table[0xe9]);
  3386. WFIFOW(fd,0)=0xe9;
  3387. WFIFOL(fd,2)=amount;
  3388. if(index==0){
  3389. WFIFOW(fd,6) = 0; // type id
  3390. WFIFOB(fd,8) = 0; //identify flag
  3391. WFIFOB(fd,9) = 0; // attribute
  3392. WFIFOB(fd,10)= 0; //refine
  3393. WFIFOW(fd,11)= 0; //card (4w)
  3394. WFIFOW(fd,13)= 0; //card (4w)
  3395. WFIFOW(fd,15)= 0; //card (4w)
  3396. WFIFOW(fd,17)= 0; //card (4w)
  3397. }
  3398. else{
  3399. index-=2; //index fix
  3400. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3401. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  3402. else
  3403. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  3404. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  3405. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  3406. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  3407. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  3408. }
  3409. WFIFOSET(fd,packet_len_table[0xe9]);
  3410. return 0;
  3411. }
  3412. /*==========================================
  3413. * アイテム追加成功/失敗
  3414. *------------------------------------------
  3415. */
  3416. int clif_tradeitemok(struct map_session_data *sd,int index,int fail)
  3417. {
  3418. int fd;
  3419. nullpo_retr(0, sd);
  3420. fd=sd->fd;
  3421. WFIFOHEAD(fd,packet_len_table[0xea]);
  3422. WFIFOW(fd,0)=0xea;
  3423. WFIFOW(fd,2)=index;
  3424. WFIFOB(fd,4)=fail;
  3425. WFIFOSET(fd,packet_len_table[0xea]);
  3426. return 0;
  3427. }
  3428. /*==========================================
  3429. * 取り引きok押し
  3430. *------------------------------------------
  3431. */
  3432. int clif_tradedeal_lock(struct map_session_data *sd,int fail)
  3433. {
  3434. int fd;
  3435. nullpo_retr(0, sd);
  3436. fd=sd->fd;
  3437. WFIFOHEAD(fd,packet_len_table[0xec]);
  3438. WFIFOW(fd,0)=0xec;
  3439. WFIFOB(fd,2)=fail; // 0=you 1=the other person
  3440. WFIFOSET(fd,packet_len_table[0xec]);
  3441. return 0;
  3442. }
  3443. /*==========================================
  3444. * 取り引きがキャンセルされました
  3445. *------------------------------------------
  3446. */
  3447. int clif_tradecancelled(struct map_session_data *sd)
  3448. {
  3449. int fd;
  3450. nullpo_retr(0, sd);
  3451. fd=sd->fd;
  3452. WFIFOHEAD(fd,packet_len_table[0xee]);
  3453. WFIFOW(fd,0)=0xee;
  3454. WFIFOSET(fd,packet_len_table[0xee]);
  3455. return 0;
  3456. }
  3457. /*==========================================
  3458. * 取り引き完了
  3459. *------------------------------------------
  3460. */
  3461. int clif_tradecompleted(struct map_session_data *sd,int fail)
  3462. {
  3463. int fd;
  3464. nullpo_retr(0, sd);
  3465. fd=sd->fd;
  3466. WFIFOHEAD(fd,packet_len_table[0xf0]);
  3467. WFIFOW(fd,0)=0xf0;
  3468. WFIFOB(fd,2)=fail;
  3469. WFIFOSET(fd,packet_len_table[0xf0]);
  3470. return 0;
  3471. }
  3472. /*==========================================
  3473. * カプラ倉庫のアイテム数を更新
  3474. *------------------------------------------
  3475. */
  3476. int clif_updatestorageamount(struct map_session_data *sd,struct storage *stor)
  3477. {
  3478. int fd;
  3479. nullpo_retr(0, sd);
  3480. nullpo_retr(0, stor);
  3481. fd=sd->fd;
  3482. WFIFOHEAD(fd,packet_len_table[0xf2]);
  3483. WFIFOW(fd,0) = 0xf2; // update storage amount
  3484. WFIFOW(fd,2) = stor->storage_amount; //items
  3485. WFIFOW(fd,4) = MAX_STORAGE; //items max
  3486. WFIFOSET(fd,packet_len_table[0xf2]);
  3487. return 0;
  3488. }
  3489. /*==========================================
  3490. * カプラ倉庫にアイテムを追加する
  3491. *------------------------------------------
  3492. */
  3493. int clif_storageitemadded(struct map_session_data *sd,struct storage *stor,int index,int amount)
  3494. {
  3495. int view,fd;
  3496. nullpo_retr(0, sd);
  3497. nullpo_retr(0, stor);
  3498. fd=sd->fd;
  3499. WFIFOHEAD(fd,packet_len_table[0xf4]);
  3500. WFIFOW(fd,0) =0xf4; // Storage item added
  3501. WFIFOW(fd,2) =index+1; // index
  3502. WFIFOL(fd,4) =amount; // amount
  3503. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3504. WFIFOW(fd,8) =view;
  3505. else
  3506. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3507. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3508. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3509. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3510. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3511. WFIFOSET(fd,packet_len_table[0xf4]);
  3512. return 0;
  3513. }
  3514. /*==========================================
  3515. *
  3516. *------------------------------------------
  3517. */
  3518. int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor)
  3519. {
  3520. int fd;
  3521. nullpo_retr(0, sd);
  3522. nullpo_retr(0, stor);
  3523. fd=sd->fd;
  3524. WFIFOHEAD(fd,packet_len_table[0xf2]);
  3525. WFIFOW(fd,0) = 0xf2; // update storage amount
  3526. WFIFOW(fd,2) = stor->storage_amount; //items
  3527. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  3528. WFIFOSET(fd,packet_len_table[0xf2]);
  3529. return 0;
  3530. }
  3531. /*==========================================
  3532. *
  3533. *------------------------------------------
  3534. */
  3535. int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount)
  3536. {
  3537. int view,fd;
  3538. nullpo_retr(0, sd);
  3539. nullpo_retr(0, stor);
  3540. fd=sd->fd;
  3541. WFIFOHEAD(fd,packet_len_table[0xf4]);
  3542. WFIFOW(fd,0) =0xf4; // Storage item added
  3543. WFIFOW(fd,2) =index+1; // index
  3544. WFIFOL(fd,4) =amount; // amount
  3545. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3546. WFIFOW(fd,8) =view;
  3547. else
  3548. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3549. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3550. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3551. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3552. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3553. WFIFOSET(fd,packet_len_table[0xf4]);
  3554. return 0;
  3555. }
  3556. /*==========================================
  3557. * カプラ倉庫からアイテムを取り去る
  3558. *------------------------------------------
  3559. */
  3560. int clif_storageitemremoved(struct map_session_data *sd,int index,int amount)
  3561. {
  3562. int fd;
  3563. nullpo_retr(0, sd);
  3564. fd=sd->fd;
  3565. WFIFOHEAD(fd,packet_len_table[0xf6]);
  3566. WFIFOW(fd,0)=0xf6; // Storage item removed
  3567. WFIFOW(fd,2)=index+1;
  3568. WFIFOL(fd,4)=amount;
  3569. WFIFOSET(fd,packet_len_table[0xf6]);
  3570. return 0;
  3571. }
  3572. /*==========================================
  3573. * カプラ倉庫を閉じる
  3574. *------------------------------------------
  3575. */
  3576. int clif_storageclose(struct map_session_data *sd)
  3577. {
  3578. int fd;
  3579. nullpo_retr(0, sd);
  3580. fd=sd->fd;
  3581. WFIFOHEAD(fd,packet_len_table[0xf8]);
  3582. WFIFOW(fd,0)=0xf8; // Storage Closed
  3583. WFIFOSET(fd,packet_len_table[0xf8]);
  3584. return 0;
  3585. }
  3586. //
  3587. // callback系 ?
  3588. //
  3589. /*==========================================
  3590. * PC表示
  3591. *------------------------------------------
  3592. */
  3593. void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3594. {
  3595. int len;
  3596. nullpo_retv(sd);
  3597. nullpo_retv(dstsd);
  3598. if(dstsd->walktimer != -1){
  3599. #if PACKETVER < 4
  3600. WFIFOHEAD(sd->fd, packet_len_table[0x7b]);
  3601. #else
  3602. WFIFOHEAD(sd->fd, packet_len_table[0x1da]);
  3603. #endif
  3604. len = clif_set007b(dstsd,WFIFOP(sd->fd,0));
  3605. WFIFOSET(sd->fd,len);
  3606. if(dstsd->disguise) {
  3607. WFIFOHEAD(sd->fd,packet_len_table[0x7b]);
  3608. len = clif_dis007b(dstsd,WFIFOP(sd->fd,0));
  3609. WFIFOSET(sd->fd,len);
  3610. }
  3611. } else {
  3612. #if PACKETVER < 4
  3613. WFIFOHEAD(sd->fd,packet_len_table[0x78]);
  3614. #else
  3615. WFIFOHEAD(sd->fd,packet_len_table[0x1d8]);
  3616. #endif
  3617. len = clif_set0078(dstsd,WFIFOP(sd->fd,0));
  3618. WFIFOSET(sd->fd,len);
  3619. if(dstsd->disguise) {
  3620. WFIFOHEAD(sd->fd,packet_len_table[0x7b]);
  3621. len = clif_dis0078(dstsd,WFIFOP(sd->fd,0));
  3622. WFIFOSET(sd->fd,len);
  3623. }
  3624. }
  3625. if(dstsd->chatID){
  3626. struct chat_data *cd;
  3627. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  3628. if(cd->usersd[0]==dstsd)
  3629. clif_dispchat(cd,sd->fd);
  3630. }
  3631. if(dstsd->vender_id){
  3632. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3633. }
  3634. if(dstsd->spiritball > 0) {
  3635. WFIFOHEAD(sd->fd, packet_len_table[0x1e1]);
  3636. clif_set01e1(dstsd,WFIFOP(sd->fd,0));
  3637. WFIFOSET(sd->fd,packet_len_table[0x1e1]);
  3638. }
  3639. if(battle_config.save_clothcolor && dstsd->status.clothes_color > 0 && ((dstsd->view_class != JOB_WEDDING && dstsd->view_class !=JOB_XMAS) ||
  3640. (dstsd->view_class==JOB_WEDDING && !battle_config.wedding_ignorepalette) || (dstsd->view_class==JOB_XMAS && !battle_config.xmas_ignorepalette)))
  3641. clif_changelook(&dstsd->bl, LOOK_CLOTHES_COLOR, dstsd->status.clothes_color);
  3642. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3643. (battle_config.disp_hpmeter && (len = pc_isGM(sd)) >= battle_config.disp_hpmeter && len >= pc_isGM(dstsd))
  3644. )
  3645. clif_hpmeter_single(sd->fd, dstsd);
  3646. if(sd->status.manner < 0 && battle_config.manner_system)
  3647. clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
  3648. if(sd->state.size==2) // tiny/big players [Valaris]
  3649. clif_specialeffect(&sd->bl,423,0);
  3650. else if(sd->state.size==1)
  3651. clif_specialeffect(&sd->bl,421,0);
  3652. // pvp circle for duel [LuzZza]
  3653. /*
  3654. if(dstsd->duel_group)
  3655. clif_specialeffect(&dstsd->bl, 159, 4);
  3656. */
  3657. }
  3658. /*==========================================
  3659. * NPC表示
  3660. *------------------------------------------
  3661. */
  3662. //fixed by Valaris
  3663. void clif_getareachar_npc(struct map_session_data* sd,struct npc_data* nd)
  3664. {
  3665. int len;
  3666. nullpo_retv(sd);
  3667. nullpo_retv(nd);
  3668. if(nd->class_ < 0 || nd->flag&1 || nd->class_ == INVISIBLE_CLASS)
  3669. return;
  3670. if(nd->state.state == MS_WALK){
  3671. WFIFOHEAD(sd->fd, packet_len_table[0x7b]);
  3672. len = clif_npc007b(nd,WFIFOP(sd->fd,0));
  3673. WFIFOSET(sd->fd,len);
  3674. } else {
  3675. WFIFOHEAD(sd->fd, packet_len_table[0x78]);
  3676. len = clif_npc0078(nd,WFIFOP(sd->fd,0));
  3677. WFIFOSET(sd->fd,len);
  3678. }
  3679. if(nd->chat_id){
  3680. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3681. }
  3682. }
  3683. /*==========================================
  3684. * 移動停止
  3685. *------------------------------------------
  3686. */
  3687. int clif_movemob(struct mob_data *md)
  3688. {
  3689. unsigned char buf[256];
  3690. int len;
  3691. nullpo_retr(0, md);
  3692. len = clif_mob007b(md,buf);
  3693. clif_send(buf,len,&md->bl,AREA);
  3694. if(battle_config.save_clothcolor && pcdb_checkid(mob_get_viewclass(md->class_)) && mob_get_clothes_color(md->class_)) // [Valaris]
  3695. clif_changelook(&md->bl, LOOK_CLOTHES_COLOR, mob_get_clothes_color(md->class_));
  3696. if(mob_get_equip(md->class_) > 0) // mob equipment [Valaris]
  3697. clif_mob_equip(md,mob_get_equip(md->class_));
  3698. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3699. clif_specialeffect(&md->bl,423,0);
  3700. else if(md->special_state.size==1)
  3701. clif_specialeffect(&md->bl,421,0);
  3702. return 0;
  3703. }
  3704. /*==========================================
  3705. * モンスターの位置修正
  3706. *------------------------------------------
  3707. */
  3708. int clif_fixmobpos(struct mob_data *md)
  3709. {
  3710. unsigned char buf[256];
  3711. int len;
  3712. nullpo_retr(0, md);
  3713. if(md->state.state == MS_WALK){
  3714. len = clif_mob007b(md,buf);
  3715. clif_send(buf,len,&md->bl,AREA);
  3716. } else {
  3717. len = clif_mob0078(md,buf);
  3718. clif_send(buf,len,&md->bl,AREA);
  3719. }
  3720. return 0;
  3721. }
  3722. /*==========================================
  3723. * PCの位置修正
  3724. *------------------------------------------
  3725. */
  3726. int clif_fixpcpos(struct map_session_data *sd)
  3727. {
  3728. unsigned char buf[256];
  3729. int len;
  3730. nullpo_retr(0, sd);
  3731. if(sd->walktimer != -1){
  3732. len = clif_set007b(sd,buf);
  3733. clif_send(buf,len,&sd->bl,AREA);
  3734. } else {
  3735. len = clif_set0078(sd,buf);
  3736. clif_send(buf,len,&sd->bl,AREA);
  3737. }
  3738. return 0;
  3739. }
  3740. /*==========================================
  3741. *
  3742. *------------------------------------------
  3743. */
  3744. int clif_fixpetpos(struct pet_data *pd)
  3745. {
  3746. unsigned char buf[256];
  3747. int len;
  3748. nullpo_retr(0, pd);
  3749. if(pd->state.state == MS_WALK){
  3750. len = clif_pet007b(pd,buf);
  3751. clif_send(buf,len,&pd->bl,AREA);
  3752. } else {
  3753. len = clif_pet0078(pd,buf);
  3754. clif_send(buf,len,&pd->bl,AREA);
  3755. }
  3756. return 0;
  3757. }
  3758. // npc walking [Valaris]
  3759. int clif_fixnpcpos(struct npc_data *nd)
  3760. {
  3761. unsigned char buf[256];
  3762. int len;
  3763. nullpo_retr(0, nd);
  3764. if(nd->state.state == MS_WALK){
  3765. len = clif_npc007b(nd,buf);
  3766. clif_send(buf,len,&nd->bl,AREA);
  3767. } else {
  3768. len = clif_npc0078(nd,buf);
  3769. clif_send(buf,len,&nd->bl,AREA);
  3770. }
  3771. return 0;
  3772. }
  3773. /*==========================================
  3774. * Modifies the type of damage according to status changes [Skotlex]
  3775. *------------------------------------------
  3776. */
  3777. static int clif_calc_delay(struct block_list *dst, int type, int delay)
  3778. {
  3779. if (type == 1 || type == 4 || type == 0x0a) //Type 1 is the crouching animation, type 4 are non-flinching attacks, 0x0a - crits.
  3780. return type;
  3781. if (delay == 0)
  3782. return 9; //Endure type attack (damage delay is 0)
  3783. return type;
  3784. }
  3785. /*==========================================
  3786. * 通常攻撃エフェクト&ダメージ
  3787. *------------------------------------------
  3788. */
  3789. 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)
  3790. {
  3791. unsigned char buf[256];
  3792. struct status_change *sc;
  3793. nullpo_retr(0, src);
  3794. nullpo_retr(0, dst);
  3795. type = clif_calc_delay(dst, type, ddelay); //Type defaults to 0 for normal attacks.
  3796. sc = status_get_sc(dst);
  3797. if(sc && sc->count) {
  3798. if(sc->data[SC_HALLUCINATION].timer != -1) {
  3799. if(damage > 0)
  3800. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3801. if(damage2 > 0)
  3802. damage2 = damage2*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3803. }
  3804. }
  3805. WBUFW(buf,0)=0x8a;
  3806. if(src->type==BL_PC && ((struct map_session_data *)src)->disguise)
  3807. WBUFL(buf,2)=-src->id;
  3808. else
  3809. WBUFL(buf,2)=src->id;
  3810. if(dst->type==BL_PC && ((struct map_session_data *)dst)->disguise)
  3811. WBUFL(buf,6)=-dst->id;
  3812. else
  3813. WBUFL(buf,6)=dst->id;
  3814. WBUFL(buf,10)=tick;
  3815. WBUFL(buf,14)=sdelay;
  3816. WBUFL(buf,18)=ddelay;
  3817. WBUFW(buf,22)=(damage > 0x7fff)? 0x7fff:damage;
  3818. WBUFW(buf,24)=div;
  3819. WBUFB(buf,26)=type;
  3820. WBUFW(buf,27)=damage2;
  3821. clif_send(buf,packet_len_table[0x8a],src,AREA);
  3822. if((src->type==BL_PC && ((struct map_session_data *)src)->disguise) || (dst->type==BL_PC && ((struct map_session_data *)dst)->disguise)) {
  3823. memset(buf,0,packet_len_table[0x8a]);
  3824. WBUFW(buf,0)=0x8a;
  3825. if(src->type==BL_PC && ((struct map_session_data *)src)->disguise)
  3826. WBUFL(buf,2)=src->id;
  3827. else
  3828. WBUFL(buf,2)=-src->id;
  3829. if(dst->type==BL_PC && ((struct map_session_data *)dst)->disguise)
  3830. WBUFL(buf,6)=dst->id;
  3831. else
  3832. WBUFL(buf,2)=-dst->id;
  3833. WBUFL(buf,10)=tick;
  3834. WBUFL(buf,14)=sdelay;
  3835. WBUFL(buf,18)=ddelay;
  3836. if(damage > 0)
  3837. WBUFW(buf,22)=-1;
  3838. else
  3839. WBUFW(buf,22)=0;
  3840. WBUFW(buf,24)=div;
  3841. WBUFB(buf,26)=type;
  3842. WBUFW(buf,27)=0;
  3843. clif_send(buf,packet_len_table[0x8a],src,AREA);
  3844. }
  3845. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3846. if (type != 4 && type != 9 && damage+damage2 > 0) //Non-endure/Non-flinch attack, update walk delay.
  3847. battle_walkdelay(dst, tick, sdelay, ddelay, div);
  3848. // [Valaris]
  3849. if(battle_config.save_clothcolor && src->type==BL_MOB &&
  3850. pcdb_checkid(mob_get_viewclass(((struct mob_data *)src)->class_)) && mob_get_clothes_color(((struct mob_data *)src)->class_) > 0)
  3851. clif_changelook(src, LOOK_CLOTHES_COLOR, mob_get_clothes_color(((struct mob_data *)src)->class_));
  3852. return 0;
  3853. }
  3854. /*==========================================
  3855. *
  3856. *------------------------------------------
  3857. */
  3858. void clif_getareachar_mob(struct map_session_data* sd,struct mob_data* md)
  3859. {
  3860. int len;
  3861. nullpo_retv(sd);
  3862. nullpo_retv(md);
  3863. if (session[sd->fd] == NULL)
  3864. return;
  3865. if(md->state.state == MS_WALK){
  3866. #if PACKETVER < 4
  3867. WFIFOHEAD(sd->fd,packet_len_table[0x78]);
  3868. #else
  3869. WFIFOHEAD(sd->fd,packet_len_table[0x1d8]);
  3870. #endif
  3871. len = clif_mob007b(md,WFIFOP(sd->fd,0));
  3872. WFIFOSET(sd->fd,len);
  3873. } else {
  3874. #if PACKETVER < 4
  3875. WFIFOHEAD(sd->fd,packet_len_table[0x78]);
  3876. #else
  3877. WFIFOHEAD(sd->fd,packet_len_table[0x1d8]);
  3878. #endif
  3879. len = clif_mob0078(md,WFIFOP(sd->fd,0));
  3880. WFIFOSET(sd->fd,len);
  3881. }
  3882. if(battle_config.save_clothcolor && pcdb_checkid(mob_get_viewclass(md->class_)) && mob_get_clothes_color(md->class_)) // [Valaris]
  3883. clif_changelook(&md->bl, LOOK_CLOTHES_COLOR, mob_get_clothes_color(md->class_));
  3884. if(mob_get_equip(md->class_) > 0) // mob equipment [Valaris]
  3885. clif_mob_equip(md,mob_get_equip(md->class_));
  3886. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3887. clif_specialeffect(&md->bl,423,0);
  3888. else if(md->special_state.size==1)
  3889. clif_specialeffect(&md->bl,421,0);
  3890. }
  3891. /*==========================================
  3892. *
  3893. *------------------------------------------
  3894. */
  3895. void clif_getareachar_pet(struct map_session_data* sd,struct pet_data* pd)
  3896. {
  3897. int len;
  3898. nullpo_retv(sd);
  3899. nullpo_retv(pd);
  3900. if(pd->state.state == MS_WALK){
  3901. #if PACKETVER < 4
  3902. WFIFOHEAD(sd->fd,packet_len_table[0x7b]);
  3903. #else
  3904. WFIFOHEAD(sd->fd,packet_len_table[0x1da]);
  3905. #endif
  3906. len = clif_pet007b(pd,WFIFOP(sd->fd,0));
  3907. WFIFOSET(sd->fd,len);
  3908. } else {
  3909. #if PACKETVER < 4
  3910. WFIFOHEAD(sd->fd,packet_len_table[0x7b]);
  3911. #else
  3912. WFIFOHEAD(sd->fd,packet_len_table[0x1da]);
  3913. #endif
  3914. len = clif_pet0078(pd,WFIFOP(sd->fd,0));
  3915. WFIFOSET(sd->fd,len);
  3916. }
  3917. }
  3918. /*==========================================
  3919. *
  3920. *------------------------------------------
  3921. */
  3922. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3923. {
  3924. int view,fd;
  3925. nullpo_retv(sd);
  3926. nullpo_retv(fitem);
  3927. fd=sd->fd;
  3928. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3929. WFIFOHEAD(fd,packet_len_table[0x9d]);
  3930. WFIFOW(fd,0)=0x9d;
  3931. WFIFOL(fd,2)=fitem->bl.id;
  3932. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3933. WFIFOW(fd,6)=view;
  3934. else
  3935. WFIFOW(fd,6)=fitem->item_data.nameid;
  3936. WFIFOB(fd,8)=fitem->item_data.identify;
  3937. WFIFOW(fd,9)=fitem->bl.x;
  3938. WFIFOW(fd,11)=fitem->bl.y;
  3939. WFIFOW(fd,13)=fitem->item_data.amount;
  3940. WFIFOB(fd,15)=fitem->subx;
  3941. WFIFOB(fd,16)=fitem->suby;
  3942. WFIFOSET(fd,packet_len_table[0x9d]);
  3943. }
  3944. /*==========================================
  3945. * 場所スキルエフェクトが視界に入る
  3946. *------------------------------------------
  3947. */
  3948. int clif_getareachar_skillunit(struct map_session_data *sd,struct skill_unit *unit)
  3949. {
  3950. int fd;
  3951. struct block_list *bl;
  3952. nullpo_retr(0, unit);
  3953. fd=sd->fd;
  3954. bl=map_id2bl(unit->group->src_id);
  3955. #if PACKETVER < 3
  3956. WFIFOHEAD(fd,packet_len_table[0x11f]);
  3957. memset(WFIFOP(fd,0),0,packet_len_table[0x11f]);
  3958. WFIFOW(fd, 0)=0x11f;
  3959. WFIFOL(fd, 2)=unit->bl.id;
  3960. WFIFOL(fd, 6)=unit->group->src_id;
  3961. WFIFOW(fd,10)=unit->bl.x;
  3962. WFIFOW(fd,12)=unit->bl.y;
  3963. WFIFOB(fd,14)=unit->group->unit_id;
  3964. WFIFOB(fd,15)=0;
  3965. WFIFOSET(fd,packet_len_table[0x11f]);
  3966. #else
  3967. WFIFOHEAD(fd,packet_len_table[0x1c9]);
  3968. memset(WFIFOP(fd,0),0,packet_len_table[0x1c9]);
  3969. WFIFOW(fd, 0)=0x1c9;
  3970. WFIFOL(fd, 2)=unit->bl.id;
  3971. WFIFOL(fd, 6)=unit->group->src_id;
  3972. WFIFOW(fd,10)=unit->bl.x;
  3973. WFIFOW(fd,12)=unit->bl.y;
  3974. WFIFOB(fd,14)=unit->group->unit_id;
  3975. WFIFOB(fd,15)=1;
  3976. if(unit->group->unit_id==0xb0) { // Graffiti [Valaris]
  3977. WFIFOB(fd,16)=1;
  3978. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3979. } else {
  3980. WFIFOL(fd,15+1)=0; //1-4調べた限り固定
  3981. WFIFOL(fd,15+5)=0; //5-8調べた限り固定
  3982. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  3983. WFIFOL(fd,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  3984. WFIFOL(fd,15+17)=0x004f37dd; //17-20調べた限り固定
  3985. WFIFOL(fd,15+21)=0x0012f674; //21-24調べた限り固定
  3986. WFIFOL(fd,15+25)=0x0012f664; //25-28調べた限り固定
  3987. WFIFOL(fd,15+29)=0x0012f654; //29-32調べた限り固定
  3988. WFIFOL(fd,15+33)=0x77527bbc; //33-36調べた限り固定
  3989. //37-39
  3990. WFIFOB(fd,15+40)=0x2d; //40調べた限り固定
  3991. WFIFOL(fd,15+41)=0; //41-44調べた限り0固定
  3992. WFIFOL(fd,15+45)=0; //45-48調べた限り0固定
  3993. WFIFOL(fd,15+49)=0; //49-52調べた限り0固定
  3994. WFIFOL(fd,15+53)=0x0048d919; //53-56調べた限り固定
  3995. WFIFOL(fd,15+57)=0x0000003e; //57-60調べた限り固定
  3996. WFIFOL(fd,15+61)=0x0012f66c; //61-64調べた限り固定
  3997. //65-68
  3998. //69-72
  3999. if(bl) WFIFOL(fd,15+73)=bl->y; //73-76術者のY座標
  4000. WFIFOL(fd,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  4001. WFIFOB(fd,15+81)=0xaa; //81終端文字0xaa
  4002. }
  4003. WFIFOSET(fd,packet_len_table[0x1c9]);
  4004. #endif
  4005. if(unit->group->skill_id == WZ_ICEWALL)
  4006. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  4007. return 0;
  4008. }
  4009. /*==========================================
  4010. * 場所スキルエフェクトが視界から消える
  4011. *------------------------------------------
  4012. */
  4013. int clif_clearchar_skillunit(struct skill_unit *unit,int fd)
  4014. {
  4015. nullpo_retr(0, unit);
  4016. WFIFOHEAD(fd,packet_len_table[0x120]);
  4017. WFIFOW(fd, 0)=0x120;
  4018. WFIFOL(fd, 2)=unit->bl.id;
  4019. WFIFOSET(fd,packet_len_table[0x120]);
  4020. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4021. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2);
  4022. return 0;
  4023. }
  4024. /*==========================================
  4025. *
  4026. *------------------------------------------
  4027. */
  4028. int clif_01ac(struct block_list *bl)
  4029. {
  4030. unsigned char buf[32];
  4031. nullpo_retr(0, bl);
  4032. WBUFW(buf, 0) = 0x1ac;
  4033. WBUFL(buf, 2) = bl->id;
  4034. clif_send(buf,packet_len_table[0x1ac],bl,AREA);
  4035. return 0;
  4036. }
  4037. /*==========================================
  4038. *
  4039. *------------------------------------------
  4040. */
  4041. int clif_getareachar(struct block_list* bl,va_list ap)
  4042. {
  4043. struct map_session_data *sd;
  4044. nullpo_retr(0, bl);
  4045. nullpo_retr(0, ap);
  4046. sd=va_arg(ap,struct map_session_data*);
  4047. if (sd == NULL || session[sd->fd] == NULL)
  4048. return 0;
  4049. switch(bl->type){
  4050. case BL_PC:
  4051. if(sd==(struct map_session_data*)bl)
  4052. break;
  4053. clif_getareachar_pc(sd,(struct map_session_data*) bl);
  4054. break;
  4055. case BL_NPC:
  4056. clif_getareachar_npc(sd,(struct npc_data*) bl);
  4057. break;
  4058. case BL_MOB:
  4059. clif_getareachar_mob(sd,(struct mob_data*) bl);
  4060. break;
  4061. case BL_PET:
  4062. clif_getareachar_pet(sd,(struct pet_data*) bl);
  4063. break;
  4064. case BL_ITEM:
  4065. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4066. break;
  4067. case BL_SKILL:
  4068. clif_getareachar_skillunit(sd,(struct skill_unit *)bl);
  4069. break;
  4070. default:
  4071. if(battle_config.error_log)
  4072. ShowError("clif_getareachar: Unrecognized type %d.\n",bl->type);
  4073. break;
  4074. }
  4075. return 0;
  4076. }
  4077. /*==========================================
  4078. *
  4079. *------------------------------------------
  4080. */
  4081. int clif_pcoutsight(struct block_list *bl,va_list ap)
  4082. {
  4083. struct map_session_data *sd,*dstsd;
  4084. nullpo_retr(0, bl);
  4085. nullpo_retr(0, ap);
  4086. nullpo_retr(0, sd=va_arg(ap,struct map_session_data*));
  4087. switch(bl->type){
  4088. case BL_PC:
  4089. dstsd = (struct map_session_data*) bl;
  4090. if(sd != dstsd) {
  4091. clif_clearchar_id(dstsd->bl.id,0,sd->fd);
  4092. clif_clearchar_id(sd->bl.id,0,dstsd->fd);
  4093. if(dstsd->disguise || sd->disguise) {
  4094. clif_clearchar_id(-dstsd->bl.id,0,sd->fd);
  4095. clif_clearchar_id(-sd->bl.id,0,dstsd->fd);
  4096. }
  4097. if(dstsd->chatID){
  4098. struct chat_data *cd;
  4099. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  4100. if(cd->usersd[0]==dstsd)
  4101. clif_dispchat(cd,sd->fd);
  4102. }
  4103. if(dstsd->vender_id){
  4104. clif_closevendingboard(&dstsd->bl,sd->fd);
  4105. }
  4106. }
  4107. break;
  4108. case BL_NPC:
  4109. if( ((struct npc_data *)bl)->class_ != INVISIBLE_CLASS )
  4110. clif_clearchar_id(bl->id,0,sd->fd);
  4111. break;
  4112. case BL_MOB:
  4113. case BL_PET:
  4114. clif_clearchar_id(bl->id,0,sd->fd);
  4115. break;
  4116. case BL_ITEM:
  4117. clif_clearflooritem((struct flooritem_data*)bl,sd->fd);
  4118. break;
  4119. case BL_SKILL:
  4120. clif_clearchar_skillunit((struct skill_unit *)bl,sd->fd);
  4121. break;
  4122. }
  4123. return 0;
  4124. }
  4125. /*==========================================
  4126. *
  4127. *------------------------------------------
  4128. */
  4129. int clif_pcinsight(struct block_list *bl,va_list ap)
  4130. {
  4131. struct map_session_data *sd,*dstsd;
  4132. nullpo_retr(0, bl);
  4133. nullpo_retr(0, ap);
  4134. nullpo_retr(0, sd=va_arg(ap,struct map_session_data*));
  4135. switch(bl->type){
  4136. case BL_PC:
  4137. dstsd = (struct map_session_data *)bl;
  4138. if(sd != dstsd) {
  4139. clif_getareachar_pc(sd,dstsd);
  4140. clif_getareachar_pc(dstsd,sd);
  4141. }
  4142. break;
  4143. case BL_NPC:
  4144. clif_getareachar_npc(sd,(struct npc_data*)bl);
  4145. break;
  4146. case BL_MOB:
  4147. clif_getareachar_mob(sd,(struct mob_data*)bl);
  4148. break;
  4149. case BL_PET:
  4150. clif_getareachar_pet(sd,(struct pet_data*)bl);
  4151. break;
  4152. case BL_ITEM:
  4153. clif_getareachar_item(sd,(struct flooritem_data*)bl);
  4154. break;
  4155. case BL_SKILL:
  4156. clif_getareachar_skillunit(sd,(struct skill_unit *)bl);
  4157. break;
  4158. }
  4159. return 0;
  4160. }
  4161. /*==========================================
  4162. *
  4163. *------------------------------------------
  4164. */
  4165. int clif_moboutsight(struct block_list *bl,va_list ap)
  4166. {
  4167. struct map_session_data *sd;
  4168. struct mob_data *md;
  4169. nullpo_retr(0, bl);
  4170. nullpo_retr(0, ap);
  4171. nullpo_retr(0, md=va_arg(ap,struct mob_data*));
  4172. if(bl->type==BL_PC
  4173. && ((sd = (struct map_session_data*) bl) != NULL)
  4174. && session[sd->fd] != NULL) {
  4175. clif_clearchar_id(md->bl.id,0,sd->fd);
  4176. }
  4177. return 0;
  4178. }
  4179. /*==========================================
  4180. *
  4181. *------------------------------------------
  4182. */
  4183. int clif_mobinsight(struct block_list *bl,va_list ap)
  4184. {
  4185. struct map_session_data *sd;
  4186. struct mob_data *md;
  4187. nullpo_retr(0, bl);
  4188. nullpo_retr(0, ap);
  4189. md=va_arg(ap,struct mob_data*);
  4190. if(bl->type==BL_PC
  4191. && ((sd = (struct map_session_data*) bl) != NULL)
  4192. && session[sd->fd] != NULL) {
  4193. clif_getareachar_mob(sd,md);
  4194. }
  4195. return 0;
  4196. }
  4197. /*==========================================
  4198. *
  4199. *------------------------------------------
  4200. */
  4201. int clif_petoutsight(struct block_list *bl,va_list ap)
  4202. {
  4203. struct map_session_data *sd;
  4204. struct pet_data *pd;
  4205. nullpo_retr(0, bl);
  4206. nullpo_retr(0, ap);
  4207. nullpo_retr(0, pd=va_arg(ap,struct pet_data*));
  4208. if(bl->type==BL_PC
  4209. && ((sd = (struct map_session_data*) bl) != NULL)
  4210. && session[sd->fd] != NULL) {
  4211. clif_clearchar_id(pd->bl.id,0,sd->fd);
  4212. }
  4213. return 0;
  4214. }
  4215. // npc walking [Valaris]
  4216. int clif_npcoutsight(struct block_list *bl,va_list ap)
  4217. {
  4218. struct map_session_data *sd;
  4219. struct npc_data *nd;
  4220. nullpo_retr(0, bl);
  4221. nullpo_retr(0, ap);
  4222. nullpo_retr(0, nd=va_arg(ap,struct npc_data*));
  4223. if(bl->type==BL_PC
  4224. && ((sd = (struct map_session_data*) bl) != NULL)
  4225. && session[sd->fd] != NULL) {
  4226. clif_clearchar_id(nd->bl.id,0,sd->fd);
  4227. }
  4228. return 0;
  4229. }
  4230. /*==========================================
  4231. *
  4232. *------------------------------------------
  4233. */
  4234. int clif_petinsight(struct block_list *bl,va_list ap)
  4235. {
  4236. struct map_session_data *sd;
  4237. struct pet_data *pd;
  4238. nullpo_retr(0, bl);
  4239. nullpo_retr(0, ap);
  4240. pd=va_arg(ap,struct pet_data*);
  4241. if(bl->type==BL_PC
  4242. && ((sd = (struct map_session_data*) bl) != NULL)
  4243. && session[sd->fd] != NULL) {
  4244. clif_getareachar_pet(sd,pd);
  4245. }
  4246. return 0;
  4247. }
  4248. // npc walking [Valaris]
  4249. int clif_npcinsight(struct block_list *bl,va_list ap)
  4250. {
  4251. struct map_session_data *sd;
  4252. struct npc_data *nd;
  4253. nullpo_retr(0, bl);
  4254. nullpo_retr(0, ap);
  4255. nd=va_arg(ap,struct npc_data*);
  4256. if(bl->type==BL_PC
  4257. && ((sd = (struct map_session_data*) bl) != NULL)
  4258. && session[sd->fd] != NULL) {
  4259. clif_getareachar_npc(sd,nd);
  4260. }
  4261. return 0;
  4262. }
  4263. /*==========================================
  4264. *
  4265. *------------------------------------------
  4266. */
  4267. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  4268. {
  4269. int fd,id, inf2;
  4270. nullpo_retr(0, sd);
  4271. fd=sd->fd;
  4272. if( (id=sd->status.skill[skillid].id) <= 0 )
  4273. return 0;
  4274. WFIFOHEAD(fd,packet_len_table[0x147]);
  4275. WFIFOW(fd,0)=0x147;
  4276. WFIFOW(fd,2) = id;
  4277. if(type < 0)
  4278. WFIFOW(fd,4) = skill_get_inf(id);
  4279. else
  4280. WFIFOW(fd,4) = type;
  4281. WFIFOW(fd,6) = 0;
  4282. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  4283. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  4284. if(range < 0)
  4285. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  4286. WFIFOW(fd,12)= range;
  4287. strncpy(WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  4288. inf2 = skill_get_inf2(id);
  4289. if(((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
  4290. !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL))) ||
  4291. (battle_config.gm_allskill > 0 && pc_isGM(sd) >= battle_config.gm_allskill))
  4292. //WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_get_max(id) && sd->status.skill[skillid].flag ==0 )? 1:0;
  4293. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_) && sd->status.skill[skillid].flag ==0 )? 1:0;
  4294. else
  4295. WFIFOB(fd,38) = 0;
  4296. WFIFOSET(fd,packet_len_table[0x147]);
  4297. return 0;
  4298. }
  4299. /*==========================================
  4300. * スキルリストを送信する
  4301. *------------------------------------------
  4302. */
  4303. int clif_skillinfoblock(struct map_session_data *sd)
  4304. {
  4305. int fd;
  4306. int i,c,len=4,id, inf2;
  4307. nullpo_retr(0, sd);
  4308. fd=sd->fd;
  4309. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4310. WFIFOW(fd,0)=0x10f;
  4311. for ( i = c = 0; i < MAX_SKILL; i++){
  4312. if( (id=sd->status.skill[i].id)!=0 ){
  4313. WFIFOW(fd,len ) = id;
  4314. WFIFOW(fd,len+2) = skill_get_inf(id);
  4315. WFIFOW(fd,len+4) = 0;
  4316. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4317. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4318. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  4319. strncpy(WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4320. inf2 = skill_get_inf2(id);
  4321. if(((!(inf2&INF2_QUEST_SKILL) || battle_config.quest_skill_learn) &&
  4322. !(inf2&(INF2_WEDDING_SKILL|INF2_SPIRIT_SKILL))) ||
  4323. (battle_config.gm_allskill > 0 && pc_isGM(sd) >= battle_config.gm_allskill) )
  4324. //WFIFOB(fd,len+36)= (sd->status.skill[i].lv < skill_get_max(id) && sd->status.skill[i].flag ==0 )? 1:0;
  4325. WFIFOB(fd,len+36)= (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_) && sd->status.skill[i].flag ==0 )? 1:0;
  4326. else
  4327. WFIFOB(fd,len+36) = 0;
  4328. len+=37;
  4329. c++;
  4330. }
  4331. }
  4332. WFIFOW(fd,2)=len;
  4333. WFIFOSET(fd,len);
  4334. return 0;
  4335. }
  4336. /*==========================================
  4337. * スキル割り振り通知
  4338. *------------------------------------------
  4339. */
  4340. int clif_skillup(struct map_session_data *sd,int skill_num)
  4341. {
  4342. int fd;
  4343. nullpo_retr(0, sd);
  4344. fd=sd->fd;
  4345. WFIFOHEAD(fd,packet_len_table[0x10e]);
  4346. WFIFOW(fd,0) = 0x10e;
  4347. WFIFOW(fd,2) = skill_num;
  4348. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  4349. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  4350. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  4351. //WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_get_max(sd->status.skill[skill_num].id)) ? 1 : 0;
  4352. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  4353. WFIFOSET(fd,packet_len_table[0x10e]);
  4354. return 0;
  4355. }
  4356. /*==========================================
  4357. * スキル詠唱エフェクトを送信する
  4358. *------------------------------------------
  4359. */
  4360. int clif_skillcasting(struct block_list* bl,
  4361. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int casttime)
  4362. {
  4363. int pl = skill_get_pl(skill_num);
  4364. unsigned char buf[32];
  4365. WBUFW(buf,0) = 0x13e;
  4366. WBUFL(buf,2) = src_id;
  4367. WBUFL(buf,6) = dst_id;
  4368. WBUFW(buf,10) = dst_x;
  4369. WBUFW(buf,12) = dst_y;
  4370. WBUFW(buf,14) = skill_num;
  4371. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  4372. WBUFL(buf,20) = casttime;
  4373. clif_send(buf,packet_len_table[0x13e], bl, AREA);
  4374. return 0;
  4375. }
  4376. /*==========================================
  4377. *
  4378. *------------------------------------------
  4379. */
  4380. int clif_skillcastcancel(struct block_list* bl)
  4381. {
  4382. unsigned char buf[16];
  4383. nullpo_retr(0, bl);
  4384. WBUFW(buf,0) = 0x1b9;
  4385. WBUFL(buf,2) = bl->id;
  4386. clif_send(buf,packet_len_table[0x1b9], bl, AREA);
  4387. return 0;
  4388. }
  4389. /*==========================================
  4390. * スキル詠唱失敗
  4391. *------------------------------------------
  4392. */
  4393. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  4394. {
  4395. int fd;
  4396. nullpo_retr(0, sd);
  4397. fd=sd->fd;
  4398. // reset all variables [celest]
  4399. sd->skillx = sd->skilly = -1;
  4400. sd->skillid = sd->skilllv = -1;
  4401. sd->skillitem = sd->skillitemlv = -1;
  4402. if(type==0x4 && !sd->state.showdelay)
  4403. return 0;
  4404. WFIFOHEAD(fd,packet_len_table[0x110]);
  4405. WFIFOW(fd,0) = 0x110;
  4406. WFIFOW(fd,2) = skill_id;
  4407. WFIFOW(fd,4) = btype;
  4408. WFIFOW(fd,6) = 0;
  4409. WFIFOB(fd,8) = 0;
  4410. WFIFOB(fd,9) = type;
  4411. WFIFOSET(fd,packet_len_table[0x110]);
  4412. return 0;
  4413. }
  4414. /*==========================================
  4415. * スキル攻撃エフェクト&ダメージ
  4416. *------------------------------------------
  4417. */
  4418. int clif_skill_damage(struct block_list *src,struct block_list *dst,
  4419. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  4420. {
  4421. unsigned char buf[64];
  4422. struct status_change *sc;
  4423. nullpo_retr(0, src);
  4424. nullpo_retr(0, dst);
  4425. type = clif_calc_delay(dst, (type>0)?type:skill_get_hit(skill_id), ddelay);
  4426. sc = status_get_sc(dst);
  4427. if(sc && sc->count) {
  4428. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  4429. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  4430. }
  4431. #if PACKETVER < 3
  4432. WBUFW(buf,0)=0x114;
  4433. WBUFW(buf,2)=skill_id;
  4434. if(src->type==BL_PC && ((struct map_session_data *)src)->disguise)
  4435. WBUFL(buf,4)=-src->id;
  4436. else
  4437. WBUFL(buf,4)=src->id;
  4438. if(dst->type==BL_PC && ((struct map_session_data *)dst)->disguise)
  4439. WBUFL(buf,8)=-dst->id;
  4440. else
  4441. WBUFL(buf,8)=dst->id;
  4442. WBUFL(buf,12)=tick;
  4443. WBUFL(buf,16)=sdelay;
  4444. WBUFL(buf,20)=ddelay;
  4445. WBUFW(buf,24)=damage;
  4446. WBUFW(buf,26)=skill_lv;
  4447. WBUFW(buf,28)=div;
  4448. WBUFB(buf,30)=type;
  4449. clif_send(buf,packet_len_table[0x114],src,AREA);
  4450. #else
  4451. WBUFW(buf,0)=0x1de;
  4452. WBUFW(buf,2)=skill_id;
  4453. if(src->type==BL_PC && ((struct map_session_data *)src)->disguise)
  4454. WBUFL(buf,4)=-src->id;
  4455. else
  4456. WBUFL(buf,4)=src->id;
  4457. if(dst->type==BL_PC && ((struct map_session_data *)dst)->disguise)
  4458. WBUFL(buf,8)=-dst->id;
  4459. else
  4460. WBUFL(buf,8)=dst->id;
  4461. WBUFL(buf,12)=tick;
  4462. WBUFL(buf,16)=sdelay;
  4463. WBUFL(buf,20)=ddelay;
  4464. WBUFL(buf,24)=damage;
  4465. WBUFW(buf,28)=skill_lv;
  4466. WBUFW(buf,30)=div;
  4467. WBUFB(buf,32)=type;
  4468. clif_send(buf,packet_len_table[0x1de],src,AREA);
  4469. #endif
  4470. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4471. if (type != 4 && type != 9 && damage > 0) //Non-endure/Non-flinch attack, update walk delay.
  4472. battle_walkdelay(dst, tick, sdelay, ddelay, div);
  4473. return 0;
  4474. }
  4475. /*==========================================
  4476. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  4477. *------------------------------------------
  4478. */
  4479. int clif_skill_damage2(struct block_list *src,struct block_list *dst,
  4480. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  4481. {
  4482. unsigned char buf[64];
  4483. struct status_change *sc;
  4484. nullpo_retr(0, src);
  4485. nullpo_retr(0, dst);
  4486. type = clif_calc_delay(dst, (type>0)?type:skill_get_hit(skill_id), ddelay);
  4487. sc = status_get_sc(dst);
  4488. if(sc && sc->count) {
  4489. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  4490. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  4491. }
  4492. WBUFW(buf,0)=0x115;
  4493. WBUFW(buf,2)=skill_id;
  4494. WBUFL(buf,4)=src->id;
  4495. WBUFL(buf,8)=dst->id;
  4496. WBUFL(buf,12)=tick;
  4497. WBUFL(buf,16)=sdelay;
  4498. WBUFL(buf,20)=ddelay;
  4499. WBUFW(buf,24)=dst->x;
  4500. WBUFW(buf,26)=dst->y;
  4501. WBUFW(buf,28)=damage;
  4502. WBUFW(buf,30)=skill_lv;
  4503. WBUFW(buf,32)=div;
  4504. WBUFB(buf,34)=type;
  4505. clif_send(buf,packet_len_table[0x115],src,AREA);
  4506. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4507. if (type != 4 && type != 9 && damage > 0) //Non-endure/Non-flinch attack, update walk delay.
  4508. battle_walkdelay(dst, tick, sdelay, ddelay, div);
  4509. return 0;
  4510. }
  4511. /*==========================================
  4512. * 支援/回復スキルエフェクト
  4513. *------------------------------------------
  4514. */
  4515. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,
  4516. int skill_id,int heal,int fail)
  4517. {
  4518. unsigned char buf[32];
  4519. nullpo_retr(0, src);
  4520. nullpo_retr(0, dst);
  4521. WBUFW(buf,0)=0x11a;
  4522. WBUFW(buf,2)=skill_id;
  4523. WBUFW(buf,4)=(heal > 0x7fff)? 0x7fff:heal;
  4524. WBUFL(buf,6)=dst->id;
  4525. WBUFL(buf,10)=src->id;
  4526. WBUFB(buf,14)=fail;
  4527. clif_send(buf,packet_len_table[0x11a],src,AREA);
  4528. return fail;
  4529. }
  4530. /*==========================================
  4531. * 場所スキルエフェクト
  4532. *------------------------------------------
  4533. */
  4534. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  4535. {
  4536. unsigned char buf[32];
  4537. nullpo_retr(0, src);
  4538. WBUFW(buf,0)=0x117;
  4539. WBUFW(buf,2)=skill_id;
  4540. WBUFL(buf,4)=src->id;
  4541. WBUFW(buf,8)=val;
  4542. WBUFW(buf,10)=x;
  4543. WBUFW(buf,12)=y;
  4544. WBUFL(buf,14)=tick;
  4545. clif_send(buf,packet_len_table[0x117],src,AREA);
  4546. return 0;
  4547. }
  4548. /*==========================================
  4549. * 場所スキルエフェクト表示
  4550. *------------------------------------------
  4551. */
  4552. int clif_skill_setunit(struct skill_unit *unit)
  4553. {
  4554. unsigned char buf[128];
  4555. struct block_list *bl;
  4556. nullpo_retr(0, unit);
  4557. bl=map_id2bl(unit->group->src_id);
  4558. #if PACKETVER < 3
  4559. memset(WBUFP(buf, 0),0,packet_len_table[0x11f]);
  4560. WBUFW(buf, 0)=0x11f;
  4561. WBUFL(buf, 2)=unit->bl.id;
  4562. WBUFL(buf, 6)=unit->group->src_id;
  4563. WBUFW(buf,10)=unit->bl.x;
  4564. WBUFW(buf,12)=unit->bl.y;
  4565. WBUFB(buf,14)=unit->group->unit_id;
  4566. WBUFB(buf,15)=0;
  4567. clif_send(buf,packet_len_table[0x11f],&unit->bl,AREA);
  4568. #else
  4569. memset(WBUFP(buf, 0),0,packet_len_table[0x1c9]);
  4570. WBUFW(buf, 0)=0x1c9;
  4571. WBUFL(buf, 2)=unit->bl.id;
  4572. WBUFL(buf, 6)=unit->group->src_id;
  4573. WBUFW(buf,10)=unit->bl.x;
  4574. WBUFW(buf,12)=unit->bl.y;
  4575. WBUFB(buf,14)=unit->group->unit_id;
  4576. WBUFB(buf,15)=1;
  4577. if(unit->group->unit_id==0xb0) { // Graffiti [Valaris]
  4578. WBUFB(buf,16)=1;
  4579. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4580. } else {
  4581. WBUFL(buf,15+1)=0; //1-4調べた限り固定
  4582. WBUFL(buf,15+5)=0; //5-8調べた限り固定
  4583. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  4584. WBUFL(buf,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  4585. WBUFL(buf,15+17)=0x004f37dd; //17-20調べた限り固定(0x1b2で0x004fdbddだった)
  4586. WBUFL(buf,15+21)=0x0012f674; //21-24調べた限り固定
  4587. WBUFL(buf,15+25)=0x0012f664; //25-28調べた限り固定
  4588. WBUFL(buf,15+29)=0x0012f654; //29-32調べた限り固定
  4589. WBUFL(buf,15+33)=0x77527bbc; //33-36調べた限り固定
  4590. //37-39
  4591. WBUFB(buf,15+40)=0x2d; //40調べた限り固定
  4592. WBUFL(buf,15+41)=0; //41-44調べた限り0固定
  4593. WBUFL(buf,15+45)=0; //45-48調べた限り0固定
  4594. WBUFL(buf,15+49)=0; //49-52調べた限り0固定
  4595. WBUFL(buf,15+53)=0x0048d919; //53-56調べた限り固定(0x01b2で0x00495119だった)
  4596. WBUFL(buf,15+57)=0x0000003e; //57-60調べた限り固定
  4597. WBUFL(buf,15+61)=0x0012f66c; //61-64調べた限り固定
  4598. //65-68
  4599. //69-72
  4600. if(bl) WBUFL(buf,15+73)=bl->y; //73-76術者のY座標
  4601. WBUFL(buf,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  4602. WBUFB(buf,15+81)=0xaa; //81終端文字0xaa
  4603. }
  4604. clif_send(buf,packet_len_table[0x1c9],&unit->bl,AREA);
  4605. #endif
  4606. return 0;
  4607. }
  4608. /*==========================================
  4609. * 場所スキルエフェクト削除
  4610. *------------------------------------------
  4611. */
  4612. int clif_skill_delunit(struct skill_unit *unit)
  4613. {
  4614. unsigned char buf[16];
  4615. nullpo_retr(0, unit);
  4616. WBUFW(buf, 0)=0x120;
  4617. WBUFL(buf, 2)=unit->bl.id;
  4618. clif_send(buf,packet_len_table[0x120],&unit->bl,AREA);
  4619. return 0;
  4620. }
  4621. /*==========================================
  4622. * ワープ場所選択
  4623. *------------------------------------------
  4624. */
  4625. int clif_skill_warppoint(struct map_session_data *sd,int skill_num,
  4626. const char *map1,const char *map2,const char *map3,const char *map4)
  4627. {
  4628. int fd;
  4629. nullpo_retr(0, sd);
  4630. fd=sd->fd;
  4631. WFIFOHEAD(fd,packet_len_table[0x11c]);
  4632. WFIFOW(fd,0)=0x11c;
  4633. WFIFOW(fd,2)=skill_num;
  4634. strncpy((char*)WFIFOP(fd, 4),map1,MAP_NAME_LENGTH);
  4635. strncpy((char*)WFIFOP(fd,20),map2,MAP_NAME_LENGTH);
  4636. strncpy((char*)WFIFOP(fd,36),map3,MAP_NAME_LENGTH);
  4637. strncpy((char*)WFIFOP(fd,52),map4,MAP_NAME_LENGTH);
  4638. WFIFOSET(fd,packet_len_table[0x11c]);
  4639. return 0;
  4640. }
  4641. /*==========================================
  4642. * メモ応答
  4643. *------------------------------------------
  4644. */
  4645. int clif_skill_memo(struct map_session_data *sd,int flag)
  4646. {
  4647. int fd;
  4648. nullpo_retr(0, sd);
  4649. fd=sd->fd;
  4650. WFIFOHEAD(fd,packet_len_table[0x11e]);
  4651. WFIFOW(fd,0)=0x11e;
  4652. WFIFOB(fd,2)=flag;
  4653. WFIFOSET(fd,packet_len_table[0x11e]);
  4654. return 0;
  4655. }
  4656. int clif_skill_teleportmessage(struct map_session_data *sd,int flag)
  4657. {
  4658. int fd;
  4659. nullpo_retr(0, sd);
  4660. fd=sd->fd;
  4661. WFIFOHEAD(fd,packet_len_table[0x189]);
  4662. WFIFOW(fd,0)=0x189;
  4663. WFIFOW(fd,2)=flag;
  4664. WFIFOSET(fd,packet_len_table[0x189]);
  4665. return 0;
  4666. }
  4667. /*==========================================
  4668. * モンスター情報
  4669. *------------------------------------------
  4670. */
  4671. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4672. {
  4673. struct mob_data *md;
  4674. unsigned char buf[64];
  4675. int i;//, fix;
  4676. nullpo_retr(0, sd);
  4677. nullpo_retr(0, dst);
  4678. if(dst->type!=BL_MOB )
  4679. return 0;
  4680. if((md=(struct mob_data *)dst) == NULL)
  4681. return 0;
  4682. WBUFW(buf, 0)=0x18c;
  4683. WBUFW(buf, 2)=mob_get_viewclass(md->class_);
  4684. WBUFW(buf, 4)=md->level;
  4685. WBUFW(buf, 6)=md->db->size;
  4686. WBUFL(buf, 8)=md->hp;
  4687. WBUFW(buf,12)= (battle_config.estimation_type&1?status_get_def(&md->bl):0)
  4688. +(battle_config.estimation_type&2?status_get_def2(&md->bl):0);
  4689. WBUFW(buf,14)=md->db->race;
  4690. WBUFW(buf,16)= (battle_config.estimation_type&1?status_get_mdef(&md->bl):0)
  4691. +(battle_config.estimation_type&2?status_get_mdef2(&md->bl) - (md->db->vit>>1):0);
  4692. WBUFW(buf,18)=status_get_elem_type(&md->bl);
  4693. for(i=0;i<9;i++)
  4694. WBUFB(buf,20+i)= (unsigned char)battle_attr_fix(NULL,dst,100,i+1,md->def_ele);
  4695. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4696. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_fix(NULL,dst,100,i+1,md->def_ele))<0?0:fix);
  4697. if(sd->status.party_id>0)
  4698. clif_send(buf,packet_len_table[0x18c],&sd->bl,PARTY_AREA);
  4699. else{
  4700. WFIFOHEAD(sd->fd,packet_len_table[0x18c]);
  4701. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x18c]);
  4702. WFIFOSET(sd->fd,packet_len_table[0x18c]);
  4703. }
  4704. return 0;
  4705. }
  4706. /*==========================================
  4707. * アイテム合成可能リスト
  4708. *------------------------------------------
  4709. */
  4710. int clif_skill_produce_mix_list(struct map_session_data *sd,int trigger)
  4711. {
  4712. int i,c,view,fd;
  4713. nullpo_retr(0, sd);
  4714. fd=sd->fd;
  4715. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4716. WFIFOW(fd, 0)=0x18d;
  4717. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4718. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4719. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4720. WFIFOW(fd,c*8+ 4)= view;
  4721. else
  4722. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4723. WFIFOW(fd,c*8+ 6)= 0x0012;
  4724. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  4725. c++;
  4726. }
  4727. }
  4728. WFIFOW(fd, 2)=c*8+8;
  4729. WFIFOSET(fd,WFIFOW(fd,2));
  4730. if(c > 0) sd->state.produce_flag = 1;
  4731. return 0;
  4732. }
  4733. /*==========================================
  4734. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  4735. *------------------------------------------
  4736. */
  4737. int clif_status_load(struct block_list *bl,int type, int flag)
  4738. {
  4739. int fd;
  4740. if (type == SI_BLANK) //It shows nothing on the client...
  4741. return 0;
  4742. if (bl->type != BL_PC)
  4743. return 0;
  4744. fd = ((struct map_session_data*)bl)->fd;
  4745. WFIFOHEAD(fd,packet_len_table[0x196]);
  4746. WFIFOW(fd,0)=0x0196;
  4747. WFIFOW(fd,2)=type;
  4748. WFIFOL(fd,4)=bl->id;
  4749. WFIFOB(fd,8)=flag; //Status start
  4750. WFIFOSET(fd, packet_len_table[0x196]);
  4751. return 0;
  4752. }
  4753. /*==========================================
  4754. * 状態異常アイコン/メッセージ表示
  4755. *------------------------------------------
  4756. */
  4757. int clif_status_change(struct block_list *bl,int type,int flag)
  4758. {
  4759. unsigned char buf[16];
  4760. if (type == SI_BLANK) //It shows nothing on the client...
  4761. return 0;
  4762. nullpo_retr(0, bl);
  4763. WBUFW(buf,0)=0x0196;
  4764. WBUFW(buf,2)=type;
  4765. WBUFL(buf,4)=bl->id;
  4766. WBUFB(buf,8)=flag;
  4767. clif_send(buf,packet_len_table[0x196],bl,AREA);
  4768. return 0;
  4769. }
  4770. /*==========================================
  4771. * Send message (modified by [Yor])
  4772. *------------------------------------------
  4773. */
  4774. int clif_displaymessage(const int fd, char* mes)
  4775. {
  4776. // invalid pointer?
  4777. nullpo_retr(-1, mes);
  4778. //Console [Wizputer] //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4779. if (fd == 0)
  4780. return 0;
  4781. else {
  4782. int len_mes = strlen(mes);
  4783. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4784. WFIFOHEAD(fd, 5 + len_mes);
  4785. WFIFOW(fd,0) = 0x8e;
  4786. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  4787. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  4788. WFIFOSET(fd, 5 + len_mes);
  4789. }
  4790. }
  4791. return 0;
  4792. }
  4793. /*==========================================
  4794. * 天の声を送信する
  4795. *------------------------------------------
  4796. */
  4797. int clif_GMmessage(struct block_list *bl, char* mes, int len, int flag)
  4798. {
  4799. unsigned char *buf;
  4800. int lp;
  4801. lp = (flag & 0x10) ? 8 : 4;
  4802. buf = (unsigned char*)aCallocA(len + lp + 8, sizeof(unsigned char));
  4803. WBUFW(buf,0) = 0x9a;
  4804. WBUFW(buf,2) = len + lp;
  4805. WBUFL(buf,4) = 0x65756c62;
  4806. memcpy(WBUFP(buf,lp), mes, len);
  4807. flag &= 0x07;
  4808. clif_send(buf, WBUFW(buf,2), bl,
  4809. (flag == 1) ? ALL_SAMEMAP :
  4810. (flag == 2) ? AREA :
  4811. (flag == 3) ? SELF :
  4812. ALL_CLIENT);
  4813. if(buf) aFree(buf);
  4814. if(use_irc && irc_announce_flag && !flag)
  4815. irc_announce(mes);
  4816. return 0;
  4817. }
  4818. /*==========================================
  4819. * グローバルメッセージ
  4820. *------------------------------------------
  4821. */
  4822. void clif_GlobalMessage(struct block_list *bl,char *message)
  4823. {
  4824. char buf[100];
  4825. int len;
  4826. nullpo_retv(bl);
  4827. if(!message)
  4828. return;
  4829. len = strlen(message)+1;
  4830. WBUFW(buf,0)=0x8d;
  4831. WBUFW(buf,2)=len+8;
  4832. WBUFL(buf,4)=bl->id;
  4833. strncpy((char *) WBUFP(buf,8),message,len);
  4834. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,AREA_CHAT_WOC);
  4835. }
  4836. /*==========================================
  4837. * Send main chat message [LuzZza]
  4838. *------------------------------------------
  4839. */
  4840. void clif_MainChatMessage(char* message) {
  4841. char buf[100];
  4842. int len;
  4843. if(!message)
  4844. return;
  4845. len = strlen(message)+1;
  4846. WBUFW(buf,0)=0x8d;
  4847. WBUFW(buf,2)=len+8;
  4848. WBUFL(buf,4)=0;
  4849. strncpy((char *) WBUFP(buf,8),message,len);
  4850. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4851. }
  4852. /*==========================================
  4853. * Does an announce message in the given color.
  4854. *------------------------------------------
  4855. */
  4856. int clif_announce(struct block_list *bl, char* mes, int len, unsigned long color, int flag)
  4857. {
  4858. unsigned char *buf;
  4859. buf = (unsigned char*)aCallocA(len + 16, sizeof(unsigned char));
  4860. WBUFW(buf,0) = 0x1c3;
  4861. WBUFW(buf,2) = len + 16;
  4862. WBUFL(buf,4) = color;
  4863. WBUFW(buf,8) = 0x190; //Font style? Type?
  4864. WBUFW(buf,10) = 0x0c; //12? Font size?
  4865. WBUFL(buf,12) = 0; //Unknown!
  4866. memcpy(WBUFP(buf,16), mes, len);
  4867. flag &= 0x07;
  4868. clif_send(buf, WBUFW(buf,2), bl,
  4869. (flag == 1) ? ALL_SAMEMAP :
  4870. (flag == 2) ? AREA :
  4871. (flag == 3) ? SELF :
  4872. ALL_CLIENT);
  4873. if(buf) aFree(buf);
  4874. return 0;
  4875. }
  4876. /*==========================================
  4877. * HPSP回復エフェクトを送信する
  4878. *------------------------------------------
  4879. */
  4880. int clif_heal(int fd,int type,int val)
  4881. {
  4882. WFIFOHEAD(fd,packet_len_table[0x13d]);
  4883. WFIFOW(fd,0)=0x13d;
  4884. WFIFOW(fd,2)=type;
  4885. WFIFOW(fd,4)=val;
  4886. WFIFOSET(fd,packet_len_table[0x13d]);
  4887. return 0;
  4888. }
  4889. /*==========================================
  4890. * 復活する
  4891. *------------------------------------------
  4892. */
  4893. int clif_resurrection(struct block_list *bl,int type)
  4894. {
  4895. unsigned char buf[16];
  4896. nullpo_retr(0, bl);
  4897. WBUFW(buf,0)=0x148;
  4898. WBUFL(buf,2)=bl->id;
  4899. WBUFW(buf,6)=type;
  4900. clif_send(buf,packet_len_table[0x148],bl,type==1 ? AREA : AREA_WOS);
  4901. if(bl->type==BL_PC && ((struct map_session_data *)bl)->disguise)
  4902. clif_spawnpc(((struct map_session_data *)bl));
  4903. return 0;
  4904. }
  4905. /*==========================================
  4906. * PVP実装?(仮)
  4907. *------------------------------------------
  4908. */
  4909. int clif_set0199(int fd,int type)
  4910. {
  4911. WFIFOHEAD(fd,packet_len_table[0x199]);
  4912. WFIFOW(fd,0)=0x199;
  4913. WFIFOW(fd,2)=type;
  4914. WFIFOSET(fd,packet_len_table[0x199]);
  4915. return 0;
  4916. }
  4917. /*==========================================
  4918. * PVP実装?(仮)
  4919. *------------------------------------------
  4920. */
  4921. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4922. {
  4923. nullpo_retr(0, sd);
  4924. if(map[sd->bl.m].flag.nopvp)
  4925. return 0;
  4926. if(type == 2) {
  4927. WFIFOHEAD(sd->fd,packet_len_table[0x19a]);
  4928. WFIFOW(sd->fd,0) = 0x19a;
  4929. WFIFOL(sd->fd,2) = sd->bl.id;
  4930. if(pvprank<=0)
  4931. pc_calc_pvprank(sd);
  4932. WFIFOL(sd->fd,6) = pvprank;
  4933. WFIFOL(sd->fd,10) = pvpnum;
  4934. WFIFOSET(sd->fd,packet_len_table[0x19a]);
  4935. } else {
  4936. unsigned char buf[32];
  4937. WBUFW(buf,0) = 0x19a;
  4938. WBUFL(buf,2) = sd->bl.id;
  4939. if(sd->sc.option&0x46)
  4940. // WTF? a -1 to an unsigned value...
  4941. WBUFL(buf,6) = 0xFFFFFFFF;
  4942. else
  4943. if(pvprank<=0)
  4944. pc_calc_pvprank(sd);
  4945. WBUFL(buf,6) = pvprank;
  4946. WBUFL(buf,10) = pvpnum;
  4947. if(!type)
  4948. clif_send(buf,packet_len_table[0x19a],&sd->bl,AREA);
  4949. else
  4950. clif_send(buf,packet_len_table[0x19a],&sd->bl,ALL_SAMEMAP);
  4951. }
  4952. return 0;
  4953. }
  4954. /*==========================================
  4955. *
  4956. *------------------------------------------
  4957. */
  4958. int clif_send0199(int map,int type)
  4959. {
  4960. struct block_list bl;
  4961. unsigned char buf[16];
  4962. bl.m = map;
  4963. WBUFW(buf,0)=0x199;
  4964. WBUFW(buf,2)=type;
  4965. clif_send(buf,packet_len_table[0x199],&bl,ALL_SAMEMAP);
  4966. return 0;
  4967. }
  4968. /*==========================================
  4969. * 精錬エフェクトを送信する
  4970. *------------------------------------------
  4971. */
  4972. int clif_refine(int fd,struct map_session_data *sd,int fail,int index,int val)
  4973. {
  4974. WFIFOHEAD(fd,packet_len_table[0x188]);
  4975. WFIFOW(fd,0)=0x188;
  4976. WFIFOW(fd,2)=fail;
  4977. WFIFOW(fd,4)=index+2;
  4978. WFIFOW(fd,6)=val;
  4979. WFIFOSET(fd,packet_len_table[0x188]);
  4980. return 0;
  4981. }
  4982. /*==========================================
  4983. * Wisp/page is transmitted to the destination player
  4984. *------------------------------------------
  4985. */
  4986. int clif_wis_message(int fd, char *nick, char *mes, int mes_len) // R 0097 <len>.w <nick>.24B <message>.?B
  4987. {
  4988. // printf("clif_wis_message(%d, %s, %s)\n", fd, nick, mes);
  4989. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4990. WFIFOW(fd,0) = 0x97;
  4991. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4992. memcpy(WFIFOP(fd,4), nick, NAME_LENGTH);
  4993. memcpy(WFIFOP(fd,28), mes, mes_len);
  4994. WFIFOSET(fd,WFIFOW(fd,2));
  4995. return 0;
  4996. }
  4997. /*==========================================
  4998. * The transmission result of Wisp/page is transmitted to the source player
  4999. *------------------------------------------
  5000. */
  5001. int clif_wis_end(int fd, int flag) // R 0098 <type>.B: 0: success to send wisper, 1: target character is not loged in, 2: ignored by target, 3: everyone ignored by target
  5002. {
  5003. WFIFOHEAD(fd,packet_len_table[0x98]);
  5004. WFIFOW(fd,0) = 0x98;
  5005. WFIFOW(fd,2) = flag;
  5006. WFIFOSET(fd,packet_len_table[0x98]);
  5007. return 0;
  5008. }
  5009. /*==========================================
  5010. * キャラID名前引き結果を送信する
  5011. *------------------------------------------
  5012. */
  5013. int clif_solved_charname(struct map_session_data *sd,int char_id)
  5014. {
  5015. char *p= map_charid2nick(char_id);
  5016. int fd;
  5017. nullpo_retr(0, sd);
  5018. fd=sd->fd;
  5019. if(p!=NULL){
  5020. WFIFOHEAD(fd,packet_len_table[0x194]);
  5021. WFIFOW(fd,0)=0x194;
  5022. WFIFOL(fd,2)=char_id;
  5023. memcpy(WFIFOP(fd,6), p, NAME_LENGTH);
  5024. WFIFOSET(fd,packet_len_table[0x194]);
  5025. }else{
  5026. map_reqchariddb(sd,char_id);
  5027. chrif_searchcharid(char_id);
  5028. }
  5029. return 0;
  5030. }
  5031. /*==========================================
  5032. * カードの挿入可能リストを返す
  5033. *------------------------------------------
  5034. */
  5035. int clif_use_card(struct map_session_data *sd,int idx)
  5036. {
  5037. int i,c,ep;
  5038. int fd=sd->fd;
  5039. nullpo_retr(0, sd);
  5040. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5041. return 0;
  5042. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != 6)
  5043. return 0; //Avoid parsing invalid item indexes (no card/no item)
  5044. ep=sd->inventory_data[idx]->equip;
  5045. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5046. WFIFOW(fd,0)=0x017b;
  5047. for(i=c=0;i<MAX_INVENTORY;i++){
  5048. int j;
  5049. if(sd->inventory_data[i] == NULL)
  5050. continue;
  5051. if(sd->inventory_data[i]->type!=4 && sd->inventory_data[i]->type!=5) // 武器防具じゃない
  5052. continue;
  5053. if(sd->status.inventory[i].card[0]==0x00ff || sd->status.inventory[i].card[0]==(short)0xff00 || sd->status.inventory[i].card[0]==0x00fe)
  5054. continue;
  5055. if(sd->status.inventory[i].identify==0 ) // 未鑑定
  5056. continue;
  5057. if((sd->inventory_data[i]->equip&ep)==0) // 装備個所が違う
  5058. continue;
  5059. if(sd->inventory_data[i]->type==4 && ep==32) // 盾カードと両手武器
  5060. continue;
  5061. for(j=0;j<sd->inventory_data[i]->slot;j++){
  5062. if( sd->status.inventory[i].card[j]==0 )
  5063. break;
  5064. }
  5065. if(j==sd->inventory_data[i]->slot) // すでにカードが一杯
  5066. continue;
  5067. WFIFOW(fd,4+c*2)=i+2;
  5068. c++;
  5069. }
  5070. WFIFOW(fd,2)=4+c*2;
  5071. WFIFOSET(fd,WFIFOW(fd,2));
  5072. return 0;
  5073. }
  5074. /*==========================================
  5075. * カードの挿入終了
  5076. *------------------------------------------
  5077. */
  5078. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5079. {
  5080. int fd;
  5081. nullpo_retr(0, sd);
  5082. fd=sd->fd;
  5083. WFIFOHEAD(fd,packet_len_table[0x17d]);
  5084. WFIFOW(fd,0)=0x17d;
  5085. WFIFOW(fd,2)=idx_equip+2;
  5086. WFIFOW(fd,4)=idx_card+2;
  5087. WFIFOB(fd,6)=flag;
  5088. WFIFOSET(fd,packet_len_table[0x17d]);
  5089. return 0;
  5090. }
  5091. /*==========================================
  5092. * 鑑定可能アイテムリスト送信
  5093. *------------------------------------------
  5094. */
  5095. int clif_item_identify_list(struct map_session_data *sd)
  5096. {
  5097. int i,c;
  5098. int fd;
  5099. nullpo_retr(0, sd);
  5100. fd=sd->fd;
  5101. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5102. WFIFOW(fd,0)=0x177;
  5103. for(i=c=0;i<MAX_INVENTORY;i++){
  5104. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].identify!=1){
  5105. WFIFOW(fd,c*2+4)=i+2;
  5106. c++;
  5107. }
  5108. }
  5109. if(c > 0) {
  5110. WFIFOW(fd,2)=c*2+4;
  5111. WFIFOSET(fd,WFIFOW(fd,2));
  5112. }
  5113. return 0;
  5114. }
  5115. /*==========================================
  5116. * 鑑定結果
  5117. *------------------------------------------
  5118. */
  5119. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5120. {
  5121. int fd;
  5122. nullpo_retr(0, sd);
  5123. fd=sd->fd;
  5124. WFIFOHEAD(fd,packet_len_table[0x179]);
  5125. WFIFOW(fd, 0)=0x179;
  5126. WFIFOW(fd, 2)=idx+2;
  5127. WFIFOB(fd, 4)=flag;
  5128. WFIFOSET(fd,packet_len_table[0x179]);
  5129. return 0;
  5130. }
  5131. /*==========================================
  5132. * 修理可能アイテムリスト送信
  5133. *------------------------------------------
  5134. */
  5135. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  5136. {
  5137. int i,c;
  5138. int fd;
  5139. int nameid;
  5140. nullpo_retr(0, sd);
  5141. nullpo_retr(0, dstsd);
  5142. fd=sd->fd;
  5143. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5144. WFIFOW(fd,0)=0x1fc;
  5145. for(i=c=0;i<MAX_INVENTORY;i++){
  5146. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5147. WFIFOW(fd,c*13+4) = i;
  5148. WFIFOW(fd,c*13+6) = nameid;
  5149. WFIFOL(fd,c*13+8) = sd->status.char_id;
  5150. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  5151. WFIFOB(fd,c*13+16)= c;
  5152. c++;
  5153. }
  5154. }
  5155. if(c > 0) {
  5156. WFIFOW(fd,2)=c*13+4;
  5157. WFIFOSET(fd,WFIFOW(fd,2));
  5158. sd->state.produce_flag = 1;
  5159. sd->repair_target=dstsd->bl.id;
  5160. }else
  5161. clif_skill_fail(sd,sd->skillid,0,0);
  5162. return 0;
  5163. }
  5164. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  5165. {
  5166. int view,fd;
  5167. nullpo_retr(0, sd);
  5168. fd=sd->fd;
  5169. WFIFOHEAD(fd,packet_len_table[0x1fe]);
  5170. WFIFOW(fd, 0)=0x1fe;
  5171. if((view = itemdb_viewid(nameid)) > 0)
  5172. WFIFOW(fd, 2)=view;
  5173. else
  5174. WFIFOW(fd, 2)=nameid;
  5175. WFIFOB(fd, 4)=flag;
  5176. WFIFOSET(fd,packet_len_table[0x1fe]);
  5177. return 0;
  5178. }
  5179. /*==========================================
  5180. * Weapon Refining - Taken from jAthena
  5181. *------------------------------------------
  5182. */
  5183. int clif_item_refine_list(struct map_session_data *sd)
  5184. {
  5185. int i,c;
  5186. int fd;
  5187. int skilllv;
  5188. int wlv;
  5189. int refine_item[5];
  5190. nullpo_retr(0, sd);
  5191. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  5192. fd=sd->fd;
  5193. refine_item[0] = -1;
  5194. refine_item[1] = pc_search_inventory(sd,1010);
  5195. refine_item[2] = pc_search_inventory(sd,1011);
  5196. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  5197. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5198. WFIFOW(fd,0)=0x221;
  5199. for(i=c=0;i<MAX_INVENTORY;i++){
  5200. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  5201. sd->status.inventory[i].identify==1 && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  5202. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  5203. WFIFOW(fd,c*13+ 4)=i+2;
  5204. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  5205. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  5206. WFIFOW(fd,c*13+10)=0;
  5207. WFIFOB(fd,c*13+12)=c;
  5208. c++;
  5209. }
  5210. }
  5211. WFIFOW(fd,2)=c*13+4;
  5212. WFIFOSET(fd,WFIFOW(fd,2));
  5213. sd->state.produce_flag = 1;
  5214. return 0;
  5215. }
  5216. /*==========================================
  5217. * アイテムによる一時的なスキル効果
  5218. *------------------------------------------
  5219. */
  5220. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv,const char *name)
  5221. {
  5222. int fd;
  5223. nullpo_retr(0, sd);
  5224. fd=sd->fd;
  5225. WFIFOHEAD(fd,packet_len_table[0x147]);
  5226. WFIFOW(fd, 0)=0x147;
  5227. WFIFOW(fd, 2)=skillid;
  5228. WFIFOW(fd, 4)=skill_get_inf(skillid);
  5229. WFIFOW(fd, 6)=0;
  5230. WFIFOW(fd, 8)=skilllv;
  5231. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  5232. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  5233. strncpy((char*)WFIFOP(fd,14),name,NAME_LENGTH);
  5234. WFIFOB(fd,38)=0;
  5235. WFIFOSET(fd,packet_len_table[0x147]);
  5236. return 0;
  5237. }
  5238. /*==========================================
  5239. * カートにアイテム追加
  5240. *------------------------------------------
  5241. */
  5242. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5243. {
  5244. int view,fd;
  5245. unsigned char *buf;
  5246. nullpo_retr(0, sd);
  5247. fd=sd->fd;
  5248. WFIFOHEAD(fd,packet_len_table[0x124]);
  5249. buf=WFIFOP(fd,0);
  5250. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  5251. return 1;
  5252. WBUFW(buf,0)=0x124;
  5253. WBUFW(buf,2)=n+2;
  5254. WBUFL(buf,4)=amount;
  5255. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  5256. WBUFW(buf,8)=view;
  5257. else
  5258. WBUFW(buf,8)=sd->status.cart[n].nameid;
  5259. WBUFB(buf,10)=sd->status.cart[n].identify;
  5260. WBUFB(buf,11)=sd->status.cart[n].attribute;
  5261. WBUFB(buf,12)=sd->status.cart[n].refine;
  5262. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  5263. WFIFOSET(fd,packet_len_table[0x124]);
  5264. return 0;
  5265. }
  5266. /*==========================================
  5267. * カートからアイテム削除
  5268. *------------------------------------------
  5269. */
  5270. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  5271. {
  5272. int fd;
  5273. nullpo_retr(0, sd);
  5274. fd=sd->fd;
  5275. WFIFOHEAD(fd,packet_len_table[0x125]);
  5276. WFIFOW(fd,0)=0x125;
  5277. WFIFOW(fd,2)=n+2;
  5278. WFIFOL(fd,4)=amount;
  5279. WFIFOSET(fd,packet_len_table[0x125]);
  5280. return 0;
  5281. }
  5282. /*==========================================
  5283. * カートのアイテムリスト
  5284. *------------------------------------------
  5285. */
  5286. int clif_cart_itemlist(struct map_session_data *sd)
  5287. {
  5288. struct item_data *id;
  5289. int i,n,fd;
  5290. unsigned char *buf;
  5291. nullpo_retr(0, sd);
  5292. fd=sd->fd;
  5293. WFIFOHEAD(fd, MAX_CART * 18 + 4);
  5294. buf = WFIFOP(fd,0);
  5295. #if PACKETVER < 5
  5296. for(i=0,n=0;i<MAX_CART;i++){
  5297. if(sd->status.cart[i].nameid<=0)
  5298. continue;
  5299. id = itemdb_search(sd->status.cart[i].nameid);
  5300. if(itemdb_isequip2(id))
  5301. continue;
  5302. WBUFW(buf,n*10+4)=i+2;
  5303. if(id->view_id > 0)
  5304. WBUFW(buf,n*10+6)=id->view_id;
  5305. else
  5306. WBUFW(buf,n*10+6)=sd->status.cart[i].nameid;
  5307. WBUFB(buf,n*10+8)=itemtype(id->type);
  5308. WBUFB(buf,n*10+9)=sd->status.cart[i].identify;
  5309. WBUFW(buf,n*10+10)=sd->status.cart[i].amount;
  5310. WBUFW(buf,n*10+12)=0;
  5311. n++;
  5312. }
  5313. if(n){
  5314. WBUFW(buf,0)=0x123;
  5315. WBUFW(buf,2)=4+n*10;
  5316. WFIFOSET(fd,WFIFOW(fd,2));
  5317. }
  5318. #else
  5319. for(i=0,n=0;i<MAX_CART;i++){
  5320. if(sd->status.cart[i].nameid<=0)
  5321. continue;
  5322. id = itemdb_search(sd->status.cart[i].nameid);
  5323. if(itemdb_isequip2(id))
  5324. continue;
  5325. WBUFW(buf,n*18+4)=i+2;
  5326. if(id->view_id > 0)
  5327. WBUFW(buf,n*18+6)=id->view_id;
  5328. else
  5329. WBUFW(buf,n*18+6)=sd->status.cart[i].nameid;
  5330. WBUFB(buf,n*18+8)=itemtype(id->type);
  5331. WBUFB(buf,n*18+9)=sd->status.cart[i].identify;
  5332. WBUFW(buf,n*18+10)=sd->status.cart[i].amount;
  5333. WBUFW(buf,n*18+12)=0; //Here goes the equip location, which seems unnecessary to fill for the cart data.
  5334. clif_addcards(WBUFP(buf,n*18+14), &sd->status.cart[i]);
  5335. n++;
  5336. }
  5337. if(n){
  5338. WBUFW(buf,0)=0x1ef;
  5339. WBUFW(buf,2)=4+n*18;
  5340. WFIFOSET(fd,WFIFOW(fd,2));
  5341. }
  5342. #endif
  5343. return 0;
  5344. }
  5345. /*==========================================
  5346. * カートの装備品リスト
  5347. *------------------------------------------
  5348. */
  5349. int clif_cart_equiplist(struct map_session_data *sd)
  5350. {
  5351. struct item_data *id;
  5352. int i,n,fd;
  5353. unsigned char *buf;
  5354. nullpo_retr(0, sd);
  5355. fd=sd->fd;
  5356. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  5357. buf = WFIFOP(fd,0);
  5358. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5359. if(sd->status.cart[i].nameid<=0)
  5360. continue;
  5361. id = itemdb_search(sd->status.cart[i].nameid);
  5362. if(!itemdb_isequip2(id))
  5363. continue;
  5364. WBUFW(buf,n*20+4)=i+2;
  5365. if(id->view_id > 0)
  5366. WBUFW(buf,n*20+6)=id->view_id;
  5367. else
  5368. WBUFW(buf,n*20+6)=sd->status.cart[i].nameid;
  5369. WBUFB(buf,n*20+8)=itemtype(id->type);
  5370. WBUFB(buf,n*20+9)=sd->status.cart[i].identify;
  5371. WBUFW(buf,n*20+10)=id->equip;
  5372. WBUFW(buf,n*20+12)=sd->status.cart[i].equip;
  5373. WBUFB(buf,n*20+14)=sd->status.cart[i].attribute;
  5374. WBUFB(buf,n*20+15)=sd->status.cart[i].refine;
  5375. clif_addcards(WBUFP(buf, n*20+16), &sd->status.cart[i]);
  5376. n++;
  5377. }
  5378. if(n){
  5379. WBUFW(buf,0)=0x122;
  5380. WBUFW(buf,2)=4+n*20;
  5381. WFIFOSET(fd,WFIFOW(fd,2));
  5382. }
  5383. return 0;
  5384. }
  5385. /*==========================================
  5386. * 露店開設
  5387. *------------------------------------------
  5388. */
  5389. int clif_openvendingreq(struct map_session_data *sd,int num)
  5390. {
  5391. int fd;
  5392. nullpo_retr(0, sd);
  5393. fd=sd->fd;
  5394. WFIFOHEAD(fd,packet_len_table[0x12d]);
  5395. WFIFOW(fd,0)=0x12d;
  5396. WFIFOW(fd,2)=num;
  5397. WFIFOSET(fd,packet_len_table[0x12d]);
  5398. return 0;
  5399. }
  5400. /*==========================================
  5401. * 露店看板表示
  5402. *------------------------------------------
  5403. */
  5404. int clif_showvendingboard(struct block_list* bl,char *message,int fd)
  5405. {
  5406. unsigned char buf[128];
  5407. nullpo_retr(0, bl);
  5408. WBUFW(buf,0)=0x131;
  5409. WBUFL(buf,2)=bl->id;
  5410. strncpy((char*)WBUFP(buf,6),message,80);
  5411. if(fd){
  5412. WFIFOHEAD(fd,packet_len_table[0x131]);
  5413. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x131]);
  5414. WFIFOSET(fd,packet_len_table[0x131]);
  5415. }else{
  5416. clif_send(buf,packet_len_table[0x131],bl,AREA_WOS);
  5417. }
  5418. return 0;
  5419. }
  5420. /*==========================================
  5421. * 露店看板消去
  5422. *------------------------------------------
  5423. */
  5424. int clif_closevendingboard(struct block_list* bl,int fd)
  5425. {
  5426. unsigned char buf[16];
  5427. nullpo_retr(0, bl);
  5428. WBUFW(buf,0)=0x132;
  5429. WBUFL(buf,2)=bl->id;
  5430. if(fd){
  5431. WFIFOHEAD(fd,packet_len_table[0x132]);
  5432. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x132]);
  5433. WFIFOSET(fd,packet_len_table[0x132]);
  5434. }else{
  5435. clif_send(buf,packet_len_table[0x132],bl,AREA_WOS);
  5436. }
  5437. return 0;
  5438. }
  5439. /*==========================================
  5440. * 露店アイテムリスト
  5441. *------------------------------------------
  5442. */
  5443. int clif_vendinglist(struct map_session_data *sd,int id,struct vending *vending)
  5444. {
  5445. struct item_data *data;
  5446. int i,n,index,fd;
  5447. struct map_session_data *vsd;
  5448. unsigned char *buf;
  5449. nullpo_retr(0, sd);
  5450. nullpo_retr(0, vending);
  5451. nullpo_retr(0, vsd=map_id2sd(id));
  5452. fd=sd->fd;
  5453. WFIFOHEAD(fd, 8+vsd->vend_num*22);
  5454. buf = WFIFOP(fd,0);
  5455. for(i=0,n=0;i<vsd->vend_num;i++){
  5456. if(vending[i].amount<=0)
  5457. continue;
  5458. WBUFL(buf,8+n*22)=vending[i].value;
  5459. WBUFW(buf,12+n*22)=vending[i].amount;
  5460. WBUFW(buf,14+n*22)=(index=vending[i].index)+2;
  5461. if(vsd->status.cart[index].nameid <= 0 || vsd->status.cart[index].amount <= 0)
  5462. continue;
  5463. data = itemdb_search(vsd->status.cart[index].nameid);
  5464. WBUFB(buf,16+n*22)=itemtype(data->type);
  5465. if(data->view_id > 0)
  5466. WBUFW(buf,17+n*22)=data->view_id;
  5467. else
  5468. WBUFW(buf,17+n*22)=vsd->status.cart[index].nameid;
  5469. WBUFB(buf,19+n*22)=vsd->status.cart[index].identify;
  5470. WBUFB(buf,20+n*22)=vsd->status.cart[index].attribute;
  5471. WBUFB(buf,21+n*22)=vsd->status.cart[index].refine;
  5472. clif_addcards(WBUFP(buf, 22+n*22), &vsd->status.cart[index]);
  5473. n++;
  5474. }
  5475. if(n > 0){
  5476. WBUFW(buf,0)=0x133;
  5477. WBUFW(buf,2)=8+n*22;
  5478. WBUFL(buf,4)=id;
  5479. WFIFOSET(fd,WFIFOW(fd,2));
  5480. }
  5481. return 0;
  5482. }
  5483. /*==========================================
  5484. * 露店アイテム購入失敗
  5485. *------------------------------------------
  5486. */
  5487. int clif_buyvending(struct map_session_data *sd,int index,int amount,int fail)
  5488. {
  5489. int fd;
  5490. nullpo_retr(0, sd);
  5491. fd=sd->fd;
  5492. WFIFOHEAD(fd,packet_len_table[0x135]);
  5493. WFIFOW(fd,0)=0x135;
  5494. WFIFOW(fd,2)=index+2;
  5495. WFIFOW(fd,4)=amount;
  5496. WFIFOB(fd,6)=fail;
  5497. WFIFOSET(fd,packet_len_table[0x135]);
  5498. return 0;
  5499. }
  5500. /*==========================================
  5501. * 露店開設成功
  5502. *------------------------------------------
  5503. */
  5504. int clif_openvending(struct map_session_data *sd,int id,struct vending *vending)
  5505. {
  5506. struct item_data *data;
  5507. int i,n,index,fd;
  5508. unsigned char *buf;
  5509. nullpo_retr(0, sd);
  5510. fd=sd->fd;
  5511. WFIFOHEAD(fd, 8+sd->vend_num*22);
  5512. buf = WFIFOP(fd,0);
  5513. for(i=0,n=0;i<sd->vend_num;i++){
  5514. if (sd->vend_num > 2+pc_checkskill(sd,MC_VENDING)) return 0;
  5515. WBUFL(buf,8+n*22)=vending[i].value;
  5516. WBUFW(buf,12+n*22)=(index=vending[i].index)+2;
  5517. WBUFW(buf,14+n*22)=vending[i].amount;
  5518. if(sd->status.cart[index].nameid <= 0 || sd->status.cart[index].amount <= 0 || sd->status.cart[index].identify==0 ||
  5519. sd->status.cart[index].attribute==1) // Prevent unidentified and broken items from being sold [Valaris]
  5520. continue;
  5521. data = itemdb_search(sd->status.cart[index].nameid);
  5522. WBUFB(buf,16+n*22)=itemtype(data->type);
  5523. if(data->view_id > 0)
  5524. WBUFW(buf,17+n*22)=data->view_id;
  5525. else
  5526. WBUFW(buf,17+n*22)=sd->status.cart[index].nameid;
  5527. WBUFB(buf,19+n*22)=sd->status.cart[index].identify;
  5528. WBUFB(buf,20+n*22)=sd->status.cart[index].attribute;
  5529. WBUFB(buf,21+n*22)=sd->status.cart[index].refine;
  5530. clif_addcards(WBUFP(buf, 22+n*22), &sd->status.cart[index]);
  5531. n++;
  5532. }
  5533. if(n > 0){
  5534. WBUFW(buf,0)=0x136;
  5535. WBUFW(buf,2)=8+n*22;
  5536. WBUFL(buf,4)=id;
  5537. WFIFOSET(fd,WFIFOW(fd,2));
  5538. }
  5539. return n;
  5540. }
  5541. /*==========================================
  5542. * 露店アイテム販売報告
  5543. *------------------------------------------
  5544. */
  5545. int clif_vendingreport(struct map_session_data *sd,int index,int amount)
  5546. {
  5547. int fd;
  5548. nullpo_retr(0, sd);
  5549. fd=sd->fd;
  5550. WFIFOHEAD(fd,packet_len_table[0x137]);
  5551. WFIFOW(fd,0)=0x137;
  5552. WFIFOW(fd,2)=index+2;
  5553. WFIFOW(fd,4)=amount;
  5554. WFIFOSET(fd,packet_len_table[0x137]);
  5555. return 0;
  5556. }
  5557. /*==========================================
  5558. * パーティ作成完了
  5559. *------------------------------------------
  5560. */
  5561. int clif_party_created(struct map_session_data *sd,int flag)
  5562. {
  5563. int fd;
  5564. // printf("clif_party_message(%s, %d, %s)\n", p->name, account_id, mes);
  5565. nullpo_retr(0, sd);
  5566. fd=sd->fd;
  5567. WFIFOHEAD(fd,packet_len_table[0xfa]);
  5568. WFIFOW(fd,0)=0xfa;
  5569. WFIFOB(fd,2)=flag;
  5570. WFIFOSET(fd,packet_len_table[0xfa]);
  5571. return 0;
  5572. }
  5573. int clif_party_main_info(struct party *p, int fd)
  5574. {
  5575. struct map_session_data *sd;
  5576. int i;
  5577. unsigned char buf[96];
  5578. for (i=0; i<MAX_PARTY && !p->member[i].leader; i++);
  5579. if (i >= MAX_PARTY) return 0; //Should never happen...
  5580. sd = p->member[i].sd;
  5581. WBUFW(buf,0)=0x1e9;
  5582. WBUFL(buf,2)= p->member[i].account_id;
  5583. WBUFL(buf,6)= 0; //We don't know yet what this long is about.
  5584. WBUFW(buf,10)=sd?sd->bl.x:0;
  5585. WBUFW(buf,12)=sd?sd->bl.y:0;
  5586. WBUFB(buf,14)=(p->member[i].online)?0:1; //This byte is also unconfirmed...
  5587. memcpy(WBUFP(buf,15), p->name, NAME_LENGTH);
  5588. memcpy(WBUFP(buf,39), p->member[i].name, NAME_LENGTH);
  5589. memcpy(WBUFP(buf,63), mapindex_id2name(p->member[i].map), MAP_NAME_LENGTH);
  5590. WBUFB(buf,79) = (p->item&1)?1:0;
  5591. WBUFB(buf,80) = (p->item&2)?1:0;
  5592. if(fd>=0){
  5593. WFIFOHEAD(fd,packet_len_table[0x1e9]);
  5594. memcpy(WFIFOP(fd,0),buf,packet_len_table[0x1e9]);
  5595. WFIFOSET(fd,packet_len_table[0x1e9]);
  5596. return 1;
  5597. }
  5598. if (!sd) {
  5599. for (i=0; i<MAX_PARTY && !p->member[i].sd; i++)
  5600. if (i >= MAX_PARTY) return 0; //Should never happen...
  5601. sd=p->member[i].sd;
  5602. }
  5603. clif_send(buf,packet_len_table[0x1e9],&sd->bl,PARTY);
  5604. return 1;
  5605. }
  5606. /*==========================================
  5607. * パーティ情報送信
  5608. *------------------------------------------
  5609. */
  5610. int clif_party_info(struct party *p,int fd)
  5611. {
  5612. unsigned char buf[1024];
  5613. int i,c;
  5614. struct map_session_data *sd=NULL;
  5615. nullpo_retr(0, p);
  5616. WBUFW(buf,0)=0xfb;
  5617. memcpy(WBUFP(buf,4),p->name,NAME_LENGTH);
  5618. for(i=c=0;i<MAX_PARTY;i++){
  5619. struct party_member *m=&p->member[i];
  5620. if(m->account_id>0){
  5621. if(sd==NULL) sd=m->sd;
  5622. WBUFL(buf,28+c*46)=m->account_id;
  5623. memcpy(WBUFP(buf,28+c*46+ 4),m->name,NAME_LENGTH);
  5624. memcpy(WBUFP(buf,28+c*46+28),mapindex_id2name(m->map),MAP_NAME_LENGTH);
  5625. WBUFB(buf,28+c*46+44)=(m->leader)?0:1;
  5626. WBUFB(buf,28+c*46+45)=(m->online)?0:1;
  5627. c++;
  5628. }
  5629. }
  5630. WBUFW(buf,2)=28+c*46;
  5631. if(fd>=0){ // fdが設定されてるならそれに送る
  5632. WFIFOHEAD(fd, 28+c*46);
  5633. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  5634. WFIFOSET(fd,WFIFOW(fd,2));
  5635. return 9;
  5636. }
  5637. if(sd!=NULL)
  5638. clif_send(buf,WBUFW(buf,2),&sd->bl,PARTY);
  5639. return 0;
  5640. }
  5641. /*==========================================
  5642. * パーティ勧誘
  5643. *------------------------------------------
  5644. */
  5645. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5646. {
  5647. int fd;
  5648. struct party *p;
  5649. nullpo_retr(0, sd);
  5650. nullpo_retr(0, tsd);
  5651. fd=tsd->fd;
  5652. if( (p=party_search(sd->status.party_id))==NULL )
  5653. return 0;
  5654. WFIFOHEAD(fd,packet_len_table[0xfe]);
  5655. WFIFOW(fd,0)=0xfe;
  5656. WFIFOL(fd,2)=sd->status.account_id;
  5657. memcpy(WFIFOP(fd,6),p->name,NAME_LENGTH);
  5658. WFIFOSET(fd,packet_len_table[0xfe]);
  5659. return 0;
  5660. }
  5661. /*==========================================
  5662. * パーティ勧誘結果
  5663. *------------------------------------------
  5664. */
  5665. int clif_party_inviteack(struct map_session_data *sd,char *nick,int flag)
  5666. {
  5667. int fd;
  5668. nullpo_retr(0, sd);
  5669. fd=sd->fd;
  5670. WFIFOHEAD(fd,packet_len_table[0xfd]);
  5671. WFIFOW(fd,0)=0xfd;
  5672. memcpy(WFIFOP(fd,2),nick,NAME_LENGTH);
  5673. WFIFOB(fd,26)=flag;
  5674. WFIFOSET(fd,packet_len_table[0xfd]);
  5675. return 0;
  5676. }
  5677. /*==========================================
  5678. * パーティ設定送信
  5679. * flag & 0x001=exp変更ミス
  5680. * 0x010=item変更ミス
  5681. * 0x100=一人にのみ送信
  5682. *------------------------------------------
  5683. */
  5684. int clif_party_option(struct party *p,struct map_session_data *sd,int flag)
  5685. {
  5686. unsigned char buf[16];
  5687. nullpo_retr(0, p);
  5688. // if(battle_config.etc_log)
  5689. // printf("clif_party_option: %d %d %d\n",p->exp,p->item,flag);
  5690. if(sd==NULL && flag==0){
  5691. int i;
  5692. for(i=0;i<MAX_PARTY;i++)
  5693. if((sd=map_id2sd(p->member[i].account_id))!=NULL)
  5694. break;
  5695. }
  5696. if(sd==NULL)
  5697. return 0;
  5698. WBUFW(buf,0)=0x101;
  5699. WBUFW(buf,2)=((flag&0x01)?2:p->exp);
  5700. WBUFW(buf,4)=0; //NOTE: We don't know yet what this is for, it is NOT for item share rules, though. [Skotlex]
  5701. if(flag==0)
  5702. clif_send(buf,packet_len_table[0x101],&sd->bl,PARTY);
  5703. else {
  5704. WFIFOHEAD(sd->fd,packet_len_table[0x101]);
  5705. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x101]);
  5706. WFIFOSET(sd->fd,packet_len_table[0x101]);
  5707. }
  5708. return 0;
  5709. }
  5710. /*==========================================
  5711. * パーティ脱退(脱退前に呼ぶこと)
  5712. *------------------------------------------
  5713. */
  5714. int clif_party_leaved(struct party *p,struct map_session_data *sd,int account_id,char *name,int flag)
  5715. {
  5716. unsigned char buf[64];
  5717. int i;
  5718. nullpo_retr(0, p);
  5719. WBUFW(buf,0)=0x105;
  5720. WBUFL(buf,2)=account_id;
  5721. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5722. WBUFB(buf,30)=flag&0x0f;
  5723. if((flag&0xf0)==0){
  5724. if(sd==NULL)
  5725. for(i=0;i<MAX_PARTY;i++)
  5726. if((sd=p->member[i].sd)!=NULL)
  5727. break;
  5728. if (sd!=NULL)
  5729. clif_send(buf,packet_len_table[0x105],&sd->bl,PARTY);
  5730. } else if (sd!=NULL) {
  5731. WFIFOHEAD(sd->fd,packet_len_table[0x105]);
  5732. memcpy(WFIFOP(sd->fd,0),buf,packet_len_table[0x105]);
  5733. WFIFOSET(sd->fd,packet_len_table[0x105]);
  5734. }
  5735. return 0;
  5736. }
  5737. /*==========================================
  5738. * パーティメッセージ送信
  5739. *------------------------------------------
  5740. */
  5741. int clif_party_message(struct party *p,int account_id,char *mes,int len)
  5742. {
  5743. struct map_session_data *sd;
  5744. int i;
  5745. nullpo_retr(0, p);
  5746. for(i=0;i<MAX_PARTY;i++){
  5747. if((sd=p->member[i].sd)!=NULL)
  5748. break;
  5749. }
  5750. if(sd!=NULL){
  5751. unsigned char buf[1024];
  5752. WBUFW(buf,0)=0x109;
  5753. WBUFW(buf,2)=len+8;
  5754. WBUFL(buf,4)=account_id;
  5755. memcpy(WBUFP(buf,8),mes,len);
  5756. clif_send(buf,len+8,&sd->bl,PARTY);
  5757. }
  5758. return 0;
  5759. }
  5760. /*==========================================
  5761. * パーティ座標通知
  5762. *------------------------------------------
  5763. */
  5764. int clif_party_xy(struct map_session_data *sd)
  5765. {
  5766. unsigned char buf[16];
  5767. nullpo_retr(0, sd);
  5768. WBUFW(buf,0)=0x107;
  5769. WBUFL(buf,2)=sd->status.account_id;
  5770. WBUFW(buf,6)=sd->bl.x;
  5771. WBUFW(buf,8)=sd->bl.y;
  5772. clif_send(buf,packet_len_table[0x107],&sd->bl,PARTY_SAMEMAP_WOS);
  5773. return 0;
  5774. }
  5775. /*==========================================
  5776. * パーティHP通知
  5777. *------------------------------------------
  5778. */
  5779. int clif_party_hp(struct map_session_data *sd)
  5780. {
  5781. unsigned char buf[16];
  5782. nullpo_retr(0, sd);
  5783. WBUFW(buf,0)=0x106;
  5784. WBUFL(buf,2)=sd->status.account_id;
  5785. WBUFW(buf,6)=(sd->status.hp > 0x7fff)? 0x7fff:sd->status.hp;
  5786. WBUFW(buf,8)=(sd->status.max_hp > 0x7fff)? 0x7fff:sd->status.max_hp;
  5787. clif_send(buf,packet_len_table[0x106],&sd->bl,PARTY_AREA_WOS);
  5788. return 0;
  5789. }
  5790. /*==========================================
  5791. * Sends HP bar to a single fd. [Skotlex]
  5792. *------------------------------------------
  5793. */
  5794. static void clif_hpmeter_single(int fd, struct map_session_data *sd)
  5795. {
  5796. WFIFOHEAD(fd,packet_len_table[0x106]);
  5797. WFIFOW(fd,0) = 0x106;
  5798. WFIFOL(fd,2) = sd->status.account_id;
  5799. WFIFOW(fd,6) = (sd->status.hp > 0x7fff) ? 0x7fff : sd->status.hp;
  5800. WFIFOW(fd,8) = (sd->status.max_hp > 0x7fff) ? 0x7fff : sd->status.max_hp;
  5801. WFIFOSET (fd, packet_len_table[0x106]);
  5802. }
  5803. /*==========================================
  5804. * GMへ場所とHP通知
  5805. *------------------------------------------
  5806. */
  5807. int clif_hpmeter(struct map_session_data *sd)
  5808. {
  5809. struct map_session_data *sd2;
  5810. unsigned char buf[16];
  5811. int i, x0, y0, x1, y1;
  5812. int level;
  5813. nullpo_retr(0, sd);
  5814. x0 = sd->bl.x - AREA_SIZE;
  5815. y0 = sd->bl.y - AREA_SIZE;
  5816. x1 = sd->bl.x + AREA_SIZE;
  5817. y1 = sd->bl.y + AREA_SIZE;
  5818. WBUFW(buf,0) = 0x106;
  5819. WBUFL(buf,2) = sd->status.account_id;
  5820. WBUFW(buf,6) = (sd->status.hp > 0x7fff) ? 0x7fff : sd->status.hp;
  5821. WBUFW(buf,8) = (sd->status.max_hp > 0x7fff) ? 0x7fff : sd->status.max_hp;
  5822. for (i = 0; i < fd_max; i++) {
  5823. if (session[i] && (sd2 = (struct map_session_data*)session[i]->session_data) && sd != sd2 && sd2->state.auth) {
  5824. if (sd2->bl.m != sd->bl.m ||
  5825. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  5826. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  5827. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  5828. level < pc_isGM(sd))
  5829. continue;
  5830. WFIFOHEAD (i, packet_len_table[0x106]);
  5831. memcpy (WFIFOP(i,0), buf, packet_len_table[0x106]);
  5832. WFIFOSET (i, packet_len_table[0x106]);
  5833. }
  5834. }
  5835. return 0;
  5836. }
  5837. /*==========================================
  5838. * パーティ場所移動(未使用)
  5839. *------------------------------------------
  5840. */
  5841. int clif_party_move(struct party *p,struct map_session_data *sd,int online)
  5842. {
  5843. unsigned char buf[128];
  5844. nullpo_retr(0, sd);
  5845. nullpo_retr(0, p);
  5846. WBUFW(buf, 0)=0x104;
  5847. WBUFL(buf, 2)=sd->status.account_id;
  5848. WBUFL(buf, 6)=0;
  5849. WBUFW(buf,10)=sd->bl.x;
  5850. WBUFW(buf,12)=sd->bl.y;
  5851. WBUFB(buf,14)=!online;
  5852. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  5853. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  5854. memcpy(WBUFP(buf,63),map[sd->bl.m].name, MAP_NAME_LENGTH);
  5855. clif_send(buf,packet_len_table[0x104],&sd->bl,PARTY);
  5856. return 0;
  5857. }
  5858. /*==========================================
  5859. * 攻撃するために移動が必要
  5860. *------------------------------------------
  5861. */
  5862. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5863. {
  5864. int fd;
  5865. nullpo_retr(0, sd);
  5866. nullpo_retr(0, bl);
  5867. fd=sd->fd;
  5868. WFIFOHEAD(fd,packet_len_table[0x139]);
  5869. WFIFOW(fd, 0)=0x139;
  5870. WFIFOL(fd, 2)=bl->id;
  5871. WFIFOW(fd, 6)=bl->x;
  5872. WFIFOW(fd, 8)=bl->y;
  5873. WFIFOW(fd,10)=sd->bl.x;
  5874. WFIFOW(fd,12)=sd->bl.y;
  5875. WFIFOW(fd,14)=sd->attackrange;
  5876. WFIFOSET(fd,packet_len_table[0x139]);
  5877. return 0;
  5878. }
  5879. /*==========================================
  5880. * 製造エフェクト
  5881. *------------------------------------------
  5882. */
  5883. int clif_produceeffect(struct map_session_data *sd,int flag,int nameid)
  5884. {
  5885. int view,fd;
  5886. nullpo_retr(0, sd);
  5887. fd=sd->fd;
  5888. // 名前の登録と送信を先にしておく
  5889. if( map_charid2nick(sd->status.char_id)==NULL )
  5890. map_addchariddb(sd->status.char_id,sd->status.name);
  5891. clif_solved_charname(sd,sd->status.char_id);
  5892. WFIFOHEAD(fd,packet_len_table[0x18f]);
  5893. WFIFOW(fd, 0)=0x18f;
  5894. WFIFOW(fd, 2)=flag;
  5895. if((view = itemdb_viewid(nameid)) > 0)
  5896. WFIFOW(fd, 4)=view;
  5897. else
  5898. WFIFOW(fd, 4)=nameid;
  5899. WFIFOSET(fd,packet_len_table[0x18f]);
  5900. return 0;
  5901. }
  5902. // pet
  5903. int clif_catch_process(struct map_session_data *sd)
  5904. {
  5905. int fd;
  5906. nullpo_retr(0, sd);
  5907. fd=sd->fd;
  5908. WFIFOHEAD(fd,packet_len_table[0x19e]);
  5909. WFIFOW(fd,0)=0x19e;
  5910. WFIFOSET(fd,packet_len_table[0x19e]);
  5911. return 0;
  5912. }
  5913. int clif_pet_rulet(struct map_session_data *sd,int data)
  5914. {
  5915. int fd;
  5916. nullpo_retr(0, sd);
  5917. fd=sd->fd;
  5918. WFIFOHEAD(fd,packet_len_table[0x1a0]);
  5919. WFIFOW(fd,0)=0x1a0;
  5920. WFIFOB(fd,2)=data;
  5921. WFIFOSET(fd,packet_len_table[0x1a0]);
  5922. return 0;
  5923. }
  5924. /*==========================================
  5925. * pet卵リスト作成
  5926. *------------------------------------------
  5927. */
  5928. int clif_sendegg(struct map_session_data *sd)
  5929. {
  5930. //R 01a6 <len>.w <index>.w*
  5931. int i,n=0,fd;
  5932. nullpo_retr(0, sd);
  5933. fd=sd->fd;
  5934. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5935. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5936. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5937. return 0;
  5938. }
  5939. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5940. WFIFOW(fd,0)=0x1a6;
  5941. if(sd->status.pet_id <= 0) {
  5942. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5943. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5944. sd->inventory_data[i]->type!=7 ||
  5945. sd->status.inventory[i].amount<=0)
  5946. continue;
  5947. WFIFOW(fd,n*2+4)=i+2;
  5948. n++;
  5949. }
  5950. }
  5951. WFIFOW(fd,2)=4+n*2;
  5952. WFIFOSET(fd,WFIFOW(fd,2));
  5953. return 0;
  5954. }
  5955. int clif_send_petdata(struct map_session_data *sd,int type,int param)
  5956. {
  5957. int fd;
  5958. nullpo_retr(0, sd);
  5959. nullpo_retr(0, sd->pd);
  5960. fd=sd->fd;
  5961. WFIFOHEAD(fd,packet_len_table[0x1a4]);
  5962. WFIFOW(fd,0)=0x1a4;
  5963. WFIFOB(fd,2)=type;
  5964. WFIFOL(fd,3)=sd->pd->bl.id;
  5965. WFIFOL(fd,7)=param;
  5966. WFIFOSET(fd,packet_len_table[0x1a4]);
  5967. return 0;
  5968. }
  5969. int clif_send_petstatus(struct map_session_data *sd)
  5970. {
  5971. int fd;
  5972. nullpo_retr(0, sd);
  5973. fd=sd->fd;
  5974. WFIFOHEAD(fd,packet_len_table[0x1a2]);
  5975. WFIFOW(fd,0)=0x1a2;
  5976. memcpy(WFIFOP(fd,2),sd->pet.name,NAME_LENGTH);
  5977. WFIFOB(fd,26)=(battle_config.pet_rename == 1)? 0:sd->pet.rename_flag;
  5978. WFIFOW(fd,27)=sd->pet.level;
  5979. WFIFOW(fd,29)=sd->pet.hungry;
  5980. WFIFOW(fd,31)=sd->pet.intimate;
  5981. WFIFOW(fd,33)=sd->pet.equip;
  5982. WFIFOSET(fd,packet_len_table[0x1a2]);
  5983. return 0;
  5984. }
  5985. /*==========================================
  5986. *
  5987. *------------------------------------------
  5988. */
  5989. int clif_pet_emotion(struct pet_data *pd,int param)
  5990. {
  5991. unsigned char buf[16];
  5992. struct map_session_data *sd;
  5993. nullpo_retr(0, pd);
  5994. nullpo_retr(0, sd = pd->msd);
  5995. memset(buf,0,packet_len_table[0x1aa]);
  5996. WBUFW(buf,0)=0x1aa;
  5997. WBUFL(buf,2)=pd->bl.id;
  5998. if(param >= 100 && sd->petDB->talk_convert_class) {
  5999. if(sd->petDB->talk_convert_class < 0)
  6000. return 0;
  6001. else if(sd->petDB->talk_convert_class > 0) {
  6002. param -= (pd->class_ - 100)*100;
  6003. param += (sd->petDB->talk_convert_class - 100)*100;
  6004. }
  6005. }
  6006. WBUFL(buf,6)=param;
  6007. clif_send(buf,packet_len_table[0x1aa],&pd->bl,AREA);
  6008. return 0;
  6009. }
  6010. int clif_pet_performance(struct block_list *bl,int param)
  6011. {
  6012. unsigned char buf[16];
  6013. nullpo_retr(0, bl);
  6014. memset(buf,0,packet_len_table[0x1a4]);
  6015. WBUFW(buf,0)=0x1a4;
  6016. WBUFB(buf,2)=4;
  6017. WBUFL(buf,3)=bl->id;
  6018. WBUFL(buf,7)=param;
  6019. clif_send(buf,packet_len_table[0x1a4],bl,AREA);
  6020. return 0;
  6021. }
  6022. int clif_pet_equip(struct pet_data *pd,int nameid)
  6023. {
  6024. unsigned char buf[16];
  6025. int view;
  6026. nullpo_retr(0, pd);
  6027. memset(buf,0,packet_len_table[0x1a4]);
  6028. WBUFW(buf,0)=0x1a4;
  6029. WBUFB(buf,2)=3;
  6030. WBUFL(buf,3)=pd->bl.id;
  6031. if((view = itemdb_viewid(nameid)) > 0)
  6032. WBUFL(buf,7)=view;
  6033. else
  6034. WBUFL(buf,7)=nameid;
  6035. clif_send(buf,packet_len_table[0x1a4],&pd->bl,AREA);
  6036. return 0;
  6037. }
  6038. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6039. {
  6040. int fd;
  6041. nullpo_retr(0, sd);
  6042. fd=sd->fd;
  6043. WFIFOHEAD(fd,packet_len_table[0x1a3]);
  6044. WFIFOW(fd,0)=0x1a3;
  6045. WFIFOB(fd,2)=fail;
  6046. WFIFOW(fd,3)=foodid;
  6047. WFIFOSET(fd,packet_len_table[0x1a3]);
  6048. return 0;
  6049. }
  6050. /*==========================================
  6051. * オートスペル リスト送信
  6052. *------------------------------------------
  6053. */
  6054. int clif_autospell(struct map_session_data *sd,int skilllv)
  6055. {
  6056. int fd;
  6057. nullpo_retr(0, sd);
  6058. fd=sd->fd;
  6059. WFIFOHEAD(fd,packet_len_table[0x1cd]);
  6060. WFIFOW(fd, 0)=0x1cd;
  6061. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6062. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6063. else
  6064. WFIFOL(fd,2)= 0x00000000;
  6065. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6066. WFIFOL(fd,6)= MG_COLDBOLT;
  6067. else
  6068. WFIFOL(fd,6)= 0x00000000;
  6069. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6070. WFIFOL(fd,10)= MG_FIREBOLT;
  6071. else
  6072. WFIFOL(fd,10)= 0x00000000;
  6073. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6074. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6075. else
  6076. WFIFOL(fd,14)= 0x00000000;
  6077. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6078. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6079. else
  6080. WFIFOL(fd,18)= 0x00000000;
  6081. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6082. WFIFOL(fd,22)= MG_FIREBALL;
  6083. else
  6084. WFIFOL(fd,22)= 0x00000000;
  6085. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6086. WFIFOL(fd,26)= MG_FROSTDIVER;
  6087. else
  6088. WFIFOL(fd,26)= 0x00000000;
  6089. WFIFOSET(fd,packet_len_table[0x1cd]);
  6090. return 0;
  6091. }
  6092. /*==========================================
  6093. * ディボーションの青い糸
  6094. *------------------------------------------
  6095. */
  6096. int clif_devotion(struct map_session_data *sd)
  6097. {
  6098. unsigned char buf[56];
  6099. int i,n;
  6100. nullpo_retr(0, sd);
  6101. WBUFW(buf,0)=0x1cf;
  6102. WBUFL(buf,2)=sd->bl.id;
  6103. for(i=0,n=0;i<5;i++) {
  6104. if (!sd->devotion[i])
  6105. continue;
  6106. WBUFL(buf,6+4*n)=sd->devotion[i];
  6107. n++;
  6108. }
  6109. for(;n<5;n++)
  6110. WBUFL(buf,6+4*n)=0;
  6111. WBUFB(buf,26)=8;
  6112. WBUFB(buf,27)=0;
  6113. clif_send(buf,packet_len_table[0x1cf],&sd->bl,AREA);
  6114. return 0;
  6115. }
  6116. int clif_marionette(struct block_list *src, struct block_list *target)
  6117. {
  6118. unsigned char buf[56];
  6119. int n;
  6120. WBUFW(buf,0)=0x1cf;
  6121. WBUFL(buf,2)=src->id;
  6122. for(n=0;n<5;n++)
  6123. WBUFL(buf,6+4*n)=0;
  6124. if (target) //The target goes on the second slot.
  6125. WBUFL(buf,6+4) = target->id;
  6126. WBUFB(buf,26)=8;
  6127. WBUFB(buf,27)=0;
  6128. clif_send(buf,packet_len_table[0x1cf],src,AREA);
  6129. return 0;
  6130. }
  6131. /*==========================================
  6132. * 氣球
  6133. *------------------------------------------
  6134. */
  6135. int clif_spiritball(struct map_session_data *sd)
  6136. {
  6137. unsigned char buf[16];
  6138. nullpo_retr(0, sd);
  6139. WBUFW(buf,0)=0x1d0;
  6140. WBUFL(buf,2)=sd->bl.id;
  6141. WBUFW(buf,6)=sd->spiritball;
  6142. clif_send(buf,packet_len_table[0x1d0],&sd->bl,AREA);
  6143. return 0;
  6144. }
  6145. /*==========================================
  6146. *
  6147. *------------------------------------------
  6148. */
  6149. int clif_combo_delay(struct block_list *bl,int wait)
  6150. {
  6151. unsigned char buf[32];
  6152. nullpo_retr(0, bl);
  6153. WBUFW(buf,0)=0x1d2;
  6154. WBUFL(buf,2)=bl->id;
  6155. WBUFL(buf,6)=wait;
  6156. clif_send(buf,packet_len_table[0x1d2],bl,AREA);
  6157. return 0;
  6158. }
  6159. /*==========================================
  6160. *白刃取り
  6161. *------------------------------------------
  6162. */
  6163. int clif_bladestop(struct block_list *src,struct block_list *dst,
  6164. int _bool)
  6165. {
  6166. unsigned char buf[32];
  6167. nullpo_retr(0, src);
  6168. nullpo_retr(0, dst);
  6169. WBUFW(buf,0)=0x1d1;
  6170. WBUFL(buf,2)=src->id;
  6171. WBUFL(buf,6)=dst->id;
  6172. WBUFL(buf,10)=_bool;
  6173. clif_send(buf,packet_len_table[0x1d1],src,AREA);
  6174. return 0;
  6175. }
  6176. /*==========================================
  6177. *
  6178. *------------------------------------------
  6179. */
  6180. int clif_changemapcell(int m,int x,int y,int cell_type,int type)
  6181. {
  6182. struct block_list bl;
  6183. unsigned char buf[32];
  6184. bl.m = m;
  6185. bl.x = x;
  6186. bl.y = y;
  6187. WBUFW(buf,0) = 0x192;
  6188. WBUFW(buf,2) = x;
  6189. WBUFW(buf,4) = y;
  6190. WBUFW(buf,6) = cell_type;
  6191. memcpy(WBUFP(buf,8),map[m].name,MAP_NAME_LENGTH);
  6192. if(!type)
  6193. clif_send(buf,packet_len_table[0x192],&bl,AREA);
  6194. else
  6195. clif_send(buf,packet_len_table[0x192],&bl,ALL_SAMEMAP);
  6196. return 0;
  6197. }
  6198. /*==========================================
  6199. * MVPエフェクト
  6200. *------------------------------------------
  6201. */
  6202. int clif_mvp_effect(struct map_session_data *sd)
  6203. {
  6204. unsigned char buf[16];
  6205. nullpo_retr(0, sd);
  6206. WBUFW(buf,0)=0x10c;
  6207. WBUFL(buf,2)=sd->bl.id;
  6208. clif_send(buf,packet_len_table[0x10c],&sd->bl,AREA);
  6209. return 0;
  6210. }
  6211. /*==========================================
  6212. * MVPアイテム所得
  6213. *------------------------------------------
  6214. */
  6215. int clif_mvp_item(struct map_session_data *sd,int nameid)
  6216. {
  6217. int view,fd;
  6218. nullpo_retr(0, sd);
  6219. fd=sd->fd;
  6220. WFIFOHEAD(fd,packet_len_table[0x10a]);
  6221. WFIFOW(fd,0)=0x10a;
  6222. if((view = itemdb_viewid(nameid)) > 0)
  6223. WFIFOW(fd,2)=view;
  6224. else
  6225. WFIFOW(fd,2)=nameid;
  6226. WFIFOSET(fd,packet_len_table[0x10a]);
  6227. return 0;
  6228. }
  6229. /*==========================================
  6230. * MVP経験値所得
  6231. *------------------------------------------
  6232. */
  6233. int clif_mvp_exp(struct map_session_data *sd,int exp)
  6234. {
  6235. int fd;
  6236. nullpo_retr(0, sd);
  6237. fd=sd->fd;
  6238. WFIFOHEAD(fd,packet_len_table[0x10b]);
  6239. WFIFOW(fd,0)=0x10b;
  6240. WFIFOL(fd,2)=exp;
  6241. WFIFOSET(fd,packet_len_table[0x10b]);
  6242. return 0;
  6243. }
  6244. /*==========================================
  6245. * ギルド作成可否通知
  6246. *------------------------------------------
  6247. */
  6248. int clif_guild_created(struct map_session_data *sd,int flag)
  6249. {
  6250. int fd;
  6251. nullpo_retr(0, sd);
  6252. fd=sd->fd;
  6253. WFIFOHEAD(fd,packet_len_table[0x167]);
  6254. WFIFOW(fd,0)=0x167;
  6255. WFIFOB(fd,2)=flag;
  6256. WFIFOSET(fd,packet_len_table[0x167]);
  6257. return 0;
  6258. }
  6259. /*==========================================
  6260. * ギルド所属通知
  6261. *------------------------------------------
  6262. */
  6263. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  6264. {
  6265. int ps,fd;
  6266. nullpo_retr(0, sd);
  6267. nullpo_retr(0, g);
  6268. fd=sd->fd;
  6269. ps=guild_getposition(sd,g);
  6270. WFIFOHEAD(fd,packet_len_table[0x16c]);
  6271. memset(WFIFOP(fd,0),0,packet_len_table[0x16c]);
  6272. WFIFOW(fd,0)=0x16c;
  6273. WFIFOL(fd,2)=g->guild_id;
  6274. WFIFOL(fd,6)=g->emblem_id;
  6275. WFIFOL(fd,10)=g->position[ps].mode;
  6276. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  6277. WFIFOSET(fd,packet_len_table[0x16c]);
  6278. return 0;
  6279. }
  6280. /*==========================================
  6281. * ギルドメンバログイン通知
  6282. *------------------------------------------
  6283. */
  6284. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  6285. {
  6286. unsigned char buf[64];
  6287. nullpo_retr(0, g);
  6288. // printf("clif_guild_message(%s, %d, %s)\n", g->name, account_id, mes);
  6289. WBUFW(buf, 0)=0x16d;
  6290. WBUFL(buf, 2)=g->member[idx].account_id;
  6291. WBUFL(buf, 6)=g->member[idx].char_id;
  6292. WBUFL(buf,10)=flag;
  6293. if(g->member[idx].sd==NULL){
  6294. struct map_session_data *sd=guild_getavailablesd(g);
  6295. if(sd!=NULL)
  6296. clif_send(buf,packet_len_table[0x16d],&sd->bl,GUILD);
  6297. }else
  6298. clif_send(buf,packet_len_table[0x16d],&g->member[idx].sd->bl,GUILD_WOS);
  6299. return 0;
  6300. }
  6301. /*==========================================
  6302. * ギルドマスター通知(14dへの応答)
  6303. *------------------------------------------
  6304. */
  6305. int clif_guild_masterormember(struct map_session_data *sd)
  6306. {
  6307. int type=0x57,fd;
  6308. nullpo_retr(0, sd);
  6309. fd=sd->fd;
  6310. if(sd->state.gmaster_flag)
  6311. type=0xd7;
  6312. WFIFOHEAD(fd,packet_len_table[0x14e]);
  6313. WFIFOW(fd,0)=0x14e;
  6314. WFIFOL(fd,2)=type;
  6315. WFIFOSET(fd,packet_len_table[0x14e]);
  6316. return 0;
  6317. }
  6318. /*==========================================
  6319. * Basic Info (Territories [Valaris])
  6320. *------------------------------------------
  6321. */
  6322. int clif_guild_basicinfo(struct map_session_data *sd)
  6323. {
  6324. int fd,i,t=0;
  6325. struct guild *g;
  6326. struct guild_castle *gc=NULL;
  6327. nullpo_retr(0, sd);
  6328. fd=sd->fd;
  6329. g=guild_search(sd->status.guild_id);
  6330. if(g==NULL)
  6331. return 0;
  6332. WFIFOHEAD(fd,packet_len_table[0x1b6]);
  6333. WFIFOW(fd, 0)=0x1b6;//0x150;
  6334. WFIFOL(fd, 2)=g->guild_id;
  6335. WFIFOL(fd, 6)=g->guild_lv;
  6336. WFIFOL(fd,10)=g->connect_member;
  6337. WFIFOL(fd,14)=g->max_member;
  6338. WFIFOL(fd,18)=g->average_lv;
  6339. WFIFOL(fd,22)=g->exp;
  6340. WFIFOL(fd,26)=g->next_exp;
  6341. WFIFOL(fd,30)=0; // 上納
  6342. WFIFOL(fd,34)=0; // VW(性格の悪さ?:性向グラフ左右)
  6343. WFIFOL(fd,38)=0; // RF(正義の度合い?:性向グラフ上下)
  6344. WFIFOL(fd,42)=0; // 人数?
  6345. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  6346. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  6347. for(i=0;i<MAX_GUILDCASTLE;i++){
  6348. gc=guild_castle_search(i);
  6349. if(!gc) continue;
  6350. if(g->guild_id == gc->guild_id) t++;
  6351. }
  6352. if (t>=0 && t<=MAX_GUILDCASTLE) //(0=None, 1..24 = N of Casles) [Lupus]
  6353. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20);
  6354. else
  6355. strncpy((char*)WFIFOP(fd,94),msg_txt(299),20);
  6356. WFIFOSET(fd,packet_len_table[WFIFOW(fd,0)]);
  6357. clif_guild_emblem(sd,g); // Guild emblem vanish fix [Valaris]
  6358. return 0;
  6359. }
  6360. /*==========================================
  6361. * ギルド同盟/敵対情報
  6362. *------------------------------------------
  6363. */
  6364. int clif_guild_allianceinfo(struct map_session_data *sd)
  6365. {
  6366. int fd,i,c;
  6367. struct guild *g;
  6368. nullpo_retr(0, sd);
  6369. fd=sd->fd;
  6370. g=guild_search(sd->status.guild_id);
  6371. if(g==NULL)
  6372. return 0;
  6373. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  6374. WFIFOW(fd, 0)=0x14c;
  6375. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  6376. struct guild_alliance *a=&g->alliance[i];
  6377. if(a->guild_id>0){
  6378. WFIFOL(fd,c*32+4)=a->opposition;
  6379. WFIFOL(fd,c*32+8)=a->guild_id;
  6380. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  6381. c++;
  6382. }
  6383. }
  6384. WFIFOW(fd, 2)=c*32+4;
  6385. WFIFOSET(fd,WFIFOW(fd,2));
  6386. return 0;
  6387. }
  6388. /*==========================================
  6389. * ギルドメンバーリスト
  6390. *------------------------------------------
  6391. */
  6392. int clif_guild_memberlist(struct map_session_data *sd)
  6393. {
  6394. int fd;
  6395. int i,c;
  6396. struct guild *g;
  6397. nullpo_retr(0, sd);
  6398. fd=sd->fd;
  6399. if (!fd)
  6400. return 0;
  6401. g=guild_search(sd->status.guild_id);
  6402. if(g==NULL)
  6403. return 0;
  6404. WFIFOHEAD(fd, g->max_member * 104 + 4);
  6405. WFIFOW(fd, 0)=0x154;
  6406. for(i=0,c=0;i<g->max_member;i++){
  6407. struct guild_member *m=&g->member[i];
  6408. if(m->account_id==0)
  6409. continue;
  6410. WFIFOL(fd,c*104+ 4)=m->account_id;
  6411. WFIFOL(fd,c*104+ 8)=m->char_id;
  6412. WFIFOW(fd,c*104+12)=m->hair;
  6413. WFIFOW(fd,c*104+14)=m->hair_color;
  6414. WFIFOW(fd,c*104+16)=m->gender;
  6415. WFIFOW(fd,c*104+18)=m->class_;
  6416. WFIFOW(fd,c*104+20)=m->lv;
  6417. WFIFOL(fd,c*104+22)=m->exp;
  6418. WFIFOL(fd,c*104+26)=m->online;
  6419. WFIFOL(fd,c*104+30)=m->position;
  6420. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  6421. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  6422. c++;
  6423. }
  6424. WFIFOW(fd, 2)=c*104+4;
  6425. WFIFOSET(fd,WFIFOW(fd,2));
  6426. return 0;
  6427. }
  6428. /*==========================================
  6429. * ギルド役職名リスト
  6430. *------------------------------------------
  6431. */
  6432. int clif_guild_positionnamelist(struct map_session_data *sd)
  6433. {
  6434. int i,fd;
  6435. struct guild *g;
  6436. nullpo_retr(0, sd);
  6437. fd=sd->fd;
  6438. g=guild_search(sd->status.guild_id);
  6439. if(g==NULL)
  6440. return 0;
  6441. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  6442. WFIFOW(fd, 0)=0x166;
  6443. for(i=0;i<MAX_GUILDPOSITION;i++){
  6444. WFIFOL(fd,i*28+4)=i;
  6445. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  6446. }
  6447. WFIFOW(fd,2)=i*28+4;
  6448. WFIFOSET(fd,WFIFOW(fd,2));
  6449. return 0;
  6450. }
  6451. /*==========================================
  6452. * ギルド役職情報リスト
  6453. *------------------------------------------
  6454. */
  6455. int clif_guild_positioninfolist(struct map_session_data *sd)
  6456. {
  6457. int i,fd;
  6458. struct guild *g;
  6459. nullpo_retr(0, sd);
  6460. fd=sd->fd;
  6461. g=guild_search(sd->status.guild_id);
  6462. if(g==NULL)
  6463. return 0;
  6464. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  6465. WFIFOW(fd, 0)=0x160;
  6466. for(i=0;i<MAX_GUILDPOSITION;i++){
  6467. struct guild_position *p=&g->position[i];
  6468. WFIFOL(fd,i*16+ 4)=i;
  6469. WFIFOL(fd,i*16+ 8)=p->mode;
  6470. WFIFOL(fd,i*16+12)=i;
  6471. WFIFOL(fd,i*16+16)=p->exp_mode;
  6472. }
  6473. WFIFOW(fd, 2)=i*16+4;
  6474. WFIFOSET(fd,WFIFOW(fd,2));
  6475. return 0;
  6476. }
  6477. /*==========================================
  6478. * ギルド役職変更通知
  6479. *------------------------------------------
  6480. */
  6481. int clif_guild_positionchanged(struct guild *g,int idx)
  6482. {
  6483. struct map_session_data *sd;
  6484. unsigned char buf[128];
  6485. nullpo_retr(0, g);
  6486. WBUFW(buf, 0)=0x174;
  6487. WBUFW(buf, 2)=44;
  6488. WBUFL(buf, 4)=idx;
  6489. WBUFL(buf, 8)=g->position[idx].mode;
  6490. WBUFL(buf,12)=idx;
  6491. WBUFL(buf,16)=g->position[idx].exp_mode;
  6492. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6493. if( (sd=guild_getavailablesd(g))!=NULL )
  6494. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6495. return 0;
  6496. }
  6497. /*==========================================
  6498. * ギルドメンバ変更通知
  6499. *------------------------------------------
  6500. */
  6501. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  6502. {
  6503. struct map_session_data *sd;
  6504. unsigned char buf[64];
  6505. nullpo_retr(0, g);
  6506. WBUFW(buf, 0)=0x156;
  6507. WBUFW(buf, 2)=16;
  6508. WBUFL(buf, 4)=g->member[idx].account_id;
  6509. WBUFL(buf, 8)=g->member[idx].char_id;
  6510. WBUFL(buf,12)=g->member[idx].position;
  6511. if( (sd=guild_getavailablesd(g))!=NULL )
  6512. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6513. return 0;
  6514. }
  6515. /*==========================================
  6516. * ギルドエンブレム送信
  6517. *------------------------------------------
  6518. */
  6519. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6520. {
  6521. int fd;
  6522. nullpo_retr(0, sd);
  6523. nullpo_retr(0, g);
  6524. fd=sd->fd;
  6525. if(g->emblem_len<=0)
  6526. return 0;
  6527. WFIFOHEAD(fd,g->emblem_len+12);
  6528. WFIFOW(fd,0)=0x152;
  6529. WFIFOW(fd,2)=g->emblem_len+12;
  6530. WFIFOL(fd,4)=g->guild_id;
  6531. WFIFOL(fd,8)=g->emblem_id;
  6532. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6533. WFIFOSET(fd,WFIFOW(fd,2));
  6534. return 0;
  6535. }
  6536. /*==========================================
  6537. * ギルドスキル送信
  6538. *------------------------------------------
  6539. */
  6540. int clif_guild_skillinfo(struct map_session_data *sd)
  6541. {
  6542. int fd;
  6543. int i,id,c,up=1;
  6544. struct guild *g;
  6545. nullpo_retr(0, sd);
  6546. fd=sd->fd;
  6547. g=guild_search(sd->status.guild_id);
  6548. if(g==NULL)
  6549. return 0;
  6550. WFIFOHEAD(fd, MAX_GUILDSKILL * 37 + 6);
  6551. WFIFOW(fd,0)=0x0162;
  6552. WFIFOW(fd,4)=g->skill_point;
  6553. for(i=c=0;i<MAX_GUILDSKILL;i++){
  6554. if(g->skill[i].id>0 && guild_check_skill_require(g,g->skill[i].id)){
  6555. WFIFOW(fd,c*37+ 6) = id = g->skill[i].id;
  6556. WFIFOW(fd,c*37+ 8) = guild_skill_get_inf(id);
  6557. WFIFOW(fd,c*37+10) = 0;
  6558. WFIFOW(fd,c*37+12) = g->skill[i].lv;
  6559. WFIFOW(fd,c*37+14) = skill_get_sp(id,g->skill[i].lv);
  6560. WFIFOW(fd,c*37+16) = skill_get_range(id,g->skill[i].lv);
  6561. memset(WFIFOP(fd,c*37+18),0,24);
  6562. if(g->skill[i].lv < guild_skill_get_max(id) && (sd == g->member[0].sd))
  6563. up = 1;
  6564. else
  6565. up = 0;
  6566. WFIFOB(fd,c*37+42)= up;
  6567. c++;
  6568. }
  6569. }
  6570. WFIFOW(fd,2)=c*37+6;
  6571. WFIFOSET(fd,WFIFOW(fd,2));
  6572. return 0;
  6573. }
  6574. /*==========================================
  6575. * ギルド告知送信
  6576. *------------------------------------------
  6577. */
  6578. int clif_guild_notice(struct map_session_data *sd,struct guild *g)
  6579. {
  6580. int fd;
  6581. nullpo_retr(0, sd);
  6582. nullpo_retr(0, g);
  6583. fd = sd->fd;
  6584. if ( !session_isActive(fd) ) //null pointer right here [Kevin]
  6585. return 0;
  6586. if (fd <= 0)
  6587. return 0;
  6588. if(*g->mes1==0 && *g->mes2==0)
  6589. return 0;
  6590. WFIFOHEAD(fd,packet_len_table[0x16f]);
  6591. WFIFOW(fd,0)=0x16f;
  6592. memcpy(WFIFOP(fd,2),g->mes1,60);
  6593. memcpy(WFIFOP(fd,62),g->mes2,120);
  6594. WFIFOSET(fd,packet_len_table[0x16f]);
  6595. return 0;
  6596. }
  6597. /*==========================================
  6598. * ギルドメンバ勧誘
  6599. *------------------------------------------
  6600. */
  6601. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6602. {
  6603. int fd;
  6604. nullpo_retr(0, sd);
  6605. nullpo_retr(0, g);
  6606. fd=sd->fd;
  6607. WFIFOHEAD(fd,packet_len_table[0x16a]);
  6608. WFIFOW(fd,0)=0x16a;
  6609. WFIFOL(fd,2)=g->guild_id;
  6610. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6611. WFIFOSET(fd,packet_len_table[0x16a]);
  6612. return 0;
  6613. }
  6614. /*==========================================
  6615. * ギルドメンバ勧誘結果
  6616. *------------------------------------------
  6617. */
  6618. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  6619. {
  6620. int fd;
  6621. nullpo_retr(0, sd);
  6622. fd=sd->fd;
  6623. WFIFOHEAD(fd,packet_len_table[0x169]);
  6624. WFIFOW(fd,0)=0x169;
  6625. WFIFOB(fd,2)=flag;
  6626. WFIFOSET(fd,packet_len_table[0x169]);
  6627. return 0;
  6628. }
  6629. /*==========================================
  6630. * ギルドメンバ脱退通知
  6631. *------------------------------------------
  6632. */
  6633. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6634. {
  6635. unsigned char buf[128];
  6636. nullpo_retr(0, sd);
  6637. WBUFW(buf, 0)=0x15a;
  6638. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6639. memcpy(WBUFP(buf,26),mes,40);
  6640. clif_send(buf,packet_len_table[0x15a],&sd->bl,GUILD);
  6641. return 0;
  6642. }
  6643. /*==========================================
  6644. * ギルドメンバ追放通知
  6645. *------------------------------------------
  6646. */
  6647. int clif_guild_explusion(struct map_session_data *sd,const char *name,const char *mes,
  6648. int account_id)
  6649. {
  6650. unsigned char buf[128];
  6651. nullpo_retr(0, sd);
  6652. WBUFW(buf, 0)=0x15c;
  6653. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6654. memcpy(WBUFP(buf,26),mes,40);
  6655. memcpy(WBUFP(buf,66),"dummy",NAME_LENGTH);
  6656. clif_send(buf,packet_len_table[0x15c],&sd->bl,GUILD);
  6657. return 0;
  6658. }
  6659. /*==========================================
  6660. * ギルド追放メンバリスト
  6661. *------------------------------------------
  6662. */
  6663. int clif_guild_explusionlist(struct map_session_data *sd)
  6664. {
  6665. int fd;
  6666. int i,c;
  6667. struct guild *g;
  6668. nullpo_retr(0, sd);
  6669. fd=sd->fd;
  6670. g=guild_search(sd->status.guild_id);
  6671. if(g==NULL)
  6672. return 0;
  6673. WFIFOHEAD(fd,MAX_GUILDEXPLUSION * 88 + 4);
  6674. WFIFOW(fd,0)=0x163;
  6675. for(i=c=0;i<MAX_GUILDEXPLUSION;i++){
  6676. struct guild_explusion *e=&g->explusion[i];
  6677. if(e->account_id>0){
  6678. memcpy(WFIFOP(fd,c*88+ 4),e->name,NAME_LENGTH);
  6679. memcpy(WFIFOP(fd,c*88+28),e->acc,24);
  6680. memcpy(WFIFOP(fd,c*88+52),e->mes,44);
  6681. c++;
  6682. }
  6683. }
  6684. WFIFOW(fd,2)=c*88+4;
  6685. WFIFOSET(fd,WFIFOW(fd,2));
  6686. return 0;
  6687. }
  6688. /*==========================================
  6689. * ギルド会話
  6690. *------------------------------------------
  6691. */
  6692. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6693. {
  6694. struct map_session_data *sd;
  6695. unsigned char *buf;
  6696. buf = (unsigned char*)aCallocA(len + 4, sizeof(unsigned char));
  6697. WBUFW(buf, 0) = 0x17f;
  6698. WBUFW(buf, 2) = len + 4;
  6699. memcpy(WBUFP(buf,4), mes, len);
  6700. if ((sd = guild_getavailablesd(g)) != NULL)
  6701. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  6702. if(buf) aFree(buf);
  6703. return 0;
  6704. }
  6705. /*==========================================
  6706. * ギルドスキル割り振り通知
  6707. *------------------------------------------
  6708. */
  6709. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  6710. {
  6711. int fd;
  6712. nullpo_retr(0, sd);
  6713. fd=sd->fd;
  6714. WFIFOHEAD(fd,11);
  6715. WFIFOW(fd,0) = 0x10e;
  6716. WFIFOW(fd,2) = skill_num;
  6717. WFIFOW(fd,4) = lv;
  6718. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  6719. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  6720. WFIFOB(fd,10) = 1;
  6721. WFIFOSET(fd,11);
  6722. return 0;
  6723. }
  6724. /*==========================================
  6725. * ギルド同盟要請
  6726. *------------------------------------------
  6727. */
  6728. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6729. {
  6730. int fd;
  6731. nullpo_retr(0, sd);
  6732. fd=sd->fd;
  6733. WFIFOHEAD(fd,packet_len_table[0x171]);
  6734. WFIFOW(fd,0)=0x171;
  6735. WFIFOL(fd,2)=account_id;
  6736. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6737. WFIFOSET(fd,packet_len_table[0x171]);
  6738. return 0;
  6739. }
  6740. /*==========================================
  6741. * ギルド同盟結果
  6742. *------------------------------------------
  6743. */
  6744. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  6745. {
  6746. int fd;
  6747. nullpo_retr(0, sd);
  6748. fd=sd->fd;
  6749. WFIFOHEAD(fd,packet_len_table[0x173]);
  6750. WFIFOW(fd,0)=0x173;
  6751. WFIFOL(fd,2)=flag;
  6752. WFIFOSET(fd,packet_len_table[0x173]);
  6753. return 0;
  6754. }
  6755. /*==========================================
  6756. * ギルド関係解消通知
  6757. *------------------------------------------
  6758. */
  6759. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6760. {
  6761. int fd;
  6762. nullpo_retr(0, sd);
  6763. fd = sd->fd;
  6764. if (fd <= 0)
  6765. return 0;
  6766. WFIFOHEAD(fd,packet_len_table[0x184]);
  6767. WFIFOW(fd,0)=0x184;
  6768. WFIFOL(fd,2)=guild_id;
  6769. WFIFOL(fd,6)=flag;
  6770. WFIFOSET(fd,packet_len_table[0x184]);
  6771. return 0;
  6772. }
  6773. /*==========================================
  6774. * ギルド敵対結果
  6775. *------------------------------------------
  6776. */
  6777. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6778. {
  6779. int fd;
  6780. nullpo_retr(0, sd);
  6781. fd=sd->fd;
  6782. WFIFOHEAD(fd,packet_len_table[0x181]);
  6783. WFIFOW(fd,0)=0x181;
  6784. WFIFOB(fd,2)=flag;
  6785. WFIFOSET(fd,packet_len_table[0x181]);
  6786. return 0;
  6787. }
  6788. /*==========================================
  6789. * ギルド関係追加
  6790. *------------------------------------------
  6791. */
  6792. /*int clif_guild_allianceadded(struct guild *g,int idx)
  6793. {
  6794. unsigned char buf[64];
  6795. WBUFW(fd,0)=0x185;
  6796. WBUFL(fd,2)=g->alliance[idx].opposition;
  6797. WBUFL(fd,6)=g->alliance[idx].guild_id;
  6798. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  6799. clif_send(buf,packet_len_table[0x185],guild_getavailablesd(g),GUILD);
  6800. return 0;
  6801. }*/
  6802. /*==========================================
  6803. * ギルド解散通知
  6804. *------------------------------------------
  6805. */
  6806. int clif_guild_broken(struct map_session_data *sd,int flag)
  6807. {
  6808. int fd;
  6809. nullpo_retr(0, sd);
  6810. fd=sd->fd;
  6811. WFIFOHEAD(fd,packet_len_table[0x15e]);
  6812. WFIFOW(fd,0)=0x15e;
  6813. WFIFOL(fd,2)=flag;
  6814. WFIFOSET(fd,packet_len_table[0x15e]);
  6815. return 0;
  6816. }
  6817. /*==========================================
  6818. * エモーション
  6819. *------------------------------------------
  6820. */
  6821. void clif_emotion(struct block_list *bl,int type)
  6822. {
  6823. unsigned char buf[8];
  6824. nullpo_retv(bl);
  6825. WBUFW(buf,0)=0xc0;
  6826. WBUFL(buf,2)=bl->id;
  6827. WBUFB(buf,6)=type;
  6828. clif_send(buf,packet_len_table[0xc0],bl,AREA);
  6829. }
  6830. /*==========================================
  6831. * トーキーボックス
  6832. *------------------------------------------
  6833. */
  6834. void clif_talkiebox(struct block_list *bl,char* talkie)
  6835. {
  6836. unsigned char buf[86];
  6837. nullpo_retv(bl);
  6838. WBUFW(buf,0)=0x191;
  6839. WBUFL(buf,2)=bl->id;
  6840. memcpy(WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6841. clif_send(buf,packet_len_table[0x191],bl,AREA);
  6842. }
  6843. /*==========================================
  6844. * 結婚エフェクト
  6845. *------------------------------------------
  6846. */
  6847. void clif_wedding_effect(struct block_list *bl) {
  6848. unsigned char buf[6];
  6849. nullpo_retv(bl);
  6850. WBUFW(buf,0) = 0x1ea;
  6851. WBUFL(buf,2) = bl->id;
  6852. clif_send(buf, packet_len_table[0x1ea], bl, AREA);
  6853. }
  6854. /*==========================================
  6855. * あなたに逢いたい使用時名前叫び
  6856. *------------------------------------------
  6857. void clif_callpartner(struct map_session_data *sd)
  6858. {
  6859. unsigned char buf[26];
  6860. char *p;
  6861. nullpo_retv(sd);
  6862. if(sd->status.partner_id){
  6863. WBUFW(buf,0)=0x1e6;
  6864. p = map_charid2nick(sd->status.partner_id);
  6865. if(p){
  6866. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6867. }else{
  6868. map_reqchariddb(sd,sd->status.partner_id);
  6869. chrif_searchcharid(sd->status.partner_id);
  6870. WBUFB(buf,2) = 0;
  6871. }
  6872. clif_send(buf,packet_len_table[0x1e6],&sd->bl,AREA);
  6873. }
  6874. return;
  6875. }
  6876. */
  6877. /*==========================================
  6878. * Adopt baby [Celest]
  6879. *------------------------------------------
  6880. */
  6881. void clif_adopt_process(struct map_session_data *sd)
  6882. {
  6883. int fd;
  6884. nullpo_retv(sd);
  6885. fd=sd->fd;
  6886. WFIFOHEAD(fd,packet_len_table[0x1f8]);
  6887. WFIFOW(fd,0)=0x1f8;
  6888. WFIFOSET(fd,packet_len_table[0x1f8]);
  6889. }
  6890. /*==========================================
  6891. * Marry [DracoRPG]
  6892. *------------------------------------------
  6893. */
  6894. void clif_marriage_process(struct map_session_data *sd)
  6895. {
  6896. int fd;
  6897. nullpo_retv(sd);
  6898. fd=sd->fd;
  6899. WFIFOHEAD(fd,packet_len_table[0x1e4]);
  6900. WFIFOW(fd,0)=0x1e4;
  6901. WFIFOSET(fd,packet_len_table[0x1e4]);
  6902. }
  6903. /*==========================================
  6904. * Notice of divorce
  6905. *------------------------------------------
  6906. */
  6907. void clif_divorced(struct map_session_data *sd, char *name)
  6908. {
  6909. int fd;
  6910. nullpo_retv(sd);
  6911. fd=sd->fd;
  6912. WFIFOHEAD(fd,packet_len_table[0x205]);
  6913. WFIFOW(fd,0)=0x205;
  6914. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6915. WFIFOSET(fd, packet_len_table[0x205]);
  6916. }
  6917. /*==========================================
  6918. *
  6919. *------------------------------------------
  6920. */
  6921. void clif_parse_ReqAdopt(int fd, struct map_session_data *sd) {
  6922. nullpo_retv(sd);
  6923. WFIFOHEAD(fd,packet_len_table[0x1f6]);
  6924. WFIFOW(fd,0)=0x1f6;
  6925. WFIFOSET(fd, packet_len_table[0x1f6]);
  6926. }
  6927. /*==========================================
  6928. *
  6929. *------------------------------------------
  6930. */
  6931. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd) {
  6932. nullpo_retv(sd);
  6933. WFIFOHEAD(fd,packet_len_table[0x1e2]);
  6934. WFIFOW(fd,0)=0x1e2;
  6935. WFIFOSET(fd, packet_len_table[0x1e2]);
  6936. }
  6937. /*==========================================
  6938. * 座る
  6939. *------------------------------------------
  6940. */
  6941. void clif_sitting(struct map_session_data *sd)
  6942. {
  6943. unsigned char buf[64];
  6944. nullpo_retv(sd);
  6945. WBUFW(buf, 0) = 0x8a;
  6946. WBUFL(buf, 2) = sd->bl.id;
  6947. WBUFB(buf,26) = 2;
  6948. clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
  6949. if(sd->disguise) {
  6950. WBUFL(buf, 2) = -sd->bl.id;
  6951. clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
  6952. }
  6953. }
  6954. /*==========================================
  6955. *
  6956. *------------------------------------------
  6957. */
  6958. int clif_disp_onlyself(struct map_session_data *sd, char *mes, int len)
  6959. {
  6960. unsigned char *buf;
  6961. nullpo_retr(0, sd);
  6962. buf = (unsigned char*)aCallocA(len + 5, sizeof(unsigned char));
  6963. WBUFW(buf, 0) = 0x17f;
  6964. WBUFW(buf, 2) = len + 5;
  6965. memcpy(WBUFP(buf,4), mes, len);
  6966. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6967. if(buf) aFree(buf);
  6968. return 0;
  6969. }
  6970. /*==========================================
  6971. *
  6972. *------------------------------------------
  6973. */
  6974. int clif_GM_kickack(struct map_session_data *sd, int id)
  6975. {
  6976. int fd;
  6977. nullpo_retr(0, sd);
  6978. fd = sd->fd;
  6979. WFIFOHEAD(fd,packet_len_table[0xcd]);
  6980. WFIFOW(fd,0) = 0xcd;
  6981. WFIFOL(fd,2) = id;
  6982. WFIFOSET(fd, packet_len_table[0xcd]);
  6983. return 0;
  6984. }
  6985. void clif_parse_QuitGame(int fd,struct map_session_data *sd);
  6986. int clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd,int type)
  6987. {
  6988. nullpo_retr(0, tsd);
  6989. if(type)
  6990. clif_GM_kickack(sd,tsd->status.account_id);
  6991. WFIFOHEAD(tsd->fd,packet_len_table[0x18b]);
  6992. WFIFOW(tsd->fd,0) = 0x18b;
  6993. WFIFOW(tsd->fd,2) = 0;
  6994. WFIFOSET(tsd->fd,packet_len_table[0x18b]);
  6995. if (tsd->fd)
  6996. {
  6997. ShowDebug("clif_GM_kick: Disconnecting session #%d\n", tsd->fd);
  6998. clif_setwaitclose(tsd->fd);
  6999. } else { //Player has no session attached, delete it right away. [Skotlex]
  7000. map_quit(tsd);
  7001. }
  7002. return 0;
  7003. }
  7004. int clif_GM_silence(struct map_session_data *sd, struct map_session_data *tsd, int type)
  7005. {
  7006. int fd;
  7007. nullpo_retr(0, sd);
  7008. nullpo_retr(0, tsd);
  7009. fd = tsd->fd;
  7010. if (fd <= 0)
  7011. return 0;
  7012. WFIFOHEAD(fd,packet_len_table[0x14b]);
  7013. WFIFOW(fd,0) = 0x14b;
  7014. WFIFOB(fd,2) = 0;
  7015. memcpy(WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  7016. WFIFOSET(fd, packet_len_table[0x14b]);
  7017. return 0;
  7018. }
  7019. /*==========================================
  7020. *
  7021. *------------------------------------------
  7022. */
  7023. int clif_timedout(struct map_session_data *sd)
  7024. {
  7025. nullpo_retr(0, sd);
  7026. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' timed out.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id);
  7027. clif_authfail_fd(sd->fd,3); // Even if player is not on we still send anyway
  7028. clif_setwaitclose(sd->fd); // Set session to EOF
  7029. return 0;
  7030. }
  7031. /*==========================================
  7032. * Wis拒否許可応答
  7033. *------------------------------------------
  7034. */
  7035. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  7036. {
  7037. int fd;
  7038. nullpo_retr(0, sd);
  7039. fd=sd->fd;
  7040. WFIFOHEAD(fd,packet_len_table[0xd1]);
  7041. WFIFOW(fd,0)=0xd1;
  7042. WFIFOB(fd,2)=type;
  7043. WFIFOB(fd,3)=flag;
  7044. WFIFOSET(fd,packet_len_table[0xd1]);
  7045. return 0;
  7046. }
  7047. /*==========================================
  7048. * Wis全拒否許可応答
  7049. *------------------------------------------
  7050. */
  7051. int clif_wisall(struct map_session_data *sd,int type,int flag)
  7052. {
  7053. int fd;
  7054. nullpo_retr(0, sd);
  7055. fd=sd->fd;
  7056. WFIFOHEAD(fd,packet_len_table[0xd2]);
  7057. WFIFOW(fd,0)=0xd2;
  7058. WFIFOB(fd,2)=type;
  7059. WFIFOB(fd,3)=flag;
  7060. WFIFOSET(fd,packet_len_table[0xd2]);
  7061. return 0;
  7062. }
  7063. /*==========================================
  7064. * サウンドエフェクト
  7065. *------------------------------------------
  7066. */
  7067. void clif_soundeffect(struct map_session_data *sd,struct block_list *bl,char *name,int type)
  7068. {
  7069. int fd;
  7070. nullpo_retv(sd);
  7071. nullpo_retv(bl);
  7072. fd=sd->fd;
  7073. WFIFOHEAD(fd,packet_len_table[0x1d3]);
  7074. WFIFOW(fd,0)=0x1d3;
  7075. memcpy(WFIFOP(fd,2),name,NAME_LENGTH);
  7076. WFIFOB(fd,26)=type;
  7077. WFIFOL(fd,27)=0;
  7078. WFIFOL(fd,31)=bl->id;
  7079. WFIFOSET(fd,packet_len_table[0x1d3]);
  7080. return;
  7081. }
  7082. int clif_soundeffectall(struct block_list *bl, char *name, int type)
  7083. {
  7084. unsigned char buf[40];
  7085. memset(buf, 0, packet_len_table[0x1d3]);
  7086. nullpo_retr(0, bl);
  7087. WBUFW(buf,0)=0x1d3;
  7088. memcpy(WBUFP(buf,2), name, NAME_LENGTH);
  7089. WBUFB(buf,26)=type;
  7090. WBUFL(buf,27)=0;
  7091. WBUFL(buf,31)=bl->id;
  7092. clif_send(buf, packet_len_table[0x1d3], bl, AREA);
  7093. return 0;
  7094. }
  7095. // displaying special effects (npcs, weather, etc) [Valaris]
  7096. int clif_specialeffect(struct block_list *bl, int type, int flag)
  7097. {
  7098. unsigned char buf[24];
  7099. nullpo_retr(0, bl);
  7100. memset(buf, 0, packet_len_table[0x1f3]);
  7101. WBUFW(buf,0) = 0x1f3;
  7102. if(bl->type==BL_PC && ((struct map_session_data *)bl)->disguise)
  7103. WBUFL(buf,2) = -bl->id;
  7104. else
  7105. WBUFL(buf,2) = bl->id;
  7106. WBUFL(buf,6) = type;
  7107. switch (flag) {
  7108. case 4:
  7109. clif_send(buf, packet_len_table[0x1f3], bl, AREA_WOS);
  7110. break;
  7111. case 3:
  7112. clif_send(buf, packet_len_table[0x1f3], bl, ALL_CLIENT);
  7113. break;
  7114. case 2:
  7115. clif_send(buf, packet_len_table[0x1f3], bl, ALL_SAMEMAP);
  7116. break;
  7117. case 1:
  7118. clif_send(buf, packet_len_table[0x1f3], bl, SELF);
  7119. break;
  7120. default:
  7121. clif_send(buf, packet_len_table[0x1f3], bl, AREA);
  7122. }
  7123. return 0;
  7124. }
  7125. // refresh the client's screen, getting rid of any effects
  7126. int clif_refresh(struct map_session_data *sd) {
  7127. nullpo_retr(-1, sd);
  7128. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  7129. map_foreachinarea(clif_getareachar,sd->bl.m,sd->bl.x-AREA_SIZE,sd->bl.y-AREA_SIZE,sd->bl.x+AREA_SIZE,sd->bl.y+AREA_SIZE,BL_ALL,sd);
  7130. return 0;
  7131. }
  7132. // updates the object's (bl) name on client
  7133. int clif_charnameack (int fd, struct block_list *bl)
  7134. {
  7135. unsigned char buf[103];
  7136. int cmd = 0x95;
  7137. nullpo_retr(0, bl);
  7138. WBUFW(buf,0) = cmd;
  7139. if(bl->type==BL_PC && ((struct map_session_data *)bl)->disguise)
  7140. WBUFL(buf,2) = -bl->id;
  7141. else
  7142. WBUFL(buf,2) = bl->id;
  7143. switch(bl->type) {
  7144. case BL_PC:
  7145. {
  7146. struct map_session_data *ssd = (struct map_session_data *)bl;
  7147. struct party *p = NULL;
  7148. struct guild *g = NULL;
  7149. nullpo_retr(0, ssd);
  7150. if (strlen(ssd->fakename)>1) {
  7151. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  7152. break;
  7153. }
  7154. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7155. if (ssd->status.party_id > 0)
  7156. p = party_search(ssd->status.party_id);
  7157. if (ssd->status.guild_id > 0)
  7158. g = guild_search(ssd->status.guild_id);
  7159. if (p == NULL && g == NULL)
  7160. break;
  7161. WBUFW(buf, 0) = cmd = 0x195;
  7162. if (p)
  7163. memcpy(WBUFP(buf,30), p->name, NAME_LENGTH);
  7164. else
  7165. WBUFB(buf,30) = 0;
  7166. if (g)
  7167. {
  7168. int i, ps = -1;
  7169. for(i = 0; i < g->max_member; i++) {
  7170. if (g->member[i].account_id == ssd->status.account_id &&
  7171. g->member[i].char_id == ssd->status.char_id )
  7172. {
  7173. ps = g->member[i].position;
  7174. break;
  7175. }
  7176. }
  7177. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  7178. {
  7179. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7180. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7181. } else { //Assume no guild.
  7182. WBUFB(buf,54) = 0;
  7183. WBUFB(buf,78) = 0;
  7184. }
  7185. } else {
  7186. WBUFB(buf,54) = 0;
  7187. WBUFB(buf,78) = 0;
  7188. }
  7189. }
  7190. break;
  7191. case BL_PET:
  7192. memcpy(WBUFP(buf,6), ((struct pet_data*)bl)->name, NAME_LENGTH);
  7193. break;
  7194. case BL_NPC:
  7195. memcpy(WBUFP(buf,6), ((struct npc_data*)bl)->name, NAME_LENGTH);
  7196. break;
  7197. case BL_MOB:
  7198. {
  7199. struct mob_data *md = (struct mob_data *)bl;
  7200. nullpo_retr(0, md);
  7201. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  7202. if (md->guardian_data && md->guardian_data->guild_id) {
  7203. WBUFW(buf, 0) = cmd = 0x195;
  7204. WBUFB(buf,30) = 0;
  7205. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  7206. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  7207. } else if (battle_config.show_mob_hp == 1) {
  7208. char mobhp[50];
  7209. WBUFW(buf, 0) = cmd = 0x195;
  7210. sprintf(mobhp, "HP: %d/%d", md->hp, md->max_hp);
  7211. //Even thought mobhp ain't a name, we send it as one so the client
  7212. //can parse it. [Skotlex]
  7213. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  7214. WBUFB(buf,54) = 0;
  7215. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  7216. }
  7217. }
  7218. break;
  7219. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  7220. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  7221. // break;
  7222. return 0;
  7223. default:
  7224. if (battle_config.error_log)
  7225. ShowError("clif_parse_GetCharNameRequest : bad type %d(%d)\n", bl->type, bl->id);
  7226. return 0;
  7227. }
  7228. // if no receipient specified just update nearby clients
  7229. if (fd == 0)
  7230. clif_send(buf, packet_len_table[cmd], bl, AREA);
  7231. else {
  7232. WFIFOHEAD(fd, packet_len_table[cmd]);
  7233. memcpy(WFIFOP(fd, 0), buf, packet_len_table[cmd]);
  7234. WFIFOSET(fd, packet_len_table[cmd]);
  7235. }
  7236. return 0;
  7237. }
  7238. //Used to update when a char leaves a party/guild. [Skotlex]
  7239. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  7240. int clif_charnameupdate (struct map_session_data *ssd)
  7241. {
  7242. unsigned char buf[103];
  7243. int cmd = 0x195;
  7244. struct party *p = NULL;
  7245. struct guild *g = NULL;
  7246. nullpo_retr(0, ssd);
  7247. if (strlen(ssd->fakename)>1)
  7248. return 0; //No need to update as the party/guild was not displayed anyway.
  7249. WBUFW(buf,0) = cmd;
  7250. if(ssd->disguise)
  7251. WBUFL(buf,2) = -(ssd->bl.id);
  7252. else
  7253. WBUFL(buf,2) = ssd->bl.id;
  7254. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  7255. if (ssd->status.party_id > 0)
  7256. p = party_search(ssd->status.party_id);
  7257. if (ssd->status.guild_id > 0)
  7258. g = guild_search(ssd->status.guild_id);
  7259. if (p)
  7260. memcpy(WBUFP(buf,30), p->name, NAME_LENGTH);
  7261. else
  7262. WBUFB(buf,30) = 0;
  7263. if (g)
  7264. {
  7265. int i, ps = -1;
  7266. for(i = 0; i < g->max_member; i++) {
  7267. if (g->member[i].account_id == ssd->status.account_id &&
  7268. g->member[i].char_id == ssd->status.char_id )
  7269. {
  7270. ps = g->member[i].position;
  7271. break;
  7272. }
  7273. }
  7274. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  7275. {
  7276. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  7277. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  7278. } else { //Assume no guild.
  7279. WBUFB(buf,54) = 0;
  7280. WBUFB(buf,78) = 0;
  7281. }
  7282. } else {
  7283. WBUFB(buf,54) = 0;
  7284. WBUFB(buf,78) = 0;
  7285. }
  7286. // Update nearby clients
  7287. clif_send(buf, packet_len_table[cmd], &ssd->bl, AREA);
  7288. return 0;
  7289. }
  7290. int clif_slide(struct block_list *bl, int x, int y){
  7291. unsigned char buf[10];
  7292. nullpo_retr(0, bl);
  7293. WBUFW(buf, 0) = 0x01ff;
  7294. WBUFL(buf, 2) = bl->id;
  7295. WBUFW(buf, 6) = x;
  7296. WBUFW(buf, 8) = y;
  7297. clif_send(buf, packet_len_table[0x1ff], bl, AREA);
  7298. return 0;
  7299. }
  7300. /*------------------------------------------
  7301. * @me command by lordalfa, rewritten implementation by Skotlex
  7302. *------------------------------------------
  7303. */
  7304. int clif_disp_overhead(struct map_session_data *sd, char* mes)
  7305. {
  7306. unsigned char buf[256]; //This should be more than sufficient, the theorical max is MESSAGE_SIZE+NAME_LENGTH + 8 (pads and extra inserted crap)
  7307. int len_mes = strlen(mes)+1; //Account for \0
  7308. if (len_mes + 8 >= 256) {
  7309. if (battle_config.error_log)
  7310. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  7311. len_mes = 247; //Trunk it to avoid problems.
  7312. }
  7313. // send message to others
  7314. WBUFW(buf,0) = 0x8d;
  7315. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  7316. WBUFL(buf,4) = sd->bl.id;
  7317. memcpy(WBUFP(buf,8), mes, len_mes);
  7318. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  7319. // send back message to the speaker
  7320. WBUFW(buf,0) = 0x8e;
  7321. WBUFW(buf, 2) = len_mes + 4;
  7322. memcpy(WBUFP(buf,4), mes, len_mes);
  7323. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  7324. return 0;
  7325. }
  7326. /*==========================
  7327. * Minimap fix [Kevin]
  7328. * Remove dot from minimap
  7329. *--------------------------
  7330. */
  7331. int clif_party_xy_remove(struct map_session_data *sd)
  7332. {
  7333. unsigned char buf[16];
  7334. nullpo_retr(0, sd);
  7335. WBUFW(buf,0)=0x107;
  7336. WBUFL(buf,2)=sd->status.account_id;
  7337. WBUFW(buf,6)=-1;
  7338. WBUFW(buf,8)=-1;
  7339. clif_send(buf,packet_len_table[0x107],&sd->bl,PARTY_SAMEMAP_WOS);
  7340. return 0;
  7341. }
  7342. /*==========================================
  7343. * Info about Star Glaldiator save map [Komurka]
  7344. *------------------------------------------
  7345. */
  7346. void clif_feel_info(struct map_session_data *sd, int feel_level)
  7347. {
  7348. int fd=sd->fd;
  7349. WFIFOHEAD(fd,packet_len_table[0x20e]);
  7350. WFIFOW(fd,0)=0x20e;
  7351. memcpy(WFIFOP(fd,2),mapindex_id2name(sd->feel_map[feel_level].index), MAP_NAME_LENGTH);
  7352. WFIFOL(fd,26)=sd->bl.id;
  7353. WFIFOW(fd,30)=0x100+feel_level;
  7354. WFIFOSET(fd, packet_len_table[0x20e]);
  7355. }
  7356. /*==========================================
  7357. * Info about Star Glaldiator hate mob [Komurka]
  7358. *------------------------------------------
  7359. */
  7360. void clif_hate_mob(struct map_session_data *sd, int skilllv,int mob_id)
  7361. {
  7362. int fd=sd->fd;
  7363. WFIFOHEAD(fd,packet_len_table[0x20e]);
  7364. WFIFOW(fd,0)=0x20e;
  7365. if (pcdb_checkid(mob_id))
  7366. strncpy(WFIFOP(fd,2),job_name(mob_id), NAME_LENGTH);
  7367. else if (mobdb_checkid(mob_id))
  7368. strncpy(WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  7369. else //Really shouldn't happen...
  7370. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  7371. WFIFOL(fd,26)=sd->bl.id;
  7372. WFIFOW(fd,30)=0xa00+skilllv-1;
  7373. WFIFOSET(fd, packet_len_table[0x20e]);
  7374. }
  7375. /*==========================================
  7376. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  7377. *------------------------------------------
  7378. */
  7379. void clif_mission_mob(struct map_session_data *sd, unsigned short mob_id, unsigned short progress)
  7380. {
  7381. int fd=sd->fd;
  7382. WFIFOHEAD(fd,packet_len_table[0x20e]);
  7383. WFIFOW(fd,0)=0x20e;
  7384. strncpy(WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  7385. WFIFOL(fd,26)=mob_id;
  7386. WFIFOW(fd,30)=0x1400+progress; //Message to display
  7387. WFIFOSET(fd, packet_len_table[0x20e]);
  7388. }
  7389. // ---------------------
  7390. // clif_guess_PacketVer
  7391. // ---------------------
  7392. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  7393. static int clif_guess_PacketVer(int fd, int get_previous)
  7394. {
  7395. static int packet_ver = -1;
  7396. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  7397. RFIFOHEAD(fd);
  7398. if (get_previous) //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]
  7399. return packet_ver;
  7400. //By default, start searching on the default one.
  7401. packet_ver = clif_config.packet_db_ver;
  7402. cmd = RFIFOW(fd,0);
  7403. packet_len = RFIFOREST(fd);
  7404. if (
  7405. cmd == clif_config.connect_cmd[packet_ver] &&
  7406. packet_len == packet_db[packet_ver][cmd].len &&
  7407. ((value = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) == 0 || value == 1) &&
  7408. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) > 700000 && //Account ID is valid
  7409. value <= max_account_id &&
  7410. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) > 0 && //Char ID is valid
  7411. value <= max_char_id &&
  7412. (int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) > 0 //Login 1 is a positive value (?)
  7413. )
  7414. return clif_config.packet_db_ver; //Default packet version found.
  7415. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  7416. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  7417. if (cmd != clif_config.connect_cmd[packet_ver] || //it is not a wanttoconnection for this version.
  7418. packet_len != packet_db[packet_ver][cmd].len) //The size of the wantoconnection packet does not matches.
  7419. continue;
  7420. if (
  7421. (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < 700000 || value > max_account_id
  7422. || (value = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) < 1 || value > max_char_id
  7423. //What is login 1? In my tests it is a very very high value.
  7424. || (int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) < 1
  7425. //This check seems redundant, all wanttoconnection packets have the gender on the very
  7426. //last byte of the packet.
  7427. || (value = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) < 0 || value > 1
  7428. )
  7429. continue;
  7430. return packet_ver; //This is our best guess.
  7431. }
  7432. packet_ver = -1;
  7433. return -1;
  7434. }
  7435. // ------------
  7436. // clif_parse_*
  7437. // ------------
  7438. // パケット読み取って色々操作
  7439. /*==========================================
  7440. *
  7441. *------------------------------------------
  7442. */
  7443. void clif_parse_WantToConnection(int fd, struct map_session_data *sd)
  7444. {
  7445. struct map_session_data *old_sd;
  7446. int cmd, account_id, char_id, login_id1, sex;
  7447. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  7448. 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])
  7449. RFIFOHEAD(fd);
  7450. if (sd) {
  7451. if (battle_config.error_log)
  7452. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)?\n");
  7453. return;
  7454. }
  7455. packet_ver = clif_guess_PacketVer(fd, 1);
  7456. cmd = RFIFOW(fd,0);
  7457. if (packet_ver > 0)
  7458. {
  7459. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7460. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7461. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7462. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7463. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7464. if ((old_sd = map_id2sd(account_id)) != NULL)
  7465. { // if same account already connected, we disconnect the 2 sessions
  7466. //Check for characters with no connection (includes those that are using autotrade) [durf],[Skotlex]
  7467. if (!old_sd->fd)
  7468. map_quit(old_sd);
  7469. else
  7470. clif_authfail_fd(old_sd->fd, 2); // same id
  7471. clif_authfail_fd(fd, 8); // still recognizes last connection
  7472. } else {
  7473. sd = (struct map_session_data*)aCalloc(1, sizeof(struct map_session_data));
  7474. sd->fd = fd;
  7475. sd->packet_ver = packet_ver;
  7476. session[fd]->session_data = sd;
  7477. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7478. WFIFOHEAD(fd,4);
  7479. WFIFOL(fd,0) = sd->bl.id;
  7480. WFIFOSET(fd,4);
  7481. chrif_authreq(sd);
  7482. }
  7483. }
  7484. return;
  7485. }
  7486. /*==========================================
  7487. * 007d クライアント側マップ読み込み完了
  7488. * map侵入時に必要なデータを全て送りつける
  7489. *------------------------------------------
  7490. */
  7491. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7492. {
  7493. if(sd->bl.prev != NULL)
  7494. return;
  7495. if(sd->npc_id) npc_event_dequeue(sd);
  7496. clif_skillinfoblock(sd);
  7497. pc_checkitem(sd);
  7498. // loadendack時
  7499. // next exp
  7500. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7501. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7502. // skill point
  7503. clif_updatestatus(sd,SP_SKILLPOINT);
  7504. // item
  7505. clif_itemlist(sd);
  7506. clif_equiplist(sd);
  7507. // cart
  7508. if(pc_iscarton(sd)){
  7509. clif_cart_itemlist(sd);
  7510. clif_cart_equiplist(sd);
  7511. clif_updatestatus(sd,SP_CARTINFO);
  7512. }
  7513. // param all
  7514. clif_initialstatus(sd);
  7515. // party
  7516. party_send_movemap(sd);
  7517. // guild
  7518. guild_send_memberinfoshort(sd,1);
  7519. if(battle_config.pc_invincible_time > 0) {
  7520. if(map_flag_gvg(sd->bl.m))
  7521. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7522. else
  7523. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7524. }
  7525. map_addblock(&sd->bl); // ブロック登録
  7526. clif_spawnpc(sd); // spawn
  7527. // weight max , now
  7528. clif_updatestatus(sd,SP_MAXWEIGHT);
  7529. clif_updatestatus(sd,SP_WEIGHT);
  7530. // Show hp after displacement [LuzZza]
  7531. if(sd->status.party_id)
  7532. clif_party_hp(sd);
  7533. // set flag, if it's a duel [LuzZza]
  7534. if(sd->duel_group) {
  7535. clif_set0199(fd, 1);
  7536. //clif_misceffect2(&sd->bl, 159);
  7537. }
  7538. // pvp
  7539. //if(sd->pvp_timer!=-1 && !battle_config.pk_mode) /PVP Client crash fix* Removed timer deletion
  7540. // delete_timer(sd->pvp_timer,pc_calc_pvprank_timer);
  7541. if(map[sd->bl.m].flag.pvp){
  7542. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7543. if (sd->pvp_timer == -1)
  7544. sd->pvp_timer=add_timer(gettick()+200,pc_calc_pvprank_timer,sd->bl.id,0);
  7545. sd->pvp_rank=0;
  7546. sd->pvp_lastusers=0;
  7547. sd->pvp_point=5;
  7548. sd->pvp_won=0;
  7549. sd->pvp_lost=0;
  7550. }
  7551. clif_set0199(sd->fd,1);
  7552. } else {
  7553. sd->pvp_timer=-1;
  7554. }
  7555. if(map_flag_gvg(sd->bl.m))
  7556. clif_set0199(sd->fd,3);
  7557. // pet
  7558. if(sd->status.pet_id > 0 && sd->pd && sd->pet.intimate > 0) {
  7559. map_addblock(&sd->pd->bl);
  7560. clif_spawnpet(sd->pd);
  7561. clif_send_petdata(sd,0,0);
  7562. clif_send_petdata(sd,5,battle_config.pet_hair_style);
  7563. clif_send_petstatus(sd);
  7564. }
  7565. if(sd->state.connect_new) {
  7566. sd->state.connect_new = 0;
  7567. if(sd->status.class_ != sd->view_class)
  7568. clif_changelook(&sd->bl,LOOK_BASE,sd->view_class);
  7569. if(sd->status.pet_id > 0 && sd->pd && sd->pet.intimate > 900)
  7570. clif_pet_emotion(sd->pd,(sd->pd->class_ - 100)*100 + 50 + pet_hungry_val(sd));
  7571. /* Stop players from spawning inside castles [Valaris] */
  7572. {
  7573. struct guild_castle *gc=guild_mapname2gc(map[sd->bl.m].name);
  7574. if (gc)
  7575. pc_setpos(sd,sd->status.save_point.map,sd->status.save_point.x,sd->status.save_point.y,2);
  7576. }
  7577. /* End Addition [Valaris] */
  7578. }
  7579. // view equipment item
  7580. #if PACKETVER < 4
  7581. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7582. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7583. #else
  7584. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7585. #endif
  7586. if(battle_config.save_clothcolor && sd->status.clothes_color > 0 && ((sd->view_class != JOB_WEDDING && sd->view_class !=JOB_XMAS) ||
  7587. (sd->view_class==JOB_WEDDING && !battle_config.wedding_ignorepalette) || (sd->view_class==JOB_XMAS && !battle_config.xmas_ignorepalette)))
  7588. clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->status.clothes_color);
  7589. if(battle_config.muting_players && sd->status.manner < 0 && battle_config.manner_system)
  7590. status_change_start(&sd->bl,SC_NOCHAT,100,0,0,0,0,0,0);
  7591. // Lance
  7592. if (script_config.event_script_type == 0) {
  7593. struct npc_data *npc;
  7594. if ((npc = npc_name2id(script_config.loadmap_event_name))) {
  7595. run_script(npc->u.scr.script,0,sd->bl.id,npc->bl.id);
  7596. ShowStatus("Event '"CL_WHITE"%s"CL_RESET"' executed.\n", script_config.loadmap_event_name);
  7597. }
  7598. } else {
  7599. ShowStatus("%d '"CL_WHITE"%s"CL_RESET"' events executed.\n",
  7600. npc_event_doall_id(script_config.loadmap_event_name, sd->bl.id), script_config.loadmap_event_name);
  7601. }
  7602. /* These should not be needed anymore. [Skotlex]
  7603. * - the option is sent on every player packet, why send it?
  7604. * - There should be no need to do a signum check on map change, it is done on equipment change.
  7605. * - Trick-dead is finished on pc_setpos
  7606. * - Night effect is handled on clif_spawnpc
  7607. // option
  7608. clif_changeoption(&sd->bl);
  7609. if(sd->sc_data[SC_TRICKDEAD].timer != -1)
  7610. status_change_end(&sd->bl,SC_TRICKDEAD,-1);
  7611. if(sd->sc_data[SC_SIGNUMCRUCIS].timer != -1 && !battle_check_undead(7,sd->def_ele))
  7612. status_change_end(&sd->bl,SC_SIGNUMCRUCIS,-1);
  7613. if(sd->special_state.infinite_endure && sd->sc_data[SC_ENDURE].timer == -1)
  7614. status_change_start(&sd->bl,SC_ENDURE,100,10,1,0,0,0,0);
  7615. // Required to eliminate glow bugs because it's executed before clif_changeoption [Lance]
  7616. //New 'night' effect by dynamix [Skotlex]
  7617. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7618. { //Display night.
  7619. if (sd->state.night) //It must be resent because otherwise players get this annoying aura...
  7620. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7621. else
  7622. sd->state.night = 1;
  7623. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7624. } else if (sd->state.night) { //Clear night display.
  7625. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7626. sd->state.night = 0;
  7627. }
  7628. */
  7629. if (pc_checkskill(sd,SG_KNOWLEDGE) ||
  7630. pc_checkskill(sd,SG_SUN_COMFORT) ||
  7631. pc_checkskill(sd,SG_MOON_COMFORT) ||
  7632. pc_checkskill(sd,SG_STAR_COMFORT))
  7633. status_calc_pc(sd,0);
  7634. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7635. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7636. map_foreachinarea(clif_getareachar,sd->bl.m,sd->bl.x-AREA_SIZE,sd->bl.y-AREA_SIZE,sd->bl.x+AREA_SIZE,sd->bl.y+AREA_SIZE,BL_ALL,sd);
  7637. }
  7638. /*==========================================
  7639. *
  7640. *------------------------------------------
  7641. */
  7642. void clif_parse_TickSend(int fd, struct map_session_data *sd) {
  7643. RFIFOHEAD(fd);
  7644. sd->client_tick=RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7645. sd->server_tick = gettick();
  7646. clif_servertick(sd);
  7647. }
  7648. /*==========================================
  7649. *
  7650. *------------------------------------------
  7651. */
  7652. void clif_parse_WalkToXY(int fd, struct map_session_data *sd) {
  7653. int x, y;
  7654. int cmd;
  7655. RFIFOHEAD(fd);
  7656. if (pc_isdead(sd)) {
  7657. clif_clearchar_area(&sd->bl, 1);
  7658. return;
  7659. }
  7660. if (pc_issit(sd)) //No walking when you are sit!
  7661. return;
  7662. if (sd->npc_id != 0 || sd->vender_id != 0 || sd->state.storage_flag)
  7663. return;
  7664. if (sd->skilltimer != -1 && pc_checkskill(sd, SA_FREECAST) <= 0) // フリーキャスト
  7665. return;
  7666. if (sd->chatID)
  7667. return;
  7668. if (!pc_can_move(sd))
  7669. return;
  7670. if(sd->sc.count && sd->sc.data[SC_RUN].timer != -1)
  7671. return;
  7672. if (sd->invincible_timer != -1)
  7673. pc_delinvincibletimer(sd);
  7674. pc_stopattack(sd);
  7675. cmd = RFIFOW(fd,0);
  7676. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7677. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7678. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7679. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7680. //Set last idle time... [Skotlex]
  7681. sd->idletime = last_tick;
  7682. pc_walktoxy(sd, x, y);
  7683. }
  7684. /*==========================================
  7685. *
  7686. *------------------------------------------
  7687. */
  7688. void clif_parse_QuitGame(int fd, struct map_session_data *sd) {
  7689. // unsigned int tick=gettick();
  7690. // struct skill_unit_group* sg;
  7691. WFIFOHEAD(fd,packet_len_table[0x18b]);
  7692. WFIFOW(fd,0) = 0x18b;
  7693. /* Rovert's prevent logout option fixed [Valaris] */
  7694. if (sd->sc.data[SC_CLOAKING].timer==-1 && sd->sc.data[SC_HIDING].timer==-1 &&
  7695. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7696. ) {
  7697. clif_setwaitclose(fd);
  7698. WFIFOW(fd,2)=0;
  7699. } else {
  7700. WFIFOW(fd,2)=1;
  7701. }
  7702. WFIFOSET(fd,packet_len_table[0x18b]);
  7703. }
  7704. /*==========================================
  7705. *
  7706. *------------------------------------------
  7707. */
  7708. void check_fake_id(int fd, struct map_session_data *sd, int target_id) {
  7709. // if player asks for the fake player (only bot and modified client can see a hiden player)
  7710. /* if (target_id == server_char_id) {
  7711. char message_to_gm[strlen(msg_txt(536)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7712. 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).
  7713. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7714. // if we block people
  7715. if (battle_config.ban_bot < 0) {
  7716. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7717. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7718. // message about the ban
  7719. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7720. // if we ban people
  7721. } else if (battle_config.ban_bot > 0) {
  7722. 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)
  7723. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7724. // message about the ban
  7725. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7726. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7727. // message about the ban
  7728. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7729. }
  7730. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7731. // send this info cause the bot ask until get an answer, damn spam
  7732. memset(WPACKETP(0), 0, packet_len_table[0x95]);
  7733. WPACKETW(0) = 0x95;
  7734. WPACKETL(2) = server_char_id;
  7735. strncpy(WPACKETP(6), sd->status.name, 24);
  7736. SENDPACKET(fd, packet_len_table[0x95]);
  7737. // take fake player out of screen
  7738. WPACKETW(0) = 0x80;
  7739. WPACKETL(2) = server_char_id;
  7740. WPACKETB(6) = 0;
  7741. SENDPACKET(fd, packet_len_table[0x80]);
  7742. // take fake mob out of screen
  7743. WPACKETW(0) = 0x80;
  7744. WPACKETL(2) = server_fake_mob_id;
  7745. WPACKETB(6) = 0;
  7746. SENDPACKET(fd, packet_len_table[0x80]);
  7747. }
  7748. // if player asks for the fake mob (only bot and modified client can see a hiden mob)
  7749. if (target_id == server_fake_mob_id) {
  7750. int fake_mob;
  7751. char message_to_gm[strlen(msg_txt(537)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7752. 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).
  7753. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7754. // if we block people
  7755. if (battle_config.ban_bot < 0) {
  7756. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7757. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7758. // message about the ban
  7759. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7760. // if we ban people
  7761. } else if (battle_config.ban_bot > 0) {
  7762. 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)
  7763. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7764. // message about the ban
  7765. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7766. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7767. // message about the ban
  7768. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7769. }
  7770. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7771. // send this info cause the bot ask until get an answer, damn spam
  7772. memset(WPACKETP(0), 0, packet_len_table[0x95]);
  7773. WPACKETW(0) = 0x95;
  7774. WPACKETL(2) = server_fake_mob_id;
  7775. 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
  7776. if (!mobdb_checkid(fake_mob))
  7777. fake_mob = 1002; // poring (default)
  7778. strncpy(WPACKETP(6), mob_db[fake_mob].name, 24);
  7779. SENDPACKET(fd, packet_len_table[0x95]);
  7780. // take fake mob out of screen
  7781. WPACKETW(0) = 0x80;
  7782. WPACKETL(2) = server_fake_mob_id;
  7783. WPACKETB(6) = 0;
  7784. SENDPACKET(fd, packet_len_table[0x80]);
  7785. // take fake player out of screen
  7786. WPACKETW(0) = 0x80;
  7787. WPACKETL(2) = server_char_id;
  7788. WPACKETB(6) = 0;
  7789. SENDPACKET(fd, packet_len_table[0x80]);
  7790. }
  7791. */
  7792. return;
  7793. }
  7794. /*==========================================
  7795. *
  7796. *------------------------------------------
  7797. */
  7798. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) {
  7799. int account_id;
  7800. struct block_list* bl;
  7801. RFIFOHEAD(fd);
  7802. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7803. if(account_id<0) // for disguises [Valaris]
  7804. account_id-=account_id*2;
  7805. //Is this possible? Lagged clients could request names of already gone mobs/players. [Skotlex]
  7806. if ((bl = map_id2bl(account_id)) != NULL)
  7807. clif_charnameack(fd, bl);
  7808. }
  7809. /*==========================================
  7810. *
  7811. *------------------------------------------
  7812. */
  7813. void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) { // S 008c <len>.w <str>.?B
  7814. char *message;
  7815. unsigned char *buf;
  7816. RFIFOHEAD(fd);
  7817. message = (char*)RFIFOP(fd,4);
  7818. if (strlen(message) < strlen(sd->status.name) || //If the incoming string is too short...
  7819. strncmp(message, sd->status.name, strlen(sd->status.name)) != 0) //Or the name does not matches...
  7820. {
  7821. ShowWarning("Hack on global message: character '%s' (account: %d), use an other name to send a (normal) message.\n", sd->status.name, sd->status.account_id);
  7822. message = (char*)aCallocA(256, sizeof(char));
  7823. // information is sended to all online GM
  7824. sprintf(message, "Hack on global message (normal message): character '%s' (account: %d) uses another name.", sd->status.name, sd->status.account_id);
  7825. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message);
  7826. if (strlen((char*)RFIFOP(fd,4)) == 0)
  7827. strcpy(message, " This player sends a void name and a void message.");
  7828. else
  7829. snprintf(message, 255, " This player sends (name:message): '%128s'.", RFIFOP(fd,4));
  7830. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message);
  7831. // message about the ban
  7832. if (battle_config.ban_spoof_namer > 0)
  7833. sprintf(message, " This player has been banned for %d minute(s).", battle_config.ban_spoof_namer);
  7834. else
  7835. sprintf(message, " This player hasn't been banned (Ban option is disabled).");
  7836. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message);
  7837. // if we ban people
  7838. if (battle_config.ban_spoof_namer > 0) {
  7839. chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, 0, battle_config.ban_spoof_namer, 0); // type: 2 - ban (year, month, day, hour, minute, second)
  7840. clif_setwaitclose(fd); // forced to disconnect because of the hack
  7841. }
  7842. else
  7843. session[fd]->eof = 1; //Disconnect them too, bad packets can cause problems down the road. [Skotlex]
  7844. if(message) aFree(message);
  7845. return;
  7846. }
  7847. if ((is_atcommand(fd, sd, message, 0) != AtCommand_None) ||
  7848. (is_charcommand(fd, sd, message,0) != CharCommand_None))
  7849. return;
  7850. if (sd->sc.count &&
  7851. (sd->sc.data[SC_BERSERK].timer != -1 || sd->sc.data[SC_NOCHAT].timer != -1 ))
  7852. return;
  7853. buf = (unsigned char*)aCallocA(RFIFOW(fd,2) + 4, sizeof(char));
  7854. // send message to others
  7855. WBUFW(buf,0) = 0x8d;
  7856. WBUFW(buf,2) = RFIFOW(fd,2) + 4; // len of message - 4 + 8
  7857. WBUFL(buf,4) = sd->bl.id;
  7858. memcpy(WBUFP(buf,8), RFIFOP(fd,4), RFIFOW(fd,2) - 4);
  7859. clif_send(buf, WBUFW(buf,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7860. // send back message to the speaker
  7861. WFIFOHEAD(fd, RFIFOW(fd,2) + 4);
  7862. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7863. WFIFOW(fd,0) = 0x8e;
  7864. WFIFOSET(fd, WFIFOW(fd,2));
  7865. #ifdef PCRE_SUPPORT
  7866. map_foreachinarea(npc_chat_sub, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_NPC, RFIFOP(fd,4), strlen(RFIFOP(fd,4)), &sd->bl);
  7867. #endif
  7868. // Celest
  7869. if ((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE) { //Super Novice.
  7870. int next = pc_nextbaseexp(sd);
  7871. char *rfifo = (char*)RFIFOP(fd,4);
  7872. if (next > 0 && (sd->status.base_exp * 1000 / next)% 100 == 0) {
  7873. if (sd->state.snovice_flag == 0 && strstr(rfifo, msg_txt(504)))
  7874. sd->state.snovice_flag = 1;
  7875. else if (sd->state.snovice_flag == 1) {
  7876. message = (char*)aCallocA(128, sizeof(char));
  7877. sprintf(message, msg_txt(505), sd->status.name);
  7878. if (strstr(rfifo, message))
  7879. sd->state.snovice_flag = 2;
  7880. aFree(message);
  7881. }
  7882. else if (sd->state.snovice_flag == 2 && strstr(rfifo, msg_txt(506)))
  7883. sd->state.snovice_flag = 3;
  7884. else if (sd->state.snovice_flag == 3) {
  7885. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,1);
  7886. status_change_start(&sd->bl,SkillStatusChangeTable[MO_EXPLOSIONSPIRITS],100,
  7887. 17,0,0,0,skill_get_time(MO_EXPLOSIONSPIRITS,1),0 ); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7888. sd->state.snovice_flag = 0;
  7889. }
  7890. }
  7891. }
  7892. if(buf) aFree(buf);
  7893. return;
  7894. }
  7895. int clif_message(struct block_list *bl, char* msg)
  7896. {
  7897. unsigned short msg_len = strlen(msg) + 1;
  7898. unsigned char buf[256];
  7899. nullpo_retr(0, bl);
  7900. WBUFW(buf, 0) = 0x8d;
  7901. WBUFW(buf, 2) = msg_len + 8;
  7902. WBUFL(buf, 4) = bl->id;
  7903. memcpy(WBUFP(buf, 8), msg, msg_len);
  7904. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC); // by Gengar
  7905. return 0;
  7906. }
  7907. /*==========================================
  7908. *
  7909. *------------------------------------------
  7910. */
  7911. void clif_parse_MapMove(int fd, struct map_session_data *sd) {
  7912. // /m /mapmove (as @rura GM command)
  7913. char output[30]; // 17+4+4=26, 30 max.
  7914. char map_name[MAP_NAME_LENGTH]; //Err... map names are 15+'\0' in size, not 16+'\0' [Skotlex]
  7915. RFIFOHEAD(fd);
  7916. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  7917. (pc_isGM(sd) >= get_atcommand_level(AtCommand_MapMove))) {
  7918. memcpy(map_name, RFIFOP(fd,2), MAP_NAME_LENGTH-1);
  7919. map_name[MAP_NAME_LENGTH-1]='\0';
  7920. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7921. atcommand_rura(fd, sd, "@rura", output);
  7922. }
  7923. return;
  7924. }
  7925. /*==========================================
  7926. *
  7927. *------------------------------------------
  7928. */
  7929. void clif_changed_dir(struct block_list *bl) {
  7930. unsigned char buf[64];
  7931. struct map_session_data *sd = NULL;
  7932. if (bl->type == BL_PC)
  7933. nullpo_retv (sd=(struct map_session_data *)bl);
  7934. WBUFW(buf,0) = 0x9c;
  7935. WBUFL(buf,2) = bl->id;
  7936. if (sd)
  7937. WBUFW(buf,6) = sd->head_dir;
  7938. WBUFB(buf,8) = status_get_dir(bl);
  7939. clif_send(buf, packet_len_table[0x9c], bl, AREA_WOS);
  7940. if(sd && sd->disguise) {
  7941. WBUFL(buf,2) = -bl->id;
  7942. WBUFW(buf,6) = 0;
  7943. WBUFB(buf,8) = status_get_dir(bl);
  7944. clif_send(buf, packet_len_table[0x9c], bl, AREA);
  7945. }
  7946. return;
  7947. }
  7948. /*==========================================
  7949. *
  7950. *------------------------------------------
  7951. */
  7952. void clif_parse_ChangeDir(int fd, struct map_session_data *sd) {
  7953. unsigned char headdir, dir;
  7954. RFIFOHEAD(fd);
  7955. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7956. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7957. pc_setdir(sd, dir, headdir);
  7958. clif_changed_dir(&sd->bl);
  7959. return;
  7960. }
  7961. /*==========================================
  7962. *
  7963. *------------------------------------------
  7964. */
  7965. void clif_parse_Emotion(int fd, struct map_session_data *sd) {
  7966. unsigned char buf[64];
  7967. RFIFOHEAD(fd);
  7968. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7969. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7970. clif_skill_fail(sd, 1, 0, 1);
  7971. return;
  7972. }
  7973. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7974. if (sd->emotionlasttime >= time(NULL)) {
  7975. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7976. clif_skill_fail(sd, 1, 0, 1);
  7977. return;
  7978. }
  7979. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7980. WBUFW(buf,0) = 0xc0;
  7981. WBUFL(buf,2) = sd->bl.id;
  7982. WBUFB(buf,6) = RFIFOB(fd,2);
  7983. clif_send(buf, packet_len_table[0xc0], &sd->bl, AREA);
  7984. } else
  7985. clif_skill_fail(sd, 1, 0, 1);
  7986. }
  7987. /*==========================================
  7988. *
  7989. *------------------------------------------
  7990. */
  7991. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd) {
  7992. WFIFOHEAD(fd,packet_len_table[0xc2]);
  7993. WFIFOW(fd,0) = 0xc2;
  7994. WFIFOL(fd,2) = map_getusers();
  7995. WFIFOSET(fd,packet_len_table[0xc2]);
  7996. }
  7997. /*==========================================
  7998. *
  7999. *------------------------------------------
  8000. */
  8001. void clif_parse_ActionRequest(int fd, struct map_session_data *sd) {
  8002. unsigned int tick;
  8003. unsigned char buf[64];
  8004. int action_type, target_id;
  8005. RFIFOHEAD(fd);
  8006. if (pc_isdead(sd)) {
  8007. clif_clearchar_area(&sd->bl, 1);
  8008. return;
  8009. }
  8010. if (sd->npc_id || sd->sc.opt1 || sd->sc.option&OPTION_HIDE || sd->state.storage_flag)
  8011. return;
  8012. if (sd->sc.count &&
  8013. (sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  8014. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  8015. sd->sc.data[SC_BLADESTOP].timer != -1))
  8016. return;
  8017. tick = gettick();
  8018. pc_stop_walking(sd, 0);
  8019. pc_stopattack(sd);
  8020. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8021. action_type = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8022. //Regardless of what they have to do, they have just requested an action, no longer idle. [Skotlex]
  8023. sd->idletime = last_tick;
  8024. if(target_id<0) // for disguises [Valaris]
  8025. target_id-=(target_id*2);
  8026. switch(action_type) {
  8027. case 0x00: // once attack
  8028. case 0x07: // continuous attack
  8029. if(sd->view_class==JOB_WEDDING || sd->view_class==JOB_XMAS)
  8030. return;
  8031. if (sd->vender_id != 0)
  8032. return;
  8033. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  8034. if (DIFF_TICK(tick, sd->canact_tick) < 0) {
  8035. clif_skill_fail(sd, 1, 4, 0);
  8036. return;
  8037. }
  8038. }
  8039. if (sd->invincible_timer != -1)
  8040. pc_delinvincibletimer(sd);
  8041. pc_attack(sd, target_id, action_type != 0);
  8042. break;
  8043. case 0x02: // sitdown
  8044. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 3) {
  8045. if (sd->skilltimer != -1) //No sitting while casting :P
  8046. break;
  8047. if (sd->sc.count && (
  8048. sd->sc.data[SC_DANCING].timer != -1 ||
  8049. (sd->sc.data[SC_GRAVITATION].timer != -1 && sd->sc.data[SC_GRAVITATION].val3 == BCT_SELF)
  8050. )) //No sitting during these states neither.
  8051. break;
  8052. pc_stopattack(sd);
  8053. pc_stop_walking(sd, 1);
  8054. pc_setsit(sd);
  8055. skill_gangsterparadise(sd, 1); // ギャングスターパラダイス設定 fixed Valaris
  8056. skill_rest(sd, 1); // TK_HPTIME sitting down mode [Dralnu]
  8057. clif_sitting(sd);
  8058. } else
  8059. clif_skill_fail(sd, 1, 0, 2);
  8060. break;
  8061. case 0x03: // standup
  8062. pc_setstand(sd);
  8063. skill_gangsterparadise(sd, 0); // ギャングスターパラダイス解除 fixed Valaris
  8064. skill_rest(sd, 0); // TK_HPTIME standing up mode [Dralnu]
  8065. WBUFW(buf, 0) = 0x8a;
  8066. WBUFL(buf, 2) = sd->bl.id;
  8067. WBUFB(buf,26) = 3;
  8068. clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
  8069. if(sd->disguise) {
  8070. WBUFL(buf, 2) = -sd->bl.id;
  8071. clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
  8072. }
  8073. break;
  8074. }
  8075. }
  8076. /*==========================================
  8077. *
  8078. *------------------------------------------
  8079. */
  8080. void clif_parse_Restart(int fd, struct map_session_data *sd) {
  8081. RFIFOHEAD(fd);
  8082. switch(RFIFOB(fd,2)) {
  8083. case 0x00:
  8084. if (pc_isdead(sd)) {
  8085. pc_setstand(sd);
  8086. pc_setrestartvalue(sd, 3);
  8087. pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, 2);
  8088. }
  8089. // in case the player's status somehow wasn't updated yet [Celest]
  8090. else if (sd->status.hp <= 0)
  8091. pc_setdead(sd);
  8092. break;
  8093. case 0x01:
  8094. /* Rovert's Prevent logout option - Fixed [Valaris] */
  8095. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  8096. {
  8097. //map_quit(sd); //A clif_quitsave is sent inmediately after this, so no need to quit yet. [Skotlex]
  8098. chrif_charselectreq(sd);
  8099. } else {
  8100. WFIFOHEAD(fd,packet_len_table[0x18b]);
  8101. WFIFOW(fd,0)=0x18b;
  8102. WFIFOW(fd,2)=1;
  8103. WFIFOSET(fd,packet_len_table[0x018b]);
  8104. }
  8105. break;
  8106. }
  8107. }
  8108. /*==========================================
  8109. * Transmission of a wisp (S 0096 <len>.w <nick>.24B <message>.?B)
  8110. *------------------------------------------
  8111. */
  8112. void clif_parse_Wis(int fd, struct map_session_data *sd) { // S 0096 <len>.w <nick>.24B <message>.?B // rewritten by [Yor]
  8113. char *gm_command;
  8114. struct map_session_data *dstsd;
  8115. int i=0;
  8116. struct npc_data *npc;
  8117. char split_data[10][50];
  8118. int j=0,k=0;
  8119. char *whisper_tmp;
  8120. char output[256];
  8121. RFIFOHEAD(fd);
  8122. //printf("clif_parse_Wis: message: '%s'.\n", RFIFOP(fd,28));
  8123. gm_command = (char*)aCallocA(strlen((const char*)RFIFOP(fd,28)) + 28, sizeof(char)); // 24+3+(RFIFOW(fd,2)-28)+1 or 24+3+(strlen(RFIFOP(fd,28))+1 (size can be wrong with hacker)
  8124. sprintf(gm_command, "%s : %s", sd->status.name, RFIFOP(fd,28));
  8125. if ((is_charcommand(fd, sd, gm_command, 0) != CharCommand_None) ||
  8126. (is_atcommand(fd, sd, gm_command, 0) != AtCommand_None)) {
  8127. if(gm_command) aFree(gm_command);
  8128. return;
  8129. }
  8130. if (sd->sc.count &&
  8131. (sd->sc.data[SC_BERSERK].timer!=-1 || sd->sc.data[SC_NOCHAT].timer != -1))
  8132. {
  8133. if(gm_command) aFree(gm_command);
  8134. return;
  8135. }
  8136. if(gm_command) aFree(gm_command);
  8137. //Chat Logging type 'W' / Whisper
  8138. if(log_config.chat&1 //we log everything then
  8139. || ( log_config.chat&2 //if Whisper bit is on
  8140. && ( !agit_flag || !(log_config.chat&16) ))) //if WOE ONLY flag is off or AGIT is OFF
  8141. log_chat("W", 0, sd->status.char_id, sd->status.account_id, (char*)mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, (char*)RFIFOP(fd, 4), (char*)RFIFOP(fd, 28));
  8142. //-------------------------------------------------------//
  8143. // Lordalfa - Paperboy - To whisper NPC commands //
  8144. //-------------------------------------------------------//
  8145. if ((strncasecmp((const char*)RFIFOP(fd,4),"NPC:",4) == 0) && (strlen((const char*)RFIFOP(fd,4)) >4)) {
  8146. whisper_tmp = (char*) RFIFOP(fd,4) + 4;
  8147. if ((npc = npc_name2id(whisper_tmp)))
  8148. {
  8149. whisper_tmp=(char *)aCallocA(strlen((char *)(RFIFOP(fd,28))+1),sizeof(char));
  8150. whisper_tmp[0]=0;
  8151. sprintf(whisper_tmp, "%s", (const char*)RFIFOP(fd,28));
  8152. for( j=0;whisper_tmp[j]!='\0';j++)
  8153. {
  8154. if(whisper_tmp[j]!='#')
  8155. {
  8156. split_data[i][j-k]=whisper_tmp[j];
  8157. }
  8158. else
  8159. {
  8160. split_data[i][j-k]='\0';
  8161. k=j+1;
  8162. i++;
  8163. }
  8164. } // Splits the message using '#' as separators
  8165. split_data[i][j-k]='\0';
  8166. aFree(whisper_tmp);
  8167. whisper_tmp=(char *)aCallocA(15,sizeof(char));
  8168. whisper_tmp[0]=0;
  8169. for (j=0;j<=10;j++)
  8170. {
  8171. sprintf(whisper_tmp, "@whispervar%d$", j);
  8172. set_var(sd,whisper_tmp,(char *) split_data[j]);
  8173. }//You don't need to zero them, just reset them [Kevin]
  8174. aFree(whisper_tmp);
  8175. whisper_tmp=(char *)aCallocA(strlen(npc->name)+18,sizeof(char));
  8176. whisper_tmp[0]=0;
  8177. sprintf(whisper_tmp, "%s::OnWhisperGlobal", npc->name);
  8178. npc_event(sd,whisper_tmp,0); // Calls the NPC label
  8179. return;
  8180. aFree(whisper_tmp); //I rewrote it a little to use memory allocation, a bit more stable =P [Kevin]
  8181. whisper_tmp = NULL;
  8182. } //should have just removed the one below that was a my bad =P
  8183. }
  8184. // Main chat [LuzZza]
  8185. if(strcmpi((const char*)RFIFOP(fd,4), main_chat_nick) == 0) {
  8186. if(!sd->state.mainchat) {
  8187. sd->state.mainchat = 1;
  8188. clif_displaymessage(fd, msg_txt(380)); // Main chat has been activated.
  8189. }
  8190. if (sd->sc.data[SC_NOCHAT].timer != -1) {
  8191. clif_displaymessage(fd, msg_txt(387));
  8192. return;
  8193. }
  8194. sprintf(output, msg_txt(386), sd->status.name, (char *)RFIFOP(fd,28));
  8195. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  8196. return;
  8197. }
  8198. // searching destination character
  8199. dstsd = map_nick2sd((char*)RFIFOP(fd,4));
  8200. // player is not on this map-server
  8201. if (dstsd == NULL ||
  8202. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  8203. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  8204. // and if we ask for 'Test', we must not contact 'test' player
  8205. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  8206. strcmp(dstsd->status.name, (const char*)RFIFOP(fd,4)) != 0) // not exactly same name
  8207. // send message to inter-server
  8208. intif_wis_message(sd, (char*)RFIFOP(fd,4), (char*)RFIFOP(fd,28), RFIFOW(fd,2)-28);
  8209. // player is on this map-server
  8210. else {
  8211. // if you send to your self, don't send anything to others
  8212. if (dstsd->fd == fd) // but, normaly, it's impossible!
  8213. clif_wis_message(fd, wisp_server_name, "You can not page yourself. Sorry.", strlen("You can not page yourself. Sorry.") + 1);
  8214. // otherwise, send message and answer immediatly
  8215. else {
  8216. if (dstsd->ignoreAll == 1) {
  8217. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  8218. clif_wis_end(fd, 1); // 1: target character is not loged in
  8219. else
  8220. clif_wis_end(fd, 3); // 3: everyone ignored by target
  8221. } else {
  8222. // if player ignore the source character
  8223. for(i = 0; i < MAX_IGNORE_LIST; i++)
  8224. if (strcmp(dstsd->ignore[i].name, sd->status.name) == 0) {
  8225. clif_wis_end(fd, 2); // 2: ignored by target
  8226. break;
  8227. }
  8228. // if source player not found in ignore list
  8229. if (i == MAX_IGNORE_LIST) {
  8230. if(strlen(dstsd->away_message) > 0) { // Send away automessage [LuzZza]
  8231. //(Automessage has been sent)
  8232. sprintf(output, "%s %s", (char*)RFIFOP(fd,28),msg_txt(543));
  8233. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  8234. clif_wis_end(fd, 0); // 0: success to send wisper
  8235. if(dstsd->state.autotrade)
  8236. //"Away [AT] - \"%s\""
  8237. sprintf(output, msg_txt(544), dstsd->away_message);
  8238. else
  8239. //"Away - \"%s\""
  8240. sprintf(output, msg_txt(545), dstsd->away_message);
  8241. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  8242. } else { // Normal message
  8243. clif_wis_message(dstsd->fd, sd->status.name, (char*)RFIFOP(fd,28), RFIFOW(fd,2) - 28);
  8244. clif_wis_end(fd, 0); // 0: success to send wisper
  8245. }
  8246. }
  8247. }
  8248. }
  8249. }
  8250. return;
  8251. }
  8252. /*==========================================
  8253. *
  8254. *------------------------------------------
  8255. */
  8256. void clif_parse_GMmessage(int fd, struct map_session_data *sd) {
  8257. // /b
  8258. RFIFOHEAD(fd);
  8259. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8260. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Broadcast)))
  8261. intif_GMmessage((char*)RFIFOP(fd,4), RFIFOW(fd,2)-4, 0);
  8262. }
  8263. /*==========================================
  8264. *
  8265. *------------------------------------------
  8266. */
  8267. void clif_parse_TakeItem(int fd, struct map_session_data *sd) {
  8268. struct flooritem_data *fitem;
  8269. int map_object_id;
  8270. RFIFOHEAD(fd);
  8271. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8272. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  8273. if (pc_isdead(sd)) {
  8274. clif_clearchar_area(&sd->bl, 1);
  8275. return;
  8276. }
  8277. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  8278. return;
  8279. if(sd->npc_id || sd->vender_id || sd->sc.opt1 || sd->trade_partner ||
  8280. pc_iscloaking(sd) || pc_ischasewalk(sd)) //Disable cloaking/chasewalking characters from looting [Skotlex]
  8281. return;
  8282. if(sd->sc.count && (
  8283. sd->sc.data[SC_TRICKDEAD].timer != -1 || //死んだふり
  8284. sd->sc.data[SC_BLADESTOP].timer != -1 || //白刃取り
  8285. sd->sc.data[SC_NOCHAT].timer!=-1 ) //会話禁止
  8286. ) {
  8287. clif_additem(sd,0,0,6); // send fail packet! [Valaris]
  8288. return;
  8289. }
  8290. pc_takeitem(sd, fitem);
  8291. }
  8292. /*==========================================
  8293. *
  8294. *------------------------------------------
  8295. */
  8296. void clif_parse_DropItem(int fd, struct map_session_data *sd) {
  8297. int item_index, item_amount;
  8298. RFIFOHEAD(fd);
  8299. if (pc_isdead(sd)) {
  8300. clif_clearchar_area(&sd->bl, 1);
  8301. return;
  8302. }
  8303. if (sd->npc_id || sd->vender_id || sd->sc.opt1 || sd->trade_partner)
  8304. return;
  8305. if (sd->sc.count && (
  8306. sd->sc.data[SC_AUTOCOUNTER].timer != -1 || //オートカウンター
  8307. sd->sc.data[SC_BLADESTOP].timer != -1//白刃取り
  8308. ))
  8309. return;
  8310. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8311. item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8312. pc_dropitem(sd, item_index, item_amount);
  8313. }
  8314. /*==========================================
  8315. *
  8316. *------------------------------------------
  8317. */
  8318. void clif_parse_UseItem(int fd, struct map_session_data *sd) {
  8319. RFIFOHEAD(fd);
  8320. if (pc_isdead(sd)) {
  8321. clif_clearchar_area(&sd->bl, 1);
  8322. return;
  8323. }
  8324. if (sd->vender_id || sd->trade_partner)
  8325. return;
  8326. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  8327. return;
  8328. if (sd->npc_id && sd->npc_id != sd->npc_item_flag) //This flag enables you to use items while in an NPC. [Skotlex]
  8329. return;
  8330. if (sd->sc.count && (
  8331. sd->sc.data[SC_TRICKDEAD].timer != -1 || //死んだふり
  8332. sd->sc.data[SC_BLADESTOP].timer != -1 || //白刃取り
  8333. sd->sc.data[SC_BERSERK].timer!=-1 || //バーサーク
  8334. sd->sc.data[SC_NOCHAT].timer!=-1 ||
  8335. sd->sc.data[SC_GRAVITATION].timer!=-1 //会話禁止
  8336. ))
  8337. return;
  8338. if (sd->invincible_timer != -1)
  8339. pc_delinvincibletimer(sd);
  8340. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  8341. sd->idletime = last_tick;
  8342. pc_useitem(sd,RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2);
  8343. }
  8344. /*==========================================
  8345. *
  8346. *------------------------------------------
  8347. */
  8348. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  8349. {
  8350. int index;
  8351. RFIFOHEAD(fd);
  8352. if(pc_isdead(sd)) {
  8353. clif_clearchar_area(&sd->bl,1);
  8354. return;
  8355. }
  8356. index = RFIFOW(fd,2)-2;
  8357. if (index < 0 || index >= MAX_INVENTORY)
  8358. return; //Out of bounds check.
  8359. if(sd->npc_id!=0 && sd->npc_id != sd->npc_item_flag)
  8360. return;
  8361. if(sd->vender_id != 0 || sd->trade_partner != 0)
  8362. return;
  8363. if(sd->sc.data[SC_BLADESTOP].timer!=-1 || sd->sc.data[SC_BERSERK].timer!=-1 )
  8364. return;
  8365. if(sd->status.inventory[index].identify != 1) { // 未鑑定
  8366. clif_equipitemack(sd,index,0,0); // fail
  8367. return;
  8368. }
  8369. //ペット用装備であるかないか
  8370. if(sd->inventory_data[index]) {
  8371. if(sd->inventory_data[index]->type != 8){
  8372. if(sd->inventory_data[index]->type == 10)
  8373. RFIFOW(fd,4)=0x8000; // 矢を無理やり装備できるように(--;
  8374. pc_equipitem(sd,index,RFIFOW(fd,4));
  8375. } else
  8376. pet_equipitem(sd,index);
  8377. }
  8378. }
  8379. /*==========================================
  8380. *
  8381. *------------------------------------------
  8382. */
  8383. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  8384. {
  8385. int index;
  8386. RFIFOHEAD(fd);
  8387. if(pc_isdead(sd)) {
  8388. clif_clearchar_area(&sd->bl,1);
  8389. return;
  8390. }
  8391. if(sd->npc_id!=0 || sd->vender_id != 0 || sd->sc.opt1 > 0 || sd->trade_partner != 0)
  8392. return;
  8393. index = RFIFOW(fd,2)-2;
  8394. pc_unequipitem(sd,index,1);
  8395. }
  8396. /*==========================================
  8397. *
  8398. *------------------------------------------
  8399. */
  8400. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8401. {
  8402. RFIFOHEAD(fd);
  8403. if(pc_isdead(sd)) {
  8404. clif_clearchar_area(&sd->bl,1);
  8405. return;
  8406. }
  8407. if(sd->npc_id!=0 || sd->vender_id != 0 || sd->trade_partner != 0 || RFIFOL(fd,2) < 0) //Clicked on a negative ID? Player disguised as NPC! [Skotlex]
  8408. return;
  8409. npc_click(sd,RFIFOL(fd,2));
  8410. }
  8411. /*==========================================
  8412. *
  8413. *------------------------------------------
  8414. */
  8415. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8416. {
  8417. RFIFOHEAD(fd);
  8418. if (sd->trade_partner != 0)
  8419. return;
  8420. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8421. }
  8422. /*==========================================
  8423. *
  8424. *------------------------------------------
  8425. */
  8426. void clif_parse_NpcBuyListSend(int fd,struct map_session_data *sd)
  8427. {
  8428. int fail=0,n;
  8429. unsigned short *item_list;
  8430. RFIFOHEAD(fd);
  8431. n = (RFIFOW(fd,2)-4) /4;
  8432. item_list = (unsigned short*)RFIFOP(fd,4);
  8433. if (sd->trade_partner != 0)
  8434. fail = 1;
  8435. else
  8436. fail = npc_buylist(sd,n,item_list);
  8437. WFIFOHEAD(fd,packet_len_table[0xca]);
  8438. WFIFOW(fd,0)=0xca;
  8439. WFIFOB(fd,2)=fail;
  8440. WFIFOSET(fd,packet_len_table[0xca]);
  8441. }
  8442. /*==========================================
  8443. *
  8444. *------------------------------------------
  8445. */
  8446. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8447. {
  8448. int fail=0,n;
  8449. unsigned short *item_list;
  8450. RFIFOHEAD(fd);
  8451. n = (RFIFOW(fd,2)-4) /4;
  8452. item_list = (unsigned short*)RFIFOP(fd,4);
  8453. if (sd->trade_partner != 0)
  8454. fail = 1;
  8455. else
  8456. fail = npc_selllist(sd,n,item_list);
  8457. WFIFOHEAD(fd,packet_len_table[0xcb]);
  8458. WFIFOW(fd,0)=0xcb;
  8459. WFIFOB(fd,2)=fail;
  8460. WFIFOSET(fd,packet_len_table[0xcb]);
  8461. }
  8462. /*==========================================
  8463. *
  8464. *------------------------------------------
  8465. */
  8466. void clif_parse_CreateChatRoom(int fd,struct map_session_data *sd)
  8467. {
  8468. RFIFOHEAD(fd);
  8469. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 4){
  8470. chat_createchat(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8471. } else
  8472. clif_skill_fail(sd,1,0,3);
  8473. }
  8474. /*==========================================
  8475. *
  8476. *------------------------------------------
  8477. */
  8478. void clif_parse_ChatAddMember(int fd,struct map_session_data *sd)
  8479. {
  8480. RFIFOHEAD(fd);
  8481. chat_joinchat(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8482. }
  8483. /*==========================================
  8484. *
  8485. *------------------------------------------
  8486. */
  8487. void clif_parse_ChatRoomStatusChange(int fd,struct map_session_data *sd)
  8488. {
  8489. RFIFOHEAD(fd);
  8490. chat_changechatstatus(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8491. }
  8492. /*==========================================
  8493. *
  8494. *------------------------------------------
  8495. */
  8496. void clif_parse_ChangeChatOwner(int fd,struct map_session_data *sd)
  8497. {
  8498. RFIFOHEAD(fd);
  8499. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8500. }
  8501. /*==========================================
  8502. *
  8503. *------------------------------------------
  8504. */
  8505. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8506. {
  8507. RFIFOHEAD(fd);
  8508. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8509. }
  8510. /*==========================================
  8511. *
  8512. *------------------------------------------
  8513. */
  8514. void clif_parse_ChatLeave(int fd,struct map_session_data *sd)
  8515. {
  8516. chat_leavechat(sd);
  8517. }
  8518. /*==========================================
  8519. * 取引要請を相手に送る
  8520. *------------------------------------------
  8521. */
  8522. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8523. {
  8524. RFIFOHEAD(fd);
  8525. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 1){
  8526. trade_traderequest(sd,RFIFOL(sd->fd,2));
  8527. } else
  8528. clif_skill_fail(sd,1,0,0);
  8529. }
  8530. /*==========================================
  8531. * 取引要請
  8532. *------------------------------------------
  8533. */
  8534. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8535. {
  8536. RFIFOHEAD(fd);
  8537. trade_tradeack(sd,RFIFOB(sd->fd,2));
  8538. }
  8539. /*==========================================
  8540. * アイテム追加
  8541. *------------------------------------------
  8542. */
  8543. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8544. {
  8545. RFIFOHEAD(fd);
  8546. trade_tradeadditem(sd,RFIFOW(sd->fd,2),RFIFOL(sd->fd,4));
  8547. }
  8548. /*==========================================
  8549. * アイテム追加完了(ok押し)
  8550. *------------------------------------------
  8551. */
  8552. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8553. {
  8554. trade_tradeok(sd);
  8555. }
  8556. /*==========================================
  8557. * 取引キャンセル
  8558. *------------------------------------------
  8559. */
  8560. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8561. {
  8562. trade_tradecancel(sd);
  8563. }
  8564. /*==========================================
  8565. * 取引許諾(trade押し)
  8566. *------------------------------------------
  8567. */
  8568. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8569. {
  8570. trade_tradecommit(sd);
  8571. }
  8572. /*==========================================
  8573. *
  8574. *------------------------------------------
  8575. */
  8576. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8577. {
  8578. pc_stopattack(sd);
  8579. }
  8580. /*==========================================
  8581. * カートへアイテムを移す
  8582. *------------------------------------------
  8583. */
  8584. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8585. {
  8586. RFIFOHEAD(fd);
  8587. if(sd->npc_id!=0 || sd->vender_id != 0 || sd->trade_partner != 0)
  8588. return;
  8589. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8590. }
  8591. /*==========================================
  8592. * カートからアイテムを出す
  8593. *------------------------------------------
  8594. */
  8595. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8596. {
  8597. RFIFOHEAD(fd);
  8598. if(sd->npc_id!=0 || sd->vender_id != 0 || sd->trade_partner != 0) return;
  8599. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8600. }
  8601. /*==========================================
  8602. * 付属品(鷹,ペコ,カート)をはずす
  8603. *------------------------------------------
  8604. */
  8605. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8606. {
  8607. pc_setoption(sd,0);
  8608. }
  8609. /*==========================================
  8610. * チェンジカート
  8611. *------------------------------------------
  8612. */
  8613. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8614. {
  8615. RFIFOHEAD(fd);
  8616. pc_setcart(sd,RFIFOW(fd,2));
  8617. }
  8618. /*==========================================
  8619. * ステータスアップ
  8620. *------------------------------------------
  8621. */
  8622. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8623. {
  8624. RFIFOHEAD(fd);
  8625. pc_statusup(sd,RFIFOW(fd,2));
  8626. }
  8627. /*==========================================
  8628. * スキルレベルアップ
  8629. *------------------------------------------
  8630. */
  8631. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8632. {
  8633. RFIFOHEAD(fd);
  8634. pc_skillup(sd,RFIFOW(fd,2));
  8635. }
  8636. /*==========================================
  8637. * スキル使用(ID指定)
  8638. *------------------------------------------
  8639. */
  8640. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd) {
  8641. int skillnum, skilllv, lv, target_id;
  8642. unsigned int tick = gettick();
  8643. RFIFOHEAD(fd);
  8644. if (sd->chatID || sd->npc_id != 0 || sd->vender_id != 0 || sd->state.storage_flag || pc_issit(sd))
  8645. return;
  8646. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8647. if (skilllv < 1) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8648. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8649. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8650. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8651. sd->idletime = last_tick;
  8652. if (skillnotok(skillnum, sd))
  8653. return;
  8654. if (sd->skilltimer != -1) {
  8655. if (skillnum != SA_CASTCANCEL)
  8656. return;
  8657. } else if (DIFF_TICK(tick, sd->canact_tick) < 0 &&
  8658. // allow monk combos to ignore this delay [celest]
  8659. !(sd->sc.count && sd->sc.data[SC_COMBO].timer!=-1 &&
  8660. (skillnum == MO_EXTREMITYFIST ||
  8661. skillnum == MO_CHAINCOMBO ||
  8662. skillnum == MO_COMBOFINISH ||
  8663. skillnum == CH_PALMSTRIKE ||
  8664. skillnum == CH_TIGERFIST ||
  8665. skillnum == CH_CHAINCRUSH))) {
  8666. clif_skill_fail(sd, skillnum, 4, 0);
  8667. return;
  8668. }
  8669. if (sd->view_class == JOB_WEDDING || sd->view_class == JOB_XMAS)
  8670. return;
  8671. if (sd->invincible_timer != -1)
  8672. pc_delinvincibletimer(sd);
  8673. if(target_id<0) // for disguises [Valaris]
  8674. target_id-=target_id*2;
  8675. if (sd->skillitem >= 0 && sd->skillitem == skillnum) {
  8676. if (skilllv != sd->skillitemlv)
  8677. skilllv = sd->skillitemlv;
  8678. skill_use_id(sd, target_id, skillnum, skilllv);
  8679. } else {
  8680. sd->skillitem = sd->skillitemlv = -1;
  8681. if (skillnum == MO_EXTREMITYFIST) {
  8682. if ((sd->sc.data[SC_COMBO].timer == -1 ||
  8683. (sd->sc.data[SC_COMBO].val1 != MO_COMBOFINISH &&
  8684. sd->sc.data[SC_COMBO].val1 != CH_TIGERFIST &&
  8685. sd->sc.data[SC_COMBO].val1 != CH_CHAINCRUSH))) {
  8686. if (!sd->state.skill_flag ) {
  8687. sd->state.skill_flag = 1;
  8688. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8689. return;
  8690. } else if (sd->bl.id == target_id) {
  8691. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8692. return;
  8693. }
  8694. }
  8695. }
  8696. if (skillnum == TK_JUMPKICK) {
  8697. if (sd->sc.data[SC_COMBO].timer == -1 ||
  8698. sd->sc.data[SC_COMBO].val1 != TK_JUMPKICK) {
  8699. if (!sd->state.skill_flag ) {
  8700. sd->state.skill_flag = 1;
  8701. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8702. return;
  8703. } else if (sd->bl.id == target_id) {
  8704. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8705. return;
  8706. }
  8707. }
  8708. }
  8709. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8710. if (skilllv > lv)
  8711. skilllv = lv;
  8712. skill_use_id(sd, target_id, skillnum, skilllv);
  8713. if (sd->state.skill_flag)
  8714. sd->state.skill_flag = 0;
  8715. }
  8716. }
  8717. }
  8718. /*==========================================
  8719. * スキル使用(場所指定)
  8720. *------------------------------------------
  8721. */
  8722. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, int skilllv, int skillnum, int x, int y, int skillmoreinfo)
  8723. {
  8724. int lv;
  8725. unsigned int tick = gettick();
  8726. RFIFOHEAD(fd);
  8727. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8728. sd->idletime = last_tick;
  8729. if (skillnotok(skillnum, sd))
  8730. return;
  8731. if (skillmoreinfo != -1) {
  8732. if (pc_issit(sd)) {
  8733. clif_skill_fail(sd, skillnum, 0, 0);
  8734. return;
  8735. }
  8736. memcpy(talkie_mes, RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8737. talkie_mes[MESSAGE_SIZE-1] = '\0'; //Overflow protection [Skotlex]
  8738. }
  8739. if (sd->skilltimer != -1)
  8740. return;
  8741. else if (DIFF_TICK(tick, sd->canact_tick) < 0)
  8742. {
  8743. clif_skill_fail(sd, skillnum, 4, 0);
  8744. return;
  8745. }
  8746. if (sd->view_class == JOB_WEDDING || sd->view_class == JOB_XMAS)
  8747. return;
  8748. if (sd->invincible_timer != -1)
  8749. pc_delinvincibletimer(sd);
  8750. if (sd->skillitem >= 0 && sd->skillitem == skillnum) {
  8751. if (skilllv != sd->skillitemlv)
  8752. skilllv = sd->skillitemlv;
  8753. skill_use_pos(sd, x, y, skillnum, skilllv);
  8754. } else {
  8755. sd->skillitem = sd->skillitemlv = -1;
  8756. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8757. if (skilllv > lv)
  8758. skilllv = lv;
  8759. skill_use_pos(sd, x, y, skillnum,skilllv);
  8760. }
  8761. }
  8762. }
  8763. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd) {
  8764. RFIFOHEAD(fd);
  8765. if (sd->npc_id != 0 || sd->vender_id != 0 || sd->chatID || sd->state.storage_flag || pc_issit(sd))
  8766. return;
  8767. clif_parse_UseSkillToPosSub(fd, sd,
  8768. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8769. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8770. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8771. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8772. -1 //Skill more info.
  8773. );
  8774. }
  8775. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd) {
  8776. RFIFOHEAD(fd);
  8777. if (sd->npc_id != 0 || sd->vender_id != 0 || sd->chatID || sd->state.storage_flag) return;
  8778. clif_parse_UseSkillToPosSub(fd, sd,
  8779. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8780. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8781. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8782. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8783. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8784. );
  8785. }
  8786. /*==========================================
  8787. * スキル使用(map指定)
  8788. *------------------------------------------
  8789. */
  8790. void clif_parse_UseSkillMap(int fd,struct map_session_data *sd)
  8791. {
  8792. RFIFOHEAD(fd);
  8793. if(sd->chatID || sd->npc_id || sd->vender_id)
  8794. return;
  8795. if (sd->view_class==JOB_WEDDING || sd->view_class == JOB_XMAS)
  8796. return;
  8797. if(sd->invincible_timer != -1)
  8798. pc_delinvincibletimer(sd);
  8799. skill_castend_map(sd,RFIFOW(fd,2),(char*)RFIFOP(fd,4));
  8800. }
  8801. /*==========================================
  8802. * メモ要求
  8803. *------------------------------------------
  8804. */
  8805. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8806. {
  8807. if (!pc_isdead(sd))
  8808. pc_memo(sd,-1);
  8809. }
  8810. /*==========================================
  8811. * アイテム合成
  8812. *------------------------------------------
  8813. */
  8814. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8815. {
  8816. RFIFOHEAD(fd);
  8817. if (!sd->state.produce_flag)
  8818. return;
  8819. sd->state.produce_flag = 0;
  8820. if (sd->npc_id) {
  8821. //Make it fail to avoid shop exploits where you sell something different than you see.
  8822. clif_skill_fail(sd,sd->skillid,0,0);
  8823. return;
  8824. }
  8825. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8826. }
  8827. /*==========================================
  8828. * 武器修理
  8829. *------------------------------------------
  8830. */
  8831. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8832. {
  8833. RFIFOHEAD(fd);
  8834. if (!sd->state.produce_flag)
  8835. return;
  8836. sd->state.produce_flag = 0;
  8837. if (sd->npc_id) {
  8838. //Make it fail to avoid shop exploits where you sell something different than you see.
  8839. clif_skill_fail(sd,sd->skillid,0,0);
  8840. return;
  8841. }
  8842. skill_repairweapon(sd,RFIFOW(fd,2));
  8843. }
  8844. /*==========================================
  8845. *
  8846. *------------------------------------------
  8847. */
  8848. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd) {
  8849. int idx;
  8850. RFIFOHEAD(fd);
  8851. if (!sd->state.produce_flag) //Packet exploit?
  8852. return;
  8853. sd->state.produce_flag = 0;
  8854. if (sd->npc_id) {
  8855. //Make it fail to avoid shop exploits where you sell something different than you see.
  8856. clif_skill_fail(sd,sd->skillid,0,0);
  8857. return;
  8858. }
  8859. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8860. skill_weaponrefine(sd, idx-2);
  8861. }
  8862. /*==========================================
  8863. *
  8864. *------------------------------------------
  8865. */
  8866. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8867. {
  8868. RFIFOHEAD(fd);
  8869. sd->npc_menu=RFIFOB(fd,6);
  8870. npc_scriptcont(sd,RFIFOL(fd,2));
  8871. }
  8872. /*==========================================
  8873. *
  8874. *------------------------------------------
  8875. */
  8876. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8877. {
  8878. RFIFOHEAD(fd);
  8879. #ifdef __WIN32
  8880. //For some extraordinarily eerie reason that noone has figured out yet,
  8881. //windows native compiles NEED this nullpo_retv or the function is not found!
  8882. nullpo_retv(sd);
  8883. #endif
  8884. npc_scriptcont(sd,RFIFOL(fd,2));
  8885. }
  8886. /*==========================================
  8887. *
  8888. *------------------------------------------
  8889. */
  8890. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8891. {
  8892. RFIFOHEAD(fd);
  8893. #define RFIFOL_(fd,pos) (*(int*)(session[fd]->rdata+session[fd]->rdata_pos+(pos)))
  8894. //Input Value overflow Exploit FIX
  8895. sd->npc_amount=RFIFOL_(fd,6); //fixed by Lupus. npc_amount is (int) but was RFIFOL changing it to (unsigned int)
  8896. #undef RFIFOL_
  8897. npc_scriptcont(sd,RFIFOL(fd,2));
  8898. }
  8899. /*==========================================
  8900. *
  8901. *------------------------------------------
  8902. */
  8903. void clif_parse_NpcStringInput(int fd,struct map_session_data *sd)
  8904. {
  8905. RFIFOHEAD(fd);
  8906. if(RFIFOW(fd,2)-7 >= sizeof(sd->npc_str)){
  8907. ShowWarning("clif: input string too long !\n");
  8908. memcpy(sd->npc_str,RFIFOP(fd,8),sizeof(sd->npc_str));
  8909. sd->npc_str[sizeof(sd->npc_str)-1]=0;
  8910. } else
  8911. strcpy(sd->npc_str,(char*)RFIFOP(fd,8));
  8912. npc_scriptcont(sd,RFIFOL(fd,4));
  8913. }
  8914. /*==========================================
  8915. *
  8916. *------------------------------------------
  8917. */
  8918. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8919. {
  8920. RFIFOHEAD(fd);
  8921. npc_scriptcont(sd,RFIFOL(fd,2));
  8922. }
  8923. /*==========================================
  8924. * アイテム鑑定
  8925. *------------------------------------------
  8926. */
  8927. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8928. {
  8929. RFIFOHEAD(fd);
  8930. skill_identify(sd,RFIFOW(fd,2)-2);
  8931. }
  8932. /*==========================================
  8933. * 矢作成
  8934. *------------------------------------------
  8935. */
  8936. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8937. {
  8938. RFIFOHEAD(fd);
  8939. if (!sd->state.produce_flag)
  8940. return;
  8941. sd->state.produce_flag = 0;
  8942. if (sd->npc_id) { //Make it fail to avoid shop exploits where you sell something different than you see.
  8943. clif_skill_fail(sd,sd->skillid,0,0);
  8944. return;
  8945. }
  8946. skill_arrow_create(sd,RFIFOW(fd,2));
  8947. }
  8948. /*==========================================
  8949. * オートスペル受信
  8950. *------------------------------------------
  8951. */
  8952. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8953. {
  8954. RFIFOHEAD(fd);
  8955. skill_autospell(sd,RFIFOW(fd,2));
  8956. }
  8957. /*==========================================
  8958. * カード使用
  8959. *------------------------------------------
  8960. */
  8961. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8962. {
  8963. RFIFOHEAD(fd);
  8964. if (sd->trade_partner != 0)
  8965. return;
  8966. clif_use_card(sd,RFIFOW(fd,2)-2);
  8967. }
  8968. /*==========================================
  8969. * カード挿入装備選択
  8970. *------------------------------------------
  8971. */
  8972. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8973. {
  8974. RFIFOHEAD(fd);
  8975. if (sd->trade_partner != 0)
  8976. return;
  8977. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8978. }
  8979. /*==========================================
  8980. * 0193 キャラID名前引き
  8981. *------------------------------------------
  8982. */
  8983. void clif_parse_SolveCharName(int fd, struct map_session_data *sd) {
  8984. int char_id;
  8985. RFIFOHEAD(fd);
  8986. char_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8987. clif_solved_charname(sd, char_id);
  8988. }
  8989. /*==========================================
  8990. * 0197 /resetskill /resetstate
  8991. *------------------------------------------
  8992. */
  8993. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  8994. RFIFOHEAD(fd);
  8995. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  8996. pc_isGM(sd) >= get_atcommand_level(AtCommand_ResetState)) {
  8997. switch(RFIFOW(fd,2)){
  8998. case 0:
  8999. pc_resetstate(sd);
  9000. break;
  9001. case 1:
  9002. pc_resetskill(sd);
  9003. break;
  9004. }
  9005. }
  9006. }
  9007. /*==========================================
  9008. * 019c /lb等
  9009. *------------------------------------------
  9010. */
  9011. void clif_parse_LGMmessage(int fd, struct map_session_data *sd) {
  9012. unsigned char buf[512];
  9013. RFIFOHEAD(fd);
  9014. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9015. (pc_isGM(sd) >= get_atcommand_level(AtCommand_LocalBroadcast))) {
  9016. WBUFW(buf,0) = 0x9a;
  9017. WBUFW(buf,2) = RFIFOW(fd,2);
  9018. memcpy(WBUFP(buf,4), RFIFOP(fd,4), RFIFOW(fd,2) - 4);
  9019. clif_send(buf, RFIFOW(fd,2), &sd->bl, ALL_SAMEMAP);
  9020. }
  9021. }
  9022. /*==========================================
  9023. * カプラ倉庫へ入れる
  9024. *------------------------------------------
  9025. */
  9026. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd) {
  9027. int item_index, item_amount;
  9028. RFIFOHEAD(fd);
  9029. if (sd->npc_id != 0 || sd->vender_id != 0 || sd->trade_partner != 0 || !sd->state.storage_flag)
  9030. return;
  9031. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9032. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9033. if (item_index < 0 || item_index >= MAX_INVENTORY)
  9034. return;
  9035. if (sd->state.storage_flag == 1)
  9036. storage_storageadd(sd, item_index, item_amount);
  9037. else if (sd->state.storage_flag == 2)
  9038. storage_guild_storageadd(sd, item_index, item_amount);
  9039. }
  9040. /*==========================================
  9041. * カプラ倉庫から出す
  9042. *------------------------------------------
  9043. */
  9044. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd) {
  9045. int item_index, item_amount;
  9046. RFIFOHEAD(fd);
  9047. if (sd->npc_id != 0 || sd->vender_id != 0 || sd->trade_partner != 0 || !sd->state.storage_flag)
  9048. return;
  9049. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  9050. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9051. if (sd->state.storage_flag == 1)
  9052. storage_storageget(sd, item_index, item_amount);
  9053. else if(sd->state.storage_flag == 2)
  9054. storage_guild_storageget(sd, item_index, item_amount);
  9055. }
  9056. /*==========================================
  9057. * カプラ倉庫へカートから入れる
  9058. *------------------------------------------
  9059. */
  9060. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd) {
  9061. RFIFOHEAD(fd);
  9062. if (sd->npc_id != 0 || sd->vender_id != 0 || sd->trade_partner != 0 || !sd->state.storage_flag)
  9063. return;
  9064. if (sd->state.storage_flag == 1)
  9065. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9066. else if (sd->state.storage_flag == 2)
  9067. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9068. }
  9069. /*==========================================
  9070. * カプラ倉庫から出す
  9071. *------------------------------------------
  9072. */
  9073. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd) {
  9074. RFIFOHEAD(fd);
  9075. if (sd->npc_id != 0 || sd->vender_id != 0 || sd->trade_partner != 0 || !sd->state.storage_flag)
  9076. return;
  9077. if (sd->state.storage_flag == 1)
  9078. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9079. else if (sd->state.storage_flag == 2)
  9080. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9081. }
  9082. /*==========================================
  9083. * カプラ倉庫を閉じる
  9084. *------------------------------------------
  9085. */
  9086. void clif_parse_CloseKafra(int fd, struct map_session_data *sd) {
  9087. if (sd->state.storage_flag == 1)
  9088. storage_storageclose(sd);
  9089. else if (sd->state.storage_flag == 2)
  9090. storage_guild_storageclose(sd);
  9091. }
  9092. /*==========================================
  9093. * パーティを作る
  9094. *------------------------------------------
  9095. */
  9096. void clif_parse_CreateParty(int fd, struct map_session_data *sd) {
  9097. RFIFOHEAD(fd);
  9098. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7) {
  9099. party_create(sd,(char*)RFIFOP(fd,2),0,0);
  9100. } else
  9101. clif_skill_fail(sd,1,0,4);
  9102. }
  9103. /*==========================================
  9104. * パーティを作る
  9105. *------------------------------------------
  9106. */
  9107. void clif_parse_CreateParty2(int fd, struct map_session_data *sd) {
  9108. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7){
  9109. RFIFOHEAD(fd);
  9110. party_create(sd,(char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27));
  9111. } else
  9112. clif_skill_fail(sd,1,0,4);
  9113. }
  9114. /*==========================================
  9115. * パーティに勧誘
  9116. *------------------------------------------
  9117. */
  9118. void clif_parse_PartyInvite(int fd, struct map_session_data *sd) {
  9119. RFIFOHEAD(fd);
  9120. party_invite(sd, RFIFOL(fd,2));
  9121. }
  9122. /*==========================================
  9123. * パーティ勧誘返答
  9124. *------------------------------------------
  9125. */
  9126. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd) {
  9127. RFIFOHEAD(fd);
  9128. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  9129. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9130. } else {
  9131. party_reply_invite(sd,RFIFOL(fd,2),-1);
  9132. clif_skill_fail(sd,1,0,4);
  9133. }
  9134. }
  9135. /*==========================================
  9136. * パーティ脱退要求
  9137. *------------------------------------------
  9138. */
  9139. void clif_parse_LeaveParty(int fd, struct map_session_data *sd) {
  9140. party_leave(sd);
  9141. }
  9142. /*==========================================
  9143. * パーティ除名要求
  9144. *------------------------------------------
  9145. */
  9146. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd) {
  9147. RFIFOHEAD(fd);
  9148. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  9149. }
  9150. /*==========================================
  9151. * パーティ設定変更要求
  9152. *------------------------------------------
  9153. */
  9154. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd) {
  9155. RFIFOHEAD(fd);
  9156. party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  9157. }
  9158. /*==========================================
  9159. * パーティメッセージ送信要求
  9160. *------------------------------------------
  9161. */
  9162. void clif_parse_PartyMessage(int fd, struct map_session_data *sd) {
  9163. RFIFOHEAD(fd);
  9164. if (is_charcommand(fd, sd, (char*)RFIFOP(fd,4), 0) != CharCommand_None ||
  9165. is_atcommand(fd, sd, (char*)RFIFOP(fd,4), 0) != AtCommand_None)
  9166. return;
  9167. if (sd->sc.count && (
  9168. sd->sc.data[SC_BERSERK].timer!=-1 || //バーサーク時は会話も不可
  9169. sd->sc.data[SC_NOCHAT].timer!=-1 //チャット禁止
  9170. ))
  9171. return;
  9172. party_send_message(sd, (char*)RFIFOP(fd,4), RFIFOW(fd,2)-4);
  9173. }
  9174. /*==========================================
  9175. * 露店閉鎖
  9176. *------------------------------------------
  9177. */
  9178. void clif_parse_CloseVending(int fd, struct map_session_data *sd) {
  9179. vending_closevending(sd);
  9180. }
  9181. /*==========================================
  9182. * 露店アイテムリスト要求
  9183. *------------------------------------------
  9184. */
  9185. void clif_parse_VendingListReq(int fd, struct map_session_data *sd) {
  9186. RFIFOHEAD(fd);
  9187. vending_vendinglistreq(sd,RFIFOL(fd,2));
  9188. if(sd->npc_id)
  9189. npc_event_dequeue(sd);
  9190. }
  9191. /*==========================================
  9192. * 露店アイテム購入
  9193. *------------------------------------------
  9194. */
  9195. void clif_parse_PurchaseReq(int fd, struct map_session_data *sd) {
  9196. RFIFOHEAD(fd);
  9197. if (sd->trade_partner != 0)
  9198. return;
  9199. vending_purchasereq(sd, RFIFOW(fd,2), RFIFOL(fd,4), RFIFOP(fd,8));
  9200. }
  9201. /*==========================================
  9202. * 露店開設
  9203. *------------------------------------------
  9204. */
  9205. void clif_parse_OpenVending(int fd,struct map_session_data *sd) {
  9206. RFIFOHEAD(fd);
  9207. if (sd->trade_partner != 0)
  9208. return;
  9209. vending_openvending(sd, RFIFOW(fd,2), (char*)RFIFOP(fd,4), RFIFOB(fd,84), RFIFOP(fd,85));
  9210. }
  9211. /*==========================================
  9212. * ギルドを作る
  9213. *------------------------------------------
  9214. */
  9215. void clif_parse_CreateGuild(int fd,struct map_session_data *sd) {
  9216. RFIFOHEAD(fd);
  9217. guild_create(sd, (char*)RFIFOP(fd,6));
  9218. }
  9219. /*==========================================
  9220. * ギルドマスターかどうか確認
  9221. *------------------------------------------
  9222. */
  9223. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd) {
  9224. clif_guild_masterormember(sd);
  9225. }
  9226. /*==========================================
  9227. * ギルド情報要求
  9228. *------------------------------------------
  9229. */
  9230. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd) {
  9231. RFIFOHEAD(fd);
  9232. switch(RFIFOL(fd,2)){
  9233. case 0: // ギルド基本情報、同盟敵対情報
  9234. clif_guild_basicinfo(sd);
  9235. clif_guild_allianceinfo(sd);
  9236. break;
  9237. case 1: // メンバーリスト、役職名リスト
  9238. clif_guild_positionnamelist(sd);
  9239. clif_guild_memberlist(sd);
  9240. break;
  9241. case 2: // 役職名リスト、役職情報リスト
  9242. clif_guild_positionnamelist(sd);
  9243. clif_guild_positioninfolist(sd);
  9244. break;
  9245. case 3: // スキルリスト
  9246. clif_guild_skillinfo(sd);
  9247. break;
  9248. case 4: // 追放リスト
  9249. clif_guild_explusionlist(sd);
  9250. break;
  9251. default:
  9252. if (battle_config.error_log)
  9253. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  9254. break;
  9255. }
  9256. }
  9257. /*==========================================
  9258. * ギルド役職変更
  9259. *------------------------------------------
  9260. */
  9261. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd) {
  9262. int i;
  9263. RFIFOHEAD(fd);
  9264. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  9265. guild_change_position(sd, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  9266. }
  9267. }
  9268. /*==========================================
  9269. * ギルドメンバ役職変更
  9270. *------------------------------------------
  9271. */
  9272. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd) {
  9273. int i;
  9274. RFIFOHEAD(fd);
  9275. for(i=4;i<RFIFOW(fd,2);i+=12){
  9276. guild_change_memberposition(sd->status.guild_id,
  9277. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  9278. }
  9279. }
  9280. /*==========================================
  9281. * ギルドエンブレム要求
  9282. *------------------------------------------
  9283. */
  9284. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd) {
  9285. struct guild *g;
  9286. RFIFOHEAD(fd);
  9287. g=guild_search(RFIFOL(fd,2));
  9288. if(g!=NULL)
  9289. clif_guild_emblem(sd,g);
  9290. }
  9291. /*==========================================
  9292. * ギルドエンブレム変更
  9293. *------------------------------------------
  9294. */
  9295. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd) {
  9296. RFIFOHEAD(fd);
  9297. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  9298. }
  9299. /*==========================================
  9300. * ギルド告知変更
  9301. *------------------------------------------
  9302. */
  9303. void clif_parse_GuildChangeNotice(int fd,struct map_session_data *sd) {
  9304. RFIFOHEAD(fd);
  9305. guild_change_notice(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6),(char*)RFIFOP(fd,66));
  9306. }
  9307. /*==========================================
  9308. * ギルド勧誘
  9309. *------------------------------------------
  9310. */
  9311. void clif_parse_GuildInvite(int fd,struct map_session_data *sd) {
  9312. RFIFOHEAD(fd);
  9313. guild_invite(sd,RFIFOL(fd,2));
  9314. }
  9315. /*==========================================
  9316. * ギルド勧誘返信
  9317. *------------------------------------------
  9318. */
  9319. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd) {
  9320. RFIFOHEAD(fd);
  9321. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9322. }
  9323. /*==========================================
  9324. * ギルド脱退
  9325. *------------------------------------------
  9326. */
  9327. void clif_parse_GuildLeave(int fd,struct map_session_data *sd) {
  9328. RFIFOHEAD(fd);
  9329. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9330. }
  9331. /*==========================================
  9332. * ギルド追放
  9333. *------------------------------------------
  9334. */
  9335. void clif_parse_GuildExplusion(int fd,struct map_session_data *sd) {
  9336. RFIFOHEAD(fd);
  9337. guild_explusion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9338. }
  9339. /*==========================================
  9340. * ギルド会話
  9341. *------------------------------------------
  9342. */
  9343. void clif_parse_GuildMessage(int fd,struct map_session_data *sd) {
  9344. RFIFOHEAD(fd);
  9345. if (is_charcommand(fd, sd, (char*)RFIFOP(fd, 4), 0) != CharCommand_None ||
  9346. is_atcommand(fd, sd, (char*)RFIFOP(fd, 4), 0) != AtCommand_None)
  9347. return;
  9348. if (sd->sc.count && (
  9349. sd->sc.data[SC_BERSERK].timer!=-1 || //バーサーク時は会話も不可
  9350. sd->sc.data[SC_NOCHAT].timer!=-1 //チャット禁止
  9351. ))
  9352. return;
  9353. guild_send_message(sd, (char*)RFIFOP(fd,4), RFIFOW(fd,2)-4);
  9354. }
  9355. /*==========================================
  9356. * ギルド同盟要求
  9357. *------------------------------------------
  9358. */
  9359. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd) {
  9360. RFIFOHEAD(fd);
  9361. guild_reqalliance(sd,RFIFOL(fd,2));
  9362. }
  9363. /*==========================================
  9364. * ギルド同盟要求返信
  9365. *------------------------------------------
  9366. */
  9367. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd) {
  9368. RFIFOHEAD(fd);
  9369. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9370. }
  9371. /*==========================================
  9372. * ギルド関係解消
  9373. *------------------------------------------
  9374. */
  9375. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd) {
  9376. RFIFOHEAD(fd);
  9377. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9378. }
  9379. /*==========================================
  9380. * ギルド敵対
  9381. *------------------------------------------
  9382. */
  9383. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd) {
  9384. RFIFOHEAD(fd);
  9385. guild_opposition(sd,RFIFOL(fd,2));
  9386. }
  9387. /*==========================================
  9388. * ギルド解散
  9389. *------------------------------------------
  9390. */
  9391. void clif_parse_GuildBreak(int fd, struct map_session_data *sd) {
  9392. RFIFOHEAD(fd);
  9393. guild_break(sd,(char*)RFIFOP(fd,2));
  9394. }
  9395. // pet
  9396. void clif_parse_PetMenu(int fd, struct map_session_data *sd) {
  9397. RFIFOHEAD(fd);
  9398. pet_menu(sd,RFIFOB(fd,2));
  9399. }
  9400. void clif_parse_CatchPet(int fd, struct map_session_data *sd) {
  9401. RFIFOHEAD(fd);
  9402. pet_catch_process2(sd,RFIFOL(fd,2));
  9403. }
  9404. void clif_parse_SelectEgg(int fd, struct map_session_data *sd) {
  9405. RFIFOHEAD(fd);
  9406. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9407. }
  9408. void clif_parse_SendEmotion(int fd, struct map_session_data *sd) {
  9409. if(sd->pd) {
  9410. RFIFOHEAD(fd);
  9411. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9412. }
  9413. }
  9414. void clif_parse_ChangePetName(int fd, struct map_session_data *sd) {
  9415. RFIFOHEAD(fd);
  9416. pet_change_name(sd,(char*)RFIFOP(fd,2));
  9417. }
  9418. // Kick (right click menu for GM "(name) force to quit")
  9419. void clif_parse_GMKick(int fd, struct map_session_data *sd) {
  9420. struct block_list *target;
  9421. int tid;
  9422. RFIFOHEAD(fd);
  9423. tid = RFIFOL(fd,2);
  9424. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9425. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Kick))) {
  9426. target = map_id2bl(tid);
  9427. if (target) {
  9428. if (target->type == BL_PC) {
  9429. struct map_session_data *tsd = (struct map_session_data *)target;
  9430. if (pc_isGM(sd) > pc_isGM(tsd))
  9431. clif_GM_kick(sd, tsd, 1);
  9432. else
  9433. clif_GM_kickack(sd, 0);
  9434. } else if (target->type == BL_MOB) {
  9435. struct mob_data *md = (struct mob_data *)target;
  9436. sd->state.attack_type = 0;
  9437. mob_damage(&sd->bl, md, md->hp, 2);
  9438. } else
  9439. clif_GM_kickack(sd, 0);
  9440. } else
  9441. clif_GM_kickack(sd, 0);
  9442. }
  9443. }
  9444. /*==========================================
  9445. * /shift
  9446. *------------------------------------------
  9447. */
  9448. void clif_parse_Shift(int fd, struct map_session_data *sd) { // Rewriten by [Yor]
  9449. char player_name[NAME_LENGTH+1];
  9450. memset(player_name, '\0', sizeof(player_name));
  9451. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9452. (pc_isGM(sd) >= get_atcommand_level(AtCommand_JumpTo))) {
  9453. RFIFOHEAD(fd);
  9454. memcpy(player_name, RFIFOP(fd,2), NAME_LENGTH);
  9455. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9456. }
  9457. return;
  9458. }
  9459. /*==========================================
  9460. * /recall
  9461. *------------------------------------------
  9462. */
  9463. void clif_parse_Recall(int fd, struct map_session_data *sd) { // Added by RoVeRT
  9464. char player_name[25];
  9465. memset(player_name, '\0', sizeof(player_name));
  9466. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9467. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Recall))) {
  9468. RFIFOHEAD(fd);
  9469. memcpy(player_name, RFIFOP(fd,2), NAME_LENGTH);
  9470. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9471. }
  9472. return;
  9473. }
  9474. /*==========================================
  9475. * /monster /item rewriten by [Yor]
  9476. *------------------------------------------
  9477. */
  9478. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd) {
  9479. char monster_item_name[NAME_LENGTH+10]; //Additional space is for logging, eg: "@monster Poring"
  9480. int level;
  9481. memset(monster_item_name, '\0', sizeof(monster_item_name));
  9482. if (battle_config.atc_gmonly == 0 || pc_isGM(sd)) {
  9483. RFIFOHEAD(fd);
  9484. memcpy(monster_item_name, RFIFOP(fd,2), NAME_LENGTH);
  9485. if (mobdb_searchname(monster_item_name) != 0) {
  9486. if (pc_isGM(sd) >= (level =get_atcommand_level(AtCommand_Monster)))
  9487. {
  9488. atcommand_monster(fd, sd, "@spawn", monster_item_name); // as @spawn
  9489. if(log_config.gm && level >= log_config.gm)
  9490. { //Log action. [Skotlex]
  9491. snprintf(monster_item_name, sizeof(monster_item_name)-1, "@spawn %s", RFIFOP(fd,2));
  9492. log_atcommand(sd, monster_item_name);
  9493. }
  9494. }
  9495. } else if (itemdb_searchname(monster_item_name) != NULL) {
  9496. if (pc_isGM(sd) >= (level = get_atcommand_level(AtCommand_Item)))
  9497. {
  9498. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9499. if(log_config.gm && level >= log_config.gm)
  9500. { //Log action. [Skotlex]
  9501. snprintf(monster_item_name, sizeof(monster_item_name)-1, "@item %s", RFIFOP(fd,2));
  9502. log_atcommand(sd, monster_item_name);
  9503. }
  9504. }
  9505. }
  9506. }
  9507. }
  9508. void clif_parse_GMHide(int fd, struct map_session_data *sd) { // Modified by [Yor]
  9509. if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
  9510. (pc_isGM(sd) >= get_atcommand_level(AtCommand_Hide))) {
  9511. if (sd->sc.option & OPTION_INVISIBLE) {
  9512. sd->sc.option &= ~OPTION_INVISIBLE;
  9513. clif_displaymessage(fd, "Invisible: Off.");
  9514. } else {
  9515. sd->sc.option |= OPTION_INVISIBLE;
  9516. clif_displaymessage(fd, "Invisible: On.");
  9517. }
  9518. clif_changeoption(&sd->bl);
  9519. }
  9520. }
  9521. /*==========================================
  9522. * GMによるチャット禁止時間付与
  9523. *------------------------------------------
  9524. */
  9525. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9526. {
  9527. int type, limit, level;
  9528. struct block_list *bl;
  9529. struct map_session_data *dstsd;
  9530. if(!battle_config.muting_players) {
  9531. clif_displaymessage(fd, "Muting is disabled.");
  9532. return;
  9533. }
  9534. RFIFOHEAD(fd);
  9535. bl = map_id2bl(RFIFOL(fd,2));
  9536. if (!bl || bl->type != BL_PC)
  9537. return;
  9538. nullpo_retv(dstsd =(struct map_session_data *)bl);
  9539. type = RFIFOB(fd,6);
  9540. limit = RFIFOW(fd,7);
  9541. if (type == 0)
  9542. limit = 0 - limit;
  9543. //Temporarily disable chars from muting themselves due to the mysterious "DON'T USE BOT!" message. [Skotlex]
  9544. //Also, if type is 2 and the ids don't match, this is a crafted hacked packet!
  9545. //So for now, type 2is just totally disabled.
  9546. if (type == 2/*&& sd->bl.id != dstsd->bl.id*/)
  9547. return;
  9548. if (
  9549. ((level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(AtCommand_Mute))
  9550. || (type == 2 && !level)) {
  9551. clif_GM_silence(sd, dstsd, ((type == 2) ? 1 : type));
  9552. if (battle_config.manner_system)
  9553. {
  9554. dstsd->status.manner -= limit;
  9555. if(dstsd->status.manner < 0)
  9556. status_change_start(bl,SC_NOCHAT,100,0,0,0,0,0,0);
  9557. else
  9558. {
  9559. dstsd->status.manner = 0;
  9560. status_change_end(bl,SC_NOCHAT,-1);
  9561. }
  9562. }
  9563. ShowDebug("GMReqNoChat: name:%s type:%d limit:%d manner:%d\n", dstsd->status.name, type, limit, dstsd->status.manner);
  9564. }
  9565. return;
  9566. }
  9567. /*==========================================
  9568. * GMによるチャット禁止時間参照(?)
  9569. *------------------------------------------
  9570. */
  9571. void clif_parse_GMReqNoChatCount(int fd, struct map_session_data *sd)
  9572. {
  9573. int tid;
  9574. RFIFOHEAD(fd);
  9575. tid = RFIFOL(fd,2);
  9576. WFIFOHEAD(fd,packet_len_table[0x1e0]);
  9577. WFIFOW(fd,0) = 0x1e0;
  9578. WFIFOL(fd,2) = tid;
  9579. sprintf((char*)WFIFOP(fd,6),"%d",tid);
  9580. // memcpy(WFIFOP(fd,6), "TESTNAME", 24);
  9581. WFIFOSET(fd, packet_len_table[0x1e0]);
  9582. return;
  9583. }
  9584. void clif_parse_PMIgnore(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9585. char output[512];
  9586. char *nick; // S 00cf <nick>.24B <type>.B: 00 (/ex nick) deny speech from nick, 01 (/in nick) allow speech from nick
  9587. int i, pos;
  9588. RFIFOHEAD(fd);
  9589. memset(output, '\0', sizeof(output));
  9590. nick = (char*)RFIFOP(fd,2); // speed up
  9591. RFIFOB(fd,NAME_LENGTH+1) = '\0'; // to be sure that the player name have at maximum 23 characters (nick range: [2]->[26])
  9592. //printf("Ignore: char '%s' state: %d\n", nick, RFIFOB(fd,26));
  9593. WFIFOHEAD(fd,packet_len_table[0xd1]);
  9594. WFIFOW(fd,0) = 0x0d1; // R 00d1 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9595. WFIFOB(fd,2) = RFIFOB(fd,26);
  9596. // do nothing only if nick can not exist
  9597. if (strlen(nick) < 4) {
  9598. WFIFOB(fd,3) = 1; // fail
  9599. WFIFOSET(fd, packet_len_table[0x0d1]);
  9600. if (RFIFOB(fd,26) == 0) // type
  9601. clif_wis_message(fd, wisp_server_name, "It's impossible to block this player.", strlen("It's impossible to block this player.") + 1);
  9602. else
  9603. clif_wis_message(fd, wisp_server_name, "It's impossible to unblock this player.", strlen("It's impossible to unblock this player.") + 1);
  9604. return;
  9605. // name can exist
  9606. } else {
  9607. // deny action (we add nick only if it's not already exist
  9608. if (RFIFOB(fd,26) == 0) { // type
  9609. pos = -1;
  9610. for(i = 0; i < MAX_IGNORE_LIST; i++) {
  9611. if (strcmp(sd->ignore[i].name, nick) == 0) {
  9612. WFIFOB(fd,3) = 1; // fail
  9613. WFIFOSET(fd, packet_len_table[0x0d1]);
  9614. clif_wis_message(fd, wisp_server_name, "This player is already blocked.", strlen("This player is already blocked.") + 1);
  9615. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9616. 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);
  9617. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9618. }
  9619. return;
  9620. } else if (pos == -1 && sd->ignore[i].name[0] == '\0')
  9621. pos = i;
  9622. }
  9623. // if a position is found and name not found, we add it in the list
  9624. if (pos != -1) {
  9625. memcpy(sd->ignore[pos].name, nick, NAME_LENGTH-1);
  9626. WFIFOB(fd,3) = 0; // success
  9627. WFIFOSET(fd, packet_len_table[0x0d1]);
  9628. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9629. 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);
  9630. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9631. // send something to be inform and force bot to ignore twice... If GM receiving block + block again, it's a bot :)
  9632. clif_wis_message(fd, wisp_server_name, "Add me in your ignore list, doesn't block my wisps.", strlen("Add me in your ignore list, doesn't block my wisps.") + 1);
  9633. }
  9634. } else {
  9635. WFIFOB(fd,3) = 1; // fail
  9636. WFIFOSET(fd, packet_len_table[0x0d1]);
  9637. clif_wis_message(fd, wisp_server_name, "You can not block more people.", strlen("You can not block more people.") + 1);
  9638. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9639. 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);
  9640. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9641. }
  9642. }
  9643. // allow action (we remove all same nicks if they exist)
  9644. } else {
  9645. pos = -1;
  9646. for(i = 0; i < MAX_IGNORE_LIST; i++)
  9647. if (strcmp(sd->ignore[i].name, nick) == 0) {
  9648. memset(sd->ignore[i].name, 0, sizeof(sd->ignore[i].name));
  9649. if (pos == -1) {
  9650. WFIFOB(fd,3) = 0; // success
  9651. WFIFOSET(fd, packet_len_table[0x0d1]);
  9652. pos = i; // don't break, to remove ALL same nick
  9653. }
  9654. }
  9655. if (pos == -1) {
  9656. WFIFOB(fd,3) = 1; // fail
  9657. WFIFOSET(fd, packet_len_table[0x0d1]);
  9658. clif_wis_message(fd, wisp_server_name, "This player is not blocked by you.", strlen("This player is not blocked by you.") + 1);
  9659. }
  9660. }
  9661. }
  9662. // for(i = 0; i < MAX_IGNORE_LIST; i++) // for debug only
  9663. // if (sd->ignore[i].name[0] != '\0')
  9664. // printf("Ignored player: '%s'\n", sd->ignore[i].name);
  9665. return;
  9666. }
  9667. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9668. //printf("Ignore all: state: %d\n", RFIFOB(fd,2));
  9669. RFIFOHEAD(fd);
  9670. if (RFIFOB(fd,2) == 0) {// S 00d0 <type>len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech
  9671. WFIFOHEAD(fd,packet_len_table[0xd2]);
  9672. WFIFOW(fd,0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9673. WFIFOB(fd,2) = 0;
  9674. if (sd->ignoreAll == 0) {
  9675. sd->ignoreAll = 1;
  9676. WFIFOB(fd,3) = 0; // success
  9677. WFIFOSET(fd, packet_len_table[0x0d2]);
  9678. } else {
  9679. WFIFOB(fd,3) = 1; // fail
  9680. WFIFOSET(fd, packet_len_table[0x0d2]);
  9681. clif_wis_message(fd, wisp_server_name, "You already block everyone.", strlen("You already block everyone.") + 1);
  9682. }
  9683. } else {
  9684. WFIFOHEAD(fd,packet_len_table[0xd2]);
  9685. WFIFOW(fd,0) = 0x0d2; // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9686. WFIFOB(fd,2) = 1;
  9687. if (sd->ignoreAll == 1) {
  9688. sd->ignoreAll = 0;
  9689. WFIFOB(fd,3) = 0; // success
  9690. WFIFOSET(fd, packet_len_table[0x0d2]);
  9691. } else {
  9692. WFIFOB(fd,3) = 1; // fail
  9693. WFIFOSET(fd, packet_len_table[0x0d2]);
  9694. clif_wis_message(fd, wisp_server_name, "You already allow everyone.", strlen("You already allow everyone.") + 1);
  9695. }
  9696. }
  9697. return;
  9698. }
  9699. /*==========================================
  9700. * Wis拒否リスト
  9701. *------------------------------------------
  9702. */
  9703. int pstrcmp(const void *a, const void *b)
  9704. {
  9705. return strcmp((char *)a, (char *)b);
  9706. }
  9707. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9708. {
  9709. int i,j=0,count=0;
  9710. qsort (sd->ignore[0].name, MAX_IGNORE_LIST, sizeof(sd->ignore[0].name), pstrcmp);
  9711. for(i = 0; i < MAX_IGNORE_LIST; i++){ //中身があるのを数える
  9712. if(sd->ignore[i].name[0] != 0)
  9713. count++;
  9714. }
  9715. WFIFOHEAD(fd, 4 + (NAME_LENGTH * count));
  9716. WFIFOW(fd,0) = 0xd4;
  9717. WFIFOW(fd,2) = 4 + (NAME_LENGTH * count);
  9718. for(i = 0; i < MAX_IGNORE_LIST; i++){
  9719. if(sd->ignore[i].name[0] != 0){
  9720. memcpy(WFIFOP(fd, 4 + j * 24),sd->ignore[i].name, NAME_LENGTH);
  9721. j++;
  9722. }
  9723. }
  9724. WFIFOSET(fd, WFIFOW(fd,2));
  9725. if(count >= MAX_IGNORE_LIST) //満タンなら最後の1個を消す
  9726. sd->ignore[MAX_IGNORE_LIST - 1].name[0] = 0;
  9727. return;
  9728. }
  9729. /*==========================================
  9730. * スパノビの/doridoriによるSPR2倍
  9731. *------------------------------------------
  9732. */
  9733. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd) {
  9734. int level;
  9735. sd->doridori_counter = 1;
  9736. if ((sd->class_&MAPID_UPPERMASK) == MAPID_TAEKWON
  9737. && sd->state.rest && (level = pc_checkskill(sd,TK_SPTIME)))
  9738. status_change_start(&sd->bl,SkillStatusChangeTable[TK_SPTIME],100,level,0,0,0,skill_get_time(TK_SPTIME, level),0);
  9739. return;
  9740. }
  9741. /*==========================================
  9742. * スパノビの爆裂波動
  9743. *------------------------------------------
  9744. */
  9745. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9746. {
  9747. if(sd){
  9748. int nextbaseexp=pc_nextbaseexp(sd);
  9749. if (battle_config.etc_log){
  9750. if(nextbaseexp != 0)
  9751. 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));
  9752. else
  9753. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9754. }
  9755. 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){
  9756. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9757. status_change_start(&sd->bl,SkillStatusChangeTable[MO_EXPLOSIONSPIRITS],100,
  9758. 5,0,0,0,skill_get_time(MO_EXPLOSIONSPIRITS,5),0));
  9759. }
  9760. }
  9761. return;
  9762. }
  9763. // random notes:
  9764. // 0x214: monster/player info ?
  9765. /*==========================================
  9766. * Friends List
  9767. *------------------------------------------
  9768. */
  9769. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9770. { //Toggles a single friend online/offline [Skotlex]
  9771. int i;
  9772. //Seek friend.
  9773. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9774. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9775. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9776. return; //Not found
  9777. WFIFOHEAD(sd->fd,packet_len_table[0x206]);
  9778. WFIFOW(sd->fd, 0) = 0x206;
  9779. WFIFOL(sd->fd, 2) = sd->status.friends[i].account_id;
  9780. WFIFOL(sd->fd, 6) = sd->status.friends[i].char_id;
  9781. WFIFOB(sd->fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9782. WFIFOSET(sd->fd, packet_len_table[0x206]);
  9783. }
  9784. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9785. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9786. {
  9787. int account_id, char_id, online;
  9788. account_id = va_arg(ap, int);
  9789. char_id = va_arg(ap, int);
  9790. online = va_arg(ap, int);
  9791. clif_friendslist_toggle(sd, account_id, char_id, online);
  9792. return 0;
  9793. }
  9794. //For sending the whole friends list.
  9795. void clif_friendslist_send(struct map_session_data *sd) {
  9796. int i = 0, n;
  9797. // Send friends list
  9798. WFIFOHEAD(sd->fd, MAX_FRIENDS * 32 + 4);
  9799. WFIFOW(sd->fd, 0) = 0x201;
  9800. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9801. {
  9802. WFIFOL(sd->fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9803. WFIFOL(sd->fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9804. memcpy(WFIFOP(sd->fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9805. }
  9806. WFIFOW(sd->fd,2) = 4 + 32 * i;
  9807. WFIFOSET(sd->fd, WFIFOW(sd->fd,2));
  9808. for (n = 0; n < i; n++)
  9809. { //Sending the online players
  9810. if (map_charid2sd(sd->status.friends[n].char_id))
  9811. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9812. }
  9813. }
  9814. // Status for adding friend - 0: successfull 1: not exist/rejected 2: over limit
  9815. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9816. {
  9817. int fd;
  9818. nullpo_retv(sd);
  9819. fd = sd->fd;
  9820. WFIFOHEAD(fd,packet_len_table[0x209]);
  9821. WFIFOW(fd,0) = 0x209;
  9822. WFIFOW(fd,2) = type;
  9823. if (f_sd)
  9824. {
  9825. WFIFOW(fd,4) = f_sd->status.account_id;
  9826. WFIFOW(fd,8) = f_sd->status.char_id;
  9827. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9828. }
  9829. WFIFOSET(fd, packet_len_table[0x209]);
  9830. }
  9831. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd) {
  9832. struct map_session_data *f_sd;
  9833. int i, f_fd;
  9834. RFIFOHEAD(fd);
  9835. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9836. // Friend doesn't exist (no player with this name)
  9837. if (f_sd == NULL) {
  9838. clif_displaymessage(fd, msg_txt(3));
  9839. return;
  9840. }
  9841. // Friend already exists
  9842. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9843. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9844. clif_displaymessage(fd, "Friend already exists.");
  9845. return;
  9846. }
  9847. }
  9848. if (i == MAX_FRIENDS) {
  9849. //No space, list full.
  9850. clif_friendslist_reqack(sd, f_sd, 2);
  9851. return;
  9852. }
  9853. f_fd = f_sd->fd;
  9854. WFIFOHEAD(fd,packet_len_table[0x207]);
  9855. WFIFOW(f_fd,0) = 0x207;
  9856. WFIFOL(f_fd,2) = sd->status.account_id;
  9857. WFIFOL(f_fd,6) = sd->status.char_id;
  9858. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9859. WFIFOSET(f_fd, packet_len_table[0x207]);
  9860. return;
  9861. }
  9862. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd) {
  9863. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9864. struct map_session_data *f_sd;
  9865. int char_id, account_id;
  9866. char reply;
  9867. RFIFOHEAD(fd);
  9868. account_id = RFIFOL(fd,2);
  9869. char_id = RFIFOL(fd,6);
  9870. reply = RFIFOB(fd,10);
  9871. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9872. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9873. if (f_sd == NULL)
  9874. return;
  9875. if (reply == 0)
  9876. clif_friendslist_reqack(f_sd, sd, 1);
  9877. else {
  9878. int i;
  9879. // Find an empty slot
  9880. for (i = 0; i < MAX_FRIENDS; i++)
  9881. if (f_sd->status.friends[i].char_id == 0)
  9882. break;
  9883. if (i == MAX_FRIENDS) {
  9884. clif_friendslist_reqack(f_sd, sd, 2);
  9885. return;
  9886. }
  9887. f_sd->status.friends[i].account_id = sd->status.account_id;
  9888. f_sd->status.friends[i].char_id = sd->status.char_id;
  9889. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9890. clif_friendslist_reqack(f_sd, sd, 0);
  9891. // clif_friendslist_send(sd); //This is not needed anymore.
  9892. }
  9893. return;
  9894. }
  9895. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd) {
  9896. // 0x203 </o> <ID to be removed W 4B>
  9897. int account_id, char_id;
  9898. int i, j;
  9899. RFIFOHEAD(fd);
  9900. account_id = RFIFOL(fd,2);
  9901. char_id = RFIFOL(fd,6);
  9902. // Search friend
  9903. for (i = 0; i < MAX_FRIENDS &&
  9904. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9905. if (i == MAX_FRIENDS) {
  9906. clif_displaymessage(fd, "Name not found in list.");
  9907. return;
  9908. }
  9909. // move all chars down
  9910. for(j = i + 1; j < MAX_FRIENDS; j++)
  9911. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9912. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9913. clif_displaymessage(fd, "Friend removed");
  9914. WFIFOHEAD(fd,packet_len_table[0x20a]);
  9915. WFIFOW(fd,0) = 0x20a;
  9916. WFIFOL(fd,2) = account_id;
  9917. WFIFOL(fd,6) = char_id;
  9918. WFIFOSET(fd, packet_len_table[0x20a]);
  9919. // clif_friendslist_send(sd); //This is not needed anymore.
  9920. return;
  9921. }
  9922. /*==========================================
  9923. * /killall
  9924. *------------------------------------------
  9925. */
  9926. void clif_parse_GMKillAll(int fd,struct map_session_data *sd)
  9927. {
  9928. char message[50];
  9929. strncpy(message,sd->status.name, NAME_LENGTH);
  9930. is_atcommand(fd, sd, strcat(message," : @kickall"),0);
  9931. return;
  9932. }
  9933. /*==========================================
  9934. * /pvpinfo
  9935. *------------------------------------------
  9936. */
  9937. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  9938. {
  9939. WFIFOHEAD(fd,packet_len_table[0x210]);
  9940. WFIFOW(fd,0) = 0x210;
  9941. //WFIFOL(fd,2) = 0; // not sure what for yet
  9942. //WFIFOL(fd,6) = 0;
  9943. WFIFOL(fd,10) = sd->pvp_won; // times won
  9944. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  9945. WFIFOL(fd,18) = sd->pvp_point;
  9946. WFIFOSET(fd, packet_len_table[0x210]);
  9947. return;
  9948. }
  9949. /*==========================================
  9950. * /blacksmith
  9951. *------------------------------------------
  9952. */
  9953. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  9954. {
  9955. int i;
  9956. char *name;
  9957. WFIFOHEAD(fd,packet_len_table[0x219]);
  9958. WFIFOW(fd,0) = 0x219;
  9959. for (i = 0; i < 10; i++) {
  9960. if (smith_fame_list[i].id > 0) {
  9961. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  9962. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  9963. {
  9964. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  9965. } else
  9966. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  9967. } else
  9968. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  9969. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  9970. }
  9971. WFIFOSET(fd, packet_len_table[0x219]);
  9972. }
  9973. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  9974. {
  9975. int fd = sd->fd;
  9976. WFIFOHEAD(fd,packet_len_table[0x21b]);
  9977. WFIFOW(fd,0) = 0x21b;
  9978. WFIFOL(fd,2) = points;
  9979. WFIFOL(fd,6) = sd->status.fame;
  9980. WFIFOSET(fd, packet_len_table[0x21b]);
  9981. return 0;
  9982. }
  9983. /*==========================================
  9984. * /alchemist
  9985. *------------------------------------------
  9986. */
  9987. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  9988. {
  9989. int i;
  9990. char *name;
  9991. WFIFOHEAD(fd,packet_len_table[0x21a]);
  9992. WFIFOW(fd,0) = 0x21a;
  9993. for (i = 0; i < 10; i++) {
  9994. if (chemist_fame_list[i].id > 0) {
  9995. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  9996. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  9997. {
  9998. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9999. } else
  10000. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  10001. } else
  10002. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10003. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  10004. }
  10005. WFIFOSET(fd, packet_len_table[0x21a]);
  10006. }
  10007. int clif_fame_alchemist(struct map_session_data *sd, int points)
  10008. {
  10009. int fd = sd->fd;
  10010. WFIFOHEAD(fd,packet_len_table[0x21c]);
  10011. WFIFOW(fd,0) = 0x21c;
  10012. WFIFOL(fd,2) = points;
  10013. WFIFOL(fd,6) = sd->status.fame;
  10014. WFIFOSET(fd, packet_len_table[0x21c]);
  10015. return 0;
  10016. }
  10017. /*==========================================
  10018. * /taekwon
  10019. *------------------------------------------
  10020. */
  10021. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  10022. {
  10023. int i;
  10024. char *name;
  10025. WFIFOHEAD(fd,packet_len_table[0x226]);
  10026. WFIFOW(fd,0) = 0x226;
  10027. for (i = 0; i < 10; i++) {
  10028. if (taekwon_fame_list[i].id > 0) {
  10029. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  10030. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  10031. {
  10032. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10033. } else
  10034. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  10035. } else
  10036. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10037. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  10038. }
  10039. WFIFOSET(fd, packet_len_table[0x226]);
  10040. }
  10041. int clif_fame_taekwon(struct map_session_data *sd, int points)
  10042. {
  10043. int fd = sd->fd;
  10044. WFIFOHEAD(fd,packet_len_table[0x224]);
  10045. WFIFOW(fd,0) = 0x224;
  10046. WFIFOL(fd,2) = points;
  10047. WFIFOL(fd,6) = sd->status.fame;
  10048. WFIFOSET(fd, packet_len_table[0x224]);
  10049. return 0;
  10050. }
  10051. /*==========================================
  10052. * PK Ranking table?
  10053. *------------------------------------------
  10054. */
  10055. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  10056. {
  10057. int i;
  10058. WFIFOHEAD(fd,packet_len_table[0x238]);
  10059. WFIFOW(fd,0) = 0x238;
  10060. for(i=0;i<10;i++){
  10061. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  10062. WFIFOL(fd,i*4+242) = 0;
  10063. }
  10064. WFIFOSET(fd, packet_len_table[0x238]);
  10065. return;
  10066. }
  10067. /*==========================================
  10068. * SG Feel save OK [Komurka]
  10069. *------------------------------------------
  10070. */
  10071. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  10072. {
  10073. if (sd->feel_level!=-1)
  10074. {
  10075. char feel_var[3][NAME_LENGTH] = {"PC_FEEL_SUN","PC_FEEL_MOON","PC_FEEL_STAR"};
  10076. sd->feel_map[sd->feel_level].index = map[sd->bl.m].index;
  10077. sd->feel_map[sd->feel_level].m = sd->bl.m;
  10078. pc_setglobalreg(sd,feel_var[sd->feel_level],map[sd->bl.m].index);
  10079. WFIFOHEAD(fd,packet_len_table[0x20e]);
  10080. WFIFOW(fd,0)=0x20e;
  10081. memcpy(WFIFOP(fd,2),map[sd->bl.m].name, MAP_NAME_LENGTH);
  10082. WFIFOL(fd,26)=sd->bl.id;
  10083. WFIFOW(fd,30)=sd->feel_level;
  10084. WFIFOSET(fd, packet_len_table[0x20e]);
  10085. sd->feel_level = -1;
  10086. if (pc_checkskill(sd,SG_KNOWLEDGE)) status_calc_pc(sd,0);
  10087. }
  10088. }
  10089. /*==========================================
  10090. * Question about Star Glaldiator save map [Komurka]
  10091. *------------------------------------------
  10092. */
  10093. void clif_parse_ReqFeel(int fd, struct map_session_data *sd) {
  10094. WFIFOHEAD(fd,packet_len_table[0x253]);
  10095. WFIFOW(fd,0)=0x253;
  10096. WFIFOSET(fd, packet_len_table[0x253]);
  10097. }
  10098. /*==========================================
  10099. * パケットデバッグ
  10100. *------------------------------------------
  10101. */
  10102. void clif_parse_debug(int fd,struct map_session_data *sd)
  10103. {
  10104. int i, cmd, len;
  10105. RFIFOHEAD(fd);
  10106. cmd = RFIFOW(fd,0);
  10107. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  10108. ShowDebug("packet debug 0x%4X\n",cmd);
  10109. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10110. for(i=0;i<len;i++){
  10111. if((i&15)==0)
  10112. printf("\n%04X ",i);
  10113. printf("%02X ",RFIFOB(fd,i));
  10114. }
  10115. printf("\n");
  10116. }
  10117. /*==========================================
  10118. * クライアントからのパケット解析
  10119. * socket.cのdo_parsepacketから呼び出される
  10120. *------------------------------------------
  10121. */
  10122. int clif_parse(int fd) {
  10123. int packet_len = 0, cmd, packet_ver, dump = 0;
  10124. struct map_session_data *sd;
  10125. RFIFOHEAD(fd);
  10126. if (fd <= 0)
  10127. { //Just in case, there are some checks for this later down below anyway which should be removed. [Skotlex]
  10128. ShowError("clif_parse: Received invalid session %d\n", fd);
  10129. return 0;
  10130. }
  10131. sd = (struct map_session_data*)session[fd]->session_data;
  10132. // 接続が切れてるので後始末
  10133. if (!chrif_isconnect() && kick_on_disconnect)
  10134. {
  10135. ShowInfo("Closing session #%d (Not connected to Char server)\n", fd);
  10136. if (sd && sd->state.auth)
  10137. clif_quitsave(fd, sd); // the function doesn't send to inter-server/char-server if it is not connected [Yor]
  10138. do_close(fd);
  10139. return 0;
  10140. } else
  10141. if (session[fd]->eof) {
  10142. if (sd && sd->state.autotrade) {
  10143. //Disassociate character from the socket connection.
  10144. session[fd]->session_data = NULL;
  10145. sd->fd = 0;
  10146. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"",sd->status.name); // Player logout display [Valaris]
  10147. } else if (sd && sd->state.auth) {
  10148. clif_quitsave(fd, sd); // the function doesn't send to inter-server/char-server if it is not connected [Yor]
  10149. if (sd->status.name != NULL)
  10150. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"",sd->status.name); // Player logout display [Valaris]
  10151. else
  10152. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id); // Player logout display [Yor]
  10153. } else {
  10154. unsigned char *ip = (unsigned char *) &session[fd]->client_addr.sin_addr;
  10155. ShowInfo("Player not identified with IP '"CL_WHITE"%d.%d.%d.%d"CL_RESET"' logged off.\n", ip[0],ip[1],ip[2],ip[3]);
  10156. }
  10157. do_close(fd);
  10158. return 0;
  10159. }
  10160. if (RFIFOREST(fd) < 2)
  10161. return 0;
  10162. // printf("clif_parse: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
  10163. cmd = RFIFOW(fd,0);
  10164. // 管理用パケット処理
  10165. if (cmd >= 30000) {
  10166. switch(cmd) {
  10167. case 0x7530: { // Athena情報所得
  10168. WFIFOHEAD(fd, 10);
  10169. WFIFOW(fd,0) = 0x7531;
  10170. WFIFOB(fd,2) = ATHENA_MAJOR_VERSION;
  10171. WFIFOB(fd,3) = ATHENA_MINOR_VERSION;
  10172. WFIFOB(fd,4) = ATHENA_REVISION;
  10173. WFIFOB(fd,5) = ATHENA_RELEASE_FLAG;
  10174. WFIFOB(fd,6) = ATHENA_OFFICIAL_FLAG;
  10175. WFIFOB(fd,7) = ATHENA_SERVER_MAP;
  10176. WFIFOW(fd,8) = ATHENA_MOD_VERSION;
  10177. WFIFOSET(fd,10);
  10178. RFIFOSKIP(fd,2);
  10179. break;
  10180. }
  10181. case 0x7532: // 接続の切断
  10182. ShowWarning("clif_parse: session #%d disconnected for sending packet 0x04%x\n", fd, cmd);
  10183. session[fd]->eof=1;
  10184. break;
  10185. }
  10186. ShowWarning("Ignoring incoming packet (command: 0x%04x, session: %d)\n", cmd, fd);
  10187. return 0;
  10188. }
  10189. // get packet version before to parse
  10190. packet_ver = 0;
  10191. if (sd) {
  10192. packet_ver = sd->packet_ver;
  10193. if (packet_ver < 0 || packet_ver > MAX_PACKET_VER) { // This should never happen unless we have some corrupted memory issues :X [Skotlex]
  10194. session[fd]->eof = 1;
  10195. return 0;
  10196. }
  10197. } else {
  10198. // check authentification packet to know packet version
  10199. packet_ver = clif_guess_PacketVer(fd, 0);
  10200. // check if version is accepted
  10201. if (packet_ver < 5 || // reject really old client versions
  10202. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  10203. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0) ||
  10204. packet_ver > MAX_PACKET_VER) // no packet version support yet
  10205. {
  10206. ShowInfo("clif_parse: Disconnecting session #%d for not having latest client version (has version %d).\n", fd, packet_ver);
  10207. WFIFOHEAD(fd, 23);
  10208. WFIFOW(fd,0) = 0x6a;
  10209. WFIFOB(fd,2) = 5; // 05 = Game's EXE is not the latest version
  10210. WFIFOSET(fd,23);
  10211. packet_len = RFIFOREST(fd);
  10212. RFIFOSKIP(fd, packet_len);
  10213. clif_setwaitclose(fd);
  10214. if (session[fd]->func_send) //socket.c doesn't wants to send the data when left on it's own... [Skotlex]
  10215. session[fd]->func_send(fd);
  10216. return 0;
  10217. }
  10218. }
  10219. // ゲーム用以外パケットか、認証を終える前に0072以外が来たら、切断する
  10220. 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
  10221. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  10222. session[fd]->eof = 1;
  10223. return 0;
  10224. }
  10225. // パケット長を計算
  10226. packet_len = packet_db[packet_ver][cmd].len;
  10227. if (packet_len == -1) {
  10228. if (RFIFOREST(fd) < 4)
  10229. return 0; // 可変長パケットで長さの所までデータが来てない
  10230. packet_len = RFIFOW(fd,2);
  10231. if (packet_len < 4 || packet_len > 32768) {
  10232. ShowWarning("clif_parse: Packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  10233. session[fd]->eof =1;
  10234. return 0;
  10235. }
  10236. }
  10237. if ((int)RFIFOREST(fd) < packet_len)
  10238. return 0; // まだ1パケット分データが揃ってない
  10239. #if DUMP_ALL_PACKETS
  10240. dump = 1;
  10241. #endif
  10242. if (sd && sd->state.auth == 1 && sd->state.waitingdisconnect == 1) { // 切断待ちの場合パケットを処理しない
  10243. } else if (packet_db[packet_ver][cmd].func) {
  10244. if (sd
  10245. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  10246. || packet_db[packet_ver][cmd].func == clif_parse_debug
  10247. ) //Only execute the function when there's an sd (except for debug/wanttoconnect packets)
  10248. packet_db[packet_ver][cmd].func(fd, sd);
  10249. } else {
  10250. // 不明なパケット
  10251. if (battle_config.error_log) {
  10252. #if DUMP_UNKNOWN_PACKET
  10253. {
  10254. int i;
  10255. FILE *fp;
  10256. char packet_txt[256] = "save/packet.txt";
  10257. time_t now;
  10258. dump = 1;
  10259. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10260. ShowError("clif.c: cant write [%s] !!! data is lost !!!\n", packet_txt);
  10261. return 1;
  10262. } else {
  10263. time(&now);
  10264. if (sd && sd->state.auth) {
  10265. if (sd->status.name != NULL)
  10266. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  10267. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10268. else
  10269. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10270. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10271. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10272. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10273. for(i = 0; i < packet_len; i++) {
  10274. if ((i & 15) == 0)
  10275. fprintf(fp, "\n\t%04X ", i);
  10276. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10277. }
  10278. fprintf(fp, "\n\n");
  10279. fclose(fp);
  10280. }
  10281. }
  10282. #endif
  10283. }
  10284. }
  10285. if (dump) {
  10286. int i;
  10287. if (fd)
  10288. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10289. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10290. for(i = 0; i < packet_len; i++) {
  10291. if ((i & 15) == 0)
  10292. printf("\n%04X ",i);
  10293. printf("%02X ", RFIFOB(fd,i));
  10294. }
  10295. printf("\n");
  10296. if (sd && sd->state.auth) {
  10297. if (sd->status.name != NULL)
  10298. printf("\nAccount ID %d, character ID %d, player name %s.\n",
  10299. sd->status.account_id, sd->status.char_id, sd->status.name);
  10300. else
  10301. printf("\nAccount ID %d.\n", sd->bl.id);
  10302. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10303. printf("\nAccount ID %d.\n", sd->bl.id);
  10304. }
  10305. RFIFOSKIP(fd, packet_len);
  10306. return 0;
  10307. }
  10308. /*==========================================
  10309. * パケットデータベース読み込み
  10310. *------------------------------------------
  10311. */
  10312. static int packetdb_readdb(void)
  10313. {
  10314. FILE *fp;
  10315. char line[1024];
  10316. int ln=0;
  10317. int cmd,i,j,k,packet_ver;
  10318. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  10319. struct {
  10320. void (*func)(int, struct map_session_data *);
  10321. char *name;
  10322. } clif_parse_func[]={
  10323. {clif_parse_WantToConnection,"wanttoconnection"},
  10324. {clif_parse_LoadEndAck,"loadendack"},
  10325. {clif_parse_TickSend,"ticksend"},
  10326. {clif_parse_WalkToXY,"walktoxy"},
  10327. {clif_parse_QuitGame,"quitgame"},
  10328. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  10329. {clif_parse_GlobalMessage,"globalmessage"},
  10330. {clif_parse_MapMove,"mapmove"},
  10331. {clif_parse_ChangeDir,"changedir"},
  10332. {clif_parse_Emotion,"emotion"},
  10333. {clif_parse_HowManyConnections,"howmanyconnections"},
  10334. {clif_parse_ActionRequest,"actionrequest"},
  10335. {clif_parse_Restart,"restart"},
  10336. {clif_parse_Wis,"wis"},
  10337. {clif_parse_GMmessage,"gmmessage"},
  10338. {clif_parse_TakeItem,"takeitem"},
  10339. {clif_parse_DropItem,"dropitem"},
  10340. {clif_parse_UseItem,"useitem"},
  10341. {clif_parse_EquipItem,"equipitem"},
  10342. {clif_parse_UnequipItem,"unequipitem"},
  10343. {clif_parse_NpcClicked,"npcclicked"},
  10344. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  10345. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  10346. {clif_parse_NpcSellListSend,"npcselllistsend"},
  10347. {clif_parse_CreateChatRoom,"createchatroom"},
  10348. {clif_parse_ChatAddMember,"chataddmember"},
  10349. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  10350. {clif_parse_ChangeChatOwner,"changechatowner"},
  10351. {clif_parse_KickFromChat,"kickfromchat"},
  10352. {clif_parse_ChatLeave,"chatleave"},
  10353. {clif_parse_TradeRequest,"traderequest"},
  10354. {clif_parse_TradeAck,"tradeack"},
  10355. {clif_parse_TradeAddItem,"tradeadditem"},
  10356. {clif_parse_TradeOk,"tradeok"},
  10357. {clif_parse_TradeCancel,"tradecancel"},
  10358. {clif_parse_TradeCommit,"tradecommit"},
  10359. {clif_parse_StopAttack,"stopattack"},
  10360. {clif_parse_PutItemToCart,"putitemtocart"},
  10361. {clif_parse_GetItemFromCart,"getitemfromcart"},
  10362. {clif_parse_RemoveOption,"removeoption"},
  10363. {clif_parse_ChangeCart,"changecart"},
  10364. {clif_parse_StatusUp,"statusup"},
  10365. {clif_parse_SkillUp,"skillup"},
  10366. {clif_parse_UseSkillToId,"useskilltoid"},
  10367. {clif_parse_UseSkillToPos,"useskilltopos"},
  10368. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  10369. {clif_parse_UseSkillMap,"useskillmap"},
  10370. {clif_parse_RequestMemo,"requestmemo"},
  10371. {clif_parse_ProduceMix,"producemix"},
  10372. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  10373. {clif_parse_NpcNextClicked,"npcnextclicked"},
  10374. {clif_parse_NpcAmountInput,"npcamountinput"},
  10375. {clif_parse_NpcStringInput,"npcstringinput"},
  10376. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  10377. {clif_parse_ItemIdentify,"itemidentify"},
  10378. {clif_parse_SelectArrow,"selectarrow"},
  10379. {clif_parse_AutoSpell,"autospell"},
  10380. {clif_parse_UseCard,"usecard"},
  10381. {clif_parse_InsertCard,"insertcard"},
  10382. {clif_parse_RepairItem,"repairitem"},
  10383. {clif_parse_WeaponRefine,"weaponrefine"},
  10384. {clif_parse_SolveCharName,"solvecharname"},
  10385. {clif_parse_ResetChar,"resetchar"},
  10386. {clif_parse_LGMmessage,"lgmmessage"},
  10387. {clif_parse_MoveToKafra,"movetokafra"},
  10388. {clif_parse_MoveFromKafra,"movefromkafra"},
  10389. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  10390. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  10391. {clif_parse_CloseKafra,"closekafra"},
  10392. {clif_parse_CreateParty,"createparty"},
  10393. {clif_parse_CreateParty2,"createparty2"},
  10394. {clif_parse_PartyInvite,"partyinvite"},
  10395. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  10396. {clif_parse_LeaveParty,"leaveparty"},
  10397. {clif_parse_RemovePartyMember,"removepartymember"},
  10398. {clif_parse_PartyChangeOption,"partychangeoption"},
  10399. {clif_parse_PartyMessage,"partymessage"},
  10400. {clif_parse_CloseVending,"closevending"},
  10401. {clif_parse_VendingListReq,"vendinglistreq"},
  10402. {clif_parse_PurchaseReq,"purchasereq"},
  10403. {clif_parse_OpenVending,"openvending"},
  10404. {clif_parse_CreateGuild,"createguild"},
  10405. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  10406. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  10407. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  10408. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  10409. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  10410. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  10411. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  10412. {clif_parse_GuildInvite,"guildinvite"},
  10413. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  10414. {clif_parse_GuildLeave,"guildleave"},
  10415. {clif_parse_GuildExplusion,"guildexplusion"},
  10416. {clif_parse_GuildMessage,"guildmessage"},
  10417. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  10418. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  10419. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  10420. {clif_parse_GuildOpposition,"guildopposition"},
  10421. {clif_parse_GuildBreak,"guildbreak"},
  10422. {clif_parse_PetMenu,"petmenu"},
  10423. {clif_parse_CatchPet,"catchpet"},
  10424. {clif_parse_SelectEgg,"selectegg"},
  10425. {clif_parse_SendEmotion,"sendemotion"},
  10426. {clif_parse_ChangePetName,"changepetname"},
  10427. {clif_parse_GMKick,"gmkick"},
  10428. {clif_parse_GMHide,"gmhide"},
  10429. {clif_parse_GMReqNoChat,"gmreqnochat"},
  10430. {clif_parse_GMReqNoChatCount,"gmreqnochatcount"},
  10431. {clif_parse_NoviceDoriDori,"sndoridori"},
  10432. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  10433. {clif_parse_PMIgnore,"wisexin"},
  10434. {clif_parse_PMIgnoreList,"wisexlist"},
  10435. {clif_parse_PMIgnoreAll,"wisall"},
  10436. {clif_parse_FriendsListAdd,"friendslistadd"},
  10437. {clif_parse_FriendsListRemove,"friendslistremove"},
  10438. {clif_parse_FriendsListReply,"friendslistreply"},
  10439. {clif_parse_GMKillAll,"killall"},
  10440. {clif_parse_Recall,"summon"},
  10441. {clif_parse_GM_Monster_Item,"itemmonster"},
  10442. {clif_parse_Shift,"shift"},
  10443. {clif_parse_Blacksmith,"blacksmith"},
  10444. {clif_parse_Alchemist,"alchemist"},
  10445. {clif_parse_Taekwon,"taekwon"},
  10446. {clif_parse_RankingPk,"rankingpk"},
  10447. {clif_parse_FeelSaveOk,"feelsaveok"},
  10448. {clif_parse_debug,"debug"},
  10449. {NULL,NULL}
  10450. };
  10451. sprintf(line, "%s/packet_db.txt", db_path);
  10452. if( (fp=fopen(line,"r"))==NULL ){
  10453. ShowFatalError("can't read %s\n", line);
  10454. exit(1);
  10455. }
  10456. clif_config.packet_db_ver = MAX_PACKET_VER;
  10457. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  10458. while(fgets(line,1020,fp)){
  10459. if(line[0]=='/' && line[1]=='/')
  10460. continue;
  10461. if (sscanf(line,"%[^:]: %[^\r\n]",w1,w2) == 2) {
  10462. if(strcmpi(w1,"packet_ver")==0) {
  10463. int prev_ver = packet_ver;
  10464. packet_ver = atoi(w2);
  10465. if (packet_ver > MAX_PACKET_VER)
  10466. { //Check to avoid overflowing. [Skotlex]
  10467. ShowWarning("The packet_db table only has support up to version %d\n", MAX_PACKET_VER);
  10468. break;
  10469. }
  10470. // copy from previous version into new version and continue
  10471. // - indicating all following packets should be read into the newer version
  10472. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  10473. continue;
  10474. } else if(strcmpi(w1,"packet_db_ver")==0) {
  10475. //This is the preferred version.
  10476. if(strcmpi(w2,"default")==0)
  10477. clif_config.packet_db_ver = MAX_PACKET_VER;
  10478. else {
  10479. // to manually set the packet DB version
  10480. clif_config.packet_db_ver = atoi(w2);
  10481. // check for invalid version
  10482. if (clif_config.packet_db_ver > MAX_PACKET_VER ||
  10483. clif_config.packet_db_ver < 0)
  10484. clif_config.packet_db_ver = MAX_PACKET_VER;
  10485. }
  10486. continue;
  10487. }
  10488. }
  10489. memset(str,0,sizeof(str));
  10490. for(j=0,p=line;j<4 && p;j++){
  10491. str[j]=p;
  10492. p=strchr(p,',');
  10493. if(p) *p++=0;
  10494. }
  10495. if(str[0]==NULL)
  10496. continue;
  10497. cmd=strtol(str[0],(char **)NULL,0);
  10498. if(cmd<=0 || cmd>=MAX_PACKET_DB)
  10499. continue;
  10500. if(str[1]==NULL){
  10501. ShowError("packet_db: packet len error\n");
  10502. continue;
  10503. }
  10504. k = atoi(str[1]);
  10505. packet_db[packet_ver][cmd].len = k;
  10506. if(str[2]==NULL){
  10507. packet_db[packet_ver][cmd].func = NULL;
  10508. ln++;
  10509. continue;
  10510. }
  10511. for(j=0;j<sizeof(clif_parse_func)/sizeof(clif_parse_func[0]);j++){
  10512. if(clif_parse_func[j].name != NULL &&
  10513. strcmp(str[2],clif_parse_func[j].name)==0)
  10514. {
  10515. if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func)
  10516. { //If we are updating a function, we need to zero up the previous one. [Skotlex]
  10517. for(i=0;i<MAX_PACKET_DB;i++){
  10518. if (packet_db[packet_ver][i].func == clif_parse_func[j].func)
  10519. {
  10520. memset(&packet_db[packet_ver][i], 0, sizeof(struct packet_db));
  10521. break;
  10522. }
  10523. }
  10524. }
  10525. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  10526. break;
  10527. }
  10528. }
  10529. // set the identifying cmd for the packet_db version
  10530. if (strcmp(str[2],"wanttoconnection")==0)
  10531. clif_config.connect_cmd[packet_ver] = cmd;
  10532. if(str[3]==NULL){
  10533. ShowError("packet_db: packet error\n");
  10534. exit(1);
  10535. }
  10536. for(j=0,p2=str[3];p2;j++){
  10537. str2[j]=p2;
  10538. p2=strchr(p2,':');
  10539. if(p2) *p2++=0;
  10540. k = atoi(str2[j]);
  10541. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  10542. packet_db[packet_ver][cmd].pos[j] = k;
  10543. }
  10544. ln++;
  10545. // if(packet_db[clif_config.packet_db_ver][cmd].len > 2 /* && packet_db[cmd].pos[0] == 0 */)
  10546. // printf("packet_db ver %d: %d 0x%x %d %s %p\n",packet_ver,ln,cmd,packet_db[packet_ver][cmd].len,str[2],packet_db[packet_ver][cmd].func);
  10547. }
  10548. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  10549. { //Locate the nearest version that we still support. [Skotlex]
  10550. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  10551. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  10552. }
  10553. 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);
  10554. return 0;
  10555. }
  10556. /*==========================================
  10557. *
  10558. *------------------------------------------
  10559. */
  10560. int do_init_clif(void) {
  10561. #ifndef __WIN32
  10562. int i;
  10563. #endif
  10564. clif_config.packet_db_ver = -1; // the main packet version of the DB
  10565. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  10566. memset(packet_db,0,sizeof(packet_db));
  10567. //Using the packet_db file is the only way to set up packets now [Skotlex]
  10568. packetdb_readdb();
  10569. set_defaultparse(clif_parse);
  10570. #ifdef __WIN32
  10571. //if (!make_listen_port(map_port)) {
  10572. if (!make_listen_bind(bind_ip,map_port)) {
  10573. ShowFatalError("cant bind game port\n");
  10574. exit(1);
  10575. }
  10576. #else
  10577. for(i = 0; i < 10; i++) {
  10578. //if (make_listen_port(map_port))
  10579. if (make_listen_bind(bind_ip,map_port))
  10580. break;
  10581. sleep(20);
  10582. }
  10583. if (i == 10) {
  10584. ShowFatalError("cant bind game port\n");
  10585. exit(1);
  10586. }
  10587. #endif
  10588. add_timer_func_list(clif_waitclose, "clif_waitclose");
  10589. add_timer_func_list(clif_clearchar_delay_sub, "clif_clearchar_delay_sub");
  10590. add_timer_func_list(clif_delayquit, "clif_delayquit");
  10591. return 0;
  10592. }