clif.cpp 576 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514
  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 int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr_t data)
  744. {
  745. struct block_list *bl = (struct block_list *)data;
  746. clif_clearunit_area(bl, (clr_type) id);
  747. ers_free(delay_clearunit_ers,bl);
  748. return 0;
  749. }
  750. void clif_clearunit_delayed(struct block_list* bl, clr_type type, unsigned int tick)
  751. {
  752. struct block_list *tbl = ers_alloc(delay_clearunit_ers, struct block_list);
  753. memcpy (tbl, bl, sizeof (struct block_list));
  754. add_timer(tick, clif_clearunit_delayed_sub, (int)type, (intptr_t)tbl);
  755. }
  756. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  757. {
  758. if(sd->sc.option&OPTION_COSTUME)
  759. {
  760. *rhand = *lhand = 0;
  761. return;
  762. }
  763. #if PACKETVER < 4
  764. *rhand = sd->status.weapon;
  765. *lhand = sd->status.shield;
  766. #else
  767. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  768. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  769. {
  770. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  771. if (id->view_id > 0)
  772. *rhand = id->view_id;
  773. else
  774. *rhand = id->nameid;
  775. } else
  776. *rhand = 0;
  777. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  778. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  779. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  780. {
  781. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  782. if (id->view_id > 0)
  783. *lhand = id->view_id;
  784. else
  785. *lhand = id->nameid;
  786. } else
  787. *lhand = 0;
  788. #endif
  789. }
  790. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  791. static int clif_setlevel_sub(int lv) {
  792. if( lv < battle_config.max_lv ) {
  793. ;
  794. } else if( lv < battle_config.aura_lv ) {
  795. lv = battle_config.max_lv - 1;
  796. } else {
  797. lv = battle_config.max_lv;
  798. }
  799. return lv;
  800. }
  801. static int clif_setlevel(struct block_list* bl) {
  802. int lv = status_get_lv(bl);
  803. if( battle_config.client_limit_unit_lv&bl->type )
  804. return clif_setlevel_sub(lv);
  805. switch( bl->type ) {
  806. case BL_NPC:
  807. case BL_PET:
  808. // npcs and pets do not have level
  809. return 0;
  810. }
  811. return lv;
  812. }
  813. /*==========================================
  814. * Prepares 'unit standing/spawning' packet
  815. *------------------------------------------*/
  816. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  817. {
  818. struct map_session_data* sd;
  819. struct status_change* sc = status_get_sc(bl);
  820. struct view_data* vd = status_get_viewdata(bl);
  821. unsigned char *buf = WBUFP(buffer, 0);
  822. #if PACKETVER < 20091103
  823. bool type = !pcdb_checkid(vd->class_);
  824. #endif
  825. unsigned short offset = 0;
  826. #if PACKETVER >= 20091103
  827. const char *name;
  828. #endif
  829. sd = BL_CAST(BL_PC, bl);
  830. #if PACKETVER < 20091103
  831. if(type)
  832. WBUFW(buf,0) = spawn ? 0x7c : 0x78;
  833. else
  834. #endif
  835. #if PACKETVER < 4
  836. WBUFW(buf,0) = spawn ? 0x79 : 0x78;
  837. #elif PACKETVER < 7
  838. WBUFW(buf,0) = spawn ? 0x1d9 : 0x1d8;
  839. #elif PACKETVER < 20080102
  840. WBUFW(buf,0) = spawn ? 0x22b : 0x22a;
  841. #elif PACKETVER < 20091103
  842. WBUFW(buf,0) = spawn ? 0x2ed : 0x2ee;
  843. #elif PACKETVER < 20101124
  844. WBUFW(buf,0) = spawn ? 0x7f8 : 0x7f9;
  845. #elif PACKETVER < 20120221
  846. WBUFW(buf,0) = spawn ? 0x858 : 0x857;
  847. #elif PACKETVER < 20131223
  848. WBUFW(buf,0) = spawn ? 0x90f : 0x915;
  849. #elif PACKETVER < 20150513
  850. WBUFW(buf,0) = spawn ? 0x9dc : 0x9dd;
  851. #else
  852. WBUFW(buf,0) = spawn ? 0x9fe : 0x9ff;
  853. #endif
  854. #if PACKETVER >= 20091103
  855. name = status_get_name(bl);
  856. #if PACKETVER < 20110111
  857. WBUFW(buf,2) = (uint16)((spawn ? 62 : 63)+strlen(name));
  858. #elif PACKETVER < 20120221
  859. WBUFW(buf,2) = (uint16)((spawn ? 64 : 65)+strlen(name));
  860. #elif PACKETVER < 20130807
  861. WBUFW(buf,2) = (uint16)((spawn ? 77 : 78)+strlen(name));
  862. #else
  863. WBUFW(buf,2) = (uint16)((spawn ? 79 : 80)+strlen(name));
  864. #endif
  865. WBUFB(buf,4) = clif_bl_type(bl);
  866. offset+=3;
  867. buf = WBUFP(buffer,offset);
  868. #elif PACKETVER >= 20071106
  869. if (type) { //Non-player packets
  870. WBUFB(buf,2) = clif_bl_type(bl);
  871. offset++;
  872. buf = WBUFP(buffer,offset);
  873. }
  874. #endif
  875. WBUFL(buf, 2) = bl->id;
  876. #if PACKETVER >= 20131223
  877. WBUFL(buf,6) = (sd) ? sd->status.char_id : 0; // GID/CCODE
  878. offset+=4;
  879. buf = WBUFP(buffer,offset);
  880. #endif
  881. WBUFW(buf, 6) = status_get_speed(bl);
  882. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  883. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  884. #if PACKETVER < 20091103
  885. if (type&&spawn) { //uses an older and different packet structure
  886. WBUFW(buf,12) = (sc)? sc->option : 0;
  887. WBUFW(buf,14) = vd->hair_style;
  888. WBUFW(buf,16) = vd->weapon;
  889. WBUFW(buf,18) = vd->head_bottom;
  890. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  891. WBUFW(buf,22) = vd->shield;
  892. } else {
  893. #endif
  894. #if PACKETVER >= 20091103
  895. WBUFL(buf,12) = (sc)? sc->option : 0;
  896. offset+=2;
  897. buf = WBUFP(buffer,offset);
  898. #elif PACKETVER >= 7
  899. if (!type) {
  900. WBUFL(buf,12) = (sc)? sc->option : 0;
  901. offset+=2;
  902. buf = WBUFP(buffer,offset);
  903. } else
  904. WBUFW(buf,12) = (sc)? sc->option : 0;
  905. #else
  906. WBUFW(buf,12) = (sc)? sc->option : 0;
  907. #endif
  908. WBUFW(buf,14) = vd->class_;
  909. WBUFW(buf,16) = vd->hair_style;
  910. WBUFW(buf,18) = vd->weapon;
  911. #if PACKETVER < 4
  912. WBUFW(buf,20) = vd->head_bottom;
  913. WBUFW(buf,22) = vd->shield;
  914. #else
  915. WBUFW(buf,20) = vd->shield;
  916. WBUFW(buf,22) = vd->head_bottom;
  917. #endif
  918. #if PACKETVER < 20091103
  919. }
  920. #endif
  921. WBUFW(buf,24) = vd->head_top;
  922. WBUFW(buf,26) = vd->head_mid;
  923. if( bl->type == BL_NPC && vd->class_ == JT_GUILD_FLAG )
  924. { //The hell, why flags work like this?
  925. WBUFW(buf,22) = status_get_emblem_id(bl);
  926. WBUFW(buf,24) = GetWord(status_get_guild_id(bl), 1);
  927. WBUFW(buf,26) = GetWord(status_get_guild_id(bl), 0);
  928. }
  929. WBUFW(buf,28) = vd->hair_color;
  930. WBUFW(buf,30) = vd->cloth_color;
  931. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  932. #if PACKETVER < 20091103
  933. if (type&&spawn) { //End of packet 0x7c
  934. WBUFB(buf,34) = (sd) ? sd->status.karma : 0; // karma
  935. WBUFB(buf,35) = vd->sex;
  936. WBUFPOS(buf,36, bl->x, bl->y, unit_getdir(bl));
  937. WBUFB(buf,39) = 0;
  938. WBUFB(buf,40) = 0;
  939. return packet_len(0x7c);
  940. }
  941. #endif
  942. #if PACKETVER >= 20110111
  943. WBUFW(buf,34) = vd->robe;
  944. offset+= 2;
  945. buf = WBUFP(buffer,offset);
  946. #endif
  947. WBUFL(buf,34) = status_get_guild_id(bl);
  948. WBUFW(buf,38) = status_get_emblem_id(bl);
  949. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  950. #if PACKETVER >= 20091103
  951. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  952. offset+=2;
  953. buf = WBUFP(buffer,offset);
  954. #elif PACKETVER >= 7
  955. if (!type) {
  956. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  957. offset+=2;
  958. buf = WBUFP(buffer,offset);
  959. } else
  960. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  961. #else
  962. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  963. #endif
  964. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  965. WBUFB(buf,45) = vd->sex;
  966. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  967. WBUFB(buf,49) = (sd)? 5 : 0;
  968. WBUFB(buf,50) = (sd)? 5 : 0;
  969. if (!spawn) {
  970. WBUFB(buf,51) = vd->dead_sit;
  971. offset++;
  972. buf = WBUFP(buffer,offset);
  973. }
  974. WBUFW(buf,51) = clif_setlevel(bl);
  975. #if PACKETVER < 20091103
  976. if (type) //End for non-player packet
  977. return packet_len(WBUFW(buffer,0));
  978. #endif
  979. #if PACKETVER >= 20080102
  980. WBUFW(buf,53) = (sd ? sd->status.font : 0);
  981. #endif
  982. #if PACKETVER >= 20120221
  983. if ( battle_config.monster_hp_bars_info && !map[bl->m].flag.hidemobhpbar && bl->type == BL_MOB && (status_get_hp(bl) < status_get_max_hp(bl)) ) {
  984. WBUFL(buf,55) = status_get_max_hp(bl); // maxHP
  985. WBUFL(buf,59) = status_get_hp(bl); // HP
  986. } else {
  987. WBUFL(buf,55) = -1; // maxHP
  988. WBUFL(buf,59) = -1; // HP
  989. }
  990. WBUFB(buf,63) = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0; // isBoss
  991. #endif
  992. #if PACKETVER >= 20150513
  993. WBUFW(buf,64) = vd->body_style; // body
  994. offset+= 2;
  995. buf = WBUFP(buffer,offset);
  996. #endif
  997. #if PACKETVER >= 20091103
  998. #if PACKETVER >= 20120221
  999. safestrncpy(WBUFCP(buf,64), name, NAME_LENGTH);
  1000. #else
  1001. safestrncpy(WBUFCP(buf,55), name, NAME_LENGTH);
  1002. #endif
  1003. return WBUFW(buffer,2);
  1004. #else
  1005. return packet_len(WBUFW(buffer,0));
  1006. #endif
  1007. }
  1008. /*==========================================
  1009. * Prepares 'unit walking' packet
  1010. *------------------------------------------*/
  1011. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  1012. {
  1013. struct map_session_data* sd;
  1014. struct status_change* sc = status_get_sc(bl);
  1015. struct view_data* vd = status_get_viewdata(bl);
  1016. unsigned char* buf = WBUFP(buffer,0);
  1017. #if PACKETVER >= 7
  1018. unsigned short offset = 0;
  1019. #endif
  1020. #if PACKETVER >= 20091103
  1021. const char *name;
  1022. #endif
  1023. sd = BL_CAST(BL_PC, bl);
  1024. #if PACKETVER < 4
  1025. WBUFW(buf, 0) = 0x7b;
  1026. #elif PACKETVER < 7
  1027. WBUFW(buf, 0) = 0x1da;
  1028. #elif PACKETVER < 20080102
  1029. WBUFW(buf, 0) = 0x22c;
  1030. #elif PACKETVER < 20091103
  1031. WBUFW(buf, 0) = 0x2ec;
  1032. #elif PACKETVER < 20101124
  1033. WBUFW(buf, 0) = 0x7f7;
  1034. #elif PACKETVER < 20120221
  1035. WBUFW(buf, 0) = 0x856;
  1036. #elif PACKETVER < 20131223
  1037. WBUFW(buf, 0) = 0x914;
  1038. #elif PACKETVER < 20150513
  1039. WBUFW(buf, 0) = 0x9db;
  1040. #else
  1041. WBUFW(buf, 0) = 0x9fd;
  1042. #endif
  1043. #if PACKETVER >= 20091103
  1044. name = status_get_name(bl);
  1045. #if PACKETVER < 20110111
  1046. WBUFW(buf, 2) = (uint16)(69+strlen(name));
  1047. #elif PACKETVER < 20120221
  1048. WBUFW(buf, 2) = (uint16)(71+strlen(name));
  1049. #elif PACKETVER < 20130807
  1050. WBUFW(buf, 2) = (uint16)(84+strlen(name));
  1051. #else
  1052. WBUFW(buf, 2) = (uint16)(86+strlen(name));
  1053. #endif
  1054. offset+=2;
  1055. buf = WBUFP(buffer,offset);
  1056. #endif
  1057. #if PACKETVER >= 20071106
  1058. WBUFB(buf, 2) = clif_bl_type(bl);
  1059. offset++;
  1060. buf = WBUFP(buffer,offset);
  1061. #endif
  1062. WBUFL(buf, 2) = bl->id;
  1063. #if PACKETVER >= 20131223
  1064. WBUFL(buf,6) = (sd) ? sd->status.char_id : 0; // GID/CCODE
  1065. offset+=4;
  1066. buf = WBUFP(buffer,offset);
  1067. #endif
  1068. WBUFW(buf, 6) = status_get_speed(bl);
  1069. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  1070. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  1071. #if PACKETVER < 7
  1072. WBUFW(buf,12) = (sc)? sc->option : 0;
  1073. #else
  1074. WBUFL(buf,12) = (sc)? sc->option : 0;
  1075. offset+=2; //Shift the rest of elements by 2 bytes.
  1076. buf = WBUFP(buffer,offset);
  1077. #endif
  1078. WBUFW(buf,14) = vd->class_;
  1079. WBUFW(buf,16) = vd->hair_style;
  1080. WBUFW(buf,18) = vd->weapon;
  1081. #if PACKETVER < 4
  1082. WBUFW(buf,20) = vd->head_bottom;
  1083. WBUFL(buf,22) = gettick();
  1084. WBUFW(buf,26) = vd->shield;
  1085. #else
  1086. WBUFW(buf,20) = vd->shield;
  1087. WBUFW(buf,22) = vd->head_bottom;
  1088. WBUFL(buf,24) = gettick();
  1089. #endif
  1090. WBUFW(buf,28) = vd->head_top;
  1091. WBUFW(buf,30) = vd->head_mid;
  1092. WBUFW(buf,32) = vd->hair_color;
  1093. WBUFW(buf,34) = vd->cloth_color;
  1094. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  1095. #if PACKETVER >= 20110111
  1096. WBUFW(buf,38) = vd->robe;
  1097. offset+= 2;
  1098. buf = WBUFP(buffer,offset);
  1099. #endif
  1100. WBUFL(buf,38) = status_get_guild_id(bl);
  1101. WBUFW(buf,42) = status_get_emblem_id(bl);
  1102. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  1103. #if PACKETVER < 7
  1104. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  1105. #else
  1106. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  1107. offset+=2; //Shift the rest of elements by 2 bytes.
  1108. buf = WBUFP(buffer,offset);
  1109. #endif
  1110. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  1111. WBUFB(buf,49) = vd->sex;
  1112. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1113. WBUFB(buf,56) = (sd)? 5 : 0;
  1114. WBUFB(buf,57) = (sd)? 5 : 0;
  1115. WBUFW(buf,58) = clif_setlevel(bl);
  1116. #if PACKETVER >= 20080102
  1117. WBUFW(buf,60) = (sd ? sd->status.font : 0);
  1118. #endif
  1119. #if PACKETVER >= 20120221
  1120. if ( battle_config.monster_hp_bars_info && !map[bl->m].flag.hidemobhpbar && bl->type == BL_MOB && (status_get_hp(bl) < status_get_max_hp(bl)) ) {
  1121. WBUFL(buf,62) = status_get_max_hp(bl); // maxHP
  1122. WBUFL(buf,66) = status_get_hp(bl); // HP
  1123. } else {
  1124. WBUFL(buf,62) = -1; // maxHP
  1125. WBUFL(buf,66) = -1; // HP
  1126. }
  1127. WBUFB(buf,70) = ( bl->type == BL_MOB && (((TBL_MOB*)bl)->db->mexp > 0) ) ? 1 : 0; // isBoss
  1128. #endif
  1129. #if PACKETVER >= 20150513
  1130. WBUFW(buf,71) = vd->body_style; // body
  1131. offset+= 2;
  1132. buf = WBUFP(buffer,offset);
  1133. #endif
  1134. #if PACKETVER >= 20091103
  1135. #if PACKETVER >= 20120221
  1136. safestrncpy(WBUFCP(buf,71), name, NAME_LENGTH);
  1137. #else
  1138. safestrncpy(WBUFCP(buf,62), name, NAME_LENGTH);
  1139. #endif
  1140. return WBUFW(buffer,2);
  1141. #else
  1142. return packet_len(WBUFW(buffer,0));
  1143. #endif
  1144. }
  1145. //Modifies the buffer for disguise characters and sends it to self.
  1146. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  1147. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  1148. {
  1149. #if PACKETVER >= 20091103
  1150. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1151. WBUFL(buf,5)=-bl->id;
  1152. #elif PACKETVER >= 20071106
  1153. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  1154. WBUFL(buf,3)=-bl->id;
  1155. #else
  1156. WBUFL(buf,2)=-bl->id;
  1157. #endif
  1158. clif_send(buf, len, bl, SELF);
  1159. }
  1160. /// Changes sprite of an NPC object (ZC_NPCSPRITE_CHANGE).
  1161. /// 01b0 <id>.L <type>.B <value>.L
  1162. /// type:
  1163. /// unused
  1164. void clif_class_change_target(struct block_list *bl,int class_,int type, enum send_target target, struct map_session_data *sd)
  1165. {
  1166. nullpo_retv(bl);
  1167. if(!pcdb_checkid(class_))
  1168. {// player classes yield missing sprites
  1169. unsigned char buf[16];
  1170. WBUFW(buf,0)=0x1b0;
  1171. WBUFL(buf,2)=bl->id;
  1172. WBUFB(buf,6)=type;
  1173. WBUFL(buf,7)=class_;
  1174. clif_send(buf,packet_len(0x1b0),(sd == NULL ? bl : &(sd->bl)),target);
  1175. }
  1176. }
  1177. /// Notifies the client of an object's spirits.
  1178. /// 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  1179. /// 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  1180. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1181. {
  1182. WFIFOHEAD(fd, packet_len(0x1e1));
  1183. WFIFOW(fd,0)=0x1e1;
  1184. WFIFOL(fd,2)=sd->bl.id;
  1185. WFIFOW(fd,6)=sd->spiritball;
  1186. WFIFOSET(fd, packet_len(0x1e1));
  1187. }
  1188. /*==========================================
  1189. * Kagerou/Oboro amulet spirit
  1190. *------------------------------------------*/
  1191. static void clif_spiritcharm_single(int fd, struct map_session_data *sd)
  1192. {
  1193. WFIFOHEAD(fd, packet_len(0x08cf));
  1194. WFIFOW(fd,0)=0x08cf;
  1195. WFIFOL(fd,2)=sd->bl.id;
  1196. WFIFOW(fd,6)=sd->spiritcharm_type;
  1197. WFIFOW(fd,8)=sd->spiritcharm;
  1198. WFIFOSET(fd, packet_len(0x08cf));
  1199. }
  1200. /*==========================================
  1201. * Run when player changes map / refreshes
  1202. * Tells its client to display all weather settings being used by this map
  1203. *------------------------------------------*/
  1204. static void clif_weather_check(struct map_session_data *sd)
  1205. {
  1206. int16 m = sd->bl.m;
  1207. int fd = sd->fd;
  1208. if (map[m].flag.snow
  1209. || map[m].flag.clouds
  1210. || map[m].flag.fog
  1211. || map[m].flag.fireworks
  1212. || map[m].flag.sakura
  1213. || map[m].flag.leaves
  1214. || map[m].flag.clouds2)
  1215. {
  1216. if (map[m].flag.snow)
  1217. clif_specialeffect_single(&sd->bl, EF_SNOW, fd);
  1218. if (map[m].flag.clouds)
  1219. clif_specialeffect_single(&sd->bl, EF_CLOUD3, fd);
  1220. if (map[m].flag.clouds2)
  1221. clif_specialeffect_single(&sd->bl, EF_CLOUD5, fd);
  1222. if (map[m].flag.fog)
  1223. clif_specialeffect_single(&sd->bl, EF_CLOUD4, fd);
  1224. if (map[m].flag.fireworks) {
  1225. clif_specialeffect_single(&sd->bl, EF_POKJUK, fd);
  1226. clif_specialeffect_single(&sd->bl, EF_THROWITEM2, fd);
  1227. clif_specialeffect_single(&sd->bl, EF_POKJUK_SOUND, fd);
  1228. }
  1229. if (map[m].flag.sakura)
  1230. clif_specialeffect_single(&sd->bl, EF_SAKURA, fd);
  1231. if (map[m].flag.leaves)
  1232. clif_specialeffect_single(&sd->bl, EF_MAPLE, fd);
  1233. }
  1234. }
  1235. /**
  1236. * Run when the weather on a map changes, throws all players in map id 'm' to clif_weather_check function
  1237. **/
  1238. void clif_weather(int16 m)
  1239. {
  1240. struct s_mapiterator* iter;
  1241. struct map_session_data *sd=NULL;
  1242. iter = mapit_getallusers();
  1243. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  1244. {
  1245. if( sd->bl.m == m )
  1246. clif_weather_check(sd);
  1247. }
  1248. mapit_free(iter);
  1249. }
  1250. /**
  1251. * Main function to spawn a unit on the client (player/mob/pet/etc)
  1252. **/
  1253. int clif_spawn(struct block_list *bl)
  1254. {
  1255. unsigned char buf[128];
  1256. struct view_data *vd;
  1257. int len;
  1258. vd = status_get_viewdata(bl);
  1259. if( !vd || vd->class_ == JT_INVISIBLE )
  1260. return 0;
  1261. /**
  1262. * Hide NPC from maya purple card.
  1263. **/
  1264. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1265. return 0;
  1266. len = clif_set_unit_idle(bl, buf,true);
  1267. clif_send(buf, len, bl, AREA_WOS);
  1268. if (disguised(bl))
  1269. clif_setdisguise(bl, buf, len);
  1270. if (vd->cloth_color)
  1271. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1272. if (vd->body_style)
  1273. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1274. switch (bl->type)
  1275. {
  1276. case BL_PC:
  1277. {
  1278. TBL_PC *sd = ((TBL_PC*)bl);
  1279. if (sd->spiritball > 0)
  1280. clif_spiritball(&sd->bl);
  1281. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1282. clif_specialeffect(bl,EF_GIANTBODY2,AREA);
  1283. else if(sd->state.size==SZ_MEDIUM)
  1284. clif_specialeffect(bl,EF_BABYBODY2,AREA);
  1285. if( sd->bg_id && map[sd->bl.m].flag.battleground )
  1286. clif_sendbgemblem_area(sd);
  1287. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  1288. clif_spiritcharm(sd);
  1289. if (sd->status.robe)
  1290. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1291. clif_efst_status_change_sub(bl, bl, AREA);
  1292. clif_hat_effects(sd,bl,AREA);
  1293. }
  1294. break;
  1295. case BL_MOB:
  1296. {
  1297. TBL_MOB *md = ((TBL_MOB*)bl);
  1298. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1299. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1300. else if(md->special_state.size==SZ_MEDIUM)
  1301. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1302. }
  1303. break;
  1304. case BL_NPC:
  1305. {
  1306. TBL_NPC *nd = ((TBL_NPC*)bl);
  1307. if( nd->size == SZ_BIG )
  1308. clif_specialeffect(&nd->bl,EF_GIANTBODY2,AREA);
  1309. else if( nd->size == SZ_MEDIUM )
  1310. clif_specialeffect(&nd->bl,EF_BABYBODY2,AREA);
  1311. clif_efst_status_change_sub(bl, bl, AREA);
  1312. clif_progressbar_npc_area(nd);
  1313. }
  1314. break;
  1315. case BL_PET:
  1316. if (vd->head_bottom)
  1317. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1318. break;
  1319. }
  1320. return 0;
  1321. }
  1322. /// Sends information about owned homunculus to the client . [orn]
  1323. /// 022e <name>.24B <modified>.B <level>.W <hunger>.W <intimacy>.W <equip id>.W <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W <hp>.W <max hp>.W <sp>.W <max sp>.W <exp>.L <max exp>.L <skill points>.W <atk range>.W (ZC_PROPERTY_HOMUN)
  1324. /// 09f7 <name>.24B <modified>.B <level>.W <hunger>.W <intimacy>.W <equip id>.W <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W <hp>.L <max hp>.L <sp>.W <max sp>.W <exp>.L <max exp>.L <skill points>.W <atk range>.W (ZC_PROPERTY_HOMUN_2)
  1325. void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1326. {
  1327. struct status_data *status;
  1328. unsigned char buf[128];
  1329. int offset;
  1330. #if PACKETVER < 20141016
  1331. const int cmd = 0x22e;
  1332. #else
  1333. const int cmd = 0x9f7;
  1334. #endif
  1335. int htype;
  1336. nullpo_retv(hd);
  1337. if (!clif_session_isValid(sd))
  1338. return;
  1339. status = &hd->battle_status;
  1340. htype = hom_class2type(hd->homunculus.class_);
  1341. memset(buf,0,packet_len(cmd));
  1342. WBUFW(buf,0) = cmd;
  1343. safestrncpy(WBUFCP(buf,2), hd->homunculus.name, NAME_LENGTH);
  1344. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1345. WBUFB(buf,26) = (battle_config.hom_rename ? 0 : hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp ? 0 : 4);
  1346. WBUFW(buf,27) = hd->homunculus.level;
  1347. WBUFW(buf,29) = hd->homunculus.hunger;
  1348. WBUFW(buf,31) = (unsigned short) (hd->homunculus.intimacy / 100) ;
  1349. WBUFW(buf,33) = 0; // equip id
  1350. #ifdef RENEWAL
  1351. WBUFW(buf,35) = cap_value(status->rhw.atk2, 0, INT16_MAX);
  1352. #else
  1353. WBUFW(buf,35) = cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
  1354. #endif
  1355. WBUFW(buf,37)=i16min(status->matk_max, INT16_MAX); //FIXME capping to INT16 here is too late
  1356. WBUFW(buf,39)=status->hit;
  1357. if (battle_config.hom_setting&HOMSET_DISPLAY_LUK)
  1358. WBUFW(buf,41) = status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1359. else
  1360. WBUFW(buf,41) = status->cri/10;
  1361. #ifdef RENEWAL
  1362. WBUFW(buf,43) = status->def + status->def2;
  1363. WBUFW(buf,45) = status->mdef + status->mdef2;
  1364. #else
  1365. WBUFW(buf,43) = status->def + status->vit;
  1366. WBUFW(buf,45) = status->mdef;
  1367. #endif
  1368. WBUFW(buf,47) = status->flee;
  1369. WBUFW(buf,49) = (flag) ? 0 : status->amotion;
  1370. #if PACKETVER >= 20141016
  1371. // Homunculus HP bar will screw up if the percentage calculation exceeds signed values
  1372. // Tested maximum: 21474836(=INT32_MAX/100), any value above will screw up the HP bar
  1373. if (status->max_hp > (INT32_MAX/100)) {
  1374. WBUFL(buf,51) = status->hp/(status->max_hp/100);
  1375. WBUFL(buf,55) = 100;
  1376. } else {
  1377. WBUFL(buf,51) = status->hp;
  1378. WBUFL(buf,55) = status->max_hp;
  1379. }
  1380. offset = 4;
  1381. #else
  1382. if (status->max_hp > INT16_MAX) {
  1383. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1384. WBUFW(buf,53) = 100;
  1385. } else {
  1386. WBUFW(buf,51) = status->hp;
  1387. WBUFW(buf,53) = status->max_hp;
  1388. }
  1389. offset = 0;
  1390. #endif
  1391. if (status->max_sp > INT16_MAX) {
  1392. WBUFW(buf,55+offset) = status->sp/(status->max_sp/100);
  1393. WBUFW(buf,57+offset) = 100;
  1394. } else {
  1395. WBUFW(buf,55+offset) = status->sp;
  1396. WBUFW(buf,57+offset) = status->max_sp;
  1397. }
  1398. WBUFL(buf,59+offset) = hd->homunculus.exp;
  1399. WBUFL(buf,63+offset) = hd->exp_next;
  1400. switch( htype ) {
  1401. case HT_REG:
  1402. case HT_EVO:
  1403. if( hd->homunculus.level >= battle_config.hom_max_level )
  1404. WBUFL(buf,63+offset) = 0;
  1405. break;
  1406. case HT_S:
  1407. if( hd->homunculus.level >= battle_config.hom_S_max_level )
  1408. WBUFL(buf,63+offset) = 0;
  1409. break;
  1410. }
  1411. WBUFW(buf,67+offset) = hd->homunculus.skillpts;
  1412. WBUFW(buf,69+offset) = status_get_range(&hd->bl);
  1413. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  1414. }
  1415. /// Notification about a change in homunuculus' state (ZC_CHANGESTATE_MER).
  1416. /// 0230 <type>.B <state>.B <id>.L <data>.L
  1417. /// type:
  1418. /// unused
  1419. /// state:
  1420. /// 0 = pre-init
  1421. /// 1 = intimacy
  1422. /// 2 = hunger
  1423. /// 3 = accessory?
  1424. /// ? = ignored
  1425. void clif_send_homdata(struct map_session_data *sd, int state, int param)
  1426. { //[orn]
  1427. int fd = sd->fd;
  1428. if ( (state == SP_INTIMATE) && (param >= 910) && (sd->hd->homunculus.class_ == sd->hd->homunculusDB->evo_class) )
  1429. hom_calc_skilltree(sd->hd, 0);
  1430. WFIFOHEAD(fd, packet_len(0x230));
  1431. WFIFOW(fd,0)=0x230;
  1432. WFIFOB(fd,2)=0;
  1433. WFIFOB(fd,3)=state;
  1434. WFIFOL(fd,4)=sd->hd->bl.id;
  1435. WFIFOL(fd,8)=param;
  1436. WFIFOSET(fd,packet_len(0x230));
  1437. }
  1438. int clif_homskillinfoblock(struct map_session_data *sd)
  1439. { //[orn]
  1440. struct homun_data *hd;
  1441. int fd = sd->fd;
  1442. int i, len=4;
  1443. nullpo_ret(sd);
  1444. hd = sd->hd;
  1445. if ( !hd )
  1446. return 0 ;
  1447. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1448. WFIFOW(fd,0)=0x235;
  1449. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1450. int id = hd->homunculus.hskill[i].id;
  1451. if( id != 0 ){
  1452. int combo = (hd->homunculus.hskill[i].flag)&SKILL_FLAG_TMP_COMBO;
  1453. short idx = hom_skill_get_index(id);
  1454. if (idx == -1)
  1455. continue;
  1456. WFIFOW(fd,len ) = id;
  1457. WFIFOW(fd,len+2) = ((combo)?INF_SELF_SKILL:skill_get_inf(id));
  1458. WFIFOW(fd,len+4) = 0;
  1459. WFIFOW(fd,len+6) = hd->homunculus.hskill[idx].lv;
  1460. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[idx].lv);
  1461. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl,id,hd->homunculus.hskill[idx].lv,false);
  1462. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1463. WFIFOB(fd,len+36) = (hd->homunculus.level < hom_skill_get_min_level(hd->homunculus.class_, id) || hd->homunculus.hskill[idx].lv >= hom_skill_tree_get_max(id, hd->homunculus.class_)) ? 0 : 1;
  1464. len+=37;
  1465. }
  1466. }
  1467. WFIFOW(fd,2)=len;
  1468. WFIFOSET(fd,len);
  1469. return 0;
  1470. }
  1471. void clif_homskillup(struct map_session_data *sd, uint16 skill_id)
  1472. { //[orn]
  1473. struct homun_data *hd;
  1474. int fd;
  1475. short idx = -1;
  1476. nullpo_retv(sd);
  1477. if ((idx = hom_skill_get_index(skill_id)) == -1)
  1478. return;
  1479. fd = sd->fd;
  1480. hd = sd->hd;
  1481. WFIFOHEAD(fd, packet_len(0x239));
  1482. WFIFOW(fd,0) = 0x239;
  1483. WFIFOW(fd,2) = skill_id;
  1484. WFIFOW(fd,4) = hd->homunculus.hskill[idx].lv;
  1485. WFIFOW(fd,6) = skill_get_sp(skill_id,hd->homunculus.hskill[idx].lv);
  1486. WFIFOW(fd,8) = skill_get_range2(&hd->bl,skill_id,hd->homunculus.hskill[idx].lv,false);
  1487. WFIFOB(fd,10) = (hd->homunculus.level < hom_skill_get_min_level(hd->homunculus.class_, skill_id) || hd->homunculus.hskill[idx].lv >= hom_skill_tree_get_max(hd->homunculus.hskill[idx].id, hd->homunculus.class_)) ? 0 : 1;
  1488. WFIFOSET(fd,packet_len(0x239));
  1489. }
  1490. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1491. {
  1492. int fd=sd->fd;
  1493. WFIFOHEAD(fd,packet_len(0x22f));
  1494. WFIFOW(fd,0)=0x22f;
  1495. WFIFOB(fd,2)=fail;
  1496. WFIFOW(fd,3)=foodid;
  1497. WFIFOSET(fd,packet_len(0x22f));
  1498. return 0;
  1499. }
  1500. /// Notifies the client, that it is walking (ZC_NOTIFY_PLAYERMOVE).
  1501. /// 0087 <walk start time>.L <walk data>.6B
  1502. void clif_walkok(struct map_session_data *sd)
  1503. {
  1504. int fd=sd->fd;
  1505. WFIFOHEAD(fd, packet_len(0x87));
  1506. WFIFOW(fd,0)=0x87;
  1507. WFIFOL(fd,2)=gettick();
  1508. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1509. WFIFOSET(fd,packet_len(0x87));
  1510. }
  1511. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1512. {
  1513. uint8 buf[128];
  1514. int len;
  1515. struct status_change *sc = NULL;
  1516. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1517. clif_ally_only = true;
  1518. len = clif_set_unit_walking(bl,ud,buf);
  1519. clif_send(buf,len,bl,AREA_WOS);
  1520. if (disguised(bl))
  1521. clif_setdisguise(bl, buf, len);
  1522. if(vd->cloth_color)
  1523. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1524. if(vd->body_style)
  1525. clif_refreshlook(bl,bl->id,LOOK_BODY2,vd->body_style,AREA_WOS);
  1526. switch(bl->type) {
  1527. case BL_PC:
  1528. {
  1529. TBL_PC *sd = ((TBL_PC*)bl);
  1530. // clif_movepc(sd);
  1531. if(sd->state.size==SZ_BIG) // tiny/big players [Valaris]
  1532. clif_specialeffect(&sd->bl,EF_GIANTBODY2,AREA);
  1533. else if(sd->state.size==SZ_MEDIUM)
  1534. clif_specialeffect(&sd->bl,EF_BABYBODY2,AREA);
  1535. if (sd->status.robe)
  1536. clif_refreshlook(bl,bl->id,LOOK_ROBE,sd->status.robe,AREA);
  1537. }
  1538. break;
  1539. case BL_MOB:
  1540. {
  1541. TBL_MOB *md = ((TBL_MOB*)bl);
  1542. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  1543. clif_specialeffect(&md->bl,EF_GIANTBODY2,AREA);
  1544. else if(md->special_state.size==SZ_MEDIUM)
  1545. clif_specialeffect(&md->bl,EF_BABYBODY2,AREA);
  1546. }
  1547. break;
  1548. case BL_PET:
  1549. if(vd->head_bottom) // needed to display pet equip properly
  1550. clif_pet_equip_area((TBL_PET*)bl);
  1551. break;
  1552. }
  1553. clif_ally_only = false;
  1554. }
  1555. /// Notifies clients in an area, that an other visible object is walking (ZC_NOTIFY_PLAYERMOVE).
  1556. /// 0086 <id>.L <walk data>.6B <walk start time>.L
  1557. /// Note: unit must not be self
  1558. void clif_move(struct unit_data *ud)
  1559. {
  1560. unsigned char buf[16];
  1561. struct view_data* vd;
  1562. struct block_list* bl = ud->bl;
  1563. struct status_change *sc = NULL;
  1564. vd = status_get_viewdata(bl);
  1565. if (!vd )
  1566. return;
  1567. //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1568. else if( vd->class_ == JT_INVISIBLE ){
  1569. // If the player was disguised we still need to update the disguised unit, since the main unit will be updated through clif_walkok
  1570. if(disguised(bl)) {
  1571. WBUFW(buf,0)=0x86;
  1572. WBUFL(buf,2)=-bl->id;
  1573. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1574. WBUFL(buf,12)=gettick();
  1575. clif_send(buf, packet_len(0x86), bl, SELF);
  1576. }
  1577. return;
  1578. }
  1579. /**
  1580. * Hide NPC from maya purple card.
  1581. **/
  1582. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  1583. return;
  1584. if (ud->state.speed_changed) {
  1585. // Since we don't know how to update the speed of other objects,
  1586. // use the old walk packet to update the data.
  1587. ud->state.speed_changed = 0;
  1588. clif_move2(bl, vd, ud);
  1589. return;
  1590. }
  1591. if ((sc = status_get_sc(bl)) && sc->option&(OPTION_HIDE|OPTION_CLOAK|OPTION_INVISIBLE|OPTION_CHASEWALK))
  1592. clif_ally_only = true;
  1593. WBUFW(buf,0)=0x86;
  1594. WBUFL(buf,2)=bl->id;
  1595. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1596. WBUFL(buf,12)=gettick();
  1597. clif_send(buf, packet_len(0x86), bl, AREA_WOS);
  1598. if (disguised(bl)) {
  1599. WBUFL(buf,2)=-bl->id;
  1600. clif_send(buf, packet_len(0x86), bl, SELF);
  1601. }
  1602. clif_ally_only = false;
  1603. }
  1604. /*==========================================
  1605. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1606. *------------------------------------------*/
  1607. static int clif_delayquit(int tid, unsigned int tick, int id, intptr_t data)
  1608. {
  1609. struct map_session_data *sd = NULL;
  1610. //Remove player from map server
  1611. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1612. map_quit(sd);
  1613. return 0;
  1614. }
  1615. /*==========================================
  1616. *
  1617. *------------------------------------------*/
  1618. void clif_quitsave(int fd,struct map_session_data *sd) {
  1619. if (!battle_config.prevent_logout ||
  1620. sd->canlog_tick == 0 ||
  1621. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1622. map_quit(sd);
  1623. else if (sd->fd) {
  1624. //Disassociate session from player (session is deleted after this function was called)
  1625. //And set a timer to make him quit later.
  1626. session[sd->fd]->session_data = NULL;
  1627. sd->fd = 0;
  1628. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1629. }
  1630. }
  1631. /// Notifies the client of a position change to coordinates on given map (ZC_NPCACK_MAPMOVE).
  1632. /// 0091 <map name>.16B <x>.W <y>.W
  1633. void clif_changemap(struct map_session_data *sd, short m, int x, int y)
  1634. {
  1635. int fd;
  1636. nullpo_retv(sd);
  1637. fd = sd->fd;
  1638. WFIFOHEAD(fd,packet_len(0x91));
  1639. WFIFOW(fd,0) = 0x91;
  1640. mapindex_getmapname_ext(map_mapid2mapname(m), WFIFOCP(fd,2));
  1641. WFIFOW(fd,18) = x;
  1642. WFIFOW(fd,20) = y;
  1643. WFIFOSET(fd,packet_len(0x91));
  1644. }
  1645. /// Notifies the client of a position change to coordinates on given map, which is on another map-server.
  1646. /// 0092 <map name>.16B <x>.W <y>.W <ip>.L <port>.W (ZC_NPCACK_SERVERMOVE)
  1647. /// 0ac7 <map name>.16B <x>.W <y>.W <ip>.L <port>.W <unknown>.128B (ZC_NPCACK_SERVERMOVE2)
  1648. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1649. {
  1650. int fd;
  1651. #if PACKETVER >= 20170315
  1652. int cmd = 0xac7;
  1653. #else
  1654. int cmd = 0x92;
  1655. #endif
  1656. nullpo_retv(sd);
  1657. fd = sd->fd;
  1658. WFIFOHEAD(fd,packet_len(cmd));
  1659. WFIFOW(fd,0) = cmd;
  1660. mapindex_getmapname_ext(mapindex_id2name(map_index), WFIFOCP(fd,2));
  1661. WFIFOW(fd,18) = x;
  1662. WFIFOW(fd,20) = y;
  1663. WFIFOL(fd,22) = htonl(ip);
  1664. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1665. #if PACKETVER >= 20170315
  1666. memset(WFIFOP(fd, 28), 0, 128); // Unknown
  1667. #endif
  1668. WFIFOSET(fd,packet_len(cmd));
  1669. }
  1670. /// In many situations (knockback, backslide, etc.) Aegis sends both clif_slide and clif_fixpos
  1671. /// This function combines both calls and allows to simplify the calling code
  1672. void clif_blown(struct block_list *bl)
  1673. {
  1674. clif_slide(bl, bl->x, bl->y);
  1675. clif_fixpos(bl);
  1676. }
  1677. /// Visually moves(slides) a character to x,y. If the target cell
  1678. /// isn't walkable, the char doesn't move at all. If the char is
  1679. /// sitting it will stand up (ZC_STOPMOVE).
  1680. /// 0088 <id>.L <x>.W <y>.W
  1681. void clif_fixpos(struct block_list *bl)
  1682. {
  1683. unsigned char buf[10];
  1684. nullpo_retv(bl);
  1685. WBUFW(buf,0) = 0x88;
  1686. WBUFL(buf,2) = bl->id;
  1687. WBUFW(buf,6) = bl->x;
  1688. WBUFW(buf,8) = bl->y;
  1689. clif_send(buf, packet_len(0x88), bl, AREA);
  1690. if( disguised(bl) ) {
  1691. WBUFL(buf,2) = -bl->id;
  1692. clif_send(buf, packet_len(0x88), bl, SELF);
  1693. }
  1694. }
  1695. /// Displays the buy/sell dialog of an NPC shop (ZC_SELECT_DEALTYPE).
  1696. /// 00c4 <shop id>.L
  1697. void clif_npcbuysell(struct map_session_data* sd, int id)
  1698. {
  1699. int fd;
  1700. nullpo_retv(sd);
  1701. fd=sd->fd;
  1702. WFIFOHEAD(fd, packet_len(0xc4));
  1703. WFIFOW(fd,0)=0xc4;
  1704. WFIFOL(fd,2)=id;
  1705. WFIFOSET(fd,packet_len(0xc4));
  1706. }
  1707. /// Presents list of items, that can be bought in an NPC shop (ZC_PC_PURCHASE_ITEMLIST).
  1708. /// 00c6 <packet len>.W { <price>.L <discount price>.L <item type>.B <name id>.W }*
  1709. void clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1710. {
  1711. int fd,i,c;
  1712. bool discount;
  1713. nullpo_retv(sd);
  1714. nullpo_retv(nd);
  1715. fd = sd->fd;
  1716. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1717. WFIFOW(fd,0) = 0xc6;
  1718. c = 0;
  1719. discount = npc_shop_discount(nd->subtype,nd->u.shop.discount);
  1720. for( i = 0; i < nd->u.shop.count; i++ )
  1721. {
  1722. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1723. int val = nd->u.shop.shop_item[i].value;
  1724. if( id == NULL )
  1725. continue;
  1726. WFIFOL(fd, 4+c*11) = val;
  1727. WFIFOL(fd, 8+c*11) = (discount) ? pc_modifybuyvalue(sd,val) : val;
  1728. WFIFOB(fd,12+c*11) = itemtype(id->nameid);
  1729. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1730. c++;
  1731. }
  1732. WFIFOW(fd,2) = 4 + c*11;
  1733. WFIFOSET(fd,WFIFOW(fd,2));
  1734. }
  1735. /// Presents list of items, that can be sold to an NPC shop (ZC_PC_SELL_ITEMLIST).
  1736. /// 00c7 <packet len>.W { <index>.W <price>.L <overcharge price>.L }*
  1737. void clif_selllist(struct map_session_data *sd)
  1738. {
  1739. int fd,i,c=0,val;
  1740. nullpo_retv(sd);
  1741. fd=sd->fd;
  1742. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1743. WFIFOW(fd,0)=0xc7;
  1744. for( i = 0; i < MAX_INVENTORY; i++ )
  1745. {
  1746. if( sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory_data[i] )
  1747. {
  1748. if( !pc_can_sell_item(sd, &sd->inventory.u.items_inventory[i]))
  1749. continue;
  1750. val=sd->inventory_data[i]->value_sell;
  1751. if( val < 0 )
  1752. continue;
  1753. WFIFOW(fd,4+c*10)=i+2;
  1754. WFIFOL(fd,6+c*10)=val;
  1755. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1756. c++;
  1757. }
  1758. }
  1759. WFIFOW(fd,2)=c*10+4;
  1760. WFIFOSET(fd,WFIFOW(fd,2));
  1761. }
  1762. /// Closes shop (CZ_NPC_TRADE_QUIT).
  1763. /// 09d4
  1764. void clif_parse_NPCShopClosed(int fd, struct map_session_data *sd) {
  1765. // TODO: State tracking?
  1766. sd->npc_shopid = 0;
  1767. }
  1768. /**
  1769. * Presents list of items, that can be sold to a Market shop.
  1770. * @author: Ind and Yommy
  1771. **/
  1772. void clif_npc_market_open(struct map_session_data *sd, struct npc_data *nd) {
  1773. #if PACKETVER >= 20131223
  1774. struct npc_item_list *shop = nd->u.shop.shop_item;
  1775. unsigned short shop_size = nd->u.shop.count, i, c, cmd = 0x9d5;
  1776. struct item_data *id = NULL;
  1777. struct s_packet_db *info;
  1778. int fd;
  1779. nullpo_retv(sd);
  1780. if (sd->state.trading)
  1781. return;
  1782. info = &packet_db[cmd];
  1783. if (!info || info->len == 0)
  1784. return;
  1785. fd = sd->fd;
  1786. WFIFOHEAD(fd, 4 + shop_size * 13);
  1787. WFIFOW(fd,0) = cmd;
  1788. for (i = 0, c = 0; i < shop_size; i++) {
  1789. if (shop[i].nameid && (id = itemdb_exists(shop[i].nameid))) {
  1790. WFIFOW(fd, 4+c*13) = shop[i].nameid;
  1791. WFIFOB(fd, 6+c*13) = itemtype(id->nameid);
  1792. WFIFOL(fd, 7+c*13) = shop[i].value;
  1793. WFIFOL(fd,11+c*13) = shop[i].qty;
  1794. WFIFOW(fd,15+c*13) = id->weight;
  1795. c++;
  1796. }
  1797. }
  1798. WFIFOW(fd,2) = 4 + c*13;
  1799. WFIFOSET(fd,WFIFOW(fd,2));
  1800. sd->state.trading = 1;
  1801. #endif
  1802. }
  1803. /// Closes the Market shop window.
  1804. void clif_parse_NPCMarketClosed(int fd, struct map_session_data *sd) {
  1805. nullpo_retv(sd);
  1806. sd->npc_shopid = 0;
  1807. sd->state.trading = 0;
  1808. }
  1809. /// Purchase item from Market shop.
  1810. void clif_npc_market_purchase_ack(struct map_session_data *sd, uint8 res, uint8 n, struct s_npc_buy_list *list) {
  1811. #if PACKETVER >= 20131223
  1812. unsigned short cmd = 0x9d7, len = 0;
  1813. struct npc_data* nd;
  1814. uint8 result = (res == 0 ? 1 : 0);
  1815. int fd = 0;
  1816. struct s_packet_db *info;
  1817. nullpo_retv(sd);
  1818. nullpo_retv((nd = map_id2nd(sd->npc_shopid)));
  1819. info = &packet_db[cmd];
  1820. if (!info || info->len == 0)
  1821. return;
  1822. fd = sd->fd;
  1823. len = 5 + 8*n;
  1824. WFIFOHEAD(fd, len);
  1825. WFIFOW(fd, 0) = cmd;
  1826. WFIFOW(fd, 2) = len;
  1827. if (result) {
  1828. uint8 i, j;
  1829. struct npc_item_list *shop = nd->u.shop.shop_item;
  1830. unsigned short count = nd->u.shop.count;
  1831. for (i = 0; i < n; i++) {
  1832. WFIFOW(fd, 5+i*8) = list[i].nameid;
  1833. WFIFOW(fd, 7+i*8) = list[i].qty;
  1834. ARR_FIND(0, count, j, list[i].nameid == shop[j].nameid);
  1835. WFIFOL(fd, 9+i*8) = (j != count) ? shop[j].value : 0;
  1836. }
  1837. }
  1838. WFIFOB(fd, 4) = n;
  1839. WFIFOSET(fd, len);
  1840. #endif
  1841. }
  1842. /// Purchase item from Market shop.
  1843. void clif_parse_NPCMarketPurchase(int fd, struct map_session_data *sd) {
  1844. #if PACKETVER >= 20131223
  1845. struct s_packet_db* info;
  1846. struct s_npc_buy_list *item_list;
  1847. uint16 len = 0, i = 0;
  1848. uint8 res = 0, n = 0;
  1849. nullpo_retv(sd);
  1850. if (!sd->npc_shopid)
  1851. return;
  1852. info = &packet_db[RFIFOW(fd,0)];
  1853. if (!info || info->len == 0)
  1854. return;
  1855. len = RFIFOW(fd,info->pos[0]);
  1856. n = (len-4) / 6;
  1857. CREATE(item_list, struct s_npc_buy_list, n);
  1858. for (i = 0; i < n; i++) {
  1859. item_list[i].nameid = RFIFOW(fd,info->pos[1]+i*6);
  1860. item_list[i].qty = (uint16)min(RFIFOL(fd,info->pos[2]+i*6),USHRT_MAX);
  1861. }
  1862. res = npc_buylist(sd, n, item_list);
  1863. clif_npc_market_purchase_ack(sd, res, n, item_list);
  1864. aFree(item_list);
  1865. #endif
  1866. }
  1867. /// Displays an NPC dialog message (ZC_SAY_DIALOG).
  1868. /// 00b4 <packet len>.W <npc id>.L <message>.?B
  1869. /// Client behavior (dialog window):
  1870. /// - disable mouse targeting
  1871. /// - open the dialog window
  1872. /// - set npcid of dialog window (0 by default)
  1873. /// - if set to clear on next mes, clear contents
  1874. /// - append this text
  1875. void clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1876. {
  1877. int fd = sd->fd;
  1878. int slen = strlen(mes) + 9;
  1879. WFIFOHEAD(fd, slen);
  1880. WFIFOW(fd,0)=0xb4;
  1881. WFIFOW(fd,2)=slen;
  1882. WFIFOL(fd,4)=npcid;
  1883. memcpy(WFIFOCP(fd,8), mes, slen-8);
  1884. WFIFOSET(fd,WFIFOW(fd,2));
  1885. }
  1886. /// Adds a 'next' button to an NPC dialog (ZC_WAIT_DIALOG).
  1887. /// 00b5 <npc id>.L
  1888. /// Client behavior (dialog window):
  1889. /// - disable mouse targeting
  1890. /// - open the dialog window
  1891. /// - add 'next' button
  1892. /// When 'next' is pressed:
  1893. /// - 00B9 <npcid of dialog window>.L
  1894. /// - set to clear on next mes
  1895. /// - remove 'next' button
  1896. void clif_scriptnext(struct map_session_data *sd,int npcid)
  1897. {
  1898. int fd;
  1899. nullpo_retv(sd);
  1900. fd=sd->fd;
  1901. WFIFOHEAD(fd, packet_len(0xb5));
  1902. WFIFOW(fd,0)=0xb5;
  1903. WFIFOL(fd,2)=npcid;
  1904. WFIFOSET(fd,packet_len(0xb5));
  1905. }
  1906. /// Adds a 'close' button to an NPC dialog (ZC_CLOSE_DIALOG).
  1907. /// 00b6 <npc id>.L
  1908. /// Client behavior:
  1909. /// - if dialog window is open:
  1910. /// - remove 'next' button
  1911. /// - add 'close' button
  1912. /// - else:
  1913. /// - enable mouse targeting
  1914. /// - close the dialog window
  1915. /// - close the menu window
  1916. /// When 'close' is pressed:
  1917. /// - enable mouse targeting
  1918. /// - close the dialog window
  1919. /// - close the menu window
  1920. /// - 0146 <npcid of dialog window>.L
  1921. void clif_scriptclose(struct map_session_data *sd, int npcid)
  1922. {
  1923. int fd;
  1924. nullpo_retv(sd);
  1925. fd=sd->fd;
  1926. WFIFOHEAD(fd, packet_len(0xb6));
  1927. WFIFOW(fd,0)=0xb6;
  1928. WFIFOL(fd,2)=npcid;
  1929. WFIFOSET(fd,packet_len(0xb6));
  1930. }
  1931. /**
  1932. * Close script when player is idle
  1933. * 08d6 <npc id>.L (ZC_CLEAR_DIALOG)
  1934. * @author [Ind/Hercules]
  1935. * @param sd : player pointer
  1936. * @param npcid : npc gid to close
  1937. */
  1938. void clif_scriptclear(struct map_session_data *sd, int npcid)
  1939. {
  1940. struct s_packet_db* info;
  1941. int16 len;
  1942. int cmd = 0;
  1943. int fd;
  1944. nullpo_retv(sd);
  1945. cmd = packet_db_ack[ZC_CLEAR_DIALOG];
  1946. if(!cmd) cmd = 0x8d6; //default
  1947. info = &packet_db[cmd];
  1948. len = info->len;
  1949. fd = sd->fd;
  1950. WFIFOHEAD(fd, len);
  1951. WFIFOW(fd,0)=0x8d6;
  1952. WFIFOL(fd,info->pos[0])=npcid;
  1953. WFIFOSET(fd,len);
  1954. }
  1955. /*==========================================
  1956. *
  1957. *------------------------------------------*/
  1958. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1959. unsigned char *buf;
  1960. int fd = sd->fd;
  1961. sd->state.using_fake_npc = 1;
  1962. WFIFOHEAD(fd, packet_len(0x78));
  1963. buf = WFIFOP(fd,0);
  1964. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1965. WBUFW(buf,0)=0x78;
  1966. #if PACKETVER >= 20071106
  1967. WBUFB(buf,2) = 0; // object type
  1968. buf = WFIFOP(fd,1);
  1969. #endif
  1970. WBUFL(buf,2)=npcid;
  1971. WBUFW(buf,14)=111;
  1972. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1973. WBUFB(buf,49)=5;
  1974. WBUFB(buf,50)=5;
  1975. WFIFOSET(fd, packet_len(0x78));
  1976. }
  1977. /// Displays an NPC dialog menu (ZC_MENU_LIST).
  1978. /// 00b7 <packet len>.W <npc id>.L <menu items>.?B
  1979. /// Client behavior:
  1980. /// - disable mouse targeting
  1981. /// - close the menu window
  1982. /// - open the menu window
  1983. /// - add options to the menu (separated in the text by ":")
  1984. /// - set npcid of menu window
  1985. /// - if dialog window is open:
  1986. /// - remove 'next' button
  1987. /// When 'ok' is pressed:
  1988. /// - 00B8 <npcid of menu window>.L <selected option>.B
  1989. /// - close the menu window
  1990. /// When 'cancel' is pressed:
  1991. /// - 00B8 <npcid of menu window>.L <-1>.B
  1992. /// - enable mouse targeting
  1993. /// - close a bunch of windows...
  1994. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1995. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1996. /// TODO investigate behavior of other windows [FlavioJS]
  1997. void clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1998. {
  1999. int fd = sd->fd;
  2000. int slen = strlen(mes) + 9;
  2001. struct block_list *bl = NULL;
  2002. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2003. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2004. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2005. clif_sendfakenpc(sd, npcid);
  2006. WFIFOHEAD(fd, slen);
  2007. WFIFOW(fd,0)=0xb7;
  2008. WFIFOW(fd,2)=slen;
  2009. WFIFOL(fd,4)=npcid;
  2010. memcpy(WFIFOCP(fd,8), mes, slen-8);
  2011. WFIFOSET(fd,WFIFOW(fd,2));
  2012. }
  2013. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLG).
  2014. /// 0142 <npc id>.L
  2015. /// Client behavior (inputnum window):
  2016. /// - if npcid exists in the client:
  2017. /// - open the inputnum window
  2018. /// - set npcid of inputnum window
  2019. /// When 'ok' is pressed:
  2020. /// - if inputnum window has text:
  2021. /// - if npcid exists in the client:
  2022. /// - 0143 <npcid of inputnum window>.L <atoi(text)>.L
  2023. /// - close inputnum window
  2024. void clif_scriptinput(struct map_session_data *sd, int npcid)
  2025. {
  2026. int fd;
  2027. struct block_list *bl = NULL;
  2028. nullpo_retv(sd);
  2029. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2030. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2031. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2032. clif_sendfakenpc(sd, npcid);
  2033. fd=sd->fd;
  2034. WFIFOHEAD(fd, packet_len(0x142));
  2035. WFIFOW(fd,0)=0x142;
  2036. WFIFOL(fd,2)=npcid;
  2037. WFIFOSET(fd,packet_len(0x142));
  2038. }
  2039. /// Displays an NPC dialog input box for numbers (ZC_OPEN_EDITDLGSTR).
  2040. /// 01d4 <npc id>.L
  2041. /// Client behavior (inputstr window):
  2042. /// - if npcid is 0 or npcid exists in the client:
  2043. /// - open the inputstr window
  2044. /// - set npcid of inputstr window
  2045. /// When 'ok' is pressed:
  2046. /// - if inputstr window has text and isn't an insult(manner.txt):
  2047. /// - if npcid is 0 or npcid exists in the client:
  2048. /// - 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  2049. /// - close inputstr window
  2050. void clif_scriptinputstr(struct map_session_data *sd, int npcid)
  2051. {
  2052. int fd;
  2053. struct block_list *bl = NULL;
  2054. nullpo_retv(sd);
  2055. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  2056. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  2057. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  2058. clif_sendfakenpc(sd, npcid);
  2059. fd=sd->fd;
  2060. WFIFOHEAD(fd, packet_len(0x1d4));
  2061. WFIFOW(fd,0)=0x1d4;
  2062. WFIFOL(fd,2)=npcid;
  2063. WFIFOSET(fd,packet_len(0x1d4));
  2064. }
  2065. /// Marks a position on client's minimap (ZC_COMPASS).
  2066. /// 0144 <npc id>.L <type>.L <x>.L <y>.L <id>.B <color>.L
  2067. /// npc id:
  2068. /// is ignored in the client
  2069. /// type:
  2070. /// 0 = display mark for 15 seconds
  2071. /// 1 = display mark until dead or teleported
  2072. /// 2 = remove mark
  2073. /// color:
  2074. /// 0x00RRGGBB
  2075. void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  2076. {
  2077. int fd;
  2078. nullpo_retv(sd);
  2079. fd=sd->fd;
  2080. WFIFOHEAD(fd, packet_len(0x144));
  2081. WFIFOW(fd,0)=0x144;
  2082. WFIFOL(fd,2)=npc_id;
  2083. WFIFOL(fd,6)=type;
  2084. WFIFOL(fd,10)=x;
  2085. WFIFOL(fd,14)=y;
  2086. WFIFOB(fd,18)=id;
  2087. WFIFOL(fd,19)=color;
  2088. WFIFOSET(fd,packet_len(0x144));
  2089. }
  2090. /// Displays an illustration image.
  2091. /// 0145 <image name>.16B <type>.B (ZC_SHOW_IMAGE)
  2092. /// 01b3 <image name>.64B <type>.B (ZC_SHOW_IMAGE2)
  2093. /// type:
  2094. /// 0 = bottom left corner
  2095. /// 1 = bottom middle
  2096. /// 2 = bottom right corner
  2097. /// 3 = middle of screen, inside a movable window
  2098. /// 4 = middle of screen, movable with a close button, chrome-less
  2099. void clif_cutin(struct map_session_data* sd, const char* image, int type)
  2100. {
  2101. int fd;
  2102. nullpo_retv(sd);
  2103. fd=sd->fd;
  2104. WFIFOHEAD(fd, packet_len(0x1b3));
  2105. WFIFOW(fd,0)=0x1b3;
  2106. strncpy(WFIFOCP(fd,2),image,64);
  2107. WFIFOB(fd,66)=type;
  2108. WFIFOSET(fd,packet_len(0x1b3));
  2109. }
  2110. /*==========================================
  2111. * Fills in card data from the given item and into the buffer. [Skotlex]
  2112. *------------------------------------------*/
  2113. static void clif_addcards(unsigned char* buf, struct item* item)
  2114. {
  2115. int i=0,j;
  2116. if( item == NULL ) { //Blank data
  2117. WBUFW(buf,0) = 0;
  2118. WBUFW(buf,2) = 0;
  2119. WBUFW(buf,4) = 0;
  2120. WBUFW(buf,6) = 0;
  2121. return;
  2122. }
  2123. if( item->card[0] == CARD0_PET ) { //pet eggs
  2124. WBUFW(buf,0) = 0;
  2125. WBUFW(buf,2) = 0;
  2126. WBUFW(buf,4) = 0;
  2127. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  2128. return;
  2129. }
  2130. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  2131. WBUFW(buf,0) = item->card[0];
  2132. WBUFW(buf,2) = item->card[1];
  2133. WBUFW(buf,4) = item->card[2];
  2134. WBUFW(buf,6) = item->card[3];
  2135. return;
  2136. }
  2137. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  2138. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  2139. i = rnd()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rnd()%3;
  2140. //Normal items.
  2141. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2142. WBUFW(buf,0) = j;
  2143. else
  2144. WBUFW(buf,0) = item->card[i];
  2145. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2146. WBUFW(buf,2) = j;
  2147. else
  2148. WBUFW(buf,2) = item->card[i];
  2149. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2150. WBUFW(buf,4) = j;
  2151. else
  2152. WBUFW(buf,4) = item->card[i];
  2153. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  2154. WBUFW(buf,6) = j;
  2155. else
  2156. WBUFW(buf,6) = item->card[i];
  2157. }
  2158. /// Fills in part of the item buffers that calls for variable bonuses data. [Napster]
  2159. /// A maximum of 5 random options can be supported.
  2160. void clif_add_random_options(unsigned char* buf, struct item *it) {
  2161. #if PACKETVER >= 20150225
  2162. int i;
  2163. for (i = 0; i < MAX_ITEM_RDM_OPT; i++) {
  2164. WBUFW(buf, i*5 + 0) = it->option[i].id; // OptIndex
  2165. WBUFW(buf, i*5 + 2) = it->option[i].value; // Value
  2166. WBUFB(buf, i*5 + 4) = it->option[i].param; // Param1
  2167. }
  2168. #if MAX_ITEM_RDM_OPT < 5
  2169. for ( ; i < 5; i++) {
  2170. WBUFW(buf, i*5 + 0) = 0; // OptIndex
  2171. WBUFW(buf, i*5 + 2) = 0; // Value
  2172. WBUFB(buf, i*5 + 4) = 0; // Param1
  2173. }
  2174. #endif
  2175. #endif
  2176. }
  2177. /// Notifies the client, about a received inventory item or the result of a pick-up request.
  2178. /// 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)
  2179. /// 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)
  2180. /// 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)
  2181. /// 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)
  2182. /// 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)
  2183. /// 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)
  2184. void clif_additem(struct map_session_data *sd, int n, int amount, unsigned char fail)
  2185. {
  2186. int fd, header, offs=0;
  2187. #if PACKETVER < 20061218
  2188. header = 0xa0;
  2189. #elif PACKETVER < 20071002
  2190. header = 0x29a;
  2191. #elif PACKETVER < 20120925
  2192. header = 0x2d4;
  2193. #elif PACKETVER < 20150225
  2194. header = 0x990;
  2195. #elif PACKETVER < 20160921
  2196. header = 0xa0c;
  2197. #else
  2198. header = 0xa37;
  2199. #endif
  2200. nullpo_retv(sd);
  2201. fd = sd->fd;
  2202. if( !session_isActive(fd) ) //Sasuke-
  2203. return;
  2204. WFIFOHEAD(fd,packet_len(header));
  2205. if( fail )
  2206. {
  2207. WFIFOW(fd,offs+0) = header;
  2208. WFIFOW(fd,offs+2) = n+2;
  2209. WFIFOW(fd,offs+4) = amount;
  2210. WFIFOW(fd,offs+6) = 0;
  2211. WFIFOB(fd,offs+8) = 0;
  2212. WFIFOB(fd,offs+9) = 0;
  2213. WFIFOB(fd,offs+10) = 0;
  2214. WFIFOW(fd,offs+11) = 0;
  2215. WFIFOW(fd,offs+13) = 0;
  2216. WFIFOW(fd,offs+15) = 0;
  2217. WFIFOW(fd,offs+17) = 0;
  2218. #if PACKETVER < 20120925
  2219. WFIFOW(fd,offs+19) = 0;
  2220. #else
  2221. WFIFOL(fd,offs+19) = 0;
  2222. offs += 2;
  2223. #endif
  2224. WFIFOB(fd,offs+21) = 0;
  2225. WFIFOB(fd,offs+22) = fail;
  2226. #if PACKETVER >= 20061218
  2227. WFIFOL(fd,offs+23) = 0;
  2228. #endif
  2229. #if PACKETVER >= 20071002
  2230. WFIFOW(fd,offs+27) = 0; // HireExpireDate
  2231. #if PACKETVER >= 20150225
  2232. clif_add_random_options(WFIFOP(fd,offs+31), &sd->inventory.u.items_inventory[n]);
  2233. #if PACKETVER >= 20160921
  2234. WFIFOB(fd,offs+54) = 0; // Favorite
  2235. WFIFOW(fd,offs+55) = 0; // View ID
  2236. #endif
  2237. #endif
  2238. #endif
  2239. }
  2240. else
  2241. {
  2242. if( n < 0 || n >= MAX_INVENTORY || sd->inventory.u.items_inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  2243. return;
  2244. WFIFOW(fd,offs+0) = header;
  2245. WFIFOW(fd,offs+2) = n+2;
  2246. WFIFOW(fd,offs+4) = amount;
  2247. if (sd->inventory_data[n]->view_id > 0)
  2248. WFIFOW(fd,offs+6) = sd->inventory_data[n]->view_id;
  2249. else
  2250. WFIFOW(fd,offs+6)=sd->inventory.u.items_inventory[n].nameid;
  2251. WFIFOB(fd,offs+8)=sd->inventory.u.items_inventory[n].identify;
  2252. WFIFOB(fd,offs+9)=sd->inventory.u.items_inventory[n].attribute;
  2253. WFIFOB(fd,offs+10)=sd->inventory.u.items_inventory[n].refine;
  2254. clif_addcards(WFIFOP(fd,offs+11), &sd->inventory.u.items_inventory[n]);
  2255. #if PACKETVER < 20120925
  2256. WFIFOW(fd,offs+19) = pc_equippoint(sd,n);
  2257. #else
  2258. WFIFOL(fd,offs+19) = pc_equippoint(sd,n);
  2259. offs += 2;
  2260. #endif
  2261. WFIFOB(fd,offs+21) = itemtype(sd->inventory_data[n]->nameid);
  2262. WFIFOB(fd,offs+22) = fail;
  2263. #if PACKETVER >= 20061218
  2264. WFIFOL(fd,offs+23)=sd->inventory.u.items_inventory[n].expire_time;
  2265. #endif
  2266. #if PACKETVER >= 20071002
  2267. /* Yellow color only for non-stackable item */
  2268. 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;
  2269. #endif
  2270. #if PACKETVER >= 20150225
  2271. clif_add_random_options(WFIFOP(fd,31), &sd->inventory.u.items_inventory[n]);
  2272. #if PACKETVER >= 20160921
  2273. WFIFOB(fd,offs+54) = sd->inventory.u.items_inventory[n].favorite;
  2274. WFIFOW(fd,offs+55) = sd->inventory_data[n]->look;
  2275. #endif
  2276. #endif
  2277. }
  2278. WFIFOSET(fd,packet_len(header));
  2279. }
  2280. /// Notifies the client, that an inventory item was deleted or dropped (ZC_ITEM_THROW_ACK).
  2281. /// 00af <index>.W <amount>.W
  2282. void clif_dropitem(struct map_session_data *sd,int n,int amount)
  2283. {
  2284. int fd;
  2285. nullpo_retv(sd);
  2286. fd=sd->fd;
  2287. WFIFOHEAD(fd, packet_len(0xaf));
  2288. WFIFOW(fd,0)=0xaf;
  2289. WFIFOW(fd,2)=n+2;
  2290. WFIFOW(fd,4)=amount;
  2291. WFIFOSET(fd,packet_len(0xaf));
  2292. }
  2293. /// Notifies the client, that an inventory item was deleted (ZC_DELETE_ITEM_FROM_BODY).
  2294. /// 07fa <delete type>.W <index>.W <amount>.W
  2295. /// delete type:
  2296. /// 0 = Normal
  2297. /// 1 = Item used for a skill
  2298. /// 2 = Refine failed
  2299. /// 3 = Material changed
  2300. /// 4 = Moved to storage
  2301. /// 5 = Moved to cart
  2302. /// 6 = Item sold
  2303. /// 7 = Consumed by Four Spirit Analysis (SO_EL_ANALYSIS) skill
  2304. void clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  2305. {
  2306. #if PACKETVER < 20091117
  2307. clif_dropitem(sd,n,amount);
  2308. #else
  2309. int fd;
  2310. nullpo_retv(sd);
  2311. fd=sd->fd;
  2312. WFIFOHEAD(fd, packet_len(0x7fa));
  2313. WFIFOW(fd,0)=0x7fa;
  2314. WFIFOW(fd,2)=reason;
  2315. WFIFOW(fd,4)=n+2;
  2316. WFIFOW(fd,6)=amount;
  2317. WFIFOSET(fd,packet_len(0x7fa));
  2318. #endif
  2319. }
  2320. void clif_item_sub_v5(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2321. char normal = (equip < 0);
  2322. int offset = 0;
  2323. WBUFW(buf,n) = idx; //index
  2324. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid;
  2325. WBUFB(buf,n+4) = itemtype(id->nameid);
  2326. if (!normal){ //equip 31B
  2327. WBUFL(buf,n+5) = equip; //location
  2328. WBUFL(buf,n+9) = it->equip; //wear state
  2329. WBUFB(buf,n+13) = it->refine; //refine lvl
  2330. clif_addcards(WBUFP(buf, n+14), it); //EQUIPSLOTINFO 8B
  2331. WBUFL(buf,n+22) = it->expire_time;
  2332. WBUFW(buf,n+26) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0; //bindOnEquipType
  2333. WBUFW(buf,n+28) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2334. #if PACKETVER >= 20150225
  2335. //V6_ITEM_Option
  2336. WBUFB(buf,n+30) = 0; // nRandomOptionCnt
  2337. clif_add_random_options(WBUFP(buf, n+31), it);// optionData
  2338. offset += 26;
  2339. #endif
  2340. //V5_ITEM_flag
  2341. WBUFB(buf,n+30+offset) = it->identify; //0x1 IsIdentified
  2342. WBUFB(buf,n+30+offset) |= (it->attribute) ? 0x2 : 0; //0x2 IsDamaged
  2343. WBUFB(buf,n+30+offset) |= (it->favorite) ? 0x4 : 0; //0x4 PlaceETCTab
  2344. }
  2345. else { //normal 24B
  2346. WBUFW(buf,n+5) = it->amount;
  2347. WBUFL(buf,n+7) = (equip == -2 && id->equip == EQP_AMMO)?id->equip:0; //wear state
  2348. clif_addcards(WBUFP(buf, n+11), it); //EQUIPSLOTINFO 8B
  2349. WBUFL(buf,n+19) = it->expire_time;
  2350. //V5_ITEM_flag
  2351. WBUFB(buf,n+23) = it->identify; //0x1 IsIdentified
  2352. WBUFB(buf,n+23) |= (it->favorite) ? 0x2 : 0; //0x4,0x2 PlaceETCTab
  2353. }
  2354. }
  2355. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  2356. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  2357. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  2358. void clif_item_sub(unsigned char *buf, int n, int idx, struct item *it, struct item_data *id, int equip) {
  2359. #if PACKETVER >= 20120925
  2360. clif_item_sub_v5(buf, n, idx, it, id, equip);
  2361. #else
  2362. WBUFW(buf,n) = idx; //index
  2363. WBUFW(buf,n+2) = (id->view_id > 0) ? id->view_id : it->nameid; //itid
  2364. WBUFB(buf,n+4) = itemtype(id->nameid);
  2365. WBUFB(buf,n+5) = it->identify;
  2366. if (equip >= 0) { //Equippable item 28.B
  2367. WBUFW(buf,n+6) = equip;
  2368. WBUFW(buf,n+8) = it->equip;
  2369. WBUFB(buf,n+10) = it->attribute;
  2370. WBUFB(buf,n+11) = it->refine;
  2371. clif_addcards(WBUFP(buf, n+12), it); //8B
  2372. #if PACKETVER >= 20071002
  2373. WBUFL(buf,n+20) = it->expire_time;
  2374. WBUFW(buf,n+24) = it->bound ? BOUND_DISPYELLOW : id->flag.bindOnEquip ? BOUND_ONEQUIP : 0;
  2375. #endif
  2376. #if PACKETVER >= 20100629
  2377. WBUFW(buf,n+26) = (id->equip&EQP_VISIBLE) ? id->look : 0;
  2378. #endif
  2379. } else { //Stackable item. 22.B
  2380. WBUFW(buf,n+6) = it->amount;
  2381. WBUFW(buf,n+8) = (equip == -2 && id->equip == EQP_AMMO) ? id->equip : 0;
  2382. clif_addcards(WBUFP(buf, n+10), it); //8B
  2383. #if PACKETVER >= 20071002
  2384. WBUFL(buf,n+18) = it->expire_time;
  2385. #endif
  2386. }
  2387. #endif
  2388. }
  2389. void clif_favorite_item(struct map_session_data* sd, unsigned short index);
  2390. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2391. void clif_inventorylist(struct map_session_data *sd) {
  2392. int i,n,ne,arrow=-1;
  2393. unsigned char *buf;
  2394. unsigned char *bufe;
  2395. #if PACKETVER < 5
  2396. const int s = 10; //Entry size
  2397. #elif PACKETVER < 20080102
  2398. const int s = 18;
  2399. #elif PACKETVER < 20120925
  2400. const int s = 22;
  2401. #else
  2402. const int s = 24;
  2403. #endif
  2404. #if PACKETVER < 20071002
  2405. const int se = 20;
  2406. #elif PACKETVER < 20100629
  2407. const int se = 26;
  2408. #elif PACKETVER < 20120925
  2409. const int se = 28;
  2410. #elif PACKETVER < 20150225
  2411. const int se = 31;
  2412. #else
  2413. const int se = 57;
  2414. #endif
  2415. buf = (unsigned char*)aMalloc(MAX_INVENTORY * s + 4);
  2416. bufe = (unsigned char*)aMalloc(MAX_INVENTORY * se + 4);
  2417. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  2418. {
  2419. if( sd->inventory.u.items_inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  2420. continue;
  2421. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  2422. { //Non-stackable (Equippable)
  2423. clif_item_sub(bufe, ne*se+4, i+2, &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2424. ne++;
  2425. }
  2426. else { //Stackable.
  2427. clif_item_sub(buf, n*s+4,i+2, &sd->inventory.u.items_inventory[i], sd->inventory_data[i], -2);
  2428. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->inventory.u.items_inventory[i].equip )
  2429. arrow=i;
  2430. n++;
  2431. }
  2432. }
  2433. if( n )
  2434. {
  2435. #if PACKETVER < 5
  2436. WBUFW(buf,0)=0xa3;
  2437. #elif PACKETVER < 20080102
  2438. WBUFW(buf,0)=0x1ee;
  2439. #elif PACKETVER < 20120925
  2440. WBUFW(buf,0)=0x2e8;
  2441. #else
  2442. WBUFW(buf,0)=0x991;
  2443. #endif
  2444. WBUFW(buf,2)=4+n*s;
  2445. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2446. }
  2447. if( arrow >= 0 )
  2448. clif_arrowequip(sd,arrow);
  2449. if( ne ) {
  2450. #if PACKETVER < 20071002
  2451. WBUFW(bufe,0)=0xa4;
  2452. #elif PACKETVER < 20120925
  2453. WBUFW(bufe,0)=0x2d0;
  2454. #elif PACKETVER < 20150225
  2455. WBUFW(bufe,0)=0x992;
  2456. #else
  2457. WBUFW(bufe,0)=0xa0d;
  2458. #endif
  2459. WBUFW(bufe,2)=4+ne*se;
  2460. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2461. }
  2462. #if PACKETVER >= 20111122 && PACKETVER < 20120925
  2463. for( i = 0; i < MAX_INVENTORY; i++ ) {
  2464. if( sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL )
  2465. continue;
  2466. if ( sd->inventory.u.items_inventory[i].favorite )
  2467. clif_favorite_item(sd, i);
  2468. }
  2469. #endif
  2470. if( buf ) aFree(buf);
  2471. if( bufe ) aFree(bufe);
  2472. }
  2473. //Required when items break/get-repaired. Only sends equippable item list.
  2474. void clif_equiplist(struct map_session_data *sd)
  2475. {
  2476. int i,n,fd = sd->fd;
  2477. unsigned char *buf;
  2478. #if PACKETVER < 20071002
  2479. const int cmd = 20;
  2480. #elif PACKETVER < 20100629
  2481. const int cmd = 26;
  2482. #elif PACKETVER < 20120925
  2483. const int cmd = 28;
  2484. #elif PACKETVER < 20150225
  2485. const int cmd = 31;
  2486. #else
  2487. const int cmd = 57;
  2488. #endif
  2489. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  2490. buf = WFIFOP(fd,0);
  2491. for(i=0,n=0;i<MAX_INVENTORY;i++){
  2492. if (sd->inventory.u.items_inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  2493. continue;
  2494. if(itemdb_isstackable2(sd->inventory_data[i]))
  2495. continue;
  2496. //Equippable
  2497. clif_item_sub(buf, n*cmd+4,i+2, &sd->inventory.u.items_inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  2498. n++;
  2499. }
  2500. if (n) {
  2501. #if PACKETVER < 20071002
  2502. WBUFW(buf,0)=0xa4;
  2503. #elif PACKETVER < 20120925
  2504. WBUFW(buf,0)=0x2d0;
  2505. #elif PACKETVER < 20150225
  2506. WBUFW(buf,0)=0x992;
  2507. #else
  2508. WBUFW(buf,0)=0xa0d;
  2509. #endif
  2510. WBUFW(buf,2)=4+n*cmd;
  2511. WFIFOSET(fd,WFIFOW(fd,2));
  2512. }
  2513. }
  2514. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length, const char *storename)
  2515. {
  2516. static const int client_buf = 0x5000; // Max buffer to send
  2517. struct item_data *id;
  2518. int i,n,ne,nn;
  2519. unsigned char *buf;
  2520. unsigned char *bufe;
  2521. #if PACKETVER < 5
  2522. const int s = 10; //Entry size.normal item
  2523. const int sidx=4; //start itemlist idx
  2524. const int cmd = 0xa5;
  2525. #elif PACKETVER < 20080102
  2526. const int s = 18;
  2527. const int sidx=4;
  2528. const int cmd = 0x1f0;
  2529. #elif PACKETVER < 20120925
  2530. const int s = 22;
  2531. const int sidx=4;
  2532. const int cmd = 0x2ea;
  2533. #else
  2534. const int s = 24;
  2535. const int sidx = 4+24;
  2536. const int cmd = 0x995;
  2537. #endif
  2538. #if PACKETVER < 20071002
  2539. const int se = 20; //entry size equip
  2540. const int sidxe = 4; //start itemlist idx
  2541. const int cmde = 0xa6;
  2542. #elif PACKETVER < 20100629
  2543. const int se = 26;
  2544. const int sidxe = 4;
  2545. const int cmde = 0x2d1;
  2546. #elif PACKETVER < 20120925
  2547. const int se = 28;
  2548. const int sidxe = 4;
  2549. const int cmde = 0x2d1;
  2550. #elif PACKETVER < 20150225
  2551. const int se = 31;
  2552. const int sidxe = 4+24;
  2553. const int cmde = 0x996;
  2554. #else
  2555. const int se = 57;
  2556. const int sidxe = 4+24;
  2557. const int cmde = 0xa10;
  2558. #endif
  2559. buf = (unsigned char*)aMalloc(items_length * s + sidx);
  2560. bufe = (unsigned char*)aMalloc(items_length * se + sidxe);
  2561. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  2562. {
  2563. if( items[i].nameid <= 0 )
  2564. continue;
  2565. id = itemdb_search(items[i].nameid);
  2566. if( !itemdb_isstackable2(id) ) { //Equippable
  2567. clif_item_sub(bufe, ne*se+sidxe,i+1, &items[i], id, id->equip);
  2568. ne++;
  2569. }
  2570. else { //Stackable
  2571. clif_item_sub(buf, n*s+sidx,i+1, &items[i], id,-1);
  2572. n++;
  2573. }
  2574. }
  2575. for (i = 0; i < n; i += nn) // Loop through non-equipable items
  2576. {
  2577. nn = n - i < (client_buf - sidx)/s ? n - i : (client_buf - sidx)/s; // Split up non-equipable items
  2578. WFIFOHEAD(sd->fd,sidx+nn*s);
  2579. WFIFOW(sd->fd,0)=cmd;
  2580. WFIFOW(sd->fd,2)=sidx+nn*s;
  2581. #if PACKETVER >= 20120925
  2582. safestrncpy(WFIFOCP(sd->fd,4), storename, NAME_LENGTH); //storename
  2583. #endif
  2584. memcpy(WFIFOP(sd->fd,sidx),buf + sidx + i*s,nn*s);
  2585. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2586. }
  2587. for (i = 0; i < ne; i += nn) // Loop through equipable items
  2588. {
  2589. nn = ne - i < (client_buf - sidxe)/se ? ne - i : (client_buf - sidxe)/se; // Split up equipable items
  2590. WFIFOHEAD(sd->fd,sidxe+nn*se);
  2591. WFIFOW(sd->fd,0)=cmde;
  2592. WFIFOW(sd->fd,2)=sidxe+nn*se;
  2593. #if PACKETVER >= 20120925
  2594. safestrncpy(WFIFOCP(sd->fd,4), storename, NAME_LENGTH); //storename
  2595. #endif
  2596. memcpy(WFIFOP(sd->fd,sidxe),bufe + sidxe + i*se,nn*se);
  2597. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2598. }
  2599. // Empty storage
  2600. if (n == 0 && ne == 0) {
  2601. WFIFOHEAD(sd->fd, 4+NAME_LENGTH);
  2602. WFIFOW(sd->fd,0) = cmd;
  2603. WFIFOW(sd->fd,2) = 4+NAME_LENGTH;
  2604. #if PACKETVER >= 20120925
  2605. safestrncpy(WFIFOCP(sd->fd,4), storename, NAME_LENGTH); //storename
  2606. #endif
  2607. WFIFOSET(sd->fd,WFIFOW(sd->fd,2));
  2608. }
  2609. if( buf ) aFree(buf);
  2610. if( bufe ) aFree(bufe);
  2611. }
  2612. void clif_cartlist(struct map_session_data *sd)
  2613. {
  2614. struct item_data *id;
  2615. int i,n,ne;
  2616. unsigned char *buf;
  2617. unsigned char *bufe;
  2618. #if PACKETVER < 5
  2619. const int s = 10; //Entry size.
  2620. #elif PACKETVER < 20080102
  2621. const int s = 18;
  2622. #elif PACKETVER < 20120925
  2623. const int s = 22;
  2624. #else
  2625. const int s = 24;
  2626. #endif
  2627. #if PACKETVER < 20071002
  2628. const int cmd = 20;
  2629. #elif PACKETVER < 20100629
  2630. const int cmd = 26;
  2631. #elif PACKETVER < 20120925
  2632. const int cmd = 28;
  2633. #elif PACKETVER < 20150225
  2634. const int cmd = 31;
  2635. #else
  2636. const int cmd = 57;
  2637. #endif
  2638. buf = (unsigned char*)aMalloc(MAX_CART * s + 4);
  2639. bufe = (unsigned char*)aMalloc(MAX_CART * cmd + 4);
  2640. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2641. {
  2642. if( sd->cart.u.items_cart[i].nameid <= 0 )
  2643. continue;
  2644. id = itemdb_search(sd->cart.u.items_cart[i].nameid);
  2645. if( !itemdb_isstackable2(id) ) { //Equippable
  2646. clif_item_sub(bufe, ne*cmd+4,i+2, &sd->cart.u.items_cart[i], id, id->equip);
  2647. ne++;
  2648. }
  2649. else { //Stackable
  2650. clif_item_sub(buf, n*s+4,i+2, &sd->cart.u.items_cart[i], id,-1);
  2651. n++;
  2652. }
  2653. }
  2654. if( n )
  2655. {
  2656. #if PACKETVER < 5
  2657. WBUFW(buf,0)=0x123;
  2658. #elif PACKETVER < 20080102
  2659. WBUFW(buf,0)=0x1ef;
  2660. #elif PACKETVER < 20120925
  2661. WBUFW(buf,0)=0x2e9;
  2662. #else
  2663. WBUFW(buf,0)=0x993;
  2664. #endif
  2665. WBUFW(buf,2)=4+n*s;
  2666. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2667. }
  2668. if( ne )
  2669. {
  2670. #if PACKETVER < 20071002
  2671. WBUFW(bufe,0)=0x122;
  2672. #elif PACKETVER < 20120925
  2673. WBUFW(bufe,0)=0x2d2;
  2674. #elif PACKETVER < 20150225
  2675. WBUFW(bufe,0)=0x994;
  2676. #else
  2677. WBUFW(bufe,0)=0xa0f;
  2678. #endif
  2679. WBUFW(bufe,2)=4+ne*cmd;
  2680. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2681. }
  2682. if( buf ) aFree(buf);
  2683. if( bufe ) aFree(bufe);
  2684. }
  2685. /// Removes cart (ZC_CARTOFF).
  2686. /// 012b
  2687. /// Client behaviour:
  2688. /// Closes the cart storage and removes all it's items from memory.
  2689. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2690. void clif_clearcart(int fd)
  2691. {
  2692. WFIFOHEAD(fd, packet_len(0x12b));
  2693. WFIFOW(fd,0) = 0x12b;
  2694. WFIFOSET(fd, packet_len(0x12b));
  2695. }
  2696. /// Guild XY locators (ZC_NOTIFY_POSITION_TO_GUILDM) [Valaris]
  2697. /// 01eb <account id>.L <x>.W <y>.W
  2698. void clif_guild_xy(struct map_session_data *sd)
  2699. {
  2700. unsigned char buf[10];
  2701. nullpo_retv(sd);
  2702. WBUFW(buf,0)=0x1eb;
  2703. WBUFL(buf,2)=sd->status.account_id;
  2704. WBUFW(buf,6)=sd->bl.x;
  2705. WBUFW(buf,8)=sd->bl.y;
  2706. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2707. }
  2708. /*==========================================
  2709. * Sends x/y dot to a single fd. [Skotlex]
  2710. *------------------------------------------*/
  2711. void clif_guild_xy_single(int fd, struct map_session_data *sd)
  2712. {
  2713. if( sd->bg_id )
  2714. return;
  2715. WFIFOHEAD(fd,packet_len(0x1eb));
  2716. WFIFOW(fd,0)=0x1eb;
  2717. WFIFOL(fd,2)=sd->status.account_id;
  2718. WFIFOW(fd,6)=sd->bl.x;
  2719. WFIFOW(fd,8)=sd->bl.y;
  2720. WFIFOSET(fd,packet_len(0x1eb));
  2721. }
  2722. // Guild XY locators [Valaris]
  2723. void clif_guild_xy_remove(struct map_session_data *sd)
  2724. {
  2725. unsigned char buf[10];
  2726. nullpo_retv(sd);
  2727. WBUFW(buf,0)=0x1eb;
  2728. WBUFL(buf,2)=sd->status.account_id;
  2729. WBUFW(buf,6)=-1;
  2730. WBUFW(buf,8)=-1;
  2731. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2732. }
  2733. /*==========================================
  2734. *
  2735. *------------------------------------------*/
  2736. static int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  2737. {
  2738. struct map_session_data *sd, *tsd;
  2739. #if PACKETVER < 20100126
  2740. const int cmd = 0x106;
  2741. #else
  2742. const int cmd = 0x80e;
  2743. #endif
  2744. sd = va_arg(ap, struct map_session_data *);
  2745. tsd = (TBL_PC *)bl;
  2746. nullpo_ret(sd);
  2747. nullpo_ret(tsd);
  2748. if( !tsd->fd || tsd == sd )
  2749. return 0;
  2750. if( !pc_has_permission(tsd, PC_PERM_VIEW_HPMETER) )
  2751. return 0;
  2752. WFIFOHEAD(tsd->fd,packet_len(cmd));
  2753. WFIFOW(tsd->fd,0) = cmd;
  2754. WFIFOL(tsd->fd,2) = sd->status.account_id;
  2755. #if PACKETVER < 20100126
  2756. if( sd->battle_status.max_hp > INT16_MAX )
  2757. { //To correctly display the %hp bar. [Skotlex]
  2758. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  2759. WFIFOW(tsd->fd,8) = 100;
  2760. } else {
  2761. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  2762. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  2763. }
  2764. #else
  2765. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  2766. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  2767. #endif
  2768. WFIFOSET(tsd->fd,packet_len(cmd));
  2769. return 0;
  2770. }
  2771. /*==========================================
  2772. * Server tells all players that are allowed to view HP bars
  2773. * and are nearby 'sd' that 'sd' hp bar was updated.
  2774. *------------------------------------------*/
  2775. static int clif_hpmeter(struct map_session_data *sd)
  2776. {
  2777. nullpo_ret(sd);
  2778. 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);
  2779. return 0;
  2780. }
  2781. /// Notifies client of a character parameter change.
  2782. /// 00b0 <var id>.W <value>.L (ZC_PAR_CHANGE)
  2783. /// 00b1 <var id>.W <value>.L (ZC_LONGPAR_CHANGE)
  2784. /// 00be <status id>.W <value>.B (ZC_STATUS_CHANGE)
  2785. /// 0121 <current count>.W <max count>.W <current weight>.L <max weight>.L (ZC_NOTIFY_CARTITEM_COUNTINFO)
  2786. /// 013a <atk range>.W (ZC_ATTACK_RANGE)
  2787. /// 0141 <status id>.L <base status>.L <plus status>.L (ZC_COUPLESTATUS)
  2788. /// 0acb <var id>.W <value>.Q (ZC_LONGPAR_CHANGE2)
  2789. /// TODO: Extract individual packets.
  2790. /// FIXME: Packet lengths from packet_len(cmd)
  2791. void clif_updatestatus(struct map_session_data *sd,int type)
  2792. {
  2793. int fd,len=8;
  2794. nullpo_retv(sd);
  2795. fd=sd->fd;
  2796. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2797. return;
  2798. WFIFOHEAD(fd, 14);
  2799. WFIFOW(fd,0)=0xb0;
  2800. WFIFOW(fd,2)=type;
  2801. switch(type){
  2802. // 00b0
  2803. case SP_WEIGHT:
  2804. pc_updateweightstatus(sd);
  2805. WFIFOHEAD(fd,14);
  2806. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2807. WFIFOW(fd,2)=type;
  2808. WFIFOL(fd,4)=sd->weight;
  2809. break;
  2810. case SP_MAXWEIGHT:
  2811. WFIFOL(fd,4)=sd->max_weight;
  2812. break;
  2813. case SP_SPEED:
  2814. WFIFOL(fd,4)=sd->battle_status.speed;
  2815. break;
  2816. case SP_BASELEVEL:
  2817. WFIFOL(fd,4)=sd->status.base_level;
  2818. break;
  2819. case SP_JOBLEVEL:
  2820. WFIFOL(fd,4)=sd->status.job_level;
  2821. break;
  2822. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2823. WFIFOL(fd,4)=sd->status.karma;
  2824. break;
  2825. case SP_MANNER:
  2826. WFIFOL(fd,4)=sd->status.manner;
  2827. break;
  2828. case SP_STATUSPOINT:
  2829. WFIFOL(fd,4)=sd->status.status_point;
  2830. break;
  2831. case SP_SKILLPOINT:
  2832. WFIFOL(fd,4)=sd->status.skill_point;
  2833. break;
  2834. case SP_HIT:
  2835. WFIFOL(fd,4)=sd->battle_status.hit;
  2836. break;
  2837. case SP_FLEE1:
  2838. WFIFOL(fd,4)=sd->battle_status.flee;
  2839. break;
  2840. case SP_FLEE2:
  2841. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2842. break;
  2843. case SP_MAXHP:
  2844. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2845. break;
  2846. case SP_MAXSP:
  2847. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2848. break;
  2849. case SP_HP:
  2850. // On officials the HP never go below 1, even if you die [Lemongrass]
  2851. // On officials the HP Novice class never go below 50%, even if you die [Napster]
  2852. WFIFOL(fd,4)= sd->battle_status.hp ? sd->battle_status.hp : (sd->class_&MAPID_UPPERMASK) != MAPID_NOVICE ? 1 : sd->battle_status.max_hp/2;
  2853. break;
  2854. case SP_SP:
  2855. WFIFOL(fd,4)=sd->battle_status.sp;
  2856. break;
  2857. case SP_ASPD:
  2858. WFIFOL(fd,4)=sd->battle_status.amotion;
  2859. break;
  2860. case SP_ATK1:
  2861. WFIFOL(fd,4)=pc_leftside_atk(sd);
  2862. break;
  2863. case SP_DEF1:
  2864. WFIFOL(fd,4)=pc_leftside_def(sd);
  2865. break;
  2866. case SP_MDEF1:
  2867. WFIFOL(fd,4)=pc_leftside_mdef(sd);
  2868. break;
  2869. case SP_ATK2:
  2870. WFIFOL(fd,4)=pc_rightside_atk(sd);
  2871. break;
  2872. case SP_DEF2:
  2873. WFIFOL(fd,4)=pc_rightside_def(sd);
  2874. break;
  2875. case SP_MDEF2: {
  2876. //negative check (in case you have something like Berserk active)
  2877. int mdef2 = pc_rightside_mdef(sd);
  2878. WFIFOL(fd,4)=
  2879. #ifndef RENEWAL
  2880. ( mdef2 < 0 ) ? 0 :
  2881. #endif
  2882. mdef2;
  2883. }
  2884. break;
  2885. case SP_CRITICAL:
  2886. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2887. break;
  2888. case SP_MATK1:
  2889. WFIFOL(fd,4)=pc_rightside_matk(sd);
  2890. break;
  2891. case SP_MATK2:
  2892. WFIFOL(fd,4)=pc_leftside_matk(sd);
  2893. break;
  2894. case SP_ZENY:
  2895. WFIFOW(fd,0)=0xb1;
  2896. WFIFOL(fd,4)=sd->status.zeny;
  2897. break;
  2898. #if PACKETVER >= 20170830
  2899. case SP_BASEEXP:
  2900. WFIFOW(fd,0)=0xacb;
  2901. WFIFOQ(fd,4)=sd->status.base_exp;
  2902. len = packet_len(0xacb);
  2903. break;
  2904. case SP_JOBEXP:
  2905. WFIFOW(fd,0)=0xacb;
  2906. WFIFOQ(fd,4)=sd->status.job_exp;
  2907. len = packet_len(0xacb);
  2908. break;
  2909. case SP_NEXTBASEEXP:
  2910. WFIFOW(fd,0)=0xacb;
  2911. WFIFOQ(fd,4)=pc_nextbaseexp(sd);
  2912. len = packet_len(0xacb);
  2913. break;
  2914. case SP_NEXTJOBEXP:
  2915. WFIFOW(fd,0)=0xacb;
  2916. WFIFOQ(fd,4)=pc_nextjobexp(sd);
  2917. len = packet_len(0xacb);
  2918. break;
  2919. #else
  2920. case SP_BASEEXP:
  2921. WFIFOW(fd,0)=0xb1;
  2922. WFIFOL(fd,4)=sd->status.base_exp;
  2923. break;
  2924. case SP_JOBEXP:
  2925. WFIFOW(fd,0)=0xb1;
  2926. WFIFOL(fd,4)=sd->status.job_exp;
  2927. break;
  2928. case SP_NEXTBASEEXP:
  2929. WFIFOW(fd,0)=0xb1;
  2930. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2931. break;
  2932. case SP_NEXTJOBEXP:
  2933. WFIFOW(fd,0)=0xb1;
  2934. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2935. break;
  2936. #endif
  2937. /**
  2938. * SP_U<STAT> are used to update the amount of points necessary to increase that stat
  2939. **/
  2940. case SP_USTR:
  2941. case SP_UAGI:
  2942. case SP_UVIT:
  2943. case SP_UINT:
  2944. case SP_UDEX:
  2945. case SP_ULUK:
  2946. WFIFOW(fd,0)=0xbe;
  2947. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR,1);
  2948. len=5;
  2949. break;
  2950. /**
  2951. * Tells the client how far it is allowed to attack (weapon range)
  2952. **/
  2953. case SP_ATTACKRANGE:
  2954. WFIFOW(fd,0)=0x13a;
  2955. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2956. len=4;
  2957. break;
  2958. case SP_STR:
  2959. WFIFOW(fd,0)=0x141;
  2960. WFIFOL(fd,2)=type;
  2961. WFIFOL(fd,6)=sd->status.str;
  2962. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2963. len=14;
  2964. break;
  2965. case SP_AGI:
  2966. WFIFOW(fd,0)=0x141;
  2967. WFIFOL(fd,2)=type;
  2968. WFIFOL(fd,6)=sd->status.agi;
  2969. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2970. len=14;
  2971. break;
  2972. case SP_VIT:
  2973. WFIFOW(fd,0)=0x141;
  2974. WFIFOL(fd,2)=type;
  2975. WFIFOL(fd,6)=sd->status.vit;
  2976. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2977. len=14;
  2978. break;
  2979. case SP_INT:
  2980. WFIFOW(fd,0)=0x141;
  2981. WFIFOL(fd,2)=type;
  2982. WFIFOL(fd,6)=sd->status.int_;
  2983. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2984. len=14;
  2985. break;
  2986. case SP_DEX:
  2987. WFIFOW(fd,0)=0x141;
  2988. WFIFOL(fd,2)=type;
  2989. WFIFOL(fd,6)=sd->status.dex;
  2990. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2991. len=14;
  2992. break;
  2993. case SP_LUK:
  2994. WFIFOW(fd,0)=0x141;
  2995. WFIFOL(fd,2)=type;
  2996. WFIFOL(fd,6)=sd->status.luk;
  2997. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2998. len=14;
  2999. break;
  3000. case SP_CARTINFO:
  3001. WFIFOW(fd,0)=0x121;
  3002. WFIFOW(fd,2)=sd->cart_num;
  3003. WFIFOW(fd,4)=MAX_CART;
  3004. WFIFOL(fd,6)=sd->cart_weight;
  3005. WFIFOL(fd,10)=sd->cart_weight_max;
  3006. len=14;
  3007. break;
  3008. default:
  3009. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  3010. return;
  3011. }
  3012. WFIFOSET(fd,len);
  3013. // Additional update packets that should be sent right after
  3014. switch( type ){
  3015. case SP_BASELEVEL:
  3016. if( sd->status.party_id ){
  3017. struct party_data* p;
  3018. int i;
  3019. if( ( p = party_search( sd->status.party_id ) ) != NULL ){
  3020. ARR_FIND(0, MAX_PARTY, i, p->party.member[i].char_id == sd->status.char_id);
  3021. if( i < MAX_PARTY ){
  3022. p->party.member[i].lv = sd->status.base_level;
  3023. clif_party_job_and_level(sd);
  3024. }
  3025. }
  3026. }
  3027. break;
  3028. case SP_HP:
  3029. if( map[sd->bl.m].hpmeter_visible ){
  3030. clif_hpmeter(sd);
  3031. }
  3032. if( !battle_config.party_hp_mode && sd->status.party_id ){
  3033. clif_party_hp(sd);
  3034. }
  3035. if( sd->bg_id ){
  3036. clif_bg_hp(sd);
  3037. }
  3038. break;
  3039. }
  3040. }
  3041. /// Notifies client of a parameter change of an another player (ZC_PAR_CHANGE_USER).
  3042. /// 01ab <account id>.L <var id>.W <value>.L
  3043. void clif_changestatus(struct map_session_data* sd,int type,int val)
  3044. {
  3045. unsigned char buf[12];
  3046. nullpo_retv(sd);
  3047. WBUFW(buf,0)=0x1ab;
  3048. WBUFL(buf,2)=sd->bl.id;
  3049. WBUFW(buf,6)=type;
  3050. switch(type)
  3051. {
  3052. case SP_MANNER:
  3053. WBUFL(buf,8)=val;
  3054. break;
  3055. default:
  3056. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  3057. return;
  3058. }
  3059. clif_send(buf,packet_len(0x1ab),&sd->bl,AREA_WOS);
  3060. }
  3061. /// 00c3 <id>.L <type>.B <value>.B (ZC_SPRITE_CHANGE)
  3062. /// 01d7 <id>.L <type>.B <value>.L (ZC_SPRITE_CHANGE2)
  3063. void clif_sprite_change(struct block_list *bl, int id, int type, int val, int val2, enum send_target target) {
  3064. unsigned char buf[32];
  3065. #if PACKETVER < 4
  3066. const int cmd = 0xc3;
  3067. #else
  3068. const int cmd = 0x1d7;
  3069. #endif
  3070. WBUFW(buf,0) = cmd;
  3071. WBUFL(buf,2) = id;
  3072. WBUFB(buf,6) = type;
  3073. WBUFW(buf,7) = val;
  3074. #if PACKETVER >= 4
  3075. WBUFW(buf,9) = val2;
  3076. #endif
  3077. clif_send(buf,packet_len(cmd), bl, target);
  3078. }
  3079. /// Updates sprite/style properties of an object.
  3080. void clif_changelook(struct block_list *bl, int type, int val) {
  3081. struct map_session_data* sd;
  3082. struct status_change* sc;
  3083. struct view_data* vd;
  3084. enum send_target target = AREA;
  3085. int val2 = 0;
  3086. nullpo_retv(bl);
  3087. sd = BL_CAST(BL_PC, bl);
  3088. sc = status_get_sc(bl);
  3089. vd = status_get_viewdata(bl);
  3090. if( vd ) //temp hack to let Warp Portal change appearance
  3091. switch(type) {
  3092. case LOOK_WEAPON:
  3093. if (sd) {
  3094. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3095. val = vd->weapon;
  3096. }
  3097. else
  3098. vd->weapon = val;
  3099. break;
  3100. case LOOK_SHIELD:
  3101. if (sd) {
  3102. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  3103. val = vd->shield;
  3104. }
  3105. else
  3106. vd->shield = val;
  3107. break;
  3108. case LOOK_BASE:
  3109. if (!sd)
  3110. break;
  3111. if ( val == JT_INVISIBLE )
  3112. return;
  3113. if (sd->sc.option&OPTION_COSTUME)
  3114. vd->weapon = vd->shield = 0;
  3115. if (!vd->cloth_color)
  3116. break;
  3117. if (sd) {
  3118. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3119. vd->cloth_color = 0;
  3120. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3121. vd->cloth_color = 0;
  3122. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  3123. vd->cloth_color = 0;
  3124. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3125. vd->cloth_color = 0;
  3126. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3127. vd->cloth_color = 0;
  3128. if (vd->body_style && (
  3129. sd->sc.option&OPTION_WEDDING || sd->sc.option&OPTION_XMAS ||
  3130. sd->sc.option&OPTION_SUMMER || sd->sc.option&OPTION_HANBOK ||
  3131. sd->sc.option&OPTION_OKTOBERFEST))
  3132. vd->body_style = 0;
  3133. }
  3134. break;
  3135. case LOOK_HAIR:
  3136. vd->hair_style = val;
  3137. break;
  3138. case LOOK_HEAD_BOTTOM:
  3139. vd->head_bottom = val;
  3140. break;
  3141. case LOOK_HEAD_TOP:
  3142. vd->head_top = val;
  3143. break;
  3144. case LOOK_HEAD_MID:
  3145. vd->head_mid = val;
  3146. break;
  3147. case LOOK_HAIR_COLOR:
  3148. vd->hair_color = val;
  3149. break;
  3150. case LOOK_CLOTHES_COLOR:
  3151. if (val && sd) {
  3152. if (sd->sc.option&OPTION_WEDDING && battle_config.wedding_ignorepalette)
  3153. val = 0;
  3154. if (sd->sc.option&OPTION_XMAS && battle_config.xmas_ignorepalette)
  3155. val = 0;
  3156. if (sd->sc.option&OPTION_SUMMER && battle_config.summer_ignorepalette)
  3157. val = 0;
  3158. if (sd->sc.option&OPTION_HANBOK && battle_config.hanbok_ignorepalette)
  3159. val = 0;
  3160. if (sd->sc.option&OPTION_OKTOBERFEST && battle_config.oktoberfest_ignorepalette)
  3161. val = 0;
  3162. }
  3163. vd->cloth_color = val;
  3164. break;
  3165. case LOOK_SHOES:
  3166. #if PACKETVER > 3
  3167. if (sd) {
  3168. int n;
  3169. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  3170. if(sd->inventory_data[n]->view_id > 0)
  3171. val = sd->inventory_data[n]->view_id;
  3172. else
  3173. val = sd->inventory.u.items_inventory[n].nameid;
  3174. } else
  3175. val = 0;
  3176. }
  3177. #endif
  3178. //Shoes? No packet uses this....
  3179. break;
  3180. case LOOK_BODY:
  3181. // unknown purpose
  3182. break;
  3183. case LOOK_ROBE:
  3184. #if PACKETVER < 20110111
  3185. return;
  3186. #else
  3187. vd->robe = val;
  3188. #endif
  3189. break;
  3190. case LOOK_BODY2:
  3191. #if PACKETVER < 20150513
  3192. return;
  3193. #else
  3194. if (val && (
  3195. sd->sc.option&OPTION_WEDDING || sd->sc.option&OPTION_XMAS ||
  3196. sd->sc.option&OPTION_SUMMER || sd->sc.option&OPTION_HANBOK ||
  3197. sd->sc.option&OPTION_OKTOBERFEST))
  3198. val = 0;
  3199. vd->body_style = val;
  3200. #endif
  3201. break;
  3202. }
  3203. // prevent leaking the presence of GM-hidden objects
  3204. if( sc && sc->option&OPTION_INVISIBLE )
  3205. target = SELF;
  3206. #if PACKETVER < 4
  3207. clif_sprite_change(bl, bl->id, type, val, 0, target);
  3208. #else
  3209. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  3210. nullpo_retv(vd);
  3211. type = LOOK_WEAPON;
  3212. val = vd->weapon;
  3213. val2 = vd->shield;
  3214. }
  3215. if( disguised(bl) ) {
  3216. clif_sprite_change(bl, bl->id, type, val, val2, AREA_WOS);
  3217. clif_sprite_change(bl, -bl->id, type, val, val2, SELF);
  3218. } else
  3219. clif_sprite_change(bl, bl->id, type, val, val2, target);
  3220. #endif
  3221. }
  3222. //Sends a change-base-look packet required for traps as they are triggered.
  3223. void clif_changetraplook(struct block_list *bl,int val) {
  3224. clif_sprite_change(bl, bl->id, LOOK_BASE, val, 0, AREA);
  3225. }
  3226. /// For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  3227. void clif_refreshlook(struct block_list *bl, int id, int type, int val, enum send_target target) {
  3228. clif_sprite_change(bl, id, type, val, 0, target);
  3229. }
  3230. /// Character status (ZC_STATUS).
  3231. /// 00bd <stpoint>.W <str>.B <need str>.B <agi>.B <need agi>.B <vit>.B <need vit>.B
  3232. /// <int>.B <need int>.B <dex>.B <need dex>.B <luk>.B <need luk>.B <atk>.W <atk2>.W
  3233. /// <matk min>.W <matk max>.W <def>.W <def2>.W <mdef>.W <mdef2>.W <hit>.W
  3234. /// <flee>.W <flee2>.W <crit>.W <aspd>.W <aspd2>.W
  3235. void clif_initialstatus(struct map_session_data *sd) {
  3236. int fd, mdef2;
  3237. unsigned char *buf;
  3238. nullpo_retv(sd);
  3239. fd=sd->fd;
  3240. WFIFOHEAD(fd, packet_len(0xbd));
  3241. buf = WFIFOP(fd,0);
  3242. WBUFW(buf,0) = 0xbd;
  3243. WBUFW(buf,2) = min(sd->status.status_point, INT16_MAX);
  3244. WBUFB(buf,4) = min(sd->status.str, UINT8_MAX);
  3245. WBUFB(buf,5) = pc_need_status_point(sd,SP_STR,1);
  3246. WBUFB(buf,6) = min(sd->status.agi, UINT8_MAX);
  3247. WBUFB(buf,7) = pc_need_status_point(sd,SP_AGI,1);
  3248. WBUFB(buf,8) = min(sd->status.vit, UINT8_MAX);
  3249. WBUFB(buf,9) = pc_need_status_point(sd,SP_VIT,1);
  3250. WBUFB(buf,10) = min(sd->status.int_, UINT8_MAX);
  3251. WBUFB(buf,11) = pc_need_status_point(sd,SP_INT,1);
  3252. WBUFB(buf,12) = min(sd->status.dex, UINT8_MAX);
  3253. WBUFB(buf,13) = pc_need_status_point(sd,SP_DEX,1);
  3254. WBUFB(buf,14) = min(sd->status.luk, UINT8_MAX);
  3255. WBUFB(buf,15) = pc_need_status_point(sd,SP_LUK,1);
  3256. WBUFW(buf,16) = pc_leftside_atk(sd);
  3257. WBUFW(buf,18) = pc_rightside_atk(sd);
  3258. WBUFW(buf,20) = pc_rightside_matk(sd);
  3259. WBUFW(buf,22) = pc_leftside_matk(sd);
  3260. WBUFW(buf,24) = pc_leftside_def(sd);
  3261. WBUFW(buf,26) = pc_rightside_def(sd);
  3262. WBUFW(buf,28) = pc_leftside_mdef(sd);
  3263. mdef2 = pc_rightside_mdef(sd);
  3264. WBUFW(buf,30) =
  3265. #ifndef RENEWAL
  3266. ( mdef2 < 0 ) ? 0 : //Negative check for Frenzy'ed characters.
  3267. #endif
  3268. mdef2;
  3269. WBUFW(buf,32) = sd->battle_status.hit;
  3270. WBUFW(buf,34) = sd->battle_status.flee;
  3271. WBUFW(buf,36) = sd->battle_status.flee2/10;
  3272. WBUFW(buf,38) = sd->battle_status.cri/10;
  3273. WBUFW(buf,40) = sd->battle_status.amotion; // aspd
  3274. WBUFW(buf,42) = 0; // always 0 (plusASPD)
  3275. WFIFOSET(fd, packet_len(0xbd));
  3276. clif_updatestatus(sd, SP_STR);
  3277. clif_updatestatus(sd, SP_AGI);
  3278. clif_updatestatus(sd, SP_VIT);
  3279. clif_updatestatus(sd, SP_INT);
  3280. clif_updatestatus(sd, SP_DEX);
  3281. clif_updatestatus(sd, SP_LUK);
  3282. clif_updatestatus(sd, SP_ATTACKRANGE);
  3283. clif_updatestatus(sd, SP_ASPD);
  3284. }
  3285. /// Marks an ammunition item in inventory as equipped (ZC_EQUIP_ARROW).
  3286. /// 013c <index>.W
  3287. void clif_arrowequip(struct map_session_data *sd,int val) {
  3288. int fd;
  3289. nullpo_retv(sd);
  3290. #if PACKETVER >= 20121128
  3291. clif_status_change(&sd->bl, EFST_CLIENT_ONLY_EQUIP_ARROW, 1, INVALID_TIMER, 0, 0, 0);
  3292. #endif
  3293. fd=sd->fd;
  3294. WFIFOHEAD(fd, packet_len(0x013c));
  3295. WFIFOW(fd,0) = 0x013c;
  3296. WFIFOW(fd,2) = val + 2; //Item ID of the arrow
  3297. WFIFOSET(fd, packet_len(0x013c));
  3298. }
  3299. /// Ammunition action message (ZC_ACTION_FAILURE).
  3300. /// 013b <type>.W
  3301. /// type:
  3302. /// 0 = MsgStringTable[242]="Please equip the proper ammunition first."
  3303. /// 1 = MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  3304. /// 2 = MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  3305. /// 3 = assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  3306. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  3307. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  3308. void clif_arrow_fail(struct map_session_data *sd,int type) {
  3309. int fd;
  3310. nullpo_retv(sd);
  3311. fd=sd->fd;
  3312. WFIFOHEAD(fd, packet_len(0x013b));
  3313. WFIFOW(fd,0) = 0x013b;
  3314. WFIFOW(fd,2) = type;
  3315. WFIFOSET(fd, packet_len(0x013b));
  3316. }
  3317. /// Presents a list of items, that can be processed by Arrow Crafting (ZC_MAKINGARROW_LIST).
  3318. /// 01ad <packet len>.W { <name id>.W }*
  3319. void clif_arrow_create_list(struct map_session_data *sd)
  3320. {
  3321. int i, c;
  3322. int fd;
  3323. nullpo_retv(sd);
  3324. fd = sd->fd;
  3325. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  3326. WFIFOW(fd,0) = 0x1ad;
  3327. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  3328. short j, nameid = skill_arrow_db[i].nameid;
  3329. if (nameid > 0 && itemdb_exists(nameid) &&
  3330. (j = pc_search_inventory(sd, nameid)) >= 0 &&
  3331. !sd->inventory.u.items_inventory[j].equip && sd->inventory.u.items_inventory[j].identify)
  3332. {
  3333. if ((j = itemdb_viewid(nameid)) > 0)
  3334. WFIFOW(fd,c*2+4) = j;
  3335. else
  3336. WFIFOW(fd,c*2+4) = nameid;
  3337. c++;
  3338. }
  3339. }
  3340. WFIFOW(fd,2) = c*2+4;
  3341. WFIFOSET(fd, WFIFOW(fd,2));
  3342. if (c > 0) {
  3343. sd->menuskill_id = AC_MAKINGARROW;
  3344. sd->menuskill_val = c;
  3345. }
  3346. }
  3347. /// Notifies the client, about the result of an status change request (ZC_STATUS_CHANGE_ACK).
  3348. /// 00bc <status id>.W <result>.B <value>.B
  3349. /// status id:
  3350. /// SP_STR ~ SP_LUK
  3351. /// result:
  3352. /// 0 = failure
  3353. /// 1 = success
  3354. void clif_statusupack(struct map_session_data *sd,int type,int ok,int val) {
  3355. int fd;
  3356. nullpo_retv(sd);
  3357. fd=sd->fd;
  3358. WFIFOHEAD(fd, packet_len(0xbc));
  3359. WFIFOW(fd,0) = 0xbc;
  3360. WFIFOW(fd,2) = type;
  3361. WFIFOB(fd,4) = ok;
  3362. WFIFOB(fd,5) = cap_value(val, 0, UINT8_MAX);
  3363. WFIFOSET(fd, packet_len(0xbc));
  3364. }
  3365. /// Notifies the client about the result of a request to equip an item.
  3366. /// 00aa <index>.W <equip location>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK)
  3367. /// 00aa <index>.W <equip location>.W <view id>.W <result>.B (PACKETVER >= 20100629)
  3368. /// 08d0 <index>.W <equip location>.W <view id>.W <result>.B (ZC_REQ_WEAR_EQUIP_ACK2)
  3369. /// 0999 <index>.W <equip location>.L <view id>.W <result>.B (ZC_ACK_WEAR_EQUIP_V5)
  3370. /// @ok: //inversed forv2 v5
  3371. /// 0 = failure
  3372. /// 1 = success
  3373. /// 2 = failure due to low level
  3374. void clif_equipitemack(struct map_session_data *sd,int n,int pos,uint8 flag)
  3375. {
  3376. int fd = 0, cmd = 0, look = 0;
  3377. struct s_packet_db *info = NULL;
  3378. nullpo_retv(sd);
  3379. cmd = packet_db_ack[ZC_WEAR_EQUIP_ACK];
  3380. if (!cmd || !(info = &packet_db[cmd]) || !info->len)
  3381. return;
  3382. fd = sd->fd;
  3383. if (flag == ITEM_EQUIP_ACK_OK && sd->inventory_data[n]->equip&EQP_VISIBLE)
  3384. look = sd->inventory_data[n]->look;
  3385. WFIFOHEAD(fd, info->len);
  3386. WFIFOW(fd, 0) = cmd;
  3387. WFIFOW(fd, info->pos[0]) = n+2;
  3388. switch (cmd) {
  3389. case 0xaa:
  3390. WFIFOW(fd, info->pos[1]) = pos;
  3391. #if PACKETVER < 20100629
  3392. WFIFOW(fd, info->pos[2]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3393. #else
  3394. WFIFOL(fd, info->pos[2]) = look;
  3395. WFIFOW(fd, info->pos[3]) = (flag == ITEM_EQUIP_ACK_OK ? 1 : 0);
  3396. #endif
  3397. break;
  3398. case 0x8d0:
  3399. if (flag == ITEM_EQUIP_ACK_FAILLEVEL)
  3400. flag = 1;
  3401. case 0x999:
  3402. if (cmd == 0x999)
  3403. WFIFOL(fd, info->pos[1]) = pos;
  3404. else
  3405. WFIFOW(fd, info->pos[1]) = pos;
  3406. WFIFOL(fd, info->pos[2]) = look;
  3407. WFIFOW(fd, info->pos[3]) = flag;
  3408. break;
  3409. }
  3410. WFIFOSET(fd, info->len);
  3411. }
  3412. /// Notifies the client about the result of a request to take off an item.
  3413. /// 00ac <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK)
  3414. /// 08d1 <index>.W <equip location>.W <result>.B (ZC_REQ_TAKEOFF_EQUIP_ACK2)
  3415. /// 099a <index>.W <equip location>.L <result>.B (ZC_ACK_TAKEOFF_EQUIP_V5)
  3416. /// @ok : //inversed for v2 v5
  3417. /// 0 = failure
  3418. /// 1 = success
  3419. void clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  3420. {
  3421. int fd, header, offs = 0;
  3422. #if PACKETVER >= 20130000
  3423. header = 0x99a;
  3424. ok = ok ? 0 : 1;
  3425. #elif PACKETVER >= 20110824
  3426. header = 0x8d1;
  3427. ok = ok ? 0 : 1;
  3428. #else
  3429. header = 0xac;
  3430. #endif
  3431. nullpo_retv(sd);
  3432. fd=sd->fd;
  3433. WFIFOHEAD(fd, packet_len(header));
  3434. WFIFOW(fd,offs+0) = header;
  3435. WFIFOW(fd,offs+2) = n+2;
  3436. #if PACKETVER >= 20130000
  3437. WFIFOL(fd,offs+4) = pos;
  3438. offs += 2;
  3439. #else
  3440. WFIFOW(fd,offs+4) = pos;
  3441. #endif
  3442. WFIFOB(fd,offs+6) = ok;
  3443. WFIFOSET(fd, packet_len(header));
  3444. }
  3445. /// Notifies clients in the area about an special/visual effect (ZC_NOTIFY_EFFECT).
  3446. /// 019b <id>.L <effect id>.L
  3447. /// effect id:
  3448. /// 0 = base level up
  3449. /// 1 = job level up
  3450. /// 2 = refine failure
  3451. /// 3 = refine success
  3452. /// 4 = game over
  3453. /// 5 = pharmacy success
  3454. /// 6 = pharmacy failure
  3455. /// 7 = base level up (super novice)
  3456. /// 8 = job level up (super novice)
  3457. /// 9 = base level up (taekwon)
  3458. void clif_misceffect(struct block_list* bl,int type)
  3459. {
  3460. unsigned char buf[32];
  3461. nullpo_retv(bl);
  3462. WBUFW(buf,0) = 0x19b;
  3463. WBUFL(buf,2) = bl->id;
  3464. WBUFL(buf,6) = type;
  3465. clif_send(buf,packet_len(0x19b),bl,AREA);
  3466. }
  3467. /// Notifies clients in the area of a state change.
  3468. /// 0119 <id>.L <body state>.W <health state>.W <effect state>.W <pk mode>.B (ZC_STATE_CHANGE)
  3469. /// 0229 <id>.L <body state>.W <health state>.W <effect state>.L <pk mode>.B (ZC_STATE_CHANGE3)
  3470. void clif_changeoption(struct block_list* bl)
  3471. {
  3472. unsigned char buf[32];
  3473. struct status_change *sc;
  3474. struct map_session_data* sd;
  3475. nullpo_retv(bl);
  3476. sc = status_get_sc(bl);
  3477. if (!sc) return; //How can an option change if there's no sc?
  3478. sd = BL_CAST(BL_PC, bl);
  3479. #if PACKETVER >= 7
  3480. WBUFW(buf,0) = 0x229;
  3481. WBUFL(buf,2) = bl->id;
  3482. WBUFW(buf,6) = sc->opt1;
  3483. WBUFW(buf,8) = sc->opt2;
  3484. WBUFL(buf,10) = sc->option;
  3485. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  3486. if(disguised(bl)) {
  3487. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  3488. WBUFL(buf,2) = -bl->id;
  3489. clif_send(buf,packet_len(0x229),bl,SELF);
  3490. WBUFL(buf,2) = bl->id;
  3491. WBUFL(buf,10) = OPTION_INVISIBLE;
  3492. clif_send(buf,packet_len(0x229),bl,SELF);
  3493. } else
  3494. clif_send(buf,packet_len(0x229),bl,AREA);
  3495. #else
  3496. WBUFW(buf,0) = 0x119;
  3497. WBUFL(buf,2) = bl->id;
  3498. WBUFW(buf,6) = sc->opt1;
  3499. WBUFW(buf,8) = sc->opt2;
  3500. WBUFW(buf,10) = sc->option;
  3501. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  3502. if(disguised(bl)) {
  3503. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  3504. WBUFL(buf,2) = -bl->id;
  3505. clif_send(buf,packet_len(0x119),bl,SELF);
  3506. WBUFL(buf,2) = bl->id;
  3507. WBUFW(buf,10) = OPTION_INVISIBLE;
  3508. clif_send(buf,packet_len(0x119),bl,SELF);
  3509. } else
  3510. clif_send(buf,packet_len(0x119),bl,AREA);
  3511. #endif
  3512. //Whenever we send "changeoption" to the client, the provoke icon is lost
  3513. //There is probably an option for the provoke icon, but as we don't know it, we have to do this for now
  3514. if (sc->data[SC_PROVOKE] && sc->data[SC_PROVOKE]->timer == INVALID_TIMER)
  3515. clif_status_change(bl, StatusIconChangeTable[SC_PROVOKE], 1, -1, 0, 0, 0);
  3516. }
  3517. /// Displays status change effects on NPCs/monsters (ZC_NPC_SHOWEFST_UPDATE).
  3518. /// 028a <id>.L <effect state>.L <level>.L <showEFST>.L
  3519. void clif_changeoption2(struct block_list* bl)
  3520. {
  3521. unsigned char buf[20];
  3522. struct status_change *sc;
  3523. sc = status_get_sc(bl);
  3524. if (!sc) return; //How can an option change if there's no sc?
  3525. WBUFW(buf,0) = 0x28a;
  3526. WBUFL(buf,2) = bl->id;
  3527. WBUFL(buf,6) = sc->option;
  3528. WBUFL(buf,10) = clif_setlevel(bl);
  3529. WBUFL(buf,14) = sc->opt3;
  3530. if(disguised(bl)) {
  3531. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  3532. WBUFL(buf,2) = -bl->id;
  3533. clif_send(buf,packet_len(0x28a),bl,SELF);
  3534. WBUFL(buf,2) = bl->id;
  3535. WBUFL(buf,6) = OPTION_INVISIBLE;
  3536. clif_send(buf,packet_len(0x28a),bl,SELF);
  3537. } else
  3538. clif_send(buf,packet_len(0x28a),bl,AREA);
  3539. }
  3540. /// Notifies the client about the result of an item use request.
  3541. /// 00a8 <index>.W <amount>.W <result>.B (ZC_USE_ITEM_ACK)
  3542. /// 01c8 <index>.W <name id>.W <id>.L <amount>.W <result>.B (ZC_USE_ITEM_ACK2)
  3543. void clif_useitemack(struct map_session_data *sd,int index,int amount,bool ok)
  3544. {
  3545. nullpo_retv(sd);
  3546. if(!ok) {
  3547. int fd=sd->fd;
  3548. WFIFOHEAD(fd,packet_len(0xa8));
  3549. WFIFOW(fd,0)=0xa8;
  3550. WFIFOW(fd,2)=index+2;
  3551. WFIFOW(fd,4)=amount;
  3552. WFIFOB(fd,6)=ok;
  3553. WFIFOSET(fd,packet_len(0xa8));
  3554. }
  3555. else {
  3556. #if PACKETVER < 3
  3557. int fd=sd->fd;
  3558. WFIFOHEAD(fd,packet_len(0xa8));
  3559. WFIFOW(fd,0)=0xa8;
  3560. WFIFOW(fd,2)=index+2;
  3561. WFIFOW(fd,4)=amount;
  3562. WFIFOB(fd,6)=ok;
  3563. WFIFOSET(fd,packet_len(0xa8));
  3564. #else
  3565. unsigned char buf[32];
  3566. WBUFW(buf,0)=0x1c8;
  3567. WBUFW(buf,2)=index+2;
  3568. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3569. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  3570. else
  3571. WBUFW(buf,4)=sd->inventory.u.items_inventory[index].nameid;
  3572. WBUFL(buf,6)=sd->bl.id;
  3573. WBUFW(buf,10)=amount;
  3574. WBUFB(buf,12)=ok;
  3575. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  3576. #endif
  3577. }
  3578. }
  3579. /// Inform client whether chatroom creation was successful or not (ZC_ACK_CREATE_CHATROOM).
  3580. /// 00d6 <flag>.B
  3581. /// flag:
  3582. /// 0 = Room has been successfully created (opens chat room)
  3583. /// 1 = Room limit exceeded
  3584. /// 2 = Same room already exists
  3585. void clif_createchat(struct map_session_data* sd, int flag)
  3586. {
  3587. int fd;
  3588. nullpo_retv(sd);
  3589. fd = sd->fd;
  3590. WFIFOHEAD(fd,packet_len(0xd6));
  3591. WFIFOW(fd,0) = 0xd6;
  3592. WFIFOB(fd,2) = flag;
  3593. WFIFOSET(fd,packet_len(0xd6));
  3594. }
  3595. /// Display a chat above the owner (ZC_ROOM_NEWENTRY).
  3596. /// 00d7 <packet len>.W <owner id>.L <char id>.L <limit>.W <users>.W <type>.B <title>.?B
  3597. /// type:
  3598. /// 0 = private (password protected)
  3599. /// 1 = public
  3600. /// 2 = arena (npc waiting room)
  3601. /// 3 = PK zone (non-clickable)
  3602. void clif_dispchat(struct chat_data* cd, int fd)
  3603. {
  3604. unsigned char buf[128];
  3605. uint8 type;
  3606. if( cd == NULL || cd->owner == NULL )
  3607. return;
  3608. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3609. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3610. : 1;
  3611. WBUFW(buf, 0) = 0xd7;
  3612. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3613. WBUFL(buf, 4) = cd->owner->id;
  3614. WBUFL(buf, 8) = cd->bl.id;
  3615. WBUFW(buf,12) = cd->limit;
  3616. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3617. WBUFB(buf,16) = type;
  3618. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3619. if( fd ) {
  3620. WFIFOHEAD(fd,WBUFW(buf,2));
  3621. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  3622. WFIFOSET(fd,WBUFW(buf,2));
  3623. } else {
  3624. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  3625. }
  3626. }
  3627. /// Chatroom properties adjustment (ZC_CHANGE_CHATROOM).
  3628. /// 00df <packet len>.W <owner id>.L <chat id>.L <limit>.W <users>.W <type>.B <title>.?B
  3629. /// type:
  3630. /// 0 = private (password protected)
  3631. /// 1 = public
  3632. /// 2 = arena (npc waiting room)
  3633. /// 3 = PK zone (non-clickable)
  3634. void clif_changechatstatus(struct chat_data* cd)
  3635. {
  3636. unsigned char buf[128];
  3637. uint8 type;
  3638. if( cd == NULL || cd->usersd[0] == NULL )
  3639. return;
  3640. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  3641. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  3642. : 1;
  3643. WBUFW(buf, 0) = 0xdf;
  3644. WBUFW(buf, 2) = (uint16)(17 + strlen(cd->title));
  3645. WBUFL(buf, 4) = cd->owner->id;
  3646. WBUFL(buf, 8) = cd->bl.id;
  3647. WBUFW(buf,12) = cd->limit;
  3648. WBUFW(buf,14) = (cd->owner->type == BL_NPC) ? cd->users+1 : cd->users;
  3649. WBUFB(buf,16) = type;
  3650. memcpy(WBUFCP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  3651. clif_send(buf,WBUFW(buf,2),cd->owner,CHAT);
  3652. }
  3653. /// Removes the chatroom (ZC_DESTROY_ROOM).
  3654. /// 00d8 <chat id>.L
  3655. void clif_clearchat(struct chat_data *cd,int fd)
  3656. {
  3657. unsigned char buf[32];
  3658. nullpo_retv(cd);
  3659. WBUFW(buf,0) = 0xd8;
  3660. WBUFL(buf,2) = cd->bl.id;
  3661. if( fd ) {
  3662. WFIFOHEAD(fd,packet_len(0xd8));
  3663. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  3664. WFIFOSET(fd,packet_len(0xd8));
  3665. } else {
  3666. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  3667. }
  3668. }
  3669. /// Displays messages regarding join chat failures (ZC_REFUSE_ENTER_ROOM).
  3670. /// 00da <result>.B
  3671. /// result:
  3672. /// 0 = room full
  3673. /// 1 = wrong password
  3674. /// 2 = kicked
  3675. /// 3 = success (no message)
  3676. /// 4 = no enough zeny
  3677. /// 5 = too low level
  3678. /// 6 = too high level
  3679. /// 7 = unsuitable job class
  3680. void clif_joinchatfail(struct map_session_data *sd,int flag)
  3681. {
  3682. int fd;
  3683. nullpo_retv(sd);
  3684. fd = sd->fd;
  3685. WFIFOHEAD(fd,packet_len(0xda));
  3686. WFIFOW(fd,0) = 0xda;
  3687. WFIFOB(fd,2) = flag;
  3688. WFIFOSET(fd,packet_len(0xda));
  3689. }
  3690. /// Notifies the client about entering a chatroom (ZC_ENTER_ROOM).
  3691. /// 00db <packet len>.W <chat id>.L { <role>.L <name>.24B }*
  3692. /// role:
  3693. /// 0 = owner (menu)
  3694. /// 1 = normal
  3695. void clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  3696. {
  3697. int fd;
  3698. int i,t;
  3699. nullpo_retv(sd);
  3700. nullpo_retv(cd);
  3701. fd = sd->fd;
  3702. if (!session_isActive(fd))
  3703. return;
  3704. t = (int)(cd->owner->type == BL_NPC);
  3705. WFIFOHEAD(fd, 8 + (28*(cd->users+t)));
  3706. WFIFOW(fd, 0) = 0xdb;
  3707. WFIFOW(fd, 2) = 8 + (28*(cd->users+t));
  3708. WFIFOL(fd, 4) = cd->bl.id;
  3709. if(cd->owner->type == BL_NPC){
  3710. WFIFOL(fd, 30) = 1;
  3711. WFIFOL(fd, 8) = 0;
  3712. safestrncpy(WFIFOCP(fd, 12), ((struct npc_data *)cd->owner)->name, NAME_LENGTH);
  3713. for (i = 0; i < cd->users; i++) {
  3714. WFIFOL(fd, 8+(i+1)*28) = 1;
  3715. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3716. }
  3717. }else{
  3718. for (i = 0; i < cd->users; i++) {
  3719. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  3720. safestrncpy(WFIFOCP(fd, 8+(i+t)*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  3721. }
  3722. }
  3723. WFIFOSET(fd, WFIFOW(fd, 2));
  3724. }
  3725. /// Notifies clients in a chat about a new member (ZC_MEMBER_NEWENTRY).
  3726. /// 00dc <users>.W <name>.24B
  3727. void clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  3728. {
  3729. unsigned char buf[29];
  3730. nullpo_retv(sd);
  3731. nullpo_retv(cd);
  3732. WBUFW(buf, 0) = 0xdc;
  3733. WBUFW(buf, 2) = cd->users;
  3734. safestrncpy(WBUFCP(buf, 4),sd->status.name,NAME_LENGTH);
  3735. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  3736. }
  3737. /// Announce the new owner (ZC_ROLE_CHANGE).
  3738. /// 00e1 <role>.L <nick>.24B
  3739. /// role:
  3740. /// 0 = owner (menu)
  3741. /// 1 = normal
  3742. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  3743. {
  3744. unsigned char buf[64];
  3745. nullpo_retv(sd);
  3746. nullpo_retv(cd);
  3747. WBUFW(buf, 0) = 0xe1;
  3748. WBUFL(buf, 2) = 1;
  3749. safestrncpy(WBUFCP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  3750. WBUFW(buf,30) = 0xe1;
  3751. WBUFL(buf,32) = 0;
  3752. safestrncpy(WBUFCP(buf,36),sd->status.name,NAME_LENGTH);
  3753. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  3754. }
  3755. /// Notify about user leaving the chatroom (ZC_MEMBER_EXIT).
  3756. /// 00dd <users>.W <nick>.24B <flag>.B
  3757. /// flag:
  3758. /// 0 = left
  3759. /// 1 = kicked
  3760. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  3761. {
  3762. unsigned char buf[32];
  3763. nullpo_retv(sd);
  3764. nullpo_retv(cd);
  3765. WBUFW(buf, 0) = 0xdd;
  3766. WBUFW(buf, 2) = cd->users-1;
  3767. safestrncpy(WBUFCP(buf,4),sd->status.name,NAME_LENGTH);
  3768. WBUFB(buf,28) = flag;
  3769. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  3770. }
  3771. /// Opens a trade request window from char 'name'.
  3772. /// 00e5 <nick>.24B (ZC_REQ_EXCHANGE_ITEM)
  3773. /// 01f4 <nick>.24B <charid>.L <baselvl>.W (ZC_REQ_EXCHANGE_ITEM2)
  3774. void clif_traderequest(struct map_session_data* sd, const char* name)
  3775. {
  3776. int fd = sd->fd;
  3777. #if PACKETVER < 6
  3778. WFIFOHEAD(fd,packet_len(0xe5));
  3779. WFIFOW(fd,0) = 0xe5;
  3780. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3781. WFIFOSET(fd,packet_len(0xe5));
  3782. #else
  3783. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3784. if( !tsd ) return;
  3785. WFIFOHEAD(fd,packet_len(0x1f4));
  3786. WFIFOW(fd,0) = 0x1f4;
  3787. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  3788. WFIFOL(fd,26) = tsd->status.char_id;
  3789. WFIFOW(fd,30) = tsd->status.base_level;
  3790. WFIFOSET(fd,packet_len(0x1f4));
  3791. #endif
  3792. }
  3793. /// Reply to a trade-request.
  3794. /// 00e7 <result>.B (ZC_ACK_EXCHANGE_ITEM)
  3795. /// 01f5 <result>.B <charid>.L <baselvl>.W (ZC_ACK_EXCHANGE_ITEM2)
  3796. /// result:
  3797. /// 0 = Char is too far
  3798. /// 1 = Character does not exist
  3799. /// 2 = Trade failed
  3800. /// 3 = Accept
  3801. /// 4 = Cancel
  3802. /// 5 = Busy
  3803. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3804. {
  3805. int fd = sd->fd;
  3806. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3807. if( PACKETVER < 6 || !tsd ) {
  3808. WFIFOHEAD(fd,packet_len(0xe7));
  3809. WFIFOW(fd,0) = 0xe7;
  3810. WFIFOB(fd,2) = type;
  3811. WFIFOSET(fd,packet_len(0xe7));
  3812. } else {
  3813. WFIFOHEAD(fd,packet_len(0x1f5));
  3814. WFIFOW(fd,0) = 0x1f5;
  3815. WFIFOB(fd,2) = type;
  3816. WFIFOL(fd,3) = tsd->status.char_id;
  3817. WFIFOW(fd,7) = tsd->status.base_level;
  3818. WFIFOSET(fd,packet_len(0x1f5));
  3819. }
  3820. }
  3821. /// Notifies the client about an item from other player in current trade.
  3822. /// 00e9 <amount>.L <nameid>.W <identified>.B <damaged>.B <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W (ZC_ADD_EXCHANGE_ITEM)
  3823. /// 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)
  3824. /// 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)
  3825. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3826. {
  3827. int fd;
  3828. unsigned char *buf;
  3829. #if PACKETVER < 20100223
  3830. const int cmd = 0xe9;
  3831. #elif PACKETVER < 20150225
  3832. const int cmd = 0x80f;
  3833. #else
  3834. const int cmd = 0xa09;
  3835. #endif
  3836. nullpo_retv(sd);
  3837. nullpo_retv(tsd);
  3838. fd = tsd->fd;
  3839. buf = WFIFOP(fd,0);
  3840. WFIFOHEAD(fd,packet_len(cmd));
  3841. WBUFW(buf,0) = cmd;
  3842. if( index == 0 )
  3843. {
  3844. #if PACKETVER < 20100223
  3845. WBUFL(buf,2) = amount; //amount
  3846. WBUFW(buf,6) = 0; // type id
  3847. #else
  3848. WBUFW(buf,2) = 0; // type id
  3849. WBUFB(buf,4) = 0; // item type
  3850. WBUFL(buf,5) = amount; // amount
  3851. buf = WBUFP(buf,1); //Advance 1B
  3852. #endif
  3853. WBUFB(buf,8) = 0; //identify flag
  3854. WBUFB(buf,9) = 0; // attribute
  3855. WBUFB(buf,10)= 0; //refine
  3856. WBUFW(buf,11)= 0; //card (4w)
  3857. WBUFW(buf,13)= 0; //card (4w)
  3858. WBUFW(buf,15)= 0; //card (4w)
  3859. WBUFW(buf,17)= 0; //card (4w)
  3860. #if PACKETVER >= 20150225
  3861. clif_add_random_options(WBUFP(buf, 19), &sd->inventory.u.items_inventory[index]);
  3862. #endif
  3863. }
  3864. else
  3865. {
  3866. index -= 2; //index fix
  3867. #if PACKETVER < 20100223
  3868. WBUFL(buf,2) = amount; //amount
  3869. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3870. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3871. else
  3872. WBUFW(buf,6) = sd->inventory.u.items_inventory[index].nameid; // type id
  3873. #else
  3874. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3875. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3876. else
  3877. WBUFW(buf,2) = sd->inventory.u.items_inventory[index].nameid; // type id
  3878. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3879. WBUFL(buf,5) = amount; // amount
  3880. buf = WBUFP(buf,1); //Advance 1B
  3881. #endif
  3882. WBUFB(buf,8) = sd->inventory.u.items_inventory[index].identify; //identify flag
  3883. WBUFB(buf,9) = sd->inventory.u.items_inventory[index].attribute; // attribute
  3884. WBUFB(buf,10)= sd->inventory.u.items_inventory[index].refine; //refine
  3885. clif_addcards(WBUFP(buf, 11), &sd->inventory.u.items_inventory[index]);
  3886. #if PACKETVER >= 20150225
  3887. clif_add_random_options(WBUFP(buf, 19), &sd->inventory.u.items_inventory[index]);
  3888. #endif
  3889. }
  3890. WFIFOSET(fd,packet_len(cmd));
  3891. }
  3892. /// Notifies the client about the result of request to add an item to the current trade (ZC_ACK_ADD_EXCHANGE_ITEM).
  3893. /// 00ea <index>.W <result>.B
  3894. /// result:
  3895. /// 0 = success
  3896. /// 1 = overweight
  3897. /// 2 = trade canceled
  3898. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3899. {
  3900. int fd;
  3901. nullpo_retv(sd);
  3902. fd = sd->fd;
  3903. WFIFOHEAD(fd,packet_len(0xea));
  3904. WFIFOW(fd,0) = 0xea;
  3905. WFIFOW(fd,2) = index;
  3906. WFIFOB(fd,4) = fail;
  3907. WFIFOSET(fd,packet_len(0xea));
  3908. }
  3909. /// Notifies the client about finishing one side of the current trade (ZC_CONCLUDE_EXCHANGE_ITEM).
  3910. /// 00ec <who>.B
  3911. /// who:
  3912. /// 0 = self
  3913. /// 1 = other player
  3914. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3915. {
  3916. int fd;
  3917. nullpo_retv(sd);
  3918. fd = sd->fd;
  3919. WFIFOHEAD(fd,packet_len(0xec));
  3920. WFIFOW(fd,0) = 0xec;
  3921. WFIFOB(fd,2) = fail;
  3922. WFIFOSET(fd,packet_len(0xec));
  3923. }
  3924. /// Notifies the client about the trade being canceled (ZC_CANCEL_EXCHANGE_ITEM).
  3925. /// 00ee
  3926. void clif_tradecancelled(struct map_session_data* sd)
  3927. {
  3928. int fd;
  3929. nullpo_retv(sd);
  3930. fd = sd->fd;
  3931. WFIFOHEAD(fd,packet_len(0xee));
  3932. WFIFOW(fd,0) = 0xee;
  3933. WFIFOSET(fd,packet_len(0xee));
  3934. }
  3935. /// Result of a trade (ZC_EXEC_EXCHANGE_ITEM).
  3936. /// 00f0 <result>.B
  3937. /// result:
  3938. /// 0 = success
  3939. /// 1 = failure
  3940. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3941. {
  3942. int fd;
  3943. nullpo_retv(sd);
  3944. fd = sd->fd;
  3945. WFIFOHEAD(fd,packet_len(0xf0));
  3946. WFIFOW(fd,0) = 0xf0;
  3947. WFIFOB(fd,2) = fail;
  3948. WFIFOSET(fd,packet_len(0xf0));
  3949. }
  3950. /// Resets the trade window on the send side (ZC_EXCHANGEITEM_UNDO).
  3951. /// 00f1
  3952. /// NOTE: Unknown purpose. Items are not removed until the window is
  3953. /// refreshed (ex. by putting another item in there).
  3954. void clif_tradeundo(struct map_session_data* sd)
  3955. {
  3956. int fd = sd->fd;
  3957. WFIFOHEAD(fd,packet_len(0xf1));
  3958. WFIFOW(fd,0) = 0xf1;
  3959. WFIFOSET(fd,packet_len(0xf1));
  3960. }
  3961. /// Updates storage total amount (ZC_NOTIFY_STOREITEM_COUNTINFO).
  3962. /// 00f2 <current count>.W <max count>.W
  3963. void clif_updatestorageamount(struct map_session_data* sd, int amount, int max_amount)
  3964. {
  3965. int fd;
  3966. nullpo_retv(sd);
  3967. fd=sd->fd;
  3968. WFIFOHEAD(fd,packet_len(0xf2));
  3969. WFIFOW(fd,0) = 0xf2;
  3970. WFIFOW(fd,2) = amount;
  3971. WFIFOW(fd,4) = max_amount;
  3972. WFIFOSET(fd,packet_len(0xf2));
  3973. }
  3974. /// Notifies the client of an item being added to the storage.
  3975. /// 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)
  3976. /// 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)
  3977. /// 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)
  3978. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3979. {
  3980. #if PACKETVER < 5
  3981. const int cmd = 0xf4;
  3982. #elif PACKETVER < 20150225
  3983. const int cmd = 0x1c4;
  3984. #else
  3985. const int cmd = 0xa0a;
  3986. #endif
  3987. int view,fd;
  3988. int offset = 0;
  3989. nullpo_retv(sd);
  3990. nullpo_retv(i);
  3991. fd=sd->fd;
  3992. view = itemdb_viewid(i->nameid);
  3993. WFIFOHEAD(fd,packet_len(cmd));
  3994. WFIFOW(fd, 0) = cmd; // Storage item added
  3995. WFIFOW(fd, 2) = index+1; // index
  3996. WFIFOL(fd, 4) = amount; // amount
  3997. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3998. #if PACKETVER >= 5
  3999. WFIFOB(fd,10) = itemtype(i->nameid); //type
  4000. offset += 1;
  4001. #endif
  4002. WFIFOB(fd,10+offset) = i->identify; //identify flag
  4003. WFIFOB(fd,11+offset) = i->attribute; // attribute
  4004. WFIFOB(fd,12+offset) = i->refine; //refine
  4005. clif_addcards(WFIFOP(fd,13+offset), i);
  4006. #if PACKETVER >= 20150225
  4007. clif_add_random_options(WFIFOP(fd,21+offset), i);
  4008. #endif
  4009. WFIFOSET(fd,packet_len(cmd));
  4010. }
  4011. /// Notifies the client of an item being deleted from the storage (ZC_DELETE_ITEM_FROM_STORE).
  4012. /// 00f6 <index>.W <amount>.L
  4013. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  4014. {
  4015. int fd;
  4016. nullpo_retv(sd);
  4017. fd=sd->fd;
  4018. WFIFOHEAD(fd,packet_len(0xf6));
  4019. WFIFOW(fd,0)=0xf6; // Storage item removed
  4020. WFIFOW(fd,2)=index+1;
  4021. WFIFOL(fd,4)=amount;
  4022. WFIFOSET(fd,packet_len(0xf6));
  4023. }
  4024. /// Closes storage (ZC_CLOSE_STORE).
  4025. /// 00f8
  4026. void clif_storageclose(struct map_session_data* sd)
  4027. {
  4028. int fd;
  4029. nullpo_retv(sd);
  4030. fd=sd->fd;
  4031. WFIFOHEAD(fd,packet_len(0xf8));
  4032. WFIFOW(fd,0) = 0xf8; // Storage Closed
  4033. WFIFOSET(fd,packet_len(0xf8));
  4034. }
  4035. /*==========================================
  4036. * Server tells 'sd' player client the abouts of 'dstsd' player
  4037. *------------------------------------------*/
  4038. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  4039. {
  4040. struct block_list *d_bl;
  4041. int i;
  4042. if( dstsd->chatID ) {
  4043. struct chat_data *cd = NULL;
  4044. if( (cd = (struct chat_data*)map_id2bl(dstsd->chatID)) && cd->usersd[0]==dstsd)
  4045. clif_dispchat(cd,sd->fd);
  4046. } else if( dstsd->state.vending )
  4047. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  4048. else if( dstsd->state.buyingstore )
  4049. clif_buyingstore_entry_single(sd, dstsd);
  4050. if(dstsd->spiritball > 0)
  4051. clif_spiritball_single(sd->fd, dstsd);
  4052. if (dstsd->spiritcharm_type != CHARM_TYPE_NONE && dstsd->spiritcharm > 0)
  4053. clif_spiritcharm_single(sd->fd, dstsd);
  4054. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  4055. (sd->bg_id && sd->bg_id == dstsd->bg_id) || //BattleGround
  4056. pc_has_permission(sd, PC_PERM_VIEW_HPMETER)
  4057. )
  4058. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  4059. // display link (sd - dstsd) to sd
  4060. ARR_FIND( 0, MAX_DEVOTION, i, sd->devotion[i] == dstsd->bl.id );
  4061. if( i < MAX_DEVOTION )
  4062. clif_devotion(&sd->bl, sd);
  4063. // display links (dstsd - devotees) to sd
  4064. ARR_FIND( 0, MAX_DEVOTION, i, dstsd->devotion[i] > 0 );
  4065. if( i < MAX_DEVOTION )
  4066. clif_devotion(&dstsd->bl, sd);
  4067. // display link (dstsd - crusader) to sd
  4068. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  4069. clif_devotion(d_bl, sd);
  4070. }
  4071. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  4072. {
  4073. uint8 buf[128];
  4074. struct unit_data *ud;
  4075. struct view_data *vd;
  4076. int len;
  4077. vd = status_get_viewdata(bl);
  4078. if (!vd || vd->class_ == JT_INVISIBLE)
  4079. return;
  4080. /**
  4081. * Hide NPC from maya purple card.
  4082. **/
  4083. if(bl->type == BL_NPC && !((TBL_NPC*)bl)->chat_id && (((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4084. return;
  4085. ud = unit_bl2ud(bl);
  4086. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  4087. clif_send(buf,len,&sd->bl,SELF);
  4088. if (vd->cloth_color)
  4089. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  4090. if (vd->body_style)
  4091. clif_refreshlook(&sd->bl,bl->id,LOOK_BODY2,vd->body_style,SELF);
  4092. switch (bl->type)
  4093. {
  4094. case BL_PC:
  4095. {
  4096. TBL_PC* tsd = (TBL_PC*)bl;
  4097. clif_getareachar_pc(sd, tsd);
  4098. if(tsd->state.size==SZ_BIG) // tiny/big players [Valaris]
  4099. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4100. else if(tsd->state.size==SZ_MEDIUM)
  4101. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4102. if( tsd->bg_id && map[tsd->bl.m].flag.battleground )
  4103. clif_sendbgemblem_single(sd->fd,tsd);
  4104. if ( tsd->status.robe )
  4105. clif_refreshlook(&sd->bl,bl->id,LOOK_ROBE,tsd->status.robe,SELF);
  4106. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4107. clif_hat_effects(sd,bl,SELF);
  4108. }
  4109. break;
  4110. case BL_MER: // Devotion Effects
  4111. if( ((TBL_MER*)bl)->devotion_flag )
  4112. clif_devotion(bl, sd);
  4113. break;
  4114. case BL_NPC:
  4115. {
  4116. TBL_NPC* nd = (TBL_NPC*)bl;
  4117. if( nd->chat_id )
  4118. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  4119. if( nd->size == SZ_BIG )
  4120. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4121. else if( nd->size == SZ_MEDIUM )
  4122. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4123. clif_efst_status_change_sub(&sd->bl, bl, SELF);
  4124. clif_progressbar_npc(nd, sd);
  4125. }
  4126. break;
  4127. case BL_MOB:
  4128. {
  4129. TBL_MOB* md = (TBL_MOB*)bl;
  4130. if(md->special_state.size==SZ_BIG) // tiny/big mobs [Valaris]
  4131. clif_specialeffect_single(bl,EF_GIANTBODY2,sd->fd);
  4132. else if(md->special_state.size==SZ_MEDIUM)
  4133. clif_specialeffect_single(bl,EF_BABYBODY2,sd->fd);
  4134. #if PACKETVER >= 20120404
  4135. if (battle_config.monster_hp_bars_info && !map[bl->m].flag.hidemobhpbar) {
  4136. int i;
  4137. for(i = 0; i < DAMAGELOG_SIZE; i++)// must show hp bar to all char who already hit the mob.
  4138. if( md->dmglog[i].id == sd->status.char_id )
  4139. clif_monster_hp_bar(md, sd->fd);
  4140. }
  4141. #endif
  4142. }
  4143. break;
  4144. case BL_PET:
  4145. if (vd->head_bottom)
  4146. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  4147. break;
  4148. }
  4149. }
  4150. //Modifies the type of damage according to status changes [Skotlex]
  4151. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  4152. static enum e_damage_type clif_calc_delay(enum e_damage_type type, int div, int64 damage, int delay)
  4153. {
  4154. return ( delay == 0 && damage > 0 ) ? ( div > 1 ? DMG_MULTI_HIT_ENDURE : DMG_ENDURE ) : type;
  4155. }
  4156. /*==========================================
  4157. * Estimates walk delay based on the damage criteria. [Skotlex]
  4158. *------------------------------------------*/
  4159. static int clif_calc_walkdelay(struct block_list *bl,int delay, char type, int64 damage, int div_)
  4160. {
  4161. if (type == DMG_ENDURE || type == DMG_MULTI_HIT_ENDURE || damage <= 0)
  4162. return 0;
  4163. if (bl->type == BL_PC) {
  4164. if (battle_config.pc_walk_delay_rate != 100)
  4165. delay = delay*battle_config.pc_walk_delay_rate/100;
  4166. } else
  4167. if (battle_config.walk_delay_rate != 100)
  4168. delay = delay*battle_config.walk_delay_rate/100;
  4169. if (div_ > 1) //Multi-hit skills mean higher delays.
  4170. delay += battle_config.multihit_delay*(div_-1);
  4171. return (delay > 0) ? delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  4172. }
  4173. /*========================================== [Playtester]
  4174. * Returns hallucination damage the client displays
  4175. *------------------------------------------*/
  4176. static int clif_hallucination_damage()
  4177. {
  4178. int digit = rnd() % 5 + 1;
  4179. switch (digit)
  4180. {
  4181. case 1:
  4182. return (rnd() % 10);
  4183. case 2:
  4184. return (rnd() % 100);
  4185. case 3:
  4186. return (rnd() % 1000);
  4187. case 4:
  4188. return (rnd() % 10000);
  4189. }
  4190. return (rnd() % 32767);
  4191. }
  4192. /// Sends a 'damage' packet (src performs action on dst)
  4193. /// 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)
  4194. /// 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)
  4195. /// 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)
  4196. /// type:
  4197. /// 0 = damage [ damage: total damage, div: amount of hits, damage2: assassin dual-wield damage ]
  4198. /// 1 = pick up item
  4199. /// 2 = sit down
  4200. /// 3 = stand up
  4201. /// 4 = damage (endure)
  4202. /// 5 = (splash?)
  4203. /// 6 = (skill?)
  4204. /// 7 = (repeat damage?)
  4205. /// 8 = multi-hit damage
  4206. /// 9 = multi-hit damage (endure)
  4207. /// 10 = critical hit
  4208. /// 11 = lucky dodge
  4209. /// 12 = (touch skill?)
  4210. 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)
  4211. {
  4212. unsigned char buf[34];
  4213. struct status_change *sc;
  4214. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4215. int damage2 = (int)cap_value(sdamage2,INT_MIN,INT_MAX);
  4216. #if PACKETVER < 20071113
  4217. const int cmd = 0x8a;
  4218. int offset = 0;
  4219. #elif PACKETVER < 20131223
  4220. const int cmd = 0x2e1;
  4221. int offset = 2;
  4222. #else
  4223. const int cmd = 0x8c8;
  4224. int offset = 3;
  4225. #endif
  4226. nullpo_ret(src);
  4227. nullpo_ret(dst);
  4228. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  4229. sc = status_get_sc(dst);
  4230. if(sc && sc->count) {
  4231. if(sc->data[SC_HALLUCINATION]) {
  4232. if(damage) damage = clif_hallucination_damage();
  4233. if(damage2) damage2 = clif_hallucination_damage();
  4234. }
  4235. }
  4236. WBUFW(buf,0) = cmd;
  4237. WBUFL(buf,2) = src->id;
  4238. WBUFL(buf,6) = dst->id;
  4239. WBUFL(buf,10) = tick;
  4240. WBUFL(buf,14) = sdelay;
  4241. WBUFL(buf,18) = ddelay;
  4242. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4243. #if PACKETVER < 20071113
  4244. WBUFW(buf,22) = damage ? div : 0;
  4245. WBUFW(buf,27+offset) = damage2 ? div : 0;
  4246. #else
  4247. WBUFL(buf, 22) = damage ? div : 0;
  4248. WBUFL(buf, 27 + offset) = damage2 ? div : 0;
  4249. #endif
  4250. } else {
  4251. #if PACKETVER < 20071113
  4252. WBUFW(buf,22) = min(damage, INT16_MAX);
  4253. WBUFW(buf,27+offset) = damage2;
  4254. #else
  4255. WBUFL(buf,22) = damage;
  4256. WBUFL(buf,27+offset) = damage2;
  4257. #endif
  4258. }
  4259. #if PACKETVER >= 20131223
  4260. WBUFB(buf,26) = (spdamage) ? 1 : 0; // IsSPDamage - Displays blue digits.
  4261. #endif
  4262. WBUFW(buf,24+offset) = div;
  4263. WBUFB(buf,26+offset) = type;
  4264. if(disguised(dst)) {
  4265. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  4266. WBUFL(buf,6) = -dst->id;
  4267. clif_send(buf, packet_len(cmd), dst, SELF);
  4268. } else
  4269. clif_send(buf, packet_len(cmd), dst, AREA);
  4270. if(disguised(src)) {
  4271. WBUFL(buf,2) = -src->id;
  4272. if (disguised(dst))
  4273. WBUFL(buf,6) = dst->id;
  4274. #if PACKETVER < 20071113
  4275. if(damage > 0) WBUFW(buf,22) = -1;
  4276. if(damage2 > 0) WBUFW(buf,27) = -1;
  4277. #else
  4278. if(damage > 0) WBUFL(buf,22) = -1;
  4279. if(damage2 > 0) WBUFL(buf,27+offset) = -1;
  4280. #endif
  4281. clif_send(buf,packet_len(cmd),src,SELF);
  4282. }
  4283. if(src == dst) {
  4284. unit_setdir(src, unit_getdir(src));
  4285. }
  4286. //Return adjusted can't walk delay for further processing.
  4287. return clif_calc_walkdelay(dst, ddelay, type, damage+damage2, div);
  4288. }
  4289. /*==========================================
  4290. * src picks up dst
  4291. *------------------------------------------*/
  4292. void clif_takeitem(struct block_list* src, struct block_list* dst)
  4293. {
  4294. //clif_damage(src,dst,0,0,0,0,0,DMG_PICKUP_ITEM,0,false);
  4295. unsigned char buf[32];
  4296. nullpo_retv(src);
  4297. nullpo_retv(dst);
  4298. WBUFW(buf, 0) = 0x8a;
  4299. WBUFL(buf, 2) = src->id;
  4300. WBUFL(buf, 6) = dst->id;
  4301. WBUFB(buf,26) = 1;
  4302. clif_send(buf, packet_len(0x8a), src, AREA);
  4303. }
  4304. /*==========================================
  4305. * inform clients in area that `bl` is sitting
  4306. *------------------------------------------*/
  4307. void clif_sitting(struct block_list* bl)
  4308. {
  4309. unsigned char buf[32];
  4310. nullpo_retv(bl);
  4311. WBUFW(buf, 0) = 0x8a;
  4312. WBUFL(buf, 2) = bl->id;
  4313. WBUFB(buf,26) = 2;
  4314. clif_send(buf, packet_len(0x8a), bl, AREA);
  4315. if(disguised(bl)) {
  4316. WBUFL(buf, 2) = - bl->id;
  4317. clif_send(buf, packet_len(0x8a), bl, SELF);
  4318. }
  4319. }
  4320. /*==========================================
  4321. * inform clients in area that `bl` is standing
  4322. *------------------------------------------*/
  4323. void clif_standing(struct block_list* bl)
  4324. {
  4325. unsigned char buf[32];
  4326. nullpo_retv(bl);
  4327. WBUFW(buf, 0) = 0x8a;
  4328. WBUFL(buf, 2) = bl->id;
  4329. WBUFB(buf,26) = 3;
  4330. clif_send(buf, packet_len(0x8a), bl, AREA);
  4331. if(disguised(bl)) {
  4332. WBUFL(buf, 2) = - bl->id;
  4333. clif_send(buf, packet_len(0x8a), bl, SELF);
  4334. }
  4335. }
  4336. /// Inform client(s) about a map-cell change (ZC_UPDATE_MAPINFO).
  4337. /// 0192 <x>.W <y>.W <type>.W <map name>.16B
  4338. void clif_changemapcell(int fd, int16 m, int x, int y, int type, enum send_target target)
  4339. {
  4340. unsigned char buf[32];
  4341. WBUFW(buf,0) = 0x192;
  4342. WBUFW(buf,2) = x;
  4343. WBUFW(buf,4) = y;
  4344. WBUFW(buf,6) = type;
  4345. mapindex_getmapname_ext(map_mapid2mapname(m),WBUFCP(buf,8));
  4346. if( fd )
  4347. {
  4348. WFIFOHEAD(fd,packet_len(0x192));
  4349. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  4350. WFIFOSET(fd,packet_len(0x192));
  4351. }
  4352. else
  4353. {
  4354. struct block_list dummy_bl;
  4355. dummy_bl.type = BL_NUL;
  4356. dummy_bl.x = x;
  4357. dummy_bl.y = y;
  4358. dummy_bl.m = m;
  4359. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  4360. }
  4361. }
  4362. /// Notifies the client about an item on floor (ZC_ITEM_ENTRY).
  4363. /// 009d <id>.L <name id>.W <identified>.B <x>.W <y>.W <amount>.W <subX>.B <subY>.B
  4364. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  4365. {
  4366. int view,fd;
  4367. fd=sd->fd;
  4368. WFIFOHEAD(fd,packet_len(0x9d));
  4369. WFIFOW(fd,0)=0x9d;
  4370. WFIFOL(fd,2)=fitem->bl.id;
  4371. if((view = itemdb_viewid(fitem->item.nameid)) > 0)
  4372. WFIFOW(fd,6)=view;
  4373. else
  4374. WFIFOW(fd,6)=fitem->item.nameid;
  4375. WFIFOB(fd,8)=fitem->item.identify;
  4376. WFIFOW(fd,9)=fitem->bl.x;
  4377. WFIFOW(fd,11)=fitem->bl.y;
  4378. WFIFOW(fd,13)=fitem->item.amount;
  4379. WFIFOB(fd,15)=fitem->subx;
  4380. WFIFOB(fd,16)=fitem->suby;
  4381. WFIFOSET(fd,packet_len(0x9d));
  4382. }
  4383. /// Notifes client about Graffiti
  4384. /// 01c9 <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B <has msg>.B <msg>.80B (ZC_SKILL_ENTRY2)
  4385. static void clif_graffiti(struct block_list *bl, struct skill_unit *unit, enum send_target target) {
  4386. unsigned char buf[128];
  4387. nullpo_retv(bl);
  4388. nullpo_retv(unit);
  4389. WBUFW(buf, 0) = 0x1c9;
  4390. WBUFL(buf, 2) = unit->bl.id;
  4391. WBUFL(buf, 6) = unit->group->src_id;
  4392. WBUFW(buf,10) = unit->bl.x;
  4393. WBUFW(buf,12) = unit->bl.y;
  4394. WBUFB(buf,14) = unit->group->unit_id;
  4395. WBUFB(buf,15) = 1;
  4396. WBUFB(buf,16) = 1;
  4397. safestrncpy(WBUFCP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4398. clif_send(buf,packet_len(0x1c9),bl,target);
  4399. }
  4400. /// Notifies the client of a skill unit.
  4401. /// 011f <id>.L <creator id>.L <x>.W <y>.W <unit id>.B <visible>.B (ZC_SKILL_ENTRY)
  4402. /// 08c7 <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.B <range>.W <visible>.B (ZC_SKILL_ENTRY3)
  4403. /// 099f <lenght>.W <id> L <creator id>.L <x>.W <y>.W <unit id>.L <range>.W <visible>.B (ZC_SKILL_ENTRY4)
  4404. /// 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)
  4405. void clif_getareachar_skillunit(struct block_list *bl, struct skill_unit *unit, enum send_target target, bool visible) {
  4406. int header = 0, unit_id = 0, pos = 0, fd = 0, len = -1;
  4407. unsigned char buf[128];
  4408. nullpo_retv(bl);
  4409. nullpo_retv(unit);
  4410. if (bl->type == BL_PC)
  4411. fd = ((TBL_PC*)bl)->fd;
  4412. if (unit->group->state.guildaura)
  4413. return;
  4414. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4415. unit_id = unit->val2&UF_SONG ? UNT_DISSONANCE : UNT_UGLYDANCE;
  4416. else if (skill_get_unit_flag(unit->group->skill_id) & UF_RANGEDSINGLEUNIT && !(unit->val2 & UF_RANGEDSINGLEUNIT))
  4417. unit_id = UNT_DUMMYSKILL; // Use invisible unit id for other case of rangedsingle unit
  4418. else
  4419. unit_id = unit->group->unit_id;
  4420. if (!visible)
  4421. unit_id = UNT_DUMMYSKILL; // Hack to makes hidden trap really hidden!
  4422. #if PACKETVER >= 3
  4423. if (unit_id == UNT_GRAFFITI) { // Graffiti [Valaris]
  4424. clif_graffiti(bl, unit, target);
  4425. return;
  4426. }
  4427. #endif
  4428. #if PACKETVER <= 20120702
  4429. header = 0x011f;
  4430. //#if PACKETVER < 20110718
  4431. // header = 0x011f;
  4432. //#elif PACKETVER < 20121212
  4433. // header = 0x08c7;
  4434. #elif PACKETVER < 20130731
  4435. header = 0x099f;
  4436. #else
  4437. header = 0x09ca;
  4438. #endif
  4439. len = packet_len(header);
  4440. WBUFW(buf,pos) = header;
  4441. if (header != 0x011f) {
  4442. WBUFW(buf, pos+2) = len;
  4443. pos += 2;
  4444. }
  4445. WBUFL(buf,pos+2) = unit->bl.id;
  4446. WBUFL(buf,pos+6) = unit->group->src_id;
  4447. WBUFW(buf,pos+10) = unit->bl.x;
  4448. WBUFW(buf,pos+12) = unit->bl.y;
  4449. switch (header) {
  4450. case 0x011f:
  4451. WBUFB(buf,pos+14) = unit_id;
  4452. WBUFB(buf,pos+15) = visible;
  4453. break;
  4454. case 0x08c7:
  4455. WBUFB(buf,pos+14) = unit_id;
  4456. WBUFW(buf,pos+15) = unit->range;
  4457. WBUFB(buf,pos+17) = visible;
  4458. break;
  4459. case 0x099f:
  4460. WBUFL(buf,pos+14) = unit_id;
  4461. WBUFW(buf,pos+18) = unit->range;
  4462. WBUFB(buf,pos+20) = visible;
  4463. break;
  4464. case 0x09ca:
  4465. WBUFL(buf,pos+14) = unit_id;
  4466. WBUFB(buf,pos+18) = (unsigned char)unit->range;
  4467. WBUFB(buf,pos+19) = visible;
  4468. WBUFB(buf,pos+20) = (unsigned char)unit->group->skill_lv;
  4469. break;
  4470. }
  4471. clif_send(buf, len, bl, target);
  4472. if (unit->group->skill_id == WZ_ICEWALL)
  4473. clif_changemapcell(fd, unit->bl.m, unit->bl.x, unit->bl.y, 5, SELF);
  4474. }
  4475. /*==========================================
  4476. * Server tells client to remove unit of id 'unit->bl.id'
  4477. *------------------------------------------*/
  4478. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  4479. {
  4480. nullpo_retv(unit);
  4481. WFIFOHEAD(fd,packet_len(0x120));
  4482. WFIFOW(fd, 0)=0x120;
  4483. WFIFOL(fd, 2)=unit->bl.id;
  4484. WFIFOSET(fd,packet_len(0x120));
  4485. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  4486. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  4487. }
  4488. /// Removes a skill unit (ZC_SKILL_DISAPPEAR).
  4489. /// 0120 <id>.L
  4490. void clif_skill_delunit(struct skill_unit *unit)
  4491. {
  4492. unsigned char buf[16];
  4493. nullpo_retv(unit);
  4494. WBUFW(buf, 0)=0x120;
  4495. WBUFL(buf, 2)=unit->bl.id;
  4496. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4497. }
  4498. /// Sent when an object gets ankle-snared (ZC_SKILL_UPDATE).
  4499. /// 01ac <id>.L
  4500. /// Only affects units with class [139,153] client-side.
  4501. void clif_skillunit_update(struct block_list* bl)
  4502. {
  4503. unsigned char buf[6];
  4504. nullpo_retv(bl);
  4505. WBUFW(buf,0) = 0x1ac;
  4506. WBUFL(buf,2) = bl->id;
  4507. clif_send(buf,packet_len(0x1ac),bl,AREA);
  4508. }
  4509. /*==========================================
  4510. *
  4511. *------------------------------------------*/
  4512. static int clif_getareachar(struct block_list* bl,va_list ap)
  4513. {
  4514. struct map_session_data *sd;
  4515. nullpo_ret(bl);
  4516. sd=va_arg(ap,struct map_session_data*);
  4517. if (sd == NULL || !sd->fd)
  4518. return 0;
  4519. switch(bl->type){
  4520. case BL_ITEM:
  4521. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  4522. break;
  4523. case BL_SKILL:
  4524. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &sd->bl);
  4525. break;
  4526. default:
  4527. if(&sd->bl == bl)
  4528. break;
  4529. clif_getareachar_unit(sd,bl);
  4530. break;
  4531. }
  4532. return 0;
  4533. }
  4534. /*==========================================
  4535. * tbl has gone out of view-size of bl
  4536. *------------------------------------------*/
  4537. int clif_outsight(struct block_list *bl,va_list ap)
  4538. {
  4539. struct block_list *tbl;
  4540. struct view_data *vd;
  4541. TBL_PC *sd, *tsd;
  4542. tbl=va_arg(ap,struct block_list*);
  4543. if(bl == tbl) return 0;
  4544. sd = BL_CAST(BL_PC, bl);
  4545. tsd = BL_CAST(BL_PC, tbl);
  4546. if (tsd && tsd->fd) { //tsd has lost sight of the bl object.
  4547. nullpo_ret(bl);
  4548. switch(bl->type){
  4549. case BL_PC:
  4550. if(sd->vd.class_ != JT_INVISIBLE)
  4551. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4552. if(sd->chatID){
  4553. struct chat_data *cd;
  4554. cd=(struct chat_data*)map_id2bl(sd->chatID);
  4555. if(cd->usersd[0]==sd)
  4556. clif_dispchat(cd,tsd->fd);
  4557. }
  4558. if(sd->state.vending)
  4559. clif_closevendingboard(bl,tsd->fd);
  4560. if(sd->state.buyingstore)
  4561. clif_buyingstore_disappear_entry_single(tsd, sd);
  4562. break;
  4563. case BL_ITEM:
  4564. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  4565. break;
  4566. case BL_SKILL:
  4567. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  4568. break;
  4569. case BL_NPC:
  4570. if(!(((TBL_NPC*)bl)->sc.option&OPTION_INVISIBLE))
  4571. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4572. break;
  4573. default:
  4574. if((vd=status_get_viewdata(bl)) && vd->class_ != JT_INVISIBLE)
  4575. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  4576. break;
  4577. }
  4578. }
  4579. if (sd && sd->fd) { //sd is watching tbl go out of view.
  4580. nullpo_ret(tbl);
  4581. if(tbl->type == BL_SKILL) //Trap knocked out of sight
  4582. clif_clearchar_skillunit((struct skill_unit *)tbl,sd->fd);
  4583. else if(((vd=status_get_viewdata(tbl)) && vd->class_ != JT_INVISIBLE) &&
  4584. !(tbl->type == BL_NPC && (((TBL_NPC*)tbl)->sc.option&OPTION_INVISIBLE)))
  4585. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  4586. }
  4587. return 0;
  4588. }
  4589. /*==========================================
  4590. * tbl has come into view of bl
  4591. *------------------------------------------*/
  4592. int clif_insight(struct block_list *bl,va_list ap)
  4593. {
  4594. struct block_list *tbl;
  4595. TBL_PC *sd, *tsd;
  4596. tbl=va_arg(ap,struct block_list*);
  4597. if (bl == tbl) return 0;
  4598. sd = BL_CAST(BL_PC, bl);
  4599. tsd = BL_CAST(BL_PC, tbl);
  4600. if (tsd && tsd->fd) { //Tell tsd that bl entered into his view
  4601. switch(bl->type){
  4602. case BL_ITEM:
  4603. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  4604. break;
  4605. case BL_SKILL:
  4606. skill_getareachar_skillunit_visibilty_single((TBL_SKILL*)bl, &tsd->bl);
  4607. break;
  4608. default:
  4609. clif_getareachar_unit(tsd,bl);
  4610. break;
  4611. }
  4612. }
  4613. if (sd && sd->fd) { //Tell sd that tbl walked into his view
  4614. clif_getareachar_unit(sd,tbl);
  4615. }
  4616. return 0;
  4617. }
  4618. /// Updates whole skill tree (ZC_SKILLINFO_LIST).
  4619. /// 010f <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  4620. void clif_skillinfoblock(struct map_session_data *sd)
  4621. {
  4622. int fd;
  4623. int i,len,id;
  4624. nullpo_retv(sd);
  4625. fd = sd->fd;
  4626. if (!fd)
  4627. return;
  4628. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  4629. WFIFOW(fd,0) = 0x10f;
  4630. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  4631. {
  4632. if( (id = sd->status.skill[i].id) != 0 )
  4633. {
  4634. // workaround for bugreport:5348
  4635. if (len + 37 > 8192)
  4636. break;
  4637. WFIFOW(fd,len) = id;
  4638. WFIFOL(fd,len+2) = skill_get_inf(id);
  4639. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  4640. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  4641. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl,id,sd->status.skill[i].lv,false);
  4642. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  4643. if(sd->status.skill[i].flag == SKILL_FLAG_PERMANENT)
  4644. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  4645. else
  4646. WFIFOB(fd,len+36) = 0;
  4647. len += 37;
  4648. }
  4649. }
  4650. WFIFOW(fd,2)=len;
  4651. WFIFOSET(fd,len);
  4652. // workaround for bugreport:5348; send the remaining skills one by one to bypass packet size limit
  4653. for ( ; i < MAX_SKILL; i++)
  4654. {
  4655. if( (id = sd->status.skill[i].id) != 0 )
  4656. {
  4657. clif_addskill(sd, id);
  4658. clif_skillinfo(sd, id, 0);
  4659. }
  4660. }
  4661. }
  4662. /**
  4663. * Server tells client 'sd' to add skill of id 'id' to it's skill tree (e.g. with Ice Falcion item)
  4664. **/
  4665. /// Adds new skill to the skill tree (ZC_ADD_SKILL).
  4666. /// 0111 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B
  4667. void clif_addskill(struct map_session_data *sd, int skill_id)
  4668. {
  4669. int fd;
  4670. uint16 idx = 0;
  4671. nullpo_retv(sd);
  4672. fd = sd->fd;
  4673. if (!fd || !(idx = skill_get_index(skill_id)))
  4674. return;
  4675. if( sd->status.skill[idx].id <= 0 )
  4676. return;
  4677. WFIFOHEAD(fd, packet_len(0x111));
  4678. WFIFOW(fd,0) = 0x111;
  4679. WFIFOW(fd,2) = skill_id;
  4680. WFIFOL(fd,4) = skill_get_inf(skill_id);
  4681. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4682. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4683. WFIFOW(fd,12)= skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4684. safestrncpy(WFIFOCP(fd,14), skill_get_name(skill_id), NAME_LENGTH);
  4685. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4686. WFIFOB(fd,38) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4687. else
  4688. WFIFOB(fd,38) = 0;
  4689. WFIFOSET(fd,packet_len(0x111));
  4690. }
  4691. /// Deletes a skill from the skill tree (ZC_SKILLINFO_DELETE).
  4692. /// 0441 <skill id>.W
  4693. void clif_deleteskill(struct map_session_data *sd, int skill_id)
  4694. {
  4695. #if PACKETVER >= 20081217
  4696. int fd;
  4697. uint16 idx = 0;
  4698. nullpo_retv(sd);
  4699. fd = sd->fd;
  4700. if (!fd || !(idx = skill_get_index(skill_id)))
  4701. return;
  4702. WFIFOHEAD(fd,packet_len(0x441));
  4703. WFIFOW(fd,0) = 0x441;
  4704. WFIFOW(fd,2) = skill_id;
  4705. WFIFOSET(fd,packet_len(0x441));
  4706. #endif
  4707. clif_skillinfoblock(sd);
  4708. }
  4709. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE).
  4710. /// 010e <skill id>.W <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4711. void clif_skillup(struct map_session_data *sd, uint16 skill_id, int lv, int range, int upgradable) {
  4712. int fd;
  4713. nullpo_retv(sd);
  4714. fd = sd->fd;
  4715. WFIFOHEAD(fd, packet_len(0x10e));
  4716. WFIFOW(fd, 0) = 0x10e;
  4717. WFIFOW(fd, 2) = skill_id;
  4718. WFIFOW(fd, 4) = lv;
  4719. WFIFOW(fd, 6) = skill_get_sp(skill_id, lv);
  4720. WFIFOW(fd, 8) = range;
  4721. WFIFOB(fd, 10) = upgradable;
  4722. WFIFOSET(fd, packet_len(0x10e));
  4723. }
  4724. /// Updates a skill in the skill tree (ZC_SKILLINFO_UPDATE2).
  4725. /// 07e1 <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <upgradable>.B
  4726. void clif_skillinfo(struct map_session_data *sd,int skill_id, int inf)
  4727. {
  4728. const int fd = sd->fd;
  4729. uint16 idx = skill_get_index(skill_id);
  4730. if (!idx)
  4731. return;
  4732. WFIFOHEAD(fd,packet_len(0x7e1));
  4733. WFIFOW(fd,0) = 0x7e1;
  4734. WFIFOW(fd,2) = skill_id;
  4735. WFIFOL(fd,4) = inf?inf:skill_get_inf(skill_id);
  4736. WFIFOW(fd,8) = sd->status.skill[idx].lv;
  4737. WFIFOW(fd,10) = skill_get_sp(skill_id,sd->status.skill[idx].lv);
  4738. WFIFOW(fd,12) = skill_get_range2(&sd->bl,skill_id,sd->status.skill[idx].lv,false);
  4739. if( sd->status.skill[idx].flag == SKILL_FLAG_PERMANENT )
  4740. WFIFOB(fd,14) = (sd->status.skill[idx].lv < skill_tree_get_max(skill_id, sd->status.class_))? 1:0;
  4741. else
  4742. WFIFOB(fd,14) = 0;
  4743. WFIFOSET(fd,packet_len(0x7e1));
  4744. }
  4745. /// Notifies clients in area, that an object is about to use a skill.
  4746. /// 013e <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L (ZC_USESKILL_ACK)
  4747. /// 07fb <src id>.L <dst id>.L <x>.W <y>.W <skill id>.W <property>.L <delaytime>.L <is disposable>.B (ZC_USESKILL_ACK2)
  4748. /// property:
  4749. /// 0 = Yellow cast aura
  4750. /// 1 = Water elemental cast aura
  4751. /// 2 = Earth elemental cast aura
  4752. /// 3 = Fire elemental cast aura
  4753. /// 4 = Wind elemental cast aura
  4754. /// 5 = Poison elemental cast aura
  4755. /// 6 = Holy elemental cast aura
  4756. /// ? = like 0
  4757. /// is disposable:
  4758. /// 0 = yellow chat text "[src name] will use skill [skill name]."
  4759. /// 1 = no text
  4760. 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)
  4761. {
  4762. #if PACKETVER < 20091124
  4763. const int cmd = 0x13e;
  4764. #else
  4765. const int cmd = 0x7fb;
  4766. #endif
  4767. unsigned char buf[32];
  4768. WBUFW(buf,0) = cmd;
  4769. WBUFL(buf,2) = src_id;
  4770. WBUFL(buf,6) = dst_id;
  4771. WBUFW(buf,10) = dst_x;
  4772. WBUFW(buf,12) = dst_y;
  4773. WBUFW(buf,14) = skill_id;
  4774. WBUFL(buf,16) = property<0?0:property; //Avoid sending negatives as element [Skotlex]
  4775. WBUFL(buf,20) = casttime;
  4776. #if PACKETVER >= 20091124
  4777. WBUFB(buf,24) = 0; // isDisposable
  4778. #endif
  4779. if (disguised(bl)) {
  4780. clif_send(buf,packet_len(cmd), bl, AREA_WOS);
  4781. WBUFL(buf,2) = -src_id;
  4782. clif_send(buf,packet_len(cmd), bl, SELF);
  4783. } else
  4784. clif_send(buf,packet_len(cmd), bl, AREA);
  4785. }
  4786. /// Notifies clients in area, that an object canceled casting (ZC_DISPEL).
  4787. /// 01b9 <id>.L
  4788. void clif_skillcastcancel(struct block_list* bl)
  4789. {
  4790. unsigned char buf[16];
  4791. nullpo_retv(bl);
  4792. WBUFW(buf,0) = 0x1b9;
  4793. WBUFL(buf,2) = bl->id;
  4794. clif_send(buf,packet_len(0x1b9), bl, AREA);
  4795. }
  4796. /// Notifies the client about the result of a skill use request (ZC_ACK_TOUSESKILL).
  4797. /// 0110 <skill id>.W <num>.L <result>.B <cause>.B
  4798. /// num (only used when skill id = NV_BASIC and cause = 0):
  4799. /// 0 = "skill failed" MsgStringTable[159]
  4800. /// 1 = "no emotions" MsgStringTable[160]
  4801. /// 2 = "no sit" MsgStringTable[161]
  4802. /// 3 = "no chat" MsgStringTable[162]
  4803. /// 4 = "no party" MsgStringTable[163]
  4804. /// 5 = "no shout" MsgStringTable[164]
  4805. /// 6 = "no PKing" MsgStringTable[165]
  4806. /// 7 = "no alligning" MsgStringTable[383]
  4807. /// ? = ignored
  4808. /// cause:
  4809. /// 0 = "not enough skill level" MsgStringTable[214] (AL_WARP)
  4810. /// "steal failed" MsgStringTable[205] (TF_STEAL)
  4811. /// "envenom failed" MsgStringTable[207] (TF_POISON)
  4812. /// "skill failed" MsgStringTable[204] (otherwise)
  4813. /// ... = @see enum useskill_fail_cause
  4814. /// ? = ignored
  4815. ///
  4816. /// if(result!=0) doesn't display any of the previous messages
  4817. /// Note: when this packet is received an unknown flag is always set to 0,
  4818. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  4819. void clif_skill_fail(struct map_session_data *sd,uint16 skill_id,enum useskill_fail_cause cause,int btype)
  4820. {
  4821. int fd;
  4822. if (!sd) { //Since this is the most common nullpo....
  4823. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  4824. return;
  4825. }
  4826. fd=sd->fd;
  4827. if (!fd) return;
  4828. if(battle_config.display_skill_fail&1)
  4829. return; //Disable all skill failed messages
  4830. if(cause==USESKILL_FAIL_SKILLINTERVAL && !sd->state.showdelay)
  4831. return; //Disable delay failed messages
  4832. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  4833. return;
  4834. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  4835. return;
  4836. WFIFOHEAD(fd,packet_len(0x110));
  4837. WFIFOW(fd,0) = 0x110;
  4838. WFIFOW(fd,2) = skill_id;
  4839. WFIFOL(fd,4) = btype;
  4840. WFIFOB(fd,8) = 0;// success
  4841. WFIFOB(fd,9) = cause;
  4842. WFIFOSET(fd,packet_len(0x110));
  4843. }
  4844. /// Skill cooldown display icon (ZC_SKILL_POSTDELAY).
  4845. /// 043d <skill ID>.W <tick>.L
  4846. void clif_skill_cooldown(struct map_session_data *sd, uint16 skill_id, unsigned int tick)
  4847. {
  4848. #if PACKETVER>=20081112
  4849. int fd;
  4850. nullpo_retv(sd);
  4851. fd=sd->fd;
  4852. WFIFOHEAD(fd,packet_len(0x43d));
  4853. WFIFOW(fd,0) = 0x43d;
  4854. WFIFOW(fd,2) = skill_id;
  4855. WFIFOL(fd,4) = tick;
  4856. WFIFOSET(fd,packet_len(0x43d));
  4857. #endif
  4858. }
  4859. /// Skill attack effect and damage.
  4860. /// 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)
  4861. /// 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)
  4862. 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)
  4863. {
  4864. unsigned char buf[64];
  4865. struct status_change *sc;
  4866. int damage = (int)cap_value(sdamage,INT_MIN,INT_MAX);
  4867. nullpo_ret(src);
  4868. nullpo_ret(dst);
  4869. type = clif_calc_delay(type,div,damage,ddelay);
  4870. if( ( sc = status_get_sc(dst) ) && sc->count ) {
  4871. if(sc->data[SC_HALLUCINATION] && damage)
  4872. damage = clif_hallucination_damage();
  4873. }
  4874. #if PACKETVER < 3
  4875. WBUFW(buf,0)=0x114;
  4876. WBUFW(buf,2)=skill_id;
  4877. WBUFL(buf,4)=src->id;
  4878. WBUFL(buf,8)=dst->id;
  4879. WBUFL(buf,12)=tick;
  4880. WBUFL(buf,16)=sdelay;
  4881. WBUFL(buf,20)=ddelay;
  4882. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4883. WBUFW(buf,24)=damage?div:0;
  4884. } else {
  4885. WBUFW(buf,24)=damage;
  4886. }
  4887. WBUFW(buf,26)=skill_lv;
  4888. WBUFW(buf,28)=div;
  4889. WBUFB(buf,30)=type;
  4890. if (disguised(dst)) {
  4891. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  4892. WBUFL(buf,8)=-dst->id;
  4893. clif_send(buf,packet_len(0x114),dst,SELF);
  4894. } else
  4895. clif_send(buf,packet_len(0x114),dst,AREA);
  4896. if(disguised(src)) {
  4897. WBUFL(buf,4)=-src->id;
  4898. if (disguised(dst))
  4899. WBUFL(buf,8)=dst->id;
  4900. if(damage > 0)
  4901. WBUFW(buf,24)=-1;
  4902. clif_send(buf,packet_len(0x114),src,SELF);
  4903. }
  4904. #else
  4905. WBUFW(buf,0)=0x1de;
  4906. WBUFW(buf,2)=skill_id;
  4907. WBUFL(buf,4)=src->id;
  4908. WBUFL(buf,8)=dst->id;
  4909. WBUFL(buf,12)=tick;
  4910. WBUFL(buf,16)=sdelay;
  4911. WBUFL(buf,20)=ddelay;
  4912. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4913. WBUFL(buf,24)=damage?div:0;
  4914. } else {
  4915. WBUFL(buf,24)=damage;
  4916. }
  4917. WBUFW(buf,28)=skill_lv;
  4918. WBUFW(buf,30)=div;
  4919. // For some reason, late 2013 and newer clients have
  4920. // a issue that causes players and monsters to endure
  4921. // type 6 (ACTION_SKILL) skills. So we have to do a small
  4922. // hack to set all type 6 to be sent as type 8 ACTION_ATTACK_MULTIPLE
  4923. #if PACKETVER < 20131223
  4924. WBUFB(buf,32)=type;
  4925. #else
  4926. WBUFB(buf,32)=( type == DMG_SKILL ) ? DMG_MULTI_HIT : type;
  4927. #endif
  4928. if (disguised(dst)) {
  4929. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  4930. WBUFL(buf,8)=-dst->id;
  4931. clif_send(buf,packet_len(0x1de),dst,SELF);
  4932. } else
  4933. clif_send(buf,packet_len(0x1de),dst,AREA);
  4934. if(disguised(src)) {
  4935. WBUFL(buf,4)=-src->id;
  4936. if (disguised(dst))
  4937. WBUFL(buf,8)=dst->id;
  4938. if(damage > 0)
  4939. WBUFL(buf,24)=-1;
  4940. clif_send(buf,packet_len(0x1de),src,SELF);
  4941. }
  4942. #endif
  4943. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4944. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4945. }
  4946. /// Ground skill attack effect and damage (ZC_NOTIFY_SKILL_POSITION).
  4947. /// 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
  4948. /*
  4949. 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)
  4950. {
  4951. unsigned char buf[64];
  4952. struct status_change *sc;
  4953. nullpo_ret(src);
  4954. nullpo_ret(dst);
  4955. type = (type>DMG_NORMAL)?type:skill_get_hit(skill_id);
  4956. type = clif_calc_delay(type,div,damage,ddelay);
  4957. sc = status_get_sc(dst);
  4958. if(sc && sc->count) {
  4959. if(sc->data[SC_HALLUCINATION] && damage)
  4960. damage = clif_hallucination_damage();
  4961. }
  4962. WBUFW(buf,0)=0x115;
  4963. WBUFW(buf,2)=skill_id;
  4964. WBUFL(buf,4)=src->id;
  4965. WBUFL(buf,8)=dst->id;
  4966. WBUFL(buf,12)=tick;
  4967. WBUFL(buf,16)=sdelay;
  4968. WBUFL(buf,20)=ddelay;
  4969. WBUFW(buf,24)=dst->x;
  4970. WBUFW(buf,26)=dst->y;
  4971. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4972. WBUFW(buf,28)=damage?div:0;
  4973. } else {
  4974. WBUFW(buf,28)=damage;
  4975. }
  4976. WBUFW(buf,30)=skill_lv;
  4977. WBUFW(buf,32)=div;
  4978. WBUFB(buf,34)=type;
  4979. clif_send(buf,packet_len(0x115),src,AREA);
  4980. if(disguised(src)) {
  4981. WBUFL(buf,4)=-src->id;
  4982. if(damage > 0)
  4983. WBUFW(buf,28)=-1;
  4984. clif_send(buf,packet_len(0x115),src,SELF);
  4985. }
  4986. if (disguised(dst)) {
  4987. WBUFL(buf,8)=-dst->id;
  4988. if (disguised(src))
  4989. WBUFL(buf,4)=src->id;
  4990. else if(damage > 0)
  4991. WBUFW(buf,28)=-1;
  4992. clif_send(buf,packet_len(0x115),dst,SELF);
  4993. }
  4994. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4995. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4996. }
  4997. */
  4998. /// Non-damaging skill effect
  4999. /// 011a <skill id>.W <heal>.W <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL).
  5000. /// 09cb <skill id>.W <heal>.L <dst id>.L <src id>.L <result>.B (ZC_USE_SKILL2).
  5001. int clif_skill_nodamage(struct block_list *src,struct block_list *dst, uint16 skill_id, int heal, int fail)
  5002. {
  5003. unsigned char buf[17];
  5004. #if PACKETVER < 20130731
  5005. const int cmd = 0x11a;
  5006. #else
  5007. const int cmd = 0x9cb;
  5008. #endif
  5009. int offset = 0;
  5010. nullpo_ret(dst);
  5011. WBUFW(buf,0) = cmd;
  5012. WBUFW(buf,2) = skill_id;
  5013. #if PACKETVER < 20130731
  5014. WBUFW(buf,4) = min(heal, INT16_MAX);
  5015. #else
  5016. WBUFL(buf,4) = min(heal, INT32_MAX);
  5017. offset += 2;
  5018. #endif
  5019. WBUFL(buf,6+offset) = dst->id;
  5020. WBUFL(buf,10+offset) = src ? src->id : 0;
  5021. WBUFB(buf,14+offset) = fail;
  5022. if (disguised(dst)) {
  5023. clif_send(buf, packet_len(cmd), dst, AREA_WOS);
  5024. WBUFL(buf,6+offset) = -dst->id;
  5025. clif_send(buf, packet_len(cmd), dst, SELF);
  5026. } else
  5027. clif_send(buf, packet_len(cmd), dst, AREA);
  5028. if(src && disguised(src)) {
  5029. WBUFL(buf,10+offset) = -src->id;
  5030. if (disguised(dst))
  5031. WBUFL(buf,6+offset) = dst->id;
  5032. clif_send(buf, packet_len(cmd), src, SELF);
  5033. }
  5034. return fail;
  5035. }
  5036. /// Non-damaging ground skill effect (ZC_NOTIFY_GROUNDSKILL).
  5037. /// 0117 <skill id>.W <src id>.L <level>.W <x>.W <y>.W <tick>.L
  5038. void clif_skill_poseffect(struct block_list *src,uint16 skill_id,int val,int x,int y,int tick)
  5039. {
  5040. unsigned char buf[32];
  5041. nullpo_retv(src);
  5042. WBUFW(buf,0)=0x117;
  5043. WBUFW(buf,2)=skill_id;
  5044. WBUFL(buf,4)=src->id;
  5045. WBUFW(buf,8)=val;
  5046. WBUFW(buf,10)=x;
  5047. WBUFW(buf,12)=y;
  5048. WBUFL(buf,14)=tick;
  5049. if(disguised(src)) {
  5050. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  5051. WBUFL(buf,4)=-src->id;
  5052. clif_send(buf,packet_len(0x117),src,SELF);
  5053. } else
  5054. clif_send(buf,packet_len(0x117),src,AREA);
  5055. }
  5056. /// Presents a list of available warp destinations (ZC_WARPLIST).
  5057. /// 011c <skill id>.W { <map name>.16B }*4
  5058. 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)
  5059. {
  5060. int fd;
  5061. nullpo_retv(sd);
  5062. fd = sd->fd;
  5063. WFIFOHEAD(fd,packet_len(0x11c));
  5064. WFIFOW(fd,0) = 0x11c;
  5065. WFIFOW(fd,2) = skill_id;
  5066. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  5067. if (map1 == (unsigned short)-1) strcpy(WFIFOCP(fd,4), "Random");
  5068. else // normal map name
  5069. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), WFIFOCP(fd,4));
  5070. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), WFIFOCP(fd,20));
  5071. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), WFIFOCP(fd,36));
  5072. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), WFIFOCP(fd,52));
  5073. WFIFOSET(fd,packet_len(0x11c));
  5074. sd->menuskill_id = skill_id;
  5075. if (skill_id == AL_WARP) {
  5076. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  5077. sd->state.workinprogress = WIP_DISABLE_ALL;
  5078. } else
  5079. sd->menuskill_val = skill_lv;
  5080. }
  5081. /// Memo message (ZC_ACK_REMEMBER_WARPPOINT).
  5082. /// 011e <type>.B
  5083. /// type:
  5084. /// 0 = "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  5085. /// 1 = "Skill Level is not high enough." in color 0x0000FF (red)
  5086. /// 2 = "You haven't learned Warp." in color 0x0000FF (red)
  5087. ///
  5088. /// @param sd Who receives the message
  5089. /// @param type What message
  5090. void clif_skill_memomessage(struct map_session_data* sd, int type)
  5091. {
  5092. int fd;
  5093. nullpo_retv(sd);
  5094. fd=sd->fd;
  5095. WFIFOHEAD(fd,packet_len(0x11e));
  5096. WFIFOW(fd,0)=0x11e;
  5097. WFIFOB(fd,2)=type;
  5098. WFIFOSET(fd,packet_len(0x11e));
  5099. }
  5100. /// Teleport message (ZC_NOTIFY_MAPINFO).
  5101. /// 0189 <type>.W
  5102. /// type:
  5103. /// 0 = "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  5104. /// 1 = "Saved point cannot be memorized." in color 0x0000FF (red)
  5105. ///
  5106. /// @param sd Who receives the message
  5107. /// @param type What message
  5108. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  5109. {
  5110. int fd;
  5111. nullpo_retv(sd);
  5112. fd=sd->fd;
  5113. WFIFOHEAD(fd,packet_len(0x189));
  5114. WFIFOW(fd,0)=0x189;
  5115. WFIFOW(fd,2)=type;
  5116. WFIFOSET(fd,packet_len(0x189));
  5117. }
  5118. /// Displays Sense (WZ_ESTIMATION) information window (ZC_MONSTER_INFO).
  5119. /// 018c <class>.W <level>.W <size>.W <hp>.L <def>.W <race>.W <mdef>.W <element>.W
  5120. /// <water%>.B <earth%>.B <fire%>.B <wind%>.B <poison%>.B <holy%>.B <shadow%>.B <ghost%>.B <undead%>.B
  5121. void clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  5122. {
  5123. struct status_data *status;
  5124. unsigned char buf[64];
  5125. int i;//, fix;
  5126. nullpo_retv(sd);
  5127. nullpo_retv(dst);
  5128. if( dst->type != BL_MOB )
  5129. return;
  5130. status = status_get_status_data(dst);
  5131. WBUFW(buf, 0)=0x18c;
  5132. WBUFW(buf, 2)=status_get_class(dst);
  5133. WBUFW(buf, 4)=status_get_lv(dst);
  5134. WBUFW(buf, 6)=status->size;
  5135. WBUFL(buf, 8)=status->hp;
  5136. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  5137. +(battle_config.estimation_type&2?status->def2:0);
  5138. WBUFW(buf,14)=status->race;
  5139. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  5140. +(battle_config.estimation_type&2?status->mdef2:0);
  5141. WBUFW(buf,18)= status->def_ele;
  5142. for(i=0;i<9;i++)
  5143. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  5144. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  5145. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  5146. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  5147. }
  5148. /// Presents a textual list of producable items (ZC_MAKABLEITEMLIST).
  5149. /// 018d <packet len>.W { <name id>.W { <material id>.W }*3 }*
  5150. /// material id:
  5151. /// unused by the client
  5152. void clif_skill_produce_mix_list(struct map_session_data *sd, int skill_id , int trigger)
  5153. {
  5154. int i,c,view,fd;
  5155. nullpo_retv(sd);
  5156. if (sd->menuskill_id == skill_id)
  5157. return; //Avoid resending the menu twice or more times...
  5158. if (skill_id == GC_CREATENEWPOISON)
  5159. skill_id = GC_RESEARCHNEWPOISON;
  5160. fd = sd->fd;
  5161. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  5162. WFIFOW(fd, 0) = 0x18d;
  5163. for (i = 0, c = 0; i < MAX_SKILL_PRODUCE_DB; i++){
  5164. if (skill_can_produce_mix(sd,skill_produce_db[i].nameid, trigger, 1) &&
  5165. (skill_id <= 0 || (skill_id > 0 && skill_produce_db[i].req_skill == skill_id))
  5166. )
  5167. {
  5168. if ((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  5169. WFIFOW(fd,c*8+ 4) = view;
  5170. else
  5171. WFIFOW(fd,c*8+ 4) = skill_produce_db[i].nameid;
  5172. WFIFOW(fd,c*8+ 6) = 0;
  5173. WFIFOW(fd,c*8+ 8) = 0;
  5174. WFIFOW(fd,c*8+10) = 0;
  5175. c++;
  5176. }
  5177. }
  5178. WFIFOW(fd, 2) = c*8+8;
  5179. WFIFOSET(fd,WFIFOW(fd,2));
  5180. if (c > 0) {
  5181. sd->menuskill_id = skill_id;
  5182. sd->menuskill_val = trigger;
  5183. return;
  5184. }
  5185. }
  5186. /// Present a list of producable items (ZC_MAKINGITEM_LIST).
  5187. /// 025a <packet len>.W <mk type>.W { <name id>.W }*
  5188. /// mk type:
  5189. /// 1 = cooking
  5190. /// 2 = arrow
  5191. /// 3 = elemental
  5192. /// 4 = GN_MIX_COOKING
  5193. /// 5 = GN_MAKEBOMB
  5194. /// 6 = GN_S_PHARMACY
  5195. void clif_cooking_list(struct map_session_data *sd, int trigger, uint16 skill_id, int qty, int list_type)
  5196. {
  5197. int fd;
  5198. int i, c;
  5199. int view;
  5200. nullpo_retv(sd);
  5201. fd = sd->fd;
  5202. if(sd->menuskill_id == skill_id)
  5203. return; //Avoid resending the menu twice or more times...
  5204. WFIFOHEAD(fd, 6 + 2 * MAX_SKILL_PRODUCE_DB);
  5205. WFIFOW(fd,0) = 0x25a;
  5206. WFIFOW(fd,4) = list_type; // list type
  5207. c = 0;
  5208. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ ) {
  5209. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, qty) )
  5210. continue;
  5211. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  5212. WFIFOW(fd, 6 + 2 * c) = view;
  5213. else
  5214. WFIFOW(fd, 6 + 2 * c) = skill_produce_db[i].nameid;
  5215. c++;
  5216. }
  5217. if( c > 0 || skill_id == AM_PHARMACY) {
  5218. sd->menuskill_id = skill_id;
  5219. sd->menuskill_val = trigger;
  5220. sd->menuskill_val2 = qty; // amount.
  5221. WFIFOW(fd,2) = 6 + 2 * c;
  5222. WFIFOSET(fd,WFIFOW(fd,2));
  5223. } else {
  5224. clif_menuskill_clear(sd);
  5225. #if PACKETVER >= 20090922
  5226. clif_msg_skill(sd,skill_id,INVENTORY_SPACE_FULL);
  5227. #else
  5228. WFIFOW(fd,2) = 6 + 2 * c;
  5229. WFIFOSET(fd,WFIFOW(fd,2));
  5230. #endif
  5231. }
  5232. }
  5233. /// Notifies clients of a status change.
  5234. /// 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)]
  5235. /// 043f <index>.W <id>.L <state>.B <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE2) [used exclusively for starting statuses on pcs]
  5236. /// 0983 <index>.W <id>.L <state>.B <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_MSG_STATE_CHANGE3) (PACKETVER >= 20120618)
  5237. /// @param bl Sends packet to clients around this object
  5238. /// @param id ID of object that has this effect
  5239. /// @param type Status icon see enum efst_types
  5240. /// @param flag 1:Active, 0:Deactive
  5241. /// @param tick Duration in ms
  5242. /// @param val1
  5243. /// @param val2
  5244. /// @param val3
  5245. 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)
  5246. {
  5247. unsigned char buf[32];
  5248. if (type == EFST_BLANK) //It shows nothing on the client...
  5249. return;
  5250. if (type == EFST_POSTDELAY && tick == 0)
  5251. return;
  5252. nullpo_retv(bl);
  5253. #if PACKETVER >= 20120618
  5254. if (flag && battle_config.display_status_timers)
  5255. WBUFW(buf,0) = 0x983;
  5256. else
  5257. #elif PACKETVER >= 20090121
  5258. if (flag && battle_config.display_status_timers)
  5259. WBUFW(buf,0) = 0x43f;
  5260. else
  5261. #endif
  5262. WBUFW(buf,0) = 0x196;
  5263. WBUFW(buf,2) = type;
  5264. WBUFL(buf,4) = id;
  5265. WBUFB(buf,8) = flag;
  5266. #if PACKETVER >= 20120618
  5267. if (flag && battle_config.display_status_timers) {
  5268. if (tick <= 0)
  5269. tick = 9999; // this is indeed what official servers do
  5270. WBUFL(buf,9) = tick;/* at this stage remain and total are the same value I believe */
  5271. WBUFL(buf,13) = tick;
  5272. WBUFL(buf,17) = val1;
  5273. WBUFL(buf,21) = val2;
  5274. WBUFL(buf,25) = val3;
  5275. }
  5276. #elif PACKETVER >= 20090121
  5277. if (flag && battle_config.display_status_timers) {
  5278. if (tick <= 0)
  5279. tick = 9999; // this is indeed what official servers do
  5280. WBUFL(buf,9) = tick;
  5281. WBUFL(buf,13) = val1;
  5282. WBUFL(buf,17) = val2;
  5283. WBUFL(buf,21) = val3;
  5284. }
  5285. #endif
  5286. clif_send(buf, packet_len(WBUFW(buf,0)), bl, target_type);
  5287. }
  5288. /* Sends status effect to clients around the bl
  5289. * @param bl Object that has the effect
  5290. * @param type Status icon see enum efst_types
  5291. * @param flag 1:Active, 0:Deactive
  5292. * @param tick Duration in ms
  5293. * @param val1
  5294. * @param val2
  5295. * @param val3
  5296. */
  5297. void clif_status_change(struct block_list *bl, int type, int flag, int tick, int val1, int val2, int val3) {
  5298. struct map_session_data *sd = NULL;
  5299. if (type == EFST_BLANK) //It shows nothing on the client...
  5300. return;
  5301. if (type == EFST_POSTDELAY && tick == 0)
  5302. return;
  5303. if (type == EFST_ILLUSION && !battle_config.display_hallucination) // Disable Hallucination.
  5304. return;
  5305. nullpo_retv(bl);
  5306. sd = BL_CAST(BL_PC, bl);
  5307. if (!(status_type2relevant_bl_types(type)&bl->type)) // only send status changes that actually matter to the client
  5308. return;
  5309. clif_status_change_sub(bl, bl->id, type, flag, tick, val1, val2, val3, ((sd ? (pc_isinvisible(sd) ? SELF : AREA) : AREA_WOS)));
  5310. }
  5311. /**
  5312. * Send any active EFST to those around.
  5313. * @param tbl: Unit to send the packet to
  5314. * @param bl: Objects walking into view
  5315. * @param target: Client send type
  5316. */
  5317. void clif_efst_status_change_sub(struct block_list *tbl, struct block_list *bl, enum send_target target) {
  5318. unsigned char i;
  5319. struct sc_display_entry **sc_display;
  5320. unsigned char sc_display_count;
  5321. bool spheres_sent;
  5322. nullpo_retv(bl);
  5323. switch( bl->type ){
  5324. case BL_PC: {
  5325. struct map_session_data* sd = (struct map_session_data*)bl;
  5326. sc_display = sd->sc_display;
  5327. sc_display_count = sd->sc_display_count;
  5328. spheres_sent = !sd->state.connect_new;
  5329. }
  5330. break;
  5331. case BL_NPC: {
  5332. struct npc_data* nd = (struct npc_data*)bl;
  5333. sc_display = nd->sc_display;
  5334. sc_display_count = nd->sc_display_count;
  5335. spheres_sent = true;
  5336. }
  5337. break;
  5338. default:
  5339. return;
  5340. }
  5341. for (i = 0; i < sc_display_count; i++) {
  5342. enum sc_type type = sc_display[i]->type;
  5343. struct status_change *sc = status_get_sc(bl);
  5344. const struct TimerData *td = (sc && sc->data[type] ? get_timer(sc->data[type]->timer) : NULL);
  5345. int tick = 0;
  5346. if (td)
  5347. tick = DIFF_TICK(td->tick, gettick());
  5348. if( spheres_sent && type >= SC_SPHERE_1 && type <= SC_SPHERE_5 ){
  5349. #if PACKETVER > 20120418
  5350. clif_efst_status_change(tbl, bl->id, AREA_WOS, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5351. #else
  5352. 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);
  5353. #endif
  5354. }else{
  5355. #if PACKETVER > 20120418
  5356. clif_efst_status_change(tbl, bl->id, target, StatusIconChangeTable[type], tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3);
  5357. #else
  5358. clif_status_change_sub(tbl, bl->id, StatusIconChangeTable[type], 1, tick, sc_display[i]->val1, sc_display[i]->val2, sc_display[i]->val3, target);
  5359. #endif
  5360. }
  5361. }
  5362. }
  5363. /// Notifies the client when a player enters the screen with an active EFST.
  5364. /// 08ff <id>.L <index>.W <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER) (PACKETVER >= 20111108)
  5365. /// 0984 <id>.L <index>.W <total msec>.L <remain msec>.L { <val>.L }*3 (ZC_EFST_SET_ENTER2) (PACKETVER >= 20120618)
  5366. 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) {
  5367. #if PACKETVER >= 20111108
  5368. unsigned char buf[32];
  5369. #if PACKETVER >= 20120618
  5370. const int cmd = 0x984;
  5371. #elif PACKETVER >= 20111108
  5372. const int cmd = 0x8ff;
  5373. #endif
  5374. int offset = 0;
  5375. if (type == EFST_BLANK)
  5376. return;
  5377. nullpo_retv(bl);
  5378. if (tick <= 0)
  5379. tick = 9999;
  5380. WBUFW(buf,offset + 0) = cmd;
  5381. WBUFL(buf,offset + 2) = tid;
  5382. WBUFW(buf,offset + 6) = type;
  5383. #if PACKETVER >= 20111108
  5384. WBUFL(buf,offset + 8) = tick; // Set remaining status duration [exneval]
  5385. #if PACKETVER >= 20120618
  5386. WBUFL(buf,offset + 12) = tick;
  5387. offset += 4;
  5388. #endif
  5389. WBUFL(buf,offset + 12) = val1;
  5390. WBUFL(buf,offset + 16) = val2;
  5391. WBUFL(buf,offset + 20) = val3;
  5392. #endif
  5393. clif_send(buf,packet_len(cmd),bl,target);
  5394. #endif
  5395. }
  5396. /// Send message (modified by [Yor]) (ZC_NOTIFY_PLAYERCHAT).
  5397. /// 008e <packet len>.W <message>.?B
  5398. void clif_displaymessage(const int fd, const char* mes)
  5399. {
  5400. nullpo_retv(mes);
  5401. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  5402. if (fd == 0)
  5403. ;
  5404. else {
  5405. char *message, *line;
  5406. message = aStrdup(mes);
  5407. line = strtok(message, "\n");
  5408. #if PACKETVER == 20141022
  5409. /** for some reason game client crashes depending on message pattern (only for this packet) **/
  5410. /** so we redirect to ZC_NPC_CHAT **/
  5411. //clif_messagecolor(&sd->bl, color_table[COLOR_DEFAULT], mes, false, SELF);
  5412. while(line != NULL) {
  5413. unsigned long color = (color_table[COLOR_DEFAULT] & 0x0000FF) << 16 | (color_table[COLOR_DEFAULT] & 0x00FF00) | (color_table[COLOR_DEFAULT] & 0xFF0000) >> 16; // RGB to BGR
  5414. unsigned short len = strnlen(line, CHAT_SIZE_MAX);
  5415. if (len > 0) {
  5416. WFIFOHEAD(fd, 13 + len);
  5417. WFIFOW(fd, 0) = 0x2C1;
  5418. WFIFOW(fd, 2) = 13 + len;
  5419. WFIFOL(fd, 4) = 0;
  5420. WFIFOL(fd, 8) = color;
  5421. safestrncpy(WFIFOCP(fd, 12), line, len + 1);
  5422. WFIFOSET(fd, WFIFOW(fd, 2));
  5423. }
  5424. #else
  5425. while(line != NULL) {
  5426. // Limit message to 255+1 characters (otherwise it causes a buffer overflow in the client)
  5427. int len = strnlen(line, CHAT_SIZE_MAX);
  5428. if (len > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  5429. WFIFOHEAD(fd, 5 + len);
  5430. WFIFOW(fd,0) = 0x8e;
  5431. WFIFOW(fd,2) = 5 + len; // 4 + len + NULL teminate
  5432. safestrncpy(WFIFOCP(fd,4), line, len + 1);
  5433. WFIFOSET(fd, 5 + len);
  5434. }
  5435. #endif
  5436. line = strtok(NULL, "\n");
  5437. }
  5438. aFree(message);
  5439. }
  5440. }
  5441. /// Send broadcast message in yellow or blue without font formatting (ZC_BROADCAST).
  5442. /// 009a <packet len>.W <message>.?B
  5443. void clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  5444. {
  5445. int lp = (type&BC_COLOR_MASK) ? 4 : 0;
  5446. std::unique_ptr<unsigned char> buf(new unsigned char[4+lp+len]);
  5447. WBUFW(buf.get(),0) = 0x9a;
  5448. WBUFW(buf.get(),2) = 4 + lp + len;
  5449. if (type&BC_BLUE)
  5450. 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.
  5451. else if (type&BC_WOE)
  5452. WBUFL(buf.get(),4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  5453. memcpy(WBUFP(buf.get(), 4 + lp), mes, len);
  5454. clif_send(buf.get(), WBUFW(buf.get(),2), bl, target);
  5455. }
  5456. /*==========================================
  5457. * Displays a message on a 'bl' to all it's nearby clients
  5458. * 008d <PacketLength>.W <GID>.L <message>.?B (ZC_NOTIFY_CHAT)
  5459. *------------------------------------------*/
  5460. void clif_GlobalMessage(struct block_list* bl, const char* message, enum send_target target) {
  5461. size_t len;
  5462. nullpo_retv(bl);
  5463. if(!message)
  5464. return;
  5465. len = strlen(message)+1;
  5466. static_assert(CHAT_SIZE_MAX > 8, "CHAT_SIZE_MAX too small for packet");
  5467. if( len > CHAT_SIZE_MAX ) {
  5468. ShowWarning("clif_GlobalMessage: Truncating too long message '%s' (len=%d).\n", message, len);
  5469. len = CHAT_SIZE_MAX;
  5470. }
  5471. std::unique_ptr<char> buf(new char[8+len]);
  5472. WBUFW(buf.get(),0)=0x8d;
  5473. WBUFW(buf.get(),2)=static_cast<uint16>(len+8);
  5474. WBUFL(buf.get(),4)=bl->id;
  5475. safestrncpy(WBUFCP(buf.get(),8),message,len);
  5476. clif_send((unsigned char *)buf.get(),WBUFW(buf.get(),2),bl,target);
  5477. }
  5478. /// Send broadcast message with font formatting (ZC_BROADCAST2).
  5479. /// 01c3 <packet len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  5480. 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)
  5481. {
  5482. std::unique_ptr<unsigned char> buf(new unsigned char[16+len]);
  5483. WBUFW(buf.get(),0) = 0x1c3;
  5484. WBUFW(buf.get(),2) = len + 16;
  5485. WBUFL(buf.get(),4) = fontColor;
  5486. WBUFW(buf.get(),8) = fontType;
  5487. WBUFW(buf.get(),10) = fontSize;
  5488. WBUFW(buf.get(),12) = fontAlign;
  5489. WBUFW(buf.get(),14) = fontY;
  5490. memcpy(WBUFP(buf.get(),16), mes, len);
  5491. clif_send(buf.get(), WBUFW(buf.get(),2), bl, target);
  5492. }
  5493. /*
  5494. * Display *msg to all *users in channel
  5495. */
  5496. void clif_channel_msg(struct Channel *channel, const char *msg, unsigned long color) {
  5497. DBIterator *iter;
  5498. struct map_session_data *user;
  5499. unsigned short msg_len = 0, len = 0;
  5500. unsigned char buf[CHAT_SIZE_MAX];
  5501. if (!channel || !msg)
  5502. return;
  5503. msg_len = (unsigned short)(strlen(msg) + 1);
  5504. if( msg_len > sizeof(buf)-12 ) {
  5505. ShowWarning("clif_channel_msg: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  5506. msg_len = sizeof(buf)-12;
  5507. }
  5508. WBUFW(buf,0) = 0x2C1;
  5509. WBUFW(buf,2) = (len = msg_len + 12);
  5510. WBUFL(buf,4) = 0;
  5511. WBUFL(buf,8) = color;
  5512. safestrncpy(WBUFCP(buf,12), msg, msg_len);
  5513. iter = db_iterator(channel->users);
  5514. for( user = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); user = (struct map_session_data *)dbi_next(iter) ) {
  5515. clif_send(buf, len, &user->bl, SELF);
  5516. }
  5517. dbi_destroy(iter);
  5518. }
  5519. /// Displays heal effect.
  5520. /// 013d <var id>.W <amount>.W (ZC_RECOVERY)
  5521. /// 0a27 <var id>.W <amount>.L (ZC_RECOVERY2)
  5522. /// var id:
  5523. /// 5 = HP (SP_HP)
  5524. /// 7 = SP (SP_SP)
  5525. /// ? = ignored
  5526. void clif_heal(int fd,int type,int val) {
  5527. #if PACKETVER < 20141022
  5528. const int cmd = 0x13d;
  5529. #else
  5530. const int cmd = 0xa27;
  5531. #endif
  5532. WFIFOHEAD(fd, packet_len(cmd));
  5533. WFIFOW(fd,0) = cmd;
  5534. WFIFOW(fd,2) = type;
  5535. #if PACKETVER < 20141022
  5536. WFIFOW(fd,4) = min(val, INT16_MAX);
  5537. #else
  5538. WFIFOL(fd,4) = min(val, INT32_MAX);
  5539. #endif
  5540. WFIFOSET(fd, packet_len(cmd));
  5541. }
  5542. /// Displays resurrection effect (ZC_RESURRECTION).
  5543. /// 0148 <id>.L <type>.W
  5544. /// type:
  5545. /// ignored
  5546. void clif_resurrection(struct block_list *bl,int type)
  5547. {
  5548. unsigned char buf[16];
  5549. nullpo_retv(bl);
  5550. WBUFW(buf,0)=0x148;
  5551. WBUFL(buf,2)=bl->id;
  5552. WBUFW(buf,6)=0;
  5553. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  5554. if (disguised(bl))
  5555. clif_spawn(bl);
  5556. }
  5557. /// Sets the map property
  5558. /// 0199 <type>.W (ZC_NOTIFY_MAPPROPERTY)
  5559. /// 099b <type>.W <flags>.L (ZC_MAPPROPERTY_R2)
  5560. void clif_map_property(struct block_list *bl, enum map_property property, enum send_target t)
  5561. {
  5562. #if PACKETVER >= 20121010
  5563. short cmd = 0x99b;
  5564. unsigned char buf[8];
  5565. #else
  5566. short cmd = 0x199;
  5567. unsigned char buf[4];
  5568. #endif
  5569. WBUFW(buf,0)=cmd;
  5570. WBUFW(buf,2)=property;
  5571. #if PACKETVER >= 20121010
  5572. WBUFL(buf,4) = ((map[bl->m].flag.pvp?1:0)<<0)| // PARTY - Show attack cursor on non-party members (PvP)
  5573. ((map[bl->m].flag.battleground || map_flag_gvg2(bl->m)?1:0)<<1)|// GUILD - Show attack cursor on non-guild members (GvG)
  5574. ((map[bl->m].flag.battleground || map_flag_gvg2(bl->m)?1:0)<<2)|// SIEGE - Show emblem over characters heads when in GvG (WoE castle)
  5575. ((map[bl->m].flag.nomineeffect || !map_flag_gvg2(bl->m)?0:1)<<3)| // USE_SIMPLE_EFFECT - Automatically enable /mineffect
  5576. ((map[bl->m].flag.nolockon || map_flag_vs(bl->m)?1:0)<<4)| // DISABLE_LOCKON - Only allow attacks on other players with shift key or /ns active
  5577. ((map[bl->m].flag.pvp?1:0)<<5)| // COUNT_PK - Show the PvP counter
  5578. ((map[bl->m].flag.partylock?1:0)<<6)| // NO_PARTY_FORMATION - Prevents party creation/modification (Might be used for instance dungeons)
  5579. ((map[bl->m].flag.battleground?1:0)<<7)| // BATTLEFIELD - Unknown (Does something for battlegrounds areas)
  5580. ((map[bl->m].flag.nocostume?1:0)<<8)| // DISABLE_COSTUMEITEM - Disable costume sprites
  5581. ((map[bl->m].flag.nousecart?0:1)<<9)| // USECART - Allow opening cart inventory (Well force it to always allow it)
  5582. ((map[bl->m].flag.nosumstarmiracle?0:1)<<10); // SUNMOONSTAR_MIRACLE - Unknown - (Guessing it blocks Star Gladiator's Miracle from activating)
  5583. //(1<<11); // Unused bits. 1 - 10 is 0x1 length and 11 is 0x15 length. May be used for future settings.
  5584. #endif
  5585. clif_send(buf,packet_len(cmd),bl,t);
  5586. }
  5587. /// Set the map type (ZC_NOTIFY_MAPPROPERTY2).
  5588. /// 01d6 <type>.W
  5589. void clif_map_type(struct map_session_data* sd, enum map_type type)
  5590. {
  5591. int fd;
  5592. nullpo_retv(sd);
  5593. fd=sd->fd;
  5594. WFIFOHEAD(fd,packet_len(0x1D6));
  5595. WFIFOW(fd,0)=0x1D6;
  5596. WFIFOW(fd,2)=type;
  5597. WFIFOSET(fd,packet_len(0x1D6));
  5598. }
  5599. /// Updates PvP ranking (ZC_NOTIFY_RANKING).
  5600. /// 019a <id>.L <ranking>.L <total>.L
  5601. void clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  5602. {
  5603. if(type == 2) {
  5604. int fd = sd->fd;
  5605. WFIFOHEAD(fd,packet_len(0x19a));
  5606. WFIFOW(fd,0) = 0x19a;
  5607. WFIFOL(fd,2) = sd->bl.id;
  5608. WFIFOL(fd,6) = pvprank;
  5609. WFIFOL(fd,10) = pvpnum;
  5610. WFIFOSET(fd,packet_len(0x19a));
  5611. } else {
  5612. unsigned char buf[32];
  5613. WBUFW(buf,0) = 0x19a;
  5614. WBUFL(buf,2) = sd->bl.id;
  5615. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  5616. WBUFL(buf,6) = UINT32_MAX; //On client displays as --
  5617. else
  5618. WBUFL(buf,6) = pvprank;
  5619. WBUFL(buf,10) = pvpnum;
  5620. if(pc_isinvisible(sd) || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  5621. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  5622. else if(!type)
  5623. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  5624. else
  5625. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  5626. }
  5627. }
  5628. /*==========================================
  5629. *
  5630. *------------------------------------------*/
  5631. void clif_map_property_mapall(int map_idx, enum map_property property)
  5632. {
  5633. struct block_list bl;
  5634. bl.id = 0;
  5635. bl.type = BL_NUL;
  5636. bl.m = map_idx;
  5637. clif_map_property( &bl, property, ALL_SAMEMAP );
  5638. }
  5639. /// Notifies the client about the result of a refine attempt (ZC_ACK_ITEMREFINING).
  5640. /// 0188 <result>.W <index>.W <refine>.W
  5641. /// result:
  5642. /// 0 = success
  5643. /// 1 = failure
  5644. /// 2 = downgrade
  5645. void clif_refine(int fd, int fail, int index, int val)
  5646. {
  5647. WFIFOHEAD(fd,packet_len(0x188));
  5648. WFIFOW(fd,0)=0x188;
  5649. WFIFOW(fd,2)=fail;
  5650. WFIFOW(fd,4)=index+2;
  5651. WFIFOW(fd,6)=val;
  5652. WFIFOSET(fd,packet_len(0x188));
  5653. }
  5654. /// Notifies the client about the result of a weapon refine attempt (ZC_ACK_WEAPONREFINE).
  5655. /// 0223 <result>.L <nameid>.W
  5656. /// result:
  5657. /// 0 = "weapon upgraded: %s" MsgStringTable[911] in rgb(0,255,255)
  5658. /// 1 = "weapon upgraded: %s" MsgStringTable[912] in rgb(0,205,205)
  5659. /// 2 = "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  5660. /// 3 = "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  5661. void clif_upgrademessage(int fd, int result, unsigned short item_id)
  5662. {
  5663. WFIFOHEAD(fd,packet_len(0x223));
  5664. WFIFOW(fd,0)=0x223;
  5665. WFIFOL(fd,2)=result;
  5666. WFIFOW(fd,6)=item_id;
  5667. WFIFOSET(fd,packet_len(0x223));
  5668. }
  5669. /// Whisper is transmitted to the destination player (ZC_WHISPER).
  5670. /// 0097 <packet len>.W <nick>.24B <message>.?B
  5671. /// 0097 <packet len>.W <nick>.24B <isAdmin>.L <message>.?B (PACKETVER >= 20091104)
  5672. void clif_wis_message(struct map_session_data* sd, const char* nick, const char* mes, int mes_len, int gmlvl){
  5673. int fd;
  5674. nullpo_retv(sd);
  5675. fd = sd->fd;
  5676. #if PACKETVER < 20091104
  5677. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  5678. WFIFOW(fd,0) = 0x97;
  5679. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  5680. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5681. safestrncpy(WFIFOCP(fd,28), mes, mes_len);
  5682. WFIFOSET(fd,WFIFOW(fd,2));
  5683. #else
  5684. struct map_session_data *ssd = map_nick2sd(nick,false);
  5685. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  5686. WFIFOW(fd,0) = 0x97;
  5687. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  5688. safestrncpy(WFIFOCP(fd,4), nick, NAME_LENGTH);
  5689. // If it is not a message from the server or a player from another map-server
  5690. if( ssd ){
  5691. gmlvl = pc_get_group_level(ssd);
  5692. }
  5693. WFIFOL(fd, 28) = (gmlvl == 99) ? 1 : 0; // isAdmin; if nonzero, also displays text above char
  5694. safestrncpy(WFIFOCP(fd,32), mes, mes_len);
  5695. WFIFOSET(fd,WFIFOW(fd,2));
  5696. #endif
  5697. }
  5698. /// Inform the player about the result of his whisper action
  5699. /// 0098 <result>.B (ZC_ACK_WHISPER).
  5700. /// 09df <result>.B <GID>.L (ZC_ACK_WHISPER02).
  5701. /// result:
  5702. /// 0 = success to send wisper
  5703. /// 1 = target character is not loged in
  5704. /// 2 = ignored by target
  5705. /// 3 = everyone ignored by target
  5706. void clif_wis_end(int fd, int result)
  5707. {
  5708. struct map_session_data *sd = (session_isValid(fd) ? (struct map_session_data *)session[fd]->session_data : NULL);
  5709. #if PACKETVER < 20131223
  5710. const int cmd = 0x98;
  5711. #else
  5712. const int cmd = 0x9df;
  5713. #endif
  5714. if (!sd)
  5715. return;
  5716. WFIFOHEAD(fd,packet_len(cmd));
  5717. WFIFOW(fd,0) = cmd;
  5718. WFIFOB(fd,2) = (char)result;
  5719. #if PACKETVER >= 20131223
  5720. WFIFOL(fd,3) = sd->status.char_id; // GID/CCODE
  5721. #endif
  5722. WFIFOSET(fd,packet_len(cmd));
  5723. }
  5724. /// Returns character name requested by char_id (ZC_ACK_REQNAME_BYGID).
  5725. /// 0194 <char id>.L <name>.24B
  5726. /// 0af7 <flag>.W <char id>.L <name>.24B
  5727. void clif_solved_charname(int fd, int charid, const char* name)
  5728. {
  5729. #if PACKETVER >= 20180221
  5730. WFIFOHEAD(fd,packet_len(0xaf7));
  5731. WFIFOW(fd,0) = 0xaf7;
  5732. WFIFOW(fd,2) = name[0] ? 3 : 2;
  5733. WFIFOL(fd,4) = charid;
  5734. safestrncpy(WFIFOCP(fd, 8), name, NAME_LENGTH);
  5735. WFIFOSET(fd,packet_len(0x0af7));
  5736. #else
  5737. WFIFOHEAD(fd,packet_len(0x194));
  5738. WFIFOW(fd,0)=0x194;
  5739. WFIFOL(fd,2)=charid;
  5740. safestrncpy(WFIFOCP(fd,6), name, NAME_LENGTH);
  5741. WFIFOSET(fd,packet_len(0x194));
  5742. #endif
  5743. }
  5744. /// Presents a list of items that can be carded/composed (ZC_ITEMCOMPOSITION_LIST).
  5745. /// 017b <packet len>.W { <name id>.W }*
  5746. void clif_use_card(struct map_session_data *sd,int idx)
  5747. {
  5748. int i,c,ep;
  5749. int fd=sd->fd;
  5750. nullpo_retv(sd);
  5751. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  5752. return;
  5753. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  5754. return; //Avoid parsing invalid item indexes (no card/no item)
  5755. ep=sd->inventory_data[idx]->equip;
  5756. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5757. WFIFOW(fd,0)=0x17b;
  5758. for(i=c=0;i<MAX_INVENTORY;i++){
  5759. int j;
  5760. if(sd->inventory_data[i] == NULL)
  5761. continue;
  5762. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  5763. continue;
  5764. if(itemdb_isspecial(sd->inventory.u.items_inventory[i].card[0])) //Can't slot it
  5765. continue;
  5766. if(sd->inventory.u.items_inventory[i].identify==0 ) //Not identified
  5767. continue;
  5768. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  5769. continue;
  5770. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  5771. continue;
  5772. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->inventory.u.items_inventory[i].card[j] == 0 );
  5773. if( j == sd->inventory_data[i]->slot ) // No room
  5774. continue;
  5775. if( sd->inventory.u.items_inventory[i].equip > 0 ) // Do not check items that are already equipped
  5776. continue;
  5777. WFIFOW(fd,4+c*2)=i+2;
  5778. c++;
  5779. }
  5780. if( !c ) return; // no item is available for card insertion
  5781. WFIFOW(fd,2)=4+c*2;
  5782. WFIFOSET(fd,WFIFOW(fd,2));
  5783. }
  5784. /// Notifies the client about the result of item carding/composition (ZC_ACK_ITEMCOMPOSITION).
  5785. /// 017d <equip index>.W <card index>.W <result>.B
  5786. /// result:
  5787. /// 0 = success
  5788. /// 1 = failure
  5789. void clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  5790. {
  5791. int fd;
  5792. nullpo_retv(sd);
  5793. fd=sd->fd;
  5794. WFIFOHEAD(fd,packet_len(0x17d));
  5795. WFIFOW(fd,0)=0x17d;
  5796. WFIFOW(fd,2)=idx_equip+2;
  5797. WFIFOW(fd,4)=idx_card+2;
  5798. WFIFOB(fd,6)=flag;
  5799. WFIFOSET(fd,packet_len(0x17d));
  5800. }
  5801. /// Presents a list of items that can be identified (ZC_ITEMIDENTIFY_LIST).
  5802. /// 0177 <packet len>.W { <name id>.W }*
  5803. void clif_item_identify_list(struct map_session_data *sd)
  5804. {
  5805. int i,c;
  5806. int fd;
  5807. nullpo_retv(sd);
  5808. fd=sd->fd;
  5809. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  5810. WFIFOW(fd,0)=0x177;
  5811. for(i=c=0;i<MAX_INVENTORY;i++){
  5812. if(sd->inventory.u.items_inventory[i].nameid > 0 && !sd->inventory.u.items_inventory[i].identify){
  5813. WFIFOW(fd,c*2+4)=i+2;
  5814. c++;
  5815. }
  5816. }
  5817. if(c > 0) {
  5818. WFIFOW(fd,2)=c*2+4;
  5819. WFIFOSET(fd,WFIFOW(fd,2));
  5820. sd->menuskill_id = MC_IDENTIFY;
  5821. sd->menuskill_val = c;
  5822. sd->state.workinprogress = WIP_DISABLE_ALL;
  5823. }
  5824. }
  5825. /// Notifies the client about the result of a item identify request (ZC_ACK_ITEMIDENTIFY).
  5826. /// 0179 <index>.W <result>.B
  5827. void clif_item_identified(struct map_session_data *sd,int idx,int flag)
  5828. {
  5829. int fd;
  5830. nullpo_retv(sd);
  5831. fd=sd->fd;
  5832. WFIFOHEAD(fd,packet_len(0x179));
  5833. WFIFOW(fd, 0)=0x179;
  5834. WFIFOW(fd, 2)=idx+2;
  5835. WFIFOB(fd, 4)=flag;
  5836. WFIFOSET(fd,packet_len(0x179));
  5837. }
  5838. /// Presents a list of items that can be repaired (ZC_REPAIRITEMLIST).
  5839. /// 01fc <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5840. void clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd, int lv)
  5841. {
  5842. int i,c;
  5843. int fd;
  5844. nullpo_retv(sd);
  5845. nullpo_retv(dstsd);
  5846. fd=sd->fd;
  5847. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5848. WFIFOW(fd,0)=0x1fc;
  5849. for(i=c=0;i<MAX_INVENTORY;i++){
  5850. unsigned short nameid;
  5851. if((nameid=dstsd->inventory.u.items_inventory[i].nameid) > 0 && dstsd->inventory.u.items_inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  5852. WFIFOW(fd,c*13+4) = i;
  5853. WFIFOW(fd,c*13+6) = nameid;
  5854. WFIFOB(fd,c*13+8) = dstsd->inventory.u.items_inventory[i].refine;
  5855. clif_addcards(WFIFOP(fd,c*13+9), &dstsd->inventory.u.items_inventory[i]);
  5856. c++;
  5857. }
  5858. }
  5859. if(c > 0) {
  5860. WFIFOW(fd,2)=c*13+4;
  5861. WFIFOSET(fd,WFIFOW(fd,2));
  5862. sd->menuskill_id = BS_REPAIRWEAPON;
  5863. sd->menuskill_val = dstsd->bl.id;
  5864. sd->menuskill_val2 = lv;
  5865. }else
  5866. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  5867. }
  5868. /// Notifies the client about the result of a item repair request (ZC_ACK_ITEMREPAIR).
  5869. /// 01fe <index>.W <result>.B
  5870. /// index:
  5871. /// ignored (inventory index)
  5872. /// result:
  5873. /// 0 = Item repair success.
  5874. /// 1 = Item repair failure.
  5875. void clif_item_repaireffect(struct map_session_data *sd,int idx,int flag)
  5876. {
  5877. int fd;
  5878. nullpo_retv(sd);
  5879. fd = sd->fd;
  5880. WFIFOHEAD(fd,packet_len(0x1fe));
  5881. WFIFOW(fd, 0)=0x1fe;
  5882. WFIFOW(fd, 2)=idx+2;
  5883. WFIFOB(fd, 4)=flag;
  5884. WFIFOSET(fd,packet_len(0x1fe));
  5885. }
  5886. /// Displays a message, that an equipment got damaged (ZC_EQUIPITEM_DAMAGED).
  5887. /// 02bb <equip location>.W <account id>.L
  5888. void clif_item_damaged(struct map_session_data* sd, unsigned short position)
  5889. {
  5890. int fd = sd->fd;
  5891. WFIFOHEAD(fd,packet_len(0x2bb));
  5892. WFIFOW(fd,0) = 0x2bb;
  5893. WFIFOW(fd,2) = position;
  5894. WFIFOL(fd,4) = sd->bl.id; // TODO: the packet seems to be sent to other people as well, probably party and/or guild.
  5895. WFIFOSET(fd,packet_len(0x2bb));
  5896. }
  5897. /// Presents a list of weapon items that can be refined [Taken from jAthena] (ZC_NOTIFY_WEAPONITEMLIST).
  5898. /// 0221 <packet len>.W { <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W }*
  5899. void clif_item_refine_list(struct map_session_data *sd)
  5900. {
  5901. int i,c;
  5902. int fd;
  5903. uint16 skill_lv;
  5904. int refine_item[5];
  5905. nullpo_retv(sd);
  5906. skill_lv = pc_checkskill(sd,WS_WEAPONREFINE);
  5907. fd=sd->fd;
  5908. refine_item[0] = -1;
  5909. refine_item[1] = pc_search_inventory(sd,ITEMID_PHRACON);
  5910. refine_item[2] = pc_search_inventory(sd,ITEMID_EMVERETARCON);
  5911. refine_item[3] = refine_item[4] = pc_search_inventory(sd,ITEMID_ORIDECON);
  5912. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  5913. WFIFOW(fd,0) = 0x221;
  5914. for(i = c = 0; i < MAX_INVENTORY; i++) {
  5915. unsigned char wlv;
  5916. if(sd->inventory.u.items_inventory[i].nameid > 0 && sd->inventory.u.items_inventory[i].refine < skill_lv &&
  5917. sd->inventory.u.items_inventory[i].identify && (wlv = itemdb_wlv(sd->inventory.u.items_inventory[i].nameid)) >=1 &&
  5918. refine_item[wlv] != -1 && !(sd->inventory.u.items_inventory[i].equip&EQP_ARMS)){
  5919. WFIFOW(fd,c*13+ 4)=i+2;
  5920. WFIFOW(fd,c*13+ 6) = sd->inventory.u.items_inventory[i].nameid;
  5921. WFIFOB(fd,c*13+ 8) = sd->inventory.u.items_inventory[i].refine;
  5922. clif_addcards(WFIFOP(fd,c*13+9), &sd->inventory.u.items_inventory[i]);
  5923. c++;
  5924. }
  5925. }
  5926. WFIFOW(fd,2)=c*13+4;
  5927. WFIFOSET(fd,WFIFOW(fd,2));
  5928. if (c > 0) {
  5929. sd->menuskill_id = WS_WEAPONREFINE;
  5930. sd->menuskill_val = skill_lv;
  5931. }
  5932. }
  5933. /// Notification of an auto-casted skill (ZC_AUTORUN_SKILL).
  5934. /// 0147 <skill id>.W <type>.L <level>.W <sp cost>.W <atk range>.W <skill name>.24B <upgradable>.B
  5935. void clif_item_skill(struct map_session_data *sd,uint16 skill_id,uint16 skill_lv)
  5936. {
  5937. int fd;
  5938. nullpo_retv(sd);
  5939. fd=sd->fd;
  5940. WFIFOHEAD(fd,packet_len(0x147));
  5941. WFIFOW(fd, 0)=0x147;
  5942. WFIFOW(fd, 2)=skill_id;
  5943. WFIFOW(fd, 4)=skill_get_inf(skill_id);
  5944. WFIFOW(fd, 6)=0;
  5945. WFIFOW(fd, 8)=skill_lv;
  5946. WFIFOW(fd,10)=skill_get_sp(skill_id,skill_lv);
  5947. WFIFOW(fd,12)=skill_get_range2(&sd->bl,skill_id,skill_lv,false);
  5948. safestrncpy(WFIFOCP(fd,14),skill_get_name(skill_id),NAME_LENGTH);
  5949. WFIFOB(fd,38)=0;
  5950. WFIFOSET(fd,packet_len(0x147));
  5951. }
  5952. /// Adds an item to character's cart.
  5953. /// 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)
  5954. /// 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)
  5955. /// 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)
  5956. void clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  5957. {
  5958. #if PACKETVER < 5
  5959. const int cmd = 0x124;
  5960. #elif PACKETVER < 20150225
  5961. const int cmd = 0x1c5;
  5962. #else
  5963. const int cmd = 0xa0b;
  5964. #endif
  5965. int view,fd;
  5966. unsigned char *buf;
  5967. int offset = 0;
  5968. nullpo_retv(sd);
  5969. fd=sd->fd;
  5970. if(n < 0 || n >= MAX_CART || sd->cart.u.items_cart[n].nameid <= 0)
  5971. return;
  5972. WFIFOHEAD(fd,packet_len(cmd));
  5973. buf=WFIFOP(fd,0);
  5974. WBUFW(buf,0)=cmd;
  5975. WBUFW(buf,2)=n+2;
  5976. WBUFL(buf,4)=amount;
  5977. if((view = itemdb_viewid(sd->cart.u.items_cart[n].nameid)) > 0)
  5978. WBUFW(buf,8)=view;
  5979. else
  5980. WBUFW(buf,8)=sd->cart.u.items_cart[n].nameid;
  5981. #if PACKETVER >= 5
  5982. WBUFB(buf,10)=itemdb_type(sd->cart.u.items_cart[n].nameid);
  5983. offset += 1;
  5984. #endif
  5985. WBUFB(buf,10+offset)=sd->cart.u.items_cart[n].identify;
  5986. WBUFB(buf,11+offset)=sd->cart.u.items_cart[n].attribute;
  5987. WBUFB(buf,12+offset)=sd->cart.u.items_cart[n].refine;
  5988. clif_addcards(WBUFP(buf,13+offset), &sd->cart.u.items_cart[n]);
  5989. #if PACKETVER >= 20150225
  5990. clif_add_random_options(WBUFP(buf,21+offset), &sd->cart.u.items_cart[n]);
  5991. #endif
  5992. WFIFOSET(fd,packet_len(cmd));
  5993. }
  5994. // [Ind/Hercules] - Data Thanks to Yommy (ZC_ACK_ADDITEM_TO_CART)
  5995. /* Acknowledge an item have been added to cart
  5996. * 012c <result>B
  5997. * result :
  5998. * 0 = ADDITEM_TO_CART_FAIL_WEIGHT
  5999. * 1 = ADDITEM_TO_CART_FAIL_COUNT
  6000. */
  6001. void clif_cart_additem_ack(struct map_session_data *sd, uint8 flag)
  6002. {
  6003. int fd;
  6004. unsigned char *buf;
  6005. nullpo_retv(sd);
  6006. fd = sd->fd;
  6007. buf = WFIFOP(fd,0);
  6008. WBUFW(buf,0) = 0x12c;
  6009. WBUFB(buf,2) = flag;
  6010. clif_send(buf,packet_len(0x12c),&sd->bl,SELF);
  6011. }
  6012. // 09B7 <unknow data> (ZC_ACK_OPEN_BANKING)
  6013. void clif_bank_open(struct map_session_data *sd){
  6014. int fd;
  6015. nullpo_retv(sd);
  6016. fd = sd->fd;
  6017. WFIFOHEAD(fd,4);
  6018. WFIFOW(fd,0) = 0x09b7;
  6019. WFIFOW(fd,2) = 0;
  6020. WFIFOSET(fd,4);
  6021. }
  6022. /*
  6023. * Request to Open the banking system
  6024. * 09B6 <aid>L ??? (dunno just wild guess checkme)
  6025. */
  6026. void clif_parse_BankOpen(int fd, struct map_session_data* sd) {
  6027. //TODO check if preventing trade or stuff like that
  6028. //also mark something in case char ain't available for saving, should we check now ?
  6029. nullpo_retv(sd);
  6030. if( !battle_config.feature_banking ) {
  6031. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6032. return;
  6033. }
  6034. else {
  6035. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6036. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6037. if(sd->status.account_id == aid){
  6038. sd->state.banking = 1;
  6039. //request save ?
  6040. //chrif_bankdata_request(sd->status.account_id, sd->status.char_id);
  6041. //on succes open bank ?
  6042. clif_bank_open(sd);
  6043. }
  6044. }
  6045. }
  6046. // 09B9 <unknow data> (ZC_ACK_CLOSE_BANKING)
  6047. void clif_bank_close(struct map_session_data *sd){
  6048. int fd;
  6049. nullpo_retv(sd);
  6050. fd = sd->fd;
  6051. WFIFOHEAD(fd,4);
  6052. WFIFOW(fd,0) = 0x09B9;
  6053. WFIFOW(fd,2) = 0;
  6054. WFIFOSET(fd,4);
  6055. }
  6056. /*
  6057. * Request to close the banking system
  6058. * 09B8 <aid>L ??? (dunno just wild guess checkme)
  6059. */
  6060. void clif_parse_BankClose(int fd, struct map_session_data* sd) {
  6061. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6062. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6063. nullpo_retv(sd);
  6064. if( !battle_config.feature_banking ) {
  6065. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6066. //still allow to go trough to not stuck player if we have disable it while they was in
  6067. }
  6068. if(sd->status.account_id == aid){
  6069. sd->state.banking = 0;
  6070. clif_bank_close(sd);
  6071. }
  6072. }
  6073. /*
  6074. * Display how much we got in bank (I suppose)
  6075. 09A6 <Bank_Vault>Q <Reason>W (PACKET_ZC_BANKING_CHECK)
  6076. */
  6077. void clif_Bank_Check(struct map_session_data* sd) {
  6078. unsigned char buf[13];
  6079. struct s_packet_db* info;
  6080. int16 len;
  6081. int cmd = 0;
  6082. nullpo_retv(sd);
  6083. cmd = packet_db_ack[ZC_BANKING_CHECK];
  6084. if(!cmd) cmd = 0x09A6; //default
  6085. info = &packet_db[cmd];
  6086. len = info->len;
  6087. if(!len) return; //version as packet disable
  6088. // sd->state.banking = 1; //mark opening and closing
  6089. WBUFW(buf,0) = cmd;
  6090. WBUFQ(buf,info->pos[0]) = sd->bank_vault; //value
  6091. WBUFW(buf,info->pos[1]) = 0; //reason
  6092. clif_send(buf,len,&sd->bl,SELF);
  6093. }
  6094. /*
  6095. * Requesting the data in bank
  6096. * 09AB <aid>L (PACKET_CZ_REQ_BANKING_CHECK)
  6097. */
  6098. void clif_parse_BankCheck(int fd, struct map_session_data* sd) {
  6099. nullpo_retv(sd);
  6100. if( !battle_config.feature_banking ) {
  6101. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6102. return;
  6103. }
  6104. else {
  6105. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6106. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6107. if(sd->status.account_id == aid) //since we have it let check it for extra security
  6108. clif_Bank_Check(sd);
  6109. }
  6110. }
  6111. /*
  6112. * Acknowledge of deposit some money in bank
  6113. 09A8 <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_DEPOSIT)
  6114. */
  6115. void clif_bank_deposit(struct map_session_data *sd, enum e_BANKING_DEPOSIT_ACK reason) {
  6116. unsigned char buf[17];
  6117. struct s_packet_db* info;
  6118. int16 len;
  6119. int cmd =0;
  6120. nullpo_retv(sd);
  6121. cmd = packet_db_ack[ZC_ACK_BANKING_DEPOSIT];
  6122. if(!cmd) cmd = 0x09A8;
  6123. info = &packet_db[cmd];
  6124. len = info->len;
  6125. if(!len) return; //version as packet disable
  6126. WBUFW(buf,0) = cmd;
  6127. WBUFW(buf,info->pos[0]) = (short)reason;
  6128. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6129. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6130. clif_send(buf,len,&sd->bl,SELF);
  6131. }
  6132. /*
  6133. * Request saving some money in bank
  6134. * @author : original [Yommy/Hercules]
  6135. * 09A7 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_DEPOSIT)
  6136. */
  6137. void clif_parse_BankDeposit(int fd, struct map_session_data* sd) {
  6138. nullpo_retv(sd);
  6139. if( !battle_config.feature_banking ) {
  6140. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6141. return;
  6142. }
  6143. else {
  6144. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6145. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6146. int money = RFIFOL(fd,info->pos[1]);
  6147. if(sd->status.account_id == aid){
  6148. enum e_BANKING_DEPOSIT_ACK reason = pc_bank_deposit(sd,max(0,money));
  6149. clif_bank_deposit(sd,reason);
  6150. }
  6151. }
  6152. }
  6153. /*
  6154. * Acknowledge of withdrawing some money from bank
  6155. 09AA <Reason>W <Money>Q <balance>L (PACKET_ZC_ACK_BANKING_WITHDRAW)
  6156. */
  6157. void clif_bank_withdraw(struct map_session_data *sd,enum e_BANKING_WITHDRAW_ACK reason) {
  6158. unsigned char buf[17];
  6159. struct s_packet_db* info;
  6160. int16 len;
  6161. int cmd;
  6162. nullpo_retv(sd);
  6163. cmd = packet_db_ack[ZC_ACK_BANKING_WITHDRAW];
  6164. if(!cmd) cmd = 0x09AA;
  6165. info = &packet_db[cmd];
  6166. len = info->len;
  6167. if(!len) return; //version as packet disable
  6168. WBUFW(buf,0) = cmd;
  6169. WBUFW(buf,info->pos[0]) = (short)reason;
  6170. WBUFQ(buf,info->pos[1]) = sd->bank_vault;/* money in the bank */
  6171. WBUFL(buf,info->pos[2]) = sd->status.zeny;/* how much zeny char has after operation */
  6172. clif_send(buf,len,&sd->bl,SELF);
  6173. }
  6174. /*
  6175. * Request Withdrawing some money from bank
  6176. * 09A9 <AID>L <Money>L (PACKET_CZ_REQ_BANKING_WITHDRAW)
  6177. */
  6178. void clif_parse_BankWithdraw(int fd, struct map_session_data* sd) {
  6179. nullpo_retv(sd);
  6180. if( !battle_config.feature_banking ) {
  6181. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1496),false,SELF); //Banking is disabled
  6182. return;
  6183. }
  6184. else {
  6185. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  6186. int aid = RFIFOL(fd,info->pos[0]); //unused should we check vs fd ?
  6187. int money = RFIFOL(fd,info->pos[1]);
  6188. if(sd->status.account_id == aid){
  6189. enum e_BANKING_WITHDRAW_ACK reason = pc_bank_withdraw(sd,max(0,money));
  6190. clif_bank_withdraw(sd,reason);
  6191. }
  6192. }
  6193. }
  6194. /// Deletes an item from character's cart (ZC_DELETE_ITEM_FROM_CART).
  6195. /// 0125 <index>.W <amount>.L
  6196. void clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  6197. {
  6198. int fd;
  6199. nullpo_retv(sd);
  6200. fd=sd->fd;
  6201. WFIFOHEAD(fd,packet_len(0x125));
  6202. WFIFOW(fd,0)=0x125;
  6203. WFIFOW(fd,2)=n+2;
  6204. WFIFOL(fd,4)=amount;
  6205. WFIFOSET(fd,packet_len(0x125));
  6206. }
  6207. /// Opens the shop creation menu (ZC_OPENSTORE).
  6208. /// 012d <num>.W
  6209. /// num:
  6210. /// number of allowed item slots
  6211. void clif_openvendingreq(struct map_session_data* sd, int num)
  6212. {
  6213. int fd;
  6214. nullpo_retv(sd);
  6215. fd = sd->fd;
  6216. WFIFOHEAD(fd,packet_len(0x12d));
  6217. WFIFOW(fd,0) = 0x12d;
  6218. WFIFOW(fd,2) = num;
  6219. WFIFOSET(fd,packet_len(0x12d));
  6220. }
  6221. /// Displays a vending board to target/area (ZC_STORE_ENTRY).
  6222. /// 0131 <owner id>.L <message>.80B
  6223. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  6224. {
  6225. unsigned char buf[128];
  6226. nullpo_retv(bl);
  6227. WBUFW(buf,0) = 0x131;
  6228. WBUFL(buf,2) = bl->id;
  6229. safestrncpy(WBUFCP(buf,6), message, 80);
  6230. if( fd ) {
  6231. WFIFOHEAD(fd,packet_len(0x131));
  6232. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  6233. WFIFOSET(fd,packet_len(0x131));
  6234. } else {
  6235. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  6236. }
  6237. }
  6238. /// Removes a vending board from screen (ZC_DISAPPEAR_ENTRY).
  6239. /// 0132 <owner id>.L
  6240. void clif_closevendingboard(struct block_list* bl, int fd)
  6241. {
  6242. unsigned char buf[16];
  6243. nullpo_retv(bl);
  6244. WBUFW(buf,0) = 0x132;
  6245. WBUFL(buf,2) = bl->id;
  6246. if( fd ) {
  6247. WFIFOHEAD(fd,packet_len(0x132));
  6248. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  6249. WFIFOSET(fd,packet_len(0x132));
  6250. } else {
  6251. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  6252. }
  6253. }
  6254. /// Sends a list of items in a shop.
  6255. /// 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)
  6256. /// 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)
  6257. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  6258. {
  6259. int i,fd;
  6260. int count;
  6261. struct map_session_data* vsd;
  6262. #if PACKETVER < 20100105
  6263. const int cmd = 0x133;
  6264. const int offset = 8;
  6265. #else
  6266. const int cmd = 0x800;
  6267. const int offset = 12;
  6268. #endif
  6269. #if PACKETVER < 20150225
  6270. const int item_length = 22;
  6271. #elif PACKETVER < 20160921
  6272. const int item_length = 47;
  6273. #else
  6274. const int item_length = 53;
  6275. #endif
  6276. nullpo_retv(sd);
  6277. nullpo_retv(vending);
  6278. nullpo_retv(vsd=map_id2sd(id));
  6279. fd = sd->fd;
  6280. count = vsd->vend_num;
  6281. WFIFOHEAD(fd, offset+count*item_length);
  6282. WFIFOW(fd,0) = cmd;
  6283. WFIFOW(fd,2) = offset+count*item_length;
  6284. WFIFOL(fd,4) = id;
  6285. #if PACKETVER >= 20100105
  6286. WFIFOL(fd,8) = vsd->vender_id;
  6287. #endif
  6288. for( i = 0; i < count; i++ )
  6289. {
  6290. int index = vending[i].index;
  6291. struct item_data* data = itemdb_search(vsd->cart.u.items_cart[index].nameid);
  6292. WFIFOL(fd,offset+ 0+i*item_length) = vending[i].value;
  6293. WFIFOW(fd,offset+ 4+i*item_length) = vending[i].amount;
  6294. WFIFOW(fd,offset+ 6+i*item_length) = vending[i].index + 2;
  6295. WFIFOB(fd,offset+ 8+i*item_length) = itemtype(data->nameid);
  6296. WFIFOW(fd,offset+ 9+i*item_length) = ( data->view_id > 0 ) ? data->view_id : vsd->cart.u.items_cart[index].nameid;
  6297. WFIFOB(fd,offset+11+i*item_length) = vsd->cart.u.items_cart[index].identify;
  6298. WFIFOB(fd,offset+12+i*item_length) = vsd->cart.u.items_cart[index].attribute;
  6299. WFIFOB(fd,offset+13+i*item_length) = vsd->cart.u.items_cart[index].refine;
  6300. clif_addcards(WFIFOP(fd,offset+14+i*item_length), &vsd->cart.u.items_cart[index]);
  6301. #if PACKETVER >= 20150225
  6302. clif_add_random_options(WFIFOP(fd,offset+22+i*item_length), &vsd->cart.u.items_cart[index]);
  6303. #if PACKETVER >= 20160921
  6304. WFIFOL(fd,offset+47+i*item_length) = pc_equippoint_sub(sd,data);
  6305. WFIFOW(fd,offset+51+i*item_length) = data->look;
  6306. #endif
  6307. #endif
  6308. }
  6309. WFIFOSET(fd,WFIFOW(fd,2));
  6310. }
  6311. /// Shop purchase failure (ZC_PC_PURCHASE_RESULT_FROMMC).
  6312. /// 0135 <index>.W <amount>.W <result>.B
  6313. /// result:
  6314. /// 0 = success
  6315. /// 1 = not enough zeny
  6316. /// 2 = overweight
  6317. /// 4 = out of stock
  6318. /// 5 = "cannot use an npc shop while in a trade"
  6319. /// 6 = Because the store information was incorrect the item was not purchased.
  6320. /// 7 = No sales information.
  6321. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  6322. {
  6323. int fd;
  6324. nullpo_retv(sd);
  6325. fd = sd->fd;
  6326. WFIFOHEAD(fd,packet_len(0x135));
  6327. WFIFOW(fd,0) = 0x135;
  6328. WFIFOW(fd,2) = index+2;
  6329. WFIFOW(fd,4) = amount;
  6330. WFIFOB(fd,6) = fail;
  6331. WFIFOSET(fd,packet_len(0x135));
  6332. }
  6333. /// Show's vending player its list of items for sale (ZC_ACK_OPENSTORE2).
  6334. /// 0a28 <Result>.B
  6335. /// result:
  6336. /// 0 = Successed
  6337. /// 1 = Failed
  6338. void clif_openvending_ack(struct map_session_data* sd, int result)
  6339. {
  6340. int fd;
  6341. nullpo_retv(sd);
  6342. fd = sd->fd;
  6343. WFIFOHEAD(fd, 3);
  6344. WFIFOW(fd,0) = 0xa28;
  6345. WFIFOB(fd,2) = result;
  6346. WFIFOSET(fd, 3);
  6347. }
  6348. /// Shop creation success (ZC_PC_PURCHASE_MYITEMLIST).
  6349. /// 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 }*
  6350. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  6351. {
  6352. int i,fd;
  6353. int count;
  6354. #if PACKETVER < 20150225
  6355. const int item_length = 22;
  6356. #else
  6357. const int item_length = 47;
  6358. #endif
  6359. nullpo_retv(sd);
  6360. fd = sd->fd;
  6361. count = sd->vend_num;
  6362. WFIFOHEAD(fd, 8+count*item_length);
  6363. WFIFOW(fd,0) = 0x136;
  6364. WFIFOW(fd,2) = 8+count*item_length;
  6365. WFIFOL(fd,4) = id;
  6366. for( i = 0; i < count; i++ ) {
  6367. int index = vending[i].index;
  6368. struct item_data* data = itemdb_search(sd->cart.u.items_cart[index].nameid);
  6369. WFIFOL(fd, 8+i*item_length) = vending[i].value;
  6370. WFIFOW(fd,12+i*item_length) = vending[i].index + 2;
  6371. WFIFOW(fd,14+i*item_length) = vending[i].amount;
  6372. WFIFOB(fd,16+i*item_length) = itemtype(data->nameid);
  6373. WFIFOW(fd,17+i*item_length) = ( data->view_id > 0 ) ? data->view_id : sd->cart.u.items_cart[index].nameid;
  6374. WFIFOB(fd,19+i*item_length) = sd->cart.u.items_cart[index].identify;
  6375. WFIFOB(fd,20+i*item_length) = sd->cart.u.items_cart[index].attribute;
  6376. WFIFOB(fd,21+i*item_length) = sd->cart.u.items_cart[index].refine;
  6377. clif_addcards(WFIFOP(fd,22+i*item_length), &sd->cart.u.items_cart[index]);
  6378. #if PACKETVER >= 20150225
  6379. clif_add_random_options(WFIFOP(fd,30+i*item_length), &sd->cart.u.items_cart[index]);
  6380. #endif
  6381. }
  6382. WFIFOSET(fd,WFIFOW(fd,2));
  6383. #if PACKETVER >= 20141022
  6384. /// 0 = Successed
  6385. /// 1 = Failed
  6386. clif_openvending_ack(sd, 0);
  6387. #endif
  6388. }
  6389. /// Inform merchant that someone has bought an item.
  6390. /// 0137 <index>.W <amount>.W (ZC_DELETEITEM_FROM_MCSTORE).
  6391. /// 09e5 <index>.W <amount>.W <GID>.L <Date>.L <zeny>.L (ZC_DELETEITEM_FROM_MCSTORE2).
  6392. void clif_vendingreport(struct map_session_data* sd, int index, int amount, uint32 char_id, int zeny) {
  6393. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  6394. const int cmd = 0x137;
  6395. #else
  6396. const int cmd = 0x9e5;
  6397. #endif
  6398. int fd = sd->fd;
  6399. nullpo_retv(sd);
  6400. WFIFOHEAD(fd,packet_len(cmd));
  6401. WFIFOW(fd,0) = cmd;
  6402. WFIFOW(fd,2) = index+2;
  6403. WFIFOW(fd,4) = amount;
  6404. #if PACKETVER >= 20141016
  6405. WFIFOL(fd,6) = char_id; // GID
  6406. WFIFOL(fd,10) = (int)time(NULL); // Date
  6407. WFIFOL(fd,14) = zeny; // zeny
  6408. #endif
  6409. WFIFOSET(fd,packet_len(cmd));
  6410. }
  6411. /// Result of organizing a party (ZC_ACK_MAKE_GROUP).
  6412. /// 00fa <result>.B
  6413. /// result:
  6414. /// 0 = opens party window and shows MsgStringTable[77]="party successfully organized"
  6415. /// 1 = MsgStringTable[78]="party name already exists"
  6416. /// 2 = MsgStringTable[79]="already in a party"
  6417. /// 3 = cannot organize parties on this map
  6418. /// ? = nothing
  6419. void clif_party_created(struct map_session_data *sd,int result)
  6420. {
  6421. int fd;
  6422. nullpo_retv(sd);
  6423. fd=sd->fd;
  6424. WFIFOHEAD(fd,packet_len(0xfa));
  6425. WFIFOW(fd,0)=0xfa;
  6426. WFIFOB(fd,2)=result;
  6427. WFIFOSET(fd,packet_len(0xfa));
  6428. }
  6429. /// Adds new member to a party.
  6430. /// 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)
  6431. /// 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)
  6432. /// 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)
  6433. /// role:
  6434. /// 0 = leader
  6435. /// 1 = normal
  6436. /// state:
  6437. /// 0 = connected
  6438. /// 1 = disconnected
  6439. void clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  6440. {
  6441. int i;
  6442. #if PACKETVER < 20170502
  6443. unsigned char buf[81];
  6444. int cmd = 0x1e9;
  6445. int offset = 0;
  6446. #else
  6447. unsigned char buf[85];
  6448. int cmd = 0xa43;
  6449. int offset = 4;
  6450. #endif
  6451. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  6452. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  6453. } else {
  6454. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  6455. }
  6456. if (i >= MAX_PARTY) return; //Should never happen...
  6457. sd = p->data[i].sd;
  6458. WBUFW(buf, 0) = cmd;
  6459. WBUFL(buf, 2) = sd->status.account_id;
  6460. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  6461. #if PACKETVER >= 20170502
  6462. WBUFW(buf,10) = sd->status.class_;
  6463. WBUFW(buf,12) = sd->status.base_level;
  6464. #endif
  6465. WBUFW(buf,offset+10) = sd->bl.x;
  6466. WBUFW(buf,offset+12) = sd->bl.y;
  6467. WBUFB(buf,offset+14) = (p->party.member[i].online)?0:1;
  6468. safestrncpy(WBUFCP(buf,offset+15), p->party.name, NAME_LENGTH);
  6469. safestrncpy(WBUFCP(buf,offset+39), sd->status.name, NAME_LENGTH);
  6470. mapindex_getmapname_ext(map_mapid2mapname(sd->bl.m), WBUFCP(buf,offset+63));
  6471. WBUFB(buf,offset+79) = (p->party.item&1)?1:0;
  6472. WBUFB(buf,offset+80) = (p->party.item&2)?1:0;
  6473. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6474. }
  6475. /// Sends party information (ZC_GROUP_LIST).
  6476. /// 00fb <packet len>.W <party name>.24B { <account id>.L <nick>.24B <map name>.16B <role>.B <state>.B }*
  6477. /// role:
  6478. /// 0 = leader
  6479. /// 1 = normal
  6480. /// state:
  6481. /// 0 = connected
  6482. /// 1 = disconnected
  6483. /// 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
  6484. void clif_party_info(struct party_data* p, struct map_session_data *sd)
  6485. {
  6486. struct map_session_data* party_sd = NULL;
  6487. int i, c;
  6488. #if PACKETVER < 20170502
  6489. const int M_SIZE = 46; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1
  6490. unsigned char buf[2+2+NAME_LENGTH+46*MAX_PARTY];
  6491. int cmd = 0xfb;
  6492. #else
  6493. const int M_SIZE = 50; // 4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1+4
  6494. unsigned char buf[2+2+NAME_LENGTH+50*MAX_PARTY+6];
  6495. int cmd = 0xa44;
  6496. #endif
  6497. const int PRE_SIZE = 28; // cmd, actual cmd_size, party_name
  6498. nullpo_retv(p);
  6499. WBUFW(buf,0) = cmd;
  6500. safestrncpy(WBUFCP(buf,4), p->party.name, NAME_LENGTH);
  6501. for(i = 0, c = 0; i < MAX_PARTY; i++)
  6502. {
  6503. struct party_member* m = &p->party.member[i];
  6504. if(!m->account_id) continue;
  6505. if(party_sd == NULL) party_sd = p->data[i].sd;
  6506. WBUFL(buf,PRE_SIZE+c*M_SIZE) = m->account_id;
  6507. safestrncpy(WBUFCP(buf,PRE_SIZE+c*M_SIZE+4), m->name, NAME_LENGTH);
  6508. mapindex_getmapname_ext(mapindex_id2name(m->map), WBUFCP(buf,PRE_SIZE+c*M_SIZE+PRE_SIZE));
  6509. WBUFB(buf,PRE_SIZE+c*M_SIZE+44) = (m->leader) ? 0 : 1;
  6510. WBUFB(buf,PRE_SIZE+c*M_SIZE+45) = (m->online) ? 0 : 1;
  6511. #if PACKETVER >= 20170502
  6512. WBUFW(buf,PRE_SIZE+c*M_SIZE+46) = m->class_;
  6513. WBUFW(buf,PRE_SIZE+c*M_SIZE+48) = m->lv;
  6514. #endif
  6515. c++;
  6516. }
  6517. #if PACKETVER < 20170502
  6518. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE;
  6519. #else
  6520. WBUFB(buf,PRE_SIZE+c*M_SIZE) = (p->party.item & 1) ? 1 : 0;
  6521. WBUFB(buf,PRE_SIZE+c*M_SIZE+1) = (p->party.item & 2) ? 1 : 0;
  6522. WBUFL(buf,PRE_SIZE+c*M_SIZE+2) = 0; // unknown
  6523. WBUFW(buf,2) = PRE_SIZE+c*M_SIZE+6;
  6524. #endif
  6525. if(sd) { // send only to self
  6526. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6527. } else if (party_sd) { // send to whole party
  6528. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  6529. }
  6530. }
  6531. /// The player's 'party invite' state, sent during login (ZC_PARTY_CONFIG).
  6532. /// 02c9 <flag>.B
  6533. /// flag:
  6534. /// 0 = allow party invites
  6535. /// 1 = auto-deny party invites
  6536. void clif_partyinvitationstate(struct map_session_data* sd)
  6537. {
  6538. int fd;
  6539. nullpo_retv(sd);
  6540. fd = sd->fd;
  6541. WFIFOHEAD(fd, packet_len(0x2c9));
  6542. WFIFOW(fd, 0) = 0x2c9;
  6543. WFIFOB(fd, 2) = 0; // not implemented
  6544. WFIFOSET(fd, packet_len(0x2c9));
  6545. }
  6546. /// Party invitation request.
  6547. /// 00fe <party id>.L <party name>.24B (ZC_REQ_JOIN_GROUP)
  6548. /// 02c6 <party id>.L <party name>.24B (ZC_PARTY_JOIN_REQ)
  6549. void clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  6550. {
  6551. #if PACKETVER < 20070821
  6552. const int cmd = 0xfe;
  6553. #else
  6554. const int cmd = 0x2c6;
  6555. #endif
  6556. int fd;
  6557. struct party_data *p;
  6558. nullpo_retv(sd);
  6559. nullpo_retv(tsd);
  6560. fd=tsd->fd;
  6561. if( (p=party_search(sd->status.party_id))==NULL )
  6562. return;
  6563. WFIFOHEAD(fd,packet_len(cmd));
  6564. WFIFOW(fd,0)=cmd;
  6565. WFIFOL(fd,2)=sd->status.party_id;
  6566. safestrncpy(WFIFOCP(fd,6),p->party.name,NAME_LENGTH);
  6567. WFIFOSET(fd,packet_len(cmd));
  6568. }
  6569. /// Party invite result.
  6570. /// 00fd <nick>.24S <result>.B (ZC_ACK_REQ_JOIN_GROUP)
  6571. /// 02c5 <nick>.24S <result>.L (ZC_PARTY_JOIN_REQ_ACK)
  6572. void clif_party_invite_reply(struct map_session_data* sd, const char* nick, enum e_party_invite_reply reply)
  6573. {
  6574. int fd;
  6575. nullpo_retv(sd);
  6576. fd=sd->fd;
  6577. #if PACKETVER < 20070904
  6578. if( reply == PARTY_REPLY_OFFLINE ) {
  6579. clif_displaymessage(fd, msg_txt(sd,3));
  6580. return;
  6581. }
  6582. #endif
  6583. #if PACKETVER < 20070821
  6584. WFIFOHEAD(fd,packet_len(0xfd));
  6585. WFIFOW(fd,0) = 0xfd;
  6586. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6587. WFIFOB(fd,26) = reply;
  6588. WFIFOSET(fd,packet_len(0xfd));
  6589. #else
  6590. WFIFOHEAD(fd,packet_len(0x2c5));
  6591. WFIFOW(fd,0) = 0x2c5;
  6592. safestrncpy(WFIFOCP(fd,2),nick,NAME_LENGTH);
  6593. WFIFOL(fd,26) = reply;
  6594. WFIFOSET(fd,packet_len(0x2c5));
  6595. #endif
  6596. }
  6597. /// Updates party settings.
  6598. /// 0101 <exp option>.L (ZC_GROUPINFO_CHANGE)
  6599. /// 07d8 <exp option>.L <item pick rule>.B <item share rule>.B (ZC_REQ_GROUPINFO_CHANGE_V2)
  6600. /// exp option:
  6601. /// 0 = exp sharing disabled
  6602. /// 1 = exp sharing enabled
  6603. /// 2 = cannot change exp sharing
  6604. ///
  6605. /// flag:
  6606. /// 0 = send to party
  6607. /// 1 = send to sd
  6608. void clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  6609. {
  6610. unsigned char buf[16];
  6611. #if PACKETVER < 20090603
  6612. const int cmd = 0x101;
  6613. #else
  6614. const int cmd = 0x7d8;
  6615. #endif
  6616. nullpo_retv(p);
  6617. if(!sd && flag==0){
  6618. int i;
  6619. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6620. if (i < MAX_PARTY)
  6621. sd = p->data[i].sd;
  6622. }
  6623. if(!sd) return;
  6624. WBUFW(buf,0)=cmd;
  6625. WBUFL(buf,2)=((flag&0x01)?2:p->party.exp);
  6626. #if PACKETVER >= 20090603
  6627. WBUFB(buf,6)=(p->party.item&1)?1:0;
  6628. WBUFB(buf,7)=(p->party.item&2)?1:0;
  6629. #endif
  6630. if(flag==0)
  6631. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  6632. else
  6633. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  6634. }
  6635. /**
  6636. * 0105 <account id>.L <char name>.24B <result>.B (ZC_DELETE_MEMBER_FROM_GROUP).
  6637. * @param sd Send the notification for this player
  6638. * @param account_id Account ID of kicked member
  6639. * @param name Name of kicked member
  6640. * @param result Party leave result @see PARTY_MEMBER_WITHDRAW
  6641. * @param target Send target
  6642. **/
  6643. 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) {
  6644. unsigned char buf[2+4+NAME_LENGTH+1];
  6645. if (!sd)
  6646. return;
  6647. WBUFW(buf,0) = 0x0105;
  6648. WBUFL(buf,2) = account_id;
  6649. memcpy(WBUFP(buf,6), name, NAME_LENGTH);
  6650. WBUFB(buf,6+NAME_LENGTH) = result;
  6651. clif_send(buf, 2+4+NAME_LENGTH+1, &sd->bl, target);
  6652. }
  6653. /// Party chat message (ZC_NOTIFY_CHAT_PARTY).
  6654. /// 0109 <packet len>.W <account id>.L <message>.?B
  6655. void clif_party_message(struct party_data* p, uint32 account_id, const char* mes, int len)
  6656. {
  6657. struct map_session_data *sd;
  6658. int i;
  6659. nullpo_retv(p);
  6660. ARR_FIND(0,MAX_PARTY,i,p->data[i].sd);
  6661. if(i < MAX_PARTY){
  6662. unsigned char buf[1024];
  6663. if( len > sizeof(buf)-8 )
  6664. {
  6665. ShowWarning("clif_party_message: Truncated message '%s' (len=%d, max=%d, party_id=%d).\n", mes, len, sizeof(buf)-8, p->party.party_id);
  6666. len = sizeof(buf)-8;
  6667. }
  6668. sd = p->data[i].sd;
  6669. WBUFW(buf,0)=0x109;
  6670. WBUFW(buf,2)=len+8;
  6671. WBUFL(buf,4)=account_id;
  6672. safestrncpy(WBUFCP(buf,8), mes, len);
  6673. clif_send(buf,len+8,&sd->bl,PARTY);
  6674. }
  6675. }
  6676. /// Updates the position of a party member on the minimap (ZC_NOTIFY_POSITION_TO_GROUPM).
  6677. /// 0107 <account id>.L <x>.W <y>.W
  6678. void clif_party_xy(struct map_session_data *sd)
  6679. {
  6680. unsigned char buf[16];
  6681. nullpo_retv(sd);
  6682. WBUFW(buf,0)=0x107;
  6683. WBUFL(buf,2)=sd->status.account_id;
  6684. WBUFW(buf,6)=sd->bl.x;
  6685. WBUFW(buf,8)=sd->bl.y;
  6686. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6687. }
  6688. /*==========================================
  6689. * Sends x/y dot to a single fd. [Skotlex]
  6690. *------------------------------------------*/
  6691. void clif_party_xy_single(int fd, struct map_session_data *sd)
  6692. {
  6693. WFIFOHEAD(fd,packet_len(0x107));
  6694. WFIFOW(fd,0)=0x107;
  6695. WFIFOL(fd,2)=sd->status.account_id;
  6696. WFIFOW(fd,6)=sd->bl.x;
  6697. WFIFOW(fd,8)=sd->bl.y;
  6698. WFIFOSET(fd,packet_len(0x107));
  6699. }
  6700. /// Updates HP bar of a party member.
  6701. /// 0106 <account id>.L <hp>.W <max hp>.W (ZC_NOTIFY_HP_TO_GROUPM)
  6702. /// 080e <account id>.L <hp>.L <max hp>.L (ZC_NOTIFY_HP_TO_GROUPM_R2)
  6703. void clif_party_hp(struct map_session_data *sd)
  6704. {
  6705. unsigned char buf[16];
  6706. #if PACKETVER < 20100126
  6707. const int cmd = 0x106;
  6708. #else
  6709. const int cmd = 0x80e;
  6710. #endif
  6711. nullpo_retv(sd);
  6712. WBUFW(buf,0)=cmd;
  6713. WBUFL(buf,2)=sd->status.account_id;
  6714. #if PACKETVER < 20100126
  6715. if (sd->battle_status.max_hp > INT16_MAX) { //To correctly display the %hp bar. [Skotlex]
  6716. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  6717. WBUFW(buf,8) = 100;
  6718. } else {
  6719. WBUFW(buf,6) = sd->battle_status.hp;
  6720. WBUFW(buf,8) = sd->battle_status.max_hp;
  6721. }
  6722. #else
  6723. WBUFL(buf,6) = sd->battle_status.hp;
  6724. WBUFL(buf,10) = sd->battle_status.max_hp;
  6725. #endif
  6726. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  6727. }
  6728. /// Updates the job and level of a party member
  6729. /// 0abd <account id>.L <job>.W <level>.W
  6730. void clif_party_job_and_level(struct map_session_data *sd){
  6731. #if PACKETVER >= 20170502
  6732. unsigned char buf[10];
  6733. nullpo_retv(sd);
  6734. WBUFW(buf, 0) = 0xabd;
  6735. WBUFL(buf, 2) = sd->status.account_id;
  6736. WBUFW(buf, 6) = sd->status.class_;
  6737. WBUFW(buf, 8) = sd->status.base_level;
  6738. clif_send(buf, packet_len(0xabd), &sd->bl, PARTY);
  6739. #endif
  6740. }
  6741. /*==========================================
  6742. * Sends HP bar to a single fd. [Skotlex]
  6743. *------------------------------------------*/
  6744. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  6745. {
  6746. #if PACKETVER < 20100126
  6747. const int cmd = 0x106;
  6748. #else
  6749. const int cmd = 0x80e;
  6750. #endif
  6751. WFIFOHEAD(fd,packet_len(cmd));
  6752. WFIFOW(fd,0) = cmd;
  6753. WFIFOL(fd,2) = id;
  6754. #if PACKETVER < 20100126
  6755. if( maxhp > INT16_MAX )
  6756. {// To correctly display the %hp bar. [Skotlex]
  6757. WFIFOW(fd,6) = hp/(maxhp/100);
  6758. WFIFOW(fd,8) = 100;
  6759. } else {
  6760. WFIFOW(fd,6) = hp;
  6761. WFIFOW(fd,8) = maxhp;
  6762. }
  6763. #else
  6764. WFIFOL(fd,6) = hp;
  6765. WFIFOL(fd,10) = maxhp;
  6766. #endif
  6767. WFIFOSET(fd, packet_len(cmd));
  6768. }
  6769. /// Notifies the client, that it's attack target is too far (ZC_ATTACK_FAILURE_FOR_DISTANCE).
  6770. /// 0139 <target id>.L <target x>.W <target y>.W <x>.W <y>.W <atk range>.W
  6771. void clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  6772. {
  6773. int fd;
  6774. nullpo_retv(sd);
  6775. nullpo_retv(bl);
  6776. fd=sd->fd;
  6777. WFIFOHEAD(fd,packet_len(0x139));
  6778. WFIFOW(fd, 0)=0x139;
  6779. WFIFOL(fd, 2)=bl->id;
  6780. WFIFOW(fd, 6)=bl->x;
  6781. WFIFOW(fd, 8)=bl->y;
  6782. WFIFOW(fd,10)=sd->bl.x;
  6783. WFIFOW(fd,12)=sd->bl.y;
  6784. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  6785. WFIFOSET(fd,packet_len(0x139));
  6786. }
  6787. /// Notifies the client about the result of an item produce request (ZC_ACK_REQMAKINGITEM).
  6788. /// 018f <result>.W <name id>.W
  6789. /// result:
  6790. /// 0 = success
  6791. /// 1 = failure
  6792. /// 2 = success (alchemist)
  6793. /// 3 = failure (alchemist)
  6794. void clif_produceeffect(struct map_session_data* sd,int flag, unsigned short nameid)
  6795. {
  6796. int view,fd;
  6797. nullpo_retv(sd);
  6798. fd = sd->fd;
  6799. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  6800. WFIFOHEAD(fd,packet_len(0x18f));
  6801. WFIFOW(fd, 0)=0x18f;
  6802. WFIFOW(fd, 2)=flag;
  6803. if((view = itemdb_viewid(nameid)) > 0)
  6804. WFIFOW(fd, 4)=view;
  6805. else
  6806. WFIFOW(fd, 4)=nameid;
  6807. WFIFOSET(fd,packet_len(0x18f));
  6808. }
  6809. /// Initiates the pet taming process (ZC_START_CAPTURE).
  6810. /// 019e
  6811. void clif_catch_process(struct map_session_data *sd)
  6812. {
  6813. int fd;
  6814. nullpo_retv(sd);
  6815. fd=sd->fd;
  6816. WFIFOHEAD(fd,packet_len(0x19e));
  6817. WFIFOW(fd,0)=0x19e;
  6818. WFIFOSET(fd,packet_len(0x19e));
  6819. }
  6820. /// Displays the result of a pet taming attempt (ZC_TRYCAPTURE_MONSTER).
  6821. /// 01a0 <result>.B
  6822. /// 0 = failure
  6823. /// 1 = success
  6824. void clif_pet_roulette(struct map_session_data *sd,int data)
  6825. {
  6826. int fd;
  6827. nullpo_retv(sd);
  6828. fd=sd->fd;
  6829. WFIFOHEAD(fd,packet_len(0x1a0));
  6830. WFIFOW(fd,0)=0x1a0;
  6831. WFIFOB(fd,2)=data;
  6832. WFIFOSET(fd,packet_len(0x1a0));
  6833. }
  6834. /// Presents a list of pet eggs that can be hatched (ZC_PETEGG_LIST).
  6835. /// 01a6 <packet len>.W { <index>.W }*
  6836. void clif_sendegg(struct map_session_data *sd)
  6837. {
  6838. int i,n=0,fd;
  6839. nullpo_retv(sd);
  6840. fd=sd->fd;
  6841. if (battle_config.pet_no_gvg && map_flag_gvg2(sd->bl.m)) { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  6842. clif_displaymessage(fd, msg_txt(sd,666));
  6843. return;
  6844. }
  6845. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  6846. WFIFOW(fd,0)=0x1a6;
  6847. for(i=0,n=0;i<MAX_INVENTORY;i++){
  6848. if(sd->inventory.u.items_inventory[i].nameid <= 0 || sd->inventory_data[i] == NULL ||
  6849. sd->inventory_data[i]->type != IT_PETEGG ||
  6850. sd->inventory.u.items_inventory[i].amount <= 0)
  6851. continue;
  6852. WFIFOW(fd,n*2+4)=i+2;
  6853. n++;
  6854. }
  6855. WFIFOW(fd,2)=4+n*2;
  6856. WFIFOSET(fd,WFIFOW(fd,2));
  6857. sd->menuskill_id = SA_TAMINGMONSTER;
  6858. sd->menuskill_val = -1;
  6859. }
  6860. /// Sends a specific pet data update (ZC_CHANGESTATE_PET).
  6861. /// 01a4 <type>.B <id>.L <data>.L
  6862. /// type:
  6863. /// 0 = pre-init (data = 0)
  6864. /// 1 = intimacy (data = 0~4)
  6865. /// 2 = hunger (data = 0~4)
  6866. /// 3 = accessory
  6867. /// 4 = performance (data = 1~3: normal, 4: special)
  6868. /// 5 = hairstyle
  6869. ///
  6870. /// If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  6871. void clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  6872. {
  6873. uint8 buf[16];
  6874. nullpo_retv(pd);
  6875. WBUFW(buf,0) = 0x1a4;
  6876. WBUFB(buf,2) = type;
  6877. WBUFL(buf,3) = pd->bl.id;
  6878. WBUFL(buf,7) = param;
  6879. if (sd)
  6880. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  6881. else
  6882. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  6883. }
  6884. /// Pet's base data (ZC_PROPERTY_PET).
  6885. /// 01a2 <name>.24B <renamed>.B <level>.W <hunger>.W <intimacy>.W <accessory id>.W <class>.W
  6886. void clif_send_petstatus(struct map_session_data *sd)
  6887. {
  6888. int fd;
  6889. struct s_pet *pet;
  6890. nullpo_retv(sd);
  6891. nullpo_retv(sd->pd);
  6892. fd=sd->fd;
  6893. pet = &sd->pd->pet;
  6894. WFIFOHEAD(fd,packet_len(0x1a2));
  6895. WFIFOW(fd,0)=0x1a2;
  6896. safestrncpy(WFIFOCP(fd,2),pet->name,NAME_LENGTH);
  6897. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  6898. WFIFOW(fd,27)=pet->level;
  6899. WFIFOW(fd,29)=pet->hungry;
  6900. WFIFOW(fd,31)=pet->intimate;
  6901. WFIFOW(fd,33)=pet->equip;
  6902. #if PACKETVER >= 20081126
  6903. WFIFOW(fd,35)=pet->class_;
  6904. #endif
  6905. WFIFOSET(fd,packet_len(0x1a2));
  6906. }
  6907. /// Notification about a pet's emotion/talk (ZC_PET_ACT).
  6908. /// 01aa <id>.L <data>.L
  6909. /// data:
  6910. /// @see CZ_PET_ACT.
  6911. void clif_pet_emotion(struct pet_data *pd,int param)
  6912. {
  6913. unsigned char buf[16];
  6914. s_pet_db *pet_db_ptr;
  6915. nullpo_retv(pd);
  6916. pet_db_ptr = pd->get_pet_db();
  6917. memset(buf,0,packet_len(0x1aa));
  6918. WBUFW(buf,0)=0x1aa;
  6919. WBUFL(buf,2)=pd->bl.id;
  6920. if(param >= 100 && pet_db_ptr->talk_convert_class) {
  6921. if(pet_db_ptr->talk_convert_class < 0)
  6922. return;
  6923. else if(pet_db_ptr->talk_convert_class > 0) {
  6924. // replace mob_id component of talk/act data
  6925. param -= (pd->pet.class_ - 100)*100;
  6926. param += (pet_db_ptr->talk_convert_class - 100)*100;
  6927. }
  6928. }
  6929. WBUFL(buf,6)=param;
  6930. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  6931. }
  6932. /// Result of request to feed a pet (ZC_FEED_PET).
  6933. /// 01a3 <result>.B <name id>.W
  6934. /// result:
  6935. /// 0 = failure
  6936. /// 1 = success
  6937. void clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  6938. {
  6939. int fd;
  6940. nullpo_retv(sd);
  6941. fd=sd->fd;
  6942. WFIFOHEAD(fd,packet_len(0x1a3));
  6943. WFIFOW(fd,0)=0x1a3;
  6944. WFIFOB(fd,2)=fail;
  6945. WFIFOW(fd,3)=foodid;
  6946. WFIFOSET(fd,packet_len(0x1a3));
  6947. }
  6948. /// Presents a list of skills that can be auto-spelled (ZC_AUTOSPELLLIST).
  6949. /// 01cd { <skill id>.L }*7
  6950. void clif_autospell(struct map_session_data *sd,uint16 skill_lv)
  6951. {
  6952. int fd;
  6953. nullpo_retv(sd);
  6954. fd=sd->fd;
  6955. WFIFOHEAD(fd,packet_len(0x1cd));
  6956. WFIFOW(fd, 0)=0x1cd;
  6957. if(skill_lv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  6958. WFIFOL(fd,2)= MG_NAPALMBEAT;
  6959. else
  6960. WFIFOL(fd,2)= 0x00000000;
  6961. if(skill_lv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  6962. WFIFOL(fd,6)= MG_COLDBOLT;
  6963. else
  6964. WFIFOL(fd,6)= 0x00000000;
  6965. if(skill_lv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  6966. WFIFOL(fd,10)= MG_FIREBOLT;
  6967. else
  6968. WFIFOL(fd,10)= 0x00000000;
  6969. if(skill_lv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  6970. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  6971. else
  6972. WFIFOL(fd,14)= 0x00000000;
  6973. if(skill_lv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  6974. WFIFOL(fd,18)= MG_SOULSTRIKE;
  6975. else
  6976. WFIFOL(fd,18)= 0x00000000;
  6977. if(skill_lv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  6978. WFIFOL(fd,22)= MG_FIREBALL;
  6979. else
  6980. WFIFOL(fd,22)= 0x00000000;
  6981. if(skill_lv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  6982. WFIFOL(fd,26)= MG_FROSTDIVER;
  6983. else
  6984. WFIFOL(fd,26)= 0x00000000;
  6985. WFIFOSET(fd,packet_len(0x1cd));
  6986. sd->menuskill_id = SA_AUTOSPELL;
  6987. sd->menuskill_val = skill_lv;
  6988. }
  6989. /// Devotion's visual effect (ZC_DEVOTIONLIST).
  6990. /// 01cf <devoter id>.L { <devotee id>.L }*5 <max distance>.W
  6991. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  6992. {
  6993. unsigned char buf[56];
  6994. nullpo_retv(src);
  6995. memset(buf,0,packet_len(0x1cf));
  6996. WBUFW(buf,0) = 0x1cf;
  6997. WBUFL(buf,2) = src->id;
  6998. if( src->type == BL_MER )
  6999. {
  7000. struct mercenary_data *md = BL_CAST(BL_MER,src);
  7001. if( md && md->master && md->devotion_flag )
  7002. WBUFL(buf,6) = md->master->bl.id;
  7003. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION), false);
  7004. }
  7005. else
  7006. {
  7007. int i;
  7008. struct map_session_data *sd = BL_CAST(BL_PC,src);
  7009. if( sd == NULL )
  7010. return;
  7011. for( i = 0; i < 5 /*MAX_DEVOTION*/; i++ ) // Client only able show to 5 links
  7012. WBUFL(buf,6+4*i) = sd->devotion[i];
  7013. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION), false);
  7014. }
  7015. if( tsd )
  7016. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  7017. else
  7018. clif_send(buf, packet_len(0x1cf), src, AREA);
  7019. }
  7020. /*==========================================
  7021. * Server tells clients nearby 'sd' (and himself) to display 'sd->spiritball' number of spiritballs on 'sd'
  7022. * Notifies clients in an area of an object's spirits.
  7023. * 01d0 <id>.L <amount>.W (ZC_SPIRITS)
  7024. * 01e1 <id>.L <amount>.W (ZC_SPIRITS2)
  7025. *------------------------------------------*/
  7026. void clif_spiritball(struct block_list *bl) {
  7027. unsigned char buf[16];
  7028. TBL_PC *sd = BL_CAST(BL_PC,bl);
  7029. TBL_HOM *hd = BL_CAST(BL_HOM,bl);
  7030. nullpo_retv(bl);
  7031. WBUFW(buf, 0) = 0x1d0;
  7032. WBUFL(buf, 2) = bl->id;
  7033. WBUFW(buf, 6) = 0; //init to 0
  7034. switch(bl->type){
  7035. case BL_PC: WBUFW(buf, 6) = sd->spiritball; break;
  7036. case BL_HOM: WBUFW(buf, 6) = hd->homunculus.spiritball; break;
  7037. }
  7038. clif_send(buf, packet_len(0x1d0), bl, AREA);
  7039. }
  7040. /// Notifies clients in area of a character's combo delay (ZC_COMBODELAY).
  7041. /// 01d2 <account id>.L <delay>.L
  7042. void clif_combo_delay(struct block_list *bl,int wait)
  7043. {
  7044. unsigned char buf[32];
  7045. nullpo_retv(bl);
  7046. WBUFW(buf,0)=0x1d2;
  7047. WBUFL(buf,2)=bl->id;
  7048. WBUFL(buf,6)=wait;
  7049. clif_send(buf,packet_len(0x1d2),bl,AREA);
  7050. }
  7051. /// Notifies clients in area that a character has blade-stopped another (ZC_BLADESTOP).
  7052. /// 01d1 <src id>.L <dst id>.L <flag>.L
  7053. /// flag:
  7054. /// 0 = inactive
  7055. /// 1 = active
  7056. void clif_bladestop(struct block_list *src, int dst_id, int active)
  7057. {
  7058. unsigned char buf[32];
  7059. nullpo_retv(src);
  7060. WBUFW(buf,0)=0x1d1;
  7061. WBUFL(buf,2)=src->id;
  7062. WBUFL(buf,6)=dst_id;
  7063. WBUFL(buf,10)=active;
  7064. clif_send(buf,packet_len(0x1d1),src,AREA);
  7065. }
  7066. /// MVP effect (ZC_MVP).
  7067. /// 010c <account id>.L
  7068. void clif_mvp_effect(struct map_session_data *sd)
  7069. {
  7070. unsigned char buf[16];
  7071. nullpo_retv(sd);
  7072. WBUFW(buf,0)=0x10c;
  7073. WBUFL(buf,2)=sd->bl.id;
  7074. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  7075. }
  7076. /// MVP item reward message (ZC_MVP_GETTING_ITEM).
  7077. /// 010a <name id>.W
  7078. void clif_mvp_item(struct map_session_data *sd, unsigned short nameid)
  7079. {
  7080. int view,fd;
  7081. nullpo_retv(sd);
  7082. fd=sd->fd;
  7083. WFIFOHEAD(fd,packet_len(0x10a));
  7084. WFIFOW(fd,0)=0x10a;
  7085. if((view = itemdb_viewid(nameid)) > 0)
  7086. WFIFOW(fd,2)=view;
  7087. else
  7088. WFIFOW(fd,2)=nameid;
  7089. WFIFOSET(fd,packet_len(0x10a));
  7090. }
  7091. /// MVP EXP reward message (ZC_MVP_GETTING_SPECIAL_EXP).
  7092. /// 010b <exp>.L
  7093. void clif_mvp_exp(struct map_session_data *sd, unsigned int exp) {
  7094. #if PACKETVER >= 20131223 // Kro remove this packet [Napster]
  7095. if (battle_config.mvp_exp_reward_message) {
  7096. char e_msg[CHAT_SIZE_MAX];
  7097. sprintf(e_msg, msg_txt(sd, 717), exp);
  7098. clif_messagecolor(&sd->bl, color_table[COLOR_CYAN], e_msg, false, SELF); // Congratulations! You are the MVP! Your reward EXP Points are %u !!
  7099. }
  7100. #else
  7101. int fd;
  7102. nullpo_retv(sd);
  7103. fd = sd->fd;
  7104. WFIFOHEAD(fd, packet_len(0x10b));
  7105. WFIFOW(fd,0) = 0x10b;
  7106. WFIFOL(fd,2) = min(exp, (unsigned int)INT32_MAX);
  7107. WFIFOSET(fd, packet_len(0x10b));
  7108. #endif
  7109. }
  7110. /// Dropped MVP item reward message (ZC_THROW_MVPITEM).
  7111. /// 010d
  7112. ///
  7113. /// "You are the MVP, but cannot obtain the reward because
  7114. /// you are overweight."
  7115. void clif_mvp_noitem(struct map_session_data* sd)
  7116. {
  7117. int fd = sd->fd;
  7118. WFIFOHEAD(fd,packet_len(0x10d));
  7119. WFIFOW(fd,0) = 0x10d;
  7120. WFIFOSET(fd,packet_len(0x10d));
  7121. }
  7122. /// Guild creation result (ZC_RESULT_MAKE_GUILD).
  7123. /// 0167 <result>.B
  7124. /// result:
  7125. /// 0 = "Guild has been created."
  7126. /// 1 = "You are already in a Guild."
  7127. /// 2 = "That Guild Name already exists."
  7128. /// 3 = "You need the neccessary item to create a Guild."
  7129. void clif_guild_created(struct map_session_data *sd,int flag)
  7130. {
  7131. int fd;
  7132. nullpo_retv(sd);
  7133. fd=sd->fd;
  7134. WFIFOHEAD(fd,packet_len(0x167));
  7135. WFIFOW(fd,0)=0x167;
  7136. WFIFOB(fd,2)=flag;
  7137. WFIFOSET(fd,packet_len(0x167));
  7138. }
  7139. /// Notifies the client that it is belonging to a guild (ZC_UPDATE_GDID).
  7140. /// 016c <guild id>.L <emblem id>.L <mode>.L <ismaster>.B <inter sid>.L <guild name>.24B
  7141. /// mode:
  7142. /// &0x01 = allow invite
  7143. /// &0x10 = allow expel
  7144. void clif_guild_belonginfo(struct map_session_data *sd)
  7145. {
  7146. int ps,fd;
  7147. struct guild* g;
  7148. nullpo_retv(sd);
  7149. nullpo_retv(g = sd->guild);
  7150. fd=sd->fd;
  7151. ps=guild_getposition(sd);
  7152. WFIFOHEAD(fd,packet_len(0x16c));
  7153. WFIFOW(fd,0)=0x16c;
  7154. WFIFOL(fd,2)=g->guild_id;
  7155. WFIFOL(fd,6)=g->emblem_id;
  7156. WFIFOL(fd,10)=g->position[ps].mode;
  7157. WFIFOB(fd,14)=(bool)(sd->state.gmaster_flag==1);
  7158. WFIFOL(fd,15)=0; // InterSID (unknown purpose)
  7159. safestrncpy(WFIFOCP(fd,19),g->name,NAME_LENGTH);
  7160. WFIFOSET(fd,packet_len(0x16c));
  7161. }
  7162. /// Guild member login notice.
  7163. /// 016d <account id>.L <char id>.L <status>.L (ZC_UPDATE_CHARSTAT)
  7164. /// 01f2 <account id>.L <char id>.L <status>.L <gender>.W <hair style>.W <hair color>.W (ZC_UPDATE_CHARSTAT2)
  7165. /// status:
  7166. /// 0 = offline
  7167. /// 1 = online
  7168. void clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  7169. {
  7170. unsigned char buf[64];
  7171. struct map_session_data* sd;
  7172. nullpo_retv(g);
  7173. WBUFW(buf, 0)=0x1f2;
  7174. WBUFL(buf, 2)=g->member[idx].account_id;
  7175. WBUFL(buf, 6)=g->member[idx].char_id;
  7176. WBUFL(buf,10)=flag;
  7177. if( ( sd = g->member[idx].sd ) != NULL )
  7178. {
  7179. WBUFW(buf,14) = sd->status.sex;
  7180. WBUFW(buf,16) = sd->status.hair;
  7181. WBUFW(buf,18) = sd->status.hair_color;
  7182. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD_WOS);
  7183. }
  7184. else if( ( sd = guild_getavailablesd(g) ) != NULL )
  7185. {
  7186. WBUFW(buf,14) = 0;
  7187. WBUFW(buf,16) = 0;
  7188. WBUFW(buf,18) = 0;
  7189. clif_send(buf,packet_len(0x1f2),&sd->bl,GUILD);
  7190. }
  7191. }
  7192. // Function `clif_guild_memberlogin_notice` sends info about
  7193. // logins and logouts of a guild member to the rest members.
  7194. // But at the 1st time (after a player login or map changing)
  7195. // the client won't show the message.
  7196. // So I suggest use this function for sending "first-time-info"
  7197. // to some player on entering the game or changing location.
  7198. // At next time the client would always show the message.
  7199. // The function sends all the statuses in the single packet
  7200. // to economize traffic. [LuzZza]
  7201. void clif_guild_send_onlineinfo(struct map_session_data *sd)
  7202. {
  7203. struct guild *g;
  7204. unsigned char buf[14*128];
  7205. int i, count=0, p_len;
  7206. nullpo_retv(sd);
  7207. p_len = packet_len(0x16d);
  7208. if(!(g = sd->guild))
  7209. return;
  7210. for(i=0; i<g->max_member; i++) {
  7211. if(g->member[i].account_id > 0 &&
  7212. g->member[i].account_id != sd->status.account_id) {
  7213. WBUFW(buf,count*p_len) = 0x16d;
  7214. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  7215. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  7216. WBUFL(buf,count*p_len+10) = g->member[i].online;
  7217. count++;
  7218. }
  7219. }
  7220. clif_send(buf, p_len*count, &sd->bl, SELF);
  7221. }
  7222. /// Bitmask of enabled guild window tabs (ZC_ACK_GUILD_MENUINTERFACE).
  7223. /// 014e <menu flag>.L
  7224. /// menu flag:
  7225. /// 0x00 = Basic Info (always on)
  7226. /// &0x01 = Member manager
  7227. /// &0x02 = Positions
  7228. /// &0x04 = Skills
  7229. /// &0x10 = Expulsion list
  7230. /// &0x40 = Unknown (GMENUFLAG_ALLGUILDLIST)
  7231. /// &0x80 = Notice
  7232. void clif_guild_masterormember(struct map_session_data *sd)
  7233. {
  7234. int fd;
  7235. nullpo_retv(sd);
  7236. fd=sd->fd;
  7237. WFIFOHEAD(fd,packet_len(0x14e));
  7238. WFIFOW(fd,0) = 0x14e;
  7239. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  7240. WFIFOSET(fd,packet_len(0x14e));
  7241. }
  7242. /// Guild basic information (Territories [Valaris])
  7243. /// 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)
  7244. /// 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)
  7245. /// 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)
  7246. void clif_guild_basicinfo(struct map_session_data *sd) {
  7247. int fd;
  7248. struct guild *g;
  7249. #if PACKETVER < 20160622
  7250. int cmd = 0x1b6;
  7251. int offset = NAME_LENGTH;
  7252. #else
  7253. int cmd = 0xa84;
  7254. int offset = 0;
  7255. #endif
  7256. nullpo_retv(sd);
  7257. fd = sd->fd;
  7258. if( (g = sd->guild) == NULL )
  7259. return;
  7260. WFIFOHEAD(fd,packet_len(cmd));
  7261. WFIFOW(fd, 0)=cmd;
  7262. WFIFOL(fd, 2)=g->guild_id;
  7263. WFIFOL(fd, 6)=g->guild_lv;
  7264. WFIFOL(fd,10)=g->connect_member;
  7265. WFIFOL(fd,14)=g->max_member;
  7266. WFIFOL(fd,18)=g->average_lv;
  7267. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT32_MAX);
  7268. WFIFOL(fd,26)=g->next_exp;
  7269. WFIFOL(fd,30)=0; // Tax Points
  7270. WFIFOL(fd,34)=0; // Honor: (left) Vulgar [-100,100] Famed (right)
  7271. WFIFOL(fd,38)=0; // Virtue: (down) Wicked [-100,100] Righteous (up)
  7272. WFIFOL(fd,42)=g->emblem_id;
  7273. safestrncpy(WFIFOCP(fd,46),g->name, NAME_LENGTH);
  7274. #if PACKETVER < 20160622
  7275. safestrncpy(WFIFOCP(fd,70),g->master, NAME_LENGTH);
  7276. #endif
  7277. safestrncpy(WFIFOCP(fd,70+offset),msg_txt(sd,300+guild_checkcastles(g)),16); // "'N' castles"
  7278. WFIFOL(fd,70+offset+16) = 0; // zeny
  7279. #if PACKETVER >= 20160622
  7280. WFIFOL(fd,70+offset+20) = g->member[0].char_id; // leader
  7281. #endif
  7282. WFIFOSET(fd,packet_len(cmd));
  7283. }
  7284. /// Guild alliance and opposition list (ZC_MYGUILD_BASIC_INFO).
  7285. /// 014c <packet len>.W { <relation>.L <guild id>.L <guild name>.24B }*
  7286. void clif_guild_allianceinfo(struct map_session_data *sd)
  7287. {
  7288. int fd,i,c;
  7289. struct guild *g;
  7290. nullpo_retv(sd);
  7291. if( (g = sd->guild) == NULL )
  7292. return;
  7293. fd = sd->fd;
  7294. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  7295. WFIFOW(fd, 0)=0x14c;
  7296. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  7297. struct guild_alliance *a=&g->alliance[i];
  7298. if(a->guild_id>0){
  7299. WFIFOL(fd,c*32+4)=a->opposition;
  7300. WFIFOL(fd,c*32+8)=a->guild_id;
  7301. safestrncpy(WFIFOCP(fd,c*32+12),a->name,NAME_LENGTH);
  7302. c++;
  7303. }
  7304. }
  7305. WFIFOW(fd, 2)=c*32+4;
  7306. WFIFOSET(fd,WFIFOW(fd,2));
  7307. }
  7308. /// Guild member manager information
  7309. /// 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)
  7310. /// state:
  7311. /// 0 = offline
  7312. /// 1 = online
  7313. /// memo:
  7314. /// probably member's self-introduction (unused, no client UI/packets for editing it)
  7315. /// 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)
  7316. void clif_guild_memberlist(struct map_session_data *sd)
  7317. {
  7318. int fd;
  7319. int i,c;
  7320. struct guild *g;
  7321. #if PACKETVER < 20161026
  7322. int cmd = 0x154;
  7323. int size = 104;
  7324. #else
  7325. int cmd = 0xaa5;
  7326. int size = 34;
  7327. #endif
  7328. nullpo_retv(sd);
  7329. if( (fd = sd->fd) == 0 )
  7330. return;
  7331. if( (g = sd->guild) == NULL )
  7332. return;
  7333. WFIFOHEAD(fd, g->max_member * size + 4);
  7334. WFIFOW(fd, 0)=cmd;
  7335. for(i=0,c=0;i<g->max_member;i++){
  7336. struct guild_member *m=&g->member[i];
  7337. if(m->account_id==0)
  7338. continue;
  7339. WFIFOL(fd,c*size+ 4)=m->account_id;
  7340. WFIFOL(fd,c*size+ 8)=m->char_id;
  7341. WFIFOW(fd,c*size+12)=m->hair;
  7342. WFIFOW(fd,c*size+14)=m->hair_color;
  7343. WFIFOW(fd,c*size+16)=m->gender;
  7344. WFIFOW(fd,c*size+18)=m->class_;
  7345. WFIFOW(fd,c*size+20)=m->lv;
  7346. WFIFOL(fd,c*size+22)=(int)cap_value(m->exp,0,INT32_MAX);
  7347. WFIFOL(fd,c*size+26)=m->online;
  7348. WFIFOL(fd,c*size+30)=m->position;
  7349. #if PACKETVER < 20161026
  7350. 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.
  7351. safestrncpy(WFIFOCP(fd,c*size+84),m->name,NAME_LENGTH);
  7352. #else
  7353. WFIFOL(fd,c*size+34)=m->last_login;
  7354. #endif
  7355. c++;
  7356. }
  7357. WFIFOW(fd, 2)=c*size+4;
  7358. WFIFOSET(fd,WFIFOW(fd,2));
  7359. }
  7360. /// Guild position name information (ZC_POSITION_ID_NAME_INFO).
  7361. /// 0166 <packet len>.W { <position id>.L <position name>.24B }*
  7362. void clif_guild_positionnamelist(struct map_session_data *sd)
  7363. {
  7364. int i,fd;
  7365. struct guild *g;
  7366. nullpo_retv(sd);
  7367. if( (g = sd->guild) == NULL )
  7368. return;
  7369. fd = sd->fd;
  7370. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  7371. WFIFOW(fd, 0)=0x166;
  7372. for(i=0;i<MAX_GUILDPOSITION;i++){
  7373. WFIFOL(fd,i*28+4)=i;
  7374. safestrncpy(WFIFOCP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  7375. }
  7376. WFIFOW(fd,2)=i*28+4;
  7377. WFIFOSET(fd,WFIFOW(fd,2));
  7378. }
  7379. /// Guild position information (ZC_POSITION_INFO).
  7380. /// 0160 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L }*
  7381. /// mode:
  7382. /// &0x01 = allow invite
  7383. /// &0x10 = allow expel
  7384. /// ranking:
  7385. /// TODO
  7386. void clif_guild_positioninfolist(struct map_session_data *sd)
  7387. {
  7388. int i,fd;
  7389. struct guild *g;
  7390. nullpo_retv(sd);
  7391. if( (g = sd->guild) == NULL )
  7392. return;
  7393. fd = sd->fd;
  7394. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  7395. WFIFOW(fd, 0)=0x160;
  7396. for(i=0;i<MAX_GUILDPOSITION;i++){
  7397. struct guild_position *p=&g->position[i];
  7398. WFIFOL(fd,i*16+ 4)=i;
  7399. WFIFOL(fd,i*16+ 8)=p->mode;
  7400. WFIFOL(fd,i*16+12)=i;
  7401. WFIFOL(fd,i*16+16)=p->exp_mode;
  7402. }
  7403. WFIFOW(fd, 2)=i*16+4;
  7404. WFIFOSET(fd,WFIFOW(fd,2));
  7405. }
  7406. /// Notifies clients in a guild about updated position information (ZC_ACK_CHANGE_GUILD_POSITIONINFO).
  7407. /// 0174 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <position name>.24B }*
  7408. /// mode:
  7409. /// &0x01 = allow invite
  7410. /// &0x10 = allow expel
  7411. /// ranking:
  7412. /// TODO
  7413. void clif_guild_positionchanged(struct guild *g,int idx)
  7414. {
  7415. // FIXME: This packet is intended to update the clients after a
  7416. // commit of position info changes, not sending one packet per
  7417. // position.
  7418. struct map_session_data *sd;
  7419. unsigned char buf[128];
  7420. nullpo_retv(g);
  7421. WBUFW(buf, 0)=0x174;
  7422. WBUFW(buf, 2)=44; // packet len
  7423. // GUILD_REG_POSITION_INFO{
  7424. WBUFL(buf, 4)=idx;
  7425. WBUFL(buf, 8)=g->position[idx].mode;
  7426. WBUFL(buf,12)=idx;
  7427. WBUFL(buf,16)=g->position[idx].exp_mode;
  7428. safestrncpy(WBUFCP(buf,20),g->position[idx].name,NAME_LENGTH);
  7429. // }*
  7430. if( (sd=guild_getavailablesd(g))!=NULL )
  7431. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7432. }
  7433. /// Notifies clients in a guild about updated member position assignments (ZC_ACK_REQ_CHANGE_MEMBERS).
  7434. /// 0156 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  7435. void clif_guild_memberpositionchanged(struct guild *g,int idx)
  7436. {
  7437. // FIXME: This packet is intended to update the clients after a
  7438. // commit of member position assignment changes, not sending one
  7439. // packet per position.
  7440. struct map_session_data *sd;
  7441. unsigned char buf[64];
  7442. nullpo_retv(g);
  7443. WBUFW(buf, 0)=0x156;
  7444. WBUFW(buf, 2)=16; // packet len
  7445. // MEMBER_POSITION_INFO{
  7446. WBUFL(buf, 4)=g->member[idx].account_id;
  7447. WBUFL(buf, 8)=g->member[idx].char_id;
  7448. WBUFL(buf,12)=g->member[idx].position;
  7449. // }*
  7450. if( (sd=guild_getavailablesd(g))!=NULL )
  7451. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  7452. }
  7453. /// Sends emblems bitmap data to the client that requested it (ZC_GUILD_EMBLEM_IMG).
  7454. /// 0152 <packet len>.W <guild id>.L <emblem id>.L <emblem data>.?B
  7455. void clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  7456. {
  7457. int fd;
  7458. nullpo_retv(sd);
  7459. nullpo_retv(g);
  7460. fd = sd->fd;
  7461. if( g->emblem_len <= 0 )
  7462. return;
  7463. WFIFOHEAD(fd,g->emblem_len+12);
  7464. WFIFOW(fd,0)=0x152;
  7465. WFIFOW(fd,2)=g->emblem_len+12;
  7466. WFIFOL(fd,4)=g->guild_id;
  7467. WFIFOL(fd,8)=g->emblem_id;
  7468. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  7469. WFIFOSET(fd,WFIFOW(fd,2));
  7470. }
  7471. /// Sends update of the guild id/emblem id to everyone in the area (ZC_CHANGE_GUILD).
  7472. /// 01b4 <id>.L <guild id>.L <emblem id>.W
  7473. void clif_guild_emblem_area(struct block_list* bl)
  7474. {
  7475. uint8 buf[12];
  7476. nullpo_retv(bl);
  7477. // TODO this packet doesn't force the update of ui components that have the emblem visible
  7478. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  7479. WBUFW(buf,0) = 0x1b4;
  7480. WBUFL(buf,2) = bl->id;
  7481. WBUFL(buf,6) = status_get_guild_id(bl);
  7482. WBUFW(buf,10) = status_get_emblem_id(bl);
  7483. clif_send(buf, 12, bl, AREA_WOS);
  7484. }
  7485. /// Sends guild skills (ZC_GUILD_SKILLINFO).
  7486. /// 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 }*
  7487. void clif_guild_skillinfo(struct map_session_data* sd)
  7488. {
  7489. int fd;
  7490. struct guild* g;
  7491. int i,c;
  7492. nullpo_retv(sd);
  7493. if( (g = sd->guild) == NULL )
  7494. return;
  7495. fd = sd->fd;
  7496. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  7497. WFIFOW(fd,0) = 0x0162;
  7498. WFIFOW(fd,4) = g->skill_point;
  7499. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  7500. {
  7501. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  7502. {
  7503. int id = g->skill[i].id;
  7504. int p = 6 + c*37;
  7505. WFIFOW(fd,p+0) = id;
  7506. WFIFOL(fd,p+2) = skill_get_inf(id);
  7507. WFIFOW(fd,p+6) = g->skill[i].lv;
  7508. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  7509. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  7510. safestrncpy(WFIFOCP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  7511. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  7512. c++;
  7513. }
  7514. }
  7515. WFIFOW(fd,2) = 6 + c*37;
  7516. WFIFOSET(fd,WFIFOW(fd,2));
  7517. }
  7518. /// Sends guild notice to client (ZC_GUILD_NOTICE).
  7519. /// 016f <subject>.60B <notice>.120B
  7520. void clif_guild_notice(struct map_session_data* sd)
  7521. {
  7522. int fd;
  7523. struct guild* g;
  7524. nullpo_retv(sd);
  7525. nullpo_retv(g = sd->guild);
  7526. fd = sd->fd;
  7527. if ( !session_isActive(fd) )
  7528. return;
  7529. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  7530. return;
  7531. WFIFOHEAD(fd,packet_len(0x16f));
  7532. WFIFOW(fd,0) = 0x16f;
  7533. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  7534. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  7535. WFIFOSET(fd,packet_len(0x16f));
  7536. }
  7537. /// Guild invite (ZC_REQ_JOIN_GUILD).
  7538. /// 016a <guild id>.L <guild name>.24B
  7539. void clif_guild_invite(struct map_session_data *sd,struct guild *g)
  7540. {
  7541. int fd;
  7542. nullpo_retv(sd);
  7543. nullpo_retv(g);
  7544. fd=sd->fd;
  7545. WFIFOHEAD(fd,packet_len(0x16a));
  7546. WFIFOW(fd,0)=0x16a;
  7547. WFIFOL(fd,2)=g->guild_id;
  7548. safestrncpy(WFIFOCP(fd,6),g->name,NAME_LENGTH);
  7549. WFIFOSET(fd,packet_len(0x16a));
  7550. }
  7551. /// Reply to invite request (ZC_ACK_REQ_JOIN_GUILD).
  7552. /// 0169 <answer>.B
  7553. /// answer:
  7554. /// 0 = Already in guild.
  7555. /// 1 = Offer rejected.
  7556. /// 2 = Offer accepted.
  7557. /// 3 = Guild full.
  7558. void clif_guild_inviteack(struct map_session_data *sd,int flag)
  7559. {
  7560. int fd;
  7561. nullpo_retv(sd);
  7562. fd=sd->fd;
  7563. WFIFOHEAD(fd,packet_len(0x169));
  7564. WFIFOW(fd,0)=0x169;
  7565. WFIFOB(fd,2)=flag;
  7566. WFIFOSET(fd,packet_len(0x169));
  7567. }
  7568. /// Notifies clients of a guild of a leaving member (ZC_ACK_LEAVE_GUILD).
  7569. /// 015a <char name>.24B <reason>.40B
  7570. void clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  7571. {
  7572. unsigned char buf[128];
  7573. nullpo_retv(sd);
  7574. WBUFW(buf, 0)=0x15a;
  7575. safestrncpy(WBUFCP(buf, 2),name,NAME_LENGTH);
  7576. memcpy(WBUFP(buf,26),mes,40);
  7577. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  7578. }
  7579. /// Notifies clients of a guild of an expelled member.
  7580. /// 015c <char name>.24B <reason>.40B <account name>.24B (ZC_ACK_BAN_GUILD)
  7581. /// 0839 <char name>.24B <reason>.40B (ZC_ACK_BAN_GUILD_SSO)
  7582. void clif_guild_expulsion(struct map_session_data* sd, const char* name, const char* mes, uint32 account_id)
  7583. {
  7584. unsigned char buf[128];
  7585. #if PACKETVER < 20100803
  7586. const unsigned short cmd = 0x15c;
  7587. #else
  7588. const unsigned short cmd = 0x839;
  7589. #endif
  7590. nullpo_retv(sd);
  7591. WBUFW(buf,0) = cmd;
  7592. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  7593. safestrncpy(WBUFCP(buf,26), mes, 40);
  7594. #if PACKETVER < 20100803
  7595. memset(WBUFP(buf,66), 0, NAME_LENGTH); // account name (not used for security reasons)
  7596. #endif
  7597. clif_send(buf, packet_len(cmd), &sd->bl, GUILD_NOBG);
  7598. }
  7599. /// Guild expulsion list (ZC_BAN_LIST).
  7600. /// 0163 <packet len>.W { <char name>.24B <account name>.24B <reason>.40B }*
  7601. /// 0163 <packet len>.W { <char name>.24B <reason>.40B }* (PACKETVER >= 20100803)
  7602. void clif_guild_expulsionlist(struct map_session_data* sd)
  7603. {
  7604. #if PACKETVER < 20100803
  7605. const int offset = NAME_LENGTH*2+40;
  7606. #else
  7607. const int offset = NAME_LENGTH+40;
  7608. #endif
  7609. int fd, i, c = 0;
  7610. struct guild* g;
  7611. nullpo_retv(sd);
  7612. if( (g = sd->guild) == NULL )
  7613. return;
  7614. fd = sd->fd;
  7615. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * offset);
  7616. WFIFOW(fd,0) = 0x163;
  7617. for( i = 0; i < MAX_GUILDEXPULSION; i++ )
  7618. {
  7619. struct guild_expulsion* e = &g->expulsion[i];
  7620. if( e->account_id > 0 )
  7621. {
  7622. safestrncpy(WFIFOCP(fd,4 + c*offset), e->name, NAME_LENGTH);
  7623. #if PACKETVER < 20100803
  7624. memset(WFIFOP(fd,4 + c*offset+24), 0, NAME_LENGTH); // account name (not used for security reasons)
  7625. memcpy(WFIFOP(fd,4 + c*offset+48), e->mes, 40);
  7626. #else
  7627. memcpy(WFIFOP(fd,4 + c*offset+24), e->mes, 40);
  7628. #endif
  7629. c++;
  7630. }
  7631. }
  7632. WFIFOW(fd,2) = 4 + c*offset;
  7633. WFIFOSET(fd,WFIFOW(fd,2));
  7634. }
  7635. /// Guild chat message (ZC_GUILD_CHAT).
  7636. /// 017f <packet len>.W <message>.?B
  7637. void clif_guild_message(struct guild *g,uint32 account_id,const char *mes,int len)
  7638. {// TODO: account_id is not used, candidate for deletion? [Ai4rei]
  7639. struct map_session_data *sd;
  7640. uint8 buf[256];
  7641. if( len == 0 )
  7642. {
  7643. return;
  7644. }
  7645. else if( len > sizeof(buf)-5 )
  7646. {
  7647. ShowWarning("clif_guild_message: Truncated message '%s' (len=%d, max=%d, guild_id=%d).\n", mes, len, sizeof(buf)-5, g->guild_id);
  7648. len = sizeof(buf)-5;
  7649. }
  7650. WBUFW(buf, 0) = 0x17f;
  7651. WBUFW(buf, 2) = len + 5;
  7652. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7653. if ((sd = guild_getavailablesd(g)) != NULL)
  7654. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  7655. }
  7656. /// Request for guild alliance (ZC_REQ_ALLY_GUILD).
  7657. /// 0171 <inviter account id>.L <guild name>.24B
  7658. void clif_guild_reqalliance(struct map_session_data *sd,uint32 account_id,const char *name)
  7659. {
  7660. int fd;
  7661. nullpo_retv(sd);
  7662. fd=sd->fd;
  7663. WFIFOHEAD(fd,packet_len(0x171));
  7664. WFIFOW(fd,0)=0x171;
  7665. WFIFOL(fd,2)=account_id;
  7666. safestrncpy(WFIFOCP(fd,6),name,NAME_LENGTH);
  7667. WFIFOSET(fd,packet_len(0x171));
  7668. }
  7669. /// Notifies the client about the result of a alliance request (ZC_ACK_REQ_ALLY_GUILD).
  7670. /// 0173 <answer>.B
  7671. /// answer:
  7672. /// 0 = Already allied.
  7673. /// 1 = You rejected the offer.
  7674. /// 2 = You accepted the offer.
  7675. /// 3 = They have too any alliances.
  7676. /// 4 = You have too many alliances.
  7677. /// 5 = Alliances are disabled.
  7678. void clif_guild_allianceack(struct map_session_data *sd,int flag)
  7679. {
  7680. int fd;
  7681. nullpo_retv(sd);
  7682. fd=sd->fd;
  7683. WFIFOHEAD(fd,packet_len(0x173));
  7684. WFIFOW(fd,0)=0x173;
  7685. WFIFOL(fd,2)=flag;
  7686. WFIFOSET(fd,packet_len(0x173));
  7687. }
  7688. /// Notifies the client that a alliance or opposition has been removed (ZC_DELETE_RELATED_GUILD).
  7689. /// 0184 <other guild id>.L <relation>.L
  7690. /// relation:
  7691. /// 0 = Ally
  7692. /// 1 = Enemy
  7693. void clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  7694. {
  7695. int fd;
  7696. nullpo_retv(sd);
  7697. fd = sd->fd;
  7698. if (fd <= 0)
  7699. return;
  7700. WFIFOHEAD(fd,packet_len(0x184));
  7701. WFIFOW(fd,0)=0x184;
  7702. WFIFOL(fd,2)=guild_id;
  7703. WFIFOL(fd,6)=flag;
  7704. WFIFOSET(fd,packet_len(0x184));
  7705. }
  7706. /// Notifies the client about the result of a opposition request (ZC_ACK_REQ_HOSTILE_GUILD).
  7707. /// 0181 <result>.B
  7708. /// result:
  7709. /// 0 = Antagonist has been set.
  7710. /// 1 = Guild has too many Antagonists.
  7711. /// 2 = Already set as an Antagonist.
  7712. /// 3 = Antagonists are disabled.
  7713. void clif_guild_oppositionack(struct map_session_data *sd,int flag)
  7714. {
  7715. int fd;
  7716. nullpo_retv(sd);
  7717. fd=sd->fd;
  7718. WFIFOHEAD(fd,packet_len(0x181));
  7719. WFIFOW(fd,0)=0x181;
  7720. WFIFOB(fd,2)=flag;
  7721. WFIFOSET(fd,packet_len(0x181));
  7722. }
  7723. /// Adds alliance or opposition (ZC_ADD_RELATED_GUILD).
  7724. /// 0185 <relation>.L <guild id>.L <guild name>.24B
  7725. /*
  7726. void clif_guild_allianceadded(struct guild *g,int idx)
  7727. {
  7728. unsigned char buf[64];
  7729. WBUFW(buf,0)=0x185;
  7730. WBUFL(buf,2)=g->alliance[idx].opposition;
  7731. WBUFL(buf,6)=g->alliance[idx].guild_id;
  7732. safestrncpy(WBUFP(buf,10),g->alliance[idx].name,NAME_LENGTH);
  7733. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  7734. }
  7735. */
  7736. /// Notifies the client about the result of a guild break (ZC_ACK_DISORGANIZE_GUILD_RESULT).
  7737. /// 015e <reason>.L
  7738. /// 0 = success
  7739. /// 1 = invalid key (guild name, @see clif_parse_GuildBreak)
  7740. /// 2 = there are still members in the guild
  7741. void clif_guild_broken(struct map_session_data *sd,int flag)
  7742. {
  7743. int fd;
  7744. nullpo_retv(sd);
  7745. fd=sd->fd;
  7746. WFIFOHEAD(fd,packet_len(0x15e));
  7747. WFIFOW(fd,0)=0x15e;
  7748. WFIFOL(fd,2)=flag;
  7749. WFIFOSET(fd,packet_len(0x15e));
  7750. }
  7751. /// Displays emotion on an object (ZC_EMOTION).
  7752. /// 00c0 <id>.L <type>.B
  7753. /// type:
  7754. /// enum emotion_type
  7755. void clif_emotion(struct block_list *bl,int type)
  7756. {
  7757. unsigned char buf[8];
  7758. nullpo_retv(bl);
  7759. WBUFW(buf,0)=0xc0;
  7760. WBUFL(buf,2)=bl->id;
  7761. WBUFB(buf,6)=type;
  7762. clif_send(buf,packet_len(0xc0),bl,AREA);
  7763. }
  7764. /// Displays the contents of a talkiebox trap (ZC_TALKBOX_CHATCONTENTS).
  7765. /// 0191 <id>.L <contents>.80B
  7766. void clif_talkiebox(struct block_list* bl, const char* talkie)
  7767. {
  7768. unsigned char buf[MESSAGE_SIZE+6];
  7769. nullpo_retv(bl);
  7770. WBUFW(buf,0) = 0x191;
  7771. WBUFL(buf,2) = bl->id;
  7772. safestrncpy(WBUFCP(buf,6),talkie,MESSAGE_SIZE);
  7773. clif_send(buf,packet_len(0x191),bl,AREA);
  7774. }
  7775. /// Displays wedding effect centered on an object (ZC_CONGRATULATION).
  7776. /// 01ea <id>.L
  7777. void clif_wedding_effect(struct block_list *bl)
  7778. {
  7779. unsigned char buf[6];
  7780. nullpo_retv(bl);
  7781. WBUFW(buf,0) = 0x1ea;
  7782. WBUFL(buf,2) = bl->id;
  7783. clif_send(buf, packet_len(0x1ea), bl, AREA);
  7784. }
  7785. /// Notifies the client of the name of the partner character (ZC_COUPLENAME).
  7786. /// 01e6 <partner name>.24B
  7787. void clif_callpartner(struct map_session_data *sd)
  7788. {
  7789. unsigned char buf[26];
  7790. nullpo_retv(sd);
  7791. WBUFW(buf,0) = 0x1e6;
  7792. if( sd->status.partner_id ) {
  7793. const char *p = map_charid2nick(sd->status.partner_id);
  7794. struct map_session_data *p_sd = pc_get_partner(sd);
  7795. if( p != NULL && p_sd != NULL && !p_sd->state.autotrade )
  7796. safestrncpy(WBUFCP(buf,2), p, NAME_LENGTH);
  7797. else
  7798. WBUFB(buf,2) = 0;
  7799. } else {// Send zero-length name if no partner, to initialize the client buffer.
  7800. WBUFB(buf,2) = 0;
  7801. }
  7802. clif_send(buf, packet_len(0x1e6), &sd->bl, AREA);
  7803. }
  7804. /// Initiates the partner "taming" process [DracoRPG] (ZC_START_COUPLE).
  7805. /// 01e4
  7806. /// This packet while still implemented by the client is no longer being officially used.
  7807. /*
  7808. void clif_marriage_process(struct map_session_data *sd)
  7809. {
  7810. int fd;
  7811. nullpo_retv(sd);
  7812. fd=sd->fd;
  7813. WFIFOHEAD(fd,packet_len(0x1e4));
  7814. WFIFOW(fd,0)=0x1e4;
  7815. WFIFOSET(fd,packet_len(0x1e4));
  7816. }
  7817. */
  7818. /// Notice of divorce (ZC_DIVORCE).
  7819. /// 0205 <partner name>.24B
  7820. void clif_divorced(struct map_session_data* sd, const char* name)
  7821. {
  7822. int fd;
  7823. nullpo_retv(sd);
  7824. fd=sd->fd;
  7825. WFIFOHEAD(fd,packet_len(0x205));
  7826. WFIFOW(fd,0)=0x205;
  7827. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7828. WFIFOSET(fd, packet_len(0x205));
  7829. }
  7830. /// Marriage proposal (ZC_REQ_COUPLE).
  7831. /// 01e2 <account id>.L <char id>.L <char name>.24B
  7832. /// This packet while still implemented by the client is no longer being officially used.
  7833. /*
  7834. void clif_marriage_proposal(int fd, struct map_session_data *sd, struct map_session_data* ssd)
  7835. {
  7836. nullpo_retv(sd);
  7837. WFIFOHEAD(fd,packet_len(0x1e2));
  7838. WFIFOW(fd,0) = 0x1e2;
  7839. WFIFOL(fd,2) = ssd->status.account_id;
  7840. WFIFOL(fd,6) = ssd->status.char_id;
  7841. safestrncpy(WFIFOCP(fd,10), ssd->status.name, NAME_LENGTH);
  7842. WFIFOSET(fd, packet_len(0x1e2));
  7843. }
  7844. */
  7845. /*==========================================
  7846. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  7847. *------------------------------------------*/
  7848. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  7849. {
  7850. unsigned char buf[256];
  7851. if( len == 0 ) {
  7852. return;
  7853. } else if( len > sizeof(buf)-5 ) {
  7854. ShowWarning("clif_disp_message: Truncated message '%s' (len=%d, max=%d, aid=%d).\n", mes, len, sizeof(buf)-5, src->id);
  7855. len = sizeof(buf)-5;
  7856. }
  7857. WBUFW(buf, 0) = 0x17f;
  7858. WBUFW(buf, 2) = len + 5;
  7859. safestrncpy(WBUFCP(buf,4), mes, len+1);
  7860. clif_send(buf, WBUFW(buf,2), src, target);
  7861. }
  7862. /// Notifies the client about the result of a request to disconnect another player (ZC_ACK_DISCONNECT_CHARACTER).
  7863. /// 00cd <result>.L (unknown packet version or invalid information at packet_len_table)
  7864. /// 00cd <result>.B
  7865. /// result:
  7866. /// 0 = failure
  7867. /// 1 = success
  7868. void clif_GM_kickack(struct map_session_data *sd, int id)
  7869. {
  7870. int fd;
  7871. nullpo_retv(sd);
  7872. fd = sd->fd;
  7873. WFIFOHEAD(fd,packet_len(0xcd));
  7874. WFIFOW(fd,0) = 0xcd;
  7875. WFIFOB(fd,2) = id; // FIXME: this is not account id
  7876. WFIFOSET(fd, packet_len(0xcd));
  7877. }
  7878. void clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd)
  7879. {
  7880. int fd;
  7881. nullpo_retv(tsd);
  7882. fd = tsd->fd;
  7883. if (sd == NULL)
  7884. tsd->state.keepshop = true;
  7885. if (fd > 0)
  7886. clif_authfail_fd(fd, 15);
  7887. else
  7888. map_quit(tsd);
  7889. if (sd)
  7890. clif_GM_kickack(sd, tsd->status.account_id);
  7891. }
  7892. /// Displays various manner-related status messages (ZC_ACK_GIVE_MANNER_POINT).
  7893. /// 014a <result>.L
  7894. /// result:
  7895. /// 0 = "A manner point has been successfully aligned."
  7896. /// 1 = MP_FAILURE_EXHAUST
  7897. /// 2 = MP_FAILURE_ALREADY_GIVING
  7898. /// 3 = "Chat Block has been applied by GM due to your ill-mannerous action."
  7899. /// 4 = "Automated Chat Block has been applied due to Anti-Spam System."
  7900. /// 5 = "You got a good point from %s."
  7901. void clif_manner_message(struct map_session_data* sd, uint32 type)
  7902. {
  7903. int fd;
  7904. nullpo_retv(sd);
  7905. fd = sd->fd;
  7906. WFIFOHEAD(fd,packet_len(0x14a));
  7907. WFIFOW(fd,0) = 0x14a;
  7908. WFIFOL(fd,2) = type;
  7909. WFIFOSET(fd, packet_len(0x14a));
  7910. }
  7911. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action (ZC_NOTIFY_MANNER_POINT_GIVEN).
  7912. /// 014b <type>.B <GM name>.24B
  7913. /// type:
  7914. /// 0 = positive (unmute)
  7915. /// 1 = negative (mute)
  7916. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  7917. {
  7918. int fd;
  7919. nullpo_retv(sd);
  7920. nullpo_retv(tsd);
  7921. fd = tsd->fd;
  7922. WFIFOHEAD(fd,packet_len(0x14b));
  7923. WFIFOW(fd,0) = 0x14b;
  7924. WFIFOB(fd,2) = type;
  7925. safestrncpy(WFIFOCP(fd,3), sd->status.name, NAME_LENGTH);
  7926. WFIFOSET(fd, packet_len(0x14b));
  7927. }
  7928. /// Notifies the client about the result of a request to allow/deny whispers from a player (ZC_SETTING_WHISPER_PC).
  7929. /// 00d1 <type>.B <result>.B
  7930. /// type:
  7931. /// 0 = /ex (deny)
  7932. /// 1 = /in (allow)
  7933. /// result:
  7934. /// 0 = success
  7935. /// 1 = failure
  7936. /// 2 = too many blocks
  7937. void clif_wisexin(struct map_session_data *sd,int type,int flag)
  7938. {
  7939. int fd;
  7940. nullpo_retv(sd);
  7941. fd=sd->fd;
  7942. WFIFOHEAD(fd,packet_len(0xd1));
  7943. WFIFOW(fd,0)=0xd1;
  7944. WFIFOB(fd,2)=type;
  7945. WFIFOB(fd,3)=flag;
  7946. WFIFOSET(fd,packet_len(0xd1));
  7947. }
  7948. /// Notifies the client about the result of a request to allow/deny whispers from anyone (ZC_SETTING_WHISPER_STATE).
  7949. /// 00d2 <type>.B <result>.B
  7950. /// type:
  7951. /// 0 = /exall (deny)
  7952. /// 1 = /inall (allow)
  7953. /// result:
  7954. /// 0 = success
  7955. /// 1 = failure
  7956. void clif_wisall(struct map_session_data *sd,int type,int flag)
  7957. {
  7958. int fd;
  7959. nullpo_retv(sd);
  7960. fd=sd->fd;
  7961. WFIFOHEAD(fd,packet_len(0xd2));
  7962. WFIFOW(fd,0)=0xd2;
  7963. WFIFOB(fd,2)=type;
  7964. WFIFOB(fd,3)=flag;
  7965. WFIFOSET(fd,packet_len(0xd2));
  7966. }
  7967. /// Play a BGM! [Rikter/Yommy] (ZC_PLAY_NPC_BGM).
  7968. /// 07fe <bgm>.24B
  7969. void clif_playBGM(struct map_session_data* sd, const char* name)
  7970. {
  7971. int fd;
  7972. nullpo_retv(sd);
  7973. fd = sd->fd;
  7974. WFIFOHEAD(fd,packet_len(0x7fe));
  7975. WFIFOW(fd,0) = 0x7fe;
  7976. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  7977. WFIFOSET(fd,packet_len(0x7fe));
  7978. }
  7979. /// Plays/stops a wave sound (ZC_SOUND).
  7980. /// 01d3 <file name>.24B <act>.B <term>.L <npc id>.L
  7981. /// file name:
  7982. /// relative to data\wav
  7983. /// act:
  7984. /// 0 = play (once)
  7985. /// 1 = play (repeat, does not work)
  7986. /// 2 = stops all sound instances of file name (does not work)
  7987. /// term:
  7988. /// unknown purpose, only relevant to act = 1
  7989. /// npc id:
  7990. /// The accustic direction of the sound is determined by the
  7991. /// relative position of the NPC to the player (3D sound).
  7992. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  7993. {
  7994. int fd;
  7995. nullpo_retv(sd);
  7996. nullpo_retv(bl);
  7997. fd = sd->fd;
  7998. WFIFOHEAD(fd,packet_len(0x1d3));
  7999. WFIFOW(fd,0) = 0x1d3;
  8000. safestrncpy(WFIFOCP(fd,2), name, NAME_LENGTH);
  8001. WFIFOB(fd,26) = type;
  8002. WFIFOL(fd,27) = 0;
  8003. WFIFOL(fd,31) = bl->id;
  8004. WFIFOSET(fd,packet_len(0x1d3));
  8005. }
  8006. void clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  8007. {
  8008. unsigned char buf[40];
  8009. nullpo_retv(bl);
  8010. WBUFW(buf,0) = 0x1d3;
  8011. safestrncpy(WBUFCP(buf,2), name, NAME_LENGTH);
  8012. WBUFB(buf,26) = type;
  8013. WBUFL(buf,27) = 0;
  8014. WBUFL(buf,31) = bl->id;
  8015. clif_send(buf, packet_len(0x1d3), bl, coverage);
  8016. }
  8017. /// Displays special effects (npcs, weather, etc) [Valaris] (ZC_NOTIFY_EFFECT2).
  8018. /// 01f3 <id>.L <effect id>.L
  8019. /// effect id:
  8020. /// @see doc/effect_list.txt
  8021. void clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  8022. {
  8023. unsigned char buf[24];
  8024. nullpo_retv(bl);
  8025. memset(buf, 0, packet_len(0x1f3));
  8026. WBUFW(buf,0) = 0x1f3;
  8027. WBUFL(buf,2) = bl->id;
  8028. WBUFL(buf,6) = type;
  8029. clif_send(buf, packet_len(0x1f3), bl, target);
  8030. if (disguised(bl)) {
  8031. WBUFL(buf,2) = -bl->id;
  8032. clif_send(buf, packet_len(0x1f3), bl, SELF);
  8033. }
  8034. }
  8035. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  8036. {
  8037. WFIFOHEAD(fd,10);
  8038. WFIFOW(fd,0) = 0x1f3;
  8039. WFIFOL(fd,2) = bl->id;
  8040. WFIFOL(fd,6) = type;
  8041. WFIFOSET(fd,10);
  8042. }
  8043. /// Notifies clients of an special/visual effect that accepts an value (ZC_NOTIFY_EFFECT3).
  8044. /// 0284 <id>.L <effect id>.L <num data>.L
  8045. /// effect id:
  8046. /// @see doc/effect_list.txt
  8047. /// num data:
  8048. /// effect-dependent value
  8049. void clif_specialeffect_value(struct block_list* bl, int effect_id, int num, send_target target)
  8050. {
  8051. uint8 buf[14];
  8052. WBUFW(buf,0) = 0x284;
  8053. WBUFL(buf,2) = bl->id;
  8054. WBUFL(buf,6) = effect_id;
  8055. WBUFL(buf,10) = num;
  8056. clif_send(buf, packet_len(0x284), bl, target);
  8057. if( disguised(bl) )
  8058. {
  8059. WBUFL(buf,2) = -bl->id;
  8060. clif_send(buf, packet_len(0x284), bl, SELF);
  8061. }
  8062. }
  8063. /// Monster/NPC color chat [SnakeDrak] (ZC_NPC_CHAT).
  8064. /// 02c1 <packet len>.W <id>.L <color>.L <message>.?B
  8065. 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) {
  8066. unsigned short msg_len = (unsigned short)(strlen(msg) + 1);
  8067. uint8 buf[CHAT_SIZE_MAX];
  8068. nullpo_retv(bl);
  8069. if (msg_len > sizeof(buf) - 12) {
  8070. ShowWarning("clif_messagecolor: Truncating too long message '%s' (len=%u).\n", msg, msg_len);
  8071. msg_len = sizeof(buf) - 12;
  8072. }
  8073. if (rgb2bgr)
  8074. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  8075. WBUFW(buf,0) = 0x2C1;
  8076. WBUFW(buf,2) = msg_len + 12;
  8077. WBUFL(buf,4) = bl->id;
  8078. WBUFL(buf,8) = color;
  8079. memcpy(WBUFCP(buf,12), msg, msg_len);
  8080. clif_send(buf, WBUFW(buf,2), (sd == NULL ? bl : &(sd->bl)), type);
  8081. }
  8082. /**
  8083. * Notifies the client that the storage window is still open
  8084. *
  8085. * Should only be used in cases where the client closed the
  8086. * storage window without server's consent
  8087. */
  8088. void clif_refresh_storagewindow(struct map_session_data *sd) {
  8089. // Notify the client that the storage is open
  8090. if( sd->state.storage_flag == 1 ) {
  8091. storage_sortitem(sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage));
  8092. clif_storagelist(sd, sd->storage.u.items_storage, ARRAYLENGTH(sd->storage.u.items_storage), storage_getName(0));
  8093. clif_updatestorageamount(sd, sd->storage.amount, MAX_STORAGE);
  8094. }
  8095. // Notify the client that the gstorage is open otherwise it will
  8096. // remain locked forever and nobody will be able to access it
  8097. if( sd->state.storage_flag == 2 ) {
  8098. struct s_storage *gstor = guild2storage2(sd->status.guild_id);
  8099. if( !gstor ) // Shouldn't happen. The information should already be at the map-server
  8100. intif_request_guild_storage(sd->status.account_id, sd->status.guild_id);
  8101. else {
  8102. storage_sortitem(gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild));
  8103. clif_storagelist(sd, gstor->u.items_guild, ARRAYLENGTH(gstor->u.items_guild), "Guild Storage");
  8104. clif_updatestorageamount(sd, gstor->amount, MAX_GUILD_STORAGE);
  8105. }
  8106. }
  8107. }
  8108. // refresh the client's screen, getting rid of any effects
  8109. void clif_refresh(struct map_session_data *sd)
  8110. {
  8111. nullpo_retv(sd);
  8112. clif_changemap(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  8113. clif_inventorylist(sd);
  8114. if(pc_iscarton(sd)) {
  8115. clif_cartlist(sd);
  8116. clif_updatestatus(sd,SP_CARTINFO);
  8117. }
  8118. clif_updatestatus(sd,SP_WEIGHT);
  8119. clif_updatestatus(sd,SP_MAXWEIGHT);
  8120. clif_updatestatus(sd,SP_STR);
  8121. clif_updatestatus(sd,SP_AGI);
  8122. clif_updatestatus(sd,SP_VIT);
  8123. clif_updatestatus(sd,SP_INT);
  8124. clif_updatestatus(sd,SP_DEX);
  8125. clif_updatestatus(sd,SP_LUK);
  8126. if (sd->spiritball)
  8127. clif_spiritball_single(sd->fd, sd);
  8128. if (sd->spiritcharm_type != CHARM_TYPE_NONE && sd->spiritcharm > 0)
  8129. clif_spiritcharm_single(sd->fd, sd);
  8130. if (sd->vd.cloth_color)
  8131. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8132. if (sd->vd.body_style)
  8133. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8134. if(hom_is_active(sd->hd))
  8135. clif_send_homdata(sd,SP_ACK,0);
  8136. if( sd->md ) {
  8137. clif_mercenary_info(sd);
  8138. clif_mercenary_skillblock(sd);
  8139. }
  8140. if( sd->ed )
  8141. clif_elemental_info(sd);
  8142. map_foreachinallrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  8143. clif_weather_check(sd);
  8144. if( sd->chatID )
  8145. chat_leavechat(sd,0);
  8146. if( sd->state.vending )
  8147. clif_openvending(sd, sd->bl.id, sd->vending);
  8148. if( pc_issit(sd) )
  8149. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  8150. if( pc_isdead(sd) ) // When you refresh, resend the death packet.
  8151. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  8152. else
  8153. clif_changed_dir(&sd->bl, SELF);
  8154. clif_efst_status_change_sub(&sd->bl,&sd->bl,SELF);
  8155. //Issue #2143
  8156. //Cancel Trading State
  8157. if (sd->state.trading)
  8158. trade_tradecancel(sd);
  8159. //Cancel Buying/Selling State
  8160. if (sd->state.buyingstore)
  8161. buyingstore_close(sd);
  8162. mail_clear(sd);
  8163. if( disguised(&sd->bl) ) {/* refresh-da */
  8164. short disguise = sd->disguise;
  8165. pc_disguise(sd, 0);
  8166. pc_disguise(sd, disguise);
  8167. }
  8168. clif_refresh_storagewindow(sd);
  8169. }
  8170. /// Updates the object's (bl) name on client.
  8171. /// Used to update when a char leaves a party/guild. [Skotlex]
  8172. /// Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  8173. /// 0095 <id>.L <char name>.24B (ZC_ACK_REQNAME)
  8174. /// 0195 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B (ZC_ACK_REQNAMEALL)
  8175. /// 0a30 <id>.L <char name>.24B <party name>.24B <guild name>.24B <position name>.24B <title ID>.L (ZC_ACK_REQNAMEALL2)
  8176. void clif_name( struct block_list* src, struct block_list *bl, send_target target ){
  8177. unsigned char buf[106];
  8178. int cmd = 0x95;
  8179. nullpo_retv(src);
  8180. nullpo_retv(bl);
  8181. WBUFW(buf,0) = cmd;
  8182. WBUFL(buf,2) = bl->id;
  8183. switch( bl->type )
  8184. {
  8185. case BL_PC:
  8186. {
  8187. struct map_session_data *sd = (struct map_session_data *)bl;
  8188. struct party_data *p = NULL;
  8189. #if PACKETVER >= 20150513
  8190. WBUFW(buf, 0) = cmd = 0xa30;
  8191. #else
  8192. WBUFW(buf, 0) = cmd = 0x195;
  8193. #endif
  8194. //Requesting your own "shadow" name. [Skotlex]
  8195. if( src == bl && target == SELF && sd->disguise ){
  8196. WBUFL(buf,2) = -bl->id;
  8197. }
  8198. if( sd->fakename[0] ) {
  8199. safestrncpy(WBUFCP(buf,6), sd->fakename, NAME_LENGTH);
  8200. WBUFB(buf,30) = WBUFB(buf,54) = WBUFB(buf,78) = 0;
  8201. #if PACKETVER >= 20150513
  8202. WBUFL(buf,102) = 0; // Title ID
  8203. #endif
  8204. break;
  8205. }
  8206. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  8207. if( sd->status.party_id ){
  8208. p = party_search(sd->status.party_id);
  8209. }
  8210. // do not display party unless the player is also in a guild
  8211. if( p && ( sd->guild || battle_config.display_party_name ) ){
  8212. safestrncpy(WBUFCP(buf,30), p->party.name, NAME_LENGTH);
  8213. }else{
  8214. WBUFB(buf,30) = 0;
  8215. }
  8216. if( sd->guild ){
  8217. int position;
  8218. // Will get the position of the guild the player is in
  8219. position = guild_getposition(sd);
  8220. safestrncpy(WBUFCP(buf,54), sd->guild->name,NAME_LENGTH);
  8221. safestrncpy(WBUFCP(buf,78), sd->guild->position[position].name, NAME_LENGTH);
  8222. }else if( sd->clan ){
  8223. WBUFB(buf,54) = 0;
  8224. safestrncpy(WBUFCP(buf,78), sd->clan->name,NAME_LENGTH);
  8225. }else{ //Assume no guild and no clan
  8226. WBUFB(buf,54) = 0;
  8227. WBUFB(buf,78) = 0;
  8228. }
  8229. #if PACKETVER >= 20150513
  8230. WBUFL(buf,102) = sd->status.title_id; // Title ID
  8231. #endif
  8232. }
  8233. break;
  8234. //[blackhole89]
  8235. case BL_HOM:
  8236. safestrncpy(WBUFCP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  8237. break;
  8238. case BL_MER:
  8239. safestrncpy(WBUFCP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  8240. break;
  8241. case BL_PET:
  8242. safestrncpy(WBUFCP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  8243. break;
  8244. case BL_NPC:
  8245. safestrncpy(WBUFCP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  8246. break;
  8247. case BL_MOB:
  8248. {
  8249. struct mob_data *md = (struct mob_data *)bl;
  8250. nullpo_retv(md);
  8251. safestrncpy(WBUFCP(buf,6), md->name, NAME_LENGTH);
  8252. if( md->guardian_data && md->guardian_data->guild_id )
  8253. {
  8254. #if PACKETVER >= 20150513
  8255. WBUFW(buf, 0) = cmd = 0xa30;
  8256. #else
  8257. WBUFW(buf, 0) = cmd = 0x195;
  8258. #endif
  8259. WBUFB(buf,30) = 0;
  8260. safestrncpy(WBUFCP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  8261. safestrncpy(WBUFCP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  8262. }
  8263. else if( battle_config.show_mob_info )
  8264. {
  8265. char mobhp[50], *str_p = mobhp;
  8266. #if PACKETVER >= 20150513
  8267. WBUFW(buf, 0) = cmd = 0xa30;
  8268. #else
  8269. WBUFW(buf, 0) = cmd = 0x195;
  8270. #endif
  8271. if( battle_config.show_mob_info&4 )
  8272. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  8273. if( battle_config.show_mob_info&1 )
  8274. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  8275. if( battle_config.show_mob_info&2 )
  8276. str_p += sprintf(str_p, "HP: %u%% | ", get_percentage(md->status.hp, md->status.max_hp));
  8277. //Even thought mobhp ain't a name, we send it as one so the client
  8278. //can parse it. [Skotlex]
  8279. if( str_p != mobhp )
  8280. {
  8281. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  8282. safestrncpy(WBUFCP(buf,30), mobhp, NAME_LENGTH);
  8283. WBUFB(buf,54) = 0;
  8284. WBUFB(buf,78) = 0;
  8285. }
  8286. }
  8287. #if PACKETVER >= 20150513
  8288. WBUFL(buf, 102) = 0; // Title ID
  8289. #endif
  8290. }
  8291. break;
  8292. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  8293. // safestrncpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  8294. // break;
  8295. return;
  8296. case BL_ELEM:
  8297. safestrncpy(WBUFCP(buf,6), ((TBL_ELEM*)bl)->db->name, NAME_LENGTH);
  8298. break;
  8299. default:
  8300. ShowError("clif_name: bad type %d(%d)\n", bl->type, bl->id);
  8301. return;
  8302. }
  8303. clif_send(buf, packet_len(cmd), src, target);
  8304. }
  8305. /// Taekwon Jump (TK_HIGHJUMP) effect (ZC_HIGHJUMP).
  8306. /// 01ff <id>.L <x>.W <y>.W
  8307. ///
  8308. /// Visually moves(instant) a character to x,y. The char moves even
  8309. /// when the target cell isn't walkable. If the char is sitting it
  8310. /// stays that way.
  8311. void clif_slide(struct block_list *bl, int x, int y)
  8312. {
  8313. unsigned char buf[10];
  8314. nullpo_retv(bl);
  8315. WBUFW(buf, 0) = 0x01ff;
  8316. WBUFL(buf, 2) = bl->id;
  8317. WBUFW(buf, 6) = x;
  8318. WBUFW(buf, 8) = y;
  8319. clif_send(buf, packet_len(0x1ff), bl, AREA);
  8320. if( disguised(bl) )
  8321. {
  8322. WBUFL(buf,2) = -bl->id;
  8323. clif_send(buf, packet_len(0x1ff), bl, SELF);
  8324. }
  8325. }
  8326. /// Public chat message (ZC_NOTIFY_CHAT). lordalfa/Skotlex - used by @me as well
  8327. /// 008d <packet len>.W <id>.L <message>.?B
  8328. void clif_disp_overhead_(struct block_list *bl, const char* mes, enum send_target flag)
  8329. {
  8330. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  8331. int len_mes = strlen(mes)+1; //Account for \0
  8332. if (len_mes > sizeof(buf)-8) {
  8333. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  8334. len_mes = sizeof(buf)-8; //Trunk it to avoid problems.
  8335. }
  8336. // send message to others
  8337. if (flag == AREA) {
  8338. WBUFW(buf,0) = 0x8d;
  8339. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  8340. WBUFL(buf,4) = bl->id;
  8341. safestrncpy(WBUFCP(buf,8), mes, len_mes);
  8342. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  8343. }
  8344. // send back message to the speaker
  8345. if( bl->type == BL_PC ) {
  8346. WBUFW(buf,0) = 0x8e;
  8347. WBUFW(buf, 2) = len_mes + 4;
  8348. safestrncpy(WBUFCP(buf,4), mes, len_mes);
  8349. clif_send(buf, WBUFW(buf,2), bl, SELF);
  8350. }
  8351. }
  8352. /*==========================
  8353. * Minimap fix [Kevin]
  8354. * Remove dot from minimap
  8355. *--------------------------*/
  8356. void clif_party_xy_remove(struct map_session_data *sd)
  8357. {
  8358. unsigned char buf[16];
  8359. nullpo_retv(sd);
  8360. WBUFW(buf,0)=0x107;
  8361. WBUFL(buf,2)=sd->status.account_id;
  8362. WBUFW(buf,6)=-1;
  8363. WBUFW(buf,8)=-1;
  8364. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  8365. }
  8366. /// Displays a skill message (thanks to Rayce) (ZC_SKILLMSG).
  8367. /// 0215 <msg id>.L
  8368. /// msg id:
  8369. /// 0x15 = End all negative status (PA_GOSPEL)
  8370. /// 0x16 = Immunity to all status (PA_GOSPEL)
  8371. /// 0x17 = MaxHP +100% (PA_GOSPEL)
  8372. /// 0x18 = MaxSP +100% (PA_GOSPEL)
  8373. /// 0x19 = All stats +20 (PA_GOSPEL)
  8374. /// 0x1c = Enchant weapon with Holy element (PA_GOSPEL)
  8375. /// 0x1d = Enchant armor with Holy element (PA_GOSPEL)
  8376. /// 0x1e = DEF +25% (PA_GOSPEL)
  8377. /// 0x1f = ATK +100% (PA_GOSPEL)
  8378. /// 0x20 = HIT/Flee +50 (PA_GOSPEL)
  8379. /// 0x28 = Full strip failed because of coating (ST_FULLSTRIP)
  8380. /// ? = nothing
  8381. void clif_gospel_info(struct map_session_data *sd, int type)
  8382. {
  8383. int fd=sd->fd;
  8384. WFIFOHEAD(fd,packet_len(0x215));
  8385. WFIFOW(fd,0)=0x215;
  8386. WFIFOL(fd,2)=type;
  8387. WFIFOSET(fd, packet_len(0x215));
  8388. }
  8389. /// Multi-purpose mission information packet (ZC_STARSKILL).
  8390. /// 020e <mapname>.24B <monster_id>.L <star>.B <result>.B
  8391. /// result:
  8392. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  8393. /// star:
  8394. /// 0 = Place of the Sun
  8395. /// 1 = Place of the Moon
  8396. /// 2 = Place of the Stars
  8397. /// 1 = Star Gladiator %s's %s: <mapname>
  8398. /// star:
  8399. /// 0 = Place of the Sun
  8400. /// 1 = Place of the Moon
  8401. /// 2 = Place of the Stars
  8402. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  8403. /// star:
  8404. /// 0 = Target of the Sun
  8405. /// 1 = Target of the Moon
  8406. /// 2 = Target of the Stars
  8407. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  8408. /// star:
  8409. /// 0 = Monster of the Sun
  8410. /// 1 = Monster of the Moon
  8411. /// 2 = Monster of the Stars
  8412. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  8413. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  8414. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  8415. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  8416. /// 40 = Target HP : <monster_id used as HP>
  8417. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  8418. {
  8419. int fd = sd->fd;
  8420. WFIFOHEAD(fd,packet_len(0x20e));
  8421. WFIFOW(fd,0) = 0x20e;
  8422. safestrncpy(WFIFOCP(fd,2), mapname, NAME_LENGTH);
  8423. WFIFOL(fd,26) = monster_id;
  8424. WFIFOB(fd,30) = star;
  8425. WFIFOB(fd,31) = result;
  8426. WFIFOSET(fd,packet_len(0x20e));
  8427. }
  8428. /*==========================================
  8429. * Info about Star Glaldiator save map [Komurka]
  8430. * type: 1: Information, 0: Map registered
  8431. *------------------------------------------*/
  8432. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  8433. {
  8434. char mapname[MAP_NAME_LENGTH_EXT];
  8435. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  8436. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  8437. }
  8438. /*==========================================
  8439. * Info about Star Glaldiator hate mob [Komurka]
  8440. * type: 1: Register mob, 0: Information.
  8441. *------------------------------------------*/
  8442. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  8443. {
  8444. if( pcdb_checkid(class_) ) {
  8445. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  8446. } else if( mobdb_checkid(class_) ) {
  8447. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  8448. } else {
  8449. 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);
  8450. }
  8451. }
  8452. /*==========================================
  8453. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  8454. *------------------------------------------*/
  8455. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  8456. {
  8457. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  8458. }
  8459. /*==========================================
  8460. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  8461. *------------------------------------------*/
  8462. void clif_feel_hate_reset(struct map_session_data *sd)
  8463. {
  8464. clif_starskill(sd, "", 0, 0, 30);
  8465. }
  8466. /// Send out reply to configuration change
  8467. /// 02d9 <type>.L <value>.L (ZC_CONFIG)
  8468. /// type: see enum e_config_type
  8469. /// value:
  8470. /// false = disabled
  8471. /// true = enabled
  8472. void clif_configuration( struct map_session_data* sd, enum e_config_type type, bool enabled ){
  8473. int fd;
  8474. nullpo_retv(sd);
  8475. fd = sd->fd;
  8476. WFIFOHEAD(fd, packet_len(0x2d9));
  8477. WFIFOW(fd, 0) = 0x2d9;
  8478. WFIFOL(fd, 2) = type;
  8479. WFIFOL(fd, 6) = enabled;
  8480. WFIFOSET(fd, packet_len(0x2d9));
  8481. }
  8482. /// The player's 'view equip' state, sent during login (ZC_CONFIG_NOTIFY).
  8483. /// 02da <open equip window>.B
  8484. /// open equip window:
  8485. /// 0 = disabled
  8486. /// 1 = enabled
  8487. void clif_equipcheckbox(struct map_session_data* sd)
  8488. {
  8489. int fd;
  8490. nullpo_retv(sd);
  8491. fd = sd->fd;
  8492. WFIFOHEAD(fd, packet_len(0x2da));
  8493. WFIFOW(fd, 0) = 0x2da;
  8494. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  8495. WFIFOSET(fd, packet_len(0x2da));
  8496. }
  8497. /// Sends info about a player's equipped items.
  8498. /// 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)
  8499. /// 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)
  8500. /// 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)
  8501. /// 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)
  8502. /// 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)
  8503. /// 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)
  8504. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  8505. {
  8506. uint8* buf;
  8507. int i, n, fd, offset = 0;
  8508. #if PACKETVER < 20100629
  8509. const int s = 26;
  8510. #elif PACKETVER < 20120925
  8511. const int s = 28;
  8512. #elif PACKETVER < 20150225
  8513. const int s = 31;
  8514. #else
  8515. const int s = 57;
  8516. #endif
  8517. nullpo_retv(sd);
  8518. nullpo_retv(tsd);
  8519. fd = sd->fd;
  8520. WFIFOHEAD(fd, MAX_INVENTORY * s + 43 + 2);
  8521. buf = WFIFOP(fd,0);
  8522. #if PACKETVER < 20101124
  8523. WBUFW(buf, 0) = 0x2d7;
  8524. #elif PACKETVER < 20120925
  8525. WBUFW(buf, 0) = 0x859;
  8526. #elif PACKETVER < 20150225
  8527. WBUFW(buf, 0) = 0x997;
  8528. #else
  8529. WBUFW(buf, 0) = 0xa2d;
  8530. #endif
  8531. safestrncpy(WBUFCP(buf, 4), tsd->status.name, NAME_LENGTH);
  8532. WBUFW(buf,28) = tsd->status.class_;
  8533. WBUFW(buf,30) = tsd->vd.hair_style;
  8534. WBUFW(buf,32) = tsd->vd.head_bottom;
  8535. WBUFW(buf,34) = tsd->vd.head_mid;
  8536. WBUFW(buf,36) = tsd->vd.head_top;
  8537. #if PACKETVER >= 20110111
  8538. WBUFW(buf,38) = tsd->vd.robe;
  8539. offset+= 2;
  8540. buf = WBUFP(buf,2);
  8541. #endif
  8542. WBUFW(buf,38) = tsd->vd.hair_color;
  8543. WBUFW(buf,40) = tsd->vd.cloth_color;
  8544. WBUFB(buf,42) = tsd->vd.sex;
  8545. for(i=0,n=0; i < MAX_INVENTORY; i++)
  8546. {
  8547. if (tsd->inventory.u.items_inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  8548. continue;
  8549. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  8550. continue;
  8551. // Add item info : refine, identify flag, element, etc.
  8552. 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));
  8553. n++;
  8554. }
  8555. WFIFOW(fd, 2) = 43+offset+n*s; // Set length
  8556. WFIFOSET(fd, WFIFOW(fd, 2));
  8557. }
  8558. /// Display msgstringtable.txt string (ZC_MSG).
  8559. /// 0291 <message>.W
  8560. void clif_msg(struct map_session_data* sd, unsigned short id)
  8561. {
  8562. int fd;
  8563. nullpo_retv(sd);
  8564. fd = sd->fd;
  8565. WFIFOHEAD(fd, packet_len(0x291));
  8566. WFIFOW(fd, 0) = 0x291;
  8567. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  8568. WFIFOSET(fd, packet_len(0x291));
  8569. }
  8570. /// Display msgstringtable.txt string and fill in a valid for %d format (ZC_MSG_VALUE).
  8571. /// 0x7e2 <message>.W <value>.L
  8572. void clif_msg_value(struct map_session_data* sd, unsigned short id, int value)
  8573. {
  8574. int fd = sd->fd;
  8575. WFIFOHEAD(fd, packet_len(0x7e2));
  8576. WFIFOW(fd,0) = 0x7e2;
  8577. WFIFOW(fd,2) = id;
  8578. WFIFOL(fd,4) = value;
  8579. WFIFOSET(fd, packet_len(0x7e2));
  8580. }
  8581. /// Displays msgstringtable.txt string, prefixed with a skill name. (ZC_MSG_SKILL).
  8582. /// 07e6 <skill id>.W <msg id>.L
  8583. ///
  8584. /// NOTE: Message has following format and is printed in color 0xCDCDFF (purple):
  8585. /// "[SkillName] Message"
  8586. void clif_msg_skill(struct map_session_data* sd, uint16 skill_id, int msg_id)
  8587. {
  8588. int fd = sd->fd;
  8589. WFIFOHEAD(fd, packet_len(0x7e6));
  8590. WFIFOW(fd,0) = 0x7e6;
  8591. WFIFOW(fd,2) = skill_id;
  8592. WFIFOL(fd,4) = msg_id;
  8593. WFIFOSET(fd, packet_len(0x7e6));
  8594. }
  8595. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  8596. /// Returns true if the packet was parsed successfully.
  8597. /// Formats: false - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  8598. /// true - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  8599. static bool clif_process_message(struct map_session_data* sd, bool whisperFormat, char* out_name, char* out_message, char* out_full_message ){
  8600. const char* seperator = " : ";
  8601. int fd;
  8602. struct s_packet_db* info;
  8603. uint16 packetLength, inputLength;
  8604. const char *input, *name, *message;
  8605. size_t nameLength, messageLength;
  8606. fd = sd->fd;
  8607. info = &packet_db[RFIFOW(fd,0)];
  8608. packetLength = RFIFOW(fd,info->pos[0]);
  8609. input = RFIFOCP(fd,info->pos[1]);
  8610. // basic structure check for the 4-byte header
  8611. if( packetLength < 4 ){
  8612. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  8613. return false;
  8614. }else{
  8615. inputLength = packetLength - 4;
  8616. }
  8617. // process <name> part of the packet
  8618. if( whisperFormat ) {
  8619. // name has fixed width
  8620. if( inputLength < NAME_LENGTH + 1 ) {
  8621. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  8622. return false;
  8623. }
  8624. name = input;
  8625. // validate name
  8626. nameLength = strnlen( name, NAME_LENGTH - 1 );
  8627. // only restriction is that the name must be zero-terminated
  8628. if( name[nameLength] != '\0' ) {
  8629. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  8630. return false;
  8631. }
  8632. message = input + NAME_LENGTH;
  8633. messageLength = inputLength - NAME_LENGTH;
  8634. }else{
  8635. // name and message are separated by ' : '
  8636. size_t seperatorLength = strnlen( seperator, NAME_LENGTH );
  8637. nameLength = strnlen( sd->status.name, NAME_LENGTH - 1 ); // name length (w/o zero byte)
  8638. // check if there's enough data provided
  8639. if( inputLength < nameLength + seperatorLength + 1 ){
  8640. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no username data)!\n", sd->status.name);
  8641. return false;
  8642. }
  8643. name = input;
  8644. // validate name
  8645. if( strncmp( name, sd->status.name, nameLength ) || // the text must start with the speaker's name
  8646. strncmp( name + nameLength, seperator, seperatorLength ) ) // followed by the seperator
  8647. {
  8648. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  8649. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  8650. set_eof(sd->fd); // Just kick them out to correct it.
  8651. return false;
  8652. }
  8653. message = input + nameLength + seperatorLength;
  8654. messageLength = inputLength - nameLength - seperatorLength;
  8655. }
  8656. #if PACKETVER < 20151001
  8657. // the declared length must match real length
  8658. if( messageLength != strnlen(message, messageLength)+1 ) {
  8659. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  8660. return false;
  8661. }
  8662. // verify <message> part of the packet
  8663. if( message[messageLength-1] != '\0' ) { // message must be zero-terminated
  8664. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  8665. return false;
  8666. }
  8667. #else
  8668. // No zero termination anymore
  8669. messageLength += 1;
  8670. #endif
  8671. // messages mustn't be too long
  8672. if( messageLength > CHAT_SIZE_MAX-1 ) {
  8673. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  8674. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  8675. // Neither the official client nor server place any restriction on the length of the data in the packet,
  8676. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  8677. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  8678. return false;
  8679. }
  8680. // If it is not a whisper message, set the name to the fakename of the player
  8681. if( whisperFormat == false && sd->fakename[0] != '\0' ){
  8682. strcpy( out_name, sd->fakename );
  8683. }else{
  8684. safestrncpy( out_name, name, nameLength + 1 );
  8685. }
  8686. safestrncpy( out_message, message, messageLength );
  8687. if( whisperFormat ){
  8688. sprintf( out_full_message, "%-24s%s", out_name, out_message );
  8689. out_full_message[nameLength] = '\0';
  8690. }else{
  8691. sprintf( out_full_message, "%s%s%s", out_name, seperator, out_message );
  8692. }
  8693. if( is_atcommand( fd, sd, out_message, 1 ) )
  8694. return false;
  8695. if (sd->sc.cant.chat)
  8696. return false; //no "chatting" while muted.
  8697. if( battle_config.min_chat_delay ) { //[Skotlex]
  8698. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8699. return false;
  8700. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8701. }
  8702. if (battle_config.idletime_option&IDLE_CHAT)
  8703. sd->idletime = last_tick;
  8704. return true;
  8705. }
  8706. /**
  8707. * Displays a message if the player enters a PK Zone (during pk_mode)
  8708. * @param sd: Player data
  8709. */
  8710. inline void clif_pk_mode_message(struct map_session_data * sd)
  8711. {
  8712. if (battle_config.pk_mode && battle_config.pk_mode_mes &&
  8713. sd && map[sd->bl.m].flag.pvp) {
  8714. if( (int)sd->status.base_level < battle_config.pk_min_level ) {
  8715. char output[CHAT_SIZE_MAX];
  8716. // 1504: You've entered a PK Zone (safe until level %d).
  8717. safesnprintf(output, CHAT_SIZE_MAX, msg_txt(sd,1504),
  8718. battle_config.pk_min_level);
  8719. clif_showscript(&sd->bl, output, SELF);
  8720. } else {
  8721. // 1503: You've entered a PK Zone.
  8722. clif_showscript(&sd->bl, msg_txt(sd,1503), SELF);
  8723. }
  8724. }
  8725. return;
  8726. }
  8727. // ---------------------
  8728. // clif_parse_wanttoconnect
  8729. // ---------------------
  8730. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  8731. // error codes:
  8732. // 0 - Success
  8733. // 1 - Unknown packet_ver
  8734. // 2 - Invalid account_id
  8735. // 3 - Invalid char_id
  8736. // 4 - Invalid login_id1 (reserved)
  8737. // 5 - Invalid client_tick (reserved)
  8738. // 6 - Invalid sex
  8739. // Only the first 'invalid' error that appears is used.
  8740. static int clif_parse_WantToConnection_sub(int fd)
  8741. {
  8742. int packet_len, value; //Value is used to temporarily store account/char_id/sex
  8743. unsigned short cmd;
  8744. //By default, start searching on the default one.
  8745. cmd = RFIFOW(fd, 0);
  8746. packet_len = RFIFOREST(fd);
  8747. // FIXME: If the packet is not received at once, this will FAIL.
  8748. // Figure out, when it happens, that only part of the packet is
  8749. // received, or fix the function to be able to deal with that
  8750. // case.
  8751. if( packet_len != packet_db[cmd].len )
  8752. return 1; /* wrong length */
  8753. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )
  8754. return 2; /* invalid account_id */
  8755. else if( (value=(int)RFIFOL(fd, packet_db[cmd].pos[1])) <= 0 )
  8756. return 3; /* invalid char_id */
  8757. /* RFIFOL(fd, packet_db[cmd].pos[2]) - don't care about login_id1 */
  8758. /* RFIFOL(fd, packet_db[cmd].pos[3]) - don't care about client_tick */
  8759. else if( (value=(int)RFIFOB(fd, packet_db[cmd].pos[4])) != 0 && value != 1 )
  8760. return 6; /* invalid sex */
  8761. else
  8762. return 0;
  8763. }
  8764. /// Request to connect to map-server.
  8765. /// 0072 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER)
  8766. /// 0436 <account id>.L <char id>.L <auth code>.L <client time>.L <gender>.B (CZ_ENTER2)
  8767. /// There are various variants of this packet, some of them have padding between fields.
  8768. void clif_parse_WantToConnection(int fd, struct map_session_data* sd)
  8769. {
  8770. struct block_list* bl;
  8771. struct auth_node* node;
  8772. int cmd, account_id, char_id, login_id1, sex, err;
  8773. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  8774. if (sd) {
  8775. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  8776. return;
  8777. }
  8778. cmd = RFIFOW(fd, 0);
  8779. account_id = RFIFOL(fd, packet_db[cmd].pos[0]);
  8780. char_id = RFIFOL(fd, packet_db[cmd].pos[1]);
  8781. login_id1 = RFIFOL(fd, packet_db[cmd].pos[2]);
  8782. client_tick = RFIFOL(fd, packet_db[cmd].pos[3]);
  8783. sex = RFIFOB(fd, packet_db[cmd].pos[4]);
  8784. err = clif_parse_WantToConnection_sub(fd);
  8785. if( err ){ // connection rejected
  8786. ShowInfo("clif_parse: Disconnecting session #%d with unknown connect packet 0x%04x(length:%d)%s\n", fd, cmd, RFIFOREST(fd), (
  8787. err == 1 ? "." :
  8788. err == 2 ? ", possibly for having an invalid account_id." :
  8789. err == 3 ? ", possibly for having an invalid char_id." :
  8790. /* Uncomment when checks are added in clif_parse_WantToConnection_sub. [FlavioJS]
  8791. err == 4 ? ", possibly for having an invalid login_id1." :
  8792. err == 5 ? ", possibly for having an invalid client_tick." :
  8793. */
  8794. err == 6 ? ", possibly for having an invalid sex." :
  8795. ". ERROR invalid error code"));
  8796. WFIFOHEAD(fd,packet_len(0x6a));
  8797. WFIFOW(fd,0) = 0x6a;
  8798. WFIFOB(fd,2) = err;
  8799. WFIFOSET(fd,packet_len(0x6a));
  8800. #ifdef DUMP_INVALID_PACKET
  8801. ShowDump(RFIFOP(fd, 0), RFIFOREST(fd));
  8802. #endif
  8803. RFIFOSKIP(fd, RFIFOREST(fd));
  8804. set_eof(fd);
  8805. return;
  8806. }
  8807. if( runflag != MAPSERVER_ST_RUNNING ) {// not allowed
  8808. clif_authfail_fd(fd,1);// server closed
  8809. return;
  8810. }
  8811. //Check for double login.
  8812. bl = map_id2bl(account_id);
  8813. if(bl && bl->type != BL_PC) {
  8814. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  8815. WFIFOHEAD(fd,packet_len(0x6a));
  8816. WFIFOW(fd,0) = 0x6a;
  8817. WFIFOB(fd,2) = 3; // Rejected by server
  8818. WFIFOSET(fd,packet_len(0x6a));
  8819. set_eof(fd);
  8820. return;
  8821. }
  8822. if (bl ||
  8823. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  8824. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  8825. {
  8826. clif_authfail_fd(fd, 8); //Still recognizes last connection
  8827. return;
  8828. }
  8829. CREATE(sd, TBL_PC, 1);
  8830. sd->fd = fd;
  8831. #ifdef PACKET_OBFUSCATION
  8832. sd->cryptKey = (((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF) * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF;
  8833. #endif
  8834. session[fd]->session_data = sd;
  8835. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  8836. #if PACKETVER < 20070521
  8837. WFIFOHEAD(fd,4);
  8838. WFIFOL(fd,0) = sd->bl.id;
  8839. WFIFOSET(fd,4);
  8840. #else
  8841. WFIFOHEAD(fd,packet_len(0x283));
  8842. WFIFOW(fd,0) = 0x283;
  8843. WFIFOL(fd,2) = sd->bl.id;
  8844. WFIFOSET(fd,packet_len(0x283));
  8845. #endif
  8846. chrif_authreq(sd,false);
  8847. }
  8848. /// Notification from the client, that it has finished map loading and is about to display player's character (CZ_NOTIFY_ACTORINIT).
  8849. /// 007d
  8850. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  8851. {
  8852. bool guild_notice = false;
  8853. if(sd->bl.prev != NULL)
  8854. return;
  8855. // Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
  8856. if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
  8857. //Let pc_reg_received or intif_parse_StorageReceived reinvoke this when ready.
  8858. sd->state.connect_new = 0;
  8859. return;
  8860. }
  8861. if (sd->state.rewarp) { //Rewarp player.
  8862. sd->state.rewarp = 0;
  8863. clif_changemap(sd, sd->bl.m, sd->bl.x, sd->bl.y);
  8864. return;
  8865. }
  8866. sd->state.warping = 0;
  8867. // look
  8868. #if PACKETVER < 4
  8869. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  8870. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  8871. #else
  8872. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  8873. #endif
  8874. pc_set_costume_view(sd);
  8875. if(sd->vd.cloth_color)
  8876. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  8877. if(sd->vd.body_style)
  8878. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_BODY2,sd->vd.body_style,SELF);
  8879. // item
  8880. clif_inventorylist(sd); // inventory list first, otherwise deleted items in pc_checkitem show up as 'unknown item'
  8881. pc_checkitem(sd);
  8882. // cart
  8883. if(pc_iscarton(sd)) {
  8884. clif_cartlist(sd);
  8885. clif_updatestatus(sd,SP_CARTINFO);
  8886. }
  8887. // weight
  8888. clif_updatestatus(sd,SP_WEIGHT);
  8889. clif_updatestatus(sd,SP_MAXWEIGHT);
  8890. // guild
  8891. // (needs to go before clif_spawn() to show guild emblems correctly)
  8892. if(sd->status.guild_id)
  8893. guild_send_memberinfoshort(sd,1);
  8894. if(battle_config.pc_invincible_time > 0) {
  8895. if(map_flag_gvg(sd->bl.m))
  8896. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  8897. else
  8898. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  8899. }
  8900. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  8901. map_spawnmobs(sd->bl.m);
  8902. if( !pc_isinvisible(sd) ) { // increment the number of pvp players on the map
  8903. map[sd->bl.m].users_pvp++;
  8904. }
  8905. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  8906. // reset the callshop flag if the player changes map
  8907. sd->state.callshop = 0;
  8908. if(map_addblock(&sd->bl))
  8909. return;
  8910. clif_spawn(&sd->bl);
  8911. // Party
  8912. // (needs to go after clif_spawn() to show hp bars correctly)
  8913. if(sd->status.party_id) {
  8914. party_send_movemap(sd);
  8915. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  8916. }
  8917. if( sd->bg_id ) clif_bg_hp(sd); // BattleGround System
  8918. if(map[sd->bl.m].flag.pvp && !pc_isinvisible(sd)) {
  8919. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  8920. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  8921. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  8922. sd->pvp_rank = 0;
  8923. sd->pvp_lastusers = 0;
  8924. sd->pvp_point = 5;
  8925. sd->pvp_won = 0;
  8926. sd->pvp_lost = 0;
  8927. }
  8928. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8929. } else if(sd->duel_group) // set flag, if it's a duel [LuzZza]
  8930. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF);
  8931. else if (map[sd->bl.m].flag.gvg_dungeon)
  8932. clif_map_property(&sd->bl, MAPPROPERTY_FREEPVPZONE, SELF); //TODO: Figure out the real packet to send here.
  8933. else if( map_flag_gvg(sd->bl.m) )
  8934. clif_map_property(&sd->bl, MAPPROPERTY_AGITZONE, SELF);
  8935. else
  8936. clif_map_property(&sd->bl, MAPPROPERTY_NOTHING, SELF);
  8937. // info about nearby objects
  8938. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  8939. 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);
  8940. // pet
  8941. if( sd->pd ) {
  8942. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) ) { //Return the pet to egg. [Skotlex]
  8943. clif_displaymessage(sd->fd, msg_txt(sd,666));
  8944. pet_menu(sd, 3); //Option 3 is return to egg.
  8945. } else {
  8946. if(map_addblock(&sd->pd->bl))
  8947. return;
  8948. clif_spawn(&sd->pd->bl);
  8949. clif_send_petdata(sd,sd->pd,0,0);
  8950. clif_send_petstatus(sd);
  8951. // skill_unit_move(&sd->pd->bl,gettick(),1);
  8952. }
  8953. }
  8954. //homunculus [blackhole89]
  8955. if( hom_is_active(sd->hd) ) {
  8956. if(map_addblock(&sd->hd->bl))
  8957. return;
  8958. clif_spawn(&sd->hd->bl);
  8959. clif_send_homdata(sd,SP_ACK,0);
  8960. clif_hominfo(sd,sd->hd,1);
  8961. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  8962. clif_homskillinfoblock(sd);
  8963. if( battle_config.hom_setting&HOMSET_COPY_SPEED )
  8964. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  8965. if( !(battle_config.hom_setting&HOMSET_NO_INSTANT_LAND_SKILL) )
  8966. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  8967. }
  8968. if( sd->md ) {
  8969. if(map_addblock(&sd->md->bl))
  8970. return;
  8971. clif_spawn(&sd->md->bl);
  8972. clif_mercenary_info(sd);
  8973. clif_mercenary_skillblock(sd);
  8974. status_calc_bl(&sd->md->bl, SCB_SPEED); // Mercenary mimic their master's speed on each map change
  8975. }
  8976. if( sd->ed ) {
  8977. if (map_addblock(&sd->ed->bl))
  8978. return;
  8979. clif_spawn(&sd->ed->bl);
  8980. clif_elemental_info(sd);
  8981. clif_elemental_updatestatus(sd,SP_HP);
  8982. clif_hpmeter_single(sd->fd,sd->ed->bl.id,sd->ed->battle_status.hp,sd->ed->battle_status.max_hp);
  8983. clif_elemental_updatestatus(sd,SP_SP);
  8984. status_calc_bl(&sd->ed->bl, SCB_SPEED); //Elemental mimic their master's speed on each map change
  8985. }
  8986. if(sd->state.connect_new) {
  8987. int lv;
  8988. guild_notice = true;
  8989. clif_skillinfoblock(sd);
  8990. clif_hotkeys_send(sd);
  8991. clif_updatestatus(sd,SP_BASEEXP);
  8992. clif_updatestatus(sd,SP_NEXTBASEEXP);
  8993. clif_updatestatus(sd,SP_JOBEXP);
  8994. clif_updatestatus(sd,SP_NEXTJOBEXP);
  8995. clif_updatestatus(sd,SP_SKILLPOINT);
  8996. clif_initialstatus(sd);
  8997. if (sd->sc.option&OPTION_FALCON)
  8998. clif_status_load(&sd->bl, EFST_FALCON, 1);
  8999. else if (sd->sc.option&(OPTION_RIDING|OPTION_DRAGON|OPTION_MADOGEAR))
  9000. clif_status_load(&sd->bl, EFST_RIDING, 1);
  9001. else if (sd->sc.option&OPTION_WUGRIDER)
  9002. clif_status_load(&sd->bl, EFST_WUGRIDER, 1);
  9003. else if (sd->sc.data[SC_ALL_RIDING])
  9004. clif_status_load(&sd->bl, EFST_ALL_RIDING, 1);
  9005. if(sd->status.manner < 0)
  9006. sc_start(&sd->bl,&sd->bl,SC_NOCHAT,100,0,0);
  9007. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  9008. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  9009. if(sd->bl.m == sd->feel_map[0].m
  9010. || sd->bl.m == sd->feel_map[1].m
  9011. || sd->bl.m == sd->feel_map[2].m)
  9012. sc_start(&sd->bl,&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  9013. }
  9014. if(sd->pd && sd->pd->pet.intimate > 900)
  9015. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  9016. if(hom_is_active(sd->hd))
  9017. hom_init_timers(sd->hd);
  9018. if (night_flag && map[sd->bl.m].flag.nightenabled) {
  9019. sd->state.night = 1;
  9020. clif_status_load(&sd->bl, EFST_SKE, 1);
  9021. }
  9022. // Notify everyone that this char logged in [Skotlex].
  9023. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  9024. if (!sd->state.autotrade) { // Don't trigger NPC event or opening vending/buyingstore will be failed
  9025. //Login Event
  9026. npc_script_event(sd, NPCE_LOGIN);
  9027. }
  9028. } else {
  9029. //For some reason the client "loses" these on warp/map-change.
  9030. clif_updatestatus(sd,SP_STR);
  9031. clif_updatestatus(sd,SP_AGI);
  9032. clif_updatestatus(sd,SP_VIT);
  9033. clif_updatestatus(sd,SP_INT);
  9034. clif_updatestatus(sd,SP_DEX);
  9035. clif_updatestatus(sd,SP_LUK);
  9036. // abort currently running script
  9037. sd->state.using_fake_npc = 0;
  9038. sd->state.menu_or_input = 0;
  9039. sd->npc_menu = 0;
  9040. if(sd->npc_id)
  9041. npc_event_dequeue(sd);
  9042. }
  9043. if( sd->state.changemap ) {// restore information that gets lost on map-change
  9044. #if PACKETVER >= 20070918
  9045. clif_partyinvitationstate(sd);
  9046. clif_equipcheckbox(sd);
  9047. #endif
  9048. #if PACKETVER >= 20170920
  9049. if( battle_config.homunculus_autofeed_always ){
  9050. // Always send ON or OFF
  9051. if( sd->hd && battle_config.feature_homunculus_autofeed ){
  9052. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, sd->hd->homunculus.autofeed );
  9053. }else{
  9054. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, false );
  9055. }
  9056. }else{
  9057. // Only send when enabled
  9058. if( sd->hd && battle_config.feature_homunculus_autofeed && sd->hd->homunculus.autofeed ){
  9059. clif_configuration( sd, CONFIG_HOMUNCULUS_AUTOFEED, true );
  9060. }
  9061. }
  9062. #endif
  9063. if (sd->guild && battle_config.guild_notice_changemap == 1){
  9064. clif_guild_notice(sd); // Displays after VIP
  9065. guild_notice = false; // Do not display it twice
  9066. }
  9067. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  9068. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  9069. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  9070. if( night_flag && map[sd->bl.m].flag.nightenabled )
  9071. { //Display night.
  9072. if( !sd->state.night )
  9073. {
  9074. sd->state.night = 1;
  9075. clif_status_load(&sd->bl, EFST_SKE, 1);
  9076. }
  9077. }
  9078. else if( sd->state.night )
  9079. { //Clear night display.
  9080. sd->state.night = 0;
  9081. clif_status_load(&sd->bl, EFST_SKE, 0);
  9082. }
  9083. if( map[sd->bl.m].flag.battleground )
  9084. {
  9085. clif_map_type(sd, MAPTYPE_BATTLEFIELD); // Battleground Mode
  9086. if( map[sd->bl.m].flag.battleground == 2 )
  9087. clif_bg_updatescore_single(sd);
  9088. }
  9089. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  9090. {
  9091. char output[128];
  9092. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  9093. clif_broadcast(&sd->bl, output, strlen(output) + 1, BC_BLUE, SELF);
  9094. }
  9095. if( pc_has_permission(sd,PC_PERM_VIEW_HPMETER) ) {
  9096. map[sd->bl.m].hpmeter_visible++;
  9097. sd->state.hpmeter_visible = 1;
  9098. }
  9099. status_change_clear_onChangeMap(&sd->bl, &sd->sc);
  9100. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  9101. status_calc_pc(sd, sd->state.autotrade ? SCO_FIRST : SCO_NONE); // Some conditions are map-dependent so we must recalculate
  9102. #ifdef VIP_ENABLE
  9103. if (!sd->state.connect_new &&
  9104. !sd->vip.disableshowrate &&
  9105. sd->state.pmap != sd->bl.m &&
  9106. map[sd->state.pmap].adjust.bexp != map[sd->bl.m].adjust.bexp
  9107. )
  9108. {
  9109. clif_display_pinfo(sd,ZC_PERSONAL_INFOMATION);
  9110. //clif_vip_display_info(sd,ZC_PERSONAL_INFOMATION_CHN);
  9111. }
  9112. #endif
  9113. // Instances do not need their own channels
  9114. if( channel_config.map_tmpl.name[0] && (channel_config.map_tmpl.opt&CHAN_OPT_AUTOJOIN) && !map[sd->bl.m].flag.chmautojoin && !map[sd->bl.m].instance_id )
  9115. channel_mjoin(sd); //join new map
  9116. clif_pk_mode_message(sd);
  9117. }
  9118. if( sd->guild && ( battle_config.guild_notice_changemap == 2 || guild_notice ) ){
  9119. clif_guild_notice(sd); // Displays at end
  9120. }
  9121. mail_clear(sd);
  9122. /* Guild Aura Init */
  9123. if( sd->state.gmaster_flag ) {
  9124. guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
  9125. guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
  9126. guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));
  9127. guild_guildaura_refresh(sd,GD_HAWKEYES,guild_checkskill(sd->guild,GD_HAWKEYES));
  9128. }
  9129. if( sd->state.vending ) { /* show we have a vending */
  9130. clif_openvending(sd,sd->bl.id,sd->vending);
  9131. clif_showvendingboard(&sd->bl,sd->message,0);
  9132. }
  9133. // Don't trigger NPC event or opening vending/buyingstore will be failed
  9134. if(!sd->state.autotrade && map[sd->bl.m].flag.loadevent) // Lance
  9135. npc_script_event(sd, NPCE_LOADMAP);
  9136. if (pc_checkskill(sd, SG_DEVIL) && pc_is_maxjoblv(sd))
  9137. clif_status_load(&sd->bl, EFST_DEVIL1, 1); //blindness [Komurka]
  9138. if (sd->sc.opt2) //Client loses these on warp.
  9139. clif_changeoption(&sd->bl);
  9140. 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)) {
  9141. status_change_end(&sd->bl, SC_MONSTER_TRANSFORM, INVALID_TIMER);
  9142. status_change_end(&sd->bl, SC_ACTIVE_MONSTER_TRANSFORM, INVALID_TIMER);
  9143. clif_displaymessage(sd->fd, msg_txt(sd,731)); // Transforming into monster is not allowed in Guild Wars.
  9144. }
  9145. clif_weather_check(sd);
  9146. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  9147. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  9148. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  9149. else
  9150. sd->areanpc_id = 0;
  9151. /* it broke at some point (e.g. during a crash), so we make it visibly dead again. */
  9152. if( !sd->status.hp && !pc_isdead(sd) && status_isdead(&sd->bl) )
  9153. pc_setdead(sd);
  9154. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  9155. if(pc_isdead(sd))
  9156. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9157. else {
  9158. skill_usave_trigger(sd);
  9159. if (battle_config.spawn_direction)
  9160. clif_changed_dir(&sd->bl, SELF);
  9161. }
  9162. // Trigger skill effects if you appear standing on them
  9163. if(!battle_config.pc_invincible_time)
  9164. skill_unit_move(&sd->bl,gettick(),1);
  9165. pc_show_questinfo_reinit(sd);
  9166. pc_show_questinfo(sd);
  9167. #if PACKETVER >= 20150513
  9168. if( sd->mail.inbox.unread ){
  9169. clif_Mail_new(sd, 0, NULL, NULL);
  9170. }
  9171. #endif
  9172. sd->state.connect_new = 0;
  9173. sd->state.changemap = false;
  9174. }
  9175. /// Server's tick (ZC_NOTIFY_TIME).
  9176. /// 007f <time>.L
  9177. void clif_notify_time(struct map_session_data* sd, unsigned long time)
  9178. {
  9179. int fd = sd->fd;
  9180. WFIFOHEAD(fd,packet_len(0x7f));
  9181. WFIFOW(fd,0) = 0x7f;
  9182. WFIFOL(fd,2) = time;
  9183. WFIFOSET(fd,packet_len(0x7f));
  9184. }
  9185. /// Request for server's tick.
  9186. /// 007e <client tick>.L (CZ_REQUEST_TIME)
  9187. /// 0360 <client tick>.L (CZ_REQUEST_TIME2)
  9188. /// There are various variants of this packet, some of them have padding between fields.
  9189. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  9190. {
  9191. sd->client_tick = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9192. clif_notify_time(sd, gettick());
  9193. }
  9194. /// Sends hotkey bar.
  9195. /// 02b9 { <is skill>.B <id>.L <count>.W }*27 (ZC_SHORTCUT_KEY_LIST)
  9196. /// 07d9 { <is skill>.B <id>.L <count>.W }*36 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090603)
  9197. /// 07d9 { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V2, PACKETVER >= 20090617)
  9198. /// 0a00 <rotate>.B { <is skill>.B <id>.L <count>.W }*38 (ZC_SHORTCUT_KEY_LIST_V3, PACKETVER >= 20141022)
  9199. void clif_hotkeys_send(struct map_session_data *sd) {
  9200. #ifdef HOTKEY_SAVING
  9201. const int fd = sd->fd;
  9202. int i;
  9203. int offset = 2;
  9204. #if PACKETVER < 20090603
  9205. const int cmd = 0x2b9;
  9206. #elif PACKETVER < 20141022
  9207. const int cmd = 0x7d9;
  9208. #else
  9209. char Rotate = sd->status.hotkey_rowshift;
  9210. const int cmd = 0xa00;
  9211. offset = 3;
  9212. #endif
  9213. if (!fd) return;
  9214. WFIFOHEAD(fd, offset + MAX_HOTKEYS * 7);
  9215. WFIFOW(fd, 0) = cmd;
  9216. #if PACKETVER >= 20141022
  9217. WFIFOB(fd, 2) = Rotate;
  9218. #endif
  9219. for(i = 0; i < MAX_HOTKEYS; i++) {
  9220. WFIFOB(fd, offset + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  9221. WFIFOL(fd, offset + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  9222. WFIFOW(fd, offset + 5 + i * 7) = sd->status.hotkeys[i].lv; // item qty or skill level
  9223. }
  9224. WFIFOSET(fd, packet_len(cmd));
  9225. #endif
  9226. }
  9227. /// Request to update a position on the hotkey row bar
  9228. void clif_parse_HotkeyRowShift(int fd, struct map_session_data *sd) {
  9229. int cmd = RFIFOW(fd, 0);
  9230. sd->status.hotkey_rowshift = RFIFOB(fd, packet_db[cmd].pos[0]);
  9231. }
  9232. /// Request to update a position on the hotkey bar (CZ_SHORTCUT_KEY_CHANGE).
  9233. /// 02ba <index>.W <is skill>.B <id>.L <count>.W
  9234. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  9235. #ifdef HOTKEY_SAVING
  9236. unsigned short idx;
  9237. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9238. idx = RFIFOW(fd, info->pos[0]);
  9239. if (idx >= MAX_HOTKEYS) return;
  9240. sd->status.hotkeys[idx].type = RFIFOB(fd,info->pos[1]);
  9241. sd->status.hotkeys[idx].id = RFIFOL(fd, info->pos[2]);
  9242. sd->status.hotkeys[idx].lv = RFIFOW(fd, info->pos[3]);
  9243. #endif
  9244. }
  9245. /// Displays cast-like progress bar (ZC_PROGRESS).
  9246. /// 02f0 <color>.L <time>.L
  9247. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  9248. {
  9249. int fd = sd->fd;
  9250. WFIFOHEAD(fd,packet_len(0x2f0));
  9251. WFIFOW(fd,0) = 0x2f0;
  9252. WFIFOL(fd,2) = color;
  9253. WFIFOL(fd,6) = second;
  9254. WFIFOSET(fd,packet_len(0x2f0));
  9255. }
  9256. /// Removes an ongoing progress bar (ZC_PROGRESS_CANCEL).
  9257. /// 02f2
  9258. void clif_progressbar_abort(struct map_session_data * sd)
  9259. {
  9260. int fd = sd->fd;
  9261. WFIFOHEAD(fd,packet_len(0x2f2));
  9262. WFIFOW(fd,0) = 0x2f2;
  9263. WFIFOSET(fd,packet_len(0x2f2));
  9264. }
  9265. /// Notification from the client, that the progress bar has reached 100% (CZ_PROGRESS).
  9266. /// 02f1
  9267. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  9268. {
  9269. int npc_id = sd->progressbar.npc_id;
  9270. if( gettick() < sd->progressbar.timeout && sd->st )
  9271. sd->st->state = END;
  9272. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  9273. sd->state.workinprogress = WIP_DISABLE_NONE;
  9274. npc_scriptcont(sd, npc_id, false);
  9275. }
  9276. /// Displays cast-like progress bar on a NPC
  9277. /// 09d1 <id>.L <color>.L <time>.L (ZC_PROGRESS_ACTOR)
  9278. void clif_progressbar_npc( struct npc_data *nd, struct map_session_data* sd ){
  9279. #if PACKETVER >= 20130821
  9280. unsigned char buf[14];
  9281. if( nd->progressbar.timeout > 0 ){
  9282. WBUFW(buf,0) = 0x9d1;
  9283. WBUFL(buf,2) = nd->bl.id;
  9284. WBUFL(buf,6) = nd->progressbar.color;
  9285. WBUFL(buf,10) = ( nd->progressbar.timeout - gettick() ) / 1000;
  9286. if( sd ){
  9287. clif_send(buf, packet_len(0x9d1), &sd->bl, SELF);
  9288. }else{
  9289. clif_send(buf, packet_len(0x9d1), &nd->bl, AREA);
  9290. }
  9291. }
  9292. #endif
  9293. }
  9294. /// Request to walk to a certain position on the current map.
  9295. /// 0085 <dest>.3B (CZ_REQUEST_MOVE)
  9296. /// 035f <dest>.3B (CZ_REQUEST_MOVE2)
  9297. /// There are various variants of this packet, some of them have padding between fields.
  9298. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  9299. {
  9300. short x, y;
  9301. if (pc_isdead(sd)) {
  9302. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9303. return;
  9304. }
  9305. if (sd->sc.opt1 && ( sd->sc.opt1 == OPT1_STONEWAIT || sd->sc.opt1 == OPT1_BURNING ))
  9306. ; //You CAN walk on this OPT1 value.
  9307. else if (sd->progressbar.npc_id) {
  9308. clif_progressbar_abort(sd);
  9309. return; // First walk attempt cancels the progress bar
  9310. } else if (pc_cant_act(sd))
  9311. return;
  9312. if(sd->sc.data[SC_RUN] || sd->sc.data[SC_WUGDASH])
  9313. return;
  9314. RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
  9315. //A move command one cell west is only valid if the target cell is free
  9316. if(battle_config.official_cell_stack_limit > 0
  9317. && sd->bl.x == x+1 && sd->bl.y == y && map_count_oncell(sd->bl.m, x, y, BL_CHAR|BL_NPC, 1))
  9318. return;
  9319. // Cloaking wall check is actually updated when you click to process next movement
  9320. // not when you move each cell. This is official behaviour.
  9321. if (sd->sc.data[SC_CLOAKING])
  9322. skill_check_cloaking(&sd->bl, sd->sc.data[SC_CLOAKING]);
  9323. status_change_end(&sd->bl, SC_ROLLINGCUTTER, INVALID_TIMER); // If you move, you lose your counters. [malufett]
  9324. pc_delinvincibletimer(sd);
  9325. //Set last idle time... [Skotlex]
  9326. if (battle_config.idletime_option&IDLE_WALK)
  9327. sd->idletime = last_tick;
  9328. unit_walktoxy(&sd->bl, x, y, 4);
  9329. }
  9330. /// Notification about the result of a disconnect request (ZC_ACK_REQ_DISCONNECT).
  9331. /// 018b <result>.W
  9332. /// result:
  9333. /// 0 = disconnect (quit)
  9334. /// 1 = cannot disconnect (wait 10 seconds)
  9335. /// ? = ignored
  9336. void clif_disconnect_ack(struct map_session_data* sd, short result)
  9337. {
  9338. int fd = sd->fd;
  9339. WFIFOHEAD(fd,packet_len(0x18b));
  9340. WFIFOW(fd,0) = 0x18b;
  9341. WFIFOW(fd,2) = result;
  9342. WFIFOSET(fd,packet_len(0x18b));
  9343. }
  9344. /// Request to disconnect from server (CZ_REQ_DISCONNECT).
  9345. /// 018a <type>.W
  9346. /// type:
  9347. /// 0 = quit
  9348. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  9349. {
  9350. /* Rovert's prevent logout option fixed [Valaris] */
  9351. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9352. 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] &&
  9353. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9354. {
  9355. set_eof(fd);
  9356. pc_damage_log_clear(sd,0);
  9357. clif_disconnect_ack(sd, 0);
  9358. } else {
  9359. clif_disconnect_ack(sd, 1);
  9360. }
  9361. }
  9362. /// Requesting unit's name.
  9363. /// 0094 <id>.L (CZ_REQNAME)
  9364. /// 0368 <id>.L (CZ_REQNAME2)
  9365. /// There are various variants of this packet, some of them have padding between fields.
  9366. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  9367. {
  9368. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9369. struct block_list* bl;
  9370. //struct status_change *sc;
  9371. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  9372. id = sd->bl.id;
  9373. bl = map_id2bl(id);
  9374. if( bl == NULL )
  9375. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  9376. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  9377. return; // Block namerequests past view range
  9378. // 'see people in GM hide' cheat detection
  9379. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  9380. sc = status_get_sc(bl);
  9381. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  9382. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  9383. pc_get_group_level(sd) < battle_config.hack_info_GM_level
  9384. ) {
  9385. char gm_msg[256];
  9386. 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);
  9387. ShowWarning(gm_msg);
  9388. // information is sent to all online GMs
  9389. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  9390. return;
  9391. }
  9392. */
  9393. clif_name(&sd->bl,bl,SELF);
  9394. }
  9395. /// Validates and processes global messages
  9396. /// 008c <packet len>.W <text>.?B (<name> : <message>) 00 (CZ_REQUEST_CHAT)
  9397. /// There are various variants of this packet.
  9398. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  9399. {
  9400. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9401. size_t length;
  9402. // validate packet and retrieve name and message
  9403. if( !clif_process_message(sd, false, name, message, output ) )
  9404. return;
  9405. if( sd->gcbind && ((sd->gcbind->opt&CHAN_OPT_CAN_CHAT) || pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN)) ) {
  9406. channel_send(sd->gcbind,sd,message);
  9407. return;
  9408. }
  9409. // send message to others (using the send buffer for temp. storage)
  9410. clif_GlobalMessage(&sd->bl,output,sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  9411. length = strlen(output) + 1;
  9412. // send back message to the speaker
  9413. WFIFOHEAD(fd,4+length);
  9414. WFIFOW(fd,0) = 0x8e;
  9415. WFIFOW(fd,2) = (uint16)(4+length);
  9416. safestrncpy(WFIFOCP(fd,4), output, length );
  9417. WFIFOSET(fd, WFIFOW(fd,2));
  9418. #ifdef PCRE_SUPPORT
  9419. // trigger listening npcs
  9420. map_foreachinallrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, output, strlen(output), &sd->bl);
  9421. #endif
  9422. // Chat logging type 'O' / Global Chat
  9423. 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);
  9424. //achievement_update_objective(sd, AG_CHAT, 1, sd->bl.m); //! TODO: What's the official use of this achievement type?
  9425. }
  9426. /// /mm /mapmove (as @rura GM command) (CZ_MOVETO_MAP).
  9427. /// Request to warp to a map on given coordinates.
  9428. /// 0140 <map name>.16B <x>.W <y>.W
  9429. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  9430. {
  9431. char command[MAP_NAME_LENGTH_EXT+25];
  9432. char* map_name;
  9433. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9434. map_name = RFIFOCP(fd,info->pos[0]);
  9435. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  9436. safesnprintf(command,sizeof(command),"%cmapmove %s %d %d", atcommand_symbol, map_name,
  9437. RFIFOW(fd,info->pos[1]), //x
  9438. RFIFOW(fd,info->pos[2])); //y
  9439. is_atcommand(fd, sd, command, 1);
  9440. }
  9441. /// Updates body and head direction of an object (ZC_CHANGE_DIRECTION).
  9442. /// 009c <id>.L <head dir>.W <dir>.B
  9443. /// head dir:
  9444. /// 0 = straight
  9445. /// 1 = turned CW
  9446. /// 2 = turned CCW
  9447. /// dir:
  9448. /// 0 = north
  9449. /// 1 = northwest
  9450. /// 2 = west
  9451. /// 3 = southwest
  9452. /// 4 = south
  9453. /// 5 = southeast
  9454. /// 6 = east
  9455. /// 7 = northeast
  9456. void clif_changed_dir(struct block_list *bl, enum send_target target)
  9457. {
  9458. unsigned char buf[64];
  9459. WBUFW(buf,0) = 0x9c;
  9460. WBUFL(buf,2) = bl->id;
  9461. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  9462. WBUFB(buf,8) = unit_getdir(bl);
  9463. clif_send(buf, packet_len(0x9c), bl, target);
  9464. if (disguised(bl)) {
  9465. WBUFL(buf,2) = -bl->id;
  9466. WBUFW(buf,6) = 0;
  9467. clif_send(buf, packet_len(0x9c), bl, SELF);
  9468. }
  9469. }
  9470. /// Request to change own body and head direction.
  9471. /// 009b <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION)
  9472. /// 0361 <head dir>.W <dir>.B (CZ_CHANGE_DIRECTION2)
  9473. /// There are various variants of this packet, some of them have padding between fields.
  9474. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  9475. {
  9476. unsigned char headdir, dir;
  9477. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9478. headdir = RFIFOB(fd,info->pos[0]);
  9479. dir = RFIFOB(fd,info->pos[1]);
  9480. pc_setdir(sd, dir, headdir);
  9481. clif_changed_dir(&sd->bl, AREA_WOS);
  9482. }
  9483. /// Request to show an emotion (CZ_REQ_EMOTION).
  9484. /// 00bf <type>.B
  9485. /// type:
  9486. /// @see enum emotion_type
  9487. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  9488. {
  9489. int emoticon = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9490. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2 || pc_checkskill(sd, SU_BASIC_SKILL) >= 1) {
  9491. if (emoticon == ET_CHAT_PROHIBIT) {// prevent use of the mute emote [Valaris]
  9492. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9493. return;
  9494. }
  9495. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  9496. if (sd->emotionlasttime + 1 >= time(NULL)) { // not more than 1 per second
  9497. sd->emotionlasttime = time(NULL);
  9498. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9499. return;
  9500. }
  9501. sd->emotionlasttime = time(NULL);
  9502. if (battle_config.idletime_option&IDLE_EMOTION)
  9503. sd->idletime = last_tick;
  9504. if(battle_config.client_reshuffle_dice && emoticon>=ET_DICE1 && emoticon<=ET_DICE6) {// re-roll dice
  9505. emoticon = rnd()%6+ET_DICE1;
  9506. }
  9507. clif_emotion(&sd->bl, emoticon);
  9508. } else
  9509. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 1);
  9510. }
  9511. /// Amount of currently online players, reply to /w /who (ZC_USER_COUNT).
  9512. /// 00c2 <count>.L
  9513. void clif_user_count(struct map_session_data* sd, int count)
  9514. {
  9515. int fd = sd->fd;
  9516. WFIFOHEAD(fd,packet_len(0xc2));
  9517. WFIFOW(fd,0) = 0xc2;
  9518. WFIFOL(fd,2) = count;
  9519. WFIFOSET(fd,packet_len(0xc2));
  9520. }
  9521. /// /w /who (CZ_REQ_USER_COUNT).
  9522. /// Request to display amount of currently connected players.
  9523. /// 00c1
  9524. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  9525. {
  9526. clif_user_count(sd, map_getusers());
  9527. }
  9528. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  9529. {
  9530. if (pc_isdead(sd)) {
  9531. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9532. return;
  9533. }
  9534. // Statuses that don't let the player sit / attack / talk with NPCs(targeted)
  9535. // (not all are included in pc_can_attack)
  9536. if (sd->sc.count &&
  9537. (sd->sc.data[SC_TRICKDEAD] ||
  9538. (sd->sc.data[SC_AUTOCOUNTER] && action_type != 0x07) ||
  9539. sd->sc.data[SC_BLADESTOP] ||
  9540. sd->sc.data[SC__MANHOLE] ||
  9541. sd->sc.data[SC_SUHIDE] ))
  9542. return;
  9543. if(action_type != 0x00 && action_type != 0x07)
  9544. pc_stop_walking(sd, 1);
  9545. pc_stop_attack(sd);
  9546. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  9547. target_id = sd->bl.id;
  9548. switch(action_type)
  9549. {
  9550. case 0x00: // once attack
  9551. case 0x07: // continuous attack
  9552. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  9553. return;
  9554. if( sd->sc.option&OPTION_COSTUME )
  9555. return;
  9556. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  9557. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  9558. clif_skill_fail(sd, 1, USESKILL_FAIL_SKILLINTERVAL, 0);
  9559. return;
  9560. }
  9561. }
  9562. pc_delinvincibletimer(sd);
  9563. if (battle_config.idletime_option&IDLE_ATTACK)
  9564. sd->idletime = last_tick;
  9565. unit_attack(&sd->bl, target_id, action_type != 0);
  9566. break;
  9567. case 0x02: // sitdown
  9568. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  9569. clif_skill_fail(sd, 1, USESKILL_FAIL_LEVEL, 2);
  9570. break;
  9571. }
  9572. if(pc_issit(sd)) {
  9573. //Bugged client? Just refresh them.
  9574. clif_sitting(&sd->bl);
  9575. return;
  9576. }
  9577. if (sd->ud.skilltimer != INVALID_TIMER || (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING))
  9578. break;
  9579. if (sd->sc.count && (
  9580. sd->sc.data[SC_DANCING] ||
  9581. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  9582. )) //No sitting during these states either.
  9583. break;
  9584. if (battle_config.idletime_option&IDLE_SIT)
  9585. sd->idletime = last_tick;
  9586. pc_setsit(sd);
  9587. skill_sit(sd, 1);
  9588. clif_sitting(&sd->bl);
  9589. break;
  9590. case 0x03: // standup
  9591. if (!pc_issit(sd)) {
  9592. //Bugged client? Just refresh them.
  9593. clif_standing(&sd->bl);
  9594. return;
  9595. }
  9596. if (sd->sc.opt1 && sd->sc.opt1 != OPT1_STONEWAIT && sd->sc.opt1 != OPT1_BURNING)
  9597. break;
  9598. if (pc_setstand(sd, false)) {
  9599. if (battle_config.idletime_option&IDLE_SIT)
  9600. sd->idletime = last_tick;
  9601. skill_sit(sd, 0);
  9602. clif_standing(&sd->bl);
  9603. }
  9604. break;
  9605. }
  9606. }
  9607. /// Request for an action.
  9608. /// 0089 <target id>.L <action>.B (CZ_REQUEST_ACT)
  9609. /// 0437 <target id>.L <action>.B (CZ_REQUEST_ACT2)
  9610. /// action:
  9611. /// 0 = attack
  9612. /// 1 = pick up item
  9613. /// 2 = sit down
  9614. /// 3 = stand up
  9615. /// 7 = continous attack
  9616. /// 12 = (touch skill?)
  9617. /// There are various variants of this packet, some of them have padding between fields.
  9618. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  9619. {
  9620. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9621. clif_parse_ActionRequest_sub(sd,
  9622. RFIFOB(fd,info->pos[1]),
  9623. RFIFOL(fd,info->pos[0]),
  9624. gettick()
  9625. );
  9626. }
  9627. /// Response to the death/system menu (CZ_RESTART).
  9628. /// 00b2 <type>.B
  9629. /// type:
  9630. /// 0 = restart (respawn)
  9631. /// 1 = char-select (disconnect)
  9632. void clif_parse_Restart(int fd, struct map_session_data *sd)
  9633. {
  9634. switch(RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0])) {
  9635. case 0x00:
  9636. pc_respawn(sd,CLR_OUTSIGHT);
  9637. break;
  9638. case 0x01:
  9639. /* Rovert's Prevent logout option - Fixed [Valaris] */
  9640. 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] &&
  9641. (!battle_config.prevent_logout || sd->canlog_tick == 0 || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  9642. { //Send to char-server for character selection.
  9643. pc_damage_log_clear(sd,0);
  9644. chrif_charselectreq(sd, session[fd]->client_addr);
  9645. } else {
  9646. clif_disconnect_ack(sd, 1);
  9647. }
  9648. break;
  9649. }
  9650. }
  9651. /// Validates and processes whispered messages (CZ_WHISPER).
  9652. /// 0096 <packet len>.W <nick>.24B <message>.?B
  9653. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  9654. {
  9655. struct map_session_data* dstsd;
  9656. int i;
  9657. char target[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  9658. // validate packet and retrieve name and message
  9659. if( !clif_process_message( sd, true, target, message, output ) )
  9660. return;
  9661. // Chat logging type 'W' / Whisper
  9662. 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);
  9663. //-------------------------------------------------------//
  9664. // Lordalfa - Paperboy - To whisper NPC commands //
  9665. //-------------------------------------------------------//
  9666. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  9667. {
  9668. char* str = target+4; //Skip the NPC: string part.
  9669. struct npc_data* npc;
  9670. if ((npc = npc_name2id(str))) {
  9671. char split_data[NUM_WHISPER_VAR][CHAT_SIZE_MAX];
  9672. char *split;
  9673. char event[EVENT_NAME_LENGTH];
  9674. str = message;
  9675. // skip codepage indicator, if detected
  9676. if( str[0] == '|' && strlen(str) >= 4 )
  9677. str += 3;
  9678. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {// Splits the message using '#' as separators
  9679. split = strchr(str,'#');
  9680. if( split == NULL ) { // use the remaining string
  9681. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9682. for( ++i; i < NUM_WHISPER_VAR; ++i )
  9683. split_data[i][0] = '\0';
  9684. break;
  9685. }
  9686. *split = '\0';
  9687. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  9688. str = split+1;
  9689. }
  9690. for( i = 0; i < NUM_WHISPER_VAR; ++i ) {
  9691. char variablename[CHAT_SIZE_MAX];
  9692. safesnprintf(variablename,sizeof(variablename),"@whispervar%d$", i);
  9693. set_var(sd,variablename,(char *) split_data[i]);
  9694. }
  9695. safesnprintf(event,sizeof(event),"%s::%s", npc->exname,script_config.onwhisper_event_name);
  9696. npc_event(sd,event,0); // Calls the NPC label
  9697. return;
  9698. }
  9699. } else if( target[0] == '#' ) {
  9700. struct Channel *channel = NULL;
  9701. char* chname = target;
  9702. channel = channel_name2channel(chname,sd,3);
  9703. if(channel && (pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) || ((channel->opt&CHAN_OPT_CAN_CHAT) && channel_pccheckgroup(channel,sd->group_id)))){
  9704. if(channel_pc_haschan(sd,channel)>=0){ //we are in the chan
  9705. channel_send(channel,sd,message);
  9706. }
  9707. else if( channel->pass[0] == '\0') { //no pass needed
  9708. if (channel_join(channel,sd)==0)
  9709. channel_send(channel,sd,message); //join success
  9710. }
  9711. else {
  9712. clif_displaymessage(fd, msg_txt(sd,1402)); //You're not in that channel, type '@join <#channel_name>'
  9713. }
  9714. return;
  9715. }
  9716. }
  9717. // searching destination character
  9718. dstsd = map_nick2sd(target,false);
  9719. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0) {
  9720. // player is not on this map-server
  9721. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  9722. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  9723. // and if we ask for 'Test', we must not contact 'test' player
  9724. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  9725. intif_wis_message(sd, target, message, strlen(message) + 1);
  9726. return;
  9727. }
  9728. // if player ignores everyone
  9729. if (dstsd->state.ignoreAll && pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9730. if (pc_isinvisible(dstsd) && pc_get_group_level(sd) < pc_get_group_level(dstsd))
  9731. clif_wis_end(fd, 1); // 1: target character is not logged in
  9732. else
  9733. clif_wis_end(fd, 3); // 3: everyone ignored by target
  9734. return;
  9735. }
  9736. // if player is autotrading
  9737. if (dstsd->state.autotrade == 1){
  9738. safesnprintf(output,sizeof(output),"%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  9739. clif_wis_message(sd, wisp_server_name, output, strlen(output) + 1, 0);
  9740. return;
  9741. }
  9742. if (pc_get_group_level(sd) <= pc_get_group_level(dstsd)) {
  9743. // if player ignores the source character
  9744. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  9745. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0') { // source char present in ignore list
  9746. clif_wis_end(fd, 2); // 2: ignored by target
  9747. return;
  9748. }
  9749. }
  9750. // notify sender of success
  9751. clif_wis_end(fd, 0); // 0: success to send wisper
  9752. // Normal message
  9753. clif_wis_message(dstsd, sd->status.name, message, strlen(message)+1, 0);
  9754. }
  9755. /// /b /nb (CZ_BROADCAST).
  9756. /// Request to broadcast a message on whole server.
  9757. /// 0099 <packet len>.W <text>.?B 00
  9758. void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
  9759. char command[CHAT_SIZE_MAX+11];
  9760. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9761. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  9762. char* msg = RFIFOCP(fd,info->pos[1]);
  9763. // as the length varies depending on the command used, just block unreasonably long strings
  9764. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9765. safesnprintf(command,sizeof(command),"%ckami %s", atcommand_symbol, msg);
  9766. is_atcommand(fd, sd, command, 1);
  9767. }
  9768. /// Request to pick up an item.
  9769. /// 009f <id>.L (CZ_ITEM_PICKUP)
  9770. /// 0362 <id>.L (CZ_ITEM_PICKUP2)
  9771. /// There are various variants of this packet, some of them have padding between fields.
  9772. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  9773. {
  9774. struct flooritem_data *fitem;
  9775. int map_object_id;
  9776. map_object_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  9777. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  9778. do {
  9779. if (pc_isdead(sd)) {
  9780. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9781. break;
  9782. }
  9783. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  9784. break;
  9785. if (pc_cant_act(sd))
  9786. break;
  9787. if (!pc_takeitem(sd, fitem))
  9788. break;
  9789. return;
  9790. } while (0);
  9791. // Client REQUIRES a fail packet or you can no longer pick items.
  9792. clif_additem(sd,0,0,6);
  9793. }
  9794. /// Request to drop an item.
  9795. /// 00a2 <index>.W <amount>.W (CZ_ITEM_THROW)
  9796. /// 0363 <index>.W <amount>.W (CZ_ITEM_THROW2)
  9797. /// There are various variants of this packet, some of them have padding between fields.
  9798. void clif_parse_DropItem(int fd, struct map_session_data *sd){
  9799. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9800. int item_index = RFIFOW(fd,info->pos[0]) -2;
  9801. int item_amount = RFIFOW(fd,info->pos[1]) ;
  9802. for(;;) {
  9803. if (pc_isdead(sd))
  9804. break;
  9805. if (pc_cant_act2(sd) || sd->npc_id)
  9806. break;
  9807. if (sd->sc.count && (
  9808. sd->sc.data[SC_AUTOCOUNTER] ||
  9809. sd->sc.data[SC_BLADESTOP] ||
  9810. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  9811. ))
  9812. break;
  9813. if (!pc_dropitem(sd, item_index, item_amount))
  9814. break;
  9815. if (battle_config.idletime_option&IDLE_DROPITEM)
  9816. sd->idletime = last_tick;
  9817. return;
  9818. }
  9819. //Because the client does not like being ignored.
  9820. clif_dropitem(sd, item_index,0);
  9821. }
  9822. /// Request to use an item.
  9823. /// 00a7 <index>.W <account id>.L (CZ_USE_ITEM)
  9824. /// 0439 <index>.W <account id>.L (CZ_USE_ITEM2)
  9825. /// There are various variants of this packet, some of them have padding between fields.
  9826. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  9827. {
  9828. int n;
  9829. if (pc_isdead(sd)) {
  9830. clif_clearunit_area(&sd->bl, CLR_DEAD);
  9831. return;
  9832. }
  9833. if ( (!sd->npc_id && pc_istrading(sd)) || sd->chatID )
  9834. return;
  9835. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  9836. if (battle_config.idletime_option&IDLE_USEITEM)
  9837. sd->idletime = last_tick;
  9838. n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9839. if(n <0 || n >= MAX_INVENTORY)
  9840. return;
  9841. if (!pc_useitem(sd,n))
  9842. clif_useitemack(sd,n,0,false); //Send an empty ack packet or the client gets stuck.
  9843. }
  9844. /// Request to equip an item
  9845. /// 00a9 <index>.W <position>.W (CZ_REQ_WEAR_EQUIP).
  9846. /// 0998 <index>.W <position>.L (CZ_REQ_WEAR_EQUIP_V5)
  9847. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  9848. {
  9849. int index;
  9850. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9851. if(pc_isdead(sd)) {
  9852. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9853. return;
  9854. }
  9855. index = RFIFOW(fd,info->pos[0])-2;
  9856. if (index < 0 || index >= MAX_INVENTORY)
  9857. return; //Out of bounds check.
  9858. if(sd->npc_id && !sd->npc_item_flag) {
  9859. return;
  9860. } else if (sd->state.storage_flag || sd->sc.opt1)
  9861. ; //You can equip/unequip stuff while storage is open/under status changes
  9862. else if (pc_cant_act2(sd))
  9863. return;
  9864. if(!sd->inventory.u.items_inventory[index].identify) {
  9865. clif_equipitemack(sd,index,0,ITEM_EQUIP_ACK_FAIL); // fail
  9866. return;
  9867. }
  9868. if(!sd->inventory_data[index])
  9869. return;
  9870. if(sd->inventory_data[index]->type == IT_PETARMOR){
  9871. pet_equipitem(sd,index);
  9872. return;
  9873. }
  9874. if (battle_config.idletime_option&IDLE_USEITEM)
  9875. sd->idletime = last_tick;
  9876. //Client doesn't send the position for ammo.
  9877. if(sd->inventory_data[index]->type == IT_AMMO)
  9878. pc_equipitem(sd,index,EQP_AMMO);
  9879. else {
  9880. int req_pos;
  9881. #if PACKETVER >= 20120925
  9882. req_pos = RFIFOL(fd,info->pos[1]);
  9883. #else
  9884. req_pos = (int)RFIFOW(fd,info->pos[1]);
  9885. #endif
  9886. pc_equipitem(sd,index,req_pos);
  9887. }
  9888. }
  9889. /// Request to take off an equip (CZ_REQ_TAKEOFF_EQUIP).
  9890. /// 00ab <index>.W
  9891. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  9892. {
  9893. int index;
  9894. if(pc_isdead(sd)) {
  9895. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9896. return;
  9897. }
  9898. if (sd->npc_id && !sd->npc_item_flag) {
  9899. return;
  9900. } else if (sd->state.storage_flag || sd->sc.opt1)
  9901. ; //You can equip/unequip stuff while storage is open/under status changes
  9902. else if (pc_cant_act2(sd))
  9903. return;
  9904. index = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
  9905. if (battle_config.idletime_option&IDLE_USEITEM)
  9906. sd->idletime = last_tick;
  9907. pc_unequipitem(sd,index,1);
  9908. }
  9909. /// Request to start a conversation with an NPC (CZ_CONTACTNPC).
  9910. /// 0090 <id>.L <type>.B
  9911. /// type:
  9912. /// 1 = click
  9913. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  9914. {
  9915. struct block_list *bl;
  9916. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9917. if(pc_isdead(sd)) {
  9918. clif_clearunit_area(&sd->bl,CLR_DEAD);
  9919. return;
  9920. }
  9921. #ifdef RENEWAL
  9922. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_NPC)) {
  9923. clif_msg(sd, WORK_IN_PROGRESS);
  9924. return;
  9925. }
  9926. #endif
  9927. if (pc_cant_act2(sd) || sd->npc_id)
  9928. return;
  9929. if( sd->state.mail_writing )
  9930. return;
  9931. bl = map_id2bl(RFIFOL(fd,info->pos[0]));
  9932. //type = RFIFOB(fd,info->pos[1]);
  9933. if (!bl) return;
  9934. switch (bl->type) {
  9935. case BL_MOB:
  9936. case BL_PC:
  9937. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  9938. break;
  9939. case BL_NPC:
  9940. #ifdef RENEWAL
  9941. 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
  9942. clif_msg(sd, WORK_IN_PROGRESS);
  9943. break;
  9944. }
  9945. #endif
  9946. if( bl->m != -1 ){ // the user can't click floating npcs directly (hack attempt)
  9947. struct npc_data* nd = (struct npc_data*)bl;
  9948. // Progressbar is running
  9949. if( nd->progressbar.timeout > 0 ){
  9950. return;
  9951. }
  9952. npc_click(sd,nd);
  9953. }
  9954. break;
  9955. }
  9956. }
  9957. /// Selection between buy/sell was made (CZ_ACK_SELECT_DEALTYPE).
  9958. /// 00c5 <id>.L <type>.B
  9959. /// type:
  9960. /// 0 = buy
  9961. /// 1 = sell
  9962. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  9963. {
  9964. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9965. if (sd->state.trading)
  9966. return;
  9967. npc_buysellsel(sd,RFIFOL(fd,info->pos[0]),RFIFOB(fd,info->pos[1]));
  9968. }
  9969. /// Notification about the result of a purchase attempt from an NPC shop (ZC_PC_PURCHASE_RESULT).
  9970. /// 00ca <result>.B
  9971. /// result:
  9972. /// 0 = "The deal has successfully completed."
  9973. /// 1 = "You do not have enough zeny."
  9974. /// 2 = "You are over your Weight Limit."
  9975. /// 3 = "Out of the maximum capacity, you have too many items."
  9976. void clif_npc_buy_result(struct map_session_data* sd, unsigned char result)
  9977. {
  9978. int fd = sd->fd;
  9979. WFIFOHEAD(fd,packet_len(0xca));
  9980. WFIFOW(fd,0) = 0xca;
  9981. WFIFOB(fd,2) = result;
  9982. WFIFOSET(fd,packet_len(0xca));
  9983. }
  9984. /// Request to buy chosen items from npc shop (CZ_PC_PURCHASE_ITEMLIST).
  9985. /// 00c8 <packet len>.W { <amount>.W <name id>.W }*
  9986. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  9987. {
  9988. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  9989. uint16 n = (RFIFOW(fd,info->pos[0])-4) /4;
  9990. int result;
  9991. if( sd->state.trading || !sd->npc_shopid )
  9992. result = 1;
  9993. else
  9994. result = npc_buylist(sd, n, (struct s_npc_buy_list*)RFIFOP(fd,info->pos[1]));
  9995. sd->npc_shopid = 0; //Clear shop data.
  9996. clif_npc_buy_result(sd, result);
  9997. }
  9998. /// Notification about the result of a sell attempt to an NPC shop (ZC_PC_SELL_RESULT).
  9999. /// 00cb <result>.B
  10000. /// result:
  10001. /// 0 = "The deal has successfully completed."
  10002. /// 1 = "The deal has failed."
  10003. void clif_npc_sell_result(struct map_session_data* sd, unsigned char result)
  10004. {
  10005. int fd = sd->fd;
  10006. WFIFOHEAD(fd,packet_len(0xcb));
  10007. WFIFOW(fd,0) = 0xcb;
  10008. WFIFOB(fd,2) = result;
  10009. WFIFOSET(fd,packet_len(0xcb));
  10010. }
  10011. /// Request to sell chosen items to npc shop (CZ_PC_SELL_ITEMLIST).
  10012. /// 00c9 <packet len>.W { <index>.W <amount>.W }*
  10013. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  10014. {
  10015. int fail=0,n;
  10016. unsigned short *item_list;
  10017. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10018. n = (RFIFOW(fd,info->pos[0])-4) /4; // (pktlen-(cmd+len))/listsize
  10019. item_list = (unsigned short*)RFIFOP(fd,info->pos[1]);
  10020. if (sd->state.trading || !sd->npc_shopid)
  10021. fail = 1;
  10022. else
  10023. fail = npc_selllist(sd,n,item_list);
  10024. sd->npc_shopid = 0; //Clear shop data.
  10025. clif_npc_sell_result(sd, fail);
  10026. }
  10027. /// Chatroom creation request (CZ_CREATE_CHATROOM).
  10028. /// 00d5 <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10029. /// type:
  10030. /// 0 = private
  10031. /// 1 = public
  10032. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  10033. {
  10034. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10035. int len = RFIFOW(fd,info->pos[0])-15;
  10036. int limit = RFIFOW(fd,info->pos[1]);
  10037. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10038. const char* password = RFIFOCP(fd,info->pos[3]); //not zero-terminated
  10039. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10040. char s_password[CHATROOM_PASS_SIZE];
  10041. char s_title[CHATROOM_TITLE_SIZE];
  10042. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  10043. return;
  10044. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10045. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,3);
  10046. return;
  10047. }
  10048. if( npc_isnear(&sd->bl) ) {
  10049. // uncomment to send msg_txt.
  10050. //char output[150];
  10051. //sprintf(output, msg_txt(662), battle_config.min_npc_vendchat_distance);
  10052. //clif_displaymessage(sd->fd, output);
  10053. clif_skill_fail(sd,1,USESKILL_FAIL_THERE_ARE_NPC_AROUND,0);
  10054. return;
  10055. }
  10056. if( len <= 0 )
  10057. return; // invalid input
  10058. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10059. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10060. chat_createpcchat(sd, s_title, s_password, limit, pub);
  10061. }
  10062. /// Chatroom join request (CZ_REQ_ENTER_ROOM).
  10063. /// 00d9 <chat ID>.L <passwd>.8B
  10064. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd){
  10065. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10066. int chatid = RFIFOL(fd,info->pos[0]);
  10067. const char* password = RFIFOCP(fd,info->pos[1]); // not zero-terminated
  10068. chat_joinchat(sd,chatid,password);
  10069. }
  10070. /// Chatroom properties adjustment request (CZ_CHANGE_CHATROOM).
  10071. /// 00de <packet len>.W <limit>.W <type>.B <passwd>.8B <title>.?B
  10072. /// type:
  10073. /// 0 = private
  10074. /// 1 = public
  10075. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd){
  10076. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10077. int len = RFIFOW(fd,info->pos[0])-15;
  10078. int limit = RFIFOW(fd,info->pos[1]);
  10079. bool pub = (RFIFOB(fd,info->pos[2]) != 0);
  10080. const char* password = RFIFOCP(fd,info->pos[3]); // not zero-terminated
  10081. const char* title = RFIFOCP(fd,info->pos[4]); // not zero-terminated
  10082. char s_password[CHATROOM_PASS_SIZE];
  10083. char s_title[CHATROOM_TITLE_SIZE];
  10084. if( len <= 0 )
  10085. return; // invalid input
  10086. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  10087. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  10088. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  10089. }
  10090. /// Request to change the chat room ownership (CZ_REQ_ROLE_CHANGE).
  10091. /// 00e0 <role>.L <nick>.24B
  10092. /// role:
  10093. /// 0 = owner
  10094. /// 1 = normal
  10095. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  10096. {
  10097. //int role = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10098. chat_changechatowner(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]));
  10099. }
  10100. /// Request to expel a player from chat room (CZ_REQ_EXPEL_MEMBER).
  10101. /// 00e2 <name>.24B
  10102. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  10103. {
  10104. chat_kickchat(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10105. }
  10106. /// Request to leave the current chatroom (CZ_EXIT_ROOM).
  10107. /// 00e3
  10108. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  10109. {
  10110. chat_leavechat(sd,0);
  10111. }
  10112. //Handles notifying asker and rejecter of what has just ocurred.
  10113. //Type is used to determine the correct msg_txt to use:
  10114. //0:
  10115. static void clif_noask_sub(struct map_session_data *sd, struct map_session_data *tsd, int type)
  10116. {
  10117. const char* msg;
  10118. char output[256];
  10119. // Your request has been rejected by autoreject option.
  10120. msg = msg_txt(sd,392);
  10121. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], msg, false, SELF);
  10122. //Notice that a request was rejected.
  10123. snprintf(output, 256, msg_txt(tsd,393+type), sd->status.name, 256);
  10124. clif_messagecolor(&tsd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  10125. }
  10126. /// Request to begin a trade (CZ_REQ_EXCHANGE_ITEM).
  10127. /// 00e4 <account id>.L
  10128. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  10129. {
  10130. struct map_session_data *t_sd;
  10131. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10132. if(!sd->chatID && pc_cant_act(sd))
  10133. return; //You can trade while in a chatroom.
  10134. if(t_sd){
  10135. // @noask [LuzZza]
  10136. if(t_sd->state.noask) {
  10137. clif_noask_sub(sd, t_sd, 0);
  10138. return;
  10139. }
  10140. if (t_sd->state.mail_writing) {
  10141. int old = sd->trade_partner;
  10142. // Fake trading
  10143. sd->trade_partner = t_sd->status.account_id;
  10144. clif_tradestart(sd, 5);
  10145. // Restore old state
  10146. sd->trade_partner = old;
  10147. return;
  10148. }
  10149. }
  10150. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1 && pc_checkskill(sd, SU_BASIC_SKILL) < 1) {
  10151. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,0);
  10152. return;
  10153. }
  10154. trade_traderequest(sd,t_sd);
  10155. }
  10156. /// Answer to a trade request (CZ_ACK_EXCHANGE_ITEM).
  10157. /// 00e6 <result>.B
  10158. /// result:
  10159. /// 3 = accepted
  10160. /// 4 = rejected
  10161. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  10162. {
  10163. trade_tradeack(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10164. }
  10165. /// Request to add an item to current trade (CZ_ADD_EXCHANGE_ITEM).
  10166. /// 00e8 <index>.W <amount>.L
  10167. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  10168. {
  10169. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10170. short index = RFIFOW(fd,info->pos[0]);
  10171. int amount = RFIFOL(fd,info->pos[1]);
  10172. if( index == 0 )
  10173. trade_tradeaddzeny(sd, amount);
  10174. else
  10175. trade_tradeadditem(sd, index, (short)amount);
  10176. }
  10177. /// Request to lock items in current trade (CZ_CONCLUDE_EXCHANGE_ITEM).
  10178. /// 00eb
  10179. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  10180. {
  10181. trade_tradeok(sd);
  10182. }
  10183. /// Request to cancel current trade (CZ_CANCEL_EXCHANGE_ITEM).
  10184. /// 00ed
  10185. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  10186. {
  10187. trade_tradecancel(sd);
  10188. }
  10189. /// Request to commit current trade (CZ_EXEC_EXCHANGE_ITEM).
  10190. /// 00ef
  10191. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  10192. {
  10193. trade_tradecommit(sd);
  10194. }
  10195. /// Request to stop chasing/attacking an unit (CZ_CANCEL_LOCKON).
  10196. /// 0118
  10197. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  10198. {
  10199. pc_stop_attack(sd);
  10200. if (sd) sd->ud.state.attack_continue = 0;
  10201. }
  10202. /// Request to move an item from inventory to cart (CZ_MOVE_ITEM_FROM_BODY_TO_CART).
  10203. /// 0126 <index>.W <amount>.L
  10204. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  10205. {
  10206. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10207. if (pc_istrading(sd))
  10208. return;
  10209. if (!pc_iscarton(sd))
  10210. return;
  10211. pc_putitemtocart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10212. }
  10213. /// Request to move an item from cart to inventory (CZ_MOVE_ITEM_FROM_CART_TO_BODY).
  10214. /// 0127 <index>.W <amount>.L
  10215. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  10216. {
  10217. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10218. if (!pc_iscarton(sd))
  10219. return;
  10220. pc_getitemfromcart(sd,RFIFOW(fd,info->pos[0])-2,RFIFOL(fd,info->pos[1]));
  10221. }
  10222. /// Request to remove cart/falcon/peco/dragon/mado (CZ_REQ_CARTOFF).
  10223. /// 012a
  10224. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  10225. {
  10226. if( !(sd->sc.option&(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR))
  10227. #ifdef NEW_CARTS
  10228. && sd->sc.data[SC_PUSH_CART] )
  10229. pc_setcart(sd,0);
  10230. #else
  10231. )
  10232. pc_setoption(sd,sd->sc.option&~OPTION_CART);
  10233. #endif
  10234. else // priority to remove this option before we can clear cart
  10235. pc_setoption(sd,sd->sc.option&~(OPTION_RIDING|OPTION_FALCON|OPTION_DRAGON|OPTION_MADOGEAR));
  10236. }
  10237. /// Request to select cart's visual look for new cart design (ZC_SELECTCART).
  10238. /// 097f <Length>.W <identity>.L <type>.B
  10239. void clif_SelectCart(struct map_session_data *sd) {
  10240. #if PACKETVER >= 20150826
  10241. int i = 0, carts = 3;
  10242. int fd = sd->fd;
  10243. WFIFOHEAD(fd,8 + carts);
  10244. WFIFOW(fd,0) = 0x97f;
  10245. WFIFOW(fd,2) = 8 + carts;
  10246. WFIFOL(fd,4) = sd->status.account_id;
  10247. // Right now we have 10-12, tested it you can also enable selection for all cart styles here(1-12)
  10248. for( i = 0; i < carts; i++ ) {
  10249. WFIFOB(fd,8 + i) = 10 + i;
  10250. }
  10251. WFIFOSET(fd,8 + carts);
  10252. #endif
  10253. }
  10254. /// Request to select cart's visual look for new cart design (CZ_SELECTCART).
  10255. /// 0980 <identity>.L <type>.B
  10256. void clif_parse_SelectCart(int fd,struct map_session_data *sd) {
  10257. #if PACKETVER >= 20150826
  10258. int type;
  10259. // Check identity
  10260. if( !sd || pc_checkskill(sd,MC_CARTDECORATE) < 1 || RFIFOL(fd,2) != sd->status.account_id )
  10261. return;
  10262. type = (int)RFIFOB(fd,6);
  10263. // Check type
  10264. if( type < 10 || type > MAX_CARTS )
  10265. return;
  10266. pc_setcart(sd, type);
  10267. #endif
  10268. }
  10269. /// Request to change cart's visual look (CZ_REQ_CHANGECART).
  10270. /// 01af <num>.W
  10271. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  10272. {// TODO: State tracking?
  10273. int type;
  10274. if( !sd || pc_checkskill(sd, MC_CHANGECART) < 1 )
  10275. return;
  10276. #ifdef RENEWAL
  10277. if (sd->npc_id || pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10278. clif_msg(sd, WORK_IN_PROGRESS);
  10279. return;
  10280. }
  10281. #endif
  10282. type = (int)RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10283. if(
  10284. #ifdef NEW_CARTS
  10285. (type == 9 && sd->status.base_level > 130) ||
  10286. (type == 8 && sd->status.base_level > 120) ||
  10287. (type == 7 && sd->status.base_level > 110) ||
  10288. (type == 6 && sd->status.base_level > 100) ||
  10289. #endif
  10290. (type == 5 && sd->status.base_level > 90) ||
  10291. (type == 4 && sd->status.base_level > 80) ||
  10292. (type == 3 && sd->status.base_level > 65) ||
  10293. (type == 2 && sd->status.base_level > 40) ||
  10294. (type == 1))
  10295. pc_setcart(sd, type);
  10296. }
  10297. /// Request to increase status (CZ_STATUS_CHANGE).
  10298. /// 00bb <status id>.W <amount>.B
  10299. /// status id:
  10300. /// SP_STR ~ SP_LUK
  10301. /// amount:
  10302. /// Old clients always send 1 for this, even when using /str+ and the like.
  10303. /// Newer clients (2013-12-23 and newer) send the correct amount.
  10304. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  10305. {
  10306. int increase_amount = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10307. if( increase_amount < 0 ) {
  10308. ShowDebug("clif_parse_StatusUp: Negative 'increase' value sent by client! (fd: %d, value: %d)\n",
  10309. fd, increase_amount);
  10310. }
  10311. pc_statusup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]),increase_amount);
  10312. }
  10313. /// Request to increase level of a skill (CZ_UPGRADE_SKILLLEVEL).
  10314. /// 0112 <skill id>.W
  10315. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  10316. {
  10317. pc_skillup(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10318. }
  10319. 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)
  10320. {
  10321. int lv;
  10322. if( !hd )
  10323. return;
  10324. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10325. clif_emotion(&hd->bl, ET_THINK);
  10326. return;
  10327. }
  10328. if( hd->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10329. target_id = hd->bl.id;
  10330. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10331. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10332. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10333. clif_emotion(&hd->bl, ET_THINK);
  10334. if (hd->master)
  10335. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10336. return;
  10337. }
  10338. lv = hom_checkskill(hd, skill_id);
  10339. if( skill_lv > lv )
  10340. skill_lv = lv;
  10341. if( skill_lv )
  10342. unit_skilluse_id(&hd->bl, target_id, skill_id, skill_lv);
  10343. }
  10344. 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)
  10345. {
  10346. int lv;
  10347. if( !hd )
  10348. return;
  10349. if( skill_isNotOk_hom(hd, skill_id, skill_lv) ) {
  10350. clif_emotion(&hd->bl, ET_THINK);
  10351. return;
  10352. }
  10353. if( hd->ud.skilltimer != INVALID_TIMER ) {
  10354. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10355. } else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 ) {
  10356. clif_emotion(&hd->bl, ET_THINK);
  10357. if (hd->master)
  10358. clif_skill_fail(hd->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10359. return;
  10360. }
  10361. if( hd->sc.data[SC_BASILICA] )
  10362. return;
  10363. lv = hom_checkskill(hd, skill_id);
  10364. if( skill_lv > lv )
  10365. skill_lv = lv;
  10366. if( skill_lv )
  10367. unit_skilluse_pos(&hd->bl, x, y, skill_id, skill_lv);
  10368. }
  10369. 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)
  10370. {
  10371. int lv;
  10372. if( !md )
  10373. return;
  10374. if( skill_isNotOk_mercenary(skill_id, md) )
  10375. return;
  10376. if( md->bl.id != target_id && skill_get_inf(skill_id)&INF_SELF_SKILL )
  10377. target_id = md->bl.id;
  10378. if( md->ud.skilltimer != INVALID_TIMER )
  10379. {
  10380. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST ) return;
  10381. }
  10382. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10383. return;
  10384. lv = mercenary_checkskill(md, skill_id);
  10385. if( skill_lv > lv )
  10386. skill_lv = lv;
  10387. if( skill_lv )
  10388. unit_skilluse_id(&md->bl, target_id, skill_id, skill_lv);
  10389. }
  10390. 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)
  10391. {
  10392. int lv;
  10393. if( !md )
  10394. return;
  10395. if( skill_isNotOk_mercenary(skill_id, md) )
  10396. return;
  10397. if( md->ud.skilltimer != INVALID_TIMER )
  10398. return;
  10399. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  10400. {
  10401. if (md->master)
  10402. clif_skill_fail(md->master, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10403. return;
  10404. }
  10405. if( md->sc.data[SC_BASILICA] )
  10406. return;
  10407. lv = mercenary_checkskill(md, skill_id);
  10408. if( skill_lv > lv )
  10409. skill_lv = lv;
  10410. if( skill_lv )
  10411. unit_skilluse_pos(&md->bl, x, y, skill_id, skill_lv);
  10412. }
  10413. /// Request to use a targeted skill.
  10414. /// 0113 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL)
  10415. /// 0438 <skill lv>.W <skill id>.W <target id>.L (CZ_USE_SKILL2)
  10416. /// There are various variants of this packet, some of them have padding between fields.
  10417. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  10418. {
  10419. uint16 skill_id, skill_lv;
  10420. int inf,target_id;
  10421. unsigned int tick = gettick();
  10422. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10423. skill_lv = RFIFOW(fd,info->pos[0]);
  10424. skill_id = RFIFOW(fd,info->pos[1]);
  10425. target_id = RFIFOL(fd,info->pos[2]);
  10426. if( skill_lv < 1 ) skill_lv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  10427. inf = skill_get_inf(skill_id);
  10428. if (inf&INF_GROUND_SKILL || !inf)
  10429. return; //Using a ground/passive skill on a target? WRONG.
  10430. if( SKILL_CHK_HOMUN(skill_id) ) {
  10431. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skill_id, skill_lv, target_id);
  10432. return;
  10433. }
  10434. if( SKILL_CHK_MERC(skill_id) ) {
  10435. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skill_id, skill_lv, target_id);
  10436. return;
  10437. }
  10438. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10439. if (battle_config.idletime_option&IDLE_USESKILLTOID)
  10440. sd->idletime = last_tick;
  10441. if (sd->npc_id) {
  10442. #ifdef RENEWAL
  10443. if (pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10444. clif_msg(sd, WORK_IN_PROGRESS);
  10445. return;
  10446. }
  10447. #else
  10448. if (!sd->npc_item_flag || !(inf&INF_SELF_SKILL))
  10449. return;
  10450. #endif
  10451. }
  10452. if( (pc_cant_act2(sd) || sd->chatID) && skill_id != RK_REFRESH && !(skill_id == SR_GENTLETOUCH_CURE &&
  10453. (sd->sc.opt1 == OPT1_STONE || sd->sc.opt1 == OPT1_FREEZE || sd->sc.opt1 == OPT1_STUN)) &&
  10454. sd->state.storage_flag && !(inf&INF_SELF_SKILL) ) //SELF skills can be used with the storage open, issue: 8027
  10455. return;
  10456. if( pc_issit(sd) )
  10457. return;
  10458. if( skill_isNotOk(skill_id, sd) )
  10459. return;
  10460. if( sd->bl.id != target_id && inf&INF_SELF_SKILL )
  10461. target_id = sd->bl.id; // never trust the client
  10462. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  10463. target_id = sd->bl.id;
  10464. if( sd->ud.skilltimer != INVALID_TIMER ) {
  10465. if( skill_id != SA_CASTCANCEL && skill_id != SO_SPELLFIST )
  10466. return;
  10467. } else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10468. if( sd->skillitem != skill_id ) {
  10469. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10470. return;
  10471. }
  10472. }
  10473. if( sd->sc.option&OPTION_COSTUME )
  10474. return;
  10475. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10476. return; // On basilica only caster can use Basilica again to stop it.
  10477. if( sd->menuskill_id ) {
  10478. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10479. clif_menuskill_clear(sd); //Cancel pet capture.
  10480. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10481. return; //Can't use skills while a menu is open.
  10482. }
  10483. if( sd->skillitem == skill_id ) {
  10484. if( skill_lv != sd->skillitemlv )
  10485. skill_lv = sd->skillitemlv;
  10486. if( !(inf&INF_SELF_SKILL) )
  10487. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  10488. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10489. return;
  10490. }
  10491. sd->skillitem = sd->skillitemlv = 0;
  10492. if( SKILL_CHK_GUILD(skill_id) ) {
  10493. if( sd->state.gmaster_flag )
  10494. skill_lv = guild_checkskill(sd->guild, skill_id);
  10495. else
  10496. skill_lv = 0;
  10497. } else {
  10498. skill_lv = min(pc_checkskill(sd, skill_id),skill_lv); //never trust client
  10499. }
  10500. pc_delinvincibletimer(sd);
  10501. if( skill_lv )
  10502. unit_skilluse_id(&sd->bl, target_id, skill_id, skill_lv);
  10503. }
  10504. /*==========================================
  10505. * Client tells server he'd like to use AoE skill id 'skill_id' of level 'skill_lv' on 'x','y' location
  10506. *------------------------------------------*/
  10507. static void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 skill_lv, uint16 skill_id, short x, short y, int skillmoreinfo)
  10508. {
  10509. unsigned int tick = gettick();
  10510. if( !(skill_get_inf(skill_id)&INF_GROUND_SKILL) )
  10511. return; //Using a target skill on the ground? WRONG.
  10512. if( SKILL_CHK_HOMUN(skill_id) ) {
  10513. clif_parse_UseSkillToPos_homun(sd->hd, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10514. return;
  10515. }
  10516. if( SKILL_CHK_MERC(skill_id) ) {
  10517. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skill_id, skill_lv, x, y, skillmoreinfo);
  10518. return;
  10519. }
  10520. #ifdef RENEWAL
  10521. if (pc_hasprogress(sd, WIP_DISABLE_SKILLITEM)) {
  10522. clif_msg(sd, WORK_IN_PROGRESS);
  10523. return;
  10524. }
  10525. #endif
  10526. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  10527. if (battle_config.idletime_option&IDLE_USESKILLTOPOS)
  10528. sd->idletime = last_tick;
  10529. if( skill_isNotOk(skill_id, sd) )
  10530. return;
  10531. if( skillmoreinfo != -1 ) {
  10532. if( pc_issit(sd) ) {
  10533. clif_skill_fail(sd, skill_id, USESKILL_FAIL_LEVEL, 0);
  10534. return;
  10535. }
  10536. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  10537. safestrncpy(sd->message, RFIFOCP(fd,skillmoreinfo), MESSAGE_SIZE);
  10538. }
  10539. if( sd->ud.skilltimer != INVALID_TIMER )
  10540. return;
  10541. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 ) {
  10542. if( sd->skillitem != skill_id ) {
  10543. clif_skill_fail(sd, skill_id, USESKILL_FAIL_SKILLINTERVAL, 0);
  10544. return;
  10545. }
  10546. }
  10547. if( sd->sc.option&OPTION_COSTUME )
  10548. return;
  10549. if( sd->sc.data[SC_BASILICA] && (skill_id != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  10550. return; // On basilica only caster can use Basilica again to stop it.
  10551. if( sd->menuskill_id ) {
  10552. if( sd->menuskill_id == SA_TAMINGMONSTER ) {
  10553. clif_menuskill_clear(sd); //Cancel pet capture.
  10554. } else if( sd->menuskill_id != SA_AUTOSPELL )
  10555. return; //Can't use skills while a menu is open.
  10556. }
  10557. pc_delinvincibletimer(sd);
  10558. if( sd->skillitem == skill_id ) {
  10559. if( skill_lv != sd->skillitemlv )
  10560. skill_lv = sd->skillitemlv;
  10561. unit_skilluse_pos(&sd->bl, x, y, skill_id, skill_lv);
  10562. } else {
  10563. int lv;
  10564. sd->skillitem = sd->skillitemlv = 0;
  10565. if( (lv = pc_checkskill(sd, skill_id)) > 0 ) {
  10566. if( skill_lv > lv )
  10567. skill_lv = lv;
  10568. unit_skilluse_pos(&sd->bl, x, y, skill_id,skill_lv);
  10569. }
  10570. }
  10571. }
  10572. /// Request to use a ground skill.
  10573. /// 0116 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND)
  10574. /// 0366 <skill lv>.W <skill id>.W <x>.W <y>.W (CZ_USE_SKILL_TOGROUND2)
  10575. /// 0AF4 <skill lv>.W <skill id>.W <x>.W <y>.W <unknown>.B (CZ_USE_SKILL_TOGROUND3)
  10576. /// There are various variants of this packet, some of them have padding between fields.
  10577. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  10578. {
  10579. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10580. if (pc_cant_act(sd))
  10581. return;
  10582. if (pc_issit(sd))
  10583. return;
  10584. clif_parse_UseSkillToPosSub(fd, sd,
  10585. RFIFOW(fd,info->pos[0]), //skill lv
  10586. RFIFOW(fd,info->pos[1]), //skill num
  10587. RFIFOW(fd,info->pos[2]), //pos x
  10588. RFIFOW(fd,info->pos[3]), //pos y
  10589. // TODO: find out what this is intended to do
  10590. //RFIFOB(fd, info->pos[4])
  10591. -1 //Skill more info.
  10592. );
  10593. }
  10594. /// Request to use a ground skill with text.
  10595. /// 0190 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX)
  10596. /// 0367 <skill lv>.W <skill id>.W <x>.W <y>.W <contents>.80B (CZ_USE_SKILL_TOGROUND_WITHTALKBOX2)
  10597. /// There are various variants of this packet, some of them have padding between fields.
  10598. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  10599. {
  10600. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10601. if (pc_cant_act(sd))
  10602. return;
  10603. if (pc_issit(sd))
  10604. return;
  10605. clif_parse_UseSkillToPosSub(fd, sd,
  10606. RFIFOW(fd,info->pos[0]), //Skill lv
  10607. RFIFOW(fd,info->pos[1]), //Skill num
  10608. RFIFOW(fd,info->pos[2]), //pos x
  10609. RFIFOW(fd,info->pos[3]), //pos y
  10610. info->pos[4] //skill more info
  10611. );
  10612. }
  10613. /// Answer to map selection dialog (CZ_SELECT_WARPPOINT).
  10614. /// 011b <skill id>.W <map name>.16B
  10615. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  10616. {
  10617. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10618. uint16 skill_id = RFIFOW(fd,info->pos[0]);
  10619. char map_name[MAP_NAME_LENGTH];
  10620. mapindex_getmapname(RFIFOCP(fd,info->pos[1]), map_name);
  10621. sd->state.workinprogress = WIP_DISABLE_NONE;
  10622. if(skill_id != sd->menuskill_id)
  10623. return;
  10624. //It is possible to use teleport with the storage window open bugreport:8027
  10625. if (pc_cant_act(sd) && !sd->state.storage_flag && skill_id != AL_TELEPORT) {
  10626. clif_menuskill_clear(sd);
  10627. return;
  10628. }
  10629. pc_delinvincibletimer(sd);
  10630. skill_castend_map(sd,skill_id,map_name);
  10631. }
  10632. /// Request to set a memo on current map (CZ_REMEMBER_WARPPOINT).
  10633. /// 011d
  10634. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  10635. {
  10636. if (!pc_isdead(sd))
  10637. pc_memo(sd,-1);
  10638. }
  10639. /// Answer to pharmacy item selection dialog (CZ_REQMAKINGITEM).
  10640. /// 018e <name id>.W { <material id>.W }*3
  10641. void clif_parse_ProduceMix(int fd,struct map_session_data *sd){
  10642. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10643. unsigned short nameid = RFIFOW(fd,info->pos[0]);
  10644. int slot1 = RFIFOW(fd,info->pos[1]);
  10645. int slot2 = RFIFOW(fd,info->pos[2]);
  10646. int slot3 = RFIFOW(fd,info->pos[3]);
  10647. short produce_idx = -1;
  10648. switch( sd->menuskill_id ) {
  10649. case -1:
  10650. case AM_PHARMACY:
  10651. case RK_RUNEMASTERY:
  10652. case GC_RESEARCHNEWPOISON:
  10653. break;
  10654. default:
  10655. return;
  10656. }
  10657. if (pc_istrading(sd)) {
  10658. //Make it fail to avoid shop exploits where you sell something different than you see.
  10659. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10660. clif_menuskill_clear(sd);
  10661. return;
  10662. }
  10663. if( (produce_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, 1)) )
  10664. skill_produce_mix(sd,0,nameid,slot1,slot2,slot3,1,produce_idx-1);
  10665. clif_menuskill_clear(sd);
  10666. }
  10667. /// Answer to mixing item selection dialog (CZ_REQ_MAKINGITEM).
  10668. /// 025b <mk type>.W <name id>.W
  10669. /// mk type:
  10670. /// 1 = cooking
  10671. /// 2 = arrow
  10672. /// 3 = elemental
  10673. /// 4 = GN_MIX_COOKING
  10674. /// 5 = GN_MAKEBOMB
  10675. /// 6 = GN_S_PHARMACY
  10676. void clif_parse_Cooking(int fd,struct map_session_data *sd) {
  10677. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10678. int type = RFIFOW(fd,info->pos[0]);
  10679. unsigned short nameid = RFIFOW(fd,info->pos[1]);
  10680. int amount = sd->menuskill_val2 ? sd->menuskill_val2 : 1;
  10681. short food_idx = -1;
  10682. if( type == 6 && sd->menuskill_id != GN_MIX_COOKING && sd->menuskill_id != GN_S_PHARMACY )
  10683. return;
  10684. if (pc_istrading(sd)) {
  10685. //Make it fail to avoid shop exploits where you sell something different than you see.
  10686. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10687. clif_menuskill_clear(sd);
  10688. return;
  10689. }
  10690. if( (food_idx = skill_can_produce_mix(sd,nameid,sd->menuskill_val, amount)) )
  10691. skill_produce_mix(sd,(type>1?sd->menuskill_id:0),nameid,0,0,0,amount,food_idx-1);
  10692. clif_menuskill_clear(sd);
  10693. }
  10694. /// Answer to repair weapon item selection dialog
  10695. /// 01fd <index> W (CZ_REQ_ITEMREPAIR)
  10696. /// 01fd <index>.W <name id>.W <refine>.B <card1>.W <card2>.W <card3>.W <card4>.W ???
  10697. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  10698. {
  10699. if (sd->menuskill_id != BS_REPAIRWEAPON)
  10700. return;
  10701. if (pc_istrading(sd)) {
  10702. //Make it fail to avoid shop exploits where you sell something different than you see.
  10703. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10704. clif_menuskill_clear(sd);
  10705. return;
  10706. }
  10707. skill_repairweapon(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10708. //nameid = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  10709. //refine = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  10710. //for(i = 0; i<MAX_SLOTS; i++)
  10711. // card[i] = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[3+i]);
  10712. clif_menuskill_clear(sd);
  10713. }
  10714. /// Answer to refine weapon item selection dialog (CZ_REQ_WEAPONREFINE).
  10715. /// 0222 <index>.L
  10716. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  10717. {
  10718. int idx;
  10719. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  10720. return;
  10721. if (pc_istrading(sd)) {
  10722. //Make it fail to avoid shop exploits where you sell something different than you see.
  10723. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10724. clif_menuskill_clear(sd);
  10725. return;
  10726. }
  10727. idx = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10728. skill_weaponrefine(sd, idx-2);
  10729. clif_menuskill_clear(sd);
  10730. }
  10731. /// Answer to script menu dialog (CZ_CHOOSE_MENU).
  10732. /// 00b8 <npc id>.L <choice>.B
  10733. /// choice:
  10734. /// 1~254 = menu item
  10735. /// 255 = cancel
  10736. /// NOTE: If there were more than 254 items in the list, choice
  10737. /// overflows to choice%256.
  10738. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd){
  10739. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10740. int npc_id = RFIFOL(fd,info->pos[0]);
  10741. uint8 select = RFIFOB(fd,info->pos[1]);
  10742. if( (select > sd->npc_menu && select != 0xff) || select == 0 ) {
  10743. #ifdef SECURE_NPCTIMEOUT
  10744. if( sd->npc_idle_timer != INVALID_TIMER ) {
  10745. #endif
  10746. TBL_NPC* nd = map_id2nd(npc_id);
  10747. 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);
  10748. clif_GM_kick(NULL,sd);
  10749. #ifdef SECURE_NPCTIMEOUT
  10750. }
  10751. #endif
  10752. return;
  10753. }
  10754. sd->npc_menu = select;
  10755. npc_scriptcont(sd,npc_id, false);
  10756. }
  10757. /// NPC dialog 'next' click (CZ_REQ_NEXT_SCRIPT).
  10758. /// 00b9 <npc id>.L
  10759. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  10760. {
  10761. npc_scriptcont(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), false);
  10762. }
  10763. /// NPC numeric input dialog value (CZ_INPUT_EDITDLG).
  10764. /// 0143 <npc id>.L <value>.L
  10765. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd){
  10766. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10767. int npcid = RFIFOL(fd,info->pos[0]);
  10768. int amount = (int)RFIFOL(fd,info->pos[1]);
  10769. sd->npc_amount = amount;
  10770. npc_scriptcont(sd, npcid, false);
  10771. }
  10772. /// NPC text input dialog value (CZ_INPUT_EDITDLGSTR).
  10773. /// 01d5 <packet len>.W <npc id>.L <string>.?B
  10774. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd){
  10775. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10776. int message_len = RFIFOW(fd,info->pos[0])-8;
  10777. int npcid = RFIFOL(fd,info->pos[1]);
  10778. const char* message = RFIFOCP(fd,info->pos[2]);
  10779. if( message_len <= 0 )
  10780. return; // invalid input
  10781. #if PACKETVER >= 20151001
  10782. message_len++;
  10783. #endif
  10784. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  10785. npc_scriptcont(sd, npcid, false);
  10786. }
  10787. /// NPC dialog 'close' click (CZ_CLOSE_DIALOG).
  10788. /// 0146 <npc id>.L
  10789. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  10790. {
  10791. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  10792. return;
  10793. npc_scriptcont(sd, RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]), true);
  10794. }
  10795. /// Answer to identify item selection dialog (CZ_REQ_ITEMIDENTIFY).
  10796. /// 0178 <index>.W
  10797. /// index:
  10798. /// -1 = cancel
  10799. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd) {
  10800. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2;
  10801. if (sd->menuskill_id != MC_IDENTIFY)
  10802. return;
  10803. // Ignore the request
  10804. // - Invalid item index
  10805. // - Invalid item ID or item doesn't exist
  10806. // - Item is already identified
  10807. if (idx < 0 || idx >= MAX_INVENTORY ||
  10808. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  10809. sd->inventory.u.items_inventory[idx].identify) {// cancel pressed
  10810. sd->state.workinprogress = WIP_DISABLE_NONE;
  10811. clif_menuskill_clear(sd);
  10812. return;
  10813. }
  10814. skill_identify(sd, idx);
  10815. clif_menuskill_clear(sd);
  10816. }
  10817. /// Answer to arrow crafting item selection dialog (CZ_REQ_MAKINGARROW).
  10818. /// 01ae <name id>.W
  10819. void clif_parse_SelectArrow(int fd,struct map_session_data *sd) {
  10820. unsigned short nameid = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10821. if (pc_istrading(sd)) {
  10822. //Make it fail to avoid shop exploits where you sell something different than you see.
  10823. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  10824. clif_menuskill_clear(sd);
  10825. return;
  10826. }
  10827. switch (sd->menuskill_id) {
  10828. case AC_MAKINGARROW:
  10829. skill_arrow_create(sd,nameid);
  10830. break;
  10831. case SA_CREATECON:
  10832. skill_produce_mix(sd,SA_CREATECON,nameid,0,0,0,1,-1);
  10833. break;
  10834. case WL_READING_SB:
  10835. skill_spellbook(sd,nameid);
  10836. break;
  10837. case GC_POISONINGWEAPON:
  10838. skill_poisoningweapon(sd,nameid);
  10839. break;
  10840. case NC_MAGICDECOY:
  10841. skill_magicdecoy(sd,nameid);
  10842. break;
  10843. }
  10844. clif_menuskill_clear(sd);
  10845. }
  10846. /// Answer to SA_AUTOSPELL skill selection dialog (CZ_SELECTAUTOSPELL).
  10847. /// 01ce <skill id>.L
  10848. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  10849. {
  10850. if (sd->menuskill_id != SA_AUTOSPELL)
  10851. return;
  10852. sd->state.workinprogress = WIP_DISABLE_NONE;
  10853. skill_autospell(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  10854. clif_menuskill_clear(sd);
  10855. }
  10856. /// Request to display item carding/composition list (CZ_REQ_ITEMCOMPOSITION_LIST).
  10857. /// 017a <card index>.W
  10858. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  10859. {
  10860. if (sd->state.trading != 0)
  10861. return;
  10862. clif_use_card(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  10863. }
  10864. /// Answer to carding/composing item selection dialog (CZ_REQ_ITEMCOMPOSITION).
  10865. /// 017c <card index>.W <equip index>.W
  10866. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  10867. {
  10868. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10869. if (sd->state.trading != 0)
  10870. return;
  10871. pc_insert_card(sd,RFIFOW(fd,info->pos[0])-2,RFIFOW(fd,info->pos[1])-2);
  10872. }
  10873. /// Request of character's name by char ID.
  10874. /// 0193 <char id>.L (CZ_REQNAME_BYGID)
  10875. /// 0369 <char id>.L (CZ_REQNAME_BYGID2)
  10876. /// There are various variants of this packet, some of them have padding between fields.
  10877. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  10878. {
  10879. int charid;
  10880. charid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  10881. map_reqnickdb(sd, charid);
  10882. }
  10883. /// /resetskill /resetstate (CZ_RESET).
  10884. /// Request to reset stats or skills.
  10885. /// 0197 <type>.W
  10886. /// type:
  10887. /// 0 = state
  10888. /// 1 = skill
  10889. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  10890. char cmd[15];
  10891. if( RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) )
  10892. safesnprintf(cmd,sizeof(cmd),"%cresetskill",atcommand_symbol);
  10893. else
  10894. safesnprintf(cmd,sizeof(cmd),"%cresetstat",atcommand_symbol);
  10895. is_atcommand(fd, sd, cmd, 1);
  10896. }
  10897. /// /lb /nlb (CZ_LOCALBROADCAST).
  10898. /// Request to broadcast a message on current map.
  10899. /// 019c <packet len>.W <text>.?B
  10900. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  10901. {
  10902. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10903. char command[CHAT_SIZE_MAX+16];
  10904. unsigned int len = RFIFOW(fd,info->pos[0])-4;
  10905. char* msg = RFIFOCP(fd,info->pos[1]);
  10906. // as the length varies depending on the command used, just block unreasonably long strings
  10907. mes_len_check(msg, len, CHAT_SIZE_MAX);
  10908. safesnprintf(command,sizeof(command),"%clkami %s", atcommand_symbol, msg);
  10909. is_atcommand(fd, sd, command, 1);
  10910. }
  10911. /// Request to move an item from inventory to storage.
  10912. /// 00f3 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE)
  10913. /// 0364 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_BODY_TO_STORE2)
  10914. /// There are various variants of this packet, some of them have padding between fields.
  10915. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  10916. {
  10917. int item_index, item_amount;
  10918. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10919. if (pc_istrading(sd))
  10920. return;
  10921. item_index = RFIFOW(fd,info->pos[0])-2;
  10922. item_amount = RFIFOL(fd,info->pos[1]);
  10923. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  10924. return;
  10925. if (sd->state.storage_flag == 1)
  10926. storage_storageadd(sd, &sd->storage, item_index, item_amount);
  10927. else
  10928. if (sd->state.storage_flag == 2)
  10929. storage_guild_storageadd(sd, item_index, item_amount);
  10930. else if (sd->state.storage_flag == 3)
  10931. storage_storageadd(sd, &sd->premiumStorage, item_index, item_amount);
  10932. }
  10933. /// Request to move an item from storage to inventory.
  10934. /// 00f5 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY)
  10935. /// 0365 <index>.W <amount>.L (CZ_MOVE_ITEM_FROM_STORE_TO_BODY2)
  10936. /// There are various variants of this packet, some of them have padding between fields.
  10937. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  10938. {
  10939. int item_index, item_amount;
  10940. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10941. item_index = RFIFOW(fd,info->pos[0])-1;
  10942. item_amount = RFIFOL(fd,info->pos[1]);
  10943. if (sd->state.storage_flag == 1)
  10944. storage_storageget(sd, &sd->storage, item_index, item_amount);
  10945. else if(sd->state.storage_flag == 2)
  10946. storage_guild_storageget(sd, item_index, item_amount);
  10947. else if(sd->state.storage_flag == 3)
  10948. storage_storageget(sd, &sd->premiumStorage, item_index, item_amount);
  10949. }
  10950. /// Request to move an item from cart to storage (CZ_MOVE_ITEM_FROM_CART_TO_STORE).
  10951. /// 0129 <index>.W <amount>.L
  10952. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd){
  10953. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10954. int idx = RFIFOW(fd,info->pos[0]) - 2;
  10955. int amount = RFIFOL(fd,info->pos[1]);
  10956. if( sd->state.vending )
  10957. return;
  10958. if (!pc_iscarton(sd))
  10959. return;
  10960. if (sd->state.storage_flag == 1)
  10961. storage_storageaddfromcart(sd, &sd->storage, idx, amount);
  10962. else if (sd->state.storage_flag == 2)
  10963. storage_guild_storageaddfromcart(sd, idx, amount);
  10964. else if (sd->state.storage_flag == 3)
  10965. storage_storageaddfromcart(sd, &sd->premiumStorage, idx, amount);
  10966. }
  10967. /// Request to move an item from storage to cart (CZ_MOVE_ITEM_FROM_STORE_TO_CART).
  10968. /// 0128 <index>.W <amount>.L
  10969. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd){
  10970. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  10971. int idx = RFIFOW(fd,info->pos[0]) - 1;
  10972. int amount = RFIFOL(fd,info->pos[1]);
  10973. if( sd->state.vending )
  10974. return;
  10975. if (!pc_iscarton(sd))
  10976. return;
  10977. if (sd->state.storage_flag == 1)
  10978. storage_storagegettocart(sd, &sd->storage, idx, amount);
  10979. else
  10980. if (sd->state.storage_flag == 2)
  10981. storage_guild_storagegettocart(sd, idx, amount);
  10982. else if (sd->state.storage_flag == 3)
  10983. storage_storagegettocart(sd, &sd->premiumStorage, idx, amount);
  10984. }
  10985. /// Request to close storage (CZ_CLOSE_STORE).
  10986. /// 00f7
  10987. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  10988. {
  10989. if( sd->state.storage_flag == 1 )
  10990. storage_storageclose(sd);
  10991. else
  10992. if( sd->state.storage_flag == 2 )
  10993. storage_guild_storageclose(sd);
  10994. else if( sd->state.storage_flag == 3 )
  10995. storage_premiumStorage_close(sd);
  10996. }
  10997. /// Displays kafra storage password dialog (ZC_REQ_STORE_PASSWORD).
  10998. /// 023a <info>.W
  10999. /// info:
  11000. /// 0 = password has not been set yet
  11001. /// 1 = storage is password-protected
  11002. /// 8 = too many wrong passwords
  11003. /// ? = ignored
  11004. /// NOTE: This packet is only available on certain non-kRO clients.
  11005. void clif_storagepassword(struct map_session_data* sd, short info)
  11006. {
  11007. int fd = sd->fd;
  11008. WFIFOHEAD(fd,packet_len(0x23a));
  11009. WFIFOW(fd,0) = 0x23a;
  11010. WFIFOW(fd,2) = info;
  11011. WFIFOSET(fd,packet_len(0x23a));
  11012. }
  11013. /// Answer to the kafra storage password dialog (CZ_ACK_STORE_PASSWORD).
  11014. /// 023b <type>.W <password>.16B <new password>.16B
  11015. /// type:
  11016. /// 2 = change password
  11017. /// 3 = check password
  11018. /// NOTE: This packet is only available on certain non-kRO clients.
  11019. void clif_parse_StoragePassword(int fd, struct map_session_data *sd){ //@TODO
  11020. // struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11021. // int type = RFIFOW(fd,info->pos[0]);
  11022. // char* password = RFIFOP(fd,info->pos[1]);
  11023. // char* new_password = RFIFOP(fd,info->pos[2]);
  11024. // storage_changepass(sd,password,new_password);
  11025. }
  11026. /// Result of kafra storage password validation (ZC_RESULT_STORE_PASSWORD).
  11027. /// 023c <result>.W <error count>.W
  11028. /// result:
  11029. /// 4 = password change success
  11030. /// 5 = password change failure
  11031. /// 6 = password check success
  11032. /// 7 = password check failure
  11033. /// 8 = too many wrong passwords
  11034. /// ? = ignored
  11035. /// NOTE: This packet is only available on certain non-kRO clients.
  11036. void clif_storagepassword_result(struct map_session_data* sd, short result, short error_count)
  11037. {
  11038. int fd = sd->fd;
  11039. WFIFOHEAD(fd,packet_len(0x23c));
  11040. WFIFOW(fd,0) = 0x23c;
  11041. WFIFOW(fd,2) = result;
  11042. WFIFOW(fd,4) = error_count;
  11043. WFIFOSET(fd,packet_len(0x23c));
  11044. }
  11045. /// Party creation request
  11046. /// 00f9 <party name>.24B (CZ_MAKE_GROUP)
  11047. void clif_parse_CreateParty(int fd, struct map_session_data *sd){
  11048. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11049. name[NAME_LENGTH-1] = '\0';
  11050. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  11051. clif_displaymessage(fd, msg_txt(sd,227));
  11052. return;
  11053. }
  11054. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11055. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11056. return;
  11057. }
  11058. party_create(sd,name,0,0);
  11059. }
  11060. /// 01e8 <party name>.24B <item pickup rule>.B <item share rule>.B (CZ_MAKE_GROUP2)
  11061. void clif_parse_CreateParty2(int fd, struct map_session_data *sd){
  11062. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11063. char* name = RFIFOCP(fd,info->pos[0]);
  11064. int item1 = RFIFOB(fd,info->pos[1]);
  11065. int item2 = RFIFOB(fd,info->pos[2]);
  11066. name[NAME_LENGTH-1] = '\0';
  11067. if( map[sd->bl.m].flag.partylock ) {// Party locked.
  11068. clif_displaymessage(fd, msg_txt(sd,227));
  11069. return;
  11070. }
  11071. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 && pc_checkskill(sd, SU_BASIC_SKILL) < 1 ) {
  11072. clif_skill_fail(sd,1,USESKILL_FAIL_LEVEL,4);
  11073. return;
  11074. }
  11075. party_create(sd,name,item1,item2);
  11076. }
  11077. /// Party invitation request
  11078. /// 00fc <account id>.L (CZ_REQ_JOIN_GROUP)
  11079. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  11080. {
  11081. struct map_session_data *t_sd;
  11082. if(map[sd->bl.m].flag.partylock) {// Party locked.
  11083. clif_displaymessage(fd, msg_txt(sd,227));
  11084. return;
  11085. }
  11086. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11087. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11088. clif_noask_sub(sd, t_sd, 1);
  11089. return;
  11090. }
  11091. party_invite(sd, t_sd);
  11092. }
  11093. /// 02c4 <char name>.24B (CZ_PARTY_JOIN_REQ)
  11094. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd){
  11095. struct map_session_data *t_sd;
  11096. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11097. name[NAME_LENGTH-1] = '\0';
  11098. if(map[sd->bl.m].flag.partylock) {// Party locked.
  11099. clif_displaymessage(fd, msg_txt(sd,227));
  11100. return;
  11101. }
  11102. t_sd = map_nick2sd(name,false);
  11103. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11104. clif_noask_sub(sd, t_sd, 1);
  11105. return;
  11106. }
  11107. party_invite(sd, t_sd);
  11108. }
  11109. /// Party invitation reply
  11110. /// 00ff <party id>.L <flag>.L (CZ_JOIN_GROUP)
  11111. /// 02c7 <party id>.L <flag>.B (CZ_PARTY_JOIN_REQ_ACK)
  11112. /// flag:
  11113. /// 0 = reject
  11114. /// 1 = accept
  11115. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  11116. {
  11117. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11118. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11119. RFIFOL(fd,info->pos[1]));
  11120. }
  11121. //(CZ_PARTY_JOIN_REQ_ACK)
  11122. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  11123. {
  11124. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11125. party_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11126. RFIFOB(fd,info->pos[1]));
  11127. }
  11128. /// Request to leave party (CZ_REQ_LEAVE_GROUP).
  11129. /// 0100
  11130. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  11131. {
  11132. if(map[sd->bl.m].flag.partylock) {// Party locked.
  11133. clif_displaymessage(fd, msg_txt(sd,227));
  11134. return;
  11135. }
  11136. party_leave(sd);
  11137. }
  11138. /// Request to expel a party member (CZ_REQ_EXPEL_GROUP_MEMBER).
  11139. /// 0103 <account id>.L <char name>.24B
  11140. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  11141. {
  11142. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11143. if(map[sd->bl.m].flag.partylock) {// Party locked.
  11144. clif_displaymessage(fd, msg_txt(sd,227));
  11145. return;
  11146. }
  11147. party_removemember(sd,RFIFOL(fd,info->pos[0]),
  11148. RFIFOCP(fd,info->pos[1]));
  11149. }
  11150. /// Request to change party options.
  11151. /// 0102 <exp share rule>.L (CZ_CHANGE_GROUPEXPOPTION)
  11152. /// 07d7 <exp share rule>.L <item pickup rule>.B <item share rule>.B (CZ_GROUPINFO_CHANGE_V2)
  11153. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  11154. {
  11155. struct party_data *p;
  11156. int i,expflag;
  11157. int cmd = RFIFOW(fd,0);
  11158. struct s_packet_db* info = &packet_db[cmd];
  11159. if( !sd->status.party_id )
  11160. return;
  11161. p = party_search(sd->status.party_id);
  11162. if( p == NULL )
  11163. return;
  11164. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  11165. if( i == MAX_PARTY )
  11166. return; //Shouldn't happen
  11167. if( !p->party.member[i].leader )
  11168. return;
  11169. expflag = RFIFOL(fd,info->pos[0]);
  11170. if(cmd == 0x0102){ //Client can't change the item-field
  11171. party_changeoption(sd, expflag, p->party.item);
  11172. }
  11173. else {
  11174. int itemflag = (RFIFOB(fd,info->pos[1])?1:0)|(RFIFOB(fd,info->pos[2])?2:0);
  11175. party_changeoption(sd, expflag, itemflag);
  11176. }
  11177. }
  11178. /// Validates and processes party messages (CZ_REQUEST_CHAT_PARTY).
  11179. /// 0108 <packet len>.W <text>.?B (<name> : <message>) 00
  11180. void clif_parse_PartyMessage(int fd, struct map_session_data* sd){
  11181. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11182. // validate packet and retrieve name and message
  11183. if( !clif_process_message( sd, false, name, message, output ) )
  11184. return;
  11185. party_send_message(sd, output, strlen(output) + 1 );
  11186. }
  11187. /// Changes Party Leader (CZ_CHANGE_GROUP_MASTER).
  11188. /// 07da <account id>.L
  11189. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd){
  11190. party_changeleader(sd, map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0])),NULL);
  11191. }
  11192. /// Party Booking in KRO [Spiria]
  11193. ///
  11194. /// Request to register a party booking advertisment (CZ_PARTY_BOOKING_REQ_REGISTER).
  11195. /// 0802 <level>.W <map id>.W { <job>.W }*6
  11196. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd){
  11197. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11198. short level = RFIFOW(fd,info->pos[0]);
  11199. short mapid = RFIFOW(fd,info->pos[1]);
  11200. int idxpbj = info->pos[2];
  11201. short job[MAX_PARTY_BOOKING_JOBS];
  11202. int i;
  11203. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11204. job[i] = RFIFOB(fd,idxpbj+i*2);
  11205. party_booking_register(sd, level, mapid, job);
  11206. }
  11207. /// Result of request to register a party booking advertisment (ZC_PARTY_BOOKING_ACK_REGISTER).
  11208. /// 0803 <result>.W
  11209. /// result:
  11210. /// 0 = success
  11211. /// 1 = failure
  11212. /// 2 = already registered
  11213. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  11214. {
  11215. int fd = sd->fd;
  11216. WFIFOHEAD(fd,packet_len(0x803));
  11217. WFIFOW(fd,0) = 0x803;
  11218. WFIFOW(fd,2) = flag;
  11219. WFIFOSET(fd,packet_len(0x803));
  11220. }
  11221. /// Request to search for party booking advertisments (CZ_PARTY_BOOKING_REQ_SEARCH).
  11222. /// 0804 <level>.W <map id>.W <job>.W <last index>.L <result count>.W
  11223. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd){
  11224. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11225. short level = RFIFOW(fd,info->pos[0]);
  11226. short mapid = RFIFOW(fd,info->pos[1]);
  11227. short job = RFIFOW(fd,info->pos[2]);
  11228. unsigned long lastindex = RFIFOL(fd,info->pos[3]);
  11229. short resultcount = RFIFOW(fd,info->pos[4]);
  11230. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  11231. }
  11232. /// Party booking search results (ZC_PARTY_BOOKING_ACK_SEARCH).
  11233. /// 0805 <packet len>.W <more results>.B { <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6 }*
  11234. /// more results:
  11235. /// 0 = no
  11236. /// 1 = yes
  11237. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  11238. {
  11239. int i, j;
  11240. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  11241. struct party_booking_ad_info *pb_ad;
  11242. WFIFOHEAD(fd,size*count + 5);
  11243. WFIFOW(fd,0) = 0x805;
  11244. WFIFOW(fd,2) = size*count + 5;
  11245. WFIFOB(fd,4) = more_result;
  11246. for(i=0; i<count; i++)
  11247. {
  11248. pb_ad = results[i];
  11249. WFIFOL(fd,i*size+5) = pb_ad->index;
  11250. safestrncpy(WFIFOCP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  11251. WFIFOL(fd,i*size+33) = pb_ad->starttime; // FIXME: This is expire time
  11252. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  11253. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  11254. for(j=0; j<MAX_PARTY_BOOKING_JOBS; j++)
  11255. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  11256. }
  11257. WFIFOSET(fd,WFIFOW(fd,2));
  11258. }
  11259. /// Request to delete own party booking advertisment (CZ_PARTY_BOOKING_REQ_DELETE).
  11260. /// 0806
  11261. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  11262. {
  11263. if(party_booking_delete(sd))
  11264. clif_PartyBookingDeleteAck(sd, 0);
  11265. }
  11266. /// Result of request to delete own party booking advertisment (ZC_PARTY_BOOKING_ACK_DELETE).
  11267. /// 0807 <result>.W
  11268. /// result:
  11269. /// 0 = success
  11270. /// 1 = success (auto-removed expired ad)
  11271. /// 2 = failure
  11272. /// 3 = nothing registered
  11273. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  11274. {
  11275. int fd = sd->fd;
  11276. WFIFOHEAD(fd,packet_len(0x807));
  11277. WFIFOW(fd,0) = 0x807;
  11278. WFIFOW(fd,2) = flag;
  11279. WFIFOSET(fd,packet_len(0x807));
  11280. }
  11281. /// Request to update party booking advertisment (CZ_PARTY_BOOKING_REQ_UPDATE).
  11282. /// 0808 { <job>.W }*6
  11283. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  11284. {
  11285. short job[MAX_PARTY_BOOKING_JOBS];
  11286. int i;
  11287. int idxpbu = packet_db[RFIFOW(fd,0)].pos[0];
  11288. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11289. job[i] = RFIFOW(fd,idxpbu+i*2);
  11290. party_booking_update(sd, job);
  11291. }
  11292. /// Notification about new party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_INSERT).
  11293. /// 0809 <index>.L <char name>.24B <expire time>.L <level>.W <map id>.W { <job>.W }*6
  11294. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11295. {
  11296. int i;
  11297. uint8 buf[38+MAX_PARTY_BOOKING_JOBS*2];
  11298. if(pb_ad == NULL) return;
  11299. WBUFW(buf,0) = 0x809;
  11300. WBUFL(buf,2) = pb_ad->index;
  11301. safestrncpy(WBUFCP(buf,6),pb_ad->charname,NAME_LENGTH);
  11302. WBUFL(buf,30) = pb_ad->starttime; // FIXME: This is expire time
  11303. WBUFW(buf,34) = pb_ad->p_detail.level;
  11304. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  11305. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11306. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  11307. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  11308. }
  11309. /// Notification about updated party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_UPDATE).
  11310. /// 080a <index>.L { <job>.W }*6
  11311. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  11312. {
  11313. int i;
  11314. uint8 buf[6+MAX_PARTY_BOOKING_JOBS*2];
  11315. if(pb_ad == NULL) return;
  11316. WBUFW(buf,0) = 0x80a;
  11317. WBUFL(buf,2) = pb_ad->index;
  11318. for(i=0; i<MAX_PARTY_BOOKING_JOBS; i++)
  11319. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  11320. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  11321. }
  11322. /// Notification about deleted party booking advertisment (ZC_PARTY_BOOKING_NOTIFY_DELETE).
  11323. /// 080b <index>.L
  11324. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  11325. {
  11326. uint8 buf[6];
  11327. WBUFW(buf,0) = 0x80b;
  11328. WBUFL(buf,2) = index;
  11329. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  11330. }
  11331. /// Request to close own vending (CZ_REQ_CLOSESTORE).
  11332. /// 012e
  11333. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  11334. {
  11335. vending_closevending(sd);
  11336. }
  11337. /// Request to open a vending shop (CZ_REQ_BUY_FROMMC).
  11338. /// 0130 <account id>.L
  11339. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  11340. {
  11341. if( sd->npc_id ) {// using an NPC
  11342. return;
  11343. }
  11344. vending_vendinglistreq(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11345. }
  11346. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC).
  11347. /// 0134 <packet len>.W <account id>.L { <amount>.W <index>.W }*
  11348. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd){
  11349. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11350. int len = (int)RFIFOW(fd,info->pos[0]) - 8;
  11351. int id = (int)RFIFOL(fd,info->pos[1]);
  11352. const uint8* data = (uint8*)RFIFOP(fd,info->pos[2]);
  11353. vending_purchasereq(sd, id, sd->vended_id, data, len/4);
  11354. // whether it fails or not, the buy window is closed
  11355. sd->vended_id = 0;
  11356. }
  11357. /// Shop item(s) purchase request (CZ_PC_PURCHASE_ITEMLIST_FROMMC2).
  11358. /// 0801 <packet len>.W <account id>.L <unique id>.L { <amount>.W <index>.W }*
  11359. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd){
  11360. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11361. int len = (int)RFIFOW(fd,info->pos[0]) - 12;
  11362. int aid = (int)RFIFOL(fd,info->pos[1]);
  11363. int uid = (int)RFIFOL(fd,info->pos[2]);
  11364. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11365. vending_purchasereq(sd, aid, uid, data, len/4);
  11366. // whether it fails or not, the buy window is closed
  11367. sd->vended_id = 0;
  11368. }
  11369. /// Confirm or cancel the shop preparation window.
  11370. /// 012f <packet len>.W <shop name>.80B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE)
  11371. /// 01b2 <packet len>.W <shop name>.80B <result>.B { <index>.W <amount>.W <price>.L }* (CZ_REQ_OPENSTORE2)
  11372. /// result:
  11373. /// 0 = canceled
  11374. /// 1 = open
  11375. void clif_parse_OpenVending(int fd, struct map_session_data* sd){
  11376. int cmd = RFIFOW(fd,0);
  11377. struct s_packet_db* info = &packet_db[cmd];
  11378. short len = (short)RFIFOW(fd,info->pos[0]);
  11379. const char* message = RFIFOCP(fd,info->pos[1]);
  11380. const uint8* data = (uint8*)RFIFOP(fd,info->pos[3]);
  11381. if(cmd == 0x12f){ // (CZ_REQ_OPENSTORE)
  11382. len -= 84;
  11383. }
  11384. else { //(CZ_REQ_OPENSTORE2)
  11385. bool flag;
  11386. len -= 85;
  11387. flag = RFIFOB(fd,info->pos[2]) != 0;
  11388. if (!flag) {
  11389. sd->state.prevend = 0;
  11390. sd->state.workinprogress = WIP_DISABLE_NONE;
  11391. }
  11392. }
  11393. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  11394. return;
  11395. if( map[sd->bl.m].flag.novending ) {
  11396. clif_displaymessage (sd->fd, msg_txt(sd,276)); // "You can't open a shop on this map"
  11397. return;
  11398. }
  11399. if( map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  11400. clif_displaymessage (sd->fd, msg_txt(sd,204)); // "You can't open a shop on this cell."
  11401. return;
  11402. }
  11403. if( message[0] == '\0' ) // invalid input
  11404. return;
  11405. vending_openvending(sd, message, data, len/8, NULL);
  11406. }
  11407. /// Guild creation request (CZ_REQ_MAKE_GUILD).
  11408. /// 0165 <char id>.L <guild name>.24B
  11409. void clif_parse_CreateGuild(int fd,struct map_session_data *sd){
  11410. //int charid = RFIFOL(fd,packet_db[cmd].pos[0]);
  11411. char* name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11412. name[NAME_LENGTH-1] = '\0';
  11413. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11414. clif_displaymessage(fd, msg_txt(sd,228));
  11415. return;
  11416. }
  11417. if(sd->clan){
  11418. // Should display a clientside message "You are currently joined in Clan !!" so we ignore it
  11419. return;
  11420. }
  11421. guild_create(sd, name);
  11422. }
  11423. /// Request for guild window interface permissions (CZ_REQ_GUILD_MENUINTERFACE).
  11424. /// 014d
  11425. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  11426. {
  11427. clif_guild_masterormember(sd);
  11428. }
  11429. /// Request for guild window information (CZ_REQ_GUILD_MENU).
  11430. /// 014f <type>.L
  11431. /// type:
  11432. /// 0 = basic info
  11433. /// 1 = member manager
  11434. /// 2 = positions
  11435. /// 3 = skills
  11436. /// 4 = expulsion list
  11437. /// 5 = unknown (GM_ALLGUILDLIST)
  11438. /// 6 = notice
  11439. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  11440. {
  11441. int type = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11442. if( !sd->status.guild_id && !sd->bg_id )
  11443. return;
  11444. switch( type )
  11445. {
  11446. case 0: // Basic Information Guild, hostile alliance information
  11447. clif_guild_basicinfo(sd);
  11448. clif_guild_allianceinfo(sd);
  11449. break;
  11450. case 1: // Members list, list job title
  11451. clif_guild_positionnamelist(sd);
  11452. clif_guild_memberlist(sd);
  11453. break;
  11454. case 2: // List job title, title information list
  11455. clif_guild_positionnamelist(sd);
  11456. clif_guild_positioninfolist(sd);
  11457. break;
  11458. case 3: // Skill list
  11459. clif_guild_skillinfo(sd);
  11460. break;
  11461. case 4: // Expulsion list
  11462. clif_guild_expulsionlist(sd);
  11463. break;
  11464. default:
  11465. ShowError("clif: guild request info: unknown type %d\n", type);
  11466. break;
  11467. }
  11468. }
  11469. /// Request to update guild positions (CZ_REG_CHANGE_GUILD_POSITIONINFO).
  11470. /// 0161 <packet len>.W { <position id>.L <mode>.L <ranking>.L <pay rate>.L <name>.24B }*
  11471. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  11472. {
  11473. int i;
  11474. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11475. int len = RFIFOW(fd,info->pos[0]);
  11476. int idxgpos = info->pos[1];
  11477. if(!sd->state.gmaster_flag)
  11478. return;
  11479. for(i = idxgpos; i < len; i += 40 ){
  11480. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), RFIFOCP(fd,i+16));
  11481. }
  11482. }
  11483. /// Request to update the position of guild members (CZ_REQ_CHANGE_MEMBERPOS).
  11484. /// 0155 <packet len>.W { <account id>.L <char id>.L <position id>.L }*
  11485. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  11486. {
  11487. int i;
  11488. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11489. int len = RFIFOW(fd,info->pos[0]);
  11490. int idxgpos = info->pos[1];
  11491. if(!sd->state.gmaster_flag)
  11492. return;
  11493. // Guild leadership change
  11494. if( len == 16 && RFIFOL(fd,12) == 0 ){
  11495. if( !battle_config.guild_leaderchange_woe && is_agit_start() ){
  11496. clif_msg(sd, GUILD_MASTER_WOE);
  11497. return;
  11498. }
  11499. if( battle_config.guild_leaderchange_delay && DIFF_TICK(time(NULL),sd->guild->last_leader_change) < battle_config.guild_leaderchange_delay ){
  11500. clif_msg(sd, GUILD_MASTER_DELAY);
  11501. return;
  11502. }
  11503. guild_gm_change(sd->status.guild_id, RFIFOL(fd, 8));
  11504. return;
  11505. }
  11506. for(i=idxgpos;i<len;i+=12){
  11507. int position = RFIFOL(fd,i+8);
  11508. if( position > 0 ){
  11509. guild_change_memberposition(sd->status.guild_id,RFIFOL(fd,i),RFIFOL(fd,i+4),position);
  11510. }
  11511. }
  11512. }
  11513. /// Request for guild emblem data (CZ_REQ_GUILD_EMBLEM_IMG).
  11514. /// 0151 <guild id>.L
  11515. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  11516. {
  11517. struct guild* g;
  11518. int guild_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11519. if( (g = guild_search(guild_id)) != NULL )
  11520. clif_guild_emblem(sd,g);
  11521. }
  11522. /// Validates data of a guild emblem (compressed bitmap)
  11523. enum e_result_validate_emblem { // Used as Result for clif_validate_emblem
  11524. EMBVALIDATE_SUCCESS = 0,
  11525. EMBVALIDATE_ERR_RAW_FILEFORMAT, // Invalid File Format (Error in zlib/decompression or malformed BMP header)
  11526. EMBVALIDATE_ERR_TRANSPARENCY // uploaded emblem does not met the requirements of battle_config.emblem_transparency_limit
  11527. };
  11528. static enum e_result_validate_emblem clif_validate_emblem(const uint8* emblem, unsigned long emblem_len)
  11529. {
  11530. uint8 buf[1800]; // no well-formed emblem bitmap is larger than 1782 (24 bit) / 1654 (8 bit) bytes
  11531. unsigned long buf_len = sizeof(buf);
  11532. int offset = 0;
  11533. if(!(( decode_zip(buf, &buf_len, emblem, emblem_len) == 0 && buf_len >= 18 ) // sizeof(BITMAPFILEHEADER) + sizeof(biSize) of the following info header struct
  11534. && RBUFW(buf,0) == 0x4d42 // BITMAPFILEHEADER.bfType (signature)
  11535. && RBUFL(buf,2) == buf_len // BITMAPFILEHEADER.bfSize (file size)
  11536. && (offset = RBUFL(buf,10)) < buf_len // BITMAPFILEHEADER.bfOffBits (offset to bitmap bits)
  11537. ))
  11538. return EMBVALIDATE_ERR_RAW_FILEFORMAT;
  11539. if(battle_config.emblem_transparency_limit != 100) {
  11540. int i, transcount = 1, tmp[3];
  11541. for(i = offset; i < buf_len-1; i++) {
  11542. int j = i%3;
  11543. tmp[j] = RBUFL(buf,i);
  11544. if(j == 2 && (tmp[0] == 0xFFFF00FF) && (tmp[1] == 0xFFFF00) && (tmp[2] == 0xFF00FFFF)) //if pixel is transparent
  11545. transcount++;
  11546. }
  11547. if(((transcount*300)/(buf_len-offset)) > battle_config.emblem_transparency_limit) //convert in % to chk
  11548. return EMBVALIDATE_ERR_TRANSPARENCY;
  11549. }
  11550. return EMBVALIDATE_SUCCESS;
  11551. }
  11552. /// Request to update the guild emblem (CZ_REGISTER_GUILD_EMBLEM_IMG).
  11553. /// 0153 <packet len>.W <emblem data>.?B
  11554. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd){
  11555. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11556. unsigned long emblem_len = RFIFOW(fd,info->pos[0])-4;
  11557. const uint8* emblem = RFIFOP(fd,info->pos[1]);
  11558. int emb_val=0;
  11559. if( !emblem_len || !sd->state.gmaster_flag )
  11560. return;
  11561. if(!(battle_config.emblem_woe_change) && is_agit_start() ){
  11562. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,385),false,SELF); //"You not allowed to change emblem during woe"
  11563. return;
  11564. }
  11565. emb_val = clif_validate_emblem(emblem, emblem_len);
  11566. if(emb_val == EMBVALIDATE_ERR_RAW_FILEFORMAT){
  11567. 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);
  11568. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,386),false,SELF); //"The chosen emblem was detected invalid\n"
  11569. return;
  11570. } else if(emb_val == EMBVALIDATE_ERR_TRANSPARENCY){
  11571. char output[128];
  11572. safesnprintf(output,sizeof(output),msg_txt(sd,387),battle_config.emblem_transparency_limit);
  11573. 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"
  11574. return;
  11575. }
  11576. guild_change_emblem(sd, emblem_len, (const char*)emblem);
  11577. }
  11578. /// Guild notice update request (CZ_GUILD_NOTICE).
  11579. /// 016e <guild id>.L <msg1>.60B <msg2>.120B
  11580. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd){
  11581. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11582. int guild_id = RFIFOL(fd,info->pos[0]);
  11583. char* msg1 = RFIFOCP(fd,info->pos[1]);
  11584. char* msg2 = RFIFOCP(fd,info->pos[2]);
  11585. if(!sd->state.gmaster_flag)
  11586. return;
  11587. // compensate for some client defects when using multilanguage mode
  11588. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  11589. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  11590. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  11591. guild_change_notice(sd, guild_id, msg1, msg2);
  11592. }
  11593. // Helper function for guild invite functions
  11594. int clif_sub_guild_invite(int fd, struct map_session_data *sd, struct map_session_data *t_sd)
  11595. {
  11596. if (t_sd == NULL) // not online or does not exist
  11597. return 1;
  11598. if (map[sd->bl.m].flag.guildlock) {//Guild locked.
  11599. clif_displaymessage(fd, msg_txt(sd,228));
  11600. return 1;
  11601. }
  11602. if(t_sd && t_sd->state.noask) {// @noask [LuzZza]
  11603. clif_noask_sub(sd, t_sd, 2);
  11604. return 1;
  11605. }
  11606. // Players in a clan can not join a guild
  11607. if(t_sd && t_sd->clan){
  11608. return 1;
  11609. }
  11610. guild_invite(sd, t_sd);
  11611. return 0;
  11612. }
  11613. /// Guild invite request (CZ_REQ_JOIN_GUILD).
  11614. /// 0168 <account id>.L <inviter account id>.L <inviter char id>.L
  11615. void clif_parse_GuildInvite(int fd,struct map_session_data *sd){
  11616. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11617. struct map_session_data *t_sd = map_id2sd(RFIFOL(fd,info->pos[0]));
  11618. // int inv_aid = RFIFOL(fd,info->pos[1]);
  11619. // int inv_cid = RFIFOL(fd,info->pos[2]);
  11620. if (clif_sub_guild_invite(fd, sd, t_sd))
  11621. return;
  11622. }
  11623. /// Guild invite request (/guildinvite)
  11624. /// 0916 <char name>.24B (CZ_REQ_JOIN_GUILD2)
  11625. void
  11626. clif_parse_GuildInvite2(int fd, struct map_session_data *sd) {
  11627. struct map_session_data *t_sd = map_nick2sd(RFIFOCP(fd, packet_db[RFIFOW(fd,0)].pos[0]),false);
  11628. if (clif_sub_guild_invite(fd, sd, t_sd))
  11629. return;
  11630. }
  11631. /// Answer to guild invitation (CZ_JOIN_GUILD).
  11632. /// 016b <guild id>.L <answer>.L
  11633. /// answer:
  11634. /// 0 = refuse
  11635. /// 1 = accept
  11636. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd){
  11637. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11638. guild_reply_invite(sd,RFIFOL(fd,info->pos[0]),
  11639. RFIFOL(fd,info->pos[1]));
  11640. }
  11641. /// Request to leave guild (CZ_REQ_LEAVE_GUILD).
  11642. /// 0159 <guild id>.L <account id>.L <char id>.L <reason>.40B
  11643. void clif_parse_GuildLeave(int fd,struct map_session_data *sd){
  11644. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11645. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11646. clif_displaymessage(fd, msg_txt(sd,228));
  11647. return;
  11648. }
  11649. if( sd->bg_id ) {
  11650. clif_displaymessage(fd, msg_txt(sd,670)); //"You can't leave battleground guilds."
  11651. return;
  11652. }
  11653. guild_leave(sd,RFIFOL(fd,info->pos[0]),
  11654. RFIFOL(fd,info->pos[1]),
  11655. RFIFOL(fd,info->pos[2]),
  11656. RFIFOCP(fd,info->pos[3]));
  11657. }
  11658. /// Request to expel a member of a guild (CZ_REQ_BAN_GUILD).
  11659. /// 015b <guild id>.L <account id>.L <char id>.L <reason>.40B
  11660. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd){
  11661. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11662. if( map[sd->bl.m].flag.guildlock || sd->bg_id )
  11663. { // Guild locked.
  11664. clif_displaymessage(fd, msg_txt(sd,228));
  11665. return;
  11666. }
  11667. guild_expulsion(sd,RFIFOL(fd,info->pos[0]),
  11668. RFIFOL(fd,info->pos[1]),
  11669. RFIFOL(fd,info->pos[2]),
  11670. RFIFOCP(fd,info->pos[3]));
  11671. }
  11672. /// Validates and processes guild messages (CZ_GUILD_CHAT).
  11673. /// 017e <packet len>.W <text>.?B (<name> : <message>) 00
  11674. void clif_parse_GuildMessage(int fd, struct map_session_data* sd){
  11675. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  11676. // validate packet and retrieve name and message
  11677. if( !clif_process_message( sd, false, name, message, output ) )
  11678. return;
  11679. if( sd->bg_id )
  11680. bg_send_message(sd, output, strlen(output) );
  11681. else
  11682. guild_send_message(sd, output, strlen(output) );
  11683. }
  11684. /// Guild alliance request (CZ_REQ_ALLY_GUILD).
  11685. /// 0170 <account id>.L <inviter account id>.L <inviter char id>.L
  11686. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  11687. {
  11688. struct map_session_data *t_sd;
  11689. if(!sd->state.gmaster_flag)
  11690. return;
  11691. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11692. clif_displaymessage(fd, msg_txt(sd,228));
  11693. return;
  11694. }
  11695. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11696. //inv_aid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  11697. //inv_cid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[2]);
  11698. // @noask [LuzZza]
  11699. if(t_sd && t_sd->state.noask) {
  11700. clif_noask_sub(sd, t_sd, 3);
  11701. return;
  11702. }
  11703. guild_reqalliance(sd,t_sd);
  11704. }
  11705. /// Answer to a guild alliance request (CZ_ALLY_GUILD).
  11706. /// 0172 <inviter account id>.L <answer>.L
  11707. /// answer:
  11708. /// 0 = refuse
  11709. /// 1 = accept
  11710. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd){
  11711. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11712. guild_reply_reqalliance(sd,
  11713. RFIFOL(fd,info->pos[0]),
  11714. RFIFOL(fd,info->pos[1]));
  11715. }
  11716. /// Request to delete a guild alliance or opposition (CZ_REQ_DELETE_RELATED_GUILD).
  11717. /// 0183 <opponent guild id>.L <relation>.L
  11718. /// relation:
  11719. /// 0 = Ally
  11720. /// 1 = Enemy
  11721. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd){
  11722. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11723. if(!sd->state.gmaster_flag)
  11724. return;
  11725. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11726. clif_displaymessage(fd, msg_txt(sd,228));
  11727. return;
  11728. }
  11729. guild_delalliance(sd,
  11730. RFIFOL(fd,info->pos[0]),
  11731. RFIFOL(fd,info->pos[1]));
  11732. }
  11733. /// Request to set a guild as opposition (CZ_REQ_HOSTILE_GUILD).
  11734. /// 0180 <account id>.L
  11735. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  11736. {
  11737. struct map_session_data *t_sd;
  11738. if(!sd->state.gmaster_flag)
  11739. return;
  11740. if(map[sd->bl.m].flag.guildlock) { //Guild locked.
  11741. clif_displaymessage(fd, msg_txt(sd,228));
  11742. return;
  11743. }
  11744. t_sd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11745. // @noask [LuzZza]
  11746. if(t_sd && t_sd->state.noask) {
  11747. clif_noask_sub(sd, t_sd, 4);
  11748. return;
  11749. }
  11750. guild_opposition(sd,t_sd);
  11751. }
  11752. /// Request to delete own guild (CZ_REQ_DISORGANIZE_GUILD).
  11753. /// 015d <key>.40B
  11754. /// key:
  11755. /// now guild name; might have been (intended) email, since the
  11756. /// field name and size is same as the one in CH_DELETE_CHAR.
  11757. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  11758. {
  11759. if( map[sd->bl.m].flag.guildlock ) { //Guild locked.
  11760. clif_displaymessage(fd, msg_txt(sd,228));
  11761. return;
  11762. }
  11763. guild_break(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11764. }
  11765. /// Pet
  11766. ///
  11767. /// Request to invoke a pet menu action (CZ_COMMAND_PET).
  11768. /// 01a1 <type>.B
  11769. /// type:
  11770. /// 0 = pet information
  11771. /// 1 = feed
  11772. /// 2 = performance
  11773. /// 3 = return to egg
  11774. /// 4 = unequip accessory
  11775. void clif_parse_PetMenu(int fd, struct map_session_data *sd){
  11776. pet_menu(sd,RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11777. }
  11778. /// Attempt to tame a monster (CZ_TRYCAPTURE_MONSTER).
  11779. /// 019f <id>.L
  11780. void clif_parse_CatchPet(int fd, struct map_session_data *sd){
  11781. pet_catch_process2(sd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11782. }
  11783. /// Answer to pet incubator egg selection dialog (CZ_SELECT_PETEGG).
  11784. /// 01a7 <index>.W
  11785. void clif_parse_SelectEgg(int fd, struct map_session_data *sd){
  11786. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  11787. return;
  11788. pet_select_egg(sd,RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2);
  11789. clif_menuskill_clear(sd);
  11790. }
  11791. /// Request to display pet's emotion/talk (CZ_PET_ACT).
  11792. /// 01a9 <data>.L
  11793. /// data:
  11794. /// is either emotion (@see enum emotion_type) or a compound value
  11795. /// (((mob id)-100)*100+(act id)*10+(hunger)) that describes an
  11796. /// entry (given in parentheses) in data\pettalktable.xml
  11797. /// act id:
  11798. /// 0 = feeding
  11799. /// 1 = hunting
  11800. /// 2 = danger
  11801. /// 3 = dead
  11802. /// 4 = normal (stand)
  11803. /// 5 = special performance (perfor_s)
  11804. /// 6 = level up (levelup)
  11805. /// 7 = performance 1 (perfor_1)
  11806. /// 8 = performance 2 (perfor_2)
  11807. /// 9 = performance 3 (perfor_3)
  11808. /// 10 = log-in greeting (connect)
  11809. /// hungry value:
  11810. /// 0 = very hungry (hungry)
  11811. /// 1 = hungry (bit_hungry)
  11812. /// 2 = satisfied (noting)
  11813. /// 3 = stuffed (full)
  11814. /// 4 = full (so_full)
  11815. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  11816. {
  11817. if(sd->pd)
  11818. clif_pet_emotion(sd->pd,RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11819. }
  11820. /// Request to change pet's name (CZ_RENAME_PET).
  11821. /// 01a5 <name>.24B
  11822. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  11823. {
  11824. pet_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  11825. }
  11826. /// /kill (CZ_DISCONNECT_CHARACTER).
  11827. /// Request to disconnect a character.
  11828. /// 00cc <account id>.L
  11829. /// NOTE: Also sent when using GM right click menu "(name) force to quit"
  11830. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  11831. {
  11832. struct block_list *target;
  11833. int tid;
  11834. tid = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11835. target = map_id2bl(tid);
  11836. if (!target) {
  11837. clif_GM_kickack(sd, 0);
  11838. return;
  11839. }
  11840. switch (target->type) {
  11841. case BL_PC:
  11842. {
  11843. char command[NAME_LENGTH+6];
  11844. safesnprintf(command,sizeof(command),"%ckick %s", atcommand_symbol, status_get_name(target));
  11845. is_atcommand(fd, sd, command, 1);
  11846. }
  11847. break;
  11848. /**
  11849. * This one does not invoke any atcommand, so we need to check for permissions.
  11850. */
  11851. case BL_MOB:
  11852. {
  11853. char command[100];
  11854. if( !pc_can_use_command(sd, "killmonster", COMMAND_ATCOMMAND)) {
  11855. clif_GM_kickack(sd, 0);
  11856. return;
  11857. }
  11858. safesnprintf(command,sizeof(command),"/kick %s (%d)", status_get_name(target), status_get_class(target));
  11859. log_atcommand(sd, command);
  11860. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  11861. }
  11862. break;
  11863. case BL_NPC:
  11864. {
  11865. struct npc_data* nd = (struct npc_data *)target;
  11866. if( pc_can_use_command(sd, "unloadnpc", COMMAND_ATCOMMAND)) {
  11867. npc_unload_duplicates(nd);
  11868. npc_unload(nd,true);
  11869. npc_read_event_script();
  11870. }
  11871. }
  11872. break;
  11873. default:
  11874. clif_GM_kickack(sd, 0);
  11875. }
  11876. }
  11877. /// /killall (CZ_DISCONNECT_ALL_CHARACTER).
  11878. /// Request to disconnect all characters.
  11879. /// 00ce
  11880. void clif_parse_GMKickAll(int fd, struct map_session_data* sd) {
  11881. char cmd[15];
  11882. safesnprintf(cmd,sizeof(cmd),"%ckickall",atcommand_symbol);
  11883. is_atcommand(fd, sd, cmd, 1);
  11884. }
  11885. /// /remove (CZ_REMOVE_AID).
  11886. /// Request to warp to a character with given login ID.
  11887. /// 01ba <account name>.24B
  11888. /// /shift (CZ_SHIFT).
  11889. /// Request to warp to a character with given name.
  11890. /// 01bb <char name>.24B
  11891. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  11892. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  11893. char *player_name;
  11894. char command[NAME_LENGTH+8];
  11895. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11896. player_name[NAME_LENGTH-1] = '\0';
  11897. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, player_name);
  11898. is_atcommand(fd, sd, command, 1);
  11899. }
  11900. /// /remove (CZ_REMOVE_AID_SSO).
  11901. /// Request to warp to a character with given account ID.
  11902. /// 0843 <account id>.L
  11903. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  11904. {
  11905. uint32 account_id;
  11906. struct map_session_data* pl_sd;
  11907. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11908. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11909. char command[NAME_LENGTH+8];
  11910. safesnprintf(command,sizeof(command),"%cjumpto %s", atcommand_symbol, pl_sd->status.name);
  11911. is_atcommand(fd, sd, command, 1);
  11912. }
  11913. }
  11914. /// /recall (CZ_RECALL).
  11915. /// Request to summon a player with given login ID to own position.
  11916. /// 01bc <account name>.24B
  11917. /// /summon (CZ_RECALL_GID).
  11918. /// Request to summon a player with given name to own position.
  11919. /// 01bd <char name>.24B
  11920. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  11921. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  11922. char *player_name;
  11923. char command [NAME_LENGTH+8];
  11924. player_name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11925. player_name[NAME_LENGTH-1] = '\0';
  11926. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, player_name);
  11927. is_atcommand(fd, sd, command, 1);
  11928. }
  11929. /// /recall (CZ_RECALL_SSO).
  11930. /// Request to summon a player with given account ID to own position.
  11931. /// 0842 <account id>.L
  11932. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  11933. {
  11934. uint32 account_id;
  11935. struct map_session_data* pl_sd;
  11936. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  11937. if( (pl_sd = map_id2sd(account_id)) != NULL ) {
  11938. char command[NAME_LENGTH+8];
  11939. safesnprintf(command,sizeof(command),"%crecall %s", atcommand_symbol, pl_sd->status.name);
  11940. is_atcommand(fd, sd, command, 1);
  11941. }
  11942. }
  11943. /// /item /monster (CZ_ITEM_CREATE).
  11944. /// Request to execute GM commands.
  11945. /// Usage:
  11946. /// /item n - summon n monster or acquire n item/s
  11947. /// /item money - grants 2147483647 zenies
  11948. /// /item whereisboss - locate boss mob in current map.(not yet implemented)
  11949. /// /item regenboss_n t - regenerate n boss monster by t millisecond.(not yet implemented)
  11950. /// /item onekillmonster - toggle an ability to kill mobs in one hit.(not yet implemented)
  11951. /// /item bossinfo - display the information of a boss monster in current map.(not yet implemented)
  11952. /// /item cap_n - capture n monster as pet.(not yet implemented)
  11953. /// /item agitinvest - reset current global agit investments.(not yet implemented)
  11954. /// 013f <item/mob name>.24B
  11955. /// 09ce <item/mob name>.100B [Ind/Yommy]
  11956. void clif_parse_GM_Item_Monster(int fd, struct map_session_data *sd)
  11957. {
  11958. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  11959. int mob_id = 0;
  11960. struct item_data *id = NULL;
  11961. struct mob_db *mob = NULL;
  11962. StringBuf command;
  11963. char *str;
  11964. //#if PACKETVER >= 20131218
  11965. // char str[100];
  11966. //#else
  11967. // char str[24];
  11968. //#endif
  11969. str = RFIFOCP(fd,info->pos[0]);
  11970. if (!str || str[0] == '\0')
  11971. return;
  11972. if (strcmpi(str,"SPPOINT") == 0 || strcmpi(str,"JOBLEVEL") == 0) //! TODO /sp sends these values
  11973. return;
  11974. trim(str);
  11975. // Zeny
  11976. if( strcmpi(str, "money") == 0 ) {
  11977. StringBuf_Init(&command);
  11978. StringBuf_Printf(&command, "%czeny %d", atcommand_symbol, INT_MAX);
  11979. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11980. StringBuf_Destroy(&command);
  11981. return;
  11982. }
  11983. // Item
  11984. if( (id = itemdb_searchname(str)) ) {
  11985. StringBuf_Init(&command);
  11986. if( !itemdb_isstackable2(id) ) //Nonstackable
  11987. StringBuf_Printf(&command, "%citem2 %d 1 0 0 0 0 0 0 0", atcommand_symbol, id->nameid);
  11988. else {
  11989. if (id->flag.guid)
  11990. StringBuf_Printf(&command, "%citem %d 1", atcommand_symbol, id->nameid);
  11991. else
  11992. StringBuf_Printf(&command, "%citem %d 20", atcommand_symbol, id->nameid);
  11993. }
  11994. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  11995. StringBuf_Destroy(&command);
  11996. return;
  11997. }
  11998. // Monster
  11999. if ((mob_id = mobdb_searchname(str)) == 0)
  12000. mob_id = mobdb_checkid(atoi(str));
  12001. if( (mob = mob_db(mob_id)) ) {
  12002. StringBuf_Init(&command);
  12003. StringBuf_Printf(&command, "%cmonster %s", atcommand_symbol, mob->sprite);
  12004. is_atcommand(fd, sd, StringBuf_Value(&command), 1);
  12005. StringBuf_Destroy(&command);
  12006. return;
  12007. }
  12008. }
  12009. /// /hide (CZ_CHANGE_EFFECTSTATE).
  12010. /// 019d <effect state>.L
  12011. /// effect state:
  12012. /// TODO: Any OPTION_* ?
  12013. void clif_parse_GMHide(int fd, struct map_session_data *sd) {
  12014. char cmd[6];
  12015. //int eff_st = RFIFOL(packet_db[RFIFOW(fd,0)].pos[0]);
  12016. safesnprintf(cmd,sizeof(cmd),"%chide",atcommand_symbol);
  12017. is_atcommand(fd, sd, cmd, 1);
  12018. }
  12019. /// Request to adjust player's manner points (CZ_REQ_GIVE_MANNER_POINT).
  12020. /// 0149 <account id>.L <type>.B <value>.W
  12021. /// type:
  12022. /// 0 = positive points
  12023. /// 1 = negative points
  12024. /// 2 = self mute (+10 minutes)
  12025. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  12026. {
  12027. int id, type, value;
  12028. struct map_session_data *dstsd;
  12029. char command[NAME_LENGTH+15];
  12030. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12031. id = RFIFOL(fd,info->pos[0]);
  12032. type = RFIFOB(fd,info->pos[1]);
  12033. value = RFIFOW(fd,info->pos[2]);
  12034. if( type == 0 )
  12035. value = -value;
  12036. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  12037. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  12038. if (type == 2 /* && (pc_get_group_level(sd) > 0 || sd->bl.id != id)*/)
  12039. return;
  12040. dstsd = map_id2sd(id);
  12041. if( dstsd == NULL )
  12042. return;
  12043. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, value, dstsd->status.name);
  12044. is_atcommand(fd, sd, command, 1);
  12045. }
  12046. /// /rc (CZ_REQ_GIVE_MANNER_BYNAME).
  12047. /// GM adjustment of a player's manner value by -60.
  12048. /// 0212 <char name>.24B
  12049. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  12050. {
  12051. char command[NAME_LENGTH+15];
  12052. char *name = RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12053. name[NAME_LENGTH-1] = '\0';
  12054. safesnprintf(command,sizeof(command),"%cmute %d %s", atcommand_symbol, 60, name);
  12055. is_atcommand(fd, sd, command, 1);
  12056. }
  12057. /// Result of request to resolve account name (ZC_ACK_ACCOUNTNAME).
  12058. /// 01e0 <account id>.L <account name>.24B
  12059. void clif_account_name(int fd, uint32 account_id, const char* accname)
  12060. {
  12061. WFIFOHEAD(fd,packet_len(0x1e0));
  12062. WFIFOW(fd,0) = 0x1e0;
  12063. WFIFOL(fd,2) = account_id;
  12064. safestrncpy(WFIFOCP(fd,6), accname, NAME_LENGTH);
  12065. WFIFOSET(fd,packet_len(0x1e0));
  12066. }
  12067. /// GM requesting account name (for right-click gm menu) (CZ_REQ_ACCOUNTNAME).
  12068. /// 01df <account id>.L
  12069. //! TODO: Figure out how does this actually work
  12070. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  12071. {
  12072. uint32 account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12073. /*
  12074. char query[30];
  12075. safesnprintf(query,sizeof(query),"%d", account_id);
  12076. intif_request_accinfo(sd->fd, sd->bl.id, pc_get_group_level(sd), query, 1); //will call clif_account_name at return
  12077. */
  12078. clif_account_name(fd, account_id, "");
  12079. }
  12080. /// /changemaptype <x> <y> <type> (CZ_CHANGE_MAPTYPE).
  12081. /// GM single cell type change request.
  12082. /// 0198 <x>.W <y>.W <type>.W
  12083. /// type:
  12084. /// 0 = not walkable
  12085. /// 1 = walkable
  12086. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  12087. {
  12088. int x,y,type;
  12089. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12090. if(! pc_has_permission(sd, PC_PERM_USE_CHANGEMAPTYPE) )
  12091. return;
  12092. x = RFIFOW(fd,info->pos[0]);
  12093. y = RFIFOW(fd,info->pos[1]);
  12094. type = RFIFOW(fd,info->pos[2]);
  12095. map_setgatcell(sd->bl.m,x,y,type);
  12096. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  12097. //FIXME: once players leave the map, the client 'forgets' this information.
  12098. }
  12099. /// /in /ex (CZ_SETTING_WHISPER_PC).
  12100. /// Request to allow/deny whispers from a nick.
  12101. /// 00cf <nick>.24B <type>.B
  12102. /// type:
  12103. /// 0 = (/ex nick) deny speech from nick
  12104. /// 1 = (/in nick) allow speech from nick
  12105. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  12106. {
  12107. char* nick;
  12108. uint8 type;
  12109. int i;
  12110. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12111. nick = RFIFOCP(fd,info->pos[0]);
  12112. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  12113. type = RFIFOB(fd,info->pos[1]);
  12114. if( type == 0 ) { // Add name to ignore list (block)
  12115. if (strcmp(wisp_server_name, nick) == 0) {
  12116. clif_wisexin(sd, type, 1); // fail
  12117. return;
  12118. }
  12119. // try to find a free spot, while checking for duplicates at the same time
  12120. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12121. if( i == MAX_IGNORE_LIST ) {// no space for new entry
  12122. clif_wisexin(sd, type, 2); // too many blocks
  12123. return;
  12124. }
  12125. if( sd->ignore[i].name[0] != '\0' ) {// name already exists
  12126. clif_wisexin(sd, type, 0); // Aegis reports success.
  12127. return;
  12128. }
  12129. //Insert in position i
  12130. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  12131. } else { // Remove name from ignore list (unblock)
  12132. // find entry
  12133. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  12134. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' ) { //Not found
  12135. clif_wisexin(sd, type, 1); // fail
  12136. return;
  12137. }
  12138. // move everything one place down to overwrite removed entry
  12139. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  12140. // wipe last entry
  12141. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  12142. }
  12143. clif_wisexin(sd, type, 0); // success
  12144. }
  12145. /// /inall /exall (CZ_SETTING_WHISPER_STATE).
  12146. /// Request to allow/deny all whispers.
  12147. /// 00d0 <type>.B
  12148. /// type:
  12149. /// 0 = (/exall) deny all speech
  12150. /// 1 = (/inall) allow all speech
  12151. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  12152. {
  12153. int type = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]), flag;
  12154. if( type == 0 ) {// Deny all
  12155. if( sd->state.ignoreAll ) {
  12156. flag = 1; // fail
  12157. } else {
  12158. sd->state.ignoreAll = 1;
  12159. flag = 0; // success
  12160. }
  12161. } else {//Unblock everyone
  12162. if( sd->state.ignoreAll ) {
  12163. sd->state.ignoreAll = 0;
  12164. flag = 0; // success
  12165. } else {
  12166. if (sd->ignore[0].name[0] != '\0')
  12167. { //Wipe the ignore list.
  12168. memset(sd->ignore, 0, sizeof(sd->ignore));
  12169. flag = 0; // success
  12170. } else {
  12171. flag = 1; // fail
  12172. }
  12173. }
  12174. }
  12175. clif_wisall(sd, type, flag);
  12176. }
  12177. /// Whisper ignore list (ZC_WHISPER_LIST).
  12178. /// 00d4 <packet len>.W { <char name>.24B }*
  12179. void clif_PMIgnoreList(struct map_session_data* sd)
  12180. {
  12181. int i, fd = sd->fd;
  12182. WFIFOHEAD(fd,4+ARRAYLENGTH(sd->ignore)*NAME_LENGTH);
  12183. WFIFOW(fd,0) = 0xd4;
  12184. for( i = 0; i < ARRAYLENGTH(sd->ignore) && sd->ignore[i].name[0]; i++ ) {
  12185. safestrncpy(WFIFOCP(fd,4+i*NAME_LENGTH), sd->ignore[i].name, NAME_LENGTH);
  12186. }
  12187. WFIFOW(fd,2) = 4+i*NAME_LENGTH;
  12188. WFIFOSET(fd,WFIFOW(fd,2));
  12189. }
  12190. /// Whisper ignore list request (CZ_REQ_WHISPER_LIST).
  12191. /// 00d3
  12192. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  12193. {
  12194. clif_PMIgnoreList(sd);
  12195. }
  12196. /// Request to invoke the /doridori recovery bonus (CZ_DORIDORI).
  12197. /// 01e7
  12198. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  12199. {
  12200. if (sd->state.doridori) return;
  12201. switch (sd->class_&MAPID_UPPERMASK) {
  12202. case MAPID_SOUL_LINKER:
  12203. case MAPID_STAR_GLADIATOR:
  12204. case MAPID_TAEKWON:
  12205. if (!sd->state.rest)
  12206. break;
  12207. case MAPID_SUPER_NOVICE:
  12208. case MAPID_SUPER_BABY:
  12209. case MAPID_SUPER_NOVICE_E:
  12210. case MAPID_SUPER_BABY_E:
  12211. sd->state.doridori=1;
  12212. break;
  12213. }
  12214. }
  12215. /// Request to invoke the effect of super novice's guardian angel prayer (CZ_CHOPOKGI).
  12216. /// 01ed
  12217. /// Note: This packet is caused by 7 lines of any text, followed by
  12218. /// the prayer and an another line of any text. The prayer is
  12219. /// defined by lines 790~793 in data\msgstringtable.txt
  12220. /// "Dear angel, can you hear my voice?"
  12221. /// "I am" (space separated player name) "Super Novice~"
  12222. /// "Help me out~ Please~ T_T"
  12223. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  12224. {
  12225. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE ) {
  12226. unsigned int next = pc_nextbaseexp(sd);
  12227. if( next ) {
  12228. int percent = (int)( ( (float)sd->status.base_exp/(float)next )*1000. );
  12229. if( percent && ( percent%100 ) == 0 ) {// 10.0%, 20.0%, ..., 90.0%
  12230. 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]
  12231. clif_skill_nodamage(&sd->bl, &sd->bl, MO_EXPLOSIONSPIRITS, 5, 1); // prayer always shows successful Lv5 cast and disregards noskill restrictions
  12232. }
  12233. }
  12234. }
  12235. }
  12236. /// Friends List
  12237. ///
  12238. /// Toggles a single friend online/offline [Skotlex] (ZC_FRIENDS_STATE).
  12239. /// 0206 <account id>.L <char id>.L <state>.B
  12240. /// 0206 <account id>.L <char id>.L <state>.B <name>.24B >= 20180221
  12241. /// state:
  12242. /// 0 = online
  12243. /// 1 = offline
  12244. void clif_friendslist_toggle(struct map_session_data *sd,uint32 account_id, uint32 char_id, int online)
  12245. {
  12246. int i, fd = sd->fd;
  12247. //Seek friend.
  12248. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  12249. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12250. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  12251. return; //Not found
  12252. WFIFOHEAD(fd,packet_len(0x206));
  12253. WFIFOW(fd, 0) = 0x206;
  12254. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  12255. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  12256. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  12257. #if PACKETVER >= 20180221
  12258. safestrncpy(WFIFOCP(fd, 11), sd->status.friends[i].name, NAME_LENGTH);
  12259. #endif
  12260. WFIFOSET(fd, packet_len(0x206));
  12261. }
  12262. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  12263. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  12264. {
  12265. uint32 account_id, char_id, online;
  12266. account_id = va_arg(ap, int);
  12267. char_id = va_arg(ap, int);
  12268. online = va_arg(ap, int);
  12269. clif_friendslist_toggle(sd, account_id, char_id, online);
  12270. return 0;
  12271. }
  12272. /// Sends the whole friends list (ZC_FRIENDS_LIST).
  12273. /// 0201 <packet len>.W { <account id>.L <char id>.L <name>.24B }*
  12274. /// 0201 <packet len>.W { <account id>.L <char id>.L }* >= 20180221
  12275. void clif_friendslist_send(struct map_session_data *sd)
  12276. {
  12277. int i = 0, n, fd = sd->fd;
  12278. #if PACKETVER >= 20180221
  12279. const int size = 8;
  12280. #else
  12281. const int size = 8 + NAME_LENGTH;
  12282. #endif
  12283. // Send friends list
  12284. WFIFOHEAD(fd, MAX_FRIENDS * size + 4);
  12285. WFIFOW(fd, 0) = 0x201;
  12286. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++) {
  12287. WFIFOL(fd, 4 + size * i + 0) = sd->status.friends[i].account_id;
  12288. WFIFOL(fd, 4 + size * i + 4) = sd->status.friends[i].char_id;
  12289. #if PACKETVER < 20180221
  12290. safestrncpy(WFIFOCP(fd, 4 + size * i + 8), sd->status.friends[i].name, NAME_LENGTH);
  12291. #endif
  12292. }
  12293. if (i) {
  12294. WFIFOW(fd,2) = 4 + size * i;
  12295. WFIFOSET(fd, WFIFOW(fd,2));
  12296. }
  12297. for (n = 0; n < i; n++) { //Sending the online players
  12298. if (map_charid2sd(sd->status.friends[n].char_id))
  12299. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  12300. }
  12301. }
  12302. /// Notification about the result of a friend add request (ZC_ADD_FRIENDS_LIST).
  12303. /// 0209 <result>.W <account id>.L <char id>.L <name>.24B
  12304. /// result:
  12305. /// 0 = MsgStringTable[821]="You have become friends with (%s)."
  12306. /// 1 = MsgStringTable[822]="(%s) does not want to be friends with you."
  12307. /// 2 = MsgStringTable[819]="Your Friend List is full."
  12308. /// 3 = MsgStringTable[820]="(%s)'s Friend List is full."
  12309. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  12310. {
  12311. int fd;
  12312. nullpo_retv(sd);
  12313. fd = sd->fd;
  12314. WFIFOHEAD(fd,packet_len(0x209));
  12315. WFIFOW(fd,0) = 0x209;
  12316. WFIFOW(fd,2) = type;
  12317. if (f_sd) {
  12318. WFIFOL(fd,4) = f_sd->status.account_id;
  12319. WFIFOL(fd,8) = f_sd->status.char_id;
  12320. safestrncpy(WFIFOCP(fd, 12), f_sd->status.name,NAME_LENGTH);
  12321. }
  12322. WFIFOSET(fd, packet_len(0x209));
  12323. }
  12324. /// Asks a player for permission to be added as friend (ZC_REQ_ADD_FRIENDS).
  12325. /// 0207 <req account id>.L <req char id>.L <req char name>.24B
  12326. void clif_friendlist_req(struct map_session_data* sd, uint32 account_id, uint32 char_id, const char* name)
  12327. {
  12328. int fd = sd->fd;
  12329. WFIFOHEAD(fd,packet_len(0x207));
  12330. WFIFOW(fd,0) = 0x207;
  12331. WFIFOL(fd,2) = account_id;
  12332. WFIFOL(fd,6) = char_id;
  12333. safestrncpy(WFIFOCP(fd,10), name, NAME_LENGTH);
  12334. WFIFOSET(fd,packet_len(0x207));
  12335. }
  12336. /// Request to add a player as friend (CZ_ADD_FRIENDS).
  12337. /// 0202 <name>.24B
  12338. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  12339. {
  12340. struct map_session_data *f_sd;
  12341. int i;
  12342. f_sd = map_nick2sd(RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]),false);
  12343. // Friend doesn't exist (no player with this name)
  12344. if (f_sd == NULL) {
  12345. clif_displaymessage(fd, msg_txt(sd,3));
  12346. return;
  12347. }
  12348. if( sd->bl.id == f_sd->bl.id ) {// adding oneself as friend
  12349. return;
  12350. }
  12351. // ensure that the request player's friend list is not full
  12352. ARR_FIND(0, MAX_FRIENDS, i, sd->status.friends[i].char_id == 0);
  12353. if( i == MAX_FRIENDS ){
  12354. clif_friendslist_reqack(sd, f_sd, 2);
  12355. return;
  12356. }
  12357. // @noask [LuzZza]
  12358. if(f_sd->state.noask) {
  12359. clif_noask_sub(sd, f_sd, 5);
  12360. return;
  12361. }
  12362. // Friend already exists
  12363. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  12364. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  12365. clif_displaymessage(fd, msg_txt(sd,671)); //"Friend already exists."
  12366. return;
  12367. }
  12368. }
  12369. f_sd->friend_req = sd->status.char_id;
  12370. sd->friend_req = f_sd->status.char_id;
  12371. clif_friendlist_req(f_sd, sd->status.account_id, sd->status.char_id, sd->status.name);
  12372. }
  12373. /// Answer to a friend add request (CZ_ACK_REQ_ADD_FRIENDS).
  12374. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.B
  12375. /// 0208 <inviter account id>.L <inviter char id>.L <reply>.L (PACKETVER >= 6)
  12376. /// reply:
  12377. /// 0 = rejected
  12378. /// 1 = accepted
  12379. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  12380. {
  12381. struct map_session_data *f_sd;
  12382. uint32 account_id;
  12383. char reply;
  12384. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12385. account_id = RFIFOL(fd,info->pos[0]);
  12386. //char_id = RFIFOL(fd,info->pos[1]);
  12387. #if PACKETVER < 6
  12388. reply = RFIFOB(fd,info->pos[2]);
  12389. #else
  12390. reply = RFIFOL(fd,info->pos[2]);
  12391. #endif
  12392. if( sd->bl.id == account_id ) {// adding oneself as friend
  12393. return;
  12394. }
  12395. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  12396. if (f_sd == NULL)
  12397. return;
  12398. if (reply == 0 || !( sd->friend_req == f_sd->status.char_id && f_sd->friend_req == sd->status.char_id ) )
  12399. clif_friendslist_reqack(f_sd, sd, 1);
  12400. else {
  12401. int i;
  12402. // Find an empty slot
  12403. for (i = 0; i < MAX_FRIENDS; i++)
  12404. if (f_sd->status.friends[i].char_id == 0)
  12405. break;
  12406. if (i == MAX_FRIENDS) {
  12407. clif_friendslist_reqack(f_sd, sd, 2);
  12408. return;
  12409. }
  12410. f_sd->status.friends[i].account_id = sd->status.account_id;
  12411. f_sd->status.friends[i].char_id = sd->status.char_id;
  12412. safestrncpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  12413. clif_friendslist_reqack(f_sd, sd, 0);
  12414. achievement_update_objective(f_sd, AG_ADD_FRIEND, 1, i + 1);
  12415. if (battle_config.friend_auto_add) {
  12416. // Also add f_sd to sd's friendlist.
  12417. for (i = 0; i < MAX_FRIENDS; i++) {
  12418. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  12419. return; //No need to add anything.
  12420. if (sd->status.friends[i].char_id == 0)
  12421. break;
  12422. }
  12423. if (i == MAX_FRIENDS) {
  12424. clif_friendslist_reqack(sd, f_sd, 2);
  12425. return;
  12426. }
  12427. sd->status.friends[i].account_id = f_sd->status.account_id;
  12428. sd->status.friends[i].char_id = f_sd->status.char_id;
  12429. safestrncpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  12430. clif_friendslist_reqack(sd, f_sd, 0);
  12431. achievement_update_objective(sd, AG_ADD_FRIEND, 1, i + 1);
  12432. }
  12433. }
  12434. }
  12435. /// Request to delete a friend (CZ_DELETE_FRIENDS).
  12436. /// 0203 <account id>.L <char id>.L
  12437. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  12438. {
  12439. struct map_session_data *f_sd = NULL;
  12440. uint32 account_id, char_id;
  12441. int i, j;
  12442. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12443. account_id = RFIFOL(fd,info->pos[0]);
  12444. char_id = RFIFOL(fd,info->pos[1]);
  12445. // Search friend
  12446. for (i = 0; i < MAX_FRIENDS &&
  12447. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12448. if (i == MAX_FRIENDS) {
  12449. clif_displaymessage(fd, msg_txt(sd,672)); //"Name not found in list."
  12450. return;
  12451. }
  12452. //remove from friend's list first
  12453. if( (f_sd = map_id2sd(account_id)) && f_sd->status.char_id == char_id) {
  12454. for (i = 0; i < MAX_FRIENDS &&
  12455. (f_sd->status.friends[i].char_id != sd->status.char_id || f_sd->status.friends[i].account_id != sd->status.account_id); i++);
  12456. if (i != MAX_FRIENDS) {
  12457. // move all chars up
  12458. for(j = i + 1; j < MAX_FRIENDS; j++)
  12459. memcpy(&f_sd->status.friends[j-1], &f_sd->status.friends[j], sizeof(f_sd->status.friends[0]));
  12460. memset(&f_sd->status.friends[MAX_FRIENDS-1], 0, sizeof(f_sd->status.friends[MAX_FRIENDS-1]));
  12461. //should the guy be notified of some message? we should add it here if so
  12462. WFIFOHEAD(f_sd->fd,packet_len(0x20a));
  12463. WFIFOW(f_sd->fd,0) = 0x20a;
  12464. WFIFOL(f_sd->fd,2) = sd->status.account_id;
  12465. WFIFOL(f_sd->fd,6) = sd->status.char_id;
  12466. WFIFOSET(f_sd->fd, packet_len(0x20a));
  12467. }
  12468. } else { //friend not online -- ask char server to delete from his friendlist
  12469. if(chrif_removefriend(char_id,sd->status.char_id)) { // char-server offline, abort
  12470. clif_displaymessage(fd, msg_txt(sd,673)); //"This action can't be performed at the moment. Please try again later."
  12471. return;
  12472. }
  12473. }
  12474. // We can now delete from original requester
  12475. for (i = 0; i < MAX_FRIENDS &&
  12476. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  12477. // move all chars up
  12478. for(j = i + 1; j < MAX_FRIENDS; j++)
  12479. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  12480. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  12481. clif_displaymessage(fd, msg_txt(sd,674)); //"Friend removed"
  12482. WFIFOHEAD(fd,packet_len(0x20a));
  12483. WFIFOW(fd,0) = 0x20a;
  12484. WFIFOL(fd,2) = account_id;
  12485. WFIFOL(fd,6) = char_id;
  12486. WFIFOSET(fd, packet_len(0x20a));
  12487. }
  12488. /// /pvpinfo list (ZC_ACK_PVPPOINT).
  12489. /// 0210 <char id>.L <account id>.L <win point>.L <lose point>.L <point>.L
  12490. void clif_PVPInfo(struct map_session_data* sd)
  12491. {
  12492. int fd = sd->fd;
  12493. WFIFOHEAD(fd,packet_len(0x210));
  12494. WFIFOW(fd,0) = 0x210;
  12495. WFIFOL(fd,2) = sd->status.char_id;
  12496. WFIFOL(fd,6) = sd->status.account_id;
  12497. WFIFOL(fd,10) = sd->pvp_won; // times won
  12498. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  12499. WFIFOL(fd,18) = sd->pvp_point;
  12500. WFIFOSET(fd, packet_len(0x210));
  12501. }
  12502. /// /pvpinfo (CZ_REQ_PVPPOINT).
  12503. /// 020f <char id>.L <account id>.L
  12504. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  12505. {
  12506. // TODO: Is there a way to use this on an another player (char/acc id)?
  12507. //int cid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12508. //int aid = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  12509. clif_PVPInfo(sd);
  12510. }
  12511. /// SG Feel save OK [Komurka] (CZ_AGREE_STARPLACE).
  12512. /// 0254 <which>.B
  12513. /// which: (unused atm for security purpose)
  12514. /// 0 = sun
  12515. /// 1 = moon
  12516. /// 2 = star
  12517. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  12518. {
  12519. int i;
  12520. //int wich = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  12521. if (sd->menuskill_id != SG_FEEL)
  12522. return;
  12523. i = sd->menuskill_val-1;
  12524. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  12525. sd->feel_map[i].index = map_id2index(sd->bl.m);
  12526. sd->feel_map[i].m = sd->bl.m;
  12527. pc_setglobalreg(sd, add_str(sg_info[i].feel_var), sd->feel_map[i].index);
  12528. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  12529. // clif_misceffect2(&sd->bl, 0x1b0);
  12530. // clif_misceffect2(&sd->bl, 0x21f);
  12531. clif_feel_info(sd, i, 0);
  12532. clif_menuskill_clear(sd);
  12533. }
  12534. /// Star Gladiator's Feeling map confirmation prompt (ZC_STARPLACE).
  12535. /// 0253 <which>.B
  12536. /// which:
  12537. /// 0 = sun
  12538. /// 1 = moon
  12539. /// 2 = star
  12540. void clif_feel_req(int fd, struct map_session_data *sd, uint16 skill_lv)
  12541. {
  12542. WFIFOHEAD(fd,packet_len(0x253));
  12543. WFIFOW(fd,0)=0x253;
  12544. WFIFOB(fd,2)=TOB(skill_lv-1);
  12545. WFIFOSET(fd, packet_len(0x253));
  12546. sd->menuskill_id = SG_FEEL;
  12547. sd->menuskill_val = skill_lv;
  12548. }
  12549. /// Request to change homunculus' name (CZ_RENAME_MER).
  12550. /// 0231 <name>.24B
  12551. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd){
  12552. hom_change_name(sd,RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  12553. }
  12554. /// Request to warp/move homunculus/mercenary to it's owner (CZ_REQUEST_MOVETOOWNER).
  12555. /// 0234 <id>.L
  12556. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd){
  12557. int id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]); // Mercenary or Homunculus
  12558. struct block_list *bl = NULL;
  12559. struct unit_data *ud = NULL;
  12560. if( sd->md && sd->md->bl.id == id )
  12561. bl = &sd->md->bl;
  12562. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12563. bl = &sd->hd->bl; // Moving Homunculus
  12564. else
  12565. return;
  12566. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  12567. ud = unit_bl2ud(bl);
  12568. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  12569. }
  12570. /// Request to move homunculus/mercenary (CZ_REQUEST_MOVENPC).
  12571. /// 0232 <id>.L <position data>.3B
  12572. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd){
  12573. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12574. int id = RFIFOL(fd,info->pos[0]); // Mercenary or Homunculus
  12575. struct block_list *bl = NULL;
  12576. short x, y;
  12577. RFIFOPOS(fd, info->pos[1], &x, &y, NULL);
  12578. if( sd->md && sd->md->bl.id == id )
  12579. bl = &sd->md->bl; // Moving Mercenary
  12580. else if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12581. bl = &sd->hd->bl; // Moving Homunculus
  12582. else
  12583. return;
  12584. unit_walktoxy(bl, x, y, 4);
  12585. }
  12586. /// Request to do an action with homunculus/mercenary (CZ_REQUEST_ACTNPC).
  12587. /// 0233 <id>.L <target id>.L <action>.B
  12588. /// action:
  12589. /// always 0
  12590. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  12591. {
  12592. struct block_list *bl = NULL;
  12593. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  12594. int id = RFIFOL(fd,info->pos[0]);
  12595. int target_id = RFIFOL(fd,info->pos[1]);
  12596. int action_type = RFIFOB(fd,info->pos[2]);
  12597. if( hom_is_active(sd->hd) && sd->hd->bl.id == id )
  12598. bl = &sd->hd->bl;
  12599. else if( sd->md && sd->md->bl.id == id )
  12600. bl = &sd->md->bl;
  12601. else return;
  12602. unit_stop_attack(bl);
  12603. unit_attack(bl, target_id, action_type != 0);
  12604. }
  12605. /// Request to invoke a homunculus menu action (CZ_COMMAND_MER).
  12606. /// 022d <type>.W <command>.B
  12607. /// type:
  12608. /// always 0
  12609. /// command:
  12610. /// 0 = homunculus information
  12611. /// 1 = feed
  12612. /// 2 = delete
  12613. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  12614. { //[orn]
  12615. int cmd = RFIFOW(fd,0);
  12616. //int type = RFIFOW(fd,packet_db[cmd].pos[0]);
  12617. if(!hom_is_active(sd->hd))
  12618. return;
  12619. hom_menu(sd,RFIFOB(fd,packet_db[cmd].pos[1]));
  12620. }
  12621. /// Request to resurrect oneself using Token of Siegfried (CZ_STANDING_RESURRECTION).
  12622. /// 0292
  12623. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  12624. {
  12625. short item_position = pc_search_inventory(sd, ITEMID_TOKEN_OF_SIEGFRIED);
  12626. uint8 hp = 100, sp = 100;
  12627. if (item_position < 0) {
  12628. if (sd->sc.data[SC_LIGHT_OF_REGENE]) {
  12629. // HP restored
  12630. hp = sd->sc.data[SC_LIGHT_OF_REGENE]->val2;
  12631. sp = 0;
  12632. }
  12633. else
  12634. return;
  12635. }
  12636. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  12637. return;
  12638. if (!status_revive(&sd->bl, hp, sp))
  12639. return;
  12640. if (item_position < 0)
  12641. status_change_end(&sd->bl, SC_LIGHT_OF_REGENE, INVALID_TIMER);
  12642. else
  12643. pc_delitem(sd, item_position, 1, 0, 1, LOG_TYPE_CONSUME);
  12644. clif_skill_nodamage(&sd->bl, &sd->bl, ALL_RESURRECTION, 4, 1);
  12645. }
  12646. /// Information about character's status values (ZC_ACK_STATUS_GM).
  12647. /// 0214 <str>.B <standardStr>.B <agi>.B <standardAgi>.B <vit>.B <standardVit>.B
  12648. /// <int>.B <standardInt>.B <dex>.B <standardDex>.B <luk>.B <standardLuk>.B
  12649. /// <attPower>.W <refiningPower>.W <max_mattPower>.W <min_mattPower>.W
  12650. /// <itemdefPower>.W <plusdefPower>.W <mdefPower>.W <plusmdefPower>.W
  12651. /// <hitSuccessValue>.W <avoidSuccessValue>.W <plusAvoidSuccessValue>.W
  12652. /// <criticalSuccessValue>.W <ASPD>.W <plusASPD>.W
  12653. void clif_check(int fd, struct map_session_data* pl_sd)
  12654. {
  12655. WFIFOHEAD(fd,packet_len(0x214));
  12656. WFIFOW(fd, 0) = 0x214;
  12657. WFIFOB(fd, 2) = min(pl_sd->status.str, UINT8_MAX);
  12658. WFIFOB(fd, 3) = pc_need_status_point(pl_sd, SP_STR, 1);
  12659. WFIFOB(fd, 4) = min(pl_sd->status.agi, UINT8_MAX);
  12660. WFIFOB(fd, 5) = pc_need_status_point(pl_sd, SP_AGI, 1);
  12661. WFIFOB(fd, 6) = min(pl_sd->status.vit, UINT8_MAX);
  12662. WFIFOB(fd, 7) = pc_need_status_point(pl_sd, SP_VIT, 1);
  12663. WFIFOB(fd, 8) = min(pl_sd->status.int_, UINT8_MAX);
  12664. WFIFOB(fd, 9) = pc_need_status_point(pl_sd, SP_INT, 1);
  12665. WFIFOB(fd,10) = min(pl_sd->status.dex, UINT8_MAX);
  12666. WFIFOB(fd,11) = pc_need_status_point(pl_sd, SP_DEX, 1);
  12667. WFIFOB(fd,12) = min(pl_sd->status.luk, UINT8_MAX);
  12668. WFIFOB(fd,13) = pc_need_status_point(pl_sd, SP_LUK, 1);
  12669. WFIFOW(fd,14) = pl_sd->battle_status.batk+pl_sd->battle_status.rhw.atk+pl_sd->battle_status.lhw.atk;
  12670. WFIFOW(fd,16) = pl_sd->battle_status.rhw.atk2+pl_sd->battle_status.lhw.atk2;
  12671. WFIFOW(fd,18) = pl_sd->battle_status.matk_max;
  12672. WFIFOW(fd,20) = pl_sd->battle_status.matk_min;
  12673. WFIFOW(fd,22) = pl_sd->battle_status.def;
  12674. WFIFOW(fd,24) = pl_sd->battle_status.def2;
  12675. WFIFOW(fd,26) = pl_sd->battle_status.mdef;
  12676. WFIFOW(fd,28) = pl_sd->battle_status.mdef2;
  12677. WFIFOW(fd,30) = pl_sd->battle_status.hit;
  12678. WFIFOW(fd,32) = pl_sd->battle_status.flee;
  12679. WFIFOW(fd,34) = pl_sd->battle_status.flee2/10;
  12680. WFIFOW(fd,36) = pl_sd->battle_status.cri/10;
  12681. WFIFOW(fd,38) = (2000-pl_sd->battle_status.amotion)/10; // aspd
  12682. WFIFOW(fd,40) = 0; // FIXME: What is 'plusASPD' supposed to be? Maybe adelay?
  12683. WFIFOSET(fd,packet_len(0x214));
  12684. }
  12685. /// /check (CZ_REQ_STATUS_GM).
  12686. /// Request character's status values.
  12687. /// 0213 <char name>.24B
  12688. void clif_parse_Check(int fd, struct map_session_data *sd)
  12689. {
  12690. char charname[NAME_LENGTH];
  12691. struct map_session_data* pl_sd;
  12692. if(!pc_has_permission(sd, PC_PERM_USE_CHECK))
  12693. return;
  12694. safestrncpy(charname, RFIFOCP(fd,packet_db[RFIFOW(fd,0)].pos[0]), sizeof(charname));
  12695. if( ( pl_sd = map_nick2sd(charname,false) ) == NULL || pc_get_group_level(sd) < pc_get_group_level(pl_sd) )
  12696. {
  12697. return;
  12698. }
  12699. clif_check(fd, pl_sd);
  12700. }
  12701. /// MAIL SYSTEM
  12702. /// By Zephyrus
  12703. ///
  12704. /// Notification about the result of adding an item to mail
  12705. /// 0255 <index>.W <result>.B (ZC_ACK_MAIL_ADD_ITEM)
  12706. /// result:
  12707. /// 0 = success
  12708. /// 1 = failure
  12709. /// 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)
  12710. /// { <card id>.W }*4 { <option index>.W <option value>.W <option parameter>.B }*5
  12711. /// result:
  12712. /// 0 = success
  12713. /// 1 = over weight
  12714. /// 2 = fatal error
  12715. void clif_Mail_setattachment(struct map_session_data* sd, int index, int amount, uint8 flag)
  12716. {
  12717. int fd = sd->fd;
  12718. #if PACKETVER < 20150513
  12719. WFIFOHEAD(fd,packet_len(0x255));
  12720. WFIFOW(fd,0) = 0x255;
  12721. WFIFOW(fd,2) = index;
  12722. WFIFOB(fd,4) = flag;
  12723. WFIFOSET(fd,packet_len(0x255));
  12724. #else
  12725. struct item* item = &sd->inventory.u.items_inventory[index-2];
  12726. int i, total = 0;
  12727. WFIFOHEAD(fd, 53);
  12728. WFIFOW(fd, 0) = 0xa05;
  12729. WFIFOB(fd, 2) = flag;
  12730. WFIFOW(fd, 3) = index;
  12731. WFIFOW(fd, 5) = amount;
  12732. WFIFOW(fd, 7) = item->nameid;
  12733. WFIFOB(fd, 9) = itemtype(item->nameid);
  12734. WFIFOB(fd, 10) = item->identify;
  12735. WFIFOB(fd, 11) = item->attribute;
  12736. WFIFOB(fd, 12) = item->refine;
  12737. clif_addcards(WFIFOP(fd,13), item);
  12738. clif_add_random_options(WFIFOP(fd,21), item);
  12739. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  12740. if( sd->mail.item[i].nameid == 0 ){
  12741. break;
  12742. }
  12743. total += sd->mail.item[i].amount * ( sd->inventory_data[sd->mail.item[i].index]->weight / 10 );
  12744. }
  12745. WFIFOW(fd, 46) = total;
  12746. // 5 empty unknown bytes
  12747. memset(WFIFOP(fd, 48), 0, 5);
  12748. WFIFOSET(fd, 53);
  12749. #endif
  12750. }
  12751. /// Notification about the result of retrieving a mail attachment
  12752. /// 0245 <result>.B (ZC_MAIL_REQ_GET_ITEM)
  12753. /// result:
  12754. /// 0 = success
  12755. /// 1 = failure
  12756. /// 2 = too many items
  12757. /// 09f2 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ZENY_FROM_MAIL)
  12758. /// 09f4 <mail id>.Q <mail tab>.B <result>.B (ZC_ACK_ITEM_FROM_MAIL)
  12759. void clif_mail_getattachment(struct map_session_data* sd, struct mail_message *msg, uint8 result, enum mail_attachment_type type) {
  12760. int fd = sd->fd;
  12761. #if PACKETVER < 20150513
  12762. WFIFOHEAD(fd,packet_len(0x245));
  12763. WFIFOW(fd,0) = 0x245;
  12764. WFIFOB(fd,2) = result;
  12765. WFIFOSET(fd,packet_len(0x245));
  12766. #else
  12767. switch( type ){
  12768. case MAIL_ATT_ITEM:
  12769. case MAIL_ATT_ZENY:
  12770. break;
  12771. default:
  12772. return;
  12773. }
  12774. WFIFOHEAD(fd, 12);
  12775. WFIFOW(fd, 0) = type == MAIL_ATT_ZENY ? 0x9f2 : 0x9f4;
  12776. WFIFOQ(fd, 2) = msg->id;
  12777. WFIFOB(fd, 10) = msg->type;
  12778. WFIFOB(fd, 11) = result;
  12779. WFIFOSET(fd, 12);
  12780. clif_Mail_refreshinbox( sd, msg->type, 0 );
  12781. #endif
  12782. }
  12783. /// Notification about the result of sending a mail
  12784. /// 0249 <result>.B (ZC_MAIL_REQ_SEND)
  12785. /// result:
  12786. /// 0 = success
  12787. /// 1 = recipinent does not exist
  12788. /// 09ed <result>.B (ZC_ACK_WRITE_MAIL)
  12789. void clif_Mail_send(struct map_session_data* sd, enum mail_send_result result){
  12790. int fd = sd->fd;
  12791. #if PACKETVER < 20150513
  12792. WFIFOHEAD(fd,packet_len(0x249));
  12793. WFIFOW(fd,0) = 0x249;
  12794. WFIFOB(fd,2) = result != WRITE_MAIL_SUCCESS;
  12795. WFIFOSET(fd,packet_len(0x249));
  12796. #else
  12797. WFIFOHEAD(fd, 3);
  12798. WFIFOW(fd, 0) = 0x9ed;
  12799. WFIFOB(fd, 2) = result;
  12800. WFIFOSET(fd, 3);
  12801. #endif
  12802. }
  12803. /// Notification about the result of deleting a mail.
  12804. /// 0257 <mail id>.L <result>.W (ZC_ACK_MAIL_DELETE)
  12805. /// result:
  12806. /// 0 = success
  12807. /// 1 = failure
  12808. // 09f6 <mail tab>.B <mail id>.Q (ZC_ACK_DELETE_MAIL)
  12809. void clif_mail_delete( struct map_session_data* sd, struct mail_message *msg, bool success ){
  12810. int fd = sd->fd;
  12811. #if PACKETVER < 20150513
  12812. WFIFOHEAD(fd, packet_len(0x257));
  12813. WFIFOW(fd,0) = 0x257;
  12814. WFIFOL(fd,2) = msg->id;
  12815. WFIFOW(fd,6) = !success;
  12816. WFIFOSET(fd, packet_len(0x257));
  12817. #else
  12818. // This is only a success notification
  12819. if( success ){
  12820. WFIFOHEAD(fd, 11);
  12821. WFIFOW(fd, 0) = 0x9f6;
  12822. WFIFOB(fd, 2) = msg->type;
  12823. WFIFOQ(fd, 3) = msg->id;
  12824. WFIFOSET(fd, 11);
  12825. }
  12826. #endif
  12827. }
  12828. /// Notification about the result of returning a mail (ZC_ACK_MAIL_RETURN).
  12829. /// 0274 <mail id>.L <result>.W
  12830. /// result:
  12831. /// 0 = success
  12832. /// 1 = failure
  12833. void clif_Mail_return(int fd, int mail_id, short fail)
  12834. {
  12835. WFIFOHEAD(fd,packet_len(0x274));
  12836. WFIFOW(fd,0) = 0x274;
  12837. WFIFOL(fd,2) = mail_id;
  12838. WFIFOW(fd,6) = fail;
  12839. WFIFOSET(fd,packet_len(0x274));
  12840. }
  12841. /// Notification about new mail.
  12842. /// 024a <mail id>.L <title>.40B <sender>.24B (ZC_MAIL_RECEIVE)
  12843. /// 09e7 <result>.B (ZC_NOTIFY_UNREADMAIL)
  12844. void clif_Mail_new(struct map_session_data* sd, int mail_id, const char *sender, const char *title){
  12845. int fd = sd->fd;
  12846. #if PACKETVER < 20150513
  12847. WFIFOHEAD(fd,packet_len(0x24a));
  12848. WFIFOW(fd,0) = 0x24a;
  12849. WFIFOL(fd,2) = mail_id;
  12850. safestrncpy(WFIFOCP(fd,6), title, MAIL_TITLE_LENGTH);
  12851. safestrncpy(WFIFOCP(fd,46), sender, NAME_LENGTH);
  12852. WFIFOSET(fd,packet_len(0x24a));
  12853. #else
  12854. WFIFOHEAD(fd,3);
  12855. WFIFOW(fd,0) = 0x9e7;
  12856. WFIFOB(fd,2) = sd->mail.inbox.unread > 0 || sd->mail.inbox.unchecked > 0; // unread
  12857. WFIFOSET(fd,3);
  12858. #endif
  12859. }
  12860. /// Opens/closes the mail window (ZC_MAIL_WINDOWS).
  12861. /// 0260 <type>.L
  12862. /// type:
  12863. /// 0 = open
  12864. /// 1 = close
  12865. void clif_Mail_window(int fd, int flag)
  12866. {
  12867. WFIFOHEAD(fd,packet_len(0x260));
  12868. WFIFOW(fd,0) = 0x260;
  12869. WFIFOL(fd,2) = flag;
  12870. WFIFOSET(fd,packet_len(0x260));
  12871. }
  12872. /// Lists mails stored in inbox.
  12873. /// 0240 <packet len>.W <amount>.L { <mail id>.L <title>.40B <read>.B <sender>.24B <time>.L }*amount (ZC_MAIL_REQ_GET_LIST)
  12874. /// read:
  12875. /// 0 = unread
  12876. /// 1 = read
  12877. /// 09f0 <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST)
  12878. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12879. /// 0a7d <packet len>.W <type>.B <amount>.B <last page>.B (ZC_ACK_MAIL_LIST2)
  12880. /// { <mail id>.Q <read>.B <type>.B <sender>.24B <received>.L <expires>.L <title length>.W <title>.?B }*
  12881. /// 0ac2 <packet len>.W <unknown>.B (ZC_ACK_MAIL_LIST3)
  12882. /// { <type>.B <mail id>.Q <read>.B <type>.B <sender>.24B <expires>.L <title length>.W <title>.?B }*
  12883. void clif_Mail_refreshinbox(struct map_session_data *sd,enum mail_inbox_type type,int64 mailID){
  12884. #if PACKETVER < 20150513
  12885. int fd = sd->fd;
  12886. struct mail_data *md = &sd->mail.inbox;
  12887. struct mail_message *msg;
  12888. int len, i, j;
  12889. len = 8 + (73 * md->amount);
  12890. WFIFOHEAD(fd,len);
  12891. WFIFOW(fd,0) = 0x240;
  12892. WFIFOW(fd,2) = len;
  12893. WFIFOL(fd,4) = md->amount;
  12894. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  12895. {
  12896. msg = &md->msg[i];
  12897. if (msg->id < 1)
  12898. continue;
  12899. WFIFOL(fd,8+73*j) = msg->id;
  12900. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  12901. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD);
  12902. safestrncpy(WFIFOCP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  12903. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  12904. j++;
  12905. }
  12906. WFIFOSET(fd,len);
  12907. if( md->full ) {// TODO: is this official?
  12908. char output[100];
  12909. safesnprintf(output,sizeof(output),"Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  12910. clif_messagecolor(&sd->bl, color_table[COLOR_LIGHT_GREEN], output, false, SELF);
  12911. }
  12912. #else
  12913. int fd = sd->fd;
  12914. struct mail_data *md = &sd->mail.inbox;
  12915. struct mail_message *msg;
  12916. int i, j, k, offset, titleLength;
  12917. uint8 mailType, amount, remaining;
  12918. uint32 now = (uint32)time(NULL);
  12919. #if PACKETVER >= 20170419
  12920. int cmd = 0xac2;
  12921. #elif PACKETVER >= 20160601
  12922. int cmd = 0xa7d;
  12923. #else
  12924. int cmd = 0x9f0;
  12925. #endif
  12926. if( battle_config.mail_daily_count ){
  12927. mail_refresh_remaining_amount(sd);
  12928. }
  12929. #if PACKETVER >= 20170419
  12930. // Always send all
  12931. i = md->amount;
  12932. #else
  12933. // If a starting mail id was sent
  12934. if( mailID != 0 ){
  12935. ARR_FIND( 0, md->amount, i, md->msg[i].id == mailID );
  12936. // Unknown mail
  12937. if( i == md->amount ){
  12938. // Ignore the request for now
  12939. return; // TODO: Should we just show the first page instead?
  12940. }
  12941. // It was actually the oldest/first mail, there is no further page
  12942. if( i == 0 ){
  12943. return;
  12944. }
  12945. // We actually want the next/older mail
  12946. i -= 1;
  12947. }else{
  12948. i = md->amount;
  12949. }
  12950. #endif
  12951. // Count the remaining mails from the starting mail or the beginning
  12952. // Only count mails of the target type(before 2017-04-19) and those that should not have been deleted already
  12953. for( j = i, remaining = 0; j >= 0; j-- ){
  12954. msg = &md->msg[j];
  12955. if (msg->id < 1)
  12956. continue;
  12957. #if PACKETVER < 20170419
  12958. if (msg->type != type)
  12959. continue;
  12960. #endif
  12961. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  12962. continue;
  12963. remaining++;
  12964. }
  12965. #if PACKETVER >= 20170419
  12966. // Always send all
  12967. amount = remaining;
  12968. #else
  12969. if( remaining > MAIL_PAGE_SIZE ){
  12970. amount = MAIL_PAGE_SIZE;
  12971. }else{
  12972. amount = remaining;
  12973. }
  12974. #endif
  12975. WFIFOHEAD(fd, 7 + ((44 + MAIL_TITLE_LENGTH) * amount));
  12976. WFIFOW(fd, 0) = cmd;
  12977. #if PACKETVER >= 20170419
  12978. WFIFOB(fd, 4) = 1; // Unknown
  12979. offset = 5;
  12980. #else
  12981. WFIFOB(fd, 4) = type;
  12982. WFIFOB(fd, 5) = amount;
  12983. WFIFOB(fd, 6) = ( remaining < MAIL_PAGE_SIZE ); // last page
  12984. offset = 7;
  12985. #endif
  12986. for( amount = 0; i >= 0; i-- ){
  12987. msg = &md->msg[i];
  12988. if (msg->id < 1)
  12989. continue;
  12990. #if PACKETVER < 20170419
  12991. if (msg->type != type)
  12992. continue;
  12993. #endif
  12994. if (msg->scheduled_deletion > 0 && msg->scheduled_deletion <= now)
  12995. continue;
  12996. #if PACKETVER >= 20170419
  12997. WFIFOB(fd, offset) = msg->type;
  12998. offset += 1;
  12999. #endif
  13000. WFIFOQ(fd, offset + 0) = (uint64)msg->id;
  13001. WFIFOB(fd, offset + 8) = (msg->status != MAIL_UNREAD);
  13002. mailType = MAIL_TYPE_TEXT; // Normal letter
  13003. if( msg->zeny > 0 ){
  13004. mailType |= MAIL_TYPE_ZENY; // Mail contains zeny
  13005. }
  13006. for( k = 0; k < MAIL_MAX_ITEM; k++ ){
  13007. if( msg->item[k].nameid > 0 ){
  13008. mailType |= MAIL_TYPE_ITEM; // Mail contains items
  13009. break;
  13010. }
  13011. }
  13012. #if PACKETVER >= 20170419
  13013. // If it came from an npc?
  13014. if( !msg->send_id ){
  13015. mailType |= MAIL_TYPE_NPC;
  13016. }
  13017. #endif
  13018. WFIFOB(fd, offset + 9) = mailType;
  13019. safestrncpy(WFIFOCP(fd, offset + 10), msg->send_name, NAME_LENGTH);
  13020. #if PACKETVER < 20170419
  13021. // How much time has passed since you received the mail
  13022. WFIFOL(fd, offset + 34 ) = now - (uint32)msg->timestamp;
  13023. offset += 4;
  13024. #endif
  13025. // If automatic return/deletion of mails is enabled, notify the client when it will kick in
  13026. if( msg->scheduled_deletion > 0 ){
  13027. WFIFOL(fd, offset + 34) = (uint32)msg->scheduled_deletion - now;
  13028. }else{
  13029. // Fake the scheduled deletion to one year in the future
  13030. // Sadly the client always displays the scheduled deletion after 24 hours no matter how high this value gets [Lemongrass]
  13031. WFIFOL(fd, offset + 34) = 365 * 24 * 60 * 60;
  13032. }
  13033. WFIFOW(fd, offset + 38) = titleLength = (int16)(strlen(msg->title) + 1);
  13034. safestrncpy(WFIFOCP(fd, offset + 40), msg->title, titleLength);
  13035. offset += 40 + titleLength;
  13036. }
  13037. WFIFOW(fd, 2) = (int16)offset;
  13038. WFIFOSET(fd, offset);
  13039. #endif
  13040. }
  13041. /// Mail inbox list request.
  13042. /// 023f (CZ_MAIL_GET_LIST)
  13043. /// 09e8 <mail tab>.B <mail id>.Q (CZ_OPEN_MAILBOX)
  13044. /// 09ee <mail tab>.B <mail id>.Q (CZ_REQ_NEXT_MAIL_LIST)
  13045. /// 09ef <mail tab>.B <mail id>.Q (CZ_REQ_REFRESH_MAIL_LIST)
  13046. /// 0ac0 <mail id>.Q <unknown>.16B (CZ_OPEN_MAILBOX2)
  13047. /// 0ac1 <mail id>.Q <unknown>.16B (CZ_REQ_REFRESH_MAIL_LIST2)
  13048. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd){
  13049. #if PACKETVER < 20150513
  13050. struct mail_data* md = &sd->mail.inbox;
  13051. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  13052. intif_Mail_requestinbox(sd->status.char_id, 1, MAIL_INBOX_NORMAL);
  13053. else
  13054. clif_Mail_refreshinbox(sd, MAIL_INBOX_NORMAL,0);
  13055. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13056. mail_removezeny(sd, false);
  13057. #else
  13058. int cmd = RFIFOW(fd, 0);
  13059. #if PACKETVER < 20170419
  13060. uint8 openType = RFIFOB(fd, 2);
  13061. uint64 mailId = RFIFOQ(fd, 3);
  13062. #else
  13063. uint8 openType;
  13064. uint64 mailId = RFIFOQ(fd, 2);
  13065. int i;
  13066. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mailId);
  13067. if( i == MAIL_MAX_INBOX ){
  13068. openType = MAIL_INBOX_NORMAL;
  13069. mailId = 0;
  13070. }else{
  13071. openType = sd->mail.inbox.msg[i].type;
  13072. mailId = 0;
  13073. }
  13074. #endif
  13075. switch( openType ){
  13076. case MAIL_INBOX_NORMAL:
  13077. case MAIL_INBOX_ACCOUNT:
  13078. case MAIL_INBOX_RETURNED:
  13079. break;
  13080. default:
  13081. // Unknown type: ignore request
  13082. return;
  13083. }
  13084. if( sd->mail.changed || ( cmd == 0x9ef || cmd == 0xac1 ) ){
  13085. intif_Mail_requestinbox(sd->status.char_id, 1, (enum mail_inbox_type)openType);
  13086. return;
  13087. }
  13088. // If it is not a next page request
  13089. if( cmd != 0x9ee ){
  13090. mailId = 0;
  13091. }
  13092. clif_Mail_refreshinbox(sd,(enum mail_inbox_type)openType,mailId);
  13093. #endif
  13094. }
  13095. /// Opens a mail
  13096. /// 0242 <packet len>.W <mail id>.L <title>.40B <sender>.24B <time>.L <zeny>.L (ZC_MAIL_REQ_OPEN)
  13097. /// <amount>.L <name id>.W <item type>.W <identified>.B <damaged>.B <refine>.B
  13098. /// <card1>.W <card2>.W <card3>.W <card4>.W <message>.?B
  13099. /// 09eb <packet len>.W <type>.B <mail id>.Q <message length>.W <zeny>.Q <item count>.B (ZC_ACK_READ_MAIL)
  13100. /// { }*n
  13101. // TODO: Packet description => for repeated block
  13102. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  13103. {
  13104. int i, fd = sd->fd;
  13105. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13106. if( i == MAIL_MAX_INBOX ) {
  13107. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  13108. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  13109. return;
  13110. } else {
  13111. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13112. struct item *item;
  13113. struct item_data *data;
  13114. int msg_len = strlen(msg->body), len;
  13115. #if PACKETVER >= 20150513
  13116. int offset, j, itemsize, count = 0;
  13117. #endif
  13118. if( msg_len == 0 ) {
  13119. strcpy(msg->body, "(no message)"); // TODO: confirm for RODEX
  13120. msg_len = strlen(msg->body);
  13121. }
  13122. #if PACKETVER < 20150513
  13123. item = &msg->item[0];
  13124. len = 101 + msg_len;
  13125. WFIFOHEAD(fd,len);
  13126. WFIFOW(fd,0) = 0x242;
  13127. WFIFOW(fd,2) = len;
  13128. WFIFOL(fd,4) = msg->id;
  13129. safestrncpy(WFIFOCP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  13130. safestrncpy(WFIFOCP(fd,48), msg->send_name, NAME_LENGTH + 1);
  13131. WFIFOL(fd,72) = 0;
  13132. WFIFOL(fd,76) = msg->zeny;
  13133. if( item->nameid && (data = itemdb_exists(item->nameid)) != NULL ) {
  13134. WFIFOL(fd,80) = item->amount;
  13135. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  13136. WFIFOW(fd,86) = data->type;
  13137. WFIFOB(fd,88) = item->identify;
  13138. WFIFOB(fd,89) = item->attribute;
  13139. WFIFOB(fd,90) = item->refine;
  13140. WFIFOW(fd,91) = item->card[0];
  13141. WFIFOW(fd,93) = item->card[1];
  13142. WFIFOW(fd,95) = item->card[2];
  13143. WFIFOW(fd,97) = item->card[3];
  13144. } else // no item, set all to zero
  13145. memset(WFIFOP(fd,80), 0x00, 19);
  13146. WFIFOB(fd,99) = (unsigned char)msg_len;
  13147. safestrncpy(WFIFOCP(fd,100), msg->body, msg_len + 1);
  13148. WFIFOSET(fd,len);
  13149. #else
  13150. // Count the attached items
  13151. ARR_FIND( 0, MAIL_MAX_ITEM, count, msg->item[count].nameid == 0 );
  13152. msg_len += 1; // Zero Termination
  13153. itemsize = 24 + 5 * 5;
  13154. len = 24 + msg_len+1 + itemsize * count;
  13155. WFIFOHEAD(fd, len);
  13156. WFIFOW(fd, 0) = 0x9eb;
  13157. WFIFOW(fd, 2) = len;
  13158. WFIFOB(fd, 4) = msg->type;
  13159. WFIFOQ(fd, 5) = msg->id;
  13160. WFIFOW(fd, 13) = msg_len;
  13161. WFIFOQ(fd, 15) = msg->zeny;
  13162. WFIFOB(fd, 23) = (uint8)count; // item count
  13163. safestrncpy(WFIFOCP(fd, 24), msg->body, msg_len);
  13164. offset = 24 + msg_len;
  13165. for (j = 0; j < MAIL_MAX_ITEM; j++) {
  13166. item = &msg->item[j];
  13167. if (item->nameid > 0 && item->amount > 0 && (data = itemdb_exists(item->nameid)) != NULL) {
  13168. WFIFOW(fd, offset) = item->amount;
  13169. WFIFOW(fd, offset + 2) = (data->view_id) ? data->view_id : item->nameid;
  13170. WFIFOB(fd, offset + 4) = item->identify;
  13171. WFIFOB(fd, offset + 5) = item->attribute;
  13172. WFIFOB(fd, offset + 6) = item->refine;
  13173. clif_addcards(WFIFOP(fd, offset + 7), item);
  13174. // 4B unsigned long location
  13175. WFIFOB(fd, offset + 15 + 4) = data->type;
  13176. // 2B unsigned short wItemSpriteNumber
  13177. //WFIFOW(fd, offset + 15 + 5) = data->view_id;
  13178. // 2B unsigned short bindOnEquipType
  13179. clif_add_random_options(WFIFOP(fd, offset + 15 + 9 ), item);
  13180. offset += itemsize;
  13181. }
  13182. }
  13183. WFIFOSET(fd, len);
  13184. #endif
  13185. if (msg->status == MAIL_UNREAD) {
  13186. msg->status = MAIL_READ;
  13187. intif_Mail_read(mail_id);
  13188. clif_parse_Mail_refreshinbox(fd, sd);
  13189. sd->mail.inbox.unread--;
  13190. clif_Mail_new(sd, 0, msg->send_name, msg->title);
  13191. }
  13192. }
  13193. }
  13194. /// Request to open a mail.
  13195. /// 0241 <mail id>.L (CZ_MAIL_OPEN)
  13196. /// 09ea <mail tab>.B <mail id>.Q (CZ_REQ_READ_MAIL)
  13197. void clif_parse_Mail_read(int fd, struct map_session_data *sd){
  13198. #if PACKETVER < 20150513
  13199. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13200. #else
  13201. //uint8 openType = RFIFOB(fd, 2);
  13202. int mail_id = (int)RFIFOQ(fd, 3);
  13203. #endif
  13204. if( mail_id <= 0 )
  13205. return;
  13206. if( mail_invalid_operation(sd) )
  13207. return;
  13208. clif_Mail_read(sd, mail_id);
  13209. }
  13210. /// Allow a player to begin writing a mail
  13211. /// 0a12 <receiver>.24B <success>.B (ZC_ACK_OPEN_WRITE_MAIL)
  13212. void clif_send_Mail_beginwrite_ack( struct map_session_data *sd, char* name, bool success ){
  13213. int fd = sd->fd;
  13214. WFIFOHEAD(fd, 27);
  13215. WFIFOW(fd, 0) = 0xa12;
  13216. safestrncpy(WFIFOCP(fd, 2), name, NAME_LENGTH);
  13217. WFIFOB(fd, 26) = success;
  13218. WFIFOSET(fd, 27);
  13219. }
  13220. /// Request to start writing a mail
  13221. /// 0a08 <receiver>.24B (CZ_REQ_OPEN_WRITE_MAIL)
  13222. void clif_parse_Mail_beginwrite( int fd, struct map_session_data *sd ){
  13223. char name[NAME_LENGTH];
  13224. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13225. if( sd->state.storage_flag || sd->state.mail_writing || sd->trade_partner ){
  13226. clif_send_Mail_beginwrite_ack(sd, name, false);
  13227. return;
  13228. }
  13229. mail_clear(sd);
  13230. sd->state.mail_writing = true;
  13231. clif_send_Mail_beginwrite_ack(sd, name,true);
  13232. }
  13233. /// Notification that the client cancelled writing a mail
  13234. /// 0a03 (CZ_REQ_CANCEL_WRITE_MAIL)
  13235. void clif_parse_Mail_cancelwrite( int fd, struct map_session_data *sd ){
  13236. sd->state.mail_writing = false;
  13237. }
  13238. /// Give the client information about the recipient, if available
  13239. /// 0a14 <char id>.L <class>.W <base level>.W (ZC_CHECK_RECEIVE_CHARACTER_NAME)
  13240. /// 0a51 <char id>.L <class>.W <base level>.W <name>.24B (ZC_CHECK_RECEIVE_CHARACTER_NAME2)
  13241. void clif_Mail_Receiver_Ack( struct map_session_data* sd, uint32 char_id, short class_, uint32 level, const char* name ){
  13242. int fd = sd->fd;
  13243. #if PACKETVER <= 20160302
  13244. int cmd = 0xa14;
  13245. #else
  13246. int cmd = 0xa51;
  13247. #endif
  13248. WFIFOHEAD(fd, packet_len(cmd));
  13249. WFIFOW(fd, 0) = cmd;
  13250. WFIFOL(fd, 2) = char_id;
  13251. WFIFOW(fd, 6) = class_;
  13252. WFIFOW(fd, 8) = level;
  13253. #if PACKETVER >= 20160302
  13254. strncpy(WFIFOCP(fd, 10), name, NAME_LENGTH);
  13255. #endif
  13256. WFIFOSET(fd, packet_len(cmd));
  13257. }
  13258. /// Request information about the recipient
  13259. /// 0a13 <name>.24B (CZ_CHECK_RECEIVE_CHARACTER_NAME)
  13260. void clif_parse_Mail_Receiver_Check(int fd, struct map_session_data *sd) {
  13261. static char name[NAME_LENGTH];
  13262. safestrncpy(name, RFIFOCP(fd, 2), NAME_LENGTH);
  13263. intif_mail_checkreceiver(sd, name);
  13264. }
  13265. /// Request to receive mail's attachment.
  13266. /// 0244 <mail id>.L (CZ_MAIL_GET_ITEM)
  13267. /// 09f1 <mail id>.Q <mail tab>.B (CZ_REQ_ZENY_FROM_MAIL)
  13268. /// 09f3 <mail id>.Q <mail tab>.B (CZ_REQ_ITEM_FROM_MAIL)
  13269. void clif_parse_Mail_getattach( int fd, struct map_session_data *sd ){
  13270. int i;
  13271. struct mail_message* msg;
  13272. #if PACKETVER < 20150513
  13273. int mail_id = RFIFOL(fd, packet_db[RFIFOW(fd, 0)].pos[0]);
  13274. int attachment = MAIL_ATT_ALL;
  13275. #else
  13276. uint16 packet_id = RFIFOW(fd, 0);
  13277. int mail_id = (int)RFIFOQ(fd, 2);
  13278. //int openType = RFIFOB(fd, 10);
  13279. int attachment = packet_id == 0x9f1 ? MAIL_ATT_ZENY : packet_id == 0x9f3 ? MAIL_ATT_ITEM : MAIL_ATT_NONE;
  13280. #endif
  13281. if( !chrif_isconnected() )
  13282. return;
  13283. if( mail_id <= 0 )
  13284. return;
  13285. if( mail_invalid_operation(sd) )
  13286. return;
  13287. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13288. if( i == MAIL_MAX_INBOX )
  13289. return;
  13290. msg = &sd->mail.inbox.msg[i];
  13291. if( attachment&MAIL_ATT_ZENY && msg->zeny < 1 ){
  13292. attachment &= ~MAIL_ATT_ZENY;
  13293. }
  13294. if( attachment&MAIL_ATT_ITEM ){
  13295. ARR_FIND(0, MAIL_MAX_ITEM, i, msg->item[i].nameid > 0 || msg->item[i].amount > 0);
  13296. // No items were found
  13297. if( i == MAIL_MAX_ITEM ){
  13298. attachment &= ~MAIL_ATT_ITEM;
  13299. }
  13300. }
  13301. // Either no attachment requested at all or there are no zeny or items in the mail
  13302. if( attachment == MAIL_ATT_NONE ){
  13303. return;
  13304. }
  13305. if( attachment&MAIL_ATT_ZENY ){
  13306. if( msg->zeny + sd->status.zeny > MAX_ZENY ){
  13307. clif_mail_getattachment(sd, msg, 1, MAIL_ATT_ZENY); //too many zeny
  13308. return;
  13309. }else{
  13310. // To make sure another request fails
  13311. msg->zeny = 0;
  13312. }
  13313. }
  13314. if( attachment&MAIL_ATT_ITEM ){
  13315. int new_ = 0, totalweight = 0;
  13316. for( i = 0; i < MAIL_MAX_ITEM; i++ ){
  13317. struct item* item = &msg->item[i];
  13318. if( item->nameid > 0 && item->amount > 0 ){
  13319. struct item_data *data;
  13320. if((data = itemdb_exists(item->nameid)) == NULL)
  13321. continue;
  13322. switch( pc_checkadditem(sd, item->nameid, item->amount) ){
  13323. case CHKADDITEM_NEW:
  13324. new_++;
  13325. break;
  13326. case CHKADDITEM_OVERAMOUNT:
  13327. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13328. return;
  13329. }
  13330. totalweight += data->weight * item->amount;
  13331. }
  13332. }
  13333. if( ( totalweight + sd->weight ) > sd->max_weight ){
  13334. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13335. return;
  13336. }else if( pc_inventoryblank(sd) < new_ ){
  13337. clif_mail_getattachment(sd, msg, 2, MAIL_ATT_ITEM);
  13338. return;
  13339. }
  13340. // To make sure another request fails
  13341. memset(msg->item, 0, MAIL_MAX_ITEM*sizeof(struct item));
  13342. }
  13343. intif_mail_getattach(sd,msg, (enum mail_attachment_type)attachment);
  13344. clif_Mail_read(sd, mail_id);
  13345. }
  13346. /// Request to delete a mail.
  13347. /// 0243 <mail id>.L (CZ_MAIL_DELETE)
  13348. /// 09f5 <mail tab>.B <mail id>.Q (CZ_REQ_DELETE_MAIL)
  13349. void clif_parse_Mail_delete(int fd, struct map_session_data *sd){
  13350. #if PACKETVER < 20150513
  13351. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13352. #else
  13353. //int openType = RFIFOB(fd, 2);
  13354. int mail_id = (int)RFIFOQ(fd, 3);
  13355. #endif
  13356. int i, j;
  13357. if( !chrif_isconnected() )
  13358. return;
  13359. if( mail_id <= 0 )
  13360. return;
  13361. if( mail_invalid_operation(sd) )
  13362. return;
  13363. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13364. if (i < MAIL_MAX_INBOX) {
  13365. struct mail_message *msg = &sd->mail.inbox.msg[i];
  13366. // can't delete mail without removing zeny first
  13367. if( msg->zeny > 0 ){
  13368. clif_mail_delete(sd, msg, false);
  13369. return;
  13370. }
  13371. // can't delete mail without removing attachment(s) first
  13372. for( j = 0; j < MAIL_MAX_ITEM; j++ ){
  13373. if( msg->item[j].nameid > 0 && msg->item[j].amount > 0 ){
  13374. clif_mail_delete(sd, msg, false);
  13375. return;
  13376. }
  13377. }
  13378. if( intif_Mail_delete(sd->status.char_id, mail_id) && msg->status == MAIL_UNREAD ){
  13379. sd->mail.inbox.unread--;
  13380. clif_Mail_new(sd,0,NULL,NULL);
  13381. }
  13382. }
  13383. }
  13384. /// Request to return a mail (CZ_REQ_MAIL_RETURN).
  13385. /// 0273 <mail id>.L <receive name>.24B
  13386. void clif_parse_Mail_return(int fd, struct map_session_data *sd){
  13387. int mail_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13388. //char *rec_name = RFIFOP(fd,packet_db[RFIFOW(fd,0)].pos[1]);
  13389. int i;
  13390. if( mail_id <= 0 )
  13391. return;
  13392. if( mail_invalid_operation(sd) )
  13393. return;
  13394. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  13395. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  13396. intif_Mail_return(sd->status.char_id, mail_id);
  13397. else
  13398. clif_Mail_return(sd->fd, mail_id, 1);
  13399. }
  13400. /// Request to add an item or Zeny to mail.
  13401. /// 0247 <index>.W <amount>.L (CZ_MAIL_ADD_ITEM)
  13402. /// 0a04 <index>.W <amount>.W (CZ_REQ_ADD_ITEM_TO_MAIL)
  13403. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd){
  13404. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13405. int idx = RFIFOW(fd,info->pos[0]);
  13406. #if PACKETVER < 20150513
  13407. int amount = RFIFOL(fd,info->pos[1]);
  13408. #else
  13409. int amount = RFIFOW(fd,info->pos[1]);
  13410. #endif
  13411. unsigned char flag;
  13412. if( !chrif_isconnected() )
  13413. return;
  13414. if (idx < 0 || amount < 0)
  13415. return;
  13416. flag = mail_setitem(sd, idx, amount);
  13417. clif_Mail_setattachment(sd,idx,amount,flag);
  13418. }
  13419. /// Remove an item from a mail
  13420. /// 0a07 <result>.B <index>.W <amount>.W <weight>.W
  13421. void clif_mail_removeitem( struct map_session_data* sd, bool success, int index, int amount ){
  13422. int fd = sd->fd;
  13423. WFIFOHEAD(fd, 9);
  13424. WFIFOW(fd, 0) = 0xa07;
  13425. WFIFOB(fd, 2) = success;
  13426. WFIFOW(fd, 3) = index;
  13427. WFIFOW(fd, 5) = amount;
  13428. WFIFOW(fd, 7) = 0; // TODO: which weight? item weight? removed weight? remaining weight?
  13429. WFIFOSET(fd, 9);
  13430. }
  13431. /// Request to reset mail item and/or Zeny
  13432. /// 0246 <type>.W (CZ_MAIL_RESET_ITEM)
  13433. /// type:
  13434. /// 0 = reset all
  13435. /// 1 = remove item
  13436. /// 2 = remove zeny
  13437. /// 0a06 <index>.W <amount>.W (CZ_REQ_REMOVE_ITEM_MAIL)
  13438. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  13439. {
  13440. #if PACKETVER < 20150513
  13441. int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13442. if (type == 0 || type == 1)
  13443. mail_removeitem(sd, 0, sd->mail.item[0].index, sd->mail.item[0].amount);
  13444. if (type == 0 || type == 2)
  13445. mail_removezeny(sd, false);
  13446. #else
  13447. uint16 index = RFIFOW(fd, 2);
  13448. uint16 count = RFIFOW(fd, 4);
  13449. mail_removeitem(sd,0,index,count);
  13450. #endif
  13451. }
  13452. /// Request to send mail
  13453. /// 0248 <packet len>.W <recipient>.24B <title>.40B <body len>.B <body>.?B (CZ_MAIL_SEND)
  13454. /// 09ec <packet len>.W <recipient>.24B <sender>.24B <zeny>.Q <title length>.W <body length>.W <title>.?B <body>.?B (CZ_REQ_WRITE_MAIL)
  13455. /// 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)
  13456. void clif_parse_Mail_send(int fd, struct map_session_data *sd){
  13457. #if PACKETVER < 20150513
  13458. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13459. if( !chrif_isconnected() )
  13460. return;
  13461. if( RFIFOW(fd,info->pos[0]) < 69 ) {
  13462. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  13463. return;
  13464. }
  13465. mail_send(sd, RFIFOCP(fd,info->pos[1]), RFIFOCP(fd,info->pos[2]), RFIFOCP(fd,info->pos[4]), RFIFOB(fd,info->pos[3]));
  13466. #else
  13467. unsigned short length;
  13468. static char receiver[NAME_LENGTH];
  13469. static char sender[NAME_LENGTH];
  13470. char *title;
  13471. char *text;
  13472. uint64 zeny;
  13473. uint16 titleLength;
  13474. uint16 textLength;
  13475. length = RFIFOW(fd, 2);
  13476. if( length < 0x3e ){
  13477. ShowWarning("Too short...\n");
  13478. clif_Mail_send(sd, WRITE_MAIL_FAILED);
  13479. return;
  13480. }
  13481. // Forged request without a begin writing packet?
  13482. if( !sd->state.mail_writing ){
  13483. return; // Ignore it
  13484. }
  13485. safestrncpy(receiver, RFIFOCP(fd, 4), NAME_LENGTH);
  13486. safestrncpy(sender, RFIFOCP(fd, 28), NAME_LENGTH);
  13487. zeny = RFIFOQ(fd, 52);
  13488. titleLength = RFIFOW(fd, 60);
  13489. textLength = RFIFOW(fd, 62);
  13490. title = (char*)aMalloc(titleLength);
  13491. text = (char*)aMalloc(textLength);
  13492. #if PACKETVER <= 20160330
  13493. safestrncpy(title, RFIFOCP(fd, 64), titleLength);
  13494. safestrncpy(text, RFIFOCP(fd, 64 + titleLength), textLength);
  13495. #else
  13496. // 64 = <char id>.L
  13497. safestrncpy(title, RFIFOCP(fd, 68), titleLength);
  13498. safestrncpy(text, RFIFOCP(fd, 68 + titleLength), textLength);
  13499. #endif
  13500. if( zeny > 0 ){
  13501. if( mail_setitem(sd,0,(uint32)zeny) != MAIL_ATTACH_SUCCESS ){
  13502. clif_Mail_send(sd,WRITE_MAIL_FAILED);
  13503. return;
  13504. }
  13505. }
  13506. mail_send(sd, receiver, title, text, textLength);
  13507. aFree(title);
  13508. aFree(text);
  13509. #endif
  13510. }
  13511. /// AUCTION SYSTEM
  13512. /// By Zephyrus
  13513. ///
  13514. /// Opens/closes the auction window (ZC_AUCTION_WINDOWS).
  13515. /// 025f <type>.L
  13516. /// type:
  13517. /// 0 = open
  13518. /// 1 = close
  13519. void clif_Auction_openwindow(struct map_session_data *sd)
  13520. {
  13521. int fd = sd->fd;
  13522. if( sd->state.storage_flag || sd->state.vending || sd->state.buyingstore || sd->state.trading )
  13523. return;
  13524. if( !battle_config.feature_auction )
  13525. return;
  13526. WFIFOHEAD(fd,packet_len(0x25f));
  13527. WFIFOW(fd,0) = 0x25f;
  13528. WFIFOL(fd,2) = 0;
  13529. WFIFOSET(fd,packet_len(0x25f));
  13530. }
  13531. /// Returns auction item search results (ZC_AUCTION_ITEM_REQ_SEARCH).
  13532. /// 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 }*
  13533. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  13534. {
  13535. int i, fd = sd->fd, len = sizeof(struct auction_data);
  13536. struct auction_data auction;
  13537. struct item_data *item;
  13538. WFIFOHEAD(fd,12 + (count * 83));
  13539. WFIFOW(fd,0) = 0x252;
  13540. WFIFOW(fd,2) = 12 + (count * 83);
  13541. WFIFOL(fd,4) = pages;
  13542. WFIFOL(fd,8) = count;
  13543. for( i = 0; i < count; i++ ) {
  13544. int k = 12 + (i * 83);
  13545. memcpy(&auction, RBUFP(buf,i * len), len);
  13546. WFIFOL(fd,k) = auction.auction_id;
  13547. safestrncpy(WFIFOCP(fd,4+k), auction.seller_name, NAME_LENGTH);
  13548. if( (item = itemdb_exists(auction.item.nameid)) != NULL && item->view_id > 0 )
  13549. WFIFOW(fd,28+k) = item->view_id;
  13550. else
  13551. WFIFOW(fd,28+k) = auction.item.nameid;
  13552. WFIFOL(fd,30+k) = auction.type;
  13553. WFIFOW(fd,34+k) = auction.item.amount; // Always 1
  13554. WFIFOB(fd,36+k) = auction.item.identify;
  13555. WFIFOB(fd,37+k) = auction.item.attribute;
  13556. WFIFOB(fd,38+k) = auction.item.refine;
  13557. WFIFOW(fd,39+k) = auction.item.card[0];
  13558. WFIFOW(fd,41+k) = auction.item.card[1];
  13559. WFIFOW(fd,43+k) = auction.item.card[2];
  13560. WFIFOW(fd,45+k) = auction.item.card[3];
  13561. WFIFOL(fd,47+k) = auction.price;
  13562. WFIFOL(fd,51+k) = auction.buynow;
  13563. safestrncpy(WFIFOCP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  13564. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  13565. }
  13566. WFIFOSET(fd,WFIFOW(fd,2));
  13567. }
  13568. /// Result from request to add an item (ZC_ACK_AUCTION_ADD_ITEM).
  13569. /// 0256 <index>.W <result>.B
  13570. /// result:
  13571. /// 0 = success
  13572. /// 1 = failure
  13573. static void clif_Auction_setitem(int fd, int index, bool fail)
  13574. {
  13575. WFIFOHEAD(fd,packet_len(0x256));
  13576. WFIFOW(fd,0) = 0x256;
  13577. WFIFOW(fd,2) = index;
  13578. WFIFOB(fd,4) = fail;
  13579. WFIFOSET(fd,packet_len(0x256));
  13580. }
  13581. /// Request to initialize 'new auction' data (CZ_AUCTION_CREATE).
  13582. /// 024b <type>.W
  13583. /// type:
  13584. /// 0 = create (any other action in auction window)
  13585. /// 1 = cancel (cancel pressed on register tab)
  13586. /// ? = junk, uninitialized value (ex. when switching between list filters)
  13587. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd){
  13588. //int type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13589. if( sd->auction.amount > 0 )
  13590. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  13591. sd->auction.amount = 0;
  13592. }
  13593. /// Request to add an item to the action (CZ_AUCTION_ADD_ITEM).
  13594. /// 024c <index>.W <count>.L
  13595. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd){
  13596. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13597. int idx = RFIFOW(fd,info->pos[0]) - 2;
  13598. int amount = RFIFOL(fd,info->pos[1]); // Always 1
  13599. struct item_data *item;
  13600. if( !battle_config.feature_auction )
  13601. return;
  13602. if( sd->auction.amount > 0 )
  13603. sd->auction.amount = 0;
  13604. if( idx < 0 || idx >= MAX_INVENTORY ) {
  13605. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  13606. return;
  13607. }
  13608. 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.
  13609. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  13610. return;
  13611. }
  13612. 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) )
  13613. { // Consumable or pets are not allowed
  13614. clif_Auction_setitem(sd->fd, idx, true);
  13615. return;
  13616. }
  13617. if( !pc_can_give_items(sd) || sd->inventory.u.items_inventory[idx].expire_time ||
  13618. !sd->inventory.u.items_inventory[idx].identify ||
  13619. (sd->inventory.u.items_inventory[idx].bound && !pc_can_give_bounded_items(sd)) ||
  13620. !itemdb_available(sd->inventory.u.items_inventory[idx].nameid) ||
  13621. !itemdb_canauction(&sd->inventory.u.items_inventory[idx],pc_get_group_level(sd)) ) { // Quest Item or something else
  13622. clif_Auction_setitem(sd->fd, idx, true);
  13623. return;
  13624. }
  13625. sd->auction.index = idx;
  13626. sd->auction.amount = amount;
  13627. clif_Auction_setitem(fd, idx + 2, false);
  13628. }
  13629. /// Result from an auction action (ZC_AUCTION_RESULT).
  13630. /// 0250 <result>.B
  13631. /// result:
  13632. /// 0 = You have failed to bid into the auction
  13633. /// 1 = You have successfully bid in the auction
  13634. /// 2 = The auction has been canceled
  13635. /// 3 = An auction with at least one bidder cannot be canceled
  13636. /// 4 = You cannot register more than 5 items in an auction at a time
  13637. /// 5 = You do not have enough Zeny to pay the Auction Fee
  13638. /// 6 = You have won the auction
  13639. /// 7 = You have failed to win the auction
  13640. /// 8 = You do not have enough Zeny
  13641. /// 9 = You cannot place more than 5 bids at a time
  13642. void clif_Auction_message(int fd, unsigned char flag)
  13643. {
  13644. WFIFOHEAD(fd,packet_len(0x250));
  13645. WFIFOW(fd,0) = 0x250;
  13646. WFIFOB(fd,2) = flag;
  13647. WFIFOSET(fd,packet_len(0x250));
  13648. }
  13649. /// Result of the auction close request (ZC_AUCTION_ACK_MY_SELL_STOP).
  13650. /// 025e <result>.W
  13651. /// result:
  13652. /// 0 = You have ended the auction
  13653. /// 1 = You cannot end the auction
  13654. /// 2 = Auction ID is incorrect
  13655. void clif_Auction_close(int fd, unsigned char flag)
  13656. {
  13657. WFIFOHEAD(fd,packet_len(0x25e));
  13658. WFIFOW(fd,0) = 0x25d; // BUG: The client identifies this packet as 0x25d (CZ_AUCTION_REQ_MY_SELL_STOP)
  13659. WFIFOW(fd,2) = flag;
  13660. WFIFOSET(fd,packet_len(0x25e));
  13661. }
  13662. /// Request to add an auction (CZ_AUCTION_ADD).
  13663. /// 024d <now money>.L <max money>.L <delete hour>.W
  13664. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  13665. {
  13666. struct auction_data auction;
  13667. struct item_data *item;
  13668. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13669. if( !battle_config.feature_auction )
  13670. return;
  13671. auction.price = RFIFOL(fd,info->pos[0]);
  13672. auction.buynow = RFIFOL(fd,info->pos[1]);
  13673. auction.hours = RFIFOW(fd,info->pos[2]);
  13674. // Invalid Situations...
  13675. if( sd->auction.amount < 1 ) {
  13676. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  13677. return;
  13678. }
  13679. if( auction.price >= auction.buynow ) {
  13680. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  13681. return;
  13682. }
  13683. if( auction.hours < 1 || auction.hours > 48 ) {
  13684. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  13685. return;
  13686. }
  13687. // Auction checks...
  13688. if( sd->inventory.u.items_inventory[sd->auction.index].bound && !pc_can_give_bounded_items(sd) ) {
  13689. clif_displaymessage(sd->fd, msg_txt(sd,293));
  13690. clif_Auction_message(fd, 2); // The auction has been canceled
  13691. return;
  13692. }
  13693. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) ) {
  13694. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  13695. return;
  13696. }
  13697. if( auction.buynow > battle_config.auction_maximumprice ) { // Zeny Limits
  13698. auction.buynow = battle_config.auction_maximumprice;
  13699. if( auction.price >= auction.buynow )
  13700. auction.price = auction.buynow - 1;
  13701. }
  13702. auction.auction_id = 0;
  13703. auction.seller_id = sd->status.char_id;
  13704. safestrncpy(auction.seller_name, sd->status.name, sizeof(auction.seller_name));
  13705. auction.buyer_id = 0;
  13706. memset(auction.buyer_name, '\0', sizeof(auction.buyer_name));
  13707. if( sd->inventory.u.items_inventory[sd->auction.index].nameid == 0 || sd->inventory.u.items_inventory[sd->auction.index].amount < sd->auction.amount )
  13708. {
  13709. clif_Auction_message(fd, 2); // The auction has been canceled
  13710. return;
  13711. }
  13712. if( (item = itemdb_exists(sd->inventory.u.items_inventory[sd->auction.index].nameid)) == NULL )
  13713. { // Just in case
  13714. clif_Auction_message(fd, 2); // The auction has been canceled
  13715. return;
  13716. }
  13717. safestrncpy(auction.item_name, item->jname, sizeof(auction.item_name));
  13718. auction.type = item->type;
  13719. memcpy(&auction.item, &sd->inventory.u.items_inventory[sd->auction.index], sizeof(struct item));
  13720. auction.item.amount = 1;
  13721. auction.timestamp = 0;
  13722. if( !intif_Auction_register(&auction) )
  13723. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  13724. else
  13725. {
  13726. int zeny = auction.hours*battle_config.auction_feeperhour;
  13727. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6, LOG_TYPE_AUCTION);
  13728. sd->auction.amount = 0;
  13729. pc_payzeny(sd, zeny, LOG_TYPE_AUCTION, NULL);
  13730. }
  13731. }
  13732. /// Cancels an auction (CZ_AUCTION_ADD_CANCEL).
  13733. /// 024e <auction id>.L
  13734. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd){
  13735. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13736. intif_Auction_cancel(sd->status.char_id, auction_id);
  13737. }
  13738. /// Closes an auction (CZ_AUCTION_REQ_MY_SELL_STOP).
  13739. /// 025d <auction id>.L
  13740. void clif_parse_Auction_close(int fd, struct map_session_data *sd){
  13741. unsigned int auction_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  13742. intif_Auction_close(sd->status.char_id, auction_id);
  13743. }
  13744. /// Places a bid on an auction (CZ_AUCTION_BUY).
  13745. /// 024f <auction id>.L <money>.L
  13746. void clif_parse_Auction_bid(int fd, struct map_session_data *sd){
  13747. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13748. unsigned int auction_id = RFIFOL(fd,info->pos[0]);
  13749. int bid = RFIFOL(fd,info->pos[1]);
  13750. if( !pc_can_give_items(sd) ) { //They aren't supposed to give zeny [Inkfish]
  13751. clif_displaymessage(sd->fd, msg_txt(sd,246));
  13752. return;
  13753. }
  13754. if( bid <= 0 )
  13755. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13756. else if( bid > sd->status.zeny )
  13757. clif_Auction_message(fd, 8); // You do not have enough zeny
  13758. else if ( CheckForCharServer() ) // char server is down (bugreport:1138)
  13759. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  13760. else {
  13761. pc_payzeny(sd, bid, LOG_TYPE_AUCTION, NULL);
  13762. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  13763. }
  13764. }
  13765. /// Auction Search (CZ_AUCTION_ITEM_SEARCH).
  13766. /// 0251 <search type>.W <auction id>.L <search text>.24B <page number>.W
  13767. /// search type:
  13768. /// 0 = armor
  13769. /// 1 = weapon
  13770. /// 2 = card
  13771. /// 3 = misc
  13772. /// 4 = name search
  13773. /// 5 = auction id search
  13774. void clif_parse_Auction_search(int fd, struct map_session_data* sd){
  13775. char search_text[NAME_LENGTH];
  13776. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  13777. short type = RFIFOW(fd,info->pos[0]);
  13778. int price = RFIFOL(fd,info->pos[1]); // FIXME: bug #5071
  13779. int page = RFIFOW(fd,info->pos[3]);
  13780. if( !battle_config.feature_auction )
  13781. return;
  13782. clif_parse_Auction_cancelreg(fd, sd);
  13783. safestrncpy(search_text, RFIFOCP(fd,info->pos[2]), sizeof(search_text));
  13784. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  13785. }
  13786. /// Requests list of own currently active bids or auctions (CZ_AUCTION_REQ_MY_INFO).
  13787. /// 025c <type>.W
  13788. /// type:
  13789. /// 0 = sell (own auctions)
  13790. /// 1 = buy (own bids)
  13791. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  13792. {
  13793. short type = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) + 6;
  13794. if( !battle_config.feature_auction )
  13795. return;
  13796. clif_parse_Auction_cancelreg(fd, sd);
  13797. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  13798. }
  13799. /// CASH/POINT SHOP
  13800. ///
  13801. void clif_cashshop_open( struct map_session_data* sd ){
  13802. WFIFOHEAD( sd->fd, 10 );
  13803. WFIFOW( sd->fd, 0 ) = 0x845;
  13804. WFIFOL( sd->fd, 2 ) = sd->cashPoints;
  13805. WFIFOL( sd->fd, 6 ) = sd->kafraPoints;
  13806. WFIFOSET( sd->fd, 10 );
  13807. }
  13808. void clif_parse_cashshop_open_request( int fd, struct map_session_data* sd ){
  13809. sd->state.cashshop_open = true;
  13810. sd->npc_shopid = -1; // Set npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13811. clif_cashshop_open( sd );
  13812. }
  13813. void clif_parse_cashshop_close( int fd, struct map_session_data* sd ){
  13814. sd->state.cashshop_open = false;
  13815. sd->npc_shopid = 0; // Reset npc_shopid when using cash shop from "cash shop" button [Aelys|Susu] bugreport:96
  13816. // No need to do anything here
  13817. }
  13818. //0846 <tabid>.W (CZ_REQ_SE_CASH_TAB_CODE))
  13819. //08c0 <len>.W <openIdentity>.L <itemcount>.W (ZC_ACK_SE_CASH_ITEM_LIST2)
  13820. void clif_parse_CashShopReqTab(int fd, struct map_session_data *sd) {
  13821. short tab = RFIFOW(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  13822. int j;
  13823. if( tab < 0 || tab >= CASHSHOP_TAB_MAX )
  13824. return;
  13825. WFIFOHEAD(fd, 10 + ( cash_shop_items[tab].count * 6 ) );
  13826. WFIFOW(fd, 0) = 0x8c0;
  13827. WFIFOW(fd, 2) = 10 + ( cash_shop_items[tab].count * 6 );
  13828. WFIFOL(fd, 4) = tab;
  13829. WFIFOW(fd, 8) = cash_shop_items[tab].count;
  13830. for( j = 0; j < cash_shop_items[tab].count; j++ ) {
  13831. struct item_data *id = itemdb_search(cash_shop_items[tab].item[j]->nameid);
  13832. WFIFOW(fd, 10 + ( 6 * j ) ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[j]->nameid;
  13833. WFIFOL(fd, 12 + ( 6 * j ) ) = cash_shop_items[tab].item[j]->price;
  13834. }
  13835. WFIFOSET(fd, 10 + ( cash_shop_items[tab].count * 6 ));
  13836. }
  13837. //08ca <len>.W <itemcount> W <tabcode>.W (ZC_ACK_SCHEDULER_CASHITEM)
  13838. void clif_cashshop_list( int fd ){
  13839. int tab;
  13840. for( tab = CASHSHOP_TAB_NEW; tab < CASHSHOP_TAB_MAX; tab++ ){
  13841. int length = 8 + cash_shop_items[tab].count * 6;
  13842. int i, offset;
  13843. WFIFOHEAD( fd, length );
  13844. WFIFOW( fd, 0 ) = 0x8ca;
  13845. WFIFOW( fd, 2 ) = length;
  13846. WFIFOW( fd, 4 ) = cash_shop_items[tab].count;
  13847. WFIFOW( fd, 6 ) = tab;
  13848. for( i = 0, offset = 8; i < cash_shop_items[tab].count; i++, offset += 6 ){
  13849. struct item_data *id = itemdb_search(cash_shop_items[tab].item[i]->nameid);
  13850. WFIFOW( fd, offset ) = (id->view_id) ? id->view_id : cash_shop_items[tab].item[i]->nameid;
  13851. WFIFOL( fd, offset + 2 ) = cash_shop_items[tab].item[i]->price;
  13852. }
  13853. WFIFOSET( fd, length );
  13854. }
  13855. }
  13856. void clif_parse_cashshop_list_request( int fd, struct map_session_data* sd ){
  13857. if( !sd->status.cashshop_sent ) {
  13858. clif_cashshop_list( fd );
  13859. #if PACKETVER_SUPPORTS_SALES
  13860. sale_notify_login(sd);
  13861. #endif
  13862. sd->status.cashshop_sent = true;
  13863. }
  13864. }
  13865. /// List of items offered in a cash shop (ZC_PC_CASH_POINT_ITEMLIST).
  13866. /// 0287 <packet len>.W <cash point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }*
  13867. /// 0287 <packet len>.W <cash point>.L <kafra point>.L { <sell price>.L <discount price>.L <item type>.B <name id>.W }* (PACKETVER >= 20070711)
  13868. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  13869. {
  13870. int fd, i, cost[2] = { 0, 0 };
  13871. #if PACKETVER < 20070711
  13872. const int offset = 8;
  13873. #else
  13874. const int offset = 12;
  13875. #endif
  13876. nullpo_retv(sd);
  13877. nullpo_retv(nd);
  13878. fd = sd->fd;
  13879. sd->npc_shopid = nd->bl.id;
  13880. npc_shop_currency_type(sd, nd, cost, true);
  13881. WFIFOHEAD(fd,offset+nd->u.shop.count*11);
  13882. WFIFOW(fd,0) = 0x287;
  13883. WFIFOW(fd,2) = offset+nd->u.shop.count*11;
  13884. WFIFOL(fd,4) = cost[0];
  13885. #if PACKETVER >= 20070711
  13886. WFIFOL(fd,8) = cost[1];
  13887. #endif
  13888. for( i = 0; i < nd->u.shop.count; i++ ) {
  13889. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  13890. WFIFOL(fd,offset+0+i*11) = nd->u.shop.shop_item[i].value;
  13891. WFIFOL(fd,offset+4+i*11) = nd->u.shop.shop_item[i].value; // Discount Price
  13892. WFIFOB(fd,offset+8+i*11) = itemtype(id->nameid);
  13893. WFIFOW(fd,offset+9+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  13894. }
  13895. WFIFOSET(fd,WFIFOW(fd,2));
  13896. }
  13897. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE).
  13898. /// 0289 <cash point>.L <error>.W
  13899. /// 0289 <cash point>.L <kafra point>.L <error>.W (PACKETVER >= 20070711)
  13900. /// error:
  13901. /// 0 = The deal has successfully completed. (ERROR_TYPE_NONE)
  13902. /// 1 = The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  13903. /// 2 = The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  13904. /// 3 = You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  13905. /// 4 = You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  13906. /// 5 = The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  13907. /// 6 = You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  13908. /// 7 = You can purchase up to 10 items. (ERROR_TYPE_AMOUNT)
  13909. /// 8 = Some items could not be purchased. (ERROR_TYPE_PURCHASE_FAIL)
  13910. void clif_cashshop_ack(struct map_session_data* sd, int error)
  13911. {
  13912. int fd, cost[2] = { 0, 0 };
  13913. struct npc_data *nd;
  13914. nullpo_retv(sd);
  13915. fd = sd->fd;
  13916. nd = map_id2nd(sd->npc_shopid);
  13917. npc_shop_currency_type(sd, nd, cost, false);
  13918. WFIFOHEAD(fd, packet_len(0x289));
  13919. WFIFOW(fd,0) = 0x289;
  13920. WFIFOL(fd,2) = cost[0];
  13921. #if PACKETVER < 20070711
  13922. WFIFOW(fd,6) = TOW(error);
  13923. #else
  13924. WFIFOL(fd,6) = cost[1];
  13925. WFIFOW(fd,10) = TOW(error);
  13926. #endif
  13927. WFIFOSET(fd, packet_len(0x289));
  13928. }
  13929. void clif_cashshop_result( struct map_session_data *sd, unsigned short item_id, uint16 result ){
  13930. WFIFOHEAD( sd->fd, 16 );
  13931. WFIFOW( sd->fd, 0 ) = 0x849;
  13932. WFIFOL( sd->fd, 2 ) = item_id;
  13933. WFIFOW( sd->fd, 6 ) = result;
  13934. WFIFOL( sd->fd, 8 ) = sd->cashPoints;
  13935. WFIFOL( sd->fd, 12 ) = sd->kafraPoints;
  13936. WFIFOSET( sd->fd, 16 );
  13937. }
  13938. /// Request to buy item(s) from cash shop (CZ_PC_BUY_CASH_POINT_ITEM).
  13939. /// 0288 <name id>.W <amount>.W
  13940. /// 0288 <name id>.W <amount>.W <kafra points>.L (PACKETVER >= 20070711)
  13941. /// 0288 <packet len>.W <kafra points>.L <count>.W { <amount>.W <name id>.W }.4B*count (PACKETVER >= 20100803)
  13942. /// 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)
  13943. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd){
  13944. struct s_packet_db* info;
  13945. int cmd = RFIFOW(fd,0);
  13946. nullpo_retv(sd);
  13947. info = &packet_db[cmd];
  13948. if( sd->state.trading || !sd->npc_shopid ) {
  13949. clif_cashshop_ack(sd,1);
  13950. return;
  13951. }
  13952. else {
  13953. #if PACKETVER < 20101116
  13954. short nameid = RFIFOW(fd,info->pos[0]);
  13955. short amount = RFIFOW(fd,info->pos[1]);
  13956. int points = RFIFOL(fd,info->pos[2]);
  13957. clif_cashshop_ack(sd,npc_cashshop_buy(sd, nameid, amount, points));
  13958. #else
  13959. int s_itl = (cmd==0x848)?10:4; //item _list size (depend on cmd even for 2013+)
  13960. int len = RFIFOW(fd,info->pos[0]);
  13961. int points = RFIFOL(fd,info->pos[1]);
  13962. int count = RFIFOW(fd,info->pos[2]);
  13963. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  13964. if( len < 10 || len != 10 + count * s_itl){
  13965. ShowWarning("Player %u sent incorrect cash shop buy packet (len %u:%u)!\n", sd->status.char_id, len, 10 + count * s_itl);
  13966. return;
  13967. }
  13968. if(cmd==0x848){
  13969. if (cashshop_buylist( sd, points, count, item_list))
  13970. clif_cashshop_ack(sd,0);
  13971. return;
  13972. } else {
  13973. clif_cashshop_ack(sd,npc_cashshop_buylist(sd,points,count,item_list));
  13974. return;
  13975. }
  13976. #endif
  13977. }
  13978. }
  13979. /// Adoption System
  13980. ///
  13981. /// Adoption message (ZC_BABYMSG).
  13982. /// 0216 <msg>.L
  13983. /// msg:
  13984. /// ADOPT_REPLY_MORE_CHILDREN = "You cannot adopt more than 1 child."
  13985. /// ADOPT_REPLY_LEVEL_70 = "You must be at least character level 70 in order to adopt someone."
  13986. /// ADOPT_REPLY_MARRIED = "You cannot adopt a married person."
  13987. void clif_Adopt_reply(struct map_session_data *sd, int type)
  13988. {
  13989. int fd = sd->fd;
  13990. WFIFOHEAD(fd,6);
  13991. WFIFOW(fd,0) = 0x216;
  13992. WFIFOL(fd,2) = type;
  13993. WFIFOSET(fd,6);
  13994. }
  13995. /// Adoption confirmation (ZC_REQ_BABY).
  13996. /// 01f6 <account id>.L <char id>.L <name>.B
  13997. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  13998. {
  13999. int fd = sd->fd;
  14000. WFIFOHEAD(fd,34);
  14001. WFIFOW(fd,0) = 0x1f6;
  14002. WFIFOL(fd,2) = src->status.account_id;
  14003. WFIFOL(fd,6) = p_id;
  14004. safestrncpy(WFIFOCP(fd,10), src->status.name, NAME_LENGTH);
  14005. WFIFOSET(fd,34);
  14006. }
  14007. /// Request to adopt a player (CZ_REQ_JOIN_BABY).
  14008. /// 01f9 <account id>.L
  14009. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  14010. {
  14011. TBL_PC *tsd = map_id2sd(RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]));
  14012. TBL_PC *p_sd = map_charid2sd(sd->status.partner_id);
  14013. if( pc_try_adopt(sd, p_sd, tsd) == ADOPT_ALLOWED )
  14014. {
  14015. tsd->adopt_invite = sd->status.account_id;
  14016. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  14017. }
  14018. }
  14019. /// Answer to adopt confirmation (CZ_JOIN_BABY).
  14020. /// 01f7 <account id>.L <char id>.L <answer>.L
  14021. /// answer:
  14022. /// 0 = rejected
  14023. /// 1 = accepted
  14024. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd){
  14025. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14026. int p1_id = RFIFOL(fd,info->pos[0]);
  14027. int p2_id = RFIFOL(fd,info->pos[1]);
  14028. int result = RFIFOL(fd,info->pos[2]);
  14029. struct map_session_data* p1_sd = map_id2sd(p1_id);
  14030. struct map_session_data* p2_sd = map_id2sd(p2_id);
  14031. int pid = sd->adopt_invite;
  14032. sd->adopt_invite = 0;
  14033. if( p1_sd == NULL || p2_sd == NULL )
  14034. return; // Both players need to be online
  14035. if( pid != p1_sd->status.account_id )
  14036. return; // Incorrect values
  14037. if( result == 0 )
  14038. return; // Rejected
  14039. pc_adoption(p1_sd, p2_sd, sd);
  14040. }
  14041. /// Convex Mirror (ZC_BOSS_INFO).
  14042. /// 0293 <infoType>.B <x>.L <y>.L <minHours>.W <minMinutes>.W <maxHours>.W <maxMinutes>.W <monster name>.51B
  14043. /// infoType:
  14044. /// BOSS_INFO_NOT = No boss on this map.
  14045. /// BOSS_INFO_ALIVE = Boss is alive (position update).
  14046. /// BOSS_INFO_ALIVE_WITHMSG = Boss is alive (initial announce).
  14047. /// BOSS_INFO_DEAD = Boss is dead.
  14048. void clif_bossmapinfo(struct map_session_data *sd, struct mob_data *md, enum e_bossmap_info flag)
  14049. {
  14050. int fd = sd->fd;
  14051. WFIFOHEAD(fd,70);
  14052. memset(WFIFOP(fd,0),0,70);
  14053. WFIFOW(fd,0) = 0x293;
  14054. switch (flag) {
  14055. case BOSS_INFO_NOT:
  14056. WFIFOB(fd,2) = BOSS_INFO_NOT;
  14057. // No data required
  14058. break;
  14059. case BOSS_INFO_ALIVE:
  14060. WFIFOB(fd,2) = BOSS_INFO_ALIVE;
  14061. // Update X/Y
  14062. WFIFOL(fd,3) = md->bl.x;
  14063. WFIFOL(fd,7) = md->bl.y;
  14064. break;
  14065. case BOSS_INFO_ALIVE_WITHMSG:
  14066. WFIFOB(fd,2) = BOSS_INFO_ALIVE_WITHMSG;
  14067. // Current X/Y
  14068. WFIFOL(fd,3) = md->bl.x;
  14069. WFIFOL(fd,7) = md->bl.y;
  14070. break;
  14071. case BOSS_INFO_DEAD:
  14072. {
  14073. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  14074. unsigned int seconds;
  14075. int hours, minutes;
  14076. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  14077. hours = seconds / (60 * 60);
  14078. seconds = seconds - (60 * 60 * hours);
  14079. minutes = seconds / 60;
  14080. WFIFOB(fd,2) = BOSS_INFO_DEAD;
  14081. // Add respawn info
  14082. WFIFOW(fd,11) = hours; // Hours
  14083. WFIFOW(fd,13) = minutes; // Minutes
  14084. }
  14085. break;
  14086. }
  14087. if (md != NULL)
  14088. safestrncpy(WFIFOCP(fd,19), md->db->jname, NAME_LENGTH);
  14089. WFIFOSET(fd,70);
  14090. }
  14091. /// Requesting equip of a player (CZ_EQUIPWIN_MICROSCOPE).
  14092. /// 02d6 <account id>.L
  14093. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  14094. {
  14095. int aid = RFIFOL(fd, packet_db[RFIFOW(fd,0)].pos[0]);
  14096. struct map_session_data* tsd = map_id2sd(aid);
  14097. if (!tsd)
  14098. return;
  14099. if( tsd->status.show_equip || pc_has_permission(sd, PC_PERM_VIEW_EQUIPMENT) )
  14100. clif_viewequip_ack(sd, tsd);
  14101. else
  14102. clif_msg(sd, VIEW_EQUIP_FAIL);
  14103. }
  14104. /// Request to a configuration.
  14105. /// 02d8 <type>.L <flag>.L (CZ_CONFIG)
  14106. /// type: see enum e_config_type
  14107. /// flag:
  14108. /// false = disabled
  14109. /// true = enabled
  14110. void clif_parse_configuration( int fd, struct map_session_data* sd ){
  14111. int cmd = RFIFOW(fd,0);
  14112. int type = RFIFOL(fd,packet_db[cmd].pos[0]);
  14113. bool flag = RFIFOL(fd,packet_db[cmd].pos[1]) != 0;
  14114. switch( type ){
  14115. case CONFIG_OPEN_EQUIPMENT_WINDOW:
  14116. sd->status.show_equip = flag;
  14117. break;
  14118. case CONFIG_PET_AUTOFEED:
  14119. // TODO: Implement with pet evolution system
  14120. break;
  14121. case CONFIG_HOMUNCULUS_AUTOFEED:
  14122. // Player can not click this if he does not have a homunculus or it is vaporized
  14123. if( sd->hd == nullptr || sd->hd->homunculus.vaporize || !battle_config.feature_homunculus_autofeed ){
  14124. return;
  14125. }
  14126. sd->hd->homunculus.autofeed = flag;
  14127. break;
  14128. default:
  14129. ShowWarning( "clif_parse_configuration: received unknown configuration type '%d'...\n", type );
  14130. return;
  14131. }
  14132. clif_configuration( sd, static_cast<e_config_type>(type), flag );
  14133. }
  14134. /// Request to change party invitation tick.
  14135. /// value:
  14136. /// 0 = disabled
  14137. /// 1 = enabled
  14138. void clif_parse_PartyTick(int fd, struct map_session_data* sd)
  14139. {
  14140. bool flag = RFIFOB(fd,6) ? true : false;
  14141. sd->status.allow_party = flag;
  14142. clif_partytickack(sd, flag);
  14143. }
  14144. /// Questlog System [Kevin] [Inkfish]
  14145. ///
  14146. /**
  14147. * Safe check to init packet len & quest num for player.
  14148. * @param def_len
  14149. * @param info_len Length of each quest info.
  14150. * @param avail_quests Avail quests that player has.
  14151. * @param limit_out Limit for quest num, to make sure the quest num is still in allowed value.
  14152. * @param len_out Packet length as initial set => def_len + limit_out * info_len.
  14153. **/
  14154. static void clif_quest_len(int def_len, int info_len, int avail_quests, int *limit_out, int *len_out) {
  14155. (*limit_out) = (0xFFFF - def_len) / info_len;
  14156. (*limit_out) = (avail_quests > (*limit_out)) ? (*limit_out) : avail_quests;
  14157. (*len_out) = ((*limit_out) * info_len) + def_len;
  14158. }
  14159. /// Sends list of all quest states
  14160. /// 02b1 <packet len>.W <num>.L { <quest id>.L <active>.B }*num (ZC_ALL_QUEST_LIST)
  14161. /// 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)
  14162. /// 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)
  14163. void clif_quest_send_list(struct map_session_data *sd)
  14164. {
  14165. int fd = sd->fd;
  14166. int i;
  14167. int offset = 8;
  14168. int limit = 0;
  14169. #if PACKETVER >= 20141022
  14170. #if PACKETVER >= 20150513
  14171. int size = 22 + NAME_LENGTH;
  14172. #else
  14173. int size = 10 + NAME_LENGTH;
  14174. #endif
  14175. clif_quest_len(offset, 15 + ( size * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &i);
  14176. WFIFOHEAD(fd,i);
  14177. #if PACKETVER >= 20150513
  14178. WFIFOW(fd, 0) = 0x9f8;
  14179. #else
  14180. WFIFOW(fd, 0) = 0x97a;
  14181. #endif
  14182. WFIFOL(fd, 4) = limit;
  14183. for (i = 0; i < limit; i++) {
  14184. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  14185. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14186. offset += 4;
  14187. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14188. offset++;
  14189. WFIFOL(fd, offset) = sd->quest_log[i].time - qi->time;
  14190. offset += 4;
  14191. WFIFOL(fd, offset) = sd->quest_log[i].time;
  14192. offset += 4;
  14193. WFIFOW(fd, offset) = qi->objectives_count;
  14194. offset += 2;
  14195. if( qi->objectives_count > 0 ){
  14196. int j;
  14197. struct mob_db *mob;
  14198. for( j = 0; j < qi->objectives_count; j++ ){
  14199. mob = mob_db(qi->objectives[j].mob);
  14200. #if PACKETVER >= 20150513
  14201. WFIFOL(fd, offset) = sd->quest_log[i].quest_id * 1000 + j;
  14202. offset += 4;
  14203. WFIFOL(fd, offset) = 0; // TODO: Find info - mobType
  14204. offset += 4;
  14205. #endif
  14206. WFIFOL(fd, offset) = qi->objectives[j].mob;
  14207. offset += 4;
  14208. #if PACKETVER >= 20150513
  14209. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMin
  14210. offset += 2;
  14211. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMax
  14212. offset += 2;
  14213. #endif
  14214. WFIFOW(fd, offset) = sd->quest_log[i].count[j];
  14215. offset += 2;
  14216. WFIFOW(fd, offset) = qi->objectives[j].count;
  14217. offset += 2;
  14218. safestrncpy((char*)WFIFOP(fd, offset), mob->jname, NAME_LENGTH);
  14219. offset += NAME_LENGTH;
  14220. }
  14221. }
  14222. }
  14223. WFIFOW(fd, 2) = offset;
  14224. WFIFOSET(fd, offset);
  14225. #else
  14226. clif_quest_len(offset, 5, sd->avail_quests, &limit, &i);
  14227. WFIFOHEAD(fd,i);
  14228. WFIFOW(fd, 0) = 0x2b1;
  14229. WFIFOL(fd, 4) = limit;
  14230. for (i = 0; i < limit; i++) {
  14231. WFIFOL(fd, offset) = sd->quest_log[i].quest_id;
  14232. offset += 4;
  14233. WFIFOB(fd, offset) = sd->quest_log[i].state;
  14234. offset += 1;
  14235. }
  14236. WFIFOW(fd, 2) = offset;
  14237. WFIFOSET(fd, offset);
  14238. #endif
  14239. }
  14240. /// Sends list of all quest missions (ZC_ALL_QUEST_MISSION).
  14241. /// 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
  14242. void clif_quest_send_mission(struct map_session_data *sd)
  14243. {
  14244. int fd = sd->fd;
  14245. int i, j, limit = 0;
  14246. int len = sd->avail_quests*104+8;
  14247. struct mob_db *mob;
  14248. clif_quest_len(8, 14 + ((6 + NAME_LENGTH) * MAX_QUEST_OBJECTIVES), sd->avail_quests, &limit, &len);
  14249. WFIFOHEAD(fd, len);
  14250. WFIFOW(fd, 0) = 0x2b2;
  14251. WFIFOW(fd, 2) = len;
  14252. WFIFOL(fd, 4) = limit;
  14253. for (i = 0; i < limit; i++) {
  14254. struct quest_db *qi = quest_search(sd->quest_log[i].quest_id);
  14255. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  14256. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - qi->time;
  14257. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  14258. WFIFOW(fd, i*104+20) = qi->objectives_count;
  14259. for (j = 0 ; j < qi->objectives_count; j++) {
  14260. WFIFOL(fd, i*104+22+j*30) = qi->objectives[j].mob;
  14261. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  14262. mob = mob_db(qi->objectives[j].mob);
  14263. safestrncpy(WFIFOCP(fd, i*104+28+j*30), mob->jname, NAME_LENGTH);
  14264. }
  14265. }
  14266. WFIFOSET(fd, len);
  14267. }
  14268. /// Notification about a new quest
  14269. /// 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)
  14270. /// 08fe <packet len>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_HUNTING_QUEST_INFO)
  14271. /// 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)
  14272. void clif_quest_add(struct map_session_data *sd, struct quest *qd)
  14273. {
  14274. int fd = sd->fd;
  14275. int i, offset;
  14276. struct quest_db *qi = quest_search(qd->quest_id);
  14277. #if PACKETVER >= 20150513
  14278. int cmd = 0x9f9;
  14279. #else
  14280. int cmd = 0x2b3;
  14281. #endif
  14282. WFIFOHEAD(fd, packet_len(cmd));
  14283. WFIFOW(fd, 0) = cmd;
  14284. WFIFOL(fd, 2) = qd->quest_id;
  14285. WFIFOB(fd, 6) = qd->state;
  14286. WFIFOB(fd, 7) = qd->time - qi->time;
  14287. WFIFOL(fd, 11) = qd->time;
  14288. WFIFOW(fd, 15) = qi->objectives_count;
  14289. for (i = 0, offset = 17; i < qi->objectives_count; i++) {
  14290. struct mob_db *mob;
  14291. #if PACKETVER >= 20150513
  14292. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14293. offset += 4;
  14294. WFIFOL(fd, offset) = 0; // TODO: Find info - mobType
  14295. offset += 4;
  14296. #endif
  14297. WFIFOL(fd, offset) = qi->objectives[i].mob;
  14298. offset += 4;
  14299. #if PACKETVER >= 20150513
  14300. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMin
  14301. offset += 2;
  14302. WFIFOW(fd, offset) = 0; // TODO: Find info - levelMax
  14303. offset += 2;
  14304. #endif
  14305. WFIFOW(fd, offset) = qd->count[i];
  14306. offset += 2;
  14307. mob = mob_db(qi->objectives[i].mob);
  14308. safestrncpy(WFIFOCP(fd, offset), mob->jname, NAME_LENGTH);
  14309. offset += NAME_LENGTH;
  14310. }
  14311. WFIFOSET(fd, packet_len(cmd));
  14312. #if PACKETVER >= 20150513
  14313. int len = 4 + qi->objectives_count * 12;
  14314. WFIFOHEAD(fd, len);
  14315. WFIFOW(fd, 0) = 0x8fe;
  14316. WFIFOW(fd, 2) = len;
  14317. for( i = 0, offset = 4; i < qi->objectives_count; i++, offset += 12 ){
  14318. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14319. WFIFOL(fd, offset+4) = qi->objectives[i].mob;
  14320. WFIFOW(fd, offset + 10) = qi->objectives[i].count;
  14321. WFIFOW(fd, offset + 12) = qd->count[i];
  14322. }
  14323. WFIFOSET(fd, len);
  14324. #endif
  14325. }
  14326. /// Notification about a quest being removed (ZC_DEL_QUEST).
  14327. /// 02b4 <quest id>.L
  14328. void clif_quest_delete(struct map_session_data *sd, int quest_id)
  14329. {
  14330. int fd = sd->fd;
  14331. WFIFOHEAD(fd, packet_len(0x2b4));
  14332. WFIFOW(fd, 0) = 0x2b4;
  14333. WFIFOL(fd, 2) = quest_id;
  14334. WFIFOSET(fd, packet_len(0x2b4));
  14335. }
  14336. /// Notification of an update to the hunting mission counter
  14337. /// 02b5 <packet len>.W <mobs>.W { <quest id>.L <mob id>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT)
  14338. /// 09fa <packet len>.W <mobs>.W { <quest id>.L <hunt identification>.L <total count>.W <current count>.W }*3 (ZC_UPDATE_MISSION_HUNT_EX)
  14339. void clif_quest_update_objective(struct map_session_data *sd, struct quest *qd, int mobid)
  14340. {
  14341. int fd = sd->fd;
  14342. int i, offset;
  14343. struct quest_db *qi = quest_search(qd->quest_id);
  14344. int len = qi->objectives_count * 12 + 6;
  14345. #if PACKETVER >= 20150513
  14346. int cmd = 0x9fa;
  14347. #else
  14348. int cmd = 0x2b5;
  14349. #endif
  14350. WFIFOHEAD(fd, len);
  14351. WFIFOW(fd, 0) = cmd;
  14352. WFIFOW(fd, 4) = qi->objectives_count;
  14353. for (i = 0, offset = 6; i < qi->objectives_count; i++) {
  14354. if (mobid == 0 || mobid == qi->objectives[i].mob) {
  14355. WFIFOL(fd, offset) = qd->quest_id;
  14356. offset += 4;
  14357. #if PACKETVER >= 20150513
  14358. WFIFOL(fd, offset) = qd->quest_id * 1000 + i;
  14359. offset += 4;
  14360. #else
  14361. WFIFOL(fd, offset) = qi->objectives[i].mob;
  14362. offset += 4;
  14363. #endif
  14364. WFIFOW(fd, offset) = qi->objectives[i].count;
  14365. offset += 2;
  14366. WFIFOW(fd, offset) = qd->count[i];
  14367. offset += 2;
  14368. }
  14369. }
  14370. WFIFOW(fd, 2) = offset;
  14371. WFIFOSET(fd, offset);
  14372. }
  14373. /// Request to change the state of a quest (CZ_ACTIVE_QUEST).
  14374. /// 02b6 <quest id>.L <active>.B
  14375. void clif_parse_questStateAck(int fd, struct map_session_data *sd)
  14376. {
  14377. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14378. quest_update_status(sd, RFIFOL(fd,info->pos[0]),
  14379. RFIFOB(fd,info->pos[1])?Q_ACTIVE:Q_INACTIVE);
  14380. }
  14381. /// Notification about the change of a quest state (ZC_ACTIVE_QUEST).
  14382. /// 02b7 <quest id>.L <active>.B
  14383. void clif_quest_update_status(struct map_session_data *sd, int quest_id, bool active)
  14384. {
  14385. int fd = sd->fd;
  14386. WFIFOHEAD(fd, packet_len(0x2b7));
  14387. WFIFOW(fd, 0) = 0x2b7;
  14388. WFIFOL(fd, 2) = quest_id;
  14389. WFIFOB(fd, 6) = active;
  14390. WFIFOSET(fd, packet_len(0x2b7));
  14391. }
  14392. /// Notification about an NPC's quest state (ZC_QUEST_NOTIFY_EFFECT).
  14393. /// 0446 <npc id>.L <x>.W <y>.W <effect>.W <color>.W
  14394. /// effect:
  14395. /// 0 = none
  14396. /// 1 = exclamation mark icon
  14397. /// 2 = question mark icon
  14398. /// color:
  14399. /// 0 = yellow
  14400. /// 1 = orange
  14401. /// 2 = green
  14402. /// 3 = purple
  14403. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short effect, short color)
  14404. {
  14405. #if PACKETVER >= 20090218
  14406. int fd = sd->fd;
  14407. WFIFOHEAD(fd, packet_len(0x446));
  14408. WFIFOW(fd, 0) = 0x446;
  14409. WFIFOL(fd, 2) = bl->id;
  14410. WFIFOW(fd, 6) = bl->x;
  14411. WFIFOW(fd, 8) = bl->y;
  14412. WFIFOW(fd, 10) = effect;
  14413. WFIFOW(fd, 12) = color;
  14414. WFIFOSET(fd, packet_len(0x446));
  14415. #endif
  14416. }
  14417. /// Mercenary System
  14418. ///
  14419. /// Notification about a mercenary status parameter change (ZC_MER_PAR_CHANGE).
  14420. /// 02a2 <var id>.W <value>.L
  14421. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  14422. {
  14423. struct mercenary_data *md;
  14424. struct status_data *status;
  14425. int fd;
  14426. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14427. return;
  14428. fd = sd->fd;
  14429. status = &md->battle_status;
  14430. WFIFOHEAD(fd,packet_len(0x2a2));
  14431. WFIFOW(fd,0) = 0x2a2;
  14432. WFIFOW(fd,2) = type;
  14433. switch( type ) {
  14434. case SP_ATK1:
  14435. {
  14436. int atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  14437. WFIFOL(fd,4) = cap_value(atk, 0, INT16_MAX);
  14438. }
  14439. break;
  14440. case SP_MATK1:
  14441. WFIFOL(fd,4) = min(status->matk_max, UINT16_MAX);
  14442. break;
  14443. case SP_HIT:
  14444. WFIFOL(fd,4) = status->hit;
  14445. break;
  14446. case SP_CRITICAL:
  14447. WFIFOL(fd,4) = status->cri/10;
  14448. break;
  14449. case SP_DEF1:
  14450. WFIFOL(fd,4) = status->def;
  14451. break;
  14452. case SP_MDEF1:
  14453. WFIFOL(fd,4) = status->mdef;
  14454. break;
  14455. case SP_MERCFLEE:
  14456. WFIFOL(fd,4) = status->flee;
  14457. break;
  14458. case SP_ASPD:
  14459. WFIFOL(fd,4) = status->amotion;
  14460. break;
  14461. case SP_HP:
  14462. WFIFOL(fd,4) = status->hp;
  14463. break;
  14464. case SP_MAXHP:
  14465. WFIFOL(fd,4) = status->max_hp;
  14466. break;
  14467. case SP_SP:
  14468. WFIFOL(fd,4) = status->sp;
  14469. break;
  14470. case SP_MAXSP:
  14471. WFIFOL(fd,4) = status->max_sp;
  14472. break;
  14473. case SP_MERCKILLS:
  14474. WFIFOL(fd,4) = md->mercenary.kill_count;
  14475. break;
  14476. case SP_MERCFAITH:
  14477. WFIFOL(fd,4) = mercenary_get_faith(md);
  14478. break;
  14479. }
  14480. WFIFOSET(fd,packet_len(0x2a2));
  14481. }
  14482. /// Mercenary base status data (ZC_MER_INIT).
  14483. /// 029b <id>.L <atk>.W <matk>.W <hit>.W <crit>.W <def>.W <mdef>.W <flee>.W <aspd>.W
  14484. /// <name>.24B <level>.W <hp>.L <maxhp>.L <sp>.L <maxsp>.L <expire time>.L <faith>.W
  14485. /// <calls>.L <kills>.L <atk range>.W
  14486. void clif_mercenary_info(struct map_session_data *sd)
  14487. {
  14488. int fd;
  14489. struct mercenary_data *md;
  14490. struct status_data *status;
  14491. int atk;
  14492. if( !clif_session_isValid(sd) || (md = sd->md) == NULL )
  14493. return;
  14494. fd = sd->fd;
  14495. status = &md->battle_status;
  14496. WFIFOHEAD(fd,packet_len(0x29b));
  14497. WFIFOW(fd,0) = 0x29b;
  14498. WFIFOL(fd,2) = md->bl.id;
  14499. // Mercenary shows ATK as a random value between ATK ~ ATK2
  14500. atk = rnd()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  14501. WFIFOW(fd,6) = cap_value(atk, 0, INT16_MAX);
  14502. WFIFOW(fd,8) = min(status->matk_max, UINT16_MAX);
  14503. WFIFOW(fd,10) = status->hit;
  14504. WFIFOW(fd,12) = status->cri/10;
  14505. WFIFOW(fd,14) = status->def;
  14506. WFIFOW(fd,16) = status->mdef;
  14507. WFIFOW(fd,18) = status->flee;
  14508. WFIFOW(fd,20) = status->amotion;
  14509. safestrncpy(WFIFOCP(fd,22), md->db->name, NAME_LENGTH);
  14510. WFIFOW(fd,46) = md->db->lv;
  14511. WFIFOL(fd,48) = status->hp;
  14512. WFIFOL(fd,52) = status->max_hp;
  14513. WFIFOL(fd,56) = status->sp;
  14514. WFIFOL(fd,60) = status->max_sp;
  14515. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  14516. WFIFOW(fd,68) = mercenary_get_faith(md);
  14517. WFIFOL(fd,70) = mercenary_get_calls(md);
  14518. WFIFOL(fd,74) = md->mercenary.kill_count;
  14519. WFIFOW(fd,78) = md->battle_status.rhw.range;
  14520. WFIFOSET(fd,packet_len(0x29b));
  14521. }
  14522. /// Mercenary skill tree (ZC_MER_SKILLINFO_LIST).
  14523. /// 029d <packet len>.W { <skill id>.W <type>.L <level>.W <sp cost>.W <attack range>.W <skill name>.24B <upgradable>.B }*
  14524. void clif_mercenary_skillblock(struct map_session_data *sd)
  14525. {
  14526. struct mercenary_data *md;
  14527. int fd, i, len = 4;
  14528. if( sd == NULL || (md = sd->md) == NULL )
  14529. return;
  14530. fd = sd->fd;
  14531. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  14532. WFIFOW(fd,0) = 0x29d;
  14533. for( i = 0; i < MAX_MERCSKILL; i++ )
  14534. {
  14535. uint16 id;
  14536. short idx = -1;
  14537. if( (id = md->db->skill[i].id) == 0 )
  14538. continue;
  14539. if ((idx = mercenary_skill_get_index(id)) == -1)
  14540. continue;
  14541. WFIFOW(fd,len) = id;
  14542. WFIFOL(fd,len+2) = skill_get_inf(id);
  14543. WFIFOW(fd,len+6) = md->db->skill[idx].lv;
  14544. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[idx].lv);
  14545. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[idx].lv, false);
  14546. safestrncpy(WFIFOCP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  14547. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  14548. len += 37;
  14549. }
  14550. WFIFOW(fd,2) = len;
  14551. WFIFOSET(fd,len);
  14552. }
  14553. /// Request to invoke a mercenary menu action (CZ_MER_COMMAND).
  14554. /// 029f <command>.B
  14555. /// 1 = mercenary information
  14556. /// 2 = delete
  14557. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  14558. {
  14559. int option = RFIFOB(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14560. if( sd->md == NULL )
  14561. return;
  14562. if( option == 2 ) mercenary_delete(sd->md, 2);
  14563. }
  14564. /// Mercenary Message
  14565. /// message:
  14566. /// 0 = Mercenary soldier's duty hour is over.
  14567. /// 1 = Your mercenary soldier has been killed.
  14568. /// 2 = Your mercenary soldier has been fired.
  14569. /// 3 = Your mercenary soldier has ran away.
  14570. void clif_mercenary_message(struct map_session_data* sd, int message){
  14571. clif_msg(sd, MERC_MSG_BASE + message);
  14572. }
  14573. /// Notification about the remaining time of a rental item (ZC_CASH_TIME_COUNTER).
  14574. /// 0298 <name id>.W <seconds>.L
  14575. void clif_rental_time(int fd, unsigned short nameid, int seconds)
  14576. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  14577. WFIFOHEAD(fd,packet_len(0x298));
  14578. WFIFOW(fd,0) = 0x298;
  14579. WFIFOW(fd,2) = nameid;
  14580. WFIFOL(fd,4) = seconds;
  14581. WFIFOSET(fd,packet_len(0x298));
  14582. }
  14583. /// Deletes a rental item from client's inventory (ZC_CASH_ITEM_DELETE).
  14584. /// 0299 <index>.W <name id>.W
  14585. void clif_rental_expired(int fd, int index, unsigned short nameid)
  14586. { // '<ItemName>' item has been deleted from the Inventory
  14587. WFIFOHEAD(fd,packet_len(0x299));
  14588. WFIFOW(fd,0) = 0x299;
  14589. WFIFOW(fd,2) = index+2;
  14590. WFIFOW(fd,4) = nameid;
  14591. WFIFOSET(fd,packet_len(0x299));
  14592. }
  14593. /// Book Reading (ZC_READ_BOOK).
  14594. /// 0294 <book id>.L <page>.L
  14595. void clif_readbook(int fd, int book_id, int page)
  14596. {
  14597. WFIFOHEAD(fd,packet_len(0x294));
  14598. WFIFOW(fd,0) = 0x294;
  14599. WFIFOL(fd,2) = book_id;
  14600. WFIFOL(fd,6) = page;
  14601. WFIFOSET(fd,packet_len(0x294));
  14602. }
  14603. /// Battlegrounds
  14604. ///
  14605. /// Updates HP bar of a camp member.
  14606. /// 02e0 <account id>.L <name>.24B <hp>.W <max hp>.W (ZC_BATTLEFIELD_NOTIFY_HP)
  14607. /// 0a0e <account id>.L <hp>.L <max hp>.L (ZC_BATTLEFIELD_NOTIFY_HP2)
  14608. void clif_bg_hp(struct map_session_data *sd) {
  14609. #if PACKETVER < 20140613
  14610. unsigned char buf[34];
  14611. const int cmd = 0x2e0;
  14612. #else
  14613. unsigned char buf[14];
  14614. const int cmd = 0xa0e;
  14615. #endif
  14616. nullpo_retv(sd);
  14617. WBUFW(buf,0) = cmd;
  14618. WBUFL(buf,2) = sd->status.account_id;
  14619. #if PACKETVER < 20140613
  14620. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14621. if( sd->battle_status.max_hp > INT16_MAX ) { // To correctly display the %hp bar. [Skotlex]
  14622. WBUFW(buf,30) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14623. WBUFW(buf,32) = 100;
  14624. } else {
  14625. WBUFW(buf,30) = sd->battle_status.hp;
  14626. WBUFW(buf,32) = sd->battle_status.max_hp;
  14627. }
  14628. #else
  14629. if( sd->battle_status.max_hp > INT32_MAX ) {
  14630. WBUFL(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  14631. WBUFL(buf,10) = 100;
  14632. } else {
  14633. WBUFL(buf,6) = sd->battle_status.hp;
  14634. WBUFL(buf,10) = sd->battle_status.max_hp;
  14635. }
  14636. #endif
  14637. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  14638. }
  14639. /// Updates the position of a camp member on the minimap (ZC_BATTLEFIELD_NOTIFY_POSITION).
  14640. /// 02df <account id>.L <name>.24B <class>.W <x>.W <y>.W
  14641. void clif_bg_xy(struct map_session_data *sd)
  14642. {
  14643. unsigned char buf[36];
  14644. nullpo_retv(sd);
  14645. WBUFW(buf,0)=0x2df;
  14646. WBUFL(buf,2)=sd->status.account_id;
  14647. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH);
  14648. WBUFW(buf,30)=sd->status.class_;
  14649. WBUFW(buf,32)=sd->bl.x;
  14650. WBUFW(buf,34)=sd->bl.y;
  14651. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14652. }
  14653. void clif_bg_xy_remove(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. memset(WBUFP(buf,6), 0, NAME_LENGTH);
  14660. WBUFW(buf,30)=0;
  14661. WBUFW(buf,32)=-1;
  14662. WBUFW(buf,34)=-1;
  14663. clif_send(buf, packet_len(0x2df), &sd->bl, BG_SAMEMAP_WOS);
  14664. }
  14665. /// Notifies clients of a battleground message (ZC_BATTLEFIELD_CHAT).
  14666. /// 02dc <packet len>.W <account id>.L <name>.24B <message>.?B
  14667. void clif_bg_message(struct battleground_data *bg, int src_id, const char *name, const char *mes, int len)
  14668. {
  14669. struct map_session_data *sd;
  14670. unsigned char *buf;
  14671. if( (sd = bg_getavailablesd(bg)) == NULL )
  14672. return;
  14673. buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  14674. WBUFW(buf,0) = 0x2dc;
  14675. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  14676. WBUFL(buf,4) = src_id;
  14677. safestrncpy(WBUFCP(buf,8), name, NAME_LENGTH);
  14678. memcpy(WBUFP(buf,32), mes, len);
  14679. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  14680. if( buf )
  14681. aFree(buf);
  14682. }
  14683. /// Validates and processes battlechat messages [pakpil] (CZ_BATTLEFIELD_CHAT).
  14684. /// 0x2db <packet len>.W <text>.?B (<name> : <message>) 00
  14685. void clif_parse_BattleChat(int fd, struct map_session_data* sd){
  14686. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  14687. if( !clif_process_message( sd, false, name, message, output ) )
  14688. return;
  14689. bg_send_message(sd, output, strlen(output) );
  14690. }
  14691. /// Notifies client of a battleground score change (ZC_BATTLEFIELD_NOTIFY_POINT).
  14692. /// 02de <camp A points>.W <camp B points>.W
  14693. void clif_bg_updatescore(int16 m)
  14694. {
  14695. struct block_list bl;
  14696. unsigned char buf[6];
  14697. bl.id = 0;
  14698. bl.type = BL_NUL;
  14699. bl.m = m;
  14700. WBUFW(buf,0) = 0x2de;
  14701. WBUFW(buf,2) = map[m].bgscore_lion;
  14702. WBUFW(buf,4) = map[m].bgscore_eagle;
  14703. clif_send(buf,packet_len(0x2de),&bl,ALL_SAMEMAP);
  14704. }
  14705. void clif_bg_updatescore_single(struct map_session_data *sd)
  14706. {
  14707. int fd;
  14708. nullpo_retv(sd);
  14709. fd = sd->fd;
  14710. WFIFOHEAD(fd,packet_len(0x2de));
  14711. WFIFOW(fd,0) = 0x2de;
  14712. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  14713. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  14714. WFIFOSET(fd,packet_len(0x2de));
  14715. }
  14716. /// Battleground camp belong-information (ZC_BATTLEFIELD_NOTIFY_CAMPINFO).
  14717. /// 02dd <account id>.L <name>.24B <camp>.W
  14718. void clif_sendbgemblem_area(struct map_session_data *sd)
  14719. {
  14720. unsigned char buf[33];
  14721. nullpo_retv(sd);
  14722. WBUFW(buf, 0) = 0x2dd;
  14723. WBUFL(buf,2) = sd->bl.id;
  14724. safestrncpy(WBUFCP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  14725. WBUFW(buf,30) = sd->bg_id;
  14726. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  14727. }
  14728. void clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  14729. {
  14730. nullpo_retv(sd);
  14731. WFIFOHEAD(fd,32);
  14732. WFIFOW(fd,0) = 0x2dd;
  14733. WFIFOL(fd,2) = sd->bl.id;
  14734. safestrncpy(WFIFOCP(fd,6), sd->status.name, NAME_LENGTH);
  14735. WFIFOW(fd,30) = sd->bg_id;
  14736. WFIFOSET(fd,packet_len(0x2dd));
  14737. }
  14738. /// Custom Fonts (ZC_NOTIFY_FONT).
  14739. /// 02ef <account_id>.L <font id>.W
  14740. void clif_font(struct map_session_data *sd)
  14741. {
  14742. #if PACKETVER >= 20080102
  14743. unsigned char buf[8];
  14744. nullpo_retv(sd);
  14745. WBUFW(buf,0) = 0x2ef;
  14746. WBUFL(buf,2) = sd->bl.id;
  14747. WBUFW(buf,6) = sd->status.font;
  14748. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  14749. #endif
  14750. }
  14751. /// Required to start the instancing information window on Client
  14752. /// This window re-appears each "refresh" of client automatically until the keep_limit reaches 0.
  14753. /// S 0x2cb <Instance name>.61B <Standby Position>.W
  14754. void clif_instance_create(unsigned short instance_id, int num)
  14755. {
  14756. #if PACKETVER >= 20071128
  14757. struct instance_db *db = NULL;
  14758. struct map_session_data *sd = NULL;
  14759. enum send_target target = PARTY;
  14760. unsigned char buf[65];
  14761. instance_getsd(instance_id, &sd, &target);
  14762. if (!sd)
  14763. return;
  14764. db = instance_searchtype_db(instance_data[instance_id].type);
  14765. if (!db)
  14766. return;
  14767. WBUFW(buf,0) = 0x2cb;
  14768. safestrncpy(WBUFCP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  14769. WBUFW(buf,63) = num;
  14770. clif_send(buf,packet_len(0x2cb),&sd->bl,target);
  14771. #endif
  14772. return;
  14773. }
  14774. /// To announce Instancing queue creation if no maps available
  14775. /// S 0x2cc <Standby Position>.W
  14776. void clif_instance_changewait(unsigned short instance_id, int num)
  14777. {
  14778. #if PACKETVER >= 20071128
  14779. struct map_session_data *sd = NULL;
  14780. enum send_target target = PARTY;
  14781. unsigned char buf[4];
  14782. instance_getsd(instance_id, &sd, &target);
  14783. if (!sd)
  14784. return;
  14785. WBUFW(buf,0) = 0x2cc;
  14786. WBUFW(buf,2) = num;
  14787. clif_send(buf,packet_len(0x2cc),&sd->bl,target);
  14788. #endif
  14789. return;
  14790. }
  14791. /// Notify the current status to members
  14792. /// S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  14793. void clif_instance_status(unsigned short instance_id, unsigned int limit1, unsigned int limit2)
  14794. {
  14795. #if PACKETVER >= 20071128
  14796. struct instance_db *db = NULL;
  14797. struct map_session_data *sd = NULL;
  14798. enum send_target target = PARTY;
  14799. unsigned char buf[71];
  14800. instance_getsd(instance_id, &sd, &target);
  14801. if (!sd)
  14802. return;
  14803. db = instance_searchtype_db(instance_data[instance_id].type);
  14804. if (!db)
  14805. return;
  14806. WBUFW(buf,0) = 0x2cd;
  14807. safestrncpy(WBUFCP(buf,2), StringBuf_Value(db->name), INSTANCE_NAME_LENGTH);
  14808. WBUFL(buf,63) = limit1;
  14809. WBUFL(buf,67) = limit2;
  14810. clif_send(buf,packet_len(0x2cd),&sd->bl,target);
  14811. #endif
  14812. return;
  14813. }
  14814. /// Notify a status change to members
  14815. /// S 0x2ce <Message ID>.L
  14816. /// 0 = Notification (EnterLimitDate update?)
  14817. /// 1 = The Memorial Dungeon expired; it has been destroyed
  14818. /// 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  14819. /// 3 = The Memorial Dungeon has been removed.
  14820. /// 4 = Create failure (removes the instance window)
  14821. void clif_instance_changestatus(unsigned int instance_id, int type, unsigned int limit)
  14822. {
  14823. #if PACKETVER >= 20071128
  14824. struct map_session_data *sd = NULL;
  14825. enum send_target target = PARTY;
  14826. unsigned char buf[10];
  14827. instance_getsd(instance_id, &sd, &target);
  14828. if (!sd)
  14829. return;
  14830. WBUFW(buf,0) = 0x2ce;
  14831. WBUFL(buf,2) = type;
  14832. WBUFL(buf,6) = limit;
  14833. clif_send(buf,packet_len(0x2ce),&sd->bl,target);
  14834. #endif
  14835. return;
  14836. }
  14837. /// Notifies clients about item picked up by a party member (ZC_ITEM_PICKUP_PARTY).
  14838. /// 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
  14839. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  14840. {
  14841. #if PACKETVER >= 20071002
  14842. unsigned char buf[22];
  14843. struct item_data* id = itemdb_search(item_data->nameid);
  14844. WBUFW(buf,0) = 0x2b8;
  14845. WBUFL(buf,2) = sd->status.account_id;
  14846. WBUFW(buf,6) = item_data->nameid;
  14847. WBUFB(buf,8) = item_data->identify;
  14848. WBUFB(buf,9) = item_data->attribute;
  14849. WBUFB(buf,10) = item_data->refine;
  14850. clif_addcards(WBUFP(buf,11), item_data);
  14851. WBUFW(buf,19) = id->equip; // equip location
  14852. WBUFB(buf,21) = itemtype(id->nameid); // item type
  14853. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  14854. #endif
  14855. }
  14856. /** Display gained exp.
  14857. * 07f6 <account id>.L <amount>.L <var id>.W <exp type>.W (ZC_NOTIFY_EXP)
  14858. * 0acc <account id>.L <amount>.Q <var id>.W <exp type>.W (ZC_NOTIFY_EXP2)
  14859. * amount: INT32_MIN ~ INT32_MAX
  14860. * var id:
  14861. * SP_BASEEXP, SP_JOBEXP
  14862. * exp type:
  14863. * 0 = normal exp gained/lost
  14864. * 1 = quest exp gained/lost
  14865. * @param sd Player
  14866. * @param exp EXP value gained/loss
  14867. * @param type SP_BASEEXP, SP_JOBEXP
  14868. * @param quest False:Normal EXP; True:Quest EXP (displayed in purple color)
  14869. * @param lost True:if lossing EXP
  14870. */
  14871. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest, bool lost)
  14872. {
  14873. int fd;
  14874. int offset;
  14875. #if PACKETVER >= 20170830
  14876. int cmd = 0xacc;
  14877. #else
  14878. int cmd = 0x7f6;
  14879. #endif
  14880. nullpo_retv(sd);
  14881. fd = sd->fd;
  14882. WFIFOHEAD(fd, packet_len(cmd));
  14883. WFIFOW(fd,0) = cmd;
  14884. WFIFOL(fd,2) = sd->bl.id;
  14885. #if PACKETVER >= 20170830
  14886. WFIFOQ(fd,6) = (int64)u64min((uint64)exp, INT_MAX) * (lost ? -1 : 1);
  14887. offset = 4;
  14888. #else
  14889. WFIFOL(fd,6) = (int)umin(exp, INT_MAX) * (lost ? -1 : 1);
  14890. offset = 0;
  14891. #endif
  14892. WFIFOW(fd,10+offset) = type;
  14893. WFIFOW(fd,12+offset) = (quest && type != SP_JOBEXP) ? 1 : 0; // NOTE: Somehow JobEXP always in yellow color
  14894. WFIFOSET(fd,packet_len(cmd));
  14895. }
  14896. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  14897. /// type:
  14898. /// 0 = Displays 'value' for 5 seconds.
  14899. /// 1 = Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  14900. /// 2 = Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  14901. /// 3 = Decremental counter (1 tick/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  14902. /// value:
  14903. /// 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).
  14904. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  14905. {
  14906. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  14907. WFIFOW(sd->fd,0) = 0x1b1;
  14908. WFIFOB(sd->fd,2) = type;
  14909. WFIFOL(sd->fd,3) = value;
  14910. WFIFOSET(sd->fd, packet_len(0x1b1));
  14911. }
  14912. /// Notification of the state of client command /effect (CZ_LESSEFFECT).
  14913. /// 021d <state>.L
  14914. /// state:
  14915. /// 0 = Full effects
  14916. /// 1 = Reduced effects
  14917. ///
  14918. /// NOTE: The state is used on Aegis for sending skill unit packet
  14919. /// 0x11f (ZC_SKILL_ENTRY) instead of 0x1c9 (ZC_SKILL_ENTRY2)
  14920. /// whenever possible. Due to the way the decision check is
  14921. /// constructed, this state tracking was rendered useless,
  14922. /// as the only skill unit, that is sent with 0x1c9 is
  14923. /// Graffiti.
  14924. void clif_parse_LessEffect(int fd, struct map_session_data* sd){
  14925. int isLess = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  14926. sd->state.lesseffect = ( isLess != 0 );
  14927. }
  14928. /// 07e4 <length>.w <option>.l <val>.l {<index>.w <amount>.w).4b* (CZ_ITEMLISTWIN_RES)
  14929. void clif_parse_ItemListWindowSelected(int fd, struct map_session_data* sd) {
  14930. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  14931. int n = (RFIFOW(fd,info->pos[0])-12) / 4;
  14932. int type = RFIFOL(fd,info->pos[1]);
  14933. int flag = RFIFOL(fd,info->pos[2]); // Button clicked: 0 = Cancel, 1 = OK
  14934. unsigned short* item_list = (unsigned short*)RFIFOP(fd,info->pos[3]);
  14935. if( sd->state.trading || sd->npc_shopid )
  14936. return;
  14937. if( flag == 0 || n == 0) {
  14938. clif_menuskill_clear(sd);
  14939. return; // Canceled by player.
  14940. }
  14941. if( sd->menuskill_id != SO_EL_ANALYSIS && sd->menuskill_id != GN_CHANGEMATERIAL ) {
  14942. clif_menuskill_clear(sd);
  14943. return; // Prevent hacking.
  14944. }
  14945. switch( type ) {
  14946. case 0: // Change Material
  14947. skill_changematerial(sd,n,item_list);
  14948. break;
  14949. case 1: // Level 1: Pure to Rough
  14950. case 2: // Level 2: Rough to Pure
  14951. skill_elementalanalysis(sd,n,type,item_list);
  14952. break;
  14953. }
  14954. clif_menuskill_clear(sd);
  14955. return;
  14956. }
  14957. /*==========================================
  14958. * Elemental System
  14959. *==========================================*/
  14960. void clif_elemental_updatestatus(struct map_session_data *sd, int type) {
  14961. struct elemental_data *ed;
  14962. struct status_data *status;
  14963. int fd;
  14964. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  14965. return;
  14966. fd = sd->fd;
  14967. status = &ed->battle_status;
  14968. WFIFOHEAD(fd,8);
  14969. WFIFOW(fd,0) = 0x81e;
  14970. WFIFOW(fd,2) = type;
  14971. switch( type ) {
  14972. case SP_HP:
  14973. WFIFOL(fd,4) = status->hp;
  14974. break;
  14975. case SP_MAXHP:
  14976. WFIFOL(fd,4) = status->max_hp;
  14977. break;
  14978. case SP_SP:
  14979. WFIFOL(fd,4) = status->sp;
  14980. break;
  14981. case SP_MAXSP:
  14982. WFIFOL(fd,4) = status->max_sp;
  14983. break;
  14984. }
  14985. WFIFOSET(fd,8);
  14986. }
  14987. void clif_elemental_info(struct map_session_data *sd) {
  14988. int fd;
  14989. struct elemental_data *ed;
  14990. struct status_data *status;
  14991. if( !clif_session_isValid(sd) || (ed = sd->ed) == NULL )
  14992. return;
  14993. fd = sd->fd;
  14994. status = &ed->battle_status;
  14995. WFIFOHEAD(fd,22);
  14996. WFIFOW(fd, 0) = 0x81d;
  14997. WFIFOL(fd, 2) = ed->bl.id;
  14998. WFIFOL(fd, 6) = status->hp;
  14999. WFIFOL(fd,10) = status->max_hp;
  15000. WFIFOL(fd,14) = status->sp;
  15001. WFIFOL(fd,18) = status->max_sp;
  15002. WFIFOSET(fd,22);
  15003. }
  15004. /// Buying Store System
  15005. ///
  15006. /// Opens preparation window for buying store (ZC_OPEN_BUYING_STORE).
  15007. /// 0810 <slots>.B
  15008. void clif_buyingstore_open(struct map_session_data* sd)
  15009. {
  15010. int fd = sd->fd;
  15011. WFIFOHEAD(fd,packet_len(0x810));
  15012. WFIFOW(fd,0) = 0x810;
  15013. WFIFOB(fd,2) = sd->buyingstore.slots;
  15014. WFIFOSET(fd,packet_len(0x810));
  15015. }
  15016. /// Request to create a buying store (CZ_REQ_OPEN_BUYING_STORE).
  15017. /// 0811 <packet len>.W <limit zeny>.L <result>.B <store name>.80B { <name id>.W <amount>.W <price>.L }*
  15018. /// result:
  15019. /// 0 = cancel
  15020. /// 1 = open
  15021. static void clif_parse_ReqOpenBuyingStore(int fd, struct map_session_data* sd)
  15022. {
  15023. const unsigned int blocksize = 8;
  15024. uint8* itemlist;
  15025. char storename[MESSAGE_SIZE];
  15026. unsigned char result;
  15027. int zenylimit;
  15028. unsigned int count, packet_len;
  15029. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15030. packet_len = RFIFOW(fd,info->pos[0]);
  15031. // TODO: Make this check global for all variable length packets.
  15032. if( packet_len < 89 )
  15033. {// minimum packet length
  15034. ShowError("clif_parse_ReqOpenBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 89, packet_len, sd->bl.id);
  15035. return;
  15036. }
  15037. zenylimit = RFIFOL(fd,info->pos[1]);
  15038. result = RFIFOL(fd,info->pos[2]);
  15039. safestrncpy(storename, RFIFOCP(fd,info->pos[3]), sizeof(storename));
  15040. itemlist = RFIFOP(fd,info->pos[4]);
  15041. // so that buyingstore_create knows, how many elements it has access to
  15042. packet_len-= info->pos[4];
  15043. if( packet_len%blocksize )
  15044. {
  15045. ShowError("clif_parse_ReqOpenBuyingStore: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  15046. return;
  15047. }
  15048. count = packet_len/blocksize;
  15049. buyingstore_create(sd, zenylimit, result, storename, itemlist, count, NULL);
  15050. }
  15051. /// Notification, that the requested buying store could not be created (ZC_FAILED_OPEN_BUYING_STORE_TO_BUYER).
  15052. /// 0812 <result>.W <total weight>.L
  15053. /// result:
  15054. /// 1 = "Failed to open buying store." (0x6cd, MSI_BUYINGSTORE_OPEN_FAILED)
  15055. /// 2 = "Total amount of then possessed items exceeds the weight limit by <weight/10-maxweight*90%>. Please re-enter." (0x6ce, MSI_BUYINGSTORE_OVERWEIGHT)
  15056. /// 8 = "No sale (purchase) information available." (0x705)
  15057. /// ? = nothing
  15058. void clif_buyingstore_open_failed(struct map_session_data* sd, unsigned short result, unsigned int weight)
  15059. {
  15060. int fd = sd->fd;
  15061. WFIFOHEAD(fd,packet_len(0x812));
  15062. WFIFOW(fd,0) = 0x812;
  15063. WFIFOW(fd,2) = result;
  15064. WFIFOL(fd,4) = weight;
  15065. WFIFOSET(fd,packet_len(0x812));
  15066. }
  15067. /// Notification, that the requested buying store was created (ZC_MYITEMLIST_BUYING_STORE).
  15068. /// 0813 <packet len>.W <account id>.L <limit zeny>.L { <price>.L <count>.W <type>.B <name id>.W }*
  15069. void clif_buyingstore_myitemlist(struct map_session_data* sd)
  15070. {
  15071. int fd = sd->fd;
  15072. unsigned int i;
  15073. WFIFOHEAD(fd,12+sd->buyingstore.slots*9);
  15074. WFIFOW(fd,0) = 0x813;
  15075. WFIFOW(fd,2) = 12+sd->buyingstore.slots*9;
  15076. WFIFOL(fd,4) = sd->bl.id;
  15077. WFIFOL(fd,8) = sd->buyingstore.zenylimit;
  15078. for( i = 0; i < sd->buyingstore.slots; i++ )
  15079. {
  15080. WFIFOL(fd,12+i*9) = sd->buyingstore.items[i].price;
  15081. WFIFOW(fd,16+i*9) = sd->buyingstore.items[i].amount;
  15082. WFIFOB(fd,18+i*9) = itemtype(sd->buyingstore.items[i].nameid);
  15083. WFIFOW(fd,19+i*9) = sd->buyingstore.items[i].nameid;
  15084. }
  15085. WFIFOSET(fd,WFIFOW(fd,2));
  15086. }
  15087. /// Notifies clients in area of a buying store (ZC_BUYING_STORE_ENTRY).
  15088. /// 0814 <account id>.L <store name>.80B
  15089. void clif_buyingstore_entry(struct map_session_data* sd)
  15090. {
  15091. uint8 buf[MESSAGE_SIZE+6];
  15092. WBUFW(buf,0) = 0x814;
  15093. WBUFL(buf,2) = sd->bl.id;
  15094. safestrncpy(WBUFCP(buf,6), sd->message, MESSAGE_SIZE);
  15095. clif_send(buf, packet_len(0x814), &sd->bl, AREA_WOS);
  15096. }
  15097. void clif_buyingstore_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15098. {
  15099. int fd = sd->fd;
  15100. WFIFOHEAD(fd,packet_len(0x814));
  15101. WFIFOW(fd,0) = 0x814;
  15102. WFIFOL(fd,2) = pl_sd->bl.id;
  15103. safestrncpy(WFIFOCP(fd,6), pl_sd->message, MESSAGE_SIZE);
  15104. WFIFOSET(fd,packet_len(0x814));
  15105. }
  15106. /// Request to close own buying store (CZ_REQ_CLOSE_BUYING_STORE).
  15107. /// 0815
  15108. static void clif_parse_ReqCloseBuyingStore(int fd, struct map_session_data* sd)
  15109. {
  15110. buyingstore_close(sd);
  15111. }
  15112. /// Notifies clients in area that a buying store was closed (ZC_DISAPPEAR_BUYING_STORE_ENTRY).
  15113. /// 0816 <account id>.L
  15114. void clif_buyingstore_disappear_entry(struct map_session_data* sd)
  15115. {
  15116. uint8 buf[6];
  15117. WBUFW(buf,0) = 0x816;
  15118. WBUFL(buf,2) = sd->bl.id;
  15119. clif_send(buf, packet_len(0x816), &sd->bl, AREA_WOS);
  15120. }
  15121. void clif_buyingstore_disappear_entry_single(struct map_session_data* sd, struct map_session_data* pl_sd)
  15122. {
  15123. int fd = sd->fd;
  15124. WFIFOHEAD(fd,packet_len(0x816));
  15125. WFIFOW(fd,0) = 0x816;
  15126. WFIFOL(fd,2) = pl_sd->bl.id;
  15127. WFIFOSET(fd,packet_len(0x816));
  15128. }
  15129. /// Request to open someone else's buying store (CZ_REQ_CLICK_TO_BUYING_STORE).
  15130. /// 0817 <account id>.L
  15131. static void clif_parse_ReqClickBuyingStore(int fd, struct map_session_data* sd)
  15132. {
  15133. uint32 account_id;
  15134. account_id = RFIFOL(fd,packet_db[RFIFOW(fd,0)].pos[0]);
  15135. buyingstore_open(sd, account_id);
  15136. }
  15137. /// Sends buying store item list (ZC_ACK_ITEMLIST_BUYING_STORE).
  15138. /// 0818 <packet len>.W <account id>.L <store id>.L <limit zeny>.L { <price>.L <amount>.W <type>.B <name id>.W }*
  15139. void clif_buyingstore_itemlist(struct map_session_data* sd, struct map_session_data* pl_sd)
  15140. {
  15141. int fd = sd->fd;
  15142. unsigned int i;
  15143. WFIFOHEAD(fd,16+pl_sd->buyingstore.slots*9);
  15144. WFIFOW(fd,0) = 0x818;
  15145. WFIFOW(fd,2) = 16+pl_sd->buyingstore.slots*9;
  15146. WFIFOL(fd,4) = pl_sd->bl.id;
  15147. WFIFOL(fd,8) = pl_sd->buyer_id;
  15148. WFIFOL(fd,12) = pl_sd->buyingstore.zenylimit;
  15149. for( i = 0; i < pl_sd->buyingstore.slots; i++ )
  15150. {
  15151. WFIFOL(fd,16+i*9) = pl_sd->buyingstore.items[i].price;
  15152. 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.
  15153. WFIFOB(fd,22+i*9) = itemtype(pl_sd->buyingstore.items[i].nameid);
  15154. WFIFOW(fd,23+i*9) = pl_sd->buyingstore.items[i].nameid;
  15155. }
  15156. WFIFOSET(fd,WFIFOW(fd,2));
  15157. }
  15158. /// Request to sell items to a buying store (CZ_REQ_TRADE_BUYING_STORE).
  15159. /// 0819 <packet len>.W <account id>.L <store id>.L { <index>.W <name id>.W <amount>.W }*
  15160. static void clif_parse_ReqTradeBuyingStore(int fd, struct map_session_data* sd)
  15161. {
  15162. const unsigned int blocksize = 6;
  15163. uint8* itemlist;
  15164. uint32 account_id;
  15165. unsigned int count, packet_len, buyer_id;
  15166. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15167. packet_len = RFIFOW(fd,info->pos[0]);
  15168. if( packet_len < 12 )
  15169. {// minimum packet length
  15170. ShowError("clif_parse_ReqTradeBuyingStore: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 12, packet_len, sd->bl.id);
  15171. return;
  15172. }
  15173. account_id = RFIFOL(fd,info->pos[1]);
  15174. buyer_id = RFIFOL(fd,info->pos[2]);
  15175. itemlist = RFIFOP(fd,info->pos[3]);
  15176. // so that buyingstore_trade knows, how many elements it has access to
  15177. packet_len-= info->pos[3];
  15178. if( packet_len%blocksize )
  15179. {
  15180. 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);
  15181. return;
  15182. }
  15183. count = packet_len/blocksize;
  15184. buyingstore_trade(sd, account_id, buyer_id, itemlist, count);
  15185. }
  15186. /// Notifies the buyer, that the buying store has been closed due to a post-trade condition (ZC_FAILED_TRADE_BUYING_STORE_TO_BUYER).
  15187. /// 081a <result>.W
  15188. /// result:
  15189. /// 3 = "All items within the buy limit were purchased." (0x6cf, MSI_BUYINGSTORE_TRADE_OVERLIMITZENY)
  15190. /// 4 = "All items were purchased." (0x6d0, MSI_BUYINGSTORE_TRADE_BUYCOMPLETE)
  15191. /// ? = nothing
  15192. void clif_buyingstore_trade_failed_buyer(struct map_session_data* sd, short result)
  15193. {
  15194. int fd = sd->fd;
  15195. WFIFOHEAD(fd,packet_len(0x81a));
  15196. WFIFOW(fd,0) = 0x81a;
  15197. WFIFOW(fd,2) = result;
  15198. WFIFOSET(fd,packet_len(0x81a));
  15199. }
  15200. /// Updates the zeny limit and an item in the buying store item list.
  15201. /// 081b <name id>.W <amount>.W <limit zeny>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE)
  15202. /// 09e6 <name id>.W <amount>.W <zeny>.L <limit zeny>.L <GID>.L <Date>.L (ZC_UPDATE_ITEM_FROM_BUYING_STORE2)
  15203. void clif_buyingstore_update_item(struct map_session_data* sd, unsigned short nameid, unsigned short amount, uint32 char_id, int zeny) {
  15204. #if PACKETVER < 20141016 // TODO : not sure for client date [Napster]
  15205. const int cmd = 0x81b;
  15206. #else
  15207. const int cmd = 0x9e6;
  15208. #endif
  15209. int offset = 0;
  15210. int fd = sd->fd;
  15211. WFIFOHEAD(fd,packet_len(cmd));
  15212. WFIFOW(fd,0) = cmd;
  15213. WFIFOW(fd,2) = nameid;
  15214. WFIFOW(fd,4) = amount; // amount of nameid received
  15215. #if PACKETVER >= 20141016
  15216. WFIFOL(fd,6) = zeny; // zeny
  15217. offset += 4;
  15218. #endif
  15219. WFIFOL(fd,6+offset) = sd->buyingstore.zenylimit;
  15220. #if PACKETVER >= 20141016
  15221. WFIFOL(fd,10+offset) = char_id; // GID
  15222. WFIFOL(fd,14+offset) = (int)time(NULL); // date
  15223. #endif
  15224. WFIFOSET(fd,packet_len(cmd));
  15225. }
  15226. /// Deletes item from inventory, that was sold to a buying store (ZC_ITEM_DELETE_BUYING_STORE).
  15227. /// 081c <index>.W <amount>.W <price>.L
  15228. /// message:
  15229. /// "%s (%d) were sold at %dz." (0x6d2, MSI_BUYINGSTORE_TRADE_SELLCOMPLETE)
  15230. ///
  15231. /// NOTE: This function has to be called _instead_ of clif_delitem/clif_dropitem.
  15232. void clif_buyingstore_delete_item(struct map_session_data* sd, short index, unsigned short amount, int price)
  15233. {
  15234. int fd = sd->fd;
  15235. WFIFOHEAD(fd,packet_len(0x81c));
  15236. WFIFOW(fd,0) = 0x81c;
  15237. WFIFOW(fd,2) = index+2;
  15238. WFIFOW(fd,4) = amount;
  15239. WFIFOL(fd,6) = price; // price per item, client calculates total Zeny by itself
  15240. WFIFOSET(fd,packet_len(0x81c));
  15241. }
  15242. /// Notifies the seller, that a buying store trade failed (ZC_FAILED_TRADE_BUYING_STORE_TO_SELLER).
  15243. /// 0824 <result>.W <name id>.W
  15244. /// result:
  15245. /// 5 = "The deal has failed." (0x39, MSI_DEAL_FAIL)
  15246. /// 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)
  15247. /// 7 = "The trade failed, because the buyer is lacking required balance." (0x6d1, MSI_BUYINGSTORE_TRADE_LACKBUYERZENY)
  15248. /// ? = nothing
  15249. void clif_buyingstore_trade_failed_seller(struct map_session_data* sd, short result, unsigned short nameid)
  15250. {
  15251. int fd = sd->fd;
  15252. WFIFOHEAD(fd,packet_len(0x824));
  15253. WFIFOW(fd,0) = 0x824;
  15254. WFIFOW(fd,2) = result;
  15255. WFIFOW(fd,4) = nameid;
  15256. WFIFOSET(fd,packet_len(0x824));
  15257. }
  15258. /// Search Store Info System
  15259. ///
  15260. /// Request to search for stores (CZ_SEARCH_STORE_INFO).
  15261. /// 0835 <packet len>.W <type>.B <max price>.L <min price>.L <name id count>.B <card count>.B { <name id>.W }* { <card>.W }*
  15262. /// type:
  15263. /// 0 = Vending
  15264. /// 1 = Buying Store
  15265. ///
  15266. /// NOTE: The client determines the item ids by specifying a name and optionally,
  15267. /// amount of card slots. If the client does not know about the item it
  15268. /// cannot be searched.
  15269. static void clif_parse_SearchStoreInfo(int fd, struct map_session_data* sd)
  15270. {
  15271. const unsigned int blocksize = 2;
  15272. const uint8* itemlist;
  15273. const uint8* cardlist;
  15274. unsigned char type;
  15275. unsigned int min_price, max_price, packet_len, count, item_count, card_count;
  15276. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15277. packet_len = RFIFOW(fd,info->pos[0]);
  15278. if( packet_len < 15 )
  15279. {// minimum packet length
  15280. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected length=%u, length=%u, account_id=%d).\n", 15, packet_len, sd->bl.id);
  15281. return;
  15282. }
  15283. type = RFIFOB(fd,info->pos[1]);
  15284. max_price = RFIFOL(fd,info->pos[2]);
  15285. min_price = RFIFOL(fd,info->pos[3]);
  15286. item_count = RFIFOB(fd,info->pos[4]);
  15287. card_count = RFIFOB(fd,info->pos[5]);
  15288. itemlist = RFIFOP(fd,info->pos[6]);
  15289. cardlist = RFIFOP(fd,info->pos[6]+blocksize*item_count);
  15290. // check, if there is enough data for the claimed count of items
  15291. packet_len-= info->pos[6];
  15292. if( packet_len%blocksize )
  15293. {
  15294. ShowError("clif_parse_SearchStoreInfo: Unexpected item list size %u (account_id=%d, block size=%u)\n", packet_len, sd->bl.id, blocksize);
  15295. return;
  15296. }
  15297. count = packet_len/blocksize;
  15298. if( count < item_count+card_count )
  15299. {
  15300. ShowError("clif_parse_SearchStoreInfo: Malformed packet (expected count=%u, count=%u, account_id=%d).\n", item_count+card_count, count, sd->bl.id);
  15301. return;
  15302. }
  15303. searchstore_query(sd, type, min_price, max_price, (const unsigned short*)itemlist, item_count, (const unsigned short*)cardlist, card_count);
  15304. }
  15305. /// Results for a store search request (ZC_SEARCH_STORE_INFO_ACK).
  15306. /// 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 }*
  15307. /// is first page:
  15308. /// 0 = appends to existing results
  15309. /// 1 = clears previous results before displaying this result set
  15310. /// is next page:
  15311. /// 0 = no "next" label
  15312. /// 1 = "next" label to retrieve more results
  15313. void clif_search_store_info_ack(struct map_session_data* sd)
  15314. {
  15315. #if PACKETVER >= 20150225
  15316. const unsigned int blocksize = MESSAGE_SIZE+26+5*5;
  15317. #else
  15318. const unsigned int blocksize = MESSAGE_SIZE+26;
  15319. #endif
  15320. int fd = sd->fd;
  15321. unsigned int i, start, end;
  15322. start = sd->searchstore.pages*SEARCHSTORE_RESULTS_PER_PAGE;
  15323. end = umin(sd->searchstore.count, start+SEARCHSTORE_RESULTS_PER_PAGE);
  15324. WFIFOHEAD(fd,7+(end-start)*blocksize);
  15325. WFIFOW(fd,0) = 0x836;
  15326. WFIFOW(fd,2) = 7+(end-start)*blocksize;
  15327. WFIFOB(fd,4) = !sd->searchstore.pages;
  15328. WFIFOB(fd,5) = searchstore_querynext(sd);
  15329. WFIFOB(fd,6) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15330. for( i = start; i < end; i++ ) {
  15331. struct s_search_store_info_item* ssitem = &sd->searchstore.items[i];
  15332. struct item it;
  15333. WFIFOL(fd,i*blocksize+ 7) = ssitem->store_id;
  15334. WFIFOL(fd,i*blocksize+11) = ssitem->account_id;
  15335. memcpy(WFIFOP(fd,i*blocksize+15), ssitem->store_name, MESSAGE_SIZE);
  15336. WFIFOW(fd,i*blocksize+15+MESSAGE_SIZE) = ssitem->nameid;
  15337. WFIFOB(fd,i*blocksize+17+MESSAGE_SIZE) = itemtype(ssitem->nameid);
  15338. WFIFOL(fd,i*blocksize+18+MESSAGE_SIZE) = ssitem->price;
  15339. WFIFOW(fd,i*blocksize+22+MESSAGE_SIZE) = ssitem->amount;
  15340. WFIFOB(fd,i*blocksize+24+MESSAGE_SIZE) = ssitem->refine;
  15341. // make-up an item for clif_addcards
  15342. memset(&it, 0, sizeof(it));
  15343. memcpy(&it.card, &ssitem->card, sizeof(it.card));
  15344. it.nameid = ssitem->nameid;
  15345. it.amount = ssitem->amount;
  15346. clif_addcards(WFIFOP(fd,i*blocksize+25+MESSAGE_SIZE), &it);
  15347. clif_add_random_options(WFIFOP(fd,i*blocksize+31+MESSAGE_SIZE), &it);
  15348. }
  15349. WFIFOSET(fd,WFIFOW(fd,2));
  15350. }
  15351. /// Notification of failure when searching for stores (ZC_SEARCH_STORE_INFO_FAILED).
  15352. /// 0837 <reason>.B
  15353. /// reason:
  15354. /// 0 = "No matching stores were found." (0x70b)
  15355. /// 1 = "There are too many results. Please enter more detailed search term." (0x6f8)
  15356. /// 2 = "You cannot search anymore." (0x706)
  15357. /// 3 = "You cannot search yet." (0x708)
  15358. /// 4 = "No sale (purchase) information available." (0x705)
  15359. void clif_search_store_info_failed(struct map_session_data* sd, unsigned char reason)
  15360. {
  15361. int fd = sd->fd;
  15362. WFIFOHEAD(fd,packet_len(0x837));
  15363. WFIFOW(fd,0) = 0x837;
  15364. WFIFOB(fd,2) = reason;
  15365. WFIFOSET(fd,packet_len(0x837));
  15366. }
  15367. /// Request to display next page of results (CZ_SEARCH_STORE_INFO_NEXT_PAGE).
  15368. /// 0838
  15369. static void clif_parse_SearchStoreInfoNextPage(int fd, struct map_session_data* sd)
  15370. {
  15371. searchstore_next(sd);
  15372. }
  15373. /// Opens the search store window (ZC_OPEN_SEARCH_STORE_INFO).
  15374. /// 083a <type>.W <remaining uses>.B
  15375. /// type:
  15376. /// 0 = Search Stores
  15377. /// 1 = Search Stores (Cash), asks for confirmation, when clicking a store
  15378. void clif_open_search_store_info(struct map_session_data* sd)
  15379. {
  15380. int fd = sd->fd;
  15381. WFIFOHEAD(fd,packet_len(0x83a));
  15382. WFIFOW(fd,0) = 0x83a;
  15383. WFIFOW(fd,2) = sd->searchstore.effect;
  15384. #if PACKETVER > 20100701
  15385. WFIFOB(fd,4) = (unsigned char)umin(sd->searchstore.uses, UINT8_MAX);
  15386. #endif
  15387. WFIFOSET(fd,packet_len(0x83a));
  15388. }
  15389. /// Request to close the store search window (CZ_CLOSE_SEARCH_STORE_INFO).
  15390. /// 083b
  15391. static void clif_parse_CloseSearchStoreInfo(int fd, struct map_session_data* sd)
  15392. {
  15393. searchstore_close(sd);
  15394. }
  15395. /// Request to invoke catalog effect on a store from search results (CZ_SSILIST_ITEM_CLICK).
  15396. /// 083c <account id>.L <store id>.L <nameid>.W
  15397. static void clif_parse_SearchStoreInfoListItemClick(int fd, struct map_session_data* sd)
  15398. {
  15399. unsigned short nameid;
  15400. uint32 account_id, store_id;
  15401. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15402. account_id = RFIFOL(fd,info->pos[0]);
  15403. store_id = RFIFOL(fd,info->pos[1]);
  15404. nameid = RFIFOW(fd,info->pos[2]);
  15405. searchstore_click(sd, account_id, store_id, nameid);
  15406. }
  15407. /// Notification of the store position on current map (ZC_SSILIST_ITEM_CLICK_ACK).
  15408. /// 083d <xPos>.W <yPos>.W
  15409. void clif_search_store_info_click_ack(struct map_session_data* sd, short x, short y)
  15410. {
  15411. int fd = sd->fd;
  15412. WFIFOHEAD(fd,packet_len(0x83d));
  15413. WFIFOW(fd,0) = 0x83d;
  15414. WFIFOW(fd,2) = x;
  15415. WFIFOW(fd,4) = y;
  15416. WFIFOSET(fd,packet_len(0x83d));
  15417. }
  15418. /// Parse function for packet debugging.
  15419. void clif_parse_debug(int fd,struct map_session_data *sd)
  15420. {
  15421. int cmd, packet_len;
  15422. // clif_parse ensures, that there is at least 2 bytes of data
  15423. cmd = RFIFOW(fd,0);
  15424. if( sd ) {
  15425. packet_len = packet_db[cmd].len;
  15426. if( packet_len == 0 )
  15427. {// unknown
  15428. packet_len = RFIFOREST(fd);
  15429. }
  15430. else if( packet_len == -1 )
  15431. {// variable length
  15432. packet_len = RFIFOW(fd,2); // clif_parse ensures, that this amount of data is already received
  15433. }
  15434. 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);
  15435. }
  15436. else
  15437. {
  15438. packet_len = RFIFOREST(fd);
  15439. ShowDebug("Packet debug of 0x%04X (length %d), session #%d\n", cmd, packet_len, fd);
  15440. }
  15441. ShowDump(RFIFOP(fd,0), packet_len);
  15442. }
  15443. /*==========================================
  15444. * Server tells client to display a window similar to Magnifier (item) one
  15445. * Server populates the window with avilable elemental converter options according to player's inventory
  15446. *------------------------------------------*/
  15447. int clif_elementalconverter_list(struct map_session_data *sd) {
  15448. int i,c,view,fd;
  15449. nullpo_ret(sd);
  15450. /// Main client packet processing function
  15451. fd=sd->fd;
  15452. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB *2+4);
  15453. WFIFOW(fd, 0)=0x1ad;
  15454. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  15455. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,23, 1) ){
  15456. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  15457. WFIFOW(fd,c*2+ 4)= view;
  15458. else
  15459. WFIFOW(fd,c*2+ 4)= skill_produce_db[i].nameid;
  15460. c++;
  15461. }
  15462. }
  15463. WFIFOW(fd,2) = c*2+4;
  15464. WFIFOSET(fd, WFIFOW(fd,2));
  15465. if (c > 0) {
  15466. sd->menuskill_id = SA_CREATECON;
  15467. sd->menuskill_val = c;
  15468. }
  15469. return 0;
  15470. }
  15471. /**
  15472. * Rune Knight
  15473. **/
  15474. void clif_millenniumshield(struct block_list *bl, short shields) {
  15475. #if PACKETVER >= 20081217
  15476. unsigned char buf[10];
  15477. WBUFW(buf,0) = 0x440;
  15478. WBUFL(buf,2) = bl->id;
  15479. WBUFW(buf,6) = shields;
  15480. WBUFW(buf,8) = 0;
  15481. clif_send(buf,packet_len(0x440),bl,AREA);
  15482. #endif
  15483. }
  15484. /**
  15485. * Warlock
  15486. **/
  15487. /*==========================================
  15488. * Spellbook list [LimitLine/3CeAM]
  15489. *------------------------------------------*/
  15490. int clif_spellbook_list(struct map_session_data *sd)
  15491. {
  15492. int i, c;
  15493. int fd;
  15494. nullpo_ret(sd);
  15495. fd = sd->fd;
  15496. WFIFOHEAD(fd, 8 * 8 + 8);
  15497. WFIFOW(fd,0) = 0x1ad;
  15498. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ )
  15499. {
  15500. if( itemdb_is_spellbook2(sd->inventory.u.items_inventory[i].nameid) )
  15501. {
  15502. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15503. c++;
  15504. }
  15505. }
  15506. if( c > 0 )
  15507. {
  15508. WFIFOW(fd,2) = c * 2 + 4;
  15509. WFIFOSET(fd, WFIFOW(fd, 2));
  15510. sd->menuskill_id = WL_READING_SB;
  15511. sd->menuskill_val = c;
  15512. }
  15513. else{
  15514. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15515. clif_skill_fail(sd, WL_READING_SB, USESKILL_FAIL_SPELLBOOK, 0);
  15516. }
  15517. return 1;
  15518. }
  15519. /**
  15520. * Mechanic
  15521. **/
  15522. /*==========================================
  15523. * Magic Decoy Material List
  15524. *------------------------------------------*/
  15525. int clif_magicdecoy_list(struct map_session_data *sd, uint16 skill_lv, short x, short y) {
  15526. int i, c;
  15527. int fd;
  15528. nullpo_ret(sd);
  15529. fd = sd->fd;
  15530. WFIFOHEAD(fd, 8 * 8 + 8);
  15531. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  15532. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  15533. if( itemdb_group_item_exists(IG_ELEMENT, sd->inventory.u.items_inventory[i].nameid) ) {
  15534. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15535. c ++;
  15536. }
  15537. }
  15538. if( c > 0 ) {
  15539. sd->menuskill_id = NC_MAGICDECOY;
  15540. sd->menuskill_val = skill_lv;
  15541. sd->sc.comet_x = x;
  15542. sd->sc.comet_y = y;
  15543. WFIFOW(fd,2) = c * 2 + 4;
  15544. WFIFOSET(fd, WFIFOW(fd, 2));
  15545. } else {
  15546. clif_skill_fail(sd,NC_MAGICDECOY,USESKILL_FAIL_LEVEL,0);
  15547. return 0;
  15548. }
  15549. return 1;
  15550. }
  15551. /*==========================================
  15552. * Guillotine Cross Poisons List
  15553. *------------------------------------------*/
  15554. int clif_poison_list(struct map_session_data *sd, uint16 skill_lv) {
  15555. int i, c;
  15556. int fd;
  15557. nullpo_ret(sd);
  15558. fd = sd->fd;
  15559. WFIFOHEAD(fd, 8 * 8 + 8);
  15560. WFIFOW(fd,0) = 0x1ad; // This is the official packet. [pakpil]
  15561. for( i = 0, c = 0; i < MAX_INVENTORY; i ++ ) {
  15562. if( itemdb_group_item_exists(IG_POISON, sd->inventory.u.items_inventory[i].nameid) ) {
  15563. WFIFOW(fd, c * 2 + 4) = sd->inventory.u.items_inventory[i].nameid;
  15564. c ++;
  15565. }
  15566. }
  15567. if( c > 0 ) {
  15568. sd->menuskill_id = GC_POISONINGWEAPON;
  15569. sd->menuskill_val = skill_lv;
  15570. WFIFOW(fd,2) = c * 2 + 4;
  15571. WFIFOSET(fd, WFIFOW(fd, 2));
  15572. } else {
  15573. clif_skill_fail(sd,GC_POISONINGWEAPON,USESKILL_FAIL_GUILLONTINE_POISON,0);
  15574. return 0;
  15575. }
  15576. return 1;
  15577. }
  15578. /// 0442 <Length>.W <count>.L <Skill_list>.W (ZC_SKILL_SELECT_REQUEST).
  15579. int clif_autoshadowspell_list(struct map_session_data *sd) {
  15580. int fd, i, c;
  15581. nullpo_ret(sd);
  15582. fd = sd->fd;
  15583. if( !fd )
  15584. return 0;
  15585. if( sd->menuskill_id == SC_AUTOSHADOWSPELL )
  15586. return 0;
  15587. WFIFOHEAD(fd, 2 * 6 + 4);
  15588. WFIFOW(fd,0) = 0x442;
  15589. //AEGIS listed the specified skills that available for SC_AUTOSHADOWSPELL
  15590. for( i = 0, c = 0; i < MAX_SKILL; i++ )
  15591. if( sd->status.skill[i].flag == SKILL_FLAG_PLAGIARIZED && sd->status.skill[i].id > 0 &&
  15592. (skill_get_inf2(sd->status.skill[i].id)&INF2_AUTOSHADOWSPELL))
  15593. {
  15594. WFIFOW(fd,8+c*2) = sd->status.skill[i].id;
  15595. c++;
  15596. }
  15597. if( c > 0 ) {
  15598. WFIFOW(fd,2) = 8 + c * 2;
  15599. WFIFOL(fd,4) = c;
  15600. WFIFOSET(fd,WFIFOW(fd,2));
  15601. sd->menuskill_id = SC_AUTOSHADOWSPELL;
  15602. sd->menuskill_val = c;
  15603. } else {
  15604. status_change_end(&sd->bl,SC_STOP,INVALID_TIMER);
  15605. clif_skill_fail(sd,SC_AUTOSHADOWSPELL,USESKILL_FAIL_IMITATION_SKILL_NONE,0);
  15606. }
  15607. return 1;
  15608. }
  15609. /*===========================================
  15610. * Skill list for Four Elemental Analysis
  15611. * and Change Material skills.
  15612. * 07e3 <type>.L (ZC_ITEMLISTWIN_OPEN).
  15613. *------------------------------------------*/
  15614. int clif_skill_itemlistwindow( struct map_session_data *sd, uint16 skill_id, uint16 skill_lv ) {
  15615. #if PACKETVER >= 20090922
  15616. int fd = sd->fd;
  15617. nullpo_ret(sd);
  15618. sd->menuskill_id = skill_id; // To prevent hacking.
  15619. sd->menuskill_val = skill_lv;
  15620. if( skill_id == GN_CHANGEMATERIAL )
  15621. skill_lv = 0; // Changematerial
  15622. WFIFOHEAD(fd, packet_len(0x7e3));
  15623. WFIFOW(fd,0) = 0x7e3;
  15624. WFIFOL(fd,2) = skill_lv;
  15625. WFIFOL(fd,4) = 0;
  15626. WFIFOSET(fd, packet_len(0x7e3));
  15627. #endif
  15628. return 1;
  15629. }
  15630. /*==========================================
  15631. * Select a skill into a given list (used by SC_AUTOSHADOWSPELL)
  15632. * 0443 <type>.L <skill_id>.W (CZ_SKILL_SELECT_RESPONSE)
  15633. * RFIFOL(fd,2) - type (currently not used)
  15634. *------------------------------------------*/
  15635. void clif_parse_SkillSelectMenu(int fd, struct map_session_data *sd) {
  15636. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15637. //int type = RFIFOL(fd,info->pos[0]); //WHY_LOWERVER_COMPATIBILITY = 0x0, WHY_SC_AUTOSHADOWSPELL = 0x1,
  15638. if( sd->menuskill_id != SC_AUTOSHADOWSPELL )
  15639. return;
  15640. if( pc_istrading(sd) ) {
  15641. clif_skill_fail(sd,sd->ud.skill_id,USESKILL_FAIL_LEVEL,0);
  15642. clif_menuskill_clear(sd);
  15643. return;
  15644. }
  15645. skill_select_menu(sd,RFIFOW(fd,info->pos[1]));
  15646. clif_menuskill_clear(sd);
  15647. }
  15648. /// Kagerou/Oboro amulet spirit (ZC_SPIRITS_ATTRIBUTE).
  15649. /// 08cf <id>.L <type>.W <num>.W
  15650. void clif_spiritcharm(struct map_session_data *sd) {
  15651. unsigned char buf[10];
  15652. nullpo_retv(sd);
  15653. WBUFW(buf,0) = 0x08cf;
  15654. WBUFL(buf,2) = sd->bl.id;
  15655. WBUFW(buf,6) = sd->spiritcharm_type;
  15656. WBUFW(buf,8) = sd->spiritcharm;
  15657. clif_send(buf, packet_len(0x08cf), &sd->bl, AREA);
  15658. }
  15659. /// Move Item from or to Personal Tab (CZ_WHATSOEVER) [FE]
  15660. /// 0907 <index>.W
  15661. ///
  15662. /// R 0908 <index>.w <type>.b
  15663. /// type:
  15664. /// 0 = move item to personal tab
  15665. /// 1 = move item to normal tab
  15666. void clif_parse_MoveItem(int fd, struct map_session_data *sd) {
  15667. #if PACKETVER >= 20111122
  15668. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15669. int index = RFIFOW(fd,info->pos[0]) - 2;
  15670. int type = RFIFOB(fd, info->pos[1]);
  15671. /* can't move while dead. */
  15672. if(pc_isdead(sd)) {
  15673. return;
  15674. }
  15675. if (index < 0 || index >= MAX_INVENTORY)
  15676. return;
  15677. if ( sd->inventory.u.items_inventory[index].favorite && type == 1 )
  15678. sd->inventory.u.items_inventory[index].favorite = 0;
  15679. else if( type == 0 )
  15680. sd->inventory.u.items_inventory[index].favorite = 1;
  15681. else
  15682. return;/* nothing to do. */
  15683. clif_favorite_item(sd, index);
  15684. #endif
  15685. }
  15686. /// Items that are in favorite tab of inventory (ZC_ITEM_FAVORITE).
  15687. /// 0900 <index>.W <favorite>.B
  15688. void clif_favorite_item(struct map_session_data* sd, unsigned short index) {
  15689. int fd = sd->fd;
  15690. WFIFOHEAD(fd,packet_len(0x908));
  15691. WFIFOW(fd,0) = 0x908;
  15692. WFIFOW(fd,2) = index+2;
  15693. WFIFOL(fd,4) = (sd->inventory.u.items_inventory[index].favorite == 1) ? 0 : 1;
  15694. WFIFOSET(fd,packet_len(0x908));
  15695. }
  15696. /// 08d2 <id>.L <Pos X>.W <Pos Y>.W (ZC_FASTMOVE).
  15697. void clif_snap( struct block_list *bl, short x, short y ) {
  15698. unsigned char buf[10];
  15699. WBUFW(buf,0) = 0x8d2;
  15700. WBUFL(buf,2) = bl->id;
  15701. WBUFW(buf,6) = x;
  15702. WBUFW(buf,8) = y;
  15703. if( disguised(bl) )
  15704. {
  15705. clif_send(buf, packet_len(0x8d2), bl, AREA_WOS);
  15706. WBUFL(buf,2) = -bl->id;
  15707. clif_send(buf, packet_len(0x8d2), bl, SELF);
  15708. } else
  15709. clif_send(buf,packet_len(0x8d2),bl, AREA);
  15710. }
  15711. /// 0977 <id>.L <HP>.L <maxHP>.L (ZC_HP_INFO).
  15712. void clif_monster_hp_bar( struct mob_data* md, int fd ) {
  15713. #if PACKETVER >= 20120404
  15714. WFIFOHEAD(fd,packet_len(0x977));
  15715. WFIFOW(fd,0) = 0x977;
  15716. WFIFOL(fd,2) = md->bl.id;
  15717. WFIFOL(fd,6) = md->status.hp;
  15718. WFIFOL(fd,10) = md->status.max_hp;
  15719. WFIFOSET(fd,packet_len(0x977));
  15720. #endif
  15721. }
  15722. /* [Ind] placeholder for unsupported incoming packets (avoids server disconnecting client) */
  15723. void __attribute__ ((unused)) clif_parse_dull(int fd, struct map_session_data *sd) {
  15724. return;
  15725. }
  15726. void clif_partytickack(struct map_session_data* sd, bool flag) {
  15727. WFIFOHEAD(sd->fd, packet_len(0x2c9));
  15728. WFIFOW(sd->fd,0) = 0x2c9;
  15729. WFIFOB(sd->fd,2) = flag;
  15730. WFIFOSET(sd->fd, packet_len(0x2c9));
  15731. }
  15732. /// Ack world info (ZC_ACK_BEFORE_WORLD_INFO)
  15733. /// 0979 <world name>.24B <char name>.24B
  15734. void clif_ackworldinfo(struct map_session_data* sd) {
  15735. int fd;
  15736. nullpo_retv(sd);
  15737. fd = sd->fd;
  15738. WFIFOHEAD(fd,packet_len(0x979));
  15739. WFIFOW(fd,0)=0x979;
  15740. //AID -> world name ?
  15741. safestrncpy(WFIFOCP(fd,2), "" /* World name */, 24);
  15742. safestrncpy(WFIFOCP(fd,26), sd->status.name, NAME_LENGTH);
  15743. WFIFOSET(fd,packet_len(0x979));
  15744. }
  15745. /// req world info (CZ_REQ_BEFORE_WORLD_INFO)
  15746. /// 0978 <AID>.L
  15747. void clif_parse_reqworldinfo(int fd,struct map_session_data *sd) {
  15748. //uint32 aid = RFIFOL(fd,2); //should we trust client ?
  15749. if(sd)
  15750. clif_ackworldinfo(sd);
  15751. }
  15752. /// unknown usage (CZ_BLOCKING_PLAY_CANCEL)
  15753. /// 0447
  15754. void clif_parse_blocking_playcancel(int fd,struct map_session_data *sd) {
  15755. //if(sd)
  15756. ;
  15757. }
  15758. /// req world info (CZ_CLIENT_VERSION)
  15759. /// 044A <version>.L
  15760. void clif_parse_client_version(int fd, struct map_session_data *sd) {
  15761. //if(sd)
  15762. ;
  15763. }
  15764. /// Ranking list
  15765. /// ranking pointlist { <name>.24B <point>.L }*10
  15766. void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, enum e_rank rankingtype){
  15767. struct fame_list* list;
  15768. int i, size = MAX_FAME_LIST;
  15769. switch(rankingtype) {
  15770. case RANK_BLACKSMITH: list = smith_fame_list; break;
  15771. case RANK_ALCHEMIST: list = chemist_fame_list; break;
  15772. case RANK_TAEKWON: list = taekwon_fame_list; break;
  15773. // PK currently unsupported
  15774. case RANK_KILLER: list = NULL; size = 0; break;
  15775. default:
  15776. ShowError( "clif_sub_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  15777. return;
  15778. }
  15779. //Packet size limits this list to 10 elements. [Skotlex]
  15780. for (i = 0; i < min(10,size); i++) {
  15781. if (list[i].id > 0) {
  15782. const char* name;
  15783. if (strcmp(list[i].name, "-") == 0 &&
  15784. (name = map_charid2nick(list[i].id)) != NULL)
  15785. {
  15786. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), name, NAME_LENGTH);
  15787. } else {
  15788. safestrncpy(WBUFCP(buf,idx + NAME_LENGTH * i), list[i].name, NAME_LENGTH);
  15789. }
  15790. } else {
  15791. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "None", NAME_LENGTH);
  15792. }
  15793. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = list[i].fame; //points
  15794. }
  15795. for(;i < 10; i++) { //In case the MAX is less than 10.
  15796. safestrncpy(WBUFCP(buf, idx + NAME_LENGTH * i), "Unavailable", NAME_LENGTH);
  15797. WBUFL(buf, idx+NAME_LENGTH*10 + i * 4) = 0;
  15798. }
  15799. }
  15800. /// Request for the blacksmith ranklist.
  15801. /// /blacksmith command sends this packet to the server.
  15802. /// 0217 (CZ_BLACKSMITH_RANK)
  15803. void clif_parse_Blacksmith( int fd, struct map_session_data *sd ){
  15804. clif_ranklist(sd,RANK_BLACKSMITH);
  15805. }
  15806. /// Request for the alchemist ranklist.
  15807. /// /alchemist command sends this packet to the server.
  15808. /// 0218 (CZ_ALCHEMIST_RANK)
  15809. void clif_parse_Alchemist( int fd, struct map_session_data *sd ){
  15810. clif_ranklist(sd,RANK_ALCHEMIST);
  15811. }
  15812. /// Request for the taekwon ranklist.
  15813. /// /taekwon command sends this packet to the server.
  15814. /// 0225 (CZ_TAEKWON_RANK)
  15815. void clif_parse_Taekwon( int fd, struct map_session_data *sd ){
  15816. clif_ranklist(sd,RANK_TAEKWON);
  15817. }
  15818. /// Request for the killer ranklist.
  15819. /// /pk command sends this packet to the server.
  15820. /// 0237 (CZ_KILLER_RANK)
  15821. void clif_parse_RankingPk( int fd, struct map_session_data *sd ){
  15822. clif_ranklist(sd,RANK_KILLER);
  15823. }
  15824. /// 0219 { <name>.24B }*10 { <point>.L }*10 (ZC_BLACKSMITH_RANK)
  15825. /// 021a { <name>.24B }*10 { <point>.L }*10 (ZC_ALCHEMIST_RANK)
  15826. /// 0226 { <name>.24B }*10 { <point>.L }*10 (ZC_TAEKWON_RANK)
  15827. /// 0238 { <name>.24B }*10 { <point>.L }*10 (ZC_KILLER_RANK)
  15828. /// 097d <RankingType>.W {<CharName>.24B <point>L}*10 <mypoint>L (ZC_ACK_RANKING)
  15829. void clif_ranklist(struct map_session_data *sd, int16 rankingType) {
  15830. enum e_rank rank;
  15831. #if PACKETVER < 20130710
  15832. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+2];
  15833. short cmd;
  15834. switch( rankingType ){
  15835. case RANK_BLACKSMITH: cmd = 0x219; break;
  15836. case RANK_ALCHEMIST: cmd = 0x21a; break;
  15837. case RANK_TAEKWON: cmd = 0x226; break;
  15838. case RANK_KILLER: cmd = 0x238; break;
  15839. default:
  15840. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  15841. return;
  15842. }
  15843. // Can be safely casted here, since we validated it before
  15844. rank = (enum e_rank)rankingType;
  15845. WBUFW(buf,0) = cmd;
  15846. clif_sub_ranklist(buf,2,sd,rank);
  15847. clif_send(buf, packet_len(cmd), &sd->bl, SELF);
  15848. #else
  15849. unsigned char buf[MAX_FAME_LIST * sizeof(struct fame_list)+8];
  15850. int mypoint = 0;
  15851. switch( rankingType ){
  15852. case RANK_BLACKSMITH:
  15853. case RANK_ALCHEMIST:
  15854. case RANK_TAEKWON:
  15855. case RANK_KILLER:
  15856. break;
  15857. default:
  15858. ShowError( "clif_ranklist: Unsupported ranking type '%d'. Please report this.\n", rankingType );
  15859. return;
  15860. }
  15861. // Can be safely casted here, since we validated it before
  15862. rank = (enum e_rank)rankingType;
  15863. WBUFW(buf,0) = 0x97d;
  15864. WBUFW(buf,2) = rank;
  15865. clif_sub_ranklist(buf,4,sd,rank);
  15866. switch(sd->class_&MAPID_UPPERMASK){ //mypoint (checking if valid type)
  15867. case MAPID_BLACKSMITH:
  15868. case MAPID_ALCHEMIST:
  15869. case MAPID_TAEKWON:
  15870. mypoint = sd->status.fame;
  15871. }
  15872. WBUFL(buf,284) = mypoint; //mypoint
  15873. clif_send(buf, 288, &sd->bl, SELF);
  15874. #endif
  15875. }
  15876. /*
  15877. * 097c <type> (CZ_REQ_RANKING)
  15878. * type
  15879. * 0: /blacksmith
  15880. * 1: /alchemist
  15881. * 2: /taekwon
  15882. * 3: /pk
  15883. * */
  15884. void clif_parse_ranklist(int fd,struct map_session_data *sd) {
  15885. struct s_packet_db* info = &packet_db[RFIFOW(fd,0)];
  15886. int16 rankingtype = RFIFOW(fd,info->pos[0]); //type
  15887. clif_ranklist(sd,rankingtype);
  15888. }
  15889. /// Updates the fame rank points for the given ranking.
  15890. /// 021b <points>.L <total points>.L (ZC_BLACKSMITH_POINT)
  15891. /// 021c <points>.L <total points>.L (ZC_ALCHEMIST_POINT)
  15892. /// 0224 <points>.L <total points>.L (ZC_TAEKWON_POINT)
  15893. /// 097e <RankingType>.W <point>.L <TotalPoint>.L (ZC_UPDATE_RANKING_POINT)
  15894. void clif_update_rankingpoint(struct map_session_data *sd, int rankingtype, int point) {
  15895. int fd=sd->fd;
  15896. #if PACKETVER < 20130710
  15897. short cmd;
  15898. switch(rankingtype){
  15899. case RANK_BLACKSMITH: cmd = 0x21b; break;
  15900. case RANK_ALCHEMIST: cmd = 0x21c; break;
  15901. case RANK_TAEKWON: cmd = 0x224; break;
  15902. default:
  15903. ShowError( "clif_update_rankingpoint: Unsupported ranking type '%d'. Please report this.\n", rankingtype );
  15904. return;
  15905. }
  15906. WFIFOHEAD(fd,packet_len(cmd));
  15907. WFIFOW(fd,0) = cmd;
  15908. WFIFOL(fd,2) = point;
  15909. WFIFOL(fd,6) = sd->status.fame;
  15910. WFIFOSET(fd, packet_len(cmd));
  15911. #else
  15912. WFIFOHEAD(fd,packet_len(0x97e));
  15913. WFIFOW(fd,0) = 0x97e;
  15914. WFIFOW(fd,2) = rankingtype;
  15915. WFIFOL(fd,4) = point;
  15916. WFIFOL(fd,8) = sd->status.fame;
  15917. WFIFOSET(fd,packet_len(0x97e));
  15918. #endif
  15919. }
  15920. /**
  15921. * Transmit personal information to player. (rates)
  15922. * 0x08cb <packet len>.W <exp>.W <death>.W <drop>.W <DETAIL_EXP_INFO>7B (ZC_PERSONAL_INFOMATION)
  15923. * <InfoType>.B <Exp>.W <Death>.W <Drop>.W (DETAIL_EXP_INFO 0x08cb)
  15924. * 0x097b <packet len>.W <exp>.L <death>.L <drop>.L <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION2)
  15925. * 0x0981 <packet len>.W <exp>.W <death>.W <drop>.W <activity rate>.W <DETAIL_EXP_INFO>13B (ZC_PERSONAL_INFOMATION_CHN)
  15926. * <InfoType>.B <Exp>.L <Death>.L <Drop>.L (DETAIL_EXP_INFO 0x97b|0981)
  15927. * FIXME!
  15928. * - Find/decide for details of EXP, Drop, and Death penalty rates
  15929. * - For now, we're assuming values for DETAIL_EXP_INFO are:
  15930. * 0 - map adjustment (bexp mapflag), 1 - Premium/VIP adjustment, 2 - Server rate adjustment, 3 - None
  15931. */
  15932. #ifdef VIP_ENABLE
  15933. void clif_display_pinfo(struct map_session_data *sd, int cmdtype) {
  15934. if (sd) {
  15935. struct s_packet_db* info;
  15936. int16 len, szdetails = 13, maxinfotype = PINFO_MAX;
  15937. int cmd = 0, fd, i = 0;
  15938. int tot_baseexp = 100, tot_penalty = 100, tot_drop = 100, factor = 1000;
  15939. int details_bexp[PINFO_MAX];
  15940. int details_drop[PINFO_MAX];
  15941. int details_penalty[PINFO_MAX];
  15942. /**
  15943. * Set for EXP
  15944. */
  15945. //0:PCRoom
  15946. details_bexp[0] = map[sd->bl.m].adjust.bexp;
  15947. if (details_bexp[0] == 100 || !details_bexp[0])
  15948. details_bexp[0] = 0;
  15949. else {
  15950. if (details_bexp[0] < 100) {
  15951. details_bexp[0] = 100 - details_bexp[0];
  15952. details_bexp[0] = 0 - details_bexp[0];
  15953. }
  15954. else
  15955. details_bexp[0] = details_bexp[0] - 100;
  15956. }
  15957. //1:Premium
  15958. if (pc_isvip(sd)) {
  15959. details_bexp[1] = battle_config.vip_base_exp_increase;
  15960. if (details_bexp[1] < 0)
  15961. details_bexp[1] = 0 - details_bexp[1];
  15962. }
  15963. else
  15964. details_bexp[1] = 0;
  15965. //2:Server
  15966. details_bexp[2] = battle_config.base_exp_rate;
  15967. if (details_bexp[2] == 100)
  15968. details_bexp[2] = 0;
  15969. else {
  15970. if (details_bexp[2] < 100) {
  15971. details_bexp[2] = 100 - details_bexp[2];
  15972. details_bexp[2] = 0 - details_bexp[2];
  15973. }
  15974. else
  15975. details_bexp[2] = details_bexp[2] - 100;
  15976. }
  15977. //3:TPLUS
  15978. details_bexp[3] = 0;
  15979. /* End - EXP set*/
  15980. /**
  15981. * Set for Drop rate
  15982. */
  15983. //0:PCRoom
  15984. details_drop[0] = 0;
  15985. //1:Premium
  15986. details_drop[1] = (battle_config.vip_drop_increase * battle_config.item_rate_common) / 100;
  15987. if (pc_isvip(sd)) {
  15988. if (details_drop[1] < 0)
  15989. details_drop[1] = 0 - details_drop[1];
  15990. }
  15991. else
  15992. details_drop[1] = 0;
  15993. //2:Server
  15994. details_drop[2] = battle_config.item_rate_common;
  15995. if (details_drop[2] == 100)
  15996. details_drop[2] = 0;
  15997. else {
  15998. if (details_drop[2] < 100) {
  15999. details_drop[2] = 100 - details_drop[2];
  16000. details_drop[2] = 0 - details_drop[2];
  16001. }
  16002. else
  16003. details_drop[2] = details_drop[2] - 100;
  16004. }
  16005. //3:TPLUS
  16006. details_drop[3] = 0;
  16007. /* End - Drop set*/
  16008. /**
  16009. * Set for Penalty rate
  16010. */
  16011. //! FIXME: Current penalty system makes this announcement unable to give info on + or - rate
  16012. //0:PCRoom
  16013. details_penalty[0] = 0;
  16014. //1:Premium
  16015. if (pc_isvip(sd)) {
  16016. details_penalty[1] = battle_config.vip_exp_penalty_base;
  16017. if (details_penalty[1] == 100)
  16018. details_penalty[1] = 0;
  16019. else {
  16020. if (details_penalty[1] < 100) {
  16021. details_penalty[1] = 100 - details_penalty[1];
  16022. details_penalty[1] = 0 - details_penalty[1];
  16023. }
  16024. else
  16025. details_penalty[1] = details_penalty[1] - 100;
  16026. }
  16027. }
  16028. else
  16029. details_penalty[1] = 0;
  16030. //2:Server
  16031. details_penalty[2] = battle_config.death_penalty_base;
  16032. if (details_penalty[2] == 100)
  16033. details_penalty[2] = 0;
  16034. else {
  16035. if (details_penalty[2] < 100) {
  16036. details_penalty[2] = 100 - details_penalty[2];
  16037. details_penalty[2] = 0 - details_penalty[2];
  16038. }
  16039. else
  16040. details_penalty[2] = details_penalty[2] - 100;
  16041. }
  16042. //3:TPLUS
  16043. details_penalty[3] = 0;
  16044. /* End - Penalty set*/
  16045. cmd = packet_db_ack[cmdtype];
  16046. info = &packet_db[cmd];
  16047. len = info->len; //this is the base len without details
  16048. if(!len) return; //version as packet disable
  16049. if (cmdtype == ZC_PERSONAL_INFOMATION && cmd == 0x08cb) { //0x08cb version
  16050. szdetails = 7;
  16051. factor = 1;
  16052. }
  16053. else if (cmd == 0x097b) {
  16054. tot_baseexp *= factor;
  16055. tot_drop *= factor;
  16056. tot_penalty *= factor;
  16057. }
  16058. fd = sd->fd;
  16059. WFIFOHEAD(fd,len+maxinfotype*szdetails);
  16060. WFIFOW(fd,0) = cmd;
  16061. for (i = 0; i < maxinfotype; i++) {
  16062. WFIFOB(fd,info->pos[4]+(i*szdetails)) = i; //infotype //0 PCRoom, 1 Premium, 2 Server, 3 TPlus
  16063. WFIFOL(fd,info->pos[5]+(i*szdetails)) = details_bexp[i]*factor;
  16064. WFIFOL(fd,info->pos[6]+(i*szdetails)) = details_penalty[i]*factor;
  16065. WFIFOL(fd,info->pos[7]+(i*szdetails)) = details_drop[i]*factor;
  16066. tot_baseexp += details_bexp[i]*factor;
  16067. tot_drop += details_penalty[i]*factor;
  16068. tot_penalty += details_drop[i]*factor;
  16069. len += szdetails;
  16070. }
  16071. WFIFOW(fd,info->pos[0]) = len; //packetlen
  16072. if (cmd == 0x08cb) { //0x08cb version
  16073. WFIFOW(fd,info->pos[1]) = tot_baseexp;
  16074. WFIFOW(fd,info->pos[2]) = tot_drop;
  16075. WFIFOW(fd,info->pos[3]) = tot_penalty;
  16076. }
  16077. else { //2013-08-07aRagexe uses 0x097b
  16078. WFIFOL(fd,info->pos[1]) = tot_baseexp;
  16079. WFIFOL(fd,info->pos[2]) = tot_drop;
  16080. WFIFOL(fd,info->pos[3]) = tot_penalty;
  16081. }
  16082. if (cmdtype == ZC_PERSONAL_INFOMATION_CHN)
  16083. WFIFOW(fd,info->pos[8]) = 0; //activity rate case of event ??
  16084. WFIFOSET(fd,len);
  16085. }
  16086. }
  16087. #endif
  16088. void clif_parse_GMFullStrip(int fd, struct map_session_data *sd) {
  16089. char cmd[30];
  16090. int t_aid = RFIFOL(fd,2);
  16091. safesnprintf(cmd,sizeof(cmd),"%cfullstrip %d",atcommand_symbol,t_aid);
  16092. is_atcommand(fd, sd, cmd, 1);
  16093. }
  16094. /**
  16095. * Marks Crimson Marker target on mini-map to the caster
  16096. * 09C1 <id>.L <x>.W <y>.W (ZC_C_MARKERINFO)
  16097. * @param fd
  16098. * @param bl Crimson Marker target
  16099. **/
  16100. void clif_crimson_marker(struct map_session_data *sd, struct block_list *bl, bool remove) {
  16101. struct s_packet_db* info;
  16102. int cmd = 0;
  16103. int16 len;
  16104. unsigned char buf[11];
  16105. nullpo_retv(sd);
  16106. cmd = packet_db_ack[ZC_C_MARKERINFO];
  16107. if (!cmd)
  16108. cmd = 0x09C1; //default
  16109. info = &packet_db[cmd];
  16110. if (!(len = info->len))
  16111. return;
  16112. WBUFW(buf, 0) = cmd;
  16113. WBUFL(buf, info->pos[0]) = bl->id;
  16114. WBUFW(buf, info->pos[1]) = (remove ? -1 : bl->x);
  16115. WBUFW(buf, info->pos[2]) = (remove ? -1 : bl->y);
  16116. clif_send(buf, len, &sd->bl, SELF);
  16117. }
  16118. /**
  16119. * 02d3 <index>.W (ZC_NOTIFY_BIND_ON_EQUIP)
  16120. **/
  16121. void clif_notify_bindOnEquip(struct map_session_data *sd, int n) {
  16122. struct s_packet_db *info = NULL;
  16123. int cmd = 0;
  16124. nullpo_retv(sd);
  16125. cmd = packet_db_ack[ZC_NOTIFY_BIND_ON_EQUIP];
  16126. info = &packet_db[cmd];
  16127. if (!cmd || !info->len)
  16128. return;
  16129. WFIFOHEAD(sd->fd, info->len);
  16130. WFIFOW(sd->fd, 0) = cmd;
  16131. WFIFOW(sd->fd, info->pos[0]) = n+2;
  16132. WFIFOSET(sd->fd, info->len);
  16133. }
  16134. /**
  16135. * [Ind/Hercules]
  16136. * 08b3 <Length>.W <id>.L <message>.?B (ZC_SHOWSCRIPT)
  16137. **/
  16138. void clif_showscript(struct block_list* bl, const char* message, enum send_target flag) {
  16139. char buf[256];
  16140. size_t len;
  16141. nullpo_retv(bl);
  16142. if(!message)
  16143. return;
  16144. len = strlen(message)+1;
  16145. if( len > sizeof(buf)-8 ) {
  16146. ShowWarning("clif_showscript: Truncating too long message '%s' (len=%d).\n", message, len);
  16147. len = sizeof(buf)-8;
  16148. }
  16149. WBUFW(buf,0) = 0x8b3;
  16150. WBUFW(buf,2) = (uint16)(len+8);
  16151. WBUFL(buf,4) = bl->id;
  16152. safestrncpy(WBUFCP(buf,8), message, len);
  16153. clif_send((unsigned char *) buf, WBUFW(buf,2), bl, flag);
  16154. }
  16155. /**
  16156. * [Ind/Hercules]
  16157. * 07fc <OldMasterAID>.L <NewMasterAID>.L (ZC_CHANGE_GROUP_MASTER)
  16158. **/
  16159. void clif_party_leaderchanged(struct map_session_data *sd, int prev_leader_aid, int new_leader_aid) {
  16160. unsigned char buf[10];
  16161. nullpo_retv(sd);
  16162. WBUFW(buf,0) = 0x7fc;
  16163. WBUFL(buf,2) = prev_leader_aid;
  16164. WBUFL(buf,6) = new_leader_aid;
  16165. clif_send(buf, packet_len(0x7fc), &sd->bl, PARTY);
  16166. }
  16167. /**
  16168. * Sends a clan message to a player
  16169. * 098e <length>.W <name>.24B <message>.?B (ZC_NOTIFY_CLAN_CHAT)
  16170. **/
  16171. void clif_clan_message(struct clan *clan,const char *mes,int len){
  16172. #if PACKETVER >= 20131223
  16173. struct map_session_data *sd;
  16174. uint8 buf[256];
  16175. if( len == 0 ){
  16176. return;
  16177. }else if( len > (sizeof(buf)-5-NAME_LENGTH) ){
  16178. ShowWarning("clif_clan_message: Truncated message '%s' (len=%d, max=%d, clan_id=%d).\n", mes, len, sizeof(buf)-5, clan->id);
  16179. len = sizeof(buf)-5-NAME_LENGTH;
  16180. }
  16181. WBUFW(buf, 0) = 0x98e;
  16182. WBUFW(buf, 2) = len + 5 + NAME_LENGTH;
  16183. // 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
  16184. //safestrncpy(WBUFCP(buf,4), sendername, NAME_LENGTH);
  16185. safestrncpy(WBUFCP(buf,4+NAME_LENGTH), mes, len+1);
  16186. if((sd = clan_getavailablesd(clan)) != NULL)
  16187. clif_send(buf, WBUFW(buf,2), &sd->bl, CLAN);
  16188. #endif
  16189. }
  16190. /**
  16191. * Parses a clan message from a player.
  16192. * 098d <length>.W <text>.?B (<name> : <message>) (CZ_CLAN_CHAT)
  16193. **/
  16194. void clif_parse_clan_chat( int fd, struct map_session_data* sd ){
  16195. #if PACKETVER >= 20131223
  16196. char name[NAME_LENGTH], message[CHAT_SIZE_MAX], output[CHAT_SIZE_MAX+NAME_LENGTH*2];
  16197. // validate packet and retrieve name and message
  16198. if( !clif_process_message(sd, false, name, message, output ) )
  16199. return;
  16200. clan_send_message( sd, RFIFOCP(fd,4), RFIFOW(fd,2) - 4 );
  16201. #endif
  16202. }
  16203. /**
  16204. * Sends the basic clan informations to the client.
  16205. * 098a <length>.W <clan id>.L <clan name>.24B <clan master>.24B <clan map>.16B <alliance count>.B
  16206. * <antagonist count>.B { <alliance>.24B } * alliance count { <antagonist>.24B } * antagonist count (ZC_CLANINFO)
  16207. **/
  16208. void clif_clan_basicinfo( struct map_session_data *sd ){
  16209. #if PACKETVER >= 20131223
  16210. int fd, offset, length, i, flag;
  16211. struct clan* clan;
  16212. char mapname[MAP_NAME_LENGTH_EXT];
  16213. nullpo_retv( sd );
  16214. nullpo_retv( clan = sd->clan );
  16215. // Check if the player has a valid session and is not autotrading
  16216. if( !clif_session_isValid( sd ) ){
  16217. return;
  16218. }
  16219. length = 8 + 2 * NAME_LENGTH + MAP_NAME_LENGTH_EXT + 2;
  16220. fd = sd->fd;
  16221. WFIFOHEAD(fd,length);
  16222. memset( WFIFOP(fd, 0), 0, length );
  16223. WFIFOW( fd, 0 ) = 0x98a;
  16224. WFIFOL( fd, 4 ) = clan->id;
  16225. offset = 8;
  16226. safestrncpy( WFIFOCP( fd, offset ), clan->name, NAME_LENGTH );
  16227. offset += NAME_LENGTH;
  16228. safestrncpy( WFIFOCP( fd, offset ), clan->master, NAME_LENGTH );
  16229. offset += NAME_LENGTH;
  16230. mapindex_getmapname_ext( clan->map, mapname );
  16231. safestrncpy( WFIFOCP( fd, offset ), mapname, MAP_NAME_LENGTH_EXT );
  16232. offset += MAP_NAME_LENGTH_EXT;
  16233. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,0);
  16234. WFIFOB(fd,offset++) = clan_get_alliance_count(clan,1);
  16235. for( flag = 0; flag < 2; flag++ ){
  16236. for( i = 0; i < MAX_CLANALLIANCE; i++ ){
  16237. if( clan->alliance[i].clan_id > 0 && clan->alliance[i].opposition == flag ){
  16238. safestrncpy( WFIFOCP( fd, offset ), clan->alliance[i].name, NAME_LENGTH );
  16239. offset += NAME_LENGTH;
  16240. }
  16241. }
  16242. }
  16243. WFIFOW( fd, 2 ) = offset;
  16244. WFIFOSET(fd,offset);
  16245. #endif
  16246. }
  16247. /**
  16248. * Updates the online and maximum player count of a clan.
  16249. * 0988 <online count>.W <maximum member amount>.W (ZC_NOTIFY_CLAN_CONNECTINFO)
  16250. **/
  16251. void clif_clan_onlinecount( struct clan* clan ){
  16252. #if PACKETVER >= 20131223
  16253. uint8 buf[6];
  16254. struct map_session_data *sd;
  16255. WBUFW(buf,0) = 0x988;
  16256. WBUFW(buf,2) = clan->connect_member;
  16257. WBUFW(buf,4) = clan->max_member;
  16258. if((sd = clan_getavailablesd(clan)) != NULL)
  16259. clif_send(buf, 6, &sd->bl, CLAN);
  16260. #endif
  16261. }
  16262. /**
  16263. * Notifies the client that the player has left his clan.
  16264. * 0989 (ZC_ACK_CLAN_LEAVE)
  16265. **/
  16266. void clif_clan_leave( struct map_session_data* sd ){
  16267. #if PACKETVER >= 20131223
  16268. int fd;
  16269. nullpo_retv( sd );
  16270. if( !clif_session_isValid( sd ) ){
  16271. return;
  16272. }
  16273. fd = sd->fd;
  16274. WFIFOHEAD(fd,2);
  16275. WFIFOW(fd,0) = 0x989;
  16276. WFIFOSET(fd,2);
  16277. #endif
  16278. }
  16279. /**
  16280. * Acknowledge the client about change title result (ZC_ACK_CHANGE_TITLE).
  16281. * 0A2F <result>.B <title_id>.L
  16282. */
  16283. void clif_change_title_ack(struct map_session_data *sd, unsigned char result, unsigned long title_id)
  16284. {
  16285. #if PACKETVER >= 20150513
  16286. int fd;
  16287. nullpo_retv(sd);
  16288. if (!clif_session_isValid(sd))
  16289. return;
  16290. fd = sd->fd;
  16291. WFIFOHEAD(fd, packet_len(0xa2f));
  16292. WFIFOW(fd, 0) = 0xa2f;
  16293. WFIFOB(fd, 2) = result;
  16294. WFIFOL(fd, 3) = title_id;
  16295. WFIFOSET(fd, packet_len(0xa2f));
  16296. #endif
  16297. }
  16298. /**
  16299. * Parsing a request from the client change title (CZ_REQ_CHANGE_TITLE).
  16300. * 0A2E <title_id>.L
  16301. */
  16302. void clif_parse_change_title(int fd, struct map_session_data *sd)
  16303. {
  16304. int title_id;
  16305. nullpo_retv(sd);
  16306. title_id = RFIFOL(fd, 2);
  16307. if( title_id == sd->status.title_id ){
  16308. // It is exactly the same as the old one
  16309. return;
  16310. }else if( title_id <= 0 ){
  16311. sd->status.title_id = 0;
  16312. }else{
  16313. if (std::find(sd->titles.begin(), sd->titles.end(), title_id) == sd->titles.end()) {
  16314. clif_change_title_ack(sd, 1, title_id);
  16315. return;
  16316. }
  16317. sd->status.title_id = title_id;
  16318. }
  16319. clif_name_area(&sd->bl);
  16320. clif_change_title_ack(sd, 0, title_id);
  16321. }
  16322. #ifdef DUMP_UNKNOWN_PACKET
  16323. void DumpUnknown(int fd,TBL_PC *sd,int cmd,int packet_len)
  16324. {
  16325. const char* packet_txt = "save/packet.txt";
  16326. FILE* fp;
  16327. time_t time_server;
  16328. struct tm *datetime;
  16329. char datestr[512];
  16330. time(&time_server); // get time in seconds since 1/1/1970
  16331. datetime = localtime(&time_server); // convert seconds in structure
  16332. // like sprintf, but only for date/time (Sunday, November 02 2003 15:12:52)
  16333. strftime(datestr, sizeof(datestr)-1, "%A, %B %d %Y %X.", datetime); // Server time (normal time): %A, %B %d %Y %X.
  16334. if( ( fp = fopen( packet_txt , "a" ) ) != NULL ) {
  16335. if( sd ) {
  16336. 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);
  16337. } else {
  16338. fprintf(fp, "Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16339. }
  16340. WriteDump(fp, RFIFOP(fd,0), packet_len);
  16341. fprintf(fp, "\n");
  16342. fclose(fp);
  16343. } else {
  16344. ShowError("Failed to write '%s'.\n", packet_txt);
  16345. // Dump on console instead
  16346. if( sd ) {
  16347. 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);
  16348. } else {
  16349. ShowDebug("Unknown packet 0x%04X (length %d), session #%d at %s\n", cmd, packet_len, fd,datestr);
  16350. }
  16351. ShowDump(RFIFOP(fd,0), packet_len);
  16352. }
  16353. }
  16354. #endif
  16355. /// Roulette System
  16356. /// Author: Yommy
  16357. /**
  16358. * Opens Roulette window
  16359. * @param fd
  16360. * @param sd
  16361. */
  16362. void clif_parse_RouletteOpen(int fd, struct map_session_data* sd)
  16363. {
  16364. nullpo_retv(sd);
  16365. if (!battle_config.feature_roulette) {
  16366. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16367. return;
  16368. }
  16369. WFIFOHEAD(fd,packet_len(0xa1a));
  16370. WFIFOW(fd,0) = 0xa1a;
  16371. WFIFOB(fd,2) = 0; // result
  16372. WFIFOL(fd,3) = 0; // serial
  16373. WFIFOB(fd,7) = (sd->roulette.claimPrize) ? sd->roulette.stage - 1 : 0;
  16374. WFIFOB(fd,8) = (sd->roulette.claimPrize) ? sd->roulette.prizeIdx : -1;
  16375. WFIFOW(fd,9) = -1; //! TODO: Display bonus item
  16376. WFIFOL(fd,11) = sd->roulette_point.gold;
  16377. WFIFOL(fd,15) = sd->roulette_point.silver;
  16378. WFIFOL(fd,19) = sd->roulette_point.bronze;
  16379. WFIFOSET(fd,packet_len(0xa1a));
  16380. }
  16381. /**
  16382. * Generates information to be displayed
  16383. * @param fd
  16384. * @param sd
  16385. */
  16386. void clif_parse_RouletteInfo(int fd, struct map_session_data* sd)
  16387. {
  16388. unsigned short i, j, count = 0;
  16389. int len = 8 + (42 * 8);
  16390. nullpo_retv(sd);
  16391. if (!battle_config.feature_roulette) {
  16392. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16393. return;
  16394. }
  16395. WFIFOHEAD(fd,len);
  16396. WFIFOW(fd,0) = 0xa1c;
  16397. WFIFOW(fd,2) = len;
  16398. WFIFOL(fd,4) = 1; // serial
  16399. for(i = 0; i < MAX_ROULETTE_LEVEL; i++) {
  16400. for(j = 0; j < MAX_ROULETTE_COLUMNS - i; j++) {
  16401. WFIFOW(fd,8 * count + 8) = i;
  16402. WFIFOW(fd,8 * count + 10) = j;
  16403. WFIFOW(fd,8 * count + 12) = rd.nameid[i][j];
  16404. WFIFOW(fd,8 * count + 14) = rd.qty[i][j];
  16405. count++;
  16406. }
  16407. }
  16408. WFIFOSET(fd,len);
  16409. return;
  16410. }
  16411. /**
  16412. * Closes Roulette window
  16413. * @param fd
  16414. * @param sd
  16415. */
  16416. void clif_parse_RouletteClose(int fd, struct map_session_data* sd)
  16417. {
  16418. nullpo_retv(sd);
  16419. if (!battle_config.feature_roulette) {
  16420. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16421. return;
  16422. }
  16423. /** What do we need this for? (other than state tracking), game client closes the window without our response. **/
  16424. return;
  16425. }
  16426. /**
  16427. *
  16428. **/
  16429. static void clif_roulette_recvitem_ack(struct map_session_data *sd, enum RECV_ROULETTE_ITEM_REQ type) {
  16430. #if PACKETVER >= 20141016
  16431. uint16 cmd = 0xa22;
  16432. unsigned char buf[5];
  16433. nullpo_retv(sd);
  16434. if (packet_db[cmd].len == 0)
  16435. return;
  16436. WBUFW(buf,0) = cmd;
  16437. WBUFB(buf,2) = type;
  16438. WBUFW(buf,3) = 0; //! TODO: Additional item
  16439. clif_send(buf, sizeof(buf), &sd->bl, SELF);
  16440. #endif
  16441. }
  16442. /**
  16443. * Claim roulette reward
  16444. * @param sd Player
  16445. * @return 0:Success
  16446. **/
  16447. static uint8 clif_roulette_getitem(struct map_session_data *sd) {
  16448. struct item it;
  16449. uint8 res = 1;
  16450. nullpo_retr(1, sd);
  16451. if (sd->roulette.prizeIdx < 0)
  16452. return RECV_ITEM_FAILED;
  16453. memset(&it, 0, sizeof(it));
  16454. it.nameid = rd.nameid[sd->roulette.prizeStage][sd->roulette.prizeIdx];
  16455. it.identify = 1;
  16456. if ((res = pc_additem(sd, &it, rd.qty[sd->roulette.prizeStage][sd->roulette.prizeIdx], LOG_TYPE_ROULETTE)) == 0) {
  16457. ; // onSuccess
  16458. }
  16459. sd->roulette.claimPrize = false;
  16460. sd->roulette.prizeStage = 0;
  16461. sd->roulette.prizeIdx = -1;
  16462. sd->roulette.stage = 0;
  16463. return res;
  16464. }
  16465. /**
  16466. * Process the stage and attempt to give a prize
  16467. * @param fd
  16468. * @param sd
  16469. */
  16470. void clif_parse_RouletteGenerate(int fd, struct map_session_data* sd)
  16471. {
  16472. enum GENERATE_ROULETTE_ACK result = GENERATE_ROULETTE_SUCCESS;
  16473. short stage = sd->roulette.stage;
  16474. nullpo_retv(sd);
  16475. if (!battle_config.feature_roulette) {
  16476. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16477. return;
  16478. }
  16479. if (sd->roulette.stage >= MAX_ROULETTE_LEVEL)
  16480. stage = sd->roulette.stage = 0;
  16481. if (!stage) {
  16482. if (sd->roulette_point.bronze <= 0 && sd->roulette_point.silver < 10 && sd->roulette_point.gold < 10)
  16483. result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
  16484. }
  16485. if (result == GENERATE_ROULETTE_SUCCESS) {
  16486. if (!stage) {
  16487. if (sd->roulette_point.bronze > 0) {
  16488. sd->roulette_point.bronze -= 1;
  16489. pc_setreg2(sd, ROULETTE_BRONZE_VAR, sd->roulette_point.bronze);
  16490. } else if (sd->roulette_point.silver > 9) {
  16491. sd->roulette_point.silver -= 10;
  16492. stage = sd->roulette.stage = 2;
  16493. pc_setreg2(sd, ROULETTE_SILVER_VAR, sd->roulette_point.silver);
  16494. } else if (sd->roulette_point.gold > 9) {
  16495. sd->roulette_point.gold -= 10;
  16496. stage = sd->roulette.stage = 4;
  16497. pc_setreg2(sd, ROULETTE_GOLD_VAR, sd->roulette_point.gold);
  16498. }
  16499. }
  16500. sd->roulette.prizeStage = stage;
  16501. sd->roulette.prizeIdx = rnd()%rd.items[stage];
  16502. if (rd.flag[stage][sd->roulette.prizeIdx]&1) {
  16503. clif_roulette_generate_ack(sd,GENERATE_ROULETTE_LOSING,stage,sd->roulette.prizeIdx,0);
  16504. clif_roulette_getitem(sd);
  16505. clif_roulette_recvitem_ack(sd, RECV_ITEM_SUCCESS);
  16506. return;
  16507. }
  16508. else {
  16509. sd->roulette.claimPrize = true;
  16510. sd->roulette.stage++;
  16511. }
  16512. }
  16513. clif_roulette_generate_ack(sd,result,stage,(sd->roulette.prizeIdx == -1 ? 0 : sd->roulette.prizeIdx),0);
  16514. }
  16515. /**
  16516. * Request to cash in prize
  16517. * @param fd
  16518. * @param sd
  16519. */
  16520. void clif_parse_RouletteRecvItem(int fd, struct map_session_data* sd)
  16521. {
  16522. enum RECV_ROULETTE_ITEM_REQ type = RECV_ITEM_FAILED;
  16523. nullpo_retv(sd);
  16524. if (!battle_config.feature_roulette) {
  16525. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,1497),false,SELF); //Roulette is disabled
  16526. return;
  16527. }
  16528. if (sd->roulette.claimPrize && sd->roulette.prizeIdx != -1) {
  16529. switch (clif_roulette_getitem(sd)) {
  16530. case 0:
  16531. type = RECV_ITEM_SUCCESS;
  16532. break;
  16533. case 1:
  16534. case 4:
  16535. case 5:
  16536. type = RECV_ITEM_OVERCOUNT;
  16537. break;
  16538. case 2:
  16539. type = RECV_ITEM_OVERWEIGHT;
  16540. break;
  16541. case 7:
  16542. default:
  16543. type = RECV_ITEM_FAILED;
  16544. break;
  16545. }
  16546. }
  16547. clif_roulette_recvitem_ack(sd,type);
  16548. return;
  16549. }
  16550. /**
  16551. * Update Roulette window with current stats
  16552. * @param sd
  16553. * @param result
  16554. * @param stage
  16555. * @param prizeIdx
  16556. * @param bonusItemID
  16557. */
  16558. void clif_roulette_generate_ack(struct map_session_data *sd, unsigned char result, short stage, short prizeIdx, short bonusItemID)
  16559. {
  16560. int fd = sd->fd;
  16561. nullpo_retv(sd);
  16562. WFIFOHEAD(fd,packet_len(0xa20));
  16563. WFIFOW(fd,0) = 0xa20;
  16564. WFIFOB(fd,2) = result;
  16565. WFIFOW(fd,3) = stage;
  16566. WFIFOW(fd,5) = prizeIdx;
  16567. WFIFOW(fd,7) = bonusItemID;
  16568. WFIFOL(fd,9) = sd->roulette_point.gold;
  16569. WFIFOL(fd,13) = sd->roulette_point.silver;
  16570. WFIFOL(fd,17) = sd->roulette_point.bronze;
  16571. WFIFOSET(fd,packet_len(0xa20));
  16572. }
  16573. /// MERGE ITEM
  16574. /**
  16575. * Acknowledge the client about item merger result
  16576. * ZC 096F <index>.W <total>.W <result>.B (ZC_ACK_MERGE_ITEM)
  16577. * @param fd
  16578. * @param sd
  16579. **/
  16580. void clif_merge_item_ack(struct map_session_data *sd, unsigned short index, unsigned short count, enum MERGE_ITEM_ACK type) {
  16581. unsigned char buf[9];
  16582. struct s_packet_db *info = NULL;
  16583. short cmd = 0;
  16584. nullpo_retv(sd);
  16585. if (!clif_session_isValid(sd))
  16586. return;
  16587. if (!(cmd = packet_db_ack[ZC_ACK_MERGE_ITEM]))
  16588. return;
  16589. if (!(info = &packet_db[cmd]) || info->len == 0)
  16590. return;
  16591. WBUFW(buf, 0) = cmd;
  16592. WBUFW(buf, info->pos[0]) = index;
  16593. WBUFW(buf, info->pos[1]) = count;
  16594. WBUFB(buf, info->pos[2]) = type;
  16595. clif_send(buf, info->len, &sd->bl, SELF);
  16596. }
  16597. /**
  16598. * Check if item has the pair to be merged
  16599. * @param sd
  16600. * @param it Item
  16601. * @return True if has pair, False if not
  16602. **/
  16603. static bool clif_merge_item_has_pair(struct map_session_data *sd, struct item *it) {
  16604. struct item *it_;
  16605. unsigned short i;
  16606. nullpo_retr(false, sd);
  16607. 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);
  16608. if (i < MAX_INVENTORY)
  16609. return true;
  16610. return false;
  16611. }
  16612. /**
  16613. * Check if item can be merged
  16614. * @param id Item Data
  16615. * @param it Item
  16616. * @return True if can be merged, False if not
  16617. **/
  16618. static bool clif_merge_item_check(struct item_data *id, struct item *it) {
  16619. if (!id || !it)
  16620. return false;
  16621. if (id->type == IT_CASH)
  16622. return false;
  16623. if (!itemdb_isstackable2(id))
  16624. return false;
  16625. if (itemdb_isspecial(it->card[0]))
  16626. return false;
  16627. if (!it->unique_id)
  16628. return false;
  16629. return true;
  16630. }
  16631. /**
  16632. * Open available item to be merged.
  16633. * Only show 1 item in 1 process.
  16634. * ZC 096D <size>.W { <index>.W }* (ZC_MERGE_ITEM_OPEN)
  16635. * @param sd
  16636. **/
  16637. void clif_merge_item_open(struct map_session_data *sd) {
  16638. unsigned char buf[4 + MAX_INVENTORY*2] = { 0 };
  16639. unsigned short cmd = 0, n = 0, i = 0, indexes[MAX_INVENTORY] = { 0 };
  16640. int len = 0;
  16641. struct s_packet_db *info = NULL;
  16642. struct item *it;
  16643. nullpo_retv(sd);
  16644. if (!clif_session_isValid(sd))
  16645. return;
  16646. if (!(cmd = packet_db_ack[ZC_MERGE_ITEM_OPEN]))
  16647. return;
  16648. if (!(info = &packet_db[cmd]) || info->len == 0)
  16649. return;
  16650. // Get entries
  16651. for (i = 0; i < MAX_INVENTORY; i++) {
  16652. if (!clif_merge_item_check(sd->inventory_data[i], (it = &sd->inventory.u.items_inventory[i])))
  16653. continue;
  16654. if (clif_merge_item_has_pair(sd, it))
  16655. indexes[n++] = i;
  16656. }
  16657. if (n < 2) { // No item need to be merged
  16658. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16659. return;
  16660. }
  16661. WBUFW(buf, 0) = cmd;
  16662. WBUFW(buf, info->pos[0]) = (len = 4 + n*2);
  16663. for (i = 0; i < n; i++) {
  16664. WBUFW(buf, info->pos[1] + i*2) = indexes[i]+2;
  16665. }
  16666. clif_send(buf, len, &sd->bl, SELF);
  16667. }
  16668. /**
  16669. * Process item merger
  16670. * CZ 096E <size>.W { <index>.W }* (CZ_REQ_MERGE_ITEM)
  16671. * @param fd
  16672. * @param sd
  16673. **/
  16674. void clif_parse_merge_item_req(int fd, struct map_session_data* sd) {
  16675. struct s_packet_db *info = NULL;
  16676. unsigned short n = 0, indexes[MAX_INVENTORY] = { 0 }, i, j;
  16677. unsigned int count = 0;
  16678. struct item_data *id = NULL;
  16679. nullpo_retv(sd);
  16680. if (!clif_session_isValid(sd))
  16681. return;
  16682. if (!(info = &packet_db[RFIFOW(fd,0)]) || info->len == 0)
  16683. return;
  16684. n = (RFIFOW(fd, info->pos[0]) - 4) / 2;
  16685. if (n < 2) { // No item need to be merged
  16686. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16687. return;
  16688. }
  16689. for (i = 0, j = 0; i < n; i++) {
  16690. unsigned short idx = RFIFOW(fd, info->pos[1] + i*2) - 2;
  16691. if (!clif_merge_item_check((id = sd->inventory_data[idx]), &sd->inventory.u.items_inventory[idx]))
  16692. continue;
  16693. indexes[j] = idx;
  16694. if (j && id->nameid != sd->inventory_data[indexes[0]]->nameid) { // Only can merge 1 kind at once
  16695. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_NOT_MERGE);
  16696. return;
  16697. }
  16698. count += sd->inventory.u.items_inventory[idx].amount;
  16699. j++;
  16700. }
  16701. if (n != j || !(id = sd->inventory_data[indexes[0]])) {
  16702. clif_msg(sd, MERGE_ITEM_NOT_AVAILABLE);
  16703. return;
  16704. }
  16705. if (count >= (id->stack.amount ? id->stack.amount : MAX_AMOUNT)) {
  16706. clif_merge_item_ack(sd, 0, 0, MERGE_ITEM_FAILED_MAX_COUNT);
  16707. return;
  16708. }
  16709. // Merrrrge!!!!
  16710. for (i = 1; i < n; i++) {
  16711. unsigned short idx = indexes[i], amt = sd->inventory.u.items_inventory[idx].amount;
  16712. log_pick_pc(sd, LOG_TYPE_MERGE_ITEM, -amt, &sd->inventory.u.items_inventory[idx]);
  16713. memset(&sd->inventory.u.items_inventory[idx], 0, sizeof(sd->inventory.u.items_inventory[0]));
  16714. sd->inventory_data[idx] = NULL;
  16715. clif_delitem(sd, idx, amt, 0);
  16716. }
  16717. sd->inventory.u.items_inventory[indexes[0]].amount = count;
  16718. clif_merge_item_ack(sd, indexes[0]+2, count, MERGE_ITEM_SUCCESS);
  16719. }
  16720. /**
  16721. * Cancel item merge
  16722. * CZ 0974 (CZ_CANCEL_MERGE_ITEM)
  16723. * @param fd
  16724. * @param sd
  16725. **/
  16726. void clif_parse_merge_item_cancel(int fd, struct map_session_data* sd) {
  16727. return; // Nothing todo yet
  16728. }
  16729. /**
  16730. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <containerid>.W (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16731. * 07fd <size>.W <type>.B <itemid>.W <charname_len>.B <charname>.24B <source_len>.B <srcname>.24B (ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN)
  16732. * type: ITEMOBTAIN_TYPE_BOXITEM & ITEMOBTAIN_TYPE_MONSTER_ITEM "[playername] ... [sourcename] ... [itemname]" -> MsgStringTable[1629]
  16733. * type: ITEMOBTAIN_TYPE_NPC "[playername] ... [itemname]" -> MsgStringTable[1870]
  16734. **/
  16735. void clif_broadcast_obtain_special_item(const char *char_name, unsigned short nameid, unsigned short container, enum BROADCASTING_SPECIAL_ITEM_OBTAIN type) {
  16736. unsigned char buf[9 + NAME_LENGTH * 2];
  16737. unsigned short cmd = 0;
  16738. struct s_packet_db *info = NULL;
  16739. if (!(cmd = packet_db_ack[ZC_BROADCASTING_SPECIAL_ITEM_OBTAIN]))
  16740. return;
  16741. if (!(info = &packet_db[cmd]) || info->len == 0)
  16742. return;
  16743. WBUFW(buf, 0) = 0x7fd;
  16744. WBUFB(buf, 4) = type;
  16745. WBUFW(buf, 5) = nameid;
  16746. WBUFB(buf, 7) = NAME_LENGTH;
  16747. if (battle_config.broadcast_hide_name) {
  16748. std::string dispname = std::string(char_name);
  16749. int hide = min(battle_config.broadcast_hide_name, dispname.length() - 1);
  16750. dispname.replace(dispname.length() - hide, hide, hide, '*');
  16751. safestrncpy(WBUFCP(buf, 8), dispname.c_str(), NAME_LENGTH);
  16752. }
  16753. else
  16754. safestrncpy(WBUFCP(buf, 8), char_name, NAME_LENGTH);
  16755. switch (type) {
  16756. case ITEMOBTAIN_TYPE_BOXITEM:
  16757. WBUFW(buf, 2) = 11 + NAME_LENGTH;
  16758. WBUFB(buf, 8 + NAME_LENGTH) = 0;
  16759. WBUFW(buf, 9 + NAME_LENGTH) = container;
  16760. break;
  16761. case ITEMOBTAIN_TYPE_MONSTER_ITEM:
  16762. {
  16763. struct mob_db *db = mob_db(container);
  16764. WBUFW(buf, 2) = 9 + NAME_LENGTH * 2;
  16765. WBUFB(buf, 8 + NAME_LENGTH) = NAME_LENGTH;
  16766. safestrncpy(WBUFCP(buf, 9 + NAME_LENGTH), db->name, NAME_LENGTH);
  16767. }
  16768. break;
  16769. case ITEMOBTAIN_TYPE_NPC:
  16770. default:
  16771. WBUFW(buf, 2) = 8 + NAME_LENGTH;
  16772. break;
  16773. }
  16774. clif_send(buf, WBUFW(buf, 2), NULL, ALL_CLIENT);
  16775. }
  16776. /// Show body view windows (ZC_DRESSROOM_OPEN).
  16777. /// 0A02 <view>.W
  16778. /// Value <flag> has the following effects:
  16779. /// 1: Open a Dress Room window.
  16780. void clif_dressing_room(struct map_session_data *sd, int flag) {
  16781. #if PACKETVER >= 20150513
  16782. int fd = sd->fd;
  16783. nullpo_retv(sd);
  16784. WFIFOHEAD(fd, packet_len(0xa02));
  16785. WFIFOW(fd,0) = 0xa02;
  16786. WFIFOW(fd,2) = flag;
  16787. WFIFOSET(fd, packet_len(0xa02));
  16788. #endif
  16789. }
  16790. /// Parsing a request from the client item identify oneclick (CZ_REQ_ONECLICK_ITEMIDENTIFY).
  16791. /// 0A35 <result>.W
  16792. void clif_parse_Oneclick_Itemidentify(int fd, struct map_session_data *sd) {
  16793. #if PACKETVER >= 20150513
  16794. short idx = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0]) - 2, magnifier_idx;
  16795. // Ignore the request
  16796. // - Invalid item index
  16797. // - Invalid item ID or item doesn't exist
  16798. // - Item is already identified
  16799. if (idx < 0 || idx >= MAX_INVENTORY ||
  16800. sd->inventory.u.items_inventory[idx].nameid <= 0 || sd->inventory_data[idx] == NULL ||
  16801. sd->inventory.u.items_inventory[idx].identify)
  16802. return;
  16803. // Ignore the request - No magnifiers in inventory
  16804. if ((magnifier_idx = pc_search_inventory(sd, ITEMID_MAGNIFIER)) == -1 &&
  16805. (magnifier_idx = pc_search_inventory(sd, ITEMID_NOVICE_MAGNIFIER)) == -1)
  16806. return;
  16807. if (pc_delitem(sd, magnifier_idx, 1, 0, 0, LOG_TYPE_OTHER) != 0) // Deleting of magnifier failed, for whatever reason...
  16808. return;
  16809. skill_identify(sd, idx);
  16810. #endif
  16811. }
  16812. /// Starts navigation to the given target on client side
  16813. void clif_navigateTo(struct map_session_data *sd, const char* mapname, uint16 x, uint16 y, uint8 flag, bool hideWindow, uint16 mob_id ){
  16814. #if PACKETVER >= 20111010
  16815. int fd = sd->fd;
  16816. WFIFOHEAD(fd,27);
  16817. WFIFOW(fd,0) = 0x08e2;
  16818. // How detailed will our navigation be?
  16819. if( mob_id > 0 ){
  16820. x = 0;
  16821. y = 0;
  16822. WFIFOB(fd,2) = 3; // monster with destination field
  16823. }else if( x > 0 && y > 0 ){
  16824. WFIFOB(fd,2) = 0; // with coordinates
  16825. }else{
  16826. x = 0;
  16827. y = 0;
  16828. WFIFOB(fd,2) = 1; // without coordinates(will fail if you are already on the map)
  16829. }
  16830. // Which services can be used for transportation?
  16831. WFIFOB(fd,3) = flag;
  16832. // If this flag is set, the navigation window will not be opened up
  16833. WFIFOB(fd,4) = hideWindow;
  16834. // Target map
  16835. safestrncpy( WFIFOCP(fd,5),mapname,MAP_NAME_LENGTH_EXT);
  16836. // Target x
  16837. WFIFOW(fd,21) = x;
  16838. // Target y
  16839. WFIFOW(fd,23) = y;
  16840. // Target monster ID
  16841. WFIFOW(fd,25) = mob_id;
  16842. WFIFOSET(fd,27);
  16843. #endif
  16844. }
  16845. /// Send hat effects to the client (ZC_HAT_EFFECT).
  16846. /// 0A3B <Length>.W <AID>.L <Status>.B { <HatEffectId>.W }
  16847. void clif_hat_effects( struct map_session_data* sd, struct block_list* bl, enum send_target target ){
  16848. #if PACKETVER >= 20150513
  16849. unsigned char* buf;
  16850. int len,i;
  16851. struct map_session_data *tsd;
  16852. struct block_list* tbl;
  16853. if( target == SELF ){
  16854. tsd = BL_CAST(BL_PC,bl);
  16855. tbl = &sd->bl;
  16856. }else{
  16857. tsd = sd;
  16858. tbl = bl;
  16859. }
  16860. if( !tsd->hatEffectCount )
  16861. return;
  16862. len = 9 + tsd->hatEffectCount * 2;
  16863. buf = (unsigned char*)aMalloc( len );
  16864. WBUFW(buf,0) = 0xa3b;
  16865. WBUFW(buf,2) = len;
  16866. WBUFL(buf,4) = tsd->bl.id;
  16867. WBUFB(buf,8) = 1;
  16868. for( i = 0; i < tsd->hatEffectCount; i++ ){
  16869. WBUFW(buf,9+i*2) = tsd->hatEffectIDs[i];
  16870. }
  16871. clif_send(buf, len,tbl,target);
  16872. aFree(buf);
  16873. #endif
  16874. }
  16875. void clif_hat_effect_single( struct map_session_data* sd, uint16 effectId, bool enable ){
  16876. #if PACKETVER >= 20150513
  16877. unsigned char buf[13];
  16878. WBUFW(buf,0) = 0xa3b;
  16879. WBUFW(buf,2) = 13;
  16880. WBUFL(buf,4) = sd->bl.id;
  16881. WBUFB(buf,8) = enable;
  16882. WBUFL(buf,9) = effectId;
  16883. clif_send(buf,13,&sd->bl,AREA);
  16884. #endif
  16885. }
  16886. /// Notify the client that a sale has started
  16887. /// 09b2 <item id>.W <remaining time>.L (ZC_NOTIFY_BARGAIN_SALE_SELLING)
  16888. void clif_sale_start( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  16889. #if PACKETVER_SUPPORTS_SALES
  16890. unsigned char buf[8];
  16891. WBUFW(buf, 0) = 0x9b2;
  16892. WBUFW(buf, 2) = sale_item->nameid;
  16893. WBUFL(buf, 4) = (uint32)(sale_item->end - time(NULL)); // time in S
  16894. clif_send(buf, 8, bl, target);
  16895. #endif
  16896. }
  16897. /// Notify the clien that a sale has ended
  16898. /// 09b3 <item id>.W (ZC_NOTIFY_BARGAIN_SALE_CLOSE)
  16899. void clif_sale_end( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  16900. #if PACKETVER_SUPPORTS_SALES
  16901. unsigned char buf[4];
  16902. WBUFW(buf, 0) = 0x9b3;
  16903. WBUFW(buf, 2) = sale_item->nameid;
  16904. clif_send(buf, 4, bl, target);
  16905. #endif
  16906. }
  16907. /// Update the remaining amount of a sale item.
  16908. /// 09c4 <item id>.W <amount>.L (ZC_ACK_COUNT_BARGAIN_SALE_ITEM)
  16909. void clif_sale_amount( struct sale_item_data* sale_item, struct block_list* bl, enum send_target target ){
  16910. #if PACKETVER_SUPPORTS_SALES
  16911. unsigned char buf[8];
  16912. WBUFW(buf, 0) = 0x9c4;
  16913. WBUFW(buf, 2) = sale_item->nameid;
  16914. WBUFL(buf, 4) = sale_item->amount;
  16915. clif_send(buf, 8, bl, target);
  16916. #endif
  16917. }
  16918. /// The client requested a refresh of the current remaining count of a sale item
  16919. /// 09ac <account id>.L <item id>.W (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  16920. void clif_parse_sale_refresh( int fd, struct map_session_data* sd ){
  16921. #if PACKETVER_SUPPORTS_SALES
  16922. struct sale_item_data* sale;
  16923. if( RFIFOL(fd, 2) != sd->status.account_id ){
  16924. return;
  16925. }
  16926. sale = sale_find_item( RFIFOW(fd, 6), true );
  16927. if( sale == NULL ){
  16928. return;
  16929. }
  16930. clif_sale_amount(sale, &sd->bl, SELF);
  16931. #endif
  16932. }
  16933. /// Opens the sale administration window on the client
  16934. /// 09b5 (ZC_OPEN_BARGAIN_SALE_TOOL)
  16935. void clif_sale_open( struct map_session_data* sd ){
  16936. #if PACKETVER_SUPPORTS_SALES
  16937. nullpo_retv(sd);
  16938. if( sd->state.sale_open ){
  16939. return;
  16940. }
  16941. sd->state.sale_open = true;
  16942. int fd = sd->fd;
  16943. WFIFOHEAD(fd, 2);
  16944. WFIFOW(fd, 0) = 0x9b5;
  16945. WFIFOSET(fd, 2);
  16946. #endif
  16947. }
  16948. /// Client request to open the sale administration window.
  16949. /// This is sent by /limitedsale
  16950. /// 09b4 <account id>.L (CZ_OPEN_BARGAIN_SALE_TOOL)
  16951. void clif_parse_sale_open( int fd, struct map_session_data* sd ){
  16952. #if PACKETVER_SUPPORTS_SALES
  16953. nullpo_retv(sd);
  16954. if( RFIFOL(fd, 2) != sd->status.account_id ){
  16955. return;
  16956. }
  16957. char command[CHAT_SIZE_MAX];
  16958. safesnprintf( command, sizeof(command), "%climitedsale", atcommand_symbol );
  16959. is_atcommand(fd, sd, command, 1);
  16960. #endif
  16961. }
  16962. /// Closes the sale administration window on the client.
  16963. /// 09bd (ZC_CLOSE_BARGAIN_SALE_TOOL)
  16964. void clif_sale_close(struct map_session_data* sd) {
  16965. #if PACKETVER_SUPPORTS_SALES
  16966. nullpo_retv(sd);
  16967. if( !sd->state.sale_open ){
  16968. return;
  16969. }
  16970. sd->state.sale_open = false;
  16971. int fd = sd->fd;
  16972. WFIFOHEAD(fd, 2);
  16973. WFIFOW(fd, 0) = 0x9bd;
  16974. WFIFOSET(fd, 2);
  16975. #endif
  16976. }
  16977. /// Client request to close the sale administration window.
  16978. /// 09bc (CZ_CLOSE_BARGAIN_SALE_TOOL)
  16979. void clif_parse_sale_close(int fd, struct map_session_data* sd) {
  16980. #if PACKETVER_SUPPORTS_SALES
  16981. nullpo_retv(sd);
  16982. if( RFIFOL(fd, 2) != sd->status.account_id ){
  16983. return;
  16984. }
  16985. clif_sale_close(sd);
  16986. #endif
  16987. }
  16988. /// Reply to a item search request for item sale administration.
  16989. /// 09ad <result>.W <item id>.W <price>.L (ZC_ACK_CASH_BARGAIN_SALE_ITEM_INFO)
  16990. void clif_sale_search_reply( struct map_session_data* sd, struct cash_item_data* item ){
  16991. #if PACKETVER_SUPPORTS_SALES
  16992. int fd = sd->fd;
  16993. WFIFOHEAD(fd, 10);
  16994. WFIFOW(fd, 0) = 0x9ad;
  16995. if( item != NULL ){
  16996. WFIFOW(fd, 2) = 0;
  16997. WFIFOW(fd, 4) = item->nameid;
  16998. WFIFOL(fd, 6) = item->price;
  16999. }else{
  17000. WFIFOW(fd, 2) = 1;
  17001. WFIFOW(fd, 4) = 0;
  17002. WFIFOL(fd, 6) = 0;
  17003. }
  17004. WFIFOSET(fd, 10);
  17005. #endif
  17006. }
  17007. /// Search request for an item sale administration.
  17008. /// 09ac <length>.W <account id>.L <item name>.?B (CZ_REQ_CASH_BARGAIN_SALE_ITEM_INFO)
  17009. void clif_parse_sale_search( int fd, struct map_session_data* sd ){
  17010. #if PACKETVER_SUPPORTS_SALES
  17011. char item_name[ITEM_NAME_LENGTH];
  17012. struct item_data *id = NULL;
  17013. nullpo_retv(sd);
  17014. if( RFIFOL(fd, 4) != sd->status.account_id ){
  17015. return;
  17016. }
  17017. if( !sd->state.sale_open ){
  17018. return;
  17019. }
  17020. safestrncpy( item_name, RFIFOCP(fd, 8), min(RFIFOW(fd, 2) - 7, ITEM_NAME_LENGTH) );
  17021. id = itemdb_searchname(item_name);
  17022. if( id ){
  17023. int i;
  17024. for( i = 0; i < cash_shop_items[CASHSHOP_TAB_SALE].count; i++ ){
  17025. if( cash_shop_items[CASHSHOP_TAB_SALE].item[i]->nameid == id->nameid ){
  17026. clif_sale_search_reply( sd, cash_shop_items[CASHSHOP_TAB_SALE].item[i] );
  17027. return;
  17028. }
  17029. }
  17030. }
  17031. // not found
  17032. clif_sale_search_reply( sd, NULL );
  17033. #endif
  17034. }
  17035. /// Reply if an item was successfully put on sale or not.
  17036. /// 09af <result>.W (ZC_ACK_APPLY_BARGAIN_SALE_ITEM)
  17037. void clif_sale_add_reply( struct map_session_data* sd, enum e_sale_add_result result ){
  17038. #if PACKETVER_SUPPORTS_SALES
  17039. int fd = sd->fd;
  17040. WFIFOHEAD(fd, 4);
  17041. WFIFOW(fd, 0) = 0x9af;
  17042. WFIFOW(fd, 2) = (uint16)result;
  17043. WFIFOSET(fd, 4);
  17044. #endif
  17045. }
  17046. /// A client request to put an item on sale.
  17047. /// 09ae <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.B (CZ_REQ_APPLY_BARGAIN_SALE_ITEM)
  17048. /// 0a3d <account id>.L <item id>.W <amount>.L <start time>.L <hours on sale>.W
  17049. void clif_parse_sale_add( int fd, struct map_session_data* sd ){
  17050. #if PACKETVER_SUPPORTS_SALES
  17051. int32 count;
  17052. int16 nameid;
  17053. int startTime;
  17054. int endTime;
  17055. uint16 sellingHours;
  17056. nullpo_retv(sd);
  17057. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17058. return;
  17059. }
  17060. if( !sd->state.sale_open ){
  17061. return;
  17062. }
  17063. nameid = RFIFOW(fd, 6);
  17064. count = RFIFOL(fd, 8);
  17065. startTime = RFIFOL(fd, 12);
  17066. #if PACKETVER >= 20150520
  17067. if( RFIFOW(fd,0) == 0xa3d )
  17068. sellingHours = RFIFOW(fd, 16);
  17069. else
  17070. #endif
  17071. sellingHours = RFIFOB(fd, 16);
  17072. endTime = startTime + sellingHours * 60 * 60;
  17073. clif_sale_add_reply( sd, sale_add_item(nameid,count,startTime,endTime) );
  17074. #endif
  17075. }
  17076. /// Reply to an item removal from sale.
  17077. /// 09b1 <result>.W (ZC_ACK_REMOVE_BARGAIN_SALE_ITEM)
  17078. void clif_sale_remove_reply( struct map_session_data* sd, bool failed ){
  17079. #if PACKETVER_SUPPORTS_SALES
  17080. int fd = sd->fd;
  17081. WFIFOHEAD(fd, 4);
  17082. WFIFOW(fd, 0) = 0x9b1;
  17083. WFIFOW(fd, 2) = failed;
  17084. WFIFOSET(fd, 4);
  17085. #endif
  17086. }
  17087. /// Request to remove an item from sale.
  17088. /// 09b0 <account id>.L <item id>.W (CZ_REQ_REMOVE_BARGAIN_SALE_ITEM)
  17089. void clif_parse_sale_remove( int fd, struct map_session_data* sd ){
  17090. #if PACKETVER_SUPPORTS_SALES
  17091. nullpo_retv(sd);
  17092. if( RFIFOL(fd, 2) != sd->status.account_id ){
  17093. return;
  17094. }
  17095. if( !sd->state.sale_open ){
  17096. return;
  17097. }
  17098. clif_sale_remove_reply(sd, !sale_remove_item(RFIFOW(fd, 6)));
  17099. #endif
  17100. }
  17101. /// Achievement System
  17102. /// Author: Luxuri, Aleos
  17103. /**
  17104. * Sends all achievement data to the client (ZC_ALL_AG_LIST).
  17105. * 0a23 <packetType>.W <packetLength>.W <ACHCount>.L <ACHPoint>.L
  17106. */
  17107. void clif_achievement_list_all(struct map_session_data *sd)
  17108. {
  17109. int i, j, len, fd, *info;
  17110. uint16 count = 0;
  17111. nullpo_retv(sd);
  17112. if (!battle_config.feature_achievement) {
  17113. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17114. return;
  17115. }
  17116. fd = sd->fd;
  17117. count = sd->achievement_data.count; // All achievements should be sent to the client
  17118. len = (50 * count) + 22;
  17119. if (len <= 22)
  17120. return;
  17121. info = achievement_level(sd, true);
  17122. WFIFOHEAD(fd,len);
  17123. WFIFOW(fd, 0) = 0xa23;
  17124. WFIFOW(fd, 2) = len;
  17125. WFIFOL(fd, 4) = count; // Amount of achievements the player has in their list (started/completed)
  17126. WFIFOL(fd, 8) = sd->achievement_data.total_score; // Top number
  17127. WFIFOW(fd, 12) = sd->achievement_data.level; // Achievement Level (gold circle)
  17128. WFIFOL(fd, 14) = info[0]; // Achievement EXP (left number in bar)
  17129. WFIFOL(fd, 18) = info[1]; // Achievement EXP TNL (right number in bar)
  17130. for (i = 0; i < count; i++) {
  17131. WFIFOL(fd, i * 50 + 22) = (uint32)sd->achievement_data.achievements[i].achievement_id;
  17132. WFIFOB(fd, i * 50 + 26) = (uint32)sd->achievement_data.achievements[i].completed > 0;
  17133. for (j = 0; j < MAX_ACHIEVEMENT_OBJECTIVES; j++)
  17134. WFIFOL(fd, (i * 50) + 27 + (j * 4)) = (uint32)sd->achievement_data.achievements[i].count[j];
  17135. WFIFOL(fd, i * 50 + 67) = (uint32)sd->achievement_data.achievements[i].completed;
  17136. WFIFOB(fd, i * 50 + 71) = sd->achievement_data.achievements[i].rewarded > 0;
  17137. }
  17138. WFIFOSET(fd, len);
  17139. }
  17140. /**
  17141. * Sends a single achievement's data to the client (ZC_AG_UPDATE).
  17142. * 0a24 <packetType>.W <ACHPoint>.L
  17143. */
  17144. void clif_achievement_update(struct map_session_data *sd, struct achievement *ach, int count)
  17145. {
  17146. int fd, i, *info;
  17147. nullpo_retv(sd);
  17148. if (!battle_config.feature_achievement) {
  17149. clif_messagecolor(&sd->bl,color_table[COLOR_RED],msg_txt(sd,772),false,SELF); // Achievements are disabled.
  17150. return;
  17151. }
  17152. fd = sd->fd;
  17153. info = achievement_level(sd, true);
  17154. WFIFOHEAD(fd, packet_len(0xa24));
  17155. WFIFOW(fd, 0) = 0xa24;
  17156. WFIFOL(fd, 2) = sd->achievement_data.total_score; // Total Achievement Points (top of screen)
  17157. WFIFOW(fd, 6) = sd->achievement_data.level; // Achievement Level (gold circle)
  17158. WFIFOL(fd, 8) = info[0]; // Achievement EXP (left number in bar)
  17159. WFIFOL(fd, 12) = info[1]; // Achievement EXP TNL (right number in bar)
  17160. if (ach) {
  17161. WFIFOL(fd, 16) = ach->achievement_id; // Achievement ID
  17162. WFIFOB(fd, 20) = ach->completed > 0; // Is it complete?
  17163. for (i = 0; i < MAX_ACHIEVEMENT_OBJECTIVES; i++)
  17164. WFIFOL(fd, 21 + (i * 4)) = (uint32)ach->count[i]; // 1~10 pre-reqs
  17165. WFIFOL(fd, 61) = (uint32)ach->completed; // Epoch time
  17166. WFIFOB(fd, 65) = ach->rewarded > 0; // Got reward?
  17167. } else
  17168. memset(WFIFOP(fd, 16), 0, 40);
  17169. WFIFOSET(fd, packet_len(0xa24));
  17170. }
  17171. /**
  17172. * Checks if an achievement reward can be rewarded (CZ_REQ_AG_REWARD).
  17173. * 0a25 <packetType>.W <achievementID>.L
  17174. */
  17175. void clif_parse_AchievementCheckReward(int fd, struct map_session_data *sd)
  17176. {
  17177. nullpo_retv(sd);
  17178. if( sd->achievement_data.save )
  17179. intif_achievement_save(sd);
  17180. achievement_check_reward(sd, RFIFOL(fd,2));
  17181. }
  17182. /**
  17183. * Returns the result of achievement_check_reward (ZC_REQ_AG_REWARD_ACK).
  17184. * 0a26 <packetType>.W <result>.W <achievementID>.L
  17185. */
  17186. void clif_achievement_reward_ack(int fd, unsigned char result, int achievement_id)
  17187. {
  17188. WFIFOHEAD(fd, packet_len(0xa26));
  17189. WFIFOW(fd, 0) = 0xa26;
  17190. WFIFOB(fd, 2) = result;
  17191. WFIFOL(fd, 3) = achievement_id;
  17192. WFIFOSET(fd, packet_len(0xa26));
  17193. }
  17194. /*
  17195. * This packet is sent by /changedress or /nocosplay
  17196. *
  17197. * 0ae8
  17198. */
  17199. void clif_parse_changedress( int fd, struct map_session_data* sd ){
  17200. #if PACKETVER >= 20180103
  17201. char command[CHAT_SIZE_MAX];
  17202. safesnprintf( command, sizeof(command), "%cchangedress", atcommand_symbol );
  17203. is_atcommand( fd, sd, command, 1 );
  17204. #endif
  17205. }
  17206. /*==========================================
  17207. * Main client packet processing function
  17208. *------------------------------------------*/
  17209. static int clif_parse(int fd)
  17210. {
  17211. int cmd, packet_len;
  17212. TBL_PC* sd;
  17213. int pnum;
  17214. #ifdef PACKET_OBFUSCATION
  17215. int cmd2;
  17216. #endif
  17217. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  17218. // Note: "click masters" can do 80+ clicks in 10 seconds
  17219. 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]
  17220. { // begin main client packet processing loop
  17221. sd = (TBL_PC *)session[fd]->session_data;
  17222. if (session[fd]->flag.eof) {
  17223. if (sd) {
  17224. if (sd->state.autotrade) {
  17225. //Disassociate character from the socket connection.
  17226. session[fd]->session_data = NULL;
  17227. sd->fd = 0;
  17228. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off (using @autotrade).\n", sd->status.name);
  17229. } else
  17230. if (sd->state.active) {
  17231. // Player logout display [Valaris]
  17232. ShowInfo("Character '" CL_WHITE "%s" CL_RESET "' logged off.\n", sd->status.name);
  17233. clif_quitsave(fd, sd);
  17234. } else {
  17235. //Unusual logout (during log on/off/map-changer procedure)
  17236. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  17237. map_quit(sd);
  17238. }
  17239. } else {
  17240. ShowInfo("Closed connection from '" CL_WHITE "%s" CL_RESET "'.\n", ip2str(session[fd]->client_addr, NULL));
  17241. }
  17242. do_close(fd);
  17243. return 0;
  17244. }
  17245. if (RFIFOREST(fd) < 2)
  17246. return 0;
  17247. cmd = RFIFOW(fd, 0);
  17248. #ifdef PACKET_OBFUSCATION
  17249. // Check if it is a player that tries to connect to the map server.
  17250. if( sd ){
  17251. // Decrypt the current packet ID with the last key stored in the session.
  17252. cmd = (cmd ^ ((sd->cryptKey >> 16) & 0x7FFF));
  17253. }else{
  17254. // Store the original value for checking
  17255. cmd2 = cmd;
  17256. // A player tries to connect - use the initial keys for the decryption of the packet ID.
  17257. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17258. }
  17259. #endif
  17260. // filter out invalid / unsupported packets
  17261. if (cmd > MAX_PACKET_DB || cmd < MIN_PACKET_DB || packet_db[cmd].len == 0) {
  17262. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  17263. #ifdef DUMP_INVALID_PACKET
  17264. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17265. #endif
  17266. #ifdef PACKET_OBFUSCATION_WARN
  17267. // If it is a connection attempt, check if the packet would have been valid without decrypting it
  17268. if( !sd ){
  17269. #ifdef PACKET_OBFUSCATION
  17270. if( cmd2 >= MIN_PACKET_DB && cmd2 < MAX_PACKET_DB && packet_db[cmd2].len != 0 && packet_db[cmd2].func == clif_parse_WantToConnection ){
  17271. ShowWarning( "clif_parse: It looks like you have enabled PACKET_OBFUSCATION on server side, but disabled it on client side.\n" );
  17272. }
  17273. #else
  17274. // Try to use the initial keys for the decryption of the packet ID.
  17275. cmd = (cmd ^ ((((clif_cryptKey[0] * clif_cryptKey[1]) + clif_cryptKey[2]) >> 16) & 0x7FFF));
  17276. if( cmd >= MIN_PACKET_DB && cmd < MAX_PACKET_DB && packet_db[cmd].len != 0 && packet_db[cmd].func == clif_parse_WantToConnection ){
  17277. ShowWarning( "clif_parse: It looks like you have disabled PACKET_OBFUSCATION on server side, but enabled it on client side.\n" );
  17278. }
  17279. #endif
  17280. }
  17281. #endif
  17282. set_eof(fd);
  17283. return 0;
  17284. }
  17285. // determine real packet length
  17286. packet_len = packet_db[cmd].len;
  17287. if (packet_len == -1) { // variable-length packet
  17288. if (RFIFOREST(fd) < 4)
  17289. return 0;
  17290. packet_len = RFIFOW(fd,2);
  17291. if (packet_len < 4 || packet_len > 32768) {
  17292. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  17293. #ifdef DUMP_INVALID_PACKET
  17294. ShowDump(RFIFOP(fd,0), RFIFOREST(fd));
  17295. #endif
  17296. set_eof(fd);
  17297. return 0;
  17298. }
  17299. }
  17300. if ((int)RFIFOREST(fd) < packet_len)
  17301. return 0; // not enough data received to form the packet
  17302. #ifdef PACKET_OBFUSCATION
  17303. RFIFOW(fd, 0) = cmd;
  17304. if (sd)
  17305. sd->cryptKey = ((sd->cryptKey * clif_cryptKey[1]) + clif_cryptKey[2]) & 0xFFFFFFFF; // Update key for the next packet
  17306. #endif
  17307. if( packet_db[cmd].func == clif_parse_debug )
  17308. packet_db[cmd].func(fd, sd);
  17309. else if( packet_db[cmd].func != NULL ) {
  17310. if( !sd && packet_db[cmd].func != clif_parse_WantToConnection )
  17311. ; //Only valid packet when there is no session
  17312. else
  17313. if( sd && sd->bl.prev == NULL && packet_db[cmd].func != clif_parse_LoadEndAck )
  17314. ; //Only valid packet when player is not on a map
  17315. else
  17316. packet_db[cmd].func(fd, sd);
  17317. }
  17318. #ifdef DUMP_UNKNOWN_PACKET
  17319. else DumpUnknown(fd,sd,cmd,packet_len);
  17320. #endif
  17321. RFIFOSKIP(fd, packet_len);
  17322. }; // main loop end
  17323. return 0;
  17324. }
  17325. void packetdb_addpacket( uint16 cmd, uint16 length, void (*func)(int, struct map_session_data *), ... ){
  17326. va_list argp;
  17327. int i;
  17328. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  17329. return;
  17330. packet_db[cmd].len = length;
  17331. packet_db[cmd].func = func;
  17332. va_start(argp, func);
  17333. for( i = 0; i < MAX_PACKET_POS; i++ ){
  17334. int offset = va_arg(argp, int);
  17335. if( offset == 0 ){
  17336. break;
  17337. }
  17338. packet_db[cmd].pos[i] = offset;
  17339. }
  17340. if( i == MAX_PACKET_POS ){
  17341. ShowError( "Too many positions found for packet 0x%04x (max=%d).\n", cmd, MAX_PACKET_POS );
  17342. }
  17343. va_end(argp);
  17344. }
  17345. /*==========================================
  17346. * Reads packets and setups its array reference
  17347. *------------------------------------------*/
  17348. void packetdb_readdb(){
  17349. memset(packet_db,0,sizeof(packet_db));
  17350. memset(packet_db_ack,0,sizeof(packet_db_ack));
  17351. #include "clif_packetdb.hpp"
  17352. #include "clif_shuffle.hpp"
  17353. ShowStatus("Using packet version: " CL_WHITE "%d" CL_RESET ".\n", PACKETVER);
  17354. #ifdef PACKET_OBFUSCATION
  17355. 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]);
  17356. #else
  17357. ShowStatus("Packet Obfuscation: " CL_RED "Disabled" CL_RESET ".\n");
  17358. #endif
  17359. }
  17360. /*==========================================
  17361. *
  17362. *------------------------------------------*/
  17363. void do_init_clif(void) {
  17364. const char* colors[COLOR_MAX] = {
  17365. "0x00FF00",
  17366. "0xFF0000",
  17367. "0xFFFFFF",
  17368. "0xFFFF00",
  17369. "0x00FFFF",
  17370. "0xB5FFB5",
  17371. };
  17372. int i;
  17373. /**
  17374. * Setup Color Table (saves unnecessary load of strtoul on every call)
  17375. **/
  17376. for(i = 0; i < COLOR_MAX; i++) {
  17377. color_table[i] = strtoul(colors[i],NULL,0);
  17378. color_table[i] = (color_table[i] & 0x0000FF) << 16 | (color_table[i] & 0x00FF00) | (color_table[i] & 0xFF0000) >> 16;//RGB to BGR
  17379. }
  17380. packetdb_readdb();
  17381. set_defaultparse(clif_parse);
  17382. if( make_listen_bind(bind_ip,map_port) == -1 ) {
  17383. ShowFatalError("Failed to bind to port '" CL_WHITE "%d" CL_RESET "'\n",map_port);
  17384. exit(EXIT_FAILURE);
  17385. }
  17386. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  17387. add_timer_func_list(clif_delayquit, "clif_delayquit");
  17388. delay_clearunit_ers = ers_new(sizeof(struct block_list),"clif.cpp::delay_clearunit_ers",ERS_OPT_CLEAR);
  17389. }
  17390. void do_final_clif(void) {
  17391. ers_destroy(delay_clearunit_ers);
  17392. }