clif.cpp 568 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "../common/cbasetypes.h"
  4. #include "../common/socket.h"
  5. #include "../common/timer.h"
  6. #include "../common/grfio.h"
  7. #include "../common/malloc.h"
  8. #include "../common/nullpo.h"
  9. #include "../common/random.h"
  10. #include "../common/showmsg.h"
  11. #include "../common/strlib.h"
  12. #include "../common/utils.h"
  13. #include "../common/ers.h"
  14. #include "../common/conf.h"
  15. #include "map.h"
  16. #include "chrif.h"
  17. #include "pc.h"
  18. #include "status.h"
  19. #include "npc.h"
  20. #include "itemdb.h"
  21. #include "chat.h"
  22. #include "trade.h"
  23. #include "storage.h"
  24. #include "script.h"
  25. #include "skill.h"
  26. #include "atcommand.h"
  27. #include "intif.h"
  28. #include "battle.h"
  29. #include "battleground.h"
  30. #include "mob.h"
  31. #include "party.h"
  32. #include "unit.h"
  33. #include "guild.h"
  34. #include "vending.h"
  35. #include "pet.h"
  36. #include "homunculus.h"
  37. #include "instance.h"
  38. #include "mercenary.h"
  39. #include "elemental.h"
  40. #include "log.h"
  41. #include "clif.h"
  42. #include "mail.h"
  43. #include "quest.h"
  44. #include "cashshop.h"
  45. #include "channel.h"
  46. #include "achievement.h"
  47. #include <stdio.h>
  48. #include <stdlib.h>
  49. #include <string.h>
  50. #include <stdarg.h>
  51. #include <time.h>
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. /* for clif_clearunit_delayed */
  56. static struct eri *delay_clearunit_ers;
  57. struct s_packet_db packet_db[MAX_PACKET_DB + 1];
  58. int packet_db_ack[MAX_ACK_FUNC + 1];
  59. unsigned long color_table[COLOR_MAX];
  60. #include "clif_obfuscation.h"
  61. static bool clif_session_isValid(struct map_session_data *sd);
  62. #if PACKETVER >= 20150513
  63. enum mail_type {
  64. MAIL_TYPE_TEXT = 0x0,
  65. MAIL_TYPE_ZENY = 0x2,
  66. MAIL_TYPE_ITEM = 0x4,
  67. MAIL_TYPE_NPC = 0x8
  68. };
  69. #endif
  70. /** Converts item type to display it on client if necessary.
  71. * @param nameid: Item ID
  72. * @return item type. For IT_PETEGG will be displayed as IT_WEAPON. If Shadow Weapon of IT_SHADOWGEAR as IT_WEAPON and else as IT_ARMOR
  73. */
  74. static inline int itemtype(unsigned short nameid) {
  75. struct item_data* id = itemdb_search(nameid); //Use itemdb_search, so non-existance item will use dummy data and won't crash the server. bugreport:8468
  76. int type = id->type;
  77. if( type == IT_SHADOWGEAR ) {
  78. if( id->equip&EQP_SHADOW_WEAPON )
  79. return IT_WEAPON;
  80. else
  81. return IT_ARMOR;
  82. }
  83. return ( type == IT_PETEGG ) ? IT_WEAPON : type;
  84. }
  85. static inline void WBUFPOS(uint8* p, unsigned short pos, short x, short y, unsigned char dir) {
  86. p += pos;
  87. p[0] = (uint8)(x>>2);
  88. p[1] = (uint8)((x<<6) | ((y>>4)&0x3f));
  89. p[2] = (uint8)((y<<4) | (dir&0xf));
  90. }
  91. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  92. static inline void WBUFPOS2(uint8* p, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  93. p += pos;
  94. p[0] = (uint8)(x0>>2);
  95. p[1] = (uint8)((x0<<6) | ((y0>>4)&0x3f));
  96. p[2] = (uint8)((y0<<4) | ((x1>>6)&0x0f));
  97. p[3] = (uint8)((x1<<2) | ((y1>>8)&0x03));
  98. p[4] = (uint8)y1;
  99. p[5] = (uint8)((sx0<<4) | (sy0&0x0f));
  100. }
  101. static inline void WFIFOPOS(int fd, unsigned short pos, short x, short y, unsigned char dir) {
  102. WBUFPOS(WFIFOP(fd,pos), 0, x, y, dir);
  103. }
  104. static inline void WFIFOPOS2(int fd, unsigned short pos, short x0, short y0, short x1, short y1, unsigned char sx0, unsigned char sy0) {
  105. WBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  106. }
  107. static inline void RBUFPOS(const uint8* p, unsigned short pos, short* x, short* y, unsigned char* dir) {
  108. p += pos;
  109. if( x ) {
  110. x[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  111. }
  112. if( y ) {
  113. y[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  114. }
  115. if( dir ) {
  116. dir[0] = ( p[2] & 0x0f );
  117. }
  118. }
  119. static inline void RBUFPOS2(const uint8* p, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  120. p += pos;
  121. if( x0 ) {
  122. x0[0] = ( ( p[0] & 0xff ) << 2 ) | ( p[1] >> 6 );
  123. }
  124. if( y0 ) {
  125. y0[0] = ( ( p[1] & 0x3f ) << 4 ) | ( p[2] >> 4 );
  126. }
  127. if( x1 ) {
  128. x1[0] = ( ( p[2] & 0x0f ) << 6 ) | ( p[3] >> 2 );
  129. }
  130. if( y1 ) {
  131. y1[0] = ( ( p[3] & 0x03 ) << 8 ) | ( p[4] >> 0 );
  132. }
  133. if( sx0 ) {
  134. sx0[0] = ( p[5] & 0xf0 ) >> 4;
  135. }
  136. if( sy0 ) {
  137. sy0[0] = ( p[5] & 0x0f ) >> 0;
  138. }
  139. }
  140. static inline void RFIFOPOS(int fd, unsigned short pos, short* x, short* y, unsigned char* dir) {
  141. RBUFPOS(RFIFOP(fd,pos), 0, x, y, dir);
  142. }
  143. static inline void RFIFOPOS2(int fd, unsigned short pos, short* x0, short* y0, short* x1, short* y1, unsigned char* sx0, unsigned char* sy0) {
  144. RBUFPOS2(WFIFOP(fd,pos), 0, x0, y0, x1, y1, sx0, sy0);
  145. }
  146. //To idenfity disguised characters.
  147. static inline bool disguised(struct block_list* bl) {
  148. return (bool)( bl->type == BL_PC && ((TBL_PC*)bl)->disguise );
  149. }
  150. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex]
  151. static inline unsigned int mes_len_check(char* mes, unsigned int len, unsigned int max) {
  152. if( len > max )
  153. len = max;
  154. mes[len-1] = '\0';
  155. return len;
  156. }
  157. static char map_ip_str[128];
  158. static uint32 map_ip;
  159. static uint32 bind_ip = INADDR_ANY;
  160. static uint16 map_port = 5121;
  161. static bool clif_ally_only = false;
  162. int map_fd;
  163. static int clif_parse (int fd);
  164. /*==========================================
  165. * Ip setting of map-server
  166. *------------------------------------------*/
  167. int clif_setip(const char* ip) {
  168. char ip_str[16];
  169. map_ip = host2ip(ip);
  170. if (!map_ip) {
  171. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  172. return 0;
  173. }
  174. safestrncpy(map_ip_str, ip, sizeof(map_ip_str));
  175. ShowInfo("Map Server IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(map_ip, ip_str));
  176. return 1;
  177. }
  178. void clif_setbindip(const char* ip)
  179. {
  180. bind_ip = host2ip(ip);
  181. if (bind_ip) {
  182. char ip_str[16];
  183. ShowInfo("Map Server Bind IP Address : '" CL_WHITE "%s" CL_RESET "' -> '" CL_WHITE "%s" CL_RESET "'.\n", ip, ip2str(bind_ip, ip_str));
  184. } else {
  185. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  186. }
  187. }
  188. /*==========================================
  189. * Sets map port to 'port'
  190. * is run from map.c upon loading map server configuration
  191. *------------------------------------------*/
  192. void clif_setport(uint16 port)
  193. {
  194. map_port = port;
  195. }
  196. /*==========================================
  197. * Returns map server IP
  198. *------------------------------------------*/
  199. uint32 clif_getip(void)
  200. {
  201. return map_ip;
  202. }
  203. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  204. uint32 clif_refresh_ip(void)
  205. {
  206. uint32 new_ip;
  207. new_ip = host2ip(map_ip_str);
  208. if (new_ip && new_ip != map_ip) {
  209. map_ip = new_ip;
  210. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  211. return map_ip;
  212. }
  213. return 0;
  214. }
  215. /*==========================================
  216. * Returns map port which is set by clif_setport()
  217. *------------------------------------------*/
  218. uint16 clif_getport(void)
  219. {
  220. return map_port;
  221. }
  222. #if PACKETVER >= 20071106
  223. static inline unsigned char clif_bl_type(struct block_list *bl) {
  224. switch (bl->type) {
  225. case BL_PC: return (disguised(bl) && !pcdb_checkid(status_get_viewdata(bl)->class_))? 0x1:0x0; //PC_TYPE
  226. case BL_ITEM: return 0x2; //ITEM_TYPE
  227. case BL_SKILL: return 0x3; //SKILL_TYPE
  228. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  229. case BL_MOB: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  230. case BL_NPC: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x6; //NPC_EVT_TYPE
  231. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  232. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  233. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  234. case BL_ELEM: return 0xa; //NPC_ELEMENTAL_TYPE
  235. default: return 0x1; //NPC_TYPE
  236. }
  237. }
  238. #endif
  239. static bool clif_session_isValid(struct map_session_data *sd) {
  240. return ( sd != NULL && session_isActive(sd->fd) );
  241. }
  242. /*==========================================
  243. * sub process of clif_send
  244. * Called from a map_foreachinallarea (grabs all players in specific area and subjects them to this function)
  245. * In order to send area-wise packets, such as:
  246. * - AREA : everyone nearby your area
  247. * - AREA_WOSC (AREA WITHOUT SAME CHAT) : Not run for people in the same chat as yours
  248. * - AREA_WOC (AREA WITHOUT CHAT) : Not run for people inside a chat
  249. * - AREA_WOS (AREA WITHOUT SELF) : Not run for self
  250. * - AREA_CHAT_WOC : Everyone in the area of your chat without a chat
  251. *------------------------------------------*/
  252. static int clif_send_sub(struct block_list *bl, va_list ap)
  253. {
  254. struct block_list *src_bl;
  255. struct map_session_data *sd;
  256. unsigned char *buf;
  257. int len, type, fd;
  258. nullpo_ret(bl);
  259. nullpo_ret(sd = (struct map_session_data *)bl);
  260. fd = sd->fd;
  261. if (!fd) //Don't send to disconnected clients.
  262. return 0;
  263. buf = va_arg(ap,unsigned char*);
  264. len = va_arg(ap,int);
  265. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  266. type = va_arg(ap,int);
  267. switch(type) {
  268. case AREA_WOS:
  269. if (bl == src_bl)
  270. return 0;
  271. break;
  272. case AREA_WOC:
  273. if (sd->chatID || bl == src_bl)
  274. return 0;
  275. break;
  276. case AREA_WOSC:
  277. {
  278. if(src_bl->type == BL_PC) {
  279. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  280. if (ssd && sd->chatID && (sd->chatID == ssd->chatID))
  281. return 0;
  282. }
  283. else if(src_bl->type == BL_NPC) {
  284. struct npc_data *nd = (struct npc_data *)src_bl;
  285. if (nd && sd->chatID && (sd->chatID == nd->chat_id))
  286. return 0;
  287. }
  288. }
  289. break;
  290. }
  291. if (session[fd] == NULL)
  292. return 0;
  293. /* unless visible, hold it here */
  294. if (!battle_config.update_enemy_position && clif_ally_only && !sd->special_state.intravision &&
  295. !sd->sc.data[SC_INTRAVISION] && battle_check_target(src_bl,&sd->bl,BCT_ENEMY) > 0)
  296. return 0;
  297. WFIFOHEAD(fd, len);
  298. if (WFIFOP(fd,0) == buf) {
  299. ShowError("WARNING: Invalid use of clif_send function\n");
  300. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  301. ShowError(" Please correct your code.\n");
  302. // don't send to not move the pointer of the packet for next sessions in the loop
  303. //WFIFOSET(fd,0);//## TODO is this ok?
  304. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  305. return 0;
  306. }
  307. memcpy(WFIFOP(fd,0), buf, len);
  308. WFIFOSET(fd,len);
  309. return 0;
  310. }
  311. /*==========================================
  312. * Packet Delegation (called on all packets that require data to be sent to more than one client)
  313. * functions that are sent solely to one use whose ID it posses use WFIFOSET
  314. *------------------------------------------*/
  315. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  316. {
  317. int i;
  318. struct map_session_data *sd, *tsd;
  319. struct party_data *p = NULL;
  320. struct guild *g = NULL;
  321. struct battleground_data *bg = NULL;
  322. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  323. struct s_mapiterator* iter;
  324. if( type != ALL_CLIENT )
  325. nullpo_ret(bl);
  326. sd = BL_CAST(BL_PC, bl);
  327. switch(type) {
  328. case ALL_CLIENT: //All player clients.
  329. iter = mapit_getallusers();
  330. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL ){
  331. WFIFOHEAD(tsd->fd, len);
  332. memcpy(WFIFOP(tsd->fd, 0), buf, len);
  333. WFIFOSET(tsd->fd, len);
  334. }
  335. mapit_free(iter);
  336. break;
  337. case ALL_SAMEMAP: //All players on the same map
  338. iter = mapit_getallusers();
  339. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  340. {
  341. if( bl->m == tsd->bl.m ){
  342. WFIFOHEAD(tsd->fd, len);
  343. memcpy(WFIFOP(tsd->fd,0), buf, len);
  344. WFIFOSET(tsd->fd,len);
  345. }
  346. }
  347. mapit_free(iter);
  348. break;
  349. case AREA:
  350. case AREA_WOSC:
  351. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  352. clif_send (buf, len, bl, SELF);
  353. case AREA_WOC:
  354. case AREA_WOS:
  355. map_foreachinallarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  356. BL_PC, buf, len, bl, type);
  357. break;
  358. case AREA_CHAT_WOC:
  359. map_foreachinallarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  360. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  361. break;
  362. case CHAT:
  363. case CHAT_WOS:
  364. {
  365. struct chat_data *cd;
  366. if (sd) {
  367. cd = (struct chat_data*)map_id2bl(sd->chatID);
  368. } else if (bl->type == BL_CHAT) {
  369. cd = (struct chat_data*)bl;
  370. } else break;
  371. if (cd == NULL)
  372. break;
  373. for(i = 0; i < cd->users; i++) {
  374. if (type == CHAT_WOS && cd->usersd[i] == sd)
  375. continue;
  376. if ((fd=cd->usersd[i]->fd) >0 && session[fd]){ // Added check to see if session exists [PoW]
  377. WFIFOHEAD(fd,len);
  378. memcpy(WFIFOP(fd,0), buf, len);
  379. WFIFOSET(fd,len);
  380. }
  381. }
  382. }
  383. break;
  384. case PARTY_AREA:
  385. case PARTY_AREA_WOS:
  386. x0 = bl->x - AREA_SIZE;
  387. y0 = bl->y - AREA_SIZE;
  388. x1 = bl->x + AREA_SIZE;
  389. y1 = bl->y + AREA_SIZE;
  390. case PARTY:
  391. case PARTY_WOS:
  392. case PARTY_SAMEMAP:
  393. case PARTY_SAMEMAP_WOS:
  394. if (sd && sd->status.party_id)
  395. p = party_search(sd->status.party_id);
  396. if (p) {
  397. for(i=0;i<MAX_PARTY;i++){
  398. if( (sd = p->data[i].sd) == NULL )
  399. continue;
  400. if( !(fd=sd->fd) )
  401. continue;
  402. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  403. continue;
  404. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  405. continue;
  406. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  407. continue;
  408. WFIFOHEAD(fd, len);
  409. memcpy(WFIFOP(fd, 0), buf, len);
  410. WFIFOSET(fd, len);
  411. }
  412. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  413. break;
  414. iter = mapit_getallusers();
  415. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  416. {
  417. if( tsd->partyspy == p->party.party_id ){
  418. WFIFOHEAD(tsd->fd, len);
  419. memcpy(WFIFOP(tsd->fd,0), buf, len);
  420. WFIFOSET(tsd->fd,len);
  421. }
  422. }
  423. mapit_free(iter);
  424. }
  425. break;
  426. case DUEL:
  427. case DUEL_WOS:
  428. if (!sd || !sd->duel_group) break; //Invalid usage.
  429. iter = mapit_getallusers();
  430. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  431. {
  432. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  433. continue;
  434. if( sd->duel_group == tsd->duel_group ){
  435. WFIFOHEAD(tsd->fd, len);
  436. memcpy(WFIFOP(tsd->fd,0), buf, len);
  437. WFIFOSET(tsd->fd,len);
  438. }
  439. }
  440. mapit_free(iter);
  441. break;
  442. case SELF:
  443. if (sd && (fd=sd->fd)) {
  444. WFIFOHEAD(fd,len);
  445. memcpy(WFIFOP(fd,0), buf, len);
  446. WFIFOSET(fd,len);
  447. }
  448. break;
  449. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  450. case GUILD_AREA:
  451. case GUILD_AREA_WOS:
  452. x0 = bl->x - AREA_SIZE;
  453. y0 = bl->y - AREA_SIZE;
  454. x1 = bl->x + AREA_SIZE;
  455. y1 = bl->y + AREA_SIZE;
  456. case GUILD_SAMEMAP:
  457. case GUILD_SAMEMAP_WOS:
  458. case GUILD:
  459. case GUILD_WOS:
  460. case GUILD_NOBG:
  461. if (sd && sd->status.guild_id)
  462. g = sd->guild;
  463. if (g) {
  464. for(i = 0; i < g->max_member; i++) {
  465. if( (sd = g->member[i].sd) != NULL )
  466. {
  467. if( !(fd=sd->fd) )
  468. continue;
  469. if( type == GUILD_NOBG && sd->bg_id )
  470. continue;
  471. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  472. continue;
  473. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  474. continue;
  475. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  476. continue;
  477. WFIFOHEAD(fd,len);
  478. memcpy(WFIFOP(fd,0), buf, len);
  479. WFIFOSET(fd,len);
  480. }
  481. }
  482. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  483. break;
  484. iter = mapit_getallusers();
  485. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  486. {
  487. if( tsd->guildspy == g->guild_id ){
  488. WFIFOHEAD(tsd->fd, len);
  489. memcpy(WFIFOP(tsd->fd,0), buf, len);
  490. WFIFOSET(tsd->fd,len);
  491. }
  492. }
  493. mapit_free(iter);
  494. }
  495. break;
  496. case BG_AREA:
  497. case BG_AREA_WOS:
  498. x0 = bl->x - AREA_SIZE;
  499. y0 = bl->y - AREA_SIZE;
  500. x1 = bl->x + AREA_SIZE;
  501. y1 = bl->y + AREA_SIZE;
  502. case BG_SAMEMAP:
  503. case BG_SAMEMAP_WOS:
  504. case BG:
  505. case BG_WOS:
  506. if( sd && sd->bg_id && (bg = bg_team_search(sd->bg_id)) != NULL )
  507. {
  508. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  509. {
  510. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  511. continue;
  512. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  513. continue;
  514. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  515. continue;
  516. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  517. continue;
  518. WFIFOHEAD(fd,len);
  519. memcpy(WFIFOP(fd,0), buf, len);
  520. WFIFOSET(fd,len);
  521. }
  522. }
  523. break;
  524. case CLAN:
  525. if( sd && sd->clan ){
  526. struct clan* clan = sd->clan;
  527. for( i = 0; i < clan->max_member; i++ ){
  528. if( ( sd = clan->members[i] ) == NULL || !(fd = sd->fd) ){
  529. continue;
  530. }
  531. WFIFOHEAD(fd,len);
  532. memcpy(WFIFOP(fd,0), buf, len);
  533. WFIFOSET(fd,len);
  534. }
  535. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  536. break;
  537. iter = mapit_getallusers();
  538. while ((tsd = (TBL_PC*)mapit_next(iter)) != NULL){
  539. if (tsd->clanspy == clan->id){
  540. WFIFOHEAD(tsd->fd, len);
  541. memcpy(WFIFOP(tsd->fd, 0), buf, len);
  542. WFIFOSET(tsd->fd, len);
  543. }
  544. }
  545. mapit_free(iter);
  546. }
  547. break;
  548. default:
  549. ShowError("clif_send: Unrecognized type %d\n",type);
  550. return -1;
  551. }
  552. return 0;
  553. }
  554. /// Notifies the client, that it's connection attempt was accepted.
  555. /// 0073 <start time>.L <position>.3B <x size>.B <y size>.B (ZC_ACCEPT_ENTER)
  556. /// 02eb <start time>.L <position>.3B <x size>.B <y size>.B <font>.W (ZC_ACCEPT_ENTER2)
  557. /// 0a18 <start time>.L <position>.3B <x size>.B <y size>.B <font>.W <sex>.B (ZC_ACCEPT_ENTER3)
  558. void clif_authok(struct map_session_data *sd)
  559. {
  560. #if PACKETVER < 20080102
  561. const int cmd = 0x73;
  562. #elif PACKETVER < 20141022 || PACKETVER >= 20160330
  563. const int cmd = 0x2eb;
  564. #else
  565. const int cmd = 0xa18;
  566. #endif
  567. int fd = sd->fd;
  568. WFIFOHEAD(fd,packet_len(cmd));
  569. WFIFOW(fd, 0) = cmd;
  570. WFIFOL(fd, 2) = gettick();
  571. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  572. WFIFOB(fd, 9) = 5; // ignored
  573. WFIFOB(fd,10) = 5; // ignored
  574. #if PACKETVER >= 20080102
  575. WFIFOW(fd,11) = sd->status.font;
  576. #endif
  577. #if PACKETVER >= 20141016 && PACKETVER < 20160330
  578. WFIFOB(fd,13) = sd->status.sex;
  579. #endif
  580. WFIFOSET(fd,packet_len(cmd));
  581. }
  582. /// Notifies the client, that it's connection attempt was refused (ZC_REFUSE_ENTER).
  583. /// 0074 <error code>.B
  584. /// error code:
  585. /// 0 = client type mismatch
  586. /// 1 = ID mismatch
  587. /// 2 = mobile - out of available time
  588. /// 3 = mobile - already logged in
  589. /// 4 = mobile - waiting state
  590. void clif_authrefuse(int fd, uint8 error_code)
  591. {
  592. WFIFOHEAD(fd,packet_len(0x74));
  593. WFIFOW(fd,0) = 0x74;
  594. WFIFOB(fd,2) = error_code;
  595. WFIFOSET(fd,packet_len(0x74));
  596. }
  597. /// Notifies the client of a ban or forced disconnect (SC_NOTIFY_BAN).
  598. /// 0081 <error code>.B
  599. /// error code:
  600. /// 0 = BAN_UNFAIR
  601. /// 1 = server closed -> MsgStringTable[4]
  602. /// 2 = ID already logged in -> MsgStringTable[5]
  603. /// 3 = timeout/too much lag -> MsgStringTable[241]
  604. /// 4 = server full -> MsgStringTable[264]
  605. /// 5 = underaged -> MsgStringTable[305]
  606. /// 8 = Server sill recognizes last connection -> MsgStringTable[441]
  607. /// 9 = too many connections from this ip -> MsgStringTable[529]
  608. /// 10 = out of available time paid for -> MsgStringTable[530]
  609. /// 11 = BAN_PAY_SUSPEND
  610. /// 12 = BAN_PAY_CHANGE
  611. /// 13 = BAN_PAY_WRONGIP
  612. /// 14 = BAN_PAY_PNGAMEROOM
  613. /// 15 = disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  614. /// 16 = BAN_JAPAN_REFUSE1
  615. /// 17 = BAN_JAPAN_REFUSE2
  616. /// 18 = BAN_INFORMATION_REMAINED_ANOTHER_ACCOUNT
  617. /// 100 = BAN_PC_IP_UNFAIR
  618. /// 101 = BAN_PC_IP_COUNT_ALL
  619. /// 102 = BAN_PC_IP_COUNT
  620. /// 103 = BAN_GRAVITY_MEM_AGREE
  621. /// 104 = BAN_GAME_MEM_AGREE
  622. /// 105 = BAN_HAN_VALID
  623. /// 106 = BAN_PC_IP_LIMIT_ACCESS
  624. /// 107 = BAN_OVER_CHARACTER_LIST
  625. /// 108 = BAN_IP_BLOCK
  626. /// 109 = BAN_INVALID_PWD_CNT
  627. /// 110 = BAN_NOT_ALLOWED_JOBCLASS
  628. /// ? = disconnected -> MsgStringTable[3]
  629. void clif_authfail_fd(int fd, int type)
  630. {
  631. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  632. return;
  633. WFIFOHEAD(fd, packet_len(0x81));
  634. WFIFOW(fd,0) = 0x81;
  635. WFIFOB(fd,2) = type;
  636. WFIFOSET(fd,packet_len(0x81));
  637. set_eof(fd);
  638. }
  639. /// Notifies the client, whether it can disconnect and change servers (ZC_RESTART_ACK).
  640. /// 00b3 <type>.B
  641. /// type:
  642. /// 1 = disconnect, char-select
  643. /// ? = nothing
  644. void clif_charselectok(int id, uint8 ok)
  645. {
  646. struct map_session_data* sd;
  647. int fd;
  648. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  649. return;
  650. fd = sd->fd;
  651. WFIFOHEAD(fd,packet_len(0xb3));
  652. WFIFOW(fd,0) = 0xb3;
  653. WFIFOB(fd,2) = ok;
  654. WFIFOSET(fd,packet_len(0xb3));
  655. }
  656. /// Makes an item appear on the ground.
  657. /// 009e <id>.L <name id>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY)
  658. /// 084b <id>.L <name id>.W <type>.W <identified>.B <x>.W <y>.W <subX>.B <subY>.B <amount>.W (ZC_ITEM_FALL_ENTRY4)
  659. void clif_dropflooritem(struct flooritem_data* fitem)
  660. {
  661. #if PACKETVER >= 20130000
  662. uint8 buf[19];
  663. uint32 header=0x84b;
  664. #else
  665. uint8 buf[17];
  666. uint32 header=0x09e;
  667. #endif
  668. int view, offset=0;
  669. nullpo_retv(fitem);
  670. if (fitem->item.nameid == 0)
  671. return;
  672. WBUFW(buf, offset+0) = header;
  673. WBUFL(buf, offset+2) = fitem->bl.id;
  674. WBUFW(buf, offset+6) = ((view = itemdb_viewid(fitem->item.nameid)) > 0) ? view : fitem->item.nameid;
  675. #if PACKETVER >= 20130000
  676. WBUFW(buf, offset+8) = itemtype(fitem->item.nameid);
  677. offset +=2;
  678. #endif
  679. WBUFB(buf, offset+8) = fitem->item.identify;
  680. WBUFW(buf, offset+9) = fitem->bl.x;
  681. WBUFW(buf, offset+11) = fitem->bl.y;
  682. WBUFB(buf, offset+13) = fitem->subx;
  683. WBUFB(buf, offset+14) = fitem->suby;
  684. WBUFW(buf, offset+15) = fitem->item.amount;
  685. clif_send(buf, packet_len(header), &fitem->bl, AREA);
  686. }
  687. /// Makes an item disappear from the ground.
  688. /// 00a1 <id>.L (ZC_ITEM_DISAPPEAR)
  689. void clif_clearflooritem(struct flooritem_data *fitem, int fd)
  690. {
  691. unsigned char buf[16];
  692. nullpo_retv(fitem);
  693. WBUFW(buf,0) = 0xa1;
  694. WBUFL(buf,2) = fitem->bl.id;
  695. if (fd == 0) {
  696. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  697. } else {
  698. WFIFOHEAD(fd,packet_len(0xa1));
  699. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  700. WFIFOSET(fd,packet_len(0xa1));
  701. }
  702. }
  703. /// Makes a unit (char, npc, mob, homun) disappear to one client (ZC_NOTIFY_VANISH).
  704. /// 0080 <id>.L <type>.B
  705. /// type:
  706. /// 0 = out of sight
  707. /// 1 = died
  708. /// 2 = logged out
  709. /// 3 = teleport
  710. /// 4 = trickdead
  711. void clif_clearunit_single(int id, clr_type type, int fd)
  712. {
  713. WFIFOHEAD(fd, packet_len(0x80));
  714. WFIFOW(fd,0) = 0x80;
  715. WFIFOL(fd,2) = id;
  716. WFIFOB(fd,6) = type;
  717. WFIFOSET(fd, packet_len(0x80));
  718. }
  719. /// Makes a unit (char, npc, mob, homun) disappear to all clients in area (ZC_NOTIFY_VANISH).
  720. /// 0080 <id>.L <type>.B
  721. /// type:
  722. /// 0 = out of sight
  723. /// 1 = died
  724. /// 2 = logged out
  725. /// 3 = teleport
  726. /// 4 = trickdead
  727. void clif_clearunit_area(struct block_list* bl, clr_type type)
  728. {
  729. unsigned char buf[8];
  730. nullpo_retv(bl);
  731. WBUFW(buf,0) = 0x80;
  732. WBUFL(buf,2) = bl->id;
  733. WBUFB(buf,6) = type;
  734. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  735. if(disguised(bl)) {
  736. WBUFL(buf,2) = -bl->id;
  737. clif_send(buf, packet_len(0x80), bl, SELF);
  738. }
  739. }
  740. /// Used to make monsters with player-sprites disappear after dying
  741. /// like normal monsters, because the client does not remove those
  742. /// automatically.
  743. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr_t data)
  744. {
  745. struct block_list *bl = (struct block_list *)data;
  746. clif_clearunit_area(bl, (clr_type) id);
  747. ers_free(delay_clearunit_ers,bl);
  748. return 0;
  749. }
  750. void clif_clearunit_delayed(struct block_list* bl, clr_type type, unsigned int tick)
  751. {
  752. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  753. memcpy (tbl, bl, sizeof (struct block_list));
  754. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  755. }
  756. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  757. {
  758. if(sd->sc.option&OPTION_COSTUME)
  759. {
  760. *rhand = *lhand = 0;
  761. return;
  762. }
  763. #if PACKETVER < 4
  764. *rhand = sd->status.weapon;
  765. *lhand = sd->status.shield;
  766. #else
  767. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  768. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  769. {
  770. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  771. if (id->view_id > 0)
  772. *rhand = id->view_id;
  773. else
  774. *rhand = id->nameid;
  775. } else
  776. *rhand = 0;
  777. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  778. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  779. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  780. {
  781. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  782. if (id->view_id > 0)
  783. *lhand = id->view_id;
  784. else
  785. *lhand = id->nameid;
  786. } else
  787. *lhand = 0;
  788. #endif
  789. }
  790. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  791. static int clif_setlevel_sub(int lv) {
  792. if( lv < battle_config.max_lv ) {
  793. ;
  794. } else if( lv < battle_config.aura_lv ) {
  795. lv = battle_config.max_lv - 1;
  796. } else {
  797. lv = battle_config.max_lv;
  798. }
  799. return lv;
  800. }
  801. static int clif_setlevel(struct block_list* bl) {
  802. int lv = status_get_lv(bl);
  803. if( battle_config.client_limit_unit_lv&bl->type )
  804. return clif_setlevel_sub(lv);
  805. switch( bl->type ) {
  806. case BL_NPC:
  807. case BL_PET:
  808. // npcs and pets do not have level
  809. return 0;
  810. }
  811. return lv;
  812. }
  813. /*==========================================
  814. * Prepares 'unit standing/spawning' packet
  815. *------------------------------------------*/
  816. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  817. {
  818. struct map_session_data* sd;
  819. struct status_change* sc = status_get_sc(bl);
  820. struct view_data* vd = status_get_viewdata(bl);
  821. unsigned char *buf = WBUFP(buffer, 0);
  822. #if PACKETVER < 20091103
  823. bool type = !pcdb_checkid(vd->class_);
  824. #endif
  825. unsigned short offset = 0;
  826. #if PACKETVER >= 20091103
  827. const char *name;
  828. #endif
  829. sd = BL_CAST(BL_PC, bl);
  830. #if PACKETVER < 20091103
  831. if(type)
  832. WBUFW(buf,0) = spawn ? 0x7c : 0x78;
  833. else
  834. #endif
  835. #if PACKETVER < 4
  836. WBUFW(buf,0) = spawn ? 0x79 : 0x78;
  837. #elif PACKETVER < 7
  838. WBUFW(buf,0) = spawn ? 0x1d9 : 0x1d8;
  839. #elif PACKETVER < 20080102
  840. WBUFW(buf,0) = spawn ? 0x22b : 0x22a;
  841. #elif PACKETVER < 20091103
  842. WBUFW(buf,0) = spawn ? 0x2ed : 0x2ee;
  843. #elif PACKETVER < 20101124
  844. WBUFW(buf,0) = spawn ? 0x7f8 : 0x7f9;
  845. #elif PACKETVER < 20120221
  846. WBUFW(buf,0) = spawn ? 0x858 : 0x857;
  847. #elif PACKETVER < 20131223
  848. WBUFW(buf,0) = spawn ? 0x90f : 0x915;
  849. #elif PACKETVER < 20150513
  850. WBUFW(buf,0) = spawn ? 0x9dc : 0x9dd;
  851. #else
  852. WBUFW(buf,0) = spawn ? 0x9fe : 0x9ff;
  853. #endif
  854. #if PACKETVER >= 20091103
  855. name = status_get_name(bl);
  856. #if PACKETVER < 20110111
  857. WBUFW(buf,2) = (uint16)((spawn ? 62 : 63)+strlen(name));
  858. #elif PACKETVER < 20120221
  859. WBUFW(buf,2) = (uint16)((spawn ? 64 : 65)+strlen(name));
  860. #elif PACKETVER < 20130807
  861. WBUFW(buf,2) = (uint16)((spawn ? 77 : 78)+strlen(name));
  862. #else
  863. WBUFW(buf,2) = (uint16)((spawn ? 79 : 80)+strlen(name));
  864. #endif
  865. WBUFB(buf,4) = clif_bl_type(bl);
  866. offset+=3;
  867. buf = WBUFP(buffer,offset);
  868. #elif PACKETVER >= 20071106
  869. if (type) { //Non-player packets
  870. WBUFB(buf,2) = clif_bl_type(bl);
  871. offset++;
  872. buf = WBUFP(buffer,offset);
  873. }
  874. #endif
  875. WBUFL(buf, 2) = bl->id;
  876. #if PACKETVER >= 20131223
  877. WBUFL(buf,6) = (sd) ? sd->status.char_id : 0; // GID/CCODE
  878. offset+=4;
  879. buf = WBUFP(buffer,offset);
  880. #endif
  881. WBUFW(buf, 6) = status_get_speed(bl);
  882. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  883. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  884. #if PACKETVER < 20091103
  885. if (type&&spawn) { //uses an older and different packet structure
  886. WBUFW(buf,12) = (sc)? sc->option : 0;
  887. WBUFW(buf,14) = vd->hair_style;
  888. WBUFW(buf,16) = vd->weapon;
  889. WBUFW(buf,18) = vd->head_bottom;
  890. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  891. WBUFW(buf,22) = vd->shield;
  892. } else {
  893. #endif
  894. #if PACKETVER >= 20091103
  895. WBUFL(buf,12) = (sc)? sc->option : 0;
  896. offset+=2;
  897. buf = WBUFP(buffer,offset);
  898. #elif PACKETVER >= 7
  899. if (!type) {
  900. WBUFL(buf,12) = (sc)? sc->option : 0;
  901. offset+=2;
  902. buf = WBUFP(buffer,offset);
  903. } else
  904. WBUFW(buf,12) = (sc)? sc->option : 0;
  905. #else
  906. WBUFW(buf,12) = (sc)? sc->option : 0;
  907. #endif
  908. WBUFW(buf,14) = vd->class_;
  909. WBUFW(buf,16) = vd->hair_style;
  910. WBUFW(buf,18) = vd->weapon;
  911. #if PACKETVER < 4
  912. WBUFW(buf,20) = vd->head_bottom;
  913. WBUFW(buf,22) = vd->shield;
  914. #else
  915. WBUFW(buf,20) = vd->shield;
  916. WBUFW(buf,22) = vd->head_bottom;
  917. #endif
  918. #if PACKETVER < 20091103
  919. }
  920. #endif
  921. WBUFW(buf,24) = vd->head_top;
  922. WBUFW(buf,26) = vd->head_mid;
  923. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  924. { //The hell, why flags work like this?
  925. WBUFW(buf,22) = status_get_emblem_id(bl);
  926. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  927. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  928. }
  929. WBUFW(buf,28) = vd->hair_color;
  930. WBUFW(buf,30) = vd->cloth_color;
  931. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  932. #if PACKETVER < 20091103
  933. if (type&&spawn) { //End of packet 0x7c
  934. WBUFB(buf,34) = (sd) ? sd->status.karma : 0; // karma
  935. WBUFB(buf,35) = vd->sex;
  936. WBUFPOS(buf,36, bl->x, bl->y, unit_getdir(bl));
  937. WBUFB(buf,39) = 0;
  938. WBUFB(buf,40) = 0;
  939. return packet_len(0x7c);
  940. }
  941. #endif
  942. #if PACKETVER >= 20110111
  943. WBUFW(buf,34) = vd->robe;
  944. offset+= 2;
  945. buf = WBUFP(buffer,offset);
  946. #endif
  947. WBUFL(buf,34) = status_get_guild_id(bl);
  948. WBUFW(buf,38) = status_get_emblem_id(bl);
  949. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  950. #if PACKETVER >= 20091103
  951. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  952. offset+=2;
  953. buf = WBUFP(buffer,offset);
  954. #elif PACKETVER >= 7
  955. if (!type) {
  956. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  957. offset+=2;
  958. buf = WBUFP(buffer,offset);
  959. } else
  960. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  961. #else
  962. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  963. #endif
  964. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  965. WBUFB(buf,45) = vd->sex;
  966. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  967. WBUFB(buf,49) = (sd)? 5 : 0;
  968. WBUFB(buf,50) = (sd)? 5 : 0;
  969. if (!spawn) {
  970. WBUFB(buf,51) = vd->dead_sit;
  971. offset++;
  972. buf = WBUFP(buffer,offset);
  973. }
  974. WBUFW(buf,51) = clif_setlevel(bl);
  975. #if PACKETVER < 20091103
  976. if (type) //End for non-player packet
  977. return packet_len(WBUFW(buffer,0));
  978. #endif
  979. #if PACKETVER >= 20080102
  980. WBUFW(buf,53) = (sd ? sd->status.font : 0);
  981. #endif
  982. #if PACKETVER >= 20120221
  983. if ( battle_config.monster_hp_bars_info && !map[bl->m].flag.hidemobhpbar && bl->type == BL_MOB && (status_get_hp(bl) < status_get_max_hp(bl)) ) {
  984. WBUFL(buf,55) = status_get_max_hp(bl); // maxHP
  985. WBUFL(buf,59) = status_get_hp(bl); // HP
  986. } else {
  987. WBUFL(buf,55) = -1; // maxHP
  988. WBUFL(buf,59) = -1; // HP
  989. }
  990. WBUFB(buf,63) = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0; // isBoss
  991. #endif
  992. #if PACKETVER >= 20150513
  993. WBUFW(buf,64) = vd->body_style; // body
  994. offset+= 2;
  995. buf = WBUFP(buffer,offset);
  996. #endif
  997. #if PACKETVER >= 20091103
  998. #if PACKETVER >= 20120221
  999. safestrncpy(WBUFCP(buf,64), name, NAME_LENGTH);
  1000. #else
  1001. safestrncpy(WBUFCP(buf,55), name, NAME_LENGTH);
  1002. #endif
  1003. return WBUFW(buffer,2);
  1004. #else
  1005. return packet_len(WBUFW(buffer,0));
  1006. #endif
  1007. }
  1008. /*==========================================
  1009. * Prepares 'unit walking' packet
  1010. *------------------------------------------*/
  1011. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  1012. {
  1013. struct map_session_data* sd;
  1014. struct status_change* sc = status_get_sc(bl);
  1015. struct view_data* vd = status_get_viewdata(bl);
  1016. unsigned char* buf = WBUFP(buffer,0);
  1017. #if PACKETVER >= 7
  1018. unsigned short offset = 0;
  1019. #endif
  1020. #if PACKETVER >= 20091103
  1021. const char *name;
  1022. #endif
  1023. sd = BL_CAST(BL_PC, bl);
  1024. #if PACKETVER < 4
  1025. WBUFW(buf, 0) = 0x7b;
  1026. #elif PACKETVER < 7
  1027. WBUFW(buf, 0) = 0x1da;
  1028. #elif PACKETVER < 20080102
  1029. WBUFW(buf, 0) = 0x22c;
  1030. #elif PACKETVER < 20091103
  1031. WBUFW(buf, 0) = 0x2ec;
  1032. #elif PACKETVER < 20101124
  1033. WBUFW(buf, 0) = 0x7f7;
  1034. #elif PACKETVER < 20120221
  1035. WBUFW(buf, 0) = 0x856;
  1036. #elif PACKETVER < 20131223
  1037. WBUFW(buf, 0) = 0x914;
  1038. #elif PACKETVER < 20150513
  1039. WBUFW(buf, 0) = 0x9db;
  1040. #else
  1041. WBUFW(buf, 0) = 0x9fd;
  1042. #endif
  1043. #if PACKETVER >= 20091103
  1044. name = status_get_name(bl);
  1045. #if PACKETVER < 20110111
  1046. WBUFW(buf, 2) = (uint16)(69+strlen(name));
  1047. #elif PACKETVER < 20120221
  1048. WBUFW(buf, 2) = (uint16)(71+strlen(name));
  1049. #elif PACKETVER < 20130807
  1050. WBUFW(buf, 2) = (uint16)(84+strlen(name));
  1051. #else
  1052. WBUFW(buf, 2) = (uint16)(86+strlen(name));
  1053. #endif
  1054. offset+=2;
  1055. buf = WBUFP(buffer,offset);
  1056. #endif
  1057. #if PACKETVER >= 20071106
  1058. WBUFB(buf, 2) = clif_bl_type(bl);
  1059. offset++;
  1060. buf = WBUFP(buffer,offset);
  1061. #endif
  1062. WBUFL(buf, 2) = bl->id;
  1063. #if PACKETVER >= 20131223
  1064. WBUFL(buf,6) = (sd) ? sd->status.char_id : 0; // GID/CCODE
  1065. offset+=4;
  1066. buf = WBUFP(buffer,offset);
  1067. #endif
  1068. WBUFW(buf, 6) = status_get_speed(bl);
  1069. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  1070. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  1071. #if PACKETVER < 7
  1072. WBUFW(buf,12) = (sc)? sc->option : 0;
  1073. #else
  1074. WBUFL(buf,12) = (sc)? sc->option : 0;
  1075. offset+=2; //Shift the rest of elements by 2 bytes.
  1076. buf = WBUFP(buffer,offset);
  1077. #endif
  1078. WBUFW(buf,14) = vd->class_;
  1079. WBUFW(buf,16) = vd->hair_style;
  1080. WBUFW(buf,18) = vd->weapon;
  1081. #if PACKETVER < 4
  1082. WBUFW(buf,20) = vd->head_bottom;
  1083. WBUFL(buf,22) = gettick();
  1084. WBUFW(buf,26) = vd->shield;
  1085. #else
  1086. WBUFW(buf,20) = vd->shield;
  1087. WBUFW(buf,22) = vd->head_bottom;
  1088. WBUFL(buf,24) = gettick();
  1089. #endif
  1090. WBUFW(buf,28) = vd->head_top;
  1091. WBUFW(buf,30) = vd->head_mid;
  1092. WBUFW(buf,32) = vd->hair_color;
  1093. WBUFW(buf,34) = vd->cloth_color;
  1094. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  1095. #if PACKETVER >= 20110111
  1096. WBUFW(buf,38) = vd->robe;
  1097. offset+= 2;
  1098. buf = WBUFP(buffer,offset);
  1099. #endif
  1100. WBUFL(buf,38) = status_get_guild_id(bl);
  1101. WBUFW(buf,42) = status_get_emblem_id(bl);
  1102. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  1103. #if PACKETVER < 7
  1104. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  1105. #else
  1106. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  1107. offset+=2; //Shift the rest of elements by 2 bytes.
  1108. buf = WBUFP(buffer,offset);
  1109. #endif
  1110. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  1111. WBUFB(buf,49) = vd->sex;
  1112. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1113. WBUFB(buf,56) = (sd)? 5 : 0;
  1114. WBUFB(buf,57) = (sd)? 5 : 0;
  1115. WBUFW(buf,58) = clif_setlevel(bl);
  1116. #if PACKETVER >= 20080102
  1117. WBUFW(buf,60) = (sd ? sd->status.font : 0);
  1118. #endif
  1119. #if PACKETVER >= 20120221
  1120. if ( battle_config.monster_hp_bars_info && !map[bl->m].flag.hidemobhpbar && bl->type == BL_MOB && (status_get_hp(bl) < status_get_max_hp(bl)) ) {
  1121. WBUFL(buf,62) = status_get_max_hp(bl); // maxHP
  1122. WBUFL(buf,66) = status_get_hp(bl); // HP
  1123. } else {
  1124. WBUFL(buf,62) = -1; // maxHP
  1125. WBUFL(buf,66) = -1; // HP
  1126. }
  1127. WBUFB(buf,70) = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0; // isBoss
  1128. #endif
  1129. #if PACKETVER >= 20150513
  1130. WBUFW(buf,71) = vd->body_style; // body
  1131. offset+= 2;
  1132. buf = WBUFP(buffer,offset);
  1133. #endif
  1134. #if PACKETVER >= 20091103
  1135. #if PACKETVER >= 20120221
  1136. safestrncpy(WBUFCP(buf,71), name, NAME_LENGTH);
  1137. #else
  1138. safestrncpy(WBUFCP(buf,62), name, NAME_LENGTH);
  1139. #endif
  1140. return WBUFW(buffer,2);
  1141. #else
  1142. return packet_len(WBUFW(buffer,0));
  1143. #endif
  1144. }
  1145. //Modifies the buffer for disguise characters and sends it to self.
  1146. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1147. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1148. {
  1149. #if PACKETVER >= 20091103
  1150. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1151. WBUFL(buf,5)=-bl->id;
  1152. #elif PACKETVER >= 20071106
  1153. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1154. WBUFL(buf,3)=-bl->id;
  1155. #else
  1156. WBUFL(buf,2)=-bl->id;
  1157. #endif
  1158. clif_send(buf, len, bl, SELF);
  1159. }
  1160. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1161. /// 01b0 <id>.L <type>.B <value>.L
  1162. /// type:
  1163. /// unused
  1164. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, struct map_session_data *sd)
  1165. {
  1166. nullpo_retv(bl);
  1167. if(!pcdb_checkid(class_))
  1168. {// player classes yield missing sprites
  1169. unsigned char buf[16];
  1170. WBUFW(buf,0)=0x1b0;
  1171. WBUFL(buf,2)=bl->id;
  1172. WBUFB(buf,6)=type;
  1173. WBUFL(buf,7)=class_;
  1174. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1175. }
  1176. }
  1177. /// Notifies the client of an object's spirits.
  1178. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1179. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1180. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1181. {
  1182. WFIFOHEAD(fd, packet_len(0x1e1));
  1183. WFIFOW(fd,0)=0x1e1;
  1184. WFIFOL(fd,2)=sd->bl.id;
  1185. WFIFOW(fd,6)=sd->spiritball;
  1186. WFIFOSET(fd, packet_len(0x1e1));
  1187. }
  1188. /*==========================================
  1189. * Kagerou/Oboro amulet spirit
  1190. *------------------------------------------*/
  1191. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1192. {
  1193. WFIFOHEAD(fd, packet_len(0x08cf));
  1194. WFIFOW(fd,0)=0x08cf;
  1195. WFIFOL(fd,2)=sd->bl.id;
  1196. WFIFOW(fd,6)=sd->spiritcharm_type;
  1197. WFIFOW(fd,8)=sd->spiritcharm;
  1198. WFIFOSET(fd, packet_len(0x08cf));
  1199. }
  1200. /*==========================================
  1201. * Run when player changes map / refreshes
  1202. * Tells its client to display all weather settings being used by this map
  1203. *------------------------------------------*/
  1204. static void clif_weather_check(struct map_session_data *sd)
  1205. {
  1206. int16 m = sd->bl.m;
  1207. int fd = sd->fd;
  1208. if (map[m].flag.snow
  1209. || map[m].flag.clouds
  1210. || map[m].flag.fog
  1211. || map[m].flag.fireworks
  1212. || map[m].flag.sakura
  1213. || map[m].flag.leaves
  1214. || map[m].flag.clouds2)
  1215. {
  1216. if (map[m].flag.snow)
  1217. clif_specialeffect_single(&sd->bl, 162, fd);
  1218. if (map[m].flag.clouds)
  1219. clif_specialeffect_single(&sd->bl, 233, fd);
  1220. if (map[m].flag.clouds2)
  1221. clif_specialeffect_single(&sd->bl, 516, fd);
  1222. if (map[m].flag.fog)
  1223. clif_specialeffect_single(&sd->bl, 515, fd);
  1224. if (map[m].flag.fireworks) {
  1225. clif_specialeffect_single(&sd->bl, 297, fd);
  1226. clif_specialeffect_single(&sd->bl, 299, fd);
  1227. clif_specialeffect_single(&sd->bl, 301, fd);
  1228. }
  1229. if (map[m].flag.sakura)
  1230. clif_specialeffect_single(&sd->bl, 163, fd);
  1231. if (map[m].flag.leaves)
  1232. clif_specialeffect_single(&sd->bl, 333, fd);
  1233. }
  1234. }
  1235. /**
  1236. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1237. **/
  1238. void clif_weather(int16 m)
  1239. {
  1240. struct s_mapiterator* iter;
  1241. struct map_session_data *sd=NULL;
  1242. iter = mapit_getallusers();
  1243. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1244. {
  1245. if( sd->bl.m == m )
  1246. clif_weather_check(sd);
  1247. }
  1248. mapit_free(iter);
  1249. }
  1250. /**
  1251. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1252. **/
  1253. int clif_spawn(struct block_list *bl)
  1254. {
  1255. unsigned char buf[128];
  1256. struct view_data *vd;
  1257. int len;
  1258. vd = status_get_viewdata(bl);
  1259. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1260. return 0;
  1261. /**
  1262. * Hide NPC from maya purple card.
  1263. **/
  1264. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1265. return 0;
  1266. len = clif_set_unit_idle(bl, buf,true);
  1267. clif_send(buf, len, bl, AREA_WOS);
  1268. if (disguised(bl))
  1269. clif_setdisguise(bl, buf, len);
  1270. if (vd->cloth_color)
  1271. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1272. if (vd->body_style)
  1273. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1274. switch (bl->type)
  1275. {
  1276. case BL_PC:
  1277. {
  1278. TBL_PC *sd = ((TBL_PC*)bl);
  1279. if (sd->spiritball > 0)
  1280. clif_spiritball(&sd->bl);
  1281. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1282. clif_specialeffect(bl,423,AREA);
  1283. else if(sd->state.size==SZ_MEDIUM)
  1284. clif_specialeffect(bl,421,AREA);
  1285. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1286. clif_sendbgemblem_area(sd);
  1287. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1288. clif_spiritcharm(sd);
  1289. if (sd->status.robe)
  1290. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1291. clif_efst_status_change_sub(bl, bl, AREA);
  1292. clif_hat_effects(sd,bl,AREA);
  1293. }
  1294. break;
  1295. case BL_MOB:
  1296. {
  1297. TBL_MOB *md = ((TBL_MOB*)bl);
  1298. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1299. clif_specialeffect(&md->bl,423,AREA);
  1300. else if(md->special_state.size==SZ_MEDIUM)
  1301. clif_specialeffect(&md->bl,421,AREA);
  1302. }
  1303. break;
  1304. case BL_NPC:
  1305. {
  1306. TBL_NPC *nd = ((TBL_NPC*)bl);
  1307. if( nd->size == SZ_BIG )
  1308. clif_specialeffect(&nd->bl,423,AREA);
  1309. else if( nd->size == SZ_MEDIUM )
  1310. clif_specialeffect(&nd->bl,421,AREA);
  1311. clif_efst_status_change_sub(bl, bl, AREA);
  1312. clif_progressbar_npc_area(nd);
  1313. }
  1314. break;
  1315. case BL_PET:
  1316. if (vd->head_bottom)
  1317. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1318. break;
  1319. }
  1320. return 0;
  1321. }
  1322. /// Sends information about owned homunculus to the client . [orn]
  1323. /// 022e <name>.24B <modified>.B <level>.W <hunger>.W <intimacy>.W <equip id>.W <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W <hp>.W <max hp>.W <sp>.W <max sp>.W <exp>.L <max exp>.L <skill points>.W <atk range>.W (ZC_PROPERTY_HOMUN)
  1324. /// 09f7 <name>.24B <modified>.B <level>.W <hunger>.W <intimacy>.W <equip id>.W <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W <hp>.L <max hp>.L <sp>.W <max sp>.W <exp>.L <max exp>.L <skill points>.W <atk range>.W (ZC_PROPERTY_HOMUN_2)
  1325. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1326. {
  1327. struct status_data *status;
  1328. unsigned char buf[128];
  1329. int offset;
  1330. #if PACKETVER < 20141016
  1331. const int cmd = 0x22e;
  1332. #else
  1333. const int cmd = 0x9f7;
  1334. #endif
  1335. int htype;
  1336. nullpo_retv(hd);
  1337. if (!clif_session_isValid(sd))
  1338. return;
  1339. status = &hd->battle_status;
  1340. htype = hom_class2type(hd->homunculus.class_);
  1341. memset(buf,0,packet_len(cmd));
  1342. WBUFW(buf,0) = cmd;
  1343. safestrncpy(WBUFCP(buf,2), hd->homunculus.name, NAME_LENGTH);
  1344. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1345. WBUFB(buf,26) = (battle_config.hom_rename ? 0 : hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp ? 0 : 4);
  1346. WBUFW(buf,27) = hd->homunculus.level;
  1347. WBUFW(buf,29) = hd->homunculus.hunger;
  1348. WBUFW(buf,31) = (unsigned short) (hd->homunculus.intimacy / 100) ;
  1349. WBUFW(buf,33) = 0; // equip id
  1350. #ifdef RENEWAL
  1351. WBUFW(buf,35) = cap_value(status->rhw.atk2, 0, INT16_MAX);
  1352. #else
  1353. WBUFW(buf,35) = cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1354. #endif
  1355. WBUFW(buf,37)=i16min(status->matk_max, INT16_MAX); //FIXME capping to INT16 here is too late
  1356. WBUFW(buf,39)=status->hit;
  1357. if (battle_config.hom_setting&HOMSET_DISPLAY_LUK)
  1358. WBUFW(buf,41) = status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1359. else
  1360. WBUFW(buf,41) = status->cri/10;
  1361. #ifdef RENEWAL
  1362. WBUFW(buf,43) = status->def + status->def2;
  1363. WBUFW(buf,45) = status->mdef + status->mdef2;
  1364. #else
  1365. WBUFW(buf,43) = status->def + status->vit;
  1366. WBUFW(buf,45) = status->mdef;
  1367. #endif
  1368. WBUFW(buf,47) = status->flee;
  1369. WBUFW(buf,49) = (flag) ? 0 : status->amotion;
  1370. #if PACKETVER >= 20141016
  1371. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1372. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1373. if (status->max_hp > (INT32_MAX/100)) {
  1374. WBUFL(buf,51) = status->hp/(status->max_hp/100);
  1375. WBUFL(buf,55) = 100;
  1376. } else {
  1377. WBUFL(buf,51) = status->hp;
  1378. WBUFL(buf,55) = status->max_hp;
  1379. }
  1380. offset = 4;
  1381. #else
  1382. if (status->max_hp > INT16_MAX) {
  1383. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1384. WBUFW(buf,53) = 100;
  1385. } else {
  1386. WBUFW(buf,51) = status->hp;
  1387. WBUFW(buf,53) = status->max_hp;
  1388. }
  1389. offset = 0;
  1390. #endif
  1391. if (status->max_sp > INT16_MAX) {
  1392. WBUFW(buf,55+offset) = status->sp/(status->max_sp/100);
  1393. WBUFW(buf,57+offset) = 100;
  1394. } else {
  1395. WBUFW(buf,55+offset) = status->sp;
  1396. WBUFW(buf,57+offset) = status->max_sp;
  1397. }
  1398. WBUFL(buf,59+offset) = hd->homunculus.exp;
  1399. WBUFL(buf,63+offset) = hd->exp_next;
  1400. switch( htype ) {
  1401. case HT_REG:
  1402. case HT_EVO:
  1403. if( hd->homunculus.level >= battle_config.hom_max_level )
  1404. WBUFL(buf,63+offset) = 0;
  1405. break;
  1406. case HT_S:
  1407. if( hd->homunculus.level >= battle_config.hom_S_max_level )
  1408. WBUFL(buf,63+offset) = 0;
  1409. break;
  1410. }
  1411. WBUFW(buf,67+offset) = hd->homunculus.skillpts;
  1412. WBUFW(buf,69+offset) = status_get_range(&hd->bl);
  1413. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  1414. }
  1415. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1416. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1417. /// type:
  1418. /// unused
  1419. /// state:
  1420. /// 0 = pre-init
  1421. /// 1 = intimacy
  1422. /// 2 = hunger
  1423. /// 3 = accessory?
  1424. /// ? = ignored
  1425. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1426. { //[orn]
  1427. int fd = sd->fd;
  1428. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1429. hom_calc_skilltree(sd->hd, 0);
  1430. WFIFOHEAD(fd, packet_len(0x230));
  1431. WFIFOW(fd,0)=0x230;
  1432. WFIFOB(fd,2)=0;
  1433. WFIFOB(fd,3)=state;
  1434. WFIFOL(fd,4)=sd->hd->bl.id;
  1435. WFIFOL(fd,8)=param;
  1436. WFIFOSET(fd,packet_len(0x230));
  1437. }
  1438. int clif_homskillinfoblock(struct map_session_data *sd)
  1439. { //[orn]
  1440. struct homun_data *hd;
  1441. int fd = sd->fd;
  1442. int i, len=4;
  1443. nullpo_ret(sd);
  1444. hd = sd->hd;
  1445. if ( !hd )
  1446. return 0 ;
  1447. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1448. WFIFOW(fd,0)=0x235;
  1449. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1450. int id = hd->homunculus.hskill[i].id;
  1451. if( id != 0 ){
  1452. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1453. short idx = hom_skill_get_index(id);
  1454. if (idx == -1)
  1455. continue;
  1456. WFIFOW(fd,len ) = id;
  1457. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1458. WFIFOW(fd,len+4) = 0;
  1459. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1460. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1461. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1462. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1463. WFIFOB(fd,len+36) = (hd->homunculus.level < hom_skill_get_min_level(hd->homunculus.class_, id) || hd->homunculus.hskill[idx].lv >= hom_skill_tree_get_max(id, hd->homunculus.class_)) ? 0 : 1;
  1464. len+=37;
  1465. }
  1466. }
  1467. WFIFOW(fd,2)=len;
  1468. WFIFOSET(fd,len);
  1469. return 0;
  1470. }
  1471. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1472. { //[orn]
  1473. struct homun_data *hd;
  1474. int fd;
  1475. short idx = -1;
  1476. nullpo_retv(sd);
  1477. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1478. return;
  1479. fd = sd->fd;
  1480. hd = sd->hd;
  1481. WFIFOHEAD(fd, packet_len(0x239));
  1482. WFIFOW(fd,0) = 0x239;
  1483. WFIFOW(fd,2) = skill_id;
  1484. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1485. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1486. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1487. WFIFOB(fd,10) = (hd->homunculus.level < hom_skill_get_min_level(hd->homunculus.class_, skill_id) || hd->homunculus.hskill[idx].lv >= hom_skill_tree_get_max(hd->homunculus.hskill[idx].id, hd->homunculus.class_)) ? 0 : 1;
  1488. WFIFOSET(fd,packet_len(0x239));
  1489. }
  1490. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1491. {
  1492. int fd=sd->fd;
  1493. WFIFOHEAD(fd,packet_len(0x22f));
  1494. WFIFOW(fd,0)=0x22f;
  1495. WFIFOB(fd,2)=fail;
  1496. WFIFOW(fd,3)=foodid;
  1497. WFIFOSET(fd,packet_len(0x22f));
  1498. return 0;
  1499. }
  1500. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1501. /// 0087 <walk start time>.L <walk data>.6B
  1502. void clif_walkok(struct map_session_data *sd)
  1503. {
  1504. int fd=sd->fd;
  1505. WFIFOHEAD(fd, packet_len(0x87));
  1506. WFIFOW(fd,0)=0x87;
  1507. WFIFOL(fd,2)=gettick();
  1508. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1509. WFIFOSET(fd,packet_len(0x87));
  1510. }
  1511. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1512. {
  1513. uint8 buf[128];
  1514. int len;
  1515. struct status_change *sc = NULL;
  1516. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1517. clif_ally_only = true;
  1518. len = clif_set_unit_walking(bl,ud,buf);
  1519. clif_send(buf,len,bl,AREA_WOS);
  1520. if (disguised(bl))
  1521. clif_setdisguise(bl, buf, len);
  1522. if(vd->cloth_color)
  1523. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1524. if(vd->body_style)
  1525. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1526. switch(bl->type) {
  1527. case BL_PC:
  1528. {
  1529. TBL_PC *sd = ((TBL_PC*)bl);
  1530. // clif_movepc(sd);
  1531. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1532. clif_specialeffect(&sd->bl,423,AREA);
  1533. else if(sd->state.size==SZ_MEDIUM)
  1534. clif_specialeffect(&sd->bl,421,AREA);
  1535. if (sd->status.robe)
  1536. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1537. }
  1538. break;
  1539. case BL_MOB:
  1540. {
  1541. TBL_MOB *md = ((TBL_MOB*)bl);
  1542. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1543. clif_specialeffect(&md->bl,423,AREA);
  1544. else if(md->special_state.size==SZ_MEDIUM)
  1545. clif_specialeffect(&md->bl,421,AREA);
  1546. }
  1547. break;
  1548. case BL_PET:
  1549. if(vd->head_bottom) // needed to display pet equip properly
  1550. clif_pet_equip_area((TBL_PET*)bl);
  1551. break;
  1552. }
  1553. clif_ally_only = false;
  1554. }
  1555. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1556. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1557. /// Note: unit must not be self
  1558. void clif_move(struct unit_data *ud)
  1559. {
  1560. unsigned char buf[16];
  1561. struct view_data* vd;
  1562. struct block_list* bl = ud->bl;
  1563. struct status_change *sc = NULL;
  1564. vd = status_get_viewdata(bl);
  1565. if (!vd )
  1566. return;
  1567. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1568. else if( vd->class_ == INVISIBLE_CLASS ){
  1569. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1570. if(disguised(bl)) {
  1571. WBUFW(buf,0)=0x86;
  1572. WBUFL(buf,2)=-bl->id;
  1573. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1574. WBUFL(buf,12)=gettick();
  1575. clif_send(buf, packet_len(0x86), bl, SELF);
  1576. }
  1577. return;
  1578. }
  1579. /**
  1580. * Hide NPC from maya purple card.
  1581. **/
  1582. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1583. return;
  1584. if (ud->state.speed_changed) {
  1585. // Since we don't know how to update the speed of other objects,
  1586. // use the old walk packet to update the data.
  1587. ud->state.speed_changed = 0;
  1588. clif_move2(bl, vd, ud);
  1589. return;
  1590. }
  1591. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1592. clif_ally_only = true;
  1593. WBUFW(buf,0)=0x86;
  1594. WBUFL(buf,2)=bl->id;
  1595. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1596. WBUFL(buf,12)=gettick();
  1597. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1598. if (disguised(bl)) {
  1599. WBUFL(buf,2)=-bl->id;
  1600. clif_send(buf, packet_len(0x86), bl, SELF);
  1601. }
  1602. clif_ally_only = false;
  1603. }
  1604. /*==========================================
  1605. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1606. *------------------------------------------*/
  1607. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1608. {
  1609. struct map_session_data *sd = NULL;
  1610. //Remove player from map server
  1611. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1612. map_quit(sd);
  1613. return 0;
  1614. }
  1615. /*==========================================
  1616. *
  1617. *------------------------------------------*/
  1618. void clif_quitsave(int fd,struct map_session_data *sd) {
  1619. if (!battle_config.prevent_logout ||
  1620. sd->canlog_tick == 0 ||
  1621. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1622. map_quit(sd);
  1623. else if (sd->fd) {
  1624. //Disassociate session from player (session is deleted after this function was called)
  1625. //And set a timer to make him quit later.
  1626. session[sd->fd]->session_data = NULL;
  1627. sd->fd = 0;
  1628. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1629. }
  1630. }
  1631. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1632. /// 0091 <map name>.16B <x>.W <y>.W
  1633. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1634. {
  1635. int fd;
  1636. nullpo_retv(sd);
  1637. fd = sd->fd;
  1638. WFIFOHEAD(fd,packet_len(0x91));
  1639. WFIFOW(fd,0) = 0x91;
  1640. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1641. WFIFOW(fd,18) = x;
  1642. WFIFOW(fd,20) = y;
  1643. WFIFOSET(fd,packet_len(0x91));
  1644. }
  1645. /// Notifies the client of a position change to coordinates on given map, which is on another map-server (ZC_NPCACK_SERVERMOVE).
  1646. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W
  1647. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1648. {
  1649. int fd;
  1650. nullpo_retv(sd);
  1651. fd = sd->fd;
  1652. WFIFOHEAD(fd,packet_len(0x92));
  1653. WFIFOW(fd,0) = 0x92;
  1654. mapindex_getmapname_ext(mapindex_id2name(map_index), WFIFOCP(fd,2));
  1655. WFIFOW(fd,18) = x;
  1656. WFIFOW(fd,20) = y;
  1657. WFIFOL(fd,22) = htonl(ip);
  1658. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1659. WFIFOSET(fd,packet_len(0x92));
  1660. }
  1661. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1662. /// This function combines both calls and allows to simplify the calling code
  1663. void clif_blown(struct block_list *bl)
  1664. {
  1665. clif_slide(bl, bl->x, bl->y);
  1666. clif_fixpos(bl);
  1667. }
  1668. /// Visually moves(slides) a character to x,y. If the target cell
  1669. /// isn't walkable, the char doesn't move at all. If the char is
  1670. /// sitting it will stand up (ZC_STOPMOVE).
  1671. /// 0088 <id>.L <x>.W <y>.W
  1672. void clif_fixpos(struct block_list *bl)
  1673. {
  1674. unsigned char buf[10];
  1675. nullpo_retv(bl);
  1676. WBUFW(buf,0) = 0x88;
  1677. WBUFL(buf,2) = bl->id;
  1678. WBUFW(buf,6) = bl->x;
  1679. WBUFW(buf,8) = bl->y;
  1680. clif_send(buf, packet_len(0x88), bl, AREA);
  1681. if( disguised(bl) ) {
  1682. WBUFL(buf,2) = -bl->id;
  1683. clif_send(buf, packet_len(0x88), bl, SELF);
  1684. }
  1685. }
  1686. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1687. /// 00c4 <shop id>.L
  1688. void clif_npcbuysell(struct map_session_data* sd, int id)
  1689. {
  1690. int fd;
  1691. nullpo_retv(sd);
  1692. fd=sd->fd;
  1693. WFIFOHEAD(fd, packet_len(0xc4));
  1694. WFIFOW(fd,0)=0xc4;
  1695. WFIFOL(fd,2)=id;
  1696. WFIFOSET(fd,packet_len(0xc4));
  1697. }
  1698. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1699. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1700. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1701. {
  1702. int fd,i,c;
  1703. bool discount;
  1704. nullpo_retv(sd);
  1705. nullpo_retv(nd);
  1706. fd = sd->fd;
  1707. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1708. WFIFOW(fd,0) = 0xc6;
  1709. c = 0;
  1710. discount = npc_shop_discount(nd->subtype,nd->u.shop.discount);
  1711. for( i = 0; i < nd->u.shop.count; i++ )
  1712. {
  1713. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1714. int val = nd->u.shop.shop_item[i].value;
  1715. if( id == NULL )
  1716. continue;
  1717. WFIFOL(fd, 4+c*11) = val;
  1718. WFIFOL(fd, 8+c*11) = (discount) ? pc_modifybuyvalue(sd,val) : val;
  1719. WFIFOB(fd,12+c*11) = itemtype(id->nameid);
  1720. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1721. c++;
  1722. }
  1723. WFIFOW(fd,2) = 4 + c*11;
  1724. WFIFOSET(fd,WFIFOW(fd,2));
  1725. }
  1726. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1727. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1728. void clif_selllist(struct map_session_data *sd)
  1729. {
  1730. int fd,i,c=0,val;
  1731. nullpo_retv(sd);
  1732. fd=sd->fd;
  1733. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1734. WFIFOW(fd,0)=0xc7;
  1735. for( i = 0; i < MAX_INVENTORY; i++ )
  1736. {
  1737. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1738. {
  1739. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i]))
  1740. continue;
  1741. val=sd->inventory_data[i]->value_sell;
  1742. if( val < 0 )
  1743. continue;
  1744. WFIFOW(fd,4+c*10)=i+2;
  1745. WFIFOL(fd,6+c*10)=val;
  1746. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1747. c++;
  1748. }
  1749. }
  1750. WFIFOW(fd,2)=c*10+4;
  1751. WFIFOSET(fd,WFIFOW(fd,2));
  1752. }
  1753. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1754. /// 09d4
  1755. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1756. // TODO: State tracking?
  1757. sd->npc_shopid = 0;
  1758. }
  1759. /**
  1760. * Presents list of items, that can be sold to a Market shop.
  1761. * @author: Ind and Yommy
  1762. **/
  1763. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1764. #if PACKETVER >= 20131223
  1765. struct npc_item_list *shop = nd->u.shop.shop_item;
  1766. unsigned short shop_size = nd->u.shop.count, i, c, cmd = 0x9d5;
  1767. struct item_data *id = NULL;
  1768. struct s_packet_db *info;
  1769. int fd;
  1770. nullpo_retv(sd);
  1771. if (sd->state.trading)
  1772. return;
  1773. info = &packet_db[cmd];
  1774. if (!info || info->len == 0)
  1775. return;
  1776. fd = sd->fd;
  1777. WFIFOHEAD(fd, 4 + shop_size * 13);
  1778. WFIFOW(fd,0) = cmd;
  1779. for (i = 0, c = 0; i < shop_size; i++) {
  1780. if (shop[i].nameid && (id = itemdb_exists(shop[i].nameid))) {
  1781. WFIFOW(fd, 4+c*13) = shop[i].nameid;
  1782. WFIFOB(fd, 6+c*13) = itemtype(id->nameid);
  1783. WFIFOL(fd, 7+c*13) = shop[i].value;
  1784. WFIFOL(fd,11+c*13) = shop[i].qty;
  1785. WFIFOW(fd,15+c*13) = id->weight;
  1786. c++;
  1787. }
  1788. }
  1789. WFIFOW(fd,2) = 4 + c*13;
  1790. WFIFOSET(fd,WFIFOW(fd,2));
  1791. sd->state.trading = 1;
  1792. #endif
  1793. }
  1794. /// Closes the Market shop window.
  1795. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  1796. nullpo_retv(sd);
  1797. sd->npc_shopid = 0;
  1798. sd->state.trading = 0;
  1799. }
  1800. /// Purchase item from Market shop.
  1801. void clif_npc_market_purchase_ack(struct map_session_data *sd, uint8 res, uint8 n, struct s_npc_buy_list *list) {
  1802. #if PACKETVER >= 20131223
  1803. unsigned short cmd = 0x9d7, len = 0;
  1804. struct npc_data* nd;
  1805. uint8 result = (res == 0 ? 1 : 0);
  1806. int fd = 0;
  1807. struct s_packet_db *info;
  1808. nullpo_retv(sd);
  1809. nullpo_retv((nd = map_id2nd(sd->npc_shopid)));
  1810. info = &packet_db[cmd];
  1811. if (!info || info->len == 0)
  1812. return;
  1813. fd = sd->fd;
  1814. len = 5 + 8*n;
  1815. WFIFOHEAD(fd, len);
  1816. WFIFOW(fd, 0) = cmd;
  1817. WFIFOW(fd, 2) = len;
  1818. if (result) {
  1819. uint8 i, j;
  1820. struct npc_item_list *shop = nd->u.shop.shop_item;
  1821. unsigned short count = nd->u.shop.count;
  1822. for (i = 0; i < n; i++) {
  1823. WFIFOW(fd, 5+i*8) = list[i].nameid;
  1824. WFIFOW(fd, 7+i*8) = list[i].qty;
  1825. ARR_FIND(0, count, j, list[i].nameid == shop[j].nameid);
  1826. WFIFOL(fd, 9+i*8) = (j != count) ? shop[j].value : 0;
  1827. }
  1828. }
  1829. WFIFOB(fd, 4) = n;
  1830. WFIFOSET(fd, len);
  1831. #endif
  1832. }
  1833. /// Purchase item from Market shop.
  1834. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  1835. #if PACKETVER >= 20131223
  1836. struct s_packet_db* info;
  1837. struct s_npc_buy_list *item_list;
  1838. uint16 len = 0, i = 0;
  1839. uint8 res = 0, n = 0;
  1840. nullpo_retv(sd);
  1841. if (!sd->npc_shopid)
  1842. return;
  1843. info = &packet_db[RFIFOW(fd,0)];
  1844. if (!info || info->len == 0)
  1845. return;
  1846. len = RFIFOW(fd,info->pos[0]);
  1847. n = (len-4) / 6;
  1848. CREATE(item_list, struct s_npc_buy_list, n);
  1849. for (i = 0; i < n; i++) {
  1850. item_list[i].nameid = RFIFOW(fd,info->pos[1]+i*6);
  1851. item_list[i].qty = (uint16)min(RFIFOL(fd,info->pos[2]+i*6),USHRT_MAX);
  1852. }
  1853. res = npc_buylist(sd, n, item_list);
  1854. clif_npc_market_purchase_ack(sd, res, n, item_list);
  1855. aFree(item_list);
  1856. #endif
  1857. }
  1858. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1859. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1860. /// Client behavior (dialog window):
  1861. /// - disable mouse targeting
  1862. /// - open the dialog window
  1863. /// - set npcid of dialog window (0 by default)
  1864. /// - if set to clear on next mes, clear contents
  1865. /// - append this text
  1866. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1867. {
  1868. int fd = sd->fd;
  1869. int slen = strlen(mes) + 9;
  1870. WFIFOHEAD(fd, slen);
  1871. WFIFOW(fd,0)=0xb4;
  1872. WFIFOW(fd,2)=slen;
  1873. WFIFOL(fd,4)=npcid;
  1874. memcpy(WFIFOCP(fd,8), mes, slen-8);
  1875. WFIFOSET(fd,WFIFOW(fd,2));
  1876. }
  1877. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1878. /// 00b5 <npc id>.L
  1879. /// Client behavior (dialog window):
  1880. /// - disable mouse targeting
  1881. /// - open the dialog window
  1882. /// - add 'next' button
  1883. /// When 'next' is pressed:
  1884. /// - 00B9 <npcid of dialog window>.L
  1885. /// - set to clear on next mes
  1886. /// - remove 'next' button
  1887. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1888. {
  1889. int fd;
  1890. nullpo_retv(sd);
  1891. fd=sd->fd;
  1892. WFIFOHEAD(fd, packet_len(0xb5));
  1893. WFIFOW(fd,0)=0xb5;
  1894. WFIFOL(fd,2)=npcid;
  1895. WFIFOSET(fd,packet_len(0xb5));
  1896. }
  1897. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1898. /// 00b6 <npc id>.L
  1899. /// Client behavior:
  1900. /// - if dialog window is open:
  1901. /// - remove 'next' button
  1902. /// - add 'close' button
  1903. /// - else:
  1904. /// - enable mouse targeting
  1905. /// - close the dialog window
  1906. /// - close the menu window
  1907. /// When 'close' is pressed:
  1908. /// - enable mouse targeting
  1909. /// - close the dialog window
  1910. /// - close the menu window
  1911. /// - 0146 <npcid of dialog window>.L
  1912. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1913. {
  1914. int fd;
  1915. nullpo_retv(sd);
  1916. fd=sd->fd;
  1917. WFIFOHEAD(fd, packet_len(0xb6));
  1918. WFIFOW(fd,0)=0xb6;
  1919. WFIFOL(fd,2)=npcid;
  1920. WFIFOSET(fd,packet_len(0xb6));
  1921. }
  1922. /**
  1923. * Close script when player is idle
  1924. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  1925. * @author [Ind/Hercules]
  1926. * @param sd : player pointer
  1927. * @param npcid : npc gid to close
  1928. */
  1929. void clif_scriptclear(struct map_session_data *sd, int npcid)
  1930. {
  1931. struct s_packet_db* info;
  1932. int16 len;
  1933. int cmd = 0;
  1934. int fd;
  1935. nullpo_retv(sd);
  1936. cmd = packet_db_ack[ZC_CLEAR_DIALOG];
  1937. if(!cmd) cmd = 0x8d6; //default
  1938. info = &packet_db[cmd];
  1939. len = info->len;
  1940. fd = sd->fd;
  1941. WFIFOHEAD(fd, len);
  1942. WFIFOW(fd,0)=0x8d6;
  1943. WFIFOL(fd,info->pos[0])=npcid;
  1944. WFIFOSET(fd,len);
  1945. }
  1946. /*==========================================
  1947. *
  1948. *------------------------------------------*/
  1949. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1950. unsigned char *buf;
  1951. int fd = sd->fd;
  1952. sd->state.using_fake_npc = 1;
  1953. WFIFOHEAD(fd, packet_len(0x78));
  1954. buf = WFIFOP(fd,0);
  1955. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1956. WBUFW(buf,0)=0x78;
  1957. #if PACKETVER >= 20071106
  1958. WBUFB(buf,2) = 0; // object type
  1959. buf = WFIFOP(fd,1);
  1960. #endif
  1961. WBUFL(buf,2)=npcid;
  1962. WBUFW(buf,14)=111;
  1963. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1964. WBUFB(buf,49)=5;
  1965. WBUFB(buf,50)=5;
  1966. WFIFOSET(fd, packet_len(0x78));
  1967. }
  1968. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1969. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1970. /// Client behavior:
  1971. /// - disable mouse targeting
  1972. /// - close the menu window
  1973. /// - open the menu window
  1974. /// - add options to the menu (separated in the text by ":")
  1975. /// - set npcid of menu window
  1976. /// - if dialog window is open:
  1977. /// - remove 'next' button
  1978. /// When 'ok' is pressed:
  1979. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1980. /// - close the menu window
  1981. /// When 'cancel' is pressed:
  1982. /// - 00B8 <npcid of menu window>.L <-1>.B
  1983. /// - enable mouse targeting
  1984. /// - close a bunch of windows...
  1985. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1986. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1987. /// TODO investigate behavior of other windows [FlavioJS]
  1988. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1989. {
  1990. int fd = sd->fd;
  1991. int slen = strlen(mes) + 9;
  1992. struct block_list *bl = NULL;
  1993. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1994. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1995. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1996. clif_sendfakenpc(sd, npcid);
  1997. WFIFOHEAD(fd, slen);
  1998. WFIFOW(fd,0)=0xb7;
  1999. WFIFOW(fd,2)=slen;
  2000. WFIFOL(fd,4)=npcid;
  2001. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2002. WFIFOSET(fd,WFIFOW(fd,2));
  2003. }
  2004. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2005. /// 0142 <npc id>.L
  2006. /// Client behavior (inputnum window):
  2007. /// - if npcid exists in the client:
  2008. /// - open the inputnum window
  2009. /// - set npcid of inputnum window
  2010. /// When 'ok' is pressed:
  2011. /// - if inputnum window has text:
  2012. /// - if npcid exists in the client:
  2013. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2014. /// - close inputnum window
  2015. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2016. {
  2017. int fd;
  2018. struct block_list *bl = NULL;
  2019. nullpo_retv(sd);
  2020. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2021. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2022. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2023. clif_sendfakenpc(sd, npcid);
  2024. fd=sd->fd;
  2025. WFIFOHEAD(fd, packet_len(0x142));
  2026. WFIFOW(fd,0)=0x142;
  2027. WFIFOL(fd,2)=npcid;
  2028. WFIFOSET(fd,packet_len(0x142));
  2029. }
  2030. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2031. /// 01d4 <npc id>.L
  2032. /// Client behavior (inputstr window):
  2033. /// - if npcid is 0 or npcid exists in the client:
  2034. /// - open the inputstr window
  2035. /// - set npcid of inputstr window
  2036. /// When 'ok' is pressed:
  2037. /// - if inputstr window has text and isn't an insult(manner.txt):
  2038. /// - if npcid is 0 or npcid exists in the client:
  2039. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2040. /// - close inputstr window
  2041. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2042. {
  2043. int fd;
  2044. struct block_list *bl = NULL;
  2045. nullpo_retv(sd);
  2046. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2047. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2048. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2049. clif_sendfakenpc(sd, npcid);
  2050. fd=sd->fd;
  2051. WFIFOHEAD(fd, packet_len(0x1d4));
  2052. WFIFOW(fd,0)=0x1d4;
  2053. WFIFOL(fd,2)=npcid;
  2054. WFIFOSET(fd,packet_len(0x1d4));
  2055. }
  2056. /// Marks a position on client's minimap (ZC_COMPASS).
  2057. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2058. /// npc id:
  2059. /// is ignored in the client
  2060. /// type:
  2061. /// 0 = display mark for 15 seconds
  2062. /// 1 = display mark until dead or teleported
  2063. /// 2 = remove mark
  2064. /// color:
  2065. /// 0x00RRGGBB
  2066. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2067. {
  2068. int fd;
  2069. nullpo_retv(sd);
  2070. fd=sd->fd;
  2071. WFIFOHEAD(fd, packet_len(0x144));
  2072. WFIFOW(fd,0)=0x144;
  2073. WFIFOL(fd,2)=npc_id;
  2074. WFIFOL(fd,6)=type;
  2075. WFIFOL(fd,10)=x;
  2076. WFIFOL(fd,14)=y;
  2077. WFIFOB(fd,18)=id;
  2078. WFIFOL(fd,19)=color;
  2079. WFIFOSET(fd,packet_len(0x144));
  2080. }
  2081. /// Displays an illustration image.
  2082. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2083. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2084. /// type:
  2085. /// 0 = bottom left corner
  2086. /// 1 = bottom middle
  2087. /// 2 = bottom right corner
  2088. /// 3 = middle of screen, inside a movable window
  2089. /// 4 = middle of screen, movable with a close button, chrome-less
  2090. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2091. {
  2092. int fd;
  2093. nullpo_retv(sd);
  2094. fd=sd->fd;
  2095. WFIFOHEAD(fd, packet_len(0x1b3));
  2096. WFIFOW(fd,0)=0x1b3;
  2097. strncpy(WFIFOCP(fd,2),image,64);
  2098. WFIFOB(fd,66)=type;
  2099. WFIFOSET(fd,packet_len(0x1b3));
  2100. }
  2101. /*==========================================
  2102. * Fills in card data from the given item and into the buffer. [Skotlex]
  2103. *------------------------------------------*/
  2104. static void clif_addcards(unsigned char* buf, struct item* item)
  2105. {
  2106. int i=0,j;
  2107. if( item == NULL ) { //Blank data
  2108. WBUFW(buf,0) = 0;
  2109. WBUFW(buf,2) = 0;
  2110. WBUFW(buf,4) = 0;
  2111. WBUFW(buf,6) = 0;
  2112. return;
  2113. }
  2114. if( item->card[0] == CARD0_PET ) { //pet eggs
  2115. WBUFW(buf,0) = 0;
  2116. WBUFW(buf,2) = 0;
  2117. WBUFW(buf,4) = 0;
  2118. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  2119. return;
  2120. }
  2121. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  2122. WBUFW(buf,0) = item->card[0];
  2123. WBUFW(buf,2) = item->card[1];
  2124. WBUFW(buf,4) = item->card[2];
  2125. WBUFW(buf,6) = item->card[3];
  2126. return;
  2127. }
  2128. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2129. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  2130. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2131. //Normal items.
  2132. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2133. WBUFW(buf,0) = j;
  2134. else
  2135. WBUFW(buf,0) = item->card[i];
  2136. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2137. WBUFW(buf,2) = j;
  2138. else
  2139. WBUFW(buf,2) = item->card[i];
  2140. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2141. WBUFW(buf,4) = j;
  2142. else
  2143. WBUFW(buf,4) = item->card[i];
  2144. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2145. WBUFW(buf,6) = j;
  2146. else
  2147. WBUFW(buf,6) = item->card[i];
  2148. }
  2149. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2150. /// A maximum of 5 random options can be supported.
  2151. void clif_add_random_options(unsigned char* buf, struct item *it) {
  2152. #if PACKETVER >= 20150225
  2153. int i;
  2154. for (i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  2155. WBUFW(buf, i*5 + 0) = it->option[i].id; // OptIndex
  2156. WBUFW(buf, i*5 + 2) = it->option[i].value; // Value
  2157. WBUFB(buf, i*5 + 4) = it->option[i].param; // Param1
  2158. }
  2159. #if MAX_ITEM_RDM_OPT < 5
  2160. for ( ; i < 5; i++) {
  2161. WBUFW(buf, i*5 + 0) = 0; // OptIndex
  2162. WBUFW(buf, i*5 + 2) = 0; // Value
  2163. WBUFB(buf, i*5 + 4) = 0; // Param1
  2164. }
  2165. #endif
  2166. #endif
  2167. }
  2168. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2169. /// 00a0 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B <result>.B (ZC_ITEM_PICKUP_ACK)
  2170. /// 029a <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B <result>.B <expire time>.L (ZC_ITEM_PICKUP_ACK2)
  2171. /// 02d4 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W (ZC_ITEM_PICKUP_ACK3)
  2172. /// 0990 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.L <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W (ZC_ITEM_PICKUP_ACK_V5)
  2173. /// 0a0c <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.L <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W (ZC_ITEM_PICKUP_ACK_V6)
  2174. /// 0a37 <index>.W <amount>.W <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.L <item type>.B <result>.B <expire time>.L <bindOnEquipType>.W <favorite>.B <view id>.W (ZC_ITEM_PICKUP_ACK_V7)
  2175. void clif_additem(struct map_session_data *sd, int n, int amount, unsigned char fail)
  2176. {
  2177. int fd, header, offs=0;
  2178. #if PACKETVER < 20061218
  2179. header = 0xa0;
  2180. #elif PACKETVER < 20071002
  2181. header = 0x29a;
  2182. #elif PACKETVER < 20120925
  2183. header = 0x2d4;
  2184. #elif PACKETVER < 20150225
  2185. header = 0x990;
  2186. #elif PACKETVER < 20160921
  2187. header = 0xa0c;
  2188. #else
  2189. header = 0xa37;
  2190. #endif
  2191. nullpo_retv(sd);
  2192. fd = sd->fd;
  2193. if( !session_isActive(fd) ) //Sasuke-
  2194. return;
  2195. WFIFOHEAD(fd,packet_len(header));
  2196. if( fail )
  2197. {
  2198. WFIFOW(fd,offs+0) = header;
  2199. WFIFOW(fd,offs+2) = n+2;
  2200. WFIFOW(fd,offs+4) = amount;
  2201. WFIFOW(fd,offs+6) = 0;
  2202. WFIFOB(fd,offs+8) = 0;
  2203. WFIFOB(fd,offs+9) = 0;
  2204. WFIFOB(fd,offs+10) = 0;
  2205. WFIFOW(fd,offs+11) = 0;
  2206. WFIFOW(fd,offs+13) = 0;
  2207. WFIFOW(fd,offs+15) = 0;
  2208. WFIFOW(fd,offs+17) = 0;
  2209. #if PACKETVER < 20120925
  2210. WFIFOW(fd,offs+19) = 0;
  2211. #else
  2212. WFIFOL(fd,offs+19) = 0;
  2213. offs += 2;
  2214. #endif
  2215. WFIFOB(fd,offs+21) = 0;
  2216. WFIFOB(fd,offs+22) = fail;
  2217. #if PACKETVER >= 20061218
  2218. WFIFOL(fd,offs+23) = 0;
  2219. #endif
  2220. #if PACKETVER >= 20071002
  2221. WFIFOW(fd,offs+27) = 0; // HireExpireDate
  2222. #if PACKETVER >= 20150225
  2223. clif_add_random_options(WFIFOP(fd,offs+31), &sd->inventory.u.items_inventory[n]);
  2224. #if PACKETVER >= 20160921
  2225. WFIFOB(fd,offs+54) = 0; // Favorite
  2226. WFIFOW(fd,offs+55) = 0; // View ID
  2227. #endif
  2228. #endif
  2229. #endif
  2230. }
  2231. else
  2232. {
  2233. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  2234. return;
  2235. WFIFOW(fd,offs+0) = header;
  2236. WFIFOW(fd,offs+2) = n+2;
  2237. WFIFOW(fd,offs+4) = amount;
  2238. if (sd->inventory_data[n]->view_id > 0)
  2239. WFIFOW(fd,offs+6) = sd->inventory_data[n]->view_id;
  2240. else
  2241. WFIFOW(fd,offs+6)=sd->inventory.u.items_inventory[n].nameid;
  2242. WFIFOB(fd,offs+8)=sd->inventory.u.items_inventory[n].identify;
  2243. WFIFOB(fd,offs+9)=sd->inventory.u.items_inventory[n].attribute;
  2244. WFIFOB(fd,offs+10)=sd->inventory.u.items_inventory[n].refine;
  2245. clif_addcards(WFIFOP(fd,offs+11), &sd->inventory.u.items_inventory[n]);
  2246. #if PACKETVER < 20120925
  2247. WFIFOW(fd,offs+19) = pc_equippoint(sd,n);
  2248. #else
  2249. WFIFOL(fd,offs+19) = pc_equippoint(sd,n);
  2250. offs += 2;
  2251. #endif
  2252. WFIFOB(fd,offs+21) = itemtype(sd->inventory_data[n]->nameid);
  2253. WFIFOB(fd,offs+22) = fail;
  2254. #if PACKETVER >= 20061218
  2255. WFIFOL(fd,offs+23)=sd->inventory.u.items_inventory[n].expire_time;
  2256. #endif
  2257. #if PACKETVER >= 20071002
  2258. /* Yellow color only for non-stackable item */
  2259. WFIFOW(fd,offs+27)=(sd->inventory.u.items_inventory[n].bound && !itemdb_isstackable(sd->inventory.u.items_inventory[n].nameid)) ? BOUND_DISPYELLOW : sd->inventory_data[n]->flag.bindOnEquip ? BOUND_ONEQUIP : 0;
  2260. #endif
  2261. #if PACKETVER >= 20150225
  2262. clif_add_random_options(WFIFOP(fd,31), &sd->inventory.u.items_inventory[n]);
  2263. #if PACKETVER >= 20160921
  2264. WFIFOB(fd,offs+54) = sd->inventory.u.items_inventory[n].favorite;
  2265. WFIFOW(fd,offs+55) = sd->inventory_data[n]->look;
  2266. #endif
  2267. #endif
  2268. }
  2269. WFIFOSET(fd,packet_len(header));
  2270. }
  2271. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2272. /// 00af <index>.W <amount>.W
  2273. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2274. {
  2275. int fd;
  2276. nullpo_retv(sd);
  2277. fd=sd->fd;
  2278. WFIFOHEAD(fd, packet_len(0xaf));
  2279. WFIFOW(fd,0)=0xaf;
  2280. WFIFOW(fd,2)=n+2;
  2281. WFIFOW(fd,4)=amount;
  2282. WFIFOSET(fd,packet_len(0xaf));
  2283. }
  2284. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2285. /// 07fa <delete type>.W <index>.W <amount>.W
  2286. /// delete type:
  2287. /// 0 = Normal
  2288. /// 1 = Item used for a skill
  2289. /// 2 = Refine failed
  2290. /// 3 = Material changed
  2291. /// 4 = Moved to storage
  2292. /// 5 = Moved to cart
  2293. /// 6 = Item sold
  2294. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2295. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2296. {
  2297. #if PACKETVER < 20091117
  2298. clif_dropitem(sd,n,amount);
  2299. #else
  2300. int fd;
  2301. nullpo_retv(sd);
  2302. fd=sd->fd;
  2303. WFIFOHEAD(fd, packet_len(0x7fa));
  2304. WFIFOW(fd,0)=0x7fa;
  2305. WFIFOW(fd,2)=reason;
  2306. WFIFOW(fd,4)=n+2;
  2307. WFIFOW(fd,6)=amount;
  2308. WFIFOSET(fd,packet_len(0x7fa));
  2309. #endif
  2310. }
  2311. void clif_item_sub_v5(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2312. char normal = (equip < 0);
  2313. int offset = 0;
  2314. WBUFW(buf,n) = idx; //index
  2315. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid;
  2316. WBUFB(buf,n+4) = itemtype(id->nameid);
  2317. if (!normal){ //equip 31B
  2318. WBUFL(buf,n+5) = equip; //location
  2319. WBUFL(buf,n+9) = it->equip; //wear state
  2320. WBUFB(buf,n+13) = it->refine; //refine lvl
  2321. clif_addcards(WBUFP(buf, n+14), it); //EQUIPSLOTINFO 8B
  2322. WBUFL(buf,n+22) = it->expire_time;
  2323. WBUFW(buf,n+26) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0; //bindOnEquipType
  2324. WBUFW(buf,n+28) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2325. #if PACKETVER >= 20150225
  2326. //V6_ITEM_Option
  2327. WBUFB(buf,n+30) = 0; // nRandomOptionCnt
  2328. clif_add_random_options(WBUFP(buf, n+31), it);// optionData
  2329. offset += 26;
  2330. #endif
  2331. //V5_ITEM_flag
  2332. WBUFB(buf,n+30+offset) = it->identify; //0x1 IsIdentified
  2333. WBUFB(buf,n+30+offset) |= (it->attribute) ? 0x2 : 0; //0x2 IsDamaged
  2334. WBUFB(buf,n+30+offset) |= (it->favorite) ? 0x4 : 0; //0x4 PlaceETCTab
  2335. }
  2336. else { //normal 24B
  2337. WBUFW(buf,n+5) = it->amount;
  2338. WBUFL(buf,n+7) = (equip == -2 && id->equip == EQP_AMMO)?id->equip:0; //wear state
  2339. clif_addcards(WBUFP(buf, n+11), it); //EQUIPSLOTINFO 8B
  2340. WBUFL(buf,n+19) = it->expire_time;
  2341. //V5_ITEM_flag
  2342. WBUFB(buf,n+23) = it->identify; //0x1 IsIdentified
  2343. WBUFB(buf,n+23) |= (it->favorite) ? 0x2 : 0; //0x4,0x2 PlaceETCTab
  2344. }
  2345. }
  2346. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2347. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2348. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2349. void clif_item_sub(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2350. #if PACKETVER >= 20120925
  2351. clif_item_sub_v5(buf, n, idx, it, id, equip);
  2352. #else
  2353. WBUFW(buf,n) = idx; //index
  2354. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid; //itid
  2355. WBUFB(buf,n+4) = itemtype(id->nameid);
  2356. WBUFB(buf,n+5) = it->identify;
  2357. if (equip >= 0) { //Equippable item 28.B
  2358. WBUFW(buf,n+6) = equip;
  2359. WBUFW(buf,n+8) = it->equip;
  2360. WBUFB(buf,n+10) = it->attribute;
  2361. WBUFB(buf,n+11) = it->refine;
  2362. clif_addcards(WBUFP(buf, n+12), it); //8B
  2363. #if PACKETVER >= 20071002
  2364. WBUFL(buf,n+20) = it->expire_time;
  2365. WBUFW(buf,n+24) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0;
  2366. #endif
  2367. #if PACKETVER >= 20100629
  2368. WBUFW(buf,n+26) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2369. #endif
  2370. } else { //Stackable item. 22.B
  2371. WBUFW(buf,n+6) = it->amount;
  2372. WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2373. clif_addcards(WBUFP(buf, n+10), it); //8B
  2374. #if PACKETVER >= 20071002
  2375. WBUFL(buf,n+18) = it->expire_time;
  2376. #endif
  2377. }
  2378. #endif
  2379. }
  2380. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2381. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2382. void clif_inventorylist(struct map_session_data *sd) {
  2383. int i,n,ne,arrow=-1;
  2384. unsigned char *buf;
  2385. unsigned char *bufe;
  2386. #if PACKETVER < 5
  2387. const int s = 10; //Entry size
  2388. #elif PACKETVER < 20080102
  2389. const int s = 18;
  2390. #elif PACKETVER < 20120925
  2391. const int s = 22;
  2392. #else
  2393. const int s = 24;
  2394. #endif
  2395. #if PACKETVER < 20071002
  2396. const int se = 20;
  2397. #elif PACKETVER < 20100629
  2398. const int se = 26;
  2399. #elif PACKETVER < 20120925
  2400. const int se = 28;
  2401. #elif PACKETVER < 20150225
  2402. const int se = 31;
  2403. #else
  2404. const int se = 57;
  2405. #endif
  2406. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2407. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2408. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2409. {
  2410. if( sd->inventory.u.items_inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2411. continue;
  2412. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2413. { //Non-stackable (Equippable)
  2414. clif_item_sub(bufe, ne*se+4, i+2, &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2415. ne++;
  2416. }
  2417. else { //Stackable.
  2418. clif_item_sub(buf, n*s+4,i+2, &sd->inventory.u.items_inventory[i], sd->inventory_data[i], -2);
  2419. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->inventory.u.items_inventory[i].equip )
  2420. arrow=i;
  2421. n++;
  2422. }
  2423. }
  2424. if( n )
  2425. {
  2426. #if PACKETVER < 5
  2427. WBUFW(buf,0)=0xa3;
  2428. #elif PACKETVER < 20080102
  2429. WBUFW(buf,0)=0x1ee;
  2430. #elif PACKETVER < 20120925
  2431. WBUFW(buf,0)=0x2e8;
  2432. #else
  2433. WBUFW(buf,0)=0x991;
  2434. #endif
  2435. WBUFW(buf,2)=4+n*s;
  2436. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2437. }
  2438. if( arrow >= 0 )
  2439. clif_arrowequip(sd,arrow);
  2440. if( ne ) {
  2441. #if PACKETVER < 20071002
  2442. WBUFW(bufe,0)=0xa4;
  2443. #elif PACKETVER < 20120925
  2444. WBUFW(bufe,0)=0x2d0;
  2445. #elif PACKETVER < 20150225
  2446. WBUFW(bufe,0)=0x992;
  2447. #else
  2448. WBUFW(bufe,0)=0xa0d;
  2449. #endif
  2450. WBUFW(bufe,2)=4+ne*se;
  2451. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2452. }
  2453. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2454. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2455. if( sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2456. continue;
  2457. if ( sd->inventory.u.items_inventory[i].favorite )
  2458. clif_favorite_item(sd, i);
  2459. }
  2460. #endif
  2461. if( buf ) aFree(buf);
  2462. if( bufe ) aFree(bufe);
  2463. }
  2464. //Required when items break/get-repaired. Only sends equippable item list.
  2465. void clif_equiplist(struct map_session_data *sd)
  2466. {
  2467. int i,n,fd = sd->fd;
  2468. unsigned char *buf;
  2469. #if PACKETVER < 20071002
  2470. const int cmd = 20;
  2471. #elif PACKETVER < 20100629
  2472. const int cmd = 26;
  2473. #elif PACKETVER < 20120925
  2474. const int cmd = 28;
  2475. #elif PACKETVER < 20150225
  2476. const int cmd = 31;
  2477. #else
  2478. const int cmd = 57;
  2479. #endif
  2480. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2481. buf = WFIFOP(fd,0);
  2482. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2483. if (sd->inventory.u.items_inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2484. continue;
  2485. if(itemdb_isstackable2(sd->inventory_data[i]))
  2486. continue;
  2487. //Equippable
  2488. clif_item_sub(buf, n*cmd+4,i+2, &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2489. n++;
  2490. }
  2491. if (n) {
  2492. #if PACKETVER < 20071002
  2493. WBUFW(buf,0)=0xa4;
  2494. #elif PACKETVER < 20120925
  2495. WBUFW(buf,0)=0x2d0;
  2496. #elif PACKETVER < 20150225
  2497. WBUFW(buf,0)=0x992;
  2498. #else
  2499. WBUFW(buf,0)=0xa0d;
  2500. #endif
  2501. WBUFW(buf,2)=4+n*cmd;
  2502. WFIFOSET(fd,WFIFOW(fd,2));
  2503. }
  2504. }
  2505. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length, const char *storename)
  2506. {
  2507. static const int client_buf = 0x5000; // Max buffer to send
  2508. struct item_data *id;
  2509. int i,n,ne,nn;
  2510. unsigned char *buf;
  2511. unsigned char *bufe;
  2512. #if PACKETVER < 5
  2513. const int s = 10; //Entry size.normal item
  2514. const int sidx=4; //start itemlist idx
  2515. const int cmd = 0xa5;
  2516. #elif PACKETVER < 20080102
  2517. const int s = 18;
  2518. const int sidx=4;
  2519. const int cmd = 0x1f0;
  2520. #elif PACKETVER < 20120925
  2521. const int s = 22;
  2522. const int sidx=4;
  2523. const int cmd = 0x2ea;
  2524. #else
  2525. const int s = 24;
  2526. const int sidx = 4+24;
  2527. const int cmd = 0x995;
  2528. #endif
  2529. #if PACKETVER < 20071002
  2530. const int se = 20; //entry size equip
  2531. const int sidxe = 4; //start itemlist idx
  2532. const int cmde = 0xa6;
  2533. #elif PACKETVER < 20100629
  2534. const int se = 26;
  2535. const int sidxe = 4;
  2536. const int cmde = 0x2d1;
  2537. #elif PACKETVER < 20120925
  2538. const int se = 28;
  2539. const int sidxe = 4;
  2540. const int cmde = 0x2d1;
  2541. #elif PACKETVER < 20150225
  2542. const int se = 31;
  2543. const int sidxe = 4+24;
  2544. const int cmde = 0x996;
  2545. #else
  2546. const int se = 57;
  2547. const int sidxe = 4+24;
  2548. const int cmde = 0xa10;
  2549. #endif
  2550. buf = (unsigned char*)aMalloc(items_length * s + sidx);
  2551. bufe = (unsigned char*)aMalloc(items_length * se + sidxe);
  2552. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2553. {
  2554. if( items[i].nameid <= 0 )
  2555. continue;
  2556. id = itemdb_search(items[i].nameid);
  2557. if( !itemdb_isstackable2(id) ) { //Equippable
  2558. clif_item_sub(bufe, ne*se+sidxe,i+1, &items[i], id, id->equip);
  2559. ne++;
  2560. }
  2561. else { //Stackable
  2562. clif_item_sub(buf, n*s+sidx,i+1, &items[i], id,-1);
  2563. n++;
  2564. }
  2565. }
  2566. for (i = 0; i < n; i += nn) // Loop through non-equipable items
  2567. {
  2568. nn = n - i < (client_buf - sidx)/s ? n - i : (client_buf - sidx)/s; // Split up non-equipable items
  2569. WFIFOHEAD(sd->fd,sidx+nn*s);
  2570. WFIFOW(sd->fd,0)=cmd;
  2571. WFIFOW(sd->fd,2)=sidx+nn*s;
  2572. #if PACKETVER >= 20120925
  2573. safestrncpy(WFIFOCP(sd->fd,4), storename, NAME_LENGTH); //storename
  2574. #endif
  2575. memcpy(WFIFOP(sd->fd,sidx),buf + sidx + i*s,nn*s);
  2576. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2577. }
  2578. for (i = 0; i < ne; i += nn) // Loop through equipable items
  2579. {
  2580. nn = ne - i < (client_buf - sidxe)/se ? ne - i : (client_buf - sidxe)/se; // Split up equipable items
  2581. WFIFOHEAD(sd->fd,sidxe+nn*se);
  2582. WFIFOW(sd->fd,0)=cmde;
  2583. WFIFOW(sd->fd,2)=sidxe+nn*se;
  2584. #if PACKETVER >= 20120925
  2585. safestrncpy(WFIFOCP(sd->fd,4), storename, NAME_LENGTH); //storename
  2586. #endif
  2587. memcpy(WFIFOP(sd->fd,sidxe),bufe + sidxe + i*se,nn*se);
  2588. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2589. }
  2590. // Empty storage
  2591. if (n == 0 && ne == 0) {
  2592. WFIFOHEAD(sd->fd, 4+NAME_LENGTH);
  2593. WFIFOW(sd->fd,0) = cmd;
  2594. WFIFOW(sd->fd,2) = 4+NAME_LENGTH;
  2595. #if PACKETVER >= 20120925
  2596. safestrncpy(WFIFOCP(sd->fd,4), storename, NAME_LENGTH); //storename
  2597. #endif
  2598. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2599. }
  2600. if( buf ) aFree(buf);
  2601. if( bufe ) aFree(bufe);
  2602. }
  2603. void clif_cartlist(struct map_session_data *sd)
  2604. {
  2605. struct item_data *id;
  2606. int i,n,ne;
  2607. unsigned char *buf;
  2608. unsigned char *bufe;
  2609. #if PACKETVER < 5
  2610. const int s = 10; //Entry size.
  2611. #elif PACKETVER < 20080102
  2612. const int s = 18;
  2613. #elif PACKETVER < 20120925
  2614. const int s = 22;
  2615. #else
  2616. const int s = 24;
  2617. #endif
  2618. #if PACKETVER < 20071002
  2619. const int cmd = 20;
  2620. #elif PACKETVER < 20100629
  2621. const int cmd = 26;
  2622. #elif PACKETVER < 20120925
  2623. const int cmd = 28;
  2624. #elif PACKETVER < 20150225
  2625. const int cmd = 31;
  2626. #else
  2627. const int cmd = 57;
  2628. #endif
  2629. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2630. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2631. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2632. {
  2633. if( sd->cart.u.items_cart[i].nameid <= 0 )
  2634. continue;
  2635. id = itemdb_search(sd->cart.u.items_cart[i].nameid);
  2636. if( !itemdb_isstackable2(id) ) { //Equippable
  2637. clif_item_sub(bufe, ne*cmd+4,i+2, &sd->cart.u.items_cart[i], id, id->equip);
  2638. ne++;
  2639. }
  2640. else { //Stackable
  2641. clif_item_sub(buf, n*s+4,i+2, &sd->cart.u.items_cart[i], id,-1);
  2642. n++;
  2643. }
  2644. }
  2645. if( n )
  2646. {
  2647. #if PACKETVER < 5
  2648. WBUFW(buf,0)=0x123;
  2649. #elif PACKETVER < 20080102
  2650. WBUFW(buf,0)=0x1ef;
  2651. #elif PACKETVER < 20120925
  2652. WBUFW(buf,0)=0x2e9;
  2653. #else
  2654. WBUFW(buf,0)=0x993;
  2655. #endif
  2656. WBUFW(buf,2)=4+n*s;
  2657. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2658. }
  2659. if( ne )
  2660. {
  2661. #if PACKETVER < 20071002
  2662. WBUFW(bufe,0)=0x122;
  2663. #elif PACKETVER < 20120925
  2664. WBUFW(bufe,0)=0x2d2;
  2665. #elif PACKETVER < 20150225
  2666. WBUFW(bufe,0)=0x994;
  2667. #else
  2668. WBUFW(bufe,0)=0xa0f;
  2669. #endif
  2670. WBUFW(bufe,2)=4+ne*cmd;
  2671. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2672. }
  2673. if( buf ) aFree(buf);
  2674. if( bufe ) aFree(bufe);
  2675. }
  2676. /// Removes cart (ZC_CARTOFF).
  2677. /// 012b
  2678. /// Client behaviour:
  2679. /// Closes the cart storage and removes all it's items from memory.
  2680. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2681. void clif_clearcart(int fd)
  2682. {
  2683. WFIFOHEAD(fd, packet_len(0x12b));
  2684. WFIFOW(fd,0) = 0x12b;
  2685. WFIFOSET(fd, packet_len(0x12b));
  2686. }
  2687. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2688. /// 01eb <account id>.L <x>.W <y>.W
  2689. void clif_guild_xy(struct map_session_data *sd)
  2690. {
  2691. unsigned char buf[10];
  2692. nullpo_retv(sd);
  2693. WBUFW(buf,0)=0x1eb;
  2694. WBUFL(buf,2)=sd->status.account_id;
  2695. WBUFW(buf,6)=sd->bl.x;
  2696. WBUFW(buf,8)=sd->bl.y;
  2697. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2698. }
  2699. /*==========================================
  2700. * Sends x/y dot to a single fd. [Skotlex]
  2701. *------------------------------------------*/
  2702. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2703. {
  2704. if( sd->bg_id )
  2705. return;
  2706. WFIFOHEAD(fd,packet_len(0x1eb));
  2707. WFIFOW(fd,0)=0x1eb;
  2708. WFIFOL(fd,2)=sd->status.account_id;
  2709. WFIFOW(fd,6)=sd->bl.x;
  2710. WFIFOW(fd,8)=sd->bl.y;
  2711. WFIFOSET(fd,packet_len(0x1eb));
  2712. }
  2713. // Guild XY locators [Valaris]
  2714. void clif_guild_xy_remove(struct map_session_data *sd)
  2715. {
  2716. unsigned char buf[10];
  2717. nullpo_retv(sd);
  2718. WBUFW(buf,0)=0x1eb;
  2719. WBUFL(buf,2)=sd->status.account_id;
  2720. WBUFW(buf,6)=-1;
  2721. WBUFW(buf,8)=-1;
  2722. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2723. }
  2724. /*==========================================
  2725. *
  2726. *------------------------------------------*/
  2727. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2728. {
  2729. struct map_session_data *sd, *tsd;
  2730. #if PACKETVER < 20100126
  2731. const int cmd = 0x106;
  2732. #else
  2733. const int cmd = 0x80e;
  2734. #endif
  2735. sd = va_arg(ap, struct map_session_data *);
  2736. tsd = (TBL_PC *)bl;
  2737. nullpo_ret(sd);
  2738. nullpo_ret(tsd);
  2739. if( !tsd->fd || tsd == sd )
  2740. return 0;
  2741. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2742. return 0;
  2743. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2744. WFIFOW(tsd->fd,0) = cmd;
  2745. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2746. #if PACKETVER < 20100126
  2747. if( sd->battle_status.max_hp > INT16_MAX )
  2748. { //To correctly display the %hp bar. [Skotlex]
  2749. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2750. WFIFOW(tsd->fd,8) = 100;
  2751. } else {
  2752. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2753. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2754. }
  2755. #else
  2756. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2757. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2758. #endif
  2759. WFIFOSET(tsd->fd,packet_len(cmd));
  2760. return 0;
  2761. }
  2762. /*==========================================
  2763. * Server tells all players that are allowed to view HP bars
  2764. * and are nearby 'sd' that 'sd' hp bar was updated.
  2765. *------------------------------------------*/
  2766. static int clif_hpmeter(struct map_session_data *sd)
  2767. {
  2768. nullpo_ret(sd);
  2769. map_foreachinallarea(clif_hpmeter_sub, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_PC, sd);
  2770. return 0;
  2771. }
  2772. /// Notifies client of a character parameter change.
  2773. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2774. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2775. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2776. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2777. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2778. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2779. /// TODO: Extract individual packets.
  2780. /// FIXME: Packet lengths from packet_len(cmd)
  2781. void clif_updatestatus(struct map_session_data *sd,int type)
  2782. {
  2783. int fd,len=8;
  2784. nullpo_retv(sd);
  2785. fd=sd->fd;
  2786. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2787. return;
  2788. WFIFOHEAD(fd, 14);
  2789. WFIFOW(fd,0)=0xb0;
  2790. WFIFOW(fd,2)=type;
  2791. switch(type){
  2792. // 00b0
  2793. case SP_WEIGHT:
  2794. pc_updateweightstatus(sd);
  2795. WFIFOHEAD(fd,14);
  2796. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2797. WFIFOW(fd,2)=type;
  2798. WFIFOL(fd,4)=sd->weight;
  2799. break;
  2800. case SP_MAXWEIGHT:
  2801. WFIFOL(fd,4)=sd->max_weight;
  2802. break;
  2803. case SP_SPEED:
  2804. WFIFOL(fd,4)=sd->battle_status.speed;
  2805. break;
  2806. case SP_BASELEVEL:
  2807. WFIFOL(fd,4)=sd->status.base_level;
  2808. break;
  2809. case SP_JOBLEVEL:
  2810. WFIFOL(fd,4)=sd->status.job_level;
  2811. break;
  2812. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2813. WFIFOL(fd,4)=sd->status.karma;
  2814. break;
  2815. case SP_MANNER:
  2816. WFIFOL(fd,4)=sd->status.manner;
  2817. break;
  2818. case SP_STATUSPOINT:
  2819. WFIFOL(fd,4)=sd->status.status_point;
  2820. break;
  2821. case SP_SKILLPOINT:
  2822. WFIFOL(fd,4)=sd->status.skill_point;
  2823. break;
  2824. case SP_HIT:
  2825. WFIFOL(fd,4)=sd->battle_status.hit;
  2826. break;
  2827. case SP_FLEE1:
  2828. WFIFOL(fd,4)=sd->battle_status.flee;
  2829. break;
  2830. case SP_FLEE2:
  2831. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2832. break;
  2833. case SP_MAXHP:
  2834. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2835. break;
  2836. case SP_MAXSP:
  2837. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2838. break;
  2839. case SP_HP:
  2840. // On officials the HP never go below 1, even if you die [Lemongrass]
  2841. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2842. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2843. break;
  2844. case SP_SP:
  2845. WFIFOL(fd,4)=sd->battle_status.sp;
  2846. break;
  2847. case SP_ASPD:
  2848. WFIFOL(fd,4)=sd->battle_status.amotion;
  2849. break;
  2850. case SP_ATK1:
  2851. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2852. break;
  2853. case SP_DEF1:
  2854. WFIFOL(fd,4)=pc_leftside_def(sd);
  2855. break;
  2856. case SP_MDEF1:
  2857. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2858. break;
  2859. case SP_ATK2:
  2860. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2861. break;
  2862. case SP_DEF2:
  2863. WFIFOL(fd,4)=pc_rightside_def(sd);
  2864. break;
  2865. case SP_MDEF2: {
  2866. //negative check (in case you have something like Berserk active)
  2867. int mdef2 = pc_rightside_mdef(sd);
  2868. WFIFOL(fd,4)=
  2869. #ifndef RENEWAL
  2870. ( mdef2 < 0 ) ? 0 :
  2871. #endif
  2872. mdef2;
  2873. }
  2874. break;
  2875. case SP_CRITICAL:
  2876. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2877. break;
  2878. case SP_MATK1:
  2879. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2880. break;
  2881. case SP_MATK2:
  2882. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2883. break;
  2884. case SP_ZENY:
  2885. WFIFOW(fd,0)=0xb1;
  2886. WFIFOL(fd,4)=sd->status.zeny;
  2887. break;
  2888. case SP_BASEEXP:
  2889. WFIFOW(fd,0)=0xb1;
  2890. WFIFOL(fd,4)=sd->status.base_exp;
  2891. break;
  2892. case SP_JOBEXP:
  2893. WFIFOW(fd,0)=0xb1;
  2894. WFIFOL(fd,4)=sd->status.job_exp;
  2895. break;
  2896. case SP_NEXTBASEEXP:
  2897. WFIFOW(fd,0)=0xb1;
  2898. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2899. break;
  2900. case SP_NEXTJOBEXP:
  2901. WFIFOW(fd,0)=0xb1;
  2902. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2903. break;
  2904. /**
  2905. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2906. **/
  2907. case SP_USTR:
  2908. case SP_UAGI:
  2909. case SP_UVIT:
  2910. case SP_UINT:
  2911. case SP_UDEX:
  2912. case SP_ULUK:
  2913. WFIFOW(fd,0)=0xbe;
  2914. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2915. len=5;
  2916. break;
  2917. /**
  2918. * Tells the client how far it is allowed to attack (weapon range)
  2919. **/
  2920. case SP_ATTACKRANGE:
  2921. WFIFOW(fd,0)=0x13a;
  2922. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2923. len=4;
  2924. break;
  2925. case SP_STR:
  2926. WFIFOW(fd,0)=0x141;
  2927. WFIFOL(fd,2)=type;
  2928. WFIFOL(fd,6)=sd->status.str;
  2929. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2930. len=14;
  2931. break;
  2932. case SP_AGI:
  2933. WFIFOW(fd,0)=0x141;
  2934. WFIFOL(fd,2)=type;
  2935. WFIFOL(fd,6)=sd->status.agi;
  2936. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2937. len=14;
  2938. break;
  2939. case SP_VIT:
  2940. WFIFOW(fd,0)=0x141;
  2941. WFIFOL(fd,2)=type;
  2942. WFIFOL(fd,6)=sd->status.vit;
  2943. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2944. len=14;
  2945. break;
  2946. case SP_INT:
  2947. WFIFOW(fd,0)=0x141;
  2948. WFIFOL(fd,2)=type;
  2949. WFIFOL(fd,6)=sd->status.int_;
  2950. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2951. len=14;
  2952. break;
  2953. case SP_DEX:
  2954. WFIFOW(fd,0)=0x141;
  2955. WFIFOL(fd,2)=type;
  2956. WFIFOL(fd,6)=sd->status.dex;
  2957. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2958. len=14;
  2959. break;
  2960. case SP_LUK:
  2961. WFIFOW(fd,0)=0x141;
  2962. WFIFOL(fd,2)=type;
  2963. WFIFOL(fd,6)=sd->status.luk;
  2964. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2965. len=14;
  2966. break;
  2967. case SP_CARTINFO:
  2968. WFIFOW(fd,0)=0x121;
  2969. WFIFOW(fd,2)=sd->cart_num;
  2970. WFIFOW(fd,4)=MAX_CART;
  2971. WFIFOL(fd,6)=sd->cart_weight;
  2972. WFIFOL(fd,10)=sd->cart_weight_max;
  2973. len=14;
  2974. break;
  2975. default:
  2976. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2977. return;
  2978. }
  2979. WFIFOSET(fd,len);
  2980. // Additional update packets that should be sent right after
  2981. switch( type ){
  2982. case SP_BASELEVEL:
  2983. if( sd->status.party_id ){
  2984. struct party_data* p;
  2985. int i;
  2986. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  2987. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  2988. if( i < MAX_PARTY ){
  2989. p->party.member[i].lv = sd->status.base_level;
  2990. clif_party_job_and_level(sd);
  2991. }
  2992. }
  2993. }
  2994. break;
  2995. case SP_HP:
  2996. if( map[sd->bl.m].hpmeter_visible ){
  2997. clif_hpmeter(sd);
  2998. }
  2999. if( !battle_config.party_hp_mode && sd->status.party_id ){
  3000. clif_party_hp(sd);
  3001. }
  3002. if( sd->bg_id ){
  3003. clif_bg_hp(sd);
  3004. }
  3005. break;
  3006. }
  3007. }
  3008. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3009. /// 01ab <account id>.L <var id>.W <value>.L
  3010. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3011. {
  3012. unsigned char buf[12];
  3013. nullpo_retv(sd);
  3014. WBUFW(buf,0)=0x1ab;
  3015. WBUFL(buf,2)=sd->bl.id;
  3016. WBUFW(buf,6)=type;
  3017. switch(type)
  3018. {
  3019. case SP_MANNER:
  3020. WBUFL(buf,8)=val;
  3021. break;
  3022. default:
  3023. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3024. return;
  3025. }
  3026. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3027. }
  3028. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3029. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  3030. void clif_sprite_change(struct block_list *bl, int id, int type, int val, int val2, enum send_target target) {
  3031. unsigned char buf[32];
  3032. #if PACKETVER < 4
  3033. const int cmd = 0xc3;
  3034. #else
  3035. const int cmd = 0x1d7;
  3036. #endif
  3037. WBUFW(buf,0) = cmd;
  3038. WBUFL(buf,2) = id;
  3039. WBUFB(buf,6) = type;
  3040. WBUFW(buf,7) = val;
  3041. #if PACKETVER >= 4
  3042. WBUFW(buf,9) = val2;
  3043. #endif
  3044. clif_send(buf,packet_len(cmd), bl, target);
  3045. }
  3046. /// Updates sprite/style properties of an object.
  3047. void clif_changelook(struct block_list *bl, int type, int val) {
  3048. struct map_session_data* sd;
  3049. struct status_change* sc;
  3050. struct view_data* vd;
  3051. enum send_target target = AREA;
  3052. int val2 = 0;
  3053. nullpo_retv(bl);
  3054. sd = BL_CAST(BL_PC, bl);
  3055. sc = status_get_sc(bl);
  3056. vd = status_get_viewdata(bl);
  3057. if( vd ) //temp hack to let Warp Portal change appearance
  3058. switch(type) {
  3059. case LOOK_WEAPON:
  3060. if (sd) {
  3061. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3062. val = vd->weapon;
  3063. }
  3064. else
  3065. vd->weapon = val;
  3066. break;
  3067. case LOOK_SHIELD:
  3068. if (sd) {
  3069. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3070. val = vd->shield;
  3071. }
  3072. else
  3073. vd->shield = val;
  3074. break;
  3075. case LOOK_BASE:
  3076. if (!sd)
  3077. break;
  3078. if ( val == INVISIBLE_CLASS )
  3079. return;
  3080. if (sd->sc.option&OPTION_COSTUME)
  3081. vd->weapon = vd->shield = 0;
  3082. if (!vd->cloth_color)
  3083. break;
  3084. if (sd) {
  3085. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3086. vd->cloth_color = 0;
  3087. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3088. vd->cloth_color = 0;
  3089. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  3090. vd->cloth_color = 0;
  3091. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3092. vd->cloth_color = 0;
  3093. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3094. vd->cloth_color = 0;
  3095. if (vd->body_style && (
  3096. sd->sc.option&OPTION_WEDDING || sd->sc.option&OPTION_XMAS ||
  3097. sd->sc.option&OPTION_SUMMER || sd->sc.option&OPTION_HANBOK ||
  3098. sd->sc.option&OPTION_OKTOBERFEST))
  3099. vd->body_style = 0;
  3100. }
  3101. break;
  3102. case LOOK_HAIR:
  3103. vd->hair_style = val;
  3104. break;
  3105. case LOOK_HEAD_BOTTOM:
  3106. vd->head_bottom = val;
  3107. break;
  3108. case LOOK_HEAD_TOP:
  3109. vd->head_top = val;
  3110. break;
  3111. case LOOK_HEAD_MID:
  3112. vd->head_mid = val;
  3113. break;
  3114. case LOOK_HAIR_COLOR:
  3115. vd->hair_color = val;
  3116. break;
  3117. case LOOK_CLOTHES_COLOR:
  3118. if (val && sd) {
  3119. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3120. val = 0;
  3121. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3122. val = 0;
  3123. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  3124. val = 0;
  3125. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3126. val = 0;
  3127. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3128. val = 0;
  3129. }
  3130. vd->cloth_color = val;
  3131. break;
  3132. case LOOK_SHOES:
  3133. #if PACKETVER > 3
  3134. if (sd) {
  3135. int n;
  3136. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  3137. if(sd->inventory_data[n]->view_id > 0)
  3138. val = sd->inventory_data[n]->view_id;
  3139. else
  3140. val = sd->inventory.u.items_inventory[n].nameid;
  3141. } else
  3142. val = 0;
  3143. }
  3144. #endif
  3145. //Shoes? No packet uses this....
  3146. break;
  3147. case LOOK_BODY:
  3148. // unknown purpose
  3149. break;
  3150. case LOOK_ROBE:
  3151. #if PACKETVER < 20110111
  3152. return;
  3153. #else
  3154. vd->robe = val;
  3155. #endif
  3156. break;
  3157. case LOOK_BODY2:
  3158. #if PACKETVER < 20150513
  3159. return;
  3160. #else
  3161. if (val && (
  3162. sd->sc.option&OPTION_WEDDING || sd->sc.option&OPTION_XMAS ||
  3163. sd->sc.option&OPTION_SUMMER || sd->sc.option&OPTION_HANBOK ||
  3164. sd->sc.option&OPTION_OKTOBERFEST))
  3165. val = 0;
  3166. vd->body_style = val;
  3167. #endif
  3168. break;
  3169. }
  3170. // prevent leaking the presence of GM-hidden objects
  3171. if( sc && sc->option&OPTION_INVISIBLE )
  3172. target = SELF;
  3173. #if PACKETVER < 4
  3174. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3175. #else
  3176. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3177. nullpo_retv(vd);
  3178. type = LOOK_WEAPON;
  3179. val = vd->weapon;
  3180. val2 = vd->shield;
  3181. }
  3182. if( disguised(bl) ) {
  3183. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3184. clif_sprite_change(bl, -bl->id, type, val, val2, SELF);
  3185. } else
  3186. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3187. #endif
  3188. }
  3189. //Sends a change-base-look packet required for traps as they are triggered.
  3190. void clif_changetraplook(struct block_list *bl,int val) {
  3191. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3192. }
  3193. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3194. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3195. clif_sprite_change(bl, id, type, val, 0, target);
  3196. }
  3197. /// Character status (ZC_STATUS).
  3198. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3199. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3200. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3201. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3202. void clif_initialstatus(struct map_session_data *sd) {
  3203. int fd, mdef2;
  3204. unsigned char *buf;
  3205. nullpo_retv(sd);
  3206. fd=sd->fd;
  3207. WFIFOHEAD(fd, packet_len(0xbd));
  3208. buf = WFIFOP(fd,0);
  3209. WBUFW(buf,0) = 0xbd;
  3210. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3211. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3212. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3213. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3214. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3215. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3216. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3217. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3218. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3219. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3220. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3221. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3222. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3223. WBUFW(buf,16) = pc_leftside_atk(sd);
  3224. WBUFW(buf,18) = pc_rightside_atk(sd);
  3225. WBUFW(buf,20) = pc_rightside_matk(sd);
  3226. WBUFW(buf,22) = pc_leftside_matk(sd);
  3227. WBUFW(buf,24) = pc_leftside_def(sd);
  3228. WBUFW(buf,26) = pc_rightside_def(sd);
  3229. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3230. mdef2 = pc_rightside_mdef(sd);
  3231. WBUFW(buf,30) =
  3232. #ifndef RENEWAL
  3233. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3234. #endif
  3235. mdef2;
  3236. WBUFW(buf,32) = sd->battle_status.hit;
  3237. WBUFW(buf,34) = sd->battle_status.flee;
  3238. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3239. WBUFW(buf,38) = sd->battle_status.cri/10;
  3240. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3241. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3242. WFIFOSET(fd, packet_len(0xbd));
  3243. clif_updatestatus(sd, SP_STR);
  3244. clif_updatestatus(sd, SP_AGI);
  3245. clif_updatestatus(sd, SP_VIT);
  3246. clif_updatestatus(sd, SP_INT);
  3247. clif_updatestatus(sd, SP_DEX);
  3248. clif_updatestatus(sd, SP_LUK);
  3249. clif_updatestatus(sd, SP_ATTACKRANGE);
  3250. clif_updatestatus(sd, SP_ASPD);
  3251. }
  3252. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3253. /// 013c <index>.W
  3254. void clif_arrowequip(struct map_session_data *sd,int val) {
  3255. int fd;
  3256. nullpo_retv(sd);
  3257. #if PACKETVER >= 20121128
  3258. clif_status_change(&sd->bl, SI_CLIENT_ONLY_EQUIP_ARROW, 1, INVALID_TIMER, 0, 0, 0);
  3259. #endif
  3260. fd=sd->fd;
  3261. WFIFOHEAD(fd, packet_len(0x013c));
  3262. WFIFOW(fd,0) = 0x013c;
  3263. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3264. WFIFOSET(fd, packet_len(0x013c));
  3265. }
  3266. /// Ammunition action message (ZC_ACTION_FAILURE).
  3267. /// 013b <type>.W
  3268. /// type:
  3269. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3270. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3271. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3272. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3273. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3274. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3275. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3276. int fd;
  3277. nullpo_retv(sd);
  3278. fd=sd->fd;
  3279. WFIFOHEAD(fd, packet_len(0x013b));
  3280. WFIFOW(fd,0) = 0x013b;
  3281. WFIFOW(fd,2) = type;
  3282. WFIFOSET(fd, packet_len(0x013b));
  3283. }
  3284. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3285. /// 01ad <packet len>.W { <name id>.W }*
  3286. void clif_arrow_create_list(struct map_session_data *sd)
  3287. {
  3288. int i, c;
  3289. int fd;
  3290. nullpo_retv(sd);
  3291. fd = sd->fd;
  3292. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  3293. WFIFOW(fd,0) = 0x1ad;
  3294. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  3295. short j, nameid = skill_arrow_db[i].nameid;
  3296. if (nameid > 0 && itemdb_exists(nameid) &&
  3297. (j = pc_search_inventory(sd, nameid)) >= 0 &&
  3298. !sd->inventory.u.items_inventory[j].equip && sd->inventory.u.items_inventory[j].identify)
  3299. {
  3300. if ((j = itemdb_viewid(nameid)) > 0)
  3301. WFIFOW(fd,c*2+4) = j;
  3302. else
  3303. WFIFOW(fd,c*2+4) = nameid;
  3304. c++;
  3305. }
  3306. }
  3307. WFIFOW(fd,2) = c*2+4;
  3308. WFIFOSET(fd, WFIFOW(fd,2));
  3309. if (c > 0) {
  3310. sd->menuskill_id = AC_MAKINGARROW;
  3311. sd->menuskill_val = c;
  3312. }
  3313. }
  3314. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3315. /// 00bc <status id>.W <result>.B <value>.B
  3316. /// status id:
  3317. /// SP_STR ~ SP_LUK
  3318. /// result:
  3319. /// 0 = failure
  3320. /// 1 = success
  3321. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3322. int fd;
  3323. nullpo_retv(sd);
  3324. fd=sd->fd;
  3325. WFIFOHEAD(fd, packet_len(0xbc));
  3326. WFIFOW(fd,0) = 0xbc;
  3327. WFIFOW(fd,2) = type;
  3328. WFIFOB(fd,4) = ok;
  3329. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3330. WFIFOSET(fd, packet_len(0xbc));
  3331. }
  3332. /// Notifies the client about the result of a request to equip an item.
  3333. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3334. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3335. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3336. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3337. /// @ok: //inversed forv2 v5
  3338. /// 0 = failure
  3339. /// 1 = success
  3340. /// 2 = failure due to low level
  3341. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3342. {
  3343. int fd = 0, cmd = 0, look = 0;
  3344. struct s_packet_db *info = NULL;
  3345. nullpo_retv(sd);
  3346. cmd = packet_db_ack[ZC_WEAR_EQUIP_ACK];
  3347. if (!cmd || !(info = &packet_db[cmd]) || !info->len)
  3348. return;
  3349. fd = sd->fd;
  3350. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3351. look = sd->inventory_data[n]->look;
  3352. WFIFOHEAD(fd, info->len);
  3353. WFIFOW(fd, 0) = cmd;
  3354. WFIFOW(fd, info->pos[0]) = n+2;
  3355. switch (cmd) {
  3356. case 0xaa:
  3357. WFIFOW(fd, info->pos[1]) = pos;
  3358. #if PACKETVER < 20100629
  3359. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3360. #else
  3361. WFIFOL(fd, info->pos[2]) = look;
  3362. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3363. #endif
  3364. break;
  3365. case 0x8d0:
  3366. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3367. flag = 1;
  3368. case 0x999:
  3369. if (cmd == 0x999)
  3370. WFIFOL(fd, info->pos[1]) = pos;
  3371. else
  3372. WFIFOW(fd, info->pos[1]) = pos;
  3373. WFIFOL(fd, info->pos[2]) = look;
  3374. WFIFOW(fd, info->pos[3]) = flag;
  3375. break;
  3376. }
  3377. WFIFOSET(fd, info->len);
  3378. }
  3379. /// Notifies the client about the result of a request to take off an item.
  3380. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3381. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3382. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3383. /// @ok : //inversed for v2 v5
  3384. /// 0 = failure
  3385. /// 1 = success
  3386. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3387. {
  3388. int fd, header, offs = 0;
  3389. #if PACKETVER >= 20130000
  3390. header = 0x99a;
  3391. ok = ok ? 0 : 1;
  3392. #elif PACKETVER >= 20110824
  3393. header = 0x8d1;
  3394. ok = ok ? 0 : 1;
  3395. #else
  3396. header = 0xac;
  3397. #endif
  3398. nullpo_retv(sd);
  3399. fd=sd->fd;
  3400. WFIFOHEAD(fd, packet_len(header));
  3401. WFIFOW(fd,offs+0) = header;
  3402. WFIFOW(fd,offs+2) = n+2;
  3403. #if PACKETVER >= 20130000
  3404. WFIFOL(fd,offs+4) = pos;
  3405. offs += 2;
  3406. #else
  3407. WFIFOW(fd,offs+4) = pos;
  3408. #endif
  3409. WFIFOB(fd,offs+6) = ok;
  3410. WFIFOSET(fd, packet_len(header));
  3411. }
  3412. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3413. /// 019b <id>.L <effect id>.L
  3414. /// effect id:
  3415. /// 0 = base level up
  3416. /// 1 = job level up
  3417. /// 2 = refine failure
  3418. /// 3 = refine success
  3419. /// 4 = game over
  3420. /// 5 = pharmacy success
  3421. /// 6 = pharmacy failure
  3422. /// 7 = base level up (super novice)
  3423. /// 8 = job level up (super novice)
  3424. /// 9 = base level up (taekwon)
  3425. void clif_misceffect(struct block_list* bl,int type)
  3426. {
  3427. unsigned char buf[32];
  3428. nullpo_retv(bl);
  3429. WBUFW(buf,0) = 0x19b;
  3430. WBUFL(buf,2) = bl->id;
  3431. WBUFL(buf,6) = type;
  3432. clif_send(buf,packet_len(0x19b),bl,AREA);
  3433. }
  3434. /// Notifies clients in the area of a state change.
  3435. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3436. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3437. void clif_changeoption(struct block_list* bl)
  3438. {
  3439. unsigned char buf[32];
  3440. struct status_change *sc;
  3441. struct map_session_data* sd;
  3442. nullpo_retv(bl);
  3443. sc = status_get_sc(bl);
  3444. if (!sc) return; //How can an option change if there's no sc?
  3445. sd = BL_CAST(BL_PC, bl);
  3446. #if PACKETVER >= 7
  3447. WBUFW(buf,0) = 0x229;
  3448. WBUFL(buf,2) = bl->id;
  3449. WBUFW(buf,6) = sc->opt1;
  3450. WBUFW(buf,8) = sc->opt2;
  3451. WBUFL(buf,10) = sc->option;
  3452. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3453. if(disguised(bl)) {
  3454. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3455. WBUFL(buf,2) = -bl->id;
  3456. clif_send(buf,packet_len(0x229),bl,SELF);
  3457. WBUFL(buf,2) = bl->id;
  3458. WBUFL(buf,10) = OPTION_INVISIBLE;
  3459. clif_send(buf,packet_len(0x229),bl,SELF);
  3460. } else
  3461. clif_send(buf,packet_len(0x229),bl,AREA);
  3462. #else
  3463. WBUFW(buf,0) = 0x119;
  3464. WBUFL(buf,2) = bl->id;
  3465. WBUFW(buf,6) = sc->opt1;
  3466. WBUFW(buf,8) = sc->opt2;
  3467. WBUFW(buf,10) = sc->option;
  3468. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3469. if(disguised(bl)) {
  3470. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3471. WBUFL(buf,2) = -bl->id;
  3472. clif_send(buf,packet_len(0x119),bl,SELF);
  3473. WBUFL(buf,2) = bl->id;
  3474. WBUFW(buf,10) = OPTION_INVISIBLE;
  3475. clif_send(buf,packet_len(0x119),bl,SELF);
  3476. } else
  3477. clif_send(buf,packet_len(0x119),bl,AREA);
  3478. #endif
  3479. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3480. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3481. if (sc->data[SC_PROVOKE] && sc->data[SC_PROVOKE]->timer == INVALID_TIMER)
  3482. clif_status_change(bl, StatusIconChangeTable[SC_PROVOKE], 1, -1, 0, 0, 0);
  3483. }
  3484. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3485. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3486. void clif_changeoption2(struct block_list* bl)
  3487. {
  3488. unsigned char buf[20];
  3489. struct status_change *sc;
  3490. sc = status_get_sc(bl);
  3491. if (!sc) return; //How can an option change if there's no sc?
  3492. WBUFW(buf,0) = 0x28a;
  3493. WBUFL(buf,2) = bl->id;
  3494. WBUFL(buf,6) = sc->option;
  3495. WBUFL(buf,10) = clif_setlevel(bl);
  3496. WBUFL(buf,14) = sc->opt3;
  3497. if(disguised(bl)) {
  3498. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3499. WBUFL(buf,2) = -bl->id;
  3500. clif_send(buf,packet_len(0x28a),bl,SELF);
  3501. WBUFL(buf,2) = bl->id;
  3502. WBUFL(buf,6) = OPTION_INVISIBLE;
  3503. clif_send(buf,packet_len(0x28a),bl,SELF);
  3504. } else
  3505. clif_send(buf,packet_len(0x28a),bl,AREA);
  3506. }
  3507. /// Notifies the client about the result of an item use request.
  3508. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3509. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3510. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3511. {
  3512. nullpo_retv(sd);
  3513. if(!ok) {
  3514. int fd=sd->fd;
  3515. WFIFOHEAD(fd,packet_len(0xa8));
  3516. WFIFOW(fd,0)=0xa8;
  3517. WFIFOW(fd,2)=index+2;
  3518. WFIFOW(fd,4)=amount;
  3519. WFIFOB(fd,6)=ok;
  3520. WFIFOSET(fd,packet_len(0xa8));
  3521. }
  3522. else {
  3523. #if PACKETVER < 3
  3524. int fd=sd->fd;
  3525. WFIFOHEAD(fd,packet_len(0xa8));
  3526. WFIFOW(fd,0)=0xa8;
  3527. WFIFOW(fd,2)=index+2;
  3528. WFIFOW(fd,4)=amount;
  3529. WFIFOB(fd,6)=ok;
  3530. WFIFOSET(fd,packet_len(0xa8));
  3531. #else
  3532. unsigned char buf[32];
  3533. WBUFW(buf,0)=0x1c8;
  3534. WBUFW(buf,2)=index+2;
  3535. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3536. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3537. else
  3538. WBUFW(buf,4)=sd->inventory.u.items_inventory[index].nameid;
  3539. WBUFL(buf,6)=sd->bl.id;
  3540. WBUFW(buf,10)=amount;
  3541. WBUFB(buf,12)=ok;
  3542. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3543. #endif
  3544. }
  3545. }
  3546. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3547. /// 00d6 <flag>.B
  3548. /// flag:
  3549. /// 0 = Room has been successfully created (opens chat room)
  3550. /// 1 = Room limit exceeded
  3551. /// 2 = Same room already exists
  3552. void clif_createchat(struct map_session_data* sd, int flag)
  3553. {
  3554. int fd;
  3555. nullpo_retv(sd);
  3556. fd = sd->fd;
  3557. WFIFOHEAD(fd,packet_len(0xd6));
  3558. WFIFOW(fd,0) = 0xd6;
  3559. WFIFOB(fd,2) = flag;
  3560. WFIFOSET(fd,packet_len(0xd6));
  3561. }
  3562. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3563. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3564. /// type:
  3565. /// 0 = private (password protected)
  3566. /// 1 = public
  3567. /// 2 = arena (npc waiting room)
  3568. /// 3 = PK zone (non-clickable)
  3569. void clif_dispchat(struct chat_data* cd, int fd)
  3570. {
  3571. unsigned char buf[128];
  3572. uint8 type;
  3573. if( cd == NULL || cd->owner == NULL )
  3574. return;
  3575. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3576. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3577. : 1;
  3578. WBUFW(buf, 0) = 0xd7;
  3579. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3580. WBUFL(buf, 4) = cd->owner->id;
  3581. WBUFL(buf, 8) = cd->bl.id;
  3582. WBUFW(buf,12) = cd->limit;
  3583. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3584. WBUFB(buf,16) = type;
  3585. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3586. if( fd ) {
  3587. WFIFOHEAD(fd,WBUFW(buf,2));
  3588. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3589. WFIFOSET(fd,WBUFW(buf,2));
  3590. } else {
  3591. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3592. }
  3593. }
  3594. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3595. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3596. /// type:
  3597. /// 0 = private (password protected)
  3598. /// 1 = public
  3599. /// 2 = arena (npc waiting room)
  3600. /// 3 = PK zone (non-clickable)
  3601. void clif_changechatstatus(struct chat_data* cd)
  3602. {
  3603. unsigned char buf[128];
  3604. uint8 type;
  3605. if( cd == NULL || cd->usersd[0] == NULL )
  3606. return;
  3607. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3608. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3609. : 1;
  3610. WBUFW(buf, 0) = 0xdf;
  3611. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3612. WBUFL(buf, 4) = cd->owner->id;
  3613. WBUFL(buf, 8) = cd->bl.id;
  3614. WBUFW(buf,12) = cd->limit;
  3615. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3616. WBUFB(buf,16) = type;
  3617. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3618. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3619. }
  3620. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3621. /// 00d8 <chat id>.L
  3622. void clif_clearchat(struct chat_data *cd,int fd)
  3623. {
  3624. unsigned char buf[32];
  3625. nullpo_retv(cd);
  3626. WBUFW(buf,0) = 0xd8;
  3627. WBUFL(buf,2) = cd->bl.id;
  3628. if( fd ) {
  3629. WFIFOHEAD(fd,packet_len(0xd8));
  3630. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3631. WFIFOSET(fd,packet_len(0xd8));
  3632. } else {
  3633. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3634. }
  3635. }
  3636. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3637. /// 00da <result>.B
  3638. /// result:
  3639. /// 0 = room full
  3640. /// 1 = wrong password
  3641. /// 2 = kicked
  3642. /// 3 = success (no message)
  3643. /// 4 = no enough zeny
  3644. /// 5 = too low level
  3645. /// 6 = too high level
  3646. /// 7 = unsuitable job class
  3647. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3648. {
  3649. int fd;
  3650. nullpo_retv(sd);
  3651. fd = sd->fd;
  3652. WFIFOHEAD(fd,packet_len(0xda));
  3653. WFIFOW(fd,0) = 0xda;
  3654. WFIFOB(fd,2) = flag;
  3655. WFIFOSET(fd,packet_len(0xda));
  3656. }
  3657. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3658. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3659. /// role:
  3660. /// 0 = owner (menu)
  3661. /// 1 = normal
  3662. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3663. {
  3664. int fd;
  3665. int i,t;
  3666. nullpo_retv(sd);
  3667. nullpo_retv(cd);
  3668. fd = sd->fd;
  3669. if (!session_isActive(fd))
  3670. return;
  3671. t = (int)(cd->owner->type == BL_NPC);
  3672. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3673. WFIFOW(fd, 0) = 0xdb;
  3674. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3675. WFIFOL(fd, 4) = cd->bl.id;
  3676. if(cd->owner->type == BL_NPC){
  3677. WFIFOL(fd, 30) = 1;
  3678. WFIFOL(fd, 8) = 0;
  3679. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3680. for (i = 0; i < cd->users; i++) {
  3681. WFIFOL(fd, 8+(i+1)*28) = 1;
  3682. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3683. }
  3684. }else{
  3685. for (i = 0; i < cd->users; i++) {
  3686. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3687. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3688. }
  3689. }
  3690. WFIFOSET(fd, WFIFOW(fd, 2));
  3691. }
  3692. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3693. /// 00dc <users>.W <name>.24B
  3694. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3695. {
  3696. unsigned char buf[29];
  3697. nullpo_retv(sd);
  3698. nullpo_retv(cd);
  3699. WBUFW(buf, 0) = 0xdc;
  3700. WBUFW(buf, 2) = cd->users;
  3701. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3702. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3703. }
  3704. /// Announce the new owner (ZC_ROLE_CHANGE).
  3705. /// 00e1 <role>.L <nick>.24B
  3706. /// role:
  3707. /// 0 = owner (menu)
  3708. /// 1 = normal
  3709. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3710. {
  3711. unsigned char buf[64];
  3712. nullpo_retv(sd);
  3713. nullpo_retv(cd);
  3714. WBUFW(buf, 0) = 0xe1;
  3715. WBUFL(buf, 2) = 1;
  3716. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3717. WBUFW(buf,30) = 0xe1;
  3718. WBUFL(buf,32) = 0;
  3719. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3720. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3721. }
  3722. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3723. /// 00dd <users>.W <nick>.24B <flag>.B
  3724. /// flag:
  3725. /// 0 = left
  3726. /// 1 = kicked
  3727. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3728. {
  3729. unsigned char buf[32];
  3730. nullpo_retv(sd);
  3731. nullpo_retv(cd);
  3732. WBUFW(buf, 0) = 0xdd;
  3733. WBUFW(buf, 2) = cd->users-1;
  3734. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3735. WBUFB(buf,28) = flag;
  3736. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3737. }
  3738. /// Opens a trade request window from char 'name'.
  3739. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3740. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3741. void clif_traderequest(struct map_session_data* sd, const char* name)
  3742. {
  3743. int fd = sd->fd;
  3744. #if PACKETVER < 6
  3745. WFIFOHEAD(fd,packet_len(0xe5));
  3746. WFIFOW(fd,0) = 0xe5;
  3747. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3748. WFIFOSET(fd,packet_len(0xe5));
  3749. #else
  3750. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3751. if( !tsd ) return;
  3752. WFIFOHEAD(fd,packet_len(0x1f4));
  3753. WFIFOW(fd,0) = 0x1f4;
  3754. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3755. WFIFOL(fd,26) = tsd->status.char_id;
  3756. WFIFOW(fd,30) = tsd->status.base_level;
  3757. WFIFOSET(fd,packet_len(0x1f4));
  3758. #endif
  3759. }
  3760. /// Reply to a trade-request.
  3761. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3762. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3763. /// result:
  3764. /// 0 = Char is too far
  3765. /// 1 = Character does not exist
  3766. /// 2 = Trade failed
  3767. /// 3 = Accept
  3768. /// 4 = Cancel
  3769. /// 5 = Busy
  3770. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3771. {
  3772. int fd = sd->fd;
  3773. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3774. if( PACKETVER < 6 || !tsd ) {
  3775. WFIFOHEAD(fd,packet_len(0xe7));
  3776. WFIFOW(fd,0) = 0xe7;
  3777. WFIFOB(fd,2) = type;
  3778. WFIFOSET(fd,packet_len(0xe7));
  3779. } else {
  3780. WFIFOHEAD(fd,packet_len(0x1f5));
  3781. WFIFOW(fd,0) = 0x1f5;
  3782. WFIFOB(fd,2) = type;
  3783. WFIFOL(fd,3) = tsd->status.char_id;
  3784. WFIFOW(fd,7) = tsd->status.base_level;
  3785. WFIFOSET(fd,packet_len(0x1f5));
  3786. }
  3787. }
  3788. /// Notifies the client about an item from other player in current trade.
  3789. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3790. /// 080f <nameid>.W <item type>.B <amount>.L <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM2)
  3791. /// 0a09 <nameid>.W <item type>.B <amount>.L <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM3)
  3792. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3793. {
  3794. int fd;
  3795. unsigned char *buf;
  3796. #if PACKETVER < 20100223
  3797. const int cmd = 0xe9;
  3798. #elif PACKETVER < 20150225
  3799. const int cmd = 0x80f;
  3800. #else
  3801. const int cmd = 0xa09;
  3802. #endif
  3803. nullpo_retv(sd);
  3804. nullpo_retv(tsd);
  3805. fd = tsd->fd;
  3806. buf = WFIFOP(fd,0);
  3807. WFIFOHEAD(fd,packet_len(cmd));
  3808. WBUFW(buf,0) = cmd;
  3809. if( index == 0 )
  3810. {
  3811. #if PACKETVER < 20100223
  3812. WBUFL(buf,2) = amount; //amount
  3813. WBUFW(buf,6) = 0; // type id
  3814. #else
  3815. WBUFW(buf,2) = 0; // type id
  3816. WBUFB(buf,4) = 0; // item type
  3817. WBUFL(buf,5) = amount; // amount
  3818. buf = WBUFP(buf,1); //Advance 1B
  3819. #endif
  3820. WBUFB(buf,8) = 0; //identify flag
  3821. WBUFB(buf,9) = 0; // attribute
  3822. WBUFB(buf,10)= 0; //refine
  3823. WBUFW(buf,11)= 0; //card (4w)
  3824. WBUFW(buf,13)= 0; //card (4w)
  3825. WBUFW(buf,15)= 0; //card (4w)
  3826. WBUFW(buf,17)= 0; //card (4w)
  3827. #if PACKETVER >= 20150225
  3828. clif_add_random_options(WBUFP(buf, 19), &sd->inventory.u.items_inventory[index]);
  3829. #endif
  3830. }
  3831. else
  3832. {
  3833. index -= 2; //index fix
  3834. #if PACKETVER < 20100223
  3835. WBUFL(buf,2) = amount; //amount
  3836. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3837. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3838. else
  3839. WBUFW(buf,6) = sd->inventory.u.items_inventory[index].nameid; // type id
  3840. #else
  3841. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3842. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3843. else
  3844. WBUFW(buf,2) = sd->inventory.u.items_inventory[index].nameid; // type id
  3845. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3846. WBUFL(buf,5) = amount; // amount
  3847. buf = WBUFP(buf,1); //Advance 1B
  3848. #endif
  3849. WBUFB(buf,8) = sd->inventory.u.items_inventory[index].identify; //identify flag
  3850. WBUFB(buf,9) = sd->inventory.u.items_inventory[index].attribute; // attribute
  3851. WBUFB(buf,10)= sd->inventory.u.items_inventory[index].refine; //refine
  3852. clif_addcards(WBUFP(buf, 11), &sd->inventory.u.items_inventory[index]);
  3853. #if PACKETVER >= 20150225
  3854. clif_add_random_options(WBUFP(buf, 19), &sd->inventory.u.items_inventory[index]);
  3855. #endif
  3856. }
  3857. WFIFOSET(fd,packet_len(cmd));
  3858. }
  3859. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3860. /// 00ea <index>.W <result>.B
  3861. /// result:
  3862. /// 0 = success
  3863. /// 1 = overweight
  3864. /// 2 = trade canceled
  3865. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3866. {
  3867. int fd;
  3868. nullpo_retv(sd);
  3869. fd = sd->fd;
  3870. WFIFOHEAD(fd,packet_len(0xea));
  3871. WFIFOW(fd,0) = 0xea;
  3872. WFIFOW(fd,2) = index;
  3873. WFIFOB(fd,4) = fail;
  3874. WFIFOSET(fd,packet_len(0xea));
  3875. }
  3876. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3877. /// 00ec <who>.B
  3878. /// who:
  3879. /// 0 = self
  3880. /// 1 = other player
  3881. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3882. {
  3883. int fd;
  3884. nullpo_retv(sd);
  3885. fd = sd->fd;
  3886. WFIFOHEAD(fd,packet_len(0xec));
  3887. WFIFOW(fd,0) = 0xec;
  3888. WFIFOB(fd,2) = fail;
  3889. WFIFOSET(fd,packet_len(0xec));
  3890. }
  3891. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3892. /// 00ee
  3893. void clif_tradecancelled(struct map_session_data* sd)
  3894. {
  3895. int fd;
  3896. nullpo_retv(sd);
  3897. fd = sd->fd;
  3898. WFIFOHEAD(fd,packet_len(0xee));
  3899. WFIFOW(fd,0) = 0xee;
  3900. WFIFOSET(fd,packet_len(0xee));
  3901. }
  3902. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3903. /// 00f0 <result>.B
  3904. /// result:
  3905. /// 0 = success
  3906. /// 1 = failure
  3907. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3908. {
  3909. int fd;
  3910. nullpo_retv(sd);
  3911. fd = sd->fd;
  3912. WFIFOHEAD(fd,packet_len(0xf0));
  3913. WFIFOW(fd,0) = 0xf0;
  3914. WFIFOB(fd,2) = fail;
  3915. WFIFOSET(fd,packet_len(0xf0));
  3916. }
  3917. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3918. /// 00f1
  3919. /// NOTE: Unknown purpose. Items are not removed until the window is
  3920. /// refreshed (ex. by putting another item in there).
  3921. void clif_tradeundo(struct map_session_data* sd)
  3922. {
  3923. int fd = sd->fd;
  3924. WFIFOHEAD(fd,packet_len(0xf1));
  3925. WFIFOW(fd,0) = 0xf1;
  3926. WFIFOSET(fd,packet_len(0xf1));
  3927. }
  3928. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3929. /// 00f2 <current count>.W <max count>.W
  3930. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3931. {
  3932. int fd;
  3933. nullpo_retv(sd);
  3934. fd=sd->fd;
  3935. WFIFOHEAD(fd,packet_len(0xf2));
  3936. WFIFOW(fd,0) = 0xf2;
  3937. WFIFOW(fd,2) = amount;
  3938. WFIFOW(fd,4) = max_amount;
  3939. WFIFOSET(fd,packet_len(0xf2));
  3940. }
  3941. /// Notifies the client of an item being added to the storage.
  3942. /// 00f4 <index>.W <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_STORE)
  3943. /// 01c4 <index>.W <amount>.L <nameid>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_STORE2)
  3944. /// 0a0a <index>.W <amount>.L <nameid>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_STORE3)
  3945. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3946. {
  3947. #if PACKETVER < 5
  3948. const int cmd = 0xf4;
  3949. #elif PACKETVER < 20150225
  3950. const int cmd = 0x1c4;
  3951. #else
  3952. const int cmd = 0xa0a;
  3953. #endif
  3954. int view,fd;
  3955. int offset = 0;
  3956. nullpo_retv(sd);
  3957. nullpo_retv(i);
  3958. fd=sd->fd;
  3959. view = itemdb_viewid(i->nameid);
  3960. WFIFOHEAD(fd,packet_len(cmd));
  3961. WFIFOW(fd, 0) = cmd; // Storage item added
  3962. WFIFOW(fd, 2) = index+1; // index
  3963. WFIFOL(fd, 4) = amount; // amount
  3964. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3965. #if PACKETVER >= 5
  3966. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3967. offset += 1;
  3968. #endif
  3969. WFIFOB(fd,10+offset) = i->identify; //identify flag
  3970. WFIFOB(fd,11+offset) = i->attribute; // attribute
  3971. WFIFOB(fd,12+offset) = i->refine; //refine
  3972. clif_addcards(WFIFOP(fd,13+offset), i);
  3973. #if PACKETVER >= 20150225
  3974. clif_add_random_options(WFIFOP(fd,21+offset), i);
  3975. #endif
  3976. WFIFOSET(fd,packet_len(cmd));
  3977. }
  3978. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  3979. /// 00f6 <index>.W <amount>.L
  3980. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3981. {
  3982. int fd;
  3983. nullpo_retv(sd);
  3984. fd=sd->fd;
  3985. WFIFOHEAD(fd,packet_len(0xf6));
  3986. WFIFOW(fd,0)=0xf6; // Storage item removed
  3987. WFIFOW(fd,2)=index+1;
  3988. WFIFOL(fd,4)=amount;
  3989. WFIFOSET(fd,packet_len(0xf6));
  3990. }
  3991. /// Closes storage (ZC_CLOSE_STORE).
  3992. /// 00f8
  3993. void clif_storageclose(struct map_session_data* sd)
  3994. {
  3995. int fd;
  3996. nullpo_retv(sd);
  3997. fd=sd->fd;
  3998. WFIFOHEAD(fd,packet_len(0xf8));
  3999. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4000. WFIFOSET(fd,packet_len(0xf8));
  4001. }
  4002. /*==========================================
  4003. * Server tells 'sd' player client the abouts of 'dstsd' player
  4004. *------------------------------------------*/
  4005. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  4006. {
  4007. struct block_list *d_bl;
  4008. int i;
  4009. if( dstsd->chatID ) {
  4010. struct chat_data *cd = NULL;
  4011. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4012. clif_dispchat(cd,sd->fd);
  4013. } else if( dstsd->state.vending )
  4014. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  4015. else if( dstsd->state.buyingstore )
  4016. clif_buyingstore_entry_single(sd, dstsd);
  4017. if(dstsd->spiritball > 0)
  4018. clif_spiritball_single(sd->fd, dstsd);
  4019. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4020. clif_spiritcharm_single(sd->fd, dstsd);
  4021. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4022. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4023. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4024. )
  4025. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  4026. // display link (sd - dstsd) to sd
  4027. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4028. if( i < MAX_DEVOTION )
  4029. clif_devotion(&sd->bl, sd);
  4030. // display links (dstsd - devotees) to sd
  4031. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4032. if( i < MAX_DEVOTION )
  4033. clif_devotion(&dstsd->bl, sd);
  4034. // display link (dstsd - crusader) to sd
  4035. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4036. clif_devotion(d_bl, sd);
  4037. }
  4038. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  4039. {
  4040. uint8 buf[128];
  4041. struct unit_data *ud;
  4042. struct view_data *vd;
  4043. int len;
  4044. vd = status_get_viewdata(bl);
  4045. if (!vd || vd->class_ == INVISIBLE_CLASS)
  4046. return;
  4047. /**
  4048. * Hide NPC from maya purple card.
  4049. **/
  4050. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4051. return;
  4052. ud = unit_bl2ud(bl);
  4053. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  4054. clif_send(buf,len,&sd->bl,SELF);
  4055. if (vd->cloth_color)
  4056. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4057. if (vd->body_style)
  4058. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4059. switch (bl->type)
  4060. {
  4061. case BL_PC:
  4062. {
  4063. TBL_PC* tsd = (TBL_PC*)bl;
  4064. clif_getareachar_pc(sd, tsd);
  4065. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4066. clif_specialeffect_single(bl,423,sd->fd);
  4067. else if(tsd->state.size==SZ_MEDIUM)
  4068. clif_specialeffect_single(bl,421,sd->fd);
  4069. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  4070. clif_sendbgemblem_single(sd->fd,tsd);
  4071. if ( tsd->status.robe )
  4072. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4073. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4074. clif_hat_effects(sd,bl,SELF);
  4075. }
  4076. break;
  4077. case BL_MER: // Devotion Effects
  4078. if( ((TBL_MER*)bl)->devotion_flag )
  4079. clif_devotion(bl, sd);
  4080. break;
  4081. case BL_NPC:
  4082. {
  4083. TBL_NPC* nd = (TBL_NPC*)bl;
  4084. if( nd->chat_id )
  4085. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4086. if( nd->size == SZ_BIG )
  4087. clif_specialeffect_single(bl,423,sd->fd);
  4088. else if( nd->size == SZ_MEDIUM )
  4089. clif_specialeffect_single(bl,421,sd->fd);
  4090. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4091. clif_progressbar_npc(nd, sd);
  4092. }
  4093. break;
  4094. case BL_MOB:
  4095. {
  4096. TBL_MOB* md = (TBL_MOB*)bl;
  4097. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4098. clif_specialeffect_single(bl,423,sd->fd);
  4099. else if(md->special_state.size==SZ_MEDIUM)
  4100. clif_specialeffect_single(bl,421,sd->fd);
  4101. #if PACKETVER >= 20120404
  4102. if (battle_config.monster_hp_bars_info && !map[bl->m].flag.hidemobhpbar) {
  4103. int i;
  4104. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4105. if( md->dmglog[i].id == sd->status.char_id )
  4106. clif_monster_hp_bar(md, sd->fd);
  4107. }
  4108. #endif
  4109. }
  4110. break;
  4111. case BL_PET:
  4112. if (vd->head_bottom)
  4113. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4114. break;
  4115. }
  4116. }
  4117. //Modifies the type of damage according to status changes [Skotlex]
  4118. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4119. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4120. {
  4121. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4122. }
  4123. /*==========================================
  4124. * Estimates walk delay based on the damage criteria. [Skotlex]
  4125. *------------------------------------------*/
  4126. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4127. {
  4128. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4129. return 0;
  4130. if (bl->type == BL_PC) {
  4131. if (battle_config.pc_walk_delay_rate != 100)
  4132. delay = delay*battle_config.pc_walk_delay_rate/100;
  4133. } else
  4134. if (battle_config.walk_delay_rate != 100)
  4135. delay = delay*battle_config.walk_delay_rate/100;
  4136. if (div_ > 1) //Multi-hit skills mean higher delays.
  4137. delay += battle_config.multihit_delay*(div_-1);
  4138. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4139. }
  4140. /*========================================== [Playtester]
  4141. * Returns hallucination damage the client displays
  4142. *------------------------------------------*/
  4143. static int clif_hallucination_damage()
  4144. {
  4145. int digit = rnd() % 5 + 1;
  4146. switch (digit)
  4147. {
  4148. case 1:
  4149. return (rnd() % 10);
  4150. case 2:
  4151. return (rnd() % 100);
  4152. case 3:
  4153. return (rnd() % 1000);
  4154. case 4:
  4155. return (rnd() % 10000);
  4156. }
  4157. return (rnd() % 32767);
  4158. }
  4159. /// Sends a 'damage' packet (src performs action on dst)
  4160. /// 008a <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.W <div>.W <type>.B <damage2>.W (ZC_NOTIFY_ACT)
  4161. /// 02e1 <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.L <div>.W <type>.B <damage2>.L (ZC_NOTIFY_ACT2)
  4162. /// 08c8 <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.L <IsSPDamage>.B <div>.W <type>.B <damage2>.L (ZC_NOTIFY_ACT3)
  4163. /// type:
  4164. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4165. /// 1 = pick up item
  4166. /// 2 = sit down
  4167. /// 3 = stand up
  4168. /// 4 = damage (endure)
  4169. /// 5 = (splash?)
  4170. /// 6 = (skill?)
  4171. /// 7 = (repeat damage?)
  4172. /// 8 = multi-hit damage
  4173. /// 9 = multi-hit damage (endure)
  4174. /// 10 = critical hit
  4175. /// 11 = lucky dodge
  4176. /// 12 = (touch skill?)
  4177. int clif_damage(struct block_list* src, struct block_list* dst, unsigned int tick, int sdelay, int ddelay, int64 sdamage, int div, enum e_damage_type type, int64 sdamage2, bool spdamage)
  4178. {
  4179. unsigned char buf[34];
  4180. struct status_change *sc;
  4181. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4182. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4183. #if PACKETVER < 20071113
  4184. const int cmd = 0x8a;
  4185. int offset = 0;
  4186. #elif PACKETVER < 20131223
  4187. const int cmd = 0x2e1;
  4188. int offset = 2;
  4189. #else
  4190. const int cmd = 0x8c8;
  4191. int offset = 3;
  4192. #endif
  4193. nullpo_ret(src);
  4194. nullpo_ret(dst);
  4195. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4196. sc = status_get_sc(dst);
  4197. if(sc && sc->count) {
  4198. if(sc->data[SC_HALLUCINATION]) {
  4199. if(damage) damage = clif_hallucination_damage();
  4200. if(damage2) damage2 = clif_hallucination_damage();
  4201. }
  4202. }
  4203. WBUFW(buf,0) = cmd;
  4204. WBUFL(buf,2) = src->id;
  4205. WBUFL(buf,6) = dst->id;
  4206. WBUFL(buf,10) = tick;
  4207. WBUFL(buf,14) = sdelay;
  4208. WBUFL(buf,18) = ddelay;
  4209. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4210. #if PACKETVER < 20071113
  4211. WBUFW(buf,22) = damage ? div : 0;
  4212. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4213. #else
  4214. WBUFL(buf, 22) = damage ? div : 0;
  4215. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4216. #endif
  4217. } else {
  4218. #if PACKETVER < 20071113
  4219. WBUFW(buf,22) = min(damage, INT16_MAX);
  4220. WBUFW(buf,27+offset) = damage2;
  4221. #else
  4222. WBUFL(buf,22) = damage;
  4223. WBUFL(buf,27+offset) = damage2;
  4224. #endif
  4225. }
  4226. #if PACKETVER >= 20131223
  4227. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4228. #endif
  4229. WBUFW(buf,24+offset) = div;
  4230. WBUFB(buf,26+offset) = type;
  4231. if(disguised(dst)) {
  4232. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4233. WBUFL(buf,6) = -dst->id;
  4234. clif_send(buf, packet_len(cmd), dst, SELF);
  4235. } else
  4236. clif_send(buf, packet_len(cmd), dst, AREA);
  4237. if(disguised(src)) {
  4238. WBUFL(buf,2) = -src->id;
  4239. if (disguised(dst))
  4240. WBUFL(buf,6) = dst->id;
  4241. #if PACKETVER < 20071113
  4242. if(damage > 0) WBUFW(buf,22) = -1;
  4243. if(damage2 > 0) WBUFW(buf,27) = -1;
  4244. #else
  4245. if(damage > 0) WBUFL(buf,22) = -1;
  4246. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4247. #endif
  4248. clif_send(buf,packet_len(cmd),src,SELF);
  4249. }
  4250. if(src == dst) {
  4251. unit_setdir(src, unit_getdir(src));
  4252. }
  4253. //Return adjusted can't walk delay for further processing.
  4254. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4255. }
  4256. /*==========================================
  4257. * src picks up dst
  4258. *------------------------------------------*/
  4259. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4260. {
  4261. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4262. unsigned char buf[32];
  4263. nullpo_retv(src);
  4264. nullpo_retv(dst);
  4265. WBUFW(buf, 0) = 0x8a;
  4266. WBUFL(buf, 2) = src->id;
  4267. WBUFL(buf, 6) = dst->id;
  4268. WBUFB(buf,26) = 1;
  4269. clif_send(buf, packet_len(0x8a), src, AREA);
  4270. }
  4271. /*==========================================
  4272. * inform clients in area that `bl` is sitting
  4273. *------------------------------------------*/
  4274. void clif_sitting(struct block_list* bl)
  4275. {
  4276. unsigned char buf[32];
  4277. nullpo_retv(bl);
  4278. WBUFW(buf, 0) = 0x8a;
  4279. WBUFL(buf, 2) = bl->id;
  4280. WBUFB(buf,26) = 2;
  4281. clif_send(buf, packet_len(0x8a), bl, AREA);
  4282. if(disguised(bl)) {
  4283. WBUFL(buf, 2) = - bl->id;
  4284. clif_send(buf, packet_len(0x8a), bl, SELF);
  4285. }
  4286. }
  4287. /*==========================================
  4288. * inform clients in area that `bl` is standing
  4289. *------------------------------------------*/
  4290. void clif_standing(struct block_list* bl)
  4291. {
  4292. unsigned char buf[32];
  4293. nullpo_retv(bl);
  4294. WBUFW(buf, 0) = 0x8a;
  4295. WBUFL(buf, 2) = bl->id;
  4296. WBUFB(buf,26) = 3;
  4297. clif_send(buf, packet_len(0x8a), bl, AREA);
  4298. if(disguised(bl)) {
  4299. WBUFL(buf, 2) = - bl->id;
  4300. clif_send(buf, packet_len(0x8a), bl, SELF);
  4301. }
  4302. }
  4303. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4304. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4305. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4306. {
  4307. unsigned char buf[32];
  4308. WBUFW(buf,0) = 0x192;
  4309. WBUFW(buf,2) = x;
  4310. WBUFW(buf,4) = y;
  4311. WBUFW(buf,6) = type;
  4312. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4313. if( fd )
  4314. {
  4315. WFIFOHEAD(fd,packet_len(0x192));
  4316. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4317. WFIFOSET(fd,packet_len(0x192));
  4318. }
  4319. else
  4320. {
  4321. struct block_list dummy_bl;
  4322. dummy_bl.type = BL_NUL;
  4323. dummy_bl.x = x;
  4324. dummy_bl.y = y;
  4325. dummy_bl.m = m;
  4326. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4327. }
  4328. }
  4329. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4330. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4331. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  4332. {
  4333. int view,fd;
  4334. fd=sd->fd;
  4335. WFIFOHEAD(fd,packet_len(0x9d));
  4336. WFIFOW(fd,0)=0x9d;
  4337. WFIFOL(fd,2)=fitem->bl.id;
  4338. if((view = itemdb_viewid(fitem->item.nameid)) > 0)
  4339. WFIFOW(fd,6)=view;
  4340. else
  4341. WFIFOW(fd,6)=fitem->item.nameid;
  4342. WFIFOB(fd,8)=fitem->item.identify;
  4343. WFIFOW(fd,9)=fitem->bl.x;
  4344. WFIFOW(fd,11)=fitem->bl.y;
  4345. WFIFOW(fd,13)=fitem->item.amount;
  4346. WFIFOB(fd,15)=fitem->subx;
  4347. WFIFOB(fd,16)=fitem->suby;
  4348. WFIFOSET(fd,packet_len(0x9d));
  4349. }
  4350. /// Notifes client about Graffiti
  4351. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4352. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4353. unsigned char buf[128];
  4354. nullpo_retv(bl);
  4355. nullpo_retv(unit);
  4356. WBUFW(buf, 0) = 0x1c9;
  4357. WBUFL(buf, 2) = unit->bl.id;
  4358. WBUFL(buf, 6) = unit->group->src_id;
  4359. WBUFW(buf,10) = unit->bl.x;
  4360. WBUFW(buf,12) = unit->bl.y;
  4361. WBUFB(buf,14) = unit->group->unit_id;
  4362. WBUFB(buf,15) = 1;
  4363. WBUFB(buf,16) = 1;
  4364. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4365. clif_send(buf,packet_len(0x1c9),bl,target);
  4366. }
  4367. /// Notifies the client of a skill unit.
  4368. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4369. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4370. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4371. /// 09ca <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.B <visible>.B <skill level>.B (ZC_SKILL_ENTRY5)
  4372. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4373. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4374. unsigned char buf[128];
  4375. nullpo_retv(bl);
  4376. nullpo_retv(unit);
  4377. if (bl->type == BL_PC)
  4378. fd = ((TBL_PC*)bl)->fd;
  4379. if (unit->group->state.guildaura)
  4380. return;
  4381. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4382. unit_id = unit->val2&UF_SONG ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4383. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4384. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4385. else
  4386. unit_id = unit->group->unit_id;
  4387. if (!visible)
  4388. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4389. #if PACKETVER >= 3
  4390. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4391. clif_graffiti(bl, unit, target);
  4392. return;
  4393. }
  4394. #endif
  4395. #if PACKETVER <= 20120702
  4396. header = 0x011f;
  4397. //#if PACKETVER < 20110718
  4398. // header = 0x011f;
  4399. //#elif PACKETVER < 20121212
  4400. // header = 0x08c7;
  4401. #elif PACKETVER < 20130731
  4402. header = 0x099f;
  4403. #else
  4404. header = 0x09ca;
  4405. #endif
  4406. len = packet_len(header);
  4407. WBUFW(buf,pos) = header;
  4408. if (header != 0x011f) {
  4409. WBUFW(buf, pos+2) = len;
  4410. pos += 2;
  4411. }
  4412. WBUFL(buf,pos+2) = unit->bl.id;
  4413. WBUFL(buf,pos+6) = unit->group->src_id;
  4414. WBUFW(buf,pos+10) = unit->bl.x;
  4415. WBUFW(buf,pos+12) = unit->bl.y;
  4416. switch (header) {
  4417. case 0x011f:
  4418. WBUFB(buf,pos+14) = unit_id;
  4419. WBUFB(buf,pos+15) = visible;
  4420. break;
  4421. case 0x08c7:
  4422. WBUFB(buf,pos+14) = unit_id;
  4423. WBUFW(buf,pos+15) = unit->range;
  4424. WBUFB(buf,pos+17) = visible;
  4425. break;
  4426. case 0x099f:
  4427. WBUFL(buf,pos+14) = unit_id;
  4428. WBUFW(buf,pos+18) = unit->range;
  4429. WBUFB(buf,pos+20) = visible;
  4430. break;
  4431. case 0x09ca:
  4432. WBUFL(buf,pos+14) = unit_id;
  4433. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4434. WBUFB(buf,pos+19) = visible;
  4435. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4436. break;
  4437. }
  4438. clif_send(buf, len, bl, target);
  4439. if (unit->group->skill_id == WZ_ICEWALL)
  4440. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4441. }
  4442. /*==========================================
  4443. * Server tells client to remove unit of id 'unit->bl.id'
  4444. *------------------------------------------*/
  4445. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4446. {
  4447. nullpo_retv(unit);
  4448. WFIFOHEAD(fd,packet_len(0x120));
  4449. WFIFOW(fd, 0)=0x120;
  4450. WFIFOL(fd, 2)=unit->bl.id;
  4451. WFIFOSET(fd,packet_len(0x120));
  4452. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4453. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4454. }
  4455. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4456. /// 0120 <id>.L
  4457. void clif_skill_delunit(struct skill_unit *unit)
  4458. {
  4459. unsigned char buf[16];
  4460. nullpo_retv(unit);
  4461. WBUFW(buf, 0)=0x120;
  4462. WBUFL(buf, 2)=unit->bl.id;
  4463. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4464. }
  4465. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4466. /// 01ac <id>.L
  4467. /// Only affects units with class [139,153] client-side.
  4468. void clif_skillunit_update(struct block_list* bl)
  4469. {
  4470. unsigned char buf[6];
  4471. nullpo_retv(bl);
  4472. WBUFW(buf,0) = 0x1ac;
  4473. WBUFL(buf,2) = bl->id;
  4474. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4475. }
  4476. /*==========================================
  4477. *
  4478. *------------------------------------------*/
  4479. static int clif_getareachar(struct block_list* bl,va_list ap)
  4480. {
  4481. struct map_session_data *sd;
  4482. nullpo_ret(bl);
  4483. sd=va_arg(ap,struct map_session_data*);
  4484. if (sd == NULL || !sd->fd)
  4485. return 0;
  4486. switch(bl->type){
  4487. case BL_ITEM:
  4488. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4489. break;
  4490. case BL_SKILL:
  4491. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4492. break;
  4493. default:
  4494. if(&sd->bl == bl)
  4495. break;
  4496. clif_getareachar_unit(sd,bl);
  4497. break;
  4498. }
  4499. return 0;
  4500. }
  4501. /*==========================================
  4502. * tbl has gone out of view-size of bl
  4503. *------------------------------------------*/
  4504. int clif_outsight(struct block_list *bl,va_list ap)
  4505. {
  4506. struct block_list *tbl;
  4507. struct view_data *vd;
  4508. TBL_PC *sd, *tsd;
  4509. tbl=va_arg(ap,struct block_list*);
  4510. if(bl == tbl) return 0;
  4511. sd = BL_CAST(BL_PC, bl);
  4512. tsd = BL_CAST(BL_PC, tbl);
  4513. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4514. nullpo_ret(bl);
  4515. switch(bl->type){
  4516. case BL_PC:
  4517. if(sd->vd.class_ != INVISIBLE_CLASS)
  4518. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4519. if(sd->chatID){
  4520. struct chat_data *cd;
  4521. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4522. if(cd->usersd[0]==sd)
  4523. clif_dispchat(cd,tsd->fd);
  4524. }
  4525. if(sd->state.vending)
  4526. clif_closevendingboard(bl,tsd->fd);
  4527. if(sd->state.buyingstore)
  4528. clif_buyingstore_disappear_entry_single(tsd, sd);
  4529. break;
  4530. case BL_ITEM:
  4531. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4532. break;
  4533. case BL_SKILL:
  4534. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4535. break;
  4536. case BL_NPC:
  4537. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4538. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4539. break;
  4540. default:
  4541. if((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  4542. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4543. break;
  4544. }
  4545. }
  4546. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4547. nullpo_ret(tbl);
  4548. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4549. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4550. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS) &&
  4551. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4552. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4553. }
  4554. return 0;
  4555. }
  4556. /*==========================================
  4557. * tbl has come into view of bl
  4558. *------------------------------------------*/
  4559. int clif_insight(struct block_list *bl,va_list ap)
  4560. {
  4561. struct block_list *tbl;
  4562. TBL_PC *sd, *tsd;
  4563. tbl=va_arg(ap,struct block_list*);
  4564. if (bl == tbl) return 0;
  4565. sd = BL_CAST(BL_PC, bl);
  4566. tsd = BL_CAST(BL_PC, tbl);
  4567. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4568. switch(bl->type){
  4569. case BL_ITEM:
  4570. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4571. break;
  4572. case BL_SKILL:
  4573. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4574. break;
  4575. default:
  4576. clif_getareachar_unit(tsd,bl);
  4577. break;
  4578. }
  4579. }
  4580. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4581. clif_getareachar_unit(sd,tbl);
  4582. }
  4583. return 0;
  4584. }
  4585. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4586. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4587. void clif_skillinfoblock(struct map_session_data *sd)
  4588. {
  4589. int fd;
  4590. int i,len,id;
  4591. nullpo_retv(sd);
  4592. fd = sd->fd;
  4593. if (!fd)
  4594. return;
  4595. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4596. WFIFOW(fd,0) = 0x10f;
  4597. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4598. {
  4599. if( (id = sd->status.skill[i].id) != 0 )
  4600. {
  4601. // workaround for bugreport:5348
  4602. if (len + 37 > 8192)
  4603. break;
  4604. WFIFOW(fd,len) = id;
  4605. WFIFOL(fd,len+2) = skill_get_inf(id);
  4606. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4607. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4608. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4609. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4610. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4611. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4612. else
  4613. WFIFOB(fd,len+36) = 0;
  4614. len += 37;
  4615. }
  4616. }
  4617. WFIFOW(fd,2)=len;
  4618. WFIFOSET(fd,len);
  4619. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4620. for ( ; i < MAX_SKILL; i++)
  4621. {
  4622. if( (id = sd->status.skill[i].id) != 0 )
  4623. {
  4624. clif_addskill(sd, id);
  4625. clif_skillinfo(sd, id, 0);
  4626. }
  4627. }
  4628. }
  4629. /**
  4630. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4631. **/
  4632. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4633. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4634. void clif_addskill(struct map_session_data *sd, int skill_id)
  4635. {
  4636. int fd;
  4637. uint16 idx = 0;
  4638. nullpo_retv(sd);
  4639. fd = sd->fd;
  4640. if (!fd || !(idx = skill_get_index(skill_id)))
  4641. return;
  4642. if( sd->status.skill[idx].id <= 0 )
  4643. return;
  4644. WFIFOHEAD(fd, packet_len(0x111));
  4645. WFIFOW(fd,0) = 0x111;
  4646. WFIFOW(fd,2) = skill_id;
  4647. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4648. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4649. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4650. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4651. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4652. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4653. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4654. else
  4655. WFIFOB(fd,38) = 0;
  4656. WFIFOSET(fd,packet_len(0x111));
  4657. }
  4658. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4659. /// 0441 <skill id>.W
  4660. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4661. {
  4662. #if PACKETVER >= 20081217
  4663. int fd;
  4664. uint16 idx = 0;
  4665. nullpo_retv(sd);
  4666. fd = sd->fd;
  4667. if (!fd || !(idx = skill_get_index(skill_id)))
  4668. return;
  4669. WFIFOHEAD(fd,packet_len(0x441));
  4670. WFIFOW(fd,0) = 0x441;
  4671. WFIFOW(fd,2) = skill_id;
  4672. WFIFOSET(fd,packet_len(0x441));
  4673. #endif
  4674. clif_skillinfoblock(sd);
  4675. }
  4676. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4677. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4678. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4679. int fd;
  4680. nullpo_retv(sd);
  4681. fd = sd->fd;
  4682. WFIFOHEAD(fd, packet_len(0x10e));
  4683. WFIFOW(fd, 0) = 0x10e;
  4684. WFIFOW(fd, 2) = skill_id;
  4685. WFIFOW(fd, 4) = lv;
  4686. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4687. WFIFOW(fd, 8) = range;
  4688. WFIFOB(fd, 10) = upgradable;
  4689. WFIFOSET(fd, packet_len(0x10e));
  4690. }
  4691. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4692. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4693. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4694. {
  4695. const int fd = sd->fd;
  4696. uint16 idx = skill_get_index(skill_id);
  4697. if (!idx)
  4698. return;
  4699. WFIFOHEAD(fd,packet_len(0x7e1));
  4700. WFIFOW(fd,0) = 0x7e1;
  4701. WFIFOW(fd,2) = skill_id;
  4702. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4703. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4704. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4705. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4706. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4707. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4708. else
  4709. WFIFOB(fd,14) = 0;
  4710. WFIFOSET(fd,packet_len(0x7e1));
  4711. }
  4712. /// Notifies clients in area, that an object is about to use a skill.
  4713. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4714. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4715. /// property:
  4716. /// 0 = Yellow cast aura
  4717. /// 1 = Water elemental cast aura
  4718. /// 2 = Earth elemental cast aura
  4719. /// 3 = Fire elemental cast aura
  4720. /// 4 = Wind elemental cast aura
  4721. /// 5 = Poison elemental cast aura
  4722. /// 6 = Holy elemental cast aura
  4723. /// ? = like 0
  4724. /// is disposable:
  4725. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4726. /// 1 = no text
  4727. void clif_skillcasting(struct block_list* bl, int src_id, int dst_id, int dst_x, int dst_y, uint16 skill_id, int property, int casttime)
  4728. {
  4729. #if PACKETVER < 20091124
  4730. const int cmd = 0x13e;
  4731. #else
  4732. const int cmd = 0x7fb;
  4733. #endif
  4734. unsigned char buf[32];
  4735. WBUFW(buf,0) = cmd;
  4736. WBUFL(buf,2) = src_id;
  4737. WBUFL(buf,6) = dst_id;
  4738. WBUFW(buf,10) = dst_x;
  4739. WBUFW(buf,12) = dst_y;
  4740. WBUFW(buf,14) = skill_id;
  4741. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4742. WBUFL(buf,20) = casttime;
  4743. #if PACKETVER >= 20091124
  4744. WBUFB(buf,24) = 0; // isDisposable
  4745. #endif
  4746. if (disguised(bl)) {
  4747. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4748. WBUFL(buf,2) = -src_id;
  4749. clif_send(buf,packet_len(cmd), bl, SELF);
  4750. } else
  4751. clif_send(buf,packet_len(cmd), bl, AREA);
  4752. }
  4753. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4754. /// 01b9 <id>.L
  4755. void clif_skillcastcancel(struct block_list* bl)
  4756. {
  4757. unsigned char buf[16];
  4758. nullpo_retv(bl);
  4759. WBUFW(buf,0) = 0x1b9;
  4760. WBUFL(buf,2) = bl->id;
  4761. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4762. }
  4763. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4764. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4765. /// num (only used when skill id = NV_BASIC and cause = 0):
  4766. /// 0 = "skill failed" MsgStringTable[159]
  4767. /// 1 = "no emotions" MsgStringTable[160]
  4768. /// 2 = "no sit" MsgStringTable[161]
  4769. /// 3 = "no chat" MsgStringTable[162]
  4770. /// 4 = "no party" MsgStringTable[163]
  4771. /// 5 = "no shout" MsgStringTable[164]
  4772. /// 6 = "no PKing" MsgStringTable[165]
  4773. /// 7 = "no alligning" MsgStringTable[383]
  4774. /// ? = ignored
  4775. /// cause:
  4776. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4777. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4778. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4779. /// "skill failed" MsgStringTable[204] (otherwise)
  4780. /// ... = @see enum useskill_fail_cause
  4781. /// ? = ignored
  4782. ///
  4783. /// if(result!=0) doesn't display any of the previous messages
  4784. /// Note: when this packet is received an unknown flag is always set to 0,
  4785. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4786. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4787. {
  4788. int fd;
  4789. if (!sd) { //Since this is the most common nullpo....
  4790. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4791. return;
  4792. }
  4793. fd=sd->fd;
  4794. if (!fd) return;
  4795. if(battle_config.display_skill_fail&1)
  4796. return; //Disable all skill failed messages
  4797. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4798. return; //Disable delay failed messages
  4799. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4800. return;
  4801. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4802. return;
  4803. WFIFOHEAD(fd,packet_len(0x110));
  4804. WFIFOW(fd,0) = 0x110;
  4805. WFIFOW(fd,2) = skill_id;
  4806. WFIFOL(fd,4) = btype;
  4807. WFIFOB(fd,8) = 0;// success
  4808. WFIFOB(fd,9) = cause;
  4809. WFIFOSET(fd,packet_len(0x110));
  4810. }
  4811. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4812. /// 043d <skill ID>.W <tick>.L
  4813. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4814. {
  4815. #if PACKETVER>=20081112
  4816. int fd;
  4817. nullpo_retv(sd);
  4818. fd=sd->fd;
  4819. WFIFOHEAD(fd,packet_len(0x43d));
  4820. WFIFOW(fd,0) = 0x43d;
  4821. WFIFOW(fd,2) = skill_id;
  4822. WFIFOL(fd,4) = tick;
  4823. WFIFOSET(fd,packet_len(0x43d));
  4824. #endif
  4825. }
  4826. /// Skill attack effect and damage.
  4827. /// 0114 <skill id>.W <src id>.L <dst id>.L <tick>.L <src delay>.L <dst delay>.L <damage>.W <level>.W <div>.W <type>.B (ZC_NOTIFY_SKILL)
  4828. /// 01de <skill id>.W <src id>.L <dst id>.L <tick>.L <src delay>.L <dst delay>.L <damage>.L <level>.W <div>.W <type>.B (ZC_NOTIFY_SKILL2)
  4829. int clif_skill_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int64 sdamage,int div,uint16 skill_id,uint16 skill_lv,enum e_damage_type type)
  4830. {
  4831. unsigned char buf[64];
  4832. struct status_change *sc;
  4833. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4834. nullpo_ret(src);
  4835. nullpo_ret(dst);
  4836. type = clif_calc_delay(type,div,damage,ddelay);
  4837. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4838. if(sc->data[SC_HALLUCINATION] && damage)
  4839. damage = clif_hallucination_damage();
  4840. }
  4841. #if PACKETVER < 3
  4842. WBUFW(buf,0)=0x114;
  4843. WBUFW(buf,2)=skill_id;
  4844. WBUFL(buf,4)=src->id;
  4845. WBUFL(buf,8)=dst->id;
  4846. WBUFL(buf,12)=tick;
  4847. WBUFL(buf,16)=sdelay;
  4848. WBUFL(buf,20)=ddelay;
  4849. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4850. WBUFW(buf,24)=damage?div:0;
  4851. } else {
  4852. WBUFW(buf,24)=damage;
  4853. }
  4854. WBUFW(buf,26)=skill_lv;
  4855. WBUFW(buf,28)=div;
  4856. WBUFB(buf,30)=type;
  4857. if (disguised(dst)) {
  4858. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4859. WBUFL(buf,8)=-dst->id;
  4860. clif_send(buf,packet_len(0x114),dst,SELF);
  4861. } else
  4862. clif_send(buf,packet_len(0x114),dst,AREA);
  4863. if(disguised(src)) {
  4864. WBUFL(buf,4)=-src->id;
  4865. if (disguised(dst))
  4866. WBUFL(buf,8)=dst->id;
  4867. if(damage > 0)
  4868. WBUFW(buf,24)=-1;
  4869. clif_send(buf,packet_len(0x114),src,SELF);
  4870. }
  4871. #else
  4872. WBUFW(buf,0)=0x1de;
  4873. WBUFW(buf,2)=skill_id;
  4874. WBUFL(buf,4)=src->id;
  4875. WBUFL(buf,8)=dst->id;
  4876. WBUFL(buf,12)=tick;
  4877. WBUFL(buf,16)=sdelay;
  4878. WBUFL(buf,20)=ddelay;
  4879. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4880. WBUFL(buf,24)=damage?div:0;
  4881. } else {
  4882. WBUFL(buf,24)=damage;
  4883. }
  4884. WBUFW(buf,28)=skill_lv;
  4885. WBUFW(buf,30)=div;
  4886. // For some reason, late 2013 and newer clients have
  4887. // a issue that causes players and monsters to endure
  4888. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4889. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4890. #if PACKETVER < 20131223
  4891. WBUFB(buf,32)=type;
  4892. #else
  4893. WBUFB(buf,32)=( type == DMG_SKILL ) ? DMG_MULTI_HIT : type;
  4894. #endif
  4895. if (disguised(dst)) {
  4896. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4897. WBUFL(buf,8)=-dst->id;
  4898. clif_send(buf,packet_len(0x1de),dst,SELF);
  4899. } else
  4900. clif_send(buf,packet_len(0x1de),dst,AREA);
  4901. if(disguised(src)) {
  4902. WBUFL(buf,4)=-src->id;
  4903. if (disguised(dst))
  4904. WBUFL(buf,8)=dst->id;
  4905. if(damage > 0)
  4906. WBUFL(buf,24)=-1;
  4907. clif_send(buf,packet_len(0x1de),src,SELF);
  4908. }
  4909. #endif
  4910. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4911. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4912. }
  4913. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4914. /// 0115 <skill id>.W <src id>.L <dst id>.L <tick>.L <src delay>.L <dst delay>.L <x>.W <y>.W <damage>.W <level>.W <div>.W <type>.B
  4915. /*
  4916. int clif_skill_damage2(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,uint16 skill_id,uint16 skill_lv,enum e_damage_type type)
  4917. {
  4918. unsigned char buf[64];
  4919. struct status_change *sc;
  4920. nullpo_ret(src);
  4921. nullpo_ret(dst);
  4922. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  4923. type = clif_calc_delay(type,div,damage,ddelay);
  4924. sc = status_get_sc(dst);
  4925. if(sc && sc->count) {
  4926. if(sc->data[SC_HALLUCINATION] && damage)
  4927. damage = clif_hallucination_damage();
  4928. }
  4929. WBUFW(buf,0)=0x115;
  4930. WBUFW(buf,2)=skill_id;
  4931. WBUFL(buf,4)=src->id;
  4932. WBUFL(buf,8)=dst->id;
  4933. WBUFL(buf,12)=tick;
  4934. WBUFL(buf,16)=sdelay;
  4935. WBUFL(buf,20)=ddelay;
  4936. WBUFW(buf,24)=dst->x;
  4937. WBUFW(buf,26)=dst->y;
  4938. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4939. WBUFW(buf,28)=damage?div:0;
  4940. } else {
  4941. WBUFW(buf,28)=damage;
  4942. }
  4943. WBUFW(buf,30)=skill_lv;
  4944. WBUFW(buf,32)=div;
  4945. WBUFB(buf,34)=type;
  4946. clif_send(buf,packet_len(0x115),src,AREA);
  4947. if(disguised(src)) {
  4948. WBUFL(buf,4)=-src->id;
  4949. if(damage > 0)
  4950. WBUFW(buf,28)=-1;
  4951. clif_send(buf,packet_len(0x115),src,SELF);
  4952. }
  4953. if (disguised(dst)) {
  4954. WBUFL(buf,8)=-dst->id;
  4955. if (disguised(src))
  4956. WBUFL(buf,4)=src->id;
  4957. else if(damage > 0)
  4958. WBUFW(buf,28)=-1;
  4959. clif_send(buf,packet_len(0x115),dst,SELF);
  4960. }
  4961. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4962. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4963. }
  4964. */
  4965. /// Non-damaging skill effect
  4966. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  4967. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  4968. int clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, int fail)
  4969. {
  4970. unsigned char buf[17];
  4971. #if PACKETVER < 20130731
  4972. const int cmd = 0x11a;
  4973. #else
  4974. const int cmd = 0x9cb;
  4975. #endif
  4976. int offset = 0;
  4977. nullpo_ret(dst);
  4978. WBUFW(buf,0) = cmd;
  4979. WBUFW(buf,2) = skill_id;
  4980. #if PACKETVER < 20130731
  4981. WBUFW(buf,4) = min(heal, INT16_MAX);
  4982. #else
  4983. WBUFL(buf,4) = min(heal, INT32_MAX);
  4984. offset += 2;
  4985. #endif
  4986. WBUFL(buf,6+offset) = dst->id;
  4987. WBUFL(buf,10+offset) = src ? src->id : 0;
  4988. WBUFB(buf,14+offset) = fail;
  4989. if (disguised(dst)) {
  4990. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4991. WBUFL(buf,6+offset) = -dst->id;
  4992. clif_send(buf, packet_len(cmd), dst, SELF);
  4993. } else
  4994. clif_send(buf, packet_len(cmd), dst, AREA);
  4995. if(src && disguised(src)) {
  4996. WBUFL(buf,10+offset) = -src->id;
  4997. if (disguised(dst))
  4998. WBUFL(buf,6+offset) = dst->id;
  4999. clif_send(buf, packet_len(cmd), src, SELF);
  5000. }
  5001. return fail;
  5002. }
  5003. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5004. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5005. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  5006. {
  5007. unsigned char buf[32];
  5008. nullpo_retv(src);
  5009. WBUFW(buf,0)=0x117;
  5010. WBUFW(buf,2)=skill_id;
  5011. WBUFL(buf,4)=src->id;
  5012. WBUFW(buf,8)=val;
  5013. WBUFW(buf,10)=x;
  5014. WBUFW(buf,12)=y;
  5015. WBUFL(buf,14)=tick;
  5016. if(disguised(src)) {
  5017. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5018. WBUFL(buf,4)=-src->id;
  5019. clif_send(buf,packet_len(0x117),src,SELF);
  5020. } else
  5021. clif_send(buf,packet_len(0x117),src,AREA);
  5022. }
  5023. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5024. /// 011c <skill id>.W { <map name>.16B }*4
  5025. void clif_skill_warppoint(struct map_session_data* sd, uint16 skill_id, uint16 skill_lv, unsigned short map1, unsigned short map2, unsigned short map3, unsigned short map4)
  5026. {
  5027. int fd;
  5028. nullpo_retv(sd);
  5029. fd = sd->fd;
  5030. WFIFOHEAD(fd,packet_len(0x11c));
  5031. WFIFOW(fd,0) = 0x11c;
  5032. WFIFOW(fd,2) = skill_id;
  5033. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5034. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5035. else // normal map name
  5036. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5037. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5038. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5039. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5040. WFIFOSET(fd,packet_len(0x11c));
  5041. sd->menuskill_id = skill_id;
  5042. if (skill_id == AL_WARP) {
  5043. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5044. sd->state.workinprogress = WIP_DISABLE_ALL;
  5045. } else
  5046. sd->menuskill_val = skill_lv;
  5047. }
  5048. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5049. /// 011e <type>.B
  5050. /// type:
  5051. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5052. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5053. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5054. ///
  5055. /// @param sd Who receives the message
  5056. /// @param type What message
  5057. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5058. {
  5059. int fd;
  5060. nullpo_retv(sd);
  5061. fd=sd->fd;
  5062. WFIFOHEAD(fd,packet_len(0x11e));
  5063. WFIFOW(fd,0)=0x11e;
  5064. WFIFOB(fd,2)=type;
  5065. WFIFOSET(fd,packet_len(0x11e));
  5066. }
  5067. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5068. /// 0189 <type>.W
  5069. /// type:
  5070. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5071. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5072. ///
  5073. /// @param sd Who receives the message
  5074. /// @param type What message
  5075. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5076. {
  5077. int fd;
  5078. nullpo_retv(sd);
  5079. fd=sd->fd;
  5080. WFIFOHEAD(fd,packet_len(0x189));
  5081. WFIFOW(fd,0)=0x189;
  5082. WFIFOW(fd,2)=type;
  5083. WFIFOSET(fd,packet_len(0x189));
  5084. }
  5085. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5086. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5087. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5088. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5089. {
  5090. struct status_data *status;
  5091. unsigned char buf[64];
  5092. int i;//, fix;
  5093. nullpo_retv(sd);
  5094. nullpo_retv(dst);
  5095. if( dst->type != BL_MOB )
  5096. return;
  5097. status = status_get_status_data(dst);
  5098. WBUFW(buf, 0)=0x18c;
  5099. WBUFW(buf, 2)=status_get_class(dst);
  5100. WBUFW(buf, 4)=status_get_lv(dst);
  5101. WBUFW(buf, 6)=status->size;
  5102. WBUFL(buf, 8)=status->hp;
  5103. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5104. +(battle_config.estimation_type&2?status->def2:0);
  5105. WBUFW(buf,14)=status->race;
  5106. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5107. +(battle_config.estimation_type&2?status->mdef2:0);
  5108. WBUFW(buf,18)= status->def_ele;
  5109. for(i=0;i<9;i++)
  5110. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  5111. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5112. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  5113. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5114. }
  5115. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5116. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5117. /// material id:
  5118. /// unused by the client
  5119. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  5120. {
  5121. int i,c,view,fd;
  5122. nullpo_retv(sd);
  5123. if (sd->menuskill_id == skill_id)
  5124. return; //Avoid resending the menu twice or more times...
  5125. if (skill_id == GC_CREATENEWPOISON)
  5126. skill_id = GC_RESEARCHNEWPOISON;
  5127. fd = sd->fd;
  5128. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  5129. WFIFOW(fd, 0) = 0x18d;
  5130. for (i = 0, c = 0; i < MAX_SKILL_PRODUCE_DB; i++){
  5131. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5132. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  5133. )
  5134. {
  5135. if ((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  5136. WFIFOW(fd,c*8+ 4) = view;
  5137. else
  5138. WFIFOW(fd,c*8+ 4) = skill_produce_db[i].nameid;
  5139. WFIFOW(fd,c*8+ 6) = 0;
  5140. WFIFOW(fd,c*8+ 8) = 0;
  5141. WFIFOW(fd,c*8+10) = 0;
  5142. c++;
  5143. }
  5144. }
  5145. WFIFOW(fd, 2) = c*8+8;
  5146. WFIFOSET(fd,WFIFOW(fd,2));
  5147. if (c > 0) {
  5148. sd->menuskill_id = skill_id;
  5149. sd->menuskill_val = trigger;
  5150. return;
  5151. }
  5152. }
  5153. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5154. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5155. /// mk type:
  5156. /// 1 = cooking
  5157. /// 2 = arrow
  5158. /// 3 = elemental
  5159. /// 4 = GN_MIX_COOKING
  5160. /// 5 = GN_MAKEBOMB
  5161. /// 6 = GN_S_PHARMACY
  5162. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  5163. {
  5164. int fd;
  5165. int i, c;
  5166. int view;
  5167. nullpo_retv(sd);
  5168. fd = sd->fd;
  5169. if(sd->menuskill_id == skill_id)
  5170. return; //Avoid resending the menu twice or more times...
  5171. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  5172. WFIFOW(fd,0) = 0x25a;
  5173. WFIFOW(fd,4) = list_type; // list type
  5174. c = 0;
  5175. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  5176. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  5177. continue;
  5178. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  5179. WFIFOW(fd, 6 + 2 * c) = view;
  5180. else
  5181. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  5182. c++;
  5183. }
  5184. if( c > 0 || skill_id == AM_PHARMACY) {
  5185. sd->menuskill_id = skill_id;
  5186. sd->menuskill_val = trigger;
  5187. sd->menuskill_val2 = qty; // amount.
  5188. WFIFOW(fd,2) = 6 + 2 * c;
  5189. WFIFOSET(fd,WFIFOW(fd,2));
  5190. } else {
  5191. clif_menuskill_clear(sd);
  5192. #if PACKETVER >= 20090922
  5193. clif_msg_skill(sd,skill_id,INVENTORY_SPACE_FULL);
  5194. #else
  5195. WFIFOW(fd,2) = 6 + 2 * c;
  5196. WFIFOSET(fd,WFIFOW(fd,2));
  5197. #endif
  5198. }
  5199. }
  5200. /// Notifies clients of a status change.
  5201. /// 0196 <index>.W <id>.L <state>.B (ZC_MSG_STATE_CHANGE) [used for ending status changes and starting them on non-pc units (when needed)]
  5202. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5203. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5204. /// @param bl Sends packet to clients around this object
  5205. /// @param id ID of object that has this effect
  5206. /// @param type Status icon see enum si_type
  5207. /// @param flag 1:Active, 0:Deactive
  5208. /// @param tick Duration in ms
  5209. /// @param val1
  5210. /// @param val2
  5211. /// @param val3
  5212. void clif_status_change_sub(struct block_list *bl, int id, int type, int flag, int tick, int val1, int val2, int val3, enum send_target target_type)
  5213. {
  5214. unsigned char buf[32];
  5215. if (type == SI_BLANK) //It shows nothing on the client...
  5216. return;
  5217. if (type == SI_ACTIONDELAY && tick == 0)
  5218. return;
  5219. nullpo_retv(bl);
  5220. #if PACKETVER >= 20120618
  5221. if (flag && battle_config.display_status_timers)
  5222. WBUFW(buf,0) = 0x983;
  5223. else
  5224. #elif PACKETVER >= 20090121
  5225. if (flag && battle_config.display_status_timers)
  5226. WBUFW(buf,0) = 0x43f;
  5227. else
  5228. #endif
  5229. WBUFW(buf,0) = 0x196;
  5230. WBUFW(buf,2) = type;
  5231. WBUFL(buf,4) = id;
  5232. WBUFB(buf,8) = flag;
  5233. #if PACKETVER >= 20120618
  5234. if (flag && battle_config.display_status_timers) {
  5235. if (tick <= 0)
  5236. tick = 9999; // this is indeed what official servers do
  5237. WBUFL(buf,9) = tick;/* at this stage remain and total are the same value I believe */
  5238. WBUFL(buf,13) = tick;
  5239. WBUFL(buf,17) = val1;
  5240. WBUFL(buf,21) = val2;
  5241. WBUFL(buf,25) = val3;
  5242. }
  5243. #elif PACKETVER >= 20090121
  5244. if (flag && battle_config.display_status_timers) {
  5245. if (tick <= 0)
  5246. tick = 9999; // this is indeed what official servers do
  5247. WBUFL(buf,9) = tick;
  5248. WBUFL(buf,13) = val1;
  5249. WBUFL(buf,17) = val2;
  5250. WBUFL(buf,21) = val3;
  5251. }
  5252. #endif
  5253. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5254. }
  5255. /* Sends status effect to clients around the bl
  5256. * @param bl Object that has the effect
  5257. * @param type Status icon see enum si_type
  5258. * @param flag 1:Active, 0:Deactive
  5259. * @param tick Duration in ms
  5260. * @param val1
  5261. * @param val2
  5262. * @param val3
  5263. */
  5264. void clif_status_change(struct block_list *bl, int type, int flag, int tick, int val1, int val2, int val3) {
  5265. struct map_session_data *sd = NULL;
  5266. if (type == SI_BLANK) //It shows nothing on the client...
  5267. return;
  5268. if (type == SI_ACTIONDELAY && tick == 0)
  5269. return;
  5270. if (type == SI_HALLUCINATION && !battle_config.display_hallucination) // Disable Hallucination.
  5271. return;
  5272. nullpo_retv(bl);
  5273. sd = BL_CAST(BL_PC, bl);
  5274. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  5275. return;
  5276. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5277. }
  5278. /**
  5279. * Send any active EFST to those around.
  5280. * @param tbl: Unit to send the packet to
  5281. * @param bl: Objects walking into view
  5282. * @param target: Client send type
  5283. */
  5284. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5285. unsigned char i;
  5286. struct sc_display_entry **sc_display;
  5287. unsigned char sc_display_count;
  5288. nullpo_retv(bl);
  5289. switch( bl->type ){
  5290. case BL_PC: {
  5291. struct map_session_data* sd = (struct map_session_data*)bl;
  5292. sc_display = sd->sc_display;
  5293. sc_display_count = sd->sc_display_count;
  5294. }
  5295. break;
  5296. case BL_NPC: {
  5297. struct npc_data* nd = (struct npc_data*)bl;
  5298. sc_display = nd->sc_display;
  5299. sc_display_count = nd->sc_display_count;
  5300. }
  5301. break;
  5302. default:
  5303. return;
  5304. }
  5305. for (i = 0; i < sc_display_count; i++) {
  5306. enum sc_type type = sc_display[i]->type;
  5307. struct status_change *sc = status_get_sc(bl);
  5308. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5309. int tick = 0;
  5310. if (td)
  5311. tick = DIFF_TICK(td->tick, gettick());
  5312. #if PACKETVER > 20120418
  5313. clif_efst_status_change(tbl, bl->id, target, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5314. #else
  5315. clif_status_change_sub(tbl, bl->id, StatusIconChangeTable[type], 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, target);
  5316. #endif
  5317. }
  5318. }
  5319. /// Notifies the client when a player enters the screen with an active EFST.
  5320. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5321. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5322. void clif_efst_status_change(struct block_list *bl, int tid, enum send_target target, int type, int tick, int val1, int val2, int val3) {
  5323. #if PACKETVER >= 20111108
  5324. unsigned char buf[32];
  5325. #if PACKETVER >= 20120618
  5326. const int cmd = 0x984;
  5327. #elif PACKETVER >= 20111108
  5328. const int cmd = 0x8ff;
  5329. #endif
  5330. int offset = 0;
  5331. if (type == SI_BLANK)
  5332. return;
  5333. nullpo_retv(bl);
  5334. if (tick <= 0)
  5335. tick = 9999;
  5336. WBUFW(buf,offset + 0) = cmd;
  5337. WBUFL(buf,offset + 2) = tid;
  5338. WBUFW(buf,offset + 6) = type;
  5339. #if PACKETVER >= 20111108
  5340. WBUFL(buf,offset + 8) = tick; // Set remaining status duration [exneval]
  5341. #if PACKETVER >= 20120618
  5342. WBUFL(buf,offset + 12) = tick;
  5343. offset += 4;
  5344. #endif
  5345. WBUFL(buf,offset + 12) = val1;
  5346. WBUFL(buf,offset + 16) = val2;
  5347. WBUFL(buf,offset + 20) = val3;
  5348. #endif
  5349. clif_send(buf,packet_len(cmd),bl,target);
  5350. #endif
  5351. }
  5352. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5353. /// 008e <packet len>.W <message>.?B
  5354. void clif_displaymessage(const int fd, const char* mes)
  5355. {
  5356. nullpo_retv(mes);
  5357. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  5358. if (fd == 0)
  5359. ;
  5360. else {
  5361. char *message, *line;
  5362. message = aStrdup(mes);
  5363. line = strtok(message, "\n");
  5364. #if PACKETVER == 20141022
  5365. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5366. /** so we redirect to ZC_NPC_CHAT **/
  5367. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5368. while(line != NULL) {
  5369. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5370. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5371. if (len > 0) {
  5372. WFIFOHEAD(fd, 13 + len);
  5373. WFIFOW(fd, 0) = 0x2C1;
  5374. WFIFOW(fd, 2) = 13 + len;
  5375. WFIFOL(fd, 4) = 0;
  5376. WFIFOL(fd, 8) = color;
  5377. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5378. WFIFOSET(fd, WFIFOW(fd, 2));
  5379. }
  5380. #else
  5381. while(line != NULL) {
  5382. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5383. int len = strnlen(line, CHAT_SIZE_MAX);
  5384. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5385. WFIFOHEAD(fd, 5 + len);
  5386. WFIFOW(fd,0) = 0x8e;
  5387. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5388. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5389. WFIFOSET(fd, 5 + len);
  5390. }
  5391. #endif
  5392. line = strtok(NULL, "\n");
  5393. }
  5394. aFree(message);
  5395. }
  5396. }
  5397. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5398. /// 009a <packet len>.W <message>.?B
  5399. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5400. {
  5401. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  5402. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  5403. WBUFW(buf,0) = 0x9a;
  5404. WBUFW(buf,2) = 4 + lp + len;
  5405. if (type&BC_BLUE)
  5406. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5407. else if (type&BC_WOE)
  5408. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5409. memcpy(WBUFP(buf, 4 + lp), mes, len);
  5410. clif_send(buf, WBUFW(buf,2), bl, target);
  5411. if (buf)
  5412. aFree(buf);
  5413. }
  5414. /*==========================================
  5415. * Displays a message on a 'bl' to all it's nearby clients
  5416. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5417. *------------------------------------------*/
  5418. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5419. char buf[8+CHAT_SIZE_MAX];
  5420. int len;
  5421. nullpo_retv(bl);
  5422. if(!message)
  5423. return;
  5424. len = strlen(message)+1;
  5425. if( len > sizeof(buf)-8 ) {
  5426. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  5427. len = sizeof(buf)-8;
  5428. }
  5429. WBUFW(buf,0)=0x8d;
  5430. WBUFW(buf,2)=len+8;
  5431. WBUFL(buf,4)=bl->id;
  5432. safestrncpy(WBUFCP(buf,8),message,len);
  5433. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,target);
  5434. }
  5435. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  5436. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  5437. void clif_broadcast2(struct block_list* bl, const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY, enum send_target target)
  5438. {
  5439. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  5440. WBUFW(buf,0) = 0x1c3;
  5441. WBUFW(buf,2) = len + 16;
  5442. WBUFL(buf,4) = fontColor;
  5443. WBUFW(buf,8) = fontType;
  5444. WBUFW(buf,10) = fontSize;
  5445. WBUFW(buf,12) = fontAlign;
  5446. WBUFW(buf,14) = fontY;
  5447. memcpy(WBUFP(buf,16), mes, len);
  5448. clif_send(buf, WBUFW(buf,2), bl, target);
  5449. if (buf)
  5450. aFree(buf);
  5451. }
  5452. /*
  5453. * Display *msg to all *users in channel
  5454. */
  5455. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5456. DBIterator *iter;
  5457. struct map_session_data *user;
  5458. unsigned short msg_len = 0, len = 0;
  5459. unsigned char buf[CHAT_SIZE_MAX];
  5460. if (!channel || !msg)
  5461. return;
  5462. msg_len = (unsigned short)(strlen(msg) + 1);
  5463. if( msg_len > sizeof(buf)-12 ) {
  5464. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5465. msg_len = sizeof(buf)-12;
  5466. }
  5467. WBUFW(buf,0) = 0x2C1;
  5468. WBUFW(buf,2) = (len = msg_len + 12);
  5469. WBUFL(buf,4) = 0;
  5470. WBUFL(buf,8) = color;
  5471. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5472. iter = db_iterator(channel->users);
  5473. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5474. clif_send(buf, len, &user->bl, SELF);
  5475. }
  5476. dbi_destroy(iter);
  5477. }
  5478. /// Displays heal effect.
  5479. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5480. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5481. /// var id:
  5482. /// 5 = HP (SP_HP)
  5483. /// 7 = SP (SP_SP)
  5484. /// ? = ignored
  5485. void clif_heal(int fd,int type,int val) {
  5486. #if PACKETVER < 20141022
  5487. const int cmd = 0x13d;
  5488. #else
  5489. const int cmd = 0xa27;
  5490. #endif
  5491. WFIFOHEAD(fd, packet_len(cmd));
  5492. WFIFOW(fd,0) = cmd;
  5493. WFIFOW(fd,2) = type;
  5494. #if PACKETVER < 20141022
  5495. WFIFOW(fd,4) = min(val, INT16_MAX);
  5496. #else
  5497. WFIFOL(fd,4) = min(val, INT32_MAX);
  5498. #endif
  5499. WFIFOSET(fd, packet_len(cmd));
  5500. }
  5501. /// Displays resurrection effect (ZC_RESURRECTION).
  5502. /// 0148 <id>.L <type>.W
  5503. /// type:
  5504. /// ignored
  5505. void clif_resurrection(struct block_list *bl,int type)
  5506. {
  5507. unsigned char buf[16];
  5508. nullpo_retv(bl);
  5509. WBUFW(buf,0)=0x148;
  5510. WBUFL(buf,2)=bl->id;
  5511. WBUFW(buf,6)=0;
  5512. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5513. if (disguised(bl))
  5514. clif_spawn(bl);
  5515. }
  5516. /// Sets the map property
  5517. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5518. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5519. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5520. {
  5521. #if PACKETVER >= 20121010
  5522. short cmd = 0x99b;
  5523. unsigned char buf[8];
  5524. #else
  5525. short cmd = 0x199;
  5526. unsigned char buf[4];
  5527. #endif
  5528. WBUFW(buf,0)=cmd;
  5529. WBUFW(buf,2)=property;
  5530. #if PACKETVER >= 20121010
  5531. WBUFL(buf,4) = ((map[bl->m].flag.pvp?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5532. ((map[bl->m].flag.battleground || map_flag_gvg2(bl->m)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5533. ((map[bl->m].flag.battleground || map_flag_gvg2(bl->m)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5534. ((map[bl->m].flag.nomineeffect || !map_flag_gvg2(bl->m)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5535. ((map[bl->m].flag.nolockon || map_flag_vs(bl->m)?1:0)<<4)| // DISABLE_LOCKON - Only allow attacks on other players with shift key or /ns active
  5536. ((map[bl->m].flag.pvp?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5537. ((map[bl->m].flag.partylock?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5538. ((map[bl->m].flag.battleground?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5539. ((map[bl->m].flag.nocostume?1:0)<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5540. ((map[bl->m].flag.nousecart?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5541. ((map[bl->m].flag.nosumstarmiracle?0:1)<<10); // SUNMOONSTAR_MIRACLE - Unknown - (Guessing it blocks Star Gladiator's Miracle from activating)
  5542. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5543. #endif
  5544. clif_send(buf,packet_len(cmd),bl,t);
  5545. }
  5546. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5547. /// 01d6 <type>.W
  5548. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5549. {
  5550. int fd;
  5551. nullpo_retv(sd);
  5552. fd=sd->fd;
  5553. WFIFOHEAD(fd,packet_len(0x1D6));
  5554. WFIFOW(fd,0)=0x1D6;
  5555. WFIFOW(fd,2)=type;
  5556. WFIFOSET(fd,packet_len(0x1D6));
  5557. }
  5558. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5559. /// 019a <id>.L <ranking>.L <total>.L
  5560. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5561. {
  5562. if(type == 2) {
  5563. int fd = sd->fd;
  5564. WFIFOHEAD(fd,packet_len(0x19a));
  5565. WFIFOW(fd,0) = 0x19a;
  5566. WFIFOL(fd,2) = sd->bl.id;
  5567. WFIFOL(fd,6) = pvprank;
  5568. WFIFOL(fd,10) = pvpnum;
  5569. WFIFOSET(fd,packet_len(0x19a));
  5570. } else {
  5571. unsigned char buf[32];
  5572. WBUFW(buf,0) = 0x19a;
  5573. WBUFL(buf,2) = sd->bl.id;
  5574. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5575. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5576. else
  5577. WBUFL(buf,6) = pvprank;
  5578. WBUFL(buf,10) = pvpnum;
  5579. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5580. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5581. else if(!type)
  5582. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5583. else
  5584. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5585. }
  5586. }
  5587. /*==========================================
  5588. *
  5589. *------------------------------------------*/
  5590. void clif_map_property_mapall(int map_idx, enum map_property property)
  5591. {
  5592. struct block_list bl;
  5593. bl.id = 0;
  5594. bl.type = BL_NUL;
  5595. bl.m = map_idx;
  5596. clif_map_property( &bl, property, ALL_SAMEMAP );
  5597. }
  5598. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5599. /// 0188 <result>.W <index>.W <refine>.W
  5600. /// result:
  5601. /// 0 = success
  5602. /// 1 = failure
  5603. /// 2 = downgrade
  5604. void clif_refine(int fd, int fail, int index, int val)
  5605. {
  5606. WFIFOHEAD(fd,packet_len(0x188));
  5607. WFIFOW(fd,0)=0x188;
  5608. WFIFOW(fd,2)=fail;
  5609. WFIFOW(fd,4)=index+2;
  5610. WFIFOW(fd,6)=val;
  5611. WFIFOSET(fd,packet_len(0x188));
  5612. }
  5613. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5614. /// 0223 <result>.L <nameid>.W
  5615. /// result:
  5616. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5617. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5618. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5619. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5620. void clif_upgrademessage(int fd, int result, unsigned short item_id)
  5621. {
  5622. WFIFOHEAD(fd,packet_len(0x223));
  5623. WFIFOW(fd,0)=0x223;
  5624. WFIFOL(fd,2)=result;
  5625. WFIFOW(fd,6)=item_id;
  5626. WFIFOSET(fd,packet_len(0x223));
  5627. }
  5628. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5629. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5630. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5631. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  5632. {
  5633. #if PACKETVER < 20091104
  5634. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5635. WFIFOW(fd,0) = 0x97;
  5636. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5637. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5638. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5639. WFIFOSET(fd,WFIFOW(fd,2));
  5640. #else
  5641. struct map_session_data *ssd = map_nick2sd(nick,false);
  5642. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5643. WFIFOW(fd,0) = 0x97;
  5644. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5645. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5646. WFIFOL(fd,28) = (ssd && pc_get_group_level(ssd) == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5647. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5648. WFIFOSET(fd,WFIFOW(fd,2));
  5649. #endif
  5650. }
  5651. /// Inform the player about the result of his whisper action
  5652. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5653. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5654. /// result:
  5655. /// 0 = success to send wisper
  5656. /// 1 = target character is not loged in
  5657. /// 2 = ignored by target
  5658. /// 3 = everyone ignored by target
  5659. void clif_wis_end(int fd, int result)
  5660. {
  5661. struct map_session_data *sd = (session_isValid(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5662. #if PACKETVER < 20131223
  5663. const int cmd = 0x98;
  5664. #else
  5665. const int cmd = 0x9df;
  5666. #endif
  5667. if (!sd)
  5668. return;
  5669. WFIFOHEAD(fd,packet_len(cmd));
  5670. WFIFOW(fd,0) = cmd;
  5671. WFIFOB(fd,2) = (char)result;
  5672. #if PACKETVER >= 20131223
  5673. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5674. #endif
  5675. WFIFOSET(fd,packet_len(cmd));
  5676. }
  5677. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5678. /// 0194 <char id>.L <name>.24B
  5679. void clif_solved_charname(int fd, int charid, const char* name)
  5680. {
  5681. WFIFOHEAD(fd,packet_len(0x194));
  5682. WFIFOW(fd,0)=0x194;
  5683. WFIFOL(fd,2)=charid;
  5684. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5685. WFIFOSET(fd,packet_len(0x194));
  5686. }
  5687. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5688. /// 017b <packet len>.W { <name id>.W }*
  5689. void clif_use_card(struct map_session_data *sd,int idx)
  5690. {
  5691. int i,c,ep;
  5692. int fd=sd->fd;
  5693. nullpo_retv(sd);
  5694. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5695. return;
  5696. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5697. return; //Avoid parsing invalid item indexes (no card/no item)
  5698. ep=sd->inventory_data[idx]->equip;
  5699. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5700. WFIFOW(fd,0)=0x17b;
  5701. for(i=c=0;i<MAX_INVENTORY;i++){
  5702. int j;
  5703. if(sd->inventory_data[i] == NULL)
  5704. continue;
  5705. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5706. continue;
  5707. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  5708. continue;
  5709. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  5710. continue;
  5711. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5712. continue;
  5713. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5714. continue;
  5715. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  5716. if( j == sd->inventory_data[i]->slot ) // No room
  5717. continue;
  5718. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  5719. continue;
  5720. WFIFOW(fd,4+c*2)=i+2;
  5721. c++;
  5722. }
  5723. if( !c ) return; // no item is available for card insertion
  5724. WFIFOW(fd,2)=4+c*2;
  5725. WFIFOSET(fd,WFIFOW(fd,2));
  5726. }
  5727. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5728. /// 017d <equip index>.W <card index>.W <result>.B
  5729. /// result:
  5730. /// 0 = success
  5731. /// 1 = failure
  5732. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5733. {
  5734. int fd;
  5735. nullpo_retv(sd);
  5736. fd=sd->fd;
  5737. WFIFOHEAD(fd,packet_len(0x17d));
  5738. WFIFOW(fd,0)=0x17d;
  5739. WFIFOW(fd,2)=idx_equip+2;
  5740. WFIFOW(fd,4)=idx_card+2;
  5741. WFIFOB(fd,6)=flag;
  5742. WFIFOSET(fd,packet_len(0x17d));
  5743. }
  5744. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5745. /// 0177 <packet len>.W { <name id>.W }*
  5746. void clif_item_identify_list(struct map_session_data *sd)
  5747. {
  5748. int i,c;
  5749. int fd;
  5750. nullpo_retv(sd);
  5751. fd=sd->fd;
  5752. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5753. WFIFOW(fd,0)=0x177;
  5754. for(i=c=0;i<MAX_INVENTORY;i++){
  5755. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  5756. WFIFOW(fd,c*2+4)=i+2;
  5757. c++;
  5758. }
  5759. }
  5760. if(c > 0) {
  5761. WFIFOW(fd,2)=c*2+4;
  5762. WFIFOSET(fd,WFIFOW(fd,2));
  5763. sd->menuskill_id = MC_IDENTIFY;
  5764. sd->menuskill_val = c;
  5765. sd->state.workinprogress = WIP_DISABLE_ALL;
  5766. }
  5767. }
  5768. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5769. /// 0179 <index>.W <result>.B
  5770. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5771. {
  5772. int fd;
  5773. nullpo_retv(sd);
  5774. fd=sd->fd;
  5775. WFIFOHEAD(fd,packet_len(0x179));
  5776. WFIFOW(fd, 0)=0x179;
  5777. WFIFOW(fd, 2)=idx+2;
  5778. WFIFOB(fd, 4)=flag;
  5779. WFIFOSET(fd,packet_len(0x179));
  5780. }
  5781. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5782. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5783. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5784. {
  5785. int i,c;
  5786. int fd;
  5787. nullpo_retv(sd);
  5788. nullpo_retv(dstsd);
  5789. fd=sd->fd;
  5790. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5791. WFIFOW(fd,0)=0x1fc;
  5792. for(i=c=0;i<MAX_INVENTORY;i++){
  5793. unsigned short nameid;
  5794. if((nameid=dstsd->inventory.u.items_inventory[i].nameid) > 0 && dstsd->inventory.u.items_inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5795. WFIFOW(fd,c*13+4) = i;
  5796. WFIFOW(fd,c*13+6) = nameid;
  5797. WFIFOB(fd,c*13+8) = dstsd->inventory.u.items_inventory[i].refine;
  5798. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->inventory.u.items_inventory[i]);
  5799. c++;
  5800. }
  5801. }
  5802. if(c > 0) {
  5803. WFIFOW(fd,2)=c*13+4;
  5804. WFIFOSET(fd,WFIFOW(fd,2));
  5805. sd->menuskill_id = BS_REPAIRWEAPON;
  5806. sd->menuskill_val = dstsd->bl.id;
  5807. sd->menuskill_val2 = lv;
  5808. }else
  5809. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5810. }
  5811. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5812. /// 01fe <index>.W <result>.B
  5813. /// index:
  5814. /// ignored (inventory index)
  5815. /// result:
  5816. /// 0 = Item repair success.
  5817. /// 1 = Item repair failure.
  5818. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5819. {
  5820. int fd;
  5821. nullpo_retv(sd);
  5822. fd = sd->fd;
  5823. WFIFOHEAD(fd,packet_len(0x1fe));
  5824. WFIFOW(fd, 0)=0x1fe;
  5825. WFIFOW(fd, 2)=idx+2;
  5826. WFIFOB(fd, 4)=flag;
  5827. WFIFOSET(fd,packet_len(0x1fe));
  5828. }
  5829. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5830. /// 02bb <equip location>.W <account id>.L
  5831. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5832. {
  5833. int fd = sd->fd;
  5834. WFIFOHEAD(fd,packet_len(0x2bb));
  5835. WFIFOW(fd,0) = 0x2bb;
  5836. WFIFOW(fd,2) = position;
  5837. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5838. WFIFOSET(fd,packet_len(0x2bb));
  5839. }
  5840. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5841. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5842. void clif_item_refine_list(struct map_session_data *sd)
  5843. {
  5844. int i,c;
  5845. int fd;
  5846. uint16 skill_lv;
  5847. int refine_item[5];
  5848. nullpo_retv(sd);
  5849. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5850. fd=sd->fd;
  5851. refine_item[0] = -1;
  5852. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5853. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5854. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5855. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5856. WFIFOW(fd,0) = 0x221;
  5857. for(i = c = 0; i < MAX_INVENTORY; i++) {
  5858. unsigned char wlv;
  5859. if(sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  5860. sd->inventory.u.items_inventory[i].identify && (wlv = itemdb_wlv(sd->inventory.u.items_inventory[i].nameid)) >=1 &&
  5861. refine_item[wlv] != -1 && !(sd->inventory.u.items_inventory[i].equip&EQP_ARMS)){
  5862. WFIFOW(fd,c*13+ 4)=i+2;
  5863. WFIFOW(fd,c*13+ 6) = sd->inventory.u.items_inventory[i].nameid;
  5864. WFIFOB(fd,c*13+ 8) = sd->inventory.u.items_inventory[i].refine;
  5865. clif_addcards(WFIFOP(fd,c*13+9), &sd->inventory.u.items_inventory[i]);
  5866. c++;
  5867. }
  5868. }
  5869. WFIFOW(fd,2)=c*13+4;
  5870. WFIFOSET(fd,WFIFOW(fd,2));
  5871. if (c > 0) {
  5872. sd->menuskill_id = WS_WEAPONREFINE;
  5873. sd->menuskill_val = skill_lv;
  5874. }
  5875. }
  5876. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5877. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5878. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5879. {
  5880. int fd;
  5881. nullpo_retv(sd);
  5882. fd=sd->fd;
  5883. WFIFOHEAD(fd,packet_len(0x147));
  5884. WFIFOW(fd, 0)=0x147;
  5885. WFIFOW(fd, 2)=skill_id;
  5886. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5887. WFIFOW(fd, 6)=0;
  5888. WFIFOW(fd, 8)=skill_lv;
  5889. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5890. WFIFOW(fd,12)=skill_get_range2(&sd->bl,skill_id,skill_lv,false);
  5891. safestrncpy(WFIFOCP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5892. WFIFOB(fd,38)=0;
  5893. WFIFOSET(fd,packet_len(0x147));
  5894. }
  5895. /// Adds an item to character's cart.
  5896. /// 0124 <index>.W <amount>.L <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_CART)
  5897. /// 01c5 <index>.W <amount>.L <name id>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_CART2)
  5898. /// 0a0b <index>.W <amount>.L <name id>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_ITEM_TO_CART3)
  5899. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5900. {
  5901. #if PACKETVER < 5
  5902. const int cmd = 0x124;
  5903. #elif PACKETVER < 20150225
  5904. const int cmd = 0x1c5;
  5905. #else
  5906. const int cmd = 0xa0b;
  5907. #endif
  5908. int view,fd;
  5909. unsigned char *buf;
  5910. int offset = 0;
  5911. nullpo_retv(sd);
  5912. fd=sd->fd;
  5913. if(n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid <= 0)
  5914. return;
  5915. WFIFOHEAD(fd,packet_len(cmd));
  5916. buf=WFIFOP(fd,0);
  5917. WBUFW(buf,0)=cmd;
  5918. WBUFW(buf,2)=n+2;
  5919. WBUFL(buf,4)=amount;
  5920. if((view = itemdb_viewid(sd->cart.u.items_cart[n].nameid)) > 0)
  5921. WBUFW(buf,8)=view;
  5922. else
  5923. WBUFW(buf,8)=sd->cart.u.items_cart[n].nameid;
  5924. #if PACKETVER >= 5
  5925. WBUFB(buf,10)=itemdb_type(sd->cart.u.items_cart[n].nameid);
  5926. offset += 1;
  5927. #endif
  5928. WBUFB(buf,10+offset)=sd->cart.u.items_cart[n].identify;
  5929. WBUFB(buf,11+offset)=sd->cart.u.items_cart[n].attribute;
  5930. WBUFB(buf,12+offset)=sd->cart.u.items_cart[n].refine;
  5931. clif_addcards(WBUFP(buf,13+offset), &sd->cart.u.items_cart[n]);
  5932. #if PACKETVER >= 20150225
  5933. clif_add_random_options(WBUFP(buf,21+offset), &sd->cart.u.items_cart[n]);
  5934. #endif
  5935. WFIFOSET(fd,packet_len(cmd));
  5936. }
  5937. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5938. /* Acknowledge an item have been added to cart
  5939. * 012c <result>B
  5940. * result :
  5941. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5942. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5943. */
  5944. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5945. {
  5946. int fd;
  5947. unsigned char *buf;
  5948. nullpo_retv(sd);
  5949. fd = sd->fd;
  5950. buf = WFIFOP(fd,0);
  5951. WBUFW(buf,0) = 0x12c;
  5952. WBUFB(buf,2) = flag;
  5953. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  5954. }
  5955. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  5956. void clif_bank_open(struct map_session_data *sd){
  5957. int fd;
  5958. nullpo_retv(sd);
  5959. fd = sd->fd;
  5960. WFIFOHEAD(fd,4);
  5961. WFIFOW(fd,0) = 0x09b7;
  5962. WFIFOW(fd,2) = 0;
  5963. WFIFOSET(fd,4);
  5964. }
  5965. /*
  5966. * Request to Open the banking system
  5967. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  5968. */
  5969. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  5970. //TODO check if preventing trade or stuff like that
  5971. //also mark something in case char ain't available for saving, should we check now ?
  5972. nullpo_retv(sd);
  5973. if( !battle_config.feature_banking ) {
  5974. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  5975. return;
  5976. }
  5977. else {
  5978. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  5979. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  5980. if(sd->status.account_id == aid){
  5981. sd->state.banking = 1;
  5982. //request save ?
  5983. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  5984. //on succes open bank ?
  5985. clif_bank_open(sd);
  5986. }
  5987. }
  5988. }
  5989. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  5990. void clif_bank_close(struct map_session_data *sd){
  5991. int fd;
  5992. nullpo_retv(sd);
  5993. fd = sd->fd;
  5994. WFIFOHEAD(fd,4);
  5995. WFIFOW(fd,0) = 0x09B9;
  5996. WFIFOW(fd,2) = 0;
  5997. WFIFOSET(fd,4);
  5998. }
  5999. /*
  6000. * Request to close the banking system
  6001. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6002. */
  6003. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6004. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6005. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6006. nullpo_retv(sd);
  6007. if( !battle_config.feature_banking ) {
  6008. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6009. //still allow to go trough to not stuck player if we have disable it while they was in
  6010. }
  6011. if(sd->status.account_id == aid){
  6012. sd->state.banking = 0;
  6013. clif_bank_close(sd);
  6014. }
  6015. }
  6016. /*
  6017. * Display how much we got in bank (I suppose)
  6018. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  6019. */
  6020. void clif_Bank_Check(struct map_session_data* sd) {
  6021. unsigned char buf[13];
  6022. struct s_packet_db* info;
  6023. int16 len;
  6024. int cmd = 0;
  6025. nullpo_retv(sd);
  6026. cmd = packet_db_ack[ZC_BANKING_CHECK];
  6027. if(!cmd) cmd = 0x09A6; //default
  6028. info = &packet_db[cmd];
  6029. len = info->len;
  6030. if(!len) return; //version as packet disable
  6031. // sd->state.banking = 1; //mark opening and closing
  6032. WBUFW(buf,0) = cmd;
  6033. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  6034. WBUFW(buf,info->pos[1]) = 0; //reason
  6035. clif_send(buf,len,&sd->bl,SELF);
  6036. }
  6037. /*
  6038. * Requesting the data in bank
  6039. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6040. */
  6041. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6042. nullpo_retv(sd);
  6043. if( !battle_config.feature_banking ) {
  6044. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6045. return;
  6046. }
  6047. else {
  6048. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6049. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6050. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6051. clif_Bank_Check(sd);
  6052. }
  6053. }
  6054. /*
  6055. * Acknowledge of deposit some money in bank
  6056. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6057. */
  6058. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  6059. unsigned char buf[17];
  6060. struct s_packet_db* info;
  6061. int16 len;
  6062. int cmd =0;
  6063. nullpo_retv(sd);
  6064. cmd = packet_db_ack[ZC_ACK_BANKING_DEPOSIT];
  6065. if(!cmd) cmd = 0x09A8;
  6066. info = &packet_db[cmd];
  6067. len = info->len;
  6068. if(!len) return; //version as packet disable
  6069. WBUFW(buf,0) = cmd;
  6070. WBUFW(buf,info->pos[0]) = (short)reason;
  6071. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6072. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6073. clif_send(buf,len,&sd->bl,SELF);
  6074. }
  6075. /*
  6076. * Request saving some money in bank
  6077. * @author : original [Yommy/Hercules]
  6078. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6079. */
  6080. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6081. nullpo_retv(sd);
  6082. if( !battle_config.feature_banking ) {
  6083. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6084. return;
  6085. }
  6086. else {
  6087. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6088. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6089. int money = RFIFOL(fd,info->pos[1]);
  6090. if(sd->status.account_id == aid){
  6091. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6092. clif_bank_deposit(sd,reason);
  6093. }
  6094. }
  6095. }
  6096. /*
  6097. * Acknowledge of withdrawing some money from bank
  6098. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6099. */
  6100. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6101. unsigned char buf[17];
  6102. struct s_packet_db* info;
  6103. int16 len;
  6104. int cmd;
  6105. nullpo_retv(sd);
  6106. cmd = packet_db_ack[ZC_ACK_BANKING_WITHDRAW];
  6107. if(!cmd) cmd = 0x09AA;
  6108. info = &packet_db[cmd];
  6109. len = info->len;
  6110. if(!len) return; //version as packet disable
  6111. WBUFW(buf,0) = cmd;
  6112. WBUFW(buf,info->pos[0]) = (short)reason;
  6113. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6114. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6115. clif_send(buf,len,&sd->bl,SELF);
  6116. }
  6117. /*
  6118. * Request Withdrawing some money from bank
  6119. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6120. */
  6121. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6122. nullpo_retv(sd);
  6123. if( !battle_config.feature_banking ) {
  6124. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6125. return;
  6126. }
  6127. else {
  6128. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6129. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6130. int money = RFIFOL(fd,info->pos[1]);
  6131. if(sd->status.account_id == aid){
  6132. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6133. clif_bank_withdraw(sd,reason);
  6134. }
  6135. }
  6136. }
  6137. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6138. /// 0125 <index>.W <amount>.L
  6139. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6140. {
  6141. int fd;
  6142. nullpo_retv(sd);
  6143. fd=sd->fd;
  6144. WFIFOHEAD(fd,packet_len(0x125));
  6145. WFIFOW(fd,0)=0x125;
  6146. WFIFOW(fd,2)=n+2;
  6147. WFIFOL(fd,4)=amount;
  6148. WFIFOSET(fd,packet_len(0x125));
  6149. }
  6150. /// Opens the shop creation menu (ZC_OPENSTORE).
  6151. /// 012d <num>.W
  6152. /// num:
  6153. /// number of allowed item slots
  6154. void clif_openvendingreq(struct map_session_data* sd, int num)
  6155. {
  6156. int fd;
  6157. nullpo_retv(sd);
  6158. fd = sd->fd;
  6159. WFIFOHEAD(fd,packet_len(0x12d));
  6160. WFIFOW(fd,0) = 0x12d;
  6161. WFIFOW(fd,2) = num;
  6162. WFIFOSET(fd,packet_len(0x12d));
  6163. }
  6164. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6165. /// 0131 <owner id>.L <message>.80B
  6166. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6167. {
  6168. unsigned char buf[128];
  6169. nullpo_retv(bl);
  6170. WBUFW(buf,0) = 0x131;
  6171. WBUFL(buf,2) = bl->id;
  6172. safestrncpy(WBUFCP(buf,6), message, 80);
  6173. if( fd ) {
  6174. WFIFOHEAD(fd,packet_len(0x131));
  6175. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6176. WFIFOSET(fd,packet_len(0x131));
  6177. } else {
  6178. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6179. }
  6180. }
  6181. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6182. /// 0132 <owner id>.L
  6183. void clif_closevendingboard(struct block_list* bl, int fd)
  6184. {
  6185. unsigned char buf[16];
  6186. nullpo_retv(bl);
  6187. WBUFW(buf,0) = 0x132;
  6188. WBUFL(buf,2) = bl->id;
  6189. if( fd ) {
  6190. WFIFOHEAD(fd,packet_len(0x132));
  6191. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6192. WFIFOSET(fd,packet_len(0x132));
  6193. } else {
  6194. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6195. }
  6196. }
  6197. /// Sends a list of items in a shop.
  6198. /// R 0133 <packet len>.W <owner id>.L { <price>.L <amount>.W <index>.W <type>.B <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_PC_PURCHASE_ITEMLIST_FROMMC)
  6199. /// R 0800 <packet len>.W <owner id>.L <unique id>.L { <price>.L <amount>.W <index>.W <type>.B <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }* (ZC_PC_PURCHASE_ITEMLIST_FROMMC2)
  6200. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  6201. {
  6202. int i,fd;
  6203. int count;
  6204. struct map_session_data* vsd;
  6205. #if PACKETVER < 20100105
  6206. const int cmd = 0x133;
  6207. const int offset = 8;
  6208. #else
  6209. const int cmd = 0x800;
  6210. const int offset = 12;
  6211. #endif
  6212. #if PACKETVER < 20150225
  6213. const int item_length = 22;
  6214. #elif PACKETVER < 20160921
  6215. const int item_length = 47;
  6216. #else
  6217. const int item_length = 53;
  6218. #endif
  6219. nullpo_retv(sd);
  6220. nullpo_retv(vending);
  6221. nullpo_retv(vsd=map_id2sd(id));
  6222. fd = sd->fd;
  6223. count = vsd->vend_num;
  6224. WFIFOHEAD(fd, offset+count*item_length);
  6225. WFIFOW(fd,0) = cmd;
  6226. WFIFOW(fd,2) = offset+count*item_length;
  6227. WFIFOL(fd,4) = id;
  6228. #if PACKETVER >= 20100105
  6229. WFIFOL(fd,8) = vsd->vender_id;
  6230. #endif
  6231. for( i = 0; i < count; i++ )
  6232. {
  6233. int index = vending[i].index;
  6234. struct item_data* data = itemdb_search(vsd->cart.u.items_cart[index].nameid);
  6235. WFIFOL(fd,offset+ 0+i*item_length) = vending[i].value;
  6236. WFIFOW(fd,offset+ 4+i*item_length) = vending[i].amount;
  6237. WFIFOW(fd,offset+ 6+i*item_length) = vending[i].index + 2;
  6238. WFIFOB(fd,offset+ 8+i*item_length) = itemtype(data->nameid);
  6239. WFIFOW(fd,offset+ 9+i*item_length) = ( data->view_id > 0 ) ? data->view_id : vsd->cart.u.items_cart[index].nameid;
  6240. WFIFOB(fd,offset+11+i*item_length) = vsd->cart.u.items_cart[index].identify;
  6241. WFIFOB(fd,offset+12+i*item_length) = vsd->cart.u.items_cart[index].attribute;
  6242. WFIFOB(fd,offset+13+i*item_length) = vsd->cart.u.items_cart[index].refine;
  6243. clif_addcards(WFIFOP(fd,offset+14+i*item_length), &vsd->cart.u.items_cart[index]);
  6244. #if PACKETVER >= 20150225
  6245. clif_add_random_options(WFIFOP(fd,offset+22+i*item_length), &vsd->cart.u.items_cart[index]);
  6246. #if PACKETVER >= 20160921
  6247. WFIFOL(fd,offset+47+i*item_length) = pc_equippoint_sub(sd,data);
  6248. WFIFOW(fd,offset+51+i*item_length) = data->look;
  6249. #endif
  6250. #endif
  6251. }
  6252. WFIFOSET(fd,WFIFOW(fd,2));
  6253. }
  6254. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6255. /// 0135 <index>.W <amount>.W <result>.B
  6256. /// result:
  6257. /// 0 = success
  6258. /// 1 = not enough zeny
  6259. /// 2 = overweight
  6260. /// 4 = out of stock
  6261. /// 5 = "cannot use an npc shop while in a trade"
  6262. /// 6 = Because the store information was incorrect the item was not purchased.
  6263. /// 7 = No sales information.
  6264. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6265. {
  6266. int fd;
  6267. nullpo_retv(sd);
  6268. fd = sd->fd;
  6269. WFIFOHEAD(fd,packet_len(0x135));
  6270. WFIFOW(fd,0) = 0x135;
  6271. WFIFOW(fd,2) = index+2;
  6272. WFIFOW(fd,4) = amount;
  6273. WFIFOB(fd,6) = fail;
  6274. WFIFOSET(fd,packet_len(0x135));
  6275. }
  6276. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6277. /// 0a28 <Result>.B
  6278. /// result:
  6279. /// 0 = Successed
  6280. /// 1 = Failed
  6281. void clif_openvending_ack(struct map_session_data* sd, int result)
  6282. {
  6283. int fd;
  6284. nullpo_retv(sd);
  6285. fd = sd->fd;
  6286. WFIFOHEAD(fd, 3);
  6287. WFIFOW(fd,0) = 0xa28;
  6288. WFIFOB(fd,2) = result;
  6289. WFIFOSET(fd, 3);
  6290. }
  6291. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  6292. /// 0136 <packet len>.W <owner id>.L { <price>.L <index>.W <amount>.W <type>.B <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  6293. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  6294. {
  6295. int i,fd;
  6296. int count;
  6297. #if PACKETVER < 20150225
  6298. const int item_length = 22;
  6299. #else
  6300. const int item_length = 47;
  6301. #endif
  6302. nullpo_retv(sd);
  6303. fd = sd->fd;
  6304. count = sd->vend_num;
  6305. WFIFOHEAD(fd, 8+count*item_length);
  6306. WFIFOW(fd,0) = 0x136;
  6307. WFIFOW(fd,2) = 8+count*item_length;
  6308. WFIFOL(fd,4) = id;
  6309. for( i = 0; i < count; i++ ) {
  6310. int index = vending[i].index;
  6311. struct item_data* data = itemdb_search(sd->cart.u.items_cart[index].nameid);
  6312. WFIFOL(fd, 8+i*item_length) = vending[i].value;
  6313. WFIFOW(fd,12+i*item_length) = vending[i].index + 2;
  6314. WFIFOW(fd,14+i*item_length) = vending[i].amount;
  6315. WFIFOB(fd,16+i*item_length) = itemtype(data->nameid);
  6316. WFIFOW(fd,17+i*item_length) = ( data->view_id > 0 ) ? data->view_id : sd->cart.u.items_cart[index].nameid;
  6317. WFIFOB(fd,19+i*item_length) = sd->cart.u.items_cart[index].identify;
  6318. WFIFOB(fd,20+i*item_length) = sd->cart.u.items_cart[index].attribute;
  6319. WFIFOB(fd,21+i*item_length) = sd->cart.u.items_cart[index].refine;
  6320. clif_addcards(WFIFOP(fd,22+i*item_length), &sd->cart.u.items_cart[index]);
  6321. #if PACKETVER >= 20150225
  6322. clif_add_random_options(WFIFOP(fd,30+i*item_length), &sd->cart.u.items_cart[index]);
  6323. #endif
  6324. }
  6325. WFIFOSET(fd,WFIFOW(fd,2));
  6326. #if PACKETVER >= 20141022
  6327. /// 0 = Successed
  6328. /// 1 = Failed
  6329. clif_openvending_ack(sd, 0);
  6330. #endif
  6331. }
  6332. /// Inform merchant that someone has bought an item.
  6333. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6334. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6335. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6336. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6337. const int cmd = 0x137;
  6338. #else
  6339. const int cmd = 0x9e5;
  6340. #endif
  6341. int fd = sd->fd;
  6342. nullpo_retv(sd);
  6343. WFIFOHEAD(fd,packet_len(cmd));
  6344. WFIFOW(fd,0) = cmd;
  6345. WFIFOW(fd,2) = index+2;
  6346. WFIFOW(fd,4) = amount;
  6347. #if PACKETVER >= 20141016
  6348. WFIFOL(fd,6) = char_id; // GID
  6349. WFIFOL(fd,10) = (int)time(NULL); // Date
  6350. WFIFOL(fd,14) = zeny; // zeny
  6351. #endif
  6352. WFIFOSET(fd,packet_len(cmd));
  6353. }
  6354. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6355. /// 00fa <result>.B
  6356. /// result:
  6357. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6358. /// 1 = MsgStringTable[78]="party name already exists"
  6359. /// 2 = MsgStringTable[79]="already in a party"
  6360. /// 3 = cannot organize parties on this map
  6361. /// ? = nothing
  6362. void clif_party_created(struct map_session_data *sd,int result)
  6363. {
  6364. int fd;
  6365. nullpo_retv(sd);
  6366. fd=sd->fd;
  6367. WFIFOHEAD(fd,packet_len(0xfa));
  6368. WFIFOW(fd,0)=0xfa;
  6369. WFIFOB(fd,2)=result;
  6370. WFIFOSET(fd,packet_len(0xfa));
  6371. }
  6372. /// Adds new member to a party.
  6373. /// 0104 <account id>.L <role>.L <x>.W <y>.W <state>.B <party name>.24B <char name>.24B <map name>.16B (ZC_ADD_MEMBER_TO_GROUP)
  6374. /// 01e9 <account id>.L <role>.L <x>.W <y>.W <state>.B <party name>.24B <char name>.24B <map name>.16B <item pickup rule>.B <item share rule>.B (ZC_ADD_MEMBER_TO_GROUP2)
  6375. /// 0a43 <account id>.L <role>.L <class>.W <base level>.W <x>.W <y>.W <state>.B <party name>.24B <char name>.24B <map name>.16B <item pickup rule>.B <item share rule>.B (ZC_ADD_MEMBER_TO_GROUP3)
  6376. /// role:
  6377. /// 0 = leader
  6378. /// 1 = normal
  6379. /// state:
  6380. /// 0 = connected
  6381. /// 1 = disconnected
  6382. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6383. {
  6384. int i;
  6385. #if PACKETVER < 20170502
  6386. unsigned char buf[81];
  6387. int cmd = 0x1e9;
  6388. int offset = 0;
  6389. #else
  6390. unsigned char buf[85];
  6391. int cmd = 0xa43;
  6392. int offset = 4;
  6393. #endif
  6394. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6395. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6396. } else {
  6397. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6398. }
  6399. if (i >= MAX_PARTY) return; //Should never happen...
  6400. sd = p->data[i].sd;
  6401. WBUFW(buf, 0) = cmd;
  6402. WBUFL(buf, 2) = sd->status.account_id;
  6403. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6404. #if PACKETVER >= 20170502
  6405. WBUFW(buf,10) = sd->status.class_;
  6406. WBUFW(buf,12) = sd->status.base_level;
  6407. #endif
  6408. WBUFW(buf,offset+10) = sd->bl.x;
  6409. WBUFW(buf,offset+12) = sd->bl.y;
  6410. WBUFB(buf,offset+14) = (p->party.member[i].online)?0:1;
  6411. safestrncpy(WBUFCP(buf,offset+15), p->party.name, NAME_LENGTH);
  6412. safestrncpy(WBUFCP(buf,offset+39), sd->status.name, NAME_LENGTH);
  6413. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), WBUFCP(buf,offset+63));
  6414. WBUFB(buf,offset+79) = (p->party.item&1)?1:0;
  6415. WBUFB(buf,offset+80) = (p->party.item&2)?1:0;
  6416. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6417. }
  6418. /// Sends party information (ZC_GROUP_LIST).
  6419. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6420. /// role:
  6421. /// 0 = leader
  6422. /// 1 = normal
  6423. /// state:
  6424. /// 0 = connected
  6425. /// 1 = disconnected
  6426. /// 0a44 <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B <class>.W <base level>.W }* <item pickup rule>.B <item share rule>.B <unknown>.L
  6427. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6428. {
  6429. struct map_session_data* party_sd = NULL;
  6430. int i, c;
  6431. #if PACKETVER < 20170502
  6432. const int M_SIZE = 46; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1
  6433. unsigned char buf[2+2+NAME_LENGTH+46*MAX_PARTY];
  6434. int cmd = 0xfb;
  6435. #else
  6436. const int M_SIZE = 50; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1+4
  6437. unsigned char buf[2+2+NAME_LENGTH+50*MAX_PARTY+6];
  6438. int cmd = 0xa44;
  6439. #endif
  6440. const int PRE_SIZE = 28; // cmd, actual cmd_size, party_name
  6441. nullpo_retv(p);
  6442. WBUFW(buf,0) = cmd;
  6443. safestrncpy(WBUFCP(buf,4), p->party.name, NAME_LENGTH);
  6444. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6445. {
  6446. struct party_member* m = &p->party.member[i];
  6447. if(!m->account_id) continue;
  6448. if(party_sd == NULL) party_sd = p->data[i].sd;
  6449. WBUFL(buf,PRE_SIZE+c*M_SIZE) = m->account_id;
  6450. safestrncpy(WBUFCP(buf,PRE_SIZE+c*M_SIZE+4), m->name, NAME_LENGTH);
  6451. mapindex_getmapname_ext(mapindex_id2name(m->map), WBUFCP(buf,PRE_SIZE+c*M_SIZE+PRE_SIZE));
  6452. WBUFB(buf,PRE_SIZE+c*M_SIZE+44) = (m->leader) ? 0 : 1;
  6453. WBUFB(buf,PRE_SIZE+c*M_SIZE+45) = (m->online) ? 0 : 1;
  6454. #if PACKETVER >= 20170502
  6455. WBUFW(buf,PRE_SIZE+c*M_SIZE+46) = m->class_;
  6456. WBUFW(buf,PRE_SIZE+c*M_SIZE+48) = m->lv;
  6457. #endif
  6458. c++;
  6459. }
  6460. #if PACKETVER < 20170502
  6461. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE;
  6462. #else
  6463. WBUFB(buf,PRE_SIZE+c*M_SIZE) = (p->party.item & 1) ? 1 : 0;
  6464. WBUFB(buf,PRE_SIZE+c*M_SIZE+1) = (p->party.item & 2) ? 1 : 0;
  6465. WBUFL(buf,PRE_SIZE+c*M_SIZE+2) = 0; // unknown
  6466. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE+6;
  6467. #endif
  6468. if(sd) { // send only to self
  6469. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6470. } else if (party_sd) { // send to whole party
  6471. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6472. }
  6473. }
  6474. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6475. /// 02c9 <flag>.B
  6476. /// flag:
  6477. /// 0 = allow party invites
  6478. /// 1 = auto-deny party invites
  6479. void clif_partyinvitationstate(struct map_session_data* sd)
  6480. {
  6481. int fd;
  6482. nullpo_retv(sd);
  6483. fd = sd->fd;
  6484. WFIFOHEAD(fd, packet_len(0x2c9));
  6485. WFIFOW(fd, 0) = 0x2c9;
  6486. WFIFOB(fd, 2) = 0; // not implemented
  6487. WFIFOSET(fd, packet_len(0x2c9));
  6488. }
  6489. /// Party invitation request.
  6490. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6491. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6492. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6493. {
  6494. #if PACKETVER < 20070821
  6495. const int cmd = 0xfe;
  6496. #else
  6497. const int cmd = 0x2c6;
  6498. #endif
  6499. int fd;
  6500. struct party_data *p;
  6501. nullpo_retv(sd);
  6502. nullpo_retv(tsd);
  6503. fd=tsd->fd;
  6504. if( (p=party_search(sd->status.party_id))==NULL )
  6505. return;
  6506. WFIFOHEAD(fd,packet_len(cmd));
  6507. WFIFOW(fd,0)=cmd;
  6508. WFIFOL(fd,2)=sd->status.party_id;
  6509. safestrncpy(WFIFOCP(fd,6),p->party.name,NAME_LENGTH);
  6510. WFIFOSET(fd,packet_len(cmd));
  6511. }
  6512. /// Party invite result.
  6513. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6514. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6515. void clif_party_invite_reply(struct map_session_data* sd, const char* nick, enum e_party_invite_reply reply)
  6516. {
  6517. int fd;
  6518. nullpo_retv(sd);
  6519. fd=sd->fd;
  6520. #if PACKETVER < 20070904
  6521. if( reply == PARTY_REPLY_OFFLINE ) {
  6522. clif_displaymessage(fd, msg_txt(sd,3));
  6523. return;
  6524. }
  6525. #endif
  6526. #if PACKETVER < 20070821
  6527. WFIFOHEAD(fd,packet_len(0xfd));
  6528. WFIFOW(fd,0) = 0xfd;
  6529. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6530. WFIFOB(fd,26) = reply;
  6531. WFIFOSET(fd,packet_len(0xfd));
  6532. #else
  6533. WFIFOHEAD(fd,packet_len(0x2c5));
  6534. WFIFOW(fd,0) = 0x2c5;
  6535. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6536. WFIFOL(fd,26) = reply;
  6537. WFIFOSET(fd,packet_len(0x2c5));
  6538. #endif
  6539. }
  6540. /// Updates party settings.
  6541. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6542. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6543. /// exp option:
  6544. /// 0 = exp sharing disabled
  6545. /// 1 = exp sharing enabled
  6546. /// 2 = cannot change exp sharing
  6547. ///
  6548. /// flag:
  6549. /// 0 = send to party
  6550. /// 1 = send to sd
  6551. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6552. {
  6553. unsigned char buf[16];
  6554. #if PACKETVER < 20090603
  6555. const int cmd = 0x101;
  6556. #else
  6557. const int cmd = 0x7d8;
  6558. #endif
  6559. nullpo_retv(p);
  6560. if(!sd && flag==0){
  6561. int i;
  6562. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6563. if (i < MAX_PARTY)
  6564. sd = p->data[i].sd;
  6565. }
  6566. if(!sd) return;
  6567. WBUFW(buf,0)=cmd;
  6568. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6569. #if PACKETVER >= 20090603
  6570. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6571. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6572. #endif
  6573. if(flag==0)
  6574. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6575. else
  6576. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6577. }
  6578. /**
  6579. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6580. * @param sd Send the notification for this player
  6581. * @param account_id Account ID of kicked member
  6582. * @param name Name of kicked member
  6583. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6584. * @param target Send target
  6585. **/
  6586. void clif_party_withdraw(struct map_session_data *sd, uint32 account_id, const char* name, enum e_party_member_withdraw result, enum send_target target) {
  6587. unsigned char buf[2+4+NAME_LENGTH+1];
  6588. if (!sd)
  6589. return;
  6590. WBUFW(buf,0) = 0x0105;
  6591. WBUFL(buf,2) = account_id;
  6592. memcpy(WBUFP(buf,6), name, NAME_LENGTH);
  6593. WBUFB(buf,6+NAME_LENGTH) = result;
  6594. clif_send(buf, 2+4+NAME_LENGTH+1, &sd->bl, target);
  6595. }
  6596. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6597. /// 0109 <packet len>.W <account id>.L <message>.?B
  6598. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6599. {
  6600. struct map_session_data *sd;
  6601. int i;
  6602. nullpo_retv(p);
  6603. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6604. if(i < MAX_PARTY){
  6605. unsigned char buf[1024];
  6606. if( len > sizeof(buf)-8 )
  6607. {
  6608. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6609. len = sizeof(buf)-8;
  6610. }
  6611. sd = p->data[i].sd;
  6612. WBUFW(buf,0)=0x109;
  6613. WBUFW(buf,2)=len+8;
  6614. WBUFL(buf,4)=account_id;
  6615. safestrncpy(WBUFCP(buf,8), mes, len);
  6616. clif_send(buf,len+8,&sd->bl,PARTY);
  6617. }
  6618. }
  6619. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6620. /// 0107 <account id>.L <x>.W <y>.W
  6621. void clif_party_xy(struct map_session_data *sd)
  6622. {
  6623. unsigned char buf[16];
  6624. nullpo_retv(sd);
  6625. WBUFW(buf,0)=0x107;
  6626. WBUFL(buf,2)=sd->status.account_id;
  6627. WBUFW(buf,6)=sd->bl.x;
  6628. WBUFW(buf,8)=sd->bl.y;
  6629. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6630. }
  6631. /*==========================================
  6632. * Sends x/y dot to a single fd. [Skotlex]
  6633. *------------------------------------------*/
  6634. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6635. {
  6636. WFIFOHEAD(fd,packet_len(0x107));
  6637. WFIFOW(fd,0)=0x107;
  6638. WFIFOL(fd,2)=sd->status.account_id;
  6639. WFIFOW(fd,6)=sd->bl.x;
  6640. WFIFOW(fd,8)=sd->bl.y;
  6641. WFIFOSET(fd,packet_len(0x107));
  6642. }
  6643. /// Updates HP bar of a party member.
  6644. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6645. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6646. void clif_party_hp(struct map_session_data *sd)
  6647. {
  6648. unsigned char buf[16];
  6649. #if PACKETVER < 20100126
  6650. const int cmd = 0x106;
  6651. #else
  6652. const int cmd = 0x80e;
  6653. #endif
  6654. nullpo_retv(sd);
  6655. WBUFW(buf,0)=cmd;
  6656. WBUFL(buf,2)=sd->status.account_id;
  6657. #if PACKETVER < 20100126
  6658. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6659. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6660. WBUFW(buf,8) = 100;
  6661. } else {
  6662. WBUFW(buf,6) = sd->battle_status.hp;
  6663. WBUFW(buf,8) = sd->battle_status.max_hp;
  6664. }
  6665. #else
  6666. WBUFL(buf,6) = sd->battle_status.hp;
  6667. WBUFL(buf,10) = sd->battle_status.max_hp;
  6668. #endif
  6669. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6670. }
  6671. /// Updates the job and level of a party member
  6672. /// 0abd <account id>.L <job>.W <level>.W
  6673. void clif_party_job_and_level(struct map_session_data *sd){
  6674. #if PACKETVER >= 20170502
  6675. unsigned char buf[10];
  6676. nullpo_retv(sd);
  6677. WBUFW(buf, 0) = 0xabd;
  6678. WBUFL(buf, 2) = sd->status.account_id;
  6679. WBUFW(buf, 6) = sd->status.class_;
  6680. WBUFW(buf, 8) = sd->status.base_level;
  6681. clif_send(buf, packet_len(0xabd), &sd->bl, PARTY);
  6682. #endif
  6683. }
  6684. /*==========================================
  6685. * Sends HP bar to a single fd. [Skotlex]
  6686. *------------------------------------------*/
  6687. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6688. {
  6689. #if PACKETVER < 20100126
  6690. const int cmd = 0x106;
  6691. #else
  6692. const int cmd = 0x80e;
  6693. #endif
  6694. WFIFOHEAD(fd,packet_len(cmd));
  6695. WFIFOW(fd,0) = cmd;
  6696. WFIFOL(fd,2) = id;
  6697. #if PACKETVER < 20100126
  6698. if( maxhp > INT16_MAX )
  6699. {// To correctly display the %hp bar. [Skotlex]
  6700. WFIFOW(fd,6) = hp/(maxhp/100);
  6701. WFIFOW(fd,8) = 100;
  6702. } else {
  6703. WFIFOW(fd,6) = hp;
  6704. WFIFOW(fd,8) = maxhp;
  6705. }
  6706. #else
  6707. WFIFOL(fd,6) = hp;
  6708. WFIFOL(fd,10) = maxhp;
  6709. #endif
  6710. WFIFOSET(fd, packet_len(cmd));
  6711. }
  6712. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6713. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6714. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6715. {
  6716. int fd;
  6717. nullpo_retv(sd);
  6718. nullpo_retv(bl);
  6719. fd=sd->fd;
  6720. WFIFOHEAD(fd,packet_len(0x139));
  6721. WFIFOW(fd, 0)=0x139;
  6722. WFIFOL(fd, 2)=bl->id;
  6723. WFIFOW(fd, 6)=bl->x;
  6724. WFIFOW(fd, 8)=bl->y;
  6725. WFIFOW(fd,10)=sd->bl.x;
  6726. WFIFOW(fd,12)=sd->bl.y;
  6727. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6728. WFIFOSET(fd,packet_len(0x139));
  6729. }
  6730. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6731. /// 018f <result>.W <name id>.W
  6732. /// result:
  6733. /// 0 = success
  6734. /// 1 = failure
  6735. /// 2 = success (alchemist)
  6736. /// 3 = failure (alchemist)
  6737. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid)
  6738. {
  6739. int view,fd;
  6740. nullpo_retv(sd);
  6741. fd = sd->fd;
  6742. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6743. WFIFOHEAD(fd,packet_len(0x18f));
  6744. WFIFOW(fd, 0)=0x18f;
  6745. WFIFOW(fd, 2)=flag;
  6746. if((view = itemdb_viewid(nameid)) > 0)
  6747. WFIFOW(fd, 4)=view;
  6748. else
  6749. WFIFOW(fd, 4)=nameid;
  6750. WFIFOSET(fd,packet_len(0x18f));
  6751. }
  6752. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6753. /// 019e
  6754. void clif_catch_process(struct map_session_data *sd)
  6755. {
  6756. int fd;
  6757. nullpo_retv(sd);
  6758. fd=sd->fd;
  6759. WFIFOHEAD(fd,packet_len(0x19e));
  6760. WFIFOW(fd,0)=0x19e;
  6761. WFIFOSET(fd,packet_len(0x19e));
  6762. }
  6763. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6764. /// 01a0 <result>.B
  6765. /// 0 = failure
  6766. /// 1 = success
  6767. void clif_pet_roulette(struct map_session_data *sd,int data)
  6768. {
  6769. int fd;
  6770. nullpo_retv(sd);
  6771. fd=sd->fd;
  6772. WFIFOHEAD(fd,packet_len(0x1a0));
  6773. WFIFOW(fd,0)=0x1a0;
  6774. WFIFOB(fd,2)=data;
  6775. WFIFOSET(fd,packet_len(0x1a0));
  6776. }
  6777. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6778. /// 01a6 <packet len>.W { <index>.W }*
  6779. void clif_sendegg(struct map_session_data *sd)
  6780. {
  6781. int i,n=0,fd;
  6782. nullpo_retv(sd);
  6783. fd=sd->fd;
  6784. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6785. clif_displaymessage(fd, msg_txt(sd,666));
  6786. return;
  6787. }
  6788. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6789. WFIFOW(fd,0)=0x1a6;
  6790. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6791. if(sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL ||
  6792. sd->inventory_data[i]->type != IT_PETEGG ||
  6793. sd->inventory.u.items_inventory[i].amount <= 0)
  6794. continue;
  6795. WFIFOW(fd,n*2+4)=i+2;
  6796. n++;
  6797. }
  6798. WFIFOW(fd,2)=4+n*2;
  6799. WFIFOSET(fd,WFIFOW(fd,2));
  6800. sd->menuskill_id = SA_TAMINGMONSTER;
  6801. sd->menuskill_val = -1;
  6802. }
  6803. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6804. /// 01a4 <type>.B <id>.L <data>.L
  6805. /// type:
  6806. /// 0 = pre-init (data = 0)
  6807. /// 1 = intimacy (data = 0~4)
  6808. /// 2 = hunger (data = 0~4)
  6809. /// 3 = accessory
  6810. /// 4 = performance (data = 1~3: normal, 4: special)
  6811. /// 5 = hairstyle
  6812. ///
  6813. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6814. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6815. {
  6816. uint8 buf[16];
  6817. nullpo_retv(pd);
  6818. WBUFW(buf,0) = 0x1a4;
  6819. WBUFB(buf,2) = type;
  6820. WBUFL(buf,3) = pd->bl.id;
  6821. WBUFL(buf,7) = param;
  6822. if (sd)
  6823. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6824. else
  6825. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6826. }
  6827. /// Pet's base data (ZC_PROPERTY_PET).
  6828. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6829. void clif_send_petstatus(struct map_session_data *sd)
  6830. {
  6831. int fd;
  6832. struct s_pet *pet;
  6833. nullpo_retv(sd);
  6834. nullpo_retv(sd->pd);
  6835. fd=sd->fd;
  6836. pet = &sd->pd->pet;
  6837. WFIFOHEAD(fd,packet_len(0x1a2));
  6838. WFIFOW(fd,0)=0x1a2;
  6839. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  6840. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6841. WFIFOW(fd,27)=pet->level;
  6842. WFIFOW(fd,29)=pet->hungry;
  6843. WFIFOW(fd,31)=pet->intimate;
  6844. WFIFOW(fd,33)=pet->equip;
  6845. #if PACKETVER >= 20081126
  6846. WFIFOW(fd,35)=pet->class_;
  6847. #endif
  6848. WFIFOSET(fd,packet_len(0x1a2));
  6849. }
  6850. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6851. /// 01aa <id>.L <data>.L
  6852. /// data:
  6853. /// @see CZ_PET_ACT.
  6854. void clif_pet_emotion(struct pet_data *pd,int param)
  6855. {
  6856. unsigned char buf[16];
  6857. nullpo_retv(pd);
  6858. memset(buf,0,packet_len(0x1aa));
  6859. WBUFW(buf,0)=0x1aa;
  6860. WBUFL(buf,2)=pd->bl.id;
  6861. if(param >= 100 && pd->petDB->talk_convert_class) {
  6862. if(pd->petDB->talk_convert_class < 0)
  6863. return;
  6864. else if(pd->petDB->talk_convert_class > 0) {
  6865. // replace mob_id component of talk/act data
  6866. param -= (pd->pet.class_ - 100)*100;
  6867. param += (pd->petDB->talk_convert_class - 100)*100;
  6868. }
  6869. }
  6870. WBUFL(buf,6)=param;
  6871. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6872. }
  6873. /// Result of request to feed a pet (ZC_FEED_PET).
  6874. /// 01a3 <result>.B <name id>.W
  6875. /// result:
  6876. /// 0 = failure
  6877. /// 1 = success
  6878. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6879. {
  6880. int fd;
  6881. nullpo_retv(sd);
  6882. fd=sd->fd;
  6883. WFIFOHEAD(fd,packet_len(0x1a3));
  6884. WFIFOW(fd,0)=0x1a3;
  6885. WFIFOB(fd,2)=fail;
  6886. WFIFOW(fd,3)=foodid;
  6887. WFIFOSET(fd,packet_len(0x1a3));
  6888. }
  6889. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6890. /// 01cd { <skill id>.L }*7
  6891. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6892. {
  6893. int fd;
  6894. nullpo_retv(sd);
  6895. fd=sd->fd;
  6896. WFIFOHEAD(fd,packet_len(0x1cd));
  6897. WFIFOW(fd, 0)=0x1cd;
  6898. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6899. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6900. else
  6901. WFIFOL(fd,2)= 0x00000000;
  6902. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6903. WFIFOL(fd,6)= MG_COLDBOLT;
  6904. else
  6905. WFIFOL(fd,6)= 0x00000000;
  6906. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6907. WFIFOL(fd,10)= MG_FIREBOLT;
  6908. else
  6909. WFIFOL(fd,10)= 0x00000000;
  6910. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6911. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6912. else
  6913. WFIFOL(fd,14)= 0x00000000;
  6914. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6915. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6916. else
  6917. WFIFOL(fd,18)= 0x00000000;
  6918. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6919. WFIFOL(fd,22)= MG_FIREBALL;
  6920. else
  6921. WFIFOL(fd,22)= 0x00000000;
  6922. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6923. WFIFOL(fd,26)= MG_FROSTDIVER;
  6924. else
  6925. WFIFOL(fd,26)= 0x00000000;
  6926. WFIFOSET(fd,packet_len(0x1cd));
  6927. sd->menuskill_id = SA_AUTOSPELL;
  6928. sd->menuskill_val = skill_lv;
  6929. }
  6930. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6931. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6932. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6933. {
  6934. unsigned char buf[56];
  6935. nullpo_retv(src);
  6936. memset(buf,0,packet_len(0x1cf));
  6937. WBUFW(buf,0) = 0x1cf;
  6938. WBUFL(buf,2) = src->id;
  6939. if( src->type == BL_MER )
  6940. {
  6941. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6942. if( md && md->master && md->devotion_flag )
  6943. WBUFL(buf,6) = md->master->bl.id;
  6944. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  6945. }
  6946. else
  6947. {
  6948. int i;
  6949. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6950. if( sd == NULL )
  6951. return;
  6952. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  6953. WBUFL(buf,6+4*i) = sd->devotion[i];
  6954. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  6955. }
  6956. if( tsd )
  6957. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6958. else
  6959. clif_send(buf, packet_len(0x1cf), src, AREA);
  6960. }
  6961. /*==========================================
  6962. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6963. * Notifies clients in an area of an object's spirits.
  6964. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6965. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6966. *------------------------------------------*/
  6967. void clif_spiritball(struct block_list *bl) {
  6968. unsigned char buf[16];
  6969. TBL_PC *sd = BL_CAST(BL_PC,bl);
  6970. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  6971. nullpo_retv(bl);
  6972. WBUFW(buf, 0) = 0x1d0;
  6973. WBUFL(buf, 2) = bl->id;
  6974. WBUFW(buf, 6) = 0; //init to 0
  6975. switch(bl->type){
  6976. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  6977. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  6978. }
  6979. clif_send(buf, packet_len(0x1d0), bl, AREA);
  6980. }
  6981. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  6982. /// 01d2 <account id>.L <delay>.L
  6983. void clif_combo_delay(struct block_list *bl,int wait)
  6984. {
  6985. unsigned char buf[32];
  6986. nullpo_retv(bl);
  6987. WBUFW(buf,0)=0x1d2;
  6988. WBUFL(buf,2)=bl->id;
  6989. WBUFL(buf,6)=wait;
  6990. clif_send(buf,packet_len(0x1d2),bl,AREA);
  6991. }
  6992. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  6993. /// 01d1 <src id>.L <dst id>.L <flag>.L
  6994. /// flag:
  6995. /// 0 = inactive
  6996. /// 1 = active
  6997. void clif_bladestop(struct block_list *src, int dst_id, int active)
  6998. {
  6999. unsigned char buf[32];
  7000. nullpo_retv(src);
  7001. WBUFW(buf,0)=0x1d1;
  7002. WBUFL(buf,2)=src->id;
  7003. WBUFL(buf,6)=dst_id;
  7004. WBUFL(buf,10)=active;
  7005. clif_send(buf,packet_len(0x1d1),src,AREA);
  7006. }
  7007. /// MVP effect (ZC_MVP).
  7008. /// 010c <account id>.L
  7009. void clif_mvp_effect(struct map_session_data *sd)
  7010. {
  7011. unsigned char buf[16];
  7012. nullpo_retv(sd);
  7013. WBUFW(buf,0)=0x10c;
  7014. WBUFL(buf,2)=sd->bl.id;
  7015. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7016. }
  7017. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7018. /// 010a <name id>.W
  7019. void clif_mvp_item(struct map_session_data *sd, unsigned short nameid)
  7020. {
  7021. int view,fd;
  7022. nullpo_retv(sd);
  7023. fd=sd->fd;
  7024. WFIFOHEAD(fd,packet_len(0x10a));
  7025. WFIFOW(fd,0)=0x10a;
  7026. if((view = itemdb_viewid(nameid)) > 0)
  7027. WFIFOW(fd,2)=view;
  7028. else
  7029. WFIFOW(fd,2)=nameid;
  7030. WFIFOSET(fd,packet_len(0x10a));
  7031. }
  7032. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7033. /// 010b <exp>.L
  7034. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp) {
  7035. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7036. if (battle_config.mvp_exp_reward_message) {
  7037. char e_msg[CHAT_SIZE_MAX];
  7038. sprintf(e_msg, msg_txt(sd, 717), exp);
  7039. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7040. }
  7041. #else
  7042. int fd;
  7043. nullpo_retv(sd);
  7044. fd = sd->fd;
  7045. WFIFOHEAD(fd, packet_len(0x10b));
  7046. WFIFOW(fd,0) = 0x10b;
  7047. WFIFOL(fd,2) = min(exp, (unsigned int)INT32_MAX);
  7048. WFIFOSET(fd, packet_len(0x10b));
  7049. #endif
  7050. }
  7051. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7052. /// 010d
  7053. ///
  7054. /// "You are the MVP, but cannot obtain the reward because
  7055. /// you are overweight."
  7056. void clif_mvp_noitem(struct map_session_data* sd)
  7057. {
  7058. int fd = sd->fd;
  7059. WFIFOHEAD(fd,packet_len(0x10d));
  7060. WFIFOW(fd,0) = 0x10d;
  7061. WFIFOSET(fd,packet_len(0x10d));
  7062. }
  7063. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7064. /// 0167 <result>.B
  7065. /// result:
  7066. /// 0 = "Guild has been created."
  7067. /// 1 = "You are already in a Guild."
  7068. /// 2 = "That Guild Name already exists."
  7069. /// 3 = "You need the neccessary item to create a Guild."
  7070. void clif_guild_created(struct map_session_data *sd,int flag)
  7071. {
  7072. int fd;
  7073. nullpo_retv(sd);
  7074. fd=sd->fd;
  7075. WFIFOHEAD(fd,packet_len(0x167));
  7076. WFIFOW(fd,0)=0x167;
  7077. WFIFOB(fd,2)=flag;
  7078. WFIFOSET(fd,packet_len(0x167));
  7079. }
  7080. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7081. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7082. /// mode:
  7083. /// &0x01 = allow invite
  7084. /// &0x10 = allow expel
  7085. void clif_guild_belonginfo(struct map_session_data *sd)
  7086. {
  7087. int ps,fd;
  7088. struct guild* g;
  7089. nullpo_retv(sd);
  7090. nullpo_retv(g = sd->guild);
  7091. fd=sd->fd;
  7092. ps=guild_getposition(sd);
  7093. WFIFOHEAD(fd,packet_len(0x16c));
  7094. WFIFOW(fd,0)=0x16c;
  7095. WFIFOL(fd,2)=g->guild_id;
  7096. WFIFOL(fd,6)=g->emblem_id;
  7097. WFIFOL(fd,10)=g->position[ps].mode;
  7098. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  7099. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  7100. safestrncpy(WFIFOCP(fd,19),g->name,NAME_LENGTH);
  7101. WFIFOSET(fd,packet_len(0x16c));
  7102. }
  7103. /// Guild member login notice.
  7104. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7105. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7106. /// status:
  7107. /// 0 = offline
  7108. /// 1 = online
  7109. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7110. {
  7111. unsigned char buf[64];
  7112. struct map_session_data* sd;
  7113. nullpo_retv(g);
  7114. WBUFW(buf, 0)=0x1f2;
  7115. WBUFL(buf, 2)=g->member[idx].account_id;
  7116. WBUFL(buf, 6)=g->member[idx].char_id;
  7117. WBUFL(buf,10)=flag;
  7118. if( ( sd = g->member[idx].sd ) != NULL )
  7119. {
  7120. WBUFW(buf,14) = sd->status.sex;
  7121. WBUFW(buf,16) = sd->status.hair;
  7122. WBUFW(buf,18) = sd->status.hair_color;
  7123. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7124. }
  7125. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7126. {
  7127. WBUFW(buf,14) = 0;
  7128. WBUFW(buf,16) = 0;
  7129. WBUFW(buf,18) = 0;
  7130. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7131. }
  7132. }
  7133. // Function `clif_guild_memberlogin_notice` sends info about
  7134. // logins and logouts of a guild member to the rest members.
  7135. // But at the 1st time (after a player login or map changing)
  7136. // the client won't show the message.
  7137. // So I suggest use this function for sending "first-time-info"
  7138. // to some player on entering the game or changing location.
  7139. // At next time the client would always show the message.
  7140. // The function sends all the statuses in the single packet
  7141. // to economize traffic. [LuzZza]
  7142. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7143. {
  7144. struct guild *g;
  7145. unsigned char buf[14*128];
  7146. int i, count=0, p_len;
  7147. nullpo_retv(sd);
  7148. p_len = packet_len(0x16d);
  7149. if(!(g = sd->guild))
  7150. return;
  7151. for(i=0; i<g->max_member; i++) {
  7152. if(g->member[i].account_id > 0 &&
  7153. g->member[i].account_id != sd->status.account_id) {
  7154. WBUFW(buf,count*p_len) = 0x16d;
  7155. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7156. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7157. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7158. count++;
  7159. }
  7160. }
  7161. clif_send(buf, p_len*count, &sd->bl, SELF);
  7162. }
  7163. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7164. /// 014e <menu flag>.L
  7165. /// menu flag:
  7166. /// 0x00 = Basic Info (always on)
  7167. /// &0x01 = Member manager
  7168. /// &0x02 = Positions
  7169. /// &0x04 = Skills
  7170. /// &0x10 = Expulsion list
  7171. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7172. /// &0x80 = Notice
  7173. void clif_guild_masterormember(struct map_session_data *sd)
  7174. {
  7175. int fd;
  7176. nullpo_retv(sd);
  7177. fd=sd->fd;
  7178. WFIFOHEAD(fd,packet_len(0x14e));
  7179. WFIFOW(fd,0) = 0x14e;
  7180. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7181. WFIFOSET(fd,packet_len(0x14e));
  7182. }
  7183. /// Guild basic information (Territories [Valaris])
  7184. /// 0150 <guild id>.L <level>.L <member num>.L <member max>.L <exp>.L <max exp>.L <points>.L <honor>.L <virtue>.L <emblem id>.L <name>.24B <master name>.24B <manage land>.16B (ZC_GUILD_INFO)
  7185. /// 01b6 <guild id>.L <level>.L <member num>.L <member max>.L <exp>.L <max exp>.L <points>.L <honor>.L <virtue>.L <emblem id>.L <name>.24B <master name>.24B <manage land>.16B <zeny>.L (ZC_GUILD_INFO2)
  7186. /// 0a84 <guild id>.L <level>.L <member num>.L <member max>.L <exp>.L <max exp>.L <points>.L <honor>.L <virtue>.L <emblem id>.L <name>.24B <manage land>.16B <zeny>.L <master char id>.L (ZC_GUILD_INFO3)
  7187. void clif_guild_basicinfo(struct map_session_data *sd) {
  7188. int fd;
  7189. struct guild *g;
  7190. #if PACKETVER < 20160622
  7191. int cmd = 0x1b6;
  7192. int offset = NAME_LENGTH;
  7193. #else
  7194. int cmd = 0xa84;
  7195. int offset = 0;
  7196. #endif
  7197. nullpo_retv(sd);
  7198. fd = sd->fd;
  7199. if( (g = sd->guild) == NULL )
  7200. return;
  7201. WFIFOHEAD(fd,packet_len(cmd));
  7202. WFIFOW(fd, 0)=cmd;
  7203. WFIFOL(fd, 2)=g->guild_id;
  7204. WFIFOL(fd, 6)=g->guild_lv;
  7205. WFIFOL(fd,10)=g->connect_member;
  7206. WFIFOL(fd,14)=g->max_member;
  7207. WFIFOL(fd,18)=g->average_lv;
  7208. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  7209. WFIFOL(fd,26)=g->next_exp;
  7210. WFIFOL(fd,30)=0; // Tax Points
  7211. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7212. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7213. WFIFOL(fd,42)=g->emblem_id;
  7214. safestrncpy(WFIFOCP(fd,46),g->name, NAME_LENGTH);
  7215. #if PACKETVER < 20160622
  7216. safestrncpy(WFIFOCP(fd,70),g->master, NAME_LENGTH);
  7217. #endif
  7218. safestrncpy(WFIFOCP(fd,70+offset),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7219. WFIFOL(fd,70+offset+16) = 0; // zeny
  7220. #if PACKETVER >= 20160622
  7221. WFIFOL(fd,70+offset+20) = g->member[0].char_id; // leader
  7222. #endif
  7223. WFIFOSET(fd,packet_len(cmd));
  7224. }
  7225. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7226. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7227. void clif_guild_allianceinfo(struct map_session_data *sd)
  7228. {
  7229. int fd,i,c;
  7230. struct guild *g;
  7231. nullpo_retv(sd);
  7232. if( (g = sd->guild) == NULL )
  7233. return;
  7234. fd = sd->fd;
  7235. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7236. WFIFOW(fd, 0)=0x14c;
  7237. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7238. struct guild_alliance *a=&g->alliance[i];
  7239. if(a->guild_id>0){
  7240. WFIFOL(fd,c*32+4)=a->opposition;
  7241. WFIFOL(fd,c*32+8)=a->guild_id;
  7242. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7243. c++;
  7244. }
  7245. }
  7246. WFIFOW(fd, 2)=c*32+4;
  7247. WFIFOSET(fd,WFIFOW(fd,2));
  7248. }
  7249. /// Guild member manager information
  7250. /// 0154 <packet len>.W { <account>.L <char id>.L <hair style>.W <hair color>.W <gender>.W <class>.W <level>.W <contrib exp>.L <state>.L <position>.L <memo>.50B <name>.24B }* (ZC_MEMBERMGR_INFO)
  7251. /// state:
  7252. /// 0 = offline
  7253. /// 1 = online
  7254. /// memo:
  7255. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7256. /// 0aa5 <packet len>.W { <account>.L <char id>.L <hair style>.W <hair color>.W <gender>.W <class>.W <level>.W <contrib exp>.L <state>.L <position>.L }* (ZC_MEMBERMGR_INFO2)
  7257. void clif_guild_memberlist(struct map_session_data *sd)
  7258. {
  7259. int fd;
  7260. int i,c;
  7261. struct guild *g;
  7262. #if PACKETVER < 20161026
  7263. int cmd = 0x154;
  7264. int size = 104;
  7265. #else
  7266. int cmd = 0xaa5;
  7267. int size = 34;
  7268. #endif
  7269. nullpo_retv(sd);
  7270. if( (fd = sd->fd) == 0 )
  7271. return;
  7272. if( (g = sd->guild) == NULL )
  7273. return;
  7274. WFIFOHEAD(fd, g->max_member * size + 4);
  7275. WFIFOW(fd, 0)=cmd;
  7276. for(i=0,c=0;i<g->max_member;i++){
  7277. struct guild_member *m=&g->member[i];
  7278. if(m->account_id==0)
  7279. continue;
  7280. WFIFOL(fd,c*size+ 4)=m->account_id;
  7281. WFIFOL(fd,c*size+ 8)=m->char_id;
  7282. WFIFOW(fd,c*size+12)=m->hair;
  7283. WFIFOW(fd,c*size+14)=m->hair_color;
  7284. WFIFOW(fd,c*size+16)=m->gender;
  7285. WFIFOW(fd,c*size+18)=m->class_;
  7286. WFIFOW(fd,c*size+20)=m->lv;
  7287. WFIFOL(fd,c*size+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7288. WFIFOL(fd,c*size+26)=m->online;
  7289. WFIFOL(fd,c*size+30)=m->position;
  7290. #if PACKETVER < 20161026
  7291. memset(WFIFOP(fd,c*size+34),0,50); //[Ind] - This is displayed in the 'note' column but being you can't edit it it's sent empty.
  7292. safestrncpy(WFIFOCP(fd,c*size+84),m->name,NAME_LENGTH);
  7293. #else
  7294. WFIFOL(fd,c*size+34)=m->last_login;
  7295. #endif
  7296. c++;
  7297. }
  7298. WFIFOW(fd, 2)=c*size+4;
  7299. WFIFOSET(fd,WFIFOW(fd,2));
  7300. }
  7301. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7302. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7303. void clif_guild_positionnamelist(struct map_session_data *sd)
  7304. {
  7305. int i,fd;
  7306. struct guild *g;
  7307. nullpo_retv(sd);
  7308. if( (g = sd->guild) == NULL )
  7309. return;
  7310. fd = sd->fd;
  7311. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7312. WFIFOW(fd, 0)=0x166;
  7313. for(i=0;i<MAX_GUILDPOSITION;i++){
  7314. WFIFOL(fd,i*28+4)=i;
  7315. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7316. }
  7317. WFIFOW(fd,2)=i*28+4;
  7318. WFIFOSET(fd,WFIFOW(fd,2));
  7319. }
  7320. /// Guild position information (ZC_POSITION_INFO).
  7321. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7322. /// mode:
  7323. /// &0x01 = allow invite
  7324. /// &0x10 = allow expel
  7325. /// ranking:
  7326. /// TODO
  7327. void clif_guild_positioninfolist(struct map_session_data *sd)
  7328. {
  7329. int i,fd;
  7330. struct guild *g;
  7331. nullpo_retv(sd);
  7332. if( (g = sd->guild) == NULL )
  7333. return;
  7334. fd = sd->fd;
  7335. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7336. WFIFOW(fd, 0)=0x160;
  7337. for(i=0;i<MAX_GUILDPOSITION;i++){
  7338. struct guild_position *p=&g->position[i];
  7339. WFIFOL(fd,i*16+ 4)=i;
  7340. WFIFOL(fd,i*16+ 8)=p->mode;
  7341. WFIFOL(fd,i*16+12)=i;
  7342. WFIFOL(fd,i*16+16)=p->exp_mode;
  7343. }
  7344. WFIFOW(fd, 2)=i*16+4;
  7345. WFIFOSET(fd,WFIFOW(fd,2));
  7346. }
  7347. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7348. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7349. /// mode:
  7350. /// &0x01 = allow invite
  7351. /// &0x10 = allow expel
  7352. /// ranking:
  7353. /// TODO
  7354. void clif_guild_positionchanged(struct guild *g,int idx)
  7355. {
  7356. // FIXME: This packet is intended to update the clients after a
  7357. // commit of position info changes, not sending one packet per
  7358. // position.
  7359. struct map_session_data *sd;
  7360. unsigned char buf[128];
  7361. nullpo_retv(g);
  7362. WBUFW(buf, 0)=0x174;
  7363. WBUFW(buf, 2)=44; // packet len
  7364. // GUILD_REG_POSITION_INFO{
  7365. WBUFL(buf, 4)=idx;
  7366. WBUFL(buf, 8)=g->position[idx].mode;
  7367. WBUFL(buf,12)=idx;
  7368. WBUFL(buf,16)=g->position[idx].exp_mode;
  7369. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7370. // }*
  7371. if( (sd=guild_getavailablesd(g))!=NULL )
  7372. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7373. }
  7374. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7375. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7376. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7377. {
  7378. // FIXME: This packet is intended to update the clients after a
  7379. // commit of member position assignment changes, not sending one
  7380. // packet per position.
  7381. struct map_session_data *sd;
  7382. unsigned char buf[64];
  7383. nullpo_retv(g);
  7384. WBUFW(buf, 0)=0x156;
  7385. WBUFW(buf, 2)=16; // packet len
  7386. // MEMBER_POSITION_INFO{
  7387. WBUFL(buf, 4)=g->member[idx].account_id;
  7388. WBUFL(buf, 8)=g->member[idx].char_id;
  7389. WBUFL(buf,12)=g->member[idx].position;
  7390. // }*
  7391. if( (sd=guild_getavailablesd(g))!=NULL )
  7392. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7393. }
  7394. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7395. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7396. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7397. {
  7398. int fd;
  7399. nullpo_retv(sd);
  7400. nullpo_retv(g);
  7401. fd = sd->fd;
  7402. if( g->emblem_len <= 0 )
  7403. return;
  7404. WFIFOHEAD(fd,g->emblem_len+12);
  7405. WFIFOW(fd,0)=0x152;
  7406. WFIFOW(fd,2)=g->emblem_len+12;
  7407. WFIFOL(fd,4)=g->guild_id;
  7408. WFIFOL(fd,8)=g->emblem_id;
  7409. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7410. WFIFOSET(fd,WFIFOW(fd,2));
  7411. }
  7412. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7413. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7414. void clif_guild_emblem_area(struct block_list* bl)
  7415. {
  7416. uint8 buf[12];
  7417. nullpo_retv(bl);
  7418. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7419. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7420. WBUFW(buf,0) = 0x1b4;
  7421. WBUFL(buf,2) = bl->id;
  7422. WBUFL(buf,6) = status_get_guild_id(bl);
  7423. WBUFW(buf,10) = status_get_emblem_id(bl);
  7424. clif_send(buf, 12, bl, AREA_WOS);
  7425. }
  7426. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7427. /// 0162 <packet len>.W <skill points>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B }*
  7428. void clif_guild_skillinfo(struct map_session_data* sd)
  7429. {
  7430. int fd;
  7431. struct guild* g;
  7432. int i,c;
  7433. nullpo_retv(sd);
  7434. if( (g = sd->guild) == NULL )
  7435. return;
  7436. fd = sd->fd;
  7437. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7438. WFIFOW(fd,0) = 0x0162;
  7439. WFIFOW(fd,4) = g->skill_point;
  7440. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7441. {
  7442. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7443. {
  7444. int id = g->skill[i].id;
  7445. int p = 6 + c*37;
  7446. WFIFOW(fd,p+0) = id;
  7447. WFIFOL(fd,p+2) = skill_get_inf(id);
  7448. WFIFOW(fd,p+6) = g->skill[i].lv;
  7449. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7450. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7451. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7452. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7453. c++;
  7454. }
  7455. }
  7456. WFIFOW(fd,2) = 6 + c*37;
  7457. WFIFOSET(fd,WFIFOW(fd,2));
  7458. }
  7459. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7460. /// 016f <subject>.60B <notice>.120B
  7461. void clif_guild_notice(struct map_session_data* sd)
  7462. {
  7463. int fd;
  7464. struct guild* g;
  7465. nullpo_retv(sd);
  7466. nullpo_retv(g = sd->guild);
  7467. fd = sd->fd;
  7468. if ( !session_isActive(fd) )
  7469. return;
  7470. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7471. return;
  7472. WFIFOHEAD(fd,packet_len(0x16f));
  7473. WFIFOW(fd,0) = 0x16f;
  7474. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7475. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7476. WFIFOSET(fd,packet_len(0x16f));
  7477. }
  7478. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7479. /// 016a <guild id>.L <guild name>.24B
  7480. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7481. {
  7482. int fd;
  7483. nullpo_retv(sd);
  7484. nullpo_retv(g);
  7485. fd=sd->fd;
  7486. WFIFOHEAD(fd,packet_len(0x16a));
  7487. WFIFOW(fd,0)=0x16a;
  7488. WFIFOL(fd,2)=g->guild_id;
  7489. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7490. WFIFOSET(fd,packet_len(0x16a));
  7491. }
  7492. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7493. /// 0169 <answer>.B
  7494. /// answer:
  7495. /// 0 = Already in guild.
  7496. /// 1 = Offer rejected.
  7497. /// 2 = Offer accepted.
  7498. /// 3 = Guild full.
  7499. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7500. {
  7501. int fd;
  7502. nullpo_retv(sd);
  7503. fd=sd->fd;
  7504. WFIFOHEAD(fd,packet_len(0x169));
  7505. WFIFOW(fd,0)=0x169;
  7506. WFIFOB(fd,2)=flag;
  7507. WFIFOSET(fd,packet_len(0x169));
  7508. }
  7509. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7510. /// 015a <char name>.24B <reason>.40B
  7511. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7512. {
  7513. unsigned char buf[128];
  7514. nullpo_retv(sd);
  7515. WBUFW(buf, 0)=0x15a;
  7516. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7517. memcpy(WBUFP(buf,26),mes,40);
  7518. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7519. }
  7520. /// Notifies clients of a guild of an expelled member.
  7521. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7522. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7523. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7524. {
  7525. unsigned char buf[128];
  7526. #if PACKETVER < 20100803
  7527. const unsigned short cmd = 0x15c;
  7528. #else
  7529. const unsigned short cmd = 0x839;
  7530. #endif
  7531. nullpo_retv(sd);
  7532. WBUFW(buf,0) = cmd;
  7533. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7534. safestrncpy(WBUFCP(buf,26), mes, 40);
  7535. #if PACKETVER < 20100803
  7536. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7537. #endif
  7538. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7539. }
  7540. /// Guild expulsion list (ZC_BAN_LIST).
  7541. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7542. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7543. void clif_guild_expulsionlist(struct map_session_data* sd)
  7544. {
  7545. #if PACKETVER < 20100803
  7546. const int offset = NAME_LENGTH*2+40;
  7547. #else
  7548. const int offset = NAME_LENGTH+40;
  7549. #endif
  7550. int fd, i, c = 0;
  7551. struct guild* g;
  7552. nullpo_retv(sd);
  7553. if( (g = sd->guild) == NULL )
  7554. return;
  7555. fd = sd->fd;
  7556. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7557. WFIFOW(fd,0) = 0x163;
  7558. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7559. {
  7560. struct guild_expulsion* e = &g->expulsion[i];
  7561. if( e->account_id > 0 )
  7562. {
  7563. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7564. #if PACKETVER < 20100803
  7565. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7566. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7567. #else
  7568. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7569. #endif
  7570. c++;
  7571. }
  7572. }
  7573. WFIFOW(fd,2) = 4 + c*offset;
  7574. WFIFOSET(fd,WFIFOW(fd,2));
  7575. }
  7576. /// Guild chat message (ZC_GUILD_CHAT).
  7577. /// 017f <packet len>.W <message>.?B
  7578. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7579. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7580. struct map_session_data *sd;
  7581. uint8 buf[256];
  7582. if( len == 0 )
  7583. {
  7584. return;
  7585. }
  7586. else if( len > sizeof(buf)-5 )
  7587. {
  7588. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7589. len = sizeof(buf)-5;
  7590. }
  7591. WBUFW(buf, 0) = 0x17f;
  7592. WBUFW(buf, 2) = len + 5;
  7593. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7594. if ((sd = guild_getavailablesd(g)) != NULL)
  7595. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7596. }
  7597. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7598. /// 0171 <inviter account id>.L <guild name>.24B
  7599. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7600. {
  7601. int fd;
  7602. nullpo_retv(sd);
  7603. fd=sd->fd;
  7604. WFIFOHEAD(fd,packet_len(0x171));
  7605. WFIFOW(fd,0)=0x171;
  7606. WFIFOL(fd,2)=account_id;
  7607. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7608. WFIFOSET(fd,packet_len(0x171));
  7609. }
  7610. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7611. /// 0173 <answer>.B
  7612. /// answer:
  7613. /// 0 = Already allied.
  7614. /// 1 = You rejected the offer.
  7615. /// 2 = You accepted the offer.
  7616. /// 3 = They have too any alliances.
  7617. /// 4 = You have too many alliances.
  7618. /// 5 = Alliances are disabled.
  7619. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7620. {
  7621. int fd;
  7622. nullpo_retv(sd);
  7623. fd=sd->fd;
  7624. WFIFOHEAD(fd,packet_len(0x173));
  7625. WFIFOW(fd,0)=0x173;
  7626. WFIFOL(fd,2)=flag;
  7627. WFIFOSET(fd,packet_len(0x173));
  7628. }
  7629. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7630. /// 0184 <other guild id>.L <relation>.L
  7631. /// relation:
  7632. /// 0 = Ally
  7633. /// 1 = Enemy
  7634. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7635. {
  7636. int fd;
  7637. nullpo_retv(sd);
  7638. fd = sd->fd;
  7639. if (fd <= 0)
  7640. return;
  7641. WFIFOHEAD(fd,packet_len(0x184));
  7642. WFIFOW(fd,0)=0x184;
  7643. WFIFOL(fd,2)=guild_id;
  7644. WFIFOL(fd,6)=flag;
  7645. WFIFOSET(fd,packet_len(0x184));
  7646. }
  7647. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7648. /// 0181 <result>.B
  7649. /// result:
  7650. /// 0 = Antagonist has been set.
  7651. /// 1 = Guild has too many Antagonists.
  7652. /// 2 = Already set as an Antagonist.
  7653. /// 3 = Antagonists are disabled.
  7654. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7655. {
  7656. int fd;
  7657. nullpo_retv(sd);
  7658. fd=sd->fd;
  7659. WFIFOHEAD(fd,packet_len(0x181));
  7660. WFIFOW(fd,0)=0x181;
  7661. WFIFOB(fd,2)=flag;
  7662. WFIFOSET(fd,packet_len(0x181));
  7663. }
  7664. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7665. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7666. /*
  7667. void clif_guild_allianceadded(struct guild *g,int idx)
  7668. {
  7669. unsigned char buf[64];
  7670. WBUFW(buf,0)=0x185;
  7671. WBUFL(buf,2)=g->alliance[idx].opposition;
  7672. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7673. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7674. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7675. }
  7676. */
  7677. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7678. /// 015e <reason>.L
  7679. /// 0 = success
  7680. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7681. /// 2 = there are still members in the guild
  7682. void clif_guild_broken(struct map_session_data *sd,int flag)
  7683. {
  7684. int fd;
  7685. nullpo_retv(sd);
  7686. fd=sd->fd;
  7687. WFIFOHEAD(fd,packet_len(0x15e));
  7688. WFIFOW(fd,0)=0x15e;
  7689. WFIFOL(fd,2)=flag;
  7690. WFIFOSET(fd,packet_len(0x15e));
  7691. }
  7692. /// Displays emotion on an object (ZC_EMOTION).
  7693. /// 00c0 <id>.L <type>.B
  7694. /// type:
  7695. /// enum emotion_type
  7696. void clif_emotion(struct block_list *bl,int type)
  7697. {
  7698. unsigned char buf[8];
  7699. nullpo_retv(bl);
  7700. WBUFW(buf,0)=0xc0;
  7701. WBUFL(buf,2)=bl->id;
  7702. WBUFB(buf,6)=type;
  7703. clif_send(buf,packet_len(0xc0),bl,AREA);
  7704. }
  7705. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7706. /// 0191 <id>.L <contents>.80B
  7707. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7708. {
  7709. unsigned char buf[MESSAGE_SIZE+6];
  7710. nullpo_retv(bl);
  7711. WBUFW(buf,0) = 0x191;
  7712. WBUFL(buf,2) = bl->id;
  7713. safestrncpy(WBUFCP(buf,6),talkie,MESSAGE_SIZE);
  7714. clif_send(buf,packet_len(0x191),bl,AREA);
  7715. }
  7716. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7717. /// 01ea <id>.L
  7718. void clif_wedding_effect(struct block_list *bl)
  7719. {
  7720. unsigned char buf[6];
  7721. nullpo_retv(bl);
  7722. WBUFW(buf,0) = 0x1ea;
  7723. WBUFL(buf,2) = bl->id;
  7724. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7725. }
  7726. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7727. /// 01e6 <partner name>.24B
  7728. void clif_callpartner(struct map_session_data *sd)
  7729. {
  7730. unsigned char buf[26];
  7731. nullpo_retv(sd);
  7732. WBUFW(buf,0) = 0x1e6;
  7733. if( sd->status.partner_id ) {
  7734. const char *p = map_charid2nick(sd->status.partner_id);
  7735. struct map_session_data *p_sd = pc_get_partner(sd);
  7736. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7737. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  7738. else
  7739. WBUFB(buf,2) = 0;
  7740. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7741. WBUFB(buf,2) = 0;
  7742. }
  7743. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7744. }
  7745. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7746. /// 01e4
  7747. /// This packet while still implemented by the client is no longer being officially used.
  7748. /*
  7749. void clif_marriage_process(struct map_session_data *sd)
  7750. {
  7751. int fd;
  7752. nullpo_retv(sd);
  7753. fd=sd->fd;
  7754. WFIFOHEAD(fd,packet_len(0x1e4));
  7755. WFIFOW(fd,0)=0x1e4;
  7756. WFIFOSET(fd,packet_len(0x1e4));
  7757. }
  7758. */
  7759. /// Notice of divorce (ZC_DIVORCE).
  7760. /// 0205 <partner name>.24B
  7761. void clif_divorced(struct map_session_data* sd, const char* name)
  7762. {
  7763. int fd;
  7764. nullpo_retv(sd);
  7765. fd=sd->fd;
  7766. WFIFOHEAD(fd,packet_len(0x205));
  7767. WFIFOW(fd,0)=0x205;
  7768. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7769. WFIFOSET(fd, packet_len(0x205));
  7770. }
  7771. /// Marriage proposal (ZC_REQ_COUPLE).
  7772. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7773. /// This packet while still implemented by the client is no longer being officially used.
  7774. /*
  7775. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7776. {
  7777. nullpo_retv(sd);
  7778. WFIFOHEAD(fd,packet_len(0x1e2));
  7779. WFIFOW(fd,0) = 0x1e2;
  7780. WFIFOL(fd,2) = ssd->status.account_id;
  7781. WFIFOL(fd,6) = ssd->status.char_id;
  7782. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7783. WFIFOSET(fd, packet_len(0x1e2));
  7784. }
  7785. */
  7786. /*==========================================
  7787. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7788. *------------------------------------------*/
  7789. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7790. {
  7791. unsigned char buf[256];
  7792. if( len == 0 ) {
  7793. return;
  7794. } else if( len > sizeof(buf)-5 ) {
  7795. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7796. len = sizeof(buf)-5;
  7797. }
  7798. WBUFW(buf, 0) = 0x17f;
  7799. WBUFW(buf, 2) = len + 5;
  7800. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7801. clif_send(buf, WBUFW(buf,2), src, target);
  7802. }
  7803. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7804. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7805. /// 00cd <result>.B
  7806. /// result:
  7807. /// 0 = failure
  7808. /// 1 = success
  7809. void clif_GM_kickack(struct map_session_data *sd, int id)
  7810. {
  7811. int fd;
  7812. nullpo_retv(sd);
  7813. fd = sd->fd;
  7814. WFIFOHEAD(fd,packet_len(0xcd));
  7815. WFIFOW(fd,0) = 0xcd;
  7816. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7817. WFIFOSET(fd, packet_len(0xcd));
  7818. }
  7819. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  7820. {
  7821. int fd;
  7822. nullpo_retv(tsd);
  7823. fd = tsd->fd;
  7824. if (sd == NULL)
  7825. tsd->state.keepshop = true;
  7826. if (fd > 0)
  7827. clif_authfail_fd(fd, 15);
  7828. else
  7829. map_quit(tsd);
  7830. if (sd)
  7831. clif_GM_kickack(sd, tsd->status.account_id);
  7832. }
  7833. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7834. /// 014a <result>.L
  7835. /// result:
  7836. /// 0 = "A manner point has been successfully aligned."
  7837. /// 1 = MP_FAILURE_EXHAUST
  7838. /// 2 = MP_FAILURE_ALREADY_GIVING
  7839. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7840. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7841. /// 5 = "You got a good point from %s."
  7842. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7843. {
  7844. int fd;
  7845. nullpo_retv(sd);
  7846. fd = sd->fd;
  7847. WFIFOHEAD(fd,packet_len(0x14a));
  7848. WFIFOW(fd,0) = 0x14a;
  7849. WFIFOL(fd,2) = type;
  7850. WFIFOSET(fd, packet_len(0x14a));
  7851. }
  7852. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7853. /// 014b <type>.B <GM name>.24B
  7854. /// type:
  7855. /// 0 = positive (unmute)
  7856. /// 1 = negative (mute)
  7857. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7858. {
  7859. int fd;
  7860. nullpo_retv(sd);
  7861. nullpo_retv(tsd);
  7862. fd = tsd->fd;
  7863. WFIFOHEAD(fd,packet_len(0x14b));
  7864. WFIFOW(fd,0) = 0x14b;
  7865. WFIFOB(fd,2) = type;
  7866. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  7867. WFIFOSET(fd, packet_len(0x14b));
  7868. }
  7869. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7870. /// 00d1 <type>.B <result>.B
  7871. /// type:
  7872. /// 0 = /ex (deny)
  7873. /// 1 = /in (allow)
  7874. /// result:
  7875. /// 0 = success
  7876. /// 1 = failure
  7877. /// 2 = too many blocks
  7878. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7879. {
  7880. int fd;
  7881. nullpo_retv(sd);
  7882. fd=sd->fd;
  7883. WFIFOHEAD(fd,packet_len(0xd1));
  7884. WFIFOW(fd,0)=0xd1;
  7885. WFIFOB(fd,2)=type;
  7886. WFIFOB(fd,3)=flag;
  7887. WFIFOSET(fd,packet_len(0xd1));
  7888. }
  7889. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7890. /// 00d2 <type>.B <result>.B
  7891. /// type:
  7892. /// 0 = /exall (deny)
  7893. /// 1 = /inall (allow)
  7894. /// result:
  7895. /// 0 = success
  7896. /// 1 = failure
  7897. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7898. {
  7899. int fd;
  7900. nullpo_retv(sd);
  7901. fd=sd->fd;
  7902. WFIFOHEAD(fd,packet_len(0xd2));
  7903. WFIFOW(fd,0)=0xd2;
  7904. WFIFOB(fd,2)=type;
  7905. WFIFOB(fd,3)=flag;
  7906. WFIFOSET(fd,packet_len(0xd2));
  7907. }
  7908. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7909. /// 07fe <bgm>.24B
  7910. void clif_playBGM(struct map_session_data* sd, const char* name)
  7911. {
  7912. int fd;
  7913. nullpo_retv(sd);
  7914. fd = sd->fd;
  7915. WFIFOHEAD(fd,packet_len(0x7fe));
  7916. WFIFOW(fd,0) = 0x7fe;
  7917. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7918. WFIFOSET(fd,packet_len(0x7fe));
  7919. }
  7920. /// Plays/stops a wave sound (ZC_SOUND).
  7921. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7922. /// file name:
  7923. /// relative to data\wav
  7924. /// act:
  7925. /// 0 = play (once)
  7926. /// 1 = play (repeat, does not work)
  7927. /// 2 = stops all sound instances of file name (does not work)
  7928. /// term:
  7929. /// unknown purpose, only relevant to act = 1
  7930. /// npc id:
  7931. /// The accustic direction of the sound is determined by the
  7932. /// relative position of the NPC to the player (3D sound).
  7933. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7934. {
  7935. int fd;
  7936. nullpo_retv(sd);
  7937. nullpo_retv(bl);
  7938. fd = sd->fd;
  7939. WFIFOHEAD(fd,packet_len(0x1d3));
  7940. WFIFOW(fd,0) = 0x1d3;
  7941. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7942. WFIFOB(fd,26) = type;
  7943. WFIFOL(fd,27) = 0;
  7944. WFIFOL(fd,31) = bl->id;
  7945. WFIFOSET(fd,packet_len(0x1d3));
  7946. }
  7947. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  7948. {
  7949. unsigned char buf[40];
  7950. nullpo_retv(bl);
  7951. WBUFW(buf,0) = 0x1d3;
  7952. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7953. WBUFB(buf,26) = type;
  7954. WBUFL(buf,27) = 0;
  7955. WBUFL(buf,31) = bl->id;
  7956. clif_send(buf, packet_len(0x1d3), bl, coverage);
  7957. }
  7958. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7959. /// 01f3 <id>.L <effect id>.L
  7960. /// effect id:
  7961. /// @see doc/effect_list.txt
  7962. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  7963. {
  7964. unsigned char buf[24];
  7965. nullpo_retv(bl);
  7966. memset(buf, 0, packet_len(0x1f3));
  7967. WBUFW(buf,0) = 0x1f3;
  7968. WBUFL(buf,2) = bl->id;
  7969. WBUFL(buf,6) = type;
  7970. clif_send(buf, packet_len(0x1f3), bl, target);
  7971. if (disguised(bl)) {
  7972. WBUFL(buf,2) = -bl->id;
  7973. clif_send(buf, packet_len(0x1f3), bl, SELF);
  7974. }
  7975. }
  7976. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  7977. {
  7978. WFIFOHEAD(fd,10);
  7979. WFIFOW(fd,0) = 0x1f3;
  7980. WFIFOL(fd,2) = bl->id;
  7981. WFIFOL(fd,6) = type;
  7982. WFIFOSET(fd,10);
  7983. }
  7984. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  7985. /// 0284 <id>.L <effect id>.L <num data>.L
  7986. /// effect id:
  7987. /// @see doc/effect_list.txt
  7988. /// num data:
  7989. /// effect-dependent value
  7990. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  7991. {
  7992. uint8 buf[14];
  7993. WBUFW(buf,0) = 0x284;
  7994. WBUFL(buf,2) = bl->id;
  7995. WBUFL(buf,6) = effect_id;
  7996. WBUFL(buf,10) = num;
  7997. clif_send(buf, packet_len(0x284), bl, target);
  7998. if( disguised(bl) )
  7999. {
  8000. WBUFL(buf,2) = -bl->id;
  8001. clif_send(buf, packet_len(0x284), bl, SELF);
  8002. }
  8003. }
  8004. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8005. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8006. void clif_messagecolor_target(struct block_list *bl, unsigned long color, const char *msg, bool rgb2bgr, enum send_target type, struct map_session_data *sd) {
  8007. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8008. uint8 buf[CHAT_SIZE_MAX];
  8009. nullpo_retv(bl);
  8010. if (msg_len > sizeof(buf) - 12) {
  8011. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8012. msg_len = sizeof(buf) - 12;
  8013. }
  8014. if (rgb2bgr)
  8015. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8016. WBUFW(buf,0) = 0x2C1;
  8017. WBUFW(buf,2) = msg_len + 12;
  8018. WBUFL(buf,4) = bl->id;
  8019. WBUFL(buf,8) = color;
  8020. memcpy(WBUFCP(buf,12), msg, msg_len);
  8021. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8022. }
  8023. /**
  8024. * Notifies the client that the storage window is still open
  8025. *
  8026. * Should only be used in cases where the client closed the
  8027. * storage window without server's consent
  8028. */
  8029. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8030. // Notify the client that the storage is open
  8031. if( sd->state.storage_flag == 1 ) {
  8032. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8033. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8034. clif_updatestorageamount(sd, sd->storage.amount, MAX_STORAGE);
  8035. }
  8036. // Notify the client that the gstorage is open otherwise it will
  8037. // remain locked forever and nobody will be able to access it
  8038. if( sd->state.storage_flag == 2 ) {
  8039. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8040. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8041. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8042. else {
  8043. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8044. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8045. clif_updatestorageamount(sd, gstor->amount, MAX_GUILD_STORAGE);
  8046. }
  8047. }
  8048. }
  8049. // refresh the client's screen, getting rid of any effects
  8050. void clif_refresh(struct map_session_data *sd)
  8051. {
  8052. nullpo_retv(sd);
  8053. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8054. clif_inventorylist(sd);
  8055. if(pc_iscarton(sd)) {
  8056. clif_cartlist(sd);
  8057. clif_updatestatus(sd,SP_CARTINFO);
  8058. }
  8059. clif_updatestatus(sd,SP_WEIGHT);
  8060. clif_updatestatus(sd,SP_MAXWEIGHT);
  8061. clif_updatestatus(sd,SP_STR);
  8062. clif_updatestatus(sd,SP_AGI);
  8063. clif_updatestatus(sd,SP_VIT);
  8064. clif_updatestatus(sd,SP_INT);
  8065. clif_updatestatus(sd,SP_DEX);
  8066. clif_updatestatus(sd,SP_LUK);
  8067. if (sd->spiritball)
  8068. clif_spiritball_single(sd->fd, sd);
  8069. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8070. clif_spiritcharm_single(sd->fd, sd);
  8071. if (sd->vd.cloth_color)
  8072. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8073. if (sd->vd.body_style)
  8074. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8075. if(hom_is_active(sd->hd))
  8076. clif_send_homdata(sd,SP_ACK,0);
  8077. if( sd->md ) {
  8078. clif_mercenary_info(sd);
  8079. clif_mercenary_skillblock(sd);
  8080. }
  8081. if( sd->ed )
  8082. clif_elemental_info(sd);
  8083. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8084. clif_weather_check(sd);
  8085. if( sd->chatID )
  8086. chat_leavechat(sd,0);
  8087. if( sd->state.vending )
  8088. clif_openvending(sd, sd->bl.id, sd->vending);
  8089. if( pc_issit(sd) )
  8090. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8091. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8092. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8093. else
  8094. clif_changed_dir(&sd->bl, SELF);
  8095. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8096. //Issue #2143
  8097. //Cancel Trading State
  8098. if (sd->state.trading)
  8099. trade_tradecancel(sd);
  8100. //Cancel Buying/Selling State
  8101. if (sd->state.buyingstore)
  8102. buyingstore_close(sd);
  8103. mail_clear(sd);
  8104. if( disguised(&sd->bl) ) {/* refresh-da */
  8105. short disguise = sd->disguise;
  8106. pc_disguise(sd, 0);
  8107. pc_disguise(sd, disguise);
  8108. }
  8109. clif_refresh_storagewindow(sd);
  8110. }
  8111. /// Updates the object's (bl) name on client.
  8112. /// Used to update when a char leaves a party/guild. [Skotlex]
  8113. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8114. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8115. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8116. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8117. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8118. unsigned char buf[106];
  8119. int cmd = 0x95;
  8120. nullpo_retv(src);
  8121. nullpo_retv(bl);
  8122. WBUFW(buf,0) = cmd;
  8123. WBUFL(buf,2) = bl->id;
  8124. switch( bl->type )
  8125. {
  8126. case BL_PC:
  8127. {
  8128. struct map_session_data *sd = (struct map_session_data *)bl;
  8129. struct party_data *p = NULL;
  8130. #if PACKETVER >= 20150513
  8131. WBUFW(buf, 0) = cmd = 0xa30;
  8132. #else
  8133. WBUFW(buf, 0) = cmd = 0x195;
  8134. #endif
  8135. //Requesting your own "shadow" name. [Skotlex]
  8136. if( src == bl && target == SELF && sd->disguise ){
  8137. WBUFL(buf,2) = -bl->id;
  8138. }
  8139. if( sd->fakename[0] ) {
  8140. safestrncpy(WBUFCP(buf,6), sd->fakename, NAME_LENGTH);
  8141. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  8142. #if PACKETVER >= 20150513
  8143. WBUFL(buf,102) = 0; // Title ID
  8144. #endif
  8145. break;
  8146. }
  8147. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  8148. if( sd->status.party_id ){
  8149. p = party_search(sd->status.party_id);
  8150. }
  8151. // do not display party unless the player is also in a guild
  8152. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8153. safestrncpy(WBUFCP(buf,30), p->party.name, NAME_LENGTH);
  8154. }else{
  8155. WBUFB(buf,30) = 0;
  8156. }
  8157. if( sd->guild ){
  8158. int position;
  8159. // Will get the position of the guild the player is in
  8160. position = guild_getposition(sd);
  8161. safestrncpy(WBUFCP(buf,54), sd->guild->name,NAME_LENGTH);
  8162. safestrncpy(WBUFCP(buf,78), sd->guild->position[position].name, NAME_LENGTH);
  8163. }else{ //Assume no guild.
  8164. WBUFB(buf,54) = 0;
  8165. WBUFB(buf,78) = 0;
  8166. }
  8167. #if PACKETVER >= 20150513
  8168. WBUFL(buf,102) = sd->status.title_id; // Title ID
  8169. #endif
  8170. }
  8171. break;
  8172. //[blackhole89]
  8173. case BL_HOM:
  8174. safestrncpy(WBUFCP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  8175. break;
  8176. case BL_MER:
  8177. safestrncpy(WBUFCP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  8178. break;
  8179. case BL_PET:
  8180. safestrncpy(WBUFCP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  8181. break;
  8182. case BL_NPC:
  8183. safestrncpy(WBUFCP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  8184. break;
  8185. case BL_MOB:
  8186. {
  8187. struct mob_data *md = (struct mob_data *)bl;
  8188. nullpo_retv(md);
  8189. safestrncpy(WBUFCP(buf,6), md->name, NAME_LENGTH);
  8190. if( md->guardian_data && md->guardian_data->guild_id )
  8191. {
  8192. #if PACKETVER >= 20150513
  8193. WBUFW(buf, 0) = cmd = 0xa30;
  8194. #else
  8195. WBUFW(buf, 0) = cmd = 0x195;
  8196. #endif
  8197. WBUFB(buf,30) = 0;
  8198. safestrncpy(WBUFCP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  8199. safestrncpy(WBUFCP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  8200. }
  8201. else if( battle_config.show_mob_info )
  8202. {
  8203. char mobhp[50], *str_p = mobhp;
  8204. #if PACKETVER >= 20150513
  8205. WBUFW(buf, 0) = cmd = 0xa30;
  8206. #else
  8207. WBUFW(buf, 0) = cmd = 0x195;
  8208. #endif
  8209. if( battle_config.show_mob_info&4 )
  8210. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  8211. if( battle_config.show_mob_info&1 )
  8212. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  8213. if( battle_config.show_mob_info&2 )
  8214. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  8215. //Even thought mobhp ain't a name, we send it as one so the client
  8216. //can parse it. [Skotlex]
  8217. if( str_p != mobhp )
  8218. {
  8219. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8220. safestrncpy(WBUFCP(buf,30), mobhp, NAME_LENGTH);
  8221. WBUFB(buf,54) = 0;
  8222. WBUFB(buf,78) = 0;
  8223. }
  8224. }
  8225. #if PACKETVER >= 20150513
  8226. WBUFL(buf, 102) = 0; // Title ID
  8227. #endif
  8228. }
  8229. break;
  8230. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  8231. // safestrncpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  8232. // break;
  8233. return;
  8234. case BL_ELEM:
  8235. safestrncpy(WBUFCP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  8236. break;
  8237. default:
  8238. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8239. return;
  8240. }
  8241. clif_send(buf, packet_len(cmd), src, target);
  8242. }
  8243. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8244. /// 01ff <id>.L <x>.W <y>.W
  8245. ///
  8246. /// Visually moves(instant) a character to x,y. The char moves even
  8247. /// when the target cell isn't walkable. If the char is sitting it
  8248. /// stays that way.
  8249. void clif_slide(struct block_list *bl, int x, int y)
  8250. {
  8251. unsigned char buf[10];
  8252. nullpo_retv(bl);
  8253. WBUFW(buf, 0) = 0x01ff;
  8254. WBUFL(buf, 2) = bl->id;
  8255. WBUFW(buf, 6) = x;
  8256. WBUFW(buf, 8) = y;
  8257. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8258. if( disguised(bl) )
  8259. {
  8260. WBUFL(buf,2) = -bl->id;
  8261. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8262. }
  8263. }
  8264. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8265. /// 008d <packet len>.W <id>.L <message>.?B
  8266. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8267. {
  8268. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8269. int len_mes = strlen(mes)+1; //Account for \0
  8270. if (len_mes > sizeof(buf)-8) {
  8271. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8272. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8273. }
  8274. // send message to others
  8275. if (flag == AREA) {
  8276. WBUFW(buf,0) = 0x8d;
  8277. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8278. WBUFL(buf,4) = bl->id;
  8279. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8280. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8281. }
  8282. // send back message to the speaker
  8283. if( bl->type == BL_PC ) {
  8284. WBUFW(buf,0) = 0x8e;
  8285. WBUFW(buf, 2) = len_mes + 4;
  8286. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8287. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8288. }
  8289. }
  8290. /*==========================
  8291. * Minimap fix [Kevin]
  8292. * Remove dot from minimap
  8293. *--------------------------*/
  8294. void clif_party_xy_remove(struct map_session_data *sd)
  8295. {
  8296. unsigned char buf[16];
  8297. nullpo_retv(sd);
  8298. WBUFW(buf,0)=0x107;
  8299. WBUFL(buf,2)=sd->status.account_id;
  8300. WBUFW(buf,6)=-1;
  8301. WBUFW(buf,8)=-1;
  8302. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8303. }
  8304. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8305. /// 0215 <msg id>.L
  8306. /// msg id:
  8307. /// 0x15 = End all negative status (PA_GOSPEL)
  8308. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8309. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8310. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8311. /// 0x19 = All stats +20 (PA_GOSPEL)
  8312. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8313. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8314. /// 0x1e = DEF +25% (PA_GOSPEL)
  8315. /// 0x1f = ATK +100% (PA_GOSPEL)
  8316. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8317. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8318. /// ? = nothing
  8319. void clif_gospel_info(struct map_session_data *sd, int type)
  8320. {
  8321. int fd=sd->fd;
  8322. WFIFOHEAD(fd,packet_len(0x215));
  8323. WFIFOW(fd,0)=0x215;
  8324. WFIFOL(fd,2)=type;
  8325. WFIFOSET(fd, packet_len(0x215));
  8326. }
  8327. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8328. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8329. /// result:
  8330. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8331. /// star:
  8332. /// 0 = Place of the Sun
  8333. /// 1 = Place of the Moon
  8334. /// 2 = Place of the Stars
  8335. /// 1 = Star Gladiator %s's %s: <mapname>
  8336. /// star:
  8337. /// 0 = Place of the Sun
  8338. /// 1 = Place of the Moon
  8339. /// 2 = Place of the Stars
  8340. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8341. /// star:
  8342. /// 0 = Target of the Sun
  8343. /// 1 = Target of the Moon
  8344. /// 2 = Target of the Stars
  8345. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8346. /// star:
  8347. /// 0 = Monster of the Sun
  8348. /// 1 = Monster of the Moon
  8349. /// 2 = Monster of the Stars
  8350. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8351. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8352. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8353. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8354. /// 40 = Target HP : <monster_id used as HP>
  8355. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8356. {
  8357. int fd = sd->fd;
  8358. WFIFOHEAD(fd,packet_len(0x20e));
  8359. WFIFOW(fd,0) = 0x20e;
  8360. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8361. WFIFOL(fd,26) = monster_id;
  8362. WFIFOB(fd,30) = star;
  8363. WFIFOB(fd,31) = result;
  8364. WFIFOSET(fd,packet_len(0x20e));
  8365. }
  8366. /*==========================================
  8367. * Info about Star Glaldiator save map [Komurka]
  8368. * type: 1: Information, 0: Map registered
  8369. *------------------------------------------*/
  8370. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8371. {
  8372. char mapname[MAP_NAME_LENGTH_EXT];
  8373. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8374. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8375. }
  8376. /*==========================================
  8377. * Info about Star Glaldiator hate mob [Komurka]
  8378. * type: 1: Register mob, 0: Information.
  8379. *------------------------------------------*/
  8380. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8381. {
  8382. if( pcdb_checkid(class_) ) {
  8383. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8384. } else if( mobdb_checkid(class_) ) {
  8385. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  8386. } else {
  8387. ShowWarning("clif_hate_info: Received invalid class %d for this packet (char_id=%d, hate_level=%u, type=%u).\n", class_, sd->status.char_id, (unsigned int)hate_level, (unsigned int)type);
  8388. }
  8389. }
  8390. /*==========================================
  8391. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8392. *------------------------------------------*/
  8393. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8394. {
  8395. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  8396. }
  8397. /*==========================================
  8398. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8399. *------------------------------------------*/
  8400. void clif_feel_hate_reset(struct map_session_data *sd)
  8401. {
  8402. clif_starskill(sd, "", 0, 0, 30);
  8403. }
  8404. /// Equip window (un)tick ack (ZC_CONFIG).
  8405. /// 02d9 <type>.L <value>.L
  8406. /// type:
  8407. /// 0 = open equip window
  8408. /// value:
  8409. /// 0 = disabled
  8410. /// 1 = enabled
  8411. void clif_equiptickack(struct map_session_data* sd, int flag)
  8412. {
  8413. int fd;
  8414. nullpo_retv(sd);
  8415. fd = sd->fd;
  8416. WFIFOHEAD(fd, packet_len(0x2d9));
  8417. WFIFOW(fd, 0) = 0x2d9;
  8418. WFIFOL(fd, 2) = 0;
  8419. WFIFOL(fd, 6) = flag;
  8420. WFIFOSET(fd, packet_len(0x2d9));
  8421. }
  8422. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8423. /// 02da <open equip window>.B
  8424. /// open equip window:
  8425. /// 0 = disabled
  8426. /// 1 = enabled
  8427. void clif_equipcheckbox(struct map_session_data* sd)
  8428. {
  8429. int fd;
  8430. nullpo_retv(sd);
  8431. fd = sd->fd;
  8432. WFIFOHEAD(fd, packet_len(0x2da));
  8433. WFIFOW(fd, 0) = 0x2da;
  8434. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8435. WFIFOSET(fd, packet_len(0x2da));
  8436. }
  8437. /// Sends info about a player's equipped items.
  8438. /// 02d7 <packet len>.W <name>.24B <class>.W <hairstyle>.W <up-viewid>.W <mid-viewid>.W <low-viewid>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.26B* (ZC_EQUIPWIN_MICROSCOPE)
  8439. /// 02d7 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.28B* (ZC_EQUIPWIN_MICROSCOPE, PACKETVER >= 20100629)
  8440. /// 0859 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.28B* (ZC_EQUIPWIN_MICROSCOPE2, PACKETVER >= 20101124)
  8441. /// 0859 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <robe>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.28B* (ZC_EQUIPWIN_MICROSCOPE2, PACKETVER >= 20110111)
  8442. /// 0997 <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <robe>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.31B* (ZC_EQUIPWIN_MICROSCOPE_V5, PACKETVER >= 20120925)
  8443. /// 0a2d <packet len>.W <name>.24B <class>.W <hairstyle>.W <bottom-viewid>.W <mid-viewid>.W <up-viewid>.W <robe>.W <haircolor>.W <cloth-dye>.W <gender>.B {equip item}.57B* (ZC_EQUIPWIN_MICROSCOPE_V6, PACKETVER >= 20150225)
  8444. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  8445. {
  8446. uint8* buf;
  8447. int i, n, fd, offset = 0;
  8448. #if PACKETVER < 20100629
  8449. const int s = 26;
  8450. #elif PACKETVER < 20120925
  8451. const int s = 28;
  8452. #elif PACKETVER < 20150225
  8453. const int s = 31;
  8454. #else
  8455. const int s = 57;
  8456. #endif
  8457. nullpo_retv(sd);
  8458. nullpo_retv(tsd);
  8459. fd = sd->fd;
  8460. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  8461. buf = WFIFOP(fd,0);
  8462. #if PACKETVER < 20101124
  8463. WBUFW(buf, 0) = 0x2d7;
  8464. #elif PACKETVER < 20120925
  8465. WBUFW(buf, 0) = 0x859;
  8466. #elif PACKETVER < 20150225
  8467. WBUFW(buf, 0) = 0x997;
  8468. #else
  8469. WBUFW(buf, 0) = 0xa2d;
  8470. #endif
  8471. safestrncpy(WBUFCP(buf, 4), tsd->status.name, NAME_LENGTH);
  8472. WBUFW(buf,28) = tsd->status.class_;
  8473. WBUFW(buf,30) = tsd->vd.hair_style;
  8474. WBUFW(buf,32) = tsd->vd.head_bottom;
  8475. WBUFW(buf,34) = tsd->vd.head_mid;
  8476. WBUFW(buf,36) = tsd->vd.head_top;
  8477. #if PACKETVER >= 20110111
  8478. WBUFW(buf,38) = tsd->vd.robe;
  8479. offset+= 2;
  8480. buf = WBUFP(buf,2);
  8481. #endif
  8482. WBUFW(buf,38) = tsd->vd.hair_color;
  8483. WBUFW(buf,40) = tsd->vd.cloth_color;
  8484. WBUFB(buf,42) = tsd->vd.sex;
  8485. for(i=0,n=0; i < MAX_INVENTORY; i++)
  8486. {
  8487. if (tsd->inventory.u.items_inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  8488. continue;
  8489. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  8490. continue;
  8491. // Add item info : refine, identify flag, element, etc.
  8492. clif_item_sub(WBUFP(buf,0), n*s+43,i + 2, &tsd->inventory.u.items_inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  8493. n++;
  8494. }
  8495. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  8496. WFIFOSET(fd, WFIFOW(fd, 2));
  8497. }
  8498. /// Display msgstringtable.txt string (ZC_MSG).
  8499. /// 0291 <message>.W
  8500. void clif_msg(struct map_session_data* sd, unsigned short id)
  8501. {
  8502. int fd;
  8503. nullpo_retv(sd);
  8504. fd = sd->fd;
  8505. WFIFOHEAD(fd, packet_len(0x291));
  8506. WFIFOW(fd, 0) = 0x291;
  8507. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8508. WFIFOSET(fd, packet_len(0x291));
  8509. }
  8510. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8511. /// 0x7e2 <message>.W <value>.L
  8512. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8513. {
  8514. int fd = sd->fd;
  8515. WFIFOHEAD(fd, packet_len(0x7e2));
  8516. WFIFOW(fd,0) = 0x7e2;
  8517. WFIFOW(fd,2) = id;
  8518. WFIFOL(fd,4) = value;
  8519. WFIFOSET(fd, packet_len(0x7e2));
  8520. }
  8521. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8522. /// 07e6 <skill id>.W <msg id>.L
  8523. ///
  8524. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8525. /// "[SkillName] Message"
  8526. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8527. {
  8528. int fd = sd->fd;
  8529. WFIFOHEAD(fd, packet_len(0x7e6));
  8530. WFIFOW(fd,0) = 0x7e6;
  8531. WFIFOW(fd,2) = skill_id;
  8532. WFIFOL(fd,4) = msg_id;
  8533. WFIFOSET(fd, packet_len(0x7e6));
  8534. }
  8535. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8536. /// Returns true if the packet was parsed successfully.
  8537. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8538. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8539. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8540. const char* seperator = " : ";
  8541. int fd;
  8542. struct s_packet_db* info;
  8543. uint16 packetLength, inputLength;
  8544. const char *input, *name, *message;
  8545. size_t nameLength, messageLength;
  8546. fd = sd->fd;
  8547. info = &packet_db[RFIFOW(fd,0)];
  8548. packetLength = RFIFOW(fd,info->pos[0]);
  8549. input = RFIFOCP(fd,info->pos[1]);
  8550. // basic structure check for the 4-byte header
  8551. if( packetLength < 4 ){
  8552. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8553. return false;
  8554. }else{
  8555. inputLength = packetLength - 4;
  8556. }
  8557. // process <name> part of the packet
  8558. if( whisperFormat ) {
  8559. // name has fixed width
  8560. if( inputLength < NAME_LENGTH + 1 ) {
  8561. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8562. return false;
  8563. }
  8564. name = input;
  8565. // validate name
  8566. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8567. // only restriction is that the name must be zero-terminated
  8568. if( name[nameLength] != '\0' ) {
  8569. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8570. return false;
  8571. }
  8572. message = input + NAME_LENGTH;
  8573. messageLength = inputLength - NAME_LENGTH;
  8574. }else{
  8575. // name and message are separated by ' : '
  8576. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8577. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8578. // check if there's enough data provided
  8579. if( inputLength < nameLength + seperatorLength + 1 ){
  8580. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8581. return false;
  8582. }
  8583. name = input;
  8584. // validate name
  8585. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8586. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8587. {
  8588. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8589. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8590. set_eof(sd->fd); // Just kick them out to correct it.
  8591. return false;
  8592. }
  8593. message = input + nameLength + seperatorLength;
  8594. messageLength = inputLength - nameLength - seperatorLength;
  8595. }
  8596. #if PACKETVER < 20151001
  8597. // the declared length must match real length
  8598. if( messageLength != strnlen(message, messageLength)+1 ) {
  8599. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8600. return false;
  8601. }
  8602. // verify <message> part of the packet
  8603. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8604. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8605. return false;
  8606. }
  8607. #else
  8608. // No zero termination anymore
  8609. messageLength += 1;
  8610. #endif
  8611. // messages mustn't be too long
  8612. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8613. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8614. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8615. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8616. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8617. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8618. return false;
  8619. }
  8620. // If it is not a whisper message, set the name to the fakename of the player
  8621. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8622. strcpy( out_name, sd->fakename );
  8623. }else{
  8624. safestrncpy( out_name, name, nameLength + 1 );
  8625. }
  8626. safestrncpy( out_message, message, messageLength );
  8627. if( whisperFormat ){
  8628. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8629. out_full_message[nameLength] = '\0';
  8630. }else{
  8631. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8632. }
  8633. if( is_atcommand( fd, sd, out_message, 1 ) )
  8634. return false;
  8635. if (sd->sc.cant.chat)
  8636. return false; //no "chatting" while muted.
  8637. if( battle_config.min_chat_delay ) { //[Skotlex]
  8638. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8639. return false;
  8640. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8641. }
  8642. if (battle_config.idletime_option&IDLE_CHAT)
  8643. sd->idletime = last_tick;
  8644. return true;
  8645. }
  8646. /**
  8647. * Displays a message if the player enters a PK Zone (during pk_mode)
  8648. * @param sd: Player data
  8649. */
  8650. inline void clif_pk_mode_message(struct map_session_data * sd)
  8651. {
  8652. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8653. sd && map[sd->bl.m].flag.pvp) {
  8654. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8655. char output[CHAT_SIZE_MAX];
  8656. // 1504: You've entered a PK Zone (safe until level %d).
  8657. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8658. battle_config.pk_min_level);
  8659. clif_showscript(&sd->bl, output, SELF);
  8660. } else {
  8661. // 1503: You've entered a PK Zone.
  8662. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8663. }
  8664. }
  8665. return;
  8666. }
  8667. // ---------------------
  8668. // clif_parse_wanttoconnect
  8669. // ---------------------
  8670. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8671. // error codes:
  8672. // 0 - Success
  8673. // 1 - Unknown packet_ver
  8674. // 2 - Invalid account_id
  8675. // 3 - Invalid char_id
  8676. // 4 - Invalid login_id1 (reserved)
  8677. // 5 - Invalid client_tick (reserved)
  8678. // 6 - Invalid sex
  8679. // Only the first 'invalid' error that appears is used.
  8680. static int clif_parse_WantToConnection_sub(int fd)
  8681. {
  8682. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8683. unsigned short cmd;
  8684. //By default, start searching on the default one.
  8685. cmd = RFIFOW(fd, 0);
  8686. packet_len = RFIFOREST(fd);
  8687. // FIXME: If the packet is not received at once, this will FAIL.
  8688. // Figure out, when it happens, that only part of the packet is
  8689. // received, or fix the function to be able to deal with that
  8690. // case.
  8691. if( packet_len != packet_db[cmd].len )
  8692. return 1; /* wrong length */
  8693. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8694. return 2; /* invalid account_id */
  8695. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8696. return 3; /* invalid char_id */
  8697. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8698. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8699. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8700. return 6; /* invalid sex */
  8701. else
  8702. return 0;
  8703. }
  8704. /// Request to connect to map-server.
  8705. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8706. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8707. /// There are various variants of this packet, some of them have padding between fields.
  8708. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8709. {
  8710. struct block_list* bl;
  8711. struct auth_node* node;
  8712. int cmd, account_id, char_id, login_id1, sex, err;
  8713. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8714. if (sd) {
  8715. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8716. return;
  8717. }
  8718. cmd = RFIFOW(fd, 0);
  8719. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8720. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8721. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8722. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8723. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8724. err = clif_parse_WantToConnection_sub(fd);
  8725. if( err ){ // connection rejected
  8726. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8727. err == 1 ? "." :
  8728. err == 2 ? ", possibly for having an invalid account_id." :
  8729. err == 3 ? ", possibly for having an invalid char_id." :
  8730. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8731. err == 4 ? ", possibly for having an invalid login_id1." :
  8732. err == 5 ? ", possibly for having an invalid client_tick." :
  8733. */
  8734. err == 6 ? ", possibly for having an invalid sex." :
  8735. ". ERROR invalid error code"));
  8736. WFIFOHEAD(fd,packet_len(0x6a));
  8737. WFIFOW(fd,0) = 0x6a;
  8738. WFIFOB(fd,2) = err;
  8739. WFIFOSET(fd,packet_len(0x6a));
  8740. #ifdef DUMP_INVALID_PACKET
  8741. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8742. #endif
  8743. RFIFOSKIP(fd, RFIFOREST(fd));
  8744. set_eof(fd);
  8745. return;
  8746. }
  8747. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8748. clif_authfail_fd(fd,1);// server closed
  8749. return;
  8750. }
  8751. //Check for double login.
  8752. bl = map_id2bl(account_id);
  8753. if(bl && bl->type != BL_PC) {
  8754. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8755. WFIFOHEAD(fd,packet_len(0x6a));
  8756. WFIFOW(fd,0) = 0x6a;
  8757. WFIFOB(fd,2) = 3; // Rejected by server
  8758. WFIFOSET(fd,packet_len(0x6a));
  8759. set_eof(fd);
  8760. return;
  8761. }
  8762. if (bl ||
  8763. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8764. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8765. {
  8766. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8767. return;
  8768. }
  8769. CREATE(sd, TBL_PC, 1);
  8770. sd->fd = fd;
  8771. #ifdef PACKET_OBFUSCATION
  8772. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8773. #endif
  8774. session[fd]->session_data = sd;
  8775. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8776. #if PACKETVER < 20070521
  8777. WFIFOHEAD(fd,4);
  8778. WFIFOL(fd,0) = sd->bl.id;
  8779. WFIFOSET(fd,4);
  8780. #else
  8781. WFIFOHEAD(fd,packet_len(0x283));
  8782. WFIFOW(fd,0) = 0x283;
  8783. WFIFOL(fd,2) = sd->bl.id;
  8784. WFIFOSET(fd,packet_len(0x283));
  8785. #endif
  8786. chrif_authreq(sd,false);
  8787. }
  8788. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8789. /// 007d
  8790. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8791. {
  8792. bool guild_notice = false;
  8793. if(sd->bl.prev != NULL)
  8794. return;
  8795. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  8796. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  8797. //Let pc_reg_received or intif_parse_StorageReceived reinvoke this when ready.
  8798. sd->state.connect_new = 0;
  8799. return;
  8800. }
  8801. if (sd->state.rewarp) { //Rewarp player.
  8802. sd->state.rewarp = 0;
  8803. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8804. return;
  8805. }
  8806. sd->state.warping = 0;
  8807. // look
  8808. #if PACKETVER < 4
  8809. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8810. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8811. #else
  8812. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8813. #endif
  8814. pc_set_costume_view(sd);
  8815. if(sd->vd.cloth_color)
  8816. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8817. if(sd->vd.body_style)
  8818. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8819. // item
  8820. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8821. pc_checkitem(sd);
  8822. // cart
  8823. if(pc_iscarton(sd)) {
  8824. clif_cartlist(sd);
  8825. clif_updatestatus(sd,SP_CARTINFO);
  8826. }
  8827. // weight
  8828. clif_updatestatus(sd,SP_WEIGHT);
  8829. clif_updatestatus(sd,SP_MAXWEIGHT);
  8830. // guild
  8831. // (needs to go before clif_spawn() to show guild emblems correctly)
  8832. if(sd->status.guild_id)
  8833. guild_send_memberinfoshort(sd,1);
  8834. if(battle_config.pc_invincible_time > 0) {
  8835. if(map_flag_gvg(sd->bl.m))
  8836. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8837. else
  8838. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8839. }
  8840. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  8841. map_spawnmobs(sd->bl.m);
  8842. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  8843. map[sd->bl.m].users_pvp++;
  8844. }
  8845. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8846. // reset the callshop flag if the player changes map
  8847. sd->state.callshop = 0;
  8848. if(map_addblock(&sd->bl))
  8849. return;
  8850. clif_spawn(&sd->bl);
  8851. // Party
  8852. // (needs to go after clif_spawn() to show hp bars correctly)
  8853. if(sd->status.party_id) {
  8854. party_send_movemap(sd);
  8855. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8856. }
  8857. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8858. if(map[sd->bl.m].flag.pvp && !pc_isinvisible(sd)) {
  8859. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8860. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  8861. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8862. sd->pvp_rank = 0;
  8863. sd->pvp_lastusers = 0;
  8864. sd->pvp_point = 5;
  8865. sd->pvp_won = 0;
  8866. sd->pvp_lost = 0;
  8867. }
  8868. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8869. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8870. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8871. else if (map[sd->bl.m].flag.gvg_dungeon)
  8872. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  8873. else if( map_flag_gvg(sd->bl.m) )
  8874. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  8875. else
  8876. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  8877. // info about nearby objects
  8878. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8879. map_foreachinallarea(clif_getareachar, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_ALL, sd);
  8880. // pet
  8881. if( sd->pd ) {
  8882. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  8883. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8884. pet_menu(sd, 3); //Option 3 is return to egg.
  8885. } else {
  8886. if(map_addblock(&sd->pd->bl))
  8887. return;
  8888. clif_spawn(&sd->pd->bl);
  8889. clif_send_petdata(sd,sd->pd,0,0);
  8890. clif_send_petstatus(sd);
  8891. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8892. }
  8893. }
  8894. //homunculus [blackhole89]
  8895. if( hom_is_active(sd->hd) ) {
  8896. if(map_addblock(&sd->hd->bl))
  8897. return;
  8898. clif_spawn(&sd->hd->bl);
  8899. clif_send_homdata(sd,SP_ACK,0);
  8900. clif_hominfo(sd,sd->hd,1);
  8901. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8902. clif_homskillinfoblock(sd);
  8903. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  8904. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8905. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8906. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8907. }
  8908. if( sd->md ) {
  8909. if(map_addblock(&sd->md->bl))
  8910. return;
  8911. clif_spawn(&sd->md->bl);
  8912. clif_mercenary_info(sd);
  8913. clif_mercenary_skillblock(sd);
  8914. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8915. }
  8916. if( sd->ed ) {
  8917. if (map_addblock(&sd->ed->bl))
  8918. return;
  8919. clif_spawn(&sd->ed->bl);
  8920. clif_elemental_info(sd);
  8921. clif_elemental_updatestatus(sd,SP_HP);
  8922. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8923. clif_elemental_updatestatus(sd,SP_SP);
  8924. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8925. }
  8926. if(sd->state.connect_new) {
  8927. int lv;
  8928. guild_notice = true;
  8929. clif_skillinfoblock(sd);
  8930. clif_hotkeys_send(sd);
  8931. clif_updatestatus(sd,SP_BASEEXP);
  8932. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8933. clif_updatestatus(sd,SP_JOBEXP);
  8934. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8935. clif_updatestatus(sd,SP_SKILLPOINT);
  8936. clif_initialstatus(sd);
  8937. if (sd->sc.option&OPTION_FALCON)
  8938. clif_status_load(&sd->bl, SI_FALCON, 1);
  8939. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  8940. clif_status_load(&sd->bl, SI_RIDING, 1);
  8941. else if (sd->sc.option&OPTION_WUGRIDER)
  8942. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  8943. else if (sd->sc.data[SC_ALL_RIDING])
  8944. clif_status_load(&sd->bl, SI_ALL_RIDING, 1);
  8945. if(sd->status.manner < 0)
  8946. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  8947. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  8948. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  8949. if(sd->bl.m == sd->feel_map[0].m
  8950. || sd->bl.m == sd->feel_map[1].m
  8951. || sd->bl.m == sd->feel_map[2].m)
  8952. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  8953. }
  8954. if(sd->pd && sd->pd->pet.intimate > 900)
  8955. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  8956. if(hom_is_active(sd->hd))
  8957. hom_init_timers(sd->hd);
  8958. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  8959. sd->state.night = 1;
  8960. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8961. }
  8962. // Notify everyone that this char logged in [Skotlex].
  8963. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  8964. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  8965. //Login Event
  8966. npc_script_event(sd, NPCE_LOGIN);
  8967. }
  8968. } else {
  8969. //For some reason the client "loses" these on warp/map-change.
  8970. clif_updatestatus(sd,SP_STR);
  8971. clif_updatestatus(sd,SP_AGI);
  8972. clif_updatestatus(sd,SP_VIT);
  8973. clif_updatestatus(sd,SP_INT);
  8974. clif_updatestatus(sd,SP_DEX);
  8975. clif_updatestatus(sd,SP_LUK);
  8976. // abort currently running script
  8977. sd->state.using_fake_npc = 0;
  8978. sd->state.menu_or_input = 0;
  8979. sd->npc_menu = 0;
  8980. if(sd->npc_id)
  8981. npc_event_dequeue(sd);
  8982. }
  8983. if( sd->state.changemap ) {// restore information that gets lost on map-change
  8984. #if PACKETVER >= 20070918
  8985. clif_partyinvitationstate(sd);
  8986. clif_equipcheckbox(sd);
  8987. #endif
  8988. if (sd->guild && battle_config.guild_notice_changemap == 1)
  8989. clif_guild_notice(sd); // Displays after VIP
  8990. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  8991. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  8992. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  8993. if( night_flag && map[sd->bl.m].flag.nightenabled )
  8994. { //Display night.
  8995. if( !sd->state.night )
  8996. {
  8997. sd->state.night = 1;
  8998. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8999. }
  9000. }
  9001. else if( sd->state.night )
  9002. { //Clear night display.
  9003. sd->state.night = 0;
  9004. clif_status_load(&sd->bl, SI_NIGHT, 0);
  9005. }
  9006. if( map[sd->bl.m].flag.battleground )
  9007. {
  9008. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9009. if( map[sd->bl.m].flag.battleground == 2 )
  9010. clif_bg_updatescore_single(sd);
  9011. }
  9012. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  9013. {
  9014. char output[128];
  9015. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9016. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9017. }
  9018. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9019. map[sd->bl.m].hpmeter_visible++;
  9020. sd->state.hpmeter_visible = 1;
  9021. }
  9022. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9023. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9024. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9025. #ifdef VIP_ENABLE
  9026. if (!sd->state.connect_new &&
  9027. !sd->vip.disableshowrate &&
  9028. sd->state.pmap != sd->bl.m &&
  9029. map[sd->state.pmap].adjust.bexp != map[sd->bl.m].adjust.bexp
  9030. )
  9031. {
  9032. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  9033. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  9034. }
  9035. #endif
  9036. // Instances do not need their own channels
  9037. if( channel_config.map_tmpl.name != NULL && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !map[sd->bl.m].flag.chmautojoin && !map[sd->bl.m].instance_id )
  9038. channel_mjoin(sd); //join new map
  9039. clif_pk_mode_message(sd);
  9040. } else if (sd->guild && (battle_config.guild_notice_changemap == 2 || guild_notice))
  9041. clif_guild_notice(sd); // Displays at end
  9042. mail_clear(sd);
  9043. /* Guild Aura Init */
  9044. if( sd->state.gmaster_flag ) {
  9045. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9046. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9047. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9048. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9049. }
  9050. if( sd->state.vending ) { /* show we have a vending */
  9051. clif_openvending(sd,sd->bl.id,sd->vending);
  9052. clif_showvendingboard(&sd->bl,sd->message,0);
  9053. }
  9054. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9055. if(!sd->state.autotrade && map[sd->bl.m].flag.loadevent) // Lance
  9056. npc_script_event(sd, NPCE_LOADMAP);
  9057. if (pc_checkskill(sd, SG_DEVIL) && pc_is_maxjoblv(sd))
  9058. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  9059. if (sd->sc.opt2) //Client loses these on warp.
  9060. clif_changeoption(&sd->bl);
  9061. if ((sd->sc.data[SC_MONSTER_TRANSFORM] || sd->sc.data[SC_ACTIVE_MONSTER_TRANSFORM]) && battle_config.mon_trans_disable_in_gvg && map_flag_gvg2(sd->bl.m)) {
  9062. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  9063. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM, INVALID_TIMER);
  9064. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9065. }
  9066. clif_weather_check(sd);
  9067. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9068. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9069. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9070. else
  9071. sd->areanpc_id = 0;
  9072. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9073. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9074. pc_setdead(sd);
  9075. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9076. if(pc_isdead(sd))
  9077. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9078. else {
  9079. skill_usave_trigger(sd);
  9080. if (battle_config.spawn_direction)
  9081. clif_changed_dir(&sd->bl, SELF);
  9082. }
  9083. // Trigger skill effects if you appear standing on them
  9084. if(!battle_config.pc_invincible_time)
  9085. skill_unit_move(&sd->bl,gettick(),1);
  9086. pc_show_questinfo_reinit(sd);
  9087. pc_show_questinfo(sd);
  9088. #if PACKETVER >= 20150513
  9089. if( sd->mail.inbox.unread ){
  9090. clif_Mail_new(sd, 0, NULL, NULL);
  9091. }
  9092. #endif
  9093. sd->state.connect_new = 0;
  9094. sd->state.changemap = false;
  9095. }
  9096. /// Server's tick (ZC_NOTIFY_TIME).
  9097. /// 007f <time>.L
  9098. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  9099. {
  9100. int fd = sd->fd;
  9101. WFIFOHEAD(fd,packet_len(0x7f));
  9102. WFIFOW(fd,0) = 0x7f;
  9103. WFIFOL(fd,2) = time;
  9104. WFIFOSET(fd,packet_len(0x7f));
  9105. }
  9106. /// Request for server's tick.
  9107. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9108. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9109. /// There are various variants of this packet, some of them have padding between fields.
  9110. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9111. {
  9112. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9113. clif_notify_time(sd, gettick());
  9114. }
  9115. /// Sends hotkey bar.
  9116. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9117. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9118. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9119. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9120. void clif_hotkeys_send(struct map_session_data *sd) {
  9121. #ifdef HOTKEY_SAVING
  9122. const int fd = sd->fd;
  9123. int i;
  9124. int offset = 2;
  9125. #if PACKETVER < 20090603
  9126. const int cmd = 0x2b9;
  9127. #elif PACKETVER < 20141022
  9128. const int cmd = 0x7d9;
  9129. #else
  9130. char Rotate = sd->status.hotkey_rowshift;
  9131. const int cmd = 0xa00;
  9132. offset = 3;
  9133. #endif
  9134. if (!fd) return;
  9135. WFIFOHEAD(fd, offset + MAX_HOTKEYS * 7);
  9136. WFIFOW(fd, 0) = cmd;
  9137. #if PACKETVER >= 20141022
  9138. WFIFOB(fd, 2) = Rotate;
  9139. #endif
  9140. for(i = 0; i < MAX_HOTKEYS; i++) {
  9141. WFIFOB(fd, offset + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  9142. WFIFOL(fd, offset + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  9143. WFIFOW(fd, offset + 5 + i * 7) = sd->status.hotkeys[i].lv; // item qty or skill level
  9144. }
  9145. WFIFOSET(fd, packet_len(cmd));
  9146. #endif
  9147. }
  9148. /// Request to update a position on the hotkey row bar
  9149. void clif_parse_HotkeyRowShift(int fd, struct map_session_data *sd) {
  9150. int cmd = RFIFOW(fd, 0);
  9151. sd->status.hotkey_rowshift = RFIFOB(fd, packet_db[cmd].pos[0]);
  9152. }
  9153. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9154. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9155. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9156. #ifdef HOTKEY_SAVING
  9157. unsigned short idx;
  9158. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9159. idx = RFIFOW(fd, info->pos[0]);
  9160. if (idx >= MAX_HOTKEYS) return;
  9161. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  9162. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  9163. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  9164. #endif
  9165. }
  9166. /// Displays cast-like progress bar (ZC_PROGRESS).
  9167. /// 02f0 <color>.L <time>.L
  9168. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9169. {
  9170. int fd = sd->fd;
  9171. WFIFOHEAD(fd,packet_len(0x2f0));
  9172. WFIFOW(fd,0) = 0x2f0;
  9173. WFIFOL(fd,2) = color;
  9174. WFIFOL(fd,6) = second;
  9175. WFIFOSET(fd,packet_len(0x2f0));
  9176. }
  9177. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9178. /// 02f2
  9179. void clif_progressbar_abort(struct map_session_data * sd)
  9180. {
  9181. int fd = sd->fd;
  9182. WFIFOHEAD(fd,packet_len(0x2f2));
  9183. WFIFOW(fd,0) = 0x2f2;
  9184. WFIFOSET(fd,packet_len(0x2f2));
  9185. }
  9186. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  9187. /// 02f1
  9188. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  9189. {
  9190. int npc_id = sd->progressbar.npc_id;
  9191. if( gettick() < sd->progressbar.timeout && sd->st )
  9192. sd->st->state = END;
  9193. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  9194. sd->state.workinprogress = WIP_DISABLE_NONE;
  9195. npc_scriptcont(sd, npc_id, false);
  9196. }
  9197. /// Displays cast-like progress bar on a NPC
  9198. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9199. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9200. #if PACKETVER >= 20130821
  9201. unsigned char buf[14];
  9202. if( nd->progressbar.timeout > 0 ){
  9203. WBUFW(buf,0) = 0x9d1;
  9204. WBUFL(buf,2) = nd->bl.id;
  9205. WBUFL(buf,6) = nd->progressbar.color;
  9206. WBUFL(buf,10) = ( nd->progressbar.timeout - gettick() ) / 1000;
  9207. if( sd ){
  9208. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9209. }else{
  9210. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9211. }
  9212. }
  9213. #endif
  9214. }
  9215. /// Request to walk to a certain position on the current map.
  9216. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9217. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9218. /// There are various variants of this packet, some of them have padding between fields.
  9219. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9220. {
  9221. short x, y;
  9222. if (pc_isdead(sd)) {
  9223. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9224. return;
  9225. }
  9226. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9227. ; //You CAN walk on this OPT1 value.
  9228. else if (sd->progressbar.npc_id) {
  9229. clif_progressbar_abort(sd);
  9230. return; // First walk attempt cancels the progress bar
  9231. } else if (pc_cant_act(sd))
  9232. return;
  9233. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9234. return;
  9235. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9236. //A move command one cell west is only valid if the target cell is free
  9237. if(battle_config.official_cell_stack_limit > 0
  9238. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9239. return;
  9240. // Cloaking wall check is actually updated when you click to process next movement
  9241. // not when you move each cell. This is official behaviour.
  9242. if (sd->sc.data[SC_CLOAKING])
  9243. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9244. pc_delinvincibletimer(sd);
  9245. //Set last idle time... [Skotlex]
  9246. if (battle_config.idletime_option&IDLE_WALK)
  9247. sd->idletime = last_tick;
  9248. unit_walktoxy(&sd->bl, x, y, 4);
  9249. }
  9250. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9251. /// 018b <result>.W
  9252. /// result:
  9253. /// 0 = disconnect (quit)
  9254. /// 1 = cannot disconnect (wait 10 seconds)
  9255. /// ? = ignored
  9256. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9257. {
  9258. int fd = sd->fd;
  9259. WFIFOHEAD(fd,packet_len(0x18b));
  9260. WFIFOW(fd,0) = 0x18b;
  9261. WFIFOW(fd,2) = result;
  9262. WFIFOSET(fd,packet_len(0x18b));
  9263. }
  9264. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9265. /// 018a <type>.W
  9266. /// type:
  9267. /// 0 = quit
  9268. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9269. {
  9270. /* Rovert's prevent logout option fixed [Valaris] */
  9271. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9272. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] && !sd->sc.data[SC_SUHIDE] &&
  9273. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9274. {
  9275. set_eof(fd);
  9276. pc_damage_log_clear(sd,0);
  9277. clif_disconnect_ack(sd, 0);
  9278. } else {
  9279. clif_disconnect_ack(sd, 1);
  9280. }
  9281. }
  9282. /// Requesting unit's name.
  9283. /// 0094 <id>.L (CZ_REQNAME)
  9284. /// 0368 <id>.L (CZ_REQNAME2)
  9285. /// There are various variants of this packet, some of them have padding between fields.
  9286. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9287. {
  9288. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9289. struct block_list* bl;
  9290. //struct status_change *sc;
  9291. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9292. id = sd->bl.id;
  9293. bl = map_id2bl(id);
  9294. if( bl == NULL )
  9295. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9296. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9297. return; // Block namerequests past view range
  9298. // 'see people in GM hide' cheat detection
  9299. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9300. sc = status_get_sc(bl);
  9301. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9302. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9303. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9304. ) {
  9305. char gm_msg[256];
  9306. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requested the name of an invisible target (id: %d).\n", sd->status.name, sd->status.account_id, id);
  9307. ShowWarning(gm_msg);
  9308. // information is sent to all online GMs
  9309. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9310. return;
  9311. }
  9312. */
  9313. clif_name(&sd->bl,bl,SELF);
  9314. }
  9315. /// Validates and processes global messages
  9316. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9317. /// There are various variants of this packet.
  9318. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9319. {
  9320. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9321. size_t length;
  9322. // validate packet and retrieve name and message
  9323. if( !clif_process_message(sd, false, name, message, output ) )
  9324. return;
  9325. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9326. channel_send(sd->gcbind,sd,message);
  9327. return;
  9328. }
  9329. // send message to others (using the send buffer for temp. storage)
  9330. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9331. length = strlen(output) + 1;
  9332. // send back message to the speaker
  9333. WFIFOHEAD(fd,4+length);
  9334. WFIFOW(fd,0) = 0x8e;
  9335. WFIFOW(fd,2) = (uint16)(4+length);
  9336. safestrncpy(WFIFOCP(fd,4), output, length );
  9337. WFIFOSET(fd, WFIFOW(fd,2));
  9338. #ifdef PCRE_SUPPORT
  9339. // trigger listening npcs
  9340. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9341. #endif
  9342. // Chat logging type 'O' / Global Chat
  9343. log_chat(LOG_CHAT_GLOBAL, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  9344. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9345. }
  9346. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9347. /// Request to warp to a map on given coordinates.
  9348. /// 0140 <map name>.16B <x>.W <y>.W
  9349. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9350. {
  9351. char command[MAP_NAME_LENGTH_EXT+25];
  9352. char* map_name;
  9353. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9354. map_name = RFIFOCP(fd,info->pos[0]);
  9355. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9356. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9357. RFIFOW(fd,info->pos[1]), //x
  9358. RFIFOW(fd,info->pos[2])); //y
  9359. is_atcommand(fd, sd, command, 1);
  9360. }
  9361. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9362. /// 009c <id>.L <head dir>.W <dir>.B
  9363. /// head dir:
  9364. /// 0 = straight
  9365. /// 1 = turned CW
  9366. /// 2 = turned CCW
  9367. /// dir:
  9368. /// 0 = north
  9369. /// 1 = northwest
  9370. /// 2 = west
  9371. /// 3 = southwest
  9372. /// 4 = south
  9373. /// 5 = southeast
  9374. /// 6 = east
  9375. /// 7 = northeast
  9376. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9377. {
  9378. unsigned char buf[64];
  9379. WBUFW(buf,0) = 0x9c;
  9380. WBUFL(buf,2) = bl->id;
  9381. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9382. WBUFB(buf,8) = unit_getdir(bl);
  9383. clif_send(buf, packet_len(0x9c), bl, target);
  9384. if (disguised(bl)) {
  9385. WBUFL(buf,2) = -bl->id;
  9386. WBUFW(buf,6) = 0;
  9387. clif_send(buf, packet_len(0x9c), bl, SELF);
  9388. }
  9389. }
  9390. /// Request to change own body and head direction.
  9391. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9392. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9393. /// There are various variants of this packet, some of them have padding between fields.
  9394. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9395. {
  9396. unsigned char headdir, dir;
  9397. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9398. headdir = RFIFOB(fd,info->pos[0]);
  9399. dir = RFIFOB(fd,info->pos[1]);
  9400. pc_setdir(sd, dir, headdir);
  9401. clif_changed_dir(&sd->bl, AREA_WOS);
  9402. }
  9403. /// Request to show an emotion (CZ_REQ_EMOTION).
  9404. /// 00bf <type>.B
  9405. /// type:
  9406. /// @see enum emotion_type
  9407. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9408. {
  9409. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9410. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9411. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  9412. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9413. return;
  9414. }
  9415. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9416. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9417. sd->emotionlasttime = time(NULL);
  9418. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9419. return;
  9420. }
  9421. sd->emotionlasttime = time(NULL);
  9422. if (battle_config.idletime_option&IDLE_EMOTION)
  9423. sd->idletime = last_tick;
  9424. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
  9425. emoticon = rnd()%6+E_DICE1;
  9426. }
  9427. clif_emotion(&sd->bl, emoticon);
  9428. } else
  9429. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9430. }
  9431. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9432. /// 00c2 <count>.L
  9433. void clif_user_count(struct map_session_data* sd, int count)
  9434. {
  9435. int fd = sd->fd;
  9436. WFIFOHEAD(fd,packet_len(0xc2));
  9437. WFIFOW(fd,0) = 0xc2;
  9438. WFIFOL(fd,2) = count;
  9439. WFIFOSET(fd,packet_len(0xc2));
  9440. }
  9441. /// /w /who (CZ_REQ_USER_COUNT).
  9442. /// Request to display amount of currently connected players.
  9443. /// 00c1
  9444. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9445. {
  9446. clif_user_count(sd, map_getusers());
  9447. }
  9448. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  9449. {
  9450. if (pc_isdead(sd)) {
  9451. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9452. return;
  9453. }
  9454. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9455. // (not all are included in pc_can_attack)
  9456. if (sd->sc.count &&
  9457. (sd->sc.data[SC_TRICKDEAD] ||
  9458. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9459. sd->sc.data[SC_BLADESTOP] ||
  9460. sd->sc.data[SC__MANHOLE] ||
  9461. sd->sc.data[SC_SUHIDE] ))
  9462. return;
  9463. if(action_type != 0x00 && action_type != 0x07)
  9464. pc_stop_walking(sd, 1);
  9465. pc_stop_attack(sd);
  9466. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9467. target_id = sd->bl.id;
  9468. switch(action_type)
  9469. {
  9470. case 0x00: // once attack
  9471. case 0x07: // continuous attack
  9472. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9473. return;
  9474. if( sd->sc.option&OPTION_COSTUME )
  9475. return;
  9476. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9477. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9478. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9479. return;
  9480. }
  9481. }
  9482. pc_delinvincibletimer(sd);
  9483. if (battle_config.idletime_option&IDLE_ATTACK)
  9484. sd->idletime = last_tick;
  9485. unit_attack(&sd->bl, target_id, action_type != 0);
  9486. break;
  9487. case 0x02: // sitdown
  9488. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9489. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9490. break;
  9491. }
  9492. if(pc_issit(sd)) {
  9493. //Bugged client? Just refresh them.
  9494. clif_sitting(&sd->bl);
  9495. return;
  9496. }
  9497. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9498. break;
  9499. if (sd->sc.count && (
  9500. sd->sc.data[SC_DANCING] ||
  9501. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9502. )) //No sitting during these states either.
  9503. break;
  9504. if (battle_config.idletime_option&IDLE_SIT)
  9505. sd->idletime = last_tick;
  9506. pc_setsit(sd);
  9507. skill_sit(sd, 1);
  9508. clif_sitting(&sd->bl);
  9509. break;
  9510. case 0x03: // standup
  9511. if (!pc_issit(sd)) {
  9512. //Bugged client? Just refresh them.
  9513. clif_standing(&sd->bl);
  9514. return;
  9515. }
  9516. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9517. break;
  9518. if (pc_setstand(sd, false)) {
  9519. if (battle_config.idletime_option&IDLE_SIT)
  9520. sd->idletime = last_tick;
  9521. skill_sit(sd, 0);
  9522. clif_standing(&sd->bl);
  9523. }
  9524. break;
  9525. }
  9526. }
  9527. /// Request for an action.
  9528. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9529. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9530. /// action:
  9531. /// 0 = attack
  9532. /// 1 = pick up item
  9533. /// 2 = sit down
  9534. /// 3 = stand up
  9535. /// 7 = continous attack
  9536. /// 12 = (touch skill?)
  9537. /// There are various variants of this packet, some of them have padding between fields.
  9538. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9539. {
  9540. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9541. clif_parse_ActionRequest_sub(sd,
  9542. RFIFOB(fd,info->pos[1]),
  9543. RFIFOL(fd,info->pos[0]),
  9544. gettick()
  9545. );
  9546. }
  9547. /// Response to the death/system menu (CZ_RESTART).
  9548. /// 00b2 <type>.B
  9549. /// type:
  9550. /// 0 = restart (respawn)
  9551. /// 1 = char-select (disconnect)
  9552. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9553. {
  9554. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9555. case 0x00:
  9556. pc_respawn(sd,CLR_OUTSIGHT);
  9557. break;
  9558. case 0x01:
  9559. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9560. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] && !sd->sc.data[SC_CLOAKINGEXCEED] && !sd->sc.data[SC_SUHIDE] &&
  9561. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9562. { //Send to char-server for character selection.
  9563. pc_damage_log_clear(sd,0);
  9564. chrif_charselectreq(sd, session[fd]->client_addr);
  9565. } else {
  9566. clif_disconnect_ack(sd, 1);
  9567. }
  9568. break;
  9569. }
  9570. }
  9571. /// Validates and processes whispered messages (CZ_WHISPER).
  9572. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9573. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9574. {
  9575. struct map_session_data* dstsd;
  9576. int i;
  9577. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9578. // validate packet and retrieve name and message
  9579. if( !clif_process_message( sd, true, target, message, output ) )
  9580. return;
  9581. // Chat logging type 'W' / Whisper
  9582. log_chat(LOG_CHAT_WHISPER, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
  9583. //-------------------------------------------------------//
  9584. // Lordalfa - Paperboy - To whisper NPC commands //
  9585. //-------------------------------------------------------//
  9586. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9587. {
  9588. char* str = target+4; //Skip the NPC: string part.
  9589. struct npc_data* npc;
  9590. if ((npc = npc_name2id(str))) {
  9591. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9592. char *split;
  9593. char event[EVENT_NAME_LENGTH];
  9594. str = message;
  9595. // skip codepage indicator, if detected
  9596. if( str[0] == '|' && strlen(str) >= 4 )
  9597. str += 3;
  9598. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9599. split = strchr(str,'#');
  9600. if( split == NULL ) { // use the remaining string
  9601. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9602. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9603. split_data[i][0] = '\0';
  9604. break;
  9605. }
  9606. *split = '\0';
  9607. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9608. str = split+1;
  9609. }
  9610. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9611. char variablename[CHAT_SIZE_MAX];
  9612. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9613. set_var(sd,variablename,(char *) split_data[i]);
  9614. }
  9615. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9616. npc_event(sd,event,0); // Calls the NPC label
  9617. return;
  9618. }
  9619. } else if( target[0] == '#' ) {
  9620. struct Channel *channel = NULL;
  9621. char* chname = target;
  9622. channel = channel_name2channel(chname,sd,3);
  9623. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9624. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9625. channel_send(channel,sd,message);
  9626. }
  9627. else if( channel->pass[0] == '\0') { //no pass needed
  9628. if (channel_join(channel,sd)==0)
  9629. channel_send(channel,sd,message); //join success
  9630. }
  9631. else {
  9632. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9633. }
  9634. return;
  9635. }
  9636. }
  9637. // searching destination character
  9638. dstsd = map_nick2sd(target,false);
  9639. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9640. // player is not on this map-server
  9641. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9642. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9643. // and if we ask for 'Test', we must not contact 'test' player
  9644. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9645. intif_wis_message(sd, target, message, strlen(message));
  9646. return;
  9647. }
  9648. // if player ignores everyone
  9649. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9650. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9651. clif_wis_end(fd, 1); // 1: target character is not logged in
  9652. else
  9653. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9654. return;
  9655. }
  9656. // if player is autotrading
  9657. if (dstsd->state.autotrade == 1){
  9658. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9659. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  9660. return;
  9661. }
  9662. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9663. // if player ignores the source character
  9664. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9665. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9666. clif_wis_end(fd, 2); // 2: ignored by target
  9667. return;
  9668. }
  9669. }
  9670. // notify sender of success
  9671. clif_wis_end(fd, 0); // 0: success to send wisper
  9672. // Normal message
  9673. clif_wis_message(dstsd->fd, sd->status.name, message, strlen(message)+1 );
  9674. }
  9675. /// /b /nb (CZ_BROADCAST).
  9676. /// Request to broadcast a message on whole server.
  9677. /// 0099 <packet len>.W <text>.?B 00
  9678. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9679. char command[CHAT_SIZE_MAX+11];
  9680. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9681. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9682. char* msg = RFIFOCP(fd,info->pos[1]);
  9683. // as the length varies depending on the command used, just block unreasonably long strings
  9684. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9685. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9686. is_atcommand(fd, sd, command, 1);
  9687. }
  9688. /// Request to pick up an item.
  9689. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9690. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9691. /// There are various variants of this packet, some of them have padding between fields.
  9692. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9693. {
  9694. struct flooritem_data *fitem;
  9695. int map_object_id;
  9696. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9697. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9698. do {
  9699. if (pc_isdead(sd)) {
  9700. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9701. break;
  9702. }
  9703. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9704. break;
  9705. if (pc_cant_act(sd))
  9706. break;
  9707. if (!pc_takeitem(sd, fitem))
  9708. break;
  9709. return;
  9710. } while (0);
  9711. // Client REQUIRES a fail packet or you can no longer pick items.
  9712. clif_additem(sd,0,0,6);
  9713. }
  9714. /// Request to drop an item.
  9715. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9716. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9717. /// There are various variants of this packet, some of them have padding between fields.
  9718. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9719. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9720. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9721. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9722. for(;;) {
  9723. if (pc_isdead(sd))
  9724. break;
  9725. if (pc_cant_act2(sd) || sd->npc_id)
  9726. break;
  9727. if (sd->sc.count && (
  9728. sd->sc.data[SC_AUTOCOUNTER] ||
  9729. sd->sc.data[SC_BLADESTOP] ||
  9730. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9731. ))
  9732. break;
  9733. if (!pc_dropitem(sd, item_index, item_amount))
  9734. break;
  9735. if (battle_config.idletime_option&IDLE_DROPITEM)
  9736. sd->idletime = last_tick;
  9737. return;
  9738. }
  9739. //Because the client does not like being ignored.
  9740. clif_dropitem(sd, item_index,0);
  9741. }
  9742. /// Request to use an item.
  9743. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9744. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9745. /// There are various variants of this packet, some of them have padding between fields.
  9746. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9747. {
  9748. int n;
  9749. if (pc_isdead(sd)) {
  9750. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9751. return;
  9752. }
  9753. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9754. return;
  9755. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9756. if (battle_config.idletime_option&IDLE_USEITEM)
  9757. sd->idletime = last_tick;
  9758. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9759. if(n <0 || n >= MAX_INVENTORY)
  9760. return;
  9761. if (!pc_useitem(sd,n))
  9762. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9763. }
  9764. /// Request to equip an item
  9765. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9766. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9767. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9768. {
  9769. int index;
  9770. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9771. if(pc_isdead(sd)) {
  9772. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9773. return;
  9774. }
  9775. index = RFIFOW(fd,info->pos[0])-2;
  9776. if (index < 0 || index >= MAX_INVENTORY)
  9777. return; //Out of bounds check.
  9778. if(sd->npc_id && !sd->npc_item_flag) {
  9779. return;
  9780. } else if (sd->state.storage_flag || sd->sc.opt1)
  9781. ; //You can equip/unequip stuff while storage is open/under status changes
  9782. else if (pc_cant_act2(sd))
  9783. return;
  9784. if(!sd->inventory.u.items_inventory[index].identify) {
  9785. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9786. return;
  9787. }
  9788. if(!sd->inventory_data[index])
  9789. return;
  9790. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9791. pet_equipitem(sd,index);
  9792. return;
  9793. }
  9794. if (battle_config.idletime_option&IDLE_USEITEM)
  9795. sd->idletime = last_tick;
  9796. //Client doesn't send the position for ammo.
  9797. if(sd->inventory_data[index]->type == IT_AMMO)
  9798. pc_equipitem(sd,index,EQP_AMMO);
  9799. else {
  9800. int req_pos;
  9801. #if PACKETVER >= 20120925
  9802. req_pos = RFIFOL(fd,info->pos[1]);
  9803. #else
  9804. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9805. #endif
  9806. pc_equipitem(sd,index,req_pos);
  9807. }
  9808. }
  9809. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9810. /// 00ab <index>.W
  9811. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9812. {
  9813. int index;
  9814. if(pc_isdead(sd)) {
  9815. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9816. return;
  9817. }
  9818. if (sd->npc_id && !sd->npc_item_flag) {
  9819. return;
  9820. } else if (sd->state.storage_flag || sd->sc.opt1)
  9821. ; //You can equip/unequip stuff while storage is open/under status changes
  9822. else if (pc_cant_act2(sd))
  9823. return;
  9824. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9825. if (battle_config.idletime_option&IDLE_USEITEM)
  9826. sd->idletime = last_tick;
  9827. pc_unequipitem(sd,index,1);
  9828. }
  9829. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9830. /// 0090 <id>.L <type>.B
  9831. /// type:
  9832. /// 1 = click
  9833. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9834. {
  9835. struct block_list *bl;
  9836. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9837. if(pc_isdead(sd)) {
  9838. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9839. return;
  9840. }
  9841. #ifdef RENEWAL
  9842. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_NPC)) {
  9843. clif_msg(sd, WORK_IN_PROGRESS);
  9844. return;
  9845. }
  9846. #endif
  9847. if (pc_cant_act2(sd) || sd->npc_id)
  9848. return;
  9849. if( sd->state.mail_writing )
  9850. return;
  9851. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9852. //type = RFIFOB(fd,info->pos[1]);
  9853. if (!bl) return;
  9854. switch (bl->type) {
  9855. case BL_MOB:
  9856. case BL_PC:
  9857. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9858. break;
  9859. case BL_NPC:
  9860. #ifdef RENEWAL
  9861. if (sd->ud.skill_id < RK_ENCHANTBLADE && sd->ud.skilltimer != INVALID_TIMER) { // Should only show an error message for non-3rd job skills with a running timer
  9862. clif_msg(sd, WORK_IN_PROGRESS);
  9863. break;
  9864. }
  9865. #endif
  9866. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  9867. struct npc_data* nd = (struct npc_data*)bl;
  9868. // Progressbar is running
  9869. if( nd->progressbar.timeout > 0 ){
  9870. return;
  9871. }
  9872. npc_click(sd,nd);
  9873. }
  9874. break;
  9875. }
  9876. }
  9877. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9878. /// 00c5 <id>.L <type>.B
  9879. /// type:
  9880. /// 0 = buy
  9881. /// 1 = sell
  9882. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9883. {
  9884. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9885. if (sd->state.trading)
  9886. return;
  9887. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9888. }
  9889. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9890. /// 00ca <result>.B
  9891. /// result:
  9892. /// 0 = "The deal has successfully completed."
  9893. /// 1 = "You do not have enough zeny."
  9894. /// 2 = "You are over your Weight Limit."
  9895. /// 3 = "Out of the maximum capacity, you have too many items."
  9896. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  9897. {
  9898. int fd = sd->fd;
  9899. WFIFOHEAD(fd,packet_len(0xca));
  9900. WFIFOW(fd,0) = 0xca;
  9901. WFIFOB(fd,2) = result;
  9902. WFIFOSET(fd,packet_len(0xca));
  9903. }
  9904. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  9905. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  9906. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  9907. {
  9908. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9909. uint16 n = (RFIFOW(fd,info->pos[0])-4) /4;
  9910. int result;
  9911. if( sd->state.trading || !sd->npc_shopid )
  9912. result = 1;
  9913. else
  9914. result = npc_buylist(sd, n, (struct s_npc_buy_list*)RFIFOP(fd,info->pos[1]));
  9915. sd->npc_shopid = 0; //Clear shop data.
  9916. clif_npc_buy_result(sd, result);
  9917. }
  9918. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  9919. /// 00cb <result>.B
  9920. /// result:
  9921. /// 0 = "The deal has successfully completed."
  9922. /// 1 = "The deal has failed."
  9923. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  9924. {
  9925. int fd = sd->fd;
  9926. WFIFOHEAD(fd,packet_len(0xcb));
  9927. WFIFOW(fd,0) = 0xcb;
  9928. WFIFOB(fd,2) = result;
  9929. WFIFOSET(fd,packet_len(0xcb));
  9930. }
  9931. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  9932. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  9933. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  9934. {
  9935. int fail=0,n;
  9936. unsigned short *item_list;
  9937. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9938. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  9939. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9940. if (sd->state.trading || !sd->npc_shopid)
  9941. fail = 1;
  9942. else
  9943. fail = npc_selllist(sd,n,item_list);
  9944. sd->npc_shopid = 0; //Clear shop data.
  9945. clif_npc_sell_result(sd, fail);
  9946. }
  9947. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  9948. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9949. /// type:
  9950. /// 0 = private
  9951. /// 1 = public
  9952. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  9953. {
  9954. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9955. int len = RFIFOW(fd,info->pos[0])-15;
  9956. int limit = RFIFOW(fd,info->pos[1]);
  9957. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9958. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  9959. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  9960. char s_password[CHATROOM_PASS_SIZE];
  9961. char s_title[CHATROOM_TITLE_SIZE];
  9962. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  9963. return;
  9964. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9965. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  9966. return;
  9967. }
  9968. if( npc_isnear(&sd->bl) ) {
  9969. // uncomment to send msg_txt.
  9970. //char output[150];
  9971. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  9972. //clif_displaymessage(sd->fd, output);
  9973. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  9974. return;
  9975. }
  9976. if( len <= 0 )
  9977. return; // invalid input
  9978. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  9979. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  9980. chat_createpcchat(sd, s_title, s_password, limit, pub);
  9981. }
  9982. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  9983. /// 00d9 <chat ID>.L <passwd>.8B
  9984. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  9985. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9986. int chatid = RFIFOL(fd,info->pos[0]);
  9987. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  9988. chat_joinchat(sd,chatid,password);
  9989. }
  9990. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  9991. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9992. /// type:
  9993. /// 0 = private
  9994. /// 1 = public
  9995. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  9996. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9997. int len = RFIFOW(fd,info->pos[0])-15;
  9998. int limit = RFIFOW(fd,info->pos[1]);
  9999. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10000. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10001. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10002. char s_password[CHATROOM_PASS_SIZE];
  10003. char s_title[CHATROOM_TITLE_SIZE];
  10004. if( len <= 0 )
  10005. return; // invalid input
  10006. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10007. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10008. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10009. }
  10010. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10011. /// 00e0 <role>.L <nick>.24B
  10012. /// role:
  10013. /// 0 = owner
  10014. /// 1 = normal
  10015. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10016. {
  10017. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10018. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10019. }
  10020. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10021. /// 00e2 <name>.24B
  10022. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10023. {
  10024. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10025. }
  10026. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10027. /// 00e3
  10028. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10029. {
  10030. chat_leavechat(sd,0);
  10031. }
  10032. //Handles notifying asker and rejecter of what has just ocurred.
  10033. //Type is used to determine the correct msg_txt to use:
  10034. //0:
  10035. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10036. {
  10037. const char* msg;
  10038. char output[256];
  10039. // Your request has been rejected by autoreject option.
  10040. msg = msg_txt(sd,392);
  10041. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10042. //Notice that a request was rejected.
  10043. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10044. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10045. }
  10046. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10047. /// 00e4 <account id>.L
  10048. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10049. {
  10050. struct map_session_data *t_sd;
  10051. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10052. if(!sd->chatID && pc_cant_act(sd))
  10053. return; //You can trade while in a chatroom.
  10054. if(t_sd){
  10055. // @noask [LuzZza]
  10056. if(t_sd->state.noask) {
  10057. clif_noask_sub(sd, t_sd, 0);
  10058. return;
  10059. }
  10060. if (t_sd->state.mail_writing) {
  10061. int old = sd->trade_partner;
  10062. // Fake trading
  10063. sd->trade_partner = t_sd->status.account_id;
  10064. clif_tradestart(sd, 5);
  10065. // Restore old state
  10066. sd->trade_partner = old;
  10067. return;
  10068. }
  10069. }
  10070. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10071. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10072. return;
  10073. }
  10074. trade_traderequest(sd,t_sd);
  10075. }
  10076. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10077. /// 00e6 <result>.B
  10078. /// result:
  10079. /// 3 = accepted
  10080. /// 4 = rejected
  10081. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10082. {
  10083. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10084. }
  10085. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10086. /// 00e8 <index>.W <amount>.L
  10087. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10088. {
  10089. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10090. short index = RFIFOW(fd,info->pos[0]);
  10091. int amount = RFIFOL(fd,info->pos[1]);
  10092. if( index == 0 )
  10093. trade_tradeaddzeny(sd, amount);
  10094. else
  10095. trade_tradeadditem(sd, index, (short)amount);
  10096. }
  10097. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10098. /// 00eb
  10099. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10100. {
  10101. trade_tradeok(sd);
  10102. }
  10103. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10104. /// 00ed
  10105. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10106. {
  10107. trade_tradecancel(sd);
  10108. }
  10109. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10110. /// 00ef
  10111. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10112. {
  10113. trade_tradecommit(sd);
  10114. }
  10115. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10116. /// 0118
  10117. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10118. {
  10119. pc_stop_attack(sd);
  10120. if (sd) sd->ud.state.attack_continue = 0;
  10121. }
  10122. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10123. /// 0126 <index>.W <amount>.L
  10124. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  10125. {
  10126. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10127. if (pc_istrading(sd))
  10128. return;
  10129. if (!pc_iscarton(sd))
  10130. return;
  10131. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10132. }
  10133. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10134. /// 0127 <index>.W <amount>.L
  10135. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10136. {
  10137. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10138. if (!pc_iscarton(sd))
  10139. return;
  10140. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10141. }
  10142. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10143. /// 012a
  10144. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10145. {
  10146. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10147. #ifdef NEW_CARTS
  10148. && sd->sc.data[SC_PUSH_CART] )
  10149. pc_setcart(sd,0);
  10150. #else
  10151. )
  10152. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10153. #endif
  10154. else // priority to remove this option before we can clear cart
  10155. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10156. }
  10157. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10158. /// 097f <Length>.W <identity>.L <type>.B
  10159. void clif_SelectCart(struct map_session_data *sd) {
  10160. #if PACKETVER >= 20150826
  10161. int i = 0, carts = 3;
  10162. int fd = sd->fd;
  10163. WFIFOHEAD(fd,8 + carts);
  10164. WFIFOW(fd,0) = 0x97f;
  10165. WFIFOW(fd,2) = 8 + carts;
  10166. WFIFOL(fd,4) = sd->status.account_id;
  10167. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10168. for( i = 0; i < carts; i++ ) {
  10169. WFIFOB(fd,8 + i) = 10 + i;
  10170. }
  10171. WFIFOSET(fd,8 + carts);
  10172. #endif
  10173. }
  10174. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10175. /// 0980 <identity>.L <type>.B
  10176. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10177. #if PACKETVER >= 20150826
  10178. int type;
  10179. // Check identity
  10180. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10181. return;
  10182. type = (int)RFIFOB(fd,6);
  10183. // Check type
  10184. if( type < 10 || type > MAX_CARTS )
  10185. return;
  10186. pc_setcart(sd, type);
  10187. #endif
  10188. }
  10189. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10190. /// 01af <num>.W
  10191. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10192. {// TODO: State tracking?
  10193. int type;
  10194. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10195. return;
  10196. #ifdef RENEWAL
  10197. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10198. clif_msg(sd, WORK_IN_PROGRESS);
  10199. return;
  10200. }
  10201. #endif
  10202. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10203. if(
  10204. #ifdef NEW_CARTS
  10205. (type == 9 && sd->status.base_level > 130) ||
  10206. (type == 8 && sd->status.base_level > 120) ||
  10207. (type == 7 && sd->status.base_level > 110) ||
  10208. (type == 6 && sd->status.base_level > 100) ||
  10209. #endif
  10210. (type == 5 && sd->status.base_level > 90) ||
  10211. (type == 4 && sd->status.base_level > 80) ||
  10212. (type == 3 && sd->status.base_level > 65) ||
  10213. (type == 2 && sd->status.base_level > 40) ||
  10214. (type == 1))
  10215. pc_setcart(sd, type);
  10216. }
  10217. /// Request to increase status (CZ_STATUS_CHANGE).
  10218. /// 00bb <status id>.W <amount>.B
  10219. /// status id:
  10220. /// SP_STR ~ SP_LUK
  10221. /// amount:
  10222. /// Old clients always send 1 for this, even when using /str+ and the like.
  10223. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10224. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10225. {
  10226. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10227. if( increase_amount < 0 ) {
  10228. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10229. fd, increase_amount);
  10230. }
  10231. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10232. }
  10233. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10234. /// 0112 <skill id>.W
  10235. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10236. {
  10237. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10238. }
  10239. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, int target_id)
  10240. {
  10241. int lv;
  10242. if( !hd )
  10243. return;
  10244. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10245. clif_emotion(&hd->bl, E_DOTS);
  10246. return;
  10247. }
  10248. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10249. target_id = hd->bl.id;
  10250. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10251. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10252. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10253. clif_emotion(&hd->bl, E_DOTS);
  10254. if (hd->master)
  10255. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10256. return;
  10257. }
  10258. lv = hom_checkskill(hd, skill_id);
  10259. if( skill_lv > lv )
  10260. skill_lv = lv;
  10261. if( skill_lv )
  10262. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10263. }
  10264. static void clif_parse_UseSkillToPos_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
  10265. {
  10266. int lv;
  10267. if( !hd )
  10268. return;
  10269. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10270. clif_emotion(&hd->bl, E_DOTS);
  10271. return;
  10272. }
  10273. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10274. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10275. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10276. clif_emotion(&hd->bl, E_DOTS);
  10277. if (hd->master)
  10278. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10279. return;
  10280. }
  10281. if( hd->sc.data[SC_BASILICA] )
  10282. return;
  10283. lv = hom_checkskill(hd, skill_id);
  10284. if( skill_lv > lv )
  10285. skill_lv = lv;
  10286. if( skill_lv )
  10287. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10288. }
  10289. static void clif_parse_UseSkillToId_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, int target_id)
  10290. {
  10291. int lv;
  10292. if( !md )
  10293. return;
  10294. if( skill_isNotOk_mercenary(skill_id, md) )
  10295. return;
  10296. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10297. target_id = md->bl.id;
  10298. if( md->ud.skilltimer != INVALID_TIMER )
  10299. {
  10300. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10301. }
  10302. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10303. return;
  10304. lv = mercenary_checkskill(md, skill_id);
  10305. if( skill_lv > lv )
  10306. skill_lv = lv;
  10307. if( skill_lv )
  10308. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10309. }
  10310. static void clif_parse_UseSkillToPos_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, uint16 skill_id, uint16 skill_lv, short x, short y, int skillmoreinfo)
  10311. {
  10312. int lv;
  10313. if( !md )
  10314. return;
  10315. if( skill_isNotOk_mercenary(skill_id, md) )
  10316. return;
  10317. if( md->ud.skilltimer != INVALID_TIMER )
  10318. return;
  10319. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10320. {
  10321. if (md->master)
  10322. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10323. return;
  10324. }
  10325. if( md->sc.data[SC_BASILICA] )
  10326. return;
  10327. lv = mercenary_checkskill(md, skill_id);
  10328. if( skill_lv > lv )
  10329. skill_lv = lv;
  10330. if( skill_lv )
  10331. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10332. }
  10333. /// Request to use a targeted skill.
  10334. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10335. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10336. /// There are various variants of this packet, some of them have padding between fields.
  10337. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  10338. {
  10339. uint16 skill_id, skill_lv;
  10340. int inf,target_id;
  10341. unsigned int tick = gettick();
  10342. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10343. skill_lv = RFIFOW(fd,info->pos[0]);
  10344. skill_id = RFIFOW(fd,info->pos[1]);
  10345. target_id = RFIFOL(fd,info->pos[2]);
  10346. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10347. inf = skill_get_inf(skill_id);
  10348. if (inf&INF_GROUND_SKILL || !inf)
  10349. return; //Using a ground/passive skill on a target? WRONG.
  10350. if( SKILL_CHK_HOMUN(skill_id) ) {
  10351. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10352. return;
  10353. }
  10354. if( SKILL_CHK_MERC(skill_id) ) {
  10355. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10356. return;
  10357. }
  10358. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10359. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10360. sd->idletime = last_tick;
  10361. if (sd->npc_id) {
  10362. #ifdef RENEWAL
  10363. if (pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10364. clif_msg(sd, WORK_IN_PROGRESS);
  10365. return;
  10366. }
  10367. #else
  10368. if (!sd->npc_item_flag || !(inf&INF_SELF_SKILL))
  10369. return;
  10370. #endif
  10371. }
  10372. if( (pc_cant_act2(sd) || sd->chatID) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE &&
  10373. (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10374. sd->state.storage_flag && !(inf&INF_SELF_SKILL) ) //SELF skills can be used with the storage open, issue: 8027
  10375. return;
  10376. if( pc_issit(sd) )
  10377. return;
  10378. if( skill_isNotOk(skill_id, sd) )
  10379. return;
  10380. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10381. target_id = sd->bl.id; // never trust the client
  10382. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10383. target_id = sd->bl.id;
  10384. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10385. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10386. return;
  10387. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10388. if( sd->skillitem != skill_id ) {
  10389. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10390. return;
  10391. }
  10392. }
  10393. if( sd->sc.option&OPTION_COSTUME )
  10394. return;
  10395. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10396. return; // On basilica only caster can use Basilica again to stop it.
  10397. if( sd->menuskill_id ) {
  10398. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10399. clif_menuskill_clear(sd); //Cancel pet capture.
  10400. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10401. return; //Can't use skills while a menu is open.
  10402. }
  10403. if( sd->skillitem == skill_id ) {
  10404. if( skill_lv != sd->skillitemlv )
  10405. skill_lv = sd->skillitemlv;
  10406. if( !(inf&INF_SELF_SKILL) )
  10407. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10408. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10409. return;
  10410. }
  10411. sd->skillitem = sd->skillitemlv = 0;
  10412. if( SKILL_CHK_GUILD(skill_id) ) {
  10413. if( sd->state.gmaster_flag )
  10414. skill_lv = guild_checkskill(sd->guild, skill_id);
  10415. else
  10416. skill_lv = 0;
  10417. } else {
  10418. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10419. }
  10420. pc_delinvincibletimer(sd);
  10421. if( skill_lv )
  10422. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10423. }
  10424. /*==========================================
  10425. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10426. *------------------------------------------*/
  10427. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10428. {
  10429. unsigned int tick = gettick();
  10430. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10431. return; //Using a target skill on the ground? WRONG.
  10432. if( SKILL_CHK_HOMUN(skill_id) ) {
  10433. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10434. return;
  10435. }
  10436. if( SKILL_CHK_MERC(skill_id) ) {
  10437. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10438. return;
  10439. }
  10440. #ifdef RENEWAL
  10441. if (pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10442. clif_msg(sd, WORK_IN_PROGRESS);
  10443. return;
  10444. }
  10445. #endif
  10446. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10447. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10448. sd->idletime = last_tick;
  10449. if( skill_isNotOk(skill_id, sd) )
  10450. return;
  10451. if( skillmoreinfo != -1 ) {
  10452. if( pc_issit(sd) ) {
  10453. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10454. return;
  10455. }
  10456. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10457. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10458. }
  10459. if( sd->ud.skilltimer != INVALID_TIMER )
  10460. return;
  10461. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10462. if( sd->skillitem != skill_id ) {
  10463. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10464. return;
  10465. }
  10466. }
  10467. if( sd->sc.option&OPTION_COSTUME )
  10468. return;
  10469. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10470. return; // On basilica only caster can use Basilica again to stop it.
  10471. if( sd->menuskill_id ) {
  10472. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10473. clif_menuskill_clear(sd); //Cancel pet capture.
  10474. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10475. return; //Can't use skills while a menu is open.
  10476. }
  10477. pc_delinvincibletimer(sd);
  10478. if( sd->skillitem == skill_id ) {
  10479. if( skill_lv != sd->skillitemlv )
  10480. skill_lv = sd->skillitemlv;
  10481. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10482. } else {
  10483. int lv;
  10484. sd->skillitem = sd->skillitemlv = 0;
  10485. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10486. if( skill_lv > lv )
  10487. skill_lv = lv;
  10488. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10489. }
  10490. }
  10491. }
  10492. /// Request to use a ground skill.
  10493. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10494. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10495. /// There are various variants of this packet, some of them have padding between fields.
  10496. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10497. {
  10498. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10499. if (pc_cant_act(sd))
  10500. return;
  10501. if (pc_issit(sd))
  10502. return;
  10503. clif_parse_UseSkillToPosSub(fd, sd,
  10504. RFIFOW(fd,info->pos[0]), //skill lv
  10505. RFIFOW(fd,info->pos[1]), //skill num
  10506. RFIFOW(fd,info->pos[2]), //pos x
  10507. RFIFOW(fd,info->pos[3]), //pos y
  10508. -1 //Skill more info.
  10509. );
  10510. }
  10511. /// Request to use a ground skill with text.
  10512. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10513. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10514. /// There are various variants of this packet, some of them have padding between fields.
  10515. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10516. {
  10517. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10518. if (pc_cant_act(sd))
  10519. return;
  10520. if (pc_issit(sd))
  10521. return;
  10522. clif_parse_UseSkillToPosSub(fd, sd,
  10523. RFIFOW(fd,info->pos[0]), //Skill lv
  10524. RFIFOW(fd,info->pos[1]), //Skill num
  10525. RFIFOW(fd,info->pos[2]), //pos x
  10526. RFIFOW(fd,info->pos[3]), //pos y
  10527. info->pos[4] //skill more info
  10528. );
  10529. }
  10530. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10531. /// 011b <skill id>.W <map name>.16B
  10532. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10533. {
  10534. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10535. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10536. char map_name[MAP_NAME_LENGTH];
  10537. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10538. sd->state.workinprogress = WIP_DISABLE_NONE;
  10539. if(skill_id != sd->menuskill_id)
  10540. return;
  10541. //It is possible to use teleport with the storage window open bugreport:8027
  10542. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10543. clif_menuskill_clear(sd);
  10544. return;
  10545. }
  10546. pc_delinvincibletimer(sd);
  10547. skill_castend_map(sd,skill_id,map_name);
  10548. }
  10549. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10550. /// 011d
  10551. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10552. {
  10553. if (!pc_isdead(sd))
  10554. pc_memo(sd,-1);
  10555. }
  10556. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10557. /// 018e <name id>.W { <material id>.W }*3
  10558. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10559. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10560. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  10561. int slot1 = RFIFOW(fd,info->pos[1]);
  10562. int slot2 = RFIFOW(fd,info->pos[2]);
  10563. int slot3 = RFIFOW(fd,info->pos[3]);
  10564. short produce_idx = -1;
  10565. switch( sd->menuskill_id ) {
  10566. case -1:
  10567. case AM_PHARMACY:
  10568. case RK_RUNEMASTERY:
  10569. case GC_RESEARCHNEWPOISON:
  10570. break;
  10571. default:
  10572. return;
  10573. }
  10574. if (pc_istrading(sd)) {
  10575. //Make it fail to avoid shop exploits where you sell something different than you see.
  10576. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10577. clif_menuskill_clear(sd);
  10578. return;
  10579. }
  10580. if( (produce_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1)) )
  10581. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3,1,produce_idx-1);
  10582. clif_menuskill_clear(sd);
  10583. }
  10584. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10585. /// 025b <mk type>.W <name id>.W
  10586. /// mk type:
  10587. /// 1 = cooking
  10588. /// 2 = arrow
  10589. /// 3 = elemental
  10590. /// 4 = GN_MIX_COOKING
  10591. /// 5 = GN_MAKEBOMB
  10592. /// 6 = GN_S_PHARMACY
  10593. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10594. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10595. int type = RFIFOW(fd,info->pos[0]);
  10596. unsigned short nameid = RFIFOW(fd,info->pos[1]);
  10597. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10598. short food_idx = -1;
  10599. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10600. return;
  10601. if (pc_istrading(sd)) {
  10602. //Make it fail to avoid shop exploits where you sell something different than you see.
  10603. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10604. clif_menuskill_clear(sd);
  10605. return;
  10606. }
  10607. if( (food_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount)) )
  10608. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount,food_idx-1);
  10609. clif_menuskill_clear(sd);
  10610. }
  10611. /// Answer to repair weapon item selection dialog
  10612. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10613. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10614. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  10615. {
  10616. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10617. return;
  10618. if (pc_istrading(sd)) {
  10619. //Make it fail to avoid shop exploits where you sell something different than you see.
  10620. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10621. clif_menuskill_clear(sd);
  10622. return;
  10623. }
  10624. skill_repairweapon(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10625. //nameid = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10626. //refine = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  10627. //for(i = 0; i<MAX_SLOTS; i++)
  10628. // card[i] = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[3+i]);
  10629. clif_menuskill_clear(sd);
  10630. }
  10631. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10632. /// 0222 <index>.L
  10633. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  10634. {
  10635. int idx;
  10636. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10637. return;
  10638. if (pc_istrading(sd)) {
  10639. //Make it fail to avoid shop exploits where you sell something different than you see.
  10640. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10641. clif_menuskill_clear(sd);
  10642. return;
  10643. }
  10644. idx = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10645. skill_weaponrefine(sd, idx-2);
  10646. clif_menuskill_clear(sd);
  10647. }
  10648. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10649. /// 00b8 <npc id>.L <choice>.B
  10650. /// choice:
  10651. /// 1~254 = menu item
  10652. /// 255 = cancel
  10653. /// NOTE: If there were more than 254 items in the list, choice
  10654. /// overflows to choice%256.
  10655. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10656. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10657. int npc_id = RFIFOL(fd,info->pos[0]);
  10658. uint8 select = RFIFOB(fd,info->pos[1]);
  10659. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10660. #ifdef SECURE_NPCTIMEOUT
  10661. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10662. #endif
  10663. TBL_NPC* nd = map_id2nd(npc_id);
  10664. ShowWarning("Invalid menu selection on npc %d:'%s' - got %d, valid range is [%d..%d] (player AID:%d, CID:%d, name:'%s')!\n", npc_id, (nd)?nd->name:"invalid npc id", select, 1, sd->npc_menu, sd->bl.id, sd->status.char_id, sd->status.name);
  10665. clif_GM_kick(NULL,sd);
  10666. #ifdef SECURE_NPCTIMEOUT
  10667. }
  10668. #endif
  10669. return;
  10670. }
  10671. sd->npc_menu = select;
  10672. npc_scriptcont(sd,npc_id, false);
  10673. }
  10674. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10675. /// 00b9 <npc id>.L
  10676. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10677. {
  10678. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  10679. }
  10680. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10681. /// 0143 <npc id>.L <value>.L
  10682. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10683. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10684. int npcid = RFIFOL(fd,info->pos[0]);
  10685. int amount = (int)RFIFOL(fd,info->pos[1]);
  10686. sd->npc_amount = amount;
  10687. npc_scriptcont(sd, npcid, false);
  10688. }
  10689. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10690. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10691. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10692. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10693. int message_len = RFIFOW(fd,info->pos[0])-8;
  10694. int npcid = RFIFOL(fd,info->pos[1]);
  10695. const char* message = RFIFOCP(fd,info->pos[2]);
  10696. if( message_len <= 0 )
  10697. return; // invalid input
  10698. #if PACKETVER >= 20151001
  10699. message_len++;
  10700. #endif
  10701. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10702. npc_scriptcont(sd, npcid, false);
  10703. }
  10704. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10705. /// 0146 <npc id>.L
  10706. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10707. {
  10708. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10709. return;
  10710. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  10711. }
  10712. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10713. /// 0178 <index>.W
  10714. /// index:
  10715. /// -1 = cancel
  10716. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  10717. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  10718. if (sd->menuskill_id != MC_IDENTIFY)
  10719. return;
  10720. // Ignore the request
  10721. // - Invalid item index
  10722. // - Invalid item ID or item doesn't exist
  10723. // - Item is already identified
  10724. if (idx < 0 || idx >= MAX_INVENTORY ||
  10725. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  10726. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  10727. sd->state.workinprogress = WIP_DISABLE_NONE;
  10728. clif_menuskill_clear(sd);
  10729. return;
  10730. }
  10731. skill_identify(sd, idx);
  10732. clif_menuskill_clear(sd);
  10733. }
  10734. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10735. /// 01ae <name id>.W
  10736. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  10737. unsigned short nameid = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10738. if (pc_istrading(sd)) {
  10739. //Make it fail to avoid shop exploits where you sell something different than you see.
  10740. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10741. clif_menuskill_clear(sd);
  10742. return;
  10743. }
  10744. switch (sd->menuskill_id) {
  10745. case AC_MAKINGARROW:
  10746. skill_arrow_create(sd,nameid);
  10747. break;
  10748. case SA_CREATECON:
  10749. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0,1,-1);
  10750. break;
  10751. case WL_READING_SB:
  10752. skill_spellbook(sd,nameid);
  10753. break;
  10754. case GC_POISONINGWEAPON:
  10755. skill_poisoningweapon(sd,nameid);
  10756. break;
  10757. case NC_MAGICDECOY:
  10758. skill_magicdecoy(sd,nameid);
  10759. break;
  10760. }
  10761. clif_menuskill_clear(sd);
  10762. }
  10763. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10764. /// 01ce <skill id>.L
  10765. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10766. {
  10767. if (sd->menuskill_id != SA_AUTOSPELL)
  10768. return;
  10769. sd->state.workinprogress = WIP_DISABLE_NONE;
  10770. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10771. clif_menuskill_clear(sd);
  10772. }
  10773. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10774. /// 017a <card index>.W
  10775. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10776. {
  10777. if (sd->state.trading != 0)
  10778. return;
  10779. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  10780. }
  10781. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10782. /// 017c <card index>.W <equip index>.W
  10783. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10784. {
  10785. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10786. if (sd->state.trading != 0)
  10787. return;
  10788. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10789. }
  10790. /// Request of character's name by char ID.
  10791. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10792. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10793. /// There are various variants of this packet, some of them have padding between fields.
  10794. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10795. {
  10796. int charid;
  10797. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10798. map_reqnickdb(sd, charid);
  10799. }
  10800. /// /resetskill /resetstate (CZ_RESET).
  10801. /// Request to reset stats or skills.
  10802. /// 0197 <type>.W
  10803. /// type:
  10804. /// 0 = state
  10805. /// 1 = skill
  10806. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10807. char cmd[15];
  10808. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  10809. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10810. else
  10811. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10812. is_atcommand(fd, sd, cmd, 1);
  10813. }
  10814. /// /lb /nlb (CZ_LOCALBROADCAST).
  10815. /// Request to broadcast a message on current map.
  10816. /// 019c <packet len>.W <text>.?B
  10817. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10818. {
  10819. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10820. char command[CHAT_SIZE_MAX+16];
  10821. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10822. char* msg = RFIFOCP(fd,info->pos[1]);
  10823. // as the length varies depending on the command used, just block unreasonably long strings
  10824. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10825. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10826. is_atcommand(fd, sd, command, 1);
  10827. }
  10828. /// Request to move an item from inventory to storage.
  10829. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10830. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10831. /// There are various variants of this packet, some of them have padding between fields.
  10832. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10833. {
  10834. int item_index, item_amount;
  10835. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10836. if (pc_istrading(sd))
  10837. return;
  10838. item_index = RFIFOW(fd,info->pos[0])-2;
  10839. item_amount = RFIFOL(fd,info->pos[1]);
  10840. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10841. return;
  10842. if (sd->state.storage_flag == 1)
  10843. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  10844. else
  10845. if (sd->state.storage_flag == 2)
  10846. storage_guild_storageadd(sd, item_index, item_amount);
  10847. else if (sd->state.storage_flag == 3)
  10848. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  10849. }
  10850. /// Request to move an item from storage to inventory.
  10851. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10852. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10853. /// There are various variants of this packet, some of them have padding between fields.
  10854. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10855. {
  10856. int item_index, item_amount;
  10857. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10858. item_index = RFIFOW(fd,info->pos[0])-1;
  10859. item_amount = RFIFOL(fd,info->pos[1]);
  10860. if (sd->state.storage_flag == 1)
  10861. storage_storageget(sd, &sd->storage, item_index, item_amount);
  10862. else if(sd->state.storage_flag == 2)
  10863. storage_guild_storageget(sd, item_index, item_amount);
  10864. else if(sd->state.storage_flag == 3)
  10865. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  10866. }
  10867. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10868. /// 0129 <index>.W <amount>.L
  10869. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10870. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10871. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10872. int amount = RFIFOL(fd,info->pos[1]);
  10873. if( sd->state.vending )
  10874. return;
  10875. if (!pc_iscarton(sd))
  10876. return;
  10877. if (sd->state.storage_flag == 1)
  10878. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  10879. else if (sd->state.storage_flag == 2)
  10880. storage_guild_storageaddfromcart(sd, idx, amount);
  10881. else if (sd->state.storage_flag == 3)
  10882. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  10883. }
  10884. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10885. /// 0128 <index>.W <amount>.L
  10886. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  10887. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10888. int idx = RFIFOW(fd,info->pos[0]) - 1;
  10889. int amount = RFIFOL(fd,info->pos[1]);
  10890. if( sd->state.vending )
  10891. return;
  10892. if (!pc_iscarton(sd))
  10893. return;
  10894. if (sd->state.storage_flag == 1)
  10895. storage_storagegettocart(sd, &sd->storage, idx, amount);
  10896. else
  10897. if (sd->state.storage_flag == 2)
  10898. storage_guild_storagegettocart(sd, idx, amount);
  10899. else if (sd->state.storage_flag == 3)
  10900. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  10901. }
  10902. /// Request to close storage (CZ_CLOSE_STORE).
  10903. /// 00f7
  10904. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  10905. {
  10906. if( sd->state.storage_flag == 1 )
  10907. storage_storageclose(sd);
  10908. else
  10909. if( sd->state.storage_flag == 2 )
  10910. storage_guild_storageclose(sd);
  10911. else if( sd->state.storage_flag == 3 )
  10912. storage_premiumStorage_close(sd);
  10913. }
  10914. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  10915. /// 023a <info>.W
  10916. /// info:
  10917. /// 0 = password has not been set yet
  10918. /// 1 = storage is password-protected
  10919. /// 8 = too many wrong passwords
  10920. /// ? = ignored
  10921. /// NOTE: This packet is only available on certain non-kRO clients.
  10922. void clif_storagepassword(struct map_session_data* sd, short info)
  10923. {
  10924. int fd = sd->fd;
  10925. WFIFOHEAD(fd,packet_len(0x23a));
  10926. WFIFOW(fd,0) = 0x23a;
  10927. WFIFOW(fd,2) = info;
  10928. WFIFOSET(fd,packet_len(0x23a));
  10929. }
  10930. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  10931. /// 023b <type>.W <password>.16B <new password>.16B
  10932. /// type:
  10933. /// 2 = change password
  10934. /// 3 = check password
  10935. /// NOTE: This packet is only available on certain non-kRO clients.
  10936. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  10937. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10938. // int type = RFIFOW(fd,info->pos[0]);
  10939. // char* password = RFIFOP(fd,info->pos[1]);
  10940. // char* new_password = RFIFOP(fd,info->pos[2]);
  10941. // storage_changepass(sd,password,new_password);
  10942. }
  10943. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  10944. /// 023c <result>.W <error count>.W
  10945. /// result:
  10946. /// 4 = password change success
  10947. /// 5 = password change failure
  10948. /// 6 = password check success
  10949. /// 7 = password check failure
  10950. /// 8 = too many wrong passwords
  10951. /// ? = ignored
  10952. /// NOTE: This packet is only available on certain non-kRO clients.
  10953. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  10954. {
  10955. int fd = sd->fd;
  10956. WFIFOHEAD(fd,packet_len(0x23c));
  10957. WFIFOW(fd,0) = 0x23c;
  10958. WFIFOW(fd,2) = result;
  10959. WFIFOW(fd,4) = error_count;
  10960. WFIFOSET(fd,packet_len(0x23c));
  10961. }
  10962. /// Party creation request
  10963. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  10964. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  10965. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10966. name[NAME_LENGTH-1] = '\0';
  10967. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10968. clif_displaymessage(fd, msg_txt(sd,227));
  10969. return;
  10970. }
  10971. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  10972. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10973. return;
  10974. }
  10975. party_create(sd,name,0,0);
  10976. }
  10977. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  10978. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  10979. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10980. char* name = RFIFOCP(fd,info->pos[0]);
  10981. int item1 = RFIFOB(fd,info->pos[1]);
  10982. int item2 = RFIFOB(fd,info->pos[2]);
  10983. name[NAME_LENGTH-1] = '\0';
  10984. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10985. clif_displaymessage(fd, msg_txt(sd,227));
  10986. return;
  10987. }
  10988. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  10989. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10990. return;
  10991. }
  10992. party_create(sd,name,item1,item2);
  10993. }
  10994. /// Party invitation request
  10995. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  10996. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  10997. {
  10998. struct map_session_data *t_sd;
  10999. if(map[sd->bl.m].flag.partylock) {// Party locked.
  11000. clif_displaymessage(fd, msg_txt(sd,227));
  11001. return;
  11002. }
  11003. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11004. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11005. clif_noask_sub(sd, t_sd, 1);
  11006. return;
  11007. }
  11008. party_invite(sd, t_sd);
  11009. }
  11010. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11011. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11012. struct map_session_data *t_sd;
  11013. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11014. name[NAME_LENGTH-1] = '\0';
  11015. if(map[sd->bl.m].flag.partylock) {// Party locked.
  11016. clif_displaymessage(fd, msg_txt(sd,227));
  11017. return;
  11018. }
  11019. t_sd = map_nick2sd(name,false);
  11020. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11021. clif_noask_sub(sd, t_sd, 1);
  11022. return;
  11023. }
  11024. party_invite(sd, t_sd);
  11025. }
  11026. /// Party invitation reply
  11027. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11028. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11029. /// flag:
  11030. /// 0 = reject
  11031. /// 1 = accept
  11032. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11033. {
  11034. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11035. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11036. RFIFOL(fd,info->pos[1]));
  11037. }
  11038. //(CZ_PARTY_JOIN_REQ_ACK)
  11039. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11040. {
  11041. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11042. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11043. RFIFOB(fd,info->pos[1]));
  11044. }
  11045. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11046. /// 0100
  11047. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11048. {
  11049. if(map[sd->bl.m].flag.partylock) {// Party locked.
  11050. clif_displaymessage(fd, msg_txt(sd,227));
  11051. return;
  11052. }
  11053. party_leave(sd);
  11054. }
  11055. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11056. /// 0103 <account id>.L <char name>.24B
  11057. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11058. {
  11059. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11060. if(map[sd->bl.m].flag.partylock) {// Party locked.
  11061. clif_displaymessage(fd, msg_txt(sd,227));
  11062. return;
  11063. }
  11064. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11065. RFIFOCP(fd,info->pos[1]));
  11066. }
  11067. /// Request to change party options.
  11068. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11069. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11070. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11071. {
  11072. struct party_data *p;
  11073. int i,expflag;
  11074. int cmd = RFIFOW(fd,0);
  11075. struct s_packet_db* info = &packet_db[cmd];
  11076. if( !sd->status.party_id )
  11077. return;
  11078. p = party_search(sd->status.party_id);
  11079. if( p == NULL )
  11080. return;
  11081. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11082. if( i == MAX_PARTY )
  11083. return; //Shouldn't happen
  11084. if( !p->party.member[i].leader )
  11085. return;
  11086. expflag = RFIFOL(fd,info->pos[0]);
  11087. if(cmd == 0x0102){ //Client can't change the item-field
  11088. party_changeoption(sd, expflag, p->party.item);
  11089. }
  11090. else {
  11091. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11092. party_changeoption(sd, expflag, itemflag);
  11093. }
  11094. }
  11095. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11096. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11097. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11098. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11099. // validate packet and retrieve name and message
  11100. if( !clif_process_message( sd, false, name, message, output ) )
  11101. return;
  11102. party_send_message(sd, output, strlen(output) + 1 );
  11103. }
  11104. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11105. /// 07da <account id>.L
  11106. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11107. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11108. }
  11109. /// Party Booking in KRO [Spiria]
  11110. ///
  11111. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11112. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11113. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11114. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11115. short level = RFIFOW(fd,info->pos[0]);
  11116. short mapid = RFIFOW(fd,info->pos[1]);
  11117. int idxpbj = info->pos[2];
  11118. short job[MAX_PARTY_BOOKING_JOBS];
  11119. int i;
  11120. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11121. job[i] = RFIFOB(fd,idxpbj+i*2);
  11122. party_booking_register(sd, level, mapid, job);
  11123. }
  11124. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11125. /// 0803 <result>.W
  11126. /// result:
  11127. /// 0 = success
  11128. /// 1 = failure
  11129. /// 2 = already registered
  11130. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11131. {
  11132. int fd = sd->fd;
  11133. WFIFOHEAD(fd,packet_len(0x803));
  11134. WFIFOW(fd,0) = 0x803;
  11135. WFIFOW(fd,2) = flag;
  11136. WFIFOSET(fd,packet_len(0x803));
  11137. }
  11138. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11139. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11140. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11141. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11142. short level = RFIFOW(fd,info->pos[0]);
  11143. short mapid = RFIFOW(fd,info->pos[1]);
  11144. short job = RFIFOW(fd,info->pos[2]);
  11145. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11146. short resultcount = RFIFOW(fd,info->pos[4]);
  11147. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11148. }
  11149. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11150. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11151. /// more results:
  11152. /// 0 = no
  11153. /// 1 = yes
  11154. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11155. {
  11156. int i, j;
  11157. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11158. struct party_booking_ad_info *pb_ad;
  11159. WFIFOHEAD(fd,size*count + 5);
  11160. WFIFOW(fd,0) = 0x805;
  11161. WFIFOW(fd,2) = size*count + 5;
  11162. WFIFOB(fd,4) = more_result;
  11163. for(i=0; i<count; i++)
  11164. {
  11165. pb_ad = results[i];
  11166. WFIFOL(fd,i*size+5) = pb_ad->index;
  11167. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11168. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11169. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11170. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11171. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11172. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11173. }
  11174. WFIFOSET(fd,WFIFOW(fd,2));
  11175. }
  11176. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11177. /// 0806
  11178. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11179. {
  11180. if(party_booking_delete(sd))
  11181. clif_PartyBookingDeleteAck(sd, 0);
  11182. }
  11183. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11184. /// 0807 <result>.W
  11185. /// result:
  11186. /// 0 = success
  11187. /// 1 = success (auto-removed expired ad)
  11188. /// 2 = failure
  11189. /// 3 = nothing registered
  11190. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11191. {
  11192. int fd = sd->fd;
  11193. WFIFOHEAD(fd,packet_len(0x807));
  11194. WFIFOW(fd,0) = 0x807;
  11195. WFIFOW(fd,2) = flag;
  11196. WFIFOSET(fd,packet_len(0x807));
  11197. }
  11198. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11199. /// 0808 { <job>.W }*6
  11200. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11201. {
  11202. short job[MAX_PARTY_BOOKING_JOBS];
  11203. int i;
  11204. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11205. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11206. job[i] = RFIFOW(fd,idxpbu+i*2);
  11207. party_booking_update(sd, job);
  11208. }
  11209. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11210. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11211. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11212. {
  11213. int i;
  11214. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11215. if(pb_ad == NULL) return;
  11216. WBUFW(buf,0) = 0x809;
  11217. WBUFL(buf,2) = pb_ad->index;
  11218. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11219. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11220. WBUFW(buf,34) = pb_ad->p_detail.level;
  11221. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11222. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11223. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11224. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11225. }
  11226. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11227. /// 080a <index>.L { <job>.W }*6
  11228. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11229. {
  11230. int i;
  11231. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11232. if(pb_ad == NULL) return;
  11233. WBUFW(buf,0) = 0x80a;
  11234. WBUFL(buf,2) = pb_ad->index;
  11235. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11236. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11237. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11238. }
  11239. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11240. /// 080b <index>.L
  11241. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11242. {
  11243. uint8 buf[6];
  11244. WBUFW(buf,0) = 0x80b;
  11245. WBUFL(buf,2) = index;
  11246. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11247. }
  11248. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11249. /// 012e
  11250. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11251. {
  11252. vending_closevending(sd);
  11253. }
  11254. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11255. /// 0130 <account id>.L
  11256. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11257. {
  11258. if( sd->npc_id ) {// using an NPC
  11259. return;
  11260. }
  11261. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11262. }
  11263. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11264. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11265. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11266. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11267. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11268. int id = (int)RFIFOL(fd,info->pos[1]);
  11269. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11270. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11271. // whether it fails or not, the buy window is closed
  11272. sd->vended_id = 0;
  11273. }
  11274. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11275. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11276. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11277. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11278. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11279. int aid = (int)RFIFOL(fd,info->pos[1]);
  11280. int uid = (int)RFIFOL(fd,info->pos[2]);
  11281. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11282. vending_purchasereq(sd, aid, uid, data, len/4);
  11283. // whether it fails or not, the buy window is closed
  11284. sd->vended_id = 0;
  11285. }
  11286. /// Confirm or cancel the shop preparation window.
  11287. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11288. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11289. /// result:
  11290. /// 0 = canceled
  11291. /// 1 = open
  11292. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11293. int cmd = RFIFOW(fd,0);
  11294. struct s_packet_db* info = &packet_db[cmd];
  11295. short len = (short)RFIFOW(fd,info->pos[0]);
  11296. const char* message = RFIFOCP(fd,info->pos[1]);
  11297. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11298. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11299. len -= 84;
  11300. }
  11301. else { //(CZ_REQ_OPENSTORE2)
  11302. bool flag;
  11303. len -= 85;
  11304. flag = RFIFOB(fd,info->pos[2]) != 0;
  11305. if (!flag) {
  11306. sd->state.prevend = 0;
  11307. sd->state.workinprogress = WIP_DISABLE_NONE;
  11308. }
  11309. }
  11310. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11311. return;
  11312. if( map[sd->bl.m].flag.novending ) {
  11313. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11314. return;
  11315. }
  11316. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11317. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11318. return;
  11319. }
  11320. if( message[0] == '\0' ) // invalid input
  11321. return;
  11322. vending_openvending(sd, message, data, len/8, NULL);
  11323. }
  11324. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11325. /// 0165 <char id>.L <guild name>.24B
  11326. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11327. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11328. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11329. name[NAME_LENGTH-1] = '\0';
  11330. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11331. clif_displaymessage(fd, msg_txt(sd,228));
  11332. return;
  11333. }
  11334. if(sd->clan){
  11335. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11336. return;
  11337. }
  11338. guild_create(sd, name);
  11339. }
  11340. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11341. /// 014d
  11342. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11343. {
  11344. clif_guild_masterormember(sd);
  11345. }
  11346. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11347. /// 014f <type>.L
  11348. /// type:
  11349. /// 0 = basic info
  11350. /// 1 = member manager
  11351. /// 2 = positions
  11352. /// 3 = skills
  11353. /// 4 = expulsion list
  11354. /// 5 = unknown (GM_ALLGUILDLIST)
  11355. /// 6 = notice
  11356. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11357. {
  11358. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11359. if( !sd->status.guild_id && !sd->bg_id )
  11360. return;
  11361. switch( type )
  11362. {
  11363. case 0: // Basic Information Guild, hostile alliance information
  11364. clif_guild_basicinfo(sd);
  11365. clif_guild_allianceinfo(sd);
  11366. break;
  11367. case 1: // Members list, list job title
  11368. clif_guild_positionnamelist(sd);
  11369. clif_guild_memberlist(sd);
  11370. break;
  11371. case 2: // List job title, title information list
  11372. clif_guild_positionnamelist(sd);
  11373. clif_guild_positioninfolist(sd);
  11374. break;
  11375. case 3: // Skill list
  11376. clif_guild_skillinfo(sd);
  11377. break;
  11378. case 4: // Expulsion list
  11379. clif_guild_expulsionlist(sd);
  11380. break;
  11381. default:
  11382. ShowError("clif: guild request info: unknown type %d\n", type);
  11383. break;
  11384. }
  11385. }
  11386. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11387. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11388. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11389. {
  11390. int i;
  11391. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11392. int len = RFIFOW(fd,info->pos[0]);
  11393. int idxgpos = info->pos[1];
  11394. if(!sd->state.gmaster_flag)
  11395. return;
  11396. for(i = idxgpos; i < len; i += 40 ){
  11397. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11398. }
  11399. }
  11400. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11401. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11402. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11403. {
  11404. int i;
  11405. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11406. int len = RFIFOW(fd,info->pos[0]);
  11407. int idxgpos = info->pos[1];
  11408. if(!sd->state.gmaster_flag)
  11409. return;
  11410. // Guild leadership change
  11411. if( len == 16 && RFIFOL(fd,12) == 0 ){
  11412. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11413. clif_msg(sd, GUILD_MASTER_WOE);
  11414. return;
  11415. }
  11416. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){
  11417. clif_msg(sd, GUILD_MASTER_DELAY);
  11418. return;
  11419. }
  11420. guild_gm_change(sd->status.guild_id, RFIFOL(fd, 8));
  11421. return;
  11422. }
  11423. for(i=idxgpos;i<len;i+=12){
  11424. int position = RFIFOL(fd,i+8);
  11425. if( position > 0 ){
  11426. guild_change_memberposition(sd->status.guild_id,RFIFOL(fd,i),RFIFOL(fd,i+4),position);
  11427. }
  11428. }
  11429. }
  11430. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11431. /// 0151 <guild id>.L
  11432. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11433. {
  11434. struct guild* g;
  11435. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11436. if( (g = guild_search(guild_id)) != NULL )
  11437. clif_guild_emblem(sd,g);
  11438. }
  11439. /// Validates data of a guild emblem (compressed bitmap)
  11440. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11441. EMBVALIDATE_SUCCESS = 0,
  11442. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11443. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of battle_config.emblem_transparency_limit
  11444. };
  11445. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11446. {
  11447. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11448. unsigned long buf_len = sizeof(buf);
  11449. int offset = 0;
  11450. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11451. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11452. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11453. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11454. ))
  11455. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11456. if(battle_config.emblem_transparency_limit != 100) {
  11457. int i, transcount = 1, tmp[3];
  11458. for(i = offset; i < buf_len-1; i++) {
  11459. int j = i%3;
  11460. tmp[j] = RBUFL(buf,i);
  11461. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11462. transcount++;
  11463. }
  11464. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  11465. return EMBVALIDATE_ERR_TRANSPARENCY;
  11466. }
  11467. return EMBVALIDATE_SUCCESS;
  11468. }
  11469. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11470. /// 0153 <packet len>.W <emblem data>.?B
  11471. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11472. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11473. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11474. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11475. int emb_val=0;
  11476. if( !emblem_len || !sd->state.gmaster_flag )
  11477. return;
  11478. if(!(battle_config.emblem_woe_change) && is_agit_start() ){
  11479. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11480. return;
  11481. }
  11482. emb_val = clif_validate_emblem(emblem, emblem_len);
  11483. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11484. ShowWarning("clif_parse_GuildChangeEmblem: Rejected malformed guild emblem (size=%lu, accound_id=%d, char_id=%d, guild_id=%d).\n", emblem_len, sd->status.account_id, sd->status.char_id, sd->status.guild_id);
  11485. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11486. return;
  11487. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11488. char output[128];
  11489. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11490. clif_messagecolor(&sd->bl,color_table[COLOR_RED],output,false,SELF); //"The chosen emblem was detected invalid as it contain too much transparency (limit=%d)\n"
  11491. return;
  11492. }
  11493. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11494. }
  11495. /// Guild notice update request (CZ_GUILD_NOTICE).
  11496. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11497. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11498. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11499. int guild_id = RFIFOL(fd,info->pos[0]);
  11500. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11501. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11502. if(!sd->state.gmaster_flag)
  11503. return;
  11504. // compensate for some client defects when using multilanguage mode
  11505. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11506. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11507. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11508. guild_change_notice(sd, guild_id, msg1, msg2);
  11509. }
  11510. // Helper function for guild invite functions
  11511. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11512. {
  11513. if (t_sd == NULL) // not online or does not exist
  11514. return 1;
  11515. if (map[sd->bl.m].flag.guildlock) {//Guild locked.
  11516. clif_displaymessage(fd, msg_txt(sd,228));
  11517. return 1;
  11518. }
  11519. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11520. clif_noask_sub(sd, t_sd, 2);
  11521. return 1;
  11522. }
  11523. // Players in a clan can not join a guild
  11524. if(t_sd && t_sd->clan){
  11525. return 1;
  11526. }
  11527. guild_invite(sd, t_sd);
  11528. return 0;
  11529. }
  11530. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11531. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11532. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11533. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11534. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11535. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11536. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11537. if (clif_sub_guild_invite(fd, sd, t_sd))
  11538. return;
  11539. }
  11540. /// Guild invite request (/guildinvite)
  11541. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11542. void
  11543. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11544. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  11545. if (clif_sub_guild_invite(fd, sd, t_sd))
  11546. return;
  11547. }
  11548. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11549. /// 016b <guild id>.L <answer>.L
  11550. /// answer:
  11551. /// 0 = refuse
  11552. /// 1 = accept
  11553. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11554. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11555. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11556. RFIFOL(fd,info->pos[1]));
  11557. }
  11558. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11559. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11560. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11561. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11562. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11563. clif_displaymessage(fd, msg_txt(sd,228));
  11564. return;
  11565. }
  11566. if( sd->bg_id ) {
  11567. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11568. return;
  11569. }
  11570. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11571. RFIFOL(fd,info->pos[1]),
  11572. RFIFOL(fd,info->pos[2]),
  11573. RFIFOCP(fd,info->pos[3]));
  11574. }
  11575. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11576. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11577. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11578. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11579. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  11580. { // Guild locked.
  11581. clif_displaymessage(fd, msg_txt(sd,228));
  11582. return;
  11583. }
  11584. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11585. RFIFOL(fd,info->pos[1]),
  11586. RFIFOL(fd,info->pos[2]),
  11587. RFIFOCP(fd,info->pos[3]));
  11588. }
  11589. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11590. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11591. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11592. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11593. // validate packet and retrieve name and message
  11594. if( !clif_process_message( sd, false, name, message, output ) )
  11595. return;
  11596. if( sd->bg_id )
  11597. bg_send_message(sd, output, strlen(output) );
  11598. else
  11599. guild_send_message(sd, output, strlen(output) );
  11600. }
  11601. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11602. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11603. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11604. {
  11605. struct map_session_data *t_sd;
  11606. if(!sd->state.gmaster_flag)
  11607. return;
  11608. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11609. clif_displaymessage(fd, msg_txt(sd,228));
  11610. return;
  11611. }
  11612. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11613. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11614. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  11615. // @noask [LuzZza]
  11616. if(t_sd && t_sd->state.noask) {
  11617. clif_noask_sub(sd, t_sd, 3);
  11618. return;
  11619. }
  11620. guild_reqalliance(sd,t_sd);
  11621. }
  11622. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11623. /// 0172 <inviter account id>.L <answer>.L
  11624. /// answer:
  11625. /// 0 = refuse
  11626. /// 1 = accept
  11627. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11628. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11629. guild_reply_reqalliance(sd,
  11630. RFIFOL(fd,info->pos[0]),
  11631. RFIFOL(fd,info->pos[1]));
  11632. }
  11633. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11634. /// 0183 <opponent guild id>.L <relation>.L
  11635. /// relation:
  11636. /// 0 = Ally
  11637. /// 1 = Enemy
  11638. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11639. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11640. if(!sd->state.gmaster_flag)
  11641. return;
  11642. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11643. clif_displaymessage(fd, msg_txt(sd,228));
  11644. return;
  11645. }
  11646. guild_delalliance(sd,
  11647. RFIFOL(fd,info->pos[0]),
  11648. RFIFOL(fd,info->pos[1]));
  11649. }
  11650. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11651. /// 0180 <account id>.L
  11652. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11653. {
  11654. struct map_session_data *t_sd;
  11655. if(!sd->state.gmaster_flag)
  11656. return;
  11657. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11658. clif_displaymessage(fd, msg_txt(sd,228));
  11659. return;
  11660. }
  11661. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11662. // @noask [LuzZza]
  11663. if(t_sd && t_sd->state.noask) {
  11664. clif_noask_sub(sd, t_sd, 4);
  11665. return;
  11666. }
  11667. guild_opposition(sd,t_sd);
  11668. }
  11669. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11670. /// 015d <key>.40B
  11671. /// key:
  11672. /// now guild name; might have been (intended) email, since the
  11673. /// field name and size is same as the one in CH_DELETE_CHAR.
  11674. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11675. {
  11676. if( map[sd->bl.m].flag.guildlock ) { //Guild locked.
  11677. clif_displaymessage(fd, msg_txt(sd,228));
  11678. return;
  11679. }
  11680. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11681. }
  11682. /// Pet
  11683. ///
  11684. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11685. /// 01a1 <type>.B
  11686. /// type:
  11687. /// 0 = pet information
  11688. /// 1 = feed
  11689. /// 2 = performance
  11690. /// 3 = return to egg
  11691. /// 4 = unequip accessory
  11692. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11693. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11694. }
  11695. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11696. /// 019f <id>.L
  11697. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11698. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11699. }
  11700. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11701. /// 01a7 <index>.W
  11702. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11703. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11704. return;
  11705. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11706. clif_menuskill_clear(sd);
  11707. }
  11708. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11709. /// 01a9 <data>.L
  11710. /// data:
  11711. /// is either emotion (@see enum emotion_type) or a compound value
  11712. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11713. /// entry (given in parentheses) in data\pettalktable.xml
  11714. /// act id:
  11715. /// 0 = feeding
  11716. /// 1 = hunting
  11717. /// 2 = danger
  11718. /// 3 = dead
  11719. /// 4 = normal (stand)
  11720. /// 5 = special performance (perfor_s)
  11721. /// 6 = level up (levelup)
  11722. /// 7 = performance 1 (perfor_1)
  11723. /// 8 = performance 2 (perfor_2)
  11724. /// 9 = performance 3 (perfor_3)
  11725. /// 10 = log-in greeting (connect)
  11726. /// hungry value:
  11727. /// 0 = very hungry (hungry)
  11728. /// 1 = hungry (bit_hungry)
  11729. /// 2 = satisfied (noting)
  11730. /// 3 = stuffed (full)
  11731. /// 4 = full (so_full)
  11732. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11733. {
  11734. if(sd->pd)
  11735. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11736. }
  11737. /// Request to change pet's name (CZ_RENAME_PET).
  11738. /// 01a5 <name>.24B
  11739. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11740. {
  11741. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11742. }
  11743. /// /kill (CZ_DISCONNECT_CHARACTER).
  11744. /// Request to disconnect a character.
  11745. /// 00cc <account id>.L
  11746. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11747. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11748. {
  11749. struct block_list *target;
  11750. int tid;
  11751. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11752. target = map_id2bl(tid);
  11753. if (!target) {
  11754. clif_GM_kickack(sd, 0);
  11755. return;
  11756. }
  11757. switch (target->type) {
  11758. case BL_PC:
  11759. {
  11760. char command[NAME_LENGTH+6];
  11761. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11762. is_atcommand(fd, sd, command, 1);
  11763. }
  11764. break;
  11765. /**
  11766. * This one does not invoke any atcommand, so we need to check for permissions.
  11767. */
  11768. case BL_MOB:
  11769. {
  11770. char command[100];
  11771. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11772. clif_GM_kickack(sd, 0);
  11773. return;
  11774. }
  11775. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11776. log_atcommand(sd, command);
  11777. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11778. }
  11779. break;
  11780. case BL_NPC:
  11781. {
  11782. struct npc_data* nd = (struct npc_data *)target;
  11783. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11784. npc_unload_duplicates(nd);
  11785. npc_unload(nd,true);
  11786. npc_read_event_script();
  11787. }
  11788. }
  11789. break;
  11790. default:
  11791. clif_GM_kickack(sd, 0);
  11792. }
  11793. }
  11794. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11795. /// Request to disconnect all characters.
  11796. /// 00ce
  11797. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11798. char cmd[15];
  11799. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11800. is_atcommand(fd, sd, cmd, 1);
  11801. }
  11802. /// /remove (CZ_REMOVE_AID).
  11803. /// Request to warp to a character with given login ID.
  11804. /// 01ba <account name>.24B
  11805. /// /shift (CZ_SHIFT).
  11806. /// Request to warp to a character with given name.
  11807. /// 01bb <char name>.24B
  11808. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11809. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11810. char *player_name;
  11811. char command[NAME_LENGTH+8];
  11812. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11813. player_name[NAME_LENGTH-1] = '\0';
  11814. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11815. is_atcommand(fd, sd, command, 1);
  11816. }
  11817. /// /remove (CZ_REMOVE_AID_SSO).
  11818. /// Request to warp to a character with given account ID.
  11819. /// 0843 <account id>.L
  11820. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  11821. {
  11822. uint32 account_id;
  11823. struct map_session_data* pl_sd;
  11824. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11825. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11826. char command[NAME_LENGTH+8];
  11827. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11828. is_atcommand(fd, sd, command, 1);
  11829. }
  11830. }
  11831. /// /recall (CZ_RECALL).
  11832. /// Request to summon a player with given login ID to own position.
  11833. /// 01bc <account name>.24B
  11834. /// /summon (CZ_RECALL_GID).
  11835. /// Request to summon a player with given name to own position.
  11836. /// 01bd <char name>.24B
  11837. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11838. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11839. char *player_name;
  11840. char command [NAME_LENGTH+8];
  11841. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11842. player_name[NAME_LENGTH-1] = '\0';
  11843. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11844. is_atcommand(fd, sd, command, 1);
  11845. }
  11846. /// /recall (CZ_RECALL_SSO).
  11847. /// Request to summon a player with given account ID to own position.
  11848. /// 0842 <account id>.L
  11849. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11850. {
  11851. uint32 account_id;
  11852. struct map_session_data* pl_sd;
  11853. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11854. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11855. char command[NAME_LENGTH+8];
  11856. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11857. is_atcommand(fd, sd, command, 1);
  11858. }
  11859. }
  11860. /// /item /monster (CZ_ITEM_CREATE).
  11861. /// Request to execute GM commands.
  11862. /// Usage:
  11863. /// /item n - summon n monster or acquire n item/s
  11864. /// /item money - grants 2147483647 zenies
  11865. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  11866. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  11867. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  11868. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  11869. /// /item cap_n - capture n monster as pet.(not yet implemented)
  11870. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  11871. /// 013f <item/mob name>.24B
  11872. /// 09ce <item/mob name>.100B [Ind/Yommy]
  11873. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  11874. {
  11875. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11876. int mob_id = 0;
  11877. struct item_data *id = NULL;
  11878. struct mob_db *mob = NULL;
  11879. StringBuf command;
  11880. char *str;
  11881. //#if PACKETVER >= 20131218
  11882. // char str[100];
  11883. //#else
  11884. // char str[24];
  11885. //#endif
  11886. str = RFIFOCP(fd,info->pos[0]);
  11887. if (!str || str[0] == '\0')
  11888. return;
  11889. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  11890. return;
  11891. trim(str);
  11892. // Zeny
  11893. if( strcmpi(str, "money") == 0 ) {
  11894. StringBuf_Init(&command);
  11895. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  11896. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11897. StringBuf_Destroy(&command);
  11898. return;
  11899. }
  11900. // Item
  11901. if( (id = itemdb_searchname(str)) ) {
  11902. StringBuf_Init(&command);
  11903. if( !itemdb_isstackable2(id) ) //Nonstackable
  11904. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  11905. else {
  11906. if (id->flag.guid)
  11907. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  11908. else
  11909. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  11910. }
  11911. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11912. StringBuf_Destroy(&command);
  11913. return;
  11914. }
  11915. // Monster
  11916. if ((mob_id = mobdb_searchname(str)) == 0)
  11917. mob_id = mobdb_checkid(atoi(str));
  11918. if( (mob = mob_db(mob_id)) ) {
  11919. StringBuf_Init(&command);
  11920. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  11921. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11922. StringBuf_Destroy(&command);
  11923. return;
  11924. }
  11925. }
  11926. /// /hide (CZ_CHANGE_EFFECTSTATE).
  11927. /// 019d <effect state>.L
  11928. /// effect state:
  11929. /// TODO: Any OPTION_* ?
  11930. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  11931. char cmd[6];
  11932. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  11933. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  11934. is_atcommand(fd, sd, cmd, 1);
  11935. }
  11936. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  11937. /// 0149 <account id>.L <type>.B <value>.W
  11938. /// type:
  11939. /// 0 = positive points
  11940. /// 1 = negative points
  11941. /// 2 = self mute (+10 minutes)
  11942. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  11943. {
  11944. int id, type, value;
  11945. struct map_session_data *dstsd;
  11946. char command[NAME_LENGTH+15];
  11947. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11948. id = RFIFOL(fd,info->pos[0]);
  11949. type = RFIFOB(fd,info->pos[1]);
  11950. value = RFIFOW(fd,info->pos[2]);
  11951. if( type == 0 )
  11952. value = -value;
  11953. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  11954. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  11955. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  11956. return;
  11957. dstsd = map_id2sd(id);
  11958. if( dstsd == NULL )
  11959. return;
  11960. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  11961. is_atcommand(fd, sd, command, 1);
  11962. }
  11963. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  11964. /// GM adjustment of a player's manner value by -60.
  11965. /// 0212 <char name>.24B
  11966. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  11967. {
  11968. char command[NAME_LENGTH+15];
  11969. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11970. name[NAME_LENGTH-1] = '\0';
  11971. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  11972. is_atcommand(fd, sd, command, 1);
  11973. }
  11974. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  11975. /// 01e0 <account id>.L <account name>.24B
  11976. void clif_account_name(int fd, uint32 account_id, const char* accname)
  11977. {
  11978. WFIFOHEAD(fd,packet_len(0x1e0));
  11979. WFIFOW(fd,0) = 0x1e0;
  11980. WFIFOL(fd,2) = account_id;
  11981. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  11982. WFIFOSET(fd,packet_len(0x1e0));
  11983. }
  11984. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  11985. /// 01df <account id>.L
  11986. //! TODO: Figure out how does this actually work
  11987. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  11988. {
  11989. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11990. /*
  11991. char query[30];
  11992. safesnprintf(query,sizeof(query),"%d", account_id);
  11993. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  11994. */
  11995. clif_account_name(fd, account_id, "");
  11996. }
  11997. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  11998. /// GM single cell type change request.
  11999. /// 0198 <x>.W <y>.W <type>.W
  12000. /// type:
  12001. /// 0 = not walkable
  12002. /// 1 = walkable
  12003. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12004. {
  12005. int x,y,type;
  12006. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12007. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12008. return;
  12009. x = RFIFOW(fd,info->pos[0]);
  12010. y = RFIFOW(fd,info->pos[1]);
  12011. type = RFIFOW(fd,info->pos[2]);
  12012. map_setgatcell(sd->bl.m,x,y,type);
  12013. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12014. //FIXME: once players leave the map, the client 'forgets' this information.
  12015. }
  12016. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12017. /// Request to allow/deny whispers from a nick.
  12018. /// 00cf <nick>.24B <type>.B
  12019. /// type:
  12020. /// 0 = (/ex nick) deny speech from nick
  12021. /// 1 = (/in nick) allow speech from nick
  12022. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12023. {
  12024. char* nick;
  12025. uint8 type;
  12026. int i;
  12027. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12028. nick = RFIFOCP(fd,info->pos[0]);
  12029. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12030. type = RFIFOB(fd,info->pos[1]);
  12031. if( type == 0 ) { // Add name to ignore list (block)
  12032. if (strcmp(wisp_server_name, nick) == 0) {
  12033. clif_wisexin(sd, type, 1); // fail
  12034. return;
  12035. }
  12036. // try to find a free spot, while checking for duplicates at the same time
  12037. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12038. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12039. clif_wisexin(sd, type, 2); // too many blocks
  12040. return;
  12041. }
  12042. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12043. clif_wisexin(sd, type, 0); // Aegis reports success.
  12044. return;
  12045. }
  12046. //Insert in position i
  12047. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12048. } else { // Remove name from ignore list (unblock)
  12049. // find entry
  12050. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12051. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  12052. clif_wisexin(sd, type, 1); // fail
  12053. return;
  12054. }
  12055. // move everything one place down to overwrite removed entry
  12056. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12057. // wipe last entry
  12058. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12059. }
  12060. clif_wisexin(sd, type, 0); // success
  12061. }
  12062. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12063. /// Request to allow/deny all whispers.
  12064. /// 00d0 <type>.B
  12065. /// type:
  12066. /// 0 = (/exall) deny all speech
  12067. /// 1 = (/inall) allow all speech
  12068. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12069. {
  12070. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12071. if( type == 0 ) {// Deny all
  12072. if( sd->state.ignoreAll ) {
  12073. flag = 1; // fail
  12074. } else {
  12075. sd->state.ignoreAll = 1;
  12076. flag = 0; // success
  12077. }
  12078. } else {//Unblock everyone
  12079. if( sd->state.ignoreAll ) {
  12080. sd->state.ignoreAll = 0;
  12081. flag = 0; // success
  12082. } else {
  12083. if (sd->ignore[0].name[0] != '\0')
  12084. { //Wipe the ignore list.
  12085. memset(sd->ignore, 0, sizeof(sd->ignore));
  12086. flag = 0; // success
  12087. } else {
  12088. flag = 1; // fail
  12089. }
  12090. }
  12091. }
  12092. clif_wisall(sd, type, flag);
  12093. }
  12094. /// Whisper ignore list (ZC_WHISPER_LIST).
  12095. /// 00d4 <packet len>.W { <char name>.24B }*
  12096. void clif_PMIgnoreList(struct map_session_data* sd)
  12097. {
  12098. int i, fd = sd->fd;
  12099. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12100. WFIFOW(fd,0) = 0xd4;
  12101. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12102. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12103. }
  12104. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12105. WFIFOSET(fd,WFIFOW(fd,2));
  12106. }
  12107. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12108. /// 00d3
  12109. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12110. {
  12111. clif_PMIgnoreList(sd);
  12112. }
  12113. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12114. /// 01e7
  12115. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12116. {
  12117. if (sd->state.doridori) return;
  12118. switch (sd->class_&MAPID_UPPERMASK) {
  12119. case MAPID_SOUL_LINKER:
  12120. case MAPID_STAR_GLADIATOR:
  12121. case MAPID_TAEKWON:
  12122. if (!sd->state.rest)
  12123. break;
  12124. case MAPID_SUPER_NOVICE:
  12125. case MAPID_SUPER_BABY:
  12126. case MAPID_SUPER_NOVICE_E:
  12127. case MAPID_SUPER_BABY_E:
  12128. sd->state.doridori=1;
  12129. break;
  12130. }
  12131. }
  12132. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12133. /// 01ed
  12134. /// Note: This packet is caused by 7 lines of any text, followed by
  12135. /// the prayer and an another line of any text. The prayer is
  12136. /// defined by lines 790~793 in data\msgstringtable.txt
  12137. /// "Dear angel, can you hear my voice?"
  12138. /// "I am" (space separated player name) "Super Novice~"
  12139. /// "Help me out~ Please~ T_T"
  12140. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12141. {
  12142. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12143. unsigned int next = pc_nextbaseexp(sd);
  12144. if( next ) {
  12145. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  12146. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12147. sc_start(&sd->bl,&sd->bl, status_skill2sc(MO_EXPLOSIONSPIRITS), 100, 17, skill_get_time(MO_EXPLOSIONSPIRITS, 5)); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  12148. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12149. }
  12150. }
  12151. }
  12152. }
  12153. /// Friends List
  12154. ///
  12155. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12156. /// 0206 <account id>.L <char id>.L <state>.B
  12157. /// state:
  12158. /// 0 = online
  12159. /// 1 = offline
  12160. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12161. {
  12162. int i, fd = sd->fd;
  12163. //Seek friend.
  12164. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12165. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12166. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12167. return; //Not found
  12168. WFIFOHEAD(fd,packet_len(0x206));
  12169. WFIFOW(fd, 0) = 0x206;
  12170. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12171. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12172. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12173. WFIFOSET(fd, packet_len(0x206));
  12174. }
  12175. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12176. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12177. {
  12178. uint32 account_id, char_id, online;
  12179. account_id = va_arg(ap, int);
  12180. char_id = va_arg(ap, int);
  12181. online = va_arg(ap, int);
  12182. clif_friendslist_toggle(sd, account_id, char_id, online);
  12183. return 0;
  12184. }
  12185. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12186. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12187. void clif_friendslist_send(struct map_session_data *sd)
  12188. {
  12189. int i = 0, n, fd = sd->fd;
  12190. // Send friends list
  12191. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  12192. WFIFOW(fd, 0) = 0x201;
  12193. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12194. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  12195. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  12196. safestrncpy(WFIFOCP(fd, 4 + 32 * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  12197. }
  12198. if (i) {
  12199. WFIFOW(fd,2) = 4 + 32 * i;
  12200. WFIFOSET(fd, WFIFOW(fd,2));
  12201. }
  12202. for (n = 0; n < i; n++) { //Sending the online players
  12203. if (map_charid2sd(sd->status.friends[n].char_id))
  12204. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12205. }
  12206. }
  12207. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12208. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12209. /// result:
  12210. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12211. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12212. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12213. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12214. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12215. {
  12216. int fd;
  12217. nullpo_retv(sd);
  12218. fd = sd->fd;
  12219. WFIFOHEAD(fd,packet_len(0x209));
  12220. WFIFOW(fd,0) = 0x209;
  12221. WFIFOW(fd,2) = type;
  12222. if (f_sd) {
  12223. WFIFOL(fd,4) = f_sd->status.account_id;
  12224. WFIFOL(fd,8) = f_sd->status.char_id;
  12225. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12226. }
  12227. WFIFOSET(fd, packet_len(0x209));
  12228. }
  12229. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12230. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12231. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12232. {
  12233. int fd = sd->fd;
  12234. WFIFOHEAD(fd,packet_len(0x207));
  12235. WFIFOW(fd,0) = 0x207;
  12236. WFIFOL(fd,2) = account_id;
  12237. WFIFOL(fd,6) = char_id;
  12238. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12239. WFIFOSET(fd,packet_len(0x207));
  12240. }
  12241. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12242. /// 0202 <name>.24B
  12243. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12244. {
  12245. struct map_session_data *f_sd;
  12246. int i;
  12247. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12248. // Friend doesn't exist (no player with this name)
  12249. if (f_sd == NULL) {
  12250. clif_displaymessage(fd, msg_txt(sd,3));
  12251. return;
  12252. }
  12253. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12254. return;
  12255. }
  12256. // ensure that the request player's friend list is not full
  12257. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12258. if( i == MAX_FRIENDS ){
  12259. clif_friendslist_reqack(sd, f_sd, 2);
  12260. return;
  12261. }
  12262. // @noask [LuzZza]
  12263. if(f_sd->state.noask) {
  12264. clif_noask_sub(sd, f_sd, 5);
  12265. return;
  12266. }
  12267. // Friend already exists
  12268. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12269. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12270. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12271. return;
  12272. }
  12273. }
  12274. f_sd->friend_req = sd->status.char_id;
  12275. sd->friend_req = f_sd->status.char_id;
  12276. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12277. }
  12278. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12279. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12280. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12281. /// reply:
  12282. /// 0 = rejected
  12283. /// 1 = accepted
  12284. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12285. {
  12286. struct map_session_data *f_sd;
  12287. uint32 account_id;
  12288. char reply;
  12289. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12290. account_id = RFIFOL(fd,info->pos[0]);
  12291. //char_id = RFIFOL(fd,info->pos[1]);
  12292. #if PACKETVER < 6
  12293. reply = RFIFOB(fd,info->pos[2]);
  12294. #else
  12295. reply = RFIFOL(fd,info->pos[2]);
  12296. #endif
  12297. if( sd->bl.id == account_id ) {// adding oneself as friend
  12298. return;
  12299. }
  12300. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12301. if (f_sd == NULL)
  12302. return;
  12303. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12304. clif_friendslist_reqack(f_sd, sd, 1);
  12305. else {
  12306. int i;
  12307. // Find an empty slot
  12308. for (i = 0; i < MAX_FRIENDS; i++)
  12309. if (f_sd->status.friends[i].char_id == 0)
  12310. break;
  12311. if (i == MAX_FRIENDS) {
  12312. clif_friendslist_reqack(f_sd, sd, 2);
  12313. return;
  12314. }
  12315. f_sd->status.friends[i].account_id = sd->status.account_id;
  12316. f_sd->status.friends[i].char_id = sd->status.char_id;
  12317. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12318. clif_friendslist_reqack(f_sd, sd, 0);
  12319. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12320. if (battle_config.friend_auto_add) {
  12321. // Also add f_sd to sd's friendlist.
  12322. for (i = 0; i < MAX_FRIENDS; i++) {
  12323. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12324. return; //No need to add anything.
  12325. if (sd->status.friends[i].char_id == 0)
  12326. break;
  12327. }
  12328. if (i == MAX_FRIENDS) {
  12329. clif_friendslist_reqack(sd, f_sd, 2);
  12330. return;
  12331. }
  12332. sd->status.friends[i].account_id = f_sd->status.account_id;
  12333. sd->status.friends[i].char_id = f_sd->status.char_id;
  12334. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12335. clif_friendslist_reqack(sd, f_sd, 0);
  12336. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12337. }
  12338. }
  12339. }
  12340. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12341. /// 0203 <account id>.L <char id>.L
  12342. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12343. {
  12344. struct map_session_data *f_sd = NULL;
  12345. uint32 account_id, char_id;
  12346. int i, j;
  12347. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12348. account_id = RFIFOL(fd,info->pos[0]);
  12349. char_id = RFIFOL(fd,info->pos[1]);
  12350. // Search friend
  12351. for (i = 0; i < MAX_FRIENDS &&
  12352. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12353. if (i == MAX_FRIENDS) {
  12354. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12355. return;
  12356. }
  12357. //remove from friend's list first
  12358. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12359. for (i = 0; i < MAX_FRIENDS &&
  12360. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12361. if (i != MAX_FRIENDS) {
  12362. // move all chars up
  12363. for(j = i + 1; j < MAX_FRIENDS; j++)
  12364. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12365. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12366. //should the guy be notified of some message? we should add it here if so
  12367. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12368. WFIFOW(f_sd->fd,0) = 0x20a;
  12369. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12370. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12371. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12372. }
  12373. } else { //friend not online -- ask char server to delete from his friendlist
  12374. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12375. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12376. return;
  12377. }
  12378. }
  12379. // We can now delete from original requester
  12380. for (i = 0; i < MAX_FRIENDS &&
  12381. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12382. // move all chars up
  12383. for(j = i + 1; j < MAX_FRIENDS; j++)
  12384. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12385. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12386. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12387. WFIFOHEAD(fd,packet_len(0x20a));
  12388. WFIFOW(fd,0) = 0x20a;
  12389. WFIFOL(fd,2) = account_id;
  12390. WFIFOL(fd,6) = char_id;
  12391. WFIFOSET(fd, packet_len(0x20a));
  12392. }
  12393. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12394. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12395. void clif_PVPInfo(struct map_session_data* sd)
  12396. {
  12397. int fd = sd->fd;
  12398. WFIFOHEAD(fd,packet_len(0x210));
  12399. WFIFOW(fd,0) = 0x210;
  12400. WFIFOL(fd,2) = sd->status.char_id;
  12401. WFIFOL(fd,6) = sd->status.account_id;
  12402. WFIFOL(fd,10) = sd->pvp_won; // times won
  12403. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12404. WFIFOL(fd,18) = sd->pvp_point;
  12405. WFIFOSET(fd, packet_len(0x210));
  12406. }
  12407. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12408. /// 020f <char id>.L <account id>.L
  12409. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12410. {
  12411. // TODO: Is there a way to use this on an another player (char/acc id)?
  12412. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12413. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12414. clif_PVPInfo(sd);
  12415. }
  12416. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12417. /// 0254 <which>.B
  12418. /// which: (unused atm for security purpose)
  12419. /// 0 = sun
  12420. /// 1 = moon
  12421. /// 2 = star
  12422. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12423. {
  12424. int i;
  12425. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12426. if (sd->menuskill_id != SG_FEEL)
  12427. return;
  12428. i = sd->menuskill_val-1;
  12429. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12430. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12431. sd->feel_map[i].m = sd->bl.m;
  12432. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12433. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12434. // clif_misceffect2(&sd->bl, 0x1b0);
  12435. // clif_misceffect2(&sd->bl, 0x21f);
  12436. clif_feel_info(sd, i, 0);
  12437. clif_menuskill_clear(sd);
  12438. }
  12439. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12440. /// 0253 <which>.B
  12441. /// which:
  12442. /// 0 = sun
  12443. /// 1 = moon
  12444. /// 2 = star
  12445. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12446. {
  12447. WFIFOHEAD(fd,packet_len(0x253));
  12448. WFIFOW(fd,0)=0x253;
  12449. WFIFOB(fd,2)=TOB(skill_lv-1);
  12450. WFIFOSET(fd, packet_len(0x253));
  12451. sd->menuskill_id = SG_FEEL;
  12452. sd->menuskill_val = skill_lv;
  12453. }
  12454. /// Request to change homunculus' name (CZ_RENAME_MER).
  12455. /// 0231 <name>.24B
  12456. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12457. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12458. }
  12459. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12460. /// 0234 <id>.L
  12461. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12462. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12463. struct block_list *bl = NULL;
  12464. struct unit_data *ud = NULL;
  12465. if( sd->md && sd->md->bl.id == id )
  12466. bl = &sd->md->bl;
  12467. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12468. bl = &sd->hd->bl; // Moving Homunculus
  12469. else
  12470. return;
  12471. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12472. ud = unit_bl2ud(bl);
  12473. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12474. }
  12475. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12476. /// 0232 <id>.L <position data>.3B
  12477. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12478. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12479. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12480. struct block_list *bl = NULL;
  12481. short x, y;
  12482. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12483. if( sd->md && sd->md->bl.id == id )
  12484. bl = &sd->md->bl; // Moving Mercenary
  12485. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12486. bl = &sd->hd->bl; // Moving Homunculus
  12487. else
  12488. return;
  12489. unit_walktoxy(bl, x, y, 4);
  12490. }
  12491. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12492. /// 0233 <id>.L <target id>.L <action>.B
  12493. /// action:
  12494. /// always 0
  12495. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12496. {
  12497. struct block_list *bl = NULL;
  12498. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12499. int id = RFIFOL(fd,info->pos[0]);
  12500. int target_id = RFIFOL(fd,info->pos[1]);
  12501. int action_type = RFIFOB(fd,info->pos[2]);
  12502. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12503. bl = &sd->hd->bl;
  12504. else if( sd->md && sd->md->bl.id == id )
  12505. bl = &sd->md->bl;
  12506. else return;
  12507. unit_stop_attack(bl);
  12508. unit_attack(bl, target_id, action_type != 0);
  12509. }
  12510. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12511. /// 022d <type>.W <command>.B
  12512. /// type:
  12513. /// always 0
  12514. /// command:
  12515. /// 0 = homunculus information
  12516. /// 1 = feed
  12517. /// 2 = delete
  12518. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12519. { //[orn]
  12520. int cmd = RFIFOW(fd,0);
  12521. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12522. if(!hom_is_active(sd->hd))
  12523. return;
  12524. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12525. }
  12526. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12527. /// 0292
  12528. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12529. {
  12530. short item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  12531. uint8 hp = 100, sp = 100;
  12532. if (item_position < 0) {
  12533. if (sd->sc.data[SC_LIGHT_OF_REGENE]) {
  12534. // HP restored
  12535. hp = sd->sc.data[SC_LIGHT_OF_REGENE]->val2;
  12536. sp = 0;
  12537. }
  12538. else
  12539. return;
  12540. }
  12541. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  12542. return;
  12543. if (!status_revive(&sd->bl, hp, sp))
  12544. return;
  12545. if (item_position < 0)
  12546. status_change_end(&sd->bl, SC_LIGHT_OF_REGENE, INVALID_TIMER);
  12547. else
  12548. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  12549. clif_skill_nodamage(&sd->bl, &sd->bl, ALL_RESURRECTION, 4, 1);
  12550. }
  12551. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12552. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12553. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12554. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12555. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12556. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12557. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12558. void clif_check(int fd, struct map_session_data* pl_sd)
  12559. {
  12560. WFIFOHEAD(fd,packet_len(0x214));
  12561. WFIFOW(fd, 0) = 0x214;
  12562. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12563. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12564. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12565. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12566. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12567. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12568. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12569. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12570. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12571. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12572. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12573. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12574. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12575. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12576. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12577. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12578. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12579. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12580. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12581. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12582. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12583. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12584. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12585. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12586. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12587. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12588. WFIFOSET(fd,packet_len(0x214));
  12589. }
  12590. /// /check (CZ_REQ_STATUS_GM).
  12591. /// Request character's status values.
  12592. /// 0213 <char name>.24B
  12593. void clif_parse_Check(int fd, struct map_session_data *sd)
  12594. {
  12595. char charname[NAME_LENGTH];
  12596. struct map_session_data* pl_sd;
  12597. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12598. return;
  12599. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12600. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12601. {
  12602. return;
  12603. }
  12604. clif_check(fd, pl_sd);
  12605. }
  12606. /// MAIL SYSTEM
  12607. /// By Zephyrus
  12608. ///
  12609. /// Notification about the result of adding an item to mail
  12610. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  12611. /// result:
  12612. /// 0 = success
  12613. /// 1 = failure
  12614. /// 0a05 <result>.B <index>.W <amount>.W <item id>.W <item type>.B <identified>.B <damaged>.B <refine>.B (ZC_ACK_ADD_ITEM_TO_MAIL)
  12615. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  12616. /// result:
  12617. /// 0 = success
  12618. /// 1 = over weight
  12619. /// 2 = fatal error
  12620. void clif_Mail_setattachment(struct map_session_data* sd, int index, int amount, uint8 flag)
  12621. {
  12622. int fd = sd->fd;
  12623. #if PACKETVER < 20150513
  12624. WFIFOHEAD(fd,packet_len(0x255));
  12625. WFIFOW(fd,0) = 0x255;
  12626. WFIFOW(fd,2) = index;
  12627. WFIFOB(fd,4) = flag;
  12628. WFIFOSET(fd,packet_len(0x255));
  12629. #else
  12630. struct item* item = &sd->inventory.u.items_inventory[index-2];
  12631. int i, total = 0;
  12632. WFIFOHEAD(fd, 53);
  12633. WFIFOW(fd, 0) = 0xa05;
  12634. WFIFOB(fd, 2) = flag;
  12635. WFIFOW(fd, 3) = index;
  12636. WFIFOW(fd, 5) = amount;
  12637. WFIFOW(fd, 7) = item->nameid;
  12638. WFIFOB(fd, 9) = itemtype(item->nameid);
  12639. WFIFOB(fd, 10) = item->identify;
  12640. WFIFOB(fd, 11) = item->attribute;
  12641. WFIFOB(fd, 12) = item->refine;
  12642. clif_addcards(WFIFOP(fd,13), item);
  12643. clif_add_random_options(WFIFOP(fd,21), item);
  12644. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  12645. if( sd->mail.item[i].nameid == 0 ){
  12646. break;
  12647. }
  12648. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  12649. }
  12650. WFIFOW(fd, 46) = total;
  12651. // 5 empty unknown bytes
  12652. memset(WFIFOP(fd, 48), 0, 5);
  12653. WFIFOSET(fd, 53);
  12654. #endif
  12655. }
  12656. /// Notification about the result of retrieving a mail attachment
  12657. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  12658. /// result:
  12659. /// 0 = success
  12660. /// 1 = failure
  12661. /// 2 = too many items
  12662. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  12663. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  12664. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  12665. int fd = sd->fd;
  12666. #if PACKETVER < 20150513
  12667. WFIFOHEAD(fd,packet_len(0x245));
  12668. WFIFOW(fd,0) = 0x245;
  12669. WFIFOB(fd,2) = result;
  12670. WFIFOSET(fd,packet_len(0x245));
  12671. #else
  12672. switch( type ){
  12673. case MAIL_ATT_ITEM:
  12674. case MAIL_ATT_ZENY:
  12675. break;
  12676. default:
  12677. return;
  12678. }
  12679. WFIFOHEAD(fd, 12);
  12680. WFIFOW(fd, 0) = type == MAIL_ATT_ZENY ? 0x9f2 : 0x9f4;
  12681. WFIFOQ(fd, 2) = msg->id;
  12682. WFIFOB(fd, 10) = msg->type;
  12683. WFIFOB(fd, 11) = result;
  12684. WFIFOSET(fd, 12);
  12685. clif_Mail_refreshinbox( sd, msg->type, 0 );
  12686. #endif
  12687. }
  12688. /// Notification about the result of sending a mail
  12689. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  12690. /// result:
  12691. /// 0 = success
  12692. /// 1 = recipinent does not exist
  12693. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  12694. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  12695. int fd = sd->fd;
  12696. #if PACKETVER < 20150513
  12697. WFIFOHEAD(fd,packet_len(0x249));
  12698. WFIFOW(fd,0) = 0x249;
  12699. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  12700. WFIFOSET(fd,packet_len(0x249));
  12701. #else
  12702. WFIFOHEAD(fd, 3);
  12703. WFIFOW(fd, 0) = 0x9ed;
  12704. WFIFOB(fd, 2) = result;
  12705. WFIFOSET(fd, 3);
  12706. #endif
  12707. }
  12708. /// Notification about the result of deleting a mail.
  12709. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  12710. /// result:
  12711. /// 0 = success
  12712. /// 1 = failure
  12713. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  12714. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  12715. int fd = sd->fd;
  12716. #if PACKETVER < 20150513
  12717. WFIFOHEAD(fd, packet_len(0x257));
  12718. WFIFOW(fd,0) = 0x257;
  12719. WFIFOL(fd,2) = msg->id;
  12720. WFIFOW(fd,6) = !success;
  12721. WFIFOSET(fd, packet_len(0x257));
  12722. #else
  12723. // This is only a success notification
  12724. if( success ){
  12725. WFIFOHEAD(fd, 11);
  12726. WFIFOW(fd, 0) = 0x9f6;
  12727. WFIFOB(fd, 2) = msg->type;
  12728. WFIFOQ(fd, 3) = msg->id;
  12729. WFIFOSET(fd, 11);
  12730. }
  12731. #endif
  12732. }
  12733. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12734. /// 0274 <mail id>.L <result>.W
  12735. /// result:
  12736. /// 0 = success
  12737. /// 1 = failure
  12738. void clif_Mail_return(int fd, int mail_id, short fail)
  12739. {
  12740. WFIFOHEAD(fd,packet_len(0x274));
  12741. WFIFOW(fd,0) = 0x274;
  12742. WFIFOL(fd,2) = mail_id;
  12743. WFIFOW(fd,6) = fail;
  12744. WFIFOSET(fd,packet_len(0x274));
  12745. }
  12746. /// Notification about new mail.
  12747. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  12748. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  12749. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  12750. int fd = sd->fd;
  12751. #if PACKETVER < 20150513
  12752. WFIFOHEAD(fd,packet_len(0x24a));
  12753. WFIFOW(fd,0) = 0x24a;
  12754. WFIFOL(fd,2) = mail_id;
  12755. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  12756. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  12757. WFIFOSET(fd,packet_len(0x24a));
  12758. #else
  12759. WFIFOHEAD(fd,3);
  12760. WFIFOW(fd,0) = 0x9e7;
  12761. WFIFOB(fd,2) = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  12762. WFIFOSET(fd,3);
  12763. #endif
  12764. }
  12765. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12766. /// 0260 <type>.L
  12767. /// type:
  12768. /// 0 = open
  12769. /// 1 = close
  12770. void clif_Mail_window(int fd, int flag)
  12771. {
  12772. WFIFOHEAD(fd,packet_len(0x260));
  12773. WFIFOW(fd,0) = 0x260;
  12774. WFIFOL(fd,2) = flag;
  12775. WFIFOSET(fd,packet_len(0x260));
  12776. }
  12777. /// Lists mails stored in inbox.
  12778. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  12779. /// read:
  12780. /// 0 = unread
  12781. /// 1 = read
  12782. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  12783. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12784. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  12785. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12786. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  12787. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  12788. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  12789. #if PACKETVER < 20150513
  12790. int fd = sd->fd;
  12791. struct mail_data *md = &sd->mail.inbox;
  12792. struct mail_message *msg;
  12793. int len, i, j;
  12794. len = 8 + (73 * md->amount);
  12795. WFIFOHEAD(fd,len);
  12796. WFIFOW(fd,0) = 0x240;
  12797. WFIFOW(fd,2) = len;
  12798. WFIFOL(fd,4) = md->amount;
  12799. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12800. {
  12801. msg = &md->msg[i];
  12802. if (msg->id < 1)
  12803. continue;
  12804. WFIFOL(fd,8+73*j) = msg->id;
  12805. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12806. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12807. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12808. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12809. j++;
  12810. }
  12811. WFIFOSET(fd,len);
  12812. if( md->full ) {// TODO: is this official?
  12813. char output[100];
  12814. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12815. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  12816. }
  12817. #else
  12818. int fd = sd->fd;
  12819. struct mail_data *md = &sd->mail.inbox;
  12820. struct mail_message *msg;
  12821. int i, j, k, offset, titleLength;
  12822. uint8 mailType, amount, remaining;
  12823. uint32 now = (uint32)time(NULL);
  12824. #if PACKETVER >= 20170419
  12825. int cmd = 0xac2;
  12826. #elif PACKETVER >= 20160601
  12827. int cmd = 0xa7d;
  12828. #else
  12829. int cmd = 0x9f0;
  12830. #endif
  12831. if( battle_config.mail_daily_count ){
  12832. mail_refresh_remaining_amount(sd);
  12833. }
  12834. #if PACKETVER >= 20170419
  12835. // Always send all
  12836. i = md->amount;
  12837. #else
  12838. // If a starting mail id was sent
  12839. if( mailID != 0 ){
  12840. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  12841. // Unknown mail
  12842. if( i == md->amount ){
  12843. // Ignore the request for now
  12844. return; // TODO: Should we just show the first page instead?
  12845. }
  12846. // It was actually the oldest/first mail, there is no further page
  12847. if( i == 0 ){
  12848. return;
  12849. }
  12850. // We actually want the next/older mail
  12851. i -= 1;
  12852. }else{
  12853. i = md->amount;
  12854. }
  12855. #endif
  12856. // Count the remaining mails from the starting mail or the beginning
  12857. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  12858. for( j = i, remaining = 0; j >= 0; j-- ){
  12859. msg = &md->msg[j];
  12860. if (msg->id < 1)
  12861. continue;
  12862. #if PACKETVER < 20170419
  12863. if (msg->type != type)
  12864. continue;
  12865. #endif
  12866. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  12867. continue;
  12868. remaining++;
  12869. }
  12870. #if PACKETVER >= 20170419
  12871. // Always send all
  12872. amount = remaining;
  12873. #else
  12874. if( remaining > MAIL_PAGE_SIZE ){
  12875. amount = MAIL_PAGE_SIZE;
  12876. }else{
  12877. amount = remaining;
  12878. }
  12879. #endif
  12880. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  12881. WFIFOW(fd, 0) = cmd;
  12882. #if PACKETVER >= 20170419
  12883. WFIFOB(fd, 4) = 1; // Unknown
  12884. offset = 5;
  12885. #else
  12886. WFIFOB(fd, 4) = type;
  12887. WFIFOB(fd, 5) = amount;
  12888. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  12889. offset = 7;
  12890. #endif
  12891. for( amount = 0; i >= 0; i-- ){
  12892. msg = &md->msg[i];
  12893. if (msg->id < 1)
  12894. continue;
  12895. #if PACKETVER < 20170419
  12896. if (msg->type != type)
  12897. continue;
  12898. #endif
  12899. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  12900. continue;
  12901. #if PACKETVER >= 20170419
  12902. WFIFOB(fd, offset) = msg->type;
  12903. offset += 1;
  12904. #endif
  12905. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  12906. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  12907. mailType = MAIL_TYPE_TEXT; // Normal letter
  12908. if( msg->zeny > 0 ){
  12909. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  12910. }
  12911. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  12912. if( msg->item[k].nameid > 0 ){
  12913. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  12914. break;
  12915. }
  12916. }
  12917. // If it came from an npc?
  12918. //mailType |= MAIL_TYPE_NPC;
  12919. WFIFOB(fd, offset + 9) = mailType;
  12920. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  12921. #if PACKETVER < 20170419
  12922. // How much time has passed since you received the mail
  12923. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  12924. offset += 4;
  12925. #endif
  12926. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  12927. if( msg->scheduled_deletion > 0 ){
  12928. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  12929. }else{
  12930. // Fake the scheduled deletion to one year in the future
  12931. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  12932. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  12933. }
  12934. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  12935. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  12936. offset += 40 + titleLength;
  12937. }
  12938. WFIFOW(fd, 2) = (int16)offset;
  12939. WFIFOSET(fd, offset);
  12940. #endif
  12941. }
  12942. /// Mail inbox list request.
  12943. /// 023f (CZ_MAIL_GET_LIST)
  12944. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  12945. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  12946. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  12947. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  12948. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  12949. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  12950. #if PACKETVER < 20150513
  12951. struct mail_data* md = &sd->mail.inbox;
  12952. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  12953. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  12954. else
  12955. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  12956. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  12957. mail_removezeny(sd, false);
  12958. #else
  12959. int cmd = RFIFOW(fd, 0);
  12960. #if PACKETVER < 20170419
  12961. uint8 openType = RFIFOB(fd, 2);
  12962. uint64 mailId = RFIFOQ(fd, 3);
  12963. #else
  12964. uint8 openType;
  12965. uint64 mailId = RFIFOQ(fd, 2);
  12966. int i;
  12967. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  12968. if( i == MAIL_MAX_INBOX ){
  12969. openType = MAIL_INBOX_NORMAL;
  12970. mailId = 0;
  12971. }else{
  12972. openType = sd->mail.inbox.msg[i].type;
  12973. mailId = 0;
  12974. }
  12975. #endif
  12976. switch( openType ){
  12977. case MAIL_INBOX_NORMAL:
  12978. case MAIL_INBOX_ACCOUNT:
  12979. case MAIL_INBOX_RETURNED:
  12980. break;
  12981. default:
  12982. // Unknown type: ignore request
  12983. return;
  12984. }
  12985. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  12986. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  12987. return;
  12988. }
  12989. // If it is not a next page request
  12990. if( cmd != 0x9ee ){
  12991. mailId = 0;
  12992. }
  12993. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  12994. #endif
  12995. }
  12996. /// Opens a mail
  12997. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  12998. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  12999. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13000. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13001. /// { }*n
  13002. // TODO: Packet description => for repeated block
  13003. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  13004. {
  13005. int i, fd = sd->fd;
  13006. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13007. if( i == MAIL_MAX_INBOX ) {
  13008. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13009. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13010. return;
  13011. } else {
  13012. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13013. struct item *item;
  13014. struct item_data *data;
  13015. int msg_len = strlen(msg->body), len;
  13016. #if PACKETVER >= 20150513
  13017. int offset, j, itemsize, count = 0;
  13018. #endif
  13019. if( msg_len == 0 ) {
  13020. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13021. msg_len = strlen(msg->body);
  13022. }
  13023. #if PACKETVER < 20150513
  13024. item = &msg->item[0];
  13025. len = 101 + msg_len;
  13026. WFIFOHEAD(fd,len);
  13027. WFIFOW(fd,0) = 0x242;
  13028. WFIFOW(fd,2) = len;
  13029. WFIFOL(fd,4) = msg->id;
  13030. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13031. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13032. WFIFOL(fd,72) = 0;
  13033. WFIFOL(fd,76) = msg->zeny;
  13034. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  13035. WFIFOL(fd,80) = item->amount;
  13036. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  13037. WFIFOW(fd,86) = data->type;
  13038. WFIFOB(fd,88) = item->identify;
  13039. WFIFOB(fd,89) = item->attribute;
  13040. WFIFOB(fd,90) = item->refine;
  13041. WFIFOW(fd,91) = item->card[0];
  13042. WFIFOW(fd,93) = item->card[1];
  13043. WFIFOW(fd,95) = item->card[2];
  13044. WFIFOW(fd,97) = item->card[3];
  13045. } else // no item, set all to zero
  13046. memset(WFIFOP(fd,80), 0x00, 19);
  13047. WFIFOB(fd,99) = (unsigned char)msg_len;
  13048. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13049. WFIFOSET(fd,len);
  13050. #else
  13051. // Count the attached items
  13052. ARR_FIND( 0, MAIL_MAX_ITEM, count, msg->item[count].nameid == 0 );
  13053. msg_len += 1; // Zero Termination
  13054. itemsize = 24 + 5 * MAX_ITEM_RDM_OPT;
  13055. len = 24 + msg_len+1 + itemsize * count;
  13056. WFIFOHEAD(fd, len);
  13057. WFIFOW(fd, 0) = 0x9eb;
  13058. WFIFOW(fd, 2) = len;
  13059. WFIFOB(fd, 4) = msg->type;
  13060. WFIFOQ(fd, 5) = msg->id;
  13061. WFIFOW(fd, 13) = msg_len;
  13062. WFIFOQ(fd, 15) = msg->zeny;
  13063. WFIFOB(fd, 23) = (uint8)count; // item count
  13064. safestrncpy(WFIFOCP(fd, 24), msg->body, msg_len);
  13065. offset = 24 + msg_len;
  13066. for (j = 0; j < MAIL_MAX_ITEM; j++) {
  13067. item = &msg->item[j];
  13068. if (item->nameid > 0 && item->amount > 0 && (data = itemdb_exists(item->nameid)) != NULL) {
  13069. WFIFOW(fd, offset) = item->amount;
  13070. WFIFOW(fd, offset + 2) = (data->view_id) ? data->view_id : item->nameid;
  13071. WFIFOB(fd, offset + 4) = item->identify;
  13072. WFIFOB(fd, offset + 5) = item->attribute;
  13073. WFIFOB(fd, offset + 6) = item->refine;
  13074. clif_addcards(WFIFOP(fd, offset + 7), item);
  13075. // 4B unsigned long location
  13076. WFIFOB(fd, offset + 15 + 4) = data->type;
  13077. // 2B unsigned short wItemSpriteNumber
  13078. //WFIFOW(fd, offset + 15 + 5) = data->view_id;
  13079. // 2B unsigned short bindOnEquipType
  13080. clif_add_random_options(WFIFOP(fd, offset + 15 + 9 ), item);
  13081. offset += itemsize;
  13082. }
  13083. }
  13084. WFIFOSET(fd, len);
  13085. #endif
  13086. if (msg->status == MAIL_UNREAD) {
  13087. msg->status = MAIL_READ;
  13088. intif_Mail_read(mail_id);
  13089. clif_parse_Mail_refreshinbox(fd, sd);
  13090. sd->mail.inbox.unread--;
  13091. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13092. }
  13093. }
  13094. }
  13095. /// Request to open a mail.
  13096. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13097. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13098. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13099. #if PACKETVER < 20150513
  13100. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13101. #else
  13102. //uint8 openType = RFIFOB(fd, 2);
  13103. int mail_id = (int)RFIFOQ(fd, 3);
  13104. #endif
  13105. if( mail_id <= 0 )
  13106. return;
  13107. if( mail_invalid_operation(sd) )
  13108. return;
  13109. clif_Mail_read(sd, mail_id);
  13110. }
  13111. /// Allow a player to begin writing a mail
  13112. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13113. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13114. int fd = sd->fd;
  13115. WFIFOHEAD(fd, 27);
  13116. WFIFOW(fd, 0) = 0xa12;
  13117. safestrncpy(WFIFOCP(fd, 2), name, NAME_LENGTH);
  13118. WFIFOB(fd, 26) = success;
  13119. WFIFOSET(fd, 27);
  13120. }
  13121. /// Request to start writing a mail
  13122. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13123. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13124. char name[NAME_LENGTH];
  13125. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13126. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13127. clif_send_Mail_beginwrite_ack(sd, name, false);
  13128. return;
  13129. }
  13130. mail_clear(sd);
  13131. sd->state.mail_writing = true;
  13132. clif_send_Mail_beginwrite_ack(sd, name,true);
  13133. }
  13134. /// Notification that the client cancelled writing a mail
  13135. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13136. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13137. sd->state.mail_writing = false;
  13138. }
  13139. /// Give the client information about the recipient, if available
  13140. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13141. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13142. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13143. int fd = sd->fd;
  13144. #if PACKETVER <= 20160302
  13145. int cmd = 0xa14;
  13146. #else
  13147. int cmd = 0xa51;
  13148. #endif
  13149. WFIFOHEAD(fd, packet_len(cmd));
  13150. WFIFOW(fd, 0) = cmd;
  13151. WFIFOL(fd, 2) = char_id;
  13152. WFIFOW(fd, 6) = class_;
  13153. WFIFOW(fd, 8) = level;
  13154. #if PACKETVER >= 20160302
  13155. strncpy(WFIFOCP(fd, 10), name, NAME_LENGTH);
  13156. #endif
  13157. WFIFOSET(fd, packet_len(cmd));
  13158. }
  13159. /// Request information about the recipient
  13160. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13161. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13162. static char name[NAME_LENGTH];
  13163. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13164. intif_mail_checkreceiver(sd, name);
  13165. }
  13166. /// Request to receive mail's attachment.
  13167. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13168. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13169. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13170. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13171. int i;
  13172. struct mail_message* msg;
  13173. #if PACKETVER < 20150513
  13174. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13175. int attachment = MAIL_ATT_ALL;
  13176. #else
  13177. uint16 packet_id = RFIFOW(fd, 0);
  13178. int mail_id = (int)RFIFOQ(fd, 2);
  13179. //int openType = RFIFOB(fd, 10);
  13180. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13181. #endif
  13182. if( !chrif_isconnected() )
  13183. return;
  13184. if( mail_id <= 0 )
  13185. return;
  13186. if( mail_invalid_operation(sd) )
  13187. return;
  13188. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13189. if( i == MAIL_MAX_INBOX )
  13190. return;
  13191. msg = &sd->mail.inbox.msg[i];
  13192. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13193. attachment &= ~MAIL_ATT_ZENY;
  13194. }
  13195. if( attachment&MAIL_ATT_ITEM ){
  13196. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13197. // No items were found
  13198. if( i == MAIL_MAX_ITEM ){
  13199. attachment &= ~MAIL_ATT_ITEM;
  13200. }
  13201. }
  13202. // Either no attachment requested at all or there are no zeny or items in the mail
  13203. if( attachment == MAIL_ATT_NONE ){
  13204. return;
  13205. }
  13206. if( attachment&MAIL_ATT_ZENY ){
  13207. if( msg->zeny + sd->status.zeny > MAX_ZENY ){
  13208. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13209. return;
  13210. }else{
  13211. // To make sure another request fails
  13212. msg->zeny = 0;
  13213. }
  13214. }
  13215. if( attachment&MAIL_ATT_ITEM ){
  13216. int new_ = 0, totalweight = 0;
  13217. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13218. struct item* item = &msg->item[i];
  13219. if( item->nameid > 0 && item->amount > 0 ){
  13220. struct item_data *data;
  13221. if((data = itemdb_exists(item->nameid)) == NULL)
  13222. continue;
  13223. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13224. case CHKADDITEM_NEW:
  13225. new_++;
  13226. break;
  13227. case CHKADDITEM_OVERAMOUNT:
  13228. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13229. return;
  13230. }
  13231. totalweight += data->weight * item->amount;
  13232. }
  13233. }
  13234. if( ( totalweight + sd->weight ) > sd->max_weight ){
  13235. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13236. return;
  13237. }else if( pc_inventoryblank(sd) < new_ ){
  13238. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13239. return;
  13240. }
  13241. // To make sure another request fails
  13242. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13243. }
  13244. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13245. clif_Mail_read(sd, mail_id);
  13246. }
  13247. /// Request to delete a mail.
  13248. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13249. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13250. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13251. #if PACKETVER < 20150513
  13252. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13253. #else
  13254. //int openType = RFIFOB(fd, 2);
  13255. int mail_id = (int)RFIFOQ(fd, 3);
  13256. #endif
  13257. int i, j;
  13258. if( !chrif_isconnected() )
  13259. return;
  13260. if( mail_id <= 0 )
  13261. return;
  13262. if( mail_invalid_operation(sd) )
  13263. return;
  13264. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13265. if (i < MAIL_MAX_INBOX) {
  13266. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13267. // can't delete mail without removing zeny first
  13268. if( msg->zeny > 0 ){
  13269. clif_mail_delete(sd, msg, false);
  13270. return;
  13271. }
  13272. // can't delete mail without removing attachment(s) first
  13273. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13274. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13275. clif_mail_delete(sd, msg, false);
  13276. return;
  13277. }
  13278. }
  13279. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13280. sd->mail.inbox.unread--;
  13281. clif_Mail_new(sd,0,NULL,NULL);
  13282. }
  13283. }
  13284. }
  13285. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13286. /// 0273 <mail id>.L <receive name>.24B
  13287. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13288. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13289. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13290. int i;
  13291. if( mail_id <= 0 )
  13292. return;
  13293. if( mail_invalid_operation(sd) )
  13294. return;
  13295. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13296. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13297. intif_Mail_return(sd->status.char_id, mail_id);
  13298. else
  13299. clif_Mail_return(sd->fd, mail_id, 1);
  13300. }
  13301. /// Request to add an item or Zeny to mail.
  13302. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13303. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13304. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13305. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13306. int idx = RFIFOW(fd,info->pos[0]);
  13307. #if PACKETVER < 20150513
  13308. int amount = RFIFOL(fd,info->pos[1]);
  13309. #else
  13310. int amount = RFIFOW(fd,info->pos[1]);
  13311. #endif
  13312. unsigned char flag;
  13313. if( !chrif_isconnected() )
  13314. return;
  13315. if (idx < 0 || amount < 0)
  13316. return;
  13317. flag = mail_setitem(sd, idx, amount);
  13318. clif_Mail_setattachment(sd,idx,amount,flag);
  13319. }
  13320. /// Remove an item from a mail
  13321. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13322. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13323. int fd = sd->fd;
  13324. WFIFOHEAD(fd, 9);
  13325. WFIFOW(fd, 0) = 0xa07;
  13326. WFIFOB(fd, 2) = success;
  13327. WFIFOW(fd, 3) = index;
  13328. WFIFOW(fd, 5) = amount;
  13329. WFIFOW(fd, 7) = 0; // TODO: which weight? item weight? removed weight? remaining weight?
  13330. WFIFOSET(fd, 9);
  13331. }
  13332. /// Request to reset mail item and/or Zeny
  13333. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13334. /// type:
  13335. /// 0 = reset all
  13336. /// 1 = remove item
  13337. /// 2 = remove zeny
  13338. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13339. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13340. {
  13341. #if PACKETVER < 20150513
  13342. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13343. if (type == 0 || type == 1)
  13344. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13345. if (type == 0 || type == 2)
  13346. mail_removezeny(sd, false);
  13347. #else
  13348. uint16 index = RFIFOW(fd, 2);
  13349. uint16 count = RFIFOW(fd, 4);
  13350. mail_removeitem(sd,0,index,count);
  13351. #endif
  13352. }
  13353. /// Request to send mail
  13354. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13355. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13356. /// 0a6e <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <char id>.L <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL2)
  13357. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  13358. #if PACKETVER < 20150513
  13359. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13360. if( !chrif_isconnected() )
  13361. return;
  13362. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13363. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13364. return;
  13365. }
  13366. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13367. #else
  13368. unsigned short length;
  13369. static char receiver[NAME_LENGTH];
  13370. static char sender[NAME_LENGTH];
  13371. char *title;
  13372. char *text;
  13373. uint64 zeny;
  13374. uint16 titleLength;
  13375. uint16 textLength;
  13376. length = RFIFOW(fd, 2);
  13377. if( length < 0x3e ){
  13378. ShowWarning("Too short...\n");
  13379. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13380. return;
  13381. }
  13382. // Forged request without a begin writing packet?
  13383. if( !sd->state.mail_writing ){
  13384. return; // Ignore it
  13385. }
  13386. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13387. safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13388. zeny = RFIFOQ(fd, 52);
  13389. titleLength = RFIFOW(fd, 60);
  13390. textLength = RFIFOW(fd, 62);
  13391. title = (char*)aMalloc(titleLength);
  13392. text = (char*)aMalloc(textLength);
  13393. #if PACKETVER <= 20160330
  13394. safestrncpy(title, RFIFOCP(fd, 64), titleLength);
  13395. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), textLength);
  13396. #else
  13397. // 64 = <char id>.L
  13398. safestrncpy(title, RFIFOCP(fd, 68), titleLength);
  13399. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), textLength);
  13400. #endif
  13401. if( zeny > 0 ){
  13402. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13403. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13404. return;
  13405. }
  13406. }
  13407. mail_send(sd, receiver, title, text, textLength);
  13408. aFree(title);
  13409. aFree(text);
  13410. #endif
  13411. }
  13412. /// AUCTION SYSTEM
  13413. /// By Zephyrus
  13414. ///
  13415. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13416. /// 025f <type>.L
  13417. /// type:
  13418. /// 0 = open
  13419. /// 1 = close
  13420. void clif_Auction_openwindow(struct map_session_data *sd)
  13421. {
  13422. int fd = sd->fd;
  13423. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13424. return;
  13425. if( !battle_config.feature_auction )
  13426. return;
  13427. WFIFOHEAD(fd,packet_len(0x25f));
  13428. WFIFOW(fd,0) = 0x25f;
  13429. WFIFOL(fd,2) = 0;
  13430. WFIFOSET(fd,packet_len(0x25f));
  13431. }
  13432. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13433. /// 0252 <packet len>.W <pages>.L <count>.L { <auction id>.L <seller name>.24B <name id>.W <type>.L <amount>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <now price>.L <max price>.L <buyer name>.24B <delete time>.L }*
  13434. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  13435. {
  13436. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13437. struct auction_data auction;
  13438. struct item_data *item;
  13439. WFIFOHEAD(fd,12 + (count * 83));
  13440. WFIFOW(fd,0) = 0x252;
  13441. WFIFOW(fd,2) = 12 + (count * 83);
  13442. WFIFOL(fd,4) = pages;
  13443. WFIFOL(fd,8) = count;
  13444. for( i = 0; i < count; i++ ) {
  13445. int k = 12 + (i * 83);
  13446. memcpy(&auction, RBUFP(buf,i * len), len);
  13447. WFIFOL(fd,k) = auction.auction_id;
  13448. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13449. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  13450. WFIFOW(fd,28+k) = item->view_id;
  13451. else
  13452. WFIFOW(fd,28+k) = auction.item.nameid;
  13453. WFIFOL(fd,30+k) = auction.type;
  13454. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13455. WFIFOB(fd,36+k) = auction.item.identify;
  13456. WFIFOB(fd,37+k) = auction.item.attribute;
  13457. WFIFOB(fd,38+k) = auction.item.refine;
  13458. WFIFOW(fd,39+k) = auction.item.card[0];
  13459. WFIFOW(fd,41+k) = auction.item.card[1];
  13460. WFIFOW(fd,43+k) = auction.item.card[2];
  13461. WFIFOW(fd,45+k) = auction.item.card[3];
  13462. WFIFOL(fd,47+k) = auction.price;
  13463. WFIFOL(fd,51+k) = auction.buynow;
  13464. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13465. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13466. }
  13467. WFIFOSET(fd,WFIFOW(fd,2));
  13468. }
  13469. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13470. /// 0256 <index>.W <result>.B
  13471. /// result:
  13472. /// 0 = success
  13473. /// 1 = failure
  13474. static void clif_Auction_setitem(int fd, int index, bool fail)
  13475. {
  13476. WFIFOHEAD(fd,packet_len(0x256));
  13477. WFIFOW(fd,0) = 0x256;
  13478. WFIFOW(fd,2) = index;
  13479. WFIFOB(fd,4) = fail;
  13480. WFIFOSET(fd,packet_len(0x256));
  13481. }
  13482. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13483. /// 024b <type>.W
  13484. /// type:
  13485. /// 0 = create (any other action in auction window)
  13486. /// 1 = cancel (cancel pressed on register tab)
  13487. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13488. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  13489. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13490. if( sd->auction.amount > 0 )
  13491. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13492. sd->auction.amount = 0;
  13493. }
  13494. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13495. /// 024c <index>.W <count>.L
  13496. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  13497. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13498. int idx = RFIFOW(fd,info->pos[0]) - 2;
  13499. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  13500. struct item_data *item;
  13501. if( !battle_config.feature_auction )
  13502. return;
  13503. if( sd->auction.amount > 0 )
  13504. sd->auction.amount = 0;
  13505. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13506. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13507. return;
  13508. }
  13509. if( amount != 1 || amount > sd->inventory.u.items_inventory[idx].amount ) { // By client, amount is always set to 1. Maybe this is a future implementation.
  13510. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13511. return;
  13512. }
  13513. if( (item = itemdb_exists(sd->inventory.u.items_inventory[idx].nameid)) != NULL && !(item->type == IT_ARMOR || item->type == IT_PETARMOR || item->type == IT_WEAPON || item->type == IT_CARD || item->type == IT_ETC || item->type == IT_SHADOWGEAR) )
  13514. { // Consumable or pets are not allowed
  13515. clif_Auction_setitem(sd->fd, idx, true);
  13516. return;
  13517. }
  13518. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13519. !sd->inventory.u.items_inventory[idx].identify ||
  13520. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13521. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13522. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13523. clif_Auction_setitem(sd->fd, idx, true);
  13524. return;
  13525. }
  13526. sd->auction.index = idx;
  13527. sd->auction.amount = amount;
  13528. clif_Auction_setitem(fd, idx + 2, false);
  13529. }
  13530. /// Result from an auction action (ZC_AUCTION_RESULT).
  13531. /// 0250 <result>.B
  13532. /// result:
  13533. /// 0 = You have failed to bid into the auction
  13534. /// 1 = You have successfully bid in the auction
  13535. /// 2 = The auction has been canceled
  13536. /// 3 = An auction with at least one bidder cannot be canceled
  13537. /// 4 = You cannot register more than 5 items in an auction at a time
  13538. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13539. /// 6 = You have won the auction
  13540. /// 7 = You have failed to win the auction
  13541. /// 8 = You do not have enough Zeny
  13542. /// 9 = You cannot place more than 5 bids at a time
  13543. void clif_Auction_message(int fd, unsigned char flag)
  13544. {
  13545. WFIFOHEAD(fd,packet_len(0x250));
  13546. WFIFOW(fd,0) = 0x250;
  13547. WFIFOB(fd,2) = flag;
  13548. WFIFOSET(fd,packet_len(0x250));
  13549. }
  13550. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13551. /// 025e <result>.W
  13552. /// result:
  13553. /// 0 = You have ended the auction
  13554. /// 1 = You cannot end the auction
  13555. /// 2 = Auction ID is incorrect
  13556. void clif_Auction_close(int fd, unsigned char flag)
  13557. {
  13558. WFIFOHEAD(fd,packet_len(0x25e));
  13559. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13560. WFIFOW(fd,2) = flag;
  13561. WFIFOSET(fd,packet_len(0x25e));
  13562. }
  13563. /// Request to add an auction (CZ_AUCTION_ADD).
  13564. /// 024d <now money>.L <max money>.L <delete hour>.W
  13565. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  13566. {
  13567. struct auction_data auction;
  13568. struct item_data *item;
  13569. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13570. if( !battle_config.feature_auction )
  13571. return;
  13572. auction.price = RFIFOL(fd,info->pos[0]);
  13573. auction.buynow = RFIFOL(fd,info->pos[1]);
  13574. auction.hours = RFIFOW(fd,info->pos[2]);
  13575. // Invalid Situations...
  13576. if( sd->auction.amount < 1 ) {
  13577. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  13578. return;
  13579. }
  13580. if( auction.price >= auction.buynow ) {
  13581. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  13582. return;
  13583. }
  13584. if( auction.hours < 1 || auction.hours > 48 ) {
  13585. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  13586. return;
  13587. }
  13588. // Auction checks...
  13589. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  13590. clif_displaymessage(sd->fd, msg_txt(sd,293));
  13591. clif_Auction_message(fd, 2); // The auction has been canceled
  13592. return;
  13593. }
  13594. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  13595. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  13596. return;
  13597. }
  13598. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  13599. auction.buynow = battle_config.auction_maximumprice;
  13600. if( auction.price >= auction.buynow )
  13601. auction.price = auction.buynow - 1;
  13602. }
  13603. auction.auction_id = 0;
  13604. auction.seller_id = sd->status.char_id;
  13605. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  13606. auction.buyer_id = 0;
  13607. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  13608. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  13609. {
  13610. clif_Auction_message(fd, 2); // The auction has been canceled
  13611. return;
  13612. }
  13613. if( (item = itemdb_exists(sd->inventory.u.items_inventory[sd->auction.index].nameid)) == NULL )
  13614. { // Just in case
  13615. clif_Auction_message(fd, 2); // The auction has been canceled
  13616. return;
  13617. }
  13618. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  13619. auction.type = item->type;
  13620. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  13621. auction.item.amount = 1;
  13622. auction.timestamp = 0;
  13623. if( !intif_Auction_register(&auction) )
  13624. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  13625. else
  13626. {
  13627. int zeny = auction.hours*battle_config.auction_feeperhour;
  13628. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  13629. sd->auction.amount = 0;
  13630. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  13631. }
  13632. }
  13633. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  13634. /// 024e <auction id>.L
  13635. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  13636. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13637. intif_Auction_cancel(sd->status.char_id, auction_id);
  13638. }
  13639. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  13640. /// 025d <auction id>.L
  13641. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  13642. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13643. intif_Auction_close(sd->status.char_id, auction_id);
  13644. }
  13645. /// Places a bid on an auction (CZ_AUCTION_BUY).
  13646. /// 024f <auction id>.L <money>.L
  13647. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  13648. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13649. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  13650. int bid = RFIFOL(fd,info->pos[1]);
  13651. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  13652. clif_displaymessage(sd->fd, msg_txt(sd,246));
  13653. return;
  13654. }
  13655. if( bid <= 0 )
  13656. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13657. else if( bid > sd->status.zeny )
  13658. clif_Auction_message(fd, 8); // You do not have enough zeny
  13659. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  13660. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13661. else {
  13662. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  13663. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  13664. }
  13665. }
  13666. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  13667. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  13668. /// search type:
  13669. /// 0 = armor
  13670. /// 1 = weapon
  13671. /// 2 = card
  13672. /// 3 = misc
  13673. /// 4 = name search
  13674. /// 5 = auction id search
  13675. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  13676. char search_text[NAME_LENGTH];
  13677. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13678. short type = RFIFOW(fd,info->pos[0]);
  13679. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  13680. int page = RFIFOW(fd,info->pos[3]);
  13681. if( !battle_config.feature_auction )
  13682. return;
  13683. clif_parse_Auction_cancelreg(fd, sd);
  13684. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  13685. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  13686. }
  13687. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  13688. /// 025c <type>.W
  13689. /// type:
  13690. /// 0 = sell (own auctions)
  13691. /// 1 = buy (own bids)
  13692. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  13693. {
  13694. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  13695. if( !battle_config.feature_auction )
  13696. return;
  13697. clif_parse_Auction_cancelreg(fd, sd);
  13698. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  13699. }
  13700. /// CASH/POINT SHOP
  13701. ///
  13702. void clif_cashshop_open( struct map_session_data* sd ){
  13703. WFIFOHEAD( sd->fd, 10 );
  13704. WFIFOW( sd->fd, 0 ) = 0x845;
  13705. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  13706. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  13707. WFIFOSET( sd->fd, 10 );
  13708. }
  13709. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13710. sd->state.cashshop_open = true;
  13711. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13712. clif_cashshop_open( sd );
  13713. }
  13714. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  13715. sd->state.cashshop_open = false;
  13716. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13717. // No need to do anything here
  13718. }
  13719. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  13720. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  13721. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  13722. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  13723. int j;
  13724. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  13725. return;
  13726. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  13727. WFIFOW(fd, 0) = 0x8c0;
  13728. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  13729. WFIFOL(fd, 4) = tab;
  13730. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  13731. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  13732. struct item_data *id = itemdb_search(cash_shop_items[tab].item[j]->nameid);
  13733. WFIFOW(fd, 10 + ( 6 * j ) ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[j]->nameid;
  13734. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  13735. }
  13736. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  13737. }
  13738. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  13739. void clif_cashshop_list( int fd ){
  13740. int tab;
  13741. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  13742. int length = 8 + cash_shop_items[tab].count * 6;
  13743. int i, offset;
  13744. WFIFOHEAD( fd, length );
  13745. WFIFOW( fd, 0 ) = 0x8ca;
  13746. WFIFOW( fd, 2 ) = length;
  13747. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  13748. WFIFOW( fd, 6 ) = tab;
  13749. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  13750. struct item_data *id = itemdb_search(cash_shop_items[tab].item[i]->nameid);
  13751. WFIFOW( fd, offset ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[i]->nameid;
  13752. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  13753. }
  13754. WFIFOSET( fd, length );
  13755. }
  13756. }
  13757. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  13758. if( !sd->status.cashshop_sent ) {
  13759. clif_cashshop_list( fd );
  13760. #if PACKETVER_SUPPORTS_SALES
  13761. sale_notify_login(sd);
  13762. #endif
  13763. sd->status.cashshop_sent = true;
  13764. }
  13765. }
  13766. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  13767. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  13768. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  13769. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  13770. {
  13771. int fd, i, cost[2] = { 0, 0 };
  13772. #if PACKETVER < 20070711
  13773. const int offset = 8;
  13774. #else
  13775. const int offset = 12;
  13776. #endif
  13777. nullpo_retv(sd);
  13778. nullpo_retv(nd);
  13779. npc_shop_currency_type(sd, nd, cost, true);
  13780. fd = sd->fd;
  13781. sd->npc_shopid = nd->bl.id;
  13782. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  13783. WFIFOW(fd,0) = 0x287;
  13784. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  13785. WFIFOL(fd,4) = cost[0];
  13786. #if PACKETVER >= 20070711
  13787. WFIFOL(fd,8) = cost[1];
  13788. #endif
  13789. for( i = 0; i < nd->u.shop.count; i++ ) {
  13790. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  13791. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  13792. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  13793. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  13794. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  13795. }
  13796. WFIFOSET(fd,WFIFOW(fd,2));
  13797. }
  13798. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  13799. /// 0289 <cash point>.L <error>.W
  13800. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  13801. /// error:
  13802. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  13803. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  13804. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  13805. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  13806. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  13807. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  13808. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  13809. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  13810. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  13811. void clif_cashshop_ack(struct map_session_data* sd, int error)
  13812. {
  13813. int fd, cost[2] = { 0, 0 };
  13814. struct npc_data *nd;
  13815. nullpo_retv(sd);
  13816. fd = sd->fd;
  13817. nd = map_id2nd(sd->npc_shopid);
  13818. npc_shop_currency_type(sd, nd, cost, false);
  13819. WFIFOHEAD(fd, packet_len(0x289));
  13820. WFIFOW(fd,0) = 0x289;
  13821. WFIFOL(fd,2) = cost[0];
  13822. #if PACKETVER < 20070711
  13823. WFIFOW(fd,6) = TOW(error);
  13824. #else
  13825. WFIFOL(fd,6) = cost[1];
  13826. WFIFOW(fd,10) = TOW(error);
  13827. #endif
  13828. WFIFOSET(fd, packet_len(0x289));
  13829. }
  13830. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  13831. WFIFOHEAD( sd->fd, 16 );
  13832. WFIFOW( sd->fd, 0 ) = 0x849;
  13833. WFIFOL( sd->fd, 2 ) = item_id;
  13834. WFIFOW( sd->fd, 6 ) = result;
  13835. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  13836. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  13837. WFIFOSET( sd->fd, 16 );
  13838. }
  13839. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  13840. /// 0288 <name id>.W <amount>.W
  13841. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  13842. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  13843. /// 0848 <packet len>.W <count>.W <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W <tab>.W }.6B*count (PACKETVER >= 20130000)
  13844. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd){
  13845. struct s_packet_db* info;
  13846. int cmd = RFIFOW(fd,0);
  13847. nullpo_retv(sd);
  13848. info = &packet_db[cmd];
  13849. if( sd->state.trading || !sd->npc_shopid ) {
  13850. clif_cashshop_ack(sd,1);
  13851. return;
  13852. }
  13853. else {
  13854. #if PACKETVER < 20101116
  13855. short nameid = RFIFOW(fd,info->pos[0]);
  13856. short amount = RFIFOW(fd,info->pos[1]);
  13857. int points = RFIFOL(fd,info->pos[2]);
  13858. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  13859. #else
  13860. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  13861. int len = RFIFOW(fd,info->pos[0]);
  13862. int points = RFIFOL(fd,info->pos[1]);
  13863. int count = RFIFOW(fd,info->pos[2]);
  13864. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13865. if( len < 10 || len != 10 + count * s_itl){
  13866. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  13867. return;
  13868. }
  13869. if(cmd==0x848){
  13870. if (cashshop_buylist( sd, points, count, item_list))
  13871. clif_cashshop_ack(sd,0);
  13872. return;
  13873. } else {
  13874. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  13875. return;
  13876. }
  13877. #endif
  13878. }
  13879. }
  13880. /// Adoption System
  13881. ///
  13882. /// Adoption message (ZC_BABYMSG).
  13883. /// 0216 <msg>.L
  13884. /// msg:
  13885. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  13886. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  13887. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  13888. void clif_Adopt_reply(struct map_session_data *sd, int type)
  13889. {
  13890. int fd = sd->fd;
  13891. WFIFOHEAD(fd,6);
  13892. WFIFOW(fd,0) = 0x216;
  13893. WFIFOL(fd,2) = type;
  13894. WFIFOSET(fd,6);
  13895. }
  13896. /// Adoption confirmation (ZC_REQ_BABY).
  13897. /// 01f6 <account id>.L <char id>.L <name>.B
  13898. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  13899. {
  13900. int fd = sd->fd;
  13901. WFIFOHEAD(fd,34);
  13902. WFIFOW(fd,0) = 0x1f6;
  13903. WFIFOL(fd,2) = src->status.account_id;
  13904. WFIFOL(fd,6) = p_id;
  13905. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  13906. WFIFOSET(fd,34);
  13907. }
  13908. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  13909. /// 01f9 <account id>.L
  13910. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  13911. {
  13912. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  13913. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  13914. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  13915. {
  13916. tsd->adopt_invite = sd->status.account_id;
  13917. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  13918. }
  13919. }
  13920. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  13921. /// 01f7 <account id>.L <char id>.L <answer>.L
  13922. /// answer:
  13923. /// 0 = rejected
  13924. /// 1 = accepted
  13925. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  13926. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13927. int p1_id = RFIFOL(fd,info->pos[0]);
  13928. int p2_id = RFIFOL(fd,info->pos[1]);
  13929. int result = RFIFOL(fd,info->pos[2]);
  13930. struct map_session_data* p1_sd = map_id2sd(p1_id);
  13931. struct map_session_data* p2_sd = map_id2sd(p2_id);
  13932. int pid = sd->adopt_invite;
  13933. sd->adopt_invite = 0;
  13934. if( p1_sd == NULL || p2_sd == NULL )
  13935. return; // Both players need to be online
  13936. if( pid != p1_sd->status.account_id )
  13937. return; // Incorrect values
  13938. if( result == 0 )
  13939. return; // Rejected
  13940. pc_adoption(p1_sd, p2_sd, sd);
  13941. }
  13942. /// Convex Mirror (ZC_BOSS_INFO).
  13943. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  13944. /// infoType:
  13945. /// 0 = No boss on this map (BOSS_INFO_NOT).
  13946. /// 1 = Boss is alive (position update) (BOSS_INFO_ALIVE).
  13947. /// 2 = Boss is alive (initial announce) (BOSS_INFO_ALIVE_WITHMSG).
  13948. /// 3 = Boss is dead (BOSS_INFO_DEAD).
  13949. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  13950. {
  13951. WFIFOHEAD(fd,70);
  13952. memset(WFIFOP(fd,0),0,70);
  13953. WFIFOW(fd,0) = 0x293;
  13954. if( md != NULL ) {
  13955. if( md->bl.prev != NULL ) { // Boss on This Map
  13956. if( flag ) {
  13957. WFIFOB(fd,2) = 1;
  13958. WFIFOL(fd,3) = md->bl.x;
  13959. WFIFOL(fd,7) = md->bl.y;
  13960. } else
  13961. WFIFOB(fd,2) = 2; // First Time
  13962. } else if (md->spawn_timer != INVALID_TIMER) { // Boss is Dead
  13963. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  13964. unsigned int seconds;
  13965. int hours, minutes;
  13966. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  13967. hours = seconds / (60 * 60);
  13968. seconds = seconds - (60 * 60 * hours);
  13969. minutes = seconds / 60;
  13970. WFIFOB(fd,2) = 3;
  13971. WFIFOW(fd,11) = hours; // Hours
  13972. WFIFOW(fd,13) = minutes; // Minutes
  13973. }
  13974. safestrncpy(WFIFOCP(fd,19), md->db->jname, NAME_LENGTH);
  13975. }
  13976. WFIFOSET(fd,70);
  13977. }
  13978. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  13979. /// 02d6 <account id>.L
  13980. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  13981. {
  13982. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  13983. struct map_session_data* tsd = map_id2sd(aid);
  13984. if (!tsd)
  13985. return;
  13986. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  13987. clif_viewequip_ack(sd, tsd);
  13988. else
  13989. clif_msg(sd, VIEW_EQUIP_FAIL);
  13990. }
  13991. /// Request to change equip window tick (CZ_CONFIG).
  13992. /// 02d8 <type>.L <flag>.L
  13993. /// type:
  13994. /// 0 = open equip window
  13995. /// flag:
  13996. /// 0 = disabled
  13997. /// 1 = enabled
  13998. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  13999. {
  14000. //int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14001. bool flag = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]) != 0;
  14002. sd->status.show_equip = flag;
  14003. clif_equiptickack(sd, flag);
  14004. }
  14005. /// Request to change party invitation tick.
  14006. /// value:
  14007. /// 0 = disabled
  14008. /// 1 = enabled
  14009. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14010. {
  14011. bool flag = RFIFOB(fd,6) ? true : false;
  14012. sd->status.allow_party = flag;
  14013. clif_partytickack(sd, flag);
  14014. }
  14015. /// Questlog System [Kevin] [Inkfish]
  14016. ///
  14017. /**
  14018. * Safe check to init packet len & quest num for player.
  14019. * @param def_len
  14020. * @param info_len Length of each quest info.
  14021. * @param avail_quests Avail quests that player has.
  14022. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14023. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14024. **/
  14025. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14026. (*limit_out) = (0xFFFF - def_len) / info_len;
  14027. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14028. (*len_out) = ((*limit_out) * info_len) + def_len;
  14029. }
  14030. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  14031. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  14032. /// 097a <packet len>.W <num>.L { <quest id>.L <active>.B <remaining time>.L <time>.L <count>.W { <mob_id>.L <killed>.W <total>.W <mob name>.24B }*count }*num (ZC_ALL_QUEST_LIST2)
  14033. /// 09f8 <packet len>.W <num>.L { <quest id>.L <active>.B <remaining time>.L <time>.L <count>.W { <mob_id>.L <killed>.W <total>.W <mob name>.24B }*count }*num (ZC_ALL_QUEST_LIST3) // TODO!
  14034. void clif_quest_send_list(struct map_session_data *sd)
  14035. {
  14036. int fd = sd->fd;
  14037. int i;
  14038. int offset = 8;
  14039. int limit = 0;
  14040. #if PACKETVER >= 20141022
  14041. clif_quest_len(offset, 15 + ((10 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14042. WFIFOHEAD(fd,i);
  14043. WFIFOW(fd, 0) = 0x97a;
  14044. WFIFOL(fd, 4) = limit;
  14045. for (i = 0; i < limit; i++) {
  14046. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  14047. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14048. offset += 4;
  14049. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14050. offset++;
  14051. WFIFOL(fd, offset) = sd->quest_log[i].time - qi->time;
  14052. offset += 4;
  14053. WFIFOL(fd, offset) = sd->quest_log[i].time;
  14054. offset += 4;
  14055. WFIFOW(fd, offset) = qi->objectives_count;
  14056. offset += 2;
  14057. if( qi->objectives_count > 0 ){
  14058. int j;
  14059. struct mob_db *mob;
  14060. for( j = 0; j < qi->objectives_count; j++ ){
  14061. mob = mob_db(qi->objectives[j].mob);
  14062. WFIFOL(fd, offset) = qi->objectives[j].mob;
  14063. offset += 4;
  14064. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14065. offset += 2;
  14066. WFIFOW(fd, offset) = qi->objectives[j].count;
  14067. offset += 2;
  14068. safestrncpy((char*)WFIFOP(fd, offset), mob->jname, NAME_LENGTH);
  14069. offset += NAME_LENGTH;
  14070. }
  14071. }
  14072. }
  14073. WFIFOW(fd, 2) = offset;
  14074. WFIFOSET(fd, offset);
  14075. #else
  14076. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14077. WFIFOHEAD(fd,i);
  14078. WFIFOW(fd, 0) = 0x2b1;
  14079. WFIFOL(fd, 4) = limit;
  14080. for (i = 0; i < limit; i++) {
  14081. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14082. offset += 4;
  14083. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14084. offset += 1;
  14085. }
  14086. WFIFOW(fd, 2) = offset;
  14087. WFIFOSET(fd, offset);
  14088. #endif
  14089. }
  14090. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14091. /// 02b2 <packet len>.W <num>.L { <quest id>.L <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3 }*num
  14092. void clif_quest_send_mission(struct map_session_data *sd)
  14093. {
  14094. int fd = sd->fd;
  14095. int i, j, limit = 0;
  14096. int len = sd->avail_quests*104+8;
  14097. struct mob_db *mob;
  14098. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14099. WFIFOHEAD(fd, len);
  14100. WFIFOW(fd, 0) = 0x2b2;
  14101. WFIFOW(fd, 2) = len;
  14102. WFIFOL(fd, 4) = limit;
  14103. for (i = 0; i < limit; i++) {
  14104. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  14105. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14106. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  14107. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  14108. WFIFOW(fd, i*104+20) = qi->objectives_count;
  14109. for (j = 0 ; j < qi->objectives_count; j++) {
  14110. WFIFOL(fd, i*104+22+j*30) = qi->objectives[j].mob;
  14111. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14112. mob = mob_db(qi->objectives[j].mob);
  14113. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  14114. }
  14115. }
  14116. WFIFOSET(fd, len);
  14117. }
  14118. /// Notification about a new quest (ZC_ADD_QUEST).
  14119. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  14120. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14121. {
  14122. int fd = sd->fd;
  14123. int i;
  14124. struct quest_db *qi = quest_search(qd->quest_id);
  14125. WFIFOHEAD(fd, packet_len(0x2b3));
  14126. WFIFOW(fd, 0) = 0x2b3;
  14127. WFIFOL(fd, 2) = qd->quest_id;
  14128. WFIFOB(fd, 6) = qd->state;
  14129. WFIFOB(fd, 7) = qd->time - qi->time;
  14130. WFIFOL(fd, 11) = qd->time;
  14131. WFIFOW(fd, 15) = qi->objectives_count;
  14132. for (i = 0; i < qi->objectives_count; i++) {
  14133. struct mob_db *mob;
  14134. WFIFOL(fd, i*30+17) = qi->objectives[i].mob;
  14135. WFIFOW(fd, i*30+21) = qd->count[i];
  14136. mob = mob_db(qi->objectives[i].mob);
  14137. safestrncpy(WFIFOCP(fd, i*30+23), mob->jname, NAME_LENGTH);
  14138. }
  14139. WFIFOSET(fd, packet_len(0x2b3));
  14140. }
  14141. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14142. /// 02b4 <quest id>.L
  14143. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  14144. {
  14145. int fd = sd->fd;
  14146. WFIFOHEAD(fd, packet_len(0x2b4));
  14147. WFIFOW(fd, 0) = 0x2b4;
  14148. WFIFOL(fd, 2) = quest_id;
  14149. WFIFOSET(fd, packet_len(0x2b4));
  14150. }
  14151. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  14152. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  14153. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd, int mobid)
  14154. {
  14155. int fd = sd->fd;
  14156. int i;
  14157. struct quest_db *qi = quest_search(qd->quest_id);
  14158. int len = qi->objectives_count * 12 + 6;
  14159. WFIFOHEAD(fd, len);
  14160. WFIFOW(fd, 0) = 0x2b5;
  14161. WFIFOW(fd, 2) = len;
  14162. WFIFOW(fd, 4) = qi->objectives_count;
  14163. for (i = 0; i < qi->objectives_count; i++) {
  14164. if (mobid == 0 || mobid == qi->objectives[i].mob) {
  14165. WFIFOL(fd, i * 12 + 6) = qd->quest_id;
  14166. WFIFOL(fd, i * 12 + 10) = qi->objectives[i].mob;
  14167. WFIFOW(fd, i * 12 + 14) = qi->objectives[i].count;
  14168. WFIFOW(fd, i * 12 + 16) = qd->count[i];
  14169. }
  14170. }
  14171. WFIFOSET(fd, len);
  14172. }
  14173. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14174. /// 02b6 <quest id>.L <active>.B
  14175. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  14176. {
  14177. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14178. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14179. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14180. }
  14181. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14182. /// 02b7 <quest id>.L <active>.B
  14183. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  14184. {
  14185. int fd = sd->fd;
  14186. WFIFOHEAD(fd, packet_len(0x2b7));
  14187. WFIFOW(fd, 0) = 0x2b7;
  14188. WFIFOL(fd, 2) = quest_id;
  14189. WFIFOB(fd, 6) = active;
  14190. WFIFOSET(fd, packet_len(0x2b7));
  14191. }
  14192. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14193. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14194. /// effect:
  14195. /// 0 = none
  14196. /// 1 = exclamation mark icon
  14197. /// 2 = question mark icon
  14198. /// color:
  14199. /// 0 = yellow
  14200. /// 1 = orange
  14201. /// 2 = green
  14202. /// 3 = purple
  14203. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short effect, short color)
  14204. {
  14205. #if PACKETVER >= 20090218
  14206. int fd = sd->fd;
  14207. WFIFOHEAD(fd, packet_len(0x446));
  14208. WFIFOW(fd, 0) = 0x446;
  14209. WFIFOL(fd, 2) = bl->id;
  14210. WFIFOW(fd, 6) = bl->x;
  14211. WFIFOW(fd, 8) = bl->y;
  14212. WFIFOW(fd, 10) = effect;
  14213. WFIFOW(fd, 12) = color;
  14214. WFIFOSET(fd, packet_len(0x446));
  14215. #endif
  14216. }
  14217. /// Mercenary System
  14218. ///
  14219. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14220. /// 02a2 <var id>.W <value>.L
  14221. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  14222. {
  14223. struct mercenary_data *md;
  14224. struct status_data *status;
  14225. int fd;
  14226. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14227. return;
  14228. fd = sd->fd;
  14229. status = &md->battle_status;
  14230. WFIFOHEAD(fd,packet_len(0x2a2));
  14231. WFIFOW(fd,0) = 0x2a2;
  14232. WFIFOW(fd,2) = type;
  14233. switch( type ) {
  14234. case SP_ATK1:
  14235. {
  14236. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  14237. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14238. }
  14239. break;
  14240. case SP_MATK1:
  14241. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14242. break;
  14243. case SP_HIT:
  14244. WFIFOL(fd,4) = status->hit;
  14245. break;
  14246. case SP_CRITICAL:
  14247. WFIFOL(fd,4) = status->cri/10;
  14248. break;
  14249. case SP_DEF1:
  14250. WFIFOL(fd,4) = status->def;
  14251. break;
  14252. case SP_MDEF1:
  14253. WFIFOL(fd,4) = status->mdef;
  14254. break;
  14255. case SP_MERCFLEE:
  14256. WFIFOL(fd,4) = status->flee;
  14257. break;
  14258. case SP_ASPD:
  14259. WFIFOL(fd,4) = status->amotion;
  14260. break;
  14261. case SP_HP:
  14262. WFIFOL(fd,4) = status->hp;
  14263. break;
  14264. case SP_MAXHP:
  14265. WFIFOL(fd,4) = status->max_hp;
  14266. break;
  14267. case SP_SP:
  14268. WFIFOL(fd,4) = status->sp;
  14269. break;
  14270. case SP_MAXSP:
  14271. WFIFOL(fd,4) = status->max_sp;
  14272. break;
  14273. case SP_MERCKILLS:
  14274. WFIFOL(fd,4) = md->mercenary.kill_count;
  14275. break;
  14276. case SP_MERCFAITH:
  14277. WFIFOL(fd,4) = mercenary_get_faith(md);
  14278. break;
  14279. }
  14280. WFIFOSET(fd,packet_len(0x2a2));
  14281. }
  14282. /// Mercenary base status data (ZC_MER_INIT).
  14283. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14284. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14285. /// <calls>.L <kills>.L <atk range>.W
  14286. void clif_mercenary_info(struct map_session_data *sd)
  14287. {
  14288. int fd;
  14289. struct mercenary_data *md;
  14290. struct status_data *status;
  14291. int atk;
  14292. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14293. return;
  14294. fd = sd->fd;
  14295. status = &md->battle_status;
  14296. WFIFOHEAD(fd,packet_len(0x29b));
  14297. WFIFOW(fd,0) = 0x29b;
  14298. WFIFOL(fd,2) = md->bl.id;
  14299. // Mercenary shows ATK as a random value between ATK ~ ATK2
  14300. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  14301. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  14302. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  14303. WFIFOW(fd,10) = status->hit;
  14304. WFIFOW(fd,12) = status->cri/10;
  14305. WFIFOW(fd,14) = status->def;
  14306. WFIFOW(fd,16) = status->mdef;
  14307. WFIFOW(fd,18) = status->flee;
  14308. WFIFOW(fd,20) = status->amotion;
  14309. safestrncpy(WFIFOCP(fd,22), md->db->name, NAME_LENGTH);
  14310. WFIFOW(fd,46) = md->db->lv;
  14311. WFIFOL(fd,48) = status->hp;
  14312. WFIFOL(fd,52) = status->max_hp;
  14313. WFIFOL(fd,56) = status->sp;
  14314. WFIFOL(fd,60) = status->max_sp;
  14315. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  14316. WFIFOW(fd,68) = mercenary_get_faith(md);
  14317. WFIFOL(fd,70) = mercenary_get_calls(md);
  14318. WFIFOL(fd,74) = md->mercenary.kill_count;
  14319. WFIFOW(fd,78) = md->battle_status.rhw.range;
  14320. WFIFOSET(fd,packet_len(0x29b));
  14321. }
  14322. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  14323. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  14324. void clif_mercenary_skillblock(struct map_session_data *sd)
  14325. {
  14326. struct mercenary_data *md;
  14327. int fd, i, len = 4;
  14328. if( sd == NULL || (md = sd->md) == NULL )
  14329. return;
  14330. fd = sd->fd;
  14331. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  14332. WFIFOW(fd,0) = 0x29d;
  14333. for( i = 0; i < MAX_MERCSKILL; i++ )
  14334. {
  14335. uint16 id;
  14336. short idx = -1;
  14337. if( (id = md->db->skill[i].id) == 0 )
  14338. continue;
  14339. if ((idx = mercenary_skill_get_index(id)) == -1)
  14340. continue;
  14341. WFIFOW(fd,len) = id;
  14342. WFIFOL(fd,len+2) = skill_get_inf(id);
  14343. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  14344. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  14345. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv, false);
  14346. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  14347. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  14348. len += 37;
  14349. }
  14350. WFIFOW(fd,2) = len;
  14351. WFIFOSET(fd,len);
  14352. }
  14353. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  14354. /// 029f <command>.B
  14355. /// 1 = mercenary information
  14356. /// 2 = delete
  14357. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  14358. {
  14359. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14360. if( sd->md == NULL )
  14361. return;
  14362. if( option == 2 ) mercenary_delete(sd->md, 2);
  14363. }
  14364. /// Mercenary Message
  14365. /// message:
  14366. /// 0 = Mercenary soldier's duty hour is over.
  14367. /// 1 = Your mercenary soldier has been killed.
  14368. /// 2 = Your mercenary soldier has been fired.
  14369. /// 3 = Your mercenary soldier has ran away.
  14370. void clif_mercenary_message(struct map_session_data* sd, int message){
  14371. clif_msg(sd, MERC_MSG_BASE + message);
  14372. }
  14373. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  14374. /// 0298 <name id>.W <seconds>.L
  14375. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  14376. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  14377. WFIFOHEAD(fd,packet_len(0x298));
  14378. WFIFOW(fd,0) = 0x298;
  14379. WFIFOW(fd,2) = nameid;
  14380. WFIFOL(fd,4) = seconds;
  14381. WFIFOSET(fd,packet_len(0x298));
  14382. }
  14383. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  14384. /// 0299 <index>.W <name id>.W
  14385. void clif_rental_expired(int fd, int index, unsigned short nameid)
  14386. { // '<ItemName>' item has been deleted from the Inventory
  14387. WFIFOHEAD(fd,packet_len(0x299));
  14388. WFIFOW(fd,0) = 0x299;
  14389. WFIFOW(fd,2) = index+2;
  14390. WFIFOW(fd,4) = nameid;
  14391. WFIFOSET(fd,packet_len(0x299));
  14392. }
  14393. /// Book Reading (ZC_READ_BOOK).
  14394. /// 0294 <book id>.L <page>.L
  14395. void clif_readbook(int fd, int book_id, int page)
  14396. {
  14397. WFIFOHEAD(fd,packet_len(0x294));
  14398. WFIFOW(fd,0) = 0x294;
  14399. WFIFOL(fd,2) = book_id;
  14400. WFIFOL(fd,6) = page;
  14401. WFIFOSET(fd,packet_len(0x294));
  14402. }
  14403. /// Battlegrounds
  14404. ///
  14405. /// Updates HP bar of a camp member.
  14406. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  14407. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  14408. void clif_bg_hp(struct map_session_data *sd) {
  14409. #if PACKETVER < 20140613
  14410. unsigned char buf[34];
  14411. const int cmd = 0x2e0;
  14412. #else
  14413. unsigned char buf[14];
  14414. const int cmd = 0xa0e;
  14415. #endif
  14416. nullpo_retv(sd);
  14417. WBUFW(buf,0) = cmd;
  14418. WBUFL(buf,2) = sd->status.account_id;
  14419. #if PACKETVER < 20140613
  14420. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14421. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  14422. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14423. WBUFW(buf,32) = 100;
  14424. } else {
  14425. WBUFW(buf,30) = sd->battle_status.hp;
  14426. WBUFW(buf,32) = sd->battle_status.max_hp;
  14427. }
  14428. #else
  14429. if( sd->battle_status.max_hp > INT32_MAX ) {
  14430. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14431. WBUFL(buf,10) = 100;
  14432. } else {
  14433. WBUFL(buf,6) = sd->battle_status.hp;
  14434. WBUFL(buf,10) = sd->battle_status.max_hp;
  14435. }
  14436. #endif
  14437. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  14438. }
  14439. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  14440. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  14441. void clif_bg_xy(struct map_session_data *sd)
  14442. {
  14443. unsigned char buf[36];
  14444. nullpo_retv(sd);
  14445. WBUFW(buf,0)=0x2df;
  14446. WBUFL(buf,2)=sd->status.account_id;
  14447. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14448. WBUFW(buf,30)=sd->status.class_;
  14449. WBUFW(buf,32)=sd->bl.x;
  14450. WBUFW(buf,34)=sd->bl.y;
  14451. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14452. }
  14453. void clif_bg_xy_remove(struct map_session_data *sd)
  14454. {
  14455. unsigned char buf[36];
  14456. nullpo_retv(sd);
  14457. WBUFW(buf,0)=0x2df;
  14458. WBUFL(buf,2)=sd->status.account_id;
  14459. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  14460. WBUFW(buf,30)=0;
  14461. WBUFW(buf,32)=-1;
  14462. WBUFW(buf,34)=-1;
  14463. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14464. }
  14465. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  14466. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  14467. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  14468. {
  14469. struct map_session_data *sd;
  14470. unsigned char *buf;
  14471. if( (sd = bg_getavailablesd(bg)) == NULL )
  14472. return;
  14473. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  14474. WBUFW(buf,0) = 0x2dc;
  14475. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  14476. WBUFL(buf,4) = src_id;
  14477. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  14478. memcpy(WBUFP(buf,32), mes, len);
  14479. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  14480. if( buf )
  14481. aFree(buf);
  14482. }
  14483. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  14484. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  14485. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  14486. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  14487. if( !clif_process_message( sd, false, name, message, output ) )
  14488. return;
  14489. bg_send_message(sd, output, strlen(output) );
  14490. }
  14491. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  14492. /// 02de <camp A points>.W <camp B points>.W
  14493. void clif_bg_updatescore(int16 m)
  14494. {
  14495. struct block_list bl;
  14496. unsigned char buf[6];
  14497. bl.id = 0;
  14498. bl.type = BL_NUL;
  14499. bl.m = m;
  14500. WBUFW(buf,0) = 0x2de;
  14501. WBUFW(buf,2) = map[m].bgscore_lion;
  14502. WBUFW(buf,4) = map[m].bgscore_eagle;
  14503. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  14504. }
  14505. void clif_bg_updatescore_single(struct map_session_data *sd)
  14506. {
  14507. int fd;
  14508. nullpo_retv(sd);
  14509. fd = sd->fd;
  14510. WFIFOHEAD(fd,packet_len(0x2de));
  14511. WFIFOW(fd,0) = 0x2de;
  14512. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  14513. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  14514. WFIFOSET(fd,packet_len(0x2de));
  14515. }
  14516. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  14517. /// 02dd <account id>.L <name>.24B <camp>.W
  14518. void clif_sendbgemblem_area(struct map_session_data *sd)
  14519. {
  14520. unsigned char buf[33];
  14521. nullpo_retv(sd);
  14522. WBUFW(buf, 0) = 0x2dd;
  14523. WBUFL(buf,2) = sd->bl.id;
  14524. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  14525. WBUFW(buf,30) = sd->bg_id;
  14526. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  14527. }
  14528. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  14529. {
  14530. nullpo_retv(sd);
  14531. WFIFOHEAD(fd,32);
  14532. WFIFOW(fd,0) = 0x2dd;
  14533. WFIFOL(fd,2) = sd->bl.id;
  14534. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  14535. WFIFOW(fd,30) = sd->bg_id;
  14536. WFIFOSET(fd,packet_len(0x2dd));
  14537. }
  14538. /// Custom Fonts (ZC_NOTIFY_FONT).
  14539. /// 02ef <account_id>.L <font id>.W
  14540. void clif_font(struct map_session_data *sd)
  14541. {
  14542. #if PACKETVER >= 20080102
  14543. unsigned char buf[8];
  14544. nullpo_retv(sd);
  14545. WBUFW(buf,0) = 0x2ef;
  14546. WBUFL(buf,2) = sd->bl.id;
  14547. WBUFW(buf,6) = sd->status.font;
  14548. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  14549. #endif
  14550. }
  14551. /// Required to start the instancing information window on Client
  14552. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  14553. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  14554. void clif_instance_create(unsigned short instance_id, int num)
  14555. {
  14556. #if PACKETVER >= 20071128
  14557. struct instance_db *db = NULL;
  14558. struct map_session_data *sd = NULL;
  14559. enum send_target target = PARTY;
  14560. unsigned char buf[65];
  14561. instance_getsd(instance_id, &sd, &target);
  14562. if (!sd)
  14563. return;
  14564. db = instance_searchtype_db(instance_data[instance_id].type);
  14565. if (!db)
  14566. return;
  14567. WBUFW(buf,0) = 0x2cb;
  14568. safestrncpy(WBUFCP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  14569. WBUFW(buf,63) = num;
  14570. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  14571. #endif
  14572. return;
  14573. }
  14574. /// To announce Instancing queue creation if no maps available
  14575. /// S 0x2cc <Standby Position>.W
  14576. void clif_instance_changewait(unsigned short instance_id, int num)
  14577. {
  14578. #if PACKETVER >= 20071128
  14579. struct map_session_data *sd = NULL;
  14580. enum send_target target = PARTY;
  14581. unsigned char buf[4];
  14582. instance_getsd(instance_id, &sd, &target);
  14583. if (!sd)
  14584. return;
  14585. WBUFW(buf,0) = 0x2cc;
  14586. WBUFW(buf,2) = num;
  14587. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  14588. #endif
  14589. return;
  14590. }
  14591. /// Notify the current status to members
  14592. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  14593. void clif_instance_status(unsigned short instance_id, unsigned int limit1, unsigned int limit2)
  14594. {
  14595. #if PACKETVER >= 20071128
  14596. struct instance_db *db = NULL;
  14597. struct map_session_data *sd = NULL;
  14598. enum send_target target = PARTY;
  14599. unsigned char buf[71];
  14600. instance_getsd(instance_id, &sd, &target);
  14601. if (!sd)
  14602. return;
  14603. db = instance_searchtype_db(instance_data[instance_id].type);
  14604. if (!db)
  14605. return;
  14606. WBUFW(buf,0) = 0x2cd;
  14607. safestrncpy(WBUFCP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  14608. WBUFL(buf,63) = limit1;
  14609. WBUFL(buf,67) = limit2;
  14610. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  14611. #endif
  14612. return;
  14613. }
  14614. /// Notify a status change to members
  14615. /// S 0x2ce <Message ID>.L
  14616. /// 0 = Notification (EnterLimitDate update?)
  14617. /// 1 = The Memorial Dungeon expired; it has been destroyed
  14618. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  14619. /// 3 = The Memorial Dungeon has been removed.
  14620. /// 4 = Create failure (removes the instance window)
  14621. void clif_instance_changestatus(unsigned int instance_id, int type, unsigned int limit)
  14622. {
  14623. #if PACKETVER >= 20071128
  14624. struct map_session_data *sd = NULL;
  14625. enum send_target target = PARTY;
  14626. unsigned char buf[10];
  14627. instance_getsd(instance_id, &sd, &target);
  14628. if (!sd)
  14629. return;
  14630. WBUFW(buf,0) = 0x2ce;
  14631. WBUFL(buf,2) = type;
  14632. WBUFL(buf,6) = limit;
  14633. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  14634. #endif
  14635. return;
  14636. }
  14637. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  14638. /// 02b8 <account id>.L <name id>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W <equip location>.W <item type>.B
  14639. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  14640. {
  14641. #if PACKETVER >= 20071002
  14642. unsigned char buf[22];
  14643. struct item_data* id = itemdb_search(item_data->nameid);
  14644. WBUFW(buf,0) = 0x2b8;
  14645. WBUFL(buf,2) = sd->status.account_id;
  14646. WBUFW(buf,6) = item_data->nameid;
  14647. WBUFB(buf,8) = item_data->identify;
  14648. WBUFB(buf,9) = item_data->attribute;
  14649. WBUFB(buf,10) = item_data->refine;
  14650. clif_addcards(WBUFP(buf,11), item_data);
  14651. WBUFW(buf,19) = id->equip; // equip location
  14652. WBUFB(buf,21) = itemtype(id->nameid); // item type
  14653. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  14654. #endif
  14655. }
  14656. /** Display gained exp (ZC_NOTIFY_EXP).
  14657. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W
  14658. * amount: INT32_MIN ~ INT32_MAX
  14659. * var id:
  14660. * SP_BASEEXP, SP_JOBEXP
  14661. * exp type:
  14662. * 0 = normal exp gained/lost
  14663. * 1 = quest exp gained/lost
  14664. * @param sd Player
  14665. * @param exp EXP value gained/loss
  14666. * @param type SP_BASEEXP, SP_JOBEXP
  14667. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  14668. * @param lost True:if lossing EXP
  14669. */
  14670. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest, bool lost)
  14671. {
  14672. int fd;
  14673. nullpo_retv(sd);
  14674. fd = sd->fd;
  14675. WFIFOHEAD(fd, packet_len(0x7f6));
  14676. WFIFOW(fd,0) = 0x7f6;
  14677. WFIFOL(fd,2) = sd->bl.id;
  14678. WFIFOL(fd,6) = (int)umin(exp, INT_MAX) * (lost ? -1 : 1);
  14679. WFIFOW(fd,10) = type;
  14680. WFIFOW(fd,12) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  14681. WFIFOSET(fd,packet_len(0x7f6));
  14682. }
  14683. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  14684. /// type:
  14685. /// 0 = Displays 'value' for 5 seconds.
  14686. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  14687. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  14688. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  14689. /// value:
  14690. /// Except for type 3 it is interpreted as seconds for displaying as DD:HH:MM:SS, HH:MM:SS, MM:SS or SS (leftmost '00' is not displayed).
  14691. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  14692. {
  14693. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  14694. WFIFOW(sd->fd,0) = 0x1b1;
  14695. WFIFOB(sd->fd,2) = type;
  14696. WFIFOL(sd->fd,3) = value;
  14697. WFIFOSET(sd->fd, packet_len(0x1b1));
  14698. }
  14699. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  14700. /// 021d <state>.L
  14701. /// state:
  14702. /// 0 = Full effects
  14703. /// 1 = Reduced effects
  14704. ///
  14705. /// NOTE: The state is used on Aegis for sending skill unit packet
  14706. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  14707. /// whenever possible. Due to the way the decision check is
  14708. /// constructed, this state tracking was rendered useless,
  14709. /// as the only skill unit, that is sent with 0x1c9 is
  14710. /// Graffiti.
  14711. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  14712. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14713. sd->state.lesseffect = ( isLess != 0 );
  14714. }
  14715. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  14716. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  14717. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14718. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  14719. int type = RFIFOL(fd,info->pos[1]);
  14720. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  14721. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  14722. if( sd->state.trading || sd->npc_shopid )
  14723. return;
  14724. if( flag == 0 || n == 0) {
  14725. clif_menuskill_clear(sd);
  14726. return; // Canceled by player.
  14727. }
  14728. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  14729. clif_menuskill_clear(sd);
  14730. return; // Prevent hacking.
  14731. }
  14732. switch( type ) {
  14733. case 0: // Change Material
  14734. skill_changematerial(sd,n,item_list);
  14735. break;
  14736. case 1: // Level 1: Pure to Rough
  14737. case 2: // Level 2: Rough to Pure
  14738. skill_elementalanalysis(sd,n,type,item_list);
  14739. break;
  14740. }
  14741. clif_menuskill_clear(sd);
  14742. return;
  14743. }
  14744. /*==========================================
  14745. * Elemental System
  14746. *==========================================*/
  14747. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  14748. struct elemental_data *ed;
  14749. struct status_data *status;
  14750. int fd;
  14751. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  14752. return;
  14753. fd = sd->fd;
  14754. status = &ed->battle_status;
  14755. WFIFOHEAD(fd,8);
  14756. WFIFOW(fd,0) = 0x81e;
  14757. WFIFOW(fd,2) = type;
  14758. switch( type ) {
  14759. case SP_HP:
  14760. WFIFOL(fd,4) = status->hp;
  14761. break;
  14762. case SP_MAXHP:
  14763. WFIFOL(fd,4) = status->max_hp;
  14764. break;
  14765. case SP_SP:
  14766. WFIFOL(fd,4) = status->sp;
  14767. break;
  14768. case SP_MAXSP:
  14769. WFIFOL(fd,4) = status->max_sp;
  14770. break;
  14771. }
  14772. WFIFOSET(fd,8);
  14773. }
  14774. void clif_elemental_info(struct map_session_data *sd) {
  14775. int fd;
  14776. struct elemental_data *ed;
  14777. struct status_data *status;
  14778. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  14779. return;
  14780. fd = sd->fd;
  14781. status = &ed->battle_status;
  14782. WFIFOHEAD(fd,22);
  14783. WFIFOW(fd, 0) = 0x81d;
  14784. WFIFOL(fd, 2) = ed->bl.id;
  14785. WFIFOL(fd, 6) = status->hp;
  14786. WFIFOL(fd,10) = status->max_hp;
  14787. WFIFOL(fd,14) = status->sp;
  14788. WFIFOL(fd,18) = status->max_sp;
  14789. WFIFOSET(fd,22);
  14790. }
  14791. /// Buying Store System
  14792. ///
  14793. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  14794. /// 0810 <slots>.B
  14795. void clif_buyingstore_open(struct map_session_data* sd)
  14796. {
  14797. int fd = sd->fd;
  14798. WFIFOHEAD(fd,packet_len(0x810));
  14799. WFIFOW(fd,0) = 0x810;
  14800. WFIFOB(fd,2) = sd->buyingstore.slots;
  14801. WFIFOSET(fd,packet_len(0x810));
  14802. }
  14803. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  14804. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  14805. /// result:
  14806. /// 0 = cancel
  14807. /// 1 = open
  14808. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  14809. {
  14810. const unsigned int blocksize = 8;
  14811. uint8* itemlist;
  14812. char storename[MESSAGE_SIZE];
  14813. unsigned char result;
  14814. int zenylimit;
  14815. unsigned int count, packet_len;
  14816. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14817. packet_len = RFIFOW(fd,info->pos[0]);
  14818. // TODO: Make this check global for all variable length packets.
  14819. if( packet_len < 89 )
  14820. {// minimum packet length
  14821. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  14822. return;
  14823. }
  14824. zenylimit = RFIFOL(fd,info->pos[1]);
  14825. result = RFIFOL(fd,info->pos[2]);
  14826. safestrncpy(storename, RFIFOCP(fd,info->pos[3]), sizeof(storename));
  14827. itemlist = RFIFOP(fd,info->pos[4]);
  14828. // so that buyingstore_create knows, how many elements it has access to
  14829. packet_len-= info->pos[4];
  14830. if( packet_len%blocksize )
  14831. {
  14832. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  14833. return;
  14834. }
  14835. count = packet_len/blocksize;
  14836. buyingstore_create(sd, zenylimit, result, storename, itemlist, count, NULL);
  14837. }
  14838. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  14839. /// 0812 <result>.W <total weight>.L
  14840. /// result:
  14841. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  14842. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  14843. /// 8 = "No sale (purchase) information available." (0x705)
  14844. /// ? = nothing
  14845. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  14846. {
  14847. int fd = sd->fd;
  14848. WFIFOHEAD(fd,packet_len(0x812));
  14849. WFIFOW(fd,0) = 0x812;
  14850. WFIFOW(fd,2) = result;
  14851. WFIFOL(fd,4) = weight;
  14852. WFIFOSET(fd,packet_len(0x812));
  14853. }
  14854. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  14855. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  14856. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  14857. {
  14858. int fd = sd->fd;
  14859. unsigned int i;
  14860. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  14861. WFIFOW(fd,0) = 0x813;
  14862. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  14863. WFIFOL(fd,4) = sd->bl.id;
  14864. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  14865. for( i = 0; i < sd->buyingstore.slots; i++ )
  14866. {
  14867. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  14868. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  14869. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  14870. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  14871. }
  14872. WFIFOSET(fd,WFIFOW(fd,2));
  14873. }
  14874. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  14875. /// 0814 <account id>.L <store name>.80B
  14876. void clif_buyingstore_entry(struct map_session_data* sd)
  14877. {
  14878. uint8 buf[MESSAGE_SIZE+6];
  14879. WBUFW(buf,0) = 0x814;
  14880. WBUFL(buf,2) = sd->bl.id;
  14881. safestrncpy(WBUFCP(buf,6), sd->message, MESSAGE_SIZE);
  14882. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  14883. }
  14884. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14885. {
  14886. int fd = sd->fd;
  14887. WFIFOHEAD(fd,packet_len(0x814));
  14888. WFIFOW(fd,0) = 0x814;
  14889. WFIFOL(fd,2) = pl_sd->bl.id;
  14890. safestrncpy(WFIFOCP(fd,6), pl_sd->message, MESSAGE_SIZE);
  14891. WFIFOSET(fd,packet_len(0x814));
  14892. }
  14893. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  14894. /// 0815
  14895. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  14896. {
  14897. buyingstore_close(sd);
  14898. }
  14899. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  14900. /// 0816 <account id>.L
  14901. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  14902. {
  14903. uint8 buf[6];
  14904. WBUFW(buf,0) = 0x816;
  14905. WBUFL(buf,2) = sd->bl.id;
  14906. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  14907. }
  14908. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14909. {
  14910. int fd = sd->fd;
  14911. WFIFOHEAD(fd,packet_len(0x816));
  14912. WFIFOW(fd,0) = 0x816;
  14913. WFIFOL(fd,2) = pl_sd->bl.id;
  14914. WFIFOSET(fd,packet_len(0x816));
  14915. }
  14916. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  14917. /// 0817 <account id>.L
  14918. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  14919. {
  14920. uint32 account_id;
  14921. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14922. buyingstore_open(sd, account_id);
  14923. }
  14924. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  14925. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  14926. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  14927. {
  14928. int fd = sd->fd;
  14929. unsigned int i;
  14930. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  14931. WFIFOW(fd,0) = 0x818;
  14932. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  14933. WFIFOL(fd,4) = pl_sd->bl.id;
  14934. WFIFOL(fd,8) = pl_sd->buyer_id;
  14935. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  14936. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  14937. {
  14938. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  14939. WFIFOW(fd,20+i*9) = pl_sd->buyingstore.items[i].amount; // TODO: Figure out, if no longer needed items (amount == 0) are listed on official.
  14940. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  14941. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  14942. }
  14943. WFIFOSET(fd,WFIFOW(fd,2));
  14944. }
  14945. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  14946. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  14947. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  14948. {
  14949. const unsigned int blocksize = 6;
  14950. uint8* itemlist;
  14951. uint32 account_id;
  14952. unsigned int count, packet_len, buyer_id;
  14953. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14954. packet_len = RFIFOW(fd,info->pos[0]);
  14955. if( packet_len < 12 )
  14956. {// minimum packet length
  14957. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  14958. return;
  14959. }
  14960. account_id = RFIFOL(fd,info->pos[1]);
  14961. buyer_id = RFIFOL(fd,info->pos[2]);
  14962. itemlist = RFIFOP(fd,info->pos[3]);
  14963. // so that buyingstore_trade knows, how many elements it has access to
  14964. packet_len-= info->pos[3];
  14965. if( packet_len%blocksize )
  14966. {
  14967. ShowError("clif_parse_ReqTradeBuyingStore: Unexpected item list size %u (account_id=%d, buyer_id=%d, block size=%u)\n", packet_len, sd->bl.id, account_id, blocksize);
  14968. return;
  14969. }
  14970. count = packet_len/blocksize;
  14971. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  14972. }
  14973. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  14974. /// 081a <result>.W
  14975. /// result:
  14976. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  14977. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  14978. /// ? = nothing
  14979. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  14980. {
  14981. int fd = sd->fd;
  14982. WFIFOHEAD(fd,packet_len(0x81a));
  14983. WFIFOW(fd,0) = 0x81a;
  14984. WFIFOW(fd,2) = result;
  14985. WFIFOSET(fd,packet_len(0x81a));
  14986. }
  14987. /// Updates the zeny limit and an item in the buying store item list.
  14988. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  14989. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  14990. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount, uint32 char_id, int zeny) {
  14991. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  14992. const int cmd = 0x81b;
  14993. #else
  14994. const int cmd = 0x9e6;
  14995. #endif
  14996. int offset = 0;
  14997. int fd = sd->fd;
  14998. WFIFOHEAD(fd,packet_len(cmd));
  14999. WFIFOW(fd,0) = cmd;
  15000. WFIFOW(fd,2) = nameid;
  15001. WFIFOW(fd,4) = amount; // amount of nameid received
  15002. #if PACKETVER >= 20141016
  15003. WFIFOL(fd,6) = zeny; // zeny
  15004. offset += 4;
  15005. #endif
  15006. WFIFOL(fd,6+offset) = sd->buyingstore.zenylimit;
  15007. #if PACKETVER >= 20141016
  15008. WFIFOL(fd,10+offset) = char_id; // GID
  15009. WFIFOL(fd,14+offset) = (int)time(NULL); // date
  15010. #endif
  15011. WFIFOSET(fd,packet_len(cmd));
  15012. }
  15013. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15014. /// 081c <index>.W <amount>.W <price>.L
  15015. /// message:
  15016. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15017. ///
  15018. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15019. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  15020. {
  15021. int fd = sd->fd;
  15022. WFIFOHEAD(fd,packet_len(0x81c));
  15023. WFIFOW(fd,0) = 0x81c;
  15024. WFIFOW(fd,2) = index+2;
  15025. WFIFOW(fd,4) = amount;
  15026. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15027. WFIFOSET(fd,packet_len(0x81c));
  15028. }
  15029. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15030. /// 0824 <result>.W <name id>.W
  15031. /// result:
  15032. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15033. /// 6 = "The trade failed, because the entered amount of item %s is higher, than the buyer is willing to buy." (0x6d3, MSI_BUYINGSTORE_TRADE_OVERCOUNT)
  15034. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15035. /// ? = nothing
  15036. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  15037. {
  15038. int fd = sd->fd;
  15039. WFIFOHEAD(fd,packet_len(0x824));
  15040. WFIFOW(fd,0) = 0x824;
  15041. WFIFOW(fd,2) = result;
  15042. WFIFOW(fd,4) = nameid;
  15043. WFIFOSET(fd,packet_len(0x824));
  15044. }
  15045. /// Search Store Info System
  15046. ///
  15047. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15048. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15049. /// type:
  15050. /// 0 = Vending
  15051. /// 1 = Buying Store
  15052. ///
  15053. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15054. /// amount of card slots. If the client does not know about the item it
  15055. /// cannot be searched.
  15056. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  15057. {
  15058. const unsigned int blocksize = 2;
  15059. const uint8* itemlist;
  15060. const uint8* cardlist;
  15061. unsigned char type;
  15062. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  15063. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15064. packet_len = RFIFOW(fd,info->pos[0]);
  15065. if( packet_len < 15 )
  15066. {// minimum packet length
  15067. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  15068. return;
  15069. }
  15070. type = RFIFOB(fd,info->pos[1]);
  15071. max_price = RFIFOL(fd,info->pos[2]);
  15072. min_price = RFIFOL(fd,info->pos[3]);
  15073. item_count = RFIFOB(fd,info->pos[4]);
  15074. card_count = RFIFOB(fd,info->pos[5]);
  15075. itemlist = RFIFOP(fd,info->pos[6]);
  15076. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  15077. // check, if there is enough data for the claimed count of items
  15078. packet_len-= info->pos[6];
  15079. if( packet_len%blocksize )
  15080. {
  15081. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  15082. return;
  15083. }
  15084. count = packet_len/blocksize;
  15085. if( count < item_count+card_count )
  15086. {
  15087. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  15088. return;
  15089. }
  15090. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  15091. }
  15092. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  15093. /// 0836 <packet len>.W <is first page>.B <is next page>.B <remaining uses>.B { <store id>.L <account id>.L <shop name>.80B <nameid>.W <item type>.B <price>.L <amount>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  15094. /// is first page:
  15095. /// 0 = appends to existing results
  15096. /// 1 = clears previous results before displaying this result set
  15097. /// is next page:
  15098. /// 0 = no "next" label
  15099. /// 1 = "next" label to retrieve more results
  15100. void clif_search_store_info_ack(struct map_session_data* sd)
  15101. {
  15102. #if PACKETVER >= 20150225
  15103. const unsigned int blocksize = MESSAGE_SIZE+26+5*MAX_ITEM_RDM_OPT;
  15104. #else
  15105. const unsigned int blocksize = MESSAGE_SIZE+26;
  15106. #endif
  15107. int fd = sd->fd;
  15108. unsigned int i, start, end;
  15109. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  15110. end = umin(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  15111. WFIFOHEAD(fd,7+(end-start)*blocksize);
  15112. WFIFOW(fd,0) = 0x836;
  15113. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  15114. WFIFOB(fd,4) = !sd->searchstore.pages;
  15115. WFIFOB(fd,5) = searchstore_querynext(sd);
  15116. WFIFOB(fd,6) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15117. for( i = start; i < end; i++ ) {
  15118. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  15119. struct item it;
  15120. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  15121. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  15122. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  15123. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  15124. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  15125. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  15126. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  15127. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  15128. // make-up an item for clif_addcards
  15129. memset(&it, 0, sizeof(it));
  15130. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  15131. it.nameid = ssitem->nameid;
  15132. it.amount = ssitem->amount;
  15133. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  15134. clif_add_random_options(WFIFOP(fd,i*blocksize+31+MESSAGE_SIZE), &it);
  15135. }
  15136. WFIFOSET(fd,WFIFOW(fd,2));
  15137. }
  15138. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  15139. /// 0837 <reason>.B
  15140. /// reason:
  15141. /// 0 = "No matching stores were found." (0x70b)
  15142. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  15143. /// 2 = "You cannot search anymore." (0x706)
  15144. /// 3 = "You cannot search yet." (0x708)
  15145. /// 4 = "No sale (purchase) information available." (0x705)
  15146. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  15147. {
  15148. int fd = sd->fd;
  15149. WFIFOHEAD(fd,packet_len(0x837));
  15150. WFIFOW(fd,0) = 0x837;
  15151. WFIFOB(fd,2) = reason;
  15152. WFIFOSET(fd,packet_len(0x837));
  15153. }
  15154. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  15155. /// 0838
  15156. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  15157. {
  15158. searchstore_next(sd);
  15159. }
  15160. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  15161. /// 083a <type>.W <remaining uses>.B
  15162. /// type:
  15163. /// 0 = Search Stores
  15164. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  15165. void clif_open_search_store_info(struct map_session_data* sd)
  15166. {
  15167. int fd = sd->fd;
  15168. WFIFOHEAD(fd,packet_len(0x83a));
  15169. WFIFOW(fd,0) = 0x83a;
  15170. WFIFOW(fd,2) = sd->searchstore.effect;
  15171. #if PACKETVER > 20100701
  15172. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15173. #endif
  15174. WFIFOSET(fd,packet_len(0x83a));
  15175. }
  15176. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  15177. /// 083b
  15178. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  15179. {
  15180. searchstore_close(sd);
  15181. }
  15182. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  15183. /// 083c <account id>.L <store id>.L <nameid>.W
  15184. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  15185. {
  15186. unsigned short nameid;
  15187. uint32 account_id, store_id;
  15188. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15189. account_id = RFIFOL(fd,info->pos[0]);
  15190. store_id = RFIFOL(fd,info->pos[1]);
  15191. nameid = RFIFOW(fd,info->pos[2]);
  15192. searchstore_click(sd, account_id, store_id, nameid);
  15193. }
  15194. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  15195. /// 083d <xPos>.W <yPos>.W
  15196. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  15197. {
  15198. int fd = sd->fd;
  15199. WFIFOHEAD(fd,packet_len(0x83d));
  15200. WFIFOW(fd,0) = 0x83d;
  15201. WFIFOW(fd,2) = x;
  15202. WFIFOW(fd,4) = y;
  15203. WFIFOSET(fd,packet_len(0x83d));
  15204. }
  15205. /// Parse function for packet debugging.
  15206. void clif_parse_debug(int fd,struct map_session_data *sd)
  15207. {
  15208. int cmd, packet_len;
  15209. // clif_parse ensures, that there is at least 2 bytes of data
  15210. cmd = RFIFOW(fd,0);
  15211. if( sd ) {
  15212. packet_len = packet_db[cmd].len;
  15213. if( packet_len == 0 )
  15214. {// unknown
  15215. packet_len = RFIFOREST(fd);
  15216. }
  15217. else if( packet_len == -1 )
  15218. {// variable length
  15219. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  15220. }
  15221. ShowDebug("Packet debug of 0x%04X (length %d), %s session #%d, %d/%d (AID/CID)\n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id);
  15222. }
  15223. else
  15224. {
  15225. packet_len = RFIFOREST(fd);
  15226. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  15227. }
  15228. ShowDump(RFIFOP(fd,0), packet_len);
  15229. }
  15230. /*==========================================
  15231. * Server tells client to display a window similar to Magnifier (item) one
  15232. * Server populates the window with avilable elemental converter options according to player's inventory
  15233. *------------------------------------------*/
  15234. int clif_elementalconverter_list(struct map_session_data *sd) {
  15235. int i,c,view,fd;
  15236. nullpo_ret(sd);
  15237. /// Main client packet processing function
  15238. fd=sd->fd;
  15239. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  15240. WFIFOW(fd, 0)=0x1ad;
  15241. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  15242. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  15243. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  15244. WFIFOW(fd,c*2+ 4)= view;
  15245. else
  15246. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  15247. c++;
  15248. }
  15249. }
  15250. WFIFOW(fd,2) = c*2+4;
  15251. WFIFOSET(fd, WFIFOW(fd,2));
  15252. if (c > 0) {
  15253. sd->menuskill_id = SA_CREATECON;
  15254. sd->menuskill_val = c;
  15255. }
  15256. return 0;
  15257. }
  15258. /**
  15259. * Rune Knight
  15260. **/
  15261. void clif_millenniumshield(struct block_list *bl, short shields) {
  15262. #if PACKETVER >= 20081217
  15263. unsigned char buf[10];
  15264. WBUFW(buf,0) = 0x440;
  15265. WBUFL(buf,2) = bl->id;
  15266. WBUFW(buf,6) = shields;
  15267. WBUFW(buf,8) = 0;
  15268. clif_send(buf,packet_len(0x440),bl,AREA);
  15269. #endif
  15270. }
  15271. /**
  15272. * Warlock
  15273. **/
  15274. /*==========================================
  15275. * Spellbook list [LimitLine/3CeAM]
  15276. *------------------------------------------*/
  15277. int clif_spellbook_list(struct map_session_data *sd)
  15278. {
  15279. int i, c;
  15280. int fd;
  15281. nullpo_ret(sd);
  15282. fd = sd->fd;
  15283. WFIFOHEAD(fd, 8 * 8 + 8);
  15284. WFIFOW(fd,0) = 0x1ad;
  15285. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  15286. {
  15287. if( itemdb_is_spellbook2(sd->inventory.u.items_inventory[i].nameid) )
  15288. {
  15289. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15290. c++;
  15291. }
  15292. }
  15293. if( c > 0 )
  15294. {
  15295. WFIFOW(fd,2) = c * 2 + 4;
  15296. WFIFOSET(fd, WFIFOW(fd, 2));
  15297. sd->menuskill_id = WL_READING_SB;
  15298. sd->menuskill_val = c;
  15299. }
  15300. else{
  15301. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15302. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  15303. }
  15304. return 1;
  15305. }
  15306. /**
  15307. * Mechanic
  15308. **/
  15309. /*==========================================
  15310. * Magic Decoy Material List
  15311. *------------------------------------------*/
  15312. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  15313. int i, c;
  15314. int fd;
  15315. nullpo_ret(sd);
  15316. fd = sd->fd;
  15317. WFIFOHEAD(fd, 8 * 8 + 8);
  15318. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  15319. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  15320. if( itemdb_group_item_exists(IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid) ) {
  15321. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15322. c ++;
  15323. }
  15324. }
  15325. if( c > 0 ) {
  15326. sd->menuskill_id = NC_MAGICDECOY;
  15327. sd->menuskill_val = skill_lv;
  15328. sd->sc.comet_x = x;
  15329. sd->sc.comet_y = y;
  15330. WFIFOW(fd,2) = c * 2 + 4;
  15331. WFIFOSET(fd, WFIFOW(fd, 2));
  15332. } else {
  15333. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  15334. return 0;
  15335. }
  15336. return 1;
  15337. }
  15338. /*==========================================
  15339. * Guillotine Cross Poisons List
  15340. *------------------------------------------*/
  15341. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  15342. int i, c;
  15343. int fd;
  15344. nullpo_ret(sd);
  15345. fd = sd->fd;
  15346. WFIFOHEAD(fd, 8 * 8 + 8);
  15347. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  15348. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  15349. if( itemdb_group_item_exists(IG_POISON, sd->inventory.u.items_inventory[i].nameid) ) {
  15350. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15351. c ++;
  15352. }
  15353. }
  15354. if( c > 0 ) {
  15355. sd->menuskill_id = GC_POISONINGWEAPON;
  15356. sd->menuskill_val = skill_lv;
  15357. WFIFOW(fd,2) = c * 2 + 4;
  15358. WFIFOSET(fd, WFIFOW(fd, 2));
  15359. } else {
  15360. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  15361. return 0;
  15362. }
  15363. return 1;
  15364. }
  15365. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  15366. int clif_autoshadowspell_list(struct map_session_data *sd) {
  15367. int fd, i, c;
  15368. nullpo_ret(sd);
  15369. fd = sd->fd;
  15370. if( !fd )
  15371. return 0;
  15372. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  15373. return 0;
  15374. WFIFOHEAD(fd, 2 * 6 + 4);
  15375. WFIFOW(fd,0) = 0x442;
  15376. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  15377. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  15378. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  15379. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  15380. {
  15381. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  15382. c++;
  15383. }
  15384. if( c > 0 ) {
  15385. WFIFOW(fd,2) = 8 + c * 2;
  15386. WFIFOL(fd,4) = c;
  15387. WFIFOSET(fd,WFIFOW(fd,2));
  15388. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  15389. sd->menuskill_val = c;
  15390. } else {
  15391. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15392. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  15393. }
  15394. return 1;
  15395. }
  15396. /*===========================================
  15397. * Skill list for Four Elemental Analysis
  15398. * and Change Material skills.
  15399. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  15400. *------------------------------------------*/
  15401. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  15402. #if PACKETVER >= 20090922
  15403. int fd = sd->fd;
  15404. nullpo_ret(sd);
  15405. sd->menuskill_id = skill_id; // To prevent hacking.
  15406. sd->menuskill_val = skill_lv;
  15407. if( skill_id == GN_CHANGEMATERIAL )
  15408. skill_lv = 0; // Changematerial
  15409. WFIFOHEAD(fd, packet_len(0x7e3));
  15410. WFIFOW(fd,0) = 0x7e3;
  15411. WFIFOL(fd,2) = skill_lv;
  15412. WFIFOL(fd,4) = 0;
  15413. WFIFOSET(fd, packet_len(0x7e3));
  15414. #endif
  15415. return 1;
  15416. }
  15417. /*==========================================
  15418. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  15419. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  15420. * RFIFOL(fd,2) - type (currently not used)
  15421. *------------------------------------------*/
  15422. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  15423. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15424. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  15425. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  15426. return;
  15427. if( pc_istrading(sd) ) {
  15428. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  15429. clif_menuskill_clear(sd);
  15430. return;
  15431. }
  15432. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  15433. clif_menuskill_clear(sd);
  15434. }
  15435. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  15436. /// 08cf <id>.L <type>.W <num>.W
  15437. void clif_spiritcharm(struct map_session_data *sd) {
  15438. unsigned char buf[10];
  15439. nullpo_retv(sd);
  15440. WBUFW(buf,0) = 0x08cf;
  15441. WBUFL(buf,2) = sd->bl.id;
  15442. WBUFW(buf,6) = sd->spiritcharm_type;
  15443. WBUFW(buf,8) = sd->spiritcharm;
  15444. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  15445. }
  15446. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  15447. /// 0907 <index>.W
  15448. ///
  15449. /// R 0908 <index>.w <type>.b
  15450. /// type:
  15451. /// 0 = move item to personal tab
  15452. /// 1 = move item to normal tab
  15453. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  15454. #if PACKETVER >= 20111122
  15455. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15456. int index = RFIFOW(fd,info->pos[0]) - 2;
  15457. int type = RFIFOB(fd, info->pos[1]);
  15458. /* can't move while dead. */
  15459. if(pc_isdead(sd)) {
  15460. return;
  15461. }
  15462. if (index < 0 || index >= MAX_INVENTORY)
  15463. return;
  15464. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  15465. sd->inventory.u.items_inventory[index].favorite = 0;
  15466. else if( type == 0 )
  15467. sd->inventory.u.items_inventory[index].favorite = 1;
  15468. else
  15469. return;/* nothing to do. */
  15470. clif_favorite_item(sd, index);
  15471. #endif
  15472. }
  15473. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  15474. /// 0900 <index>.W <favorite>.B
  15475. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  15476. int fd = sd->fd;
  15477. WFIFOHEAD(fd,packet_len(0x908));
  15478. WFIFOW(fd,0) = 0x908;
  15479. WFIFOW(fd,2) = index+2;
  15480. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  15481. WFIFOSET(fd,packet_len(0x908));
  15482. }
  15483. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  15484. void clif_snap( struct block_list *bl, short x, short y ) {
  15485. unsigned char buf[10];
  15486. WBUFW(buf,0) = 0x8d2;
  15487. WBUFL(buf,2) = bl->id;
  15488. WBUFW(buf,6) = x;
  15489. WBUFW(buf,8) = y;
  15490. if( disguised(bl) )
  15491. {
  15492. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  15493. WBUFL(buf,2) = -bl->id;
  15494. clif_send(buf, packet_len(0x8d2), bl, SELF);
  15495. } else
  15496. clif_send(buf,packet_len(0x8d2),bl, AREA);
  15497. }
  15498. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  15499. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  15500. #if PACKETVER >= 20120404
  15501. WFIFOHEAD(fd,packet_len(0x977));
  15502. WFIFOW(fd,0) = 0x977;
  15503. WFIFOL(fd,2) = md->bl.id;
  15504. WFIFOL(fd,6) = md->status.hp;
  15505. WFIFOL(fd,10) = md->status.max_hp;
  15506. WFIFOSET(fd,packet_len(0x977));
  15507. #endif
  15508. }
  15509. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  15510. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  15511. return;
  15512. }
  15513. void clif_partytickack(struct map_session_data* sd, bool flag) {
  15514. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  15515. WFIFOW(sd->fd,0) = 0x2c9;
  15516. WFIFOB(sd->fd,2) = flag;
  15517. WFIFOSET(sd->fd, packet_len(0x2c9));
  15518. }
  15519. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  15520. /// 0979 <world name>.24B <char name>.24B
  15521. void clif_ackworldinfo(struct map_session_data* sd) {
  15522. int fd;
  15523. nullpo_retv(sd);
  15524. fd = sd->fd;
  15525. WFIFOHEAD(fd,packet_len(0x979));
  15526. WFIFOW(fd,0)=0x979;
  15527. //AID -> world name ?
  15528. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  15529. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  15530. WFIFOSET(fd,packet_len(0x979));
  15531. }
  15532. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  15533. /// 0978 <AID>.L
  15534. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  15535. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  15536. if(sd)
  15537. clif_ackworldinfo(sd);
  15538. }
  15539. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  15540. /// 0447
  15541. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd) {
  15542. //if(sd)
  15543. ;
  15544. }
  15545. /// req world info (CZ_CLIENT_VERSION)
  15546. /// 044A <version>.L
  15547. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  15548. //if(sd)
  15549. ;
  15550. }
  15551. /// Ranking list
  15552. /// ranking pointlist { <name>.24B <point>.L }*10
  15553. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  15554. struct fame_list* list;
  15555. int i, size = MAX_FAME_LIST;
  15556. switch(rankingtype) {
  15557. case RANK_BLACKSMITH: list = smith_fame_list; break;
  15558. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  15559. case RANK_TAEKWON: list = taekwon_fame_list; break;
  15560. // PK currently unsupported
  15561. case RANK_KILLER: list = NULL; size = 0; break;
  15562. default:
  15563. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  15564. return;
  15565. }
  15566. //Packet size limits this list to 10 elements. [Skotlex]
  15567. for (i = 0; i < min(10,size); i++) {
  15568. if (list[i].id > 0) {
  15569. const char* name;
  15570. if (strcmp(list[i].name, "-") == 0 &&
  15571. (name = map_charid2nick(list[i].id)) != NULL)
  15572. {
  15573. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  15574. } else {
  15575. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  15576. }
  15577. } else {
  15578. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  15579. }
  15580. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  15581. }
  15582. for(;i < 10; i++) { //In case the MAX is less than 10.
  15583. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  15584. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  15585. }
  15586. }
  15587. /// Request for the blacksmith ranklist.
  15588. /// /blacksmith command sends this packet to the server.
  15589. /// 0217 (CZ_BLACKSMITH_RANK)
  15590. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  15591. clif_ranklist(sd,RANK_BLACKSMITH);
  15592. }
  15593. /// Request for the alchemist ranklist.
  15594. /// /alchemist command sends this packet to the server.
  15595. /// 0218 (CZ_ALCHEMIST_RANK)
  15596. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  15597. clif_ranklist(sd,RANK_ALCHEMIST);
  15598. }
  15599. /// Request for the taekwon ranklist.
  15600. /// /taekwon command sends this packet to the server.
  15601. /// 0225 (CZ_TAEKWON_RANK)
  15602. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  15603. clif_ranklist(sd,RANK_TAEKWON);
  15604. }
  15605. /// Request for the killer ranklist.
  15606. /// /pk command sends this packet to the server.
  15607. /// 0237 (CZ_KILLER_RANK)
  15608. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  15609. clif_ranklist(sd,RANK_KILLER);
  15610. }
  15611. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  15612. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  15613. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  15614. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  15615. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  15616. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  15617. enum e_rank rank;
  15618. #if PACKETVER < 20130710
  15619. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  15620. short cmd;
  15621. switch( rankingType ){
  15622. case RANK_BLACKSMITH: cmd = 0x219; break;
  15623. case RANK_ALCHEMIST: cmd = 0x21a; break;
  15624. case RANK_TAEKWON: cmd = 0x226; break;
  15625. case RANK_KILLER: cmd = 0x238; break;
  15626. default:
  15627. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  15628. return;
  15629. }
  15630. // Can be safely casted here, since we validated it before
  15631. rank = (enum e_rank)rankingType;
  15632. WBUFW(buf,0) = cmd;
  15633. clif_sub_ranklist(buf,2,sd,rank);
  15634. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  15635. #else
  15636. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  15637. int mypoint = 0;
  15638. switch( rankingType ){
  15639. case RANK_BLACKSMITH:
  15640. case RANK_ALCHEMIST:
  15641. case RANK_TAEKWON:
  15642. case RANK_KILLER:
  15643. break;
  15644. default:
  15645. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  15646. return;
  15647. }
  15648. // Can be safely casted here, since we validated it before
  15649. rank = (enum e_rank)rankingType;
  15650. WBUFW(buf,0) = 0x97d;
  15651. WBUFW(buf,2) = rank;
  15652. clif_sub_ranklist(buf,4,sd,rank);
  15653. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  15654. case MAPID_BLACKSMITH:
  15655. case MAPID_ALCHEMIST:
  15656. case MAPID_TAEKWON:
  15657. mypoint = sd->status.fame;
  15658. }
  15659. WBUFL(buf,284) = mypoint; //mypoint
  15660. clif_send(buf, 288, &sd->bl, SELF);
  15661. #endif
  15662. }
  15663. /*
  15664. * 097c <type> (CZ_REQ_RANKING)
  15665. * type
  15666. * 0: /blacksmith
  15667. * 1: /alchemist
  15668. * 2: /taekwon
  15669. * 3: /pk
  15670. * */
  15671. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  15672. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15673. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  15674. clif_ranklist(sd,rankingtype);
  15675. }
  15676. /// Updates the fame rank points for the given ranking.
  15677. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  15678. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  15679. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  15680. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  15681. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  15682. int fd=sd->fd;
  15683. #if PACKETVER < 20130710
  15684. short cmd;
  15685. switch(rankingtype){
  15686. case RANK_BLACKSMITH: cmd = 0x21b; break;
  15687. case RANK_ALCHEMIST: cmd = 0x21c; break;
  15688. case RANK_TAEKWON: cmd = 0x224; break;
  15689. default:
  15690. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  15691. return;
  15692. }
  15693. WFIFOHEAD(fd,packet_len(cmd));
  15694. WFIFOW(fd,0) = cmd;
  15695. WFIFOL(fd,2) = point;
  15696. WFIFOL(fd,6) = sd->status.fame;
  15697. WFIFOSET(fd, packet_len(cmd));
  15698. #else
  15699. WFIFOHEAD(fd,packet_len(0x97e));
  15700. WFIFOW(fd,0) = 0x97e;
  15701. WFIFOW(fd,2) = rankingtype;
  15702. WFIFOL(fd,4) = point;
  15703. WFIFOL(fd,8) = sd->status.fame;
  15704. WFIFOSET(fd,packet_len(0x97e));
  15705. #endif
  15706. }
  15707. /**
  15708. * Transmit personal information to player. (rates)
  15709. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  15710. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  15711. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  15712. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  15713. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  15714. * FIXME!
  15715. * - Find/decide for details of EXP, Drop, and Death penalty rates
  15716. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  15717. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  15718. */
  15719. #ifdef VIP_ENABLE
  15720. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  15721. if (sd) {
  15722. struct s_packet_db* info;
  15723. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  15724. int cmd = 0, fd, i = 0;
  15725. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  15726. int details_bexp[PINFO_MAX];
  15727. int details_drop[PINFO_MAX];
  15728. int details_penalty[PINFO_MAX];
  15729. /**
  15730. * Set for EXP
  15731. */
  15732. //0:PCRoom
  15733. details_bexp[0] = map[sd->bl.m].adjust.bexp;
  15734. if (details_bexp[0] == 100 || !details_bexp[0])
  15735. details_bexp[0] = 0;
  15736. else {
  15737. if (details_bexp[0] < 100) {
  15738. details_bexp[0] = 100 - details_bexp[0];
  15739. details_bexp[0] = 0 - details_bexp[0];
  15740. }
  15741. else
  15742. details_bexp[0] = details_bexp[0] - 100;
  15743. }
  15744. //1:Premium
  15745. if (pc_isvip(sd)) {
  15746. details_bexp[1] = battle_config.vip_base_exp_increase;
  15747. if (details_bexp[1] < 0)
  15748. details_bexp[1] = 0 - details_bexp[1];
  15749. }
  15750. else
  15751. details_bexp[1] = 0;
  15752. //2:Server
  15753. details_bexp[2] = battle_config.base_exp_rate;
  15754. if (details_bexp[2] == 100)
  15755. details_bexp[2] = 0;
  15756. else {
  15757. if (details_bexp[2] < 100) {
  15758. details_bexp[2] = 100 - details_bexp[2];
  15759. details_bexp[2] = 0 - details_bexp[2];
  15760. }
  15761. else
  15762. details_bexp[2] = details_bexp[2] - 100;
  15763. }
  15764. //3:TPLUS
  15765. details_bexp[3] = 0;
  15766. /* End - EXP set*/
  15767. /**
  15768. * Set for Drop rate
  15769. */
  15770. //0:PCRoom
  15771. details_drop[0] = 0;
  15772. //1:Premium
  15773. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  15774. if (pc_isvip(sd)) {
  15775. if (details_drop[1] < 0)
  15776. details_drop[1] = 0 - details_drop[1];
  15777. }
  15778. else
  15779. details_drop[1] = 0;
  15780. //2:Server
  15781. details_drop[2] = battle_config.item_rate_common;
  15782. if (details_drop[2] == 100)
  15783. details_drop[2] = 0;
  15784. else {
  15785. if (details_drop[2] < 100) {
  15786. details_drop[2] = 100 - details_drop[2];
  15787. details_drop[2] = 0 - details_drop[2];
  15788. }
  15789. else
  15790. details_drop[2] = details_drop[2] - 100;
  15791. }
  15792. //3:TPLUS
  15793. details_drop[3] = 0;
  15794. /* End - Drop set*/
  15795. /**
  15796. * Set for Penalty rate
  15797. */
  15798. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  15799. //0:PCRoom
  15800. details_penalty[0] = 0;
  15801. //1:Premium
  15802. if (pc_isvip(sd)) {
  15803. details_penalty[1] = battle_config.vip_exp_penalty_base;
  15804. if (details_penalty[1] == 100)
  15805. details_penalty[1] = 0;
  15806. else {
  15807. if (details_penalty[1] < 100) {
  15808. details_penalty[1] = 100 - details_penalty[1];
  15809. details_penalty[1] = 0 - details_penalty[1];
  15810. }
  15811. else
  15812. details_penalty[1] = details_penalty[1] - 100;
  15813. }
  15814. }
  15815. else
  15816. details_penalty[1] = 0;
  15817. //2:Server
  15818. details_penalty[2] = battle_config.death_penalty_base;
  15819. if (details_penalty[2] == 100)
  15820. details_penalty[2] = 0;
  15821. else {
  15822. if (details_penalty[2] < 100) {
  15823. details_penalty[2] = 100 - details_penalty[2];
  15824. details_penalty[2] = 0 - details_penalty[2];
  15825. }
  15826. else
  15827. details_penalty[2] = details_penalty[2] - 100;
  15828. }
  15829. //3:TPLUS
  15830. details_penalty[3] = 0;
  15831. /* End - Penalty set*/
  15832. cmd = packet_db_ack[cmdtype];
  15833. info = &packet_db[cmd];
  15834. len = info->len; //this is the base len without details
  15835. if(!len) return; //version as packet disable
  15836. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  15837. szdetails = 7;
  15838. factor = 1;
  15839. }
  15840. else if (cmd == 0x097b) {
  15841. tot_baseexp *= factor;
  15842. tot_drop *= factor;
  15843. tot_penalty *= factor;
  15844. }
  15845. fd = sd->fd;
  15846. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  15847. WFIFOW(fd,0) = cmd;
  15848. for (i = 0; i < maxinfotype; i++) {
  15849. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  15850. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  15851. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  15852. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  15853. tot_baseexp += details_bexp[i]*factor;
  15854. tot_drop += details_penalty[i]*factor;
  15855. tot_penalty += details_drop[i]*factor;
  15856. len += szdetails;
  15857. }
  15858. WFIFOW(fd,info->pos[0]) = len; //packetlen
  15859. if (cmd == 0x08cb) { //0x08cb version
  15860. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  15861. WFIFOW(fd,info->pos[2]) = tot_drop;
  15862. WFIFOW(fd,info->pos[3]) = tot_penalty;
  15863. }
  15864. else { //2013-08-07aRagexe uses 0x097b
  15865. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  15866. WFIFOL(fd,info->pos[2]) = tot_drop;
  15867. WFIFOL(fd,info->pos[3]) = tot_penalty;
  15868. }
  15869. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  15870. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  15871. WFIFOSET(fd,len);
  15872. }
  15873. }
  15874. #endif
  15875. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  15876. char cmd[30];
  15877. int t_aid = RFIFOL(fd,2);
  15878. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  15879. is_atcommand(fd, sd, cmd, 1);
  15880. }
  15881. /**
  15882. * Marks Crimson Marker target on mini-map to the caster
  15883. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  15884. * @param fd
  15885. * @param bl Crimson Marker target
  15886. **/
  15887. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  15888. struct s_packet_db* info;
  15889. int cmd = 0;
  15890. int16 len;
  15891. unsigned char buf[11];
  15892. nullpo_retv(sd);
  15893. cmd = packet_db_ack[ZC_C_MARKERINFO];
  15894. if (!cmd)
  15895. cmd = 0x09C1; //default
  15896. info = &packet_db[cmd];
  15897. if (!(len = info->len))
  15898. return;
  15899. WBUFW(buf, 0) = cmd;
  15900. WBUFL(buf, info->pos[0]) = bl->id;
  15901. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  15902. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  15903. clif_send(buf, len, &sd->bl, SELF);
  15904. }
  15905. /**
  15906. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  15907. **/
  15908. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  15909. struct s_packet_db *info = NULL;
  15910. int cmd = 0;
  15911. nullpo_retv(sd);
  15912. cmd = packet_db_ack[ZC_NOTIFY_BIND_ON_EQUIP];
  15913. info = &packet_db[cmd];
  15914. if (!cmd || !info->len)
  15915. return;
  15916. WFIFOHEAD(sd->fd, info->len);
  15917. WFIFOW(sd->fd, 0) = cmd;
  15918. WFIFOW(sd->fd, info->pos[0]) = n+2;
  15919. WFIFOSET(sd->fd, info->len);
  15920. }
  15921. /**
  15922. * [Ind/Hercules]
  15923. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  15924. **/
  15925. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  15926. char buf[256];
  15927. size_t len;
  15928. nullpo_retv(bl);
  15929. if(!message)
  15930. return;
  15931. len = strlen(message)+1;
  15932. if( len > sizeof(buf)-8 ) {
  15933. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%d).\n", message, len);
  15934. len = sizeof(buf)-8;
  15935. }
  15936. WBUFW(buf,0) = 0x8b3;
  15937. WBUFW(buf,2) = (uint16)(len+8);
  15938. WBUFL(buf,4) = bl->id;
  15939. safestrncpy(WBUFCP(buf,8), message, len);
  15940. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  15941. }
  15942. /**
  15943. * [Ind/Hercules]
  15944. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  15945. **/
  15946. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  15947. unsigned char buf[10];
  15948. nullpo_retv(sd);
  15949. WBUFW(buf,0) = 0x7fc;
  15950. WBUFL(buf,2) = prev_leader_aid;
  15951. WBUFL(buf,6) = new_leader_aid;
  15952. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  15953. }
  15954. /**
  15955. * Sends a clan message to a player
  15956. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  15957. **/
  15958. void clif_clan_message(struct clan *clan,const char *mes,int len){
  15959. #if PACKETVER >= 20131223
  15960. struct map_session_data *sd;
  15961. uint8 buf[256];
  15962. if( len == 0 ){
  15963. return;
  15964. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  15965. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%d, clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  15966. len = sizeof(buf)-5-NAME_LENGTH;
  15967. }
  15968. WBUFW(buf, 0) = 0x98e;
  15969. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  15970. // Offially the sender name should also be filled here, but it is not required by the client and since it's in the message too we do not fill it
  15971. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  15972. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  15973. if((sd = clan_getavailablesd(clan)) != NULL)
  15974. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  15975. #endif
  15976. }
  15977. /**
  15978. * Parses a clan message from a player.
  15979. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  15980. **/
  15981. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  15982. #if PACKETVER >= 20131223
  15983. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  15984. // validate packet and retrieve name and message
  15985. if( !clif_process_message(sd, false, name, message, output ) )
  15986. return;
  15987. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  15988. #endif
  15989. }
  15990. /**
  15991. * Sends the basic clan informations to the client.
  15992. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  15993. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  15994. **/
  15995. void clif_clan_basicinfo( struct map_session_data *sd ){
  15996. #if PACKETVER >= 20131223
  15997. int fd, offset, length, i, flag;
  15998. struct clan* clan;
  15999. char mapname[MAP_NAME_LENGTH_EXT];
  16000. nullpo_retv( sd );
  16001. nullpo_retv( clan = sd->clan );
  16002. // Check if the player has a valid session and is not autotrading
  16003. if( !clif_session_isValid( sd ) ){
  16004. return;
  16005. }
  16006. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16007. fd = sd->fd;
  16008. WFIFOHEAD(fd,length);
  16009. memset( WFIFOP(fd, 0), 0, length );
  16010. WFIFOW( fd, 0 ) = 0x98a;
  16011. WFIFOL( fd, 4 ) = clan->id;
  16012. offset = 8;
  16013. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16014. offset += NAME_LENGTH;
  16015. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16016. offset += NAME_LENGTH;
  16017. mapindex_getmapname_ext( clan->map, mapname );
  16018. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16019. offset += MAP_NAME_LENGTH_EXT;
  16020. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16021. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16022. for( flag = 0; flag < 2; flag++ ){
  16023. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16024. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16025. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16026. offset += NAME_LENGTH;
  16027. }
  16028. }
  16029. }
  16030. WFIFOW( fd, 2 ) = offset;
  16031. WFIFOSET(fd,offset);
  16032. #endif
  16033. }
  16034. /**
  16035. * Updates the online and maximum player count of a clan.
  16036. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16037. **/
  16038. void clif_clan_onlinecount( struct clan* clan ){
  16039. #if PACKETVER >= 20131223
  16040. uint8 buf[6];
  16041. struct map_session_data *sd;
  16042. WBUFW(buf,0) = 0x988;
  16043. WBUFW(buf,2) = clan->connect_member;
  16044. WBUFW(buf,4) = clan->max_member;
  16045. if((sd = clan_getavailablesd(clan)) != NULL)
  16046. clif_send(buf, 6, &sd->bl, CLAN);
  16047. #endif
  16048. }
  16049. /**
  16050. * Notifies the client that the player has left his clan.
  16051. * 0989 (ZC_ACK_CLAN_LEAVE)
  16052. **/
  16053. void clif_clan_leave( struct map_session_data* sd ){
  16054. #if PACKETVER >= 20131223
  16055. int fd;
  16056. nullpo_retv( sd );
  16057. if( !clif_session_isValid( sd ) ){
  16058. return;
  16059. }
  16060. fd = sd->fd;
  16061. WFIFOHEAD(fd,2);
  16062. WFIFOW(fd,0) = 0x989;
  16063. WFIFOSET(fd,2);
  16064. #endif
  16065. }
  16066. /**
  16067. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16068. * 0A2F <result>.B <title_id>.L
  16069. */
  16070. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  16071. {
  16072. #if PACKETVER >= 20150513
  16073. int fd;
  16074. nullpo_retv(sd);
  16075. if (!clif_session_isValid(sd))
  16076. return;
  16077. fd = sd->fd;
  16078. WFIFOHEAD(fd, packet_len(0xa2f));
  16079. WFIFOW(fd, 0) = 0xa2f;
  16080. WFIFOB(fd, 2) = result;
  16081. WFIFOL(fd, 3) = title_id;
  16082. WFIFOSET(fd, packet_len(0xa2f));
  16083. #endif
  16084. }
  16085. /**
  16086. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16087. * 0A2E <title_id>.L
  16088. */
  16089. void clif_parse_change_title(int fd, struct map_session_data *sd)
  16090. {
  16091. int title_id, i;
  16092. nullpo_retv(sd);
  16093. title_id = RFIFOL(fd, 2);
  16094. if( title_id == sd->status.title_id ){
  16095. // It is exactly the same as the old one
  16096. return;
  16097. }else if( title_id <= 0 ){
  16098. sd->status.title_id = 0;
  16099. }else{
  16100. ARR_FIND(0, sd->titleCount, i, sd->titles[i] == title_id);
  16101. if( i == sd->titleCount ){
  16102. clif_change_title_ack(sd, 1, title_id);
  16103. return;
  16104. }
  16105. sd->status.title_id = title_id;
  16106. }
  16107. clif_name_area(&sd->bl);
  16108. clif_change_title_ack(sd, 0, title_id);
  16109. }
  16110. #ifdef DUMP_UNKNOWN_PACKET
  16111. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  16112. {
  16113. const char* packet_txt = "save/packet.txt";
  16114. FILE* fp;
  16115. time_t time_server;
  16116. struct tm *datetime;
  16117. char datestr[512];
  16118. time(&time_server); // get time in seconds since 1/1/1970
  16119. datetime = localtime(&time_server); // convert seconds in structure
  16120. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  16121. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  16122. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  16123. if( sd ) {
  16124. fprintf(fp, "Unknown packet 0x%04X (length %d), %s session #%d, %d/%d (AID/CID) at %s \n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id,datestr);
  16125. } else {
  16126. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16127. }
  16128. WriteDump(fp, RFIFOP(fd,0), packet_len);
  16129. fprintf(fp, "\n");
  16130. fclose(fp);
  16131. } else {
  16132. ShowError("Failed to write '%s'.\n", packet_txt);
  16133. // Dump on console instead
  16134. if( sd ) {
  16135. ShowDebug("Unknown packet 0x%04X (length %d), %s session #%d, %d/%d (AID/CID) at %s\n", cmd, packet_len, sd->state.active ? "authed" : "unauthed", fd, sd->status.account_id, sd->status.char_id,datestr);
  16136. } else {
  16137. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16138. }
  16139. ShowDump(RFIFOP(fd,0), packet_len);
  16140. }
  16141. }
  16142. #endif
  16143. /// Roulette System
  16144. /// Author: Yommy
  16145. /**
  16146. * Opens Roulette window
  16147. * @param fd
  16148. * @param sd
  16149. */
  16150. void clif_parse_RouletteOpen(int fd, struct map_session_data* sd)
  16151. {
  16152. nullpo_retv(sd);
  16153. if (!battle_config.feature_roulette) {
  16154. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16155. return;
  16156. }
  16157. WFIFOHEAD(fd,packet_len(0xa1a));
  16158. WFIFOW(fd,0) = 0xa1a;
  16159. WFIFOB(fd,2) = 0; // result
  16160. WFIFOL(fd,3) = 0; // serial
  16161. WFIFOB(fd,7) = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  16162. WFIFOB(fd,8) = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  16163. WFIFOW(fd,9) = -1; //! TODO: Display bonus item
  16164. WFIFOL(fd,11) = sd->roulette_point.gold;
  16165. WFIFOL(fd,15) = sd->roulette_point.silver;
  16166. WFIFOL(fd,19) = sd->roulette_point.bronze;
  16167. WFIFOSET(fd,packet_len(0xa1a));
  16168. }
  16169. /**
  16170. * Generates information to be displayed
  16171. * @param fd
  16172. * @param sd
  16173. */
  16174. void clif_parse_RouletteInfo(int fd, struct map_session_data* sd)
  16175. {
  16176. unsigned short i, j, count = 0;
  16177. int len = 8 + (42 * 8);
  16178. nullpo_retv(sd);
  16179. if (!battle_config.feature_roulette) {
  16180. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16181. return;
  16182. }
  16183. WFIFOHEAD(fd,len);
  16184. WFIFOW(fd,0) = 0xa1c;
  16185. WFIFOW(fd,2) = len;
  16186. WFIFOL(fd,4) = 1; // serial
  16187. for(i = 0; i < MAX_ROULETTE_LEVEL; i++) {
  16188. for(j = 0; j < MAX_ROULETTE_COLUMNS - i; j++) {
  16189. WFIFOW(fd,8 * count + 8) = i;
  16190. WFIFOW(fd,8 * count + 10) = j;
  16191. WFIFOW(fd,8 * count + 12) = rd.nameid[i][j];
  16192. WFIFOW(fd,8 * count + 14) = rd.qty[i][j];
  16193. count++;
  16194. }
  16195. }
  16196. WFIFOSET(fd,len);
  16197. return;
  16198. }
  16199. /**
  16200. * Closes Roulette window
  16201. * @param fd
  16202. * @param sd
  16203. */
  16204. void clif_parse_RouletteClose(int fd, struct map_session_data* sd)
  16205. {
  16206. nullpo_retv(sd);
  16207. if (!battle_config.feature_roulette) {
  16208. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16209. return;
  16210. }
  16211. /** What do we need this for? (other than state tracking), game client closes the window without our response. **/
  16212. return;
  16213. }
  16214. /**
  16215. *
  16216. **/
  16217. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  16218. #if PACKETVER >= 20141016
  16219. uint16 cmd = 0xa22;
  16220. unsigned char buf[5];
  16221. nullpo_retv(sd);
  16222. if (packet_db[cmd].len == 0)
  16223. return;
  16224. WBUFW(buf,0) = cmd;
  16225. WBUFB(buf,2) = type;
  16226. WBUFW(buf,3) = 0; //! TODO: Additional item
  16227. clif_send(buf, sizeof(buf), &sd->bl, SELF);
  16228. #endif
  16229. }
  16230. /**
  16231. * Claim roulette reward
  16232. * @param sd Player
  16233. * @return 0:Success
  16234. **/
  16235. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  16236. struct item it;
  16237. uint8 res = 1;
  16238. nullpo_retr(1, sd);
  16239. if (sd->roulette.prizeIdx < 0)
  16240. return RECV_ITEM_FAILED;
  16241. memset(&it, 0, sizeof(it));
  16242. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  16243. it.identify = 1;
  16244. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  16245. ; // onSuccess
  16246. }
  16247. sd->roulette.claimPrize = false;
  16248. sd->roulette.prizeStage = 0;
  16249. sd->roulette.prizeIdx = -1;
  16250. sd->roulette.stage = 0;
  16251. return res;
  16252. }
  16253. /**
  16254. * Process the stage and attempt to give a prize
  16255. * @param fd
  16256. * @param sd
  16257. */
  16258. void clif_parse_RouletteGenerate(int fd, struct map_session_data* sd)
  16259. {
  16260. enum GENERATE_ROULETTE_ACK result = GENERATE_ROULETTE_SUCCESS;
  16261. short stage = sd->roulette.stage;
  16262. nullpo_retv(sd);
  16263. if (!battle_config.feature_roulette) {
  16264. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16265. return;
  16266. }
  16267. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL)
  16268. stage = sd->roulette.stage = 0;
  16269. if (!stage) {
  16270. if (sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10)
  16271. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  16272. }
  16273. if (result == GENERATE_ROULETTE_SUCCESS) {
  16274. if (!stage) {
  16275. if (sd->roulette_point.bronze > 0) {
  16276. sd->roulette_point.bronze -= 1;
  16277. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  16278. } else if (sd->roulette_point.silver > 9) {
  16279. sd->roulette_point.silver -= 10;
  16280. stage = sd->roulette.stage = 2;
  16281. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  16282. } else if (sd->roulette_point.gold > 9) {
  16283. sd->roulette_point.gold -= 10;
  16284. stage = sd->roulette.stage = 4;
  16285. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  16286. }
  16287. }
  16288. sd->roulette.prizeStage = stage;
  16289. sd->roulette.prizeIdx = rnd()%rd.items[stage];
  16290. if (rd.flag[stage][sd->roulette.prizeIdx]&1) {
  16291. clif_roulette_generate_ack(sd,GENERATE_ROULETTE_LOSING,stage,sd->roulette.prizeIdx,0);
  16292. clif_roulette_getitem(sd);
  16293. clif_roulette_recvitem_ack(sd, RECV_ITEM_SUCCESS);
  16294. return;
  16295. }
  16296. else {
  16297. sd->roulette.claimPrize = true;
  16298. sd->roulette.stage++;
  16299. }
  16300. }
  16301. clif_roulette_generate_ack(sd,result,stage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  16302. }
  16303. /**
  16304. * Request to cash in prize
  16305. * @param fd
  16306. * @param sd
  16307. */
  16308. void clif_parse_RouletteRecvItem(int fd, struct map_session_data* sd)
  16309. {
  16310. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  16311. nullpo_retv(sd);
  16312. if (!battle_config.feature_roulette) {
  16313. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16314. return;
  16315. }
  16316. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  16317. switch (clif_roulette_getitem(sd)) {
  16318. case 0:
  16319. type = RECV_ITEM_SUCCESS;
  16320. break;
  16321. case 1:
  16322. case 4:
  16323. case 5:
  16324. type = RECV_ITEM_OVERCOUNT;
  16325. break;
  16326. case 2:
  16327. type = RECV_ITEM_OVERWEIGHT;
  16328. break;
  16329. case 7:
  16330. default:
  16331. type = RECV_ITEM_FAILED;
  16332. break;
  16333. }
  16334. }
  16335. clif_roulette_recvitem_ack(sd,type);
  16336. return;
  16337. }
  16338. /**
  16339. * Update Roulette window with current stats
  16340. * @param sd
  16341. * @param result
  16342. * @param stage
  16343. * @param prizeIdx
  16344. * @param bonusItemID
  16345. */
  16346. void clif_roulette_generate_ack(struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, short bonusItemID)
  16347. {
  16348. int fd = sd->fd;
  16349. nullpo_retv(sd);
  16350. WFIFOHEAD(fd,packet_len(0xa20));
  16351. WFIFOW(fd,0) = 0xa20;
  16352. WFIFOB(fd,2) = result;
  16353. WFIFOW(fd,3) = stage;
  16354. WFIFOW(fd,5) = prizeIdx;
  16355. WFIFOW(fd,7) = bonusItemID;
  16356. WFIFOL(fd,9) = sd->roulette_point.gold;
  16357. WFIFOL(fd,13) = sd->roulette_point.silver;
  16358. WFIFOL(fd,17) = sd->roulette_point.bronze;
  16359. WFIFOSET(fd,packet_len(0xa20));
  16360. }
  16361. /// MERGE ITEM
  16362. /**
  16363. * Acknowledge the client about item merger result
  16364. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  16365. * @param fd
  16366. * @param sd
  16367. **/
  16368. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  16369. unsigned char buf[9];
  16370. struct s_packet_db *info = NULL;
  16371. short cmd = 0;
  16372. nullpo_retv(sd);
  16373. if (!clif_session_isValid(sd))
  16374. return;
  16375. if (!(cmd = packet_db_ack[ZC_ACK_MERGE_ITEM]))
  16376. return;
  16377. if (!(info = &packet_db[cmd]) || info->len == 0)
  16378. return;
  16379. WBUFW(buf, 0) = cmd;
  16380. WBUFW(buf, info->pos[0]) = index;
  16381. WBUFW(buf, info->pos[1]) = count;
  16382. WBUFB(buf, info->pos[2]) = type;
  16383. clif_send(buf, info->len, &sd->bl, SELF);
  16384. }
  16385. /**
  16386. * Check if item has the pair to be merged
  16387. * @param sd
  16388. * @param it Item
  16389. * @return True if has pair, False if not
  16390. **/
  16391. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  16392. struct item *it_;
  16393. unsigned short i;
  16394. nullpo_retr(false, sd);
  16395. ARR_FIND(0, MAX_INVENTORY, i, (it_ = &sd->inventory.u.items_inventory[i]) && it->nameid == it_->nameid && it->bound == it_->bound && memcmp(it_, it, sizeof(struct item)) != 0);
  16396. if (i < MAX_INVENTORY)
  16397. return true;
  16398. return false;
  16399. }
  16400. /**
  16401. * Check if item can be merged
  16402. * @param id Item Data
  16403. * @param it Item
  16404. * @return True if can be merged, False if not
  16405. **/
  16406. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  16407. if (!id || !it)
  16408. return false;
  16409. if (id->type == IT_CASH)
  16410. return false;
  16411. if (!itemdb_isstackable2(id))
  16412. return false;
  16413. if (itemdb_isspecial(it->card[0]))
  16414. return false;
  16415. if (!it->unique_id)
  16416. return false;
  16417. return true;
  16418. }
  16419. /**
  16420. * Open available item to be merged.
  16421. * Only show 1 item in 1 process.
  16422. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  16423. * @param sd
  16424. **/
  16425. void clif_merge_item_open(struct map_session_data *sd) {
  16426. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  16427. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  16428. int len = 0;
  16429. struct s_packet_db *info = NULL;
  16430. struct item *it;
  16431. nullpo_retv(sd);
  16432. if (!clif_session_isValid(sd))
  16433. return;
  16434. if (!(cmd = packet_db_ack[ZC_MERGE_ITEM_OPEN]))
  16435. return;
  16436. if (!(info = &packet_db[cmd]) || info->len == 0)
  16437. return;
  16438. // Get entries
  16439. for (i = 0; i < MAX_INVENTORY; i++) {
  16440. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->inventory.u.items_inventory[i])))
  16441. continue;
  16442. if (clif_merge_item_has_pair(sd, it))
  16443. indexes[n++] = i;
  16444. }
  16445. if (n < 2) { // No item need to be merged
  16446. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16447. return;
  16448. }
  16449. WBUFW(buf, 0) = cmd;
  16450. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  16451. for (i = 0; i < n; i++) {
  16452. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  16453. }
  16454. clif_send(buf, len, &sd->bl, SELF);
  16455. }
  16456. /**
  16457. * Process item merger
  16458. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  16459. * @param fd
  16460. * @param sd
  16461. **/
  16462. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  16463. struct s_packet_db *info = NULL;
  16464. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  16465. unsigned int count = 0;
  16466. struct item_data *id = NULL;
  16467. nullpo_retv(sd);
  16468. if (!clif_session_isValid(sd))
  16469. return;
  16470. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  16471. return;
  16472. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  16473. if (n < 2) { // No item need to be merged
  16474. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16475. return;
  16476. }
  16477. for (i = 0, j = 0; i < n; i++) {
  16478. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  16479. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  16480. continue;
  16481. indexes[j] = idx;
  16482. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  16483. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  16484. return;
  16485. }
  16486. count += sd->inventory.u.items_inventory[idx].amount;
  16487. j++;
  16488. }
  16489. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  16490. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16491. return;
  16492. }
  16493. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  16494. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  16495. return;
  16496. }
  16497. // Merrrrge!!!!
  16498. for (i = 1; i < n; i++) {
  16499. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  16500. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  16501. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  16502. sd->inventory_data[idx] = NULL;
  16503. clif_delitem(sd, idx, amt, 0);
  16504. }
  16505. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  16506. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  16507. }
  16508. /**
  16509. * Cancel item merge
  16510. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  16511. * @param fd
  16512. * @param sd
  16513. **/
  16514. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  16515. return; // Nothing todo yet
  16516. }
  16517. /**
  16518. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16519. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16520. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [surcename] ... [itemname]" -> MsgStringTable[1629]
  16521. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  16522. **/
  16523. void clif_broadcast_obtain_special_item(const char *char_name, unsigned short nameid, unsigned short container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type, const char *srcname) {
  16524. unsigned char buf[9 + NAME_LENGTH * 2];
  16525. unsigned short cmd = 0;
  16526. struct s_packet_db *info = NULL;
  16527. if (!(cmd = packet_db_ack[ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN]))
  16528. return;
  16529. if (!(info = &packet_db[cmd]) || info->len == 0)
  16530. return;
  16531. WBUFW(buf, 0) = 0x7fd;
  16532. WBUFB(buf, 4) = type;
  16533. WBUFW(buf, 5) = nameid;
  16534. WBUFB(buf, 7) = NAME_LENGTH;
  16535. safestrncpy(WBUFCP(buf, 8), char_name, NAME_LENGTH);
  16536. switch (type) {
  16537. case ITEMOBTAIN_TYPE_BOXITEM:
  16538. WBUFW(buf, 2) = 11 + NAME_LENGTH;
  16539. WBUFB(buf, 8 + NAME_LENGTH) = 0;
  16540. WBUFW(buf, 9 + NAME_LENGTH) = container;
  16541. break;
  16542. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  16543. {
  16544. struct mob_db *db = mob_db(container);
  16545. WBUFW(buf, 2) = 9 + NAME_LENGTH * 2;
  16546. WBUFB(buf, 8 + NAME_LENGTH) = NAME_LENGTH;
  16547. safestrncpy(WBUFCP(buf, 9 + NAME_LENGTH), db->name, NAME_LENGTH);
  16548. }
  16549. break;
  16550. case ITEMOBTAIN_TYPE_NPC:
  16551. default:
  16552. WBUFW(buf, 2) = 8 + NAME_LENGTH;
  16553. break;
  16554. }
  16555. clif_send(buf, WBUFW(buf, 2), NULL, ALL_CLIENT);
  16556. }
  16557. /// Show body view windows (ZC_DRESSROOM_OPEN).
  16558. /// 0A02 <view>.W
  16559. /// Value <flag> has the following effects:
  16560. /// 1: Open a Dress Room window.
  16561. void clif_dressing_room(struct map_session_data *sd, int flag) {
  16562. #if PACKETVER >= 20150513
  16563. int fd = sd->fd;
  16564. nullpo_retv(sd);
  16565. WFIFOHEAD(fd, packet_len(0xa02));
  16566. WFIFOW(fd,0) = 0xa02;
  16567. WFIFOW(fd,2) = flag;
  16568. WFIFOSET(fd, packet_len(0xa02));
  16569. #endif
  16570. }
  16571. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  16572. /// 0A35 <result>.W
  16573. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  16574. #if PACKETVER >= 20150513
  16575. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  16576. // Ignore the request
  16577. // - Invalid item index
  16578. // - Invalid item ID or item doesn't exist
  16579. // - Item is already identified
  16580. if (idx < 0 || idx >= MAX_INVENTORY ||
  16581. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  16582. sd->inventory.u.items_inventory[idx].identify)
  16583. return;
  16584. // Ignore the request - No magnifiers in inventory
  16585. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  16586. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  16587. return;
  16588. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  16589. return;
  16590. skill_identify(sd, idx);
  16591. #endif
  16592. }
  16593. /// Starts navigation to the given target on client side
  16594. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  16595. #if PACKETVER >= 20111010
  16596. int fd = sd->fd;
  16597. WFIFOHEAD(fd,27);
  16598. WFIFOW(fd,0) = 0x08e2;
  16599. // How detailed will our navigation be?
  16600. if( mob_id > 0 ){
  16601. x = 0;
  16602. y = 0;
  16603. WFIFOB(fd,2) = 3; // monster with destination field
  16604. }else if( x > 0 && y > 0 ){
  16605. WFIFOB(fd,2) = 0; // with coordinates
  16606. }else{
  16607. x = 0;
  16608. y = 0;
  16609. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  16610. }
  16611. // Which services can be used for transportation?
  16612. WFIFOB(fd,3) = flag;
  16613. // If this flag is set, the navigation window will not be opened up
  16614. WFIFOB(fd,4) = hideWindow;
  16615. // Target map
  16616. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  16617. // Target x
  16618. WFIFOW(fd,21) = x;
  16619. // Target y
  16620. WFIFOW(fd,23) = y;
  16621. // Target monster ID
  16622. WFIFOW(fd,25) = mob_id;
  16623. WFIFOSET(fd,27);
  16624. #endif
  16625. }
  16626. /// Send hat effects to the client (ZC_HAT_EFFECT).
  16627. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  16628. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  16629. #if PACKETVER >= 20150513
  16630. unsigned char* buf;
  16631. int len,i;
  16632. struct map_session_data *tsd;
  16633. struct block_list* tbl;
  16634. if( target == SELF ){
  16635. tsd = BL_CAST(BL_PC,bl);
  16636. tbl = &sd->bl;
  16637. }else{
  16638. tsd = sd;
  16639. tbl = bl;
  16640. }
  16641. if( !tsd->hatEffectCount )
  16642. return;
  16643. len = 9 + tsd->hatEffectCount * 2;
  16644. buf = (unsigned char*)aMalloc( len );
  16645. WBUFW(buf,0) = 0xa3b;
  16646. WBUFW(buf,2) = len;
  16647. WBUFL(buf,4) = tsd->bl.id;
  16648. WBUFB(buf,8) = 1;
  16649. for( i = 0; i < tsd->hatEffectCount; i++ ){
  16650. WBUFW(buf,9+i*2) = tsd->hatEffectIDs[i];
  16651. }
  16652. clif_send(buf, len,tbl,target);
  16653. aFree(buf);
  16654. #endif
  16655. }
  16656. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  16657. #if PACKETVER >= 20150513
  16658. unsigned char buf[13];
  16659. WBUFW(buf,0) = 0xa3b;
  16660. WBUFW(buf,2) = 13;
  16661. WBUFL(buf,4) = sd->bl.id;
  16662. WBUFB(buf,8) = enable;
  16663. WBUFL(buf,9) = effectId;
  16664. clif_send(buf,13,&sd->bl,AREA);
  16665. #endif
  16666. }
  16667. /// Notify the client that a sale has started
  16668. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  16669. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  16670. #if PACKETVER_SUPPORTS_SALES
  16671. unsigned char buf[8];
  16672. WBUFW(buf, 0) = 0x9b2;
  16673. WBUFW(buf, 2) = sale_item->nameid;
  16674. WBUFL(buf, 4) = (uint32)(sale_item->end - time(NULL)); // time in S
  16675. clif_send(buf, 8, bl, target);
  16676. #endif
  16677. }
  16678. /// Notify the clien that a sale has ended
  16679. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  16680. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  16681. #if PACKETVER_SUPPORTS_SALES
  16682. unsigned char buf[4];
  16683. WBUFW(buf, 0) = 0x9b3;
  16684. WBUFW(buf, 2) = sale_item->nameid;
  16685. clif_send(buf, 4, bl, target);
  16686. #endif
  16687. }
  16688. /// Update the remaining amount of a sale item.
  16689. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  16690. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  16691. #if PACKETVER_SUPPORTS_SALES
  16692. unsigned char buf[8];
  16693. WBUFW(buf, 0) = 0x9c4;
  16694. WBUFW(buf, 2) = sale_item->nameid;
  16695. WBUFL(buf, 4) = sale_item->amount;
  16696. clif_send(buf, 8, bl, target);
  16697. #endif
  16698. }
  16699. /// The client requested a refresh of the current remaining count of a sale item
  16700. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  16701. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  16702. #if PACKETVER_SUPPORTS_SALES
  16703. struct sale_item_data* sale;
  16704. if( RFIFOL(fd, 2) != sd->status.account_id ){
  16705. return;
  16706. }
  16707. sale = sale_find_item( RFIFOW(fd, 6), true );
  16708. if( sale == NULL ){
  16709. return;
  16710. }
  16711. clif_sale_amount(sale, &sd->bl, SELF);
  16712. #endif
  16713. }
  16714. /// Opens the sale administration window on the client
  16715. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  16716. void clif_sale_open( struct map_session_data* sd ){
  16717. #if PACKETVER_SUPPORTS_SALES
  16718. int fd = sd->fd;
  16719. // TODO: do we want state tracking?
  16720. WFIFOHEAD(fd, 2);
  16721. WFIFOW(fd, 0) = 0x9b5;
  16722. WFIFOSET(fd, 2);
  16723. #endif
  16724. }
  16725. /// Client request to open the sale administration window.
  16726. /// This is sent by /limitedsale
  16727. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  16728. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  16729. #if PACKETVER_SUPPORTS_SALES
  16730. nullpo_retv(sd);
  16731. if( RFIFOL(fd, 2) != sd->status.account_id ){
  16732. return;
  16733. }
  16734. if( !pc_has_permission( sd, PC_PERM_CASHSHOP_SALE ) ){
  16735. return;
  16736. }
  16737. clif_sale_open(sd);
  16738. #endif
  16739. }
  16740. /// Closes the sale administration window on the client.
  16741. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  16742. void clif_sale_close(struct map_session_data* sd) {
  16743. #if PACKETVER_SUPPORTS_SALES
  16744. int fd = sd->fd;
  16745. WFIFOHEAD(fd, 2);
  16746. WFIFOW(fd, 0) = 0x9bd;
  16747. WFIFOSET(fd, 2);
  16748. #endif
  16749. }
  16750. /// Client request to close the sale administration window.
  16751. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  16752. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  16753. #if PACKETVER_SUPPORTS_SALES
  16754. nullpo_retv(sd);
  16755. if( RFIFOL(fd, 2) != sd->status.account_id ){
  16756. return;
  16757. }
  16758. // TODO: do we want state tracking?
  16759. clif_sale_close(sd);
  16760. #endif
  16761. }
  16762. /// Reply to a item search request for item sale administration.
  16763. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  16764. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  16765. #if PACKETVER_SUPPORTS_SALES
  16766. int fd = sd->fd;
  16767. WFIFOHEAD(fd, 10);
  16768. WFIFOW(fd, 0) = 0x9ad;
  16769. if( item != NULL ){
  16770. WFIFOW(fd, 2) = 0;
  16771. WFIFOW(fd, 4) = item->nameid;
  16772. WFIFOL(fd, 6) = item->price;
  16773. }else{
  16774. WFIFOW(fd, 2) = 1;
  16775. WFIFOW(fd, 4) = 0;
  16776. WFIFOL(fd, 6) = 0;
  16777. }
  16778. WFIFOSET(fd, 10);
  16779. #endif
  16780. }
  16781. /// Search request for an item sale administration.
  16782. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  16783. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  16784. #if PACKETVER_SUPPORTS_SALES
  16785. char item_name[ITEM_NAME_LENGTH];
  16786. struct item_data *id = NULL;
  16787. nullpo_retv(sd);
  16788. if( RFIFOL(fd, 4) != sd->status.account_id ){
  16789. return;
  16790. }
  16791. if( !pc_has_permission( sd, PC_PERM_CASHSHOP_SALE ) ){
  16792. return;
  16793. }
  16794. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  16795. id = itemdb_searchname(item_name);
  16796. if( id ){
  16797. int i;
  16798. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  16799. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  16800. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  16801. return;
  16802. }
  16803. }
  16804. }
  16805. // not found
  16806. clif_sale_search_reply( sd, NULL );
  16807. #endif
  16808. }
  16809. /// Reply if an item was successfully put on sale or not.
  16810. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  16811. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  16812. #if PACKETVER_SUPPORTS_SALES
  16813. int fd = sd->fd;
  16814. WFIFOHEAD(fd, 4);
  16815. WFIFOW(fd, 0) = 0x9af;
  16816. WFIFOW(fd, 2) = (uint16)result;
  16817. WFIFOSET(fd, 4);
  16818. #endif
  16819. }
  16820. /// A client request to put an item on sale.
  16821. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  16822. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W
  16823. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  16824. #if PACKETVER_SUPPORTS_SALES
  16825. int32 count;
  16826. int16 nameid;
  16827. int startTime;
  16828. int endTime;
  16829. uint16 sellingHours;
  16830. nullpo_retv(sd);
  16831. if( RFIFOL(fd, 2) != sd->status.account_id ){
  16832. return;
  16833. }
  16834. if( !pc_has_permission( sd, PC_PERM_CASHSHOP_SALE ) ){
  16835. return;
  16836. }
  16837. nameid = RFIFOW(fd, 6);
  16838. count = RFIFOL(fd, 8);
  16839. startTime = RFIFOL(fd, 12);
  16840. #if PACKETVER >= 20150520
  16841. if( RFIFOW(fd,0) == 0xa3d )
  16842. sellingHours = RFIFOW(fd, 16);
  16843. else
  16844. #endif
  16845. sellingHours = RFIFOB(fd, 16);
  16846. endTime = startTime + sellingHours * 60 * 60;
  16847. clif_sale_add_reply( sd, sale_add_item(nameid,count,startTime,endTime) );
  16848. #endif
  16849. }
  16850. /// Reply to an item removal from sale.
  16851. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  16852. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  16853. #if PACKETVER_SUPPORTS_SALES
  16854. int fd = sd->fd;
  16855. WFIFOHEAD(fd, 4);
  16856. WFIFOW(fd, 0) = 0x9b1;
  16857. WFIFOW(fd, 2) = failed;
  16858. WFIFOSET(fd, 4);
  16859. #endif
  16860. }
  16861. /// Request to remove an item from sale.
  16862. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  16863. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  16864. #if PACKETVER_SUPPORTS_SALES
  16865. nullpo_retv(sd);
  16866. if( RFIFOL(fd, 2) != sd->status.account_id ){
  16867. return;
  16868. }
  16869. if( !pc_has_permission( sd, PC_PERM_CASHSHOP_SALE ) ){
  16870. return;
  16871. }
  16872. clif_sale_remove_reply(sd, !sale_remove_item(RFIFOW(fd, 6)));
  16873. #endif
  16874. }
  16875. /// Achievement System
  16876. /// Author: Luxuri, Aleos
  16877. /**
  16878. * Sends all achievement data to the client (ZC_ALL_AG_LIST).
  16879. * 0a23 <packetType>.W <packetLength>.W <ACHCount>.L <ACHPoint>.L
  16880. */
  16881. void clif_achievement_list_all(struct map_session_data *sd)
  16882. {
  16883. int i, j, len, fd, *info;
  16884. uint16 count = 0;
  16885. nullpo_retv(sd);
  16886. if (!battle_config.feature_achievement) {
  16887. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  16888. return;
  16889. }
  16890. fd = sd->fd;
  16891. count = sd->achievement_data.count; // All achievements should be sent to the client
  16892. len = (50 * count) + 22;
  16893. if (len <= 22)
  16894. return;
  16895. info = achievement_level(sd, true);
  16896. WFIFOHEAD(fd,len);
  16897. WFIFOW(fd, 0) = 0xa23;
  16898. WFIFOW(fd, 2) = len;
  16899. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  16900. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  16901. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  16902. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  16903. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  16904. for (i = 0; i < count; i++) {
  16905. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  16906. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  16907. for (j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  16908. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  16909. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  16910. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  16911. }
  16912. WFIFOSET(fd, len);
  16913. }
  16914. /**
  16915. * Sends a single achievement's data to the client (ZC_AG_UPDATE).
  16916. * 0a24 <packetType>.W <ACHPoint>.L
  16917. */
  16918. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  16919. {
  16920. int fd, i, *info;
  16921. nullpo_retv(sd);
  16922. if (!battle_config.feature_achievement) {
  16923. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  16924. return;
  16925. }
  16926. fd = sd->fd;
  16927. info = achievement_level(sd, true);
  16928. WFIFOHEAD(fd, packet_len(0xa24));
  16929. WFIFOW(fd, 0) = 0xa24;
  16930. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  16931. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  16932. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  16933. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  16934. if (ach) {
  16935. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  16936. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  16937. for (i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  16938. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  16939. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  16940. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  16941. } else
  16942. memset(WFIFOP(fd, 16), 0, 40);
  16943. WFIFOSET(fd, packet_len(0xa24));
  16944. }
  16945. /**
  16946. * Checks if an achievement reward can be rewarded (CZ_REQ_AG_REWARD).
  16947. * 0a25 <packetType>.W <achievementID>.L
  16948. */
  16949. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  16950. {
  16951. nullpo_retv(sd);
  16952. if( sd->achievement_data.save )
  16953. intif_achievement_save(sd);
  16954. achievement_check_reward(sd, RFIFOL(fd,2));
  16955. }
  16956. /**
  16957. * Returns the result of achievement_check_reward (ZC_REQ_AG_REWARD_ACK).
  16958. * 0a26 <packetType>.W <result>.W <achievementID>.L
  16959. */
  16960. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  16961. {
  16962. WFIFOHEAD(fd, packet_len(0xa26));
  16963. WFIFOW(fd, 0) = 0xa26;
  16964. WFIFOB(fd, 2) = result;
  16965. WFIFOL(fd, 3) = achievement_id;
  16966. WFIFOSET(fd, packet_len(0xa26));
  16967. }
  16968. /*==========================================
  16969. * Main client packet processing function
  16970. *------------------------------------------*/
  16971. static int clif_parse(int fd)
  16972. {
  16973. int cmd, packet_len;
  16974. TBL_PC* sd;
  16975. int pnum;
  16976. #ifdef PACKET_OBFUSCATION
  16977. int cmd2;
  16978. #endif
  16979. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  16980. // Note: "click masters" can do 80+ clicks in 10 seconds
  16981. for( pnum = 0; pnum < 3; ++pnum )// Limit max packets per cycle to 3 (delay packet spammers) [FlavioJS] -- This actually aids packet spammers, but stuff like /str+ gets slow without it [Ai4rei]
  16982. { // begin main client packet processing loop
  16983. sd = (TBL_PC *)session[fd]->session_data;
  16984. if (session[fd]->flag.eof) {
  16985. if (sd) {
  16986. if (sd->state.autotrade) {
  16987. //Disassociate character from the socket connection.
  16988. session[fd]->session_data = NULL;
  16989. sd->fd = 0;
  16990. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  16991. } else
  16992. if (sd->state.active) {
  16993. // Player logout display [Valaris]
  16994. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  16995. clif_quitsave(fd, sd);
  16996. } else {
  16997. //Unusual logout (during log on/off/map-changer procedure)
  16998. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  16999. map_quit(sd);
  17000. }
  17001. } else {
  17002. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  17003. }
  17004. do_close(fd);
  17005. return 0;
  17006. }
  17007. if (RFIFOREST(fd) < 2)
  17008. return 0;
  17009. cmd = RFIFOW(fd, 0);
  17010. #ifdef PACKET_OBFUSCATION
  17011. // Check if it is a player that tries to connect to the map server.
  17012. if( sd ){
  17013. // Decrypt the current packet ID with the last key stored in the session.
  17014. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  17015. }else{
  17016. // Store the original value for checking
  17017. cmd2 = cmd;
  17018. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  17019. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17020. }
  17021. #endif
  17022. // filter out invalid / unsupported packets
  17023. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  17024. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  17025. #ifdef DUMP_INVALID_PACKET
  17026. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17027. #endif
  17028. #ifdef PACKET_OBFUSCATION_WARN
  17029. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  17030. if( !sd ){
  17031. #ifdef PACKET_OBFUSCATION
  17032. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  17033. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  17034. }
  17035. #else
  17036. // Try to use the initial keys for the decryption of the packet ID.
  17037. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17038. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  17039. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  17040. }
  17041. #endif
  17042. }
  17043. #endif
  17044. set_eof(fd);
  17045. return 0;
  17046. }
  17047. // determine real packet length
  17048. packet_len = packet_db[cmd].len;
  17049. if (packet_len == -1) { // variable-length packet
  17050. if (RFIFOREST(fd) < 4)
  17051. return 0;
  17052. packet_len = RFIFOW(fd,2);
  17053. if (packet_len < 4 || packet_len > 32768) {
  17054. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  17055. #ifdef DUMP_INVALID_PACKET
  17056. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17057. #endif
  17058. set_eof(fd);
  17059. return 0;
  17060. }
  17061. }
  17062. if ((int)RFIFOREST(fd) < packet_len)
  17063. return 0; // not enough data received to form the packet
  17064. #ifdef PACKET_OBFUSCATION
  17065. RFIFOW(fd, 0) = cmd;
  17066. if (sd)
  17067. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  17068. #endif
  17069. if( packet_db[cmd].func == clif_parse_debug )
  17070. packet_db[cmd].func(fd, sd);
  17071. else if( packet_db[cmd].func != NULL ) {
  17072. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  17073. ; //Only valid packet when there is no session
  17074. else
  17075. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  17076. ; //Only valid packet when player is not on a map
  17077. else
  17078. packet_db[cmd].func(fd, sd);
  17079. }
  17080. #ifdef DUMP_UNKNOWN_PACKET
  17081. else DumpUnknown(fd,sd,cmd,packet_len);
  17082. #endif
  17083. RFIFOSKIP(fd, packet_len);
  17084. }; // main loop end
  17085. return 0;
  17086. }
  17087. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  17088. va_list argp;
  17089. int i;
  17090. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  17091. return;
  17092. packet_db[cmd].len = length;
  17093. packet_db[cmd].func = func;
  17094. va_start(argp, func);
  17095. for( i = 0; i < MAX_PACKET_POS; i++ ){
  17096. int offset = va_arg(argp, int);
  17097. if( offset == 0 ){
  17098. break;
  17099. }
  17100. packet_db[cmd].pos[i] = offset;
  17101. }
  17102. if( i == MAX_PACKET_POS ){
  17103. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  17104. }
  17105. va_end(argp);
  17106. }
  17107. /*==========================================
  17108. * Reads packets and setups its array reference
  17109. *------------------------------------------*/
  17110. void packetdb_readdb(){
  17111. memset(packet_db,0,sizeof(packet_db));
  17112. memset(packet_db_ack,0,sizeof(packet_db_ack));
  17113. #include "clif_packetdb.h"
  17114. #include "clif_shuffle.h"
  17115. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  17116. #ifdef PACKET_OBFUSCATION
  17117. ShowStatus("Packet Obfuscation: " CL_GREEN "Enabled" CL_RESET ". Keys: " CL_WHITE "0x%08X, 0x%08X, 0x%08X" CL_RESET "\n", clif_cryptKey[0], clif_cryptKey[1], clif_cryptKey[2]);
  17118. #else
  17119. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  17120. #endif
  17121. }
  17122. /*==========================================
  17123. *
  17124. *------------------------------------------*/
  17125. void do_init_clif(void) {
  17126. const char* colors[COLOR_MAX] = {
  17127. "0x00FF00",
  17128. "0xFF0000",
  17129. "0xFFFFFF",
  17130. "0xFFFF00",
  17131. "0x00FFFF",
  17132. "0xB5FFB5",
  17133. };
  17134. int i;
  17135. /**
  17136. * Setup Color Table (saves unnecessary load of strtoul on every call)
  17137. **/
  17138. for(i = 0; i < COLOR_MAX; i++) {
  17139. color_table[i] = strtoul(colors[i],NULL,0);
  17140. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  17141. }
  17142. packetdb_readdb();
  17143. set_defaultparse(clif_parse);
  17144. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  17145. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  17146. exit(EXIT_FAILURE);
  17147. }
  17148. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  17149. add_timer_func_list(clif_delayquit, "clif_delayquit");
  17150. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  17151. }
  17152. void do_final_clif(void) {
  17153. ers_destroy(delay_clearunit_ers);
  17154. }
  17155. #ifdef __cplusplus
  17156. }
  17157. #endif