clif.cpp 569 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307
  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_ == JT_GUILD_FLAG )
  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, EF_SNOW, fd);
  1218. if (map[m].flag.clouds)
  1219. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1220. if (map[m].flag.clouds2)
  1221. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1222. if (map[m].flag.fog)
  1223. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1224. if (map[m].flag.fireworks) {
  1225. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1226. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1227. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1228. }
  1229. if (map[m].flag.sakura)
  1230. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1231. if (map[m].flag.leaves)
  1232. clif_specialeffect_single(&sd->bl, EF_MAPLE, 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_ == JT_INVISIBLE )
  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,EF_GIANTBODY2,AREA);
  1283. else if(sd->state.size==SZ_MEDIUM)
  1284. clif_specialeffect(bl,EF_BABYBODY2,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,EF_GIANTBODY2,AREA);
  1300. else if(md->special_state.size==SZ_MEDIUM)
  1301. clif_specialeffect(&md->bl,EF_BABYBODY2,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,EF_GIANTBODY2,AREA);
  1309. else if( nd->size == SZ_MEDIUM )
  1310. clif_specialeffect(&nd->bl,EF_BABYBODY2,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,EF_GIANTBODY2,AREA);
  1533. else if(sd->state.size==SZ_MEDIUM)
  1534. clif_specialeffect(&sd->bl,EF_BABYBODY2,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,EF_GIANTBODY2,AREA);
  1544. else if(md->special_state.size==SZ_MEDIUM)
  1545. clif_specialeffect(&md->bl,EF_BABYBODY2,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_ == JT_INVISIBLE ){
  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. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2780. /// TODO: Extract individual packets.
  2781. /// FIXME: Packet lengths from packet_len(cmd)
  2782. void clif_updatestatus(struct map_session_data *sd,int type)
  2783. {
  2784. int fd,len=8;
  2785. nullpo_retv(sd);
  2786. fd=sd->fd;
  2787. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2788. return;
  2789. WFIFOHEAD(fd, 14);
  2790. WFIFOW(fd,0)=0xb0;
  2791. WFIFOW(fd,2)=type;
  2792. switch(type){
  2793. // 00b0
  2794. case SP_WEIGHT:
  2795. pc_updateweightstatus(sd);
  2796. WFIFOHEAD(fd,14);
  2797. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2798. WFIFOW(fd,2)=type;
  2799. WFIFOL(fd,4)=sd->weight;
  2800. break;
  2801. case SP_MAXWEIGHT:
  2802. WFIFOL(fd,4)=sd->max_weight;
  2803. break;
  2804. case SP_SPEED:
  2805. WFIFOL(fd,4)=sd->battle_status.speed;
  2806. break;
  2807. case SP_BASELEVEL:
  2808. WFIFOL(fd,4)=sd->status.base_level;
  2809. break;
  2810. case SP_JOBLEVEL:
  2811. WFIFOL(fd,4)=sd->status.job_level;
  2812. break;
  2813. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2814. WFIFOL(fd,4)=sd->status.karma;
  2815. break;
  2816. case SP_MANNER:
  2817. WFIFOL(fd,4)=sd->status.manner;
  2818. break;
  2819. case SP_STATUSPOINT:
  2820. WFIFOL(fd,4)=sd->status.status_point;
  2821. break;
  2822. case SP_SKILLPOINT:
  2823. WFIFOL(fd,4)=sd->status.skill_point;
  2824. break;
  2825. case SP_HIT:
  2826. WFIFOL(fd,4)=sd->battle_status.hit;
  2827. break;
  2828. case SP_FLEE1:
  2829. WFIFOL(fd,4)=sd->battle_status.flee;
  2830. break;
  2831. case SP_FLEE2:
  2832. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2833. break;
  2834. case SP_MAXHP:
  2835. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2836. break;
  2837. case SP_MAXSP:
  2838. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2839. break;
  2840. case SP_HP:
  2841. // On officials the HP never go below 1, even if you die [Lemongrass]
  2842. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2843. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2844. break;
  2845. case SP_SP:
  2846. WFIFOL(fd,4)=sd->battle_status.sp;
  2847. break;
  2848. case SP_ASPD:
  2849. WFIFOL(fd,4)=sd->battle_status.amotion;
  2850. break;
  2851. case SP_ATK1:
  2852. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2853. break;
  2854. case SP_DEF1:
  2855. WFIFOL(fd,4)=pc_leftside_def(sd);
  2856. break;
  2857. case SP_MDEF1:
  2858. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2859. break;
  2860. case SP_ATK2:
  2861. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2862. break;
  2863. case SP_DEF2:
  2864. WFIFOL(fd,4)=pc_rightside_def(sd);
  2865. break;
  2866. case SP_MDEF2: {
  2867. //negative check (in case you have something like Berserk active)
  2868. int mdef2 = pc_rightside_mdef(sd);
  2869. WFIFOL(fd,4)=
  2870. #ifndef RENEWAL
  2871. ( mdef2 < 0 ) ? 0 :
  2872. #endif
  2873. mdef2;
  2874. }
  2875. break;
  2876. case SP_CRITICAL:
  2877. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2878. break;
  2879. case SP_MATK1:
  2880. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2881. break;
  2882. case SP_MATK2:
  2883. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2884. break;
  2885. case SP_ZENY:
  2886. WFIFOW(fd,0)=0xb1;
  2887. WFIFOL(fd,4)=sd->status.zeny;
  2888. break;
  2889. #if PACKETVER >= 20170830
  2890. case SP_BASEEXP:
  2891. WFIFOW(fd,0)=0xacb;
  2892. WFIFOQ(fd,4)=sd->status.base_exp;
  2893. len = packet_len(0xacb);
  2894. break;
  2895. case SP_JOBEXP:
  2896. WFIFOW(fd,0)=0xacb;
  2897. WFIFOQ(fd,4)=sd->status.job_exp;
  2898. len = packet_len(0xacb);
  2899. break;
  2900. case SP_NEXTBASEEXP:
  2901. WFIFOW(fd,0)=0xacb;
  2902. WFIFOQ(fd,4)=pc_nextbaseexp(sd);
  2903. len = packet_len(0xacb);
  2904. break;
  2905. case SP_NEXTJOBEXP:
  2906. WFIFOW(fd,0)=0xacb;
  2907. WFIFOQ(fd,4)=pc_nextjobexp(sd);
  2908. len = packet_len(0xacb);
  2909. break;
  2910. #else
  2911. case SP_BASEEXP:
  2912. WFIFOW(fd,0)=0xb1;
  2913. WFIFOL(fd,4)=sd->status.base_exp;
  2914. break;
  2915. case SP_JOBEXP:
  2916. WFIFOW(fd,0)=0xb1;
  2917. WFIFOL(fd,4)=sd->status.job_exp;
  2918. break;
  2919. case SP_NEXTBASEEXP:
  2920. WFIFOW(fd,0)=0xb1;
  2921. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2922. break;
  2923. case SP_NEXTJOBEXP:
  2924. WFIFOW(fd,0)=0xb1;
  2925. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2926. break;
  2927. #endif
  2928. /**
  2929. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2930. **/
  2931. case SP_USTR:
  2932. case SP_UAGI:
  2933. case SP_UVIT:
  2934. case SP_UINT:
  2935. case SP_UDEX:
  2936. case SP_ULUK:
  2937. WFIFOW(fd,0)=0xbe;
  2938. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2939. len=5;
  2940. break;
  2941. /**
  2942. * Tells the client how far it is allowed to attack (weapon range)
  2943. **/
  2944. case SP_ATTACKRANGE:
  2945. WFIFOW(fd,0)=0x13a;
  2946. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2947. len=4;
  2948. break;
  2949. case SP_STR:
  2950. WFIFOW(fd,0)=0x141;
  2951. WFIFOL(fd,2)=type;
  2952. WFIFOL(fd,6)=sd->status.str;
  2953. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2954. len=14;
  2955. break;
  2956. case SP_AGI:
  2957. WFIFOW(fd,0)=0x141;
  2958. WFIFOL(fd,2)=type;
  2959. WFIFOL(fd,6)=sd->status.agi;
  2960. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2961. len=14;
  2962. break;
  2963. case SP_VIT:
  2964. WFIFOW(fd,0)=0x141;
  2965. WFIFOL(fd,2)=type;
  2966. WFIFOL(fd,6)=sd->status.vit;
  2967. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2968. len=14;
  2969. break;
  2970. case SP_INT:
  2971. WFIFOW(fd,0)=0x141;
  2972. WFIFOL(fd,2)=type;
  2973. WFIFOL(fd,6)=sd->status.int_;
  2974. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2975. len=14;
  2976. break;
  2977. case SP_DEX:
  2978. WFIFOW(fd,0)=0x141;
  2979. WFIFOL(fd,2)=type;
  2980. WFIFOL(fd,6)=sd->status.dex;
  2981. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2982. len=14;
  2983. break;
  2984. case SP_LUK:
  2985. WFIFOW(fd,0)=0x141;
  2986. WFIFOL(fd,2)=type;
  2987. WFIFOL(fd,6)=sd->status.luk;
  2988. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2989. len=14;
  2990. break;
  2991. case SP_CARTINFO:
  2992. WFIFOW(fd,0)=0x121;
  2993. WFIFOW(fd,2)=sd->cart_num;
  2994. WFIFOW(fd,4)=MAX_CART;
  2995. WFIFOL(fd,6)=sd->cart_weight;
  2996. WFIFOL(fd,10)=sd->cart_weight_max;
  2997. len=14;
  2998. break;
  2999. default:
  3000. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3001. return;
  3002. }
  3003. WFIFOSET(fd,len);
  3004. // Additional update packets that should be sent right after
  3005. switch( type ){
  3006. case SP_BASELEVEL:
  3007. if( sd->status.party_id ){
  3008. struct party_data* p;
  3009. int i;
  3010. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3011. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3012. if( i < MAX_PARTY ){
  3013. p->party.member[i].lv = sd->status.base_level;
  3014. clif_party_job_and_level(sd);
  3015. }
  3016. }
  3017. }
  3018. break;
  3019. case SP_HP:
  3020. if( map[sd->bl.m].hpmeter_visible ){
  3021. clif_hpmeter(sd);
  3022. }
  3023. if( !battle_config.party_hp_mode && sd->status.party_id ){
  3024. clif_party_hp(sd);
  3025. }
  3026. if( sd->bg_id ){
  3027. clif_bg_hp(sd);
  3028. }
  3029. break;
  3030. }
  3031. }
  3032. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3033. /// 01ab <account id>.L <var id>.W <value>.L
  3034. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3035. {
  3036. unsigned char buf[12];
  3037. nullpo_retv(sd);
  3038. WBUFW(buf,0)=0x1ab;
  3039. WBUFL(buf,2)=sd->bl.id;
  3040. WBUFW(buf,6)=type;
  3041. switch(type)
  3042. {
  3043. case SP_MANNER:
  3044. WBUFL(buf,8)=val;
  3045. break;
  3046. default:
  3047. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3048. return;
  3049. }
  3050. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3051. }
  3052. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3053. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  3054. void clif_sprite_change(struct block_list *bl, int id, int type, int val, int val2, enum send_target target) {
  3055. unsigned char buf[32];
  3056. #if PACKETVER < 4
  3057. const int cmd = 0xc3;
  3058. #else
  3059. const int cmd = 0x1d7;
  3060. #endif
  3061. WBUFW(buf,0) = cmd;
  3062. WBUFL(buf,2) = id;
  3063. WBUFB(buf,6) = type;
  3064. WBUFW(buf,7) = val;
  3065. #if PACKETVER >= 4
  3066. WBUFW(buf,9) = val2;
  3067. #endif
  3068. clif_send(buf,packet_len(cmd), bl, target);
  3069. }
  3070. /// Updates sprite/style properties of an object.
  3071. void clif_changelook(struct block_list *bl, int type, int val) {
  3072. struct map_session_data* sd;
  3073. struct status_change* sc;
  3074. struct view_data* vd;
  3075. enum send_target target = AREA;
  3076. int val2 = 0;
  3077. nullpo_retv(bl);
  3078. sd = BL_CAST(BL_PC, bl);
  3079. sc = status_get_sc(bl);
  3080. vd = status_get_viewdata(bl);
  3081. if( vd ) //temp hack to let Warp Portal change appearance
  3082. switch(type) {
  3083. case LOOK_WEAPON:
  3084. if (sd) {
  3085. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3086. val = vd->weapon;
  3087. }
  3088. else
  3089. vd->weapon = val;
  3090. break;
  3091. case LOOK_SHIELD:
  3092. if (sd) {
  3093. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3094. val = vd->shield;
  3095. }
  3096. else
  3097. vd->shield = val;
  3098. break;
  3099. case LOOK_BASE:
  3100. if (!sd)
  3101. break;
  3102. if ( val == JT_INVISIBLE )
  3103. return;
  3104. if (sd->sc.option&OPTION_COSTUME)
  3105. vd->weapon = vd->shield = 0;
  3106. if (!vd->cloth_color)
  3107. break;
  3108. if (sd) {
  3109. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3110. vd->cloth_color = 0;
  3111. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3112. vd->cloth_color = 0;
  3113. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  3114. vd->cloth_color = 0;
  3115. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3116. vd->cloth_color = 0;
  3117. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3118. vd->cloth_color = 0;
  3119. if (vd->body_style && (
  3120. sd->sc.option&OPTION_WEDDING || sd->sc.option&OPTION_XMAS ||
  3121. sd->sc.option&OPTION_SUMMER || sd->sc.option&OPTION_HANBOK ||
  3122. sd->sc.option&OPTION_OKTOBERFEST))
  3123. vd->body_style = 0;
  3124. }
  3125. break;
  3126. case LOOK_HAIR:
  3127. vd->hair_style = val;
  3128. break;
  3129. case LOOK_HEAD_BOTTOM:
  3130. vd->head_bottom = val;
  3131. break;
  3132. case LOOK_HEAD_TOP:
  3133. vd->head_top = val;
  3134. break;
  3135. case LOOK_HEAD_MID:
  3136. vd->head_mid = val;
  3137. break;
  3138. case LOOK_HAIR_COLOR:
  3139. vd->hair_color = val;
  3140. break;
  3141. case LOOK_CLOTHES_COLOR:
  3142. if (val && sd) {
  3143. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3144. val = 0;
  3145. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3146. val = 0;
  3147. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  3148. val = 0;
  3149. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3150. val = 0;
  3151. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3152. val = 0;
  3153. }
  3154. vd->cloth_color = val;
  3155. break;
  3156. case LOOK_SHOES:
  3157. #if PACKETVER > 3
  3158. if (sd) {
  3159. int n;
  3160. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  3161. if(sd->inventory_data[n]->view_id > 0)
  3162. val = sd->inventory_data[n]->view_id;
  3163. else
  3164. val = sd->inventory.u.items_inventory[n].nameid;
  3165. } else
  3166. val = 0;
  3167. }
  3168. #endif
  3169. //Shoes? No packet uses this....
  3170. break;
  3171. case LOOK_BODY:
  3172. // unknown purpose
  3173. break;
  3174. case LOOK_ROBE:
  3175. #if PACKETVER < 20110111
  3176. return;
  3177. #else
  3178. vd->robe = val;
  3179. #endif
  3180. break;
  3181. case LOOK_BODY2:
  3182. #if PACKETVER < 20150513
  3183. return;
  3184. #else
  3185. if (val && (
  3186. sd->sc.option&OPTION_WEDDING || sd->sc.option&OPTION_XMAS ||
  3187. sd->sc.option&OPTION_SUMMER || sd->sc.option&OPTION_HANBOK ||
  3188. sd->sc.option&OPTION_OKTOBERFEST))
  3189. val = 0;
  3190. vd->body_style = val;
  3191. #endif
  3192. break;
  3193. }
  3194. // prevent leaking the presence of GM-hidden objects
  3195. if( sc && sc->option&OPTION_INVISIBLE )
  3196. target = SELF;
  3197. #if PACKETVER < 4
  3198. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3199. #else
  3200. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3201. nullpo_retv(vd);
  3202. type = LOOK_WEAPON;
  3203. val = vd->weapon;
  3204. val2 = vd->shield;
  3205. }
  3206. if( disguised(bl) ) {
  3207. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3208. clif_sprite_change(bl, -bl->id, type, val, val2, SELF);
  3209. } else
  3210. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3211. #endif
  3212. }
  3213. //Sends a change-base-look packet required for traps as they are triggered.
  3214. void clif_changetraplook(struct block_list *bl,int val) {
  3215. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3216. }
  3217. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3218. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3219. clif_sprite_change(bl, id, type, val, 0, target);
  3220. }
  3221. /// Character status (ZC_STATUS).
  3222. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3223. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3224. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3225. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3226. void clif_initialstatus(struct map_session_data *sd) {
  3227. int fd, mdef2;
  3228. unsigned char *buf;
  3229. nullpo_retv(sd);
  3230. fd=sd->fd;
  3231. WFIFOHEAD(fd, packet_len(0xbd));
  3232. buf = WFIFOP(fd,0);
  3233. WBUFW(buf,0) = 0xbd;
  3234. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3235. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3236. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3237. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3238. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3239. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3240. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3241. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3242. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3243. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3244. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3245. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3246. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3247. WBUFW(buf,16) = pc_leftside_atk(sd);
  3248. WBUFW(buf,18) = pc_rightside_atk(sd);
  3249. WBUFW(buf,20) = pc_rightside_matk(sd);
  3250. WBUFW(buf,22) = pc_leftside_matk(sd);
  3251. WBUFW(buf,24) = pc_leftside_def(sd);
  3252. WBUFW(buf,26) = pc_rightside_def(sd);
  3253. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3254. mdef2 = pc_rightside_mdef(sd);
  3255. WBUFW(buf,30) =
  3256. #ifndef RENEWAL
  3257. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3258. #endif
  3259. mdef2;
  3260. WBUFW(buf,32) = sd->battle_status.hit;
  3261. WBUFW(buf,34) = sd->battle_status.flee;
  3262. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3263. WBUFW(buf,38) = sd->battle_status.cri/10;
  3264. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3265. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3266. WFIFOSET(fd, packet_len(0xbd));
  3267. clif_updatestatus(sd, SP_STR);
  3268. clif_updatestatus(sd, SP_AGI);
  3269. clif_updatestatus(sd, SP_VIT);
  3270. clif_updatestatus(sd, SP_INT);
  3271. clif_updatestatus(sd, SP_DEX);
  3272. clif_updatestatus(sd, SP_LUK);
  3273. clif_updatestatus(sd, SP_ATTACKRANGE);
  3274. clif_updatestatus(sd, SP_ASPD);
  3275. }
  3276. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3277. /// 013c <index>.W
  3278. void clif_arrowequip(struct map_session_data *sd,int val) {
  3279. int fd;
  3280. nullpo_retv(sd);
  3281. #if PACKETVER >= 20121128
  3282. clif_status_change(&sd->bl, SI_CLIENT_ONLY_EQUIP_ARROW, 1, INVALID_TIMER, 0, 0, 0);
  3283. #endif
  3284. fd=sd->fd;
  3285. WFIFOHEAD(fd, packet_len(0x013c));
  3286. WFIFOW(fd,0) = 0x013c;
  3287. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3288. WFIFOSET(fd, packet_len(0x013c));
  3289. }
  3290. /// Ammunition action message (ZC_ACTION_FAILURE).
  3291. /// 013b <type>.W
  3292. /// type:
  3293. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3294. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3295. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3296. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3297. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3298. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3299. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3300. int fd;
  3301. nullpo_retv(sd);
  3302. fd=sd->fd;
  3303. WFIFOHEAD(fd, packet_len(0x013b));
  3304. WFIFOW(fd,0) = 0x013b;
  3305. WFIFOW(fd,2) = type;
  3306. WFIFOSET(fd, packet_len(0x013b));
  3307. }
  3308. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3309. /// 01ad <packet len>.W { <name id>.W }*
  3310. void clif_arrow_create_list(struct map_session_data *sd)
  3311. {
  3312. int i, c;
  3313. int fd;
  3314. nullpo_retv(sd);
  3315. fd = sd->fd;
  3316. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  3317. WFIFOW(fd,0) = 0x1ad;
  3318. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  3319. short j, nameid = skill_arrow_db[i].nameid;
  3320. if (nameid > 0 && itemdb_exists(nameid) &&
  3321. (j = pc_search_inventory(sd, nameid)) >= 0 &&
  3322. !sd->inventory.u.items_inventory[j].equip && sd->inventory.u.items_inventory[j].identify)
  3323. {
  3324. if ((j = itemdb_viewid(nameid)) > 0)
  3325. WFIFOW(fd,c*2+4) = j;
  3326. else
  3327. WFIFOW(fd,c*2+4) = nameid;
  3328. c++;
  3329. }
  3330. }
  3331. WFIFOW(fd,2) = c*2+4;
  3332. WFIFOSET(fd, WFIFOW(fd,2));
  3333. if (c > 0) {
  3334. sd->menuskill_id = AC_MAKINGARROW;
  3335. sd->menuskill_val = c;
  3336. }
  3337. }
  3338. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3339. /// 00bc <status id>.W <result>.B <value>.B
  3340. /// status id:
  3341. /// SP_STR ~ SP_LUK
  3342. /// result:
  3343. /// 0 = failure
  3344. /// 1 = success
  3345. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3346. int fd;
  3347. nullpo_retv(sd);
  3348. fd=sd->fd;
  3349. WFIFOHEAD(fd, packet_len(0xbc));
  3350. WFIFOW(fd,0) = 0xbc;
  3351. WFIFOW(fd,2) = type;
  3352. WFIFOB(fd,4) = ok;
  3353. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3354. WFIFOSET(fd, packet_len(0xbc));
  3355. }
  3356. /// Notifies the client about the result of a request to equip an item.
  3357. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3358. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3359. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3360. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3361. /// @ok: //inversed forv2 v5
  3362. /// 0 = failure
  3363. /// 1 = success
  3364. /// 2 = failure due to low level
  3365. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3366. {
  3367. int fd = 0, cmd = 0, look = 0;
  3368. struct s_packet_db *info = NULL;
  3369. nullpo_retv(sd);
  3370. cmd = packet_db_ack[ZC_WEAR_EQUIP_ACK];
  3371. if (!cmd || !(info = &packet_db[cmd]) || !info->len)
  3372. return;
  3373. fd = sd->fd;
  3374. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3375. look = sd->inventory_data[n]->look;
  3376. WFIFOHEAD(fd, info->len);
  3377. WFIFOW(fd, 0) = cmd;
  3378. WFIFOW(fd, info->pos[0]) = n+2;
  3379. switch (cmd) {
  3380. case 0xaa:
  3381. WFIFOW(fd, info->pos[1]) = pos;
  3382. #if PACKETVER < 20100629
  3383. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3384. #else
  3385. WFIFOL(fd, info->pos[2]) = look;
  3386. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3387. #endif
  3388. break;
  3389. case 0x8d0:
  3390. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3391. flag = 1;
  3392. case 0x999:
  3393. if (cmd == 0x999)
  3394. WFIFOL(fd, info->pos[1]) = pos;
  3395. else
  3396. WFIFOW(fd, info->pos[1]) = pos;
  3397. WFIFOL(fd, info->pos[2]) = look;
  3398. WFIFOW(fd, info->pos[3]) = flag;
  3399. break;
  3400. }
  3401. WFIFOSET(fd, info->len);
  3402. }
  3403. /// Notifies the client about the result of a request to take off an item.
  3404. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3405. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3406. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3407. /// @ok : //inversed for v2 v5
  3408. /// 0 = failure
  3409. /// 1 = success
  3410. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3411. {
  3412. int fd, header, offs = 0;
  3413. #if PACKETVER >= 20130000
  3414. header = 0x99a;
  3415. ok = ok ? 0 : 1;
  3416. #elif PACKETVER >= 20110824
  3417. header = 0x8d1;
  3418. ok = ok ? 0 : 1;
  3419. #else
  3420. header = 0xac;
  3421. #endif
  3422. nullpo_retv(sd);
  3423. fd=sd->fd;
  3424. WFIFOHEAD(fd, packet_len(header));
  3425. WFIFOW(fd,offs+0) = header;
  3426. WFIFOW(fd,offs+2) = n+2;
  3427. #if PACKETVER >= 20130000
  3428. WFIFOL(fd,offs+4) = pos;
  3429. offs += 2;
  3430. #else
  3431. WFIFOW(fd,offs+4) = pos;
  3432. #endif
  3433. WFIFOB(fd,offs+6) = ok;
  3434. WFIFOSET(fd, packet_len(header));
  3435. }
  3436. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3437. /// 019b <id>.L <effect id>.L
  3438. /// effect id:
  3439. /// 0 = base level up
  3440. /// 1 = job level up
  3441. /// 2 = refine failure
  3442. /// 3 = refine success
  3443. /// 4 = game over
  3444. /// 5 = pharmacy success
  3445. /// 6 = pharmacy failure
  3446. /// 7 = base level up (super novice)
  3447. /// 8 = job level up (super novice)
  3448. /// 9 = base level up (taekwon)
  3449. void clif_misceffect(struct block_list* bl,int type)
  3450. {
  3451. unsigned char buf[32];
  3452. nullpo_retv(bl);
  3453. WBUFW(buf,0) = 0x19b;
  3454. WBUFL(buf,2) = bl->id;
  3455. WBUFL(buf,6) = type;
  3456. clif_send(buf,packet_len(0x19b),bl,AREA);
  3457. }
  3458. /// Notifies clients in the area of a state change.
  3459. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3460. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3461. void clif_changeoption(struct block_list* bl)
  3462. {
  3463. unsigned char buf[32];
  3464. struct status_change *sc;
  3465. struct map_session_data* sd;
  3466. nullpo_retv(bl);
  3467. sc = status_get_sc(bl);
  3468. if (!sc) return; //How can an option change if there's no sc?
  3469. sd = BL_CAST(BL_PC, bl);
  3470. #if PACKETVER >= 7
  3471. WBUFW(buf,0) = 0x229;
  3472. WBUFL(buf,2) = bl->id;
  3473. WBUFW(buf,6) = sc->opt1;
  3474. WBUFW(buf,8) = sc->opt2;
  3475. WBUFL(buf,10) = sc->option;
  3476. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3477. if(disguised(bl)) {
  3478. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3479. WBUFL(buf,2) = -bl->id;
  3480. clif_send(buf,packet_len(0x229),bl,SELF);
  3481. WBUFL(buf,2) = bl->id;
  3482. WBUFL(buf,10) = OPTION_INVISIBLE;
  3483. clif_send(buf,packet_len(0x229),bl,SELF);
  3484. } else
  3485. clif_send(buf,packet_len(0x229),bl,AREA);
  3486. #else
  3487. WBUFW(buf,0) = 0x119;
  3488. WBUFL(buf,2) = bl->id;
  3489. WBUFW(buf,6) = sc->opt1;
  3490. WBUFW(buf,8) = sc->opt2;
  3491. WBUFW(buf,10) = sc->option;
  3492. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3493. if(disguised(bl)) {
  3494. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3495. WBUFL(buf,2) = -bl->id;
  3496. clif_send(buf,packet_len(0x119),bl,SELF);
  3497. WBUFL(buf,2) = bl->id;
  3498. WBUFW(buf,10) = OPTION_INVISIBLE;
  3499. clif_send(buf,packet_len(0x119),bl,SELF);
  3500. } else
  3501. clif_send(buf,packet_len(0x119),bl,AREA);
  3502. #endif
  3503. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3504. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3505. if (sc->data[SC_PROVOKE] && sc->data[SC_PROVOKE]->timer == INVALID_TIMER)
  3506. clif_status_change(bl, StatusIconChangeTable[SC_PROVOKE], 1, -1, 0, 0, 0);
  3507. }
  3508. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3509. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3510. void clif_changeoption2(struct block_list* bl)
  3511. {
  3512. unsigned char buf[20];
  3513. struct status_change *sc;
  3514. sc = status_get_sc(bl);
  3515. if (!sc) return; //How can an option change if there's no sc?
  3516. WBUFW(buf,0) = 0x28a;
  3517. WBUFL(buf,2) = bl->id;
  3518. WBUFL(buf,6) = sc->option;
  3519. WBUFL(buf,10) = clif_setlevel(bl);
  3520. WBUFL(buf,14) = sc->opt3;
  3521. if(disguised(bl)) {
  3522. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3523. WBUFL(buf,2) = -bl->id;
  3524. clif_send(buf,packet_len(0x28a),bl,SELF);
  3525. WBUFL(buf,2) = bl->id;
  3526. WBUFL(buf,6) = OPTION_INVISIBLE;
  3527. clif_send(buf,packet_len(0x28a),bl,SELF);
  3528. } else
  3529. clif_send(buf,packet_len(0x28a),bl,AREA);
  3530. }
  3531. /// Notifies the client about the result of an item use request.
  3532. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3533. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3534. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3535. {
  3536. nullpo_retv(sd);
  3537. if(!ok) {
  3538. int fd=sd->fd;
  3539. WFIFOHEAD(fd,packet_len(0xa8));
  3540. WFIFOW(fd,0)=0xa8;
  3541. WFIFOW(fd,2)=index+2;
  3542. WFIFOW(fd,4)=amount;
  3543. WFIFOB(fd,6)=ok;
  3544. WFIFOSET(fd,packet_len(0xa8));
  3545. }
  3546. else {
  3547. #if PACKETVER < 3
  3548. int fd=sd->fd;
  3549. WFIFOHEAD(fd,packet_len(0xa8));
  3550. WFIFOW(fd,0)=0xa8;
  3551. WFIFOW(fd,2)=index+2;
  3552. WFIFOW(fd,4)=amount;
  3553. WFIFOB(fd,6)=ok;
  3554. WFIFOSET(fd,packet_len(0xa8));
  3555. #else
  3556. unsigned char buf[32];
  3557. WBUFW(buf,0)=0x1c8;
  3558. WBUFW(buf,2)=index+2;
  3559. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3560. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3561. else
  3562. WBUFW(buf,4)=sd->inventory.u.items_inventory[index].nameid;
  3563. WBUFL(buf,6)=sd->bl.id;
  3564. WBUFW(buf,10)=amount;
  3565. WBUFB(buf,12)=ok;
  3566. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3567. #endif
  3568. }
  3569. }
  3570. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3571. /// 00d6 <flag>.B
  3572. /// flag:
  3573. /// 0 = Room has been successfully created (opens chat room)
  3574. /// 1 = Room limit exceeded
  3575. /// 2 = Same room already exists
  3576. void clif_createchat(struct map_session_data* sd, int flag)
  3577. {
  3578. int fd;
  3579. nullpo_retv(sd);
  3580. fd = sd->fd;
  3581. WFIFOHEAD(fd,packet_len(0xd6));
  3582. WFIFOW(fd,0) = 0xd6;
  3583. WFIFOB(fd,2) = flag;
  3584. WFIFOSET(fd,packet_len(0xd6));
  3585. }
  3586. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3587. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3588. /// type:
  3589. /// 0 = private (password protected)
  3590. /// 1 = public
  3591. /// 2 = arena (npc waiting room)
  3592. /// 3 = PK zone (non-clickable)
  3593. void clif_dispchat(struct chat_data* cd, int fd)
  3594. {
  3595. unsigned char buf[128];
  3596. uint8 type;
  3597. if( cd == NULL || cd->owner == NULL )
  3598. return;
  3599. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3600. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3601. : 1;
  3602. WBUFW(buf, 0) = 0xd7;
  3603. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3604. WBUFL(buf, 4) = cd->owner->id;
  3605. WBUFL(buf, 8) = cd->bl.id;
  3606. WBUFW(buf,12) = cd->limit;
  3607. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3608. WBUFB(buf,16) = type;
  3609. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3610. if( fd ) {
  3611. WFIFOHEAD(fd,WBUFW(buf,2));
  3612. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3613. WFIFOSET(fd,WBUFW(buf,2));
  3614. } else {
  3615. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3616. }
  3617. }
  3618. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3619. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3620. /// type:
  3621. /// 0 = private (password protected)
  3622. /// 1 = public
  3623. /// 2 = arena (npc waiting room)
  3624. /// 3 = PK zone (non-clickable)
  3625. void clif_changechatstatus(struct chat_data* cd)
  3626. {
  3627. unsigned char buf[128];
  3628. uint8 type;
  3629. if( cd == NULL || cd->usersd[0] == NULL )
  3630. return;
  3631. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3632. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3633. : 1;
  3634. WBUFW(buf, 0) = 0xdf;
  3635. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3636. WBUFL(buf, 4) = cd->owner->id;
  3637. WBUFL(buf, 8) = cd->bl.id;
  3638. WBUFW(buf,12) = cd->limit;
  3639. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3640. WBUFB(buf,16) = type;
  3641. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3642. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3643. }
  3644. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3645. /// 00d8 <chat id>.L
  3646. void clif_clearchat(struct chat_data *cd,int fd)
  3647. {
  3648. unsigned char buf[32];
  3649. nullpo_retv(cd);
  3650. WBUFW(buf,0) = 0xd8;
  3651. WBUFL(buf,2) = cd->bl.id;
  3652. if( fd ) {
  3653. WFIFOHEAD(fd,packet_len(0xd8));
  3654. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3655. WFIFOSET(fd,packet_len(0xd8));
  3656. } else {
  3657. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3658. }
  3659. }
  3660. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3661. /// 00da <result>.B
  3662. /// result:
  3663. /// 0 = room full
  3664. /// 1 = wrong password
  3665. /// 2 = kicked
  3666. /// 3 = success (no message)
  3667. /// 4 = no enough zeny
  3668. /// 5 = too low level
  3669. /// 6 = too high level
  3670. /// 7 = unsuitable job class
  3671. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3672. {
  3673. int fd;
  3674. nullpo_retv(sd);
  3675. fd = sd->fd;
  3676. WFIFOHEAD(fd,packet_len(0xda));
  3677. WFIFOW(fd,0) = 0xda;
  3678. WFIFOB(fd,2) = flag;
  3679. WFIFOSET(fd,packet_len(0xda));
  3680. }
  3681. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3682. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3683. /// role:
  3684. /// 0 = owner (menu)
  3685. /// 1 = normal
  3686. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3687. {
  3688. int fd;
  3689. int i,t;
  3690. nullpo_retv(sd);
  3691. nullpo_retv(cd);
  3692. fd = sd->fd;
  3693. if (!session_isActive(fd))
  3694. return;
  3695. t = (int)(cd->owner->type == BL_NPC);
  3696. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3697. WFIFOW(fd, 0) = 0xdb;
  3698. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3699. WFIFOL(fd, 4) = cd->bl.id;
  3700. if(cd->owner->type == BL_NPC){
  3701. WFIFOL(fd, 30) = 1;
  3702. WFIFOL(fd, 8) = 0;
  3703. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3704. for (i = 0; i < cd->users; i++) {
  3705. WFIFOL(fd, 8+(i+1)*28) = 1;
  3706. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3707. }
  3708. }else{
  3709. for (i = 0; i < cd->users; i++) {
  3710. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3711. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3712. }
  3713. }
  3714. WFIFOSET(fd, WFIFOW(fd, 2));
  3715. }
  3716. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3717. /// 00dc <users>.W <name>.24B
  3718. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3719. {
  3720. unsigned char buf[29];
  3721. nullpo_retv(sd);
  3722. nullpo_retv(cd);
  3723. WBUFW(buf, 0) = 0xdc;
  3724. WBUFW(buf, 2) = cd->users;
  3725. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3726. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3727. }
  3728. /// Announce the new owner (ZC_ROLE_CHANGE).
  3729. /// 00e1 <role>.L <nick>.24B
  3730. /// role:
  3731. /// 0 = owner (menu)
  3732. /// 1 = normal
  3733. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3734. {
  3735. unsigned char buf[64];
  3736. nullpo_retv(sd);
  3737. nullpo_retv(cd);
  3738. WBUFW(buf, 0) = 0xe1;
  3739. WBUFL(buf, 2) = 1;
  3740. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3741. WBUFW(buf,30) = 0xe1;
  3742. WBUFL(buf,32) = 0;
  3743. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3744. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3745. }
  3746. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3747. /// 00dd <users>.W <nick>.24B <flag>.B
  3748. /// flag:
  3749. /// 0 = left
  3750. /// 1 = kicked
  3751. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3752. {
  3753. unsigned char buf[32];
  3754. nullpo_retv(sd);
  3755. nullpo_retv(cd);
  3756. WBUFW(buf, 0) = 0xdd;
  3757. WBUFW(buf, 2) = cd->users-1;
  3758. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3759. WBUFB(buf,28) = flag;
  3760. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3761. }
  3762. /// Opens a trade request window from char 'name'.
  3763. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3764. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3765. void clif_traderequest(struct map_session_data* sd, const char* name)
  3766. {
  3767. int fd = sd->fd;
  3768. #if PACKETVER < 6
  3769. WFIFOHEAD(fd,packet_len(0xe5));
  3770. WFIFOW(fd,0) = 0xe5;
  3771. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3772. WFIFOSET(fd,packet_len(0xe5));
  3773. #else
  3774. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3775. if( !tsd ) return;
  3776. WFIFOHEAD(fd,packet_len(0x1f4));
  3777. WFIFOW(fd,0) = 0x1f4;
  3778. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3779. WFIFOL(fd,26) = tsd->status.char_id;
  3780. WFIFOW(fd,30) = tsd->status.base_level;
  3781. WFIFOSET(fd,packet_len(0x1f4));
  3782. #endif
  3783. }
  3784. /// Reply to a trade-request.
  3785. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3786. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3787. /// result:
  3788. /// 0 = Char is too far
  3789. /// 1 = Character does not exist
  3790. /// 2 = Trade failed
  3791. /// 3 = Accept
  3792. /// 4 = Cancel
  3793. /// 5 = Busy
  3794. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3795. {
  3796. int fd = sd->fd;
  3797. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3798. if( PACKETVER < 6 || !tsd ) {
  3799. WFIFOHEAD(fd,packet_len(0xe7));
  3800. WFIFOW(fd,0) = 0xe7;
  3801. WFIFOB(fd,2) = type;
  3802. WFIFOSET(fd,packet_len(0xe7));
  3803. } else {
  3804. WFIFOHEAD(fd,packet_len(0x1f5));
  3805. WFIFOW(fd,0) = 0x1f5;
  3806. WFIFOB(fd,2) = type;
  3807. WFIFOL(fd,3) = tsd->status.char_id;
  3808. WFIFOW(fd,7) = tsd->status.base_level;
  3809. WFIFOSET(fd,packet_len(0x1f5));
  3810. }
  3811. }
  3812. /// Notifies the client about an item from other player in current trade.
  3813. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3814. /// 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)
  3815. /// 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)
  3816. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3817. {
  3818. int fd;
  3819. unsigned char *buf;
  3820. #if PACKETVER < 20100223
  3821. const int cmd = 0xe9;
  3822. #elif PACKETVER < 20150225
  3823. const int cmd = 0x80f;
  3824. #else
  3825. const int cmd = 0xa09;
  3826. #endif
  3827. nullpo_retv(sd);
  3828. nullpo_retv(tsd);
  3829. fd = tsd->fd;
  3830. buf = WFIFOP(fd,0);
  3831. WFIFOHEAD(fd,packet_len(cmd));
  3832. WBUFW(buf,0) = cmd;
  3833. if( index == 0 )
  3834. {
  3835. #if PACKETVER < 20100223
  3836. WBUFL(buf,2) = amount; //amount
  3837. WBUFW(buf,6) = 0; // type id
  3838. #else
  3839. WBUFW(buf,2) = 0; // type id
  3840. WBUFB(buf,4) = 0; // item type
  3841. WBUFL(buf,5) = amount; // amount
  3842. buf = WBUFP(buf,1); //Advance 1B
  3843. #endif
  3844. WBUFB(buf,8) = 0; //identify flag
  3845. WBUFB(buf,9) = 0; // attribute
  3846. WBUFB(buf,10)= 0; //refine
  3847. WBUFW(buf,11)= 0; //card (4w)
  3848. WBUFW(buf,13)= 0; //card (4w)
  3849. WBUFW(buf,15)= 0; //card (4w)
  3850. WBUFW(buf,17)= 0; //card (4w)
  3851. #if PACKETVER >= 20150225
  3852. clif_add_random_options(WBUFP(buf, 19), &sd->inventory.u.items_inventory[index]);
  3853. #endif
  3854. }
  3855. else
  3856. {
  3857. index -= 2; //index fix
  3858. #if PACKETVER < 20100223
  3859. WBUFL(buf,2) = amount; //amount
  3860. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3861. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3862. else
  3863. WBUFW(buf,6) = sd->inventory.u.items_inventory[index].nameid; // type id
  3864. #else
  3865. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3866. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3867. else
  3868. WBUFW(buf,2) = sd->inventory.u.items_inventory[index].nameid; // type id
  3869. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3870. WBUFL(buf,5) = amount; // amount
  3871. buf = WBUFP(buf,1); //Advance 1B
  3872. #endif
  3873. WBUFB(buf,8) = sd->inventory.u.items_inventory[index].identify; //identify flag
  3874. WBUFB(buf,9) = sd->inventory.u.items_inventory[index].attribute; // attribute
  3875. WBUFB(buf,10)= sd->inventory.u.items_inventory[index].refine; //refine
  3876. clif_addcards(WBUFP(buf, 11), &sd->inventory.u.items_inventory[index]);
  3877. #if PACKETVER >= 20150225
  3878. clif_add_random_options(WBUFP(buf, 19), &sd->inventory.u.items_inventory[index]);
  3879. #endif
  3880. }
  3881. WFIFOSET(fd,packet_len(cmd));
  3882. }
  3883. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3884. /// 00ea <index>.W <result>.B
  3885. /// result:
  3886. /// 0 = success
  3887. /// 1 = overweight
  3888. /// 2 = trade canceled
  3889. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3890. {
  3891. int fd;
  3892. nullpo_retv(sd);
  3893. fd = sd->fd;
  3894. WFIFOHEAD(fd,packet_len(0xea));
  3895. WFIFOW(fd,0) = 0xea;
  3896. WFIFOW(fd,2) = index;
  3897. WFIFOB(fd,4) = fail;
  3898. WFIFOSET(fd,packet_len(0xea));
  3899. }
  3900. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3901. /// 00ec <who>.B
  3902. /// who:
  3903. /// 0 = self
  3904. /// 1 = other player
  3905. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3906. {
  3907. int fd;
  3908. nullpo_retv(sd);
  3909. fd = sd->fd;
  3910. WFIFOHEAD(fd,packet_len(0xec));
  3911. WFIFOW(fd,0) = 0xec;
  3912. WFIFOB(fd,2) = fail;
  3913. WFIFOSET(fd,packet_len(0xec));
  3914. }
  3915. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3916. /// 00ee
  3917. void clif_tradecancelled(struct map_session_data* sd)
  3918. {
  3919. int fd;
  3920. nullpo_retv(sd);
  3921. fd = sd->fd;
  3922. WFIFOHEAD(fd,packet_len(0xee));
  3923. WFIFOW(fd,0) = 0xee;
  3924. WFIFOSET(fd,packet_len(0xee));
  3925. }
  3926. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3927. /// 00f0 <result>.B
  3928. /// result:
  3929. /// 0 = success
  3930. /// 1 = failure
  3931. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3932. {
  3933. int fd;
  3934. nullpo_retv(sd);
  3935. fd = sd->fd;
  3936. WFIFOHEAD(fd,packet_len(0xf0));
  3937. WFIFOW(fd,0) = 0xf0;
  3938. WFIFOB(fd,2) = fail;
  3939. WFIFOSET(fd,packet_len(0xf0));
  3940. }
  3941. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3942. /// 00f1
  3943. /// NOTE: Unknown purpose. Items are not removed until the window is
  3944. /// refreshed (ex. by putting another item in there).
  3945. void clif_tradeundo(struct map_session_data* sd)
  3946. {
  3947. int fd = sd->fd;
  3948. WFIFOHEAD(fd,packet_len(0xf1));
  3949. WFIFOW(fd,0) = 0xf1;
  3950. WFIFOSET(fd,packet_len(0xf1));
  3951. }
  3952. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3953. /// 00f2 <current count>.W <max count>.W
  3954. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3955. {
  3956. int fd;
  3957. nullpo_retv(sd);
  3958. fd=sd->fd;
  3959. WFIFOHEAD(fd,packet_len(0xf2));
  3960. WFIFOW(fd,0) = 0xf2;
  3961. WFIFOW(fd,2) = amount;
  3962. WFIFOW(fd,4) = max_amount;
  3963. WFIFOSET(fd,packet_len(0xf2));
  3964. }
  3965. /// Notifies the client of an item being added to the storage.
  3966. /// 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)
  3967. /// 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)
  3968. /// 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)
  3969. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3970. {
  3971. #if PACKETVER < 5
  3972. const int cmd = 0xf4;
  3973. #elif PACKETVER < 20150225
  3974. const int cmd = 0x1c4;
  3975. #else
  3976. const int cmd = 0xa0a;
  3977. #endif
  3978. int view,fd;
  3979. int offset = 0;
  3980. nullpo_retv(sd);
  3981. nullpo_retv(i);
  3982. fd=sd->fd;
  3983. view = itemdb_viewid(i->nameid);
  3984. WFIFOHEAD(fd,packet_len(cmd));
  3985. WFIFOW(fd, 0) = cmd; // Storage item added
  3986. WFIFOW(fd, 2) = index+1; // index
  3987. WFIFOL(fd, 4) = amount; // amount
  3988. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3989. #if PACKETVER >= 5
  3990. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3991. offset += 1;
  3992. #endif
  3993. WFIFOB(fd,10+offset) = i->identify; //identify flag
  3994. WFIFOB(fd,11+offset) = i->attribute; // attribute
  3995. WFIFOB(fd,12+offset) = i->refine; //refine
  3996. clif_addcards(WFIFOP(fd,13+offset), i);
  3997. #if PACKETVER >= 20150225
  3998. clif_add_random_options(WFIFOP(fd,21+offset), i);
  3999. #endif
  4000. WFIFOSET(fd,packet_len(cmd));
  4001. }
  4002. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  4003. /// 00f6 <index>.W <amount>.L
  4004. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  4005. {
  4006. int fd;
  4007. nullpo_retv(sd);
  4008. fd=sd->fd;
  4009. WFIFOHEAD(fd,packet_len(0xf6));
  4010. WFIFOW(fd,0)=0xf6; // Storage item removed
  4011. WFIFOW(fd,2)=index+1;
  4012. WFIFOL(fd,4)=amount;
  4013. WFIFOSET(fd,packet_len(0xf6));
  4014. }
  4015. /// Closes storage (ZC_CLOSE_STORE).
  4016. /// 00f8
  4017. void clif_storageclose(struct map_session_data* sd)
  4018. {
  4019. int fd;
  4020. nullpo_retv(sd);
  4021. fd=sd->fd;
  4022. WFIFOHEAD(fd,packet_len(0xf8));
  4023. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4024. WFIFOSET(fd,packet_len(0xf8));
  4025. }
  4026. /*==========================================
  4027. * Server tells 'sd' player client the abouts of 'dstsd' player
  4028. *------------------------------------------*/
  4029. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  4030. {
  4031. struct block_list *d_bl;
  4032. int i;
  4033. if( dstsd->chatID ) {
  4034. struct chat_data *cd = NULL;
  4035. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4036. clif_dispchat(cd,sd->fd);
  4037. } else if( dstsd->state.vending )
  4038. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  4039. else if( dstsd->state.buyingstore )
  4040. clif_buyingstore_entry_single(sd, dstsd);
  4041. if(dstsd->spiritball > 0)
  4042. clif_spiritball_single(sd->fd, dstsd);
  4043. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4044. clif_spiritcharm_single(sd->fd, dstsd);
  4045. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4046. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4047. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4048. )
  4049. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  4050. // display link (sd - dstsd) to sd
  4051. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4052. if( i < MAX_DEVOTION )
  4053. clif_devotion(&sd->bl, sd);
  4054. // display links (dstsd - devotees) to sd
  4055. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4056. if( i < MAX_DEVOTION )
  4057. clif_devotion(&dstsd->bl, sd);
  4058. // display link (dstsd - crusader) to sd
  4059. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4060. clif_devotion(d_bl, sd);
  4061. }
  4062. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  4063. {
  4064. uint8 buf[128];
  4065. struct unit_data *ud;
  4066. struct view_data *vd;
  4067. int len;
  4068. vd = status_get_viewdata(bl);
  4069. if (!vd || vd->class_ == JT_INVISIBLE)
  4070. return;
  4071. /**
  4072. * Hide NPC from maya purple card.
  4073. **/
  4074. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4075. return;
  4076. ud = unit_bl2ud(bl);
  4077. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  4078. clif_send(buf,len,&sd->bl,SELF);
  4079. if (vd->cloth_color)
  4080. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4081. if (vd->body_style)
  4082. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4083. switch (bl->type)
  4084. {
  4085. case BL_PC:
  4086. {
  4087. TBL_PC* tsd = (TBL_PC*)bl;
  4088. clif_getareachar_pc(sd, tsd);
  4089. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4090. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4091. else if(tsd->state.size==SZ_MEDIUM)
  4092. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4093. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  4094. clif_sendbgemblem_single(sd->fd,tsd);
  4095. if ( tsd->status.robe )
  4096. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4097. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4098. clif_hat_effects(sd,bl,SELF);
  4099. }
  4100. break;
  4101. case BL_MER: // Devotion Effects
  4102. if( ((TBL_MER*)bl)->devotion_flag )
  4103. clif_devotion(bl, sd);
  4104. break;
  4105. case BL_NPC:
  4106. {
  4107. TBL_NPC* nd = (TBL_NPC*)bl;
  4108. if( nd->chat_id )
  4109. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4110. if( nd->size == SZ_BIG )
  4111. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4112. else if( nd->size == SZ_MEDIUM )
  4113. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4114. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4115. clif_progressbar_npc(nd, sd);
  4116. }
  4117. break;
  4118. case BL_MOB:
  4119. {
  4120. TBL_MOB* md = (TBL_MOB*)bl;
  4121. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4122. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4123. else if(md->special_state.size==SZ_MEDIUM)
  4124. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4125. #if PACKETVER >= 20120404
  4126. if (battle_config.monster_hp_bars_info && !map[bl->m].flag.hidemobhpbar) {
  4127. int i;
  4128. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4129. if( md->dmglog[i].id == sd->status.char_id )
  4130. clif_monster_hp_bar(md, sd->fd);
  4131. }
  4132. #endif
  4133. }
  4134. break;
  4135. case BL_PET:
  4136. if (vd->head_bottom)
  4137. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4138. break;
  4139. }
  4140. }
  4141. //Modifies the type of damage according to status changes [Skotlex]
  4142. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4143. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4144. {
  4145. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4146. }
  4147. /*==========================================
  4148. * Estimates walk delay based on the damage criteria. [Skotlex]
  4149. *------------------------------------------*/
  4150. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4151. {
  4152. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4153. return 0;
  4154. if (bl->type == BL_PC) {
  4155. if (battle_config.pc_walk_delay_rate != 100)
  4156. delay = delay*battle_config.pc_walk_delay_rate/100;
  4157. } else
  4158. if (battle_config.walk_delay_rate != 100)
  4159. delay = delay*battle_config.walk_delay_rate/100;
  4160. if (div_ > 1) //Multi-hit skills mean higher delays.
  4161. delay += battle_config.multihit_delay*(div_-1);
  4162. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4163. }
  4164. /*========================================== [Playtester]
  4165. * Returns hallucination damage the client displays
  4166. *------------------------------------------*/
  4167. static int clif_hallucination_damage()
  4168. {
  4169. int digit = rnd() % 5 + 1;
  4170. switch (digit)
  4171. {
  4172. case 1:
  4173. return (rnd() % 10);
  4174. case 2:
  4175. return (rnd() % 100);
  4176. case 3:
  4177. return (rnd() % 1000);
  4178. case 4:
  4179. return (rnd() % 10000);
  4180. }
  4181. return (rnd() % 32767);
  4182. }
  4183. /// Sends a 'damage' packet (src performs action on dst)
  4184. /// 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)
  4185. /// 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)
  4186. /// 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)
  4187. /// type:
  4188. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4189. /// 1 = pick up item
  4190. /// 2 = sit down
  4191. /// 3 = stand up
  4192. /// 4 = damage (endure)
  4193. /// 5 = (splash?)
  4194. /// 6 = (skill?)
  4195. /// 7 = (repeat damage?)
  4196. /// 8 = multi-hit damage
  4197. /// 9 = multi-hit damage (endure)
  4198. /// 10 = critical hit
  4199. /// 11 = lucky dodge
  4200. /// 12 = (touch skill?)
  4201. 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)
  4202. {
  4203. unsigned char buf[34];
  4204. struct status_change *sc;
  4205. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4206. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4207. #if PACKETVER < 20071113
  4208. const int cmd = 0x8a;
  4209. int offset = 0;
  4210. #elif PACKETVER < 20131223
  4211. const int cmd = 0x2e1;
  4212. int offset = 2;
  4213. #else
  4214. const int cmd = 0x8c8;
  4215. int offset = 3;
  4216. #endif
  4217. nullpo_ret(src);
  4218. nullpo_ret(dst);
  4219. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4220. sc = status_get_sc(dst);
  4221. if(sc && sc->count) {
  4222. if(sc->data[SC_HALLUCINATION]) {
  4223. if(damage) damage = clif_hallucination_damage();
  4224. if(damage2) damage2 = clif_hallucination_damage();
  4225. }
  4226. }
  4227. WBUFW(buf,0) = cmd;
  4228. WBUFL(buf,2) = src->id;
  4229. WBUFL(buf,6) = dst->id;
  4230. WBUFL(buf,10) = tick;
  4231. WBUFL(buf,14) = sdelay;
  4232. WBUFL(buf,18) = ddelay;
  4233. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4234. #if PACKETVER < 20071113
  4235. WBUFW(buf,22) = damage ? div : 0;
  4236. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4237. #else
  4238. WBUFL(buf, 22) = damage ? div : 0;
  4239. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4240. #endif
  4241. } else {
  4242. #if PACKETVER < 20071113
  4243. WBUFW(buf,22) = min(damage, INT16_MAX);
  4244. WBUFW(buf,27+offset) = damage2;
  4245. #else
  4246. WBUFL(buf,22) = damage;
  4247. WBUFL(buf,27+offset) = damage2;
  4248. #endif
  4249. }
  4250. #if PACKETVER >= 20131223
  4251. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4252. #endif
  4253. WBUFW(buf,24+offset) = div;
  4254. WBUFB(buf,26+offset) = type;
  4255. if(disguised(dst)) {
  4256. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4257. WBUFL(buf,6) = -dst->id;
  4258. clif_send(buf, packet_len(cmd), dst, SELF);
  4259. } else
  4260. clif_send(buf, packet_len(cmd), dst, AREA);
  4261. if(disguised(src)) {
  4262. WBUFL(buf,2) = -src->id;
  4263. if (disguised(dst))
  4264. WBUFL(buf,6) = dst->id;
  4265. #if PACKETVER < 20071113
  4266. if(damage > 0) WBUFW(buf,22) = -1;
  4267. if(damage2 > 0) WBUFW(buf,27) = -1;
  4268. #else
  4269. if(damage > 0) WBUFL(buf,22) = -1;
  4270. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4271. #endif
  4272. clif_send(buf,packet_len(cmd),src,SELF);
  4273. }
  4274. if(src == dst) {
  4275. unit_setdir(src, unit_getdir(src));
  4276. }
  4277. //Return adjusted can't walk delay for further processing.
  4278. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4279. }
  4280. /*==========================================
  4281. * src picks up dst
  4282. *------------------------------------------*/
  4283. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4284. {
  4285. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4286. unsigned char buf[32];
  4287. nullpo_retv(src);
  4288. nullpo_retv(dst);
  4289. WBUFW(buf, 0) = 0x8a;
  4290. WBUFL(buf, 2) = src->id;
  4291. WBUFL(buf, 6) = dst->id;
  4292. WBUFB(buf,26) = 1;
  4293. clif_send(buf, packet_len(0x8a), src, AREA);
  4294. }
  4295. /*==========================================
  4296. * inform clients in area that `bl` is sitting
  4297. *------------------------------------------*/
  4298. void clif_sitting(struct block_list* bl)
  4299. {
  4300. unsigned char buf[32];
  4301. nullpo_retv(bl);
  4302. WBUFW(buf, 0) = 0x8a;
  4303. WBUFL(buf, 2) = bl->id;
  4304. WBUFB(buf,26) = 2;
  4305. clif_send(buf, packet_len(0x8a), bl, AREA);
  4306. if(disguised(bl)) {
  4307. WBUFL(buf, 2) = - bl->id;
  4308. clif_send(buf, packet_len(0x8a), bl, SELF);
  4309. }
  4310. }
  4311. /*==========================================
  4312. * inform clients in area that `bl` is standing
  4313. *------------------------------------------*/
  4314. void clif_standing(struct block_list* bl)
  4315. {
  4316. unsigned char buf[32];
  4317. nullpo_retv(bl);
  4318. WBUFW(buf, 0) = 0x8a;
  4319. WBUFL(buf, 2) = bl->id;
  4320. WBUFB(buf,26) = 3;
  4321. clif_send(buf, packet_len(0x8a), bl, AREA);
  4322. if(disguised(bl)) {
  4323. WBUFL(buf, 2) = - bl->id;
  4324. clif_send(buf, packet_len(0x8a), bl, SELF);
  4325. }
  4326. }
  4327. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4328. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4329. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4330. {
  4331. unsigned char buf[32];
  4332. WBUFW(buf,0) = 0x192;
  4333. WBUFW(buf,2) = x;
  4334. WBUFW(buf,4) = y;
  4335. WBUFW(buf,6) = type;
  4336. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4337. if( fd )
  4338. {
  4339. WFIFOHEAD(fd,packet_len(0x192));
  4340. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4341. WFIFOSET(fd,packet_len(0x192));
  4342. }
  4343. else
  4344. {
  4345. struct block_list dummy_bl;
  4346. dummy_bl.type = BL_NUL;
  4347. dummy_bl.x = x;
  4348. dummy_bl.y = y;
  4349. dummy_bl.m = m;
  4350. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4351. }
  4352. }
  4353. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4354. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4355. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  4356. {
  4357. int view,fd;
  4358. fd=sd->fd;
  4359. WFIFOHEAD(fd,packet_len(0x9d));
  4360. WFIFOW(fd,0)=0x9d;
  4361. WFIFOL(fd,2)=fitem->bl.id;
  4362. if((view = itemdb_viewid(fitem->item.nameid)) > 0)
  4363. WFIFOW(fd,6)=view;
  4364. else
  4365. WFIFOW(fd,6)=fitem->item.nameid;
  4366. WFIFOB(fd,8)=fitem->item.identify;
  4367. WFIFOW(fd,9)=fitem->bl.x;
  4368. WFIFOW(fd,11)=fitem->bl.y;
  4369. WFIFOW(fd,13)=fitem->item.amount;
  4370. WFIFOB(fd,15)=fitem->subx;
  4371. WFIFOB(fd,16)=fitem->suby;
  4372. WFIFOSET(fd,packet_len(0x9d));
  4373. }
  4374. /// Notifes client about Graffiti
  4375. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4376. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4377. unsigned char buf[128];
  4378. nullpo_retv(bl);
  4379. nullpo_retv(unit);
  4380. WBUFW(buf, 0) = 0x1c9;
  4381. WBUFL(buf, 2) = unit->bl.id;
  4382. WBUFL(buf, 6) = unit->group->src_id;
  4383. WBUFW(buf,10) = unit->bl.x;
  4384. WBUFW(buf,12) = unit->bl.y;
  4385. WBUFB(buf,14) = unit->group->unit_id;
  4386. WBUFB(buf,15) = 1;
  4387. WBUFB(buf,16) = 1;
  4388. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4389. clif_send(buf,packet_len(0x1c9),bl,target);
  4390. }
  4391. /// Notifies the client of a skill unit.
  4392. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4393. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4394. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4395. /// 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)
  4396. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4397. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4398. unsigned char buf[128];
  4399. nullpo_retv(bl);
  4400. nullpo_retv(unit);
  4401. if (bl->type == BL_PC)
  4402. fd = ((TBL_PC*)bl)->fd;
  4403. if (unit->group->state.guildaura)
  4404. return;
  4405. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4406. unit_id = unit->val2&UF_SONG ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4407. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4408. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4409. else
  4410. unit_id = unit->group->unit_id;
  4411. if (!visible)
  4412. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4413. #if PACKETVER >= 3
  4414. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4415. clif_graffiti(bl, unit, target);
  4416. return;
  4417. }
  4418. #endif
  4419. #if PACKETVER <= 20120702
  4420. header = 0x011f;
  4421. //#if PACKETVER < 20110718
  4422. // header = 0x011f;
  4423. //#elif PACKETVER < 20121212
  4424. // header = 0x08c7;
  4425. #elif PACKETVER < 20130731
  4426. header = 0x099f;
  4427. #else
  4428. header = 0x09ca;
  4429. #endif
  4430. len = packet_len(header);
  4431. WBUFW(buf,pos) = header;
  4432. if (header != 0x011f) {
  4433. WBUFW(buf, pos+2) = len;
  4434. pos += 2;
  4435. }
  4436. WBUFL(buf,pos+2) = unit->bl.id;
  4437. WBUFL(buf,pos+6) = unit->group->src_id;
  4438. WBUFW(buf,pos+10) = unit->bl.x;
  4439. WBUFW(buf,pos+12) = unit->bl.y;
  4440. switch (header) {
  4441. case 0x011f:
  4442. WBUFB(buf,pos+14) = unit_id;
  4443. WBUFB(buf,pos+15) = visible;
  4444. break;
  4445. case 0x08c7:
  4446. WBUFB(buf,pos+14) = unit_id;
  4447. WBUFW(buf,pos+15) = unit->range;
  4448. WBUFB(buf,pos+17) = visible;
  4449. break;
  4450. case 0x099f:
  4451. WBUFL(buf,pos+14) = unit_id;
  4452. WBUFW(buf,pos+18) = unit->range;
  4453. WBUFB(buf,pos+20) = visible;
  4454. break;
  4455. case 0x09ca:
  4456. WBUFL(buf,pos+14) = unit_id;
  4457. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4458. WBUFB(buf,pos+19) = visible;
  4459. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4460. break;
  4461. }
  4462. clif_send(buf, len, bl, target);
  4463. if (unit->group->skill_id == WZ_ICEWALL)
  4464. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4465. }
  4466. /*==========================================
  4467. * Server tells client to remove unit of id 'unit->bl.id'
  4468. *------------------------------------------*/
  4469. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4470. {
  4471. nullpo_retv(unit);
  4472. WFIFOHEAD(fd,packet_len(0x120));
  4473. WFIFOW(fd, 0)=0x120;
  4474. WFIFOL(fd, 2)=unit->bl.id;
  4475. WFIFOSET(fd,packet_len(0x120));
  4476. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4477. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4478. }
  4479. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4480. /// 0120 <id>.L
  4481. void clif_skill_delunit(struct skill_unit *unit)
  4482. {
  4483. unsigned char buf[16];
  4484. nullpo_retv(unit);
  4485. WBUFW(buf, 0)=0x120;
  4486. WBUFL(buf, 2)=unit->bl.id;
  4487. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4488. }
  4489. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4490. /// 01ac <id>.L
  4491. /// Only affects units with class [139,153] client-side.
  4492. void clif_skillunit_update(struct block_list* bl)
  4493. {
  4494. unsigned char buf[6];
  4495. nullpo_retv(bl);
  4496. WBUFW(buf,0) = 0x1ac;
  4497. WBUFL(buf,2) = bl->id;
  4498. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4499. }
  4500. /*==========================================
  4501. *
  4502. *------------------------------------------*/
  4503. static int clif_getareachar(struct block_list* bl,va_list ap)
  4504. {
  4505. struct map_session_data *sd;
  4506. nullpo_ret(bl);
  4507. sd=va_arg(ap,struct map_session_data*);
  4508. if (sd == NULL || !sd->fd)
  4509. return 0;
  4510. switch(bl->type){
  4511. case BL_ITEM:
  4512. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4513. break;
  4514. case BL_SKILL:
  4515. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4516. break;
  4517. default:
  4518. if(&sd->bl == bl)
  4519. break;
  4520. clif_getareachar_unit(sd,bl);
  4521. break;
  4522. }
  4523. return 0;
  4524. }
  4525. /*==========================================
  4526. * tbl has gone out of view-size of bl
  4527. *------------------------------------------*/
  4528. int clif_outsight(struct block_list *bl,va_list ap)
  4529. {
  4530. struct block_list *tbl;
  4531. struct view_data *vd;
  4532. TBL_PC *sd, *tsd;
  4533. tbl=va_arg(ap,struct block_list*);
  4534. if(bl == tbl) return 0;
  4535. sd = BL_CAST(BL_PC, bl);
  4536. tsd = BL_CAST(BL_PC, tbl);
  4537. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4538. nullpo_ret(bl);
  4539. switch(bl->type){
  4540. case BL_PC:
  4541. if(sd->vd.class_ != JT_INVISIBLE)
  4542. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4543. if(sd->chatID){
  4544. struct chat_data *cd;
  4545. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4546. if(cd->usersd[0]==sd)
  4547. clif_dispchat(cd,tsd->fd);
  4548. }
  4549. if(sd->state.vending)
  4550. clif_closevendingboard(bl,tsd->fd);
  4551. if(sd->state.buyingstore)
  4552. clif_buyingstore_disappear_entry_single(tsd, sd);
  4553. break;
  4554. case BL_ITEM:
  4555. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4556. break;
  4557. case BL_SKILL:
  4558. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4559. break;
  4560. case BL_NPC:
  4561. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4562. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4563. break;
  4564. default:
  4565. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4566. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4567. break;
  4568. }
  4569. }
  4570. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4571. nullpo_ret(tbl);
  4572. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4573. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4574. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4575. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4576. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4577. }
  4578. return 0;
  4579. }
  4580. /*==========================================
  4581. * tbl has come into view of bl
  4582. *------------------------------------------*/
  4583. int clif_insight(struct block_list *bl,va_list ap)
  4584. {
  4585. struct block_list *tbl;
  4586. TBL_PC *sd, *tsd;
  4587. tbl=va_arg(ap,struct block_list*);
  4588. if (bl == tbl) return 0;
  4589. sd = BL_CAST(BL_PC, bl);
  4590. tsd = BL_CAST(BL_PC, tbl);
  4591. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4592. switch(bl->type){
  4593. case BL_ITEM:
  4594. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4595. break;
  4596. case BL_SKILL:
  4597. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4598. break;
  4599. default:
  4600. clif_getareachar_unit(tsd,bl);
  4601. break;
  4602. }
  4603. }
  4604. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4605. clif_getareachar_unit(sd,tbl);
  4606. }
  4607. return 0;
  4608. }
  4609. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4610. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4611. void clif_skillinfoblock(struct map_session_data *sd)
  4612. {
  4613. int fd;
  4614. int i,len,id;
  4615. nullpo_retv(sd);
  4616. fd = sd->fd;
  4617. if (!fd)
  4618. return;
  4619. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4620. WFIFOW(fd,0) = 0x10f;
  4621. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4622. {
  4623. if( (id = sd->status.skill[i].id) != 0 )
  4624. {
  4625. // workaround for bugreport:5348
  4626. if (len + 37 > 8192)
  4627. break;
  4628. WFIFOW(fd,len) = id;
  4629. WFIFOL(fd,len+2) = skill_get_inf(id);
  4630. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4631. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4632. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4633. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4634. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4635. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4636. else
  4637. WFIFOB(fd,len+36) = 0;
  4638. len += 37;
  4639. }
  4640. }
  4641. WFIFOW(fd,2)=len;
  4642. WFIFOSET(fd,len);
  4643. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4644. for ( ; i < MAX_SKILL; i++)
  4645. {
  4646. if( (id = sd->status.skill[i].id) != 0 )
  4647. {
  4648. clif_addskill(sd, id);
  4649. clif_skillinfo(sd, id, 0);
  4650. }
  4651. }
  4652. }
  4653. /**
  4654. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4655. **/
  4656. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4657. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4658. void clif_addskill(struct map_session_data *sd, int skill_id)
  4659. {
  4660. int fd;
  4661. uint16 idx = 0;
  4662. nullpo_retv(sd);
  4663. fd = sd->fd;
  4664. if (!fd || !(idx = skill_get_index(skill_id)))
  4665. return;
  4666. if( sd->status.skill[idx].id <= 0 )
  4667. return;
  4668. WFIFOHEAD(fd, packet_len(0x111));
  4669. WFIFOW(fd,0) = 0x111;
  4670. WFIFOW(fd,2) = skill_id;
  4671. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4672. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4673. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4674. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4675. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4676. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4677. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4678. else
  4679. WFIFOB(fd,38) = 0;
  4680. WFIFOSET(fd,packet_len(0x111));
  4681. }
  4682. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4683. /// 0441 <skill id>.W
  4684. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4685. {
  4686. #if PACKETVER >= 20081217
  4687. int fd;
  4688. uint16 idx = 0;
  4689. nullpo_retv(sd);
  4690. fd = sd->fd;
  4691. if (!fd || !(idx = skill_get_index(skill_id)))
  4692. return;
  4693. WFIFOHEAD(fd,packet_len(0x441));
  4694. WFIFOW(fd,0) = 0x441;
  4695. WFIFOW(fd,2) = skill_id;
  4696. WFIFOSET(fd,packet_len(0x441));
  4697. #endif
  4698. clif_skillinfoblock(sd);
  4699. }
  4700. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4701. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4702. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4703. int fd;
  4704. nullpo_retv(sd);
  4705. fd = sd->fd;
  4706. WFIFOHEAD(fd, packet_len(0x10e));
  4707. WFIFOW(fd, 0) = 0x10e;
  4708. WFIFOW(fd, 2) = skill_id;
  4709. WFIFOW(fd, 4) = lv;
  4710. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4711. WFIFOW(fd, 8) = range;
  4712. WFIFOB(fd, 10) = upgradable;
  4713. WFIFOSET(fd, packet_len(0x10e));
  4714. }
  4715. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4716. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4717. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4718. {
  4719. const int fd = sd->fd;
  4720. uint16 idx = skill_get_index(skill_id);
  4721. if (!idx)
  4722. return;
  4723. WFIFOHEAD(fd,packet_len(0x7e1));
  4724. WFIFOW(fd,0) = 0x7e1;
  4725. WFIFOW(fd,2) = skill_id;
  4726. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4727. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4728. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4729. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4730. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4731. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4732. else
  4733. WFIFOB(fd,14) = 0;
  4734. WFIFOSET(fd,packet_len(0x7e1));
  4735. }
  4736. /// Notifies clients in area, that an object is about to use a skill.
  4737. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4738. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4739. /// property:
  4740. /// 0 = Yellow cast aura
  4741. /// 1 = Water elemental cast aura
  4742. /// 2 = Earth elemental cast aura
  4743. /// 3 = Fire elemental cast aura
  4744. /// 4 = Wind elemental cast aura
  4745. /// 5 = Poison elemental cast aura
  4746. /// 6 = Holy elemental cast aura
  4747. /// ? = like 0
  4748. /// is disposable:
  4749. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4750. /// 1 = no text
  4751. 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)
  4752. {
  4753. #if PACKETVER < 20091124
  4754. const int cmd = 0x13e;
  4755. #else
  4756. const int cmd = 0x7fb;
  4757. #endif
  4758. unsigned char buf[32];
  4759. WBUFW(buf,0) = cmd;
  4760. WBUFL(buf,2) = src_id;
  4761. WBUFL(buf,6) = dst_id;
  4762. WBUFW(buf,10) = dst_x;
  4763. WBUFW(buf,12) = dst_y;
  4764. WBUFW(buf,14) = skill_id;
  4765. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4766. WBUFL(buf,20) = casttime;
  4767. #if PACKETVER >= 20091124
  4768. WBUFB(buf,24) = 0; // isDisposable
  4769. #endif
  4770. if (disguised(bl)) {
  4771. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4772. WBUFL(buf,2) = -src_id;
  4773. clif_send(buf,packet_len(cmd), bl, SELF);
  4774. } else
  4775. clif_send(buf,packet_len(cmd), bl, AREA);
  4776. }
  4777. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4778. /// 01b9 <id>.L
  4779. void clif_skillcastcancel(struct block_list* bl)
  4780. {
  4781. unsigned char buf[16];
  4782. nullpo_retv(bl);
  4783. WBUFW(buf,0) = 0x1b9;
  4784. WBUFL(buf,2) = bl->id;
  4785. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4786. }
  4787. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4788. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4789. /// num (only used when skill id = NV_BASIC and cause = 0):
  4790. /// 0 = "skill failed" MsgStringTable[159]
  4791. /// 1 = "no emotions" MsgStringTable[160]
  4792. /// 2 = "no sit" MsgStringTable[161]
  4793. /// 3 = "no chat" MsgStringTable[162]
  4794. /// 4 = "no party" MsgStringTable[163]
  4795. /// 5 = "no shout" MsgStringTable[164]
  4796. /// 6 = "no PKing" MsgStringTable[165]
  4797. /// 7 = "no alligning" MsgStringTable[383]
  4798. /// ? = ignored
  4799. /// cause:
  4800. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4801. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4802. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4803. /// "skill failed" MsgStringTable[204] (otherwise)
  4804. /// ... = @see enum useskill_fail_cause
  4805. /// ? = ignored
  4806. ///
  4807. /// if(result!=0) doesn't display any of the previous messages
  4808. /// Note: when this packet is received an unknown flag is always set to 0,
  4809. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4810. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4811. {
  4812. int fd;
  4813. if (!sd) { //Since this is the most common nullpo....
  4814. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4815. return;
  4816. }
  4817. fd=sd->fd;
  4818. if (!fd) return;
  4819. if(battle_config.display_skill_fail&1)
  4820. return; //Disable all skill failed messages
  4821. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4822. return; //Disable delay failed messages
  4823. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4824. return;
  4825. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4826. return;
  4827. WFIFOHEAD(fd,packet_len(0x110));
  4828. WFIFOW(fd,0) = 0x110;
  4829. WFIFOW(fd,2) = skill_id;
  4830. WFIFOL(fd,4) = btype;
  4831. WFIFOB(fd,8) = 0;// success
  4832. WFIFOB(fd,9) = cause;
  4833. WFIFOSET(fd,packet_len(0x110));
  4834. }
  4835. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4836. /// 043d <skill ID>.W <tick>.L
  4837. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4838. {
  4839. #if PACKETVER>=20081112
  4840. int fd;
  4841. nullpo_retv(sd);
  4842. fd=sd->fd;
  4843. WFIFOHEAD(fd,packet_len(0x43d));
  4844. WFIFOW(fd,0) = 0x43d;
  4845. WFIFOW(fd,2) = skill_id;
  4846. WFIFOL(fd,4) = tick;
  4847. WFIFOSET(fd,packet_len(0x43d));
  4848. #endif
  4849. }
  4850. /// Skill attack effect and damage.
  4851. /// 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)
  4852. /// 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)
  4853. 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)
  4854. {
  4855. unsigned char buf[64];
  4856. struct status_change *sc;
  4857. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4858. nullpo_ret(src);
  4859. nullpo_ret(dst);
  4860. type = clif_calc_delay(type,div,damage,ddelay);
  4861. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4862. if(sc->data[SC_HALLUCINATION] && damage)
  4863. damage = clif_hallucination_damage();
  4864. }
  4865. #if PACKETVER < 3
  4866. WBUFW(buf,0)=0x114;
  4867. WBUFW(buf,2)=skill_id;
  4868. WBUFL(buf,4)=src->id;
  4869. WBUFL(buf,8)=dst->id;
  4870. WBUFL(buf,12)=tick;
  4871. WBUFL(buf,16)=sdelay;
  4872. WBUFL(buf,20)=ddelay;
  4873. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4874. WBUFW(buf,24)=damage?div:0;
  4875. } else {
  4876. WBUFW(buf,24)=damage;
  4877. }
  4878. WBUFW(buf,26)=skill_lv;
  4879. WBUFW(buf,28)=div;
  4880. WBUFB(buf,30)=type;
  4881. if (disguised(dst)) {
  4882. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4883. WBUFL(buf,8)=-dst->id;
  4884. clif_send(buf,packet_len(0x114),dst,SELF);
  4885. } else
  4886. clif_send(buf,packet_len(0x114),dst,AREA);
  4887. if(disguised(src)) {
  4888. WBUFL(buf,4)=-src->id;
  4889. if (disguised(dst))
  4890. WBUFL(buf,8)=dst->id;
  4891. if(damage > 0)
  4892. WBUFW(buf,24)=-1;
  4893. clif_send(buf,packet_len(0x114),src,SELF);
  4894. }
  4895. #else
  4896. WBUFW(buf,0)=0x1de;
  4897. WBUFW(buf,2)=skill_id;
  4898. WBUFL(buf,4)=src->id;
  4899. WBUFL(buf,8)=dst->id;
  4900. WBUFL(buf,12)=tick;
  4901. WBUFL(buf,16)=sdelay;
  4902. WBUFL(buf,20)=ddelay;
  4903. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4904. WBUFL(buf,24)=damage?div:0;
  4905. } else {
  4906. WBUFL(buf,24)=damage;
  4907. }
  4908. WBUFW(buf,28)=skill_lv;
  4909. WBUFW(buf,30)=div;
  4910. // For some reason, late 2013 and newer clients have
  4911. // a issue that causes players and monsters to endure
  4912. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4913. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4914. #if PACKETVER < 20131223
  4915. WBUFB(buf,32)=type;
  4916. #else
  4917. WBUFB(buf,32)=( type == DMG_SKILL ) ? DMG_MULTI_HIT : type;
  4918. #endif
  4919. if (disguised(dst)) {
  4920. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4921. WBUFL(buf,8)=-dst->id;
  4922. clif_send(buf,packet_len(0x1de),dst,SELF);
  4923. } else
  4924. clif_send(buf,packet_len(0x1de),dst,AREA);
  4925. if(disguised(src)) {
  4926. WBUFL(buf,4)=-src->id;
  4927. if (disguised(dst))
  4928. WBUFL(buf,8)=dst->id;
  4929. if(damage > 0)
  4930. WBUFL(buf,24)=-1;
  4931. clif_send(buf,packet_len(0x1de),src,SELF);
  4932. }
  4933. #endif
  4934. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4935. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4936. }
  4937. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4938. /// 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
  4939. /*
  4940. 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)
  4941. {
  4942. unsigned char buf[64];
  4943. struct status_change *sc;
  4944. nullpo_ret(src);
  4945. nullpo_ret(dst);
  4946. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  4947. type = clif_calc_delay(type,div,damage,ddelay);
  4948. sc = status_get_sc(dst);
  4949. if(sc && sc->count) {
  4950. if(sc->data[SC_HALLUCINATION] && damage)
  4951. damage = clif_hallucination_damage();
  4952. }
  4953. WBUFW(buf,0)=0x115;
  4954. WBUFW(buf,2)=skill_id;
  4955. WBUFL(buf,4)=src->id;
  4956. WBUFL(buf,8)=dst->id;
  4957. WBUFL(buf,12)=tick;
  4958. WBUFL(buf,16)=sdelay;
  4959. WBUFL(buf,20)=ddelay;
  4960. WBUFW(buf,24)=dst->x;
  4961. WBUFW(buf,26)=dst->y;
  4962. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4963. WBUFW(buf,28)=damage?div:0;
  4964. } else {
  4965. WBUFW(buf,28)=damage;
  4966. }
  4967. WBUFW(buf,30)=skill_lv;
  4968. WBUFW(buf,32)=div;
  4969. WBUFB(buf,34)=type;
  4970. clif_send(buf,packet_len(0x115),src,AREA);
  4971. if(disguised(src)) {
  4972. WBUFL(buf,4)=-src->id;
  4973. if(damage > 0)
  4974. WBUFW(buf,28)=-1;
  4975. clif_send(buf,packet_len(0x115),src,SELF);
  4976. }
  4977. if (disguised(dst)) {
  4978. WBUFL(buf,8)=-dst->id;
  4979. if (disguised(src))
  4980. WBUFL(buf,4)=src->id;
  4981. else if(damage > 0)
  4982. WBUFW(buf,28)=-1;
  4983. clif_send(buf,packet_len(0x115),dst,SELF);
  4984. }
  4985. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4986. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4987. }
  4988. */
  4989. /// Non-damaging skill effect
  4990. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  4991. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  4992. int clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, int fail)
  4993. {
  4994. unsigned char buf[17];
  4995. #if PACKETVER < 20130731
  4996. const int cmd = 0x11a;
  4997. #else
  4998. const int cmd = 0x9cb;
  4999. #endif
  5000. int offset = 0;
  5001. nullpo_ret(dst);
  5002. WBUFW(buf,0) = cmd;
  5003. WBUFW(buf,2) = skill_id;
  5004. #if PACKETVER < 20130731
  5005. WBUFW(buf,4) = min(heal, INT16_MAX);
  5006. #else
  5007. WBUFL(buf,4) = min(heal, INT32_MAX);
  5008. offset += 2;
  5009. #endif
  5010. WBUFL(buf,6+offset) = dst->id;
  5011. WBUFL(buf,10+offset) = src ? src->id : 0;
  5012. WBUFB(buf,14+offset) = fail;
  5013. if (disguised(dst)) {
  5014. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5015. WBUFL(buf,6+offset) = -dst->id;
  5016. clif_send(buf, packet_len(cmd), dst, SELF);
  5017. } else
  5018. clif_send(buf, packet_len(cmd), dst, AREA);
  5019. if(src && disguised(src)) {
  5020. WBUFL(buf,10+offset) = -src->id;
  5021. if (disguised(dst))
  5022. WBUFL(buf,6+offset) = dst->id;
  5023. clif_send(buf, packet_len(cmd), src, SELF);
  5024. }
  5025. return fail;
  5026. }
  5027. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5028. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5029. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  5030. {
  5031. unsigned char buf[32];
  5032. nullpo_retv(src);
  5033. WBUFW(buf,0)=0x117;
  5034. WBUFW(buf,2)=skill_id;
  5035. WBUFL(buf,4)=src->id;
  5036. WBUFW(buf,8)=val;
  5037. WBUFW(buf,10)=x;
  5038. WBUFW(buf,12)=y;
  5039. WBUFL(buf,14)=tick;
  5040. if(disguised(src)) {
  5041. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5042. WBUFL(buf,4)=-src->id;
  5043. clif_send(buf,packet_len(0x117),src,SELF);
  5044. } else
  5045. clif_send(buf,packet_len(0x117),src,AREA);
  5046. }
  5047. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5048. /// 011c <skill id>.W { <map name>.16B }*4
  5049. 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)
  5050. {
  5051. int fd;
  5052. nullpo_retv(sd);
  5053. fd = sd->fd;
  5054. WFIFOHEAD(fd,packet_len(0x11c));
  5055. WFIFOW(fd,0) = 0x11c;
  5056. WFIFOW(fd,2) = skill_id;
  5057. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5058. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5059. else // normal map name
  5060. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5061. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5062. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5063. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5064. WFIFOSET(fd,packet_len(0x11c));
  5065. sd->menuskill_id = skill_id;
  5066. if (skill_id == AL_WARP) {
  5067. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5068. sd->state.workinprogress = WIP_DISABLE_ALL;
  5069. } else
  5070. sd->menuskill_val = skill_lv;
  5071. }
  5072. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5073. /// 011e <type>.B
  5074. /// type:
  5075. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5076. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5077. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5078. ///
  5079. /// @param sd Who receives the message
  5080. /// @param type What message
  5081. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5082. {
  5083. int fd;
  5084. nullpo_retv(sd);
  5085. fd=sd->fd;
  5086. WFIFOHEAD(fd,packet_len(0x11e));
  5087. WFIFOW(fd,0)=0x11e;
  5088. WFIFOB(fd,2)=type;
  5089. WFIFOSET(fd,packet_len(0x11e));
  5090. }
  5091. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5092. /// 0189 <type>.W
  5093. /// type:
  5094. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5095. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5096. ///
  5097. /// @param sd Who receives the message
  5098. /// @param type What message
  5099. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5100. {
  5101. int fd;
  5102. nullpo_retv(sd);
  5103. fd=sd->fd;
  5104. WFIFOHEAD(fd,packet_len(0x189));
  5105. WFIFOW(fd,0)=0x189;
  5106. WFIFOW(fd,2)=type;
  5107. WFIFOSET(fd,packet_len(0x189));
  5108. }
  5109. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5110. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5111. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5112. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5113. {
  5114. struct status_data *status;
  5115. unsigned char buf[64];
  5116. int i;//, fix;
  5117. nullpo_retv(sd);
  5118. nullpo_retv(dst);
  5119. if( dst->type != BL_MOB )
  5120. return;
  5121. status = status_get_status_data(dst);
  5122. WBUFW(buf, 0)=0x18c;
  5123. WBUFW(buf, 2)=status_get_class(dst);
  5124. WBUFW(buf, 4)=status_get_lv(dst);
  5125. WBUFW(buf, 6)=status->size;
  5126. WBUFL(buf, 8)=status->hp;
  5127. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5128. +(battle_config.estimation_type&2?status->def2:0);
  5129. WBUFW(buf,14)=status->race;
  5130. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5131. +(battle_config.estimation_type&2?status->mdef2:0);
  5132. WBUFW(buf,18)= status->def_ele;
  5133. for(i=0;i<9;i++)
  5134. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  5135. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5136. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  5137. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5138. }
  5139. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5140. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5141. /// material id:
  5142. /// unused by the client
  5143. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  5144. {
  5145. int i,c,view,fd;
  5146. nullpo_retv(sd);
  5147. if (sd->menuskill_id == skill_id)
  5148. return; //Avoid resending the menu twice or more times...
  5149. if (skill_id == GC_CREATENEWPOISON)
  5150. skill_id = GC_RESEARCHNEWPOISON;
  5151. fd = sd->fd;
  5152. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  5153. WFIFOW(fd, 0) = 0x18d;
  5154. for (i = 0, c = 0; i < MAX_SKILL_PRODUCE_DB; i++){
  5155. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5156. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  5157. )
  5158. {
  5159. if ((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  5160. WFIFOW(fd,c*8+ 4) = view;
  5161. else
  5162. WFIFOW(fd,c*8+ 4) = skill_produce_db[i].nameid;
  5163. WFIFOW(fd,c*8+ 6) = 0;
  5164. WFIFOW(fd,c*8+ 8) = 0;
  5165. WFIFOW(fd,c*8+10) = 0;
  5166. c++;
  5167. }
  5168. }
  5169. WFIFOW(fd, 2) = c*8+8;
  5170. WFIFOSET(fd,WFIFOW(fd,2));
  5171. if (c > 0) {
  5172. sd->menuskill_id = skill_id;
  5173. sd->menuskill_val = trigger;
  5174. return;
  5175. }
  5176. }
  5177. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5178. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5179. /// mk type:
  5180. /// 1 = cooking
  5181. /// 2 = arrow
  5182. /// 3 = elemental
  5183. /// 4 = GN_MIX_COOKING
  5184. /// 5 = GN_MAKEBOMB
  5185. /// 6 = GN_S_PHARMACY
  5186. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  5187. {
  5188. int fd;
  5189. int i, c;
  5190. int view;
  5191. nullpo_retv(sd);
  5192. fd = sd->fd;
  5193. if(sd->menuskill_id == skill_id)
  5194. return; //Avoid resending the menu twice or more times...
  5195. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  5196. WFIFOW(fd,0) = 0x25a;
  5197. WFIFOW(fd,4) = list_type; // list type
  5198. c = 0;
  5199. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  5200. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  5201. continue;
  5202. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  5203. WFIFOW(fd, 6 + 2 * c) = view;
  5204. else
  5205. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  5206. c++;
  5207. }
  5208. if( c > 0 || skill_id == AM_PHARMACY) {
  5209. sd->menuskill_id = skill_id;
  5210. sd->menuskill_val = trigger;
  5211. sd->menuskill_val2 = qty; // amount.
  5212. WFIFOW(fd,2) = 6 + 2 * c;
  5213. WFIFOSET(fd,WFIFOW(fd,2));
  5214. } else {
  5215. clif_menuskill_clear(sd);
  5216. #if PACKETVER >= 20090922
  5217. clif_msg_skill(sd,skill_id,INVENTORY_SPACE_FULL);
  5218. #else
  5219. WFIFOW(fd,2) = 6 + 2 * c;
  5220. WFIFOSET(fd,WFIFOW(fd,2));
  5221. #endif
  5222. }
  5223. }
  5224. /// Notifies clients of a status change.
  5225. /// 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)]
  5226. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5227. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5228. /// @param bl Sends packet to clients around this object
  5229. /// @param id ID of object that has this effect
  5230. /// @param type Status icon see enum si_type
  5231. /// @param flag 1:Active, 0:Deactive
  5232. /// @param tick Duration in ms
  5233. /// @param val1
  5234. /// @param val2
  5235. /// @param val3
  5236. 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)
  5237. {
  5238. unsigned char buf[32];
  5239. if (type == SI_BLANK) //It shows nothing on the client...
  5240. return;
  5241. if (type == SI_ACTIONDELAY && tick == 0)
  5242. return;
  5243. nullpo_retv(bl);
  5244. #if PACKETVER >= 20120618
  5245. if (flag && battle_config.display_status_timers)
  5246. WBUFW(buf,0) = 0x983;
  5247. else
  5248. #elif PACKETVER >= 20090121
  5249. if (flag && battle_config.display_status_timers)
  5250. WBUFW(buf,0) = 0x43f;
  5251. else
  5252. #endif
  5253. WBUFW(buf,0) = 0x196;
  5254. WBUFW(buf,2) = type;
  5255. WBUFL(buf,4) = id;
  5256. WBUFB(buf,8) = flag;
  5257. #if PACKETVER >= 20120618
  5258. if (flag && battle_config.display_status_timers) {
  5259. if (tick <= 0)
  5260. tick = 9999; // this is indeed what official servers do
  5261. WBUFL(buf,9) = tick;/* at this stage remain and total are the same value I believe */
  5262. WBUFL(buf,13) = tick;
  5263. WBUFL(buf,17) = val1;
  5264. WBUFL(buf,21) = val2;
  5265. WBUFL(buf,25) = val3;
  5266. }
  5267. #elif PACKETVER >= 20090121
  5268. if (flag && battle_config.display_status_timers) {
  5269. if (tick <= 0)
  5270. tick = 9999; // this is indeed what official servers do
  5271. WBUFL(buf,9) = tick;
  5272. WBUFL(buf,13) = val1;
  5273. WBUFL(buf,17) = val2;
  5274. WBUFL(buf,21) = val3;
  5275. }
  5276. #endif
  5277. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5278. }
  5279. /* Sends status effect to clients around the bl
  5280. * @param bl Object that has the effect
  5281. * @param type Status icon see enum si_type
  5282. * @param flag 1:Active, 0:Deactive
  5283. * @param tick Duration in ms
  5284. * @param val1
  5285. * @param val2
  5286. * @param val3
  5287. */
  5288. void clif_status_change(struct block_list *bl, int type, int flag, int tick, int val1, int val2, int val3) {
  5289. struct map_session_data *sd = NULL;
  5290. if (type == SI_BLANK) //It shows nothing on the client...
  5291. return;
  5292. if (type == SI_ACTIONDELAY && tick == 0)
  5293. return;
  5294. if (type == SI_HALLUCINATION && !battle_config.display_hallucination) // Disable Hallucination.
  5295. return;
  5296. nullpo_retv(bl);
  5297. sd = BL_CAST(BL_PC, bl);
  5298. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  5299. return;
  5300. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5301. }
  5302. /**
  5303. * Send any active EFST to those around.
  5304. * @param tbl: Unit to send the packet to
  5305. * @param bl: Objects walking into view
  5306. * @param target: Client send type
  5307. */
  5308. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5309. unsigned char i;
  5310. struct sc_display_entry **sc_display;
  5311. unsigned char sc_display_count;
  5312. nullpo_retv(bl);
  5313. switch( bl->type ){
  5314. case BL_PC: {
  5315. struct map_session_data* sd = (struct map_session_data*)bl;
  5316. sc_display = sd->sc_display;
  5317. sc_display_count = sd->sc_display_count;
  5318. }
  5319. break;
  5320. case BL_NPC: {
  5321. struct npc_data* nd = (struct npc_data*)bl;
  5322. sc_display = nd->sc_display;
  5323. sc_display_count = nd->sc_display_count;
  5324. }
  5325. break;
  5326. default:
  5327. return;
  5328. }
  5329. for (i = 0; i < sc_display_count; i++) {
  5330. enum sc_type type = sc_display[i]->type;
  5331. struct status_change *sc = status_get_sc(bl);
  5332. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5333. int tick = 0;
  5334. if (td)
  5335. tick = DIFF_TICK(td->tick, gettick());
  5336. #if PACKETVER > 20120418
  5337. clif_efst_status_change(tbl, bl->id, target, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5338. #else
  5339. clif_status_change_sub(tbl, bl->id, StatusIconChangeTable[type], 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, target);
  5340. #endif
  5341. }
  5342. }
  5343. /// Notifies the client when a player enters the screen with an active EFST.
  5344. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5345. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5346. 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) {
  5347. #if PACKETVER >= 20111108
  5348. unsigned char buf[32];
  5349. #if PACKETVER >= 20120618
  5350. const int cmd = 0x984;
  5351. #elif PACKETVER >= 20111108
  5352. const int cmd = 0x8ff;
  5353. #endif
  5354. int offset = 0;
  5355. if (type == SI_BLANK)
  5356. return;
  5357. nullpo_retv(bl);
  5358. if (tick <= 0)
  5359. tick = 9999;
  5360. WBUFW(buf,offset + 0) = cmd;
  5361. WBUFL(buf,offset + 2) = tid;
  5362. WBUFW(buf,offset + 6) = type;
  5363. #if PACKETVER >= 20111108
  5364. WBUFL(buf,offset + 8) = tick; // Set remaining status duration [exneval]
  5365. #if PACKETVER >= 20120618
  5366. WBUFL(buf,offset + 12) = tick;
  5367. offset += 4;
  5368. #endif
  5369. WBUFL(buf,offset + 12) = val1;
  5370. WBUFL(buf,offset + 16) = val2;
  5371. WBUFL(buf,offset + 20) = val3;
  5372. #endif
  5373. clif_send(buf,packet_len(cmd),bl,target);
  5374. #endif
  5375. }
  5376. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5377. /// 008e <packet len>.W <message>.?B
  5378. void clif_displaymessage(const int fd, const char* mes)
  5379. {
  5380. nullpo_retv(mes);
  5381. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  5382. if (fd == 0)
  5383. ;
  5384. else {
  5385. char *message, *line;
  5386. message = aStrdup(mes);
  5387. line = strtok(message, "\n");
  5388. #if PACKETVER == 20141022
  5389. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5390. /** so we redirect to ZC_NPC_CHAT **/
  5391. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5392. while(line != NULL) {
  5393. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5394. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5395. if (len > 0) {
  5396. WFIFOHEAD(fd, 13 + len);
  5397. WFIFOW(fd, 0) = 0x2C1;
  5398. WFIFOW(fd, 2) = 13 + len;
  5399. WFIFOL(fd, 4) = 0;
  5400. WFIFOL(fd, 8) = color;
  5401. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5402. WFIFOSET(fd, WFIFOW(fd, 2));
  5403. }
  5404. #else
  5405. while(line != NULL) {
  5406. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5407. int len = strnlen(line, CHAT_SIZE_MAX);
  5408. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5409. WFIFOHEAD(fd, 5 + len);
  5410. WFIFOW(fd,0) = 0x8e;
  5411. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5412. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5413. WFIFOSET(fd, 5 + len);
  5414. }
  5415. #endif
  5416. line = strtok(NULL, "\n");
  5417. }
  5418. aFree(message);
  5419. }
  5420. }
  5421. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5422. /// 009a <packet len>.W <message>.?B
  5423. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5424. {
  5425. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  5426. unsigned char *buf = (unsigned char*)aMalloc((4 + lp + len)*sizeof(unsigned char));
  5427. WBUFW(buf,0) = 0x9a;
  5428. WBUFW(buf,2) = 4 + lp + len;
  5429. if (type&BC_BLUE)
  5430. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5431. else if (type&BC_WOE)
  5432. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5433. memcpy(WBUFP(buf, 4 + lp), mes, len);
  5434. clif_send(buf, WBUFW(buf,2), bl, target);
  5435. if (buf)
  5436. aFree(buf);
  5437. }
  5438. /*==========================================
  5439. * Displays a message on a 'bl' to all it's nearby clients
  5440. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5441. *------------------------------------------*/
  5442. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5443. char buf[8+CHAT_SIZE_MAX];
  5444. int len;
  5445. nullpo_retv(bl);
  5446. if(!message)
  5447. return;
  5448. len = strlen(message)+1;
  5449. if( len > sizeof(buf)-8 ) {
  5450. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  5451. len = sizeof(buf)-8;
  5452. }
  5453. WBUFW(buf,0)=0x8d;
  5454. WBUFW(buf,2)=len+8;
  5455. WBUFL(buf,4)=bl->id;
  5456. safestrncpy(WBUFCP(buf,8),message,len);
  5457. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,target);
  5458. }
  5459. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  5460. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  5461. 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)
  5462. {
  5463. unsigned char *buf = (unsigned char*)aMalloc((16 + len)*sizeof(unsigned char));
  5464. WBUFW(buf,0) = 0x1c3;
  5465. WBUFW(buf,2) = len + 16;
  5466. WBUFL(buf,4) = fontColor;
  5467. WBUFW(buf,8) = fontType;
  5468. WBUFW(buf,10) = fontSize;
  5469. WBUFW(buf,12) = fontAlign;
  5470. WBUFW(buf,14) = fontY;
  5471. memcpy(WBUFP(buf,16), mes, len);
  5472. clif_send(buf, WBUFW(buf,2), bl, target);
  5473. if (buf)
  5474. aFree(buf);
  5475. }
  5476. /*
  5477. * Display *msg to all *users in channel
  5478. */
  5479. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5480. DBIterator *iter;
  5481. struct map_session_data *user;
  5482. unsigned short msg_len = 0, len = 0;
  5483. unsigned char buf[CHAT_SIZE_MAX];
  5484. if (!channel || !msg)
  5485. return;
  5486. msg_len = (unsigned short)(strlen(msg) + 1);
  5487. if( msg_len > sizeof(buf)-12 ) {
  5488. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5489. msg_len = sizeof(buf)-12;
  5490. }
  5491. WBUFW(buf,0) = 0x2C1;
  5492. WBUFW(buf,2) = (len = msg_len + 12);
  5493. WBUFL(buf,4) = 0;
  5494. WBUFL(buf,8) = color;
  5495. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5496. iter = db_iterator(channel->users);
  5497. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5498. clif_send(buf, len, &user->bl, SELF);
  5499. }
  5500. dbi_destroy(iter);
  5501. }
  5502. /// Displays heal effect.
  5503. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5504. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5505. /// var id:
  5506. /// 5 = HP (SP_HP)
  5507. /// 7 = SP (SP_SP)
  5508. /// ? = ignored
  5509. void clif_heal(int fd,int type,int val) {
  5510. #if PACKETVER < 20141022
  5511. const int cmd = 0x13d;
  5512. #else
  5513. const int cmd = 0xa27;
  5514. #endif
  5515. WFIFOHEAD(fd, packet_len(cmd));
  5516. WFIFOW(fd,0) = cmd;
  5517. WFIFOW(fd,2) = type;
  5518. #if PACKETVER < 20141022
  5519. WFIFOW(fd,4) = min(val, INT16_MAX);
  5520. #else
  5521. WFIFOL(fd,4) = min(val, INT32_MAX);
  5522. #endif
  5523. WFIFOSET(fd, packet_len(cmd));
  5524. }
  5525. /// Displays resurrection effect (ZC_RESURRECTION).
  5526. /// 0148 <id>.L <type>.W
  5527. /// type:
  5528. /// ignored
  5529. void clif_resurrection(struct block_list *bl,int type)
  5530. {
  5531. unsigned char buf[16];
  5532. nullpo_retv(bl);
  5533. WBUFW(buf,0)=0x148;
  5534. WBUFL(buf,2)=bl->id;
  5535. WBUFW(buf,6)=0;
  5536. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5537. if (disguised(bl))
  5538. clif_spawn(bl);
  5539. }
  5540. /// Sets the map property
  5541. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5542. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5543. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5544. {
  5545. #if PACKETVER >= 20121010
  5546. short cmd = 0x99b;
  5547. unsigned char buf[8];
  5548. #else
  5549. short cmd = 0x199;
  5550. unsigned char buf[4];
  5551. #endif
  5552. WBUFW(buf,0)=cmd;
  5553. WBUFW(buf,2)=property;
  5554. #if PACKETVER >= 20121010
  5555. WBUFL(buf,4) = ((map[bl->m].flag.pvp?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5556. ((map[bl->m].flag.battleground || map_flag_gvg2(bl->m)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5557. ((map[bl->m].flag.battleground || map_flag_gvg2(bl->m)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5558. ((map[bl->m].flag.nomineeffect || !map_flag_gvg2(bl->m)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5559. ((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
  5560. ((map[bl->m].flag.pvp?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5561. ((map[bl->m].flag.partylock?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5562. ((map[bl->m].flag.battleground?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5563. ((map[bl->m].flag.nocostume?1:0)<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5564. ((map[bl->m].flag.nousecart?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5565. ((map[bl->m].flag.nosumstarmiracle?0:1)<<10); // SUNMOONSTAR_MIRACLE - Unknown - (Guessing it blocks Star Gladiator's Miracle from activating)
  5566. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5567. #endif
  5568. clif_send(buf,packet_len(cmd),bl,t);
  5569. }
  5570. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5571. /// 01d6 <type>.W
  5572. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5573. {
  5574. int fd;
  5575. nullpo_retv(sd);
  5576. fd=sd->fd;
  5577. WFIFOHEAD(fd,packet_len(0x1D6));
  5578. WFIFOW(fd,0)=0x1D6;
  5579. WFIFOW(fd,2)=type;
  5580. WFIFOSET(fd,packet_len(0x1D6));
  5581. }
  5582. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5583. /// 019a <id>.L <ranking>.L <total>.L
  5584. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5585. {
  5586. if(type == 2) {
  5587. int fd = sd->fd;
  5588. WFIFOHEAD(fd,packet_len(0x19a));
  5589. WFIFOW(fd,0) = 0x19a;
  5590. WFIFOL(fd,2) = sd->bl.id;
  5591. WFIFOL(fd,6) = pvprank;
  5592. WFIFOL(fd,10) = pvpnum;
  5593. WFIFOSET(fd,packet_len(0x19a));
  5594. } else {
  5595. unsigned char buf[32];
  5596. WBUFW(buf,0) = 0x19a;
  5597. WBUFL(buf,2) = sd->bl.id;
  5598. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5599. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5600. else
  5601. WBUFL(buf,6) = pvprank;
  5602. WBUFL(buf,10) = pvpnum;
  5603. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5604. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5605. else if(!type)
  5606. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5607. else
  5608. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5609. }
  5610. }
  5611. /*==========================================
  5612. *
  5613. *------------------------------------------*/
  5614. void clif_map_property_mapall(int map_idx, enum map_property property)
  5615. {
  5616. struct block_list bl;
  5617. bl.id = 0;
  5618. bl.type = BL_NUL;
  5619. bl.m = map_idx;
  5620. clif_map_property( &bl, property, ALL_SAMEMAP );
  5621. }
  5622. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5623. /// 0188 <result>.W <index>.W <refine>.W
  5624. /// result:
  5625. /// 0 = success
  5626. /// 1 = failure
  5627. /// 2 = downgrade
  5628. void clif_refine(int fd, int fail, int index, int val)
  5629. {
  5630. WFIFOHEAD(fd,packet_len(0x188));
  5631. WFIFOW(fd,0)=0x188;
  5632. WFIFOW(fd,2)=fail;
  5633. WFIFOW(fd,4)=index+2;
  5634. WFIFOW(fd,6)=val;
  5635. WFIFOSET(fd,packet_len(0x188));
  5636. }
  5637. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5638. /// 0223 <result>.L <nameid>.W
  5639. /// result:
  5640. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5641. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5642. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5643. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5644. void clif_upgrademessage(int fd, int result, unsigned short item_id)
  5645. {
  5646. WFIFOHEAD(fd,packet_len(0x223));
  5647. WFIFOW(fd,0)=0x223;
  5648. WFIFOL(fd,2)=result;
  5649. WFIFOW(fd,6)=item_id;
  5650. WFIFOSET(fd,packet_len(0x223));
  5651. }
  5652. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5653. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5654. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5655. void clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  5656. {
  5657. #if PACKETVER < 20091104
  5658. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5659. WFIFOW(fd,0) = 0x97;
  5660. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5661. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5662. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5663. WFIFOSET(fd,WFIFOW(fd,2));
  5664. #else
  5665. struct map_session_data *ssd = map_nick2sd(nick,false);
  5666. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5667. WFIFOW(fd,0) = 0x97;
  5668. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5669. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5670. WFIFOL(fd,28) = (ssd && pc_get_group_level(ssd) == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5671. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5672. WFIFOSET(fd,WFIFOW(fd,2));
  5673. #endif
  5674. }
  5675. /// Inform the player about the result of his whisper action
  5676. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5677. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5678. /// result:
  5679. /// 0 = success to send wisper
  5680. /// 1 = target character is not loged in
  5681. /// 2 = ignored by target
  5682. /// 3 = everyone ignored by target
  5683. void clif_wis_end(int fd, int result)
  5684. {
  5685. struct map_session_data *sd = (session_isValid(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5686. #if PACKETVER < 20131223
  5687. const int cmd = 0x98;
  5688. #else
  5689. const int cmd = 0x9df;
  5690. #endif
  5691. if (!sd)
  5692. return;
  5693. WFIFOHEAD(fd,packet_len(cmd));
  5694. WFIFOW(fd,0) = cmd;
  5695. WFIFOB(fd,2) = (char)result;
  5696. #if PACKETVER >= 20131223
  5697. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5698. #endif
  5699. WFIFOSET(fd,packet_len(cmd));
  5700. }
  5701. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5702. /// 0194 <char id>.L <name>.24B
  5703. void clif_solved_charname(int fd, int charid, const char* name)
  5704. {
  5705. WFIFOHEAD(fd,packet_len(0x194));
  5706. WFIFOW(fd,0)=0x194;
  5707. WFIFOL(fd,2)=charid;
  5708. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5709. WFIFOSET(fd,packet_len(0x194));
  5710. }
  5711. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5712. /// 017b <packet len>.W { <name id>.W }*
  5713. void clif_use_card(struct map_session_data *sd,int idx)
  5714. {
  5715. int i,c,ep;
  5716. int fd=sd->fd;
  5717. nullpo_retv(sd);
  5718. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5719. return;
  5720. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5721. return; //Avoid parsing invalid item indexes (no card/no item)
  5722. ep=sd->inventory_data[idx]->equip;
  5723. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5724. WFIFOW(fd,0)=0x17b;
  5725. for(i=c=0;i<MAX_INVENTORY;i++){
  5726. int j;
  5727. if(sd->inventory_data[i] == NULL)
  5728. continue;
  5729. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5730. continue;
  5731. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  5732. continue;
  5733. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  5734. continue;
  5735. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5736. continue;
  5737. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5738. continue;
  5739. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  5740. if( j == sd->inventory_data[i]->slot ) // No room
  5741. continue;
  5742. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  5743. continue;
  5744. WFIFOW(fd,4+c*2)=i+2;
  5745. c++;
  5746. }
  5747. if( !c ) return; // no item is available for card insertion
  5748. WFIFOW(fd,2)=4+c*2;
  5749. WFIFOSET(fd,WFIFOW(fd,2));
  5750. }
  5751. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5752. /// 017d <equip index>.W <card index>.W <result>.B
  5753. /// result:
  5754. /// 0 = success
  5755. /// 1 = failure
  5756. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5757. {
  5758. int fd;
  5759. nullpo_retv(sd);
  5760. fd=sd->fd;
  5761. WFIFOHEAD(fd,packet_len(0x17d));
  5762. WFIFOW(fd,0)=0x17d;
  5763. WFIFOW(fd,2)=idx_equip+2;
  5764. WFIFOW(fd,4)=idx_card+2;
  5765. WFIFOB(fd,6)=flag;
  5766. WFIFOSET(fd,packet_len(0x17d));
  5767. }
  5768. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5769. /// 0177 <packet len>.W { <name id>.W }*
  5770. void clif_item_identify_list(struct map_session_data *sd)
  5771. {
  5772. int i,c;
  5773. int fd;
  5774. nullpo_retv(sd);
  5775. fd=sd->fd;
  5776. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5777. WFIFOW(fd,0)=0x177;
  5778. for(i=c=0;i<MAX_INVENTORY;i++){
  5779. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  5780. WFIFOW(fd,c*2+4)=i+2;
  5781. c++;
  5782. }
  5783. }
  5784. if(c > 0) {
  5785. WFIFOW(fd,2)=c*2+4;
  5786. WFIFOSET(fd,WFIFOW(fd,2));
  5787. sd->menuskill_id = MC_IDENTIFY;
  5788. sd->menuskill_val = c;
  5789. sd->state.workinprogress = WIP_DISABLE_ALL;
  5790. }
  5791. }
  5792. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5793. /// 0179 <index>.W <result>.B
  5794. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5795. {
  5796. int fd;
  5797. nullpo_retv(sd);
  5798. fd=sd->fd;
  5799. WFIFOHEAD(fd,packet_len(0x179));
  5800. WFIFOW(fd, 0)=0x179;
  5801. WFIFOW(fd, 2)=idx+2;
  5802. WFIFOB(fd, 4)=flag;
  5803. WFIFOSET(fd,packet_len(0x179));
  5804. }
  5805. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5806. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5807. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5808. {
  5809. int i,c;
  5810. int fd;
  5811. nullpo_retv(sd);
  5812. nullpo_retv(dstsd);
  5813. fd=sd->fd;
  5814. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5815. WFIFOW(fd,0)=0x1fc;
  5816. for(i=c=0;i<MAX_INVENTORY;i++){
  5817. unsigned short nameid;
  5818. if((nameid=dstsd->inventory.u.items_inventory[i].nameid) > 0 && dstsd->inventory.u.items_inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5819. WFIFOW(fd,c*13+4) = i;
  5820. WFIFOW(fd,c*13+6) = nameid;
  5821. WFIFOB(fd,c*13+8) = dstsd->inventory.u.items_inventory[i].refine;
  5822. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->inventory.u.items_inventory[i]);
  5823. c++;
  5824. }
  5825. }
  5826. if(c > 0) {
  5827. WFIFOW(fd,2)=c*13+4;
  5828. WFIFOSET(fd,WFIFOW(fd,2));
  5829. sd->menuskill_id = BS_REPAIRWEAPON;
  5830. sd->menuskill_val = dstsd->bl.id;
  5831. sd->menuskill_val2 = lv;
  5832. }else
  5833. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5834. }
  5835. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5836. /// 01fe <index>.W <result>.B
  5837. /// index:
  5838. /// ignored (inventory index)
  5839. /// result:
  5840. /// 0 = Item repair success.
  5841. /// 1 = Item repair failure.
  5842. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5843. {
  5844. int fd;
  5845. nullpo_retv(sd);
  5846. fd = sd->fd;
  5847. WFIFOHEAD(fd,packet_len(0x1fe));
  5848. WFIFOW(fd, 0)=0x1fe;
  5849. WFIFOW(fd, 2)=idx+2;
  5850. WFIFOB(fd, 4)=flag;
  5851. WFIFOSET(fd,packet_len(0x1fe));
  5852. }
  5853. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5854. /// 02bb <equip location>.W <account id>.L
  5855. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5856. {
  5857. int fd = sd->fd;
  5858. WFIFOHEAD(fd,packet_len(0x2bb));
  5859. WFIFOW(fd,0) = 0x2bb;
  5860. WFIFOW(fd,2) = position;
  5861. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5862. WFIFOSET(fd,packet_len(0x2bb));
  5863. }
  5864. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5865. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5866. void clif_item_refine_list(struct map_session_data *sd)
  5867. {
  5868. int i,c;
  5869. int fd;
  5870. uint16 skill_lv;
  5871. int refine_item[5];
  5872. nullpo_retv(sd);
  5873. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5874. fd=sd->fd;
  5875. refine_item[0] = -1;
  5876. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5877. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5878. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5879. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5880. WFIFOW(fd,0) = 0x221;
  5881. for(i = c = 0; i < MAX_INVENTORY; i++) {
  5882. unsigned char wlv;
  5883. if(sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  5884. sd->inventory.u.items_inventory[i].identify && (wlv = itemdb_wlv(sd->inventory.u.items_inventory[i].nameid)) >=1 &&
  5885. refine_item[wlv] != -1 && !(sd->inventory.u.items_inventory[i].equip&EQP_ARMS)){
  5886. WFIFOW(fd,c*13+ 4)=i+2;
  5887. WFIFOW(fd,c*13+ 6) = sd->inventory.u.items_inventory[i].nameid;
  5888. WFIFOB(fd,c*13+ 8) = sd->inventory.u.items_inventory[i].refine;
  5889. clif_addcards(WFIFOP(fd,c*13+9), &sd->inventory.u.items_inventory[i]);
  5890. c++;
  5891. }
  5892. }
  5893. WFIFOW(fd,2)=c*13+4;
  5894. WFIFOSET(fd,WFIFOW(fd,2));
  5895. if (c > 0) {
  5896. sd->menuskill_id = WS_WEAPONREFINE;
  5897. sd->menuskill_val = skill_lv;
  5898. }
  5899. }
  5900. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5901. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5902. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5903. {
  5904. int fd;
  5905. nullpo_retv(sd);
  5906. fd=sd->fd;
  5907. WFIFOHEAD(fd,packet_len(0x147));
  5908. WFIFOW(fd, 0)=0x147;
  5909. WFIFOW(fd, 2)=skill_id;
  5910. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5911. WFIFOW(fd, 6)=0;
  5912. WFIFOW(fd, 8)=skill_lv;
  5913. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5914. WFIFOW(fd,12)=skill_get_range2(&sd->bl,skill_id,skill_lv,false);
  5915. safestrncpy(WFIFOCP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5916. WFIFOB(fd,38)=0;
  5917. WFIFOSET(fd,packet_len(0x147));
  5918. }
  5919. /// Adds an item to character's cart.
  5920. /// 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)
  5921. /// 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)
  5922. /// 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)
  5923. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5924. {
  5925. #if PACKETVER < 5
  5926. const int cmd = 0x124;
  5927. #elif PACKETVER < 20150225
  5928. const int cmd = 0x1c5;
  5929. #else
  5930. const int cmd = 0xa0b;
  5931. #endif
  5932. int view,fd;
  5933. unsigned char *buf;
  5934. int offset = 0;
  5935. nullpo_retv(sd);
  5936. fd=sd->fd;
  5937. if(n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid <= 0)
  5938. return;
  5939. WFIFOHEAD(fd,packet_len(cmd));
  5940. buf=WFIFOP(fd,0);
  5941. WBUFW(buf,0)=cmd;
  5942. WBUFW(buf,2)=n+2;
  5943. WBUFL(buf,4)=amount;
  5944. if((view = itemdb_viewid(sd->cart.u.items_cart[n].nameid)) > 0)
  5945. WBUFW(buf,8)=view;
  5946. else
  5947. WBUFW(buf,8)=sd->cart.u.items_cart[n].nameid;
  5948. #if PACKETVER >= 5
  5949. WBUFB(buf,10)=itemdb_type(sd->cart.u.items_cart[n].nameid);
  5950. offset += 1;
  5951. #endif
  5952. WBUFB(buf,10+offset)=sd->cart.u.items_cart[n].identify;
  5953. WBUFB(buf,11+offset)=sd->cart.u.items_cart[n].attribute;
  5954. WBUFB(buf,12+offset)=sd->cart.u.items_cart[n].refine;
  5955. clif_addcards(WBUFP(buf,13+offset), &sd->cart.u.items_cart[n]);
  5956. #if PACKETVER >= 20150225
  5957. clif_add_random_options(WBUFP(buf,21+offset), &sd->cart.u.items_cart[n]);
  5958. #endif
  5959. WFIFOSET(fd,packet_len(cmd));
  5960. }
  5961. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5962. /* Acknowledge an item have been added to cart
  5963. * 012c <result>B
  5964. * result :
  5965. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5966. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5967. */
  5968. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5969. {
  5970. int fd;
  5971. unsigned char *buf;
  5972. nullpo_retv(sd);
  5973. fd = sd->fd;
  5974. buf = WFIFOP(fd,0);
  5975. WBUFW(buf,0) = 0x12c;
  5976. WBUFB(buf,2) = flag;
  5977. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  5978. }
  5979. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  5980. void clif_bank_open(struct map_session_data *sd){
  5981. int fd;
  5982. nullpo_retv(sd);
  5983. fd = sd->fd;
  5984. WFIFOHEAD(fd,4);
  5985. WFIFOW(fd,0) = 0x09b7;
  5986. WFIFOW(fd,2) = 0;
  5987. WFIFOSET(fd,4);
  5988. }
  5989. /*
  5990. * Request to Open the banking system
  5991. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  5992. */
  5993. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  5994. //TODO check if preventing trade or stuff like that
  5995. //also mark something in case char ain't available for saving, should we check now ?
  5996. nullpo_retv(sd);
  5997. if( !battle_config.feature_banking ) {
  5998. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  5999. return;
  6000. }
  6001. else {
  6002. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6003. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6004. if(sd->status.account_id == aid){
  6005. sd->state.banking = 1;
  6006. //request save ?
  6007. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6008. //on succes open bank ?
  6009. clif_bank_open(sd);
  6010. }
  6011. }
  6012. }
  6013. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6014. void clif_bank_close(struct map_session_data *sd){
  6015. int fd;
  6016. nullpo_retv(sd);
  6017. fd = sd->fd;
  6018. WFIFOHEAD(fd,4);
  6019. WFIFOW(fd,0) = 0x09B9;
  6020. WFIFOW(fd,2) = 0;
  6021. WFIFOSET(fd,4);
  6022. }
  6023. /*
  6024. * Request to close the banking system
  6025. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6026. */
  6027. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6028. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6029. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6030. nullpo_retv(sd);
  6031. if( !battle_config.feature_banking ) {
  6032. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6033. //still allow to go trough to not stuck player if we have disable it while they was in
  6034. }
  6035. if(sd->status.account_id == aid){
  6036. sd->state.banking = 0;
  6037. clif_bank_close(sd);
  6038. }
  6039. }
  6040. /*
  6041. * Display how much we got in bank (I suppose)
  6042. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  6043. */
  6044. void clif_Bank_Check(struct map_session_data* sd) {
  6045. unsigned char buf[13];
  6046. struct s_packet_db* info;
  6047. int16 len;
  6048. int cmd = 0;
  6049. nullpo_retv(sd);
  6050. cmd = packet_db_ack[ZC_BANKING_CHECK];
  6051. if(!cmd) cmd = 0x09A6; //default
  6052. info = &packet_db[cmd];
  6053. len = info->len;
  6054. if(!len) return; //version as packet disable
  6055. // sd->state.banking = 1; //mark opening and closing
  6056. WBUFW(buf,0) = cmd;
  6057. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  6058. WBUFW(buf,info->pos[1]) = 0; //reason
  6059. clif_send(buf,len,&sd->bl,SELF);
  6060. }
  6061. /*
  6062. * Requesting the data in bank
  6063. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6064. */
  6065. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6066. nullpo_retv(sd);
  6067. if( !battle_config.feature_banking ) {
  6068. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6069. return;
  6070. }
  6071. else {
  6072. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6073. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6074. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6075. clif_Bank_Check(sd);
  6076. }
  6077. }
  6078. /*
  6079. * Acknowledge of deposit some money in bank
  6080. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6081. */
  6082. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  6083. unsigned char buf[17];
  6084. struct s_packet_db* info;
  6085. int16 len;
  6086. int cmd =0;
  6087. nullpo_retv(sd);
  6088. cmd = packet_db_ack[ZC_ACK_BANKING_DEPOSIT];
  6089. if(!cmd) cmd = 0x09A8;
  6090. info = &packet_db[cmd];
  6091. len = info->len;
  6092. if(!len) return; //version as packet disable
  6093. WBUFW(buf,0) = cmd;
  6094. WBUFW(buf,info->pos[0]) = (short)reason;
  6095. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6096. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6097. clif_send(buf,len,&sd->bl,SELF);
  6098. }
  6099. /*
  6100. * Request saving some money in bank
  6101. * @author : original [Yommy/Hercules]
  6102. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6103. */
  6104. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6105. nullpo_retv(sd);
  6106. if( !battle_config.feature_banking ) {
  6107. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6108. return;
  6109. }
  6110. else {
  6111. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6112. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6113. int money = RFIFOL(fd,info->pos[1]);
  6114. if(sd->status.account_id == aid){
  6115. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6116. clif_bank_deposit(sd,reason);
  6117. }
  6118. }
  6119. }
  6120. /*
  6121. * Acknowledge of withdrawing some money from bank
  6122. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6123. */
  6124. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6125. unsigned char buf[17];
  6126. struct s_packet_db* info;
  6127. int16 len;
  6128. int cmd;
  6129. nullpo_retv(sd);
  6130. cmd = packet_db_ack[ZC_ACK_BANKING_WITHDRAW];
  6131. if(!cmd) cmd = 0x09AA;
  6132. info = &packet_db[cmd];
  6133. len = info->len;
  6134. if(!len) return; //version as packet disable
  6135. WBUFW(buf,0) = cmd;
  6136. WBUFW(buf,info->pos[0]) = (short)reason;
  6137. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6138. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6139. clif_send(buf,len,&sd->bl,SELF);
  6140. }
  6141. /*
  6142. * Request Withdrawing some money from bank
  6143. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6144. */
  6145. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6146. nullpo_retv(sd);
  6147. if( !battle_config.feature_banking ) {
  6148. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6149. return;
  6150. }
  6151. else {
  6152. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6153. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6154. int money = RFIFOL(fd,info->pos[1]);
  6155. if(sd->status.account_id == aid){
  6156. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6157. clif_bank_withdraw(sd,reason);
  6158. }
  6159. }
  6160. }
  6161. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6162. /// 0125 <index>.W <amount>.L
  6163. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6164. {
  6165. int fd;
  6166. nullpo_retv(sd);
  6167. fd=sd->fd;
  6168. WFIFOHEAD(fd,packet_len(0x125));
  6169. WFIFOW(fd,0)=0x125;
  6170. WFIFOW(fd,2)=n+2;
  6171. WFIFOL(fd,4)=amount;
  6172. WFIFOSET(fd,packet_len(0x125));
  6173. }
  6174. /// Opens the shop creation menu (ZC_OPENSTORE).
  6175. /// 012d <num>.W
  6176. /// num:
  6177. /// number of allowed item slots
  6178. void clif_openvendingreq(struct map_session_data* sd, int num)
  6179. {
  6180. int fd;
  6181. nullpo_retv(sd);
  6182. fd = sd->fd;
  6183. WFIFOHEAD(fd,packet_len(0x12d));
  6184. WFIFOW(fd,0) = 0x12d;
  6185. WFIFOW(fd,2) = num;
  6186. WFIFOSET(fd,packet_len(0x12d));
  6187. }
  6188. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6189. /// 0131 <owner id>.L <message>.80B
  6190. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6191. {
  6192. unsigned char buf[128];
  6193. nullpo_retv(bl);
  6194. WBUFW(buf,0) = 0x131;
  6195. WBUFL(buf,2) = bl->id;
  6196. safestrncpy(WBUFCP(buf,6), message, 80);
  6197. if( fd ) {
  6198. WFIFOHEAD(fd,packet_len(0x131));
  6199. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6200. WFIFOSET(fd,packet_len(0x131));
  6201. } else {
  6202. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6203. }
  6204. }
  6205. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6206. /// 0132 <owner id>.L
  6207. void clif_closevendingboard(struct block_list* bl, int fd)
  6208. {
  6209. unsigned char buf[16];
  6210. nullpo_retv(bl);
  6211. WBUFW(buf,0) = 0x132;
  6212. WBUFL(buf,2) = bl->id;
  6213. if( fd ) {
  6214. WFIFOHEAD(fd,packet_len(0x132));
  6215. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6216. WFIFOSET(fd,packet_len(0x132));
  6217. } else {
  6218. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6219. }
  6220. }
  6221. /// Sends a list of items in a shop.
  6222. /// 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)
  6223. /// 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)
  6224. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  6225. {
  6226. int i,fd;
  6227. int count;
  6228. struct map_session_data* vsd;
  6229. #if PACKETVER < 20100105
  6230. const int cmd = 0x133;
  6231. const int offset = 8;
  6232. #else
  6233. const int cmd = 0x800;
  6234. const int offset = 12;
  6235. #endif
  6236. #if PACKETVER < 20150225
  6237. const int item_length = 22;
  6238. #elif PACKETVER < 20160921
  6239. const int item_length = 47;
  6240. #else
  6241. const int item_length = 53;
  6242. #endif
  6243. nullpo_retv(sd);
  6244. nullpo_retv(vending);
  6245. nullpo_retv(vsd=map_id2sd(id));
  6246. fd = sd->fd;
  6247. count = vsd->vend_num;
  6248. WFIFOHEAD(fd, offset+count*item_length);
  6249. WFIFOW(fd,0) = cmd;
  6250. WFIFOW(fd,2) = offset+count*item_length;
  6251. WFIFOL(fd,4) = id;
  6252. #if PACKETVER >= 20100105
  6253. WFIFOL(fd,8) = vsd->vender_id;
  6254. #endif
  6255. for( i = 0; i < count; i++ )
  6256. {
  6257. int index = vending[i].index;
  6258. struct item_data* data = itemdb_search(vsd->cart.u.items_cart[index].nameid);
  6259. WFIFOL(fd,offset+ 0+i*item_length) = vending[i].value;
  6260. WFIFOW(fd,offset+ 4+i*item_length) = vending[i].amount;
  6261. WFIFOW(fd,offset+ 6+i*item_length) = vending[i].index + 2;
  6262. WFIFOB(fd,offset+ 8+i*item_length) = itemtype(data->nameid);
  6263. WFIFOW(fd,offset+ 9+i*item_length) = ( data->view_id > 0 ) ? data->view_id : vsd->cart.u.items_cart[index].nameid;
  6264. WFIFOB(fd,offset+11+i*item_length) = vsd->cart.u.items_cart[index].identify;
  6265. WFIFOB(fd,offset+12+i*item_length) = vsd->cart.u.items_cart[index].attribute;
  6266. WFIFOB(fd,offset+13+i*item_length) = vsd->cart.u.items_cart[index].refine;
  6267. clif_addcards(WFIFOP(fd,offset+14+i*item_length), &vsd->cart.u.items_cart[index]);
  6268. #if PACKETVER >= 20150225
  6269. clif_add_random_options(WFIFOP(fd,offset+22+i*item_length), &vsd->cart.u.items_cart[index]);
  6270. #if PACKETVER >= 20160921
  6271. WFIFOL(fd,offset+47+i*item_length) = pc_equippoint_sub(sd,data);
  6272. WFIFOW(fd,offset+51+i*item_length) = data->look;
  6273. #endif
  6274. #endif
  6275. }
  6276. WFIFOSET(fd,WFIFOW(fd,2));
  6277. }
  6278. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6279. /// 0135 <index>.W <amount>.W <result>.B
  6280. /// result:
  6281. /// 0 = success
  6282. /// 1 = not enough zeny
  6283. /// 2 = overweight
  6284. /// 4 = out of stock
  6285. /// 5 = "cannot use an npc shop while in a trade"
  6286. /// 6 = Because the store information was incorrect the item was not purchased.
  6287. /// 7 = No sales information.
  6288. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6289. {
  6290. int fd;
  6291. nullpo_retv(sd);
  6292. fd = sd->fd;
  6293. WFIFOHEAD(fd,packet_len(0x135));
  6294. WFIFOW(fd,0) = 0x135;
  6295. WFIFOW(fd,2) = index+2;
  6296. WFIFOW(fd,4) = amount;
  6297. WFIFOB(fd,6) = fail;
  6298. WFIFOSET(fd,packet_len(0x135));
  6299. }
  6300. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6301. /// 0a28 <Result>.B
  6302. /// result:
  6303. /// 0 = Successed
  6304. /// 1 = Failed
  6305. void clif_openvending_ack(struct map_session_data* sd, int result)
  6306. {
  6307. int fd;
  6308. nullpo_retv(sd);
  6309. fd = sd->fd;
  6310. WFIFOHEAD(fd, 3);
  6311. WFIFOW(fd,0) = 0xa28;
  6312. WFIFOB(fd,2) = result;
  6313. WFIFOSET(fd, 3);
  6314. }
  6315. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  6316. /// 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 }*
  6317. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  6318. {
  6319. int i,fd;
  6320. int count;
  6321. #if PACKETVER < 20150225
  6322. const int item_length = 22;
  6323. #else
  6324. const int item_length = 47;
  6325. #endif
  6326. nullpo_retv(sd);
  6327. fd = sd->fd;
  6328. count = sd->vend_num;
  6329. WFIFOHEAD(fd, 8+count*item_length);
  6330. WFIFOW(fd,0) = 0x136;
  6331. WFIFOW(fd,2) = 8+count*item_length;
  6332. WFIFOL(fd,4) = id;
  6333. for( i = 0; i < count; i++ ) {
  6334. int index = vending[i].index;
  6335. struct item_data* data = itemdb_search(sd->cart.u.items_cart[index].nameid);
  6336. WFIFOL(fd, 8+i*item_length) = vending[i].value;
  6337. WFIFOW(fd,12+i*item_length) = vending[i].index + 2;
  6338. WFIFOW(fd,14+i*item_length) = vending[i].amount;
  6339. WFIFOB(fd,16+i*item_length) = itemtype(data->nameid);
  6340. WFIFOW(fd,17+i*item_length) = ( data->view_id > 0 ) ? data->view_id : sd->cart.u.items_cart[index].nameid;
  6341. WFIFOB(fd,19+i*item_length) = sd->cart.u.items_cart[index].identify;
  6342. WFIFOB(fd,20+i*item_length) = sd->cart.u.items_cart[index].attribute;
  6343. WFIFOB(fd,21+i*item_length) = sd->cart.u.items_cart[index].refine;
  6344. clif_addcards(WFIFOP(fd,22+i*item_length), &sd->cart.u.items_cart[index]);
  6345. #if PACKETVER >= 20150225
  6346. clif_add_random_options(WFIFOP(fd,30+i*item_length), &sd->cart.u.items_cart[index]);
  6347. #endif
  6348. }
  6349. WFIFOSET(fd,WFIFOW(fd,2));
  6350. #if PACKETVER >= 20141022
  6351. /// 0 = Successed
  6352. /// 1 = Failed
  6353. clif_openvending_ack(sd, 0);
  6354. #endif
  6355. }
  6356. /// Inform merchant that someone has bought an item.
  6357. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6358. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6359. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6360. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6361. const int cmd = 0x137;
  6362. #else
  6363. const int cmd = 0x9e5;
  6364. #endif
  6365. int fd = sd->fd;
  6366. nullpo_retv(sd);
  6367. WFIFOHEAD(fd,packet_len(cmd));
  6368. WFIFOW(fd,0) = cmd;
  6369. WFIFOW(fd,2) = index+2;
  6370. WFIFOW(fd,4) = amount;
  6371. #if PACKETVER >= 20141016
  6372. WFIFOL(fd,6) = char_id; // GID
  6373. WFIFOL(fd,10) = (int)time(NULL); // Date
  6374. WFIFOL(fd,14) = zeny; // zeny
  6375. #endif
  6376. WFIFOSET(fd,packet_len(cmd));
  6377. }
  6378. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6379. /// 00fa <result>.B
  6380. /// result:
  6381. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6382. /// 1 = MsgStringTable[78]="party name already exists"
  6383. /// 2 = MsgStringTable[79]="already in a party"
  6384. /// 3 = cannot organize parties on this map
  6385. /// ? = nothing
  6386. void clif_party_created(struct map_session_data *sd,int result)
  6387. {
  6388. int fd;
  6389. nullpo_retv(sd);
  6390. fd=sd->fd;
  6391. WFIFOHEAD(fd,packet_len(0xfa));
  6392. WFIFOW(fd,0)=0xfa;
  6393. WFIFOB(fd,2)=result;
  6394. WFIFOSET(fd,packet_len(0xfa));
  6395. }
  6396. /// Adds new member to a party.
  6397. /// 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)
  6398. /// 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)
  6399. /// 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)
  6400. /// role:
  6401. /// 0 = leader
  6402. /// 1 = normal
  6403. /// state:
  6404. /// 0 = connected
  6405. /// 1 = disconnected
  6406. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6407. {
  6408. int i;
  6409. #if PACKETVER < 20170502
  6410. unsigned char buf[81];
  6411. int cmd = 0x1e9;
  6412. int offset = 0;
  6413. #else
  6414. unsigned char buf[85];
  6415. int cmd = 0xa43;
  6416. int offset = 4;
  6417. #endif
  6418. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6419. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6420. } else {
  6421. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6422. }
  6423. if (i >= MAX_PARTY) return; //Should never happen...
  6424. sd = p->data[i].sd;
  6425. WBUFW(buf, 0) = cmd;
  6426. WBUFL(buf, 2) = sd->status.account_id;
  6427. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6428. #if PACKETVER >= 20170502
  6429. WBUFW(buf,10) = sd->status.class_;
  6430. WBUFW(buf,12) = sd->status.base_level;
  6431. #endif
  6432. WBUFW(buf,offset+10) = sd->bl.x;
  6433. WBUFW(buf,offset+12) = sd->bl.y;
  6434. WBUFB(buf,offset+14) = (p->party.member[i].online)?0:1;
  6435. safestrncpy(WBUFCP(buf,offset+15), p->party.name, NAME_LENGTH);
  6436. safestrncpy(WBUFCP(buf,offset+39), sd->status.name, NAME_LENGTH);
  6437. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), WBUFCP(buf,offset+63));
  6438. WBUFB(buf,offset+79) = (p->party.item&1)?1:0;
  6439. WBUFB(buf,offset+80) = (p->party.item&2)?1:0;
  6440. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6441. }
  6442. /// Sends party information (ZC_GROUP_LIST).
  6443. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6444. /// role:
  6445. /// 0 = leader
  6446. /// 1 = normal
  6447. /// state:
  6448. /// 0 = connected
  6449. /// 1 = disconnected
  6450. /// 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
  6451. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6452. {
  6453. struct map_session_data* party_sd = NULL;
  6454. int i, c;
  6455. #if PACKETVER < 20170502
  6456. const int M_SIZE = 46; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1
  6457. unsigned char buf[2+2+NAME_LENGTH+46*MAX_PARTY];
  6458. int cmd = 0xfb;
  6459. #else
  6460. const int M_SIZE = 50; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1+4
  6461. unsigned char buf[2+2+NAME_LENGTH+50*MAX_PARTY+6];
  6462. int cmd = 0xa44;
  6463. #endif
  6464. const int PRE_SIZE = 28; // cmd, actual cmd_size, party_name
  6465. nullpo_retv(p);
  6466. WBUFW(buf,0) = cmd;
  6467. safestrncpy(WBUFCP(buf,4), p->party.name, NAME_LENGTH);
  6468. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6469. {
  6470. struct party_member* m = &p->party.member[i];
  6471. if(!m->account_id) continue;
  6472. if(party_sd == NULL) party_sd = p->data[i].sd;
  6473. WBUFL(buf,PRE_SIZE+c*M_SIZE) = m->account_id;
  6474. safestrncpy(WBUFCP(buf,PRE_SIZE+c*M_SIZE+4), m->name, NAME_LENGTH);
  6475. mapindex_getmapname_ext(mapindex_id2name(m->map), WBUFCP(buf,PRE_SIZE+c*M_SIZE+PRE_SIZE));
  6476. WBUFB(buf,PRE_SIZE+c*M_SIZE+44) = (m->leader) ? 0 : 1;
  6477. WBUFB(buf,PRE_SIZE+c*M_SIZE+45) = (m->online) ? 0 : 1;
  6478. #if PACKETVER >= 20170502
  6479. WBUFW(buf,PRE_SIZE+c*M_SIZE+46) = m->class_;
  6480. WBUFW(buf,PRE_SIZE+c*M_SIZE+48) = m->lv;
  6481. #endif
  6482. c++;
  6483. }
  6484. #if PACKETVER < 20170502
  6485. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE;
  6486. #else
  6487. WBUFB(buf,PRE_SIZE+c*M_SIZE) = (p->party.item & 1) ? 1 : 0;
  6488. WBUFB(buf,PRE_SIZE+c*M_SIZE+1) = (p->party.item & 2) ? 1 : 0;
  6489. WBUFL(buf,PRE_SIZE+c*M_SIZE+2) = 0; // unknown
  6490. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE+6;
  6491. #endif
  6492. if(sd) { // send only to self
  6493. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6494. } else if (party_sd) { // send to whole party
  6495. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6496. }
  6497. }
  6498. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6499. /// 02c9 <flag>.B
  6500. /// flag:
  6501. /// 0 = allow party invites
  6502. /// 1 = auto-deny party invites
  6503. void clif_partyinvitationstate(struct map_session_data* sd)
  6504. {
  6505. int fd;
  6506. nullpo_retv(sd);
  6507. fd = sd->fd;
  6508. WFIFOHEAD(fd, packet_len(0x2c9));
  6509. WFIFOW(fd, 0) = 0x2c9;
  6510. WFIFOB(fd, 2) = 0; // not implemented
  6511. WFIFOSET(fd, packet_len(0x2c9));
  6512. }
  6513. /// Party invitation request.
  6514. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6515. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6516. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6517. {
  6518. #if PACKETVER < 20070821
  6519. const int cmd = 0xfe;
  6520. #else
  6521. const int cmd = 0x2c6;
  6522. #endif
  6523. int fd;
  6524. struct party_data *p;
  6525. nullpo_retv(sd);
  6526. nullpo_retv(tsd);
  6527. fd=tsd->fd;
  6528. if( (p=party_search(sd->status.party_id))==NULL )
  6529. return;
  6530. WFIFOHEAD(fd,packet_len(cmd));
  6531. WFIFOW(fd,0)=cmd;
  6532. WFIFOL(fd,2)=sd->status.party_id;
  6533. safestrncpy(WFIFOCP(fd,6),p->party.name,NAME_LENGTH);
  6534. WFIFOSET(fd,packet_len(cmd));
  6535. }
  6536. /// Party invite result.
  6537. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6538. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6539. void clif_party_invite_reply(struct map_session_data* sd, const char* nick, enum e_party_invite_reply reply)
  6540. {
  6541. int fd;
  6542. nullpo_retv(sd);
  6543. fd=sd->fd;
  6544. #if PACKETVER < 20070904
  6545. if( reply == PARTY_REPLY_OFFLINE ) {
  6546. clif_displaymessage(fd, msg_txt(sd,3));
  6547. return;
  6548. }
  6549. #endif
  6550. #if PACKETVER < 20070821
  6551. WFIFOHEAD(fd,packet_len(0xfd));
  6552. WFIFOW(fd,0) = 0xfd;
  6553. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6554. WFIFOB(fd,26) = reply;
  6555. WFIFOSET(fd,packet_len(0xfd));
  6556. #else
  6557. WFIFOHEAD(fd,packet_len(0x2c5));
  6558. WFIFOW(fd,0) = 0x2c5;
  6559. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6560. WFIFOL(fd,26) = reply;
  6561. WFIFOSET(fd,packet_len(0x2c5));
  6562. #endif
  6563. }
  6564. /// Updates party settings.
  6565. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6566. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6567. /// exp option:
  6568. /// 0 = exp sharing disabled
  6569. /// 1 = exp sharing enabled
  6570. /// 2 = cannot change exp sharing
  6571. ///
  6572. /// flag:
  6573. /// 0 = send to party
  6574. /// 1 = send to sd
  6575. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6576. {
  6577. unsigned char buf[16];
  6578. #if PACKETVER < 20090603
  6579. const int cmd = 0x101;
  6580. #else
  6581. const int cmd = 0x7d8;
  6582. #endif
  6583. nullpo_retv(p);
  6584. if(!sd && flag==0){
  6585. int i;
  6586. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6587. if (i < MAX_PARTY)
  6588. sd = p->data[i].sd;
  6589. }
  6590. if(!sd) return;
  6591. WBUFW(buf,0)=cmd;
  6592. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6593. #if PACKETVER >= 20090603
  6594. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6595. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6596. #endif
  6597. if(flag==0)
  6598. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6599. else
  6600. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6601. }
  6602. /**
  6603. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6604. * @param sd Send the notification for this player
  6605. * @param account_id Account ID of kicked member
  6606. * @param name Name of kicked member
  6607. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6608. * @param target Send target
  6609. **/
  6610. 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) {
  6611. unsigned char buf[2+4+NAME_LENGTH+1];
  6612. if (!sd)
  6613. return;
  6614. WBUFW(buf,0) = 0x0105;
  6615. WBUFL(buf,2) = account_id;
  6616. memcpy(WBUFP(buf,6), name, NAME_LENGTH);
  6617. WBUFB(buf,6+NAME_LENGTH) = result;
  6618. clif_send(buf, 2+4+NAME_LENGTH+1, &sd->bl, target);
  6619. }
  6620. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6621. /// 0109 <packet len>.W <account id>.L <message>.?B
  6622. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6623. {
  6624. struct map_session_data *sd;
  6625. int i;
  6626. nullpo_retv(p);
  6627. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6628. if(i < MAX_PARTY){
  6629. unsigned char buf[1024];
  6630. if( len > sizeof(buf)-8 )
  6631. {
  6632. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6633. len = sizeof(buf)-8;
  6634. }
  6635. sd = p->data[i].sd;
  6636. WBUFW(buf,0)=0x109;
  6637. WBUFW(buf,2)=len+8;
  6638. WBUFL(buf,4)=account_id;
  6639. safestrncpy(WBUFCP(buf,8), mes, len);
  6640. clif_send(buf,len+8,&sd->bl,PARTY);
  6641. }
  6642. }
  6643. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6644. /// 0107 <account id>.L <x>.W <y>.W
  6645. void clif_party_xy(struct map_session_data *sd)
  6646. {
  6647. unsigned char buf[16];
  6648. nullpo_retv(sd);
  6649. WBUFW(buf,0)=0x107;
  6650. WBUFL(buf,2)=sd->status.account_id;
  6651. WBUFW(buf,6)=sd->bl.x;
  6652. WBUFW(buf,8)=sd->bl.y;
  6653. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6654. }
  6655. /*==========================================
  6656. * Sends x/y dot to a single fd. [Skotlex]
  6657. *------------------------------------------*/
  6658. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6659. {
  6660. WFIFOHEAD(fd,packet_len(0x107));
  6661. WFIFOW(fd,0)=0x107;
  6662. WFIFOL(fd,2)=sd->status.account_id;
  6663. WFIFOW(fd,6)=sd->bl.x;
  6664. WFIFOW(fd,8)=sd->bl.y;
  6665. WFIFOSET(fd,packet_len(0x107));
  6666. }
  6667. /// Updates HP bar of a party member.
  6668. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6669. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6670. void clif_party_hp(struct map_session_data *sd)
  6671. {
  6672. unsigned char buf[16];
  6673. #if PACKETVER < 20100126
  6674. const int cmd = 0x106;
  6675. #else
  6676. const int cmd = 0x80e;
  6677. #endif
  6678. nullpo_retv(sd);
  6679. WBUFW(buf,0)=cmd;
  6680. WBUFL(buf,2)=sd->status.account_id;
  6681. #if PACKETVER < 20100126
  6682. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6683. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6684. WBUFW(buf,8) = 100;
  6685. } else {
  6686. WBUFW(buf,6) = sd->battle_status.hp;
  6687. WBUFW(buf,8) = sd->battle_status.max_hp;
  6688. }
  6689. #else
  6690. WBUFL(buf,6) = sd->battle_status.hp;
  6691. WBUFL(buf,10) = sd->battle_status.max_hp;
  6692. #endif
  6693. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6694. }
  6695. /// Updates the job and level of a party member
  6696. /// 0abd <account id>.L <job>.W <level>.W
  6697. void clif_party_job_and_level(struct map_session_data *sd){
  6698. #if PACKETVER >= 20170502
  6699. unsigned char buf[10];
  6700. nullpo_retv(sd);
  6701. WBUFW(buf, 0) = 0xabd;
  6702. WBUFL(buf, 2) = sd->status.account_id;
  6703. WBUFW(buf, 6) = sd->status.class_;
  6704. WBUFW(buf, 8) = sd->status.base_level;
  6705. clif_send(buf, packet_len(0xabd), &sd->bl, PARTY);
  6706. #endif
  6707. }
  6708. /*==========================================
  6709. * Sends HP bar to a single fd. [Skotlex]
  6710. *------------------------------------------*/
  6711. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6712. {
  6713. #if PACKETVER < 20100126
  6714. const int cmd = 0x106;
  6715. #else
  6716. const int cmd = 0x80e;
  6717. #endif
  6718. WFIFOHEAD(fd,packet_len(cmd));
  6719. WFIFOW(fd,0) = cmd;
  6720. WFIFOL(fd,2) = id;
  6721. #if PACKETVER < 20100126
  6722. if( maxhp > INT16_MAX )
  6723. {// To correctly display the %hp bar. [Skotlex]
  6724. WFIFOW(fd,6) = hp/(maxhp/100);
  6725. WFIFOW(fd,8) = 100;
  6726. } else {
  6727. WFIFOW(fd,6) = hp;
  6728. WFIFOW(fd,8) = maxhp;
  6729. }
  6730. #else
  6731. WFIFOL(fd,6) = hp;
  6732. WFIFOL(fd,10) = maxhp;
  6733. #endif
  6734. WFIFOSET(fd, packet_len(cmd));
  6735. }
  6736. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6737. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6738. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6739. {
  6740. int fd;
  6741. nullpo_retv(sd);
  6742. nullpo_retv(bl);
  6743. fd=sd->fd;
  6744. WFIFOHEAD(fd,packet_len(0x139));
  6745. WFIFOW(fd, 0)=0x139;
  6746. WFIFOL(fd, 2)=bl->id;
  6747. WFIFOW(fd, 6)=bl->x;
  6748. WFIFOW(fd, 8)=bl->y;
  6749. WFIFOW(fd,10)=sd->bl.x;
  6750. WFIFOW(fd,12)=sd->bl.y;
  6751. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6752. WFIFOSET(fd,packet_len(0x139));
  6753. }
  6754. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6755. /// 018f <result>.W <name id>.W
  6756. /// result:
  6757. /// 0 = success
  6758. /// 1 = failure
  6759. /// 2 = success (alchemist)
  6760. /// 3 = failure (alchemist)
  6761. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid)
  6762. {
  6763. int view,fd;
  6764. nullpo_retv(sd);
  6765. fd = sd->fd;
  6766. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6767. WFIFOHEAD(fd,packet_len(0x18f));
  6768. WFIFOW(fd, 0)=0x18f;
  6769. WFIFOW(fd, 2)=flag;
  6770. if((view = itemdb_viewid(nameid)) > 0)
  6771. WFIFOW(fd, 4)=view;
  6772. else
  6773. WFIFOW(fd, 4)=nameid;
  6774. WFIFOSET(fd,packet_len(0x18f));
  6775. }
  6776. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6777. /// 019e
  6778. void clif_catch_process(struct map_session_data *sd)
  6779. {
  6780. int fd;
  6781. nullpo_retv(sd);
  6782. fd=sd->fd;
  6783. WFIFOHEAD(fd,packet_len(0x19e));
  6784. WFIFOW(fd,0)=0x19e;
  6785. WFIFOSET(fd,packet_len(0x19e));
  6786. }
  6787. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6788. /// 01a0 <result>.B
  6789. /// 0 = failure
  6790. /// 1 = success
  6791. void clif_pet_roulette(struct map_session_data *sd,int data)
  6792. {
  6793. int fd;
  6794. nullpo_retv(sd);
  6795. fd=sd->fd;
  6796. WFIFOHEAD(fd,packet_len(0x1a0));
  6797. WFIFOW(fd,0)=0x1a0;
  6798. WFIFOB(fd,2)=data;
  6799. WFIFOSET(fd,packet_len(0x1a0));
  6800. }
  6801. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6802. /// 01a6 <packet len>.W { <index>.W }*
  6803. void clif_sendegg(struct map_session_data *sd)
  6804. {
  6805. int i,n=0,fd;
  6806. nullpo_retv(sd);
  6807. fd=sd->fd;
  6808. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6809. clif_displaymessage(fd, msg_txt(sd,666));
  6810. return;
  6811. }
  6812. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6813. WFIFOW(fd,0)=0x1a6;
  6814. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6815. if(sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL ||
  6816. sd->inventory_data[i]->type != IT_PETEGG ||
  6817. sd->inventory.u.items_inventory[i].amount <= 0)
  6818. continue;
  6819. WFIFOW(fd,n*2+4)=i+2;
  6820. n++;
  6821. }
  6822. WFIFOW(fd,2)=4+n*2;
  6823. WFIFOSET(fd,WFIFOW(fd,2));
  6824. sd->menuskill_id = SA_TAMINGMONSTER;
  6825. sd->menuskill_val = -1;
  6826. }
  6827. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6828. /// 01a4 <type>.B <id>.L <data>.L
  6829. /// type:
  6830. /// 0 = pre-init (data = 0)
  6831. /// 1 = intimacy (data = 0~4)
  6832. /// 2 = hunger (data = 0~4)
  6833. /// 3 = accessory
  6834. /// 4 = performance (data = 1~3: normal, 4: special)
  6835. /// 5 = hairstyle
  6836. ///
  6837. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6838. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6839. {
  6840. uint8 buf[16];
  6841. nullpo_retv(pd);
  6842. WBUFW(buf,0) = 0x1a4;
  6843. WBUFB(buf,2) = type;
  6844. WBUFL(buf,3) = pd->bl.id;
  6845. WBUFL(buf,7) = param;
  6846. if (sd)
  6847. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6848. else
  6849. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6850. }
  6851. /// Pet's base data (ZC_PROPERTY_PET).
  6852. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6853. void clif_send_petstatus(struct map_session_data *sd)
  6854. {
  6855. int fd;
  6856. struct s_pet *pet;
  6857. nullpo_retv(sd);
  6858. nullpo_retv(sd->pd);
  6859. fd=sd->fd;
  6860. pet = &sd->pd->pet;
  6861. WFIFOHEAD(fd,packet_len(0x1a2));
  6862. WFIFOW(fd,0)=0x1a2;
  6863. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  6864. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6865. WFIFOW(fd,27)=pet->level;
  6866. WFIFOW(fd,29)=pet->hungry;
  6867. WFIFOW(fd,31)=pet->intimate;
  6868. WFIFOW(fd,33)=pet->equip;
  6869. #if PACKETVER >= 20081126
  6870. WFIFOW(fd,35)=pet->class_;
  6871. #endif
  6872. WFIFOSET(fd,packet_len(0x1a2));
  6873. }
  6874. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6875. /// 01aa <id>.L <data>.L
  6876. /// data:
  6877. /// @see CZ_PET_ACT.
  6878. void clif_pet_emotion(struct pet_data *pd,int param)
  6879. {
  6880. unsigned char buf[16];
  6881. nullpo_retv(pd);
  6882. memset(buf,0,packet_len(0x1aa));
  6883. WBUFW(buf,0)=0x1aa;
  6884. WBUFL(buf,2)=pd->bl.id;
  6885. if(param >= 100 && pd->petDB->talk_convert_class) {
  6886. if(pd->petDB->talk_convert_class < 0)
  6887. return;
  6888. else if(pd->petDB->talk_convert_class > 0) {
  6889. // replace mob_id component of talk/act data
  6890. param -= (pd->pet.class_ - 100)*100;
  6891. param += (pd->petDB->talk_convert_class - 100)*100;
  6892. }
  6893. }
  6894. WBUFL(buf,6)=param;
  6895. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6896. }
  6897. /// Result of request to feed a pet (ZC_FEED_PET).
  6898. /// 01a3 <result>.B <name id>.W
  6899. /// result:
  6900. /// 0 = failure
  6901. /// 1 = success
  6902. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6903. {
  6904. int fd;
  6905. nullpo_retv(sd);
  6906. fd=sd->fd;
  6907. WFIFOHEAD(fd,packet_len(0x1a3));
  6908. WFIFOW(fd,0)=0x1a3;
  6909. WFIFOB(fd,2)=fail;
  6910. WFIFOW(fd,3)=foodid;
  6911. WFIFOSET(fd,packet_len(0x1a3));
  6912. }
  6913. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6914. /// 01cd { <skill id>.L }*7
  6915. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6916. {
  6917. int fd;
  6918. nullpo_retv(sd);
  6919. fd=sd->fd;
  6920. WFIFOHEAD(fd,packet_len(0x1cd));
  6921. WFIFOW(fd, 0)=0x1cd;
  6922. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6923. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6924. else
  6925. WFIFOL(fd,2)= 0x00000000;
  6926. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6927. WFIFOL(fd,6)= MG_COLDBOLT;
  6928. else
  6929. WFIFOL(fd,6)= 0x00000000;
  6930. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6931. WFIFOL(fd,10)= MG_FIREBOLT;
  6932. else
  6933. WFIFOL(fd,10)= 0x00000000;
  6934. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6935. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6936. else
  6937. WFIFOL(fd,14)= 0x00000000;
  6938. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6939. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6940. else
  6941. WFIFOL(fd,18)= 0x00000000;
  6942. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6943. WFIFOL(fd,22)= MG_FIREBALL;
  6944. else
  6945. WFIFOL(fd,22)= 0x00000000;
  6946. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6947. WFIFOL(fd,26)= MG_FROSTDIVER;
  6948. else
  6949. WFIFOL(fd,26)= 0x00000000;
  6950. WFIFOSET(fd,packet_len(0x1cd));
  6951. sd->menuskill_id = SA_AUTOSPELL;
  6952. sd->menuskill_val = skill_lv;
  6953. }
  6954. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6955. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6956. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6957. {
  6958. unsigned char buf[56];
  6959. nullpo_retv(src);
  6960. memset(buf,0,packet_len(0x1cf));
  6961. WBUFW(buf,0) = 0x1cf;
  6962. WBUFL(buf,2) = src->id;
  6963. if( src->type == BL_MER )
  6964. {
  6965. struct mercenary_data *md = BL_CAST(BL_MER,src);
  6966. if( md && md->master && md->devotion_flag )
  6967. WBUFL(buf,6) = md->master->bl.id;
  6968. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  6969. }
  6970. else
  6971. {
  6972. int i;
  6973. struct map_session_data *sd = BL_CAST(BL_PC,src);
  6974. if( sd == NULL )
  6975. return;
  6976. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  6977. WBUFL(buf,6+4*i) = sd->devotion[i];
  6978. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  6979. }
  6980. if( tsd )
  6981. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  6982. else
  6983. clif_send(buf, packet_len(0x1cf), src, AREA);
  6984. }
  6985. /*==========================================
  6986. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  6987. * Notifies clients in an area of an object's spirits.
  6988. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  6989. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  6990. *------------------------------------------*/
  6991. void clif_spiritball(struct block_list *bl) {
  6992. unsigned char buf[16];
  6993. TBL_PC *sd = BL_CAST(BL_PC,bl);
  6994. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  6995. nullpo_retv(bl);
  6996. WBUFW(buf, 0) = 0x1d0;
  6997. WBUFL(buf, 2) = bl->id;
  6998. WBUFW(buf, 6) = 0; //init to 0
  6999. switch(bl->type){
  7000. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  7001. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  7002. }
  7003. clif_send(buf, packet_len(0x1d0), bl, AREA);
  7004. }
  7005. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7006. /// 01d2 <account id>.L <delay>.L
  7007. void clif_combo_delay(struct block_list *bl,int wait)
  7008. {
  7009. unsigned char buf[32];
  7010. nullpo_retv(bl);
  7011. WBUFW(buf,0)=0x1d2;
  7012. WBUFL(buf,2)=bl->id;
  7013. WBUFL(buf,6)=wait;
  7014. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7015. }
  7016. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7017. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7018. /// flag:
  7019. /// 0 = inactive
  7020. /// 1 = active
  7021. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7022. {
  7023. unsigned char buf[32];
  7024. nullpo_retv(src);
  7025. WBUFW(buf,0)=0x1d1;
  7026. WBUFL(buf,2)=src->id;
  7027. WBUFL(buf,6)=dst_id;
  7028. WBUFL(buf,10)=active;
  7029. clif_send(buf,packet_len(0x1d1),src,AREA);
  7030. }
  7031. /// MVP effect (ZC_MVP).
  7032. /// 010c <account id>.L
  7033. void clif_mvp_effect(struct map_session_data *sd)
  7034. {
  7035. unsigned char buf[16];
  7036. nullpo_retv(sd);
  7037. WBUFW(buf,0)=0x10c;
  7038. WBUFL(buf,2)=sd->bl.id;
  7039. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7040. }
  7041. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7042. /// 010a <name id>.W
  7043. void clif_mvp_item(struct map_session_data *sd, unsigned short nameid)
  7044. {
  7045. int view,fd;
  7046. nullpo_retv(sd);
  7047. fd=sd->fd;
  7048. WFIFOHEAD(fd,packet_len(0x10a));
  7049. WFIFOW(fd,0)=0x10a;
  7050. if((view = itemdb_viewid(nameid)) > 0)
  7051. WFIFOW(fd,2)=view;
  7052. else
  7053. WFIFOW(fd,2)=nameid;
  7054. WFIFOSET(fd,packet_len(0x10a));
  7055. }
  7056. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7057. /// 010b <exp>.L
  7058. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp) {
  7059. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7060. if (battle_config.mvp_exp_reward_message) {
  7061. char e_msg[CHAT_SIZE_MAX];
  7062. sprintf(e_msg, msg_txt(sd, 717), exp);
  7063. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7064. }
  7065. #else
  7066. int fd;
  7067. nullpo_retv(sd);
  7068. fd = sd->fd;
  7069. WFIFOHEAD(fd, packet_len(0x10b));
  7070. WFIFOW(fd,0) = 0x10b;
  7071. WFIFOL(fd,2) = min(exp, (unsigned int)INT32_MAX);
  7072. WFIFOSET(fd, packet_len(0x10b));
  7073. #endif
  7074. }
  7075. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7076. /// 010d
  7077. ///
  7078. /// "You are the MVP, but cannot obtain the reward because
  7079. /// you are overweight."
  7080. void clif_mvp_noitem(struct map_session_data* sd)
  7081. {
  7082. int fd = sd->fd;
  7083. WFIFOHEAD(fd,packet_len(0x10d));
  7084. WFIFOW(fd,0) = 0x10d;
  7085. WFIFOSET(fd,packet_len(0x10d));
  7086. }
  7087. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7088. /// 0167 <result>.B
  7089. /// result:
  7090. /// 0 = "Guild has been created."
  7091. /// 1 = "You are already in a Guild."
  7092. /// 2 = "That Guild Name already exists."
  7093. /// 3 = "You need the neccessary item to create a Guild."
  7094. void clif_guild_created(struct map_session_data *sd,int flag)
  7095. {
  7096. int fd;
  7097. nullpo_retv(sd);
  7098. fd=sd->fd;
  7099. WFIFOHEAD(fd,packet_len(0x167));
  7100. WFIFOW(fd,0)=0x167;
  7101. WFIFOB(fd,2)=flag;
  7102. WFIFOSET(fd,packet_len(0x167));
  7103. }
  7104. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7105. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7106. /// mode:
  7107. /// &0x01 = allow invite
  7108. /// &0x10 = allow expel
  7109. void clif_guild_belonginfo(struct map_session_data *sd)
  7110. {
  7111. int ps,fd;
  7112. struct guild* g;
  7113. nullpo_retv(sd);
  7114. nullpo_retv(g = sd->guild);
  7115. fd=sd->fd;
  7116. ps=guild_getposition(sd);
  7117. WFIFOHEAD(fd,packet_len(0x16c));
  7118. WFIFOW(fd,0)=0x16c;
  7119. WFIFOL(fd,2)=g->guild_id;
  7120. WFIFOL(fd,6)=g->emblem_id;
  7121. WFIFOL(fd,10)=g->position[ps].mode;
  7122. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  7123. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  7124. safestrncpy(WFIFOCP(fd,19),g->name,NAME_LENGTH);
  7125. WFIFOSET(fd,packet_len(0x16c));
  7126. }
  7127. /// Guild member login notice.
  7128. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7129. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7130. /// status:
  7131. /// 0 = offline
  7132. /// 1 = online
  7133. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7134. {
  7135. unsigned char buf[64];
  7136. struct map_session_data* sd;
  7137. nullpo_retv(g);
  7138. WBUFW(buf, 0)=0x1f2;
  7139. WBUFL(buf, 2)=g->member[idx].account_id;
  7140. WBUFL(buf, 6)=g->member[idx].char_id;
  7141. WBUFL(buf,10)=flag;
  7142. if( ( sd = g->member[idx].sd ) != NULL )
  7143. {
  7144. WBUFW(buf,14) = sd->status.sex;
  7145. WBUFW(buf,16) = sd->status.hair;
  7146. WBUFW(buf,18) = sd->status.hair_color;
  7147. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7148. }
  7149. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7150. {
  7151. WBUFW(buf,14) = 0;
  7152. WBUFW(buf,16) = 0;
  7153. WBUFW(buf,18) = 0;
  7154. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7155. }
  7156. }
  7157. // Function `clif_guild_memberlogin_notice` sends info about
  7158. // logins and logouts of a guild member to the rest members.
  7159. // But at the 1st time (after a player login or map changing)
  7160. // the client won't show the message.
  7161. // So I suggest use this function for sending "first-time-info"
  7162. // to some player on entering the game or changing location.
  7163. // At next time the client would always show the message.
  7164. // The function sends all the statuses in the single packet
  7165. // to economize traffic. [LuzZza]
  7166. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7167. {
  7168. struct guild *g;
  7169. unsigned char buf[14*128];
  7170. int i, count=0, p_len;
  7171. nullpo_retv(sd);
  7172. p_len = packet_len(0x16d);
  7173. if(!(g = sd->guild))
  7174. return;
  7175. for(i=0; i<g->max_member; i++) {
  7176. if(g->member[i].account_id > 0 &&
  7177. g->member[i].account_id != sd->status.account_id) {
  7178. WBUFW(buf,count*p_len) = 0x16d;
  7179. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7180. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7181. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7182. count++;
  7183. }
  7184. }
  7185. clif_send(buf, p_len*count, &sd->bl, SELF);
  7186. }
  7187. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7188. /// 014e <menu flag>.L
  7189. /// menu flag:
  7190. /// 0x00 = Basic Info (always on)
  7191. /// &0x01 = Member manager
  7192. /// &0x02 = Positions
  7193. /// &0x04 = Skills
  7194. /// &0x10 = Expulsion list
  7195. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7196. /// &0x80 = Notice
  7197. void clif_guild_masterormember(struct map_session_data *sd)
  7198. {
  7199. int fd;
  7200. nullpo_retv(sd);
  7201. fd=sd->fd;
  7202. WFIFOHEAD(fd,packet_len(0x14e));
  7203. WFIFOW(fd,0) = 0x14e;
  7204. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7205. WFIFOSET(fd,packet_len(0x14e));
  7206. }
  7207. /// Guild basic information (Territories [Valaris])
  7208. /// 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)
  7209. /// 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)
  7210. /// 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)
  7211. void clif_guild_basicinfo(struct map_session_data *sd) {
  7212. int fd;
  7213. struct guild *g;
  7214. #if PACKETVER < 20160622
  7215. int cmd = 0x1b6;
  7216. int offset = NAME_LENGTH;
  7217. #else
  7218. int cmd = 0xa84;
  7219. int offset = 0;
  7220. #endif
  7221. nullpo_retv(sd);
  7222. fd = sd->fd;
  7223. if( (g = sd->guild) == NULL )
  7224. return;
  7225. WFIFOHEAD(fd,packet_len(cmd));
  7226. WFIFOW(fd, 0)=cmd;
  7227. WFIFOL(fd, 2)=g->guild_id;
  7228. WFIFOL(fd, 6)=g->guild_lv;
  7229. WFIFOL(fd,10)=g->connect_member;
  7230. WFIFOL(fd,14)=g->max_member;
  7231. WFIFOL(fd,18)=g->average_lv;
  7232. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  7233. WFIFOL(fd,26)=g->next_exp;
  7234. WFIFOL(fd,30)=0; // Tax Points
  7235. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7236. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7237. WFIFOL(fd,42)=g->emblem_id;
  7238. safestrncpy(WFIFOCP(fd,46),g->name, NAME_LENGTH);
  7239. #if PACKETVER < 20160622
  7240. safestrncpy(WFIFOCP(fd,70),g->master, NAME_LENGTH);
  7241. #endif
  7242. safestrncpy(WFIFOCP(fd,70+offset),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7243. WFIFOL(fd,70+offset+16) = 0; // zeny
  7244. #if PACKETVER >= 20160622
  7245. WFIFOL(fd,70+offset+20) = g->member[0].char_id; // leader
  7246. #endif
  7247. WFIFOSET(fd,packet_len(cmd));
  7248. }
  7249. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7250. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7251. void clif_guild_allianceinfo(struct map_session_data *sd)
  7252. {
  7253. int fd,i,c;
  7254. struct guild *g;
  7255. nullpo_retv(sd);
  7256. if( (g = sd->guild) == NULL )
  7257. return;
  7258. fd = sd->fd;
  7259. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7260. WFIFOW(fd, 0)=0x14c;
  7261. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7262. struct guild_alliance *a=&g->alliance[i];
  7263. if(a->guild_id>0){
  7264. WFIFOL(fd,c*32+4)=a->opposition;
  7265. WFIFOL(fd,c*32+8)=a->guild_id;
  7266. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7267. c++;
  7268. }
  7269. }
  7270. WFIFOW(fd, 2)=c*32+4;
  7271. WFIFOSET(fd,WFIFOW(fd,2));
  7272. }
  7273. /// Guild member manager information
  7274. /// 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)
  7275. /// state:
  7276. /// 0 = offline
  7277. /// 1 = online
  7278. /// memo:
  7279. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7280. /// 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)
  7281. void clif_guild_memberlist(struct map_session_data *sd)
  7282. {
  7283. int fd;
  7284. int i,c;
  7285. struct guild *g;
  7286. #if PACKETVER < 20161026
  7287. int cmd = 0x154;
  7288. int size = 104;
  7289. #else
  7290. int cmd = 0xaa5;
  7291. int size = 34;
  7292. #endif
  7293. nullpo_retv(sd);
  7294. if( (fd = sd->fd) == 0 )
  7295. return;
  7296. if( (g = sd->guild) == NULL )
  7297. return;
  7298. WFIFOHEAD(fd, g->max_member * size + 4);
  7299. WFIFOW(fd, 0)=cmd;
  7300. for(i=0,c=0;i<g->max_member;i++){
  7301. struct guild_member *m=&g->member[i];
  7302. if(m->account_id==0)
  7303. continue;
  7304. WFIFOL(fd,c*size+ 4)=m->account_id;
  7305. WFIFOL(fd,c*size+ 8)=m->char_id;
  7306. WFIFOW(fd,c*size+12)=m->hair;
  7307. WFIFOW(fd,c*size+14)=m->hair_color;
  7308. WFIFOW(fd,c*size+16)=m->gender;
  7309. WFIFOW(fd,c*size+18)=m->class_;
  7310. WFIFOW(fd,c*size+20)=m->lv;
  7311. WFIFOL(fd,c*size+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7312. WFIFOL(fd,c*size+26)=m->online;
  7313. WFIFOL(fd,c*size+30)=m->position;
  7314. #if PACKETVER < 20161026
  7315. 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.
  7316. safestrncpy(WFIFOCP(fd,c*size+84),m->name,NAME_LENGTH);
  7317. #else
  7318. WFIFOL(fd,c*size+34)=m->last_login;
  7319. #endif
  7320. c++;
  7321. }
  7322. WFIFOW(fd, 2)=c*size+4;
  7323. WFIFOSET(fd,WFIFOW(fd,2));
  7324. }
  7325. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7326. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7327. void clif_guild_positionnamelist(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 * 28 + 4);
  7336. WFIFOW(fd, 0)=0x166;
  7337. for(i=0;i<MAX_GUILDPOSITION;i++){
  7338. WFIFOL(fd,i*28+4)=i;
  7339. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7340. }
  7341. WFIFOW(fd,2)=i*28+4;
  7342. WFIFOSET(fd,WFIFOW(fd,2));
  7343. }
  7344. /// Guild position information (ZC_POSITION_INFO).
  7345. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7346. /// mode:
  7347. /// &0x01 = allow invite
  7348. /// &0x10 = allow expel
  7349. /// ranking:
  7350. /// TODO
  7351. void clif_guild_positioninfolist(struct map_session_data *sd)
  7352. {
  7353. int i,fd;
  7354. struct guild *g;
  7355. nullpo_retv(sd);
  7356. if( (g = sd->guild) == NULL )
  7357. return;
  7358. fd = sd->fd;
  7359. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7360. WFIFOW(fd, 0)=0x160;
  7361. for(i=0;i<MAX_GUILDPOSITION;i++){
  7362. struct guild_position *p=&g->position[i];
  7363. WFIFOL(fd,i*16+ 4)=i;
  7364. WFIFOL(fd,i*16+ 8)=p->mode;
  7365. WFIFOL(fd,i*16+12)=i;
  7366. WFIFOL(fd,i*16+16)=p->exp_mode;
  7367. }
  7368. WFIFOW(fd, 2)=i*16+4;
  7369. WFIFOSET(fd,WFIFOW(fd,2));
  7370. }
  7371. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7372. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7373. /// mode:
  7374. /// &0x01 = allow invite
  7375. /// &0x10 = allow expel
  7376. /// ranking:
  7377. /// TODO
  7378. void clif_guild_positionchanged(struct guild *g,int idx)
  7379. {
  7380. // FIXME: This packet is intended to update the clients after a
  7381. // commit of position info changes, not sending one packet per
  7382. // position.
  7383. struct map_session_data *sd;
  7384. unsigned char buf[128];
  7385. nullpo_retv(g);
  7386. WBUFW(buf, 0)=0x174;
  7387. WBUFW(buf, 2)=44; // packet len
  7388. // GUILD_REG_POSITION_INFO{
  7389. WBUFL(buf, 4)=idx;
  7390. WBUFL(buf, 8)=g->position[idx].mode;
  7391. WBUFL(buf,12)=idx;
  7392. WBUFL(buf,16)=g->position[idx].exp_mode;
  7393. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7394. // }*
  7395. if( (sd=guild_getavailablesd(g))!=NULL )
  7396. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7397. }
  7398. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7399. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7400. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7401. {
  7402. // FIXME: This packet is intended to update the clients after a
  7403. // commit of member position assignment changes, not sending one
  7404. // packet per position.
  7405. struct map_session_data *sd;
  7406. unsigned char buf[64];
  7407. nullpo_retv(g);
  7408. WBUFW(buf, 0)=0x156;
  7409. WBUFW(buf, 2)=16; // packet len
  7410. // MEMBER_POSITION_INFO{
  7411. WBUFL(buf, 4)=g->member[idx].account_id;
  7412. WBUFL(buf, 8)=g->member[idx].char_id;
  7413. WBUFL(buf,12)=g->member[idx].position;
  7414. // }*
  7415. if( (sd=guild_getavailablesd(g))!=NULL )
  7416. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7417. }
  7418. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7419. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7420. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7421. {
  7422. int fd;
  7423. nullpo_retv(sd);
  7424. nullpo_retv(g);
  7425. fd = sd->fd;
  7426. if( g->emblem_len <= 0 )
  7427. return;
  7428. WFIFOHEAD(fd,g->emblem_len+12);
  7429. WFIFOW(fd,0)=0x152;
  7430. WFIFOW(fd,2)=g->emblem_len+12;
  7431. WFIFOL(fd,4)=g->guild_id;
  7432. WFIFOL(fd,8)=g->emblem_id;
  7433. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7434. WFIFOSET(fd,WFIFOW(fd,2));
  7435. }
  7436. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7437. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7438. void clif_guild_emblem_area(struct block_list* bl)
  7439. {
  7440. uint8 buf[12];
  7441. nullpo_retv(bl);
  7442. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7443. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7444. WBUFW(buf,0) = 0x1b4;
  7445. WBUFL(buf,2) = bl->id;
  7446. WBUFL(buf,6) = status_get_guild_id(bl);
  7447. WBUFW(buf,10) = status_get_emblem_id(bl);
  7448. clif_send(buf, 12, bl, AREA_WOS);
  7449. }
  7450. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7451. /// 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 }*
  7452. void clif_guild_skillinfo(struct map_session_data* sd)
  7453. {
  7454. int fd;
  7455. struct guild* g;
  7456. int i,c;
  7457. nullpo_retv(sd);
  7458. if( (g = sd->guild) == NULL )
  7459. return;
  7460. fd = sd->fd;
  7461. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7462. WFIFOW(fd,0) = 0x0162;
  7463. WFIFOW(fd,4) = g->skill_point;
  7464. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7465. {
  7466. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7467. {
  7468. int id = g->skill[i].id;
  7469. int p = 6 + c*37;
  7470. WFIFOW(fd,p+0) = id;
  7471. WFIFOL(fd,p+2) = skill_get_inf(id);
  7472. WFIFOW(fd,p+6) = g->skill[i].lv;
  7473. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7474. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7475. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7476. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7477. c++;
  7478. }
  7479. }
  7480. WFIFOW(fd,2) = 6 + c*37;
  7481. WFIFOSET(fd,WFIFOW(fd,2));
  7482. }
  7483. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7484. /// 016f <subject>.60B <notice>.120B
  7485. void clif_guild_notice(struct map_session_data* sd)
  7486. {
  7487. int fd;
  7488. struct guild* g;
  7489. nullpo_retv(sd);
  7490. nullpo_retv(g = sd->guild);
  7491. fd = sd->fd;
  7492. if ( !session_isActive(fd) )
  7493. return;
  7494. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7495. return;
  7496. WFIFOHEAD(fd,packet_len(0x16f));
  7497. WFIFOW(fd,0) = 0x16f;
  7498. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7499. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7500. WFIFOSET(fd,packet_len(0x16f));
  7501. }
  7502. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7503. /// 016a <guild id>.L <guild name>.24B
  7504. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7505. {
  7506. int fd;
  7507. nullpo_retv(sd);
  7508. nullpo_retv(g);
  7509. fd=sd->fd;
  7510. WFIFOHEAD(fd,packet_len(0x16a));
  7511. WFIFOW(fd,0)=0x16a;
  7512. WFIFOL(fd,2)=g->guild_id;
  7513. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7514. WFIFOSET(fd,packet_len(0x16a));
  7515. }
  7516. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7517. /// 0169 <answer>.B
  7518. /// answer:
  7519. /// 0 = Already in guild.
  7520. /// 1 = Offer rejected.
  7521. /// 2 = Offer accepted.
  7522. /// 3 = Guild full.
  7523. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7524. {
  7525. int fd;
  7526. nullpo_retv(sd);
  7527. fd=sd->fd;
  7528. WFIFOHEAD(fd,packet_len(0x169));
  7529. WFIFOW(fd,0)=0x169;
  7530. WFIFOB(fd,2)=flag;
  7531. WFIFOSET(fd,packet_len(0x169));
  7532. }
  7533. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7534. /// 015a <char name>.24B <reason>.40B
  7535. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7536. {
  7537. unsigned char buf[128];
  7538. nullpo_retv(sd);
  7539. WBUFW(buf, 0)=0x15a;
  7540. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7541. memcpy(WBUFP(buf,26),mes,40);
  7542. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7543. }
  7544. /// Notifies clients of a guild of an expelled member.
  7545. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7546. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7547. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7548. {
  7549. unsigned char buf[128];
  7550. #if PACKETVER < 20100803
  7551. const unsigned short cmd = 0x15c;
  7552. #else
  7553. const unsigned short cmd = 0x839;
  7554. #endif
  7555. nullpo_retv(sd);
  7556. WBUFW(buf,0) = cmd;
  7557. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7558. safestrncpy(WBUFCP(buf,26), mes, 40);
  7559. #if PACKETVER < 20100803
  7560. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7561. #endif
  7562. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7563. }
  7564. /// Guild expulsion list (ZC_BAN_LIST).
  7565. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7566. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7567. void clif_guild_expulsionlist(struct map_session_data* sd)
  7568. {
  7569. #if PACKETVER < 20100803
  7570. const int offset = NAME_LENGTH*2+40;
  7571. #else
  7572. const int offset = NAME_LENGTH+40;
  7573. #endif
  7574. int fd, i, c = 0;
  7575. struct guild* g;
  7576. nullpo_retv(sd);
  7577. if( (g = sd->guild) == NULL )
  7578. return;
  7579. fd = sd->fd;
  7580. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7581. WFIFOW(fd,0) = 0x163;
  7582. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7583. {
  7584. struct guild_expulsion* e = &g->expulsion[i];
  7585. if( e->account_id > 0 )
  7586. {
  7587. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7588. #if PACKETVER < 20100803
  7589. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7590. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7591. #else
  7592. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7593. #endif
  7594. c++;
  7595. }
  7596. }
  7597. WFIFOW(fd,2) = 4 + c*offset;
  7598. WFIFOSET(fd,WFIFOW(fd,2));
  7599. }
  7600. /// Guild chat message (ZC_GUILD_CHAT).
  7601. /// 017f <packet len>.W <message>.?B
  7602. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7603. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7604. struct map_session_data *sd;
  7605. uint8 buf[256];
  7606. if( len == 0 )
  7607. {
  7608. return;
  7609. }
  7610. else if( len > sizeof(buf)-5 )
  7611. {
  7612. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7613. len = sizeof(buf)-5;
  7614. }
  7615. WBUFW(buf, 0) = 0x17f;
  7616. WBUFW(buf, 2) = len + 5;
  7617. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7618. if ((sd = guild_getavailablesd(g)) != NULL)
  7619. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7620. }
  7621. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7622. /// 0171 <inviter account id>.L <guild name>.24B
  7623. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7624. {
  7625. int fd;
  7626. nullpo_retv(sd);
  7627. fd=sd->fd;
  7628. WFIFOHEAD(fd,packet_len(0x171));
  7629. WFIFOW(fd,0)=0x171;
  7630. WFIFOL(fd,2)=account_id;
  7631. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7632. WFIFOSET(fd,packet_len(0x171));
  7633. }
  7634. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7635. /// 0173 <answer>.B
  7636. /// answer:
  7637. /// 0 = Already allied.
  7638. /// 1 = You rejected the offer.
  7639. /// 2 = You accepted the offer.
  7640. /// 3 = They have too any alliances.
  7641. /// 4 = You have too many alliances.
  7642. /// 5 = Alliances are disabled.
  7643. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7644. {
  7645. int fd;
  7646. nullpo_retv(sd);
  7647. fd=sd->fd;
  7648. WFIFOHEAD(fd,packet_len(0x173));
  7649. WFIFOW(fd,0)=0x173;
  7650. WFIFOL(fd,2)=flag;
  7651. WFIFOSET(fd,packet_len(0x173));
  7652. }
  7653. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7654. /// 0184 <other guild id>.L <relation>.L
  7655. /// relation:
  7656. /// 0 = Ally
  7657. /// 1 = Enemy
  7658. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7659. {
  7660. int fd;
  7661. nullpo_retv(sd);
  7662. fd = sd->fd;
  7663. if (fd <= 0)
  7664. return;
  7665. WFIFOHEAD(fd,packet_len(0x184));
  7666. WFIFOW(fd,0)=0x184;
  7667. WFIFOL(fd,2)=guild_id;
  7668. WFIFOL(fd,6)=flag;
  7669. WFIFOSET(fd,packet_len(0x184));
  7670. }
  7671. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7672. /// 0181 <result>.B
  7673. /// result:
  7674. /// 0 = Antagonist has been set.
  7675. /// 1 = Guild has too many Antagonists.
  7676. /// 2 = Already set as an Antagonist.
  7677. /// 3 = Antagonists are disabled.
  7678. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7679. {
  7680. int fd;
  7681. nullpo_retv(sd);
  7682. fd=sd->fd;
  7683. WFIFOHEAD(fd,packet_len(0x181));
  7684. WFIFOW(fd,0)=0x181;
  7685. WFIFOB(fd,2)=flag;
  7686. WFIFOSET(fd,packet_len(0x181));
  7687. }
  7688. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7689. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7690. /*
  7691. void clif_guild_allianceadded(struct guild *g,int idx)
  7692. {
  7693. unsigned char buf[64];
  7694. WBUFW(buf,0)=0x185;
  7695. WBUFL(buf,2)=g->alliance[idx].opposition;
  7696. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7697. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7698. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7699. }
  7700. */
  7701. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7702. /// 015e <reason>.L
  7703. /// 0 = success
  7704. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7705. /// 2 = there are still members in the guild
  7706. void clif_guild_broken(struct map_session_data *sd,int flag)
  7707. {
  7708. int fd;
  7709. nullpo_retv(sd);
  7710. fd=sd->fd;
  7711. WFIFOHEAD(fd,packet_len(0x15e));
  7712. WFIFOW(fd,0)=0x15e;
  7713. WFIFOL(fd,2)=flag;
  7714. WFIFOSET(fd,packet_len(0x15e));
  7715. }
  7716. /// Displays emotion on an object (ZC_EMOTION).
  7717. /// 00c0 <id>.L <type>.B
  7718. /// type:
  7719. /// enum emotion_type
  7720. void clif_emotion(struct block_list *bl,int type)
  7721. {
  7722. unsigned char buf[8];
  7723. nullpo_retv(bl);
  7724. WBUFW(buf,0)=0xc0;
  7725. WBUFL(buf,2)=bl->id;
  7726. WBUFB(buf,6)=type;
  7727. clif_send(buf,packet_len(0xc0),bl,AREA);
  7728. }
  7729. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7730. /// 0191 <id>.L <contents>.80B
  7731. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7732. {
  7733. unsigned char buf[MESSAGE_SIZE+6];
  7734. nullpo_retv(bl);
  7735. WBUFW(buf,0) = 0x191;
  7736. WBUFL(buf,2) = bl->id;
  7737. safestrncpy(WBUFCP(buf,6),talkie,MESSAGE_SIZE);
  7738. clif_send(buf,packet_len(0x191),bl,AREA);
  7739. }
  7740. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7741. /// 01ea <id>.L
  7742. void clif_wedding_effect(struct block_list *bl)
  7743. {
  7744. unsigned char buf[6];
  7745. nullpo_retv(bl);
  7746. WBUFW(buf,0) = 0x1ea;
  7747. WBUFL(buf,2) = bl->id;
  7748. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7749. }
  7750. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7751. /// 01e6 <partner name>.24B
  7752. void clif_callpartner(struct map_session_data *sd)
  7753. {
  7754. unsigned char buf[26];
  7755. nullpo_retv(sd);
  7756. WBUFW(buf,0) = 0x1e6;
  7757. if( sd->status.partner_id ) {
  7758. const char *p = map_charid2nick(sd->status.partner_id);
  7759. struct map_session_data *p_sd = pc_get_partner(sd);
  7760. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7761. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  7762. else
  7763. WBUFB(buf,2) = 0;
  7764. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7765. WBUFB(buf,2) = 0;
  7766. }
  7767. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7768. }
  7769. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7770. /// 01e4
  7771. /// This packet while still implemented by the client is no longer being officially used.
  7772. /*
  7773. void clif_marriage_process(struct map_session_data *sd)
  7774. {
  7775. int fd;
  7776. nullpo_retv(sd);
  7777. fd=sd->fd;
  7778. WFIFOHEAD(fd,packet_len(0x1e4));
  7779. WFIFOW(fd,0)=0x1e4;
  7780. WFIFOSET(fd,packet_len(0x1e4));
  7781. }
  7782. */
  7783. /// Notice of divorce (ZC_DIVORCE).
  7784. /// 0205 <partner name>.24B
  7785. void clif_divorced(struct map_session_data* sd, const char* name)
  7786. {
  7787. int fd;
  7788. nullpo_retv(sd);
  7789. fd=sd->fd;
  7790. WFIFOHEAD(fd,packet_len(0x205));
  7791. WFIFOW(fd,0)=0x205;
  7792. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7793. WFIFOSET(fd, packet_len(0x205));
  7794. }
  7795. /// Marriage proposal (ZC_REQ_COUPLE).
  7796. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7797. /// This packet while still implemented by the client is no longer being officially used.
  7798. /*
  7799. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7800. {
  7801. nullpo_retv(sd);
  7802. WFIFOHEAD(fd,packet_len(0x1e2));
  7803. WFIFOW(fd,0) = 0x1e2;
  7804. WFIFOL(fd,2) = ssd->status.account_id;
  7805. WFIFOL(fd,6) = ssd->status.char_id;
  7806. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7807. WFIFOSET(fd, packet_len(0x1e2));
  7808. }
  7809. */
  7810. /*==========================================
  7811. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7812. *------------------------------------------*/
  7813. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7814. {
  7815. unsigned char buf[256];
  7816. if( len == 0 ) {
  7817. return;
  7818. } else if( len > sizeof(buf)-5 ) {
  7819. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7820. len = sizeof(buf)-5;
  7821. }
  7822. WBUFW(buf, 0) = 0x17f;
  7823. WBUFW(buf, 2) = len + 5;
  7824. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7825. clif_send(buf, WBUFW(buf,2), src, target);
  7826. }
  7827. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7828. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7829. /// 00cd <result>.B
  7830. /// result:
  7831. /// 0 = failure
  7832. /// 1 = success
  7833. void clif_GM_kickack(struct map_session_data *sd, int id)
  7834. {
  7835. int fd;
  7836. nullpo_retv(sd);
  7837. fd = sd->fd;
  7838. WFIFOHEAD(fd,packet_len(0xcd));
  7839. WFIFOW(fd,0) = 0xcd;
  7840. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7841. WFIFOSET(fd, packet_len(0xcd));
  7842. }
  7843. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  7844. {
  7845. int fd;
  7846. nullpo_retv(tsd);
  7847. fd = tsd->fd;
  7848. if (sd == NULL)
  7849. tsd->state.keepshop = true;
  7850. if (fd > 0)
  7851. clif_authfail_fd(fd, 15);
  7852. else
  7853. map_quit(tsd);
  7854. if (sd)
  7855. clif_GM_kickack(sd, tsd->status.account_id);
  7856. }
  7857. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7858. /// 014a <result>.L
  7859. /// result:
  7860. /// 0 = "A manner point has been successfully aligned."
  7861. /// 1 = MP_FAILURE_EXHAUST
  7862. /// 2 = MP_FAILURE_ALREADY_GIVING
  7863. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7864. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7865. /// 5 = "You got a good point from %s."
  7866. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7867. {
  7868. int fd;
  7869. nullpo_retv(sd);
  7870. fd = sd->fd;
  7871. WFIFOHEAD(fd,packet_len(0x14a));
  7872. WFIFOW(fd,0) = 0x14a;
  7873. WFIFOL(fd,2) = type;
  7874. WFIFOSET(fd, packet_len(0x14a));
  7875. }
  7876. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7877. /// 014b <type>.B <GM name>.24B
  7878. /// type:
  7879. /// 0 = positive (unmute)
  7880. /// 1 = negative (mute)
  7881. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7882. {
  7883. int fd;
  7884. nullpo_retv(sd);
  7885. nullpo_retv(tsd);
  7886. fd = tsd->fd;
  7887. WFIFOHEAD(fd,packet_len(0x14b));
  7888. WFIFOW(fd,0) = 0x14b;
  7889. WFIFOB(fd,2) = type;
  7890. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  7891. WFIFOSET(fd, packet_len(0x14b));
  7892. }
  7893. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7894. /// 00d1 <type>.B <result>.B
  7895. /// type:
  7896. /// 0 = /ex (deny)
  7897. /// 1 = /in (allow)
  7898. /// result:
  7899. /// 0 = success
  7900. /// 1 = failure
  7901. /// 2 = too many blocks
  7902. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7903. {
  7904. int fd;
  7905. nullpo_retv(sd);
  7906. fd=sd->fd;
  7907. WFIFOHEAD(fd,packet_len(0xd1));
  7908. WFIFOW(fd,0)=0xd1;
  7909. WFIFOB(fd,2)=type;
  7910. WFIFOB(fd,3)=flag;
  7911. WFIFOSET(fd,packet_len(0xd1));
  7912. }
  7913. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7914. /// 00d2 <type>.B <result>.B
  7915. /// type:
  7916. /// 0 = /exall (deny)
  7917. /// 1 = /inall (allow)
  7918. /// result:
  7919. /// 0 = success
  7920. /// 1 = failure
  7921. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7922. {
  7923. int fd;
  7924. nullpo_retv(sd);
  7925. fd=sd->fd;
  7926. WFIFOHEAD(fd,packet_len(0xd2));
  7927. WFIFOW(fd,0)=0xd2;
  7928. WFIFOB(fd,2)=type;
  7929. WFIFOB(fd,3)=flag;
  7930. WFIFOSET(fd,packet_len(0xd2));
  7931. }
  7932. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7933. /// 07fe <bgm>.24B
  7934. void clif_playBGM(struct map_session_data* sd, const char* name)
  7935. {
  7936. int fd;
  7937. nullpo_retv(sd);
  7938. fd = sd->fd;
  7939. WFIFOHEAD(fd,packet_len(0x7fe));
  7940. WFIFOW(fd,0) = 0x7fe;
  7941. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7942. WFIFOSET(fd,packet_len(0x7fe));
  7943. }
  7944. /// Plays/stops a wave sound (ZC_SOUND).
  7945. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7946. /// file name:
  7947. /// relative to data\wav
  7948. /// act:
  7949. /// 0 = play (once)
  7950. /// 1 = play (repeat, does not work)
  7951. /// 2 = stops all sound instances of file name (does not work)
  7952. /// term:
  7953. /// unknown purpose, only relevant to act = 1
  7954. /// npc id:
  7955. /// The accustic direction of the sound is determined by the
  7956. /// relative position of the NPC to the player (3D sound).
  7957. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7958. {
  7959. int fd;
  7960. nullpo_retv(sd);
  7961. nullpo_retv(bl);
  7962. fd = sd->fd;
  7963. WFIFOHEAD(fd,packet_len(0x1d3));
  7964. WFIFOW(fd,0) = 0x1d3;
  7965. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7966. WFIFOB(fd,26) = type;
  7967. WFIFOL(fd,27) = 0;
  7968. WFIFOL(fd,31) = bl->id;
  7969. WFIFOSET(fd,packet_len(0x1d3));
  7970. }
  7971. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  7972. {
  7973. unsigned char buf[40];
  7974. nullpo_retv(bl);
  7975. WBUFW(buf,0) = 0x1d3;
  7976. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7977. WBUFB(buf,26) = type;
  7978. WBUFL(buf,27) = 0;
  7979. WBUFL(buf,31) = bl->id;
  7980. clif_send(buf, packet_len(0x1d3), bl, coverage);
  7981. }
  7982. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  7983. /// 01f3 <id>.L <effect id>.L
  7984. /// effect id:
  7985. /// @see doc/effect_list.txt
  7986. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  7987. {
  7988. unsigned char buf[24];
  7989. nullpo_retv(bl);
  7990. memset(buf, 0, packet_len(0x1f3));
  7991. WBUFW(buf,0) = 0x1f3;
  7992. WBUFL(buf,2) = bl->id;
  7993. WBUFL(buf,6) = type;
  7994. clif_send(buf, packet_len(0x1f3), bl, target);
  7995. if (disguised(bl)) {
  7996. WBUFL(buf,2) = -bl->id;
  7997. clif_send(buf, packet_len(0x1f3), bl, SELF);
  7998. }
  7999. }
  8000. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8001. {
  8002. WFIFOHEAD(fd,10);
  8003. WFIFOW(fd,0) = 0x1f3;
  8004. WFIFOL(fd,2) = bl->id;
  8005. WFIFOL(fd,6) = type;
  8006. WFIFOSET(fd,10);
  8007. }
  8008. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8009. /// 0284 <id>.L <effect id>.L <num data>.L
  8010. /// effect id:
  8011. /// @see doc/effect_list.txt
  8012. /// num data:
  8013. /// effect-dependent value
  8014. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8015. {
  8016. uint8 buf[14];
  8017. WBUFW(buf,0) = 0x284;
  8018. WBUFL(buf,2) = bl->id;
  8019. WBUFL(buf,6) = effect_id;
  8020. WBUFL(buf,10) = num;
  8021. clif_send(buf, packet_len(0x284), bl, target);
  8022. if( disguised(bl) )
  8023. {
  8024. WBUFL(buf,2) = -bl->id;
  8025. clif_send(buf, packet_len(0x284), bl, SELF);
  8026. }
  8027. }
  8028. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8029. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8030. 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) {
  8031. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8032. uint8 buf[CHAT_SIZE_MAX];
  8033. nullpo_retv(bl);
  8034. if (msg_len > sizeof(buf) - 12) {
  8035. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8036. msg_len = sizeof(buf) - 12;
  8037. }
  8038. if (rgb2bgr)
  8039. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8040. WBUFW(buf,0) = 0x2C1;
  8041. WBUFW(buf,2) = msg_len + 12;
  8042. WBUFL(buf,4) = bl->id;
  8043. WBUFL(buf,8) = color;
  8044. memcpy(WBUFCP(buf,12), msg, msg_len);
  8045. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8046. }
  8047. /**
  8048. * Notifies the client that the storage window is still open
  8049. *
  8050. * Should only be used in cases where the client closed the
  8051. * storage window without server's consent
  8052. */
  8053. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8054. // Notify the client that the storage is open
  8055. if( sd->state.storage_flag == 1 ) {
  8056. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8057. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8058. clif_updatestorageamount(sd, sd->storage.amount, MAX_STORAGE);
  8059. }
  8060. // Notify the client that the gstorage is open otherwise it will
  8061. // remain locked forever and nobody will be able to access it
  8062. if( sd->state.storage_flag == 2 ) {
  8063. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8064. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8065. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8066. else {
  8067. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8068. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8069. clif_updatestorageamount(sd, gstor->amount, MAX_GUILD_STORAGE);
  8070. }
  8071. }
  8072. }
  8073. // refresh the client's screen, getting rid of any effects
  8074. void clif_refresh(struct map_session_data *sd)
  8075. {
  8076. nullpo_retv(sd);
  8077. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8078. clif_inventorylist(sd);
  8079. if(pc_iscarton(sd)) {
  8080. clif_cartlist(sd);
  8081. clif_updatestatus(sd,SP_CARTINFO);
  8082. }
  8083. clif_updatestatus(sd,SP_WEIGHT);
  8084. clif_updatestatus(sd,SP_MAXWEIGHT);
  8085. clif_updatestatus(sd,SP_STR);
  8086. clif_updatestatus(sd,SP_AGI);
  8087. clif_updatestatus(sd,SP_VIT);
  8088. clif_updatestatus(sd,SP_INT);
  8089. clif_updatestatus(sd,SP_DEX);
  8090. clif_updatestatus(sd,SP_LUK);
  8091. if (sd->spiritball)
  8092. clif_spiritball_single(sd->fd, sd);
  8093. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8094. clif_spiritcharm_single(sd->fd, sd);
  8095. if (sd->vd.cloth_color)
  8096. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8097. if (sd->vd.body_style)
  8098. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8099. if(hom_is_active(sd->hd))
  8100. clif_send_homdata(sd,SP_ACK,0);
  8101. if( sd->md ) {
  8102. clif_mercenary_info(sd);
  8103. clif_mercenary_skillblock(sd);
  8104. }
  8105. if( sd->ed )
  8106. clif_elemental_info(sd);
  8107. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8108. clif_weather_check(sd);
  8109. if( sd->chatID )
  8110. chat_leavechat(sd,0);
  8111. if( sd->state.vending )
  8112. clif_openvending(sd, sd->bl.id, sd->vending);
  8113. if( pc_issit(sd) )
  8114. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8115. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8116. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8117. else
  8118. clif_changed_dir(&sd->bl, SELF);
  8119. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8120. //Issue #2143
  8121. //Cancel Trading State
  8122. if (sd->state.trading)
  8123. trade_tradecancel(sd);
  8124. //Cancel Buying/Selling State
  8125. if (sd->state.buyingstore)
  8126. buyingstore_close(sd);
  8127. mail_clear(sd);
  8128. if( disguised(&sd->bl) ) {/* refresh-da */
  8129. short disguise = sd->disguise;
  8130. pc_disguise(sd, 0);
  8131. pc_disguise(sd, disguise);
  8132. }
  8133. clif_refresh_storagewindow(sd);
  8134. }
  8135. /// Updates the object's (bl) name on client.
  8136. /// Used to update when a char leaves a party/guild. [Skotlex]
  8137. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8138. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8139. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8140. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8141. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8142. unsigned char buf[106];
  8143. int cmd = 0x95;
  8144. nullpo_retv(src);
  8145. nullpo_retv(bl);
  8146. WBUFW(buf,0) = cmd;
  8147. WBUFL(buf,2) = bl->id;
  8148. switch( bl->type )
  8149. {
  8150. case BL_PC:
  8151. {
  8152. struct map_session_data *sd = (struct map_session_data *)bl;
  8153. struct party_data *p = NULL;
  8154. #if PACKETVER >= 20150513
  8155. WBUFW(buf, 0) = cmd = 0xa30;
  8156. #else
  8157. WBUFW(buf, 0) = cmd = 0x195;
  8158. #endif
  8159. //Requesting your own "shadow" name. [Skotlex]
  8160. if( src == bl && target == SELF && sd->disguise ){
  8161. WBUFL(buf,2) = -bl->id;
  8162. }
  8163. if( sd->fakename[0] ) {
  8164. safestrncpy(WBUFCP(buf,6), sd->fakename, NAME_LENGTH);
  8165. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  8166. #if PACKETVER >= 20150513
  8167. WBUFL(buf,102) = 0; // Title ID
  8168. #endif
  8169. break;
  8170. }
  8171. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  8172. if( sd->status.party_id ){
  8173. p = party_search(sd->status.party_id);
  8174. }
  8175. // do not display party unless the player is also in a guild
  8176. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8177. safestrncpy(WBUFCP(buf,30), p->party.name, NAME_LENGTH);
  8178. }else{
  8179. WBUFB(buf,30) = 0;
  8180. }
  8181. if( sd->guild ){
  8182. int position;
  8183. // Will get the position of the guild the player is in
  8184. position = guild_getposition(sd);
  8185. safestrncpy(WBUFCP(buf,54), sd->guild->name,NAME_LENGTH);
  8186. safestrncpy(WBUFCP(buf,78), sd->guild->position[position].name, NAME_LENGTH);
  8187. }else{ //Assume no guild.
  8188. WBUFB(buf,54) = 0;
  8189. WBUFB(buf,78) = 0;
  8190. }
  8191. #if PACKETVER >= 20150513
  8192. WBUFL(buf,102) = sd->status.title_id; // Title ID
  8193. #endif
  8194. }
  8195. break;
  8196. //[blackhole89]
  8197. case BL_HOM:
  8198. safestrncpy(WBUFCP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  8199. break;
  8200. case BL_MER:
  8201. safestrncpy(WBUFCP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  8202. break;
  8203. case BL_PET:
  8204. safestrncpy(WBUFCP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  8205. break;
  8206. case BL_NPC:
  8207. safestrncpy(WBUFCP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  8208. break;
  8209. case BL_MOB:
  8210. {
  8211. struct mob_data *md = (struct mob_data *)bl;
  8212. nullpo_retv(md);
  8213. safestrncpy(WBUFCP(buf,6), md->name, NAME_LENGTH);
  8214. if( md->guardian_data && md->guardian_data->guild_id )
  8215. {
  8216. #if PACKETVER >= 20150513
  8217. WBUFW(buf, 0) = cmd = 0xa30;
  8218. #else
  8219. WBUFW(buf, 0) = cmd = 0x195;
  8220. #endif
  8221. WBUFB(buf,30) = 0;
  8222. safestrncpy(WBUFCP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  8223. safestrncpy(WBUFCP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  8224. }
  8225. else if( battle_config.show_mob_info )
  8226. {
  8227. char mobhp[50], *str_p = mobhp;
  8228. #if PACKETVER >= 20150513
  8229. WBUFW(buf, 0) = cmd = 0xa30;
  8230. #else
  8231. WBUFW(buf, 0) = cmd = 0x195;
  8232. #endif
  8233. if( battle_config.show_mob_info&4 )
  8234. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  8235. if( battle_config.show_mob_info&1 )
  8236. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  8237. if( battle_config.show_mob_info&2 )
  8238. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  8239. //Even thought mobhp ain't a name, we send it as one so the client
  8240. //can parse it. [Skotlex]
  8241. if( str_p != mobhp )
  8242. {
  8243. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8244. safestrncpy(WBUFCP(buf,30), mobhp, NAME_LENGTH);
  8245. WBUFB(buf,54) = 0;
  8246. WBUFB(buf,78) = 0;
  8247. }
  8248. }
  8249. #if PACKETVER >= 20150513
  8250. WBUFL(buf, 102) = 0; // Title ID
  8251. #endif
  8252. }
  8253. break;
  8254. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  8255. // safestrncpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  8256. // break;
  8257. return;
  8258. case BL_ELEM:
  8259. safestrncpy(WBUFCP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  8260. break;
  8261. default:
  8262. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8263. return;
  8264. }
  8265. clif_send(buf, packet_len(cmd), src, target);
  8266. }
  8267. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8268. /// 01ff <id>.L <x>.W <y>.W
  8269. ///
  8270. /// Visually moves(instant) a character to x,y. The char moves even
  8271. /// when the target cell isn't walkable. If the char is sitting it
  8272. /// stays that way.
  8273. void clif_slide(struct block_list *bl, int x, int y)
  8274. {
  8275. unsigned char buf[10];
  8276. nullpo_retv(bl);
  8277. WBUFW(buf, 0) = 0x01ff;
  8278. WBUFL(buf, 2) = bl->id;
  8279. WBUFW(buf, 6) = x;
  8280. WBUFW(buf, 8) = y;
  8281. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8282. if( disguised(bl) )
  8283. {
  8284. WBUFL(buf,2) = -bl->id;
  8285. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8286. }
  8287. }
  8288. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8289. /// 008d <packet len>.W <id>.L <message>.?B
  8290. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8291. {
  8292. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8293. int len_mes = strlen(mes)+1; //Account for \0
  8294. if (len_mes > sizeof(buf)-8) {
  8295. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8296. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8297. }
  8298. // send message to others
  8299. if (flag == AREA) {
  8300. WBUFW(buf,0) = 0x8d;
  8301. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8302. WBUFL(buf,4) = bl->id;
  8303. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8304. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8305. }
  8306. // send back message to the speaker
  8307. if( bl->type == BL_PC ) {
  8308. WBUFW(buf,0) = 0x8e;
  8309. WBUFW(buf, 2) = len_mes + 4;
  8310. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8311. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8312. }
  8313. }
  8314. /*==========================
  8315. * Minimap fix [Kevin]
  8316. * Remove dot from minimap
  8317. *--------------------------*/
  8318. void clif_party_xy_remove(struct map_session_data *sd)
  8319. {
  8320. unsigned char buf[16];
  8321. nullpo_retv(sd);
  8322. WBUFW(buf,0)=0x107;
  8323. WBUFL(buf,2)=sd->status.account_id;
  8324. WBUFW(buf,6)=-1;
  8325. WBUFW(buf,8)=-1;
  8326. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8327. }
  8328. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8329. /// 0215 <msg id>.L
  8330. /// msg id:
  8331. /// 0x15 = End all negative status (PA_GOSPEL)
  8332. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8333. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8334. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8335. /// 0x19 = All stats +20 (PA_GOSPEL)
  8336. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8337. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8338. /// 0x1e = DEF +25% (PA_GOSPEL)
  8339. /// 0x1f = ATK +100% (PA_GOSPEL)
  8340. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8341. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8342. /// ? = nothing
  8343. void clif_gospel_info(struct map_session_data *sd, int type)
  8344. {
  8345. int fd=sd->fd;
  8346. WFIFOHEAD(fd,packet_len(0x215));
  8347. WFIFOW(fd,0)=0x215;
  8348. WFIFOL(fd,2)=type;
  8349. WFIFOSET(fd, packet_len(0x215));
  8350. }
  8351. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8352. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8353. /// result:
  8354. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8355. /// star:
  8356. /// 0 = Place of the Sun
  8357. /// 1 = Place of the Moon
  8358. /// 2 = Place of the Stars
  8359. /// 1 = Star Gladiator %s's %s: <mapname>
  8360. /// star:
  8361. /// 0 = Place of the Sun
  8362. /// 1 = Place of the Moon
  8363. /// 2 = Place of the Stars
  8364. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8365. /// star:
  8366. /// 0 = Target of the Sun
  8367. /// 1 = Target of the Moon
  8368. /// 2 = Target of the Stars
  8369. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8370. /// star:
  8371. /// 0 = Monster of the Sun
  8372. /// 1 = Monster of the Moon
  8373. /// 2 = Monster of the Stars
  8374. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8375. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8376. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8377. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8378. /// 40 = Target HP : <monster_id used as HP>
  8379. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8380. {
  8381. int fd = sd->fd;
  8382. WFIFOHEAD(fd,packet_len(0x20e));
  8383. WFIFOW(fd,0) = 0x20e;
  8384. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8385. WFIFOL(fd,26) = monster_id;
  8386. WFIFOB(fd,30) = star;
  8387. WFIFOB(fd,31) = result;
  8388. WFIFOSET(fd,packet_len(0x20e));
  8389. }
  8390. /*==========================================
  8391. * Info about Star Glaldiator save map [Komurka]
  8392. * type: 1: Information, 0: Map registered
  8393. *------------------------------------------*/
  8394. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8395. {
  8396. char mapname[MAP_NAME_LENGTH_EXT];
  8397. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8398. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8399. }
  8400. /*==========================================
  8401. * Info about Star Glaldiator hate mob [Komurka]
  8402. * type: 1: Register mob, 0: Information.
  8403. *------------------------------------------*/
  8404. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8405. {
  8406. if( pcdb_checkid(class_) ) {
  8407. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8408. } else if( mobdb_checkid(class_) ) {
  8409. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  8410. } else {
  8411. 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);
  8412. }
  8413. }
  8414. /*==========================================
  8415. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8416. *------------------------------------------*/
  8417. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8418. {
  8419. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  8420. }
  8421. /*==========================================
  8422. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8423. *------------------------------------------*/
  8424. void clif_feel_hate_reset(struct map_session_data *sd)
  8425. {
  8426. clif_starskill(sd, "", 0, 0, 30);
  8427. }
  8428. /// Equip window (un)tick ack (ZC_CONFIG).
  8429. /// 02d9 <type>.L <value>.L
  8430. /// type:
  8431. /// 0 = open equip window
  8432. /// value:
  8433. /// 0 = disabled
  8434. /// 1 = enabled
  8435. void clif_equiptickack(struct map_session_data* sd, int flag)
  8436. {
  8437. int fd;
  8438. nullpo_retv(sd);
  8439. fd = sd->fd;
  8440. WFIFOHEAD(fd, packet_len(0x2d9));
  8441. WFIFOW(fd, 0) = 0x2d9;
  8442. WFIFOL(fd, 2) = 0;
  8443. WFIFOL(fd, 6) = flag;
  8444. WFIFOSET(fd, packet_len(0x2d9));
  8445. }
  8446. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8447. /// 02da <open equip window>.B
  8448. /// open equip window:
  8449. /// 0 = disabled
  8450. /// 1 = enabled
  8451. void clif_equipcheckbox(struct map_session_data* sd)
  8452. {
  8453. int fd;
  8454. nullpo_retv(sd);
  8455. fd = sd->fd;
  8456. WFIFOHEAD(fd, packet_len(0x2da));
  8457. WFIFOW(fd, 0) = 0x2da;
  8458. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8459. WFIFOSET(fd, packet_len(0x2da));
  8460. }
  8461. /// Sends info about a player's equipped items.
  8462. /// 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)
  8463. /// 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)
  8464. /// 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)
  8465. /// 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)
  8466. /// 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)
  8467. /// 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)
  8468. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  8469. {
  8470. uint8* buf;
  8471. int i, n, fd, offset = 0;
  8472. #if PACKETVER < 20100629
  8473. const int s = 26;
  8474. #elif PACKETVER < 20120925
  8475. const int s = 28;
  8476. #elif PACKETVER < 20150225
  8477. const int s = 31;
  8478. #else
  8479. const int s = 57;
  8480. #endif
  8481. nullpo_retv(sd);
  8482. nullpo_retv(tsd);
  8483. fd = sd->fd;
  8484. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  8485. buf = WFIFOP(fd,0);
  8486. #if PACKETVER < 20101124
  8487. WBUFW(buf, 0) = 0x2d7;
  8488. #elif PACKETVER < 20120925
  8489. WBUFW(buf, 0) = 0x859;
  8490. #elif PACKETVER < 20150225
  8491. WBUFW(buf, 0) = 0x997;
  8492. #else
  8493. WBUFW(buf, 0) = 0xa2d;
  8494. #endif
  8495. safestrncpy(WBUFCP(buf, 4), tsd->status.name, NAME_LENGTH);
  8496. WBUFW(buf,28) = tsd->status.class_;
  8497. WBUFW(buf,30) = tsd->vd.hair_style;
  8498. WBUFW(buf,32) = tsd->vd.head_bottom;
  8499. WBUFW(buf,34) = tsd->vd.head_mid;
  8500. WBUFW(buf,36) = tsd->vd.head_top;
  8501. #if PACKETVER >= 20110111
  8502. WBUFW(buf,38) = tsd->vd.robe;
  8503. offset+= 2;
  8504. buf = WBUFP(buf,2);
  8505. #endif
  8506. WBUFW(buf,38) = tsd->vd.hair_color;
  8507. WBUFW(buf,40) = tsd->vd.cloth_color;
  8508. WBUFB(buf,42) = tsd->vd.sex;
  8509. for(i=0,n=0; i < MAX_INVENTORY; i++)
  8510. {
  8511. if (tsd->inventory.u.items_inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  8512. continue;
  8513. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  8514. continue;
  8515. // Add item info : refine, identify flag, element, etc.
  8516. 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));
  8517. n++;
  8518. }
  8519. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  8520. WFIFOSET(fd, WFIFOW(fd, 2));
  8521. }
  8522. /// Display msgstringtable.txt string (ZC_MSG).
  8523. /// 0291 <message>.W
  8524. void clif_msg(struct map_session_data* sd, unsigned short id)
  8525. {
  8526. int fd;
  8527. nullpo_retv(sd);
  8528. fd = sd->fd;
  8529. WFIFOHEAD(fd, packet_len(0x291));
  8530. WFIFOW(fd, 0) = 0x291;
  8531. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8532. WFIFOSET(fd, packet_len(0x291));
  8533. }
  8534. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8535. /// 0x7e2 <message>.W <value>.L
  8536. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8537. {
  8538. int fd = sd->fd;
  8539. WFIFOHEAD(fd, packet_len(0x7e2));
  8540. WFIFOW(fd,0) = 0x7e2;
  8541. WFIFOW(fd,2) = id;
  8542. WFIFOL(fd,4) = value;
  8543. WFIFOSET(fd, packet_len(0x7e2));
  8544. }
  8545. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8546. /// 07e6 <skill id>.W <msg id>.L
  8547. ///
  8548. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8549. /// "[SkillName] Message"
  8550. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8551. {
  8552. int fd = sd->fd;
  8553. WFIFOHEAD(fd, packet_len(0x7e6));
  8554. WFIFOW(fd,0) = 0x7e6;
  8555. WFIFOW(fd,2) = skill_id;
  8556. WFIFOL(fd,4) = msg_id;
  8557. WFIFOSET(fd, packet_len(0x7e6));
  8558. }
  8559. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8560. /// Returns true if the packet was parsed successfully.
  8561. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8562. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8563. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8564. const char* seperator = " : ";
  8565. int fd;
  8566. struct s_packet_db* info;
  8567. uint16 packetLength, inputLength;
  8568. const char *input, *name, *message;
  8569. size_t nameLength, messageLength;
  8570. fd = sd->fd;
  8571. info = &packet_db[RFIFOW(fd,0)];
  8572. packetLength = RFIFOW(fd,info->pos[0]);
  8573. input = RFIFOCP(fd,info->pos[1]);
  8574. // basic structure check for the 4-byte header
  8575. if( packetLength < 4 ){
  8576. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8577. return false;
  8578. }else{
  8579. inputLength = packetLength - 4;
  8580. }
  8581. // process <name> part of the packet
  8582. if( whisperFormat ) {
  8583. // name has fixed width
  8584. if( inputLength < NAME_LENGTH + 1 ) {
  8585. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8586. return false;
  8587. }
  8588. name = input;
  8589. // validate name
  8590. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8591. // only restriction is that the name must be zero-terminated
  8592. if( name[nameLength] != '\0' ) {
  8593. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8594. return false;
  8595. }
  8596. message = input + NAME_LENGTH;
  8597. messageLength = inputLength - NAME_LENGTH;
  8598. }else{
  8599. // name and message are separated by ' : '
  8600. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8601. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8602. // check if there's enough data provided
  8603. if( inputLength < nameLength + seperatorLength + 1 ){
  8604. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8605. return false;
  8606. }
  8607. name = input;
  8608. // validate name
  8609. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8610. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8611. {
  8612. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8613. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8614. set_eof(sd->fd); // Just kick them out to correct it.
  8615. return false;
  8616. }
  8617. message = input + nameLength + seperatorLength;
  8618. messageLength = inputLength - nameLength - seperatorLength;
  8619. }
  8620. #if PACKETVER < 20151001
  8621. // the declared length must match real length
  8622. if( messageLength != strnlen(message, messageLength)+1 ) {
  8623. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8624. return false;
  8625. }
  8626. // verify <message> part of the packet
  8627. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8628. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8629. return false;
  8630. }
  8631. #else
  8632. // No zero termination anymore
  8633. messageLength += 1;
  8634. #endif
  8635. // messages mustn't be too long
  8636. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8637. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8638. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8639. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8640. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8641. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8642. return false;
  8643. }
  8644. // If it is not a whisper message, set the name to the fakename of the player
  8645. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8646. strcpy( out_name, sd->fakename );
  8647. }else{
  8648. safestrncpy( out_name, name, nameLength + 1 );
  8649. }
  8650. safestrncpy( out_message, message, messageLength );
  8651. if( whisperFormat ){
  8652. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8653. out_full_message[nameLength] = '\0';
  8654. }else{
  8655. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8656. }
  8657. if( is_atcommand( fd, sd, out_message, 1 ) )
  8658. return false;
  8659. if (sd->sc.cant.chat)
  8660. return false; //no "chatting" while muted.
  8661. if( battle_config.min_chat_delay ) { //[Skotlex]
  8662. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8663. return false;
  8664. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8665. }
  8666. if (battle_config.idletime_option&IDLE_CHAT)
  8667. sd->idletime = last_tick;
  8668. return true;
  8669. }
  8670. /**
  8671. * Displays a message if the player enters a PK Zone (during pk_mode)
  8672. * @param sd: Player data
  8673. */
  8674. inline void clif_pk_mode_message(struct map_session_data * sd)
  8675. {
  8676. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8677. sd && map[sd->bl.m].flag.pvp) {
  8678. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8679. char output[CHAT_SIZE_MAX];
  8680. // 1504: You've entered a PK Zone (safe until level %d).
  8681. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8682. battle_config.pk_min_level);
  8683. clif_showscript(&sd->bl, output, SELF);
  8684. } else {
  8685. // 1503: You've entered a PK Zone.
  8686. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8687. }
  8688. }
  8689. return;
  8690. }
  8691. // ---------------------
  8692. // clif_parse_wanttoconnect
  8693. // ---------------------
  8694. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8695. // error codes:
  8696. // 0 - Success
  8697. // 1 - Unknown packet_ver
  8698. // 2 - Invalid account_id
  8699. // 3 - Invalid char_id
  8700. // 4 - Invalid login_id1 (reserved)
  8701. // 5 - Invalid client_tick (reserved)
  8702. // 6 - Invalid sex
  8703. // Only the first 'invalid' error that appears is used.
  8704. static int clif_parse_WantToConnection_sub(int fd)
  8705. {
  8706. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8707. unsigned short cmd;
  8708. //By default, start searching on the default one.
  8709. cmd = RFIFOW(fd, 0);
  8710. packet_len = RFIFOREST(fd);
  8711. // FIXME: If the packet is not received at once, this will FAIL.
  8712. // Figure out, when it happens, that only part of the packet is
  8713. // received, or fix the function to be able to deal with that
  8714. // case.
  8715. if( packet_len != packet_db[cmd].len )
  8716. return 1; /* wrong length */
  8717. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8718. return 2; /* invalid account_id */
  8719. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8720. return 3; /* invalid char_id */
  8721. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8722. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8723. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8724. return 6; /* invalid sex */
  8725. else
  8726. return 0;
  8727. }
  8728. /// Request to connect to map-server.
  8729. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8730. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8731. /// There are various variants of this packet, some of them have padding between fields.
  8732. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8733. {
  8734. struct block_list* bl;
  8735. struct auth_node* node;
  8736. int cmd, account_id, char_id, login_id1, sex, err;
  8737. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8738. if (sd) {
  8739. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8740. return;
  8741. }
  8742. cmd = RFIFOW(fd, 0);
  8743. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8744. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8745. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8746. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8747. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8748. err = clif_parse_WantToConnection_sub(fd);
  8749. if( err ){ // connection rejected
  8750. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8751. err == 1 ? "." :
  8752. err == 2 ? ", possibly for having an invalid account_id." :
  8753. err == 3 ? ", possibly for having an invalid char_id." :
  8754. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8755. err == 4 ? ", possibly for having an invalid login_id1." :
  8756. err == 5 ? ", possibly for having an invalid client_tick." :
  8757. */
  8758. err == 6 ? ", possibly for having an invalid sex." :
  8759. ". ERROR invalid error code"));
  8760. WFIFOHEAD(fd,packet_len(0x6a));
  8761. WFIFOW(fd,0) = 0x6a;
  8762. WFIFOB(fd,2) = err;
  8763. WFIFOSET(fd,packet_len(0x6a));
  8764. #ifdef DUMP_INVALID_PACKET
  8765. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8766. #endif
  8767. RFIFOSKIP(fd, RFIFOREST(fd));
  8768. set_eof(fd);
  8769. return;
  8770. }
  8771. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8772. clif_authfail_fd(fd,1);// server closed
  8773. return;
  8774. }
  8775. //Check for double login.
  8776. bl = map_id2bl(account_id);
  8777. if(bl && bl->type != BL_PC) {
  8778. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8779. WFIFOHEAD(fd,packet_len(0x6a));
  8780. WFIFOW(fd,0) = 0x6a;
  8781. WFIFOB(fd,2) = 3; // Rejected by server
  8782. WFIFOSET(fd,packet_len(0x6a));
  8783. set_eof(fd);
  8784. return;
  8785. }
  8786. if (bl ||
  8787. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8788. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8789. {
  8790. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8791. return;
  8792. }
  8793. CREATE(sd, TBL_PC, 1);
  8794. sd->fd = fd;
  8795. #ifdef PACKET_OBFUSCATION
  8796. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8797. #endif
  8798. session[fd]->session_data = sd;
  8799. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8800. #if PACKETVER < 20070521
  8801. WFIFOHEAD(fd,4);
  8802. WFIFOL(fd,0) = sd->bl.id;
  8803. WFIFOSET(fd,4);
  8804. #else
  8805. WFIFOHEAD(fd,packet_len(0x283));
  8806. WFIFOW(fd,0) = 0x283;
  8807. WFIFOL(fd,2) = sd->bl.id;
  8808. WFIFOSET(fd,packet_len(0x283));
  8809. #endif
  8810. chrif_authreq(sd,false);
  8811. }
  8812. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8813. /// 007d
  8814. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8815. {
  8816. bool guild_notice = false;
  8817. if(sd->bl.prev != NULL)
  8818. return;
  8819. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  8820. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  8821. //Let pc_reg_received or intif_parse_StorageReceived reinvoke this when ready.
  8822. sd->state.connect_new = 0;
  8823. return;
  8824. }
  8825. if (sd->state.rewarp) { //Rewarp player.
  8826. sd->state.rewarp = 0;
  8827. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8828. return;
  8829. }
  8830. sd->state.warping = 0;
  8831. // look
  8832. #if PACKETVER < 4
  8833. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8834. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8835. #else
  8836. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8837. #endif
  8838. pc_set_costume_view(sd);
  8839. if(sd->vd.cloth_color)
  8840. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8841. if(sd->vd.body_style)
  8842. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8843. // item
  8844. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8845. pc_checkitem(sd);
  8846. // cart
  8847. if(pc_iscarton(sd)) {
  8848. clif_cartlist(sd);
  8849. clif_updatestatus(sd,SP_CARTINFO);
  8850. }
  8851. // weight
  8852. clif_updatestatus(sd,SP_WEIGHT);
  8853. clif_updatestatus(sd,SP_MAXWEIGHT);
  8854. // guild
  8855. // (needs to go before clif_spawn() to show guild emblems correctly)
  8856. if(sd->status.guild_id)
  8857. guild_send_memberinfoshort(sd,1);
  8858. if(battle_config.pc_invincible_time > 0) {
  8859. if(map_flag_gvg(sd->bl.m))
  8860. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8861. else
  8862. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8863. }
  8864. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  8865. map_spawnmobs(sd->bl.m);
  8866. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  8867. map[sd->bl.m].users_pvp++;
  8868. }
  8869. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8870. // reset the callshop flag if the player changes map
  8871. sd->state.callshop = 0;
  8872. if(map_addblock(&sd->bl))
  8873. return;
  8874. clif_spawn(&sd->bl);
  8875. // Party
  8876. // (needs to go after clif_spawn() to show hp bars correctly)
  8877. if(sd->status.party_id) {
  8878. party_send_movemap(sd);
  8879. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8880. }
  8881. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8882. if(map[sd->bl.m].flag.pvp && !pc_isinvisible(sd)) {
  8883. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8884. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  8885. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8886. sd->pvp_rank = 0;
  8887. sd->pvp_lastusers = 0;
  8888. sd->pvp_point = 5;
  8889. sd->pvp_won = 0;
  8890. sd->pvp_lost = 0;
  8891. }
  8892. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8893. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8894. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8895. else if (map[sd->bl.m].flag.gvg_dungeon)
  8896. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  8897. else if( map_flag_gvg(sd->bl.m) )
  8898. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  8899. else
  8900. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  8901. // info about nearby objects
  8902. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8903. 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);
  8904. // pet
  8905. if( sd->pd ) {
  8906. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  8907. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8908. pet_menu(sd, 3); //Option 3 is return to egg.
  8909. } else {
  8910. if(map_addblock(&sd->pd->bl))
  8911. return;
  8912. clif_spawn(&sd->pd->bl);
  8913. clif_send_petdata(sd,sd->pd,0,0);
  8914. clif_send_petstatus(sd);
  8915. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8916. }
  8917. }
  8918. //homunculus [blackhole89]
  8919. if( hom_is_active(sd->hd) ) {
  8920. if(map_addblock(&sd->hd->bl))
  8921. return;
  8922. clif_spawn(&sd->hd->bl);
  8923. clif_send_homdata(sd,SP_ACK,0);
  8924. clif_hominfo(sd,sd->hd,1);
  8925. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8926. clif_homskillinfoblock(sd);
  8927. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  8928. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8929. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8930. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8931. }
  8932. if( sd->md ) {
  8933. if(map_addblock(&sd->md->bl))
  8934. return;
  8935. clif_spawn(&sd->md->bl);
  8936. clif_mercenary_info(sd);
  8937. clif_mercenary_skillblock(sd);
  8938. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8939. }
  8940. if( sd->ed ) {
  8941. if (map_addblock(&sd->ed->bl))
  8942. return;
  8943. clif_spawn(&sd->ed->bl);
  8944. clif_elemental_info(sd);
  8945. clif_elemental_updatestatus(sd,SP_HP);
  8946. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8947. clif_elemental_updatestatus(sd,SP_SP);
  8948. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8949. }
  8950. if(sd->state.connect_new) {
  8951. int lv;
  8952. guild_notice = true;
  8953. clif_skillinfoblock(sd);
  8954. clif_hotkeys_send(sd);
  8955. clif_updatestatus(sd,SP_BASEEXP);
  8956. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8957. clif_updatestatus(sd,SP_JOBEXP);
  8958. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8959. clif_updatestatus(sd,SP_SKILLPOINT);
  8960. clif_initialstatus(sd);
  8961. if (sd->sc.option&OPTION_FALCON)
  8962. clif_status_load(&sd->bl, SI_FALCON, 1);
  8963. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  8964. clif_status_load(&sd->bl, SI_RIDING, 1);
  8965. else if (sd->sc.option&OPTION_WUGRIDER)
  8966. clif_status_load(&sd->bl, SI_WUGRIDER, 1);
  8967. else if (sd->sc.data[SC_ALL_RIDING])
  8968. clif_status_load(&sd->bl, SI_ALL_RIDING, 1);
  8969. if(sd->status.manner < 0)
  8970. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  8971. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  8972. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  8973. if(sd->bl.m == sd->feel_map[0].m
  8974. || sd->bl.m == sd->feel_map[1].m
  8975. || sd->bl.m == sd->feel_map[2].m)
  8976. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  8977. }
  8978. if(sd->pd && sd->pd->pet.intimate > 900)
  8979. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  8980. if(hom_is_active(sd->hd))
  8981. hom_init_timers(sd->hd);
  8982. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  8983. sd->state.night = 1;
  8984. clif_status_load(&sd->bl, SI_NIGHT, 1);
  8985. }
  8986. // Notify everyone that this char logged in [Skotlex].
  8987. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  8988. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  8989. //Login Event
  8990. npc_script_event(sd, NPCE_LOGIN);
  8991. }
  8992. } else {
  8993. //For some reason the client "loses" these on warp/map-change.
  8994. clif_updatestatus(sd,SP_STR);
  8995. clif_updatestatus(sd,SP_AGI);
  8996. clif_updatestatus(sd,SP_VIT);
  8997. clif_updatestatus(sd,SP_INT);
  8998. clif_updatestatus(sd,SP_DEX);
  8999. clif_updatestatus(sd,SP_LUK);
  9000. // abort currently running script
  9001. sd->state.using_fake_npc = 0;
  9002. sd->state.menu_or_input = 0;
  9003. sd->npc_menu = 0;
  9004. if(sd->npc_id)
  9005. npc_event_dequeue(sd);
  9006. }
  9007. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9008. #if PACKETVER >= 20070918
  9009. clif_partyinvitationstate(sd);
  9010. clif_equipcheckbox(sd);
  9011. #endif
  9012. if (sd->guild && battle_config.guild_notice_changemap == 1)
  9013. clif_guild_notice(sd); // Displays after VIP
  9014. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  9015. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  9016. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  9017. if( night_flag && map[sd->bl.m].flag.nightenabled )
  9018. { //Display night.
  9019. if( !sd->state.night )
  9020. {
  9021. sd->state.night = 1;
  9022. clif_status_load(&sd->bl, SI_NIGHT, 1);
  9023. }
  9024. }
  9025. else if( sd->state.night )
  9026. { //Clear night display.
  9027. sd->state.night = 0;
  9028. clif_status_load(&sd->bl, SI_NIGHT, 0);
  9029. }
  9030. if( map[sd->bl.m].flag.battleground )
  9031. {
  9032. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9033. if( map[sd->bl.m].flag.battleground == 2 )
  9034. clif_bg_updatescore_single(sd);
  9035. }
  9036. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  9037. {
  9038. char output[128];
  9039. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9040. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9041. }
  9042. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9043. map[sd->bl.m].hpmeter_visible++;
  9044. sd->state.hpmeter_visible = 1;
  9045. }
  9046. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9047. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9048. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9049. #ifdef VIP_ENABLE
  9050. if (!sd->state.connect_new &&
  9051. !sd->vip.disableshowrate &&
  9052. sd->state.pmap != sd->bl.m &&
  9053. map[sd->state.pmap].adjust.bexp != map[sd->bl.m].adjust.bexp
  9054. )
  9055. {
  9056. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  9057. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  9058. }
  9059. #endif
  9060. // Instances do not need their own channels
  9061. 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 )
  9062. channel_mjoin(sd); //join new map
  9063. clif_pk_mode_message(sd);
  9064. } else if (sd->guild && (battle_config.guild_notice_changemap == 2 || guild_notice))
  9065. clif_guild_notice(sd); // Displays at end
  9066. mail_clear(sd);
  9067. /* Guild Aura Init */
  9068. if( sd->state.gmaster_flag ) {
  9069. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9070. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9071. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9072. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9073. }
  9074. if( sd->state.vending ) { /* show we have a vending */
  9075. clif_openvending(sd,sd->bl.id,sd->vending);
  9076. clif_showvendingboard(&sd->bl,sd->message,0);
  9077. }
  9078. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9079. if(!sd->state.autotrade && map[sd->bl.m].flag.loadevent) // Lance
  9080. npc_script_event(sd, NPCE_LOADMAP);
  9081. if (pc_checkskill(sd, SG_DEVIL) && pc_is_maxjoblv(sd))
  9082. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  9083. if (sd->sc.opt2) //Client loses these on warp.
  9084. clif_changeoption(&sd->bl);
  9085. 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)) {
  9086. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  9087. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM, INVALID_TIMER);
  9088. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9089. }
  9090. clif_weather_check(sd);
  9091. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9092. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9093. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9094. else
  9095. sd->areanpc_id = 0;
  9096. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9097. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9098. pc_setdead(sd);
  9099. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9100. if(pc_isdead(sd))
  9101. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9102. else {
  9103. skill_usave_trigger(sd);
  9104. if (battle_config.spawn_direction)
  9105. clif_changed_dir(&sd->bl, SELF);
  9106. }
  9107. // Trigger skill effects if you appear standing on them
  9108. if(!battle_config.pc_invincible_time)
  9109. skill_unit_move(&sd->bl,gettick(),1);
  9110. pc_show_questinfo_reinit(sd);
  9111. pc_show_questinfo(sd);
  9112. #if PACKETVER >= 20150513
  9113. if( sd->mail.inbox.unread ){
  9114. clif_Mail_new(sd, 0, NULL, NULL);
  9115. }
  9116. #endif
  9117. sd->state.connect_new = 0;
  9118. sd->state.changemap = false;
  9119. }
  9120. /// Server's tick (ZC_NOTIFY_TIME).
  9121. /// 007f <time>.L
  9122. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  9123. {
  9124. int fd = sd->fd;
  9125. WFIFOHEAD(fd,packet_len(0x7f));
  9126. WFIFOW(fd,0) = 0x7f;
  9127. WFIFOL(fd,2) = time;
  9128. WFIFOSET(fd,packet_len(0x7f));
  9129. }
  9130. /// Request for server's tick.
  9131. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9132. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9133. /// There are various variants of this packet, some of them have padding between fields.
  9134. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9135. {
  9136. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9137. clif_notify_time(sd, gettick());
  9138. }
  9139. /// Sends hotkey bar.
  9140. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9141. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9142. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9143. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9144. void clif_hotkeys_send(struct map_session_data *sd) {
  9145. #ifdef HOTKEY_SAVING
  9146. const int fd = sd->fd;
  9147. int i;
  9148. int offset = 2;
  9149. #if PACKETVER < 20090603
  9150. const int cmd = 0x2b9;
  9151. #elif PACKETVER < 20141022
  9152. const int cmd = 0x7d9;
  9153. #else
  9154. char Rotate = sd->status.hotkey_rowshift;
  9155. const int cmd = 0xa00;
  9156. offset = 3;
  9157. #endif
  9158. if (!fd) return;
  9159. WFIFOHEAD(fd, offset + MAX_HOTKEYS * 7);
  9160. WFIFOW(fd, 0) = cmd;
  9161. #if PACKETVER >= 20141022
  9162. WFIFOB(fd, 2) = Rotate;
  9163. #endif
  9164. for(i = 0; i < MAX_HOTKEYS; i++) {
  9165. WFIFOB(fd, offset + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  9166. WFIFOL(fd, offset + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  9167. WFIFOW(fd, offset + 5 + i * 7) = sd->status.hotkeys[i].lv; // item qty or skill level
  9168. }
  9169. WFIFOSET(fd, packet_len(cmd));
  9170. #endif
  9171. }
  9172. /// Request to update a position on the hotkey row bar
  9173. void clif_parse_HotkeyRowShift(int fd, struct map_session_data *sd) {
  9174. int cmd = RFIFOW(fd, 0);
  9175. sd->status.hotkey_rowshift = RFIFOB(fd, packet_db[cmd].pos[0]);
  9176. }
  9177. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9178. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9179. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9180. #ifdef HOTKEY_SAVING
  9181. unsigned short idx;
  9182. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9183. idx = RFIFOW(fd, info->pos[0]);
  9184. if (idx >= MAX_HOTKEYS) return;
  9185. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  9186. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  9187. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  9188. #endif
  9189. }
  9190. /// Displays cast-like progress bar (ZC_PROGRESS).
  9191. /// 02f0 <color>.L <time>.L
  9192. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9193. {
  9194. int fd = sd->fd;
  9195. WFIFOHEAD(fd,packet_len(0x2f0));
  9196. WFIFOW(fd,0) = 0x2f0;
  9197. WFIFOL(fd,2) = color;
  9198. WFIFOL(fd,6) = second;
  9199. WFIFOSET(fd,packet_len(0x2f0));
  9200. }
  9201. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9202. /// 02f2
  9203. void clif_progressbar_abort(struct map_session_data * sd)
  9204. {
  9205. int fd = sd->fd;
  9206. WFIFOHEAD(fd,packet_len(0x2f2));
  9207. WFIFOW(fd,0) = 0x2f2;
  9208. WFIFOSET(fd,packet_len(0x2f2));
  9209. }
  9210. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  9211. /// 02f1
  9212. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  9213. {
  9214. int npc_id = sd->progressbar.npc_id;
  9215. if( gettick() < sd->progressbar.timeout && sd->st )
  9216. sd->st->state = END;
  9217. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  9218. sd->state.workinprogress = WIP_DISABLE_NONE;
  9219. npc_scriptcont(sd, npc_id, false);
  9220. }
  9221. /// Displays cast-like progress bar on a NPC
  9222. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9223. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9224. #if PACKETVER >= 20130821
  9225. unsigned char buf[14];
  9226. if( nd->progressbar.timeout > 0 ){
  9227. WBUFW(buf,0) = 0x9d1;
  9228. WBUFL(buf,2) = nd->bl.id;
  9229. WBUFL(buf,6) = nd->progressbar.color;
  9230. WBUFL(buf,10) = ( nd->progressbar.timeout - gettick() ) / 1000;
  9231. if( sd ){
  9232. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9233. }else{
  9234. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9235. }
  9236. }
  9237. #endif
  9238. }
  9239. /// Request to walk to a certain position on the current map.
  9240. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9241. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9242. /// There are various variants of this packet, some of them have padding between fields.
  9243. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9244. {
  9245. short x, y;
  9246. if (pc_isdead(sd)) {
  9247. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9248. return;
  9249. }
  9250. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9251. ; //You CAN walk on this OPT1 value.
  9252. else if (sd->progressbar.npc_id) {
  9253. clif_progressbar_abort(sd);
  9254. return; // First walk attempt cancels the progress bar
  9255. } else if (pc_cant_act(sd))
  9256. return;
  9257. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9258. return;
  9259. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9260. //A move command one cell west is only valid if the target cell is free
  9261. if(battle_config.official_cell_stack_limit > 0
  9262. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9263. return;
  9264. // Cloaking wall check is actually updated when you click to process next movement
  9265. // not when you move each cell. This is official behaviour.
  9266. if (sd->sc.data[SC_CLOAKING])
  9267. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9268. pc_delinvincibletimer(sd);
  9269. //Set last idle time... [Skotlex]
  9270. if (battle_config.idletime_option&IDLE_WALK)
  9271. sd->idletime = last_tick;
  9272. unit_walktoxy(&sd->bl, x, y, 4);
  9273. }
  9274. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9275. /// 018b <result>.W
  9276. /// result:
  9277. /// 0 = disconnect (quit)
  9278. /// 1 = cannot disconnect (wait 10 seconds)
  9279. /// ? = ignored
  9280. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9281. {
  9282. int fd = sd->fd;
  9283. WFIFOHEAD(fd,packet_len(0x18b));
  9284. WFIFOW(fd,0) = 0x18b;
  9285. WFIFOW(fd,2) = result;
  9286. WFIFOSET(fd,packet_len(0x18b));
  9287. }
  9288. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9289. /// 018a <type>.W
  9290. /// type:
  9291. /// 0 = quit
  9292. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9293. {
  9294. /* Rovert's prevent logout option fixed [Valaris] */
  9295. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9296. 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] &&
  9297. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9298. {
  9299. set_eof(fd);
  9300. pc_damage_log_clear(sd,0);
  9301. clif_disconnect_ack(sd, 0);
  9302. } else {
  9303. clif_disconnect_ack(sd, 1);
  9304. }
  9305. }
  9306. /// Requesting unit's name.
  9307. /// 0094 <id>.L (CZ_REQNAME)
  9308. /// 0368 <id>.L (CZ_REQNAME2)
  9309. /// There are various variants of this packet, some of them have padding between fields.
  9310. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9311. {
  9312. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9313. struct block_list* bl;
  9314. //struct status_change *sc;
  9315. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9316. id = sd->bl.id;
  9317. bl = map_id2bl(id);
  9318. if( bl == NULL )
  9319. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9320. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9321. return; // Block namerequests past view range
  9322. // 'see people in GM hide' cheat detection
  9323. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9324. sc = status_get_sc(bl);
  9325. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9326. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9327. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9328. ) {
  9329. char gm_msg[256];
  9330. 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);
  9331. ShowWarning(gm_msg);
  9332. // information is sent to all online GMs
  9333. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9334. return;
  9335. }
  9336. */
  9337. clif_name(&sd->bl,bl,SELF);
  9338. }
  9339. /// Validates and processes global messages
  9340. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9341. /// There are various variants of this packet.
  9342. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9343. {
  9344. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9345. size_t length;
  9346. // validate packet and retrieve name and message
  9347. if( !clif_process_message(sd, false, name, message, output ) )
  9348. return;
  9349. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9350. channel_send(sd->gcbind,sd,message);
  9351. return;
  9352. }
  9353. // send message to others (using the send buffer for temp. storage)
  9354. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9355. length = strlen(output) + 1;
  9356. // send back message to the speaker
  9357. WFIFOHEAD(fd,4+length);
  9358. WFIFOW(fd,0) = 0x8e;
  9359. WFIFOW(fd,2) = (uint16)(4+length);
  9360. safestrncpy(WFIFOCP(fd,4), output, length );
  9361. WFIFOSET(fd, WFIFOW(fd,2));
  9362. #ifdef PCRE_SUPPORT
  9363. // trigger listening npcs
  9364. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9365. #endif
  9366. // Chat logging type 'O' / Global Chat
  9367. 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);
  9368. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9369. }
  9370. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9371. /// Request to warp to a map on given coordinates.
  9372. /// 0140 <map name>.16B <x>.W <y>.W
  9373. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9374. {
  9375. char command[MAP_NAME_LENGTH_EXT+25];
  9376. char* map_name;
  9377. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9378. map_name = RFIFOCP(fd,info->pos[0]);
  9379. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9380. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9381. RFIFOW(fd,info->pos[1]), //x
  9382. RFIFOW(fd,info->pos[2])); //y
  9383. is_atcommand(fd, sd, command, 1);
  9384. }
  9385. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9386. /// 009c <id>.L <head dir>.W <dir>.B
  9387. /// head dir:
  9388. /// 0 = straight
  9389. /// 1 = turned CW
  9390. /// 2 = turned CCW
  9391. /// dir:
  9392. /// 0 = north
  9393. /// 1 = northwest
  9394. /// 2 = west
  9395. /// 3 = southwest
  9396. /// 4 = south
  9397. /// 5 = southeast
  9398. /// 6 = east
  9399. /// 7 = northeast
  9400. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9401. {
  9402. unsigned char buf[64];
  9403. WBUFW(buf,0) = 0x9c;
  9404. WBUFL(buf,2) = bl->id;
  9405. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9406. WBUFB(buf,8) = unit_getdir(bl);
  9407. clif_send(buf, packet_len(0x9c), bl, target);
  9408. if (disguised(bl)) {
  9409. WBUFL(buf,2) = -bl->id;
  9410. WBUFW(buf,6) = 0;
  9411. clif_send(buf, packet_len(0x9c), bl, SELF);
  9412. }
  9413. }
  9414. /// Request to change own body and head direction.
  9415. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9416. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9417. /// There are various variants of this packet, some of them have padding between fields.
  9418. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9419. {
  9420. unsigned char headdir, dir;
  9421. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9422. headdir = RFIFOB(fd,info->pos[0]);
  9423. dir = RFIFOB(fd,info->pos[1]);
  9424. pc_setdir(sd, dir, headdir);
  9425. clif_changed_dir(&sd->bl, AREA_WOS);
  9426. }
  9427. /// Request to show an emotion (CZ_REQ_EMOTION).
  9428. /// 00bf <type>.B
  9429. /// type:
  9430. /// @see enum emotion_type
  9431. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9432. {
  9433. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9434. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9435. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  9436. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9437. return;
  9438. }
  9439. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9440. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9441. sd->emotionlasttime = time(NULL);
  9442. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9443. return;
  9444. }
  9445. sd->emotionlasttime = time(NULL);
  9446. if (battle_config.idletime_option&IDLE_EMOTION)
  9447. sd->idletime = last_tick;
  9448. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
  9449. emoticon = rnd()%6+E_DICE1;
  9450. }
  9451. clif_emotion(&sd->bl, emoticon);
  9452. } else
  9453. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9454. }
  9455. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9456. /// 00c2 <count>.L
  9457. void clif_user_count(struct map_session_data* sd, int count)
  9458. {
  9459. int fd = sd->fd;
  9460. WFIFOHEAD(fd,packet_len(0xc2));
  9461. WFIFOW(fd,0) = 0xc2;
  9462. WFIFOL(fd,2) = count;
  9463. WFIFOSET(fd,packet_len(0xc2));
  9464. }
  9465. /// /w /who (CZ_REQ_USER_COUNT).
  9466. /// Request to display amount of currently connected players.
  9467. /// 00c1
  9468. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9469. {
  9470. clif_user_count(sd, map_getusers());
  9471. }
  9472. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  9473. {
  9474. if (pc_isdead(sd)) {
  9475. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9476. return;
  9477. }
  9478. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9479. // (not all are included in pc_can_attack)
  9480. if (sd->sc.count &&
  9481. (sd->sc.data[SC_TRICKDEAD] ||
  9482. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9483. sd->sc.data[SC_BLADESTOP] ||
  9484. sd->sc.data[SC__MANHOLE] ||
  9485. sd->sc.data[SC_SUHIDE] ))
  9486. return;
  9487. if(action_type != 0x00 && action_type != 0x07)
  9488. pc_stop_walking(sd, 1);
  9489. pc_stop_attack(sd);
  9490. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9491. target_id = sd->bl.id;
  9492. switch(action_type)
  9493. {
  9494. case 0x00: // once attack
  9495. case 0x07: // continuous attack
  9496. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9497. return;
  9498. if( sd->sc.option&OPTION_COSTUME )
  9499. return;
  9500. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9501. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9502. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9503. return;
  9504. }
  9505. }
  9506. pc_delinvincibletimer(sd);
  9507. if (battle_config.idletime_option&IDLE_ATTACK)
  9508. sd->idletime = last_tick;
  9509. unit_attack(&sd->bl, target_id, action_type != 0);
  9510. break;
  9511. case 0x02: // sitdown
  9512. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9513. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9514. break;
  9515. }
  9516. if(pc_issit(sd)) {
  9517. //Bugged client? Just refresh them.
  9518. clif_sitting(&sd->bl);
  9519. return;
  9520. }
  9521. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9522. break;
  9523. if (sd->sc.count && (
  9524. sd->sc.data[SC_DANCING] ||
  9525. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9526. )) //No sitting during these states either.
  9527. break;
  9528. if (battle_config.idletime_option&IDLE_SIT)
  9529. sd->idletime = last_tick;
  9530. pc_setsit(sd);
  9531. skill_sit(sd, 1);
  9532. clif_sitting(&sd->bl);
  9533. break;
  9534. case 0x03: // standup
  9535. if (!pc_issit(sd)) {
  9536. //Bugged client? Just refresh them.
  9537. clif_standing(&sd->bl);
  9538. return;
  9539. }
  9540. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9541. break;
  9542. if (pc_setstand(sd, false)) {
  9543. if (battle_config.idletime_option&IDLE_SIT)
  9544. sd->idletime = last_tick;
  9545. skill_sit(sd, 0);
  9546. clif_standing(&sd->bl);
  9547. }
  9548. break;
  9549. }
  9550. }
  9551. /// Request for an action.
  9552. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9553. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9554. /// action:
  9555. /// 0 = attack
  9556. /// 1 = pick up item
  9557. /// 2 = sit down
  9558. /// 3 = stand up
  9559. /// 7 = continous attack
  9560. /// 12 = (touch skill?)
  9561. /// There are various variants of this packet, some of them have padding between fields.
  9562. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9563. {
  9564. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9565. clif_parse_ActionRequest_sub(sd,
  9566. RFIFOB(fd,info->pos[1]),
  9567. RFIFOL(fd,info->pos[0]),
  9568. gettick()
  9569. );
  9570. }
  9571. /// Response to the death/system menu (CZ_RESTART).
  9572. /// 00b2 <type>.B
  9573. /// type:
  9574. /// 0 = restart (respawn)
  9575. /// 1 = char-select (disconnect)
  9576. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9577. {
  9578. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9579. case 0x00:
  9580. pc_respawn(sd,CLR_OUTSIGHT);
  9581. break;
  9582. case 0x01:
  9583. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9584. 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] &&
  9585. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9586. { //Send to char-server for character selection.
  9587. pc_damage_log_clear(sd,0);
  9588. chrif_charselectreq(sd, session[fd]->client_addr);
  9589. } else {
  9590. clif_disconnect_ack(sd, 1);
  9591. }
  9592. break;
  9593. }
  9594. }
  9595. /// Validates and processes whispered messages (CZ_WHISPER).
  9596. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9597. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9598. {
  9599. struct map_session_data* dstsd;
  9600. int i;
  9601. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9602. // validate packet and retrieve name and message
  9603. if( !clif_process_message( sd, true, target, message, output ) )
  9604. return;
  9605. // Chat logging type 'W' / Whisper
  9606. 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);
  9607. //-------------------------------------------------------//
  9608. // Lordalfa - Paperboy - To whisper NPC commands //
  9609. //-------------------------------------------------------//
  9610. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9611. {
  9612. char* str = target+4; //Skip the NPC: string part.
  9613. struct npc_data* npc;
  9614. if ((npc = npc_name2id(str))) {
  9615. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9616. char *split;
  9617. char event[EVENT_NAME_LENGTH];
  9618. str = message;
  9619. // skip codepage indicator, if detected
  9620. if( str[0] == '|' && strlen(str) >= 4 )
  9621. str += 3;
  9622. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9623. split = strchr(str,'#');
  9624. if( split == NULL ) { // use the remaining string
  9625. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9626. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9627. split_data[i][0] = '\0';
  9628. break;
  9629. }
  9630. *split = '\0';
  9631. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9632. str = split+1;
  9633. }
  9634. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9635. char variablename[CHAT_SIZE_MAX];
  9636. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9637. set_var(sd,variablename,(char *) split_data[i]);
  9638. }
  9639. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9640. npc_event(sd,event,0); // Calls the NPC label
  9641. return;
  9642. }
  9643. } else if( target[0] == '#' ) {
  9644. struct Channel *channel = NULL;
  9645. char* chname = target;
  9646. channel = channel_name2channel(chname,sd,3);
  9647. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9648. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9649. channel_send(channel,sd,message);
  9650. }
  9651. else if( channel->pass[0] == '\0') { //no pass needed
  9652. if (channel_join(channel,sd)==0)
  9653. channel_send(channel,sd,message); //join success
  9654. }
  9655. else {
  9656. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9657. }
  9658. return;
  9659. }
  9660. }
  9661. // searching destination character
  9662. dstsd = map_nick2sd(target,false);
  9663. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9664. // player is not on this map-server
  9665. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9666. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9667. // and if we ask for 'Test', we must not contact 'test' player
  9668. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9669. intif_wis_message(sd, target, message, strlen(message));
  9670. return;
  9671. }
  9672. // if player ignores everyone
  9673. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9674. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9675. clif_wis_end(fd, 1); // 1: target character is not logged in
  9676. else
  9677. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9678. return;
  9679. }
  9680. // if player is autotrading
  9681. if (dstsd->state.autotrade == 1){
  9682. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9683. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  9684. return;
  9685. }
  9686. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9687. // if player ignores the source character
  9688. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9689. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9690. clif_wis_end(fd, 2); // 2: ignored by target
  9691. return;
  9692. }
  9693. }
  9694. // notify sender of success
  9695. clif_wis_end(fd, 0); // 0: success to send wisper
  9696. // Normal message
  9697. clif_wis_message(dstsd->fd, sd->status.name, message, strlen(message)+1 );
  9698. }
  9699. /// /b /nb (CZ_BROADCAST).
  9700. /// Request to broadcast a message on whole server.
  9701. /// 0099 <packet len>.W <text>.?B 00
  9702. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9703. char command[CHAT_SIZE_MAX+11];
  9704. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9705. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9706. char* msg = RFIFOCP(fd,info->pos[1]);
  9707. // as the length varies depending on the command used, just block unreasonably long strings
  9708. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9709. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9710. is_atcommand(fd, sd, command, 1);
  9711. }
  9712. /// Request to pick up an item.
  9713. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9714. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9715. /// There are various variants of this packet, some of them have padding between fields.
  9716. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9717. {
  9718. struct flooritem_data *fitem;
  9719. int map_object_id;
  9720. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9721. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9722. do {
  9723. if (pc_isdead(sd)) {
  9724. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9725. break;
  9726. }
  9727. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9728. break;
  9729. if (pc_cant_act(sd))
  9730. break;
  9731. if (!pc_takeitem(sd, fitem))
  9732. break;
  9733. return;
  9734. } while (0);
  9735. // Client REQUIRES a fail packet or you can no longer pick items.
  9736. clif_additem(sd,0,0,6);
  9737. }
  9738. /// Request to drop an item.
  9739. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9740. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9741. /// There are various variants of this packet, some of them have padding between fields.
  9742. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9743. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9744. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9745. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9746. for(;;) {
  9747. if (pc_isdead(sd))
  9748. break;
  9749. if (pc_cant_act2(sd) || sd->npc_id)
  9750. break;
  9751. if (sd->sc.count && (
  9752. sd->sc.data[SC_AUTOCOUNTER] ||
  9753. sd->sc.data[SC_BLADESTOP] ||
  9754. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9755. ))
  9756. break;
  9757. if (!pc_dropitem(sd, item_index, item_amount))
  9758. break;
  9759. if (battle_config.idletime_option&IDLE_DROPITEM)
  9760. sd->idletime = last_tick;
  9761. return;
  9762. }
  9763. //Because the client does not like being ignored.
  9764. clif_dropitem(sd, item_index,0);
  9765. }
  9766. /// Request to use an item.
  9767. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9768. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9769. /// There are various variants of this packet, some of them have padding between fields.
  9770. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9771. {
  9772. int n;
  9773. if (pc_isdead(sd)) {
  9774. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9775. return;
  9776. }
  9777. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9778. return;
  9779. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9780. if (battle_config.idletime_option&IDLE_USEITEM)
  9781. sd->idletime = last_tick;
  9782. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9783. if(n <0 || n >= MAX_INVENTORY)
  9784. return;
  9785. if (!pc_useitem(sd,n))
  9786. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9787. }
  9788. /// Request to equip an item
  9789. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9790. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9791. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9792. {
  9793. int index;
  9794. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9795. if(pc_isdead(sd)) {
  9796. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9797. return;
  9798. }
  9799. index = RFIFOW(fd,info->pos[0])-2;
  9800. if (index < 0 || index >= MAX_INVENTORY)
  9801. return; //Out of bounds check.
  9802. if(sd->npc_id && !sd->npc_item_flag) {
  9803. return;
  9804. } else if (sd->state.storage_flag || sd->sc.opt1)
  9805. ; //You can equip/unequip stuff while storage is open/under status changes
  9806. else if (pc_cant_act2(sd))
  9807. return;
  9808. if(!sd->inventory.u.items_inventory[index].identify) {
  9809. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9810. return;
  9811. }
  9812. if(!sd->inventory_data[index])
  9813. return;
  9814. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9815. pet_equipitem(sd,index);
  9816. return;
  9817. }
  9818. if (battle_config.idletime_option&IDLE_USEITEM)
  9819. sd->idletime = last_tick;
  9820. //Client doesn't send the position for ammo.
  9821. if(sd->inventory_data[index]->type == IT_AMMO)
  9822. pc_equipitem(sd,index,EQP_AMMO);
  9823. else {
  9824. int req_pos;
  9825. #if PACKETVER >= 20120925
  9826. req_pos = RFIFOL(fd,info->pos[1]);
  9827. #else
  9828. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9829. #endif
  9830. pc_equipitem(sd,index,req_pos);
  9831. }
  9832. }
  9833. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9834. /// 00ab <index>.W
  9835. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9836. {
  9837. int index;
  9838. if(pc_isdead(sd)) {
  9839. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9840. return;
  9841. }
  9842. if (sd->npc_id && !sd->npc_item_flag) {
  9843. return;
  9844. } else if (sd->state.storage_flag || sd->sc.opt1)
  9845. ; //You can equip/unequip stuff while storage is open/under status changes
  9846. else if (pc_cant_act2(sd))
  9847. return;
  9848. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9849. if (battle_config.idletime_option&IDLE_USEITEM)
  9850. sd->idletime = last_tick;
  9851. pc_unequipitem(sd,index,1);
  9852. }
  9853. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9854. /// 0090 <id>.L <type>.B
  9855. /// type:
  9856. /// 1 = click
  9857. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9858. {
  9859. struct block_list *bl;
  9860. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9861. if(pc_isdead(sd)) {
  9862. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9863. return;
  9864. }
  9865. #ifdef RENEWAL
  9866. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_NPC)) {
  9867. clif_msg(sd, WORK_IN_PROGRESS);
  9868. return;
  9869. }
  9870. #endif
  9871. if (pc_cant_act2(sd) || sd->npc_id)
  9872. return;
  9873. if( sd->state.mail_writing )
  9874. return;
  9875. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9876. //type = RFIFOB(fd,info->pos[1]);
  9877. if (!bl) return;
  9878. switch (bl->type) {
  9879. case BL_MOB:
  9880. case BL_PC:
  9881. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9882. break;
  9883. case BL_NPC:
  9884. #ifdef RENEWAL
  9885. 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
  9886. clif_msg(sd, WORK_IN_PROGRESS);
  9887. break;
  9888. }
  9889. #endif
  9890. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  9891. struct npc_data* nd = (struct npc_data*)bl;
  9892. // Progressbar is running
  9893. if( nd->progressbar.timeout > 0 ){
  9894. return;
  9895. }
  9896. npc_click(sd,nd);
  9897. }
  9898. break;
  9899. }
  9900. }
  9901. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9902. /// 00c5 <id>.L <type>.B
  9903. /// type:
  9904. /// 0 = buy
  9905. /// 1 = sell
  9906. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9907. {
  9908. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9909. if (sd->state.trading)
  9910. return;
  9911. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9912. }
  9913. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9914. /// 00ca <result>.B
  9915. /// result:
  9916. /// 0 = "The deal has successfully completed."
  9917. /// 1 = "You do not have enough zeny."
  9918. /// 2 = "You are over your Weight Limit."
  9919. /// 3 = "Out of the maximum capacity, you have too many items."
  9920. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  9921. {
  9922. int fd = sd->fd;
  9923. WFIFOHEAD(fd,packet_len(0xca));
  9924. WFIFOW(fd,0) = 0xca;
  9925. WFIFOB(fd,2) = result;
  9926. WFIFOSET(fd,packet_len(0xca));
  9927. }
  9928. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  9929. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  9930. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  9931. {
  9932. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9933. uint16 n = (RFIFOW(fd,info->pos[0])-4) /4;
  9934. int result;
  9935. if( sd->state.trading || !sd->npc_shopid )
  9936. result = 1;
  9937. else
  9938. result = npc_buylist(sd, n, (struct s_npc_buy_list*)RFIFOP(fd,info->pos[1]));
  9939. sd->npc_shopid = 0; //Clear shop data.
  9940. clif_npc_buy_result(sd, result);
  9941. }
  9942. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  9943. /// 00cb <result>.B
  9944. /// result:
  9945. /// 0 = "The deal has successfully completed."
  9946. /// 1 = "The deal has failed."
  9947. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  9948. {
  9949. int fd = sd->fd;
  9950. WFIFOHEAD(fd,packet_len(0xcb));
  9951. WFIFOW(fd,0) = 0xcb;
  9952. WFIFOB(fd,2) = result;
  9953. WFIFOSET(fd,packet_len(0xcb));
  9954. }
  9955. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  9956. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  9957. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  9958. {
  9959. int fail=0,n;
  9960. unsigned short *item_list;
  9961. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9962. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  9963. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  9964. if (sd->state.trading || !sd->npc_shopid)
  9965. fail = 1;
  9966. else
  9967. fail = npc_selllist(sd,n,item_list);
  9968. sd->npc_shopid = 0; //Clear shop data.
  9969. clif_npc_sell_result(sd, fail);
  9970. }
  9971. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  9972. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  9973. /// type:
  9974. /// 0 = private
  9975. /// 1 = public
  9976. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  9977. {
  9978. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9979. int len = RFIFOW(fd,info->pos[0])-15;
  9980. int limit = RFIFOW(fd,info->pos[1]);
  9981. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  9982. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  9983. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  9984. char s_password[CHATROOM_PASS_SIZE];
  9985. char s_title[CHATROOM_TITLE_SIZE];
  9986. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  9987. return;
  9988. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9989. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  9990. return;
  9991. }
  9992. if( npc_isnear(&sd->bl) ) {
  9993. // uncomment to send msg_txt.
  9994. //char output[150];
  9995. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  9996. //clif_displaymessage(sd->fd, output);
  9997. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  9998. return;
  9999. }
  10000. if( len <= 0 )
  10001. return; // invalid input
  10002. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10003. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10004. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10005. }
  10006. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10007. /// 00d9 <chat ID>.L <passwd>.8B
  10008. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10009. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10010. int chatid = RFIFOL(fd,info->pos[0]);
  10011. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10012. chat_joinchat(sd,chatid,password);
  10013. }
  10014. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10015. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10016. /// type:
  10017. /// 0 = private
  10018. /// 1 = public
  10019. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  10020. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10021. int len = RFIFOW(fd,info->pos[0])-15;
  10022. int limit = RFIFOW(fd,info->pos[1]);
  10023. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10024. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10025. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10026. char s_password[CHATROOM_PASS_SIZE];
  10027. char s_title[CHATROOM_TITLE_SIZE];
  10028. if( len <= 0 )
  10029. return; // invalid input
  10030. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10031. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10032. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10033. }
  10034. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10035. /// 00e0 <role>.L <nick>.24B
  10036. /// role:
  10037. /// 0 = owner
  10038. /// 1 = normal
  10039. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10040. {
  10041. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10042. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10043. }
  10044. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10045. /// 00e2 <name>.24B
  10046. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10047. {
  10048. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10049. }
  10050. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10051. /// 00e3
  10052. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10053. {
  10054. chat_leavechat(sd,0);
  10055. }
  10056. //Handles notifying asker and rejecter of what has just ocurred.
  10057. //Type is used to determine the correct msg_txt to use:
  10058. //0:
  10059. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10060. {
  10061. const char* msg;
  10062. char output[256];
  10063. // Your request has been rejected by autoreject option.
  10064. msg = msg_txt(sd,392);
  10065. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10066. //Notice that a request was rejected.
  10067. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10068. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10069. }
  10070. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10071. /// 00e4 <account id>.L
  10072. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10073. {
  10074. struct map_session_data *t_sd;
  10075. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10076. if(!sd->chatID && pc_cant_act(sd))
  10077. return; //You can trade while in a chatroom.
  10078. if(t_sd){
  10079. // @noask [LuzZza]
  10080. if(t_sd->state.noask) {
  10081. clif_noask_sub(sd, t_sd, 0);
  10082. return;
  10083. }
  10084. if (t_sd->state.mail_writing) {
  10085. int old = sd->trade_partner;
  10086. // Fake trading
  10087. sd->trade_partner = t_sd->status.account_id;
  10088. clif_tradestart(sd, 5);
  10089. // Restore old state
  10090. sd->trade_partner = old;
  10091. return;
  10092. }
  10093. }
  10094. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10095. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10096. return;
  10097. }
  10098. trade_traderequest(sd,t_sd);
  10099. }
  10100. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10101. /// 00e6 <result>.B
  10102. /// result:
  10103. /// 3 = accepted
  10104. /// 4 = rejected
  10105. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10106. {
  10107. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10108. }
  10109. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10110. /// 00e8 <index>.W <amount>.L
  10111. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10112. {
  10113. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10114. short index = RFIFOW(fd,info->pos[0]);
  10115. int amount = RFIFOL(fd,info->pos[1]);
  10116. if( index == 0 )
  10117. trade_tradeaddzeny(sd, amount);
  10118. else
  10119. trade_tradeadditem(sd, index, (short)amount);
  10120. }
  10121. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10122. /// 00eb
  10123. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10124. {
  10125. trade_tradeok(sd);
  10126. }
  10127. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10128. /// 00ed
  10129. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10130. {
  10131. trade_tradecancel(sd);
  10132. }
  10133. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10134. /// 00ef
  10135. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10136. {
  10137. trade_tradecommit(sd);
  10138. }
  10139. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10140. /// 0118
  10141. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10142. {
  10143. pc_stop_attack(sd);
  10144. if (sd) sd->ud.state.attack_continue = 0;
  10145. }
  10146. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10147. /// 0126 <index>.W <amount>.L
  10148. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  10149. {
  10150. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10151. if (pc_istrading(sd))
  10152. return;
  10153. if (!pc_iscarton(sd))
  10154. return;
  10155. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10156. }
  10157. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10158. /// 0127 <index>.W <amount>.L
  10159. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10160. {
  10161. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10162. if (!pc_iscarton(sd))
  10163. return;
  10164. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10165. }
  10166. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10167. /// 012a
  10168. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10169. {
  10170. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10171. #ifdef NEW_CARTS
  10172. && sd->sc.data[SC_PUSH_CART] )
  10173. pc_setcart(sd,0);
  10174. #else
  10175. )
  10176. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10177. #endif
  10178. else // priority to remove this option before we can clear cart
  10179. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10180. }
  10181. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10182. /// 097f <Length>.W <identity>.L <type>.B
  10183. void clif_SelectCart(struct map_session_data *sd) {
  10184. #if PACKETVER >= 20150826
  10185. int i = 0, carts = 3;
  10186. int fd = sd->fd;
  10187. WFIFOHEAD(fd,8 + carts);
  10188. WFIFOW(fd,0) = 0x97f;
  10189. WFIFOW(fd,2) = 8 + carts;
  10190. WFIFOL(fd,4) = sd->status.account_id;
  10191. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10192. for( i = 0; i < carts; i++ ) {
  10193. WFIFOB(fd,8 + i) = 10 + i;
  10194. }
  10195. WFIFOSET(fd,8 + carts);
  10196. #endif
  10197. }
  10198. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10199. /// 0980 <identity>.L <type>.B
  10200. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10201. #if PACKETVER >= 20150826
  10202. int type;
  10203. // Check identity
  10204. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10205. return;
  10206. type = (int)RFIFOB(fd,6);
  10207. // Check type
  10208. if( type < 10 || type > MAX_CARTS )
  10209. return;
  10210. pc_setcart(sd, type);
  10211. #endif
  10212. }
  10213. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10214. /// 01af <num>.W
  10215. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10216. {// TODO: State tracking?
  10217. int type;
  10218. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10219. return;
  10220. #ifdef RENEWAL
  10221. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10222. clif_msg(sd, WORK_IN_PROGRESS);
  10223. return;
  10224. }
  10225. #endif
  10226. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10227. if(
  10228. #ifdef NEW_CARTS
  10229. (type == 9 && sd->status.base_level > 130) ||
  10230. (type == 8 && sd->status.base_level > 120) ||
  10231. (type == 7 && sd->status.base_level > 110) ||
  10232. (type == 6 && sd->status.base_level > 100) ||
  10233. #endif
  10234. (type == 5 && sd->status.base_level > 90) ||
  10235. (type == 4 && sd->status.base_level > 80) ||
  10236. (type == 3 && sd->status.base_level > 65) ||
  10237. (type == 2 && sd->status.base_level > 40) ||
  10238. (type == 1))
  10239. pc_setcart(sd, type);
  10240. }
  10241. /// Request to increase status (CZ_STATUS_CHANGE).
  10242. /// 00bb <status id>.W <amount>.B
  10243. /// status id:
  10244. /// SP_STR ~ SP_LUK
  10245. /// amount:
  10246. /// Old clients always send 1 for this, even when using /str+ and the like.
  10247. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10248. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10249. {
  10250. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10251. if( increase_amount < 0 ) {
  10252. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10253. fd, increase_amount);
  10254. }
  10255. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10256. }
  10257. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10258. /// 0112 <skill id>.W
  10259. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10260. {
  10261. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10262. }
  10263. 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)
  10264. {
  10265. int lv;
  10266. if( !hd )
  10267. return;
  10268. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10269. clif_emotion(&hd->bl, E_DOTS);
  10270. return;
  10271. }
  10272. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10273. target_id = hd->bl.id;
  10274. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10275. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10276. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10277. clif_emotion(&hd->bl, E_DOTS);
  10278. if (hd->master)
  10279. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10280. return;
  10281. }
  10282. lv = hom_checkskill(hd, skill_id);
  10283. if( skill_lv > lv )
  10284. skill_lv = lv;
  10285. if( skill_lv )
  10286. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10287. }
  10288. 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)
  10289. {
  10290. int lv;
  10291. if( !hd )
  10292. return;
  10293. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10294. clif_emotion(&hd->bl, E_DOTS);
  10295. return;
  10296. }
  10297. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10298. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10299. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10300. clif_emotion(&hd->bl, E_DOTS);
  10301. if (hd->master)
  10302. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10303. return;
  10304. }
  10305. if( hd->sc.data[SC_BASILICA] )
  10306. return;
  10307. lv = hom_checkskill(hd, skill_id);
  10308. if( skill_lv > lv )
  10309. skill_lv = lv;
  10310. if( skill_lv )
  10311. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10312. }
  10313. 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)
  10314. {
  10315. int lv;
  10316. if( !md )
  10317. return;
  10318. if( skill_isNotOk_mercenary(skill_id, md) )
  10319. return;
  10320. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10321. target_id = md->bl.id;
  10322. if( md->ud.skilltimer != INVALID_TIMER )
  10323. {
  10324. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10325. }
  10326. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10327. return;
  10328. lv = mercenary_checkskill(md, skill_id);
  10329. if( skill_lv > lv )
  10330. skill_lv = lv;
  10331. if( skill_lv )
  10332. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10333. }
  10334. 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)
  10335. {
  10336. int lv;
  10337. if( !md )
  10338. return;
  10339. if( skill_isNotOk_mercenary(skill_id, md) )
  10340. return;
  10341. if( md->ud.skilltimer != INVALID_TIMER )
  10342. return;
  10343. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10344. {
  10345. if (md->master)
  10346. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10347. return;
  10348. }
  10349. if( md->sc.data[SC_BASILICA] )
  10350. return;
  10351. lv = mercenary_checkskill(md, skill_id);
  10352. if( skill_lv > lv )
  10353. skill_lv = lv;
  10354. if( skill_lv )
  10355. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10356. }
  10357. /// Request to use a targeted skill.
  10358. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10359. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10360. /// There are various variants of this packet, some of them have padding between fields.
  10361. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  10362. {
  10363. uint16 skill_id, skill_lv;
  10364. int inf,target_id;
  10365. unsigned int tick = gettick();
  10366. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10367. skill_lv = RFIFOW(fd,info->pos[0]);
  10368. skill_id = RFIFOW(fd,info->pos[1]);
  10369. target_id = RFIFOL(fd,info->pos[2]);
  10370. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10371. inf = skill_get_inf(skill_id);
  10372. if (inf&INF_GROUND_SKILL || !inf)
  10373. return; //Using a ground/passive skill on a target? WRONG.
  10374. if( SKILL_CHK_HOMUN(skill_id) ) {
  10375. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10376. return;
  10377. }
  10378. if( SKILL_CHK_MERC(skill_id) ) {
  10379. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10380. return;
  10381. }
  10382. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10383. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10384. sd->idletime = last_tick;
  10385. if (sd->npc_id) {
  10386. #ifdef RENEWAL
  10387. if (pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10388. clif_msg(sd, WORK_IN_PROGRESS);
  10389. return;
  10390. }
  10391. #else
  10392. if (!sd->npc_item_flag || !(inf&INF_SELF_SKILL))
  10393. return;
  10394. #endif
  10395. }
  10396. if( (pc_cant_act2(sd) || sd->chatID) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE &&
  10397. (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10398. sd->state.storage_flag && !(inf&INF_SELF_SKILL) ) //SELF skills can be used with the storage open, issue: 8027
  10399. return;
  10400. if( pc_issit(sd) )
  10401. return;
  10402. if( skill_isNotOk(skill_id, sd) )
  10403. return;
  10404. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10405. target_id = sd->bl.id; // never trust the client
  10406. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10407. target_id = sd->bl.id;
  10408. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10409. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10410. return;
  10411. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10412. if( sd->skillitem != skill_id ) {
  10413. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10414. return;
  10415. }
  10416. }
  10417. if( sd->sc.option&OPTION_COSTUME )
  10418. return;
  10419. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10420. return; // On basilica only caster can use Basilica again to stop it.
  10421. if( sd->menuskill_id ) {
  10422. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10423. clif_menuskill_clear(sd); //Cancel pet capture.
  10424. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10425. return; //Can't use skills while a menu is open.
  10426. }
  10427. if( sd->skillitem == skill_id ) {
  10428. if( skill_lv != sd->skillitemlv )
  10429. skill_lv = sd->skillitemlv;
  10430. if( !(inf&INF_SELF_SKILL) )
  10431. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10432. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10433. return;
  10434. }
  10435. sd->skillitem = sd->skillitemlv = 0;
  10436. if( SKILL_CHK_GUILD(skill_id) ) {
  10437. if( sd->state.gmaster_flag )
  10438. skill_lv = guild_checkskill(sd->guild, skill_id);
  10439. else
  10440. skill_lv = 0;
  10441. } else {
  10442. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10443. }
  10444. pc_delinvincibletimer(sd);
  10445. if( skill_lv )
  10446. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10447. }
  10448. /*==========================================
  10449. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10450. *------------------------------------------*/
  10451. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10452. {
  10453. unsigned int tick = gettick();
  10454. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10455. return; //Using a target skill on the ground? WRONG.
  10456. if( SKILL_CHK_HOMUN(skill_id) ) {
  10457. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10458. return;
  10459. }
  10460. if( SKILL_CHK_MERC(skill_id) ) {
  10461. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10462. return;
  10463. }
  10464. #ifdef RENEWAL
  10465. if (pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10466. clif_msg(sd, WORK_IN_PROGRESS);
  10467. return;
  10468. }
  10469. #endif
  10470. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10471. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10472. sd->idletime = last_tick;
  10473. if( skill_isNotOk(skill_id, sd) )
  10474. return;
  10475. if( skillmoreinfo != -1 ) {
  10476. if( pc_issit(sd) ) {
  10477. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10478. return;
  10479. }
  10480. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10481. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10482. }
  10483. if( sd->ud.skilltimer != INVALID_TIMER )
  10484. return;
  10485. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10486. if( sd->skillitem != skill_id ) {
  10487. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10488. return;
  10489. }
  10490. }
  10491. if( sd->sc.option&OPTION_COSTUME )
  10492. return;
  10493. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10494. return; // On basilica only caster can use Basilica again to stop it.
  10495. if( sd->menuskill_id ) {
  10496. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10497. clif_menuskill_clear(sd); //Cancel pet capture.
  10498. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10499. return; //Can't use skills while a menu is open.
  10500. }
  10501. pc_delinvincibletimer(sd);
  10502. if( sd->skillitem == skill_id ) {
  10503. if( skill_lv != sd->skillitemlv )
  10504. skill_lv = sd->skillitemlv;
  10505. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10506. } else {
  10507. int lv;
  10508. sd->skillitem = sd->skillitemlv = 0;
  10509. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10510. if( skill_lv > lv )
  10511. skill_lv = lv;
  10512. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10513. }
  10514. }
  10515. }
  10516. /// Request to use a ground skill.
  10517. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10518. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10519. /// There are various variants of this packet, some of them have padding between fields.
  10520. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10521. {
  10522. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10523. if (pc_cant_act(sd))
  10524. return;
  10525. if (pc_issit(sd))
  10526. return;
  10527. clif_parse_UseSkillToPosSub(fd, sd,
  10528. RFIFOW(fd,info->pos[0]), //skill lv
  10529. RFIFOW(fd,info->pos[1]), //skill num
  10530. RFIFOW(fd,info->pos[2]), //pos x
  10531. RFIFOW(fd,info->pos[3]), //pos y
  10532. -1 //Skill more info.
  10533. );
  10534. }
  10535. /// Request to use a ground skill with text.
  10536. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10537. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10538. /// There are various variants of this packet, some of them have padding between fields.
  10539. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10540. {
  10541. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10542. if (pc_cant_act(sd))
  10543. return;
  10544. if (pc_issit(sd))
  10545. return;
  10546. clif_parse_UseSkillToPosSub(fd, sd,
  10547. RFIFOW(fd,info->pos[0]), //Skill lv
  10548. RFIFOW(fd,info->pos[1]), //Skill num
  10549. RFIFOW(fd,info->pos[2]), //pos x
  10550. RFIFOW(fd,info->pos[3]), //pos y
  10551. info->pos[4] //skill more info
  10552. );
  10553. }
  10554. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10555. /// 011b <skill id>.W <map name>.16B
  10556. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10557. {
  10558. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10559. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10560. char map_name[MAP_NAME_LENGTH];
  10561. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10562. sd->state.workinprogress = WIP_DISABLE_NONE;
  10563. if(skill_id != sd->menuskill_id)
  10564. return;
  10565. //It is possible to use teleport with the storage window open bugreport:8027
  10566. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10567. clif_menuskill_clear(sd);
  10568. return;
  10569. }
  10570. pc_delinvincibletimer(sd);
  10571. skill_castend_map(sd,skill_id,map_name);
  10572. }
  10573. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10574. /// 011d
  10575. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10576. {
  10577. if (!pc_isdead(sd))
  10578. pc_memo(sd,-1);
  10579. }
  10580. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10581. /// 018e <name id>.W { <material id>.W }*3
  10582. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10583. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10584. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  10585. int slot1 = RFIFOW(fd,info->pos[1]);
  10586. int slot2 = RFIFOW(fd,info->pos[2]);
  10587. int slot3 = RFIFOW(fd,info->pos[3]);
  10588. short produce_idx = -1;
  10589. switch( sd->menuskill_id ) {
  10590. case -1:
  10591. case AM_PHARMACY:
  10592. case RK_RUNEMASTERY:
  10593. case GC_RESEARCHNEWPOISON:
  10594. break;
  10595. default:
  10596. return;
  10597. }
  10598. if (pc_istrading(sd)) {
  10599. //Make it fail to avoid shop exploits where you sell something different than you see.
  10600. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10601. clif_menuskill_clear(sd);
  10602. return;
  10603. }
  10604. if( (produce_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1)) )
  10605. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3,1,produce_idx-1);
  10606. clif_menuskill_clear(sd);
  10607. }
  10608. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10609. /// 025b <mk type>.W <name id>.W
  10610. /// mk type:
  10611. /// 1 = cooking
  10612. /// 2 = arrow
  10613. /// 3 = elemental
  10614. /// 4 = GN_MIX_COOKING
  10615. /// 5 = GN_MAKEBOMB
  10616. /// 6 = GN_S_PHARMACY
  10617. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10618. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10619. int type = RFIFOW(fd,info->pos[0]);
  10620. unsigned short nameid = RFIFOW(fd,info->pos[1]);
  10621. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10622. short food_idx = -1;
  10623. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10624. return;
  10625. if (pc_istrading(sd)) {
  10626. //Make it fail to avoid shop exploits where you sell something different than you see.
  10627. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10628. clif_menuskill_clear(sd);
  10629. return;
  10630. }
  10631. if( (food_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount)) )
  10632. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount,food_idx-1);
  10633. clif_menuskill_clear(sd);
  10634. }
  10635. /// Answer to repair weapon item selection dialog
  10636. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10637. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10638. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  10639. {
  10640. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10641. return;
  10642. if (pc_istrading(sd)) {
  10643. //Make it fail to avoid shop exploits where you sell something different than you see.
  10644. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10645. clif_menuskill_clear(sd);
  10646. return;
  10647. }
  10648. skill_repairweapon(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10649. //nameid = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10650. //refine = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  10651. //for(i = 0; i<MAX_SLOTS; i++)
  10652. // card[i] = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[3+i]);
  10653. clif_menuskill_clear(sd);
  10654. }
  10655. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10656. /// 0222 <index>.L
  10657. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  10658. {
  10659. int idx;
  10660. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10661. return;
  10662. if (pc_istrading(sd)) {
  10663. //Make it fail to avoid shop exploits where you sell something different than you see.
  10664. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10665. clif_menuskill_clear(sd);
  10666. return;
  10667. }
  10668. idx = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10669. skill_weaponrefine(sd, idx-2);
  10670. clif_menuskill_clear(sd);
  10671. }
  10672. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10673. /// 00b8 <npc id>.L <choice>.B
  10674. /// choice:
  10675. /// 1~254 = menu item
  10676. /// 255 = cancel
  10677. /// NOTE: If there were more than 254 items in the list, choice
  10678. /// overflows to choice%256.
  10679. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10680. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10681. int npc_id = RFIFOL(fd,info->pos[0]);
  10682. uint8 select = RFIFOB(fd,info->pos[1]);
  10683. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10684. #ifdef SECURE_NPCTIMEOUT
  10685. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10686. #endif
  10687. TBL_NPC* nd = map_id2nd(npc_id);
  10688. 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);
  10689. clif_GM_kick(NULL,sd);
  10690. #ifdef SECURE_NPCTIMEOUT
  10691. }
  10692. #endif
  10693. return;
  10694. }
  10695. sd->npc_menu = select;
  10696. npc_scriptcont(sd,npc_id, false);
  10697. }
  10698. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10699. /// 00b9 <npc id>.L
  10700. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10701. {
  10702. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  10703. }
  10704. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10705. /// 0143 <npc id>.L <value>.L
  10706. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10707. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10708. int npcid = RFIFOL(fd,info->pos[0]);
  10709. int amount = (int)RFIFOL(fd,info->pos[1]);
  10710. sd->npc_amount = amount;
  10711. npc_scriptcont(sd, npcid, false);
  10712. }
  10713. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10714. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10715. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10716. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10717. int message_len = RFIFOW(fd,info->pos[0])-8;
  10718. int npcid = RFIFOL(fd,info->pos[1]);
  10719. const char* message = RFIFOCP(fd,info->pos[2]);
  10720. if( message_len <= 0 )
  10721. return; // invalid input
  10722. #if PACKETVER >= 20151001
  10723. message_len++;
  10724. #endif
  10725. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10726. npc_scriptcont(sd, npcid, false);
  10727. }
  10728. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10729. /// 0146 <npc id>.L
  10730. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10731. {
  10732. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10733. return;
  10734. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  10735. }
  10736. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10737. /// 0178 <index>.W
  10738. /// index:
  10739. /// -1 = cancel
  10740. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  10741. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  10742. if (sd->menuskill_id != MC_IDENTIFY)
  10743. return;
  10744. // Ignore the request
  10745. // - Invalid item index
  10746. // - Invalid item ID or item doesn't exist
  10747. // - Item is already identified
  10748. if (idx < 0 || idx >= MAX_INVENTORY ||
  10749. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  10750. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  10751. sd->state.workinprogress = WIP_DISABLE_NONE;
  10752. clif_menuskill_clear(sd);
  10753. return;
  10754. }
  10755. skill_identify(sd, idx);
  10756. clif_menuskill_clear(sd);
  10757. }
  10758. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10759. /// 01ae <name id>.W
  10760. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  10761. unsigned short nameid = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10762. if (pc_istrading(sd)) {
  10763. //Make it fail to avoid shop exploits where you sell something different than you see.
  10764. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10765. clif_menuskill_clear(sd);
  10766. return;
  10767. }
  10768. switch (sd->menuskill_id) {
  10769. case AC_MAKINGARROW:
  10770. skill_arrow_create(sd,nameid);
  10771. break;
  10772. case SA_CREATECON:
  10773. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0,1,-1);
  10774. break;
  10775. case WL_READING_SB:
  10776. skill_spellbook(sd,nameid);
  10777. break;
  10778. case GC_POISONINGWEAPON:
  10779. skill_poisoningweapon(sd,nameid);
  10780. break;
  10781. case NC_MAGICDECOY:
  10782. skill_magicdecoy(sd,nameid);
  10783. break;
  10784. }
  10785. clif_menuskill_clear(sd);
  10786. }
  10787. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10788. /// 01ce <skill id>.L
  10789. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10790. {
  10791. if (sd->menuskill_id != SA_AUTOSPELL)
  10792. return;
  10793. sd->state.workinprogress = WIP_DISABLE_NONE;
  10794. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10795. clif_menuskill_clear(sd);
  10796. }
  10797. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10798. /// 017a <card index>.W
  10799. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10800. {
  10801. if (sd->state.trading != 0)
  10802. return;
  10803. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  10804. }
  10805. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10806. /// 017c <card index>.W <equip index>.W
  10807. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10808. {
  10809. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10810. if (sd->state.trading != 0)
  10811. return;
  10812. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10813. }
  10814. /// Request of character's name by char ID.
  10815. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10816. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10817. /// There are various variants of this packet, some of them have padding between fields.
  10818. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10819. {
  10820. int charid;
  10821. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10822. map_reqnickdb(sd, charid);
  10823. }
  10824. /// /resetskill /resetstate (CZ_RESET).
  10825. /// Request to reset stats or skills.
  10826. /// 0197 <type>.W
  10827. /// type:
  10828. /// 0 = state
  10829. /// 1 = skill
  10830. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10831. char cmd[15];
  10832. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  10833. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10834. else
  10835. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10836. is_atcommand(fd, sd, cmd, 1);
  10837. }
  10838. /// /lb /nlb (CZ_LOCALBROADCAST).
  10839. /// Request to broadcast a message on current map.
  10840. /// 019c <packet len>.W <text>.?B
  10841. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10842. {
  10843. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10844. char command[CHAT_SIZE_MAX+16];
  10845. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10846. char* msg = RFIFOCP(fd,info->pos[1]);
  10847. // as the length varies depending on the command used, just block unreasonably long strings
  10848. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10849. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10850. is_atcommand(fd, sd, command, 1);
  10851. }
  10852. /// Request to move an item from inventory to storage.
  10853. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10854. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10855. /// There are various variants of this packet, some of them have padding between fields.
  10856. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10857. {
  10858. int item_index, item_amount;
  10859. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10860. if (pc_istrading(sd))
  10861. return;
  10862. item_index = RFIFOW(fd,info->pos[0])-2;
  10863. item_amount = RFIFOL(fd,info->pos[1]);
  10864. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10865. return;
  10866. if (sd->state.storage_flag == 1)
  10867. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  10868. else
  10869. if (sd->state.storage_flag == 2)
  10870. storage_guild_storageadd(sd, item_index, item_amount);
  10871. else if (sd->state.storage_flag == 3)
  10872. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  10873. }
  10874. /// Request to move an item from storage to inventory.
  10875. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10876. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10877. /// There are various variants of this packet, some of them have padding between fields.
  10878. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10879. {
  10880. int item_index, item_amount;
  10881. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10882. item_index = RFIFOW(fd,info->pos[0])-1;
  10883. item_amount = RFIFOL(fd,info->pos[1]);
  10884. if (sd->state.storage_flag == 1)
  10885. storage_storageget(sd, &sd->storage, item_index, item_amount);
  10886. else if(sd->state.storage_flag == 2)
  10887. storage_guild_storageget(sd, item_index, item_amount);
  10888. else if(sd->state.storage_flag == 3)
  10889. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  10890. }
  10891. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10892. /// 0129 <index>.W <amount>.L
  10893. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10894. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10895. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10896. int amount = RFIFOL(fd,info->pos[1]);
  10897. if( sd->state.vending )
  10898. return;
  10899. if (!pc_iscarton(sd))
  10900. return;
  10901. if (sd->state.storage_flag == 1)
  10902. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  10903. else if (sd->state.storage_flag == 2)
  10904. storage_guild_storageaddfromcart(sd, idx, amount);
  10905. else if (sd->state.storage_flag == 3)
  10906. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  10907. }
  10908. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10909. /// 0128 <index>.W <amount>.L
  10910. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  10911. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10912. int idx = RFIFOW(fd,info->pos[0]) - 1;
  10913. int amount = RFIFOL(fd,info->pos[1]);
  10914. if( sd->state.vending )
  10915. return;
  10916. if (!pc_iscarton(sd))
  10917. return;
  10918. if (sd->state.storage_flag == 1)
  10919. storage_storagegettocart(sd, &sd->storage, idx, amount);
  10920. else
  10921. if (sd->state.storage_flag == 2)
  10922. storage_guild_storagegettocart(sd, idx, amount);
  10923. else if (sd->state.storage_flag == 3)
  10924. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  10925. }
  10926. /// Request to close storage (CZ_CLOSE_STORE).
  10927. /// 00f7
  10928. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  10929. {
  10930. if( sd->state.storage_flag == 1 )
  10931. storage_storageclose(sd);
  10932. else
  10933. if( sd->state.storage_flag == 2 )
  10934. storage_guild_storageclose(sd);
  10935. else if( sd->state.storage_flag == 3 )
  10936. storage_premiumStorage_close(sd);
  10937. }
  10938. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  10939. /// 023a <info>.W
  10940. /// info:
  10941. /// 0 = password has not been set yet
  10942. /// 1 = storage is password-protected
  10943. /// 8 = too many wrong passwords
  10944. /// ? = ignored
  10945. /// NOTE: This packet is only available on certain non-kRO clients.
  10946. void clif_storagepassword(struct map_session_data* sd, short info)
  10947. {
  10948. int fd = sd->fd;
  10949. WFIFOHEAD(fd,packet_len(0x23a));
  10950. WFIFOW(fd,0) = 0x23a;
  10951. WFIFOW(fd,2) = info;
  10952. WFIFOSET(fd,packet_len(0x23a));
  10953. }
  10954. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  10955. /// 023b <type>.W <password>.16B <new password>.16B
  10956. /// type:
  10957. /// 2 = change password
  10958. /// 3 = check password
  10959. /// NOTE: This packet is only available on certain non-kRO clients.
  10960. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  10961. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10962. // int type = RFIFOW(fd,info->pos[0]);
  10963. // char* password = RFIFOP(fd,info->pos[1]);
  10964. // char* new_password = RFIFOP(fd,info->pos[2]);
  10965. // storage_changepass(sd,password,new_password);
  10966. }
  10967. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  10968. /// 023c <result>.W <error count>.W
  10969. /// result:
  10970. /// 4 = password change success
  10971. /// 5 = password change failure
  10972. /// 6 = password check success
  10973. /// 7 = password check failure
  10974. /// 8 = too many wrong passwords
  10975. /// ? = ignored
  10976. /// NOTE: This packet is only available on certain non-kRO clients.
  10977. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  10978. {
  10979. int fd = sd->fd;
  10980. WFIFOHEAD(fd,packet_len(0x23c));
  10981. WFIFOW(fd,0) = 0x23c;
  10982. WFIFOW(fd,2) = result;
  10983. WFIFOW(fd,4) = error_count;
  10984. WFIFOSET(fd,packet_len(0x23c));
  10985. }
  10986. /// Party creation request
  10987. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  10988. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  10989. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10990. name[NAME_LENGTH-1] = '\0';
  10991. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  10992. clif_displaymessage(fd, msg_txt(sd,227));
  10993. return;
  10994. }
  10995. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  10996. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  10997. return;
  10998. }
  10999. party_create(sd,name,0,0);
  11000. }
  11001. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11002. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11003. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11004. char* name = RFIFOCP(fd,info->pos[0]);
  11005. int item1 = RFIFOB(fd,info->pos[1]);
  11006. int item2 = RFIFOB(fd,info->pos[2]);
  11007. name[NAME_LENGTH-1] = '\0';
  11008. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  11009. clif_displaymessage(fd, msg_txt(sd,227));
  11010. return;
  11011. }
  11012. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11013. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11014. return;
  11015. }
  11016. party_create(sd,name,item1,item2);
  11017. }
  11018. /// Party invitation request
  11019. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11020. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11021. {
  11022. struct map_session_data *t_sd;
  11023. if(map[sd->bl.m].flag.partylock) {// Party locked.
  11024. clif_displaymessage(fd, msg_txt(sd,227));
  11025. return;
  11026. }
  11027. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11028. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11029. clif_noask_sub(sd, t_sd, 1);
  11030. return;
  11031. }
  11032. party_invite(sd, t_sd);
  11033. }
  11034. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11035. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11036. struct map_session_data *t_sd;
  11037. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11038. name[NAME_LENGTH-1] = '\0';
  11039. if(map[sd->bl.m].flag.partylock) {// Party locked.
  11040. clif_displaymessage(fd, msg_txt(sd,227));
  11041. return;
  11042. }
  11043. t_sd = map_nick2sd(name,false);
  11044. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11045. clif_noask_sub(sd, t_sd, 1);
  11046. return;
  11047. }
  11048. party_invite(sd, t_sd);
  11049. }
  11050. /// Party invitation reply
  11051. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11052. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11053. /// flag:
  11054. /// 0 = reject
  11055. /// 1 = accept
  11056. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11057. {
  11058. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11059. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11060. RFIFOL(fd,info->pos[1]));
  11061. }
  11062. //(CZ_PARTY_JOIN_REQ_ACK)
  11063. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11064. {
  11065. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11066. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11067. RFIFOB(fd,info->pos[1]));
  11068. }
  11069. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11070. /// 0100
  11071. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11072. {
  11073. if(map[sd->bl.m].flag.partylock) {// Party locked.
  11074. clif_displaymessage(fd, msg_txt(sd,227));
  11075. return;
  11076. }
  11077. party_leave(sd);
  11078. }
  11079. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11080. /// 0103 <account id>.L <char name>.24B
  11081. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11082. {
  11083. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11084. if(map[sd->bl.m].flag.partylock) {// Party locked.
  11085. clif_displaymessage(fd, msg_txt(sd,227));
  11086. return;
  11087. }
  11088. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11089. RFIFOCP(fd,info->pos[1]));
  11090. }
  11091. /// Request to change party options.
  11092. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11093. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11094. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11095. {
  11096. struct party_data *p;
  11097. int i,expflag;
  11098. int cmd = RFIFOW(fd,0);
  11099. struct s_packet_db* info = &packet_db[cmd];
  11100. if( !sd->status.party_id )
  11101. return;
  11102. p = party_search(sd->status.party_id);
  11103. if( p == NULL )
  11104. return;
  11105. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11106. if( i == MAX_PARTY )
  11107. return; //Shouldn't happen
  11108. if( !p->party.member[i].leader )
  11109. return;
  11110. expflag = RFIFOL(fd,info->pos[0]);
  11111. if(cmd == 0x0102){ //Client can't change the item-field
  11112. party_changeoption(sd, expflag, p->party.item);
  11113. }
  11114. else {
  11115. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11116. party_changeoption(sd, expflag, itemflag);
  11117. }
  11118. }
  11119. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11120. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11121. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11122. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11123. // validate packet and retrieve name and message
  11124. if( !clif_process_message( sd, false, name, message, output ) )
  11125. return;
  11126. party_send_message(sd, output, strlen(output) + 1 );
  11127. }
  11128. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11129. /// 07da <account id>.L
  11130. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11131. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11132. }
  11133. /// Party Booking in KRO [Spiria]
  11134. ///
  11135. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11136. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11137. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11138. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11139. short level = RFIFOW(fd,info->pos[0]);
  11140. short mapid = RFIFOW(fd,info->pos[1]);
  11141. int idxpbj = info->pos[2];
  11142. short job[MAX_PARTY_BOOKING_JOBS];
  11143. int i;
  11144. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11145. job[i] = RFIFOB(fd,idxpbj+i*2);
  11146. party_booking_register(sd, level, mapid, job);
  11147. }
  11148. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11149. /// 0803 <result>.W
  11150. /// result:
  11151. /// 0 = success
  11152. /// 1 = failure
  11153. /// 2 = already registered
  11154. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11155. {
  11156. int fd = sd->fd;
  11157. WFIFOHEAD(fd,packet_len(0x803));
  11158. WFIFOW(fd,0) = 0x803;
  11159. WFIFOW(fd,2) = flag;
  11160. WFIFOSET(fd,packet_len(0x803));
  11161. }
  11162. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11163. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11164. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11165. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11166. short level = RFIFOW(fd,info->pos[0]);
  11167. short mapid = RFIFOW(fd,info->pos[1]);
  11168. short job = RFIFOW(fd,info->pos[2]);
  11169. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11170. short resultcount = RFIFOW(fd,info->pos[4]);
  11171. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11172. }
  11173. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11174. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11175. /// more results:
  11176. /// 0 = no
  11177. /// 1 = yes
  11178. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11179. {
  11180. int i, j;
  11181. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11182. struct party_booking_ad_info *pb_ad;
  11183. WFIFOHEAD(fd,size*count + 5);
  11184. WFIFOW(fd,0) = 0x805;
  11185. WFIFOW(fd,2) = size*count + 5;
  11186. WFIFOB(fd,4) = more_result;
  11187. for(i=0; i<count; i++)
  11188. {
  11189. pb_ad = results[i];
  11190. WFIFOL(fd,i*size+5) = pb_ad->index;
  11191. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11192. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11193. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11194. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11195. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11196. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11197. }
  11198. WFIFOSET(fd,WFIFOW(fd,2));
  11199. }
  11200. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11201. /// 0806
  11202. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11203. {
  11204. if(party_booking_delete(sd))
  11205. clif_PartyBookingDeleteAck(sd, 0);
  11206. }
  11207. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11208. /// 0807 <result>.W
  11209. /// result:
  11210. /// 0 = success
  11211. /// 1 = success (auto-removed expired ad)
  11212. /// 2 = failure
  11213. /// 3 = nothing registered
  11214. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11215. {
  11216. int fd = sd->fd;
  11217. WFIFOHEAD(fd,packet_len(0x807));
  11218. WFIFOW(fd,0) = 0x807;
  11219. WFIFOW(fd,2) = flag;
  11220. WFIFOSET(fd,packet_len(0x807));
  11221. }
  11222. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11223. /// 0808 { <job>.W }*6
  11224. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11225. {
  11226. short job[MAX_PARTY_BOOKING_JOBS];
  11227. int i;
  11228. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11229. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11230. job[i] = RFIFOW(fd,idxpbu+i*2);
  11231. party_booking_update(sd, job);
  11232. }
  11233. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11234. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11235. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11236. {
  11237. int i;
  11238. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11239. if(pb_ad == NULL) return;
  11240. WBUFW(buf,0) = 0x809;
  11241. WBUFL(buf,2) = pb_ad->index;
  11242. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11243. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11244. WBUFW(buf,34) = pb_ad->p_detail.level;
  11245. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11246. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11247. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11248. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11249. }
  11250. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11251. /// 080a <index>.L { <job>.W }*6
  11252. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11253. {
  11254. int i;
  11255. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11256. if(pb_ad == NULL) return;
  11257. WBUFW(buf,0) = 0x80a;
  11258. WBUFL(buf,2) = pb_ad->index;
  11259. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11260. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11261. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11262. }
  11263. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11264. /// 080b <index>.L
  11265. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11266. {
  11267. uint8 buf[6];
  11268. WBUFW(buf,0) = 0x80b;
  11269. WBUFL(buf,2) = index;
  11270. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11271. }
  11272. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11273. /// 012e
  11274. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11275. {
  11276. vending_closevending(sd);
  11277. }
  11278. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11279. /// 0130 <account id>.L
  11280. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11281. {
  11282. if( sd->npc_id ) {// using an NPC
  11283. return;
  11284. }
  11285. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11286. }
  11287. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11288. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11289. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11290. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11291. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11292. int id = (int)RFIFOL(fd,info->pos[1]);
  11293. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11294. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11295. // whether it fails or not, the buy window is closed
  11296. sd->vended_id = 0;
  11297. }
  11298. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11299. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11300. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11301. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11302. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11303. int aid = (int)RFIFOL(fd,info->pos[1]);
  11304. int uid = (int)RFIFOL(fd,info->pos[2]);
  11305. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11306. vending_purchasereq(sd, aid, uid, data, len/4);
  11307. // whether it fails or not, the buy window is closed
  11308. sd->vended_id = 0;
  11309. }
  11310. /// Confirm or cancel the shop preparation window.
  11311. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11312. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11313. /// result:
  11314. /// 0 = canceled
  11315. /// 1 = open
  11316. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11317. int cmd = RFIFOW(fd,0);
  11318. struct s_packet_db* info = &packet_db[cmd];
  11319. short len = (short)RFIFOW(fd,info->pos[0]);
  11320. const char* message = RFIFOCP(fd,info->pos[1]);
  11321. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11322. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11323. len -= 84;
  11324. }
  11325. else { //(CZ_REQ_OPENSTORE2)
  11326. bool flag;
  11327. len -= 85;
  11328. flag = RFIFOB(fd,info->pos[2]) != 0;
  11329. if (!flag) {
  11330. sd->state.prevend = 0;
  11331. sd->state.workinprogress = WIP_DISABLE_NONE;
  11332. }
  11333. }
  11334. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11335. return;
  11336. if( map[sd->bl.m].flag.novending ) {
  11337. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11338. return;
  11339. }
  11340. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11341. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11342. return;
  11343. }
  11344. if( message[0] == '\0' ) // invalid input
  11345. return;
  11346. vending_openvending(sd, message, data, len/8, NULL);
  11347. }
  11348. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11349. /// 0165 <char id>.L <guild name>.24B
  11350. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11351. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11352. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11353. name[NAME_LENGTH-1] = '\0';
  11354. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11355. clif_displaymessage(fd, msg_txt(sd,228));
  11356. return;
  11357. }
  11358. if(sd->clan){
  11359. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11360. return;
  11361. }
  11362. guild_create(sd, name);
  11363. }
  11364. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11365. /// 014d
  11366. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11367. {
  11368. clif_guild_masterormember(sd);
  11369. }
  11370. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11371. /// 014f <type>.L
  11372. /// type:
  11373. /// 0 = basic info
  11374. /// 1 = member manager
  11375. /// 2 = positions
  11376. /// 3 = skills
  11377. /// 4 = expulsion list
  11378. /// 5 = unknown (GM_ALLGUILDLIST)
  11379. /// 6 = notice
  11380. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11381. {
  11382. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11383. if( !sd->status.guild_id && !sd->bg_id )
  11384. return;
  11385. switch( type )
  11386. {
  11387. case 0: // Basic Information Guild, hostile alliance information
  11388. clif_guild_basicinfo(sd);
  11389. clif_guild_allianceinfo(sd);
  11390. break;
  11391. case 1: // Members list, list job title
  11392. clif_guild_positionnamelist(sd);
  11393. clif_guild_memberlist(sd);
  11394. break;
  11395. case 2: // List job title, title information list
  11396. clif_guild_positionnamelist(sd);
  11397. clif_guild_positioninfolist(sd);
  11398. break;
  11399. case 3: // Skill list
  11400. clif_guild_skillinfo(sd);
  11401. break;
  11402. case 4: // Expulsion list
  11403. clif_guild_expulsionlist(sd);
  11404. break;
  11405. default:
  11406. ShowError("clif: guild request info: unknown type %d\n", type);
  11407. break;
  11408. }
  11409. }
  11410. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11411. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11412. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11413. {
  11414. int i;
  11415. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11416. int len = RFIFOW(fd,info->pos[0]);
  11417. int idxgpos = info->pos[1];
  11418. if(!sd->state.gmaster_flag)
  11419. return;
  11420. for(i = idxgpos; i < len; i += 40 ){
  11421. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11422. }
  11423. }
  11424. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11425. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11426. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11427. {
  11428. int i;
  11429. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11430. int len = RFIFOW(fd,info->pos[0]);
  11431. int idxgpos = info->pos[1];
  11432. if(!sd->state.gmaster_flag)
  11433. return;
  11434. // Guild leadership change
  11435. if( len == 16 && RFIFOL(fd,12) == 0 ){
  11436. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11437. clif_msg(sd, GUILD_MASTER_WOE);
  11438. return;
  11439. }
  11440. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){
  11441. clif_msg(sd, GUILD_MASTER_DELAY);
  11442. return;
  11443. }
  11444. guild_gm_change(sd->status.guild_id, RFIFOL(fd, 8));
  11445. return;
  11446. }
  11447. for(i=idxgpos;i<len;i+=12){
  11448. int position = RFIFOL(fd,i+8);
  11449. if( position > 0 ){
  11450. guild_change_memberposition(sd->status.guild_id,RFIFOL(fd,i),RFIFOL(fd,i+4),position);
  11451. }
  11452. }
  11453. }
  11454. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11455. /// 0151 <guild id>.L
  11456. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11457. {
  11458. struct guild* g;
  11459. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11460. if( (g = guild_search(guild_id)) != NULL )
  11461. clif_guild_emblem(sd,g);
  11462. }
  11463. /// Validates data of a guild emblem (compressed bitmap)
  11464. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11465. EMBVALIDATE_SUCCESS = 0,
  11466. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11467. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of battle_config.emblem_transparency_limit
  11468. };
  11469. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11470. {
  11471. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11472. unsigned long buf_len = sizeof(buf);
  11473. int offset = 0;
  11474. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11475. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11476. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11477. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11478. ))
  11479. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11480. if(battle_config.emblem_transparency_limit != 100) {
  11481. int i, transcount = 1, tmp[3];
  11482. for(i = offset; i < buf_len-1; i++) {
  11483. int j = i%3;
  11484. tmp[j] = RBUFL(buf,i);
  11485. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11486. transcount++;
  11487. }
  11488. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  11489. return EMBVALIDATE_ERR_TRANSPARENCY;
  11490. }
  11491. return EMBVALIDATE_SUCCESS;
  11492. }
  11493. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11494. /// 0153 <packet len>.W <emblem data>.?B
  11495. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11496. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11497. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11498. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11499. int emb_val=0;
  11500. if( !emblem_len || !sd->state.gmaster_flag )
  11501. return;
  11502. if(!(battle_config.emblem_woe_change) && is_agit_start() ){
  11503. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11504. return;
  11505. }
  11506. emb_val = clif_validate_emblem(emblem, emblem_len);
  11507. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11508. 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);
  11509. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11510. return;
  11511. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11512. char output[128];
  11513. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11514. 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"
  11515. return;
  11516. }
  11517. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11518. }
  11519. /// Guild notice update request (CZ_GUILD_NOTICE).
  11520. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11521. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11522. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11523. int guild_id = RFIFOL(fd,info->pos[0]);
  11524. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11525. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11526. if(!sd->state.gmaster_flag)
  11527. return;
  11528. // compensate for some client defects when using multilanguage mode
  11529. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11530. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11531. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11532. guild_change_notice(sd, guild_id, msg1, msg2);
  11533. }
  11534. // Helper function for guild invite functions
  11535. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11536. {
  11537. if (t_sd == NULL) // not online or does not exist
  11538. return 1;
  11539. if (map[sd->bl.m].flag.guildlock) {//Guild locked.
  11540. clif_displaymessage(fd, msg_txt(sd,228));
  11541. return 1;
  11542. }
  11543. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11544. clif_noask_sub(sd, t_sd, 2);
  11545. return 1;
  11546. }
  11547. // Players in a clan can not join a guild
  11548. if(t_sd && t_sd->clan){
  11549. return 1;
  11550. }
  11551. guild_invite(sd, t_sd);
  11552. return 0;
  11553. }
  11554. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11555. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11556. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11557. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11558. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11559. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11560. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11561. if (clif_sub_guild_invite(fd, sd, t_sd))
  11562. return;
  11563. }
  11564. /// Guild invite request (/guildinvite)
  11565. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11566. void
  11567. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11568. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  11569. if (clif_sub_guild_invite(fd, sd, t_sd))
  11570. return;
  11571. }
  11572. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11573. /// 016b <guild id>.L <answer>.L
  11574. /// answer:
  11575. /// 0 = refuse
  11576. /// 1 = accept
  11577. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11578. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11579. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11580. RFIFOL(fd,info->pos[1]));
  11581. }
  11582. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11583. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11584. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11585. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11586. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11587. clif_displaymessage(fd, msg_txt(sd,228));
  11588. return;
  11589. }
  11590. if( sd->bg_id ) {
  11591. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11592. return;
  11593. }
  11594. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11595. RFIFOL(fd,info->pos[1]),
  11596. RFIFOL(fd,info->pos[2]),
  11597. RFIFOCP(fd,info->pos[3]));
  11598. }
  11599. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11600. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11601. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11602. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11603. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  11604. { // Guild locked.
  11605. clif_displaymessage(fd, msg_txt(sd,228));
  11606. return;
  11607. }
  11608. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11609. RFIFOL(fd,info->pos[1]),
  11610. RFIFOL(fd,info->pos[2]),
  11611. RFIFOCP(fd,info->pos[3]));
  11612. }
  11613. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11614. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11615. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11616. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11617. // validate packet and retrieve name and message
  11618. if( !clif_process_message( sd, false, name, message, output ) )
  11619. return;
  11620. if( sd->bg_id )
  11621. bg_send_message(sd, output, strlen(output) );
  11622. else
  11623. guild_send_message(sd, output, strlen(output) );
  11624. }
  11625. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11626. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11627. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11628. {
  11629. struct map_session_data *t_sd;
  11630. if(!sd->state.gmaster_flag)
  11631. return;
  11632. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11633. clif_displaymessage(fd, msg_txt(sd,228));
  11634. return;
  11635. }
  11636. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11637. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11638. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  11639. // @noask [LuzZza]
  11640. if(t_sd && t_sd->state.noask) {
  11641. clif_noask_sub(sd, t_sd, 3);
  11642. return;
  11643. }
  11644. guild_reqalliance(sd,t_sd);
  11645. }
  11646. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11647. /// 0172 <inviter account id>.L <answer>.L
  11648. /// answer:
  11649. /// 0 = refuse
  11650. /// 1 = accept
  11651. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11652. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11653. guild_reply_reqalliance(sd,
  11654. RFIFOL(fd,info->pos[0]),
  11655. RFIFOL(fd,info->pos[1]));
  11656. }
  11657. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11658. /// 0183 <opponent guild id>.L <relation>.L
  11659. /// relation:
  11660. /// 0 = Ally
  11661. /// 1 = Enemy
  11662. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11663. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11664. if(!sd->state.gmaster_flag)
  11665. return;
  11666. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11667. clif_displaymessage(fd, msg_txt(sd,228));
  11668. return;
  11669. }
  11670. guild_delalliance(sd,
  11671. RFIFOL(fd,info->pos[0]),
  11672. RFIFOL(fd,info->pos[1]));
  11673. }
  11674. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11675. /// 0180 <account id>.L
  11676. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11677. {
  11678. struct map_session_data *t_sd;
  11679. if(!sd->state.gmaster_flag)
  11680. return;
  11681. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11682. clif_displaymessage(fd, msg_txt(sd,228));
  11683. return;
  11684. }
  11685. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11686. // @noask [LuzZza]
  11687. if(t_sd && t_sd->state.noask) {
  11688. clif_noask_sub(sd, t_sd, 4);
  11689. return;
  11690. }
  11691. guild_opposition(sd,t_sd);
  11692. }
  11693. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11694. /// 015d <key>.40B
  11695. /// key:
  11696. /// now guild name; might have been (intended) email, since the
  11697. /// field name and size is same as the one in CH_DELETE_CHAR.
  11698. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11699. {
  11700. if( map[sd->bl.m].flag.guildlock ) { //Guild locked.
  11701. clif_displaymessage(fd, msg_txt(sd,228));
  11702. return;
  11703. }
  11704. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11705. }
  11706. /// Pet
  11707. ///
  11708. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11709. /// 01a1 <type>.B
  11710. /// type:
  11711. /// 0 = pet information
  11712. /// 1 = feed
  11713. /// 2 = performance
  11714. /// 3 = return to egg
  11715. /// 4 = unequip accessory
  11716. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11717. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11718. }
  11719. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11720. /// 019f <id>.L
  11721. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11722. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11723. }
  11724. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11725. /// 01a7 <index>.W
  11726. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11727. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11728. return;
  11729. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11730. clif_menuskill_clear(sd);
  11731. }
  11732. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11733. /// 01a9 <data>.L
  11734. /// data:
  11735. /// is either emotion (@see enum emotion_type) or a compound value
  11736. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11737. /// entry (given in parentheses) in data\pettalktable.xml
  11738. /// act id:
  11739. /// 0 = feeding
  11740. /// 1 = hunting
  11741. /// 2 = danger
  11742. /// 3 = dead
  11743. /// 4 = normal (stand)
  11744. /// 5 = special performance (perfor_s)
  11745. /// 6 = level up (levelup)
  11746. /// 7 = performance 1 (perfor_1)
  11747. /// 8 = performance 2 (perfor_2)
  11748. /// 9 = performance 3 (perfor_3)
  11749. /// 10 = log-in greeting (connect)
  11750. /// hungry value:
  11751. /// 0 = very hungry (hungry)
  11752. /// 1 = hungry (bit_hungry)
  11753. /// 2 = satisfied (noting)
  11754. /// 3 = stuffed (full)
  11755. /// 4 = full (so_full)
  11756. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11757. {
  11758. if(sd->pd)
  11759. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11760. }
  11761. /// Request to change pet's name (CZ_RENAME_PET).
  11762. /// 01a5 <name>.24B
  11763. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11764. {
  11765. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11766. }
  11767. /// /kill (CZ_DISCONNECT_CHARACTER).
  11768. /// Request to disconnect a character.
  11769. /// 00cc <account id>.L
  11770. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11771. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11772. {
  11773. struct block_list *target;
  11774. int tid;
  11775. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11776. target = map_id2bl(tid);
  11777. if (!target) {
  11778. clif_GM_kickack(sd, 0);
  11779. return;
  11780. }
  11781. switch (target->type) {
  11782. case BL_PC:
  11783. {
  11784. char command[NAME_LENGTH+6];
  11785. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11786. is_atcommand(fd, sd, command, 1);
  11787. }
  11788. break;
  11789. /**
  11790. * This one does not invoke any atcommand, so we need to check for permissions.
  11791. */
  11792. case BL_MOB:
  11793. {
  11794. char command[100];
  11795. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11796. clif_GM_kickack(sd, 0);
  11797. return;
  11798. }
  11799. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11800. log_atcommand(sd, command);
  11801. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11802. }
  11803. break;
  11804. case BL_NPC:
  11805. {
  11806. struct npc_data* nd = (struct npc_data *)target;
  11807. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11808. npc_unload_duplicates(nd);
  11809. npc_unload(nd,true);
  11810. npc_read_event_script();
  11811. }
  11812. }
  11813. break;
  11814. default:
  11815. clif_GM_kickack(sd, 0);
  11816. }
  11817. }
  11818. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11819. /// Request to disconnect all characters.
  11820. /// 00ce
  11821. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11822. char cmd[15];
  11823. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11824. is_atcommand(fd, sd, cmd, 1);
  11825. }
  11826. /// /remove (CZ_REMOVE_AID).
  11827. /// Request to warp to a character with given login ID.
  11828. /// 01ba <account name>.24B
  11829. /// /shift (CZ_SHIFT).
  11830. /// Request to warp to a character with given name.
  11831. /// 01bb <char name>.24B
  11832. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11833. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11834. char *player_name;
  11835. char command[NAME_LENGTH+8];
  11836. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11837. player_name[NAME_LENGTH-1] = '\0';
  11838. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11839. is_atcommand(fd, sd, command, 1);
  11840. }
  11841. /// /remove (CZ_REMOVE_AID_SSO).
  11842. /// Request to warp to a character with given account ID.
  11843. /// 0843 <account id>.L
  11844. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  11845. {
  11846. uint32 account_id;
  11847. struct map_session_data* pl_sd;
  11848. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11849. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11850. char command[NAME_LENGTH+8];
  11851. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11852. is_atcommand(fd, sd, command, 1);
  11853. }
  11854. }
  11855. /// /recall (CZ_RECALL).
  11856. /// Request to summon a player with given login ID to own position.
  11857. /// 01bc <account name>.24B
  11858. /// /summon (CZ_RECALL_GID).
  11859. /// Request to summon a player with given name to own position.
  11860. /// 01bd <char name>.24B
  11861. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11862. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11863. char *player_name;
  11864. char command [NAME_LENGTH+8];
  11865. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11866. player_name[NAME_LENGTH-1] = '\0';
  11867. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11868. is_atcommand(fd, sd, command, 1);
  11869. }
  11870. /// /recall (CZ_RECALL_SSO).
  11871. /// Request to summon a player with given account ID to own position.
  11872. /// 0842 <account id>.L
  11873. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11874. {
  11875. uint32 account_id;
  11876. struct map_session_data* pl_sd;
  11877. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11878. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11879. char command[NAME_LENGTH+8];
  11880. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11881. is_atcommand(fd, sd, command, 1);
  11882. }
  11883. }
  11884. /// /item /monster (CZ_ITEM_CREATE).
  11885. /// Request to execute GM commands.
  11886. /// Usage:
  11887. /// /item n - summon n monster or acquire n item/s
  11888. /// /item money - grants 2147483647 zenies
  11889. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  11890. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  11891. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  11892. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  11893. /// /item cap_n - capture n monster as pet.(not yet implemented)
  11894. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  11895. /// 013f <item/mob name>.24B
  11896. /// 09ce <item/mob name>.100B [Ind/Yommy]
  11897. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  11898. {
  11899. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11900. int mob_id = 0;
  11901. struct item_data *id = NULL;
  11902. struct mob_db *mob = NULL;
  11903. StringBuf command;
  11904. char *str;
  11905. //#if PACKETVER >= 20131218
  11906. // char str[100];
  11907. //#else
  11908. // char str[24];
  11909. //#endif
  11910. str = RFIFOCP(fd,info->pos[0]);
  11911. if (!str || str[0] == '\0')
  11912. return;
  11913. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  11914. return;
  11915. trim(str);
  11916. // Zeny
  11917. if( strcmpi(str, "money") == 0 ) {
  11918. StringBuf_Init(&command);
  11919. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  11920. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11921. StringBuf_Destroy(&command);
  11922. return;
  11923. }
  11924. // Item
  11925. if( (id = itemdb_searchname(str)) ) {
  11926. StringBuf_Init(&command);
  11927. if( !itemdb_isstackable2(id) ) //Nonstackable
  11928. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  11929. else {
  11930. if (id->flag.guid)
  11931. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  11932. else
  11933. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  11934. }
  11935. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11936. StringBuf_Destroy(&command);
  11937. return;
  11938. }
  11939. // Monster
  11940. if ((mob_id = mobdb_searchname(str)) == 0)
  11941. mob_id = mobdb_checkid(atoi(str));
  11942. if( (mob = mob_db(mob_id)) ) {
  11943. StringBuf_Init(&command);
  11944. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  11945. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11946. StringBuf_Destroy(&command);
  11947. return;
  11948. }
  11949. }
  11950. /// /hide (CZ_CHANGE_EFFECTSTATE).
  11951. /// 019d <effect state>.L
  11952. /// effect state:
  11953. /// TODO: Any OPTION_* ?
  11954. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  11955. char cmd[6];
  11956. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  11957. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  11958. is_atcommand(fd, sd, cmd, 1);
  11959. }
  11960. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  11961. /// 0149 <account id>.L <type>.B <value>.W
  11962. /// type:
  11963. /// 0 = positive points
  11964. /// 1 = negative points
  11965. /// 2 = self mute (+10 minutes)
  11966. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  11967. {
  11968. int id, type, value;
  11969. struct map_session_data *dstsd;
  11970. char command[NAME_LENGTH+15];
  11971. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11972. id = RFIFOL(fd,info->pos[0]);
  11973. type = RFIFOB(fd,info->pos[1]);
  11974. value = RFIFOW(fd,info->pos[2]);
  11975. if( type == 0 )
  11976. value = -value;
  11977. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  11978. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  11979. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  11980. return;
  11981. dstsd = map_id2sd(id);
  11982. if( dstsd == NULL )
  11983. return;
  11984. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  11985. is_atcommand(fd, sd, command, 1);
  11986. }
  11987. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  11988. /// GM adjustment of a player's manner value by -60.
  11989. /// 0212 <char name>.24B
  11990. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  11991. {
  11992. char command[NAME_LENGTH+15];
  11993. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11994. name[NAME_LENGTH-1] = '\0';
  11995. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  11996. is_atcommand(fd, sd, command, 1);
  11997. }
  11998. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  11999. /// 01e0 <account id>.L <account name>.24B
  12000. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12001. {
  12002. WFIFOHEAD(fd,packet_len(0x1e0));
  12003. WFIFOW(fd,0) = 0x1e0;
  12004. WFIFOL(fd,2) = account_id;
  12005. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12006. WFIFOSET(fd,packet_len(0x1e0));
  12007. }
  12008. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12009. /// 01df <account id>.L
  12010. //! TODO: Figure out how does this actually work
  12011. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12012. {
  12013. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12014. /*
  12015. char query[30];
  12016. safesnprintf(query,sizeof(query),"%d", account_id);
  12017. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12018. */
  12019. clif_account_name(fd, account_id, "");
  12020. }
  12021. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12022. /// GM single cell type change request.
  12023. /// 0198 <x>.W <y>.W <type>.W
  12024. /// type:
  12025. /// 0 = not walkable
  12026. /// 1 = walkable
  12027. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12028. {
  12029. int x,y,type;
  12030. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12031. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12032. return;
  12033. x = RFIFOW(fd,info->pos[0]);
  12034. y = RFIFOW(fd,info->pos[1]);
  12035. type = RFIFOW(fd,info->pos[2]);
  12036. map_setgatcell(sd->bl.m,x,y,type);
  12037. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12038. //FIXME: once players leave the map, the client 'forgets' this information.
  12039. }
  12040. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12041. /// Request to allow/deny whispers from a nick.
  12042. /// 00cf <nick>.24B <type>.B
  12043. /// type:
  12044. /// 0 = (/ex nick) deny speech from nick
  12045. /// 1 = (/in nick) allow speech from nick
  12046. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12047. {
  12048. char* nick;
  12049. uint8 type;
  12050. int i;
  12051. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12052. nick = RFIFOCP(fd,info->pos[0]);
  12053. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12054. type = RFIFOB(fd,info->pos[1]);
  12055. if( type == 0 ) { // Add name to ignore list (block)
  12056. if (strcmp(wisp_server_name, nick) == 0) {
  12057. clif_wisexin(sd, type, 1); // fail
  12058. return;
  12059. }
  12060. // try to find a free spot, while checking for duplicates at the same time
  12061. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12062. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12063. clif_wisexin(sd, type, 2); // too many blocks
  12064. return;
  12065. }
  12066. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12067. clif_wisexin(sd, type, 0); // Aegis reports success.
  12068. return;
  12069. }
  12070. //Insert in position i
  12071. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12072. } else { // Remove name from ignore list (unblock)
  12073. // find entry
  12074. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12075. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  12076. clif_wisexin(sd, type, 1); // fail
  12077. return;
  12078. }
  12079. // move everything one place down to overwrite removed entry
  12080. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12081. // wipe last entry
  12082. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12083. }
  12084. clif_wisexin(sd, type, 0); // success
  12085. }
  12086. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12087. /// Request to allow/deny all whispers.
  12088. /// 00d0 <type>.B
  12089. /// type:
  12090. /// 0 = (/exall) deny all speech
  12091. /// 1 = (/inall) allow all speech
  12092. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12093. {
  12094. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12095. if( type == 0 ) {// Deny all
  12096. if( sd->state.ignoreAll ) {
  12097. flag = 1; // fail
  12098. } else {
  12099. sd->state.ignoreAll = 1;
  12100. flag = 0; // success
  12101. }
  12102. } else {//Unblock everyone
  12103. if( sd->state.ignoreAll ) {
  12104. sd->state.ignoreAll = 0;
  12105. flag = 0; // success
  12106. } else {
  12107. if (sd->ignore[0].name[0] != '\0')
  12108. { //Wipe the ignore list.
  12109. memset(sd->ignore, 0, sizeof(sd->ignore));
  12110. flag = 0; // success
  12111. } else {
  12112. flag = 1; // fail
  12113. }
  12114. }
  12115. }
  12116. clif_wisall(sd, type, flag);
  12117. }
  12118. /// Whisper ignore list (ZC_WHISPER_LIST).
  12119. /// 00d4 <packet len>.W { <char name>.24B }*
  12120. void clif_PMIgnoreList(struct map_session_data* sd)
  12121. {
  12122. int i, fd = sd->fd;
  12123. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12124. WFIFOW(fd,0) = 0xd4;
  12125. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12126. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12127. }
  12128. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12129. WFIFOSET(fd,WFIFOW(fd,2));
  12130. }
  12131. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12132. /// 00d3
  12133. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12134. {
  12135. clif_PMIgnoreList(sd);
  12136. }
  12137. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12138. /// 01e7
  12139. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12140. {
  12141. if (sd->state.doridori) return;
  12142. switch (sd->class_&MAPID_UPPERMASK) {
  12143. case MAPID_SOUL_LINKER:
  12144. case MAPID_STAR_GLADIATOR:
  12145. case MAPID_TAEKWON:
  12146. if (!sd->state.rest)
  12147. break;
  12148. case MAPID_SUPER_NOVICE:
  12149. case MAPID_SUPER_BABY:
  12150. case MAPID_SUPER_NOVICE_E:
  12151. case MAPID_SUPER_BABY_E:
  12152. sd->state.doridori=1;
  12153. break;
  12154. }
  12155. }
  12156. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12157. /// 01ed
  12158. /// Note: This packet is caused by 7 lines of any text, followed by
  12159. /// the prayer and an another line of any text. The prayer is
  12160. /// defined by lines 790~793 in data\msgstringtable.txt
  12161. /// "Dear angel, can you hear my voice?"
  12162. /// "I am" (space separated player name) "Super Novice~"
  12163. /// "Help me out~ Please~ T_T"
  12164. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12165. {
  12166. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12167. unsigned int next = pc_nextbaseexp(sd);
  12168. if( next ) {
  12169. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  12170. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12171. 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]
  12172. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12173. }
  12174. }
  12175. }
  12176. }
  12177. /// Friends List
  12178. ///
  12179. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12180. /// 0206 <account id>.L <char id>.L <state>.B
  12181. /// state:
  12182. /// 0 = online
  12183. /// 1 = offline
  12184. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12185. {
  12186. int i, fd = sd->fd;
  12187. //Seek friend.
  12188. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12189. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12190. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12191. return; //Not found
  12192. WFIFOHEAD(fd,packet_len(0x206));
  12193. WFIFOW(fd, 0) = 0x206;
  12194. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12195. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12196. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12197. WFIFOSET(fd, packet_len(0x206));
  12198. }
  12199. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12200. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12201. {
  12202. uint32 account_id, char_id, online;
  12203. account_id = va_arg(ap, int);
  12204. char_id = va_arg(ap, int);
  12205. online = va_arg(ap, int);
  12206. clif_friendslist_toggle(sd, account_id, char_id, online);
  12207. return 0;
  12208. }
  12209. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12210. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12211. void clif_friendslist_send(struct map_session_data *sd)
  12212. {
  12213. int i = 0, n, fd = sd->fd;
  12214. // Send friends list
  12215. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  12216. WFIFOW(fd, 0) = 0x201;
  12217. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12218. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  12219. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  12220. safestrncpy(WFIFOCP(fd, 4 + 32 * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  12221. }
  12222. if (i) {
  12223. WFIFOW(fd,2) = 4 + 32 * i;
  12224. WFIFOSET(fd, WFIFOW(fd,2));
  12225. }
  12226. for (n = 0; n < i; n++) { //Sending the online players
  12227. if (map_charid2sd(sd->status.friends[n].char_id))
  12228. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12229. }
  12230. }
  12231. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12232. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12233. /// result:
  12234. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12235. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12236. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12237. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12238. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12239. {
  12240. int fd;
  12241. nullpo_retv(sd);
  12242. fd = sd->fd;
  12243. WFIFOHEAD(fd,packet_len(0x209));
  12244. WFIFOW(fd,0) = 0x209;
  12245. WFIFOW(fd,2) = type;
  12246. if (f_sd) {
  12247. WFIFOL(fd,4) = f_sd->status.account_id;
  12248. WFIFOL(fd,8) = f_sd->status.char_id;
  12249. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12250. }
  12251. WFIFOSET(fd, packet_len(0x209));
  12252. }
  12253. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12254. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12255. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12256. {
  12257. int fd = sd->fd;
  12258. WFIFOHEAD(fd,packet_len(0x207));
  12259. WFIFOW(fd,0) = 0x207;
  12260. WFIFOL(fd,2) = account_id;
  12261. WFIFOL(fd,6) = char_id;
  12262. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12263. WFIFOSET(fd,packet_len(0x207));
  12264. }
  12265. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12266. /// 0202 <name>.24B
  12267. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12268. {
  12269. struct map_session_data *f_sd;
  12270. int i;
  12271. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12272. // Friend doesn't exist (no player with this name)
  12273. if (f_sd == NULL) {
  12274. clif_displaymessage(fd, msg_txt(sd,3));
  12275. return;
  12276. }
  12277. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12278. return;
  12279. }
  12280. // ensure that the request player's friend list is not full
  12281. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12282. if( i == MAX_FRIENDS ){
  12283. clif_friendslist_reqack(sd, f_sd, 2);
  12284. return;
  12285. }
  12286. // @noask [LuzZza]
  12287. if(f_sd->state.noask) {
  12288. clif_noask_sub(sd, f_sd, 5);
  12289. return;
  12290. }
  12291. // Friend already exists
  12292. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12293. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12294. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12295. return;
  12296. }
  12297. }
  12298. f_sd->friend_req = sd->status.char_id;
  12299. sd->friend_req = f_sd->status.char_id;
  12300. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12301. }
  12302. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12303. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12304. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12305. /// reply:
  12306. /// 0 = rejected
  12307. /// 1 = accepted
  12308. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12309. {
  12310. struct map_session_data *f_sd;
  12311. uint32 account_id;
  12312. char reply;
  12313. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12314. account_id = RFIFOL(fd,info->pos[0]);
  12315. //char_id = RFIFOL(fd,info->pos[1]);
  12316. #if PACKETVER < 6
  12317. reply = RFIFOB(fd,info->pos[2]);
  12318. #else
  12319. reply = RFIFOL(fd,info->pos[2]);
  12320. #endif
  12321. if( sd->bl.id == account_id ) {// adding oneself as friend
  12322. return;
  12323. }
  12324. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12325. if (f_sd == NULL)
  12326. return;
  12327. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12328. clif_friendslist_reqack(f_sd, sd, 1);
  12329. else {
  12330. int i;
  12331. // Find an empty slot
  12332. for (i = 0; i < MAX_FRIENDS; i++)
  12333. if (f_sd->status.friends[i].char_id == 0)
  12334. break;
  12335. if (i == MAX_FRIENDS) {
  12336. clif_friendslist_reqack(f_sd, sd, 2);
  12337. return;
  12338. }
  12339. f_sd->status.friends[i].account_id = sd->status.account_id;
  12340. f_sd->status.friends[i].char_id = sd->status.char_id;
  12341. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12342. clif_friendslist_reqack(f_sd, sd, 0);
  12343. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12344. if (battle_config.friend_auto_add) {
  12345. // Also add f_sd to sd's friendlist.
  12346. for (i = 0; i < MAX_FRIENDS; i++) {
  12347. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12348. return; //No need to add anything.
  12349. if (sd->status.friends[i].char_id == 0)
  12350. break;
  12351. }
  12352. if (i == MAX_FRIENDS) {
  12353. clif_friendslist_reqack(sd, f_sd, 2);
  12354. return;
  12355. }
  12356. sd->status.friends[i].account_id = f_sd->status.account_id;
  12357. sd->status.friends[i].char_id = f_sd->status.char_id;
  12358. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12359. clif_friendslist_reqack(sd, f_sd, 0);
  12360. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12361. }
  12362. }
  12363. }
  12364. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12365. /// 0203 <account id>.L <char id>.L
  12366. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12367. {
  12368. struct map_session_data *f_sd = NULL;
  12369. uint32 account_id, char_id;
  12370. int i, j;
  12371. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12372. account_id = RFIFOL(fd,info->pos[0]);
  12373. char_id = RFIFOL(fd,info->pos[1]);
  12374. // Search friend
  12375. for (i = 0; i < MAX_FRIENDS &&
  12376. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12377. if (i == MAX_FRIENDS) {
  12378. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12379. return;
  12380. }
  12381. //remove from friend's list first
  12382. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12383. for (i = 0; i < MAX_FRIENDS &&
  12384. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12385. if (i != MAX_FRIENDS) {
  12386. // move all chars up
  12387. for(j = i + 1; j < MAX_FRIENDS; j++)
  12388. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12389. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12390. //should the guy be notified of some message? we should add it here if so
  12391. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12392. WFIFOW(f_sd->fd,0) = 0x20a;
  12393. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12394. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12395. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12396. }
  12397. } else { //friend not online -- ask char server to delete from his friendlist
  12398. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12399. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12400. return;
  12401. }
  12402. }
  12403. // We can now delete from original requester
  12404. for (i = 0; i < MAX_FRIENDS &&
  12405. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12406. // move all chars up
  12407. for(j = i + 1; j < MAX_FRIENDS; j++)
  12408. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12409. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12410. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12411. WFIFOHEAD(fd,packet_len(0x20a));
  12412. WFIFOW(fd,0) = 0x20a;
  12413. WFIFOL(fd,2) = account_id;
  12414. WFIFOL(fd,6) = char_id;
  12415. WFIFOSET(fd, packet_len(0x20a));
  12416. }
  12417. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12418. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12419. void clif_PVPInfo(struct map_session_data* sd)
  12420. {
  12421. int fd = sd->fd;
  12422. WFIFOHEAD(fd,packet_len(0x210));
  12423. WFIFOW(fd,0) = 0x210;
  12424. WFIFOL(fd,2) = sd->status.char_id;
  12425. WFIFOL(fd,6) = sd->status.account_id;
  12426. WFIFOL(fd,10) = sd->pvp_won; // times won
  12427. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12428. WFIFOL(fd,18) = sd->pvp_point;
  12429. WFIFOSET(fd, packet_len(0x210));
  12430. }
  12431. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12432. /// 020f <char id>.L <account id>.L
  12433. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12434. {
  12435. // TODO: Is there a way to use this on an another player (char/acc id)?
  12436. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12437. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12438. clif_PVPInfo(sd);
  12439. }
  12440. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12441. /// 0254 <which>.B
  12442. /// which: (unused atm for security purpose)
  12443. /// 0 = sun
  12444. /// 1 = moon
  12445. /// 2 = star
  12446. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12447. {
  12448. int i;
  12449. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12450. if (sd->menuskill_id != SG_FEEL)
  12451. return;
  12452. i = sd->menuskill_val-1;
  12453. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12454. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12455. sd->feel_map[i].m = sd->bl.m;
  12456. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12457. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12458. // clif_misceffect2(&sd->bl, 0x1b0);
  12459. // clif_misceffect2(&sd->bl, 0x21f);
  12460. clif_feel_info(sd, i, 0);
  12461. clif_menuskill_clear(sd);
  12462. }
  12463. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12464. /// 0253 <which>.B
  12465. /// which:
  12466. /// 0 = sun
  12467. /// 1 = moon
  12468. /// 2 = star
  12469. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12470. {
  12471. WFIFOHEAD(fd,packet_len(0x253));
  12472. WFIFOW(fd,0)=0x253;
  12473. WFIFOB(fd,2)=TOB(skill_lv-1);
  12474. WFIFOSET(fd, packet_len(0x253));
  12475. sd->menuskill_id = SG_FEEL;
  12476. sd->menuskill_val = skill_lv;
  12477. }
  12478. /// Request to change homunculus' name (CZ_RENAME_MER).
  12479. /// 0231 <name>.24B
  12480. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12481. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12482. }
  12483. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12484. /// 0234 <id>.L
  12485. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12486. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12487. struct block_list *bl = NULL;
  12488. struct unit_data *ud = NULL;
  12489. if( sd->md && sd->md->bl.id == id )
  12490. bl = &sd->md->bl;
  12491. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12492. bl = &sd->hd->bl; // Moving Homunculus
  12493. else
  12494. return;
  12495. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12496. ud = unit_bl2ud(bl);
  12497. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12498. }
  12499. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12500. /// 0232 <id>.L <position data>.3B
  12501. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12502. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12503. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12504. struct block_list *bl = NULL;
  12505. short x, y;
  12506. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12507. if( sd->md && sd->md->bl.id == id )
  12508. bl = &sd->md->bl; // Moving Mercenary
  12509. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12510. bl = &sd->hd->bl; // Moving Homunculus
  12511. else
  12512. return;
  12513. unit_walktoxy(bl, x, y, 4);
  12514. }
  12515. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12516. /// 0233 <id>.L <target id>.L <action>.B
  12517. /// action:
  12518. /// always 0
  12519. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12520. {
  12521. struct block_list *bl = NULL;
  12522. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12523. int id = RFIFOL(fd,info->pos[0]);
  12524. int target_id = RFIFOL(fd,info->pos[1]);
  12525. int action_type = RFIFOB(fd,info->pos[2]);
  12526. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12527. bl = &sd->hd->bl;
  12528. else if( sd->md && sd->md->bl.id == id )
  12529. bl = &sd->md->bl;
  12530. else return;
  12531. unit_stop_attack(bl);
  12532. unit_attack(bl, target_id, action_type != 0);
  12533. }
  12534. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12535. /// 022d <type>.W <command>.B
  12536. /// type:
  12537. /// always 0
  12538. /// command:
  12539. /// 0 = homunculus information
  12540. /// 1 = feed
  12541. /// 2 = delete
  12542. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12543. { //[orn]
  12544. int cmd = RFIFOW(fd,0);
  12545. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12546. if(!hom_is_active(sd->hd))
  12547. return;
  12548. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12549. }
  12550. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12551. /// 0292
  12552. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12553. {
  12554. short item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  12555. uint8 hp = 100, sp = 100;
  12556. if (item_position < 0) {
  12557. if (sd->sc.data[SC_LIGHT_OF_REGENE]) {
  12558. // HP restored
  12559. hp = sd->sc.data[SC_LIGHT_OF_REGENE]->val2;
  12560. sp = 0;
  12561. }
  12562. else
  12563. return;
  12564. }
  12565. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  12566. return;
  12567. if (!status_revive(&sd->bl, hp, sp))
  12568. return;
  12569. if (item_position < 0)
  12570. status_change_end(&sd->bl, SC_LIGHT_OF_REGENE, INVALID_TIMER);
  12571. else
  12572. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  12573. clif_skill_nodamage(&sd->bl, &sd->bl, ALL_RESURRECTION, 4, 1);
  12574. }
  12575. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12576. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12577. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12578. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12579. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12580. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12581. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12582. void clif_check(int fd, struct map_session_data* pl_sd)
  12583. {
  12584. WFIFOHEAD(fd,packet_len(0x214));
  12585. WFIFOW(fd, 0) = 0x214;
  12586. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12587. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12588. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12589. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12590. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12591. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12592. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12593. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12594. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12595. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12596. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12597. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12598. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12599. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12600. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12601. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12602. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12603. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12604. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12605. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12606. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12607. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12608. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12609. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12610. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12611. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12612. WFIFOSET(fd,packet_len(0x214));
  12613. }
  12614. /// /check (CZ_REQ_STATUS_GM).
  12615. /// Request character's status values.
  12616. /// 0213 <char name>.24B
  12617. void clif_parse_Check(int fd, struct map_session_data *sd)
  12618. {
  12619. char charname[NAME_LENGTH];
  12620. struct map_session_data* pl_sd;
  12621. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12622. return;
  12623. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12624. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12625. {
  12626. return;
  12627. }
  12628. clif_check(fd, pl_sd);
  12629. }
  12630. /// MAIL SYSTEM
  12631. /// By Zephyrus
  12632. ///
  12633. /// Notification about the result of adding an item to mail
  12634. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  12635. /// result:
  12636. /// 0 = success
  12637. /// 1 = failure
  12638. /// 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)
  12639. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  12640. /// result:
  12641. /// 0 = success
  12642. /// 1 = over weight
  12643. /// 2 = fatal error
  12644. void clif_Mail_setattachment(struct map_session_data* sd, int index, int amount, uint8 flag)
  12645. {
  12646. int fd = sd->fd;
  12647. #if PACKETVER < 20150513
  12648. WFIFOHEAD(fd,packet_len(0x255));
  12649. WFIFOW(fd,0) = 0x255;
  12650. WFIFOW(fd,2) = index;
  12651. WFIFOB(fd,4) = flag;
  12652. WFIFOSET(fd,packet_len(0x255));
  12653. #else
  12654. struct item* item = &sd->inventory.u.items_inventory[index-2];
  12655. int i, total = 0;
  12656. WFIFOHEAD(fd, 53);
  12657. WFIFOW(fd, 0) = 0xa05;
  12658. WFIFOB(fd, 2) = flag;
  12659. WFIFOW(fd, 3) = index;
  12660. WFIFOW(fd, 5) = amount;
  12661. WFIFOW(fd, 7) = item->nameid;
  12662. WFIFOB(fd, 9) = itemtype(item->nameid);
  12663. WFIFOB(fd, 10) = item->identify;
  12664. WFIFOB(fd, 11) = item->attribute;
  12665. WFIFOB(fd, 12) = item->refine;
  12666. clif_addcards(WFIFOP(fd,13), item);
  12667. clif_add_random_options(WFIFOP(fd,21), item);
  12668. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  12669. if( sd->mail.item[i].nameid == 0 ){
  12670. break;
  12671. }
  12672. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  12673. }
  12674. WFIFOW(fd, 46) = total;
  12675. // 5 empty unknown bytes
  12676. memset(WFIFOP(fd, 48), 0, 5);
  12677. WFIFOSET(fd, 53);
  12678. #endif
  12679. }
  12680. /// Notification about the result of retrieving a mail attachment
  12681. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  12682. /// result:
  12683. /// 0 = success
  12684. /// 1 = failure
  12685. /// 2 = too many items
  12686. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  12687. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  12688. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  12689. int fd = sd->fd;
  12690. #if PACKETVER < 20150513
  12691. WFIFOHEAD(fd,packet_len(0x245));
  12692. WFIFOW(fd,0) = 0x245;
  12693. WFIFOB(fd,2) = result;
  12694. WFIFOSET(fd,packet_len(0x245));
  12695. #else
  12696. switch( type ){
  12697. case MAIL_ATT_ITEM:
  12698. case MAIL_ATT_ZENY:
  12699. break;
  12700. default:
  12701. return;
  12702. }
  12703. WFIFOHEAD(fd, 12);
  12704. WFIFOW(fd, 0) = type == MAIL_ATT_ZENY ? 0x9f2 : 0x9f4;
  12705. WFIFOQ(fd, 2) = msg->id;
  12706. WFIFOB(fd, 10) = msg->type;
  12707. WFIFOB(fd, 11) = result;
  12708. WFIFOSET(fd, 12);
  12709. clif_Mail_refreshinbox( sd, msg->type, 0 );
  12710. #endif
  12711. }
  12712. /// Notification about the result of sending a mail
  12713. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  12714. /// result:
  12715. /// 0 = success
  12716. /// 1 = recipinent does not exist
  12717. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  12718. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  12719. int fd = sd->fd;
  12720. #if PACKETVER < 20150513
  12721. WFIFOHEAD(fd,packet_len(0x249));
  12722. WFIFOW(fd,0) = 0x249;
  12723. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  12724. WFIFOSET(fd,packet_len(0x249));
  12725. #else
  12726. WFIFOHEAD(fd, 3);
  12727. WFIFOW(fd, 0) = 0x9ed;
  12728. WFIFOB(fd, 2) = result;
  12729. WFIFOSET(fd, 3);
  12730. #endif
  12731. }
  12732. /// Notification about the result of deleting a mail.
  12733. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  12734. /// result:
  12735. /// 0 = success
  12736. /// 1 = failure
  12737. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  12738. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  12739. int fd = sd->fd;
  12740. #if PACKETVER < 20150513
  12741. WFIFOHEAD(fd, packet_len(0x257));
  12742. WFIFOW(fd,0) = 0x257;
  12743. WFIFOL(fd,2) = msg->id;
  12744. WFIFOW(fd,6) = !success;
  12745. WFIFOSET(fd, packet_len(0x257));
  12746. #else
  12747. // This is only a success notification
  12748. if( success ){
  12749. WFIFOHEAD(fd, 11);
  12750. WFIFOW(fd, 0) = 0x9f6;
  12751. WFIFOB(fd, 2) = msg->type;
  12752. WFIFOQ(fd, 3) = msg->id;
  12753. WFIFOSET(fd, 11);
  12754. }
  12755. #endif
  12756. }
  12757. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12758. /// 0274 <mail id>.L <result>.W
  12759. /// result:
  12760. /// 0 = success
  12761. /// 1 = failure
  12762. void clif_Mail_return(int fd, int mail_id, short fail)
  12763. {
  12764. WFIFOHEAD(fd,packet_len(0x274));
  12765. WFIFOW(fd,0) = 0x274;
  12766. WFIFOL(fd,2) = mail_id;
  12767. WFIFOW(fd,6) = fail;
  12768. WFIFOSET(fd,packet_len(0x274));
  12769. }
  12770. /// Notification about new mail.
  12771. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  12772. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  12773. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  12774. int fd = sd->fd;
  12775. #if PACKETVER < 20150513
  12776. WFIFOHEAD(fd,packet_len(0x24a));
  12777. WFIFOW(fd,0) = 0x24a;
  12778. WFIFOL(fd,2) = mail_id;
  12779. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  12780. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  12781. WFIFOSET(fd,packet_len(0x24a));
  12782. #else
  12783. WFIFOHEAD(fd,3);
  12784. WFIFOW(fd,0) = 0x9e7;
  12785. WFIFOB(fd,2) = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  12786. WFIFOSET(fd,3);
  12787. #endif
  12788. }
  12789. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12790. /// 0260 <type>.L
  12791. /// type:
  12792. /// 0 = open
  12793. /// 1 = close
  12794. void clif_Mail_window(int fd, int flag)
  12795. {
  12796. WFIFOHEAD(fd,packet_len(0x260));
  12797. WFIFOW(fd,0) = 0x260;
  12798. WFIFOL(fd,2) = flag;
  12799. WFIFOSET(fd,packet_len(0x260));
  12800. }
  12801. /// Lists mails stored in inbox.
  12802. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  12803. /// read:
  12804. /// 0 = unread
  12805. /// 1 = read
  12806. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  12807. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12808. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  12809. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12810. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  12811. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  12812. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  12813. #if PACKETVER < 20150513
  12814. int fd = sd->fd;
  12815. struct mail_data *md = &sd->mail.inbox;
  12816. struct mail_message *msg;
  12817. int len, i, j;
  12818. len = 8 + (73 * md->amount);
  12819. WFIFOHEAD(fd,len);
  12820. WFIFOW(fd,0) = 0x240;
  12821. WFIFOW(fd,2) = len;
  12822. WFIFOL(fd,4) = md->amount;
  12823. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12824. {
  12825. msg = &md->msg[i];
  12826. if (msg->id < 1)
  12827. continue;
  12828. WFIFOL(fd,8+73*j) = msg->id;
  12829. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12830. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12831. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12832. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12833. j++;
  12834. }
  12835. WFIFOSET(fd,len);
  12836. if( md->full ) {// TODO: is this official?
  12837. char output[100];
  12838. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12839. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  12840. }
  12841. #else
  12842. int fd = sd->fd;
  12843. struct mail_data *md = &sd->mail.inbox;
  12844. struct mail_message *msg;
  12845. int i, j, k, offset, titleLength;
  12846. uint8 mailType, amount, remaining;
  12847. uint32 now = (uint32)time(NULL);
  12848. #if PACKETVER >= 20170419
  12849. int cmd = 0xac2;
  12850. #elif PACKETVER >= 20160601
  12851. int cmd = 0xa7d;
  12852. #else
  12853. int cmd = 0x9f0;
  12854. #endif
  12855. if( battle_config.mail_daily_count ){
  12856. mail_refresh_remaining_amount(sd);
  12857. }
  12858. #if PACKETVER >= 20170419
  12859. // Always send all
  12860. i = md->amount;
  12861. #else
  12862. // If a starting mail id was sent
  12863. if( mailID != 0 ){
  12864. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  12865. // Unknown mail
  12866. if( i == md->amount ){
  12867. // Ignore the request for now
  12868. return; // TODO: Should we just show the first page instead?
  12869. }
  12870. // It was actually the oldest/first mail, there is no further page
  12871. if( i == 0 ){
  12872. return;
  12873. }
  12874. // We actually want the next/older mail
  12875. i -= 1;
  12876. }else{
  12877. i = md->amount;
  12878. }
  12879. #endif
  12880. // Count the remaining mails from the starting mail or the beginning
  12881. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  12882. for( j = i, remaining = 0; j >= 0; j-- ){
  12883. msg = &md->msg[j];
  12884. if (msg->id < 1)
  12885. continue;
  12886. #if PACKETVER < 20170419
  12887. if (msg->type != type)
  12888. continue;
  12889. #endif
  12890. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  12891. continue;
  12892. remaining++;
  12893. }
  12894. #if PACKETVER >= 20170419
  12895. // Always send all
  12896. amount = remaining;
  12897. #else
  12898. if( remaining > MAIL_PAGE_SIZE ){
  12899. amount = MAIL_PAGE_SIZE;
  12900. }else{
  12901. amount = remaining;
  12902. }
  12903. #endif
  12904. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  12905. WFIFOW(fd, 0) = cmd;
  12906. #if PACKETVER >= 20170419
  12907. WFIFOB(fd, 4) = 1; // Unknown
  12908. offset = 5;
  12909. #else
  12910. WFIFOB(fd, 4) = type;
  12911. WFIFOB(fd, 5) = amount;
  12912. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  12913. offset = 7;
  12914. #endif
  12915. for( amount = 0; i >= 0; i-- ){
  12916. msg = &md->msg[i];
  12917. if (msg->id < 1)
  12918. continue;
  12919. #if PACKETVER < 20170419
  12920. if (msg->type != type)
  12921. continue;
  12922. #endif
  12923. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  12924. continue;
  12925. #if PACKETVER >= 20170419
  12926. WFIFOB(fd, offset) = msg->type;
  12927. offset += 1;
  12928. #endif
  12929. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  12930. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  12931. mailType = MAIL_TYPE_TEXT; // Normal letter
  12932. if( msg->zeny > 0 ){
  12933. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  12934. }
  12935. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  12936. if( msg->item[k].nameid > 0 ){
  12937. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  12938. break;
  12939. }
  12940. }
  12941. // If it came from an npc?
  12942. //mailType |= MAIL_TYPE_NPC;
  12943. WFIFOB(fd, offset + 9) = mailType;
  12944. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  12945. #if PACKETVER < 20170419
  12946. // How much time has passed since you received the mail
  12947. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  12948. offset += 4;
  12949. #endif
  12950. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  12951. if( msg->scheduled_deletion > 0 ){
  12952. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  12953. }else{
  12954. // Fake the scheduled deletion to one year in the future
  12955. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  12956. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  12957. }
  12958. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  12959. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  12960. offset += 40 + titleLength;
  12961. }
  12962. WFIFOW(fd, 2) = (int16)offset;
  12963. WFIFOSET(fd, offset);
  12964. #endif
  12965. }
  12966. /// Mail inbox list request.
  12967. /// 023f (CZ_MAIL_GET_LIST)
  12968. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  12969. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  12970. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  12971. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  12972. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  12973. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  12974. #if PACKETVER < 20150513
  12975. struct mail_data* md = &sd->mail.inbox;
  12976. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  12977. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  12978. else
  12979. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  12980. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  12981. mail_removezeny(sd, false);
  12982. #else
  12983. int cmd = RFIFOW(fd, 0);
  12984. #if PACKETVER < 20170419
  12985. uint8 openType = RFIFOB(fd, 2);
  12986. uint64 mailId = RFIFOQ(fd, 3);
  12987. #else
  12988. uint8 openType;
  12989. uint64 mailId = RFIFOQ(fd, 2);
  12990. int i;
  12991. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  12992. if( i == MAIL_MAX_INBOX ){
  12993. openType = MAIL_INBOX_NORMAL;
  12994. mailId = 0;
  12995. }else{
  12996. openType = sd->mail.inbox.msg[i].type;
  12997. mailId = 0;
  12998. }
  12999. #endif
  13000. switch( openType ){
  13001. case MAIL_INBOX_NORMAL:
  13002. case MAIL_INBOX_ACCOUNT:
  13003. case MAIL_INBOX_RETURNED:
  13004. break;
  13005. default:
  13006. // Unknown type: ignore request
  13007. return;
  13008. }
  13009. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13010. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13011. return;
  13012. }
  13013. // If it is not a next page request
  13014. if( cmd != 0x9ee ){
  13015. mailId = 0;
  13016. }
  13017. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13018. #endif
  13019. }
  13020. /// Opens a mail
  13021. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13022. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13023. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13024. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13025. /// { }*n
  13026. // TODO: Packet description => for repeated block
  13027. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  13028. {
  13029. int i, fd = sd->fd;
  13030. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13031. if( i == MAIL_MAX_INBOX ) {
  13032. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13033. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13034. return;
  13035. } else {
  13036. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13037. struct item *item;
  13038. struct item_data *data;
  13039. int msg_len = strlen(msg->body), len;
  13040. #if PACKETVER >= 20150513
  13041. int offset, j, itemsize, count = 0;
  13042. #endif
  13043. if( msg_len == 0 ) {
  13044. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13045. msg_len = strlen(msg->body);
  13046. }
  13047. #if PACKETVER < 20150513
  13048. item = &msg->item[0];
  13049. len = 101 + msg_len;
  13050. WFIFOHEAD(fd,len);
  13051. WFIFOW(fd,0) = 0x242;
  13052. WFIFOW(fd,2) = len;
  13053. WFIFOL(fd,4) = msg->id;
  13054. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13055. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13056. WFIFOL(fd,72) = 0;
  13057. WFIFOL(fd,76) = msg->zeny;
  13058. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  13059. WFIFOL(fd,80) = item->amount;
  13060. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  13061. WFIFOW(fd,86) = data->type;
  13062. WFIFOB(fd,88) = item->identify;
  13063. WFIFOB(fd,89) = item->attribute;
  13064. WFIFOB(fd,90) = item->refine;
  13065. WFIFOW(fd,91) = item->card[0];
  13066. WFIFOW(fd,93) = item->card[1];
  13067. WFIFOW(fd,95) = item->card[2];
  13068. WFIFOW(fd,97) = item->card[3];
  13069. } else // no item, set all to zero
  13070. memset(WFIFOP(fd,80), 0x00, 19);
  13071. WFIFOB(fd,99) = (unsigned char)msg_len;
  13072. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13073. WFIFOSET(fd,len);
  13074. #else
  13075. // Count the attached items
  13076. ARR_FIND( 0, MAIL_MAX_ITEM, count, msg->item[count].nameid == 0 );
  13077. msg_len += 1; // Zero Termination
  13078. itemsize = 24 + 5 * MAX_ITEM_RDM_OPT;
  13079. len = 24 + msg_len+1 + itemsize * count;
  13080. WFIFOHEAD(fd, len);
  13081. WFIFOW(fd, 0) = 0x9eb;
  13082. WFIFOW(fd, 2) = len;
  13083. WFIFOB(fd, 4) = msg->type;
  13084. WFIFOQ(fd, 5) = msg->id;
  13085. WFIFOW(fd, 13) = msg_len;
  13086. WFIFOQ(fd, 15) = msg->zeny;
  13087. WFIFOB(fd, 23) = (uint8)count; // item count
  13088. safestrncpy(WFIFOCP(fd, 24), msg->body, msg_len);
  13089. offset = 24 + msg_len;
  13090. for (j = 0; j < MAIL_MAX_ITEM; j++) {
  13091. item = &msg->item[j];
  13092. if (item->nameid > 0 && item->amount > 0 && (data = itemdb_exists(item->nameid)) != NULL) {
  13093. WFIFOW(fd, offset) = item->amount;
  13094. WFIFOW(fd, offset + 2) = (data->view_id) ? data->view_id : item->nameid;
  13095. WFIFOB(fd, offset + 4) = item->identify;
  13096. WFIFOB(fd, offset + 5) = item->attribute;
  13097. WFIFOB(fd, offset + 6) = item->refine;
  13098. clif_addcards(WFIFOP(fd, offset + 7), item);
  13099. // 4B unsigned long location
  13100. WFIFOB(fd, offset + 15 + 4) = data->type;
  13101. // 2B unsigned short wItemSpriteNumber
  13102. //WFIFOW(fd, offset + 15 + 5) = data->view_id;
  13103. // 2B unsigned short bindOnEquipType
  13104. clif_add_random_options(WFIFOP(fd, offset + 15 + 9 ), item);
  13105. offset += itemsize;
  13106. }
  13107. }
  13108. WFIFOSET(fd, len);
  13109. #endif
  13110. if (msg->status == MAIL_UNREAD) {
  13111. msg->status = MAIL_READ;
  13112. intif_Mail_read(mail_id);
  13113. clif_parse_Mail_refreshinbox(fd, sd);
  13114. sd->mail.inbox.unread--;
  13115. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13116. }
  13117. }
  13118. }
  13119. /// Request to open a mail.
  13120. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13121. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13122. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13123. #if PACKETVER < 20150513
  13124. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13125. #else
  13126. //uint8 openType = RFIFOB(fd, 2);
  13127. int mail_id = (int)RFIFOQ(fd, 3);
  13128. #endif
  13129. if( mail_id <= 0 )
  13130. return;
  13131. if( mail_invalid_operation(sd) )
  13132. return;
  13133. clif_Mail_read(sd, mail_id);
  13134. }
  13135. /// Allow a player to begin writing a mail
  13136. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13137. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13138. int fd = sd->fd;
  13139. WFIFOHEAD(fd, 27);
  13140. WFIFOW(fd, 0) = 0xa12;
  13141. safestrncpy(WFIFOCP(fd, 2), name, NAME_LENGTH);
  13142. WFIFOB(fd, 26) = success;
  13143. WFIFOSET(fd, 27);
  13144. }
  13145. /// Request to start writing a mail
  13146. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13147. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13148. char name[NAME_LENGTH];
  13149. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13150. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13151. clif_send_Mail_beginwrite_ack(sd, name, false);
  13152. return;
  13153. }
  13154. mail_clear(sd);
  13155. sd->state.mail_writing = true;
  13156. clif_send_Mail_beginwrite_ack(sd, name,true);
  13157. }
  13158. /// Notification that the client cancelled writing a mail
  13159. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13160. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13161. sd->state.mail_writing = false;
  13162. }
  13163. /// Give the client information about the recipient, if available
  13164. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13165. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13166. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13167. int fd = sd->fd;
  13168. #if PACKETVER <= 20160302
  13169. int cmd = 0xa14;
  13170. #else
  13171. int cmd = 0xa51;
  13172. #endif
  13173. WFIFOHEAD(fd, packet_len(cmd));
  13174. WFIFOW(fd, 0) = cmd;
  13175. WFIFOL(fd, 2) = char_id;
  13176. WFIFOW(fd, 6) = class_;
  13177. WFIFOW(fd, 8) = level;
  13178. #if PACKETVER >= 20160302
  13179. strncpy(WFIFOCP(fd, 10), name, NAME_LENGTH);
  13180. #endif
  13181. WFIFOSET(fd, packet_len(cmd));
  13182. }
  13183. /// Request information about the recipient
  13184. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13185. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13186. static char name[NAME_LENGTH];
  13187. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13188. intif_mail_checkreceiver(sd, name);
  13189. }
  13190. /// Request to receive mail's attachment.
  13191. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13192. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13193. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13194. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13195. int i;
  13196. struct mail_message* msg;
  13197. #if PACKETVER < 20150513
  13198. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13199. int attachment = MAIL_ATT_ALL;
  13200. #else
  13201. uint16 packet_id = RFIFOW(fd, 0);
  13202. int mail_id = (int)RFIFOQ(fd, 2);
  13203. //int openType = RFIFOB(fd, 10);
  13204. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13205. #endif
  13206. if( !chrif_isconnected() )
  13207. return;
  13208. if( mail_id <= 0 )
  13209. return;
  13210. if( mail_invalid_operation(sd) )
  13211. return;
  13212. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13213. if( i == MAIL_MAX_INBOX )
  13214. return;
  13215. msg = &sd->mail.inbox.msg[i];
  13216. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13217. attachment &= ~MAIL_ATT_ZENY;
  13218. }
  13219. if( attachment&MAIL_ATT_ITEM ){
  13220. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13221. // No items were found
  13222. if( i == MAIL_MAX_ITEM ){
  13223. attachment &= ~MAIL_ATT_ITEM;
  13224. }
  13225. }
  13226. // Either no attachment requested at all or there are no zeny or items in the mail
  13227. if( attachment == MAIL_ATT_NONE ){
  13228. return;
  13229. }
  13230. if( attachment&MAIL_ATT_ZENY ){
  13231. if( msg->zeny + sd->status.zeny > MAX_ZENY ){
  13232. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13233. return;
  13234. }else{
  13235. // To make sure another request fails
  13236. msg->zeny = 0;
  13237. }
  13238. }
  13239. if( attachment&MAIL_ATT_ITEM ){
  13240. int new_ = 0, totalweight = 0;
  13241. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13242. struct item* item = &msg->item[i];
  13243. if( item->nameid > 0 && item->amount > 0 ){
  13244. struct item_data *data;
  13245. if((data = itemdb_exists(item->nameid)) == NULL)
  13246. continue;
  13247. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13248. case CHKADDITEM_NEW:
  13249. new_++;
  13250. break;
  13251. case CHKADDITEM_OVERAMOUNT:
  13252. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13253. return;
  13254. }
  13255. totalweight += data->weight * item->amount;
  13256. }
  13257. }
  13258. if( ( totalweight + sd->weight ) > sd->max_weight ){
  13259. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13260. return;
  13261. }else if( pc_inventoryblank(sd) < new_ ){
  13262. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13263. return;
  13264. }
  13265. // To make sure another request fails
  13266. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13267. }
  13268. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13269. clif_Mail_read(sd, mail_id);
  13270. }
  13271. /// Request to delete a mail.
  13272. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13273. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13274. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13275. #if PACKETVER < 20150513
  13276. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13277. #else
  13278. //int openType = RFIFOB(fd, 2);
  13279. int mail_id = (int)RFIFOQ(fd, 3);
  13280. #endif
  13281. int i, j;
  13282. if( !chrif_isconnected() )
  13283. return;
  13284. if( mail_id <= 0 )
  13285. return;
  13286. if( mail_invalid_operation(sd) )
  13287. return;
  13288. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13289. if (i < MAIL_MAX_INBOX) {
  13290. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13291. // can't delete mail without removing zeny first
  13292. if( msg->zeny > 0 ){
  13293. clif_mail_delete(sd, msg, false);
  13294. return;
  13295. }
  13296. // can't delete mail without removing attachment(s) first
  13297. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13298. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13299. clif_mail_delete(sd, msg, false);
  13300. return;
  13301. }
  13302. }
  13303. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13304. sd->mail.inbox.unread--;
  13305. clif_Mail_new(sd,0,NULL,NULL);
  13306. }
  13307. }
  13308. }
  13309. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13310. /// 0273 <mail id>.L <receive name>.24B
  13311. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13312. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13313. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13314. int i;
  13315. if( mail_id <= 0 )
  13316. return;
  13317. if( mail_invalid_operation(sd) )
  13318. return;
  13319. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13320. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13321. intif_Mail_return(sd->status.char_id, mail_id);
  13322. else
  13323. clif_Mail_return(sd->fd, mail_id, 1);
  13324. }
  13325. /// Request to add an item or Zeny to mail.
  13326. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13327. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13328. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13329. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13330. int idx = RFIFOW(fd,info->pos[0]);
  13331. #if PACKETVER < 20150513
  13332. int amount = RFIFOL(fd,info->pos[1]);
  13333. #else
  13334. int amount = RFIFOW(fd,info->pos[1]);
  13335. #endif
  13336. unsigned char flag;
  13337. if( !chrif_isconnected() )
  13338. return;
  13339. if (idx < 0 || amount < 0)
  13340. return;
  13341. flag = mail_setitem(sd, idx, amount);
  13342. clif_Mail_setattachment(sd,idx,amount,flag);
  13343. }
  13344. /// Remove an item from a mail
  13345. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13346. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13347. int fd = sd->fd;
  13348. WFIFOHEAD(fd, 9);
  13349. WFIFOW(fd, 0) = 0xa07;
  13350. WFIFOB(fd, 2) = success;
  13351. WFIFOW(fd, 3) = index;
  13352. WFIFOW(fd, 5) = amount;
  13353. WFIFOW(fd, 7) = 0; // TODO: which weight? item weight? removed weight? remaining weight?
  13354. WFIFOSET(fd, 9);
  13355. }
  13356. /// Request to reset mail item and/or Zeny
  13357. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13358. /// type:
  13359. /// 0 = reset all
  13360. /// 1 = remove item
  13361. /// 2 = remove zeny
  13362. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13363. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13364. {
  13365. #if PACKETVER < 20150513
  13366. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13367. if (type == 0 || type == 1)
  13368. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13369. if (type == 0 || type == 2)
  13370. mail_removezeny(sd, false);
  13371. #else
  13372. uint16 index = RFIFOW(fd, 2);
  13373. uint16 count = RFIFOW(fd, 4);
  13374. mail_removeitem(sd,0,index,count);
  13375. #endif
  13376. }
  13377. /// Request to send mail
  13378. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13379. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13380. /// 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)
  13381. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  13382. #if PACKETVER < 20150513
  13383. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13384. if( !chrif_isconnected() )
  13385. return;
  13386. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13387. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13388. return;
  13389. }
  13390. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13391. #else
  13392. unsigned short length;
  13393. static char receiver[NAME_LENGTH];
  13394. static char sender[NAME_LENGTH];
  13395. char *title;
  13396. char *text;
  13397. uint64 zeny;
  13398. uint16 titleLength;
  13399. uint16 textLength;
  13400. length = RFIFOW(fd, 2);
  13401. if( length < 0x3e ){
  13402. ShowWarning("Too short...\n");
  13403. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13404. return;
  13405. }
  13406. // Forged request without a begin writing packet?
  13407. if( !sd->state.mail_writing ){
  13408. return; // Ignore it
  13409. }
  13410. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13411. safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13412. zeny = RFIFOQ(fd, 52);
  13413. titleLength = RFIFOW(fd, 60);
  13414. textLength = RFIFOW(fd, 62);
  13415. title = (char*)aMalloc(titleLength);
  13416. text = (char*)aMalloc(textLength);
  13417. #if PACKETVER <= 20160330
  13418. safestrncpy(title, RFIFOCP(fd, 64), titleLength);
  13419. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), textLength);
  13420. #else
  13421. // 64 = <char id>.L
  13422. safestrncpy(title, RFIFOCP(fd, 68), titleLength);
  13423. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), textLength);
  13424. #endif
  13425. if( zeny > 0 ){
  13426. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13427. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13428. return;
  13429. }
  13430. }
  13431. mail_send(sd, receiver, title, text, textLength);
  13432. aFree(title);
  13433. aFree(text);
  13434. #endif
  13435. }
  13436. /// AUCTION SYSTEM
  13437. /// By Zephyrus
  13438. ///
  13439. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13440. /// 025f <type>.L
  13441. /// type:
  13442. /// 0 = open
  13443. /// 1 = close
  13444. void clif_Auction_openwindow(struct map_session_data *sd)
  13445. {
  13446. int fd = sd->fd;
  13447. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13448. return;
  13449. if( !battle_config.feature_auction )
  13450. return;
  13451. WFIFOHEAD(fd,packet_len(0x25f));
  13452. WFIFOW(fd,0) = 0x25f;
  13453. WFIFOL(fd,2) = 0;
  13454. WFIFOSET(fd,packet_len(0x25f));
  13455. }
  13456. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13457. /// 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 }*
  13458. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  13459. {
  13460. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13461. struct auction_data auction;
  13462. struct item_data *item;
  13463. WFIFOHEAD(fd,12 + (count * 83));
  13464. WFIFOW(fd,0) = 0x252;
  13465. WFIFOW(fd,2) = 12 + (count * 83);
  13466. WFIFOL(fd,4) = pages;
  13467. WFIFOL(fd,8) = count;
  13468. for( i = 0; i < count; i++ ) {
  13469. int k = 12 + (i * 83);
  13470. memcpy(&auction, RBUFP(buf,i * len), len);
  13471. WFIFOL(fd,k) = auction.auction_id;
  13472. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13473. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  13474. WFIFOW(fd,28+k) = item->view_id;
  13475. else
  13476. WFIFOW(fd,28+k) = auction.item.nameid;
  13477. WFIFOL(fd,30+k) = auction.type;
  13478. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13479. WFIFOB(fd,36+k) = auction.item.identify;
  13480. WFIFOB(fd,37+k) = auction.item.attribute;
  13481. WFIFOB(fd,38+k) = auction.item.refine;
  13482. WFIFOW(fd,39+k) = auction.item.card[0];
  13483. WFIFOW(fd,41+k) = auction.item.card[1];
  13484. WFIFOW(fd,43+k) = auction.item.card[2];
  13485. WFIFOW(fd,45+k) = auction.item.card[3];
  13486. WFIFOL(fd,47+k) = auction.price;
  13487. WFIFOL(fd,51+k) = auction.buynow;
  13488. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13489. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13490. }
  13491. WFIFOSET(fd,WFIFOW(fd,2));
  13492. }
  13493. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13494. /// 0256 <index>.W <result>.B
  13495. /// result:
  13496. /// 0 = success
  13497. /// 1 = failure
  13498. static void clif_Auction_setitem(int fd, int index, bool fail)
  13499. {
  13500. WFIFOHEAD(fd,packet_len(0x256));
  13501. WFIFOW(fd,0) = 0x256;
  13502. WFIFOW(fd,2) = index;
  13503. WFIFOB(fd,4) = fail;
  13504. WFIFOSET(fd,packet_len(0x256));
  13505. }
  13506. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13507. /// 024b <type>.W
  13508. /// type:
  13509. /// 0 = create (any other action in auction window)
  13510. /// 1 = cancel (cancel pressed on register tab)
  13511. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13512. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  13513. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13514. if( sd->auction.amount > 0 )
  13515. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13516. sd->auction.amount = 0;
  13517. }
  13518. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13519. /// 024c <index>.W <count>.L
  13520. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  13521. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13522. int idx = RFIFOW(fd,info->pos[0]) - 2;
  13523. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  13524. struct item_data *item;
  13525. if( !battle_config.feature_auction )
  13526. return;
  13527. if( sd->auction.amount > 0 )
  13528. sd->auction.amount = 0;
  13529. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13530. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13531. return;
  13532. }
  13533. 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.
  13534. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13535. return;
  13536. }
  13537. 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) )
  13538. { // Consumable or pets are not allowed
  13539. clif_Auction_setitem(sd->fd, idx, true);
  13540. return;
  13541. }
  13542. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13543. !sd->inventory.u.items_inventory[idx].identify ||
  13544. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13545. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13546. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13547. clif_Auction_setitem(sd->fd, idx, true);
  13548. return;
  13549. }
  13550. sd->auction.index = idx;
  13551. sd->auction.amount = amount;
  13552. clif_Auction_setitem(fd, idx + 2, false);
  13553. }
  13554. /// Result from an auction action (ZC_AUCTION_RESULT).
  13555. /// 0250 <result>.B
  13556. /// result:
  13557. /// 0 = You have failed to bid into the auction
  13558. /// 1 = You have successfully bid in the auction
  13559. /// 2 = The auction has been canceled
  13560. /// 3 = An auction with at least one bidder cannot be canceled
  13561. /// 4 = You cannot register more than 5 items in an auction at a time
  13562. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13563. /// 6 = You have won the auction
  13564. /// 7 = You have failed to win the auction
  13565. /// 8 = You do not have enough Zeny
  13566. /// 9 = You cannot place more than 5 bids at a time
  13567. void clif_Auction_message(int fd, unsigned char flag)
  13568. {
  13569. WFIFOHEAD(fd,packet_len(0x250));
  13570. WFIFOW(fd,0) = 0x250;
  13571. WFIFOB(fd,2) = flag;
  13572. WFIFOSET(fd,packet_len(0x250));
  13573. }
  13574. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13575. /// 025e <result>.W
  13576. /// result:
  13577. /// 0 = You have ended the auction
  13578. /// 1 = You cannot end the auction
  13579. /// 2 = Auction ID is incorrect
  13580. void clif_Auction_close(int fd, unsigned char flag)
  13581. {
  13582. WFIFOHEAD(fd,packet_len(0x25e));
  13583. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13584. WFIFOW(fd,2) = flag;
  13585. WFIFOSET(fd,packet_len(0x25e));
  13586. }
  13587. /// Request to add an auction (CZ_AUCTION_ADD).
  13588. /// 024d <now money>.L <max money>.L <delete hour>.W
  13589. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  13590. {
  13591. struct auction_data auction;
  13592. struct item_data *item;
  13593. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13594. if( !battle_config.feature_auction )
  13595. return;
  13596. auction.price = RFIFOL(fd,info->pos[0]);
  13597. auction.buynow = RFIFOL(fd,info->pos[1]);
  13598. auction.hours = RFIFOW(fd,info->pos[2]);
  13599. // Invalid Situations...
  13600. if( sd->auction.amount < 1 ) {
  13601. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  13602. return;
  13603. }
  13604. if( auction.price >= auction.buynow ) {
  13605. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  13606. return;
  13607. }
  13608. if( auction.hours < 1 || auction.hours > 48 ) {
  13609. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  13610. return;
  13611. }
  13612. // Auction checks...
  13613. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  13614. clif_displaymessage(sd->fd, msg_txt(sd,293));
  13615. clif_Auction_message(fd, 2); // The auction has been canceled
  13616. return;
  13617. }
  13618. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  13619. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  13620. return;
  13621. }
  13622. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  13623. auction.buynow = battle_config.auction_maximumprice;
  13624. if( auction.price >= auction.buynow )
  13625. auction.price = auction.buynow - 1;
  13626. }
  13627. auction.auction_id = 0;
  13628. auction.seller_id = sd->status.char_id;
  13629. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  13630. auction.buyer_id = 0;
  13631. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  13632. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  13633. {
  13634. clif_Auction_message(fd, 2); // The auction has been canceled
  13635. return;
  13636. }
  13637. if( (item = itemdb_exists(sd->inventory.u.items_inventory[sd->auction.index].nameid)) == NULL )
  13638. { // Just in case
  13639. clif_Auction_message(fd, 2); // The auction has been canceled
  13640. return;
  13641. }
  13642. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  13643. auction.type = item->type;
  13644. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  13645. auction.item.amount = 1;
  13646. auction.timestamp = 0;
  13647. if( !intif_Auction_register(&auction) )
  13648. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  13649. else
  13650. {
  13651. int zeny = auction.hours*battle_config.auction_feeperhour;
  13652. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  13653. sd->auction.amount = 0;
  13654. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  13655. }
  13656. }
  13657. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  13658. /// 024e <auction id>.L
  13659. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  13660. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13661. intif_Auction_cancel(sd->status.char_id, auction_id);
  13662. }
  13663. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  13664. /// 025d <auction id>.L
  13665. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  13666. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13667. intif_Auction_close(sd->status.char_id, auction_id);
  13668. }
  13669. /// Places a bid on an auction (CZ_AUCTION_BUY).
  13670. /// 024f <auction id>.L <money>.L
  13671. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  13672. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13673. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  13674. int bid = RFIFOL(fd,info->pos[1]);
  13675. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  13676. clif_displaymessage(sd->fd, msg_txt(sd,246));
  13677. return;
  13678. }
  13679. if( bid <= 0 )
  13680. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13681. else if( bid > sd->status.zeny )
  13682. clif_Auction_message(fd, 8); // You do not have enough zeny
  13683. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  13684. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13685. else {
  13686. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  13687. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  13688. }
  13689. }
  13690. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  13691. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  13692. /// search type:
  13693. /// 0 = armor
  13694. /// 1 = weapon
  13695. /// 2 = card
  13696. /// 3 = misc
  13697. /// 4 = name search
  13698. /// 5 = auction id search
  13699. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  13700. char search_text[NAME_LENGTH];
  13701. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13702. short type = RFIFOW(fd,info->pos[0]);
  13703. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  13704. int page = RFIFOW(fd,info->pos[3]);
  13705. if( !battle_config.feature_auction )
  13706. return;
  13707. clif_parse_Auction_cancelreg(fd, sd);
  13708. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  13709. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  13710. }
  13711. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  13712. /// 025c <type>.W
  13713. /// type:
  13714. /// 0 = sell (own auctions)
  13715. /// 1 = buy (own bids)
  13716. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  13717. {
  13718. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  13719. if( !battle_config.feature_auction )
  13720. return;
  13721. clif_parse_Auction_cancelreg(fd, sd);
  13722. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  13723. }
  13724. /// CASH/POINT SHOP
  13725. ///
  13726. void clif_cashshop_open( struct map_session_data* sd ){
  13727. WFIFOHEAD( sd->fd, 10 );
  13728. WFIFOW( sd->fd, 0 ) = 0x845;
  13729. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  13730. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  13731. WFIFOSET( sd->fd, 10 );
  13732. }
  13733. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13734. sd->state.cashshop_open = true;
  13735. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13736. clif_cashshop_open( sd );
  13737. }
  13738. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  13739. sd->state.cashshop_open = false;
  13740. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13741. // No need to do anything here
  13742. }
  13743. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  13744. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  13745. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  13746. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  13747. int j;
  13748. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  13749. return;
  13750. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  13751. WFIFOW(fd, 0) = 0x8c0;
  13752. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  13753. WFIFOL(fd, 4) = tab;
  13754. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  13755. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  13756. struct item_data *id = itemdb_search(cash_shop_items[tab].item[j]->nameid);
  13757. WFIFOW(fd, 10 + ( 6 * j ) ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[j]->nameid;
  13758. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  13759. }
  13760. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  13761. }
  13762. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  13763. void clif_cashshop_list( int fd ){
  13764. int tab;
  13765. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  13766. int length = 8 + cash_shop_items[tab].count * 6;
  13767. int i, offset;
  13768. WFIFOHEAD( fd, length );
  13769. WFIFOW( fd, 0 ) = 0x8ca;
  13770. WFIFOW( fd, 2 ) = length;
  13771. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  13772. WFIFOW( fd, 6 ) = tab;
  13773. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  13774. struct item_data *id = itemdb_search(cash_shop_items[tab].item[i]->nameid);
  13775. WFIFOW( fd, offset ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[i]->nameid;
  13776. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  13777. }
  13778. WFIFOSET( fd, length );
  13779. }
  13780. }
  13781. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  13782. if( !sd->status.cashshop_sent ) {
  13783. clif_cashshop_list( fd );
  13784. #if PACKETVER_SUPPORTS_SALES
  13785. sale_notify_login(sd);
  13786. #endif
  13787. sd->status.cashshop_sent = true;
  13788. }
  13789. }
  13790. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  13791. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  13792. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  13793. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  13794. {
  13795. int fd, i, cost[2] = { 0, 0 };
  13796. #if PACKETVER < 20070711
  13797. const int offset = 8;
  13798. #else
  13799. const int offset = 12;
  13800. #endif
  13801. nullpo_retv(sd);
  13802. nullpo_retv(nd);
  13803. npc_shop_currency_type(sd, nd, cost, true);
  13804. fd = sd->fd;
  13805. sd->npc_shopid = nd->bl.id;
  13806. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  13807. WFIFOW(fd,0) = 0x287;
  13808. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  13809. WFIFOL(fd,4) = cost[0];
  13810. #if PACKETVER >= 20070711
  13811. WFIFOL(fd,8) = cost[1];
  13812. #endif
  13813. for( i = 0; i < nd->u.shop.count; i++ ) {
  13814. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  13815. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  13816. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  13817. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  13818. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  13819. }
  13820. WFIFOSET(fd,WFIFOW(fd,2));
  13821. }
  13822. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  13823. /// 0289 <cash point>.L <error>.W
  13824. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  13825. /// error:
  13826. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  13827. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  13828. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  13829. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  13830. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  13831. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  13832. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  13833. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  13834. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  13835. void clif_cashshop_ack(struct map_session_data* sd, int error)
  13836. {
  13837. int fd, cost[2] = { 0, 0 };
  13838. struct npc_data *nd;
  13839. nullpo_retv(sd);
  13840. fd = sd->fd;
  13841. nd = map_id2nd(sd->npc_shopid);
  13842. npc_shop_currency_type(sd, nd, cost, false);
  13843. WFIFOHEAD(fd, packet_len(0x289));
  13844. WFIFOW(fd,0) = 0x289;
  13845. WFIFOL(fd,2) = cost[0];
  13846. #if PACKETVER < 20070711
  13847. WFIFOW(fd,6) = TOW(error);
  13848. #else
  13849. WFIFOL(fd,6) = cost[1];
  13850. WFIFOW(fd,10) = TOW(error);
  13851. #endif
  13852. WFIFOSET(fd, packet_len(0x289));
  13853. }
  13854. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  13855. WFIFOHEAD( sd->fd, 16 );
  13856. WFIFOW( sd->fd, 0 ) = 0x849;
  13857. WFIFOL( sd->fd, 2 ) = item_id;
  13858. WFIFOW( sd->fd, 6 ) = result;
  13859. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  13860. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  13861. WFIFOSET( sd->fd, 16 );
  13862. }
  13863. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  13864. /// 0288 <name id>.W <amount>.W
  13865. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  13866. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  13867. /// 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)
  13868. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd){
  13869. struct s_packet_db* info;
  13870. int cmd = RFIFOW(fd,0);
  13871. nullpo_retv(sd);
  13872. info = &packet_db[cmd];
  13873. if( sd->state.trading || !sd->npc_shopid ) {
  13874. clif_cashshop_ack(sd,1);
  13875. return;
  13876. }
  13877. else {
  13878. #if PACKETVER < 20101116
  13879. short nameid = RFIFOW(fd,info->pos[0]);
  13880. short amount = RFIFOW(fd,info->pos[1]);
  13881. int points = RFIFOL(fd,info->pos[2]);
  13882. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  13883. #else
  13884. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  13885. int len = RFIFOW(fd,info->pos[0]);
  13886. int points = RFIFOL(fd,info->pos[1]);
  13887. int count = RFIFOW(fd,info->pos[2]);
  13888. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13889. if( len < 10 || len != 10 + count * s_itl){
  13890. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  13891. return;
  13892. }
  13893. if(cmd==0x848){
  13894. if (cashshop_buylist( sd, points, count, item_list))
  13895. clif_cashshop_ack(sd,0);
  13896. return;
  13897. } else {
  13898. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  13899. return;
  13900. }
  13901. #endif
  13902. }
  13903. }
  13904. /// Adoption System
  13905. ///
  13906. /// Adoption message (ZC_BABYMSG).
  13907. /// 0216 <msg>.L
  13908. /// msg:
  13909. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  13910. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  13911. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  13912. void clif_Adopt_reply(struct map_session_data *sd, int type)
  13913. {
  13914. int fd = sd->fd;
  13915. WFIFOHEAD(fd,6);
  13916. WFIFOW(fd,0) = 0x216;
  13917. WFIFOL(fd,2) = type;
  13918. WFIFOSET(fd,6);
  13919. }
  13920. /// Adoption confirmation (ZC_REQ_BABY).
  13921. /// 01f6 <account id>.L <char id>.L <name>.B
  13922. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  13923. {
  13924. int fd = sd->fd;
  13925. WFIFOHEAD(fd,34);
  13926. WFIFOW(fd,0) = 0x1f6;
  13927. WFIFOL(fd,2) = src->status.account_id;
  13928. WFIFOL(fd,6) = p_id;
  13929. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  13930. WFIFOSET(fd,34);
  13931. }
  13932. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  13933. /// 01f9 <account id>.L
  13934. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  13935. {
  13936. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  13937. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  13938. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  13939. {
  13940. tsd->adopt_invite = sd->status.account_id;
  13941. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  13942. }
  13943. }
  13944. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  13945. /// 01f7 <account id>.L <char id>.L <answer>.L
  13946. /// answer:
  13947. /// 0 = rejected
  13948. /// 1 = accepted
  13949. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  13950. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13951. int p1_id = RFIFOL(fd,info->pos[0]);
  13952. int p2_id = RFIFOL(fd,info->pos[1]);
  13953. int result = RFIFOL(fd,info->pos[2]);
  13954. struct map_session_data* p1_sd = map_id2sd(p1_id);
  13955. struct map_session_data* p2_sd = map_id2sd(p2_id);
  13956. int pid = sd->adopt_invite;
  13957. sd->adopt_invite = 0;
  13958. if( p1_sd == NULL || p2_sd == NULL )
  13959. return; // Both players need to be online
  13960. if( pid != p1_sd->status.account_id )
  13961. return; // Incorrect values
  13962. if( result == 0 )
  13963. return; // Rejected
  13964. pc_adoption(p1_sd, p2_sd, sd);
  13965. }
  13966. /// Convex Mirror (ZC_BOSS_INFO).
  13967. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  13968. /// infoType:
  13969. /// BOSS_INFO_NOT = No boss on this map.
  13970. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  13971. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  13972. /// BOSS_INFO_DEAD = Boss is dead.
  13973. void clif_bossmapinfo(struct map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  13974. {
  13975. int fd = sd->fd;
  13976. WFIFOHEAD(fd,70);
  13977. memset(WFIFOP(fd,0),0,70);
  13978. WFIFOW(fd,0) = 0x293;
  13979. switch (flag) {
  13980. case BOSS_INFO_NOT:
  13981. WFIFOB(fd,2) = BOSS_INFO_NOT;
  13982. // No data required
  13983. break;
  13984. case BOSS_INFO_ALIVE:
  13985. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  13986. // Update X/Y
  13987. WFIFOL(fd,3) = md->bl.x;
  13988. WFIFOL(fd,7) = md->bl.y;
  13989. break;
  13990. case BOSS_INFO_ALIVE_WITHMSG:
  13991. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  13992. // Current X/Y
  13993. WFIFOL(fd,3) = md->bl.x;
  13994. WFIFOL(fd,7) = md->bl.y;
  13995. break;
  13996. case BOSS_INFO_DEAD:
  13997. {
  13998. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  13999. unsigned int seconds;
  14000. int hours, minutes;
  14001. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  14002. hours = seconds / (60 * 60);
  14003. seconds = seconds - (60 * 60 * hours);
  14004. minutes = seconds / 60;
  14005. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14006. // Add respawn info
  14007. WFIFOW(fd,11) = hours; // Hours
  14008. WFIFOW(fd,13) = minutes; // Minutes
  14009. }
  14010. break;
  14011. }
  14012. if (md != NULL)
  14013. safestrncpy(WFIFOCP(fd,19), md->db->jname, NAME_LENGTH);
  14014. WFIFOSET(fd,70);
  14015. }
  14016. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14017. /// 02d6 <account id>.L
  14018. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  14019. {
  14020. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14021. struct map_session_data* tsd = map_id2sd(aid);
  14022. if (!tsd)
  14023. return;
  14024. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14025. clif_viewequip_ack(sd, tsd);
  14026. else
  14027. clif_msg(sd, VIEW_EQUIP_FAIL);
  14028. }
  14029. /// Request to change equip window tick (CZ_CONFIG).
  14030. /// 02d8 <type>.L <flag>.L
  14031. /// type:
  14032. /// 0 = open equip window
  14033. /// flag:
  14034. /// 0 = disabled
  14035. /// 1 = enabled
  14036. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  14037. {
  14038. //int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14039. bool flag = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]) != 0;
  14040. sd->status.show_equip = flag;
  14041. clif_equiptickack(sd, flag);
  14042. }
  14043. /// Request to change party invitation tick.
  14044. /// value:
  14045. /// 0 = disabled
  14046. /// 1 = enabled
  14047. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14048. {
  14049. bool flag = RFIFOB(fd,6) ? true : false;
  14050. sd->status.allow_party = flag;
  14051. clif_partytickack(sd, flag);
  14052. }
  14053. /// Questlog System [Kevin] [Inkfish]
  14054. ///
  14055. /**
  14056. * Safe check to init packet len & quest num for player.
  14057. * @param def_len
  14058. * @param info_len Length of each quest info.
  14059. * @param avail_quests Avail quests that player has.
  14060. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14061. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14062. **/
  14063. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14064. (*limit_out) = (0xFFFF - def_len) / info_len;
  14065. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14066. (*len_out) = ((*limit_out) * info_len) + def_len;
  14067. }
  14068. /// Sends list of all quest states (ZC_ALL_QUEST_LIST).
  14069. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num
  14070. /// 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)
  14071. /// 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!
  14072. void clif_quest_send_list(struct map_session_data *sd)
  14073. {
  14074. int fd = sd->fd;
  14075. int i;
  14076. int offset = 8;
  14077. int limit = 0;
  14078. #if PACKETVER >= 20141022
  14079. clif_quest_len(offset, 15 + ((10 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14080. WFIFOHEAD(fd,i);
  14081. WFIFOW(fd, 0) = 0x97a;
  14082. WFIFOL(fd, 4) = limit;
  14083. for (i = 0; i < limit; i++) {
  14084. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  14085. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14086. offset += 4;
  14087. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14088. offset++;
  14089. WFIFOL(fd, offset) = sd->quest_log[i].time - qi->time;
  14090. offset += 4;
  14091. WFIFOL(fd, offset) = sd->quest_log[i].time;
  14092. offset += 4;
  14093. WFIFOW(fd, offset) = qi->objectives_count;
  14094. offset += 2;
  14095. if( qi->objectives_count > 0 ){
  14096. int j;
  14097. struct mob_db *mob;
  14098. for( j = 0; j < qi->objectives_count; j++ ){
  14099. mob = mob_db(qi->objectives[j].mob);
  14100. WFIFOL(fd, offset) = qi->objectives[j].mob;
  14101. offset += 4;
  14102. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14103. offset += 2;
  14104. WFIFOW(fd, offset) = qi->objectives[j].count;
  14105. offset += 2;
  14106. safestrncpy((char*)WFIFOP(fd, offset), mob->jname, NAME_LENGTH);
  14107. offset += NAME_LENGTH;
  14108. }
  14109. }
  14110. }
  14111. WFIFOW(fd, 2) = offset;
  14112. WFIFOSET(fd, offset);
  14113. #else
  14114. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14115. WFIFOHEAD(fd,i);
  14116. WFIFOW(fd, 0) = 0x2b1;
  14117. WFIFOL(fd, 4) = limit;
  14118. for (i = 0; i < limit; i++) {
  14119. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14120. offset += 4;
  14121. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14122. offset += 1;
  14123. }
  14124. WFIFOW(fd, 2) = offset;
  14125. WFIFOSET(fd, offset);
  14126. #endif
  14127. }
  14128. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14129. /// 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
  14130. void clif_quest_send_mission(struct map_session_data *sd)
  14131. {
  14132. int fd = sd->fd;
  14133. int i, j, limit = 0;
  14134. int len = sd->avail_quests*104+8;
  14135. struct mob_db *mob;
  14136. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14137. WFIFOHEAD(fd, len);
  14138. WFIFOW(fd, 0) = 0x2b2;
  14139. WFIFOW(fd, 2) = len;
  14140. WFIFOL(fd, 4) = limit;
  14141. for (i = 0; i < limit; i++) {
  14142. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  14143. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14144. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  14145. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  14146. WFIFOW(fd, i*104+20) = qi->objectives_count;
  14147. for (j = 0 ; j < qi->objectives_count; j++) {
  14148. WFIFOL(fd, i*104+22+j*30) = qi->objectives[j].mob;
  14149. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14150. mob = mob_db(qi->objectives[j].mob);
  14151. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  14152. }
  14153. }
  14154. WFIFOSET(fd, len);
  14155. }
  14156. /// Notification about a new quest (ZC_ADD_QUEST).
  14157. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3
  14158. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14159. {
  14160. int fd = sd->fd;
  14161. int i;
  14162. struct quest_db *qi = quest_search(qd->quest_id);
  14163. WFIFOHEAD(fd, packet_len(0x2b3));
  14164. WFIFOW(fd, 0) = 0x2b3;
  14165. WFIFOL(fd, 2) = qd->quest_id;
  14166. WFIFOB(fd, 6) = qd->state;
  14167. WFIFOB(fd, 7) = qd->time - qi->time;
  14168. WFIFOL(fd, 11) = qd->time;
  14169. WFIFOW(fd, 15) = qi->objectives_count;
  14170. for (i = 0; i < qi->objectives_count; i++) {
  14171. struct mob_db *mob;
  14172. WFIFOL(fd, i*30+17) = qi->objectives[i].mob;
  14173. WFIFOW(fd, i*30+21) = qd->count[i];
  14174. mob = mob_db(qi->objectives[i].mob);
  14175. safestrncpy(WFIFOCP(fd, i*30+23), mob->jname, NAME_LENGTH);
  14176. }
  14177. WFIFOSET(fd, packet_len(0x2b3));
  14178. }
  14179. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14180. /// 02b4 <quest id>.L
  14181. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  14182. {
  14183. int fd = sd->fd;
  14184. WFIFOHEAD(fd, packet_len(0x2b4));
  14185. WFIFOW(fd, 0) = 0x2b4;
  14186. WFIFOL(fd, 2) = quest_id;
  14187. WFIFOSET(fd, packet_len(0x2b4));
  14188. }
  14189. /// Notification of an update to the hunting mission counter (ZC_UPDATE_MISSION_HUNT).
  14190. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3
  14191. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd, int mobid)
  14192. {
  14193. int fd = sd->fd;
  14194. int i;
  14195. struct quest_db *qi = quest_search(qd->quest_id);
  14196. int len = qi->objectives_count * 12 + 6;
  14197. WFIFOHEAD(fd, len);
  14198. WFIFOW(fd, 0) = 0x2b5;
  14199. WFIFOW(fd, 2) = len;
  14200. WFIFOW(fd, 4) = qi->objectives_count;
  14201. for (i = 0; i < qi->objectives_count; i++) {
  14202. if (mobid == 0 || mobid == qi->objectives[i].mob) {
  14203. WFIFOL(fd, i * 12 + 6) = qd->quest_id;
  14204. WFIFOL(fd, i * 12 + 10) = qi->objectives[i].mob;
  14205. WFIFOW(fd, i * 12 + 14) = qi->objectives[i].count;
  14206. WFIFOW(fd, i * 12 + 16) = qd->count[i];
  14207. }
  14208. }
  14209. WFIFOSET(fd, len);
  14210. }
  14211. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14212. /// 02b6 <quest id>.L <active>.B
  14213. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  14214. {
  14215. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14216. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14217. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14218. }
  14219. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14220. /// 02b7 <quest id>.L <active>.B
  14221. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  14222. {
  14223. int fd = sd->fd;
  14224. WFIFOHEAD(fd, packet_len(0x2b7));
  14225. WFIFOW(fd, 0) = 0x2b7;
  14226. WFIFOL(fd, 2) = quest_id;
  14227. WFIFOB(fd, 6) = active;
  14228. WFIFOSET(fd, packet_len(0x2b7));
  14229. }
  14230. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14231. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14232. /// effect:
  14233. /// 0 = none
  14234. /// 1 = exclamation mark icon
  14235. /// 2 = question mark icon
  14236. /// color:
  14237. /// 0 = yellow
  14238. /// 1 = orange
  14239. /// 2 = green
  14240. /// 3 = purple
  14241. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short effect, short color)
  14242. {
  14243. #if PACKETVER >= 20090218
  14244. int fd = sd->fd;
  14245. WFIFOHEAD(fd, packet_len(0x446));
  14246. WFIFOW(fd, 0) = 0x446;
  14247. WFIFOL(fd, 2) = bl->id;
  14248. WFIFOW(fd, 6) = bl->x;
  14249. WFIFOW(fd, 8) = bl->y;
  14250. WFIFOW(fd, 10) = effect;
  14251. WFIFOW(fd, 12) = color;
  14252. WFIFOSET(fd, packet_len(0x446));
  14253. #endif
  14254. }
  14255. /// Mercenary System
  14256. ///
  14257. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14258. /// 02a2 <var id>.W <value>.L
  14259. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  14260. {
  14261. struct mercenary_data *md;
  14262. struct status_data *status;
  14263. int fd;
  14264. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14265. return;
  14266. fd = sd->fd;
  14267. status = &md->battle_status;
  14268. WFIFOHEAD(fd,packet_len(0x2a2));
  14269. WFIFOW(fd,0) = 0x2a2;
  14270. WFIFOW(fd,2) = type;
  14271. switch( type ) {
  14272. case SP_ATK1:
  14273. {
  14274. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  14275. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14276. }
  14277. break;
  14278. case SP_MATK1:
  14279. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14280. break;
  14281. case SP_HIT:
  14282. WFIFOL(fd,4) = status->hit;
  14283. break;
  14284. case SP_CRITICAL:
  14285. WFIFOL(fd,4) = status->cri/10;
  14286. break;
  14287. case SP_DEF1:
  14288. WFIFOL(fd,4) = status->def;
  14289. break;
  14290. case SP_MDEF1:
  14291. WFIFOL(fd,4) = status->mdef;
  14292. break;
  14293. case SP_MERCFLEE:
  14294. WFIFOL(fd,4) = status->flee;
  14295. break;
  14296. case SP_ASPD:
  14297. WFIFOL(fd,4) = status->amotion;
  14298. break;
  14299. case SP_HP:
  14300. WFIFOL(fd,4) = status->hp;
  14301. break;
  14302. case SP_MAXHP:
  14303. WFIFOL(fd,4) = status->max_hp;
  14304. break;
  14305. case SP_SP:
  14306. WFIFOL(fd,4) = status->sp;
  14307. break;
  14308. case SP_MAXSP:
  14309. WFIFOL(fd,4) = status->max_sp;
  14310. break;
  14311. case SP_MERCKILLS:
  14312. WFIFOL(fd,4) = md->mercenary.kill_count;
  14313. break;
  14314. case SP_MERCFAITH:
  14315. WFIFOL(fd,4) = mercenary_get_faith(md);
  14316. break;
  14317. }
  14318. WFIFOSET(fd,packet_len(0x2a2));
  14319. }
  14320. /// Mercenary base status data (ZC_MER_INIT).
  14321. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14322. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14323. /// <calls>.L <kills>.L <atk range>.W
  14324. void clif_mercenary_info(struct map_session_data *sd)
  14325. {
  14326. int fd;
  14327. struct mercenary_data *md;
  14328. struct status_data *status;
  14329. int atk;
  14330. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14331. return;
  14332. fd = sd->fd;
  14333. status = &md->battle_status;
  14334. WFIFOHEAD(fd,packet_len(0x29b));
  14335. WFIFOW(fd,0) = 0x29b;
  14336. WFIFOL(fd,2) = md->bl.id;
  14337. // Mercenary shows ATK as a random value between ATK ~ ATK2
  14338. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  14339. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  14340. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  14341. WFIFOW(fd,10) = status->hit;
  14342. WFIFOW(fd,12) = status->cri/10;
  14343. WFIFOW(fd,14) = status->def;
  14344. WFIFOW(fd,16) = status->mdef;
  14345. WFIFOW(fd,18) = status->flee;
  14346. WFIFOW(fd,20) = status->amotion;
  14347. safestrncpy(WFIFOCP(fd,22), md->db->name, NAME_LENGTH);
  14348. WFIFOW(fd,46) = md->db->lv;
  14349. WFIFOL(fd,48) = status->hp;
  14350. WFIFOL(fd,52) = status->max_hp;
  14351. WFIFOL(fd,56) = status->sp;
  14352. WFIFOL(fd,60) = status->max_sp;
  14353. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  14354. WFIFOW(fd,68) = mercenary_get_faith(md);
  14355. WFIFOL(fd,70) = mercenary_get_calls(md);
  14356. WFIFOL(fd,74) = md->mercenary.kill_count;
  14357. WFIFOW(fd,78) = md->battle_status.rhw.range;
  14358. WFIFOSET(fd,packet_len(0x29b));
  14359. }
  14360. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  14361. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  14362. void clif_mercenary_skillblock(struct map_session_data *sd)
  14363. {
  14364. struct mercenary_data *md;
  14365. int fd, i, len = 4;
  14366. if( sd == NULL || (md = sd->md) == NULL )
  14367. return;
  14368. fd = sd->fd;
  14369. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  14370. WFIFOW(fd,0) = 0x29d;
  14371. for( i = 0; i < MAX_MERCSKILL; i++ )
  14372. {
  14373. uint16 id;
  14374. short idx = -1;
  14375. if( (id = md->db->skill[i].id) == 0 )
  14376. continue;
  14377. if ((idx = mercenary_skill_get_index(id)) == -1)
  14378. continue;
  14379. WFIFOW(fd,len) = id;
  14380. WFIFOL(fd,len+2) = skill_get_inf(id);
  14381. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  14382. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  14383. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv, false);
  14384. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  14385. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  14386. len += 37;
  14387. }
  14388. WFIFOW(fd,2) = len;
  14389. WFIFOSET(fd,len);
  14390. }
  14391. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  14392. /// 029f <command>.B
  14393. /// 1 = mercenary information
  14394. /// 2 = delete
  14395. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  14396. {
  14397. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14398. if( sd->md == NULL )
  14399. return;
  14400. if( option == 2 ) mercenary_delete(sd->md, 2);
  14401. }
  14402. /// Mercenary Message
  14403. /// message:
  14404. /// 0 = Mercenary soldier's duty hour is over.
  14405. /// 1 = Your mercenary soldier has been killed.
  14406. /// 2 = Your mercenary soldier has been fired.
  14407. /// 3 = Your mercenary soldier has ran away.
  14408. void clif_mercenary_message(struct map_session_data* sd, int message){
  14409. clif_msg(sd, MERC_MSG_BASE + message);
  14410. }
  14411. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  14412. /// 0298 <name id>.W <seconds>.L
  14413. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  14414. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  14415. WFIFOHEAD(fd,packet_len(0x298));
  14416. WFIFOW(fd,0) = 0x298;
  14417. WFIFOW(fd,2) = nameid;
  14418. WFIFOL(fd,4) = seconds;
  14419. WFIFOSET(fd,packet_len(0x298));
  14420. }
  14421. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  14422. /// 0299 <index>.W <name id>.W
  14423. void clif_rental_expired(int fd, int index, unsigned short nameid)
  14424. { // '<ItemName>' item has been deleted from the Inventory
  14425. WFIFOHEAD(fd,packet_len(0x299));
  14426. WFIFOW(fd,0) = 0x299;
  14427. WFIFOW(fd,2) = index+2;
  14428. WFIFOW(fd,4) = nameid;
  14429. WFIFOSET(fd,packet_len(0x299));
  14430. }
  14431. /// Book Reading (ZC_READ_BOOK).
  14432. /// 0294 <book id>.L <page>.L
  14433. void clif_readbook(int fd, int book_id, int page)
  14434. {
  14435. WFIFOHEAD(fd,packet_len(0x294));
  14436. WFIFOW(fd,0) = 0x294;
  14437. WFIFOL(fd,2) = book_id;
  14438. WFIFOL(fd,6) = page;
  14439. WFIFOSET(fd,packet_len(0x294));
  14440. }
  14441. /// Battlegrounds
  14442. ///
  14443. /// Updates HP bar of a camp member.
  14444. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  14445. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  14446. void clif_bg_hp(struct map_session_data *sd) {
  14447. #if PACKETVER < 20140613
  14448. unsigned char buf[34];
  14449. const int cmd = 0x2e0;
  14450. #else
  14451. unsigned char buf[14];
  14452. const int cmd = 0xa0e;
  14453. #endif
  14454. nullpo_retv(sd);
  14455. WBUFW(buf,0) = cmd;
  14456. WBUFL(buf,2) = sd->status.account_id;
  14457. #if PACKETVER < 20140613
  14458. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14459. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  14460. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14461. WBUFW(buf,32) = 100;
  14462. } else {
  14463. WBUFW(buf,30) = sd->battle_status.hp;
  14464. WBUFW(buf,32) = sd->battle_status.max_hp;
  14465. }
  14466. #else
  14467. if( sd->battle_status.max_hp > INT32_MAX ) {
  14468. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14469. WBUFL(buf,10) = 100;
  14470. } else {
  14471. WBUFL(buf,6) = sd->battle_status.hp;
  14472. WBUFL(buf,10) = sd->battle_status.max_hp;
  14473. }
  14474. #endif
  14475. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  14476. }
  14477. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  14478. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  14479. void clif_bg_xy(struct map_session_data *sd)
  14480. {
  14481. unsigned char buf[36];
  14482. nullpo_retv(sd);
  14483. WBUFW(buf,0)=0x2df;
  14484. WBUFL(buf,2)=sd->status.account_id;
  14485. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14486. WBUFW(buf,30)=sd->status.class_;
  14487. WBUFW(buf,32)=sd->bl.x;
  14488. WBUFW(buf,34)=sd->bl.y;
  14489. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14490. }
  14491. void clif_bg_xy_remove(struct map_session_data *sd)
  14492. {
  14493. unsigned char buf[36];
  14494. nullpo_retv(sd);
  14495. WBUFW(buf,0)=0x2df;
  14496. WBUFL(buf,2)=sd->status.account_id;
  14497. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  14498. WBUFW(buf,30)=0;
  14499. WBUFW(buf,32)=-1;
  14500. WBUFW(buf,34)=-1;
  14501. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14502. }
  14503. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  14504. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  14505. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  14506. {
  14507. struct map_session_data *sd;
  14508. unsigned char *buf;
  14509. if( (sd = bg_getavailablesd(bg)) == NULL )
  14510. return;
  14511. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  14512. WBUFW(buf,0) = 0x2dc;
  14513. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  14514. WBUFL(buf,4) = src_id;
  14515. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  14516. memcpy(WBUFP(buf,32), mes, len);
  14517. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  14518. if( buf )
  14519. aFree(buf);
  14520. }
  14521. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  14522. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  14523. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  14524. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  14525. if( !clif_process_message( sd, false, name, message, output ) )
  14526. return;
  14527. bg_send_message(sd, output, strlen(output) );
  14528. }
  14529. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  14530. /// 02de <camp A points>.W <camp B points>.W
  14531. void clif_bg_updatescore(int16 m)
  14532. {
  14533. struct block_list bl;
  14534. unsigned char buf[6];
  14535. bl.id = 0;
  14536. bl.type = BL_NUL;
  14537. bl.m = m;
  14538. WBUFW(buf,0) = 0x2de;
  14539. WBUFW(buf,2) = map[m].bgscore_lion;
  14540. WBUFW(buf,4) = map[m].bgscore_eagle;
  14541. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  14542. }
  14543. void clif_bg_updatescore_single(struct map_session_data *sd)
  14544. {
  14545. int fd;
  14546. nullpo_retv(sd);
  14547. fd = sd->fd;
  14548. WFIFOHEAD(fd,packet_len(0x2de));
  14549. WFIFOW(fd,0) = 0x2de;
  14550. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  14551. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  14552. WFIFOSET(fd,packet_len(0x2de));
  14553. }
  14554. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  14555. /// 02dd <account id>.L <name>.24B <camp>.W
  14556. void clif_sendbgemblem_area(struct map_session_data *sd)
  14557. {
  14558. unsigned char buf[33];
  14559. nullpo_retv(sd);
  14560. WBUFW(buf, 0) = 0x2dd;
  14561. WBUFL(buf,2) = sd->bl.id;
  14562. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  14563. WBUFW(buf,30) = sd->bg_id;
  14564. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  14565. }
  14566. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  14567. {
  14568. nullpo_retv(sd);
  14569. WFIFOHEAD(fd,32);
  14570. WFIFOW(fd,0) = 0x2dd;
  14571. WFIFOL(fd,2) = sd->bl.id;
  14572. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  14573. WFIFOW(fd,30) = sd->bg_id;
  14574. WFIFOSET(fd,packet_len(0x2dd));
  14575. }
  14576. /// Custom Fonts (ZC_NOTIFY_FONT).
  14577. /// 02ef <account_id>.L <font id>.W
  14578. void clif_font(struct map_session_data *sd)
  14579. {
  14580. #if PACKETVER >= 20080102
  14581. unsigned char buf[8];
  14582. nullpo_retv(sd);
  14583. WBUFW(buf,0) = 0x2ef;
  14584. WBUFL(buf,2) = sd->bl.id;
  14585. WBUFW(buf,6) = sd->status.font;
  14586. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  14587. #endif
  14588. }
  14589. /// Required to start the instancing information window on Client
  14590. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  14591. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  14592. void clif_instance_create(unsigned short instance_id, int num)
  14593. {
  14594. #if PACKETVER >= 20071128
  14595. struct instance_db *db = NULL;
  14596. struct map_session_data *sd = NULL;
  14597. enum send_target target = PARTY;
  14598. unsigned char buf[65];
  14599. instance_getsd(instance_id, &sd, &target);
  14600. if (!sd)
  14601. return;
  14602. db = instance_searchtype_db(instance_data[instance_id].type);
  14603. if (!db)
  14604. return;
  14605. WBUFW(buf,0) = 0x2cb;
  14606. safestrncpy(WBUFCP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  14607. WBUFW(buf,63) = num;
  14608. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  14609. #endif
  14610. return;
  14611. }
  14612. /// To announce Instancing queue creation if no maps available
  14613. /// S 0x2cc <Standby Position>.W
  14614. void clif_instance_changewait(unsigned short instance_id, int num)
  14615. {
  14616. #if PACKETVER >= 20071128
  14617. struct map_session_data *sd = NULL;
  14618. enum send_target target = PARTY;
  14619. unsigned char buf[4];
  14620. instance_getsd(instance_id, &sd, &target);
  14621. if (!sd)
  14622. return;
  14623. WBUFW(buf,0) = 0x2cc;
  14624. WBUFW(buf,2) = num;
  14625. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  14626. #endif
  14627. return;
  14628. }
  14629. /// Notify the current status to members
  14630. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  14631. void clif_instance_status(unsigned short instance_id, unsigned int limit1, unsigned int limit2)
  14632. {
  14633. #if PACKETVER >= 20071128
  14634. struct instance_db *db = NULL;
  14635. struct map_session_data *sd = NULL;
  14636. enum send_target target = PARTY;
  14637. unsigned char buf[71];
  14638. instance_getsd(instance_id, &sd, &target);
  14639. if (!sd)
  14640. return;
  14641. db = instance_searchtype_db(instance_data[instance_id].type);
  14642. if (!db)
  14643. return;
  14644. WBUFW(buf,0) = 0x2cd;
  14645. safestrncpy(WBUFCP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  14646. WBUFL(buf,63) = limit1;
  14647. WBUFL(buf,67) = limit2;
  14648. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  14649. #endif
  14650. return;
  14651. }
  14652. /// Notify a status change to members
  14653. /// S 0x2ce <Message ID>.L
  14654. /// 0 = Notification (EnterLimitDate update?)
  14655. /// 1 = The Memorial Dungeon expired; it has been destroyed
  14656. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  14657. /// 3 = The Memorial Dungeon has been removed.
  14658. /// 4 = Create failure (removes the instance window)
  14659. void clif_instance_changestatus(unsigned int instance_id, int type, unsigned int limit)
  14660. {
  14661. #if PACKETVER >= 20071128
  14662. struct map_session_data *sd = NULL;
  14663. enum send_target target = PARTY;
  14664. unsigned char buf[10];
  14665. instance_getsd(instance_id, &sd, &target);
  14666. if (!sd)
  14667. return;
  14668. WBUFW(buf,0) = 0x2ce;
  14669. WBUFL(buf,2) = type;
  14670. WBUFL(buf,6) = limit;
  14671. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  14672. #endif
  14673. return;
  14674. }
  14675. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  14676. /// 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
  14677. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  14678. {
  14679. #if PACKETVER >= 20071002
  14680. unsigned char buf[22];
  14681. struct item_data* id = itemdb_search(item_data->nameid);
  14682. WBUFW(buf,0) = 0x2b8;
  14683. WBUFL(buf,2) = sd->status.account_id;
  14684. WBUFW(buf,6) = item_data->nameid;
  14685. WBUFB(buf,8) = item_data->identify;
  14686. WBUFB(buf,9) = item_data->attribute;
  14687. WBUFB(buf,10) = item_data->refine;
  14688. clif_addcards(WBUFP(buf,11), item_data);
  14689. WBUFW(buf,19) = id->equip; // equip location
  14690. WBUFB(buf,21) = itemtype(id->nameid); // item type
  14691. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  14692. #endif
  14693. }
  14694. /** Display gained exp.
  14695. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  14696. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  14697. * amount: INT32_MIN ~ INT32_MAX
  14698. * var id:
  14699. * SP_BASEEXP, SP_JOBEXP
  14700. * exp type:
  14701. * 0 = normal exp gained/lost
  14702. * 1 = quest exp gained/lost
  14703. * @param sd Player
  14704. * @param exp EXP value gained/loss
  14705. * @param type SP_BASEEXP, SP_JOBEXP
  14706. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  14707. * @param lost True:if lossing EXP
  14708. */
  14709. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest, bool lost)
  14710. {
  14711. int fd;
  14712. int offset;
  14713. #if PACKETVER >= 20170830
  14714. int cmd = 0xacc;
  14715. #else
  14716. int cmd = 0x7f6;
  14717. #endif
  14718. nullpo_retv(sd);
  14719. fd = sd->fd;
  14720. WFIFOHEAD(fd, packet_len(cmd));
  14721. WFIFOW(fd,0) = cmd;
  14722. WFIFOL(fd,2) = sd->bl.id;
  14723. #if PACKETVER >= 20170830
  14724. WFIFOQ(fd,6) = (int64)u64min((uint64)exp, INT_MAX) * (lost ? -1 : 1);
  14725. offset = 4;
  14726. #else
  14727. WFIFOL(fd,6) = (int)umin(exp, INT_MAX) * (lost ? -1 : 1);
  14728. offset = 0;
  14729. #endif
  14730. WFIFOW(fd,10+offset) = type;
  14731. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  14732. WFIFOSET(fd,packet_len(cmd));
  14733. }
  14734. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  14735. /// type:
  14736. /// 0 = Displays 'value' for 5 seconds.
  14737. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  14738. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  14739. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  14740. /// value:
  14741. /// 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).
  14742. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  14743. {
  14744. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  14745. WFIFOW(sd->fd,0) = 0x1b1;
  14746. WFIFOB(sd->fd,2) = type;
  14747. WFIFOL(sd->fd,3) = value;
  14748. WFIFOSET(sd->fd, packet_len(0x1b1));
  14749. }
  14750. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  14751. /// 021d <state>.L
  14752. /// state:
  14753. /// 0 = Full effects
  14754. /// 1 = Reduced effects
  14755. ///
  14756. /// NOTE: The state is used on Aegis for sending skill unit packet
  14757. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  14758. /// whenever possible. Due to the way the decision check is
  14759. /// constructed, this state tracking was rendered useless,
  14760. /// as the only skill unit, that is sent with 0x1c9 is
  14761. /// Graffiti.
  14762. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  14763. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14764. sd->state.lesseffect = ( isLess != 0 );
  14765. }
  14766. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  14767. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  14768. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14769. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  14770. int type = RFIFOL(fd,info->pos[1]);
  14771. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  14772. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  14773. if( sd->state.trading || sd->npc_shopid )
  14774. return;
  14775. if( flag == 0 || n == 0) {
  14776. clif_menuskill_clear(sd);
  14777. return; // Canceled by player.
  14778. }
  14779. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  14780. clif_menuskill_clear(sd);
  14781. return; // Prevent hacking.
  14782. }
  14783. switch( type ) {
  14784. case 0: // Change Material
  14785. skill_changematerial(sd,n,item_list);
  14786. break;
  14787. case 1: // Level 1: Pure to Rough
  14788. case 2: // Level 2: Rough to Pure
  14789. skill_elementalanalysis(sd,n,type,item_list);
  14790. break;
  14791. }
  14792. clif_menuskill_clear(sd);
  14793. return;
  14794. }
  14795. /*==========================================
  14796. * Elemental System
  14797. *==========================================*/
  14798. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  14799. struct elemental_data *ed;
  14800. struct status_data *status;
  14801. int fd;
  14802. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  14803. return;
  14804. fd = sd->fd;
  14805. status = &ed->battle_status;
  14806. WFIFOHEAD(fd,8);
  14807. WFIFOW(fd,0) = 0x81e;
  14808. WFIFOW(fd,2) = type;
  14809. switch( type ) {
  14810. case SP_HP:
  14811. WFIFOL(fd,4) = status->hp;
  14812. break;
  14813. case SP_MAXHP:
  14814. WFIFOL(fd,4) = status->max_hp;
  14815. break;
  14816. case SP_SP:
  14817. WFIFOL(fd,4) = status->sp;
  14818. break;
  14819. case SP_MAXSP:
  14820. WFIFOL(fd,4) = status->max_sp;
  14821. break;
  14822. }
  14823. WFIFOSET(fd,8);
  14824. }
  14825. void clif_elemental_info(struct map_session_data *sd) {
  14826. int fd;
  14827. struct elemental_data *ed;
  14828. struct status_data *status;
  14829. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  14830. return;
  14831. fd = sd->fd;
  14832. status = &ed->battle_status;
  14833. WFIFOHEAD(fd,22);
  14834. WFIFOW(fd, 0) = 0x81d;
  14835. WFIFOL(fd, 2) = ed->bl.id;
  14836. WFIFOL(fd, 6) = status->hp;
  14837. WFIFOL(fd,10) = status->max_hp;
  14838. WFIFOL(fd,14) = status->sp;
  14839. WFIFOL(fd,18) = status->max_sp;
  14840. WFIFOSET(fd,22);
  14841. }
  14842. /// Buying Store System
  14843. ///
  14844. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  14845. /// 0810 <slots>.B
  14846. void clif_buyingstore_open(struct map_session_data* sd)
  14847. {
  14848. int fd = sd->fd;
  14849. WFIFOHEAD(fd,packet_len(0x810));
  14850. WFIFOW(fd,0) = 0x810;
  14851. WFIFOB(fd,2) = sd->buyingstore.slots;
  14852. WFIFOSET(fd,packet_len(0x810));
  14853. }
  14854. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  14855. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  14856. /// result:
  14857. /// 0 = cancel
  14858. /// 1 = open
  14859. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  14860. {
  14861. const unsigned int blocksize = 8;
  14862. uint8* itemlist;
  14863. char storename[MESSAGE_SIZE];
  14864. unsigned char result;
  14865. int zenylimit;
  14866. unsigned int count, packet_len;
  14867. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14868. packet_len = RFIFOW(fd,info->pos[0]);
  14869. // TODO: Make this check global for all variable length packets.
  14870. if( packet_len < 89 )
  14871. {// minimum packet length
  14872. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  14873. return;
  14874. }
  14875. zenylimit = RFIFOL(fd,info->pos[1]);
  14876. result = RFIFOL(fd,info->pos[2]);
  14877. safestrncpy(storename, RFIFOCP(fd,info->pos[3]), sizeof(storename));
  14878. itemlist = RFIFOP(fd,info->pos[4]);
  14879. // so that buyingstore_create knows, how many elements it has access to
  14880. packet_len-= info->pos[4];
  14881. if( packet_len%blocksize )
  14882. {
  14883. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  14884. return;
  14885. }
  14886. count = packet_len/blocksize;
  14887. buyingstore_create(sd, zenylimit, result, storename, itemlist, count, NULL);
  14888. }
  14889. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  14890. /// 0812 <result>.W <total weight>.L
  14891. /// result:
  14892. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  14893. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  14894. /// 8 = "No sale (purchase) information available." (0x705)
  14895. /// ? = nothing
  14896. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  14897. {
  14898. int fd = sd->fd;
  14899. WFIFOHEAD(fd,packet_len(0x812));
  14900. WFIFOW(fd,0) = 0x812;
  14901. WFIFOW(fd,2) = result;
  14902. WFIFOL(fd,4) = weight;
  14903. WFIFOSET(fd,packet_len(0x812));
  14904. }
  14905. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  14906. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  14907. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  14908. {
  14909. int fd = sd->fd;
  14910. unsigned int i;
  14911. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  14912. WFIFOW(fd,0) = 0x813;
  14913. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  14914. WFIFOL(fd,4) = sd->bl.id;
  14915. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  14916. for( i = 0; i < sd->buyingstore.slots; i++ )
  14917. {
  14918. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  14919. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  14920. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  14921. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  14922. }
  14923. WFIFOSET(fd,WFIFOW(fd,2));
  14924. }
  14925. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  14926. /// 0814 <account id>.L <store name>.80B
  14927. void clif_buyingstore_entry(struct map_session_data* sd)
  14928. {
  14929. uint8 buf[MESSAGE_SIZE+6];
  14930. WBUFW(buf,0) = 0x814;
  14931. WBUFL(buf,2) = sd->bl.id;
  14932. safestrncpy(WBUFCP(buf,6), sd->message, MESSAGE_SIZE);
  14933. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  14934. }
  14935. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14936. {
  14937. int fd = sd->fd;
  14938. WFIFOHEAD(fd,packet_len(0x814));
  14939. WFIFOW(fd,0) = 0x814;
  14940. WFIFOL(fd,2) = pl_sd->bl.id;
  14941. safestrncpy(WFIFOCP(fd,6), pl_sd->message, MESSAGE_SIZE);
  14942. WFIFOSET(fd,packet_len(0x814));
  14943. }
  14944. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  14945. /// 0815
  14946. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  14947. {
  14948. buyingstore_close(sd);
  14949. }
  14950. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  14951. /// 0816 <account id>.L
  14952. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  14953. {
  14954. uint8 buf[6];
  14955. WBUFW(buf,0) = 0x816;
  14956. WBUFL(buf,2) = sd->bl.id;
  14957. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  14958. }
  14959. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  14960. {
  14961. int fd = sd->fd;
  14962. WFIFOHEAD(fd,packet_len(0x816));
  14963. WFIFOW(fd,0) = 0x816;
  14964. WFIFOL(fd,2) = pl_sd->bl.id;
  14965. WFIFOSET(fd,packet_len(0x816));
  14966. }
  14967. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  14968. /// 0817 <account id>.L
  14969. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  14970. {
  14971. uint32 account_id;
  14972. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14973. buyingstore_open(sd, account_id);
  14974. }
  14975. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  14976. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  14977. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  14978. {
  14979. int fd = sd->fd;
  14980. unsigned int i;
  14981. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  14982. WFIFOW(fd,0) = 0x818;
  14983. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  14984. WFIFOL(fd,4) = pl_sd->bl.id;
  14985. WFIFOL(fd,8) = pl_sd->buyer_id;
  14986. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  14987. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  14988. {
  14989. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  14990. 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.
  14991. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  14992. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  14993. }
  14994. WFIFOSET(fd,WFIFOW(fd,2));
  14995. }
  14996. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  14997. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  14998. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  14999. {
  15000. const unsigned int blocksize = 6;
  15001. uint8* itemlist;
  15002. uint32 account_id;
  15003. unsigned int count, packet_len, buyer_id;
  15004. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15005. packet_len = RFIFOW(fd,info->pos[0]);
  15006. if( packet_len < 12 )
  15007. {// minimum packet length
  15008. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  15009. return;
  15010. }
  15011. account_id = RFIFOL(fd,info->pos[1]);
  15012. buyer_id = RFIFOL(fd,info->pos[2]);
  15013. itemlist = RFIFOP(fd,info->pos[3]);
  15014. // so that buyingstore_trade knows, how many elements it has access to
  15015. packet_len-= info->pos[3];
  15016. if( packet_len%blocksize )
  15017. {
  15018. 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);
  15019. return;
  15020. }
  15021. count = packet_len/blocksize;
  15022. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  15023. }
  15024. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15025. /// 081a <result>.W
  15026. /// result:
  15027. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15028. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15029. /// ? = nothing
  15030. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  15031. {
  15032. int fd = sd->fd;
  15033. WFIFOHEAD(fd,packet_len(0x81a));
  15034. WFIFOW(fd,0) = 0x81a;
  15035. WFIFOW(fd,2) = result;
  15036. WFIFOSET(fd,packet_len(0x81a));
  15037. }
  15038. /// Updates the zeny limit and an item in the buying store item list.
  15039. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15040. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15041. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount, uint32 char_id, int zeny) {
  15042. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  15043. const int cmd = 0x81b;
  15044. #else
  15045. const int cmd = 0x9e6;
  15046. #endif
  15047. int offset = 0;
  15048. int fd = sd->fd;
  15049. WFIFOHEAD(fd,packet_len(cmd));
  15050. WFIFOW(fd,0) = cmd;
  15051. WFIFOW(fd,2) = nameid;
  15052. WFIFOW(fd,4) = amount; // amount of nameid received
  15053. #if PACKETVER >= 20141016
  15054. WFIFOL(fd,6) = zeny; // zeny
  15055. offset += 4;
  15056. #endif
  15057. WFIFOL(fd,6+offset) = sd->buyingstore.zenylimit;
  15058. #if PACKETVER >= 20141016
  15059. WFIFOL(fd,10+offset) = char_id; // GID
  15060. WFIFOL(fd,14+offset) = (int)time(NULL); // date
  15061. #endif
  15062. WFIFOSET(fd,packet_len(cmd));
  15063. }
  15064. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15065. /// 081c <index>.W <amount>.W <price>.L
  15066. /// message:
  15067. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15068. ///
  15069. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15070. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  15071. {
  15072. int fd = sd->fd;
  15073. WFIFOHEAD(fd,packet_len(0x81c));
  15074. WFIFOW(fd,0) = 0x81c;
  15075. WFIFOW(fd,2) = index+2;
  15076. WFIFOW(fd,4) = amount;
  15077. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15078. WFIFOSET(fd,packet_len(0x81c));
  15079. }
  15080. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15081. /// 0824 <result>.W <name id>.W
  15082. /// result:
  15083. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15084. /// 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)
  15085. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15086. /// ? = nothing
  15087. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  15088. {
  15089. int fd = sd->fd;
  15090. WFIFOHEAD(fd,packet_len(0x824));
  15091. WFIFOW(fd,0) = 0x824;
  15092. WFIFOW(fd,2) = result;
  15093. WFIFOW(fd,4) = nameid;
  15094. WFIFOSET(fd,packet_len(0x824));
  15095. }
  15096. /// Search Store Info System
  15097. ///
  15098. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15099. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15100. /// type:
  15101. /// 0 = Vending
  15102. /// 1 = Buying Store
  15103. ///
  15104. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15105. /// amount of card slots. If the client does not know about the item it
  15106. /// cannot be searched.
  15107. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  15108. {
  15109. const unsigned int blocksize = 2;
  15110. const uint8* itemlist;
  15111. const uint8* cardlist;
  15112. unsigned char type;
  15113. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  15114. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15115. packet_len = RFIFOW(fd,info->pos[0]);
  15116. if( packet_len < 15 )
  15117. {// minimum packet length
  15118. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  15119. return;
  15120. }
  15121. type = RFIFOB(fd,info->pos[1]);
  15122. max_price = RFIFOL(fd,info->pos[2]);
  15123. min_price = RFIFOL(fd,info->pos[3]);
  15124. item_count = RFIFOB(fd,info->pos[4]);
  15125. card_count = RFIFOB(fd,info->pos[5]);
  15126. itemlist = RFIFOP(fd,info->pos[6]);
  15127. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  15128. // check, if there is enough data for the claimed count of items
  15129. packet_len-= info->pos[6];
  15130. if( packet_len%blocksize )
  15131. {
  15132. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  15133. return;
  15134. }
  15135. count = packet_len/blocksize;
  15136. if( count < item_count+card_count )
  15137. {
  15138. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  15139. return;
  15140. }
  15141. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  15142. }
  15143. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  15144. /// 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 }*
  15145. /// is first page:
  15146. /// 0 = appends to existing results
  15147. /// 1 = clears previous results before displaying this result set
  15148. /// is next page:
  15149. /// 0 = no "next" label
  15150. /// 1 = "next" label to retrieve more results
  15151. void clif_search_store_info_ack(struct map_session_data* sd)
  15152. {
  15153. #if PACKETVER >= 20150225
  15154. const unsigned int blocksize = MESSAGE_SIZE+26+5*MAX_ITEM_RDM_OPT;
  15155. #else
  15156. const unsigned int blocksize = MESSAGE_SIZE+26;
  15157. #endif
  15158. int fd = sd->fd;
  15159. unsigned int i, start, end;
  15160. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  15161. end = umin(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  15162. WFIFOHEAD(fd,7+(end-start)*blocksize);
  15163. WFIFOW(fd,0) = 0x836;
  15164. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  15165. WFIFOB(fd,4) = !sd->searchstore.pages;
  15166. WFIFOB(fd,5) = searchstore_querynext(sd);
  15167. WFIFOB(fd,6) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15168. for( i = start; i < end; i++ ) {
  15169. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  15170. struct item it;
  15171. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  15172. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  15173. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  15174. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  15175. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  15176. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  15177. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  15178. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  15179. // make-up an item for clif_addcards
  15180. memset(&it, 0, sizeof(it));
  15181. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  15182. it.nameid = ssitem->nameid;
  15183. it.amount = ssitem->amount;
  15184. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  15185. clif_add_random_options(WFIFOP(fd,i*blocksize+31+MESSAGE_SIZE), &it);
  15186. }
  15187. WFIFOSET(fd,WFIFOW(fd,2));
  15188. }
  15189. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  15190. /// 0837 <reason>.B
  15191. /// reason:
  15192. /// 0 = "No matching stores were found." (0x70b)
  15193. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  15194. /// 2 = "You cannot search anymore." (0x706)
  15195. /// 3 = "You cannot search yet." (0x708)
  15196. /// 4 = "No sale (purchase) information available." (0x705)
  15197. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  15198. {
  15199. int fd = sd->fd;
  15200. WFIFOHEAD(fd,packet_len(0x837));
  15201. WFIFOW(fd,0) = 0x837;
  15202. WFIFOB(fd,2) = reason;
  15203. WFIFOSET(fd,packet_len(0x837));
  15204. }
  15205. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  15206. /// 0838
  15207. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  15208. {
  15209. searchstore_next(sd);
  15210. }
  15211. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  15212. /// 083a <type>.W <remaining uses>.B
  15213. /// type:
  15214. /// 0 = Search Stores
  15215. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  15216. void clif_open_search_store_info(struct map_session_data* sd)
  15217. {
  15218. int fd = sd->fd;
  15219. WFIFOHEAD(fd,packet_len(0x83a));
  15220. WFIFOW(fd,0) = 0x83a;
  15221. WFIFOW(fd,2) = sd->searchstore.effect;
  15222. #if PACKETVER > 20100701
  15223. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15224. #endif
  15225. WFIFOSET(fd,packet_len(0x83a));
  15226. }
  15227. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  15228. /// 083b
  15229. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  15230. {
  15231. searchstore_close(sd);
  15232. }
  15233. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  15234. /// 083c <account id>.L <store id>.L <nameid>.W
  15235. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  15236. {
  15237. unsigned short nameid;
  15238. uint32 account_id, store_id;
  15239. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15240. account_id = RFIFOL(fd,info->pos[0]);
  15241. store_id = RFIFOL(fd,info->pos[1]);
  15242. nameid = RFIFOW(fd,info->pos[2]);
  15243. searchstore_click(sd, account_id, store_id, nameid);
  15244. }
  15245. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  15246. /// 083d <xPos>.W <yPos>.W
  15247. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  15248. {
  15249. int fd = sd->fd;
  15250. WFIFOHEAD(fd,packet_len(0x83d));
  15251. WFIFOW(fd,0) = 0x83d;
  15252. WFIFOW(fd,2) = x;
  15253. WFIFOW(fd,4) = y;
  15254. WFIFOSET(fd,packet_len(0x83d));
  15255. }
  15256. /// Parse function for packet debugging.
  15257. void clif_parse_debug(int fd,struct map_session_data *sd)
  15258. {
  15259. int cmd, packet_len;
  15260. // clif_parse ensures, that there is at least 2 bytes of data
  15261. cmd = RFIFOW(fd,0);
  15262. if( sd ) {
  15263. packet_len = packet_db[cmd].len;
  15264. if( packet_len == 0 )
  15265. {// unknown
  15266. packet_len = RFIFOREST(fd);
  15267. }
  15268. else if( packet_len == -1 )
  15269. {// variable length
  15270. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  15271. }
  15272. 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);
  15273. }
  15274. else
  15275. {
  15276. packet_len = RFIFOREST(fd);
  15277. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  15278. }
  15279. ShowDump(RFIFOP(fd,0), packet_len);
  15280. }
  15281. /*==========================================
  15282. * Server tells client to display a window similar to Magnifier (item) one
  15283. * Server populates the window with avilable elemental converter options according to player's inventory
  15284. *------------------------------------------*/
  15285. int clif_elementalconverter_list(struct map_session_data *sd) {
  15286. int i,c,view,fd;
  15287. nullpo_ret(sd);
  15288. /// Main client packet processing function
  15289. fd=sd->fd;
  15290. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  15291. WFIFOW(fd, 0)=0x1ad;
  15292. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  15293. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  15294. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  15295. WFIFOW(fd,c*2+ 4)= view;
  15296. else
  15297. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  15298. c++;
  15299. }
  15300. }
  15301. WFIFOW(fd,2) = c*2+4;
  15302. WFIFOSET(fd, WFIFOW(fd,2));
  15303. if (c > 0) {
  15304. sd->menuskill_id = SA_CREATECON;
  15305. sd->menuskill_val = c;
  15306. }
  15307. return 0;
  15308. }
  15309. /**
  15310. * Rune Knight
  15311. **/
  15312. void clif_millenniumshield(struct block_list *bl, short shields) {
  15313. #if PACKETVER >= 20081217
  15314. unsigned char buf[10];
  15315. WBUFW(buf,0) = 0x440;
  15316. WBUFL(buf,2) = bl->id;
  15317. WBUFW(buf,6) = shields;
  15318. WBUFW(buf,8) = 0;
  15319. clif_send(buf,packet_len(0x440),bl,AREA);
  15320. #endif
  15321. }
  15322. /**
  15323. * Warlock
  15324. **/
  15325. /*==========================================
  15326. * Spellbook list [LimitLine/3CeAM]
  15327. *------------------------------------------*/
  15328. int clif_spellbook_list(struct map_session_data *sd)
  15329. {
  15330. int i, c;
  15331. int fd;
  15332. nullpo_ret(sd);
  15333. fd = sd->fd;
  15334. WFIFOHEAD(fd, 8 * 8 + 8);
  15335. WFIFOW(fd,0) = 0x1ad;
  15336. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  15337. {
  15338. if( itemdb_is_spellbook2(sd->inventory.u.items_inventory[i].nameid) )
  15339. {
  15340. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15341. c++;
  15342. }
  15343. }
  15344. if( c > 0 )
  15345. {
  15346. WFIFOW(fd,2) = c * 2 + 4;
  15347. WFIFOSET(fd, WFIFOW(fd, 2));
  15348. sd->menuskill_id = WL_READING_SB;
  15349. sd->menuskill_val = c;
  15350. }
  15351. else{
  15352. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15353. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  15354. }
  15355. return 1;
  15356. }
  15357. /**
  15358. * Mechanic
  15359. **/
  15360. /*==========================================
  15361. * Magic Decoy Material List
  15362. *------------------------------------------*/
  15363. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  15364. int i, c;
  15365. int fd;
  15366. nullpo_ret(sd);
  15367. fd = sd->fd;
  15368. WFIFOHEAD(fd, 8 * 8 + 8);
  15369. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  15370. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  15371. if( itemdb_group_item_exists(IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid) ) {
  15372. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15373. c ++;
  15374. }
  15375. }
  15376. if( c > 0 ) {
  15377. sd->menuskill_id = NC_MAGICDECOY;
  15378. sd->menuskill_val = skill_lv;
  15379. sd->sc.comet_x = x;
  15380. sd->sc.comet_y = y;
  15381. WFIFOW(fd,2) = c * 2 + 4;
  15382. WFIFOSET(fd, WFIFOW(fd, 2));
  15383. } else {
  15384. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  15385. return 0;
  15386. }
  15387. return 1;
  15388. }
  15389. /*==========================================
  15390. * Guillotine Cross Poisons List
  15391. *------------------------------------------*/
  15392. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  15393. int i, c;
  15394. int fd;
  15395. nullpo_ret(sd);
  15396. fd = sd->fd;
  15397. WFIFOHEAD(fd, 8 * 8 + 8);
  15398. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  15399. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  15400. if( itemdb_group_item_exists(IG_POISON, sd->inventory.u.items_inventory[i].nameid) ) {
  15401. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15402. c ++;
  15403. }
  15404. }
  15405. if( c > 0 ) {
  15406. sd->menuskill_id = GC_POISONINGWEAPON;
  15407. sd->menuskill_val = skill_lv;
  15408. WFIFOW(fd,2) = c * 2 + 4;
  15409. WFIFOSET(fd, WFIFOW(fd, 2));
  15410. } else {
  15411. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  15412. return 0;
  15413. }
  15414. return 1;
  15415. }
  15416. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  15417. int clif_autoshadowspell_list(struct map_session_data *sd) {
  15418. int fd, i, c;
  15419. nullpo_ret(sd);
  15420. fd = sd->fd;
  15421. if( !fd )
  15422. return 0;
  15423. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  15424. return 0;
  15425. WFIFOHEAD(fd, 2 * 6 + 4);
  15426. WFIFOW(fd,0) = 0x442;
  15427. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  15428. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  15429. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  15430. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  15431. {
  15432. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  15433. c++;
  15434. }
  15435. if( c > 0 ) {
  15436. WFIFOW(fd,2) = 8 + c * 2;
  15437. WFIFOL(fd,4) = c;
  15438. WFIFOSET(fd,WFIFOW(fd,2));
  15439. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  15440. sd->menuskill_val = c;
  15441. } else {
  15442. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15443. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  15444. }
  15445. return 1;
  15446. }
  15447. /*===========================================
  15448. * Skill list for Four Elemental Analysis
  15449. * and Change Material skills.
  15450. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  15451. *------------------------------------------*/
  15452. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  15453. #if PACKETVER >= 20090922
  15454. int fd = sd->fd;
  15455. nullpo_ret(sd);
  15456. sd->menuskill_id = skill_id; // To prevent hacking.
  15457. sd->menuskill_val = skill_lv;
  15458. if( skill_id == GN_CHANGEMATERIAL )
  15459. skill_lv = 0; // Changematerial
  15460. WFIFOHEAD(fd, packet_len(0x7e3));
  15461. WFIFOW(fd,0) = 0x7e3;
  15462. WFIFOL(fd,2) = skill_lv;
  15463. WFIFOL(fd,4) = 0;
  15464. WFIFOSET(fd, packet_len(0x7e3));
  15465. #endif
  15466. return 1;
  15467. }
  15468. /*==========================================
  15469. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  15470. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  15471. * RFIFOL(fd,2) - type (currently not used)
  15472. *------------------------------------------*/
  15473. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  15474. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15475. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  15476. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  15477. return;
  15478. if( pc_istrading(sd) ) {
  15479. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  15480. clif_menuskill_clear(sd);
  15481. return;
  15482. }
  15483. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  15484. clif_menuskill_clear(sd);
  15485. }
  15486. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  15487. /// 08cf <id>.L <type>.W <num>.W
  15488. void clif_spiritcharm(struct map_session_data *sd) {
  15489. unsigned char buf[10];
  15490. nullpo_retv(sd);
  15491. WBUFW(buf,0) = 0x08cf;
  15492. WBUFL(buf,2) = sd->bl.id;
  15493. WBUFW(buf,6) = sd->spiritcharm_type;
  15494. WBUFW(buf,8) = sd->spiritcharm;
  15495. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  15496. }
  15497. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  15498. /// 0907 <index>.W
  15499. ///
  15500. /// R 0908 <index>.w <type>.b
  15501. /// type:
  15502. /// 0 = move item to personal tab
  15503. /// 1 = move item to normal tab
  15504. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  15505. #if PACKETVER >= 20111122
  15506. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15507. int index = RFIFOW(fd,info->pos[0]) - 2;
  15508. int type = RFIFOB(fd, info->pos[1]);
  15509. /* can't move while dead. */
  15510. if(pc_isdead(sd)) {
  15511. return;
  15512. }
  15513. if (index < 0 || index >= MAX_INVENTORY)
  15514. return;
  15515. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  15516. sd->inventory.u.items_inventory[index].favorite = 0;
  15517. else if( type == 0 )
  15518. sd->inventory.u.items_inventory[index].favorite = 1;
  15519. else
  15520. return;/* nothing to do. */
  15521. clif_favorite_item(sd, index);
  15522. #endif
  15523. }
  15524. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  15525. /// 0900 <index>.W <favorite>.B
  15526. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  15527. int fd = sd->fd;
  15528. WFIFOHEAD(fd,packet_len(0x908));
  15529. WFIFOW(fd,0) = 0x908;
  15530. WFIFOW(fd,2) = index+2;
  15531. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  15532. WFIFOSET(fd,packet_len(0x908));
  15533. }
  15534. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  15535. void clif_snap( struct block_list *bl, short x, short y ) {
  15536. unsigned char buf[10];
  15537. WBUFW(buf,0) = 0x8d2;
  15538. WBUFL(buf,2) = bl->id;
  15539. WBUFW(buf,6) = x;
  15540. WBUFW(buf,8) = y;
  15541. if( disguised(bl) )
  15542. {
  15543. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  15544. WBUFL(buf,2) = -bl->id;
  15545. clif_send(buf, packet_len(0x8d2), bl, SELF);
  15546. } else
  15547. clif_send(buf,packet_len(0x8d2),bl, AREA);
  15548. }
  15549. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  15550. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  15551. #if PACKETVER >= 20120404
  15552. WFIFOHEAD(fd,packet_len(0x977));
  15553. WFIFOW(fd,0) = 0x977;
  15554. WFIFOL(fd,2) = md->bl.id;
  15555. WFIFOL(fd,6) = md->status.hp;
  15556. WFIFOL(fd,10) = md->status.max_hp;
  15557. WFIFOSET(fd,packet_len(0x977));
  15558. #endif
  15559. }
  15560. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  15561. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  15562. return;
  15563. }
  15564. void clif_partytickack(struct map_session_data* sd, bool flag) {
  15565. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  15566. WFIFOW(sd->fd,0) = 0x2c9;
  15567. WFIFOB(sd->fd,2) = flag;
  15568. WFIFOSET(sd->fd, packet_len(0x2c9));
  15569. }
  15570. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  15571. /// 0979 <world name>.24B <char name>.24B
  15572. void clif_ackworldinfo(struct map_session_data* sd) {
  15573. int fd;
  15574. nullpo_retv(sd);
  15575. fd = sd->fd;
  15576. WFIFOHEAD(fd,packet_len(0x979));
  15577. WFIFOW(fd,0)=0x979;
  15578. //AID -> world name ?
  15579. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  15580. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  15581. WFIFOSET(fd,packet_len(0x979));
  15582. }
  15583. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  15584. /// 0978 <AID>.L
  15585. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  15586. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  15587. if(sd)
  15588. clif_ackworldinfo(sd);
  15589. }
  15590. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  15591. /// 0447
  15592. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd) {
  15593. //if(sd)
  15594. ;
  15595. }
  15596. /// req world info (CZ_CLIENT_VERSION)
  15597. /// 044A <version>.L
  15598. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  15599. //if(sd)
  15600. ;
  15601. }
  15602. /// Ranking list
  15603. /// ranking pointlist { <name>.24B <point>.L }*10
  15604. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  15605. struct fame_list* list;
  15606. int i, size = MAX_FAME_LIST;
  15607. switch(rankingtype) {
  15608. case RANK_BLACKSMITH: list = smith_fame_list; break;
  15609. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  15610. case RANK_TAEKWON: list = taekwon_fame_list; break;
  15611. // PK currently unsupported
  15612. case RANK_KILLER: list = NULL; size = 0; break;
  15613. default:
  15614. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  15615. return;
  15616. }
  15617. //Packet size limits this list to 10 elements. [Skotlex]
  15618. for (i = 0; i < min(10,size); i++) {
  15619. if (list[i].id > 0) {
  15620. const char* name;
  15621. if (strcmp(list[i].name, "-") == 0 &&
  15622. (name = map_charid2nick(list[i].id)) != NULL)
  15623. {
  15624. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  15625. } else {
  15626. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  15627. }
  15628. } else {
  15629. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  15630. }
  15631. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  15632. }
  15633. for(;i < 10; i++) { //In case the MAX is less than 10.
  15634. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  15635. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  15636. }
  15637. }
  15638. /// Request for the blacksmith ranklist.
  15639. /// /blacksmith command sends this packet to the server.
  15640. /// 0217 (CZ_BLACKSMITH_RANK)
  15641. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  15642. clif_ranklist(sd,RANK_BLACKSMITH);
  15643. }
  15644. /// Request for the alchemist ranklist.
  15645. /// /alchemist command sends this packet to the server.
  15646. /// 0218 (CZ_ALCHEMIST_RANK)
  15647. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  15648. clif_ranklist(sd,RANK_ALCHEMIST);
  15649. }
  15650. /// Request for the taekwon ranklist.
  15651. /// /taekwon command sends this packet to the server.
  15652. /// 0225 (CZ_TAEKWON_RANK)
  15653. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  15654. clif_ranklist(sd,RANK_TAEKWON);
  15655. }
  15656. /// Request for the killer ranklist.
  15657. /// /pk command sends this packet to the server.
  15658. /// 0237 (CZ_KILLER_RANK)
  15659. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  15660. clif_ranklist(sd,RANK_KILLER);
  15661. }
  15662. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  15663. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  15664. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  15665. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  15666. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  15667. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  15668. enum e_rank rank;
  15669. #if PACKETVER < 20130710
  15670. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  15671. short cmd;
  15672. switch( rankingType ){
  15673. case RANK_BLACKSMITH: cmd = 0x219; break;
  15674. case RANK_ALCHEMIST: cmd = 0x21a; break;
  15675. case RANK_TAEKWON: cmd = 0x226; break;
  15676. case RANK_KILLER: cmd = 0x238; break;
  15677. default:
  15678. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  15679. return;
  15680. }
  15681. // Can be safely casted here, since we validated it before
  15682. rank = (enum e_rank)rankingType;
  15683. WBUFW(buf,0) = cmd;
  15684. clif_sub_ranklist(buf,2,sd,rank);
  15685. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  15686. #else
  15687. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  15688. int mypoint = 0;
  15689. switch( rankingType ){
  15690. case RANK_BLACKSMITH:
  15691. case RANK_ALCHEMIST:
  15692. case RANK_TAEKWON:
  15693. case RANK_KILLER:
  15694. break;
  15695. default:
  15696. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  15697. return;
  15698. }
  15699. // Can be safely casted here, since we validated it before
  15700. rank = (enum e_rank)rankingType;
  15701. WBUFW(buf,0) = 0x97d;
  15702. WBUFW(buf,2) = rank;
  15703. clif_sub_ranklist(buf,4,sd,rank);
  15704. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  15705. case MAPID_BLACKSMITH:
  15706. case MAPID_ALCHEMIST:
  15707. case MAPID_TAEKWON:
  15708. mypoint = sd->status.fame;
  15709. }
  15710. WBUFL(buf,284) = mypoint; //mypoint
  15711. clif_send(buf, 288, &sd->bl, SELF);
  15712. #endif
  15713. }
  15714. /*
  15715. * 097c <type> (CZ_REQ_RANKING)
  15716. * type
  15717. * 0: /blacksmith
  15718. * 1: /alchemist
  15719. * 2: /taekwon
  15720. * 3: /pk
  15721. * */
  15722. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  15723. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15724. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  15725. clif_ranklist(sd,rankingtype);
  15726. }
  15727. /// Updates the fame rank points for the given ranking.
  15728. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  15729. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  15730. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  15731. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  15732. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  15733. int fd=sd->fd;
  15734. #if PACKETVER < 20130710
  15735. short cmd;
  15736. switch(rankingtype){
  15737. case RANK_BLACKSMITH: cmd = 0x21b; break;
  15738. case RANK_ALCHEMIST: cmd = 0x21c; break;
  15739. case RANK_TAEKWON: cmd = 0x224; break;
  15740. default:
  15741. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  15742. return;
  15743. }
  15744. WFIFOHEAD(fd,packet_len(cmd));
  15745. WFIFOW(fd,0) = cmd;
  15746. WFIFOL(fd,2) = point;
  15747. WFIFOL(fd,6) = sd->status.fame;
  15748. WFIFOSET(fd, packet_len(cmd));
  15749. #else
  15750. WFIFOHEAD(fd,packet_len(0x97e));
  15751. WFIFOW(fd,0) = 0x97e;
  15752. WFIFOW(fd,2) = rankingtype;
  15753. WFIFOL(fd,4) = point;
  15754. WFIFOL(fd,8) = sd->status.fame;
  15755. WFIFOSET(fd,packet_len(0x97e));
  15756. #endif
  15757. }
  15758. /**
  15759. * Transmit personal information to player. (rates)
  15760. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  15761. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  15762. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  15763. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  15764. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  15765. * FIXME!
  15766. * - Find/decide for details of EXP, Drop, and Death penalty rates
  15767. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  15768. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  15769. */
  15770. #ifdef VIP_ENABLE
  15771. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  15772. if (sd) {
  15773. struct s_packet_db* info;
  15774. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  15775. int cmd = 0, fd, i = 0;
  15776. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  15777. int details_bexp[PINFO_MAX];
  15778. int details_drop[PINFO_MAX];
  15779. int details_penalty[PINFO_MAX];
  15780. /**
  15781. * Set for EXP
  15782. */
  15783. //0:PCRoom
  15784. details_bexp[0] = map[sd->bl.m].adjust.bexp;
  15785. if (details_bexp[0] == 100 || !details_bexp[0])
  15786. details_bexp[0] = 0;
  15787. else {
  15788. if (details_bexp[0] < 100) {
  15789. details_bexp[0] = 100 - details_bexp[0];
  15790. details_bexp[0] = 0 - details_bexp[0];
  15791. }
  15792. else
  15793. details_bexp[0] = details_bexp[0] - 100;
  15794. }
  15795. //1:Premium
  15796. if (pc_isvip(sd)) {
  15797. details_bexp[1] = battle_config.vip_base_exp_increase;
  15798. if (details_bexp[1] < 0)
  15799. details_bexp[1] = 0 - details_bexp[1];
  15800. }
  15801. else
  15802. details_bexp[1] = 0;
  15803. //2:Server
  15804. details_bexp[2] = battle_config.base_exp_rate;
  15805. if (details_bexp[2] == 100)
  15806. details_bexp[2] = 0;
  15807. else {
  15808. if (details_bexp[2] < 100) {
  15809. details_bexp[2] = 100 - details_bexp[2];
  15810. details_bexp[2] = 0 - details_bexp[2];
  15811. }
  15812. else
  15813. details_bexp[2] = details_bexp[2] - 100;
  15814. }
  15815. //3:TPLUS
  15816. details_bexp[3] = 0;
  15817. /* End - EXP set*/
  15818. /**
  15819. * Set for Drop rate
  15820. */
  15821. //0:PCRoom
  15822. details_drop[0] = 0;
  15823. //1:Premium
  15824. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  15825. if (pc_isvip(sd)) {
  15826. if (details_drop[1] < 0)
  15827. details_drop[1] = 0 - details_drop[1];
  15828. }
  15829. else
  15830. details_drop[1] = 0;
  15831. //2:Server
  15832. details_drop[2] = battle_config.item_rate_common;
  15833. if (details_drop[2] == 100)
  15834. details_drop[2] = 0;
  15835. else {
  15836. if (details_drop[2] < 100) {
  15837. details_drop[2] = 100 - details_drop[2];
  15838. details_drop[2] = 0 - details_drop[2];
  15839. }
  15840. else
  15841. details_drop[2] = details_drop[2] - 100;
  15842. }
  15843. //3:TPLUS
  15844. details_drop[3] = 0;
  15845. /* End - Drop set*/
  15846. /**
  15847. * Set for Penalty rate
  15848. */
  15849. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  15850. //0:PCRoom
  15851. details_penalty[0] = 0;
  15852. //1:Premium
  15853. if (pc_isvip(sd)) {
  15854. details_penalty[1] = battle_config.vip_exp_penalty_base;
  15855. if (details_penalty[1] == 100)
  15856. details_penalty[1] = 0;
  15857. else {
  15858. if (details_penalty[1] < 100) {
  15859. details_penalty[1] = 100 - details_penalty[1];
  15860. details_penalty[1] = 0 - details_penalty[1];
  15861. }
  15862. else
  15863. details_penalty[1] = details_penalty[1] - 100;
  15864. }
  15865. }
  15866. else
  15867. details_penalty[1] = 0;
  15868. //2:Server
  15869. details_penalty[2] = battle_config.death_penalty_base;
  15870. if (details_penalty[2] == 100)
  15871. details_penalty[2] = 0;
  15872. else {
  15873. if (details_penalty[2] < 100) {
  15874. details_penalty[2] = 100 - details_penalty[2];
  15875. details_penalty[2] = 0 - details_penalty[2];
  15876. }
  15877. else
  15878. details_penalty[2] = details_penalty[2] - 100;
  15879. }
  15880. //3:TPLUS
  15881. details_penalty[3] = 0;
  15882. /* End - Penalty set*/
  15883. cmd = packet_db_ack[cmdtype];
  15884. info = &packet_db[cmd];
  15885. len = info->len; //this is the base len without details
  15886. if(!len) return; //version as packet disable
  15887. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  15888. szdetails = 7;
  15889. factor = 1;
  15890. }
  15891. else if (cmd == 0x097b) {
  15892. tot_baseexp *= factor;
  15893. tot_drop *= factor;
  15894. tot_penalty *= factor;
  15895. }
  15896. fd = sd->fd;
  15897. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  15898. WFIFOW(fd,0) = cmd;
  15899. for (i = 0; i < maxinfotype; i++) {
  15900. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  15901. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  15902. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  15903. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  15904. tot_baseexp += details_bexp[i]*factor;
  15905. tot_drop += details_penalty[i]*factor;
  15906. tot_penalty += details_drop[i]*factor;
  15907. len += szdetails;
  15908. }
  15909. WFIFOW(fd,info->pos[0]) = len; //packetlen
  15910. if (cmd == 0x08cb) { //0x08cb version
  15911. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  15912. WFIFOW(fd,info->pos[2]) = tot_drop;
  15913. WFIFOW(fd,info->pos[3]) = tot_penalty;
  15914. }
  15915. else { //2013-08-07aRagexe uses 0x097b
  15916. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  15917. WFIFOL(fd,info->pos[2]) = tot_drop;
  15918. WFIFOL(fd,info->pos[3]) = tot_penalty;
  15919. }
  15920. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  15921. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  15922. WFIFOSET(fd,len);
  15923. }
  15924. }
  15925. #endif
  15926. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  15927. char cmd[30];
  15928. int t_aid = RFIFOL(fd,2);
  15929. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  15930. is_atcommand(fd, sd, cmd, 1);
  15931. }
  15932. /**
  15933. * Marks Crimson Marker target on mini-map to the caster
  15934. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  15935. * @param fd
  15936. * @param bl Crimson Marker target
  15937. **/
  15938. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  15939. struct s_packet_db* info;
  15940. int cmd = 0;
  15941. int16 len;
  15942. unsigned char buf[11];
  15943. nullpo_retv(sd);
  15944. cmd = packet_db_ack[ZC_C_MARKERINFO];
  15945. if (!cmd)
  15946. cmd = 0x09C1; //default
  15947. info = &packet_db[cmd];
  15948. if (!(len = info->len))
  15949. return;
  15950. WBUFW(buf, 0) = cmd;
  15951. WBUFL(buf, info->pos[0]) = bl->id;
  15952. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  15953. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  15954. clif_send(buf, len, &sd->bl, SELF);
  15955. }
  15956. /**
  15957. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  15958. **/
  15959. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  15960. struct s_packet_db *info = NULL;
  15961. int cmd = 0;
  15962. nullpo_retv(sd);
  15963. cmd = packet_db_ack[ZC_NOTIFY_BIND_ON_EQUIP];
  15964. info = &packet_db[cmd];
  15965. if (!cmd || !info->len)
  15966. return;
  15967. WFIFOHEAD(sd->fd, info->len);
  15968. WFIFOW(sd->fd, 0) = cmd;
  15969. WFIFOW(sd->fd, info->pos[0]) = n+2;
  15970. WFIFOSET(sd->fd, info->len);
  15971. }
  15972. /**
  15973. * [Ind/Hercules]
  15974. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  15975. **/
  15976. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  15977. char buf[256];
  15978. size_t len;
  15979. nullpo_retv(bl);
  15980. if(!message)
  15981. return;
  15982. len = strlen(message)+1;
  15983. if( len > sizeof(buf)-8 ) {
  15984. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%d).\n", message, len);
  15985. len = sizeof(buf)-8;
  15986. }
  15987. WBUFW(buf,0) = 0x8b3;
  15988. WBUFW(buf,2) = (uint16)(len+8);
  15989. WBUFL(buf,4) = bl->id;
  15990. safestrncpy(WBUFCP(buf,8), message, len);
  15991. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  15992. }
  15993. /**
  15994. * [Ind/Hercules]
  15995. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  15996. **/
  15997. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  15998. unsigned char buf[10];
  15999. nullpo_retv(sd);
  16000. WBUFW(buf,0) = 0x7fc;
  16001. WBUFL(buf,2) = prev_leader_aid;
  16002. WBUFL(buf,6) = new_leader_aid;
  16003. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16004. }
  16005. /**
  16006. * Sends a clan message to a player
  16007. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16008. **/
  16009. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16010. #if PACKETVER >= 20131223
  16011. struct map_session_data *sd;
  16012. uint8 buf[256];
  16013. if( len == 0 ){
  16014. return;
  16015. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16016. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%d, clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16017. len = sizeof(buf)-5-NAME_LENGTH;
  16018. }
  16019. WBUFW(buf, 0) = 0x98e;
  16020. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16021. // 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
  16022. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16023. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16024. if((sd = clan_getavailablesd(clan)) != NULL)
  16025. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16026. #endif
  16027. }
  16028. /**
  16029. * Parses a clan message from a player.
  16030. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16031. **/
  16032. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  16033. #if PACKETVER >= 20131223
  16034. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16035. // validate packet and retrieve name and message
  16036. if( !clif_process_message(sd, false, name, message, output ) )
  16037. return;
  16038. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16039. #endif
  16040. }
  16041. /**
  16042. * Sends the basic clan informations to the client.
  16043. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16044. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16045. **/
  16046. void clif_clan_basicinfo( struct map_session_data *sd ){
  16047. #if PACKETVER >= 20131223
  16048. int fd, offset, length, i, flag;
  16049. struct clan* clan;
  16050. char mapname[MAP_NAME_LENGTH_EXT];
  16051. nullpo_retv( sd );
  16052. nullpo_retv( clan = sd->clan );
  16053. // Check if the player has a valid session and is not autotrading
  16054. if( !clif_session_isValid( sd ) ){
  16055. return;
  16056. }
  16057. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16058. fd = sd->fd;
  16059. WFIFOHEAD(fd,length);
  16060. memset( WFIFOP(fd, 0), 0, length );
  16061. WFIFOW( fd, 0 ) = 0x98a;
  16062. WFIFOL( fd, 4 ) = clan->id;
  16063. offset = 8;
  16064. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16065. offset += NAME_LENGTH;
  16066. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16067. offset += NAME_LENGTH;
  16068. mapindex_getmapname_ext( clan->map, mapname );
  16069. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16070. offset += MAP_NAME_LENGTH_EXT;
  16071. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16072. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16073. for( flag = 0; flag < 2; flag++ ){
  16074. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16075. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16076. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16077. offset += NAME_LENGTH;
  16078. }
  16079. }
  16080. }
  16081. WFIFOW( fd, 2 ) = offset;
  16082. WFIFOSET(fd,offset);
  16083. #endif
  16084. }
  16085. /**
  16086. * Updates the online and maximum player count of a clan.
  16087. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16088. **/
  16089. void clif_clan_onlinecount( struct clan* clan ){
  16090. #if PACKETVER >= 20131223
  16091. uint8 buf[6];
  16092. struct map_session_data *sd;
  16093. WBUFW(buf,0) = 0x988;
  16094. WBUFW(buf,2) = clan->connect_member;
  16095. WBUFW(buf,4) = clan->max_member;
  16096. if((sd = clan_getavailablesd(clan)) != NULL)
  16097. clif_send(buf, 6, &sd->bl, CLAN);
  16098. #endif
  16099. }
  16100. /**
  16101. * Notifies the client that the player has left his clan.
  16102. * 0989 (ZC_ACK_CLAN_LEAVE)
  16103. **/
  16104. void clif_clan_leave( struct map_session_data* sd ){
  16105. #if PACKETVER >= 20131223
  16106. int fd;
  16107. nullpo_retv( sd );
  16108. if( !clif_session_isValid( sd ) ){
  16109. return;
  16110. }
  16111. fd = sd->fd;
  16112. WFIFOHEAD(fd,2);
  16113. WFIFOW(fd,0) = 0x989;
  16114. WFIFOSET(fd,2);
  16115. #endif
  16116. }
  16117. /**
  16118. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16119. * 0A2F <result>.B <title_id>.L
  16120. */
  16121. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  16122. {
  16123. #if PACKETVER >= 20150513
  16124. int fd;
  16125. nullpo_retv(sd);
  16126. if (!clif_session_isValid(sd))
  16127. return;
  16128. fd = sd->fd;
  16129. WFIFOHEAD(fd, packet_len(0xa2f));
  16130. WFIFOW(fd, 0) = 0xa2f;
  16131. WFIFOB(fd, 2) = result;
  16132. WFIFOL(fd, 3) = title_id;
  16133. WFIFOSET(fd, packet_len(0xa2f));
  16134. #endif
  16135. }
  16136. /**
  16137. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16138. * 0A2E <title_id>.L
  16139. */
  16140. void clif_parse_change_title(int fd, struct map_session_data *sd)
  16141. {
  16142. int title_id, i;
  16143. nullpo_retv(sd);
  16144. title_id = RFIFOL(fd, 2);
  16145. if( title_id == sd->status.title_id ){
  16146. // It is exactly the same as the old one
  16147. return;
  16148. }else if( title_id <= 0 ){
  16149. sd->status.title_id = 0;
  16150. }else{
  16151. ARR_FIND(0, sd->titleCount, i, sd->titles[i] == title_id);
  16152. if( i == sd->titleCount ){
  16153. clif_change_title_ack(sd, 1, title_id);
  16154. return;
  16155. }
  16156. sd->status.title_id = title_id;
  16157. }
  16158. clif_name_area(&sd->bl);
  16159. clif_change_title_ack(sd, 0, title_id);
  16160. }
  16161. #ifdef DUMP_UNKNOWN_PACKET
  16162. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  16163. {
  16164. const char* packet_txt = "save/packet.txt";
  16165. FILE* fp;
  16166. time_t time_server;
  16167. struct tm *datetime;
  16168. char datestr[512];
  16169. time(&time_server); // get time in seconds since 1/1/1970
  16170. datetime = localtime(&time_server); // convert seconds in structure
  16171. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  16172. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  16173. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  16174. if( sd ) {
  16175. 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);
  16176. } else {
  16177. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16178. }
  16179. WriteDump(fp, RFIFOP(fd,0), packet_len);
  16180. fprintf(fp, "\n");
  16181. fclose(fp);
  16182. } else {
  16183. ShowError("Failed to write '%s'.\n", packet_txt);
  16184. // Dump on console instead
  16185. if( sd ) {
  16186. 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);
  16187. } else {
  16188. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16189. }
  16190. ShowDump(RFIFOP(fd,0), packet_len);
  16191. }
  16192. }
  16193. #endif
  16194. /// Roulette System
  16195. /// Author: Yommy
  16196. /**
  16197. * Opens Roulette window
  16198. * @param fd
  16199. * @param sd
  16200. */
  16201. void clif_parse_RouletteOpen(int fd, struct map_session_data* sd)
  16202. {
  16203. nullpo_retv(sd);
  16204. if (!battle_config.feature_roulette) {
  16205. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16206. return;
  16207. }
  16208. WFIFOHEAD(fd,packet_len(0xa1a));
  16209. WFIFOW(fd,0) = 0xa1a;
  16210. WFIFOB(fd,2) = 0; // result
  16211. WFIFOL(fd,3) = 0; // serial
  16212. WFIFOB(fd,7) = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  16213. WFIFOB(fd,8) = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  16214. WFIFOW(fd,9) = -1; //! TODO: Display bonus item
  16215. WFIFOL(fd,11) = sd->roulette_point.gold;
  16216. WFIFOL(fd,15) = sd->roulette_point.silver;
  16217. WFIFOL(fd,19) = sd->roulette_point.bronze;
  16218. WFIFOSET(fd,packet_len(0xa1a));
  16219. }
  16220. /**
  16221. * Generates information to be displayed
  16222. * @param fd
  16223. * @param sd
  16224. */
  16225. void clif_parse_RouletteInfo(int fd, struct map_session_data* sd)
  16226. {
  16227. unsigned short i, j, count = 0;
  16228. int len = 8 + (42 * 8);
  16229. nullpo_retv(sd);
  16230. if (!battle_config.feature_roulette) {
  16231. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16232. return;
  16233. }
  16234. WFIFOHEAD(fd,len);
  16235. WFIFOW(fd,0) = 0xa1c;
  16236. WFIFOW(fd,2) = len;
  16237. WFIFOL(fd,4) = 1; // serial
  16238. for(i = 0; i < MAX_ROULETTE_LEVEL; i++) {
  16239. for(j = 0; j < MAX_ROULETTE_COLUMNS - i; j++) {
  16240. WFIFOW(fd,8 * count + 8) = i;
  16241. WFIFOW(fd,8 * count + 10) = j;
  16242. WFIFOW(fd,8 * count + 12) = rd.nameid[i][j];
  16243. WFIFOW(fd,8 * count + 14) = rd.qty[i][j];
  16244. count++;
  16245. }
  16246. }
  16247. WFIFOSET(fd,len);
  16248. return;
  16249. }
  16250. /**
  16251. * Closes Roulette window
  16252. * @param fd
  16253. * @param sd
  16254. */
  16255. void clif_parse_RouletteClose(int fd, struct map_session_data* sd)
  16256. {
  16257. nullpo_retv(sd);
  16258. if (!battle_config.feature_roulette) {
  16259. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16260. return;
  16261. }
  16262. /** What do we need this for? (other than state tracking), game client closes the window without our response. **/
  16263. return;
  16264. }
  16265. /**
  16266. *
  16267. **/
  16268. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  16269. #if PACKETVER >= 20141016
  16270. uint16 cmd = 0xa22;
  16271. unsigned char buf[5];
  16272. nullpo_retv(sd);
  16273. if (packet_db[cmd].len == 0)
  16274. return;
  16275. WBUFW(buf,0) = cmd;
  16276. WBUFB(buf,2) = type;
  16277. WBUFW(buf,3) = 0; //! TODO: Additional item
  16278. clif_send(buf, sizeof(buf), &sd->bl, SELF);
  16279. #endif
  16280. }
  16281. /**
  16282. * Claim roulette reward
  16283. * @param sd Player
  16284. * @return 0:Success
  16285. **/
  16286. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  16287. struct item it;
  16288. uint8 res = 1;
  16289. nullpo_retr(1, sd);
  16290. if (sd->roulette.prizeIdx < 0)
  16291. return RECV_ITEM_FAILED;
  16292. memset(&it, 0, sizeof(it));
  16293. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  16294. it.identify = 1;
  16295. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  16296. ; // onSuccess
  16297. }
  16298. sd->roulette.claimPrize = false;
  16299. sd->roulette.prizeStage = 0;
  16300. sd->roulette.prizeIdx = -1;
  16301. sd->roulette.stage = 0;
  16302. return res;
  16303. }
  16304. /**
  16305. * Process the stage and attempt to give a prize
  16306. * @param fd
  16307. * @param sd
  16308. */
  16309. void clif_parse_RouletteGenerate(int fd, struct map_session_data* sd)
  16310. {
  16311. enum GENERATE_ROULETTE_ACK result = GENERATE_ROULETTE_SUCCESS;
  16312. short stage = sd->roulette.stage;
  16313. nullpo_retv(sd);
  16314. if (!battle_config.feature_roulette) {
  16315. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16316. return;
  16317. }
  16318. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL)
  16319. stage = sd->roulette.stage = 0;
  16320. if (!stage) {
  16321. if (sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10)
  16322. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  16323. }
  16324. if (result == GENERATE_ROULETTE_SUCCESS) {
  16325. if (!stage) {
  16326. if (sd->roulette_point.bronze > 0) {
  16327. sd->roulette_point.bronze -= 1;
  16328. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  16329. } else if (sd->roulette_point.silver > 9) {
  16330. sd->roulette_point.silver -= 10;
  16331. stage = sd->roulette.stage = 2;
  16332. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  16333. } else if (sd->roulette_point.gold > 9) {
  16334. sd->roulette_point.gold -= 10;
  16335. stage = sd->roulette.stage = 4;
  16336. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  16337. }
  16338. }
  16339. sd->roulette.prizeStage = stage;
  16340. sd->roulette.prizeIdx = rnd()%rd.items[stage];
  16341. if (rd.flag[stage][sd->roulette.prizeIdx]&1) {
  16342. clif_roulette_generate_ack(sd,GENERATE_ROULETTE_LOSING,stage,sd->roulette.prizeIdx,0);
  16343. clif_roulette_getitem(sd);
  16344. clif_roulette_recvitem_ack(sd, RECV_ITEM_SUCCESS);
  16345. return;
  16346. }
  16347. else {
  16348. sd->roulette.claimPrize = true;
  16349. sd->roulette.stage++;
  16350. }
  16351. }
  16352. clif_roulette_generate_ack(sd,result,stage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  16353. }
  16354. /**
  16355. * Request to cash in prize
  16356. * @param fd
  16357. * @param sd
  16358. */
  16359. void clif_parse_RouletteRecvItem(int fd, struct map_session_data* sd)
  16360. {
  16361. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  16362. nullpo_retv(sd);
  16363. if (!battle_config.feature_roulette) {
  16364. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16365. return;
  16366. }
  16367. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  16368. switch (clif_roulette_getitem(sd)) {
  16369. case 0:
  16370. type = RECV_ITEM_SUCCESS;
  16371. break;
  16372. case 1:
  16373. case 4:
  16374. case 5:
  16375. type = RECV_ITEM_OVERCOUNT;
  16376. break;
  16377. case 2:
  16378. type = RECV_ITEM_OVERWEIGHT;
  16379. break;
  16380. case 7:
  16381. default:
  16382. type = RECV_ITEM_FAILED;
  16383. break;
  16384. }
  16385. }
  16386. clif_roulette_recvitem_ack(sd,type);
  16387. return;
  16388. }
  16389. /**
  16390. * Update Roulette window with current stats
  16391. * @param sd
  16392. * @param result
  16393. * @param stage
  16394. * @param prizeIdx
  16395. * @param bonusItemID
  16396. */
  16397. void clif_roulette_generate_ack(struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, short bonusItemID)
  16398. {
  16399. int fd = sd->fd;
  16400. nullpo_retv(sd);
  16401. WFIFOHEAD(fd,packet_len(0xa20));
  16402. WFIFOW(fd,0) = 0xa20;
  16403. WFIFOB(fd,2) = result;
  16404. WFIFOW(fd,3) = stage;
  16405. WFIFOW(fd,5) = prizeIdx;
  16406. WFIFOW(fd,7) = bonusItemID;
  16407. WFIFOL(fd,9) = sd->roulette_point.gold;
  16408. WFIFOL(fd,13) = sd->roulette_point.silver;
  16409. WFIFOL(fd,17) = sd->roulette_point.bronze;
  16410. WFIFOSET(fd,packet_len(0xa20));
  16411. }
  16412. /// MERGE ITEM
  16413. /**
  16414. * Acknowledge the client about item merger result
  16415. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  16416. * @param fd
  16417. * @param sd
  16418. **/
  16419. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  16420. unsigned char buf[9];
  16421. struct s_packet_db *info = NULL;
  16422. short cmd = 0;
  16423. nullpo_retv(sd);
  16424. if (!clif_session_isValid(sd))
  16425. return;
  16426. if (!(cmd = packet_db_ack[ZC_ACK_MERGE_ITEM]))
  16427. return;
  16428. if (!(info = &packet_db[cmd]) || info->len == 0)
  16429. return;
  16430. WBUFW(buf, 0) = cmd;
  16431. WBUFW(buf, info->pos[0]) = index;
  16432. WBUFW(buf, info->pos[1]) = count;
  16433. WBUFB(buf, info->pos[2]) = type;
  16434. clif_send(buf, info->len, &sd->bl, SELF);
  16435. }
  16436. /**
  16437. * Check if item has the pair to be merged
  16438. * @param sd
  16439. * @param it Item
  16440. * @return True if has pair, False if not
  16441. **/
  16442. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  16443. struct item *it_;
  16444. unsigned short i;
  16445. nullpo_retr(false, sd);
  16446. 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);
  16447. if (i < MAX_INVENTORY)
  16448. return true;
  16449. return false;
  16450. }
  16451. /**
  16452. * Check if item can be merged
  16453. * @param id Item Data
  16454. * @param it Item
  16455. * @return True if can be merged, False if not
  16456. **/
  16457. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  16458. if (!id || !it)
  16459. return false;
  16460. if (id->type == IT_CASH)
  16461. return false;
  16462. if (!itemdb_isstackable2(id))
  16463. return false;
  16464. if (itemdb_isspecial(it->card[0]))
  16465. return false;
  16466. if (!it->unique_id)
  16467. return false;
  16468. return true;
  16469. }
  16470. /**
  16471. * Open available item to be merged.
  16472. * Only show 1 item in 1 process.
  16473. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  16474. * @param sd
  16475. **/
  16476. void clif_merge_item_open(struct map_session_data *sd) {
  16477. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  16478. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  16479. int len = 0;
  16480. struct s_packet_db *info = NULL;
  16481. struct item *it;
  16482. nullpo_retv(sd);
  16483. if (!clif_session_isValid(sd))
  16484. return;
  16485. if (!(cmd = packet_db_ack[ZC_MERGE_ITEM_OPEN]))
  16486. return;
  16487. if (!(info = &packet_db[cmd]) || info->len == 0)
  16488. return;
  16489. // Get entries
  16490. for (i = 0; i < MAX_INVENTORY; i++) {
  16491. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->inventory.u.items_inventory[i])))
  16492. continue;
  16493. if (clif_merge_item_has_pair(sd, it))
  16494. indexes[n++] = i;
  16495. }
  16496. if (n < 2) { // No item need to be merged
  16497. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16498. return;
  16499. }
  16500. WBUFW(buf, 0) = cmd;
  16501. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  16502. for (i = 0; i < n; i++) {
  16503. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  16504. }
  16505. clif_send(buf, len, &sd->bl, SELF);
  16506. }
  16507. /**
  16508. * Process item merger
  16509. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  16510. * @param fd
  16511. * @param sd
  16512. **/
  16513. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  16514. struct s_packet_db *info = NULL;
  16515. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  16516. unsigned int count = 0;
  16517. struct item_data *id = NULL;
  16518. nullpo_retv(sd);
  16519. if (!clif_session_isValid(sd))
  16520. return;
  16521. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  16522. return;
  16523. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  16524. if (n < 2) { // No item need to be merged
  16525. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16526. return;
  16527. }
  16528. for (i = 0, j = 0; i < n; i++) {
  16529. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  16530. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  16531. continue;
  16532. indexes[j] = idx;
  16533. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  16534. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  16535. return;
  16536. }
  16537. count += sd->inventory.u.items_inventory[idx].amount;
  16538. j++;
  16539. }
  16540. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  16541. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16542. return;
  16543. }
  16544. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  16545. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  16546. return;
  16547. }
  16548. // Merrrrge!!!!
  16549. for (i = 1; i < n; i++) {
  16550. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  16551. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  16552. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  16553. sd->inventory_data[idx] = NULL;
  16554. clif_delitem(sd, idx, amt, 0);
  16555. }
  16556. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  16557. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  16558. }
  16559. /**
  16560. * Cancel item merge
  16561. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  16562. * @param fd
  16563. * @param sd
  16564. **/
  16565. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  16566. return; // Nothing todo yet
  16567. }
  16568. /**
  16569. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16570. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16571. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [surcename] ... [itemname]" -> MsgStringTable[1629]
  16572. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  16573. **/
  16574. 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) {
  16575. unsigned char buf[9 + NAME_LENGTH * 2];
  16576. unsigned short cmd = 0;
  16577. struct s_packet_db *info = NULL;
  16578. if (!(cmd = packet_db_ack[ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN]))
  16579. return;
  16580. if (!(info = &packet_db[cmd]) || info->len == 0)
  16581. return;
  16582. WBUFW(buf, 0) = 0x7fd;
  16583. WBUFB(buf, 4) = type;
  16584. WBUFW(buf, 5) = nameid;
  16585. WBUFB(buf, 7) = NAME_LENGTH;
  16586. safestrncpy(WBUFCP(buf, 8), char_name, NAME_LENGTH);
  16587. switch (type) {
  16588. case ITEMOBTAIN_TYPE_BOXITEM:
  16589. WBUFW(buf, 2) = 11 + NAME_LENGTH;
  16590. WBUFB(buf, 8 + NAME_LENGTH) = 0;
  16591. WBUFW(buf, 9 + NAME_LENGTH) = container;
  16592. break;
  16593. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  16594. {
  16595. struct mob_db *db = mob_db(container);
  16596. WBUFW(buf, 2) = 9 + NAME_LENGTH * 2;
  16597. WBUFB(buf, 8 + NAME_LENGTH) = NAME_LENGTH;
  16598. safestrncpy(WBUFCP(buf, 9 + NAME_LENGTH), db->name, NAME_LENGTH);
  16599. }
  16600. break;
  16601. case ITEMOBTAIN_TYPE_NPC:
  16602. default:
  16603. WBUFW(buf, 2) = 8 + NAME_LENGTH;
  16604. break;
  16605. }
  16606. clif_send(buf, WBUFW(buf, 2), NULL, ALL_CLIENT);
  16607. }
  16608. /// Show body view windows (ZC_DRESSROOM_OPEN).
  16609. /// 0A02 <view>.W
  16610. /// Value <flag> has the following effects:
  16611. /// 1: Open a Dress Room window.
  16612. void clif_dressing_room(struct map_session_data *sd, int flag) {
  16613. #if PACKETVER >= 20150513
  16614. int fd = sd->fd;
  16615. nullpo_retv(sd);
  16616. WFIFOHEAD(fd, packet_len(0xa02));
  16617. WFIFOW(fd,0) = 0xa02;
  16618. WFIFOW(fd,2) = flag;
  16619. WFIFOSET(fd, packet_len(0xa02));
  16620. #endif
  16621. }
  16622. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  16623. /// 0A35 <result>.W
  16624. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  16625. #if PACKETVER >= 20150513
  16626. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  16627. // Ignore the request
  16628. // - Invalid item index
  16629. // - Invalid item ID or item doesn't exist
  16630. // - Item is already identified
  16631. if (idx < 0 || idx >= MAX_INVENTORY ||
  16632. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  16633. sd->inventory.u.items_inventory[idx].identify)
  16634. return;
  16635. // Ignore the request - No magnifiers in inventory
  16636. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  16637. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  16638. return;
  16639. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  16640. return;
  16641. skill_identify(sd, idx);
  16642. #endif
  16643. }
  16644. /// Starts navigation to the given target on client side
  16645. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  16646. #if PACKETVER >= 20111010
  16647. int fd = sd->fd;
  16648. WFIFOHEAD(fd,27);
  16649. WFIFOW(fd,0) = 0x08e2;
  16650. // How detailed will our navigation be?
  16651. if( mob_id > 0 ){
  16652. x = 0;
  16653. y = 0;
  16654. WFIFOB(fd,2) = 3; // monster with destination field
  16655. }else if( x > 0 && y > 0 ){
  16656. WFIFOB(fd,2) = 0; // with coordinates
  16657. }else{
  16658. x = 0;
  16659. y = 0;
  16660. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  16661. }
  16662. // Which services can be used for transportation?
  16663. WFIFOB(fd,3) = flag;
  16664. // If this flag is set, the navigation window will not be opened up
  16665. WFIFOB(fd,4) = hideWindow;
  16666. // Target map
  16667. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  16668. // Target x
  16669. WFIFOW(fd,21) = x;
  16670. // Target y
  16671. WFIFOW(fd,23) = y;
  16672. // Target monster ID
  16673. WFIFOW(fd,25) = mob_id;
  16674. WFIFOSET(fd,27);
  16675. #endif
  16676. }
  16677. /// Send hat effects to the client (ZC_HAT_EFFECT).
  16678. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  16679. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  16680. #if PACKETVER >= 20150513
  16681. unsigned char* buf;
  16682. int len,i;
  16683. struct map_session_data *tsd;
  16684. struct block_list* tbl;
  16685. if( target == SELF ){
  16686. tsd = BL_CAST(BL_PC,bl);
  16687. tbl = &sd->bl;
  16688. }else{
  16689. tsd = sd;
  16690. tbl = bl;
  16691. }
  16692. if( !tsd->hatEffectCount )
  16693. return;
  16694. len = 9 + tsd->hatEffectCount * 2;
  16695. buf = (unsigned char*)aMalloc( len );
  16696. WBUFW(buf,0) = 0xa3b;
  16697. WBUFW(buf,2) = len;
  16698. WBUFL(buf,4) = tsd->bl.id;
  16699. WBUFB(buf,8) = 1;
  16700. for( i = 0; i < tsd->hatEffectCount; i++ ){
  16701. WBUFW(buf,9+i*2) = tsd->hatEffectIDs[i];
  16702. }
  16703. clif_send(buf, len,tbl,target);
  16704. aFree(buf);
  16705. #endif
  16706. }
  16707. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  16708. #if PACKETVER >= 20150513
  16709. unsigned char buf[13];
  16710. WBUFW(buf,0) = 0xa3b;
  16711. WBUFW(buf,2) = 13;
  16712. WBUFL(buf,4) = sd->bl.id;
  16713. WBUFB(buf,8) = enable;
  16714. WBUFL(buf,9) = effectId;
  16715. clif_send(buf,13,&sd->bl,AREA);
  16716. #endif
  16717. }
  16718. /// Notify the client that a sale has started
  16719. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  16720. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  16721. #if PACKETVER_SUPPORTS_SALES
  16722. unsigned char buf[8];
  16723. WBUFW(buf, 0) = 0x9b2;
  16724. WBUFW(buf, 2) = sale_item->nameid;
  16725. WBUFL(buf, 4) = (uint32)(sale_item->end - time(NULL)); // time in S
  16726. clif_send(buf, 8, bl, target);
  16727. #endif
  16728. }
  16729. /// Notify the clien that a sale has ended
  16730. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  16731. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  16732. #if PACKETVER_SUPPORTS_SALES
  16733. unsigned char buf[4];
  16734. WBUFW(buf, 0) = 0x9b3;
  16735. WBUFW(buf, 2) = sale_item->nameid;
  16736. clif_send(buf, 4, bl, target);
  16737. #endif
  16738. }
  16739. /// Update the remaining amount of a sale item.
  16740. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  16741. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  16742. #if PACKETVER_SUPPORTS_SALES
  16743. unsigned char buf[8];
  16744. WBUFW(buf, 0) = 0x9c4;
  16745. WBUFW(buf, 2) = sale_item->nameid;
  16746. WBUFL(buf, 4) = sale_item->amount;
  16747. clif_send(buf, 8, bl, target);
  16748. #endif
  16749. }
  16750. /// The client requested a refresh of the current remaining count of a sale item
  16751. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  16752. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  16753. #if PACKETVER_SUPPORTS_SALES
  16754. struct sale_item_data* sale;
  16755. if( RFIFOL(fd, 2) != sd->status.account_id ){
  16756. return;
  16757. }
  16758. sale = sale_find_item( RFIFOW(fd, 6), true );
  16759. if( sale == NULL ){
  16760. return;
  16761. }
  16762. clif_sale_amount(sale, &sd->bl, SELF);
  16763. #endif
  16764. }
  16765. /// Opens the sale administration window on the client
  16766. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  16767. void clif_sale_open( struct map_session_data* sd ){
  16768. #if PACKETVER_SUPPORTS_SALES
  16769. int fd = sd->fd;
  16770. // TODO: do we want state tracking?
  16771. WFIFOHEAD(fd, 2);
  16772. WFIFOW(fd, 0) = 0x9b5;
  16773. WFIFOSET(fd, 2);
  16774. #endif
  16775. }
  16776. /// Client request to open the sale administration window.
  16777. /// This is sent by /limitedsale
  16778. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  16779. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  16780. #if PACKETVER_SUPPORTS_SALES
  16781. nullpo_retv(sd);
  16782. if( RFIFOL(fd, 2) != sd->status.account_id ){
  16783. return;
  16784. }
  16785. if( !pc_has_permission( sd, PC_PERM_CASHSHOP_SALE ) ){
  16786. return;
  16787. }
  16788. clif_sale_open(sd);
  16789. #endif
  16790. }
  16791. /// Closes the sale administration window on the client.
  16792. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  16793. void clif_sale_close(struct map_session_data* sd) {
  16794. #if PACKETVER_SUPPORTS_SALES
  16795. int fd = sd->fd;
  16796. WFIFOHEAD(fd, 2);
  16797. WFIFOW(fd, 0) = 0x9bd;
  16798. WFIFOSET(fd, 2);
  16799. #endif
  16800. }
  16801. /// Client request to close the sale administration window.
  16802. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  16803. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  16804. #if PACKETVER_SUPPORTS_SALES
  16805. nullpo_retv(sd);
  16806. if( RFIFOL(fd, 2) != sd->status.account_id ){
  16807. return;
  16808. }
  16809. // TODO: do we want state tracking?
  16810. clif_sale_close(sd);
  16811. #endif
  16812. }
  16813. /// Reply to a item search request for item sale administration.
  16814. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  16815. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  16816. #if PACKETVER_SUPPORTS_SALES
  16817. int fd = sd->fd;
  16818. WFIFOHEAD(fd, 10);
  16819. WFIFOW(fd, 0) = 0x9ad;
  16820. if( item != NULL ){
  16821. WFIFOW(fd, 2) = 0;
  16822. WFIFOW(fd, 4) = item->nameid;
  16823. WFIFOL(fd, 6) = item->price;
  16824. }else{
  16825. WFIFOW(fd, 2) = 1;
  16826. WFIFOW(fd, 4) = 0;
  16827. WFIFOL(fd, 6) = 0;
  16828. }
  16829. WFIFOSET(fd, 10);
  16830. #endif
  16831. }
  16832. /// Search request for an item sale administration.
  16833. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  16834. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  16835. #if PACKETVER_SUPPORTS_SALES
  16836. char item_name[ITEM_NAME_LENGTH];
  16837. struct item_data *id = NULL;
  16838. nullpo_retv(sd);
  16839. if( RFIFOL(fd, 4) != sd->status.account_id ){
  16840. return;
  16841. }
  16842. if( !pc_has_permission( sd, PC_PERM_CASHSHOP_SALE ) ){
  16843. return;
  16844. }
  16845. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  16846. id = itemdb_searchname(item_name);
  16847. if( id ){
  16848. int i;
  16849. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  16850. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  16851. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  16852. return;
  16853. }
  16854. }
  16855. }
  16856. // not found
  16857. clif_sale_search_reply( sd, NULL );
  16858. #endif
  16859. }
  16860. /// Reply if an item was successfully put on sale or not.
  16861. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  16862. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  16863. #if PACKETVER_SUPPORTS_SALES
  16864. int fd = sd->fd;
  16865. WFIFOHEAD(fd, 4);
  16866. WFIFOW(fd, 0) = 0x9af;
  16867. WFIFOW(fd, 2) = (uint16)result;
  16868. WFIFOSET(fd, 4);
  16869. #endif
  16870. }
  16871. /// A client request to put an item on sale.
  16872. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  16873. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W
  16874. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  16875. #if PACKETVER_SUPPORTS_SALES
  16876. int32 count;
  16877. int16 nameid;
  16878. int startTime;
  16879. int endTime;
  16880. uint16 sellingHours;
  16881. nullpo_retv(sd);
  16882. if( RFIFOL(fd, 2) != sd->status.account_id ){
  16883. return;
  16884. }
  16885. if( !pc_has_permission( sd, PC_PERM_CASHSHOP_SALE ) ){
  16886. return;
  16887. }
  16888. nameid = RFIFOW(fd, 6);
  16889. count = RFIFOL(fd, 8);
  16890. startTime = RFIFOL(fd, 12);
  16891. #if PACKETVER >= 20150520
  16892. if( RFIFOW(fd,0) == 0xa3d )
  16893. sellingHours = RFIFOW(fd, 16);
  16894. else
  16895. #endif
  16896. sellingHours = RFIFOB(fd, 16);
  16897. endTime = startTime + sellingHours * 60 * 60;
  16898. clif_sale_add_reply( sd, sale_add_item(nameid,count,startTime,endTime) );
  16899. #endif
  16900. }
  16901. /// Reply to an item removal from sale.
  16902. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  16903. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  16904. #if PACKETVER_SUPPORTS_SALES
  16905. int fd = sd->fd;
  16906. WFIFOHEAD(fd, 4);
  16907. WFIFOW(fd, 0) = 0x9b1;
  16908. WFIFOW(fd, 2) = failed;
  16909. WFIFOSET(fd, 4);
  16910. #endif
  16911. }
  16912. /// Request to remove an item from sale.
  16913. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  16914. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  16915. #if PACKETVER_SUPPORTS_SALES
  16916. nullpo_retv(sd);
  16917. if( RFIFOL(fd, 2) != sd->status.account_id ){
  16918. return;
  16919. }
  16920. if( !pc_has_permission( sd, PC_PERM_CASHSHOP_SALE ) ){
  16921. return;
  16922. }
  16923. clif_sale_remove_reply(sd, !sale_remove_item(RFIFOW(fd, 6)));
  16924. #endif
  16925. }
  16926. /// Achievement System
  16927. /// Author: Luxuri, Aleos
  16928. /**
  16929. * Sends all achievement data to the client (ZC_ALL_AG_LIST).
  16930. * 0a23 <packetType>.W <packetLength>.W <ACHCount>.L <ACHPoint>.L
  16931. */
  16932. void clif_achievement_list_all(struct map_session_data *sd)
  16933. {
  16934. int i, j, len, fd, *info;
  16935. uint16 count = 0;
  16936. nullpo_retv(sd);
  16937. if (!battle_config.feature_achievement) {
  16938. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  16939. return;
  16940. }
  16941. fd = sd->fd;
  16942. count = sd->achievement_data.count; // All achievements should be sent to the client
  16943. len = (50 * count) + 22;
  16944. if (len <= 22)
  16945. return;
  16946. info = achievement_level(sd, true);
  16947. WFIFOHEAD(fd,len);
  16948. WFIFOW(fd, 0) = 0xa23;
  16949. WFIFOW(fd, 2) = len;
  16950. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  16951. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  16952. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  16953. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  16954. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  16955. for (i = 0; i < count; i++) {
  16956. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  16957. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  16958. for (j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  16959. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  16960. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  16961. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  16962. }
  16963. WFIFOSET(fd, len);
  16964. }
  16965. /**
  16966. * Sends a single achievement's data to the client (ZC_AG_UPDATE).
  16967. * 0a24 <packetType>.W <ACHPoint>.L
  16968. */
  16969. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  16970. {
  16971. int fd, i, *info;
  16972. nullpo_retv(sd);
  16973. if (!battle_config.feature_achievement) {
  16974. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  16975. return;
  16976. }
  16977. fd = sd->fd;
  16978. info = achievement_level(sd, true);
  16979. WFIFOHEAD(fd, packet_len(0xa24));
  16980. WFIFOW(fd, 0) = 0xa24;
  16981. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  16982. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  16983. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  16984. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  16985. if (ach) {
  16986. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  16987. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  16988. for (i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  16989. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  16990. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  16991. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  16992. } else
  16993. memset(WFIFOP(fd, 16), 0, 40);
  16994. WFIFOSET(fd, packet_len(0xa24));
  16995. }
  16996. /**
  16997. * Checks if an achievement reward can be rewarded (CZ_REQ_AG_REWARD).
  16998. * 0a25 <packetType>.W <achievementID>.L
  16999. */
  17000. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17001. {
  17002. nullpo_retv(sd);
  17003. if( sd->achievement_data.save )
  17004. intif_achievement_save(sd);
  17005. achievement_check_reward(sd, RFIFOL(fd,2));
  17006. }
  17007. /**
  17008. * Returns the result of achievement_check_reward (ZC_REQ_AG_REWARD_ACK).
  17009. * 0a26 <packetType>.W <result>.W <achievementID>.L
  17010. */
  17011. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17012. {
  17013. WFIFOHEAD(fd, packet_len(0xa26));
  17014. WFIFOW(fd, 0) = 0xa26;
  17015. WFIFOB(fd, 2) = result;
  17016. WFIFOL(fd, 3) = achievement_id;
  17017. WFIFOSET(fd, packet_len(0xa26));
  17018. }
  17019. /*==========================================
  17020. * Main client packet processing function
  17021. *------------------------------------------*/
  17022. static int clif_parse(int fd)
  17023. {
  17024. int cmd, packet_len;
  17025. TBL_PC* sd;
  17026. int pnum;
  17027. #ifdef PACKET_OBFUSCATION
  17028. int cmd2;
  17029. #endif
  17030. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  17031. // Note: "click masters" can do 80+ clicks in 10 seconds
  17032. 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]
  17033. { // begin main client packet processing loop
  17034. sd = (TBL_PC *)session[fd]->session_data;
  17035. if (session[fd]->flag.eof) {
  17036. if (sd) {
  17037. if (sd->state.autotrade) {
  17038. //Disassociate character from the socket connection.
  17039. session[fd]->session_data = NULL;
  17040. sd->fd = 0;
  17041. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  17042. } else
  17043. if (sd->state.active) {
  17044. // Player logout display [Valaris]
  17045. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  17046. clif_quitsave(fd, sd);
  17047. } else {
  17048. //Unusual logout (during log on/off/map-changer procedure)
  17049. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  17050. map_quit(sd);
  17051. }
  17052. } else {
  17053. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  17054. }
  17055. do_close(fd);
  17056. return 0;
  17057. }
  17058. if (RFIFOREST(fd) < 2)
  17059. return 0;
  17060. cmd = RFIFOW(fd, 0);
  17061. #ifdef PACKET_OBFUSCATION
  17062. // Check if it is a player that tries to connect to the map server.
  17063. if( sd ){
  17064. // Decrypt the current packet ID with the last key stored in the session.
  17065. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  17066. }else{
  17067. // Store the original value for checking
  17068. cmd2 = cmd;
  17069. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  17070. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17071. }
  17072. #endif
  17073. // filter out invalid / unsupported packets
  17074. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  17075. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  17076. #ifdef DUMP_INVALID_PACKET
  17077. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17078. #endif
  17079. #ifdef PACKET_OBFUSCATION_WARN
  17080. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  17081. if( !sd ){
  17082. #ifdef PACKET_OBFUSCATION
  17083. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  17084. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  17085. }
  17086. #else
  17087. // Try to use the initial keys for the decryption of the packet ID.
  17088. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17089. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  17090. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  17091. }
  17092. #endif
  17093. }
  17094. #endif
  17095. set_eof(fd);
  17096. return 0;
  17097. }
  17098. // determine real packet length
  17099. packet_len = packet_db[cmd].len;
  17100. if (packet_len == -1) { // variable-length packet
  17101. if (RFIFOREST(fd) < 4)
  17102. return 0;
  17103. packet_len = RFIFOW(fd,2);
  17104. if (packet_len < 4 || packet_len > 32768) {
  17105. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  17106. #ifdef DUMP_INVALID_PACKET
  17107. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17108. #endif
  17109. set_eof(fd);
  17110. return 0;
  17111. }
  17112. }
  17113. if ((int)RFIFOREST(fd) < packet_len)
  17114. return 0; // not enough data received to form the packet
  17115. #ifdef PACKET_OBFUSCATION
  17116. RFIFOW(fd, 0) = cmd;
  17117. if (sd)
  17118. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  17119. #endif
  17120. if( packet_db[cmd].func == clif_parse_debug )
  17121. packet_db[cmd].func(fd, sd);
  17122. else if( packet_db[cmd].func != NULL ) {
  17123. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  17124. ; //Only valid packet when there is no session
  17125. else
  17126. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  17127. ; //Only valid packet when player is not on a map
  17128. else
  17129. packet_db[cmd].func(fd, sd);
  17130. }
  17131. #ifdef DUMP_UNKNOWN_PACKET
  17132. else DumpUnknown(fd,sd,cmd,packet_len);
  17133. #endif
  17134. RFIFOSKIP(fd, packet_len);
  17135. }; // main loop end
  17136. return 0;
  17137. }
  17138. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  17139. va_list argp;
  17140. int i;
  17141. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  17142. return;
  17143. packet_db[cmd].len = length;
  17144. packet_db[cmd].func = func;
  17145. va_start(argp, func);
  17146. for( i = 0; i < MAX_PACKET_POS; i++ ){
  17147. int offset = va_arg(argp, int);
  17148. if( offset == 0 ){
  17149. break;
  17150. }
  17151. packet_db[cmd].pos[i] = offset;
  17152. }
  17153. if( i == MAX_PACKET_POS ){
  17154. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  17155. }
  17156. va_end(argp);
  17157. }
  17158. /*==========================================
  17159. * Reads packets and setups its array reference
  17160. *------------------------------------------*/
  17161. void packetdb_readdb(){
  17162. memset(packet_db,0,sizeof(packet_db));
  17163. memset(packet_db_ack,0,sizeof(packet_db_ack));
  17164. #include "clif_packetdb.h"
  17165. #include "clif_shuffle.h"
  17166. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  17167. #ifdef PACKET_OBFUSCATION
  17168. 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]);
  17169. #else
  17170. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  17171. #endif
  17172. }
  17173. /*==========================================
  17174. *
  17175. *------------------------------------------*/
  17176. void do_init_clif(void) {
  17177. const char* colors[COLOR_MAX] = {
  17178. "0x00FF00",
  17179. "0xFF0000",
  17180. "0xFFFFFF",
  17181. "0xFFFF00",
  17182. "0x00FFFF",
  17183. "0xB5FFB5",
  17184. };
  17185. int i;
  17186. /**
  17187. * Setup Color Table (saves unnecessary load of strtoul on every call)
  17188. **/
  17189. for(i = 0; i < COLOR_MAX; i++) {
  17190. color_table[i] = strtoul(colors[i],NULL,0);
  17191. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  17192. }
  17193. packetdb_readdb();
  17194. set_defaultparse(clif_parse);
  17195. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  17196. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  17197. exit(EXIT_FAILURE);
  17198. }
  17199. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  17200. add_timer_func_list(clif_delayquit, "clif_delayquit");
  17201. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  17202. }
  17203. void do_final_clif(void) {
  17204. ers_destroy(delay_clearunit_ers);
  17205. }
  17206. #ifdef __cplusplus
  17207. }
  17208. #endif