clif.c 365 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "../common/cbasetypes.h"
  4. #include "../common/socket.h"
  5. #include "../common/timer.h"
  6. #include "../common/malloc.h"
  7. #include "../common/version.h"
  8. #include "../common/nullpo.h"
  9. #include "../common/showmsg.h"
  10. #include "../common/strlib.h"
  11. #include "../common/utils.h"
  12. #include "map.h"
  13. #include "chrif.h"
  14. #include "pc.h"
  15. #include "status.h"
  16. #include "npc.h"
  17. #include "itemdb.h"
  18. #include "chat.h"
  19. #include "trade.h"
  20. #include "storage.h"
  21. #include "script.h"
  22. #include "skill.h"
  23. #include "atcommand.h"
  24. #include "intif.h"
  25. #include "battle.h"
  26. #include "battleground.h"
  27. #include "mob.h"
  28. #include "party.h"
  29. #include "unit.h"
  30. #include "guild.h"
  31. #include "vending.h"
  32. #include "pet.h"
  33. #include "homunculus.h"
  34. #include "mercenary.h"
  35. #include "log.h"
  36. #include "clif.h"
  37. #include "mail.h"
  38. #include "quest.h"
  39. #include <stdio.h>
  40. #include <stdlib.h>
  41. #include <string.h>
  42. #include <stdarg.h>
  43. #include <time.h>
  44. #define DUMP_UNKNOWN_PACKET 0
  45. struct Clif_Config {
  46. int packet_db_ver; //Preferred packet version.
  47. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  48. } clif_config;
  49. struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
  50. //Converts item type in case of pet eggs.
  51. #define itemtype(a) (a == IT_PETEGG)?IT_WEAPON:a
  52. #define WBUFPOS(p,pos,x,y,dir) \
  53. do { \
  54. uint8 *__p = (p); \
  55. __p+=(pos); \
  56. __p[0] = (uint8)((x)>>2); \
  57. __p[1] = (uint8)(((x)<<6) | (((y)>>4)&0x3f)); \
  58. __p[2] = (uint8)(((y)<<4) | ((dir)&0xf)); \
  59. } while(0)
  60. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  61. #define WBUFPOS2(p,pos,x0,y0,x1,y1,sx0,sy0) \
  62. do { \
  63. uint8 *__p = (p); \
  64. __p+=(pos); \
  65. __p[0]=(uint8)((x0)>>2); \
  66. __p[1]=(uint8)(((x0)<<6) | (((y0)>>4)&0x3f)); \
  67. __p[2]=(uint8)(((y0)<<4) | (((x1)>>6)&0x0f)); \
  68. __p[3]=(uint8)(((x1)<<2) | (((y1)>>8)&0x03)); \
  69. __p[4]=(uint8)(y1); \
  70. __p[5]=(uint8)(((sx0)<<4) | ((sy0)&0x0f)); \
  71. } while(0)
  72. #define WFIFOPOS(fd,pos,x,y,dir) WBUFPOS(WFIFOP(fd,pos),0,x,y,dir)
  73. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1,sx0,sy0) WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1,sx0,sy0)
  74. //To idenfity disguised characters.
  75. #define disguised(bl) ((bl)->type==BL_PC && ((TBL_PC*)bl)->disguise)
  76. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex\]
  77. #define mes_len_check(mes, len, max) if (len > max) { mes[max-1] = '\0'; len = max; } else mes[len-1] = '\0';
  78. static char map_ip_str[128];
  79. static uint32 map_ip;
  80. static uint32 bind_ip = INADDR_ANY;
  81. static uint16 map_port = 5121;
  82. int map_fd;
  83. int clif_parse (int fd);
  84. /*==========================================
  85. * map鯖のip設定
  86. *------------------------------------------*/
  87. int clif_setip(const char* ip)
  88. {
  89. char ip_str[16];
  90. map_ip = host2ip(ip);
  91. if (!map_ip) {
  92. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  93. return 0;
  94. }
  95. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  96. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  97. return 1;
  98. }
  99. void clif_setbindip(const char* ip)
  100. {
  101. char ip_str[16];
  102. bind_ip = host2ip(ip);
  103. if (bind_ip) {
  104. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  105. } else {
  106. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  107. }
  108. }
  109. /*==========================================
  110. * map鯖のport設定
  111. *------------------------------------------*/
  112. void clif_setport(uint16 port)
  113. {
  114. map_port = port;
  115. }
  116. /*==========================================
  117. * map鯖のip読み出し
  118. *------------------------------------------*/
  119. uint32 clif_getip(void)
  120. {
  121. return map_ip;
  122. }
  123. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  124. uint32 clif_refresh_ip(void)
  125. {
  126. uint32 new_ip;
  127. new_ip = host2ip(map_ip_str);
  128. if (new_ip && new_ip != map_ip) {
  129. map_ip = new_ip;
  130. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  131. return map_ip;
  132. }
  133. return 0;
  134. }
  135. /*==========================================
  136. * map鯖のport読み出し
  137. *------------------------------------------*/
  138. uint16 clif_getport(void)
  139. {
  140. return map_port;
  141. }
  142. /*==========================================
  143. * clif_sendでAREA*指定時用
  144. *------------------------------------------*/
  145. int clif_send_sub(struct block_list *bl, va_list ap)
  146. {
  147. struct block_list *src_bl;
  148. struct map_session_data *sd;
  149. unsigned char *buf;
  150. int len, type, fd;
  151. nullpo_retr(0, bl);
  152. nullpo_retr(0, sd = (struct map_session_data *)bl);
  153. fd = sd->fd;
  154. if (!fd) //Don't send to disconnected clients.
  155. return 0;
  156. buf = va_arg(ap,unsigned char*);
  157. len = va_arg(ap,int);
  158. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  159. type = va_arg(ap,int);
  160. switch(type)
  161. {
  162. case AREA_WOS:
  163. if (bl == src_bl)
  164. return 0;
  165. break;
  166. case AREA_WOC:
  167. if (sd->chatID || bl == src_bl)
  168. return 0;
  169. break;
  170. case AREA_WOSC:
  171. {
  172. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  173. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  174. return 0;
  175. }
  176. break;
  177. }
  178. if (session[fd] == NULL)
  179. return 0;
  180. WFIFOHEAD(fd, len);
  181. if (WFIFOP(fd,0) == buf) {
  182. ShowError("WARNING: Invalid use of clif_send function\n");
  183. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  184. ShowError(" Please correct your code.\n");
  185. // don't send to not move the pointer of the packet for next sessions in the loop
  186. //WFIFOSET(fd,0);//## TODO is this ok?
  187. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  188. return 0;
  189. }
  190. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  191. memcpy(WFIFOP(fd,0), buf, len);
  192. WFIFOSET(fd,len);
  193. }
  194. return 0;
  195. }
  196. /*==========================================
  197. *
  198. *------------------------------------------*/
  199. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  200. {
  201. int i;
  202. struct map_session_data *sd, *tsd;
  203. struct party_data *p = NULL;
  204. struct guild *g = NULL;
  205. struct battleground_data *bg = NULL;
  206. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  207. struct s_mapiterator* iter;
  208. if( type != ALL_CLIENT && type != CHAT_MAINCHAT )
  209. nullpo_retr(0, bl);
  210. sd = BL_CAST(BL_PC, bl);
  211. switch(type) {
  212. case ALL_CLIENT: //All player clients.
  213. iter = mapit_getallusers();
  214. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  215. {
  216. if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  217. { // packet must exist for the client version
  218. WFIFOHEAD(tsd->fd, len);
  219. memcpy(WFIFOP(tsd->fd,0), buf, len);
  220. WFIFOSET(tsd->fd,len);
  221. }
  222. }
  223. mapit_free(iter);
  224. break;
  225. case ALL_SAMEMAP: //All players on the same map
  226. iter = mapit_getallusers();
  227. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  228. {
  229. if( bl->m == tsd->bl.m && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  230. { // packet must exist for the client version
  231. WFIFOHEAD(tsd->fd, len);
  232. memcpy(WFIFOP(tsd->fd,0), buf, len);
  233. WFIFOSET(tsd->fd,len);
  234. }
  235. }
  236. mapit_free(iter);
  237. break;
  238. case AREA:
  239. case AREA_WOSC:
  240. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  241. clif_send (buf, len, bl, SELF);
  242. case AREA_WOC:
  243. case AREA_WOS:
  244. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  245. BL_PC, buf, len, bl, type);
  246. break;
  247. case AREA_CHAT_WOC:
  248. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  249. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  250. break;
  251. case CHAT:
  252. case CHAT_WOS:
  253. {
  254. struct chat_data *cd;
  255. if (sd) {
  256. cd = (struct chat_data*)map_id2bl(sd->chatID);
  257. } else if (bl->type == BL_CHAT) {
  258. cd = (struct chat_data*)bl;
  259. } else break;
  260. if (cd == NULL)
  261. break;
  262. for(i = 0; i < cd->users; i++) {
  263. if (type == CHAT_WOS && cd->usersd[i] == sd)
  264. continue;
  265. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  266. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  267. {
  268. WFIFOHEAD(fd,len);
  269. memcpy(WFIFOP(fd,0), buf, len);
  270. WFIFOSET(fd,len);
  271. }
  272. }
  273. }
  274. }
  275. break;
  276. case CHAT_MAINCHAT: //[LuzZza]
  277. iter = mapit_getallusers();
  278. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  279. {
  280. if( tsd->state.mainchat && tsd->chatID == 0 && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  281. { // packet must exist for the client version
  282. WFIFOHEAD(tsd->fd, len);
  283. memcpy(WFIFOP(tsd->fd,0), buf, len);
  284. WFIFOSET(tsd->fd,len);
  285. }
  286. }
  287. mapit_free(iter);
  288. break;
  289. case PARTY_AREA:
  290. case PARTY_AREA_WOS:
  291. x0 = bl->x - AREA_SIZE;
  292. y0 = bl->y - AREA_SIZE;
  293. x1 = bl->x + AREA_SIZE;
  294. y1 = bl->y + AREA_SIZE;
  295. case PARTY:
  296. case PARTY_WOS:
  297. case PARTY_SAMEMAP:
  298. case PARTY_SAMEMAP_WOS:
  299. if (sd && sd->status.party_id)
  300. p = party_search(sd->status.party_id);
  301. if (p) {
  302. for(i=0;i<MAX_PARTY;i++){
  303. if( (sd = p->data[i].sd) == NULL )
  304. continue;
  305. if( !(fd=sd->fd) )
  306. continue;
  307. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  308. continue;
  309. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  310. continue;
  311. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  312. continue;
  313. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  314. { // packet must exist for the client version
  315. WFIFOHEAD(fd,len);
  316. memcpy(WFIFOP(fd,0), buf, len);
  317. WFIFOSET(fd,len);
  318. }
  319. }
  320. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  321. break;
  322. iter = mapit_getallusers();
  323. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  324. {
  325. if( tsd->partyspy == p->party.party_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  326. { // packet must exist for the client version
  327. WFIFOHEAD(tsd->fd, len);
  328. memcpy(WFIFOP(tsd->fd,0), buf, len);
  329. WFIFOSET(tsd->fd,len);
  330. }
  331. }
  332. mapit_free(iter);
  333. }
  334. break;
  335. case DUEL:
  336. case DUEL_WOS:
  337. if (!sd || !sd->duel_group) break; //Invalid usage.
  338. iter = mapit_getallusers();
  339. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  340. {
  341. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  342. continue;
  343. if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  344. { // packet must exist for the client version
  345. WFIFOHEAD(tsd->fd, len);
  346. memcpy(WFIFOP(tsd->fd,0), buf, len);
  347. WFIFOSET(tsd->fd,len);
  348. }
  349. }
  350. mapit_free(iter);
  351. break;
  352. case SELF:
  353. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  354. WFIFOHEAD(fd,len);
  355. memcpy(WFIFOP(fd,0), buf, len);
  356. WFIFOSET(fd,len);
  357. }
  358. break;
  359. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  360. case GUILD_AREA:
  361. case GUILD_AREA_WOS:
  362. x0 = bl->x - AREA_SIZE;
  363. y0 = bl->y - AREA_SIZE;
  364. x1 = bl->x + AREA_SIZE;
  365. y1 = bl->y + AREA_SIZE;
  366. case GUILD_SAMEMAP:
  367. case GUILD_SAMEMAP_WOS:
  368. case GUILD:
  369. case GUILD_WOS:
  370. case GUILD_NOBG:
  371. if (sd && sd->status.guild_id)
  372. g = guild_search(sd->status.guild_id);
  373. if (g) {
  374. for(i = 0; i < g->max_member; i++) {
  375. if( (sd = g->member[i].sd) != NULL )
  376. {
  377. if( !(fd=sd->fd) )
  378. continue;
  379. if( type == GUILD_NOBG && sd->state.bg_id )
  380. continue;
  381. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  382. continue;
  383. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  384. continue;
  385. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  386. continue;
  387. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  388. { // packet must exist for the client version
  389. WFIFOHEAD(fd,len);
  390. memcpy(WFIFOP(fd,0), buf, len);
  391. WFIFOSET(fd,len);
  392. }
  393. }
  394. }
  395. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  396. break;
  397. iter = mapit_getallusers();
  398. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  399. {
  400. if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  401. { // packet must exist for the client version
  402. WFIFOHEAD(tsd->fd, len);
  403. memcpy(WFIFOP(tsd->fd,0), buf, len);
  404. WFIFOSET(tsd->fd,len);
  405. }
  406. }
  407. mapit_free(iter);
  408. }
  409. break;
  410. case BG_AREA:
  411. case BG_AREA_WOS:
  412. x0 = bl->x - AREA_SIZE;
  413. y0 = bl->y - AREA_SIZE;
  414. x1 = bl->x + AREA_SIZE;
  415. y1 = bl->y + AREA_SIZE;
  416. case BG_SAMEMAP:
  417. case BG_SAMEMAP_WOS:
  418. case BG:
  419. case BG_WOS:
  420. if( sd && sd->state.bg_id && (bg = bg_team_search(sd->state.bg_id)) != NULL )
  421. {
  422. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  423. {
  424. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  425. continue;
  426. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  427. continue;
  428. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  429. continue;
  430. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  431. continue;
  432. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  433. { // packet must exist for the client version
  434. WFIFOHEAD(fd,len);
  435. memcpy(WFIFOP(fd,0), buf, len);
  436. WFIFOSET(fd,len);
  437. }
  438. }
  439. }
  440. break;
  441. default:
  442. ShowError("clif_send: Unrecognized type %d\n",type);
  443. return -1;
  444. }
  445. return 0;
  446. }
  447. //
  448. // パケット作って送信
  449. //
  450. /*==========================================
  451. *
  452. *------------------------------------------*/
  453. int clif_authok(struct map_session_data *sd)
  454. {
  455. int fd;
  456. if (!sd->fd)
  457. return 0;
  458. fd = sd->fd;
  459. WFIFOHEAD(fd, packet_len(0x73));
  460. WFIFOW(fd, 0) = 0x73;
  461. WFIFOL(fd, 2) = gettick();
  462. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  463. WFIFOB(fd, 9) = 5; // ignored
  464. WFIFOB(fd,10) = 5; // ignored
  465. WFIFOSET(fd,packet_len(0x73));
  466. return 0;
  467. }
  468. /*==========================================
  469. * Authentication failed/disconnect client.
  470. *------------------------------------------
  471. * The client closes it's socket and displays a message according to type:
  472. * 1 - server closed -> MsgStringTable[4]
  473. * 2 - ID already logged in -> MsgStringTable[5]
  474. * 3 - timeout/too much lag -> MsgStringTable[241]
  475. * 4 - server full -> MsgStringTable[264]
  476. * 5 - underaged -> MsgStringTable[305]
  477. * 8 - Server sill recognizes last connection -> MsgStringTable[441]
  478. * 9 - too many connections from this ip -> MsgStringTable[529]
  479. * 10 - out of available time paid for -> MsgStringTable[530]
  480. * 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  481. * other - disconnected -> MsgStringTable[3]
  482. */
  483. int clif_authfail_fd(int fd, int type)
  484. {
  485. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  486. return 0;
  487. WFIFOHEAD(fd, packet_len(0x81));
  488. WFIFOW(fd,0) = 0x81;
  489. WFIFOB(fd,2) = type;
  490. WFIFOSET(fd,packet_len(0x81));
  491. set_eof(fd);
  492. return 0;
  493. }
  494. /*==========================================
  495. *
  496. *------------------------------------------*/
  497. int clif_charselectok(int id)
  498. {
  499. struct map_session_data* sd;
  500. int fd;
  501. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  502. return 1;
  503. fd = sd->fd;
  504. WFIFOHEAD(fd,packet_len(0xb3));
  505. WFIFOW(fd,0) = 0xb3;
  506. WFIFOB(fd,2) = 1;
  507. WFIFOSET(fd,packet_len(0xb3));
  508. return 0;
  509. }
  510. /*==========================================
  511. * Makes an item appear on the ground
  512. * 009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  513. *------------------------------------------*/
  514. int clif_dropflooritem(struct flooritem_data* fitem)
  515. {
  516. uint8 buf[17];
  517. int view;
  518. nullpo_retr(0, fitem);
  519. if (fitem->item_data.nameid <= 0)
  520. return 0;
  521. WBUFW(buf, 0) = 0x9e;
  522. WBUFL(buf, 2) = fitem->bl.id;
  523. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  524. WBUFB(buf, 8) = fitem->item_data.identify;
  525. WBUFW(buf, 9) = fitem->bl.x;
  526. WBUFW(buf,11) = fitem->bl.y;
  527. WBUFB(buf,13) = fitem->subx;
  528. WBUFB(buf,14) = fitem->suby;
  529. WBUFW(buf,15) = fitem->item_data.amount;
  530. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  531. return 0;
  532. }
  533. /*==========================================
  534. *
  535. *------------------------------------------*/
  536. int clif_clearflooritem(struct flooritem_data *fitem, int fd)
  537. {
  538. unsigned char buf[16];
  539. nullpo_retr(0, fitem);
  540. WBUFW(buf,0) = 0xa1;
  541. WBUFL(buf,2) = fitem->bl.id;
  542. if (fd == 0) {
  543. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  544. } else {
  545. WFIFOHEAD(fd,packet_len(0xa1));
  546. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  547. WFIFOSET(fd,packet_len(0xa1));
  548. }
  549. return 0;
  550. }
  551. /*==========================================
  552. * make a unit (char, npc, mob, homun) disappear to one client
  553. * id : the id of the unit
  554. * type: 0 - moved out of sight
  555. * 1 - died
  556. * 2 - respawned
  557. * 3 - teleported / logged out
  558. * fd : the target client
  559. *------------------------------------------*/
  560. int clif_clearunit_single(int id, uint8 type, int fd)
  561. {
  562. WFIFOHEAD(fd, packet_len(0x80));
  563. WFIFOW(fd,0) = 0x80;
  564. WFIFOL(fd,2) = id;
  565. WFIFOB(fd,6) = type;
  566. WFIFOSET(fd, packet_len(0x80));
  567. return 0;
  568. }
  569. /*==========================================
  570. * make a unit (char, npc, mob, homun) disappear to all clients in area
  571. * type: 0 - moved out of sight
  572. * 1 - died
  573. * 2 - respawned
  574. * 3 - teleported / logged out
  575. *------------------------------------------*/
  576. int clif_clearunit_area(struct block_list* bl, uint8 type)
  577. {
  578. unsigned char buf[16];
  579. nullpo_retr(0, bl);
  580. WBUFW(buf,0) = 0x80;
  581. WBUFL(buf,2) = bl->id;
  582. WBUFB(buf,6) = type;
  583. clif_send(buf, packet_len(0x80), bl, type == 1 ? AREA : AREA_WOS);
  584. if(disguised(bl)) {
  585. WBUFL(buf,2) = -bl->id;
  586. clif_send(buf, packet_len(0x80), bl, SELF);
  587. }
  588. return 0;
  589. }
  590. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr data)
  591. {
  592. struct block_list *bl = (struct block_list *)data;
  593. clif_clearunit_area(bl, 0);
  594. aFree(bl);
  595. return 0;
  596. }
  597. int clif_clearunit_delayed(struct block_list* bl, unsigned int tick)
  598. {
  599. struct block_list *tbl;
  600. tbl = (struct block_list*)aMalloc(sizeof (struct block_list));
  601. memcpy (tbl, bl, sizeof (struct block_list));
  602. add_timer(tick, clif_clearunit_delayed_sub, 0, (intptr)tbl);
  603. return 0;
  604. }
  605. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  606. {
  607. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  608. {
  609. *rhand = *lhand = 0;
  610. return;
  611. }
  612. #if PACKETVER < 4
  613. *rhand = sd->status.weapon;
  614. *lhand = sd->status.shield;
  615. #else
  616. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  617. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  618. {
  619. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  620. if (id->view_id > 0)
  621. *rhand = id->view_id;
  622. else
  623. *rhand = id->nameid;
  624. } else
  625. *rhand = 0;
  626. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  627. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  628. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  629. {
  630. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  631. if (id->view_id > 0)
  632. *lhand = id->view_id;
  633. else
  634. *lhand = id->nameid;
  635. } else
  636. *lhand = 0;
  637. #endif
  638. }
  639. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  640. static int clif_setlevel(int lv)
  641. {
  642. if( lv < battle_config.max_lv )
  643. return lv;
  644. if( lv < battle_config.aura_lv )
  645. return battle_config.max_lv - 1;
  646. return battle_config.max_lv;
  647. }
  648. /*==========================================
  649. * Prepares 'unit standing/spawning' packet
  650. *------------------------------------------*/
  651. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  652. {
  653. struct map_session_data* sd;
  654. struct status_change* sc = status_get_sc(bl);
  655. struct view_data* vd = status_get_viewdata(bl);
  656. unsigned char *buf = WBUFP(buffer,0);
  657. bool type = !pcdb_checkid(vd->class_);
  658. #if PACKETVER >= 7
  659. unsigned short offset = 0;
  660. #endif
  661. sd = BL_CAST(BL_PC, bl);
  662. if(type)
  663. WBUFW(buf,0) = spawn?0x7c:0x78;
  664. else
  665. #if PACKETVER < 4
  666. WBUFW(buf,0) = spawn?0x79:0x78;
  667. #elif PACKETVER < 7
  668. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  669. #else
  670. WBUFW(buf,0) = spawn?0x22b:0x22a;
  671. #endif
  672. #if PACKETVER >= 20071106
  673. if (type) {
  674. // shift payload 1 byte to the right for mob packets
  675. WBUFB(buf,2) = 0; // padding?
  676. offset++;
  677. buf = WBUFP(buffer,offset);
  678. }
  679. #endif
  680. WBUFL(buf, 2) = bl->id;
  681. WBUFW(buf, 6) = status_get_speed(bl);
  682. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  683. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  684. if (type&&spawn) { //uses an older and different packet structure
  685. WBUFW(buf,12) = (sc)? sc->option : 0;
  686. WBUFW(buf,14) = vd->hair_style;
  687. WBUFW(buf,16) = vd->weapon;
  688. WBUFW(buf,18) = vd->head_bottom;
  689. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  690. WBUFW(buf,22) = vd->shield;
  691. } else {
  692. #if PACKETVER >= 7
  693. if (!type) {
  694. WBUFL(buf,12) = (sc)? sc->option : 0;
  695. offset+=2;
  696. buf = WBUFP(buffer,offset); //Shift 2 bytes to the right for the rest of fields
  697. } else
  698. #endif
  699. WBUFW(buf,12) = (sc)? sc->option : 0;
  700. WBUFW(buf,14) = vd->class_;
  701. WBUFW(buf,16) = vd->hair_style;
  702. WBUFW(buf,18) = vd->weapon;
  703. #if PACKETVER < 4
  704. WBUFW(buf,20) = vd->head_bottom;
  705. WBUFW(buf,22) = vd->shield;
  706. #else
  707. WBUFW(buf,20) = vd->shield;
  708. WBUFW(buf,22) = vd->head_bottom;
  709. #endif
  710. }
  711. WBUFW(buf,24) = vd->head_top;
  712. WBUFW(buf,26) = vd->head_mid;
  713. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  714. { //The hell, why flags work like this?
  715. WBUFL(buf,22) = status_get_emblem_id(bl);
  716. WBUFL(buf,26) = status_get_guild_id(bl);
  717. }
  718. WBUFW(buf,28) = vd->hair_color;
  719. WBUFW(buf,30) = vd->cloth_color;
  720. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  721. if (type&&spawn) { //End of packet 0x7c
  722. WBUFB(buf,34) = 0; // karma
  723. WBUFB(buf,35) = vd->sex;
  724. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  725. WBUFB(buf,39) = 0;
  726. WBUFB(buf,40) = 0;
  727. return packet_len(0x7c);
  728. }
  729. WBUFL(buf,34) = status_get_guild_id(bl);
  730. WBUFW(buf,38) = status_get_emblem_id(bl);
  731. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  732. #if PACKETVER >= 7
  733. if (!type) {
  734. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  735. offset+=2;
  736. buf = WBUFP(buffer,offset); //Shift additional 2 bytes...
  737. } else
  738. #endif
  739. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  740. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  741. WBUFB(buf,45) = vd->sex;
  742. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  743. WBUFB(buf,49) = (sd)? 5 : 0;
  744. WBUFB(buf,50) = (sd)? 5 : 0;
  745. if (spawn) {
  746. WBUFW(buf,51) = clif_setlevel(status_get_lv(bl));
  747. } else {
  748. WBUFB(buf,51) = vd->dead_sit;
  749. WBUFW(buf,52) = clif_setlevel(status_get_lv(bl));
  750. }
  751. return packet_len(WBUFW(buffer,0));
  752. }
  753. /*==========================================
  754. * Prepares 'unit walking' packet
  755. *------------------------------------------*/
  756. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  757. {
  758. struct map_session_data* sd;
  759. struct status_change* sc = status_get_sc(bl);
  760. struct view_data* vd = status_get_viewdata(bl);
  761. unsigned char* buf = WBUFP(buffer,0);
  762. #if PACKETVER >= 7
  763. unsigned short offset = 0;
  764. #endif
  765. sd = BL_CAST(BL_PC, bl);
  766. #if PACKETVER < 4
  767. WBUFW(buf, 0) = 0x7b;
  768. #elif PACKETVER < 7
  769. WBUFW(buf, 0) = 0x1da;
  770. #else
  771. WBUFW(buf, 0) = 0x22c;
  772. #endif
  773. #if PACKETVER >= 20071106
  774. WBUFB(buf, 2) = 0; // padding?
  775. offset++;
  776. buf = WBUFP(buf,offset);
  777. #endif
  778. WBUFL(buf, 2) = bl->id;
  779. WBUFW(buf, 6) = status_get_speed(bl);
  780. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  781. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  782. #if PACKETVER < 7
  783. WBUFW(buf,12) = (sc)? sc->option : 0;
  784. #else
  785. WBUFL(buf,12) = (sc)? sc->option : 0;
  786. offset+=2; //Shift the rest of elements by 2 bytes.
  787. buf = WBUFP(buffer,offset);
  788. #endif
  789. WBUFW(buf,14) = vd->class_;
  790. WBUFW(buf,16) = vd->hair_style;
  791. WBUFW(buf,18) = vd->weapon;
  792. #if PACKETVER < 4
  793. WBUFW(buf,20) = vd->head_bottom;
  794. WBUFL(buf,22) = gettick();
  795. WBUFW(buf,26) = vd->shield;
  796. #else
  797. WBUFW(buf,20) = vd->shield;
  798. WBUFW(buf,22) = vd->head_bottom;
  799. WBUFL(buf,24) = gettick();
  800. #endif
  801. WBUFW(buf,28) = vd->head_top;
  802. WBUFW(buf,30) = vd->head_mid;
  803. WBUFW(buf,32) = vd->hair_color;
  804. WBUFW(buf,34) = vd->cloth_color;
  805. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  806. WBUFL(buf,38) = status_get_guild_id(bl);
  807. WBUFW(buf,42) = status_get_emblem_id(bl);
  808. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  809. #if PACKETVER < 7
  810. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  811. #else
  812. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  813. offset+=2; //Shift the rest of elements by 2 bytes.
  814. buf = WBUFP(buffer,offset);
  815. #endif
  816. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  817. WBUFB(buf,49) = vd->sex;
  818. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  819. WBUFB(buf,56) = (sd)? 5 : 0;
  820. WBUFB(buf,57) = (sd)? 5 : 0;
  821. WBUFW(buf,58) = clif_setlevel(status_get_lv(bl));
  822. return packet_len(WBUFW(buffer,0));
  823. }
  824. //Modifies the buffer for disguise characters and sends it to self.
  825. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  826. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  827. {
  828. #if PACKETVER >= 20071106
  829. WBUFL(buf,3)=-bl->id;
  830. #else
  831. WBUFL(buf,2)=-bl->id;
  832. #endif
  833. clif_send(buf, len, bl, SELF);
  834. }
  835. /*==========================================
  836. * クラスチェンジ typeはMobの場合は1で他は0?
  837. *------------------------------------------*/
  838. int clif_class_change(struct block_list *bl,int class_,int type)
  839. {
  840. unsigned char buf[16];
  841. nullpo_retr(0, bl);
  842. if(!pcdb_checkid(class_)) {
  843. WBUFW(buf,0)=0x1b0;
  844. WBUFL(buf,2)=bl->id;
  845. WBUFB(buf,6)=type;
  846. WBUFL(buf,7)=class_;
  847. clif_send(buf,packet_len(0x1b0),bl,AREA);
  848. }
  849. return 0;
  850. }
  851. /*==========================================
  852. *
  853. *------------------------------------------*/
  854. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  855. {
  856. WFIFOHEAD(fd, packet_len(0x1e1));
  857. WFIFOW(fd,0)=0x1e1;
  858. WFIFOL(fd,2)=sd->bl.id;
  859. WFIFOW(fd,6)=sd->spiritball;
  860. WFIFOSET(fd, packet_len(0x1e1));
  861. }
  862. // new and improved weather display [Valaris]
  863. static void clif_weather_sub(int fd, int id, int type)
  864. {
  865. WFIFOHEAD(fd,packet_len(0x1f3));
  866. WFIFOW(fd,0) = 0x1f3;
  867. WFIFOL(fd,2) = id;
  868. WFIFOL(fd,6) = type;
  869. WFIFOSET(fd,packet_len(0x1f3));
  870. }
  871. /*==========================================
  872. *
  873. *------------------------------------------*/
  874. static void clif_weather_check(struct map_session_data *sd)
  875. {
  876. int m = sd->bl.m, fd = sd->fd;
  877. if (map[m].flag.snow
  878. || map[m].flag.clouds
  879. || map[m].flag.fog
  880. || map[m].flag.fireworks
  881. || map[m].flag.sakura
  882. || map[m].flag.leaves
  883. || map[m].flag.rain
  884. || map[m].flag.clouds2)
  885. {
  886. if (map[m].flag.snow)
  887. clif_weather_sub(fd, sd->bl.id, 162);
  888. if (map[m].flag.clouds)
  889. clif_weather_sub(fd, sd->bl.id, 233);
  890. if (map[m].flag.clouds2)
  891. clif_weather_sub(fd, sd->bl.id, 516);
  892. if (map[m].flag.fog)
  893. clif_weather_sub(fd, sd->bl.id, 515);
  894. if (map[m].flag.fireworks) {
  895. clif_weather_sub(fd, sd->bl.id, 297);
  896. clif_weather_sub(fd, sd->bl.id, 299);
  897. clif_weather_sub(fd, sd->bl.id, 301);
  898. }
  899. if (map[m].flag.sakura)
  900. clif_weather_sub(fd, sd->bl.id, 163);
  901. if (map[m].flag.leaves)
  902. clif_weather_sub(fd, sd->bl.id, 333);
  903. if (map[m].flag.rain)
  904. clif_weather_sub(fd, sd->bl.id, 161);
  905. }
  906. }
  907. void clif_weather(int m)
  908. {
  909. struct s_mapiterator* iter;
  910. struct map_session_data *sd=NULL;
  911. iter = mapit_getallusers();
  912. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  913. {
  914. if( sd->bl.m == m )
  915. clif_weather_check(sd);
  916. }
  917. mapit_free(iter);
  918. }
  919. int clif_spawn(struct block_list *bl)
  920. {
  921. unsigned char buf[128];
  922. struct view_data *vd;
  923. int len;
  924. vd = status_get_viewdata(bl);
  925. if( !vd || vd->class_ == INVISIBLE_CLASS )
  926. return 0;
  927. len = clif_set_unit_idle(bl, buf,true);
  928. clif_send(buf, len, bl, AREA_WOS);
  929. if (disguised(bl))
  930. clif_setdisguise(bl, buf, len);
  931. if (vd->cloth_color)
  932. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  933. switch (bl->type)
  934. {
  935. case BL_PC:
  936. {
  937. TBL_PC *sd = ((TBL_PC*)bl);
  938. if (sd->spiritball > 0)
  939. clif_spiritball(sd);
  940. if(sd->state.size==2) // tiny/big players [Valaris]
  941. clif_specialeffect(bl,423,AREA);
  942. else if(sd->state.size==1)
  943. clif_specialeffect(bl,421,AREA);
  944. if( sd->state.user_font )
  945. clif_font_area(sd);
  946. if( sd->state.bg_id && map[sd->bl.m].flag.battleground )
  947. clif_sendbgemblem_area(sd);
  948. }
  949. break;
  950. case BL_MOB:
  951. {
  952. TBL_MOB *md = ((TBL_MOB*)bl);
  953. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  954. clif_specialeffect(&md->bl,423,AREA);
  955. else if(md->special_state.size==1)
  956. clif_specialeffect(&md->bl,421,AREA);
  957. }
  958. break;
  959. case BL_NPC:
  960. {
  961. TBL_NPC *nd = ((TBL_NPC*)bl);
  962. if( nd->size == 2 )
  963. clif_specialeffect(&nd->bl,423,AREA);
  964. else if( nd->size == 1 )
  965. clif_specialeffect(&nd->bl,421,AREA);
  966. }
  967. break;
  968. case BL_PET:
  969. if (vd->head_bottom)
  970. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  971. break;
  972. }
  973. return 0;
  974. }
  975. //[orn]
  976. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  977. {
  978. struct status_data *status;
  979. unsigned char buf[128];
  980. nullpo_retr(0, hd);
  981. status = &hd->battle_status;
  982. memset(buf,0,packet_len(0x22e));
  983. WBUFW(buf,0)=0x22e;
  984. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  985. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  986. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  987. WBUFW(buf,27)=hd->homunculus.level;
  988. WBUFW(buf,29)=hd->homunculus.hunger;
  989. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  990. WBUFW(buf,33)=0; // equip id
  991. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, SHRT_MAX);
  992. WBUFW(buf,37)=cap_value(status->matk_max, 0, SHRT_MAX);
  993. WBUFW(buf,39)=status->hit;
  994. if (battle_config.hom_setting&0x10)
  995. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  996. else
  997. WBUFW(buf,41)=status->cri/10;
  998. WBUFW(buf,43)=status->def + status->vit ;
  999. WBUFW(buf,45)=status->mdef;
  1000. WBUFW(buf,47)=status->flee;
  1001. WBUFW(buf,49)=(flag)?0:status->amotion;
  1002. if (status->max_hp > SHRT_MAX) {
  1003. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1004. WBUFW(buf,53) = 100;
  1005. } else {
  1006. WBUFW(buf,51)=status->hp;
  1007. WBUFW(buf,53)=status->max_hp;
  1008. }
  1009. if (status->max_sp > SHRT_MAX) {
  1010. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1011. WBUFW(buf,57) = 100;
  1012. } else {
  1013. WBUFW(buf,55)=status->sp;
  1014. WBUFW(buf,57)=status->max_sp;
  1015. }
  1016. WBUFL(buf,59)=hd->homunculus.exp;
  1017. WBUFL(buf,63)=hd->exp_next;
  1018. WBUFW(buf,67)=hd->homunculus.skillpts;
  1019. WBUFW(buf,69)=2; // FIXME: undocumented flag, seems to be '2' all the time [ultramage]
  1020. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1021. return 0;
  1022. }
  1023. void clif_send_homdata(struct map_session_data *sd, int type, int param)
  1024. { //[orn]
  1025. int fd = sd->fd;
  1026. WFIFOHEAD(fd, packet_len(0x230));
  1027. nullpo_retv(sd->hd);
  1028. WFIFOW(fd,0)=0x230;
  1029. WFIFOW(fd,2)=type;
  1030. WFIFOL(fd,4)=sd->hd->bl.id;
  1031. WFIFOL(fd,8)=param;
  1032. WFIFOSET(fd,packet_len(0x230));
  1033. return;
  1034. }
  1035. int clif_homskillinfoblock(struct map_session_data *sd)
  1036. { //[orn]
  1037. struct homun_data *hd;
  1038. int fd = sd->fd;
  1039. int i,j,len=4,id;
  1040. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1041. hd = sd->hd;
  1042. if ( !hd )
  1043. return 0 ;
  1044. WFIFOW(fd,0)=0x235;
  1045. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1046. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1047. j = id - HM_SKILLBASE;
  1048. WFIFOW(fd,len ) = id;
  1049. WFIFOW(fd,len+2) = skill_get_inf(id);
  1050. WFIFOW(fd,len+4) = 0;
  1051. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv;
  1052. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
  1053. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
  1054. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1055. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1056. len+=37;
  1057. }
  1058. }
  1059. WFIFOW(fd,2)=len;
  1060. WFIFOSET(fd,len);
  1061. return 0;
  1062. }
  1063. void clif_homskillup(struct map_session_data *sd, int skill_num)
  1064. { //[orn]
  1065. struct homun_data *hd;
  1066. int fd=sd->fd, skillid;
  1067. WFIFOHEAD(fd, packet_len(0x239));
  1068. nullpo_retv(sd);
  1069. skillid = skill_num - HM_SKILLBASE;
  1070. hd=sd->hd;
  1071. WFIFOW(fd,0) = 0x239;
  1072. WFIFOW(fd,2) = skill_num;
  1073. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1074. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1075. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1076. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1077. WFIFOSET(fd,packet_len(0x239));
  1078. return;
  1079. }
  1080. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1081. {
  1082. int fd=sd->fd;
  1083. WFIFOHEAD(fd,packet_len(0x22f));
  1084. WFIFOW(fd,0)=0x22f;
  1085. WFIFOB(fd,2)=fail;
  1086. WFIFOW(fd,3)=foodid;
  1087. WFIFOSET(fd,packet_len(0x22f));
  1088. return 0;
  1089. }
  1090. /*==========================================
  1091. *
  1092. *------------------------------------------*/
  1093. int clif_walkok(struct map_session_data *sd)
  1094. {
  1095. int fd=sd->fd;
  1096. WFIFOHEAD(fd, packet_len(0x87));
  1097. WFIFOW(fd,0)=0x87;
  1098. WFIFOL(fd,2)=gettick();
  1099. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1100. WFIFOSET(fd,packet_len(0x87));
  1101. return 0;
  1102. }
  1103. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1104. {
  1105. uint8 buf[128];
  1106. int len;
  1107. len = clif_set_unit_walking(bl,ud,buf);
  1108. clif_send(buf,len,bl,AREA_WOS);
  1109. if (disguised(bl))
  1110. clif_setdisguise(bl, buf, len);
  1111. if(vd->cloth_color)
  1112. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1113. switch(bl->type)
  1114. {
  1115. case BL_PC:
  1116. {
  1117. TBL_PC *sd = ((TBL_PC*)bl);
  1118. // clif_movepc(sd);
  1119. if(sd->state.size==2) // tiny/big players [Valaris]
  1120. clif_specialeffect(&sd->bl,423,AREA);
  1121. else if(sd->state.size==1)
  1122. clif_specialeffect(&sd->bl,421,AREA);
  1123. }
  1124. break;
  1125. case BL_MOB:
  1126. {
  1127. TBL_MOB *md = ((TBL_MOB*)bl);
  1128. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1129. clif_specialeffect(&md->bl,423,AREA);
  1130. else if(md->special_state.size==1)
  1131. clif_specialeffect(&md->bl,421,AREA);
  1132. }
  1133. break;
  1134. }
  1135. return;
  1136. }
  1137. /// Move the unit (does nothing if the client has no info about the unit)
  1138. /// Note: unit must not be self
  1139. void clif_move(struct unit_data *ud)
  1140. {
  1141. unsigned char buf[16];
  1142. struct view_data* vd;
  1143. struct block_list* bl = ud->bl;
  1144. vd = status_get_viewdata(bl);
  1145. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1146. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1147. if (ud->state.speed_changed) {
  1148. // Since we don't know how to update the speed of other objects,
  1149. // use the old walk packet to update the data.
  1150. ud->state.speed_changed = 0;
  1151. clif_move2(bl, vd, ud);
  1152. return;
  1153. }
  1154. WBUFW(buf,0)=0x86;
  1155. WBUFL(buf,2)=bl->id;
  1156. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1157. WBUFL(buf,12)=gettick();
  1158. clif_send(buf, 16, bl, AREA_WOS);
  1159. if (disguised(bl))
  1160. {
  1161. WBUFL(buf,2)=-bl->id;
  1162. clif_send(buf, 16, bl, SELF);
  1163. }
  1164. }
  1165. /*==========================================
  1166. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1167. *------------------------------------------*/
  1168. static int clif_delayquit(int tid, unsigned int tick, int id, intptr data)
  1169. {
  1170. struct map_session_data *sd = NULL;
  1171. //Remove player from map server
  1172. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1173. map_quit(sd);
  1174. return 0;
  1175. }
  1176. /*==========================================
  1177. *
  1178. *------------------------------------------*/
  1179. void clif_quitsave(int fd,struct map_session_data *sd)
  1180. {
  1181. if (!battle_config.prevent_logout ||
  1182. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1183. map_quit(sd);
  1184. else if (sd->fd)
  1185. { //Disassociate session from player (session is deleted after this function was called)
  1186. //And set a timer to make him quit later.
  1187. session[sd->fd]->session_data = NULL;
  1188. sd->fd = 0;
  1189. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1190. }
  1191. }
  1192. /*==========================================
  1193. *
  1194. *------------------------------------------*/
  1195. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1196. {
  1197. int fd;
  1198. nullpo_retv(sd);
  1199. fd = sd->fd;
  1200. WFIFOHEAD(fd,packet_len(0x91));
  1201. WFIFOW(fd,0) = 0x91;
  1202. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1203. WFIFOW(fd,18) = x;
  1204. WFIFOW(fd,20) = y;
  1205. WFIFOSET(fd,packet_len(0x91));
  1206. }
  1207. /*==========================================
  1208. * Tells the client to connect to another map-server
  1209. *------------------------------------------*/
  1210. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1211. {
  1212. int fd;
  1213. nullpo_retv(sd);
  1214. fd = sd->fd;
  1215. WFIFOHEAD(fd,packet_len(0x92));
  1216. WFIFOW(fd,0) = 0x92;
  1217. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1218. WFIFOW(fd,18) = x;
  1219. WFIFOW(fd,20) = y;
  1220. WFIFOL(fd,22) = htonl(ip);
  1221. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1222. WFIFOSET(fd,packet_len(0x92));
  1223. }
  1224. void clif_blown(struct block_list *bl)
  1225. {
  1226. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1227. // clif_fixpos(bl);
  1228. clif_slide(bl, bl->x, bl->y);
  1229. }
  1230. /*==========================================
  1231. *
  1232. *------------------------------------------*/
  1233. void clif_fixpos(struct block_list *bl)
  1234. {
  1235. unsigned char buf[10];
  1236. nullpo_retv(bl);
  1237. WBUFW(buf,0) = 0x88;
  1238. WBUFL(buf,2) = bl->id;
  1239. WBUFW(buf,6) = bl->x;
  1240. WBUFW(buf,8) = bl->y;
  1241. clif_send(buf, packet_len(0x88), bl, AREA);
  1242. if( disguised(bl) )
  1243. {
  1244. WBUFL(buf,2) = -bl->id;
  1245. clif_send(buf, packet_len(0x88), bl, SELF);
  1246. }
  1247. }
  1248. /*==========================================
  1249. *
  1250. *------------------------------------------*/
  1251. int clif_npcbuysell(struct map_session_data* sd, int id)
  1252. {
  1253. int fd;
  1254. nullpo_retr(0, sd);
  1255. fd=sd->fd;
  1256. WFIFOHEAD(fd, packet_len(0xc4));
  1257. WFIFOW(fd,0)=0xc4;
  1258. WFIFOL(fd,2)=id;
  1259. WFIFOSET(fd,packet_len(0xc4));
  1260. return 0;
  1261. }
  1262. /*==========================================
  1263. *
  1264. *------------------------------------------*/
  1265. int clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1266. {
  1267. int fd,i,c;
  1268. nullpo_retr(0, sd);
  1269. nullpo_retr(0, nd);
  1270. fd = sd->fd;
  1271. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1272. WFIFOW(fd,0) = 0xc6;
  1273. c = 0;
  1274. for( i = 0; i < nd->u.shop.count; i++ )
  1275. {
  1276. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1277. int val = nd->u.shop.shop_item[i].value;
  1278. if( id == NULL )
  1279. continue;
  1280. WFIFOL(fd, 4+c*11) = val;
  1281. if (!id->flag.value_notdc)
  1282. val = pc_modifybuyvalue(sd,val);
  1283. WFIFOL(fd, 8+c*11) = val;
  1284. WFIFOB(fd,12+c*11) = itemtype(id->type);
  1285. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1286. c++;
  1287. }
  1288. WFIFOW(fd,2) = 4 + c*11;
  1289. WFIFOSET(fd,WFIFOW(fd,2));
  1290. return 0;
  1291. }
  1292. /*==========================================
  1293. *
  1294. *------------------------------------------*/
  1295. int clif_selllist(struct map_session_data *sd)
  1296. {
  1297. int fd,i,c=0,val;
  1298. nullpo_retr(0, sd);
  1299. fd=sd->fd;
  1300. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1301. WFIFOW(fd,0)=0xc7;
  1302. for( i = 0; i < MAX_INVENTORY; i++ )
  1303. {
  1304. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1305. {
  1306. if( !itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)) )
  1307. continue;
  1308. if( sd->status.inventory[i].expire_time )
  1309. continue; // Cannot Sell Rental Items
  1310. val=sd->inventory_data[i]->value_sell;
  1311. if( val < 0 )
  1312. continue;
  1313. WFIFOW(fd,4+c*10)=i+2;
  1314. WFIFOL(fd,6+c*10)=val;
  1315. if( !sd->inventory_data[i]->flag.value_notoc )
  1316. val=pc_modifysellvalue(sd,val);
  1317. WFIFOL(fd,10+c*10)=val;
  1318. c++;
  1319. }
  1320. }
  1321. WFIFOW(fd,2)=c*10+4;
  1322. WFIFOSET(fd,WFIFOW(fd,2));
  1323. return 0;
  1324. }
  1325. /// Client behavior (dialog window):
  1326. /// - disable mouse targeting
  1327. /// - open the dialog window
  1328. /// - set npcid of dialog window (0 by default)
  1329. /// - if set to clear on next mes, clear contents
  1330. /// - append this text
  1331. int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1332. {
  1333. int fd = sd->fd;
  1334. int slen = strlen(mes) + 9;
  1335. WFIFOHEAD(fd, slen);
  1336. WFIFOW(fd,0)=0xb4;
  1337. WFIFOW(fd,2)=slen;
  1338. WFIFOL(fd,4)=npcid;
  1339. strcpy((char*)WFIFOP(fd,8),mes);
  1340. WFIFOSET(fd,WFIFOW(fd,2));
  1341. return 0;
  1342. }
  1343. /// Client behavior (dialog window):
  1344. /// - disable mouse targeting
  1345. /// - open the dialog window
  1346. /// - add 'next' button
  1347. /// When 'next' is pressed:
  1348. /// - S 00B9 <npcid of dialog window>.L
  1349. /// - set to clear on next mes
  1350. /// - remove 'next' button
  1351. int clif_scriptnext(struct map_session_data *sd,int npcid)
  1352. {
  1353. int fd;
  1354. nullpo_retr(0, sd);
  1355. fd=sd->fd;
  1356. WFIFOHEAD(fd, packet_len(0xb5));
  1357. WFIFOW(fd,0)=0xb5;
  1358. WFIFOL(fd,2)=npcid;
  1359. WFIFOSET(fd,packet_len(0xb5));
  1360. return 0;
  1361. }
  1362. /// Client behavior:
  1363. /// - if dialog window is open:
  1364. /// - remove 'next' button
  1365. /// - add 'close' button
  1366. /// - else:
  1367. /// - enable mouse targeting
  1368. /// - close the dialog window
  1369. /// - close the menu window
  1370. /// When 'close' is pressed:
  1371. /// - enable mouse targeting
  1372. /// - close the dialog window
  1373. /// - close the menu window
  1374. /// - S 0146 <npcid of dialog window>.L
  1375. int clif_scriptclose(struct map_session_data *sd, int npcid)
  1376. {
  1377. int fd;
  1378. nullpo_retr(0, sd);
  1379. fd=sd->fd;
  1380. WFIFOHEAD(fd, packet_len(0xb6));
  1381. WFIFOW(fd,0)=0xb6;
  1382. WFIFOL(fd,2)=npcid;
  1383. WFIFOSET(fd,packet_len(0xb6));
  1384. return 0;
  1385. }
  1386. /*==========================================
  1387. *
  1388. *------------------------------------------*/
  1389. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1390. {
  1391. unsigned char *buf;
  1392. int fd = sd->fd;
  1393. sd->state.using_fake_npc = 1;
  1394. WFIFOHEAD(fd, packet_len(0x78));
  1395. buf = WFIFOP(fd,0);
  1396. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1397. WBUFW(buf,0)=0x78;
  1398. #if PACKETVER >= 20071106
  1399. WBUFB(buf,2) = 0; //Unknown bit
  1400. buf = WFIFOP(fd,1);
  1401. #endif
  1402. WBUFL(buf,2)=npcid;
  1403. WBUFW(buf,14)=111;
  1404. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1405. WBUFB(buf,49)=5;
  1406. WBUFB(buf,50)=5;
  1407. WFIFOSET(fd, packet_len(0x78));
  1408. return;
  1409. }
  1410. /// Client behavior:
  1411. /// - disable mouse targeting
  1412. /// - close the menu window
  1413. /// - open the menu window
  1414. /// - add options to the menu (separated in the text by ":")
  1415. /// - set npcid of menu window
  1416. /// - if dialog window is open:
  1417. /// - remove 'next' button
  1418. /// When 'ok' is pressed:
  1419. /// - S 00B8 <npcid of menu window>.L <selected option>.B
  1420. /// - close the menu window
  1421. /// When 'cancel' is pressed:
  1422. /// - S 00B8 <npcid of menu window>.L <-1>.B
  1423. /// - enable mouse targeting
  1424. /// - close a bunch of windows...
  1425. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1426. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1427. /// TODO investigate behavior of other windows [FlavioJS]
  1428. int clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1429. {
  1430. int fd = sd->fd;
  1431. int slen = strlen(mes) + 8;
  1432. struct block_list *bl = NULL;
  1433. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1434. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1435. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1436. clif_sendfakenpc(sd, npcid);
  1437. WFIFOHEAD(fd, slen);
  1438. WFIFOW(fd,0)=0xb7;
  1439. WFIFOW(fd,2)=slen;
  1440. WFIFOL(fd,4)=npcid;
  1441. strcpy((char*)WFIFOP(fd,8),mes);
  1442. WFIFOSET(fd,WFIFOW(fd,2));
  1443. return 0;
  1444. }
  1445. /// Client behavior (inputnum window):
  1446. /// - if npcid exists in the client:
  1447. /// - open the inputnum window
  1448. /// - set npcid of inputnum window
  1449. /// When 'ok' is pressed:
  1450. /// - if inputnum window has text:
  1451. /// - if npcid exists in the client:
  1452. /// - S 0143 <npcid of inputnum window>.L <atoi(text)>.L
  1453. /// - close inputnum window
  1454. int clif_scriptinput(struct map_session_data *sd, int npcid)
  1455. {
  1456. int fd;
  1457. struct block_list *bl = NULL;
  1458. nullpo_retr(0, sd);
  1459. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1460. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1461. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1462. clif_sendfakenpc(sd, npcid);
  1463. fd=sd->fd;
  1464. WFIFOHEAD(fd, packet_len(0x142));
  1465. WFIFOW(fd,0)=0x142;
  1466. WFIFOL(fd,2)=npcid;
  1467. WFIFOSET(fd,packet_len(0x142));
  1468. return 0;
  1469. }
  1470. /// Client behavior (inputstr window):
  1471. /// - if npcid is 0 or npcid exists in the client:
  1472. /// - open the inputstr window
  1473. /// - set npcid of inputstr window
  1474. /// When 'ok' is pressed:
  1475. /// - if inputstr window has text and isn't an insult(manner.txt):
  1476. /// - if npcid is 0 or npcid exists in the client:
  1477. /// - S 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  1478. /// - close inputstr window
  1479. int clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1480. {
  1481. int fd;
  1482. struct block_list *bl = NULL;
  1483. nullpo_retr(0, sd);
  1484. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1485. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1486. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1487. clif_sendfakenpc(sd, npcid);
  1488. fd=sd->fd;
  1489. WFIFOHEAD(fd, packet_len(0x1d4));
  1490. WFIFOW(fd,0)=0x1d4;
  1491. WFIFOL(fd,2)=npcid;
  1492. WFIFOSET(fd,packet_len(0x1d4));
  1493. return 0;
  1494. }
  1495. /// npc_id is ignored in the client
  1496. /// type=2 : Remove viewpoint
  1497. /// type=other : Show viewpoint
  1498. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1499. {
  1500. int fd;
  1501. nullpo_retr(0, sd);
  1502. fd=sd->fd;
  1503. WFIFOHEAD(fd, packet_len(0x144));
  1504. WFIFOW(fd,0)=0x144;
  1505. WFIFOL(fd,2)=npc_id;
  1506. WFIFOL(fd,6)=type;
  1507. WFIFOL(fd,10)=x;
  1508. WFIFOL(fd,14)=y;
  1509. WFIFOB(fd,18)=id;
  1510. WFIFOL(fd,19)=color;
  1511. WFIFOSET(fd,packet_len(0x144));
  1512. return 0;
  1513. }
  1514. /*==========================================
  1515. *
  1516. *------------------------------------------*/
  1517. int clif_cutin(struct map_session_data* sd, const char* image, int type)
  1518. {
  1519. int fd;
  1520. nullpo_retr(0, sd);
  1521. fd=sd->fd;
  1522. WFIFOHEAD(fd, packet_len(0x1b3));
  1523. WFIFOW(fd,0)=0x1b3;
  1524. strncpy((char*)WFIFOP(fd,2),image,64);
  1525. WFIFOB(fd,66)=type;
  1526. WFIFOSET(fd,packet_len(0x1b3));
  1527. return 0;
  1528. }
  1529. /*==========================================
  1530. * Fills in card data from the given item and into the buffer. [Skotlex]
  1531. *------------------------------------------*/
  1532. static void clif_addcards(unsigned char* buf, struct item* item)
  1533. {
  1534. int i=0,j;
  1535. if( item == NULL ) { //Blank data
  1536. WBUFW(buf,0) = 0;
  1537. WBUFW(buf,2) = 0;
  1538. WBUFW(buf,4) = 0;
  1539. WBUFW(buf,6) = 0;
  1540. return;
  1541. }
  1542. if( item->card[0] == CARD0_PET ) { //pet eggs
  1543. WBUFW(buf,0) = 0;
  1544. WBUFW(buf,2) = 0;
  1545. WBUFW(buf,4) = 0;
  1546. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1547. return;
  1548. }
  1549. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1550. WBUFW(buf,0) = item->card[0];
  1551. WBUFW(buf,2) = item->card[1];
  1552. WBUFW(buf,4) = item->card[2];
  1553. WBUFW(buf,6) = item->card[3];
  1554. return;
  1555. }
  1556. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1557. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1558. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1559. //Normal items.
  1560. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1561. WBUFW(buf,0) = j;
  1562. else
  1563. WBUFW(buf,0) = item->card[i];
  1564. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1565. WBUFW(buf,2) = j;
  1566. else
  1567. WBUFW(buf,2) = item->card[i];
  1568. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1569. WBUFW(buf,4) = j;
  1570. else
  1571. WBUFW(buf,4) = item->card[i];
  1572. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1573. WBUFW(buf,6) = j;
  1574. else
  1575. WBUFW(buf,6) = item->card[i];
  1576. }
  1577. /*==========================================
  1578. *
  1579. *------------------------------------------*/
  1580. int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1581. {
  1582. int fd;
  1583. nullpo_retr(0, sd);
  1584. fd = sd->fd;
  1585. if (!session_isActive(fd)) //Sasuke-
  1586. return 0;
  1587. WFIFOHEAD(fd,packet_len(0xa0));
  1588. if(fail) {
  1589. WFIFOW(fd,0)=0xa0;
  1590. WFIFOW(fd,2)=n+2;
  1591. WFIFOW(fd,4)=amount;
  1592. WFIFOW(fd,6)=0;
  1593. WFIFOB(fd,8)=0;
  1594. WFIFOB(fd,9)=0;
  1595. WFIFOB(fd,10)=0;
  1596. WFIFOW(fd,11)=0;
  1597. WFIFOW(fd,13)=0;
  1598. WFIFOW(fd,15)=0;
  1599. WFIFOW(fd,17)=0;
  1600. WFIFOW(fd,19)=0;
  1601. WFIFOB(fd,21)=0;
  1602. WFIFOB(fd,22)=fail;
  1603. } else {
  1604. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1605. return 1;
  1606. WFIFOW(fd,0)=0xa0;
  1607. WFIFOW(fd,2)=n+2;
  1608. WFIFOW(fd,4)=amount;
  1609. if (sd->inventory_data[n]->view_id > 0)
  1610. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1611. else
  1612. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1613. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1614. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1615. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1616. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1617. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1618. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1619. WFIFOB(fd,22)=fail;
  1620. }
  1621. WFIFOSET(fd,packet_len(0xa0));
  1622. return 0;
  1623. }
  1624. /*==========================================
  1625. *
  1626. *------------------------------------------*/
  1627. int clif_delitem(struct map_session_data *sd,int n,int amount)
  1628. {
  1629. int fd;
  1630. nullpo_retr(0, sd);
  1631. fd=sd->fd;
  1632. WFIFOHEAD(fd, packet_len(0xaf));
  1633. WFIFOW(fd,0)=0xaf;
  1634. WFIFOW(fd,2)=n+2;
  1635. WFIFOW(fd,4)=amount;
  1636. WFIFOSET(fd,packet_len(0xaf));
  1637. return 0;
  1638. }
  1639. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1640. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1641. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1642. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1643. {
  1644. if (id->view_id > 0)
  1645. WBUFW(buf,n)=id->view_id;
  1646. else
  1647. WBUFW(buf,n)=i->nameid;
  1648. WBUFB(buf,n+2)=itemtype(id->type);
  1649. WBUFB(buf,n+3)=i->identify;
  1650. if (equip >= 0) { //Equippable item
  1651. WBUFW(buf,n+4)=equip;
  1652. WBUFW(buf,n+6)=i->equip;
  1653. WBUFB(buf,n+8)=i->attribute;
  1654. WBUFB(buf,n+9)=i->refine;
  1655. } else { //Stackable item.
  1656. WBUFW(buf,n+4)=i->amount;
  1657. if (equip == -2 && id->equip == EQP_AMMO)
  1658. WBUFW(buf,n+6)=EQP_AMMO;
  1659. else
  1660. WBUFW(buf,n+6)=0;
  1661. }
  1662. }
  1663. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1664. void clif_inventorylist(struct map_session_data *sd)
  1665. {
  1666. int i,n,ne,fd = sd->fd,arrow=-1;
  1667. unsigned char *buf;
  1668. unsigned char bufe[MAX_INVENTORY*20+4];
  1669. #if PACKETVER < 5
  1670. const int s = 10; //Entry size.
  1671. #else
  1672. const int s = 18;
  1673. #endif
  1674. WFIFOHEAD(fd, MAX_INVENTORY * s + 4);
  1675. buf = WFIFOP(fd,0);
  1676. for(i=0,n=0,ne=0;i<MAX_INVENTORY;i++){
  1677. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1678. continue;
  1679. if(!itemdb_isstackable2(sd->inventory_data[i]))
  1680. { //Non-stackable (Equippable)
  1681. WBUFW(bufe,ne*20+4)=i+2;
  1682. clif_item_sub(bufe, ne*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1683. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.inventory[i]);
  1684. ne++;
  1685. } else { //Stackable.
  1686. WBUFW(buf,n*s+4)=i+2;
  1687. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1688. if (sd->inventory_data[i]->equip == EQP_AMMO &&
  1689. sd->status.inventory[i].equip)
  1690. arrow=i;
  1691. #if PACKETVER >= 5
  1692. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1693. #endif
  1694. n++;
  1695. }
  1696. }
  1697. if (n) {
  1698. #if PACKETVER < 5
  1699. WBUFW(buf,0)=0xa3;
  1700. #else
  1701. WBUFW(buf,0)=0x1ee;
  1702. #endif
  1703. WBUFW(buf,2)=4+n*s;
  1704. WFIFOSET(fd,WFIFOW(fd,2));
  1705. }
  1706. if(arrow >= 0)
  1707. clif_arrowequip(sd,arrow);
  1708. if(ne){
  1709. WBUFW(bufe,0)=0xa4;
  1710. WBUFW(bufe,2)=4+ne*20;
  1711. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1712. }
  1713. }
  1714. //Required when items break/get-repaired. Only sends equippable item list.
  1715. void clif_equiplist(struct map_session_data *sd)
  1716. {
  1717. int i,n,fd = sd->fd;
  1718. unsigned char *buf;
  1719. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  1720. buf = WFIFOP(fd,0);
  1721. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1722. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1723. continue;
  1724. if(itemdb_isstackable2(sd->inventory_data[i]))
  1725. continue;
  1726. //Equippable
  1727. WBUFW(buf,n*20+4)=i+2;
  1728. clif_item_sub(buf, n*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1729. clif_addcards(WBUFP(buf, n*20+16), &sd->status.inventory[i]);
  1730. n++;
  1731. }
  1732. if (n) {
  1733. WBUFW(buf,0)=0xa4;
  1734. WBUFW(buf,2)=4+n*20;
  1735. WFIFOSET(fd,WFIFOW(fd,2));
  1736. }
  1737. }
  1738. void clif_storagelist(struct map_session_data* sd, struct storage_data* stor)
  1739. {
  1740. struct item_data *id;
  1741. int i,n,ne,fd=sd->fd;
  1742. unsigned char *buf;
  1743. unsigned char bufe[MAX_STORAGE*20+4];
  1744. #if PACKETVER < 5
  1745. const int s = 10; //Entry size.
  1746. #else
  1747. const int s = 18;
  1748. #endif
  1749. WFIFOHEAD(fd,MAX_STORAGE * s + 4);
  1750. buf = WFIFOP(fd,0);
  1751. for(i=0,n=0,ne=0;i<MAX_STORAGE;i++){
  1752. if(stor->items[i].nameid<=0)
  1753. continue;
  1754. id = itemdb_search(stor->items[i].nameid);
  1755. if(!itemdb_isstackable2(id))
  1756. { //Equippable
  1757. WBUFW(bufe,ne*20+4)=i+1;
  1758. clif_item_sub(bufe, ne*20+6, &stor->items[i], id, id->equip);
  1759. clif_addcards(WBUFP(bufe, ne*20+16), &stor->items[i]);
  1760. ne++;
  1761. } else { //Stackable
  1762. WBUFW(buf,n*s+4)=i+1;
  1763. clif_item_sub(buf, n*s+6, &stor->items[i], id,-1);
  1764. #if PACKETVER >= 5
  1765. clif_addcards(WBUFP(buf,n*s+14), &stor->items[i]);
  1766. #endif
  1767. n++;
  1768. }
  1769. }
  1770. if(n){
  1771. #if PACKETVER < 5
  1772. WBUFW(buf,0)=0xa5;
  1773. #else
  1774. WBUFW(buf,0)=0x1f0;
  1775. #endif
  1776. WBUFW(buf,2)=4+n*s;
  1777. WFIFOSET(fd,WFIFOW(fd,2));
  1778. }
  1779. if(ne){
  1780. WBUFW(bufe,0)=0xa6;
  1781. WBUFW(bufe,2)=4+ne*20;
  1782. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1783. }
  1784. }
  1785. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1786. void clif_guildstoragelist(struct map_session_data *sd,struct guild_storage *stor)
  1787. {
  1788. struct item_data *id;
  1789. int i,n,ne,fd=sd->fd;
  1790. unsigned char *buf;
  1791. unsigned char bufe[MAX_GUILD_STORAGE*20+4];
  1792. #if PACKETVER < 5
  1793. const int s = 10; //Entry size.
  1794. #else
  1795. const int s = 18;
  1796. #endif
  1797. WFIFOHEAD(fd,MAX_GUILD_STORAGE * s + 4);
  1798. buf = WFIFOP(fd,0);
  1799. for(i=0,n=0,ne=0;i<MAX_GUILD_STORAGE;i++){
  1800. if(stor->storage_[i].nameid<=0)
  1801. continue;
  1802. id = itemdb_search(stor->storage_[i].nameid);
  1803. if(!itemdb_isstackable2(id))
  1804. { //Equippable
  1805. WBUFW(bufe,ne*20+4)=i+1;
  1806. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  1807. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  1808. ne++;
  1809. } else { //Stackable
  1810. WBUFW(buf,n*s+4)=i+1;
  1811. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  1812. #if PACKETVER >= 5
  1813. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  1814. #endif
  1815. n++;
  1816. }
  1817. }
  1818. if(n){
  1819. #if PACKETVER < 5
  1820. WBUFW(buf,0)=0xa5;
  1821. #else
  1822. WBUFW(buf,0)=0x1f0;
  1823. #endif
  1824. WBUFW(buf,2)=4+n*s;
  1825. WFIFOSET(fd,WFIFOW(fd,2));
  1826. }
  1827. if(ne){
  1828. WBUFW(bufe,0)=0xa6;
  1829. WBUFW(bufe,2)=4+ne*20;
  1830. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1831. }
  1832. }
  1833. void clif_cartlist(struct map_session_data *sd)
  1834. {
  1835. struct item_data *id;
  1836. int i,n,ne,fd=sd->fd;
  1837. unsigned char *buf;
  1838. unsigned char bufe[MAX_CART*20+4];
  1839. #if PACKETVER < 5
  1840. const int s = 10; //Entry size.
  1841. #else
  1842. const int s = 18;
  1843. #endif
  1844. WFIFOHEAD(fd, MAX_CART * s + 4);
  1845. buf = WFIFOP(fd,0);
  1846. for(i=0,n=0,ne=0;i<MAX_CART;i++){
  1847. if(sd->status.cart[i].nameid<=0)
  1848. continue;
  1849. id = itemdb_search(sd->status.cart[i].nameid);
  1850. if(!itemdb_isstackable2(id))
  1851. { //Equippable
  1852. WBUFW(bufe,ne*20+4)=i+2;
  1853. clif_item_sub(bufe, ne*20+6, &sd->status.cart[i], id, id->equip);
  1854. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.cart[i]);
  1855. ne++;
  1856. } else { //Stackable
  1857. WBUFW(buf,n*s+4)=i+2;
  1858. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  1859. #if PACKETVER >= 5
  1860. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  1861. #endif
  1862. n++;
  1863. }
  1864. }
  1865. if(n){
  1866. #if PACKETVER < 5
  1867. WBUFW(buf,0)=0x123;
  1868. #else
  1869. WBUFW(buf,0)=0x1ef;
  1870. #endif
  1871. WBUFW(buf,2)=4+n*s;
  1872. WFIFOSET(fd,WFIFOW(fd,2));
  1873. }
  1874. if(ne){
  1875. WBUFW(bufe,0)=0x122;
  1876. WBUFW(bufe,2)=4+ne*20;
  1877. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1878. }
  1879. return;
  1880. }
  1881. /// Client behaviour:
  1882. /// Closes the cart storage and removes all it's items from memory.
  1883. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  1884. void clif_clearcart(int fd)
  1885. {
  1886. WFIFOHEAD(fd, packet_len(0x12b));
  1887. WFIFOW(fd,0) = 0x12b;
  1888. }
  1889. // Guild XY locators [Valaris]
  1890. int clif_guild_xy(struct map_session_data *sd)
  1891. {
  1892. unsigned char buf[10];
  1893. nullpo_retr(0, sd);
  1894. WBUFW(buf,0)=0x1eb;
  1895. WBUFL(buf,2)=sd->status.account_id;
  1896. WBUFW(buf,6)=sd->bl.x;
  1897. WBUFW(buf,8)=sd->bl.y;
  1898. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  1899. return 0;
  1900. }
  1901. /*==========================================
  1902. * Sends x/y dot to a single fd. [Skotlex]
  1903. *------------------------------------------*/
  1904. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  1905. {
  1906. if( sd->state.bg_id )
  1907. return 0;
  1908. WFIFOHEAD(fd,packet_len(0x1eb));
  1909. WFIFOW(fd,0)=0x1eb;
  1910. WFIFOL(fd,2)=sd->status.account_id;
  1911. WFIFOW(fd,6)=sd->bl.x;
  1912. WFIFOW(fd,8)=sd->bl.y;
  1913. WFIFOSET(fd,packet_len(0x1eb));
  1914. return 0;
  1915. }
  1916. // Guild XY locators [Valaris]
  1917. int clif_guild_xy_remove(struct map_session_data *sd)
  1918. {
  1919. unsigned char buf[10];
  1920. nullpo_retr(0, sd);
  1921. WBUFW(buf,0)=0x1eb;
  1922. WBUFL(buf,2)=sd->status.account_id;
  1923. WBUFW(buf,6)=-1;
  1924. WBUFW(buf,8)=-1;
  1925. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  1926. return 0;
  1927. }
  1928. /*==========================================
  1929. * ステータスを送りつける
  1930. * 表示専用数字はこの中で計算して送る
  1931. *------------------------------------------*/
  1932. int clif_updatestatus(struct map_session_data *sd,int type)
  1933. {
  1934. int fd,len=8;
  1935. nullpo_retr(0, sd);
  1936. fd=sd->fd;
  1937. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  1938. return 0;
  1939. WFIFOHEAD(fd, 14);
  1940. WFIFOW(fd,0)=0xb0;
  1941. WFIFOW(fd,2)=type;
  1942. switch(type){
  1943. // 00b0
  1944. case SP_WEIGHT:
  1945. pc_updateweightstatus(sd);
  1946. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  1947. WFIFOW(fd,2)=type;
  1948. WFIFOL(fd,4)=sd->weight;
  1949. break;
  1950. case SP_MAXWEIGHT:
  1951. WFIFOL(fd,4)=sd->max_weight;
  1952. break;
  1953. case SP_SPEED:
  1954. WFIFOL(fd,4)=sd->battle_status.speed;
  1955. break;
  1956. case SP_BASELEVEL:
  1957. WFIFOL(fd,4)=sd->status.base_level;
  1958. break;
  1959. case SP_JOBLEVEL:
  1960. WFIFOL(fd,4)=sd->status.job_level;
  1961. break;
  1962. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  1963. WFIFOL(fd,4)=sd->status.karma;
  1964. break;
  1965. case SP_MANNER:
  1966. WFIFOL(fd,4)=sd->status.manner;
  1967. break;
  1968. case SP_STATUSPOINT:
  1969. WFIFOL(fd,4)=sd->status.status_point;
  1970. break;
  1971. case SP_SKILLPOINT:
  1972. WFIFOL(fd,4)=sd->status.skill_point;
  1973. break;
  1974. case SP_HIT:
  1975. WFIFOL(fd,4)=sd->battle_status.hit;
  1976. break;
  1977. case SP_FLEE1:
  1978. WFIFOL(fd,4)=sd->battle_status.flee;
  1979. break;
  1980. case SP_FLEE2:
  1981. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  1982. break;
  1983. case SP_MAXHP:
  1984. WFIFOL(fd,4)=sd->battle_status.max_hp;
  1985. break;
  1986. case SP_MAXSP:
  1987. WFIFOL(fd,4)=sd->battle_status.max_sp;
  1988. break;
  1989. case SP_HP:
  1990. WFIFOL(fd,4)=sd->battle_status.hp;
  1991. if( battle_config.disp_hpmeter )
  1992. clif_hpmeter(sd);
  1993. if( !battle_config.party_hp_mode && sd->status.party_id )
  1994. clif_party_hp(sd);
  1995. if( sd->state.bg_id )
  1996. clif_bg_hp(sd);
  1997. break;
  1998. case SP_SP:
  1999. WFIFOL(fd,4)=sd->battle_status.sp;
  2000. break;
  2001. case SP_ASPD:
  2002. WFIFOL(fd,4)=sd->battle_status.amotion;
  2003. break;
  2004. case SP_ATK1:
  2005. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw.atk;
  2006. break;
  2007. case SP_DEF1:
  2008. WFIFOL(fd,4)=sd->battle_status.def;
  2009. break;
  2010. case SP_MDEF1:
  2011. WFIFOL(fd,4)=sd->battle_status.mdef;
  2012. break;
  2013. case SP_ATK2:
  2014. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2;
  2015. break;
  2016. case SP_DEF2:
  2017. WFIFOL(fd,4)=sd->battle_status.def2;
  2018. break;
  2019. case SP_MDEF2:
  2020. //negative check (in case you have something like Berserk active)
  2021. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2022. if (len < 0) len = 0;
  2023. WFIFOL(fd,4)= len;
  2024. len = 8;
  2025. break;
  2026. case SP_CRITICAL:
  2027. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2028. break;
  2029. case SP_MATK1:
  2030. WFIFOL(fd,4)=sd->battle_status.matk_max;
  2031. break;
  2032. case SP_MATK2:
  2033. WFIFOL(fd,4)=sd->battle_status.matk_min;
  2034. break;
  2035. case SP_ZENY:
  2036. WFIFOW(fd,0)=0xb1;
  2037. WFIFOL(fd,4)=sd->status.zeny;
  2038. break;
  2039. case SP_BASEEXP:
  2040. WFIFOW(fd,0)=0xb1;
  2041. WFIFOL(fd,4)=sd->status.base_exp;
  2042. break;
  2043. case SP_JOBEXP:
  2044. WFIFOW(fd,0)=0xb1;
  2045. WFIFOL(fd,4)=sd->status.job_exp;
  2046. break;
  2047. case SP_NEXTBASEEXP:
  2048. WFIFOW(fd,0)=0xb1;
  2049. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2050. break;
  2051. case SP_NEXTJOBEXP:
  2052. WFIFOW(fd,0)=0xb1;
  2053. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2054. break;
  2055. // 00be 終了
  2056. case SP_USTR:
  2057. case SP_UAGI:
  2058. case SP_UVIT:
  2059. case SP_UINT:
  2060. case SP_UDEX:
  2061. case SP_ULUK:
  2062. WFIFOW(fd,0)=0xbe;
  2063. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2064. len=5;
  2065. break;
  2066. // 013a 終了
  2067. case SP_ATTACKRANGE:
  2068. WFIFOW(fd,0)=0x13a;
  2069. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2070. len=4;
  2071. break;
  2072. // 0141 終了
  2073. case SP_STR:
  2074. WFIFOW(fd,0)=0x141;
  2075. WFIFOL(fd,2)=type;
  2076. WFIFOL(fd,6)=sd->status.str;
  2077. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2078. len=14;
  2079. break;
  2080. case SP_AGI:
  2081. WFIFOW(fd,0)=0x141;
  2082. WFIFOL(fd,2)=type;
  2083. WFIFOL(fd,6)=sd->status.agi;
  2084. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2085. len=14;
  2086. break;
  2087. case SP_VIT:
  2088. WFIFOW(fd,0)=0x141;
  2089. WFIFOL(fd,2)=type;
  2090. WFIFOL(fd,6)=sd->status.vit;
  2091. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2092. len=14;
  2093. break;
  2094. case SP_INT:
  2095. WFIFOW(fd,0)=0x141;
  2096. WFIFOL(fd,2)=type;
  2097. WFIFOL(fd,6)=sd->status.int_;
  2098. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2099. len=14;
  2100. break;
  2101. case SP_DEX:
  2102. WFIFOW(fd,0)=0x141;
  2103. WFIFOL(fd,2)=type;
  2104. WFIFOL(fd,6)=sd->status.dex;
  2105. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2106. len=14;
  2107. break;
  2108. case SP_LUK:
  2109. WFIFOW(fd,0)=0x141;
  2110. WFIFOL(fd,2)=type;
  2111. WFIFOL(fd,6)=sd->status.luk;
  2112. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2113. len=14;
  2114. break;
  2115. case SP_CARTINFO:
  2116. WFIFOW(fd,0)=0x121;
  2117. WFIFOW(fd,2)=sd->cart_num;
  2118. WFIFOW(fd,4)=MAX_CART;
  2119. WFIFOL(fd,6)=sd->cart_weight;
  2120. WFIFOL(fd,10)=battle_config.max_cart_weight;
  2121. len=14;
  2122. break;
  2123. default:
  2124. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2125. return 1;
  2126. }
  2127. WFIFOSET(fd,len);
  2128. return 0;
  2129. }
  2130. int clif_changestatus(struct block_list *bl,int type,int val)
  2131. {
  2132. unsigned char buf[12];
  2133. struct map_session_data *sd = NULL;
  2134. nullpo_retr(0, bl);
  2135. if(bl->type == BL_PC)
  2136. sd = (struct map_session_data *)bl;
  2137. if(sd){
  2138. WBUFW(buf,0)=0x1ab;
  2139. WBUFL(buf,2)=bl->id;
  2140. WBUFW(buf,6)=type;
  2141. switch(type){
  2142. case SP_MANNER:
  2143. WBUFL(buf,8)=val;
  2144. break;
  2145. default:
  2146. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2147. return 1;
  2148. }
  2149. clif_send(buf,packet_len(0x1ab),bl,AREA_WOS);
  2150. }
  2151. return 0;
  2152. }
  2153. /*==========================================
  2154. *
  2155. *------------------------------------------*/
  2156. void clif_changelook(struct block_list *bl,int type,int val)
  2157. {
  2158. unsigned char buf[16];
  2159. struct map_session_data* sd = NULL;
  2160. struct status_change* sc;
  2161. struct view_data* vd;
  2162. enum send_target target = AREA;
  2163. nullpo_retv(bl);
  2164. sd = BL_CAST(BL_PC, bl);
  2165. sc = status_get_sc(bl);
  2166. vd = status_get_viewdata(bl);
  2167. //nullpo_ret(vd);
  2168. if( vd ) //temp hack to let Warp Portal change appearance
  2169. switch(type)
  2170. {
  2171. case LOOK_WEAPON:
  2172. if (sd)
  2173. {
  2174. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2175. val = vd->weapon;
  2176. }
  2177. else vd->weapon = val;
  2178. break;
  2179. case LOOK_SHIELD:
  2180. if (sd)
  2181. {
  2182. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2183. val = vd->shield;
  2184. }
  2185. else vd->shield = val;
  2186. break;
  2187. case LOOK_BASE:
  2188. vd->class_ = val;
  2189. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2190. vd->weapon = vd->shield = 0;
  2191. if (vd->cloth_color && (
  2192. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2193. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2194. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2195. ))
  2196. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2197. break;
  2198. case LOOK_HAIR:
  2199. vd->hair_style = val;
  2200. break;
  2201. case LOOK_HEAD_BOTTOM:
  2202. vd->head_bottom = val;
  2203. break;
  2204. case LOOK_HEAD_TOP:
  2205. vd->head_top = val;
  2206. break;
  2207. case LOOK_HEAD_MID:
  2208. vd->head_mid = val;
  2209. break;
  2210. case LOOK_HAIR_COLOR:
  2211. vd->hair_color = val;
  2212. break;
  2213. case LOOK_CLOTHES_COLOR:
  2214. if (val && (
  2215. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2216. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2217. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2218. ))
  2219. val = 0;
  2220. vd->cloth_color = val;
  2221. break;
  2222. case LOOK_SHOES:
  2223. #if PACKETVER > 3
  2224. if (sd) {
  2225. int n;
  2226. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2227. if(sd->inventory_data[n]->view_id > 0)
  2228. val = sd->inventory_data[n]->view_id;
  2229. else
  2230. val = sd->status.inventory[n].nameid;
  2231. }
  2232. val = 0;
  2233. }
  2234. #endif
  2235. //Shoes? No packet uses this....
  2236. break;
  2237. }
  2238. // prevent leaking the presence of GM-hidden objects
  2239. if( sc && sc->option&OPTION_INVISIBLE )
  2240. target = SELF;
  2241. #if PACKETVER < 4
  2242. WBUFW(buf,0)=0xc3;
  2243. WBUFL(buf,2)=bl->id;
  2244. WBUFB(buf,6)=type;
  2245. WBUFB(buf,7)=val;
  2246. clif_send(buf,packet_len(0xc3),bl,target);
  2247. #else
  2248. WBUFW(buf,0)=0x1d7;
  2249. WBUFL(buf,2)=bl->id;
  2250. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2251. WBUFB(buf,6)=LOOK_WEAPON;
  2252. WBUFW(buf,7)=vd->weapon;
  2253. WBUFW(buf,9)=vd->shield;
  2254. } else {
  2255. WBUFB(buf,6)=type;
  2256. WBUFW(buf,7)=val;
  2257. WBUFW(buf,9)=0;
  2258. }
  2259. clif_send(buf,packet_len(0x1d7),bl,target);
  2260. #endif
  2261. }
  2262. //Sends a change-base-look packet required for traps as they are triggered.
  2263. void clif_changetraplook(struct block_list *bl,int val)
  2264. {
  2265. unsigned char buf[32];
  2266. #if PACKETVER < 4
  2267. WBUFW(buf,0)=0xc3;
  2268. WBUFL(buf,2)=bl->id;
  2269. WBUFB(buf,6)=LOOK_BASE;
  2270. WBUFB(buf,7)=val;
  2271. clif_send(buf,packet_len(0xc3),bl,AREA);
  2272. #else
  2273. WBUFW(buf,0)=0x1d7;
  2274. WBUFL(buf,2)=bl->id;
  2275. WBUFB(buf,6)=LOOK_BASE;
  2276. WBUFW(buf,7)=val;
  2277. WBUFW(buf,9)=0;
  2278. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2279. #endif
  2280. }
  2281. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2282. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2283. {
  2284. unsigned char buf[32];
  2285. #if PACKETVER < 4
  2286. WBUFW(buf,0)=0xc3;
  2287. WBUFL(buf,2)=id;
  2288. WBUFB(buf,6)=type;
  2289. WBUFB(buf,7)=val;
  2290. clif_send(buf,packet_len(0xc3),bl,target);
  2291. #else
  2292. WBUFW(buf,0)=0x1d7;
  2293. WBUFL(buf,2)=id;
  2294. WBUFB(buf,6)=type;
  2295. WBUFW(buf,7)=val;
  2296. WBUFW(buf,9)=0;
  2297. clif_send(buf,packet_len(0x1d7),bl,target);
  2298. #endif
  2299. return;
  2300. }
  2301. /*==========================================
  2302. *
  2303. *------------------------------------------*/
  2304. int clif_initialstatus(struct map_session_data *sd)
  2305. {
  2306. int fd;
  2307. unsigned char *buf;
  2308. nullpo_retr(0, sd);
  2309. fd=sd->fd;
  2310. WFIFOHEAD(fd,packet_len(0xbd));
  2311. buf=WFIFOP(fd,0);
  2312. WBUFW(buf,0)=0xbd;
  2313. WBUFW(buf,2)=min(sd->status.status_point, SHRT_MAX);
  2314. WBUFB(buf,4)=min(sd->status.str, UCHAR_MAX);
  2315. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2316. WBUFB(buf,6)=min(sd->status.agi, UCHAR_MAX);
  2317. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2318. WBUFB(buf,8)=min(sd->status.vit, UCHAR_MAX);
  2319. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2320. WBUFB(buf,10)=min(sd->status.int_, UCHAR_MAX);
  2321. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2322. WBUFB(buf,12)=min(sd->status.dex, UCHAR_MAX);
  2323. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2324. WBUFB(buf,14)=min(sd->status.luk, UCHAR_MAX);
  2325. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2326. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw.atk;
  2327. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2; //atk bonus
  2328. WBUFW(buf,20) = sd->battle_status.matk_max;
  2329. WBUFW(buf,22) = sd->battle_status.matk_min;
  2330. WBUFW(buf,24) = sd->battle_status.def; // def
  2331. WBUFW(buf,26) = sd->battle_status.def2;
  2332. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2333. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2334. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2335. WBUFW(buf,30) = fd;
  2336. fd = sd->fd;
  2337. WBUFW(buf,32) = sd->battle_status.hit;
  2338. WBUFW(buf,34) = sd->battle_status.flee;
  2339. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2340. WBUFW(buf,38) = sd->battle_status.cri/10;
  2341. WBUFW(buf,40) = sd->status.karma;
  2342. WBUFW(buf,42) = sd->status.manner;
  2343. WFIFOSET(fd,packet_len(0xbd));
  2344. clif_updatestatus(sd,SP_STR);
  2345. clif_updatestatus(sd,SP_AGI);
  2346. clif_updatestatus(sd,SP_VIT);
  2347. clif_updatestatus(sd,SP_INT);
  2348. clif_updatestatus(sd,SP_DEX);
  2349. clif_updatestatus(sd,SP_LUK);
  2350. clif_updatestatus(sd,SP_ATTACKRANGE);
  2351. clif_updatestatus(sd,SP_ASPD);
  2352. return 0;
  2353. }
  2354. /*==========================================
  2355. *矢装備
  2356. *------------------------------------------*/
  2357. int clif_arrowequip(struct map_session_data *sd,int val)
  2358. {
  2359. int fd;
  2360. nullpo_retr(0, sd);
  2361. pc_stop_attack(sd); // [Valaris]
  2362. fd=sd->fd;
  2363. WFIFOHEAD(fd, packet_len(0x013c));
  2364. WFIFOW(fd,0)=0x013c;
  2365. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2366. WFIFOSET(fd,packet_len(0x013c));
  2367. return 0;
  2368. }
  2369. /// Ammunition action message.
  2370. /// type=0 : MsgStringTable[242]="Please equip the proper ammunition first."
  2371. /// type=1 : MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2372. /// type=2 : MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2373. /// type=3 : assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2374. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2375. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2376. int clif_arrow_fail(struct map_session_data *sd,int type)
  2377. {
  2378. int fd;
  2379. nullpo_retr(0, sd);
  2380. fd=sd->fd;
  2381. WFIFOHEAD(fd, packet_len(0x013b));
  2382. WFIFOW(fd,0)=0x013b;
  2383. WFIFOW(fd,2)=type;
  2384. WFIFOSET(fd,packet_len(0x013b));
  2385. return 0;
  2386. }
  2387. /*==========================================
  2388. * 作成可能 矢リスト送信
  2389. *------------------------------------------*/
  2390. int clif_arrow_create_list(struct map_session_data *sd)
  2391. {
  2392. int i, c, j;
  2393. int fd;
  2394. nullpo_retr(0, sd);
  2395. fd = sd->fd;
  2396. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2397. WFIFOW(fd,0) = 0x1ad;
  2398. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2399. if (skill_arrow_db[i].nameid > 0 &&
  2400. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2401. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2402. {
  2403. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2404. WFIFOW(fd,c*2+4) = j;
  2405. else
  2406. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2407. c++;
  2408. }
  2409. }
  2410. WFIFOW(fd,2) = c*2+4;
  2411. WFIFOSET(fd, WFIFOW(fd,2));
  2412. if (c > 0) {
  2413. sd->menuskill_id = AC_MAKINGARROW;
  2414. sd->menuskill_val = c;
  2415. }
  2416. return 0;
  2417. }
  2418. /*==========================================
  2419. *
  2420. *------------------------------------------*/
  2421. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2422. {
  2423. int fd;
  2424. nullpo_retr(0, sd);
  2425. fd=sd->fd;
  2426. WFIFOHEAD(fd,packet_len(0xbc));
  2427. WFIFOW(fd,0)=0xbc;
  2428. WFIFOW(fd,2)=type;
  2429. WFIFOB(fd,4)=ok;
  2430. WFIFOB(fd,5)=cap_value(val,0,UCHAR_MAX);
  2431. WFIFOSET(fd,packet_len(0xbc));
  2432. return 0;
  2433. }
  2434. /*==========================================
  2435. *
  2436. *------------------------------------------*/
  2437. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2438. {
  2439. int fd;
  2440. nullpo_retr(0, sd);
  2441. fd=sd->fd;
  2442. WFIFOHEAD(fd,packet_len(0xaa));
  2443. WFIFOW(fd,0)=0xaa;
  2444. WFIFOW(fd,2)=n+2;
  2445. WFIFOW(fd,4)=pos;
  2446. WFIFOB(fd,6)=ok;
  2447. WFIFOSET(fd,packet_len(0xaa));
  2448. return 0;
  2449. }
  2450. /*==========================================
  2451. *
  2452. *------------------------------------------*/
  2453. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2454. {
  2455. int fd;
  2456. nullpo_retr(0, sd);
  2457. fd=sd->fd;
  2458. WFIFOHEAD(fd,packet_len(0xac));
  2459. WFIFOW(fd,0)=0xac;
  2460. WFIFOW(fd,2)=n+2;
  2461. WFIFOW(fd,4)=pos;
  2462. WFIFOB(fd,6)=ok;
  2463. WFIFOSET(fd,packet_len(0xac));
  2464. return 0;
  2465. }
  2466. /*==========================================
  2467. *
  2468. *------------------------------------------*/
  2469. int clif_misceffect(struct block_list* bl,int type)
  2470. {
  2471. unsigned char buf[32];
  2472. nullpo_retr(0, bl);
  2473. WBUFW(buf,0) = 0x19b;
  2474. WBUFL(buf,2) = bl->id;
  2475. WBUFL(buf,6) = type;
  2476. clif_send(buf,packet_len(0x19b),bl,AREA);
  2477. return 0;
  2478. }
  2479. int clif_misceffect2(struct block_list *bl, int type)
  2480. {
  2481. unsigned char buf[24];
  2482. nullpo_retr(0, bl);
  2483. memset(buf, 0, packet_len(0x1f3));
  2484. WBUFW(buf,0) = 0x1f3;
  2485. WBUFL(buf,2) = bl->id;
  2486. WBUFL(buf,6) = type;
  2487. clif_send(buf, packet_len(0x1f3), bl, AREA);
  2488. return 0;
  2489. }
  2490. /*==========================================
  2491. * 表示オプション変更
  2492. *------------------------------------------*/
  2493. int clif_changeoption(struct block_list* bl)
  2494. {
  2495. unsigned char buf[32];
  2496. struct status_change *sc;
  2497. nullpo_retr(0, bl);
  2498. sc = status_get_sc(bl);
  2499. if (!sc) return 0; //How can an option change if there's no sc?
  2500. #if PACKETVER >= 7
  2501. WBUFW(buf,0) = 0x229;
  2502. WBUFL(buf,2) = bl->id;
  2503. WBUFW(buf,6) = sc->opt1;
  2504. WBUFW(buf,8) = sc->opt2;
  2505. WBUFL(buf,10) = sc->option;
  2506. WBUFB(buf,14) = 0; // PK???
  2507. if(disguised(bl)) {
  2508. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2509. WBUFL(buf,2) = -bl->id;
  2510. clif_send(buf,packet_len(0x229),bl,SELF);
  2511. WBUFL(buf,2) = bl->id;
  2512. WBUFL(buf,10) = OPTION_INVISIBLE;
  2513. clif_send(buf,packet_len(0x229),bl,SELF);
  2514. } else
  2515. clif_send(buf,packet_len(0x229),bl,AREA);
  2516. #else
  2517. WBUFW(buf,0) = 0x119;
  2518. WBUFL(buf,2) = bl->id;
  2519. WBUFW(buf,6) = sc->opt1;
  2520. WBUFW(buf,8) = sc->opt2;
  2521. WBUFW(buf,10) = sc->option;
  2522. WBUFB(buf,12) = 0; // ??
  2523. if(disguised(bl)) {
  2524. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2525. WBUFL(buf,2) = -bl->id;
  2526. clif_send(buf,packet_len(0x119),bl,SELF);
  2527. WBUFL(buf,2) = bl->id;
  2528. WBUFW(buf,10) = OPTION_INVISIBLE;
  2529. clif_send(buf,packet_len(0x119),bl,SELF);
  2530. } else
  2531. clif_send(buf,packet_len(0x119),bl,AREA);
  2532. #endif
  2533. return 0;
  2534. }
  2535. int clif_changeoption2(struct block_list* bl)
  2536. {
  2537. unsigned char buf[20];
  2538. struct status_change *sc;
  2539. sc = status_get_sc(bl);
  2540. if (!sc) return 0; //How can an option change if there's no sc?
  2541. WBUFW(buf,0) = 0x28a;
  2542. WBUFL(buf,2) = bl->id;
  2543. WBUFL(buf,6) = sc->option;
  2544. WBUFL(buf,10) = clif_setlevel(status_get_lv(bl));
  2545. WBUFL(buf,14) = sc->opt3;
  2546. if(disguised(bl)) {
  2547. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  2548. WBUFL(buf,2) = -bl->id;
  2549. clif_send(buf,packet_len(0x28a),bl,SELF);
  2550. WBUFL(buf,2) = bl->id;
  2551. WBUFL(buf,6) = OPTION_INVISIBLE;
  2552. clif_send(buf,packet_len(0x28a),bl,SELF);
  2553. } else
  2554. clif_send(buf,packet_len(0x28a),bl,AREA);
  2555. return 0;
  2556. }
  2557. /*==========================================
  2558. *
  2559. *------------------------------------------*/
  2560. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2561. {
  2562. nullpo_retr(0, sd);
  2563. if(!ok) {
  2564. int fd=sd->fd;
  2565. WFIFOHEAD(fd,packet_len(0xa8));
  2566. WFIFOW(fd,0)=0xa8;
  2567. WFIFOW(fd,2)=index+2;
  2568. WFIFOW(fd,4)=amount;
  2569. WFIFOB(fd,6)=ok;
  2570. WFIFOSET(fd,packet_len(0xa8));
  2571. }
  2572. else {
  2573. #if PACKETVER < 3
  2574. int fd=sd->fd;
  2575. WFIFOHEAD(fd,packet_len(0xa8));
  2576. WFIFOW(fd,0)=0xa8;
  2577. WFIFOW(fd,2)=index+2;
  2578. WFIFOW(fd,4)=amount;
  2579. WFIFOB(fd,6)=ok;
  2580. WFIFOSET(fd,packet_len(0xa8));
  2581. #else
  2582. unsigned char buf[32];
  2583. WBUFW(buf,0)=0x1c8;
  2584. WBUFW(buf,2)=index+2;
  2585. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2586. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2587. else
  2588. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2589. WBUFL(buf,6)=sd->bl.id;
  2590. WBUFW(buf,10)=amount;
  2591. WBUFB(buf,12)=ok;
  2592. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2593. #endif
  2594. }
  2595. return 0;
  2596. }
  2597. /*==========================================
  2598. * Inform client whether chatroom creation was successful or not
  2599. * R 00d6 <fail>.B
  2600. *------------------------------------------*/
  2601. void clif_createchat(struct map_session_data* sd, int fail)
  2602. {
  2603. int fd;
  2604. nullpo_retv(sd);
  2605. fd = sd->fd;
  2606. WFIFOHEAD(fd,packet_len(0xd6));
  2607. WFIFOW(fd,0) = 0xd6;
  2608. WFIFOB(fd,2) = fail;
  2609. WFIFOSET(fd,packet_len(0xd6));
  2610. }
  2611. /*==========================================
  2612. * Display a chat above the owner
  2613. * R 00d7 <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <type>.B <title>.?B
  2614. *------------------------------------------*/
  2615. int clif_dispchat(struct chat_data* cd, int fd)
  2616. {
  2617. unsigned char buf[128];
  2618. uint8 type;
  2619. if( cd == NULL || cd->owner == NULL )
  2620. return 1;
  2621. // type - 0: private, 1: public, 2: npc, 3: non-clickable
  2622. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  2623. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  2624. : 1;
  2625. WBUFW(buf, 0) = 0xd7;
  2626. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2627. WBUFL(buf, 4) = cd->owner->id;
  2628. WBUFL(buf, 8) = cd->bl.id;
  2629. WBUFW(buf,12) = cd->limit;
  2630. WBUFW(buf,14) = cd->users;
  2631. WBUFB(buf,16) = type;
  2632. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2633. if( fd ) {
  2634. WFIFOHEAD(fd,WBUFW(buf,2));
  2635. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2636. WFIFOSET(fd,WBUFW(buf,2));
  2637. } else {
  2638. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  2639. }
  2640. return 0;
  2641. }
  2642. /*==========================================
  2643. * Chatroom properties adjustment
  2644. * R 00df <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <pub>.B <title>.?B
  2645. *------------------------------------------*/
  2646. int clif_changechatstatus(struct chat_data* cd)
  2647. {
  2648. unsigned char buf[128];
  2649. if( cd == NULL || cd->usersd[0] == NULL )
  2650. return 1;
  2651. WBUFW(buf, 0) = 0xdf;
  2652. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2653. WBUFL(buf, 4) = cd->usersd[0]->bl.id;
  2654. WBUFL(buf, 8) = cd->bl.id;
  2655. WBUFW(buf,12) = cd->limit;
  2656. WBUFW(buf,14) = cd->users;
  2657. WBUFB(buf,16) = cd->pub;
  2658. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2659. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2660. return 0;
  2661. }
  2662. /*==========================================
  2663. *
  2664. *------------------------------------------*/
  2665. int clif_clearchat(struct chat_data *cd,int fd)
  2666. {
  2667. unsigned char buf[32];
  2668. nullpo_retr(0, cd);
  2669. WBUFW(buf,0) = 0xd8;
  2670. WBUFL(buf,2) = cd->bl.id;
  2671. if( fd ) {
  2672. WFIFOHEAD(fd,packet_len(0xd8));
  2673. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2674. WFIFOSET(fd,packet_len(0xd8));
  2675. } else {
  2676. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  2677. }
  2678. return 0;
  2679. }
  2680. /*==========================================
  2681. *
  2682. *------------------------------------------*/
  2683. int clif_joinchatfail(struct map_session_data *sd,int fail)
  2684. {
  2685. int fd;
  2686. nullpo_retr(0, sd);
  2687. fd = sd->fd;
  2688. WFIFOHEAD(fd,packet_len(0xda));
  2689. WFIFOW(fd,0) = 0xda;
  2690. WFIFOB(fd,2) = fail;
  2691. WFIFOSET(fd,packet_len(0xda));
  2692. return 0;
  2693. }
  2694. /*==========================================
  2695. *
  2696. *------------------------------------------*/
  2697. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2698. {
  2699. int fd;
  2700. int i;
  2701. nullpo_retr(0, sd);
  2702. nullpo_retr(0, cd);
  2703. fd = sd->fd;
  2704. if (!session_isActive(fd))
  2705. return 0;
  2706. WFIFOHEAD(fd, 8 + (28*cd->users));
  2707. WFIFOW(fd, 0) = 0xdb;
  2708. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2709. WFIFOL(fd, 4) = cd->bl.id;
  2710. for (i = 0; i < cd->users; i++) {
  2711. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  2712. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2713. }
  2714. WFIFOSET(fd, WFIFOW(fd, 2));
  2715. return 0;
  2716. }
  2717. /*==========================================
  2718. *
  2719. *------------------------------------------*/
  2720. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2721. {
  2722. unsigned char buf[32];
  2723. nullpo_retr(0, sd);
  2724. nullpo_retr(0, cd);
  2725. WBUFW(buf, 0) = 0x0dc;
  2726. WBUFW(buf, 2) = cd->users;
  2727. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2728. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  2729. return 0;
  2730. }
  2731. /*==========================================
  2732. * Announce the new owner
  2733. * R 00e1 <index>.l <nick>.24B
  2734. *------------------------------------------*/
  2735. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  2736. {
  2737. unsigned char buf[64];
  2738. nullpo_retv(sd);
  2739. nullpo_retv(cd);
  2740. //FIXME: this announces a swap between positions 0 and 1 (probably not what we want) [ultramage]
  2741. //FIXME: aegis sends obviously incorrect packets; need to figure out what to send to display it correctly :X
  2742. //TODO: is it just owner swap, or can it do general-purpose reordering?
  2743. WBUFW(buf, 0) = 0xe1;
  2744. WBUFL(buf, 2) = 1;
  2745. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2746. WBUFW(buf,30) = 0xe1;
  2747. WBUFL(buf,32) = 0;
  2748. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2749. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  2750. }
  2751. /*==========================================
  2752. * Notify about user leaving the chatroom
  2753. * R 00dd <index>.w <nick>.24B <flag>.B
  2754. *------------------------------------------*/
  2755. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  2756. {
  2757. unsigned char buf[32];
  2758. nullpo_retv(sd);
  2759. nullpo_retv(cd);
  2760. WBUFW(buf, 0) = 0xdd;
  2761. WBUFW(buf, 2) = cd->users-1;
  2762. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2763. WBUFB(buf,28) = flag; // 0: left, 1: was kicked
  2764. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  2765. }
  2766. /*==========================================
  2767. * Opens a trade request window from char 'name'
  2768. * R 00e5 <nick>.24B
  2769. * R 01f4 <nick>.24B <charid>.L <baselvl>.W
  2770. *------------------------------------------*/
  2771. void clif_traderequest(struct map_session_data* sd, const char* name)
  2772. {
  2773. int fd = sd->fd;
  2774. #if PACKETVER < 6
  2775. WFIFOHEAD(fd,packet_len(0xe5));
  2776. WFIFOW(fd,0) = 0xe5;
  2777. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2778. WFIFOSET(fd,packet_len(0xe5));
  2779. #else
  2780. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2781. if( !tsd ) return;
  2782. WFIFOHEAD(fd,packet_len(0x1f4));
  2783. WFIFOW(fd,0) = 0x1f4;
  2784. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2785. WFIFOL(fd,26) = tsd->status.char_id;
  2786. WFIFOW(fd,30) = clif_setlevel(tsd->status.base_level);
  2787. WFIFOSET(fd,packet_len(0x1f4));
  2788. #endif
  2789. }
  2790. /*==========================================
  2791. * Reply to a trade-request.
  2792. * R 00e7 <type>.B
  2793. * R 01f5 <type>.B <charid>.L <baselvl>.W
  2794. * Type:
  2795. * 0: Char is too far
  2796. * 1: Character does not exist
  2797. * 2: Trade failed
  2798. * 3: Accept
  2799. * 4: Cancel
  2800. *------------------------------------------*/
  2801. void clif_tradestart(struct map_session_data* sd, uint8 type)
  2802. {
  2803. int fd = sd->fd;
  2804. #if PACKETVER < 6
  2805. WFIFOHEAD(fd,packet_len(0xe7));
  2806. WFIFOW(fd,0) = 0xe7;
  2807. WFIFOB(fd,2) = type;
  2808. WFIFOSET(fd,packet_len(0xe7));
  2809. #else
  2810. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2811. if( !tsd ) return;
  2812. WFIFOHEAD(fd,packet_len(0x1f5));
  2813. WFIFOW(fd,0) = 0x1f5;
  2814. WFIFOB(fd,2) = type;
  2815. WFIFOL(fd,3) = tsd->status.char_id;
  2816. WFIFOW(fd,7) = clif_setlevel(tsd->status.base_level);
  2817. WFIFOSET(fd,packet_len(0x1f5));
  2818. #endif
  2819. }
  2820. /*==========================================
  2821. * 相手方からのアイテム追加
  2822. *------------------------------------------*/
  2823. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  2824. {
  2825. int fd;
  2826. nullpo_retv(sd);
  2827. nullpo_retv(tsd);
  2828. fd = tsd->fd;
  2829. WFIFOHEAD(fd,packet_len(0xe9));
  2830. WFIFOW(fd,0) = 0xe9;
  2831. WFIFOL(fd,2) = amount;
  2832. if( index == 0 )
  2833. {
  2834. WFIFOW(fd,6) = 0; // type id
  2835. WFIFOB(fd,8) = 0; //identify flag
  2836. WFIFOB(fd,9) = 0; // attribute
  2837. WFIFOB(fd,10)= 0; //refine
  2838. WFIFOW(fd,11)= 0; //card (4w)
  2839. WFIFOW(fd,13)= 0; //card (4w)
  2840. WFIFOW(fd,15)= 0; //card (4w)
  2841. WFIFOW(fd,17)= 0; //card (4w)
  2842. }
  2843. else
  2844. {
  2845. index -= 2; //index fix
  2846. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2847. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  2848. else
  2849. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  2850. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  2851. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  2852. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  2853. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  2854. }
  2855. WFIFOSET(fd,packet_len(0xe9));
  2856. }
  2857. /*==========================================
  2858. * アイテム追加成功/失敗
  2859. *------------------------------------------*/
  2860. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  2861. {
  2862. int fd;
  2863. nullpo_retv(sd);
  2864. fd = sd->fd;
  2865. WFIFOHEAD(fd,packet_len(0xea));
  2866. WFIFOW(fd,0) = 0xea;
  2867. WFIFOW(fd,2) = index;
  2868. WFIFOB(fd,4) = fail;
  2869. WFIFOSET(fd,packet_len(0xea));
  2870. }
  2871. /*==========================================
  2872. * 取り引きok押し
  2873. *------------------------------------------*/
  2874. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  2875. {
  2876. int fd;
  2877. nullpo_retv(sd);
  2878. fd = sd->fd;
  2879. WFIFOHEAD(fd,packet_len(0xec));
  2880. WFIFOW(fd,0) = 0xec;
  2881. WFIFOB(fd,2) = fail; // 0=you 1=the other person
  2882. WFIFOSET(fd,packet_len(0xec));
  2883. }
  2884. /*==========================================
  2885. * 取り引きがキャンセルされました
  2886. *------------------------------------------*/
  2887. void clif_tradecancelled(struct map_session_data* sd)
  2888. {
  2889. int fd;
  2890. nullpo_retv(sd);
  2891. fd = sd->fd;
  2892. WFIFOHEAD(fd,packet_len(0xee));
  2893. WFIFOW(fd,0) = 0xee;
  2894. WFIFOSET(fd,packet_len(0xee));
  2895. }
  2896. /*==========================================
  2897. * 取り引き完了
  2898. *------------------------------------------*/
  2899. void clif_tradecompleted(struct map_session_data* sd, int fail)
  2900. {
  2901. int fd;
  2902. nullpo_retv(sd);
  2903. fd = sd->fd;
  2904. WFIFOHEAD(fd,packet_len(0xf0));
  2905. WFIFOW(fd,0) = 0xf0;
  2906. WFIFOB(fd,2) = fail;
  2907. WFIFOSET(fd,packet_len(0xf0));
  2908. }
  2909. /*==========================================
  2910. * カプラ倉庫のアイテム数を更新
  2911. *------------------------------------------*/
  2912. void clif_updatestorageamount(struct map_session_data* sd, int amount)
  2913. {
  2914. int fd;
  2915. nullpo_retv(sd);
  2916. fd=sd->fd;
  2917. WFIFOHEAD(fd,packet_len(0xf2));
  2918. WFIFOW(fd,0) = 0xf2; // update storage amount
  2919. WFIFOW(fd,2) = amount; //items
  2920. WFIFOW(fd,4) = MAX_STORAGE; //items max
  2921. WFIFOSET(fd,packet_len(0xf2));
  2922. }
  2923. /*==========================================
  2924. * カプラ倉庫にアイテムを追加する
  2925. *------------------------------------------*/
  2926. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  2927. {
  2928. int view,fd;
  2929. nullpo_retv(sd);
  2930. nullpo_retv(i);
  2931. fd=sd->fd;
  2932. view = itemdb_viewid(i->nameid);
  2933. #if PACKETVER < 5
  2934. WFIFOHEAD(fd,packet_len(0xf4));
  2935. WFIFOW(fd, 0) = 0xf4; // Storage item added
  2936. WFIFOW(fd, 2) = index+1; // index
  2937. WFIFOL(fd, 4) = amount; // amount
  2938. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  2939. WFIFOB(fd,10) = i->identify; //identify flag
  2940. WFIFOB(fd,11) = i->attribute; // attribute
  2941. WFIFOB(fd,12) = i->refine; //refine
  2942. clif_addcards(WFIFOP(fd,13), i);
  2943. WFIFOSET(fd,packet_len(0xf4));
  2944. #else
  2945. WFIFOHEAD(fd,packet_len(0x1c4));
  2946. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  2947. WFIFOW(fd, 2) = index+1; // index
  2948. WFIFOL(fd, 4) = amount; // amount
  2949. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  2950. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  2951. WFIFOB(fd,11) = i->identify; //identify flag
  2952. WFIFOB(fd,12) = i->attribute; // attribute
  2953. WFIFOB(fd,13) = i->refine; //refine
  2954. clif_addcards(WFIFOP(fd,14), i);
  2955. WFIFOSET(fd,packet_len(0x1c4));
  2956. #endif
  2957. }
  2958. /*==========================================
  2959. *
  2960. *------------------------------------------*/
  2961. void clif_updateguildstorageamount(struct map_session_data* sd, int amount)
  2962. {
  2963. int fd;
  2964. nullpo_retv(sd);
  2965. fd=sd->fd;
  2966. WFIFOHEAD(fd,packet_len(0xf2));
  2967. WFIFOW(fd,0) = 0xf2; // update storage amount
  2968. WFIFOW(fd,2) = amount; //items
  2969. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  2970. WFIFOSET(fd,packet_len(0xf2));
  2971. }
  2972. /*==========================================
  2973. *
  2974. *------------------------------------------*/
  2975. void clif_guildstorageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  2976. {
  2977. int view,fd;
  2978. nullpo_retv(sd);
  2979. nullpo_retv(i);
  2980. fd=sd->fd;
  2981. view = itemdb_viewid(i->nameid);
  2982. WFIFOHEAD(fd,packet_len(0xf4));
  2983. WFIFOW(fd, 0) = 0xf4; // Storage item added
  2984. WFIFOW(fd, 2) = index+1; // index
  2985. WFIFOL(fd, 4) = amount; // amount
  2986. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  2987. WFIFOB(fd,10) = i->identify; //identify flag
  2988. WFIFOB(fd,11) = i->attribute; // attribute
  2989. WFIFOB(fd,12) = i->refine; //refine
  2990. clif_addcards(WFIFOP(fd,13), i);
  2991. WFIFOSET(fd,packet_len(0xf4));
  2992. }
  2993. /*==========================================
  2994. * カプラ倉庫からアイテムを取り去る
  2995. *------------------------------------------*/
  2996. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  2997. {
  2998. int fd;
  2999. nullpo_retv(sd);
  3000. fd=sd->fd;
  3001. WFIFOHEAD(fd,packet_len(0xf6));
  3002. WFIFOW(fd,0)=0xf6; // Storage item removed
  3003. WFIFOW(fd,2)=index+1;
  3004. WFIFOL(fd,4)=amount;
  3005. WFIFOSET(fd,packet_len(0xf6));
  3006. }
  3007. /*==========================================
  3008. * カプラ倉庫を閉じる
  3009. *------------------------------------------*/
  3010. void clif_storageclose(struct map_session_data* sd)
  3011. {
  3012. int fd;
  3013. nullpo_retv(sd);
  3014. fd=sd->fd;
  3015. WFIFOHEAD(fd,packet_len(0xf8));
  3016. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3017. WFIFOSET(fd,packet_len(0xf8));
  3018. }
  3019. /*==========================================
  3020. * PC表示
  3021. *------------------------------------------*/
  3022. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3023. {
  3024. int gmlvl;
  3025. struct block_list *d_bl;
  3026. int i;
  3027. if(dstsd->chatID)
  3028. {
  3029. struct chat_data *cd;
  3030. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  3031. if(cd && cd->usersd[0]==dstsd)
  3032. clif_dispchat(cd,sd->fd);
  3033. }
  3034. if(dstsd->vender_id)
  3035. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3036. if(dstsd->spiritball > 0)
  3037. clif_spiritball_single(sd->fd, dstsd);
  3038. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3039. (sd->state.bg_id && sd->state.bg_id == dstsd->state.bg_id) || //BattleGround
  3040. (battle_config.disp_hpmeter && (gmlvl = pc_isGM(sd)) >= battle_config.disp_hpmeter && gmlvl >= pc_isGM(dstsd)) )
  3041. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3042. // display link (sd - dstsd) to sd
  3043. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  3044. if( i < 5 ) clif_devotion(&sd->bl, sd);
  3045. // display links (dstsd - devotees) to sd
  3046. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  3047. if( i < 5 ) clif_devotion(&dstsd->bl, sd);
  3048. // display link (dstsd - crusader) to sd
  3049. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3050. clif_devotion(d_bl, sd);
  3051. }
  3052. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3053. {
  3054. uint8 buf[128];
  3055. struct unit_data *ud;
  3056. struct view_data *vd;
  3057. int len;
  3058. vd = status_get_viewdata(bl);
  3059. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3060. return;
  3061. ud = unit_bl2ud(bl);
  3062. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3063. clif_send(buf,len,&sd->bl,SELF);
  3064. if (vd->cloth_color)
  3065. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3066. switch (bl->type)
  3067. {
  3068. case BL_PC:
  3069. {
  3070. TBL_PC* tsd = (TBL_PC*)bl;
  3071. clif_getareachar_pc(sd, tsd);
  3072. if(tsd->state.size==2) // tiny/big players [Valaris]
  3073. clif_specialeffect_single(bl,423,sd->fd);
  3074. else if(tsd->state.size==1)
  3075. clif_specialeffect_single(bl,421,sd->fd);
  3076. if( tsd->state.user_font )
  3077. clif_font_single(sd->fd,tsd);
  3078. if( tsd->state.bg_id && map[tsd->bl.m].flag.battleground )
  3079. clif_sendbgemblem_single(sd->fd,tsd);
  3080. }
  3081. break;
  3082. case BL_MER: // Devotion Effects
  3083. if( ((TBL_MER*)bl)->devotion_flag )
  3084. clif_devotion(bl, sd);
  3085. break;
  3086. case BL_NPC:
  3087. {
  3088. TBL_NPC* nd = (TBL_NPC*)bl;
  3089. if( nd->chat_id )
  3090. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3091. if( nd->size == 2 )
  3092. clif_specialeffect_single(bl,423,sd->fd);
  3093. else if( nd->size == 1 )
  3094. clif_specialeffect_single(bl,421,sd->fd);
  3095. }
  3096. break;
  3097. case BL_MOB:
  3098. {
  3099. TBL_MOB* md = (TBL_MOB*)bl;
  3100. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3101. clif_specialeffect_single(bl,423,sd->fd);
  3102. else if(md->special_state.size==1)
  3103. clif_specialeffect_single(bl,421,sd->fd);
  3104. }
  3105. break;
  3106. case BL_PET:
  3107. if (vd->head_bottom)
  3108. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3109. break;
  3110. }
  3111. }
  3112. //Modifies the type of damage according to status changes [Skotlex]
  3113. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3114. #define clif_calc_delay(type,div,damage,delay) ((delay)==0&&(damage)>0?((div)>1?9:4):type)
  3115. /*==========================================
  3116. * Estimates walk delay based on the damage criteria. [Skotlex]
  3117. *------------------------------------------*/
  3118. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3119. {
  3120. if (type == 4 || type == 9 || damage <=0)
  3121. return 0;
  3122. if (bl->type == BL_PC) {
  3123. if (battle_config.pc_walk_delay_rate != 100)
  3124. delay = delay*battle_config.pc_walk_delay_rate/100;
  3125. } else
  3126. if (battle_config.walk_delay_rate != 100)
  3127. delay = delay*battle_config.walk_delay_rate/100;
  3128. if (div_ > 1) //Multi-hit skills mean higher delays.
  3129. delay += battle_config.multihit_delay*(div_-1);
  3130. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3131. }
  3132. /*==========================================
  3133. * Sends a 'damage' packet (src performs action on dst)
  3134. * R 008a <src ID>.l <dst ID>.l <server tick>.l <src speed>.l <dst speed>.l <param1>.w <param2>.w <type>.B <param3>.w
  3135. *
  3136. * type=00 damage [param1: total damage, param2: div, param3: assassin dual-wield damage]
  3137. * type=01 pick up item
  3138. * type=02 sit down
  3139. * type=03 stand up
  3140. * type=04 reflected/absorbed damage?
  3141. * type=08 double attack
  3142. * type=09 don't display flinch animation (endure)
  3143. * type=0a critical hit
  3144. * type=0b lucky dodge
  3145. *------------------------------------------*/
  3146. int clif_damage(struct block_list* src, struct block_list* dst, unsigned int tick, int sdelay, int ddelay, int damage, int div, int type, int damage2)
  3147. {
  3148. unsigned char buf[256];
  3149. struct status_change *sc;
  3150. nullpo_retr(0, src);
  3151. nullpo_retr(0, dst);
  3152. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3153. sc = status_get_sc(dst);
  3154. if(sc && sc->count) {
  3155. if(sc->data[SC_HALLUCINATION]) {
  3156. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3157. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3158. }
  3159. }
  3160. WBUFW(buf,0)=0x8a;
  3161. WBUFL(buf,2)=src->id;
  3162. WBUFL(buf,6)=dst->id;
  3163. WBUFL(buf,10)=tick;
  3164. WBUFL(buf,14)=sdelay;
  3165. WBUFL(buf,18)=ddelay;
  3166. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3167. WBUFW(buf,22)=damage?div:0;
  3168. WBUFW(buf,27)=damage2?div:0;
  3169. } else {
  3170. WBUFW(buf,22)=min(damage, SHRT_MAX);
  3171. WBUFW(buf,27)=damage2;
  3172. }
  3173. WBUFW(buf,24)=div;
  3174. WBUFB(buf,26)=type;
  3175. if(disguised(dst)) {
  3176. clif_send(buf,packet_len(0x8a),dst,AREA_WOS);
  3177. WBUFL(buf,6) = -dst->id;
  3178. clif_send(buf,packet_len(0x8a),dst,SELF);
  3179. } else
  3180. clif_send(buf,packet_len(0x8a),dst,AREA);
  3181. if(disguised(src)) {
  3182. WBUFL(buf,2) = -src->id;
  3183. if (disguised(dst))
  3184. WBUFL(buf,6) = dst->id;
  3185. if(damage > 0) WBUFW(buf,22) = -1;
  3186. if(damage2 > 0) WBUFW(buf,27) = -1;
  3187. clif_send(buf,packet_len(0x8a),src,SELF);
  3188. }
  3189. //Return adjusted can't walk delay for further processing.
  3190. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3191. }
  3192. /*==========================================
  3193. * src picks up dst
  3194. *------------------------------------------*/
  3195. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3196. {
  3197. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3198. unsigned char buf[32];
  3199. nullpo_retv(src);
  3200. nullpo_retv(dst);
  3201. WBUFW(buf, 0) = 0x8a;
  3202. WBUFL(buf, 2) = src->id;
  3203. WBUFL(buf, 6) = dst->id;
  3204. WBUFB(buf,26) = 1;
  3205. clif_send(buf, packet_len(0x8a), src, AREA);
  3206. }
  3207. /*==========================================
  3208. * inform clients in area that `bl` is sitting
  3209. *------------------------------------------*/
  3210. void clif_sitting(struct block_list* bl)
  3211. {
  3212. unsigned char buf[32];
  3213. nullpo_retv(bl);
  3214. WBUFW(buf, 0) = 0x8a;
  3215. WBUFL(buf, 2) = bl->id;
  3216. WBUFB(buf,26) = 2;
  3217. clif_send(buf, packet_len(0x8a), bl, AREA);
  3218. if(disguised(bl)) {
  3219. WBUFL(buf, 2) = - bl->id;
  3220. clif_send(buf, packet_len(0x8a), bl, SELF);
  3221. }
  3222. }
  3223. /*==========================================
  3224. * inform clients in area that `bl` is standing
  3225. *------------------------------------------*/
  3226. void clif_standing(struct block_list* bl)
  3227. {
  3228. unsigned char buf[32];
  3229. nullpo_retv(bl);
  3230. WBUFW(buf, 0) = 0x8a;
  3231. WBUFL(buf, 2) = bl->id;
  3232. WBUFB(buf,26) = 3;
  3233. clif_send(buf, packet_len(0x8a), bl, AREA);
  3234. if(disguised(bl)) {
  3235. WBUFL(buf, 2) = - bl->id;
  3236. clif_send(buf, packet_len(0x8a), bl, SELF);
  3237. }
  3238. }
  3239. /*==========================================
  3240. * Inform client(s) about a map-cell change
  3241. *------------------------------------------*/
  3242. void clif_changemapcell(int fd, int m, int x, int y, int type, enum send_target target)
  3243. {
  3244. unsigned char buf[32];
  3245. WBUFW(buf,0) = 0x192;
  3246. WBUFW(buf,2) = x;
  3247. WBUFW(buf,4) = y;
  3248. WBUFW(buf,6) = type;
  3249. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3250. if( fd )
  3251. {
  3252. WFIFOHEAD(fd,packet_len(0x192));
  3253. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3254. WFIFOSET(fd,packet_len(0x192));
  3255. }
  3256. else
  3257. {
  3258. struct block_list dummy_bl;
  3259. dummy_bl.type = BL_NUL;
  3260. dummy_bl.x = x;
  3261. dummy_bl.y = y;
  3262. dummy_bl.m = m;
  3263. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3264. }
  3265. }
  3266. /*==========================================
  3267. *
  3268. *------------------------------------------*/
  3269. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3270. {
  3271. int view,fd;
  3272. fd=sd->fd;
  3273. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3274. WFIFOHEAD(fd,packet_len(0x9d));
  3275. WFIFOW(fd,0)=0x9d;
  3276. WFIFOL(fd,2)=fitem->bl.id;
  3277. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3278. WFIFOW(fd,6)=view;
  3279. else
  3280. WFIFOW(fd,6)=fitem->item_data.nameid;
  3281. WFIFOB(fd,8)=fitem->item_data.identify;
  3282. WFIFOW(fd,9)=fitem->bl.x;
  3283. WFIFOW(fd,11)=fitem->bl.y;
  3284. WFIFOW(fd,13)=fitem->item_data.amount;
  3285. WFIFOB(fd,15)=fitem->subx;
  3286. WFIFOB(fd,16)=fitem->suby;
  3287. WFIFOSET(fd,packet_len(0x9d));
  3288. }
  3289. /*==========================================
  3290. * 場所スキルエフェクトが視界に入る
  3291. *------------------------------------------*/
  3292. static void clif_getareachar_skillunit(struct map_session_data *sd, struct skill_unit *unit)
  3293. {
  3294. int fd = sd->fd;
  3295. #if PACKETVER >= 3
  3296. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3297. WFIFOHEAD(fd,packet_len(0x1c9));
  3298. WFIFOW(fd, 0)=0x1c9;
  3299. WFIFOL(fd, 2)=unit->bl.id;
  3300. WFIFOL(fd, 6)=unit->group->src_id;
  3301. WFIFOW(fd,10)=unit->bl.x;
  3302. WFIFOW(fd,12)=unit->bl.y;
  3303. WFIFOB(fd,14)=unit->group->unit_id;
  3304. WFIFOB(fd,15)=1;
  3305. WFIFOB(fd,16)=1;
  3306. safestrncpy((char*)WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3307. WFIFOSET(fd,packet_len(0x1c9));
  3308. return;
  3309. }
  3310. #endif
  3311. WFIFOHEAD(fd,packet_len(0x11f));
  3312. WFIFOW(fd, 0)=0x11f;
  3313. WFIFOL(fd, 2)=unit->bl.id;
  3314. WFIFOL(fd, 6)=unit->group->src_id;
  3315. WFIFOW(fd,10)=unit->bl.x;
  3316. WFIFOW(fd,12)=unit->bl.y;
  3317. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3318. WFIFOB(fd,14)=UNT_DUMMYSKILL; //Use invisible unit id for traps.
  3319. else
  3320. WFIFOB(fd,14)=unit->group->unit_id;
  3321. WFIFOB(fd,15)=1; // ignored by client (always gets set to 1)
  3322. WFIFOSET(fd,packet_len(0x11f));
  3323. if(unit->group->skill_id == WZ_ICEWALL)
  3324. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  3325. }
  3326. /*==========================================
  3327. * 場所スキルエフェクトが視界から消える
  3328. *------------------------------------------*/
  3329. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3330. {
  3331. nullpo_retv(unit);
  3332. WFIFOHEAD(fd,packet_len(0x120));
  3333. WFIFOW(fd, 0)=0x120;
  3334. WFIFOL(fd, 2)=unit->bl.id;
  3335. WFIFOSET(fd,packet_len(0x120));
  3336. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3337. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  3338. }
  3339. /*==========================================
  3340. * 場所スキルエフェクト削除
  3341. *------------------------------------------*/
  3342. void clif_skill_delunit(struct skill_unit *unit)
  3343. {
  3344. unsigned char buf[16];
  3345. nullpo_retv(unit);
  3346. WBUFW(buf, 0)=0x120;
  3347. WBUFL(buf, 2)=unit->bl.id;
  3348. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3349. }
  3350. /*==========================================
  3351. * Unknown... trap related?
  3352. * Sent when an object gets ankle-snared
  3353. * Only affects units with class [139,153] client-side
  3354. * R 01ac <object id>.l
  3355. *------------------------------------------*/
  3356. void clif_01ac(struct block_list* bl)
  3357. {
  3358. unsigned char buf[6];
  3359. nullpo_retv(bl);
  3360. WBUFW(buf,0) = 0x1ac;
  3361. WBUFL(buf,2) = bl->id;
  3362. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3363. }
  3364. /*==========================================
  3365. *
  3366. *------------------------------------------*/
  3367. int clif_getareachar(struct block_list* bl,va_list ap)
  3368. {
  3369. struct map_session_data *sd;
  3370. nullpo_retr(0, bl);
  3371. sd=va_arg(ap,struct map_session_data*);
  3372. if (sd == NULL || !sd->fd)
  3373. return 0;
  3374. switch(bl->type){
  3375. case BL_ITEM:
  3376. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3377. break;
  3378. case BL_SKILL:
  3379. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3380. break;
  3381. default:
  3382. if(&sd->bl == bl)
  3383. break;
  3384. clif_getareachar_unit(sd,bl);
  3385. break;
  3386. }
  3387. return 0;
  3388. }
  3389. /*==========================================
  3390. * tbl has gone out of view-size of bl
  3391. *------------------------------------------*/
  3392. int clif_outsight(struct block_list *bl,va_list ap)
  3393. {
  3394. struct block_list *tbl;
  3395. struct view_data *vd;
  3396. TBL_PC *sd, *tsd;
  3397. tbl=va_arg(ap,struct block_list*);
  3398. if(bl == tbl) return 0;
  3399. sd = BL_CAST(BL_PC, bl);
  3400. tsd = BL_CAST(BL_PC, tbl);
  3401. if (tsd && tsd->fd)
  3402. { //tsd has lost sight of the bl object.
  3403. switch(bl->type){
  3404. case BL_PC:
  3405. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS)
  3406. clif_clearunit_single(bl->id,0,tsd->fd);
  3407. if(sd->chatID){
  3408. struct chat_data *cd;
  3409. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3410. if(cd->usersd[0]==sd)
  3411. clif_dispchat(cd,tsd->fd);
  3412. }
  3413. if(sd->vender_id)
  3414. clif_closevendingboard(bl,tsd->fd);
  3415. break;
  3416. case BL_ITEM:
  3417. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3418. break;
  3419. case BL_SKILL:
  3420. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3421. break;
  3422. default:
  3423. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3424. clif_clearunit_single(bl->id,0,tsd->fd);
  3425. break;
  3426. }
  3427. }
  3428. if (sd && sd->fd)
  3429. { //sd is watching tbl go out of view.
  3430. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3431. clif_clearunit_single(tbl->id,0,sd->fd);
  3432. }
  3433. return 0;
  3434. }
  3435. /*==========================================
  3436. * tbl has come into view of bl
  3437. *------------------------------------------*/
  3438. int clif_insight(struct block_list *bl,va_list ap)
  3439. {
  3440. struct block_list *tbl;
  3441. TBL_PC *sd, *tsd;
  3442. tbl=va_arg(ap,struct block_list*);
  3443. if (bl == tbl) return 0;
  3444. sd = BL_CAST(BL_PC, bl);
  3445. tsd = BL_CAST(BL_PC, tbl);
  3446. if (tsd && tsd->fd)
  3447. { //Tell tsd that bl entered into his view
  3448. switch(bl->type){
  3449. case BL_ITEM:
  3450. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3451. break;
  3452. case BL_SKILL:
  3453. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3454. break;
  3455. default:
  3456. clif_getareachar_unit(tsd,bl);
  3457. break;
  3458. }
  3459. }
  3460. if (sd && sd->fd)
  3461. { //Tell sd that tbl walked into his view
  3462. clif_getareachar_unit(sd,tbl);
  3463. }
  3464. return 0;
  3465. }
  3466. /*==========================================
  3467. *
  3468. *------------------------------------------*/
  3469. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3470. {
  3471. int fd,id;
  3472. nullpo_retr(0, sd);
  3473. fd=sd->fd;
  3474. if( (id=sd->status.skill[skillid].id) <= 0 )
  3475. return 0;
  3476. WFIFOHEAD(fd,packet_len(0x147));
  3477. WFIFOW(fd,0)=0x147;
  3478. WFIFOW(fd,2) = id;
  3479. if(type < 0)
  3480. WFIFOW(fd,4) = skill_get_inf(id);
  3481. else
  3482. WFIFOW(fd,4) = type;
  3483. WFIFOW(fd,6) = 0;
  3484. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3485. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3486. if(range < 0)
  3487. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3488. WFIFOW(fd,12)= range;
  3489. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3490. if(sd->status.skill[skillid].flag ==0)
  3491. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3492. else
  3493. WFIFOB(fd,38) = 0;
  3494. WFIFOSET(fd,packet_len(0x147));
  3495. return 0;
  3496. }
  3497. /*==========================================
  3498. * スキルリストを送信する
  3499. *------------------------------------------*/
  3500. int clif_skillinfoblock(struct map_session_data *sd)
  3501. {
  3502. int fd;
  3503. int i,c,len,id;
  3504. nullpo_retr(0, sd);
  3505. fd=sd->fd;
  3506. if (!fd) return 0;
  3507. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3508. WFIFOW(fd,0) = 0x10f;
  3509. for ( i = 0, c = 0, len = 4; i < MAX_SKILL; i++)
  3510. {
  3511. if( (id = sd->status.skill[i].id) != 0 )
  3512. {
  3513. WFIFOW(fd,len) = id;
  3514. WFIFOW(fd,len+2) = skill_get_inf(id);
  3515. WFIFOW(fd,len+4) = 0;
  3516. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3517. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3518. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3519. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3520. if(sd->status.skill[i].flag == 0)
  3521. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3522. else
  3523. WFIFOB(fd,len+36) = 0;
  3524. len += 37;
  3525. c++;
  3526. }
  3527. }
  3528. WFIFOW(fd,2)=len;
  3529. WFIFOSET(fd,len);
  3530. return 1;
  3531. }
  3532. /*==========================================
  3533. * スキル割り振り通知
  3534. *------------------------------------------*/
  3535. int clif_skillup(struct map_session_data *sd,int skill_num)
  3536. {
  3537. int fd;
  3538. nullpo_retr(0, sd);
  3539. fd=sd->fd;
  3540. WFIFOHEAD(fd,packet_len(0x10e));
  3541. WFIFOW(fd,0) = 0x10e;
  3542. WFIFOW(fd,2) = skill_num;
  3543. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3544. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3545. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3546. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3547. WFIFOSET(fd,packet_len(0x10e));
  3548. return 0;
  3549. }
  3550. /*==========================================
  3551. * スキル詠唱エフェクトを送信する
  3552. *------------------------------------------*/
  3553. int clif_skillcasting(struct block_list* bl,
  3554. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int pl, int casttime)
  3555. {
  3556. unsigned char buf[32];
  3557. WBUFW(buf,0) = 0x13e;
  3558. WBUFL(buf,2) = src_id;
  3559. WBUFL(buf,6) = dst_id;
  3560. WBUFW(buf,10) = dst_x;
  3561. WBUFW(buf,12) = dst_y;
  3562. WBUFW(buf,14) = skill_num;
  3563. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3564. WBUFL(buf,20) = casttime;
  3565. if (disguised(bl)) {
  3566. clif_send(buf,packet_len(0x13e), bl, AREA_WOS);
  3567. WBUFL(buf,2) = -src_id;
  3568. clif_send(buf,packet_len(0x13e), bl, SELF);
  3569. } else
  3570. clif_send(buf,packet_len(0x13e), bl, AREA);
  3571. return 0;
  3572. }
  3573. /*==========================================
  3574. *
  3575. *------------------------------------------*/
  3576. int clif_skillcastcancel(struct block_list* bl)
  3577. {
  3578. unsigned char buf[16];
  3579. nullpo_retr(0, bl);
  3580. WBUFW(buf,0) = 0x1b9;
  3581. WBUFL(buf,2) = bl->id;
  3582. clif_send(buf,packet_len(0x1b9), bl, AREA);
  3583. return 0;
  3584. }
  3585. /// only when type==0:
  3586. /// if(skill_id==NV_BASIC)
  3587. /// btype==0 "skill failed" MsgStringTable[159]
  3588. /// btype==1 "no emotions" MsgStringTable[160]
  3589. /// btype==2 "no sit" MsgStringTable[161]
  3590. /// btype==3 "no chat" MsgStringTable[162]
  3591. /// btype==4 "no party" MsgStringTable[163]
  3592. /// btype==5 "no shout" MsgStringTable[164]
  3593. /// btype==6 "no PKing" MsgStringTable[165]
  3594. /// btype==7 "no alligning" MsgStringTable[383]
  3595. /// btype>=8: ignored
  3596. /// if(skill_id==AL_WARP) "not enough skill level" MsgStringTable[214]
  3597. /// if(skill_id==TF_STEAL) "steal failed" MsgStringTable[205]
  3598. /// if(skill_id==TF_POISON) "envenom failed" MsgStringTable[207]
  3599. /// otherwise "skill failed" MsgStringTable[204]
  3600. /// btype irrelevant
  3601. /// type==1 "insufficient SP" MsgStringTable[202]
  3602. /// type==2 "insufficient HP" MsgStringTable[203]
  3603. /// type==3 "insufficient materials" MsgStringTable[808]
  3604. /// type==4 "there is a delay after using a skill" MsgStringTable[219]
  3605. /// type==5 "insufficient zeny" MsgStringTable[233]
  3606. /// type==6 "wrong weapon" MsgStringTable[239]
  3607. /// type==7 "red gemstone needed" MsgStringTable[246]
  3608. /// type==8 "blue gemstone needed" MsgStringTable[247]
  3609. /// type==9 "overweight" MsgStringTable[580]
  3610. /// type==10 "skill failed" MsgStringTable[285]
  3611. /// type>=11 ignored
  3612. ///
  3613. /// if(success!=0) doesn't display any of the previous messages
  3614. /// Note: when this packet is received an unknown flag is always set to 0,
  3615. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  3616. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3617. {
  3618. int fd;
  3619. if (!sd) { //Since this is the most common nullpo....
  3620. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3621. return 0;
  3622. }
  3623. fd=sd->fd;
  3624. if (!fd) return 0;
  3625. if(battle_config.display_skill_fail&1)
  3626. return 0; //Disable all skill failed messages
  3627. if(type==0x4 && !sd->state.showdelay)
  3628. return 0; //Disable delay failed messages
  3629. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3630. return 0;
  3631. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3632. return 0;
  3633. WFIFOHEAD(fd,packet_len(0x110));
  3634. WFIFOW(fd,0) = 0x110;
  3635. WFIFOW(fd,2) = skill_id;
  3636. WFIFOL(fd,4) = btype;
  3637. WFIFOB(fd,8) = 0;// success?
  3638. WFIFOB(fd,9) = type;
  3639. WFIFOSET(fd,packet_len(0x110));
  3640. return 1;
  3641. }
  3642. /*==========================================
  3643. * skill attack effect and damage
  3644. * R 01de <skill ID>.w <src ID>.l <dst ID>.l <tick>.l <src delay>.l <dst delay>.l <damage>.l <skillv>.w <div>.w <type>.B
  3645. *------------------------------------------*/
  3646. int clif_skill_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3647. {
  3648. unsigned char buf[64];
  3649. struct status_change *sc;
  3650. nullpo_retr(0, src);
  3651. nullpo_retr(0, dst);
  3652. type = clif_calc_delay(type,div,damage,ddelay);
  3653. sc = status_get_sc(dst);
  3654. if(sc && sc->count) {
  3655. if(sc->data[SC_HALLUCINATION] && damage)
  3656. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3657. }
  3658. #if PACKETVER < 3
  3659. WBUFW(buf,0)=0x114;
  3660. WBUFW(buf,2)=skill_id;
  3661. WBUFL(buf,4)=src->id;
  3662. WBUFL(buf,8)=dst->id;
  3663. WBUFL(buf,12)=tick;
  3664. WBUFL(buf,16)=sdelay;
  3665. WBUFL(buf,20)=ddelay;
  3666. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3667. WBUFW(buf,24)=damage?div:0;
  3668. } else {
  3669. WBUFW(buf,24)=damage;
  3670. }
  3671. WBUFW(buf,26)=skill_lv;
  3672. WBUFW(buf,28)=div;
  3673. WBUFB(buf,30)=type;
  3674. if (disguised(dst)) {
  3675. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  3676. WBUFL(buf,8)=-dst->id;
  3677. clif_send(buf,packet_len(0x114),dst,SELF);
  3678. } else
  3679. clif_send(buf,packet_len(0x114),dst,AREA);
  3680. if(disguised(src)) {
  3681. WBUFL(buf,4)=-src->id;
  3682. if (disguised(dst))
  3683. WBUFL(buf,8)=dst->id;
  3684. if(damage > 0)
  3685. WBUFW(buf,24)=-1;
  3686. clif_send(buf,packet_len(0x114),src,SELF);
  3687. }
  3688. #else
  3689. WBUFW(buf,0)=0x1de;
  3690. WBUFW(buf,2)=skill_id;
  3691. WBUFL(buf,4)=src->id;
  3692. WBUFL(buf,8)=dst->id;
  3693. WBUFL(buf,12)=tick;
  3694. WBUFL(buf,16)=sdelay;
  3695. WBUFL(buf,20)=ddelay;
  3696. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3697. WBUFL(buf,24)=damage?div:0;
  3698. } else {
  3699. WBUFL(buf,24)=damage;
  3700. }
  3701. WBUFW(buf,28)=skill_lv;
  3702. WBUFW(buf,30)=div;
  3703. WBUFB(buf,32)=type;
  3704. if (disguised(dst)) {
  3705. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  3706. WBUFL(buf,8)=-dst->id;
  3707. clif_send(buf,packet_len(0x1de),dst,SELF);
  3708. } else
  3709. clif_send(buf,packet_len(0x1de),dst,AREA);
  3710. if(disguised(src)) {
  3711. WBUFL(buf,4)=-src->id;
  3712. if (disguised(dst))
  3713. WBUFL(buf,8)=dst->id;
  3714. if(damage > 0)
  3715. WBUFL(buf,24)=-1;
  3716. clif_send(buf,packet_len(0x1de),src,SELF);
  3717. }
  3718. #endif
  3719. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3720. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3721. }
  3722. /*==========================================
  3723. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3724. *------------------------------------------*/
  3725. /*
  3726. int clif_skill_damage2(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3727. {
  3728. unsigned char buf[64];
  3729. struct status_change *sc;
  3730. nullpo_retr(0, src);
  3731. nullpo_retr(0, dst);
  3732. type = (type>0)?type:skill_get_hit(skill_id);
  3733. type = clif_calc_delay(type,div,damage,ddelay);
  3734. sc = status_get_sc(dst);
  3735. if(sc && sc->count) {
  3736. if(sc->data[SC_HALLUCINATION] && damage)
  3737. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3738. }
  3739. WBUFW(buf,0)=0x115;
  3740. WBUFW(buf,2)=skill_id;
  3741. WBUFL(buf,4)=src->id;
  3742. WBUFL(buf,8)=dst->id;
  3743. WBUFL(buf,12)=tick;
  3744. WBUFL(buf,16)=sdelay;
  3745. WBUFL(buf,20)=ddelay;
  3746. WBUFW(buf,24)=dst->x;
  3747. WBUFW(buf,26)=dst->y;
  3748. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3749. WBUFW(buf,28)=damage?div:0;
  3750. } else {
  3751. WBUFW(buf,28)=damage;
  3752. }
  3753. WBUFW(buf,30)=skill_lv;
  3754. WBUFW(buf,32)=div;
  3755. WBUFB(buf,34)=type;
  3756. clif_send(buf,packet_len(0x115),src,AREA);
  3757. if(disguised(src)) {
  3758. WBUFL(buf,4)=-src->id;
  3759. if(damage > 0)
  3760. WBUFW(buf,28)=-1;
  3761. clif_send(buf,packet_len(0x115),src,SELF);
  3762. }
  3763. if (disguised(dst)) {
  3764. WBUFL(buf,8)=-dst->id;
  3765. if (disguised(src))
  3766. WBUFL(buf,4)=src->id;
  3767. else if(damage > 0)
  3768. WBUFW(buf,28)=-1;
  3769. clif_send(buf,packet_len(0x115),dst,SELF);
  3770. }
  3771. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3772. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3773. }
  3774. */
  3775. /*==========================================
  3776. * 支援/回復スキルエフェクト
  3777. *------------------------------------------*/
  3778. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_id,int heal,int fail)
  3779. {
  3780. unsigned char buf[32];
  3781. nullpo_retr(0, dst);
  3782. WBUFW(buf,0)=0x11a;
  3783. WBUFW(buf,2)=skill_id;
  3784. WBUFW(buf,4)=min(heal, SHRT_MAX);
  3785. WBUFL(buf,6)=dst->id;
  3786. WBUFL(buf,10)=src?src->id:0;
  3787. WBUFB(buf,14)=fail;
  3788. if (disguised(dst)) {
  3789. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  3790. WBUFL(buf,6)=-dst->id;
  3791. clif_send(buf,packet_len(0x11a),dst,SELF);
  3792. } else
  3793. clif_send(buf,packet_len(0x11a),dst,AREA);
  3794. if(src && disguised(src)) {
  3795. WBUFL(buf,10)=-src->id;
  3796. if (disguised(dst))
  3797. WBUFL(buf,6)=dst->id;
  3798. clif_send(buf,packet_len(0x11a),src,SELF);
  3799. }
  3800. return fail;
  3801. }
  3802. /*==========================================
  3803. * 場所スキルエフェクト
  3804. *------------------------------------------*/
  3805. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  3806. {
  3807. unsigned char buf[32];
  3808. nullpo_retr(0, src);
  3809. WBUFW(buf,0)=0x117;
  3810. WBUFW(buf,2)=skill_id;
  3811. WBUFL(buf,4)=src->id;
  3812. WBUFW(buf,8)=val;
  3813. WBUFW(buf,10)=x;
  3814. WBUFW(buf,12)=y;
  3815. WBUFL(buf,14)=tick;
  3816. if(disguised(src)) {
  3817. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  3818. WBUFL(buf,4)=-src->id;
  3819. clif_send(buf,packet_len(0x117),src,SELF);
  3820. } else
  3821. clif_send(buf,packet_len(0x117),src,AREA);
  3822. return 0;
  3823. }
  3824. /*==========================================
  3825. * 場所スキルエフェクト表示
  3826. *------------------------------------------*/
  3827. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  3828. void clif_skill_setunit(struct skill_unit *unit)
  3829. {
  3830. unsigned char buf[128];
  3831. nullpo_retv(unit);
  3832. #if PACKETVER >= 3
  3833. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3834. WBUFW(buf, 0)=0x1c9;
  3835. WBUFL(buf, 2)=unit->bl.id;
  3836. WBUFL(buf, 6)=unit->group->src_id;
  3837. WBUFW(buf,10)=unit->bl.x;
  3838. WBUFW(buf,12)=unit->bl.y;
  3839. WBUFB(buf,14)=unit->group->unit_id;
  3840. WBUFB(buf,15)=1;
  3841. WBUFB(buf,16)=1;
  3842. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  3843. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  3844. return;
  3845. }
  3846. #endif
  3847. WBUFW(buf, 0)=0x11f;
  3848. WBUFL(buf, 2)=unit->bl.id;
  3849. WBUFL(buf, 6)=unit->group->src_id;
  3850. WBUFW(buf,10)=unit->bl.x;
  3851. WBUFW(buf,12)=unit->bl.y;
  3852. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  3853. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  3854. else
  3855. WBUFB(buf,14)=unit->group->unit_id;
  3856. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  3857. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  3858. }
  3859. /*==========================================
  3860. * ワープ場所選択
  3861. *------------------------------------------*/
  3862. void clif_skill_warppoint(struct map_session_data* sd, short skill_num, short skill_lv, unsigned short map1, unsigned short map2, unsigned short map3, unsigned short map4)
  3863. {
  3864. int fd;
  3865. nullpo_retv(sd);
  3866. fd = sd->fd;
  3867. WFIFOHEAD(fd,packet_len(0x11c));
  3868. WFIFOW(fd,0) = 0x11c;
  3869. WFIFOW(fd,2) = skill_num;
  3870. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  3871. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  3872. else // normal map name
  3873. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  3874. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  3875. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  3876. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  3877. WFIFOSET(fd,packet_len(0x11c));
  3878. sd->menuskill_id = skill_num;
  3879. if (skill_num == AL_WARP)
  3880. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  3881. else
  3882. sd->menuskill_val = skill_lv;
  3883. }
  3884. /// Memo message.
  3885. /// type=0 : "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  3886. /// type=1 : "Skill Level is not high enough." in color 0x0000FF (red)
  3887. /// type=2 : "You haven't learned Warp." in color 0x0000FF (red)
  3888. ///
  3889. /// @param sd Who receives the message
  3890. /// @param type What message
  3891. void clif_skill_memomessage(struct map_session_data* sd, int type)
  3892. {
  3893. int fd;
  3894. nullpo_retv(sd);
  3895. fd=sd->fd;
  3896. WFIFOHEAD(fd,packet_len(0x11e));
  3897. WFIFOW(fd,0)=0x11e;
  3898. WFIFOB(fd,2)=type;
  3899. WFIFOSET(fd,packet_len(0x11e));
  3900. }
  3901. /// Teleport message.
  3902. /// type=0 : "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  3903. /// type=1 : "Saved point cannot be memorized." in color 0x0000FF (red)
  3904. ///
  3905. /// @param sd Who receives the message
  3906. /// @param type What message
  3907. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  3908. {
  3909. int fd;
  3910. nullpo_retv(sd);
  3911. fd=sd->fd;
  3912. WFIFOHEAD(fd,packet_len(0x189));
  3913. WFIFOW(fd,0)=0x189;
  3914. WFIFOW(fd,2)=type;
  3915. WFIFOSET(fd,packet_len(0x189));
  3916. }
  3917. /*==========================================
  3918. * モンスター情報
  3919. *------------------------------------------*/
  3920. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  3921. {
  3922. struct status_data *status;
  3923. unsigned char buf[64];
  3924. int i;//, fix;
  3925. nullpo_retr(0, sd);
  3926. nullpo_retr(0, dst);
  3927. if( dst->type != BL_MOB )
  3928. return 0;
  3929. status = status_get_status_data(dst);
  3930. WBUFW(buf, 0)=0x18c;
  3931. WBUFW(buf, 2)=status_get_class(dst);
  3932. WBUFW(buf, 4)=status_get_lv(dst);
  3933. WBUFW(buf, 6)=status->size;
  3934. WBUFL(buf, 8)=status->hp;
  3935. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  3936. +(battle_config.estimation_type&2?status->def2:0);
  3937. WBUFW(buf,14)=status->race;
  3938. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  3939. +(battle_config.estimation_type&2?status->mdef2:0);
  3940. WBUFW(buf,18)= status->def_ele;
  3941. for(i=0;i<9;i++)
  3942. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  3943. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  3944. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  3945. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  3946. return 0;
  3947. }
  3948. /*==========================================
  3949. * アイテム合成可能リスト
  3950. *------------------------------------------*/
  3951. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  3952. {
  3953. int i,c,view,fd;
  3954. nullpo_retr(0, sd);
  3955. if(sd->menuskill_id == AM_PHARMACY)
  3956. return 0; //Avoid resending the menu twice or more times...
  3957. fd=sd->fd;
  3958. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  3959. WFIFOW(fd, 0)=0x18d;
  3960. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  3961. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  3962. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  3963. WFIFOW(fd,c*8+ 4)= view;
  3964. else
  3965. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  3966. WFIFOW(fd,c*8+ 6)= 0x0012;
  3967. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  3968. c++;
  3969. }
  3970. }
  3971. WFIFOW(fd, 2)=c*8+8;
  3972. WFIFOSET(fd,WFIFOW(fd,2));
  3973. if(c > 0) {
  3974. sd->menuskill_id = AM_PHARMACY;
  3975. sd->menuskill_val = trigger;
  3976. return 1;
  3977. }
  3978. return 0;
  3979. }
  3980. /*==========================================
  3981. *
  3982. *------------------------------------------*/
  3983. void clif_cooking_list(struct map_session_data *sd, int trigger)
  3984. {
  3985. int fd;
  3986. int i, c;
  3987. int view;
  3988. nullpo_retv(sd);
  3989. fd = sd->fd;
  3990. WFIFOHEAD(fd, 6 + 2*MAX_SKILL_PRODUCE_DB);
  3991. WFIFOW(fd,0) = 0x25a;
  3992. WFIFOW(fd,4) = 1; // list type
  3993. c = 0;
  3994. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ )
  3995. {
  3996. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) )
  3997. continue;
  3998. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  3999. WFIFOW(fd, 6+2*c)= view;
  4000. else
  4001. WFIFOW(fd, 6+2*c)= skill_produce_db[i].nameid;
  4002. c++;
  4003. }
  4004. WFIFOW(fd,2) = 6 + 2*c;
  4005. WFIFOSET(fd,WFIFOW(fd,2));
  4006. //TODO: replace with proper solution
  4007. if( c > 0 )
  4008. {
  4009. sd->menuskill_id = AM_PHARMACY;
  4010. sd->menuskill_val = trigger;
  4011. }
  4012. }
  4013. /*==========================================
  4014. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  4015. *------------------------------------------*/
  4016. int clif_status_load(struct block_list *bl,int type, int flag)
  4017. {
  4018. int fd;
  4019. if (type == SI_BLANK) //It shows nothing on the client...
  4020. return 0;
  4021. if (bl->type != BL_PC)
  4022. return 0;
  4023. fd = ((struct map_session_data*)bl)->fd;
  4024. WFIFOHEAD(fd,packet_len(0x196));
  4025. WFIFOW(fd,0)=0x0196;
  4026. WFIFOW(fd,2)=type;
  4027. WFIFOL(fd,4)=bl->id;
  4028. WFIFOB(fd,8)=flag; //Status start
  4029. WFIFOSET(fd, packet_len(0x196));
  4030. return 0;
  4031. }
  4032. /*==========================================
  4033. * 状態異常アイコン/メッセージ表示
  4034. *------------------------------------------*/
  4035. int clif_status_change(struct block_list *bl,int type,int flag,unsigned int tick)
  4036. {
  4037. unsigned char buf[32];
  4038. if (type == SI_BLANK) //It shows nothing on the client...
  4039. return 0;
  4040. nullpo_retr(0, bl);
  4041. if (type == SI_BLANK || type == SI_MAXIMIZEPOWER || type == SI_RIDING ||
  4042. type == SI_FALCON || type == SI_TRICKDEAD || type == SI_BROKENARMOR ||
  4043. type == SI_BROKENWEAPON || type == SI_WEIGHT50 || type == SI_WEIGHT90 ||
  4044. type == SI_TENSIONRELAX || type == SI_LANDENDOW || type == SI_AUTOBERSERK ||
  4045. type == SI_BUMP || type == SI_READYSTORM || type == SI_READYDOWN ||
  4046. type == SI_READYTURN || type == SI_READYCOUNTER || type == SI_DODGE ||
  4047. type == SI_DEVIL || type == SI_NIGHT || type == SI_INTRAVISION)
  4048. tick=0;
  4049. if( battle_config.display_status_timers && tick>0 )
  4050. WBUFW(buf,0)=0x043f;
  4051. else
  4052. WBUFW(buf,0)=0x0196;
  4053. WBUFW(buf,2)=type;
  4054. WBUFL(buf,4)=bl->id;
  4055. WBUFB(buf,8)=flag;
  4056. if( battle_config.display_status_timers && tick>0 )
  4057. {
  4058. WBUFL(buf,9)=tick;
  4059. WBUFL(buf,13)=0;
  4060. WBUFL(buf,17)=0;
  4061. WBUFL(buf,21)=0;
  4062. }
  4063. clif_send(buf,packet_len(WBUFW(buf,0)),bl,AREA);
  4064. return 0;
  4065. }
  4066. /*==========================================
  4067. * Send message (modified by [Yor])
  4068. *------------------------------------------*/
  4069. int clif_displaymessage(const int fd, const char* mes)
  4070. {
  4071. // invalid pointer?
  4072. nullpo_retr(-1, mes);
  4073. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4074. if (fd == 0)
  4075. return 0;
  4076. else {
  4077. int len_mes = strlen(mes);
  4078. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4079. WFIFOHEAD(fd, 5 + len_mes);
  4080. WFIFOW(fd,0) = 0x8e;
  4081. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  4082. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  4083. WFIFOSET(fd, 5 + len_mes);
  4084. }
  4085. }
  4086. return 0;
  4087. }
  4088. /*==========================================
  4089. * 天の声を送信する
  4090. *------------------------------------------*/
  4091. int clif_GMmessage(struct block_list* bl, const char* mes, int len, int flag)
  4092. {
  4093. unsigned char *buf;
  4094. int lp;
  4095. lp = (flag & 0x10) ? 8 : 4;
  4096. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  4097. WBUFW(buf,0) = 0x9a;
  4098. WBUFW(buf,2) = len + lp;
  4099. WBUFL(buf,4) = 0x65756c62; //"blue":
  4100. memcpy(WBUFP(buf,lp), mes, len);
  4101. flag &= 0x07;
  4102. clif_send(buf, WBUFW(buf,2), bl,
  4103. (flag == 1) ? ALL_SAMEMAP :
  4104. (flag == 2) ? AREA :
  4105. (flag == 3) ? SELF :
  4106. ALL_CLIENT);
  4107. if(buf) aFree(buf);
  4108. return 0;
  4109. }
  4110. /*==========================================
  4111. * グローバルメッセージ
  4112. *------------------------------------------*/
  4113. void clif_GlobalMessage(struct block_list* bl, const char* message)
  4114. {
  4115. char buf[100];
  4116. int len;
  4117. nullpo_retv(bl);
  4118. if(!message)
  4119. return;
  4120. len = strlen(message)+1;
  4121. WBUFW(buf,0)=0x8d;
  4122. WBUFW(buf,2)=len+8;
  4123. WBUFL(buf,4)=bl->id;
  4124. strncpy((char *) WBUFP(buf,8),message,len);
  4125. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4126. }
  4127. /*==========================================
  4128. * Send main chat message [LuzZza]
  4129. *------------------------------------------*/
  4130. void clif_MainChatMessage(const char* message)
  4131. {
  4132. char buf[200];
  4133. int len;
  4134. if(!message)
  4135. return;
  4136. len = strlen(message)+1;
  4137. if (len+8 > sizeof(buf)) {
  4138. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4139. len = sizeof(buf)-8;
  4140. }
  4141. WBUFW(buf,0)=0x8d;
  4142. WBUFW(buf,2)=len+8;
  4143. WBUFL(buf,4)=0;
  4144. strncpy((char *) WBUFP(buf,8),message,len);
  4145. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4146. }
  4147. /*==========================================
  4148. * Does an announce message in the given color.
  4149. *------------------------------------------*/
  4150. int clif_announce(struct block_list* bl, const char* mes, int len, unsigned long color, int flag)
  4151. {
  4152. return clif_announce_ex(bl, mes, len, color, flag, 12);
  4153. }
  4154. int clif_announce_ex(struct block_list* bl, const char* mes, int len, unsigned long color, int flag, int size)
  4155. {
  4156. unsigned char *buf;
  4157. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4158. WBUFW(buf,0) = 0x1c3;
  4159. WBUFW(buf,2) = len + 16;
  4160. WBUFL(buf,4) = color;
  4161. WBUFW(buf,8) = 0x190; //Font style? Type?
  4162. WBUFW(buf,10) = size; // Font size
  4163. WBUFL(buf,12) = 0; //Unknown!
  4164. memcpy(WBUFP(buf,16), mes, len);
  4165. flag &= 0x07;
  4166. clif_send(buf, WBUFW(buf,2), bl,
  4167. (flag == 1) ? ALL_SAMEMAP :
  4168. (flag == 2) ? AREA :
  4169. (flag == 3) ? SELF :
  4170. ALL_CLIENT);
  4171. if(buf) aFree(buf);
  4172. return 0;
  4173. }
  4174. /*==========================================
  4175. * HPSP回復エフェクトを送信する
  4176. *------------------------------------------*/
  4177. int clif_heal(int fd,int type,int val)
  4178. {
  4179. WFIFOHEAD(fd,packet_len(0x13d));
  4180. WFIFOW(fd,0)=0x13d;
  4181. WFIFOW(fd,2)=type;
  4182. WFIFOW(fd,4)=cap_value(val,0,SHRT_MAX);
  4183. WFIFOSET(fd,packet_len(0x13d));
  4184. return 0;
  4185. }
  4186. /*==========================================
  4187. * 復活する
  4188. *------------------------------------------*/
  4189. int clif_resurrection(struct block_list *bl,int type)
  4190. {
  4191. unsigned char buf[16];
  4192. nullpo_retr(0, bl);
  4193. WBUFW(buf,0)=0x148;
  4194. WBUFL(buf,2)=bl->id;
  4195. WBUFW(buf,6)=type;
  4196. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4197. if (disguised(bl))
  4198. clif_spawn(bl);
  4199. return 0;
  4200. }
  4201. /// Sets the map mode.
  4202. ///
  4203. /// mode=1 : pvp mode
  4204. /// mode=2 : unknown mode (pk?)
  4205. /// mode=3 : gvg mode
  4206. /// mode=4 : message "You are in a PK area. Please beware of sudden attacks." in color 0x9B9BFF (light red)
  4207. /// mode=5 : pvp mode
  4208. /// mode=other : ?
  4209. void clif_set0199(struct map_session_data* sd, int mode)
  4210. {
  4211. int fd;
  4212. nullpo_retv(sd);
  4213. fd=sd->fd;
  4214. WFIFOHEAD(fd,packet_len(0x199));
  4215. WFIFOW(fd,0)=0x199;
  4216. WFIFOW(fd,2)=mode;
  4217. WFIFOSET(fd,packet_len(0x199));
  4218. }
  4219. /// Set the map mode (special)
  4220. /// 19 = battleground
  4221. void clif_set01D6(struct map_session_data* sd, int mode)
  4222. {
  4223. int fd;
  4224. nullpo_retv(sd);
  4225. fd=sd->fd;
  4226. WFIFOHEAD(fd,packet_len(0x1D6));
  4227. WFIFOW(fd,0)=0x1D6;
  4228. WFIFOW(fd,2)=mode;
  4229. WFIFOSET(fd,packet_len(0x1D6));
  4230. }
  4231. /*==========================================
  4232. * PVP実装?(仮)
  4233. *------------------------------------------*/
  4234. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4235. {
  4236. if(type == 2) {
  4237. int fd = sd->fd;
  4238. WFIFOHEAD(fd,packet_len(0x19a));
  4239. WFIFOW(fd,0) = 0x19a;
  4240. WFIFOL(fd,2) = sd->bl.id;
  4241. WFIFOL(fd,6) = pvprank;
  4242. WFIFOL(fd,10) = pvpnum;
  4243. WFIFOSET(fd,packet_len(0x19a));
  4244. } else {
  4245. unsigned char buf[32];
  4246. WBUFW(buf,0) = 0x19a;
  4247. WBUFL(buf,2) = sd->bl.id;
  4248. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4249. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4250. else
  4251. WBUFL(buf,6) = pvprank;
  4252. WBUFL(buf,10) = pvpnum;
  4253. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  4254. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4255. else if(!type)
  4256. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4257. else
  4258. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4259. }
  4260. return 0;
  4261. }
  4262. /*==========================================
  4263. *
  4264. *------------------------------------------*/
  4265. int clif_send0199(int map,int type)
  4266. {
  4267. struct block_list bl;
  4268. unsigned char buf[16];
  4269. bl.id = 0;
  4270. bl.type = BL_NUL;
  4271. bl.m = map;
  4272. WBUFW(buf,0)=0x199;
  4273. WBUFW(buf,2)=type;
  4274. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4275. return 0;
  4276. }
  4277. /*==========================================
  4278. * 精錬エフェクトを送信する
  4279. *------------------------------------------*/
  4280. void clif_refine(int fd, int fail, int index, int val)
  4281. {
  4282. WFIFOHEAD(fd,packet_len(0x188));
  4283. WFIFOW(fd,0)=0x188;
  4284. WFIFOW(fd,2)=fail;
  4285. WFIFOW(fd,4)=index+2;
  4286. WFIFOW(fd,6)=val;
  4287. WFIFOSET(fd,packet_len(0x188));
  4288. }
  4289. /// result=0: "weapon upgrated: %s" MsgStringTable[911] in rgb(0,255,255)
  4290. /// result=1: "weapon upgrated: %s" MsgStringTable[912] in rgb(0,205,205)
  4291. /// result=2: "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4292. /// result=3: "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4293. void clif_upgrademessage(int fd, int result, int item_id)
  4294. {
  4295. WFIFOHEAD(fd,packet_len(0x223));
  4296. WFIFOW(fd,0)=0x223;
  4297. WFIFOL(fd,2)=result;
  4298. WFIFOW(fd,6)=item_id;
  4299. WFIFOSET(fd,packet_len(0x223));
  4300. }
  4301. /*==========================================
  4302. * Wisp/page is transmitted to the destination player
  4303. * R 0097 <len>.w <nick>.24B <message>.?B
  4304. *------------------------------------------*/
  4305. int clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4306. {
  4307. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4308. WFIFOW(fd,0) = 0x97;
  4309. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4310. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4311. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  4312. WFIFOSET(fd,WFIFOW(fd,2));
  4313. return 0;
  4314. }
  4315. /*==========================================
  4316. * Inform the player about the result of his whisper action
  4317. * R 0098 <type>.B
  4318. * 0: success to send wisper
  4319. * 1: target character is not loged in
  4320. * 2: ignored by target
  4321. * 3: everyone ignored by target
  4322. *------------------------------------------*/
  4323. int clif_wis_end(int fd, int flag)
  4324. {
  4325. WFIFOHEAD(fd,packet_len(0x98));
  4326. WFIFOW(fd,0) = 0x98;
  4327. WFIFOW(fd,2) = flag;
  4328. WFIFOSET(fd,packet_len(0x98));
  4329. return 0;
  4330. }
  4331. /*==========================================
  4332. * キャラID名前引き結果を送信する
  4333. *------------------------------------------*/
  4334. int clif_solved_charname(int fd, int charid, const char* name)
  4335. {
  4336. WFIFOHEAD(fd,packet_len(0x194));
  4337. WFIFOW(fd,0)=0x194;
  4338. WFIFOL(fd,2)=charid;
  4339. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  4340. WFIFOSET(fd,packet_len(0x194));
  4341. return 0;
  4342. }
  4343. /*==========================================
  4344. * カードの挿入可能リストを返す
  4345. *------------------------------------------*/
  4346. int clif_use_card(struct map_session_data *sd,int idx)
  4347. {
  4348. int i,c,ep;
  4349. int fd=sd->fd;
  4350. nullpo_retr(0, sd);
  4351. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4352. return 0;
  4353. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4354. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4355. ep=sd->inventory_data[idx]->equip;
  4356. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4357. WFIFOW(fd,0)=0x017b;
  4358. for(i=c=0;i<MAX_INVENTORY;i++){
  4359. int j;
  4360. if(sd->inventory_data[i] == NULL)
  4361. continue;
  4362. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4363. continue;
  4364. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4365. continue;
  4366. if(sd->status.inventory[i].identify==0 ) //Not identified
  4367. continue;
  4368. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4369. continue;
  4370. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  4371. continue;
  4372. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  4373. if( j == sd->inventory_data[i]->slot ) // No room
  4374. continue;
  4375. WFIFOW(fd,4+c*2)=i+2;
  4376. c++;
  4377. }
  4378. WFIFOW(fd,2)=4+c*2;
  4379. WFIFOSET(fd,WFIFOW(fd,2));
  4380. return 0;
  4381. }
  4382. /*==========================================
  4383. * カードの挿入終了
  4384. *------------------------------------------*/
  4385. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4386. {
  4387. int fd;
  4388. nullpo_retr(0, sd);
  4389. fd=sd->fd;
  4390. WFIFOHEAD(fd,packet_len(0x17d));
  4391. WFIFOW(fd,0)=0x17d;
  4392. WFIFOW(fd,2)=idx_equip+2;
  4393. WFIFOW(fd,4)=idx_card+2;
  4394. WFIFOB(fd,6)=flag;
  4395. WFIFOSET(fd,packet_len(0x17d));
  4396. return 0;
  4397. }
  4398. /*==========================================
  4399. * 鑑定可能アイテムリスト送信
  4400. *------------------------------------------*/
  4401. int clif_item_identify_list(struct map_session_data *sd)
  4402. {
  4403. int i,c;
  4404. int fd;
  4405. nullpo_retr(0, sd);
  4406. fd=sd->fd;
  4407. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4408. WFIFOW(fd,0)=0x177;
  4409. for(i=c=0;i<MAX_INVENTORY;i++){
  4410. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4411. WFIFOW(fd,c*2+4)=i+2;
  4412. c++;
  4413. }
  4414. }
  4415. if(c > 0) {
  4416. WFIFOW(fd,2)=c*2+4;
  4417. WFIFOSET(fd,WFIFOW(fd,2));
  4418. sd->menuskill_id = MC_IDENTIFY;
  4419. sd->menuskill_val = c;
  4420. }
  4421. return 0;
  4422. }
  4423. /*==========================================
  4424. * 鑑定結果
  4425. *------------------------------------------*/
  4426. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4427. {
  4428. int fd;
  4429. nullpo_retr(0, sd);
  4430. fd=sd->fd;
  4431. WFIFOHEAD(fd,packet_len(0x179));
  4432. WFIFOW(fd, 0)=0x179;
  4433. WFIFOW(fd, 2)=idx+2;
  4434. WFIFOB(fd, 4)=flag;
  4435. WFIFOSET(fd,packet_len(0x179));
  4436. return 0;
  4437. }
  4438. /*==========================================
  4439. * 修理可能アイテムリスト送信
  4440. *------------------------------------------*/
  4441. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4442. {
  4443. int i,c;
  4444. int fd;
  4445. int nameid;
  4446. nullpo_retr(0, sd);
  4447. nullpo_retr(0, dstsd);
  4448. fd=sd->fd;
  4449. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4450. WFIFOW(fd,0)=0x1fc;
  4451. for(i=c=0;i<MAX_INVENTORY;i++){
  4452. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4453. WFIFOW(fd,c*13+4) = i;
  4454. WFIFOW(fd,c*13+6) = nameid;
  4455. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4456. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4457. WFIFOB(fd,c*13+16)= c;
  4458. c++;
  4459. }
  4460. }
  4461. if(c > 0) {
  4462. WFIFOW(fd,2)=c*13+4;
  4463. WFIFOSET(fd,WFIFOW(fd,2));
  4464. sd->menuskill_id = BS_REPAIRWEAPON;
  4465. sd->menuskill_val = dstsd->bl.id;
  4466. }else
  4467. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4468. return 0;
  4469. }
  4470. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4471. {
  4472. int view,fd;
  4473. nullpo_retr(0, sd);
  4474. fd=sd->fd;
  4475. WFIFOHEAD(fd,packet_len(0x1fe));
  4476. WFIFOW(fd, 0)=0x1fe;
  4477. if((view = itemdb_viewid(nameid)) > 0)
  4478. WFIFOW(fd, 2)=view;
  4479. else
  4480. WFIFOW(fd, 2)=nameid;
  4481. WFIFOB(fd, 4)=flag;
  4482. WFIFOSET(fd,packet_len(0x1fe));
  4483. return 0;
  4484. }
  4485. /*==========================================
  4486. * Weapon Refining - Taken from jAthena
  4487. *------------------------------------------*/
  4488. int clif_item_refine_list(struct map_session_data *sd)
  4489. {
  4490. int i,c;
  4491. int fd;
  4492. int skilllv;
  4493. int wlv;
  4494. int refine_item[5];
  4495. nullpo_retr(0, sd);
  4496. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4497. fd=sd->fd;
  4498. refine_item[0] = -1;
  4499. refine_item[1] = pc_search_inventory(sd,1010);
  4500. refine_item[2] = pc_search_inventory(sd,1011);
  4501. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4502. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4503. WFIFOW(fd,0)=0x221;
  4504. for(i=c=0;i<MAX_INVENTORY;i++){
  4505. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4506. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4507. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4508. WFIFOW(fd,c*13+ 4)=i+2;
  4509. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4510. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4511. WFIFOW(fd,c*13+10)=0;
  4512. WFIFOB(fd,c*13+12)=c;
  4513. c++;
  4514. }
  4515. }
  4516. WFIFOW(fd,2)=c*13+4;
  4517. WFIFOSET(fd,WFIFOW(fd,2));
  4518. if (c > 0) {
  4519. sd->menuskill_id = WS_WEAPONREFINE;
  4520. sd->menuskill_val = skilllv;
  4521. }
  4522. return 0;
  4523. }
  4524. /*==========================================
  4525. * アイテムによる一時的なスキル効果
  4526. *------------------------------------------*/
  4527. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  4528. {
  4529. int fd;
  4530. nullpo_retr(0, sd);
  4531. fd=sd->fd;
  4532. WFIFOHEAD(fd,packet_len(0x147));
  4533. WFIFOW(fd, 0)=0x147;
  4534. WFIFOW(fd, 2)=skillid;
  4535. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4536. WFIFOW(fd, 6)=0;
  4537. WFIFOW(fd, 8)=skilllv;
  4538. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4539. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4540. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  4541. WFIFOB(fd,38)=0;
  4542. WFIFOSET(fd,packet_len(0x147));
  4543. return 0;
  4544. }
  4545. /*==========================================
  4546. * カートにアイテム追加
  4547. *------------------------------------------*/
  4548. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4549. {
  4550. int view,fd;
  4551. unsigned char *buf;
  4552. nullpo_retr(0, sd);
  4553. fd=sd->fd;
  4554. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4555. return 1;
  4556. #if PACKETVER < 5
  4557. WFIFOHEAD(fd,packet_len(0x124));
  4558. buf=WFIFOP(fd,0);
  4559. WBUFW(buf,0)=0x124;
  4560. WBUFW(buf,2)=n+2;
  4561. WBUFL(buf,4)=amount;
  4562. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4563. WBUFW(buf,8)=view;
  4564. else
  4565. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4566. WBUFB(buf,10)=sd->status.cart[n].identify;
  4567. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4568. WBUFB(buf,12)=sd->status.cart[n].refine;
  4569. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4570. WFIFOSET(fd,packet_len(0x124));
  4571. #else
  4572. WFIFOHEAD(fd,packet_len(0x1c5));
  4573. buf=WFIFOP(fd,0);
  4574. WBUFW(buf,0)=0x1c5;
  4575. WBUFW(buf,2)=n+2;
  4576. WBUFL(buf,4)=amount;
  4577. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4578. WBUFW(buf,8)=view;
  4579. else
  4580. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4581. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  4582. WBUFB(buf,11)=sd->status.cart[n].identify;
  4583. WBUFB(buf,12)=sd->status.cart[n].attribute;
  4584. WBUFB(buf,13)=sd->status.cart[n].refine;
  4585. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  4586. WFIFOSET(fd,packet_len(0x1c5));
  4587. #endif
  4588. return 0;
  4589. }
  4590. /*==========================================
  4591. * カートからアイテム削除
  4592. *------------------------------------------*/
  4593. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4594. {
  4595. int fd;
  4596. nullpo_retr(0, sd);
  4597. fd=sd->fd;
  4598. WFIFOHEAD(fd,packet_len(0x125));
  4599. WFIFOW(fd,0)=0x125;
  4600. WFIFOW(fd,2)=n+2;
  4601. WFIFOL(fd,4)=amount;
  4602. WFIFOSET(fd,packet_len(0x125));
  4603. return 0;
  4604. }
  4605. /*==========================================
  4606. * Opens the shop creation menu.
  4607. * R 012d <num>.w
  4608. * 'num' is the number of allowed item slots
  4609. *------------------------------------------*/
  4610. void clif_openvendingreq(struct map_session_data* sd, int num)
  4611. {
  4612. int fd;
  4613. nullpo_retv(sd);
  4614. fd = sd->fd;
  4615. WFIFOHEAD(fd,packet_len(0x12d));
  4616. WFIFOW(fd,0) = 0x12d;
  4617. WFIFOW(fd,2) = num;
  4618. WFIFOSET(fd,packet_len(0x12d));
  4619. }
  4620. /*==========================================
  4621. * Displays a vending board to target/area
  4622. * R 0131 <ID>.l <message>.80B
  4623. *------------------------------------------*/
  4624. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  4625. {
  4626. unsigned char buf[128];
  4627. nullpo_retv(bl);
  4628. WBUFW(buf,0) = 0x131;
  4629. WBUFL(buf,2) = bl->id;
  4630. safestrncpy((char*)WBUFP(buf,6), message, 80);
  4631. if( fd ) {
  4632. WFIFOHEAD(fd,packet_len(0x131));
  4633. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  4634. WFIFOSET(fd,packet_len(0x131));
  4635. } else {
  4636. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  4637. }
  4638. }
  4639. /*==========================================
  4640. * Removes a vending board from screen
  4641. *------------------------------------------*/
  4642. void clif_closevendingboard(struct block_list* bl, int fd)
  4643. {
  4644. unsigned char buf[16];
  4645. nullpo_retv(bl);
  4646. WBUFW(buf,0) = 0x132;
  4647. WBUFL(buf,2) = bl->id;
  4648. if( fd ) {
  4649. WFIFOHEAD(fd,packet_len(0x132));
  4650. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  4651. WFIFOSET(fd,packet_len(0x132));
  4652. } else {
  4653. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  4654. }
  4655. }
  4656. /*==========================================
  4657. * Sends a list of items in a shop
  4658. * R 0133 <len>.w <ID>.l {<value>.l <amount>.w <index>.w <type>.B <item ID>.w <identify flag>.B <attribute?>.B <refine>.B <card>.4w}.22B
  4659. *------------------------------------------*/
  4660. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  4661. {
  4662. int i,fd;
  4663. int count;
  4664. struct map_session_data* vsd;
  4665. nullpo_retv(sd);
  4666. nullpo_retv(vending);
  4667. nullpo_retv(vsd=map_id2sd(id));
  4668. fd = sd->fd;
  4669. count = vsd->vend_num;
  4670. WFIFOHEAD(fd, 8+count*22);
  4671. WFIFOW(fd,0) = 0x133;
  4672. WFIFOW(fd,2) = 8+count*22;
  4673. WFIFOL(fd,4) = id;
  4674. for( i = 0; i < count; i++ )
  4675. {
  4676. int index = vending[i].index;
  4677. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  4678. WFIFOL(fd, 8+i*22) = vending[i].value;
  4679. WFIFOW(fd,12+i*22) = vending[i].amount;
  4680. WFIFOW(fd,14+i*22) = vending[i].index + 2;
  4681. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4682. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  4683. WFIFOB(fd,19+i*22) = vsd->status.cart[index].identify;
  4684. WFIFOB(fd,20+i*22) = vsd->status.cart[index].attribute;
  4685. WFIFOB(fd,21+i*22) = vsd->status.cart[index].refine;
  4686. clif_addcards(WFIFOP(fd, 22+i*22), &vsd->status.cart[index]);
  4687. }
  4688. WFIFOSET(fd,WFIFOW(fd,2));
  4689. }
  4690. /*==========================================
  4691. * Shop purchase failure
  4692. * R 0135 <index>.w <amount>.w <fail>.B
  4693. * fail=1 - not enough zeny
  4694. * fail=2 - overweight
  4695. * fail=4 - out of stock
  4696. * fail=5 - "cannot use an npc shop while in a trade"
  4697. *------------------------------------------*/
  4698. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  4699. {
  4700. int fd;
  4701. nullpo_retv(sd);
  4702. fd = sd->fd;
  4703. WFIFOHEAD(fd,packet_len(0x135));
  4704. WFIFOW(fd,0) = 0x135;
  4705. WFIFOW(fd,2) = index+2;
  4706. WFIFOW(fd,4) = amount;
  4707. WFIFOB(fd,6) = fail;
  4708. WFIFOSET(fd,packet_len(0x135));
  4709. }
  4710. /*==========================================
  4711. * Shop creation success
  4712. * R 0136 <len>.w <ID>.l {<value>.l <index>.w <amount>.w <type>.B <item ID>.w <identify flag>.B <attribute?>.B <refine>.B <card>.4w}.22B*
  4713. *------------------------------------------*/
  4714. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  4715. {
  4716. int i,fd;
  4717. int count;
  4718. nullpo_retv(sd);
  4719. fd = sd->fd;
  4720. count = sd->vend_num;
  4721. WFIFOHEAD(fd, 8+count*22);
  4722. WFIFOW(fd,0) = 0x136;
  4723. WFIFOW(fd,2) = 8+count*22;
  4724. WFIFOL(fd,4) = id;
  4725. for( i = 0; i < count; i++ )
  4726. {
  4727. int index = vending[i].index;
  4728. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  4729. WFIFOL(fd, 8+i*22) = vending[i].value;
  4730. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  4731. WFIFOW(fd,14+i*22) = vending[i].amount;
  4732. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4733. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  4734. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  4735. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  4736. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  4737. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  4738. }
  4739. WFIFOSET(fd,WFIFOW(fd,2));
  4740. }
  4741. /*==========================================
  4742. * Inform merchant that someone has bought an item.
  4743. * R 0137 <index>.w <amount>.w
  4744. *------------------------------------------*/
  4745. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  4746. {
  4747. int fd;
  4748. nullpo_retv(sd);
  4749. fd = sd->fd;
  4750. WFIFOHEAD(fd,packet_len(0x137));
  4751. WFIFOW(fd,0) = 0x137;
  4752. WFIFOW(fd,2) = index+2;
  4753. WFIFOW(fd,4) = amount;
  4754. WFIFOSET(fd,packet_len(0x137));
  4755. }
  4756. /// Result of organizing a party.
  4757. /// R 00FA <result>.B
  4758. ///
  4759. /// result=0 : opens party window and shows MsgStringTable[77]="party successfully organized"
  4760. /// result=1 : MsgStringTable[78]="party name already exists"
  4761. /// result=2 : MsgStringTable[79]="already in a party"
  4762. /// result=other : nothing
  4763. int clif_party_created(struct map_session_data *sd,int result)
  4764. {
  4765. int fd;
  4766. nullpo_retr(0, sd);
  4767. fd=sd->fd;
  4768. WFIFOHEAD(fd,packet_len(0xfa));
  4769. WFIFOW(fd,0)=0xfa;
  4770. WFIFOB(fd,2)=result;
  4771. WFIFOSET(fd,packet_len(0xfa));
  4772. return 0;
  4773. }
  4774. int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  4775. {
  4776. unsigned char buf[96];
  4777. int i;
  4778. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  4779. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  4780. } else {
  4781. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  4782. }
  4783. if (i >= MAX_PARTY) return 0; //Should never happen...
  4784. sd = p->data[i].sd;
  4785. WBUFW(buf, 0) = 0x1e9;
  4786. WBUFL(buf, 2) = sd->status.account_id;
  4787. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  4788. WBUFW(buf,10) = sd->bl.x;
  4789. WBUFW(buf,12) = sd->bl.y;
  4790. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  4791. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  4792. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  4793. mapindex_getmapname_ext(mapindex_id2name(sd->mapindex), (char*)WBUFP(buf,63));
  4794. WBUFB(buf,79) = (p->party.item&1)?1:0;
  4795. WBUFB(buf,80) = (p->party.item&2)?1:0;
  4796. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  4797. return 1;
  4798. }
  4799. /*==========================================
  4800. * Sends party information
  4801. * R 00fb <len>.w <party name>.24B {<ID>.l <nick>.24B <map name>.16B <leader>.B <offline>.B}.46B*
  4802. *------------------------------------------*/
  4803. int clif_party_info(struct party_data* p, struct map_session_data *sd)
  4804. {
  4805. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  4806. struct map_session_data* party_sd = NULL;
  4807. int i, c;
  4808. nullpo_retr(0, p);
  4809. WBUFW(buf,0) = 0xfb;
  4810. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  4811. for(i = 0, c = 0; i < MAX_PARTY; i++)
  4812. {
  4813. struct party_member* m = &p->party.member[i];
  4814. if(!m->account_id) continue;
  4815. if(party_sd == NULL) party_sd = p->data[i].sd;
  4816. WBUFL(buf,28+c*46) = m->account_id;
  4817. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  4818. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  4819. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  4820. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  4821. c++;
  4822. }
  4823. WBUFW(buf,2) = 28+c*46;
  4824. if(sd) { // send only to self
  4825. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  4826. } else if (party_sd) { // send to whole party
  4827. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  4828. }
  4829. return 0;
  4830. }
  4831. /*==========================================
  4832. * The player's 'party invite' state, sent during login
  4833. * R 02c9 <flag>.B
  4834. *------------------------------------------*/
  4835. void clif_partyinvitationstate(struct map_session_data* sd)
  4836. {
  4837. int fd;
  4838. nullpo_retv(sd);
  4839. fd = sd->fd;
  4840. WFIFOHEAD(fd, packet_len(0x2c9));
  4841. WFIFOW(fd, 0) = 0x2c9;
  4842. WFIFOB(fd, 2) = 0; // not implemented
  4843. WFIFOSET(fd, packet_len(0x2c9));
  4844. }
  4845. /*==========================================
  4846. * パーティ勧誘
  4847. *------------------------------------------*/
  4848. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  4849. {
  4850. int fd;
  4851. struct party_data *p;
  4852. nullpo_retr(0, sd);
  4853. nullpo_retr(0, tsd);
  4854. fd=tsd->fd;
  4855. if( (p=party_search(sd->status.party_id))==NULL )
  4856. return 0;
  4857. WFIFOHEAD(fd,packet_len(0xfe));
  4858. WFIFOW(fd,0)=0xfe;
  4859. WFIFOL(fd,2)=sd->status.account_id;
  4860. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  4861. WFIFOSET(fd,packet_len(0xfe));
  4862. return 0;
  4863. }
  4864. /*==========================================
  4865. * Party invitation result.
  4866. * R 00fd <nick>.24S <flag>.B
  4867. * R 02c5 <nick>.24S <flag>.L
  4868. * Flag values are:
  4869. * 0 -> char is already in a party
  4870. * 1 -> party invite was rejected
  4871. * 2 -> party invite was accepted
  4872. * 3 -> party is full
  4873. * 4 -> char of the same account already joined the party
  4874. *------------------------------------------*/
  4875. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int flag)
  4876. {
  4877. int fd;
  4878. nullpo_retv(sd);
  4879. fd=sd->fd;
  4880. #if PACKETVER < 20070821
  4881. WFIFOHEAD(fd,packet_len(0xfd));
  4882. WFIFOW(fd,0) = 0xfd;
  4883. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  4884. WFIFOB(fd,26) = flag;
  4885. WFIFOSET(fd,packet_len(0xfd));
  4886. #else
  4887. WFIFOHEAD(fd,packet_len(0x2c5));
  4888. WFIFOW(fd,0) = 0x2c5;
  4889. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  4890. WFIFOL(fd,26) = flag;
  4891. WFIFOSET(fd,packet_len(0x2c5));
  4892. #endif
  4893. }
  4894. /*==========================================
  4895. * パーティ設定送信
  4896. * flag & 0x001=exp変更ミス
  4897. * 0x010=item変更ミス
  4898. * 0x100=一人にのみ送信
  4899. *------------------------------------------*/
  4900. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  4901. {
  4902. unsigned char buf[16];
  4903. nullpo_retr(0, p);
  4904. if(!sd && flag==0){
  4905. int i;
  4906. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4907. if (i < MAX_PARTY)
  4908. sd = p->data[i].sd;
  4909. }
  4910. if(!sd) return 0;
  4911. WBUFW(buf,0)=0x101;
  4912. // WBUFL(buf,2) // that's how the client reads it, still need to check it's uses [FlavioJS]
  4913. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  4914. WBUFW(buf,4)=0;
  4915. if(flag==0)
  4916. clif_send(buf,packet_len(0x101),&sd->bl,PARTY);
  4917. else
  4918. clif_send(buf,packet_len(0x101),&sd->bl,SELF);
  4919. return 0;
  4920. }
  4921. /*==========================================
  4922. * パーティ脱退(脱退前に呼ぶこと)
  4923. *------------------------------------------*/
  4924. int clif_party_leaved(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  4925. {
  4926. unsigned char buf[64];
  4927. int i;
  4928. nullpo_retr(0, p);
  4929. if(!sd && (flag&0xf0)==0)
  4930. {
  4931. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4932. if (i < MAX_PARTY)
  4933. sd = p->data[i].sd;
  4934. }
  4935. if(!sd) return 0;
  4936. WBUFW(buf,0)=0x105;
  4937. WBUFL(buf,2)=account_id;
  4938. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  4939. WBUFB(buf,30)=flag&0x0f;
  4940. if((flag&0xf0)==0)
  4941. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  4942. else
  4943. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  4944. return 0;
  4945. }
  4946. /*==========================================
  4947. * パーティメッセージ送信
  4948. *------------------------------------------*/
  4949. int clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  4950. {
  4951. struct map_session_data *sd;
  4952. int i;
  4953. nullpo_retr(0, p);
  4954. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  4955. if(i < MAX_PARTY){
  4956. unsigned char buf[1024];
  4957. sd = p->data[i].sd;
  4958. WBUFW(buf,0)=0x109;
  4959. WBUFW(buf,2)=len+8;
  4960. WBUFL(buf,4)=account_id;
  4961. memcpy(WBUFP(buf,8),mes,len);
  4962. clif_send(buf,len+8,&sd->bl,PARTY);
  4963. }
  4964. return 0;
  4965. }
  4966. /*==========================================
  4967. * パーティ座標通知
  4968. *------------------------------------------*/
  4969. int clif_party_xy(struct map_session_data *sd)
  4970. {
  4971. unsigned char buf[16];
  4972. nullpo_retr(0, sd);
  4973. WBUFW(buf,0)=0x107;
  4974. WBUFL(buf,2)=sd->status.account_id;
  4975. WBUFW(buf,6)=sd->bl.x;
  4976. WBUFW(buf,8)=sd->bl.y;
  4977. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  4978. return 0;
  4979. }
  4980. /*==========================================
  4981. * Sends x/y dot to a single fd. [Skotlex]
  4982. *------------------------------------------*/
  4983. int clif_party_xy_single(int fd, struct map_session_data *sd)
  4984. {
  4985. WFIFOHEAD(fd,packet_len(0x107));
  4986. WFIFOW(fd,0)=0x107;
  4987. WFIFOL(fd,2)=sd->status.account_id;
  4988. WFIFOW(fd,6)=sd->bl.x;
  4989. WFIFOW(fd,8)=sd->bl.y;
  4990. WFIFOSET(fd,packet_len(0x107));
  4991. return 0;
  4992. }
  4993. /*==========================================
  4994. * パーティHP通知
  4995. *------------------------------------------*/
  4996. int clif_party_hp(struct map_session_data *sd)
  4997. {
  4998. unsigned char buf[16];
  4999. nullpo_retr(0, sd);
  5000. WBUFW(buf,0)=0x106;
  5001. WBUFL(buf,2)=sd->status.account_id;
  5002. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5003. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5004. WBUFW(buf,8) = 100;
  5005. } else {
  5006. WBUFW(buf,6) = sd->battle_status.hp;
  5007. WBUFW(buf,8) = sd->battle_status.max_hp;
  5008. }
  5009. clif_send(buf,packet_len(0x106),&sd->bl,PARTY_AREA_WOS);
  5010. return 0;
  5011. }
  5012. /*==========================================
  5013. * Sends HP bar to a single fd. [Skotlex]
  5014. *------------------------------------------*/
  5015. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  5016. {
  5017. WFIFOHEAD(fd,packet_len(0x106));
  5018. WFIFOW(fd,0) = 0x106;
  5019. WFIFOL(fd,2) = id;
  5020. if( maxhp > SHRT_MAX )
  5021. {// To correctly display the %hp bar. [Skotlex]
  5022. WFIFOW(fd,6) = hp/(maxhp/100);
  5023. WFIFOW(fd,8) = 100;
  5024. } else {
  5025. WFIFOW(fd,6) = hp;
  5026. WFIFOW(fd,8) = maxhp;
  5027. }
  5028. WFIFOSET(fd, packet_len(0x106));
  5029. }
  5030. /*==========================================
  5031. * GMへ場所とHP通知
  5032. *------------------------------------------*/
  5033. int clif_hpmeter(struct map_session_data *sd)
  5034. {
  5035. struct map_session_data *sd2;
  5036. unsigned char buf[16];
  5037. int i, x0, y0, x1, y1;
  5038. int level;
  5039. nullpo_retr(0, sd);
  5040. x0 = sd->bl.x - AREA_SIZE;
  5041. y0 = sd->bl.y - AREA_SIZE;
  5042. x1 = sd->bl.x + AREA_SIZE;
  5043. y1 = sd->bl.y + AREA_SIZE;
  5044. WBUFW(buf,0) = 0x106;
  5045. WBUFL(buf,2) = sd->status.account_id;
  5046. if( sd->battle_status.max_hp > SHRT_MAX )
  5047. { //To correctly display the %hp bar. [Skotlex]
  5048. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5049. WBUFW(buf,8) = 100;
  5050. }
  5051. else
  5052. {
  5053. WBUFW(buf,6) = sd->battle_status.hp;
  5054. WBUFW(buf,8) = sd->battle_status.max_hp;
  5055. }
  5056. //TODO: replace with map_foreachinarea?
  5057. for( i = 0; i < fd_max; i++ )
  5058. {
  5059. if( session[i] && session[i]->func_parse == clif_parse && (sd2 = (struct map_session_data*)session[i]->session_data) && sd != sd2 && sd2->state.active )
  5060. {
  5061. if( sd2->bl.m != sd->bl.m || sd2->bl.x < x0 || sd2->bl.y < y0 || sd2->bl.x > x1 || sd2->bl.y > y1 )
  5062. continue; // Not in the Visual Area
  5063. if( battle_config.disp_hpmeter && (level = pc_isGM(sd2)) >= battle_config.disp_hpmeter && level >= pc_isGM(sd) )
  5064. {
  5065. WFIFOHEAD(i,packet_len(0x106));
  5066. memcpy(WFIFOP(i,0),buf,packet_len(0x106));
  5067. WFIFOSET(i,packet_len(0x106));
  5068. }
  5069. }
  5070. }
  5071. return 0;
  5072. }
  5073. /*==========================================
  5074. * パーティ場所移動(未使用)
  5075. *------------------------------------------*/
  5076. void clif_party_move(struct party* p, struct map_session_data* sd, int online)
  5077. {
  5078. unsigned char buf[128];
  5079. nullpo_retv(sd);
  5080. nullpo_retv(p);
  5081. WBUFW(buf, 0) = 0x104;
  5082. WBUFL(buf, 2) = sd->status.account_id;
  5083. WBUFL(buf, 6) = 0;
  5084. WBUFW(buf,10) = sd->bl.x;
  5085. WBUFW(buf,12) = sd->bl.y;
  5086. WBUFB(buf,14) = !online;
  5087. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  5088. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  5089. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  5090. clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
  5091. }
  5092. /*==========================================
  5093. * 攻撃するために移動が必要
  5094. *------------------------------------------*/
  5095. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5096. {
  5097. int fd;
  5098. nullpo_retr(0, sd);
  5099. nullpo_retr(0, bl);
  5100. fd=sd->fd;
  5101. WFIFOHEAD(fd,packet_len(0x139));
  5102. WFIFOW(fd, 0)=0x139;
  5103. WFIFOL(fd, 2)=bl->id;
  5104. WFIFOW(fd, 6)=bl->x;
  5105. WFIFOW(fd, 8)=bl->y;
  5106. WFIFOW(fd,10)=sd->bl.x;
  5107. WFIFOW(fd,12)=sd->bl.y;
  5108. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5109. WFIFOSET(fd,packet_len(0x139));
  5110. return 0;
  5111. }
  5112. /*==========================================
  5113. * 製造エフェクト
  5114. *------------------------------------------*/
  5115. int clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  5116. {
  5117. int view,fd;
  5118. nullpo_retr(0, sd);
  5119. fd = sd->fd;
  5120. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  5121. WFIFOHEAD(fd,packet_len(0x18f));
  5122. WFIFOW(fd, 0)=0x18f;
  5123. WFIFOW(fd, 2)=flag;
  5124. if((view = itemdb_viewid(nameid)) > 0)
  5125. WFIFOW(fd, 4)=view;
  5126. else
  5127. WFIFOW(fd, 4)=nameid;
  5128. WFIFOSET(fd,packet_len(0x18f));
  5129. return 0;
  5130. }
  5131. // pet
  5132. int clif_catch_process(struct map_session_data *sd)
  5133. {
  5134. int fd;
  5135. nullpo_retr(0, sd);
  5136. fd=sd->fd;
  5137. WFIFOHEAD(fd,packet_len(0x19e));
  5138. WFIFOW(fd,0)=0x19e;
  5139. WFIFOSET(fd,packet_len(0x19e));
  5140. return 0;
  5141. }
  5142. int clif_pet_roulette(struct map_session_data *sd,int data)
  5143. {
  5144. int fd;
  5145. nullpo_retr(0, sd);
  5146. fd=sd->fd;
  5147. WFIFOHEAD(fd,packet_len(0x1a0));
  5148. WFIFOW(fd,0)=0x1a0;
  5149. WFIFOB(fd,2)=data;
  5150. WFIFOSET(fd,packet_len(0x1a0));
  5151. return 0;
  5152. }
  5153. /*==========================================
  5154. * pet卵リスト作成
  5155. *------------------------------------------*/
  5156. int clif_sendegg(struct map_session_data *sd)
  5157. {
  5158. //R 01a6 <len>.w <index>.w*
  5159. int i,n=0,fd;
  5160. nullpo_retr(0, sd);
  5161. fd=sd->fd;
  5162. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5163. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5164. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5165. return 0;
  5166. }
  5167. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5168. WFIFOW(fd,0)=0x1a6;
  5169. if(sd->status.pet_id <= 0) {
  5170. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5171. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5172. sd->inventory_data[i]->type!=IT_PETEGG ||
  5173. sd->status.inventory[i].amount<=0)
  5174. continue;
  5175. WFIFOW(fd,n*2+4)=i+2;
  5176. n++;
  5177. }
  5178. }
  5179. WFIFOW(fd,2)=4+n*2;
  5180. WFIFOSET(fd,WFIFOW(fd,2));
  5181. sd->menuskill_id = SA_TAMINGMONSTER;
  5182. sd->menuskill_val = -1;
  5183. return 0;
  5184. }
  5185. /*==========================================
  5186. * Sends a specific pet data update.
  5187. * type = 0 -> param = 0 (initial data)
  5188. * type = 1 -> param = intimacy value
  5189. * type = 2 -> param = hungry value
  5190. * type = 3 -> param = accessory id
  5191. * type = 4 -> param = performance number (1-3:normal, 4:special)
  5192. * type = 5 -> param = hairstyle number
  5193. * If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5194. *------------------------------------------*/
  5195. int clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5196. {
  5197. uint8 buf[16];
  5198. nullpo_retr(0, pd);
  5199. WBUFW(buf,0) = 0x1a4;
  5200. WBUFB(buf,2) = type;
  5201. WBUFL(buf,3) = pd->bl.id;
  5202. WBUFL(buf,7) = param;
  5203. if (sd)
  5204. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5205. else
  5206. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5207. return 0;
  5208. }
  5209. int clif_send_petstatus(struct map_session_data *sd)
  5210. {
  5211. int fd;
  5212. struct s_pet *pet;
  5213. nullpo_retr(0, sd);
  5214. nullpo_retr(0, sd->pd);
  5215. fd=sd->fd;
  5216. pet = &sd->pd->pet;
  5217. WFIFOHEAD(fd,packet_len(0x1a2));
  5218. WFIFOW(fd,0)=0x1a2;
  5219. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5220. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5221. WFIFOW(fd,27)=pet->level;
  5222. WFIFOW(fd,29)=pet->hungry;
  5223. WFIFOW(fd,31)=pet->intimate;
  5224. WFIFOW(fd,33)=pet->equip;
  5225. #if PACKETVER >= 20081126
  5226. WFIFOW(fd,35)=pet->class_;
  5227. #endif
  5228. WFIFOSET(fd,packet_len(0x1a2));
  5229. return 0;
  5230. }
  5231. /*==========================================
  5232. *
  5233. *------------------------------------------*/
  5234. int clif_pet_emotion(struct pet_data *pd,int param)
  5235. {
  5236. unsigned char buf[16];
  5237. nullpo_retr(0, pd);
  5238. memset(buf,0,packet_len(0x1aa));
  5239. WBUFW(buf,0)=0x1aa;
  5240. WBUFL(buf,2)=pd->bl.id;
  5241. if(param >= 100 && pd->petDB->talk_convert_class) {
  5242. if(pd->petDB->talk_convert_class < 0)
  5243. return 0;
  5244. else if(pd->petDB->talk_convert_class > 0) {
  5245. param -= (pd->pet.class_ - 100)*100;
  5246. param += (pd->petDB->talk_convert_class - 100)*100;
  5247. }
  5248. }
  5249. WBUFL(buf,6)=param;
  5250. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5251. return 0;
  5252. }
  5253. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5254. {
  5255. int fd;
  5256. nullpo_retr(0, sd);
  5257. fd=sd->fd;
  5258. WFIFOHEAD(fd,packet_len(0x1a3));
  5259. WFIFOW(fd,0)=0x1a3;
  5260. WFIFOB(fd,2)=fail;
  5261. WFIFOW(fd,3)=foodid;
  5262. WFIFOSET(fd,packet_len(0x1a3));
  5263. return 0;
  5264. }
  5265. /*==========================================
  5266. * オートスペル リスト送信
  5267. *------------------------------------------*/
  5268. int clif_autospell(struct map_session_data *sd,int skilllv)
  5269. {
  5270. int fd;
  5271. nullpo_retr(0, sd);
  5272. fd=sd->fd;
  5273. WFIFOHEAD(fd,packet_len(0x1cd));
  5274. WFIFOW(fd, 0)=0x1cd;
  5275. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5276. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5277. else
  5278. WFIFOL(fd,2)= 0x00000000;
  5279. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5280. WFIFOL(fd,6)= MG_COLDBOLT;
  5281. else
  5282. WFIFOL(fd,6)= 0x00000000;
  5283. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5284. WFIFOL(fd,10)= MG_FIREBOLT;
  5285. else
  5286. WFIFOL(fd,10)= 0x00000000;
  5287. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5288. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5289. else
  5290. WFIFOL(fd,14)= 0x00000000;
  5291. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5292. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5293. else
  5294. WFIFOL(fd,18)= 0x00000000;
  5295. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5296. WFIFOL(fd,22)= MG_FIREBALL;
  5297. else
  5298. WFIFOL(fd,22)= 0x00000000;
  5299. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5300. WFIFOL(fd,26)= MG_FROSTDIVER;
  5301. else
  5302. WFIFOL(fd,26)= 0x00000000;
  5303. WFIFOSET(fd,packet_len(0x1cd));
  5304. sd->menuskill_id = SA_AUTOSPELL;
  5305. sd->menuskill_val = skilllv;
  5306. return 0;
  5307. }
  5308. /*==========================================
  5309. * Devotion's visual effect
  5310. * S 01cf <devoter id>.L { <devotee id>.L }[5] <max distance>.W
  5311. *------------------------------------------*/
  5312. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  5313. {
  5314. unsigned char buf[56];
  5315. int i;
  5316. nullpo_retv(src);
  5317. memset(buf,0,packet_len(0x1cf));
  5318. WBUFW(buf,0) = 0x1cf;
  5319. WBUFL(buf,2) = src->id;
  5320. if( src->type == BL_MER )
  5321. {
  5322. struct mercenary_data *md = BL_CAST(BL_MER,src);
  5323. if( md && md->master && md->devotion_flag )
  5324. WBUFL(buf,6) = md->master->bl.id;
  5325. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  5326. }
  5327. else
  5328. {
  5329. struct map_session_data *sd = BL_CAST(BL_PC,src);
  5330. if( sd == NULL )
  5331. return;
  5332. for( i = 0; i < 5; i++ )
  5333. WBUFL(buf,6+4*i) = sd->devotion[i];
  5334. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  5335. }
  5336. if( tsd )
  5337. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  5338. else
  5339. clif_send(buf, packet_len(0x1cf), src, AREA);
  5340. }
  5341. /*==========================================
  5342. * 氣球
  5343. *------------------------------------------*/
  5344. int clif_spiritball(struct map_session_data *sd)
  5345. {
  5346. unsigned char buf[16];
  5347. nullpo_retr(0, sd);
  5348. WBUFW(buf,0)=0x1d0;
  5349. WBUFL(buf,2)=sd->bl.id;
  5350. WBUFW(buf,6)=sd->spiritball;
  5351. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5352. return 0;
  5353. }
  5354. /*==========================================
  5355. *
  5356. *------------------------------------------*/
  5357. int clif_combo_delay(struct block_list *bl,int wait)
  5358. {
  5359. unsigned char buf[32];
  5360. nullpo_retr(0, bl);
  5361. WBUFW(buf,0)=0x1d2;
  5362. WBUFL(buf,2)=bl->id;
  5363. WBUFL(buf,6)=wait;
  5364. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5365. return 0;
  5366. }
  5367. /*==========================================
  5368. *白刃取り
  5369. *------------------------------------------*/
  5370. void clif_bladestop(struct block_list *src, int dst_id, int active)
  5371. {
  5372. unsigned char buf[32];
  5373. nullpo_retv(src);
  5374. WBUFW(buf,0)=0x1d1;
  5375. WBUFL(buf,2)=src->id;
  5376. WBUFL(buf,6)=dst_id;
  5377. WBUFL(buf,10)=active;
  5378. clif_send(buf,packet_len(0x1d1),src,AREA);
  5379. }
  5380. /*==========================================
  5381. * MVPエフェクト
  5382. *------------------------------------------*/
  5383. int clif_mvp_effect(struct map_session_data *sd)
  5384. {
  5385. unsigned char buf[16];
  5386. nullpo_retr(0, sd);
  5387. WBUFW(buf,0)=0x10c;
  5388. WBUFL(buf,2)=sd->bl.id;
  5389. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5390. return 0;
  5391. }
  5392. /*==========================================
  5393. * MVPアイテム所得
  5394. *------------------------------------------*/
  5395. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5396. {
  5397. int view,fd;
  5398. nullpo_retr(0, sd);
  5399. fd=sd->fd;
  5400. WFIFOHEAD(fd,packet_len(0x10a));
  5401. WFIFOW(fd,0)=0x10a;
  5402. if((view = itemdb_viewid(nameid)) > 0)
  5403. WFIFOW(fd,2)=view;
  5404. else
  5405. WFIFOW(fd,2)=nameid;
  5406. WFIFOSET(fd,packet_len(0x10a));
  5407. return 0;
  5408. }
  5409. /*==========================================
  5410. * MVP経験値所得
  5411. *------------------------------------------*/
  5412. int clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  5413. {
  5414. int fd;
  5415. nullpo_retr(0, sd);
  5416. fd=sd->fd;
  5417. WFIFOHEAD(fd,packet_len(0x10b));
  5418. WFIFOW(fd,0)=0x10b;
  5419. WFIFOL(fd,2)=cap_value(exp,0,INT_MAX);
  5420. WFIFOSET(fd,packet_len(0x10b));
  5421. return 0;
  5422. }
  5423. /*==========================================
  5424. * Guild creation result
  5425. * R 0167 <flag>.B
  5426. * flag = 0 -> "Guild has been created."
  5427. * flag = 1 -> "You are already in a Guild."
  5428. * flag = 2 -> "That Guild Name already exists."
  5429. * flag = 3 -> "You need the neccessary item to create a Guild."
  5430. *------------------------------------------*/
  5431. int clif_guild_created(struct map_session_data *sd,int flag)
  5432. {
  5433. int fd;
  5434. nullpo_retr(0, sd);
  5435. fd=sd->fd;
  5436. WFIFOHEAD(fd,packet_len(0x167));
  5437. WFIFOW(fd,0)=0x167;
  5438. WFIFOB(fd,2)=flag;
  5439. WFIFOSET(fd,packet_len(0x167));
  5440. return 0;
  5441. }
  5442. /*==========================================
  5443. * ギルド所属通知
  5444. *------------------------------------------*/
  5445. int clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  5446. {
  5447. int ps,fd;
  5448. nullpo_retr(0, sd);
  5449. nullpo_retr(0, g);
  5450. fd=sd->fd;
  5451. ps=guild_getposition(g,sd);
  5452. WFIFOHEAD(fd,packet_len(0x16c));
  5453. memset(WFIFOP(fd,0),0,packet_len(0x16c));
  5454. WFIFOW(fd,0)=0x16c;
  5455. WFIFOL(fd,2)=g->guild_id;
  5456. WFIFOL(fd,6)=g->emblem_id;
  5457. WFIFOL(fd,10)=g->position[ps].mode;
  5458. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5459. WFIFOSET(fd,packet_len(0x16c));
  5460. return 0;
  5461. }
  5462. /*==========================================
  5463. * ギルドメンバログイン通知
  5464. *------------------------------------------*/
  5465. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5466. {
  5467. unsigned char buf[64];
  5468. nullpo_retr(0, g);
  5469. WBUFW(buf, 0)=0x16d;
  5470. WBUFL(buf, 2)=g->member[idx].account_id;
  5471. WBUFL(buf, 6)=g->member[idx].char_id;
  5472. WBUFL(buf,10)=flag;
  5473. if(g->member[idx].sd==NULL){
  5474. struct map_session_data *sd=guild_getavailablesd(g);
  5475. if(sd!=NULL)
  5476. clif_send(buf,packet_len(0x16d),&sd->bl,GUILD);
  5477. }else
  5478. clif_send(buf,packet_len(0x16d),&g->member[idx].sd->bl,GUILD_WOS);
  5479. return 0;
  5480. }
  5481. // Function `clif_guild_memberlogin_notice` sends info about
  5482. // logins and logouts of a guild member to the rest members.
  5483. // But at the 1st time (after a player login or map changing)
  5484. // the client won't show the message.
  5485. // So I suggest use this function for sending "first-time-info"
  5486. // to some player on entering the game or changing location.
  5487. // At next time the client would always show the message.
  5488. // The function sends all the statuses in the single packet
  5489. // to economize traffic. [LuzZza]
  5490. int clif_guild_send_onlineinfo(struct map_session_data *sd)
  5491. {
  5492. struct guild *g;
  5493. unsigned char buf[14*128];
  5494. int i, count=0, p_len;
  5495. nullpo_retr(0, sd);
  5496. p_len = packet_len(0x16d);
  5497. if(!(g = guild_search(sd->status.guild_id)))
  5498. return 0;
  5499. for(i=0; i<g->max_member; i++) {
  5500. if(g->member[i].account_id > 0 &&
  5501. g->member[i].account_id != sd->status.account_id) {
  5502. WBUFW(buf,count*p_len) = 0x16d;
  5503. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5504. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5505. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5506. count++;
  5507. }
  5508. }
  5509. clif_send(buf, p_len*count, &sd->bl, SELF);
  5510. return 0;
  5511. }
  5512. /*==========================================
  5513. * ギルドマスター通知(14dへの応答)
  5514. *------------------------------------------*/
  5515. int clif_guild_masterormember(struct map_session_data *sd)
  5516. {
  5517. int fd;
  5518. nullpo_retr(0, sd);
  5519. fd=sd->fd;
  5520. WFIFOHEAD(fd,packet_len(0x14e));
  5521. WFIFOW(fd,0) = 0x14e;
  5522. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  5523. WFIFOSET(fd,packet_len(0x14e));
  5524. return 0;
  5525. }
  5526. /*==========================================
  5527. * Basic Info (Territories [Valaris])
  5528. *------------------------------------------*/
  5529. int clif_guild_basicinfo(struct map_session_data *sd)
  5530. {
  5531. int fd,i,t;
  5532. struct guild *g;
  5533. struct guild_castle *gc = NULL;
  5534. nullpo_retr(0, sd);
  5535. fd = sd->fd;
  5536. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5537. return 0;
  5538. WFIFOHEAD(fd,packet_len(0x1b6));
  5539. WFIFOW(fd, 0)=0x1b6;//0x150;
  5540. WFIFOL(fd, 2)=g->guild_id;
  5541. WFIFOL(fd, 6)=g->guild_lv;
  5542. WFIFOL(fd,10)=g->connect_member;
  5543. WFIFOL(fd,14)=g->max_member;
  5544. WFIFOL(fd,18)=g->average_lv;
  5545. WFIFOL(fd,22)=g->exp;
  5546. WFIFOL(fd,26)=g->next_exp;
  5547. WFIFOL(fd,30)=0; // Tax Points
  5548. WFIFOL(fd,34)=0; // Tendency: (left) Vulgar [-100,100] Famed (right)
  5549. WFIFOL(fd,38)=0; // Tendency: (down) Wicked [-100,100] Righteous (up)
  5550. WFIFOL(fd,42)=g->emblem_id;
  5551. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5552. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5553. for(i = 0, t = 0; i < MAX_GUILDCASTLE; i++)
  5554. {
  5555. gc = guild_castle_search(i);
  5556. if(gc && g->guild_id == gc->guild_id)
  5557. t++;
  5558. }
  5559. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20); // "'N' castles"
  5560. WFIFOSET(fd,packet_len(WFIFOW(fd,0)));
  5561. return 0;
  5562. }
  5563. /*==========================================
  5564. * ギルド同盟/敵対情報
  5565. *------------------------------------------*/
  5566. int clif_guild_allianceinfo(struct map_session_data *sd)
  5567. {
  5568. int fd,i,c;
  5569. struct guild *g;
  5570. nullpo_retr(0, sd);
  5571. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5572. return 0;
  5573. fd = sd->fd;
  5574. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5575. WFIFOW(fd, 0)=0x14c;
  5576. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5577. struct guild_alliance *a=&g->alliance[i];
  5578. if(a->guild_id>0){
  5579. WFIFOL(fd,c*32+4)=a->opposition;
  5580. WFIFOL(fd,c*32+8)=a->guild_id;
  5581. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5582. c++;
  5583. }
  5584. }
  5585. WFIFOW(fd, 2)=c*32+4;
  5586. WFIFOSET(fd,WFIFOW(fd,2));
  5587. return 0;
  5588. }
  5589. /*==========================================
  5590. * ギルドメンバーリスト
  5591. *------------------------------------------*/
  5592. int clif_guild_memberlist(struct map_session_data *sd)
  5593. {
  5594. int fd;
  5595. int i,c;
  5596. struct guild *g;
  5597. nullpo_retr(0, sd);
  5598. if( (fd = sd->fd) == 0 )
  5599. return 0;
  5600. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5601. return 0;
  5602. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5603. WFIFOW(fd, 0)=0x154;
  5604. for(i=0,c=0;i<g->max_member;i++){
  5605. struct guild_member *m=&g->member[i];
  5606. if(m->account_id==0)
  5607. continue;
  5608. WFIFOL(fd,c*104+ 4)=m->account_id;
  5609. WFIFOL(fd,c*104+ 8)=m->char_id;
  5610. WFIFOW(fd,c*104+12)=m->hair;
  5611. WFIFOW(fd,c*104+14)=m->hair_color;
  5612. WFIFOW(fd,c*104+16)=m->gender;
  5613. WFIFOW(fd,c*104+18)=m->class_;
  5614. WFIFOW(fd,c*104+20)=m->lv;
  5615. WFIFOL(fd,c*104+22)=m->exp;
  5616. WFIFOL(fd,c*104+26)=m->online;
  5617. WFIFOL(fd,c*104+30)=m->position;
  5618. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5619. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5620. c++;
  5621. }
  5622. WFIFOW(fd, 2)=c*104+4;
  5623. WFIFOSET(fd,WFIFOW(fd,2));
  5624. return 0;
  5625. }
  5626. /*==========================================
  5627. * ギルド役職名リスト
  5628. *------------------------------------------*/
  5629. int clif_guild_positionnamelist(struct map_session_data *sd)
  5630. {
  5631. int i,fd;
  5632. struct guild *g;
  5633. nullpo_retr(0, sd);
  5634. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5635. return 0;
  5636. fd = sd->fd;
  5637. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5638. WFIFOW(fd, 0)=0x166;
  5639. for(i=0;i<MAX_GUILDPOSITION;i++){
  5640. WFIFOL(fd,i*28+4)=i;
  5641. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5642. }
  5643. WFIFOW(fd,2)=i*28+4;
  5644. WFIFOSET(fd,WFIFOW(fd,2));
  5645. return 0;
  5646. }
  5647. /*==========================================
  5648. * ギルド役職情報リスト
  5649. *------------------------------------------*/
  5650. int clif_guild_positioninfolist(struct map_session_data *sd)
  5651. {
  5652. int i,fd;
  5653. struct guild *g;
  5654. nullpo_retr(0, sd);
  5655. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5656. return 0;
  5657. fd = sd->fd;
  5658. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5659. WFIFOW(fd, 0)=0x160;
  5660. for(i=0;i<MAX_GUILDPOSITION;i++){
  5661. struct guild_position *p=&g->position[i];
  5662. WFIFOL(fd,i*16+ 4)=i;
  5663. WFIFOL(fd,i*16+ 8)=p->mode;
  5664. WFIFOL(fd,i*16+12)=i;
  5665. WFIFOL(fd,i*16+16)=p->exp_mode;
  5666. }
  5667. WFIFOW(fd, 2)=i*16+4;
  5668. WFIFOSET(fd,WFIFOW(fd,2));
  5669. return 0;
  5670. }
  5671. /*==========================================
  5672. * ギルド役職変更通知
  5673. *------------------------------------------*/
  5674. int clif_guild_positionchanged(struct guild *g,int idx)
  5675. {
  5676. struct map_session_data *sd;
  5677. unsigned char buf[128];
  5678. nullpo_retr(0, g);
  5679. WBUFW(buf, 0)=0x174;
  5680. WBUFW(buf, 2)=44;
  5681. WBUFL(buf, 4)=idx;
  5682. WBUFL(buf, 8)=g->position[idx].mode;
  5683. WBUFL(buf,12)=idx;
  5684. WBUFL(buf,16)=g->position[idx].exp_mode;
  5685. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  5686. if( (sd=guild_getavailablesd(g))!=NULL )
  5687. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5688. return 0;
  5689. }
  5690. /*==========================================
  5691. * ギルドメンバ変更通知
  5692. *------------------------------------------*/
  5693. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  5694. {
  5695. struct map_session_data *sd;
  5696. unsigned char buf[64];
  5697. nullpo_retr(0, g);
  5698. WBUFW(buf, 0)=0x156;
  5699. WBUFW(buf, 2)=16;
  5700. WBUFL(buf, 4)=g->member[idx].account_id;
  5701. WBUFL(buf, 8)=g->member[idx].char_id;
  5702. WBUFL(buf,12)=g->member[idx].position;
  5703. if( (sd=guild_getavailablesd(g))!=NULL )
  5704. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5705. return 0;
  5706. }
  5707. /*==========================================
  5708. * ギルドエンブレム送信
  5709. *------------------------------------------*/
  5710. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  5711. {
  5712. int fd;
  5713. nullpo_retr(0, sd);
  5714. nullpo_retr(0, g);
  5715. fd = sd->fd;
  5716. if( g->emblem_len <= 0 )
  5717. return 0;
  5718. WFIFOHEAD(fd,g->emblem_len+12);
  5719. WFIFOW(fd,0)=0x152;
  5720. WFIFOW(fd,2)=g->emblem_len+12;
  5721. WFIFOL(fd,4)=g->guild_id;
  5722. WFIFOL(fd,8)=g->emblem_id;
  5723. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  5724. WFIFOSET(fd,WFIFOW(fd,2));
  5725. return 0;
  5726. }
  5727. /// Sends update of the guild id/emblem id to everyone in the area.
  5728. void clif_guild_emblem_area(struct block_list* bl)
  5729. {
  5730. uint8 buf[12];
  5731. nullpo_retv(bl);
  5732. // TODO this packet doesn't force the update of ui components that have the emblem visible
  5733. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  5734. WBUFW(buf,0) = 0x1B4;
  5735. WBUFL(buf,2) = bl->id;
  5736. WBUFL(buf,6) = status_get_guild_id(bl);
  5737. WBUFW(buf,10) = status_get_emblem_id(bl);
  5738. clif_send(buf, 12, bl, AREA_WOS);
  5739. }
  5740. /*==========================================
  5741. * Send guild skills
  5742. *------------------------------------------*/
  5743. int clif_guild_skillinfo(struct map_session_data* sd)
  5744. {
  5745. int fd;
  5746. struct guild* g;
  5747. int i,c;
  5748. nullpo_retr(0, sd);
  5749. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5750. return 0;
  5751. fd = sd->fd;
  5752. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  5753. WFIFOW(fd,0) = 0x0162;
  5754. WFIFOW(fd,4) = g->skill_point;
  5755. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  5756. {
  5757. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  5758. {
  5759. int id = g->skill[i].id;
  5760. int p = 6 + c*37;
  5761. WFIFOW(fd,p+0) = id;
  5762. WFIFOW(fd,p+2) = skill_get_inf(id);
  5763. WFIFOW(fd,p+4) = 0;
  5764. WFIFOW(fd,p+6) = g->skill[i].lv;
  5765. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  5766. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  5767. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  5768. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  5769. c++;
  5770. }
  5771. }
  5772. WFIFOW(fd,2) = 6 + c*37;
  5773. WFIFOSET(fd,WFIFOW(fd,2));
  5774. return 0;
  5775. }
  5776. /*==========================================
  5777. * Sends guild notice to client
  5778. * R 016f <str1z>.60B <str2z>.120B
  5779. *------------------------------------------*/
  5780. int clif_guild_notice(struct map_session_data* sd, struct guild* g)
  5781. {
  5782. int fd;
  5783. nullpo_retr(0, sd);
  5784. nullpo_retr(0, g);
  5785. fd = sd->fd;
  5786. if ( !session_isActive(fd) )
  5787. return 0;
  5788. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  5789. return 0;
  5790. WFIFOHEAD(fd,packet_len(0x16f));
  5791. WFIFOW(fd,0) = 0x16f;
  5792. memcpy(WFIFOP(fd,2), g->mes1, 60);
  5793. memcpy(WFIFOP(fd,62), g->mes2, 120);
  5794. WFIFOSET(fd,packet_len(0x16f));
  5795. return 0;
  5796. }
  5797. /*==========================================
  5798. * ギルドメンバ勧誘
  5799. *------------------------------------------*/
  5800. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  5801. {
  5802. int fd;
  5803. nullpo_retr(0, sd);
  5804. nullpo_retr(0, g);
  5805. fd=sd->fd;
  5806. WFIFOHEAD(fd,packet_len(0x16a));
  5807. WFIFOW(fd,0)=0x16a;
  5808. WFIFOL(fd,2)=g->guild_id;
  5809. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  5810. WFIFOSET(fd,packet_len(0x16a));
  5811. return 0;
  5812. }
  5813. /*==========================================
  5814. * ギルドメンバ勧誘結果
  5815. *------------------------------------------*/
  5816. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  5817. {
  5818. int fd;
  5819. nullpo_retr(0, sd);
  5820. fd=sd->fd;
  5821. WFIFOHEAD(fd,packet_len(0x169));
  5822. WFIFOW(fd,0)=0x169;
  5823. WFIFOB(fd,2)=flag;
  5824. WFIFOSET(fd,packet_len(0x169));
  5825. return 0;
  5826. }
  5827. /*==========================================
  5828. * ギルドメンバ脱退通知
  5829. *------------------------------------------*/
  5830. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  5831. {
  5832. unsigned char buf[128];
  5833. nullpo_retr(0, sd);
  5834. WBUFW(buf, 0)=0x15a;
  5835. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5836. memcpy(WBUFP(buf,26),mes,40);
  5837. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  5838. return 0;
  5839. }
  5840. /*==========================================
  5841. * ギルドメンバ追放通知
  5842. *------------------------------------------*/
  5843. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,int account_id)
  5844. {
  5845. unsigned char buf[128];
  5846. nullpo_retr(0, sd);
  5847. WBUFW(buf, 0)=0x15c;
  5848. safestrncpy((char*)WBUFP(buf, 2),name,NAME_LENGTH);
  5849. safestrncpy((char*)WBUFP(buf,26),mes,40);
  5850. safestrncpy((char*)WBUFP(buf,66),"",NAME_LENGTH); // account name (not used for security reasons)
  5851. clif_send(buf,packet_len(0x15c),&sd->bl,GUILD_NOBG);
  5852. return 0;
  5853. }
  5854. /*==========================================
  5855. * ギルド追放メンバリスト
  5856. *------------------------------------------*/
  5857. int clif_guild_expulsionlist(struct map_session_data *sd)
  5858. {
  5859. int fd;
  5860. int i,c;
  5861. struct guild *g;
  5862. nullpo_retr(0, sd);
  5863. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5864. return 0;
  5865. fd = sd->fd;
  5866. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * 88);
  5867. WFIFOW(fd,0)=0x163;
  5868. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  5869. struct guild_expulsion *e=&g->expulsion[i];
  5870. if(e->account_id>0){
  5871. safestrncpy((char*)WFIFOP(fd,4 + c*88),e->name,NAME_LENGTH);
  5872. safestrncpy((char*)WFIFOP(fd,4 + c*88+24),"",24); // account name (not used for security reasons)
  5873. safestrncpy((char*)WFIFOP(fd,4 + c*88+48),e->mes,40);
  5874. c++;
  5875. }
  5876. }
  5877. WFIFOW(fd,2) = 4 + c*88;
  5878. WFIFOSET(fd,WFIFOW(fd,2));
  5879. return 0;
  5880. }
  5881. /*==========================================
  5882. * ギルド会話
  5883. *------------------------------------------*/
  5884. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  5885. {
  5886. struct map_session_data *sd;
  5887. unsigned char *buf;
  5888. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  5889. WBUFW(buf, 0) = 0x17f;
  5890. WBUFW(buf, 2) = len + 4;
  5891. memcpy(WBUFP(buf,4), mes, len);
  5892. if ((sd = guild_getavailablesd(g)) != NULL)
  5893. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  5894. if(buf) aFree(buf);
  5895. return 0;
  5896. }
  5897. /*==========================================
  5898. * ギルドスキル割り振り通知
  5899. *------------------------------------------*/
  5900. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  5901. {
  5902. int fd;
  5903. nullpo_retr(0, sd);
  5904. fd=sd->fd;
  5905. WFIFOHEAD(fd,11);
  5906. WFIFOW(fd,0) = 0x10e;
  5907. WFIFOW(fd,2) = skill_num;
  5908. WFIFOW(fd,4) = lv;
  5909. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  5910. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  5911. WFIFOB(fd,10) = 1;
  5912. WFIFOSET(fd,11);
  5913. return 0;
  5914. }
  5915. /*==========================================
  5916. * ギルド同盟要請
  5917. *------------------------------------------*/
  5918. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  5919. {
  5920. int fd;
  5921. nullpo_retr(0, sd);
  5922. fd=sd->fd;
  5923. WFIFOHEAD(fd,packet_len(0x171));
  5924. WFIFOW(fd,0)=0x171;
  5925. WFIFOL(fd,2)=account_id;
  5926. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  5927. WFIFOSET(fd,packet_len(0x171));
  5928. return 0;
  5929. }
  5930. /*==========================================
  5931. * Reply to alliance request.
  5932. * Flag values are:
  5933. * 0: Already allied.
  5934. * 1: You rejected the offer.
  5935. * 2: You accepted the offer.
  5936. * 3: They have too any alliances
  5937. * 4: You have too many alliances.
  5938. *------------------------------------------*/
  5939. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  5940. {
  5941. int fd;
  5942. nullpo_retr(0, sd);
  5943. fd=sd->fd;
  5944. WFIFOHEAD(fd,packet_len(0x173));
  5945. WFIFOW(fd,0)=0x173;
  5946. WFIFOL(fd,2)=flag;
  5947. WFIFOSET(fd,packet_len(0x173));
  5948. return 0;
  5949. }
  5950. /*==========================================
  5951. * ギルド関係解消通知
  5952. *------------------------------------------*/
  5953. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  5954. {
  5955. int fd;
  5956. nullpo_retr(0, sd);
  5957. fd = sd->fd;
  5958. if (fd <= 0)
  5959. return 0;
  5960. WFIFOHEAD(fd,packet_len(0x184));
  5961. WFIFOW(fd,0)=0x184;
  5962. WFIFOL(fd,2)=guild_id;
  5963. WFIFOL(fd,6)=flag;
  5964. WFIFOSET(fd,packet_len(0x184));
  5965. return 0;
  5966. }
  5967. /*==========================================
  5968. * ギルド敵対結果
  5969. *------------------------------------------*/
  5970. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  5971. {
  5972. int fd;
  5973. nullpo_retr(0, sd);
  5974. fd=sd->fd;
  5975. WFIFOHEAD(fd,packet_len(0x181));
  5976. WFIFOW(fd,0)=0x181;
  5977. WFIFOB(fd,2)=flag;
  5978. WFIFOSET(fd,packet_len(0x181));
  5979. return 0;
  5980. }
  5981. /*==========================================
  5982. * ギルド関係追加
  5983. *------------------------------------------*/
  5984. /*int clif_guild_allianceadded(struct guild *g,int idx)
  5985. {
  5986. unsigned char buf[64];
  5987. WBUFW(fd,0)=0x185;
  5988. WBUFL(fd,2)=g->alliance[idx].opposition;
  5989. WBUFL(fd,6)=g->alliance[idx].guild_id;
  5990. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  5991. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  5992. return 0;
  5993. }*/
  5994. /*==========================================
  5995. * ギルド解散通知
  5996. *------------------------------------------*/
  5997. int clif_guild_broken(struct map_session_data *sd,int flag)
  5998. {
  5999. int fd;
  6000. nullpo_retr(0, sd);
  6001. fd=sd->fd;
  6002. WFIFOHEAD(fd,packet_len(0x15e));
  6003. WFIFOW(fd,0)=0x15e;
  6004. WFIFOL(fd,2)=flag;
  6005. WFIFOSET(fd,packet_len(0x15e));
  6006. return 0;
  6007. }
  6008. /*==========================================
  6009. * エモーション
  6010. *------------------------------------------*/
  6011. void clif_emotion(struct block_list *bl,int type)
  6012. {
  6013. unsigned char buf[8];
  6014. nullpo_retv(bl);
  6015. WBUFW(buf,0)=0xc0;
  6016. WBUFL(buf,2)=bl->id;
  6017. WBUFB(buf,6)=type;
  6018. clif_send(buf,packet_len(0xc0),bl,AREA);
  6019. }
  6020. /*==========================================
  6021. * トーキーボックス
  6022. *------------------------------------------*/
  6023. void clif_talkiebox(struct block_list* bl, const char* talkie)
  6024. {
  6025. unsigned char buf[86];
  6026. nullpo_retv(bl);
  6027. WBUFW(buf,0) = 0x191;
  6028. WBUFL(buf,2) = bl->id;
  6029. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6030. clif_send(buf,packet_len(0x191),bl,AREA);
  6031. }
  6032. /*==========================================
  6033. * 結婚エフェクト
  6034. *------------------------------------------*/
  6035. void clif_wedding_effect(struct block_list *bl)
  6036. {
  6037. unsigned char buf[6];
  6038. nullpo_retv(bl);
  6039. WBUFW(buf,0) = 0x1ea;
  6040. WBUFL(buf,2) = bl->id;
  6041. clif_send(buf, packet_len(0x1ea), bl, AREA);
  6042. }
  6043. /*==========================================
  6044. * ?なたに逢いたい使用時名前叫び
  6045. *------------------------------------------
  6046. void clif_callpartner(struct map_session_data *sd)
  6047. {
  6048. unsigned char buf[26];
  6049. char *p;
  6050. nullpo_retv(sd);
  6051. if(sd->status.partner_id){
  6052. WBUFW(buf,0)=0x1e6;
  6053. p = map_charid2nick(sd->status.partner_id);
  6054. if(p){
  6055. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6056. }else{
  6057. map_reqchariddb(sd,sd->status.partner_id);
  6058. chrif_searchcharid(sd->status.partner_id);
  6059. WBUFB(buf,2) = 0;
  6060. }
  6061. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  6062. }
  6063. return;
  6064. }
  6065. */
  6066. /*==========================================
  6067. * Marry [DracoRPG]
  6068. *------------------------------------------
  6069. void clif_marriage_process(struct map_session_data *sd)
  6070. {
  6071. int fd;
  6072. nullpo_retv(sd);
  6073. fd=sd->fd;
  6074. WFIFOHEAD(fd,packet_len(0x1e4));
  6075. WFIFOW(fd,0)=0x1e4;
  6076. WFIFOSET(fd,packet_len(0x1e4));
  6077. }
  6078. */
  6079. /*==========================================
  6080. * Notice of divorce
  6081. *------------------------------------------*/
  6082. void clif_divorced(struct map_session_data* sd, const char* name)
  6083. {
  6084. int fd;
  6085. nullpo_retv(sd);
  6086. fd=sd->fd;
  6087. WFIFOHEAD(fd,packet_len(0x205));
  6088. WFIFOW(fd,0)=0x205;
  6089. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6090. WFIFOSET(fd, packet_len(0x205));
  6091. }
  6092. /*==========================================
  6093. *
  6094. *------------------------------------------*/
  6095. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd)
  6096. {
  6097. nullpo_retv(sd);
  6098. WFIFOHEAD(fd,packet_len(0x1e2));
  6099. WFIFOW(fd,0)=0x1e2;
  6100. WFIFOSET(fd, packet_len(0x1e2));
  6101. }
  6102. /*==========================================
  6103. *
  6104. *------------------------------------------*/
  6105. int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  6106. {
  6107. int fd;
  6108. nullpo_retr(0, sd);
  6109. fd = sd->fd;
  6110. if (!fd || !len) return 0; //Disconnected player.
  6111. WFIFOHEAD(fd, len+5);
  6112. WFIFOW(fd, 0) = 0x17f;
  6113. WFIFOW(fd, 2) = len + 5;
  6114. memcpy(WFIFOP(fd,4), mes, len);
  6115. WFIFOSET(fd, WFIFOW(fd,2));
  6116. return 1;
  6117. }
  6118. /*==========================================
  6119. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6120. *------------------------------------------*/
  6121. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  6122. {
  6123. unsigned char buf[1024];
  6124. if (!len) return;
  6125. WBUFW(buf, 0) = 0x17f;
  6126. WBUFW(buf, 2) = len + 5;
  6127. memcpy(WBUFP(buf,4), mes, len);
  6128. clif_send(buf, WBUFW(buf,2), src, target);
  6129. return;
  6130. }
  6131. /*==========================================
  6132. *
  6133. *------------------------------------------*/
  6134. int clif_GM_kickack(struct map_session_data *sd, int id)
  6135. {
  6136. int fd;
  6137. nullpo_retr(0, sd);
  6138. fd = sd->fd;
  6139. WFIFOHEAD(fd,packet_len(0xcd));
  6140. WFIFOW(fd,0) = 0xcd;
  6141. WFIFOL(fd,2) = id;
  6142. WFIFOSET(fd, packet_len(0xcd));
  6143. return 0;
  6144. }
  6145. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  6146. {
  6147. int fd = tsd->fd;
  6148. if( fd > 0 )
  6149. clif_authfail_fd(fd, 15);
  6150. else
  6151. map_quit(tsd);
  6152. if( sd )
  6153. clif_GM_kickack(sd,tsd->status.account_id);
  6154. }
  6155. /// Displays various manner-related status messages
  6156. /// R 014a <type>.L
  6157. /// type: 0 - "A manner point has been successfully aligned."
  6158. /// 1 - ?
  6159. /// 2 - ?
  6160. /// 3 - "Chat Block has been applied by GM due to your ill-mannerous action."
  6161. /// 4 - "Automated Chat Block has been applied due to Anti-Spam System."
  6162. /// 5 - "You got a good point from %s."
  6163. void clif_manner_message(struct map_session_data* sd, uint32 type)
  6164. {
  6165. int fd;
  6166. nullpo_retv(sd);
  6167. fd = sd->fd;
  6168. WFIFOHEAD(fd,packet_len(0x14a));
  6169. WFIFOW(fd,0) = 0x14a;
  6170. WFIFOL(fd,2) = type;
  6171. WFIFOSET(fd, packet_len(0x14a));
  6172. }
  6173. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action.
  6174. /// R 014b <type>.B <GM name>.24B
  6175. /// type: 0 - positive (unmute)
  6176. /// 1 - negative (mute)
  6177. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  6178. {
  6179. int fd;
  6180. nullpo_retv(sd);
  6181. nullpo_retv(tsd);
  6182. fd = tsd->fd;
  6183. WFIFOHEAD(fd,packet_len(0x14b));
  6184. WFIFOW(fd,0) = 0x14b;
  6185. WFIFOB(fd,2) = type;
  6186. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6187. WFIFOSET(fd, packet_len(0x14b));
  6188. }
  6189. /*==========================================
  6190. * Wis拒否許可応答
  6191. *------------------------------------------*/
  6192. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6193. {
  6194. int fd;
  6195. nullpo_retr(0, sd);
  6196. fd=sd->fd;
  6197. WFIFOHEAD(fd,packet_len(0xd1));
  6198. WFIFOW(fd,0)=0xd1;
  6199. WFIFOB(fd,2)=type;
  6200. WFIFOB(fd,3)=flag;
  6201. WFIFOSET(fd,packet_len(0xd1));
  6202. return 0;
  6203. }
  6204. /*==========================================
  6205. * Wis全拒否許可応答
  6206. *------------------------------------------*/
  6207. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6208. {
  6209. int fd;
  6210. nullpo_retr(0, sd);
  6211. fd=sd->fd;
  6212. WFIFOHEAD(fd,packet_len(0xd2));
  6213. WFIFOW(fd,0)=0xd2;
  6214. WFIFOB(fd,2)=type;
  6215. WFIFOB(fd,3)=flag;
  6216. WFIFOSET(fd,packet_len(0xd2));
  6217. return 0;
  6218. }
  6219. /*==========================================
  6220. * サウンドエフェクト
  6221. *------------------------------------------*/
  6222. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6223. {
  6224. int fd;
  6225. nullpo_retv(sd);
  6226. nullpo_retv(bl);
  6227. fd = sd->fd;
  6228. WFIFOHEAD(fd,packet_len(0x1d3));
  6229. WFIFOW(fd,0) = 0x1d3;
  6230. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6231. WFIFOB(fd,26) = type;
  6232. WFIFOL(fd,27) = 0;
  6233. WFIFOL(fd,31) = bl->id;
  6234. WFIFOSET(fd,packet_len(0x1d3));
  6235. return;
  6236. }
  6237. int clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6238. {
  6239. unsigned char buf[40];
  6240. nullpo_retr(0, bl);
  6241. WBUFW(buf,0) = 0x1d3;
  6242. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6243. WBUFB(buf,26) = type;
  6244. WBUFL(buf,27) = 0;
  6245. WBUFL(buf,31) = bl->id;
  6246. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6247. return 0;
  6248. }
  6249. // displaying special effects (npcs, weather, etc) [Valaris]
  6250. int clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6251. {
  6252. unsigned char buf[24];
  6253. nullpo_retr(0, bl);
  6254. memset(buf, 0, packet_len(0x1f3));
  6255. WBUFW(buf,0) = 0x1f3;
  6256. WBUFL(buf,2) = bl->id;
  6257. WBUFL(buf,6) = type;
  6258. clif_send(buf, packet_len(0x1f3), bl, target);
  6259. if (disguised(bl)) {
  6260. WBUFL(buf,2) = -bl->id;
  6261. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6262. }
  6263. return 0;
  6264. }
  6265. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  6266. {
  6267. WFIFOHEAD(fd,10);
  6268. WFIFOW(fd,0) = 0x1f3;
  6269. WFIFOL(fd,2) = bl->id;
  6270. WFIFOL(fd,6) = type;
  6271. WFIFOSET(fd,10);
  6272. }
  6273. // messages (from mobs/npcs) [Valaris]
  6274. int clif_message(struct block_list* bl, const char* msg)
  6275. {
  6276. unsigned short msg_len = strlen(msg) + 1;
  6277. uint8 buf[256];
  6278. nullpo_retr(0, bl);
  6279. WBUFW(buf,0) = 0x8d;
  6280. WBUFW(buf,2) = msg_len + 8;
  6281. WBUFL(buf,4) = bl->id;
  6282. memcpy(WBUFP(buf,8), msg, msg_len);
  6283. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6284. return 0;
  6285. }
  6286. // refresh the client's screen, getting rid of any effects
  6287. int clif_refresh(struct map_session_data *sd)
  6288. {
  6289. nullpo_retr(-1, sd);
  6290. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6291. clif_inventorylist(sd);
  6292. if(pc_iscarton(sd)) {
  6293. clif_cartlist(sd);
  6294. clif_updatestatus(sd,SP_CARTINFO);
  6295. }
  6296. clif_updatestatus(sd,SP_WEIGHT);
  6297. clif_updatestatus(sd,SP_MAXWEIGHT);
  6298. clif_updatestatus(sd,SP_STR);
  6299. clif_updatestatus(sd,SP_AGI);
  6300. clif_updatestatus(sd,SP_VIT);
  6301. clif_updatestatus(sd,SP_INT);
  6302. clif_updatestatus(sd,SP_DEX);
  6303. clif_updatestatus(sd,SP_LUK);
  6304. if (sd->spiritball)
  6305. clif_spiritball_single(sd->fd, sd);
  6306. if (sd->vd.cloth_color)
  6307. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6308. if(merc_is_hom_active(sd->hd))
  6309. clif_send_homdata(sd,0,0);
  6310. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6311. clif_weather_check(sd);
  6312. if( pc_issit(sd) )
  6313. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  6314. if( pc_isdead(sd) ) //When you refresh, resend the death packet.
  6315. clif_clearunit_single(sd->bl.id,1,sd->fd);
  6316. #ifndef TXT_ONLY
  6317. mail_clear(sd);
  6318. #endif
  6319. return 0;
  6320. }
  6321. // updates the object's (bl) name on client
  6322. int clif_charnameack (int fd, struct block_list *bl)
  6323. {
  6324. unsigned char buf[103];
  6325. int cmd = 0x95, i, ps = -1;
  6326. nullpo_retr(0, bl);
  6327. WBUFW(buf,0) = cmd;
  6328. WBUFL(buf,2) = bl->id;
  6329. switch( bl->type )
  6330. {
  6331. case BL_PC:
  6332. {
  6333. struct map_session_data *ssd = (struct map_session_data *)bl;
  6334. struct party_data *p = NULL;
  6335. struct guild *g = NULL;
  6336. //Requesting your own "shadow" name. [Skotlex]
  6337. if (ssd->fd == fd && ssd->disguise)
  6338. WBUFL(buf,2) = -bl->id;
  6339. if (strlen(ssd->fakename)>1) {
  6340. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6341. break;
  6342. }
  6343. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6344. if (ssd->status.party_id > 0)
  6345. p = party_search(ssd->status.party_id);
  6346. if( ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL )
  6347. {
  6348. ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id);
  6349. if( i < g->max_member ) ps = g->member[i].position;
  6350. }
  6351. if (p == NULL && g == NULL)
  6352. break;
  6353. WBUFW(buf, 0) = cmd = 0x195;
  6354. if (p)
  6355. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6356. else
  6357. WBUFB(buf,30) = 0;
  6358. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  6359. {
  6360. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6361. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6362. } else { //Assume no guild.
  6363. WBUFB(buf,54) = 0;
  6364. WBUFB(buf,78) = 0;
  6365. }
  6366. }
  6367. break;
  6368. //[blackhole89]
  6369. case BL_HOM:
  6370. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6371. break;
  6372. case BL_MER:
  6373. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  6374. break;
  6375. case BL_PET:
  6376. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6377. break;
  6378. case BL_NPC:
  6379. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6380. break;
  6381. case BL_MOB:
  6382. {
  6383. struct mob_data *md = (struct mob_data *)bl;
  6384. nullpo_retr(0, md);
  6385. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6386. if( md->guardian_data && md->guardian_data->guild_id )
  6387. {
  6388. WBUFW(buf, 0) = cmd = 0x195;
  6389. WBUFB(buf,30) = 0;
  6390. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6391. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6392. }
  6393. else if( battle_config.show_mob_info )
  6394. {
  6395. char mobhp[50], *str_p = mobhp;
  6396. WBUFW(buf, 0) = cmd = 0x195;
  6397. if( battle_config.show_mob_info&4 )
  6398. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6399. if( battle_config.show_mob_info&1 )
  6400. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6401. if( battle_config.show_mob_info&2 )
  6402. str_p += sprintf(str_p, "HP: %d%% | ", get_percentage(md->status.hp, md->status.max_hp));
  6403. //Even thought mobhp ain't a name, we send it as one so the client
  6404. //can parse it. [Skotlex]
  6405. if( str_p != mobhp )
  6406. {
  6407. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6408. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6409. WBUFB(buf,54) = 0;
  6410. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6411. }
  6412. }
  6413. }
  6414. break;
  6415. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6416. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6417. // break;
  6418. return 0;
  6419. default:
  6420. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  6421. return 0;
  6422. }
  6423. // if no receipient specified just update nearby clients
  6424. if (fd == 0)
  6425. clif_send(buf, packet_len(cmd), bl, AREA);
  6426. else {
  6427. WFIFOHEAD(fd, packet_len(cmd));
  6428. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  6429. WFIFOSET(fd, packet_len(cmd));
  6430. }
  6431. return 0;
  6432. }
  6433. //Used to update when a char leaves a party/guild. [Skotlex]
  6434. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6435. int clif_charnameupdate (struct map_session_data *ssd)
  6436. {
  6437. unsigned char buf[103];
  6438. int cmd = 0x195, ps = -1, i;
  6439. struct party_data *p = NULL;
  6440. struct guild *g = NULL;
  6441. nullpo_retr(0, ssd);
  6442. if (strlen(ssd->fakename)>1)
  6443. return 0; //No need to update as the party/guild was not displayed anyway.
  6444. WBUFW(buf,0) = cmd;
  6445. WBUFL(buf,2) = ssd->bl.id;
  6446. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6447. if( ssd->status.party_id > 0 )
  6448. p = party_search(ssd->status.party_id);
  6449. if( ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL )
  6450. {
  6451. ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id);
  6452. if( i < g->max_member ) ps = g->member[i].position;
  6453. }
  6454. if( p )
  6455. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6456. else
  6457. WBUFB(buf,30) = 0;
  6458. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  6459. {
  6460. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6461. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6462. }
  6463. else
  6464. {
  6465. WBUFB(buf,54) = 0;
  6466. WBUFB(buf,78) = 0;
  6467. }
  6468. // Update nearby clients
  6469. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  6470. return 0;
  6471. }
  6472. void clif_slide(struct block_list *bl, int x, int y)
  6473. {
  6474. unsigned char buf[10];
  6475. nullpo_retv(bl);
  6476. WBUFW(buf, 0) = 0x01ff;
  6477. WBUFL(buf, 2) = bl->id;
  6478. WBUFW(buf, 6) = x;
  6479. WBUFW(buf, 8) = y;
  6480. clif_send(buf, packet_len(0x1ff), bl, AREA);
  6481. if( disguised(bl) )
  6482. {
  6483. WBUFL(buf,2) = -bl->id;
  6484. clif_send(buf, packet_len(0x1ff), bl, SELF);
  6485. }
  6486. }
  6487. /*------------------------------------------
  6488. * @me command by lordalfa, rewritten implementation by Skotlex
  6489. *------------------------------------------*/
  6490. int clif_disp_overhead(struct map_session_data *sd, const char* mes)
  6491. {
  6492. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  6493. int len_mes = strlen(mes)+1; //Account for \0
  6494. if (len_mes + 8 >= 256) {
  6495. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6496. len_mes = 247; //Trunk it to avoid problems.
  6497. }
  6498. // send message to others
  6499. WBUFW(buf,0) = 0x8d;
  6500. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6501. WBUFL(buf,4) = sd->bl.id;
  6502. memcpy(WBUFP(buf,8), mes, len_mes);
  6503. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6504. // send back message to the speaker
  6505. WBUFW(buf,0) = 0x8e;
  6506. WBUFW(buf, 2) = len_mes + 4;
  6507. memcpy(WBUFP(buf,4), mes, len_mes);
  6508. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6509. return 0;
  6510. }
  6511. /*==========================
  6512. * Minimap fix [Kevin]
  6513. * Remove dot from minimap
  6514. *--------------------------*/
  6515. int clif_party_xy_remove(struct map_session_data *sd)
  6516. {
  6517. unsigned char buf[16];
  6518. nullpo_retr(0, sd);
  6519. WBUFW(buf,0)=0x107;
  6520. WBUFL(buf,2)=sd->status.account_id;
  6521. WBUFW(buf,6)=-1;
  6522. WBUFW(buf,8)=-1;
  6523. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6524. return 0;
  6525. }
  6526. //Displays gospel-buff information (thanks to Rayce):
  6527. //Type determines message based on this table:
  6528. /*
  6529. 0x15 End all negative status
  6530. 0x16 Immunity to all status
  6531. 0x17 MaxHP +100%
  6532. 0x18 MaxSP +100%
  6533. 0x19 All stats +20
  6534. 0x1c Enchant weapon with Holy element
  6535. 0x1d Enchant armor with Holy element
  6536. 0x1e DEF +25%
  6537. 0x1f ATK +100%
  6538. 0x20 HIT/Flee +50
  6539. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  6540. */
  6541. void clif_gospel_info(struct map_session_data *sd, int type)
  6542. {
  6543. int fd=sd->fd;
  6544. WFIFOHEAD(fd,packet_len(0x215));
  6545. WFIFOW(fd,0)=0x215;
  6546. WFIFOL(fd,2)=type;
  6547. WFIFOSET(fd, packet_len(0x215));
  6548. }
  6549. /*==========================================
  6550. * Info about Star Glaldiator save map [Komurka]
  6551. * type: 1: Information, 0: Map registered
  6552. *------------------------------------------*/
  6553. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  6554. {
  6555. int fd=sd->fd;
  6556. WFIFOHEAD(fd,packet_len(0x20e));
  6557. WFIFOW(fd,0) = 0x20e;
  6558. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), (char*)WFIFOP(fd,2));
  6559. WFIFOL(fd,26) = sd->bl.id;
  6560. WFIFOB(fd,30) = feel_level;
  6561. WFIFOB(fd,31) = type?1:0;
  6562. WFIFOSET(fd,packet_len(0x20e));
  6563. }
  6564. /*==========================================
  6565. * Info about Star Glaldiator hate mob [Komurka]
  6566. * type: 1: Register mob, 0: Information.
  6567. *------------------------------------------*/
  6568. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  6569. {
  6570. int fd=sd->fd;
  6571. WFIFOHEAD(fd,packet_len(0x20e));
  6572. WFIFOW(fd,0)=0x20e;
  6573. if (pcdb_checkid(class_))
  6574. strncpy((char*)WFIFOP(fd,2),job_name(class_), NAME_LENGTH);
  6575. else if (mobdb_checkid(class_))
  6576. strncpy((char*)WFIFOP(fd,2),mob_db(class_)->jname, NAME_LENGTH);
  6577. else //Really shouldn't happen...
  6578. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  6579. WFIFOL(fd,26)=sd->bl.id;
  6580. WFIFOB(fd,30)=hate_level;
  6581. WFIFOB(fd,31)=type?10:11; //Register/Info
  6582. WFIFOSET(fd, packet_len(0x20e));
  6583. }
  6584. /*==========================================
  6585. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6586. *------------------------------------------*/
  6587. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  6588. {
  6589. int fd=sd->fd;
  6590. WFIFOHEAD(fd,packet_len(0x20e));
  6591. WFIFOW(fd,0)=0x20e;
  6592. strncpy((char*)WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6593. WFIFOL(fd,26)=mob_id;
  6594. WFIFOB(fd,30)=progress; //Message to display
  6595. WFIFOB(fd,31)=20;
  6596. WFIFOSET(fd, packet_len(0x20e));
  6597. }
  6598. /*==========================================
  6599. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  6600. *------------------------------------------*/
  6601. void clif_feel_hate_reset(struct map_session_data *sd)
  6602. {
  6603. int fd=sd->fd;
  6604. WFIFOHEAD(fd,packet_len(0x20e));
  6605. WFIFOW(fd,0)=0x20e;
  6606. memset(WFIFOP(fd,2), 0, NAME_LENGTH); //Blank name as all was reset.
  6607. WFIFOL(fd,26)=sd->bl.id;
  6608. WFIFOB(fd,30)=0; //Feel/hate level: irrelevant
  6609. WFIFOB(fd,31)=30;
  6610. WFIFOSET(fd, packet_len(0x20e));
  6611. }
  6612. /*==========================================
  6613. * Equip window (un)tick ack
  6614. * R 02d9 <zero>.L <flag>.L
  6615. *------------------------------------------*/
  6616. void clif_equiptickack(struct map_session_data* sd, int flag)
  6617. {
  6618. int fd;
  6619. nullpo_retv(sd);
  6620. fd = sd->fd;
  6621. WFIFOHEAD(fd, packet_len(0x2d9));
  6622. WFIFOW(fd, 0) = 0x2d9;
  6623. WFIFOL(fd, 2) = 0;
  6624. WFIFOL(fd, 6) = flag;
  6625. WFIFOSET(fd, packet_len(0x2d9));
  6626. }
  6627. /*==========================================
  6628. * The player's 'view equip' state, sent during login
  6629. * R 02da <flag>.B
  6630. *------------------------------------------*/
  6631. void clif_equipcheckbox(struct map_session_data* sd)
  6632. {
  6633. int fd;
  6634. nullpo_retv(sd);
  6635. fd = sd->fd;
  6636. WFIFOHEAD(fd, packet_len(0x2da));
  6637. WFIFOW(fd, 0) = 0x2da;
  6638. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  6639. WFIFOSET(fd, packet_len(0x2da));
  6640. }
  6641. /*==========================================
  6642. * Sends info about a player's equipped items
  6643. * R 002d7 <length>.W <name>.24B <class>.w <hairstyle>.w <up-viewid>.w <mid-viewid>.w <low-viewid>.w <haircolor>.w <cloth-dye>.w <gender>.1B {equip item}.26B*
  6644. *------------------------------------------*/
  6645. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  6646. {
  6647. int i, n, fd;
  6648. nullpo_retv(sd);
  6649. nullpo_retv(tsd);
  6650. fd = sd->fd;
  6651. WFIFOHEAD(fd, MAX_INVENTORY * 26 + 43);
  6652. WFIFOW(fd, 0) = 0x2d7;
  6653. safestrncpy((char*)WFIFOP(fd, 4), tsd->status.name, NAME_LENGTH);
  6654. WFIFOW(fd,28) = tsd->status.class_;
  6655. WFIFOW(fd,30) = tsd->vd.hair_style;
  6656. WFIFOW(fd,32) = tsd->vd.head_top;
  6657. WFIFOW(fd,34) = tsd->vd.head_mid;
  6658. WFIFOW(fd,36) = tsd->vd.head_bottom;
  6659. WFIFOW(fd,38) = tsd->vd.hair_color;
  6660. WFIFOW(fd,40) = tsd->vd.cloth_color;
  6661. WFIFOB(fd,42) = tsd->vd.sex;
  6662. for(i=0,n=0; i < MAX_INVENTORY; i++)
  6663. {
  6664. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  6665. continue;
  6666. if (itemdb_isstackable2(tsd->inventory_data[i])) // Is not equippable
  6667. continue;
  6668. // Inventory position
  6669. WFIFOW(fd, n*26+43) = i + 2;
  6670. // Add refine, identify flag, element, etc.
  6671. clif_item_sub(WFIFOP(fd,0), n*26+45, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  6672. // Add cards
  6673. clif_addcards(WFIFOP(fd, n*26+55), &tsd->status.inventory[i]);
  6674. // Expiration date stuff, if all of those are set to 0 then the client doesn't show anything related (6 bytes)
  6675. memset(WFIFOP(fd, n*26+63), 0, 6);
  6676. n++;
  6677. }
  6678. WFIFOW(fd, 2) = 43 + n*26; // Set length
  6679. WFIFOSET(fd, WFIFOW(fd, 2));
  6680. }
  6681. /*==========================================
  6682. * View player equip request denied
  6683. * R 0291 <message>.W
  6684. * TODO: this looks like a general-purpose packet to print msgstringtable entries.
  6685. *------------------------------------------*/
  6686. void clif_viewequip_fail(struct map_session_data* sd)
  6687. {
  6688. int fd;
  6689. nullpo_retv(sd);
  6690. fd = sd->fd;
  6691. WFIFOHEAD(fd, packet_len(0x291));
  6692. WFIFOW(fd, 0) = 0x291;
  6693. WFIFOW(fd, 2) = 0x54d; // This controls which message is displayed. 0x54d is the correct one. Maybe it's used for something else too?
  6694. WFIFOSET(fd, packet_len(0x291));
  6695. }
  6696. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  6697. /// Returns true if the packet was parsed successfully.
  6698. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  6699. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  6700. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  6701. {
  6702. char *text, *name, *message;
  6703. unsigned int packetlen, textlen, namelen, messagelen;
  6704. int fd = sd->fd;
  6705. *name_ = NULL;
  6706. *namelen_ = 0;
  6707. *message_ = NULL;
  6708. *messagelen_ = 0;
  6709. packetlen = RFIFOW(fd,2);
  6710. // basic structure checks
  6711. if( packetlen > RFIFOREST(fd) )
  6712. { // there has to be enough data to read
  6713. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6714. return false;
  6715. }
  6716. if( packetlen < 4 + 1 )
  6717. { // 4-byte header and at least an empty string is expected
  6718. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  6719. return false;
  6720. }
  6721. text = (char*)RFIFOP(fd,4);
  6722. textlen = packetlen - 4;
  6723. // process <name> part of the packet
  6724. if( format == 0 )
  6725. {// name and message are separated by ' : '
  6726. // validate name
  6727. name = text;
  6728. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  6729. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  6730. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  6731. {
  6732. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  6733. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  6734. set_eof(fd); // Just kick them out to correct it.
  6735. return false;
  6736. }
  6737. message = name + namelen + 3;
  6738. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  6739. }
  6740. else
  6741. {// name has fixed width
  6742. if( textlen < NAME_LENGTH + 1 )
  6743. {
  6744. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6745. return false;
  6746. }
  6747. // validate name
  6748. name = text;
  6749. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  6750. if( name[namelen] != '\0' )
  6751. { // only restriction is that the name must be zero-terminated
  6752. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  6753. return false;
  6754. }
  6755. message = name + NAME_LENGTH;
  6756. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  6757. }
  6758. if( messagelen != strnlen(message, messagelen)+1 )
  6759. { // the declared length must match real length
  6760. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  6761. return false;
  6762. }
  6763. // verify <message> part of the packet
  6764. if( message[messagelen-1] != '\0' )
  6765. { // message must be zero-terminated
  6766. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  6767. return false;
  6768. }
  6769. if( messagelen > CHAT_SIZE_MAX-1 )
  6770. { // messages mustn't be too long
  6771. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  6772. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  6773. // Neither the official client nor server place any restriction on the length of the data in the packet,
  6774. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  6775. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  6776. return false;
  6777. }
  6778. *name_ = name;
  6779. *namelen_ = namelen;
  6780. *message_ = message;
  6781. *messagelen_ = messagelen;
  6782. return true;
  6783. }
  6784. // ---------------------
  6785. // clif_guess_PacketVer
  6786. // ---------------------
  6787. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  6788. // error codes:
  6789. // 0 - Success
  6790. // 1 - Unknown packet_ver
  6791. // 2 - Invalid account_id
  6792. // 3 - Invalid char_id
  6793. // 4 - Invalid login_id1 (reserved)
  6794. // 5 - Invalid client_tick (reserved)
  6795. // 6 - Invalid sex
  6796. // Only the first 'invalid' error that appears is used.
  6797. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  6798. {
  6799. static int err = 1;
  6800. static int packet_ver = -1;
  6801. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  6802. if (get_previous)
  6803. {//For quick reruns, since the normal code flow is to fetch this once to identify the packet version, then again in the wanttoconnect function. [Skotlex]
  6804. if( error )
  6805. *error = err;
  6806. return packet_ver;
  6807. }
  6808. //By default, start searching on the default one.
  6809. err = 1;
  6810. packet_ver = clif_config.packet_db_ver;
  6811. cmd = RFIFOW(fd,0);
  6812. packet_len = RFIFOREST(fd);
  6813. #define SET_ERROR(n) \
  6814. if( err == 1 )\
  6815. err = n;\
  6816. //define SET_ERROR
  6817. #define CHECK_PACKET_VER() \
  6818. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  6819. ;/* not wanttoconnection or wrong length */\
  6820. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  6821. { SET_ERROR(2); }/* invalid account_id */\
  6822. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  6823. { SET_ERROR(3); }/* invalid char_id */\
  6824. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  6825. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  6826. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  6827. { SET_ERROR(6); }/* invalid sex */\
  6828. else\
  6829. {\
  6830. err = 0;\
  6831. if( error )\
  6832. *error = 0;\
  6833. return packet_ver;\
  6834. }\
  6835. //define CHECK_PACKET_VER
  6836. CHECK_PACKET_VER();//Default packet version found.
  6837. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  6838. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  6839. CHECK_PACKET_VER();
  6840. }
  6841. if( error )
  6842. *error = err;
  6843. packet_ver = -1;
  6844. return -1;
  6845. #undef SET_ERROR
  6846. #undef CHECK_PACKET_VER
  6847. }
  6848. // ------------
  6849. // clif_parse_*
  6850. // ------------
  6851. // パケット読み取って色々操作
  6852. /*==========================================
  6853. *
  6854. *------------------------------------------*/
  6855. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  6856. {
  6857. struct block_list* bl;
  6858. struct auth_node* node;
  6859. int cmd, account_id, char_id, login_id1, sex;
  6860. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  6861. int packet_ver; // 5: old, 6: 7july04, 7: 13july04, 8: 26july04, 9: 9aug04/16aug04/17aug04, 10: 6sept04, 11: 21sept04, 12: 18oct04, 13: 25oct04 (by [Yor])
  6862. if (sd) {
  6863. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  6864. return;
  6865. }
  6866. // Only valid packet version get here
  6867. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  6868. cmd = RFIFOW(fd,0);
  6869. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  6870. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  6871. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  6872. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  6873. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  6874. if( packet_ver < 5 || // reject really old client versions
  6875. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  6876. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  6877. {// packet version rejected
  6878. ShowInfo("Rejected connection attempt, forbidden packet version (AID/CID: '"CL_WHITE"%d/%d"CL_RESET"', Packet Ver: '"CL_WHITE"%d"CL_RESET"', IP: '"CL_WHITE"%s"CL_RESET"').\n", account_id, char_id, packet_ver, ip2str(session[fd]->client_addr, NULL));
  6879. WFIFOHEAD(fd,packet_len(0x6a));
  6880. WFIFOW(fd,0) = 0x6a;
  6881. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  6882. WFIFOSET(fd,packet_len(0x6a));
  6883. set_eof(fd);
  6884. return;
  6885. }
  6886. //Check for double login.
  6887. bl = map_id2bl(account_id);
  6888. if(bl && bl->type != BL_PC) {
  6889. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  6890. WFIFOHEAD(fd,packet_len(0x6a));
  6891. WFIFOW(fd,0) = 0x6a;
  6892. WFIFOB(fd,2) = 3; // Rejected by server
  6893. WFIFOSET(fd,packet_len(0x6a));
  6894. set_eof(fd);
  6895. return;
  6896. }
  6897. if (bl ||
  6898. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  6899. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  6900. {
  6901. clif_authfail_fd(fd, 8); //Still recognizes last connection
  6902. return;
  6903. }
  6904. CREATE(sd, TBL_PC, 1);
  6905. sd->fd = fd;
  6906. sd->packet_ver = packet_ver;
  6907. session[fd]->session_data = sd;
  6908. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  6909. #if PACKETVER < 20070521
  6910. WFIFOHEAD(fd,4);
  6911. WFIFOL(fd,0) = sd->bl.id;
  6912. WFIFOSET(fd,4);
  6913. #else
  6914. WFIFOHEAD(fd,packet_len(0x283));
  6915. WFIFOW(fd,0) = 0x283;
  6916. WFIFOL(fd,2) = sd->bl.id;
  6917. WFIFOSET(fd,packet_len(0x283));
  6918. #endif
  6919. chrif_authreq(sd);
  6920. return;
  6921. }
  6922. /*==========================================
  6923. * 007d クライアント側マップ読み込み完了
  6924. * map侵入時に必要なデータを全て送りつける
  6925. *------------------------------------------*/
  6926. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  6927. {
  6928. if(sd->bl.prev != NULL)
  6929. return;
  6930. if (!sd->state.active)
  6931. { //Character loading is not complete yet!
  6932. //Let pc_reg_received reinvoke this when ready.
  6933. sd->state.connect_new = 0;
  6934. return;
  6935. }
  6936. if (sd->state.rewarp)
  6937. { //Rewarp player.
  6938. sd->state.rewarp = 0;
  6939. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  6940. return;
  6941. }
  6942. // look
  6943. #if PACKETVER < 4
  6944. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  6945. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  6946. #else
  6947. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  6948. #endif
  6949. if(sd->vd.cloth_color)
  6950. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6951. // item
  6952. pc_checkitem(sd);
  6953. clif_inventorylist(sd);
  6954. // cart
  6955. if(pc_iscarton(sd)) {
  6956. clif_cartlist(sd);
  6957. clif_updatestatus(sd,SP_CARTINFO);
  6958. }
  6959. // weight
  6960. clif_updatestatus(sd,SP_WEIGHT);
  6961. clif_updatestatus(sd,SP_MAXWEIGHT);
  6962. // guild
  6963. // (needs to go before clif_spawn() to show guild emblems correctly)
  6964. if(sd->status.guild_id)
  6965. guild_send_memberinfoshort(sd,1);
  6966. if(battle_config.pc_invincible_time > 0) {
  6967. if(map_flag_gvg(sd->bl.m))
  6968. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  6969. else
  6970. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  6971. }
  6972. if (map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs) //Skotlex
  6973. map_spawnmobs(sd->bl.m);
  6974. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  6975. map_addblock(&sd->bl);
  6976. clif_spawn(&sd->bl);
  6977. // Party
  6978. // (needs to go after clif_spawn() to show hp bars correctly)
  6979. if(sd->status.party_id) {
  6980. party_send_movemap(sd);
  6981. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  6982. }
  6983. if( sd->state.bg_id ) clif_bg_hp(sd); // BattleGround System
  6984. if( sd->state.changemap && map[sd->bl.m].flag.battleground )
  6985. {
  6986. clif_set01D6(sd,19); // Battleground Mode
  6987. if( map[sd->bl.m].flag.battleground == 2 )
  6988. clif_bg_updatescore_single(sd);
  6989. }
  6990. if(map[sd->bl.m].flag.pvp) {
  6991. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  6992. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  6993. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  6994. sd->pvp_rank = 0;
  6995. sd->pvp_lastusers = 0;
  6996. sd->pvp_point = 5;
  6997. sd->pvp_won = 0;
  6998. sd->pvp_lost = 0;
  6999. }
  7000. clif_set0199(sd,1);
  7001. } else
  7002. // set flag, if it's a duel [LuzZza]
  7003. if(sd->duel_group)
  7004. clif_set0199(sd,1);
  7005. if (map[sd->bl.m].flag.gvg_dungeon)
  7006. {
  7007. clif_set0199(sd,1); //TODO: Figure out the real packet to send here.
  7008. if (!sd->pvp_point)
  7009. {
  7010. sd->pvp_point = 5; //Need to die twice to be warped out.
  7011. sd->pvp_won = 0;
  7012. sd->pvp_lost = 0;
  7013. }
  7014. }
  7015. if( map_flag_gvg(sd->bl.m) )
  7016. clif_set0199(sd,3);
  7017. // info about nearby objects
  7018. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  7019. map_foreachinarea(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);
  7020. //TODO: merge it with the code below
  7021. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) && sd->pd)
  7022. { //Return the pet to egg. [Skotlex]
  7023. clif_displaymessage(sd->fd, "Pets are not allowed in Guild Wars.");
  7024. pet_menu(sd, 3); //Option 3 is return to egg.
  7025. }
  7026. // pet
  7027. if(sd->pd) {
  7028. map_addblock(&sd->pd->bl);
  7029. clif_spawn(&sd->pd->bl);
  7030. clif_send_petdata(sd,sd->pd,0,0);
  7031. clif_send_petstatus(sd);
  7032. // skill_unit_move(&sd->pd->bl,gettick(),1);
  7033. }
  7034. //homunculus [blackhole89]
  7035. if( merc_is_hom_active(sd->hd) )
  7036. {
  7037. map_addblock(&sd->hd->bl);
  7038. clif_spawn(&sd->hd->bl);
  7039. clif_send_homdata(sd,0,0);
  7040. clif_hominfo(sd,sd->hd,1);
  7041. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  7042. clif_homskillinfoblock(sd);
  7043. if( battle_config.hom_setting&0x8 )
  7044. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  7045. if( !(battle_config.hom_setting&0x2) )
  7046. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  7047. }
  7048. if( sd->md )
  7049. {
  7050. map_addblock(&sd->md->bl);
  7051. clif_spawn(&sd->md->bl);
  7052. clif_mercenary_info(sd);
  7053. clif_mercenary_skillblock(sd);
  7054. }
  7055. if(sd->state.connect_new) {
  7056. int lv;
  7057. sd->state.connect_new = 0;
  7058. clif_skillinfoblock(sd);
  7059. clif_hotkeys_send(sd);
  7060. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7061. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7062. clif_updatestatus(sd,SP_SKILLPOINT);
  7063. clif_initialstatus(sd);
  7064. if (sd->sc.option&OPTION_FALCON)
  7065. clif_status_load(&sd->bl, SI_FALCON, 1);
  7066. if (sd->sc.option&OPTION_RIDING)
  7067. clif_status_load(&sd->bl, SI_RIDING, 1);
  7068. if(sd->status.manner < 0)
  7069. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7070. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7071. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7072. if(sd->bl.m == sd->feel_map[0].m
  7073. || sd->bl.m == sd->feel_map[1].m
  7074. || sd->bl.m == sd->feel_map[2].m)
  7075. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7076. }
  7077. if(sd->pd && sd->pd->pet.intimate > 900)
  7078. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7079. if(merc_is_hom_active(sd->hd))
  7080. merc_hom_init_timers(sd->hd);
  7081. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7082. {
  7083. sd->state.night = 1;
  7084. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7085. }
  7086. // Notify everyone that this char logged in [Skotlex].
  7087. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  7088. //Login Event
  7089. npc_script_event(sd, NPCE_LOGIN);
  7090. } else {
  7091. //For some reason the client "loses" these on warp/map-change.
  7092. clif_updatestatus(sd,SP_STR);
  7093. clif_updatestatus(sd,SP_AGI);
  7094. clif_updatestatus(sd,SP_VIT);
  7095. clif_updatestatus(sd,SP_INT);
  7096. clif_updatestatus(sd,SP_DEX);
  7097. clif_updatestatus(sd,SP_LUK);
  7098. // abort currently running script
  7099. sd->state.using_fake_npc = 0;
  7100. sd->state.menu_or_input = 0;
  7101. sd->npc_menu = 0;
  7102. if(sd->npc_id)
  7103. npc_event_dequeue(sd);
  7104. }
  7105. if( sd->state.changemap )
  7106. {// restore information that gets lost on map-change
  7107. #if PACKETVER >= 20070918
  7108. clif_partyinvitationstate(sd);
  7109. clif_equipcheckbox(sd);
  7110. #endif
  7111. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  7112. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  7113. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  7114. if( night_flag && map[sd->bl.m].flag.nightenabled )
  7115. { //Display night.
  7116. if( !sd->state.night )
  7117. {
  7118. sd->state.night = 1;
  7119. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7120. }
  7121. }
  7122. else if( sd->state.night )
  7123. { //Clear night display.
  7124. sd->state.night = 0;
  7125. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7126. }
  7127. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  7128. {
  7129. char output[128];
  7130. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  7131. clif_announce(&sd->bl, output, strlen(output) + 1, 0x00CC66, 3);
  7132. }
  7133. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  7134. sd->state.changemap = false;
  7135. }
  7136. #ifndef TXT_ONLY
  7137. mail_clear(sd);
  7138. #endif
  7139. quest_pc_login(sd);
  7140. if(map[sd->bl.m].flag.loadevent) // Lance
  7141. npc_script_event(sd, NPCE_LOADMAP);
  7142. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7143. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7144. if (sd->sc.opt2) //Client loses these on warp.
  7145. clif_changeoption(&sd->bl);
  7146. clif_weather_check(sd);
  7147. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7148. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7149. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7150. else
  7151. sd->areanpc_id = 0;
  7152. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  7153. if(pc_isdead(sd))
  7154. clif_clearunit_area(&sd->bl, 1);
  7155. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  7156. // else
  7157. // clif_changed_dir(&sd->bl, SELF);
  7158. // Trigger skill effects if you appear standing on them
  7159. if(!battle_config.pc_invincible_time)
  7160. skill_unit_move(&sd->bl,gettick(),1);
  7161. }
  7162. /*==========================================
  7163. *
  7164. *------------------------------------------*/
  7165. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  7166. {
  7167. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7168. WFIFOHEAD(fd, packet_len(0x7f));
  7169. WFIFOW(fd,0)=0x7f;
  7170. WFIFOL(fd,2)=gettick();
  7171. WFIFOSET(fd,packet_len(0x7f));
  7172. // removed until the socket problems are fixed. [FlavioJS]
  7173. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  7174. return;
  7175. }
  7176. void clif_hotkeys_send(struct map_session_data *sd) {
  7177. #ifdef HOTKEY_SAVING
  7178. const int fd = sd->fd;
  7179. int i;
  7180. if (!fd) return;
  7181. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  7182. WFIFOW(fd, 0) = 0x02b9;
  7183. for(i = 0; i < MAX_HOTKEYS; i++) {
  7184. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  7185. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  7186. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  7187. }
  7188. WFIFOSET(fd, packet_len(0x02b9));
  7189. #endif
  7190. }
  7191. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  7192. #ifdef HOTKEY_SAVING
  7193. unsigned short idx;
  7194. int cmd;
  7195. cmd = RFIFOW(fd, 0);
  7196. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  7197. if (idx >= MAX_HOTKEYS) return;
  7198. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  7199. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  7200. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  7201. return;
  7202. #endif
  7203. }
  7204. /*==========================================
  7205. *
  7206. *------------------------------------------*/
  7207. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  7208. {
  7209. short x, y;
  7210. int cmd;
  7211. if (pc_isdead(sd)) {
  7212. clif_clearunit_area(&sd->bl, 1);
  7213. return;
  7214. }
  7215. if (sd->sc.opt1 && sd->sc.opt1 == OPT1_STONEWAIT)
  7216. ; //You CAN walk on this OPT1 value.
  7217. else if (pc_cant_act(sd))
  7218. return;
  7219. if(sd->sc.data[SC_RUN])
  7220. return;
  7221. pc_delinvincibletimer(sd);
  7222. cmd = RFIFOW(fd,0);
  7223. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7224. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7225. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7226. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7227. //Set last idle time... [Skotlex]
  7228. sd->idletime = last_tick;
  7229. unit_walktoxy(&sd->bl, x, y, 4);
  7230. }
  7231. /*==========================================
  7232. *
  7233. *------------------------------------------*/
  7234. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  7235. {
  7236. WFIFOHEAD(fd,packet_len(0x18b));
  7237. WFIFOW(fd,0) = 0x18b;
  7238. /* Rovert's prevent logout option fixed [Valaris] */
  7239. if (!sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] &&
  7240. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7241. ) {
  7242. set_eof(fd);
  7243. WFIFOW(fd,2)=0;
  7244. } else {
  7245. WFIFOW(fd,2)=1;
  7246. }
  7247. WFIFOSET(fd,packet_len(0x18b));
  7248. }
  7249. /// Requesting unit's name
  7250. /// S 0094 <object id>.l
  7251. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  7252. {
  7253. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7254. struct block_list* bl;
  7255. //struct status_change *sc;
  7256. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  7257. id = sd->bl.id;
  7258. bl = map_id2bl(id);
  7259. if( bl == NULL )
  7260. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  7261. // 'see people in GM hide' cheat detection
  7262. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  7263. sc = status_get_sc(bl);
  7264. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  7265. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  7266. pc_isGM(sd) < battle_config.hack_info_GM_level
  7267. ) {
  7268. char gm_msg[256];
  7269. 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);
  7270. ShowWarning(gm_msg);
  7271. // information is sent to all online GMs
  7272. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7273. return;
  7274. }
  7275. */
  7276. clif_charnameack(fd, bl);
  7277. }
  7278. /*==========================================
  7279. * Validates and processes global messages
  7280. * S 008c/00f3 <packet len>.w <text>.?B (<name> : <message>) 00
  7281. *------------------------------------------*/
  7282. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  7283. {
  7284. const char* text = (char*)RFIFOP(fd,4);
  7285. int textlen = RFIFOW(fd,2) - 4;
  7286. char *name, *message;
  7287. int namelen, messagelen;
  7288. // validate packet and retrieve name and message
  7289. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  7290. return;
  7291. if( is_atcommand(fd, sd, message, 1) )
  7292. return;
  7293. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  7294. return;
  7295. if( battle_config.min_chat_delay )
  7296. { //[Skotlex]
  7297. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7298. return;
  7299. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7300. }
  7301. // send message to others (using the send buffer for temp. storage)
  7302. WFIFOHEAD(fd, 8 + textlen);
  7303. WFIFOW(fd,0) = 0x8d;
  7304. WFIFOW(fd,2) = 8 + textlen;
  7305. WFIFOL(fd,4) = sd->bl.id;
  7306. safestrncpy((char*)WFIFOP(fd,8), text, textlen);
  7307. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7308. // send back message to the speaker
  7309. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7310. WFIFOW(fd,0) = 0x8e;
  7311. WFIFOSET(fd, WFIFOW(fd,2));
  7312. #ifdef PCRE_SUPPORT
  7313. // trigger listening npcs
  7314. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  7315. #endif
  7316. // check for special supernovice phrase
  7317. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE )
  7318. {
  7319. unsigned int next = pc_nextbaseexp(sd);
  7320. if( next == 0 ) next = pc_thisbaseexp(sd);
  7321. if( get_percentage(sd->status.base_exp, next)% 10 == 0 ) // 0%, 10%, 20%, ...
  7322. {
  7323. switch (sd->state.snovice_call_flag) {
  7324. case 0:
  7325. if( strstr(message, msg_txt(504)) ) // "Guardian Angel, can you hear my voice? ^^;"
  7326. sd->state.snovice_call_flag++;
  7327. break;
  7328. case 1: {
  7329. char buf[256];
  7330. sprintf(buf, msg_txt(505), sd->status.name);
  7331. if( strstr(message, buf) ) // "My name is %s, and I'm a Super Novice~"
  7332. sd->state.snovice_call_flag++;
  7333. }
  7334. break;
  7335. case 2:
  7336. if( strstr(message, msg_txt(506)) ) // "Please help me~ T.T"
  7337. sd->state.snovice_call_flag++;
  7338. break;
  7339. case 3:
  7340. if( skillnotok(MO_EXPLOSIONSPIRITS,sd) )
  7341. break; //Do not override the noskill mapflag. [Skotlex]
  7342. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7343. sc_start(&sd->bl,status_skill2sc(MO_EXPLOSIONSPIRITS),100,
  7344. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7345. sd->state.snovice_call_flag = 0;
  7346. break;
  7347. }
  7348. }
  7349. }
  7350. // Chat logging type 'O' / Global Chat
  7351. if( log_config.chat&1 || (log_config.chat&2 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  7352. log_chat("O", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7353. return;
  7354. }
  7355. /*==========================================
  7356. * /mm /mapmove (as @rura GM command)
  7357. *------------------------------------------*/
  7358. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  7359. {
  7360. char output[MAP_NAME_LENGTH_EXT+15]; // Max length of a short: ' -6XXXX' -> 7 digits
  7361. char message[MAP_NAME_LENGTH_EXT+15+5]; // "/mm "+output
  7362. char* map_name;
  7363. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7364. return;
  7365. if(pc_isGM(sd) < get_atcommand_level(atcommand_mapmove))
  7366. return;
  7367. map_name = (char*)RFIFOP(fd,2);
  7368. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  7369. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7370. atcommand_mapmove(fd, sd, "@mapmove", output);
  7371. if( log_config.gm && get_atcommand_level(atcommand_mapmove) >= log_config.gm )
  7372. {
  7373. sprintf(message, "/mm %s", output);
  7374. log_atcommand(sd, message);
  7375. }
  7376. return;
  7377. }
  7378. /*==========================================
  7379. *
  7380. *------------------------------------------*/
  7381. void clif_changed_dir(struct block_list *bl, enum send_target target)
  7382. {
  7383. unsigned char buf[64];
  7384. WBUFW(buf,0) = 0x9c;
  7385. WBUFL(buf,2) = bl->id;
  7386. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7387. WBUFB(buf,8) = unit_getdir(bl);
  7388. clif_send(buf, packet_len(0x9c), bl, target);
  7389. if (disguised(bl)) {
  7390. WBUFL(buf,2) = -bl->id;
  7391. WBUFW(buf,6) = 0;
  7392. clif_send(buf, packet_len(0x9c), bl, SELF);
  7393. }
  7394. return;
  7395. }
  7396. /*==========================================
  7397. *
  7398. *------------------------------------------*/
  7399. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  7400. {
  7401. unsigned char headdir, dir;
  7402. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7403. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7404. pc_setdir(sd, dir, headdir);
  7405. clif_changed_dir(&sd->bl, AREA_WOS);
  7406. return;
  7407. }
  7408. /*==========================================
  7409. *
  7410. *------------------------------------------*/
  7411. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  7412. {
  7413. unsigned char buf[64];
  7414. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7415. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7416. clif_skill_fail(sd, 1, 0, 1);
  7417. return;
  7418. }
  7419. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7420. if (sd->emotionlasttime >= time(NULL)) {
  7421. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7422. clif_skill_fail(sd, 1, 0, 1);
  7423. return;
  7424. }
  7425. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7426. WBUFW(buf,0) = 0xc0;
  7427. WBUFL(buf,2) = sd->bl.id;
  7428. WBUFB(buf,6) = RFIFOB(fd,2);
  7429. clif_send(buf, packet_len(0xc0), &sd->bl, AREA);
  7430. } else
  7431. clif_skill_fail(sd, 1, 0, 1);
  7432. }
  7433. /*==========================================
  7434. *
  7435. *------------------------------------------*/
  7436. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  7437. {
  7438. WFIFOHEAD(fd,packet_len(0xc2));
  7439. WFIFOW(fd,0) = 0xc2;
  7440. WFIFOL(fd,2) = map_getusers();
  7441. WFIFOSET(fd,packet_len(0xc2));
  7442. }
  7443. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7444. {
  7445. if (pc_isdead(sd)) {
  7446. clif_clearunit_area(&sd->bl, 1);
  7447. return;
  7448. }
  7449. if (sd->sc.count &&
  7450. (sd->sc.data[SC_TRICKDEAD] ||
  7451. sd->sc.data[SC_AUTOCOUNTER] ||
  7452. sd->sc.data[SC_BLADESTOP]))
  7453. return;
  7454. pc_stop_walking(sd, 1);
  7455. pc_stop_attack(sd);
  7456. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7457. target_id = sd->bl.id;
  7458. switch(action_type)
  7459. {
  7460. case 0x00: // once attack
  7461. case 0x07: // continuous attack
  7462. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  7463. return;
  7464. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  7465. return;
  7466. if( sd->sc.data[SC_BASILICA] )
  7467. return;
  7468. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7469. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7470. clif_skill_fail(sd, 1, 4, 0);
  7471. return;
  7472. }
  7473. }
  7474. pc_delinvincibletimer(sd);
  7475. sd->idletime = last_tick;
  7476. unit_attack(&sd->bl, target_id, action_type != 0);
  7477. break;
  7478. case 0x02: // sitdown
  7479. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7480. clif_skill_fail(sd, 1, 0, 2);
  7481. break;
  7482. }
  7483. if(pc_issit(sd)) {
  7484. //Bugged client? Just refresh them.
  7485. clif_sitting(&sd->bl);
  7486. return;
  7487. }
  7488. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7489. break;
  7490. if (sd->sc.count && (
  7491. sd->sc.data[SC_DANCING] ||
  7492. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  7493. )) //No sitting during these states either.
  7494. break;
  7495. pc_setsit(sd);
  7496. skill_sit(sd,1);
  7497. clif_sitting(&sd->bl);
  7498. break;
  7499. case 0x03: // standup
  7500. if (!pc_issit(sd)) {
  7501. //Bugged client? Just refresh them.
  7502. clif_standing(&sd->bl);
  7503. return;
  7504. }
  7505. pc_setstand(sd);
  7506. skill_sit(sd,0);
  7507. clif_standing(&sd->bl);
  7508. break;
  7509. }
  7510. }
  7511. /*==========================================
  7512. *
  7513. *------------------------------------------*/
  7514. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  7515. {
  7516. clif_parse_ActionRequest_sub(sd,
  7517. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7518. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7519. gettick()
  7520. );
  7521. }
  7522. /*==========================================
  7523. *
  7524. *------------------------------------------*/
  7525. void clif_parse_Restart(int fd, struct map_session_data *sd)
  7526. {
  7527. switch(RFIFOB(fd,2)) {
  7528. case 0x00:
  7529. pc_respawn(sd,2);
  7530. break;
  7531. case 0x01:
  7532. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7533. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7534. { //Send to char-server for character selection.
  7535. chrif_charselectreq(sd, session[fd]->client_addr);
  7536. } else {
  7537. WFIFOHEAD(fd,packet_len(0x18b));
  7538. WFIFOW(fd,0)=0x18b;
  7539. WFIFOW(fd,2)=1;
  7540. WFIFOSET(fd,packet_len(0x018b));
  7541. }
  7542. break;
  7543. }
  7544. }
  7545. /*==========================================
  7546. * Validates and processes whispered messages
  7547. * S 0096 <packet len>.w <nick>.23B 00 <message>.?B
  7548. *------------------------------------------*/
  7549. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  7550. {
  7551. struct map_session_data* dstsd;
  7552. int i;
  7553. char *target, *message;
  7554. int namelen, messagelen;
  7555. // validate packet and retrieve name and message
  7556. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  7557. return;
  7558. if (is_atcommand(fd, sd, message, 1) )
  7559. return;
  7560. if (sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT))
  7561. return;
  7562. if (battle_config.min_chat_delay)
  7563. { //[Skotlex]
  7564. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  7565. return;
  7566. }
  7567. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7568. }
  7569. // Chat logging type 'W' / Whisper
  7570. if( log_config.chat&1 || (log_config.chat&4 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  7571. log_chat("W", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
  7572. //-------------------------------------------------------//
  7573. // Lordalfa - Paperboy - To whisper NPC commands //
  7574. //-------------------------------------------------------//
  7575. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  7576. {
  7577. char* str = target+4; //Skip the NPC: string part.
  7578. struct npc_data* npc;
  7579. if ((npc = npc_name2id(str)))
  7580. {
  7581. char split_data[10][50];
  7582. char *split;
  7583. char output[256];
  7584. str = message;
  7585. for( i = 0; i < 10; ++i )
  7586. {// Splits the message using '#' as separators
  7587. split = strchr(str,'#');
  7588. if( split == NULL )
  7589. { // use the remaining string
  7590. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7591. for( ++i; i < 10; ++i )
  7592. split_data[i][0] = '\0';
  7593. break;
  7594. }
  7595. *split = '\0';
  7596. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7597. str = split+1;
  7598. }
  7599. for( i = 0; i < 10; ++i )
  7600. {
  7601. sprintf(output, "@whispervar%d$", i);
  7602. set_var(sd,output,(char *) split_data[i]);
  7603. }
  7604. sprintf(output, "%s::OnWhisperGlobal", npc->name);
  7605. npc_event(sd,output,0); // Calls the NPC label
  7606. return;
  7607. }
  7608. }
  7609. // Main chat [LuzZza]
  7610. if(strcmpi(target, main_chat_nick) == 0)
  7611. {
  7612. if(!sd->state.mainchat)
  7613. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7614. else {
  7615. char output[256];
  7616. snprintf(output, ARRAYLENGTH(output), msg_txt(386), sd->status.name, message);
  7617. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7618. }
  7619. // Chat logging type 'M' / Main Chat
  7620. if( log_config.chat&1 || (log_config.chat&32 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  7621. log_chat("M", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7622. return;
  7623. }
  7624. // searching destination character
  7625. dstsd = map_nick2sd(target);
  7626. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
  7627. {
  7628. // player is not on this map-server
  7629. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7630. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7631. // and if we ask for 'Test', we must not contact 'test' player
  7632. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7633. intif_wis_message(sd, target, message, messagelen);
  7634. return;
  7635. }
  7636. // if player ignores everyone
  7637. if (dstsd->state.ignoreAll)
  7638. {
  7639. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7640. clif_wis_end(fd, 1); // 1: target character is not loged in
  7641. else
  7642. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7643. return;
  7644. }
  7645. // if player ignores the source character
  7646. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  7647. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  7648. { // source char present in ignore list
  7649. clif_wis_end(fd, 2); // 2: ignored by target
  7650. return;
  7651. }
  7652. // if player is autotrading
  7653. if( dstsd->state.autotrade == 1 )
  7654. {
  7655. char output[256];
  7656. sprintf(output, "%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  7657. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  7658. return;
  7659. }
  7660. // notify sender of success
  7661. clif_wis_end(fd, 0); // 0: success to send wisper
  7662. // if player has an auto-away message
  7663. if(dstsd->away_message[0] != '\0')
  7664. {
  7665. char output[256];
  7666. sprintf(output, "%s %s", message, msg_txt(543)); // "(Automessage has been sent)"
  7667. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  7668. if(dstsd->state.autotrade)
  7669. sprintf(output, msg_txt(544), dstsd->away_message); // "Away [AT] - "%s""
  7670. else
  7671. sprintf(output, msg_txt(545), dstsd->away_message); // "Away - "%s""
  7672. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  7673. return;
  7674. }
  7675. // Normal message
  7676. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  7677. return;
  7678. }
  7679. /*==========================================
  7680. * /b /nb
  7681. * S 0099 <packet len>.w <text>.?B 00
  7682. *------------------------------------------*/
  7683. void clif_parse_GMmessage(int fd, struct map_session_data* sd)
  7684. {
  7685. char* msg = (char*)RFIFOP(fd,4);
  7686. unsigned int len = RFIFOW(fd,2)-4;
  7687. int lv;
  7688. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  7689. return;
  7690. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_broadcast)) )
  7691. return;
  7692. // as the length varies depending on the command used, just block unreasonably long strings
  7693. mes_len_check(msg, len, CHAT_SIZE_MAX);
  7694. intif_GMmessage(msg, len, 0);
  7695. if(log_config.gm && lv >= log_config.gm) {
  7696. char logmsg[CHAT_SIZE_MAX+4];
  7697. sprintf(logmsg, "/b %s", msg);
  7698. log_atcommand(sd, logmsg);
  7699. }
  7700. }
  7701. /*==========================================
  7702. *
  7703. *------------------------------------------*/
  7704. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  7705. {
  7706. struct flooritem_data *fitem;
  7707. int map_object_id;
  7708. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7709. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  7710. do {
  7711. if (pc_isdead(sd)) {
  7712. clif_clearunit_area(&sd->bl, 1);
  7713. break;
  7714. }
  7715. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  7716. break;
  7717. if (pc_cant_act(sd))
  7718. break;
  7719. if(sd->sc.count && (
  7720. sd->sc.data[SC_HIDING] ||
  7721. sd->sc.data[SC_CLOAKING] ||
  7722. sd->sc.data[SC_TRICKDEAD] ||
  7723. sd->sc.data[SC_BLADESTOP] ||
  7724. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM))
  7725. )
  7726. break;
  7727. if (!pc_takeitem(sd, fitem))
  7728. break;
  7729. return;
  7730. } while (0);
  7731. // Client REQUIRES a fail packet or you can no longer pick items.
  7732. clif_additem(sd,0,0,6);
  7733. }
  7734. /*==========================================
  7735. *
  7736. *------------------------------------------*/
  7737. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  7738. {
  7739. int item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7740. int item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7741. do {
  7742. if (pc_isdead(sd))
  7743. break;
  7744. if (pc_cant_act(sd))
  7745. break;
  7746. if (sd->sc.count && (
  7747. sd->sc.data[SC_HIDING] ||
  7748. sd->sc.data[SC_AUTOCOUNTER] ||
  7749. sd->sc.data[SC_BLADESTOP] ||
  7750. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  7751. ))
  7752. break;
  7753. if (!pc_dropitem(sd, item_index, item_amount))
  7754. break;
  7755. return;
  7756. } while (0);
  7757. //Because the client does not like being ignored.
  7758. clif_delitem(sd, item_index,0);
  7759. }
  7760. /*==========================================
  7761. *
  7762. *------------------------------------------*/
  7763. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  7764. {
  7765. int n;
  7766. if (pc_isdead(sd)) {
  7767. clif_clearunit_area(&sd->bl, 1);
  7768. return;
  7769. }
  7770. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  7771. return;
  7772. //This flag enables you to use items while in an NPC. [Skotlex]
  7773. if (sd->npc_id) {
  7774. if (sd->npc_id != sd->npc_item_flag)
  7775. return;
  7776. } else
  7777. if (pc_istrading(sd))
  7778. return;
  7779. pc_delinvincibletimer(sd);
  7780. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  7781. sd->idletime = last_tick;
  7782. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7783. if(n <0 || n >= MAX_INVENTORY)
  7784. return;
  7785. if (!pc_useitem(sd,n))
  7786. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  7787. }
  7788. /*==========================================
  7789. *
  7790. *------------------------------------------*/
  7791. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  7792. {
  7793. int index;
  7794. if(pc_isdead(sd)) {
  7795. clif_clearunit_area(&sd->bl,1);
  7796. return;
  7797. }
  7798. index = RFIFOW(fd,2)-2;
  7799. if (index < 0 || index >= MAX_INVENTORY)
  7800. return; //Out of bounds check.
  7801. if(sd->npc_id) {
  7802. if (sd->npc_id != sd->npc_item_flag)
  7803. return;
  7804. } else if (sd->state.storage_flag || sd->sc.opt1)
  7805. ; //You can equip/unequip stuff while storage is open/under status changes
  7806. else if (pc_cant_act(sd))
  7807. return;
  7808. if(!sd->status.inventory[index].identify) {
  7809. clif_equipitemack(sd,index,0,0); // fail
  7810. return;
  7811. }
  7812. if(!sd->inventory_data[index])
  7813. return;
  7814. if(sd->inventory_data[index]->type == IT_PETARMOR){
  7815. pet_equipitem(sd,index);
  7816. return;
  7817. }
  7818. //Client doesn't send the position for ammo.
  7819. if(sd->inventory_data[index]->type == IT_AMMO)
  7820. pc_equipitem(sd,index,EQP_AMMO);
  7821. else
  7822. pc_equipitem(sd,index,RFIFOW(fd,4));
  7823. }
  7824. /*==========================================
  7825. *
  7826. *------------------------------------------*/
  7827. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  7828. {
  7829. int index;
  7830. if(pc_isdead(sd)) {
  7831. clif_clearunit_area(&sd->bl,1);
  7832. return;
  7833. }
  7834. if (sd->state.storage_flag)
  7835. ; //You can equip/unequip stuff while storage is open.
  7836. else if (pc_cant_act(sd))
  7837. return;
  7838. index = RFIFOW(fd,2)-2;
  7839. pc_unequipitem(sd,index,1);
  7840. }
  7841. /*==========================================
  7842. *
  7843. *------------------------------------------*/
  7844. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  7845. {
  7846. struct block_list *bl;
  7847. if(pc_isdead(sd)) {
  7848. clif_clearunit_area(&sd->bl,1);
  7849. return;
  7850. }
  7851. if (pc_cant_act(sd))
  7852. return;
  7853. bl = map_id2bl(RFIFOL(fd,2));
  7854. if (!bl) return;
  7855. switch (bl->type) {
  7856. case BL_MOB:
  7857. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7858. break;
  7859. case BL_PC:
  7860. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7861. break;
  7862. case BL_NPC:
  7863. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  7864. npc_click(sd,(TBL_NPC*)bl);
  7865. break;
  7866. }
  7867. return;
  7868. }
  7869. /*==========================================
  7870. *
  7871. *------------------------------------------*/
  7872. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  7873. {
  7874. if (sd->state.trading)
  7875. return;
  7876. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  7877. }
  7878. /// Request to buy chosen items from npc shop
  7879. /// S 00c8 <length>.w {<amount>.w <itemid>.w).4b*
  7880. /// R 00ca <result>.b
  7881. /// result = 00 -> "The deal has successfully completed."
  7882. /// result = 01 -> "You do not have enough zeny."
  7883. /// result = 02 -> "You are over your Weight Limit."
  7884. /// result = 03 -> "Out of the maximum capacity, you have too many items."
  7885. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  7886. {
  7887. int n = (RFIFOW(fd,2)-4) /4;
  7888. unsigned short* item_list = (unsigned short*)RFIFOP(fd,4);
  7889. int result;
  7890. if( sd->state.trading || !sd->npc_shopid )
  7891. result = 1;
  7892. else
  7893. result = npc_buylist(sd,n,item_list);
  7894. sd->npc_shopid = 0; //Clear shop data.
  7895. WFIFOHEAD(fd,packet_len(0xca));
  7896. WFIFOW(fd,0) = 0xca;
  7897. WFIFOB(fd,2) = result;
  7898. WFIFOSET(fd,packet_len(0xca));
  7899. }
  7900. /*==========================================
  7901. *
  7902. *------------------------------------------*/
  7903. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  7904. {
  7905. int fail=0,n;
  7906. unsigned short *item_list;
  7907. n = (RFIFOW(fd,2)-4) /4;
  7908. item_list = (unsigned short*)RFIFOP(fd,4);
  7909. if (sd->state.trading || !sd->npc_shopid)
  7910. fail = 1;
  7911. else
  7912. fail = npc_selllist(sd,n,item_list);
  7913. sd->npc_shopid = 0; //Clear shop data.
  7914. WFIFOHEAD(fd,packet_len(0xcb));
  7915. WFIFOW(fd,0)=0xcb;
  7916. WFIFOB(fd,2)=fail;
  7917. WFIFOSET(fd,packet_len(0xcb));
  7918. }
  7919. /*==========================================
  7920. * Chatroom creation request
  7921. * S 00d5 <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7922. *------------------------------------------*/
  7923. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  7924. {
  7925. int len = RFIFOW(fd,2)-15;
  7926. int limit = RFIFOW(fd,4);
  7927. bool pub = (RFIFOB(fd,6) != 0);
  7928. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  7929. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7930. char s_password[CHATROOM_PASS_SIZE];
  7931. char s_title[CHATROOM_TITLE_SIZE];
  7932. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  7933. return;
  7934. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  7935. clif_skill_fail(sd,1,0,3);
  7936. return;
  7937. }
  7938. if( len <= 0 )
  7939. return; // invalid input
  7940. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7941. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  7942. chat_createpcchat(sd, s_title, s_password, limit, pub);
  7943. }
  7944. /*==========================================
  7945. * Chatroom join request
  7946. * S 00d9 <chat ID>.l <passwd>.8B
  7947. *------------------------------------------*/
  7948. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  7949. {
  7950. int chatid = RFIFOL(fd,2);
  7951. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  7952. chat_joinchat(sd,chatid,password);
  7953. }
  7954. /*==========================================
  7955. * Chatroom properties adjustment request
  7956. * S 00de <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7957. *------------------------------------------*/
  7958. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  7959. {
  7960. int len = RFIFOW(fd,2)-15;
  7961. int limit = RFIFOW(fd,4);
  7962. bool pub = (RFIFOB(fd,6) != 0);
  7963. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  7964. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7965. char s_password[CHATROOM_PASS_SIZE];
  7966. char s_title[CHATROOM_TITLE_SIZE];
  7967. if( len <= 0 )
  7968. return; // invalid input
  7969. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7970. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  7971. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  7972. }
  7973. /*==========================================
  7974. * S 00e0 ?.l <nick>.24B
  7975. *------------------------------------------*/
  7976. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  7977. {
  7978. //TODO: the first argument seems to be the destination position (always 0) [ultramage]
  7979. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  7980. }
  7981. /*==========================================
  7982. *
  7983. *------------------------------------------*/
  7984. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  7985. {
  7986. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  7987. }
  7988. /*==========================================
  7989. * Request to leave the current chatroom
  7990. * S 00e3
  7991. *------------------------------------------*/
  7992. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  7993. {
  7994. chat_leavechat(sd,0);
  7995. }
  7996. //Handles notifying asker and rejecter of what has just ocurred.
  7997. //Type is used to determine the correct msg_txt to use:
  7998. //0:
  7999. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  8000. {
  8001. char *msg, output[256];
  8002. // Your request has been rejected by autoreject option.
  8003. msg = msg_txt(392);
  8004. clif_disp_onlyself(src, msg, strlen(msg));
  8005. //Notice that a request was rejected.
  8006. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  8007. clif_disp_onlyself(target, output, strlen(output));
  8008. }
  8009. /*==========================================
  8010. * 取引要請を相手に送る
  8011. *------------------------------------------*/
  8012. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8013. {
  8014. struct map_session_data *t_sd;
  8015. t_sd = map_id2sd(RFIFOL(fd,2));
  8016. if(!sd->chatID && pc_cant_act(sd))
  8017. return; //You can trade while in a chatroom.
  8018. // @noask [LuzZza]
  8019. if(t_sd && t_sd->state.noask) {
  8020. clif_noask_sub(sd, t_sd, 0);
  8021. return;
  8022. }
  8023. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1)
  8024. {
  8025. clif_skill_fail(sd,1,0,0);
  8026. return;
  8027. }
  8028. trade_traderequest(sd,t_sd);
  8029. }
  8030. /*==========================================
  8031. * 取引要請
  8032. *------------------------------------------*/
  8033. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8034. {
  8035. trade_tradeack(sd,RFIFOB(fd,2));
  8036. }
  8037. /*==========================================
  8038. * アイテム追加
  8039. *------------------------------------------*/
  8040. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8041. {
  8042. short index = RFIFOW(fd,2);
  8043. int amount = RFIFOL(fd,4);
  8044. if( index == 0 )
  8045. trade_tradeaddzeny(sd, amount);
  8046. else
  8047. trade_tradeadditem(sd, index, (short)amount);
  8048. }
  8049. /*==========================================
  8050. * アイテム追加完了(ok押し)
  8051. *------------------------------------------*/
  8052. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8053. {
  8054. trade_tradeok(sd);
  8055. }
  8056. /*==========================================
  8057. * 取引キャンセル
  8058. *------------------------------------------*/
  8059. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8060. {
  8061. trade_tradecancel(sd);
  8062. }
  8063. /*==========================================
  8064. * 取引許諾(trade押し)
  8065. *------------------------------------------*/
  8066. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8067. {
  8068. trade_tradecommit(sd);
  8069. }
  8070. /*==========================================
  8071. *
  8072. *------------------------------------------*/
  8073. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8074. {
  8075. pc_stop_attack(sd);
  8076. }
  8077. /*==========================================
  8078. * カートへアイテムを移す
  8079. *------------------------------------------*/
  8080. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8081. {
  8082. if (pc_istrading(sd))
  8083. return;
  8084. if (!pc_iscarton(sd))
  8085. return;
  8086. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8087. }
  8088. /*==========================================
  8089. * カートからアイテムを出す
  8090. *------------------------------------------*/
  8091. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8092. {
  8093. if (!pc_iscarton(sd))
  8094. return;
  8095. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8096. }
  8097. /*==========================================
  8098. * 付属品(鷹,ペコ,カート)をはずす
  8099. *------------------------------------------*/
  8100. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8101. {
  8102. //Can only remove Cart/Riding/Falcon.
  8103. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  8104. }
  8105. /*==========================================
  8106. * チェンジカート
  8107. *------------------------------------------*/
  8108. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8109. {
  8110. int type;
  8111. type = (int)RFIFOW(fd,2);
  8112. if( (type == 5 && sd->status.base_level > 90) ||
  8113. (type == 4 && sd->status.base_level > 80) ||
  8114. (type == 3 && sd->status.base_level > 65) ||
  8115. (type == 2 && sd->status.base_level > 40) ||
  8116. (type == 1))
  8117. pc_setcart(sd,type);
  8118. }
  8119. /*==========================================
  8120. * ステータスアップ
  8121. *------------------------------------------*/
  8122. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8123. {
  8124. pc_statusup(sd,RFIFOW(fd,2));
  8125. }
  8126. /*==========================================
  8127. * スキルレベルアップ
  8128. *------------------------------------------*/
  8129. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8130. {
  8131. pc_skillup(sd,RFIFOW(fd,2));
  8132. }
  8133. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, short skillnum, short skilllv, int target_id)
  8134. {
  8135. int lv;
  8136. if( !hd )
  8137. return;
  8138. if( skillnotok_hom(skillnum, hd) )
  8139. return;
  8140. if( hd->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8141. target_id = hd->bl.id;
  8142. if( hd->ud.skilltimer != -1 )
  8143. {
  8144. if( skillnum != SA_CASTCANCEL ) return;
  8145. }
  8146. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  8147. return;
  8148. lv = merc_hom_checkskill(hd, skillnum);
  8149. if( skilllv > lv )
  8150. skilllv = lv;
  8151. if( skilllv )
  8152. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  8153. }
  8154. static void clif_parse_UseSkillToId_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, short skillnum, short skilllv, int target_id)
  8155. {
  8156. int lv;
  8157. if( !md )
  8158. return;
  8159. if( skillnotok_mercenary(skillnum, md) )
  8160. return;
  8161. if( md->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8162. target_id = md->bl.id;
  8163. if( md->ud.skilltimer != INVALID_TIMER )
  8164. {
  8165. if( skillnum != SA_CASTCANCEL ) return;
  8166. }
  8167. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  8168. return;
  8169. lv = mercenary_checkskill(md, skillnum);
  8170. if( skilllv > lv )
  8171. skilllv = lv;
  8172. if( skilllv )
  8173. unit_skilluse_id(&md->bl, target_id, skillnum, skilllv);
  8174. }
  8175. static void clif_parse_UseSkillToPos_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, short skillnum, short skilllv, short x, short y, int skillmoreinfo)
  8176. {
  8177. int lv;
  8178. if( !md )
  8179. return;
  8180. if( skillnotok_mercenary(skillnum, md) )
  8181. return;
  8182. if( md->ud.skilltimer != INVALID_TIMER )
  8183. return;
  8184. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  8185. {
  8186. clif_skill_fail(md->master, skillnum, 4, 0);
  8187. return;
  8188. }
  8189. if( md->sc.data[SC_BASILICA] )
  8190. return;
  8191. lv = mercenary_checkskill(md, skillnum);
  8192. if( skilllv > lv )
  8193. skilllv = lv;
  8194. if( skilllv )
  8195. unit_skilluse_pos(&md->bl, x, y, skillnum, skilllv);
  8196. }
  8197. /*==========================================
  8198. * スキル使用(ID指定)
  8199. *------------------------------------------*/
  8200. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  8201. {
  8202. short skillnum, skilllv;
  8203. int tmp, target_id;
  8204. unsigned int tick = gettick();
  8205. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8206. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8207. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8208. if( skilllv < 1 ) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8209. tmp = skill_get_inf(skillnum);
  8210. if (tmp&INF_GROUND_SKILL || !tmp)
  8211. return; //Using a ground/passive skill on a target? WRONG.
  8212. if( skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE + MAX_HOMUNSKILL )
  8213. {
  8214. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  8215. return;
  8216. }
  8217. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  8218. {
  8219. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skillnum, skilllv, target_id);
  8220. return;
  8221. }
  8222. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8223. sd->idletime = last_tick;
  8224. if( pc_cant_act(sd) )
  8225. return;
  8226. if( pc_issit(sd) )
  8227. return;
  8228. if( skillnotok(skillnum, sd) )
  8229. return;
  8230. if( sd->bl.id != target_id && !sd->state.skill_flag && tmp&INF_SELF_SKILL )
  8231. target_id = sd->bl.id; // never trust the client
  8232. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  8233. target_id = sd->bl.id;
  8234. if( sd->ud.skilltimer != -1 )
  8235. {
  8236. if( skillnum != SA_CASTCANCEL )
  8237. return;
  8238. }
  8239. else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  8240. {
  8241. if( sd->skillitem != skillnum )
  8242. {
  8243. clif_skill_fail(sd, skillnum, 4, 0);
  8244. return;
  8245. }
  8246. }
  8247. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8248. return;
  8249. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  8250. return; // On basilica only caster can use Basilica again to stop it.
  8251. if( sd->menuskill_id )
  8252. {
  8253. if( sd->menuskill_id == SA_TAMINGMONSTER )
  8254. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8255. else if( sd->menuskill_id != SA_AUTOSPELL )
  8256. return; //Can't use skills while a menu is open.
  8257. }
  8258. if( sd->skillitem == skillnum )
  8259. {
  8260. if( skilllv != sd->skillitemlv )
  8261. skilllv = sd->skillitemlv;
  8262. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8263. return;
  8264. }
  8265. sd->skillitem = sd->skillitemlv = 0;
  8266. if( skillnum == MO_EXTREMITYFIST )
  8267. {
  8268. if( (!sd->sc.data[SC_COMBO] ||
  8269. (sd->sc.data[SC_COMBO]->val1 != MO_COMBOFINISH &&
  8270. sd->sc.data[SC_COMBO]->val1 != CH_TIGERFIST &&
  8271. sd->sc.data[SC_COMBO]->val1 != CH_CHAINCRUSH))) {
  8272. if( !sd->state.skill_flag )
  8273. {
  8274. sd->state.skill_flag = 1;
  8275. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8276. return;
  8277. } else if( sd->bl.id == target_id )
  8278. {
  8279. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8280. return;
  8281. }
  8282. }
  8283. }
  8284. if( skillnum == TK_JUMPKICK )
  8285. {
  8286. if( !sd->sc.data[SC_COMBO] || sd->sc.data[SC_COMBO]->val1 != TK_JUMPKICK )
  8287. {
  8288. if( !sd->state.skill_flag )
  8289. {
  8290. sd->state.skill_flag = 1;
  8291. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8292. return;
  8293. }
  8294. else if( sd->bl.id == target_id )
  8295. {
  8296. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8297. return;
  8298. }
  8299. }
  8300. }
  8301. if( skillnum >= GD_SKILLBASE )
  8302. {
  8303. if( sd->state.gmaster_flag )
  8304. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8305. else
  8306. skilllv = 0;
  8307. }
  8308. else
  8309. {
  8310. tmp = pc_checkskill(sd, skillnum);
  8311. if( skilllv > tmp )
  8312. skilllv = tmp;
  8313. }
  8314. pc_delinvincibletimer(sd);
  8315. if( skilllv )
  8316. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8317. if( sd->state.skill_flag )
  8318. sd->state.skill_flag = 0;
  8319. }
  8320. /*==========================================
  8321. * スキル使用(場所指定)
  8322. *------------------------------------------*/
  8323. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, short skilllv, short skillnum, short x, short y, int skillmoreinfo)
  8324. {
  8325. int lv;
  8326. unsigned int tick = gettick();
  8327. if( !(skill_get_inf(skillnum)&INF_GROUND_SKILL) )
  8328. return; //Using a target skill on the ground? WRONG.
  8329. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  8330. {
  8331. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skillnum, skilllv, x, y, skillmoreinfo);
  8332. return;
  8333. }
  8334. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8335. sd->idletime = last_tick;
  8336. if( skillnotok(skillnum, sd) )
  8337. return;
  8338. if( skillmoreinfo != -1 )
  8339. {
  8340. if( pc_issit(sd) )
  8341. {
  8342. clif_skill_fail(sd, skillnum, 0, 0);
  8343. return;
  8344. }
  8345. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  8346. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8347. }
  8348. if( sd->ud.skilltimer != -1 )
  8349. return;
  8350. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  8351. {
  8352. if( sd->skillitem != skillnum )
  8353. {
  8354. clif_skill_fail(sd, skillnum, 4, 0);
  8355. return;
  8356. }
  8357. }
  8358. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8359. return;
  8360. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  8361. return; // On basilica only caster can use Basilica again to stop it.
  8362. if( sd->menuskill_id )
  8363. {
  8364. if( sd->menuskill_id == SA_TAMINGMONSTER )
  8365. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8366. else if( sd->menuskill_id != SA_AUTOSPELL )
  8367. return; //Can't use skills while a menu is open.
  8368. }
  8369. pc_delinvincibletimer(sd);
  8370. if( sd->skillitem == skillnum )
  8371. {
  8372. if( skilllv != sd->skillitemlv )
  8373. skilllv = sd->skillitemlv;
  8374. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8375. }
  8376. else
  8377. {
  8378. sd->skillitem = sd->skillitemlv = 0;
  8379. if( (lv = pc_checkskill(sd, skillnum)) > 0 )
  8380. {
  8381. if( skilllv > lv )
  8382. skilllv = lv;
  8383. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8384. }
  8385. }
  8386. }
  8387. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  8388. {
  8389. if (pc_cant_act(sd))
  8390. return;
  8391. if (pc_issit(sd))
  8392. return;
  8393. clif_parse_UseSkillToPosSub(fd, sd,
  8394. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8395. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8396. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8397. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8398. -1 //Skill more info.
  8399. );
  8400. }
  8401. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  8402. {
  8403. if (pc_cant_act(sd))
  8404. return;
  8405. if (pc_issit(sd))
  8406. return;
  8407. clif_parse_UseSkillToPosSub(fd, sd,
  8408. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8409. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8410. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8411. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8412. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8413. );
  8414. }
  8415. /*==========================================
  8416. * スキル使用(map指定)
  8417. *------------------------------------------*/
  8418. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  8419. {
  8420. short skill_num = RFIFOW(fd,2);
  8421. char map_name[MAP_NAME_LENGTH];
  8422. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  8423. if(skill_num != sd->menuskill_id)
  8424. return;
  8425. if( pc_cant_act(sd) )
  8426. {
  8427. sd->menuskill_id = sd->menuskill_val = 0;
  8428. return;
  8429. }
  8430. pc_delinvincibletimer(sd);
  8431. skill_castend_map(sd,skill_num,map_name);
  8432. }
  8433. /*==========================================
  8434. * メモ要求
  8435. *------------------------------------------*/
  8436. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8437. {
  8438. if (!pc_isdead(sd))
  8439. pc_memo(sd,-1);
  8440. }
  8441. /*==========================================
  8442. * アイテム合成
  8443. *------------------------------------------*/
  8444. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8445. {
  8446. if (sd->menuskill_id != AM_PHARMACY)
  8447. return;
  8448. if (pc_istrading(sd)) {
  8449. //Make it fail to avoid shop exploits where you sell something different than you see.
  8450. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8451. sd->menuskill_val = sd->menuskill_id = 0;
  8452. return;
  8453. }
  8454. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8455. sd->menuskill_val = sd->menuskill_id = 0;
  8456. }
  8457. /*==========================================
  8458. *
  8459. *------------------------------------------*/
  8460. void clif_parse_Cooking(int fd,struct map_session_data *sd)
  8461. {
  8462. //int type = RFIFOW(fd,2); // '1' for cooking, but what do other values mean?
  8463. int nameid = RFIFOW(fd,4);
  8464. if (pc_istrading(sd)) {
  8465. //Make it fail to avoid shop exploits where you sell something different than you see.
  8466. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8467. sd->menuskill_val = sd->menuskill_id = 0;
  8468. return;
  8469. }
  8470. skill_produce_mix(sd,0,nameid,0,0,0,1);
  8471. sd->menuskill_val = sd->menuskill_id = 0;
  8472. }
  8473. /*==========================================
  8474. * 武器修理
  8475. *------------------------------------------*/
  8476. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8477. {
  8478. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8479. return;
  8480. if (pc_istrading(sd)) {
  8481. //Make it fail to avoid shop exploits where you sell something different than you see.
  8482. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8483. sd->menuskill_val = sd->menuskill_id = 0;
  8484. return;
  8485. }
  8486. skill_repairweapon(sd,RFIFOW(fd,2));
  8487. sd->menuskill_val = sd->menuskill_id = 0;
  8488. }
  8489. /*==========================================
  8490. *
  8491. *------------------------------------------*/
  8492. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  8493. {
  8494. int idx;
  8495. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8496. return;
  8497. if (pc_istrading(sd)) {
  8498. //Make it fail to avoid shop exploits where you sell something different than you see.
  8499. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8500. sd->menuskill_val = sd->menuskill_id = 0;
  8501. return;
  8502. }
  8503. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8504. skill_weaponrefine(sd, idx-2);
  8505. sd->menuskill_val = sd->menuskill_id = 0;
  8506. }
  8507. /*==========================================
  8508. *
  8509. *------------------------------------------*/
  8510. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8511. {
  8512. int npc_id = RFIFOL(fd,2);
  8513. uint8 select = RFIFOB(fd,6);
  8514. if( (select > sd->npc_menu && select != 0xff) || select == 0 )
  8515. {
  8516. TBL_NPC* nd = map_id2nd(npc_id);
  8517. 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);
  8518. clif_GM_kick(NULL,sd);
  8519. return;
  8520. }
  8521. sd->npc_menu = select;
  8522. npc_scriptcont(sd,npc_id);
  8523. }
  8524. /*==========================================
  8525. *
  8526. *------------------------------------------*/
  8527. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8528. {
  8529. npc_scriptcont(sd,RFIFOL(fd,2));
  8530. }
  8531. /*==========================================
  8532. * Value entered into a NPC input box.
  8533. * S 0143 <npcID>.l <amount>.l
  8534. *------------------------------------------*/
  8535. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8536. {
  8537. int npcid = RFIFOL(fd,2);
  8538. int amount = (int)RFIFOL(fd,6);
  8539. sd->npc_amount = amount;
  8540. npc_scriptcont(sd, npcid);
  8541. }
  8542. /*==========================================
  8543. * Text entered into a NPC input box.
  8544. * S 01d5 <len>.w <npcID>.l <input>.?B 00
  8545. *------------------------------------------*/
  8546. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  8547. {
  8548. int message_len = RFIFOW(fd,2)-8;
  8549. int npcid = RFIFOL(fd,4);
  8550. const char* message = (char*)RFIFOP(fd,8);
  8551. if( message_len <= 0 )
  8552. return; // invalid input
  8553. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  8554. npc_scriptcont(sd, npcid);
  8555. }
  8556. /*==========================================
  8557. *
  8558. *------------------------------------------*/
  8559. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8560. {
  8561. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8562. return;
  8563. npc_scriptcont(sd,RFIFOL(fd,2));
  8564. }
  8565. /*==========================================
  8566. * アイテム鑑定
  8567. *------------------------------------------*/
  8568. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8569. {
  8570. if (sd->menuskill_id != MC_IDENTIFY)
  8571. return;
  8572. skill_identify(sd,RFIFOW(fd,2)-2);
  8573. sd->menuskill_val = sd->menuskill_id = 0;
  8574. }
  8575. /*==========================================
  8576. * 矢作成
  8577. *------------------------------------------*/
  8578. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8579. {
  8580. if (sd->menuskill_id != AC_MAKINGARROW)
  8581. return;
  8582. if (pc_istrading(sd)) {
  8583. //Make it fail to avoid shop exploits where you sell something different than you see.
  8584. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8585. sd->menuskill_val = sd->menuskill_id = 0;
  8586. return;
  8587. }
  8588. skill_arrow_create(sd,RFIFOW(fd,2));
  8589. sd->menuskill_val = sd->menuskill_id = 0;
  8590. }
  8591. /*==========================================
  8592. * オートスペル受信
  8593. *------------------------------------------*/
  8594. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8595. {
  8596. if (sd->menuskill_id != SA_AUTOSPELL)
  8597. return;
  8598. skill_autospell(sd,RFIFOW(fd,2));
  8599. sd->menuskill_val = sd->menuskill_id = 0;
  8600. }
  8601. /*==========================================
  8602. * カード使用
  8603. *------------------------------------------*/
  8604. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8605. {
  8606. if (sd->state.trading != 0)
  8607. return;
  8608. clif_use_card(sd,RFIFOW(fd,2)-2);
  8609. }
  8610. /*==========================================
  8611. * カード挿入装備選択
  8612. *------------------------------------------*/
  8613. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8614. {
  8615. if (sd->state.trading != 0)
  8616. return;
  8617. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8618. }
  8619. /*==========================================
  8620. * 0193 キャラID名前引き
  8621. *------------------------------------------*/
  8622. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  8623. {
  8624. int charid;
  8625. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8626. map_reqnickdb(sd, charid);
  8627. }
  8628. /*==========================================
  8629. * 0197 /resetskill /resetstate
  8630. *------------------------------------------*/
  8631. void clif_parse_ResetChar(int fd, struct map_session_data *sd)
  8632. {
  8633. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8634. return;
  8635. if( pc_isGM(sd) < get_atcommand_level(atcommand_reset) )
  8636. return;
  8637. if( RFIFOW(fd,2) )
  8638. pc_resetskill(sd,1);
  8639. else
  8640. pc_resetstate(sd);
  8641. if( log_config.gm && get_atcommand_level(atcommand_reset) >= log_config.gm )
  8642. log_atcommand(sd, RFIFOW(fd,2) ? "/resetskill" : "/resetstate");
  8643. }
  8644. /*==========================================
  8645. * /lb /nlb
  8646. * S 019c <packet len>.w <text>.?B 00
  8647. *------------------------------------------*/
  8648. void clif_parse_LGMmessage(int fd, struct map_session_data* sd)
  8649. {
  8650. char* msg = (char*)RFIFOP(fd,4);
  8651. unsigned int len = RFIFOW(fd,2)-4;
  8652. int lv;
  8653. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8654. return;
  8655. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_localbroadcast)) )
  8656. return;
  8657. // as the length varies depending on the command used, just block unreasonably long strings
  8658. mes_len_check(msg, len, CHAT_SIZE_MAX);
  8659. clif_GMmessage(&sd->bl, msg, len, 1);
  8660. if( log_config.gm && lv >= log_config.gm ) {
  8661. char logmsg[CHAT_SIZE_MAX+5];
  8662. sprintf(logmsg, "/lb %s", msg);
  8663. log_atcommand(sd, logmsg);
  8664. }
  8665. }
  8666. /*==========================================
  8667. * カプラ倉庫へ入れる
  8668. *------------------------------------------*/
  8669. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  8670. {
  8671. int item_index, item_amount;
  8672. if (pc_istrading(sd))
  8673. return;
  8674. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8675. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8676. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  8677. return;
  8678. if (sd->state.storage_flag == 1)
  8679. storage_storageadd(sd, item_index, item_amount);
  8680. else
  8681. if (sd->state.storage_flag == 2)
  8682. storage_guild_storageadd(sd, item_index, item_amount);
  8683. }
  8684. /*==========================================
  8685. * カプラ倉庫から出す
  8686. *------------------------------------------*/
  8687. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  8688. {
  8689. int item_index, item_amount;
  8690. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8691. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8692. if (sd->state.storage_flag == 1)
  8693. storage_storageget(sd, item_index, item_amount);
  8694. else
  8695. if(sd->state.storage_flag == 2)
  8696. storage_guild_storageget(sd, item_index, item_amount);
  8697. }
  8698. /*==========================================
  8699. * カプラ倉庫へカートから入れる
  8700. *------------------------------------------*/
  8701. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  8702. {
  8703. if(sd->vender_id)
  8704. return;
  8705. if (!pc_iscarton(sd))
  8706. return;
  8707. if (sd->state.storage_flag == 1)
  8708. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8709. else
  8710. if (sd->state.storage_flag == 2)
  8711. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8712. }
  8713. /*==========================================
  8714. * カプラ倉庫から出す
  8715. *------------------------------------------*/
  8716. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  8717. {
  8718. if (sd->vender_id)
  8719. return;
  8720. if (!pc_iscarton(sd))
  8721. return;
  8722. if (sd->state.storage_flag == 1)
  8723. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8724. else
  8725. if (sd->state.storage_flag == 2)
  8726. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8727. }
  8728. /*==========================================
  8729. * カプラ倉庫を閉じる
  8730. *------------------------------------------*/
  8731. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  8732. {
  8733. if( sd->state.storage_flag == 1 )
  8734. storage_storageclose(sd);
  8735. else
  8736. if( sd->state.storage_flag == 2 )
  8737. storage_guild_storageclose(sd);
  8738. }
  8739. /*==========================================
  8740. * Kafra storage protection password system
  8741. *------------------------------------------*/
  8742. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  8743. {
  8744. //TODO
  8745. }
  8746. /*==========================================
  8747. * Party creation request
  8748. * S 00f9 <party name>.24S
  8749. * S 01e8 <party name>.24S <item1>.B <item2>.B
  8750. *------------------------------------------*/
  8751. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  8752. {
  8753. char* name = (char*)RFIFOP(fd,2);
  8754. name[NAME_LENGTH-1] = '\0';
  8755. if( map[sd->bl.m].flag.partylock )
  8756. {// Party locked.
  8757. clif_displaymessage(fd, msg_txt(227));
  8758. return;
  8759. }
  8760. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  8761. {
  8762. clif_skill_fail(sd,1,0,4);
  8763. return;
  8764. }
  8765. party_create(sd,name,0,0);
  8766. }
  8767. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  8768. {
  8769. char* name = (char*)RFIFOP(fd,2);
  8770. int item1 = RFIFOB(fd,26);
  8771. int item2 = RFIFOB(fd,27);
  8772. name[NAME_LENGTH-1] = '\0';
  8773. if( map[sd->bl.m].flag.partylock )
  8774. {// Party locked.
  8775. clif_displaymessage(fd, msg_txt(227));
  8776. return;
  8777. }
  8778. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  8779. {
  8780. clif_skill_fail(sd,1,0,4);
  8781. return;
  8782. }
  8783. party_create(sd,name,item1,item2);
  8784. }
  8785. /*==========================================
  8786. * Party invitation request
  8787. * S 00fc <account ID>.L
  8788. * S 02c4 <char name>.24S
  8789. *------------------------------------------*/
  8790. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  8791. {
  8792. struct map_session_data *t_sd;
  8793. if(map[sd->bl.m].flag.partylock)
  8794. {// Party locked.
  8795. clif_displaymessage(fd, msg_txt(227));
  8796. return;
  8797. }
  8798. t_sd = map_id2sd(RFIFOL(fd,2));
  8799. if(t_sd && t_sd->state.noask)
  8800. {// @noask [LuzZza]
  8801. clif_noask_sub(sd, t_sd, 1);
  8802. return;
  8803. }
  8804. party_invite(sd, t_sd);
  8805. }
  8806. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  8807. {
  8808. struct map_session_data *t_sd;
  8809. char *name = (char*)RFIFOP(fd,2);
  8810. name[NAME_LENGTH-1] = '\0';
  8811. if(map[sd->bl.m].flag.partylock)
  8812. {// Party locked.
  8813. clif_displaymessage(fd, msg_txt(227));
  8814. return;
  8815. }
  8816. t_sd = map_nick2sd(name);
  8817. if(t_sd && t_sd->state.noask)
  8818. {// @noask [LuzZza]
  8819. clif_noask_sub(sd, t_sd, 1);
  8820. return;
  8821. }
  8822. party_invite(sd, t_sd);
  8823. }
  8824. /*==========================================
  8825. * Party invitation reply
  8826. * S 00ff <account ID>.L <flag>.L
  8827. * S 02c7 <account ID>.L <flag>.B
  8828. * flag: 0-reject, 1-accept
  8829. *------------------------------------------*/
  8830. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  8831. {
  8832. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8833. }
  8834. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  8835. {
  8836. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8837. }
  8838. /*==========================================
  8839. * パーティ脱退要求
  8840. *------------------------------------------*/
  8841. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  8842. {
  8843. if(map[sd->bl.m].flag.partylock)
  8844. { //Guild locked.
  8845. clif_displaymessage(fd, msg_txt(227));
  8846. return;
  8847. }
  8848. party_leave(sd);
  8849. }
  8850. /*==========================================
  8851. * パーティ除名要求
  8852. *------------------------------------------*/
  8853. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  8854. {
  8855. if(map[sd->bl.m].flag.partylock)
  8856. { //Guild locked.
  8857. clif_displaymessage(fd, msg_txt(227));
  8858. return;
  8859. }
  8860. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8861. }
  8862. /*==========================================
  8863. * パーティ設定変更要求
  8864. *------------------------------------------*/
  8865. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  8866. {
  8867. struct party_data *p;
  8868. int i;
  8869. if( !sd->status.party_id )
  8870. return;
  8871. p = party_search(sd->status.party_id);
  8872. if( p == NULL )
  8873. return;
  8874. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  8875. if( i == MAX_PARTY )
  8876. return; //Shouldn't happen
  8877. if( !p->party.member[i].leader )
  8878. return;
  8879. //The client no longer can change the item-field, therefore it always
  8880. //comes as zero. Here, resend the item data as it is.
  8881. // party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  8882. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  8883. }
  8884. /*==========================================
  8885. * Validates and processes party messages
  8886. * S 0108 <packet len>.w <text>.?B (<name> : <message>) 00
  8887. *------------------------------------------*/
  8888. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  8889. {
  8890. const char* text = (char*)RFIFOP(fd,4);
  8891. int textlen = RFIFOW(fd,2) - 4;
  8892. char *name, *message;
  8893. int namelen, messagelen;
  8894. // validate packet and retrieve name and message
  8895. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8896. return;
  8897. if( is_atcommand(fd, sd, message, 1) )
  8898. return;
  8899. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8900. return;
  8901. if( battle_config.min_chat_delay )
  8902. { //[Skotlex]
  8903. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8904. return;
  8905. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8906. }
  8907. party_send_message(sd, text, textlen);
  8908. }
  8909. /*==========================================
  8910. * 露店閉鎖
  8911. *------------------------------------------*/
  8912. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  8913. {
  8914. vending_closevending(sd);
  8915. }
  8916. /*==========================================
  8917. * 露店アイテムリスト要求
  8918. *------------------------------------------*/
  8919. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  8920. {
  8921. vending_vendinglistreq(sd,RFIFOL(fd,2));
  8922. if( sd->npc_id )
  8923. npc_event_dequeue(sd);
  8924. }
  8925. /*==========================================
  8926. * Shop item(s) purchase request
  8927. * S 0134 <len>.w <ID>.l {<amount>.w <index>.w}.4B*
  8928. *------------------------------------------*/
  8929. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  8930. {
  8931. int len = (int)RFIFOW(fd,2) - 8;
  8932. int id = (int)RFIFOL(fd,4);
  8933. const uint8* data = (uint8*)RFIFOP(fd,8);
  8934. vending_purchasereq(sd, id, data, len/4);
  8935. }
  8936. /*==========================================
  8937. * Confirm or cancel the shop preparation window
  8938. * S 01b2 <len>.w <message>.80B <flag>.B {<index>.w <amount>.w <value>.l}.8B*
  8939. * flag: 0=cancel, 1=confirm
  8940. *------------------------------------------*/
  8941. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  8942. {
  8943. short len = (short)RFIFOW(fd,2) - 85;
  8944. const char* message = (char*)RFIFOP(fd,4);
  8945. bool flag = (bool)RFIFOB(fd,84);
  8946. const uint8* data = (uint8*)RFIFOP(fd,85);
  8947. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  8948. return;
  8949. if( map[sd->bl.m].flag.novending || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  8950. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open a shop on this map"
  8951. return;
  8952. }
  8953. if( message[0] == '\0' ) // invalid input
  8954. return;
  8955. vending_openvending(sd, message, flag, data, len/8);
  8956. }
  8957. /*==========================================
  8958. * Guild creation request
  8959. * S 0165 <account id>.L <guild name>.24S
  8960. *------------------------------------------*/
  8961. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  8962. {
  8963. char* name = (char*)RFIFOP(fd,6);
  8964. name[NAME_LENGTH-1] = '\0';
  8965. if(map[sd->bl.m].flag.guildlock)
  8966. { //Guild locked.
  8967. clif_displaymessage(fd, msg_txt(228));
  8968. return;
  8969. }
  8970. guild_create(sd, name);
  8971. }
  8972. /*==========================================
  8973. * ギルドマスターかどうか確認
  8974. *------------------------------------------*/
  8975. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  8976. {
  8977. clif_guild_masterormember(sd);
  8978. }
  8979. /*==========================================
  8980. * ギルド情報要求
  8981. *------------------------------------------*/
  8982. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  8983. {
  8984. if( !sd->status.guild_id && !sd->state.bg_id )
  8985. return;
  8986. switch( RFIFOL(fd,2) )
  8987. {
  8988. case 0: // ギルド基本情報、同盟敵対情報
  8989. clif_guild_basicinfo(sd);
  8990. clif_guild_allianceinfo(sd);
  8991. break;
  8992. case 1: // メンバーリスト、役職名リスト
  8993. clif_guild_positionnamelist(sd);
  8994. clif_guild_memberlist(sd);
  8995. break;
  8996. case 2: // 役職名リスト、役職情報リスト
  8997. clif_guild_positionnamelist(sd);
  8998. clif_guild_positioninfolist(sd);
  8999. break;
  9000. case 3: // スキルリスト
  9001. clif_guild_skillinfo(sd);
  9002. break;
  9003. case 4: // 追放リスト
  9004. clif_guild_expulsionlist(sd);
  9005. break;
  9006. default:
  9007. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  9008. break;
  9009. }
  9010. }
  9011. /*==========================================
  9012. * ギルド役職変更
  9013. *------------------------------------------*/
  9014. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  9015. {
  9016. int i;
  9017. if(!sd->state.gmaster_flag)
  9018. return;
  9019. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  9020. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  9021. }
  9022. }
  9023. /*==========================================
  9024. * ギルドメンバ役職変更
  9025. *------------------------------------------*/
  9026. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  9027. {
  9028. int i;
  9029. if(!sd->state.gmaster_flag)
  9030. return;
  9031. for(i=4;i<RFIFOW(fd,2);i+=12){
  9032. guild_change_memberposition(sd->status.guild_id,
  9033. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  9034. }
  9035. }
  9036. /*==========================================
  9037. * ギルドエンブレム要求
  9038. *------------------------------------------*/
  9039. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  9040. {
  9041. struct guild* g;
  9042. int guild_id = RFIFOL(fd,2);
  9043. if( (g = guild_search(guild_id)) != NULL )
  9044. clif_guild_emblem(sd,g);
  9045. }
  9046. /*==========================================
  9047. * ギルドエンブレム変更
  9048. *------------------------------------------*/
  9049. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  9050. {
  9051. if(!sd->state.gmaster_flag)
  9052. return;
  9053. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  9054. }
  9055. /*==========================================
  9056. * Guild notice update request
  9057. * S 016E <guildID>.l <msg1>.60B <msg2>.120B
  9058. *------------------------------------------*/
  9059. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  9060. {
  9061. int guild_id = RFIFOL(fd,2);
  9062. char* msg1 = (char*)RFIFOP(fd,6);
  9063. char* msg2 = (char*)RFIFOP(fd,66);
  9064. if(!sd->state.gmaster_flag)
  9065. return;
  9066. // compensate for some client defects when using multilanguage mode
  9067. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  9068. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  9069. if (msg2[0] == '|') msg2[strnlen(msg2, 120)-1] = '\0'; // delete extra space at the end of string
  9070. guild_change_notice(sd, guild_id, msg1, msg2);
  9071. }
  9072. /*==========================================
  9073. * ギルド勧誘
  9074. *------------------------------------------*/
  9075. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  9076. {
  9077. struct map_session_data *t_sd;
  9078. if(map[sd->bl.m].flag.guildlock)
  9079. { //Guild locked.
  9080. clif_displaymessage(fd, msg_txt(228));
  9081. return;
  9082. }
  9083. t_sd = map_id2sd(RFIFOL(fd,2));
  9084. // @noask [LuzZza]
  9085. if(t_sd && t_sd->state.noask) {
  9086. clif_noask_sub(sd, t_sd, 2);
  9087. return;
  9088. }
  9089. guild_invite(sd,t_sd);
  9090. }
  9091. /*==========================================
  9092. * ギルド勧誘返信
  9093. *------------------------------------------*/
  9094. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  9095. {
  9096. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9097. }
  9098. /*==========================================
  9099. * ギルド脱退
  9100. *------------------------------------------*/
  9101. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  9102. {
  9103. if(map[sd->bl.m].flag.guildlock)
  9104. { //Guild locked.
  9105. clif_displaymessage(fd, msg_txt(228));
  9106. return;
  9107. }
  9108. if( sd->state.bg_id )
  9109. {
  9110. clif_displaymessage(fd, "You can't leave battleground guilds.");
  9111. return;
  9112. }
  9113. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9114. }
  9115. /*==========================================
  9116. * Request to expel a member of a guild
  9117. * S 015b <guild_id>.L <account_id>.L <char_id>.L <reason>.39B 00
  9118. *------------------------------------------*/
  9119. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  9120. {
  9121. if( map[sd->bl.m].flag.guildlock || sd->state.bg_id )
  9122. { // Guild locked.
  9123. clif_displaymessage(fd, msg_txt(228));
  9124. return;
  9125. }
  9126. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9127. }
  9128. /*==========================================
  9129. * Validates and processes guild messages
  9130. * S 017e <packet len>.w <text>.?B (<name> : <message>) 00
  9131. *------------------------------------------*/
  9132. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  9133. {
  9134. const char* text = (char*)RFIFOP(fd,4);
  9135. int textlen = RFIFOW(fd,2) - 4;
  9136. char *name, *message;
  9137. int namelen, messagelen;
  9138. // validate packet and retrieve name and message
  9139. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9140. return;
  9141. if( is_atcommand(fd, sd, message, 1) )
  9142. return;
  9143. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  9144. return;
  9145. if( battle_config.min_chat_delay )
  9146. { //[Skotlex]
  9147. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9148. return;
  9149. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9150. }
  9151. if( sd->state.bg_id )
  9152. bg_send_message(sd, text, textlen);
  9153. else
  9154. guild_send_message(sd, text, textlen);
  9155. }
  9156. /*==========================================
  9157. * ギルド同盟要求
  9158. *------------------------------------------*/
  9159. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  9160. {
  9161. struct map_session_data *t_sd;
  9162. if(!sd->state.gmaster_flag)
  9163. return;
  9164. if(map[sd->bl.m].flag.guildlock)
  9165. { //Guild locked.
  9166. clif_displaymessage(fd, msg_txt(228));
  9167. return;
  9168. }
  9169. t_sd = map_id2sd(RFIFOL(fd,2));
  9170. // @noask [LuzZza]
  9171. if(t_sd && t_sd->state.noask) {
  9172. clif_noask_sub(sd, t_sd, 3);
  9173. return;
  9174. }
  9175. guild_reqalliance(sd,t_sd);
  9176. }
  9177. /*==========================================
  9178. * ギルド同盟要求返信
  9179. *------------------------------------------*/
  9180. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  9181. {
  9182. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9183. }
  9184. /*==========================================
  9185. * ギルド関係解消
  9186. *------------------------------------------*/
  9187. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  9188. {
  9189. if(!sd->state.gmaster_flag)
  9190. return;
  9191. if(map[sd->bl.m].flag.guildlock)
  9192. { //Guild locked.
  9193. clif_displaymessage(fd, msg_txt(228));
  9194. return;
  9195. }
  9196. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9197. }
  9198. /*==========================================
  9199. * ギルド敵対
  9200. *------------------------------------------*/
  9201. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  9202. {
  9203. struct map_session_data *t_sd;
  9204. if(!sd->state.gmaster_flag)
  9205. return;
  9206. if(map[sd->bl.m].flag.guildlock)
  9207. { //Guild locked.
  9208. clif_displaymessage(fd, msg_txt(228));
  9209. return;
  9210. }
  9211. t_sd = map_id2sd(RFIFOL(fd,2));
  9212. // @noask [LuzZza]
  9213. if(t_sd && t_sd->state.noask) {
  9214. clif_noask_sub(sd, t_sd, 4);
  9215. return;
  9216. }
  9217. guild_opposition(sd,t_sd);
  9218. }
  9219. /*==========================================
  9220. * ギルド解散
  9221. *------------------------------------------*/
  9222. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  9223. {
  9224. if( map[sd->bl.m].flag.guildlock )
  9225. { //Guild locked.
  9226. clif_displaymessage(fd, msg_txt(228));
  9227. return;
  9228. }
  9229. guild_break(sd,(char*)RFIFOP(fd,2));
  9230. }
  9231. // pet
  9232. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  9233. {
  9234. pet_menu(sd,RFIFOB(fd,2));
  9235. }
  9236. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  9237. {
  9238. pet_catch_process2(sd,RFIFOL(fd,2));
  9239. }
  9240. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  9241. {
  9242. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  9243. {
  9244. //Forged packet, disconnect them [Kevin]
  9245. clif_authfail_fd(fd, 0);
  9246. return;
  9247. }
  9248. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9249. sd->menuskill_val = sd->menuskill_id = 0;
  9250. }
  9251. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  9252. {
  9253. if(sd->pd)
  9254. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9255. }
  9256. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  9257. {
  9258. pet_change_name(sd,(char*)RFIFOP(fd,2));
  9259. }
  9260. /*==========================================
  9261. * /kill <???>
  9262. * (or right click menu for GM "(name) force to quit")
  9263. * S 00cc <id>.L
  9264. *------------------------------------------*/
  9265. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  9266. {
  9267. struct block_list *target;
  9268. int tid,lv;
  9269. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9270. return;
  9271. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_kick)) )
  9272. return;
  9273. tid = RFIFOL(fd,2);
  9274. target = map_id2bl(tid);
  9275. if (!target) {
  9276. clif_GM_kickack(sd, 0);
  9277. return;
  9278. }
  9279. switch (target->type) {
  9280. case BL_PC:
  9281. {
  9282. struct map_session_data *tsd = (struct map_session_data *)target;
  9283. if (pc_isGM(sd) <= pc_isGM(tsd)) {
  9284. clif_GM_kickack(sd, 0);
  9285. return;
  9286. }
  9287. clif_GM_kick(sd, tsd);
  9288. if(log_config.gm && lv >= log_config.gm) {
  9289. char message[256];
  9290. sprintf(message, "/kick %s (%d)", tsd->status.name, tsd->status.char_id);
  9291. log_atcommand(sd, message);
  9292. }
  9293. }
  9294. break;
  9295. case BL_MOB:
  9296. status_percent_damage(&sd->bl, target, 100, 0, true);
  9297. if(log_config.gm && lv >= log_config.gm) {
  9298. char message[256];
  9299. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9300. log_atcommand(sd, message);
  9301. }
  9302. break;
  9303. case BL_NPC:
  9304. {
  9305. struct npc_data* nd = (struct npc_data *)target;
  9306. lv = get_atcommand_level(atcommand_unloadnpc);
  9307. if( pc_isGM(sd) < lv )
  9308. return;
  9309. // copy-pasted from atcommand_unloadnpc
  9310. npc_unload_duplicates(nd);
  9311. npc_unload(nd);
  9312. npc_read_event_script();
  9313. if( log_config.gm && lv >= log_config.gm ) {
  9314. char message[256];
  9315. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9316. log_atcommand(sd, message);
  9317. }
  9318. }
  9319. break;
  9320. default:
  9321. clif_GM_kickack(sd, 0);
  9322. }
  9323. }
  9324. /*==========================================
  9325. * /killall
  9326. *------------------------------------------*/
  9327. void clif_parse_GMKickAll(int fd, struct map_session_data* sd)
  9328. {
  9329. is_atcommand(fd, sd, "@kickall", 1);
  9330. }
  9331. /*==========================================
  9332. * /shift <name>
  9333. *------------------------------------------*/
  9334. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  9335. {
  9336. char *player_name;
  9337. int lv;
  9338. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9339. return;
  9340. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_jumpto)) )
  9341. return;
  9342. player_name = (char*)RFIFOP(fd,2);
  9343. player_name[NAME_LENGTH-1] = '\0';
  9344. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9345. if( log_config.gm && lv >= log_config.gm ) {
  9346. char message[NAME_LENGTH+7];
  9347. sprintf(message, "/shift %s", player_name);
  9348. log_atcommand(sd, message);
  9349. }
  9350. }
  9351. /*==========================================
  9352. * /recall <name>
  9353. *------------------------------------------*/
  9354. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  9355. {
  9356. char *player_name;
  9357. int lv;
  9358. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9359. return;
  9360. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_recall)) )
  9361. return;
  9362. player_name = (char*)RFIFOP(fd,2);
  9363. player_name[NAME_LENGTH-1] = '\0';
  9364. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9365. if( log_config.gm && lv >= log_config.gm ) {
  9366. char message[NAME_LENGTH+8];
  9367. sprintf(message, "/recall %s", player_name);
  9368. log_atcommand(sd, message);
  9369. }
  9370. }
  9371. /*==========================================
  9372. * /monster /item
  9373. *------------------------------------------*/
  9374. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  9375. {
  9376. char *monster_item_name;
  9377. char message[NAME_LENGTH+10]; //For logging.
  9378. int level;
  9379. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9380. return;
  9381. monster_item_name = (char*)RFIFOP(fd,2);
  9382. monster_item_name[NAME_LENGTH-1] = '\0';
  9383. if( mobdb_searchname(monster_item_name) ) {
  9384. if( pc_isGM(sd) < (level=get_atcommand_level(atcommand_monster)) )
  9385. return;
  9386. atcommand_monster(fd, sd, "@monster", monster_item_name); // as @monster
  9387. if( log_config.gm && level >= log_config.gm )
  9388. { //Log action. [Skotlex]
  9389. snprintf(message, sizeof(message)-1, "@spawn %s", monster_item_name);
  9390. log_atcommand(sd, message);
  9391. }
  9392. return;
  9393. }
  9394. if( itemdb_searchname(monster_item_name) == NULL )
  9395. return;
  9396. if( pc_isGM(sd) < (level = get_atcommand_level(atcommand_item)) )
  9397. return;
  9398. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9399. if( log_config.gm && level >= log_config.gm )
  9400. { //Log action. [Skotlex]
  9401. sprintf(message, "@item %s", monster_item_name);
  9402. log_atcommand(sd, message);
  9403. }
  9404. }
  9405. /*==========================================
  9406. * /hide
  9407. *------------------------------------------*/
  9408. void clif_parse_GMHide(int fd, struct map_session_data *sd)
  9409. {
  9410. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9411. return;
  9412. if( pc_isGM(sd) < get_atcommand_level(atcommand_hide) )
  9413. return;
  9414. if( sd->sc.option & OPTION_INVISIBLE ) {
  9415. sd->sc.option &= ~OPTION_INVISIBLE;
  9416. if (sd->disguise)
  9417. status_set_viewdata(&sd->bl, sd->disguise);
  9418. else
  9419. status_set_viewdata(&sd->bl, sd->status.class_);
  9420. clif_displaymessage(fd, "Invisible: Off.");
  9421. } else {
  9422. sd->sc.option |= OPTION_INVISIBLE;
  9423. sd->vd.class_ = INVISIBLE_CLASS;
  9424. clif_displaymessage(fd, "Invisible: On.");
  9425. if( log_config.gm && get_atcommand_level(atcommand_hide) >= log_config.gm )
  9426. log_atcommand(sd, "/hide");
  9427. }
  9428. clif_changeoption(&sd->bl);
  9429. }
  9430. /*==========================================
  9431. * GM adjustment of a player's manner value (right-click GM menu)
  9432. * S 0149 <id>.L <type>.B <value>.W
  9433. * type: 0 - positive points
  9434. * 1 - negative points
  9435. * 2 - self mute (+10 minutes)
  9436. *------------------------------------------*/
  9437. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9438. {
  9439. int id, type, value, level;
  9440. struct map_session_data *dstsd;
  9441. id = RFIFOL(fd,2);
  9442. type = RFIFOB(fd,6);
  9443. value = RFIFOW(fd,7);
  9444. if( type == 0 )
  9445. value = 0 - value;
  9446. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  9447. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  9448. if (type == 2 /* && (pc_isGM(sd) > 0 || sd->bl.id != id)*/)
  9449. return;
  9450. dstsd = map_id2sd(id);
  9451. if( dstsd == NULL )
  9452. return;
  9453. if( (level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(atcommand_mute) )
  9454. {
  9455. clif_manner_message(sd, 0);
  9456. clif_manner_message(dstsd, 5);
  9457. if( dstsd->status.manner < value ) {
  9458. dstsd->status.manner -= value;
  9459. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  9460. } else {
  9461. dstsd->status.manner = 0;
  9462. status_change_end(&dstsd->bl,SC_NOCHAT,-1);
  9463. }
  9464. if( type != 2 )
  9465. clif_GM_silence(sd, dstsd, type);
  9466. }
  9467. }
  9468. /*==========================================
  9469. * GM adjustment of a player's manner value by -60 (using name)
  9470. * /rc <name>
  9471. * S 0212 <name>.24B
  9472. *------------------------------------------*/
  9473. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  9474. {
  9475. char* name = (char*)RFIFOP(fd,2);
  9476. struct map_session_data* dstsd;
  9477. name[23] = '\0';
  9478. dstsd = map_nick2sd(name);
  9479. if( dstsd == NULL )
  9480. return;
  9481. if( pc_isGM(sd) > pc_isGM(dstsd) && pc_isGM(sd) >= get_atcommand_level(atcommand_mute) )
  9482. {
  9483. clif_manner_message(sd, 0);
  9484. clif_manner_message(dstsd, 3);
  9485. dstsd->status.manner -= 60;
  9486. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  9487. clif_GM_silence(sd, dstsd, 1);
  9488. }
  9489. }
  9490. /*==========================================
  9491. * GM requesting account name (for right-click gm menu)
  9492. * S 01df <id>.L
  9493. * R 01e0 <id>.L <name>.24B
  9494. *------------------------------------------*/
  9495. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  9496. {
  9497. int tid;
  9498. tid = RFIFOL(fd,2);
  9499. //TODO: find out if this works for any player or only for authorized GMs
  9500. WFIFOHEAD(fd,packet_len(0x1e0));
  9501. WFIFOW(fd,0) = 0x1e0;
  9502. WFIFOL(fd,2) = tid;
  9503. safestrncpy((char*)WFIFOP(fd,6), "", 24); // insert account name here >_<
  9504. WFIFOSET(fd, packet_len(0x1e0));
  9505. }
  9506. /*==========================================
  9507. * GM single cell type change request
  9508. * /changemaptype <x> <y> <type>
  9509. * S 0198 <x>.W <y>.W <gat>.W
  9510. *------------------------------------------*/
  9511. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  9512. {
  9513. int x,y,type;
  9514. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9515. return;
  9516. if( pc_isGM(sd) < 99 ) //TODO: add proper check
  9517. return;
  9518. x = RFIFOW(fd,2);
  9519. y = RFIFOW(fd,4);
  9520. type = RFIFOW(fd,6);
  9521. map_setgatcell(sd->bl.m,x,y,type);
  9522. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  9523. //FIXME: once players leave the map, the client 'forgets' this information.
  9524. }
  9525. /// S 00cf <nick>.24B <type>.B
  9526. /// type: 0 (/ex nick) deny speech from nick
  9527. /// 1 (/in nick) allow speech from nick
  9528. ///
  9529. /// R 00d1 <type>.B <result>.B
  9530. /// type: 0: deny, 1: allow
  9531. /// result: 0: success, 1: fail 2: list full
  9532. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  9533. {
  9534. char output[512];
  9535. char* nick;
  9536. uint8 type;
  9537. int i;
  9538. nick = (char*)RFIFOP(fd,2); // speed up
  9539. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  9540. type = RFIFOB(fd,26);
  9541. WFIFOHEAD(fd,packet_len(0xd1));
  9542. WFIFOW(fd,0) = 0x0d1;
  9543. WFIFOB(fd,2) = type;
  9544. if( type == 0 )
  9545. { // Add name to ignore list (block)
  9546. // Bot-check...
  9547. if (strcmp(wisp_server_name, nick) == 0)
  9548. { // to find possible bot users who automaticaly ignore people
  9549. sprintf(output, "Character '%s' (account: %d) has tried to block wisps from '%s' (wisp name of the server). Bot user?", sd->status.name, sd->status.account_id, wisp_server_name);
  9550. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9551. WFIFOB(fd,3) = 1; // fail
  9552. WFIFOSET(fd, packet_len(0x0d1));
  9553. return;
  9554. }
  9555. // try to find a free spot, while checking for duplicates at the same time
  9556. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  9557. if( i == MAX_IGNORE_LIST )
  9558. {// no space for new entry
  9559. WFIFOB(fd,3) = 2; // fail
  9560. WFIFOSET(fd, packet_len(0x0d1));
  9561. return;
  9562. }
  9563. if( sd->ignore[i].name[0] != '\0' )
  9564. {// name already exists
  9565. WFIFOB(fd,3) = 0; // Aegis reports success.
  9566. WFIFOSET(fd, packet_len(0x0d1));
  9567. return;
  9568. }
  9569. //Insert in position i
  9570. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  9571. WFIFOB(fd,3) = 0; // success
  9572. WFIFOSET(fd, packet_len(0x0d1));
  9573. }
  9574. else
  9575. { // Remove name from ignore list (unblock)
  9576. // find entry
  9577. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  9578. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' )
  9579. { //Not found
  9580. WFIFOB(fd,3) = 1; // fail
  9581. WFIFOSET(fd, packet_len(0x0d1));
  9582. return;
  9583. }
  9584. // move everything one place down to overwrite removed entry
  9585. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  9586. // wipe last entry
  9587. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  9588. WFIFOB(fd,3) = 0; // success
  9589. WFIFOSET(fd, packet_len(0x0d1));
  9590. }
  9591. return;
  9592. }
  9593. /// S 00d0 <type>.B
  9594. /// type: 0 (/exall) deny all speech
  9595. /// 1 (/inall) allow all speech
  9596. ///
  9597. /// R 00d2 <type>.B <fail>.B
  9598. /// type: 0: deny, 1: allow
  9599. /// fail: 0: success, 1: fail
  9600. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  9601. {
  9602. WFIFOHEAD(fd,packet_len(0xd2));
  9603. WFIFOW(fd,0) = 0x0d2;
  9604. WFIFOB(fd,2) = RFIFOB(fd,2);
  9605. if( RFIFOB(fd,2) == 0 )
  9606. {// Deny all
  9607. if( sd->state.ignoreAll ) {
  9608. WFIFOB(fd,3) = 1; // fail
  9609. } else {
  9610. sd->state.ignoreAll = 1;
  9611. WFIFOB(fd,3) = 0; // success
  9612. }
  9613. }
  9614. else
  9615. {//Unblock everyone
  9616. if( sd->state.ignoreAll ) {
  9617. sd->state.ignoreAll = 0;
  9618. WFIFOB(fd,3) = 0; // success
  9619. } else {
  9620. if (sd->ignore[0].name[0] != '\0')
  9621. { //Wipe the ignore list.
  9622. memset(sd->ignore, 0, sizeof(sd->ignore));
  9623. WFIFOB(fd,3) = 0; // success
  9624. } else {
  9625. WFIFOB(fd,3) = 1; // fail
  9626. }
  9627. }
  9628. }
  9629. WFIFOSET(fd, packet_len(0x0d2));
  9630. return;
  9631. }
  9632. /*==========================================
  9633. * Wis拒否リスト
  9634. *------------------------------------------*/
  9635. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9636. {
  9637. int i;
  9638. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  9639. WFIFOW(fd,0) = 0xd4;
  9640. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9641. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  9642. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  9643. WFIFOSET(fd, WFIFOW(fd,2));
  9644. return;
  9645. }
  9646. /*==========================================
  9647. * スパノビの/doridoriによるSPR2倍
  9648. *------------------------------------------*/
  9649. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  9650. {
  9651. if (sd->state.doridori) return;
  9652. switch (sd->class_&MAPID_UPPERMASK)
  9653. {
  9654. case MAPID_SOUL_LINKER:
  9655. case MAPID_STAR_GLADIATOR:
  9656. case MAPID_TAEKWON:
  9657. if (!sd->state.rest)
  9658. break;
  9659. case MAPID_SUPER_NOVICE:
  9660. sd->state.doridori=1;
  9661. break;
  9662. }
  9663. return;
  9664. }
  9665. /*==========================================
  9666. * スパノビの爆裂波動
  9667. *------------------------------------------*/
  9668. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9669. {
  9670. if(sd){
  9671. int nextbaseexp=pc_nextbaseexp(sd);
  9672. if (battle_config.etc_log){
  9673. if(nextbaseexp != 0)
  9674. ShowInfo("SuperNovice explosionspirits!! %d %d %d %d\n",sd->bl.id,sd->status.class_,sd->status.base_exp,(int)((double)1000*sd->status.base_exp/nextbaseexp));
  9675. else
  9676. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9677. }
  9678. if((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE && sd->status.base_exp > 0 && nextbaseexp > 0 && (int)((double)1000*sd->status.base_exp/nextbaseexp)%100==0){
  9679. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9680. sc_start(&sd->bl,status_skill2sc(MO_EXPLOSIONSPIRITS),100,
  9681. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9682. }
  9683. }
  9684. return;
  9685. }
  9686. // random notes:
  9687. // 0x214: monster/player info ?
  9688. /*==========================================
  9689. * Friends List
  9690. *------------------------------------------*/
  9691. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9692. { //Toggles a single friend online/offline [Skotlex]
  9693. int i, fd = sd->fd;
  9694. //Seek friend.
  9695. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9696. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9697. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9698. return; //Not found
  9699. WFIFOHEAD(fd,packet_len(0x206));
  9700. WFIFOW(fd, 0) = 0x206;
  9701. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  9702. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  9703. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9704. WFIFOSET(fd, packet_len(0x206));
  9705. }
  9706. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9707. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9708. {
  9709. int account_id, char_id, online;
  9710. account_id = va_arg(ap, int);
  9711. char_id = va_arg(ap, int);
  9712. online = va_arg(ap, int);
  9713. clif_friendslist_toggle(sd, account_id, char_id, online);
  9714. return 0;
  9715. }
  9716. //For sending the whole friends list.
  9717. void clif_friendslist_send(struct map_session_data *sd)
  9718. {
  9719. int i = 0, n, fd = sd->fd;
  9720. // Send friends list
  9721. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  9722. WFIFOW(fd, 0) = 0x201;
  9723. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9724. {
  9725. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9726. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9727. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9728. }
  9729. if (i) {
  9730. WFIFOW(fd,2) = 4 + 32 * i;
  9731. WFIFOSET(fd, WFIFOW(fd,2));
  9732. }
  9733. for (n = 0; n < i; n++)
  9734. { //Sending the online players
  9735. if (map_charid2sd(sd->status.friends[n].char_id))
  9736. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9737. }
  9738. }
  9739. /// Reply for add friend request: (success => type 0)
  9740. /// type=0 : MsgStringTable[821]="You have become friends with (%s)."
  9741. /// type=1 : MsgStringTable[822]="(%s) does not want to be friends with you."
  9742. /// type=2 : MsgStringTable[819]="Your Friend List is full."
  9743. /// type=3 : MsgStringTable[820]="(%s)'s Friend List is full."
  9744. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9745. {
  9746. int fd;
  9747. nullpo_retv(sd);
  9748. fd = sd->fd;
  9749. WFIFOHEAD(fd,packet_len(0x209));
  9750. WFIFOW(fd,0) = 0x209;
  9751. WFIFOW(fd,2) = type;
  9752. if (f_sd)
  9753. {
  9754. WFIFOL(fd,4) = f_sd->status.account_id;
  9755. WFIFOL(fd,8) = f_sd->status.char_id;
  9756. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9757. }
  9758. WFIFOSET(fd, packet_len(0x209));
  9759. }
  9760. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  9761. {
  9762. struct map_session_data *f_sd;
  9763. int i, f_fd;
  9764. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9765. // Friend doesn't exist (no player with this name)
  9766. if (f_sd == NULL) {
  9767. clif_displaymessage(fd, msg_txt(3));
  9768. return;
  9769. }
  9770. // @noask [LuzZza]
  9771. if(f_sd->state.noask) {
  9772. clif_noask_sub(sd, f_sd, 5);
  9773. return;
  9774. }
  9775. // Friend already exists
  9776. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9777. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9778. clif_displaymessage(fd, "Friend already exists.");
  9779. return;
  9780. }
  9781. }
  9782. if (i == MAX_FRIENDS) {
  9783. //No space, list full.
  9784. clif_friendslist_reqack(sd, f_sd, 2);
  9785. return;
  9786. }
  9787. f_fd = f_sd->fd;
  9788. WFIFOHEAD(f_fd,packet_len(0x207));
  9789. WFIFOW(f_fd,0) = 0x207;
  9790. WFIFOL(f_fd,2) = sd->status.account_id;
  9791. WFIFOL(f_fd,6) = sd->status.char_id;
  9792. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9793. WFIFOSET(f_fd, packet_len(0x207));
  9794. return;
  9795. }
  9796. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  9797. {
  9798. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9799. struct map_session_data *f_sd;
  9800. int char_id, account_id;
  9801. char reply;
  9802. account_id = RFIFOL(fd,2);
  9803. char_id = RFIFOL(fd,6);
  9804. reply = RFIFOB(fd,10);
  9805. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9806. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9807. if (f_sd == NULL)
  9808. return;
  9809. if (reply == 0)
  9810. clif_friendslist_reqack(f_sd, sd, 1);
  9811. else {
  9812. int i;
  9813. // Find an empty slot
  9814. for (i = 0; i < MAX_FRIENDS; i++)
  9815. if (f_sd->status.friends[i].char_id == 0)
  9816. break;
  9817. if (i == MAX_FRIENDS) {
  9818. clif_friendslist_reqack(f_sd, sd, 2);
  9819. return;
  9820. }
  9821. f_sd->status.friends[i].account_id = sd->status.account_id;
  9822. f_sd->status.friends[i].char_id = sd->status.char_id;
  9823. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9824. clif_friendslist_reqack(f_sd, sd, 0);
  9825. if (battle_config.friend_auto_add) {
  9826. // Also add f_sd to sd's friendlist.
  9827. for (i = 0; i < MAX_FRIENDS; i++) {
  9828. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  9829. return; //No need to add anything.
  9830. if (sd->status.friends[i].char_id == 0)
  9831. break;
  9832. }
  9833. if (i == MAX_FRIENDS) {
  9834. clif_friendslist_reqack(sd, f_sd, 2);
  9835. return;
  9836. }
  9837. sd->status.friends[i].account_id = f_sd->status.account_id;
  9838. sd->status.friends[i].char_id = f_sd->status.char_id;
  9839. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  9840. clif_friendslist_reqack(sd, f_sd, 0);
  9841. }
  9842. }
  9843. return;
  9844. }
  9845. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  9846. {
  9847. // 0x203 </o> <ID to be removed W 4B>
  9848. int account_id, char_id;
  9849. int i, j;
  9850. account_id = RFIFOL(fd,2);
  9851. char_id = RFIFOL(fd,6);
  9852. // Search friend
  9853. for (i = 0; i < MAX_FRIENDS &&
  9854. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9855. if (i == MAX_FRIENDS) {
  9856. clif_displaymessage(fd, "Name not found in list.");
  9857. return;
  9858. }
  9859. // move all chars down
  9860. for(j = i + 1; j < MAX_FRIENDS; j++)
  9861. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9862. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9863. clif_displaymessage(fd, "Friend removed");
  9864. WFIFOHEAD(fd,packet_len(0x20a));
  9865. WFIFOW(fd,0) = 0x20a;
  9866. WFIFOL(fd,2) = account_id;
  9867. WFIFOL(fd,6) = char_id;
  9868. WFIFOSET(fd, packet_len(0x20a));
  9869. // clif_friendslist_send(sd); //This is not needed anymore.
  9870. return;
  9871. }
  9872. /*==========================================
  9873. * /pvpinfo
  9874. *------------------------------------------*/
  9875. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  9876. {
  9877. WFIFOHEAD(fd,packet_len(0x210));
  9878. WFIFOW(fd,0) = 0x210;
  9879. //WFIFOL(fd,2) = 0; // not sure what for yet
  9880. //WFIFOL(fd,6) = 0;
  9881. WFIFOL(fd,10) = sd->pvp_won; // times won
  9882. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  9883. WFIFOL(fd,18) = sd->pvp_point;
  9884. WFIFOSET(fd, packet_len(0x210));
  9885. return;
  9886. }
  9887. /*==========================================
  9888. * /blacksmith
  9889. *------------------------------------------*/
  9890. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  9891. {
  9892. int i;
  9893. const char* name;
  9894. WFIFOHEAD(fd,packet_len(0x219));
  9895. WFIFOW(fd,0) = 0x219;
  9896. //Packet size limits this list to 10 elements. [Skotlex]
  9897. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9898. if (smith_fame_list[i].id > 0) {
  9899. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  9900. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  9901. {
  9902. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  9903. } else
  9904. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  9905. } else
  9906. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  9907. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  9908. }
  9909. for(;i < 10; i++) { //In case the MAX is less than 10.
  9910. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  9911. WFIFOL(fd, 242 + i * 4) = 0;
  9912. }
  9913. WFIFOSET(fd, packet_len(0x219));
  9914. }
  9915. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  9916. {
  9917. int fd = sd->fd;
  9918. WFIFOHEAD(fd,packet_len(0x21b));
  9919. WFIFOW(fd,0) = 0x21b;
  9920. WFIFOL(fd,2) = points;
  9921. WFIFOL(fd,6) = sd->status.fame;
  9922. WFIFOSET(fd, packet_len(0x21b));
  9923. return 0;
  9924. }
  9925. /*==========================================
  9926. * /alchemist
  9927. *------------------------------------------*/
  9928. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  9929. {
  9930. int i;
  9931. const char* name;
  9932. WFIFOHEAD(fd,packet_len(0x21a));
  9933. WFIFOW(fd,0) = 0x21a;
  9934. //Packet size limits this list to 10 elements. [Skotlex]
  9935. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9936. if (chemist_fame_list[i].id > 0) {
  9937. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  9938. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  9939. {
  9940. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9941. } else
  9942. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  9943. } else
  9944. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9945. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  9946. }
  9947. for(;i < 10; i++) { //In case the MAX is less than 10.
  9948. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9949. WFIFOL(fd, 242 + i * 4) = 0;
  9950. }
  9951. WFIFOSET(fd, packet_len(0x21a));
  9952. }
  9953. int clif_fame_alchemist(struct map_session_data *sd, int points)
  9954. {
  9955. int fd = sd->fd;
  9956. WFIFOHEAD(fd,packet_len(0x21c));
  9957. WFIFOW(fd,0) = 0x21c;
  9958. WFIFOL(fd,2) = points;
  9959. WFIFOL(fd,6) = sd->status.fame;
  9960. WFIFOSET(fd, packet_len(0x21c));
  9961. return 0;
  9962. }
  9963. /*==========================================
  9964. * /taekwon
  9965. *------------------------------------------*/
  9966. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  9967. {
  9968. int i;
  9969. const char* name;
  9970. WFIFOHEAD(fd,packet_len(0x226));
  9971. WFIFOW(fd,0) = 0x226;
  9972. //Packet size limits this list to 10 elements. [Skotlex]
  9973. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9974. if (taekwon_fame_list[i].id > 0) {
  9975. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  9976. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  9977. {
  9978. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9979. } else
  9980. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  9981. } else
  9982. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9983. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  9984. }
  9985. for(;i < 10; i++) { //In case the MAX is less than 10.
  9986. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9987. WFIFOL(fd, 242 + i * 4) = 0;
  9988. }
  9989. WFIFOSET(fd, packet_len(0x226));
  9990. }
  9991. int clif_fame_taekwon(struct map_session_data *sd, int points)
  9992. {
  9993. int fd = sd->fd;
  9994. WFIFOHEAD(fd,packet_len(0x224));
  9995. WFIFOW(fd,0) = 0x224;
  9996. WFIFOL(fd,2) = points;
  9997. WFIFOL(fd,6) = sd->status.fame;
  9998. WFIFOSET(fd, packet_len(0x224));
  9999. return 0;
  10000. }
  10001. /*==========================================
  10002. * PK Ranking table?
  10003. *------------------------------------------*/
  10004. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  10005. {
  10006. int i;
  10007. WFIFOHEAD(fd,packet_len(0x238));
  10008. WFIFOW(fd,0) = 0x238;
  10009. for(i=0;i<10;i++){
  10010. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  10011. WFIFOL(fd,i*4+242) = 0;
  10012. }
  10013. WFIFOSET(fd, packet_len(0x238));
  10014. return;
  10015. }
  10016. /*==========================================
  10017. * SG Feel save OK [Komurka]
  10018. *------------------------------------------*/
  10019. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  10020. {
  10021. int i;
  10022. if (sd->menuskill_id != SG_FEEL)
  10023. return;
  10024. i = sd->menuskill_val-1;
  10025. if (i<0 || i > 2) return; //Bug?
  10026. sd->feel_map[i].index = map_id2index(sd->bl.m);
  10027. sd->feel_map[i].m = sd->bl.m;
  10028. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  10029. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  10030. // clif_misceffect2(&sd->bl, 0x1b0);
  10031. // clif_misceffect2(&sd->bl, 0x21f);
  10032. clif_feel_info(sd, i, 0);
  10033. sd->menuskill_val = sd->menuskill_id = 0;
  10034. }
  10035. /*==========================================
  10036. * Question about Star Glaldiator save map [Komurka]
  10037. *------------------------------------------*/
  10038. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv)
  10039. {
  10040. WFIFOHEAD(fd,packet_len(0x253));
  10041. WFIFOW(fd,0)=0x253;
  10042. WFIFOSET(fd, packet_len(0x253));
  10043. sd->menuskill_id = SG_FEEL;
  10044. sd->menuskill_val = skilllv;
  10045. }
  10046. /*==========================================
  10047. * Homunculus packets
  10048. *------------------------------------------*/
  10049. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  10050. {
  10051. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  10052. }
  10053. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  10054. {
  10055. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  10056. struct block_list *bl = NULL;
  10057. struct unit_data *ud = NULL;
  10058. if( sd->md && sd->md->bl.id == id )
  10059. bl = &sd->md->bl;
  10060. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  10061. bl = &sd->hd->bl; // Moving Homunculus
  10062. else return;
  10063. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  10064. ud = unit_bl2ud(bl);
  10065. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  10066. }
  10067. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd)
  10068. {
  10069. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  10070. struct block_list *bl = NULL;
  10071. short x, y, cmd;
  10072. cmd = RFIFOW(fd,0);
  10073. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 + (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  10074. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) + (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  10075. if( sd->md && sd->md->bl.id == id )
  10076. bl = &sd->md->bl; // Moving Mercenary
  10077. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  10078. bl = &sd->hd->bl; // Moving Homunculus
  10079. else return;
  10080. unit_walktoxy(bl, x, y, 4);
  10081. }
  10082. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  10083. {
  10084. struct block_list *bl = NULL;
  10085. int id = RFIFOL(fd,2),
  10086. target_id = RFIFOL(fd,6),
  10087. action_type = RFIFOB(fd,10);
  10088. if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  10089. bl = &sd->hd->bl;
  10090. else if( sd->md && sd->md->bl.id == id )
  10091. bl = &sd->md->bl;
  10092. else return;
  10093. unit_stop_attack(bl);
  10094. unit_attack(bl, target_id, action_type != 0);
  10095. }
  10096. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  10097. { //[orn]
  10098. int cmd;
  10099. cmd = RFIFOW(fd,0);
  10100. if(!merc_is_hom_active(sd->hd))
  10101. return;
  10102. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  10103. }
  10104. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  10105. {
  10106. int item_position = pc_search_inventory(sd, 7621);
  10107. if (item_position < 0)
  10108. return;
  10109. if (!status_revive(&sd->bl, 100, 100))
  10110. return;
  10111. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  10112. pc_delitem(sd, item_position, 1, 0);
  10113. }
  10114. /// /check <string>
  10115. /// S 0213 <string>.24B
  10116. void clif_parse_Check(int fd, struct map_session_data *sd)
  10117. {
  10118. // no info
  10119. }
  10120. #ifndef TXT_ONLY
  10121. /*==========================================
  10122. * MAIL SYSTEM
  10123. * By Zephyrus
  10124. *==========================================*/
  10125. /*------------------------------------------
  10126. * Reply to Set Attachment operation
  10127. * 0 : Successfully attached item to mail
  10128. * 1 : Fail to set the attachment
  10129. *------------------------------------------*/
  10130. static void clif_Mail_setattachment(int fd, int index, uint8 flag)
  10131. {
  10132. WFIFOHEAD(fd,packet_len(0x255));
  10133. WFIFOW(fd,0) = 0x255;
  10134. WFIFOW(fd,2) = index;
  10135. WFIFOB(fd,4) = flag;
  10136. WFIFOSET(fd,packet_len(0x255));
  10137. }
  10138. /*------------------------------------------
  10139. * Reply to Get Attachment operation
  10140. * 0 : Successfully added attachment to Inventory
  10141. * 1 : Fail to set the item to inventory
  10142. * 2 : Weight problems
  10143. *------------------------------------------*/
  10144. void clif_Mail_getattachment(int fd, uint8 flag)
  10145. {
  10146. WFIFOHEAD(fd,packet_len(0x245));
  10147. WFIFOW(fd,0) = 0x245;
  10148. WFIFOB(fd,2) = flag;
  10149. WFIFOSET(fd,packet_len(0x245));
  10150. }
  10151. /*------------------------------------------
  10152. * Send Mail ack
  10153. * 0 : Message Send Ok
  10154. * 1 : Recipient does not exist
  10155. *------------------------------------------*/
  10156. void clif_Mail_send(int fd, bool fail)
  10157. {
  10158. WFIFOHEAD(fd,packet_len(0x249));
  10159. WFIFOW(fd,0) = 0x249;
  10160. WFIFOB(fd,2) = fail;
  10161. WFIFOSET(fd,packet_len(0x249));
  10162. }
  10163. /*------------------------------------------
  10164. * Delete Mail ack
  10165. * 0 : Delete ok
  10166. * 1 : Delete failed
  10167. *------------------------------------------*/
  10168. void clif_Mail_delete(int fd, int mail_id, short fail)
  10169. {
  10170. WFIFOHEAD(fd, packet_len(0x257));
  10171. WFIFOW(fd,0) = 0x257;
  10172. WFIFOL(fd,2) = mail_id;
  10173. WFIFOW(fd,6) = fail;
  10174. WFIFOSET(fd, packet_len(0x257));
  10175. }
  10176. /*------------------------------------------
  10177. * Return Mail ack
  10178. * 0 : Mail returned to the sender
  10179. * 1 : The mail does not exist
  10180. *------------------------------------------*/
  10181. void clif_Mail_return(int fd, int mail_id, short fail)
  10182. {
  10183. WFIFOHEAD(fd,packet_len(0x274));
  10184. WFIFOW(fd,0) = 0x274;
  10185. WFIFOL(fd,2) = mail_id;
  10186. WFIFOW(fd,6) = fail;
  10187. WFIFOSET(fd,packet_len(0x274));
  10188. }
  10189. /*------------------------------------------
  10190. * You have New Mail
  10191. *------------------------------------------*/
  10192. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  10193. {
  10194. WFIFOHEAD(fd,packet_len(0x24a));
  10195. WFIFOW(fd,0) = 0x24a;
  10196. WFIFOL(fd,2) = mail_id;
  10197. safestrncpy((char*)WFIFOP(fd,6), sender, NAME_LENGTH);
  10198. safestrncpy((char*)WFIFOP(fd,30), title, MAIL_TITLE_LENGTH);
  10199. WFIFOSET(fd,packet_len(0x24a));
  10200. }
  10201. /*------------------------------------------
  10202. * Handles Mail Window on Client
  10203. * flag : 0 open | 1 close
  10204. *------------------------------------------*/
  10205. void clif_Mail_window(int fd, int flag)
  10206. {
  10207. WFIFOHEAD(fd,packet_len(0x260));
  10208. WFIFOW(fd,0) = 0x260;
  10209. WFIFOL(fd,2) = flag;
  10210. WFIFOSET(fd,packet_len(0x260));
  10211. }
  10212. /*------------------------------------------
  10213. * Send Inbox Data to Client
  10214. *------------------------------------------*/
  10215. void clif_Mail_refreshinbox(struct map_session_data *sd)
  10216. {
  10217. int fd = sd->fd;
  10218. struct mail_data *md = &sd->mail.inbox;
  10219. struct mail_message *msg;
  10220. int len, i, j;
  10221. len = 8 + (73 * md->amount);
  10222. WFIFOHEAD(fd,len);
  10223. WFIFOW(fd,0) = 0x240;
  10224. WFIFOW(fd,2) = len;
  10225. WFIFOL(fd,4) = md->amount;
  10226. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  10227. {
  10228. msg = &md->msg[i];
  10229. if (msg->id < 1)
  10230. continue;
  10231. WFIFOL(fd,8+73*j) = msg->id;
  10232. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  10233. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD); // 0: unread, 1: read
  10234. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  10235. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  10236. j++;
  10237. }
  10238. WFIFOSET(fd,len);
  10239. if( md->full )
  10240. {
  10241. char output[100];
  10242. sprintf(output, "Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  10243. clif_disp_onlyself(sd, output, strlen(output));
  10244. }
  10245. }
  10246. /*------------------------------------------
  10247. * Client Request Inbox List
  10248. *------------------------------------------*/
  10249. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  10250. {
  10251. struct mail_data* md = &sd->mail.inbox;
  10252. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  10253. intif_Mail_requestinbox(sd->status.char_id, 1);
  10254. else
  10255. clif_Mail_refreshinbox(sd);
  10256. mail_removeitem(sd, 0);
  10257. mail_removezeny(sd, 0);
  10258. }
  10259. /*------------------------------------------
  10260. * Read Message
  10261. *------------------------------------------*/
  10262. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  10263. {
  10264. int i, fd = sd->fd;
  10265. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10266. if( i == MAIL_MAX_INBOX )
  10267. {
  10268. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  10269. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  10270. return;
  10271. }
  10272. else
  10273. {
  10274. struct mail_message *msg = &sd->mail.inbox.msg[i];
  10275. struct item *item = &msg->item;
  10276. struct item_data *data;
  10277. int msg_len = strlen(msg->body), len;
  10278. if( msg_len == 0 ) {
  10279. strcpy(msg->body, "(no message)");
  10280. msg_len = strlen(msg->body);
  10281. }
  10282. len = 101 + msg_len;
  10283. WFIFOHEAD(fd,len);
  10284. WFIFOW(fd,0) = 0x242;
  10285. WFIFOW(fd,2) = len;
  10286. WFIFOL(fd,4) = msg->id;
  10287. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  10288. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  10289. WFIFOL(fd,72) = 0;
  10290. WFIFOL(fd,76) = msg->zeny;
  10291. if( item->nameid && (data = itemdb_search(item->nameid)) != NULL )
  10292. {
  10293. WFIFOL(fd,80) = item->amount;
  10294. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  10295. WFIFOW(fd,86) = data->type;
  10296. WFIFOB(fd,88) = item->identify;
  10297. WFIFOB(fd,89) = item->attribute;
  10298. WFIFOB(fd,90) = item->refine;
  10299. WFIFOW(fd,91) = item->card[0];
  10300. WFIFOW(fd,93) = item->card[1];
  10301. WFIFOW(fd,95) = item->card[2];
  10302. WFIFOW(fd,97) = item->card[3];
  10303. }
  10304. else // no item, set all to zero
  10305. memset(WFIFOP(fd,80), 0x00, 19);
  10306. WFIFOB(fd,99) = (unsigned char)msg_len;
  10307. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  10308. WFIFOSET(fd,len);
  10309. if (msg->status == MAIL_UNREAD) {
  10310. msg->status = MAIL_READ;
  10311. intif_Mail_read(mail_id);
  10312. clif_parse_Mail_refreshinbox(fd, sd);
  10313. }
  10314. }
  10315. }
  10316. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  10317. {
  10318. int mail_id = RFIFOL(fd,2);
  10319. if( mail_id <= 0 )
  10320. return;
  10321. if( mail_invalid_operation(sd) )
  10322. return;
  10323. clif_Mail_read(sd, RFIFOL(fd,2));
  10324. }
  10325. /*------------------------------------------
  10326. * Get Attachment from Message
  10327. *------------------------------------------*/
  10328. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  10329. {
  10330. int mail_id = RFIFOL(fd,2);
  10331. int i;
  10332. bool fail = false;
  10333. if( mail_id <= 0 )
  10334. return;
  10335. if( mail_invalid_operation(sd) )
  10336. return;
  10337. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10338. if( i == MAIL_MAX_INBOX )
  10339. return;
  10340. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  10341. return;
  10342. if( sd->mail.inbox.msg[i].item.nameid > 0 )
  10343. {
  10344. struct item_data *data;
  10345. unsigned int weight;
  10346. if ((data = itemdb_search(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  10347. return;
  10348. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) )
  10349. {
  10350. case ADDITEM_NEW:
  10351. fail = ( pc_inventoryblank(sd) == 0 );
  10352. break;
  10353. case ADDITEM_OVERAMOUNT:
  10354. fail = true;
  10355. }
  10356. if( fail )
  10357. {
  10358. clif_Mail_getattachment(fd, 1);
  10359. return;
  10360. }
  10361. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  10362. if( weight > sd->max_weight - sd->weight )
  10363. {
  10364. clif_Mail_getattachment(fd, 2);
  10365. return;
  10366. }
  10367. }
  10368. sd->mail.inbox.msg[i].zeny = 0;
  10369. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  10370. clif_Mail_read(sd, mail_id);
  10371. intif_Mail_getattach(sd->status.char_id, mail_id);
  10372. }
  10373. /*------------------------------------------
  10374. * Delete Message
  10375. *------------------------------------------*/
  10376. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  10377. {
  10378. int mail_id = RFIFOL(fd,2);
  10379. int i;
  10380. if( mail_id <= 0 )
  10381. return;
  10382. if( mail_invalid_operation(sd) )
  10383. return;
  10384. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10385. if (i < MAIL_MAX_INBOX)
  10386. {
  10387. struct mail_message *msg = &sd->mail.inbox.msg[i];
  10388. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 )
  10389. {// can't delete mail without removing attachment first
  10390. clif_Mail_delete(sd->fd, mail_id, 1);
  10391. return;
  10392. }
  10393. intif_Mail_delete(sd->status.char_id, mail_id);
  10394. }
  10395. }
  10396. /*------------------------------------------
  10397. * Return Mail Message
  10398. *------------------------------------------*/
  10399. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  10400. {
  10401. int mail_id = RFIFOL(fd,2);
  10402. int i;
  10403. if( mail_id <= 0 )
  10404. return;
  10405. if( mail_invalid_operation(sd) )
  10406. return;
  10407. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10408. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  10409. intif_Mail_return(sd->status.char_id, mail_id);
  10410. else
  10411. clif_Mail_return(sd->fd, mail_id, 1);
  10412. }
  10413. /*------------------------------------------
  10414. * Set Attachment
  10415. *------------------------------------------*/
  10416. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  10417. {
  10418. int idx = RFIFOW(fd,2);
  10419. int amount = RFIFOL(fd,4);
  10420. unsigned char flag;
  10421. if (idx < 0 || amount < 0)
  10422. return;
  10423. flag = mail_setitem(sd, idx, amount);
  10424. clif_Mail_setattachment(fd,idx,flag);
  10425. }
  10426. /*------------------------------------------
  10427. * Mail Window Operation
  10428. * 0 : Switch to 'new mail' window, or Close mailbox
  10429. * 1 : ???
  10430. * 2 : ???
  10431. *------------------------------------------*/
  10432. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  10433. {
  10434. int flag = RFIFOW(fd,2);
  10435. if (flag == 0 || flag == 1)
  10436. mail_removeitem(sd, 0);
  10437. if (flag == 0 || flag == 2)
  10438. mail_removezeny(sd, 0);
  10439. }
  10440. /*------------------------------------------
  10441. * Send Mail
  10442. * S 0248 <packet len>.w <nick>.24B <title>.40B <body len>.B <message>.?B 00
  10443. *------------------------------------------*/
  10444. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  10445. {
  10446. struct mail_message msg;
  10447. int body_len;
  10448. if( sd->state.trading )
  10449. return;
  10450. if( RFIFOW(fd,2) < 69 ) {
  10451. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  10452. return;
  10453. }
  10454. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 )
  10455. {
  10456. clif_displaymessage(sd->fd,"Cannot send mails too fast!!.");
  10457. clif_Mail_send(fd, true); // fail
  10458. return;
  10459. }
  10460. body_len = RFIFOB(fd,68);
  10461. if (body_len > MAIL_BODY_LENGTH)
  10462. body_len = MAIL_BODY_LENGTH;
  10463. if( !mail_setattachment(sd, &msg) )
  10464. { // Invalid Append condition
  10465. clif_Mail_send(sd->fd, true); // fail
  10466. mail_removeitem(sd,0);
  10467. mail_removezeny(sd,0);
  10468. return;
  10469. }
  10470. msg.id = 0; // id will be assigned by charserver
  10471. msg.send_id = sd->status.char_id;
  10472. msg.dest_id = 0; // will attempt to resolve name
  10473. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  10474. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  10475. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  10476. if (body_len)
  10477. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  10478. else
  10479. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  10480. msg.timestamp = time(NULL);
  10481. if( !intif_Mail_send(sd->status.account_id, &msg) )
  10482. mail_deliveryfail(sd, &msg);
  10483. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  10484. }
  10485. /*==========================================
  10486. * AUCTION SYSTEM
  10487. * By Zephyrus
  10488. *==========================================*/
  10489. void clif_Auction_openwindow(struct map_session_data *sd)
  10490. {
  10491. int fd = sd->fd;
  10492. if( sd->state.storage_flag || sd->vender_id || sd->state.trading )
  10493. return;
  10494. WFIFOHEAD(fd,12);
  10495. WFIFOW(fd,0) = 0x25f;
  10496. WFIFOL(fd,2) = 0;
  10497. WFIFOB(fd,6) = 0xb6;
  10498. WFIFOB(fd,7) = 0x00;
  10499. WFIFOB(fd,8) = 0xa6;
  10500. WFIFOB(fd,9) = 0xde;
  10501. WFIFOW(fd,10) = 0;
  10502. WFIFOSET(fd,12);
  10503. }
  10504. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  10505. {
  10506. int i, fd = sd->fd, len = sizeof(struct auction_data);
  10507. struct auction_data auction;
  10508. struct item_data *item;
  10509. int k;
  10510. WFIFOHEAD(fd,20);
  10511. WFIFOW(fd,0) = 0x252;
  10512. WFIFOW(fd,2) = 12 + (count * 83);
  10513. WFIFOL(fd,4) = pages;
  10514. WFIFOL(fd,8) = count;
  10515. for( i = 0; i < count; i++ )
  10516. {
  10517. memcpy(&auction, RBUFP(buf,i * len), len);
  10518. k = 12 + (i * 83);
  10519. WFIFOL(fd,k) = auction.auction_id;
  10520. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  10521. if( (item = itemdb_search(auction.item.nameid)) != NULL && item->view_id > 0 )
  10522. WFIFOW(fd,28+k) = item->view_id;
  10523. else
  10524. WFIFOW(fd,28+k) = auction.item.nameid;
  10525. WFIFOW(fd,30+k) = auction.type;
  10526. WFIFOW(fd,32+k) = 0; // ??
  10527. WFIFOW(fd,34+k) = auction.item.amount; // Allways 1
  10528. WFIFOB(fd,36+k) = auction.item.identify;
  10529. WFIFOB(fd,37+k) = auction.item.attribute;
  10530. WFIFOB(fd,38+k) = auction.item.refine;
  10531. WFIFOW(fd,39+k) = auction.item.card[0];
  10532. WFIFOW(fd,41+k) = auction.item.card[1];
  10533. WFIFOW(fd,43+k) = auction.item.card[2];
  10534. WFIFOW(fd,45+k) = auction.item.card[3];
  10535. WFIFOL(fd,47+k) = auction.price;
  10536. WFIFOL(fd,51+k) = auction.buynow;
  10537. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  10538. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  10539. }
  10540. WFIFOSET(fd, 12 + (count * 83));
  10541. }
  10542. static void clif_Auction_setitem(int fd, int index, bool fail)
  10543. {
  10544. WFIFOHEAD(fd,packet_len(0x256));
  10545. WFIFOW(fd,0) = 0x256;
  10546. WFIFOW(fd,2) = index;
  10547. WFIFOB(fd,4) = fail;
  10548. WFIFOSET(fd,packet_len(0x256));
  10549. }
  10550. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd)
  10551. {
  10552. if( sd->auction.amount > 0 )
  10553. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  10554. sd->auction.amount = 0;
  10555. }
  10556. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
  10557. {
  10558. int idx = RFIFOW(fd,2) - 2;
  10559. int amount = RFIFOL(fd,4); // Allways 1
  10560. struct item_data *item;
  10561. if( sd->auction.amount > 0 )
  10562. sd->auction.amount = 0;
  10563. if( idx < 0 || idx >= MAX_INVENTORY )
  10564. {
  10565. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  10566. return;
  10567. }
  10568. if( amount != 1 || amount < 0 || amount > sd->status.inventory[idx].amount )
  10569. { // By client, amount is allways set to 1. Maybe this is a future implementation.
  10570. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  10571. return;
  10572. }
  10573. if( (item = itemdb_search(sd->status.inventory[idx].nameid)) != NULL && !(item->type == IT_ARMOR || item->type == IT_PETARMOR || item->type == IT_WEAPON || item->type == IT_CARD || item->type == IT_ETC) )
  10574. { // Consumible or pets are not allowed
  10575. clif_Auction_setitem(sd->fd, idx, true);
  10576. return;
  10577. }
  10578. if( !pc_candrop(sd, &sd->status.inventory[idx]) || !sd->status.inventory[idx].identify || sd->status.inventory[idx].expire_time )
  10579. { // Quest Item or something else
  10580. clif_Auction_setitem(sd->fd, idx, true);
  10581. return;
  10582. }
  10583. sd->auction.index = idx;
  10584. sd->auction.amount = amount;
  10585. clif_Auction_setitem(fd, idx + 2, false);
  10586. }
  10587. // 0 = You have failed to bid into the auction
  10588. // 1 = You have successfully bid in the auction
  10589. // 2 = The auction has been canceled
  10590. // 3 = An auction with at least one bidder cannot be canceled
  10591. // 4 = You cannot register more than 5 items in an auction at a time
  10592. // 5 = You do not have enough Zeny to pay the Auction Fee
  10593. // 6 = You have won the auction
  10594. // 7 = You have failed to win the auction
  10595. // 8 = You do not have enough Zeny
  10596. // 9 = You cannot place more than 5 bids at a time
  10597. void clif_Auction_message(int fd, unsigned char flag)
  10598. {
  10599. WFIFOHEAD(fd,3);
  10600. WFIFOW(fd,0) = 0x250;
  10601. WFIFOB(fd,2) = flag;
  10602. WFIFOSET(fd,3);
  10603. }
  10604. // 0 = You have ended the auction
  10605. // 1 = You cannot end the auction
  10606. // 2 = Bid number is incorrect
  10607. void clif_Auction_close(int fd, unsigned char flag)
  10608. {
  10609. WFIFOHEAD(fd,6);
  10610. WFIFOW(fd,0) = 0x25d;
  10611. WFIFOL(fd,2) = flag;
  10612. WFIFOSET(fd,6);
  10613. }
  10614. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  10615. {
  10616. struct auction_data auction;
  10617. struct item_data *item;
  10618. auction.price = RFIFOL(fd,2);
  10619. auction.buynow = RFIFOL(fd,6);
  10620. auction.hours = RFIFOW(fd,10);
  10621. // Invalid Situations...
  10622. if( sd->auction.amount < 1 )
  10623. {
  10624. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  10625. return;
  10626. }
  10627. if( auction.price >= auction.buynow )
  10628. {
  10629. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  10630. return;
  10631. }
  10632. if( auction.hours < 1 || auction.hours > 48 )
  10633. {
  10634. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  10635. return;
  10636. }
  10637. // Auction checks...
  10638. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) )
  10639. {
  10640. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  10641. return;
  10642. }
  10643. if( auction.buynow > battle_config.auction_maximumprice )
  10644. { // Zeny Limits
  10645. auction.buynow = battle_config.auction_maximumprice;
  10646. if( auction.price >= auction.buynow )
  10647. auction.price = auction.buynow - 1;
  10648. }
  10649. auction.auction_id = 0;
  10650. auction.seller_id = sd->status.char_id;
  10651. safestrncpy(auction.seller_name, sd->status.name, NAME_LENGTH);
  10652. auction.buyer_id = 0;
  10653. memset(&auction.buyer_name, '\0', NAME_LENGTH);
  10654. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  10655. {
  10656. clif_Auction_message(fd, 2); // The auction has been canceled
  10657. return;
  10658. }
  10659. if( (item = itemdb_search(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  10660. { // Just in case
  10661. clif_Auction_message(fd, 2); // The auction has been canceled
  10662. return;
  10663. }
  10664. safestrncpy(auction.item_name, item->jname, ITEM_NAME_LENGTH);
  10665. auction.type = item->type;
  10666. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  10667. auction.item.amount = 1;
  10668. auction.timestamp = 0;
  10669. if( !intif_Auction_register(&auction) )
  10670. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  10671. else
  10672. {
  10673. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1);
  10674. sd->auction.amount = 0;
  10675. pc_payzeny(sd, auction.hours * battle_config.auction_feeperhour);
  10676. }
  10677. }
  10678. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd)
  10679. {
  10680. unsigned int auction_id = RFIFOL(fd,2);
  10681. intif_Auction_cancel(sd->status.char_id, auction_id);
  10682. }
  10683. void clif_parse_Auction_close(int fd, struct map_session_data *sd)
  10684. {
  10685. unsigned int auction_id = RFIFOL(fd,2);
  10686. intif_Auction_close(sd->status.char_id, auction_id);
  10687. }
  10688. void clif_parse_Auction_bid(int fd, struct map_session_data *sd)
  10689. {
  10690. unsigned int auction_id = RFIFOL(fd,2);
  10691. int bid = RFIFOL(fd,6);
  10692. if( bid <= 0 )
  10693. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  10694. else if( bid > sd->status.zeny )
  10695. clif_Auction_message(fd, 8); // You do not have enough zeny
  10696. else
  10697. {
  10698. pc_payzeny(sd, bid);
  10699. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  10700. }
  10701. }
  10702. /*------------------------------------------
  10703. * Auction Search
  10704. * S 0251 <search type>.w <search price>.l <search text>.24B <page number>.w
  10705. * Search Type: 0 Armor 1 Weapon 2 Card 3 Misc 4 By Text 5 By Price 6 Sell 7 Buy
  10706. *------------------------------------------*/
  10707. void clif_parse_Auction_search(int fd, struct map_session_data* sd)
  10708. {
  10709. char search_text[NAME_LENGTH];
  10710. short type = RFIFOW(fd,2), page = RFIFOW(fd,32);
  10711. int price = RFIFOL(fd,4);
  10712. clif_parse_Auction_cancelreg(fd, sd);
  10713. safestrncpy(search_text, (char*)RFIFOP(fd,8), NAME_LENGTH);
  10714. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  10715. }
  10716. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  10717. {
  10718. short type = RFIFOW(fd,2) + 6;
  10719. clif_parse_Auction_cancelreg(fd, sd);
  10720. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  10721. }
  10722. #endif
  10723. /*==========================================
  10724. * CASH/POINT SHOP
  10725. *==========================================*/
  10726. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  10727. {
  10728. int fd,i;
  10729. nullpo_retv(sd);
  10730. nullpo_retv(nd);
  10731. fd = sd->fd;
  10732. sd->npc_shopid = nd->bl.id;
  10733. WFIFOHEAD(fd, 200 * 11 + 12);
  10734. WFIFOW(fd,0) = 0x287;
  10735. WFIFOW(fd,2) = 12 + nd->u.shop.count*11;
  10736. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  10737. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  10738. for( i = 0; i < nd->u.shop.count; i++ )
  10739. {
  10740. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  10741. WFIFOL(fd,12+i*11) = nd->u.shop.shop_item[i].value;
  10742. WFIFOL(fd,16+i*11) = nd->u.shop.shop_item[i].value; // Discount Price? Maybe a Discount item
  10743. WFIFOB(fd,20+i*11) = itemtype(id->type);
  10744. WFIFOW(fd,21+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  10745. }
  10746. WFIFOSET(fd,WFIFOW(fd,2));
  10747. }
  10748. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
  10749. {
  10750. int fail = 0, amount, points;
  10751. short nameid;
  10752. struct npc_data *nd;
  10753. nullpo_retv(sd);
  10754. nd = (struct npc_data *)map_id2bl(sd->npc_shopid);
  10755. nameid = RFIFOW(fd,2);
  10756. amount = RFIFOW(fd,4);
  10757. points = RFIFOL(fd,6); // Not Implemented. Should be 0
  10758. if( sd->state.trading || !sd->npc_shopid )
  10759. fail = 1;
  10760. else
  10761. fail = npc_cashshop_buy(sd, nameid, amount, points);
  10762. WFIFOHEAD(fd,12);
  10763. WFIFOW(fd,0) = 0x289;
  10764. WFIFOL(fd,2) = sd->cashPoints;
  10765. WFIFOL(fd,6) = sd->kafraPoints;
  10766. WFIFOW(fd,10) = fail;
  10767. WFIFOSET(fd,12);
  10768. }
  10769. /*==========================================
  10770. * Adoption System
  10771. *==========================================*/
  10772. // 0 : "You cannot adopt more than 1 child."
  10773. // 1 : "You must be at least character level 70 in order to adopt someone."
  10774. // 2 : "You cannot adopt a married person."
  10775. void clif_Adopt_reply(struct map_session_data *sd, int type)
  10776. {
  10777. int fd = sd->fd;
  10778. WFIFOHEAD(fd,6);
  10779. WFIFOW(fd,0) = 0x0216;
  10780. WFIFOL(fd,2) = type;
  10781. WFIFOSET(fd,6);
  10782. }
  10783. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  10784. {
  10785. int fd = sd->fd;
  10786. WFIFOHEAD(fd,34);
  10787. WFIFOW(fd,0) = 0x01f6;
  10788. WFIFOL(fd,2) = src->status.account_id;
  10789. WFIFOL(fd,6) = p_id;
  10790. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  10791. WFIFOSET(fd,34);
  10792. }
  10793. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  10794. {
  10795. struct map_session_data *tsd = map_id2sd(RFIFOL(fd,2)), *p_sd = map_charid2sd(sd->status.partner_id);
  10796. if( pc_can_Adopt(sd, p_sd, tsd) )
  10797. {
  10798. tsd->adopt_invite = sd->status.account_id;
  10799. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  10800. }
  10801. }
  10802. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd)
  10803. {
  10804. int p1_id = RFIFOL(fd,2);
  10805. int p2_id = RFIFOL(fd,6);
  10806. int result = RFIFOL(fd,10);
  10807. struct map_session_data* p1_sd = map_id2sd(p1_id);
  10808. struct map_session_data* p2_sd = map_id2sd(p2_id);
  10809. int pid = sd->adopt_invite;
  10810. sd->adopt_invite = 0;
  10811. if( p1_sd == NULL || p2_sd == NULL )
  10812. return; // Both players need to be online
  10813. if( pid != p1_sd->status.account_id )
  10814. return; // Incorrect values
  10815. if( result == 0 )
  10816. return; // Rejected
  10817. pc_adoption(p1_sd, p2_sd, sd);
  10818. }
  10819. /*==========================================
  10820. * Convex Mirror
  10821. * S 0293 <flag>.b <x>.l <y>.l <Hours>.w <Minutes>.w <unknown>.l <monster name>.40B <unknown>.11B
  10822. *==========================================*/
  10823. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  10824. {
  10825. WFIFOHEAD(fd,70);
  10826. memset(WFIFOP(fd,0),0,70);
  10827. WFIFOW(fd,0) = 0x0293;
  10828. if( md != NULL )
  10829. {
  10830. if( md->bl.prev != NULL )
  10831. { // Boss on This Map
  10832. if( flag )
  10833. {
  10834. WFIFOB(fd,2) = 1;
  10835. WFIFOL(fd,3) = md->bl.x;
  10836. WFIFOL(fd,7) = md->bl.y;
  10837. }
  10838. else
  10839. WFIFOB(fd,2) = 2; // First Time
  10840. }
  10841. else if (md->spawn_timer != -1)
  10842. { // Boss is Dead
  10843. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  10844. unsigned int seconds;
  10845. int hours, minutes;
  10846. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  10847. hours = seconds / (60 * 60);
  10848. seconds = seconds - (60 * 60 * hours);
  10849. minutes = seconds / 60;
  10850. WFIFOB(fd,2) = 3;
  10851. WFIFOW(fd,11) = hours; // Hours
  10852. WFIFOW(fd,13) = minutes; // Minutes
  10853. }
  10854. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  10855. }
  10856. WFIFOSET(fd,70);
  10857. }
  10858. /*==========================================
  10859. * Requesting equip of a player
  10860. *------------------------------------------*/
  10861. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  10862. {
  10863. int charid = RFIFOL(fd, 2);
  10864. struct map_session_data* tsd = map_id2sd(charid);
  10865. if (!tsd)
  10866. return;
  10867. if( tsd->status.show_equip || (battle_config.gm_viewequip_min_lv && pc_isGM(sd) >= battle_config.gm_viewequip_min_lv) )
  10868. clif_viewequip_ack(sd, tsd);
  10869. else
  10870. clif_viewequip_fail(sd);
  10871. }
  10872. /*==========================================
  10873. * Equip window (un)tick
  10874. * S 02d8 <zero?>.L <flag>.L
  10875. *------------------------------------------*/
  10876. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  10877. {
  10878. bool flag = (bool)RFIFOL(fd,6); // 0=off, 1=on
  10879. sd->status.show_equip = flag;
  10880. clif_equiptickack(sd, flag);
  10881. }
  10882. /*==========================================
  10883. * Questlog System [Kevin]
  10884. * 02B5 <packet_len>.W <ignored>.L { }.10B* <-- UNKOWN PACKET
  10885. * 02B6 <quest_id>.L <state>.B
  10886. *------------------------------------------*/
  10887. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  10888. {
  10889. }
  10890. //Send simple list of quests upon login
  10891. //* 02B1 <packet_len>.W <ignored>.L { <quest_id>.L <state>.B }.5B*
  10892. void clif_send_questlog(struct map_session_data * sd)
  10893. {
  10894. int fd = sd->fd;
  10895. int i;
  10896. WFIFOHEAD(fd,sd->num_quests*5+8);
  10897. WFIFOW(fd, 0) = 0x02B1;
  10898. WFIFOW(fd, 2) = sd->num_quests*5+8;
  10899. for(i=0; i<MAX_QUEST; i++)
  10900. {
  10901. if(!sd->quest_log[i].quest_id)
  10902. continue;
  10903. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  10904. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  10905. }
  10906. WFIFOSET(fd, WFIFOW(fd, 2));
  10907. }
  10908. //Send objective info on login
  10909. //* 02B2 <packet_len>.W <ignored>.L { <quest_id>.L <ignored>.L <time>.L <num mobs>.W {<ignored>.L <mob count>.W <Mob Name>.24B}.30B[3] }.104B*
  10910. void clif_send_questlog_info(struct map_session_data * sd)
  10911. {
  10912. int fd = sd->fd;
  10913. int i, j;
  10914. WFIFOHEAD(fd,sd->num_quests*104+8);
  10915. WFIFOW(fd, 0) = 0x02B2;
  10916. WFIFOW(fd, 2) = sd->num_quests*104+8;
  10917. for(i=0; i<MAX_QUEST; i++)
  10918. {
  10919. if(!sd->quest_log[i].quest_id)
  10920. continue;
  10921. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  10922. // I have no idea what the time field does [Kevin]
  10923. WFIFOL(fd, i*104+16) = 0;
  10924. WFIFOW(fd, i*104+20) = sd->quest_log[i].num_objectives;
  10925. for(j=0; j<sd->quest_log[i].num_objectives; j++)
  10926. {
  10927. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].objectives[j].count;
  10928. memcpy(WFIFOP(fd, i*104+28+j*30), sd->quest_log[i].objectives[j].name, NAME_LENGTH);
  10929. }
  10930. }
  10931. WFIFOSET(fd, WFIFOW(fd, 2));
  10932. }
  10933. //Send info when objective info needs an update
  10934. //* 02B3 <quest_id>.L <state>.B <ignored>.L <time>.L <num mobs>.W {<ignored>.L <mob count>.W <Mob Name>.24B}.30B[3]
  10935. void clif_send_quest_info(struct map_session_data * sd, struct quest * qd)
  10936. {
  10937. int fd = sd->fd;
  10938. int i;
  10939. WFIFOHEAD(fd,qd->num_objectives*30+17);
  10940. WFIFOW(fd, 0) = 0x02B3;
  10941. WFIFOL(fd, 2) = qd->quest_id;
  10942. WFIFOB(fd, 6) = qd->state;
  10943. //Same time value thing
  10944. WFIFOW(fd, 11) = 0;
  10945. WFIFOW(fd, 15) = qd->num_objectives;
  10946. for(i=0; i<qd->num_objectives; i++)
  10947. {
  10948. WFIFOW(fd, i*30+21) = qd->objectives[i].count;
  10949. memcpy(WFIFOP(fd, i*30+23), qd->objectives[i].name, NAME_LENGTH);
  10950. }
  10951. WFIFOSET(fd, qd->num_objectives*30+17);
  10952. }
  10953. //Send delete msg
  10954. //* 02B4 <quest_id>.L
  10955. void clif_send_quest_delete(struct map_session_data * sd, int quest_id)
  10956. {
  10957. int fd = sd->fd;
  10958. WFIFOHEAD(fd, 6);
  10959. WFIFOW(fd, 0) = 0x02B4;
  10960. WFIFOL(fd, 2) = quest_id;
  10961. WFIFOSET(fd, 6);
  10962. }
  10963. //Change active state of the quest
  10964. //* 02B7 <quest_id>.L <state_to>.B
  10965. void clif_send_quest_status(struct map_session_data * sd, int quest_id, bool active)
  10966. {
  10967. int fd = sd->fd;
  10968. WFIFOHEAD(fd, 7);
  10969. WFIFOW(fd, 0) = 0x02B7;
  10970. WFIFOL(fd, 2) = quest_id;
  10971. WFIFOB(fd, 6) = active?1:0;
  10972. WFIFOSET(fd, 7);
  10973. }
  10974. /*==========================================
  10975. * Mercenary System
  10976. *==========================================*/
  10977. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  10978. {
  10979. struct mercenary_data *md;
  10980. struct status_data *status;
  10981. int fd;
  10982. if( sd == NULL || (md = sd->md) == NULL )
  10983. return;
  10984. fd = sd->fd;
  10985. status = &md->battle_status;
  10986. WFIFOHEAD(fd,8);
  10987. WFIFOW(fd,0) = 0x02a2;
  10988. WFIFOW(fd,2) = type;
  10989. switch( type )
  10990. {
  10991. case SP_ATK1:
  10992. {
  10993. int atk = rand()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  10994. WFIFOL(fd,4) = cap_value(atk, 0, SHRT_MAX);
  10995. }
  10996. break;
  10997. case SP_MATK1:
  10998. WFIFOL(fd,4) = cap_value(status->matk_max, 0, SHRT_MAX);
  10999. break;
  11000. case SP_HIT:
  11001. WFIFOL(fd,4) = status->hit;
  11002. break;
  11003. case SP_CRITICAL:
  11004. WFIFOL(fd,4) = status->cri/10;
  11005. break;
  11006. case SP_DEF1:
  11007. WFIFOL(fd,4) = status->def;
  11008. break;
  11009. case SP_MDEF1:
  11010. WFIFOL(fd,4) = status->mdef;
  11011. break;
  11012. case SP_MERCFLEE:
  11013. WFIFOL(fd,4) = status->flee;
  11014. break;
  11015. case SP_ASPD:
  11016. WFIFOL(fd,4) = status->amotion;
  11017. break;
  11018. case SP_HP:
  11019. WFIFOL(fd,4) = status->hp;
  11020. break;
  11021. case SP_MAXHP:
  11022. WFIFOL(fd,4) = status->max_hp;
  11023. break;
  11024. case SP_SP:
  11025. WFIFOL(fd,4) = status->sp;
  11026. break;
  11027. case SP_MAXSP:
  11028. WFIFOL(fd,4) = status->max_sp;
  11029. break;
  11030. case SP_MERCKILLS:
  11031. WFIFOL(fd,4) = md->mercenary.kill_count;
  11032. break;
  11033. case SP_MERCFAITH:
  11034. WFIFOL(fd,4) = mercenary_get_faith(md);
  11035. break;
  11036. }
  11037. WFIFOSET(fd,8);
  11038. }
  11039. void clif_mercenary_info(struct map_session_data *sd)
  11040. {
  11041. int fd;
  11042. struct mercenary_data *md;
  11043. struct status_data *status;
  11044. int atk;
  11045. if( sd == NULL || (md = sd->md) == NULL )
  11046. return;
  11047. fd = sd->fd;
  11048. status = &md->battle_status;
  11049. WFIFOHEAD(fd,80);
  11050. WFIFOW(fd,0) = 0x029b;
  11051. WFIFOL(fd,2) = md->bl.id;
  11052. // Mercenary shows ATK as a random value between ATK ~ ATK2
  11053. atk = rand()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  11054. WFIFOW(fd,6) = cap_value(atk, 0, SHRT_MAX);
  11055. WFIFOW(fd,8) = cap_value(status->matk_max, 0, SHRT_MAX);
  11056. WFIFOW(fd,10) = status->hit;
  11057. WFIFOW(fd,12) = status->cri/10;
  11058. WFIFOW(fd,14) = status->def;
  11059. WFIFOW(fd,16) = status->mdef;
  11060. WFIFOW(fd,18) = status->flee;
  11061. WFIFOW(fd,20) = status->amotion;
  11062. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  11063. WFIFOW(fd,46) = md->db->lv;
  11064. WFIFOL(fd,48) = status->hp;
  11065. WFIFOL(fd,52) = status->max_hp;
  11066. WFIFOL(fd,56) = status->sp;
  11067. WFIFOL(fd,60) = status->max_sp;
  11068. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  11069. WFIFOW(fd,68) = mercenary_get_faith(md);
  11070. WFIFOL(fd,70) = mercenary_get_calls(md);
  11071. WFIFOL(fd,74) = md->mercenary.kill_count;
  11072. WFIFOW(fd,78) = md->battle_status.rhw.range;
  11073. WFIFOSET(fd,80);
  11074. }
  11075. void clif_mercenary_skillblock(struct map_session_data *sd)
  11076. {
  11077. struct mercenary_data *md;
  11078. int fd, i, len = 4, id, j;
  11079. if( sd == NULL || (md = sd->md) == NULL )
  11080. return;
  11081. fd = sd->fd;
  11082. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  11083. WFIFOW(fd,0) = 0x029d;
  11084. for( i = 0; i < MAX_MERCSKILL; i++ )
  11085. {
  11086. if( (id = md->db->skill[i].id) == 0 )
  11087. continue;
  11088. j = id - MC_SKILLBASE;
  11089. WFIFOW(fd,len) = id;
  11090. WFIFOW(fd,len+2) = skill_get_inf(id);
  11091. WFIFOW(fd,len+4) = 0;
  11092. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  11093. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  11094. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  11095. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  11096. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  11097. len += 37;
  11098. }
  11099. WFIFOW(fd,2) = len;
  11100. WFIFOSET(fd,len);
  11101. }
  11102. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  11103. {
  11104. int option = RFIFOB(fd,2);
  11105. if( sd->md == NULL )
  11106. return;
  11107. if( option == 2 ) merc_delete(sd->md, 2);
  11108. }
  11109. /*------------------------------------------
  11110. * Mercenary Message
  11111. * 0 = Mercenary soldier's duty hour is over.
  11112. * 1 = Your mercenary soldier has been killed.
  11113. * 2 = Your mercenary soldier has been fired.
  11114. * 3 = Your mercenary soldier has ran away.
  11115. *------------------------------------------*/
  11116. void clif_mercenary_message(int fd, int message)
  11117. {
  11118. WFIFOHEAD(fd,4);
  11119. WFIFOW(fd,0) = 0x0291;
  11120. WFIFOW(fd,2) = 1266 + message;
  11121. WFIFOSET(fd,4);
  11122. }
  11123. /*------------------------------------------
  11124. * Rental System Messages
  11125. *------------------------------------------*/
  11126. void clif_rental_time(int fd, int nameid, int seconds)
  11127. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  11128. WFIFOHEAD(fd,8);
  11129. WFIFOW(fd,0) = 0x0298;
  11130. WFIFOW(fd,2) = nameid;
  11131. WFIFOL(fd,4) = seconds;
  11132. WFIFOSET(fd,8);
  11133. }
  11134. void clif_rental_expired(int fd, int nameid)
  11135. { // '<ItemName>' item has been deleted from the Inventory
  11136. WFIFOHEAD(fd,6);
  11137. WFIFOW(fd,0) = 0x0299;
  11138. WFIFOW(fd,2) = 0;
  11139. WFIFOW(fd,4) = nameid;
  11140. WFIFOSET(fd,6);
  11141. }
  11142. /*------------------------------------------
  11143. * Book Reading
  11144. *------------------------------------------*/
  11145. void clif_readbook(int fd, int book_id, int page)
  11146. {
  11147. WFIFOHEAD(fd,10);
  11148. WFIFOW(fd,0) = 0x0294;
  11149. WFIFOL(fd,2) = book_id;
  11150. WFIFOL(fd,6) = page;
  11151. WFIFOSET(fd,10);
  11152. }
  11153. /*------------------------------------------
  11154. * BattleGround Packets
  11155. *------------------------------------------*/
  11156. int clif_bg_hp(struct map_session_data *sd)
  11157. {
  11158. unsigned char buf[16];
  11159. nullpo_retr(0, sd);
  11160. WBUFW(buf,0)=0x106;
  11161. WBUFL(buf,2) = sd->status.account_id;
  11162. if( sd->battle_status.max_hp > SHRT_MAX )
  11163. { // To correctly display the %hp bar. [Skotlex]
  11164. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  11165. WBUFW(buf,8) = 100;
  11166. }
  11167. else
  11168. {
  11169. WBUFW(buf,6) = sd->battle_status.hp;
  11170. WBUFW(buf,8) = sd->battle_status.max_hp;
  11171. }
  11172. clif_send(buf, packet_len(0x106), &sd->bl, BG_AREA_WOS);
  11173. return 0;
  11174. }
  11175. int clif_bg_xy(struct map_session_data *sd)
  11176. {
  11177. unsigned char buf[10];
  11178. nullpo_retr(0, sd);
  11179. WBUFW(buf,0)=0x1eb;
  11180. WBUFL(buf,2)=sd->status.account_id;
  11181. WBUFW(buf,6)=sd->bl.x;
  11182. WBUFW(buf,8)=sd->bl.y;
  11183. clif_send(buf, packet_len(0x1eb), &sd->bl, BG_SAMEMAP_WOS);
  11184. return 0;
  11185. }
  11186. int clif_bg_xy_remove(struct map_session_data *sd)
  11187. {
  11188. unsigned char buf[10];
  11189. nullpo_retr(0, sd);
  11190. WBUFW(buf,0)=0x1eb;
  11191. WBUFL(buf,2)=sd->status.account_id;
  11192. WBUFW(buf,6)=-1;
  11193. WBUFW(buf,8)=-1;
  11194. clif_send(buf,packet_len(0x1eb),&sd->bl,BG_SAMEMAP_WOS);
  11195. return 0;
  11196. }
  11197. int clif_bg_message(struct battleground_data *bg, const char *name, const char *mes, int len)
  11198. {
  11199. struct map_session_data *sd;
  11200. unsigned char *buf;
  11201. if( (sd = bg_getavailablesd(bg)) == NULL )
  11202. return 0;
  11203. buf = (unsigned char*)aMallocA((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  11204. WBUFW(buf,0) = 0x2dc;
  11205. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  11206. WBUFL(buf,4) = sd->state.bg_id;
  11207. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  11208. memcpy(WBUFP(buf,32), mes, len);
  11209. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  11210. if( buf ) aFree(buf);
  11211. return 0;
  11212. }
  11213. /*==========================================
  11214. * Validates and processes battlechat messages [pakpil]
  11215. * S 0x2db <packet len>.w <text>.?B (<name> : <message>) 00
  11216. *------------------------------------------*/
  11217. void clif_parse_BattleChat(int fd, struct map_session_data* sd)
  11218. {
  11219. const char* text = (char*)RFIFOP(fd,4);
  11220. int textlen = RFIFOW(fd,2) - 4;
  11221. char *name, *message;
  11222. int namelen, messagelen;
  11223. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  11224. return;
  11225. if( is_atcommand(fd, sd, message, 1) )
  11226. return;
  11227. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  11228. return;
  11229. if( battle_config.min_chat_delay )
  11230. {
  11231. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  11232. return;
  11233. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  11234. }
  11235. bg_send_message(sd, text, textlen);
  11236. }
  11237. int clif_bg_updatescore(int m)
  11238. {
  11239. struct block_list bl;
  11240. unsigned char buf[6];
  11241. bl.id = 0;
  11242. bl.type = BL_NUL;
  11243. bl.m = m;
  11244. WBUFW(buf,0) = 0x2de;
  11245. WBUFW(buf,2) = map[m].bgscore_lion;
  11246. WBUFW(buf,4) = map[m].bgscore_eagle;
  11247. clif_send(buf,6,&bl,ALL_SAMEMAP);
  11248. return 0;
  11249. }
  11250. int clif_bg_updatescore_single(struct map_session_data *sd)
  11251. {
  11252. int fd;
  11253. nullpo_retr(0,sd);
  11254. fd = sd->fd;
  11255. WFIFOHEAD(fd,6);
  11256. WFIFOW(fd,0) = 0x2de;
  11257. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  11258. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  11259. WFIFOSET(fd,6);
  11260. return 0;
  11261. }
  11262. int clif_sendbgemblem_area(struct map_session_data *sd)
  11263. {
  11264. unsigned char buf[33];
  11265. nullpo_retr(0,sd);
  11266. WBUFW(buf, 0) = 0x2dd;
  11267. WBUFL(buf,2) = sd->bl.id;
  11268. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  11269. WBUFW(buf,30) = sd->state.bg_id;
  11270. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  11271. return 0;
  11272. }
  11273. int clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  11274. {
  11275. nullpo_retr(0,sd);
  11276. WFIFOHEAD(fd,32);
  11277. WFIFOW(fd,0) = 0x2dd;
  11278. WFIFOL(fd,2) = sd->bl.id;
  11279. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  11280. WFIFOW(fd,30) = sd->state.bg_id;
  11281. WFIFOSET(fd,packet_len(0x2dd));
  11282. return 0;
  11283. }
  11284. /*==========================================
  11285. * Custom Fonts
  11286. * S 0x2ef <account_id>.l <font id>.w
  11287. *------------------------------------------*/
  11288. int clif_font_area(struct map_session_data *sd)
  11289. {
  11290. unsigned char buf[8];
  11291. nullpo_retr(0,sd);
  11292. WBUFW(buf,0) = 0x2ef;
  11293. WBUFL(buf,2) = sd->bl.id;
  11294. WBUFW(buf,6) = sd->state.user_font;
  11295. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  11296. return 1;
  11297. }
  11298. int clif_font_single(int fd, struct map_session_data *sd)
  11299. {
  11300. nullpo_retr(0,sd);
  11301. WFIFOHEAD(fd,packet_len(0x2ef));
  11302. WFIFOW(fd,0) = 0x2ef;
  11303. WFIFOL(fd,2) = sd->bl.id;
  11304. WFIFOW(fd,6) = sd->state.user_font;
  11305. WFIFOSET(fd,packet_len(0x2ef));
  11306. return 1;
  11307. }
  11308. /*==========================================
  11309. * パケットデバッグ
  11310. *------------------------------------------*/
  11311. void clif_parse_debug(int fd,struct map_session_data *sd)
  11312. {
  11313. int i, cmd, len;
  11314. cmd = RFIFOW(fd,0);
  11315. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  11316. ShowDebug("packet debug 0x%4X\n",cmd);
  11317. ShowMessage("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  11318. for(i=0;i<len;i++){
  11319. if((i&15)==0)
  11320. ShowMessage("\n%04X ",i);
  11321. ShowMessage("%02X ",RFIFOB(fd,i));
  11322. }
  11323. ShowMessage("\n");
  11324. }
  11325. /*==========================================
  11326. * Main client packet processing function
  11327. *------------------------------------------*/
  11328. int clif_parse(int fd)
  11329. {
  11330. int cmd, packet_ver, packet_len, err;
  11331. TBL_PC* sd;
  11332. int pnum;
  11333. //TODO apply deplays or disconnect based on packet throughput [FlavioJS]
  11334. // Note: "click masters" can do 80+ clicks in 10 seconds
  11335. for( pnum = 0; pnum < 3; ++pnum )// Limit max packets per cycle to 3 (delay packet spammers) [FlavioJS]
  11336. { // begin main client packet processing loop
  11337. sd = (TBL_PC *)session[fd]->session_data;
  11338. if (session[fd]->flag.eof) {
  11339. if (sd) {
  11340. if (sd->state.autotrade) {
  11341. //Disassociate character from the socket connection.
  11342. session[fd]->session_data = NULL;
  11343. sd->fd = 0;
  11344. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  11345. } else
  11346. if (sd->state.active) {
  11347. // Player logout display [Valaris]
  11348. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  11349. clif_quitsave(fd, sd);
  11350. } else {
  11351. //Unusual logout (during log on/off/map-changer procedure)
  11352. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  11353. map_quit(sd);
  11354. }
  11355. } else {
  11356. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  11357. }
  11358. do_close(fd);
  11359. return 0;
  11360. }
  11361. if (RFIFOREST(fd) < 2)
  11362. return 0;
  11363. cmd = RFIFOW(fd,0);
  11364. // identify client's packet version
  11365. if (sd) {
  11366. packet_ver = sd->packet_ver;
  11367. } else {
  11368. // check authentification packet to know packet version
  11369. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  11370. if( err )
  11371. {// failed to identify packet version
  11372. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  11373. err == 1 ? "" :
  11374. err == 2 ? ", possibly for having an invalid account_id" :
  11375. err == 3 ? ", possibly for having an invalid char_id." :
  11376. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  11377. err == 4 ? ", possibly for having an invalid login_id1." :
  11378. err == 5 ? ", possibly for having an invalid client_tick." :
  11379. */
  11380. err == 6 ? ", possibly for having an invalid sex." :
  11381. ". ERROR invalid error code"));
  11382. WFIFOHEAD(fd,packet_len(0x6a));
  11383. WFIFOW(fd,0) = 0x6a;
  11384. WFIFOB(fd,2) = 3; // Rejected from Server
  11385. WFIFOSET(fd,packet_len(0x6a));
  11386. RFIFOSKIP(fd, RFIFOREST(fd));
  11387. set_eof(fd);
  11388. return 0;
  11389. }
  11390. }
  11391. // filter out invalid / unsupported packets
  11392. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  11393. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  11394. set_eof(fd);
  11395. return 0;
  11396. }
  11397. // determine real packet length
  11398. packet_len = packet_db[packet_ver][cmd].len;
  11399. if (packet_len == -1) { // variable-length packet
  11400. if (RFIFOREST(fd) < 4)
  11401. return 0;
  11402. packet_len = RFIFOW(fd,2);
  11403. if (packet_len < 4 || packet_len > 32768) {
  11404. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  11405. set_eof(fd);
  11406. return 0;
  11407. }
  11408. }
  11409. if ((int)RFIFOREST(fd) < packet_len)
  11410. return 0; // not enough data received to form the packet
  11411. if (packet_db[packet_ver][cmd].func) {
  11412. if (sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck)
  11413. ; //Only valid packet when player is not on a map is the finish-loading packet.
  11414. else
  11415. if ((sd && sd->state.active)
  11416. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  11417. || packet_db[packet_ver][cmd].func == clif_parse_debug
  11418. ) //Only execute the function when there's an active sd (except for debug/wanttoconnect packets)
  11419. packet_db[packet_ver][cmd].func(fd, sd);
  11420. }
  11421. #if DUMP_UNKNOWN_PACKET
  11422. else if (battle_config.error_log)
  11423. {
  11424. int i;
  11425. FILE *fp;
  11426. char packet_txt[256] = "save/packet.txt";
  11427. time_t now;
  11428. dump = 1;
  11429. if ((fp = fopen(packet_txt, "a")) == NULL) {
  11430. ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
  11431. return 1;
  11432. } else {
  11433. time(&now);
  11434. if (sd && sd->state.active) {
  11435. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  11436. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  11437. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  11438. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  11439. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  11440. for(i = 0; i < packet_len; i++) {
  11441. if ((i & 15) == 0)
  11442. fprintf(fp, "\n\t%04X ", i);
  11443. fprintf(fp, "%02X ", RFIFOB(fd,i));
  11444. }
  11445. fprintf(fp, "\n\n");
  11446. fclose(fp);
  11447. }
  11448. }
  11449. #endif
  11450. /* TODO: use utils.c :: dump()
  11451. if (dump) {
  11452. int i;
  11453. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  11454. ShowMessage("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  11455. for(i = 0; i < packet_len; i++) {
  11456. if ((i & 15) == 0)
  11457. ShowMessage("\n%04X ",i);
  11458. ShowMessage("%02X ", RFIFOB(fd,i));
  11459. }
  11460. ShowMessage("\n");
  11461. if (sd && sd->state.active) {
  11462. if (sd->status.name != NULL)
  11463. ShowMessage("\nAccount ID %d, character ID %d, player name %s.\n",
  11464. sd->status.account_id, sd->status.char_id, sd->status.name);
  11465. else
  11466. ShowMessage("\nAccount ID %d.\n", sd->bl.id);
  11467. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  11468. ShowMessage("\nAccount ID %d.\n", sd->bl.id);
  11469. }*/
  11470. RFIFOSKIP(fd, packet_len);
  11471. }; // main loop end
  11472. return 0;
  11473. }
  11474. /*==========================================
  11475. * パケットデータベース読み込み
  11476. *------------------------------------------*/
  11477. static int packetdb_readdb(void)
  11478. {
  11479. FILE *fp;
  11480. char line[1024];
  11481. int ln=0;
  11482. int cmd,i,j,packet_ver;
  11483. int max_cmd=-1;
  11484. int skip_ver = 0;
  11485. int warned = 0;
  11486. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  11487. int packet_len_table[MAX_PACKET_DB] = {
  11488. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11492. //#0x0040
  11493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11495. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  11496. #if PACKETVER < 2
  11497. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  11498. #elif PACKETVER < 20071106 // 78-7b 亀島以降 lv99エフェクト用
  11499. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  11500. #else // change in 0x78 and 0x7c
  11501. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  11502. #endif
  11503. //#0x0080
  11504. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  11505. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  11506. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  11507. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  11508. //#0x00C0
  11509. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  11510. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  11511. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  11512. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  11513. //#0x0100
  11514. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  11515. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  11516. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  11517. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  11518. //#0x0140
  11519. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  11520. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  11521. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  11522. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  11523. //#0x0180
  11524. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  11525. #if PACKETVER < 1
  11526. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  11527. #else // 196 comodo以降 状態表示アイコン用
  11528. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  11529. #endif
  11530. #if PACKETVER < 20081126
  11531. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  11532. #else // 0x1a2 changed (35->37)
  11533. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  11534. #endif
  11535. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  11536. //#0x01C0, Set 0x1d5=-1
  11537. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  11538. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  11539. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  11540. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  11541. //#0x0200
  11542. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  11543. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  11544. #if PACKETVER < 20071106
  11545. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  11546. #else // 0x22c changed
  11547. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  11548. #endif
  11549. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, -1, -1, 4, 2,
  11550. //#0x0240
  11551. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  11552. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, -1, 4, 0,
  11553. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11554. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11555. //#0x0280
  11556. 0, 0, 0, 6, 0, 0, 0, 0, 0, 8, 18, 0, 0, 0, 0, 0,
  11557. 0, 4, 0, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11559. 0, 0, 0, 0, 0, 0, 0, 0, 0,191, 0, 0, 0, 0, 0, 0,
  11560. //#0x02C0
  11561. 0, 0, 0, 0, 0, 30, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0,
  11562. 0, 0, 0, 0, 0, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 0,
  11563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  11564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11565. //#0x0300
  11566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11570. //#0x0340
  11571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11575. //#0x0380
  11576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11580. //#0x03C0
  11581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11585. //#0x0400
  11586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  11590. //#0x0440
  11591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11595. //#0x0480
  11596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11600. //#0x04C0
  11601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11605. };
  11606. struct {
  11607. void (*func)(int, struct map_session_data *);
  11608. char *name;
  11609. } clif_parse_func[]={
  11610. {clif_parse_WantToConnection,"wanttoconnection"},
  11611. {clif_parse_LoadEndAck,"loadendack"},
  11612. {clif_parse_TickSend,"ticksend"},
  11613. {clif_parse_WalkToXY,"walktoxy"},
  11614. {clif_parse_QuitGame,"quitgame"},
  11615. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  11616. {clif_parse_GlobalMessage,"globalmessage"},
  11617. {clif_parse_MapMove,"mapmove"},
  11618. {clif_parse_ChangeDir,"changedir"},
  11619. {clif_parse_Emotion,"emotion"},
  11620. {clif_parse_HowManyConnections,"howmanyconnections"},
  11621. {clif_parse_ActionRequest,"actionrequest"},
  11622. {clif_parse_Restart,"restart"},
  11623. {clif_parse_WisMessage,"wis"},
  11624. {clif_parse_GMmessage,"gmmessage"},
  11625. {clif_parse_TakeItem,"takeitem"},
  11626. {clif_parse_DropItem,"dropitem"},
  11627. {clif_parse_UseItem,"useitem"},
  11628. {clif_parse_EquipItem,"equipitem"},
  11629. {clif_parse_UnequipItem,"unequipitem"},
  11630. {clif_parse_NpcClicked,"npcclicked"},
  11631. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  11632. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  11633. {clif_parse_NpcSellListSend,"npcselllistsend"},
  11634. {clif_parse_CreateChatRoom,"createchatroom"},
  11635. {clif_parse_ChatAddMember,"chataddmember"},
  11636. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  11637. {clif_parse_ChangeChatOwner,"changechatowner"},
  11638. {clif_parse_KickFromChat,"kickfromchat"},
  11639. {clif_parse_ChatLeave,"chatleave"},
  11640. {clif_parse_TradeRequest,"traderequest"},
  11641. {clif_parse_TradeAck,"tradeack"},
  11642. {clif_parse_TradeAddItem,"tradeadditem"},
  11643. {clif_parse_TradeOk,"tradeok"},
  11644. {clif_parse_TradeCancel,"tradecancel"},
  11645. {clif_parse_TradeCommit,"tradecommit"},
  11646. {clif_parse_StopAttack,"stopattack"},
  11647. {clif_parse_PutItemToCart,"putitemtocart"},
  11648. {clif_parse_GetItemFromCart,"getitemfromcart"},
  11649. {clif_parse_RemoveOption,"removeoption"},
  11650. {clif_parse_ChangeCart,"changecart"},
  11651. {clif_parse_StatusUp,"statusup"},
  11652. {clif_parse_SkillUp,"skillup"},
  11653. {clif_parse_UseSkillToId,"useskilltoid"},
  11654. {clif_parse_UseSkillToPos,"useskilltopos"},
  11655. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  11656. {clif_parse_UseSkillMap,"useskillmap"},
  11657. {clif_parse_RequestMemo,"requestmemo"},
  11658. {clif_parse_ProduceMix,"producemix"},
  11659. {clif_parse_Cooking,"cooking"},
  11660. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  11661. {clif_parse_NpcNextClicked,"npcnextclicked"},
  11662. {clif_parse_NpcAmountInput,"npcamountinput"},
  11663. {clif_parse_NpcStringInput,"npcstringinput"},
  11664. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  11665. {clif_parse_ItemIdentify,"itemidentify"},
  11666. {clif_parse_SelectArrow,"selectarrow"},
  11667. {clif_parse_AutoSpell,"autospell"},
  11668. {clif_parse_UseCard,"usecard"},
  11669. {clif_parse_InsertCard,"insertcard"},
  11670. {clif_parse_RepairItem,"repairitem"},
  11671. {clif_parse_WeaponRefine,"weaponrefine"},
  11672. {clif_parse_SolveCharName,"solvecharname"},
  11673. {clif_parse_ResetChar,"resetchar"},
  11674. {clif_parse_LGMmessage,"lgmmessage"},
  11675. {clif_parse_MoveToKafra,"movetokafra"},
  11676. {clif_parse_MoveFromKafra,"movefromkafra"},
  11677. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  11678. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  11679. {clif_parse_CloseKafra,"closekafra"},
  11680. {clif_parse_CreateParty,"createparty"},
  11681. {clif_parse_CreateParty2,"createparty2"},
  11682. {clif_parse_PartyInvite,"partyinvite"},
  11683. {clif_parse_PartyInvite2,"partyinvite2"},
  11684. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  11685. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  11686. {clif_parse_LeaveParty,"leaveparty"},
  11687. {clif_parse_RemovePartyMember,"removepartymember"},
  11688. {clif_parse_PartyChangeOption,"partychangeoption"},
  11689. {clif_parse_PartyMessage,"partymessage"},
  11690. {clif_parse_CloseVending,"closevending"},
  11691. {clif_parse_VendingListReq,"vendinglistreq"},
  11692. {clif_parse_PurchaseReq,"purchasereq"},
  11693. {clif_parse_OpenVending,"openvending"},
  11694. {clif_parse_CreateGuild,"createguild"},
  11695. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  11696. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  11697. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  11698. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  11699. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  11700. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  11701. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  11702. {clif_parse_GuildInvite,"guildinvite"},
  11703. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  11704. {clif_parse_GuildLeave,"guildleave"},
  11705. {clif_parse_GuildExpulsion,"guildexpulsion"},
  11706. {clif_parse_GuildMessage,"guildmessage"},
  11707. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  11708. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  11709. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  11710. {clif_parse_GuildOpposition,"guildopposition"},
  11711. {clif_parse_GuildBreak,"guildbreak"},
  11712. {clif_parse_PetMenu,"petmenu"},
  11713. {clif_parse_CatchPet,"catchpet"},
  11714. {clif_parse_SelectEgg,"selectegg"},
  11715. {clif_parse_SendEmotion,"sendemotion"},
  11716. {clif_parse_ChangePetName,"changepetname"},
  11717. {clif_parse_GMKick,"gmkick"},
  11718. {clif_parse_GMHide,"gmhide"},
  11719. {clif_parse_GMReqNoChat,"gmreqnochat"},
  11720. {clif_parse_GMReqAccountName,"gmreqaccname"},
  11721. {clif_parse_GMKickAll,"killall"},
  11722. {clif_parse_GMRecall,"recall"},
  11723. {clif_parse_GMRecall,"summon"},
  11724. {clif_parse_GM_Monster_Item,"itemmonster"},
  11725. {clif_parse_GMShift,"remove"},
  11726. {clif_parse_GMShift,"shift"},
  11727. {clif_parse_GMChangeMapType,"changemaptype"},
  11728. {clif_parse_GMRc,"rc"},
  11729. {clif_parse_NoviceDoriDori,"sndoridori"},
  11730. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  11731. {clif_parse_PMIgnore,"wisexin"},
  11732. {clif_parse_PMIgnoreList,"wisexlist"},
  11733. {clif_parse_PMIgnoreAll,"wisall"},
  11734. {clif_parse_FriendsListAdd,"friendslistadd"},
  11735. {clif_parse_FriendsListRemove,"friendslistremove"},
  11736. {clif_parse_FriendsListReply,"friendslistreply"},
  11737. {clif_parse_Blacksmith,"blacksmith"},
  11738. {clif_parse_Alchemist,"alchemist"},
  11739. {clif_parse_Taekwon,"taekwon"},
  11740. {clif_parse_RankingPk,"rankingpk"},
  11741. {clif_parse_FeelSaveOk,"feelsaveok"},
  11742. {clif_parse_debug,"debug"},
  11743. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  11744. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  11745. {clif_parse_HomMoveTo,"hommoveto"},
  11746. {clif_parse_HomAttack,"homattack"},
  11747. {clif_parse_HomMenu,"hommenu"},
  11748. {clif_parse_StoragePassword,"storagepassword"},
  11749. {clif_parse_Hotkey,"hotkey"},
  11750. {clif_parse_AutoRevive,"autorevive"},
  11751. {clif_parse_Check,"check"},
  11752. {clif_parse_Adopt_request,"adoptrequest"},
  11753. {clif_parse_Adopt_reply,"adoptreply"},
  11754. #ifndef TXT_ONLY
  11755. // MAIL SYSTEM
  11756. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  11757. {clif_parse_Mail_read,"mailread"},
  11758. {clif_parse_Mail_getattach,"mailgetattach"},
  11759. {clif_parse_Mail_delete,"maildelete"},
  11760. {clif_parse_Mail_return,"mailreturn"},
  11761. {clif_parse_Mail_setattach,"mailsetattach"},
  11762. {clif_parse_Mail_winopen,"mailwinopen"},
  11763. {clif_parse_Mail_send,"mailsend"},
  11764. // AUCTION SYSTEM
  11765. {clif_parse_Auction_search,"auctionsearch"},
  11766. {clif_parse_Auction_buysell,"auctionbuysell"},
  11767. {clif_parse_Auction_setitem,"auctionsetitem"},
  11768. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  11769. {clif_parse_Auction_register,"auctionregister"},
  11770. {clif_parse_Auction_cancel,"auctioncancel"},
  11771. {clif_parse_Auction_close,"auctionclose"},
  11772. {clif_parse_Auction_bid,"auctionbid"},
  11773. #endif
  11774. {clif_parse_cashshop_buy,"cashshopbuy"},
  11775. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  11776. {clif_parse_EquipTick,"equiptickbox"},
  11777. {clif_parse_BattleChat,"battlechat"},
  11778. {clif_parse_mercenary_action,"mermenu"},
  11779. {NULL,NULL}
  11780. };
  11781. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  11782. memset(packet_db,0,sizeof(packet_db));
  11783. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  11784. packet_len(i) = packet_len_table[i];
  11785. sprintf(line, "%s/packet_db.txt", db_path);
  11786. if( (fp=fopen(line,"r"))==NULL ){
  11787. ShowFatalError("can't read %s\n", line);
  11788. exit(EXIT_FAILURE);
  11789. }
  11790. clif_config.packet_db_ver = MAX_PACKET_VER;
  11791. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  11792. while( fgets(line, sizeof(line), fp) )
  11793. {
  11794. ln++;
  11795. if(line[0]=='/' && line[1]=='/')
  11796. continue;
  11797. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  11798. {
  11799. if(strcmpi(w1,"packet_ver")==0) {
  11800. int prev_ver = packet_ver;
  11801. skip_ver = 0;
  11802. packet_ver = atoi(w2);
  11803. if ( packet_ver > MAX_PACKET_VER )
  11804. { //Check to avoid overflowing. [Skotlex]
  11805. if( (warned&1) == 0 )
  11806. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  11807. warned &= 1;
  11808. skip_ver = 1;
  11809. }
  11810. else if( packet_ver < 0 )
  11811. {
  11812. if( (warned&2) == 0 )
  11813. ShowWarning("Negative packet versions are not supported.\n");
  11814. warned &= 2;
  11815. skip_ver = 1;
  11816. }
  11817. else if( packet_ver == SERVER )
  11818. {
  11819. if( (warned&4) == 0 )
  11820. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  11821. warned &= 4;
  11822. skip_ver = 1;
  11823. }
  11824. if( skip_ver )
  11825. {
  11826. ShowWarning("Skipping packet version %d.\n", packet_ver);
  11827. packet_ver = prev_ver;
  11828. continue;
  11829. }
  11830. // copy from previous version into new version and continue
  11831. // - indicating all following packets should be read into the newer version
  11832. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  11833. continue;
  11834. } else if(strcmpi(w1,"packet_db_ver")==0) {
  11835. if(strcmpi(w2,"default")==0) //This is the preferred version.
  11836. clif_config.packet_db_ver = MAX_PACKET_VER;
  11837. else // to manually set the packet DB version
  11838. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  11839. continue;
  11840. }
  11841. }
  11842. if( skip_ver != 0 )
  11843. continue; // Skipping current packet version
  11844. memset(str,0,sizeof(str));
  11845. for(j=0,p=line;j<4 && p; ++j)
  11846. {
  11847. str[j]=p;
  11848. p=strchr(p,',');
  11849. if(p) *p++=0;
  11850. }
  11851. if(str[0]==NULL)
  11852. continue;
  11853. cmd=strtol(str[0],(char **)NULL,0);
  11854. if(max_cmd < cmd)
  11855. max_cmd = cmd;
  11856. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  11857. continue;
  11858. if(str[1]==NULL){
  11859. ShowError("packet_db: packet len error\n");
  11860. continue;
  11861. }
  11862. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  11863. if(str[2]==NULL){
  11864. packet_db[packet_ver][cmd].func = NULL;
  11865. ln++;
  11866. continue;
  11867. }
  11868. // look up processing function by name
  11869. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  11870. if( j < ARRAYLENGTH(clif_parse_func) )
  11871. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  11872. // set the identifying cmd for the packet_db version
  11873. if (strcmp(str[2],"wanttoconnection")==0)
  11874. clif_config.connect_cmd[packet_ver] = cmd;
  11875. if(str[3]==NULL){
  11876. ShowError("packet_db: packet error\n");
  11877. exit(EXIT_FAILURE);
  11878. }
  11879. for(j=0,p2=str[3];p2;j++){
  11880. short k;
  11881. str2[j]=p2;
  11882. p2=strchr(p2,':');
  11883. if(p2) *p2++=0;
  11884. k = atoi(str2[j]);
  11885. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  11886. packet_db[packet_ver][cmd].pos[j] = k;
  11887. }
  11888. }
  11889. fclose(fp);
  11890. if(max_cmd > MAX_PACKET_DB)
  11891. {
  11892. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  11893. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  11894. }
  11895. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  11896. { //Locate the nearest version that we still support. [Skotlex]
  11897. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  11898. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  11899. }
  11900. ShowStatus("Done reading packet database from '"CL_WHITE"%s"CL_RESET"'. Using default packet version: "CL_WHITE"%d"CL_RESET".\n", "packet_db.txt", clif_config.packet_db_ver);
  11901. return 0;
  11902. }
  11903. /*==========================================
  11904. *
  11905. *------------------------------------------*/
  11906. int do_init_clif(void)
  11907. {
  11908. clif_config.packet_db_ver = -1; // the main packet version of the DB
  11909. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  11910. memset(packet_db,0,sizeof(packet_db));
  11911. //Using the packet_db file is the only way to set up packets now [Skotlex]
  11912. packetdb_readdb();
  11913. set_defaultparse(clif_parse);
  11914. if( make_listen_bind(bind_ip,map_port) == -1 )
  11915. {
  11916. ShowFatalError("can't bind game port\n");
  11917. exit(EXIT_FAILURE);
  11918. }
  11919. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  11920. add_timer_func_list(clif_delayquit, "clif_delayquit");
  11921. return 0;
  11922. }