clif.cpp 583 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730
  1. // Copyright (c) rAthena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "clif.hpp"
  4. #include <cstdarg>
  5. #include <cstdio>
  6. #include <cstdlib>
  7. #include <cstring>
  8. #include <ctime>
  9. #include "../common/cbasetypes.hpp"
  10. #include "../common/conf.hpp"
  11. #include "../common/ers.hpp"
  12. #include "../common/grfio.hpp"
  13. #include "../common/malloc.hpp"
  14. #include "../common/nullpo.hpp"
  15. #include "../common/random.hpp"
  16. #include "../common/showmsg.hpp"
  17. #include "../common/socket.hpp"
  18. #include "../common/strlib.hpp"
  19. #include "../common/timer.hpp"
  20. #include "../common/utils.hpp"
  21. #include "achievement.hpp"
  22. #include "atcommand.hpp"
  23. #include "battle.hpp"
  24. #include "battleground.hpp"
  25. #include "cashshop.hpp"
  26. #include "channel.hpp"
  27. #include "chat.hpp"
  28. #include "chrif.hpp"
  29. #include "clan.hpp"
  30. #include "clif.hpp"
  31. #include "elemental.hpp"
  32. #include "guild.hpp"
  33. #include "homunculus.hpp"
  34. #include "instance.hpp"
  35. #include "intif.hpp"
  36. #include "itemdb.hpp"
  37. #include "log.hpp"
  38. #include "mail.hpp"
  39. #include "map.hpp"
  40. #include "mercenary.hpp"
  41. #include "mob.hpp"
  42. #include "npc.hpp"
  43. #include "party.hpp"
  44. #include "pc.hpp"
  45. #include "pc_groups.hpp"
  46. #include "pet.hpp"
  47. #include "quest.hpp"
  48. #include "script.hpp"
  49. #include "skill.hpp"
  50. #include "status.hpp"
  51. #include "storage.hpp"
  52. #include "trade.hpp"
  53. #include "unit.hpp"
  54. #include "vending.hpp"
  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.hpp"
  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_ARMOR. 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_ARMOR : 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 TIMER_FUNC(clif_clearunit_delayed_sub){
  744. struct block_list *bl = (struct block_list *)data;
  745. clif_clearunit_area(bl, (clr_type) id);
  746. ers_free(delay_clearunit_ers,bl);
  747. return 0;
  748. }
  749. void clif_clearunit_delayed(struct block_list* bl, clr_type type, unsigned int tick)
  750. {
  751. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  752. memcpy (tbl, bl, sizeof (struct block_list));
  753. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  754. }
  755. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  756. {
  757. if(sd->sc.option&OPTION_COSTUME)
  758. {
  759. *rhand = *lhand = 0;
  760. return;
  761. }
  762. #if PACKETVER < 4
  763. *rhand = sd->status.weapon;
  764. *lhand = sd->status.shield;
  765. #else
  766. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  767. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  768. {
  769. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  770. if (id->view_id > 0)
  771. *rhand = id->view_id;
  772. else
  773. *rhand = id->nameid;
  774. } else
  775. *rhand = 0;
  776. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  777. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  778. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  779. {
  780. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  781. if (id->view_id > 0)
  782. *lhand = id->view_id;
  783. else
  784. *lhand = id->nameid;
  785. } else
  786. *lhand = 0;
  787. #endif
  788. }
  789. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  790. static int clif_setlevel_sub(int lv) {
  791. if( lv < battle_config.max_lv ) {
  792. ;
  793. } else if( lv < battle_config.aura_lv ) {
  794. lv = battle_config.max_lv - 1;
  795. } else {
  796. lv = battle_config.max_lv;
  797. }
  798. return lv;
  799. }
  800. static int clif_setlevel(struct block_list* bl) {
  801. int lv = status_get_lv(bl);
  802. if( battle_config.client_limit_unit_lv&bl->type )
  803. return clif_setlevel_sub(lv);
  804. switch( bl->type ) {
  805. case BL_NPC:
  806. case BL_PET:
  807. // npcs and pets do not have level
  808. return 0;
  809. }
  810. return lv;
  811. }
  812. /*==========================================
  813. * Prepares 'unit standing/spawning' packet
  814. *------------------------------------------*/
  815. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  816. {
  817. struct map_session_data* sd;
  818. struct status_change* sc = status_get_sc(bl);
  819. struct view_data* vd = status_get_viewdata(bl);
  820. unsigned char *buf = WBUFP(buffer, 0);
  821. #if PACKETVER < 20091103
  822. bool type = !pcdb_checkid(vd->class_);
  823. #endif
  824. unsigned short offset = 0;
  825. #if PACKETVER >= 20091103
  826. const char *name;
  827. #endif
  828. sd = BL_CAST(BL_PC, bl);
  829. #if PACKETVER < 20091103
  830. if(type)
  831. WBUFW(buf,0) = spawn ? 0x7c : 0x78;
  832. else
  833. #endif
  834. #if PACKETVER < 4
  835. WBUFW(buf,0) = spawn ? 0x79 : 0x78;
  836. #elif PACKETVER < 7
  837. WBUFW(buf,0) = spawn ? 0x1d9 : 0x1d8;
  838. #elif PACKETVER < 20080102
  839. WBUFW(buf,0) = spawn ? 0x22b : 0x22a;
  840. #elif PACKETVER < 20091103
  841. WBUFW(buf,0) = spawn ? 0x2ed : 0x2ee;
  842. #elif PACKETVER < 20101124
  843. WBUFW(buf,0) = spawn ? 0x7f8 : 0x7f9;
  844. #elif PACKETVER < 20120221
  845. WBUFW(buf,0) = spawn ? 0x858 : 0x857;
  846. #elif PACKETVER < 20131223
  847. WBUFW(buf,0) = spawn ? 0x90f : 0x915;
  848. #elif PACKETVER < 20150513
  849. WBUFW(buf,0) = spawn ? 0x9dc : 0x9dd;
  850. #else
  851. WBUFW(buf,0) = spawn ? 0x9fe : 0x9ff;
  852. #endif
  853. #if PACKETVER >= 20091103
  854. name = status_get_name(bl);
  855. #if PACKETVER < 20110111
  856. WBUFW(buf,2) = (uint16)((spawn ? 62 : 63)+strlen(name));
  857. #elif PACKETVER < 20120221
  858. WBUFW(buf,2) = (uint16)((spawn ? 64 : 65)+strlen(name));
  859. #elif PACKETVER < 20130807
  860. WBUFW(buf,2) = (uint16)((spawn ? 77 : 78)+strlen(name));
  861. #else
  862. WBUFW(buf,2) = (uint16)((spawn ? 79 : 80)+strlen(name));
  863. #endif
  864. WBUFB(buf,4) = clif_bl_type(bl);
  865. offset+=3;
  866. buf = WBUFP(buffer,offset);
  867. #elif PACKETVER >= 20071106
  868. if (type) { //Non-player packets
  869. WBUFB(buf,2) = clif_bl_type(bl);
  870. offset++;
  871. buf = WBUFP(buffer,offset);
  872. }
  873. #endif
  874. WBUFL(buf, 2) = bl->id;
  875. #if PACKETVER >= 20131223
  876. WBUFL(buf,6) = (sd) ? sd->status.char_id : 0; // GID/CCODE
  877. offset+=4;
  878. buf = WBUFP(buffer,offset);
  879. #endif
  880. WBUFW(buf, 6) = status_get_speed(bl);
  881. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  882. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  883. #if PACKETVER < 20091103
  884. if (type&&spawn) { //uses an older and different packet structure
  885. WBUFW(buf,12) = (sc)? sc->option : 0;
  886. WBUFW(buf,14) = vd->hair_style;
  887. WBUFW(buf,16) = vd->weapon;
  888. WBUFW(buf,18) = vd->head_bottom;
  889. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  890. WBUFW(buf,22) = vd->shield;
  891. } else {
  892. #endif
  893. #if PACKETVER >= 20091103
  894. WBUFL(buf,12) = (sc)? sc->option : 0;
  895. offset+=2;
  896. buf = WBUFP(buffer,offset);
  897. #elif PACKETVER >= 7
  898. if (!type) {
  899. WBUFL(buf,12) = (sc)? sc->option : 0;
  900. offset+=2;
  901. buf = WBUFP(buffer,offset);
  902. } else
  903. WBUFW(buf,12) = (sc)? sc->option : 0;
  904. #else
  905. WBUFW(buf,12) = (sc)? sc->option : 0;
  906. #endif
  907. WBUFW(buf,14) = vd->class_;
  908. WBUFW(buf,16) = vd->hair_style;
  909. WBUFW(buf,18) = vd->weapon;
  910. #if PACKETVER < 4
  911. WBUFW(buf,20) = vd->head_bottom;
  912. WBUFW(buf,22) = vd->shield;
  913. #else
  914. WBUFW(buf,20) = vd->shield;
  915. WBUFW(buf,22) = vd->head_bottom;
  916. #endif
  917. #if PACKETVER < 20091103
  918. }
  919. #endif
  920. WBUFW(buf,24) = vd->head_top;
  921. WBUFW(buf,26) = vd->head_mid;
  922. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG )
  923. { //The hell, why flags work like this?
  924. WBUFW(buf,22) = status_get_emblem_id(bl);
  925. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  926. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  927. }
  928. WBUFW(buf,28) = vd->hair_color;
  929. WBUFW(buf,30) = vd->cloth_color;
  930. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  931. #if PACKETVER < 20091103
  932. if (type&&spawn) { //End of packet 0x7c
  933. WBUFB(buf,34) = (sd) ? sd->status.karma : 0; // karma
  934. WBUFB(buf,35) = vd->sex;
  935. WBUFPOS(buf,36, bl->x, bl->y, unit_getdir(bl));
  936. WBUFB(buf,39) = 0;
  937. WBUFB(buf,40) = 0;
  938. return packet_len(0x7c);
  939. }
  940. #endif
  941. #if PACKETVER >= 20110111
  942. WBUFW(buf,34) = vd->robe;
  943. offset+= 2;
  944. buf = WBUFP(buffer,offset);
  945. #endif
  946. WBUFL(buf,34) = status_get_guild_id(bl);
  947. WBUFW(buf,38) = status_get_emblem_id(bl);
  948. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  949. #if PACKETVER >= 20091103
  950. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  951. offset+=2;
  952. buf = WBUFP(buffer,offset);
  953. #elif PACKETVER >= 7
  954. if (!type) {
  955. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  956. offset+=2;
  957. buf = WBUFP(buffer,offset);
  958. } else
  959. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  960. #else
  961. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  962. #endif
  963. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  964. WBUFB(buf,45) = vd->sex;
  965. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  966. WBUFB(buf,49) = (sd)? 5 : 0;
  967. WBUFB(buf,50) = (sd)? 5 : 0;
  968. if (!spawn) {
  969. WBUFB(buf,51) = vd->dead_sit;
  970. offset++;
  971. buf = WBUFP(buffer,offset);
  972. }
  973. WBUFW(buf,51) = clif_setlevel(bl);
  974. #if PACKETVER < 20091103
  975. if (type) //End for non-player packet
  976. return packet_len(WBUFW(buffer,0));
  977. #endif
  978. #if PACKETVER >= 20080102
  979. WBUFW(buf,53) = (sd ? sd->status.font : 0);
  980. #endif
  981. #if PACKETVER >= 20120221
  982. if ( battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR) && bl->type == BL_MOB && (status_get_hp(bl) < status_get_max_hp(bl)) ) {
  983. WBUFL(buf,55) = status_get_max_hp(bl); // maxHP
  984. WBUFL(buf,59) = status_get_hp(bl); // HP
  985. } else {
  986. WBUFL(buf,55) = -1; // maxHP
  987. WBUFL(buf,59) = -1; // HP
  988. }
  989. WBUFB(buf,63) = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0; // isBoss
  990. #endif
  991. #if PACKETVER >= 20150513
  992. WBUFW(buf,64) = vd->body_style; // body
  993. offset+= 2;
  994. buf = WBUFP(buffer,offset);
  995. #endif
  996. #if PACKETVER >= 20091103
  997. #if PACKETVER >= 20120221
  998. safestrncpy(WBUFCP(buf,64), name, NAME_LENGTH);
  999. #else
  1000. safestrncpy(WBUFCP(buf,55), name, NAME_LENGTH);
  1001. #endif
  1002. return WBUFW(buffer,2);
  1003. #else
  1004. return packet_len(WBUFW(buffer,0));
  1005. #endif
  1006. }
  1007. /*==========================================
  1008. * Prepares 'unit walking' packet
  1009. *------------------------------------------*/
  1010. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  1011. {
  1012. struct map_session_data* sd;
  1013. struct status_change* sc = status_get_sc(bl);
  1014. struct view_data* vd = status_get_viewdata(bl);
  1015. unsigned char* buf = WBUFP(buffer,0);
  1016. #if PACKETVER >= 7
  1017. unsigned short offset = 0;
  1018. #endif
  1019. #if PACKETVER >= 20091103
  1020. const char *name;
  1021. #endif
  1022. sd = BL_CAST(BL_PC, bl);
  1023. #if PACKETVER < 4
  1024. WBUFW(buf, 0) = 0x7b;
  1025. #elif PACKETVER < 7
  1026. WBUFW(buf, 0) = 0x1da;
  1027. #elif PACKETVER < 20080102
  1028. WBUFW(buf, 0) = 0x22c;
  1029. #elif PACKETVER < 20091103
  1030. WBUFW(buf, 0) = 0x2ec;
  1031. #elif PACKETVER < 20101124
  1032. WBUFW(buf, 0) = 0x7f7;
  1033. #elif PACKETVER < 20120221
  1034. WBUFW(buf, 0) = 0x856;
  1035. #elif PACKETVER < 20131223
  1036. WBUFW(buf, 0) = 0x914;
  1037. #elif PACKETVER < 20150513
  1038. WBUFW(buf, 0) = 0x9db;
  1039. #else
  1040. WBUFW(buf, 0) = 0x9fd;
  1041. #endif
  1042. #if PACKETVER >= 20091103
  1043. name = status_get_name(bl);
  1044. #if PACKETVER < 20110111
  1045. WBUFW(buf, 2) = (uint16)(69+strlen(name));
  1046. #elif PACKETVER < 20120221
  1047. WBUFW(buf, 2) = (uint16)(71+strlen(name));
  1048. #elif PACKETVER < 20130807
  1049. WBUFW(buf, 2) = (uint16)(84+strlen(name));
  1050. #else
  1051. WBUFW(buf, 2) = (uint16)(86+strlen(name));
  1052. #endif
  1053. offset+=2;
  1054. buf = WBUFP(buffer,offset);
  1055. #endif
  1056. #if PACKETVER >= 20071106
  1057. WBUFB(buf, 2) = clif_bl_type(bl);
  1058. offset++;
  1059. buf = WBUFP(buffer,offset);
  1060. #endif
  1061. WBUFL(buf, 2) = bl->id;
  1062. #if PACKETVER >= 20131223
  1063. WBUFL(buf,6) = (sd) ? sd->status.char_id : 0; // GID/CCODE
  1064. offset+=4;
  1065. buf = WBUFP(buffer,offset);
  1066. #endif
  1067. WBUFW(buf, 6) = status_get_speed(bl);
  1068. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  1069. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  1070. #if PACKETVER < 7
  1071. WBUFW(buf,12) = (sc)? sc->option : 0;
  1072. #else
  1073. WBUFL(buf,12) = (sc)? sc->option : 0;
  1074. offset+=2; //Shift the rest of elements by 2 bytes.
  1075. buf = WBUFP(buffer,offset);
  1076. #endif
  1077. WBUFW(buf,14) = vd->class_;
  1078. WBUFW(buf,16) = vd->hair_style;
  1079. WBUFW(buf,18) = vd->weapon;
  1080. #if PACKETVER < 4
  1081. WBUFW(buf,20) = vd->head_bottom;
  1082. WBUFL(buf,22) = gettick();
  1083. WBUFW(buf,26) = vd->shield;
  1084. #else
  1085. WBUFW(buf,20) = vd->shield;
  1086. WBUFW(buf,22) = vd->head_bottom;
  1087. WBUFL(buf,24) = gettick();
  1088. #endif
  1089. WBUFW(buf,28) = vd->head_top;
  1090. WBUFW(buf,30) = vd->head_mid;
  1091. WBUFW(buf,32) = vd->hair_color;
  1092. WBUFW(buf,34) = vd->cloth_color;
  1093. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  1094. #if PACKETVER >= 20110111
  1095. WBUFW(buf,38) = vd->robe;
  1096. offset+= 2;
  1097. buf = WBUFP(buffer,offset);
  1098. #endif
  1099. WBUFL(buf,38) = status_get_guild_id(bl);
  1100. WBUFW(buf,42) = status_get_emblem_id(bl);
  1101. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  1102. #if PACKETVER < 7
  1103. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  1104. #else
  1105. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  1106. offset+=2; //Shift the rest of elements by 2 bytes.
  1107. buf = WBUFP(buffer,offset);
  1108. #endif
  1109. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  1110. WBUFB(buf,49) = vd->sex;
  1111. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1112. WBUFB(buf,56) = (sd)? 5 : 0;
  1113. WBUFB(buf,57) = (sd)? 5 : 0;
  1114. WBUFW(buf,58) = clif_setlevel(bl);
  1115. #if PACKETVER >= 20080102
  1116. WBUFW(buf,60) = (sd ? sd->status.font : 0);
  1117. #endif
  1118. #if PACKETVER >= 20120221
  1119. if ( battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR) && bl->type == BL_MOB && (status_get_hp(bl) < status_get_max_hp(bl)) ) {
  1120. WBUFL(buf,62) = status_get_max_hp(bl); // maxHP
  1121. WBUFL(buf,66) = status_get_hp(bl); // HP
  1122. } else {
  1123. WBUFL(buf,62) = -1; // maxHP
  1124. WBUFL(buf,66) = -1; // HP
  1125. }
  1126. WBUFB(buf,70) = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0; // isBoss
  1127. #endif
  1128. #if PACKETVER >= 20150513
  1129. WBUFW(buf,71) = vd->body_style; // body
  1130. offset+= 2;
  1131. buf = WBUFP(buffer,offset);
  1132. #endif
  1133. #if PACKETVER >= 20091103
  1134. #if PACKETVER >= 20120221
  1135. safestrncpy(WBUFCP(buf,71), name, NAME_LENGTH);
  1136. #else
  1137. safestrncpy(WBUFCP(buf,62), name, NAME_LENGTH);
  1138. #endif
  1139. return WBUFW(buffer,2);
  1140. #else
  1141. return packet_len(WBUFW(buffer,0));
  1142. #endif
  1143. }
  1144. //Modifies the buffer for disguise characters and sends it to self.
  1145. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1146. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1147. {
  1148. #if PACKETVER >= 20091103
  1149. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1150. WBUFL(buf,5)=-bl->id;
  1151. #elif PACKETVER >= 20071106
  1152. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1153. WBUFL(buf,3)=-bl->id;
  1154. #else
  1155. WBUFL(buf,2)=-bl->id;
  1156. #endif
  1157. clif_send(buf, len, bl, SELF);
  1158. }
  1159. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1160. /// 01b0 <id>.L <type>.B <value>.L
  1161. /// type:
  1162. /// unused
  1163. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, struct map_session_data *sd)
  1164. {
  1165. nullpo_retv(bl);
  1166. if(!pcdb_checkid(class_))
  1167. {// player classes yield missing sprites
  1168. unsigned char buf[16];
  1169. WBUFW(buf,0)=0x1b0;
  1170. WBUFL(buf,2)=bl->id;
  1171. WBUFB(buf,6)=type;
  1172. WBUFL(buf,7)=class_;
  1173. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1174. }
  1175. }
  1176. /// Notifies the client of an object's spirits.
  1177. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1178. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1179. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1180. {
  1181. WFIFOHEAD(fd, packet_len(0x1e1));
  1182. WFIFOW(fd,0)=0x1e1;
  1183. WFIFOL(fd,2)=sd->bl.id;
  1184. WFIFOW(fd,6)=sd->spiritball;
  1185. WFIFOSET(fd, packet_len(0x1e1));
  1186. }
  1187. /*==========================================
  1188. * Kagerou/Oboro amulet spirit
  1189. *------------------------------------------*/
  1190. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1191. {
  1192. WFIFOHEAD(fd, packet_len(0x08cf));
  1193. WFIFOW(fd,0)=0x08cf;
  1194. WFIFOL(fd,2)=sd->bl.id;
  1195. WFIFOW(fd,6)=sd->spiritcharm_type;
  1196. WFIFOW(fd,8)=sd->spiritcharm;
  1197. WFIFOSET(fd, packet_len(0x08cf));
  1198. }
  1199. /*==========================================
  1200. * Run when player changes map / refreshes
  1201. * Tells its client to display all weather settings being used by this map
  1202. *------------------------------------------*/
  1203. static void clif_weather_check(struct map_session_data *sd)
  1204. {
  1205. int16 m = sd->bl.m;
  1206. int fd = sd->fd;
  1207. if (map_getmapflag(m, MF_SNOW)
  1208. || map_getmapflag(m, MF_CLOUDS)
  1209. || map_getmapflag(m, MF_FOG)
  1210. || map_getmapflag(m, MF_FIREWORKS)
  1211. || map_getmapflag(m, MF_SAKURA)
  1212. || map_getmapflag(m, MF_LEAVES)
  1213. || map_getmapflag(m, MF_CLOUDS2))
  1214. {
  1215. if (map_getmapflag(m, MF_SNOW))
  1216. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1217. if (map_getmapflag(m, MF_CLOUDS))
  1218. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1219. if (map_getmapflag(m, MF_CLOUDS2))
  1220. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1221. if (map_getmapflag(m, MF_FOG))
  1222. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1223. if (map_getmapflag(m, MF_FIREWORKS)) {
  1224. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1225. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1226. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1227. }
  1228. if (map_getmapflag(m, MF_SAKURA))
  1229. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1230. if (map_getmapflag(m, MF_LEAVES))
  1231. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1232. }
  1233. }
  1234. /**
  1235. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1236. **/
  1237. void clif_weather(int16 m)
  1238. {
  1239. struct s_mapiterator* iter;
  1240. struct map_session_data *sd=NULL;
  1241. iter = mapit_getallusers();
  1242. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1243. {
  1244. if( sd->bl.m == m )
  1245. clif_weather_check(sd);
  1246. }
  1247. mapit_free(iter);
  1248. }
  1249. /**
  1250. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1251. **/
  1252. int clif_spawn(struct block_list *bl)
  1253. {
  1254. unsigned char buf[128];
  1255. struct view_data *vd;
  1256. int len;
  1257. vd = status_get_viewdata(bl);
  1258. if( !vd || vd->class_ == JT_INVISIBLE )
  1259. return 0;
  1260. /**
  1261. * Hide NPC from maya purple card.
  1262. **/
  1263. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1264. return 0;
  1265. len = clif_set_unit_idle(bl, buf,true);
  1266. clif_send(buf, len, bl, AREA_WOS);
  1267. if (disguised(bl))
  1268. clif_setdisguise(bl, buf, len);
  1269. if (vd->cloth_color)
  1270. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1271. if (vd->body_style)
  1272. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1273. switch (bl->type)
  1274. {
  1275. case BL_PC:
  1276. {
  1277. TBL_PC *sd = ((TBL_PC*)bl);
  1278. if (sd->spiritball > 0)
  1279. clif_spiritball(&sd->bl);
  1280. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1281. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1282. else if(sd->state.size==SZ_MEDIUM)
  1283. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1284. if( sd->bg_id && map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  1285. clif_sendbgemblem_area(sd);
  1286. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1287. clif_spiritcharm(sd);
  1288. if (sd->status.robe)
  1289. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1290. clif_efst_status_change_sub(bl, bl, AREA);
  1291. clif_hat_effects(sd,bl,AREA);
  1292. }
  1293. break;
  1294. case BL_MOB:
  1295. {
  1296. TBL_MOB *md = ((TBL_MOB*)bl);
  1297. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1298. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1299. else if(md->special_state.size==SZ_MEDIUM)
  1300. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1301. }
  1302. break;
  1303. case BL_NPC:
  1304. {
  1305. TBL_NPC *nd = ((TBL_NPC*)bl);
  1306. if( nd->size == SZ_BIG )
  1307. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1308. else if( nd->size == SZ_MEDIUM )
  1309. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1310. clif_efst_status_change_sub(bl, bl, AREA);
  1311. clif_progressbar_npc_area(nd);
  1312. }
  1313. break;
  1314. case BL_PET:
  1315. if (vd->head_bottom)
  1316. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1317. break;
  1318. }
  1319. return 0;
  1320. }
  1321. /// Sends information about owned homunculus to the client . [orn]
  1322. /// 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)
  1323. /// 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)
  1324. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1325. {
  1326. struct status_data *status;
  1327. unsigned char buf[128];
  1328. int offset;
  1329. #if PACKETVER < 20141016
  1330. const int cmd = 0x22e;
  1331. #else
  1332. const int cmd = 0x9f7;
  1333. #endif
  1334. int htype;
  1335. nullpo_retv(hd);
  1336. if (!clif_session_isValid(sd))
  1337. return;
  1338. status = &hd->battle_status;
  1339. htype = hom_class2type(hd->homunculus.class_);
  1340. memset(buf,0,packet_len(cmd));
  1341. WBUFW(buf,0) = cmd;
  1342. safestrncpy(WBUFCP(buf,2), hd->homunculus.name, NAME_LENGTH);
  1343. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1344. WBUFB(buf,26) = (battle_config.hom_rename ? 0 : hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp ? 0 : 4);
  1345. WBUFW(buf,27) = hd->homunculus.level;
  1346. WBUFW(buf,29) = hd->homunculus.hunger;
  1347. WBUFW(buf,31) = (unsigned short) (hd->homunculus.intimacy / 100) ;
  1348. WBUFW(buf,33) = 0; // equip id
  1349. #ifdef RENEWAL
  1350. WBUFW(buf,35) = cap_value(status->rhw.atk2, 0, INT16_MAX);
  1351. #else
  1352. WBUFW(buf,35) = cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1353. #endif
  1354. WBUFW(buf,37)=i16min(status->matk_max, INT16_MAX); //FIXME capping to INT16 here is too late
  1355. WBUFW(buf,39)=status->hit;
  1356. if (battle_config.hom_setting&HOMSET_DISPLAY_LUK)
  1357. WBUFW(buf,41) = status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1358. else
  1359. WBUFW(buf,41) = status->cri/10;
  1360. #ifdef RENEWAL
  1361. WBUFW(buf,43) = status->def + status->def2;
  1362. WBUFW(buf,45) = status->mdef + status->mdef2;
  1363. #else
  1364. WBUFW(buf,43) = status->def + status->vit;
  1365. WBUFW(buf,45) = status->mdef;
  1366. #endif
  1367. WBUFW(buf,47) = status->flee;
  1368. WBUFW(buf,49) = (flag) ? 0 : status->amotion;
  1369. #if PACKETVER >= 20141016
  1370. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1371. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1372. if (status->max_hp > (INT32_MAX/100)) {
  1373. WBUFL(buf,51) = status->hp/(status->max_hp/100);
  1374. WBUFL(buf,55) = 100;
  1375. } else {
  1376. WBUFL(buf,51) = status->hp;
  1377. WBUFL(buf,55) = status->max_hp;
  1378. }
  1379. offset = 4;
  1380. #else
  1381. if (status->max_hp > INT16_MAX) {
  1382. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1383. WBUFW(buf,53) = 100;
  1384. } else {
  1385. WBUFW(buf,51) = status->hp;
  1386. WBUFW(buf,53) = status->max_hp;
  1387. }
  1388. offset = 0;
  1389. #endif
  1390. if (status->max_sp > INT16_MAX) {
  1391. WBUFW(buf,55+offset) = status->sp/(status->max_sp/100);
  1392. WBUFW(buf,57+offset) = 100;
  1393. } else {
  1394. WBUFW(buf,55+offset) = status->sp;
  1395. WBUFW(buf,57+offset) = status->max_sp;
  1396. }
  1397. WBUFL(buf,59+offset) = hd->homunculus.exp;
  1398. WBUFL(buf,63+offset) = hd->exp_next;
  1399. switch( htype ) {
  1400. case HT_REG:
  1401. case HT_EVO:
  1402. if( hd->homunculus.level >= battle_config.hom_max_level )
  1403. WBUFL(buf,63+offset) = 0;
  1404. break;
  1405. case HT_S:
  1406. if( hd->homunculus.level >= battle_config.hom_S_max_level )
  1407. WBUFL(buf,63+offset) = 0;
  1408. break;
  1409. }
  1410. WBUFW(buf,67+offset) = hd->homunculus.skillpts;
  1411. WBUFW(buf,69+offset) = status_get_range(&hd->bl);
  1412. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  1413. }
  1414. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1415. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1416. /// type:
  1417. /// unused
  1418. /// state:
  1419. /// 0 = pre-init
  1420. /// 1 = intimacy
  1421. /// 2 = hunger
  1422. /// 3 = accessory?
  1423. /// ? = ignored
  1424. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1425. { //[orn]
  1426. int fd = sd->fd;
  1427. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1428. hom_calc_skilltree(sd->hd, 0);
  1429. WFIFOHEAD(fd, packet_len(0x230));
  1430. WFIFOW(fd,0)=0x230;
  1431. WFIFOB(fd,2)=0;
  1432. WFIFOB(fd,3)=state;
  1433. WFIFOL(fd,4)=sd->hd->bl.id;
  1434. WFIFOL(fd,8)=param;
  1435. WFIFOSET(fd,packet_len(0x230));
  1436. }
  1437. int clif_homskillinfoblock(struct map_session_data *sd)
  1438. { //[orn]
  1439. struct homun_data *hd;
  1440. int fd = sd->fd;
  1441. int i, len=4;
  1442. nullpo_ret(sd);
  1443. hd = sd->hd;
  1444. if ( !hd )
  1445. return 0 ;
  1446. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1447. WFIFOW(fd,0)=0x235;
  1448. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1449. int id = hd->homunculus.hskill[i].id;
  1450. if( id != 0 ){
  1451. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1452. short idx = hom_skill_get_index(id);
  1453. if (idx == -1)
  1454. continue;
  1455. WFIFOW(fd,len ) = id;
  1456. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1457. WFIFOW(fd,len+4) = 0;
  1458. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1459. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1460. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1461. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1462. 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;
  1463. len+=37;
  1464. }
  1465. }
  1466. WFIFOW(fd,2)=len;
  1467. WFIFOSET(fd,len);
  1468. return 0;
  1469. }
  1470. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1471. { //[orn]
  1472. struct homun_data *hd;
  1473. int fd;
  1474. short idx = -1;
  1475. nullpo_retv(sd);
  1476. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1477. return;
  1478. fd = sd->fd;
  1479. hd = sd->hd;
  1480. WFIFOHEAD(fd, packet_len(0x239));
  1481. WFIFOW(fd,0) = 0x239;
  1482. WFIFOW(fd,2) = skill_id;
  1483. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1484. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1485. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1486. 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;
  1487. WFIFOSET(fd,packet_len(0x239));
  1488. }
  1489. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1490. {
  1491. int fd=sd->fd;
  1492. WFIFOHEAD(fd,packet_len(0x22f));
  1493. WFIFOW(fd,0)=0x22f;
  1494. WFIFOB(fd,2)=fail;
  1495. WFIFOW(fd,3)=foodid;
  1496. WFIFOSET(fd,packet_len(0x22f));
  1497. return 0;
  1498. }
  1499. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1500. /// 0087 <walk start time>.L <walk data>.6B
  1501. void clif_walkok(struct map_session_data *sd)
  1502. {
  1503. int fd=sd->fd;
  1504. WFIFOHEAD(fd, packet_len(0x87));
  1505. WFIFOW(fd,0)=0x87;
  1506. WFIFOL(fd,2)=gettick();
  1507. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1508. WFIFOSET(fd,packet_len(0x87));
  1509. }
  1510. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1511. {
  1512. uint8 buf[128];
  1513. int len;
  1514. struct status_change *sc = NULL;
  1515. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1516. clif_ally_only = true;
  1517. len = clif_set_unit_walking(bl,ud,buf);
  1518. clif_send(buf,len,bl,AREA_WOS);
  1519. if (disguised(bl))
  1520. clif_setdisguise(bl, buf, len);
  1521. if(vd->cloth_color)
  1522. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1523. if(vd->body_style)
  1524. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1525. switch(bl->type) {
  1526. case BL_PC:
  1527. {
  1528. TBL_PC *sd = ((TBL_PC*)bl);
  1529. // clif_movepc(sd);
  1530. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1531. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1532. else if(sd->state.size==SZ_MEDIUM)
  1533. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1534. if (sd->status.robe)
  1535. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1536. }
  1537. break;
  1538. case BL_MOB:
  1539. {
  1540. TBL_MOB *md = ((TBL_MOB*)bl);
  1541. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1542. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1543. else if(md->special_state.size==SZ_MEDIUM)
  1544. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1545. }
  1546. break;
  1547. case BL_PET:
  1548. if(vd->head_bottom) // needed to display pet equip properly
  1549. clif_pet_equip_area((TBL_PET*)bl);
  1550. break;
  1551. }
  1552. clif_ally_only = false;
  1553. }
  1554. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1555. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1556. /// Note: unit must not be self
  1557. void clif_move(struct unit_data *ud)
  1558. {
  1559. unsigned char buf[16];
  1560. struct view_data* vd;
  1561. struct block_list* bl = ud->bl;
  1562. struct status_change *sc = NULL;
  1563. vd = status_get_viewdata(bl);
  1564. if (!vd )
  1565. return;
  1566. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1567. else if( vd->class_ == JT_INVISIBLE ){
  1568. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1569. if(disguised(bl)) {
  1570. WBUFW(buf,0)=0x86;
  1571. WBUFL(buf,2)=-bl->id;
  1572. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1573. WBUFL(buf,12)=gettick();
  1574. clif_send(buf, packet_len(0x86), bl, SELF);
  1575. }
  1576. return;
  1577. }
  1578. /**
  1579. * Hide NPC from maya purple card.
  1580. **/
  1581. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1582. return;
  1583. if (ud->state.speed_changed) {
  1584. // Since we don't know how to update the speed of other objects,
  1585. // use the old walk packet to update the data.
  1586. ud->state.speed_changed = 0;
  1587. clif_move2(bl, vd, ud);
  1588. return;
  1589. }
  1590. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1591. clif_ally_only = true;
  1592. WBUFW(buf,0)=0x86;
  1593. WBUFL(buf,2)=bl->id;
  1594. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1595. WBUFL(buf,12)=gettick();
  1596. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1597. if (disguised(bl)) {
  1598. WBUFL(buf,2)=-bl->id;
  1599. clif_send(buf, packet_len(0x86), bl, SELF);
  1600. }
  1601. clif_ally_only = false;
  1602. }
  1603. /*==========================================
  1604. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1605. *------------------------------------------*/
  1606. static TIMER_FUNC(clif_delayquit){
  1607. struct map_session_data *sd = NULL;
  1608. //Remove player from map server
  1609. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1610. map_quit(sd);
  1611. return 0;
  1612. }
  1613. /*==========================================
  1614. *
  1615. *------------------------------------------*/
  1616. void clif_quitsave(int fd,struct map_session_data *sd) {
  1617. if (!battle_config.prevent_logout ||
  1618. sd->canlog_tick == 0 ||
  1619. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1620. map_quit(sd);
  1621. else if (sd->fd) {
  1622. //Disassociate session from player (session is deleted after this function was called)
  1623. //And set a timer to make him quit later.
  1624. session[sd->fd]->session_data = NULL;
  1625. sd->fd = 0;
  1626. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1627. }
  1628. }
  1629. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1630. /// 0091 <map name>.16B <x>.W <y>.W
  1631. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1632. {
  1633. int fd;
  1634. nullpo_retv(sd);
  1635. fd = sd->fd;
  1636. WFIFOHEAD(fd,packet_len(0x91));
  1637. WFIFOW(fd,0) = 0x91;
  1638. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1639. WFIFOW(fd,18) = x;
  1640. WFIFOW(fd,20) = y;
  1641. WFIFOSET(fd,packet_len(0x91));
  1642. }
  1643. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1644. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1645. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1646. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1647. {
  1648. int fd;
  1649. #if PACKETVER >= 20170315
  1650. int cmd = 0xac7;
  1651. #else
  1652. int cmd = 0x92;
  1653. #endif
  1654. nullpo_retv(sd);
  1655. fd = sd->fd;
  1656. WFIFOHEAD(fd,packet_len(cmd));
  1657. WFIFOW(fd,0) = cmd;
  1658. mapindex_getmapname_ext(mapindex_id2name(map_index), WFIFOCP(fd,2));
  1659. WFIFOW(fd,18) = x;
  1660. WFIFOW(fd,20) = y;
  1661. WFIFOL(fd,22) = htonl(ip);
  1662. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1663. #if PACKETVER >= 20170315
  1664. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1665. #endif
  1666. WFIFOSET(fd,packet_len(cmd));
  1667. }
  1668. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1669. /// This function combines both calls and allows to simplify the calling code
  1670. void clif_blown(struct block_list *bl)
  1671. {
  1672. clif_slide(bl, bl->x, bl->y);
  1673. clif_fixpos(bl);
  1674. }
  1675. /// Visually moves(slides) a character to x,y. If the target cell
  1676. /// isn't walkable, the char doesn't move at all. If the char is
  1677. /// sitting it will stand up (ZC_STOPMOVE).
  1678. /// 0088 <id>.L <x>.W <y>.W
  1679. void clif_fixpos(struct block_list *bl)
  1680. {
  1681. unsigned char buf[10];
  1682. nullpo_retv(bl);
  1683. WBUFW(buf,0) = 0x88;
  1684. WBUFL(buf,2) = bl->id;
  1685. WBUFW(buf,6) = bl->x;
  1686. WBUFW(buf,8) = bl->y;
  1687. clif_send(buf, packet_len(0x88), bl, AREA);
  1688. if( disguised(bl) ) {
  1689. WBUFL(buf,2) = -bl->id;
  1690. clif_send(buf, packet_len(0x88), bl, SELF);
  1691. }
  1692. }
  1693. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1694. /// 00c4 <shop id>.L
  1695. void clif_npcbuysell(struct map_session_data* sd, int id)
  1696. {
  1697. int fd;
  1698. nullpo_retv(sd);
  1699. fd=sd->fd;
  1700. WFIFOHEAD(fd, packet_len(0xc4));
  1701. WFIFOW(fd,0)=0xc4;
  1702. WFIFOL(fd,2)=id;
  1703. WFIFOSET(fd,packet_len(0xc4));
  1704. }
  1705. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1706. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1707. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1708. {
  1709. int fd,i,c;
  1710. bool discount;
  1711. nullpo_retv(sd);
  1712. nullpo_retv(nd);
  1713. fd = sd->fd;
  1714. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1715. WFIFOW(fd,0) = 0xc6;
  1716. c = 0;
  1717. discount = npc_shop_discount(nd->subtype,nd->u.shop.discount);
  1718. for( i = 0; i < nd->u.shop.count; i++ )
  1719. {
  1720. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1721. int val = nd->u.shop.shop_item[i].value;
  1722. if( id == NULL )
  1723. continue;
  1724. WFIFOL(fd, 4+c*11) = val;
  1725. WFIFOL(fd, 8+c*11) = (discount) ? pc_modifybuyvalue(sd,val) : val;
  1726. WFIFOB(fd,12+c*11) = itemtype(id->nameid);
  1727. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1728. c++;
  1729. }
  1730. WFIFOW(fd,2) = 4 + c*11;
  1731. WFIFOSET(fd,WFIFOW(fd,2));
  1732. }
  1733. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1734. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1735. void clif_selllist(struct map_session_data *sd)
  1736. {
  1737. int fd,i,c=0,val;
  1738. nullpo_retv(sd);
  1739. fd=sd->fd;
  1740. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1741. WFIFOW(fd,0)=0xc7;
  1742. for( i = 0; i < MAX_INVENTORY; i++ )
  1743. {
  1744. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1745. {
  1746. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i]))
  1747. continue;
  1748. val=sd->inventory_data[i]->value_sell;
  1749. if( val < 0 )
  1750. continue;
  1751. WFIFOW(fd,4+c*10)=i+2;
  1752. WFIFOL(fd,6+c*10)=val;
  1753. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1754. c++;
  1755. }
  1756. }
  1757. WFIFOW(fd,2)=c*10+4;
  1758. WFIFOSET(fd,WFIFOW(fd,2));
  1759. }
  1760. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1761. /// 09d4
  1762. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1763. // TODO: State tracking?
  1764. sd->npc_shopid = 0;
  1765. }
  1766. /**
  1767. * Presents list of items, that can be sold to a Market shop.
  1768. * @author: Ind and Yommy
  1769. **/
  1770. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1771. #if PACKETVER >= 20131223
  1772. struct npc_item_list *shop = nd->u.shop.shop_item;
  1773. unsigned short shop_size = nd->u.shop.count, i, c, cmd = 0x9d5;
  1774. struct item_data *id = NULL;
  1775. struct s_packet_db *info;
  1776. int fd;
  1777. nullpo_retv(sd);
  1778. if (sd->state.trading)
  1779. return;
  1780. info = &packet_db[cmd];
  1781. if (!info || info->len == 0)
  1782. return;
  1783. fd = sd->fd;
  1784. WFIFOHEAD(fd, 4 + shop_size * 13);
  1785. WFIFOW(fd,0) = cmd;
  1786. for (i = 0, c = 0; i < shop_size; i++) {
  1787. if (shop[i].nameid && (id = itemdb_exists(shop[i].nameid))) {
  1788. WFIFOW(fd, 4+c*13) = shop[i].nameid;
  1789. WFIFOB(fd, 6+c*13) = itemtype(id->nameid);
  1790. WFIFOL(fd, 7+c*13) = shop[i].value;
  1791. WFIFOL(fd,11+c*13) = shop[i].qty;
  1792. WFIFOW(fd,15+c*13) = id->weight;
  1793. c++;
  1794. }
  1795. }
  1796. WFIFOW(fd,2) = 4 + c*13;
  1797. WFIFOSET(fd,WFIFOW(fd,2));
  1798. sd->state.trading = 1;
  1799. #endif
  1800. }
  1801. /// Closes the Market shop window.
  1802. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  1803. nullpo_retv(sd);
  1804. sd->npc_shopid = 0;
  1805. sd->state.trading = 0;
  1806. }
  1807. /// Purchase item from Market shop.
  1808. void clif_npc_market_purchase_ack(struct map_session_data *sd, uint8 res, uint8 n, struct s_npc_buy_list *list) {
  1809. #if PACKETVER >= 20131223
  1810. unsigned short cmd = 0x9d7, len = 0;
  1811. struct npc_data* nd;
  1812. uint8 result = (res == 0 ? 1 : 0);
  1813. int fd = 0;
  1814. struct s_packet_db *info;
  1815. nullpo_retv(sd);
  1816. nullpo_retv((nd = map_id2nd(sd->npc_shopid)));
  1817. info = &packet_db[cmd];
  1818. if (!info || info->len == 0)
  1819. return;
  1820. fd = sd->fd;
  1821. len = 5 + 8*n;
  1822. WFIFOHEAD(fd, len);
  1823. WFIFOW(fd, 0) = cmd;
  1824. WFIFOW(fd, 2) = len;
  1825. if (result) {
  1826. uint8 i, j;
  1827. struct npc_item_list *shop = nd->u.shop.shop_item;
  1828. unsigned short count = nd->u.shop.count;
  1829. for (i = 0; i < n; i++) {
  1830. WFIFOW(fd, 5+i*8) = list[i].nameid;
  1831. WFIFOW(fd, 7+i*8) = list[i].qty;
  1832. ARR_FIND(0, count, j, list[i].nameid == shop[j].nameid);
  1833. WFIFOL(fd, 9+i*8) = (j != count) ? shop[j].value : 0;
  1834. }
  1835. }
  1836. WFIFOB(fd, 4) = n;
  1837. WFIFOSET(fd, len);
  1838. #endif
  1839. }
  1840. /// Purchase item from Market shop.
  1841. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  1842. #if PACKETVER >= 20131223
  1843. struct s_packet_db* info;
  1844. struct s_npc_buy_list *item_list;
  1845. uint16 len = 0, i = 0;
  1846. uint8 res = 0, n = 0;
  1847. nullpo_retv(sd);
  1848. if (!sd->npc_shopid)
  1849. return;
  1850. info = &packet_db[RFIFOW(fd,0)];
  1851. if (!info || info->len == 0)
  1852. return;
  1853. len = RFIFOW(fd,info->pos[0]);
  1854. n = (len-4) / 6;
  1855. CREATE(item_list, struct s_npc_buy_list, n);
  1856. for (i = 0; i < n; i++) {
  1857. item_list[i].nameid = RFIFOW(fd,info->pos[1]+i*6);
  1858. item_list[i].qty = (uint16)min(RFIFOL(fd,info->pos[2]+i*6),USHRT_MAX);
  1859. }
  1860. res = npc_buylist(sd, n, item_list);
  1861. clif_npc_market_purchase_ack(sd, res, n, item_list);
  1862. aFree(item_list);
  1863. #endif
  1864. }
  1865. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1866. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1867. /// Client behavior (dialog window):
  1868. /// - disable mouse targeting
  1869. /// - open the dialog window
  1870. /// - set npcid of dialog window (0 by default)
  1871. /// - if set to clear on next mes, clear contents
  1872. /// - append this text
  1873. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1874. {
  1875. int fd = sd->fd;
  1876. int slen = strlen(mes) + 9;
  1877. WFIFOHEAD(fd, slen);
  1878. WFIFOW(fd,0)=0xb4;
  1879. WFIFOW(fd,2)=slen;
  1880. WFIFOL(fd,4)=npcid;
  1881. memcpy(WFIFOCP(fd,8), mes, slen-8);
  1882. WFIFOSET(fd,WFIFOW(fd,2));
  1883. }
  1884. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1885. /// 00b5 <npc id>.L
  1886. /// Client behavior (dialog window):
  1887. /// - disable mouse targeting
  1888. /// - open the dialog window
  1889. /// - add 'next' button
  1890. /// When 'next' is pressed:
  1891. /// - 00B9 <npcid of dialog window>.L
  1892. /// - set to clear on next mes
  1893. /// - remove 'next' button
  1894. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1895. {
  1896. int fd;
  1897. nullpo_retv(sd);
  1898. fd=sd->fd;
  1899. WFIFOHEAD(fd, packet_len(0xb5));
  1900. WFIFOW(fd,0)=0xb5;
  1901. WFIFOL(fd,2)=npcid;
  1902. WFIFOSET(fd,packet_len(0xb5));
  1903. }
  1904. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1905. /// 00b6 <npc id>.L
  1906. /// Client behavior:
  1907. /// - if dialog window is open:
  1908. /// - remove 'next' button
  1909. /// - add 'close' button
  1910. /// - else:
  1911. /// - enable mouse targeting
  1912. /// - close the dialog window
  1913. /// - close the menu window
  1914. /// When 'close' is pressed:
  1915. /// - enable mouse targeting
  1916. /// - close the dialog window
  1917. /// - close the menu window
  1918. /// - 0146 <npcid of dialog window>.L
  1919. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1920. {
  1921. int fd;
  1922. nullpo_retv(sd);
  1923. fd=sd->fd;
  1924. WFIFOHEAD(fd, packet_len(0xb6));
  1925. WFIFOW(fd,0)=0xb6;
  1926. WFIFOL(fd,2)=npcid;
  1927. WFIFOSET(fd,packet_len(0xb6));
  1928. }
  1929. /**
  1930. * Close script when player is idle
  1931. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  1932. * @author [Ind/Hercules]
  1933. * @param sd : player pointer
  1934. * @param npcid : npc gid to close
  1935. */
  1936. void clif_scriptclear(struct map_session_data *sd, int npcid)
  1937. {
  1938. struct s_packet_db* info;
  1939. int16 len;
  1940. int cmd = 0;
  1941. int fd;
  1942. nullpo_retv(sd);
  1943. cmd = packet_db_ack[ZC_CLEAR_DIALOG];
  1944. if(!cmd) cmd = 0x8d6; //default
  1945. info = &packet_db[cmd];
  1946. len = info->len;
  1947. fd = sd->fd;
  1948. WFIFOHEAD(fd, len);
  1949. WFIFOW(fd,0)=0x8d6;
  1950. WFIFOL(fd,info->pos[0])=npcid;
  1951. WFIFOSET(fd,len);
  1952. }
  1953. /*==========================================
  1954. *
  1955. *------------------------------------------*/
  1956. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1957. unsigned char *buf;
  1958. int fd = sd->fd;
  1959. sd->state.using_fake_npc = 1;
  1960. WFIFOHEAD(fd, packet_len(0x78));
  1961. buf = WFIFOP(fd,0);
  1962. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1963. WBUFW(buf,0)=0x78;
  1964. #if PACKETVER >= 20071106
  1965. WBUFB(buf,2) = 0; // object type
  1966. buf = WFIFOP(fd,1);
  1967. #endif
  1968. WBUFL(buf,2)=npcid;
  1969. WBUFW(buf,14)=111;
  1970. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1971. WBUFB(buf,49)=5;
  1972. WBUFB(buf,50)=5;
  1973. WFIFOSET(fd, packet_len(0x78));
  1974. }
  1975. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1976. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1977. /// Client behavior:
  1978. /// - disable mouse targeting
  1979. /// - close the menu window
  1980. /// - open the menu window
  1981. /// - add options to the menu (separated in the text by ":")
  1982. /// - set npcid of menu window
  1983. /// - if dialog window is open:
  1984. /// - remove 'next' button
  1985. /// When 'ok' is pressed:
  1986. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1987. /// - close the menu window
  1988. /// When 'cancel' is pressed:
  1989. /// - 00B8 <npcid of menu window>.L <-1>.B
  1990. /// - enable mouse targeting
  1991. /// - close a bunch of windows...
  1992. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1993. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1994. /// TODO investigate behavior of other windows [FlavioJS]
  1995. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1996. {
  1997. int fd = sd->fd;
  1998. int slen = strlen(mes) + 9;
  1999. struct block_list *bl = NULL;
  2000. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2001. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2002. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2003. clif_sendfakenpc(sd, npcid);
  2004. WFIFOHEAD(fd, slen);
  2005. WFIFOW(fd,0)=0xb7;
  2006. WFIFOW(fd,2)=slen;
  2007. WFIFOL(fd,4)=npcid;
  2008. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2009. WFIFOSET(fd,WFIFOW(fd,2));
  2010. }
  2011. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2012. /// 0142 <npc id>.L
  2013. /// Client behavior (inputnum window):
  2014. /// - if npcid exists in the client:
  2015. /// - open the inputnum window
  2016. /// - set npcid of inputnum window
  2017. /// When 'ok' is pressed:
  2018. /// - if inputnum window has text:
  2019. /// - if npcid exists in the client:
  2020. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2021. /// - close inputnum window
  2022. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2023. {
  2024. int fd;
  2025. struct block_list *bl = NULL;
  2026. nullpo_retv(sd);
  2027. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2028. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2029. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2030. clif_sendfakenpc(sd, npcid);
  2031. fd=sd->fd;
  2032. WFIFOHEAD(fd, packet_len(0x142));
  2033. WFIFOW(fd,0)=0x142;
  2034. WFIFOL(fd,2)=npcid;
  2035. WFIFOSET(fd,packet_len(0x142));
  2036. }
  2037. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2038. /// 01d4 <npc id>.L
  2039. /// Client behavior (inputstr window):
  2040. /// - if npcid is 0 or npcid exists in the client:
  2041. /// - open the inputstr window
  2042. /// - set npcid of inputstr window
  2043. /// When 'ok' is pressed:
  2044. /// - if inputstr window has text and isn't an insult(manner.txt):
  2045. /// - if npcid is 0 or npcid exists in the client:
  2046. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2047. /// - close inputstr window
  2048. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2049. {
  2050. int fd;
  2051. struct block_list *bl = NULL;
  2052. nullpo_retv(sd);
  2053. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2054. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2055. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2056. clif_sendfakenpc(sd, npcid);
  2057. fd=sd->fd;
  2058. WFIFOHEAD(fd, packet_len(0x1d4));
  2059. WFIFOW(fd,0)=0x1d4;
  2060. WFIFOL(fd,2)=npcid;
  2061. WFIFOSET(fd,packet_len(0x1d4));
  2062. }
  2063. /// Marks a position on client's minimap (ZC_COMPASS).
  2064. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2065. /// npc id:
  2066. /// is ignored in the client
  2067. /// type:
  2068. /// 0 = display mark for 15 seconds
  2069. /// 1 = display mark until dead or teleported
  2070. /// 2 = remove mark
  2071. /// color:
  2072. /// 0x00RRGGBB
  2073. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2074. {
  2075. int fd;
  2076. nullpo_retv(sd);
  2077. fd=sd->fd;
  2078. WFIFOHEAD(fd, packet_len(0x144));
  2079. WFIFOW(fd,0)=0x144;
  2080. WFIFOL(fd,2)=npc_id;
  2081. WFIFOL(fd,6)=type;
  2082. WFIFOL(fd,10)=x;
  2083. WFIFOL(fd,14)=y;
  2084. WFIFOB(fd,18)=id;
  2085. WFIFOL(fd,19)=color;
  2086. WFIFOSET(fd,packet_len(0x144));
  2087. }
  2088. /// Displays an illustration image.
  2089. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2090. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2091. /// type:
  2092. /// 0 = bottom left corner
  2093. /// 1 = bottom middle
  2094. /// 2 = bottom right corner
  2095. /// 3 = middle of screen, inside a movable window
  2096. /// 4 = middle of screen, movable with a close button, chrome-less
  2097. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2098. {
  2099. int fd;
  2100. nullpo_retv(sd);
  2101. fd=sd->fd;
  2102. WFIFOHEAD(fd, packet_len(0x1b3));
  2103. WFIFOW(fd,0)=0x1b3;
  2104. strncpy(WFIFOCP(fd,2),image,64);
  2105. WFIFOB(fd,66)=type;
  2106. WFIFOSET(fd,packet_len(0x1b3));
  2107. }
  2108. /*==========================================
  2109. * Fills in card data from the given item and into the buffer. [Skotlex]
  2110. *------------------------------------------*/
  2111. static void clif_addcards(unsigned char* buf, struct item* item)
  2112. {
  2113. int i=0,j;
  2114. if( item == NULL ) { //Blank data
  2115. WBUFW(buf,0) = 0;
  2116. WBUFW(buf,2) = 0;
  2117. WBUFW(buf,4) = 0;
  2118. WBUFW(buf,6) = 0;
  2119. return;
  2120. }
  2121. if( item->card[0] == CARD0_PET ) { //pet eggs
  2122. WBUFW(buf,0) = 0;
  2123. WBUFW(buf,2) = 0;
  2124. WBUFW(buf,4) = 0;
  2125. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  2126. return;
  2127. }
  2128. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  2129. WBUFW(buf,0) = item->card[0];
  2130. WBUFW(buf,2) = item->card[1];
  2131. WBUFW(buf,4) = item->card[2];
  2132. WBUFW(buf,6) = item->card[3];
  2133. return;
  2134. }
  2135. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2136. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  2137. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2138. //Normal items.
  2139. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2140. WBUFW(buf,0) = j;
  2141. else
  2142. WBUFW(buf,0) = item->card[i];
  2143. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2144. WBUFW(buf,2) = j;
  2145. else
  2146. WBUFW(buf,2) = item->card[i];
  2147. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2148. WBUFW(buf,4) = j;
  2149. else
  2150. WBUFW(buf,4) = item->card[i];
  2151. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2152. WBUFW(buf,6) = j;
  2153. else
  2154. WBUFW(buf,6) = item->card[i];
  2155. }
  2156. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2157. /// A maximum of 5 random options can be supported.
  2158. void clif_add_random_options(unsigned char* buf, struct item *it) {
  2159. #if PACKETVER >= 20150225
  2160. int i;
  2161. for (i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  2162. WBUFW(buf, i*5 + 0) = it->option[i].id; // OptIndex
  2163. WBUFW(buf, i*5 + 2) = it->option[i].value; // Value
  2164. WBUFB(buf, i*5 + 4) = it->option[i].param; // Param1
  2165. }
  2166. #if MAX_ITEM_RDM_OPT < 5
  2167. for ( ; i < 5; i++) {
  2168. WBUFW(buf, i*5 + 0) = 0; // OptIndex
  2169. WBUFW(buf, i*5 + 2) = 0; // Value
  2170. WBUFB(buf, i*5 + 4) = 0; // Param1
  2171. }
  2172. #endif
  2173. #endif
  2174. }
  2175. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2176. /// 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)
  2177. /// 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)
  2178. /// 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)
  2179. /// 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)
  2180. /// 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 { <option id>.W <option value>.W <option param>.B }*5 (ZC_ITEM_PICKUP_ACK_V6)
  2181. /// 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 { <option id>.W <option value>.W <option param>.B }*5 <favorite>.B <view id>.W (ZC_ITEM_PICKUP_ACK_V7)
  2182. void clif_additem(struct map_session_data *sd, int n, int amount, unsigned char fail)
  2183. {
  2184. int fd, header, offs=0;
  2185. #if PACKETVER < 20061218
  2186. header = 0xa0;
  2187. #elif PACKETVER < 20071002
  2188. header = 0x29a;
  2189. #elif PACKETVER < 20120925
  2190. header = 0x2d4;
  2191. #elif PACKETVER < 20150225
  2192. header = 0x990;
  2193. #elif PACKETVER < 20160921
  2194. header = 0xa0c;
  2195. #else
  2196. header = 0xa37;
  2197. #endif
  2198. nullpo_retv(sd);
  2199. fd = sd->fd;
  2200. if( !session_isActive(fd) ) //Sasuke-
  2201. return;
  2202. WFIFOHEAD(fd,packet_len(header));
  2203. if( fail )
  2204. {
  2205. WFIFOW(fd,offs+0) = header;
  2206. WFIFOW(fd,offs+2) = n+2;
  2207. WFIFOW(fd,offs+4) = amount;
  2208. WFIFOW(fd,offs+6) = 0;
  2209. WFIFOB(fd,offs+8) = 0;
  2210. WFIFOB(fd,offs+9) = 0;
  2211. WFIFOB(fd,offs+10) = 0;
  2212. WFIFOW(fd,offs+11) = 0;
  2213. WFIFOW(fd,offs+13) = 0;
  2214. WFIFOW(fd,offs+15) = 0;
  2215. WFIFOW(fd,offs+17) = 0;
  2216. #if PACKETVER < 20120925
  2217. WFIFOW(fd,offs+19) = 0;
  2218. #else
  2219. WFIFOL(fd,offs+19) = 0;
  2220. offs += 2;
  2221. #endif
  2222. WFIFOB(fd,offs+21) = 0;
  2223. WFIFOB(fd,offs+22) = fail;
  2224. #if PACKETVER >= 20061218
  2225. WFIFOL(fd,offs+23) = 0;
  2226. #endif
  2227. #if PACKETVER >= 20071002
  2228. WFIFOW(fd,offs+27) = 0; // HireExpireDate
  2229. #if PACKETVER >= 20150225
  2230. clif_add_random_options(WFIFOP(fd,offs+31), &sd->inventory.u.items_inventory[n]);
  2231. #if PACKETVER >= 20160921
  2232. WFIFOB(fd,offs+54) = 0; // Favorite
  2233. WFIFOW(fd,offs+55) = 0; // View ID
  2234. #endif
  2235. #endif
  2236. #endif
  2237. }
  2238. else
  2239. {
  2240. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  2241. return;
  2242. WFIFOW(fd,offs+0) = header;
  2243. WFIFOW(fd,offs+2) = n+2;
  2244. WFIFOW(fd,offs+4) = amount;
  2245. if (sd->inventory_data[n]->view_id > 0)
  2246. WFIFOW(fd,offs+6) = sd->inventory_data[n]->view_id;
  2247. else
  2248. WFIFOW(fd,offs+6)=sd->inventory.u.items_inventory[n].nameid;
  2249. WFIFOB(fd,offs+8)=sd->inventory.u.items_inventory[n].identify;
  2250. WFIFOB(fd,offs+9)=sd->inventory.u.items_inventory[n].attribute;
  2251. WFIFOB(fd,offs+10)=sd->inventory.u.items_inventory[n].refine;
  2252. clif_addcards(WFIFOP(fd,offs+11), &sd->inventory.u.items_inventory[n]);
  2253. #if PACKETVER < 20120925
  2254. WFIFOW(fd,offs+19) = pc_equippoint(sd,n);
  2255. #else
  2256. WFIFOL(fd,offs+19) = pc_equippoint(sd,n);
  2257. offs += 2;
  2258. #endif
  2259. WFIFOB(fd,offs+21) = itemtype(sd->inventory_data[n]->nameid);
  2260. WFIFOB(fd,offs+22) = fail;
  2261. #if PACKETVER >= 20061218
  2262. WFIFOL(fd,offs+23)=sd->inventory.u.items_inventory[n].expire_time;
  2263. #endif
  2264. #if PACKETVER >= 20071002
  2265. /* Yellow color only for non-stackable item */
  2266. 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;
  2267. #endif
  2268. #if PACKETVER >= 20150225
  2269. clif_add_random_options(WFIFOP(fd,31), &sd->inventory.u.items_inventory[n]);
  2270. #if PACKETVER >= 20160921
  2271. WFIFOB(fd,offs+54) = sd->inventory.u.items_inventory[n].favorite;
  2272. WFIFOW(fd,offs+55) = sd->inventory_data[n]->look;
  2273. #endif
  2274. #endif
  2275. }
  2276. WFIFOSET(fd,packet_len(header));
  2277. }
  2278. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2279. /// 00af <index>.W <amount>.W
  2280. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2281. {
  2282. int fd;
  2283. nullpo_retv(sd);
  2284. fd=sd->fd;
  2285. WFIFOHEAD(fd, packet_len(0xaf));
  2286. WFIFOW(fd,0)=0xaf;
  2287. WFIFOW(fd,2)=n+2;
  2288. WFIFOW(fd,4)=amount;
  2289. WFIFOSET(fd,packet_len(0xaf));
  2290. }
  2291. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2292. /// 07fa <delete type>.W <index>.W <amount>.W
  2293. /// delete type:
  2294. /// 0 = Normal
  2295. /// 1 = Item used for a skill
  2296. /// 2 = Refine failed
  2297. /// 3 = Material changed
  2298. /// 4 = Moved to storage
  2299. /// 5 = Moved to cart
  2300. /// 6 = Item sold
  2301. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2302. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2303. {
  2304. #if PACKETVER < 20091117
  2305. clif_dropitem(sd,n,amount);
  2306. #else
  2307. int fd;
  2308. nullpo_retv(sd);
  2309. fd=sd->fd;
  2310. WFIFOHEAD(fd, packet_len(0x7fa));
  2311. WFIFOW(fd,0)=0x7fa;
  2312. WFIFOW(fd,2)=reason;
  2313. WFIFOW(fd,4)=n+2;
  2314. WFIFOW(fd,6)=amount;
  2315. WFIFOSET(fd,packet_len(0x7fa));
  2316. #endif
  2317. }
  2318. void clif_item_sub_v5(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2319. char normal = (equip < 0);
  2320. int offset = 0;
  2321. WBUFW(buf,n) = idx; //index
  2322. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid;
  2323. WBUFB(buf,n+4) = itemtype(id->nameid);
  2324. if (!normal){ //equip 31B
  2325. WBUFL(buf,n+5) = equip; //location
  2326. WBUFL(buf,n+9) = it->equip; //wear state
  2327. WBUFB(buf,n+13) = it->refine; //refine lvl
  2328. clif_addcards(WBUFP(buf, n+14), it); //EQUIPSLOTINFO 8B
  2329. WBUFL(buf,n+22) = it->expire_time;
  2330. WBUFW(buf,n+26) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0; //bindOnEquipType
  2331. WBUFW(buf,n+28) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2332. #if PACKETVER >= 20150225
  2333. //V6_ITEM_Option
  2334. WBUFB(buf,n+30) = 0; // nRandomOptionCnt
  2335. clif_add_random_options(WBUFP(buf, n+31), it);// optionData
  2336. offset += 26;
  2337. #endif
  2338. //V5_ITEM_flag
  2339. WBUFB(buf,n+30+offset) = it->identify; //0x1 IsIdentified
  2340. WBUFB(buf,n+30+offset) |= (it->attribute) ? 0x2 : 0; //0x2 IsDamaged
  2341. WBUFB(buf,n+30+offset) |= (it->favorite) ? 0x4 : 0; //0x4 PlaceETCTab
  2342. }
  2343. else { //normal 24B
  2344. WBUFW(buf,n+5) = it->amount;
  2345. WBUFL(buf,n+7) = (equip == -2 && id->equip == EQP_AMMO)?id->equip:0; //wear state
  2346. clif_addcards(WBUFP(buf, n+11), it); //EQUIPSLOTINFO 8B
  2347. WBUFL(buf,n+19) = it->expire_time;
  2348. //V5_ITEM_flag
  2349. WBUFB(buf,n+23) = it->identify; //0x1 IsIdentified
  2350. WBUFB(buf,n+23) |= (it->favorite) ? 0x2 : 0; //0x4,0x2 PlaceETCTab
  2351. }
  2352. }
  2353. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2354. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2355. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2356. void clif_item_sub(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2357. #if PACKETVER >= 20120925
  2358. clif_item_sub_v5(buf, n, idx, it, id, equip);
  2359. #else
  2360. WBUFW(buf,n) = idx; //index
  2361. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid; //itid
  2362. WBUFB(buf,n+4) = itemtype(id->nameid);
  2363. WBUFB(buf,n+5) = it->identify;
  2364. if (equip >= 0) { //Equippable item 28.B
  2365. WBUFW(buf,n+6) = equip;
  2366. WBUFW(buf,n+8) = it->equip;
  2367. WBUFB(buf,n+10) = it->attribute;
  2368. WBUFB(buf,n+11) = it->refine;
  2369. clif_addcards(WBUFP(buf, n+12), it); //8B
  2370. #if PACKETVER >= 20071002
  2371. WBUFL(buf,n+20) = it->expire_time;
  2372. WBUFW(buf,n+24) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0;
  2373. #endif
  2374. #if PACKETVER >= 20100629
  2375. WBUFW(buf,n+26) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2376. #endif
  2377. } else { //Stackable item. 22.B
  2378. WBUFW(buf,n+6) = it->amount;
  2379. WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2380. clif_addcards(WBUFP(buf, n+10), it); //8B
  2381. #if PACKETVER >= 20071002
  2382. WBUFL(buf,n+18) = it->expire_time;
  2383. #endif
  2384. }
  2385. #endif
  2386. }
  2387. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2388. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2389. void clif_inventorylist(struct map_session_data *sd) {
  2390. int i,n,ne,arrow=-1;
  2391. unsigned char *buf;
  2392. unsigned char *bufe;
  2393. #if PACKETVER < 5
  2394. const int s = 10; //Entry size
  2395. #elif PACKETVER < 20080102
  2396. const int s = 18;
  2397. #elif PACKETVER < 20120925
  2398. const int s = 22;
  2399. #else
  2400. const int s = 24;
  2401. #endif
  2402. #if PACKETVER < 20071002
  2403. const int se = 20;
  2404. #elif PACKETVER < 20100629
  2405. const int se = 26;
  2406. #elif PACKETVER < 20120925
  2407. const int se = 28;
  2408. #elif PACKETVER < 20150225
  2409. const int se = 31;
  2410. #else
  2411. const int se = 57;
  2412. #endif
  2413. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2414. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2415. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2416. {
  2417. if( sd->inventory.u.items_inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2418. continue;
  2419. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2420. { //Non-stackable (Equippable)
  2421. clif_item_sub(bufe, ne*se+4, i+2, &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2422. ne++;
  2423. }
  2424. else { //Stackable.
  2425. clif_item_sub(buf, n*s+4,i+2, &sd->inventory.u.items_inventory[i], sd->inventory_data[i], -2);
  2426. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->inventory.u.items_inventory[i].equip )
  2427. arrow=i;
  2428. n++;
  2429. }
  2430. }
  2431. if( n )
  2432. {
  2433. #if PACKETVER < 5
  2434. WBUFW(buf,0)=0xa3;
  2435. #elif PACKETVER < 20080102
  2436. WBUFW(buf,0)=0x1ee;
  2437. #elif PACKETVER < 20120925
  2438. WBUFW(buf,0)=0x2e8;
  2439. #else
  2440. WBUFW(buf,0)=0x991;
  2441. #endif
  2442. WBUFW(buf,2)=4+n*s;
  2443. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2444. }
  2445. if( arrow >= 0 )
  2446. clif_arrowequip(sd,arrow);
  2447. if( ne ) {
  2448. #if PACKETVER < 20071002
  2449. WBUFW(bufe,0)=0xa4;
  2450. #elif PACKETVER < 20120925
  2451. WBUFW(bufe,0)=0x2d0;
  2452. #elif PACKETVER < 20150225
  2453. WBUFW(bufe,0)=0x992;
  2454. #else
  2455. WBUFW(bufe,0)=0xa0d;
  2456. #endif
  2457. WBUFW(bufe,2)=4+ne*se;
  2458. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2459. }
  2460. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2461. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2462. if( sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2463. continue;
  2464. if ( sd->inventory.u.items_inventory[i].favorite )
  2465. clif_favorite_item(sd, i);
  2466. }
  2467. #endif
  2468. if( buf ) aFree(buf);
  2469. if( bufe ) aFree(bufe);
  2470. }
  2471. //Required when items break/get-repaired. Only sends equippable item list.
  2472. void clif_equiplist(struct map_session_data *sd)
  2473. {
  2474. int i,n,fd = sd->fd;
  2475. unsigned char *buf;
  2476. #if PACKETVER < 20071002
  2477. const int cmd = 20;
  2478. #elif PACKETVER < 20100629
  2479. const int cmd = 26;
  2480. #elif PACKETVER < 20120925
  2481. const int cmd = 28;
  2482. #elif PACKETVER < 20150225
  2483. const int cmd = 31;
  2484. #else
  2485. const int cmd = 57;
  2486. #endif
  2487. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2488. buf = WFIFOP(fd,0);
  2489. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2490. if (sd->inventory.u.items_inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2491. continue;
  2492. if(itemdb_isstackable2(sd->inventory_data[i]))
  2493. continue;
  2494. //Equippable
  2495. clif_item_sub(buf, n*cmd+4,i+2, &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2496. n++;
  2497. }
  2498. if (n) {
  2499. #if PACKETVER < 20071002
  2500. WBUFW(buf,0)=0xa4;
  2501. #elif PACKETVER < 20120925
  2502. WBUFW(buf,0)=0x2d0;
  2503. #elif PACKETVER < 20150225
  2504. WBUFW(buf,0)=0x992;
  2505. #else
  2506. WBUFW(buf,0)=0xa0d;
  2507. #endif
  2508. WBUFW(buf,2)=4+n*cmd;
  2509. WFIFOSET(fd,WFIFOW(fd,2));
  2510. }
  2511. }
  2512. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length, const char *storename)
  2513. {
  2514. static const int client_buf = 0x5000; // Max buffer to send
  2515. struct item_data *id;
  2516. int i,n,ne,nn;
  2517. unsigned char *buf;
  2518. unsigned char *bufe;
  2519. #if PACKETVER < 5
  2520. const int s = 10; //Entry size.normal item
  2521. const int sidx=4; //start itemlist idx
  2522. const int cmd = 0xa5;
  2523. #elif PACKETVER < 20080102
  2524. const int s = 18;
  2525. const int sidx=4;
  2526. const int cmd = 0x1f0;
  2527. #elif PACKETVER < 20120925
  2528. const int s = 22;
  2529. const int sidx=4;
  2530. const int cmd = 0x2ea;
  2531. #else
  2532. const int s = 24;
  2533. const int sidx = 4+24;
  2534. const int cmd = 0x995;
  2535. #endif
  2536. #if PACKETVER < 20071002
  2537. const int se = 20; //entry size equip
  2538. const int sidxe = 4; //start itemlist idx
  2539. const int cmde = 0xa6;
  2540. #elif PACKETVER < 20100629
  2541. const int se = 26;
  2542. const int sidxe = 4;
  2543. const int cmde = 0x2d1;
  2544. #elif PACKETVER < 20120925
  2545. const int se = 28;
  2546. const int sidxe = 4;
  2547. const int cmde = 0x2d1;
  2548. #elif PACKETVER < 20150225
  2549. const int se = 31;
  2550. const int sidxe = 4+24;
  2551. const int cmde = 0x996;
  2552. #else
  2553. const int se = 57;
  2554. const int sidxe = 4+24;
  2555. const int cmde = 0xa10;
  2556. #endif
  2557. buf = (unsigned char*)aMalloc(items_length * s + sidx);
  2558. bufe = (unsigned char*)aMalloc(items_length * se + sidxe);
  2559. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2560. {
  2561. if( items[i].nameid <= 0 )
  2562. continue;
  2563. id = itemdb_search(items[i].nameid);
  2564. if( !itemdb_isstackable2(id) ) { //Equippable
  2565. clif_item_sub(bufe, ne*se+sidxe,i+1, &items[i], id, id->equip);
  2566. ne++;
  2567. }
  2568. else { //Stackable
  2569. clif_item_sub(buf, n*s+sidx,i+1, &items[i], id,-1);
  2570. n++;
  2571. }
  2572. }
  2573. for (i = 0; i < n; i += nn) // Loop through non-equipable items
  2574. {
  2575. nn = n - i < (client_buf - sidx)/s ? n - i : (client_buf - sidx)/s; // Split up non-equipable items
  2576. WFIFOHEAD(sd->fd,sidx+nn*s);
  2577. WFIFOW(sd->fd,0)=cmd;
  2578. WFIFOW(sd->fd,2)=sidx+nn*s;
  2579. #if PACKETVER >= 20120925
  2580. safestrncpy(WFIFOCP(sd->fd,4), storename, NAME_LENGTH); //storename
  2581. #endif
  2582. memcpy(WFIFOP(sd->fd,sidx),buf + sidx + i*s,nn*s);
  2583. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2584. }
  2585. for (i = 0; i < ne; i += nn) // Loop through equipable items
  2586. {
  2587. nn = ne - i < (client_buf - sidxe)/se ? ne - i : (client_buf - sidxe)/se; // Split up equipable items
  2588. WFIFOHEAD(sd->fd,sidxe+nn*se);
  2589. WFIFOW(sd->fd,0)=cmde;
  2590. WFIFOW(sd->fd,2)=sidxe+nn*se;
  2591. #if PACKETVER >= 20120925
  2592. safestrncpy(WFIFOCP(sd->fd,4), storename, NAME_LENGTH); //storename
  2593. #endif
  2594. memcpy(WFIFOP(sd->fd,sidxe),bufe + sidxe + i*se,nn*se);
  2595. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2596. }
  2597. // Empty storage
  2598. if (n == 0 && ne == 0) {
  2599. WFIFOHEAD(sd->fd, 4+NAME_LENGTH);
  2600. WFIFOW(sd->fd,0) = cmd;
  2601. WFIFOW(sd->fd,2) = 4+NAME_LENGTH;
  2602. #if PACKETVER >= 20120925
  2603. safestrncpy(WFIFOCP(sd->fd,4), storename, NAME_LENGTH); //storename
  2604. #endif
  2605. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2606. }
  2607. if( buf ) aFree(buf);
  2608. if( bufe ) aFree(bufe);
  2609. }
  2610. void clif_cartlist(struct map_session_data *sd)
  2611. {
  2612. struct item_data *id;
  2613. int i,n,ne;
  2614. unsigned char *buf;
  2615. unsigned char *bufe;
  2616. #if PACKETVER < 5
  2617. const int s = 10; //Entry size.
  2618. #elif PACKETVER < 20080102
  2619. const int s = 18;
  2620. #elif PACKETVER < 20120925
  2621. const int s = 22;
  2622. #else
  2623. const int s = 24;
  2624. #endif
  2625. #if PACKETVER < 20071002
  2626. const int cmd = 20;
  2627. #elif PACKETVER < 20100629
  2628. const int cmd = 26;
  2629. #elif PACKETVER < 20120925
  2630. const int cmd = 28;
  2631. #elif PACKETVER < 20150225
  2632. const int cmd = 31;
  2633. #else
  2634. const int cmd = 57;
  2635. #endif
  2636. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2637. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2638. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2639. {
  2640. if( sd->cart.u.items_cart[i].nameid <= 0 )
  2641. continue;
  2642. id = itemdb_search(sd->cart.u.items_cart[i].nameid);
  2643. if( !itemdb_isstackable2(id) ) { //Equippable
  2644. clif_item_sub(bufe, ne*cmd+4,i+2, &sd->cart.u.items_cart[i], id, id->equip);
  2645. ne++;
  2646. }
  2647. else { //Stackable
  2648. clif_item_sub(buf, n*s+4,i+2, &sd->cart.u.items_cart[i], id,-1);
  2649. n++;
  2650. }
  2651. }
  2652. if( n )
  2653. {
  2654. #if PACKETVER < 5
  2655. WBUFW(buf,0)=0x123;
  2656. #elif PACKETVER < 20080102
  2657. WBUFW(buf,0)=0x1ef;
  2658. #elif PACKETVER < 20120925
  2659. WBUFW(buf,0)=0x2e9;
  2660. #else
  2661. WBUFW(buf,0)=0x993;
  2662. #endif
  2663. WBUFW(buf,2)=4+n*s;
  2664. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2665. }
  2666. if( ne )
  2667. {
  2668. #if PACKETVER < 20071002
  2669. WBUFW(bufe,0)=0x122;
  2670. #elif PACKETVER < 20120925
  2671. WBUFW(bufe,0)=0x2d2;
  2672. #elif PACKETVER < 20150225
  2673. WBUFW(bufe,0)=0x994;
  2674. #else
  2675. WBUFW(bufe,0)=0xa0f;
  2676. #endif
  2677. WBUFW(bufe,2)=4+ne*cmd;
  2678. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2679. }
  2680. if( buf ) aFree(buf);
  2681. if( bufe ) aFree(bufe);
  2682. }
  2683. /// Removes cart (ZC_CARTOFF).
  2684. /// 012b
  2685. /// Client behaviour:
  2686. /// Closes the cart storage and removes all it's items from memory.
  2687. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2688. void clif_clearcart(int fd)
  2689. {
  2690. WFIFOHEAD(fd, packet_len(0x12b));
  2691. WFIFOW(fd,0) = 0x12b;
  2692. WFIFOSET(fd, packet_len(0x12b));
  2693. }
  2694. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2695. /// 01eb <account id>.L <x>.W <y>.W
  2696. void clif_guild_xy(struct map_session_data *sd)
  2697. {
  2698. unsigned char buf[10];
  2699. nullpo_retv(sd);
  2700. WBUFW(buf,0)=0x1eb;
  2701. WBUFL(buf,2)=sd->status.account_id;
  2702. WBUFW(buf,6)=sd->bl.x;
  2703. WBUFW(buf,8)=sd->bl.y;
  2704. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2705. }
  2706. /*==========================================
  2707. * Sends x/y dot to a single fd. [Skotlex]
  2708. *------------------------------------------*/
  2709. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2710. {
  2711. if( sd->bg_id )
  2712. return;
  2713. WFIFOHEAD(fd,packet_len(0x1eb));
  2714. WFIFOW(fd,0)=0x1eb;
  2715. WFIFOL(fd,2)=sd->status.account_id;
  2716. WFIFOW(fd,6)=sd->bl.x;
  2717. WFIFOW(fd,8)=sd->bl.y;
  2718. WFIFOSET(fd,packet_len(0x1eb));
  2719. }
  2720. // Guild XY locators [Valaris]
  2721. void clif_guild_xy_remove(struct map_session_data *sd)
  2722. {
  2723. unsigned char buf[10];
  2724. nullpo_retv(sd);
  2725. WBUFW(buf,0)=0x1eb;
  2726. WBUFL(buf,2)=sd->status.account_id;
  2727. WBUFW(buf,6)=-1;
  2728. WBUFW(buf,8)=-1;
  2729. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2730. }
  2731. /*==========================================
  2732. *
  2733. *------------------------------------------*/
  2734. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2735. {
  2736. struct map_session_data *sd, *tsd;
  2737. #if PACKETVER < 20100126
  2738. const int cmd = 0x106;
  2739. #else
  2740. const int cmd = 0x80e;
  2741. #endif
  2742. sd = va_arg(ap, struct map_session_data *);
  2743. tsd = (TBL_PC *)bl;
  2744. nullpo_ret(sd);
  2745. nullpo_ret(tsd);
  2746. if( !tsd->fd || tsd == sd )
  2747. return 0;
  2748. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2749. return 0;
  2750. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2751. WFIFOW(tsd->fd,0) = cmd;
  2752. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2753. #if PACKETVER < 20100126
  2754. if( sd->battle_status.max_hp > INT16_MAX )
  2755. { //To correctly display the %hp bar. [Skotlex]
  2756. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2757. WFIFOW(tsd->fd,8) = 100;
  2758. } else {
  2759. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2760. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2761. }
  2762. #else
  2763. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2764. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2765. #endif
  2766. WFIFOSET(tsd->fd,packet_len(cmd));
  2767. return 0;
  2768. }
  2769. /*==========================================
  2770. * Server tells all players that are allowed to view HP bars
  2771. * and are nearby 'sd' that 'sd' hp bar was updated.
  2772. *------------------------------------------*/
  2773. static int clif_hpmeter(struct map_session_data *sd)
  2774. {
  2775. nullpo_ret(sd);
  2776. 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);
  2777. return 0;
  2778. }
  2779. /// Notifies client of a character parameter change.
  2780. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2781. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2782. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2783. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2784. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2785. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2786. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2787. /// TODO: Extract individual packets.
  2788. /// FIXME: Packet lengths from packet_len(cmd)
  2789. void clif_updatestatus(struct map_session_data *sd,int type)
  2790. {
  2791. int fd,len=8;
  2792. nullpo_retv(sd);
  2793. fd=sd->fd;
  2794. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2795. return;
  2796. WFIFOHEAD(fd, 14);
  2797. WFIFOW(fd,0)=0xb0;
  2798. WFIFOW(fd,2)=type;
  2799. switch(type){
  2800. // 00b0
  2801. case SP_WEIGHT:
  2802. pc_updateweightstatus(sd);
  2803. WFIFOHEAD(fd,14);
  2804. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2805. WFIFOW(fd,2)=type;
  2806. WFIFOL(fd,4)=sd->weight;
  2807. break;
  2808. case SP_MAXWEIGHT:
  2809. WFIFOL(fd,4)=sd->max_weight;
  2810. break;
  2811. case SP_SPEED:
  2812. WFIFOL(fd,4)=sd->battle_status.speed;
  2813. break;
  2814. case SP_BASELEVEL:
  2815. WFIFOL(fd,4)=sd->status.base_level;
  2816. break;
  2817. case SP_JOBLEVEL:
  2818. WFIFOL(fd,4)=sd->status.job_level;
  2819. break;
  2820. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2821. WFIFOL(fd,4)=sd->status.karma;
  2822. break;
  2823. case SP_MANNER:
  2824. WFIFOL(fd,4)=sd->status.manner;
  2825. break;
  2826. case SP_STATUSPOINT:
  2827. WFIFOL(fd,4)=sd->status.status_point;
  2828. break;
  2829. case SP_SKILLPOINT:
  2830. WFIFOL(fd,4)=sd->status.skill_point;
  2831. break;
  2832. case SP_HIT:
  2833. WFIFOL(fd,4)=sd->battle_status.hit;
  2834. break;
  2835. case SP_FLEE1:
  2836. WFIFOL(fd,4)=sd->battle_status.flee;
  2837. break;
  2838. case SP_FLEE2:
  2839. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2840. break;
  2841. case SP_MAXHP:
  2842. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2843. break;
  2844. case SP_MAXSP:
  2845. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2846. break;
  2847. case SP_HP:
  2848. // On officials the HP never go below 1, even if you die [Lemongrass]
  2849. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2850. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2851. break;
  2852. case SP_SP:
  2853. WFIFOL(fd,4)=sd->battle_status.sp;
  2854. break;
  2855. case SP_ASPD:
  2856. WFIFOL(fd,4)=sd->battle_status.amotion;
  2857. break;
  2858. case SP_ATK1:
  2859. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2860. break;
  2861. case SP_DEF1:
  2862. WFIFOL(fd,4)=pc_leftside_def(sd);
  2863. break;
  2864. case SP_MDEF1:
  2865. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2866. break;
  2867. case SP_ATK2:
  2868. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2869. break;
  2870. case SP_DEF2:
  2871. WFIFOL(fd,4)=pc_rightside_def(sd);
  2872. break;
  2873. case SP_MDEF2: {
  2874. //negative check (in case you have something like Berserk active)
  2875. int mdef2 = pc_rightside_mdef(sd);
  2876. WFIFOL(fd,4)=
  2877. #ifndef RENEWAL
  2878. ( mdef2 < 0 ) ? 0 :
  2879. #endif
  2880. mdef2;
  2881. }
  2882. break;
  2883. case SP_CRITICAL:
  2884. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2885. break;
  2886. case SP_MATK1:
  2887. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2888. break;
  2889. case SP_MATK2:
  2890. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2891. break;
  2892. case SP_ZENY:
  2893. WFIFOW(fd,0)=0xb1;
  2894. WFIFOL(fd,4)=sd->status.zeny;
  2895. break;
  2896. #if PACKETVER >= 20170830
  2897. case SP_BASEEXP:
  2898. WFIFOW(fd,0)=0xacb;
  2899. WFIFOQ(fd,4)=sd->status.base_exp;
  2900. len = packet_len(0xacb);
  2901. break;
  2902. case SP_JOBEXP:
  2903. WFIFOW(fd,0)=0xacb;
  2904. WFIFOQ(fd,4)=sd->status.job_exp;
  2905. len = packet_len(0xacb);
  2906. break;
  2907. case SP_NEXTBASEEXP:
  2908. WFIFOW(fd,0)=0xacb;
  2909. WFIFOQ(fd,4)=pc_nextbaseexp(sd);
  2910. len = packet_len(0xacb);
  2911. break;
  2912. case SP_NEXTJOBEXP:
  2913. WFIFOW(fd,0)=0xacb;
  2914. WFIFOQ(fd,4)=pc_nextjobexp(sd);
  2915. len = packet_len(0xacb);
  2916. break;
  2917. #else
  2918. case SP_BASEEXP:
  2919. WFIFOW(fd,0)=0xb1;
  2920. WFIFOL(fd,4)=sd->status.base_exp;
  2921. break;
  2922. case SP_JOBEXP:
  2923. WFIFOW(fd,0)=0xb1;
  2924. WFIFOL(fd,4)=sd->status.job_exp;
  2925. break;
  2926. case SP_NEXTBASEEXP:
  2927. WFIFOW(fd,0)=0xb1;
  2928. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2929. break;
  2930. case SP_NEXTJOBEXP:
  2931. WFIFOW(fd,0)=0xb1;
  2932. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2933. break;
  2934. #endif
  2935. /**
  2936. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2937. **/
  2938. case SP_USTR:
  2939. case SP_UAGI:
  2940. case SP_UVIT:
  2941. case SP_UINT:
  2942. case SP_UDEX:
  2943. case SP_ULUK:
  2944. WFIFOW(fd,0)=0xbe;
  2945. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2946. len=5;
  2947. break;
  2948. /**
  2949. * Tells the client how far it is allowed to attack (weapon range)
  2950. **/
  2951. case SP_ATTACKRANGE:
  2952. WFIFOW(fd,0)=0x13a;
  2953. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2954. len=4;
  2955. break;
  2956. case SP_STR:
  2957. WFIFOW(fd,0)=0x141;
  2958. WFIFOL(fd,2)=type;
  2959. WFIFOL(fd,6)=sd->status.str;
  2960. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2961. len=14;
  2962. break;
  2963. case SP_AGI:
  2964. WFIFOW(fd,0)=0x141;
  2965. WFIFOL(fd,2)=type;
  2966. WFIFOL(fd,6)=sd->status.agi;
  2967. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2968. len=14;
  2969. break;
  2970. case SP_VIT:
  2971. WFIFOW(fd,0)=0x141;
  2972. WFIFOL(fd,2)=type;
  2973. WFIFOL(fd,6)=sd->status.vit;
  2974. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2975. len=14;
  2976. break;
  2977. case SP_INT:
  2978. WFIFOW(fd,0)=0x141;
  2979. WFIFOL(fd,2)=type;
  2980. WFIFOL(fd,6)=sd->status.int_;
  2981. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2982. len=14;
  2983. break;
  2984. case SP_DEX:
  2985. WFIFOW(fd,0)=0x141;
  2986. WFIFOL(fd,2)=type;
  2987. WFIFOL(fd,6)=sd->status.dex;
  2988. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2989. len=14;
  2990. break;
  2991. case SP_LUK:
  2992. WFIFOW(fd,0)=0x141;
  2993. WFIFOL(fd,2)=type;
  2994. WFIFOL(fd,6)=sd->status.luk;
  2995. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2996. len=14;
  2997. break;
  2998. case SP_CARTINFO:
  2999. WFIFOW(fd,0)=0x121;
  3000. WFIFOW(fd,2)=sd->cart_num;
  3001. WFIFOW(fd,4)=MAX_CART;
  3002. WFIFOL(fd,6)=sd->cart_weight;
  3003. WFIFOL(fd,10)=sd->cart_weight_max;
  3004. len=14;
  3005. break;
  3006. default:
  3007. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3008. return;
  3009. }
  3010. WFIFOSET(fd,len);
  3011. // Additional update packets that should be sent right after
  3012. switch( type ){
  3013. case SP_BASELEVEL:
  3014. if( sd->status.party_id ){
  3015. struct party_data* p;
  3016. int i;
  3017. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3018. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3019. if( i < MAX_PARTY ){
  3020. p->party.member[i].lv = sd->status.base_level;
  3021. clif_party_job_and_level(sd);
  3022. }
  3023. }
  3024. }
  3025. break;
  3026. case SP_HP:
  3027. if( map_getmapdata(sd->bl.m)->hpmeter_visible ){
  3028. clif_hpmeter(sd);
  3029. }
  3030. if( !battle_config.party_hp_mode && sd->status.party_id ){
  3031. clif_party_hp(sd);
  3032. }
  3033. if( sd->bg_id ){
  3034. clif_bg_hp(sd);
  3035. }
  3036. break;
  3037. }
  3038. }
  3039. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3040. /// 01ab <account id>.L <var id>.W <value>.L
  3041. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3042. {
  3043. unsigned char buf[12];
  3044. nullpo_retv(sd);
  3045. WBUFW(buf,0)=0x1ab;
  3046. WBUFL(buf,2)=sd->bl.id;
  3047. WBUFW(buf,6)=type;
  3048. switch(type)
  3049. {
  3050. case SP_MANNER:
  3051. WBUFL(buf,8)=val;
  3052. break;
  3053. default:
  3054. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3055. return;
  3056. }
  3057. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3058. }
  3059. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3060. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  3061. void clif_sprite_change(struct block_list *bl, int id, int type, int val, int val2, enum send_target target) {
  3062. unsigned char buf[32];
  3063. #if PACKETVER < 4
  3064. const int cmd = 0xc3;
  3065. #else
  3066. const int cmd = 0x1d7;
  3067. #endif
  3068. WBUFW(buf,0) = cmd;
  3069. WBUFL(buf,2) = id;
  3070. WBUFB(buf,6) = type;
  3071. WBUFW(buf,7) = val;
  3072. #if PACKETVER >= 4
  3073. WBUFW(buf,9) = val2;
  3074. #endif
  3075. clif_send(buf,packet_len(cmd), bl, target);
  3076. }
  3077. /// Updates sprite/style properties of an object.
  3078. void clif_changelook(struct block_list *bl, int type, int val) {
  3079. struct map_session_data* sd;
  3080. struct status_change* sc;
  3081. struct view_data* vd;
  3082. enum send_target target = AREA;
  3083. int val2 = 0;
  3084. nullpo_retv(bl);
  3085. sd = BL_CAST(BL_PC, bl);
  3086. sc = status_get_sc(bl);
  3087. vd = status_get_viewdata(bl);
  3088. if( vd ) //temp hack to let Warp Portal change appearance
  3089. switch(type) {
  3090. case LOOK_WEAPON:
  3091. if (sd) {
  3092. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3093. val = vd->weapon;
  3094. }
  3095. else
  3096. vd->weapon = val;
  3097. break;
  3098. case LOOK_SHIELD:
  3099. if (sd) {
  3100. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3101. val = vd->shield;
  3102. }
  3103. else
  3104. vd->shield = val;
  3105. break;
  3106. case LOOK_BASE:
  3107. if (!sd)
  3108. break;
  3109. if ( val == JT_INVISIBLE )
  3110. return;
  3111. if (sd->sc.option&OPTION_COSTUME)
  3112. vd->weapon = vd->shield = 0;
  3113. if (!vd->cloth_color)
  3114. break;
  3115. if (sd) {
  3116. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3117. vd->cloth_color = 0;
  3118. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3119. vd->cloth_color = 0;
  3120. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3121. vd->cloth_color = 0;
  3122. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3123. vd->cloth_color = 0;
  3124. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3125. vd->cloth_color = 0;
  3126. if (vd->body_style && sd->sc.option&OPTION_COSTUME)
  3127. vd->body_style = 0;
  3128. }
  3129. break;
  3130. case LOOK_HAIR:
  3131. vd->hair_style = val;
  3132. break;
  3133. case LOOK_HEAD_BOTTOM:
  3134. vd->head_bottom = val;
  3135. break;
  3136. case LOOK_HEAD_TOP:
  3137. vd->head_top = val;
  3138. break;
  3139. case LOOK_HEAD_MID:
  3140. vd->head_mid = val;
  3141. break;
  3142. case LOOK_HAIR_COLOR:
  3143. vd->hair_color = val;
  3144. break;
  3145. case LOOK_CLOTHES_COLOR:
  3146. if (val && sd) {
  3147. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3148. val = 0;
  3149. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3150. val = 0;
  3151. if (sd->sc.option&(OPTION_SUMMER|OPTION_SUMMER2) && battle_config.summer_ignorepalette)
  3152. val = 0;
  3153. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3154. val = 0;
  3155. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3156. val = 0;
  3157. }
  3158. vd->cloth_color = val;
  3159. break;
  3160. case LOOK_SHOES:
  3161. #if PACKETVER > 3
  3162. if (sd) {
  3163. int n;
  3164. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  3165. if(sd->inventory_data[n]->view_id > 0)
  3166. val = sd->inventory_data[n]->view_id;
  3167. else
  3168. val = sd->inventory.u.items_inventory[n].nameid;
  3169. } else
  3170. val = 0;
  3171. }
  3172. #endif
  3173. //Shoes? No packet uses this....
  3174. break;
  3175. case LOOK_BODY:
  3176. // unknown purpose
  3177. break;
  3178. case LOOK_ROBE:
  3179. #if PACKETVER < 20110111
  3180. return;
  3181. #else
  3182. vd->robe = val;
  3183. #endif
  3184. break;
  3185. case LOOK_BODY2:
  3186. #if PACKETVER < 20150513
  3187. return;
  3188. #else
  3189. if (val && sd->sc.option&OPTION_COSTUME)
  3190. val = 0;
  3191. vd->body_style = val;
  3192. #endif
  3193. break;
  3194. }
  3195. // prevent leaking the presence of GM-hidden objects
  3196. if( sc && sc->option&OPTION_INVISIBLE )
  3197. target = SELF;
  3198. #if PACKETVER < 4
  3199. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3200. #else
  3201. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3202. nullpo_retv(vd);
  3203. type = LOOK_WEAPON;
  3204. val = vd->weapon;
  3205. val2 = vd->shield;
  3206. }
  3207. if( disguised(bl) ) {
  3208. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3209. clif_sprite_change(bl, -bl->id, type, val, val2, SELF);
  3210. } else
  3211. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3212. #endif
  3213. }
  3214. //Sends a change-base-look packet required for traps as they are triggered.
  3215. void clif_changetraplook(struct block_list *bl,int val) {
  3216. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3217. }
  3218. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3219. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3220. clif_sprite_change(bl, id, type, val, 0, target);
  3221. }
  3222. /// Character status (ZC_STATUS).
  3223. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3224. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3225. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3226. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3227. void clif_initialstatus(struct map_session_data *sd) {
  3228. int fd, mdef2;
  3229. unsigned char *buf;
  3230. nullpo_retv(sd);
  3231. fd=sd->fd;
  3232. WFIFOHEAD(fd, packet_len(0xbd));
  3233. buf = WFIFOP(fd,0);
  3234. WBUFW(buf,0) = 0xbd;
  3235. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3236. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3237. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3238. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3239. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3240. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3241. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3242. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3243. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3244. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3245. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3246. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3247. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3248. WBUFW(buf,16) = pc_leftside_atk(sd);
  3249. WBUFW(buf,18) = pc_rightside_atk(sd);
  3250. WBUFW(buf,20) = pc_rightside_matk(sd);
  3251. WBUFW(buf,22) = pc_leftside_matk(sd);
  3252. WBUFW(buf,24) = pc_leftside_def(sd);
  3253. WBUFW(buf,26) = pc_rightside_def(sd);
  3254. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3255. mdef2 = pc_rightside_mdef(sd);
  3256. WBUFW(buf,30) =
  3257. #ifndef RENEWAL
  3258. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3259. #endif
  3260. mdef2;
  3261. WBUFW(buf,32) = sd->battle_status.hit;
  3262. WBUFW(buf,34) = sd->battle_status.flee;
  3263. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3264. WBUFW(buf,38) = sd->battle_status.cri/10;
  3265. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3266. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3267. WFIFOSET(fd, packet_len(0xbd));
  3268. clif_updatestatus(sd, SP_STR);
  3269. clif_updatestatus(sd, SP_AGI);
  3270. clif_updatestatus(sd, SP_VIT);
  3271. clif_updatestatus(sd, SP_INT);
  3272. clif_updatestatus(sd, SP_DEX);
  3273. clif_updatestatus(sd, SP_LUK);
  3274. clif_updatestatus(sd, SP_ATTACKRANGE);
  3275. clif_updatestatus(sd, SP_ASPD);
  3276. }
  3277. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3278. /// 013c <index>.W
  3279. void clif_arrowequip(struct map_session_data *sd,int val) {
  3280. int fd;
  3281. nullpo_retv(sd);
  3282. #if PACKETVER >= 20121128
  3283. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INVALID_TIMER, 0, 0, 0);
  3284. #endif
  3285. fd=sd->fd;
  3286. WFIFOHEAD(fd, packet_len(0x013c));
  3287. WFIFOW(fd,0) = 0x013c;
  3288. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3289. WFIFOSET(fd, packet_len(0x013c));
  3290. }
  3291. /// Ammunition action message (ZC_ACTION_FAILURE).
  3292. /// 013b <type>.W
  3293. /// type:
  3294. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3295. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3296. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3297. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3298. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3299. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3300. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3301. int fd;
  3302. nullpo_retv(sd);
  3303. fd=sd->fd;
  3304. WFIFOHEAD(fd, packet_len(0x013b));
  3305. WFIFOW(fd,0) = 0x013b;
  3306. WFIFOW(fd,2) = type;
  3307. WFIFOSET(fd, packet_len(0x013b));
  3308. }
  3309. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3310. /// 01ad <packet len>.W { <name id>.W }*
  3311. void clif_arrow_create_list(struct map_session_data *sd)
  3312. {
  3313. int i, c;
  3314. int fd;
  3315. nullpo_retv(sd);
  3316. fd = sd->fd;
  3317. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  3318. WFIFOW(fd,0) = 0x1ad;
  3319. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  3320. short j, nameid = skill_arrow_db[i].nameid;
  3321. if (nameid > 0 && itemdb_exists(nameid) &&
  3322. (j = pc_search_inventory(sd, nameid)) >= 0 &&
  3323. !sd->inventory.u.items_inventory[j].equip && sd->inventory.u.items_inventory[j].identify)
  3324. {
  3325. if ((j = itemdb_viewid(nameid)) > 0)
  3326. WFIFOW(fd,c*2+4) = j;
  3327. else
  3328. WFIFOW(fd,c*2+4) = nameid;
  3329. c++;
  3330. }
  3331. }
  3332. WFIFOW(fd,2) = c*2+4;
  3333. WFIFOSET(fd, WFIFOW(fd,2));
  3334. if (c > 0) {
  3335. sd->menuskill_id = AC_MAKINGARROW;
  3336. sd->menuskill_val = c;
  3337. }
  3338. }
  3339. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3340. /// 00bc <status id>.W <result>.B <value>.B
  3341. /// status id:
  3342. /// SP_STR ~ SP_LUK
  3343. /// result:
  3344. /// 0 = failure
  3345. /// 1 = success
  3346. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3347. int fd;
  3348. nullpo_retv(sd);
  3349. fd=sd->fd;
  3350. WFIFOHEAD(fd, packet_len(0xbc));
  3351. WFIFOW(fd,0) = 0xbc;
  3352. WFIFOW(fd,2) = type;
  3353. WFIFOB(fd,4) = ok;
  3354. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3355. WFIFOSET(fd, packet_len(0xbc));
  3356. }
  3357. /// Notifies the client about the result of a request to equip an item.
  3358. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3359. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3360. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3361. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3362. /// @ok: //inversed forv2 v5
  3363. /// 0 = failure
  3364. /// 1 = success
  3365. /// 2 = failure due to low level
  3366. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3367. {
  3368. int fd = 0, cmd = 0, look = 0;
  3369. struct s_packet_db *info = NULL;
  3370. nullpo_retv(sd);
  3371. cmd = packet_db_ack[ZC_WEAR_EQUIP_ACK];
  3372. if (!cmd || !(info = &packet_db[cmd]) || !info->len)
  3373. return;
  3374. fd = sd->fd;
  3375. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3376. look = sd->inventory_data[n]->look;
  3377. WFIFOHEAD(fd, info->len);
  3378. WFIFOW(fd, 0) = cmd;
  3379. WFIFOW(fd, info->pos[0]) = n+2;
  3380. switch (cmd) {
  3381. case 0xaa:
  3382. WFIFOW(fd, info->pos[1]) = pos;
  3383. #if PACKETVER < 20100629
  3384. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3385. #else
  3386. WFIFOL(fd, info->pos[2]) = look;
  3387. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3388. #endif
  3389. break;
  3390. case 0x8d0:
  3391. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3392. flag = 1;
  3393. case 0x999:
  3394. if (cmd == 0x999)
  3395. WFIFOL(fd, info->pos[1]) = pos;
  3396. else
  3397. WFIFOW(fd, info->pos[1]) = pos;
  3398. WFIFOL(fd, info->pos[2]) = look;
  3399. WFIFOW(fd, info->pos[3]) = flag;
  3400. break;
  3401. }
  3402. WFIFOSET(fd, info->len);
  3403. }
  3404. /// Notifies the client about the result of a request to take off an item.
  3405. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3406. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3407. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3408. /// @ok : //inversed for v2 v5
  3409. /// 0 = failure
  3410. /// 1 = success
  3411. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3412. {
  3413. int fd, header, offs = 0;
  3414. #if PACKETVER >= 20130000
  3415. header = 0x99a;
  3416. ok = ok ? 0 : 1;
  3417. #elif PACKETVER >= 20110824
  3418. header = 0x8d1;
  3419. ok = ok ? 0 : 1;
  3420. #else
  3421. header = 0xac;
  3422. #endif
  3423. nullpo_retv(sd);
  3424. fd=sd->fd;
  3425. WFIFOHEAD(fd, packet_len(header));
  3426. WFIFOW(fd,offs+0) = header;
  3427. WFIFOW(fd,offs+2) = n+2;
  3428. #if PACKETVER >= 20130000
  3429. WFIFOL(fd,offs+4) = pos;
  3430. offs += 2;
  3431. #else
  3432. WFIFOW(fd,offs+4) = pos;
  3433. #endif
  3434. WFIFOB(fd,offs+6) = ok;
  3435. WFIFOSET(fd, packet_len(header));
  3436. }
  3437. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3438. /// 019b <id>.L <effect id>.L
  3439. /// effect id:
  3440. /// 0 = base level up
  3441. /// 1 = job level up
  3442. /// 2 = refine failure
  3443. /// 3 = refine success
  3444. /// 4 = game over
  3445. /// 5 = pharmacy success
  3446. /// 6 = pharmacy failure
  3447. /// 7 = base level up (super novice)
  3448. /// 8 = job level up (super novice)
  3449. /// 9 = base level up (taekwon)
  3450. void clif_misceffect(struct block_list* bl,int type)
  3451. {
  3452. unsigned char buf[32];
  3453. nullpo_retv(bl);
  3454. WBUFW(buf,0) = 0x19b;
  3455. WBUFL(buf,2) = bl->id;
  3456. WBUFL(buf,6) = type;
  3457. clif_send(buf,packet_len(0x19b),bl,AREA);
  3458. }
  3459. /// Notifies clients in the area of a state change.
  3460. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3461. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3462. void clif_changeoption(struct block_list* bl)
  3463. {
  3464. unsigned char buf[32];
  3465. struct status_change *sc;
  3466. struct map_session_data* sd;
  3467. nullpo_retv(bl);
  3468. sc = status_get_sc(bl);
  3469. if (!sc) return; //How can an option change if there's no sc?
  3470. sd = BL_CAST(BL_PC, bl);
  3471. #if PACKETVER >= 7
  3472. WBUFW(buf,0) = 0x229;
  3473. WBUFL(buf,2) = bl->id;
  3474. WBUFW(buf,6) = sc->opt1;
  3475. WBUFW(buf,8) = sc->opt2;
  3476. WBUFL(buf,10) = sc->option;
  3477. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3478. if(disguised(bl)) {
  3479. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3480. WBUFL(buf,2) = -bl->id;
  3481. clif_send(buf,packet_len(0x229),bl,SELF);
  3482. WBUFL(buf,2) = bl->id;
  3483. WBUFL(buf,10) = OPTION_INVISIBLE;
  3484. clif_send(buf,packet_len(0x229),bl,SELF);
  3485. } else
  3486. clif_send(buf,packet_len(0x229),bl,AREA);
  3487. #else
  3488. WBUFW(buf,0) = 0x119;
  3489. WBUFL(buf,2) = bl->id;
  3490. WBUFW(buf,6) = sc->opt1;
  3491. WBUFW(buf,8) = sc->opt2;
  3492. WBUFW(buf,10) = sc->option;
  3493. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3494. if(disguised(bl)) {
  3495. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3496. WBUFL(buf,2) = -bl->id;
  3497. clif_send(buf,packet_len(0x119),bl,SELF);
  3498. WBUFL(buf,2) = bl->id;
  3499. WBUFW(buf,10) = OPTION_INVISIBLE;
  3500. clif_send(buf,packet_len(0x119),bl,SELF);
  3501. } else
  3502. clif_send(buf,packet_len(0x119),bl,AREA);
  3503. #endif
  3504. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3505. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3506. if (sc->data[SC_PROVOKE] && sc->data[SC_PROVOKE]->timer == INVALID_TIMER)
  3507. clif_status_change(bl, StatusIconChangeTable[SC_PROVOKE], 1, -1, 0, 0, 0);
  3508. }
  3509. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3510. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3511. void clif_changeoption2(struct block_list* bl)
  3512. {
  3513. unsigned char buf[20];
  3514. struct status_change *sc;
  3515. sc = status_get_sc(bl);
  3516. if (!sc) return; //How can an option change if there's no sc?
  3517. WBUFW(buf,0) = 0x28a;
  3518. WBUFL(buf,2) = bl->id;
  3519. WBUFL(buf,6) = sc->option;
  3520. WBUFL(buf,10) = clif_setlevel(bl);
  3521. WBUFL(buf,14) = sc->opt3;
  3522. if(disguised(bl)) {
  3523. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3524. WBUFL(buf,2) = -bl->id;
  3525. clif_send(buf,packet_len(0x28a),bl,SELF);
  3526. WBUFL(buf,2) = bl->id;
  3527. WBUFL(buf,6) = OPTION_INVISIBLE;
  3528. clif_send(buf,packet_len(0x28a),bl,SELF);
  3529. } else
  3530. clif_send(buf,packet_len(0x28a),bl,AREA);
  3531. }
  3532. /// Notifies the client about the result of an item use request.
  3533. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3534. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3535. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3536. {
  3537. nullpo_retv(sd);
  3538. if(!ok) {
  3539. int fd=sd->fd;
  3540. WFIFOHEAD(fd,packet_len(0xa8));
  3541. WFIFOW(fd,0)=0xa8;
  3542. WFIFOW(fd,2)=index+2;
  3543. WFIFOW(fd,4)=amount;
  3544. WFIFOB(fd,6)=ok;
  3545. WFIFOSET(fd,packet_len(0xa8));
  3546. }
  3547. else {
  3548. #if PACKETVER < 3
  3549. int fd=sd->fd;
  3550. WFIFOHEAD(fd,packet_len(0xa8));
  3551. WFIFOW(fd,0)=0xa8;
  3552. WFIFOW(fd,2)=index+2;
  3553. WFIFOW(fd,4)=amount;
  3554. WFIFOB(fd,6)=ok;
  3555. WFIFOSET(fd,packet_len(0xa8));
  3556. #else
  3557. unsigned char buf[32];
  3558. WBUFW(buf,0)=0x1c8;
  3559. WBUFW(buf,2)=index+2;
  3560. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3561. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3562. else
  3563. WBUFW(buf,4)=sd->inventory.u.items_inventory[index].nameid;
  3564. WBUFL(buf,6)=sd->bl.id;
  3565. WBUFW(buf,10)=amount;
  3566. WBUFB(buf,12)=ok;
  3567. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3568. #endif
  3569. }
  3570. }
  3571. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3572. /// 00d6 <flag>.B
  3573. /// flag:
  3574. /// 0 = Room has been successfully created (opens chat room)
  3575. /// 1 = Room limit exceeded
  3576. /// 2 = Same room already exists
  3577. void clif_createchat(struct map_session_data* sd, int flag)
  3578. {
  3579. int fd;
  3580. nullpo_retv(sd);
  3581. fd = sd->fd;
  3582. WFIFOHEAD(fd,packet_len(0xd6));
  3583. WFIFOW(fd,0) = 0xd6;
  3584. WFIFOB(fd,2) = flag;
  3585. WFIFOSET(fd,packet_len(0xd6));
  3586. }
  3587. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3588. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3589. /// type:
  3590. /// 0 = private (password protected)
  3591. /// 1 = public
  3592. /// 2 = arena (npc waiting room)
  3593. /// 3 = PK zone (non-clickable)
  3594. void clif_dispchat(struct chat_data* cd, int fd)
  3595. {
  3596. unsigned char buf[128];
  3597. uint8 type;
  3598. if( cd == NULL || cd->owner == NULL )
  3599. return;
  3600. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3601. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3602. : 1;
  3603. WBUFW(buf, 0) = 0xd7;
  3604. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3605. WBUFL(buf, 4) = cd->owner->id;
  3606. WBUFL(buf, 8) = cd->bl.id;
  3607. WBUFW(buf,12) = cd->limit;
  3608. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3609. WBUFB(buf,16) = type;
  3610. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3611. if( fd ) {
  3612. WFIFOHEAD(fd,WBUFW(buf,2));
  3613. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3614. WFIFOSET(fd,WBUFW(buf,2));
  3615. } else {
  3616. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3617. }
  3618. }
  3619. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3620. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3621. /// type:
  3622. /// 0 = private (password protected)
  3623. /// 1 = public
  3624. /// 2 = arena (npc waiting room)
  3625. /// 3 = PK zone (non-clickable)
  3626. void clif_changechatstatus(struct chat_data* cd)
  3627. {
  3628. unsigned char buf[128];
  3629. uint8 type;
  3630. if( cd == NULL || cd->usersd[0] == NULL )
  3631. return;
  3632. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3633. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3634. : 1;
  3635. WBUFW(buf, 0) = 0xdf;
  3636. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3637. WBUFL(buf, 4) = cd->owner->id;
  3638. WBUFL(buf, 8) = cd->bl.id;
  3639. WBUFW(buf,12) = cd->limit;
  3640. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3641. WBUFB(buf,16) = type;
  3642. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3643. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3644. }
  3645. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3646. /// 00d8 <chat id>.L
  3647. void clif_clearchat(struct chat_data *cd,int fd)
  3648. {
  3649. unsigned char buf[32];
  3650. nullpo_retv(cd);
  3651. WBUFW(buf,0) = 0xd8;
  3652. WBUFL(buf,2) = cd->bl.id;
  3653. if( fd ) {
  3654. WFIFOHEAD(fd,packet_len(0xd8));
  3655. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3656. WFIFOSET(fd,packet_len(0xd8));
  3657. } else {
  3658. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3659. }
  3660. }
  3661. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3662. /// 00da <result>.B
  3663. /// result:
  3664. /// 0 = room full
  3665. /// 1 = wrong password
  3666. /// 2 = kicked
  3667. /// 3 = success (no message)
  3668. /// 4 = no enough zeny
  3669. /// 5 = too low level
  3670. /// 6 = too high level
  3671. /// 7 = unsuitable job class
  3672. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3673. {
  3674. int fd;
  3675. nullpo_retv(sd);
  3676. fd = sd->fd;
  3677. WFIFOHEAD(fd,packet_len(0xda));
  3678. WFIFOW(fd,0) = 0xda;
  3679. WFIFOB(fd,2) = flag;
  3680. WFIFOSET(fd,packet_len(0xda));
  3681. }
  3682. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3683. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3684. /// role:
  3685. /// 0 = owner (menu)
  3686. /// 1 = normal
  3687. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3688. {
  3689. int fd;
  3690. int i,t;
  3691. nullpo_retv(sd);
  3692. nullpo_retv(cd);
  3693. fd = sd->fd;
  3694. if (!session_isActive(fd))
  3695. return;
  3696. t = (int)(cd->owner->type == BL_NPC);
  3697. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3698. WFIFOW(fd, 0) = 0xdb;
  3699. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3700. WFIFOL(fd, 4) = cd->bl.id;
  3701. if(cd->owner->type == BL_NPC){
  3702. WFIFOL(fd, 30) = 1;
  3703. WFIFOL(fd, 8) = 0;
  3704. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3705. for (i = 0; i < cd->users; i++) {
  3706. WFIFOL(fd, 8+(i+1)*28) = 1;
  3707. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3708. }
  3709. }else{
  3710. for (i = 0; i < cd->users; i++) {
  3711. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3712. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3713. }
  3714. }
  3715. WFIFOSET(fd, WFIFOW(fd, 2));
  3716. }
  3717. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3718. /// 00dc <users>.W <name>.24B
  3719. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3720. {
  3721. unsigned char buf[29];
  3722. nullpo_retv(sd);
  3723. nullpo_retv(cd);
  3724. WBUFW(buf, 0) = 0xdc;
  3725. WBUFW(buf, 2) = cd->users;
  3726. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3727. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3728. }
  3729. /// Announce the new owner (ZC_ROLE_CHANGE).
  3730. /// 00e1 <role>.L <nick>.24B
  3731. /// role:
  3732. /// 0 = owner (menu)
  3733. /// 1 = normal
  3734. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3735. {
  3736. unsigned char buf[64];
  3737. nullpo_retv(sd);
  3738. nullpo_retv(cd);
  3739. WBUFW(buf, 0) = 0xe1;
  3740. WBUFL(buf, 2) = 1;
  3741. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3742. WBUFW(buf,30) = 0xe1;
  3743. WBUFL(buf,32) = 0;
  3744. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3745. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3746. }
  3747. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3748. /// 00dd <users>.W <nick>.24B <flag>.B
  3749. /// flag:
  3750. /// 0 = left
  3751. /// 1 = kicked
  3752. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3753. {
  3754. unsigned char buf[32];
  3755. nullpo_retv(sd);
  3756. nullpo_retv(cd);
  3757. WBUFW(buf, 0) = 0xdd;
  3758. WBUFW(buf, 2) = cd->users-1;
  3759. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3760. WBUFB(buf,28) = flag;
  3761. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3762. }
  3763. /// Opens a trade request window from char 'name'.
  3764. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3765. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3766. void clif_traderequest(struct map_session_data* sd, const char* name)
  3767. {
  3768. int fd = sd->fd;
  3769. #if PACKETVER < 6
  3770. WFIFOHEAD(fd,packet_len(0xe5));
  3771. WFIFOW(fd,0) = 0xe5;
  3772. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3773. WFIFOSET(fd,packet_len(0xe5));
  3774. #else
  3775. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3776. if( !tsd ) return;
  3777. WFIFOHEAD(fd,packet_len(0x1f4));
  3778. WFIFOW(fd,0) = 0x1f4;
  3779. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3780. WFIFOL(fd,26) = tsd->status.char_id;
  3781. WFIFOW(fd,30) = tsd->status.base_level;
  3782. WFIFOSET(fd,packet_len(0x1f4));
  3783. #endif
  3784. }
  3785. /// Reply to a trade-request.
  3786. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3787. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3788. /// result:
  3789. /// 0 = Char is too far
  3790. /// 1 = Character does not exist
  3791. /// 2 = Trade failed
  3792. /// 3 = Accept
  3793. /// 4 = Cancel
  3794. /// 5 = Busy
  3795. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3796. {
  3797. int fd = sd->fd;
  3798. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3799. if( PACKETVER < 6 || !tsd ) {
  3800. WFIFOHEAD(fd,packet_len(0xe7));
  3801. WFIFOW(fd,0) = 0xe7;
  3802. WFIFOB(fd,2) = type;
  3803. WFIFOSET(fd,packet_len(0xe7));
  3804. } else {
  3805. WFIFOHEAD(fd,packet_len(0x1f5));
  3806. WFIFOW(fd,0) = 0x1f5;
  3807. WFIFOB(fd,2) = type;
  3808. WFIFOL(fd,3) = tsd->status.char_id;
  3809. WFIFOW(fd,7) = tsd->status.base_level;
  3810. WFIFOSET(fd,packet_len(0x1f5));
  3811. }
  3812. }
  3813. /// Notifies the client about an item from other player in current trade.
  3814. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3815. /// 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)
  3816. /// 0a09 <nameid>.W <item type>.B <amount>.L <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W { <option id>.W <option value>.W <option param>.B }*5 (ZC_ADD_EXCHANGE_ITEM3)
  3817. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3818. {
  3819. int fd;
  3820. unsigned char *buf;
  3821. #if PACKETVER < 20100223
  3822. const int cmd = 0xe9;
  3823. #elif PACKETVER < 20150225
  3824. const int cmd = 0x80f;
  3825. #else
  3826. const int cmd = 0xa09;
  3827. #endif
  3828. nullpo_retv(sd);
  3829. nullpo_retv(tsd);
  3830. fd = tsd->fd;
  3831. buf = WFIFOP(fd,0);
  3832. WFIFOHEAD(fd,packet_len(cmd));
  3833. WBUFW(buf,0) = cmd;
  3834. if( index == 0 )
  3835. {
  3836. #if PACKETVER < 20100223
  3837. WBUFL(buf,2) = amount; //amount
  3838. WBUFW(buf,6) = 0; // type id
  3839. #else
  3840. WBUFW(buf,2) = 0; // type id
  3841. WBUFB(buf,4) = 0; // item type
  3842. WBUFL(buf,5) = amount; // amount
  3843. buf = WBUFP(buf,1); //Advance 1B
  3844. #endif
  3845. WBUFB(buf,8) = 0; //identify flag
  3846. WBUFB(buf,9) = 0; // attribute
  3847. WBUFB(buf,10)= 0; //refine
  3848. WBUFW(buf,11)= 0; //card (4w)
  3849. WBUFW(buf,13)= 0; //card (4w)
  3850. WBUFW(buf,15)= 0; //card (4w)
  3851. WBUFW(buf,17)= 0; //card (4w)
  3852. #if PACKETVER >= 20150225
  3853. clif_add_random_options(WBUFP(buf, 19), &sd->inventory.u.items_inventory[index]);
  3854. #endif
  3855. }
  3856. else
  3857. {
  3858. index -= 2; //index fix
  3859. #if PACKETVER < 20100223
  3860. WBUFL(buf,2) = amount; //amount
  3861. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3862. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3863. else
  3864. WBUFW(buf,6) = sd->inventory.u.items_inventory[index].nameid; // type id
  3865. #else
  3866. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3867. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3868. else
  3869. WBUFW(buf,2) = sd->inventory.u.items_inventory[index].nameid; // type id
  3870. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3871. WBUFL(buf,5) = amount; // amount
  3872. buf = WBUFP(buf,1); //Advance 1B
  3873. #endif
  3874. WBUFB(buf,8) = sd->inventory.u.items_inventory[index].identify; //identify flag
  3875. WBUFB(buf,9) = sd->inventory.u.items_inventory[index].attribute; // attribute
  3876. WBUFB(buf,10)= sd->inventory.u.items_inventory[index].refine; //refine
  3877. clif_addcards(WBUFP(buf, 11), &sd->inventory.u.items_inventory[index]);
  3878. #if PACKETVER >= 20150225
  3879. clif_add_random_options(WBUFP(buf, 19), &sd->inventory.u.items_inventory[index]);
  3880. #endif
  3881. }
  3882. WFIFOSET(fd,packet_len(cmd));
  3883. }
  3884. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3885. /// 00ea <index>.W <result>.B
  3886. /// result:
  3887. /// 0 = success
  3888. /// 1 = overweight
  3889. /// 2 = trade canceled
  3890. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3891. {
  3892. int fd;
  3893. nullpo_retv(sd);
  3894. fd = sd->fd;
  3895. WFIFOHEAD(fd,packet_len(0xea));
  3896. WFIFOW(fd,0) = 0xea;
  3897. WFIFOW(fd,2) = index;
  3898. WFIFOB(fd,4) = fail;
  3899. WFIFOSET(fd,packet_len(0xea));
  3900. }
  3901. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3902. /// 00ec <who>.B
  3903. /// who:
  3904. /// 0 = self
  3905. /// 1 = other player
  3906. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3907. {
  3908. int fd;
  3909. nullpo_retv(sd);
  3910. fd = sd->fd;
  3911. WFIFOHEAD(fd,packet_len(0xec));
  3912. WFIFOW(fd,0) = 0xec;
  3913. WFIFOB(fd,2) = fail;
  3914. WFIFOSET(fd,packet_len(0xec));
  3915. }
  3916. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3917. /// 00ee
  3918. void clif_tradecancelled(struct map_session_data* sd)
  3919. {
  3920. int fd;
  3921. nullpo_retv(sd);
  3922. fd = sd->fd;
  3923. WFIFOHEAD(fd,packet_len(0xee));
  3924. WFIFOW(fd,0) = 0xee;
  3925. WFIFOSET(fd,packet_len(0xee));
  3926. }
  3927. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3928. /// 00f0 <result>.B
  3929. /// result:
  3930. /// 0 = success
  3931. /// 1 = failure
  3932. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3933. {
  3934. int fd;
  3935. nullpo_retv(sd);
  3936. fd = sd->fd;
  3937. WFIFOHEAD(fd,packet_len(0xf0));
  3938. WFIFOW(fd,0) = 0xf0;
  3939. WFIFOB(fd,2) = fail;
  3940. WFIFOSET(fd,packet_len(0xf0));
  3941. }
  3942. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3943. /// 00f1
  3944. /// NOTE: Unknown purpose. Items are not removed until the window is
  3945. /// refreshed (ex. by putting another item in there).
  3946. void clif_tradeundo(struct map_session_data* sd)
  3947. {
  3948. int fd = sd->fd;
  3949. WFIFOHEAD(fd,packet_len(0xf1));
  3950. WFIFOW(fd,0) = 0xf1;
  3951. WFIFOSET(fd,packet_len(0xf1));
  3952. }
  3953. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3954. /// 00f2 <current count>.W <max count>.W
  3955. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3956. {
  3957. int fd;
  3958. nullpo_retv(sd);
  3959. fd=sd->fd;
  3960. WFIFOHEAD(fd,packet_len(0xf2));
  3961. WFIFOW(fd,0) = 0xf2;
  3962. WFIFOW(fd,2) = amount;
  3963. WFIFOW(fd,4) = max_amount;
  3964. WFIFOSET(fd,packet_len(0xf2));
  3965. }
  3966. /// Notifies the client of an item being added to the storage.
  3967. /// 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)
  3968. /// 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)
  3969. /// 0a0a <index>.W <amount>.L <nameid>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W { <option id>.W <option value>.W <option param>.B }*5 (ZC_ADD_ITEM_TO_STORE3)
  3970. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3971. {
  3972. #if PACKETVER < 5
  3973. const int cmd = 0xf4;
  3974. #elif PACKETVER < 20150225
  3975. const int cmd = 0x1c4;
  3976. #else
  3977. const int cmd = 0xa0a;
  3978. #endif
  3979. int view,fd;
  3980. int offset = 0;
  3981. nullpo_retv(sd);
  3982. nullpo_retv(i);
  3983. fd=sd->fd;
  3984. view = itemdb_viewid(i->nameid);
  3985. WFIFOHEAD(fd,packet_len(cmd));
  3986. WFIFOW(fd, 0) = cmd; // Storage item added
  3987. WFIFOW(fd, 2) = index+1; // index
  3988. WFIFOL(fd, 4) = amount; // amount
  3989. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3990. #if PACKETVER >= 5
  3991. WFIFOB(fd,10) = itemtype(i->nameid); //type
  3992. offset += 1;
  3993. #endif
  3994. WFIFOB(fd,10+offset) = i->identify; //identify flag
  3995. WFIFOB(fd,11+offset) = i->attribute; // attribute
  3996. WFIFOB(fd,12+offset) = i->refine; //refine
  3997. clif_addcards(WFIFOP(fd,13+offset), i);
  3998. #if PACKETVER >= 20150225
  3999. clif_add_random_options(WFIFOP(fd,21+offset), i);
  4000. #endif
  4001. WFIFOSET(fd,packet_len(cmd));
  4002. }
  4003. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  4004. /// 00f6 <index>.W <amount>.L
  4005. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  4006. {
  4007. int fd;
  4008. nullpo_retv(sd);
  4009. fd=sd->fd;
  4010. WFIFOHEAD(fd,packet_len(0xf6));
  4011. WFIFOW(fd,0)=0xf6; // Storage item removed
  4012. WFIFOW(fd,2)=index+1;
  4013. WFIFOL(fd,4)=amount;
  4014. WFIFOSET(fd,packet_len(0xf6));
  4015. }
  4016. /// Closes storage (ZC_CLOSE_STORE).
  4017. /// 00f8
  4018. void clif_storageclose(struct map_session_data* sd)
  4019. {
  4020. int fd;
  4021. nullpo_retv(sd);
  4022. fd=sd->fd;
  4023. WFIFOHEAD(fd,packet_len(0xf8));
  4024. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4025. WFIFOSET(fd,packet_len(0xf8));
  4026. }
  4027. /*==========================================
  4028. * Server tells 'sd' player client the abouts of 'dstsd' player
  4029. *------------------------------------------*/
  4030. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  4031. {
  4032. struct block_list *d_bl;
  4033. int i;
  4034. if( dstsd->chatID ) {
  4035. struct chat_data *cd = NULL;
  4036. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4037. clif_dispchat(cd,sd->fd);
  4038. } else if( dstsd->state.vending )
  4039. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  4040. else if( dstsd->state.buyingstore )
  4041. clif_buyingstore_entry_single(sd, dstsd);
  4042. if(dstsd->spiritball > 0)
  4043. clif_spiritball_single(sd->fd, dstsd);
  4044. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4045. clif_spiritcharm_single(sd->fd, dstsd);
  4046. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4047. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4048. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4049. )
  4050. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  4051. // display link (sd - dstsd) to sd
  4052. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4053. if( i < MAX_DEVOTION )
  4054. clif_devotion(&sd->bl, sd);
  4055. // display links (dstsd - devotees) to sd
  4056. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4057. if( i < MAX_DEVOTION )
  4058. clif_devotion(&dstsd->bl, sd);
  4059. // display link (dstsd - crusader) to sd
  4060. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4061. clif_devotion(d_bl, sd);
  4062. }
  4063. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  4064. {
  4065. uint8 buf[128];
  4066. struct unit_data *ud;
  4067. struct view_data *vd;
  4068. int len;
  4069. vd = status_get_viewdata(bl);
  4070. if (!vd || vd->class_ == JT_INVISIBLE)
  4071. return;
  4072. /**
  4073. * Hide NPC from maya purple card.
  4074. **/
  4075. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4076. return;
  4077. ud = unit_bl2ud(bl);
  4078. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  4079. clif_send(buf,len,&sd->bl,SELF);
  4080. if (vd->cloth_color)
  4081. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4082. if (vd->body_style)
  4083. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4084. switch (bl->type)
  4085. {
  4086. case BL_PC:
  4087. {
  4088. TBL_PC* tsd = (TBL_PC*)bl;
  4089. clif_getareachar_pc(sd, tsd);
  4090. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4091. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4092. else if(tsd->state.size==SZ_MEDIUM)
  4093. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4094. if( tsd->bg_id && map_getmapflag(tsd->bl.m, MF_BATTLEGROUND) )
  4095. clif_sendbgemblem_single(sd->fd,tsd);
  4096. if ( tsd->status.robe )
  4097. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4098. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4099. clif_hat_effects(sd,bl,SELF);
  4100. }
  4101. break;
  4102. case BL_MER: // Devotion Effects
  4103. if( ((TBL_MER*)bl)->devotion_flag )
  4104. clif_devotion(bl, sd);
  4105. break;
  4106. case BL_NPC:
  4107. {
  4108. TBL_NPC* nd = (TBL_NPC*)bl;
  4109. if( nd->chat_id )
  4110. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4111. if( nd->size == SZ_BIG )
  4112. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4113. else if( nd->size == SZ_MEDIUM )
  4114. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4115. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4116. clif_progressbar_npc(nd, sd);
  4117. }
  4118. break;
  4119. case BL_MOB:
  4120. {
  4121. TBL_MOB* md = (TBL_MOB*)bl;
  4122. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4123. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4124. else if(md->special_state.size==SZ_MEDIUM)
  4125. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4126. #if PACKETVER >= 20120404
  4127. if (battle_config.monster_hp_bars_info && !map_getmapflag(bl->m, MF_HIDEMOBHPBAR)) {
  4128. int i;
  4129. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4130. if( md->dmglog[i].id == sd->status.char_id )
  4131. clif_monster_hp_bar(md, sd->fd);
  4132. }
  4133. #endif
  4134. }
  4135. break;
  4136. case BL_PET:
  4137. if (vd->head_bottom)
  4138. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4139. break;
  4140. }
  4141. }
  4142. //Modifies the type of damage according to status changes [Skotlex]
  4143. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4144. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4145. {
  4146. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4147. }
  4148. /*==========================================
  4149. * Estimates walk delay based on the damage criteria. [Skotlex]
  4150. *------------------------------------------*/
  4151. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4152. {
  4153. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4154. return 0;
  4155. if (bl->type == BL_PC) {
  4156. if (battle_config.pc_walk_delay_rate != 100)
  4157. delay = delay*battle_config.pc_walk_delay_rate/100;
  4158. } else
  4159. if (battle_config.walk_delay_rate != 100)
  4160. delay = delay*battle_config.walk_delay_rate/100;
  4161. if (div_ > 1) //Multi-hit skills mean higher delays.
  4162. delay += battle_config.multihit_delay*(div_-1);
  4163. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4164. }
  4165. /*========================================== [Playtester]
  4166. * Returns hallucination damage the client displays
  4167. *------------------------------------------*/
  4168. static int clif_hallucination_damage()
  4169. {
  4170. int digit = rnd() % 5 + 1;
  4171. switch (digit)
  4172. {
  4173. case 1:
  4174. return (rnd() % 10);
  4175. case 2:
  4176. return (rnd() % 100);
  4177. case 3:
  4178. return (rnd() % 1000);
  4179. case 4:
  4180. return (rnd() % 10000);
  4181. }
  4182. return (rnd() % 32767);
  4183. }
  4184. /// Sends a 'damage' packet (src performs action on dst)
  4185. /// 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)
  4186. /// 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)
  4187. /// 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)
  4188. /// type:
  4189. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4190. /// 1 = pick up item
  4191. /// 2 = sit down
  4192. /// 3 = stand up
  4193. /// 4 = damage (endure)
  4194. /// 5 = (splash?)
  4195. /// 6 = (skill?)
  4196. /// 7 = (repeat damage?)
  4197. /// 8 = multi-hit damage
  4198. /// 9 = multi-hit damage (endure)
  4199. /// 10 = critical hit
  4200. /// 11 = lucky dodge
  4201. /// 12 = (touch skill?)
  4202. 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)
  4203. {
  4204. unsigned char buf[34];
  4205. struct status_change *sc;
  4206. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4207. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4208. #if PACKETVER < 20071113
  4209. const int cmd = 0x8a;
  4210. int offset = 0;
  4211. #elif PACKETVER < 20131223
  4212. const int cmd = 0x2e1;
  4213. int offset = 2;
  4214. #else
  4215. const int cmd = 0x8c8;
  4216. int offset = 3;
  4217. #endif
  4218. nullpo_ret(src);
  4219. nullpo_ret(dst);
  4220. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4221. sc = status_get_sc(dst);
  4222. if(sc && sc->count) {
  4223. if(sc->data[SC_HALLUCINATION]) {
  4224. if(damage) damage = clif_hallucination_damage();
  4225. if(damage2) damage2 = clif_hallucination_damage();
  4226. }
  4227. }
  4228. WBUFW(buf,0) = cmd;
  4229. WBUFL(buf,2) = src->id;
  4230. WBUFL(buf,6) = dst->id;
  4231. WBUFL(buf,10) = tick;
  4232. WBUFL(buf,14) = sdelay;
  4233. WBUFL(buf,18) = ddelay;
  4234. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4235. #if PACKETVER < 20071113
  4236. WBUFW(buf,22) = damage ? div : 0;
  4237. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4238. #else
  4239. WBUFL(buf, 22) = damage ? div : 0;
  4240. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4241. #endif
  4242. } else {
  4243. #if PACKETVER < 20071113
  4244. WBUFW(buf,22) = min(damage, INT16_MAX);
  4245. WBUFW(buf,27+offset) = damage2;
  4246. #else
  4247. WBUFL(buf,22) = damage;
  4248. WBUFL(buf,27+offset) = damage2;
  4249. #endif
  4250. }
  4251. #if PACKETVER >= 20131223
  4252. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4253. #endif
  4254. WBUFW(buf,24+offset) = div;
  4255. WBUFB(buf,26+offset) = type;
  4256. if(disguised(dst)) {
  4257. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4258. WBUFL(buf,6) = -dst->id;
  4259. clif_send(buf, packet_len(cmd), dst, SELF);
  4260. } else
  4261. clif_send(buf, packet_len(cmd), dst, AREA);
  4262. if(disguised(src)) {
  4263. WBUFL(buf,2) = -src->id;
  4264. if (disguised(dst))
  4265. WBUFL(buf,6) = dst->id;
  4266. #if PACKETVER < 20071113
  4267. if(damage > 0) WBUFW(buf,22) = -1;
  4268. if(damage2 > 0) WBUFW(buf,27) = -1;
  4269. #else
  4270. if(damage > 0) WBUFL(buf,22) = -1;
  4271. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4272. #endif
  4273. clif_send(buf,packet_len(cmd),src,SELF);
  4274. }
  4275. if(src == dst) {
  4276. unit_setdir(src, unit_getdir(src));
  4277. }
  4278. //Return adjusted can't walk delay for further processing.
  4279. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4280. }
  4281. /*==========================================
  4282. * src picks up dst
  4283. *------------------------------------------*/
  4284. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4285. {
  4286. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4287. unsigned char buf[32];
  4288. nullpo_retv(src);
  4289. nullpo_retv(dst);
  4290. WBUFW(buf, 0) = 0x8a;
  4291. WBUFL(buf, 2) = src->id;
  4292. WBUFL(buf, 6) = dst->id;
  4293. WBUFB(buf,26) = 1;
  4294. clif_send(buf, packet_len(0x8a), src, AREA);
  4295. }
  4296. /*==========================================
  4297. * inform clients in area that `bl` is sitting
  4298. *------------------------------------------*/
  4299. void clif_sitting(struct block_list* bl)
  4300. {
  4301. unsigned char buf[32];
  4302. nullpo_retv(bl);
  4303. WBUFW(buf, 0) = 0x8a;
  4304. WBUFL(buf, 2) = bl->id;
  4305. WBUFB(buf,26) = 2;
  4306. clif_send(buf, packet_len(0x8a), bl, AREA);
  4307. if(disguised(bl)) {
  4308. WBUFL(buf, 2) = - bl->id;
  4309. clif_send(buf, packet_len(0x8a), bl, SELF);
  4310. }
  4311. }
  4312. /*==========================================
  4313. * inform clients in area that `bl` is standing
  4314. *------------------------------------------*/
  4315. void clif_standing(struct block_list* bl)
  4316. {
  4317. unsigned char buf[32];
  4318. nullpo_retv(bl);
  4319. WBUFW(buf, 0) = 0x8a;
  4320. WBUFL(buf, 2) = bl->id;
  4321. WBUFB(buf,26) = 3;
  4322. clif_send(buf, packet_len(0x8a), bl, AREA);
  4323. if(disguised(bl)) {
  4324. WBUFL(buf, 2) = - bl->id;
  4325. clif_send(buf, packet_len(0x8a), bl, SELF);
  4326. }
  4327. }
  4328. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4329. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4330. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4331. {
  4332. unsigned char buf[32];
  4333. WBUFW(buf,0) = 0x192;
  4334. WBUFW(buf,2) = x;
  4335. WBUFW(buf,4) = y;
  4336. WBUFW(buf,6) = type;
  4337. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4338. if( fd )
  4339. {
  4340. WFIFOHEAD(fd,packet_len(0x192));
  4341. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4342. WFIFOSET(fd,packet_len(0x192));
  4343. }
  4344. else
  4345. {
  4346. struct block_list dummy_bl;
  4347. dummy_bl.type = BL_NUL;
  4348. dummy_bl.x = x;
  4349. dummy_bl.y = y;
  4350. dummy_bl.m = m;
  4351. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4352. }
  4353. }
  4354. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4355. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4356. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  4357. {
  4358. int view,fd;
  4359. fd=sd->fd;
  4360. WFIFOHEAD(fd,packet_len(0x9d));
  4361. WFIFOW(fd,0)=0x9d;
  4362. WFIFOL(fd,2)=fitem->bl.id;
  4363. if((view = itemdb_viewid(fitem->item.nameid)) > 0)
  4364. WFIFOW(fd,6)=view;
  4365. else
  4366. WFIFOW(fd,6)=fitem->item.nameid;
  4367. WFIFOB(fd,8)=fitem->item.identify;
  4368. WFIFOW(fd,9)=fitem->bl.x;
  4369. WFIFOW(fd,11)=fitem->bl.y;
  4370. WFIFOW(fd,13)=fitem->item.amount;
  4371. WFIFOB(fd,15)=fitem->subx;
  4372. WFIFOB(fd,16)=fitem->suby;
  4373. WFIFOSET(fd,packet_len(0x9d));
  4374. }
  4375. /// Notifes client about Graffiti
  4376. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4377. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4378. unsigned char buf[128];
  4379. nullpo_retv(bl);
  4380. nullpo_retv(unit);
  4381. WBUFW(buf, 0) = 0x1c9;
  4382. WBUFL(buf, 2) = unit->bl.id;
  4383. WBUFL(buf, 6) = unit->group->src_id;
  4384. WBUFW(buf,10) = unit->bl.x;
  4385. WBUFW(buf,12) = unit->bl.y;
  4386. WBUFB(buf,14) = unit->group->unit_id;
  4387. WBUFB(buf,15) = 1;
  4388. WBUFB(buf,16) = 1;
  4389. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4390. clif_send(buf,packet_len(0x1c9),bl,target);
  4391. }
  4392. /// Notifies the client of a skill unit.
  4393. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4394. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4395. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4396. /// 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)
  4397. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4398. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4399. unsigned char buf[128];
  4400. nullpo_retv(bl);
  4401. nullpo_retv(unit);
  4402. if (bl->type == BL_PC)
  4403. fd = ((TBL_PC*)bl)->fd;
  4404. if (unit->group->state.guildaura)
  4405. return;
  4406. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4407. unit_id = unit->val2&UF_SONG ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4408. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4409. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4410. else
  4411. unit_id = unit->group->unit_id;
  4412. if (!visible)
  4413. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4414. #if PACKETVER >= 3
  4415. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4416. clif_graffiti(bl, unit, target);
  4417. return;
  4418. }
  4419. #endif
  4420. #if PACKETVER <= 20120702
  4421. header = 0x011f;
  4422. //#if PACKETVER < 20110718
  4423. // header = 0x011f;
  4424. //#elif PACKETVER < 20121212
  4425. // header = 0x08c7;
  4426. #elif PACKETVER < 20130731
  4427. header = 0x099f;
  4428. #else
  4429. header = 0x09ca;
  4430. #endif
  4431. len = packet_len(header);
  4432. WBUFW(buf,pos) = header;
  4433. if (header != 0x011f) {
  4434. WBUFW(buf, pos+2) = len;
  4435. pos += 2;
  4436. }
  4437. WBUFL(buf,pos+2) = unit->bl.id;
  4438. WBUFL(buf,pos+6) = unit->group->src_id;
  4439. WBUFW(buf,pos+10) = unit->bl.x;
  4440. WBUFW(buf,pos+12) = unit->bl.y;
  4441. switch (header) {
  4442. case 0x011f:
  4443. WBUFB(buf,pos+14) = unit_id;
  4444. WBUFB(buf,pos+15) = visible;
  4445. break;
  4446. case 0x08c7:
  4447. WBUFB(buf,pos+14) = unit_id;
  4448. WBUFW(buf,pos+15) = unit->range;
  4449. WBUFB(buf,pos+17) = visible;
  4450. break;
  4451. case 0x099f:
  4452. WBUFL(buf,pos+14) = unit_id;
  4453. WBUFW(buf,pos+18) = unit->range;
  4454. WBUFB(buf,pos+20) = visible;
  4455. break;
  4456. case 0x09ca:
  4457. WBUFL(buf,pos+14) = unit_id;
  4458. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4459. WBUFB(buf,pos+19) = visible;
  4460. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4461. break;
  4462. }
  4463. clif_send(buf, len, bl, target);
  4464. if (unit->group->skill_id == WZ_ICEWALL)
  4465. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4466. }
  4467. /*==========================================
  4468. * Server tells client to remove unit of id 'unit->bl.id'
  4469. *------------------------------------------*/
  4470. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4471. {
  4472. nullpo_retv(unit);
  4473. WFIFOHEAD(fd,packet_len(0x120));
  4474. WFIFOW(fd, 0)=0x120;
  4475. WFIFOL(fd, 2)=unit->bl.id;
  4476. WFIFOSET(fd,packet_len(0x120));
  4477. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4478. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4479. }
  4480. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4481. /// 0120 <id>.L
  4482. void clif_skill_delunit(struct skill_unit *unit)
  4483. {
  4484. unsigned char buf[16];
  4485. nullpo_retv(unit);
  4486. WBUFW(buf, 0)=0x120;
  4487. WBUFL(buf, 2)=unit->bl.id;
  4488. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4489. }
  4490. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4491. /// 01ac <id>.L
  4492. /// Only affects units with class [139,153] client-side.
  4493. void clif_skillunit_update(struct block_list* bl)
  4494. {
  4495. unsigned char buf[6];
  4496. nullpo_retv(bl);
  4497. WBUFW(buf,0) = 0x1ac;
  4498. WBUFL(buf,2) = bl->id;
  4499. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4500. }
  4501. /*==========================================
  4502. *
  4503. *------------------------------------------*/
  4504. static int clif_getareachar(struct block_list* bl,va_list ap)
  4505. {
  4506. struct map_session_data *sd;
  4507. nullpo_ret(bl);
  4508. sd=va_arg(ap,struct map_session_data*);
  4509. if (sd == NULL || !sd->fd)
  4510. return 0;
  4511. switch(bl->type){
  4512. case BL_ITEM:
  4513. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4514. break;
  4515. case BL_SKILL:
  4516. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4517. break;
  4518. default:
  4519. if(&sd->bl == bl)
  4520. break;
  4521. clif_getareachar_unit(sd,bl);
  4522. break;
  4523. }
  4524. return 0;
  4525. }
  4526. /*==========================================
  4527. * tbl has gone out of view-size of bl
  4528. *------------------------------------------*/
  4529. int clif_outsight(struct block_list *bl,va_list ap)
  4530. {
  4531. struct block_list *tbl;
  4532. struct view_data *vd;
  4533. TBL_PC *sd, *tsd;
  4534. tbl=va_arg(ap,struct block_list*);
  4535. if(bl == tbl) return 0;
  4536. sd = BL_CAST(BL_PC, bl);
  4537. tsd = BL_CAST(BL_PC, tbl);
  4538. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4539. nullpo_ret(bl);
  4540. switch(bl->type){
  4541. case BL_PC:
  4542. if(sd->vd.class_ != JT_INVISIBLE)
  4543. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4544. if(sd->chatID){
  4545. struct chat_data *cd;
  4546. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4547. if(cd->usersd[0]==sd)
  4548. clif_dispchat(cd,tsd->fd);
  4549. }
  4550. if(sd->state.vending)
  4551. clif_closevendingboard(bl,tsd->fd);
  4552. if(sd->state.buyingstore)
  4553. clif_buyingstore_disappear_entry_single(tsd, sd);
  4554. break;
  4555. case BL_ITEM:
  4556. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4557. break;
  4558. case BL_SKILL:
  4559. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4560. break;
  4561. case BL_NPC:
  4562. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4563. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4564. break;
  4565. default:
  4566. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4567. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4568. break;
  4569. }
  4570. }
  4571. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4572. nullpo_ret(tbl);
  4573. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4574. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4575. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4576. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4577. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4578. }
  4579. return 0;
  4580. }
  4581. /*==========================================
  4582. * tbl has come into view of bl
  4583. *------------------------------------------*/
  4584. int clif_insight(struct block_list *bl,va_list ap)
  4585. {
  4586. struct block_list *tbl;
  4587. TBL_PC *sd, *tsd;
  4588. tbl=va_arg(ap,struct block_list*);
  4589. if (bl == tbl) return 0;
  4590. sd = BL_CAST(BL_PC, bl);
  4591. tsd = BL_CAST(BL_PC, tbl);
  4592. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4593. switch(bl->type){
  4594. case BL_ITEM:
  4595. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4596. break;
  4597. case BL_SKILL:
  4598. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4599. break;
  4600. default:
  4601. clif_getareachar_unit(tsd,bl);
  4602. break;
  4603. }
  4604. }
  4605. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4606. clif_getareachar_unit(sd,tbl);
  4607. }
  4608. return 0;
  4609. }
  4610. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4611. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4612. void clif_skillinfoblock(struct map_session_data *sd)
  4613. {
  4614. int fd;
  4615. int i,len,id;
  4616. nullpo_retv(sd);
  4617. fd = sd->fd;
  4618. if (!fd)
  4619. return;
  4620. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4621. WFIFOW(fd,0) = 0x10f;
  4622. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4623. {
  4624. if( (id = sd->status.skill[i].id) != 0 )
  4625. {
  4626. // workaround for bugreport:5348
  4627. if (len + 37 > 8192)
  4628. break;
  4629. WFIFOW(fd,len) = id;
  4630. WFIFOL(fd,len+2) = skill_get_inf(id);
  4631. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4632. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4633. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4634. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4635. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4636. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4637. else
  4638. WFIFOB(fd,len+36) = 0;
  4639. len += 37;
  4640. }
  4641. }
  4642. WFIFOW(fd,2)=len;
  4643. WFIFOSET(fd,len);
  4644. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4645. for ( ; i < MAX_SKILL; i++)
  4646. {
  4647. if( (id = sd->status.skill[i].id) != 0 )
  4648. {
  4649. clif_addskill(sd, id);
  4650. clif_skillinfo(sd, id, 0);
  4651. }
  4652. }
  4653. }
  4654. /**
  4655. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4656. **/
  4657. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4658. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4659. void clif_addskill(struct map_session_data *sd, int skill_id)
  4660. {
  4661. int fd;
  4662. uint16 idx = 0;
  4663. nullpo_retv(sd);
  4664. fd = sd->fd;
  4665. if (!fd || !(idx = skill_get_index(skill_id)))
  4666. return;
  4667. if( sd->status.skill[idx].id <= 0 )
  4668. return;
  4669. WFIFOHEAD(fd, packet_len(0x111));
  4670. WFIFOW(fd,0) = 0x111;
  4671. WFIFOW(fd,2) = skill_id;
  4672. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4673. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4674. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4675. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4676. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4677. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4678. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4679. else
  4680. WFIFOB(fd,38) = 0;
  4681. WFIFOSET(fd,packet_len(0x111));
  4682. }
  4683. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4684. /// 0441 <skill id>.W
  4685. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4686. {
  4687. #if PACKETVER >= 20081217
  4688. int fd;
  4689. uint16 idx = 0;
  4690. nullpo_retv(sd);
  4691. fd = sd->fd;
  4692. if (!fd || !(idx = skill_get_index(skill_id)))
  4693. return;
  4694. WFIFOHEAD(fd,packet_len(0x441));
  4695. WFIFOW(fd,0) = 0x441;
  4696. WFIFOW(fd,2) = skill_id;
  4697. WFIFOSET(fd,packet_len(0x441));
  4698. #endif
  4699. clif_skillinfoblock(sd);
  4700. }
  4701. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4702. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4703. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4704. int fd;
  4705. nullpo_retv(sd);
  4706. fd = sd->fd;
  4707. WFIFOHEAD(fd, packet_len(0x10e));
  4708. WFIFOW(fd, 0) = 0x10e;
  4709. WFIFOW(fd, 2) = skill_id;
  4710. WFIFOW(fd, 4) = lv;
  4711. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4712. WFIFOW(fd, 8) = range;
  4713. WFIFOB(fd, 10) = upgradable;
  4714. WFIFOSET(fd, packet_len(0x10e));
  4715. }
  4716. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4717. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4718. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4719. {
  4720. const int fd = sd->fd;
  4721. uint16 idx = skill_get_index(skill_id);
  4722. if (!idx)
  4723. return;
  4724. WFIFOHEAD(fd,packet_len(0x7e1));
  4725. WFIFOW(fd,0) = 0x7e1;
  4726. WFIFOW(fd,2) = skill_id;
  4727. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4728. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4729. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4730. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4731. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4732. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4733. else
  4734. WFIFOB(fd,14) = 0;
  4735. WFIFOSET(fd,packet_len(0x7e1));
  4736. }
  4737. /// Notifies clients in area, that an object is about to use a skill.
  4738. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4739. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4740. /// property:
  4741. /// 0 = Yellow cast aura
  4742. /// 1 = Water elemental cast aura
  4743. /// 2 = Earth elemental cast aura
  4744. /// 3 = Fire elemental cast aura
  4745. /// 4 = Wind elemental cast aura
  4746. /// 5 = Poison elemental cast aura
  4747. /// 6 = Holy elemental cast aura
  4748. /// ? = like 0
  4749. /// is disposable:
  4750. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4751. /// 1 = no text
  4752. 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)
  4753. {
  4754. #if PACKETVER < 20091124
  4755. const int cmd = 0x13e;
  4756. #else
  4757. const int cmd = 0x7fb;
  4758. #endif
  4759. unsigned char buf[32];
  4760. WBUFW(buf,0) = cmd;
  4761. WBUFL(buf,2) = src_id;
  4762. WBUFL(buf,6) = dst_id;
  4763. WBUFW(buf,10) = dst_x;
  4764. WBUFW(buf,12) = dst_y;
  4765. WBUFW(buf,14) = skill_id;
  4766. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4767. WBUFL(buf,20) = casttime;
  4768. #if PACKETVER >= 20091124
  4769. WBUFB(buf,24) = 0; // isDisposable
  4770. #endif
  4771. if (disguised(bl)) {
  4772. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4773. WBUFL(buf,2) = -src_id;
  4774. clif_send(buf,packet_len(cmd), bl, SELF);
  4775. } else
  4776. clif_send(buf,packet_len(cmd), bl, AREA);
  4777. }
  4778. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4779. /// 01b9 <id>.L
  4780. void clif_skillcastcancel(struct block_list* bl)
  4781. {
  4782. unsigned char buf[16];
  4783. nullpo_retv(bl);
  4784. WBUFW(buf,0) = 0x1b9;
  4785. WBUFL(buf,2) = bl->id;
  4786. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4787. }
  4788. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4789. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4790. /// num (only used when skill id = NV_BASIC and cause = 0):
  4791. /// 0 = "skill failed" MsgStringTable[159]
  4792. /// 1 = "no emotions" MsgStringTable[160]
  4793. /// 2 = "no sit" MsgStringTable[161]
  4794. /// 3 = "no chat" MsgStringTable[162]
  4795. /// 4 = "no party" MsgStringTable[163]
  4796. /// 5 = "no shout" MsgStringTable[164]
  4797. /// 6 = "no PKing" MsgStringTable[165]
  4798. /// 7 = "no alligning" MsgStringTable[383]
  4799. /// ? = ignored
  4800. /// cause:
  4801. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4802. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4803. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4804. /// "skill failed" MsgStringTable[204] (otherwise)
  4805. /// ... = @see enum useskill_fail_cause
  4806. /// ? = ignored
  4807. ///
  4808. /// if(result!=0) doesn't display any of the previous messages
  4809. /// Note: when this packet is received an unknown flag is always set to 0,
  4810. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4811. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4812. {
  4813. int fd;
  4814. if (!sd) { //Since this is the most common nullpo....
  4815. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4816. return;
  4817. }
  4818. fd=sd->fd;
  4819. if (!fd) return;
  4820. if(battle_config.display_skill_fail&1)
  4821. return; //Disable all skill failed messages
  4822. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4823. return; //Disable delay failed messages
  4824. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4825. return;
  4826. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4827. return;
  4828. WFIFOHEAD(fd,packet_len(0x110));
  4829. WFIFOW(fd,0) = 0x110;
  4830. WFIFOW(fd,2) = skill_id;
  4831. WFIFOL(fd,4) = btype;
  4832. WFIFOB(fd,8) = 0;// success
  4833. WFIFOB(fd,9) = cause;
  4834. WFIFOSET(fd,packet_len(0x110));
  4835. }
  4836. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4837. /// 043d <skill ID>.W <tick>.L
  4838. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4839. {
  4840. #if PACKETVER>=20081112
  4841. int fd;
  4842. nullpo_retv(sd);
  4843. fd=sd->fd;
  4844. WFIFOHEAD(fd,packet_len(0x43d));
  4845. WFIFOW(fd,0) = 0x43d;
  4846. WFIFOW(fd,2) = skill_id;
  4847. WFIFOL(fd,4) = tick;
  4848. WFIFOSET(fd,packet_len(0x43d));
  4849. #endif
  4850. }
  4851. /// Skill attack effect and damage.
  4852. /// 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)
  4853. /// 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)
  4854. 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)
  4855. {
  4856. unsigned char buf[64];
  4857. struct status_change *sc;
  4858. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4859. nullpo_ret(src);
  4860. nullpo_ret(dst);
  4861. type = clif_calc_delay(type,div,damage,ddelay);
  4862. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4863. if(sc->data[SC_HALLUCINATION] && damage)
  4864. damage = clif_hallucination_damage();
  4865. }
  4866. #if PACKETVER < 3
  4867. WBUFW(buf,0)=0x114;
  4868. WBUFW(buf,2)=skill_id;
  4869. WBUFL(buf,4)=src->id;
  4870. WBUFL(buf,8)=dst->id;
  4871. WBUFL(buf,12)=tick;
  4872. WBUFL(buf,16)=sdelay;
  4873. WBUFL(buf,20)=ddelay;
  4874. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4875. WBUFW(buf,24)=damage?div:0;
  4876. } else {
  4877. WBUFW(buf,24)=damage;
  4878. }
  4879. WBUFW(buf,26)=skill_lv;
  4880. WBUFW(buf,28)=div;
  4881. WBUFB(buf,30)=type;
  4882. if (disguised(dst)) {
  4883. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4884. WBUFL(buf,8)=-dst->id;
  4885. clif_send(buf,packet_len(0x114),dst,SELF);
  4886. } else
  4887. clif_send(buf,packet_len(0x114),dst,AREA);
  4888. if(disguised(src)) {
  4889. WBUFL(buf,4)=-src->id;
  4890. if (disguised(dst))
  4891. WBUFL(buf,8)=dst->id;
  4892. if(damage > 0)
  4893. WBUFW(buf,24)=-1;
  4894. clif_send(buf,packet_len(0x114),src,SELF);
  4895. }
  4896. #else
  4897. WBUFW(buf,0)=0x1de;
  4898. WBUFW(buf,2)=skill_id;
  4899. WBUFL(buf,4)=src->id;
  4900. WBUFL(buf,8)=dst->id;
  4901. WBUFL(buf,12)=tick;
  4902. WBUFL(buf,16)=sdelay;
  4903. WBUFL(buf,20)=ddelay;
  4904. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4905. WBUFL(buf,24)=damage?div:0;
  4906. } else {
  4907. WBUFL(buf,24)=damage;
  4908. }
  4909. WBUFW(buf,28)=skill_lv;
  4910. WBUFW(buf,30)=div;
  4911. // For some reason, late 2013 and newer clients have
  4912. // a issue that causes players and monsters to endure
  4913. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4914. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4915. #if PACKETVER < 20131223
  4916. WBUFB(buf,32)=type;
  4917. #else
  4918. WBUFB(buf,32)=( type == DMG_SKILL ) ? DMG_MULTI_HIT : type;
  4919. #endif
  4920. if (disguised(dst)) {
  4921. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4922. WBUFL(buf,8)=-dst->id;
  4923. clif_send(buf,packet_len(0x1de),dst,SELF);
  4924. } else
  4925. clif_send(buf,packet_len(0x1de),dst,AREA);
  4926. if(disguised(src)) {
  4927. WBUFL(buf,4)=-src->id;
  4928. if (disguised(dst))
  4929. WBUFL(buf,8)=dst->id;
  4930. if(damage > 0)
  4931. WBUFL(buf,24)=-1;
  4932. clif_send(buf,packet_len(0x1de),src,SELF);
  4933. }
  4934. #endif
  4935. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4936. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4937. }
  4938. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4939. /// 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
  4940. /*
  4941. 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)
  4942. {
  4943. unsigned char buf[64];
  4944. struct status_change *sc;
  4945. nullpo_ret(src);
  4946. nullpo_ret(dst);
  4947. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  4948. type = clif_calc_delay(type,div,damage,ddelay);
  4949. sc = status_get_sc(dst);
  4950. if(sc && sc->count) {
  4951. if(sc->data[SC_HALLUCINATION] && damage)
  4952. damage = clif_hallucination_damage();
  4953. }
  4954. WBUFW(buf,0)=0x115;
  4955. WBUFW(buf,2)=skill_id;
  4956. WBUFL(buf,4)=src->id;
  4957. WBUFL(buf,8)=dst->id;
  4958. WBUFL(buf,12)=tick;
  4959. WBUFL(buf,16)=sdelay;
  4960. WBUFL(buf,20)=ddelay;
  4961. WBUFW(buf,24)=dst->x;
  4962. WBUFW(buf,26)=dst->y;
  4963. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4964. WBUFW(buf,28)=damage?div:0;
  4965. } else {
  4966. WBUFW(buf,28)=damage;
  4967. }
  4968. WBUFW(buf,30)=skill_lv;
  4969. WBUFW(buf,32)=div;
  4970. WBUFB(buf,34)=type;
  4971. clif_send(buf,packet_len(0x115),src,AREA);
  4972. if(disguised(src)) {
  4973. WBUFL(buf,4)=-src->id;
  4974. if(damage > 0)
  4975. WBUFW(buf,28)=-1;
  4976. clif_send(buf,packet_len(0x115),src,SELF);
  4977. }
  4978. if (disguised(dst)) {
  4979. WBUFL(buf,8)=-dst->id;
  4980. if (disguised(src))
  4981. WBUFL(buf,4)=src->id;
  4982. else if(damage > 0)
  4983. WBUFW(buf,28)=-1;
  4984. clif_send(buf,packet_len(0x115),dst,SELF);
  4985. }
  4986. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4987. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4988. }
  4989. */
  4990. /// Non-damaging skill effect
  4991. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  4992. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  4993. int clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, int fail)
  4994. {
  4995. unsigned char buf[17];
  4996. #if PACKETVER < 20130731
  4997. const int cmd = 0x11a;
  4998. #else
  4999. const int cmd = 0x9cb;
  5000. #endif
  5001. int offset = 0;
  5002. nullpo_ret(dst);
  5003. WBUFW(buf,0) = cmd;
  5004. WBUFW(buf,2) = skill_id;
  5005. #if PACKETVER < 20130731
  5006. WBUFW(buf,4) = min(heal, INT16_MAX);
  5007. #else
  5008. WBUFL(buf,4) = min(heal, INT32_MAX);
  5009. offset += 2;
  5010. #endif
  5011. WBUFL(buf,6+offset) = dst->id;
  5012. WBUFL(buf,10+offset) = src ? src->id : 0;
  5013. WBUFB(buf,14+offset) = fail;
  5014. if (disguised(dst)) {
  5015. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5016. WBUFL(buf,6+offset) = -dst->id;
  5017. clif_send(buf, packet_len(cmd), dst, SELF);
  5018. } else
  5019. clif_send(buf, packet_len(cmd), dst, AREA);
  5020. if(src && disguised(src)) {
  5021. WBUFL(buf,10+offset) = -src->id;
  5022. if (disguised(dst))
  5023. WBUFL(buf,6+offset) = dst->id;
  5024. clif_send(buf, packet_len(cmd), src, SELF);
  5025. }
  5026. return fail;
  5027. }
  5028. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5029. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5030. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  5031. {
  5032. unsigned char buf[32];
  5033. nullpo_retv(src);
  5034. WBUFW(buf,0)=0x117;
  5035. WBUFW(buf,2)=skill_id;
  5036. WBUFL(buf,4)=src->id;
  5037. WBUFW(buf,8)=val;
  5038. WBUFW(buf,10)=x;
  5039. WBUFW(buf,12)=y;
  5040. WBUFL(buf,14)=tick;
  5041. if(disguised(src)) {
  5042. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5043. WBUFL(buf,4)=-src->id;
  5044. clif_send(buf,packet_len(0x117),src,SELF);
  5045. } else
  5046. clif_send(buf,packet_len(0x117),src,AREA);
  5047. }
  5048. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5049. /// 011c <skill id>.W { <map name>.16B }*4
  5050. 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)
  5051. {
  5052. int fd;
  5053. nullpo_retv(sd);
  5054. fd = sd->fd;
  5055. WFIFOHEAD(fd,packet_len(0x11c));
  5056. WFIFOW(fd,0) = 0x11c;
  5057. WFIFOW(fd,2) = skill_id;
  5058. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5059. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5060. else // normal map name
  5061. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5062. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5063. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5064. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5065. WFIFOSET(fd,packet_len(0x11c));
  5066. sd->menuskill_id = skill_id;
  5067. if (skill_id == AL_WARP) {
  5068. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5069. sd->state.workinprogress = WIP_DISABLE_ALL;
  5070. } else
  5071. sd->menuskill_val = skill_lv;
  5072. }
  5073. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5074. /// 011e <type>.B
  5075. /// type:
  5076. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5077. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5078. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5079. ///
  5080. /// @param sd Who receives the message
  5081. /// @param type What message
  5082. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5083. {
  5084. int fd;
  5085. nullpo_retv(sd);
  5086. fd=sd->fd;
  5087. WFIFOHEAD(fd,packet_len(0x11e));
  5088. WFIFOW(fd,0)=0x11e;
  5089. WFIFOB(fd,2)=type;
  5090. WFIFOSET(fd,packet_len(0x11e));
  5091. }
  5092. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5093. /// 0189 <type>.W
  5094. /// type:
  5095. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5096. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5097. ///
  5098. /// @param sd Who receives the message
  5099. /// @param type What message
  5100. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5101. {
  5102. int fd;
  5103. nullpo_retv(sd);
  5104. fd=sd->fd;
  5105. WFIFOHEAD(fd,packet_len(0x189));
  5106. WFIFOW(fd,0)=0x189;
  5107. WFIFOW(fd,2)=type;
  5108. WFIFOSET(fd,packet_len(0x189));
  5109. }
  5110. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5111. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5112. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5113. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5114. {
  5115. struct status_data *status;
  5116. unsigned char buf[64];
  5117. int i;//, fix;
  5118. nullpo_retv(sd);
  5119. nullpo_retv(dst);
  5120. if( dst->type != BL_MOB )
  5121. return;
  5122. status = status_get_status_data(dst);
  5123. WBUFW(buf, 0)=0x18c;
  5124. WBUFW(buf, 2)=status_get_class(dst);
  5125. WBUFW(buf, 4)=status_get_lv(dst);
  5126. WBUFW(buf, 6)=status->size;
  5127. WBUFL(buf, 8)=status->hp;
  5128. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5129. +(battle_config.estimation_type&2?status->def2:0);
  5130. WBUFW(buf,14)=status->race;
  5131. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5132. +(battle_config.estimation_type&2?status->mdef2:0);
  5133. WBUFW(buf,18)= status->def_ele;
  5134. for(i=0;i<9;i++)
  5135. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  5136. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5137. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  5138. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5139. }
  5140. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5141. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5142. /// material id:
  5143. /// unused by the client
  5144. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  5145. {
  5146. int i,c,view,fd;
  5147. nullpo_retv(sd);
  5148. if (sd->menuskill_id == skill_id)
  5149. return; //Avoid resending the menu twice or more times...
  5150. if (skill_id == GC_CREATENEWPOISON)
  5151. skill_id = GC_RESEARCHNEWPOISON;
  5152. fd = sd->fd;
  5153. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  5154. WFIFOW(fd, 0) = 0x18d;
  5155. for (i = 0, c = 0; i < MAX_SKILL_PRODUCE_DB; i++){
  5156. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5157. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  5158. )
  5159. {
  5160. if ((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  5161. WFIFOW(fd,c*8+ 4) = view;
  5162. else
  5163. WFIFOW(fd,c*8+ 4) = skill_produce_db[i].nameid;
  5164. WFIFOW(fd,c*8+ 6) = 0;
  5165. WFIFOW(fd,c*8+ 8) = 0;
  5166. WFIFOW(fd,c*8+10) = 0;
  5167. c++;
  5168. }
  5169. }
  5170. WFIFOW(fd, 2) = c*8+8;
  5171. WFIFOSET(fd,WFIFOW(fd,2));
  5172. if (c > 0) {
  5173. sd->menuskill_id = skill_id;
  5174. sd->menuskill_val = trigger;
  5175. return;
  5176. }
  5177. }
  5178. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5179. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5180. /// mk type:
  5181. /// 1 = cooking
  5182. /// 2 = arrow
  5183. /// 3 = elemental
  5184. /// 4 = GN_MIX_COOKING
  5185. /// 5 = GN_MAKEBOMB
  5186. /// 6 = GN_S_PHARMACY
  5187. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  5188. {
  5189. int fd;
  5190. int i, c;
  5191. int view;
  5192. nullpo_retv(sd);
  5193. fd = sd->fd;
  5194. if(sd->menuskill_id == skill_id)
  5195. return; //Avoid resending the menu twice or more times...
  5196. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  5197. WFIFOW(fd,0) = 0x25a;
  5198. WFIFOW(fd,4) = list_type; // list type
  5199. c = 0;
  5200. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  5201. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  5202. continue;
  5203. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  5204. WFIFOW(fd, 6 + 2 * c) = view;
  5205. else
  5206. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  5207. c++;
  5208. }
  5209. if( c > 0 || skill_id == AM_PHARMACY) {
  5210. sd->menuskill_id = skill_id;
  5211. sd->menuskill_val = trigger;
  5212. sd->menuskill_val2 = qty; // amount.
  5213. WFIFOW(fd,2) = 6 + 2 * c;
  5214. WFIFOSET(fd,WFIFOW(fd,2));
  5215. } else {
  5216. clif_menuskill_clear(sd);
  5217. #if PACKETVER >= 20090922
  5218. clif_msg_skill(sd,skill_id,INVENTORY_SPACE_FULL);
  5219. #else
  5220. WFIFOW(fd,2) = 6 + 2 * c;
  5221. WFIFOSET(fd,WFIFOW(fd,2));
  5222. #endif
  5223. }
  5224. }
  5225. /// Notifies clients of a status change.
  5226. /// 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)]
  5227. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5228. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5229. /// @param bl Sends packet to clients around this object
  5230. /// @param id ID of object that has this effect
  5231. /// @param type Status icon see enum efst_types
  5232. /// @param flag 1:Active, 0:Deactive
  5233. /// @param tick Duration in ms
  5234. /// @param val1
  5235. /// @param val2
  5236. /// @param val3
  5237. 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)
  5238. {
  5239. unsigned char buf[32];
  5240. if (type == EFST_BLANK) //It shows nothing on the client...
  5241. return;
  5242. if (type == EFST_POSTDELAY && tick == 0)
  5243. return;
  5244. nullpo_retv(bl);
  5245. #if PACKETVER >= 20120618
  5246. if (flag && battle_config.display_status_timers)
  5247. WBUFW(buf,0) = 0x983;
  5248. else
  5249. #elif PACKETVER >= 20090121
  5250. if (flag && battle_config.display_status_timers)
  5251. WBUFW(buf,0) = 0x43f;
  5252. else
  5253. #endif
  5254. WBUFW(buf,0) = 0x196;
  5255. WBUFW(buf,2) = type;
  5256. WBUFL(buf,4) = id;
  5257. WBUFB(buf,8) = flag;
  5258. #if PACKETVER >= 20120618
  5259. if (flag && battle_config.display_status_timers) {
  5260. if (tick <= 0)
  5261. tick = 9999; // this is indeed what official servers do
  5262. WBUFL(buf,9) = tick;/* at this stage remain and total are the same value I believe */
  5263. WBUFL(buf,13) = tick;
  5264. WBUFL(buf,17) = val1;
  5265. WBUFL(buf,21) = val2;
  5266. WBUFL(buf,25) = val3;
  5267. }
  5268. #elif PACKETVER >= 20090121
  5269. if (flag && battle_config.display_status_timers) {
  5270. if (tick <= 0)
  5271. tick = 9999; // this is indeed what official servers do
  5272. WBUFL(buf,9) = tick;
  5273. WBUFL(buf,13) = val1;
  5274. WBUFL(buf,17) = val2;
  5275. WBUFL(buf,21) = val3;
  5276. }
  5277. #endif
  5278. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5279. }
  5280. /* Sends status effect to clients around the bl
  5281. * @param bl Object that has the effect
  5282. * @param type Status icon see enum efst_types
  5283. * @param flag 1:Active, 0:Deactive
  5284. * @param tick Duration in ms
  5285. * @param val1
  5286. * @param val2
  5287. * @param val3
  5288. */
  5289. void clif_status_change(struct block_list *bl, int type, int flag, int tick, int val1, int val2, int val3) {
  5290. struct map_session_data *sd = NULL;
  5291. if (type == EFST_BLANK) //It shows nothing on the client...
  5292. return;
  5293. if (type == EFST_POSTDELAY && tick == 0)
  5294. return;
  5295. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5296. return;
  5297. nullpo_retv(bl);
  5298. sd = BL_CAST(BL_PC, bl);
  5299. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  5300. return;
  5301. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5302. }
  5303. /**
  5304. * Send any active EFST to those around.
  5305. * @param tbl: Unit to send the packet to
  5306. * @param bl: Objects walking into view
  5307. * @param target: Client send type
  5308. */
  5309. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5310. unsigned char i;
  5311. struct sc_display_entry **sc_display;
  5312. unsigned char sc_display_count;
  5313. bool spheres_sent;
  5314. nullpo_retv(bl);
  5315. switch( bl->type ){
  5316. case BL_PC: {
  5317. struct map_session_data* sd = (struct map_session_data*)bl;
  5318. sc_display = sd->sc_display;
  5319. sc_display_count = sd->sc_display_count;
  5320. spheres_sent = !sd->state.connect_new;
  5321. }
  5322. break;
  5323. case BL_NPC: {
  5324. struct npc_data* nd = (struct npc_data*)bl;
  5325. sc_display = nd->sc_display;
  5326. sc_display_count = nd->sc_display_count;
  5327. spheres_sent = true;
  5328. }
  5329. break;
  5330. default:
  5331. return;
  5332. }
  5333. for (i = 0; i < sc_display_count; i++) {
  5334. enum sc_type type = sc_display[i]->type;
  5335. struct status_change *sc = status_get_sc(bl);
  5336. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5337. int tick = 0;
  5338. if (td)
  5339. tick = DIFF_TICK(td->tick, gettick());
  5340. if( spheres_sent && type >= SC_SPHERE_1 && type <= SC_SPHERE_5 ){
  5341. #if PACKETVER > 20120418
  5342. clif_efst_status_change(tbl, bl->id, AREA_WOS, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5343. #else
  5344. clif_status_change_sub(tbl, bl->id, StatusIconChangeTable[type], 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, AREA_WOS);
  5345. #endif
  5346. }else{
  5347. #if PACKETVER > 20120418
  5348. clif_efst_status_change(tbl, bl->id, target, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5349. #else
  5350. clif_status_change_sub(tbl, bl->id, StatusIconChangeTable[type], 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, target);
  5351. #endif
  5352. }
  5353. }
  5354. }
  5355. /// Notifies the client when a player enters the screen with an active EFST.
  5356. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5357. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5358. 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) {
  5359. #if PACKETVER >= 20111108
  5360. unsigned char buf[32];
  5361. #if PACKETVER >= 20120618
  5362. const int cmd = 0x984;
  5363. #elif PACKETVER >= 20111108
  5364. const int cmd = 0x8ff;
  5365. #endif
  5366. int offset = 0;
  5367. if (type == EFST_BLANK)
  5368. return;
  5369. nullpo_retv(bl);
  5370. if (tick <= 0)
  5371. tick = 9999;
  5372. WBUFW(buf,offset + 0) = cmd;
  5373. WBUFL(buf,offset + 2) = tid;
  5374. WBUFW(buf,offset + 6) = type;
  5375. #if PACKETVER >= 20111108
  5376. WBUFL(buf,offset + 8) = tick; // Set remaining status duration [exneval]
  5377. #if PACKETVER >= 20120618
  5378. WBUFL(buf,offset + 12) = tick;
  5379. offset += 4;
  5380. #endif
  5381. WBUFL(buf,offset + 12) = val1;
  5382. WBUFL(buf,offset + 16) = val2;
  5383. WBUFL(buf,offset + 20) = val3;
  5384. #endif
  5385. clif_send(buf,packet_len(cmd),bl,target);
  5386. #endif
  5387. }
  5388. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5389. /// 008e <packet len>.W <message>.?B
  5390. void clif_displaymessage(const int fd, const char* mes)
  5391. {
  5392. nullpo_retv(mes);
  5393. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  5394. if (fd == 0)
  5395. ;
  5396. else {
  5397. char *message, *line;
  5398. message = aStrdup(mes);
  5399. line = strtok(message, "\n");
  5400. #if PACKETVER == 20141022
  5401. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5402. /** so we redirect to ZC_NPC_CHAT **/
  5403. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5404. while(line != NULL) {
  5405. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5406. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5407. if (len > 0) {
  5408. WFIFOHEAD(fd, 13 + len);
  5409. WFIFOW(fd, 0) = 0x2C1;
  5410. WFIFOW(fd, 2) = 13 + len;
  5411. WFIFOL(fd, 4) = 0;
  5412. WFIFOL(fd, 8) = color;
  5413. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5414. WFIFOSET(fd, WFIFOW(fd, 2));
  5415. }
  5416. #else
  5417. while(line != NULL) {
  5418. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5419. int len = strnlen(line, CHAT_SIZE_MAX);
  5420. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5421. WFIFOHEAD(fd, 5 + len);
  5422. WFIFOW(fd,0) = 0x8e;
  5423. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5424. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5425. WFIFOSET(fd, 5 + len);
  5426. }
  5427. #endif
  5428. line = strtok(NULL, "\n");
  5429. }
  5430. aFree(message);
  5431. }
  5432. }
  5433. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5434. /// 009a <packet len>.W <message>.?B
  5435. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5436. {
  5437. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  5438. std::unique_ptr<unsigned char> buf(new unsigned char[4+lp+len]);
  5439. WBUFW(buf.get(),0) = 0x9a;
  5440. WBUFW(buf.get(),2) = 4 + lp + len;
  5441. if (type&BC_BLUE)
  5442. WBUFL(buf.get(),4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  5443. else if (type&BC_WOE)
  5444. WBUFL(buf.get(),4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5445. memcpy(WBUFP(buf.get(), 4 + lp), mes, len);
  5446. clif_send(buf.get(), WBUFW(buf.get(),2), bl, target);
  5447. }
  5448. /*==========================================
  5449. * Displays a message on a 'bl' to all it's nearby clients
  5450. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5451. *------------------------------------------*/
  5452. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5453. size_t len;
  5454. nullpo_retv(bl);
  5455. if(!message)
  5456. return;
  5457. len = strlen(message)+1;
  5458. static_assert(CHAT_SIZE_MAX > 8, "CHAT_SIZE_MAX too small for packet");
  5459. if( len > CHAT_SIZE_MAX ) {
  5460. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  5461. len = CHAT_SIZE_MAX;
  5462. }
  5463. std::unique_ptr<char> buf(new char[8+len]);
  5464. WBUFW(buf.get(),0)=0x8d;
  5465. WBUFW(buf.get(),2)=static_cast<uint16>(len+8);
  5466. WBUFL(buf.get(),4)=bl->id;
  5467. safestrncpy(WBUFCP(buf.get(),8),message,len);
  5468. clif_send((unsigned char *)buf.get(),WBUFW(buf.get(),2),bl,target);
  5469. }
  5470. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  5471. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  5472. 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)
  5473. {
  5474. std::unique_ptr<unsigned char> buf(new unsigned char[16+len]);
  5475. WBUFW(buf.get(),0) = 0x1c3;
  5476. WBUFW(buf.get(),2) = len + 16;
  5477. WBUFL(buf.get(),4) = fontColor;
  5478. WBUFW(buf.get(),8) = fontType;
  5479. WBUFW(buf.get(),10) = fontSize;
  5480. WBUFW(buf.get(),12) = fontAlign;
  5481. WBUFW(buf.get(),14) = fontY;
  5482. memcpy(WBUFP(buf.get(),16), mes, len);
  5483. clif_send(buf.get(), WBUFW(buf.get(),2), bl, target);
  5484. }
  5485. /*
  5486. * Display *msg to all *users in channel
  5487. */
  5488. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5489. DBIterator *iter;
  5490. struct map_session_data *user;
  5491. unsigned short msg_len = 0, len = 0;
  5492. unsigned char buf[CHAT_SIZE_MAX];
  5493. if (!channel || !msg)
  5494. return;
  5495. msg_len = (unsigned short)(strlen(msg) + 1);
  5496. if( msg_len > sizeof(buf)-12 ) {
  5497. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5498. msg_len = sizeof(buf)-12;
  5499. }
  5500. WBUFW(buf,0) = 0x2C1;
  5501. WBUFW(buf,2) = (len = msg_len + 12);
  5502. WBUFL(buf,4) = 0;
  5503. WBUFL(buf,8) = color;
  5504. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5505. iter = db_iterator(channel->users);
  5506. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5507. clif_send(buf, len, &user->bl, SELF);
  5508. }
  5509. dbi_destroy(iter);
  5510. }
  5511. /// Displays heal effect.
  5512. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5513. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5514. /// var id:
  5515. /// 5 = HP (SP_HP)
  5516. /// 7 = SP (SP_SP)
  5517. /// ? = ignored
  5518. void clif_heal(int fd,int type,int val) {
  5519. #if PACKETVER < 20141022
  5520. const int cmd = 0x13d;
  5521. #else
  5522. const int cmd = 0xa27;
  5523. #endif
  5524. WFIFOHEAD(fd, packet_len(cmd));
  5525. WFIFOW(fd,0) = cmd;
  5526. WFIFOW(fd,2) = type;
  5527. #if PACKETVER < 20141022
  5528. WFIFOW(fd,4) = min(val, INT16_MAX);
  5529. #else
  5530. WFIFOL(fd,4) = min(val, INT32_MAX);
  5531. #endif
  5532. WFIFOSET(fd, packet_len(cmd));
  5533. }
  5534. /// Displays resurrection effect (ZC_RESURRECTION).
  5535. /// 0148 <id>.L <type>.W
  5536. /// type:
  5537. /// ignored
  5538. void clif_resurrection(struct block_list *bl,int type)
  5539. {
  5540. unsigned char buf[16];
  5541. nullpo_retv(bl);
  5542. WBUFW(buf,0)=0x148;
  5543. WBUFL(buf,2)=bl->id;
  5544. WBUFW(buf,6)=0;
  5545. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5546. if (disguised(bl))
  5547. clif_spawn(bl);
  5548. }
  5549. /// Sets the map property
  5550. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5551. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5552. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5553. {
  5554. #if PACKETVER >= 20121010
  5555. short cmd = 0x99b;
  5556. unsigned char buf[8];
  5557. #else
  5558. short cmd = 0x199;
  5559. unsigned char buf[4];
  5560. #endif
  5561. WBUFW(buf,0)=cmd;
  5562. WBUFW(buf,2)=property;
  5563. #if PACKETVER >= 20121010
  5564. WBUFL(buf,4) = ((map_getmapflag(bl->m, MF_PVP)?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5565. ((map_getmapflag(bl->m, MF_BATTLEGROUND) || map_flag_gvg2(bl->m)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5566. ((map_getmapflag(bl->m, MF_BATTLEGROUND) || map_flag_gvg2(bl->m)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5567. ((map_getmapflag(bl->m, MF_NOMINEEFFECT) || !map_flag_gvg2(bl->m)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5568. ((map_getmapflag(bl->m, MF_NOLOCKON) || map_flag_vs(bl->m)?1:0)<<4)| // DISABLE_LOCKON - Only allow attacks on other players with shift key or /ns active
  5569. ((map_getmapflag(bl->m, MF_PVP)?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5570. ((map_getmapflag(bl->m, MF_PARTYLOCK)?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5571. ((map_getmapflag(bl->m, MF_BATTLEGROUND)?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5572. ((map_getmapflag(bl->m, MF_NOCOSTUME)?1:0)<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5573. ((map_getmapflag(bl->m, MF_NOUSECART)?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5574. ((map_getmapflag(bl->m, MF_NOSUNMOONSTARMIRACLE)?0:1)<<10); // SUNMOONSTAR_MIRACLE - Blocks Star Gladiator's Miracle from activating
  5575. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5576. #endif
  5577. clif_send(buf,packet_len(cmd),bl,t);
  5578. }
  5579. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5580. /// 01d6 <type>.W
  5581. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5582. {
  5583. int fd;
  5584. nullpo_retv(sd);
  5585. fd=sd->fd;
  5586. WFIFOHEAD(fd,packet_len(0x1D6));
  5587. WFIFOW(fd,0)=0x1D6;
  5588. WFIFOW(fd,2)=type;
  5589. WFIFOSET(fd,packet_len(0x1D6));
  5590. }
  5591. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5592. /// 019a <id>.L <ranking>.L <total>.L
  5593. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5594. {
  5595. if(type == 2) {
  5596. int fd = sd->fd;
  5597. WFIFOHEAD(fd,packet_len(0x19a));
  5598. WFIFOW(fd,0) = 0x19a;
  5599. WFIFOL(fd,2) = sd->bl.id;
  5600. WFIFOL(fd,6) = pvprank;
  5601. WFIFOL(fd,10) = pvpnum;
  5602. WFIFOSET(fd,packet_len(0x19a));
  5603. } else {
  5604. unsigned char buf[32];
  5605. WBUFW(buf,0) = 0x19a;
  5606. WBUFL(buf,2) = sd->bl.id;
  5607. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5608. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5609. else
  5610. WBUFL(buf,6) = pvprank;
  5611. WBUFL(buf,10) = pvpnum;
  5612. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5613. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5614. else if(!type)
  5615. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5616. else
  5617. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5618. }
  5619. }
  5620. /*==========================================
  5621. *
  5622. *------------------------------------------*/
  5623. void clif_map_property_mapall(int map_idx, enum map_property property)
  5624. {
  5625. struct block_list bl;
  5626. bl.id = 0;
  5627. bl.type = BL_NUL;
  5628. bl.m = map_idx;
  5629. clif_map_property( &bl, property, ALL_SAMEMAP );
  5630. }
  5631. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5632. /// 0188 <result>.W <index>.W <refine>.W
  5633. /// result:
  5634. /// 0 = success
  5635. /// 1 = failure
  5636. /// 2 = downgrade
  5637. void clif_refine(int fd, int fail, int index, int val)
  5638. {
  5639. WFIFOHEAD(fd,packet_len(0x188));
  5640. WFIFOW(fd,0)=0x188;
  5641. WFIFOW(fd,2)=fail;
  5642. WFIFOW(fd,4)=index+2;
  5643. WFIFOW(fd,6)=val;
  5644. WFIFOSET(fd,packet_len(0x188));
  5645. }
  5646. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5647. /// 0223 <result>.L <nameid>.W
  5648. /// result:
  5649. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5650. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5651. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5652. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5653. void clif_upgrademessage(int fd, int result, unsigned short item_id)
  5654. {
  5655. WFIFOHEAD(fd,packet_len(0x223));
  5656. WFIFOW(fd,0)=0x223;
  5657. WFIFOL(fd,2)=result;
  5658. WFIFOW(fd,6)=item_id;
  5659. WFIFOSET(fd,packet_len(0x223));
  5660. }
  5661. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5662. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5663. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5664. void clif_wis_message(struct map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  5665. int fd;
  5666. nullpo_retv(sd);
  5667. fd = sd->fd;
  5668. #if PACKETVER < 20091104
  5669. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5670. WFIFOW(fd,0) = 0x97;
  5671. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5672. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5673. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5674. WFIFOSET(fd,WFIFOW(fd,2));
  5675. #else
  5676. struct map_session_data *ssd = map_nick2sd(nick,false);
  5677. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5678. WFIFOW(fd,0) = 0x97;
  5679. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5680. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5681. // If it is not a message from the server or a player from another map-server
  5682. if( ssd ){
  5683. gmlvl = pc_get_group_level(ssd);
  5684. }
  5685. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5686. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5687. WFIFOSET(fd,WFIFOW(fd,2));
  5688. #endif
  5689. }
  5690. /// Inform the player about the result of his whisper action
  5691. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5692. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5693. /// result:
  5694. /// 0 = success to send wisper
  5695. /// 1 = target character is not loged in
  5696. /// 2 = ignored by target
  5697. /// 3 = everyone ignored by target
  5698. void clif_wis_end(int fd, int result)
  5699. {
  5700. struct map_session_data *sd = (session_isValid(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5701. #if PACKETVER < 20131223
  5702. const int cmd = 0x98;
  5703. #else
  5704. const int cmd = 0x9df;
  5705. #endif
  5706. if (!sd)
  5707. return;
  5708. WFIFOHEAD(fd,packet_len(cmd));
  5709. WFIFOW(fd,0) = cmd;
  5710. WFIFOB(fd,2) = (char)result;
  5711. #if PACKETVER >= 20131223
  5712. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5713. #endif
  5714. WFIFOSET(fd,packet_len(cmd));
  5715. }
  5716. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5717. /// 0194 <char id>.L <name>.24B
  5718. /// 0af7 <flag>.W <char id>.L <name>.24B
  5719. void clif_solved_charname(int fd, int charid, const char* name)
  5720. {
  5721. #if PACKETVER >= 20180221
  5722. WFIFOHEAD(fd,packet_len(0xaf7));
  5723. WFIFOW(fd,0) = 0xaf7;
  5724. WFIFOW(fd,2) = name[0] ? 3 : 2;
  5725. WFIFOL(fd,4) = charid;
  5726. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  5727. WFIFOSET(fd,packet_len(0x0af7));
  5728. #else
  5729. WFIFOHEAD(fd,packet_len(0x194));
  5730. WFIFOW(fd,0)=0x194;
  5731. WFIFOL(fd,2)=charid;
  5732. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5733. WFIFOSET(fd,packet_len(0x194));
  5734. #endif
  5735. }
  5736. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5737. /// 017b <packet len>.W { <name id>.W }*
  5738. void clif_use_card(struct map_session_data *sd,int idx)
  5739. {
  5740. int i,c,ep;
  5741. int fd=sd->fd;
  5742. nullpo_retv(sd);
  5743. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5744. return;
  5745. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5746. return; //Avoid parsing invalid item indexes (no card/no item)
  5747. ep=sd->inventory_data[idx]->equip;
  5748. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5749. WFIFOW(fd,0)=0x17b;
  5750. for(i=c=0;i<MAX_INVENTORY;i++){
  5751. int j;
  5752. if(sd->inventory_data[i] == NULL)
  5753. continue;
  5754. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5755. continue;
  5756. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  5757. continue;
  5758. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  5759. continue;
  5760. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5761. continue;
  5762. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5763. continue;
  5764. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  5765. if( j == sd->inventory_data[i]->slot ) // No room
  5766. continue;
  5767. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  5768. continue;
  5769. WFIFOW(fd,4+c*2)=i+2;
  5770. c++;
  5771. }
  5772. if( !c ) return; // no item is available for card insertion
  5773. WFIFOW(fd,2)=4+c*2;
  5774. WFIFOSET(fd,WFIFOW(fd,2));
  5775. }
  5776. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5777. /// 017d <equip index>.W <card index>.W <result>.B
  5778. /// result:
  5779. /// 0 = success
  5780. /// 1 = failure
  5781. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5782. {
  5783. int fd;
  5784. nullpo_retv(sd);
  5785. fd=sd->fd;
  5786. WFIFOHEAD(fd,packet_len(0x17d));
  5787. WFIFOW(fd,0)=0x17d;
  5788. WFIFOW(fd,2)=idx_equip+2;
  5789. WFIFOW(fd,4)=idx_card+2;
  5790. WFIFOB(fd,6)=flag;
  5791. WFIFOSET(fd,packet_len(0x17d));
  5792. }
  5793. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5794. /// 0177 <packet len>.W { <name id>.W }*
  5795. void clif_item_identify_list(struct map_session_data *sd)
  5796. {
  5797. int i,c;
  5798. int fd;
  5799. nullpo_retv(sd);
  5800. fd=sd->fd;
  5801. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5802. WFIFOW(fd,0)=0x177;
  5803. for(i=c=0;i<MAX_INVENTORY;i++){
  5804. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  5805. WFIFOW(fd,c*2+4)=i+2;
  5806. c++;
  5807. }
  5808. }
  5809. if(c > 0) {
  5810. WFIFOW(fd,2)=c*2+4;
  5811. WFIFOSET(fd,WFIFOW(fd,2));
  5812. sd->menuskill_id = MC_IDENTIFY;
  5813. sd->menuskill_val = c;
  5814. sd->state.workinprogress = WIP_DISABLE_ALL;
  5815. }
  5816. }
  5817. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5818. /// 0179 <index>.W <result>.B
  5819. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5820. {
  5821. int fd;
  5822. nullpo_retv(sd);
  5823. fd=sd->fd;
  5824. WFIFOHEAD(fd,packet_len(0x179));
  5825. WFIFOW(fd, 0)=0x179;
  5826. WFIFOW(fd, 2)=idx+2;
  5827. WFIFOB(fd, 4)=flag;
  5828. WFIFOSET(fd,packet_len(0x179));
  5829. }
  5830. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5831. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5832. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5833. {
  5834. int i,c;
  5835. int fd;
  5836. nullpo_retv(sd);
  5837. nullpo_retv(dstsd);
  5838. fd=sd->fd;
  5839. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5840. WFIFOW(fd,0)=0x1fc;
  5841. for(i=c=0;i<MAX_INVENTORY;i++){
  5842. unsigned short nameid;
  5843. if((nameid=dstsd->inventory.u.items_inventory[i].nameid) > 0 && dstsd->inventory.u.items_inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5844. WFIFOW(fd,c*13+4) = i;
  5845. WFIFOW(fd,c*13+6) = nameid;
  5846. WFIFOB(fd,c*13+8) = dstsd->inventory.u.items_inventory[i].refine;
  5847. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->inventory.u.items_inventory[i]);
  5848. c++;
  5849. }
  5850. }
  5851. if(c > 0) {
  5852. WFIFOW(fd,2)=c*13+4;
  5853. WFIFOSET(fd,WFIFOW(fd,2));
  5854. sd->menuskill_id = BS_REPAIRWEAPON;
  5855. sd->menuskill_val = dstsd->bl.id;
  5856. sd->menuskill_val2 = lv;
  5857. }else
  5858. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5859. }
  5860. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5861. /// 01fe <index>.W <result>.B
  5862. /// index:
  5863. /// ignored (inventory index)
  5864. /// result:
  5865. /// 0 = Item repair success.
  5866. /// 1 = Item repair failure.
  5867. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5868. {
  5869. int fd;
  5870. nullpo_retv(sd);
  5871. fd = sd->fd;
  5872. WFIFOHEAD(fd,packet_len(0x1fe));
  5873. WFIFOW(fd, 0)=0x1fe;
  5874. WFIFOW(fd, 2)=idx+2;
  5875. WFIFOB(fd, 4)=flag;
  5876. WFIFOSET(fd,packet_len(0x1fe));
  5877. }
  5878. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5879. /// 02bb <equip location>.W <account id>.L
  5880. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5881. {
  5882. int fd = sd->fd;
  5883. WFIFOHEAD(fd,packet_len(0x2bb));
  5884. WFIFOW(fd,0) = 0x2bb;
  5885. WFIFOW(fd,2) = position;
  5886. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5887. WFIFOSET(fd,packet_len(0x2bb));
  5888. }
  5889. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5890. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5891. void clif_item_refine_list(struct map_session_data *sd)
  5892. {
  5893. int i,c;
  5894. int fd;
  5895. uint16 skill_lv;
  5896. int refine_item[5];
  5897. nullpo_retv(sd);
  5898. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5899. fd=sd->fd;
  5900. refine_item[0] = -1;
  5901. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5902. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5903. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5904. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5905. WFIFOW(fd,0) = 0x221;
  5906. for(i = c = 0; i < MAX_INVENTORY; i++) {
  5907. unsigned char wlv;
  5908. if(sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  5909. sd->inventory.u.items_inventory[i].identify && (wlv = itemdb_wlv(sd->inventory.u.items_inventory[i].nameid)) >=1 &&
  5910. refine_item[wlv] != -1 && !(sd->inventory.u.items_inventory[i].equip&EQP_ARMS)){
  5911. WFIFOW(fd,c*13+ 4)=i+2;
  5912. WFIFOW(fd,c*13+ 6) = sd->inventory.u.items_inventory[i].nameid;
  5913. WFIFOB(fd,c*13+ 8) = sd->inventory.u.items_inventory[i].refine;
  5914. clif_addcards(WFIFOP(fd,c*13+9), &sd->inventory.u.items_inventory[i]);
  5915. c++;
  5916. }
  5917. }
  5918. WFIFOW(fd,2)=c*13+4;
  5919. WFIFOSET(fd,WFIFOW(fd,2));
  5920. if (c > 0) {
  5921. sd->menuskill_id = WS_WEAPONREFINE;
  5922. sd->menuskill_val = skill_lv;
  5923. }
  5924. }
  5925. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5926. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5927. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5928. {
  5929. int fd;
  5930. nullpo_retv(sd);
  5931. fd=sd->fd;
  5932. WFIFOHEAD(fd,packet_len(0x147));
  5933. WFIFOW(fd, 0)=0x147;
  5934. WFIFOW(fd, 2)=skill_id;
  5935. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5936. WFIFOW(fd, 6)=0;
  5937. WFIFOW(fd, 8)=skill_lv;
  5938. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5939. WFIFOW(fd,12)=skill_get_range2(&sd->bl,skill_id,skill_lv,false);
  5940. safestrncpy(WFIFOCP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5941. WFIFOB(fd,38)=0;
  5942. WFIFOSET(fd,packet_len(0x147));
  5943. }
  5944. /// Adds an item to character's cart.
  5945. /// 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)
  5946. /// 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)
  5947. /// 0a0b <index>.W <amount>.L <name id>.W <type>.B <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W { <option id>.W <option value>.W <option param>.B }*5 (ZC_ADD_ITEM_TO_CART3)
  5948. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5949. {
  5950. #if PACKETVER < 5
  5951. const int cmd = 0x124;
  5952. #elif PACKETVER < 20150225
  5953. const int cmd = 0x1c5;
  5954. #else
  5955. const int cmd = 0xa0b;
  5956. #endif
  5957. int view,fd;
  5958. unsigned char *buf;
  5959. int offset = 0;
  5960. nullpo_retv(sd);
  5961. fd=sd->fd;
  5962. if(n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid <= 0)
  5963. return;
  5964. WFIFOHEAD(fd,packet_len(cmd));
  5965. buf=WFIFOP(fd,0);
  5966. WBUFW(buf,0)=cmd;
  5967. WBUFW(buf,2)=n+2;
  5968. WBUFL(buf,4)=amount;
  5969. if((view = itemdb_viewid(sd->cart.u.items_cart[n].nameid)) > 0)
  5970. WBUFW(buf,8)=view;
  5971. else
  5972. WBUFW(buf,8)=sd->cart.u.items_cart[n].nameid;
  5973. #if PACKETVER >= 5
  5974. WBUFB(buf,10)=itemdb_type(sd->cart.u.items_cart[n].nameid);
  5975. offset += 1;
  5976. #endif
  5977. WBUFB(buf,10+offset)=sd->cart.u.items_cart[n].identify;
  5978. WBUFB(buf,11+offset)=sd->cart.u.items_cart[n].attribute;
  5979. WBUFB(buf,12+offset)=sd->cart.u.items_cart[n].refine;
  5980. clif_addcards(WBUFP(buf,13+offset), &sd->cart.u.items_cart[n]);
  5981. #if PACKETVER >= 20150225
  5982. clif_add_random_options(WBUFP(buf,21+offset), &sd->cart.u.items_cart[n]);
  5983. #endif
  5984. WFIFOSET(fd,packet_len(cmd));
  5985. }
  5986. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5987. /* Acknowledge an item have been added to cart
  5988. * 012c <result>B
  5989. * result :
  5990. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5991. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  5992. */
  5993. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  5994. {
  5995. int fd;
  5996. unsigned char *buf;
  5997. nullpo_retv(sd);
  5998. fd = sd->fd;
  5999. buf = WFIFOP(fd,0);
  6000. WBUFW(buf,0) = 0x12c;
  6001. WBUFB(buf,2) = flag;
  6002. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6003. }
  6004. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6005. void clif_bank_open(struct map_session_data *sd){
  6006. int fd;
  6007. nullpo_retv(sd);
  6008. fd = sd->fd;
  6009. WFIFOHEAD(fd,4);
  6010. WFIFOW(fd,0) = 0x09b7;
  6011. WFIFOW(fd,2) = 0;
  6012. WFIFOSET(fd,4);
  6013. }
  6014. /*
  6015. * Request to Open the banking system
  6016. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6017. */
  6018. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  6019. //TODO check if preventing trade or stuff like that
  6020. //also mark something in case char ain't available for saving, should we check now ?
  6021. nullpo_retv(sd);
  6022. if( !battle_config.feature_banking ) {
  6023. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6024. return;
  6025. }
  6026. else {
  6027. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6028. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6029. if(sd->status.account_id == aid){
  6030. sd->state.banking = 1;
  6031. //request save ?
  6032. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6033. //on succes open bank ?
  6034. clif_bank_open(sd);
  6035. }
  6036. }
  6037. }
  6038. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6039. void clif_bank_close(struct map_session_data *sd){
  6040. int fd;
  6041. nullpo_retv(sd);
  6042. fd = sd->fd;
  6043. WFIFOHEAD(fd,4);
  6044. WFIFOW(fd,0) = 0x09B9;
  6045. WFIFOW(fd,2) = 0;
  6046. WFIFOSET(fd,4);
  6047. }
  6048. /*
  6049. * Request to close the banking system
  6050. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6051. */
  6052. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6053. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6054. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6055. nullpo_retv(sd);
  6056. if( !battle_config.feature_banking ) {
  6057. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6058. //still allow to go trough to not stuck player if we have disable it while they was in
  6059. }
  6060. if(sd->status.account_id == aid){
  6061. sd->state.banking = 0;
  6062. clif_bank_close(sd);
  6063. }
  6064. }
  6065. /*
  6066. * Display how much we got in bank (I suppose)
  6067. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  6068. */
  6069. void clif_Bank_Check(struct map_session_data* sd) {
  6070. unsigned char buf[13];
  6071. struct s_packet_db* info;
  6072. int16 len;
  6073. int cmd = 0;
  6074. nullpo_retv(sd);
  6075. cmd = packet_db_ack[ZC_BANKING_CHECK];
  6076. if(!cmd) cmd = 0x09A6; //default
  6077. info = &packet_db[cmd];
  6078. len = info->len;
  6079. if(!len) return; //version as packet disable
  6080. // sd->state.banking = 1; //mark opening and closing
  6081. WBUFW(buf,0) = cmd;
  6082. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  6083. WBUFW(buf,info->pos[1]) = 0; //reason
  6084. clif_send(buf,len,&sd->bl,SELF);
  6085. }
  6086. /*
  6087. * Requesting the data in bank
  6088. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6089. */
  6090. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6091. nullpo_retv(sd);
  6092. if( !battle_config.feature_banking ) {
  6093. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6094. return;
  6095. }
  6096. else {
  6097. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6098. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6099. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6100. clif_Bank_Check(sd);
  6101. }
  6102. }
  6103. /*
  6104. * Acknowledge of deposit some money in bank
  6105. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6106. */
  6107. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  6108. unsigned char buf[17];
  6109. struct s_packet_db* info;
  6110. int16 len;
  6111. int cmd =0;
  6112. nullpo_retv(sd);
  6113. cmd = packet_db_ack[ZC_ACK_BANKING_DEPOSIT];
  6114. if(!cmd) cmd = 0x09A8;
  6115. info = &packet_db[cmd];
  6116. len = info->len;
  6117. if(!len) return; //version as packet disable
  6118. WBUFW(buf,0) = cmd;
  6119. WBUFW(buf,info->pos[0]) = (short)reason;
  6120. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6121. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6122. clif_send(buf,len,&sd->bl,SELF);
  6123. }
  6124. /*
  6125. * Request saving some money in bank
  6126. * @author : original [Yommy/Hercules]
  6127. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6128. */
  6129. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6130. nullpo_retv(sd);
  6131. if( !battle_config.feature_banking ) {
  6132. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6133. return;
  6134. }
  6135. else {
  6136. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6137. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6138. int money = RFIFOL(fd,info->pos[1]);
  6139. if(sd->status.account_id == aid){
  6140. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6141. clif_bank_deposit(sd,reason);
  6142. }
  6143. }
  6144. }
  6145. /*
  6146. * Acknowledge of withdrawing some money from bank
  6147. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6148. */
  6149. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6150. unsigned char buf[17];
  6151. struct s_packet_db* info;
  6152. int16 len;
  6153. int cmd;
  6154. nullpo_retv(sd);
  6155. cmd = packet_db_ack[ZC_ACK_BANKING_WITHDRAW];
  6156. if(!cmd) cmd = 0x09AA;
  6157. info = &packet_db[cmd];
  6158. len = info->len;
  6159. if(!len) return; //version as packet disable
  6160. WBUFW(buf,0) = cmd;
  6161. WBUFW(buf,info->pos[0]) = (short)reason;
  6162. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6163. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6164. clif_send(buf,len,&sd->bl,SELF);
  6165. }
  6166. /*
  6167. * Request Withdrawing some money from bank
  6168. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6169. */
  6170. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6171. nullpo_retv(sd);
  6172. if( !battle_config.feature_banking ) {
  6173. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6174. return;
  6175. }
  6176. else {
  6177. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6178. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6179. int money = RFIFOL(fd,info->pos[1]);
  6180. if(sd->status.account_id == aid){
  6181. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6182. clif_bank_withdraw(sd,reason);
  6183. }
  6184. }
  6185. }
  6186. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6187. /// 0125 <index>.W <amount>.L
  6188. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6189. {
  6190. int fd;
  6191. nullpo_retv(sd);
  6192. fd=sd->fd;
  6193. WFIFOHEAD(fd,packet_len(0x125));
  6194. WFIFOW(fd,0)=0x125;
  6195. WFIFOW(fd,2)=n+2;
  6196. WFIFOL(fd,4)=amount;
  6197. WFIFOSET(fd,packet_len(0x125));
  6198. }
  6199. /// Opens the shop creation menu (ZC_OPENSTORE).
  6200. /// 012d <num>.W
  6201. /// num:
  6202. /// number of allowed item slots
  6203. void clif_openvendingreq(struct map_session_data* sd, int num)
  6204. {
  6205. int fd;
  6206. nullpo_retv(sd);
  6207. fd = sd->fd;
  6208. WFIFOHEAD(fd,packet_len(0x12d));
  6209. WFIFOW(fd,0) = 0x12d;
  6210. WFIFOW(fd,2) = num;
  6211. WFIFOSET(fd,packet_len(0x12d));
  6212. }
  6213. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6214. /// 0131 <owner id>.L <message>.80B
  6215. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6216. {
  6217. unsigned char buf[128];
  6218. nullpo_retv(bl);
  6219. WBUFW(buf,0) = 0x131;
  6220. WBUFL(buf,2) = bl->id;
  6221. safestrncpy(WBUFCP(buf,6), message, 80);
  6222. if( fd ) {
  6223. WFIFOHEAD(fd,packet_len(0x131));
  6224. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6225. WFIFOSET(fd,packet_len(0x131));
  6226. } else {
  6227. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6228. }
  6229. }
  6230. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6231. /// 0132 <owner id>.L
  6232. void clif_closevendingboard(struct block_list* bl, int fd)
  6233. {
  6234. unsigned char buf[16];
  6235. nullpo_retv(bl);
  6236. WBUFW(buf,0) = 0x132;
  6237. WBUFL(buf,2) = bl->id;
  6238. if( fd ) {
  6239. WFIFOHEAD(fd,packet_len(0x132));
  6240. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6241. WFIFOSET(fd,packet_len(0x132));
  6242. } else {
  6243. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6244. }
  6245. }
  6246. /// Sends a list of items in a shop.
  6247. /// 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)
  6248. /// 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)
  6249. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  6250. {
  6251. int i,fd;
  6252. int count;
  6253. struct map_session_data* vsd;
  6254. #if PACKETVER < 20100105
  6255. const int cmd = 0x133;
  6256. const int offset = 8;
  6257. #else
  6258. const int cmd = 0x800;
  6259. const int offset = 12;
  6260. #endif
  6261. #if PACKETVER < 20150225
  6262. const int item_length = 22;
  6263. #elif PACKETVER < 20160921
  6264. const int item_length = 47;
  6265. #else
  6266. const int item_length = 53;
  6267. #endif
  6268. nullpo_retv(sd);
  6269. nullpo_retv(vending);
  6270. nullpo_retv(vsd=map_id2sd(id));
  6271. fd = sd->fd;
  6272. count = vsd->vend_num;
  6273. WFIFOHEAD(fd, offset+count*item_length);
  6274. WFIFOW(fd,0) = cmd;
  6275. WFIFOW(fd,2) = offset+count*item_length;
  6276. WFIFOL(fd,4) = id;
  6277. #if PACKETVER >= 20100105
  6278. WFIFOL(fd,8) = vsd->vender_id;
  6279. #endif
  6280. for( i = 0; i < count; i++ )
  6281. {
  6282. int index = vending[i].index;
  6283. struct item_data* data = itemdb_search(vsd->cart.u.items_cart[index].nameid);
  6284. WFIFOL(fd,offset+ 0+i*item_length) = vending[i].value;
  6285. WFIFOW(fd,offset+ 4+i*item_length) = vending[i].amount;
  6286. WFIFOW(fd,offset+ 6+i*item_length) = vending[i].index + 2;
  6287. WFIFOB(fd,offset+ 8+i*item_length) = itemtype(data->nameid);
  6288. WFIFOW(fd,offset+ 9+i*item_length) = ( data->view_id > 0 ) ? data->view_id : vsd->cart.u.items_cart[index].nameid;
  6289. WFIFOB(fd,offset+11+i*item_length) = vsd->cart.u.items_cart[index].identify;
  6290. WFIFOB(fd,offset+12+i*item_length) = vsd->cart.u.items_cart[index].attribute;
  6291. WFIFOB(fd,offset+13+i*item_length) = vsd->cart.u.items_cart[index].refine;
  6292. clif_addcards(WFIFOP(fd,offset+14+i*item_length), &vsd->cart.u.items_cart[index]);
  6293. #if PACKETVER >= 20150225
  6294. clif_add_random_options(WFIFOP(fd,offset+22+i*item_length), &vsd->cart.u.items_cart[index]);
  6295. #if PACKETVER >= 20160921
  6296. WFIFOL(fd,offset+47+i*item_length) = pc_equippoint_sub(sd,data);
  6297. WFIFOW(fd,offset+51+i*item_length) = data->look;
  6298. #endif
  6299. #endif
  6300. }
  6301. WFIFOSET(fd,WFIFOW(fd,2));
  6302. }
  6303. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6304. /// 0135 <index>.W <amount>.W <result>.B
  6305. /// result:
  6306. /// 0 = success
  6307. /// 1 = not enough zeny
  6308. /// 2 = overweight
  6309. /// 4 = out of stock
  6310. /// 5 = "cannot use an npc shop while in a trade"
  6311. /// 6 = Because the store information was incorrect the item was not purchased.
  6312. /// 7 = No sales information.
  6313. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6314. {
  6315. int fd;
  6316. nullpo_retv(sd);
  6317. fd = sd->fd;
  6318. WFIFOHEAD(fd,packet_len(0x135));
  6319. WFIFOW(fd,0) = 0x135;
  6320. WFIFOW(fd,2) = index+2;
  6321. WFIFOW(fd,4) = amount;
  6322. WFIFOB(fd,6) = fail;
  6323. WFIFOSET(fd,packet_len(0x135));
  6324. }
  6325. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6326. /// 0a28 <Result>.B
  6327. /// result:
  6328. /// 0 = Successed
  6329. /// 1 = Failed
  6330. void clif_openvending_ack(struct map_session_data* sd, int result)
  6331. {
  6332. int fd;
  6333. nullpo_retv(sd);
  6334. fd = sd->fd;
  6335. WFIFOHEAD(fd, 3);
  6336. WFIFOW(fd,0) = 0xa28;
  6337. WFIFOB(fd,2) = result;
  6338. WFIFOSET(fd, 3);
  6339. }
  6340. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  6341. /// 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 }*
  6342. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  6343. {
  6344. int i,fd;
  6345. int count;
  6346. #if PACKETVER < 20150225
  6347. const int item_length = 22;
  6348. #else
  6349. const int item_length = 47;
  6350. #endif
  6351. nullpo_retv(sd);
  6352. fd = sd->fd;
  6353. count = sd->vend_num;
  6354. WFIFOHEAD(fd, 8+count*item_length);
  6355. WFIFOW(fd,0) = 0x136;
  6356. WFIFOW(fd,2) = 8+count*item_length;
  6357. WFIFOL(fd,4) = id;
  6358. for( i = 0; i < count; i++ ) {
  6359. int index = vending[i].index;
  6360. struct item_data* data = itemdb_search(sd->cart.u.items_cart[index].nameid);
  6361. WFIFOL(fd, 8+i*item_length) = vending[i].value;
  6362. WFIFOW(fd,12+i*item_length) = vending[i].index + 2;
  6363. WFIFOW(fd,14+i*item_length) = vending[i].amount;
  6364. WFIFOB(fd,16+i*item_length) = itemtype(data->nameid);
  6365. WFIFOW(fd,17+i*item_length) = ( data->view_id > 0 ) ? data->view_id : sd->cart.u.items_cart[index].nameid;
  6366. WFIFOB(fd,19+i*item_length) = sd->cart.u.items_cart[index].identify;
  6367. WFIFOB(fd,20+i*item_length) = sd->cart.u.items_cart[index].attribute;
  6368. WFIFOB(fd,21+i*item_length) = sd->cart.u.items_cart[index].refine;
  6369. clif_addcards(WFIFOP(fd,22+i*item_length), &sd->cart.u.items_cart[index]);
  6370. #if PACKETVER >= 20150225
  6371. clif_add_random_options(WFIFOP(fd,30+i*item_length), &sd->cart.u.items_cart[index]);
  6372. #endif
  6373. }
  6374. WFIFOSET(fd,WFIFOW(fd,2));
  6375. #if PACKETVER >= 20141022
  6376. /// 0 = Successed
  6377. /// 1 = Failed
  6378. clif_openvending_ack(sd, 0);
  6379. #endif
  6380. }
  6381. /// Inform merchant that someone has bought an item.
  6382. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6383. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6384. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6385. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6386. const int cmd = 0x137;
  6387. #else
  6388. const int cmd = 0x9e5;
  6389. #endif
  6390. int fd = sd->fd;
  6391. nullpo_retv(sd);
  6392. WFIFOHEAD(fd,packet_len(cmd));
  6393. WFIFOW(fd,0) = cmd;
  6394. WFIFOW(fd,2) = index+2;
  6395. WFIFOW(fd,4) = amount;
  6396. #if PACKETVER >= 20141016
  6397. WFIFOL(fd,6) = char_id; // GID
  6398. WFIFOL(fd,10) = (int)time(NULL); // Date
  6399. WFIFOL(fd,14) = zeny; // zeny
  6400. #endif
  6401. WFIFOSET(fd,packet_len(cmd));
  6402. }
  6403. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6404. /// 00fa <result>.B
  6405. /// result:
  6406. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6407. /// 1 = MsgStringTable[78]="party name already exists"
  6408. /// 2 = MsgStringTable[79]="already in a party"
  6409. /// 3 = cannot organize parties on this map
  6410. /// ? = nothing
  6411. void clif_party_created(struct map_session_data *sd,int result)
  6412. {
  6413. int fd;
  6414. nullpo_retv(sd);
  6415. fd=sd->fd;
  6416. WFIFOHEAD(fd,packet_len(0xfa));
  6417. WFIFOW(fd,0)=0xfa;
  6418. WFIFOB(fd,2)=result;
  6419. WFIFOSET(fd,packet_len(0xfa));
  6420. }
  6421. /// Adds new member to a party.
  6422. /// 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)
  6423. /// 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)
  6424. /// 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)
  6425. /// role:
  6426. /// 0 = leader
  6427. /// 1 = normal
  6428. /// state:
  6429. /// 0 = connected
  6430. /// 1 = disconnected
  6431. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6432. {
  6433. int i;
  6434. #if PACKETVER < 20170502
  6435. unsigned char buf[81];
  6436. int cmd = 0x1e9;
  6437. int offset = 0;
  6438. #else
  6439. unsigned char buf[85];
  6440. int cmd = 0xa43;
  6441. int offset = 4;
  6442. #endif
  6443. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6444. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6445. } else {
  6446. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6447. }
  6448. if (i >= MAX_PARTY) return; //Should never happen...
  6449. sd = p->data[i].sd;
  6450. WBUFW(buf, 0) = cmd;
  6451. WBUFL(buf, 2) = sd->status.account_id;
  6452. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6453. #if PACKETVER >= 20170502
  6454. WBUFW(buf,10) = sd->status.class_;
  6455. WBUFW(buf,12) = sd->status.base_level;
  6456. #endif
  6457. WBUFW(buf,offset+10) = sd->bl.x;
  6458. WBUFW(buf,offset+12) = sd->bl.y;
  6459. WBUFB(buf,offset+14) = (p->party.member[i].online)?0:1;
  6460. safestrncpy(WBUFCP(buf,offset+15), p->party.name, NAME_LENGTH);
  6461. safestrncpy(WBUFCP(buf,offset+39), sd->status.name, NAME_LENGTH);
  6462. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), WBUFCP(buf,offset+63));
  6463. WBUFB(buf,offset+79) = (p->party.item&1)?1:0;
  6464. WBUFB(buf,offset+80) = (p->party.item&2)?1:0;
  6465. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6466. }
  6467. /// Sends party information (ZC_GROUP_LIST).
  6468. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6469. /// role:
  6470. /// 0 = leader
  6471. /// 1 = normal
  6472. /// state:
  6473. /// 0 = connected
  6474. /// 1 = disconnected
  6475. /// 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
  6476. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6477. {
  6478. struct map_session_data* party_sd = NULL;
  6479. int i, c;
  6480. #if PACKETVER < 20170502
  6481. const int M_SIZE = 46; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1
  6482. unsigned char buf[2+2+NAME_LENGTH+46*MAX_PARTY];
  6483. int cmd = 0xfb;
  6484. #else
  6485. const int M_SIZE = 50; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1+4
  6486. unsigned char buf[2+2+NAME_LENGTH+50*MAX_PARTY+6];
  6487. int cmd = 0xa44;
  6488. #endif
  6489. const int PRE_SIZE = 28; // cmd, actual cmd_size, party_name
  6490. nullpo_retv(p);
  6491. WBUFW(buf,0) = cmd;
  6492. safestrncpy(WBUFCP(buf,4), p->party.name, NAME_LENGTH);
  6493. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6494. {
  6495. struct party_member* m = &p->party.member[i];
  6496. if(!m->account_id) continue;
  6497. if(party_sd == NULL) party_sd = p->data[i].sd;
  6498. WBUFL(buf,PRE_SIZE+c*M_SIZE) = m->account_id;
  6499. safestrncpy(WBUFCP(buf,PRE_SIZE+c*M_SIZE+4), m->name, NAME_LENGTH);
  6500. mapindex_getmapname_ext(mapindex_id2name(m->map), WBUFCP(buf,PRE_SIZE+c*M_SIZE+PRE_SIZE));
  6501. WBUFB(buf,PRE_SIZE+c*M_SIZE+44) = (m->leader) ? 0 : 1;
  6502. WBUFB(buf,PRE_SIZE+c*M_SIZE+45) = (m->online) ? 0 : 1;
  6503. #if PACKETVER >= 20170502
  6504. WBUFW(buf,PRE_SIZE+c*M_SIZE+46) = m->class_;
  6505. WBUFW(buf,PRE_SIZE+c*M_SIZE+48) = m->lv;
  6506. #endif
  6507. c++;
  6508. }
  6509. #if PACKETVER < 20170502
  6510. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE;
  6511. #else
  6512. WBUFB(buf,PRE_SIZE+c*M_SIZE) = (p->party.item & 1) ? 1 : 0;
  6513. WBUFB(buf,PRE_SIZE+c*M_SIZE+1) = (p->party.item & 2) ? 1 : 0;
  6514. WBUFL(buf,PRE_SIZE+c*M_SIZE+2) = 0; // unknown
  6515. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE+6;
  6516. #endif
  6517. if(sd) { // send only to self
  6518. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6519. } else if (party_sd) { // send to whole party
  6520. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6521. }
  6522. }
  6523. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6524. /// 02c9 <flag>.B
  6525. /// flag:
  6526. /// 0 = allow party invites
  6527. /// 1 = auto-deny party invites
  6528. void clif_partyinvitationstate(struct map_session_data* sd)
  6529. {
  6530. int fd;
  6531. nullpo_retv(sd);
  6532. fd = sd->fd;
  6533. WFIFOHEAD(fd, packet_len(0x2c9));
  6534. WFIFOW(fd, 0) = 0x2c9;
  6535. WFIFOB(fd, 2) = 0; // not implemented
  6536. WFIFOSET(fd, packet_len(0x2c9));
  6537. }
  6538. /// Party invitation request.
  6539. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6540. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6541. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6542. {
  6543. #if PACKETVER < 20070821
  6544. const int cmd = 0xfe;
  6545. #else
  6546. const int cmd = 0x2c6;
  6547. #endif
  6548. int fd;
  6549. struct party_data *p;
  6550. nullpo_retv(sd);
  6551. nullpo_retv(tsd);
  6552. fd=tsd->fd;
  6553. if( (p=party_search(sd->status.party_id))==NULL )
  6554. return;
  6555. WFIFOHEAD(fd,packet_len(cmd));
  6556. WFIFOW(fd,0)=cmd;
  6557. WFIFOL(fd,2)=sd->status.party_id;
  6558. safestrncpy(WFIFOCP(fd,6),p->party.name,NAME_LENGTH);
  6559. WFIFOSET(fd,packet_len(cmd));
  6560. }
  6561. /// Party invite result.
  6562. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6563. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6564. void clif_party_invite_reply(struct map_session_data* sd, const char* nick, enum e_party_invite_reply reply)
  6565. {
  6566. int fd;
  6567. nullpo_retv(sd);
  6568. fd=sd->fd;
  6569. #if PACKETVER < 20070904
  6570. if( reply == PARTY_REPLY_OFFLINE ) {
  6571. clif_displaymessage(fd, msg_txt(sd,3));
  6572. return;
  6573. }
  6574. #endif
  6575. #if PACKETVER < 20070821
  6576. WFIFOHEAD(fd,packet_len(0xfd));
  6577. WFIFOW(fd,0) = 0xfd;
  6578. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6579. WFIFOB(fd,26) = reply;
  6580. WFIFOSET(fd,packet_len(0xfd));
  6581. #else
  6582. WFIFOHEAD(fd,packet_len(0x2c5));
  6583. WFIFOW(fd,0) = 0x2c5;
  6584. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6585. WFIFOL(fd,26) = reply;
  6586. WFIFOSET(fd,packet_len(0x2c5));
  6587. #endif
  6588. }
  6589. /// Updates party settings.
  6590. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6591. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6592. /// exp option:
  6593. /// 0 = exp sharing disabled
  6594. /// 1 = exp sharing enabled
  6595. /// 2 = cannot change exp sharing
  6596. ///
  6597. /// flag:
  6598. /// 0 = send to party
  6599. /// 1 = send to sd
  6600. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6601. {
  6602. unsigned char buf[16];
  6603. #if PACKETVER < 20090603
  6604. const int cmd = 0x101;
  6605. #else
  6606. const int cmd = 0x7d8;
  6607. #endif
  6608. nullpo_retv(p);
  6609. if(!sd && flag==0){
  6610. int i;
  6611. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6612. if (i < MAX_PARTY)
  6613. sd = p->data[i].sd;
  6614. }
  6615. if(!sd) return;
  6616. WBUFW(buf,0)=cmd;
  6617. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6618. #if PACKETVER >= 20090603
  6619. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6620. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6621. #endif
  6622. if(flag==0)
  6623. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6624. else
  6625. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6626. }
  6627. /**
  6628. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6629. * @param sd Send the notification for this player
  6630. * @param account_id Account ID of kicked member
  6631. * @param name Name of kicked member
  6632. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6633. * @param target Send target
  6634. **/
  6635. 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) {
  6636. unsigned char buf[2+4+NAME_LENGTH+1];
  6637. if (!sd)
  6638. return;
  6639. WBUFW(buf,0) = 0x0105;
  6640. WBUFL(buf,2) = account_id;
  6641. memcpy(WBUFP(buf,6), name, NAME_LENGTH);
  6642. WBUFB(buf,6+NAME_LENGTH) = result;
  6643. clif_send(buf, 2+4+NAME_LENGTH+1, &sd->bl, target);
  6644. }
  6645. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6646. /// 0109 <packet len>.W <account id>.L <message>.?B
  6647. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6648. {
  6649. struct map_session_data *sd;
  6650. int i;
  6651. nullpo_retv(p);
  6652. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6653. if(i < MAX_PARTY){
  6654. unsigned char buf[1024];
  6655. if( len > sizeof(buf)-8 )
  6656. {
  6657. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6658. len = sizeof(buf)-8;
  6659. }
  6660. sd = p->data[i].sd;
  6661. WBUFW(buf,0)=0x109;
  6662. WBUFW(buf,2)=len+8;
  6663. WBUFL(buf,4)=account_id;
  6664. safestrncpy(WBUFCP(buf,8), mes, len);
  6665. clif_send(buf,len+8,&sd->bl,PARTY);
  6666. }
  6667. }
  6668. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6669. /// 0107 <account id>.L <x>.W <y>.W
  6670. void clif_party_xy(struct map_session_data *sd)
  6671. {
  6672. unsigned char buf[16];
  6673. nullpo_retv(sd);
  6674. WBUFW(buf,0)=0x107;
  6675. WBUFL(buf,2)=sd->status.account_id;
  6676. WBUFW(buf,6)=sd->bl.x;
  6677. WBUFW(buf,8)=sd->bl.y;
  6678. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6679. }
  6680. /*==========================================
  6681. * Sends x/y dot to a single fd. [Skotlex]
  6682. *------------------------------------------*/
  6683. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6684. {
  6685. WFIFOHEAD(fd,packet_len(0x107));
  6686. WFIFOW(fd,0)=0x107;
  6687. WFIFOL(fd,2)=sd->status.account_id;
  6688. WFIFOW(fd,6)=sd->bl.x;
  6689. WFIFOW(fd,8)=sd->bl.y;
  6690. WFIFOSET(fd,packet_len(0x107));
  6691. }
  6692. /// Updates HP bar of a party member.
  6693. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6694. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6695. void clif_party_hp(struct map_session_data *sd)
  6696. {
  6697. unsigned char buf[16];
  6698. #if PACKETVER < 20100126
  6699. const int cmd = 0x106;
  6700. #else
  6701. const int cmd = 0x80e;
  6702. #endif
  6703. nullpo_retv(sd);
  6704. WBUFW(buf,0)=cmd;
  6705. WBUFL(buf,2)=sd->status.account_id;
  6706. #if PACKETVER < 20100126
  6707. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6708. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6709. WBUFW(buf,8) = 100;
  6710. } else {
  6711. WBUFW(buf,6) = sd->battle_status.hp;
  6712. WBUFW(buf,8) = sd->battle_status.max_hp;
  6713. }
  6714. #else
  6715. WBUFL(buf,6) = sd->battle_status.hp;
  6716. WBUFL(buf,10) = sd->battle_status.max_hp;
  6717. #endif
  6718. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6719. }
  6720. /// Notifies the party members of a character's death or revival.
  6721. /// 0AB2 <GID>.L <dead>.B
  6722. void clif_party_dead( struct map_session_data *sd ){
  6723. #if PACKETVER >= 20170502
  6724. unsigned char buf[7];
  6725. nullpo_retv(sd);
  6726. WBUFW(buf, 0) = 0xab2;
  6727. WBUFL(buf, 2) = sd->status.account_id;
  6728. WBUFB(buf, 6) = pc_isdead(sd);
  6729. clif_send(buf, packet_len(0xab2), &sd->bl, PARTY);
  6730. #endif
  6731. }
  6732. /// Updates the job and level of a party member
  6733. /// 0abd <account id>.L <job>.W <level>.W
  6734. void clif_party_job_and_level(struct map_session_data *sd){
  6735. #if PACKETVER >= 20170502
  6736. unsigned char buf[10];
  6737. nullpo_retv(sd);
  6738. WBUFW(buf, 0) = 0xabd;
  6739. WBUFL(buf, 2) = sd->status.account_id;
  6740. WBUFW(buf, 6) = sd->status.class_;
  6741. WBUFW(buf, 8) = sd->status.base_level;
  6742. clif_send(buf, packet_len(0xabd), &sd->bl, PARTY);
  6743. #endif
  6744. }
  6745. /*==========================================
  6746. * Sends HP bar to a single fd. [Skotlex]
  6747. *------------------------------------------*/
  6748. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6749. {
  6750. #if PACKETVER < 20100126
  6751. const int cmd = 0x106;
  6752. #else
  6753. const int cmd = 0x80e;
  6754. #endif
  6755. WFIFOHEAD(fd,packet_len(cmd));
  6756. WFIFOW(fd,0) = cmd;
  6757. WFIFOL(fd,2) = id;
  6758. #if PACKETVER < 20100126
  6759. if( maxhp > INT16_MAX )
  6760. {// To correctly display the %hp bar. [Skotlex]
  6761. WFIFOW(fd,6) = hp/(maxhp/100);
  6762. WFIFOW(fd,8) = 100;
  6763. } else {
  6764. WFIFOW(fd,6) = hp;
  6765. WFIFOW(fd,8) = maxhp;
  6766. }
  6767. #else
  6768. WFIFOL(fd,6) = hp;
  6769. WFIFOL(fd,10) = maxhp;
  6770. #endif
  6771. WFIFOSET(fd, packet_len(cmd));
  6772. }
  6773. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6774. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6775. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6776. {
  6777. int fd;
  6778. nullpo_retv(sd);
  6779. nullpo_retv(bl);
  6780. fd=sd->fd;
  6781. WFIFOHEAD(fd,packet_len(0x139));
  6782. WFIFOW(fd, 0)=0x139;
  6783. WFIFOL(fd, 2)=bl->id;
  6784. WFIFOW(fd, 6)=bl->x;
  6785. WFIFOW(fd, 8)=bl->y;
  6786. WFIFOW(fd,10)=sd->bl.x;
  6787. WFIFOW(fd,12)=sd->bl.y;
  6788. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6789. WFIFOSET(fd,packet_len(0x139));
  6790. }
  6791. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6792. /// 018f <result>.W <name id>.W
  6793. /// result:
  6794. /// 0 = success
  6795. /// 1 = failure
  6796. /// 2 = success (alchemist)
  6797. /// 3 = failure (alchemist)
  6798. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid)
  6799. {
  6800. int view,fd;
  6801. nullpo_retv(sd);
  6802. fd = sd->fd;
  6803. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6804. WFIFOHEAD(fd,packet_len(0x18f));
  6805. WFIFOW(fd, 0)=0x18f;
  6806. WFIFOW(fd, 2)=flag;
  6807. if((view = itemdb_viewid(nameid)) > 0)
  6808. WFIFOW(fd, 4)=view;
  6809. else
  6810. WFIFOW(fd, 4)=nameid;
  6811. WFIFOSET(fd,packet_len(0x18f));
  6812. }
  6813. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6814. /// 019e
  6815. void clif_catch_process(struct map_session_data *sd)
  6816. {
  6817. int fd;
  6818. nullpo_retv(sd);
  6819. fd=sd->fd;
  6820. WFIFOHEAD(fd,packet_len(0x19e));
  6821. WFIFOW(fd,0)=0x19e;
  6822. WFIFOSET(fd,packet_len(0x19e));
  6823. }
  6824. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6825. /// 01a0 <result>.B
  6826. /// 0 = failure
  6827. /// 1 = success
  6828. void clif_pet_roulette(struct map_session_data *sd,int data)
  6829. {
  6830. int fd;
  6831. nullpo_retv(sd);
  6832. fd=sd->fd;
  6833. WFIFOHEAD(fd,packet_len(0x1a0));
  6834. WFIFOW(fd,0)=0x1a0;
  6835. WFIFOB(fd,2)=data;
  6836. WFIFOSET(fd,packet_len(0x1a0));
  6837. }
  6838. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6839. /// 01a6 <packet len>.W { <index>.W }*
  6840. void clif_sendegg(struct map_session_data *sd)
  6841. {
  6842. int i,n=0,fd;
  6843. nullpo_retv(sd);
  6844. fd=sd->fd;
  6845. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6846. clif_displaymessage(fd, msg_txt(sd,666));
  6847. return;
  6848. }
  6849. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6850. WFIFOW(fd,0)=0x1a6;
  6851. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6852. if(sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL ||
  6853. sd->inventory_data[i]->type != IT_PETEGG ||
  6854. sd->inventory.u.items_inventory[i].amount <= 0)
  6855. continue;
  6856. WFIFOW(fd,n*2+4)=i+2;
  6857. n++;
  6858. }
  6859. WFIFOW(fd,2)=4+n*2;
  6860. WFIFOSET(fd,WFIFOW(fd,2));
  6861. sd->menuskill_id = SA_TAMINGMONSTER;
  6862. sd->menuskill_val = -1;
  6863. }
  6864. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6865. /// 01a4 <type>.B <id>.L <data>.L
  6866. /// type:
  6867. /// 0 = pre-init (data = 0)
  6868. /// 1 = intimacy (data = 0~4)
  6869. /// 2 = hunger (data = 0~4)
  6870. /// 3 = accessory
  6871. /// 4 = performance (data = 1~3: normal, 4: special)
  6872. /// 5 = hairstyle
  6873. ///
  6874. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6875. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6876. {
  6877. uint8 buf[16];
  6878. nullpo_retv(pd);
  6879. WBUFW(buf,0) = 0x1a4;
  6880. WBUFB(buf,2) = type;
  6881. WBUFL(buf,3) = pd->bl.id;
  6882. WBUFL(buf,7) = param;
  6883. if (sd)
  6884. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6885. else
  6886. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6887. }
  6888. /// Pet's base data (ZC_PROPERTY_PET).
  6889. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6890. void clif_send_petstatus(struct map_session_data *sd)
  6891. {
  6892. int fd;
  6893. struct s_pet *pet;
  6894. nullpo_retv(sd);
  6895. nullpo_retv(sd->pd);
  6896. fd=sd->fd;
  6897. pet = &sd->pd->pet;
  6898. WFIFOHEAD(fd,packet_len(0x1a2));
  6899. WFIFOW(fd,0)=0x1a2;
  6900. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  6901. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6902. WFIFOW(fd,27)=pet->level;
  6903. WFIFOW(fd,29)=pet->hungry;
  6904. WFIFOW(fd,31)=pet->intimate;
  6905. WFIFOW(fd,33)=pet->equip;
  6906. #if PACKETVER >= 20081126
  6907. WFIFOW(fd,35)=pet->class_;
  6908. #endif
  6909. WFIFOSET(fd,packet_len(0x1a2));
  6910. }
  6911. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6912. /// 01aa <id>.L <data>.L
  6913. /// data:
  6914. /// @see CZ_PET_ACT.
  6915. void clif_pet_emotion(struct pet_data *pd,int param)
  6916. {
  6917. unsigned char buf[16];
  6918. s_pet_db *pet_db_ptr;
  6919. nullpo_retv(pd);
  6920. pet_db_ptr = pd->get_pet_db();
  6921. memset(buf,0,packet_len(0x1aa));
  6922. WBUFW(buf,0)=0x1aa;
  6923. WBUFL(buf,2)=pd->bl.id;
  6924. if(param >= 100 && pet_db_ptr->talk_convert_class) {
  6925. if(pet_db_ptr->talk_convert_class < 0)
  6926. return;
  6927. else if(pet_db_ptr->talk_convert_class > 0) {
  6928. // replace mob_id component of talk/act data
  6929. param -= (pd->pet.class_ - 100)*100;
  6930. param += (pet_db_ptr->talk_convert_class - 100)*100;
  6931. }
  6932. }
  6933. WBUFL(buf,6)=param;
  6934. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6935. }
  6936. /// Result of request to feed a pet (ZC_FEED_PET).
  6937. /// 01a3 <result>.B <name id>.W
  6938. /// result:
  6939. /// 0 = failure
  6940. /// 1 = success
  6941. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6942. {
  6943. int fd;
  6944. nullpo_retv(sd);
  6945. fd=sd->fd;
  6946. WFIFOHEAD(fd,packet_len(0x1a3));
  6947. WFIFOW(fd,0)=0x1a3;
  6948. WFIFOB(fd,2)=fail;
  6949. WFIFOW(fd,3)=foodid;
  6950. WFIFOSET(fd,packet_len(0x1a3));
  6951. }
  6952. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6953. /// 01cd { <skill id>.L }*7
  6954. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6955. {
  6956. int fd;
  6957. nullpo_retv(sd);
  6958. fd=sd->fd;
  6959. WFIFOHEAD(fd,packet_len(0x1cd));
  6960. WFIFOW(fd, 0)=0x1cd;
  6961. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6962. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6963. else
  6964. WFIFOL(fd,2)= 0x00000000;
  6965. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6966. WFIFOL(fd,6)= MG_COLDBOLT;
  6967. else
  6968. WFIFOL(fd,6)= 0x00000000;
  6969. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6970. WFIFOL(fd,10)= MG_FIREBOLT;
  6971. else
  6972. WFIFOL(fd,10)= 0x00000000;
  6973. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6974. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6975. else
  6976. WFIFOL(fd,14)= 0x00000000;
  6977. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6978. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6979. else
  6980. WFIFOL(fd,18)= 0x00000000;
  6981. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6982. WFIFOL(fd,22)= MG_FIREBALL;
  6983. else
  6984. WFIFOL(fd,22)= 0x00000000;
  6985. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6986. WFIFOL(fd,26)= MG_FROSTDIVER;
  6987. else
  6988. WFIFOL(fd,26)= 0x00000000;
  6989. WFIFOSET(fd,packet_len(0x1cd));
  6990. sd->menuskill_id = SA_AUTOSPELL;
  6991. sd->menuskill_val = skill_lv;
  6992. }
  6993. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6994. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6995. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6996. {
  6997. unsigned char buf[56];
  6998. nullpo_retv(src);
  6999. memset(buf,0,packet_len(0x1cf));
  7000. WBUFW(buf,0) = 0x1cf;
  7001. WBUFL(buf,2) = src->id;
  7002. if( src->type == BL_MER )
  7003. {
  7004. struct mercenary_data *md = BL_CAST(BL_MER,src);
  7005. if( md && md->master && md->devotion_flag )
  7006. WBUFL(buf,6) = md->master->bl.id;
  7007. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7008. }
  7009. else
  7010. {
  7011. int i;
  7012. struct map_session_data *sd = BL_CAST(BL_PC,src);
  7013. if( sd == NULL )
  7014. return;
  7015. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7016. WBUFL(buf,6+4*i) = sd->devotion[i];
  7017. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7018. }
  7019. if( tsd )
  7020. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7021. else
  7022. clif_send(buf, packet_len(0x1cf), src, AREA);
  7023. }
  7024. /*==========================================
  7025. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  7026. * Notifies clients in an area of an object's spirits.
  7027. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7028. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7029. *------------------------------------------*/
  7030. void clif_spiritball(struct block_list *bl) {
  7031. unsigned char buf[16];
  7032. TBL_PC *sd = BL_CAST(BL_PC,bl);
  7033. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  7034. nullpo_retv(bl);
  7035. WBUFW(buf, 0) = 0x1d0;
  7036. WBUFL(buf, 2) = bl->id;
  7037. WBUFW(buf, 6) = 0; //init to 0
  7038. switch(bl->type){
  7039. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  7040. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  7041. }
  7042. clif_send(buf, packet_len(0x1d0), bl, AREA);
  7043. }
  7044. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7045. /// 01d2 <account id>.L <delay>.L
  7046. void clif_combo_delay(struct block_list *bl,int wait)
  7047. {
  7048. unsigned char buf[32];
  7049. nullpo_retv(bl);
  7050. WBUFW(buf,0)=0x1d2;
  7051. WBUFL(buf,2)=bl->id;
  7052. WBUFL(buf,6)=wait;
  7053. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7054. }
  7055. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7056. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7057. /// flag:
  7058. /// 0 = inactive
  7059. /// 1 = active
  7060. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7061. {
  7062. unsigned char buf[32];
  7063. nullpo_retv(src);
  7064. WBUFW(buf,0)=0x1d1;
  7065. WBUFL(buf,2)=src->id;
  7066. WBUFL(buf,6)=dst_id;
  7067. WBUFL(buf,10)=active;
  7068. clif_send(buf,packet_len(0x1d1),src,AREA);
  7069. }
  7070. /// MVP effect (ZC_MVP).
  7071. /// 010c <account id>.L
  7072. void clif_mvp_effect(struct map_session_data *sd)
  7073. {
  7074. unsigned char buf[16];
  7075. nullpo_retv(sd);
  7076. WBUFW(buf,0)=0x10c;
  7077. WBUFL(buf,2)=sd->bl.id;
  7078. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7079. }
  7080. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7081. /// 010a <name id>.W
  7082. void clif_mvp_item(struct map_session_data *sd, unsigned short nameid)
  7083. {
  7084. int view,fd;
  7085. nullpo_retv(sd);
  7086. fd=sd->fd;
  7087. WFIFOHEAD(fd,packet_len(0x10a));
  7088. WFIFOW(fd,0)=0x10a;
  7089. if((view = itemdb_viewid(nameid)) > 0)
  7090. WFIFOW(fd,2)=view;
  7091. else
  7092. WFIFOW(fd,2)=nameid;
  7093. WFIFOSET(fd,packet_len(0x10a));
  7094. }
  7095. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7096. /// 010b <exp>.L
  7097. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp) {
  7098. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7099. if (battle_config.mvp_exp_reward_message) {
  7100. char e_msg[CHAT_SIZE_MAX];
  7101. sprintf(e_msg, msg_txt(sd, 717), exp);
  7102. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7103. }
  7104. #else
  7105. int fd;
  7106. nullpo_retv(sd);
  7107. fd = sd->fd;
  7108. WFIFOHEAD(fd, packet_len(0x10b));
  7109. WFIFOW(fd,0) = 0x10b;
  7110. WFIFOL(fd,2) = min(exp, (unsigned int)INT32_MAX);
  7111. WFIFOSET(fd, packet_len(0x10b));
  7112. #endif
  7113. }
  7114. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7115. /// 010d
  7116. ///
  7117. /// "You are the MVP, but cannot obtain the reward because
  7118. /// you are overweight."
  7119. void clif_mvp_noitem(struct map_session_data* sd)
  7120. {
  7121. int fd = sd->fd;
  7122. WFIFOHEAD(fd,packet_len(0x10d));
  7123. WFIFOW(fd,0) = 0x10d;
  7124. WFIFOSET(fd,packet_len(0x10d));
  7125. }
  7126. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7127. /// 0167 <result>.B
  7128. /// result:
  7129. /// 0 = "Guild has been created."
  7130. /// 1 = "You are already in a Guild."
  7131. /// 2 = "That Guild Name already exists."
  7132. /// 3 = "You need the neccessary item to create a Guild."
  7133. void clif_guild_created(struct map_session_data *sd,int flag)
  7134. {
  7135. int fd;
  7136. nullpo_retv(sd);
  7137. fd=sd->fd;
  7138. WFIFOHEAD(fd,packet_len(0x167));
  7139. WFIFOW(fd,0)=0x167;
  7140. WFIFOB(fd,2)=flag;
  7141. WFIFOSET(fd,packet_len(0x167));
  7142. }
  7143. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7144. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7145. /// mode:
  7146. /// &0x01 = allow invite
  7147. /// &0x10 = allow expel
  7148. void clif_guild_belonginfo(struct map_session_data *sd)
  7149. {
  7150. int ps,fd;
  7151. struct guild* g;
  7152. nullpo_retv(sd);
  7153. nullpo_retv(g = sd->guild);
  7154. fd=sd->fd;
  7155. ps=guild_getposition(sd);
  7156. WFIFOHEAD(fd,packet_len(0x16c));
  7157. WFIFOW(fd,0)=0x16c;
  7158. WFIFOL(fd,2)=g->guild_id;
  7159. WFIFOL(fd,6)=g->emblem_id;
  7160. WFIFOL(fd,10)=g->position[ps].mode;
  7161. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  7162. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  7163. safestrncpy(WFIFOCP(fd,19),g->name,NAME_LENGTH);
  7164. WFIFOSET(fd,packet_len(0x16c));
  7165. }
  7166. /// Guild member login notice.
  7167. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7168. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7169. /// status:
  7170. /// 0 = offline
  7171. /// 1 = online
  7172. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7173. {
  7174. unsigned char buf[64];
  7175. struct map_session_data* sd;
  7176. nullpo_retv(g);
  7177. WBUFW(buf, 0)=0x1f2;
  7178. WBUFL(buf, 2)=g->member[idx].account_id;
  7179. WBUFL(buf, 6)=g->member[idx].char_id;
  7180. WBUFL(buf,10)=flag;
  7181. if( ( sd = g->member[idx].sd ) != NULL )
  7182. {
  7183. WBUFW(buf,14) = sd->status.sex;
  7184. WBUFW(buf,16) = sd->status.hair;
  7185. WBUFW(buf,18) = sd->status.hair_color;
  7186. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7187. }
  7188. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7189. {
  7190. WBUFW(buf,14) = 0;
  7191. WBUFW(buf,16) = 0;
  7192. WBUFW(buf,18) = 0;
  7193. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7194. }
  7195. }
  7196. // Function `clif_guild_memberlogin_notice` sends info about
  7197. // logins and logouts of a guild member to the rest members.
  7198. // But at the 1st time (after a player login or map changing)
  7199. // the client won't show the message.
  7200. // So I suggest use this function for sending "first-time-info"
  7201. // to some player on entering the game or changing location.
  7202. // At next time the client would always show the message.
  7203. // The function sends all the statuses in the single packet
  7204. // to economize traffic. [LuzZza]
  7205. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7206. {
  7207. struct guild *g;
  7208. unsigned char buf[14*128];
  7209. int i, count=0, p_len;
  7210. nullpo_retv(sd);
  7211. p_len = packet_len(0x16d);
  7212. if(!(g = sd->guild))
  7213. return;
  7214. for(i=0; i<g->max_member; i++) {
  7215. if(g->member[i].account_id > 0 &&
  7216. g->member[i].account_id != sd->status.account_id) {
  7217. WBUFW(buf,count*p_len) = 0x16d;
  7218. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7219. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7220. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7221. count++;
  7222. }
  7223. }
  7224. clif_send(buf, p_len*count, &sd->bl, SELF);
  7225. }
  7226. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7227. /// 014e <menu flag>.L
  7228. /// menu flag:
  7229. /// 0x00 = Basic Info (always on)
  7230. /// &0x01 = Member manager
  7231. /// &0x02 = Positions
  7232. /// &0x04 = Skills
  7233. /// &0x10 = Expulsion list
  7234. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7235. /// &0x80 = Notice
  7236. void clif_guild_masterormember(struct map_session_data *sd)
  7237. {
  7238. int fd;
  7239. nullpo_retv(sd);
  7240. fd=sd->fd;
  7241. WFIFOHEAD(fd,packet_len(0x14e));
  7242. WFIFOW(fd,0) = 0x14e;
  7243. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7244. WFIFOSET(fd,packet_len(0x14e));
  7245. }
  7246. /// Guild basic information (Territories [Valaris])
  7247. /// 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)
  7248. /// 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)
  7249. /// 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)
  7250. void clif_guild_basicinfo(struct map_session_data *sd) {
  7251. int fd;
  7252. struct guild *g;
  7253. #if PACKETVER < 20160622
  7254. int cmd = 0x1b6;
  7255. int offset = NAME_LENGTH;
  7256. #else
  7257. int cmd = 0xa84;
  7258. int offset = 0;
  7259. #endif
  7260. nullpo_retv(sd);
  7261. fd = sd->fd;
  7262. if( (g = sd->guild) == NULL )
  7263. return;
  7264. WFIFOHEAD(fd,packet_len(cmd));
  7265. WFIFOW(fd, 0)=cmd;
  7266. WFIFOL(fd, 2)=g->guild_id;
  7267. WFIFOL(fd, 6)=g->guild_lv;
  7268. WFIFOL(fd,10)=g->connect_member;
  7269. WFIFOL(fd,14)=g->max_member;
  7270. WFIFOL(fd,18)=g->average_lv;
  7271. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  7272. WFIFOL(fd,26)=g->next_exp;
  7273. WFIFOL(fd,30)=0; // Tax Points
  7274. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7275. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7276. WFIFOL(fd,42)=g->emblem_id;
  7277. safestrncpy(WFIFOCP(fd,46),g->name, NAME_LENGTH);
  7278. #if PACKETVER < 20160622
  7279. safestrncpy(WFIFOCP(fd,70),g->master, NAME_LENGTH);
  7280. #endif
  7281. safestrncpy(WFIFOCP(fd,70+offset),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7282. WFIFOL(fd,70+offset+16) = 0; // zeny
  7283. #if PACKETVER >= 20160622
  7284. WFIFOL(fd,70+offset+20) = g->member[0].char_id; // leader
  7285. #endif
  7286. WFIFOSET(fd,packet_len(cmd));
  7287. }
  7288. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7289. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7290. void clif_guild_allianceinfo(struct map_session_data *sd)
  7291. {
  7292. int fd,i,c;
  7293. struct guild *g;
  7294. nullpo_retv(sd);
  7295. if( (g = sd->guild) == NULL )
  7296. return;
  7297. fd = sd->fd;
  7298. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7299. WFIFOW(fd, 0)=0x14c;
  7300. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7301. struct guild_alliance *a=&g->alliance[i];
  7302. if(a->guild_id>0){
  7303. WFIFOL(fd,c*32+4)=a->opposition;
  7304. WFIFOL(fd,c*32+8)=a->guild_id;
  7305. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7306. c++;
  7307. }
  7308. }
  7309. WFIFOW(fd, 2)=c*32+4;
  7310. WFIFOSET(fd,WFIFOW(fd,2));
  7311. }
  7312. /// Guild member manager information
  7313. /// 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)
  7314. /// state:
  7315. /// 0 = offline
  7316. /// 1 = online
  7317. /// memo:
  7318. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7319. /// 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 <lastlogin>.L }* (ZC_MEMBERMGR_INFO2)
  7320. void clif_guild_memberlist(struct map_session_data *sd)
  7321. {
  7322. int fd;
  7323. int i,c;
  7324. struct guild *g;
  7325. #if PACKETVER < 20161026
  7326. int cmd = 0x154;
  7327. int size = 104;
  7328. #else
  7329. int cmd = 0xaa5;
  7330. int size = 34;
  7331. #endif
  7332. nullpo_retv(sd);
  7333. if( (fd = sd->fd) == 0 )
  7334. return;
  7335. if( (g = sd->guild) == NULL )
  7336. return;
  7337. WFIFOHEAD(fd, g->max_member * size + 4);
  7338. WFIFOW(fd, 0)=cmd;
  7339. for(i=0,c=0;i<g->max_member;i++){
  7340. struct guild_member *m=&g->member[i];
  7341. if(m->account_id==0)
  7342. continue;
  7343. WFIFOL(fd,c*size+ 4)=m->account_id;
  7344. WFIFOL(fd,c*size+ 8)=m->char_id;
  7345. WFIFOW(fd,c*size+12)=m->hair;
  7346. WFIFOW(fd,c*size+14)=m->hair_color;
  7347. WFIFOW(fd,c*size+16)=m->gender;
  7348. WFIFOW(fd,c*size+18)=m->class_;
  7349. WFIFOW(fd,c*size+20)=m->lv;
  7350. WFIFOL(fd,c*size+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7351. WFIFOL(fd,c*size+26)=m->online;
  7352. WFIFOL(fd,c*size+30)=m->position;
  7353. #if PACKETVER < 20161026
  7354. 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.
  7355. safestrncpy(WFIFOCP(fd,c*size+84),m->name,NAME_LENGTH);
  7356. #else
  7357. WFIFOL(fd,c*size+34)=m->last_login;
  7358. #endif
  7359. c++;
  7360. }
  7361. WFIFOW(fd, 2)=c*size+4;
  7362. WFIFOSET(fd,WFIFOW(fd,2));
  7363. }
  7364. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7365. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7366. void clif_guild_positionnamelist(struct map_session_data *sd)
  7367. {
  7368. int i,fd;
  7369. struct guild *g;
  7370. nullpo_retv(sd);
  7371. if( (g = sd->guild) == NULL )
  7372. return;
  7373. fd = sd->fd;
  7374. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7375. WFIFOW(fd, 0)=0x166;
  7376. for(i=0;i<MAX_GUILDPOSITION;i++){
  7377. WFIFOL(fd,i*28+4)=i;
  7378. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7379. }
  7380. WFIFOW(fd,2)=i*28+4;
  7381. WFIFOSET(fd,WFIFOW(fd,2));
  7382. }
  7383. /// Guild position information (ZC_POSITION_INFO).
  7384. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7385. /// mode:
  7386. /// &0x01 = allow invite
  7387. /// &0x10 = allow expel
  7388. /// ranking:
  7389. /// TODO
  7390. void clif_guild_positioninfolist(struct map_session_data *sd)
  7391. {
  7392. int i,fd;
  7393. struct guild *g;
  7394. nullpo_retv(sd);
  7395. if( (g = sd->guild) == NULL )
  7396. return;
  7397. fd = sd->fd;
  7398. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7399. WFIFOW(fd, 0)=0x160;
  7400. for(i=0;i<MAX_GUILDPOSITION;i++){
  7401. struct guild_position *p=&g->position[i];
  7402. WFIFOL(fd,i*16+ 4)=i;
  7403. WFIFOL(fd,i*16+ 8)=p->mode;
  7404. WFIFOL(fd,i*16+12)=i;
  7405. WFIFOL(fd,i*16+16)=p->exp_mode;
  7406. }
  7407. WFIFOW(fd, 2)=i*16+4;
  7408. WFIFOSET(fd,WFIFOW(fd,2));
  7409. }
  7410. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7411. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7412. /// mode:
  7413. /// &0x01 = allow invite
  7414. /// &0x10 = allow expel
  7415. /// ranking:
  7416. /// TODO
  7417. void clif_guild_positionchanged(struct guild *g,int idx)
  7418. {
  7419. // FIXME: This packet is intended to update the clients after a
  7420. // commit of position info changes, not sending one packet per
  7421. // position.
  7422. struct map_session_data *sd;
  7423. unsigned char buf[128];
  7424. nullpo_retv(g);
  7425. WBUFW(buf, 0)=0x174;
  7426. WBUFW(buf, 2)=44; // packet len
  7427. // GUILD_REG_POSITION_INFO{
  7428. WBUFL(buf, 4)=idx;
  7429. WBUFL(buf, 8)=g->position[idx].mode;
  7430. WBUFL(buf,12)=idx;
  7431. WBUFL(buf,16)=g->position[idx].exp_mode;
  7432. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7433. // }*
  7434. if( (sd=guild_getavailablesd(g))!=NULL )
  7435. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7436. }
  7437. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7438. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7439. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7440. {
  7441. // FIXME: This packet is intended to update the clients after a
  7442. // commit of member position assignment changes, not sending one
  7443. // packet per position.
  7444. struct map_session_data *sd;
  7445. unsigned char buf[64];
  7446. nullpo_retv(g);
  7447. WBUFW(buf, 0)=0x156;
  7448. WBUFW(buf, 2)=16; // packet len
  7449. // MEMBER_POSITION_INFO{
  7450. WBUFL(buf, 4)=g->member[idx].account_id;
  7451. WBUFL(buf, 8)=g->member[idx].char_id;
  7452. WBUFL(buf,12)=g->member[idx].position;
  7453. // }*
  7454. if( (sd=guild_getavailablesd(g))!=NULL )
  7455. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7456. }
  7457. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7458. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7459. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7460. {
  7461. int fd;
  7462. nullpo_retv(sd);
  7463. nullpo_retv(g);
  7464. fd = sd->fd;
  7465. if( g->emblem_len <= 0 )
  7466. return;
  7467. WFIFOHEAD(fd,g->emblem_len+12);
  7468. WFIFOW(fd,0)=0x152;
  7469. WFIFOW(fd,2)=g->emblem_len+12;
  7470. WFIFOL(fd,4)=g->guild_id;
  7471. WFIFOL(fd,8)=g->emblem_id;
  7472. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7473. WFIFOSET(fd,WFIFOW(fd,2));
  7474. }
  7475. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7476. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7477. void clif_guild_emblem_area(struct block_list* bl)
  7478. {
  7479. uint8 buf[12];
  7480. nullpo_retv(bl);
  7481. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7482. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7483. WBUFW(buf,0) = 0x1b4;
  7484. WBUFL(buf,2) = bl->id;
  7485. WBUFL(buf,6) = status_get_guild_id(bl);
  7486. WBUFW(buf,10) = status_get_emblem_id(bl);
  7487. clif_send(buf, 12, bl, AREA_WOS);
  7488. }
  7489. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7490. /// 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 }*
  7491. void clif_guild_skillinfo(struct map_session_data* sd)
  7492. {
  7493. int fd;
  7494. struct guild* g;
  7495. int i,c;
  7496. nullpo_retv(sd);
  7497. if( (g = sd->guild) == NULL )
  7498. return;
  7499. fd = sd->fd;
  7500. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7501. WFIFOW(fd,0) = 0x0162;
  7502. WFIFOW(fd,4) = g->skill_point;
  7503. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7504. {
  7505. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7506. {
  7507. int id = g->skill[i].id;
  7508. int p = 6 + c*37;
  7509. WFIFOW(fd,p+0) = id;
  7510. WFIFOL(fd,p+2) = skill_get_inf(id);
  7511. WFIFOW(fd,p+6) = g->skill[i].lv;
  7512. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7513. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7514. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7515. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7516. c++;
  7517. }
  7518. }
  7519. WFIFOW(fd,2) = 6 + c*37;
  7520. WFIFOSET(fd,WFIFOW(fd,2));
  7521. }
  7522. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7523. /// 016f <subject>.60B <notice>.120B
  7524. void clif_guild_notice(struct map_session_data* sd)
  7525. {
  7526. int fd;
  7527. struct guild* g;
  7528. nullpo_retv(sd);
  7529. nullpo_retv(g = sd->guild);
  7530. fd = sd->fd;
  7531. if ( !session_isActive(fd) )
  7532. return;
  7533. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7534. return;
  7535. WFIFOHEAD(fd,packet_len(0x16f));
  7536. WFIFOW(fd,0) = 0x16f;
  7537. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7538. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7539. WFIFOSET(fd,packet_len(0x16f));
  7540. }
  7541. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7542. /// 016a <guild id>.L <guild name>.24B
  7543. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7544. {
  7545. int fd;
  7546. nullpo_retv(sd);
  7547. nullpo_retv(g);
  7548. fd=sd->fd;
  7549. WFIFOHEAD(fd,packet_len(0x16a));
  7550. WFIFOW(fd,0)=0x16a;
  7551. WFIFOL(fd,2)=g->guild_id;
  7552. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7553. WFIFOSET(fd,packet_len(0x16a));
  7554. }
  7555. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7556. /// 0169 <answer>.B
  7557. /// answer:
  7558. /// 0 = Already in guild.
  7559. /// 1 = Offer rejected.
  7560. /// 2 = Offer accepted.
  7561. /// 3 = Guild full.
  7562. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7563. {
  7564. int fd;
  7565. nullpo_retv(sd);
  7566. fd=sd->fd;
  7567. WFIFOHEAD(fd,packet_len(0x169));
  7568. WFIFOW(fd,0)=0x169;
  7569. WFIFOB(fd,2)=flag;
  7570. WFIFOSET(fd,packet_len(0x169));
  7571. }
  7572. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7573. /// 015a <char name>.24B <reason>.40B
  7574. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7575. {
  7576. unsigned char buf[128];
  7577. nullpo_retv(sd);
  7578. WBUFW(buf, 0)=0x15a;
  7579. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7580. memcpy(WBUFP(buf,26),mes,40);
  7581. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7582. }
  7583. /// Notifies clients of a guild of an expelled member.
  7584. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7585. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7586. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7587. {
  7588. unsigned char buf[128];
  7589. #if PACKETVER < 20100803
  7590. const unsigned short cmd = 0x15c;
  7591. #else
  7592. const unsigned short cmd = 0x839;
  7593. #endif
  7594. nullpo_retv(sd);
  7595. WBUFW(buf,0) = cmd;
  7596. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7597. safestrncpy(WBUFCP(buf,26), mes, 40);
  7598. #if PACKETVER < 20100803
  7599. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7600. #endif
  7601. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7602. }
  7603. /// Guild expulsion list (ZC_BAN_LIST).
  7604. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7605. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7606. void clif_guild_expulsionlist(struct map_session_data* sd)
  7607. {
  7608. #if PACKETVER < 20100803
  7609. const int offset = NAME_LENGTH*2+40;
  7610. #else
  7611. const int offset = NAME_LENGTH+40;
  7612. #endif
  7613. int fd, i, c = 0;
  7614. struct guild* g;
  7615. nullpo_retv(sd);
  7616. if( (g = sd->guild) == NULL )
  7617. return;
  7618. fd = sd->fd;
  7619. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7620. WFIFOW(fd,0) = 0x163;
  7621. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7622. {
  7623. struct guild_expulsion* e = &g->expulsion[i];
  7624. if( e->account_id > 0 )
  7625. {
  7626. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7627. #if PACKETVER < 20100803
  7628. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7629. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7630. #else
  7631. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7632. #endif
  7633. c++;
  7634. }
  7635. }
  7636. WFIFOW(fd,2) = 4 + c*offset;
  7637. WFIFOSET(fd,WFIFOW(fd,2));
  7638. }
  7639. /// Guild chat message (ZC_GUILD_CHAT).
  7640. /// 017f <packet len>.W <message>.?B
  7641. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7642. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7643. struct map_session_data *sd;
  7644. uint8 buf[256];
  7645. if( len == 0 )
  7646. {
  7647. return;
  7648. }
  7649. else if( len > sizeof(buf)-5 )
  7650. {
  7651. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7652. len = sizeof(buf)-5;
  7653. }
  7654. WBUFW(buf, 0) = 0x17f;
  7655. WBUFW(buf, 2) = len + 5;
  7656. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7657. if ((sd = guild_getavailablesd(g)) != NULL)
  7658. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7659. }
  7660. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7661. /// 0171 <inviter account id>.L <guild name>.24B
  7662. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7663. {
  7664. int fd;
  7665. nullpo_retv(sd);
  7666. fd=sd->fd;
  7667. WFIFOHEAD(fd,packet_len(0x171));
  7668. WFIFOW(fd,0)=0x171;
  7669. WFIFOL(fd,2)=account_id;
  7670. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7671. WFIFOSET(fd,packet_len(0x171));
  7672. }
  7673. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7674. /// 0173 <answer>.B
  7675. /// answer:
  7676. /// 0 = Already allied.
  7677. /// 1 = You rejected the offer.
  7678. /// 2 = You accepted the offer.
  7679. /// 3 = They have too any alliances.
  7680. /// 4 = You have too many alliances.
  7681. /// 5 = Alliances are disabled.
  7682. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7683. {
  7684. int fd;
  7685. nullpo_retv(sd);
  7686. fd=sd->fd;
  7687. WFIFOHEAD(fd,packet_len(0x173));
  7688. WFIFOW(fd,0)=0x173;
  7689. WFIFOL(fd,2)=flag;
  7690. WFIFOSET(fd,packet_len(0x173));
  7691. }
  7692. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7693. /// 0184 <other guild id>.L <relation>.L
  7694. /// relation:
  7695. /// 0 = Ally
  7696. /// 1 = Enemy
  7697. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7698. {
  7699. int fd;
  7700. nullpo_retv(sd);
  7701. fd = sd->fd;
  7702. if (fd <= 0)
  7703. return;
  7704. WFIFOHEAD(fd,packet_len(0x184));
  7705. WFIFOW(fd,0)=0x184;
  7706. WFIFOL(fd,2)=guild_id;
  7707. WFIFOL(fd,6)=flag;
  7708. WFIFOSET(fd,packet_len(0x184));
  7709. }
  7710. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7711. /// 0181 <result>.B
  7712. /// result:
  7713. /// 0 = Antagonist has been set.
  7714. /// 1 = Guild has too many Antagonists.
  7715. /// 2 = Already set as an Antagonist.
  7716. /// 3 = Antagonists are disabled.
  7717. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7718. {
  7719. int fd;
  7720. nullpo_retv(sd);
  7721. fd=sd->fd;
  7722. WFIFOHEAD(fd,packet_len(0x181));
  7723. WFIFOW(fd,0)=0x181;
  7724. WFIFOB(fd,2)=flag;
  7725. WFIFOSET(fd,packet_len(0x181));
  7726. }
  7727. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7728. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7729. /*
  7730. void clif_guild_allianceadded(struct guild *g,int idx)
  7731. {
  7732. unsigned char buf[64];
  7733. WBUFW(buf,0)=0x185;
  7734. WBUFL(buf,2)=g->alliance[idx].opposition;
  7735. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7736. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7737. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7738. }
  7739. */
  7740. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7741. /// 015e <reason>.L
  7742. /// 0 = success
  7743. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7744. /// 2 = there are still members in the guild
  7745. void clif_guild_broken(struct map_session_data *sd,int flag)
  7746. {
  7747. int fd;
  7748. nullpo_retv(sd);
  7749. fd=sd->fd;
  7750. WFIFOHEAD(fd,packet_len(0x15e));
  7751. WFIFOW(fd,0)=0x15e;
  7752. WFIFOL(fd,2)=flag;
  7753. WFIFOSET(fd,packet_len(0x15e));
  7754. }
  7755. /// Displays emotion on an object (ZC_EMOTION).
  7756. /// 00c0 <id>.L <type>.B
  7757. /// type:
  7758. /// enum emotion_type
  7759. void clif_emotion(struct block_list *bl,int type)
  7760. {
  7761. unsigned char buf[8];
  7762. nullpo_retv(bl);
  7763. WBUFW(buf,0)=0xc0;
  7764. WBUFL(buf,2)=bl->id;
  7765. WBUFB(buf,6)=type;
  7766. clif_send(buf,packet_len(0xc0),bl,AREA);
  7767. }
  7768. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7769. /// 0191 <id>.L <contents>.80B
  7770. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7771. {
  7772. unsigned char buf[MESSAGE_SIZE+6];
  7773. nullpo_retv(bl);
  7774. WBUFW(buf,0) = 0x191;
  7775. WBUFL(buf,2) = bl->id;
  7776. safestrncpy(WBUFCP(buf,6),talkie,MESSAGE_SIZE);
  7777. clif_send(buf,packet_len(0x191),bl,AREA);
  7778. }
  7779. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7780. /// 01ea <id>.L
  7781. void clif_wedding_effect(struct block_list *bl)
  7782. {
  7783. unsigned char buf[6];
  7784. nullpo_retv(bl);
  7785. WBUFW(buf,0) = 0x1ea;
  7786. WBUFL(buf,2) = bl->id;
  7787. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7788. }
  7789. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7790. /// 01e6 <partner name>.24B
  7791. void clif_callpartner(struct map_session_data *sd)
  7792. {
  7793. unsigned char buf[26];
  7794. nullpo_retv(sd);
  7795. WBUFW(buf,0) = 0x1e6;
  7796. if( sd->status.partner_id ) {
  7797. const char *p = map_charid2nick(sd->status.partner_id);
  7798. struct map_session_data *p_sd = pc_get_partner(sd);
  7799. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7800. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  7801. else
  7802. WBUFB(buf,2) = 0;
  7803. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7804. WBUFB(buf,2) = 0;
  7805. }
  7806. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7807. }
  7808. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7809. /// 01e4
  7810. /// This packet while still implemented by the client is no longer being officially used.
  7811. /*
  7812. void clif_marriage_process(struct map_session_data *sd)
  7813. {
  7814. int fd;
  7815. nullpo_retv(sd);
  7816. fd=sd->fd;
  7817. WFIFOHEAD(fd,packet_len(0x1e4));
  7818. WFIFOW(fd,0)=0x1e4;
  7819. WFIFOSET(fd,packet_len(0x1e4));
  7820. }
  7821. */
  7822. /// Notice of divorce (ZC_DIVORCE).
  7823. /// 0205 <partner name>.24B
  7824. void clif_divorced(struct map_session_data* sd, const char* name)
  7825. {
  7826. int fd;
  7827. nullpo_retv(sd);
  7828. fd=sd->fd;
  7829. WFIFOHEAD(fd,packet_len(0x205));
  7830. WFIFOW(fd,0)=0x205;
  7831. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7832. WFIFOSET(fd, packet_len(0x205));
  7833. }
  7834. /// Marriage proposal (ZC_REQ_COUPLE).
  7835. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7836. /// This packet while still implemented by the client is no longer being officially used.
  7837. /*
  7838. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7839. {
  7840. nullpo_retv(sd);
  7841. WFIFOHEAD(fd,packet_len(0x1e2));
  7842. WFIFOW(fd,0) = 0x1e2;
  7843. WFIFOL(fd,2) = ssd->status.account_id;
  7844. WFIFOL(fd,6) = ssd->status.char_id;
  7845. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7846. WFIFOSET(fd, packet_len(0x1e2));
  7847. }
  7848. */
  7849. /*==========================================
  7850. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7851. *------------------------------------------*/
  7852. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7853. {
  7854. unsigned char buf[256];
  7855. if( len == 0 ) {
  7856. return;
  7857. } else if( len > sizeof(buf)-5 ) {
  7858. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7859. len = sizeof(buf)-5;
  7860. }
  7861. WBUFW(buf, 0) = 0x17f;
  7862. WBUFW(buf, 2) = len + 5;
  7863. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7864. clif_send(buf, WBUFW(buf,2), src, target);
  7865. }
  7866. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7867. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7868. /// 00cd <result>.B
  7869. /// result:
  7870. /// 0 = failure
  7871. /// 1 = success
  7872. void clif_GM_kickack(struct map_session_data *sd, int id)
  7873. {
  7874. int fd;
  7875. nullpo_retv(sd);
  7876. fd = sd->fd;
  7877. WFIFOHEAD(fd,packet_len(0xcd));
  7878. WFIFOW(fd,0) = 0xcd;
  7879. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7880. WFIFOSET(fd, packet_len(0xcd));
  7881. }
  7882. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  7883. {
  7884. int fd;
  7885. nullpo_retv(tsd);
  7886. fd = tsd->fd;
  7887. if (sd == NULL)
  7888. tsd->state.keepshop = true;
  7889. if (fd > 0)
  7890. clif_authfail_fd(fd, 15);
  7891. else
  7892. map_quit(tsd);
  7893. if (sd)
  7894. clif_GM_kickack(sd, tsd->status.account_id);
  7895. }
  7896. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7897. /// 014a <result>.L
  7898. /// result:
  7899. /// 0 = "A manner point has been successfully aligned."
  7900. /// 1 = MP_FAILURE_EXHAUST
  7901. /// 2 = MP_FAILURE_ALREADY_GIVING
  7902. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7903. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7904. /// 5 = "You got a good point from %s."
  7905. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7906. {
  7907. int fd;
  7908. nullpo_retv(sd);
  7909. fd = sd->fd;
  7910. WFIFOHEAD(fd,packet_len(0x14a));
  7911. WFIFOW(fd,0) = 0x14a;
  7912. WFIFOL(fd,2) = type;
  7913. WFIFOSET(fd, packet_len(0x14a));
  7914. }
  7915. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7916. /// 014b <type>.B <GM name>.24B
  7917. /// type:
  7918. /// 0 = positive (unmute)
  7919. /// 1 = negative (mute)
  7920. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7921. {
  7922. int fd;
  7923. nullpo_retv(sd);
  7924. nullpo_retv(tsd);
  7925. fd = tsd->fd;
  7926. WFIFOHEAD(fd,packet_len(0x14b));
  7927. WFIFOW(fd,0) = 0x14b;
  7928. WFIFOB(fd,2) = type;
  7929. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  7930. WFIFOSET(fd, packet_len(0x14b));
  7931. }
  7932. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7933. /// 00d1 <type>.B <result>.B
  7934. /// type:
  7935. /// 0 = /ex (deny)
  7936. /// 1 = /in (allow)
  7937. /// result:
  7938. /// 0 = success
  7939. /// 1 = failure
  7940. /// 2 = too many blocks
  7941. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7942. {
  7943. int fd;
  7944. nullpo_retv(sd);
  7945. fd=sd->fd;
  7946. WFIFOHEAD(fd,packet_len(0xd1));
  7947. WFIFOW(fd,0)=0xd1;
  7948. WFIFOB(fd,2)=type;
  7949. WFIFOB(fd,3)=flag;
  7950. WFIFOSET(fd,packet_len(0xd1));
  7951. }
  7952. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7953. /// 00d2 <type>.B <result>.B
  7954. /// type:
  7955. /// 0 = /exall (deny)
  7956. /// 1 = /inall (allow)
  7957. /// result:
  7958. /// 0 = success
  7959. /// 1 = failure
  7960. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7961. {
  7962. int fd;
  7963. nullpo_retv(sd);
  7964. fd=sd->fd;
  7965. WFIFOHEAD(fd,packet_len(0xd2));
  7966. WFIFOW(fd,0)=0xd2;
  7967. WFIFOB(fd,2)=type;
  7968. WFIFOB(fd,3)=flag;
  7969. WFIFOSET(fd,packet_len(0xd2));
  7970. }
  7971. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7972. /// 07fe <bgm>.24B
  7973. void clif_playBGM(struct map_session_data* sd, const char* name)
  7974. {
  7975. int fd;
  7976. nullpo_retv(sd);
  7977. fd = sd->fd;
  7978. WFIFOHEAD(fd,packet_len(0x7fe));
  7979. WFIFOW(fd,0) = 0x7fe;
  7980. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7981. WFIFOSET(fd,packet_len(0x7fe));
  7982. }
  7983. /// Plays/stops a wave sound (ZC_SOUND).
  7984. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7985. /// file name:
  7986. /// relative to data\wav
  7987. /// act:
  7988. /// 0 = play (once)
  7989. /// 1 = play (repeat, does not work)
  7990. /// 2 = stops all sound instances of file name (does not work)
  7991. /// term:
  7992. /// unknown purpose, only relevant to act = 1
  7993. /// npc id:
  7994. /// The accustic direction of the sound is determined by the
  7995. /// relative position of the NPC to the player (3D sound).
  7996. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7997. {
  7998. int fd;
  7999. nullpo_retv(sd);
  8000. nullpo_retv(bl);
  8001. fd = sd->fd;
  8002. WFIFOHEAD(fd,packet_len(0x1d3));
  8003. WFIFOW(fd,0) = 0x1d3;
  8004. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8005. WFIFOB(fd,26) = type;
  8006. WFIFOL(fd,27) = 0;
  8007. WFIFOL(fd,31) = bl->id;
  8008. WFIFOSET(fd,packet_len(0x1d3));
  8009. }
  8010. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  8011. {
  8012. unsigned char buf[40];
  8013. nullpo_retv(bl);
  8014. WBUFW(buf,0) = 0x1d3;
  8015. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  8016. WBUFB(buf,26) = type;
  8017. WBUFL(buf,27) = 0;
  8018. WBUFL(buf,31) = bl->id;
  8019. clif_send(buf, packet_len(0x1d3), bl, coverage);
  8020. }
  8021. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8022. /// 01f3 <id>.L <effect id>.L
  8023. /// effect id:
  8024. /// @see doc/effect_list.txt
  8025. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8026. {
  8027. unsigned char buf[24];
  8028. nullpo_retv(bl);
  8029. memset(buf, 0, packet_len(0x1f3));
  8030. WBUFW(buf,0) = 0x1f3;
  8031. WBUFL(buf,2) = bl->id;
  8032. WBUFL(buf,6) = type;
  8033. clif_send(buf, packet_len(0x1f3), bl, target);
  8034. if (disguised(bl)) {
  8035. WBUFL(buf,2) = -bl->id;
  8036. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8037. }
  8038. }
  8039. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8040. {
  8041. WFIFOHEAD(fd,10);
  8042. WFIFOW(fd,0) = 0x1f3;
  8043. WFIFOL(fd,2) = bl->id;
  8044. WFIFOL(fd,6) = type;
  8045. WFIFOSET(fd,10);
  8046. }
  8047. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8048. /// 0284 <id>.L <effect id>.L <num data>.L
  8049. /// effect id:
  8050. /// @see doc/effect_list.txt
  8051. /// num data:
  8052. /// effect-dependent value
  8053. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8054. {
  8055. uint8 buf[14];
  8056. WBUFW(buf,0) = 0x284;
  8057. WBUFL(buf,2) = bl->id;
  8058. WBUFL(buf,6) = effect_id;
  8059. WBUFL(buf,10) = num;
  8060. clif_send(buf, packet_len(0x284), bl, target);
  8061. if( disguised(bl) )
  8062. {
  8063. WBUFL(buf,2) = -bl->id;
  8064. clif_send(buf, packet_len(0x284), bl, SELF);
  8065. }
  8066. }
  8067. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8068. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8069. 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) {
  8070. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8071. uint8 buf[CHAT_SIZE_MAX];
  8072. nullpo_retv(bl);
  8073. if (msg_len > sizeof(buf) - 12) {
  8074. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8075. msg_len = sizeof(buf) - 12;
  8076. }
  8077. if (rgb2bgr)
  8078. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8079. WBUFW(buf,0) = 0x2C1;
  8080. WBUFW(buf,2) = msg_len + 12;
  8081. WBUFL(buf,4) = bl->id;
  8082. WBUFL(buf,8) = color;
  8083. memcpy(WBUFCP(buf,12), msg, msg_len);
  8084. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8085. }
  8086. /**
  8087. * Notifies the client that the storage window is still open
  8088. *
  8089. * Should only be used in cases where the client closed the
  8090. * storage window without server's consent
  8091. */
  8092. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8093. // Notify the client that the storage is open
  8094. if( sd->state.storage_flag == 1 ) {
  8095. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8096. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8097. clif_updatestorageamount(sd, sd->storage.amount, MAX_STORAGE);
  8098. }
  8099. // Notify the client that the gstorage is open otherwise it will
  8100. // remain locked forever and nobody will be able to access it
  8101. if( sd->state.storage_flag == 2 ) {
  8102. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8103. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8104. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8105. else {
  8106. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8107. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8108. clif_updatestorageamount(sd, gstor->amount, MAX_GUILD_STORAGE);
  8109. }
  8110. }
  8111. }
  8112. // refresh the client's screen, getting rid of any effects
  8113. void clif_refresh(struct map_session_data *sd)
  8114. {
  8115. nullpo_retv(sd);
  8116. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8117. clif_inventorylist(sd);
  8118. if(pc_iscarton(sd)) {
  8119. clif_cartlist(sd);
  8120. clif_updatestatus(sd,SP_CARTINFO);
  8121. }
  8122. clif_updatestatus(sd,SP_WEIGHT);
  8123. clif_updatestatus(sd,SP_MAXWEIGHT);
  8124. clif_updatestatus(sd,SP_STR);
  8125. clif_updatestatus(sd,SP_AGI);
  8126. clif_updatestatus(sd,SP_VIT);
  8127. clif_updatestatus(sd,SP_INT);
  8128. clif_updatestatus(sd,SP_DEX);
  8129. clif_updatestatus(sd,SP_LUK);
  8130. if (sd->spiritball)
  8131. clif_spiritball_single(sd->fd, sd);
  8132. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8133. clif_spiritcharm_single(sd->fd, sd);
  8134. if (sd->vd.cloth_color)
  8135. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8136. if (sd->vd.body_style)
  8137. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8138. if(hom_is_active(sd->hd))
  8139. clif_send_homdata(sd,SP_ACK,0);
  8140. if( sd->md ) {
  8141. clif_mercenary_info(sd);
  8142. clif_mercenary_skillblock(sd);
  8143. }
  8144. if( sd->ed )
  8145. clif_elemental_info(sd);
  8146. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8147. clif_weather_check(sd);
  8148. if( sd->chatID )
  8149. chat_leavechat(sd,0);
  8150. if( sd->state.vending )
  8151. clif_openvending(sd, sd->bl.id, sd->vending);
  8152. if( pc_issit(sd) )
  8153. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8154. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8155. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8156. else
  8157. clif_changed_dir(&sd->bl, SELF);
  8158. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8159. //Issue #2143
  8160. //Cancel Trading State
  8161. if (sd->state.trading)
  8162. trade_tradecancel(sd);
  8163. //Cancel Buying/Selling State
  8164. if (sd->state.buyingstore)
  8165. buyingstore_close(sd);
  8166. mail_clear(sd);
  8167. if( disguised(&sd->bl) ) {/* refresh-da */
  8168. short disguise = sd->disguise;
  8169. pc_disguise(sd, 0);
  8170. pc_disguise(sd, disguise);
  8171. }
  8172. clif_refresh_storagewindow(sd);
  8173. }
  8174. /// Updates the object's (bl) name on client.
  8175. /// Used to update when a char leaves a party/guild. [Skotlex]
  8176. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8177. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8178. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8179. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8180. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8181. unsigned char buf[106];
  8182. int cmd = 0x95;
  8183. nullpo_retv(src);
  8184. nullpo_retv(bl);
  8185. WBUFW(buf,0) = cmd;
  8186. WBUFL(buf,2) = bl->id;
  8187. switch( bl->type )
  8188. {
  8189. case BL_PC:
  8190. {
  8191. struct map_session_data *sd = (struct map_session_data *)bl;
  8192. struct party_data *p = NULL;
  8193. #if PACKETVER >= 20150513
  8194. WBUFW(buf, 0) = cmd = 0xa30;
  8195. #else
  8196. WBUFW(buf, 0) = cmd = 0x195;
  8197. #endif
  8198. //Requesting your own "shadow" name. [Skotlex]
  8199. if( src == bl && target == SELF && sd->disguise ){
  8200. WBUFL(buf,2) = -bl->id;
  8201. }
  8202. if( sd->fakename[0] ) {
  8203. safestrncpy(WBUFCP(buf,6), sd->fakename, NAME_LENGTH);
  8204. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  8205. #if PACKETVER >= 20150513
  8206. WBUFL(buf,102) = 0; // Title ID
  8207. #endif
  8208. break;
  8209. }
  8210. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  8211. if( sd->status.party_id ){
  8212. p = party_search(sd->status.party_id);
  8213. }
  8214. // do not display party unless the player is also in a guild
  8215. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8216. safestrncpy(WBUFCP(buf,30), p->party.name, NAME_LENGTH);
  8217. }else{
  8218. WBUFB(buf,30) = 0;
  8219. }
  8220. if( sd->guild ){
  8221. int position;
  8222. // Will get the position of the guild the player is in
  8223. position = guild_getposition(sd);
  8224. safestrncpy(WBUFCP(buf,54), sd->guild->name,NAME_LENGTH);
  8225. safestrncpy(WBUFCP(buf,78), sd->guild->position[position].name, NAME_LENGTH);
  8226. }else if( sd->clan ){
  8227. WBUFB(buf,54) = 0;
  8228. safestrncpy(WBUFCP(buf,78), sd->clan->name,NAME_LENGTH);
  8229. }else{ //Assume no guild and no clan
  8230. WBUFB(buf,54) = 0;
  8231. WBUFB(buf,78) = 0;
  8232. }
  8233. #if PACKETVER >= 20150513
  8234. WBUFL(buf,102) = sd->status.title_id; // Title ID
  8235. #endif
  8236. }
  8237. break;
  8238. //[blackhole89]
  8239. case BL_HOM:
  8240. safestrncpy(WBUFCP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  8241. break;
  8242. case BL_MER:
  8243. safestrncpy(WBUFCP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  8244. break;
  8245. case BL_PET:
  8246. safestrncpy(WBUFCP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  8247. break;
  8248. case BL_NPC:
  8249. safestrncpy(WBUFCP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  8250. break;
  8251. case BL_MOB:
  8252. {
  8253. struct mob_data *md = (struct mob_data *)bl;
  8254. nullpo_retv(md);
  8255. safestrncpy(WBUFCP(buf,6), md->name, NAME_LENGTH);
  8256. if( md->guardian_data && md->guardian_data->guild_id )
  8257. {
  8258. #if PACKETVER >= 20150513
  8259. WBUFW(buf, 0) = cmd = 0xa30;
  8260. #else
  8261. WBUFW(buf, 0) = cmd = 0x195;
  8262. #endif
  8263. WBUFB(buf,30) = 0;
  8264. safestrncpy(WBUFCP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  8265. safestrncpy(WBUFCP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  8266. }
  8267. else if( battle_config.show_mob_info )
  8268. {
  8269. char mobhp[50], *str_p = mobhp;
  8270. #if PACKETVER >= 20150513
  8271. WBUFW(buf, 0) = cmd = 0xa30;
  8272. #else
  8273. WBUFW(buf, 0) = cmd = 0x195;
  8274. #endif
  8275. if( battle_config.show_mob_info&4 )
  8276. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  8277. if( battle_config.show_mob_info&1 )
  8278. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  8279. if( battle_config.show_mob_info&2 )
  8280. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  8281. //Even thought mobhp ain't a name, we send it as one so the client
  8282. //can parse it. [Skotlex]
  8283. if( str_p != mobhp )
  8284. {
  8285. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8286. safestrncpy(WBUFCP(buf,30), mobhp, NAME_LENGTH);
  8287. WBUFB(buf,54) = 0;
  8288. WBUFB(buf,78) = 0;
  8289. }
  8290. }
  8291. #if PACKETVER >= 20150513
  8292. WBUFL(buf, 102) = 0; // Title ID
  8293. #endif
  8294. }
  8295. break;
  8296. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  8297. // safestrncpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  8298. // break;
  8299. return;
  8300. case BL_ELEM:
  8301. safestrncpy(WBUFCP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  8302. break;
  8303. default:
  8304. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8305. return;
  8306. }
  8307. clif_send(buf, packet_len(cmd), src, target);
  8308. }
  8309. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8310. /// 01ff <id>.L <x>.W <y>.W
  8311. ///
  8312. /// Visually moves(instant) a character to x,y. The char moves even
  8313. /// when the target cell isn't walkable. If the char is sitting it
  8314. /// stays that way.
  8315. void clif_slide(struct block_list *bl, int x, int y)
  8316. {
  8317. unsigned char buf[10];
  8318. nullpo_retv(bl);
  8319. WBUFW(buf, 0) = 0x01ff;
  8320. WBUFL(buf, 2) = bl->id;
  8321. WBUFW(buf, 6) = x;
  8322. WBUFW(buf, 8) = y;
  8323. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8324. if( disguised(bl) )
  8325. {
  8326. WBUFL(buf,2) = -bl->id;
  8327. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8328. }
  8329. }
  8330. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8331. /// 008d <packet len>.W <id>.L <message>.?B
  8332. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8333. {
  8334. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8335. int len_mes = strlen(mes)+1; //Account for \0
  8336. if (len_mes > sizeof(buf)-8) {
  8337. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8338. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8339. }
  8340. // send message to others
  8341. if (flag == AREA) {
  8342. WBUFW(buf,0) = 0x8d;
  8343. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8344. WBUFL(buf,4) = bl->id;
  8345. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8346. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8347. }
  8348. // send back message to the speaker
  8349. if( bl->type == BL_PC ) {
  8350. WBUFW(buf,0) = 0x8e;
  8351. WBUFW(buf, 2) = len_mes + 4;
  8352. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8353. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8354. }
  8355. }
  8356. /*==========================
  8357. * Minimap fix [Kevin]
  8358. * Remove dot from minimap
  8359. *--------------------------*/
  8360. void clif_party_xy_remove(struct map_session_data *sd)
  8361. {
  8362. unsigned char buf[16];
  8363. nullpo_retv(sd);
  8364. WBUFW(buf,0)=0x107;
  8365. WBUFL(buf,2)=sd->status.account_id;
  8366. WBUFW(buf,6)=-1;
  8367. WBUFW(buf,8)=-1;
  8368. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8369. }
  8370. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8371. /// 0215 <msg id>.L
  8372. /// msg id:
  8373. /// 0x15 = End all negative status (PA_GOSPEL)
  8374. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8375. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8376. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8377. /// 0x19 = All stats +20 (PA_GOSPEL)
  8378. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8379. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8380. /// 0x1e = DEF +25% (PA_GOSPEL)
  8381. /// 0x1f = ATK +100% (PA_GOSPEL)
  8382. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8383. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8384. /// ? = nothing
  8385. void clif_gospel_info(struct map_session_data *sd, int type)
  8386. {
  8387. int fd=sd->fd;
  8388. WFIFOHEAD(fd,packet_len(0x215));
  8389. WFIFOW(fd,0)=0x215;
  8390. WFIFOL(fd,2)=type;
  8391. WFIFOSET(fd, packet_len(0x215));
  8392. }
  8393. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8394. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8395. /// result:
  8396. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8397. /// star:
  8398. /// 0 = Place of the Sun
  8399. /// 1 = Place of the Moon
  8400. /// 2 = Place of the Stars
  8401. /// 1 = Star Gladiator %s's %s: <mapname>
  8402. /// star:
  8403. /// 0 = Place of the Sun
  8404. /// 1 = Place of the Moon
  8405. /// 2 = Place of the Stars
  8406. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8407. /// star:
  8408. /// 0 = Target of the Sun
  8409. /// 1 = Target of the Moon
  8410. /// 2 = Target of the Stars
  8411. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8412. /// star:
  8413. /// 0 = Monster of the Sun
  8414. /// 1 = Monster of the Moon
  8415. /// 2 = Monster of the Stars
  8416. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8417. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8418. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8419. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8420. /// 40 = Target HP : <monster_id used as HP>
  8421. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8422. {
  8423. int fd = sd->fd;
  8424. WFIFOHEAD(fd,packet_len(0x20e));
  8425. WFIFOW(fd,0) = 0x20e;
  8426. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8427. WFIFOL(fd,26) = monster_id;
  8428. WFIFOB(fd,30) = star;
  8429. WFIFOB(fd,31) = result;
  8430. WFIFOSET(fd,packet_len(0x20e));
  8431. }
  8432. /*==========================================
  8433. * Info about Star Glaldiator save map [Komurka]
  8434. * type: 1: Information, 0: Map registered
  8435. *------------------------------------------*/
  8436. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8437. {
  8438. char mapname[MAP_NAME_LENGTH_EXT];
  8439. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8440. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8441. }
  8442. /*==========================================
  8443. * Info about Star Glaldiator hate mob [Komurka]
  8444. * type: 1: Register mob, 0: Information.
  8445. *------------------------------------------*/
  8446. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8447. {
  8448. if( pcdb_checkid(class_) ) {
  8449. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8450. } else if( mobdb_checkid(class_) ) {
  8451. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  8452. } else {
  8453. 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);
  8454. }
  8455. }
  8456. /*==========================================
  8457. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8458. *------------------------------------------*/
  8459. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8460. {
  8461. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  8462. }
  8463. /*==========================================
  8464. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8465. *------------------------------------------*/
  8466. void clif_feel_hate_reset(struct map_session_data *sd)
  8467. {
  8468. clif_starskill(sd, "", 0, 0, 30);
  8469. }
  8470. /// Send out reply to configuration change
  8471. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8472. /// type: see enum e_config_type
  8473. /// value:
  8474. /// false = disabled
  8475. /// true = enabled
  8476. void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled ){
  8477. int fd;
  8478. nullpo_retv(sd);
  8479. fd = sd->fd;
  8480. WFIFOHEAD(fd, packet_len(0x2d9));
  8481. WFIFOW(fd, 0) = 0x2d9;
  8482. WFIFOL(fd, 2) = type;
  8483. WFIFOL(fd, 6) = enabled;
  8484. WFIFOSET(fd, packet_len(0x2d9));
  8485. }
  8486. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8487. /// 02da <open equip window>.B
  8488. /// open equip window:
  8489. /// 0 = disabled
  8490. /// 1 = enabled
  8491. void clif_equipcheckbox(struct map_session_data* sd)
  8492. {
  8493. int fd;
  8494. nullpo_retv(sd);
  8495. fd = sd->fd;
  8496. WFIFOHEAD(fd, packet_len(0x2da));
  8497. WFIFOW(fd, 0) = 0x2da;
  8498. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8499. WFIFOSET(fd, packet_len(0x2da));
  8500. }
  8501. /// Sends info about a player's equipped items.
  8502. /// 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)
  8503. /// 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)
  8504. /// 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)
  8505. /// 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)
  8506. /// 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)
  8507. /// 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)
  8508. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  8509. {
  8510. uint8* buf;
  8511. int i, n, fd, offset = 0;
  8512. #if PACKETVER < 20100629
  8513. const int s = 26;
  8514. #elif PACKETVER < 20120925
  8515. const int s = 28;
  8516. #elif PACKETVER < 20150225
  8517. const int s = 31;
  8518. #else
  8519. const int s = 57;
  8520. #endif
  8521. nullpo_retv(sd);
  8522. nullpo_retv(tsd);
  8523. fd = sd->fd;
  8524. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  8525. buf = WFIFOP(fd,0);
  8526. #if PACKETVER < 20101124
  8527. WBUFW(buf, 0) = 0x2d7;
  8528. #elif PACKETVER < 20120925
  8529. WBUFW(buf, 0) = 0x859;
  8530. #elif PACKETVER < 20150225
  8531. WBUFW(buf, 0) = 0x997;
  8532. #else
  8533. WBUFW(buf, 0) = 0xa2d;
  8534. #endif
  8535. safestrncpy(WBUFCP(buf, 4), tsd->status.name, NAME_LENGTH);
  8536. WBUFW(buf,28) = tsd->status.class_;
  8537. WBUFW(buf,30) = tsd->vd.hair_style;
  8538. WBUFW(buf,32) = tsd->vd.head_bottom;
  8539. WBUFW(buf,34) = tsd->vd.head_mid;
  8540. WBUFW(buf,36) = tsd->vd.head_top;
  8541. #if PACKETVER >= 20110111
  8542. WBUFW(buf,38) = tsd->vd.robe;
  8543. offset+= 2;
  8544. buf = WBUFP(buf,2);
  8545. #endif
  8546. WBUFW(buf,38) = tsd->vd.hair_color;
  8547. WBUFW(buf,40) = tsd->vd.cloth_color;
  8548. WBUFB(buf,42) = tsd->vd.sex;
  8549. for(i=0,n=0; i < MAX_INVENTORY; i++)
  8550. {
  8551. if (tsd->inventory.u.items_inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  8552. continue;
  8553. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  8554. continue;
  8555. // Add item info : refine, identify flag, element, etc.
  8556. 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));
  8557. n++;
  8558. }
  8559. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  8560. WFIFOSET(fd, WFIFOW(fd, 2));
  8561. }
  8562. /// Display msgstringtable.txt string (ZC_MSG).
  8563. /// 0291 <message>.W
  8564. void clif_msg(struct map_session_data* sd, unsigned short id)
  8565. {
  8566. int fd;
  8567. nullpo_retv(sd);
  8568. fd = sd->fd;
  8569. WFIFOHEAD(fd, packet_len(0x291));
  8570. WFIFOW(fd, 0) = 0x291;
  8571. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8572. WFIFOSET(fd, packet_len(0x291));
  8573. }
  8574. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8575. /// 0x7e2 <message>.W <value>.L
  8576. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8577. {
  8578. int fd = sd->fd;
  8579. WFIFOHEAD(fd, packet_len(0x7e2));
  8580. WFIFOW(fd,0) = 0x7e2;
  8581. WFIFOW(fd,2) = id;
  8582. WFIFOL(fd,4) = value;
  8583. WFIFOSET(fd, packet_len(0x7e2));
  8584. }
  8585. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8586. /// 07e6 <skill id>.W <msg id>.L
  8587. ///
  8588. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8589. /// "[SkillName] Message"
  8590. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8591. {
  8592. int fd = sd->fd;
  8593. WFIFOHEAD(fd, packet_len(0x7e6));
  8594. WFIFOW(fd,0) = 0x7e6;
  8595. WFIFOW(fd,2) = skill_id;
  8596. WFIFOL(fd,4) = msg_id;
  8597. WFIFOSET(fd, packet_len(0x7e6));
  8598. }
  8599. /// Displays msgstringtable.txt string in a color. (ZC_MSG_COLOR).
  8600. /// 09cd <msg id>.W <color>.L
  8601. void clif_msg_color( struct map_session_data *sd, uint16 msg_id, uint32 color ){
  8602. nullpo_retv(sd);
  8603. int fd = sd->fd;
  8604. WFIFOHEAD(fd, packet_len(0x9cd));
  8605. WFIFOW(fd, 0) = 0x9cd;
  8606. WFIFOW(fd, 2) = msg_id;
  8607. WFIFOL(fd, 4) = color;
  8608. WFIFOSET(fd, packet_len(0x9cd));
  8609. }
  8610. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8611. /// Returns true if the packet was parsed successfully.
  8612. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8613. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8614. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8615. const char* seperator = " : ";
  8616. int fd;
  8617. struct s_packet_db* info;
  8618. uint16 packetLength, inputLength;
  8619. const char *input, *name, *message;
  8620. size_t nameLength, messageLength;
  8621. fd = sd->fd;
  8622. info = &packet_db[RFIFOW(fd,0)];
  8623. packetLength = RFIFOW(fd,info->pos[0]);
  8624. input = RFIFOCP(fd,info->pos[1]);
  8625. // basic structure check for the 4-byte header
  8626. if( packetLength < 4 ){
  8627. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8628. return false;
  8629. }else{
  8630. inputLength = packetLength - 4;
  8631. }
  8632. // process <name> part of the packet
  8633. if( whisperFormat ) {
  8634. // name has fixed width
  8635. if( inputLength < NAME_LENGTH + 1 ) {
  8636. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8637. return false;
  8638. }
  8639. name = input;
  8640. // validate name
  8641. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8642. // only restriction is that the name must be zero-terminated
  8643. if( name[nameLength] != '\0' ) {
  8644. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8645. return false;
  8646. }
  8647. message = input + NAME_LENGTH;
  8648. messageLength = inputLength - NAME_LENGTH;
  8649. }else{
  8650. // name and message are separated by ' : '
  8651. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8652. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8653. // check if there's enough data provided
  8654. if( inputLength < nameLength + seperatorLength + 1 ){
  8655. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8656. return false;
  8657. }
  8658. name = input;
  8659. // validate name
  8660. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8661. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8662. {
  8663. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8664. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8665. set_eof(sd->fd); // Just kick them out to correct it.
  8666. return false;
  8667. }
  8668. message = input + nameLength + seperatorLength;
  8669. messageLength = inputLength - nameLength - seperatorLength;
  8670. }
  8671. #if PACKETVER < 20151001
  8672. // the declared length must match real length
  8673. if( messageLength != strnlen(message, messageLength)+1 ) {
  8674. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8675. return false;
  8676. }
  8677. // verify <message> part of the packet
  8678. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8679. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8680. return false;
  8681. }
  8682. #else
  8683. // No zero termination anymore
  8684. messageLength += 1;
  8685. #endif
  8686. // messages mustn't be too long
  8687. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8688. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8689. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8690. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8691. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8692. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8693. return false;
  8694. }
  8695. // If it is not a whisper message, set the name to the fakename of the player
  8696. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8697. strcpy( out_name, sd->fakename );
  8698. }else{
  8699. safestrncpy( out_name, name, nameLength + 1 );
  8700. }
  8701. safestrncpy( out_message, message, messageLength );
  8702. if( whisperFormat ){
  8703. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8704. out_full_message[nameLength] = '\0';
  8705. }else{
  8706. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8707. }
  8708. if( is_atcommand( fd, sd, out_message, 1 ) )
  8709. return false;
  8710. if (sd->sc.cant.chat)
  8711. return false; //no "chatting" while muted.
  8712. if( battle_config.min_chat_delay ) { //[Skotlex]
  8713. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8714. return false;
  8715. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8716. }
  8717. if (battle_config.idletime_option&IDLE_CHAT)
  8718. sd->idletime = last_tick;
  8719. return true;
  8720. }
  8721. /**
  8722. * Displays a message if the player enters a PK Zone (during pk_mode)
  8723. * @param sd: Player data
  8724. */
  8725. inline void clif_pk_mode_message(struct map_session_data * sd)
  8726. {
  8727. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8728. sd && map_getmapflag(sd->bl.m, MF_PVP)) {
  8729. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8730. char output[CHAT_SIZE_MAX];
  8731. // 1504: You've entered a PK Zone (safe until level %d).
  8732. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8733. battle_config.pk_min_level);
  8734. clif_showscript(&sd->bl, output, SELF);
  8735. } else {
  8736. // 1503: You've entered a PK Zone.
  8737. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8738. }
  8739. }
  8740. return;
  8741. }
  8742. // ---------------------
  8743. // clif_parse_wanttoconnect
  8744. // ---------------------
  8745. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8746. // error codes:
  8747. // 0 - Success
  8748. // 1 - Unknown packet_ver
  8749. // 2 - Invalid account_id
  8750. // 3 - Invalid char_id
  8751. // 4 - Invalid login_id1 (reserved)
  8752. // 5 - Invalid client_tick (reserved)
  8753. // 6 - Invalid sex
  8754. // Only the first 'invalid' error that appears is used.
  8755. static int clif_parse_WantToConnection_sub(int fd)
  8756. {
  8757. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8758. unsigned short cmd;
  8759. //By default, start searching on the default one.
  8760. cmd = RFIFOW(fd, 0);
  8761. packet_len = RFIFOREST(fd);
  8762. // FIXME: If the packet is not received at once, this will FAIL.
  8763. // Figure out, when it happens, that only part of the packet is
  8764. // received, or fix the function to be able to deal with that
  8765. // case.
  8766. if( packet_len != packet_db[cmd].len )
  8767. return 1; /* wrong length */
  8768. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8769. return 2; /* invalid account_id */
  8770. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8771. return 3; /* invalid char_id */
  8772. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8773. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8774. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8775. return 6; /* invalid sex */
  8776. else
  8777. return 0;
  8778. }
  8779. /// Request to connect to map-server.
  8780. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8781. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8782. /// There are various variants of this packet, some of them have padding between fields.
  8783. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8784. {
  8785. struct block_list* bl;
  8786. struct auth_node* node;
  8787. int cmd, account_id, char_id, login_id1, sex, err;
  8788. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8789. if (sd) {
  8790. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8791. return;
  8792. }
  8793. cmd = RFIFOW(fd, 0);
  8794. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8795. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8796. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8797. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8798. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8799. err = clif_parse_WantToConnection_sub(fd);
  8800. if( err ){ // connection rejected
  8801. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8802. err == 1 ? "." :
  8803. err == 2 ? ", possibly for having an invalid account_id." :
  8804. err == 3 ? ", possibly for having an invalid char_id." :
  8805. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8806. err == 4 ? ", possibly for having an invalid login_id1." :
  8807. err == 5 ? ", possibly for having an invalid client_tick." :
  8808. */
  8809. err == 6 ? ", possibly for having an invalid sex." :
  8810. ". ERROR invalid error code"));
  8811. WFIFOHEAD(fd,packet_len(0x6a));
  8812. WFIFOW(fd,0) = 0x6a;
  8813. WFIFOB(fd,2) = err;
  8814. WFIFOSET(fd,packet_len(0x6a));
  8815. #ifdef DUMP_INVALID_PACKET
  8816. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8817. #endif
  8818. RFIFOSKIP(fd, RFIFOREST(fd));
  8819. set_eof(fd);
  8820. return;
  8821. }
  8822. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8823. clif_authfail_fd(fd,1);// server closed
  8824. return;
  8825. }
  8826. //Check for double login.
  8827. bl = map_id2bl(account_id);
  8828. if(bl && bl->type != BL_PC) {
  8829. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8830. WFIFOHEAD(fd,packet_len(0x6a));
  8831. WFIFOW(fd,0) = 0x6a;
  8832. WFIFOB(fd,2) = 3; // Rejected by server
  8833. WFIFOSET(fd,packet_len(0x6a));
  8834. set_eof(fd);
  8835. return;
  8836. }
  8837. if (bl ||
  8838. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8839. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8840. {
  8841. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8842. return;
  8843. }
  8844. CREATE(sd, TBL_PC, 1);
  8845. sd->fd = fd;
  8846. #ifdef PACKET_OBFUSCATION
  8847. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8848. #endif
  8849. session[fd]->session_data = sd;
  8850. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8851. #if PACKETVER < 20070521
  8852. WFIFOHEAD(fd,4);
  8853. WFIFOL(fd,0) = sd->bl.id;
  8854. WFIFOSET(fd,4);
  8855. #else
  8856. WFIFOHEAD(fd,packet_len(0x283));
  8857. WFIFOW(fd,0) = 0x283;
  8858. WFIFOL(fd,2) = sd->bl.id;
  8859. WFIFOSET(fd,packet_len(0x283));
  8860. #endif
  8861. chrif_authreq(sd,false);
  8862. }
  8863. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8864. /// 007d
  8865. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8866. {
  8867. bool guild_notice = false;
  8868. if(sd->bl.prev != NULL)
  8869. return;
  8870. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  8871. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  8872. //Let pc_reg_received or intif_parse_StorageReceived reinvoke this when ready.
  8873. sd->state.connect_new = 0;
  8874. return;
  8875. }
  8876. if (sd->state.rewarp) { //Rewarp player.
  8877. sd->state.rewarp = 0;
  8878. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8879. return;
  8880. }
  8881. sd->state.warping = 0;
  8882. // look
  8883. #if PACKETVER < 4
  8884. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8885. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8886. #else
  8887. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8888. #endif
  8889. pc_set_costume_view(sd);
  8890. if(sd->vd.cloth_color)
  8891. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8892. if(sd->vd.body_style)
  8893. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8894. // item
  8895. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8896. pc_checkitem(sd);
  8897. // cart
  8898. if(pc_iscarton(sd)) {
  8899. clif_cartlist(sd);
  8900. clif_updatestatus(sd,SP_CARTINFO);
  8901. }
  8902. // weight
  8903. clif_updatestatus(sd,SP_WEIGHT);
  8904. clif_updatestatus(sd,SP_MAXWEIGHT);
  8905. // guild
  8906. // (needs to go before clif_spawn() to show guild emblems correctly)
  8907. if(sd->status.guild_id)
  8908. guild_send_memberinfoshort(sd,1);
  8909. if(battle_config.pc_invincible_time > 0) {
  8910. if(map_flag_gvg(sd->bl.m))
  8911. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8912. else
  8913. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8914. }
  8915. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  8916. if( mapdata->users++ == 0 && battle_config.dynamic_mobs )
  8917. map_spawnmobs(sd->bl.m);
  8918. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  8919. mapdata->users_pvp++;
  8920. }
  8921. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8922. // reset the callshop flag if the player changes map
  8923. sd->state.callshop = 0;
  8924. if(map_addblock(&sd->bl))
  8925. return;
  8926. clif_spawn(&sd->bl);
  8927. // Party
  8928. // (needs to go after clif_spawn() to show hp bars correctly)
  8929. if(sd->status.party_id) {
  8930. party_send_movemap(sd);
  8931. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8932. }
  8933. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8934. if(map_getmapflag(sd->bl.m, MF_PVP) && !pc_isinvisible(sd)) {
  8935. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8936. if (!map_getmapflag(sd->bl.m, MF_PVP_NOCALCRANK))
  8937. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8938. sd->pvp_rank = 0;
  8939. sd->pvp_lastusers = 0;
  8940. sd->pvp_point = 5;
  8941. sd->pvp_won = 0;
  8942. sd->pvp_lost = 0;
  8943. }
  8944. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8945. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8946. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8947. else if (map_getmapflag(sd->bl.m, MF_GVG_DUNGEON))
  8948. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  8949. else if( map_flag_gvg(sd->bl.m) )
  8950. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  8951. else
  8952. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  8953. // info about nearby objects
  8954. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8955. 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);
  8956. // pet
  8957. if( sd->pd ) {
  8958. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  8959. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8960. pet_menu(sd, 3); //Option 3 is return to egg.
  8961. } else {
  8962. if(map_addblock(&sd->pd->bl))
  8963. return;
  8964. clif_spawn(&sd->pd->bl);
  8965. clif_send_petdata(sd,sd->pd,0,0);
  8966. clif_send_petstatus(sd);
  8967. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8968. }
  8969. }
  8970. //homunculus [blackhole89]
  8971. if( hom_is_active(sd->hd) ) {
  8972. if(map_addblock(&sd->hd->bl))
  8973. return;
  8974. clif_spawn(&sd->hd->bl);
  8975. clif_send_homdata(sd,SP_ACK,0);
  8976. clif_hominfo(sd,sd->hd,1);
  8977. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8978. clif_homskillinfoblock(sd);
  8979. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  8980. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8981. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8982. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8983. }
  8984. if( sd->md ) {
  8985. if(map_addblock(&sd->md->bl))
  8986. return;
  8987. clif_spawn(&sd->md->bl);
  8988. clif_mercenary_info(sd);
  8989. clif_mercenary_skillblock(sd);
  8990. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8991. }
  8992. if( sd->ed ) {
  8993. if (map_addblock(&sd->ed->bl))
  8994. return;
  8995. clif_spawn(&sd->ed->bl);
  8996. clif_elemental_info(sd);
  8997. clif_elemental_updatestatus(sd,SP_HP);
  8998. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8999. clif_elemental_updatestatus(sd,SP_SP);
  9000. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  9001. }
  9002. if(sd->state.connect_new) {
  9003. int lv;
  9004. guild_notice = true;
  9005. clif_skillinfoblock(sd);
  9006. clif_hotkeys_send(sd);
  9007. clif_updatestatus(sd,SP_BASEEXP);
  9008. clif_updatestatus(sd,SP_NEXTBASEEXP);
  9009. clif_updatestatus(sd,SP_JOBEXP);
  9010. clif_updatestatus(sd,SP_NEXTJOBEXP);
  9011. clif_updatestatus(sd,SP_SKILLPOINT);
  9012. clif_initialstatus(sd);
  9013. if (sd->sc.option&OPTION_FALCON)
  9014. clif_status_load(&sd->bl, EFST_FALCON, 1);
  9015. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  9016. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9017. else if (sd->sc.option&OPTION_WUGRIDER)
  9018. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9019. else if (sd->sc.data[SC_ALL_RIDING])
  9020. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9021. if(sd->status.manner < 0)
  9022. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9023. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9024. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9025. if(sd->bl.m == sd->feel_map[0].m
  9026. || sd->bl.m == sd->feel_map[1].m
  9027. || sd->bl.m == sd->feel_map[2].m)
  9028. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9029. }
  9030. if(sd->pd && sd->pd->pet.intimate > 900)
  9031. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9032. if(hom_is_active(sd->hd))
  9033. hom_init_timers(sd->hd);
  9034. if (night_flag && map_getmapflag(sd->bl.m, MF_NIGHTENABLED)) {
  9035. sd->state.night = 1;
  9036. clif_status_load(&sd->bl, EFST_SKE, 1);
  9037. }
  9038. // Notify everyone that this char logged in [Skotlex].
  9039. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9040. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9041. //Login Event
  9042. npc_script_event(sd, NPCE_LOGIN);
  9043. }
  9044. } else {
  9045. //For some reason the client "loses" these on warp/map-change.
  9046. clif_updatestatus(sd,SP_STR);
  9047. clif_updatestatus(sd,SP_AGI);
  9048. clif_updatestatus(sd,SP_VIT);
  9049. clif_updatestatus(sd,SP_INT);
  9050. clif_updatestatus(sd,SP_DEX);
  9051. clif_updatestatus(sd,SP_LUK);
  9052. // abort currently running script
  9053. sd->state.using_fake_npc = 0;
  9054. sd->state.menu_or_input = 0;
  9055. sd->npc_menu = 0;
  9056. if(sd->npc_id)
  9057. npc_event_dequeue(sd);
  9058. }
  9059. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9060. #if PACKETVER >= 20070918
  9061. clif_partyinvitationstate(sd);
  9062. clif_equipcheckbox(sd);
  9063. #endif
  9064. #if PACKETVER >= 20170920
  9065. if( battle_config.homunculus_autofeed_always ){
  9066. // Always send ON or OFF
  9067. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9068. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9069. }else{
  9070. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9071. }
  9072. }else{
  9073. // Only send when enabled
  9074. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9075. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9076. }
  9077. }
  9078. #endif
  9079. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9080. clif_guild_notice(sd); // Displays after VIP
  9081. guild_notice = false; // Do not display it twice
  9082. }
  9083. if (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) {
  9084. if ((sd->state.pmap != 0 && map_getmapdata(sd->state.pmap) != nullptr && (map_flag_gvg(sd->state.pmap) || map_getmapflag(sd->state.pmap, MF_BATTLEGROUND))) || (mapdata != nullptr && (map_flag_gvg(sd->bl.m) || map_getmapflag(sd->bl.m, MF_BATTLEGROUND))))
  9085. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  9086. }
  9087. if( night_flag && map_getmapflag(sd->bl.m, MF_NIGHTENABLED) )
  9088. { //Display night.
  9089. if( !sd->state.night )
  9090. {
  9091. sd->state.night = 1;
  9092. clif_status_load(&sd->bl, EFST_SKE, 1);
  9093. }
  9094. }
  9095. else if( sd->state.night )
  9096. { //Clear night display.
  9097. sd->state.night = 0;
  9098. clif_status_load(&sd->bl, EFST_SKE, 0);
  9099. }
  9100. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) )
  9101. {
  9102. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9103. if( map_getmapflag(sd->bl.m, MF_BATTLEGROUND) == 2 )
  9104. clif_bg_updatescore_single(sd);
  9105. }
  9106. if( map_getmapflag(sd->bl.m, MF_ALLOWKS) && !map_flag_ks(sd->bl.m) )
  9107. {
  9108. char output[128];
  9109. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9110. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9111. }
  9112. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9113. mapdata->hpmeter_visible++;
  9114. sd->state.hpmeter_visible = 1;
  9115. }
  9116. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9117. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9118. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9119. #ifdef VIP_ENABLE
  9120. if (!sd->state.connect_new &&
  9121. !sd->vip.disableshowrate &&
  9122. sd->state.pmap != sd->bl.m &&
  9123. map_getmapflag(sd->state.pmap, MF_BEXP) != map_getmapflag(sd->bl.m, MF_BEXP)
  9124. )
  9125. {
  9126. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  9127. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  9128. }
  9129. #endif
  9130. // Instances do not need their own channels
  9131. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !map_getmapflag(sd->bl.m,MF_NOMAPCHANNELAUTOJOIN) && !mapdata->instance_id )
  9132. channel_mjoin(sd); //join new map
  9133. clif_pk_mode_message(sd);
  9134. }
  9135. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9136. clif_guild_notice(sd); // Displays at end
  9137. }
  9138. mail_clear(sd);
  9139. /* Guild Aura Init */
  9140. if( sd->state.gmaster_flag ) {
  9141. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9142. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9143. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9144. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9145. }
  9146. if( sd->state.vending ) { /* show we have a vending */
  9147. clif_openvending(sd,sd->bl.id,sd->vending);
  9148. clif_showvendingboard(&sd->bl,sd->message,0);
  9149. }
  9150. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9151. if(!sd->state.autotrade && map_getmapflag(sd->bl.m, MF_LOADEVENT)) // Lance
  9152. npc_script_event(sd, NPCE_LOADMAP);
  9153. if (pc_checkskill(sd, SG_DEVIL) && pc_is_maxjoblv(sd))
  9154. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9155. if (sd->sc.opt2) //Client loses these on warp.
  9156. clif_changeoption(&sd->bl);
  9157. 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)) {
  9158. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  9159. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM, INVALID_TIMER);
  9160. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9161. }
  9162. clif_weather_check(sd);
  9163. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9164. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9165. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9166. else
  9167. sd->areanpc_id = 0;
  9168. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9169. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9170. pc_setdead(sd);
  9171. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9172. if(pc_isdead(sd))
  9173. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9174. else {
  9175. skill_usave_trigger(sd);
  9176. if (battle_config.spawn_direction)
  9177. clif_changed_dir(&sd->bl, SELF);
  9178. }
  9179. // Trigger skill effects if you appear standing on them
  9180. if(!battle_config.pc_invincible_time)
  9181. skill_unit_move(&sd->bl,gettick(),1);
  9182. pc_show_questinfo_reinit(sd);
  9183. pc_show_questinfo(sd);
  9184. #if PACKETVER >= 20150513
  9185. if( sd->mail.inbox.unread ){
  9186. clif_Mail_new(sd, 0, NULL, NULL);
  9187. }
  9188. #endif
  9189. sd->state.connect_new = 0;
  9190. sd->state.changemap = false;
  9191. }
  9192. /// Server's tick (ZC_NOTIFY_TIME).
  9193. /// 007f <time>.L
  9194. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  9195. {
  9196. int fd = sd->fd;
  9197. WFIFOHEAD(fd,packet_len(0x7f));
  9198. WFIFOW(fd,0) = 0x7f;
  9199. WFIFOL(fd,2) = time;
  9200. WFIFOSET(fd,packet_len(0x7f));
  9201. }
  9202. /// Request for server's tick.
  9203. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9204. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9205. /// There are various variants of this packet, some of them have padding between fields.
  9206. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9207. {
  9208. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9209. clif_notify_time(sd, gettick());
  9210. }
  9211. /// Sends hotkey bar.
  9212. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9213. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9214. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9215. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9216. void clif_hotkeys_send(struct map_session_data *sd) {
  9217. #ifdef HOTKEY_SAVING
  9218. const int fd = sd->fd;
  9219. int i;
  9220. int offset = 2;
  9221. #if PACKETVER < 20090603
  9222. const int cmd = 0x2b9;
  9223. #elif PACKETVER < 20141022
  9224. const int cmd = 0x7d9;
  9225. #else
  9226. char Rotate = sd->status.hotkey_rowshift;
  9227. const int cmd = 0xa00;
  9228. offset = 3;
  9229. #endif
  9230. if (!fd) return;
  9231. WFIFOHEAD(fd, offset + MAX_HOTKEYS * 7);
  9232. WFIFOW(fd, 0) = cmd;
  9233. #if PACKETVER >= 20141022
  9234. WFIFOB(fd, 2) = Rotate;
  9235. #endif
  9236. for(i = 0; i < MAX_HOTKEYS; i++) {
  9237. WFIFOB(fd, offset + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  9238. WFIFOL(fd, offset + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  9239. WFIFOW(fd, offset + 5 + i * 7) = sd->status.hotkeys[i].lv; // item qty or skill level
  9240. }
  9241. WFIFOSET(fd, packet_len(cmd));
  9242. #endif
  9243. }
  9244. /// Request to update a position on the hotkey row bar
  9245. void clif_parse_HotkeyRowShift(int fd, struct map_session_data *sd) {
  9246. int cmd = RFIFOW(fd, 0);
  9247. sd->status.hotkey_rowshift = RFIFOB(fd, packet_db[cmd].pos[0]);
  9248. }
  9249. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9250. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9251. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9252. #ifdef HOTKEY_SAVING
  9253. unsigned short idx;
  9254. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9255. idx = RFIFOW(fd, info->pos[0]);
  9256. if (idx >= MAX_HOTKEYS) return;
  9257. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  9258. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  9259. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  9260. #endif
  9261. }
  9262. /// Displays cast-like progress bar (ZC_PROGRESS).
  9263. /// 02f0 <color>.L <time>.L
  9264. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9265. {
  9266. int fd = sd->fd;
  9267. WFIFOHEAD(fd,packet_len(0x2f0));
  9268. WFIFOW(fd,0) = 0x2f0;
  9269. WFIFOL(fd,2) = color;
  9270. WFIFOL(fd,6) = second;
  9271. WFIFOSET(fd,packet_len(0x2f0));
  9272. }
  9273. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9274. /// 02f2
  9275. void clif_progressbar_abort(struct map_session_data * sd)
  9276. {
  9277. int fd = sd->fd;
  9278. WFIFOHEAD(fd,packet_len(0x2f2));
  9279. WFIFOW(fd,0) = 0x2f2;
  9280. WFIFOSET(fd,packet_len(0x2f2));
  9281. }
  9282. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  9283. /// 02f1
  9284. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  9285. {
  9286. int npc_id = sd->progressbar.npc_id;
  9287. if( gettick() < sd->progressbar.timeout && sd->st )
  9288. sd->st->state = END;
  9289. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  9290. sd->state.workinprogress = WIP_DISABLE_NONE;
  9291. npc_scriptcont(sd, npc_id, false);
  9292. }
  9293. /// Displays cast-like progress bar on a NPC
  9294. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9295. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9296. #if PACKETVER >= 20130821
  9297. unsigned char buf[14];
  9298. if( nd->progressbar.timeout > 0 ){
  9299. WBUFW(buf,0) = 0x9d1;
  9300. WBUFL(buf,2) = nd->bl.id;
  9301. WBUFL(buf,6) = nd->progressbar.color;
  9302. WBUFL(buf,10) = ( nd->progressbar.timeout - gettick() ) / 1000;
  9303. if( sd ){
  9304. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9305. }else{
  9306. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9307. }
  9308. }
  9309. #endif
  9310. }
  9311. /// Request to walk to a certain position on the current map.
  9312. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9313. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9314. /// There are various variants of this packet, some of them have padding between fields.
  9315. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9316. {
  9317. short x, y;
  9318. if (pc_isdead(sd)) {
  9319. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9320. return;
  9321. }
  9322. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9323. ; //You CAN walk on this OPT1 value.
  9324. else if (sd->progressbar.npc_id) {
  9325. clif_progressbar_abort(sd);
  9326. return; // First walk attempt cancels the progress bar
  9327. } else if (pc_cant_act(sd))
  9328. return;
  9329. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9330. return;
  9331. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9332. //A move command one cell west is only valid if the target cell is free
  9333. if(battle_config.official_cell_stack_limit > 0
  9334. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9335. return;
  9336. // Cloaking wall check is actually updated when you click to process next movement
  9337. // not when you move each cell. This is official behaviour.
  9338. if (sd->sc.data[SC_CLOAKING])
  9339. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9340. status_change_end(&sd->bl, SC_ROLLINGCUTTER, INVALID_TIMER); // If you move, you lose your counters. [malufett]
  9341. pc_delinvincibletimer(sd);
  9342. //Set last idle time... [Skotlex]
  9343. if (battle_config.idletime_option&IDLE_WALK)
  9344. sd->idletime = last_tick;
  9345. unit_walktoxy(&sd->bl, x, y, 4);
  9346. }
  9347. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9348. /// 018b <result>.W
  9349. /// result:
  9350. /// 0 = disconnect (quit)
  9351. /// 1 = cannot disconnect (wait 10 seconds)
  9352. /// ? = ignored
  9353. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9354. {
  9355. int fd = sd->fd;
  9356. WFIFOHEAD(fd,packet_len(0x18b));
  9357. WFIFOW(fd,0) = 0x18b;
  9358. WFIFOW(fd,2) = result;
  9359. WFIFOSET(fd,packet_len(0x18b));
  9360. }
  9361. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9362. /// 018a <type>.W
  9363. /// type:
  9364. /// 0 = quit
  9365. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9366. {
  9367. /* Rovert's prevent logout option fixed [Valaris] */
  9368. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9369. 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] &&
  9370. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9371. {
  9372. set_eof(fd);
  9373. pc_damage_log_clear(sd,0);
  9374. clif_disconnect_ack(sd, 0);
  9375. } else {
  9376. clif_disconnect_ack(sd, 1);
  9377. }
  9378. }
  9379. /// Requesting unit's name.
  9380. /// 0094 <id>.L (CZ_REQNAME)
  9381. /// 0368 <id>.L (CZ_REQNAME2)
  9382. /// There are various variants of this packet, some of them have padding between fields.
  9383. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9384. {
  9385. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9386. struct block_list* bl;
  9387. //struct status_change *sc;
  9388. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9389. id = sd->bl.id;
  9390. bl = map_id2bl(id);
  9391. if( bl == NULL )
  9392. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9393. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9394. return; // Block namerequests past view range
  9395. // 'see people in GM hide' cheat detection
  9396. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9397. sc = status_get_sc(bl);
  9398. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9399. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9400. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9401. ) {
  9402. char gm_msg[256];
  9403. 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);
  9404. ShowWarning(gm_msg);
  9405. // information is sent to all online GMs
  9406. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9407. return;
  9408. }
  9409. */
  9410. clif_name(&sd->bl,bl,SELF);
  9411. }
  9412. /// Validates and processes global messages
  9413. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9414. /// There are various variants of this packet.
  9415. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9416. {
  9417. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9418. size_t length;
  9419. // validate packet and retrieve name and message
  9420. if( !clif_process_message(sd, false, name, message, output ) )
  9421. return;
  9422. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9423. channel_send(sd->gcbind,sd,message);
  9424. return;
  9425. }
  9426. // send message to others (using the send buffer for temp. storage)
  9427. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9428. length = strlen(output) + 1;
  9429. // send back message to the speaker
  9430. WFIFOHEAD(fd,4+length);
  9431. WFIFOW(fd,0) = 0x8e;
  9432. WFIFOW(fd,2) = (uint16)(4+length);
  9433. safestrncpy(WFIFOCP(fd,4), output, length );
  9434. WFIFOSET(fd, WFIFOW(fd,2));
  9435. #ifdef PCRE_SUPPORT
  9436. // trigger listening npcs
  9437. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9438. #endif
  9439. // Chat logging type 'O' / Global Chat
  9440. 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);
  9441. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9442. }
  9443. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9444. /// Request to warp to a map on given coordinates.
  9445. /// 0140 <map name>.16B <x>.W <y>.W
  9446. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9447. {
  9448. char command[MAP_NAME_LENGTH_EXT+25];
  9449. char* map_name;
  9450. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9451. map_name = RFIFOCP(fd,info->pos[0]);
  9452. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9453. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9454. RFIFOW(fd,info->pos[1]), //x
  9455. RFIFOW(fd,info->pos[2])); //y
  9456. is_atcommand(fd, sd, command, 1);
  9457. }
  9458. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9459. /// 009c <id>.L <head dir>.W <dir>.B
  9460. /// head dir:
  9461. /// 0 = straight
  9462. /// 1 = turned CW
  9463. /// 2 = turned CCW
  9464. /// dir:
  9465. /// 0 = north
  9466. /// 1 = northwest
  9467. /// 2 = west
  9468. /// 3 = southwest
  9469. /// 4 = south
  9470. /// 5 = southeast
  9471. /// 6 = east
  9472. /// 7 = northeast
  9473. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9474. {
  9475. unsigned char buf[64];
  9476. WBUFW(buf,0) = 0x9c;
  9477. WBUFL(buf,2) = bl->id;
  9478. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9479. WBUFB(buf,8) = unit_getdir(bl);
  9480. clif_send(buf, packet_len(0x9c), bl, target);
  9481. if (disguised(bl)) {
  9482. WBUFL(buf,2) = -bl->id;
  9483. WBUFW(buf,6) = 0;
  9484. clif_send(buf, packet_len(0x9c), bl, SELF);
  9485. }
  9486. }
  9487. /// Request to change own body and head direction.
  9488. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9489. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9490. /// There are various variants of this packet, some of them have padding between fields.
  9491. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9492. {
  9493. unsigned char headdir, dir;
  9494. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9495. headdir = RFIFOB(fd,info->pos[0]);
  9496. dir = RFIFOB(fd,info->pos[1]);
  9497. pc_setdir(sd, dir, headdir);
  9498. clif_changed_dir(&sd->bl, AREA_WOS);
  9499. }
  9500. /// Request to show an emotion (CZ_REQ_EMOTION).
  9501. /// 00bf <type>.B
  9502. /// type:
  9503. /// @see enum emotion_type
  9504. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9505. {
  9506. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9507. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9508. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9509. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9510. return;
  9511. }
  9512. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9513. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9514. sd->emotionlasttime = time(NULL);
  9515. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9516. return;
  9517. }
  9518. sd->emotionlasttime = time(NULL);
  9519. if (battle_config.idletime_option&IDLE_EMOTION)
  9520. sd->idletime = last_tick;
  9521. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9522. emoticon = rnd()%6+ET_DICE1;
  9523. }
  9524. clif_emotion(&sd->bl, emoticon);
  9525. } else
  9526. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9527. }
  9528. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9529. /// 00c2 <count>.L
  9530. void clif_user_count(struct map_session_data* sd, int count)
  9531. {
  9532. int fd = sd->fd;
  9533. WFIFOHEAD(fd,packet_len(0xc2));
  9534. WFIFOW(fd,0) = 0xc2;
  9535. WFIFOL(fd,2) = count;
  9536. WFIFOSET(fd,packet_len(0xc2));
  9537. }
  9538. /// /w /who (CZ_REQ_USER_COUNT).
  9539. /// Request to display amount of currently connected players.
  9540. /// 00c1
  9541. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9542. {
  9543. clif_user_count(sd, map_getusers());
  9544. }
  9545. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  9546. {
  9547. if (pc_isdead(sd)) {
  9548. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9549. return;
  9550. }
  9551. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9552. // (not all are included in pc_can_attack)
  9553. if (sd->sc.count &&
  9554. (sd->sc.data[SC_TRICKDEAD] ||
  9555. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9556. sd->sc.data[SC_BLADESTOP] ||
  9557. sd->sc.data[SC__MANHOLE] ||
  9558. sd->sc.data[SC_SUHIDE] ))
  9559. return;
  9560. if(action_type != 0x00 && action_type != 0x07)
  9561. pc_stop_walking(sd, 1);
  9562. pc_stop_attack(sd);
  9563. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9564. target_id = sd->bl.id;
  9565. switch(action_type)
  9566. {
  9567. case 0x00: // once attack
  9568. case 0x07: // continuous attack
  9569. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9570. return;
  9571. if( sd->sc.option&OPTION_COSTUME )
  9572. return;
  9573. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9574. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9575. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9576. return;
  9577. }
  9578. }
  9579. pc_delinvincibletimer(sd);
  9580. if (battle_config.idletime_option&IDLE_ATTACK)
  9581. sd->idletime = last_tick;
  9582. unit_attack(&sd->bl, target_id, action_type != 0);
  9583. break;
  9584. case 0x02: // sitdown
  9585. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9586. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9587. break;
  9588. }
  9589. if(pc_issit(sd)) {
  9590. //Bugged client? Just refresh them.
  9591. clif_sitting(&sd->bl);
  9592. return;
  9593. }
  9594. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9595. break;
  9596. if (sd->sc.count && (
  9597. sd->sc.data[SC_DANCING] ||
  9598. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9599. )) //No sitting during these states either.
  9600. break;
  9601. if (battle_config.idletime_option&IDLE_SIT)
  9602. sd->idletime = last_tick;
  9603. pc_setsit(sd);
  9604. skill_sit(sd, 1);
  9605. clif_sitting(&sd->bl);
  9606. break;
  9607. case 0x03: // standup
  9608. if (!pc_issit(sd)) {
  9609. //Bugged client? Just refresh them.
  9610. clif_standing(&sd->bl);
  9611. return;
  9612. }
  9613. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9614. break;
  9615. if (pc_setstand(sd, false)) {
  9616. if (battle_config.idletime_option&IDLE_SIT)
  9617. sd->idletime = last_tick;
  9618. skill_sit(sd, 0);
  9619. clif_standing(&sd->bl);
  9620. }
  9621. break;
  9622. }
  9623. }
  9624. /// Request for an action.
  9625. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9626. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9627. /// action:
  9628. /// 0 = attack
  9629. /// 1 = pick up item
  9630. /// 2 = sit down
  9631. /// 3 = stand up
  9632. /// 7 = continous attack
  9633. /// 12 = (touch skill?)
  9634. /// There are various variants of this packet, some of them have padding between fields.
  9635. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9636. {
  9637. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9638. clif_parse_ActionRequest_sub(sd,
  9639. RFIFOB(fd,info->pos[1]),
  9640. RFIFOL(fd,info->pos[0]),
  9641. gettick()
  9642. );
  9643. }
  9644. /// Response to the death/system menu (CZ_RESTART).
  9645. /// 00b2 <type>.B
  9646. /// type:
  9647. /// 0 = restart (respawn)
  9648. /// 1 = char-select (disconnect)
  9649. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9650. {
  9651. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9652. case 0x00:
  9653. pc_respawn(sd,CLR_OUTSIGHT);
  9654. break;
  9655. case 0x01:
  9656. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9657. 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] &&
  9658. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9659. { //Send to char-server for character selection.
  9660. pc_damage_log_clear(sd,0);
  9661. chrif_charselectreq(sd, session[fd]->client_addr);
  9662. } else {
  9663. clif_disconnect_ack(sd, 1);
  9664. }
  9665. break;
  9666. }
  9667. }
  9668. /// Validates and processes whispered messages (CZ_WHISPER).
  9669. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9670. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9671. {
  9672. struct map_session_data* dstsd;
  9673. int i;
  9674. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9675. // validate packet and retrieve name and message
  9676. if( !clif_process_message( sd, true, target, message, output ) )
  9677. return;
  9678. // Chat logging type 'W' / Whisper
  9679. 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);
  9680. //-------------------------------------------------------//
  9681. // Lordalfa - Paperboy - To whisper NPC commands //
  9682. //-------------------------------------------------------//
  9683. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9684. {
  9685. char* str = target+4; //Skip the NPC: string part.
  9686. struct npc_data* npc;
  9687. if ((npc = npc_name2id(str))) {
  9688. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9689. char *split;
  9690. char event[EVENT_NAME_LENGTH];
  9691. str = message;
  9692. // skip codepage indicator, if detected
  9693. if( str[0] == '|' && strlen(str) >= 4 )
  9694. str += 3;
  9695. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9696. split = strchr(str,'#');
  9697. if( split == NULL ) { // use the remaining string
  9698. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9699. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9700. split_data[i][0] = '\0';
  9701. break;
  9702. }
  9703. *split = '\0';
  9704. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9705. str = split+1;
  9706. }
  9707. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9708. char variablename[CHAT_SIZE_MAX];
  9709. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9710. set_var(sd,variablename,(char *) split_data[i]);
  9711. }
  9712. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9713. npc_event(sd,event,0); // Calls the NPC label
  9714. return;
  9715. }
  9716. } else if( target[0] == '#' ) {
  9717. struct Channel *channel = NULL;
  9718. char* chname = target;
  9719. channel = channel_name2channel(chname,sd,3);
  9720. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9721. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9722. channel_send(channel,sd,message);
  9723. }
  9724. else if( channel->pass[0] == '\0') { //no pass needed
  9725. if (channel_join(channel,sd)==0)
  9726. channel_send(channel,sd,message); //join success
  9727. }
  9728. else {
  9729. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9730. }
  9731. return;
  9732. }
  9733. }
  9734. // searching destination character
  9735. dstsd = map_nick2sd(target,false);
  9736. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9737. // player is not on this map-server
  9738. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9739. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9740. // and if we ask for 'Test', we must not contact 'test' player
  9741. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9742. intif_wis_message(sd, target, message, strlen(message) + 1);
  9743. return;
  9744. }
  9745. // if player ignores everyone
  9746. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9747. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9748. clif_wis_end(fd, 1); // 1: target character is not logged in
  9749. else
  9750. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9751. return;
  9752. }
  9753. // if player is autotrading
  9754. if (dstsd->state.autotrade == 1){
  9755. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9756. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  9757. return;
  9758. }
  9759. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9760. // if player ignores the source character
  9761. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9762. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9763. clif_wis_end(fd, 2); // 2: ignored by target
  9764. return;
  9765. }
  9766. }
  9767. // notify sender of success
  9768. clif_wis_end(fd, 0); // 0: success to send wisper
  9769. // Normal message
  9770. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  9771. }
  9772. /// /b /nb (CZ_BROADCAST).
  9773. /// Request to broadcast a message on whole server.
  9774. /// 0099 <packet len>.W <text>.?B 00
  9775. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9776. char command[CHAT_SIZE_MAX+11];
  9777. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9778. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9779. char* msg = RFIFOCP(fd,info->pos[1]);
  9780. // as the length varies depending on the command used, just block unreasonably long strings
  9781. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9782. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9783. is_atcommand(fd, sd, command, 1);
  9784. }
  9785. /// Request to pick up an item.
  9786. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9787. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9788. /// There are various variants of this packet, some of them have padding between fields.
  9789. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9790. {
  9791. struct flooritem_data *fitem;
  9792. int map_object_id;
  9793. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9794. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9795. do {
  9796. if (pc_isdead(sd)) {
  9797. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9798. break;
  9799. }
  9800. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9801. break;
  9802. if (pc_cant_act(sd))
  9803. break;
  9804. if (!pc_takeitem(sd, fitem))
  9805. break;
  9806. return;
  9807. } while (0);
  9808. // Client REQUIRES a fail packet or you can no longer pick items.
  9809. clif_additem(sd,0,0,6);
  9810. }
  9811. /// Request to drop an item.
  9812. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9813. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9814. /// There are various variants of this packet, some of them have padding between fields.
  9815. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9816. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9817. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9818. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9819. for(;;) {
  9820. if (pc_isdead(sd))
  9821. break;
  9822. if (pc_cant_act2(sd) || sd->npc_id)
  9823. break;
  9824. if (sd->sc.count && (
  9825. sd->sc.data[SC_AUTOCOUNTER] ||
  9826. sd->sc.data[SC_BLADESTOP] ||
  9827. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9828. ))
  9829. break;
  9830. if (!pc_dropitem(sd, item_index, item_amount))
  9831. break;
  9832. if (battle_config.idletime_option&IDLE_DROPITEM)
  9833. sd->idletime = last_tick;
  9834. return;
  9835. }
  9836. //Because the client does not like being ignored.
  9837. clif_dropitem(sd, item_index,0);
  9838. }
  9839. /// Request to use an item.
  9840. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9841. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9842. /// There are various variants of this packet, some of them have padding between fields.
  9843. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9844. {
  9845. int n;
  9846. if (pc_isdead(sd)) {
  9847. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9848. return;
  9849. }
  9850. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9851. return;
  9852. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9853. if (battle_config.idletime_option&IDLE_USEITEM)
  9854. sd->idletime = last_tick;
  9855. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9856. if(n <0 || n >= MAX_INVENTORY)
  9857. return;
  9858. if (!pc_useitem(sd,n))
  9859. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9860. }
  9861. /// Request to equip an item
  9862. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9863. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9864. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9865. {
  9866. int index;
  9867. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9868. if(pc_isdead(sd)) {
  9869. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9870. return;
  9871. }
  9872. index = RFIFOW(fd,info->pos[0])-2;
  9873. if (index < 0 || index >= MAX_INVENTORY)
  9874. return; //Out of bounds check.
  9875. if(sd->npc_id && !sd->npc_item_flag) {
  9876. return;
  9877. } else if (sd->state.storage_flag || sd->sc.opt1)
  9878. ; //You can equip/unequip stuff while storage is open/under status changes
  9879. else if (pc_cant_act2(sd))
  9880. return;
  9881. if(!sd->inventory.u.items_inventory[index].identify) {
  9882. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9883. return;
  9884. }
  9885. if(!sd->inventory_data[index])
  9886. return;
  9887. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9888. pet_equipitem(sd,index);
  9889. return;
  9890. }
  9891. if (battle_config.idletime_option&IDLE_USEITEM)
  9892. sd->idletime = last_tick;
  9893. //Client doesn't send the position for ammo.
  9894. if(sd->inventory_data[index]->type == IT_AMMO)
  9895. pc_equipitem(sd,index,EQP_AMMO);
  9896. else {
  9897. int req_pos;
  9898. #if PACKETVER >= 20120925
  9899. req_pos = RFIFOL(fd,info->pos[1]);
  9900. #else
  9901. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9902. #endif
  9903. pc_equipitem(sd,index,req_pos);
  9904. }
  9905. }
  9906. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9907. /// 00ab <index>.W
  9908. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9909. {
  9910. int index;
  9911. if(pc_isdead(sd)) {
  9912. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9913. return;
  9914. }
  9915. if (sd->npc_id && !sd->npc_item_flag) {
  9916. return;
  9917. } else if (sd->state.storage_flag || sd->sc.opt1)
  9918. ; //You can equip/unequip stuff while storage is open/under status changes
  9919. else if (pc_cant_act2(sd))
  9920. return;
  9921. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9922. if (battle_config.idletime_option&IDLE_USEITEM)
  9923. sd->idletime = last_tick;
  9924. pc_unequipitem(sd,index,1);
  9925. }
  9926. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9927. /// 0090 <id>.L <type>.B
  9928. /// type:
  9929. /// 1 = click
  9930. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9931. {
  9932. struct block_list *bl;
  9933. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9934. if(pc_isdead(sd)) {
  9935. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9936. return;
  9937. }
  9938. if( pc_cant_act2(sd) || sd->npc_id || pc_hasprogress( sd, WIP_DISABLE_NPC ) ){
  9939. #ifdef RENEWAL
  9940. clif_msg( sd, WORK_IN_PROGRESS );
  9941. #endif
  9942. return;
  9943. }
  9944. if( sd->state.mail_writing )
  9945. return;
  9946. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9947. //type = RFIFOB(fd,info->pos[1]);
  9948. if (!bl) return;
  9949. switch (bl->type) {
  9950. case BL_MOB:
  9951. case BL_PC:
  9952. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9953. break;
  9954. case BL_NPC:
  9955. #ifdef RENEWAL
  9956. 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
  9957. clif_msg(sd, WORK_IN_PROGRESS);
  9958. break;
  9959. }
  9960. #endif
  9961. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  9962. struct npc_data* nd = (struct npc_data*)bl;
  9963. // Progressbar is running
  9964. if( nd->progressbar.timeout > 0 ){
  9965. return;
  9966. }
  9967. npc_click(sd,nd);
  9968. }
  9969. break;
  9970. }
  9971. }
  9972. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9973. /// 00c5 <id>.L <type>.B
  9974. /// type:
  9975. /// 0 = buy
  9976. /// 1 = sell
  9977. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9978. {
  9979. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9980. if (sd->state.trading)
  9981. return;
  9982. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9983. }
  9984. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9985. /// 00ca <result>.B
  9986. /// result:
  9987. /// 0 = "The deal has successfully completed."
  9988. /// 1 = "You do not have enough zeny."
  9989. /// 2 = "You are over your Weight Limit."
  9990. /// 3 = "Out of the maximum capacity, you have too many items."
  9991. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  9992. {
  9993. int fd = sd->fd;
  9994. WFIFOHEAD(fd,packet_len(0xca));
  9995. WFIFOW(fd,0) = 0xca;
  9996. WFIFOB(fd,2) = result;
  9997. WFIFOSET(fd,packet_len(0xca));
  9998. }
  9999. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  10000. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  10001. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  10002. {
  10003. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10004. uint16 n = (RFIFOW(fd,info->pos[0])-4) /4;
  10005. int result;
  10006. if( sd->state.trading || !sd->npc_shopid )
  10007. result = 1;
  10008. else
  10009. result = npc_buylist(sd, n, (struct s_npc_buy_list*)RFIFOP(fd,info->pos[1]));
  10010. sd->npc_shopid = 0; //Clear shop data.
  10011. clif_npc_buy_result(sd, result);
  10012. }
  10013. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  10014. /// 00cb <result>.B
  10015. /// result:
  10016. /// 0 = "The deal has successfully completed."
  10017. /// 1 = "The deal has failed."
  10018. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  10019. {
  10020. int fd = sd->fd;
  10021. WFIFOHEAD(fd,packet_len(0xcb));
  10022. WFIFOW(fd,0) = 0xcb;
  10023. WFIFOB(fd,2) = result;
  10024. WFIFOSET(fd,packet_len(0xcb));
  10025. }
  10026. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10027. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10028. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  10029. {
  10030. int fail=0,n;
  10031. unsigned short *item_list;
  10032. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10033. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  10034. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  10035. if (sd->state.trading || !sd->npc_shopid)
  10036. fail = 1;
  10037. else
  10038. fail = npc_selllist(sd,n,item_list);
  10039. sd->npc_shopid = 0; //Clear shop data.
  10040. clif_npc_sell_result(sd, fail);
  10041. }
  10042. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10043. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10044. /// type:
  10045. /// 0 = private
  10046. /// 1 = public
  10047. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  10048. {
  10049. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10050. int len = RFIFOW(fd,info->pos[0])-15;
  10051. int limit = RFIFOW(fd,info->pos[1]);
  10052. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10053. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10054. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10055. char s_password[CHATROOM_PASS_SIZE];
  10056. char s_title[CHATROOM_TITLE_SIZE];
  10057. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  10058. return;
  10059. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10060. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10061. return;
  10062. }
  10063. if( npc_isnear(&sd->bl) ) {
  10064. // uncomment to send msg_txt.
  10065. //char output[150];
  10066. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10067. //clif_displaymessage(sd->fd, output);
  10068. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10069. return;
  10070. }
  10071. if( len <= 0 )
  10072. return; // invalid input
  10073. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10074. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10075. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10076. }
  10077. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10078. /// 00d9 <chat ID>.L <passwd>.8B
  10079. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10080. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10081. int chatid = RFIFOL(fd,info->pos[0]);
  10082. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10083. chat_joinchat(sd,chatid,password);
  10084. }
  10085. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10086. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10087. /// type:
  10088. /// 0 = private
  10089. /// 1 = public
  10090. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  10091. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10092. int len = RFIFOW(fd,info->pos[0])-15;
  10093. int limit = RFIFOW(fd,info->pos[1]);
  10094. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10095. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10096. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10097. char s_password[CHATROOM_PASS_SIZE];
  10098. char s_title[CHATROOM_TITLE_SIZE];
  10099. if( len <= 0 )
  10100. return; // invalid input
  10101. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10102. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10103. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10104. }
  10105. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10106. /// 00e0 <role>.L <nick>.24B
  10107. /// role:
  10108. /// 0 = owner
  10109. /// 1 = normal
  10110. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10111. {
  10112. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10113. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10114. }
  10115. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10116. /// 00e2 <name>.24B
  10117. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10118. {
  10119. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10120. }
  10121. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10122. /// 00e3
  10123. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10124. {
  10125. chat_leavechat(sd,0);
  10126. }
  10127. //Handles notifying asker and rejecter of what has just ocurred.
  10128. //Type is used to determine the correct msg_txt to use:
  10129. //0:
  10130. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10131. {
  10132. const char* msg;
  10133. char output[256];
  10134. // Your request has been rejected by autoreject option.
  10135. msg = msg_txt(sd,392);
  10136. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10137. //Notice that a request was rejected.
  10138. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10139. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10140. }
  10141. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10142. /// 00e4 <account id>.L
  10143. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10144. {
  10145. struct map_session_data *t_sd;
  10146. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10147. if(!sd->chatID && pc_cant_act(sd))
  10148. return; //You can trade while in a chatroom.
  10149. if(t_sd){
  10150. // @noask [LuzZza]
  10151. if(t_sd->state.noask) {
  10152. clif_noask_sub(sd, t_sd, 0);
  10153. return;
  10154. }
  10155. if (t_sd->state.mail_writing) {
  10156. int old = sd->trade_partner;
  10157. // Fake trading
  10158. sd->trade_partner = t_sd->status.account_id;
  10159. clif_tradestart(sd, 5);
  10160. // Restore old state
  10161. sd->trade_partner = old;
  10162. return;
  10163. }
  10164. }
  10165. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10166. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10167. return;
  10168. }
  10169. trade_traderequest(sd,t_sd);
  10170. }
  10171. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10172. /// 00e6 <result>.B
  10173. /// result:
  10174. /// 3 = accepted
  10175. /// 4 = rejected
  10176. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10177. {
  10178. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10179. }
  10180. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10181. /// 00e8 <index>.W <amount>.L
  10182. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10183. {
  10184. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10185. short index = RFIFOW(fd,info->pos[0]);
  10186. int amount = RFIFOL(fd,info->pos[1]);
  10187. if( index == 0 )
  10188. trade_tradeaddzeny(sd, amount);
  10189. else
  10190. trade_tradeadditem(sd, index, (short)amount);
  10191. }
  10192. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10193. /// 00eb
  10194. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10195. {
  10196. trade_tradeok(sd);
  10197. }
  10198. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10199. /// 00ed
  10200. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10201. {
  10202. trade_tradecancel(sd);
  10203. }
  10204. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10205. /// 00ef
  10206. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10207. {
  10208. trade_tradecommit(sd);
  10209. }
  10210. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10211. /// 0118
  10212. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10213. {
  10214. pc_stop_attack(sd);
  10215. if (sd) sd->ud.state.attack_continue = 0;
  10216. }
  10217. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10218. /// 0126 <index>.W <amount>.L
  10219. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  10220. {
  10221. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10222. if (pc_istrading(sd))
  10223. return;
  10224. if (!pc_iscarton(sd))
  10225. return;
  10226. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10227. }
  10228. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10229. /// 0127 <index>.W <amount>.L
  10230. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10231. {
  10232. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10233. if (!pc_iscarton(sd))
  10234. return;
  10235. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10236. }
  10237. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10238. /// 012a
  10239. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10240. {
  10241. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10242. #ifdef NEW_CARTS
  10243. && sd->sc.data[SC_PUSH_CART] )
  10244. pc_setcart(sd,0);
  10245. #else
  10246. )
  10247. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10248. #endif
  10249. else // priority to remove this option before we can clear cart
  10250. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10251. }
  10252. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10253. /// 097f <Length>.W <identity>.L <type>.B
  10254. void clif_SelectCart(struct map_session_data *sd) {
  10255. #if PACKETVER >= 20150826
  10256. int i = 0, carts = 3;
  10257. int fd = sd->fd;
  10258. WFIFOHEAD(fd,8 + carts);
  10259. WFIFOW(fd,0) = 0x97f;
  10260. WFIFOW(fd,2) = 8 + carts;
  10261. WFIFOL(fd,4) = sd->status.account_id;
  10262. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10263. for( i = 0; i < carts; i++ ) {
  10264. WFIFOB(fd,8 + i) = 10 + i;
  10265. }
  10266. WFIFOSET(fd,8 + carts);
  10267. #endif
  10268. }
  10269. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10270. /// 0980 <identity>.L <type>.B
  10271. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10272. #if PACKETVER >= 20150826
  10273. int type;
  10274. // Check identity
  10275. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10276. return;
  10277. type = (int)RFIFOB(fd,6);
  10278. // Check type
  10279. if( type < 10 || type > MAX_CARTS )
  10280. return;
  10281. pc_setcart(sd, type);
  10282. #endif
  10283. }
  10284. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10285. /// 01af <num>.W
  10286. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10287. {// TODO: State tracking?
  10288. int type;
  10289. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10290. return;
  10291. #ifdef RENEWAL
  10292. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10293. clif_msg(sd, WORK_IN_PROGRESS);
  10294. return;
  10295. }
  10296. #endif
  10297. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10298. if(
  10299. #ifdef NEW_CARTS
  10300. (type == 9 && sd->status.base_level > 130) ||
  10301. (type == 8 && sd->status.base_level > 120) ||
  10302. (type == 7 && sd->status.base_level > 110) ||
  10303. (type == 6 && sd->status.base_level > 100) ||
  10304. #endif
  10305. (type == 5 && sd->status.base_level > 90) ||
  10306. (type == 4 && sd->status.base_level > 80) ||
  10307. (type == 3 && sd->status.base_level > 65) ||
  10308. (type == 2 && sd->status.base_level > 40) ||
  10309. (type == 1))
  10310. pc_setcart(sd, type);
  10311. }
  10312. /// Request to increase status (CZ_STATUS_CHANGE).
  10313. /// 00bb <status id>.W <amount>.B
  10314. /// status id:
  10315. /// SP_STR ~ SP_LUK
  10316. /// amount:
  10317. /// Old clients always send 1 for this, even when using /str+ and the like.
  10318. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10319. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10320. {
  10321. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10322. if( increase_amount < 0 ) {
  10323. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10324. fd, increase_amount);
  10325. }
  10326. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10327. }
  10328. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10329. /// 0112 <skill id>.W
  10330. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10331. {
  10332. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10333. }
  10334. 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)
  10335. {
  10336. int lv;
  10337. if( !hd )
  10338. return;
  10339. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10340. clif_emotion(&hd->bl, ET_THINK);
  10341. return;
  10342. }
  10343. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10344. target_id = hd->bl.id;
  10345. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10346. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10347. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10348. clif_emotion(&hd->bl, ET_THINK);
  10349. if (hd->master)
  10350. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10351. return;
  10352. }
  10353. lv = hom_checkskill(hd, skill_id);
  10354. if( skill_lv > lv )
  10355. skill_lv = lv;
  10356. if( skill_lv )
  10357. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10358. }
  10359. 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)
  10360. {
  10361. int lv;
  10362. if( !hd )
  10363. return;
  10364. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10365. clif_emotion(&hd->bl, ET_THINK);
  10366. return;
  10367. }
  10368. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10369. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10370. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10371. clif_emotion(&hd->bl, ET_THINK);
  10372. if (hd->master)
  10373. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10374. return;
  10375. }
  10376. if( hd->sc.data[SC_BASILICA] )
  10377. return;
  10378. lv = hom_checkskill(hd, skill_id);
  10379. if( skill_lv > lv )
  10380. skill_lv = lv;
  10381. if( skill_lv )
  10382. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10383. }
  10384. 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)
  10385. {
  10386. int lv;
  10387. if( !md )
  10388. return;
  10389. if( skill_isNotOk_mercenary(skill_id, md) )
  10390. return;
  10391. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10392. target_id = md->bl.id;
  10393. if( md->ud.skilltimer != INVALID_TIMER )
  10394. {
  10395. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10396. }
  10397. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10398. return;
  10399. lv = mercenary_checkskill(md, skill_id);
  10400. if( skill_lv > lv )
  10401. skill_lv = lv;
  10402. if( skill_lv )
  10403. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10404. }
  10405. 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)
  10406. {
  10407. int lv;
  10408. if( !md )
  10409. return;
  10410. if( skill_isNotOk_mercenary(skill_id, md) )
  10411. return;
  10412. if( md->ud.skilltimer != INVALID_TIMER )
  10413. return;
  10414. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10415. {
  10416. if (md->master)
  10417. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10418. return;
  10419. }
  10420. if( md->sc.data[SC_BASILICA] )
  10421. return;
  10422. lv = mercenary_checkskill(md, skill_id);
  10423. if( skill_lv > lv )
  10424. skill_lv = lv;
  10425. if( skill_lv )
  10426. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10427. }
  10428. /// Request to use a targeted skill.
  10429. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10430. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10431. /// There are various variants of this packet, some of them have padding between fields.
  10432. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  10433. {
  10434. uint16 skill_id, skill_lv;
  10435. int inf,target_id;
  10436. unsigned int tick = gettick();
  10437. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10438. skill_lv = RFIFOW(fd,info->pos[0]);
  10439. skill_id = RFIFOW(fd,info->pos[1]);
  10440. target_id = RFIFOL(fd,info->pos[2]);
  10441. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10442. inf = skill_get_inf(skill_id);
  10443. if (inf&INF_GROUND_SKILL || !inf)
  10444. return; //Using a ground/passive skill on a target? WRONG.
  10445. if( SKILL_CHK_HOMUN(skill_id) ) {
  10446. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10447. return;
  10448. }
  10449. if( SKILL_CHK_MERC(skill_id) ) {
  10450. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10451. return;
  10452. }
  10453. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10454. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10455. sd->idletime = last_tick;
  10456. if( sd->npc_id ){
  10457. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) || !sd->npc_item_flag || !( inf & INF_SELF_SKILL ) ){
  10458. #ifdef RENEWAL
  10459. clif_msg( sd, WORK_IN_PROGRESS );
  10460. #endif
  10461. return;
  10462. }
  10463. }
  10464. if( (pc_cant_act2(sd) || sd->chatID) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE &&
  10465. (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10466. sd->state.storage_flag && !(inf&INF_SELF_SKILL) ) //SELF skills can be used with the storage open, issue: 8027
  10467. return;
  10468. if( pc_issit(sd) )
  10469. return;
  10470. if( skill_isNotOk(skill_id, sd) )
  10471. return;
  10472. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10473. target_id = sd->bl.id; // never trust the client
  10474. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10475. target_id = sd->bl.id;
  10476. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10477. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10478. return;
  10479. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10480. if( sd->skillitem != skill_id ) {
  10481. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10482. return;
  10483. }
  10484. }
  10485. if( sd->sc.option&OPTION_COSTUME )
  10486. return;
  10487. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10488. return; // On basilica only caster can use Basilica again to stop it.
  10489. if( sd->menuskill_id ) {
  10490. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10491. clif_menuskill_clear(sd); //Cancel pet capture.
  10492. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10493. return; //Can't use skills while a menu is open.
  10494. }
  10495. if( sd->skillitem == skill_id ) {
  10496. if( skill_lv != sd->skillitemlv )
  10497. skill_lv = sd->skillitemlv;
  10498. if( !(inf&INF_SELF_SKILL) )
  10499. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10500. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10501. return;
  10502. }
  10503. sd->skillitem = sd->skillitemlv = 0;
  10504. if( SKILL_CHK_GUILD(skill_id) ) {
  10505. if( sd->state.gmaster_flag )
  10506. skill_lv = guild_checkskill(sd->guild, skill_id);
  10507. else
  10508. skill_lv = 0;
  10509. } else {
  10510. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10511. }
  10512. pc_delinvincibletimer(sd);
  10513. if( skill_lv )
  10514. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10515. }
  10516. /*==========================================
  10517. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10518. *------------------------------------------*/
  10519. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10520. {
  10521. unsigned int tick = gettick();
  10522. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10523. return; //Using a target skill on the ground? WRONG.
  10524. if( SKILL_CHK_HOMUN(skill_id) ) {
  10525. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10526. return;
  10527. }
  10528. if( SKILL_CHK_MERC(skill_id) ) {
  10529. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10530. return;
  10531. }
  10532. if( pc_hasprogress( sd, WIP_DISABLE_SKILLITEM ) ){
  10533. #ifdef RENEWAL
  10534. clif_msg( sd, WORK_IN_PROGRESS );
  10535. #endif
  10536. return;
  10537. }
  10538. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10539. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10540. sd->idletime = last_tick;
  10541. if( skill_isNotOk(skill_id, sd) )
  10542. return;
  10543. if( skillmoreinfo != -1 ) {
  10544. if( pc_issit(sd) ) {
  10545. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10546. return;
  10547. }
  10548. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10549. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10550. }
  10551. if( sd->ud.skilltimer != INVALID_TIMER )
  10552. return;
  10553. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10554. if( sd->skillitem != skill_id ) {
  10555. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10556. return;
  10557. }
  10558. }
  10559. if( sd->sc.option&OPTION_COSTUME )
  10560. return;
  10561. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10562. return; // On basilica only caster can use Basilica again to stop it.
  10563. if( sd->menuskill_id ) {
  10564. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10565. clif_menuskill_clear(sd); //Cancel pet capture.
  10566. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10567. return; //Can't use skills while a menu is open.
  10568. }
  10569. pc_delinvincibletimer(sd);
  10570. if( sd->skillitem == skill_id ) {
  10571. if( skill_lv != sd->skillitemlv )
  10572. skill_lv = sd->skillitemlv;
  10573. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10574. } else {
  10575. int lv;
  10576. sd->skillitem = sd->skillitemlv = 0;
  10577. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10578. if( skill_lv > lv )
  10579. skill_lv = lv;
  10580. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10581. }
  10582. }
  10583. }
  10584. /// Request to use a ground skill.
  10585. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10586. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10587. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  10588. /// There are various variants of this packet, some of them have padding between fields.
  10589. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10590. {
  10591. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10592. if (pc_cant_act(sd))
  10593. return;
  10594. if (pc_issit(sd))
  10595. return;
  10596. clif_parse_UseSkillToPosSub(fd, sd,
  10597. RFIFOW(fd,info->pos[0]), //skill lv
  10598. RFIFOW(fd,info->pos[1]), //skill num
  10599. RFIFOW(fd,info->pos[2]), //pos x
  10600. RFIFOW(fd,info->pos[3]), //pos y
  10601. // TODO: find out what this is intended to do
  10602. //RFIFOB(fd, info->pos[4])
  10603. -1 //Skill more info.
  10604. );
  10605. }
  10606. /// Request to use a ground skill with text.
  10607. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10608. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10609. /// There are various variants of this packet, some of them have padding between fields.
  10610. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10611. {
  10612. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10613. if (pc_cant_act(sd))
  10614. return;
  10615. if (pc_issit(sd))
  10616. return;
  10617. clif_parse_UseSkillToPosSub(fd, sd,
  10618. RFIFOW(fd,info->pos[0]), //Skill lv
  10619. RFIFOW(fd,info->pos[1]), //Skill num
  10620. RFIFOW(fd,info->pos[2]), //pos x
  10621. RFIFOW(fd,info->pos[3]), //pos y
  10622. info->pos[4] //skill more info
  10623. );
  10624. }
  10625. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10626. /// 011b <skill id>.W <map name>.16B
  10627. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10628. {
  10629. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10630. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10631. char map_name[MAP_NAME_LENGTH];
  10632. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10633. sd->state.workinprogress = WIP_DISABLE_NONE;
  10634. if(skill_id != sd->menuskill_id)
  10635. return;
  10636. //It is possible to use teleport with the storage window open bugreport:8027
  10637. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10638. clif_menuskill_clear(sd);
  10639. return;
  10640. }
  10641. pc_delinvincibletimer(sd);
  10642. skill_castend_map(sd,skill_id,map_name);
  10643. }
  10644. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10645. /// 011d
  10646. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10647. {
  10648. if (!pc_isdead(sd))
  10649. pc_memo(sd,-1);
  10650. }
  10651. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10652. /// 018e <name id>.W { <material id>.W }*3
  10653. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10654. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10655. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  10656. int slot1 = RFIFOW(fd,info->pos[1]);
  10657. int slot2 = RFIFOW(fd,info->pos[2]);
  10658. int slot3 = RFIFOW(fd,info->pos[3]);
  10659. short produce_idx = -1;
  10660. switch( sd->menuskill_id ) {
  10661. case -1:
  10662. case AM_PHARMACY:
  10663. case RK_RUNEMASTERY:
  10664. case GC_RESEARCHNEWPOISON:
  10665. break;
  10666. default:
  10667. return;
  10668. }
  10669. if (pc_istrading(sd)) {
  10670. //Make it fail to avoid shop exploits where you sell something different than you see.
  10671. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10672. clif_menuskill_clear(sd);
  10673. return;
  10674. }
  10675. if( (produce_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1)) )
  10676. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3,1,produce_idx-1);
  10677. clif_menuskill_clear(sd);
  10678. }
  10679. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10680. /// 025b <mk type>.W <name id>.W
  10681. /// mk type:
  10682. /// 1 = cooking
  10683. /// 2 = arrow
  10684. /// 3 = elemental
  10685. /// 4 = GN_MIX_COOKING
  10686. /// 5 = GN_MAKEBOMB
  10687. /// 6 = GN_S_PHARMACY
  10688. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10689. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10690. int type = RFIFOW(fd,info->pos[0]);
  10691. unsigned short nameid = RFIFOW(fd,info->pos[1]);
  10692. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10693. short food_idx = -1;
  10694. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10695. return;
  10696. if (pc_istrading(sd)) {
  10697. //Make it fail to avoid shop exploits where you sell something different than you see.
  10698. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10699. clif_menuskill_clear(sd);
  10700. return;
  10701. }
  10702. if( (food_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount)) )
  10703. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount,food_idx-1);
  10704. clif_menuskill_clear(sd);
  10705. }
  10706. /// Answer to repair weapon item selection dialog
  10707. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10708. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10709. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  10710. {
  10711. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10712. return;
  10713. if (pc_istrading(sd)) {
  10714. //Make it fail to avoid shop exploits where you sell something different than you see.
  10715. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10716. clif_menuskill_clear(sd);
  10717. return;
  10718. }
  10719. skill_repairweapon(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10720. //nameid = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10721. //refine = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  10722. //for(i = 0; i<MAX_SLOTS; i++)
  10723. // card[i] = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[3+i]);
  10724. clif_menuskill_clear(sd);
  10725. }
  10726. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10727. /// 0222 <index>.L
  10728. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  10729. {
  10730. int idx;
  10731. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10732. return;
  10733. if (pc_istrading(sd)) {
  10734. //Make it fail to avoid shop exploits where you sell something different than you see.
  10735. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10736. clif_menuskill_clear(sd);
  10737. return;
  10738. }
  10739. idx = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10740. skill_weaponrefine(sd, idx-2);
  10741. clif_menuskill_clear(sd);
  10742. }
  10743. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10744. /// 00b8 <npc id>.L <choice>.B
  10745. /// choice:
  10746. /// 1~254 = menu item
  10747. /// 255 = cancel
  10748. /// NOTE: If there were more than 254 items in the list, choice
  10749. /// overflows to choice%256.
  10750. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10751. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10752. int npc_id = RFIFOL(fd,info->pos[0]);
  10753. uint8 select = RFIFOB(fd,info->pos[1]);
  10754. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10755. #ifdef SECURE_NPCTIMEOUT
  10756. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10757. #endif
  10758. TBL_NPC* nd = map_id2nd(npc_id);
  10759. 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);
  10760. clif_GM_kick(NULL,sd);
  10761. #ifdef SECURE_NPCTIMEOUT
  10762. }
  10763. #endif
  10764. return;
  10765. }
  10766. sd->npc_menu = select;
  10767. npc_scriptcont(sd,npc_id, false);
  10768. }
  10769. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10770. /// 00b9 <npc id>.L
  10771. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10772. {
  10773. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  10774. }
  10775. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10776. /// 0143 <npc id>.L <value>.L
  10777. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10778. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10779. int npcid = RFIFOL(fd,info->pos[0]);
  10780. int amount = (int)RFIFOL(fd,info->pos[1]);
  10781. sd->npc_amount = amount;
  10782. npc_scriptcont(sd, npcid, false);
  10783. }
  10784. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10785. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10786. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10787. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10788. int message_len = RFIFOW(fd,info->pos[0])-8;
  10789. int npcid = RFIFOL(fd,info->pos[1]);
  10790. const char* message = RFIFOCP(fd,info->pos[2]);
  10791. if( message_len <= 0 )
  10792. return; // invalid input
  10793. #if PACKETVER >= 20151001
  10794. message_len++;
  10795. #endif
  10796. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10797. npc_scriptcont(sd, npcid, false);
  10798. }
  10799. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10800. /// 0146 <npc id>.L
  10801. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10802. {
  10803. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10804. return;
  10805. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  10806. }
  10807. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10808. /// 0178 <index>.W
  10809. /// index:
  10810. /// -1 = cancel
  10811. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  10812. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  10813. if (sd->menuskill_id != MC_IDENTIFY)
  10814. return;
  10815. // Ignore the request
  10816. // - Invalid item index
  10817. // - Invalid item ID or item doesn't exist
  10818. // - Item is already identified
  10819. if (idx < 0 || idx >= MAX_INVENTORY ||
  10820. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  10821. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  10822. sd->state.workinprogress = WIP_DISABLE_NONE;
  10823. clif_menuskill_clear(sd);
  10824. return;
  10825. }
  10826. skill_identify(sd, idx);
  10827. clif_menuskill_clear(sd);
  10828. }
  10829. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10830. /// 01ae <name id>.W
  10831. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  10832. unsigned short nameid = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10833. if (pc_istrading(sd)) {
  10834. //Make it fail to avoid shop exploits where you sell something different than you see.
  10835. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10836. clif_menuskill_clear(sd);
  10837. return;
  10838. }
  10839. switch (sd->menuskill_id) {
  10840. case AC_MAKINGARROW:
  10841. skill_arrow_create(sd,nameid);
  10842. break;
  10843. case SA_CREATECON:
  10844. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0,1,-1);
  10845. break;
  10846. case WL_READING_SB:
  10847. skill_spellbook(sd,nameid);
  10848. break;
  10849. case GC_POISONINGWEAPON:
  10850. skill_poisoningweapon(sd,nameid);
  10851. break;
  10852. case NC_MAGICDECOY:
  10853. skill_magicdecoy(sd,nameid);
  10854. break;
  10855. }
  10856. clif_menuskill_clear(sd);
  10857. }
  10858. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10859. /// 01ce <skill id>.L
  10860. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10861. {
  10862. if (sd->menuskill_id != SA_AUTOSPELL)
  10863. return;
  10864. sd->state.workinprogress = WIP_DISABLE_NONE;
  10865. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10866. clif_menuskill_clear(sd);
  10867. }
  10868. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10869. /// 017a <card index>.W
  10870. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10871. {
  10872. if (sd->state.trading != 0)
  10873. return;
  10874. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  10875. }
  10876. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10877. /// 017c <card index>.W <equip index>.W
  10878. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10879. {
  10880. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10881. if (sd->state.trading != 0)
  10882. return;
  10883. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10884. }
  10885. /// Request of character's name by char ID.
  10886. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10887. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10888. /// There are various variants of this packet, some of them have padding between fields.
  10889. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10890. {
  10891. int charid;
  10892. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10893. map_reqnickdb(sd, charid);
  10894. }
  10895. /// /resetskill /resetstate (CZ_RESET).
  10896. /// Request to reset stats or skills.
  10897. /// 0197 <type>.W
  10898. /// type:
  10899. /// 0 = state
  10900. /// 1 = skill
  10901. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10902. char cmd[15];
  10903. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  10904. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10905. else
  10906. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10907. is_atcommand(fd, sd, cmd, 1);
  10908. }
  10909. /// /lb /nlb (CZ_LOCALBROADCAST).
  10910. /// Request to broadcast a message on current map.
  10911. /// 019c <packet len>.W <text>.?B
  10912. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10913. {
  10914. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10915. char command[CHAT_SIZE_MAX+16];
  10916. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10917. char* msg = RFIFOCP(fd,info->pos[1]);
  10918. // as the length varies depending on the command used, just block unreasonably long strings
  10919. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10920. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10921. is_atcommand(fd, sd, command, 1);
  10922. }
  10923. /// Request to move an item from inventory to storage.
  10924. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10925. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10926. /// There are various variants of this packet, some of them have padding between fields.
  10927. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10928. {
  10929. int item_index, item_amount;
  10930. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10931. if (pc_istrading(sd))
  10932. return;
  10933. item_index = RFIFOW(fd,info->pos[0])-2;
  10934. item_amount = RFIFOL(fd,info->pos[1]);
  10935. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10936. return;
  10937. if (sd->state.storage_flag == 1)
  10938. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  10939. else
  10940. if (sd->state.storage_flag == 2)
  10941. storage_guild_storageadd(sd, item_index, item_amount);
  10942. else if (sd->state.storage_flag == 3)
  10943. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  10944. }
  10945. /// Request to move an item from storage to inventory.
  10946. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10947. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10948. /// There are various variants of this packet, some of them have padding between fields.
  10949. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10950. {
  10951. int item_index, item_amount;
  10952. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10953. item_index = RFIFOW(fd,info->pos[0])-1;
  10954. item_amount = RFIFOL(fd,info->pos[1]);
  10955. if (sd->state.storage_flag == 1)
  10956. storage_storageget(sd, &sd->storage, item_index, item_amount);
  10957. else if(sd->state.storage_flag == 2)
  10958. storage_guild_storageget(sd, item_index, item_amount);
  10959. else if(sd->state.storage_flag == 3)
  10960. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  10961. }
  10962. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10963. /// 0129 <index>.W <amount>.L
  10964. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10965. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10966. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10967. int amount = RFIFOL(fd,info->pos[1]);
  10968. if( sd->state.vending )
  10969. return;
  10970. if (!pc_iscarton(sd))
  10971. return;
  10972. if (sd->state.storage_flag == 1)
  10973. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  10974. else if (sd->state.storage_flag == 2)
  10975. storage_guild_storageaddfromcart(sd, idx, amount);
  10976. else if (sd->state.storage_flag == 3)
  10977. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  10978. }
  10979. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10980. /// 0128 <index>.W <amount>.L
  10981. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  10982. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10983. int idx = RFIFOW(fd,info->pos[0]) - 1;
  10984. int amount = RFIFOL(fd,info->pos[1]);
  10985. if( sd->state.vending )
  10986. return;
  10987. if (!pc_iscarton(sd))
  10988. return;
  10989. if (sd->state.storage_flag == 1)
  10990. storage_storagegettocart(sd, &sd->storage, idx, amount);
  10991. else
  10992. if (sd->state.storage_flag == 2)
  10993. storage_guild_storagegettocart(sd, idx, amount);
  10994. else if (sd->state.storage_flag == 3)
  10995. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  10996. }
  10997. /// Request to close storage (CZ_CLOSE_STORE).
  10998. /// 00f7
  10999. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  11000. {
  11001. if( sd->state.storage_flag == 1 )
  11002. storage_storageclose(sd);
  11003. else
  11004. if( sd->state.storage_flag == 2 )
  11005. storage_guild_storageclose(sd);
  11006. else if( sd->state.storage_flag == 3 )
  11007. storage_premiumStorage_close(sd);
  11008. }
  11009. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  11010. /// 023a <info>.W
  11011. /// info:
  11012. /// 0 = password has not been set yet
  11013. /// 1 = storage is password-protected
  11014. /// 8 = too many wrong passwords
  11015. /// ? = ignored
  11016. /// NOTE: This packet is only available on certain non-kRO clients.
  11017. void clif_storagepassword(struct map_session_data* sd, short info)
  11018. {
  11019. int fd = sd->fd;
  11020. WFIFOHEAD(fd,packet_len(0x23a));
  11021. WFIFOW(fd,0) = 0x23a;
  11022. WFIFOW(fd,2) = info;
  11023. WFIFOSET(fd,packet_len(0x23a));
  11024. }
  11025. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11026. /// 023b <type>.W <password>.16B <new password>.16B
  11027. /// type:
  11028. /// 2 = change password
  11029. /// 3 = check password
  11030. /// NOTE: This packet is only available on certain non-kRO clients.
  11031. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  11032. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11033. // int type = RFIFOW(fd,info->pos[0]);
  11034. // char* password = RFIFOP(fd,info->pos[1]);
  11035. // char* new_password = RFIFOP(fd,info->pos[2]);
  11036. // storage_changepass(sd,password,new_password);
  11037. }
  11038. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11039. /// 023c <result>.W <error count>.W
  11040. /// result:
  11041. /// 4 = password change success
  11042. /// 5 = password change failure
  11043. /// 6 = password check success
  11044. /// 7 = password check failure
  11045. /// 8 = too many wrong passwords
  11046. /// ? = ignored
  11047. /// NOTE: This packet is only available on certain non-kRO clients.
  11048. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  11049. {
  11050. int fd = sd->fd;
  11051. WFIFOHEAD(fd,packet_len(0x23c));
  11052. WFIFOW(fd,0) = 0x23c;
  11053. WFIFOW(fd,2) = result;
  11054. WFIFOW(fd,4) = error_count;
  11055. WFIFOSET(fd,packet_len(0x23c));
  11056. }
  11057. /// Party creation request
  11058. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11059. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  11060. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11061. name[NAME_LENGTH-1] = '\0';
  11062. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11063. clif_displaymessage(fd, msg_txt(sd,227));
  11064. return;
  11065. }
  11066. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11067. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11068. return;
  11069. }
  11070. party_create(sd,name,0,0);
  11071. }
  11072. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11073. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11074. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11075. char* name = RFIFOCP(fd,info->pos[0]);
  11076. int item1 = RFIFOB(fd,info->pos[1]);
  11077. int item2 = RFIFOB(fd,info->pos[2]);
  11078. name[NAME_LENGTH-1] = '\0';
  11079. if( map_getmapflag(sd->bl.m, MF_PARTYLOCK) ) {// Party locked.
  11080. clif_displaymessage(fd, msg_txt(sd,227));
  11081. return;
  11082. }
  11083. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11084. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11085. return;
  11086. }
  11087. party_create(sd,name,item1,item2);
  11088. }
  11089. /// Party invitation request
  11090. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11091. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11092. {
  11093. struct map_session_data *t_sd;
  11094. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11095. clif_displaymessage(fd, msg_txt(sd,227));
  11096. return;
  11097. }
  11098. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11099. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11100. clif_noask_sub(sd, t_sd, 1);
  11101. return;
  11102. }
  11103. party_invite(sd, t_sd);
  11104. }
  11105. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11106. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11107. struct map_session_data *t_sd;
  11108. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11109. name[NAME_LENGTH-1] = '\0';
  11110. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11111. clif_displaymessage(fd, msg_txt(sd,227));
  11112. return;
  11113. }
  11114. t_sd = map_nick2sd(name,false);
  11115. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11116. clif_noask_sub(sd, t_sd, 1);
  11117. return;
  11118. }
  11119. party_invite(sd, t_sd);
  11120. }
  11121. /// Party invitation reply
  11122. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11123. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11124. /// flag:
  11125. /// 0 = reject
  11126. /// 1 = accept
  11127. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11128. {
  11129. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11130. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11131. RFIFOL(fd,info->pos[1]));
  11132. }
  11133. //(CZ_PARTY_JOIN_REQ_ACK)
  11134. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11135. {
  11136. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11137. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11138. RFIFOB(fd,info->pos[1]));
  11139. }
  11140. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11141. /// 0100
  11142. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11143. {
  11144. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11145. clif_displaymessage(fd, msg_txt(sd,227));
  11146. return;
  11147. }
  11148. party_leave(sd);
  11149. }
  11150. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11151. /// 0103 <account id>.L <char name>.24B
  11152. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11153. {
  11154. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11155. if(map_getmapflag(sd->bl.m, MF_PARTYLOCK)) {// Party locked.
  11156. clif_displaymessage(fd, msg_txt(sd,227));
  11157. return;
  11158. }
  11159. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11160. RFIFOCP(fd,info->pos[1]));
  11161. }
  11162. /// Request to change party options.
  11163. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11164. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11165. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11166. {
  11167. struct party_data *p;
  11168. int i,expflag;
  11169. int cmd = RFIFOW(fd,0);
  11170. struct s_packet_db* info = &packet_db[cmd];
  11171. if( !sd->status.party_id )
  11172. return;
  11173. p = party_search(sd->status.party_id);
  11174. if( p == NULL )
  11175. return;
  11176. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11177. if( i == MAX_PARTY )
  11178. return; //Shouldn't happen
  11179. if( !p->party.member[i].leader )
  11180. return;
  11181. expflag = RFIFOL(fd,info->pos[0]);
  11182. if(cmd == 0x0102){ //Client can't change the item-field
  11183. party_changeoption(sd, expflag, p->party.item);
  11184. }
  11185. else {
  11186. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11187. party_changeoption(sd, expflag, itemflag);
  11188. }
  11189. }
  11190. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11191. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11192. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11193. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11194. // validate packet and retrieve name and message
  11195. if( !clif_process_message( sd, false, name, message, output ) )
  11196. return;
  11197. party_send_message(sd, output, strlen(output) + 1 );
  11198. }
  11199. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11200. /// 07da <account id>.L
  11201. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11202. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11203. }
  11204. /// Party Booking in KRO [Spiria]
  11205. ///
  11206. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11207. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11208. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11209. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11210. short level = RFIFOW(fd,info->pos[0]);
  11211. short mapid = RFIFOW(fd,info->pos[1]);
  11212. int idxpbj = info->pos[2];
  11213. short job[MAX_PARTY_BOOKING_JOBS];
  11214. int i;
  11215. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11216. job[i] = RFIFOB(fd,idxpbj+i*2);
  11217. party_booking_register(sd, level, mapid, job);
  11218. }
  11219. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11220. /// 0803 <result>.W
  11221. /// result:
  11222. /// 0 = success
  11223. /// 1 = failure
  11224. /// 2 = already registered
  11225. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11226. {
  11227. int fd = sd->fd;
  11228. WFIFOHEAD(fd,packet_len(0x803));
  11229. WFIFOW(fd,0) = 0x803;
  11230. WFIFOW(fd,2) = flag;
  11231. WFIFOSET(fd,packet_len(0x803));
  11232. }
  11233. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11234. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11235. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11236. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11237. short level = RFIFOW(fd,info->pos[0]);
  11238. short mapid = RFIFOW(fd,info->pos[1]);
  11239. short job = RFIFOW(fd,info->pos[2]);
  11240. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11241. short resultcount = RFIFOW(fd,info->pos[4]);
  11242. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11243. }
  11244. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11245. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11246. /// more results:
  11247. /// 0 = no
  11248. /// 1 = yes
  11249. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11250. {
  11251. int i, j;
  11252. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11253. struct party_booking_ad_info *pb_ad;
  11254. WFIFOHEAD(fd,size*count + 5);
  11255. WFIFOW(fd,0) = 0x805;
  11256. WFIFOW(fd,2) = size*count + 5;
  11257. WFIFOB(fd,4) = more_result;
  11258. for(i=0; i<count; i++)
  11259. {
  11260. pb_ad = results[i];
  11261. WFIFOL(fd,i*size+5) = pb_ad->index;
  11262. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11263. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11264. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11265. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11266. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11267. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11268. }
  11269. WFIFOSET(fd,WFIFOW(fd,2));
  11270. }
  11271. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11272. /// 0806
  11273. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11274. {
  11275. if(party_booking_delete(sd))
  11276. clif_PartyBookingDeleteAck(sd, 0);
  11277. }
  11278. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11279. /// 0807 <result>.W
  11280. /// result:
  11281. /// 0 = success
  11282. /// 1 = success (auto-removed expired ad)
  11283. /// 2 = failure
  11284. /// 3 = nothing registered
  11285. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11286. {
  11287. int fd = sd->fd;
  11288. WFIFOHEAD(fd,packet_len(0x807));
  11289. WFIFOW(fd,0) = 0x807;
  11290. WFIFOW(fd,2) = flag;
  11291. WFIFOSET(fd,packet_len(0x807));
  11292. }
  11293. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11294. /// 0808 { <job>.W }*6
  11295. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11296. {
  11297. short job[MAX_PARTY_BOOKING_JOBS];
  11298. int i;
  11299. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11300. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11301. job[i] = RFIFOW(fd,idxpbu+i*2);
  11302. party_booking_update(sd, job);
  11303. }
  11304. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11305. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11306. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11307. {
  11308. int i;
  11309. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11310. if(pb_ad == NULL) return;
  11311. WBUFW(buf,0) = 0x809;
  11312. WBUFL(buf,2) = pb_ad->index;
  11313. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11314. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11315. WBUFW(buf,34) = pb_ad->p_detail.level;
  11316. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11317. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11318. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11319. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11320. }
  11321. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11322. /// 080a <index>.L { <job>.W }*6
  11323. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11324. {
  11325. int i;
  11326. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11327. if(pb_ad == NULL) return;
  11328. WBUFW(buf,0) = 0x80a;
  11329. WBUFL(buf,2) = pb_ad->index;
  11330. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11331. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11332. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11333. }
  11334. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11335. /// 080b <index>.L
  11336. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11337. {
  11338. uint8 buf[6];
  11339. WBUFW(buf,0) = 0x80b;
  11340. WBUFL(buf,2) = index;
  11341. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11342. }
  11343. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11344. /// 012e
  11345. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11346. {
  11347. vending_closevending(sd);
  11348. }
  11349. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11350. /// 0130 <account id>.L
  11351. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11352. {
  11353. if( sd->npc_id ) {// using an NPC
  11354. return;
  11355. }
  11356. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11357. }
  11358. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11359. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11360. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11361. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11362. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11363. int id = (int)RFIFOL(fd,info->pos[1]);
  11364. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11365. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11366. // whether it fails or not, the buy window is closed
  11367. sd->vended_id = 0;
  11368. }
  11369. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11370. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11371. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11372. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11373. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11374. int aid = (int)RFIFOL(fd,info->pos[1]);
  11375. int uid = (int)RFIFOL(fd,info->pos[2]);
  11376. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11377. vending_purchasereq(sd, aid, uid, data, len/4);
  11378. // whether it fails or not, the buy window is closed
  11379. sd->vended_id = 0;
  11380. }
  11381. /// Confirm or cancel the shop preparation window.
  11382. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11383. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11384. /// result:
  11385. /// 0 = canceled
  11386. /// 1 = open
  11387. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11388. int cmd = RFIFOW(fd,0);
  11389. struct s_packet_db* info = &packet_db[cmd];
  11390. short len = (short)RFIFOW(fd,info->pos[0]);
  11391. const char* message = RFIFOCP(fd,info->pos[1]);
  11392. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11393. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11394. len -= 84;
  11395. }
  11396. else { //(CZ_REQ_OPENSTORE2)
  11397. bool flag;
  11398. len -= 85;
  11399. flag = RFIFOB(fd,info->pos[2]) != 0;
  11400. if (!flag) {
  11401. sd->state.prevend = 0;
  11402. sd->state.workinprogress = WIP_DISABLE_NONE;
  11403. }
  11404. }
  11405. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11406. return;
  11407. if( map_getmapflag(sd->bl.m, MF_NOVENDING) ) {
  11408. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11409. return;
  11410. }
  11411. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11412. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11413. return;
  11414. }
  11415. if( message[0] == '\0' ) // invalid input
  11416. return;
  11417. vending_openvending(sd, message, data, len/8, NULL);
  11418. }
  11419. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11420. /// 0165 <char id>.L <guild name>.24B
  11421. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11422. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11423. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11424. name[NAME_LENGTH-1] = '\0';
  11425. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11426. clif_displaymessage(fd, msg_txt(sd,228));
  11427. return;
  11428. }
  11429. if(sd->clan){
  11430. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11431. return;
  11432. }
  11433. guild_create(sd, name);
  11434. }
  11435. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11436. /// 014d
  11437. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11438. {
  11439. clif_guild_masterormember(sd);
  11440. }
  11441. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11442. /// 014f <type>.L
  11443. /// type:
  11444. /// 0 = basic info
  11445. /// 1 = member manager
  11446. /// 2 = positions
  11447. /// 3 = skills
  11448. /// 4 = expulsion list
  11449. /// 5 = unknown (GM_ALLGUILDLIST)
  11450. /// 6 = notice
  11451. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11452. {
  11453. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11454. if( !sd->status.guild_id && !sd->bg_id )
  11455. return;
  11456. switch( type )
  11457. {
  11458. case 0: // Basic Information Guild, hostile alliance information
  11459. clif_guild_basicinfo(sd);
  11460. clif_guild_allianceinfo(sd);
  11461. break;
  11462. case 1: // Members list, list job title
  11463. clif_guild_positionnamelist(sd);
  11464. clif_guild_memberlist(sd);
  11465. break;
  11466. case 2: // List job title, title information list
  11467. clif_guild_positionnamelist(sd);
  11468. clif_guild_positioninfolist(sd);
  11469. break;
  11470. case 3: // Skill list
  11471. clif_guild_skillinfo(sd);
  11472. break;
  11473. case 4: // Expulsion list
  11474. clif_guild_expulsionlist(sd);
  11475. break;
  11476. default:
  11477. ShowError("clif: guild request info: unknown type %d\n", type);
  11478. break;
  11479. }
  11480. }
  11481. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11482. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11483. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11484. {
  11485. int i;
  11486. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11487. int len = RFIFOW(fd,info->pos[0]);
  11488. int idxgpos = info->pos[1];
  11489. if(!sd->state.gmaster_flag)
  11490. return;
  11491. for(i = idxgpos; i < len; i += 40 ){
  11492. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11493. }
  11494. }
  11495. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11496. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11497. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11498. {
  11499. int i;
  11500. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11501. int len = RFIFOW(fd,info->pos[0]);
  11502. int idxgpos = info->pos[1];
  11503. if(!sd->state.gmaster_flag)
  11504. return;
  11505. // Guild leadership change
  11506. if( len == 16 && RFIFOL(fd,12) == 0 ){
  11507. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11508. clif_msg(sd, GUILD_MASTER_WOE);
  11509. return;
  11510. }
  11511. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){
  11512. clif_msg(sd, GUILD_MASTER_DELAY);
  11513. return;
  11514. }
  11515. guild_gm_change(sd->status.guild_id, RFIFOL(fd, 8));
  11516. return;
  11517. }
  11518. for(i=idxgpos;i<len;i+=12){
  11519. int position = RFIFOL(fd,i+8);
  11520. if( position > 0 ){
  11521. guild_change_memberposition(sd->status.guild_id,RFIFOL(fd,i),RFIFOL(fd,i+4),position);
  11522. }
  11523. }
  11524. }
  11525. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11526. /// 0151 <guild id>.L
  11527. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11528. {
  11529. struct guild* g;
  11530. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11531. if( (g = guild_search(guild_id)) != NULL )
  11532. clif_guild_emblem(sd,g);
  11533. }
  11534. /// Validates data of a guild emblem (compressed bitmap)
  11535. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11536. EMBVALIDATE_SUCCESS = 0,
  11537. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11538. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of battle_config.emblem_transparency_limit
  11539. };
  11540. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11541. {
  11542. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11543. unsigned long buf_len = sizeof(buf);
  11544. int offset = 0;
  11545. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11546. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11547. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11548. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11549. ))
  11550. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11551. if(battle_config.emblem_transparency_limit != 100) {
  11552. int i, transcount = 1, tmp[3];
  11553. for(i = offset; i < buf_len-1; i++) {
  11554. int j = i%3;
  11555. tmp[j] = RBUFL(buf,i);
  11556. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11557. transcount++;
  11558. }
  11559. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  11560. return EMBVALIDATE_ERR_TRANSPARENCY;
  11561. }
  11562. return EMBVALIDATE_SUCCESS;
  11563. }
  11564. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11565. /// 0153 <packet len>.W <emblem data>.?B
  11566. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11567. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11568. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11569. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11570. int emb_val=0;
  11571. if( !emblem_len || !sd->state.gmaster_flag )
  11572. return;
  11573. if(!(battle_config.emblem_woe_change) && is_agit_start() ){
  11574. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11575. return;
  11576. }
  11577. emb_val = clif_validate_emblem(emblem, emblem_len);
  11578. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11579. 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);
  11580. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11581. return;
  11582. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11583. char output[128];
  11584. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11585. 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"
  11586. return;
  11587. }
  11588. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11589. }
  11590. /// Guild notice update request (CZ_GUILD_NOTICE).
  11591. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11592. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11593. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11594. int guild_id = RFIFOL(fd,info->pos[0]);
  11595. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11596. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11597. if(!sd->state.gmaster_flag)
  11598. return;
  11599. // compensate for some client defects when using multilanguage mode
  11600. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11601. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11602. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11603. guild_change_notice(sd, guild_id, msg1, msg2);
  11604. }
  11605. // Helper function for guild invite functions
  11606. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11607. {
  11608. if (t_sd == NULL) // not online or does not exist
  11609. return 1;
  11610. if (map_getmapflag(sd->bl.m, MF_GUILDLOCK)) {//Guild locked.
  11611. clif_displaymessage(fd, msg_txt(sd,228));
  11612. return 1;
  11613. }
  11614. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11615. clif_noask_sub(sd, t_sd, 2);
  11616. return 1;
  11617. }
  11618. // Players in a clan can not join a guild
  11619. if(t_sd && t_sd->clan){
  11620. return 1;
  11621. }
  11622. guild_invite(sd, t_sd);
  11623. return 0;
  11624. }
  11625. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11626. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11627. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11628. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11629. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11630. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11631. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11632. if (clif_sub_guild_invite(fd, sd, t_sd))
  11633. return;
  11634. }
  11635. /// Guild invite request (/guildinvite)
  11636. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11637. void
  11638. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11639. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  11640. if (clif_sub_guild_invite(fd, sd, t_sd))
  11641. return;
  11642. }
  11643. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11644. /// 016b <guild id>.L <answer>.L
  11645. /// answer:
  11646. /// 0 = refuse
  11647. /// 1 = accept
  11648. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11649. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11650. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11651. RFIFOL(fd,info->pos[1]));
  11652. }
  11653. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11654. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11655. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11656. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11657. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11658. clif_displaymessage(fd, msg_txt(sd,228));
  11659. return;
  11660. }
  11661. if( sd->bg_id ) {
  11662. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11663. return;
  11664. }
  11665. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11666. RFIFOL(fd,info->pos[1]),
  11667. RFIFOL(fd,info->pos[2]),
  11668. RFIFOCP(fd,info->pos[3]));
  11669. }
  11670. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11671. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11672. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11673. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11674. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) || sd->bg_id )
  11675. { // Guild locked.
  11676. clif_displaymessage(fd, msg_txt(sd,228));
  11677. return;
  11678. }
  11679. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11680. RFIFOL(fd,info->pos[1]),
  11681. RFIFOL(fd,info->pos[2]),
  11682. RFIFOCP(fd,info->pos[3]));
  11683. }
  11684. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11685. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11686. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11687. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11688. // validate packet and retrieve name and message
  11689. if( !clif_process_message( sd, false, name, message, output ) )
  11690. return;
  11691. if( sd->bg_id )
  11692. bg_send_message(sd, output, strlen(output) );
  11693. else
  11694. guild_send_message(sd, output, strlen(output) );
  11695. }
  11696. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11697. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11698. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11699. {
  11700. struct map_session_data *t_sd;
  11701. if(!sd->state.gmaster_flag)
  11702. return;
  11703. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11704. clif_displaymessage(fd, msg_txt(sd,228));
  11705. return;
  11706. }
  11707. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11708. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11709. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  11710. // @noask [LuzZza]
  11711. if(t_sd && t_sd->state.noask) {
  11712. clif_noask_sub(sd, t_sd, 3);
  11713. return;
  11714. }
  11715. guild_reqalliance(sd,t_sd);
  11716. }
  11717. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11718. /// 0172 <inviter account id>.L <answer>.L
  11719. /// answer:
  11720. /// 0 = refuse
  11721. /// 1 = accept
  11722. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11723. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11724. guild_reply_reqalliance(sd,
  11725. RFIFOL(fd,info->pos[0]),
  11726. RFIFOL(fd,info->pos[1]));
  11727. }
  11728. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11729. /// 0183 <opponent guild id>.L <relation>.L
  11730. /// relation:
  11731. /// 0 = Ally
  11732. /// 1 = Enemy
  11733. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11734. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11735. if(!sd->state.gmaster_flag)
  11736. return;
  11737. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11738. clif_displaymessage(fd, msg_txt(sd,228));
  11739. return;
  11740. }
  11741. guild_delalliance(sd,
  11742. RFIFOL(fd,info->pos[0]),
  11743. RFIFOL(fd,info->pos[1]));
  11744. }
  11745. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11746. /// 0180 <account id>.L
  11747. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11748. {
  11749. struct map_session_data *t_sd;
  11750. if(!sd->state.gmaster_flag)
  11751. return;
  11752. if(map_getmapflag(sd->bl.m, MF_GUILDLOCK)) { //Guild locked.
  11753. clif_displaymessage(fd, msg_txt(sd,228));
  11754. return;
  11755. }
  11756. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11757. // @noask [LuzZza]
  11758. if(t_sd && t_sd->state.noask) {
  11759. clif_noask_sub(sd, t_sd, 4);
  11760. return;
  11761. }
  11762. guild_opposition(sd,t_sd);
  11763. }
  11764. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11765. /// 015d <key>.40B
  11766. /// key:
  11767. /// now guild name; might have been (intended) email, since the
  11768. /// field name and size is same as the one in CH_DELETE_CHAR.
  11769. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11770. {
  11771. if( map_getmapflag(sd->bl.m, MF_GUILDLOCK) ) { //Guild locked.
  11772. clif_displaymessage(fd, msg_txt(sd,228));
  11773. return;
  11774. }
  11775. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11776. }
  11777. /// Pet
  11778. ///
  11779. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11780. /// 01a1 <type>.B
  11781. /// type:
  11782. /// 0 = pet information
  11783. /// 1 = feed
  11784. /// 2 = performance
  11785. /// 3 = return to egg
  11786. /// 4 = unequip accessory
  11787. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11788. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11789. }
  11790. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11791. /// 019f <id>.L
  11792. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11793. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11794. }
  11795. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11796. /// 01a7 <index>.W
  11797. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11798. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11799. return;
  11800. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11801. clif_menuskill_clear(sd);
  11802. }
  11803. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11804. /// 01a9 <data>.L
  11805. /// data:
  11806. /// is either emotion (@see enum emotion_type) or a compound value
  11807. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11808. /// entry (given in parentheses) in data\pettalktable.xml
  11809. /// act id:
  11810. /// 0 = feeding
  11811. /// 1 = hunting
  11812. /// 2 = danger
  11813. /// 3 = dead
  11814. /// 4 = normal (stand)
  11815. /// 5 = special performance (perfor_s)
  11816. /// 6 = level up (levelup)
  11817. /// 7 = performance 1 (perfor_1)
  11818. /// 8 = performance 2 (perfor_2)
  11819. /// 9 = performance 3 (perfor_3)
  11820. /// 10 = log-in greeting (connect)
  11821. /// hungry value:
  11822. /// 0 = very hungry (hungry)
  11823. /// 1 = hungry (bit_hungry)
  11824. /// 2 = satisfied (noting)
  11825. /// 3 = stuffed (full)
  11826. /// 4 = full (so_full)
  11827. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11828. {
  11829. if(sd->pd)
  11830. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11831. }
  11832. /// Request to change pet's name (CZ_RENAME_PET).
  11833. /// 01a5 <name>.24B
  11834. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11835. {
  11836. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11837. }
  11838. /// /kill (CZ_DISCONNECT_CHARACTER).
  11839. /// Request to disconnect a character.
  11840. /// 00cc <account id>.L
  11841. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11842. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11843. {
  11844. struct block_list *target;
  11845. int tid;
  11846. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11847. target = map_id2bl(tid);
  11848. if (!target) {
  11849. clif_GM_kickack(sd, 0);
  11850. return;
  11851. }
  11852. switch (target->type) {
  11853. case BL_PC:
  11854. {
  11855. char command[NAME_LENGTH+6];
  11856. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11857. is_atcommand(fd, sd, command, 1);
  11858. }
  11859. break;
  11860. /**
  11861. * This one does not invoke any atcommand, so we need to check for permissions.
  11862. */
  11863. case BL_MOB:
  11864. {
  11865. char command[100];
  11866. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11867. clif_GM_kickack(sd, 0);
  11868. return;
  11869. }
  11870. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11871. log_atcommand(sd, command);
  11872. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11873. }
  11874. break;
  11875. case BL_NPC:
  11876. {
  11877. struct npc_data* nd = (struct npc_data *)target;
  11878. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11879. npc_unload_duplicates(nd);
  11880. npc_unload(nd,true);
  11881. npc_read_event_script();
  11882. }
  11883. }
  11884. break;
  11885. default:
  11886. clif_GM_kickack(sd, 0);
  11887. }
  11888. }
  11889. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11890. /// Request to disconnect all characters.
  11891. /// 00ce
  11892. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11893. char cmd[15];
  11894. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11895. is_atcommand(fd, sd, cmd, 1);
  11896. }
  11897. /// /remove (CZ_REMOVE_AID).
  11898. /// Request to warp to a character with given login ID.
  11899. /// 01ba <account name>.24B
  11900. /// /shift (CZ_SHIFT).
  11901. /// Request to warp to a character with given name.
  11902. /// 01bb <char name>.24B
  11903. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11904. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11905. char *player_name;
  11906. char command[NAME_LENGTH+8];
  11907. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11908. player_name[NAME_LENGTH-1] = '\0';
  11909. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11910. is_atcommand(fd, sd, command, 1);
  11911. }
  11912. /// /remove (CZ_REMOVE_AID_SSO).
  11913. /// Request to warp to a character with given account ID.
  11914. /// 0843 <account id>.L
  11915. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  11916. {
  11917. uint32 account_id;
  11918. struct map_session_data* pl_sd;
  11919. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11920. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11921. char command[NAME_LENGTH+8];
  11922. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11923. is_atcommand(fd, sd, command, 1);
  11924. }
  11925. }
  11926. /// /recall (CZ_RECALL).
  11927. /// Request to summon a player with given login ID to own position.
  11928. /// 01bc <account name>.24B
  11929. /// /summon (CZ_RECALL_GID).
  11930. /// Request to summon a player with given name to own position.
  11931. /// 01bd <char name>.24B
  11932. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11933. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11934. char *player_name;
  11935. char command [NAME_LENGTH+8];
  11936. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11937. player_name[NAME_LENGTH-1] = '\0';
  11938. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11939. is_atcommand(fd, sd, command, 1);
  11940. }
  11941. /// /recall (CZ_RECALL_SSO).
  11942. /// Request to summon a player with given account ID to own position.
  11943. /// 0842 <account id>.L
  11944. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11945. {
  11946. uint32 account_id;
  11947. struct map_session_data* pl_sd;
  11948. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11949. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11950. char command[NAME_LENGTH+8];
  11951. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11952. is_atcommand(fd, sd, command, 1);
  11953. }
  11954. }
  11955. /// /item /monster (CZ_ITEM_CREATE).
  11956. /// Request to execute GM commands.
  11957. /// Usage:
  11958. /// /item n - summon n monster or acquire n item/s
  11959. /// /item money - grants 2147483647 zenies
  11960. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  11961. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  11962. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  11963. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  11964. /// /item cap_n - capture n monster as pet.(not yet implemented)
  11965. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  11966. /// 013f <item/mob name>.24B
  11967. /// 09ce <item/mob name>.100B [Ind/Yommy]
  11968. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  11969. {
  11970. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11971. int mob_id = 0;
  11972. struct item_data *id = NULL;
  11973. struct mob_db *mob = NULL;
  11974. StringBuf command;
  11975. char *str;
  11976. //#if PACKETVER >= 20131218
  11977. // char str[100];
  11978. //#else
  11979. // char str[24];
  11980. //#endif
  11981. str = RFIFOCP(fd,info->pos[0]);
  11982. if (!str || str[0] == '\0')
  11983. return;
  11984. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  11985. return;
  11986. trim(str);
  11987. // Zeny
  11988. if( strcmpi(str, "money") == 0 ) {
  11989. StringBuf_Init(&command);
  11990. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  11991. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11992. StringBuf_Destroy(&command);
  11993. return;
  11994. }
  11995. // Item
  11996. if( (id = itemdb_searchname(str)) ) {
  11997. StringBuf_Init(&command);
  11998. if( !itemdb_isstackable2(id) ) //Nonstackable
  11999. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  12000. else {
  12001. if (id->flag.guid)
  12002. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  12003. else
  12004. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  12005. }
  12006. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12007. StringBuf_Destroy(&command);
  12008. return;
  12009. }
  12010. // Monster
  12011. if ((mob_id = mobdb_searchname(str)) == 0)
  12012. mob_id = mobdb_checkid(atoi(str));
  12013. if( (mob = mob_db(mob_id)) ) {
  12014. StringBuf_Init(&command);
  12015. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  12016. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12017. StringBuf_Destroy(&command);
  12018. return;
  12019. }
  12020. }
  12021. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12022. /// 019d <effect state>.L
  12023. /// effect state:
  12024. /// TODO: Any OPTION_* ?
  12025. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  12026. char cmd[6];
  12027. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12028. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12029. is_atcommand(fd, sd, cmd, 1);
  12030. }
  12031. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12032. /// 0149 <account id>.L <type>.B <value>.W
  12033. /// type:
  12034. /// 0 = positive points
  12035. /// 1 = negative points
  12036. /// 2 = self mute (+10 minutes)
  12037. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  12038. {
  12039. int id, type, value;
  12040. struct map_session_data *dstsd;
  12041. char command[NAME_LENGTH+15];
  12042. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12043. id = RFIFOL(fd,info->pos[0]);
  12044. type = RFIFOB(fd,info->pos[1]);
  12045. value = RFIFOW(fd,info->pos[2]);
  12046. if( type == 0 )
  12047. value = -value;
  12048. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12049. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12050. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12051. return;
  12052. dstsd = map_id2sd(id);
  12053. if( dstsd == NULL )
  12054. return;
  12055. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12056. is_atcommand(fd, sd, command, 1);
  12057. }
  12058. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12059. /// GM adjustment of a player's manner value by -60.
  12060. /// 0212 <char name>.24B
  12061. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  12062. {
  12063. char command[NAME_LENGTH+15];
  12064. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12065. name[NAME_LENGTH-1] = '\0';
  12066. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12067. is_atcommand(fd, sd, command, 1);
  12068. }
  12069. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12070. /// 01e0 <account id>.L <account name>.24B
  12071. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12072. {
  12073. WFIFOHEAD(fd,packet_len(0x1e0));
  12074. WFIFOW(fd,0) = 0x1e0;
  12075. WFIFOL(fd,2) = account_id;
  12076. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12077. WFIFOSET(fd,packet_len(0x1e0));
  12078. }
  12079. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12080. /// 01df <account id>.L
  12081. //! TODO: Figure out how does this actually work
  12082. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12083. {
  12084. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12085. /*
  12086. char query[30];
  12087. safesnprintf(query,sizeof(query),"%d", account_id);
  12088. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12089. */
  12090. clif_account_name(fd, account_id, "");
  12091. }
  12092. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12093. /// GM single cell type change request.
  12094. /// 0198 <x>.W <y>.W <type>.W
  12095. /// type:
  12096. /// 0 = not walkable
  12097. /// 1 = walkable
  12098. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12099. {
  12100. int x,y,type;
  12101. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12102. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12103. return;
  12104. x = RFIFOW(fd,info->pos[0]);
  12105. y = RFIFOW(fd,info->pos[1]);
  12106. type = RFIFOW(fd,info->pos[2]);
  12107. map_setgatcell(sd->bl.m,x,y,type);
  12108. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12109. //FIXME: once players leave the map, the client 'forgets' this information.
  12110. }
  12111. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12112. /// Request to allow/deny whispers from a nick.
  12113. /// 00cf <nick>.24B <type>.B
  12114. /// type:
  12115. /// 0 = (/ex nick) deny speech from nick
  12116. /// 1 = (/in nick) allow speech from nick
  12117. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12118. {
  12119. char* nick;
  12120. uint8 type;
  12121. int i;
  12122. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12123. nick = RFIFOCP(fd,info->pos[0]);
  12124. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12125. type = RFIFOB(fd,info->pos[1]);
  12126. if( type == 0 ) { // Add name to ignore list (block)
  12127. if (strcmp(wisp_server_name, nick) == 0) {
  12128. clif_wisexin(sd, type, 1); // fail
  12129. return;
  12130. }
  12131. // try to find a free spot, while checking for duplicates at the same time
  12132. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12133. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12134. clif_wisexin(sd, type, 2); // too many blocks
  12135. return;
  12136. }
  12137. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12138. clif_wisexin(sd, type, 0); // Aegis reports success.
  12139. return;
  12140. }
  12141. //Insert in position i
  12142. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12143. } else { // Remove name from ignore list (unblock)
  12144. // find entry
  12145. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12146. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  12147. clif_wisexin(sd, type, 1); // fail
  12148. return;
  12149. }
  12150. // move everything one place down to overwrite removed entry
  12151. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12152. // wipe last entry
  12153. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12154. }
  12155. clif_wisexin(sd, type, 0); // success
  12156. }
  12157. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12158. /// Request to allow/deny all whispers.
  12159. /// 00d0 <type>.B
  12160. /// type:
  12161. /// 0 = (/exall) deny all speech
  12162. /// 1 = (/inall) allow all speech
  12163. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12164. {
  12165. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12166. if( type == 0 ) {// Deny all
  12167. if( sd->state.ignoreAll ) {
  12168. flag = 1; // fail
  12169. } else {
  12170. sd->state.ignoreAll = 1;
  12171. flag = 0; // success
  12172. }
  12173. } else {//Unblock everyone
  12174. if( sd->state.ignoreAll ) {
  12175. sd->state.ignoreAll = 0;
  12176. flag = 0; // success
  12177. } else {
  12178. if (sd->ignore[0].name[0] != '\0')
  12179. { //Wipe the ignore list.
  12180. memset(sd->ignore, 0, sizeof(sd->ignore));
  12181. flag = 0; // success
  12182. } else {
  12183. flag = 1; // fail
  12184. }
  12185. }
  12186. }
  12187. clif_wisall(sd, type, flag);
  12188. }
  12189. /// Whisper ignore list (ZC_WHISPER_LIST).
  12190. /// 00d4 <packet len>.W { <char name>.24B }*
  12191. void clif_PMIgnoreList(struct map_session_data* sd)
  12192. {
  12193. int i, fd = sd->fd;
  12194. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12195. WFIFOW(fd,0) = 0xd4;
  12196. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12197. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12198. }
  12199. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12200. WFIFOSET(fd,WFIFOW(fd,2));
  12201. }
  12202. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12203. /// 00d3
  12204. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12205. {
  12206. clif_PMIgnoreList(sd);
  12207. }
  12208. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12209. /// 01e7
  12210. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12211. {
  12212. if (sd->state.doridori) return;
  12213. switch (sd->class_&MAPID_UPPERMASK) {
  12214. case MAPID_SOUL_LINKER:
  12215. case MAPID_STAR_GLADIATOR:
  12216. case MAPID_TAEKWON:
  12217. if (!sd->state.rest)
  12218. break;
  12219. case MAPID_SUPER_NOVICE:
  12220. case MAPID_SUPER_BABY:
  12221. case MAPID_SUPER_NOVICE_E:
  12222. case MAPID_SUPER_BABY_E:
  12223. sd->state.doridori=1;
  12224. break;
  12225. }
  12226. }
  12227. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12228. /// 01ed
  12229. /// Note: This packet is caused by 7 lines of any text, followed by
  12230. /// the prayer and an another line of any text. The prayer is
  12231. /// defined by lines 790~793 in data\msgstringtable.txt
  12232. /// "Dear angel, can you hear my voice?"
  12233. /// "I am" (space separated player name) "Super Novice~"
  12234. /// "Help me out~ Please~ T_T"
  12235. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12236. {
  12237. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12238. unsigned int next = pc_nextbaseexp(sd);
  12239. if( next ) {
  12240. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  12241. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12242. 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]
  12243. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12244. }
  12245. }
  12246. }
  12247. }
  12248. /// Friends List
  12249. ///
  12250. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12251. /// 0206 <account id>.L <char id>.L <state>.B
  12252. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12253. /// state:
  12254. /// 0 = online
  12255. /// 1 = offline
  12256. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12257. {
  12258. int i, fd = sd->fd;
  12259. //Seek friend.
  12260. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12261. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12262. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12263. return; //Not found
  12264. WFIFOHEAD(fd,packet_len(0x206));
  12265. WFIFOW(fd, 0) = 0x206;
  12266. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12267. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12268. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12269. #if PACKETVER >= 20180221
  12270. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12271. #endif
  12272. WFIFOSET(fd, packet_len(0x206));
  12273. }
  12274. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12275. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12276. {
  12277. uint32 account_id, char_id, online;
  12278. account_id = va_arg(ap, int);
  12279. char_id = va_arg(ap, int);
  12280. online = va_arg(ap, int);
  12281. clif_friendslist_toggle(sd, account_id, char_id, online);
  12282. return 0;
  12283. }
  12284. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12285. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12286. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12287. void clif_friendslist_send(struct map_session_data *sd)
  12288. {
  12289. int i = 0, n, fd = sd->fd;
  12290. #if PACKETVER >= 20180221
  12291. const int size = 8;
  12292. #else
  12293. const int size = 8 + NAME_LENGTH;
  12294. #endif
  12295. // Send friends list
  12296. WFIFOHEAD(fd, MAX_FRIENDS * size + 4);
  12297. WFIFOW(fd, 0) = 0x201;
  12298. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12299. WFIFOL(fd, 4 + size * i + 0) = sd->status.friends[i].account_id;
  12300. WFIFOL(fd, 4 + size * i + 4) = sd->status.friends[i].char_id;
  12301. #if PACKETVER < 20180221
  12302. safestrncpy(WFIFOCP(fd, 4 + size * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  12303. #endif
  12304. }
  12305. if (i) {
  12306. WFIFOW(fd,2) = 4 + size * i;
  12307. WFIFOSET(fd, WFIFOW(fd,2));
  12308. }
  12309. for (n = 0; n < i; n++) { //Sending the online players
  12310. if (map_charid2sd(sd->status.friends[n].char_id))
  12311. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12312. }
  12313. }
  12314. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12315. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12316. /// result:
  12317. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12318. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12319. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12320. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12321. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12322. {
  12323. int fd;
  12324. nullpo_retv(sd);
  12325. fd = sd->fd;
  12326. WFIFOHEAD(fd,packet_len(0x209));
  12327. WFIFOW(fd,0) = 0x209;
  12328. WFIFOW(fd,2) = type;
  12329. if (f_sd) {
  12330. WFIFOL(fd,4) = f_sd->status.account_id;
  12331. WFIFOL(fd,8) = f_sd->status.char_id;
  12332. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12333. }
  12334. WFIFOSET(fd, packet_len(0x209));
  12335. }
  12336. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12337. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12338. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12339. {
  12340. int fd = sd->fd;
  12341. WFIFOHEAD(fd,packet_len(0x207));
  12342. WFIFOW(fd,0) = 0x207;
  12343. WFIFOL(fd,2) = account_id;
  12344. WFIFOL(fd,6) = char_id;
  12345. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12346. WFIFOSET(fd,packet_len(0x207));
  12347. }
  12348. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12349. /// 0202 <name>.24B
  12350. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12351. {
  12352. struct map_session_data *f_sd;
  12353. int i;
  12354. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12355. // Friend doesn't exist (no player with this name)
  12356. if (f_sd == NULL) {
  12357. clif_displaymessage(fd, msg_txt(sd,3));
  12358. return;
  12359. }
  12360. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12361. return;
  12362. }
  12363. // ensure that the request player's friend list is not full
  12364. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12365. if( i == MAX_FRIENDS ){
  12366. clif_friendslist_reqack(sd, f_sd, 2);
  12367. return;
  12368. }
  12369. // @noask [LuzZza]
  12370. if(f_sd->state.noask) {
  12371. clif_noask_sub(sd, f_sd, 5);
  12372. return;
  12373. }
  12374. // Friend already exists
  12375. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12376. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12377. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12378. return;
  12379. }
  12380. }
  12381. f_sd->friend_req = sd->status.char_id;
  12382. sd->friend_req = f_sd->status.char_id;
  12383. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12384. }
  12385. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12386. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12387. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12388. /// reply:
  12389. /// 0 = rejected
  12390. /// 1 = accepted
  12391. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12392. {
  12393. struct map_session_data *f_sd;
  12394. uint32 account_id;
  12395. char reply;
  12396. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12397. account_id = RFIFOL(fd,info->pos[0]);
  12398. //char_id = RFIFOL(fd,info->pos[1]);
  12399. #if PACKETVER < 6
  12400. reply = RFIFOB(fd,info->pos[2]);
  12401. #else
  12402. reply = RFIFOL(fd,info->pos[2]);
  12403. #endif
  12404. if( sd->bl.id == account_id ) {// adding oneself as friend
  12405. return;
  12406. }
  12407. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12408. if (f_sd == NULL)
  12409. return;
  12410. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12411. clif_friendslist_reqack(f_sd, sd, 1);
  12412. else {
  12413. int i;
  12414. // Find an empty slot
  12415. for (i = 0; i < MAX_FRIENDS; i++)
  12416. if (f_sd->status.friends[i].char_id == 0)
  12417. break;
  12418. if (i == MAX_FRIENDS) {
  12419. clif_friendslist_reqack(f_sd, sd, 2);
  12420. return;
  12421. }
  12422. f_sd->status.friends[i].account_id = sd->status.account_id;
  12423. f_sd->status.friends[i].char_id = sd->status.char_id;
  12424. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12425. clif_friendslist_reqack(f_sd, sd, 0);
  12426. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12427. if (battle_config.friend_auto_add) {
  12428. // Also add f_sd to sd's friendlist.
  12429. for (i = 0; i < MAX_FRIENDS; i++) {
  12430. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12431. return; //No need to add anything.
  12432. if (sd->status.friends[i].char_id == 0)
  12433. break;
  12434. }
  12435. if (i == MAX_FRIENDS) {
  12436. clif_friendslist_reqack(sd, f_sd, 2);
  12437. return;
  12438. }
  12439. sd->status.friends[i].account_id = f_sd->status.account_id;
  12440. sd->status.friends[i].char_id = f_sd->status.char_id;
  12441. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12442. clif_friendslist_reqack(sd, f_sd, 0);
  12443. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12444. }
  12445. }
  12446. }
  12447. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12448. /// 0203 <account id>.L <char id>.L
  12449. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12450. {
  12451. struct map_session_data *f_sd = NULL;
  12452. uint32 account_id, char_id;
  12453. int i, j;
  12454. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12455. account_id = RFIFOL(fd,info->pos[0]);
  12456. char_id = RFIFOL(fd,info->pos[1]);
  12457. // Search friend
  12458. for (i = 0; i < MAX_FRIENDS &&
  12459. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12460. if (i == MAX_FRIENDS) {
  12461. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12462. return;
  12463. }
  12464. //remove from friend's list first
  12465. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12466. for (i = 0; i < MAX_FRIENDS &&
  12467. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12468. if (i != MAX_FRIENDS) {
  12469. // move all chars up
  12470. for(j = i + 1; j < MAX_FRIENDS; j++)
  12471. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12472. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12473. //should the guy be notified of some message? we should add it here if so
  12474. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12475. WFIFOW(f_sd->fd,0) = 0x20a;
  12476. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12477. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12478. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12479. }
  12480. } else { //friend not online -- ask char server to delete from his friendlist
  12481. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12482. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12483. return;
  12484. }
  12485. }
  12486. // We can now delete from original requester
  12487. for (i = 0; i < MAX_FRIENDS &&
  12488. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12489. // move all chars up
  12490. for(j = i + 1; j < MAX_FRIENDS; j++)
  12491. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12492. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12493. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12494. WFIFOHEAD(fd,packet_len(0x20a));
  12495. WFIFOW(fd,0) = 0x20a;
  12496. WFIFOL(fd,2) = account_id;
  12497. WFIFOL(fd,6) = char_id;
  12498. WFIFOSET(fd, packet_len(0x20a));
  12499. }
  12500. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12501. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12502. void clif_PVPInfo(struct map_session_data* sd)
  12503. {
  12504. int fd = sd->fd;
  12505. WFIFOHEAD(fd,packet_len(0x210));
  12506. WFIFOW(fd,0) = 0x210;
  12507. WFIFOL(fd,2) = sd->status.char_id;
  12508. WFIFOL(fd,6) = sd->status.account_id;
  12509. WFIFOL(fd,10) = sd->pvp_won; // times won
  12510. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12511. WFIFOL(fd,18) = sd->pvp_point;
  12512. WFIFOSET(fd, packet_len(0x210));
  12513. }
  12514. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12515. /// 020f <char id>.L <account id>.L
  12516. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12517. {
  12518. // TODO: Is there a way to use this on an another player (char/acc id)?
  12519. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12520. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12521. clif_PVPInfo(sd);
  12522. }
  12523. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12524. /// 0254 <which>.B
  12525. /// which: (unused atm for security purpose)
  12526. /// 0 = sun
  12527. /// 1 = moon
  12528. /// 2 = star
  12529. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12530. {
  12531. int i;
  12532. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12533. if (sd->menuskill_id != SG_FEEL)
  12534. return;
  12535. i = sd->menuskill_val-1;
  12536. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12537. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12538. sd->feel_map[i].m = sd->bl.m;
  12539. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12540. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12541. // clif_misceffect2(&sd->bl, 0x1b0);
  12542. // clif_misceffect2(&sd->bl, 0x21f);
  12543. clif_feel_info(sd, i, 0);
  12544. clif_menuskill_clear(sd);
  12545. }
  12546. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12547. /// 0253 <which>.B
  12548. /// which:
  12549. /// 0 = sun
  12550. /// 1 = moon
  12551. /// 2 = star
  12552. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12553. {
  12554. WFIFOHEAD(fd,packet_len(0x253));
  12555. WFIFOW(fd,0)=0x253;
  12556. WFIFOB(fd,2)=TOB(skill_lv-1);
  12557. WFIFOSET(fd, packet_len(0x253));
  12558. sd->menuskill_id = SG_FEEL;
  12559. sd->menuskill_val = skill_lv;
  12560. }
  12561. /// Request to change homunculus' name (CZ_RENAME_MER).
  12562. /// 0231 <name>.24B
  12563. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12564. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12565. }
  12566. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12567. /// 0234 <id>.L
  12568. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12569. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12570. struct block_list *bl = NULL;
  12571. struct unit_data *ud = NULL;
  12572. if( sd->md && sd->md->bl.id == id )
  12573. bl = &sd->md->bl;
  12574. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12575. bl = &sd->hd->bl; // Moving Homunculus
  12576. else
  12577. return;
  12578. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12579. ud = unit_bl2ud(bl);
  12580. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12581. }
  12582. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12583. /// 0232 <id>.L <position data>.3B
  12584. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12585. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12586. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12587. struct block_list *bl = NULL;
  12588. short x, y;
  12589. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12590. if( sd->md && sd->md->bl.id == id )
  12591. bl = &sd->md->bl; // Moving Mercenary
  12592. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12593. bl = &sd->hd->bl; // Moving Homunculus
  12594. else
  12595. return;
  12596. unit_walktoxy(bl, x, y, 4);
  12597. }
  12598. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12599. /// 0233 <id>.L <target id>.L <action>.B
  12600. /// action:
  12601. /// always 0
  12602. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12603. {
  12604. struct block_list *bl = NULL;
  12605. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12606. int id = RFIFOL(fd,info->pos[0]);
  12607. int target_id = RFIFOL(fd,info->pos[1]);
  12608. int action_type = RFIFOB(fd,info->pos[2]);
  12609. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12610. bl = &sd->hd->bl;
  12611. else if( sd->md && sd->md->bl.id == id )
  12612. bl = &sd->md->bl;
  12613. else return;
  12614. unit_stop_attack(bl);
  12615. unit_attack(bl, target_id, action_type != 0);
  12616. }
  12617. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12618. /// 022d <type>.W <command>.B
  12619. /// type:
  12620. /// always 0
  12621. /// command:
  12622. /// 0 = homunculus information
  12623. /// 1 = feed
  12624. /// 2 = delete
  12625. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12626. { //[orn]
  12627. int cmd = RFIFOW(fd,0);
  12628. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12629. if(!hom_is_active(sd->hd))
  12630. return;
  12631. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12632. }
  12633. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12634. /// 0292
  12635. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12636. {
  12637. short item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  12638. uint8 hp = 100, sp = 100;
  12639. if (item_position < 0) {
  12640. if (sd->sc.data[SC_LIGHT_OF_REGENE]) {
  12641. // HP restored
  12642. hp = sd->sc.data[SC_LIGHT_OF_REGENE]->val2;
  12643. sp = 0;
  12644. }
  12645. else
  12646. return;
  12647. }
  12648. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  12649. return;
  12650. if (!status_revive(&sd->bl, hp, sp))
  12651. return;
  12652. if (item_position < 0)
  12653. status_change_end(&sd->bl, SC_LIGHT_OF_REGENE, INVALID_TIMER);
  12654. else
  12655. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  12656. clif_skill_nodamage(&sd->bl, &sd->bl, ALL_RESURRECTION, 4, 1);
  12657. }
  12658. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12659. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12660. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12661. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12662. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12663. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12664. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12665. void clif_check(int fd, struct map_session_data* pl_sd)
  12666. {
  12667. WFIFOHEAD(fd,packet_len(0x214));
  12668. WFIFOW(fd, 0) = 0x214;
  12669. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12670. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12671. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12672. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12673. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12674. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12675. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12676. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12677. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12678. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12679. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12680. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12681. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12682. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12683. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12684. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12685. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12686. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12687. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12688. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12689. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12690. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12691. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12692. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12693. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12694. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12695. WFIFOSET(fd,packet_len(0x214));
  12696. }
  12697. /// /check (CZ_REQ_STATUS_GM).
  12698. /// Request character's status values.
  12699. /// 0213 <char name>.24B
  12700. void clif_parse_Check(int fd, struct map_session_data *sd)
  12701. {
  12702. char charname[NAME_LENGTH];
  12703. struct map_session_data* pl_sd;
  12704. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12705. return;
  12706. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12707. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12708. {
  12709. return;
  12710. }
  12711. clif_check(fd, pl_sd);
  12712. }
  12713. /// MAIL SYSTEM
  12714. /// By Zephyrus
  12715. ///
  12716. /// Notification about the result of adding an item to mail
  12717. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  12718. /// result:
  12719. /// 0 = success
  12720. /// 1 = failure
  12721. /// 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)
  12722. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  12723. /// result:
  12724. /// 0 = success
  12725. /// 1 = over weight
  12726. /// 2 = fatal error
  12727. void clif_Mail_setattachment(struct map_session_data* sd, int index, int amount, uint8 flag)
  12728. {
  12729. int fd = sd->fd;
  12730. #if PACKETVER < 20150513
  12731. WFIFOHEAD(fd,packet_len(0x255));
  12732. WFIFOW(fd,0) = 0x255;
  12733. WFIFOW(fd,2) = index;
  12734. WFIFOB(fd,4) = flag;
  12735. WFIFOSET(fd,packet_len(0x255));
  12736. #else
  12737. struct item* item = &sd->inventory.u.items_inventory[index-2];
  12738. int i, total = 0;
  12739. WFIFOHEAD(fd, 53);
  12740. WFIFOW(fd, 0) = 0xa05;
  12741. WFIFOB(fd, 2) = flag;
  12742. WFIFOW(fd, 3) = index;
  12743. WFIFOW(fd, 5) = amount;
  12744. WFIFOW(fd, 7) = item->nameid;
  12745. WFIFOB(fd, 9) = itemtype(item->nameid);
  12746. WFIFOB(fd, 10) = item->identify;
  12747. WFIFOB(fd, 11) = item->attribute;
  12748. WFIFOB(fd, 12) = item->refine;
  12749. clif_addcards(WFIFOP(fd,13), item);
  12750. clif_add_random_options(WFIFOP(fd,21), item);
  12751. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  12752. if( sd->mail.item[i].nameid == 0 ){
  12753. break;
  12754. }
  12755. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  12756. }
  12757. WFIFOW(fd, 46) = total;
  12758. // 5 empty unknown bytes
  12759. memset(WFIFOP(fd, 48), 0, 5);
  12760. WFIFOSET(fd, 53);
  12761. #endif
  12762. }
  12763. /// Notification about the result of retrieving a mail attachment
  12764. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  12765. /// result:
  12766. /// 0 = success
  12767. /// 1 = failure
  12768. /// 2 = too many items
  12769. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  12770. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  12771. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  12772. int fd = sd->fd;
  12773. #if PACKETVER < 20150513
  12774. WFIFOHEAD(fd,packet_len(0x245));
  12775. WFIFOW(fd,0) = 0x245;
  12776. WFIFOB(fd,2) = result;
  12777. WFIFOSET(fd,packet_len(0x245));
  12778. #else
  12779. switch( type ){
  12780. case MAIL_ATT_ITEM:
  12781. case MAIL_ATT_ZENY:
  12782. break;
  12783. default:
  12784. return;
  12785. }
  12786. WFIFOHEAD(fd, 12);
  12787. WFIFOW(fd, 0) = type == MAIL_ATT_ZENY ? 0x9f2 : 0x9f4;
  12788. WFIFOQ(fd, 2) = msg->id;
  12789. WFIFOB(fd, 10) = msg->type;
  12790. WFIFOB(fd, 11) = result;
  12791. WFIFOSET(fd, 12);
  12792. clif_Mail_refreshinbox( sd, msg->type, 0 );
  12793. #endif
  12794. }
  12795. /// Notification about the result of sending a mail
  12796. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  12797. /// result:
  12798. /// 0 = success
  12799. /// 1 = recipinent does not exist
  12800. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  12801. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  12802. int fd = sd->fd;
  12803. #if PACKETVER < 20150513
  12804. WFIFOHEAD(fd,packet_len(0x249));
  12805. WFIFOW(fd,0) = 0x249;
  12806. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  12807. WFIFOSET(fd,packet_len(0x249));
  12808. #else
  12809. WFIFOHEAD(fd, 3);
  12810. WFIFOW(fd, 0) = 0x9ed;
  12811. WFIFOB(fd, 2) = result;
  12812. WFIFOSET(fd, 3);
  12813. #endif
  12814. }
  12815. /// Notification about the result of deleting a mail.
  12816. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  12817. /// result:
  12818. /// 0 = success
  12819. /// 1 = failure
  12820. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  12821. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  12822. int fd = sd->fd;
  12823. #if PACKETVER < 20150513
  12824. WFIFOHEAD(fd, packet_len(0x257));
  12825. WFIFOW(fd,0) = 0x257;
  12826. WFIFOL(fd,2) = msg->id;
  12827. WFIFOW(fd,6) = !success;
  12828. WFIFOSET(fd, packet_len(0x257));
  12829. #else
  12830. // This is only a success notification
  12831. if( success ){
  12832. WFIFOHEAD(fd, 11);
  12833. WFIFOW(fd, 0) = 0x9f6;
  12834. WFIFOB(fd, 2) = msg->type;
  12835. WFIFOQ(fd, 3) = msg->id;
  12836. WFIFOSET(fd, 11);
  12837. }
  12838. #endif
  12839. }
  12840. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12841. /// 0274 <mail id>.L <result>.W
  12842. /// result:
  12843. /// 0 = success
  12844. /// 1 = failure
  12845. void clif_Mail_return(int fd, int mail_id, short fail)
  12846. {
  12847. WFIFOHEAD(fd,packet_len(0x274));
  12848. WFIFOW(fd,0) = 0x274;
  12849. WFIFOL(fd,2) = mail_id;
  12850. WFIFOW(fd,6) = fail;
  12851. WFIFOSET(fd,packet_len(0x274));
  12852. }
  12853. /// Notification about new mail.
  12854. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  12855. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  12856. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  12857. int fd = sd->fd;
  12858. #if PACKETVER < 20150513
  12859. WFIFOHEAD(fd,packet_len(0x24a));
  12860. WFIFOW(fd,0) = 0x24a;
  12861. WFIFOL(fd,2) = mail_id;
  12862. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  12863. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  12864. WFIFOSET(fd,packet_len(0x24a));
  12865. #else
  12866. WFIFOHEAD(fd,3);
  12867. WFIFOW(fd,0) = 0x9e7;
  12868. WFIFOB(fd,2) = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  12869. WFIFOSET(fd,3);
  12870. #endif
  12871. }
  12872. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12873. /// 0260 <type>.L
  12874. /// type:
  12875. /// 0 = open
  12876. /// 1 = close
  12877. void clif_Mail_window(int fd, int flag)
  12878. {
  12879. WFIFOHEAD(fd,packet_len(0x260));
  12880. WFIFOW(fd,0) = 0x260;
  12881. WFIFOL(fd,2) = flag;
  12882. WFIFOSET(fd,packet_len(0x260));
  12883. }
  12884. /// Lists mails stored in inbox.
  12885. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  12886. /// read:
  12887. /// 0 = unread
  12888. /// 1 = read
  12889. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  12890. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12891. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  12892. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12893. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  12894. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  12895. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  12896. #if PACKETVER < 20150513
  12897. int fd = sd->fd;
  12898. struct mail_data *md = &sd->mail.inbox;
  12899. struct mail_message *msg;
  12900. int len, i, j;
  12901. len = 8 + (73 * md->amount);
  12902. WFIFOHEAD(fd,len);
  12903. WFIFOW(fd,0) = 0x240;
  12904. WFIFOW(fd,2) = len;
  12905. WFIFOL(fd,4) = md->amount;
  12906. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12907. {
  12908. msg = &md->msg[i];
  12909. if (msg->id < 1)
  12910. continue;
  12911. WFIFOL(fd,8+73*j) = msg->id;
  12912. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12913. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12914. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12915. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12916. j++;
  12917. }
  12918. WFIFOSET(fd,len);
  12919. if( md->full ) {// TODO: is this official?
  12920. char output[100];
  12921. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12922. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  12923. }
  12924. #else
  12925. int fd = sd->fd;
  12926. struct mail_data *md = &sd->mail.inbox;
  12927. struct mail_message *msg;
  12928. int i, j, k, offset, titleLength;
  12929. uint8 mailType, amount, remaining;
  12930. uint32 now = (uint32)time(NULL);
  12931. #if PACKETVER >= 20170419
  12932. int cmd = 0xac2;
  12933. #elif PACKETVER >= 20160601
  12934. int cmd = 0xa7d;
  12935. #else
  12936. int cmd = 0x9f0;
  12937. #endif
  12938. if( battle_config.mail_daily_count ){
  12939. mail_refresh_remaining_amount(sd);
  12940. }
  12941. #if PACKETVER >= 20170419
  12942. // Always send all
  12943. i = md->amount;
  12944. #else
  12945. // If a starting mail id was sent
  12946. if( mailID != 0 ){
  12947. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  12948. // Unknown mail
  12949. if( i == md->amount ){
  12950. // Ignore the request for now
  12951. return; // TODO: Should we just show the first page instead?
  12952. }
  12953. // It was actually the oldest/first mail, there is no further page
  12954. if( i == 0 ){
  12955. return;
  12956. }
  12957. // We actually want the next/older mail
  12958. i -= 1;
  12959. }else{
  12960. i = md->amount;
  12961. }
  12962. #endif
  12963. // Count the remaining mails from the starting mail or the beginning
  12964. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  12965. for( j = i, remaining = 0; j >= 0; j-- ){
  12966. msg = &md->msg[j];
  12967. if (msg->id < 1)
  12968. continue;
  12969. #if PACKETVER < 20170419
  12970. if (msg->type != type)
  12971. continue;
  12972. #endif
  12973. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  12974. continue;
  12975. remaining++;
  12976. }
  12977. #if PACKETVER >= 20170419
  12978. // Always send all
  12979. amount = remaining;
  12980. #else
  12981. if( remaining > MAIL_PAGE_SIZE ){
  12982. amount = MAIL_PAGE_SIZE;
  12983. }else{
  12984. amount = remaining;
  12985. }
  12986. #endif
  12987. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  12988. WFIFOW(fd, 0) = cmd;
  12989. #if PACKETVER >= 20170419
  12990. WFIFOB(fd, 4) = 1; // Unknown
  12991. offset = 5;
  12992. #else
  12993. WFIFOB(fd, 4) = type;
  12994. WFIFOB(fd, 5) = amount;
  12995. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  12996. offset = 7;
  12997. #endif
  12998. for( amount = 0; i >= 0; i-- ){
  12999. msg = &md->msg[i];
  13000. if (msg->id < 1)
  13001. continue;
  13002. #if PACKETVER < 20170419
  13003. if (msg->type != type)
  13004. continue;
  13005. #endif
  13006. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  13007. continue;
  13008. #if PACKETVER >= 20170419
  13009. WFIFOB(fd, offset) = msg->type;
  13010. offset += 1;
  13011. #endif
  13012. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13013. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13014. mailType = MAIL_TYPE_TEXT; // Normal letter
  13015. if( msg->zeny > 0 ){
  13016. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13017. }
  13018. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13019. if( msg->item[k].nameid > 0 ){
  13020. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13021. break;
  13022. }
  13023. }
  13024. #if PACKETVER >= 20170419
  13025. // If it came from an npc?
  13026. if( !msg->send_id ){
  13027. mailType |= MAIL_TYPE_NPC;
  13028. }
  13029. #endif
  13030. WFIFOB(fd, offset + 9) = mailType;
  13031. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13032. #if PACKETVER < 20170419
  13033. // How much time has passed since you received the mail
  13034. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13035. offset += 4;
  13036. #endif
  13037. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13038. if( msg->scheduled_deletion > 0 ){
  13039. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13040. }else{
  13041. // Fake the scheduled deletion to one year in the future
  13042. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13043. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13044. }
  13045. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13046. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13047. offset += 40 + titleLength;
  13048. }
  13049. WFIFOW(fd, 2) = (int16)offset;
  13050. WFIFOSET(fd, offset);
  13051. #endif
  13052. }
  13053. /// Mail inbox list request.
  13054. /// 023f (CZ_MAIL_GET_LIST)
  13055. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13056. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13057. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13058. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13059. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13060. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  13061. #if PACKETVER < 20150513
  13062. struct mail_data* md = &sd->mail.inbox;
  13063. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13064. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13065. else
  13066. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13067. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13068. mail_removezeny(sd, false);
  13069. #else
  13070. int cmd = RFIFOW(fd, 0);
  13071. #if PACKETVER < 20170419
  13072. uint8 openType = RFIFOB(fd, 2);
  13073. uint64 mailId = RFIFOQ(fd, 3);
  13074. #else
  13075. uint8 openType;
  13076. uint64 mailId = RFIFOQ(fd, 2);
  13077. int i;
  13078. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13079. if( i == MAIL_MAX_INBOX ){
  13080. openType = MAIL_INBOX_NORMAL;
  13081. mailId = 0;
  13082. }else{
  13083. openType = sd->mail.inbox.msg[i].type;
  13084. mailId = 0;
  13085. }
  13086. #endif
  13087. switch( openType ){
  13088. case MAIL_INBOX_NORMAL:
  13089. case MAIL_INBOX_ACCOUNT:
  13090. case MAIL_INBOX_RETURNED:
  13091. break;
  13092. default:
  13093. // Unknown type: ignore request
  13094. return;
  13095. }
  13096. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13097. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13098. return;
  13099. }
  13100. // If it is not a next page request
  13101. if( cmd != 0x9ee ){
  13102. mailId = 0;
  13103. }
  13104. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13105. #endif
  13106. }
  13107. /// Opens a mail
  13108. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13109. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13110. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13111. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13112. /// { }*n
  13113. // TODO: Packet description => for repeated block
  13114. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  13115. {
  13116. int i, fd = sd->fd;
  13117. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13118. if( i == MAIL_MAX_INBOX ) {
  13119. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13120. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13121. return;
  13122. } else {
  13123. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13124. struct item *item;
  13125. struct item_data *data;
  13126. int msg_len = strlen(msg->body), len;
  13127. #if PACKETVER >= 20150513
  13128. int offset, j, itemsize, count = 0;
  13129. #endif
  13130. if( msg_len == 0 ) {
  13131. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13132. msg_len = strlen(msg->body);
  13133. }
  13134. #if PACKETVER < 20150513
  13135. item = &msg->item[0];
  13136. len = 101 + msg_len;
  13137. WFIFOHEAD(fd,len);
  13138. WFIFOW(fd,0) = 0x242;
  13139. WFIFOW(fd,2) = len;
  13140. WFIFOL(fd,4) = msg->id;
  13141. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13142. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13143. WFIFOL(fd,72) = 0;
  13144. WFIFOL(fd,76) = msg->zeny;
  13145. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  13146. WFIFOL(fd,80) = item->amount;
  13147. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  13148. WFIFOW(fd,86) = data->type;
  13149. WFIFOB(fd,88) = item->identify;
  13150. WFIFOB(fd,89) = item->attribute;
  13151. WFIFOB(fd,90) = item->refine;
  13152. WFIFOW(fd,91) = item->card[0];
  13153. WFIFOW(fd,93) = item->card[1];
  13154. WFIFOW(fd,95) = item->card[2];
  13155. WFIFOW(fd,97) = item->card[3];
  13156. } else // no item, set all to zero
  13157. memset(WFIFOP(fd,80), 0x00, 19);
  13158. WFIFOB(fd,99) = (unsigned char)msg_len;
  13159. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13160. WFIFOSET(fd,len);
  13161. #else
  13162. // Count the attached items
  13163. ARR_FIND( 0, MAIL_MAX_ITEM, count, msg->item[count].nameid == 0 );
  13164. msg_len += 1; // Zero Termination
  13165. itemsize = 24 + 5 * 5;
  13166. len = 24 + msg_len+1 + itemsize * count;
  13167. WFIFOHEAD(fd, len);
  13168. WFIFOW(fd, 0) = 0x9eb;
  13169. WFIFOW(fd, 2) = len;
  13170. WFIFOB(fd, 4) = msg->type;
  13171. WFIFOQ(fd, 5) = msg->id;
  13172. WFIFOW(fd, 13) = msg_len;
  13173. WFIFOQ(fd, 15) = msg->zeny;
  13174. WFIFOB(fd, 23) = (uint8)count; // item count
  13175. safestrncpy(WFIFOCP(fd, 24), msg->body, msg_len);
  13176. offset = 24 + msg_len;
  13177. for (j = 0; j < MAIL_MAX_ITEM; j++) {
  13178. item = &msg->item[j];
  13179. if (item->nameid > 0 && item->amount > 0 && (data = itemdb_exists(item->nameid)) != NULL) {
  13180. WFIFOW(fd, offset) = item->amount;
  13181. WFIFOW(fd, offset + 2) = (data->view_id) ? data->view_id : item->nameid;
  13182. WFIFOB(fd, offset + 4) = item->identify;
  13183. WFIFOB(fd, offset + 5) = item->attribute;
  13184. WFIFOB(fd, offset + 6) = item->refine;
  13185. clif_addcards(WFIFOP(fd, offset + 7), item);
  13186. // 4B unsigned long location
  13187. WFIFOB(fd, offset + 15 + 4) = data->type;
  13188. // 2B unsigned short wItemSpriteNumber
  13189. //WFIFOW(fd, offset + 15 + 5) = data->view_id;
  13190. // 2B unsigned short bindOnEquipType
  13191. clif_add_random_options(WFIFOP(fd, offset + 15 + 9 ), item);
  13192. offset += itemsize;
  13193. }
  13194. }
  13195. WFIFOSET(fd, len);
  13196. #endif
  13197. if (msg->status == MAIL_UNREAD) {
  13198. msg->status = MAIL_READ;
  13199. intif_Mail_read(mail_id);
  13200. clif_parse_Mail_refreshinbox(fd, sd);
  13201. sd->mail.inbox.unread--;
  13202. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13203. }
  13204. }
  13205. }
  13206. /// Request to open a mail.
  13207. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13208. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13209. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13210. #if PACKETVER < 20150513
  13211. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13212. #else
  13213. //uint8 openType = RFIFOB(fd, 2);
  13214. int mail_id = (int)RFIFOQ(fd, 3);
  13215. #endif
  13216. if( mail_id <= 0 )
  13217. return;
  13218. if( mail_invalid_operation(sd) )
  13219. return;
  13220. clif_Mail_read(sd, mail_id);
  13221. }
  13222. /// Allow a player to begin writing a mail
  13223. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13224. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13225. int fd = sd->fd;
  13226. WFIFOHEAD(fd, 27);
  13227. WFIFOW(fd, 0) = 0xa12;
  13228. safestrncpy(WFIFOCP(fd, 2), name, NAME_LENGTH);
  13229. WFIFOB(fd, 26) = success;
  13230. WFIFOSET(fd, 27);
  13231. }
  13232. /// Request to start writing a mail
  13233. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13234. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13235. char name[NAME_LENGTH];
  13236. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13237. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13238. clif_send_Mail_beginwrite_ack(sd, name, false);
  13239. return;
  13240. }
  13241. mail_clear(sd);
  13242. sd->state.mail_writing = true;
  13243. clif_send_Mail_beginwrite_ack(sd, name,true);
  13244. }
  13245. /// Notification that the client cancelled writing a mail
  13246. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13247. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13248. sd->state.mail_writing = false;
  13249. }
  13250. /// Give the client information about the recipient, if available
  13251. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13252. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13253. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13254. int fd = sd->fd;
  13255. #if PACKETVER <= 20160302
  13256. int cmd = 0xa14;
  13257. #else
  13258. int cmd = 0xa51;
  13259. #endif
  13260. WFIFOHEAD(fd, packet_len(cmd));
  13261. WFIFOW(fd, 0) = cmd;
  13262. WFIFOL(fd, 2) = char_id;
  13263. WFIFOW(fd, 6) = class_;
  13264. WFIFOW(fd, 8) = level;
  13265. #if PACKETVER >= 20160302
  13266. strncpy(WFIFOCP(fd, 10), name, NAME_LENGTH);
  13267. #endif
  13268. WFIFOSET(fd, packet_len(cmd));
  13269. }
  13270. /// Request information about the recipient
  13271. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13272. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13273. static char name[NAME_LENGTH];
  13274. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13275. intif_mail_checkreceiver(sd, name);
  13276. }
  13277. /// Request to receive mail's attachment.
  13278. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13279. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13280. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13281. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13282. int i;
  13283. struct mail_message* msg;
  13284. #if PACKETVER < 20150513
  13285. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13286. int attachment = MAIL_ATT_ALL;
  13287. #else
  13288. uint16 packet_id = RFIFOW(fd, 0);
  13289. int mail_id = (int)RFIFOQ(fd, 2);
  13290. //int openType = RFIFOB(fd, 10);
  13291. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13292. #endif
  13293. if( !chrif_isconnected() )
  13294. return;
  13295. if( mail_id <= 0 )
  13296. return;
  13297. if( mail_invalid_operation(sd) )
  13298. return;
  13299. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13300. if( i == MAIL_MAX_INBOX )
  13301. return;
  13302. msg = &sd->mail.inbox.msg[i];
  13303. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13304. attachment &= ~MAIL_ATT_ZENY;
  13305. }
  13306. if( attachment&MAIL_ATT_ITEM ){
  13307. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13308. // No items were found
  13309. if( i == MAIL_MAX_ITEM ){
  13310. attachment &= ~MAIL_ATT_ITEM;
  13311. }
  13312. }
  13313. // Either no attachment requested at all or there are no zeny or items in the mail
  13314. if( attachment == MAIL_ATT_NONE ){
  13315. return;
  13316. }
  13317. if( attachment&MAIL_ATT_ZENY ){
  13318. if( msg->zeny + sd->status.zeny > MAX_ZENY ){
  13319. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13320. return;
  13321. }else{
  13322. // To make sure another request fails
  13323. msg->zeny = 0;
  13324. }
  13325. }
  13326. if( attachment&MAIL_ATT_ITEM ){
  13327. int new_ = 0, totalweight = 0;
  13328. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13329. struct item* item = &msg->item[i];
  13330. if( item->nameid > 0 && item->amount > 0 ){
  13331. struct item_data *data;
  13332. if((data = itemdb_exists(item->nameid)) == NULL)
  13333. continue;
  13334. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13335. case CHKADDITEM_NEW:
  13336. new_++;
  13337. break;
  13338. case CHKADDITEM_OVERAMOUNT:
  13339. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13340. return;
  13341. }
  13342. totalweight += data->weight * item->amount;
  13343. }
  13344. }
  13345. if( ( totalweight + sd->weight ) > sd->max_weight ){
  13346. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13347. return;
  13348. }else if( pc_inventoryblank(sd) < new_ ){
  13349. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13350. return;
  13351. }
  13352. // To make sure another request fails
  13353. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13354. }
  13355. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13356. clif_Mail_read(sd, mail_id);
  13357. }
  13358. /// Request to delete a mail.
  13359. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13360. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13361. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13362. #if PACKETVER < 20150513
  13363. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13364. #else
  13365. //int openType = RFIFOB(fd, 2);
  13366. int mail_id = (int)RFIFOQ(fd, 3);
  13367. #endif
  13368. int i, j;
  13369. if( !chrif_isconnected() )
  13370. return;
  13371. if( mail_id <= 0 )
  13372. return;
  13373. if( mail_invalid_operation(sd) )
  13374. return;
  13375. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13376. if (i < MAIL_MAX_INBOX) {
  13377. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13378. // can't delete mail without removing zeny first
  13379. if( msg->zeny > 0 ){
  13380. clif_mail_delete(sd, msg, false);
  13381. return;
  13382. }
  13383. // can't delete mail without removing attachment(s) first
  13384. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13385. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13386. clif_mail_delete(sd, msg, false);
  13387. return;
  13388. }
  13389. }
  13390. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13391. sd->mail.inbox.unread--;
  13392. clif_Mail_new(sd,0,NULL,NULL);
  13393. }
  13394. }
  13395. }
  13396. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13397. /// 0273 <mail id>.L <receive name>.24B
  13398. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13399. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13400. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13401. int i;
  13402. if( mail_id <= 0 )
  13403. return;
  13404. if( mail_invalid_operation(sd) )
  13405. return;
  13406. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13407. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13408. intif_Mail_return(sd->status.char_id, mail_id);
  13409. else
  13410. clif_Mail_return(sd->fd, mail_id, 1);
  13411. }
  13412. /// Request to add an item or Zeny to mail.
  13413. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13414. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13415. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13416. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13417. int idx = RFIFOW(fd,info->pos[0]);
  13418. #if PACKETVER < 20150513
  13419. int amount = RFIFOL(fd,info->pos[1]);
  13420. #else
  13421. int amount = RFIFOW(fd,info->pos[1]);
  13422. #endif
  13423. unsigned char flag;
  13424. if( !chrif_isconnected() )
  13425. return;
  13426. if (idx < 0 || amount < 0)
  13427. return;
  13428. flag = mail_setitem(sd, idx, amount);
  13429. clif_Mail_setattachment(sd,idx,amount,flag);
  13430. }
  13431. /// Remove an item from a mail
  13432. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13433. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13434. int fd = sd->fd;
  13435. WFIFOHEAD(fd, 9);
  13436. WFIFOW(fd, 0) = 0xa07;
  13437. WFIFOB(fd, 2) = success;
  13438. WFIFOW(fd, 3) = index;
  13439. WFIFOW(fd, 5) = amount;
  13440. WFIFOW(fd, 7) = 0; // TODO: which weight? item weight? removed weight? remaining weight?
  13441. WFIFOSET(fd, 9);
  13442. }
  13443. /// Request to reset mail item and/or Zeny
  13444. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13445. /// type:
  13446. /// 0 = reset all
  13447. /// 1 = remove item
  13448. /// 2 = remove zeny
  13449. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13450. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13451. {
  13452. #if PACKETVER < 20150513
  13453. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13454. if (type == 0 || type == 1)
  13455. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13456. if (type == 0 || type == 2)
  13457. mail_removezeny(sd, false);
  13458. #else
  13459. uint16 index = RFIFOW(fd, 2);
  13460. uint16 count = RFIFOW(fd, 4);
  13461. mail_removeitem(sd,0,index,count);
  13462. #endif
  13463. }
  13464. /// Request to send mail
  13465. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13466. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13467. /// 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)
  13468. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  13469. #if PACKETVER < 20150513
  13470. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13471. if( !chrif_isconnected() )
  13472. return;
  13473. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13474. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13475. return;
  13476. }
  13477. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13478. #else
  13479. unsigned short length;
  13480. static char receiver[NAME_LENGTH];
  13481. static char sender[NAME_LENGTH];
  13482. char *title;
  13483. char *text;
  13484. uint64 zeny;
  13485. uint16 titleLength;
  13486. uint16 textLength;
  13487. length = RFIFOW(fd, 2);
  13488. if( length < 0x3e ){
  13489. ShowWarning("Too short...\n");
  13490. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13491. return;
  13492. }
  13493. // Forged request without a begin writing packet?
  13494. if( !sd->state.mail_writing ){
  13495. return; // Ignore it
  13496. }
  13497. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13498. safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13499. zeny = RFIFOQ(fd, 52);
  13500. titleLength = RFIFOW(fd, 60);
  13501. textLength = RFIFOW(fd, 62);
  13502. title = (char*)aMalloc(titleLength);
  13503. text = (char*)aMalloc(textLength);
  13504. #if PACKETVER <= 20160330
  13505. safestrncpy(title, RFIFOCP(fd, 64), titleLength);
  13506. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), textLength);
  13507. #else
  13508. // 64 = <char id>.L
  13509. safestrncpy(title, RFIFOCP(fd, 68), titleLength);
  13510. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), textLength);
  13511. #endif
  13512. if( zeny > 0 ){
  13513. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13514. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13515. return;
  13516. }
  13517. }
  13518. mail_send(sd, receiver, title, text, textLength);
  13519. aFree(title);
  13520. aFree(text);
  13521. #endif
  13522. }
  13523. /// AUCTION SYSTEM
  13524. /// By Zephyrus
  13525. ///
  13526. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13527. /// 025f <type>.L
  13528. /// type:
  13529. /// 0 = open
  13530. /// 1 = close
  13531. void clif_Auction_openwindow(struct map_session_data *sd)
  13532. {
  13533. int fd = sd->fd;
  13534. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13535. return;
  13536. if( !battle_config.feature_auction )
  13537. return;
  13538. WFIFOHEAD(fd,packet_len(0x25f));
  13539. WFIFOW(fd,0) = 0x25f;
  13540. WFIFOL(fd,2) = 0;
  13541. WFIFOSET(fd,packet_len(0x25f));
  13542. }
  13543. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13544. /// 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 }*
  13545. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  13546. {
  13547. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13548. struct auction_data auction;
  13549. struct item_data *item;
  13550. WFIFOHEAD(fd,12 + (count * 83));
  13551. WFIFOW(fd,0) = 0x252;
  13552. WFIFOW(fd,2) = 12 + (count * 83);
  13553. WFIFOL(fd,4) = pages;
  13554. WFIFOL(fd,8) = count;
  13555. for( i = 0; i < count; i++ ) {
  13556. int k = 12 + (i * 83);
  13557. memcpy(&auction, RBUFP(buf,i * len), len);
  13558. WFIFOL(fd,k) = auction.auction_id;
  13559. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13560. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  13561. WFIFOW(fd,28+k) = item->view_id;
  13562. else
  13563. WFIFOW(fd,28+k) = auction.item.nameid;
  13564. WFIFOL(fd,30+k) = auction.type;
  13565. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13566. WFIFOB(fd,36+k) = auction.item.identify;
  13567. WFIFOB(fd,37+k) = auction.item.attribute;
  13568. WFIFOB(fd,38+k) = auction.item.refine;
  13569. WFIFOW(fd,39+k) = auction.item.card[0];
  13570. WFIFOW(fd,41+k) = auction.item.card[1];
  13571. WFIFOW(fd,43+k) = auction.item.card[2];
  13572. WFIFOW(fd,45+k) = auction.item.card[3];
  13573. WFIFOL(fd,47+k) = auction.price;
  13574. WFIFOL(fd,51+k) = auction.buynow;
  13575. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13576. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13577. }
  13578. WFIFOSET(fd,WFIFOW(fd,2));
  13579. }
  13580. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13581. /// 0256 <index>.W <result>.B
  13582. /// result:
  13583. /// 0 = success
  13584. /// 1 = failure
  13585. static void clif_Auction_setitem(int fd, int index, bool fail)
  13586. {
  13587. WFIFOHEAD(fd,packet_len(0x256));
  13588. WFIFOW(fd,0) = 0x256;
  13589. WFIFOW(fd,2) = index;
  13590. WFIFOB(fd,4) = fail;
  13591. WFIFOSET(fd,packet_len(0x256));
  13592. }
  13593. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13594. /// 024b <type>.W
  13595. /// type:
  13596. /// 0 = create (any other action in auction window)
  13597. /// 1 = cancel (cancel pressed on register tab)
  13598. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13599. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  13600. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13601. if( sd->auction.amount > 0 )
  13602. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13603. sd->auction.amount = 0;
  13604. }
  13605. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13606. /// 024c <index>.W <count>.L
  13607. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  13608. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13609. int idx = RFIFOW(fd,info->pos[0]) - 2;
  13610. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  13611. struct item_data *item;
  13612. if( !battle_config.feature_auction )
  13613. return;
  13614. if( sd->auction.amount > 0 )
  13615. sd->auction.amount = 0;
  13616. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13617. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13618. return;
  13619. }
  13620. 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.
  13621. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13622. return;
  13623. }
  13624. 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) )
  13625. { // Consumable or pets are not allowed
  13626. clif_Auction_setitem(sd->fd, idx, true);
  13627. return;
  13628. }
  13629. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13630. !sd->inventory.u.items_inventory[idx].identify ||
  13631. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13632. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13633. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13634. clif_Auction_setitem(sd->fd, idx, true);
  13635. return;
  13636. }
  13637. sd->auction.index = idx;
  13638. sd->auction.amount = amount;
  13639. clif_Auction_setitem(fd, idx + 2, false);
  13640. }
  13641. /// Result from an auction action (ZC_AUCTION_RESULT).
  13642. /// 0250 <result>.B
  13643. /// result:
  13644. /// 0 = You have failed to bid into the auction
  13645. /// 1 = You have successfully bid in the auction
  13646. /// 2 = The auction has been canceled
  13647. /// 3 = An auction with at least one bidder cannot be canceled
  13648. /// 4 = You cannot register more than 5 items in an auction at a time
  13649. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13650. /// 6 = You have won the auction
  13651. /// 7 = You have failed to win the auction
  13652. /// 8 = You do not have enough Zeny
  13653. /// 9 = You cannot place more than 5 bids at a time
  13654. void clif_Auction_message(int fd, unsigned char flag)
  13655. {
  13656. WFIFOHEAD(fd,packet_len(0x250));
  13657. WFIFOW(fd,0) = 0x250;
  13658. WFIFOB(fd,2) = flag;
  13659. WFIFOSET(fd,packet_len(0x250));
  13660. }
  13661. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13662. /// 025e <result>.W
  13663. /// result:
  13664. /// 0 = You have ended the auction
  13665. /// 1 = You cannot end the auction
  13666. /// 2 = Auction ID is incorrect
  13667. void clif_Auction_close(int fd, unsigned char flag)
  13668. {
  13669. WFIFOHEAD(fd,packet_len(0x25e));
  13670. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13671. WFIFOW(fd,2) = flag;
  13672. WFIFOSET(fd,packet_len(0x25e));
  13673. }
  13674. /// Request to add an auction (CZ_AUCTION_ADD).
  13675. /// 024d <now money>.L <max money>.L <delete hour>.W
  13676. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  13677. {
  13678. struct auction_data auction;
  13679. struct item_data *item;
  13680. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13681. if( !battle_config.feature_auction )
  13682. return;
  13683. auction.price = RFIFOL(fd,info->pos[0]);
  13684. auction.buynow = RFIFOL(fd,info->pos[1]);
  13685. auction.hours = RFIFOW(fd,info->pos[2]);
  13686. // Invalid Situations...
  13687. if( sd->auction.amount < 1 ) {
  13688. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  13689. return;
  13690. }
  13691. if( auction.price >= auction.buynow ) {
  13692. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  13693. return;
  13694. }
  13695. if( auction.hours < 1 || auction.hours > 48 ) {
  13696. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  13697. return;
  13698. }
  13699. // Auction checks...
  13700. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  13701. clif_displaymessage(sd->fd, msg_txt(sd,293));
  13702. clif_Auction_message(fd, 2); // The auction has been canceled
  13703. return;
  13704. }
  13705. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  13706. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  13707. return;
  13708. }
  13709. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  13710. auction.buynow = battle_config.auction_maximumprice;
  13711. if( auction.price >= auction.buynow )
  13712. auction.price = auction.buynow - 1;
  13713. }
  13714. auction.auction_id = 0;
  13715. auction.seller_id = sd->status.char_id;
  13716. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  13717. auction.buyer_id = 0;
  13718. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  13719. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  13720. {
  13721. clif_Auction_message(fd, 2); // The auction has been canceled
  13722. return;
  13723. }
  13724. if( (item = itemdb_exists(sd->inventory.u.items_inventory[sd->auction.index].nameid)) == NULL )
  13725. { // Just in case
  13726. clif_Auction_message(fd, 2); // The auction has been canceled
  13727. return;
  13728. }
  13729. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  13730. auction.type = item->type;
  13731. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  13732. auction.item.amount = 1;
  13733. auction.timestamp = 0;
  13734. if( !intif_Auction_register(&auction) )
  13735. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  13736. else
  13737. {
  13738. int zeny = auction.hours*battle_config.auction_feeperhour;
  13739. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  13740. sd->auction.amount = 0;
  13741. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  13742. }
  13743. }
  13744. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  13745. /// 024e <auction id>.L
  13746. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  13747. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13748. intif_Auction_cancel(sd->status.char_id, auction_id);
  13749. }
  13750. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  13751. /// 025d <auction id>.L
  13752. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  13753. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13754. intif_Auction_close(sd->status.char_id, auction_id);
  13755. }
  13756. /// Places a bid on an auction (CZ_AUCTION_BUY).
  13757. /// 024f <auction id>.L <money>.L
  13758. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  13759. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13760. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  13761. int bid = RFIFOL(fd,info->pos[1]);
  13762. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  13763. clif_displaymessage(sd->fd, msg_txt(sd,246));
  13764. return;
  13765. }
  13766. if( bid <= 0 )
  13767. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13768. else if( bid > sd->status.zeny )
  13769. clif_Auction_message(fd, 8); // You do not have enough zeny
  13770. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  13771. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13772. else {
  13773. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  13774. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  13775. }
  13776. }
  13777. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  13778. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  13779. /// search type:
  13780. /// 0 = armor
  13781. /// 1 = weapon
  13782. /// 2 = card
  13783. /// 3 = misc
  13784. /// 4 = name search
  13785. /// 5 = auction id search
  13786. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  13787. char search_text[NAME_LENGTH];
  13788. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13789. short type = RFIFOW(fd,info->pos[0]);
  13790. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  13791. int page = RFIFOW(fd,info->pos[3]);
  13792. if( !battle_config.feature_auction )
  13793. return;
  13794. clif_parse_Auction_cancelreg(fd, sd);
  13795. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  13796. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  13797. }
  13798. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  13799. /// 025c <type>.W
  13800. /// type:
  13801. /// 0 = sell (own auctions)
  13802. /// 1 = buy (own bids)
  13803. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  13804. {
  13805. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  13806. if( !battle_config.feature_auction )
  13807. return;
  13808. clif_parse_Auction_cancelreg(fd, sd);
  13809. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  13810. }
  13811. /// CASH/POINT SHOP
  13812. ///
  13813. void clif_cashshop_open( struct map_session_data* sd ){
  13814. WFIFOHEAD( sd->fd, 10 );
  13815. WFIFOW( sd->fd, 0 ) = 0x845;
  13816. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  13817. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  13818. WFIFOSET( sd->fd, 10 );
  13819. }
  13820. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13821. sd->state.cashshop_open = true;
  13822. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13823. clif_cashshop_open( sd );
  13824. }
  13825. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  13826. sd->state.cashshop_open = false;
  13827. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13828. // No need to do anything here
  13829. }
  13830. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  13831. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  13832. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  13833. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  13834. int j;
  13835. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  13836. return;
  13837. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  13838. WFIFOW(fd, 0) = 0x8c0;
  13839. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  13840. WFIFOL(fd, 4) = tab;
  13841. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  13842. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  13843. struct item_data *id = itemdb_search(cash_shop_items[tab].item[j]->nameid);
  13844. WFIFOW(fd, 10 + ( 6 * j ) ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[j]->nameid;
  13845. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  13846. }
  13847. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  13848. }
  13849. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  13850. void clif_cashshop_list( int fd ){
  13851. int tab;
  13852. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  13853. int length = 8 + cash_shop_items[tab].count * 6;
  13854. int i, offset;
  13855. WFIFOHEAD( fd, length );
  13856. WFIFOW( fd, 0 ) = 0x8ca;
  13857. WFIFOW( fd, 2 ) = length;
  13858. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  13859. WFIFOW( fd, 6 ) = tab;
  13860. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  13861. struct item_data *id = itemdb_search(cash_shop_items[tab].item[i]->nameid);
  13862. WFIFOW( fd, offset ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[i]->nameid;
  13863. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  13864. }
  13865. WFIFOSET( fd, length );
  13866. }
  13867. }
  13868. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  13869. if( !sd->status.cashshop_sent ) {
  13870. clif_cashshop_list( fd );
  13871. #if PACKETVER_SUPPORTS_SALES
  13872. sale_notify_login(sd);
  13873. #endif
  13874. sd->status.cashshop_sent = true;
  13875. }
  13876. }
  13877. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  13878. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  13879. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  13880. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  13881. {
  13882. int fd, i, cost[2] = { 0, 0 };
  13883. #if PACKETVER < 20070711
  13884. const int offset = 8;
  13885. #else
  13886. const int offset = 12;
  13887. #endif
  13888. nullpo_retv(sd);
  13889. nullpo_retv(nd);
  13890. fd = sd->fd;
  13891. sd->npc_shopid = nd->bl.id;
  13892. npc_shop_currency_type(sd, nd, cost, true);
  13893. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  13894. WFIFOW(fd,0) = 0x287;
  13895. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  13896. WFIFOL(fd,4) = cost[0];
  13897. #if PACKETVER >= 20070711
  13898. WFIFOL(fd,8) = cost[1];
  13899. #endif
  13900. for( i = 0; i < nd->u.shop.count; i++ ) {
  13901. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  13902. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  13903. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  13904. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  13905. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  13906. }
  13907. WFIFOSET(fd,WFIFOW(fd,2));
  13908. }
  13909. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  13910. /// 0289 <cash point>.L <error>.W
  13911. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  13912. /// error:
  13913. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  13914. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  13915. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  13916. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  13917. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  13918. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  13919. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  13920. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  13921. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  13922. void clif_cashshop_ack(struct map_session_data* sd, int error)
  13923. {
  13924. int fd, cost[2] = { 0, 0 };
  13925. struct npc_data *nd;
  13926. nullpo_retv(sd);
  13927. fd = sd->fd;
  13928. nd = map_id2nd(sd->npc_shopid);
  13929. npc_shop_currency_type(sd, nd, cost, false);
  13930. WFIFOHEAD(fd, packet_len(0x289));
  13931. WFIFOW(fd,0) = 0x289;
  13932. WFIFOL(fd,2) = cost[0];
  13933. #if PACKETVER < 20070711
  13934. WFIFOW(fd,6) = TOW(error);
  13935. #else
  13936. WFIFOL(fd,6) = cost[1];
  13937. WFIFOW(fd,10) = TOW(error);
  13938. #endif
  13939. WFIFOSET(fd, packet_len(0x289));
  13940. }
  13941. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  13942. WFIFOHEAD( sd->fd, 16 );
  13943. WFIFOW( sd->fd, 0 ) = 0x849;
  13944. WFIFOL( sd->fd, 2 ) = item_id;
  13945. WFIFOW( sd->fd, 6 ) = result;
  13946. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  13947. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  13948. WFIFOSET( sd->fd, 16 );
  13949. }
  13950. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  13951. /// 0288 <name id>.W <amount>.W
  13952. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  13953. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  13954. /// 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)
  13955. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd){
  13956. struct s_packet_db* info;
  13957. int cmd = RFIFOW(fd,0);
  13958. nullpo_retv(sd);
  13959. info = &packet_db[cmd];
  13960. if( sd->state.trading || !sd->npc_shopid ) {
  13961. clif_cashshop_ack(sd,1);
  13962. return;
  13963. }
  13964. else {
  13965. #if PACKETVER < 20101116
  13966. short nameid = RFIFOW(fd,info->pos[0]);
  13967. short amount = RFIFOW(fd,info->pos[1]);
  13968. int points = RFIFOL(fd,info->pos[2]);
  13969. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  13970. #else
  13971. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  13972. int len = RFIFOW(fd,info->pos[0]);
  13973. int points = RFIFOL(fd,info->pos[1]);
  13974. int count = RFIFOW(fd,info->pos[2]);
  13975. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13976. if( len < 10 || len != 10 + count * s_itl){
  13977. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  13978. return;
  13979. }
  13980. if(cmd==0x848){
  13981. if (cashshop_buylist( sd, points, count, item_list))
  13982. clif_cashshop_ack(sd,0);
  13983. return;
  13984. } else {
  13985. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  13986. return;
  13987. }
  13988. #endif
  13989. }
  13990. }
  13991. /// Adoption System
  13992. ///
  13993. /// Adoption message (ZC_BABYMSG).
  13994. /// 0216 <msg>.L
  13995. /// msg:
  13996. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  13997. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  13998. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  13999. void clif_Adopt_reply(struct map_session_data *sd, int type)
  14000. {
  14001. int fd = sd->fd;
  14002. WFIFOHEAD(fd,6);
  14003. WFIFOW(fd,0) = 0x216;
  14004. WFIFOL(fd,2) = type;
  14005. WFIFOSET(fd,6);
  14006. }
  14007. /// Adoption confirmation (ZC_REQ_BABY).
  14008. /// 01f6 <account id>.L <char id>.L <name>.B
  14009. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  14010. {
  14011. int fd = sd->fd;
  14012. WFIFOHEAD(fd,34);
  14013. WFIFOW(fd,0) = 0x1f6;
  14014. WFIFOL(fd,2) = src->status.account_id;
  14015. WFIFOL(fd,6) = p_id;
  14016. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14017. WFIFOSET(fd,34);
  14018. }
  14019. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14020. /// 01f9 <account id>.L
  14021. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  14022. {
  14023. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14024. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14025. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14026. {
  14027. tsd->adopt_invite = sd->status.account_id;
  14028. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14029. }
  14030. }
  14031. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14032. /// 01f7 <account id>.L <char id>.L <answer>.L
  14033. /// answer:
  14034. /// 0 = rejected
  14035. /// 1 = accepted
  14036. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  14037. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14038. int p1_id = RFIFOL(fd,info->pos[0]);
  14039. int p2_id = RFIFOL(fd,info->pos[1]);
  14040. int result = RFIFOL(fd,info->pos[2]);
  14041. struct map_session_data* p1_sd = map_id2sd(p1_id);
  14042. struct map_session_data* p2_sd = map_id2sd(p2_id);
  14043. int pid = sd->adopt_invite;
  14044. sd->adopt_invite = 0;
  14045. if( p1_sd == NULL || p2_sd == NULL )
  14046. return; // Both players need to be online
  14047. if( pid != p1_sd->status.account_id )
  14048. return; // Incorrect values
  14049. if( result == 0 )
  14050. return; // Rejected
  14051. pc_adoption(p1_sd, p2_sd, sd);
  14052. }
  14053. /// Convex Mirror (ZC_BOSS_INFO).
  14054. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  14055. /// infoType:
  14056. /// BOSS_INFO_NOT = No boss on this map.
  14057. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14058. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14059. /// BOSS_INFO_DEAD = Boss is dead.
  14060. void clif_bossmapinfo(struct map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  14061. {
  14062. int fd = sd->fd;
  14063. WFIFOHEAD(fd,70);
  14064. memset(WFIFOP(fd,0),0,70);
  14065. WFIFOW(fd,0) = 0x293;
  14066. switch (flag) {
  14067. case BOSS_INFO_NOT:
  14068. WFIFOB(fd,2) = BOSS_INFO_NOT;
  14069. // No data required
  14070. break;
  14071. case BOSS_INFO_ALIVE:
  14072. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  14073. // Update X/Y
  14074. WFIFOL(fd,3) = md->bl.x;
  14075. WFIFOL(fd,7) = md->bl.y;
  14076. break;
  14077. case BOSS_INFO_ALIVE_WITHMSG:
  14078. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  14079. // Current X/Y
  14080. WFIFOL(fd,3) = md->bl.x;
  14081. WFIFOL(fd,7) = md->bl.y;
  14082. break;
  14083. case BOSS_INFO_DEAD:
  14084. {
  14085. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14086. unsigned int seconds;
  14087. int hours, minutes;
  14088. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  14089. hours = seconds / (60 * 60);
  14090. seconds = seconds - (60 * 60 * hours);
  14091. minutes = seconds / 60;
  14092. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14093. // Add respawn info
  14094. WFIFOW(fd,11) = hours; // Hours
  14095. WFIFOW(fd,13) = minutes; // Minutes
  14096. }
  14097. break;
  14098. }
  14099. if (md != NULL)
  14100. safestrncpy(WFIFOCP(fd,19), md->db->jname, NAME_LENGTH);
  14101. WFIFOSET(fd,70);
  14102. }
  14103. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14104. /// 02d6 <account id>.L
  14105. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  14106. {
  14107. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14108. struct map_session_data* tsd = map_id2sd(aid);
  14109. if (!tsd)
  14110. return;
  14111. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14112. clif_viewequip_ack(sd, tsd);
  14113. else
  14114. clif_msg(sd, VIEW_EQUIP_FAIL);
  14115. }
  14116. /// Request to a configuration.
  14117. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14118. /// type: see enum e_config_type
  14119. /// flag:
  14120. /// false = disabled
  14121. /// true = enabled
  14122. void clif_parse_configuration( int fd, struct map_session_data* sd ){
  14123. int cmd = RFIFOW(fd,0);
  14124. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14125. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14126. switch( type ){
  14127. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14128. sd->status.show_equip = flag;
  14129. break;
  14130. case CONFIG_PET_AUTOFEED:
  14131. // TODO: Implement with pet evolution system
  14132. break;
  14133. case CONFIG_HOMUNCULUS_AUTOFEED:
  14134. // Player can not click this if he does not have a homunculus or it is vaporized
  14135. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14136. return;
  14137. }
  14138. sd->hd->homunculus.autofeed = flag;
  14139. break;
  14140. default:
  14141. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14142. return;
  14143. }
  14144. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14145. }
  14146. /// Request to change party invitation tick.
  14147. /// value:
  14148. /// 0 = disabled
  14149. /// 1 = enabled
  14150. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14151. {
  14152. bool flag = RFIFOB(fd,6) ? true : false;
  14153. sd->status.allow_party = flag;
  14154. clif_partytickack(sd, flag);
  14155. }
  14156. /// Questlog System [Kevin] [Inkfish]
  14157. ///
  14158. /**
  14159. * Safe check to init packet len & quest num for player.
  14160. * @param def_len
  14161. * @param info_len Length of each quest info.
  14162. * @param avail_quests Avail quests that player has.
  14163. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14164. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14165. **/
  14166. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14167. (*limit_out) = (0xFFFF - def_len) / info_len;
  14168. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14169. (*len_out) = ((*limit_out) * info_len) + def_len;
  14170. }
  14171. /// Sends list of all quest states
  14172. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14173. /// 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)
  14174. /// 09f8 <packet len>.W <num>.L { <quest id>.L <active>.B <remaining time>.L <time>.L <count>.W { <hunt identification>.L <mob type>.L <mob_id>.L <min level>.W <max level>.W <killed>.W <total>.W <mob name>.24B }*count }*num (ZC_ALL_QUEST_LIST3)
  14175. void clif_quest_send_list(struct map_session_data *sd)
  14176. {
  14177. int fd = sd->fd;
  14178. int i;
  14179. int offset = 8;
  14180. int limit = 0;
  14181. #if PACKETVER >= 20141022
  14182. #if PACKETVER >= 20150513
  14183. int size = 22 + NAME_LENGTH;
  14184. #else
  14185. int size = 10 + NAME_LENGTH;
  14186. #endif
  14187. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14188. WFIFOHEAD(fd,i);
  14189. #if PACKETVER >= 20150513
  14190. WFIFOW(fd, 0) = 0x9f8;
  14191. #else
  14192. WFIFOW(fd, 0) = 0x97a;
  14193. #endif
  14194. WFIFOL(fd, 4) = limit;
  14195. for (i = 0; i < limit; i++) {
  14196. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  14197. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14198. offset += 4;
  14199. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14200. offset++;
  14201. WFIFOL(fd, offset) = sd->quest_log[i].time - qi->time;
  14202. offset += 4;
  14203. WFIFOL(fd, offset) = sd->quest_log[i].time;
  14204. offset += 4;
  14205. WFIFOW(fd, offset) = qi->objectives_count;
  14206. offset += 2;
  14207. if( qi->objectives_count > 0 ){
  14208. int j;
  14209. struct mob_db *mob;
  14210. for( j = 0; j < qi->objectives_count; j++ ){
  14211. mob = mob_db(qi->objectives[j].mob);
  14212. #if PACKETVER >= 20150513
  14213. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14214. offset += 4;
  14215. WFIFOL(fd, offset) = 0; // TODO: Find info - mobType
  14216. offset += 4;
  14217. #endif
  14218. WFIFOL(fd, offset) = qi->objectives[j].mob;
  14219. offset += 4;
  14220. #if PACKETVER >= 20150513
  14221. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMin
  14222. offset += 2;
  14223. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMax
  14224. offset += 2;
  14225. #endif
  14226. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14227. offset += 2;
  14228. WFIFOW(fd, offset) = qi->objectives[j].count;
  14229. offset += 2;
  14230. safestrncpy((char*)WFIFOP(fd, offset), mob->jname, NAME_LENGTH);
  14231. offset += NAME_LENGTH;
  14232. }
  14233. }
  14234. }
  14235. WFIFOW(fd, 2) = offset;
  14236. WFIFOSET(fd, offset);
  14237. #else
  14238. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14239. WFIFOHEAD(fd,i);
  14240. WFIFOW(fd, 0) = 0x2b1;
  14241. WFIFOL(fd, 4) = limit;
  14242. for (i = 0; i < limit; i++) {
  14243. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14244. offset += 4;
  14245. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14246. offset += 1;
  14247. }
  14248. WFIFOW(fd, 2) = offset;
  14249. WFIFOSET(fd, offset);
  14250. #endif
  14251. }
  14252. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14253. /// 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
  14254. void clif_quest_send_mission(struct map_session_data *sd)
  14255. {
  14256. int fd = sd->fd;
  14257. int i, j, limit = 0;
  14258. int len = sd->avail_quests*104+8;
  14259. struct mob_db *mob;
  14260. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14261. WFIFOHEAD(fd, len);
  14262. WFIFOW(fd, 0) = 0x2b2;
  14263. WFIFOW(fd, 2) = len;
  14264. WFIFOL(fd, 4) = limit;
  14265. for (i = 0; i < limit; i++) {
  14266. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  14267. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14268. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  14269. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  14270. WFIFOW(fd, i*104+20) = qi->objectives_count;
  14271. for (j = 0 ; j < qi->objectives_count; j++) {
  14272. WFIFOL(fd, i*104+22+j*30) = qi->objectives[j].mob;
  14273. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14274. mob = mob_db(qi->objectives[j].mob);
  14275. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  14276. }
  14277. }
  14278. WFIFOSET(fd, len);
  14279. }
  14280. /// Notification about a new quest
  14281. /// 02b3 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <mob id>.L <mob count>.W <mob name>.24B }*3 (ZC_ADD_QUEST)
  14282. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14283. /// 09f9 <quest id>.L <active>.B <start time>.L <expire time>.L <mobs>.W { <hunt identification>.L <mob type>.L <mob id>.L <min level>.W <max level>.W <mob count>.W <mob name>.24B }*3 (ZC_ADD_QUEST_EX)
  14284. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14285. {
  14286. int fd = sd->fd;
  14287. int i, offset;
  14288. struct quest_db *qi = quest_search(qd->quest_id);
  14289. #if PACKETVER >= 20150513
  14290. int cmd = 0x9f9;
  14291. #else
  14292. int cmd = 0x2b3;
  14293. #endif
  14294. WFIFOHEAD(fd, packet_len(cmd));
  14295. WFIFOW(fd, 0) = cmd;
  14296. WFIFOL(fd, 2) = qd->quest_id;
  14297. WFIFOB(fd, 6) = qd->state;
  14298. WFIFOB(fd, 7) = qd->time - qi->time;
  14299. WFIFOL(fd, 11) = qd->time;
  14300. WFIFOW(fd, 15) = qi->objectives_count;
  14301. for (i = 0, offset = 17; i < qi->objectives_count; i++) {
  14302. struct mob_db *mob;
  14303. #if PACKETVER >= 20150513
  14304. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14305. offset += 4;
  14306. WFIFOL(fd, offset) = 0; // TODO: Find info - mobType
  14307. offset += 4;
  14308. #endif
  14309. WFIFOL(fd, offset) = qi->objectives[i].mob;
  14310. offset += 4;
  14311. #if PACKETVER >= 20150513
  14312. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMin
  14313. offset += 2;
  14314. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMax
  14315. offset += 2;
  14316. #endif
  14317. WFIFOW(fd, offset) = qd->count[i];
  14318. offset += 2;
  14319. mob = mob_db(qi->objectives[i].mob);
  14320. safestrncpy(WFIFOCP(fd, offset), mob->jname, NAME_LENGTH);
  14321. offset += NAME_LENGTH;
  14322. }
  14323. WFIFOSET(fd, packet_len(cmd));
  14324. #if PACKETVER >= 20150513
  14325. int len = 4 + qi->objectives_count * 12;
  14326. WFIFOHEAD(fd, len);
  14327. WFIFOW(fd, 0) = 0x8fe;
  14328. WFIFOW(fd, 2) = len;
  14329. for( i = 0, offset = 4; i < qi->objectives_count; i++, offset += 12 ){
  14330. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14331. WFIFOL(fd, offset+4) = qi->objectives[i].mob;
  14332. WFIFOW(fd, offset + 10) = qi->objectives[i].count;
  14333. WFIFOW(fd, offset + 12) = qd->count[i];
  14334. }
  14335. WFIFOSET(fd, len);
  14336. #endif
  14337. }
  14338. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14339. /// 02b4 <quest id>.L
  14340. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  14341. {
  14342. int fd = sd->fd;
  14343. WFIFOHEAD(fd, packet_len(0x2b4));
  14344. WFIFOW(fd, 0) = 0x2b4;
  14345. WFIFOL(fd, 2) = quest_id;
  14346. WFIFOSET(fd, packet_len(0x2b4));
  14347. }
  14348. /// Notification of an update to the hunting mission counter
  14349. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14350. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14351. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd, int mobid)
  14352. {
  14353. int fd = sd->fd;
  14354. int i, offset;
  14355. struct quest_db *qi = quest_search(qd->quest_id);
  14356. int len = qi->objectives_count * 12 + 6;
  14357. #if PACKETVER >= 20150513
  14358. int cmd = 0x9fa;
  14359. #else
  14360. int cmd = 0x2b5;
  14361. #endif
  14362. WFIFOHEAD(fd, len);
  14363. WFIFOW(fd, 0) = cmd;
  14364. WFIFOW(fd, 4) = qi->objectives_count;
  14365. for (i = 0, offset = 6; i < qi->objectives_count; i++) {
  14366. if (mobid == 0 || mobid == qi->objectives[i].mob) {
  14367. WFIFOL(fd, offset) = qd->quest_id;
  14368. offset += 4;
  14369. #if PACKETVER >= 20150513
  14370. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14371. offset += 4;
  14372. #else
  14373. WFIFOL(fd, offset) = qi->objectives[i].mob;
  14374. offset += 4;
  14375. #endif
  14376. WFIFOW(fd, offset) = qi->objectives[i].count;
  14377. offset += 2;
  14378. WFIFOW(fd, offset) = qd->count[i];
  14379. offset += 2;
  14380. }
  14381. }
  14382. WFIFOW(fd, 2) = offset;
  14383. WFIFOSET(fd, offset);
  14384. }
  14385. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14386. /// 02b6 <quest id>.L <active>.B
  14387. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  14388. {
  14389. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14390. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14391. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14392. }
  14393. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14394. /// 02b7 <quest id>.L <active>.B
  14395. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  14396. {
  14397. int fd = sd->fd;
  14398. WFIFOHEAD(fd, packet_len(0x2b7));
  14399. WFIFOW(fd, 0) = 0x2b7;
  14400. WFIFOL(fd, 2) = quest_id;
  14401. WFIFOB(fd, 6) = active;
  14402. WFIFOSET(fd, packet_len(0x2b7));
  14403. }
  14404. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14405. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14406. /// effect:
  14407. /// 0 = none
  14408. /// 1 = exclamation mark icon
  14409. /// 2 = question mark icon
  14410. /// color:
  14411. /// 0 = yellow
  14412. /// 1 = orange
  14413. /// 2 = green
  14414. /// 3 = purple
  14415. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short effect, short color)
  14416. {
  14417. #if PACKETVER >= 20090218
  14418. int fd = sd->fd;
  14419. WFIFOHEAD(fd, packet_len(0x446));
  14420. WFIFOW(fd, 0) = 0x446;
  14421. WFIFOL(fd, 2) = bl->id;
  14422. WFIFOW(fd, 6) = bl->x;
  14423. WFIFOW(fd, 8) = bl->y;
  14424. WFIFOW(fd, 10) = effect;
  14425. WFIFOW(fd, 12) = color;
  14426. WFIFOSET(fd, packet_len(0x446));
  14427. #endif
  14428. }
  14429. /// Mercenary System
  14430. ///
  14431. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14432. /// 02a2 <var id>.W <value>.L
  14433. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  14434. {
  14435. struct mercenary_data *md;
  14436. struct status_data *status;
  14437. int fd;
  14438. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14439. return;
  14440. fd = sd->fd;
  14441. status = &md->battle_status;
  14442. WFIFOHEAD(fd,packet_len(0x2a2));
  14443. WFIFOW(fd,0) = 0x2a2;
  14444. WFIFOW(fd,2) = type;
  14445. switch( type ) {
  14446. case SP_ATK1:
  14447. {
  14448. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  14449. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14450. }
  14451. break;
  14452. case SP_MATK1:
  14453. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14454. break;
  14455. case SP_HIT:
  14456. WFIFOL(fd,4) = status->hit;
  14457. break;
  14458. case SP_CRITICAL:
  14459. WFIFOL(fd,4) = status->cri/10;
  14460. break;
  14461. case SP_DEF1:
  14462. WFIFOL(fd,4) = status->def;
  14463. break;
  14464. case SP_MDEF1:
  14465. WFIFOL(fd,4) = status->mdef;
  14466. break;
  14467. case SP_MERCFLEE:
  14468. WFIFOL(fd,4) = status->flee;
  14469. break;
  14470. case SP_ASPD:
  14471. WFIFOL(fd,4) = status->amotion;
  14472. break;
  14473. case SP_HP:
  14474. WFIFOL(fd,4) = status->hp;
  14475. break;
  14476. case SP_MAXHP:
  14477. WFIFOL(fd,4) = status->max_hp;
  14478. break;
  14479. case SP_SP:
  14480. WFIFOL(fd,4) = status->sp;
  14481. break;
  14482. case SP_MAXSP:
  14483. WFIFOL(fd,4) = status->max_sp;
  14484. break;
  14485. case SP_MERCKILLS:
  14486. WFIFOL(fd,4) = md->mercenary.kill_count;
  14487. break;
  14488. case SP_MERCFAITH:
  14489. WFIFOL(fd,4) = mercenary_get_faith(md);
  14490. break;
  14491. }
  14492. WFIFOSET(fd,packet_len(0x2a2));
  14493. }
  14494. /// Mercenary base status data (ZC_MER_INIT).
  14495. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14496. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14497. /// <calls>.L <kills>.L <atk range>.W
  14498. void clif_mercenary_info(struct map_session_data *sd)
  14499. {
  14500. int fd;
  14501. struct mercenary_data *md;
  14502. struct status_data *status;
  14503. int atk;
  14504. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14505. return;
  14506. fd = sd->fd;
  14507. status = &md->battle_status;
  14508. WFIFOHEAD(fd,packet_len(0x29b));
  14509. WFIFOW(fd,0) = 0x29b;
  14510. WFIFOL(fd,2) = md->bl.id;
  14511. // Mercenary shows ATK as a random value between ATK ~ ATK2
  14512. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  14513. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  14514. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  14515. WFIFOW(fd,10) = status->hit;
  14516. WFIFOW(fd,12) = status->cri/10;
  14517. WFIFOW(fd,14) = status->def;
  14518. WFIFOW(fd,16) = status->mdef;
  14519. WFIFOW(fd,18) = status->flee;
  14520. WFIFOW(fd,20) = status->amotion;
  14521. safestrncpy(WFIFOCP(fd,22), md->db->name, NAME_LENGTH);
  14522. WFIFOW(fd,46) = md->db->lv;
  14523. WFIFOL(fd,48) = status->hp;
  14524. WFIFOL(fd,52) = status->max_hp;
  14525. WFIFOL(fd,56) = status->sp;
  14526. WFIFOL(fd,60) = status->max_sp;
  14527. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  14528. WFIFOW(fd,68) = mercenary_get_faith(md);
  14529. WFIFOL(fd,70) = mercenary_get_calls(md);
  14530. WFIFOL(fd,74) = md->mercenary.kill_count;
  14531. WFIFOW(fd,78) = md->battle_status.rhw.range;
  14532. WFIFOSET(fd,packet_len(0x29b));
  14533. }
  14534. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  14535. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  14536. void clif_mercenary_skillblock(struct map_session_data *sd)
  14537. {
  14538. struct mercenary_data *md;
  14539. int fd, i, len = 4;
  14540. if( sd == NULL || (md = sd->md) == NULL )
  14541. return;
  14542. fd = sd->fd;
  14543. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  14544. WFIFOW(fd,0) = 0x29d;
  14545. for( i = 0; i < MAX_MERCSKILL; i++ )
  14546. {
  14547. uint16 id;
  14548. short idx = -1;
  14549. if( (id = md->db->skill[i].id) == 0 )
  14550. continue;
  14551. if ((idx = mercenary_skill_get_index(id)) == -1)
  14552. continue;
  14553. WFIFOW(fd,len) = id;
  14554. WFIFOL(fd,len+2) = skill_get_inf(id);
  14555. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  14556. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  14557. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv, false);
  14558. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  14559. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  14560. len += 37;
  14561. }
  14562. WFIFOW(fd,2) = len;
  14563. WFIFOSET(fd,len);
  14564. }
  14565. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  14566. /// 029f <command>.B
  14567. /// 1 = mercenary information
  14568. /// 2 = delete
  14569. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  14570. {
  14571. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14572. if( sd->md == NULL )
  14573. return;
  14574. if( option == 2 ) mercenary_delete(sd->md, 2);
  14575. }
  14576. /// Mercenary Message
  14577. /// message:
  14578. /// 0 = Mercenary soldier's duty hour is over.
  14579. /// 1 = Your mercenary soldier has been killed.
  14580. /// 2 = Your mercenary soldier has been fired.
  14581. /// 3 = Your mercenary soldier has ran away.
  14582. void clif_mercenary_message(struct map_session_data* sd, int message){
  14583. clif_msg(sd, MERC_MSG_BASE + message);
  14584. }
  14585. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  14586. /// 0298 <name id>.W <seconds>.L
  14587. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  14588. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  14589. WFIFOHEAD(fd,packet_len(0x298));
  14590. WFIFOW(fd,0) = 0x298;
  14591. WFIFOW(fd,2) = nameid;
  14592. WFIFOL(fd,4) = seconds;
  14593. WFIFOSET(fd,packet_len(0x298));
  14594. }
  14595. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  14596. /// 0299 <index>.W <name id>.W
  14597. void clif_rental_expired(int fd, int index, unsigned short nameid)
  14598. { // '<ItemName>' item has been deleted from the Inventory
  14599. WFIFOHEAD(fd,packet_len(0x299));
  14600. WFIFOW(fd,0) = 0x299;
  14601. WFIFOW(fd,2) = index+2;
  14602. WFIFOW(fd,4) = nameid;
  14603. WFIFOSET(fd,packet_len(0x299));
  14604. }
  14605. /// Book Reading (ZC_READ_BOOK).
  14606. /// 0294 <book id>.L <page>.L
  14607. void clif_readbook(int fd, int book_id, int page)
  14608. {
  14609. WFIFOHEAD(fd,packet_len(0x294));
  14610. WFIFOW(fd,0) = 0x294;
  14611. WFIFOL(fd,2) = book_id;
  14612. WFIFOL(fd,6) = page;
  14613. WFIFOSET(fd,packet_len(0x294));
  14614. }
  14615. /// Battlegrounds
  14616. ///
  14617. /// Updates HP bar of a camp member.
  14618. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  14619. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  14620. void clif_bg_hp(struct map_session_data *sd) {
  14621. #if PACKETVER < 20140613
  14622. unsigned char buf[34];
  14623. const int cmd = 0x2e0;
  14624. #else
  14625. unsigned char buf[14];
  14626. const int cmd = 0xa0e;
  14627. #endif
  14628. nullpo_retv(sd);
  14629. WBUFW(buf,0) = cmd;
  14630. WBUFL(buf,2) = sd->status.account_id;
  14631. #if PACKETVER < 20140613
  14632. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14633. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  14634. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14635. WBUFW(buf,32) = 100;
  14636. } else {
  14637. WBUFW(buf,30) = sd->battle_status.hp;
  14638. WBUFW(buf,32) = sd->battle_status.max_hp;
  14639. }
  14640. #else
  14641. if( sd->battle_status.max_hp > INT32_MAX ) {
  14642. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14643. WBUFL(buf,10) = 100;
  14644. } else {
  14645. WBUFL(buf,6) = sd->battle_status.hp;
  14646. WBUFL(buf,10) = sd->battle_status.max_hp;
  14647. }
  14648. #endif
  14649. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  14650. }
  14651. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  14652. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  14653. void clif_bg_xy(struct map_session_data *sd)
  14654. {
  14655. unsigned char buf[36];
  14656. nullpo_retv(sd);
  14657. WBUFW(buf,0)=0x2df;
  14658. WBUFL(buf,2)=sd->status.account_id;
  14659. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14660. WBUFW(buf,30)=sd->status.class_;
  14661. WBUFW(buf,32)=sd->bl.x;
  14662. WBUFW(buf,34)=sd->bl.y;
  14663. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14664. }
  14665. void clif_bg_xy_remove(struct map_session_data *sd)
  14666. {
  14667. unsigned char buf[36];
  14668. nullpo_retv(sd);
  14669. WBUFW(buf,0)=0x2df;
  14670. WBUFL(buf,2)=sd->status.account_id;
  14671. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  14672. WBUFW(buf,30)=0;
  14673. WBUFW(buf,32)=-1;
  14674. WBUFW(buf,34)=-1;
  14675. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14676. }
  14677. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  14678. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  14679. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  14680. {
  14681. struct map_session_data *sd;
  14682. unsigned char *buf;
  14683. if( (sd = bg_getavailablesd(bg)) == NULL )
  14684. return;
  14685. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  14686. WBUFW(buf,0) = 0x2dc;
  14687. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  14688. WBUFL(buf,4) = src_id;
  14689. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  14690. memcpy(WBUFP(buf,32), mes, len);
  14691. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  14692. if( buf )
  14693. aFree(buf);
  14694. }
  14695. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  14696. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  14697. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  14698. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  14699. if( !clif_process_message( sd, false, name, message, output ) )
  14700. return;
  14701. bg_send_message(sd, output, strlen(output) );
  14702. }
  14703. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  14704. /// 02de <camp A points>.W <camp B points>.W
  14705. void clif_bg_updatescore(int16 m)
  14706. {
  14707. struct block_list bl;
  14708. unsigned char buf[6];
  14709. struct map_data *mapdata = map_getmapdata(m);
  14710. bl.id = 0;
  14711. bl.type = BL_NUL;
  14712. bl.m = m;
  14713. WBUFW(buf,0) = 0x2de;
  14714. WBUFW(buf,2) = mapdata->bgscore_lion;
  14715. WBUFW(buf,4) = mapdata->bgscore_eagle;
  14716. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  14717. }
  14718. void clif_bg_updatescore_single(struct map_session_data *sd)
  14719. {
  14720. int fd;
  14721. nullpo_retv(sd);
  14722. fd = sd->fd;
  14723. struct map_data *mapdata = map_getmapdata(sd->bl.m);
  14724. WFIFOHEAD(fd,packet_len(0x2de));
  14725. WFIFOW(fd,0) = 0x2de;
  14726. WFIFOW(fd,2) = mapdata->bgscore_lion;
  14727. WFIFOW(fd,4) = mapdata->bgscore_eagle;
  14728. WFIFOSET(fd,packet_len(0x2de));
  14729. }
  14730. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  14731. /// 02dd <account id>.L <name>.24B <camp>.W
  14732. void clif_sendbgemblem_area(struct map_session_data *sd)
  14733. {
  14734. unsigned char buf[33];
  14735. nullpo_retv(sd);
  14736. WBUFW(buf, 0) = 0x2dd;
  14737. WBUFL(buf,2) = sd->bl.id;
  14738. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  14739. WBUFW(buf,30) = sd->bg_id;
  14740. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  14741. }
  14742. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  14743. {
  14744. nullpo_retv(sd);
  14745. WFIFOHEAD(fd,32);
  14746. WFIFOW(fd,0) = 0x2dd;
  14747. WFIFOL(fd,2) = sd->bl.id;
  14748. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  14749. WFIFOW(fd,30) = sd->bg_id;
  14750. WFIFOSET(fd,packet_len(0x2dd));
  14751. }
  14752. /// Custom Fonts (ZC_NOTIFY_FONT).
  14753. /// 02ef <account_id>.L <font id>.W
  14754. void clif_font(struct map_session_data *sd)
  14755. {
  14756. #if PACKETVER >= 20080102
  14757. unsigned char buf[8];
  14758. nullpo_retv(sd);
  14759. WBUFW(buf,0) = 0x2ef;
  14760. WBUFL(buf,2) = sd->bl.id;
  14761. WBUFW(buf,6) = sd->status.font;
  14762. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  14763. #endif
  14764. }
  14765. /// Required to start the instancing information window on Client
  14766. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  14767. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  14768. void clif_instance_create(unsigned short instance_id, int num)
  14769. {
  14770. #if PACKETVER >= 20071128
  14771. struct instance_db *db = NULL;
  14772. struct map_session_data *sd = NULL;
  14773. enum send_target target = PARTY;
  14774. unsigned char buf[65];
  14775. instance_getsd(instance_id, &sd, &target);
  14776. if (!sd)
  14777. return;
  14778. db = instance_searchtype_db(instance_data[instance_id].type);
  14779. if (!db)
  14780. return;
  14781. WBUFW(buf,0) = 0x2cb;
  14782. safestrncpy(WBUFCP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  14783. WBUFW(buf,63) = num;
  14784. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  14785. #endif
  14786. return;
  14787. }
  14788. /// To announce Instancing queue creation if no maps available
  14789. /// S 0x2cc <Standby Position>.W
  14790. void clif_instance_changewait(unsigned short instance_id, int num)
  14791. {
  14792. #if PACKETVER >= 20071128
  14793. struct map_session_data *sd = NULL;
  14794. enum send_target target = PARTY;
  14795. unsigned char buf[4];
  14796. instance_getsd(instance_id, &sd, &target);
  14797. if (!sd)
  14798. return;
  14799. WBUFW(buf,0) = 0x2cc;
  14800. WBUFW(buf,2) = num;
  14801. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  14802. #endif
  14803. return;
  14804. }
  14805. /// Notify the current status to members
  14806. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  14807. void clif_instance_status(unsigned short instance_id, unsigned int limit1, unsigned int limit2)
  14808. {
  14809. #if PACKETVER >= 20071128
  14810. struct instance_db *db = NULL;
  14811. struct map_session_data *sd = NULL;
  14812. enum send_target target = PARTY;
  14813. unsigned char buf[71];
  14814. instance_getsd(instance_id, &sd, &target);
  14815. if (!sd)
  14816. return;
  14817. db = instance_searchtype_db(instance_data[instance_id].type);
  14818. if (!db)
  14819. return;
  14820. WBUFW(buf,0) = 0x2cd;
  14821. safestrncpy(WBUFCP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  14822. WBUFL(buf,63) = limit1;
  14823. WBUFL(buf,67) = limit2;
  14824. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  14825. #endif
  14826. return;
  14827. }
  14828. /// Notify a status change to members
  14829. /// S 0x2ce <Message ID>.L
  14830. /// 0 = Notification (EnterLimitDate update?)
  14831. /// 1 = The Memorial Dungeon expired; it has been destroyed
  14832. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  14833. /// 3 = The Memorial Dungeon has been removed.
  14834. /// 4 = Create failure (removes the instance window)
  14835. void clif_instance_changestatus(unsigned int instance_id, int type, unsigned int limit)
  14836. {
  14837. #if PACKETVER >= 20071128
  14838. struct map_session_data *sd = NULL;
  14839. enum send_target target = PARTY;
  14840. unsigned char buf[10];
  14841. instance_getsd(instance_id, &sd, &target);
  14842. if (!sd)
  14843. return;
  14844. WBUFW(buf,0) = 0x2ce;
  14845. WBUFL(buf,2) = type;
  14846. WBUFL(buf,6) = limit;
  14847. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  14848. #endif
  14849. return;
  14850. }
  14851. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  14852. /// 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
  14853. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  14854. {
  14855. #if PACKETVER >= 20071002
  14856. unsigned char buf[22];
  14857. struct item_data* id = itemdb_search(item_data->nameid);
  14858. WBUFW(buf,0) = 0x2b8;
  14859. WBUFL(buf,2) = sd->status.account_id;
  14860. WBUFW(buf,6) = item_data->nameid;
  14861. WBUFB(buf,8) = item_data->identify;
  14862. WBUFB(buf,9) = item_data->attribute;
  14863. WBUFB(buf,10) = item_data->refine;
  14864. clif_addcards(WBUFP(buf,11), item_data);
  14865. WBUFW(buf,19) = id->equip; // equip location
  14866. WBUFB(buf,21) = itemtype(id->nameid); // item type
  14867. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  14868. #endif
  14869. }
  14870. /** Display gained exp.
  14871. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  14872. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  14873. * amount: INT32_MIN ~ INT32_MAX
  14874. * var id:
  14875. * SP_BASEEXP, SP_JOBEXP
  14876. * exp type:
  14877. * 0 = normal exp gained/lost
  14878. * 1 = quest exp gained/lost
  14879. * @param sd Player
  14880. * @param exp EXP value gained/loss
  14881. * @param type SP_BASEEXP, SP_JOBEXP
  14882. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  14883. * @param lost True:if lossing EXP
  14884. */
  14885. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest, bool lost)
  14886. {
  14887. int fd;
  14888. int offset;
  14889. #if PACKETVER >= 20170830
  14890. int cmd = 0xacc;
  14891. #else
  14892. int cmd = 0x7f6;
  14893. #endif
  14894. nullpo_retv(sd);
  14895. fd = sd->fd;
  14896. WFIFOHEAD(fd, packet_len(cmd));
  14897. WFIFOW(fd,0) = cmd;
  14898. WFIFOL(fd,2) = sd->bl.id;
  14899. #if PACKETVER >= 20170830
  14900. WFIFOQ(fd,6) = (int64)u64min((uint64)exp, INT_MAX) * (lost ? -1 : 1);
  14901. offset = 4;
  14902. #else
  14903. WFIFOL(fd,6) = (int)umin(exp, INT_MAX) * (lost ? -1 : 1);
  14904. offset = 0;
  14905. #endif
  14906. WFIFOW(fd,10+offset) = type;
  14907. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  14908. WFIFOSET(fd,packet_len(cmd));
  14909. }
  14910. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  14911. /// type:
  14912. /// 0 = Displays 'value' for 5 seconds.
  14913. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  14914. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  14915. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  14916. /// value:
  14917. /// 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).
  14918. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  14919. {
  14920. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  14921. WFIFOW(sd->fd,0) = 0x1b1;
  14922. WFIFOB(sd->fd,2) = type;
  14923. WFIFOL(sd->fd,3) = value;
  14924. WFIFOSET(sd->fd, packet_len(0x1b1));
  14925. }
  14926. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  14927. /// 021d <state>.L
  14928. /// state:
  14929. /// 0 = Full effects
  14930. /// 1 = Reduced effects
  14931. ///
  14932. /// NOTE: The state is used on Aegis for sending skill unit packet
  14933. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  14934. /// whenever possible. Due to the way the decision check is
  14935. /// constructed, this state tracking was rendered useless,
  14936. /// as the only skill unit, that is sent with 0x1c9 is
  14937. /// Graffiti.
  14938. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  14939. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14940. sd->state.lesseffect = ( isLess != 0 );
  14941. }
  14942. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  14943. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  14944. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14945. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  14946. int type = RFIFOL(fd,info->pos[1]);
  14947. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  14948. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  14949. if( sd->state.trading || sd->npc_shopid )
  14950. return;
  14951. if( flag == 0 || n == 0) {
  14952. clif_menuskill_clear(sd);
  14953. return; // Canceled by player.
  14954. }
  14955. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  14956. clif_menuskill_clear(sd);
  14957. return; // Prevent hacking.
  14958. }
  14959. switch( type ) {
  14960. case 0: // Change Material
  14961. skill_changematerial(sd,n,item_list);
  14962. break;
  14963. case 1: // Level 1: Pure to Rough
  14964. case 2: // Level 2: Rough to Pure
  14965. skill_elementalanalysis(sd,n,type,item_list);
  14966. break;
  14967. }
  14968. clif_menuskill_clear(sd);
  14969. return;
  14970. }
  14971. /*==========================================
  14972. * Elemental System
  14973. *==========================================*/
  14974. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  14975. struct elemental_data *ed;
  14976. struct status_data *status;
  14977. int fd;
  14978. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  14979. return;
  14980. fd = sd->fd;
  14981. status = &ed->battle_status;
  14982. WFIFOHEAD(fd,8);
  14983. WFIFOW(fd,0) = 0x81e;
  14984. WFIFOW(fd,2) = type;
  14985. switch( type ) {
  14986. case SP_HP:
  14987. WFIFOL(fd,4) = status->hp;
  14988. break;
  14989. case SP_MAXHP:
  14990. WFIFOL(fd,4) = status->max_hp;
  14991. break;
  14992. case SP_SP:
  14993. WFIFOL(fd,4) = status->sp;
  14994. break;
  14995. case SP_MAXSP:
  14996. WFIFOL(fd,4) = status->max_sp;
  14997. break;
  14998. }
  14999. WFIFOSET(fd,8);
  15000. }
  15001. void clif_elemental_info(struct map_session_data *sd) {
  15002. int fd;
  15003. struct elemental_data *ed;
  15004. struct status_data *status;
  15005. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  15006. return;
  15007. fd = sd->fd;
  15008. status = &ed->battle_status;
  15009. WFIFOHEAD(fd,22);
  15010. WFIFOW(fd, 0) = 0x81d;
  15011. WFIFOL(fd, 2) = ed->bl.id;
  15012. WFIFOL(fd, 6) = status->hp;
  15013. WFIFOL(fd,10) = status->max_hp;
  15014. WFIFOL(fd,14) = status->sp;
  15015. WFIFOL(fd,18) = status->max_sp;
  15016. WFIFOSET(fd,22);
  15017. }
  15018. /// Buying Store System
  15019. ///
  15020. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15021. /// 0810 <slots>.B
  15022. void clif_buyingstore_open(struct map_session_data* sd)
  15023. {
  15024. int fd = sd->fd;
  15025. WFIFOHEAD(fd,packet_len(0x810));
  15026. WFIFOW(fd,0) = 0x810;
  15027. WFIFOB(fd,2) = sd->buyingstore.slots;
  15028. WFIFOSET(fd,packet_len(0x810));
  15029. }
  15030. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15031. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15032. /// result:
  15033. /// 0 = cancel
  15034. /// 1 = open
  15035. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  15036. {
  15037. const unsigned int blocksize = 8;
  15038. uint8* itemlist;
  15039. char storename[MESSAGE_SIZE];
  15040. unsigned char result;
  15041. int zenylimit;
  15042. unsigned int count, packet_len;
  15043. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15044. packet_len = RFIFOW(fd,info->pos[0]);
  15045. // TODO: Make this check global for all variable length packets.
  15046. if( packet_len < 89 )
  15047. {// minimum packet length
  15048. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  15049. return;
  15050. }
  15051. zenylimit = RFIFOL(fd,info->pos[1]);
  15052. result = RFIFOL(fd,info->pos[2]);
  15053. safestrncpy(storename, RFIFOCP(fd,info->pos[3]), sizeof(storename));
  15054. itemlist = RFIFOP(fd,info->pos[4]);
  15055. // so that buyingstore_create knows, how many elements it has access to
  15056. packet_len-= info->pos[4];
  15057. if( packet_len%blocksize )
  15058. {
  15059. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  15060. return;
  15061. }
  15062. count = packet_len/blocksize;
  15063. buyingstore_create(sd, zenylimit, result, storename, itemlist, count, NULL);
  15064. }
  15065. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15066. /// 0812 <result>.W <total weight>.L
  15067. /// result:
  15068. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15069. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15070. /// 8 = "No sale (purchase) information available." (0x705)
  15071. /// ? = nothing
  15072. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  15073. {
  15074. int fd = sd->fd;
  15075. WFIFOHEAD(fd,packet_len(0x812));
  15076. WFIFOW(fd,0) = 0x812;
  15077. WFIFOW(fd,2) = result;
  15078. WFIFOL(fd,4) = weight;
  15079. WFIFOSET(fd,packet_len(0x812));
  15080. }
  15081. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15082. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15083. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  15084. {
  15085. int fd = sd->fd;
  15086. unsigned int i;
  15087. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  15088. WFIFOW(fd,0) = 0x813;
  15089. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  15090. WFIFOL(fd,4) = sd->bl.id;
  15091. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  15092. for( i = 0; i < sd->buyingstore.slots; i++ )
  15093. {
  15094. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  15095. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  15096. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  15097. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  15098. }
  15099. WFIFOSET(fd,WFIFOW(fd,2));
  15100. }
  15101. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15102. /// 0814 <account id>.L <store name>.80B
  15103. void clif_buyingstore_entry(struct map_session_data* sd)
  15104. {
  15105. uint8 buf[MESSAGE_SIZE+6];
  15106. WBUFW(buf,0) = 0x814;
  15107. WBUFL(buf,2) = sd->bl.id;
  15108. safestrncpy(WBUFCP(buf,6), sd->message, MESSAGE_SIZE);
  15109. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  15110. }
  15111. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15112. {
  15113. int fd = sd->fd;
  15114. WFIFOHEAD(fd,packet_len(0x814));
  15115. WFIFOW(fd,0) = 0x814;
  15116. WFIFOL(fd,2) = pl_sd->bl.id;
  15117. safestrncpy(WFIFOCP(fd,6), pl_sd->message, MESSAGE_SIZE);
  15118. WFIFOSET(fd,packet_len(0x814));
  15119. }
  15120. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15121. /// 0815
  15122. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  15123. {
  15124. buyingstore_close(sd);
  15125. }
  15126. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15127. /// 0816 <account id>.L
  15128. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  15129. {
  15130. uint8 buf[6];
  15131. WBUFW(buf,0) = 0x816;
  15132. WBUFL(buf,2) = sd->bl.id;
  15133. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  15134. }
  15135. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15136. {
  15137. int fd = sd->fd;
  15138. WFIFOHEAD(fd,packet_len(0x816));
  15139. WFIFOW(fd,0) = 0x816;
  15140. WFIFOL(fd,2) = pl_sd->bl.id;
  15141. WFIFOSET(fd,packet_len(0x816));
  15142. }
  15143. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15144. /// 0817 <account id>.L
  15145. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  15146. {
  15147. uint32 account_id;
  15148. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15149. buyingstore_open(sd, account_id);
  15150. }
  15151. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  15152. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  15153. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  15154. {
  15155. int fd = sd->fd;
  15156. unsigned int i;
  15157. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  15158. WFIFOW(fd,0) = 0x818;
  15159. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  15160. WFIFOL(fd,4) = pl_sd->bl.id;
  15161. WFIFOL(fd,8) = pl_sd->buyer_id;
  15162. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  15163. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  15164. {
  15165. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  15166. 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.
  15167. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  15168. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  15169. }
  15170. WFIFOSET(fd,WFIFOW(fd,2));
  15171. }
  15172. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  15173. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  15174. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  15175. {
  15176. const unsigned int blocksize = 6;
  15177. uint8* itemlist;
  15178. uint32 account_id;
  15179. unsigned int count, packet_len, buyer_id;
  15180. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15181. packet_len = RFIFOW(fd,info->pos[0]);
  15182. if( packet_len < 12 )
  15183. {// minimum packet length
  15184. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  15185. return;
  15186. }
  15187. account_id = RFIFOL(fd,info->pos[1]);
  15188. buyer_id = RFIFOL(fd,info->pos[2]);
  15189. itemlist = RFIFOP(fd,info->pos[3]);
  15190. // so that buyingstore_trade knows, how many elements it has access to
  15191. packet_len-= info->pos[3];
  15192. if( packet_len%blocksize )
  15193. {
  15194. 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);
  15195. return;
  15196. }
  15197. count = packet_len/blocksize;
  15198. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  15199. }
  15200. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15201. /// 081a <result>.W
  15202. /// result:
  15203. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15204. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15205. /// ? = nothing
  15206. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  15207. {
  15208. int fd = sd->fd;
  15209. WFIFOHEAD(fd,packet_len(0x81a));
  15210. WFIFOW(fd,0) = 0x81a;
  15211. WFIFOW(fd,2) = result;
  15212. WFIFOSET(fd,packet_len(0x81a));
  15213. }
  15214. /// Updates the zeny limit and an item in the buying store item list.
  15215. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15216. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15217. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount, uint32 char_id, int zeny) {
  15218. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  15219. const int cmd = 0x81b;
  15220. #else
  15221. const int cmd = 0x9e6;
  15222. #endif
  15223. int offset = 0;
  15224. int fd = sd->fd;
  15225. WFIFOHEAD(fd,packet_len(cmd));
  15226. WFIFOW(fd,0) = cmd;
  15227. WFIFOW(fd,2) = nameid;
  15228. WFIFOW(fd,4) = amount; // amount of nameid received
  15229. #if PACKETVER >= 20141016
  15230. WFIFOL(fd,6) = zeny; // zeny
  15231. offset += 4;
  15232. #endif
  15233. WFIFOL(fd,6+offset) = sd->buyingstore.zenylimit;
  15234. #if PACKETVER >= 20141016
  15235. WFIFOL(fd,10+offset) = char_id; // GID
  15236. WFIFOL(fd,14+offset) = (int)time(NULL); // date
  15237. #endif
  15238. WFIFOSET(fd,packet_len(cmd));
  15239. }
  15240. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15241. /// 081c <index>.W <amount>.W <price>.L
  15242. /// message:
  15243. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15244. ///
  15245. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15246. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  15247. {
  15248. int fd = sd->fd;
  15249. WFIFOHEAD(fd,packet_len(0x81c));
  15250. WFIFOW(fd,0) = 0x81c;
  15251. WFIFOW(fd,2) = index+2;
  15252. WFIFOW(fd,4) = amount;
  15253. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15254. WFIFOSET(fd,packet_len(0x81c));
  15255. }
  15256. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15257. /// 0824 <result>.W <name id>.W
  15258. /// result:
  15259. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15260. /// 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)
  15261. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15262. /// ? = nothing
  15263. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  15264. {
  15265. int fd = sd->fd;
  15266. WFIFOHEAD(fd,packet_len(0x824));
  15267. WFIFOW(fd,0) = 0x824;
  15268. WFIFOW(fd,2) = result;
  15269. WFIFOW(fd,4) = nameid;
  15270. WFIFOSET(fd,packet_len(0x824));
  15271. }
  15272. /// Search Store Info System
  15273. ///
  15274. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15275. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15276. /// type:
  15277. /// 0 = Vending
  15278. /// 1 = Buying Store
  15279. ///
  15280. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15281. /// amount of card slots. If the client does not know about the item it
  15282. /// cannot be searched.
  15283. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  15284. {
  15285. const unsigned int blocksize = 2;
  15286. const uint8* itemlist;
  15287. const uint8* cardlist;
  15288. unsigned char type;
  15289. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  15290. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15291. packet_len = RFIFOW(fd,info->pos[0]);
  15292. if( packet_len < 15 )
  15293. {// minimum packet length
  15294. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  15295. return;
  15296. }
  15297. type = RFIFOB(fd,info->pos[1]);
  15298. max_price = RFIFOL(fd,info->pos[2]);
  15299. min_price = RFIFOL(fd,info->pos[3]);
  15300. item_count = RFIFOB(fd,info->pos[4]);
  15301. card_count = RFIFOB(fd,info->pos[5]);
  15302. itemlist = RFIFOP(fd,info->pos[6]);
  15303. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  15304. // check, if there is enough data for the claimed count of items
  15305. packet_len-= info->pos[6];
  15306. if( packet_len%blocksize )
  15307. {
  15308. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  15309. return;
  15310. }
  15311. count = packet_len/blocksize;
  15312. if( count < item_count+card_count )
  15313. {
  15314. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  15315. return;
  15316. }
  15317. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  15318. }
  15319. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  15320. /// 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 }*
  15321. /// is first page:
  15322. /// 0 = appends to existing results
  15323. /// 1 = clears previous results before displaying this result set
  15324. /// is next page:
  15325. /// 0 = no "next" label
  15326. /// 1 = "next" label to retrieve more results
  15327. void clif_search_store_info_ack(struct map_session_data* sd)
  15328. {
  15329. #if PACKETVER >= 20150225
  15330. const unsigned int blocksize = MESSAGE_SIZE+26+5*5;
  15331. #else
  15332. const unsigned int blocksize = MESSAGE_SIZE+26;
  15333. #endif
  15334. int fd = sd->fd;
  15335. unsigned int i, start, end;
  15336. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  15337. end = umin(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  15338. WFIFOHEAD(fd,7+(end-start)*blocksize);
  15339. WFIFOW(fd,0) = 0x836;
  15340. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  15341. WFIFOB(fd,4) = !sd->searchstore.pages;
  15342. WFIFOB(fd,5) = searchstore_querynext(sd);
  15343. WFIFOB(fd,6) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15344. for( i = start; i < end; i++ ) {
  15345. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  15346. struct item it;
  15347. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  15348. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  15349. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  15350. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  15351. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  15352. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  15353. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  15354. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  15355. // make-up an item for clif_addcards
  15356. memset(&it, 0, sizeof(it));
  15357. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  15358. it.nameid = ssitem->nameid;
  15359. it.amount = ssitem->amount;
  15360. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  15361. clif_add_random_options(WFIFOP(fd,i*blocksize+31+MESSAGE_SIZE), &it);
  15362. }
  15363. WFIFOSET(fd,WFIFOW(fd,2));
  15364. }
  15365. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  15366. /// 0837 <reason>.B
  15367. /// reason:
  15368. /// 0 = "No matching stores were found." (0x70b)
  15369. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  15370. /// 2 = "You cannot search anymore." (0x706)
  15371. /// 3 = "You cannot search yet." (0x708)
  15372. /// 4 = "No sale (purchase) information available." (0x705)
  15373. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  15374. {
  15375. int fd = sd->fd;
  15376. WFIFOHEAD(fd,packet_len(0x837));
  15377. WFIFOW(fd,0) = 0x837;
  15378. WFIFOB(fd,2) = reason;
  15379. WFIFOSET(fd,packet_len(0x837));
  15380. }
  15381. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  15382. /// 0838
  15383. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  15384. {
  15385. searchstore_next(sd);
  15386. }
  15387. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  15388. /// 083a <type>.W <remaining uses>.B
  15389. /// type:
  15390. /// 0 = Search Stores
  15391. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  15392. void clif_open_search_store_info(struct map_session_data* sd)
  15393. {
  15394. int fd = sd->fd;
  15395. WFIFOHEAD(fd,packet_len(0x83a));
  15396. WFIFOW(fd,0) = 0x83a;
  15397. WFIFOW(fd,2) = sd->searchstore.effect;
  15398. #if PACKETVER > 20100701
  15399. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15400. #endif
  15401. WFIFOSET(fd,packet_len(0x83a));
  15402. }
  15403. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  15404. /// 083b
  15405. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  15406. {
  15407. searchstore_close(sd);
  15408. }
  15409. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  15410. /// 083c <account id>.L <store id>.L <nameid>.W
  15411. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  15412. {
  15413. unsigned short nameid;
  15414. uint32 account_id, store_id;
  15415. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15416. account_id = RFIFOL(fd,info->pos[0]);
  15417. store_id = RFIFOL(fd,info->pos[1]);
  15418. nameid = RFIFOW(fd,info->pos[2]);
  15419. searchstore_click(sd, account_id, store_id, nameid);
  15420. }
  15421. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  15422. /// 083d <xPos>.W <yPos>.W
  15423. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  15424. {
  15425. int fd = sd->fd;
  15426. WFIFOHEAD(fd,packet_len(0x83d));
  15427. WFIFOW(fd,0) = 0x83d;
  15428. WFIFOW(fd,2) = x;
  15429. WFIFOW(fd,4) = y;
  15430. WFIFOSET(fd,packet_len(0x83d));
  15431. }
  15432. /// Parse function for packet debugging.
  15433. void clif_parse_debug(int fd,struct map_session_data *sd)
  15434. {
  15435. int cmd, packet_len;
  15436. // clif_parse ensures, that there is at least 2 bytes of data
  15437. cmd = RFIFOW(fd,0);
  15438. if( sd ) {
  15439. packet_len = packet_db[cmd].len;
  15440. if( packet_len == 0 )
  15441. {// unknown
  15442. packet_len = RFIFOREST(fd);
  15443. }
  15444. else if( packet_len == -1 )
  15445. {// variable length
  15446. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  15447. }
  15448. 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);
  15449. }
  15450. else
  15451. {
  15452. packet_len = RFIFOREST(fd);
  15453. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  15454. }
  15455. ShowDump(RFIFOP(fd,0), packet_len);
  15456. }
  15457. /*==========================================
  15458. * Server tells client to display a window similar to Magnifier (item) one
  15459. * Server populates the window with avilable elemental converter options according to player's inventory
  15460. *------------------------------------------*/
  15461. int clif_elementalconverter_list(struct map_session_data *sd) {
  15462. int i,c,view,fd;
  15463. nullpo_ret(sd);
  15464. /// Main client packet processing function
  15465. fd=sd->fd;
  15466. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  15467. WFIFOW(fd, 0)=0x1ad;
  15468. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  15469. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  15470. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  15471. WFIFOW(fd,c*2+ 4)= view;
  15472. else
  15473. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  15474. c++;
  15475. }
  15476. }
  15477. WFIFOW(fd,2) = c*2+4;
  15478. WFIFOSET(fd, WFIFOW(fd,2));
  15479. if (c > 0) {
  15480. sd->menuskill_id = SA_CREATECON;
  15481. sd->menuskill_val = c;
  15482. }
  15483. return 0;
  15484. }
  15485. /**
  15486. * Rune Knight
  15487. **/
  15488. void clif_millenniumshield(struct block_list *bl, short shields) {
  15489. #if PACKETVER >= 20081217
  15490. unsigned char buf[10];
  15491. WBUFW(buf,0) = 0x440;
  15492. WBUFL(buf,2) = bl->id;
  15493. WBUFW(buf,6) = shields;
  15494. WBUFW(buf,8) = 0;
  15495. clif_send(buf,packet_len(0x440),bl,AREA);
  15496. #endif
  15497. }
  15498. /**
  15499. * Warlock
  15500. **/
  15501. /*==========================================
  15502. * Spellbook list [LimitLine/3CeAM]
  15503. *------------------------------------------*/
  15504. int clif_spellbook_list(struct map_session_data *sd)
  15505. {
  15506. int i, c;
  15507. int fd;
  15508. nullpo_ret(sd);
  15509. fd = sd->fd;
  15510. WFIFOHEAD(fd, 8 * 8 + 8);
  15511. WFIFOW(fd,0) = 0x1ad;
  15512. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  15513. {
  15514. if( itemdb_is_spellbook2(sd->inventory.u.items_inventory[i].nameid) )
  15515. {
  15516. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15517. c++;
  15518. }
  15519. }
  15520. if( c > 0 )
  15521. {
  15522. WFIFOW(fd,2) = c * 2 + 4;
  15523. WFIFOSET(fd, WFIFOW(fd, 2));
  15524. sd->menuskill_id = WL_READING_SB;
  15525. sd->menuskill_val = c;
  15526. }
  15527. else{
  15528. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15529. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  15530. }
  15531. return 1;
  15532. }
  15533. /**
  15534. * Mechanic
  15535. **/
  15536. /*==========================================
  15537. * Magic Decoy Material List
  15538. *------------------------------------------*/
  15539. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  15540. int i, c;
  15541. int fd;
  15542. nullpo_ret(sd);
  15543. fd = sd->fd;
  15544. WFIFOHEAD(fd, 8 * 8 + 8);
  15545. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  15546. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  15547. if( itemdb_group_item_exists(IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid) ) {
  15548. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15549. c ++;
  15550. }
  15551. }
  15552. if( c > 0 ) {
  15553. sd->menuskill_id = NC_MAGICDECOY;
  15554. sd->menuskill_val = skill_lv;
  15555. sd->sc.comet_x = x;
  15556. sd->sc.comet_y = y;
  15557. WFIFOW(fd,2) = c * 2 + 4;
  15558. WFIFOSET(fd, WFIFOW(fd, 2));
  15559. } else {
  15560. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  15561. return 0;
  15562. }
  15563. return 1;
  15564. }
  15565. /*==========================================
  15566. * Guillotine Cross Poisons List
  15567. *------------------------------------------*/
  15568. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  15569. int i, c;
  15570. int fd;
  15571. nullpo_ret(sd);
  15572. fd = sd->fd;
  15573. WFIFOHEAD(fd, 8 * 8 + 8);
  15574. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  15575. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  15576. if( itemdb_group_item_exists(IG_POISON, sd->inventory.u.items_inventory[i].nameid) ) {
  15577. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15578. c ++;
  15579. }
  15580. }
  15581. if( c > 0 ) {
  15582. sd->menuskill_id = GC_POISONINGWEAPON;
  15583. sd->menuskill_val = skill_lv;
  15584. WFIFOW(fd,2) = c * 2 + 4;
  15585. WFIFOSET(fd, WFIFOW(fd, 2));
  15586. } else {
  15587. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  15588. return 0;
  15589. }
  15590. return 1;
  15591. }
  15592. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  15593. int clif_autoshadowspell_list(struct map_session_data *sd) {
  15594. int fd, i, c;
  15595. nullpo_ret(sd);
  15596. fd = sd->fd;
  15597. if( !fd )
  15598. return 0;
  15599. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  15600. return 0;
  15601. WFIFOHEAD(fd, 2 * 6 + 4);
  15602. WFIFOW(fd,0) = 0x442;
  15603. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  15604. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  15605. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  15606. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  15607. {
  15608. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  15609. c++;
  15610. }
  15611. if( c > 0 ) {
  15612. WFIFOW(fd,2) = 8 + c * 2;
  15613. WFIFOL(fd,4) = c;
  15614. WFIFOSET(fd,WFIFOW(fd,2));
  15615. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  15616. sd->menuskill_val = c;
  15617. } else {
  15618. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15619. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  15620. }
  15621. return 1;
  15622. }
  15623. /*===========================================
  15624. * Skill list for Four Elemental Analysis
  15625. * and Change Material skills.
  15626. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  15627. *------------------------------------------*/
  15628. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  15629. #if PACKETVER >= 20090922
  15630. int fd = sd->fd;
  15631. nullpo_ret(sd);
  15632. sd->menuskill_id = skill_id; // To prevent hacking.
  15633. sd->menuskill_val = skill_lv;
  15634. if( skill_id == GN_CHANGEMATERIAL )
  15635. skill_lv = 0; // Changematerial
  15636. WFIFOHEAD(fd, packet_len(0x7e3));
  15637. WFIFOW(fd,0) = 0x7e3;
  15638. WFIFOL(fd,2) = skill_lv;
  15639. WFIFOL(fd,4) = 0;
  15640. WFIFOSET(fd, packet_len(0x7e3));
  15641. #endif
  15642. return 1;
  15643. }
  15644. /*==========================================
  15645. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  15646. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  15647. * RFIFOL(fd,2) - type (currently not used)
  15648. *------------------------------------------*/
  15649. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  15650. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15651. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  15652. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  15653. return;
  15654. if( pc_istrading(sd) ) {
  15655. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  15656. clif_menuskill_clear(sd);
  15657. return;
  15658. }
  15659. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  15660. clif_menuskill_clear(sd);
  15661. }
  15662. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  15663. /// 08cf <id>.L <type>.W <num>.W
  15664. void clif_spiritcharm(struct map_session_data *sd) {
  15665. unsigned char buf[10];
  15666. nullpo_retv(sd);
  15667. WBUFW(buf,0) = 0x08cf;
  15668. WBUFL(buf,2) = sd->bl.id;
  15669. WBUFW(buf,6) = sd->spiritcharm_type;
  15670. WBUFW(buf,8) = sd->spiritcharm;
  15671. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  15672. }
  15673. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  15674. /// 0907 <index>.W
  15675. ///
  15676. /// R 0908 <index>.w <type>.b
  15677. /// type:
  15678. /// 0 = move item to personal tab
  15679. /// 1 = move item to normal tab
  15680. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  15681. #if PACKETVER >= 20111122
  15682. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15683. int index = RFIFOW(fd,info->pos[0]) - 2;
  15684. int type = RFIFOB(fd, info->pos[1]);
  15685. /* can't move while dead. */
  15686. if(pc_isdead(sd)) {
  15687. return;
  15688. }
  15689. if (index < 0 || index >= MAX_INVENTORY)
  15690. return;
  15691. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  15692. sd->inventory.u.items_inventory[index].favorite = 0;
  15693. else if( type == 0 )
  15694. sd->inventory.u.items_inventory[index].favorite = 1;
  15695. else
  15696. return;/* nothing to do. */
  15697. clif_favorite_item(sd, index);
  15698. #endif
  15699. }
  15700. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  15701. /// 0900 <index>.W <favorite>.B
  15702. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  15703. int fd = sd->fd;
  15704. WFIFOHEAD(fd,packet_len(0x908));
  15705. WFIFOW(fd,0) = 0x908;
  15706. WFIFOW(fd,2) = index+2;
  15707. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  15708. WFIFOSET(fd,packet_len(0x908));
  15709. }
  15710. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  15711. void clif_snap( struct block_list *bl, short x, short y ) {
  15712. unsigned char buf[10];
  15713. WBUFW(buf,0) = 0x8d2;
  15714. WBUFL(buf,2) = bl->id;
  15715. WBUFW(buf,6) = x;
  15716. WBUFW(buf,8) = y;
  15717. if( disguised(bl) )
  15718. {
  15719. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  15720. WBUFL(buf,2) = -bl->id;
  15721. clif_send(buf, packet_len(0x8d2), bl, SELF);
  15722. } else
  15723. clif_send(buf,packet_len(0x8d2),bl, AREA);
  15724. }
  15725. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  15726. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  15727. #if PACKETVER >= 20120404
  15728. WFIFOHEAD(fd,packet_len(0x977));
  15729. WFIFOW(fd,0) = 0x977;
  15730. WFIFOL(fd,2) = md->bl.id;
  15731. WFIFOL(fd,6) = md->status.hp;
  15732. WFIFOL(fd,10) = md->status.max_hp;
  15733. WFIFOSET(fd,packet_len(0x977));
  15734. #endif
  15735. }
  15736. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  15737. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  15738. return;
  15739. }
  15740. void clif_partytickack(struct map_session_data* sd, bool flag) {
  15741. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  15742. WFIFOW(sd->fd,0) = 0x2c9;
  15743. WFIFOB(sd->fd,2) = flag;
  15744. WFIFOSET(sd->fd, packet_len(0x2c9));
  15745. }
  15746. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  15747. /// 0979 <world name>.24B <char name>.24B
  15748. void clif_ackworldinfo(struct map_session_data* sd) {
  15749. int fd;
  15750. nullpo_retv(sd);
  15751. fd = sd->fd;
  15752. WFIFOHEAD(fd,packet_len(0x979));
  15753. WFIFOW(fd,0)=0x979;
  15754. //AID -> world name ?
  15755. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  15756. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  15757. WFIFOSET(fd,packet_len(0x979));
  15758. }
  15759. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  15760. /// 0978 <AID>.L
  15761. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  15762. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  15763. if(sd)
  15764. clif_ackworldinfo(sd);
  15765. }
  15766. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  15767. /// 0447
  15768. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd) {
  15769. //if(sd)
  15770. ;
  15771. }
  15772. /// req world info (CZ_CLIENT_VERSION)
  15773. /// 044A <version>.L
  15774. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  15775. //if(sd)
  15776. ;
  15777. }
  15778. /// Ranking list
  15779. /// ranking pointlist { <name>.24B <point>.L }*10
  15780. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  15781. struct fame_list* list;
  15782. int i, size = MAX_FAME_LIST;
  15783. switch(rankingtype) {
  15784. case RANK_BLACKSMITH: list = smith_fame_list; break;
  15785. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  15786. case RANK_TAEKWON: list = taekwon_fame_list; break;
  15787. // PK currently unsupported
  15788. case RANK_KILLER: list = NULL; size = 0; break;
  15789. default:
  15790. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  15791. return;
  15792. }
  15793. //Packet size limits this list to 10 elements. [Skotlex]
  15794. for (i = 0; i < min(10,size); i++) {
  15795. if (list[i].id > 0) {
  15796. const char* name;
  15797. if (strcmp(list[i].name, "-") == 0 &&
  15798. (name = map_charid2nick(list[i].id)) != NULL)
  15799. {
  15800. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  15801. } else {
  15802. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  15803. }
  15804. } else {
  15805. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  15806. }
  15807. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  15808. }
  15809. for(;i < 10; i++) { //In case the MAX is less than 10.
  15810. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  15811. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  15812. }
  15813. }
  15814. /// Request for the blacksmith ranklist.
  15815. /// /blacksmith command sends this packet to the server.
  15816. /// 0217 (CZ_BLACKSMITH_RANK)
  15817. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  15818. clif_ranklist(sd,RANK_BLACKSMITH);
  15819. }
  15820. /// Request for the alchemist ranklist.
  15821. /// /alchemist command sends this packet to the server.
  15822. /// 0218 (CZ_ALCHEMIST_RANK)
  15823. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  15824. clif_ranklist(sd,RANK_ALCHEMIST);
  15825. }
  15826. /// Request for the taekwon ranklist.
  15827. /// /taekwon command sends this packet to the server.
  15828. /// 0225 (CZ_TAEKWON_RANK)
  15829. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  15830. clif_ranklist(sd,RANK_TAEKWON);
  15831. }
  15832. /// Request for the killer ranklist.
  15833. /// /pk command sends this packet to the server.
  15834. /// 0237 (CZ_KILLER_RANK)
  15835. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  15836. clif_ranklist(sd,RANK_KILLER);
  15837. }
  15838. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  15839. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  15840. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  15841. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  15842. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  15843. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  15844. enum e_rank rank;
  15845. #if PACKETVER < 20130710
  15846. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  15847. short cmd;
  15848. switch( rankingType ){
  15849. case RANK_BLACKSMITH: cmd = 0x219; break;
  15850. case RANK_ALCHEMIST: cmd = 0x21a; break;
  15851. case RANK_TAEKWON: cmd = 0x226; break;
  15852. case RANK_KILLER: cmd = 0x238; break;
  15853. default:
  15854. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  15855. return;
  15856. }
  15857. // Can be safely casted here, since we validated it before
  15858. rank = (enum e_rank)rankingType;
  15859. WBUFW(buf,0) = cmd;
  15860. clif_sub_ranklist(buf,2,sd,rank);
  15861. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  15862. #else
  15863. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  15864. int mypoint = 0;
  15865. switch( rankingType ){
  15866. case RANK_BLACKSMITH:
  15867. case RANK_ALCHEMIST:
  15868. case RANK_TAEKWON:
  15869. case RANK_KILLER:
  15870. break;
  15871. default:
  15872. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  15873. return;
  15874. }
  15875. // Can be safely casted here, since we validated it before
  15876. rank = (enum e_rank)rankingType;
  15877. WBUFW(buf,0) = 0x97d;
  15878. WBUFW(buf,2) = rank;
  15879. clif_sub_ranklist(buf,4,sd,rank);
  15880. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  15881. case MAPID_BLACKSMITH:
  15882. case MAPID_ALCHEMIST:
  15883. case MAPID_TAEKWON:
  15884. mypoint = sd->status.fame;
  15885. }
  15886. WBUFL(buf,284) = mypoint; //mypoint
  15887. clif_send(buf, 288, &sd->bl, SELF);
  15888. #endif
  15889. }
  15890. /*
  15891. * 097c <type> (CZ_REQ_RANKING)
  15892. * type
  15893. * 0: /blacksmith
  15894. * 1: /alchemist
  15895. * 2: /taekwon
  15896. * 3: /pk
  15897. * */
  15898. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  15899. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15900. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  15901. clif_ranklist(sd,rankingtype);
  15902. }
  15903. /// Updates the fame rank points for the given ranking.
  15904. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  15905. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  15906. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  15907. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  15908. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  15909. int fd=sd->fd;
  15910. #if PACKETVER < 20130710
  15911. short cmd;
  15912. switch(rankingtype){
  15913. case RANK_BLACKSMITH: cmd = 0x21b; break;
  15914. case RANK_ALCHEMIST: cmd = 0x21c; break;
  15915. case RANK_TAEKWON: cmd = 0x224; break;
  15916. default:
  15917. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  15918. return;
  15919. }
  15920. WFIFOHEAD(fd,packet_len(cmd));
  15921. WFIFOW(fd,0) = cmd;
  15922. WFIFOL(fd,2) = point;
  15923. WFIFOL(fd,6) = sd->status.fame;
  15924. WFIFOSET(fd, packet_len(cmd));
  15925. #else
  15926. WFIFOHEAD(fd,packet_len(0x97e));
  15927. WFIFOW(fd,0) = 0x97e;
  15928. WFIFOW(fd,2) = rankingtype;
  15929. WFIFOL(fd,4) = point;
  15930. WFIFOL(fd,8) = sd->status.fame;
  15931. WFIFOSET(fd,packet_len(0x97e));
  15932. #endif
  15933. }
  15934. /**
  15935. * Transmit personal information to player. (rates)
  15936. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  15937. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  15938. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  15939. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  15940. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  15941. * FIXME!
  15942. * - Find/decide for details of EXP, Drop, and Death penalty rates
  15943. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  15944. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  15945. */
  15946. #ifdef VIP_ENABLE
  15947. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  15948. if (sd) {
  15949. struct s_packet_db* info;
  15950. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  15951. int cmd = 0, fd, i = 0;
  15952. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  15953. int details_bexp[PINFO_MAX];
  15954. int details_drop[PINFO_MAX];
  15955. int details_penalty[PINFO_MAX];
  15956. /**
  15957. * Set for EXP
  15958. */
  15959. //0:PCRoom
  15960. details_bexp[0] = map_getmapflag(sd->bl.m, MF_BEXP);
  15961. if (details_bexp[0] == 100 || !details_bexp[0])
  15962. details_bexp[0] = 0;
  15963. else {
  15964. if (details_bexp[0] < 100) {
  15965. details_bexp[0] = 100 - details_bexp[0];
  15966. details_bexp[0] = 0 - details_bexp[0];
  15967. }
  15968. else
  15969. details_bexp[0] = details_bexp[0] - 100;
  15970. }
  15971. //1:Premium
  15972. if (pc_isvip(sd)) {
  15973. details_bexp[1] = battle_config.vip_base_exp_increase;
  15974. if (details_bexp[1] < 0)
  15975. details_bexp[1] = 0 - details_bexp[1];
  15976. }
  15977. else
  15978. details_bexp[1] = 0;
  15979. //2:Server
  15980. details_bexp[2] = battle_config.base_exp_rate;
  15981. if (details_bexp[2] == 100)
  15982. details_bexp[2] = 0;
  15983. else {
  15984. if (details_bexp[2] < 100) {
  15985. details_bexp[2] = 100 - details_bexp[2];
  15986. details_bexp[2] = 0 - details_bexp[2];
  15987. }
  15988. else
  15989. details_bexp[2] = details_bexp[2] - 100;
  15990. }
  15991. //3:TPLUS
  15992. details_bexp[3] = 0;
  15993. /* End - EXP set*/
  15994. /**
  15995. * Set for Drop rate
  15996. */
  15997. //0:PCRoom
  15998. details_drop[0] = 0;
  15999. //1:Premium
  16000. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  16001. if (pc_isvip(sd)) {
  16002. if (details_drop[1] < 0)
  16003. details_drop[1] = 0 - details_drop[1];
  16004. }
  16005. else
  16006. details_drop[1] = 0;
  16007. //2:Server
  16008. details_drop[2] = battle_config.item_rate_common;
  16009. if (details_drop[2] == 100)
  16010. details_drop[2] = 0;
  16011. else {
  16012. if (details_drop[2] < 100) {
  16013. details_drop[2] = 100 - details_drop[2];
  16014. details_drop[2] = 0 - details_drop[2];
  16015. }
  16016. else
  16017. details_drop[2] = details_drop[2] - 100;
  16018. }
  16019. //3:TPLUS
  16020. details_drop[3] = 0;
  16021. /* End - Drop set*/
  16022. /**
  16023. * Set for Penalty rate
  16024. */
  16025. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16026. //0:PCRoom
  16027. details_penalty[0] = 0;
  16028. //1:Premium
  16029. if (pc_isvip(sd)) {
  16030. details_penalty[1] = battle_config.vip_exp_penalty_base;
  16031. if (details_penalty[1] == 100)
  16032. details_penalty[1] = 0;
  16033. else {
  16034. if (details_penalty[1] < 100) {
  16035. details_penalty[1] = 100 - details_penalty[1];
  16036. details_penalty[1] = 0 - details_penalty[1];
  16037. }
  16038. else
  16039. details_penalty[1] = details_penalty[1] - 100;
  16040. }
  16041. }
  16042. else
  16043. details_penalty[1] = 0;
  16044. //2:Server
  16045. details_penalty[2] = battle_config.death_penalty_base;
  16046. if (details_penalty[2] == 100)
  16047. details_penalty[2] = 0;
  16048. else {
  16049. if (details_penalty[2] < 100) {
  16050. details_penalty[2] = 100 - details_penalty[2];
  16051. details_penalty[2] = 0 - details_penalty[2];
  16052. }
  16053. else
  16054. details_penalty[2] = details_penalty[2] - 100;
  16055. }
  16056. //3:TPLUS
  16057. details_penalty[3] = 0;
  16058. /* End - Penalty set*/
  16059. cmd = packet_db_ack[cmdtype];
  16060. info = &packet_db[cmd];
  16061. len = info->len; //this is the base len without details
  16062. if(!len) return; //version as packet disable
  16063. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  16064. szdetails = 7;
  16065. factor = 1;
  16066. }
  16067. else if (cmd == 0x097b) {
  16068. tot_baseexp *= factor;
  16069. tot_drop *= factor;
  16070. tot_penalty *= factor;
  16071. }
  16072. fd = sd->fd;
  16073. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  16074. WFIFOW(fd,0) = cmd;
  16075. for (i = 0; i < maxinfotype; i++) {
  16076. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16077. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  16078. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  16079. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  16080. tot_baseexp += details_bexp[i]*factor;
  16081. tot_drop += details_penalty[i]*factor;
  16082. tot_penalty += details_drop[i]*factor;
  16083. len += szdetails;
  16084. }
  16085. WFIFOW(fd,info->pos[0]) = len; //packetlen
  16086. if (cmd == 0x08cb) { //0x08cb version
  16087. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  16088. WFIFOW(fd,info->pos[2]) = tot_drop;
  16089. WFIFOW(fd,info->pos[3]) = tot_penalty;
  16090. }
  16091. else { //2013-08-07aRagexe uses 0x097b
  16092. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  16093. WFIFOL(fd,info->pos[2]) = tot_drop;
  16094. WFIFOL(fd,info->pos[3]) = tot_penalty;
  16095. }
  16096. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  16097. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  16098. WFIFOSET(fd,len);
  16099. }
  16100. }
  16101. #endif
  16102. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  16103. char cmd[30];
  16104. int t_aid = RFIFOL(fd,2);
  16105. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16106. is_atcommand(fd, sd, cmd, 1);
  16107. }
  16108. /**
  16109. * Marks Crimson Marker target on mini-map to the caster
  16110. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16111. * @param fd
  16112. * @param bl Crimson Marker target
  16113. **/
  16114. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  16115. struct s_packet_db* info;
  16116. int cmd = 0;
  16117. int16 len;
  16118. unsigned char buf[11];
  16119. nullpo_retv(sd);
  16120. cmd = packet_db_ack[ZC_C_MARKERINFO];
  16121. if (!cmd)
  16122. cmd = 0x09C1; //default
  16123. info = &packet_db[cmd];
  16124. if (!(len = info->len))
  16125. return;
  16126. WBUFW(buf, 0) = cmd;
  16127. WBUFL(buf, info->pos[0]) = bl->id;
  16128. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  16129. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  16130. clif_send(buf, len, &sd->bl, SELF);
  16131. }
  16132. /**
  16133. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16134. **/
  16135. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  16136. struct s_packet_db *info = NULL;
  16137. int cmd = 0;
  16138. nullpo_retv(sd);
  16139. cmd = packet_db_ack[ZC_NOTIFY_BIND_ON_EQUIP];
  16140. info = &packet_db[cmd];
  16141. if (!cmd || !info->len)
  16142. return;
  16143. WFIFOHEAD(sd->fd, info->len);
  16144. WFIFOW(sd->fd, 0) = cmd;
  16145. WFIFOW(sd->fd, info->pos[0]) = n+2;
  16146. WFIFOSET(sd->fd, info->len);
  16147. }
  16148. /**
  16149. * [Ind/Hercules]
  16150. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16151. **/
  16152. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16153. char buf[256];
  16154. size_t len;
  16155. nullpo_retv(bl);
  16156. if(!message)
  16157. return;
  16158. len = strlen(message)+1;
  16159. if( len > sizeof(buf)-8 ) {
  16160. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%d).\n", message, len);
  16161. len = sizeof(buf)-8;
  16162. }
  16163. WBUFW(buf,0) = 0x8b3;
  16164. WBUFW(buf,2) = (uint16)(len+8);
  16165. WBUFL(buf,4) = bl->id;
  16166. safestrncpy(WBUFCP(buf,8), message, len);
  16167. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16168. }
  16169. /**
  16170. * [Ind/Hercules]
  16171. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16172. **/
  16173. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16174. unsigned char buf[10];
  16175. nullpo_retv(sd);
  16176. WBUFW(buf,0) = 0x7fc;
  16177. WBUFL(buf,2) = prev_leader_aid;
  16178. WBUFL(buf,6) = new_leader_aid;
  16179. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16180. }
  16181. /**
  16182. * Sends a clan message to a player
  16183. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16184. **/
  16185. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16186. #if PACKETVER >= 20131223
  16187. struct map_session_data *sd;
  16188. uint8 buf[256];
  16189. if( len == 0 ){
  16190. return;
  16191. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16192. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%d, clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16193. len = sizeof(buf)-5-NAME_LENGTH;
  16194. }
  16195. WBUFW(buf, 0) = 0x98e;
  16196. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16197. // 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
  16198. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16199. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16200. if((sd = clan_getavailablesd(clan)) != NULL)
  16201. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16202. #endif
  16203. }
  16204. /**
  16205. * Parses a clan message from a player.
  16206. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16207. **/
  16208. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  16209. #if PACKETVER >= 20131223
  16210. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16211. // validate packet and retrieve name and message
  16212. if( !clif_process_message(sd, false, name, message, output ) )
  16213. return;
  16214. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16215. #endif
  16216. }
  16217. /**
  16218. * Sends the basic clan informations to the client.
  16219. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16220. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16221. **/
  16222. void clif_clan_basicinfo( struct map_session_data *sd ){
  16223. #if PACKETVER >= 20131223
  16224. int fd, offset, length, i, flag;
  16225. struct clan* clan;
  16226. char mapname[MAP_NAME_LENGTH_EXT];
  16227. nullpo_retv( sd );
  16228. nullpo_retv( clan = sd->clan );
  16229. // Check if the player has a valid session and is not autotrading
  16230. if( !clif_session_isValid( sd ) ){
  16231. return;
  16232. }
  16233. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16234. fd = sd->fd;
  16235. WFIFOHEAD(fd,length);
  16236. memset( WFIFOP(fd, 0), 0, length );
  16237. WFIFOW( fd, 0 ) = 0x98a;
  16238. WFIFOL( fd, 4 ) = clan->id;
  16239. offset = 8;
  16240. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16241. offset += NAME_LENGTH;
  16242. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16243. offset += NAME_LENGTH;
  16244. mapindex_getmapname_ext( clan->map, mapname );
  16245. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16246. offset += MAP_NAME_LENGTH_EXT;
  16247. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16248. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16249. for( flag = 0; flag < 2; flag++ ){
  16250. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16251. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16252. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16253. offset += NAME_LENGTH;
  16254. }
  16255. }
  16256. }
  16257. WFIFOW( fd, 2 ) = offset;
  16258. WFIFOSET(fd,offset);
  16259. #endif
  16260. }
  16261. /**
  16262. * Updates the online and maximum player count of a clan.
  16263. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16264. **/
  16265. void clif_clan_onlinecount( struct clan* clan ){
  16266. #if PACKETVER >= 20131223
  16267. uint8 buf[6];
  16268. struct map_session_data *sd;
  16269. WBUFW(buf,0) = 0x988;
  16270. WBUFW(buf,2) = clan->connect_member;
  16271. WBUFW(buf,4) = clan->max_member;
  16272. if((sd = clan_getavailablesd(clan)) != NULL)
  16273. clif_send(buf, 6, &sd->bl, CLAN);
  16274. #endif
  16275. }
  16276. /**
  16277. * Notifies the client that the player has left his clan.
  16278. * 0989 (ZC_ACK_CLAN_LEAVE)
  16279. **/
  16280. void clif_clan_leave( struct map_session_data* sd ){
  16281. #if PACKETVER >= 20131223
  16282. int fd;
  16283. nullpo_retv( sd );
  16284. if( !clif_session_isValid( sd ) ){
  16285. return;
  16286. }
  16287. fd = sd->fd;
  16288. WFIFOHEAD(fd,2);
  16289. WFIFOW(fd,0) = 0x989;
  16290. WFIFOSET(fd,2);
  16291. #endif
  16292. }
  16293. /**
  16294. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16295. * 0A2F <result>.B <title_id>.L
  16296. */
  16297. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  16298. {
  16299. #if PACKETVER >= 20150513
  16300. int fd;
  16301. nullpo_retv(sd);
  16302. if (!clif_session_isValid(sd))
  16303. return;
  16304. fd = sd->fd;
  16305. WFIFOHEAD(fd, packet_len(0xa2f));
  16306. WFIFOW(fd, 0) = 0xa2f;
  16307. WFIFOB(fd, 2) = result;
  16308. WFIFOL(fd, 3) = title_id;
  16309. WFIFOSET(fd, packet_len(0xa2f));
  16310. #endif
  16311. }
  16312. /**
  16313. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16314. * 0A2E <title_id>.L
  16315. */
  16316. void clif_parse_change_title(int fd, struct map_session_data *sd)
  16317. {
  16318. int title_id;
  16319. nullpo_retv(sd);
  16320. title_id = RFIFOL(fd, 2);
  16321. if( title_id == sd->status.title_id ){
  16322. // It is exactly the same as the old one
  16323. return;
  16324. }else if( title_id <= 0 ){
  16325. sd->status.title_id = 0;
  16326. }else{
  16327. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  16328. clif_change_title_ack(sd, 1, title_id);
  16329. return;
  16330. }
  16331. sd->status.title_id = title_id;
  16332. }
  16333. clif_name_area(&sd->bl);
  16334. clif_change_title_ack(sd, 0, title_id);
  16335. }
  16336. #ifdef DUMP_UNKNOWN_PACKET
  16337. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  16338. {
  16339. const char* packet_txt = "save/packet.txt";
  16340. FILE* fp;
  16341. time_t time_server;
  16342. struct tm *datetime;
  16343. char datestr[512];
  16344. time(&time_server); // get time in seconds since 1/1/1970
  16345. datetime = localtime(&time_server); // convert seconds in structure
  16346. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  16347. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  16348. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  16349. if( sd ) {
  16350. 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);
  16351. } else {
  16352. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16353. }
  16354. WriteDump(fp, RFIFOP(fd,0), packet_len);
  16355. fprintf(fp, "\n");
  16356. fclose(fp);
  16357. } else {
  16358. ShowError("Failed to write '%s'.\n", packet_txt);
  16359. // Dump on console instead
  16360. if( sd ) {
  16361. 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);
  16362. } else {
  16363. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16364. }
  16365. ShowDump(RFIFOP(fd,0), packet_len);
  16366. }
  16367. }
  16368. #endif
  16369. /// Roulette System
  16370. /// Author: Yommy
  16371. /// Opens the roulette window
  16372. /// 0A1A <result>.B <serial>.L <stage>.B <price index>.B <additional item id>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_OPEN_ROULETTE)
  16373. void clif_roulette_open( struct map_session_data* sd ){
  16374. nullpo_retv(sd);
  16375. int fd = sd->fd;
  16376. WFIFOHEAD(fd,packet_len(0xa1a));
  16377. WFIFOW(fd,0) = 0xa1a;
  16378. WFIFOB(fd,2) = 0; // result
  16379. WFIFOL(fd,3) = 0; // serial
  16380. WFIFOB(fd,7) = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  16381. WFIFOB(fd,8) = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  16382. WFIFOW(fd,9) = -1; //! TODO: Display bonus item
  16383. WFIFOL(fd,11) = sd->roulette_point.gold;
  16384. WFIFOL(fd,15) = sd->roulette_point.silver;
  16385. WFIFOL(fd,19) = sd->roulette_point.bronze;
  16386. WFIFOSET(fd,packet_len(0xa1a));
  16387. }
  16388. /// Request to open the roulette window
  16389. /// 0A19 (CZ_REQ_OPEN_ROULETTE)
  16390. void clif_parse_roulette_open( int fd, struct map_session_data* sd ){
  16391. nullpo_retv(sd);
  16392. if (!battle_config.feature_roulette) {
  16393. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16394. return;
  16395. }
  16396. clif_roulette_open(sd);
  16397. }
  16398. /// Sends the info about the available roulette rewards to the client
  16399. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.W <amount>.W } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO)
  16400. /// 0A1C <length>.W <serial>.L { { <level>.W <column>.W <item>.L <amount>.L } * MAX_ROULETTE_COLUMNS } * MAX_ROULETTE_LEVEL (ZC_ACK_ROULEITTE_INFO) >= 20180516
  16401. void clif_roulette_info( struct map_session_data* sd ){
  16402. nullpo_retv(sd);
  16403. int fd = sd->fd;
  16404. int len = 8; // Initialize to header size
  16405. #if PACKETVER < 20180516
  16406. int size = 8;
  16407. #else
  16408. int size = 12;
  16409. #endif
  16410. for( int i = 0; i < MAX_ROULETTE_LEVEL; i++ ){
  16411. len += (MAX_ROULETTE_COLUMNS - i) * size;
  16412. }
  16413. WFIFOHEAD(fd,len);
  16414. WFIFOW(fd,0) = 0xa1c;
  16415. WFIFOW(fd,2) = len;
  16416. WFIFOL(fd,4) = 1; // serial
  16417. for(int i = 0, offset = 8; i < MAX_ROULETTE_LEVEL; i++) {
  16418. for(int j = 0; j < MAX_ROULETTE_COLUMNS - i; j++) {
  16419. WFIFOW(fd,offset + 0) = i;
  16420. WFIFOW(fd,offset + 2) = j;
  16421. #if PACKETVER < 20180516
  16422. WFIFOW(fd,offset + 4) = rd.nameid[i][j];
  16423. WFIFOW(fd,offset + 6) = rd.qty[i][j];
  16424. #else
  16425. WFIFOL(fd,offset + 4) = rd.nameid[i][j];
  16426. WFIFOL(fd,offset + 8) = rd.qty[i][j];
  16427. #endif
  16428. offset += size;
  16429. }
  16430. }
  16431. WFIFOSET(fd,len);
  16432. }
  16433. /// Request the roulette reward data
  16434. /// 0A1B (CZ_REQ_ROULETTE_INFO)
  16435. void clif_parse_roulette_info( int fd, struct map_session_data* sd ){
  16436. nullpo_retv(sd);
  16437. if (!battle_config.feature_roulette) {
  16438. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16439. return;
  16440. }
  16441. clif_roulette_info(sd);
  16442. }
  16443. /// Notification of the client that the roulette window was closed
  16444. /// 0A1D (CZ_REQ_CLOSE_ROULETTE)
  16445. void clif_parse_roulette_close( int fd, struct map_session_data* sd ){
  16446. nullpo_retv(sd);
  16447. if (!battle_config.feature_roulette) {
  16448. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16449. return;
  16450. }
  16451. // What do we need this for? (other than state tracking), game client closes the window without our response.
  16452. }
  16453. /// Response to a item reward request
  16454. /// 0A22 <type>.B <bonus item>.W (ZC_RECV_ROULETTE_ITEM)
  16455. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  16456. #if PACKETVER >= 20141016
  16457. nullpo_retv(sd);
  16458. int fd = sd->fd;
  16459. WFIFOHEAD(fd,packet_len(0xa22));
  16460. WFIFOW(fd,0) = 0xa22;
  16461. WFIFOB(fd,2) = type;
  16462. WFIFOW(fd,3) = 0; //! TODO: Additional item
  16463. WFIFOSET(fd,packet_len(0xa22));
  16464. #endif
  16465. }
  16466. /**
  16467. * Claim roulette reward
  16468. * @param sd Player
  16469. * @return 0:Success
  16470. **/
  16471. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  16472. struct item it;
  16473. uint8 res = 1;
  16474. nullpo_retr(1, sd);
  16475. if (sd->roulette.prizeIdx < 0)
  16476. return RECV_ITEM_FAILED;
  16477. memset(&it, 0, sizeof(it));
  16478. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  16479. it.identify = 1;
  16480. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  16481. ; // onSuccess
  16482. }
  16483. sd->roulette.claimPrize = false;
  16484. sd->roulette.prizeStage = 0;
  16485. sd->roulette.prizeIdx = -1;
  16486. sd->roulette.stage = 0;
  16487. return res;
  16488. }
  16489. /// Update Roulette window with current stats
  16490. /// 0A20 <result>.B <stage>.W <price index>.W <bonus item>.W <gold>.L <silver>.L <bronze>.L (ZC_ACK_GENERATE_ROULETTE)
  16491. void clif_roulette_generate( struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, short bonusItemID ){
  16492. nullpo_retv(sd);
  16493. int fd = sd->fd;
  16494. WFIFOHEAD(fd,packet_len(0xa20));
  16495. WFIFOW(fd,0) = 0xa20;
  16496. WFIFOB(fd,2) = result;
  16497. WFIFOW(fd,3) = stage;
  16498. WFIFOW(fd,5) = prizeIdx;
  16499. WFIFOW(fd,7) = bonusItemID;
  16500. WFIFOL(fd,9) = sd->roulette_point.gold;
  16501. WFIFOL(fd,13) = sd->roulette_point.silver;
  16502. WFIFOL(fd,17) = sd->roulette_point.bronze;
  16503. WFIFOSET(fd,packet_len(0xa20));
  16504. }
  16505. /// Request to start the roulette
  16506. /// 0A1F (CZ_REQ_GENERATE_ROULETTE)
  16507. void clif_parse_roulette_generate( int fd, struct map_session_data* sd ){
  16508. enum GENERATE_ROULETTE_ACK result;
  16509. nullpo_retv(sd);
  16510. if (!battle_config.feature_roulette) {
  16511. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16512. return;
  16513. }
  16514. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16515. return;
  16516. }
  16517. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL){
  16518. sd->roulette.stage = 0;
  16519. sd->roulette.claimPrize = false;
  16520. sd->roulette.prizeStage = 0;
  16521. sd->roulette.prizeIdx = -1;
  16522. }
  16523. if( !sd->roulette.stage && sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10 ){
  16524. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  16525. }else{
  16526. if (!sd->roulette.stage) {
  16527. if (sd->roulette_point.bronze > 0) {
  16528. sd->roulette_point.bronze -= 1;
  16529. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  16530. } else if (sd->roulette_point.silver > 9) {
  16531. sd->roulette_point.silver -= 10;
  16532. sd->roulette.stage = 2;
  16533. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  16534. } else if (sd->roulette_point.gold > 9) {
  16535. sd->roulette_point.gold -= 10;
  16536. sd->roulette.stage = 4;
  16537. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  16538. }
  16539. }
  16540. sd->roulette.prizeStage = sd->roulette.stage;
  16541. sd->roulette.prizeIdx = rnd()%rd.items[sd->roulette.stage];
  16542. sd->roulette.claimPrize = true;
  16543. sd->roulette.tick = gettick() + max( 1, ( MAX_ROULETTE_COLUMNS - sd->roulette.prizeStage - 3 ) ) * 1000;
  16544. if( rd.flag[sd->roulette.stage][sd->roulette.prizeIdx]&1 ){
  16545. result = GENERATE_ROULETTE_LOSING;
  16546. sd->roulette.stage = 0;
  16547. }else{
  16548. result = GENERATE_ROULETTE_SUCCESS;
  16549. sd->roulette.stage++;
  16550. }
  16551. }
  16552. clif_roulette_generate(sd,result,sd->roulette.prizeStage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  16553. }
  16554. /// Request to claim a prize
  16555. /// 0A21 (CZ_RECV_ROULETTE_ITEM)
  16556. void clif_parse_roulette_item( int fd, struct map_session_data* sd ){
  16557. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  16558. nullpo_retv(sd);
  16559. if (!battle_config.feature_roulette) {
  16560. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16561. return;
  16562. }
  16563. if( sd->roulette.tick && DIFF_TICK( sd->roulette.tick, gettick() ) > 0 ){
  16564. return;
  16565. }
  16566. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  16567. switch (clif_roulette_getitem(sd)) {
  16568. case ADDITEM_SUCCESS:
  16569. type = RECV_ITEM_SUCCESS;
  16570. break;
  16571. case ADDITEM_INVALID:
  16572. case ADDITEM_OVERITEM:
  16573. case ADDITEM_OVERAMOUNT:
  16574. type = RECV_ITEM_OVERCOUNT;
  16575. break;
  16576. case ADDITEM_OVERWEIGHT:
  16577. type = RECV_ITEM_OVERWEIGHT;
  16578. break;
  16579. case ADDITEM_STACKLIMIT:
  16580. default:
  16581. type = RECV_ITEM_FAILED;
  16582. break;
  16583. }
  16584. }
  16585. clif_roulette_recvitem_ack(sd,type);
  16586. }
  16587. /// MERGE ITEM
  16588. /**
  16589. * Acknowledge the client about item merger result
  16590. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  16591. * @param fd
  16592. * @param sd
  16593. **/
  16594. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  16595. unsigned char buf[9];
  16596. struct s_packet_db *info = NULL;
  16597. short cmd = 0;
  16598. nullpo_retv(sd);
  16599. if (!clif_session_isValid(sd))
  16600. return;
  16601. if (!(cmd = packet_db_ack[ZC_ACK_MERGE_ITEM]))
  16602. return;
  16603. if (!(info = &packet_db[cmd]) || info->len == 0)
  16604. return;
  16605. WBUFW(buf, 0) = cmd;
  16606. WBUFW(buf, info->pos[0]) = index;
  16607. WBUFW(buf, info->pos[1]) = count;
  16608. WBUFB(buf, info->pos[2]) = type;
  16609. clif_send(buf, info->len, &sd->bl, SELF);
  16610. }
  16611. /**
  16612. * Check if item has the pair to be merged
  16613. * @param sd
  16614. * @param it Item
  16615. * @return True if has pair, False if not
  16616. **/
  16617. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  16618. struct item *it_;
  16619. unsigned short i;
  16620. nullpo_retr(false, sd);
  16621. 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);
  16622. if (i < MAX_INVENTORY)
  16623. return true;
  16624. return false;
  16625. }
  16626. /**
  16627. * Check if item can be merged
  16628. * @param id Item Data
  16629. * @param it Item
  16630. * @return True if can be merged, False if not
  16631. **/
  16632. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  16633. if (!id || !it)
  16634. return false;
  16635. if (id->type == IT_CASH)
  16636. return false;
  16637. if (!itemdb_isstackable2(id))
  16638. return false;
  16639. if (itemdb_isspecial(it->card[0]))
  16640. return false;
  16641. if (!it->unique_id)
  16642. return false;
  16643. return true;
  16644. }
  16645. /**
  16646. * Open available item to be merged.
  16647. * Only show 1 item in 1 process.
  16648. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  16649. * @param sd
  16650. **/
  16651. void clif_merge_item_open(struct map_session_data *sd) {
  16652. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  16653. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  16654. int len = 0;
  16655. struct s_packet_db *info = NULL;
  16656. struct item *it;
  16657. nullpo_retv(sd);
  16658. if (!clif_session_isValid(sd))
  16659. return;
  16660. if (!(cmd = packet_db_ack[ZC_MERGE_ITEM_OPEN]))
  16661. return;
  16662. if (!(info = &packet_db[cmd]) || info->len == 0)
  16663. return;
  16664. // Get entries
  16665. for (i = 0; i < MAX_INVENTORY; i++) {
  16666. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->inventory.u.items_inventory[i])))
  16667. continue;
  16668. if (clif_merge_item_has_pair(sd, it))
  16669. indexes[n++] = i;
  16670. }
  16671. if (n < 2) { // No item need to be merged
  16672. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16673. return;
  16674. }
  16675. WBUFW(buf, 0) = cmd;
  16676. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  16677. for (i = 0; i < n; i++) {
  16678. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  16679. }
  16680. clif_send(buf, len, &sd->bl, SELF);
  16681. }
  16682. /**
  16683. * Process item merger
  16684. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  16685. * @param fd
  16686. * @param sd
  16687. **/
  16688. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  16689. struct s_packet_db *info = NULL;
  16690. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  16691. unsigned int count = 0;
  16692. struct item_data *id = NULL;
  16693. nullpo_retv(sd);
  16694. if (!clif_session_isValid(sd))
  16695. return;
  16696. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  16697. return;
  16698. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  16699. if (n < 2) { // No item need to be merged
  16700. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16701. return;
  16702. }
  16703. for (i = 0, j = 0; i < n; i++) {
  16704. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  16705. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  16706. continue;
  16707. indexes[j] = idx;
  16708. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  16709. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  16710. return;
  16711. }
  16712. count += sd->inventory.u.items_inventory[idx].amount;
  16713. j++;
  16714. }
  16715. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  16716. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16717. return;
  16718. }
  16719. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  16720. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  16721. return;
  16722. }
  16723. // Merrrrge!!!!
  16724. for (i = 1; i < n; i++) {
  16725. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  16726. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  16727. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  16728. sd->inventory_data[idx] = NULL;
  16729. clif_delitem(sd, idx, amt, 0);
  16730. }
  16731. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  16732. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  16733. }
  16734. /**
  16735. * Cancel item merge
  16736. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  16737. * @param fd
  16738. * @param sd
  16739. **/
  16740. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  16741. return; // Nothing todo yet
  16742. }
  16743. /**
  16744. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16745. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16746. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  16747. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  16748. **/
  16749. void clif_broadcast_obtain_special_item(const char *char_name, unsigned short nameid, unsigned short container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type) {
  16750. unsigned char buf[9 + NAME_LENGTH * 2];
  16751. unsigned short cmd = 0;
  16752. struct s_packet_db *info = NULL;
  16753. if (!(cmd = packet_db_ack[ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN]))
  16754. return;
  16755. if (!(info = &packet_db[cmd]) || info->len == 0)
  16756. return;
  16757. WBUFW(buf, 0) = 0x7fd;
  16758. WBUFB(buf, 4) = type;
  16759. WBUFW(buf, 5) = nameid;
  16760. WBUFB(buf, 7) = NAME_LENGTH;
  16761. if (battle_config.broadcast_hide_name) {
  16762. std::string dispname = std::string(char_name);
  16763. int hide = min(battle_config.broadcast_hide_name, dispname.length() - 1);
  16764. dispname.replace(dispname.length() - hide, hide, hide, '*');
  16765. safestrncpy(WBUFCP(buf, 8), dispname.c_str(), NAME_LENGTH);
  16766. }
  16767. else
  16768. safestrncpy(WBUFCP(buf, 8), char_name, NAME_LENGTH);
  16769. switch (type) {
  16770. case ITEMOBTAIN_TYPE_BOXITEM:
  16771. WBUFW(buf, 2) = 11 + NAME_LENGTH;
  16772. WBUFB(buf, 8 + NAME_LENGTH) = 0;
  16773. WBUFW(buf, 9 + NAME_LENGTH) = container;
  16774. break;
  16775. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  16776. {
  16777. struct mob_db *db = mob_db(container);
  16778. WBUFW(buf, 2) = 9 + NAME_LENGTH * 2;
  16779. WBUFB(buf, 8 + NAME_LENGTH) = NAME_LENGTH;
  16780. safestrncpy(WBUFCP(buf, 9 + NAME_LENGTH), db->name, NAME_LENGTH);
  16781. }
  16782. break;
  16783. case ITEMOBTAIN_TYPE_NPC:
  16784. default:
  16785. WBUFW(buf, 2) = 8 + NAME_LENGTH;
  16786. break;
  16787. }
  16788. clif_send(buf, WBUFW(buf, 2), NULL, ALL_CLIENT);
  16789. }
  16790. /// Show body view windows (ZC_DRESSROOM_OPEN).
  16791. /// 0A02 <view>.W
  16792. /// Value <flag> has the following effects:
  16793. /// 1: Open a Dress Room window.
  16794. void clif_dressing_room(struct map_session_data *sd, int flag) {
  16795. #if PACKETVER >= 20150513
  16796. int fd = sd->fd;
  16797. nullpo_retv(sd);
  16798. WFIFOHEAD(fd, packet_len(0xa02));
  16799. WFIFOW(fd,0) = 0xa02;
  16800. WFIFOW(fd,2) = flag;
  16801. WFIFOSET(fd, packet_len(0xa02));
  16802. #endif
  16803. }
  16804. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  16805. /// 0A35 <result>.W
  16806. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  16807. #if PACKETVER >= 20150513
  16808. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  16809. // Ignore the request
  16810. // - Invalid item index
  16811. // - Invalid item ID or item doesn't exist
  16812. // - Item is already identified
  16813. if (idx < 0 || idx >= MAX_INVENTORY ||
  16814. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  16815. sd->inventory.u.items_inventory[idx].identify)
  16816. return;
  16817. // Ignore the request - No magnifiers in inventory
  16818. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  16819. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  16820. return;
  16821. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  16822. return;
  16823. skill_identify(sd, idx);
  16824. #endif
  16825. }
  16826. /// Starts navigation to the given target on client side
  16827. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  16828. #if PACKETVER >= 20111010
  16829. int fd = sd->fd;
  16830. WFIFOHEAD(fd,27);
  16831. WFIFOW(fd,0) = 0x08e2;
  16832. // How detailed will our navigation be?
  16833. if( mob_id > 0 ){
  16834. x = 0;
  16835. y = 0;
  16836. WFIFOB(fd,2) = 3; // monster with destination field
  16837. }else if( x > 0 && y > 0 ){
  16838. WFIFOB(fd,2) = 0; // with coordinates
  16839. }else{
  16840. x = 0;
  16841. y = 0;
  16842. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  16843. }
  16844. // Which services can be used for transportation?
  16845. WFIFOB(fd,3) = flag;
  16846. // If this flag is set, the navigation window will not be opened up
  16847. WFIFOB(fd,4) = hideWindow;
  16848. // Target map
  16849. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  16850. // Target x
  16851. WFIFOW(fd,21) = x;
  16852. // Target y
  16853. WFIFOW(fd,23) = y;
  16854. // Target monster ID
  16855. WFIFOW(fd,25) = mob_id;
  16856. WFIFOSET(fd,27);
  16857. #endif
  16858. }
  16859. /// Send hat effects to the client (ZC_HAT_EFFECT).
  16860. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  16861. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  16862. #if PACKETVER >= 20150513
  16863. unsigned char* buf;
  16864. int len,i;
  16865. struct map_session_data *tsd;
  16866. struct block_list* tbl;
  16867. if( target == SELF ){
  16868. tsd = BL_CAST(BL_PC,bl);
  16869. tbl = &sd->bl;
  16870. }else{
  16871. tsd = sd;
  16872. tbl = bl;
  16873. }
  16874. if( !tsd->hatEffectCount )
  16875. return;
  16876. len = 9 + tsd->hatEffectCount * 2;
  16877. buf = (unsigned char*)aMalloc( len );
  16878. WBUFW(buf,0) = 0xa3b;
  16879. WBUFW(buf,2) = len;
  16880. WBUFL(buf,4) = tsd->bl.id;
  16881. WBUFB(buf,8) = 1;
  16882. for( i = 0; i < tsd->hatEffectCount; i++ ){
  16883. WBUFW(buf,9+i*2) = tsd->hatEffectIDs[i];
  16884. }
  16885. clif_send(buf, len,tbl,target);
  16886. aFree(buf);
  16887. #endif
  16888. }
  16889. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  16890. #if PACKETVER >= 20150513
  16891. unsigned char buf[13];
  16892. WBUFW(buf,0) = 0xa3b;
  16893. WBUFW(buf,2) = 13;
  16894. WBUFL(buf,4) = sd->bl.id;
  16895. WBUFB(buf,8) = enable;
  16896. WBUFL(buf,9) = effectId;
  16897. clif_send(buf,13,&sd->bl,AREA);
  16898. #endif
  16899. }
  16900. /// Notify the client that a sale has started
  16901. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  16902. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  16903. #if PACKETVER_SUPPORTS_SALES
  16904. unsigned char buf[8];
  16905. WBUFW(buf, 0) = 0x9b2;
  16906. WBUFW(buf, 2) = sale_item->nameid;
  16907. WBUFL(buf, 4) = (uint32)(sale_item->end - time(NULL)); // time in S
  16908. clif_send(buf, 8, bl, target);
  16909. #endif
  16910. }
  16911. /// Notify the clien that a sale has ended
  16912. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  16913. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  16914. #if PACKETVER_SUPPORTS_SALES
  16915. unsigned char buf[4];
  16916. WBUFW(buf, 0) = 0x9b3;
  16917. WBUFW(buf, 2) = sale_item->nameid;
  16918. clif_send(buf, 4, bl, target);
  16919. #endif
  16920. }
  16921. /// Update the remaining amount of a sale item.
  16922. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  16923. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  16924. #if PACKETVER_SUPPORTS_SALES
  16925. unsigned char buf[8];
  16926. WBUFW(buf, 0) = 0x9c4;
  16927. WBUFW(buf, 2) = sale_item->nameid;
  16928. WBUFL(buf, 4) = sale_item->amount;
  16929. clif_send(buf, 8, bl, target);
  16930. #endif
  16931. }
  16932. /// The client requested a refresh of the current remaining count of a sale item
  16933. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  16934. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  16935. #if PACKETVER_SUPPORTS_SALES
  16936. struct sale_item_data* sale;
  16937. if( RFIFOL(fd, 2) != sd->status.account_id ){
  16938. return;
  16939. }
  16940. sale = sale_find_item( RFIFOW(fd, 6), true );
  16941. if( sale == NULL ){
  16942. return;
  16943. }
  16944. clif_sale_amount(sale, &sd->bl, SELF);
  16945. #endif
  16946. }
  16947. /// Opens the sale administration window on the client
  16948. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  16949. void clif_sale_open( struct map_session_data* sd ){
  16950. #if PACKETVER_SUPPORTS_SALES
  16951. nullpo_retv(sd);
  16952. if( sd->state.sale_open ){
  16953. return;
  16954. }
  16955. sd->state.sale_open = true;
  16956. int fd = sd->fd;
  16957. WFIFOHEAD(fd, 2);
  16958. WFIFOW(fd, 0) = 0x9b5;
  16959. WFIFOSET(fd, 2);
  16960. #endif
  16961. }
  16962. /// Client request to open the sale administration window.
  16963. /// This is sent by /limitedsale
  16964. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  16965. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  16966. #if PACKETVER_SUPPORTS_SALES
  16967. nullpo_retv(sd);
  16968. if( RFIFOL(fd, 2) != sd->status.account_id ){
  16969. return;
  16970. }
  16971. char command[CHAT_SIZE_MAX];
  16972. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  16973. is_atcommand(fd, sd, command, 1);
  16974. #endif
  16975. }
  16976. /// Closes the sale administration window on the client.
  16977. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  16978. void clif_sale_close(struct map_session_data* sd) {
  16979. #if PACKETVER_SUPPORTS_SALES
  16980. nullpo_retv(sd);
  16981. if( !sd->state.sale_open ){
  16982. return;
  16983. }
  16984. sd->state.sale_open = false;
  16985. int fd = sd->fd;
  16986. WFIFOHEAD(fd, 2);
  16987. WFIFOW(fd, 0) = 0x9bd;
  16988. WFIFOSET(fd, 2);
  16989. #endif
  16990. }
  16991. /// Client request to close the sale administration window.
  16992. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  16993. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  16994. #if PACKETVER_SUPPORTS_SALES
  16995. nullpo_retv(sd);
  16996. if( RFIFOL(fd, 2) != sd->status.account_id ){
  16997. return;
  16998. }
  16999. clif_sale_close(sd);
  17000. #endif
  17001. }
  17002. /// Reply to a item search request for item sale administration.
  17003. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  17004. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  17005. #if PACKETVER_SUPPORTS_SALES
  17006. int fd = sd->fd;
  17007. WFIFOHEAD(fd, 10);
  17008. WFIFOW(fd, 0) = 0x9ad;
  17009. if( item != NULL ){
  17010. WFIFOW(fd, 2) = 0;
  17011. WFIFOW(fd, 4) = item->nameid;
  17012. WFIFOL(fd, 6) = item->price;
  17013. }else{
  17014. WFIFOW(fd, 2) = 1;
  17015. WFIFOW(fd, 4) = 0;
  17016. WFIFOL(fd, 6) = 0;
  17017. }
  17018. WFIFOSET(fd, 10);
  17019. #endif
  17020. }
  17021. /// Search request for an item sale administration.
  17022. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17023. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  17024. #if PACKETVER_SUPPORTS_SALES
  17025. char item_name[ITEM_NAME_LENGTH];
  17026. struct item_data *id = NULL;
  17027. nullpo_retv(sd);
  17028. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17029. return;
  17030. }
  17031. if( !sd->state.sale_open ){
  17032. return;
  17033. }
  17034. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17035. id = itemdb_searchname(item_name);
  17036. if( id ){
  17037. int i;
  17038. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17039. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17040. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17041. return;
  17042. }
  17043. }
  17044. }
  17045. // not found
  17046. clif_sale_search_reply( sd, NULL );
  17047. #endif
  17048. }
  17049. /// Reply if an item was successfully put on sale or not.
  17050. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17051. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  17052. #if PACKETVER_SUPPORTS_SALES
  17053. int fd = sd->fd;
  17054. WFIFOHEAD(fd, 4);
  17055. WFIFOW(fd, 0) = 0x9af;
  17056. WFIFOW(fd, 2) = (uint16)result;
  17057. WFIFOSET(fd, 4);
  17058. #endif
  17059. }
  17060. /// A client request to put an item on sale.
  17061. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17062. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W
  17063. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  17064. #if PACKETVER_SUPPORTS_SALES
  17065. int32 count;
  17066. int16 nameid;
  17067. int startTime;
  17068. int endTime;
  17069. uint16 sellingHours;
  17070. nullpo_retv(sd);
  17071. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17072. return;
  17073. }
  17074. if( !sd->state.sale_open ){
  17075. return;
  17076. }
  17077. nameid = RFIFOW(fd, 6);
  17078. count = RFIFOL(fd, 8);
  17079. startTime = RFIFOL(fd, 12);
  17080. #if PACKETVER >= 20150520
  17081. if( RFIFOW(fd,0) == 0xa3d )
  17082. sellingHours = RFIFOW(fd, 16);
  17083. else
  17084. #endif
  17085. sellingHours = RFIFOB(fd, 16);
  17086. endTime = startTime + sellingHours * 60 * 60;
  17087. clif_sale_add_reply( sd, sale_add_item(nameid,count,startTime,endTime) );
  17088. #endif
  17089. }
  17090. /// Reply to an item removal from sale.
  17091. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17092. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  17093. #if PACKETVER_SUPPORTS_SALES
  17094. int fd = sd->fd;
  17095. WFIFOHEAD(fd, 4);
  17096. WFIFOW(fd, 0) = 0x9b1;
  17097. WFIFOW(fd, 2) = failed;
  17098. WFIFOSET(fd, 4);
  17099. #endif
  17100. }
  17101. /// Request to remove an item from sale.
  17102. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17103. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  17104. #if PACKETVER_SUPPORTS_SALES
  17105. nullpo_retv(sd);
  17106. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17107. return;
  17108. }
  17109. if( !sd->state.sale_open ){
  17110. return;
  17111. }
  17112. clif_sale_remove_reply(sd, !sale_remove_item(RFIFOW(fd, 6)));
  17113. #endif
  17114. }
  17115. /// Achievement System
  17116. /// Author: Luxuri, Aleos
  17117. /**
  17118. * Sends all achievement data to the client (ZC_ALL_AG_LIST).
  17119. * 0a23 <packetType>.W <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17120. */
  17121. void clif_achievement_list_all(struct map_session_data *sd)
  17122. {
  17123. int i, j, len, fd, *info;
  17124. uint16 count = 0;
  17125. nullpo_retv(sd);
  17126. if (!battle_config.feature_achievement) {
  17127. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17128. return;
  17129. }
  17130. fd = sd->fd;
  17131. count = sd->achievement_data.count; // All achievements should be sent to the client
  17132. len = (50 * count) + 22;
  17133. if (len <= 22)
  17134. return;
  17135. info = achievement_level(sd, true);
  17136. WFIFOHEAD(fd,len);
  17137. WFIFOW(fd, 0) = 0xa23;
  17138. WFIFOW(fd, 2) = len;
  17139. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17140. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17141. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17142. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17143. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17144. for (i = 0; i < count; i++) {
  17145. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17146. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17147. for (j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17148. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17149. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17150. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17151. }
  17152. WFIFOSET(fd, len);
  17153. }
  17154. /**
  17155. * Sends a single achievement's data to the client (ZC_AG_UPDATE).
  17156. * 0a24 <packetType>.W <ACHPoint>.L
  17157. */
  17158. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  17159. {
  17160. int fd, i, *info;
  17161. nullpo_retv(sd);
  17162. if (!battle_config.feature_achievement) {
  17163. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17164. return;
  17165. }
  17166. fd = sd->fd;
  17167. info = achievement_level(sd, true);
  17168. WFIFOHEAD(fd, packet_len(0xa24));
  17169. WFIFOW(fd, 0) = 0xa24;
  17170. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17171. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17172. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17173. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17174. if (ach) {
  17175. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17176. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17177. for (i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17178. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17179. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17180. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17181. } else
  17182. memset(WFIFOP(fd, 16), 0, 40);
  17183. WFIFOSET(fd, packet_len(0xa24));
  17184. }
  17185. /**
  17186. * Checks if an achievement reward can be rewarded (CZ_REQ_AG_REWARD).
  17187. * 0a25 <packetType>.W <achievementID>.L
  17188. */
  17189. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17190. {
  17191. nullpo_retv(sd);
  17192. if( sd->achievement_data.save )
  17193. intif_achievement_save(sd);
  17194. achievement_check_reward(sd, RFIFOL(fd,2));
  17195. }
  17196. /**
  17197. * Returns the result of achievement_check_reward (ZC_REQ_AG_REWARD_ACK).
  17198. * 0a26 <packetType>.W <result>.W <achievementID>.L
  17199. */
  17200. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17201. {
  17202. WFIFOHEAD(fd, packet_len(0xa26));
  17203. WFIFOW(fd, 0) = 0xa26;
  17204. WFIFOB(fd, 2) = result;
  17205. WFIFOL(fd, 3) = achievement_id;
  17206. WFIFOSET(fd, packet_len(0xa26));
  17207. }
  17208. /*
  17209. * This packet is sent by /changedress or /nocosplay
  17210. *
  17211. * 0ae8
  17212. */
  17213. void clif_parse_changedress( int fd, struct map_session_data* sd ){
  17214. #if PACKETVER >= 20180103
  17215. char command[CHAT_SIZE_MAX];
  17216. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17217. is_atcommand( fd, sd, command, 1 );
  17218. #endif
  17219. }
  17220. /// Opens an UI window of the given type and initializes it with the given data
  17221. /// 0AE2 <type>.B <data>.L
  17222. void clif_ui_open( struct map_session_data *sd, enum out_ui_type ui_type, int32 data ){
  17223. nullpo_retv(sd);
  17224. int fd = sd->fd;
  17225. WFIFOHEAD(fd,packet_len(0xae2));
  17226. WFIFOW(fd,0) = 0xae2;
  17227. WFIFOB(fd,2) = ui_type;
  17228. WFIFOL(fd,3) = data;
  17229. WFIFOSET(fd,packet_len(0xae2));
  17230. }
  17231. /// Request to open an UI window of the given type
  17232. /// 0A68 <type>.B
  17233. void clif_parse_open_ui( int fd, struct map_session_data* sd ){
  17234. switch( RFIFOB(fd,2) ){
  17235. case IN_UI_ATTENDANCE:
  17236. if( !pc_has_permission( sd, PC_PERM_ATTENDANCE ) ){
  17237. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 791 ), false, SELF ); // You are not allowed to use the attendance system.
  17238. }else if( pc_attendance_enabled() ){
  17239. clif_ui_open( sd, OUT_UI_ATTENDANCE, pc_attendance_counter( sd ) );
  17240. }else{
  17241. clif_msg_color( sd, MSG_ATTENDANCE_DISABLED, color_table[COLOR_RED] );
  17242. }
  17243. break;
  17244. }
  17245. }
  17246. /// Response for attedance request
  17247. /// 0AF0 <unknown>.L <data>.L
  17248. void clif_attendence_response( struct map_session_data *sd, int32 data ){
  17249. nullpo_retv(sd);
  17250. int fd = sd->fd;
  17251. WFIFOHEAD(fd,packet_len(0xAF0));
  17252. WFIFOW(fd,0) = 0xAF0;
  17253. WFIFOL(fd,2) = 0;
  17254. WFIFOL(fd,6) = data;
  17255. WFIFOSET(fd,packet_len(0xAF0));
  17256. }
  17257. /// Request from the client to retrieve today's attendance reward
  17258. /// 0AEF
  17259. void clif_parse_attendance_request( int fd, struct map_session_data* sd ){
  17260. pc_attendance_claim_reward(sd);
  17261. }
  17262. /// Send out the percentage of weight that causes it to be displayed in red.
  17263. /// 0ADE <percentage>.L
  17264. void clif_weight_limit( struct map_session_data* sd ){
  17265. #if PACKETVER >= 20171025
  17266. nullpo_retv(sd);
  17267. int fd = sd->fd;
  17268. WFIFOHEAD(fd, packet_len(0xADE));
  17269. WFIFOW(fd, 0) = 0xADE;
  17270. #ifdef RENEWAL
  17271. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate_renewal;
  17272. #else
  17273. WFIFOL(fd, 2) = battle_config.natural_heal_weight_rate;
  17274. #endif
  17275. WFIFOSET(fd, packet_len(0xADE));
  17276. #endif
  17277. }
  17278. enum e_private_airship_response : uint32{
  17279. PRIVATEAIRSHIP_OK,
  17280. PRIVATEAIRSHIP_RETRY,
  17281. PRIVATEAIRSHIP_ITEM_NOT_ENOUGH,
  17282. PRIVATEAIRSHIP_DESTINATION_MAP_INVALID,
  17283. PRIVATEAIRSHIP_SOURCE_MAP_INVALID,
  17284. PRIVATEAIRSHIP_ITEM_UNAVAILABLE
  17285. };
  17286. /// Send out the response to a private airship request
  17287. /// 0A4A <response>.L
  17288. void clif_private_airship_response( struct map_session_data* sd, enum e_private_airship_response response ){
  17289. #if PACKETVER >= 20180321
  17290. nullpo_retv( sd );
  17291. int fd = sd->fd;
  17292. WFIFOHEAD( fd, packet_len( 0xA4A ) );
  17293. WFIFOW( fd, 0 ) = 0xA4A;
  17294. WFIFOL( fd, 2 ) = response;
  17295. WFIFOSET( fd, packet_len( 0xA4A ) );
  17296. #endif
  17297. }
  17298. /// Parses a request for a private airship
  17299. /// 0A49 <mapname>.16B <itemid>.W
  17300. void clif_parse_private_airship_request( int fd, struct map_session_data* sd ){
  17301. #if PACKETVER >= 20180321
  17302. // Check if the feature is enabled
  17303. if( !battle_config.feature_privateairship ){
  17304. clif_messagecolor( &sd->bl, color_table[COLOR_RED], msg_txt( sd, 792 ), false, SELF ); // The private airship system is disabled.
  17305. return;
  17306. }
  17307. // Check if the player is allowed to warp from the source map
  17308. if( !map_getmapflag( sd->bl.m, MF_PRIVATEAIRSHIP_SOURCE ) ){
  17309. clif_private_airship_response( sd, PRIVATEAIRSHIP_SOURCE_MAP_INVALID );
  17310. return;
  17311. }
  17312. char mapname[MAP_NAME_LENGTH_EXT];
  17313. safestrncpy( mapname, RFIFOCP( fd, 2 ), MAP_NAME_LENGTH_EXT );
  17314. int16 mapindex = mapindex_name2id( mapname );
  17315. // Check if we know the mapname
  17316. if( mapindex < 0 ){
  17317. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17318. return;
  17319. }
  17320. int16 mapid = map_mapindex2mapid( mapindex );
  17321. // Check if the map is available on this server
  17322. if( mapid < 0 ){
  17323. // TODO: add multi map-server support, cant validate the mapflags of the other server
  17324. return;
  17325. }
  17326. // Check if the player tried to warp to the map he is on
  17327. if( sd->bl.m == mapid ){
  17328. // This is blocked by the client, but just to be sure
  17329. return;
  17330. }
  17331. // This can only be a hack, so we prevent it
  17332. if( map_getmapdata( mapid )->instance_id ){
  17333. // Ignore requests to warp directly into a running instance
  17334. return;
  17335. }
  17336. // Check if the player is allowed to warp to the target map
  17337. if( !map_getmapflag( mapid, MF_PRIVATEAIRSHIP_DESTINATION ) ){
  17338. clif_private_airship_response( sd, PRIVATEAIRSHIP_DESTINATION_MAP_INVALID );
  17339. return;
  17340. }
  17341. // The UI only offers these two buttons(items) for now
  17342. uint16 item_ids[] = {
  17343. ITEMID_ACTINIDIA_CAT_FRUIT,
  17344. ITEMID_WORLD_MOVING_RIGHTS
  17345. };
  17346. uint16 item_id = RFIFOW( fd, 2 + MAP_NAME_LENGTH_EXT );
  17347. int i;
  17348. ARR_FIND( 0, ARRAYLENGTH( item_ids ), i, item_ids[i] == item_id );
  17349. // Check if the item sent by the client is known to us
  17350. if( i == ARRAYLENGTH( item_ids ) ){
  17351. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_UNAVAILABLE );
  17352. return;
  17353. }
  17354. int idx = pc_search_inventory( sd, item_id );
  17355. // Check if the player has the item at all
  17356. if( idx < 0 ){
  17357. clif_private_airship_response( sd, PRIVATEAIRSHIP_ITEM_NOT_ENOUGH );
  17358. return;
  17359. }
  17360. // Delete the chosen item
  17361. if( pc_delitem( sd, idx, 1, 0, 0, LOG_TYPE_PRIVATE_AIRSHIP ) ){
  17362. clif_private_airship_response( sd, PRIVATEAIRSHIP_RETRY );
  17363. return;
  17364. }
  17365. // Warp the player to a random spot on the destination map
  17366. pc_setpos( sd, mapindex, 0, 0, CLR_TELEPORT );
  17367. #endif
  17368. }
  17369. /*==========================================
  17370. * Main client packet processing function
  17371. *------------------------------------------*/
  17372. static int clif_parse(int fd)
  17373. {
  17374. int cmd, packet_len;
  17375. TBL_PC* sd;
  17376. int pnum;
  17377. #ifdef PACKET_OBFUSCATION
  17378. int cmd2;
  17379. #endif
  17380. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  17381. // Note: "click masters" can do 80+ clicks in 10 seconds
  17382. 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]
  17383. { // begin main client packet processing loop
  17384. sd = (TBL_PC *)session[fd]->session_data;
  17385. if (session[fd]->flag.eof) {
  17386. if (sd) {
  17387. if (sd->state.autotrade) {
  17388. //Disassociate character from the socket connection.
  17389. session[fd]->session_data = NULL;
  17390. sd->fd = 0;
  17391. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  17392. } else
  17393. if (sd->state.active) {
  17394. // Player logout display [Valaris]
  17395. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  17396. clif_quitsave(fd, sd);
  17397. } else {
  17398. //Unusual logout (during log on/off/map-changer procedure)
  17399. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  17400. map_quit(sd);
  17401. }
  17402. } else {
  17403. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  17404. }
  17405. do_close(fd);
  17406. return 0;
  17407. }
  17408. if (RFIFOREST(fd) < 2)
  17409. return 0;
  17410. cmd = RFIFOW(fd, 0);
  17411. #ifdef PACKET_OBFUSCATION
  17412. // Check if it is a player that tries to connect to the map server.
  17413. if( sd ){
  17414. // Decrypt the current packet ID with the last key stored in the session.
  17415. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  17416. }else{
  17417. // Store the original value for checking
  17418. cmd2 = cmd;
  17419. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  17420. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17421. }
  17422. #endif
  17423. // filter out invalid / unsupported packets
  17424. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  17425. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  17426. #ifdef DUMP_INVALID_PACKET
  17427. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17428. #endif
  17429. #ifdef PACKET_OBFUSCATION_WARN
  17430. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  17431. if( !sd ){
  17432. #ifdef PACKET_OBFUSCATION
  17433. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  17434. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  17435. }
  17436. #else
  17437. // Try to use the initial keys for the decryption of the packet ID.
  17438. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17439. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  17440. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  17441. }
  17442. #endif
  17443. }
  17444. #endif
  17445. set_eof(fd);
  17446. return 0;
  17447. }
  17448. // determine real packet length
  17449. packet_len = packet_db[cmd].len;
  17450. if (packet_len == -1) { // variable-length packet
  17451. if (RFIFOREST(fd) < 4)
  17452. return 0;
  17453. packet_len = RFIFOW(fd,2);
  17454. if (packet_len < 4 || packet_len > 32768) {
  17455. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  17456. #ifdef DUMP_INVALID_PACKET
  17457. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17458. #endif
  17459. set_eof(fd);
  17460. return 0;
  17461. }
  17462. }
  17463. if ((int)RFIFOREST(fd) < packet_len)
  17464. return 0; // not enough data received to form the packet
  17465. #ifdef PACKET_OBFUSCATION
  17466. RFIFOW(fd, 0) = cmd;
  17467. if (sd)
  17468. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  17469. #endif
  17470. if( packet_db[cmd].func == clif_parse_debug )
  17471. packet_db[cmd].func(fd, sd);
  17472. else if( packet_db[cmd].func != NULL ) {
  17473. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  17474. ; //Only valid packet when there is no session
  17475. else
  17476. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  17477. ; //Only valid packet when player is not on a map
  17478. else
  17479. packet_db[cmd].func(fd, sd);
  17480. }
  17481. #ifdef DUMP_UNKNOWN_PACKET
  17482. else DumpUnknown(fd,sd,cmd,packet_len);
  17483. #endif
  17484. RFIFOSKIP(fd, packet_len);
  17485. }; // main loop end
  17486. return 0;
  17487. }
  17488. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  17489. va_list argp;
  17490. int i;
  17491. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  17492. return;
  17493. packet_db[cmd].len = length;
  17494. packet_db[cmd].func = func;
  17495. va_start(argp, func);
  17496. for( i = 0; i < MAX_PACKET_POS; i++ ){
  17497. int offset = va_arg(argp, int);
  17498. if( offset == 0 ){
  17499. break;
  17500. }
  17501. packet_db[cmd].pos[i] = offset;
  17502. }
  17503. if( i == MAX_PACKET_POS ){
  17504. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  17505. }
  17506. va_end(argp);
  17507. }
  17508. /*==========================================
  17509. * Reads packets and setups its array reference
  17510. *------------------------------------------*/
  17511. void packetdb_readdb(){
  17512. memset(packet_db,0,sizeof(packet_db));
  17513. memset(packet_db_ack,0,sizeof(packet_db_ack));
  17514. #include "clif_packetdb.hpp"
  17515. #include "clif_shuffle.hpp"
  17516. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  17517. #ifdef PACKET_OBFUSCATION
  17518. 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]);
  17519. #else
  17520. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  17521. #endif
  17522. }
  17523. /*==========================================
  17524. *
  17525. *------------------------------------------*/
  17526. void do_init_clif(void) {
  17527. const char* colors[COLOR_MAX] = {
  17528. "0x00FF00",
  17529. "0xFF0000",
  17530. "0xFFFFFF",
  17531. "0xFFFF00",
  17532. "0x00FFFF",
  17533. "0xB5FFB5",
  17534. };
  17535. int i;
  17536. /**
  17537. * Setup Color Table (saves unnecessary load of strtoul on every call)
  17538. **/
  17539. for(i = 0; i < COLOR_MAX; i++) {
  17540. color_table[i] = strtoul(colors[i],NULL,0);
  17541. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  17542. }
  17543. packetdb_readdb();
  17544. set_defaultparse(clif_parse);
  17545. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  17546. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  17547. exit(EXIT_FAILURE);
  17548. }
  17549. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  17550. add_timer_func_list(clif_delayquit, "clif_delayquit");
  17551. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  17552. }
  17553. void do_final_clif(void) {
  17554. ers_destroy(delay_clearunit_ers);
  17555. }