clif.c 320 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361
  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. #include <time.h>
  11. #include "../common/cbasetypes.h"
  12. #include "../common/socket.h"
  13. #include "../common/timer.h"
  14. #include "../common/malloc.h"
  15. #include "../common/version.h"
  16. #include "../common/nullpo.h"
  17. #include "../common/showmsg.h"
  18. #include "../common/strlib.h"
  19. #include "map.h"
  20. #include "chrif.h"
  21. #include "clif.h"
  22. #include "pc.h"
  23. #include "status.h"
  24. #include "npc.h"
  25. #include "itemdb.h"
  26. #include "chat.h"
  27. #include "trade.h"
  28. #include "storage.h"
  29. #include "script.h"
  30. #include "skill.h"
  31. #include "atcommand.h"
  32. #include "charcommand.h"
  33. #include "intif.h"
  34. #include "battle.h"
  35. #include "mob.h"
  36. #include "party.h"
  37. #include "unit.h"
  38. #include "guild.h"
  39. #include "vending.h"
  40. #include "pet.h"
  41. #include "mercenary.h" //[orn]
  42. #include "log.h"
  43. #include "irc.h"
  44. struct Clif_Config {
  45. int packet_db_ver; //Preferred packet version.
  46. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  47. } clif_config;
  48. struct packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB];
  49. //Converts item type in case of pet eggs.
  50. #define itemtype(a) (a == 7)?4:a
  51. #define WBUFPOS(p,pos,x,y,dir) \
  52. do { \
  53. uint8 *__p = (p); \
  54. __p+=(pos); \
  55. __p[0] = (uint8)((x)>>2); \
  56. __p[1] = (uint8)(((x)<<6) | (((y)>>4)&0x3f)); \
  57. __p[2] = (uint8)(((y)<<4) | ((dir)&0xf)); \
  58. } while(0)
  59. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  60. #define WBUFPOS2(p,pos,x0,y0,x1,y1,sx0,sy0) \
  61. do { \
  62. uint8 *__p = (p); \
  63. __p+=(pos); \
  64. __p[0]=(uint8)((x0)>>2); \
  65. __p[1]=(uint8)(((x0)<<6) | (((y0)>>4)&0x3f)); \
  66. __p[2]=(uint8)(((y0)<<4) | (((x1)>>6)&0x0f)); \
  67. __p[3]=(uint8)(((x1)<<2) | (((y1)>>8)&0x03)); \
  68. __p[4]=(uint8)(y1); \
  69. __p[5]=(uint8)(((sx0)<<4) | ((sy0)&0x0f)); \
  70. } while(0)
  71. #define WFIFOPOS(fd,pos,x,y,dir) WBUFPOS(WFIFOP(fd,pos),0,x,y,dir)
  72. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1,sx0,sy0) WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1,sx0,sy0)
  73. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  74. #define clif_setlevel(lv) (lv<battle_config.max_lv?lv:battle_config.max_lv-(lv<battle_config.aura_lv?1:0));
  75. //Removed sd->npc_shopid because there is no packet sent from the client when you cancel a buy!
  76. //Quick check to know if the player shouldn't be "busy" with something else to deny action requests. [Skotlex]
  77. #define clif_cant_act(sd) (sd->npc_id || sd->vender_id || sd->chatID || sd->sc.opt1 || sd->state.trading || sd->state.storage_flag)
  78. // Checks if SD is in a trade/shop (where messing with the inventory can cause problems/exploits)
  79. #define clif_trading(sd) (sd->npc_id || sd->vender_id || sd->state.trading )
  80. //To idenfity disguised characters.
  81. #define disguised(bl) (bl->type==BL_PC && ((TBL_PC*)bl)->disguise)
  82. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex\]
  83. #define mes_len_check(mes, len, max) if (len > max) { mes[max-1] = '\0'; len = max; } else mes[len-1] = '\0';
  84. static char map_ip_str[128];
  85. static in_addr_t map_ip;
  86. static in_addr_t bind_ip = INADDR_ANY;
  87. static int map_port = 5121;
  88. int map_fd;
  89. //These two will be used to verify the incoming player's validity.
  90. //It helps identify their client packet version correctly. [Skotlex]
  91. static int max_account_id = DEFAULT_MAX_ACCOUNT_ID;
  92. static int max_char_id = DEFAULT_MAX_CHAR_ID;
  93. int clif_parse (int fd);
  94. static void clif_hpmeter_single(int fd, struct map_session_data *sd);
  95. /*==========================================
  96. * map鯖のip設定
  97. *------------------------------------------
  98. */
  99. int clif_setip(char *ip)
  100. {
  101. char ip_str[16];
  102. map_ip = resolve_hostbyname(ip,NULL,ip_str);
  103. if (!map_ip) {
  104. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  105. return 0;
  106. }
  107. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  108. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip_str);
  109. return 1;
  110. }
  111. void clif_setbindip(char *ip)
  112. {
  113. unsigned char ip_str[4];
  114. bind_ip = resolve_hostbyname(ip,ip_str,NULL);
  115. if (bind_ip) {
  116. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%d.%d.%d.%d"CL_RESET"'.\n", ip, ip_str[0], ip_str[1], ip_str[2], ip_str[3]);
  117. } else {
  118. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  119. }
  120. }
  121. /*==========================================
  122. * map鯖のport設定
  123. *------------------------------------------
  124. */
  125. void clif_setport(int port)
  126. {
  127. map_port = port;
  128. }
  129. /*==========================================
  130. * map鯖のip読み出し
  131. *------------------------------------------
  132. */
  133. in_addr_t clif_getip(void)
  134. {
  135. return map_ip;
  136. }
  137. //Returns the ip casted as a basic type, to avoid needing to include the socket/net related libs by calling modules.
  138. unsigned long clif_getip_long(void)
  139. {
  140. return (unsigned long)map_ip;
  141. }
  142. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it
  143. //returns 0.
  144. unsigned long clif_refresh_ip(void) {
  145. in_addr_t new_ip;
  146. new_ip = resolve_hostbyname(map_ip_str, NULL, NULL);
  147. if (new_ip && new_ip != map_ip) {
  148. map_ip = new_ip;
  149. ShowInfo("Updating IP resolution of [%s].\n",map_ip_str);
  150. return (unsigned long)map_ip;
  151. }
  152. return 0;
  153. }
  154. /*==========================================
  155. * map鯖のport読み出し
  156. *------------------------------------------
  157. */
  158. int clif_getport(void)
  159. {
  160. return map_port;
  161. }
  162. /*==========================================
  163. * Counts connected players.
  164. *------------------------------------------
  165. */
  166. int clif_countusers(void)
  167. {
  168. int users = 0, i;
  169. struct map_session_data *sd;
  170. for(i = 0; i < fd_max; i++) {
  171. if (session[i] && session[i]->func_parse == clif_parse &&
  172. (sd = (struct map_session_data*)session[i]->session_data) &&
  173. sd->state.auth && !(battle_config.hide_GM_session && pc_isGM(sd)))
  174. users++;
  175. }
  176. return users;
  177. }
  178. /*==========================================
  179. * 全てのclientに対してfunc()実行
  180. *------------------------------------------
  181. */
  182. int clif_foreachclient(int (*func)(struct map_session_data*, va_list),...) //recoded by sasuke, bug when player count gets higher [Kevin]
  183. {
  184. int i;
  185. va_list ap;
  186. struct map_session_data *sd;
  187. va_start(ap,func);
  188. for(i = 0; i < fd_max; i++) {
  189. if ( session[i] && session[i]->func_parse == clif_parse) {
  190. sd = (struct map_session_data*)session[i]->session_data;
  191. if ( sd && sd->state.auth && !sd->state.waitingdisconnect )
  192. func(sd, ap);
  193. }
  194. }
  195. va_end(ap);
  196. return 0;
  197. }
  198. /*==========================================
  199. * clif_sendでAREA*指定時用
  200. *------------------------------------------
  201. */
  202. int clif_send_sub(struct block_list *bl, va_list ap)
  203. {
  204. struct block_list *src_bl;
  205. struct map_session_data *sd;
  206. unsigned char *buf;
  207. int len, type, fd;
  208. nullpo_retr(0, bl);
  209. nullpo_retr(0, ap);
  210. nullpo_retr(0, sd = (struct map_session_data *)bl);
  211. fd = sd->fd;
  212. if (!fd) //Don't send to disconnected clients.
  213. return 0;
  214. buf = va_arg(ap,unsigned char*);
  215. len = va_arg(ap,int);
  216. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  217. type = va_arg(ap,int);
  218. switch(type) {
  219. case AREA_WOS:
  220. if (bl == src_bl)
  221. return 0;
  222. break;
  223. case AREA_WOC:
  224. if (sd->chatID || bl == src_bl)
  225. return 0;
  226. break;
  227. case AREA_WOSC:
  228. {
  229. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  230. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  231. return 0;
  232. }
  233. break;
  234. }
  235. if (session[fd] != NULL) {
  236. WFIFOHEAD(fd, len);
  237. if (WFIFOP(fd,0) == buf) {
  238. printf("WARNING: Invalid use of clif_send function\n");
  239. printf(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  240. printf(" Please correct your code.\n");
  241. // don't send to not move the pointer of the packet for next sessions in the loop
  242. WFIFOSET(fd,0);//## TODO is this ok?
  243. } else {
  244. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  245. memcpy(WFIFOP(fd,0), buf, len);
  246. WFIFOSET(fd,len);
  247. }
  248. }
  249. }
  250. return 0;
  251. }
  252. /*==========================================
  253. *
  254. *------------------------------------------
  255. */
  256. int clif_send (unsigned char *buf, int len, struct block_list *bl, int type) {
  257. int i;
  258. struct map_session_data *sd = NULL;
  259. struct party_data *p = NULL;
  260. struct guild *g = NULL;
  261. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  262. if (type != ALL_CLIENT &&
  263. type != CHAT_MAINCHAT) {
  264. nullpo_retr(0, bl);
  265. if (bl->type == BL_PC) {
  266. sd = (struct map_session_data *)bl;
  267. }
  268. }
  269. switch(type) {
  270. case ALL_CLIENT: //All player clients.
  271. for (i = 0; i < fd_max; i++) {
  272. if (session[i] && session[i]->func_parse == clif_parse &&
  273. (sd = (struct map_session_data *)session[i]->session_data) != NULL&&
  274. sd->state.auth) {
  275. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  276. WFIFOHEAD(i, len);
  277. memcpy(WFIFOP(i,0), buf, len);
  278. WFIFOSET(i,len);
  279. }
  280. }
  281. }
  282. break;
  283. case ALL_SAMEMAP: //All players on the same map
  284. for(i = 0; i < fd_max; i++) {
  285. if (session[i] && session[i]->func_parse == clif_parse &&
  286. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  287. sd->state.auth && sd->bl.m == bl->m) {
  288. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  289. WFIFOHEAD(i,len);
  290. memcpy(WFIFOP(i,0), buf, len);
  291. WFIFOSET(i,len);
  292. }
  293. }
  294. }
  295. break;
  296. case AREA:
  297. case AREA_WOSC:
  298. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  299. clif_send (buf, len, bl, SELF);
  300. case AREA_WOC:
  301. case AREA_WOS:
  302. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  303. BL_PC, buf, len, bl, type);
  304. break;
  305. case AREA_CHAT_WOC:
  306. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  307. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  308. break;
  309. case CHAT:
  310. case CHAT_WOS:
  311. {
  312. struct chat_data *cd;
  313. if (sd) {
  314. cd = (struct chat_data*)map_id2bl(sd->chatID);
  315. } else if (bl->type == BL_CHAT) {
  316. cd = (struct chat_data*)bl;
  317. } else break;
  318. if (cd == NULL)
  319. break;
  320. for(i = 0; i < cd->users; i++) {
  321. if (type == CHAT_WOS && cd->usersd[i] == sd)
  322. continue;
  323. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  324. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  325. {
  326. WFIFOHEAD(fd,len);
  327. memcpy(WFIFOP(fd,0), buf, len);
  328. WFIFOSET(fd,len);
  329. }
  330. }
  331. }
  332. }
  333. break;
  334. case CHAT_MAINCHAT: //[LuzZza]
  335. for(i=1; i<fd_max; i++) {
  336. if (session[i] && session[i]->func_parse == clif_parse &&
  337. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  338. sd->state.mainchat && (fd=sd->fd))
  339. {
  340. WFIFOHEAD(fd,len);
  341. memcpy(WFIFOP(fd,0), buf, len);
  342. WFIFOSET(fd, len);
  343. }
  344. }
  345. break;
  346. case PARTY_AREA:
  347. case PARTY_AREA_WOS:
  348. x0 = bl->x - AREA_SIZE;
  349. y0 = bl->y - AREA_SIZE;
  350. x1 = bl->x + AREA_SIZE;
  351. y1 = bl->y + AREA_SIZE;
  352. case PARTY:
  353. case PARTY_WOS:
  354. case PARTY_SAMEMAP:
  355. case PARTY_SAMEMAP_WOS:
  356. if (sd && sd->status.party_id)
  357. p = party_search(sd->status.party_id);
  358. if (p) {
  359. for(i=0;i<MAX_PARTY;i++){
  360. if ((sd = p->data[i].sd) == NULL)
  361. continue;
  362. if (!(fd=sd->fd) || session[fd] == NULL || sd->state.auth == 0
  363. || session[fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  364. continue;
  365. if (sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS))
  366. continue;
  367. if (type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m)
  368. continue;
  369. if ((type == PARTY_AREA || type == PARTY_AREA_WOS) &&
  370. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  371. continue;
  372. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  373. WFIFOHEAD(fd,len);
  374. memcpy(WFIFOP(fd,0), buf, len);
  375. WFIFOSET(fd,len);
  376. }
  377. }
  378. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  379. break;
  380. for (i = 1; i < fd_max; i++){ // partyspy [Syrus22]
  381. if (session[i] && session[i]->func_parse == clif_parse &&
  382. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  383. sd->state.auth && (fd=sd->fd) && sd->partyspy == p->party.party_id)
  384. {
  385. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  386. WFIFOHEAD(fd,len);
  387. memcpy(WFIFOP(fd,0), buf, len);
  388. WFIFOSET(fd,len);
  389. }
  390. }
  391. }
  392. }
  393. break;
  394. case DUEL:
  395. case DUEL_WOS:
  396. if (!sd || !sd->duel_group) break; //Invalid usage.
  397. x0 = sd->duel_group; //Here we use x0 to store the duel group. [Skotlex]
  398. for (i = 0; i < fd_max; i++) {
  399. if (session[i] && session[i]->func_parse == clif_parse &&
  400. (sd = (struct map_session_data *)session[i]->session_data) != NULL &&
  401. sd->state.auth && sd->duel_group == x0) {
  402. if (type == DUEL_WOS && bl->id == sd->bl.id)
  403. continue;
  404. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) {
  405. WFIFOHEAD(i, len);
  406. memcpy(WFIFOP(i,0), buf, len);
  407. WFIFOSET(i,len);
  408. }
  409. }
  410. }
  411. break;
  412. case SELF:
  413. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  414. WFIFOHEAD(fd,len);
  415. memcpy(WFIFOP(fd,0), buf, len);
  416. WFIFOSET(fd,len);
  417. }
  418. break;
  419. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  420. case GUILD_AREA:
  421. case GUILD_AREA_WOS:
  422. x0 = bl->x - AREA_SIZE;
  423. y0 = bl->y - AREA_SIZE;
  424. x1 = bl->x + AREA_SIZE;
  425. y1 = bl->y + AREA_SIZE;
  426. case GUILD_SAMEMAP:
  427. case GUILD_SAMEMAP_WOS:
  428. case GUILD:
  429. case GUILD_WOS:
  430. if (sd && sd->status.guild_id)
  431. g = guild_search(sd->status.guild_id);
  432. if (g) {
  433. for(i = 0; i < g->max_member; i++) {
  434. if ((sd = g->member[i].sd) != NULL) {
  435. if (!(fd=sd->fd) || session[fd] == NULL || sd->state.auth == 0
  436. || session[fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  437. continue;
  438. if (sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS))
  439. continue;
  440. if (type != GUILD && type != GUILD_WOS && sd->bl.m != bl->m)
  441. continue;
  442. if ((type == GUILD_AREA || type == GUILD_AREA_WOS) &&
  443. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  444. continue;
  445. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  446. WFIFOHEAD(fd,len);
  447. memcpy(WFIFOP(fd,0), buf, len);
  448. WFIFOSET(fd,len);
  449. }
  450. }
  451. }
  452. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  453. break;
  454. for (i = 1; i < fd_max; i++){ // guildspy [Syrus22]
  455. if (session[i] && session[i]->func_parse == clif_parse &&
  456. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  457. sd->state.auth && (fd=sd->fd) && sd->guildspy == g->guild_id) {
  458. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  459. WFIFOHEAD(fd,len);
  460. memcpy(WFIFOP(fd,0), buf, len);
  461. WFIFOSET(fd,len);
  462. }
  463. }
  464. }
  465. }
  466. break;
  467. /* End [Valaris] */
  468. default:
  469. if (battle_config.error_log)
  470. ShowError("clif_send: Unrecognized type %d\n",type);
  471. return -1;
  472. }
  473. return 0;
  474. }
  475. //
  476. // パケット作って送信
  477. //
  478. /*==========================================
  479. *
  480. *------------------------------------------
  481. */
  482. int clif_authok(struct map_session_data *sd) {
  483. int fd;
  484. if (!sd->fd)
  485. return 0;
  486. fd = sd->fd;
  487. WFIFOHEAD(fd, packet_len(0x73));
  488. WFIFOW(fd, 0) = 0x73;
  489. WFIFOL(fd, 2) = gettick();
  490. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  491. WFIFOB(fd, 9) = 5; // ignored
  492. WFIFOB(fd,10) = 5; // ignored
  493. WFIFOSET(fd,packet_len(0x73));
  494. return 0;
  495. }
  496. /*==========================================
  497. * Authentication failed/disconnect client.
  498. *------------------------------------------
  499. * The client closes it's socket and displays a message according to type:
  500. * 1 - server closed -> MsgStringTable[4]
  501. * 2 - ID already logged in -> MsgStringTable[5]
  502. * 3 - timeout/too much lag -> MsgStringTable[241]
  503. * 4 - server full -> MsgStringTable[264]
  504. * 5 - underaged -> MsgStringTable[305]
  505. * 9 - too many connections from this ip -> MsgStringTable[529]
  506. * 10 - payed time has ended -> MsgStringTable[530]
  507. * 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  508. * other - disconnected -> MsgStringTable[3]
  509. */
  510. int clif_authfail_fd(int fd, int type) {
  511. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  512. return 0;
  513. WFIFOHEAD(fd, packet_len(0x81));
  514. WFIFOW(fd,0) = 0x81;
  515. WFIFOB(fd,2) = type;
  516. WFIFOSET(fd,packet_len(0x81));
  517. clif_setwaitclose(fd);
  518. return 0;
  519. }
  520. /*==========================================
  521. * Used to know which is the max valid account/char id [Skotlex]
  522. *------------------------------------------
  523. */
  524. void clif_updatemaxid(int account_id, int char_id)
  525. {
  526. max_account_id = account_id;
  527. max_char_id = char_id;
  528. }
  529. /*==========================================
  530. *
  531. *------------------------------------------
  532. */
  533. int clif_charselectok(int id) {
  534. struct map_session_data *sd;
  535. int fd;
  536. if ((sd = map_id2sd(id)) == NULL)
  537. return 1;
  538. if (!sd->fd)
  539. return 1;
  540. fd = sd->fd;
  541. WFIFOHEAD(fd, packet_len(0xb3));
  542. WFIFOW(fd,0) = 0xb3;
  543. WFIFOB(fd,2) = 1;
  544. WFIFOSET(fd,packet_len(0xb3));
  545. return 0;
  546. }
  547. /*==========================================
  548. *
  549. *------------------------------------------
  550. */
  551. static int clif_set009e(struct flooritem_data *fitem,unsigned char *buf) {
  552. int view;
  553. nullpo_retr(0, fitem);
  554. //009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  555. WBUFW(buf, 0) = 0x9e;
  556. WBUFL(buf, 2) = fitem->bl.id;
  557. if ((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  558. WBUFW(buf, 6) = view;
  559. else
  560. WBUFW(buf, 6) = fitem->item_data.nameid;
  561. WBUFB(buf, 8) = fitem->item_data.identify;
  562. WBUFW(buf, 9) = fitem->bl.x;
  563. WBUFW(buf,11) = fitem->bl.y;
  564. WBUFB(buf,13) = fitem->subx;
  565. WBUFB(buf,14) = fitem->suby;
  566. WBUFW(buf,15) = fitem->item_data.amount;
  567. return packet_len(0x9e);
  568. }
  569. /*==========================================
  570. *
  571. *------------------------------------------
  572. */
  573. int clif_dropflooritem(struct flooritem_data *fitem) {
  574. unsigned char buf[64];
  575. nullpo_retr(0, fitem);
  576. if (fitem->item_data.nameid <= 0)
  577. return 0;
  578. clif_set009e(fitem, buf);
  579. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  580. return 0;
  581. }
  582. /*==========================================
  583. *
  584. *------------------------------------------
  585. */
  586. int clif_clearflooritem(struct flooritem_data *fitem, int fd) {
  587. unsigned char buf[16];
  588. nullpo_retr(0, fitem);
  589. WBUFW(buf,0) = 0xa1;
  590. WBUFL(buf,2) = fitem->bl.id;
  591. if (fd == 0) {
  592. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  593. } else {
  594. WFIFOHEAD(fd,packet_len(0xa1));
  595. memcpy(WFIFOP(fd,0), buf, 6);
  596. WFIFOSET(fd,packet_len(0xa1));
  597. }
  598. return 0;
  599. }
  600. /*==========================================
  601. *
  602. *------------------------------------------
  603. */
  604. int clif_clearchar(struct block_list *bl, int type) {
  605. unsigned char buf[16];
  606. nullpo_retr(0, bl);
  607. WBUFW(buf,0) = 0x80;
  608. WBUFL(buf,2) = bl->id;
  609. WBUFB(buf,6) = type;
  610. clif_send(buf, packet_len(0x80), bl, type == 1 ? AREA : AREA_WOS);
  611. if(disguised(bl)) {
  612. WBUFL(buf,2) = -bl->id;
  613. clif_send(buf, packet_len(0x80), bl, SELF);
  614. }
  615. return 0;
  616. }
  617. static int clif_clearchar_delay_sub(int tid, unsigned int tick, int id, int data) {
  618. struct block_list *bl = (struct block_list *)id;
  619. clif_clearchar(bl,data);
  620. aFree(bl);
  621. return 0;
  622. }
  623. int clif_clearchar_delay(unsigned int tick, struct block_list *bl, int type) {
  624. struct block_list *tbl;
  625. tbl = aMalloc(sizeof (struct block_list));
  626. memcpy (tbl, bl, sizeof (struct block_list));
  627. add_timer(tick, clif_clearchar_delay_sub, (int)tbl, type);
  628. return 0;
  629. }
  630. /*==========================================
  631. *
  632. *------------------------------------------
  633. */
  634. int clif_clearchar_id(int id, int type, int fd) {
  635. WFIFOHEAD(fd, packet_len(0x80));
  636. WFIFOW(fd,0) = 0x80;
  637. WFIFOL(fd,2) = id;
  638. WFIFOB(fd,6) = (char)type; // Why use int for a char in the first place?
  639. WFIFOSET(fd, packet_len(0x80));
  640. return 0;
  641. }
  642. void clif_get_weapon_view(TBL_PC* sd, unsigned short *rhand, unsigned short *lhand)
  643. {
  644. #if PACKETVER > 3
  645. struct item_data *id;
  646. #endif
  647. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  648. {
  649. *rhand = *lhand = 0;
  650. return;
  651. }
  652. #if PACKETVER < 4
  653. *rhand = sd->status.weapon;
  654. *lhand = sd->status.shield;
  655. #else
  656. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  657. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  658. {
  659. id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  660. if (id->view_id > 0)
  661. *rhand = id->view_id;
  662. else
  663. *rhand = id->nameid;
  664. } else
  665. *rhand = 0;
  666. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  667. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  668. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  669. {
  670. id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  671. if (id->view_id > 0)
  672. *lhand = id->view_id;
  673. else
  674. *lhand = id->nameid;
  675. } else
  676. *lhand = 0;
  677. #endif
  678. }
  679. static void clif_get_guild_data(struct block_list *bl, long *guild_id, short *emblem_id)
  680. {
  681. //TODO: There has to be a way to clean this up.
  682. switch (bl->type) {
  683. case BL_PC:
  684. *guild_id = ((TBL_PC*)bl)->status.guild_id;
  685. *emblem_id = ((TBL_PC*)bl)->guild_emblem_id;
  686. break;
  687. case BL_MOB:
  688. if (((TBL_MOB*)bl)->guardian_data) {
  689. *guild_id =((TBL_MOB*)bl)->guardian_data->guild_id;
  690. *emblem_id =((TBL_MOB*)bl)->guardian_data->emblem_id;
  691. }
  692. break;
  693. case BL_NPC:
  694. if (bl->subtype == SCRIPT && ((TBL_NPC*)bl)->u.scr.guild_id > 0) {
  695. struct guild *g = guild_search(((TBL_NPC*)bl)->u.scr.guild_id);
  696. if (g) {
  697. *guild_id =g->guild_id;
  698. *emblem_id =g->emblem_id;
  699. }
  700. }
  701. break;
  702. default:
  703. *guild_id = status_get_guild_id(bl);
  704. }
  705. return;
  706. }
  707. /*==========================================
  708. *
  709. *------------------------------------------
  710. */
  711. static int clif_set0078(struct block_list *bl, struct view_data *vd, unsigned char *buf) {
  712. struct status_change *sc;
  713. struct map_session_data *sd;
  714. long guild_id=0;
  715. unsigned short emblem_id=0, lv;
  716. unsigned short dir;
  717. nullpo_retr(0, bl);
  718. BL_CAST(BL_PC, bl, sd);
  719. sc = status_get_sc(bl);
  720. clif_get_guild_data(bl, &guild_id, &emblem_id);
  721. dir = unit_getdir(bl);
  722. lv = status_get_lv(bl);
  723. if(pcdb_checkid(vd->class_)) {
  724. #if PACKETVER > 6
  725. memset(buf,0,packet_len(0x22a));
  726. WBUFW(buf,0)=0x22a;
  727. WBUFL(buf,2)=bl->id;
  728. WBUFW(buf,6)=status_get_speed(bl);
  729. if (sc) {
  730. WBUFW(buf,8)=sc->opt1;
  731. WBUFW(buf,10)=sc->opt2;
  732. WBUFL(buf,12)=sc->option;
  733. WBUFL(buf,44)=sc->opt3;
  734. }
  735. WBUFW(buf,16)=vd->class_;
  736. WBUFW(buf,18)=vd->hair_style;
  737. WBUFW(buf,20)=vd->weapon;
  738. WBUFW(buf,22)=vd->shield;
  739. WBUFW(buf,24)=vd->head_bottom;
  740. WBUFW(buf,26)=vd->head_top;
  741. WBUFW(buf,28)=vd->head_mid;
  742. WBUFW(buf,30)=vd->hair_color;
  743. WBUFW(buf,32)=vd->cloth_color;
  744. WBUFW(buf,34)=sd?sd->head_dir:0;
  745. WBUFL(buf,36)=guild_id;
  746. WBUFW(buf,40)=emblem_id;
  747. if (sd) {
  748. WBUFW(buf,42)=sd->status.manner;
  749. WBUFB(buf,48)=sd->status.karma;
  750. }
  751. WBUFB(buf,49)=vd->sex;
  752. WBUFPOS(buf,50,bl->x,bl->y,dir);
  753. WBUFB(buf,53)=5;
  754. WBUFB(buf,54)=5;
  755. WBUFB(buf,55)=vd->dead_sit;
  756. WBUFW(buf,56)=clif_setlevel(lv);
  757. return packet_len(0x22a);
  758. #elif PACKETVER > 3
  759. memset(buf,0,packet_len(0x1d8));
  760. WBUFW(buf,0)=0x1d8;
  761. WBUFL(buf,2)=bl->id;
  762. WBUFW(buf,6)=status_get_speed(bl);
  763. if (sc) {
  764. WBUFW(buf,8)=sc->opt1;
  765. WBUFW(buf,10)=sc->opt2;
  766. WBUFW(buf,12)=sc->option;
  767. WBUFW(buf,42)=sc->opt3;
  768. }
  769. WBUFW(buf,14)=vd->class_;
  770. WBUFW(buf,16)=vd->hair_style;
  771. WBUFW(buf,18)=vd->weapon;
  772. WBUFW(buf,20)=vd->shield;
  773. WBUFW(buf,22)=vd->head_bottom;
  774. WBUFW(buf,24)=vd->head_top;
  775. WBUFW(buf,26)=vd->head_mid;
  776. WBUFW(buf,28)=vd->hair_color;
  777. WBUFW(buf,30)=vd->cloth_color;
  778. WBUFW(buf,32)=sd?sd->head_dir:0;
  779. WBUFL(buf,34)=guild_id;
  780. WBUFW(buf,38)=emblem_id;
  781. if (sd) {
  782. WBUFW(buf,40)=sd->status.manner;
  783. WBUFB(buf,44)=sd->status.karma;
  784. }
  785. WBUFB(buf,45)=vd->sex;
  786. WBUFPOS(buf,46,bl->x,bl->y,dir);
  787. WBUFB(buf,49)=5;
  788. WBUFB(buf,50)=5;
  789. WBUFB(buf,51)=vd->dead_sit;
  790. WBUFW(buf,52)=clif_setlevel(lv);
  791. return packet_len(0x1d8);
  792. #else
  793. memset(buf,0,packet_len(0x78));
  794. WBUFW(buf,0)=0x78;
  795. WBUFL(buf,2)=bl->id;
  796. WBUFW(buf,6)=status_get_speed(bl);
  797. if (sc) {
  798. WBUFW(buf,8)=sc->opt1;
  799. WBUFW(buf,10)=sc->opt2;
  800. WBUFW(buf,12)=sc->option;
  801. WBUFW(buf,42)=sc->opt3;
  802. }
  803. WBUFW(buf,14)=vd->class_;
  804. WBUFW(buf,16)=vd->hair_style;
  805. WBUFW(buf,18)=vd->weapon;
  806. WBUFW(buf,20)=vd->head_bottom;
  807. WBUFW(buf,22)=vd->shield;
  808. WBUFW(buf,24)=vd->head_top;
  809. WBUFW(buf,26)=vd->head_mid;
  810. WBUFW(buf,28)=vd->hair_color;
  811. WBUFW(buf,30)=vd->cloth_color;
  812. WBUFW(buf,32)=sd?sd->head_dir:0;
  813. WBUFL(buf,34)=guild_id;
  814. WBUFL(buf,38)=emblem_id;
  815. if (sd)
  816. WBUFB(buf,44)=sd->status.karma;
  817. WBUFB(buf,45)=vd->sex;
  818. WBUFPOS(buf,46,bl->x,bl->y,dir);
  819. WBUFB(buf,49)=5;
  820. WBUFB(buf,50)=5;
  821. WBUFB(buf,51)=vd->dead_sit;
  822. WBUFW(buf,52)=clif_setlevel(lv);
  823. return packet_len(0x78);
  824. #endif
  825. }
  826. //Non-player sprites need just a few fields filled.
  827. memset(buf,0,packet_len(0x78));
  828. WBUFW(buf,0)=0x78;
  829. WBUFL(buf,2)=bl->id;
  830. WBUFW(buf,6)=status_get_speed(bl);
  831. if (sc) {
  832. WBUFW(buf,8)=sc->opt1;
  833. WBUFW(buf,10)=sc->opt2;
  834. WBUFW(buf,12)=sc->option;
  835. WBUFW(buf,42)=sc->opt3;
  836. }
  837. WBUFW(buf,14)=vd->class_;
  838. WBUFW(buf,16)=vd->hair_style; //Required for pets.
  839. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  840. if (bl->type == BL_NPC && vd->class_ == 722)
  841. { //The hell, why flags work like this?
  842. WBUFL(buf,22)=emblem_id;
  843. WBUFL(buf,26)=guild_id;
  844. }
  845. WBUFW(buf,32)=dir;
  846. WBUFL(buf,34)=guild_id;
  847. WBUFL(buf,38)=emblem_id;
  848. WBUFPOS(buf,46,bl->x,bl->y,dir);
  849. WBUFB(buf,49)=5;
  850. WBUFB(buf,50)=5;
  851. WBUFW(buf,52)=clif_setlevel(lv);
  852. return packet_len(0x78);
  853. }
  854. /*==========================================
  855. *
  856. *------------------------------------------
  857. */
  858. static int clif_set007b(struct block_list *bl, struct view_data *vd, struct unit_data *ud, unsigned char *buf) {
  859. struct status_change *sc;
  860. struct map_session_data *sd;
  861. long guild_id=0;
  862. unsigned short emblem_id=0, lv;
  863. nullpo_retr(0, bl);
  864. BL_CAST(BL_PC, bl, sd);
  865. sc = status_get_sc(bl);
  866. clif_get_guild_data(bl, &guild_id, &emblem_id);
  867. lv = status_get_lv(bl);
  868. if(pcdb_checkid(vd->class_)) {
  869. #if PACKETVER > 6
  870. memset(buf,0,packet_len(0x22c));
  871. WBUFW(buf,0)=0x22c;
  872. WBUFL(buf,2)=bl->id;
  873. WBUFW(buf,6)=status_get_speed(bl);
  874. if (sc) {
  875. WBUFW(buf,8)= sc->opt1;
  876. WBUFW(buf,10)= sc->opt2;
  877. WBUFL(buf,12)= sc->option;
  878. WBUFL(buf,48)= sc->opt3;
  879. }
  880. WBUFW(buf,16)=vd->class_;
  881. WBUFW(buf,18)=vd->hair_style;
  882. WBUFW(buf,20)=vd->weapon;
  883. WBUFW(buf,22)=vd->shield;
  884. WBUFW(buf,24)=vd->head_bottom;
  885. WBUFL(buf,26)=gettick();
  886. WBUFW(buf,30)=vd->head_top;
  887. WBUFW(buf,32)=vd->head_mid;
  888. WBUFW(buf,34)=vd->hair_color;
  889. WBUFW(buf,36)=vd->cloth_color;
  890. WBUFW(buf,38)=sd?sd->head_dir:0;
  891. WBUFL(buf,40)=guild_id;
  892. WBUFW(buf,44)=emblem_id;
  893. if (sd) {
  894. WBUFW(buf,46)=sd->status.manner;
  895. WBUFB(buf,52)=sd->status.karma;
  896. }
  897. WBUFB(buf,53)=vd->sex;
  898. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  899. WBUFB(buf,60)=0;
  900. WBUFB(buf,61)=0;
  901. WBUFW(buf,62)=clif_setlevel(lv);
  902. return packet_len(0x22c);
  903. #elif PACKETVER > 3
  904. memset(buf,0,packet_len(0x1da));
  905. WBUFW(buf,0)=0x1da;
  906. WBUFL(buf,2)=bl->id;
  907. WBUFW(buf,6)=status_get_speed(bl);
  908. if (sc) {
  909. WBUFW(buf,8)=sc->opt1;
  910. WBUFW(buf,10)=sc->opt2;
  911. WBUFW(buf,12)=sc->option;
  912. WBUFW(buf,46)=sc->opt3;
  913. }
  914. WBUFW(buf,14)=vd->class_;
  915. WBUFW(buf,16)=vd->hair_style;
  916. WBUFW(buf,18)=vd->weapon;
  917. WBUFW(buf,20)=vd->shield;
  918. WBUFW(buf,22)=vd->head_bottom;
  919. WBUFL(buf,24)=gettick();
  920. WBUFW(buf,28)=vd->head_top;
  921. WBUFW(buf,30)=vd->head_mid;
  922. WBUFW(buf,32)=vd->hair_color;
  923. WBUFW(buf,34)=vd->cloth_color;
  924. WBUFW(buf,36)=sd?sd->head_dir:0;
  925. WBUFL(buf,38)=guild_id;
  926. WBUFW(buf,42)=emblem_id;
  927. if (sd) {
  928. WBUFW(buf,44)=sd->status.manner;
  929. WBUFB(buf,48)=sd->status.karma;
  930. }
  931. WBUFB(buf,49)=vd->sex;
  932. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  933. WBUFB(buf,56)=5;
  934. WBUFB(buf,57)=5;
  935. WBUFW(buf,58)=clif_setlevel(lv);
  936. return packet_len(0x1da);
  937. #else
  938. memset(buf,0,packet_len(0x7b));
  939. WBUFW(buf,0)=0x7b;
  940. WBUFL(buf,2)=bl->id;
  941. WBUFW(buf,6)=status_get_speed(bl);
  942. if (sc) {
  943. WBUFW(buf,8)=sc->opt1;
  944. WBUFW(buf,10)=sc->opt2;
  945. WBUFW(buf,12)=sc->option;
  946. WBUFW(buf,46)=sc->opt3;
  947. }
  948. WBUFW(buf,14)=vd->class_;
  949. WBUFW(buf,16)=vd->hair_style;
  950. WBUFW(buf,18)=vd->weapon;
  951. WBUFW(buf,20)=vd->head_bottom;
  952. WBUFL(buf,22)=gettick();
  953. WBUFW(buf,26)=vd->shield;
  954. WBUFW(buf,28)=vd->head_top;
  955. WBUFW(buf,30)=vd->head_mid;
  956. WBUFW(buf,32)=vd->hair_color;
  957. WBUFW(buf,34)=vd->cloth_color;
  958. WBUFW(buf,36)=sd?sd->head_dir:0;
  959. WBUFL(buf,38)=guild_id;
  960. WBUFL(buf,42)=emblem_id;
  961. if (sd)
  962. WBUFB(buf,48)=sd->status.karma;
  963. WBUFB(buf,49)=vd->sex;
  964. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  965. WBUFB(buf,56)=5;
  966. WBUFB(buf,57)=5;
  967. WBUFW(buf,58)=clif_setlevel(lv);
  968. return packet_len(0x7b);
  969. #endif
  970. }
  971. //Non-player sprites only require a few fields.
  972. #if PACKETVER > 6
  973. memset(buf,0,packet_len(0x22c));
  974. WBUFW(buf,0)=0x22c;
  975. WBUFL(buf,2)=bl->id;
  976. WBUFW(buf,6)=status_get_speed(bl);
  977. if (sc) {
  978. WBUFW(buf,8)=sc->opt1;
  979. WBUFW(buf,10)=sc->opt2;
  980. WBUFL(buf,12)=sc->option;
  981. WBUFL(buf,48)=sc->opt3;
  982. }
  983. WBUFW(buf,16)=vd->class_;
  984. WBUFW(buf,18)=vd->hair_style; //For pets
  985. WBUFW(buf,24)=vd->head_bottom; //Pet armor
  986. WBUFL(buf,26)=gettick();
  987. WBUFW(buf,38)=unit_getdir(bl);
  988. WBUFL(buf,40)=guild_id;
  989. WBUFL(buf,44)=emblem_id;
  990. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  991. WBUFB(buf,60)=0;
  992. WBUFB(buf,61)=0;
  993. WBUFW(buf,62)=clif_setlevel(lv);
  994. return packet_len(0x22c);
  995. #else
  996. memset(buf,0,packet_len(0x7b));
  997. WBUFW(buf,0)=0x7b;
  998. WBUFL(buf,2)=bl->id;
  999. WBUFW(buf,6)=status_get_speed(bl);
  1000. if (sc) {
  1001. WBUFW(buf,8)=sc->opt1;
  1002. WBUFW(buf,10)=sc->opt2;
  1003. WBUFW(buf,12)=sc->option;
  1004. WBUFW(buf,46)=sc->opt3;
  1005. }
  1006. WBUFW(buf,14)=vd->class_;
  1007. WBUFW(buf,16)=vd->hair_style; //For pets
  1008. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  1009. WBUFL(buf,22)=gettick();
  1010. WBUFW(buf,36)=unit_getdir(bl);
  1011. WBUFL(buf,38)=guild_id;
  1012. WBUFL(buf,42)=emblem_id;
  1013. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1014. WBUFB(buf,56)=5;
  1015. WBUFB(buf,57)=5;
  1016. WBUFW(buf,58)=clif_setlevel(lv);
  1017. return packet_len(0x7b);
  1018. #endif
  1019. }
  1020. //Modifies the buffer for disguise characters and sends it to self.
  1021. //Flag = 0: change id to negative, buf will have disguise data.
  1022. //Flag = 1: change id to positive, class and option to make your own char invisible.
  1023. //Luckily, the offsets that need to be changed are the same in packets 0x78, 0x7b, 0x1d8 and 0x1da
  1024. //But no longer holds true for those packet of PACKETVER 7.
  1025. static void clif_setdisguise(struct map_session_data *sd, unsigned char *buf,int len, int flag) {
  1026. if (flag) {
  1027. #if PACKETVER > 6
  1028. switch (WBUFW(buf,0)) {
  1029. case 0x22c:
  1030. case 0x22b:
  1031. case 0x22a:
  1032. WBUFL(buf,12)=OPTION_INVISIBLE;
  1033. WBUFW(buf,16)=sd->status.class_;
  1034. break;
  1035. default:
  1036. #endif
  1037. WBUFL(buf,2)=sd->bl.id;
  1038. WBUFW(buf,12)=OPTION_INVISIBLE;
  1039. WBUFW(buf,14)=sd->status.class_;
  1040. #if PACKETVER > 6
  1041. break;
  1042. }
  1043. #endif
  1044. } else {
  1045. WBUFL(buf,2)=-sd->bl.id;
  1046. }
  1047. clif_send(buf, len, &sd->bl, SELF);
  1048. }
  1049. /*==========================================
  1050. * クラスチェンジ typeはMobの場合は1で他は0?
  1051. *------------------------------------------
  1052. */
  1053. int clif_class_change(struct block_list *bl,int class_,int type)
  1054. {
  1055. unsigned char buf[16];
  1056. nullpo_retr(0, bl);
  1057. if(!pcdb_checkid(class_)) {
  1058. WBUFW(buf,0)=0x1b0;
  1059. WBUFL(buf,2)=bl->id;
  1060. WBUFB(buf,6)=type;
  1061. WBUFL(buf,7)=class_;
  1062. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1063. }
  1064. return 0;
  1065. }
  1066. /*==========================================
  1067. *
  1068. *------------------------------------------
  1069. */
  1070. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1071. {
  1072. WFIFOHEAD(fd, packet_len(0x1e1));
  1073. WFIFOW(fd,0)=0x1e1;
  1074. WFIFOL(fd,2)=sd->bl.id;
  1075. WFIFOW(fd,6)=sd->spiritball;
  1076. WFIFOSET(fd, packet_len(0x1e1));
  1077. }
  1078. /*==========================================
  1079. *
  1080. *------------------------------------------
  1081. */
  1082. static int clif_set0192(int fd, int m, int x, int y, int type) {
  1083. WFIFOHEAD(fd, packet_len(0x192));
  1084. WFIFOW(fd,0) = 0x192;
  1085. WFIFOW(fd,2) = x;
  1086. WFIFOW(fd,4) = y;
  1087. WFIFOW(fd,6) = type;
  1088. memcpy(WFIFOP(fd,8),map[m].name,MAP_NAME_LENGTH);
  1089. WFIFOSET(fd,packet_len(0x192));
  1090. return 0;
  1091. }
  1092. // new and improved weather display [Valaris]
  1093. static void clif_weather_sub(int fd, int id, int type) {
  1094. WFIFOHEAD(fd, packet_len(0x1f3));
  1095. WFIFOW(fd,0) = 0x1f3;
  1096. WFIFOL(fd,2) = id;
  1097. WFIFOL(fd,6) = type;
  1098. WFIFOSET(fd,packet_len(0x1f3));
  1099. }
  1100. /*==========================================
  1101. *
  1102. *------------------------------------------
  1103. */
  1104. static void clif_weather_check(struct map_session_data *sd) {
  1105. int m = sd->bl.m, fd = sd->fd;
  1106. if (map[m].flag.snow
  1107. || map[m].flag.clouds
  1108. || map[m].flag.fog
  1109. || map[m].flag.fireworks
  1110. || map[m].flag.sakura
  1111. || map[m].flag.leaves
  1112. || map[m].flag.rain
  1113. || map[m].flag.clouds2)
  1114. {
  1115. if (map[m].flag.snow)
  1116. clif_weather_sub(fd, sd->bl.id, 162);
  1117. if (map[m].flag.clouds)
  1118. clif_weather_sub(fd, sd->bl.id, 233);
  1119. if (map[m].flag.clouds2)
  1120. clif_weather_sub(fd, sd->bl.id, 516);
  1121. if (map[m].flag.fog)
  1122. clif_weather_sub(fd, sd->bl.id, 515);
  1123. if (map[m].flag.fireworks) {
  1124. clif_weather_sub(fd, sd->bl.id, 297);
  1125. clif_weather_sub(fd, sd->bl.id, 299);
  1126. clif_weather_sub(fd, sd->bl.id, 301);
  1127. }
  1128. if (map[m].flag.sakura)
  1129. clif_weather_sub(fd, sd->bl.id, 163);
  1130. if (map[m].flag.leaves)
  1131. clif_weather_sub(fd, sd->bl.id, 333);
  1132. if (map[m].flag.rain)
  1133. clif_weather_sub(fd, sd->bl.id, 161);
  1134. }
  1135. }
  1136. int clif_weather(int m) {
  1137. int i;
  1138. struct map_session_data *sd=NULL;
  1139. for(i = 0; i < fd_max; i++) {
  1140. if (session[i] && session[i]->func_parse == clif_parse &&
  1141. (sd = session[i]->session_data) != NULL &&
  1142. sd->state.auth && sd->bl.m == m) {
  1143. clif_weather_check(sd);
  1144. }
  1145. }
  1146. return 0;
  1147. }
  1148. int clif_spawn(struct block_list *bl)
  1149. {
  1150. unsigned char buf[128];
  1151. struct view_data *vd;
  1152. nullpo_retr(0, bl);
  1153. vd = status_get_viewdata(bl);
  1154. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1155. return 0;
  1156. if (pcdb_checkid(vd->class_))
  1157. { //Player spawn packet.
  1158. clif_set0078(bl, vd, buf);
  1159. switch(WBUFW(buf,0)) {
  1160. case 0x78: //Convert to 0x79
  1161. WBUFW(buf, 0) = 0x79;
  1162. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1163. clif_send(buf, packet_len(0x79), bl, AREA_WOS);
  1164. if (disguised(bl))
  1165. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x79), 0);
  1166. break;
  1167. #if PACKETVER > 3
  1168. case 0x1d8: //Convert to 0x1d9
  1169. WBUFW(buf, 0) = 0x1d9;
  1170. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1171. clif_send(buf, packet_len(0x1d9), bl, AREA_WOS);
  1172. if (disguised(bl))
  1173. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x1d9), 0);
  1174. break;
  1175. #endif
  1176. #if PACKETVER > 6
  1177. case 0x22a: //Convert to 0x22b
  1178. WBUFW(buf, 0) = 0x22b;
  1179. WBUFW(buf,55) = WBUFW(buf,56); //Lv is placed on offset 56
  1180. clif_send(buf, packet_len(0x22b), bl, AREA_WOS);
  1181. if (disguised(bl))
  1182. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x22b), 0);
  1183. break;
  1184. #endif
  1185. }
  1186. } else { //Mob spawn packet.
  1187. struct status_change *sc = status_get_sc(bl);
  1188. memset(buf,0,sizeof(buf));
  1189. WBUFW(buf,0)=0x7c;
  1190. WBUFL(buf,2)=bl->id;
  1191. WBUFW(buf,6)=status_get_speed(bl);
  1192. if (sc) {
  1193. WBUFW(buf,8)=sc->opt1;
  1194. WBUFW(buf,10)=sc->opt2;
  1195. WBUFW(buf,12)=sc->option;
  1196. }
  1197. WBUFW(buf,20)=vd->class_;
  1198. WBUFW(buf,22)=vd->hair_style; //Required for pets.
  1199. WBUFW(buf,24)=vd->head_bottom; //Pet armor
  1200. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  1201. clif_send(buf,packet_len(0x7c),bl,AREA_WOS);
  1202. if (disguised(bl)) {
  1203. WBUFL(buf,2)=-bl->id;
  1204. clif_send(buf,packet_len(0x7c),bl,SELF);
  1205. }
  1206. }
  1207. if (vd->cloth_color)
  1208. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1209. switch (bl->type)
  1210. {
  1211. case BL_PC:
  1212. {
  1213. TBL_PC *sd = ((TBL_PC*)bl);
  1214. if (sd->spiritball > 0)
  1215. clif_spiritball(sd);
  1216. if(sd->state.size==2) // tiny/big players [Valaris]
  1217. clif_specialeffect(bl,423,AREA);
  1218. else if(sd->state.size==1)
  1219. clif_specialeffect(bl,421,AREA);
  1220. }
  1221. break;
  1222. case BL_MOB:
  1223. {
  1224. TBL_MOB *md = ((TBL_MOB*)bl);
  1225. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1226. clif_specialeffect(&md->bl,423,AREA);
  1227. else if(md->special_state.size==1)
  1228. clif_specialeffect(&md->bl,421,AREA);
  1229. }
  1230. break;
  1231. }
  1232. return 0;
  1233. }
  1234. //[orn]
  1235. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1236. {
  1237. struct status_data *status;
  1238. unsigned char buf[128];
  1239. nullpo_retr(0, hd);
  1240. status = &hd->battle_status;
  1241. memset(buf,0,packet_len(0x22e));
  1242. WBUFW(buf,0)=0x22e;
  1243. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1244. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1245. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1246. WBUFW(buf,27)=hd->homunculus.level;
  1247. WBUFW(buf,29)=hd->homunculus.hunger;
  1248. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1249. WBUFW(buf,33)=0; // equip id
  1250. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, SHRT_MAX);
  1251. WBUFW(buf,37)=cap_value(status->matk_max, 0, SHRT_MAX);
  1252. WBUFW(buf,39)=status->hit;
  1253. if (battle_config.hom_setting&0x10)
  1254. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1255. else
  1256. WBUFW(buf,41)=status->cri/10;
  1257. WBUFW(buf,43)=status->def + status->vit ;
  1258. WBUFW(buf,45)=status->mdef;
  1259. WBUFW(buf,47)=status->flee;
  1260. WBUFW(buf,49)=(flag)?0:status->amotion;
  1261. if (status->max_hp > SHRT_MAX) {
  1262. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1263. WBUFW(buf,53) = 100;
  1264. } else {
  1265. WBUFW(buf,51)=status->hp;
  1266. WBUFW(buf,53)=status->max_hp;
  1267. }
  1268. if (status->max_sp > SHRT_MAX) {
  1269. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1270. WBUFW(buf,57) = 100;
  1271. } else {
  1272. WBUFW(buf,55)=status->sp;
  1273. WBUFW(buf,57)=status->max_sp;
  1274. }
  1275. WBUFL(buf,59)=hd->homunculus.exp;
  1276. WBUFL(buf,63)=hd->exp_next;
  1277. WBUFW(buf,67)=hd->homunculus.skillpts;
  1278. WBUFW(buf,69)=1; // FIXME: Attackable? When exactly is a homun not attackable? [Skotlex]
  1279. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1280. return 0;
  1281. }
  1282. void clif_send_homdata(struct map_session_data *sd, int type, int param) { //[orn]
  1283. int fd = sd->fd;
  1284. WFIFOHEAD(fd, packet_len(0x230));
  1285. nullpo_retv(sd->hd);
  1286. WFIFOW(fd,0)=0x230;
  1287. WFIFOW(fd,2)=type;
  1288. WFIFOL(fd,4)=sd->hd->bl.id;
  1289. WFIFOL(fd,8)=param;
  1290. WFIFOSET(fd,packet_len(0x230));
  1291. return;
  1292. }
  1293. int clif_homskillinfoblock(struct map_session_data *sd) { //[orn]
  1294. struct homun_data *hd;
  1295. int fd = sd->fd;
  1296. int i,j,len=4,id;
  1297. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1298. hd = sd->hd;
  1299. if ( !hd )
  1300. return 0 ;
  1301. WFIFOW(fd,0)=0x235;
  1302. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1303. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1304. j = id - HM_SKILLBASE - 1 ;
  1305. WFIFOW(fd,len ) = id ;
  1306. WFIFOW(fd,len+2) = skill_get_inf(id) ;
  1307. WFIFOW(fd,len+4) = 0 ;
  1308. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv ;
  1309. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv) ;
  1310. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv) ;
  1311. strncpy(WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH) ;
  1312. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1313. len+=37;
  1314. }
  1315. }
  1316. WFIFOW(fd,2)=len;
  1317. WFIFOSET(fd,len);
  1318. return 0;
  1319. }
  1320. void clif_homskillup(struct map_session_data *sd, int skill_num) { //[orn]
  1321. struct homun_data *hd;
  1322. int fd=sd->fd, skillid;
  1323. WFIFOHEAD(fd, packet_len(0x239));
  1324. nullpo_retv(sd);
  1325. skillid = skill_num - HM_SKILLBASE - 1;
  1326. hd=sd->hd;
  1327. WFIFOW(fd,0) = 0x239;
  1328. WFIFOW(fd,2) = skill_num;
  1329. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1330. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1331. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1332. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1333. WFIFOSET(fd,packet_len(0x239));
  1334. return;
  1335. }
  1336. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1337. {
  1338. int fd=sd->fd;
  1339. WFIFOHEAD(fd,packet_len(0x22f));
  1340. WFIFOW(fd,0)=0x22f;
  1341. WFIFOB(fd,2)=fail;
  1342. WFIFOW(fd,3)=foodid;
  1343. WFIFOSET(fd,packet_len(0x22f));
  1344. return 0;
  1345. }
  1346. /*==========================================
  1347. *
  1348. *------------------------------------------
  1349. */
  1350. int clif_walkok(struct map_session_data *sd)
  1351. {
  1352. int fd=sd->fd;
  1353. WFIFOHEAD(fd, packet_len(0x87));
  1354. WFIFOW(fd,0)=0x87;
  1355. WFIFOL(fd,2)=gettick();
  1356. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1357. WFIFOSET(fd,packet_len(0x87));
  1358. return 0;
  1359. }
  1360. /*==========================================
  1361. *
  1362. *------------------------------------------
  1363. */
  1364. int clif_movepc(struct map_session_data *sd) {
  1365. unsigned char buf[256];
  1366. nullpo_retr(0, sd);
  1367. if (map[sd->bl.m].flag.snow
  1368. || map[sd->bl.m].flag.clouds
  1369. || map[sd->bl.m].flag.fog
  1370. || map[sd->bl.m].flag.fireworks
  1371. || map[sd->bl.m].flag.sakura
  1372. || map[sd->bl.m].flag.leaves
  1373. || map[sd->bl.m].flag.rain
  1374. || map[sd->bl.m].flag.clouds2
  1375. ) {
  1376. memset(buf,0,packet_len(0x7b));
  1377. WBUFW(buf,0)=0x7b;
  1378. WBUFL(buf,2)=-10;
  1379. WBUFW(buf,6)=sd->battle_status.speed;
  1380. WBUFW(buf,8)=0;
  1381. WBUFW(buf,10)=0;
  1382. WBUFW(buf,12)=OPTION_INVISIBLE;
  1383. WBUFW(buf,14)=100;
  1384. WBUFL(buf,22)=gettick();
  1385. WBUFPOS2(buf,50,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1386. WBUFB(buf,56)=5;
  1387. WBUFB(buf,57)=5;
  1388. clif_send(buf, packet_len(0x7b), &sd->bl, SELF);
  1389. }
  1390. return 0;
  1391. }
  1392. /*==========================================
  1393. *
  1394. *------------------------------------------
  1395. */
  1396. int clif_move(struct block_list *bl) {
  1397. struct view_data *vd;
  1398. struct unit_data *ud;
  1399. unsigned char buf[256];
  1400. int len;
  1401. nullpo_retr(0, bl);
  1402. vd = status_get_viewdata(bl);
  1403. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1404. return 0;
  1405. ud = unit_bl2ud(bl);
  1406. nullpo_retr(0, ud);
  1407. len = clif_set007b(bl,vd,ud,buf);
  1408. clif_send(buf,len,bl,AREA_WOS);
  1409. if (disguised(bl))
  1410. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  1411. //Stupid client that needs this resent every time someone walks :X
  1412. if(vd->cloth_color)
  1413. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1414. switch(bl->type)
  1415. {
  1416. case BL_PC:
  1417. {
  1418. TBL_PC *sd = ((TBL_PC*)bl);
  1419. // clif_movepc(sd);
  1420. if(sd->state.size==2) // tiny/big players [Valaris]
  1421. clif_specialeffect(&sd->bl,423,AREA);
  1422. else if(sd->state.size==1)
  1423. clif_specialeffect(&sd->bl,421,AREA);
  1424. }
  1425. break;
  1426. case BL_MOB:
  1427. {
  1428. TBL_MOB *md = ((TBL_MOB*)bl);
  1429. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1430. clif_specialeffect(&md->bl,423,AREA);
  1431. else if(md->special_state.size==1)
  1432. clif_specialeffect(&md->bl,421,AREA);
  1433. }
  1434. break;
  1435. }
  1436. return 0;
  1437. }
  1438. /*==========================================
  1439. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1440. *------------------------------------------
  1441. */
  1442. static int clif_delayquit(int tid, unsigned int tick, int id, int data) {
  1443. struct map_session_data *sd = NULL;
  1444. //Remove player from map server
  1445. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1446. map_quit(sd);
  1447. return 0;
  1448. }
  1449. /*==========================================
  1450. *
  1451. *------------------------------------------
  1452. */
  1453. void clif_quitsave(int fd,struct map_session_data *sd)
  1454. {
  1455. if (sd->state.waitingdisconnect || //Was already waiting to be disconnected.
  1456. !battle_config.prevent_logout ||
  1457. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1458. map_quit(sd);
  1459. else if (sd->fd)
  1460. { //Disassociate session from player (session is deleted after this function was called)
  1461. //And set a timer to make him quit later.
  1462. session[sd->fd]->session_data = NULL;
  1463. sd->fd = 0;
  1464. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1465. }
  1466. }
  1467. /*==========================================
  1468. *
  1469. *------------------------------------------
  1470. */
  1471. static int clif_waitclose(int tid, unsigned int tick, int id, int data) {
  1472. if (session[id] && session[id]->func_parse == clif_parse) //Avoid disconnecting non-players, as pointed out by End of Exam [Skotlex]
  1473. session[id]->eof = 1;
  1474. return 0;
  1475. }
  1476. /*==========================================
  1477. *
  1478. *------------------------------------------
  1479. */
  1480. void clif_setwaitclose(int fd) {
  1481. struct map_session_data *sd;
  1482. // if player is not already in the game (double connection probably)
  1483. if ((sd = (struct map_session_data*)session[fd]->session_data) == NULL) {
  1484. // limited timer, just to send information.
  1485. add_timer(gettick() + 1000, clif_waitclose, fd, 0);
  1486. } else
  1487. add_timer(gettick() + 5000, clif_waitclose, fd, 0);
  1488. }
  1489. /*==========================================
  1490. *
  1491. *------------------------------------------
  1492. */
  1493. int clif_changemap(struct map_session_data *sd, short map, int x, int y) {
  1494. int fd;
  1495. nullpo_retr(0, sd);
  1496. fd = sd->fd;
  1497. WFIFOHEAD(fd, packet_len(0x91));
  1498. WFIFOW(fd,0) = 0x91;
  1499. memcpy(WFIFOP(fd,2), mapindex_id2name(map), MAP_NAME_LENGTH);
  1500. WFIFOW(fd,18) = x;
  1501. WFIFOW(fd,20) = y;
  1502. WFIFOSET(fd, packet_len(0x91));
  1503. return 0;
  1504. }
  1505. /*==========================================
  1506. *
  1507. *------------------------------------------
  1508. */
  1509. int clif_changemapserver(struct map_session_data *sd, char *mapname, int x, int y, int ip, int port) {
  1510. int fd;
  1511. nullpo_retr(0, sd);
  1512. fd = sd->fd;
  1513. WFIFOHEAD(fd, packet_len(0x92));
  1514. WFIFOW(fd,0) = 0x92;
  1515. //Better not trust the null-terminator is there. [Skotlex]
  1516. memcpy(WFIFOP(fd,2), mapname, MAP_NAME_LENGTH);
  1517. WFIFOB(fd,17) = 0; //Null terminator for mapname
  1518. WFIFOW(fd,18) = x;
  1519. WFIFOW(fd,20) = y;
  1520. WFIFOL(fd,22) = ip;
  1521. WFIFOW(fd,26) = port;
  1522. WFIFOSET(fd, packet_len(0x92));
  1523. return 0;
  1524. }
  1525. int clif_blown(struct block_list *bl) {
  1526. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1527. // return clif_fixpos(bl);
  1528. return clif_slide(bl, bl->x, bl->y);
  1529. }
  1530. /*==========================================
  1531. *
  1532. *------------------------------------------
  1533. */
  1534. int clif_fixpos(struct block_list *bl) {
  1535. unsigned char buf[16];
  1536. nullpo_retr(0, bl);
  1537. WBUFW(buf,0)=0x88;
  1538. WBUFL(buf,2)=bl->id;
  1539. WBUFW(buf,6)=bl->x;
  1540. WBUFW(buf,8)=bl->y;
  1541. clif_send(buf, packet_len(0x88), bl, AREA);
  1542. if (disguised(bl)) {
  1543. WBUFL(buf,2)=-bl->id;
  1544. clif_send(buf, packet_len(0x88), bl, SELF);
  1545. }
  1546. return 0;
  1547. }
  1548. /*==========================================
  1549. *
  1550. *------------------------------------------
  1551. */
  1552. int clif_npcbuysell(struct map_session_data* sd, int id) {
  1553. int fd;
  1554. nullpo_retr(0, sd);
  1555. fd=sd->fd;
  1556. WFIFOHEAD(fd, packet_len(0xc4));
  1557. WFIFOW(fd,0)=0xc4;
  1558. WFIFOL(fd,2)=id;
  1559. WFIFOSET(fd,packet_len(0xc4));
  1560. return 0;
  1561. }
  1562. /*==========================================
  1563. *
  1564. *------------------------------------------
  1565. */
  1566. int clif_buylist(struct map_session_data *sd, struct npc_data *nd) {
  1567. struct item_data *id;
  1568. int fd,i,val;
  1569. nullpo_retr(0, sd);
  1570. nullpo_retr(0, nd);
  1571. fd=sd->fd;
  1572. WFIFOHEAD(fd, 200 * 11 + 4);
  1573. WFIFOW(fd,0)=0xc6;
  1574. for(i=0;nd->u.shop_item[i].nameid > 0;i++){
  1575. id = itemdb_search(nd->u.shop_item[i].nameid);
  1576. val=nd->u.shop_item[i].value;
  1577. WFIFOL(fd,4+i*11)=val;
  1578. if (!id->flag.value_notdc)
  1579. val=pc_modifybuyvalue(sd,val);
  1580. WFIFOL(fd,8+i*11)=val;
  1581. WFIFOB(fd,12+i*11)=itemtype(id->type);
  1582. if (id->view_id > 0)
  1583. WFIFOW(fd,13+i*11)=id->view_id;
  1584. else
  1585. WFIFOW(fd,13+i*11)=nd->u.shop_item[i].nameid;
  1586. }
  1587. WFIFOW(fd,2)=i*11+4;
  1588. WFIFOSET(fd,WFIFOW(fd,2));
  1589. return 0;
  1590. }
  1591. /*==========================================
  1592. *
  1593. *------------------------------------------
  1594. */
  1595. int clif_selllist(struct map_session_data *sd) {
  1596. int fd,i,c=0,val;
  1597. nullpo_retr(0, sd);
  1598. fd=sd->fd;
  1599. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1600. WFIFOW(fd,0)=0xc7;
  1601. for(i=0;i<MAX_INVENTORY;i++) {
  1602. if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
  1603. if (!itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)))
  1604. continue;
  1605. val=sd->inventory_data[i]->value_sell;
  1606. if (val < 0)
  1607. continue;
  1608. WFIFOW(fd,4+c*10)=i+2;
  1609. WFIFOL(fd,6+c*10)=val;
  1610. if (!sd->inventory_data[i]->flag.value_notoc)
  1611. val=pc_modifysellvalue(sd,val);
  1612. WFIFOL(fd,10+c*10)=val;
  1613. c++;
  1614. }
  1615. }
  1616. WFIFOW(fd,2)=c*10+4;
  1617. WFIFOSET(fd,WFIFOW(fd,2));
  1618. return 0;
  1619. }
  1620. /*==========================================
  1621. *
  1622. *------------------------------------------
  1623. */
  1624. int clif_scriptmes(struct map_session_data *sd, int npcid, char *mes) {
  1625. int fd = sd->fd;
  1626. int slen = strlen(mes) + 9;
  1627. WFIFOHEAD(fd, slen);
  1628. WFIFOW(fd,0)=0xb4;
  1629. WFIFOW(fd,2)=slen;
  1630. WFIFOL(fd,4)=npcid;
  1631. strcpy((char*)WFIFOP(fd,8),mes);
  1632. WFIFOSET(fd,WFIFOW(fd,2));
  1633. return 0;
  1634. }
  1635. /*==========================================
  1636. *
  1637. *------------------------------------------
  1638. */
  1639. int clif_scriptnext(struct map_session_data *sd,int npcid) {
  1640. int fd;
  1641. nullpo_retr(0, sd);
  1642. fd=sd->fd;
  1643. WFIFOHEAD(fd, packet_len(0xb5));
  1644. WFIFOW(fd,0)=0xb5;
  1645. WFIFOL(fd,2)=npcid;
  1646. WFIFOSET(fd,packet_len(0xb5));
  1647. return 0;
  1648. }
  1649. /*==========================================
  1650. *
  1651. *------------------------------------------
  1652. */
  1653. int clif_scriptclose(struct map_session_data *sd, int npcid) {
  1654. int fd;
  1655. nullpo_retr(0, sd);
  1656. fd=sd->fd;
  1657. WFIFOHEAD(fd, packet_len(0xb6));
  1658. WFIFOW(fd,0)=0xb6;
  1659. WFIFOL(fd,2)=npcid;
  1660. WFIFOSET(fd,packet_len(0xb6));
  1661. return 0;
  1662. }
  1663. /*==========================================
  1664. *
  1665. *------------------------------------------
  1666. */
  1667. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1668. int fd = sd->fd;
  1669. WFIFOHEAD(fd, packet_len(0x78));
  1670. sd->state.using_fake_npc = 1;
  1671. memset(WFIFOP(fd,0), 0, packet_len(0x78));
  1672. WFIFOW(fd,0)=0x78;
  1673. WFIFOL(fd,2)=npcid;
  1674. WFIFOW(fd,14)=111;
  1675. WFIFOPOS(fd,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1676. WFIFOB(fd,49)=5;
  1677. WFIFOB(fd,50)=5;
  1678. WFIFOSET(fd, packet_len(0x78));
  1679. return;
  1680. }
  1681. /*==========================================
  1682. *
  1683. *------------------------------------------
  1684. */
  1685. int clif_scriptmenu(struct map_session_data *sd, int npcid, char *mes) {
  1686. int fd = sd->fd;
  1687. int slen = strlen(mes) + 8;
  1688. struct block_list *bl = NULL;
  1689. WFIFOHEAD(fd, slen);
  1690. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1691. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1692. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1693. clif_sendfakenpc(sd, npcid);
  1694. WFIFOW(fd,0)=0xb7;
  1695. WFIFOW(fd,2)=slen;
  1696. WFIFOL(fd,4)=npcid;
  1697. strcpy((char*)WFIFOP(fd,8),mes);
  1698. WFIFOSET(fd,WFIFOW(fd,2));
  1699. return 0;
  1700. }
  1701. /*==========================================
  1702. *
  1703. *------------------------------------------
  1704. */
  1705. int clif_scriptinput(struct map_session_data *sd, int npcid) {
  1706. int fd;
  1707. struct block_list *bl = NULL;
  1708. nullpo_retr(0, sd);
  1709. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1710. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1711. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1712. clif_sendfakenpc(sd, npcid);
  1713. fd=sd->fd;
  1714. WFIFOHEAD(fd, packet_len(0x142));
  1715. WFIFOW(fd,0)=0x142;
  1716. WFIFOL(fd,2)=npcid;
  1717. WFIFOSET(fd,packet_len(0x142));
  1718. return 0;
  1719. }
  1720. /*==========================================
  1721. *
  1722. *------------------------------------------
  1723. */
  1724. int clif_scriptinputstr(struct map_session_data *sd, int npcid) {
  1725. int fd;
  1726. struct block_list *bl = NULL;
  1727. nullpo_retr(0, sd);
  1728. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1729. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1730. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1731. clif_sendfakenpc(sd, npcid);
  1732. fd=sd->fd;
  1733. WFIFOHEAD(fd, packet_len(0x1d4));
  1734. WFIFOW(fd,0)=0x1d4;
  1735. WFIFOL(fd,2)=npcid;
  1736. WFIFOSET(fd,packet_len(0x1d4));
  1737. return 0;
  1738. }
  1739. /*==========================================
  1740. *
  1741. *------------------------------------------
  1742. */
  1743. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color) {
  1744. int fd;
  1745. nullpo_retr(0, sd);
  1746. fd=sd->fd;
  1747. WFIFOHEAD(fd, packet_len(0x144));
  1748. WFIFOW(fd,0)=0x144;
  1749. WFIFOL(fd,2)=npc_id;
  1750. WFIFOL(fd,6)=type;
  1751. WFIFOL(fd,10)=x;
  1752. WFIFOL(fd,14)=y;
  1753. WFIFOB(fd,18)=id;
  1754. WFIFOL(fd,19)=color;
  1755. WFIFOSET(fd,packet_len(0x144));
  1756. return 0;
  1757. }
  1758. /*==========================================
  1759. *
  1760. *------------------------------------------
  1761. */
  1762. int clif_cutin(struct map_session_data *sd, char *image, int type) {
  1763. int fd;
  1764. nullpo_retr(0, sd);
  1765. fd=sd->fd;
  1766. WFIFOHEAD(fd, packet_len(0x1b3));
  1767. WFIFOW(fd,0)=0x1b3;
  1768. strncpy((char*)WFIFOP(fd,2),image,64);
  1769. WFIFOB(fd,66)=type;
  1770. WFIFOSET(fd,packet_len(0x1b3));
  1771. return 0;
  1772. }
  1773. /*==========================================
  1774. * Fills in card data from the given item and into the buffer. [Skotlex]
  1775. *------------------------------------------
  1776. */
  1777. static void clif_addcards(unsigned char* buf, struct item* item)
  1778. {
  1779. int i=0,j;
  1780. if (item == NULL) { //Blank data
  1781. WBUFW(buf,0)=0;
  1782. WBUFW(buf,2)=0;
  1783. WBUFW(buf,4)=0;
  1784. WBUFW(buf,6)=0;
  1785. return;
  1786. }
  1787. if(item->card[0]==CARD0_PET) { //pet eggs
  1788. WBUFW(buf,0)=0;
  1789. WBUFW(buf,2)=0;
  1790. WBUFW(buf,4)=0;
  1791. WBUFW(buf,6)=item->card[3]; //Pet renamed flag.
  1792. return;
  1793. }
  1794. if(item->card[0]==CARD0_FORGE || item->card[0]==CARD0_CREATE) { //Forged/created items
  1795. WBUFW(buf,0)=item->card[0];
  1796. WBUFW(buf,2)=item->card[1];
  1797. WBUFW(buf,4)=item->card[2];
  1798. WBUFW(buf,6)=item->card[3];
  1799. return;
  1800. }
  1801. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1802. if (MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4)
  1803. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1804. //Normal items.
  1805. if (item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1806. WBUFW(buf,0)=j;
  1807. else
  1808. WBUFW(buf,0)= item->card[i];
  1809. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1810. WBUFW(buf,2)=j;
  1811. else
  1812. WBUFW(buf,2)=item->card[i];
  1813. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1814. WBUFW(buf,4)=j;
  1815. else
  1816. WBUFW(buf,4)=item->card[i];
  1817. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1818. WBUFW(buf,6)=j;
  1819. else
  1820. WBUFW(buf,6)=item->card[i];
  1821. }
  1822. /*==========================================
  1823. *
  1824. *------------------------------------------
  1825. */
  1826. int clif_additem(struct map_session_data *sd, int n, int amount, int fail) {
  1827. int fd;
  1828. unsigned char *buf;
  1829. nullpo_retr(0, sd);
  1830. fd = sd->fd;
  1831. if (!session_isActive(fd)) //Sasuke-
  1832. return 0;
  1833. WFIFOHEAD(fd,packet_len(0xa0));
  1834. buf = WFIFOP(fd,0);
  1835. if(fail) {
  1836. WBUFW(buf,0)=0xa0;
  1837. WBUFW(buf,2)=n+2;
  1838. WBUFW(buf,4)=amount;
  1839. WBUFW(buf,6)=0;
  1840. WBUFB(buf,8)=0;
  1841. WBUFB(buf,9)=0;
  1842. WBUFB(buf,10)=0;
  1843. WBUFW(buf,11)=0;
  1844. WBUFW(buf,13)=0;
  1845. WBUFW(buf,15)=0;
  1846. WBUFW(buf,17)=0;
  1847. WBUFW(buf,19)=0;
  1848. WBUFB(buf,21)=0;
  1849. WBUFB(buf,22)=fail;
  1850. } else {
  1851. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1852. return 1;
  1853. WBUFW(buf,0)=0xa0;
  1854. WBUFW(buf,2)=n+2;
  1855. WBUFW(buf,4)=amount;
  1856. if (sd->inventory_data[n]->view_id > 0)
  1857. WBUFW(buf,6)=sd->inventory_data[n]->view_id;
  1858. else
  1859. WBUFW(buf,6)=sd->status.inventory[n].nameid;
  1860. WBUFB(buf,8)=sd->status.inventory[n].identify;
  1861. WBUFB(buf,9)=sd->status.inventory[n].attribute;
  1862. WBUFB(buf,10)=sd->status.inventory[n].refine;
  1863. clif_addcards(WBUFP(buf,11), &sd->status.inventory[n]);
  1864. WBUFW(buf,19)=pc_equippoint(sd,n);
  1865. WBUFB(buf,21)=itemtype(sd->inventory_data[n]->type);
  1866. WBUFB(buf,22)=fail;
  1867. }
  1868. WFIFOSET(fd,packet_len(0xa0));
  1869. return 0;
  1870. }
  1871. /*==========================================
  1872. *
  1873. *------------------------------------------
  1874. */
  1875. int clif_delitem(struct map_session_data *sd,int n,int amount)
  1876. {
  1877. int fd;
  1878. nullpo_retr(0, sd);
  1879. fd=sd->fd;
  1880. WFIFOHEAD(fd, packet_len(0xaf));
  1881. WFIFOW(fd,0)=0xaf;
  1882. WFIFOW(fd,2)=n+2;
  1883. WFIFOW(fd,4)=amount;
  1884. WFIFOSET(fd,packet_len(0xaf));
  1885. return 0;
  1886. }
  1887. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1888. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1889. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1890. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1891. {
  1892. if (id->view_id > 0)
  1893. WBUFW(buf,n)=id->view_id;
  1894. else
  1895. WBUFW(buf,n)=i->nameid;
  1896. WBUFB(buf,n+2)=itemtype(id->type);
  1897. WBUFB(buf,n+3)=i->identify;
  1898. if (equip >= 0) { //Equippable item
  1899. WBUFW(buf,n+4)=equip;
  1900. WBUFW(buf,n+6)=i->equip;
  1901. WBUFB(buf,n+8)=i->attribute;
  1902. WBUFB(buf,n+9)=i->refine;
  1903. } else { //Stackable item.
  1904. WBUFW(buf,n+4)=i->amount;
  1905. if (equip == -2 && id->equip == EQP_AMMO)
  1906. WBUFW(buf,n+6)=EQP_AMMO;
  1907. else
  1908. WBUFW(buf,n+6)=0;
  1909. }
  1910. }
  1911. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1912. void clif_inventorylist(struct map_session_data *sd)
  1913. {
  1914. int i,n,ne,fd = sd->fd,arrow=-1;
  1915. unsigned char *buf;
  1916. unsigned char bufe[MAX_INVENTORY*20+4];
  1917. #if PACKETVER < 5
  1918. const int s = 10; //Entry size.
  1919. #else
  1920. const int s = 18;
  1921. #endif
  1922. WFIFOHEAD(fd, MAX_INVENTORY * s + 4);
  1923. buf = WFIFOP(fd,0);
  1924. for(i=0,n=0,ne=0;i<MAX_INVENTORY;i++){
  1925. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1926. continue;
  1927. if(!itemdb_isstackable2(sd->inventory_data[i]))
  1928. { //Non-stackable (Equippable)
  1929. WBUFW(bufe,ne*20+4)=i+2;
  1930. clif_item_sub(bufe, ne*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1931. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.inventory[i]);
  1932. ne++;
  1933. } else { //Stackable.
  1934. WBUFW(buf,n*s+4)=i+2;
  1935. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1936. if (sd->inventory_data[i]->equip == EQP_AMMO &&
  1937. sd->status.inventory[i].equip)
  1938. arrow=i;
  1939. #if PACKETVER >= 5
  1940. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1941. #endif
  1942. n++;
  1943. }
  1944. }
  1945. if (n) {
  1946. #if PACKETVER < 5
  1947. WBUFW(buf,0)=0xa3;
  1948. #else
  1949. WBUFW(buf,0)=0x1ee;
  1950. #endif
  1951. WBUFW(buf,2)=4+n*s;
  1952. WFIFOSET(fd,WFIFOW(fd,2));
  1953. }
  1954. if(arrow >= 0)
  1955. clif_arrowequip(sd,arrow);
  1956. if(ne){
  1957. WBUFW(bufe,0)=0xa4;
  1958. WBUFW(bufe,2)=4+ne*20;
  1959. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1960. }
  1961. }
  1962. //Required when items break/get-repaired. Only sends equippable item list.
  1963. void clif_equiplist(struct map_session_data *sd)
  1964. {
  1965. int i,n,fd = sd->fd;
  1966. unsigned char *buf;
  1967. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  1968. buf = WFIFOP(fd,0);
  1969. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1970. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1971. continue;
  1972. if(itemdb_isstackable2(sd->inventory_data[i]))
  1973. continue;
  1974. //Equippable
  1975. WBUFW(buf,n*20+4)=i+2;
  1976. clif_item_sub(buf, n*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1977. clif_addcards(WBUFP(buf, n*20+16), &sd->status.inventory[i]);
  1978. n++;
  1979. }
  1980. if (n) {
  1981. WBUFW(buf,0)=0xa4;
  1982. WBUFW(buf,2)=4+n*20;
  1983. WFIFOSET(fd,WFIFOW(fd,2));
  1984. }
  1985. }
  1986. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1987. void clif_storagelist(struct map_session_data *sd,struct storage *stor)
  1988. {
  1989. struct item_data *id;
  1990. int i,n,ne,fd=sd->fd;
  1991. unsigned char *buf;
  1992. unsigned char bufe[MAX_STORAGE*20+4];
  1993. #if PACKETVER < 5
  1994. const int s = 10; //Entry size.
  1995. #else
  1996. const int s = 18;
  1997. #endif
  1998. WFIFOHEAD(fd,MAX_STORAGE * s + 4);
  1999. buf = WFIFOP(fd,0);
  2000. for(i=0,n=0,ne=0;i<MAX_STORAGE;i++){
  2001. if(stor->storage_[i].nameid<=0)
  2002. continue;
  2003. id = itemdb_search(stor->storage_[i].nameid);
  2004. if(!itemdb_isstackable2(id))
  2005. { //Equippable
  2006. WBUFW(bufe,ne*20+4)=i+1;
  2007. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  2008. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  2009. ne++;
  2010. } else { //Stackable
  2011. WBUFW(buf,n*s+4)=i+1;
  2012. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  2013. #if PACKETVER >= 5
  2014. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  2015. #endif
  2016. n++;
  2017. }
  2018. }
  2019. if(n){
  2020. #if PACKETVER < 5
  2021. WBUFW(buf,0)=0xa5;
  2022. #else
  2023. WBUFW(buf,0)=0x1f0;
  2024. #endif
  2025. WBUFW(buf,2)=4+n*s;
  2026. WFIFOSET(fd,WFIFOW(fd,2));
  2027. }
  2028. if(ne){
  2029. WBUFW(bufe,0)=0xa6;
  2030. WBUFW(bufe,2)=4+ne*20;
  2031. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2032. }
  2033. }
  2034. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2035. void clif_guildstoragelist(struct map_session_data *sd,struct guild_storage *stor)
  2036. {
  2037. struct item_data *id;
  2038. int i,n,ne,fd=sd->fd;
  2039. unsigned char *buf;
  2040. unsigned char bufe[MAX_GUILD_STORAGE*20+4];
  2041. #if PACKETVER < 5
  2042. const int s = 10; //Entry size.
  2043. #else
  2044. const int s = 18;
  2045. #endif
  2046. WFIFOHEAD(fd,MAX_GUILD_STORAGE * s + 4);
  2047. buf = WFIFOP(fd,0);
  2048. for(i=0,n=0,ne=0;i<MAX_GUILD_STORAGE;i++){
  2049. if(stor->storage_[i].nameid<=0)
  2050. continue;
  2051. id = itemdb_search(stor->storage_[i].nameid);
  2052. if(!itemdb_isstackable2(id))
  2053. { //Equippable
  2054. WBUFW(bufe,ne*20+4)=i+1;
  2055. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  2056. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  2057. ne++;
  2058. } else { //Stackable
  2059. WBUFW(buf,n*s+4)=i+1;
  2060. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  2061. #if PACKETVER >= 5
  2062. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  2063. #endif
  2064. n++;
  2065. }
  2066. }
  2067. if(n){
  2068. #if PACKETVER < 5
  2069. WBUFW(buf,0)=0xa5;
  2070. #else
  2071. WBUFW(buf,0)=0x1f0;
  2072. #endif
  2073. WBUFW(buf,2)=4+n*s;
  2074. WFIFOSET(fd,WFIFOW(fd,2));
  2075. }
  2076. if(ne){
  2077. WBUFW(bufe,0)=0xa6;
  2078. WBUFW(bufe,2)=4+ne*20;
  2079. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2080. }
  2081. }
  2082. void clif_cartlist(struct map_session_data *sd)
  2083. {
  2084. struct item_data *id;
  2085. int i,n,ne,fd=sd->fd;
  2086. unsigned char *buf;
  2087. unsigned char bufe[MAX_CART*20+4];
  2088. #if PACKETVER < 5
  2089. const int s = 10; //Entry size.
  2090. #else
  2091. const int s = 18;
  2092. #endif
  2093. WFIFOHEAD(fd, MAX_CART * s + 4);
  2094. buf = WFIFOP(fd,0);
  2095. for(i=0,n=0,ne=0;i<MAX_CART;i++){
  2096. if(sd->status.cart[i].nameid<=0)
  2097. continue;
  2098. id = itemdb_search(sd->status.cart[i].nameid);
  2099. if(!itemdb_isstackable2(id))
  2100. { //Equippable
  2101. WBUFW(bufe,ne*20+4)=i+2;
  2102. clif_item_sub(bufe, ne*20+6, &sd->status.cart[i], id, id->equip);
  2103. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.cart[i]);
  2104. ne++;
  2105. } else { //Stackable
  2106. WBUFW(buf,n*s+4)=i+2;
  2107. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  2108. #if PACKETVER >= 5
  2109. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  2110. #endif
  2111. n++;
  2112. }
  2113. }
  2114. if(n){
  2115. #if PACKETVER < 5
  2116. WBUFW(buf,0)=0x123;
  2117. #else
  2118. WBUFW(buf,0)=0x1ef;
  2119. #endif
  2120. WBUFW(buf,2)=4+n*s;
  2121. WFIFOSET(fd,WFIFOW(fd,2));
  2122. }
  2123. if(ne){
  2124. WBUFW(bufe,0)=0x122;
  2125. WBUFW(bufe,2)=4+ne*20;
  2126. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2127. }
  2128. return;
  2129. }
  2130. // Guild XY locators [Valaris]
  2131. int clif_guild_xy(struct map_session_data *sd)
  2132. {
  2133. unsigned char buf[10];
  2134. nullpo_retr(0, sd);
  2135. WBUFW(buf,0)=0x1eb;
  2136. WBUFL(buf,2)=sd->status.account_id;
  2137. WBUFW(buf,6)=sd->bl.x;
  2138. WBUFW(buf,8)=sd->bl.y;
  2139. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2140. return 0;
  2141. }
  2142. /*==========================================
  2143. * Sends x/y dot to a single fd. [Skotlex]
  2144. *------------------------------------------
  2145. */
  2146. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  2147. {
  2148. WFIFOHEAD(fd,packet_len(0x1eb));
  2149. WFIFOW(fd,0)=0x1eb;
  2150. WFIFOL(fd,2)=sd->status.account_id;
  2151. WFIFOW(fd,6)=sd->bl.x;
  2152. WFIFOW(fd,8)=sd->bl.y;
  2153. WFIFOSET(fd,packet_len(0x1eb));
  2154. return 0;
  2155. }
  2156. // Guild XY locators [Valaris]
  2157. int clif_guild_xy_remove(struct map_session_data *sd)
  2158. {
  2159. unsigned char buf[10];
  2160. nullpo_retr(0, sd);
  2161. WBUFW(buf,0)=0x1eb;
  2162. WBUFL(buf,2)=sd->status.account_id;
  2163. WBUFW(buf,6)=-1;
  2164. WBUFW(buf,8)=-1;
  2165. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2166. return 0;
  2167. }
  2168. /*==========================================
  2169. * ステータスを送りつける
  2170. * 表示専用数字はこの中で計算して送る
  2171. *------------------------------------------
  2172. */
  2173. int clif_updatestatus(struct map_session_data *sd,int type)
  2174. {
  2175. int fd,len=8;
  2176. nullpo_retr(0, sd);
  2177. fd=sd->fd;
  2178. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2179. return 0;
  2180. WFIFOHEAD(fd, 14);
  2181. WFIFOW(fd,0)=0xb0;
  2182. WFIFOW(fd,2)=type;
  2183. switch(type){
  2184. // 00b0
  2185. case SP_WEIGHT:
  2186. pc_updateweightstatus(sd);
  2187. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2188. WFIFOW(fd,2)=type;
  2189. WFIFOL(fd,4)=sd->weight;
  2190. break;
  2191. case SP_MAXWEIGHT:
  2192. WFIFOL(fd,4)=sd->max_weight;
  2193. break;
  2194. case SP_SPEED:
  2195. WFIFOL(fd,4)=sd->battle_status.speed;
  2196. break;
  2197. case SP_BASELEVEL:
  2198. WFIFOL(fd,4)=sd->status.base_level;
  2199. break;
  2200. case SP_JOBLEVEL:
  2201. WFIFOL(fd,4)=sd->status.job_level;
  2202. break;
  2203. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2204. WFIFOL(fd,4)=sd->status.karma;
  2205. break;
  2206. case SP_MANNER:
  2207. WFIFOL(fd,4)=sd->status.manner;
  2208. clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
  2209. break;
  2210. case SP_STATUSPOINT:
  2211. WFIFOL(fd,4)=sd->status.status_point;
  2212. break;
  2213. case SP_SKILLPOINT:
  2214. WFIFOL(fd,4)=sd->status.skill_point;
  2215. break;
  2216. case SP_HIT:
  2217. WFIFOL(fd,4)=sd->battle_status.hit;
  2218. break;
  2219. case SP_FLEE1:
  2220. WFIFOL(fd,4)=sd->battle_status.flee;
  2221. break;
  2222. case SP_FLEE2:
  2223. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2224. break;
  2225. case SP_MAXHP:
  2226. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2227. break;
  2228. case SP_MAXSP:
  2229. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2230. break;
  2231. case SP_HP:
  2232. WFIFOL(fd,4)=sd->battle_status.hp;
  2233. if (battle_config.disp_hpmeter)
  2234. clif_hpmeter(sd);
  2235. if (!battle_config.party_hp_mode && sd->status.party_id)
  2236. clif_party_hp(sd);
  2237. break;
  2238. case SP_SP:
  2239. WFIFOL(fd,4)=sd->battle_status.sp;
  2240. break;
  2241. case SP_ASPD:
  2242. WFIFOL(fd,4)=sd->battle_status.amotion;
  2243. break;
  2244. case SP_ATK1:
  2245. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw->atk;
  2246. break;
  2247. case SP_DEF1:
  2248. WFIFOL(fd,4)=sd->battle_status.def;
  2249. break;
  2250. case SP_MDEF1:
  2251. WFIFOL(fd,4)=sd->battle_status.mdef;
  2252. break;
  2253. case SP_ATK2:
  2254. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw->atk2;
  2255. break;
  2256. case SP_DEF2:
  2257. WFIFOL(fd,4)=sd->battle_status.def2;
  2258. break;
  2259. case SP_MDEF2:
  2260. //negative check (in case you have something like Berserk active)
  2261. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2262. if (len < 0) len = 0;
  2263. WFIFOL(fd,4)= len;
  2264. len = 8;
  2265. break;
  2266. case SP_CRITICAL:
  2267. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2268. break;
  2269. case SP_MATK1:
  2270. WFIFOL(fd,4)=sd->battle_status.matk_max;
  2271. break;
  2272. case SP_MATK2:
  2273. WFIFOL(fd,4)=sd->battle_status.matk_min;
  2274. break;
  2275. case SP_ZENY:
  2276. WFIFOW(fd,0)=0xb1;
  2277. WFIFOL(fd,4)=sd->status.zeny;
  2278. break;
  2279. case SP_BASEEXP:
  2280. WFIFOW(fd,0)=0xb1;
  2281. WFIFOL(fd,4)=sd->status.base_exp;
  2282. break;
  2283. case SP_JOBEXP:
  2284. WFIFOW(fd,0)=0xb1;
  2285. WFIFOL(fd,4)=sd->status.job_exp;
  2286. break;
  2287. case SP_NEXTBASEEXP:
  2288. WFIFOW(fd,0)=0xb1;
  2289. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2290. break;
  2291. case SP_NEXTJOBEXP:
  2292. WFIFOW(fd,0)=0xb1;
  2293. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2294. break;
  2295. // 00be 終了
  2296. case SP_USTR:
  2297. case SP_UAGI:
  2298. case SP_UVIT:
  2299. case SP_UINT:
  2300. case SP_UDEX:
  2301. case SP_ULUK:
  2302. WFIFOW(fd,0)=0xbe;
  2303. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2304. len=5;
  2305. break;
  2306. // 013a 終了
  2307. case SP_ATTACKRANGE:
  2308. WFIFOW(fd,0)=0x13a;
  2309. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2310. len=4;
  2311. break;
  2312. // 0141 終了
  2313. case SP_STR:
  2314. WFIFOW(fd,0)=0x141;
  2315. WFIFOL(fd,2)=type;
  2316. WFIFOL(fd,6)=sd->status.str;
  2317. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2318. len=14;
  2319. break;
  2320. case SP_AGI:
  2321. WFIFOW(fd,0)=0x141;
  2322. WFIFOL(fd,2)=type;
  2323. WFIFOL(fd,6)=sd->status.agi;
  2324. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2325. len=14;
  2326. break;
  2327. case SP_VIT:
  2328. WFIFOW(fd,0)=0x141;
  2329. WFIFOL(fd,2)=type;
  2330. WFIFOL(fd,6)=sd->status.vit;
  2331. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2332. len=14;
  2333. break;
  2334. case SP_INT:
  2335. WFIFOW(fd,0)=0x141;
  2336. WFIFOL(fd,2)=type;
  2337. WFIFOL(fd,6)=sd->status.int_;
  2338. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2339. len=14;
  2340. break;
  2341. case SP_DEX:
  2342. WFIFOW(fd,0)=0x141;
  2343. WFIFOL(fd,2)=type;
  2344. WFIFOL(fd,6)=sd->status.dex;
  2345. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2346. len=14;
  2347. break;
  2348. case SP_LUK:
  2349. WFIFOW(fd,0)=0x141;
  2350. WFIFOL(fd,2)=type;
  2351. WFIFOL(fd,6)=sd->status.luk;
  2352. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2353. len=14;
  2354. break;
  2355. case SP_CARTINFO:
  2356. WFIFOW(fd,0)=0x121;
  2357. WFIFOW(fd,2)=sd->cart_num;
  2358. WFIFOW(fd,4)=sd->cart_max_num;
  2359. WFIFOL(fd,6)=sd->cart_weight;
  2360. WFIFOL(fd,10)=sd->cart_max_weight;
  2361. len=14;
  2362. break;
  2363. default:
  2364. if(battle_config.error_log)
  2365. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2366. return 1;
  2367. }
  2368. WFIFOSET(fd,len);
  2369. return 0;
  2370. }
  2371. int clif_changestatus(struct block_list *bl,int type,int val)
  2372. {
  2373. unsigned char buf[12];
  2374. struct map_session_data *sd = NULL;
  2375. nullpo_retr(0, bl);
  2376. if(bl->type == BL_PC)
  2377. sd = (struct map_session_data *)bl;
  2378. //printf("clif_changestatus id:%d type:%d val:%d\n",bl->id,type,val);
  2379. if(sd){
  2380. WBUFW(buf,0)=0x1ab;
  2381. WBUFL(buf,2)=bl->id;
  2382. WBUFW(buf,6)=type;
  2383. switch(type){
  2384. case SP_MANNER:
  2385. WBUFL(buf,8)=val;
  2386. break;
  2387. default:
  2388. if(battle_config.error_log)
  2389. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2390. return 1;
  2391. }
  2392. clif_send(buf,packet_len(0x1ab),bl,AREA_WOS);
  2393. }
  2394. return 0;
  2395. }
  2396. /*==========================================
  2397. *
  2398. *------------------------------------------
  2399. */
  2400. int clif_changelook(struct block_list *bl,int type,int val)
  2401. {
  2402. unsigned char buf[32];
  2403. struct map_session_data *sd = NULL;
  2404. struct view_data *vd;
  2405. vd = status_get_viewdata(bl);
  2406. nullpo_retr(0, vd);
  2407. BL_CAST(BL_PC, bl, sd);
  2408. switch(type) {
  2409. case LOOK_WEAPON:
  2410. if (sd)
  2411. {
  2412. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2413. val = vd->weapon;
  2414. }
  2415. else vd->weapon = val;
  2416. break;
  2417. case LOOK_SHIELD:
  2418. if (sd)
  2419. {
  2420. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2421. val = vd->shield;
  2422. }
  2423. else vd->shield = val;
  2424. break;
  2425. case LOOK_BASE:
  2426. vd->class_ = val;
  2427. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS)
  2428. vd->weapon = vd->shield = 0;
  2429. if (vd->cloth_color && (
  2430. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2431. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette)
  2432. ))
  2433. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2434. break;
  2435. case LOOK_HAIR:
  2436. vd->hair_style = val;
  2437. break;
  2438. case LOOK_HEAD_BOTTOM:
  2439. vd->head_bottom = val;
  2440. break;
  2441. case LOOK_HEAD_TOP:
  2442. vd->head_top = val;
  2443. break;
  2444. case LOOK_HEAD_MID:
  2445. vd->head_mid = val;
  2446. break;
  2447. case LOOK_HAIR_COLOR:
  2448. vd->hair_color = val;
  2449. break;
  2450. case LOOK_CLOTHES_COLOR:
  2451. if (val && (
  2452. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2453. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette)
  2454. ))
  2455. val = 0;
  2456. vd->cloth_color = val;
  2457. break;
  2458. case LOOK_SHOES:
  2459. #if PACKETVER > 3
  2460. if (sd) {
  2461. int n;
  2462. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2463. if(sd->inventory_data[n]->view_id > 0)
  2464. val = sd->inventory_data[n]->view_id;
  2465. else
  2466. val = sd->status.inventory[n].nameid;
  2467. }
  2468. val = 0;
  2469. }
  2470. #endif
  2471. //Shoes? No packet uses this....
  2472. break;
  2473. }
  2474. #if PACKETVER < 4
  2475. WBUFW(buf,0)=0xc3;
  2476. WBUFL(buf,2)=bl->id;
  2477. WBUFB(buf,6)=type;
  2478. WBUFB(buf,7)=val;
  2479. clif_send(buf,packet_len(0xc3),bl,AREA);
  2480. #else
  2481. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2482. WBUFW(buf,0)=0x1d7;
  2483. WBUFL(buf,2)=bl->id;
  2484. WBUFB(buf,6)=LOOK_WEAPON;
  2485. WBUFW(buf,7)=vd->weapon;
  2486. WBUFW(buf,9)=vd->shield;
  2487. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2488. }
  2489. else
  2490. {
  2491. WBUFW(buf,0)=0x1d7;
  2492. WBUFL(buf,2)=bl->id;
  2493. WBUFB(buf,6)=type;
  2494. WBUFW(buf,7)=val;
  2495. WBUFW(buf,9)=0;
  2496. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2497. }
  2498. #endif
  2499. return 0;
  2500. }
  2501. //Sends a change-base-look packet required for traps as they are triggered.
  2502. void clif_changetraplook(struct block_list *bl,int val)
  2503. {
  2504. unsigned char buf[32];
  2505. #if PACKETVER < 4
  2506. WBUFW(buf,0)=0xc3;
  2507. WBUFL(buf,2)=bl->id;
  2508. WBUFB(buf,6)=LOOK_BASE;
  2509. WBUFB(buf,7)=val;
  2510. clif_send(buf,packet_len(0xc3),bl,AREA);
  2511. #else
  2512. WBUFW(buf,0)=0x1d7;
  2513. WBUFL(buf,2)=bl->id;
  2514. WBUFB(buf,6)=LOOK_BASE;
  2515. WBUFW(buf,7)=val;
  2516. WBUFW(buf,9)=0;
  2517. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2518. #endif
  2519. }
  2520. //For the stupid cloth-dye bug. Resends the given view data
  2521. //to the area specified by bl.
  2522. void clif_refreshlook(struct block_list *bl,int id,int type,int val,int area)
  2523. {
  2524. unsigned char buf[32];
  2525. #if PACKETVER < 4
  2526. WBUFW(buf,0)=0xc3;
  2527. WBUFL(buf,2)=id;
  2528. WBUFB(buf,6)=type;
  2529. WBUFB(buf,7)=val;
  2530. clif_send(buf,packet_len(0xc3),bl,area);
  2531. #else
  2532. WBUFW(buf,0)=0x1d7;
  2533. WBUFL(buf,2)=id;
  2534. WBUFB(buf,6)=type;
  2535. WBUFW(buf,7)=val;
  2536. WBUFW(buf,9)=0;
  2537. clif_send(buf,packet_len(0x1d7),bl,area);
  2538. #endif
  2539. return;
  2540. }
  2541. /*==========================================
  2542. *
  2543. *------------------------------------------
  2544. */
  2545. int clif_initialstatus(struct map_session_data *sd)
  2546. {
  2547. int fd;
  2548. unsigned char *buf;
  2549. nullpo_retr(0, sd);
  2550. fd=sd->fd;
  2551. WFIFOHEAD(fd,packet_len(0xbd));
  2552. buf=WFIFOP(fd,0);
  2553. WBUFW(buf,0)=0xbd;
  2554. WBUFW(buf,2)=(sd->status.status_point > SHRT_MAX)? SHRT_MAX:sd->status.status_point;
  2555. WBUFB(buf,4)=(sd->status.str > UCHAR_MAX)? UCHAR_MAX:sd->status.str;
  2556. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2557. WBUFB(buf,6)=(sd->status.agi > UCHAR_MAX)? UCHAR_MAX:sd->status.agi;
  2558. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2559. WBUFB(buf,8)=(sd->status.vit > UCHAR_MAX)? UCHAR_MAX:sd->status.vit;
  2560. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2561. WBUFB(buf,10)=(sd->status.int_ > UCHAR_MAX)? UCHAR_MAX:sd->status.int_;
  2562. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2563. WBUFB(buf,12)=(sd->status.dex > UCHAR_MAX)? UCHAR_MAX:sd->status.dex;
  2564. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2565. WBUFB(buf,14)=(sd->status.luk > UCHAR_MAX)? UCHAR_MAX:sd->status.luk;
  2566. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2567. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw->atk;
  2568. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw->atk2; //atk bonus
  2569. WBUFW(buf,20) = sd->battle_status.matk_max;
  2570. WBUFW(buf,22) = sd->battle_status.matk_min;
  2571. WBUFW(buf,24) = sd->battle_status.def; // def
  2572. WBUFW(buf,26) = sd->battle_status.def2;
  2573. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2574. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2575. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2576. WBUFW(buf,30) = fd;
  2577. fd = sd->fd;
  2578. WBUFW(buf,32) = sd->battle_status.hit;
  2579. WBUFW(buf,34) = sd->battle_status.flee;
  2580. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2581. WBUFW(buf,38) = sd->battle_status.cri/10;
  2582. WBUFW(buf,40) = sd->status.karma;
  2583. WBUFW(buf,42) = sd->status.manner;
  2584. WFIFOSET(fd,packet_len(0xbd));
  2585. clif_updatestatus(sd,SP_STR);
  2586. clif_updatestatus(sd,SP_AGI);
  2587. clif_updatestatus(sd,SP_VIT);
  2588. clif_updatestatus(sd,SP_INT);
  2589. clif_updatestatus(sd,SP_DEX);
  2590. clif_updatestatus(sd,SP_LUK);
  2591. clif_updatestatus(sd,SP_ATTACKRANGE);
  2592. clif_updatestatus(sd,SP_ASPD);
  2593. return 0;
  2594. }
  2595. /*==========================================
  2596. *矢装備
  2597. *------------------------------------------
  2598. */
  2599. int clif_arrowequip(struct map_session_data *sd,int val)
  2600. {
  2601. int fd;
  2602. nullpo_retr(0, sd);
  2603. pc_stop_attack(sd); // [Valaris]
  2604. fd=sd->fd;
  2605. WFIFOHEAD(fd, packet_len(0x013c));
  2606. WFIFOW(fd,0)=0x013c;
  2607. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2608. WFIFOSET(fd,packet_len(0x013c));
  2609. return 0;
  2610. }
  2611. /*==========================================
  2612. *
  2613. *------------------------------------------
  2614. */
  2615. int clif_arrow_fail(struct map_session_data *sd,int type)
  2616. {
  2617. int fd;
  2618. nullpo_retr(0, sd);
  2619. fd=sd->fd;
  2620. WFIFOHEAD(fd, packet_len(0x013b));
  2621. WFIFOW(fd,0)=0x013b;
  2622. WFIFOW(fd,2)=type;
  2623. WFIFOSET(fd,packet_len(0x013b));
  2624. return 0;
  2625. }
  2626. /*==========================================
  2627. * 作成可能 矢リスト送信
  2628. *------------------------------------------
  2629. */
  2630. int clif_arrow_create_list(struct map_session_data *sd)
  2631. {
  2632. int i, c, j;
  2633. int fd;
  2634. nullpo_retr(0, sd);
  2635. fd = sd->fd;
  2636. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2637. WFIFOW(fd,0) = 0x1ad;
  2638. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2639. if (skill_arrow_db[i].nameid > 0 &&
  2640. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2641. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2642. {
  2643. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2644. WFIFOW(fd,c*2+4) = j;
  2645. else
  2646. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2647. c++;
  2648. }
  2649. }
  2650. WFIFOW(fd,2) = c*2+4;
  2651. WFIFOSET(fd, WFIFOW(fd,2));
  2652. if (c > 0) {
  2653. sd->menuskill_id = AC_MAKINGARROW;
  2654. sd->menuskill_lv = c;
  2655. }
  2656. return 0;
  2657. }
  2658. /*==========================================
  2659. *
  2660. *------------------------------------------
  2661. */
  2662. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2663. {
  2664. int fd;
  2665. nullpo_retr(0, sd);
  2666. fd=sd->fd;
  2667. WFIFOHEAD(fd,packet_len(0xbc));
  2668. WFIFOW(fd,0)=0xbc;
  2669. WFIFOW(fd,2)=type;
  2670. WFIFOB(fd,4)=ok;
  2671. WFIFOB(fd,5)=val;
  2672. WFIFOSET(fd,packet_len(0xbc));
  2673. return 0;
  2674. }
  2675. /*==========================================
  2676. *
  2677. *------------------------------------------
  2678. */
  2679. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2680. {
  2681. int fd;
  2682. nullpo_retr(0, sd);
  2683. fd=sd->fd;
  2684. WFIFOHEAD(fd,packet_len(0xaa));
  2685. WFIFOW(fd,0)=0xaa;
  2686. WFIFOW(fd,2)=n+2;
  2687. WFIFOW(fd,4)=pos;
  2688. WFIFOB(fd,6)=ok;
  2689. WFIFOSET(fd,packet_len(0xaa));
  2690. return 0;
  2691. }
  2692. /*==========================================
  2693. *
  2694. *------------------------------------------
  2695. */
  2696. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2697. {
  2698. int fd;
  2699. nullpo_retr(0, sd);
  2700. fd=sd->fd;
  2701. WFIFOHEAD(fd,packet_len(0xac));
  2702. WFIFOW(fd,0)=0xac;
  2703. WFIFOW(fd,2)=n+2;
  2704. WFIFOW(fd,4)=pos;
  2705. WFIFOB(fd,6)=ok;
  2706. WFIFOSET(fd,packet_len(0xac));
  2707. return 0;
  2708. }
  2709. /*==========================================
  2710. *
  2711. *------------------------------------------
  2712. */
  2713. int clif_misceffect(struct block_list* bl,int type)
  2714. {
  2715. unsigned char buf[32];
  2716. nullpo_retr(0, bl);
  2717. WBUFW(buf,0) = 0x19b;
  2718. WBUFL(buf,2) = bl->id;
  2719. WBUFL(buf,6) = type;
  2720. clif_send(buf,packet_len(0x19b),bl,AREA);
  2721. return 0;
  2722. }
  2723. int clif_misceffect2(struct block_list *bl, int type) {
  2724. unsigned char buf[24];
  2725. nullpo_retr(0, bl);
  2726. memset(buf, 0, packet_len(0x1f3));
  2727. WBUFW(buf,0) = 0x1f3;
  2728. WBUFL(buf,2) = bl->id;
  2729. WBUFL(buf,6) = type;
  2730. clif_send(buf, packet_len(0x1f3), bl, AREA);
  2731. return 0;
  2732. }
  2733. /*==========================================
  2734. * 表示オプション変更
  2735. *------------------------------------------
  2736. */
  2737. int clif_changeoption(struct block_list* bl)
  2738. {
  2739. unsigned char buf[32];
  2740. struct status_change *sc;
  2741. nullpo_retr(0, bl);
  2742. sc = status_get_sc(bl);
  2743. if (!sc) return 0; //How can an option change if there's no sc?
  2744. #if PACKETVER > 6
  2745. WBUFW(buf,0) = 0x229;
  2746. WBUFL(buf,2) = bl->id;
  2747. WBUFW(buf,6) = sc->opt1;
  2748. WBUFW(buf,8) = sc->opt2;
  2749. WBUFL(buf,10) = sc->option;
  2750. WBUFB(buf,14) = 0; // PK???
  2751. if(disguised(bl)) {
  2752. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2753. WBUFL(buf,2) = -bl->id;
  2754. clif_send(buf,packet_len(0x229),bl,SELF);
  2755. WBUFL(buf,2) = bl->id;
  2756. WBUFL(buf,10) = OPTION_INVISIBLE;
  2757. clif_send(buf,packet_len(0x229),bl,SELF);
  2758. } else
  2759. clif_send(buf,packet_len(0x229),bl,AREA);
  2760. #else
  2761. WBUFW(buf,0) = 0x119;
  2762. WBUFL(buf,2) = bl->id;
  2763. WBUFW(buf,6) = sc->opt1;
  2764. WBUFW(buf,8) = sc->opt2;
  2765. WBUFW(buf,10) = sc->option;
  2766. WBUFB(buf,12) = 0; // ??
  2767. if(disguised(bl)) {
  2768. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2769. WBUFL(buf,2) = -bl->id;
  2770. clif_send(buf,packet_len(0x119),bl,SELF);
  2771. WBUFL(buf,2) = bl->id;
  2772. WBUFW(buf,10) = OPTION_INVISIBLE;
  2773. clif_send(buf,packet_len(0x119),bl,SELF);
  2774. } else
  2775. clif_send(buf,packet_len(0x119),bl,AREA);
  2776. #endif
  2777. return 0;
  2778. }
  2779. /*==========================================
  2780. *
  2781. *------------------------------------------
  2782. */
  2783. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2784. {
  2785. nullpo_retr(0, sd);
  2786. if(!ok) {
  2787. int fd=sd->fd;
  2788. WFIFOHEAD(fd,packet_len(0xa8));
  2789. WFIFOW(fd,0)=0xa8;
  2790. WFIFOW(fd,2)=index+2;
  2791. WFIFOW(fd,4)=amount;
  2792. WFIFOB(fd,6)=ok;
  2793. WFIFOSET(fd,packet_len(0xa8));
  2794. }
  2795. else {
  2796. #if PACKETVER < 3
  2797. int fd=sd->fd;
  2798. WFIFOHEAD(fd,packet_len(0xa8));
  2799. WFIFOW(fd,0)=0xa8;
  2800. WFIFOW(fd,2)=index+2;
  2801. WFIFOW(fd,4)=amount;
  2802. WFIFOB(fd,6)=ok;
  2803. WFIFOSET(fd,packet_len(0xa8));
  2804. #else
  2805. unsigned char buf[32];
  2806. WBUFW(buf,0)=0x1c8;
  2807. WBUFW(buf,2)=index+2;
  2808. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2809. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2810. else
  2811. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2812. WBUFL(buf,6)=sd->bl.id;
  2813. WBUFW(buf,10)=amount;
  2814. WBUFB(buf,12)=ok;
  2815. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2816. #endif
  2817. }
  2818. return 0;
  2819. }
  2820. /*==========================================
  2821. *
  2822. *------------------------------------------
  2823. */
  2824. int clif_createchat(struct map_session_data *sd,int fail)
  2825. {
  2826. int fd;
  2827. nullpo_retr(0, sd);
  2828. fd=sd->fd;
  2829. WFIFOHEAD(fd,packet_len(0xd6));
  2830. WFIFOW(fd,0)=0xd6;
  2831. WFIFOB(fd,2)=fail;
  2832. WFIFOSET(fd,packet_len(0xd6));
  2833. return 0;
  2834. }
  2835. /*==========================================
  2836. *
  2837. *------------------------------------------
  2838. */
  2839. int clif_dispchat(struct chat_data *cd,int fd)
  2840. {
  2841. unsigned char buf[128]; // 最大title(60バイト)+17
  2842. if(cd==NULL || *cd->owner==NULL)
  2843. return 1;
  2844. WBUFW(buf,0)=0xd7;
  2845. WBUFW(buf,2)=strlen((const char*)cd->title)+17;
  2846. WBUFL(buf,4)=(*cd->owner)->id;
  2847. WBUFL(buf,8)=cd->bl.id;
  2848. WBUFW(buf,12)=cd->limit;
  2849. WBUFW(buf,14)=cd->users;
  2850. WBUFB(buf,16)=cd->pub;
  2851. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  2852. if(fd){
  2853. WFIFOHEAD(fd, WBUFW(buf,2));
  2854. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2855. WFIFOSET(fd,WBUFW(buf,2));
  2856. } else {
  2857. clif_send(buf,WBUFW(buf,2),*cd->owner,AREA_WOSC);
  2858. }
  2859. return 0;
  2860. }
  2861. /*==========================================
  2862. * chatの状態変更成功
  2863. * 外部の人用と命令コード(d7->df)が違うだけ
  2864. *------------------------------------------
  2865. */
  2866. int clif_changechatstatus(struct chat_data *cd)
  2867. {
  2868. unsigned char buf[128]; // 最大title(60バイト)+17
  2869. if(cd==NULL || cd->usersd[0]==NULL)
  2870. return 1;
  2871. WBUFW(buf,0)=0xdf;
  2872. WBUFW(buf,2)=strlen((char*)cd->title)+17;
  2873. WBUFL(buf,4)=cd->usersd[0]->bl.id;
  2874. WBUFL(buf,8)=cd->bl.id;
  2875. WBUFW(buf,12)=cd->limit;
  2876. WBUFW(buf,14)=cd->users;
  2877. WBUFB(buf,16)=cd->pub;
  2878. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  2879. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2880. return 0;
  2881. }
  2882. /*==========================================
  2883. *
  2884. *------------------------------------------
  2885. */
  2886. int clif_clearchat(struct chat_data *cd,int fd)
  2887. {
  2888. unsigned char buf[32];
  2889. nullpo_retr(0, cd);
  2890. WBUFW(buf,0)=0xd8;
  2891. WBUFL(buf,2)=cd->bl.id;
  2892. if(fd){
  2893. WFIFOHEAD(fd,packet_len(0xd8));
  2894. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2895. WFIFOSET(fd,packet_len(0xd8));
  2896. } else {
  2897. clif_send(buf,packet_len(0xd8),*cd->owner,AREA_WOSC);
  2898. }
  2899. return 0;
  2900. }
  2901. /*==========================================
  2902. *
  2903. *------------------------------------------
  2904. */
  2905. int clif_joinchatfail(struct map_session_data *sd,int fail)
  2906. {
  2907. int fd;
  2908. nullpo_retr(0, sd);
  2909. fd=sd->fd;
  2910. WFIFOHEAD(fd,packet_len(0xda));
  2911. WFIFOW(fd,0)=0xda;
  2912. WFIFOB(fd,2)=fail;
  2913. WFIFOSET(fd,packet_len(0xda));
  2914. return 0;
  2915. }
  2916. /*==========================================
  2917. *
  2918. *------------------------------------------
  2919. */
  2920. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2921. {
  2922. int fd;
  2923. int i;
  2924. nullpo_retr(0, sd);
  2925. nullpo_retr(0, cd);
  2926. fd = sd->fd;
  2927. if (!session_isActive(fd))
  2928. return 0;
  2929. WFIFOHEAD(fd, 8 + (28*cd->users));
  2930. WFIFOW(fd, 0) = 0xdb;
  2931. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2932. WFIFOL(fd, 4) = cd->bl.id;
  2933. for (i = 0; i < cd->users; i++) {
  2934. WFIFOL(fd, 8+i*28) = (i!=0) || ((*cd->owner)->type == BL_NPC);
  2935. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2936. }
  2937. WFIFOSET(fd, WFIFOW(fd, 2));
  2938. return 0;
  2939. }
  2940. /*==========================================
  2941. *
  2942. *------------------------------------------
  2943. */
  2944. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2945. {
  2946. unsigned char buf[32];
  2947. nullpo_retr(0, sd);
  2948. nullpo_retr(0, cd);
  2949. WBUFW(buf, 0) = 0x0dc;
  2950. WBUFW(buf, 2) = cd->users;
  2951. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2952. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  2953. return 0;
  2954. }
  2955. /*==========================================
  2956. *
  2957. *------------------------------------------
  2958. */
  2959. int clif_changechatowner(struct chat_data* cd,struct map_session_data *sd)
  2960. {
  2961. unsigned char buf[64];
  2962. nullpo_retr(0, sd);
  2963. nullpo_retr(0, cd);
  2964. WBUFW(buf, 0) = 0xe1;
  2965. WBUFL(buf, 2) = 1;
  2966. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2967. WBUFW(buf,30) = 0xe1;
  2968. WBUFL(buf,32) = 0;
  2969. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2970. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  2971. return 0;
  2972. }
  2973. /*==========================================
  2974. *
  2975. *------------------------------------------
  2976. */
  2977. int clif_leavechat(struct chat_data* cd,struct map_session_data *sd)
  2978. {
  2979. unsigned char buf[32];
  2980. nullpo_retr(0, sd);
  2981. nullpo_retr(0, cd);
  2982. WBUFW(buf, 0) = 0xdd;
  2983. WBUFW(buf, 2) = cd->users-1;
  2984. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2985. WBUFB(buf,28) = 0;
  2986. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  2987. return 0;
  2988. }
  2989. /*==========================================
  2990. * 取り引き要請受け
  2991. *------------------------------------------
  2992. */
  2993. int clif_traderequest(struct map_session_data *sd,char *name)
  2994. {
  2995. int fd;
  2996. nullpo_retr(0, sd);
  2997. fd=sd->fd;
  2998. WFIFOHEAD(fd,packet_len(0xe5));
  2999. WFIFOW(fd,0)=0xe5;
  3000. strcpy((char*)WFIFOP(fd,2),name);
  3001. WFIFOSET(fd,packet_len(0xe5));
  3002. return 0;
  3003. }
  3004. /*==========================================
  3005. * 取り引き要求応答
  3006. *------------------------------------------
  3007. */
  3008. int clif_tradestart(struct map_session_data *sd,int type)
  3009. {
  3010. int fd;
  3011. nullpo_retr(0, sd);
  3012. fd=sd->fd;
  3013. WFIFOHEAD(fd,packet_len(0xe7));
  3014. WFIFOW(fd,0)=0xe7;
  3015. WFIFOB(fd,2)=type;
  3016. WFIFOSET(fd,packet_len(0xe7));
  3017. return 0;
  3018. }
  3019. /*==========================================
  3020. * 相手方からのアイテム追加
  3021. *------------------------------------------
  3022. */
  3023. int clif_tradeadditem(struct map_session_data *sd,struct map_session_data *tsd,int index,int amount)
  3024. {
  3025. int fd;
  3026. nullpo_retr(0, sd);
  3027. nullpo_retr(0, tsd);
  3028. fd=tsd->fd;
  3029. WFIFOHEAD(fd,packet_len(0xe9));
  3030. WFIFOW(fd,0)=0xe9;
  3031. WFIFOL(fd,2)=amount;
  3032. if(index==0){
  3033. WFIFOW(fd,6) = 0; // type id
  3034. WFIFOB(fd,8) = 0; //identify flag
  3035. WFIFOB(fd,9) = 0; // attribute
  3036. WFIFOB(fd,10)= 0; //refine
  3037. WFIFOW(fd,11)= 0; //card (4w)
  3038. WFIFOW(fd,13)= 0; //card (4w)
  3039. WFIFOW(fd,15)= 0; //card (4w)
  3040. WFIFOW(fd,17)= 0; //card (4w)
  3041. }
  3042. else{
  3043. index-=2; //index fix
  3044. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3045. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  3046. else
  3047. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  3048. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  3049. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  3050. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  3051. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  3052. }
  3053. WFIFOSET(fd,packet_len(0xe9));
  3054. return 0;
  3055. }
  3056. /*==========================================
  3057. * アイテム追加成功/失敗
  3058. *------------------------------------------
  3059. */
  3060. int clif_tradeitemok(struct map_session_data *sd,int index,int fail)
  3061. {
  3062. int fd;
  3063. nullpo_retr(0, sd);
  3064. fd=sd->fd;
  3065. WFIFOHEAD(fd,packet_len(0xea));
  3066. WFIFOW(fd,0)=0xea;
  3067. WFIFOW(fd,2)=index;
  3068. WFIFOB(fd,4)=fail;
  3069. WFIFOSET(fd,packet_len(0xea));
  3070. return 0;
  3071. }
  3072. /*==========================================
  3073. * 取り引きok押し
  3074. *------------------------------------------
  3075. */
  3076. int clif_tradedeal_lock(struct map_session_data *sd,int fail)
  3077. {
  3078. int fd;
  3079. nullpo_retr(0, sd);
  3080. fd=sd->fd;
  3081. WFIFOHEAD(fd,packet_len(0xec));
  3082. WFIFOW(fd,0)=0xec;
  3083. WFIFOB(fd,2)=fail; // 0=you 1=the other person
  3084. WFIFOSET(fd,packet_len(0xec));
  3085. return 0;
  3086. }
  3087. /*==========================================
  3088. * 取り引きがキャンセルされました
  3089. *------------------------------------------
  3090. */
  3091. int clif_tradecancelled(struct map_session_data *sd)
  3092. {
  3093. int fd;
  3094. nullpo_retr(0, sd);
  3095. fd=sd->fd;
  3096. WFIFOHEAD(fd,packet_len(0xee));
  3097. WFIFOW(fd,0)=0xee;
  3098. WFIFOSET(fd,packet_len(0xee));
  3099. return 0;
  3100. }
  3101. /*==========================================
  3102. * 取り引き完了
  3103. *------------------------------------------
  3104. */
  3105. int clif_tradecompleted(struct map_session_data *sd,int fail)
  3106. {
  3107. int fd;
  3108. nullpo_retr(0, sd);
  3109. fd=sd->fd;
  3110. WFIFOHEAD(fd,packet_len(0xf0));
  3111. WFIFOW(fd,0)=0xf0;
  3112. WFIFOB(fd,2)=fail;
  3113. WFIFOSET(fd,packet_len(0xf0));
  3114. return 0;
  3115. }
  3116. /*==========================================
  3117. * カプラ倉庫のアイテム数を更新
  3118. *------------------------------------------
  3119. */
  3120. int clif_updatestorageamount(struct map_session_data *sd,struct storage *stor)
  3121. {
  3122. int fd;
  3123. nullpo_retr(0, sd);
  3124. nullpo_retr(0, stor);
  3125. fd=sd->fd;
  3126. WFIFOHEAD(fd,packet_len(0xf2));
  3127. WFIFOW(fd,0) = 0xf2; // update storage amount
  3128. WFIFOW(fd,2) = stor->storage_amount; //items
  3129. WFIFOW(fd,4) = MAX_STORAGE; //items max
  3130. WFIFOSET(fd,packet_len(0xf2));
  3131. return 0;
  3132. }
  3133. /*==========================================
  3134. * カプラ倉庫にアイテムを追加する
  3135. *------------------------------------------
  3136. */
  3137. int clif_storageitemadded(struct map_session_data *sd,struct storage *stor,int index,int amount)
  3138. {
  3139. int view,fd;
  3140. nullpo_retr(0, sd);
  3141. nullpo_retr(0, stor);
  3142. fd=sd->fd;
  3143. WFIFOHEAD(fd,packet_len(0xf4));
  3144. WFIFOW(fd,0) =0xf4; // Storage item added
  3145. WFIFOW(fd,2) =index+1; // index
  3146. WFIFOL(fd,4) =amount; // amount
  3147. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3148. WFIFOW(fd,8) =view;
  3149. else
  3150. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3151. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3152. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3153. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3154. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3155. WFIFOSET(fd,packet_len(0xf4));
  3156. return 0;
  3157. }
  3158. /*==========================================
  3159. *
  3160. *------------------------------------------
  3161. */
  3162. int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor)
  3163. {
  3164. int fd;
  3165. nullpo_retr(0, sd);
  3166. nullpo_retr(0, stor);
  3167. fd=sd->fd;
  3168. WFIFOHEAD(fd,packet_len(0xf2));
  3169. WFIFOW(fd,0) = 0xf2; // update storage amount
  3170. WFIFOW(fd,2) = stor->storage_amount; //items
  3171. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  3172. WFIFOSET(fd,packet_len(0xf2));
  3173. return 0;
  3174. }
  3175. /*==========================================
  3176. *
  3177. *------------------------------------------
  3178. */
  3179. int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount)
  3180. {
  3181. int view,fd;
  3182. nullpo_retr(0, sd);
  3183. nullpo_retr(0, stor);
  3184. fd=sd->fd;
  3185. WFIFOHEAD(fd,packet_len(0xf4));
  3186. WFIFOW(fd,0) =0xf4; // Storage item added
  3187. WFIFOW(fd,2) =index+1; // index
  3188. WFIFOL(fd,4) =amount; // amount
  3189. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3190. WFIFOW(fd,8) =view;
  3191. else
  3192. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3193. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3194. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3195. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3196. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3197. WFIFOSET(fd,packet_len(0xf4));
  3198. return 0;
  3199. }
  3200. /*==========================================
  3201. * カプラ倉庫からアイテムを取り去る
  3202. *------------------------------------------
  3203. */
  3204. int clif_storageitemremoved(struct map_session_data *sd,int index,int amount)
  3205. {
  3206. int fd;
  3207. nullpo_retr(0, sd);
  3208. fd=sd->fd;
  3209. WFIFOHEAD(fd,packet_len(0xf6));
  3210. WFIFOW(fd,0)=0xf6; // Storage item removed
  3211. WFIFOW(fd,2)=index+1;
  3212. WFIFOL(fd,4)=amount;
  3213. WFIFOSET(fd,packet_len(0xf6));
  3214. return 0;
  3215. }
  3216. /*==========================================
  3217. * カプラ倉庫を閉じる
  3218. *------------------------------------------
  3219. */
  3220. int clif_storageclose(struct map_session_data *sd)
  3221. {
  3222. int fd;
  3223. nullpo_retr(0, sd);
  3224. fd=sd->fd;
  3225. WFIFOHEAD(fd,packet_len(0xf8));
  3226. WFIFOW(fd,0)=0xf8; // Storage Closed
  3227. WFIFOSET(fd,packet_len(0xf8));
  3228. return 0;
  3229. }
  3230. //
  3231. // callback系 ?
  3232. //
  3233. /*==========================================
  3234. * PC表示
  3235. *------------------------------------------
  3236. */
  3237. void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3238. {
  3239. int len;
  3240. if(dstsd->chatID){
  3241. struct chat_data *cd;
  3242. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  3243. if(cd && cd->usersd[0]==dstsd)
  3244. clif_dispchat(cd,sd->fd);
  3245. }
  3246. if(dstsd->vender_id)
  3247. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3248. if(dstsd->spiritball > 0)
  3249. clif_spiritball_single(sd->fd, dstsd);
  3250. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3251. (battle_config.disp_hpmeter && (len = pc_isGM(sd)) >= battle_config.disp_hpmeter && len >= pc_isGM(dstsd))
  3252. )
  3253. clif_hpmeter_single(sd->fd, dstsd);
  3254. if(dstsd->status.manner < 0)
  3255. clif_changestatus(&dstsd->bl,SP_MANNER,dstsd->status.manner);
  3256. // pvp circle for duel [LuzZza]
  3257. /*
  3258. if(dstsd->duel_group)
  3259. clif_specialeffect(&dstsd->bl, 159, 4);
  3260. */
  3261. }
  3262. void clif_getareachar_char(struct map_session_data* sd,struct block_list *bl)
  3263. {
  3264. struct unit_data *ud;
  3265. struct view_data *vd;
  3266. int len, fd = sd->fd;
  3267. vd = status_get_viewdata(bl);
  3268. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3269. return;
  3270. ud = unit_bl2ud(bl);
  3271. if (ud && ud->walktimer != -1)
  3272. {
  3273. #if PACKETVER > 6
  3274. WFIFOHEAD(fd, packet_len(0x22c));
  3275. #elif PACKETVER > 3
  3276. WFIFOHEAD(fd, packet_len(0x1da));
  3277. #else
  3278. WFIFOHEAD(fd, packet_len(0x7b));
  3279. #endif
  3280. len = clif_set007b(bl,vd,ud,WFIFOP(fd,0));
  3281. WFIFOSET(fd,len);
  3282. } else {
  3283. #if PACKETVER > 6
  3284. WFIFOHEAD(fd,packet_len(0x22a));
  3285. #elif PACKETVER > 3
  3286. WFIFOHEAD(fd,packet_len(0x1d8));
  3287. #else
  3288. WFIFOHEAD(fd,packet_len(0x78));
  3289. #endif
  3290. len = clif_set0078(bl,vd,WFIFOP(fd,0));
  3291. WFIFOSET(fd,len);
  3292. }
  3293. if (vd->cloth_color)
  3294. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3295. switch (bl->type)
  3296. {
  3297. case BL_PC:
  3298. {
  3299. TBL_PC* tsd = (TBL_PC*)bl;
  3300. clif_getareachar_pc(sd, tsd);
  3301. if(tsd->state.size==2) // tiny/big players [Valaris]
  3302. clif_specialeffect(bl,423,AREA);
  3303. else if(tsd->state.size==1)
  3304. clif_specialeffect(bl,421,AREA);
  3305. }
  3306. break;
  3307. case BL_NPC:
  3308. {
  3309. if(((TBL_NPC*)bl)->chat_id)
  3310. clif_dispchat((struct chat_data*)map_id2bl(((TBL_NPC*)bl)->chat_id),sd->fd);
  3311. }
  3312. break;
  3313. case BL_MOB:
  3314. {
  3315. TBL_MOB* md = (TBL_MOB*)bl;
  3316. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3317. clif_specialeffect(bl,423,AREA);
  3318. else if(md->special_state.size==1)
  3319. clif_specialeffect(bl,421,AREA);
  3320. }
  3321. break;
  3322. }
  3323. }
  3324. /*==========================================
  3325. * Older fix pos packet.
  3326. *------------------------------------------
  3327. */
  3328. int clif_fixpos2(struct block_list* bl)
  3329. {
  3330. struct unit_data *ud;
  3331. struct view_data *vd;
  3332. unsigned char buf[256];
  3333. int len;
  3334. nullpo_retr(0, bl);
  3335. ud = unit_bl2ud(bl);
  3336. vd = status_get_viewdata(bl);
  3337. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3338. return 0;
  3339. if(ud && ud->walktimer != -1)
  3340. len = clif_set007b(bl,vd,ud,buf);
  3341. else
  3342. len = clif_set0078(bl,vd,buf);
  3343. if (disguised(bl)) {
  3344. clif_send(buf,len,bl,AREA_WOS);
  3345. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  3346. clif_setdisguise((TBL_PC*)bl, buf, len, 1);
  3347. } else
  3348. clif_send(buf,len,bl,AREA);
  3349. return 0;
  3350. }
  3351. //Modifies the type of damage according to status changes [Skotlex]
  3352. #define clif_calc_delay(type,delay) (type==1||type==4||type==0x0a)?type:(delay==0?9:type)
  3353. /*==========================================
  3354. * Estimates walk delay based on the damage criteria. [Skotlex]
  3355. *------------------------------------------
  3356. */
  3357. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_) {
  3358. if (type == 4 || type == 9 || damage <=0)
  3359. return 0;
  3360. if (bl->type == BL_PC) {
  3361. if (battle_config.pc_walk_delay_rate != 100)
  3362. delay = delay*battle_config.pc_walk_delay_rate/100;
  3363. } else
  3364. if (battle_config.walk_delay_rate != 100)
  3365. delay = delay*battle_config.walk_delay_rate/100;
  3366. if (div_ > 1) //Multi-hit skills mean higher delays.
  3367. delay += battle_config.multihit_delay*(div_-1);
  3368. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3369. }
  3370. /*==========================================
  3371. * 通常攻撃エフェクト&ダメージ
  3372. *------------------------------------------
  3373. */
  3374. 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)
  3375. {
  3376. unsigned char buf[256];
  3377. struct status_change *sc;
  3378. nullpo_retr(0, src);
  3379. nullpo_retr(0, dst);
  3380. type = clif_calc_delay(type, ddelay); //Type defaults to 0 for normal attacks.
  3381. sc = status_get_sc(dst);
  3382. if(sc && sc->count) {
  3383. if(sc->data[SC_HALLUCINATION].timer != -1) {
  3384. if(damage > 0)
  3385. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3386. if(damage2 > 0)
  3387. damage2 = damage2*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3388. }
  3389. }
  3390. WBUFW(buf,0)=0x8a;
  3391. WBUFL(buf,2)=src->id;
  3392. WBUFL(buf,6)=dst->id;
  3393. WBUFL(buf,10)=tick;
  3394. WBUFL(buf,14)=sdelay;
  3395. WBUFL(buf,18)=ddelay;
  3396. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3397. WBUFW(buf,22)=damage?div:0;
  3398. WBUFW(buf,27)=damage2?div:0;
  3399. } else {
  3400. WBUFW(buf,22)=(damage > SHRT_MAX)?SHRT_MAX:damage;
  3401. WBUFW(buf,27)=damage2;
  3402. }
  3403. WBUFW(buf,24)=div;
  3404. WBUFB(buf,26)=type;
  3405. clif_send(buf,packet_len(0x8a),src,AREA);
  3406. if(disguised(src)) {
  3407. WBUFL(buf,2)=-src->id;
  3408. if(damage > 0)
  3409. WBUFW(buf,22)=-1;
  3410. if(damage2 > 0)
  3411. WBUFW(buf,27)=-1;
  3412. clif_send(buf,packet_len(0x8a),src,SELF);
  3413. }
  3414. if (disguised(dst)) {
  3415. WBUFL(buf,6)=-dst->id;
  3416. if (disguised(src))
  3417. WBUFL(buf,2)=src->id;
  3418. else {
  3419. if(damage > 0)
  3420. WBUFW(buf,22)=-1;
  3421. if(damage2 > 0)
  3422. WBUFW(buf,27)=-1;
  3423. }
  3424. clif_send(buf,packet_len(0x8a),dst,SELF);
  3425. }
  3426. //Return adjusted can't walk delay for further processing.
  3427. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3428. }
  3429. /*==========================================
  3430. *
  3431. *------------------------------------------
  3432. */
  3433. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3434. {
  3435. int view,fd;
  3436. fd=sd->fd;
  3437. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3438. WFIFOHEAD(fd,packet_len(0x9d));
  3439. WFIFOW(fd,0)=0x9d;
  3440. WFIFOL(fd,2)=fitem->bl.id;
  3441. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3442. WFIFOW(fd,6)=view;
  3443. else
  3444. WFIFOW(fd,6)=fitem->item_data.nameid;
  3445. WFIFOB(fd,8)=fitem->item_data.identify;
  3446. WFIFOW(fd,9)=fitem->bl.x;
  3447. WFIFOW(fd,11)=fitem->bl.y;
  3448. WFIFOW(fd,13)=fitem->item_data.amount;
  3449. WFIFOB(fd,15)=fitem->subx;
  3450. WFIFOB(fd,16)=fitem->suby;
  3451. WFIFOSET(fd,packet_len(0x9d));
  3452. }
  3453. /*==========================================
  3454. * 場所スキルエフェクトが視界に入る
  3455. *------------------------------------------
  3456. */
  3457. int clif_getareachar_skillunit(struct map_session_data *sd,struct skill_unit *unit)
  3458. {
  3459. int fd;
  3460. struct block_list *bl;
  3461. fd=sd->fd;
  3462. bl=map_id2bl(unit->group->src_id);
  3463. #if PACKETVER >= 3
  3464. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3465. WFIFOHEAD(fd,packet_len(0x1c9));
  3466. memset(WFIFOP(fd,0),0,packet_len(0x1c9));
  3467. WFIFOW(fd, 0)=0x1c9;
  3468. WFIFOL(fd, 2)=unit->bl.id;
  3469. WFIFOL(fd, 6)=unit->group->src_id;
  3470. WFIFOW(fd,10)=unit->bl.x;
  3471. WFIFOW(fd,12)=unit->bl.y; // might be typo? [Lance]
  3472. WFIFOB(fd,14)=unit->group->unit_id;
  3473. WFIFOB(fd,15)=1;
  3474. WFIFOB(fd,16)=1;
  3475. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3476. WFIFOSET(fd,packet_len(0x1c9));
  3477. return 0;
  3478. }
  3479. #endif
  3480. WFIFOHEAD(fd,packet_len(0x11f));
  3481. memset(WFIFOP(fd,0),0,packet_len(0x11f));
  3482. WFIFOW(fd, 0)=0x11f;
  3483. WFIFOL(fd, 2)=unit->bl.id;
  3484. WFIFOL(fd, 6)=unit->group->src_id;
  3485. WFIFOW(fd,10)=unit->bl.x;
  3486. WFIFOW(fd,12)=unit->bl.y;
  3487. //Use invisible unit id for traps.
  3488. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3489. WFIFOB(fd,14)=UNT_ATTACK_SKILLS;
  3490. else
  3491. WFIFOB(fd,14)=unit->group->unit_id;
  3492. WFIFOB(fd,15)=0;
  3493. WFIFOSET(fd,packet_len(0x11f));
  3494. if(unit->group->skill_id == WZ_ICEWALL)
  3495. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3496. return 0;
  3497. /* Previous implementation guess of packet 0x1c9, who can understand what all those fields are for? [Skotlex]
  3498. WFIFOHEAD(fd,packet_len(0x1c9));
  3499. memset(WFIFOP(fd,0),0,packet_len(0x1c9));
  3500. WFIFOW(fd, 0)=0x1c9;
  3501. WFIFOL(fd, 2)=unit->bl.id;
  3502. WFIFOL(fd, 6)=unit->group->src_id;
  3503. WFIFOW(fd,10)=unit->bl.x;
  3504. WFIFOW(fd,12)=unit->bl.y;
  3505. WFIFOB(fd,14)=unit->group->unit_id;
  3506. WFIFOB(fd,15)=1;
  3507. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3508. WFIFOB(fd,16)=1;
  3509. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3510. } else {
  3511. WFIFOL(fd,15+1)=0; //1-4調べた限り固定
  3512. WFIFOL(fd,15+5)=0; //5-8調べた限り固定
  3513. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  3514. WFIFOL(fd,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  3515. WFIFOL(fd,15+17)=0x004f37dd; //17-20調べた限り固定
  3516. WFIFOL(fd,15+21)=0x0012f674; //21-24調べた限り固定
  3517. WFIFOL(fd,15+25)=0x0012f664; //25-28調べた限り固定
  3518. WFIFOL(fd,15+29)=0x0012f654; //29-32調べた限り固定
  3519. WFIFOL(fd,15+33)=0x77527bbc; //33-36調べた限り固定
  3520. //37-39
  3521. WFIFOB(fd,15+40)=0x2d; //40調べた限り固定
  3522. WFIFOL(fd,15+41)=0; //41-44調べた限り0固定
  3523. WFIFOL(fd,15+45)=0; //45-48調べた限り0固定
  3524. WFIFOL(fd,15+49)=0; //49-52調べた限り0固定
  3525. WFIFOL(fd,15+53)=0x0048d919; //53-56調べた限り固定
  3526. WFIFOL(fd,15+57)=0x0000003e; //57-60調べた限り固定
  3527. WFIFOL(fd,15+61)=0x0012f66c; //61-64調べた限り固定
  3528. //65-68
  3529. //69-72
  3530. if(bl) WFIFOL(fd,15+73)=bl->y; //73-76術者のY座標
  3531. WFIFOL(fd,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  3532. WFIFOB(fd,15+81)=0xaa; //81終端文字0xaa
  3533. }
  3534. WFIFOSET(fd,packet_len(0x1c9));
  3535. #endif
  3536. if(unit->group->skill_id == WZ_ICEWALL)
  3537. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3538. return 0;
  3539. */
  3540. }
  3541. /*==========================================
  3542. * 場所スキルエフェクトが視界から消える
  3543. *------------------------------------------
  3544. */
  3545. int clif_clearchar_skillunit(struct skill_unit *unit,int fd)
  3546. {
  3547. nullpo_retr(0, unit);
  3548. WFIFOHEAD(fd,packet_len(0x120));
  3549. WFIFOW(fd, 0)=0x120;
  3550. WFIFOL(fd, 2)=unit->bl.id;
  3551. WFIFOSET(fd,packet_len(0x120));
  3552. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3553. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2);
  3554. return 0;
  3555. }
  3556. /*==========================================
  3557. * Unknown... trap related?
  3558. * Only affects units with class [139,153] client-side
  3559. *------------------------------------------
  3560. */
  3561. int clif_01ac(struct block_list *bl)
  3562. {
  3563. unsigned char buf[32];
  3564. nullpo_retr(0, bl);
  3565. WBUFW(buf, 0) = 0x1ac;
  3566. WBUFL(buf, 2) = bl->id;
  3567. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3568. return 0;
  3569. }
  3570. /*==========================================
  3571. *
  3572. *------------------------------------------
  3573. */
  3574. int clif_getareachar(struct block_list* bl,va_list ap)
  3575. {
  3576. struct map_session_data *sd;
  3577. nullpo_retr(0, bl);
  3578. nullpo_retr(0, ap);
  3579. sd=va_arg(ap,struct map_session_data*);
  3580. if (sd == NULL || !sd->fd || session[sd->fd] == NULL)
  3581. return 0;
  3582. switch(bl->type){
  3583. case BL_ITEM:
  3584. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3585. break;
  3586. case BL_SKILL:
  3587. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3588. break;
  3589. default:
  3590. if(&sd->bl == bl)
  3591. break;
  3592. clif_getareachar_char(sd,bl);
  3593. break;
  3594. }
  3595. return 0;
  3596. }
  3597. /*==========================================
  3598. * tbl has gone out of view-size of bl
  3599. *------------------------------------------
  3600. */
  3601. int clif_outsight(struct block_list *bl,va_list ap)
  3602. {
  3603. struct block_list *tbl;
  3604. struct view_data *vd;
  3605. TBL_PC *sd, *tsd;
  3606. tbl=va_arg(ap,struct block_list*);
  3607. if(bl == tbl) return 0;
  3608. BL_CAST(BL_PC, bl, sd);
  3609. BL_CAST(BL_PC, tbl, tsd);
  3610. if (tsd && tsd->fd)
  3611. { //tsd has lost sight of the bl object.
  3612. switch(bl->type){
  3613. case BL_PC:
  3614. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS)
  3615. clif_clearchar_id(bl->id,0,tsd->fd);
  3616. if(sd->chatID){
  3617. struct chat_data *cd;
  3618. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3619. if(cd->usersd[0]==sd)
  3620. clif_dispchat(cd,tsd->fd);
  3621. }
  3622. if(sd->vender_id)
  3623. clif_closevendingboard(bl,tsd->fd);
  3624. break;
  3625. case BL_ITEM:
  3626. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3627. break;
  3628. case BL_SKILL:
  3629. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3630. break;
  3631. default:
  3632. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3633. clif_clearchar_id(bl->id,0,tsd->fd);
  3634. break;
  3635. }
  3636. }
  3637. if (sd && sd->fd)
  3638. { //sd is watching tbl go out of view.
  3639. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3640. clif_clearchar_id(tbl->id,0,sd->fd);
  3641. }
  3642. return 0;
  3643. }
  3644. /*==========================================
  3645. * tbl has come into view of bl
  3646. *------------------------------------------
  3647. */
  3648. int clif_insight(struct block_list *bl,va_list ap)
  3649. {
  3650. struct block_list *tbl;
  3651. TBL_PC *sd, *tsd;
  3652. tbl=va_arg(ap,struct block_list*);
  3653. if (bl == tbl) return 0;
  3654. BL_CAST(BL_PC, bl, sd);
  3655. BL_CAST(BL_PC, tbl, tsd);
  3656. if (tsd && tsd->fd)
  3657. { //Tell tsd that bl entered into his view
  3658. switch(bl->type){
  3659. case BL_ITEM:
  3660. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3661. break;
  3662. case BL_SKILL:
  3663. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3664. break;
  3665. default:
  3666. clif_getareachar_char(tsd,bl);
  3667. break;
  3668. }
  3669. }
  3670. if (sd && sd->fd)
  3671. { //Tell sd that tbl walked into his view
  3672. clif_getareachar_char(sd,tbl);
  3673. }
  3674. return 0;
  3675. }
  3676. /*==========================================
  3677. *
  3678. *------------------------------------------
  3679. */
  3680. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3681. {
  3682. int fd,id;
  3683. nullpo_retr(0, sd);
  3684. fd=sd->fd;
  3685. if( (id=sd->status.skill[skillid].id) <= 0 )
  3686. return 0;
  3687. WFIFOHEAD(fd,packet_len(0x147));
  3688. WFIFOW(fd,0)=0x147;
  3689. WFIFOW(fd,2) = id;
  3690. if(type < 0)
  3691. WFIFOW(fd,4) = skill_get_inf(id);
  3692. else
  3693. WFIFOW(fd,4) = type;
  3694. WFIFOW(fd,6) = 0;
  3695. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3696. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3697. if(range < 0)
  3698. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3699. WFIFOW(fd,12)= range;
  3700. strncpy(WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3701. if(sd->status.skill[skillid].flag ==0)
  3702. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3703. else
  3704. WFIFOB(fd,38) = 0;
  3705. WFIFOSET(fd,packet_len(0x147));
  3706. return 0;
  3707. }
  3708. /*==========================================
  3709. * スキルリストを送信する
  3710. *------------------------------------------
  3711. */
  3712. int clif_skillinfoblock(struct map_session_data *sd)
  3713. {
  3714. int fd;
  3715. int i,c,len=4,id;
  3716. nullpo_retr(0, sd);
  3717. fd=sd->fd;
  3718. if (!fd) return 0;
  3719. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3720. WFIFOW(fd,0)=0x10f;
  3721. for ( i = c = 0; i < MAX_SKILL; i++){
  3722. if( (id=sd->status.skill[i].id)!=0 ){
  3723. WFIFOW(fd,len ) = id;
  3724. WFIFOW(fd,len+2) = skill_get_inf(id);
  3725. WFIFOW(fd,len+4) = 0;
  3726. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3727. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3728. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3729. strncpy(WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3730. if(sd->status.skill[i].flag ==0)
  3731. WFIFOB(fd,len+36)= (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3732. else
  3733. WFIFOB(fd,len+36) = 0;
  3734. len+=37;
  3735. c++;
  3736. }
  3737. }
  3738. WFIFOW(fd,2)=len;
  3739. WFIFOSET(fd,len);
  3740. return 1;
  3741. }
  3742. /*==========================================
  3743. * スキル割り振り通知
  3744. *------------------------------------------
  3745. */
  3746. int clif_skillup(struct map_session_data *sd,int skill_num)
  3747. {
  3748. int fd;
  3749. nullpo_retr(0, sd);
  3750. fd=sd->fd;
  3751. WFIFOHEAD(fd,packet_len(0x10e));
  3752. WFIFOW(fd,0) = 0x10e;
  3753. WFIFOW(fd,2) = skill_num;
  3754. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3755. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3756. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3757. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3758. WFIFOSET(fd,packet_len(0x10e));
  3759. return 0;
  3760. }
  3761. /*==========================================
  3762. * スキル詠唱エフェクトを送信する
  3763. *------------------------------------------
  3764. */
  3765. int clif_skillcasting(struct block_list* bl,
  3766. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int casttime)
  3767. {
  3768. int pl = skill_get_pl(skill_num);
  3769. unsigned char buf[32];
  3770. WBUFW(buf,0) = 0x13e;
  3771. WBUFL(buf,2) = src_id;
  3772. WBUFL(buf,6) = dst_id;
  3773. WBUFW(buf,10) = dst_x;
  3774. WBUFW(buf,12) = dst_y;
  3775. WBUFW(buf,14) = skill_num;
  3776. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3777. WBUFL(buf,20) = casttime;
  3778. clif_send(buf,packet_len(0x13e), bl, AREA);
  3779. if (disguised(bl)) {
  3780. WBUFL(buf,2) = -src_id;
  3781. WBUFL(buf,20) = 0;
  3782. clif_send(buf,packet_len(0x13e), bl, SELF);
  3783. }
  3784. return 0;
  3785. }
  3786. /*==========================================
  3787. *
  3788. *------------------------------------------
  3789. */
  3790. int clif_skillcastcancel(struct block_list* bl)
  3791. {
  3792. unsigned char buf[16];
  3793. nullpo_retr(0, bl);
  3794. WBUFW(buf,0) = 0x1b9;
  3795. WBUFL(buf,2) = bl->id;
  3796. clif_send(buf,packet_len(0x1b9), bl, AREA);
  3797. return 0;
  3798. }
  3799. /*==========================================
  3800. * スキル詠唱失敗
  3801. *------------------------------------------
  3802. */
  3803. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3804. {
  3805. int fd;
  3806. if (!sd) { //Since this is the most common nullpo....
  3807. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3808. return 0;
  3809. }
  3810. fd=sd->fd;
  3811. if (!fd) return 0;
  3812. if(battle_config.display_skill_fail&1)
  3813. return 0; //Disable all skill failed messages
  3814. if(type==0x4 && !sd->state.showdelay)
  3815. return 0; //Disable delay failed messages
  3816. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3817. return 0;
  3818. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3819. return 0;
  3820. WFIFOHEAD(fd,packet_len(0x110));
  3821. WFIFOW(fd,0) = 0x110;
  3822. WFIFOW(fd,2) = skill_id;
  3823. WFIFOW(fd,4) = btype;
  3824. WFIFOW(fd,6) = 0;
  3825. WFIFOB(fd,8) = 0;
  3826. WFIFOB(fd,9) = type;
  3827. WFIFOSET(fd,packet_len(0x110));
  3828. return 1;
  3829. }
  3830. /*==========================================
  3831. * スキル攻撃エフェクト&ダメージ
  3832. *------------------------------------------
  3833. */
  3834. int clif_skill_damage(struct block_list *src,struct block_list *dst,
  3835. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3836. {
  3837. unsigned char buf[64];
  3838. struct status_change *sc;
  3839. nullpo_retr(0, src);
  3840. nullpo_retr(0, dst);
  3841. type = (type>0)?type:skill_get_hit(skill_id);
  3842. type = clif_calc_delay(type, ddelay);
  3843. sc = status_get_sc(dst);
  3844. if(sc && sc->count) {
  3845. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  3846. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3847. }
  3848. #if PACKETVER < 3
  3849. WBUFW(buf,0)=0x114;
  3850. WBUFW(buf,2)=skill_id;
  3851. WBUFL(buf,4)=src->id;
  3852. WBUFL(buf,8)=dst->id;
  3853. WBUFL(buf,12)=tick;
  3854. WBUFL(buf,16)=sdelay;
  3855. WBUFL(buf,20)=ddelay;
  3856. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3857. WBUFW(buf,24)=damage?div:0;
  3858. } else {
  3859. WBUFW(buf,24)=damage;
  3860. }
  3861. WBUFW(buf,26)=skill_lv;
  3862. WBUFW(buf,28)=div;
  3863. WBUFB(buf,30)=type;
  3864. clif_send(buf,packet_len(0x114),src,AREA);
  3865. if(disguised(src)) {
  3866. WBUFL(buf,4)=-src->id;
  3867. if(damage > 0)
  3868. WBUFW(buf,24)=-1;
  3869. clif_send(buf,packet_len(0x114),src,SELF);
  3870. }
  3871. if (disguised(dst)) {
  3872. WBUFL(buf,8)=-dst->id;
  3873. if (disguised(src))
  3874. WBUFL(buf,4)=src->id;
  3875. else if(damage > 0)
  3876. WBUFW(buf,24)=-1;
  3877. clif_send(buf,packet_len(0x114),dst,SELF);
  3878. }
  3879. #else
  3880. WBUFW(buf,0)=0x1de;
  3881. WBUFW(buf,2)=skill_id;
  3882. WBUFL(buf,4)=src->id;
  3883. WBUFL(buf,8)=dst->id;
  3884. WBUFL(buf,12)=tick;
  3885. WBUFL(buf,16)=sdelay;
  3886. WBUFL(buf,20)=ddelay;
  3887. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3888. WBUFL(buf,24)=damage?div:0;
  3889. } else {
  3890. WBUFL(buf,24)=damage;
  3891. }
  3892. WBUFW(buf,28)=skill_lv;
  3893. WBUFW(buf,30)=div;
  3894. WBUFB(buf,32)=type;
  3895. clif_send(buf,packet_len(0x1de),src,AREA);
  3896. if(disguised(src)) {
  3897. WBUFL(buf,4)=-src->id;
  3898. if(damage > 0)
  3899. WBUFL(buf,24)=-1;
  3900. clif_send(buf,packet_len(0x1de),src,SELF);
  3901. }
  3902. if (disguised(dst)) {
  3903. WBUFL(buf,8)=-dst->id;
  3904. if (disguised(src))
  3905. WBUFL(buf,4)=src->id;
  3906. else if(damage > 0)
  3907. WBUFL(buf,24)=-1;
  3908. clif_send(buf,packet_len(0x1de),dst,SELF);
  3909. }
  3910. #endif
  3911. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3912. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3913. }
  3914. /*==========================================
  3915. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3916. *------------------------------------------
  3917. */
  3918. int clif_skill_damage2(struct block_list *src,struct block_list *dst,
  3919. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3920. {
  3921. unsigned char buf[64];
  3922. struct status_change *sc;
  3923. nullpo_retr(0, src);
  3924. nullpo_retr(0, dst);
  3925. type = (type>0)?type:skill_get_hit(skill_id);
  3926. type = clif_calc_delay(type, ddelay);
  3927. sc = status_get_sc(dst);
  3928. if(sc && sc->count) {
  3929. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  3930. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3931. }
  3932. WBUFW(buf,0)=0x115;
  3933. WBUFW(buf,2)=skill_id;
  3934. WBUFL(buf,4)=src->id;
  3935. WBUFL(buf,8)=dst->id;
  3936. WBUFL(buf,12)=tick;
  3937. WBUFL(buf,16)=sdelay;
  3938. WBUFL(buf,20)=ddelay;
  3939. WBUFW(buf,24)=dst->x;
  3940. WBUFW(buf,26)=dst->y;
  3941. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3942. WBUFW(buf,28)=damage?div:0;
  3943. } else {
  3944. WBUFW(buf,28)=damage;
  3945. }
  3946. WBUFW(buf,30)=skill_lv;
  3947. WBUFW(buf,32)=div;
  3948. WBUFB(buf,34)=type;
  3949. clif_send(buf,packet_len(0x115),src,AREA);
  3950. if(disguised(src)) {
  3951. WBUFL(buf,4)=-src->id;
  3952. if(damage > 0)
  3953. WBUFW(buf,28)=-1;
  3954. clif_send(buf,packet_len(0x115),src,SELF);
  3955. }
  3956. if (disguised(dst)) {
  3957. WBUFL(buf,8)=-dst->id;
  3958. if (disguised(src))
  3959. WBUFL(buf,4)=src->id;
  3960. else if(damage > 0)
  3961. WBUFW(buf,28)=-1;
  3962. clif_send(buf,packet_len(0x115),dst,SELF);
  3963. }
  3964. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3965. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3966. }
  3967. /*==========================================
  3968. * 支援/回復スキルエフェクト
  3969. *------------------------------------------
  3970. */
  3971. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,
  3972. int skill_id,int heal,int fail)
  3973. {
  3974. unsigned char buf[32];
  3975. nullpo_retr(0, dst);
  3976. WBUFW(buf,0)=0x11a;
  3977. WBUFW(buf,2)=skill_id;
  3978. WBUFW(buf,4)=(heal > SHRT_MAX)? SHRT_MAX:heal;
  3979. WBUFL(buf,6)=dst->id;
  3980. WBUFL(buf,10)=src?src->id:0;
  3981. WBUFB(buf,14)=fail;
  3982. clif_send(buf,packet_len(0x11a),dst,AREA);
  3983. if (disguised(dst)) {
  3984. WBUFL(buf,6)=-dst->id;
  3985. clif_send(buf,packet_len(0x115),dst,SELF);
  3986. }
  3987. if(src && disguised(src)) {
  3988. WBUFL(buf,10)=-src->id;
  3989. if (disguised(dst))
  3990. WBUFL(buf,6)=dst->id;
  3991. clif_send(buf,packet_len(0x115),src,SELF);
  3992. }
  3993. return fail;
  3994. }
  3995. /*==========================================
  3996. * 場所スキルエフェクト
  3997. *------------------------------------------
  3998. */
  3999. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  4000. {
  4001. unsigned char buf[32];
  4002. nullpo_retr(0, src);
  4003. WBUFW(buf,0)=0x117;
  4004. WBUFW(buf,2)=skill_id;
  4005. WBUFL(buf,4)=src->id;
  4006. WBUFW(buf,8)=val;
  4007. WBUFW(buf,10)=x;
  4008. WBUFW(buf,12)=y;
  4009. WBUFL(buf,14)=tick;
  4010. clif_send(buf,packet_len(0x117),src,AREA);
  4011. if(disguised(src)) {
  4012. WBUFL(buf,4)=-src->id;
  4013. clif_send(buf,packet_len(0x117),src,SELF);
  4014. }
  4015. return 0;
  4016. }
  4017. /*==========================================
  4018. * 場所スキルエフェクト表示
  4019. *------------------------------------------
  4020. */
  4021. int clif_skill_setunit(struct skill_unit *unit)
  4022. {
  4023. unsigned char buf[128];
  4024. struct block_list *bl;
  4025. nullpo_retr(0, unit);
  4026. bl=map_id2bl(unit->group->src_id);
  4027. // These are invisible client-side, but are necessary because
  4028. // otherwise the client will not know who caused the attack.
  4029. // if (unit->group->unit_id == UNT_ATTACK_SKILLS)
  4030. // return 0;
  4031. #if PACKETVER >= 3
  4032. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4033. memset(WBUFP(buf, 0),0,packet_len(0x1c9));
  4034. WBUFW(buf, 0)=0x1c9;
  4035. WBUFL(buf, 2)=unit->bl.id;
  4036. WBUFL(buf, 6)=unit->group->src_id;
  4037. WBUFW(buf,10)=unit->bl.x;
  4038. WBUFW(buf,12)=unit->bl.y;
  4039. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE) {
  4040. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4041. } else {
  4042. WBUFB(buf,14)=unit->group->unit_id;
  4043. }
  4044. WBUFB(buf,15)=1;
  4045. WBUFB(buf,16)=1;
  4046. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4047. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4048. return 0;
  4049. }
  4050. #endif
  4051. memset(WBUFP(buf, 0),0,packet_len(0x11f));
  4052. WBUFW(buf, 0)=0x11f;
  4053. WBUFL(buf, 2)=unit->bl.id;
  4054. WBUFL(buf, 6)=unit->group->src_id;
  4055. WBUFW(buf,10)=unit->bl.x;
  4056. WBUFW(buf,12)=unit->bl.y;
  4057. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE) {
  4058. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4059. } else {
  4060. WBUFB(buf,14)=unit->group->unit_id;
  4061. }
  4062. WBUFB(buf,15)=0;
  4063. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4064. return 0;
  4065. /* Previous mysterious implementation noone really understands. [Skotlex]
  4066. memset(WBUFP(buf, 0),0,packet_len(0x1c9));
  4067. WBUFW(buf, 0)=0x1c9;
  4068. WBUFL(buf, 2)=unit->bl.id;
  4069. WBUFL(buf, 6)=unit->group->src_id;
  4070. WBUFW(buf,10)=unit->bl.x;
  4071. WBUFW(buf,12)=unit->bl.y;
  4072. WBUFB(buf,14)=unit->group->unit_id;
  4073. WBUFB(buf,15)=1;
  4074. if(unit->group->unit_id==0xb0) { // Graffiti [Valaris]
  4075. WBUFB(buf,16)=1;
  4076. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4077. } else {
  4078. WBUFL(buf,15+1)=0; //1-4調べた限り固定
  4079. WBUFL(buf,15+5)=0; //5-8調べた限り固定
  4080. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  4081. WBUFL(buf,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  4082. WBUFL(buf,15+17)=0x004f37dd; //17-20調べた限り固定(0x1b2で0x004fdbddだった)
  4083. WBUFL(buf,15+21)=0x0012f674; //21-24調べた限り固定
  4084. WBUFL(buf,15+25)=0x0012f664; //25-28調べた限り固定
  4085. WBUFL(buf,15+29)=0x0012f654; //29-32調べた限り固定
  4086. WBUFL(buf,15+33)=0x77527bbc; //33-36調べた限り固定
  4087. //37-39
  4088. WBUFB(buf,15+40)=0x2d; //40調べた限り固定
  4089. WBUFL(buf,15+41)=0; //41-44調べた限り0固定
  4090. WBUFL(buf,15+45)=0; //45-48調べた限り0固定
  4091. WBUFL(buf,15+49)=0; //49-52調べた限り0固定
  4092. WBUFL(buf,15+53)=0x0048d919; //53-56調べた限り固定(0x01b2で0x00495119だった)
  4093. WBUFL(buf,15+57)=0x0000003e; //57-60調べた限り固定
  4094. WBUFL(buf,15+61)=0x0012f66c; //61-64調べた限り固定
  4095. //65-68
  4096. //69-72
  4097. if(bl) WBUFL(buf,15+73)=bl->y; //73-76術者のY座標
  4098. WBUFL(buf,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  4099. WBUFB(buf,15+81)=0xaa; //81終端文字0xaa
  4100. }
  4101. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4102. #endif
  4103. return 0;
  4104. */
  4105. }
  4106. /*==========================================
  4107. * 場所スキルエフェクト削除
  4108. *------------------------------------------
  4109. */
  4110. int clif_skill_delunit(struct skill_unit *unit)
  4111. {
  4112. unsigned char buf[16];
  4113. nullpo_retr(0, unit);
  4114. WBUFW(buf, 0)=0x120;
  4115. WBUFL(buf, 2)=unit->bl.id;
  4116. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4117. return 0;
  4118. }
  4119. /*==========================================
  4120. * ワープ場所選択
  4121. *------------------------------------------
  4122. */
  4123. int clif_skill_warppoint(struct map_session_data *sd,int skill_num,int skill_lv,
  4124. const char *map1,const char *map2,const char *map3,const char *map4)
  4125. {
  4126. int fd;
  4127. nullpo_retr(0, sd);
  4128. fd=sd->fd;
  4129. WFIFOHEAD(fd,packet_len(0x11c));
  4130. WFIFOW(fd,0)=0x11c;
  4131. WFIFOW(fd,2)=skill_num;
  4132. strncpy((char*)WFIFOP(fd, 4),map1,MAP_NAME_LENGTH);
  4133. strncpy((char*)WFIFOP(fd,20),map2,MAP_NAME_LENGTH);
  4134. strncpy((char*)WFIFOP(fd,36),map3,MAP_NAME_LENGTH);
  4135. strncpy((char*)WFIFOP(fd,52),map4,MAP_NAME_LENGTH);
  4136. WFIFOSET(fd,packet_len(0x11c));
  4137. sd->menuskill_id = skill_num;
  4138. if (skill_num == AL_WARP)
  4139. sd->menuskill_lv = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4140. else
  4141. sd->menuskill_lv = skill_lv;
  4142. return 0;
  4143. }
  4144. /*==========================================
  4145. * メモ応答
  4146. *------------------------------------------
  4147. */
  4148. int clif_skill_memo(struct map_session_data *sd,int flag)
  4149. {
  4150. int fd;
  4151. nullpo_retr(0, sd);
  4152. fd=sd->fd;
  4153. WFIFOHEAD(fd,packet_len(0x11e));
  4154. WFIFOW(fd,0)=0x11e;
  4155. WFIFOB(fd,2)=flag;
  4156. WFIFOSET(fd,packet_len(0x11e));
  4157. return 0;
  4158. }
  4159. int clif_skill_teleportmessage(struct map_session_data *sd,int flag)
  4160. {
  4161. int fd;
  4162. nullpo_retr(0, sd);
  4163. fd=sd->fd;
  4164. WFIFOHEAD(fd,packet_len(0x189));
  4165. WFIFOW(fd,0)=0x189;
  4166. WFIFOW(fd,2)=flag;
  4167. WFIFOSET(fd,packet_len(0x189));
  4168. return 0;
  4169. }
  4170. /*==========================================
  4171. * モンスター情報
  4172. *------------------------------------------
  4173. */
  4174. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4175. {
  4176. struct status_data *status;
  4177. unsigned char buf[64];
  4178. int i;//, fix;
  4179. nullpo_retr(0, sd);
  4180. nullpo_retr(0, dst);
  4181. if(dst->type!=BL_MOB )
  4182. return 0;
  4183. status = status_get_status_data(dst);
  4184. WBUFW(buf, 0)=0x18c;
  4185. WBUFW(buf, 2)=status_get_class(dst);
  4186. WBUFW(buf, 4)=status_get_lv(dst);
  4187. WBUFW(buf, 6)=status->size;
  4188. WBUFL(buf, 8)=status->hp;
  4189. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4190. +(battle_config.estimation_type&2?status->def2:0);
  4191. WBUFW(buf,14)=status->race;
  4192. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4193. +(battle_config.estimation_type&2?status->mdef2:0);
  4194. WBUFW(buf,18)= status->def_ele;
  4195. for(i=0;i<9;i++)
  4196. WBUFB(buf,20+i)= (unsigned char)battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv);
  4197. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4198. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4199. clif_send(buf,packet_len(0x18c),&sd->bl,
  4200. sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4201. return 0;
  4202. }
  4203. /*==========================================
  4204. * アイテム合成可能リスト
  4205. *------------------------------------------
  4206. */
  4207. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  4208. {
  4209. int i,c,view,fd;
  4210. nullpo_retr(0, sd);
  4211. if(sd->menuskill_id == AM_PHARMACY)
  4212. return 0; //Avoid resending the menu twice or more times...
  4213. fd=sd->fd;
  4214. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4215. WFIFOW(fd, 0)=0x18d;
  4216. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4217. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4218. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4219. WFIFOW(fd,c*8+ 4)= view;
  4220. else
  4221. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4222. WFIFOW(fd,c*8+ 6)= 0x0012;
  4223. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  4224. c++;
  4225. }
  4226. }
  4227. WFIFOW(fd, 2)=c*8+8;
  4228. WFIFOSET(fd,WFIFOW(fd,2));
  4229. if(c > 0) {
  4230. sd->menuskill_id = AM_PHARMACY;
  4231. sd->menuskill_lv = trigger;
  4232. return 1;
  4233. }
  4234. return 0;
  4235. }
  4236. /*==========================================
  4237. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  4238. *------------------------------------------
  4239. */
  4240. int clif_status_load(struct block_list *bl,int type, int flag)
  4241. {
  4242. int fd;
  4243. if (type == SI_BLANK) //It shows nothing on the client...
  4244. return 0;
  4245. if (bl->type != BL_PC)
  4246. return 0;
  4247. fd = ((struct map_session_data*)bl)->fd;
  4248. WFIFOHEAD(fd,packet_len(0x196));
  4249. WFIFOW(fd,0)=0x0196;
  4250. WFIFOW(fd,2)=type;
  4251. WFIFOL(fd,4)=bl->id;
  4252. WFIFOB(fd,8)=flag; //Status start
  4253. WFIFOSET(fd, packet_len(0x196));
  4254. return 0;
  4255. }
  4256. /*==========================================
  4257. * 状態異常アイコン/メッセージ表示
  4258. *------------------------------------------
  4259. */
  4260. int clif_status_change(struct block_list *bl,int type,int flag)
  4261. {
  4262. unsigned char buf[16];
  4263. if (type == SI_BLANK) //It shows nothing on the client...
  4264. return 0;
  4265. nullpo_retr(0, bl);
  4266. WBUFW(buf,0)=0x0196;
  4267. WBUFW(buf,2)=type;
  4268. WBUFL(buf,4)=bl->id;
  4269. WBUFB(buf,8)=flag;
  4270. clif_send(buf,packet_len(0x196),bl,AREA);
  4271. return 0;
  4272. }
  4273. /*==========================================
  4274. * Send message (modified by [Yor])
  4275. *------------------------------------------
  4276. */
  4277. int clif_displaymessage(const int fd, char* mes)
  4278. {
  4279. // invalid pointer?
  4280. nullpo_retr(-1, mes);
  4281. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4282. if (fd == 0)
  4283. return 0;
  4284. else {
  4285. int len_mes = strlen(mes);
  4286. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4287. WFIFOHEAD(fd, 5 + len_mes);
  4288. WFIFOW(fd,0) = 0x8e;
  4289. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  4290. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  4291. WFIFOSET(fd, 5 + len_mes);
  4292. }
  4293. }
  4294. return 0;
  4295. }
  4296. /*==========================================
  4297. * 天の声を送信する
  4298. *------------------------------------------
  4299. */
  4300. int clif_GMmessage(struct block_list *bl, char* mes, int len, int flag)
  4301. {
  4302. unsigned char *buf;
  4303. int lp;
  4304. lp = (flag & 0x10) ? 8 : 4;
  4305. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  4306. WBUFW(buf,0) = 0x9a;
  4307. WBUFW(buf,2) = len + lp;
  4308. WBUFL(buf,4) = 0x65756c62; //"blue":
  4309. memcpy(WBUFP(buf,lp), mes, len);
  4310. flag &= 0x07;
  4311. clif_send(buf, WBUFW(buf,2), bl,
  4312. (flag == 1) ? ALL_SAMEMAP :
  4313. (flag == 2) ? AREA :
  4314. (flag == 3) ? SELF :
  4315. ALL_CLIENT);
  4316. if(buf) aFree(buf);
  4317. if(use_irc && irc_announce_flag && !flag)
  4318. irc_announce(mes);
  4319. return 0;
  4320. }
  4321. /*==========================================
  4322. * グローバルメッセージ
  4323. *------------------------------------------
  4324. */
  4325. void clif_GlobalMessage(struct block_list *bl,char *message)
  4326. {
  4327. char buf[100];
  4328. int len;
  4329. nullpo_retv(bl);
  4330. if(!message)
  4331. return;
  4332. len = strlen(message)+1;
  4333. WBUFW(buf,0)=0x8d;
  4334. WBUFW(buf,2)=len+8;
  4335. WBUFL(buf,4)=bl->id;
  4336. strncpy((char *) WBUFP(buf,8),message,len);
  4337. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4338. }
  4339. /*==========================================
  4340. * Send main chat message [LuzZza]
  4341. *------------------------------------------
  4342. */
  4343. void clif_MainChatMessage(char* message) {
  4344. char buf[200];
  4345. int len;
  4346. if(!message)
  4347. return;
  4348. len = strlen(message)+1;
  4349. if (len+8 > sizeof(buf)) {
  4350. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4351. len = sizeof(buf)-8;
  4352. }
  4353. WBUFW(buf,0)=0x8d;
  4354. WBUFW(buf,2)=len+8;
  4355. WBUFL(buf,4)=0;
  4356. strncpy((char *) WBUFP(buf,8),message,len);
  4357. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4358. }
  4359. /*==========================================
  4360. * Does an announce message in the given color.
  4361. *------------------------------------------
  4362. */
  4363. int clif_announce(struct block_list *bl, char* mes, int len, unsigned long color, int flag)
  4364. {
  4365. unsigned char *buf;
  4366. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4367. WBUFW(buf,0) = 0x1c3;
  4368. WBUFW(buf,2) = len + 16;
  4369. WBUFL(buf,4) = color;
  4370. WBUFW(buf,8) = 0x190; //Font style? Type?
  4371. WBUFW(buf,10) = 0x0c; //12? Font size?
  4372. WBUFL(buf,12) = 0; //Unknown!
  4373. memcpy(WBUFP(buf,16), mes, len);
  4374. flag &= 0x07;
  4375. clif_send(buf, WBUFW(buf,2), bl,
  4376. (flag == 1) ? ALL_SAMEMAP :
  4377. (flag == 2) ? AREA :
  4378. (flag == 3) ? SELF :
  4379. ALL_CLIENT);
  4380. if(buf) aFree(buf);
  4381. return 0;
  4382. }
  4383. /*==========================================
  4384. * HPSP回復エフェクトを送信する
  4385. *------------------------------------------
  4386. */
  4387. int clif_heal(int fd,int type,int val)
  4388. {
  4389. WFIFOHEAD(fd,packet_len(0x13d));
  4390. WFIFOW(fd,0)=0x13d;
  4391. WFIFOW(fd,2)=type;
  4392. WFIFOW(fd,4)=val;
  4393. WFIFOSET(fd,packet_len(0x13d));
  4394. return 0;
  4395. }
  4396. /*==========================================
  4397. * 復活する
  4398. *------------------------------------------
  4399. */
  4400. int clif_resurrection(struct block_list *bl,int type)
  4401. {
  4402. unsigned char buf[16];
  4403. nullpo_retr(0, bl);
  4404. WBUFW(buf,0)=0x148;
  4405. WBUFL(buf,2)=bl->id;
  4406. WBUFW(buf,6)=type;
  4407. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4408. if (disguised(bl))
  4409. clif_spawn(bl);
  4410. return 0;
  4411. }
  4412. /*==========================================
  4413. * PVP実装?(仮)
  4414. *------------------------------------------
  4415. */
  4416. int clif_set0199(int fd,int type)
  4417. {
  4418. WFIFOHEAD(fd,packet_len(0x199));
  4419. WFIFOW(fd,0)=0x199;
  4420. WFIFOW(fd,2)=type;
  4421. WFIFOSET(fd,packet_len(0x199));
  4422. return 0;
  4423. }
  4424. /*==========================================
  4425. * PVP実装?(仮)
  4426. *------------------------------------------
  4427. */
  4428. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4429. {
  4430. int fd = sd->fd;
  4431. if(type == 2) {
  4432. WFIFOHEAD(fd,packet_len(0x19a));
  4433. WFIFOW(fd,0) = 0x19a;
  4434. WFIFOL(fd,2) = sd->bl.id;
  4435. WFIFOL(fd,6) = pvprank;
  4436. WFIFOL(fd,10) = pvpnum;
  4437. WFIFOSET(fd,packet_len(0x19a));
  4438. } else {
  4439. unsigned char buf[32];
  4440. WBUFW(buf,0) = 0x19a;
  4441. WBUFL(buf,2) = sd->bl.id;
  4442. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4443. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4444. else
  4445. WBUFL(buf,6) = pvprank;
  4446. WBUFL(buf,10) = pvpnum;
  4447. if(sd->sc.option&OPTION_INVISIBLE)
  4448. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4449. else if(!type)
  4450. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4451. else
  4452. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4453. }
  4454. return 0;
  4455. }
  4456. /*==========================================
  4457. *
  4458. *------------------------------------------
  4459. */
  4460. int clif_send0199(int map,int type)
  4461. {
  4462. struct block_list bl;
  4463. unsigned char buf[16];
  4464. bl.id = 0;
  4465. bl.type = BL_NUL;
  4466. bl.m = map;
  4467. WBUFW(buf,0)=0x199;
  4468. WBUFW(buf,2)=type;
  4469. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4470. return 0;
  4471. }
  4472. /*==========================================
  4473. * 精錬エフェクトを送信する
  4474. *------------------------------------------
  4475. */
  4476. int clif_refine(int fd,struct map_session_data *sd,int fail,int index,int val)
  4477. {
  4478. WFIFOHEAD(fd,packet_len(0x188));
  4479. WFIFOW(fd,0)=0x188;
  4480. WFIFOW(fd,2)=fail;
  4481. WFIFOW(fd,4)=index+2;
  4482. WFIFOW(fd,6)=val;
  4483. WFIFOSET(fd,packet_len(0x188));
  4484. return 0;
  4485. }
  4486. /*==========================================
  4487. * Wisp/page is transmitted to the destination player
  4488. *------------------------------------------
  4489. */
  4490. int clif_wis_message(int fd, char *nick, char *mes, int mes_len) // R 0097 <len>.w <nick>.24B <message>.?B
  4491. {
  4492. // printf("clif_wis_message(%d, %s, %s)\n", fd, nick, mes);
  4493. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4494. WFIFOW(fd,0) = 0x97;
  4495. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4496. memcpy(WFIFOP(fd,4), nick, NAME_LENGTH);
  4497. memcpy(WFIFOP(fd,28), mes, mes_len);
  4498. WFIFOSET(fd,WFIFOW(fd,2));
  4499. return 0;
  4500. }
  4501. /*==========================================
  4502. * The transmission result of Wisp/page is transmitted to the source player
  4503. *------------------------------------------
  4504. */
  4505. 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
  4506. {
  4507. WFIFOHEAD(fd,packet_len(0x98));
  4508. WFIFOW(fd,0) = 0x98;
  4509. WFIFOW(fd,2) = flag;
  4510. WFIFOSET(fd,packet_len(0x98));
  4511. return 0;
  4512. }
  4513. /*==========================================
  4514. * キャラID名前引き結果を送信する
  4515. *------------------------------------------
  4516. */
  4517. int clif_solved_charname(struct map_session_data *sd,int char_id)
  4518. {
  4519. char *p= map_charid2nick(char_id);
  4520. int fd;
  4521. nullpo_retr(0, sd);
  4522. fd=sd->fd;
  4523. if(p!=NULL){
  4524. WFIFOHEAD(fd,packet_len(0x194));
  4525. WFIFOW(fd,0)=0x194;
  4526. WFIFOL(fd,2)=char_id;
  4527. memcpy(WFIFOP(fd,6), p, NAME_LENGTH);
  4528. WFIFOSET(fd,packet_len(0x194));
  4529. }else{
  4530. map_reqchariddb(sd,char_id);
  4531. chrif_searchcharid(char_id);
  4532. }
  4533. return 0;
  4534. }
  4535. /*==========================================
  4536. * カードの挿入可能リストを返す
  4537. *------------------------------------------
  4538. */
  4539. int clif_use_card(struct map_session_data *sd,int idx)
  4540. {
  4541. int i,c,ep;
  4542. int fd=sd->fd;
  4543. nullpo_retr(0, sd);
  4544. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4545. return 0;
  4546. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4547. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4548. ep=sd->inventory_data[idx]->equip;
  4549. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4550. WFIFOW(fd,0)=0x017b;
  4551. for(i=c=0;i<MAX_INVENTORY;i++){
  4552. int j;
  4553. if(sd->inventory_data[i] == NULL)
  4554. continue;
  4555. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4556. continue;
  4557. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4558. continue;
  4559. if(sd->status.inventory[i].identify==0 ) //Not identified
  4560. continue;
  4561. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4562. continue;
  4563. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_HAND_L) //Shield card won't go on left weapon.
  4564. continue;
  4565. for(j=0;j<sd->inventory_data[i]->slot;j++){
  4566. if( sd->status.inventory[i].card[j]==0 )
  4567. break;
  4568. }
  4569. if(j==sd->inventory_data[i]->slot) // No room
  4570. continue;
  4571. WFIFOW(fd,4+c*2)=i+2;
  4572. c++;
  4573. }
  4574. WFIFOW(fd,2)=4+c*2;
  4575. WFIFOSET(fd,WFIFOW(fd,2));
  4576. return 0;
  4577. }
  4578. /*==========================================
  4579. * カードの挿入終了
  4580. *------------------------------------------
  4581. */
  4582. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4583. {
  4584. int fd;
  4585. nullpo_retr(0, sd);
  4586. fd=sd->fd;
  4587. WFIFOHEAD(fd,packet_len(0x17d));
  4588. WFIFOW(fd,0)=0x17d;
  4589. WFIFOW(fd,2)=idx_equip+2;
  4590. WFIFOW(fd,4)=idx_card+2;
  4591. WFIFOB(fd,6)=flag;
  4592. WFIFOSET(fd,packet_len(0x17d));
  4593. return 0;
  4594. }
  4595. /*==========================================
  4596. * 鑑定可能アイテムリスト送信
  4597. *------------------------------------------
  4598. */
  4599. int clif_item_identify_list(struct map_session_data *sd)
  4600. {
  4601. int i,c;
  4602. int fd;
  4603. nullpo_retr(0, sd);
  4604. fd=sd->fd;
  4605. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4606. WFIFOW(fd,0)=0x177;
  4607. for(i=c=0;i<MAX_INVENTORY;i++){
  4608. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4609. WFIFOW(fd,c*2+4)=i+2;
  4610. c++;
  4611. }
  4612. }
  4613. if(c > 0) {
  4614. WFIFOW(fd,2)=c*2+4;
  4615. WFIFOSET(fd,WFIFOW(fd,2));
  4616. sd->menuskill_id = MC_IDENTIFY;
  4617. sd->menuskill_lv = c;
  4618. }
  4619. return 0;
  4620. }
  4621. /*==========================================
  4622. * 鑑定結果
  4623. *------------------------------------------
  4624. */
  4625. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4626. {
  4627. int fd;
  4628. nullpo_retr(0, sd);
  4629. fd=sd->fd;
  4630. WFIFOHEAD(fd,packet_len(0x179));
  4631. WFIFOW(fd, 0)=0x179;
  4632. WFIFOW(fd, 2)=idx+2;
  4633. WFIFOB(fd, 4)=flag;
  4634. WFIFOSET(fd,packet_len(0x179));
  4635. return 0;
  4636. }
  4637. /*==========================================
  4638. * 修理可能アイテムリスト送信
  4639. *------------------------------------------
  4640. */
  4641. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4642. {
  4643. int i,c;
  4644. int fd;
  4645. int nameid;
  4646. nullpo_retr(0, sd);
  4647. nullpo_retr(0, dstsd);
  4648. fd=sd->fd;
  4649. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4650. WFIFOW(fd,0)=0x1fc;
  4651. for(i=c=0;i<MAX_INVENTORY;i++){
  4652. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4653. WFIFOW(fd,c*13+4) = i;
  4654. WFIFOW(fd,c*13+6) = nameid;
  4655. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4656. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4657. WFIFOB(fd,c*13+16)= c;
  4658. c++;
  4659. }
  4660. }
  4661. if(c > 0) {
  4662. WFIFOW(fd,2)=c*13+4;
  4663. WFIFOSET(fd,WFIFOW(fd,2));
  4664. sd->menuskill_id = BS_REPAIRWEAPON;
  4665. sd->menuskill_lv = dstsd->bl.id;
  4666. }else
  4667. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4668. return 0;
  4669. }
  4670. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4671. {
  4672. int view,fd;
  4673. nullpo_retr(0, sd);
  4674. fd=sd->fd;
  4675. WFIFOHEAD(fd,packet_len(0x1fe));
  4676. WFIFOW(fd, 0)=0x1fe;
  4677. if((view = itemdb_viewid(nameid)) > 0)
  4678. WFIFOW(fd, 2)=view;
  4679. else
  4680. WFIFOW(fd, 2)=nameid;
  4681. WFIFOB(fd, 4)=flag;
  4682. WFIFOSET(fd,packet_len(0x1fe));
  4683. return 0;
  4684. }
  4685. /*==========================================
  4686. * Weapon Refining - Taken from jAthena
  4687. *------------------------------------------
  4688. */
  4689. int clif_item_refine_list(struct map_session_data *sd)
  4690. {
  4691. int i,c;
  4692. int fd;
  4693. int skilllv;
  4694. int wlv;
  4695. int refine_item[5];
  4696. nullpo_retr(0, sd);
  4697. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4698. fd=sd->fd;
  4699. refine_item[0] = -1;
  4700. refine_item[1] = pc_search_inventory(sd,1010);
  4701. refine_item[2] = pc_search_inventory(sd,1011);
  4702. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4703. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4704. WFIFOW(fd,0)=0x221;
  4705. for(i=c=0;i<MAX_INVENTORY;i++){
  4706. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4707. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4708. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4709. WFIFOW(fd,c*13+ 4)=i+2;
  4710. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4711. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4712. WFIFOW(fd,c*13+10)=0;
  4713. WFIFOB(fd,c*13+12)=c;
  4714. c++;
  4715. }
  4716. }
  4717. WFIFOW(fd,2)=c*13+4;
  4718. WFIFOSET(fd,WFIFOW(fd,2));
  4719. sd->menuskill_id = WS_WEAPONREFINE;
  4720. sd->menuskill_lv = skilllv;
  4721. return 0;
  4722. }
  4723. /*==========================================
  4724. * アイテムによる一時的なスキル効果
  4725. *------------------------------------------
  4726. */
  4727. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv,const char *name)
  4728. {
  4729. int fd;
  4730. nullpo_retr(0, sd);
  4731. fd=sd->fd;
  4732. WFIFOHEAD(fd,packet_len(0x147));
  4733. WFIFOW(fd, 0)=0x147;
  4734. WFIFOW(fd, 2)=skillid;
  4735. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4736. WFIFOW(fd, 6)=0;
  4737. WFIFOW(fd, 8)=skilllv;
  4738. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4739. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4740. strncpy((char*)WFIFOP(fd,14),name,NAME_LENGTH);
  4741. WFIFOB(fd,38)=0;
  4742. WFIFOSET(fd,packet_len(0x147));
  4743. return 0;
  4744. }
  4745. /*==========================================
  4746. * カートにアイテム追加
  4747. *------------------------------------------
  4748. */
  4749. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4750. {
  4751. int view,fd;
  4752. unsigned char *buf;
  4753. nullpo_retr(0, sd);
  4754. fd=sd->fd;
  4755. WFIFOHEAD(fd,packet_len(0x124));
  4756. buf=WFIFOP(fd,0);
  4757. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4758. return 1;
  4759. WBUFW(buf,0)=0x124;
  4760. WBUFW(buf,2)=n+2;
  4761. WBUFL(buf,4)=amount;
  4762. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4763. WBUFW(buf,8)=view;
  4764. else
  4765. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4766. WBUFB(buf,10)=sd->status.cart[n].identify;
  4767. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4768. WBUFB(buf,12)=sd->status.cart[n].refine;
  4769. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4770. WFIFOSET(fd,packet_len(0x124));
  4771. return 0;
  4772. }
  4773. /*==========================================
  4774. * カートからアイテム削除
  4775. *------------------------------------------
  4776. */
  4777. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4778. {
  4779. int fd;
  4780. nullpo_retr(0, sd);
  4781. fd=sd->fd;
  4782. WFIFOHEAD(fd,packet_len(0x125));
  4783. WFIFOW(fd,0)=0x125;
  4784. WFIFOW(fd,2)=n+2;
  4785. WFIFOL(fd,4)=amount;
  4786. WFIFOSET(fd,packet_len(0x125));
  4787. return 0;
  4788. }
  4789. /*==========================================
  4790. * 露店開設
  4791. *------------------------------------------
  4792. */
  4793. int clif_openvendingreq(struct map_session_data *sd,int num)
  4794. {
  4795. int fd;
  4796. nullpo_retr(0, sd);
  4797. fd=sd->fd;
  4798. WFIFOHEAD(fd,packet_len(0x12d));
  4799. WFIFOW(fd,0)=0x12d;
  4800. WFIFOW(fd,2)=num;
  4801. WFIFOSET(fd,packet_len(0x12d));
  4802. return 0;
  4803. }
  4804. /*==========================================
  4805. * 露店看板表示
  4806. *------------------------------------------
  4807. */
  4808. int clif_showvendingboard(struct block_list* bl,char *message,int fd)
  4809. {
  4810. unsigned char buf[128];
  4811. nullpo_retr(0, bl);
  4812. WBUFW(buf,0)=0x131;
  4813. WBUFL(buf,2)=bl->id;
  4814. strncpy((char*)WBUFP(buf,6),message,80);
  4815. if(fd){
  4816. WFIFOHEAD(fd,packet_len(0x131));
  4817. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  4818. WFIFOSET(fd,packet_len(0x131));
  4819. }else{
  4820. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  4821. }
  4822. return 0;
  4823. }
  4824. /*==========================================
  4825. * 露店看板消去
  4826. *------------------------------------------
  4827. */
  4828. int clif_closevendingboard(struct block_list* bl,int fd)
  4829. {
  4830. unsigned char buf[16];
  4831. nullpo_retr(0, bl);
  4832. WBUFW(buf,0)=0x132;
  4833. WBUFL(buf,2)=bl->id;
  4834. if(fd){
  4835. WFIFOHEAD(fd,packet_len(0x132));
  4836. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  4837. WFIFOSET(fd,packet_len(0x132));
  4838. }else{
  4839. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  4840. }
  4841. return 0;
  4842. }
  4843. /*==========================================
  4844. * 露店アイテムリスト
  4845. *------------------------------------------
  4846. */
  4847. int clif_vendinglist(struct map_session_data *sd,int id,struct vending *vending)
  4848. {
  4849. struct item_data *data;
  4850. int i,n,index,fd;
  4851. struct map_session_data *vsd;
  4852. unsigned char *buf;
  4853. nullpo_retr(0, sd);
  4854. nullpo_retr(0, vending);
  4855. nullpo_retr(0, vsd=map_id2sd(id));
  4856. fd=sd->fd;
  4857. WFIFOHEAD(fd, 8+vsd->vend_num*22);
  4858. buf = WFIFOP(fd,0);
  4859. for(i=0,n=0;i<vsd->vend_num;i++){
  4860. if(vending[i].amount<=0)
  4861. continue;
  4862. WBUFL(buf,8+n*22)=vending[i].value;
  4863. WBUFW(buf,12+n*22)=vending[i].amount;
  4864. WBUFW(buf,14+n*22)=(index=vending[i].index)+2;
  4865. if(vsd->status.cart[index].nameid <= 0 || vsd->status.cart[index].amount <= 0)
  4866. continue;
  4867. data = itemdb_search(vsd->status.cart[index].nameid);
  4868. WBUFB(buf,16+n*22)=itemtype(data->type);
  4869. if(data->view_id > 0)
  4870. WBUFW(buf,17+n*22)=data->view_id;
  4871. else
  4872. WBUFW(buf,17+n*22)=vsd->status.cart[index].nameid;
  4873. WBUFB(buf,19+n*22)=vsd->status.cart[index].identify;
  4874. WBUFB(buf,20+n*22)=vsd->status.cart[index].attribute;
  4875. WBUFB(buf,21+n*22)=vsd->status.cart[index].refine;
  4876. clif_addcards(WBUFP(buf, 22+n*22), &vsd->status.cart[index]);
  4877. n++;
  4878. }
  4879. if(n > 0){
  4880. WBUFW(buf,0)=0x133;
  4881. WBUFW(buf,2)=8+n*22;
  4882. WBUFL(buf,4)=id;
  4883. WFIFOSET(fd,WFIFOW(fd,2));
  4884. }
  4885. return 0;
  4886. }
  4887. /*==========================================
  4888. * 露店アイテム購入失敗
  4889. *------------------------------------------
  4890. */
  4891. int clif_buyvending(struct map_session_data *sd,int index,int amount,int fail)
  4892. {
  4893. int fd;
  4894. nullpo_retr(0, sd);
  4895. fd=sd->fd;
  4896. WFIFOHEAD(fd,packet_len(0x135));
  4897. WFIFOW(fd,0)=0x135;
  4898. WFIFOW(fd,2)=index+2;
  4899. WFIFOW(fd,4)=amount;
  4900. WFIFOB(fd,6)=fail;
  4901. WFIFOSET(fd,packet_len(0x135));
  4902. return 0;
  4903. }
  4904. /*==========================================
  4905. * 露店開設成功
  4906. *------------------------------------------
  4907. */
  4908. int clif_openvending(struct map_session_data *sd,int id,struct vending *vending)
  4909. {
  4910. struct item_data *data;
  4911. int i,n,index,fd;
  4912. unsigned char *buf;
  4913. nullpo_retr(0, sd);
  4914. fd=sd->fd;
  4915. WFIFOHEAD(fd, 8+sd->vend_num*22);
  4916. buf = WFIFOP(fd,0);
  4917. for(i=0,n=0;i<sd->vend_num;i++){
  4918. if (sd->vend_num > 2+pc_checkskill(sd,MC_VENDING)) return 0;
  4919. WBUFL(buf,8+n*22)=vending[i].value;
  4920. WBUFW(buf,12+n*22)=(index=vending[i].index)+2;
  4921. WBUFW(buf,14+n*22)=vending[i].amount;
  4922. if(sd->status.cart[index].nameid <= 0 || sd->status.cart[index].amount <= 0 || !sd->status.cart[index].identify ||
  4923. sd->status.cart[index].attribute==1) // Prevent unidentified and broken items from being sold [Valaris]
  4924. continue;
  4925. data = itemdb_search(sd->status.cart[index].nameid);
  4926. WBUFB(buf,16+n*22)=itemtype(data->type);
  4927. if(data->view_id > 0)
  4928. WBUFW(buf,17+n*22)=data->view_id;
  4929. else
  4930. WBUFW(buf,17+n*22)=sd->status.cart[index].nameid;
  4931. WBUFB(buf,19+n*22)=sd->status.cart[index].identify;
  4932. WBUFB(buf,20+n*22)=sd->status.cart[index].attribute;
  4933. WBUFB(buf,21+n*22)=sd->status.cart[index].refine;
  4934. clif_addcards(WBUFP(buf, 22+n*22), &sd->status.cart[index]);
  4935. n++;
  4936. }
  4937. if(n > 0){
  4938. WBUFW(buf,0)=0x136;
  4939. WBUFW(buf,2)=8+n*22;
  4940. WBUFL(buf,4)=id;
  4941. WFIFOSET(fd,WFIFOW(fd,2));
  4942. }
  4943. return n;
  4944. }
  4945. /*==========================================
  4946. * 露店アイテム販売報告
  4947. *------------------------------------------
  4948. */
  4949. int clif_vendingreport(struct map_session_data *sd,int index,int amount)
  4950. {
  4951. int fd;
  4952. nullpo_retr(0, sd);
  4953. fd=sd->fd;
  4954. WFIFOHEAD(fd,packet_len(0x137));
  4955. WFIFOW(fd,0)=0x137;
  4956. WFIFOW(fd,2)=index+2;
  4957. WFIFOW(fd,4)=amount;
  4958. WFIFOSET(fd,packet_len(0x137));
  4959. return 0;
  4960. }
  4961. /*==========================================
  4962. * パーティ作成完了
  4963. *------------------------------------------
  4964. */
  4965. int clif_party_created(struct map_session_data *sd,int flag)
  4966. {
  4967. int fd;
  4968. nullpo_retr(0, sd);
  4969. fd=sd->fd;
  4970. WFIFOHEAD(fd,packet_len(0xfa));
  4971. WFIFOW(fd,0)=0xfa;
  4972. WFIFOB(fd,2)=flag;
  4973. WFIFOSET(fd,packet_len(0xfa));
  4974. return 0;
  4975. }
  4976. int clif_party_main_info(struct party_data *p, int fd)
  4977. {
  4978. struct map_session_data *sd;
  4979. int i;
  4980. unsigned char buf[96];
  4981. for (i=0; i<MAX_PARTY && !p->party.member[i].leader; i++);
  4982. if (i >= MAX_PARTY) return 0; //Should never happen...
  4983. sd = p->data[i].sd;
  4984. WBUFW(buf,0)=0x1e9;
  4985. WBUFL(buf,2)= p->party.member[i].account_id;
  4986. WBUFL(buf,6)= 0; //We don't know yet what this long is about.
  4987. WBUFW(buf,10)=sd?sd->bl.x:0;
  4988. WBUFW(buf,12)=sd?sd->bl.y:0;
  4989. WBUFB(buf,14)=(p->party.member[i].online)?0:1; //This byte is also unconfirmed...
  4990. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  4991. memcpy(WBUFP(buf,39), p->party.member[i].name, NAME_LENGTH);
  4992. memcpy(WBUFP(buf,63), mapindex_id2name(p->party.member[i].map), MAP_NAME_LENGTH);
  4993. WBUFB(buf,79) = (p->party.item&1)?1:0;
  4994. WBUFB(buf,80) = (p->party.item&2)?1:0;
  4995. if(fd>=0){
  4996. WFIFOHEAD(fd,packet_len(0x1e9));
  4997. memcpy(WFIFOP(fd,0),buf,packet_len(0x1e9));
  4998. WFIFOSET(fd,packet_len(0x1e9));
  4999. return 1;
  5000. }
  5001. if (!sd) {
  5002. for (i=0; i<MAX_PARTY && !p->data[i].sd; i++)
  5003. if (i >= MAX_PARTY) return 0; //Should never happen...
  5004. sd=p->data[i].sd;
  5005. }
  5006. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  5007. return 1;
  5008. }
  5009. int clif_party_join_info(struct party *p, struct map_session_data *sd)
  5010. {
  5011. unsigned char buf[96];
  5012. WBUFW(buf,0)=0x1e9;
  5013. WBUFL(buf,2)= sd->status.account_id;
  5014. WBUFL(buf,6)= 0; //Apparently setting this to 1 makes you adoptable.
  5015. WBUFW(buf,10)=sd->bl.x;
  5016. WBUFW(buf,12)=sd->bl.y;
  5017. WBUFB(buf,14)=0; //Unconfirmed byte.
  5018. memcpy(WBUFP(buf,15), p->name, NAME_LENGTH);
  5019. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5020. memcpy(WBUFP(buf,63), mapindex_id2name(sd->mapindex), MAP_NAME_LENGTH);
  5021. WBUFB(buf,79) = (p->item&1)?1:0;
  5022. WBUFB(buf,80) = (p->item&2)?1:0;
  5023. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY_WOS);
  5024. return 1;
  5025. }
  5026. /*==========================================
  5027. * パーティ情報送信
  5028. *------------------------------------------
  5029. */
  5030. int clif_party_info(struct party_data *p,int fd)
  5031. {
  5032. unsigned char buf[1024];
  5033. int i,c;
  5034. struct map_session_data *sd=NULL;
  5035. nullpo_retr(0, p);
  5036. WBUFW(buf,0)=0xfb;
  5037. memcpy(WBUFP(buf,4),p->party.name,NAME_LENGTH);
  5038. for(i=c=0;i<MAX_PARTY;i++){
  5039. struct party_member *m=&p->party.member[i];
  5040. if(!m->account_id)
  5041. continue;
  5042. if(sd==NULL) sd=p->data[i].sd;
  5043. WBUFL(buf,28+c*46)=m->account_id;
  5044. memcpy(WBUFP(buf,28+c*46+ 4),m->name,NAME_LENGTH);
  5045. memcpy(WBUFP(buf,28+c*46+28),mapindex_id2name(m->map),MAP_NAME_LENGTH);
  5046. WBUFB(buf,28+c*46+44)=(m->leader)?0:1;
  5047. WBUFB(buf,28+c*46+45)=(m->online)?0:1;
  5048. c++;
  5049. }
  5050. WBUFW(buf,2)=28+c*46;
  5051. if(fd>=0){ // fdが設定されてるならそれに送る
  5052. WFIFOHEAD(fd, 28+c*46);
  5053. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  5054. WFIFOSET(fd,WFIFOW(fd,2));
  5055. return 9;
  5056. }
  5057. if(sd!=NULL)
  5058. clif_send(buf,WBUFW(buf,2),&sd->bl,PARTY);
  5059. return 0;
  5060. }
  5061. /*==========================================
  5062. * パーティ勧誘
  5063. *------------------------------------------
  5064. */
  5065. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5066. {
  5067. int fd;
  5068. struct party_data *p;
  5069. nullpo_retr(0, sd);
  5070. nullpo_retr(0, tsd);
  5071. fd=tsd->fd;
  5072. if( (p=party_search(sd->status.party_id))==NULL )
  5073. return 0;
  5074. WFIFOHEAD(fd,packet_len(0xfe));
  5075. WFIFOW(fd,0)=0xfe;
  5076. WFIFOL(fd,2)=sd->status.account_id;
  5077. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5078. WFIFOSET(fd,packet_len(0xfe));
  5079. return 0;
  5080. }
  5081. /*==========================================
  5082. * Party invitation result. Flag values are:
  5083. * 0 -> char is already in a party
  5084. * 1 -> party invite was rejected
  5085. * 2 -> party invite was accepted
  5086. * 3 -> party is full
  5087. * 4 -> char of the same account already joined the party
  5088. *------------------------------------------
  5089. */
  5090. int clif_party_inviteack(struct map_session_data *sd,char *nick,int flag)
  5091. {
  5092. int fd;
  5093. nullpo_retr(0, sd);
  5094. fd=sd->fd;
  5095. WFIFOHEAD(fd,packet_len(0xfd));
  5096. WFIFOW(fd,0)=0xfd;
  5097. memcpy(WFIFOP(fd,2),nick,NAME_LENGTH);
  5098. WFIFOB(fd,26)=flag;
  5099. WFIFOSET(fd,packet_len(0xfd));
  5100. return 0;
  5101. }
  5102. /*==========================================
  5103. * パーティ設定送信
  5104. * flag & 0x001=exp変更ミス
  5105. * 0x010=item変更ミス
  5106. * 0x100=一人にのみ送信
  5107. *------------------------------------------
  5108. */
  5109. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5110. {
  5111. unsigned char buf[16];
  5112. nullpo_retr(0, p);
  5113. if(!sd && flag==0){
  5114. int i;
  5115. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5116. if (i < MAX_PARTY)
  5117. sd = p->data[i].sd;
  5118. }
  5119. if(!sd) return 0;
  5120. WBUFW(buf,0)=0x101;
  5121. // WBUFL(buf,2) // that's how the client reads it, still need to check it's uses [FlavioJS]
  5122. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  5123. WBUFW(buf,4)=0;
  5124. if(flag==0)
  5125. clif_send(buf,packet_len(0x101),&sd->bl,PARTY);
  5126. else
  5127. clif_send(buf,packet_len(0x101),&sd->bl,SELF);
  5128. return 0;
  5129. }
  5130. /*==========================================
  5131. * パーティ脱退(脱退前に呼ぶこと)
  5132. *------------------------------------------
  5133. */
  5134. int clif_party_leaved(struct party_data *p,struct map_session_data *sd,int account_id,char *name,int flag)
  5135. {
  5136. unsigned char buf[64];
  5137. int i;
  5138. nullpo_retr(0, p);
  5139. if(!sd && (flag&0xf0)==0)
  5140. {
  5141. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5142. if (i < MAX_PARTY)
  5143. sd = p->data[i].sd;
  5144. }
  5145. if(!sd) return 0;
  5146. WBUFW(buf,0)=0x105;
  5147. WBUFL(buf,2)=account_id;
  5148. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5149. WBUFB(buf,30)=flag&0x0f;
  5150. if((flag&0xf0)==0)
  5151. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  5152. else
  5153. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  5154. return 0;
  5155. }
  5156. /*==========================================
  5157. * パーティメッセージ送信
  5158. *------------------------------------------
  5159. */
  5160. int clif_party_message(struct party_data *p,int account_id,char *mes,int len)
  5161. {
  5162. struct map_session_data *sd;
  5163. int i;
  5164. nullpo_retr(0, p);
  5165. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  5166. if(i < MAX_PARTY){
  5167. unsigned char buf[1024];
  5168. sd = p->data[i].sd;
  5169. WBUFW(buf,0)=0x109;
  5170. WBUFW(buf,2)=len+8;
  5171. WBUFL(buf,4)=account_id;
  5172. memcpy(WBUFP(buf,8),mes,len);
  5173. clif_send(buf,len+8,&sd->bl,PARTY);
  5174. }
  5175. return 0;
  5176. }
  5177. /*==========================================
  5178. * パーティ座標通知
  5179. *------------------------------------------
  5180. */
  5181. int clif_party_xy(struct map_session_data *sd)
  5182. {
  5183. unsigned char buf[16];
  5184. nullpo_retr(0, sd);
  5185. WBUFW(buf,0)=0x107;
  5186. WBUFL(buf,2)=sd->status.account_id;
  5187. WBUFW(buf,6)=sd->bl.x;
  5188. WBUFW(buf,8)=sd->bl.y;
  5189. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  5190. return 0;
  5191. }
  5192. /*==========================================
  5193. * Sends x/y dot to a single fd. [Skotlex]
  5194. *------------------------------------------
  5195. */
  5196. int clif_party_xy_single(int fd, struct map_session_data *sd)
  5197. {
  5198. WFIFOHEAD(fd,packet_len(0x107));
  5199. WFIFOW(fd,0)=0x107;
  5200. WFIFOL(fd,2)=sd->status.account_id;
  5201. WFIFOW(fd,6)=sd->bl.x;
  5202. WFIFOW(fd,8)=sd->bl.y;
  5203. WFIFOSET(fd,packet_len(0x107));
  5204. return 0;
  5205. }
  5206. /*==========================================
  5207. * パーティHP通知
  5208. *------------------------------------------
  5209. */
  5210. int clif_party_hp(struct map_session_data *sd)
  5211. {
  5212. unsigned char buf[16];
  5213. nullpo_retr(0, sd);
  5214. WBUFW(buf,0)=0x106;
  5215. WBUFL(buf,2)=sd->status.account_id;
  5216. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5217. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5218. WBUFW(buf,8) = 100;
  5219. } else {
  5220. WBUFW(buf,6) = sd->battle_status.hp;
  5221. WBUFW(buf,8) = sd->battle_status.max_hp;
  5222. }
  5223. clif_send(buf,packet_len(0x106),&sd->bl,PARTY_AREA_WOS);
  5224. return 0;
  5225. }
  5226. /*==========================================
  5227. * Sends HP bar to a single fd. [Skotlex]
  5228. *------------------------------------------
  5229. */
  5230. static void clif_hpmeter_single(int fd, struct map_session_data *sd)
  5231. {
  5232. WFIFOHEAD(fd,packet_len(0x106));
  5233. WFIFOW(fd,0) = 0x106;
  5234. WFIFOL(fd,2) = sd->status.account_id;
  5235. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5236. WFIFOW(fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5237. WFIFOW(fd,8) = 100;
  5238. } else {
  5239. WFIFOW(fd,6) = sd->battle_status.hp;
  5240. WFIFOW(fd,8) = sd->battle_status.max_hp;
  5241. }
  5242. WFIFOSET (fd, packet_len(0x106));
  5243. }
  5244. /*==========================================
  5245. * GMへ場所とHP通知
  5246. *------------------------------------------
  5247. */
  5248. int clif_hpmeter(struct map_session_data *sd)
  5249. {
  5250. struct map_session_data *sd2;
  5251. unsigned char buf[16];
  5252. int i, x0, y0, x1, y1;
  5253. int level;
  5254. nullpo_retr(0, sd);
  5255. x0 = sd->bl.x - AREA_SIZE;
  5256. y0 = sd->bl.y - AREA_SIZE;
  5257. x1 = sd->bl.x + AREA_SIZE;
  5258. y1 = sd->bl.y + AREA_SIZE;
  5259. WBUFW(buf,0) = 0x106;
  5260. WBUFL(buf,2) = sd->status.account_id;
  5261. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5262. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5263. WBUFW(buf,8) = 100;
  5264. } else {
  5265. WBUFW(buf,6) = sd->battle_status.hp;
  5266. WBUFW(buf,8) = sd->battle_status.max_hp;
  5267. }
  5268. for (i = 0; i < fd_max; i++) {
  5269. if (session[i] && session[i]->func_parse == clif_parse &&
  5270. (sd2 = (struct map_session_data*)session[i]->session_data) &&
  5271. sd != sd2 && sd2->state.auth) {
  5272. if (sd2->bl.m != sd->bl.m ||
  5273. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  5274. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  5275. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  5276. level < pc_isGM(sd))
  5277. continue;
  5278. WFIFOHEAD (i, packet_len(0x106));
  5279. memcpy (WFIFOP(i,0), buf, packet_len(0x106));
  5280. WFIFOSET (i, packet_len(0x106));
  5281. }
  5282. }
  5283. return 0;
  5284. }
  5285. /*==========================================
  5286. * パーティ場所移動(未使用)
  5287. *------------------------------------------
  5288. */
  5289. int clif_party_move(struct party *p,struct map_session_data *sd,int online)
  5290. {
  5291. unsigned char buf[128];
  5292. nullpo_retr(0, sd);
  5293. nullpo_retr(0, p);
  5294. WBUFW(buf, 0)=0x104;
  5295. WBUFL(buf, 2)=sd->status.account_id;
  5296. WBUFL(buf, 6)=0;
  5297. WBUFW(buf,10)=sd->bl.x;
  5298. WBUFW(buf,12)=sd->bl.y;
  5299. WBUFB(buf,14)=!online;
  5300. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  5301. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  5302. memcpy(WBUFP(buf,63),map[sd->bl.m].name, MAP_NAME_LENGTH);
  5303. clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
  5304. return 0;
  5305. }
  5306. /*==========================================
  5307. * 攻撃するために移動が必要
  5308. *------------------------------------------
  5309. */
  5310. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5311. {
  5312. int fd;
  5313. nullpo_retr(0, sd);
  5314. nullpo_retr(0, bl);
  5315. fd=sd->fd;
  5316. WFIFOHEAD(fd,packet_len(0x139));
  5317. WFIFOW(fd, 0)=0x139;
  5318. WFIFOL(fd, 2)=bl->id;
  5319. WFIFOW(fd, 6)=bl->x;
  5320. WFIFOW(fd, 8)=bl->y;
  5321. WFIFOW(fd,10)=sd->bl.x;
  5322. WFIFOW(fd,12)=sd->bl.y;
  5323. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5324. WFIFOSET(fd,packet_len(0x139));
  5325. return 0;
  5326. }
  5327. /*==========================================
  5328. * 製造エフェクト
  5329. *------------------------------------------
  5330. */
  5331. int clif_produceeffect(struct map_session_data *sd,int flag,int nameid)
  5332. {
  5333. int view,fd;
  5334. nullpo_retr(0, sd);
  5335. fd=sd->fd;
  5336. // 名前の登録と送信を先にしておく
  5337. if( map_charid2nick(sd->status.char_id)==NULL )
  5338. map_addchariddb(sd->status.char_id,sd->status.name);
  5339. clif_solved_charname(sd,sd->status.char_id);
  5340. WFIFOHEAD(fd,packet_len(0x18f));
  5341. WFIFOW(fd, 0)=0x18f;
  5342. WFIFOW(fd, 2)=flag;
  5343. if((view = itemdb_viewid(nameid)) > 0)
  5344. WFIFOW(fd, 4)=view;
  5345. else
  5346. WFIFOW(fd, 4)=nameid;
  5347. WFIFOSET(fd,packet_len(0x18f));
  5348. return 0;
  5349. }
  5350. // pet
  5351. int clif_catch_process(struct map_session_data *sd)
  5352. {
  5353. int fd;
  5354. nullpo_retr(0, sd);
  5355. fd=sd->fd;
  5356. WFIFOHEAD(fd,packet_len(0x19e));
  5357. WFIFOW(fd,0)=0x19e;
  5358. WFIFOSET(fd,packet_len(0x19e));
  5359. sd->menuskill_id = SA_TAMINGMONSTER;
  5360. if (sd->ud.skillid == SA_TAMINGMONSTER)
  5361. sd->menuskill_lv = 0; //Free catch
  5362. else
  5363. sd->menuskill_lv = sd->itemid; //Consume catch
  5364. return 0;
  5365. }
  5366. int clif_pet_rulet(struct map_session_data *sd,int data)
  5367. {
  5368. int fd;
  5369. nullpo_retr(0, sd);
  5370. fd=sd->fd;
  5371. WFIFOHEAD(fd,packet_len(0x1a0));
  5372. WFIFOW(fd,0)=0x1a0;
  5373. WFIFOB(fd,2)=data;
  5374. WFIFOSET(fd,packet_len(0x1a0));
  5375. return 0;
  5376. }
  5377. /*==========================================
  5378. * pet卵リスト作成
  5379. *------------------------------------------
  5380. */
  5381. int clif_sendegg(struct map_session_data *sd)
  5382. {
  5383. //R 01a6 <len>.w <index>.w*
  5384. int i,n=0,fd;
  5385. nullpo_retr(0, sd);
  5386. fd=sd->fd;
  5387. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5388. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5389. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5390. return 0;
  5391. }
  5392. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5393. WFIFOW(fd,0)=0x1a6;
  5394. if(sd->status.pet_id <= 0) {
  5395. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5396. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5397. sd->inventory_data[i]->type!=IT_PETEGG ||
  5398. sd->status.inventory[i].amount<=0)
  5399. continue;
  5400. WFIFOW(fd,n*2+4)=i+2;
  5401. n++;
  5402. }
  5403. }
  5404. WFIFOW(fd,2)=4+n*2;
  5405. WFIFOSET(fd,WFIFOW(fd,2));
  5406. sd->menuskill_id = SA_TAMINGMONSTER;
  5407. sd->menuskill_lv = -1;
  5408. return 0;
  5409. }
  5410. int clif_send_petdata(struct map_session_data *sd,int type,int param)
  5411. {
  5412. int fd;
  5413. nullpo_retr(0, sd);
  5414. nullpo_retr(0, sd->pd);
  5415. fd=sd->fd;
  5416. WFIFOHEAD(fd,packet_len(0x1a4));
  5417. WFIFOW(fd,0)=0x1a4;
  5418. WFIFOB(fd,2)=type;
  5419. WFIFOL(fd,3)=sd->pd->bl.id;
  5420. WFIFOL(fd,7)=param;
  5421. WFIFOSET(fd,packet_len(0x1a4));
  5422. return 0;
  5423. }
  5424. int clif_send_petstatus(struct map_session_data *sd)
  5425. {
  5426. int fd;
  5427. struct s_pet *pet;
  5428. nullpo_retr(0, sd);
  5429. nullpo_retr(0, sd->pd);
  5430. fd=sd->fd;
  5431. pet = &sd->pd->pet;
  5432. WFIFOHEAD(fd,packet_len(0x1a2));
  5433. WFIFOW(fd,0)=0x1a2;
  5434. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5435. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5436. WFIFOW(fd,27)=pet->level;
  5437. WFIFOW(fd,29)=pet->hungry;
  5438. WFIFOW(fd,31)=pet->intimate;
  5439. WFIFOW(fd,33)=pet->equip;
  5440. WFIFOSET(fd,packet_len(0x1a2));
  5441. return 0;
  5442. }
  5443. /*==========================================
  5444. *
  5445. *------------------------------------------
  5446. */
  5447. int clif_pet_emotion(struct pet_data *pd,int param)
  5448. {
  5449. unsigned char buf[16];
  5450. nullpo_retr(0, pd);
  5451. memset(buf,0,packet_len(0x1aa));
  5452. WBUFW(buf,0)=0x1aa;
  5453. WBUFL(buf,2)=pd->bl.id;
  5454. if(param >= 100 && pd->petDB->talk_convert_class) {
  5455. if(pd->petDB->talk_convert_class < 0)
  5456. return 0;
  5457. else if(pd->petDB->talk_convert_class > 0) {
  5458. param -= (pd->pet.class_ - 100)*100;
  5459. param += (pd->petDB->talk_convert_class - 100)*100;
  5460. }
  5461. }
  5462. WBUFL(buf,6)=param;
  5463. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5464. return 0;
  5465. }
  5466. int clif_pet_performance(struct block_list *bl,int param)
  5467. {
  5468. unsigned char buf[16];
  5469. nullpo_retr(0, bl);
  5470. memset(buf,0,packet_len(0x1a4));
  5471. WBUFW(buf,0)=0x1a4;
  5472. WBUFB(buf,2)=4;
  5473. WBUFL(buf,3)=bl->id;
  5474. WBUFL(buf,7)=param;
  5475. clif_send(buf,packet_len(0x1a4),bl,AREA);
  5476. return 0;
  5477. }
  5478. int clif_pet_equip(struct pet_data *pd)
  5479. {
  5480. unsigned char buf[16];
  5481. nullpo_retr(0, pd);
  5482. memset(buf,0,packet_len(0x1a4));
  5483. WBUFW(buf,0)=0x1a4;
  5484. WBUFB(buf,2)=3;
  5485. WBUFL(buf,3)=pd->bl.id;
  5486. WBUFL(buf,7)=pd->vd.shield;
  5487. clif_send(buf,packet_len(0x1a4),&pd->bl,AREA);
  5488. return 0;
  5489. }
  5490. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5491. {
  5492. int fd;
  5493. nullpo_retr(0, sd);
  5494. fd=sd->fd;
  5495. WFIFOHEAD(fd,packet_len(0x1a3));
  5496. WFIFOW(fd,0)=0x1a3;
  5497. WFIFOB(fd,2)=fail;
  5498. WFIFOW(fd,3)=foodid;
  5499. WFIFOSET(fd,packet_len(0x1a3));
  5500. return 0;
  5501. }
  5502. /*==========================================
  5503. * オートスペル リスト送信
  5504. *------------------------------------------
  5505. */
  5506. int clif_autospell(struct map_session_data *sd,int skilllv)
  5507. {
  5508. int fd;
  5509. nullpo_retr(0, sd);
  5510. fd=sd->fd;
  5511. WFIFOHEAD(fd,packet_len(0x1cd));
  5512. WFIFOW(fd, 0)=0x1cd;
  5513. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5514. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5515. else
  5516. WFIFOL(fd,2)= 0x00000000;
  5517. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5518. WFIFOL(fd,6)= MG_COLDBOLT;
  5519. else
  5520. WFIFOL(fd,6)= 0x00000000;
  5521. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5522. WFIFOL(fd,10)= MG_FIREBOLT;
  5523. else
  5524. WFIFOL(fd,10)= 0x00000000;
  5525. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5526. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5527. else
  5528. WFIFOL(fd,14)= 0x00000000;
  5529. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5530. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5531. else
  5532. WFIFOL(fd,18)= 0x00000000;
  5533. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5534. WFIFOL(fd,22)= MG_FIREBALL;
  5535. else
  5536. WFIFOL(fd,22)= 0x00000000;
  5537. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5538. WFIFOL(fd,26)= MG_FROSTDIVER;
  5539. else
  5540. WFIFOL(fd,26)= 0x00000000;
  5541. WFIFOSET(fd,packet_len(0x1cd));
  5542. sd->menuskill_id = SA_AUTOSPELL;
  5543. sd->menuskill_lv = skilllv;
  5544. return 0;
  5545. }
  5546. /*==========================================
  5547. * ディボーションの青い糸
  5548. *------------------------------------------
  5549. */
  5550. int clif_devotion(struct map_session_data *sd)
  5551. {
  5552. unsigned char buf[56];
  5553. int i,n;
  5554. nullpo_retr(0, sd);
  5555. WBUFW(buf,0)=0x1cf;
  5556. WBUFL(buf,2)=sd->bl.id;
  5557. for(i=0,n=0;i<5;i++) {
  5558. if (!sd->devotion[i])
  5559. continue;
  5560. WBUFL(buf,6+4*n)=sd->devotion[i];
  5561. n++;
  5562. }
  5563. for(;n<5;n++)
  5564. WBUFL(buf,6+4*n)=0;
  5565. WBUFB(buf,26)=8;
  5566. WBUFB(buf,27)=0;
  5567. clif_send(buf,packet_len(0x1cf),&sd->bl,AREA);
  5568. return 0;
  5569. }
  5570. int clif_marionette(struct block_list *src, struct block_list *target)
  5571. {
  5572. unsigned char buf[56];
  5573. int n;
  5574. WBUFW(buf,0)=0x1cf;
  5575. WBUFL(buf,2)=src->id;
  5576. for(n=0;n<5;n++)
  5577. WBUFL(buf,6+4*n)=0;
  5578. if (target) //The target goes on the second slot.
  5579. WBUFL(buf,6+4) = target->id;
  5580. WBUFB(buf,26)=8;
  5581. WBUFB(buf,27)=0;
  5582. clif_send(buf,packet_len(0x1cf),src,AREA);
  5583. return 0;
  5584. }
  5585. /*==========================================
  5586. * 氣球
  5587. *------------------------------------------
  5588. */
  5589. int clif_spiritball(struct map_session_data *sd)
  5590. {
  5591. unsigned char buf[16];
  5592. nullpo_retr(0, sd);
  5593. WBUFW(buf,0)=0x1d0;
  5594. WBUFL(buf,2)=sd->bl.id;
  5595. WBUFW(buf,6)=sd->spiritball;
  5596. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5597. return 0;
  5598. }
  5599. /*==========================================
  5600. *
  5601. *------------------------------------------
  5602. */
  5603. int clif_combo_delay(struct block_list *bl,int wait)
  5604. {
  5605. unsigned char buf[32];
  5606. nullpo_retr(0, bl);
  5607. WBUFW(buf,0)=0x1d2;
  5608. WBUFL(buf,2)=bl->id;
  5609. WBUFL(buf,6)=wait;
  5610. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5611. return 0;
  5612. }
  5613. /*==========================================
  5614. *白刃取り
  5615. *------------------------------------------
  5616. */
  5617. int clif_bladestop(struct block_list *src,struct block_list *dst,
  5618. int _bool)
  5619. {
  5620. unsigned char buf[32];
  5621. nullpo_retr(0, src);
  5622. nullpo_retr(0, dst);
  5623. WBUFW(buf,0)=0x1d1;
  5624. WBUFL(buf,2)=src->id;
  5625. WBUFL(buf,6)=dst->id;
  5626. WBUFL(buf,10)=_bool;
  5627. clif_send(buf,packet_len(0x1d1),src,AREA);
  5628. return 0;
  5629. }
  5630. /*==========================================
  5631. *
  5632. *------------------------------------------
  5633. */
  5634. int clif_changemapcell(int m,int x,int y,int cell_type,int type)
  5635. {
  5636. struct block_list bl;
  5637. unsigned char buf[32];
  5638. bl.type = BL_NUL;
  5639. bl.m = m;
  5640. bl.x = x;
  5641. bl.y = y;
  5642. WBUFW(buf,0) = 0x192;
  5643. WBUFW(buf,2) = x;
  5644. WBUFW(buf,4) = y;
  5645. WBUFW(buf,6) = cell_type;
  5646. memcpy(WBUFP(buf,8),map[m].name,MAP_NAME_LENGTH);
  5647. if(!type)
  5648. clif_send(buf,packet_len(0x192),&bl,AREA);
  5649. else
  5650. clif_send(buf,packet_len(0x192),&bl,ALL_SAMEMAP);
  5651. return 0;
  5652. }
  5653. /*==========================================
  5654. * MVPエフェクト
  5655. *------------------------------------------
  5656. */
  5657. int clif_mvp_effect(struct map_session_data *sd)
  5658. {
  5659. unsigned char buf[16];
  5660. nullpo_retr(0, sd);
  5661. WBUFW(buf,0)=0x10c;
  5662. WBUFL(buf,2)=sd->bl.id;
  5663. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5664. return 0;
  5665. }
  5666. /*==========================================
  5667. * MVPアイテム所得
  5668. *------------------------------------------
  5669. */
  5670. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5671. {
  5672. int view,fd;
  5673. nullpo_retr(0, sd);
  5674. fd=sd->fd;
  5675. WFIFOHEAD(fd,packet_len(0x10a));
  5676. WFIFOW(fd,0)=0x10a;
  5677. if((view = itemdb_viewid(nameid)) > 0)
  5678. WFIFOW(fd,2)=view;
  5679. else
  5680. WFIFOW(fd,2)=nameid;
  5681. WFIFOSET(fd,packet_len(0x10a));
  5682. return 0;
  5683. }
  5684. /*==========================================
  5685. * MVP経験値所得
  5686. *------------------------------------------
  5687. */
  5688. int clif_mvp_exp(struct map_session_data *sd,unsigned long exp)
  5689. {
  5690. int fd;
  5691. nullpo_retr(0, sd);
  5692. fd=sd->fd;
  5693. WFIFOHEAD(fd,packet_len(0x10b));
  5694. WFIFOW(fd,0)=0x10b;
  5695. WFIFOL(fd,2)=exp;
  5696. WFIFOSET(fd,packet_len(0x10b));
  5697. return 0;
  5698. }
  5699. /*==========================================
  5700. * ギルド作成可否通知
  5701. *------------------------------------------
  5702. */
  5703. int clif_guild_created(struct map_session_data *sd,int flag)
  5704. {
  5705. int fd;
  5706. nullpo_retr(0, sd);
  5707. fd=sd->fd;
  5708. WFIFOHEAD(fd,packet_len(0x167));
  5709. WFIFOW(fd,0)=0x167;
  5710. WFIFOB(fd,2)=flag;
  5711. WFIFOSET(fd,packet_len(0x167));
  5712. return 0;
  5713. }
  5714. /*==========================================
  5715. * ギルド所属通知
  5716. *------------------------------------------
  5717. */
  5718. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  5719. {
  5720. int ps,fd;
  5721. nullpo_retr(0, sd);
  5722. nullpo_retr(0, g);
  5723. fd=sd->fd;
  5724. ps=guild_getposition(sd,g);
  5725. WFIFOHEAD(fd,packet_len(0x16c));
  5726. memset(WFIFOP(fd,0),0,packet_len(0x16c));
  5727. WFIFOW(fd,0)=0x16c;
  5728. WFIFOL(fd,2)=g->guild_id;
  5729. WFIFOL(fd,6)=g->emblem_id;
  5730. WFIFOL(fd,10)=g->position[ps].mode;
  5731. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5732. WFIFOSET(fd,packet_len(0x16c));
  5733. return 0;
  5734. }
  5735. /*==========================================
  5736. * ギルドメンバログイン通知
  5737. *------------------------------------------
  5738. */
  5739. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5740. {
  5741. unsigned char buf[64];
  5742. nullpo_retr(0, g);
  5743. WBUFW(buf, 0)=0x16d;
  5744. WBUFL(buf, 2)=g->member[idx].account_id;
  5745. WBUFL(buf, 6)=g->member[idx].char_id;
  5746. WBUFL(buf,10)=flag;
  5747. if(g->member[idx].sd==NULL){
  5748. struct map_session_data *sd=guild_getavailablesd(g);
  5749. if(sd!=NULL)
  5750. clif_send(buf,packet_len(0x16d),&sd->bl,GUILD);
  5751. }else
  5752. clif_send(buf,packet_len(0x16d),&g->member[idx].sd->bl,GUILD_WOS);
  5753. return 0;
  5754. }
  5755. // Function `clif_guild_memberlogin_notice` sends info about
  5756. // logins and logouts of a guild member to the rest members.
  5757. // But at the 1st time (after a player login or map changing)
  5758. // the client won't show the message.
  5759. // So I suggest use this function for sending "first-time-info"
  5760. // to some player on entering the game or changing location.
  5761. // At next time the client would always show the message.
  5762. // The function sends all the statuses in the single packet
  5763. // to economize traffic. [LuzZza]
  5764. int clif_guild_send_onlineinfo(struct map_session_data *sd) {
  5765. struct guild *g;
  5766. char buf[14*128];
  5767. int i, count=0, p_len;
  5768. nullpo_retr(0, sd);
  5769. p_len = packet_len(0x16d);
  5770. if(!(g = guild_search(sd->status.guild_id)))
  5771. return 0;
  5772. for(i=0; i<g->max_member; i++) {
  5773. if(g->member[i].account_id > 0 &&
  5774. g->member[i].account_id != sd->status.account_id) {
  5775. WBUFW(buf,count*p_len) = 0x16d;
  5776. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5777. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5778. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5779. count++;
  5780. }
  5781. }
  5782. clif_send(buf,p_len*count,&sd->bl,SELF);
  5783. return 0;
  5784. }
  5785. /*==========================================
  5786. * ギルドマスター通知(14dへの応答)
  5787. *------------------------------------------
  5788. */
  5789. int clif_guild_masterormember(struct map_session_data *sd)
  5790. {
  5791. int type=0x57,fd;
  5792. nullpo_retr(0, sd);
  5793. fd=sd->fd;
  5794. if(sd->state.gmaster_flag)
  5795. type=0xd7;
  5796. WFIFOHEAD(fd,packet_len(0x14e));
  5797. WFIFOW(fd,0)=0x14e;
  5798. WFIFOL(fd,2)=type;
  5799. WFIFOSET(fd,packet_len(0x14e));
  5800. return 0;
  5801. }
  5802. /*==========================================
  5803. * Basic Info (Territories [Valaris])
  5804. *------------------------------------------
  5805. */
  5806. int clif_guild_basicinfo(struct map_session_data *sd)
  5807. {
  5808. int fd,i,t=0;
  5809. struct guild *g;
  5810. struct guild_castle *gc=NULL;
  5811. nullpo_retr(0, sd);
  5812. fd=sd->fd;
  5813. g=guild_search(sd->status.guild_id);
  5814. if(g==NULL)
  5815. return 0;
  5816. WFIFOHEAD(fd,packet_len(0x1b6));
  5817. WFIFOW(fd, 0)=0x1b6;//0x150;
  5818. WFIFOL(fd, 2)=g->guild_id;
  5819. WFIFOL(fd, 6)=g->guild_lv;
  5820. WFIFOL(fd,10)=g->connect_member;
  5821. WFIFOL(fd,14)=g->max_member;
  5822. WFIFOL(fd,18)=g->average_lv;
  5823. WFIFOL(fd,22)=g->exp;
  5824. WFIFOL(fd,26)=g->next_exp;
  5825. WFIFOL(fd,30)=0; // Tax Points
  5826. WFIFOL(fd,34)=0; // Tendency: (left) Vulgar [-100,100] Famed (right)
  5827. WFIFOL(fd,38)=0; // Tendency: (down) Wicked [-100,100] Righteous (up)
  5828. WFIFOL(fd,42)=g->emblem_id;
  5829. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5830. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5831. for(i=0;i<MAX_GUILDCASTLE;i++){
  5832. gc=guild_castle_search(i);
  5833. if(!gc) continue;
  5834. if(g->guild_id == gc->guild_id) t++;
  5835. }
  5836. if (t>=0 && t<=MAX_GUILDCASTLE) //(0=None, 1..24 = N of Casles) [Lupus]
  5837. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20);
  5838. else
  5839. strncpy((char*)WFIFOP(fd,94),msg_txt(299),20);
  5840. WFIFOSET(fd,packet_len(WFIFOW(fd,0)));
  5841. return 0;
  5842. }
  5843. /*==========================================
  5844. * ギルド同盟/敵対情報
  5845. *------------------------------------------
  5846. */
  5847. int clif_guild_allianceinfo(struct map_session_data *sd)
  5848. {
  5849. int fd,i,c;
  5850. struct guild *g;
  5851. nullpo_retr(0, sd);
  5852. fd=sd->fd;
  5853. g=guild_search(sd->status.guild_id);
  5854. if(g==NULL)
  5855. return 0;
  5856. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5857. WFIFOW(fd, 0)=0x14c;
  5858. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5859. struct guild_alliance *a=&g->alliance[i];
  5860. if(a->guild_id>0){
  5861. WFIFOL(fd,c*32+4)=a->opposition;
  5862. WFIFOL(fd,c*32+8)=a->guild_id;
  5863. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5864. c++;
  5865. }
  5866. }
  5867. WFIFOW(fd, 2)=c*32+4;
  5868. WFIFOSET(fd,WFIFOW(fd,2));
  5869. return 0;
  5870. }
  5871. /*==========================================
  5872. * ギルドメンバーリスト
  5873. *------------------------------------------
  5874. */
  5875. int clif_guild_memberlist(struct map_session_data *sd)
  5876. {
  5877. int fd;
  5878. int i,c;
  5879. struct guild *g;
  5880. nullpo_retr(0, sd);
  5881. fd=sd->fd;
  5882. if (!fd)
  5883. return 0;
  5884. g=guild_search(sd->status.guild_id);
  5885. if(g==NULL)
  5886. return 0;
  5887. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5888. WFIFOW(fd, 0)=0x154;
  5889. for(i=0,c=0;i<g->max_member;i++){
  5890. struct guild_member *m=&g->member[i];
  5891. if(m->account_id==0)
  5892. continue;
  5893. WFIFOL(fd,c*104+ 4)=m->account_id;
  5894. WFIFOL(fd,c*104+ 8)=m->char_id;
  5895. WFIFOW(fd,c*104+12)=m->hair;
  5896. WFIFOW(fd,c*104+14)=m->hair_color;
  5897. WFIFOW(fd,c*104+16)=m->gender;
  5898. WFIFOW(fd,c*104+18)=m->class_;
  5899. WFIFOW(fd,c*104+20)=m->lv;
  5900. WFIFOL(fd,c*104+22)=m->exp;
  5901. WFIFOL(fd,c*104+26)=m->online;
  5902. WFIFOL(fd,c*104+30)=m->position;
  5903. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5904. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5905. c++;
  5906. }
  5907. WFIFOW(fd, 2)=c*104+4;
  5908. WFIFOSET(fd,WFIFOW(fd,2));
  5909. return 0;
  5910. }
  5911. /*==========================================
  5912. * ギルド役職名リスト
  5913. *------------------------------------------
  5914. */
  5915. int clif_guild_positionnamelist(struct map_session_data *sd)
  5916. {
  5917. int i,fd;
  5918. struct guild *g;
  5919. nullpo_retr(0, sd);
  5920. fd=sd->fd;
  5921. g=guild_search(sd->status.guild_id);
  5922. if(g==NULL)
  5923. return 0;
  5924. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5925. WFIFOW(fd, 0)=0x166;
  5926. for(i=0;i<MAX_GUILDPOSITION;i++){
  5927. WFIFOL(fd,i*28+4)=i;
  5928. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5929. }
  5930. WFIFOW(fd,2)=i*28+4;
  5931. WFIFOSET(fd,WFIFOW(fd,2));
  5932. return 0;
  5933. }
  5934. /*==========================================
  5935. * ギルド役職情報リスト
  5936. *------------------------------------------
  5937. */
  5938. int clif_guild_positioninfolist(struct map_session_data *sd)
  5939. {
  5940. int i,fd;
  5941. struct guild *g;
  5942. nullpo_retr(0, sd);
  5943. fd=sd->fd;
  5944. g=guild_search(sd->status.guild_id);
  5945. if(g==NULL)
  5946. return 0;
  5947. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5948. WFIFOW(fd, 0)=0x160;
  5949. for(i=0;i<MAX_GUILDPOSITION;i++){
  5950. struct guild_position *p=&g->position[i];
  5951. WFIFOL(fd,i*16+ 4)=i;
  5952. WFIFOL(fd,i*16+ 8)=p->mode;
  5953. WFIFOL(fd,i*16+12)=i;
  5954. WFIFOL(fd,i*16+16)=p->exp_mode;
  5955. }
  5956. WFIFOW(fd, 2)=i*16+4;
  5957. WFIFOSET(fd,WFIFOW(fd,2));
  5958. return 0;
  5959. }
  5960. /*==========================================
  5961. * ギルド役職変更通知
  5962. *------------------------------------------
  5963. */
  5964. int clif_guild_positionchanged(struct guild *g,int idx)
  5965. {
  5966. struct map_session_data *sd;
  5967. unsigned char buf[128];
  5968. nullpo_retr(0, g);
  5969. WBUFW(buf, 0)=0x174;
  5970. WBUFW(buf, 2)=44;
  5971. WBUFL(buf, 4)=idx;
  5972. WBUFL(buf, 8)=g->position[idx].mode;
  5973. WBUFL(buf,12)=idx;
  5974. WBUFL(buf,16)=g->position[idx].exp_mode;
  5975. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  5976. if( (sd=guild_getavailablesd(g))!=NULL )
  5977. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5978. return 0;
  5979. }
  5980. /*==========================================
  5981. * ギルドメンバ変更通知
  5982. *------------------------------------------
  5983. */
  5984. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  5985. {
  5986. struct map_session_data *sd;
  5987. unsigned char buf[64];
  5988. nullpo_retr(0, g);
  5989. WBUFW(buf, 0)=0x156;
  5990. WBUFW(buf, 2)=16;
  5991. WBUFL(buf, 4)=g->member[idx].account_id;
  5992. WBUFL(buf, 8)=g->member[idx].char_id;
  5993. WBUFL(buf,12)=g->member[idx].position;
  5994. if( (sd=guild_getavailablesd(g))!=NULL )
  5995. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5996. return 0;
  5997. }
  5998. /*==========================================
  5999. * ギルドエンブレム送信
  6000. *------------------------------------------
  6001. */
  6002. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6003. {
  6004. int fd;
  6005. nullpo_retr(0, sd);
  6006. nullpo_retr(0, g);
  6007. fd=sd->fd;
  6008. if(g->emblem_len<=0)
  6009. return 0;
  6010. WFIFOHEAD(fd,g->emblem_len+12);
  6011. WFIFOW(fd,0)=0x152;
  6012. WFIFOW(fd,2)=g->emblem_len+12;
  6013. WFIFOL(fd,4)=g->guild_id;
  6014. WFIFOL(fd,8)=g->emblem_id;
  6015. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6016. WFIFOSET(fd,WFIFOW(fd,2));
  6017. return 0;
  6018. }
  6019. /*==========================================
  6020. * ギルドスキル送信
  6021. *------------------------------------------
  6022. */
  6023. int clif_guild_skillinfo(struct map_session_data *sd)
  6024. {
  6025. int fd;
  6026. int i,id,c,up=1;
  6027. struct guild *g;
  6028. nullpo_retr(0, sd);
  6029. fd=sd->fd;
  6030. g=guild_search(sd->status.guild_id);
  6031. if(g==NULL)
  6032. return 0;
  6033. WFIFOHEAD(fd, MAX_GUILDSKILL * 37 + 6);
  6034. WFIFOW(fd,0)=0x0162;
  6035. WFIFOW(fd,4)=g->skill_point;
  6036. for(i=c=0;i<MAX_GUILDSKILL;i++){
  6037. if(g->skill[i].id>0 && guild_check_skill_require(g,g->skill[i].id)){
  6038. WFIFOW(fd,c*37+ 6) = id = g->skill[i].id;
  6039. WFIFOW(fd,c*37+ 8) = skill_get_inf(id);
  6040. WFIFOW(fd,c*37+10) = 0;
  6041. WFIFOW(fd,c*37+12) = g->skill[i].lv;
  6042. WFIFOW(fd,c*37+14) = skill_get_sp(id,g->skill[i].lv);
  6043. WFIFOW(fd,c*37+16) = skill_get_range(id,g->skill[i].lv);
  6044. strncpy(WFIFOP(fd,c*37+18), skill_get_name(id), NAME_LENGTH);
  6045. if(g->skill[i].lv < guild_skill_get_max(id) && (sd == g->member[0].sd))
  6046. up = 1;
  6047. else
  6048. up = 0;
  6049. WFIFOB(fd,c*37+42)= up;
  6050. c++;
  6051. }
  6052. }
  6053. WFIFOW(fd,2)=c*37+6;
  6054. WFIFOSET(fd,WFIFOW(fd,2));
  6055. return 0;
  6056. }
  6057. /*==========================================
  6058. * ギルド告知送信
  6059. *------------------------------------------
  6060. */
  6061. int clif_guild_notice(struct map_session_data *sd,struct guild *g)
  6062. {
  6063. int fd;
  6064. nullpo_retr(0, sd);
  6065. nullpo_retr(0, g);
  6066. fd = sd->fd;
  6067. if ( !session_isActive(fd) ) //null pointer right here [Kevin]
  6068. return 0;
  6069. if (fd <= 0)
  6070. return 0;
  6071. if(*g->mes1==0 && *g->mes2==0)
  6072. return 0;
  6073. WFIFOHEAD(fd,packet_len(0x16f));
  6074. WFIFOW(fd,0)=0x16f;
  6075. memcpy(WFIFOP(fd,2),g->mes1,60);
  6076. memcpy(WFIFOP(fd,62),g->mes2,120);
  6077. WFIFOSET(fd,packet_len(0x16f));
  6078. return 0;
  6079. }
  6080. /*==========================================
  6081. * ギルドメンバ勧誘
  6082. *------------------------------------------
  6083. */
  6084. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6085. {
  6086. int fd;
  6087. nullpo_retr(0, sd);
  6088. nullpo_retr(0, g);
  6089. fd=sd->fd;
  6090. WFIFOHEAD(fd,packet_len(0x16a));
  6091. WFIFOW(fd,0)=0x16a;
  6092. WFIFOL(fd,2)=g->guild_id;
  6093. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6094. WFIFOSET(fd,packet_len(0x16a));
  6095. return 0;
  6096. }
  6097. /*==========================================
  6098. * ギルドメンバ勧誘結果
  6099. *------------------------------------------
  6100. */
  6101. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  6102. {
  6103. int fd;
  6104. nullpo_retr(0, sd);
  6105. fd=sd->fd;
  6106. WFIFOHEAD(fd,packet_len(0x169));
  6107. WFIFOW(fd,0)=0x169;
  6108. WFIFOB(fd,2)=flag;
  6109. WFIFOSET(fd,packet_len(0x169));
  6110. return 0;
  6111. }
  6112. /*==========================================
  6113. * ギルドメンバ脱退通知
  6114. *------------------------------------------
  6115. */
  6116. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6117. {
  6118. unsigned char buf[128];
  6119. nullpo_retr(0, sd);
  6120. WBUFW(buf, 0)=0x15a;
  6121. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6122. memcpy(WBUFP(buf,26),mes,40);
  6123. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD);
  6124. return 0;
  6125. }
  6126. /*==========================================
  6127. * ギルドメンバ追放通知
  6128. *------------------------------------------
  6129. */
  6130. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,
  6131. int account_id)
  6132. {
  6133. unsigned char buf[128];
  6134. nullpo_retr(0, sd);
  6135. WBUFW(buf, 0)=0x15c;
  6136. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6137. memcpy(WBUFP(buf,26),mes,40);
  6138. memcpy(WBUFP(buf,66),"dummy",NAME_LENGTH);
  6139. clif_send(buf,packet_len(0x15c),&sd->bl,GUILD);
  6140. return 0;
  6141. }
  6142. /*==========================================
  6143. * ギルド追放メンバリスト
  6144. *------------------------------------------
  6145. */
  6146. int clif_guild_expulsionlist(struct map_session_data *sd)
  6147. {
  6148. int fd;
  6149. int i,c;
  6150. struct guild *g;
  6151. nullpo_retr(0, sd);
  6152. fd=sd->fd;
  6153. g=guild_search(sd->status.guild_id);
  6154. if(g==NULL)
  6155. return 0;
  6156. WFIFOHEAD(fd,MAX_GUILDEXPULSION * 88 + 4);
  6157. WFIFOW(fd,0)=0x163;
  6158. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  6159. struct guild_expulsion *e=&g->expulsion[i];
  6160. if(e->account_id>0){
  6161. memcpy(WFIFOP(fd,c*88+ 4),e->name,NAME_LENGTH);
  6162. memcpy(WFIFOP(fd,c*88+28),e->acc,24);
  6163. memcpy(WFIFOP(fd,c*88+52),e->mes,44);
  6164. c++;
  6165. }
  6166. }
  6167. WFIFOW(fd,2)=c*88+4;
  6168. WFIFOSET(fd,WFIFOW(fd,2));
  6169. return 0;
  6170. }
  6171. /*==========================================
  6172. * ギルド会話
  6173. *------------------------------------------
  6174. */
  6175. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6176. {
  6177. struct map_session_data *sd;
  6178. unsigned char *buf;
  6179. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  6180. WBUFW(buf, 0) = 0x17f;
  6181. WBUFW(buf, 2) = len + 4;
  6182. memcpy(WBUFP(buf,4), mes, len);
  6183. if ((sd = guild_getavailablesd(g)) != NULL)
  6184. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  6185. if(buf) aFree(buf);
  6186. return 0;
  6187. }
  6188. /*==========================================
  6189. * ギルドスキル割り振り通知
  6190. *------------------------------------------
  6191. */
  6192. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  6193. {
  6194. int fd;
  6195. nullpo_retr(0, sd);
  6196. fd=sd->fd;
  6197. WFIFOHEAD(fd,11);
  6198. WFIFOW(fd,0) = 0x10e;
  6199. WFIFOW(fd,2) = skill_num;
  6200. WFIFOW(fd,4) = lv;
  6201. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  6202. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  6203. WFIFOB(fd,10) = 1;
  6204. WFIFOSET(fd,11);
  6205. return 0;
  6206. }
  6207. /*==========================================
  6208. * ギルド同盟要請
  6209. *------------------------------------------
  6210. */
  6211. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6212. {
  6213. int fd;
  6214. nullpo_retr(0, sd);
  6215. fd=sd->fd;
  6216. WFIFOHEAD(fd,packet_len(0x171));
  6217. WFIFOW(fd,0)=0x171;
  6218. WFIFOL(fd,2)=account_id;
  6219. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6220. WFIFOSET(fd,packet_len(0x171));
  6221. return 0;
  6222. }
  6223. /*==========================================
  6224. * Reply to alliance request.
  6225. * Flag values are:
  6226. * 0: Already allied.
  6227. * 1: You rejected the offer.
  6228. * 2: You accepted the offer.
  6229. * 3: They have too any alliances
  6230. * 4: You have too many alliances.
  6231. *------------------------------------------
  6232. */
  6233. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  6234. {
  6235. int fd;
  6236. nullpo_retr(0, sd);
  6237. fd=sd->fd;
  6238. WFIFOHEAD(fd,packet_len(0x173));
  6239. WFIFOW(fd,0)=0x173;
  6240. WFIFOL(fd,2)=flag;
  6241. WFIFOSET(fd,packet_len(0x173));
  6242. return 0;
  6243. }
  6244. /*==========================================
  6245. * ギルド関係解消通知
  6246. *------------------------------------------
  6247. */
  6248. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6249. {
  6250. int fd;
  6251. nullpo_retr(0, sd);
  6252. fd = sd->fd;
  6253. if (fd <= 0)
  6254. return 0;
  6255. WFIFOHEAD(fd,packet_len(0x184));
  6256. WFIFOW(fd,0)=0x184;
  6257. WFIFOL(fd,2)=guild_id;
  6258. WFIFOL(fd,6)=flag;
  6259. WFIFOSET(fd,packet_len(0x184));
  6260. return 0;
  6261. }
  6262. /*==========================================
  6263. * ギルド敵対結果
  6264. *------------------------------------------
  6265. */
  6266. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6267. {
  6268. int fd;
  6269. nullpo_retr(0, sd);
  6270. fd=sd->fd;
  6271. WFIFOHEAD(fd,packet_len(0x181));
  6272. WFIFOW(fd,0)=0x181;
  6273. WFIFOB(fd,2)=flag;
  6274. WFIFOSET(fd,packet_len(0x181));
  6275. return 0;
  6276. }
  6277. /*==========================================
  6278. * ギルド関係追加
  6279. *------------------------------------------
  6280. */
  6281. /*int clif_guild_allianceadded(struct guild *g,int idx)
  6282. {
  6283. unsigned char buf[64];
  6284. WBUFW(fd,0)=0x185;
  6285. WBUFL(fd,2)=g->alliance[idx].opposition;
  6286. WBUFL(fd,6)=g->alliance[idx].guild_id;
  6287. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  6288. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  6289. return 0;
  6290. }*/
  6291. /*==========================================
  6292. * ギルド解散通知
  6293. *------------------------------------------
  6294. */
  6295. int clif_guild_broken(struct map_session_data *sd,int flag)
  6296. {
  6297. int fd;
  6298. nullpo_retr(0, sd);
  6299. fd=sd->fd;
  6300. WFIFOHEAD(fd,packet_len(0x15e));
  6301. WFIFOW(fd,0)=0x15e;
  6302. WFIFOL(fd,2)=flag;
  6303. WFIFOSET(fd,packet_len(0x15e));
  6304. return 0;
  6305. }
  6306. /*==========================================
  6307. * エモーション
  6308. *------------------------------------------
  6309. */
  6310. void clif_emotion(struct block_list *bl,int type)
  6311. {
  6312. unsigned char buf[8];
  6313. nullpo_retv(bl);
  6314. WBUFW(buf,0)=0xc0;
  6315. WBUFL(buf,2)=bl->id;
  6316. WBUFB(buf,6)=type;
  6317. clif_send(buf,packet_len(0xc0),bl,AREA);
  6318. }
  6319. /*==========================================
  6320. * トーキーボックス
  6321. *------------------------------------------
  6322. */
  6323. void clif_talkiebox(struct block_list *bl,char* talkie)
  6324. {
  6325. unsigned char buf[86];
  6326. nullpo_retv(bl);
  6327. WBUFW(buf,0)=0x191;
  6328. WBUFL(buf,2)=bl->id;
  6329. memcpy(WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6330. clif_send(buf,packet_len(0x191),bl,AREA);
  6331. }
  6332. /*==========================================
  6333. * 結婚エフェクト
  6334. *------------------------------------------
  6335. */
  6336. void clif_wedding_effect(struct block_list *bl) {
  6337. unsigned char buf[6];
  6338. nullpo_retv(bl);
  6339. WBUFW(buf,0) = 0x1ea;
  6340. WBUFL(buf,2) = bl->id;
  6341. clif_send(buf, packet_len(0x1ea), bl, AREA);
  6342. }
  6343. /*==========================================
  6344. * あなたに逢いたい使用時名前叫び
  6345. *------------------------------------------
  6346. void clif_callpartner(struct map_session_data *sd)
  6347. {
  6348. unsigned char buf[26];
  6349. char *p;
  6350. nullpo_retv(sd);
  6351. if(sd->status.partner_id){
  6352. WBUFW(buf,0)=0x1e6;
  6353. p = map_charid2nick(sd->status.partner_id);
  6354. if(p){
  6355. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6356. }else{
  6357. map_reqchariddb(sd,sd->status.partner_id);
  6358. chrif_searchcharid(sd->status.partner_id);
  6359. WBUFB(buf,2) = 0;
  6360. }
  6361. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  6362. }
  6363. return;
  6364. }
  6365. */
  6366. /*==========================================
  6367. * Adopt baby [Celest]
  6368. *------------------------------------------
  6369. */
  6370. void clif_adopt_process(struct map_session_data *sd)
  6371. {
  6372. int fd;
  6373. nullpo_retv(sd);
  6374. fd=sd->fd;
  6375. WFIFOHEAD(fd,packet_len(0x1f8));
  6376. WFIFOW(fd,0)=0x1f8;
  6377. WFIFOSET(fd,packet_len(0x1f8));
  6378. }
  6379. /*==========================================
  6380. * Marry [DracoRPG]
  6381. *------------------------------------------
  6382. */
  6383. void clif_marriage_process(struct map_session_data *sd)
  6384. {
  6385. int fd;
  6386. nullpo_retv(sd);
  6387. fd=sd->fd;
  6388. WFIFOHEAD(fd,packet_len(0x1e4));
  6389. WFIFOW(fd,0)=0x1e4;
  6390. WFIFOSET(fd,packet_len(0x1e4));
  6391. }
  6392. /*==========================================
  6393. * Notice of divorce
  6394. *------------------------------------------
  6395. */
  6396. void clif_divorced(struct map_session_data *sd, char *name)
  6397. {
  6398. int fd;
  6399. nullpo_retv(sd);
  6400. fd=sd->fd;
  6401. WFIFOHEAD(fd,packet_len(0x205));
  6402. WFIFOW(fd,0)=0x205;
  6403. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6404. WFIFOSET(fd, packet_len(0x205));
  6405. }
  6406. /*==========================================
  6407. *
  6408. *------------------------------------------
  6409. */
  6410. void clif_parse_ReqAdopt(int fd, struct map_session_data *sd) {
  6411. nullpo_retv(sd);
  6412. WFIFOHEAD(fd,packet_len(0x1f6));
  6413. WFIFOW(fd,0)=0x1f6;
  6414. WFIFOSET(fd, packet_len(0x1f6));
  6415. }
  6416. /*==========================================
  6417. *
  6418. *------------------------------------------
  6419. */
  6420. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd) {
  6421. nullpo_retv(sd);
  6422. WFIFOHEAD(fd,packet_len(0x1e2));
  6423. WFIFOW(fd,0)=0x1e2;
  6424. WFIFOSET(fd, packet_len(0x1e2));
  6425. }
  6426. /*==========================================
  6427. * 座る
  6428. *------------------------------------------
  6429. */
  6430. void clif_sitting(struct map_session_data *sd)
  6431. {
  6432. unsigned char buf[64];
  6433. nullpo_retv(sd);
  6434. WBUFW(buf, 0) = 0x8a;
  6435. WBUFL(buf, 2) = sd->bl.id;
  6436. WBUFB(buf,26) = 2;
  6437. clif_send(buf, packet_len(0x8a), &sd->bl, AREA);
  6438. }
  6439. /*==========================================
  6440. *
  6441. *------------------------------------------
  6442. */
  6443. int clif_disp_onlyself(struct map_session_data *sd, char *mes, int len)
  6444. {
  6445. int fd;
  6446. nullpo_retr(0, sd);
  6447. fd = sd->fd;
  6448. if (!fd || !len) return 0; //Disconnected player.
  6449. WFIFOHEAD(fd, len+5);
  6450. WFIFOW(fd, 0) = 0x17f;
  6451. WFIFOW(fd, 2) = len + 5;
  6452. memcpy(WFIFOP(fd,4), mes, len);
  6453. WFIFOSET(fd, WFIFOW(fd,2));
  6454. return 1;
  6455. }
  6456. /*==========================================
  6457. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6458. *------------------------------------------
  6459. */
  6460. void clif_disp_message(struct block_list *src, char *mes, int len, int type)
  6461. {
  6462. unsigned char buf[1024];
  6463. if (!len) return;
  6464. WBUFW(buf, 0) = 0x17f;
  6465. WBUFW(buf, 2) = len + 5;
  6466. memcpy(WBUFP(buf,4), mes, len);
  6467. clif_send(buf, WBUFW(buf,2), src, type);
  6468. return;
  6469. }
  6470. /*==========================================
  6471. *
  6472. *------------------------------------------
  6473. */
  6474. int clif_GM_kickack(struct map_session_data *sd, int id)
  6475. {
  6476. int fd;
  6477. nullpo_retr(0, sd);
  6478. fd = sd->fd;
  6479. WFIFOHEAD(fd,packet_len(0xcd));
  6480. WFIFOW(fd,0) = 0xcd;
  6481. WFIFOL(fd,2) = id;
  6482. WFIFOSET(fd, packet_len(0xcd));
  6483. return 0;
  6484. }
  6485. void clif_parse_QuitGame(int fd,struct map_session_data *sd);
  6486. int clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd,int type)
  6487. {
  6488. int fd = tsd->fd;
  6489. WFIFOHEAD(fd,packet_len(0x18b));
  6490. if(type)
  6491. clif_GM_kickack(sd,tsd->status.account_id);
  6492. if (!fd) {
  6493. map_quit(tsd);
  6494. return 0;
  6495. }
  6496. WFIFOW(fd,0) = 0x18b;
  6497. WFIFOW(fd,2) = 0;
  6498. WFIFOSET(fd,packet_len(0x18b));
  6499. clif_setwaitclose(fd);
  6500. return 0;
  6501. }
  6502. int clif_GM_silence(struct map_session_data *sd, struct map_session_data *tsd, int type)
  6503. {
  6504. int fd;
  6505. nullpo_retr(0, sd);
  6506. nullpo_retr(0, tsd);
  6507. fd = tsd->fd;
  6508. if (fd <= 0)
  6509. return 0;
  6510. WFIFOHEAD(fd,packet_len(0x14b));
  6511. WFIFOW(fd,0) = 0x14b;
  6512. WFIFOB(fd,2) = 0;
  6513. memcpy(WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6514. WFIFOSET(fd, packet_len(0x14b));
  6515. return 0;
  6516. }
  6517. /*==========================================
  6518. *
  6519. *------------------------------------------
  6520. */
  6521. int clif_timedout(struct map_session_data *sd)
  6522. {
  6523. nullpo_retr(0, sd);
  6524. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' timed out.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id);
  6525. clif_authfail_fd(sd->fd,3); // Even if player is not on we still send anyway
  6526. clif_setwaitclose(sd->fd); // Set session to EOF
  6527. return 0;
  6528. }
  6529. /*==========================================
  6530. * Wis拒否許可応答
  6531. *------------------------------------------
  6532. */
  6533. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6534. {
  6535. int fd;
  6536. nullpo_retr(0, sd);
  6537. fd=sd->fd;
  6538. WFIFOHEAD(fd,packet_len(0xd1));
  6539. WFIFOW(fd,0)=0xd1;
  6540. WFIFOB(fd,2)=type;
  6541. WFIFOB(fd,3)=flag;
  6542. WFIFOSET(fd,packet_len(0xd1));
  6543. return 0;
  6544. }
  6545. /*==========================================
  6546. * Wis全拒否許可応答
  6547. *------------------------------------------
  6548. */
  6549. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6550. {
  6551. int fd;
  6552. nullpo_retr(0, sd);
  6553. fd=sd->fd;
  6554. WFIFOHEAD(fd,packet_len(0xd2));
  6555. WFIFOW(fd,0)=0xd2;
  6556. WFIFOB(fd,2)=type;
  6557. WFIFOB(fd,3)=flag;
  6558. WFIFOSET(fd,packet_len(0xd2));
  6559. return 0;
  6560. }
  6561. /*==========================================
  6562. * サウンドエフェクト
  6563. *------------------------------------------
  6564. */
  6565. void clif_soundeffect(struct map_session_data *sd,struct block_list *bl,char *name,int type)
  6566. {
  6567. int fd;
  6568. nullpo_retv(sd);
  6569. nullpo_retv(bl);
  6570. fd=sd->fd;
  6571. WFIFOHEAD(fd,packet_len(0x1d3));
  6572. WFIFOW(fd,0)=0x1d3;
  6573. memcpy(WFIFOP(fd,2),name,NAME_LENGTH);
  6574. WFIFOB(fd,26)=type;
  6575. WFIFOL(fd,27)=0;
  6576. WFIFOL(fd,31)=bl->id;
  6577. WFIFOSET(fd,packet_len(0x1d3));
  6578. return;
  6579. }
  6580. int clif_soundeffectall(struct block_list *bl, char *name, int type, int coverage)
  6581. {
  6582. unsigned char buf[40];
  6583. memset(buf, 0, packet_len(0x1d3));
  6584. if(coverage < 0 || coverage > 22){
  6585. ShowError("clif_soundeffectall: undefined coverage.\n");
  6586. return 0;
  6587. }
  6588. nullpo_retr(0, bl);
  6589. WBUFW(buf,0)=0x1d3;
  6590. memcpy(WBUFP(buf,2), name, NAME_LENGTH);
  6591. WBUFB(buf,26)=type;
  6592. WBUFL(buf,27)=0;
  6593. WBUFL(buf,31)=bl->id;
  6594. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6595. return 0;
  6596. }
  6597. // displaying special effects (npcs, weather, etc) [Valaris]
  6598. int clif_specialeffect(struct block_list *bl, int type, int flag)
  6599. {
  6600. unsigned char buf[24];
  6601. nullpo_retr(0, bl);
  6602. memset(buf, 0, packet_len(0x1f3));
  6603. WBUFW(buf,0) = 0x1f3;
  6604. WBUFL(buf,2) = bl->id;
  6605. WBUFL(buf,6) = type;
  6606. clif_send(buf, packet_len(0x1f3), bl, flag);
  6607. if (disguised(bl)) {
  6608. WBUFL(buf,2) = -bl->id;
  6609. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6610. }
  6611. return 0;
  6612. }
  6613. // refresh the client's screen, getting rid of any effects
  6614. int clif_refresh(struct map_session_data *sd) {
  6615. nullpo_retr(-1, sd);
  6616. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6617. clif_inventorylist(sd);
  6618. if(pc_iscarton(sd)){
  6619. clif_cartlist(sd);
  6620. clif_updatestatus(sd,SP_CARTINFO);
  6621. }
  6622. clif_updatestatus(sd,SP_MAXWEIGHT);
  6623. clif_updatestatus(sd,SP_WEIGHT);
  6624. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6625. clif_weather_check(sd);
  6626. return 0;
  6627. }
  6628. // updates the object's (bl) name on client
  6629. int clif_charnameack (int fd, struct block_list *bl)
  6630. {
  6631. unsigned char buf[103];
  6632. int cmd = 0x95;
  6633. nullpo_retr(0, bl);
  6634. WBUFW(buf,0) = cmd;
  6635. WBUFL(buf,2) = bl->id;
  6636. switch(bl->type) {
  6637. case BL_PC:
  6638. {
  6639. struct map_session_data *ssd = (struct map_session_data *)bl;
  6640. struct party_data *p = NULL;
  6641. struct guild *g = NULL;
  6642. //Requesting your own "shadow" name. [Skotlex]
  6643. if (ssd->fd == fd && ssd->disguise)
  6644. WBUFL(buf,2) = -bl->id;
  6645. if (strlen(ssd->fakename)>1) {
  6646. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6647. break;
  6648. }
  6649. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6650. if (ssd->status.party_id > 0)
  6651. p = party_search(ssd->status.party_id);
  6652. if (ssd->status.guild_id > 0)
  6653. g = guild_search(ssd->status.guild_id);
  6654. if (p == NULL && g == NULL)
  6655. break;
  6656. WBUFW(buf, 0) = cmd = 0x195;
  6657. if (p)
  6658. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6659. else
  6660. WBUFB(buf,30) = 0;
  6661. if (g)
  6662. {
  6663. int i, ps = -1;
  6664. for(i = 0; i < g->max_member; i++) {
  6665. if (g->member[i].account_id == ssd->status.account_id &&
  6666. g->member[i].char_id == ssd->status.char_id )
  6667. {
  6668. ps = g->member[i].position;
  6669. break;
  6670. }
  6671. }
  6672. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6673. {
  6674. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6675. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6676. } else { //Assume no guild.
  6677. WBUFB(buf,54) = 0;
  6678. WBUFB(buf,78) = 0;
  6679. }
  6680. } else {
  6681. WBUFB(buf,54) = 0;
  6682. WBUFB(buf,78) = 0;
  6683. }
  6684. }
  6685. break;
  6686. //[blackhole89]
  6687. case BL_HOM:
  6688. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6689. break;
  6690. case BL_PET:
  6691. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6692. break;
  6693. case BL_NPC:
  6694. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6695. break;
  6696. case BL_MOB:
  6697. {
  6698. struct mob_data *md = (struct mob_data *)bl;
  6699. nullpo_retr(0, md);
  6700. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6701. if (md->guardian_data && md->guardian_data->guild_id) {
  6702. WBUFW(buf, 0) = cmd = 0x195;
  6703. WBUFB(buf,30) = 0;
  6704. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6705. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6706. } else if (battle_config.show_mob_info) {
  6707. char mobhp[50], *str_p = mobhp;
  6708. WBUFW(buf, 0) = cmd = 0x195;
  6709. if (battle_config.show_mob_info&4)
  6710. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6711. if (battle_config.show_mob_info&1)
  6712. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6713. if (battle_config.show_mob_info&2)
  6714. str_p += sprintf(str_p, "HP: %d%% | ",
  6715. md->status.max_hp > 10000?
  6716. md->status.hp/(md->status.max_hp/100):
  6717. 100*md->status.hp/md->status.max_hp);
  6718. //Even thought mobhp ain't a name, we send it as one so the client
  6719. //can parse it. [Skotlex]
  6720. if (str_p != mobhp) {
  6721. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6722. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6723. WBUFB(buf,54) = 0;
  6724. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6725. }
  6726. }
  6727. }
  6728. break;
  6729. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6730. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6731. // break;
  6732. return 0;
  6733. default:
  6734. if (battle_config.error_log)
  6735. ShowError("clif_parse_GetCharNameRequest : bad type %d(%d)\n", bl->type, bl->id);
  6736. return 0;
  6737. }
  6738. // if no receipient specified just update nearby clients
  6739. if (fd == 0)
  6740. clif_send(buf, packet_len(cmd), bl, AREA);
  6741. else {
  6742. WFIFOHEAD(fd, packet_len(cmd));
  6743. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  6744. WFIFOSET(fd, packet_len(cmd));
  6745. }
  6746. return 0;
  6747. }
  6748. //Used to update when a char leaves a party/guild. [Skotlex]
  6749. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6750. int clif_charnameupdate (struct map_session_data *ssd)
  6751. {
  6752. unsigned char buf[103];
  6753. int cmd = 0x195;
  6754. struct party_data *p = NULL;
  6755. struct guild *g = NULL;
  6756. nullpo_retr(0, ssd);
  6757. if (strlen(ssd->fakename)>1)
  6758. return 0; //No need to update as the party/guild was not displayed anyway.
  6759. WBUFW(buf,0) = cmd;
  6760. WBUFL(buf,2) = ssd->bl.id;
  6761. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6762. if (ssd->status.party_id > 0)
  6763. p = party_search(ssd->status.party_id);
  6764. if (ssd->status.guild_id > 0)
  6765. g = guild_search(ssd->status.guild_id);
  6766. if (p)
  6767. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6768. else
  6769. WBUFB(buf,30) = 0;
  6770. if (g)
  6771. {
  6772. int i, ps = -1;
  6773. for(i = 0; i < g->max_member; i++) {
  6774. if (g->member[i].account_id == ssd->status.account_id &&
  6775. g->member[i].char_id == ssd->status.char_id )
  6776. {
  6777. ps = g->member[i].position;
  6778. break;
  6779. }
  6780. }
  6781. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6782. {
  6783. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6784. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6785. } else { //Assume no guild.
  6786. WBUFB(buf,54) = 0;
  6787. WBUFB(buf,78) = 0;
  6788. }
  6789. } else {
  6790. WBUFB(buf,54) = 0;
  6791. WBUFB(buf,78) = 0;
  6792. }
  6793. // Update nearby clients
  6794. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  6795. return 0;
  6796. }
  6797. int clif_slide(struct block_list *bl, int x, int y){
  6798. unsigned char buf[10];
  6799. nullpo_retr(0, bl);
  6800. WBUFW(buf, 0) = 0x01ff;
  6801. WBUFL(buf, 2) = bl->id;
  6802. WBUFW(buf, 6) = x;
  6803. WBUFW(buf, 8) = y;
  6804. clif_send(buf, packet_len(0x1ff), bl, AREA);
  6805. return 0;
  6806. }
  6807. /*------------------------------------------
  6808. * @me command by lordalfa, rewritten implementation by Skotlex
  6809. *------------------------------------------
  6810. */
  6811. int clif_disp_overhead(struct map_session_data *sd, char* mes)
  6812. {
  6813. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  6814. int len_mes = strlen(mes)+1; //Account for \0
  6815. if (len_mes + 8 >= 256) {
  6816. if (battle_config.error_log)
  6817. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6818. len_mes = 247; //Trunk it to avoid problems.
  6819. }
  6820. // send message to others
  6821. WBUFW(buf,0) = 0x8d;
  6822. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6823. WBUFL(buf,4) = sd->bl.id;
  6824. memcpy(WBUFP(buf,8), mes, len_mes);
  6825. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6826. // send back message to the speaker
  6827. WBUFW(buf,0) = 0x8e;
  6828. WBUFW(buf, 2) = len_mes + 4;
  6829. memcpy(WBUFP(buf,4), mes, len_mes);
  6830. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6831. return 0;
  6832. }
  6833. /*==========================
  6834. * Minimap fix [Kevin]
  6835. * Remove dot from minimap
  6836. *--------------------------
  6837. */
  6838. int clif_party_xy_remove(struct map_session_data *sd)
  6839. {
  6840. unsigned char buf[16];
  6841. nullpo_retr(0, sd);
  6842. WBUFW(buf,0)=0x107;
  6843. WBUFL(buf,2)=sd->status.account_id;
  6844. WBUFW(buf,6)=-1;
  6845. WBUFW(buf,8)=-1;
  6846. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6847. return 0;
  6848. }
  6849. //Displays gospel-buff information (thanks to Rayce):
  6850. //Type determines message based on this table:
  6851. /*
  6852. 0x15 End all negative status
  6853. 0x16 Immunity to all status
  6854. 0x17 MaxHP +100%
  6855. 0x18 MaxSP +100%
  6856. 0x19 All stats +20
  6857. 0x1c Enchant weapon with Holy element
  6858. 0x1d Enchant armor with Holy element
  6859. 0x1e DEF +25%
  6860. 0x1f ATK +100%
  6861. 0x20 HIT/Flee +50
  6862. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  6863. */
  6864. void clif_gospel_info(struct map_session_data *sd, int type)
  6865. {
  6866. int fd=sd->fd;
  6867. WFIFOHEAD(fd,packet_len(0x215));
  6868. WFIFOW(fd,0)=0x215;
  6869. WFIFOL(fd,2)=type;
  6870. WFIFOSET(fd, packet_len(0x215));
  6871. }
  6872. /*==========================================
  6873. * Info about Star Glaldiator save map [Komurka]
  6874. * type: 1: Information, 0: Map registered
  6875. *------------------------------------------
  6876. */
  6877. void clif_feel_info(struct map_session_data *sd, unsigned char feel_level, unsigned char type)
  6878. {
  6879. int fd=sd->fd;
  6880. WFIFOHEAD(fd,packet_len(0x20e));
  6881. WFIFOW(fd,0)=0x20e;
  6882. memcpy(WFIFOP(fd,2),mapindex_id2name(sd->feel_map[feel_level].index), MAP_NAME_LENGTH);
  6883. WFIFOL(fd,26)=sd->bl.id;
  6884. WFIFOB(fd,30)=feel_level;
  6885. WFIFOB(fd,31)=type?1:0;
  6886. WFIFOSET(fd, packet_len(0x20e));
  6887. }
  6888. /*==========================================
  6889. * Info about Star Glaldiator hate mob [Komurka]
  6890. * type: 1: Register mob, 0: Information.
  6891. *------------------------------------------
  6892. */
  6893. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  6894. {
  6895. int fd=sd->fd;
  6896. WFIFOHEAD(fd,packet_len(0x20e));
  6897. WFIFOW(fd,0)=0x20e;
  6898. if (pcdb_checkid(class_))
  6899. strncpy(WFIFOP(fd,2),job_name(class_), NAME_LENGTH);
  6900. else if (mobdb_checkid(class_))
  6901. strncpy(WFIFOP(fd,2),mob_db(class_)->jname, NAME_LENGTH);
  6902. else //Really shouldn't happen...
  6903. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  6904. WFIFOL(fd,26)=sd->bl.id;
  6905. WFIFOB(fd,30)=hate_level;
  6906. WFIFOB(fd,31)=type?10:11; //Register/Info
  6907. WFIFOSET(fd, packet_len(0x20e));
  6908. }
  6909. /*==========================================
  6910. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6911. *------------------------------------------
  6912. */
  6913. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  6914. {
  6915. int fd=sd->fd;
  6916. WFIFOHEAD(fd,packet_len(0x20e));
  6917. WFIFOW(fd,0)=0x20e;
  6918. strncpy(WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6919. WFIFOL(fd,26)=mob_id;
  6920. WFIFOB(fd,30)=progress; //Message to display
  6921. WFIFOB(fd,31)=20;
  6922. WFIFOSET(fd, packet_len(0x20e));
  6923. }
  6924. /*==========================================
  6925. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  6926. *------------------------------------------
  6927. */
  6928. void clif_feel_hate_reset(struct map_session_data *sd)
  6929. {
  6930. int fd=sd->fd;
  6931. WFIFOHEAD(fd,packet_len(0x20e));
  6932. WFIFOW(fd,0)=0x20e;
  6933. memset(WFIFOP(fd,2), 0, NAME_LENGTH); //Blank name as all was reset.
  6934. WFIFOL(fd,26)=sd->bl.id;
  6935. WFIFOB(fd,30)=0; //Feel/hate level: irrelevant
  6936. WFIFOB(fd,31)=30;
  6937. WFIFOSET(fd, packet_len(0x20e));
  6938. }
  6939. // ---------------------
  6940. // clif_guess_PacketVer
  6941. // ---------------------
  6942. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  6943. // error codes:
  6944. // 0 - Success
  6945. // 1 - Unknown packet_ver
  6946. // 2 - Invalid account_id
  6947. // 3 - Invalid char_id
  6948. // 4 - Invalid login_id1 (reserved)
  6949. // 5 - Invalid client_tick (reserved)
  6950. // 6 - Invalid sex
  6951. // Only the first 'invalid' error that appears is used.
  6952. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  6953. {
  6954. static int err = 1;
  6955. static int packet_ver = -1;
  6956. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  6957. RFIFOHEAD(fd);
  6958. if (get_previous)
  6959. {//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]
  6960. if( error )
  6961. *error = err;
  6962. return packet_ver;
  6963. }
  6964. //By default, start searching on the default one.
  6965. err = 1;
  6966. packet_ver = clif_config.packet_db_ver;
  6967. cmd = RFIFOW(fd,0);
  6968. packet_len = RFIFOREST(fd);
  6969. #define SET_ERROR(n) \
  6970. if( err == 1 )\
  6971. err = n;\
  6972. //define SET_ERROR
  6973. #define CHECK_PACKET_VER() \
  6974. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  6975. ;/* not wanttoconnection or wrong length */\
  6976. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > max_account_id )\
  6977. { SET_ERROR(2); }/* invalid account_id */\
  6978. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 || value > max_char_id )\
  6979. { SET_ERROR(3); }/* invalid char_id */\
  6980. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  6981. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  6982. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  6983. { SET_ERROR(6); }/* invalid sex */\
  6984. else\
  6985. {\
  6986. err = 0;\
  6987. if( error )\
  6988. *error = 0;\
  6989. return packet_ver;\
  6990. }\
  6991. //define CHECK_PACKET_VER
  6992. CHECK_PACKET_VER();//Default packet version found.
  6993. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  6994. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  6995. CHECK_PACKET_VER();
  6996. }
  6997. if( error )
  6998. *error = err;
  6999. packet_ver = -1;
  7000. return -1;
  7001. #undef SET_ERROR
  7002. #undef CHECK_PACKET_VER
  7003. }
  7004. // ------------
  7005. // clif_parse_*
  7006. // ------------
  7007. // パケット読み取って色々操作
  7008. /*==========================================
  7009. *
  7010. *------------------------------------------
  7011. */
  7012. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  7013. {
  7014. int cmd, account_id, char_id, login_id1, sex;
  7015. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  7016. 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])
  7017. RFIFOHEAD(fd);
  7018. if (sd) {
  7019. if (battle_config.error_log)
  7020. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)?\n");
  7021. return;
  7022. }
  7023. // Only valid packet version get here
  7024. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  7025. cmd = RFIFOW(fd,0);
  7026. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7027. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7028. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7029. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7030. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7031. if( packet_ver < 5 || // reject really old client versions
  7032. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  7033. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  7034. {// packet version rejected
  7035. WFIFOHEAD(fd,packet_len(0x6a));
  7036. WFIFOW(fd,0) = 0x6a;
  7037. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  7038. WFIFOSET(fd,packet_len(0x6a));
  7039. clif_setwaitclose(fd);
  7040. return;
  7041. } else
  7042. {// packet version accepted
  7043. TBL_PC* old_sd;
  7044. struct block_list* bl;
  7045. if( (bl=map_id2bl(account_id)) != NULL && bl->type != BL_PC )
  7046. {// non-player object already has that id
  7047. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  7048. WFIFOHEAD(fd,packet_len(0x6a));
  7049. WFIFOW(fd,0) = 0x6a;
  7050. WFIFOB(fd,2) = 3; // Rejected by server
  7051. WFIFOSET(fd,packet_len(0x6a));
  7052. clif_setwaitclose(fd);
  7053. return;
  7054. }
  7055. if( (old_sd=map_id2sd(account_id)) != NULL ){
  7056. // if same account already connected, we disconnect the 2 sessions
  7057. //Check for characters with no connection (includes those that are using autotrade) [durf],[Skotlex]
  7058. if (old_sd->state.finalsave || !old_sd->state.auth)
  7059. ; //Previous player is not done loading.
  7060. //Or he has quit, but is not done saving on the charserver.
  7061. else if (old_sd->fd)
  7062. clif_authfail_fd(old_sd->fd, 2); // same id
  7063. else
  7064. map_quit(old_sd);
  7065. clif_authfail_fd(fd, 8); // still recognizes last connection
  7066. return;
  7067. }
  7068. }
  7069. CREATE(sd, TBL_PC, 1);
  7070. sd->fd = fd;
  7071. sd->packet_ver = packet_ver;
  7072. session[fd]->session_data = sd;
  7073. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7074. WFIFOHEAD(fd,4);
  7075. WFIFOL(fd,0) = sd->bl.id;
  7076. WFIFOSET(fd,4);
  7077. chrif_authreq(sd);
  7078. return;
  7079. }
  7080. /*==========================================
  7081. * 007d クライアント側マップ読み込み完了
  7082. * map侵入時に必要なデータを全て送りつける
  7083. *------------------------------------------
  7084. */
  7085. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7086. {
  7087. if(sd->bl.prev != NULL)
  7088. return;
  7089. if (!sd->state.auth)
  7090. { //Character loading is not complete yet!
  7091. //Let pc_reg_received reinvoke this when ready.
  7092. sd->state.connect_new = 0;
  7093. return;
  7094. }
  7095. if (sd->state.rewarp)
  7096. { //Rewarp player.
  7097. sd->state.rewarp = 0;
  7098. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  7099. return;
  7100. }
  7101. // look
  7102. #if PACKETVER < 4
  7103. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7104. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7105. #else
  7106. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7107. #endif
  7108. if(sd->vd.cloth_color)
  7109. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7110. // item
  7111. pc_checkitem(sd);
  7112. clif_inventorylist(sd);
  7113. // cart
  7114. if(pc_iscarton(sd)){
  7115. clif_cartlist(sd);
  7116. clif_updatestatus(sd,SP_CARTINFO);
  7117. }
  7118. // weight max , now
  7119. clif_updatestatus(sd,SP_MAXWEIGHT);
  7120. clif_updatestatus(sd,SP_WEIGHT);
  7121. if(battle_config.pc_invincible_time > 0) {
  7122. if(map_flag_gvg(sd->bl.m))
  7123. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7124. else
  7125. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7126. }
  7127. map_addblock(&sd->bl); // ブロック登録
  7128. clif_spawn(&sd->bl); // spawn
  7129. // Party
  7130. if(sd->status.party_id) {
  7131. party_send_movemap(sd);
  7132. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  7133. }
  7134. // guild
  7135. if(sd->status.guild_id)
  7136. guild_send_memberinfoshort(sd,1);
  7137. if(map[sd->bl.m].flag.pvp){
  7138. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7139. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  7140. sd->pvp_timer= add_timer(gettick()+200,
  7141. pc_calc_pvprank_timer,sd->bl.id,0);
  7142. sd->pvp_rank=0;
  7143. sd->pvp_lastusers=0;
  7144. sd->pvp_point=5;
  7145. sd->pvp_won=0;
  7146. sd->pvp_lost=0;
  7147. }
  7148. clif_set0199(fd,1);
  7149. } else
  7150. // set flag, if it's a duel [LuzZza]
  7151. if(sd->duel_group)
  7152. clif_set0199(fd, 1);
  7153. if (map[sd->bl.m].flag.gvg_dungeon)
  7154. {
  7155. clif_set0199(fd, 1); //TODO: Figure out the real packet to send here.
  7156. if (!sd->pvp_point)
  7157. {
  7158. sd->pvp_point=5; //Need to die twice to be warped out.
  7159. sd->pvp_won=0;
  7160. sd->pvp_lost=0;
  7161. }
  7162. }
  7163. if(map_flag_gvg(sd->bl.m))
  7164. clif_set0199(fd,3);
  7165. // pet
  7166. if(sd->pd) {
  7167. map_addblock(&sd->pd->bl);
  7168. clif_spawn(&sd->pd->bl);
  7169. clif_send_petdata(sd,0,0);
  7170. clif_send_petdata(sd,5,battle_config.pet_hair_style);
  7171. clif_send_petstatus(sd);
  7172. // skill_unit_move(&sd->pd->bl,gettick(),1);
  7173. }
  7174. //homunculus [blackhole89]
  7175. if(merc_is_hom_active(sd->hd)) {
  7176. map_addblock(&sd->hd->bl);
  7177. clif_spawn(&sd->hd->bl);
  7178. clif_hominfo(sd,sd->hd,1);
  7179. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  7180. clif_send_homdata(sd,0,0);
  7181. clif_homskillinfoblock(sd);
  7182. //Homunc mimic their master's speed on each map change. [Skotlex]
  7183. if (battle_config.hom_setting&0x8)
  7184. status_calc_bl(&sd->hd->bl, SCB_SPEED);
  7185. if (!(battle_config.hom_setting&0x2))
  7186. skill_unit_move(&sd->hd->bl,gettick(),1);
  7187. }
  7188. if(sd->state.connect_new) {
  7189. int lv;
  7190. sd->state.connect_new = 0;
  7191. clif_skillinfoblock(sd);
  7192. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7193. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7194. clif_updatestatus(sd,SP_SKILLPOINT);
  7195. clif_initialstatus(sd);
  7196. if (sd->sc.option&OPTION_FALCON)
  7197. clif_status_load(&sd->bl, SI_FALCON, 1);
  7198. if (sd->sc.option&OPTION_RIDING)
  7199. clif_status_load(&sd->bl, SI_RIDING, 1);
  7200. if(sd->status.manner < 0)
  7201. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7202. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7203. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7204. if(sd->bl.m == sd->feel_map[0].m
  7205. || sd->bl.m == sd->feel_map[1].m
  7206. || sd->bl.m == sd->feel_map[2].m)
  7207. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7208. }
  7209. if(sd->pd && sd->pd->pet.intimate > 900)
  7210. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7211. if(merc_is_hom_active(sd->hd))
  7212. merc_hom_init_timers(sd->hd);
  7213. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7214. {
  7215. sd->state.night = 1;
  7216. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7217. }
  7218. // Notify everyone that this char logged in [Skotlex].
  7219. clif_foreachclient(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  7220. //Login Event
  7221. npc_script_event(sd, NPCE_LOGIN);
  7222. } else {
  7223. //For some reason the client "loses" these on map-change.
  7224. clif_updatestatus(sd,SP_STR);
  7225. clif_updatestatus(sd,SP_AGI);
  7226. clif_updatestatus(sd,SP_VIT);
  7227. clif_updatestatus(sd,SP_INT);
  7228. clif_updatestatus(sd,SP_DEX);
  7229. clif_updatestatus(sd,SP_LUK);
  7230. sd->state.using_fake_npc = 0;
  7231. //New 'night' effect by dynamix [Skotlex]
  7232. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7233. { //Display night.
  7234. if (!sd->state.night) {
  7235. sd->state.night = 1;
  7236. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7237. }
  7238. } else if (sd->state.night) { //Clear night display.
  7239. sd->state.night = 0;
  7240. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7241. }
  7242. if(sd->npc_id)
  7243. npc_event_dequeue(sd);
  7244. }
  7245. // Lance
  7246. if(sd->state.event_loadmap && map[sd->bl.m].flag.loadevent){
  7247. pc_setregstr(sd, add_str("@maploaded$"), map[sd->bl.m].name);
  7248. npc_script_event(sd, NPCE_LOADMAP);
  7249. }
  7250. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7251. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7252. clif_weather_check(sd);
  7253. map_foreachinarea(clif_getareachar,sd->bl.m,
  7254. sd->bl.x-AREA_SIZE,sd->bl.y-AREA_SIZE,sd->bl.x+AREA_SIZE,sd->bl.y+AREA_SIZE,
  7255. BL_ALL,sd);
  7256. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7257. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7258. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7259. else
  7260. sd->areanpc_id = 0;
  7261. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  7262. if(pc_isdead(sd))
  7263. clif_clearchar_area(&sd->bl,1);
  7264. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  7265. // else
  7266. // clif_changed_dir(&sd->bl, SELF);
  7267. // Trigger skill effects if you appear standing on them
  7268. if(!battle_config.pc_invincible_time)
  7269. skill_unit_move(&sd->bl,gettick(),1);
  7270. }
  7271. /*==========================================
  7272. *
  7273. *------------------------------------------
  7274. */
  7275. void clif_parse_TickSend(int fd, struct map_session_data *sd) {
  7276. RFIFOHEAD(fd);
  7277. sd->client_tick=RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7278. WFIFOHEAD(fd, packet_len(0x7f));
  7279. WFIFOW(fd,0)=0x7f;
  7280. WFIFOL(fd,2)=gettick();
  7281. WFIFOSET(fd,packet_len(0x7f));
  7282. // removed until the socket problems are fixed. [FlavioJS]
  7283. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  7284. return;
  7285. }
  7286. /*==========================================
  7287. *
  7288. *------------------------------------------
  7289. */
  7290. void clif_parse_WalkToXY(int fd, struct map_session_data *sd) {
  7291. int x, y;
  7292. int cmd;
  7293. RFIFOHEAD(fd);
  7294. if (pc_isdead(sd)) {
  7295. clif_clearchar_area(&sd->bl, 1);
  7296. return;
  7297. }
  7298. if (sd->sc.opt1 && sd->sc.opt1 == OPT1_STONEWAIT)
  7299. ; //You CAN walk on this OPT1 value.
  7300. else if (clif_cant_act(sd))
  7301. return;
  7302. if(sd->sc.count && sd->sc.data[SC_RUN].timer != -1)
  7303. return;
  7304. pc_stop_attack(sd);
  7305. pc_delinvincibletimer(sd);
  7306. cmd = RFIFOW(fd,0);
  7307. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7308. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7309. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7310. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7311. //Set last idle time... [Skotlex]
  7312. sd->idletime = last_tick;
  7313. unit_walktoxy(&sd->bl, x, y, 4);
  7314. }
  7315. /*==========================================
  7316. *
  7317. *------------------------------------------
  7318. */
  7319. void clif_parse_QuitGame(int fd, struct map_session_data *sd) {
  7320. WFIFOHEAD(fd,packet_len(0x18b));
  7321. WFIFOW(fd,0) = 0x18b;
  7322. /* Rovert's prevent logout option fixed [Valaris] */
  7323. if (sd->sc.data[SC_CLOAKING].timer==-1 && sd->sc.data[SC_HIDING].timer==-1 &&
  7324. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7325. ) {
  7326. clif_setwaitclose(fd);
  7327. WFIFOW(fd,2)=0;
  7328. } else {
  7329. WFIFOW(fd,2)=1;
  7330. }
  7331. WFIFOSET(fd,packet_len(0x18b));
  7332. }
  7333. /*==========================================
  7334. *
  7335. *------------------------------------------
  7336. */
  7337. void check_fake_id(int fd, struct map_session_data *sd, int target_id) {
  7338. // if player asks for the fake player (only bot and modified client can see a hiden player)
  7339. /* if (target_id == server_char_id) {
  7340. char message_to_gm[strlen(msg_txt(536)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7341. 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).
  7342. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7343. // if we block people
  7344. if (battle_config.ban_bot < 0) {
  7345. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7346. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7347. // message about the ban
  7348. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7349. // if we ban people
  7350. } else if (battle_config.ban_bot > 0) {
  7351. 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)
  7352. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7353. // message about the ban
  7354. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7355. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7356. // message about the ban
  7357. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7358. }
  7359. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7360. // send this info cause the bot ask until get an answer, damn spam
  7361. memset(WPACKETP(0), 0, packet_len(0x95));
  7362. WPACKETW(0) = 0x95;
  7363. WPACKETL(2) = server_char_id;
  7364. strncpy(WPACKETP(6), sd->status.name, 24);
  7365. SENDPACKET(fd, packet_len(0x95));
  7366. // take fake player out of screen
  7367. WPACKETW(0) = 0x80;
  7368. WPACKETL(2) = server_char_id;
  7369. WPACKETB(6) = 0;
  7370. SENDPACKET(fd, packet_len(0x80));
  7371. // take fake mob out of screen
  7372. WPACKETW(0) = 0x80;
  7373. WPACKETL(2) = server_fake_mob_id;
  7374. WPACKETB(6) = 0;
  7375. SENDPACKET(fd, packet_len(0x80));
  7376. }
  7377. // if player asks for the fake mob (only bot and modified client can see a hiden mob)
  7378. if (target_id == server_fake_mob_id) {
  7379. int fake_mob;
  7380. char message_to_gm[strlen(msg_txt(537)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7381. 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).
  7382. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7383. // if we block people
  7384. if (battle_config.ban_bot < 0) {
  7385. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7386. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7387. // message about the ban
  7388. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7389. // if we ban people
  7390. } else if (battle_config.ban_bot > 0) {
  7391. 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)
  7392. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7393. // message about the ban
  7394. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7395. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7396. // message about the ban
  7397. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7398. }
  7399. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7400. // send this info cause the bot ask until get an answer, damn spam
  7401. memset(WPACKETP(0), 0, packet_len(0x95));
  7402. WPACKETW(0) = 0x95;
  7403. WPACKETL(2) = server_fake_mob_id;
  7404. 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
  7405. if (!mobdb_checkid(fake_mob))
  7406. fake_mob = 1002; // poring (default)
  7407. strncpy(WPACKETP(6), mob_db[fake_mob].name, 24);
  7408. SENDPACKET(fd, packet_len(0x95));
  7409. // take fake mob out of screen
  7410. WPACKETW(0) = 0x80;
  7411. WPACKETL(2) = server_fake_mob_id;
  7412. WPACKETB(6) = 0;
  7413. SENDPACKET(fd, packet_len(0x80));
  7414. // take fake player out of screen
  7415. WPACKETW(0) = 0x80;
  7416. WPACKETL(2) = server_char_id;
  7417. WPACKETB(6) = 0;
  7418. SENDPACKET(fd, packet_len(0x80));
  7419. }
  7420. */
  7421. return;
  7422. }
  7423. /*==========================================
  7424. *
  7425. *------------------------------------------
  7426. */
  7427. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) {
  7428. int account_id;
  7429. struct block_list* bl;
  7430. struct status_change *sc;
  7431. RFIFOHEAD(fd);
  7432. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7433. if(account_id<0 && -account_id == sd->bl.id) // for disguises [Valaris]
  7434. account_id= sd->bl.id;
  7435. bl = map_id2bl(account_id);
  7436. //Is this possible? Lagged clients could request names of already gone mobs/players. [Skotlex]
  7437. if (!bl) return;
  7438. sc = status_get_sc(bl);
  7439. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) && pc_isGM(sd) < battle_config.hack_info_GM_level)
  7440. {
  7441. //GM characters (with client side GM enabled are able to see invisible stuff) [Lance]
  7442. //Asked name of invisible player, this shouldn't be possible!
  7443. //Possible bot? Thanks to veider and qspirit
  7444. //FIXME: Still isn't perfected as clients keep asking for this on legitimate situations.
  7445. unsigned char gm_msg[256];
  7446. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requests name of invisible chars.", sd->status.name, sd->status.account_id);
  7447. ShowWarning(gm_msg);
  7448. // information is sended to all online GM
  7449. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7450. return;
  7451. }
  7452. clif_charnameack(fd, bl);
  7453. }
  7454. /*==========================================
  7455. * Validates and processes global messages
  7456. * S 008c/00f3 <packet len>.w <strz>.?B
  7457. *------------------------------------------*/
  7458. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  7459. {
  7460. char* message;
  7461. unsigned int packetlen, messagelen, namelen;
  7462. RFIFOHEAD(fd);
  7463. packetlen = RFIFOW(fd,2);
  7464. if (packetlen > RFIFOREST(fd)) { // there has to be enough data to read
  7465. ShowWarning("clif_parse_GlobalMessage: Received malformed packet from player '%s' (length is incorrect)!", sd->status.name);
  7466. return;
  7467. }
  7468. if (packetlen < 4 + 1) { // 4-byte header and at least an empty string is expected
  7469. ShowWarning("clif_parse_GlobalMessage: Received malformed packet from player '%s' (no message data)!", sd->status.name);
  7470. return;
  7471. }
  7472. message = (char*)RFIFOP(fd,4);
  7473. messagelen = packetlen - 4; // let's trust the client here, nothing can go wrong and it saves us one strlen()
  7474. if (messagelen > CHAT_SIZE) { // messages mustn't be too long
  7475. int i;
  7476. // special case here - allow some more freedom for frost joke & dazzler
  7477. // TODO:? You could use a state flag when FrostJoke/Scream is used, and unset it once the skill triggers. [Skotlex]
  7478. for(i = 0; i < MAX_SKILLTIMERSKILL && sd->ud.skilltimerskill[i] &&
  7479. sd->ud.skilltimerskill[i]->skill_id != BA_FROSTJOKE &&
  7480. sd->ud.skilltimerskill[i]->skill_id != DC_SCREAM; i++);
  7481. if (i == MAX_SKILLTIMERSKILL || !sd->ud.skilltimerskill[i]) { // normal message, too long
  7482. ShowWarning("clif_parse_GlobalMessage: Player '%s' sent a message too long ('%.*s')!", sd->status.name, CHAT_SIZE, message);
  7483. return;
  7484. }
  7485. if (messagelen > 255) { // frost joke/dazzler, but still too long
  7486. ShowWarning("clif_parse_GlobalMessage: Player '%s' sent a message too long ('%.*s')!", sd->status.name, 255, message);
  7487. return;
  7488. }
  7489. }
  7490. if (message[messagelen-1] != '\0') { // message must be zero-terminated
  7491. ShowWarning("clif_parse_GlobalMessage: Player '%s' sent an unterminated string!", sd->status.name);
  7492. return;
  7493. }
  7494. namelen = strnlen(sd->status.name, NAME_LENGTH - 1);
  7495. if (strncmp(message, sd->status.name, namelen) || // the name has to match the speaker's name
  7496. message[namelen] != ' ' || message[namelen+1] != ':' || message[namelen+2] != ' ') // completely, not just the prefix
  7497. {
  7498. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  7499. clif_setwaitclose(fd); // Just kick them out to correct it.
  7500. ShowWarning("clif_parse_GlobalMessage: Player '%.*s' sent a messsage using an incorrect name ('%s')! Forcing a relog...", namelen, sd->status.name, message);
  7501. return;
  7502. }
  7503. if (is_atcommand(fd, sd, message) != AtCommand_None ||
  7504. is_charcommand(fd, sd, message) != CharCommand_None)
  7505. return;
  7506. if (sd->sc.count &&
  7507. (sd->sc.data[SC_BERSERK].timer != -1 ||
  7508. (sd->sc.data[SC_NOCHAT].timer != -1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)))
  7509. return;
  7510. if (battle_config.min_chat_delay)
  7511. { //[Skotlex]
  7512. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7513. return;
  7514. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7515. }
  7516. // send message to others
  7517. WFIFOHEAD(fd, messagelen + 8);
  7518. WFIFOW(fd,0) = 0x8d;
  7519. WFIFOW(fd,2) = messagelen + 8;
  7520. WFIFOL(fd,4) = sd->bl.id;
  7521. memcpy(WFIFOP(fd,8), message, messagelen);
  7522. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7523. // send back message to the speaker
  7524. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), packetlen);
  7525. WFIFOW(fd,0) = 0x8e;
  7526. WFIFOSET(fd, WFIFOW(fd,2));
  7527. #ifdef PCRE_SUPPORT
  7528. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, message, strlen(message), &sd->bl);
  7529. map_foreachinrange(mob_chat_sub, &sd->bl, AREA_SIZE, BL_MOB, message, strlen(message), &sd->bl);
  7530. #endif
  7531. // Celest
  7532. if ((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE) { //Super Novice.
  7533. char buf[256];
  7534. int next = pc_nextbaseexp(sd);
  7535. if (next > 0 && (sd->status.base_exp * 1000 / next)% 100 == 0) {
  7536. switch (sd->state.snovice_call_flag) {
  7537. case 0:
  7538. if (strstr(message, msg_txt(504)))
  7539. sd->state.snovice_call_flag++;
  7540. break;
  7541. case 1:
  7542. sprintf(buf, msg_txt(505), sd->status.name);
  7543. if (strstr(message, buf))
  7544. sd->state.snovice_call_flag++;
  7545. break;
  7546. case 2:
  7547. if (strstr(message, msg_txt(506)))
  7548. sd->state.snovice_call_flag++;
  7549. break;
  7550. case 3:
  7551. if (skillnotok(MO_EXPLOSIONSPIRITS,sd))
  7552. break; //Do not override the noskill mapflag. [Skotlex]
  7553. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7554. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  7555. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7556. sd->state.snovice_call_flag= 0;
  7557. break;
  7558. }
  7559. }
  7560. }
  7561. return;
  7562. }
  7563. int clif_message(struct block_list *bl, char* msg)
  7564. {
  7565. unsigned short msg_len = strlen(msg) + 1;
  7566. unsigned char buf[256];
  7567. nullpo_retr(0, bl);
  7568. WBUFW(buf, 0) = 0x8d;
  7569. WBUFW(buf, 2) = msg_len + 8;
  7570. WBUFL(buf, 4) = bl->id;
  7571. memcpy(WBUFP(buf, 8), msg, msg_len);
  7572. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC); // by Gengar
  7573. return 0;
  7574. }
  7575. /*==========================================
  7576. *
  7577. *------------------------------------------
  7578. */
  7579. void clif_parse_MapMove(int fd, struct map_session_data *sd) {
  7580. // /m /mapmove (as @rura GM command)
  7581. char output[MAP_NAME_LENGTH+15]; // Max length of a short: ' -6XXXX' -> 7 digits
  7582. char message[MAP_NAME_LENGTH+15+5]; // "/mm "+output
  7583. char *map_name;
  7584. RFIFOHEAD(fd);
  7585. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7586. return;
  7587. if(pc_isGM(sd) < get_atcommand_level(AtCommand_MapMove))
  7588. return;
  7589. map_name = RFIFOP(fd,2);
  7590. map_name[MAP_NAME_LENGTH-1]='\0';
  7591. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7592. atcommand_rura(fd, sd, "@rura", output);
  7593. if(log_config.gm && get_atcommand_level(AtCommand_MapMove) >= log_config.gm)
  7594. {
  7595. sprintf(message, "/mm %s", output);
  7596. log_atcommand(sd, message);
  7597. }
  7598. return;
  7599. }
  7600. /*==========================================
  7601. *
  7602. *------------------------------------------
  7603. */
  7604. void clif_changed_dir(struct block_list *bl, int type) {
  7605. unsigned char buf[64];
  7606. WBUFW(buf,0) = 0x9c;
  7607. WBUFL(buf,2) = bl->id;
  7608. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7609. WBUFB(buf,8) = unit_getdir(bl);
  7610. clif_send(buf, packet_len(0x9c), bl, type);
  7611. if (disguised(bl)) {
  7612. WBUFL(buf,2) = -bl->id;
  7613. WBUFW(buf,6) = 0;
  7614. clif_send(buf, packet_len(0x9c), bl, SELF);
  7615. }
  7616. return;
  7617. }
  7618. /*==========================================
  7619. *
  7620. *------------------------------------------
  7621. */
  7622. void clif_parse_ChangeDir(int fd, struct map_session_data *sd) {
  7623. unsigned char headdir, dir;
  7624. RFIFOHEAD(fd);
  7625. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7626. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7627. pc_setdir(sd, dir, headdir);
  7628. clif_changed_dir(&sd->bl, AREA_WOS);
  7629. return;
  7630. }
  7631. /*==========================================
  7632. *
  7633. *------------------------------------------
  7634. */
  7635. void clif_parse_Emotion(int fd, struct map_session_data *sd) {
  7636. unsigned char buf[64];
  7637. RFIFOHEAD(fd);
  7638. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7639. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7640. clif_skill_fail(sd, 1, 0, 1);
  7641. return;
  7642. }
  7643. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7644. if (sd->emotionlasttime >= time(NULL)) {
  7645. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7646. clif_skill_fail(sd, 1, 0, 1);
  7647. return;
  7648. }
  7649. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7650. WBUFW(buf,0) = 0xc0;
  7651. WBUFL(buf,2) = sd->bl.id;
  7652. WBUFB(buf,6) = RFIFOB(fd,2);
  7653. clif_send(buf, packet_len(0xc0), &sd->bl, AREA);
  7654. } else
  7655. clif_skill_fail(sd, 1, 0, 1);
  7656. }
  7657. /*==========================================
  7658. *
  7659. *------------------------------------------
  7660. */
  7661. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd) {
  7662. WFIFOHEAD(fd,packet_len(0xc2));
  7663. WFIFOW(fd,0) = 0xc2;
  7664. WFIFOL(fd,2) = map_getusers();
  7665. WFIFOSET(fd,packet_len(0xc2));
  7666. }
  7667. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7668. {
  7669. unsigned char buf[64];
  7670. if (pc_isdead(sd)) {
  7671. clif_clearchar_area(&sd->bl, 1);
  7672. return;
  7673. }
  7674. if (sd->sc.count &&
  7675. (sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  7676. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  7677. sd->sc.data[SC_BLADESTOP].timer != -1))
  7678. return;
  7679. pc_stop_walking(sd, 1);
  7680. pc_stop_attack(sd);
  7681. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7682. target_id = sd->bl.id;
  7683. switch(action_type) {
  7684. case 0x00: // once attack
  7685. case 0x07: // continuous attack
  7686. if (clif_cant_act(sd) || sd->sc.option&OPTION_HIDE)
  7687. return;
  7688. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  7689. return;
  7690. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7691. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7692. clif_skill_fail(sd, 1, 4, 0);
  7693. return;
  7694. }
  7695. }
  7696. pc_delinvincibletimer(sd);
  7697. sd->idletime = last_tick;
  7698. unit_attack(&sd->bl, target_id, action_type != 0);
  7699. break;
  7700. case 0x02: // sitdown
  7701. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7702. clif_skill_fail(sd, 1, 0, 2);
  7703. break;
  7704. }
  7705. if(pc_issit(sd)) {
  7706. //Bugged client? Just refresh them.
  7707. WBUFW(buf, 0) = 0x8a;
  7708. WBUFL(buf, 2) = sd->bl.id;
  7709. WBUFB(buf,26) = 2;
  7710. clif_send(buf, packet_len(0x8a), &sd->bl, SELF);
  7711. return;
  7712. }
  7713. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7714. break;
  7715. if (sd->sc.count && (
  7716. sd->sc.data[SC_DANCING].timer != -1 ||
  7717. (sd->sc.data[SC_GRAVITATION].timer != -1 && sd->sc.data[SC_GRAVITATION].val3 == BCT_SELF)
  7718. )) //No sitting during these states neither.
  7719. break;
  7720. pc_setsit(sd);
  7721. skill_sit(sd, 1);
  7722. clif_sitting(sd);
  7723. break;
  7724. case 0x03: // standup
  7725. if (!pc_issit(sd)) {
  7726. //Bugged client? Just refresh them.
  7727. WBUFW(buf, 0) = 0x8a;
  7728. WBUFL(buf, 2) = sd->bl.id;
  7729. WBUFB(buf,26) = 3;
  7730. clif_send(buf, packet_len(0x8a), &sd->bl, SELF);
  7731. return;
  7732. }
  7733. pc_setstand(sd);
  7734. skill_sit(sd, 0);
  7735. WBUFW(buf, 0) = 0x8a;
  7736. WBUFL(buf, 2) = sd->bl.id;
  7737. WBUFB(buf,26) = 3;
  7738. clif_send(buf, packet_len(0x8a), &sd->bl, AREA);
  7739. break;
  7740. }
  7741. }
  7742. /*==========================================
  7743. *
  7744. *------------------------------------------
  7745. */
  7746. void clif_parse_ActionRequest(int fd, struct map_session_data *sd) {
  7747. RFIFOHEAD(fd);
  7748. clif_parse_ActionRequest_sub(sd,
  7749. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7750. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7751. gettick()
  7752. );
  7753. }
  7754. /*==========================================
  7755. *
  7756. *------------------------------------------
  7757. */
  7758. void clif_parse_Restart(int fd, struct map_session_data *sd) {
  7759. RFIFOHEAD(fd);
  7760. switch(RFIFOB(fd,2)) {
  7761. case 0x00:
  7762. if (pc_isdead(sd)) {
  7763. pc_setstand(sd);
  7764. pc_setrestartvalue(sd, 3);
  7765. if (sd->sc.count && battle_config.debuff_on_logout&2) {
  7766. //For some reason food buffs are removed when you respawn.
  7767. if(sd->sc.data[SC_STRFOOD].timer!=-1)
  7768. status_change_end(&sd->bl,SC_STRFOOD,-1);
  7769. if(sd->sc.data[SC_AGIFOOD].timer!=-1)
  7770. status_change_end(&sd->bl,SC_AGIFOOD,-1);
  7771. if(sd->sc.data[SC_VITFOOD].timer!=-1)
  7772. status_change_end(&sd->bl,SC_VITFOOD,-1);
  7773. if(sd->sc.data[SC_INTFOOD].timer!=-1)
  7774. status_change_end(&sd->bl,SC_INTFOOD,-1);
  7775. if(sd->sc.data[SC_DEXFOOD].timer!=-1)
  7776. status_change_end(&sd->bl,SC_DEXFOOD,-1);
  7777. if(sd->sc.data[SC_LUKFOOD].timer!=-1)
  7778. status_change_end(&sd->bl,SC_LUKFOOD,-1);
  7779. if(sd->sc.data[SC_HITFOOD].timer!=-1)
  7780. status_change_end(&sd->bl,SC_HITFOOD,-1);
  7781. if(sd->sc.data[SC_FLEEFOOD].timer!=-1)
  7782. status_change_end(&sd->bl,SC_FLEEFOOD,-1);
  7783. if(sd->sc.data[SC_BATKFOOD].timer!=-1)
  7784. status_change_end(&sd->bl,SC_BATKFOOD,-1);
  7785. if(sd->sc.data[SC_WATKFOOD].timer!=-1)
  7786. status_change_end(&sd->bl,SC_WATKFOOD,-1);
  7787. if(sd->sc.data[SC_MATKFOOD].timer!=-1)
  7788. status_change_end(&sd->bl,SC_MATKFOOD,-1);
  7789. }
  7790. pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, 2);
  7791. }
  7792. // in case the player's status somehow wasn't updated yet [Celest]
  7793. else if (sd->battle_status.hp <= 0)
  7794. pc_setdead(sd);
  7795. break;
  7796. case 0x01:
  7797. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7798. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7799. { //Send to char-server for character selection.
  7800. chrif_charselectreq(sd, session[fd]->client_addr.sin_addr.s_addr);
  7801. } else {
  7802. WFIFOHEAD(fd,packet_len(0x18b));
  7803. WFIFOW(fd,0)=0x18b;
  7804. WFIFOW(fd,2)=1;
  7805. WFIFOSET(fd,packet_len(0x018b));
  7806. }
  7807. break;
  7808. }
  7809. }
  7810. /*==========================================
  7811. * Transmission of a wisp (S 0096 <len>.w <nick>.24B <message>.?B)
  7812. *------------------------------------------
  7813. */
  7814. void clif_parse_Wis(int fd, struct map_session_data *sd) { // S 0096 <len>.w <nick>.24B <message>.?B // rewritten by [Yor]
  7815. char *command, *msg;
  7816. struct map_session_data *dstsd;
  7817. int i=0;
  7818. struct npc_data *npc;
  7819. char split_data[10][50];
  7820. char target[NAME_LENGTH+1];
  7821. char output[256];
  7822. unsigned int len;
  7823. RFIFOHEAD(fd);
  7824. len = RFIFOW(fd,2); //Packet length
  7825. if (len < 28)
  7826. { //Invalid packet, specified size is less than minimum! [Skotlex]
  7827. ShowWarning("Hack on Whisper: %s (AID/CID: %d:%d)!\n", sd->status.name, sd->status.account_id, sd->status.char_id);
  7828. clif_setwaitclose(fd);
  7829. return;
  7830. }
  7831. if (len == 28) return; //Not sure if client really lets you send a blank line.
  7832. len-=28; //Message length
  7833. // 24+3+(RFIFOW(fd,2)-28)+1 <- last 1 is '\0'
  7834. command = (char*)aMallocA((NAME_LENGTH+4+len) * sizeof(char));
  7835. //No need for out of memory checks, malloc.c aborts the map when that happens.
  7836. msg = command;
  7837. msg+= sprintf(command, "%s : ", sd->status.name);
  7838. memcpy(msg, RFIFOP(fd, 28), len);
  7839. mes_len_check(msg, len, CHATBOX_SIZE);
  7840. if ((is_charcommand(fd, sd, command) != CharCommand_None) ||
  7841. (is_atcommand(fd, sd, command) != AtCommand_None)) {
  7842. aFree(command);
  7843. return;
  7844. }
  7845. if (sd->sc.count &&
  7846. (sd->sc.data[SC_BERSERK].timer!=-1 ||
  7847. (sd->sc.data[SC_NOCHAT].timer != -1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT))) {
  7848. aFree(command);
  7849. return;
  7850. }
  7851. if (battle_config.min_chat_delay)
  7852. { //[Skotlex]
  7853. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  7854. aFree(command);
  7855. return;
  7856. }
  7857. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7858. }
  7859. memcpy(&target,RFIFOP(fd, 4),NAME_LENGTH);
  7860. target[NAME_LENGTH]='\0';
  7861. //Chat Logging type 'W' / Whisper
  7862. if(log_config.chat&1 //we log everything then
  7863. || ( log_config.chat&2 //if Whisper bit is on
  7864. && ( !agit_flag || !(log_config.chat&16) ))) //if WOE ONLY flag is off or AGIT is OFF
  7865. log_chat("W", 0, sd->status.char_id, sd->status.account_id, (char*)mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, msg);
  7866. //-------------------------------------------------------//
  7867. // Lordalfa - Paperboy - To whisper NPC commands //
  7868. //-------------------------------------------------------//
  7869. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) >4)) {
  7870. char *str= target+4; //Skip the NPC: string part.
  7871. if ((npc = npc_name2id(str)))
  7872. {
  7873. char *split;
  7874. str = msg;
  7875. for( i=0; i < 10; ++i )
  7876. {// Splits the message using '#' as separators
  7877. split = strchr(str,'#');
  7878. if( split == NULL )
  7879. { // use the remaining string
  7880. strncpy(split_data[i], str, sizeof(split_data[0])/sizeof(char));
  7881. split_data[i][sizeof(split_data[0])/sizeof(char)-1] = '\0';
  7882. for( ++i; i < 10; ++i )
  7883. split_data[i][0] = '\0';
  7884. break;
  7885. }
  7886. *split = '\0';
  7887. strncpy(split_data[i], str, sizeof(split_data[0])/sizeof(char));
  7888. split_data[i][sizeof(split_data[0])/sizeof(char)-1] = '\0';
  7889. str = split+1;
  7890. }
  7891. for (i=0;i<10;i++)
  7892. {
  7893. sprintf(output, "@whispervar%d$", i);
  7894. set_var(sd,output,(char *) split_data[i]);
  7895. }
  7896. sprintf(output, "%s::OnWhisperGlobal", npc->name);
  7897. npc_event(sd,output,0); // Calls the NPC label
  7898. aFree(command);
  7899. return;
  7900. }
  7901. }
  7902. // Main chat [LuzZza]
  7903. if(strcmpi(target, main_chat_nick) == 0) {
  7904. if(!sd->state.mainchat)
  7905. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7906. else {
  7907. snprintf(output, sizeof(output)/sizeof(char), msg_txt(386), sd->status.name, msg);
  7908. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7909. }
  7910. aFree(command);
  7911. return;
  7912. }
  7913. // searching destination character
  7914. dstsd = map_nick2sd(target);
  7915. // player is not on this map-server
  7916. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7917. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7918. // and if we ask for 'Test', we must not contact 'test' player
  7919. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7920. if (dstsd == NULL ||
  7921. strcmp(dstsd->status.name, target) != 0)
  7922. { // send message to inter-server
  7923. intif_wis_message(sd, target, msg, len);
  7924. aFree(command);
  7925. return;
  7926. }
  7927. // player is on this map-server
  7928. if (dstsd->fd == fd) {
  7929. // if you send to your self, don't send anything to others
  7930. // but, normally, it's impossible!
  7931. clif_wis_message(fd, wisp_server_name,
  7932. "You can not page yourself. Sorry.",
  7933. strlen("You can not page yourself. Sorry.") + 1);
  7934. aFree(command);
  7935. return;
  7936. }
  7937. // otherwise, send message and answer immediately
  7938. if (dstsd->state.ignoreAll) {
  7939. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7940. clif_wis_end(fd, 1); // 1: target character is not loged in
  7941. else
  7942. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7943. aFree(command);
  7944. return;
  7945. }
  7946. // if player ignore the source character
  7947. for(i = 0; i < MAX_IGNORE_LIST &&
  7948. dstsd->ignore[i].name[0] != '\0' &&
  7949. strcmp(dstsd->ignore[i].name, sd->status.name) != 0
  7950. ; i++);
  7951. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  7952. { //Ignored
  7953. clif_wis_end(fd, 2); // 2: ignored by target
  7954. aFree(command);
  7955. return;
  7956. }
  7957. // if source player not found in ignore list
  7958. if(dstsd->away_message[0] != '\0') { // Send away automessage [LuzZza]
  7959. //(Automessage has been sent)
  7960. sprintf(output, "%s %s", msg, msg_txt(543));
  7961. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  7962. clif_wis_end(fd, 0); // 0: success to send wisper
  7963. if(dstsd->state.autotrade)
  7964. //"Away [AT] - \"%s\""
  7965. sprintf(output, msg_txt(544), dstsd->away_message);
  7966. else
  7967. //"Away - \"%s\""
  7968. sprintf(output, msg_txt(545), dstsd->away_message);
  7969. aFree(command);
  7970. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  7971. return;
  7972. }
  7973. // Normal message
  7974. clif_wis_message(dstsd->fd, sd->status.name, msg, len);
  7975. clif_wis_end(fd, 0); // 0: success to send wisper
  7976. aFree(command);
  7977. return;
  7978. }
  7979. /*==========================================
  7980. *
  7981. *------------------------------------------
  7982. */
  7983. void clif_parse_GMmessage(int fd, struct map_session_data *sd) {
  7984. // /b
  7985. char* mes;
  7986. int size, lv;
  7987. RFIFOHEAD(fd);
  7988. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7989. return;
  7990. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_Broadcast)))
  7991. return;
  7992. size = WFIFOW(fd,2)-4;
  7993. mes = RFIFOP(fd,4);
  7994. mes_len_check(mes, size, CHAT_SIZE);
  7995. intif_GMmessage(mes, size, 0);
  7996. if(log_config.gm && lv >= log_config.gm) {
  7997. char message[CHAT_SIZE+4];
  7998. sprintf(message, "/b %s", mes);
  7999. log_atcommand(sd, message);
  8000. }
  8001. }
  8002. /*==========================================
  8003. *
  8004. *------------------------------------------
  8005. */
  8006. void clif_parse_TakeItem(int fd, struct map_session_data *sd) {
  8007. struct flooritem_data *fitem;
  8008. int map_object_id;
  8009. RFIFOHEAD(fd);
  8010. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8011. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  8012. do {
  8013. if (pc_isdead(sd)) {
  8014. clif_clearchar_area(&sd->bl, 1);
  8015. break;
  8016. }
  8017. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  8018. break;
  8019. if (clif_cant_act(sd))
  8020. break;
  8021. //Disable cloaking/chasewalking characters from looting [Skotlex]
  8022. if(pc_iscloaking(sd) || pc_ischasewalk(sd))
  8023. break;
  8024. if(sd->sc.count && (
  8025. sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  8026. sd->sc.data[SC_BLADESTOP].timer != -1 ||
  8027. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOITEM))
  8028. )
  8029. break;
  8030. if (!pc_takeitem(sd, fitem))
  8031. break;
  8032. return;
  8033. } while (0);
  8034. // Client REQUIRES a fail packet or you can no longer pick items.
  8035. clif_additem(sd,0,0,6);
  8036. }
  8037. /*==========================================
  8038. *
  8039. *------------------------------------------
  8040. */
  8041. void clif_parse_DropItem(int fd, struct map_session_data *sd) {
  8042. int item_index, item_amount;
  8043. RFIFOHEAD(fd);
  8044. if (pc_isdead(sd)) {
  8045. clif_clearchar_area(&sd->bl, 1);
  8046. return;
  8047. }
  8048. if (clif_cant_act(sd))
  8049. return;
  8050. if (sd->sc.count && (
  8051. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  8052. sd->sc.data[SC_BLADESTOP].timer != -1 ||
  8053. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOITEM)
  8054. ))
  8055. return;
  8056. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8057. item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8058. if (!pc_dropitem(sd, item_index, item_amount))
  8059. //Because the client does not likes being ignored.
  8060. clif_delitem(sd, item_index,0);
  8061. }
  8062. /*==========================================
  8063. *
  8064. *------------------------------------------
  8065. */
  8066. void clif_parse_UseItem(int fd, struct map_session_data *sd) {
  8067. int n;
  8068. RFIFOHEAD(fd);
  8069. if (pc_isdead(sd)) {
  8070. clif_clearchar_area(&sd->bl, 1);
  8071. return;
  8072. }
  8073. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  8074. return;
  8075. //This flag enables you to use items while in an NPC. [Skotlex]
  8076. if (sd->npc_id) {
  8077. if (sd->npc_id != sd->npc_item_flag)
  8078. return;
  8079. } else
  8080. if (clif_trading(sd))
  8081. return;
  8082. pc_delinvincibletimer(sd);
  8083. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  8084. sd->idletime = last_tick;
  8085. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8086. if(n <0 || n >= MAX_INVENTORY)
  8087. return;
  8088. if (!pc_useitem(sd,n))
  8089. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  8090. }
  8091. /*==========================================
  8092. *
  8093. *------------------------------------------
  8094. */
  8095. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  8096. {
  8097. int index;
  8098. RFIFOHEAD(fd);
  8099. if(pc_isdead(sd)) {
  8100. clif_clearchar_area(&sd->bl,1);
  8101. return;
  8102. }
  8103. index = RFIFOW(fd,2)-2;
  8104. if (index < 0 || index >= MAX_INVENTORY)
  8105. return; //Out of bounds check.
  8106. if(sd->npc_id) {
  8107. if (sd->npc_id != sd->npc_item_flag)
  8108. return;
  8109. } else if (sd->state.storage_flag || sd->sc.opt1)
  8110. ; //You can equip/unequip stuff while storage is open/under status changes
  8111. else if (clif_cant_act(sd))
  8112. return;
  8113. if(sd->sc.data[SC_BLADESTOP].timer!=-1 || sd->sc.data[SC_BERSERK].timer!=-1 )
  8114. return;
  8115. if(!sd->status.inventory[index].identify) { // 未鑑定
  8116. clif_equipitemack(sd,index,0,0); // fail
  8117. return;
  8118. }
  8119. //ペット用装備であるかないか
  8120. if(sd->inventory_data[index]) {
  8121. if(sd->inventory_data[index]->type != IT_PETARMOR){
  8122. if(sd->inventory_data[index]->type == IT_AMMO)
  8123. pc_equipitem(sd,index,EQP_AMMO); //Client doesn't sends the position.
  8124. else
  8125. pc_equipitem(sd,index,RFIFOW(fd,4));
  8126. } else
  8127. pet_equipitem(sd,index);
  8128. }
  8129. }
  8130. /*==========================================
  8131. *
  8132. *------------------------------------------
  8133. */
  8134. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  8135. {
  8136. int index;
  8137. RFIFOHEAD(fd);
  8138. if(pc_isdead(sd)) {
  8139. clif_clearchar_area(&sd->bl,1);
  8140. return;
  8141. }
  8142. if (sd->state.storage_flag)
  8143. ; //You can equip/unequip stuff while storage is open.
  8144. else if (clif_cant_act(sd))
  8145. return;
  8146. index = RFIFOW(fd,2)-2;
  8147. pc_unequipitem(sd,index,1);
  8148. }
  8149. /*==========================================
  8150. *
  8151. *------------------------------------------
  8152. */
  8153. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8154. {
  8155. struct block_list *bl;
  8156. RFIFOHEAD(fd);
  8157. if(pc_isdead(sd)) {
  8158. clif_clearchar_area(&sd->bl,1);
  8159. return;
  8160. }
  8161. if (clif_cant_act(sd))
  8162. return;
  8163. bl = map_id2bl(RFIFOL(fd,2));
  8164. if (!bl) return;
  8165. switch (bl->type) {
  8166. case BL_MOB:
  8167. if (!((TBL_MOB *)bl)->nd || !mob_script_callback((TBL_MOB *)bl, &sd->bl, CALLBACK_NPCCLICK))
  8168. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8169. break;
  8170. case BL_PC:
  8171. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8172. break;
  8173. case BL_NPC:
  8174. npc_click(sd,(TBL_NPC*)bl);
  8175. break;
  8176. }
  8177. return;
  8178. }
  8179. /*==========================================
  8180. *
  8181. *------------------------------------------
  8182. */
  8183. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8184. {
  8185. RFIFOHEAD(fd);
  8186. if (sd->state.trading)
  8187. return;
  8188. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8189. }
  8190. /*==========================================
  8191. *
  8192. *------------------------------------------
  8193. */
  8194. void clif_parse_NpcBuyListSend(int fd,struct map_session_data *sd)
  8195. {
  8196. int fail=0,n;
  8197. unsigned short *item_list;
  8198. RFIFOHEAD(fd);
  8199. n = (RFIFOW(fd,2)-4) /4;
  8200. item_list = (unsigned short*)RFIFOP(fd,4);
  8201. if (sd->state.trading|| !sd->npc_shopid)
  8202. fail = 1;
  8203. else
  8204. fail = npc_buylist(sd,n,item_list);
  8205. sd->npc_shopid = 0; //Clear shop data.
  8206. WFIFOHEAD(fd,packet_len(0xca));
  8207. WFIFOW(fd,0)=0xca;
  8208. WFIFOB(fd,2)=fail;
  8209. WFIFOSET(fd,packet_len(0xca));
  8210. }
  8211. /*==========================================
  8212. *
  8213. *------------------------------------------
  8214. */
  8215. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8216. {
  8217. int fail=0,n;
  8218. unsigned short *item_list;
  8219. RFIFOHEAD(fd);
  8220. n = (RFIFOW(fd,2)-4) /4;
  8221. item_list = (unsigned short*)RFIFOP(fd,4);
  8222. if (sd->state.trading || !sd->npc_shopid)
  8223. fail = 1;
  8224. else
  8225. fail = npc_selllist(sd,n,item_list);
  8226. sd->npc_shopid = 0; //Clear shop data.
  8227. WFIFOHEAD(fd,packet_len(0xcb));
  8228. WFIFOW(fd,0)=0xcb;
  8229. WFIFOB(fd,2)=fail;
  8230. WFIFOSET(fd,packet_len(0xcb));
  8231. }
  8232. /*==========================================
  8233. *
  8234. *------------------------------------------
  8235. */
  8236. void clif_parse_CreateChatRoom(int fd,struct map_session_data *sd)
  8237. {
  8238. RFIFOHEAD(fd);
  8239. if (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOROOM)
  8240. return;
  8241. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 4){
  8242. chat_createchat(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8243. } else
  8244. clif_skill_fail(sd,1,0,3);
  8245. }
  8246. /*==========================================
  8247. *
  8248. *------------------------------------------
  8249. */
  8250. void clif_parse_ChatAddMember(int fd,struct map_session_data *sd)
  8251. {
  8252. RFIFOHEAD(fd);
  8253. chat_joinchat(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8254. }
  8255. /*==========================================
  8256. *
  8257. *------------------------------------------
  8258. */
  8259. void clif_parse_ChatRoomStatusChange(int fd,struct map_session_data *sd)
  8260. {
  8261. RFIFOHEAD(fd);
  8262. chat_changechatstatus(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8263. }
  8264. /*==========================================
  8265. *
  8266. *------------------------------------------
  8267. */
  8268. void clif_parse_ChangeChatOwner(int fd,struct map_session_data *sd)
  8269. {
  8270. RFIFOHEAD(fd);
  8271. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8272. }
  8273. /*==========================================
  8274. *
  8275. *------------------------------------------
  8276. */
  8277. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8278. {
  8279. RFIFOHEAD(fd);
  8280. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8281. }
  8282. /*==========================================
  8283. *
  8284. *------------------------------------------
  8285. */
  8286. void clif_parse_ChatLeave(int fd,struct map_session_data *sd)
  8287. {
  8288. chat_leavechat(sd);
  8289. }
  8290. //Handles notifying asker and rejecter of what has just ocurred.
  8291. //Type is used to determine the correct msg_txt to use:
  8292. //0:
  8293. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  8294. {
  8295. char *msg, output[256];
  8296. // Your request has been rejected by autoreject option.
  8297. msg = msg_txt(392);
  8298. clif_disp_onlyself(src, msg, strlen(msg));
  8299. //Notice that a request was rejected.
  8300. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  8301. clif_disp_onlyself(target, output, strlen(output));
  8302. }
  8303. /*==========================================
  8304. * 取引要請を相手に送る
  8305. *------------------------------------------
  8306. */
  8307. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8308. {
  8309. struct map_session_data *t_sd;
  8310. RFIFOHEAD(fd);
  8311. t_sd = map_id2sd(RFIFOL(fd,2));
  8312. if(!sd->chatID && clif_cant_act(sd))
  8313. return; //You can trade while in a chatroom.
  8314. // @noask [LuzZza]
  8315. if(t_sd && t_sd->state.noask) {
  8316. clif_noask_sub(sd, t_sd, 0);
  8317. return;
  8318. }
  8319. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 1){
  8320. trade_traderequest(sd,t_sd);
  8321. } else
  8322. clif_skill_fail(sd,1,0,0);
  8323. }
  8324. /*==========================================
  8325. * 取引要請
  8326. *------------------------------------------
  8327. */
  8328. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8329. {
  8330. RFIFOHEAD(fd);
  8331. trade_tradeack(sd,RFIFOB(fd,2));
  8332. }
  8333. /*==========================================
  8334. * アイテム追加
  8335. *------------------------------------------
  8336. */
  8337. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8338. {
  8339. RFIFOHEAD(fd);
  8340. trade_tradeadditem(sd,RFIFOW(fd,2),RFIFOL(fd,4));
  8341. }
  8342. /*==========================================
  8343. * アイテム追加完了(ok押し)
  8344. *------------------------------------------
  8345. */
  8346. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8347. {
  8348. trade_tradeok(sd);
  8349. }
  8350. /*==========================================
  8351. * 取引キャンセル
  8352. *------------------------------------------
  8353. */
  8354. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8355. {
  8356. trade_tradecancel(sd);
  8357. }
  8358. /*==========================================
  8359. * 取引許諾(trade押し)
  8360. *------------------------------------------
  8361. */
  8362. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8363. {
  8364. trade_tradecommit(sd);
  8365. }
  8366. /*==========================================
  8367. *
  8368. *------------------------------------------
  8369. */
  8370. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8371. {
  8372. pc_stop_attack(sd);
  8373. }
  8374. /*==========================================
  8375. * カートへアイテムを移す
  8376. *------------------------------------------
  8377. */
  8378. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8379. {
  8380. RFIFOHEAD(fd);
  8381. if (clif_trading(sd))
  8382. return;
  8383. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8384. }
  8385. /*==========================================
  8386. * カートからアイテムを出す
  8387. *------------------------------------------
  8388. */
  8389. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8390. {
  8391. RFIFOHEAD(fd);
  8392. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8393. }
  8394. /*==========================================
  8395. * 付属品(鷹,ペコ,カート)をはずす
  8396. *------------------------------------------
  8397. */
  8398. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8399. {
  8400. //Can only remove Cart/Riding/Falcon.
  8401. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  8402. }
  8403. /*==========================================
  8404. * チェンジカート
  8405. *------------------------------------------
  8406. */
  8407. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8408. {
  8409. RFIFOHEAD(fd);
  8410. pc_setcart(sd,RFIFOW(fd,2));
  8411. }
  8412. /*==========================================
  8413. * ステータスアップ
  8414. *------------------------------------------
  8415. */
  8416. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8417. {
  8418. RFIFOHEAD(fd);
  8419. pc_statusup(sd,RFIFOW(fd,2));
  8420. }
  8421. /*==========================================
  8422. * スキルレベルアップ
  8423. *------------------------------------------
  8424. */
  8425. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8426. {
  8427. RFIFOHEAD(fd);
  8428. pc_skillup(sd,RFIFOW(fd,2));
  8429. }
  8430. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, int skillnum, int skilllv, int target_id)
  8431. {
  8432. int lv;
  8433. if (!hd)
  8434. return;
  8435. if (skillnotok_hom(skillnum, hd)) //[orn]
  8436. return;
  8437. if (hd->bl.id != target_id &&
  8438. skill_get_inf(skillnum)&INF_SELF_SKILL)
  8439. target_id = hd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8440. if (hd->ud.skilltimer != -1) {
  8441. if (skillnum != SA_CASTCANCEL)
  8442. return;
  8443. } else if (DIFF_TICK(tick, hd->ud.canact_tick) < 0)
  8444. return;
  8445. lv = merc_hom_checkskill(hd, skillnum);
  8446. if (skilllv > lv)
  8447. skilllv = lv;
  8448. if (skilllv)
  8449. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  8450. }
  8451. /*==========================================
  8452. * スキル使用(ID指定)
  8453. *------------------------------------------
  8454. */
  8455. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd) {
  8456. int skillnum, skilllv, tmp, target_id;
  8457. unsigned int tick = gettick();
  8458. RFIFOHEAD(fd);
  8459. if (clif_cant_act(sd))
  8460. return;
  8461. if (pc_issit(sd))
  8462. return;
  8463. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8464. if (skilllv < 1) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8465. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8466. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8467. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8468. sd->idletime = last_tick;
  8469. tmp = skill_get_inf(skillnum);
  8470. if (tmp&INF_GROUND_SKILL)
  8471. return; //Using a ground skill on a target? WRONG.
  8472. if (skillnum >= HM_SKILLBASE && skillnum <= HM_SKILLBASE+MAX_HOMUNSKILL) {
  8473. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  8474. return;
  8475. }
  8476. if (skillnotok(skillnum, sd))
  8477. return;
  8478. if (sd->bl.id != target_id && !sd->state.skill_flag && tmp&INF_SELF_SKILL)
  8479. target_id = sd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8480. if (sd->ud.skilltimer != -1) {
  8481. if (skillnum != SA_CASTCANCEL)
  8482. return;
  8483. } else if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8484. clif_skill_fail(sd, skillnum, 4, 0);
  8485. return;
  8486. }
  8487. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8488. return;
  8489. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8490. target_id = sd->bl.id;
  8491. if (sd->skillitem == skillnum) {
  8492. if (skilllv != sd->skillitemlv)
  8493. skilllv = sd->skillitemlv;
  8494. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8495. return;
  8496. }
  8497. sd->skillitem = sd->skillitemlv = 0;
  8498. if (skillnum == MO_EXTREMITYFIST) {
  8499. if ((sd->sc.data[SC_COMBO].timer == -1 ||
  8500. (sd->sc.data[SC_COMBO].val1 != MO_COMBOFINISH &&
  8501. sd->sc.data[SC_COMBO].val1 != CH_TIGERFIST &&
  8502. sd->sc.data[SC_COMBO].val1 != CH_CHAINCRUSH))) {
  8503. if (!sd->state.skill_flag ) {
  8504. sd->state.skill_flag = 1;
  8505. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8506. return;
  8507. } else if (sd->bl.id == target_id) {
  8508. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8509. return;
  8510. }
  8511. }
  8512. }
  8513. if (skillnum == TK_JUMPKICK) {
  8514. if (sd->sc.data[SC_COMBO].timer == -1 ||
  8515. sd->sc.data[SC_COMBO].val1 != TK_JUMPKICK) {
  8516. if (!sd->state.skill_flag ) {
  8517. sd->state.skill_flag = 1;
  8518. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8519. return;
  8520. } else if (sd->bl.id == target_id) {
  8521. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8522. return;
  8523. }
  8524. }
  8525. }
  8526. if (skillnum >= GD_SKILLBASE) {
  8527. if (sd->state.gmaster_flag)
  8528. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8529. else
  8530. skilllv = 0;
  8531. } else {
  8532. tmp = pc_checkskill(sd, skillnum);
  8533. if (skilllv > tmp)
  8534. skilllv = tmp;
  8535. }
  8536. pc_delinvincibletimer(sd);
  8537. if (skilllv)
  8538. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8539. if (sd->state.skill_flag)
  8540. sd->state.skill_flag = 0;
  8541. }
  8542. /*==========================================
  8543. * スキル使用(場所指定)
  8544. *------------------------------------------
  8545. */
  8546. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, int skilllv, int skillnum, int x, int y, int skillmoreinfo)
  8547. {
  8548. int lv;
  8549. unsigned int tick = gettick();
  8550. RFIFOHEAD(fd);
  8551. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8552. sd->idletime = last_tick;
  8553. if (skillnotok(skillnum, sd))
  8554. return;
  8555. if (!(skill_get_inf(skillnum)&INF_GROUND_SKILL))
  8556. return; //Using a target skill on the ground? WRONG.
  8557. if (skillmoreinfo != -1) {
  8558. if (pc_issit(sd)) {
  8559. clif_skill_fail(sd, skillnum, 0, 0);
  8560. return;
  8561. }
  8562. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  8563. memcpy(sd->message, RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8564. sd->message[MESSAGE_SIZE-1] = '\0'; //Overflow protection [Skotlex]
  8565. }
  8566. if (sd->ud.skilltimer != -1)
  8567. return;
  8568. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0)
  8569. {
  8570. clif_skill_fail(sd, skillnum, 4, 0);
  8571. return;
  8572. }
  8573. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8574. return;
  8575. pc_delinvincibletimer(sd);
  8576. if (sd->skillitem == skillnum) {
  8577. if (skilllv != sd->skillitemlv)
  8578. skilllv = sd->skillitemlv;
  8579. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8580. } else {
  8581. sd->skillitem = sd->skillitemlv = 0;
  8582. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8583. if (skilllv > lv)
  8584. skilllv = lv;
  8585. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8586. }
  8587. }
  8588. }
  8589. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd) {
  8590. RFIFOHEAD(fd);
  8591. if (clif_cant_act(sd))
  8592. return;
  8593. if (pc_issit(sd))
  8594. return;
  8595. clif_parse_UseSkillToPosSub(fd, sd,
  8596. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8597. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8598. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8599. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8600. -1 //Skill more info.
  8601. );
  8602. }
  8603. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd) {
  8604. RFIFOHEAD(fd);
  8605. if (clif_cant_act(sd))
  8606. return;
  8607. if (pc_issit(sd))
  8608. return;
  8609. clif_parse_UseSkillToPosSub(fd, sd,
  8610. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8611. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8612. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8613. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8614. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8615. );
  8616. }
  8617. /*==========================================
  8618. * スキル使用(map指定)
  8619. *------------------------------------------
  8620. */
  8621. void clif_parse_UseSkillMap(int fd,struct map_session_data *sd)
  8622. {
  8623. RFIFOHEAD(fd);
  8624. if (clif_cant_act(sd))
  8625. return;
  8626. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8627. return;
  8628. pc_delinvincibletimer(sd);
  8629. skill_castend_map(sd,RFIFOW(fd,2),(char*)RFIFOP(fd,4));
  8630. }
  8631. /*==========================================
  8632. * メモ要求
  8633. *------------------------------------------
  8634. */
  8635. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8636. {
  8637. if (!pc_isdead(sd))
  8638. pc_memo(sd,-1);
  8639. }
  8640. /*==========================================
  8641. * アイテム合成
  8642. *------------------------------------------
  8643. */
  8644. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8645. {
  8646. RFIFOHEAD(fd);
  8647. if (sd->menuskill_id != AM_PHARMACY)
  8648. return;
  8649. if (clif_trading(sd)) {
  8650. //Make it fail to avoid shop exploits where you sell something different than you see.
  8651. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8652. sd->menuskill_lv = sd->menuskill_id = 0;
  8653. return;
  8654. }
  8655. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8656. sd->menuskill_lv = sd->menuskill_id = 0;
  8657. }
  8658. /*==========================================
  8659. * 武器修理
  8660. *------------------------------------------
  8661. */
  8662. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8663. {
  8664. RFIFOHEAD(fd);
  8665. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8666. return;
  8667. if (clif_trading(sd)) {
  8668. //Make it fail to avoid shop exploits where you sell something different than you see.
  8669. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8670. sd->menuskill_lv = sd->menuskill_id = 0;
  8671. return;
  8672. }
  8673. skill_repairweapon(sd,RFIFOW(fd,2));
  8674. sd->menuskill_lv = sd->menuskill_id = 0;
  8675. }
  8676. /*==========================================
  8677. *
  8678. *------------------------------------------
  8679. */
  8680. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd) {
  8681. int idx;
  8682. RFIFOHEAD(fd);
  8683. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8684. return;
  8685. if (clif_trading(sd)) {
  8686. //Make it fail to avoid shop exploits where you sell something different than you see.
  8687. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8688. sd->menuskill_lv = sd->menuskill_id = 0;
  8689. return;
  8690. }
  8691. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8692. skill_weaponrefine(sd, idx-2);
  8693. sd->menuskill_lv = sd->menuskill_id = 0;
  8694. }
  8695. /*==========================================
  8696. *
  8697. *------------------------------------------
  8698. */
  8699. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8700. {
  8701. unsigned char select;
  8702. RFIFOHEAD(fd);
  8703. select = RFIFOB(fd,6);
  8704. if((select > sd->npc_menu && select != 0xff) || !select){
  8705. ShowWarning("Hack on NPC Select Menu: %s (AID: %d)!\n",sd->status.name,sd->bl.id);
  8706. clif_GM_kick(sd,sd,0);
  8707. } else {
  8708. sd->npc_menu=select;
  8709. npc_scriptcont(sd,RFIFOL(fd,2));
  8710. }
  8711. }
  8712. /*==========================================
  8713. *
  8714. *------------------------------------------
  8715. */
  8716. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8717. {
  8718. RFIFOHEAD(fd);
  8719. npc_scriptcont(sd,RFIFOL(fd,2));
  8720. }
  8721. /*==========================================
  8722. *
  8723. *------------------------------------------
  8724. */
  8725. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8726. {
  8727. RFIFOHEAD(fd);
  8728. sd->npc_amount=(int)RFIFOL(fd,6);
  8729. npc_scriptcont(sd,RFIFOL(fd,2));
  8730. }
  8731. /*==========================================
  8732. *
  8733. *------------------------------------------
  8734. */
  8735. void clif_parse_NpcStringInput(int fd,struct map_session_data *sd)
  8736. {
  8737. short message_len;
  8738. RFIFOHEAD(fd);
  8739. message_len = RFIFOW(fd,2)-7;
  8740. if(message_len < 1)
  8741. return; //Blank message?
  8742. if(message_len >= sizeof(sd->npc_str)){
  8743. ShowWarning("clif: input string too long !\n");
  8744. message_len = sizeof(sd->npc_str);
  8745. }
  8746. // Exploit prevention if crafted packets (without null) is being sent. [Lance]
  8747. memcpy(sd->npc_str,RFIFOP(fd,8),message_len);
  8748. sd->npc_str[message_len-1]=0;
  8749. npc_scriptcont(sd,RFIFOL(fd,4));
  8750. }
  8751. /*==========================================
  8752. *
  8753. *------------------------------------------
  8754. */
  8755. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8756. {
  8757. RFIFOHEAD(fd);
  8758. if (sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8759. npc_scriptcont(sd,RFIFOL(fd,2));
  8760. }
  8761. /*==========================================
  8762. * アイテム鑑定
  8763. *------------------------------------------
  8764. */
  8765. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8766. {
  8767. RFIFOHEAD(fd);
  8768. if (sd->menuskill_id != MC_IDENTIFY)
  8769. return;
  8770. skill_identify(sd,RFIFOW(fd,2)-2);
  8771. sd->menuskill_lv = sd->menuskill_id = 0;
  8772. }
  8773. /*==========================================
  8774. * 矢作成
  8775. *------------------------------------------
  8776. */
  8777. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8778. {
  8779. RFIFOHEAD(fd);
  8780. if (sd->menuskill_id != AC_MAKINGARROW)
  8781. return;
  8782. if (clif_trading(sd)) {
  8783. //Make it fail to avoid shop exploits where you sell something different than you see.
  8784. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8785. sd->menuskill_lv = sd->menuskill_id = 0;
  8786. return;
  8787. }
  8788. skill_arrow_create(sd,RFIFOW(fd,2));
  8789. sd->menuskill_lv = sd->menuskill_id = 0;
  8790. }
  8791. /*==========================================
  8792. * オートスペル受信
  8793. *------------------------------------------
  8794. */
  8795. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8796. {
  8797. RFIFOHEAD(fd);
  8798. if (sd->menuskill_id != SA_AUTOSPELL)
  8799. return;
  8800. skill_autospell(sd,RFIFOW(fd,2));
  8801. sd->menuskill_lv = sd->menuskill_id = 0;
  8802. }
  8803. /*==========================================
  8804. * カード使用
  8805. *------------------------------------------
  8806. */
  8807. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8808. {
  8809. RFIFOHEAD(fd);
  8810. if (sd->state.trading!= 0)
  8811. return;
  8812. clif_use_card(sd,RFIFOW(fd,2)-2);
  8813. }
  8814. /*==========================================
  8815. * カード挿入装備選択
  8816. *------------------------------------------
  8817. */
  8818. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8819. {
  8820. RFIFOHEAD(fd);
  8821. if (sd->state.trading!= 0)
  8822. return;
  8823. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8824. }
  8825. /*==========================================
  8826. * 0193 キャラID名前引き
  8827. *------------------------------------------
  8828. */
  8829. void clif_parse_SolveCharName(int fd, struct map_session_data *sd) {
  8830. int char_id;
  8831. RFIFOHEAD(fd);
  8832. char_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8833. clif_solved_charname(sd, char_id);
  8834. }
  8835. /*==========================================
  8836. * 0197 /resetskill /resetstate
  8837. *------------------------------------------
  8838. */
  8839. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  8840. RFIFOHEAD(fd);
  8841. if (battle_config.atc_gmonly && !pc_isGM(sd))
  8842. return;
  8843. if (pc_isGM(sd) < get_atcommand_level(AtCommand_ResetState))
  8844. return;
  8845. if (RFIFOW(fd,2))
  8846. pc_resetskill(sd,1);
  8847. else
  8848. pc_resetstate(sd);
  8849. if(log_config.gm && get_atcommand_level(AtCommand_ResetState >= log_config.gm))
  8850. log_atcommand(sd, RFIFOW(fd,2) ? "/resetskill" : "/resetstate");
  8851. }
  8852. /*==========================================
  8853. * 019c /lb等
  8854. *------------------------------------------
  8855. */
  8856. void clif_parse_LGMmessage(int fd, struct map_session_data *sd) {
  8857. unsigned char buf[CHAT_SIZE+4];
  8858. char *mes;
  8859. int len, lv;
  8860. RFIFOHEAD(fd);
  8861. if (battle_config.atc_gmonly && !pc_isGM(sd))
  8862. return;
  8863. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_LocalBroadcast)))
  8864. return;
  8865. len = RFIFOW(fd,2) - 4;
  8866. mes = RFIFOP(fd,4);
  8867. mes_len_check(mes, len, CHAT_SIZE);
  8868. WBUFW(buf,0) = 0x9a;
  8869. WBUFW(buf,2) = len+4;
  8870. memcpy(WBUFP(buf,4), mes, len);
  8871. clif_send(buf, WBUFW(buf,2), &sd->bl, ALL_SAMEMAP);
  8872. if(log_config.gm && lv >= log_config.gm) {
  8873. char message[CHAT_SIZE+5];
  8874. sprintf(message, "/lb %s", mes);
  8875. log_atcommand(sd, message);
  8876. }
  8877. }
  8878. /*==========================================
  8879. * カプラ倉庫へ入れる
  8880. *------------------------------------------
  8881. */
  8882. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd) {
  8883. int item_index, item_amount;
  8884. RFIFOHEAD(fd);
  8885. if (clif_trading(sd))
  8886. return;
  8887. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8888. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8889. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  8890. return;
  8891. if (sd->state.storage_flag == 1)
  8892. storage_storageadd(sd, item_index, item_amount);
  8893. else if (sd->state.storage_flag == 2)
  8894. storage_guild_storageadd(sd, item_index, item_amount);
  8895. }
  8896. /*==========================================
  8897. * カプラ倉庫から出す
  8898. *------------------------------------------
  8899. */
  8900. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd) {
  8901. int item_index, item_amount;
  8902. RFIFOHEAD(fd);
  8903. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8904. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8905. if (sd->state.storage_flag == 1)
  8906. storage_storageget(sd, item_index, item_amount);
  8907. else if(sd->state.storage_flag == 2)
  8908. storage_guild_storageget(sd, item_index, item_amount);
  8909. }
  8910. /*==========================================
  8911. * カプラ倉庫へカートから入れる
  8912. *------------------------------------------
  8913. */
  8914. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd) {
  8915. RFIFOHEAD(fd);
  8916. if(sd->vender_id)
  8917. return;
  8918. if (sd->state.storage_flag == 1)
  8919. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8920. else if (sd->state.storage_flag == 2)
  8921. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8922. }
  8923. /*==========================================
  8924. * カプラ倉庫から出す
  8925. *------------------------------------------
  8926. */
  8927. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd) {
  8928. RFIFOHEAD(fd);
  8929. if (sd->vender_id)
  8930. return;
  8931. if (sd->state.storage_flag == 1)
  8932. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8933. else if (sd->state.storage_flag == 2)
  8934. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8935. }
  8936. /*==========================================
  8937. * カプラ倉庫を閉じる
  8938. *------------------------------------------
  8939. */
  8940. void clif_parse_CloseKafra(int fd, struct map_session_data *sd) {
  8941. if (sd->state.storage_flag == 1)
  8942. storage_storageclose(sd);
  8943. else if (sd->state.storage_flag == 2)
  8944. storage_guild_storageclose(sd);
  8945. }
  8946. /*==========================================
  8947. * Kafra storage protection password system
  8948. *------------------------------------------
  8949. */
  8950. void clif_parse_StoragePassword(int fd, struct map_session_data *sd) {
  8951. //TODO
  8952. }
  8953. /*==========================================
  8954. * パーティを作る
  8955. *------------------------------------------
  8956. */
  8957. void clif_parse_CreateParty(int fd, struct map_session_data *sd) {
  8958. RFIFOHEAD(fd);
  8959. if(map[sd->bl.m].flag.partylock)
  8960. { //Guild locked.
  8961. clif_displaymessage(fd, msg_txt(227));
  8962. return;
  8963. }
  8964. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7) {
  8965. party_create(sd,(char*)RFIFOP(fd,2),0,0);
  8966. } else
  8967. clif_skill_fail(sd,1,0,4);
  8968. }
  8969. /*==========================================
  8970. * パーティを作る
  8971. *------------------------------------------
  8972. */
  8973. void clif_parse_CreateParty2(int fd, struct map_session_data *sd) {
  8974. if(map[sd->bl.m].flag.partylock)
  8975. { //Guild locked.
  8976. clif_displaymessage(fd, msg_txt(227));
  8977. return;
  8978. }
  8979. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7){
  8980. RFIFOHEAD(fd);
  8981. party_create(sd,(char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27));
  8982. } else
  8983. clif_skill_fail(sd,1,0,4);
  8984. }
  8985. /*==========================================
  8986. * パーティに勧誘
  8987. *------------------------------------------
  8988. */
  8989. void clif_parse_PartyInvite(int fd, struct map_session_data *sd) {
  8990. struct map_session_data *t_sd;
  8991. RFIFOHEAD(fd);
  8992. if(map[sd->bl.m].flag.partylock)
  8993. { //Guild locked.
  8994. clif_displaymessage(fd, msg_txt(227));
  8995. return;
  8996. }
  8997. t_sd = map_id2sd(RFIFOL(fd,2));
  8998. // @noask [LuzZza]
  8999. if(t_sd && t_sd->state.noask) {
  9000. clif_noask_sub(sd, t_sd, 1);
  9001. return;
  9002. }
  9003. party_invite(sd, t_sd);
  9004. }
  9005. /*==========================================
  9006. * パーティ勧誘返答
  9007. *------------------------------------------
  9008. */
  9009. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd) {
  9010. RFIFOHEAD(fd);
  9011. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  9012. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9013. } else {
  9014. party_reply_invite(sd,RFIFOL(fd,2),-1);
  9015. clif_skill_fail(sd,1,0,4);
  9016. }
  9017. }
  9018. /*==========================================
  9019. * パーティ脱退要求
  9020. *------------------------------------------
  9021. */
  9022. void clif_parse_LeaveParty(int fd, struct map_session_data *sd) {
  9023. if(map[sd->bl.m].flag.partylock)
  9024. { //Guild locked.
  9025. clif_displaymessage(fd, msg_txt(227));
  9026. return;
  9027. }
  9028. party_leave(sd);
  9029. }
  9030. /*==========================================
  9031. * パーティ除名要求
  9032. *------------------------------------------
  9033. */
  9034. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd) {
  9035. RFIFOHEAD(fd);
  9036. if(map[sd->bl.m].flag.partylock)
  9037. { //Guild locked.
  9038. clif_displaymessage(fd, msg_txt(227));
  9039. return;
  9040. }
  9041. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  9042. }
  9043. /*==========================================
  9044. * パーティ設定変更要求
  9045. *------------------------------------------
  9046. */
  9047. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd) {
  9048. struct party_data *p;
  9049. RFIFOHEAD(fd);
  9050. if(!sd->status.party_id)
  9051. return;
  9052. p = party_search(sd->status.party_id);
  9053. if (!p) return;
  9054. //The client no longer can change the item-field, therefore it always
  9055. //comes as zero. Here, resend the item data as it is.
  9056. // party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  9057. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  9058. }
  9059. /*==========================================
  9060. * パーティメッセージ送信要求
  9061. *------------------------------------------
  9062. */
  9063. void clif_parse_PartyMessage(int fd, struct map_session_data *sd) {
  9064. char *mes;
  9065. int len;
  9066. RFIFOHEAD(fd);
  9067. len = RFIFOW(fd,2) - 4;
  9068. mes = RFIFOP(fd,4);
  9069. mes_len_check(mes, len, CHAT_SIZE);
  9070. if (is_charcommand(fd, sd, mes) != CharCommand_None ||
  9071. is_atcommand(fd, sd, mes) != AtCommand_None)
  9072. return;
  9073. if (sd->sc.count && (
  9074. sd->sc.data[SC_BERSERK].timer!=-1 ||
  9075. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)
  9076. ))
  9077. return;
  9078. if (battle_config.min_chat_delay)
  9079. { //[Skotlex]
  9080. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9081. return;
  9082. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9083. }
  9084. party_send_message(sd, mes, len);
  9085. }
  9086. /*==========================================
  9087. * 露店閉鎖
  9088. *------------------------------------------
  9089. */
  9090. void clif_parse_CloseVending(int fd, struct map_session_data *sd) {
  9091. vending_closevending(sd);
  9092. }
  9093. /*==========================================
  9094. * 露店アイテムリスト要求
  9095. *------------------------------------------
  9096. */
  9097. void clif_parse_VendingListReq(int fd, struct map_session_data *sd) {
  9098. RFIFOHEAD(fd);
  9099. vending_vendinglistreq(sd,RFIFOL(fd,2));
  9100. if(sd->npc_id)
  9101. npc_event_dequeue(sd);
  9102. }
  9103. /*==========================================
  9104. * 露店アイテム購入
  9105. *------------------------------------------
  9106. */
  9107. void clif_parse_PurchaseReq(int fd, struct map_session_data *sd) {
  9108. RFIFOHEAD(fd);
  9109. vending_purchasereq(sd, RFIFOW(fd,2), RFIFOL(fd,4), RFIFOP(fd,8));
  9110. }
  9111. /*==========================================
  9112. * 露店開設
  9113. *------------------------------------------
  9114. */
  9115. void clif_parse_OpenVending(int fd,struct map_session_data *sd) {
  9116. RFIFOHEAD(fd);
  9117. if (clif_trading(sd))
  9118. return;
  9119. if (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOROOM)
  9120. return;
  9121. vending_openvending(sd, RFIFOW(fd,2), (char*)RFIFOP(fd,4), RFIFOB(fd,84), RFIFOP(fd,85));
  9122. }
  9123. /*==========================================
  9124. * ギルドを作る
  9125. *------------------------------------------
  9126. */
  9127. void clif_parse_CreateGuild(int fd,struct map_session_data *sd) {
  9128. RFIFOHEAD(fd);
  9129. if(map[sd->bl.m].flag.guildlock)
  9130. { //Guild locked.
  9131. clif_displaymessage(fd, msg_txt(228));
  9132. return;
  9133. }
  9134. guild_create(sd, (char*)RFIFOP(fd,6));
  9135. }
  9136. /*==========================================
  9137. * ギルドマスターかどうか確認
  9138. *------------------------------------------
  9139. */
  9140. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd) {
  9141. clif_guild_masterormember(sd);
  9142. }
  9143. /*==========================================
  9144. * ギルド情報要求
  9145. *------------------------------------------
  9146. */
  9147. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd) {
  9148. RFIFOHEAD(fd);
  9149. if (!sd->status.guild_id) return;
  9150. switch(RFIFOL(fd,2)){
  9151. case 0: // ギルド基本情報、同盟敵対情報
  9152. clif_guild_basicinfo(sd);
  9153. clif_guild_allianceinfo(sd);
  9154. break;
  9155. case 1: // メンバーリスト、役職名リスト
  9156. clif_guild_positionnamelist(sd);
  9157. clif_guild_memberlist(sd);
  9158. break;
  9159. case 2: // 役職名リスト、役職情報リスト
  9160. clif_guild_positionnamelist(sd);
  9161. clif_guild_positioninfolist(sd);
  9162. break;
  9163. case 3: // スキルリスト
  9164. clif_guild_skillinfo(sd);
  9165. break;
  9166. case 4: // 追放リスト
  9167. clif_guild_expulsionlist(sd);
  9168. break;
  9169. default:
  9170. if (battle_config.error_log)
  9171. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  9172. break;
  9173. }
  9174. }
  9175. /*==========================================
  9176. * ギルド役職変更
  9177. *------------------------------------------
  9178. */
  9179. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd) {
  9180. int i;
  9181. RFIFOHEAD(fd);
  9182. if(!sd->state.gmaster_flag)
  9183. return;
  9184. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  9185. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  9186. }
  9187. }
  9188. /*==========================================
  9189. * ギルドメンバ役職変更
  9190. *------------------------------------------
  9191. */
  9192. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd) {
  9193. int i;
  9194. RFIFOHEAD(fd);
  9195. if(!sd->state.gmaster_flag)
  9196. return;
  9197. for(i=4;i<RFIFOW(fd,2);i+=12){
  9198. guild_change_memberposition(sd->status.guild_id,
  9199. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  9200. }
  9201. }
  9202. /*==========================================
  9203. * ギルドエンブレム要求
  9204. *------------------------------------------
  9205. */
  9206. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd) {
  9207. struct guild *g;
  9208. RFIFOHEAD(fd);
  9209. g=guild_search(RFIFOL(fd,2));
  9210. if(g!=NULL)
  9211. clif_guild_emblem(sd,g);
  9212. }
  9213. /*==========================================
  9214. * ギルドエンブレム変更
  9215. *------------------------------------------
  9216. */
  9217. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd) {
  9218. RFIFOHEAD(fd);
  9219. if(!sd->state.gmaster_flag)
  9220. return;
  9221. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  9222. }
  9223. /*==========================================
  9224. * ギルド告知変更
  9225. *------------------------------------------
  9226. */
  9227. void clif_parse_GuildChangeNotice(int fd,struct map_session_data *sd) {
  9228. RFIFOHEAD(fd);
  9229. if(!sd->state.gmaster_flag)
  9230. return;
  9231. // compensate for the client's double marker bug (in both strings)
  9232. if ((RFIFOB(fd, 6) == '|') && (RFIFOB(fd, 6+3) == '|')) {
  9233. memmove(RFIFOP(fd, 6+3), RFIFOP(fd, 6+6), 60-6); memset(RFIFOP(fd, 60-3), 0x00, 3); // drop the duplicate marker
  9234. }
  9235. if ((RFIFOB(fd, 66) == '|') && (RFIFOB(fd, 66+3) == '|')) {
  9236. memmove(RFIFOP(fd, 66+3), RFIFOP(fd, 66+6), 180-6); memset(RFIFOP(fd, 180-3), 0x00, 3); // drop the duplicate marker
  9237. }
  9238. // compensate for the client's adding of an extra space at the end of the message
  9239. if (RFIFOB(fd, 66) == '|') {
  9240. memset(RFIFOP(fd, 66 + strnlen(RFIFOP(fd, 66), 120)-1), 0x00, 1); // delete extra space at the end
  9241. }
  9242. guild_change_notice(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6),(char*)RFIFOP(fd,66));
  9243. }
  9244. /*==========================================
  9245. * ギルド勧誘
  9246. *------------------------------------------
  9247. */
  9248. void clif_parse_GuildInvite(int fd,struct map_session_data *sd) {
  9249. struct map_session_data *t_sd;
  9250. RFIFOHEAD(fd);
  9251. if(map[sd->bl.m].flag.guildlock)
  9252. { //Guild locked.
  9253. clif_displaymessage(fd, msg_txt(228));
  9254. return;
  9255. }
  9256. t_sd = map_id2sd(RFIFOL(fd,2));
  9257. // @noask [LuzZza]
  9258. if(t_sd && t_sd->state.noask) {
  9259. clif_noask_sub(sd, t_sd, 2);
  9260. return;
  9261. }
  9262. guild_invite(sd,t_sd);
  9263. }
  9264. /*==========================================
  9265. * ギルド勧誘返信
  9266. *------------------------------------------
  9267. */
  9268. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd) {
  9269. RFIFOHEAD(fd);
  9270. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9271. }
  9272. /*==========================================
  9273. * ギルド脱退
  9274. *------------------------------------------
  9275. */
  9276. void clif_parse_GuildLeave(int fd,struct map_session_data *sd) {
  9277. RFIFOHEAD(fd);
  9278. if(map[sd->bl.m].flag.guildlock)
  9279. { //Guild locked.
  9280. clif_displaymessage(fd, msg_txt(228));
  9281. return;
  9282. }
  9283. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9284. }
  9285. /*==========================================
  9286. * ギルド追放
  9287. *------------------------------------------
  9288. */
  9289. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd) {
  9290. RFIFOHEAD(fd);
  9291. if(map[sd->bl.m].flag.guildlock)
  9292. { //Guild locked.
  9293. clif_displaymessage(fd, msg_txt(228));
  9294. return;
  9295. }
  9296. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9297. }
  9298. /*==========================================
  9299. * ギルド会話
  9300. *------------------------------------------
  9301. */
  9302. void clif_parse_GuildMessage(int fd,struct map_session_data *sd) {
  9303. char *mes;
  9304. int len;
  9305. RFIFOHEAD(fd);
  9306. len = RFIFOW(fd,2) - 4;
  9307. mes = RFIFOP(fd,4);
  9308. mes_len_check(mes, len, CHAT_SIZE);
  9309. if (is_charcommand(fd, sd, mes) != CharCommand_None ||
  9310. is_atcommand(fd, sd, mes) != AtCommand_None)
  9311. return;
  9312. if (sd->sc.count && (
  9313. sd->sc.data[SC_BERSERK].timer!=-1 ||
  9314. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)
  9315. ))
  9316. return;
  9317. if (battle_config.min_chat_delay)
  9318. { //[Skotlex]
  9319. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9320. return;
  9321. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9322. }
  9323. guild_send_message(sd, mes, len);
  9324. }
  9325. /*==========================================
  9326. * ギルド同盟要求
  9327. *------------------------------------------
  9328. */
  9329. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd) {
  9330. struct map_session_data *t_sd;
  9331. RFIFOHEAD(fd);
  9332. if(!sd->state.gmaster_flag)
  9333. return;
  9334. if(map[sd->bl.m].flag.guildlock)
  9335. { //Guild locked.
  9336. clif_displaymessage(fd, msg_txt(228));
  9337. return;
  9338. }
  9339. t_sd = map_id2sd(RFIFOL(fd,2));
  9340. // @noask [LuzZza]
  9341. if(t_sd && t_sd->state.noask) {
  9342. clif_noask_sub(sd, t_sd, 3);
  9343. return;
  9344. }
  9345. guild_reqalliance(sd,t_sd);
  9346. }
  9347. /*==========================================
  9348. * ギルド同盟要求返信
  9349. *------------------------------------------
  9350. */
  9351. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd) {
  9352. RFIFOHEAD(fd);
  9353. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9354. }
  9355. /*==========================================
  9356. * ギルド関係解消
  9357. *------------------------------------------
  9358. */
  9359. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd) {
  9360. RFIFOHEAD(fd);
  9361. if(!sd->state.gmaster_flag)
  9362. return;
  9363. if(map[sd->bl.m].flag.guildlock)
  9364. { //Guild locked.
  9365. clif_displaymessage(fd, msg_txt(228));
  9366. return;
  9367. }
  9368. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9369. }
  9370. /*==========================================
  9371. * ギルド敵対
  9372. *------------------------------------------
  9373. */
  9374. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd) {
  9375. struct map_session_data *t_sd;
  9376. RFIFOHEAD(fd);
  9377. if(!sd->state.gmaster_flag)
  9378. return;
  9379. if(map[sd->bl.m].flag.guildlock)
  9380. { //Guild locked.
  9381. clif_displaymessage(fd, msg_txt(228));
  9382. return;
  9383. }
  9384. t_sd = map_id2sd(RFIFOL(fd,2));
  9385. // @noask [LuzZza]
  9386. if(t_sd && t_sd->state.noask) {
  9387. clif_noask_sub(sd, t_sd, 4);
  9388. return;
  9389. }
  9390. guild_opposition(sd,t_sd);
  9391. }
  9392. /*==========================================
  9393. * ギルド解散
  9394. *------------------------------------------
  9395. */
  9396. void clif_parse_GuildBreak(int fd, struct map_session_data *sd) {
  9397. RFIFOHEAD(fd);
  9398. if(map[sd->bl.m].flag.guildlock)
  9399. { //Guild locked.
  9400. clif_displaymessage(fd, msg_txt(228));
  9401. return;
  9402. }
  9403. guild_break(sd,(char*)RFIFOP(fd,2));
  9404. }
  9405. // pet
  9406. void clif_parse_PetMenu(int fd, struct map_session_data *sd) {
  9407. RFIFOHEAD(fd);
  9408. pet_menu(sd,RFIFOB(fd,2));
  9409. }
  9410. void clif_parse_CatchPet(int fd, struct map_session_data *sd) {
  9411. RFIFOHEAD(fd);
  9412. pet_catch_process2(sd,RFIFOL(fd,2));
  9413. }
  9414. void clif_parse_SelectEgg(int fd, struct map_session_data *sd) {
  9415. RFIFOHEAD(fd);
  9416. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_lv != -1)
  9417. return;
  9418. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9419. sd->menuskill_lv = sd->menuskill_id = 0;
  9420. }
  9421. void clif_parse_SendEmotion(int fd, struct map_session_data *sd) {
  9422. if(sd->pd) {
  9423. RFIFOHEAD(fd);
  9424. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9425. }
  9426. }
  9427. void clif_parse_ChangePetName(int fd, struct map_session_data *sd) {
  9428. RFIFOHEAD(fd);
  9429. pet_change_name(sd,(char*)RFIFOP(fd,2));
  9430. }
  9431. // Kick (right click menu for GM "(name) force to quit")
  9432. void clif_parse_GMKick(int fd, struct map_session_data *sd) {
  9433. struct block_list *target;
  9434. int tid,lv;
  9435. RFIFOHEAD(fd);
  9436. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9437. return;
  9438. if (pc_isGM(sd) >= (lv=get_atcommand_level(AtCommand_Kick)))
  9439. return;
  9440. tid = RFIFOL(fd,2);
  9441. target = map_id2bl(tid);
  9442. if (!target) {
  9443. clif_GM_kickack(sd, 0);
  9444. return;
  9445. }
  9446. switch (target->type) {
  9447. case BL_PC:
  9448. {
  9449. struct map_session_data *tsd = (struct map_session_data *)target;
  9450. if (pc_isGM(sd) <= pc_isGM(tsd)) {
  9451. clif_GM_kickack(sd, 0);
  9452. return;
  9453. }
  9454. clif_GM_kick(sd, tsd, 1);
  9455. if(log_config.gm && lv >= log_config.gm) {
  9456. char message[NAME_LENGTH+6];
  9457. sprintf(message, "/kick %d", tsd->status.char_id);
  9458. log_atcommand(sd, message);
  9459. }
  9460. break;
  9461. }
  9462. case BL_MOB:
  9463. status_percent_damage(&sd->bl, target, 100, 0);
  9464. if(log_config.gm && lv >= log_config.gm) {
  9465. char message[NAME_LENGTH+16];
  9466. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9467. log_atcommand(sd, message);
  9468. }
  9469. break;
  9470. default:
  9471. clif_GM_kickack(sd, 0);
  9472. }
  9473. }
  9474. /*==========================================
  9475. * /shift
  9476. *------------------------------------------
  9477. */
  9478. void clif_parse_Shift(int fd, struct map_session_data *sd) { // Rewriten by [Yor]
  9479. char *player_name;
  9480. int lv;
  9481. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9482. return;
  9483. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_JumpTo)))
  9484. return;
  9485. RFIFOHEAD(fd);
  9486. player_name = RFIFOP(fd,2);
  9487. player_name[NAME_LENGTH-1] = '\0';
  9488. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9489. if(log_config.gm && lv >= log_config.gm) {
  9490. char message[NAME_LENGTH+7];
  9491. sprintf(message, "/shift %s", player_name);
  9492. log_atcommand(sd, message);
  9493. }
  9494. return;
  9495. }
  9496. /*==========================================
  9497. * /recall
  9498. *------------------------------------------
  9499. */
  9500. void clif_parse_Recall(int fd, struct map_session_data *sd) { // Added by RoVeRT
  9501. char *player_name;
  9502. int lv;
  9503. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9504. return;
  9505. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_Recall)))
  9506. return;
  9507. RFIFOHEAD(fd);
  9508. player_name = RFIFOP(fd,2);
  9509. player_name[NAME_LENGTH-1] = '\0';
  9510. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9511. if(log_config.gm && lv >= log_config.gm) {
  9512. char message[NAME_LENGTH+8];
  9513. sprintf(message, "/recall %s", player_name);
  9514. log_atcommand(sd, message);
  9515. }
  9516. return;
  9517. }
  9518. /*==========================================
  9519. * /monster /item
  9520. *------------------------------------------
  9521. */
  9522. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd) {
  9523. char *monster_item_name;
  9524. char message[NAME_LENGTH+10]; //For logging.
  9525. int level;
  9526. RFIFOHEAD(fd);
  9527. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9528. return;
  9529. monster_item_name = RFIFOP(fd,2);
  9530. monster_item_name[NAME_LENGTH-1] = '\0';
  9531. if (mobdb_searchname(monster_item_name)) {
  9532. if (pc_isGM(sd) < (level=get_atcommand_level(AtCommand_Spawn)))
  9533. return;
  9534. atcommand_monster(fd, sd, "@spawn", monster_item_name); // as @spawn
  9535. if(log_config.gm && level >= log_config.gm)
  9536. { //Log action. [Skotlex]
  9537. snprintf(message, sizeof(message)-1, "@spawn %s", monster_item_name);
  9538. log_atcommand(sd, message);
  9539. }
  9540. return;
  9541. }
  9542. if (itemdb_searchname(monster_item_name) == NULL)
  9543. return;
  9544. if (pc_isGM(sd) < (level = get_atcommand_level(AtCommand_Item)))
  9545. return;
  9546. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9547. if(log_config.gm && level >= log_config.gm)
  9548. { //Log action. [Skotlex]
  9549. sprintf(message, "@item %s", monster_item_name);
  9550. log_atcommand(sd, message);
  9551. }
  9552. }
  9553. void clif_parse_GMHide(int fd, struct map_session_data *sd) { // Modified by [Yor]
  9554. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9555. return;
  9556. if (pc_isGM(sd) < get_atcommand_level(AtCommand_Hide))
  9557. return;
  9558. if (sd->sc.option & OPTION_INVISIBLE) {
  9559. sd->sc.option &= ~OPTION_INVISIBLE;
  9560. if (sd->disguise)
  9561. status_set_viewdata(&sd->bl, sd->disguise);
  9562. else
  9563. status_set_viewdata(&sd->bl, sd->status.class_);
  9564. clif_displaymessage(fd, "Invisible: Off.");
  9565. } else {
  9566. sd->sc.option |= OPTION_INVISIBLE;
  9567. sd->vd.class_ = INVISIBLE_CLASS;
  9568. clif_displaymessage(fd, "Invisible: On.");
  9569. if(log_config.gm && get_atcommand_level(AtCommand_Hide) >= log_config.gm)
  9570. log_atcommand(sd, "/hide");
  9571. }
  9572. clif_changeoption(&sd->bl);
  9573. }
  9574. /*==========================================
  9575. * GMによるチャット禁止時間付与
  9576. *------------------------------------------
  9577. */
  9578. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9579. {
  9580. int type, limit, level;
  9581. struct block_list *bl;
  9582. struct map_session_data *dstsd;
  9583. RFIFOHEAD(fd);
  9584. bl = map_id2bl(RFIFOL(fd,2));
  9585. if (!bl || bl->type != BL_PC)
  9586. return;
  9587. dstsd =(struct map_session_data *)bl;
  9588. type = RFIFOB(fd,6);
  9589. limit = RFIFOW(fd,7);
  9590. if (type == 0)
  9591. limit = 0 - limit;
  9592. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  9593. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  9594. if (type == 2/* && sd->bl.id != dstsd->bl.id*/)
  9595. return;
  9596. if (
  9597. ((level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(AtCommand_Mute))
  9598. || (type == 2 && !level)) {
  9599. clif_GM_silence(sd, dstsd, ((type == 2) ? 1 : type));
  9600. dstsd->status.manner -= limit;
  9601. if(dstsd->status.manner < 0)
  9602. sc_start(bl,SC_NOCHAT,100,0,0);
  9603. else
  9604. {
  9605. dstsd->status.manner = 0;
  9606. status_change_end(bl,SC_NOCHAT,-1);
  9607. }
  9608. }
  9609. return;
  9610. }
  9611. /*==========================================
  9612. * GMによるチャット禁止時間参照(?)
  9613. *------------------------------------------
  9614. */
  9615. void clif_parse_GMReqNoChatCount(int fd, struct map_session_data *sd)
  9616. {
  9617. int tid;
  9618. RFIFOHEAD(fd);
  9619. tid = RFIFOL(fd,2);
  9620. WFIFOHEAD(fd,packet_len(0x1e0));
  9621. WFIFOW(fd,0) = 0x1e0;
  9622. WFIFOL(fd,2) = tid;
  9623. sprintf((char*)WFIFOP(fd,6),"%d",tid);
  9624. // memcpy(WFIFOP(fd,6), "TESTNAME", 24);
  9625. WFIFOSET(fd, packet_len(0x1e0));
  9626. return;
  9627. }
  9628. static int pstrcmp(const void *a, const void *b)
  9629. {
  9630. char *name1 = (char *)a;
  9631. char *name2 = (char *)b;
  9632. if (name1[0] && name2[0])
  9633. return strcmp(name1, name2);
  9634. //Since names are sorted in ascending order, send blank entries to the bottom.
  9635. if (name1[0])
  9636. return -1;
  9637. if (name2[0])
  9638. return 1;
  9639. return 0;
  9640. }
  9641. void clif_parse_PMIgnore(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9642. char output[512];
  9643. char *nick; // S 00cf <nick>.24B <type>.B: 00 (/ex nick) deny speech from nick, 01 (/in nick) allow speech from nick
  9644. int i;
  9645. WFIFOHEAD(fd,packet_len(0xd1));
  9646. RFIFOHEAD(fd);
  9647. memset(output, '\0', sizeof(output));
  9648. nick = (char*)RFIFOP(fd,2); // speed up
  9649. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name have at maximum 23 characters
  9650. WFIFOW(fd,0) = 0x0d1; // R 00d1 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9651. WFIFOB(fd,2) = RFIFOB(fd,26);
  9652. // deny action (we add nick only if it's not already exist
  9653. if (RFIFOB(fd,26) == 0) { // Add block
  9654. for(i = 0; i < MAX_IGNORE_LIST &&
  9655. sd->ignore[i].name[0] != '\0' &&
  9656. strcmp(sd->ignore[i].name, nick) != 0
  9657. ; i++);
  9658. if (i == MAX_IGNORE_LIST) { //Full List
  9659. WFIFOB(fd,3) = 1; // fail
  9660. WFIFOSET(fd, packet_len(0x0d1));
  9661. if (strcmp(wisp_server_name, nick) == 0)
  9662. { // to found possible bot users who automaticaly ignore people.
  9663. 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);
  9664. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9665. }
  9666. return;
  9667. }
  9668. if(sd->ignore[i].name[0] != '\0')
  9669. { //Name already exists.
  9670. WFIFOB(fd,3) = 0; // Aegis reports success.
  9671. WFIFOSET(fd, packet_len(0x0d1));
  9672. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9673. 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);
  9674. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9675. }
  9676. return;
  9677. }
  9678. //Insert in position i
  9679. memcpy(sd->ignore[i].name, nick, NAME_LENGTH-1);
  9680. WFIFOB(fd,3) = 0; // success
  9681. WFIFOSET(fd, packet_len(0x0d1));
  9682. if (strcmp(wisp_server_name, nick) == 0)
  9683. { // to found possible bot users who automaticaly ignore people.
  9684. 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);
  9685. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9686. // send something to be inform and force bot to ignore twice... If GM receiving block + block again, it's a bot :)
  9687. clif_wis_message(fd, wisp_server_name,
  9688. "Adding me in your ignore list will not block my wisps.",
  9689. strlen("Adding me in your ignore list will not block my wisps.") + 1);
  9690. }
  9691. //Sort the ignore list.
  9692. qsort (sd->ignore[0].name, MAX_IGNORE_LIST, sizeof(sd->ignore[0].name), pstrcmp);
  9693. return;
  9694. }
  9695. //Remove name
  9696. for(i = 0; i < MAX_IGNORE_LIST &&
  9697. sd->ignore[i].name[0] != '\0' &&
  9698. strcmp(sd->ignore[i].name, nick) != 0
  9699. ; i++);
  9700. if (i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0')
  9701. { //Not found
  9702. WFIFOB(fd,3) = 1; // fail
  9703. WFIFOSET(fd, packet_len(0x0d1));
  9704. return;
  9705. }
  9706. //Move everything one place down to overwrite removed entry.
  9707. memmove(sd->ignore[i].name, sd->ignore[i+1].name,
  9708. (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  9709. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  9710. // success
  9711. WFIFOB(fd,3) = 0;
  9712. WFIFOSET(fd, packet_len(0x0d1));
  9713. // for debug only
  9714. // for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++) /
  9715. // ShowDebug("Ignored player: '%s'\n", sd->ignore[i].name);
  9716. return;
  9717. }
  9718. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9719. //printf("Ignore all: state: %d\n", RFIFOB(fd,2));
  9720. RFIFOHEAD(fd);
  9721. WFIFOHEAD(fd,packet_len(0xd2));
  9722. // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9723. // S 00d0 <type>len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech
  9724. WFIFOW(fd,0) = 0x0d2;
  9725. WFIFOB(fd,2) = RFIFOB(fd,2);
  9726. if (RFIFOB(fd,2) == 0) { //Deny all
  9727. if (sd->state.ignoreAll) {
  9728. WFIFOB(fd,3) = 1; // fail
  9729. WFIFOSET(fd, packet_len(0x0d2));
  9730. return;
  9731. }
  9732. sd->state.ignoreAll = 1;
  9733. WFIFOB(fd,3) = 0; // success
  9734. WFIFOSET(fd, packet_len(0x0d2));
  9735. return;
  9736. }
  9737. //Unblock everyone
  9738. if (!sd->state.ignoreAll) {
  9739. if (sd->ignore[0].name[0] != '\0')
  9740. { //Wipe the ignore list.
  9741. memset(sd->ignore, 0, sizeof(sd->ignore));
  9742. WFIFOB(fd,3) = 0;
  9743. WFIFOSET(fd, packet_len(0x0d2));
  9744. return;
  9745. }
  9746. WFIFOB(fd,3) = 1; // fail
  9747. WFIFOSET(fd, packet_len(0x0d2));
  9748. return;
  9749. }
  9750. sd->state.ignoreAll = 0;
  9751. WFIFOB(fd,3) = 0; // success
  9752. WFIFOSET(fd, packet_len(0x0d2));
  9753. return;
  9754. }
  9755. /*==========================================
  9756. * Wis拒否リスト
  9757. *------------------------------------------
  9758. */
  9759. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9760. {
  9761. int i;
  9762. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  9763. WFIFOW(fd,0) = 0xd4;
  9764. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9765. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  9766. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  9767. WFIFOSET(fd, WFIFOW(fd,2));
  9768. return;
  9769. }
  9770. /*==========================================
  9771. * スパノビの/doridoriによるSPR2倍
  9772. *------------------------------------------
  9773. */
  9774. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd) {
  9775. if (sd->state.doridori) return;
  9776. switch (sd->class_&MAPID_UPPERMASK)
  9777. {
  9778. case MAPID_SOUL_LINKER:
  9779. case MAPID_STAR_GLADIATOR:
  9780. case MAPID_TAEKWON:
  9781. if (!sd->state.rest)
  9782. break;
  9783. case MAPID_SUPER_NOVICE:
  9784. sd->state.doridori=1;
  9785. break;
  9786. }
  9787. return;
  9788. }
  9789. /*==========================================
  9790. * スパノビの爆裂波動
  9791. *------------------------------------------
  9792. */
  9793. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9794. {
  9795. if(sd){
  9796. int nextbaseexp=pc_nextbaseexp(sd);
  9797. if (battle_config.etc_log){
  9798. if(nextbaseexp != 0)
  9799. 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));
  9800. else
  9801. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9802. }
  9803. 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){
  9804. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9805. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  9806. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9807. }
  9808. }
  9809. return;
  9810. }
  9811. // random notes:
  9812. // 0x214: monster/player info ?
  9813. /*==========================================
  9814. * Friends List
  9815. *------------------------------------------
  9816. */
  9817. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9818. { //Toggles a single friend online/offline [Skotlex]
  9819. int i, fd = sd->fd;
  9820. //Seek friend.
  9821. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9822. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9823. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9824. return; //Not found
  9825. WFIFOHEAD(fd,packet_len(0x206));
  9826. WFIFOW(fd, 0) = 0x206;
  9827. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  9828. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  9829. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9830. WFIFOSET(fd, packet_len(0x206));
  9831. }
  9832. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9833. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9834. {
  9835. int account_id, char_id, online;
  9836. account_id = va_arg(ap, int);
  9837. char_id = va_arg(ap, int);
  9838. online = va_arg(ap, int);
  9839. clif_friendslist_toggle(sd, account_id, char_id, online);
  9840. return 0;
  9841. }
  9842. //For sending the whole friends list.
  9843. void clif_friendslist_send(struct map_session_data *sd) {
  9844. int i = 0, n, fd = sd->fd;
  9845. // Send friends list
  9846. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  9847. WFIFOW(fd, 0) = 0x201;
  9848. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9849. {
  9850. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9851. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9852. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9853. }
  9854. if (i) {
  9855. WFIFOW(fd,2) = 4 + 32 * i;
  9856. WFIFOSET(fd, WFIFOW(fd,2));
  9857. }
  9858. for (n = 0; n < i; n++)
  9859. { //Sending the online players
  9860. if (map_charid2sd(sd->status.friends[n].char_id))
  9861. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9862. }
  9863. }
  9864. // Status for adding friend - 0: successfull 1: not exist/rejected 2: over limit
  9865. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9866. {
  9867. int fd;
  9868. nullpo_retv(sd);
  9869. fd = sd->fd;
  9870. WFIFOHEAD(fd,packet_len(0x209));
  9871. WFIFOW(fd,0) = 0x209;
  9872. WFIFOW(fd,2) = type;
  9873. if (f_sd)
  9874. {
  9875. WFIFOW(fd,4) = f_sd->status.account_id;
  9876. WFIFOW(fd,8) = f_sd->status.char_id;
  9877. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9878. }
  9879. WFIFOSET(fd, packet_len(0x209));
  9880. }
  9881. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd) {
  9882. struct map_session_data *f_sd;
  9883. int i, f_fd;
  9884. RFIFOHEAD(fd);
  9885. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9886. // Friend doesn't exist (no player with this name)
  9887. if (f_sd == NULL) {
  9888. clif_displaymessage(fd, msg_txt(3));
  9889. return;
  9890. }
  9891. // @noask [LuzZza]
  9892. if(f_sd->state.noask) {
  9893. clif_noask_sub(sd, f_sd, 5);
  9894. return;
  9895. }
  9896. // Friend already exists
  9897. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9898. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9899. clif_displaymessage(fd, "Friend already exists.");
  9900. return;
  9901. }
  9902. }
  9903. if (i == MAX_FRIENDS) {
  9904. //No space, list full.
  9905. clif_friendslist_reqack(sd, f_sd, 2);
  9906. return;
  9907. }
  9908. f_fd = f_sd->fd;
  9909. WFIFOHEAD(f_fd,packet_len(0x207));
  9910. WFIFOW(f_fd,0) = 0x207;
  9911. WFIFOL(f_fd,2) = sd->status.account_id;
  9912. WFIFOL(f_fd,6) = sd->status.char_id;
  9913. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9914. WFIFOSET(f_fd, packet_len(0x207));
  9915. return;
  9916. }
  9917. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd) {
  9918. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9919. struct map_session_data *f_sd;
  9920. int char_id, account_id;
  9921. char reply;
  9922. RFIFOHEAD(fd);
  9923. account_id = RFIFOL(fd,2);
  9924. char_id = RFIFOL(fd,6);
  9925. reply = RFIFOB(fd,10);
  9926. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9927. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9928. if (f_sd == NULL)
  9929. return;
  9930. if (reply == 0)
  9931. clif_friendslist_reqack(f_sd, sd, 1);
  9932. else {
  9933. int i;
  9934. // Find an empty slot
  9935. for (i = 0; i < MAX_FRIENDS; i++)
  9936. if (f_sd->status.friends[i].char_id == 0)
  9937. break;
  9938. if (i == MAX_FRIENDS) {
  9939. clif_friendslist_reqack(f_sd, sd, 2);
  9940. return;
  9941. }
  9942. f_sd->status.friends[i].account_id = sd->status.account_id;
  9943. f_sd->status.friends[i].char_id = sd->status.char_id;
  9944. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9945. clif_friendslist_reqack(f_sd, sd, 0);
  9946. if (battle_config.friend_auto_add) {
  9947. // Also add f_sd to sd's friendlist.
  9948. for (i = 0; i < MAX_FRIENDS; i++) {
  9949. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  9950. return; //No need to add anything.
  9951. if (sd->status.friends[i].char_id == 0)
  9952. break;
  9953. }
  9954. if (i == MAX_FRIENDS) {
  9955. clif_friendslist_reqack(sd, f_sd, 2);
  9956. return;
  9957. }
  9958. sd->status.friends[i].account_id = f_sd->status.account_id;
  9959. sd->status.friends[i].char_id = f_sd->status.char_id;
  9960. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  9961. clif_friendslist_reqack(sd, f_sd, 0);
  9962. }
  9963. }
  9964. return;
  9965. }
  9966. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd) {
  9967. // 0x203 </o> <ID to be removed W 4B>
  9968. int account_id, char_id;
  9969. int i, j;
  9970. RFIFOHEAD(fd);
  9971. account_id = RFIFOL(fd,2);
  9972. char_id = RFIFOL(fd,6);
  9973. // Search friend
  9974. for (i = 0; i < MAX_FRIENDS &&
  9975. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9976. if (i == MAX_FRIENDS) {
  9977. clif_displaymessage(fd, "Name not found in list.");
  9978. return;
  9979. }
  9980. // move all chars down
  9981. for(j = i + 1; j < MAX_FRIENDS; j++)
  9982. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9983. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9984. clif_displaymessage(fd, "Friend removed");
  9985. WFIFOHEAD(fd,packet_len(0x20a));
  9986. WFIFOW(fd,0) = 0x20a;
  9987. WFIFOL(fd,2) = account_id;
  9988. WFIFOL(fd,6) = char_id;
  9989. WFIFOSET(fd, packet_len(0x20a));
  9990. // clif_friendslist_send(sd); //This is not needed anymore.
  9991. return;
  9992. }
  9993. /*==========================================
  9994. * /killall
  9995. *------------------------------------------
  9996. */
  9997. void clif_parse_GMKillAll(int fd,struct map_session_data *sd)
  9998. {
  9999. char message[50];
  10000. strncpy(message,sd->status.name, NAME_LENGTH);
  10001. is_atcommand(fd, sd, strcat(message," : @kickall"));
  10002. return;
  10003. }
  10004. /*==========================================
  10005. * /pvpinfo
  10006. *------------------------------------------
  10007. */
  10008. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  10009. {
  10010. WFIFOHEAD(fd,packet_len(0x210));
  10011. WFIFOW(fd,0) = 0x210;
  10012. //WFIFOL(fd,2) = 0; // not sure what for yet
  10013. //WFIFOL(fd,6) = 0;
  10014. WFIFOL(fd,10) = sd->pvp_won; // times won
  10015. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  10016. WFIFOL(fd,18) = sd->pvp_point;
  10017. WFIFOSET(fd, packet_len(0x210));
  10018. return;
  10019. }
  10020. /*==========================================
  10021. * /blacksmith
  10022. *------------------------------------------
  10023. */
  10024. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  10025. {
  10026. int i;
  10027. char *name;
  10028. WFIFOHEAD(fd,packet_len(0x219));
  10029. WFIFOW(fd,0) = 0x219;
  10030. //Packet size limits this list to 10 elements. [Skotlex]
  10031. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10032. if (smith_fame_list[i].id > 0) {
  10033. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  10034. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  10035. {
  10036. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  10037. } else
  10038. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  10039. } else
  10040. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  10041. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  10042. }
  10043. for(;i < 10; i++) { //In case the MAX is less than 10.
  10044. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  10045. WFIFOL(fd, 242 + i * 4) = 0;
  10046. }
  10047. WFIFOSET(fd, packet_len(0x219));
  10048. }
  10049. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  10050. {
  10051. int fd = sd->fd;
  10052. WFIFOHEAD(fd,packet_len(0x21b));
  10053. WFIFOW(fd,0) = 0x21b;
  10054. WFIFOL(fd,2) = points;
  10055. WFIFOL(fd,6) = sd->status.fame;
  10056. WFIFOSET(fd, packet_len(0x21b));
  10057. return 0;
  10058. }
  10059. /*==========================================
  10060. * /alchemist
  10061. *------------------------------------------
  10062. */
  10063. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  10064. {
  10065. int i;
  10066. char *name;
  10067. WFIFOHEAD(fd,packet_len(0x21a));
  10068. WFIFOW(fd,0) = 0x21a;
  10069. //Packet size limits this list to 10 elements. [Skotlex]
  10070. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10071. if (chemist_fame_list[i].id > 0) {
  10072. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  10073. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  10074. {
  10075. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10076. } else
  10077. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  10078. } else
  10079. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10080. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  10081. }
  10082. for(;i < 10; i++) { //In case the MAX is less than 10.
  10083. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  10084. WFIFOL(fd, 242 + i * 4) = 0;
  10085. }
  10086. WFIFOSET(fd, packet_len(0x21a));
  10087. }
  10088. int clif_fame_alchemist(struct map_session_data *sd, int points)
  10089. {
  10090. int fd = sd->fd;
  10091. WFIFOHEAD(fd,packet_len(0x21c));
  10092. WFIFOW(fd,0) = 0x21c;
  10093. WFIFOL(fd,2) = points;
  10094. WFIFOL(fd,6) = sd->status.fame;
  10095. WFIFOSET(fd, packet_len(0x21c));
  10096. return 0;
  10097. }
  10098. /*==========================================
  10099. * /taekwon
  10100. *------------------------------------------
  10101. */
  10102. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  10103. {
  10104. int i;
  10105. char *name;
  10106. WFIFOHEAD(fd,packet_len(0x226));
  10107. WFIFOW(fd,0) = 0x226;
  10108. //Packet size limits this list to 10 elements. [Skotlex]
  10109. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10110. if (taekwon_fame_list[i].id > 0) {
  10111. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  10112. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  10113. {
  10114. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10115. } else
  10116. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  10117. } else
  10118. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10119. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  10120. }
  10121. for(;i < 10; i++) { //In case the MAX is less than 10.
  10122. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  10123. WFIFOL(fd, 242 + i * 4) = 0;
  10124. }
  10125. WFIFOSET(fd, packet_len(0x226));
  10126. }
  10127. int clif_fame_taekwon(struct map_session_data *sd, int points)
  10128. {
  10129. int fd = sd->fd;
  10130. WFIFOHEAD(fd,packet_len(0x224));
  10131. WFIFOW(fd,0) = 0x224;
  10132. WFIFOL(fd,2) = points;
  10133. WFIFOL(fd,6) = sd->status.fame;
  10134. WFIFOSET(fd, packet_len(0x224));
  10135. return 0;
  10136. }
  10137. /*==========================================
  10138. * PK Ranking table?
  10139. *------------------------------------------
  10140. */
  10141. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  10142. {
  10143. int i;
  10144. WFIFOHEAD(fd,packet_len(0x238));
  10145. WFIFOW(fd,0) = 0x238;
  10146. for(i=0;i<10;i++){
  10147. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  10148. WFIFOL(fd,i*4+242) = 0;
  10149. }
  10150. WFIFOSET(fd, packet_len(0x238));
  10151. return;
  10152. }
  10153. /*==========================================
  10154. * SG Feel save OK [Komurka]
  10155. *------------------------------------------
  10156. */
  10157. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  10158. {
  10159. char feel_var[3][NAME_LENGTH] = {"PC_FEEL_SUN","PC_FEEL_MOON","PC_FEEL_STAR"};
  10160. int i;
  10161. if (sd->menuskill_id != SG_FEEL)
  10162. return;
  10163. i = sd->menuskill_lv-1;
  10164. if (i<0 || i > 2) return; //Bug?
  10165. sd->feel_map[i].index = map[sd->bl.m].index;
  10166. sd->feel_map[i].m = sd->bl.m;
  10167. pc_setglobalreg(sd,feel_var[i],map[sd->bl.m].index);
  10168. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  10169. // clif_misceffect2(&sd->bl, 0x1b0);
  10170. // clif_misceffect2(&sd->bl, 0x21f);
  10171. clif_feel_info(sd, i, 0);
  10172. sd->menuskill_lv = sd->menuskill_id = 0;
  10173. }
  10174. /*==========================================
  10175. * Question about Star Glaldiator save map [Komurka]
  10176. *------------------------------------------
  10177. */
  10178. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv) {
  10179. WFIFOHEAD(fd,packet_len(0x253));
  10180. WFIFOW(fd,0)=0x253;
  10181. WFIFOSET(fd, packet_len(0x253));
  10182. sd->menuskill_id=SG_FEEL;
  10183. sd->menuskill_lv=skilllv;
  10184. }
  10185. void clif_parse_AdoptRequest(int fd,struct map_session_data *sd) {
  10186. //TODO: add somewhere the adopt code, checks for exploits, etc, etc.
  10187. //Missing packets are the client's reply packets to the adopt request one.
  10188. //[Skotlex]
  10189. int account_id;
  10190. struct map_session_data *sd2;
  10191. RFIFOHEAD(fd);
  10192. account_id = RFIFOL(fd,2);
  10193. sd2 = map_id2sd(account_id);
  10194. if(sd2 && sd2->fd && sd2 != sd && sd2->status.party_id == sd->status.party_id) { //FIXME: No checks whatsoever are in place yet!
  10195. fd = sd2->fd;
  10196. WFIFOHEAD(fd,packet_len(0x1f9));
  10197. WFIFOW(fd,0)=0x1f9;
  10198. WFIFOSET(fd, packet_len(0x1f9));
  10199. }
  10200. }
  10201. /*==========================================
  10202. * Homunculus packets
  10203. *------------------------------------------
  10204. */
  10205. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd) {
  10206. RFIFOHEAD(fd);
  10207. merc_hom_change_name(sd,RFIFOP(fd,2));
  10208. }
  10209. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd) { //[orn]
  10210. nullpo_retv(sd);
  10211. if(!merc_is_hom_active(sd->hd))
  10212. return;
  10213. unit_walktoxy(&sd->hd->bl, sd->bl.x,sd->bl.y-1, 4);
  10214. }
  10215. void clif_parse_HomMoveTo(int fd,struct map_session_data *sd) { //[orn]
  10216. int x,y,cmd;
  10217. RFIFOHEAD(fd);
  10218. nullpo_retv(sd);
  10219. if(!merc_is_hom_active(sd->hd))
  10220. return;
  10221. cmd = RFIFOW(fd,0);
  10222. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  10223. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  10224. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  10225. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  10226. unit_walktoxy(&(sd->hd->bl),x,y,4);
  10227. }
  10228. void clif_parse_HomAttack(int fd,struct map_session_data *sd) { //[orn]
  10229. RFIFOHEAD(fd);
  10230. if(!merc_is_hom_active(sd->hd))
  10231. return;
  10232. unit_attack(&sd->hd->bl,RFIFOL(fd,6),0) ;
  10233. }
  10234. void clif_parse_HomMenu(int fd, struct map_session_data *sd) { //[orn]
  10235. int cmd;
  10236. RFIFOHEAD(fd);
  10237. cmd = RFIFOW(fd,0);
  10238. if(!merc_is_hom_active(sd->hd))
  10239. return;
  10240. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  10241. }
  10242. /*==========================================
  10243. * パケットデバッグ
  10244. *------------------------------------------
  10245. */
  10246. void clif_parse_debug(int fd,struct map_session_data *sd)
  10247. {
  10248. int i, cmd, len;
  10249. RFIFOHEAD(fd);
  10250. cmd = RFIFOW(fd,0);
  10251. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  10252. ShowDebug("packet debug 0x%4X\n",cmd);
  10253. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10254. for(i=0;i<len;i++){
  10255. if((i&15)==0)
  10256. printf("\n%04X ",i);
  10257. printf("%02X ",RFIFOB(fd,i));
  10258. }
  10259. printf("\n");
  10260. }
  10261. /*==========================================
  10262. * クライアントからのパケット解析
  10263. * socket.cのdo_parsepacketから呼び出される
  10264. *------------------------------------------
  10265. */
  10266. int clif_parse(int fd) {
  10267. int packet_len = 0, cmd, packet_ver, err, dump = 0;
  10268. TBL_PC *sd;
  10269. RFIFOHEAD(fd);
  10270. if (fd <= 0)
  10271. { //Just in case, there are some checks for this later down below anyway which should be removed. [Skotlex]
  10272. ShowError("clif_parse: Received invalid session %d\n", fd);
  10273. return 0;
  10274. }
  10275. sd = (TBL_PC *)session[fd]->session_data;
  10276. if (session[fd]->eof) {
  10277. if (sd) {
  10278. if (sd->state.autotrade) {
  10279. //Disassociate character from the socket connection.
  10280. session[fd]->session_data = NULL;
  10281. sd->fd = 0;
  10282. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n",
  10283. (pc_isGM(sd))?"GM ":"",sd->status.name);
  10284. } else
  10285. if (sd->state.auth) {
  10286. // Player logout display [Valaris]
  10287. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n",
  10288. (pc_isGM(sd))?"GM ":"",sd->status.name);
  10289. clif_quitsave(fd, sd);
  10290. } else {
  10291. ShowInfo("Player AID:%d/CID:%d (not authenticated) logged off.\n",
  10292. sd->bl.id, sd->status.char_id);
  10293. map_quit(sd);
  10294. }
  10295. } else {
  10296. unsigned char *ip = (unsigned char *) &session[fd]->client_addr.sin_addr;
  10297. ShowInfo("Closed connection from '"CL_WHITE"%d.%d.%d.%d"CL_RESET"'.\n", ip[0],ip[1],ip[2],ip[3]);
  10298. }
  10299. do_close(fd);
  10300. return 0;
  10301. }
  10302. if (RFIFOREST(fd) < 2)
  10303. return 0;
  10304. // printf("clif_parse: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
  10305. cmd = RFIFOW(fd,0);
  10306. // get packet version before to parse
  10307. packet_ver = 0;
  10308. if (sd) {
  10309. packet_ver = sd->packet_ver;
  10310. if (packet_ver < 0 || packet_ver > MAX_PACKET_VER) { // This should never happen unless we have some corrupted memory issues :X [Skotlex]
  10311. ShowWarning("clif_parse: Disconnecting session #%d (AID:%d/CID:%d) for having invalid packet_ver=%d.", fd, sd->status.account_id, sd->status.char_id, packet_ver);
  10312. session[fd]->eof = 1;
  10313. return 0;
  10314. }
  10315. } else {
  10316. // check authentification packet to know packet version
  10317. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  10318. if( err )
  10319. {// failed to identify packet version
  10320. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  10321. err == 1 ? "" :
  10322. err == 2 ? ", possibly for having an invalid account_id" :
  10323. err == 3 ? ", possibly for having an invalid char_id." :
  10324. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  10325. err == 4 ? ", possibly for having an invalid login_id1." :
  10326. err == 5 ? ", possibly for having an invalid client_tick." :
  10327. */
  10328. err == 6 ? ", possibly for having an invalid sex." :
  10329. ". ERROR invalid error code"));
  10330. WFIFOHEAD(fd,packet_len(0x6a));
  10331. WFIFOW(fd,0) = 0x6a;
  10332. WFIFOB(fd,2) = 3; // Rejected from Server
  10333. WFIFOSET(fd,packet_len(0x6a));
  10334. RFIFOSKIP(fd, RFIFOREST(fd));
  10335. clif_setwaitclose(fd);
  10336. /*
  10337. //## TODO check if it still doesn't send and why. [FlavioJS]
  10338. if (session[fd]->func_send) //socket.c doesn't wants to send the data when left on it's own... [Skotlex]
  10339. session[fd]->func_send(fd);
  10340. */
  10341. return 0;
  10342. }
  10343. }
  10344. // ゲーム用以外パケットか、認証を終える前に0072以外が来たら、切断する
  10345. 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
  10346. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  10347. session[fd]->eof = 1;
  10348. return 0;
  10349. }
  10350. // パケット長を計算
  10351. packet_len = packet_db[packet_ver][cmd].len;
  10352. if (packet_len == -1) {
  10353. if (RFIFOREST(fd) < 4)
  10354. return 0; // 可変長パケットで長さの所までデータが来てない
  10355. packet_len = RFIFOW(fd,2);
  10356. if (packet_len < 4 || packet_len > 32768) {
  10357. ShowWarning("clif_parse: Packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  10358. session[fd]->eof =1;
  10359. return 0;
  10360. }
  10361. }
  10362. if ((int)RFIFOREST(fd) < packet_len)
  10363. return 0; // まだ1パケット分データが揃ってない
  10364. #if DUMP_ALL_PACKETS
  10365. {
  10366. int i;
  10367. FILE *fp;
  10368. char packet_txt[256] = "save/packet.txt";
  10369. time_t now;
  10370. dump = 1;
  10371. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10372. ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
  10373. return 1;
  10374. } else {
  10375. time(&now);
  10376. if (sd && sd->state.auth) {
  10377. if (sd->status.name != NULL)
  10378. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent packet:\n",
  10379. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10380. else
  10381. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10382. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10383. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10384. fprintf(fp, "\tsession #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10385. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10386. for(i = 0; i < packet_len; i++) {
  10387. if ((i & 15) == 0)
  10388. fprintf(fp, "\n\t%04X ", i);
  10389. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10390. }
  10391. fprintf(fp, "\n\n");
  10392. fclose(fp);
  10393. }
  10394. }
  10395. #endif
  10396. if (sd && sd->state.waitingdisconnect == 1) {
  10397. // 切断待ちの場合パケットを処理しない
  10398. } else if (packet_db[packet_ver][cmd].func) {
  10399. if (sd && sd->bl.prev == NULL &&
  10400. packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck)
  10401. ; //Only valid packet when player is not on a map is the finish-loading packet.
  10402. else
  10403. if (sd
  10404. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  10405. || packet_db[packet_ver][cmd].func == clif_parse_debug
  10406. ) //Only execute the function when there's an sd (except for debug/wanttoconnect packets)
  10407. packet_db[packet_ver][cmd].func(fd, sd);
  10408. }
  10409. #if DUMP_UNKNOWN_PACKET
  10410. else if (battle_config.error_log)
  10411. {
  10412. int i;
  10413. FILE *fp;
  10414. char packet_txt[256] = "save/packet.txt";
  10415. time_t now;
  10416. dump = 1;
  10417. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10418. ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
  10419. return 1;
  10420. } else {
  10421. time(&now);
  10422. if (sd && sd->state.auth) {
  10423. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  10424. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10425. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10426. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10427. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10428. for(i = 0; i < packet_len; i++) {
  10429. if ((i & 15) == 0)
  10430. fprintf(fp, "\n\t%04X ", i);
  10431. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10432. }
  10433. fprintf(fp, "\n\n");
  10434. fclose(fp);
  10435. }
  10436. }
  10437. #endif
  10438. if (dump) {
  10439. int i;
  10440. if (fd)
  10441. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10442. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10443. for(i = 0; i < packet_len; i++) {
  10444. if ((i & 15) == 0)
  10445. printf("\n%04X ",i);
  10446. printf("%02X ", RFIFOB(fd,i));
  10447. }
  10448. printf("\n");
  10449. if (sd && sd->state.auth) {
  10450. if (sd->status.name != NULL)
  10451. printf("\nAccount ID %d, character ID %d, player name %s.\n",
  10452. sd->status.account_id, sd->status.char_id, sd->status.name);
  10453. else
  10454. printf("\nAccount ID %d.\n", sd->bl.id);
  10455. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10456. printf("\nAccount ID %d.\n", sd->bl.id);
  10457. }
  10458. RFIFOSKIP(fd, packet_len);
  10459. return 0;
  10460. }
  10461. /*==========================================
  10462. * パケットデータベース読み込み
  10463. *------------------------------------------
  10464. */
  10465. static int packetdb_readdb(void)
  10466. {
  10467. FILE *fp;
  10468. char line[1024];
  10469. int ln=0;
  10470. int cmd,i,j,k,packet_ver;
  10471. int max_cmd=-1;
  10472. int skip_ver = 0;
  10473. int warned = 0;
  10474. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  10475. int packet_len_table[0x260] = {
  10476. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10480. //#0x0040
  10481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10483. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  10484. #if PACKETVER < 2
  10485. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  10486. #else // 78-7b 亀島以降 lv99エフェクト用
  10487. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  10488. #endif
  10489. //#0x0080
  10490. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  10491. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  10492. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  10493. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  10494. //#0x00C0
  10495. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  10496. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  10497. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  10498. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  10499. //#0x0100
  10500. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  10501. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  10502. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  10503. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  10504. //#0x0140
  10505. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  10506. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  10507. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  10508. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  10509. //#0x0180
  10510. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  10511. #if PACKETVER < 1
  10512. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10513. #else // 196 comodo以降 状態表示アイコン用
  10514. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10515. #endif
  10516. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  10517. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  10518. //#0x01C0, Set 0x1d5=-1
  10519. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  10520. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  10521. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  10522. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  10523. //#0x0200
  10524. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  10525. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282,10, 10, -1, -1, 66,
  10526. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  10527. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1,-1, 4, 2,
  10528. //#0x0240
  10529. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8,12, 4, 10,
  10530. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4,-1, 4, 0
  10531. };
  10532. struct {
  10533. void (*func)(int, struct map_session_data *);
  10534. char *name;
  10535. } clif_parse_func[]={
  10536. {clif_parse_WantToConnection,"wanttoconnection"},
  10537. {clif_parse_LoadEndAck,"loadendack"},
  10538. {clif_parse_TickSend,"ticksend"},
  10539. {clif_parse_WalkToXY,"walktoxy"},
  10540. {clif_parse_QuitGame,"quitgame"},
  10541. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  10542. {clif_parse_GlobalMessage,"globalmessage"},
  10543. {clif_parse_MapMove,"mapmove"},
  10544. {clif_parse_ChangeDir,"changedir"},
  10545. {clif_parse_Emotion,"emotion"},
  10546. {clif_parse_HowManyConnections,"howmanyconnections"},
  10547. {clif_parse_ActionRequest,"actionrequest"},
  10548. {clif_parse_Restart,"restart"},
  10549. {clif_parse_Wis,"wis"},
  10550. {clif_parse_GMmessage,"gmmessage"},
  10551. {clif_parse_TakeItem,"takeitem"},
  10552. {clif_parse_DropItem,"dropitem"},
  10553. {clif_parse_UseItem,"useitem"},
  10554. {clif_parse_EquipItem,"equipitem"},
  10555. {clif_parse_UnequipItem,"unequipitem"},
  10556. {clif_parse_NpcClicked,"npcclicked"},
  10557. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  10558. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  10559. {clif_parse_NpcSellListSend,"npcselllistsend"},
  10560. {clif_parse_CreateChatRoom,"createchatroom"},
  10561. {clif_parse_ChatAddMember,"chataddmember"},
  10562. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  10563. {clif_parse_ChangeChatOwner,"changechatowner"},
  10564. {clif_parse_KickFromChat,"kickfromchat"},
  10565. {clif_parse_ChatLeave,"chatleave"},
  10566. {clif_parse_TradeRequest,"traderequest"},
  10567. {clif_parse_TradeAck,"tradeack"},
  10568. {clif_parse_TradeAddItem,"tradeadditem"},
  10569. {clif_parse_TradeOk,"tradeok"},
  10570. {clif_parse_TradeCancel,"tradecancel"},
  10571. {clif_parse_TradeCommit,"tradecommit"},
  10572. {clif_parse_StopAttack,"stopattack"},
  10573. {clif_parse_PutItemToCart,"putitemtocart"},
  10574. {clif_parse_GetItemFromCart,"getitemfromcart"},
  10575. {clif_parse_RemoveOption,"removeoption"},
  10576. {clif_parse_ChangeCart,"changecart"},
  10577. {clif_parse_StatusUp,"statusup"},
  10578. {clif_parse_SkillUp,"skillup"},
  10579. {clif_parse_UseSkillToId,"useskilltoid"},
  10580. {clif_parse_UseSkillToPos,"useskilltopos"},
  10581. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  10582. {clif_parse_UseSkillMap,"useskillmap"},
  10583. {clif_parse_RequestMemo,"requestmemo"},
  10584. {clif_parse_ProduceMix,"producemix"},
  10585. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  10586. {clif_parse_NpcNextClicked,"npcnextclicked"},
  10587. {clif_parse_NpcAmountInput,"npcamountinput"},
  10588. {clif_parse_NpcStringInput,"npcstringinput"},
  10589. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  10590. {clif_parse_ItemIdentify,"itemidentify"},
  10591. {clif_parse_SelectArrow,"selectarrow"},
  10592. {clif_parse_AutoSpell,"autospell"},
  10593. {clif_parse_UseCard,"usecard"},
  10594. {clif_parse_InsertCard,"insertcard"},
  10595. {clif_parse_RepairItem,"repairitem"},
  10596. {clif_parse_WeaponRefine,"weaponrefine"},
  10597. {clif_parse_SolveCharName,"solvecharname"},
  10598. {clif_parse_ResetChar,"resetchar"},
  10599. {clif_parse_LGMmessage,"lgmmessage"},
  10600. {clif_parse_MoveToKafra,"movetokafra"},
  10601. {clif_parse_MoveFromKafra,"movefromkafra"},
  10602. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  10603. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  10604. {clif_parse_CloseKafra,"closekafra"},
  10605. {clif_parse_CreateParty,"createparty"},
  10606. {clif_parse_CreateParty2,"createparty2"},
  10607. {clif_parse_PartyInvite,"partyinvite"},
  10608. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  10609. {clif_parse_LeaveParty,"leaveparty"},
  10610. {clif_parse_RemovePartyMember,"removepartymember"},
  10611. {clif_parse_PartyChangeOption,"partychangeoption"},
  10612. {clif_parse_PartyMessage,"partymessage"},
  10613. {clif_parse_CloseVending,"closevending"},
  10614. {clif_parse_VendingListReq,"vendinglistreq"},
  10615. {clif_parse_PurchaseReq,"purchasereq"},
  10616. {clif_parse_OpenVending,"openvending"},
  10617. {clif_parse_CreateGuild,"createguild"},
  10618. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  10619. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  10620. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  10621. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  10622. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  10623. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  10624. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  10625. {clif_parse_GuildInvite,"guildinvite"},
  10626. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  10627. {clif_parse_GuildLeave,"guildleave"},
  10628. {clif_parse_GuildExpulsion,"guildexplusion"},
  10629. {clif_parse_GuildMessage,"guildmessage"},
  10630. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  10631. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  10632. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  10633. {clif_parse_GuildOpposition,"guildopposition"},
  10634. {clif_parse_GuildBreak,"guildbreak"},
  10635. {clif_parse_PetMenu,"petmenu"},
  10636. {clif_parse_CatchPet,"catchpet"},
  10637. {clif_parse_SelectEgg,"selectegg"},
  10638. {clif_parse_SendEmotion,"sendemotion"},
  10639. {clif_parse_ChangePetName,"changepetname"},
  10640. {clif_parse_GMKick,"gmkick"},
  10641. {clif_parse_GMHide,"gmhide"},
  10642. {clif_parse_GMReqNoChat,"gmreqnochat"},
  10643. {clif_parse_GMReqNoChatCount,"gmreqnochatcount"},
  10644. {clif_parse_NoviceDoriDori,"sndoridori"},
  10645. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  10646. {clif_parse_PMIgnore,"wisexin"},
  10647. {clif_parse_PMIgnoreList,"wisexlist"},
  10648. {clif_parse_PMIgnoreAll,"wisall"},
  10649. {clif_parse_FriendsListAdd,"friendslistadd"},
  10650. {clif_parse_FriendsListRemove,"friendslistremove"},
  10651. {clif_parse_FriendsListReply,"friendslistreply"},
  10652. {clif_parse_GMKillAll,"killall"},
  10653. {clif_parse_Recall,"summon"},
  10654. {clif_parse_GM_Monster_Item,"itemmonster"},
  10655. {clif_parse_Shift,"shift"},
  10656. {clif_parse_Blacksmith,"blacksmith"},
  10657. {clif_parse_Alchemist,"alchemist"},
  10658. {clif_parse_Taekwon,"taekwon"},
  10659. {clif_parse_RankingPk,"rankingpk"},
  10660. {clif_parse_FeelSaveOk,"feelsaveok"},
  10661. {clif_parse_AdoptRequest,"adopt"},
  10662. {clif_parse_debug,"debug"},
  10663. //[blackhole89] //[orn]
  10664. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  10665. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  10666. {clif_parse_HomMoveTo,"hommoveto"},
  10667. {clif_parse_HomAttack,"homattack"},
  10668. {clif_parse_HomMenu,"hommenu"},
  10669. {clif_parse_StoragePassword,"storagepassword"},
  10670. {NULL,NULL}
  10671. };
  10672. // Set server packet lengths - packet_db[SERVER]
  10673. memset(packet_db,0,sizeof(packet_db));
  10674. for( i = 0; i < 0x260; ++i )
  10675. packet_len(i) = packet_len_table[i];
  10676. sprintf(line, "%s/packet_db.txt", db_path);
  10677. if( (fp=fopen(line,"r"))==NULL ){
  10678. ShowFatalError("can't read %s\n", line);
  10679. exit(1);
  10680. }
  10681. clif_config.packet_db_ver = MAX_PACKET_VER;
  10682. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  10683. while(fgets(line,1020,fp)){
  10684. if(line[0]=='/' && line[1]=='/')
  10685. continue;
  10686. if (sscanf(line,"%[^:]: %[^\r\n]",w1,w2) == 2) {
  10687. if(strcmpi(w1,"packet_ver")==0) {
  10688. int prev_ver = packet_ver;
  10689. skip_ver = 0;
  10690. packet_ver = atoi(w2);
  10691. if ( packet_ver > MAX_PACKET_VER )
  10692. { //Check to avoid overflowing. [Skotlex]
  10693. if( (warned&1) == 0 )
  10694. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  10695. warned &= 1;
  10696. skip_ver = 1;
  10697. }
  10698. else if( packet_ver < 0 )
  10699. {
  10700. if( (warned&2) == 0 )
  10701. ShowWarning("Negative packet versions are not supported.\n");
  10702. warned &= 2;
  10703. skip_ver = 1;
  10704. }
  10705. else if( packet_ver == SERVER )
  10706. {
  10707. if( (warned&4) == 0 )
  10708. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  10709. warned &= 4;
  10710. skip_ver = 1;
  10711. }
  10712. if( skip_ver )
  10713. {
  10714. ShowWarning("Skipping packet version %d.\n", packet_ver);
  10715. packet_ver = prev_ver;
  10716. continue;
  10717. }
  10718. // copy from previous version into new version and continue
  10719. // - indicating all following packets should be read into the newer version
  10720. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  10721. continue;
  10722. } else if(strcmpi(w1,"packet_db_ver")==0) {
  10723. //This is the preferred version.
  10724. if(strcmpi(w2,"default")==0)
  10725. clif_config.packet_db_ver = MAX_PACKET_VER;
  10726. else {
  10727. // to manually set the packet DB version
  10728. clif_config.packet_db_ver = atoi(w2);
  10729. // check for invalid version
  10730. if (clif_config.packet_db_ver > MAX_PACKET_VER ||
  10731. clif_config.packet_db_ver < 0)
  10732. clif_config.packet_db_ver = MAX_PACKET_VER;
  10733. }
  10734. continue;
  10735. }
  10736. }
  10737. if( skip_ver != 0 )
  10738. continue; // Skipping current packet version
  10739. memset(str,0,sizeof(str));
  10740. for(j=0,p=line;j<4 && p;j++){
  10741. str[j]=p;
  10742. p=strchr(p,',');
  10743. if(p) *p++=0;
  10744. }
  10745. if(str[0]==NULL)
  10746. continue;
  10747. cmd=strtol(str[0],(char **)NULL,0);
  10748. if(max_cmd < cmd)
  10749. max_cmd = cmd;
  10750. if(cmd<=0 || cmd>=MAX_PACKET_DB)
  10751. continue;
  10752. if(str[1]==NULL){
  10753. ShowError("packet_db: packet len error\n");
  10754. continue;
  10755. }
  10756. k = atoi(str[1]);
  10757. packet_db[packet_ver][cmd].len = k;
  10758. if(str[2]==NULL){
  10759. packet_db[packet_ver][cmd].func = NULL;
  10760. ln++;
  10761. continue;
  10762. }
  10763. for(j=0;j<sizeof(clif_parse_func)/sizeof(clif_parse_func[0]);j++){
  10764. if(clif_parse_func[j].name != NULL &&
  10765. strcmp(str[2],clif_parse_func[j].name)==0)
  10766. {
  10767. if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func)
  10768. { //If we are updating a function, we need to zero up the previous one. [Skotlex]
  10769. for(i=0;i<MAX_PACKET_DB;i++){
  10770. if (packet_db[packet_ver][i].func == clif_parse_func[j].func)
  10771. {
  10772. memset(&packet_db[packet_ver][i], 0, sizeof(struct packet_db));
  10773. break;
  10774. }
  10775. }
  10776. }
  10777. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  10778. break;
  10779. }
  10780. }
  10781. // set the identifying cmd for the packet_db version
  10782. if (strcmp(str[2],"wanttoconnection")==0)
  10783. clif_config.connect_cmd[packet_ver] = cmd;
  10784. if(str[3]==NULL){
  10785. ShowError("packet_db: packet error\n");
  10786. exit(1);
  10787. }
  10788. for(j=0,p2=str[3];p2;j++){
  10789. str2[j]=p2;
  10790. p2=strchr(p2,':');
  10791. if(p2) *p2++=0;
  10792. k = atoi(str2[j]);
  10793. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  10794. packet_db[packet_ver][cmd].pos[j] = k;
  10795. }
  10796. ln++;
  10797. // if(packet_db[clif_config.packet_db_ver][cmd].len > 2 /* && packet_db[cmd].pos[0] == 0 */)
  10798. // 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);
  10799. }
  10800. fclose(fp);
  10801. if(max_cmd > MAX_PACKET_DB)
  10802. {
  10803. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  10804. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  10805. }
  10806. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  10807. { //Locate the nearest version that we still support. [Skotlex]
  10808. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  10809. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  10810. }
  10811. 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);
  10812. return 0;
  10813. }
  10814. /*==========================================
  10815. *
  10816. *------------------------------------------
  10817. */
  10818. int do_init_clif(void) {
  10819. clif_config.packet_db_ver = -1; // the main packet version of the DB
  10820. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  10821. memset(packet_db,0,sizeof(packet_db));
  10822. //Using the packet_db file is the only way to set up packets now [Skotlex]
  10823. packetdb_readdb();
  10824. set_defaultparse(clif_parse);
  10825. if (!make_listen_bind(bind_ip,map_port)) {
  10826. ShowFatalError("can't bind game port\n");
  10827. exit(1);
  10828. }
  10829. add_timer_func_list(clif_waitclose, "clif_waitclose");
  10830. add_timer_func_list(clif_clearchar_delay_sub, "clif_clearchar_delay_sub");
  10831. add_timer_func_list(clif_delayquit, "clif_delayquit");
  10832. return 0;
  10833. }