clif.c 396 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764
  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 "instance.h"
  35. #include "mercenary.h"
  36. #include "log.h"
  37. #include "clif.h"
  38. #include "mail.h"
  39. #include "quest.h"
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include <stdarg.h>
  44. #include <time.h>
  45. #define DUMP_UNKNOWN_PACKET 0
  46. struct Clif_Config {
  47. int packet_db_ver; //Preferred packet version.
  48. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  49. } clif_config;
  50. struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
  51. //Converts item type in case of pet eggs.
  52. #define itemtype(a) (a == IT_PETEGG)?IT_WEAPON:a
  53. #define WBUFPOS(p,pos,x,y,dir) \
  54. do { \
  55. uint8 *__p = (p); \
  56. __p+=(pos); \
  57. __p[0] = (uint8)((x)>>2); \
  58. __p[1] = (uint8)(((x)<<6) | (((y)>>4)&0x3f)); \
  59. __p[2] = (uint8)(((y)<<4) | ((dir)&0xf)); \
  60. } while(0)
  61. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  62. #define WBUFPOS2(p,pos,x0,y0,x1,y1,sx0,sy0) \
  63. do { \
  64. uint8 *__p = (p); \
  65. __p+=(pos); \
  66. __p[0]=(uint8)((x0)>>2); \
  67. __p[1]=(uint8)(((x0)<<6) | (((y0)>>4)&0x3f)); \
  68. __p[2]=(uint8)(((y0)<<4) | (((x1)>>6)&0x0f)); \
  69. __p[3]=(uint8)(((x1)<<2) | (((y1)>>8)&0x03)); \
  70. __p[4]=(uint8)(y1); \
  71. __p[5]=(uint8)(((sx0)<<4) | ((sy0)&0x0f)); \
  72. } while(0)
  73. #define WFIFOPOS(fd,pos,x,y,dir) WBUFPOS(WFIFOP(fd,pos),0,x,y,dir)
  74. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1,sx0,sy0) WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1,sx0,sy0)
  75. //To idenfity disguised characters.
  76. #define disguised(bl) ((bl)->type==BL_PC && ((TBL_PC*)bl)->disguise)
  77. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex\]
  78. #define mes_len_check(mes, len, max) if (len > max) { mes[max-1] = '\0'; len = max; } else mes[len-1] = '\0';
  79. static char map_ip_str[128];
  80. static uint32 map_ip;
  81. static uint32 bind_ip = INADDR_ANY;
  82. static uint16 map_port = 5121;
  83. int map_fd;
  84. int clif_parse (int fd);
  85. /*==========================================
  86. * map鯖のip設定
  87. *------------------------------------------*/
  88. int clif_setip(const char* ip)
  89. {
  90. char ip_str[16];
  91. map_ip = host2ip(ip);
  92. if (!map_ip) {
  93. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  94. return 0;
  95. }
  96. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  97. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  98. return 1;
  99. }
  100. void clif_setbindip(const char* ip)
  101. {
  102. char ip_str[16];
  103. bind_ip = host2ip(ip);
  104. if (bind_ip) {
  105. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  106. } else {
  107. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  108. }
  109. }
  110. /*==========================================
  111. * map鯖のport設定
  112. *------------------------------------------*/
  113. void clif_setport(uint16 port)
  114. {
  115. map_port = port;
  116. }
  117. /*==========================================
  118. * map鯖のip読み出し
  119. *------------------------------------------*/
  120. uint32 clif_getip(void)
  121. {
  122. return map_ip;
  123. }
  124. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  125. uint32 clif_refresh_ip(void)
  126. {
  127. uint32 new_ip;
  128. new_ip = host2ip(map_ip_str);
  129. if (new_ip && new_ip != map_ip) {
  130. map_ip = new_ip;
  131. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  132. return map_ip;
  133. }
  134. return 0;
  135. }
  136. /*==========================================
  137. * map鯖のport読み出し
  138. *------------------------------------------*/
  139. uint16 clif_getport(void)
  140. {
  141. return map_port;
  142. }
  143. #if PACKETVER >= 20071106
  144. static inline unsigned char clif_bl_type(struct block_list *bl) {
  145. switch (bl->type) {
  146. case BL_PC: return disguised(bl)?0x1:0x0; //PC_TYPE
  147. case BL_ITEM: return 0x2; //ITEM_TYPE
  148. case BL_SKILL: return 0x3; //SKILL_TYPE
  149. case BL_CHAT: return 0x4; //UNKNOWN_TYPE
  150. case BL_MOB: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x5; //NPC_MOB_TYPE
  151. case BL_NPC: return 0x6; //NPC_EVT_TYPE
  152. case BL_PET: return pcdb_checkid(status_get_viewdata(bl)->class_)?0x0:0x7; //NPC_PET_TYPE
  153. case BL_HOM: return 0x8; //NPC_HOM_TYPE
  154. case BL_MER: return 0x9; //NPC_MERSOL_TYPE
  155. // case BL_ELEM: return 0xA; //NPC_ELEMENTAL_TYPE
  156. default: return 0x1; //NPC_TYPE
  157. }
  158. }
  159. #endif
  160. /*==========================================
  161. * clif_sendでAREA*指定時用
  162. *------------------------------------------*/
  163. int clif_send_sub(struct block_list *bl, va_list ap)
  164. {
  165. struct block_list *src_bl;
  166. struct map_session_data *sd;
  167. unsigned char *buf;
  168. int len, type, fd;
  169. nullpo_ret(bl);
  170. nullpo_ret(sd = (struct map_session_data *)bl);
  171. fd = sd->fd;
  172. if (!fd) //Don't send to disconnected clients.
  173. return 0;
  174. buf = va_arg(ap,unsigned char*);
  175. len = va_arg(ap,int);
  176. nullpo_ret(src_bl = va_arg(ap,struct block_list*));
  177. type = va_arg(ap,int);
  178. switch(type)
  179. {
  180. case AREA_WOS:
  181. if (bl == src_bl)
  182. return 0;
  183. break;
  184. case AREA_WOC:
  185. if (sd->chatID || bl == src_bl)
  186. return 0;
  187. break;
  188. case AREA_WOSC:
  189. {
  190. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  191. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  192. return 0;
  193. }
  194. break;
  195. }
  196. if (session[fd] == NULL)
  197. return 0;
  198. WFIFOHEAD(fd, len);
  199. if (WFIFOP(fd,0) == buf) {
  200. ShowError("WARNING: Invalid use of clif_send function\n");
  201. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  202. ShowError(" Please correct your code.\n");
  203. // don't send to not move the pointer of the packet for next sessions in the loop
  204. //WFIFOSET(fd,0);//## TODO is this ok?
  205. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  206. return 0;
  207. }
  208. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  209. memcpy(WFIFOP(fd,0), buf, len);
  210. WFIFOSET(fd,len);
  211. }
  212. return 0;
  213. }
  214. /*==========================================
  215. *
  216. *------------------------------------------*/
  217. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  218. {
  219. int i;
  220. struct map_session_data *sd, *tsd;
  221. struct party_data *p = NULL;
  222. struct guild *g = NULL;
  223. struct battleground_data *bg = NULL;
  224. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  225. struct s_mapiterator* iter;
  226. if( type != ALL_CLIENT && type != CHAT_MAINCHAT )
  227. nullpo_ret(bl);
  228. sd = BL_CAST(BL_PC, bl);
  229. switch(type) {
  230. case ALL_CLIENT: //All player clients.
  231. iter = mapit_getallusers();
  232. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  233. {
  234. if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  235. { // packet must exist for the client version
  236. WFIFOHEAD(tsd->fd, len);
  237. memcpy(WFIFOP(tsd->fd,0), buf, len);
  238. WFIFOSET(tsd->fd,len);
  239. }
  240. }
  241. mapit_free(iter);
  242. break;
  243. case ALL_SAMEMAP: //All players on the same map
  244. iter = mapit_getallusers();
  245. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  246. {
  247. if( bl->m == tsd->bl.m && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  248. { // packet must exist for the client version
  249. WFIFOHEAD(tsd->fd, len);
  250. memcpy(WFIFOP(tsd->fd,0), buf, len);
  251. WFIFOSET(tsd->fd,len);
  252. }
  253. }
  254. mapit_free(iter);
  255. break;
  256. case AREA:
  257. case AREA_WOSC:
  258. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  259. clif_send (buf, len, bl, SELF);
  260. case AREA_WOC:
  261. case AREA_WOS:
  262. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  263. BL_PC, buf, len, bl, type);
  264. break;
  265. case AREA_CHAT_WOC:
  266. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  267. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  268. break;
  269. case CHAT:
  270. case CHAT_WOS:
  271. {
  272. struct chat_data *cd;
  273. if (sd) {
  274. cd = (struct chat_data*)map_id2bl(sd->chatID);
  275. } else if (bl->type == BL_CHAT) {
  276. cd = (struct chat_data*)bl;
  277. } else break;
  278. if (cd == NULL)
  279. break;
  280. for(i = 0; i < cd->users; i++) {
  281. if (type == CHAT_WOS && cd->usersd[i] == sd)
  282. continue;
  283. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  284. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  285. {
  286. WFIFOHEAD(fd,len);
  287. memcpy(WFIFOP(fd,0), buf, len);
  288. WFIFOSET(fd,len);
  289. }
  290. }
  291. }
  292. }
  293. break;
  294. case CHAT_MAINCHAT: //[LuzZza]
  295. iter = mapit_getallusers();
  296. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  297. {
  298. if( tsd->state.mainchat && tsd->chatID == 0 && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  299. { // packet must exist for the client version
  300. WFIFOHEAD(tsd->fd, len);
  301. memcpy(WFIFOP(tsd->fd,0), buf, len);
  302. WFIFOSET(tsd->fd,len);
  303. }
  304. }
  305. mapit_free(iter);
  306. break;
  307. case PARTY_AREA:
  308. case PARTY_AREA_WOS:
  309. x0 = bl->x - AREA_SIZE;
  310. y0 = bl->y - AREA_SIZE;
  311. x1 = bl->x + AREA_SIZE;
  312. y1 = bl->y + AREA_SIZE;
  313. case PARTY:
  314. case PARTY_WOS:
  315. case PARTY_SAMEMAP:
  316. case PARTY_SAMEMAP_WOS:
  317. if (sd && sd->status.party_id)
  318. p = party_search(sd->status.party_id);
  319. if (p) {
  320. for(i=0;i<MAX_PARTY;i++){
  321. if( (sd = p->data[i].sd) == NULL )
  322. continue;
  323. if( !(fd=sd->fd) )
  324. continue;
  325. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  326. continue;
  327. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  328. continue;
  329. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  330. continue;
  331. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  332. { // packet must exist for the client version
  333. WFIFOHEAD(fd,len);
  334. memcpy(WFIFOP(fd,0), buf, len);
  335. WFIFOSET(fd,len);
  336. }
  337. }
  338. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  339. break;
  340. iter = mapit_getallusers();
  341. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  342. {
  343. if( tsd->partyspy == p->party.party_id && 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. }
  352. break;
  353. case DUEL:
  354. case DUEL_WOS:
  355. if (!sd || !sd->duel_group) break; //Invalid usage.
  356. iter = mapit_getallusers();
  357. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  358. {
  359. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  360. continue;
  361. if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  362. { // packet must exist for the client version
  363. WFIFOHEAD(tsd->fd, len);
  364. memcpy(WFIFOP(tsd->fd,0), buf, len);
  365. WFIFOSET(tsd->fd,len);
  366. }
  367. }
  368. mapit_free(iter);
  369. break;
  370. case SELF:
  371. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  372. WFIFOHEAD(fd,len);
  373. memcpy(WFIFOP(fd,0), buf, len);
  374. WFIFOSET(fd,len);
  375. }
  376. break;
  377. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  378. case GUILD_AREA:
  379. case GUILD_AREA_WOS:
  380. x0 = bl->x - AREA_SIZE;
  381. y0 = bl->y - AREA_SIZE;
  382. x1 = bl->x + AREA_SIZE;
  383. y1 = bl->y + AREA_SIZE;
  384. case GUILD_SAMEMAP:
  385. case GUILD_SAMEMAP_WOS:
  386. case GUILD:
  387. case GUILD_WOS:
  388. case GUILD_NOBG:
  389. if (sd && sd->status.guild_id)
  390. g = guild_search(sd->status.guild_id);
  391. if (g) {
  392. for(i = 0; i < g->max_member; i++) {
  393. if( (sd = g->member[i].sd) != NULL )
  394. {
  395. if( !(fd=sd->fd) )
  396. continue;
  397. if( type == GUILD_NOBG && sd->state.bg_id )
  398. continue;
  399. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  400. continue;
  401. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  402. continue;
  403. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  404. continue;
  405. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  406. { // packet must exist for the client version
  407. WFIFOHEAD(fd,len);
  408. memcpy(WFIFOP(fd,0), buf, len);
  409. WFIFOSET(fd,len);
  410. }
  411. }
  412. }
  413. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  414. break;
  415. iter = mapit_getallusers();
  416. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  417. {
  418. if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  419. { // packet must exist for the client version
  420. WFIFOHEAD(tsd->fd, len);
  421. memcpy(WFIFOP(tsd->fd,0), buf, len);
  422. WFIFOSET(tsd->fd,len);
  423. }
  424. }
  425. mapit_free(iter);
  426. }
  427. break;
  428. case BG_AREA:
  429. case BG_AREA_WOS:
  430. x0 = bl->x - AREA_SIZE;
  431. y0 = bl->y - AREA_SIZE;
  432. x1 = bl->x + AREA_SIZE;
  433. y1 = bl->y + AREA_SIZE;
  434. case BG_SAMEMAP:
  435. case BG_SAMEMAP_WOS:
  436. case BG:
  437. case BG_WOS:
  438. if( sd && sd->state.bg_id && (bg = bg_team_search(sd->state.bg_id)) != NULL )
  439. {
  440. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  441. {
  442. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  443. continue;
  444. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  445. continue;
  446. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  447. continue;
  448. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  449. continue;
  450. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  451. { // packet must exist for the client version
  452. WFIFOHEAD(fd,len);
  453. memcpy(WFIFOP(fd,0), buf, len);
  454. WFIFOSET(fd,len);
  455. }
  456. }
  457. }
  458. break;
  459. default:
  460. ShowError("clif_send: Unrecognized type %d\n",type);
  461. return -1;
  462. }
  463. return 0;
  464. }
  465. //
  466. // パケット作って送信
  467. //
  468. /*==========================================
  469. *
  470. *------------------------------------------*/
  471. int clif_authok(struct map_session_data *sd)
  472. {
  473. int fd;
  474. if (!sd->fd)
  475. return 0;
  476. fd = sd->fd;
  477. WFIFOHEAD(fd, packet_len(0x73));
  478. WFIFOW(fd, 0) = 0x73;
  479. WFIFOL(fd, 2) = gettick();
  480. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  481. WFIFOB(fd, 9) = 5; // ignored
  482. WFIFOB(fd,10) = 5; // ignored
  483. WFIFOSET(fd,packet_len(0x73));
  484. return 0;
  485. }
  486. /*==========================================
  487. * Authentication failed/disconnect client.
  488. *------------------------------------------
  489. * The client closes it's socket and displays a message according to type:
  490. * 1 - server closed -> MsgStringTable[4]
  491. * 2 - ID already logged in -> MsgStringTable[5]
  492. * 3 - timeout/too much lag -> MsgStringTable[241]
  493. * 4 - server full -> MsgStringTable[264]
  494. * 5 - underaged -> MsgStringTable[305]
  495. * 8 - Server sill recognizes last connection -> MsgStringTable[441]
  496. * 9 - too many connections from this ip -> MsgStringTable[529]
  497. * 10 - out of available time paid for -> MsgStringTable[530]
  498. * 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  499. * other - disconnected -> MsgStringTable[3]
  500. */
  501. int clif_authfail_fd(int fd, int type)
  502. {
  503. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  504. return 0;
  505. WFIFOHEAD(fd, packet_len(0x81));
  506. WFIFOW(fd,0) = 0x81;
  507. WFIFOB(fd,2) = type;
  508. WFIFOSET(fd,packet_len(0x81));
  509. set_eof(fd);
  510. return 0;
  511. }
  512. /*==========================================
  513. *
  514. *------------------------------------------*/
  515. int clif_charselectok(int id)
  516. {
  517. struct map_session_data* sd;
  518. int fd;
  519. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  520. return 1;
  521. fd = sd->fd;
  522. WFIFOHEAD(fd,packet_len(0xb3));
  523. WFIFOW(fd,0) = 0xb3;
  524. WFIFOB(fd,2) = 1;
  525. WFIFOSET(fd,packet_len(0xb3));
  526. return 0;
  527. }
  528. /*==========================================
  529. * Makes an item appear on the ground
  530. * 009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  531. *------------------------------------------*/
  532. int clif_dropflooritem(struct flooritem_data* fitem)
  533. {
  534. uint8 buf[17];
  535. int view;
  536. nullpo_ret(fitem);
  537. if (fitem->item_data.nameid <= 0)
  538. return 0;
  539. WBUFW(buf, 0) = 0x9e;
  540. WBUFL(buf, 2) = fitem->bl.id;
  541. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  542. WBUFB(buf, 8) = fitem->item_data.identify;
  543. WBUFW(buf, 9) = fitem->bl.x;
  544. WBUFW(buf,11) = fitem->bl.y;
  545. WBUFB(buf,13) = fitem->subx;
  546. WBUFB(buf,14) = fitem->suby;
  547. WBUFW(buf,15) = fitem->item_data.amount;
  548. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  549. return 0;
  550. }
  551. /*==========================================
  552. *
  553. *------------------------------------------*/
  554. int clif_clearflooritem(struct flooritem_data *fitem, int fd)
  555. {
  556. unsigned char buf[16];
  557. nullpo_ret(fitem);
  558. WBUFW(buf,0) = 0xa1;
  559. WBUFL(buf,2) = fitem->bl.id;
  560. if (fd == 0) {
  561. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  562. } else {
  563. WFIFOHEAD(fd,packet_len(0xa1));
  564. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  565. WFIFOSET(fd,packet_len(0xa1));
  566. }
  567. return 0;
  568. }
  569. /*==========================================
  570. * make a unit (char, npc, mob, homun) disappear to one client
  571. * id : the id of the unit
  572. * type: 0 - moved out of sight
  573. * 1 - died
  574. * 2 - respawned
  575. * 3 - teleported / logged out
  576. * fd : the target client
  577. *------------------------------------------*/
  578. int clif_clearunit_single(int id, clr_type type, int fd)
  579. {
  580. WFIFOHEAD(fd, packet_len(0x80));
  581. WFIFOW(fd,0) = 0x80;
  582. WFIFOL(fd,2) = id;
  583. WFIFOB(fd,6) = type;
  584. WFIFOSET(fd, packet_len(0x80));
  585. return 0;
  586. }
  587. /*==========================================
  588. * make a unit (char, npc, mob, homun) disappear to all clients in area
  589. * type: 0 - moved out of sight
  590. * 1 - died
  591. * 2 - respawned
  592. * 3 - teleported / logged out
  593. *------------------------------------------*/
  594. int clif_clearunit_area(struct block_list* bl, clr_type type)
  595. {
  596. unsigned char buf[16];
  597. nullpo_ret(bl);
  598. WBUFW(buf,0) = 0x80;
  599. WBUFL(buf,2) = bl->id;
  600. WBUFB(buf,6) = type;
  601. clif_send(buf, packet_len(0x80), bl, type == CLR_DEAD ? AREA : AREA_WOS);
  602. if(disguised(bl)) {
  603. WBUFL(buf,2) = -bl->id;
  604. clif_send(buf, packet_len(0x80), bl, SELF);
  605. }
  606. return 0;
  607. }
  608. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr data)
  609. {
  610. struct block_list *bl = (struct block_list *)data;
  611. clif_clearunit_area(bl, CLR_OUTSIGHT);
  612. aFree(bl);
  613. return 0;
  614. }
  615. int clif_clearunit_delayed(struct block_list* bl, unsigned int tick)
  616. {
  617. struct block_list *tbl;
  618. tbl = (struct block_list*)aMalloc(sizeof (struct block_list));
  619. memcpy (tbl, bl, sizeof (struct block_list));
  620. add_timer(tick, clif_clearunit_delayed_sub, 0, (intptr)tbl);
  621. return 0;
  622. }
  623. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  624. {
  625. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  626. {
  627. *rhand = *lhand = 0;
  628. return;
  629. }
  630. #if PACKETVER < 4
  631. *rhand = sd->status.weapon;
  632. *lhand = sd->status.shield;
  633. #else
  634. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  635. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  636. {
  637. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  638. if (id->view_id > 0)
  639. *rhand = id->view_id;
  640. else
  641. *rhand = id->nameid;
  642. } else
  643. *rhand = 0;
  644. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  645. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  646. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  647. {
  648. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  649. if (id->view_id > 0)
  650. *lhand = id->view_id;
  651. else
  652. *lhand = id->nameid;
  653. } else
  654. *lhand = 0;
  655. #endif
  656. }
  657. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  658. static int clif_setlevel(int lv)
  659. {
  660. if( lv < battle_config.max_lv )
  661. return lv;
  662. if( lv < battle_config.aura_lv )
  663. return battle_config.max_lv - 1;
  664. return battle_config.max_lv;
  665. }
  666. /*==========================================
  667. * Prepares 'unit standing/spawning' packet
  668. *------------------------------------------*/
  669. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  670. {
  671. struct map_session_data* sd;
  672. struct status_change* sc = status_get_sc(bl);
  673. struct view_data* vd = status_get_viewdata(bl);
  674. unsigned char *buf = WBUFP(buffer,0);
  675. #if PACKETVER < 20091103
  676. bool type = !pcdb_checkid(vd->class_);
  677. #endif
  678. #if PACKETVER >= 7
  679. unsigned short offset = 0;
  680. #endif
  681. #if PACKETVER >= 20091103
  682. const char *name;
  683. #endif
  684. sd = BL_CAST(BL_PC, bl);
  685. #if PACKETVER < 20091103
  686. if(type)
  687. WBUFW(buf,0) = spawn?0x7c:0x78;
  688. else
  689. #endif
  690. #if PACKETVER < 4
  691. WBUFW(buf,0) = spawn?0x79:0x78;
  692. #elif PACKETVER < 7
  693. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  694. #elif PACKETVER < 20080102
  695. WBUFW(buf,0) = spawn?0x22b:0x22a;
  696. #elif PACKETVER < 20091103
  697. WBUFW(buf,0) = spawn?0x2ed:0x2ee;
  698. #else
  699. WBUFW(buf,0) = spawn?0x7f8:0x7f9;
  700. #endif
  701. #if PACKETVER >= 20091103
  702. name = status_get_name(bl);
  703. WBUFW(buf,2) = (spawn?62:63)+strlen(name);
  704. WBUFB(buf,4) = clif_bl_type(bl);
  705. offset+=3;
  706. buf = WBUFP(buffer,offset);
  707. #elif PACKETVER >= 20071106
  708. if (type) { //Non-player packets
  709. WBUFB(buf,2) = clif_bl_type(bl);
  710. offset++;
  711. buf = WBUFP(buffer,offset);
  712. }
  713. #endif
  714. WBUFL(buf, 2) = bl->id;
  715. WBUFW(buf, 6) = status_get_speed(bl);
  716. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  717. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  718. #if PACKETVER < 20091103
  719. if (type&&spawn) { //uses an older and different packet structure
  720. WBUFW(buf,12) = (sc)? sc->option : 0;
  721. WBUFW(buf,14) = vd->hair_style;
  722. WBUFW(buf,16) = vd->weapon;
  723. WBUFW(buf,18) = vd->head_bottom;
  724. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  725. WBUFW(buf,22) = vd->shield;
  726. } else {
  727. #endif
  728. #if PACKETVER >= 20091103
  729. WBUFL(buf,12) = (sc)? sc->option : 0;
  730. offset+=2;
  731. buf = WBUFP(buffer,offset);
  732. #elif PACKETVER >= 7
  733. if (!type) {
  734. WBUFL(buf,12) = (sc)? sc->option : 0;
  735. offset+=2;
  736. buf = WBUFP(buffer,offset);
  737. } else
  738. WBUFW(buf,12) = (sc)? sc->option : 0;
  739. #else
  740. WBUFW(buf,12) = (sc)? sc->option : 0;
  741. #endif
  742. WBUFW(buf,14) = vd->class_;
  743. WBUFW(buf,16) = vd->hair_style;
  744. WBUFW(buf,18) = vd->weapon;
  745. #if PACKETVER < 4
  746. WBUFW(buf,20) = vd->head_bottom;
  747. WBUFW(buf,22) = vd->shield;
  748. #else
  749. WBUFW(buf,20) = vd->shield;
  750. WBUFW(buf,22) = vd->head_bottom;
  751. #endif
  752. #if PACKETVER < 20091103
  753. }
  754. #endif
  755. WBUFW(buf,24) = vd->head_top;
  756. WBUFW(buf,26) = vd->head_mid;
  757. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  758. { //The hell, why flags work like this?
  759. WBUFL(buf,22) = status_get_emblem_id(bl);
  760. WBUFL(buf,26) = status_get_guild_id(bl);
  761. }
  762. WBUFW(buf,28) = vd->hair_color;
  763. WBUFW(buf,30) = vd->cloth_color;
  764. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  765. #if PACKETVER < 20091103
  766. if (type&&spawn) { //End of packet 0x7c
  767. WBUFB(buf,34) = (sd)?sd->status.karma:0; // karma
  768. WBUFB(buf,35) = vd->sex;
  769. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  770. WBUFB(buf,39) = 0;
  771. WBUFB(buf,40) = 0;
  772. return packet_len(0x7c);
  773. }
  774. #endif
  775. WBUFL(buf,34) = status_get_guild_id(bl);
  776. WBUFW(buf,38) = status_get_emblem_id(bl);
  777. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  778. #if PACKETVER >= 20091103
  779. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  780. offset+=2;
  781. buf = WBUFP(buffer,offset);
  782. #elif PACKETVER >= 7
  783. if (!type) {
  784. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  785. offset+=2;
  786. buf = WBUFP(buffer,offset);
  787. } else
  788. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  789. #else
  790. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  791. #endif
  792. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  793. WBUFB(buf,45) = vd->sex;
  794. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  795. WBUFB(buf,49) = (sd)? 5 : 0;
  796. WBUFB(buf,50) = (sd)? 5 : 0;
  797. if (!spawn) {
  798. WBUFB(buf,51) = vd->dead_sit;
  799. offset++;
  800. buf = WBUFP(buffer,offset);
  801. }
  802. WBUFW(buf,51) = clif_setlevel(status_get_lv(bl));
  803. #if PACKETVER < 20091103
  804. if (type) //End for non-player packet
  805. return packet_len(WBUFW(buffer,0));
  806. #endif
  807. #if PACKETVER >= 20080102
  808. WBUFW(buf,53) = sd?sd->state.user_font:0;
  809. #endif
  810. #if PACKETVER >= 20091103
  811. strcpy((char*)WBUFP(buf,55), name);
  812. return WBUFW(buffer,2);
  813. #else
  814. return packet_len(WBUFW(buffer,0));
  815. #endif
  816. }
  817. /*==========================================
  818. * Prepares 'unit walking' packet
  819. *------------------------------------------*/
  820. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  821. {
  822. struct map_session_data* sd;
  823. struct status_change* sc = status_get_sc(bl);
  824. struct view_data* vd = status_get_viewdata(bl);
  825. unsigned char* buf = WBUFP(buffer,0);
  826. #if PACKETVER >= 7
  827. unsigned short offset = 0;
  828. #endif
  829. #if PACKETVER >= 20091103
  830. const char *name;
  831. #endif
  832. sd = BL_CAST(BL_PC, bl);
  833. #if PACKETVER < 4
  834. WBUFW(buf, 0) = 0x7b;
  835. #elif PACKETVER < 7
  836. WBUFW(buf, 0) = 0x1da;
  837. #elif PACKETVER < 20080102
  838. WBUFW(buf, 0) = 0x22c;
  839. #elif PACKETVER < 20091103
  840. WBUFW(buf, 0) = 0x2ec;
  841. #else
  842. WBUFW(buf, 0) = 0x7f7;
  843. #endif
  844. #if PACKETVER >= 20091103
  845. name = status_get_name(bl);
  846. WBUFW(buf, 2) = 69+strlen(name);
  847. offset+=2;
  848. buf = WBUFP(buffer,offset);
  849. #endif
  850. #if PACKETVER >= 20071106
  851. WBUFB(buf, 2) = clif_bl_type(bl);
  852. offset++;
  853. buf = WBUFP(buffer,offset);
  854. #endif
  855. WBUFL(buf, 2) = bl->id;
  856. WBUFW(buf, 6) = status_get_speed(bl);
  857. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  858. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  859. #if PACKETVER < 7
  860. WBUFW(buf,12) = (sc)? sc->option : 0;
  861. #else
  862. WBUFL(buf,12) = (sc)? sc->option : 0;
  863. offset+=2; //Shift the rest of elements by 2 bytes.
  864. buf = WBUFP(buffer,offset);
  865. #endif
  866. WBUFW(buf,14) = vd->class_;
  867. WBUFW(buf,16) = vd->hair_style;
  868. WBUFW(buf,18) = vd->weapon;
  869. #if PACKETVER < 4
  870. WBUFW(buf,20) = vd->head_bottom;
  871. WBUFL(buf,22) = gettick();
  872. WBUFW(buf,26) = vd->shield;
  873. #else
  874. WBUFW(buf,20) = vd->shield;
  875. WBUFW(buf,22) = vd->head_bottom;
  876. WBUFL(buf,24) = gettick();
  877. #endif
  878. WBUFW(buf,28) = vd->head_top;
  879. WBUFW(buf,30) = vd->head_mid;
  880. WBUFW(buf,32) = vd->hair_color;
  881. WBUFW(buf,34) = vd->cloth_color;
  882. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  883. WBUFL(buf,38) = status_get_guild_id(bl);
  884. WBUFW(buf,42) = status_get_emblem_id(bl);
  885. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  886. #if PACKETVER < 7
  887. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  888. #else
  889. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  890. offset+=2; //Shift the rest of elements by 2 bytes.
  891. buf = WBUFP(buffer,offset);
  892. #endif
  893. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  894. WBUFB(buf,49) = vd->sex;
  895. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  896. WBUFB(buf,56) = (sd)? 5 : 0;
  897. WBUFB(buf,57) = (sd)? 5 : 0;
  898. WBUFW(buf,58) = clif_setlevel(status_get_lv(bl));
  899. #if PACKETVER >= 20080102
  900. WBUFW(buf,60) = sd?sd->state.user_font:0;
  901. #endif
  902. #if PACKETVER >= 20091103
  903. strcpy((char*)WBUFP(buf,62), name);
  904. return WBUFW(buffer,2);
  905. #else
  906. return packet_len(WBUFW(buffer,0));
  907. #endif
  908. }
  909. //Modifies the buffer for disguise characters and sends it to self.
  910. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  911. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  912. {
  913. #if PACKETVER >= 20091103
  914. WBUFB(buf,4)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  915. WBUFL(buf,5)=-bl->id;
  916. #elif PACKETVER >= 20071106
  917. WBUFB(buf,2)= pcdb_checkid(status_get_viewdata(bl)->class_) ? 0x0 : 0x5; //PC_TYPE : NPC_MOB_TYPE
  918. WBUFL(buf,3)=-bl->id;
  919. #else
  920. WBUFL(buf,2)=-bl->id;
  921. #endif
  922. clif_send(buf, len, bl, SELF);
  923. }
  924. /*==========================================
  925. * クラスチェンジ typeはMobの場合は1で他は0?
  926. *------------------------------------------*/
  927. int clif_class_change(struct block_list *bl,int class_,int type)
  928. {
  929. unsigned char buf[16];
  930. nullpo_ret(bl);
  931. if(!pcdb_checkid(class_)) {
  932. WBUFW(buf,0)=0x1b0;
  933. WBUFL(buf,2)=bl->id;
  934. WBUFB(buf,6)=type;
  935. WBUFL(buf,7)=class_;
  936. clif_send(buf,packet_len(0x1b0),bl,AREA);
  937. }
  938. return 0;
  939. }
  940. /*==========================================
  941. *
  942. *------------------------------------------*/
  943. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  944. {
  945. WFIFOHEAD(fd, packet_len(0x1e1));
  946. WFIFOW(fd,0)=0x1e1;
  947. WFIFOL(fd,2)=sd->bl.id;
  948. WFIFOW(fd,6)=sd->spiritball;
  949. WFIFOSET(fd, packet_len(0x1e1));
  950. }
  951. /*==========================================
  952. *
  953. *------------------------------------------*/
  954. static void clif_weather_check(struct map_session_data *sd)
  955. {
  956. int m = sd->bl.m, fd = sd->fd;
  957. if (map[m].flag.snow
  958. || map[m].flag.clouds
  959. || map[m].flag.fog
  960. || map[m].flag.fireworks
  961. || map[m].flag.sakura
  962. || map[m].flag.leaves
  963. || map[m].flag.rain
  964. || map[m].flag.clouds2)
  965. {
  966. if (map[m].flag.snow)
  967. clif_specialeffect_single(&sd->bl, 162, fd);
  968. if (map[m].flag.clouds)
  969. clif_specialeffect_single(&sd->bl, 233, fd);
  970. if (map[m].flag.clouds2)
  971. clif_specialeffect_single(&sd->bl, 516, fd);
  972. if (map[m].flag.fog)
  973. clif_specialeffect_single(&sd->bl, 515, fd);
  974. if (map[m].flag.fireworks) {
  975. clif_specialeffect_single(&sd->bl, 297, fd);
  976. clif_specialeffect_single(&sd->bl, 299, fd);
  977. clif_specialeffect_single(&sd->bl, 301, fd);
  978. }
  979. if (map[m].flag.sakura)
  980. clif_specialeffect_single(&sd->bl, 163, fd);
  981. if (map[m].flag.leaves)
  982. clif_specialeffect_single(&sd->bl, 333, fd);
  983. if (map[m].flag.rain)
  984. clif_specialeffect_single(&sd->bl, 161, fd);
  985. }
  986. }
  987. void clif_weather(int m)
  988. {
  989. struct s_mapiterator* iter;
  990. struct map_session_data *sd=NULL;
  991. iter = mapit_getallusers();
  992. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  993. {
  994. if( sd->bl.m == m )
  995. clif_weather_check(sd);
  996. }
  997. mapit_free(iter);
  998. }
  999. int clif_spawn(struct block_list *bl)
  1000. {
  1001. unsigned char buf[128];
  1002. struct view_data *vd;
  1003. int len;
  1004. vd = status_get_viewdata(bl);
  1005. if( !vd || vd->class_ == INVISIBLE_CLASS )
  1006. return 0;
  1007. len = clif_set_unit_idle(bl, buf,true);
  1008. clif_send(buf, len, bl, AREA_WOS);
  1009. if (disguised(bl))
  1010. clif_setdisguise(bl, buf, len);
  1011. if (vd->cloth_color)
  1012. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1013. switch (bl->type)
  1014. {
  1015. case BL_PC:
  1016. {
  1017. TBL_PC *sd = ((TBL_PC*)bl);
  1018. if (sd->spiritball > 0)
  1019. clif_spiritball(sd);
  1020. if(sd->state.size==2) // tiny/big players [Valaris]
  1021. clif_specialeffect(bl,423,AREA);
  1022. else if(sd->state.size==1)
  1023. clif_specialeffect(bl,421,AREA);
  1024. if( sd->state.bg_id && map[sd->bl.m].flag.battleground )
  1025. clif_sendbgemblem_area(sd);
  1026. }
  1027. break;
  1028. case BL_MOB:
  1029. {
  1030. TBL_MOB *md = ((TBL_MOB*)bl);
  1031. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1032. clif_specialeffect(&md->bl,423,AREA);
  1033. else if(md->special_state.size==1)
  1034. clif_specialeffect(&md->bl,421,AREA);
  1035. }
  1036. break;
  1037. case BL_NPC:
  1038. {
  1039. TBL_NPC *nd = ((TBL_NPC*)bl);
  1040. if( nd->size == 2 )
  1041. clif_specialeffect(&nd->bl,423,AREA);
  1042. else if( nd->size == 1 )
  1043. clif_specialeffect(&nd->bl,421,AREA);
  1044. }
  1045. break;
  1046. case BL_PET:
  1047. if (vd->head_bottom)
  1048. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1049. break;
  1050. }
  1051. return 0;
  1052. }
  1053. //[orn]
  1054. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1055. {
  1056. struct status_data *status;
  1057. unsigned char buf[128];
  1058. nullpo_ret(hd);
  1059. status = &hd->battle_status;
  1060. memset(buf,0,packet_len(0x22e));
  1061. WBUFW(buf,0)=0x22e;
  1062. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1063. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1064. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1065. WBUFW(buf,27)=hd->homunculus.level;
  1066. WBUFW(buf,29)=hd->homunculus.hunger;
  1067. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1068. WBUFW(buf,33)=0; // equip id
  1069. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, SHRT_MAX);
  1070. WBUFW(buf,37)=cap_value(status->matk_max, 0, SHRT_MAX);
  1071. WBUFW(buf,39)=status->hit;
  1072. if (battle_config.hom_setting&0x10)
  1073. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1074. else
  1075. WBUFW(buf,41)=status->cri/10;
  1076. WBUFW(buf,43)=status->def + status->vit ;
  1077. WBUFW(buf,45)=status->mdef;
  1078. WBUFW(buf,47)=status->flee;
  1079. WBUFW(buf,49)=(flag)?0:status->amotion;
  1080. if (status->max_hp > SHRT_MAX) {
  1081. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1082. WBUFW(buf,53) = 100;
  1083. } else {
  1084. WBUFW(buf,51)=status->hp;
  1085. WBUFW(buf,53)=status->max_hp;
  1086. }
  1087. if (status->max_sp > SHRT_MAX) {
  1088. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1089. WBUFW(buf,57) = 100;
  1090. } else {
  1091. WBUFW(buf,55)=status->sp;
  1092. WBUFW(buf,57)=status->max_sp;
  1093. }
  1094. WBUFL(buf,59)=hd->homunculus.exp;
  1095. WBUFL(buf,63)=hd->exp_next;
  1096. WBUFW(buf,67)=hd->homunculus.skillpts;
  1097. WBUFW(buf,69)=2; // FIXME: undocumented flag, seems to be '2' all the time [ultramage]
  1098. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1099. return 0;
  1100. }
  1101. void clif_send_homdata(struct map_session_data *sd, int type, int param)
  1102. { //[orn]
  1103. int fd = sd->fd;
  1104. WFIFOHEAD(fd, packet_len(0x230));
  1105. nullpo_retv(sd->hd);
  1106. WFIFOW(fd,0)=0x230;
  1107. WFIFOW(fd,2)=type;
  1108. WFIFOL(fd,4)=sd->hd->bl.id;
  1109. WFIFOL(fd,8)=param;
  1110. WFIFOSET(fd,packet_len(0x230));
  1111. return;
  1112. }
  1113. int clif_homskillinfoblock(struct map_session_data *sd)
  1114. { //[orn]
  1115. struct homun_data *hd;
  1116. int fd = sd->fd;
  1117. int i,j,len=4,id;
  1118. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1119. hd = sd->hd;
  1120. if ( !hd )
  1121. return 0 ;
  1122. WFIFOW(fd,0)=0x235;
  1123. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1124. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1125. j = id - HM_SKILLBASE;
  1126. WFIFOW(fd,len ) = id;
  1127. WFIFOW(fd,len+2) = skill_get_inf(id);
  1128. WFIFOW(fd,len+4) = 0;
  1129. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv;
  1130. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
  1131. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
  1132. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1133. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1134. len+=37;
  1135. }
  1136. }
  1137. WFIFOW(fd,2)=len;
  1138. WFIFOSET(fd,len);
  1139. return 0;
  1140. }
  1141. void clif_homskillup(struct map_session_data *sd, int skill_num)
  1142. { //[orn]
  1143. struct homun_data *hd;
  1144. int fd, skillid;
  1145. nullpo_retv(sd);
  1146. skillid = skill_num - HM_SKILLBASE;
  1147. fd=sd->fd;
  1148. hd=sd->hd;
  1149. WFIFOHEAD(fd, packet_len(0x239));
  1150. WFIFOW(fd,0) = 0x239;
  1151. WFIFOW(fd,2) = skill_num;
  1152. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1153. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1154. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1155. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1156. WFIFOSET(fd,packet_len(0x239));
  1157. return;
  1158. }
  1159. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1160. {
  1161. int fd=sd->fd;
  1162. WFIFOHEAD(fd,packet_len(0x22f));
  1163. WFIFOW(fd,0)=0x22f;
  1164. WFIFOB(fd,2)=fail;
  1165. WFIFOW(fd,3)=foodid;
  1166. WFIFOSET(fd,packet_len(0x22f));
  1167. return 0;
  1168. }
  1169. /*==========================================
  1170. *
  1171. *------------------------------------------*/
  1172. int clif_walkok(struct map_session_data *sd)
  1173. {
  1174. int fd=sd->fd;
  1175. WFIFOHEAD(fd, packet_len(0x87));
  1176. WFIFOW(fd,0)=0x87;
  1177. WFIFOL(fd,2)=gettick();
  1178. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1179. WFIFOSET(fd,packet_len(0x87));
  1180. return 0;
  1181. }
  1182. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1183. {
  1184. uint8 buf[128];
  1185. int len;
  1186. len = clif_set_unit_walking(bl,ud,buf);
  1187. clif_send(buf,len,bl,AREA_WOS);
  1188. if (disguised(bl))
  1189. clif_setdisguise(bl, buf, len);
  1190. if(vd->cloth_color)
  1191. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1192. switch(bl->type)
  1193. {
  1194. case BL_PC:
  1195. {
  1196. TBL_PC *sd = ((TBL_PC*)bl);
  1197. // clif_movepc(sd);
  1198. if(sd->state.size==2) // tiny/big players [Valaris]
  1199. clif_specialeffect(&sd->bl,423,AREA);
  1200. else if(sd->state.size==1)
  1201. clif_specialeffect(&sd->bl,421,AREA);
  1202. }
  1203. break;
  1204. case BL_MOB:
  1205. {
  1206. TBL_MOB *md = ((TBL_MOB*)bl);
  1207. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1208. clif_specialeffect(&md->bl,423,AREA);
  1209. else if(md->special_state.size==1)
  1210. clif_specialeffect(&md->bl,421,AREA);
  1211. }
  1212. break;
  1213. }
  1214. return;
  1215. }
  1216. /// Move the unit (does nothing if the client has no info about the unit)
  1217. /// Note: unit must not be self
  1218. void clif_move(struct unit_data *ud)
  1219. {
  1220. unsigned char buf[16];
  1221. struct view_data* vd;
  1222. struct block_list* bl = ud->bl;
  1223. vd = status_get_viewdata(bl);
  1224. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1225. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1226. if (ud->state.speed_changed) {
  1227. // Since we don't know how to update the speed of other objects,
  1228. // use the old walk packet to update the data.
  1229. ud->state.speed_changed = 0;
  1230. clif_move2(bl, vd, ud);
  1231. return;
  1232. }
  1233. WBUFW(buf,0)=0x86;
  1234. WBUFL(buf,2)=bl->id;
  1235. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1236. WBUFL(buf,12)=gettick();
  1237. clif_send(buf, 16, bl, AREA_WOS);
  1238. if (disguised(bl))
  1239. {
  1240. WBUFL(buf,2)=-bl->id;
  1241. clif_send(buf, 16, bl, SELF);
  1242. }
  1243. }
  1244. /*==========================================
  1245. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1246. *------------------------------------------*/
  1247. static int clif_delayquit(int tid, unsigned int tick, int id, intptr data)
  1248. {
  1249. struct map_session_data *sd = NULL;
  1250. //Remove player from map server
  1251. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1252. map_quit(sd);
  1253. return 0;
  1254. }
  1255. /*==========================================
  1256. *
  1257. *------------------------------------------*/
  1258. void clif_quitsave(int fd,struct map_session_data *sd)
  1259. {
  1260. if (!battle_config.prevent_logout ||
  1261. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1262. map_quit(sd);
  1263. else if (sd->fd)
  1264. { //Disassociate session from player (session is deleted after this function was called)
  1265. //And set a timer to make him quit later.
  1266. session[sd->fd]->session_data = NULL;
  1267. sd->fd = 0;
  1268. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1269. }
  1270. }
  1271. /*==========================================
  1272. *
  1273. *------------------------------------------*/
  1274. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1275. {
  1276. int fd;
  1277. nullpo_retv(sd);
  1278. fd = sd->fd;
  1279. WFIFOHEAD(fd,packet_len(0x91));
  1280. WFIFOW(fd,0) = 0x91;
  1281. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1282. WFIFOW(fd,18) = x;
  1283. WFIFOW(fd,20) = y;
  1284. WFIFOSET(fd,packet_len(0x91));
  1285. }
  1286. /*==========================================
  1287. * Tells the client to connect to another map-server
  1288. *------------------------------------------*/
  1289. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1290. {
  1291. int fd;
  1292. nullpo_retv(sd);
  1293. fd = sd->fd;
  1294. WFIFOHEAD(fd,packet_len(0x92));
  1295. WFIFOW(fd,0) = 0x92;
  1296. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1297. WFIFOW(fd,18) = x;
  1298. WFIFOW(fd,20) = y;
  1299. WFIFOL(fd,22) = htonl(ip);
  1300. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1301. WFIFOSET(fd,packet_len(0x92));
  1302. }
  1303. void clif_blown(struct block_list *bl)
  1304. {
  1305. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1306. // clif_fixpos(bl);
  1307. clif_slide(bl, bl->x, bl->y);
  1308. }
  1309. /// Visually moves(slides) a character to x,y. If the target cell
  1310. /// isn't walkable, the char doesn't move at all. If the char is
  1311. /// sitting it will stand up.
  1312. /// S 0088 <gid>.L <x>.W <y>.W
  1313. void clif_fixpos(struct block_list *bl)
  1314. {
  1315. unsigned char buf[10];
  1316. nullpo_retv(bl);
  1317. WBUFW(buf,0) = 0x88;
  1318. WBUFL(buf,2) = bl->id;
  1319. WBUFW(buf,6) = bl->x;
  1320. WBUFW(buf,8) = bl->y;
  1321. clif_send(buf, packet_len(0x88), bl, AREA);
  1322. if( disguised(bl) )
  1323. {
  1324. WBUFL(buf,2) = -bl->id;
  1325. clif_send(buf, packet_len(0x88), bl, SELF);
  1326. }
  1327. }
  1328. /*==========================================
  1329. *
  1330. *------------------------------------------*/
  1331. int clif_npcbuysell(struct map_session_data* sd, int id)
  1332. {
  1333. int fd;
  1334. nullpo_ret(sd);
  1335. fd=sd->fd;
  1336. WFIFOHEAD(fd, packet_len(0xc4));
  1337. WFIFOW(fd,0)=0xc4;
  1338. WFIFOL(fd,2)=id;
  1339. WFIFOSET(fd,packet_len(0xc4));
  1340. return 0;
  1341. }
  1342. /*==========================================
  1343. *
  1344. *------------------------------------------*/
  1345. int clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1346. {
  1347. int fd,i,c;
  1348. nullpo_ret(sd);
  1349. nullpo_ret(nd);
  1350. fd = sd->fd;
  1351. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1352. WFIFOW(fd,0) = 0xc6;
  1353. c = 0;
  1354. for( i = 0; i < nd->u.shop.count; i++ )
  1355. {
  1356. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1357. int val = nd->u.shop.shop_item[i].value;
  1358. if( id == NULL )
  1359. continue;
  1360. WFIFOL(fd, 4+c*11) = val;
  1361. WFIFOL(fd, 8+c*11) = pc_modifybuyvalue(sd,val);
  1362. WFIFOB(fd,12+c*11) = itemtype(id->type);
  1363. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1364. c++;
  1365. }
  1366. WFIFOW(fd,2) = 4 + c*11;
  1367. WFIFOSET(fd,WFIFOW(fd,2));
  1368. return 0;
  1369. }
  1370. /*==========================================
  1371. *
  1372. *------------------------------------------*/
  1373. int clif_selllist(struct map_session_data *sd)
  1374. {
  1375. int fd,i,c=0,val;
  1376. nullpo_ret(sd);
  1377. fd=sd->fd;
  1378. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1379. WFIFOW(fd,0)=0xc7;
  1380. for( i = 0; i < MAX_INVENTORY; i++ )
  1381. {
  1382. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1383. {
  1384. if( !itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)) )
  1385. continue;
  1386. if( sd->status.inventory[i].expire_time )
  1387. continue; // Cannot Sell Rental Items
  1388. val=sd->inventory_data[i]->value_sell;
  1389. if( val < 0 )
  1390. continue;
  1391. WFIFOW(fd,4+c*10)=i+2;
  1392. WFIFOL(fd,6+c*10)=val;
  1393. WFIFOL(fd,10+c*10)=pc_modifysellvalue(sd,val);
  1394. c++;
  1395. }
  1396. }
  1397. WFIFOW(fd,2)=c*10+4;
  1398. WFIFOSET(fd,WFIFOW(fd,2));
  1399. return 0;
  1400. }
  1401. /// Client behavior (dialog window):
  1402. /// - disable mouse targeting
  1403. /// - open the dialog window
  1404. /// - set npcid of dialog window (0 by default)
  1405. /// - if set to clear on next mes, clear contents
  1406. /// - append this text
  1407. int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1408. {
  1409. int fd = sd->fd;
  1410. int slen = strlen(mes) + 9;
  1411. WFIFOHEAD(fd, slen);
  1412. WFIFOW(fd,0)=0xb4;
  1413. WFIFOW(fd,2)=slen;
  1414. WFIFOL(fd,4)=npcid;
  1415. strcpy((char*)WFIFOP(fd,8),mes);
  1416. WFIFOSET(fd,WFIFOW(fd,2));
  1417. return 0;
  1418. }
  1419. /// Client behavior (dialog window):
  1420. /// - disable mouse targeting
  1421. /// - open the dialog window
  1422. /// - add 'next' button
  1423. /// When 'next' is pressed:
  1424. /// - S 00B9 <npcid of dialog window>.L
  1425. /// - set to clear on next mes
  1426. /// - remove 'next' button
  1427. int clif_scriptnext(struct map_session_data *sd,int npcid)
  1428. {
  1429. int fd;
  1430. nullpo_ret(sd);
  1431. fd=sd->fd;
  1432. WFIFOHEAD(fd, packet_len(0xb5));
  1433. WFIFOW(fd,0)=0xb5;
  1434. WFIFOL(fd,2)=npcid;
  1435. WFIFOSET(fd,packet_len(0xb5));
  1436. return 0;
  1437. }
  1438. /// Client behavior:
  1439. /// - if dialog window is open:
  1440. /// - remove 'next' button
  1441. /// - add 'close' button
  1442. /// - else:
  1443. /// - enable mouse targeting
  1444. /// - close the dialog window
  1445. /// - close the menu window
  1446. /// When 'close' is pressed:
  1447. /// - enable mouse targeting
  1448. /// - close the dialog window
  1449. /// - close the menu window
  1450. /// - S 0146 <npcid of dialog window>.L
  1451. int clif_scriptclose(struct map_session_data *sd, int npcid)
  1452. {
  1453. int fd;
  1454. nullpo_ret(sd);
  1455. fd=sd->fd;
  1456. WFIFOHEAD(fd, packet_len(0xb6));
  1457. WFIFOW(fd,0)=0xb6;
  1458. WFIFOL(fd,2)=npcid;
  1459. WFIFOSET(fd,packet_len(0xb6));
  1460. return 0;
  1461. }
  1462. /*==========================================
  1463. *
  1464. *------------------------------------------*/
  1465. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1466. {
  1467. unsigned char *buf;
  1468. int fd = sd->fd;
  1469. sd->state.using_fake_npc = 1;
  1470. WFIFOHEAD(fd, packet_len(0x78));
  1471. buf = WFIFOP(fd,0);
  1472. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1473. WBUFW(buf,0)=0x78;
  1474. #if PACKETVER >= 20071106
  1475. WBUFB(buf,2) = 0; //Unknown bit
  1476. buf = WFIFOP(fd,1);
  1477. #endif
  1478. WBUFL(buf,2)=npcid;
  1479. WBUFW(buf,14)=111;
  1480. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1481. WBUFB(buf,49)=5;
  1482. WBUFB(buf,50)=5;
  1483. WFIFOSET(fd, packet_len(0x78));
  1484. return;
  1485. }
  1486. /// Client behavior:
  1487. /// - disable mouse targeting
  1488. /// - close the menu window
  1489. /// - open the menu window
  1490. /// - add options to the menu (separated in the text by ":")
  1491. /// - set npcid of menu window
  1492. /// - if dialog window is open:
  1493. /// - remove 'next' button
  1494. /// When 'ok' is pressed:
  1495. /// - S 00B8 <npcid of menu window>.L <selected option>.B
  1496. /// - close the menu window
  1497. /// When 'cancel' is pressed:
  1498. /// - S 00B8 <npcid of menu window>.L <-1>.B
  1499. /// - enable mouse targeting
  1500. /// - close a bunch of windows...
  1501. /// WARNING: the 'cancel' button closes other windows besides the dialog window and the menu window.
  1502. /// Which suggests their have intertwined behavior. (probably the mouse targeting)
  1503. /// TODO investigate behavior of other windows [FlavioJS]
  1504. int clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1505. {
  1506. int fd = sd->fd;
  1507. int slen = strlen(mes) + 8;
  1508. struct block_list *bl = NULL;
  1509. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1510. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1511. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1512. clif_sendfakenpc(sd, npcid);
  1513. WFIFOHEAD(fd, slen);
  1514. WFIFOW(fd,0)=0xb7;
  1515. WFIFOW(fd,2)=slen;
  1516. WFIFOL(fd,4)=npcid;
  1517. strcpy((char*)WFIFOP(fd,8),mes);
  1518. WFIFOSET(fd,WFIFOW(fd,2));
  1519. return 0;
  1520. }
  1521. /// Client behavior (inputnum window):
  1522. /// - if npcid exists in the client:
  1523. /// - open the inputnum window
  1524. /// - set npcid of inputnum window
  1525. /// When 'ok' is pressed:
  1526. /// - if inputnum window has text:
  1527. /// - if npcid exists in the client:
  1528. /// - S 0143 <npcid of inputnum window>.L <atoi(text)>.L
  1529. /// - close inputnum window
  1530. int clif_scriptinput(struct map_session_data *sd, int npcid)
  1531. {
  1532. int fd;
  1533. struct block_list *bl = NULL;
  1534. nullpo_ret(sd);
  1535. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1536. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1537. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1538. clif_sendfakenpc(sd, npcid);
  1539. fd=sd->fd;
  1540. WFIFOHEAD(fd, packet_len(0x142));
  1541. WFIFOW(fd,0)=0x142;
  1542. WFIFOL(fd,2)=npcid;
  1543. WFIFOSET(fd,packet_len(0x142));
  1544. return 0;
  1545. }
  1546. /// Client behavior (inputstr window):
  1547. /// - if npcid is 0 or npcid exists in the client:
  1548. /// - open the inputstr window
  1549. /// - set npcid of inputstr window
  1550. /// When 'ok' is pressed:
  1551. /// - if inputstr window has text and isn't an insult(manner.txt):
  1552. /// - if npcid is 0 or npcid exists in the client:
  1553. /// - S 01d5 <packetlen>.W <npcid of inputstr window>.L <text>.?B
  1554. /// - close inputstr window
  1555. int clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1556. {
  1557. int fd;
  1558. struct block_list *bl = NULL;
  1559. nullpo_ret(sd);
  1560. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1561. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1562. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1563. clif_sendfakenpc(sd, npcid);
  1564. fd=sd->fd;
  1565. WFIFOHEAD(fd, packet_len(0x1d4));
  1566. WFIFOW(fd,0)=0x1d4;
  1567. WFIFOL(fd,2)=npcid;
  1568. WFIFOSET(fd,packet_len(0x1d4));
  1569. return 0;
  1570. }
  1571. /// npc_id is ignored in the client
  1572. /// type=2 : Remove viewpoint
  1573. /// type=other : Show viewpoint
  1574. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1575. {
  1576. int fd;
  1577. nullpo_ret(sd);
  1578. fd=sd->fd;
  1579. WFIFOHEAD(fd, packet_len(0x144));
  1580. WFIFOW(fd,0)=0x144;
  1581. WFIFOL(fd,2)=npc_id;
  1582. WFIFOL(fd,6)=type;
  1583. WFIFOL(fd,10)=x;
  1584. WFIFOL(fd,14)=y;
  1585. WFIFOB(fd,18)=id;
  1586. WFIFOL(fd,19)=color;
  1587. WFIFOSET(fd,packet_len(0x144));
  1588. return 0;
  1589. }
  1590. /*==========================================
  1591. *
  1592. *------------------------------------------*/
  1593. int clif_cutin(struct map_session_data* sd, const char* image, int type)
  1594. {
  1595. int fd;
  1596. nullpo_ret(sd);
  1597. fd=sd->fd;
  1598. WFIFOHEAD(fd, packet_len(0x1b3));
  1599. WFIFOW(fd,0)=0x1b3;
  1600. strncpy((char*)WFIFOP(fd,2),image,64);
  1601. WFIFOB(fd,66)=type;
  1602. WFIFOSET(fd,packet_len(0x1b3));
  1603. return 0;
  1604. }
  1605. /*==========================================
  1606. * Fills in card data from the given item and into the buffer. [Skotlex]
  1607. *------------------------------------------*/
  1608. static void clif_addcards(unsigned char* buf, struct item* item)
  1609. {
  1610. int i=0,j;
  1611. if( item == NULL ) { //Blank data
  1612. WBUFW(buf,0) = 0;
  1613. WBUFW(buf,2) = 0;
  1614. WBUFW(buf,4) = 0;
  1615. WBUFW(buf,6) = 0;
  1616. return;
  1617. }
  1618. if( item->card[0] == CARD0_PET ) { //pet eggs
  1619. WBUFW(buf,0) = 0;
  1620. WBUFW(buf,2) = 0;
  1621. WBUFW(buf,4) = 0;
  1622. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1623. return;
  1624. }
  1625. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1626. WBUFW(buf,0) = item->card[0];
  1627. WBUFW(buf,2) = item->card[1];
  1628. WBUFW(buf,4) = item->card[2];
  1629. WBUFW(buf,6) = item->card[3];
  1630. return;
  1631. }
  1632. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1633. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1634. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1635. //Normal items.
  1636. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1637. WBUFW(buf,0) = j;
  1638. else
  1639. WBUFW(buf,0) = item->card[i];
  1640. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1641. WBUFW(buf,2) = j;
  1642. else
  1643. WBUFW(buf,2) = item->card[i];
  1644. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1645. WBUFW(buf,4) = j;
  1646. else
  1647. WBUFW(buf,4) = item->card[i];
  1648. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1649. WBUFW(buf,6) = j;
  1650. else
  1651. WBUFW(buf,6) = item->card[i];
  1652. }
  1653. /*==========================================
  1654. *
  1655. *------------------------------------------*/
  1656. int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1657. {
  1658. int fd;
  1659. #if PACKETVER < 20071002
  1660. const int cmd = 0xa0;
  1661. #else
  1662. const int cmd = 0x2d4;
  1663. #endif
  1664. nullpo_ret(sd);
  1665. fd = sd->fd;
  1666. if( !session_isActive(fd) ) //Sasuke-
  1667. return 0;
  1668. WFIFOHEAD(fd,packet_len(cmd));
  1669. if( fail )
  1670. {
  1671. WFIFOW(fd,0)=cmd;
  1672. WFIFOW(fd,2)=n+2;
  1673. WFIFOW(fd,4)=amount;
  1674. WFIFOW(fd,6)=0;
  1675. WFIFOB(fd,8)=0;
  1676. WFIFOB(fd,9)=0;
  1677. WFIFOB(fd,10)=0;
  1678. WFIFOW(fd,11)=0;
  1679. WFIFOW(fd,13)=0;
  1680. WFIFOW(fd,15)=0;
  1681. WFIFOW(fd,17)=0;
  1682. WFIFOW(fd,19)=0;
  1683. WFIFOB(fd,21)=0;
  1684. WFIFOB(fd,22)=fail;
  1685. #if PACKETVER >= 20071002
  1686. WFIFOW(fd,23)=0;
  1687. WFIFOW(fd,25)=0;
  1688. WFIFOW(fd,27)=0;
  1689. #endif
  1690. }
  1691. else
  1692. {
  1693. if( n < 0 || n >= MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL )
  1694. return 1;
  1695. WFIFOW(fd,0)=cmd;
  1696. WFIFOW(fd,2)=n+2;
  1697. WFIFOW(fd,4)=amount;
  1698. if (sd->inventory_data[n]->view_id > 0)
  1699. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1700. else
  1701. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1702. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1703. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1704. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1705. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1706. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1707. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1708. WFIFOB(fd,22)=fail;
  1709. #if PACKETVER >= 20071002
  1710. WFIFOL(fd,23)=sd->status.inventory[n].expire_time;
  1711. WFIFOW(fd,27)=0;
  1712. #endif
  1713. }
  1714. WFIFOSET(fd,packet_len(cmd));
  1715. return 0;
  1716. }
  1717. /*==========================================
  1718. *
  1719. *------------------------------------------*/
  1720. int clif_dropitem(struct map_session_data *sd,int n,int amount)
  1721. {
  1722. int fd;
  1723. nullpo_ret(sd);
  1724. fd=sd->fd;
  1725. WFIFOHEAD(fd, packet_len(0xaf));
  1726. WFIFOW(fd,0)=0xaf;
  1727. WFIFOW(fd,2)=n+2;
  1728. WFIFOW(fd,4)=amount;
  1729. WFIFOSET(fd,packet_len(0xaf));
  1730. return 0;
  1731. }
  1732. /*==========================================
  1733. * Deletes an item from your inventory.
  1734. * Reason values:
  1735. * 0 - Normal
  1736. * 1 - Item used for a skill
  1737. * 2 - Refine failed
  1738. * 3 - Material changed
  1739. * 4 - Moved to storage
  1740. * 5 - Moved to cart
  1741. * 6 - Item sold
  1742. * 7 - Item dropped
  1743. *------------------------------------------*/
  1744. int clif_delitem(struct map_session_data *sd,int n,int amount, short reason)
  1745. {
  1746. #if PACKETVER < 20091117
  1747. return clif_dropitem(sd,n,amount);
  1748. #else
  1749. int fd;
  1750. nullpo_ret(sd);
  1751. if (reason == 7)
  1752. return clif_dropitem(sd,n,amount);
  1753. fd=sd->fd;
  1754. WFIFOHEAD(fd, packet_len(0x7fa));
  1755. WFIFOW(fd,0)=0x7fa;
  1756. WFIFOW(fd,2)=reason;
  1757. WFIFOW(fd,4)=n+2;
  1758. WFIFOW(fd,6)=amount;
  1759. WFIFOSET(fd,packet_len(0x7fa));
  1760. return 0;
  1761. #endif
  1762. }
  1763. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1764. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1765. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1766. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1767. {
  1768. if (id->view_id > 0)
  1769. WBUFW(buf,n)=id->view_id;
  1770. else
  1771. WBUFW(buf,n)=i->nameid;
  1772. WBUFB(buf,n+2)=itemtype(id->type);
  1773. WBUFB(buf,n+3)=i->identify;
  1774. if (equip >= 0) { //Equippable item
  1775. WBUFW(buf,n+4)=equip;
  1776. WBUFW(buf,n+6)=i->equip;
  1777. WBUFB(buf,n+8)=i->attribute;
  1778. WBUFB(buf,n+9)=i->refine;
  1779. } else { //Stackable item.
  1780. WBUFW(buf,n+4)=i->amount;
  1781. if (equip == -2 && id->equip == EQP_AMMO)
  1782. WBUFW(buf,n+6)=EQP_AMMO;
  1783. else
  1784. WBUFW(buf,n+6)=0;
  1785. }
  1786. }
  1787. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1788. void clif_inventorylist(struct map_session_data *sd)
  1789. {
  1790. int i,n,ne,arrow=-1;
  1791. unsigned char *buf;
  1792. unsigned char *bufe;
  1793. #if PACKETVER < 5
  1794. const int s = 10; //Entry size.
  1795. #elif PACKETVER < 20080102
  1796. const int s = 18;
  1797. #else
  1798. const int s = 22;
  1799. #endif
  1800. #if PACKETVER < 20071002
  1801. const int se = 20;
  1802. #elif PACKETVER < 20100629
  1803. const int se = 26;
  1804. #else
  1805. const int se = 28;
  1806. #endif
  1807. buf = (unsigned char*)aMallocA(MAX_INVENTORY * s + 4);
  1808. bufe = (unsigned char*)aMallocA(MAX_INVENTORY * se + 4);
  1809. for( i = 0, n = 0, ne = 0; i < MAX_INVENTORY; i++ )
  1810. {
  1811. if( sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL )
  1812. continue;
  1813. if( !itemdb_isstackable2(sd->inventory_data[i]) )
  1814. { //Non-stackable (Equippable)
  1815. WBUFW(bufe,ne*se+4)=i+2;
  1816. clif_item_sub(bufe, ne*se+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1817. clif_addcards(WBUFP(bufe, ne*se+16), &sd->status.inventory[i]);
  1818. #if PACKETVER >= 20071002
  1819. WBUFL(bufe,ne*se+24)=sd->status.inventory[i].expire_time;
  1820. WBUFW(bufe,ne*se+28)=0; //Unknown
  1821. #endif
  1822. #if PACKETVER >= 20100629
  1823. if (sd->inventory_data[i]->equip&EQP_HELM)
  1824. WBUFW(bufe,ne*se+30)= sd->inventory_data[i]->look;
  1825. else
  1826. WBUFW(bufe,ne*se+30)=0;
  1827. #endif
  1828. ne++;
  1829. }
  1830. else
  1831. { //Stackable.
  1832. WBUFW(buf,n*s+4)=i+2;
  1833. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1834. if( sd->inventory_data[i]->equip == EQP_AMMO && sd->status.inventory[i].equip )
  1835. arrow=i;
  1836. #if PACKETVER >= 5
  1837. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1838. #endif
  1839. #if PACKETVER >= 20080102
  1840. WBUFL(buf,n*s+22)=sd->status.inventory[i].expire_time;
  1841. #endif
  1842. n++;
  1843. }
  1844. }
  1845. if( n )
  1846. {
  1847. #if PACKETVER < 5
  1848. WBUFW(buf,0)=0xa3;
  1849. #elif PACKETVER < 20080102
  1850. WBUFW(buf,0)=0x1ee;
  1851. #else
  1852. WBUFW(buf,0)=0x2e8;
  1853. #endif
  1854. WBUFW(buf,2)=4+n*s;
  1855. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  1856. }
  1857. if( arrow >= 0 )
  1858. clif_arrowequip(sd,arrow);
  1859. if( ne )
  1860. {
  1861. #if PACKETVER < 20071002
  1862. WBUFW(bufe,0)=0xa4;
  1863. #else
  1864. WBUFW(bufe,0)=0x2d0;
  1865. #endif
  1866. WBUFW(bufe,2)=4+ne*se;
  1867. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1868. }
  1869. if( buf ) aFree(buf);
  1870. if( bufe ) aFree(bufe);
  1871. }
  1872. //Required when items break/get-repaired. Only sends equippable item list.
  1873. void clif_equiplist(struct map_session_data *sd)
  1874. {
  1875. int i,n,fd = sd->fd;
  1876. unsigned char *buf;
  1877. #if PACKETVER < 20071002
  1878. const int cmd = 20;
  1879. #elif PACKETVER < 20100629
  1880. const int cmd = 26;
  1881. #else
  1882. const int cmd = 28;
  1883. #endif
  1884. WFIFOHEAD(fd, MAX_INVENTORY * cmd + 4);
  1885. buf = WFIFOP(fd,0);
  1886. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1887. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1888. continue;
  1889. if(itemdb_isstackable2(sd->inventory_data[i]))
  1890. continue;
  1891. //Equippable
  1892. WBUFW(buf,n*cmd+4)=i+2;
  1893. clif_item_sub(buf, n*cmd+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1894. clif_addcards(WBUFP(buf, n*cmd+16), &sd->status.inventory[i]);
  1895. #if PACKETVER >= 20071002
  1896. WBUFL(buf,n*cmd+24)=sd->status.inventory[i].expire_time;
  1897. WBUFW(buf,n*cmd+28)=0; //Unknown
  1898. #endif
  1899. #if PACKETVER >= 20100629
  1900. if (sd->inventory_data[i]->equip&EQP_HELM)
  1901. WBUFW(buf,n*cmd+30)= sd->inventory_data[i]->look;
  1902. else
  1903. WBUFW(buf,n*cmd+30)=0;
  1904. #endif
  1905. n++;
  1906. }
  1907. if (n) {
  1908. #if PACKETVER < 20071002
  1909. WBUFW(buf,0)=0xa4;
  1910. #else
  1911. WBUFW(buf,0)=0x2d0;
  1912. #endif
  1913. WBUFW(buf,2)=4+n*cmd;
  1914. WFIFOSET(fd,WFIFOW(fd,2));
  1915. }
  1916. }
  1917. void clif_storagelist(struct map_session_data* sd, struct item* items, int items_length)
  1918. {
  1919. struct item_data *id;
  1920. int i,n,ne;
  1921. unsigned char *buf;
  1922. unsigned char *bufe;
  1923. #if PACKETVER < 5
  1924. const int s = 10; //Entry size.
  1925. #elif PACKETVER < 20080102
  1926. const int s = 18;
  1927. #else
  1928. const int s = 22;
  1929. #endif
  1930. #if PACKETVER < 20071002
  1931. const int cmd = 20;
  1932. #elif PACKETVER < 20100629
  1933. const int cmd = 26;
  1934. #else
  1935. const int cmd = 28;
  1936. #endif
  1937. buf = (unsigned char*)aMallocA(items_length * s + 4);
  1938. bufe = (unsigned char*)aMallocA(items_length * cmd + 4);
  1939. for( i = 0, n = 0, ne = 0; i < items_length; i++ )
  1940. {
  1941. if( items[i].nameid <= 0 )
  1942. continue;
  1943. id = itemdb_search(items[i].nameid);
  1944. if( !itemdb_isstackable2(id) )
  1945. { //Equippable
  1946. WBUFW(bufe,ne*cmd+4)=i+1;
  1947. clif_item_sub(bufe, ne*cmd+6, &items[i], id, id->equip);
  1948. clif_addcards(WBUFP(bufe, ne*cmd+16), &items[i]);
  1949. #if PACKETVER >= 20071002
  1950. WBUFL(bufe,ne*cmd+24)=items[i].expire_time;
  1951. WBUFW(bufe,ne*cmd+28)=0; //Unknown
  1952. #endif
  1953. ne++;
  1954. }
  1955. else
  1956. { //Stackable
  1957. WBUFW(buf,n*s+4)=i+1;
  1958. clif_item_sub(buf, n*s+6, &items[i], id,-1);
  1959. #if PACKETVER >= 5
  1960. clif_addcards(WBUFP(buf,n*s+14), &items[i]);
  1961. #endif
  1962. #if PACKETVER >= 20080102
  1963. WBUFL(buf,n*s+22)=items[i].expire_time;
  1964. #endif
  1965. n++;
  1966. }
  1967. }
  1968. if( n )
  1969. {
  1970. #if PACKETVER < 5
  1971. WBUFW(buf,0)=0xa5;
  1972. #elif PACKETVER < 20080102
  1973. WBUFW(buf,0)=0x1f0;
  1974. #else
  1975. WBUFW(buf,0)=0x2ea;
  1976. #endif
  1977. WBUFW(buf,2)=4+n*s;
  1978. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  1979. }
  1980. if( ne )
  1981. {
  1982. #if PACKETVER < 20071002
  1983. WBUFW(bufe,0)=0xa6;
  1984. #else
  1985. WBUFW(bufe,0)=0x2d1;
  1986. #endif
  1987. WBUFW(bufe,2)=4+ne*cmd;
  1988. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1989. }
  1990. if( buf ) aFree(buf);
  1991. if( bufe ) aFree(bufe);
  1992. }
  1993. void clif_cartlist(struct map_session_data *sd)
  1994. {
  1995. struct item_data *id;
  1996. int i,n,ne;
  1997. unsigned char *buf;
  1998. unsigned char *bufe;
  1999. #if PACKETVER < 5
  2000. const int s = 10; //Entry size.
  2001. #elif PACKETVER < 20080102
  2002. const int s = 18;
  2003. #else
  2004. const int s = 22;
  2005. #endif
  2006. #if PACKETVER < 20071002
  2007. const int cmd = 20;
  2008. #elif PACKETVER < 20100629
  2009. const int cmd = 26;
  2010. #else
  2011. const int cmd = 28;
  2012. #endif
  2013. buf = (unsigned char*)aMallocA(MAX_CART * s + 4);
  2014. bufe = (unsigned char*)aMallocA(MAX_CART * cmd + 4);
  2015. for( i = 0, n = 0, ne = 0; i < MAX_CART; i++ )
  2016. {
  2017. if( sd->status.cart[i].nameid <= 0 )
  2018. continue;
  2019. id = itemdb_search(sd->status.cart[i].nameid);
  2020. if( !itemdb_isstackable2(id) )
  2021. { //Equippable
  2022. WBUFW(bufe,ne*cmd+4)=i+2;
  2023. clif_item_sub(bufe, ne*cmd+6, &sd->status.cart[i], id, id->equip);
  2024. clif_addcards(WBUFP(bufe, ne*cmd+16), &sd->status.cart[i]);
  2025. #if PACKETVER >= 20071002
  2026. WBUFL(bufe,ne*cmd+24)=sd->status.cart[i].expire_time;
  2027. WBUFW(bufe,ne*cmd+28)=0; //Unknown
  2028. #endif
  2029. ne++;
  2030. }
  2031. else
  2032. { //Stackable
  2033. WBUFW(buf,n*s+4)=i+2;
  2034. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  2035. #if PACKETVER >= 5
  2036. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  2037. #endif
  2038. #if PACKETVER >= 20080102
  2039. WBUFL(buf,n*s+22)=sd->status.cart[i].expire_time;
  2040. #endif
  2041. n++;
  2042. }
  2043. }
  2044. if( n )
  2045. {
  2046. #if PACKETVER < 5
  2047. WBUFW(buf,0)=0x123;
  2048. #elif PACKETVER < 20080102
  2049. WBUFW(buf,0)=0x1ef;
  2050. #else
  2051. WBUFW(buf,0)=0x2e9;
  2052. #endif
  2053. WBUFW(buf,2)=4+n*s;
  2054. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  2055. }
  2056. if( ne )
  2057. {
  2058. #if PACKETVER < 20071002
  2059. WBUFW(bufe,0)=0x122;
  2060. #else
  2061. WBUFW(bufe,0)=0x2d2;
  2062. #endif
  2063. WBUFW(bufe,2)=4+ne*cmd;
  2064. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2065. }
  2066. if( buf ) aFree(buf);
  2067. if( bufe ) aFree(bufe);
  2068. }
  2069. /// Client behaviour:
  2070. /// Closes the cart storage and removes all it's items from memory.
  2071. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2072. void clif_clearcart(int fd)
  2073. {
  2074. WFIFOHEAD(fd, packet_len(0x12b));
  2075. WFIFOW(fd,0) = 0x12b;
  2076. WFIFOSET(fd, packet_len(0x12b));
  2077. }
  2078. // Guild XY locators [Valaris]
  2079. int clif_guild_xy(struct map_session_data *sd)
  2080. {
  2081. unsigned char buf[10];
  2082. nullpo_ret(sd);
  2083. WBUFW(buf,0)=0x1eb;
  2084. WBUFL(buf,2)=sd->status.account_id;
  2085. WBUFW(buf,6)=sd->bl.x;
  2086. WBUFW(buf,8)=sd->bl.y;
  2087. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2088. return 0;
  2089. }
  2090. /*==========================================
  2091. * Sends x/y dot to a single fd. [Skotlex]
  2092. *------------------------------------------*/
  2093. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  2094. {
  2095. if( sd->state.bg_id )
  2096. return 0;
  2097. WFIFOHEAD(fd,packet_len(0x1eb));
  2098. WFIFOW(fd,0)=0x1eb;
  2099. WFIFOL(fd,2)=sd->status.account_id;
  2100. WFIFOW(fd,6)=sd->bl.x;
  2101. WFIFOW(fd,8)=sd->bl.y;
  2102. WFIFOSET(fd,packet_len(0x1eb));
  2103. return 0;
  2104. }
  2105. // Guild XY locators [Valaris]
  2106. int clif_guild_xy_remove(struct map_session_data *sd)
  2107. {
  2108. unsigned char buf[10];
  2109. nullpo_ret(sd);
  2110. WBUFW(buf,0)=0x1eb;
  2111. WBUFL(buf,2)=sd->status.account_id;
  2112. WBUFW(buf,6)=-1;
  2113. WBUFW(buf,8)=-1;
  2114. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2115. return 0;
  2116. }
  2117. /*==========================================
  2118. * ステータスを送りつける
  2119. * 表示専用数字はこの中で計算して送る
  2120. *------------------------------------------*/
  2121. int clif_updatestatus(struct map_session_data *sd,int type)
  2122. {
  2123. int fd,len=8;
  2124. nullpo_ret(sd);
  2125. fd=sd->fd;
  2126. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2127. return 0;
  2128. WFIFOHEAD(fd, 14);
  2129. WFIFOW(fd,0)=0xb0;
  2130. WFIFOW(fd,2)=type;
  2131. switch(type){
  2132. // 00b0
  2133. case SP_WEIGHT:
  2134. pc_updateweightstatus(sd);
  2135. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2136. WFIFOW(fd,2)=type;
  2137. WFIFOL(fd,4)=sd->weight;
  2138. break;
  2139. case SP_MAXWEIGHT:
  2140. WFIFOL(fd,4)=sd->max_weight;
  2141. break;
  2142. case SP_SPEED:
  2143. WFIFOL(fd,4)=sd->battle_status.speed;
  2144. break;
  2145. case SP_BASELEVEL:
  2146. WFIFOL(fd,4)=sd->status.base_level;
  2147. break;
  2148. case SP_JOBLEVEL:
  2149. WFIFOL(fd,4)=sd->status.job_level;
  2150. break;
  2151. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2152. WFIFOL(fd,4)=sd->status.karma;
  2153. break;
  2154. case SP_MANNER:
  2155. WFIFOL(fd,4)=sd->status.manner;
  2156. break;
  2157. case SP_STATUSPOINT:
  2158. WFIFOL(fd,4)=sd->status.status_point;
  2159. break;
  2160. case SP_SKILLPOINT:
  2161. WFIFOL(fd,4)=sd->status.skill_point;
  2162. break;
  2163. case SP_HIT:
  2164. WFIFOL(fd,4)=sd->battle_status.hit;
  2165. break;
  2166. case SP_FLEE1:
  2167. WFIFOL(fd,4)=sd->battle_status.flee;
  2168. break;
  2169. case SP_FLEE2:
  2170. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2171. break;
  2172. case SP_MAXHP:
  2173. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2174. break;
  2175. case SP_MAXSP:
  2176. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2177. break;
  2178. case SP_HP:
  2179. WFIFOL(fd,4)=sd->battle_status.hp;
  2180. if( battle_config.disp_hpmeter )
  2181. clif_hpmeter(sd);
  2182. if( !battle_config.party_hp_mode && sd->status.party_id )
  2183. clif_party_hp(sd);
  2184. if( sd->state.bg_id )
  2185. clif_bg_hp(sd);
  2186. break;
  2187. case SP_SP:
  2188. WFIFOL(fd,4)=sd->battle_status.sp;
  2189. break;
  2190. case SP_ASPD:
  2191. WFIFOL(fd,4)=sd->battle_status.amotion;
  2192. break;
  2193. case SP_ATK1:
  2194. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw.atk;
  2195. break;
  2196. case SP_DEF1:
  2197. WFIFOL(fd,4)=sd->battle_status.def;
  2198. break;
  2199. case SP_MDEF1:
  2200. WFIFOL(fd,4)=sd->battle_status.mdef;
  2201. break;
  2202. case SP_ATK2:
  2203. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2;
  2204. break;
  2205. case SP_DEF2:
  2206. WFIFOL(fd,4)=sd->battle_status.def2;
  2207. break;
  2208. case SP_MDEF2:
  2209. //negative check (in case you have something like Berserk active)
  2210. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2211. if (len < 0) len = 0;
  2212. WFIFOL(fd,4)= len;
  2213. len = 8;
  2214. break;
  2215. case SP_CRITICAL:
  2216. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2217. break;
  2218. case SP_MATK1:
  2219. WFIFOL(fd,4)=sd->battle_status.matk_max;
  2220. break;
  2221. case SP_MATK2:
  2222. WFIFOL(fd,4)=sd->battle_status.matk_min;
  2223. break;
  2224. case SP_ZENY:
  2225. WFIFOW(fd,0)=0xb1;
  2226. WFIFOL(fd,4)=sd->status.zeny;
  2227. break;
  2228. case SP_BASEEXP:
  2229. WFIFOW(fd,0)=0xb1;
  2230. WFIFOL(fd,4)=sd->status.base_exp;
  2231. break;
  2232. case SP_JOBEXP:
  2233. WFIFOW(fd,0)=0xb1;
  2234. WFIFOL(fd,4)=sd->status.job_exp;
  2235. break;
  2236. case SP_NEXTBASEEXP:
  2237. WFIFOW(fd,0)=0xb1;
  2238. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2239. break;
  2240. case SP_NEXTJOBEXP:
  2241. WFIFOW(fd,0)=0xb1;
  2242. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2243. break;
  2244. // 00be 終了
  2245. case SP_USTR:
  2246. case SP_UAGI:
  2247. case SP_UVIT:
  2248. case SP_UINT:
  2249. case SP_UDEX:
  2250. case SP_ULUK:
  2251. WFIFOW(fd,0)=0xbe;
  2252. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2253. len=5;
  2254. break;
  2255. // 013a 終了
  2256. case SP_ATTACKRANGE:
  2257. WFIFOW(fd,0)=0x13a;
  2258. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2259. len=4;
  2260. break;
  2261. // 0141 終了
  2262. case SP_STR:
  2263. WFIFOW(fd,0)=0x141;
  2264. WFIFOL(fd,2)=type;
  2265. WFIFOL(fd,6)=sd->status.str;
  2266. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2267. len=14;
  2268. break;
  2269. case SP_AGI:
  2270. WFIFOW(fd,0)=0x141;
  2271. WFIFOL(fd,2)=type;
  2272. WFIFOL(fd,6)=sd->status.agi;
  2273. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2274. len=14;
  2275. break;
  2276. case SP_VIT:
  2277. WFIFOW(fd,0)=0x141;
  2278. WFIFOL(fd,2)=type;
  2279. WFIFOL(fd,6)=sd->status.vit;
  2280. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2281. len=14;
  2282. break;
  2283. case SP_INT:
  2284. WFIFOW(fd,0)=0x141;
  2285. WFIFOL(fd,2)=type;
  2286. WFIFOL(fd,6)=sd->status.int_;
  2287. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2288. len=14;
  2289. break;
  2290. case SP_DEX:
  2291. WFIFOW(fd,0)=0x141;
  2292. WFIFOL(fd,2)=type;
  2293. WFIFOL(fd,6)=sd->status.dex;
  2294. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2295. len=14;
  2296. break;
  2297. case SP_LUK:
  2298. WFIFOW(fd,0)=0x141;
  2299. WFIFOL(fd,2)=type;
  2300. WFIFOL(fd,6)=sd->status.luk;
  2301. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2302. len=14;
  2303. break;
  2304. case SP_CARTINFO:
  2305. WFIFOW(fd,0)=0x121;
  2306. WFIFOW(fd,2)=sd->cart_num;
  2307. WFIFOW(fd,4)=MAX_CART;
  2308. WFIFOL(fd,6)=sd->cart_weight;
  2309. WFIFOL(fd,10)=battle_config.max_cart_weight;
  2310. len=14;
  2311. break;
  2312. default:
  2313. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2314. return 1;
  2315. }
  2316. WFIFOSET(fd,len);
  2317. return 0;
  2318. }
  2319. int clif_changestatus(struct block_list *bl,int type,int val)
  2320. {
  2321. unsigned char buf[12];
  2322. struct map_session_data *sd = NULL;
  2323. nullpo_ret(bl);
  2324. if(bl->type == BL_PC)
  2325. sd = (struct map_session_data *)bl;
  2326. if(sd){
  2327. WBUFW(buf,0)=0x1ab;
  2328. WBUFL(buf,2)=bl->id;
  2329. WBUFW(buf,6)=type;
  2330. switch(type){
  2331. case SP_MANNER:
  2332. WBUFL(buf,8)=val;
  2333. break;
  2334. default:
  2335. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2336. return 1;
  2337. }
  2338. clif_send(buf,packet_len(0x1ab),bl,AREA_WOS);
  2339. }
  2340. return 0;
  2341. }
  2342. /*==========================================
  2343. *
  2344. *------------------------------------------*/
  2345. void clif_changelook(struct block_list *bl,int type,int val)
  2346. {
  2347. unsigned char buf[16];
  2348. struct map_session_data* sd = NULL;
  2349. struct status_change* sc;
  2350. struct view_data* vd;
  2351. enum send_target target = AREA;
  2352. nullpo_retv(bl);
  2353. sd = BL_CAST(BL_PC, bl);
  2354. sc = status_get_sc(bl);
  2355. vd = status_get_viewdata(bl);
  2356. //nullpo_ret(vd);
  2357. if( vd ) //temp hack to let Warp Portal change appearance
  2358. switch(type)
  2359. {
  2360. case LOOK_WEAPON:
  2361. if (sd)
  2362. {
  2363. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2364. val = vd->weapon;
  2365. }
  2366. else vd->weapon = val;
  2367. break;
  2368. case LOOK_SHIELD:
  2369. if (sd)
  2370. {
  2371. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2372. val = vd->shield;
  2373. }
  2374. else vd->shield = val;
  2375. break;
  2376. case LOOK_BASE:
  2377. vd->class_ = val;
  2378. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2379. vd->weapon = vd->shield = 0;
  2380. if (vd->cloth_color && (
  2381. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2382. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2383. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2384. ))
  2385. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2386. break;
  2387. case LOOK_HAIR:
  2388. vd->hair_style = val;
  2389. break;
  2390. case LOOK_HEAD_BOTTOM:
  2391. vd->head_bottom = val;
  2392. break;
  2393. case LOOK_HEAD_TOP:
  2394. vd->head_top = val;
  2395. break;
  2396. case LOOK_HEAD_MID:
  2397. vd->head_mid = val;
  2398. break;
  2399. case LOOK_HAIR_COLOR:
  2400. vd->hair_color = val;
  2401. break;
  2402. case LOOK_CLOTHES_COLOR:
  2403. if (val && (
  2404. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2405. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2406. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2407. ))
  2408. val = 0;
  2409. vd->cloth_color = val;
  2410. break;
  2411. case LOOK_SHOES:
  2412. #if PACKETVER > 3
  2413. if (sd) {
  2414. int n;
  2415. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2416. if(sd->inventory_data[n]->view_id > 0)
  2417. val = sd->inventory_data[n]->view_id;
  2418. else
  2419. val = sd->status.inventory[n].nameid;
  2420. }
  2421. val = 0;
  2422. }
  2423. #endif
  2424. //Shoes? No packet uses this....
  2425. break;
  2426. }
  2427. // prevent leaking the presence of GM-hidden objects
  2428. if( sc && sc->option&OPTION_INVISIBLE )
  2429. target = SELF;
  2430. #if PACKETVER < 4
  2431. WBUFW(buf,0)=0xc3;
  2432. WBUFL(buf,2)=bl->id;
  2433. WBUFB(buf,6)=type;
  2434. WBUFB(buf,7)=val;
  2435. clif_send(buf,packet_len(0xc3),bl,target);
  2436. #else
  2437. WBUFW(buf,0)=0x1d7;
  2438. WBUFL(buf,2)=bl->id;
  2439. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2440. WBUFB(buf,6)=LOOK_WEAPON;
  2441. WBUFW(buf,7)=vd->weapon;
  2442. WBUFW(buf,9)=vd->shield;
  2443. } else {
  2444. WBUFB(buf,6)=type;
  2445. WBUFW(buf,7)=val;
  2446. WBUFW(buf,9)=0;
  2447. }
  2448. clif_send(buf,packet_len(0x1d7),bl,target);
  2449. #endif
  2450. }
  2451. //Sends a change-base-look packet required for traps as they are triggered.
  2452. void clif_changetraplook(struct block_list *bl,int val)
  2453. {
  2454. unsigned char buf[32];
  2455. #if PACKETVER < 4
  2456. WBUFW(buf,0)=0xc3;
  2457. WBUFL(buf,2)=bl->id;
  2458. WBUFB(buf,6)=LOOK_BASE;
  2459. WBUFB(buf,7)=val;
  2460. clif_send(buf,packet_len(0xc3),bl,AREA);
  2461. #else
  2462. WBUFW(buf,0)=0x1d7;
  2463. WBUFL(buf,2)=bl->id;
  2464. WBUFB(buf,6)=LOOK_BASE;
  2465. WBUFW(buf,7)=val;
  2466. WBUFW(buf,9)=0;
  2467. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2468. #endif
  2469. }
  2470. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2471. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2472. {
  2473. unsigned char buf[32];
  2474. #if PACKETVER < 4
  2475. WBUFW(buf,0)=0xc3;
  2476. WBUFL(buf,2)=id;
  2477. WBUFB(buf,6)=type;
  2478. WBUFB(buf,7)=val;
  2479. clif_send(buf,packet_len(0xc3),bl,target);
  2480. #else
  2481. WBUFW(buf,0)=0x1d7;
  2482. WBUFL(buf,2)=id;
  2483. WBUFB(buf,6)=type;
  2484. WBUFW(buf,7)=val;
  2485. WBUFW(buf,9)=0;
  2486. clif_send(buf,packet_len(0x1d7),bl,target);
  2487. #endif
  2488. return;
  2489. }
  2490. /*==========================================
  2491. *
  2492. *------------------------------------------*/
  2493. int clif_initialstatus(struct map_session_data *sd)
  2494. {
  2495. int fd;
  2496. unsigned char *buf;
  2497. nullpo_ret(sd);
  2498. fd=sd->fd;
  2499. WFIFOHEAD(fd,packet_len(0xbd));
  2500. buf=WFIFOP(fd,0);
  2501. WBUFW(buf,0)=0xbd;
  2502. WBUFW(buf,2)=min(sd->status.status_point, SHRT_MAX);
  2503. WBUFB(buf,4)=min(sd->status.str, UCHAR_MAX);
  2504. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2505. WBUFB(buf,6)=min(sd->status.agi, UCHAR_MAX);
  2506. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2507. WBUFB(buf,8)=min(sd->status.vit, UCHAR_MAX);
  2508. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2509. WBUFB(buf,10)=min(sd->status.int_, UCHAR_MAX);
  2510. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2511. WBUFB(buf,12)=min(sd->status.dex, UCHAR_MAX);
  2512. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2513. WBUFB(buf,14)=min(sd->status.luk, UCHAR_MAX);
  2514. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2515. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw.atk;
  2516. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2; //atk bonus
  2517. WBUFW(buf,20) = sd->battle_status.matk_max;
  2518. WBUFW(buf,22) = sd->battle_status.matk_min;
  2519. WBUFW(buf,24) = sd->battle_status.def; // def
  2520. WBUFW(buf,26) = sd->battle_status.def2;
  2521. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2522. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2523. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2524. WBUFW(buf,30) = fd;
  2525. fd = sd->fd;
  2526. WBUFW(buf,32) = sd->battle_status.hit;
  2527. WBUFW(buf,34) = sd->battle_status.flee;
  2528. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2529. WBUFW(buf,38) = sd->battle_status.cri/10;
  2530. WBUFW(buf,40) = sd->status.karma;
  2531. WBUFW(buf,42) = sd->status.manner;
  2532. WFIFOSET(fd,packet_len(0xbd));
  2533. clif_updatestatus(sd,SP_STR);
  2534. clif_updatestatus(sd,SP_AGI);
  2535. clif_updatestatus(sd,SP_VIT);
  2536. clif_updatestatus(sd,SP_INT);
  2537. clif_updatestatus(sd,SP_DEX);
  2538. clif_updatestatus(sd,SP_LUK);
  2539. clif_updatestatus(sd,SP_ATTACKRANGE);
  2540. clif_updatestatus(sd,SP_ASPD);
  2541. return 0;
  2542. }
  2543. /*==========================================
  2544. *矢装備
  2545. *------------------------------------------*/
  2546. int clif_arrowequip(struct map_session_data *sd,int val)
  2547. {
  2548. int fd;
  2549. nullpo_ret(sd);
  2550. pc_stop_attack(sd); // [Valaris]
  2551. fd=sd->fd;
  2552. WFIFOHEAD(fd, packet_len(0x013c));
  2553. WFIFOW(fd,0)=0x013c;
  2554. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2555. WFIFOSET(fd,packet_len(0x013c));
  2556. return 0;
  2557. }
  2558. /// Ammunition action message.
  2559. /// type=0 : MsgStringTable[242]="Please equip the proper ammunition first."
  2560. /// type=1 : MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2561. /// type=2 : MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2562. /// type=3 : assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2563. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2564. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2565. int clif_arrow_fail(struct map_session_data *sd,int type)
  2566. {
  2567. int fd;
  2568. nullpo_ret(sd);
  2569. fd=sd->fd;
  2570. WFIFOHEAD(fd, packet_len(0x013b));
  2571. WFIFOW(fd,0)=0x013b;
  2572. WFIFOW(fd,2)=type;
  2573. WFIFOSET(fd,packet_len(0x013b));
  2574. return 0;
  2575. }
  2576. /*==========================================
  2577. * 作成可能 矢リスト送信
  2578. *------------------------------------------*/
  2579. int clif_arrow_create_list(struct map_session_data *sd)
  2580. {
  2581. int i, c, j;
  2582. int fd;
  2583. nullpo_ret(sd);
  2584. fd = sd->fd;
  2585. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2586. WFIFOW(fd,0) = 0x1ad;
  2587. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2588. if (skill_arrow_db[i].nameid > 0 &&
  2589. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2590. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2591. {
  2592. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2593. WFIFOW(fd,c*2+4) = j;
  2594. else
  2595. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2596. c++;
  2597. }
  2598. }
  2599. WFIFOW(fd,2) = c*2+4;
  2600. WFIFOSET(fd, WFIFOW(fd,2));
  2601. if (c > 0) {
  2602. sd->menuskill_id = AC_MAKINGARROW;
  2603. sd->menuskill_val = c;
  2604. }
  2605. return 0;
  2606. }
  2607. /*==========================================
  2608. *
  2609. *------------------------------------------*/
  2610. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2611. {
  2612. int fd;
  2613. nullpo_ret(sd);
  2614. fd=sd->fd;
  2615. WFIFOHEAD(fd,packet_len(0xbc));
  2616. WFIFOW(fd,0)=0xbc;
  2617. WFIFOW(fd,2)=type;
  2618. WFIFOB(fd,4)=ok;
  2619. WFIFOB(fd,5)=cap_value(val,0,UCHAR_MAX);
  2620. WFIFOSET(fd,packet_len(0xbc));
  2621. return 0;
  2622. }
  2623. /*==========================================
  2624. *
  2625. *------------------------------------------*/
  2626. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2627. {
  2628. int fd;
  2629. nullpo_ret(sd);
  2630. fd=sd->fd;
  2631. WFIFOHEAD(fd,packet_len(0xaa));
  2632. WFIFOW(fd,0)=0xaa;
  2633. WFIFOW(fd,2)=n+2;
  2634. WFIFOW(fd,4)=pos;
  2635. #if PACKETVER < 20100629
  2636. WFIFOB(fd,6)=ok;
  2637. #else
  2638. if (ok && sd->inventory_data[n]->equip&EQP_HELM)
  2639. WFIFOW(fd,6)=sd->inventory_data[n]->look;
  2640. else
  2641. WFIFOW(fd,6)=0;
  2642. WFIFOB(fd,8)=ok;
  2643. #endif
  2644. WFIFOSET(fd,packet_len(0xaa));
  2645. return 0;
  2646. }
  2647. /*==========================================
  2648. *
  2649. *------------------------------------------*/
  2650. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2651. {
  2652. int fd;
  2653. nullpo_ret(sd);
  2654. fd=sd->fd;
  2655. WFIFOHEAD(fd,packet_len(0xac));
  2656. WFIFOW(fd,0)=0xac;
  2657. WFIFOW(fd,2)=n+2;
  2658. WFIFOW(fd,4)=pos;
  2659. WFIFOB(fd,6)=ok;
  2660. WFIFOSET(fd,packet_len(0xac));
  2661. return 0;
  2662. }
  2663. /*==========================================
  2664. *
  2665. *------------------------------------------*/
  2666. int clif_misceffect(struct block_list* bl,int type)
  2667. {
  2668. unsigned char buf[32];
  2669. nullpo_ret(bl);
  2670. WBUFW(buf,0) = 0x19b;
  2671. WBUFL(buf,2) = bl->id;
  2672. WBUFL(buf,6) = type;
  2673. clif_send(buf,packet_len(0x19b),bl,AREA);
  2674. return 0;
  2675. }
  2676. /*==========================================
  2677. * 表示オプション変更
  2678. *------------------------------------------*/
  2679. int clif_changeoption(struct block_list* bl)
  2680. {
  2681. unsigned char buf[32];
  2682. struct status_change *sc;
  2683. struct map_session_data* sd;
  2684. nullpo_ret(bl);
  2685. sc = status_get_sc(bl);
  2686. if (!sc) return 0; //How can an option change if there's no sc?
  2687. sd = BL_CAST(BL_PC, bl);
  2688. #if PACKETVER >= 7
  2689. WBUFW(buf,0) = 0x229;
  2690. WBUFL(buf,2) = bl->id;
  2691. WBUFW(buf,6) = sc->opt1;
  2692. WBUFW(buf,8) = sc->opt2;
  2693. WBUFL(buf,10) = sc->option;
  2694. WBUFB(buf,14) = (sd)? sd->status.karma : 0;
  2695. if(disguised(bl)) {
  2696. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2697. WBUFL(buf,2) = -bl->id;
  2698. clif_send(buf,packet_len(0x229),bl,SELF);
  2699. WBUFL(buf,2) = bl->id;
  2700. WBUFL(buf,10) = OPTION_INVISIBLE;
  2701. clif_send(buf,packet_len(0x229),bl,SELF);
  2702. } else
  2703. clif_send(buf,packet_len(0x229),bl,AREA);
  2704. #else
  2705. WBUFW(buf,0) = 0x119;
  2706. WBUFL(buf,2) = bl->id;
  2707. WBUFW(buf,6) = sc->opt1;
  2708. WBUFW(buf,8) = sc->opt2;
  2709. WBUFW(buf,10) = sc->option;
  2710. WBUFB(buf,12) = (sd)? sd->status.karma : 0;
  2711. if(disguised(bl)) {
  2712. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2713. WBUFL(buf,2) = -bl->id;
  2714. clif_send(buf,packet_len(0x119),bl,SELF);
  2715. WBUFL(buf,2) = bl->id;
  2716. WBUFW(buf,10) = OPTION_INVISIBLE;
  2717. clif_send(buf,packet_len(0x119),bl,SELF);
  2718. } else
  2719. clif_send(buf,packet_len(0x119),bl,AREA);
  2720. #endif
  2721. return 0;
  2722. }
  2723. int clif_changeoption2(struct block_list* bl)
  2724. {
  2725. unsigned char buf[20];
  2726. struct status_change *sc;
  2727. sc = status_get_sc(bl);
  2728. if (!sc) return 0; //How can an option change if there's no sc?
  2729. WBUFW(buf,0) = 0x28a;
  2730. WBUFL(buf,2) = bl->id;
  2731. WBUFL(buf,6) = sc->option;
  2732. WBUFL(buf,10) = clif_setlevel(status_get_lv(bl));
  2733. WBUFL(buf,14) = sc->opt3;
  2734. if(disguised(bl)) {
  2735. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  2736. WBUFL(buf,2) = -bl->id;
  2737. clif_send(buf,packet_len(0x28a),bl,SELF);
  2738. WBUFL(buf,2) = bl->id;
  2739. WBUFL(buf,6) = OPTION_INVISIBLE;
  2740. clif_send(buf,packet_len(0x28a),bl,SELF);
  2741. } else
  2742. clif_send(buf,packet_len(0x28a),bl,AREA);
  2743. return 0;
  2744. }
  2745. /*==========================================
  2746. *
  2747. *------------------------------------------*/
  2748. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2749. {
  2750. nullpo_ret(sd);
  2751. if(!ok) {
  2752. int fd=sd->fd;
  2753. WFIFOHEAD(fd,packet_len(0xa8));
  2754. WFIFOW(fd,0)=0xa8;
  2755. WFIFOW(fd,2)=index+2;
  2756. WFIFOW(fd,4)=amount;
  2757. WFIFOB(fd,6)=ok;
  2758. WFIFOSET(fd,packet_len(0xa8));
  2759. }
  2760. else {
  2761. #if PACKETVER < 3
  2762. int fd=sd->fd;
  2763. WFIFOHEAD(fd,packet_len(0xa8));
  2764. WFIFOW(fd,0)=0xa8;
  2765. WFIFOW(fd,2)=index+2;
  2766. WFIFOW(fd,4)=amount;
  2767. WFIFOB(fd,6)=ok;
  2768. WFIFOSET(fd,packet_len(0xa8));
  2769. #else
  2770. unsigned char buf[32];
  2771. WBUFW(buf,0)=0x1c8;
  2772. WBUFW(buf,2)=index+2;
  2773. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2774. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2775. else
  2776. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2777. WBUFL(buf,6)=sd->bl.id;
  2778. WBUFW(buf,10)=amount;
  2779. WBUFB(buf,12)=ok;
  2780. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2781. #endif
  2782. }
  2783. return 0;
  2784. }
  2785. /// Inform client whether chatroom creation was successful or not
  2786. /// R 00d6 <flag>.B
  2787. /// flag:
  2788. /// 0 = Room has been successfully created (opens chat room)
  2789. /// 1 = Room limit exceeded
  2790. /// 2 = Same room already exists
  2791. void clif_createchat(struct map_session_data* sd, int flag)
  2792. {
  2793. int fd;
  2794. nullpo_retv(sd);
  2795. fd = sd->fd;
  2796. WFIFOHEAD(fd,packet_len(0xd6));
  2797. WFIFOW(fd,0) = 0xd6;
  2798. WFIFOB(fd,2) = flag;
  2799. WFIFOSET(fd,packet_len(0xd6));
  2800. }
  2801. /*==========================================
  2802. * Display a chat above the owner
  2803. * R 00d7 <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <type>.B <title>.?B
  2804. *------------------------------------------*/
  2805. int clif_dispchat(struct chat_data* cd, int fd)
  2806. {
  2807. unsigned char buf[128];
  2808. uint8 type;
  2809. if( cd == NULL || cd->owner == NULL )
  2810. return 1;
  2811. // type - 0: private, 1: public, 2: npc, 3: non-clickable
  2812. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  2813. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  2814. : 1;
  2815. WBUFW(buf, 0) = 0xd7;
  2816. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2817. WBUFL(buf, 4) = cd->owner->id;
  2818. WBUFL(buf, 8) = cd->bl.id;
  2819. WBUFW(buf,12) = cd->limit;
  2820. WBUFW(buf,14) = cd->users;
  2821. WBUFB(buf,16) = type;
  2822. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2823. if( fd ) {
  2824. WFIFOHEAD(fd,WBUFW(buf,2));
  2825. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2826. WFIFOSET(fd,WBUFW(buf,2));
  2827. } else {
  2828. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  2829. }
  2830. return 0;
  2831. }
  2832. /*==========================================
  2833. * Chatroom properties adjustment
  2834. * R 00df <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <pub>.B <title>.?B
  2835. *------------------------------------------*/
  2836. int clif_changechatstatus(struct chat_data* cd)
  2837. {
  2838. unsigned char buf[128];
  2839. if( cd == NULL || cd->usersd[0] == NULL )
  2840. return 1;
  2841. WBUFW(buf, 0) = 0xdf;
  2842. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2843. WBUFL(buf, 4) = cd->usersd[0]->bl.id;
  2844. WBUFL(buf, 8) = cd->bl.id;
  2845. WBUFW(buf,12) = cd->limit;
  2846. WBUFW(buf,14) = cd->users;
  2847. WBUFB(buf,16) = cd->pub;
  2848. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2849. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2850. return 0;
  2851. }
  2852. /*==========================================
  2853. *
  2854. *------------------------------------------*/
  2855. int clif_clearchat(struct chat_data *cd,int fd)
  2856. {
  2857. unsigned char buf[32];
  2858. nullpo_ret(cd);
  2859. WBUFW(buf,0) = 0xd8;
  2860. WBUFL(buf,2) = cd->bl.id;
  2861. if( fd ) {
  2862. WFIFOHEAD(fd,packet_len(0xd8));
  2863. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2864. WFIFOSET(fd,packet_len(0xd8));
  2865. } else {
  2866. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  2867. }
  2868. return 0;
  2869. }
  2870. /// Displays message (mostly) regarding join chat
  2871. /// failures
  2872. /// R 0x00da <flag>.B
  2873. /// flag:
  2874. /// 0 = The room is already full.
  2875. /// 1 = Incorrect password, please try again.
  2876. /// 2 = You have been kicked out of the room.
  2877. /// 4 = You don't have enough money.
  2878. /// 5 = You are not the required level.
  2879. /// 6 = Too high level for this job.
  2880. /// 7 = Not the suitable job for this type of work.
  2881. int clif_joinchatfail(struct map_session_data *sd,int flag)
  2882. {
  2883. int fd;
  2884. nullpo_ret(sd);
  2885. fd = sd->fd;
  2886. WFIFOHEAD(fd,packet_len(0xda));
  2887. WFIFOW(fd,0) = 0xda;
  2888. WFIFOB(fd,2) = flag;
  2889. WFIFOSET(fd,packet_len(0xda));
  2890. return 0;
  2891. }
  2892. /*==========================================
  2893. *
  2894. *------------------------------------------*/
  2895. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2896. {
  2897. int fd;
  2898. int i;
  2899. nullpo_ret(sd);
  2900. nullpo_ret(cd);
  2901. fd = sd->fd;
  2902. if (!session_isActive(fd))
  2903. return 0;
  2904. WFIFOHEAD(fd, 8 + (28*cd->users));
  2905. WFIFOW(fd, 0) = 0xdb;
  2906. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2907. WFIFOL(fd, 4) = cd->bl.id;
  2908. for (i = 0; i < cd->users; i++) {
  2909. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  2910. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2911. }
  2912. WFIFOSET(fd, WFIFOW(fd, 2));
  2913. return 0;
  2914. }
  2915. /*==========================================
  2916. *
  2917. *------------------------------------------*/
  2918. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2919. {
  2920. unsigned char buf[32];
  2921. nullpo_ret(sd);
  2922. nullpo_ret(cd);
  2923. WBUFW(buf, 0) = 0x0dc;
  2924. WBUFW(buf, 2) = cd->users;
  2925. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2926. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  2927. return 0;
  2928. }
  2929. /*==========================================
  2930. * Announce the new owner
  2931. * R 00e1 <owner flag>.l <nick>.24B
  2932. *------------------------------------------*/
  2933. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  2934. {
  2935. unsigned char buf[64];
  2936. nullpo_retv(sd);
  2937. nullpo_retv(cd);
  2938. //FIXME: this announces a swap between positions 0 and 1 (probably not what we want) [ultramage]
  2939. //FIXME: aegis sends obviously incorrect packets; need to figure out what to send to display it correctly :X
  2940. //TODO: is it just owner swap, or can it do general-purpose reordering?
  2941. // It's not position, but operator flag, everyone set to 1 gets chat
  2942. // operator menu (yes, that means a chat may host multiple operators) [Ai4rei]
  2943. WBUFW(buf, 0) = 0xe1;
  2944. WBUFL(buf, 2) = 1;
  2945. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2946. WBUFW(buf,30) = 0xe1;
  2947. WBUFL(buf,32) = 0;
  2948. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2949. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  2950. }
  2951. /*==========================================
  2952. * Notify about user leaving the chatroom
  2953. * R 00dd <index>.w <nick>.24B <flag>.B
  2954. *------------------------------------------*/
  2955. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  2956. {
  2957. unsigned char buf[32];
  2958. nullpo_retv(sd);
  2959. nullpo_retv(cd);
  2960. WBUFW(buf, 0) = 0xdd;
  2961. WBUFW(buf, 2) = cd->users-1;
  2962. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2963. WBUFB(buf,28) = flag; // 0: left, 1: was kicked
  2964. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  2965. }
  2966. /*==========================================
  2967. * Opens a trade request window from char 'name'
  2968. * R 00e5 <nick>.24B
  2969. * R 01f4 <nick>.24B <charid>.L <baselvl>.W
  2970. *------------------------------------------*/
  2971. void clif_traderequest(struct map_session_data* sd, const char* name)
  2972. {
  2973. int fd = sd->fd;
  2974. #if PACKETVER < 6
  2975. WFIFOHEAD(fd,packet_len(0xe5));
  2976. WFIFOW(fd,0) = 0xe5;
  2977. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2978. WFIFOSET(fd,packet_len(0xe5));
  2979. #else
  2980. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2981. if( !tsd ) return;
  2982. WFIFOHEAD(fd,packet_len(0x1f4));
  2983. WFIFOW(fd,0) = 0x1f4;
  2984. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2985. WFIFOL(fd,26) = tsd->status.char_id;
  2986. WFIFOW(fd,30) = tsd->status.base_level;
  2987. WFIFOSET(fd,packet_len(0x1f4));
  2988. #endif
  2989. }
  2990. /*==========================================
  2991. * Reply to a trade-request.
  2992. * R 00e7 <type>.B
  2993. * R 01f5 <type>.B <charid>.L <baselvl>.W
  2994. * Type:
  2995. * 0: Char is too far
  2996. * 1: Character does not exist
  2997. * 2: Trade failed
  2998. * 3: Accept
  2999. * 4: Cancel
  3000. *------------------------------------------*/
  3001. void clif_tradestart(struct map_session_data* sd, uint8 type)
  3002. {
  3003. int fd = sd->fd;
  3004. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  3005. if( PACKETVER < 6 || !tsd ) {
  3006. WFIFOHEAD(fd,packet_len(0xe7));
  3007. WFIFOW(fd,0) = 0xe7;
  3008. WFIFOB(fd,2) = type;
  3009. WFIFOSET(fd,packet_len(0xe7));
  3010. } else {
  3011. WFIFOHEAD(fd,packet_len(0x1f5));
  3012. WFIFOW(fd,0) = 0x1f5;
  3013. WFIFOB(fd,2) = type;
  3014. WFIFOL(fd,3) = tsd->status.char_id;
  3015. WFIFOW(fd,7) = tsd->status.base_level;
  3016. WFIFOSET(fd,packet_len(0x1f5));
  3017. }
  3018. }
  3019. /*==========================================
  3020. * 相手方からのアイテム追加
  3021. *------------------------------------------*/
  3022. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3023. {
  3024. int fd;
  3025. unsigned char *buf;
  3026. #if PACKETVER < 20100223
  3027. const int cmd = 0xe9;
  3028. #else
  3029. const int cmd = 0x80f;
  3030. #endif
  3031. nullpo_retv(sd);
  3032. nullpo_retv(tsd);
  3033. fd = tsd->fd;
  3034. buf = WFIFOP(fd,0);
  3035. WFIFOHEAD(fd,packet_len(cmd));
  3036. WBUFW(buf,0) = cmd;
  3037. if( index == 0 )
  3038. {
  3039. #if PACKETVER < 20100223
  3040. WBUFL(buf,2) = amount; //amount
  3041. WBUFW(buf,6) = 0; // type id
  3042. #else
  3043. WBUFW(buf,2) = 0; // type id
  3044. WBUFB(buf,4) = 0; // item type
  3045. WBUFL(buf,5) = amount; // amount
  3046. buf = WBUFP(buf,1); //Advance 1B
  3047. #endif
  3048. WBUFB(buf,8) = 0; //identify flag
  3049. WBUFB(buf,9) = 0; // attribute
  3050. WBUFB(buf,10)= 0; //refine
  3051. WBUFW(buf,11)= 0; //card (4w)
  3052. WBUFW(buf,13)= 0; //card (4w)
  3053. WBUFW(buf,15)= 0; //card (4w)
  3054. WBUFW(buf,17)= 0; //card (4w)
  3055. }
  3056. else
  3057. {
  3058. index -= 2; //index fix
  3059. #if PACKETVER < 20100223
  3060. WBUFL(buf,2) = amount; //amount
  3061. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3062. WBUFW(buf,6) = sd->inventory_data[index]->view_id;
  3063. else
  3064. WBUFW(buf,6) = sd->status.inventory[index].nameid; // type id
  3065. #else
  3066. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3067. WBUFW(buf,2) = sd->inventory_data[index]->view_id;
  3068. else
  3069. WBUFW(buf,2) = sd->status.inventory[index].nameid; // type id
  3070. WBUFB(buf,4) = sd->inventory_data[index]->type; // item type
  3071. WBUFL(buf,5) = amount; // amount
  3072. buf = WBUFP(buf,1); //Advance 1B
  3073. #endif
  3074. WBUFB(buf,8) = sd->status.inventory[index].identify; //identify flag
  3075. WBUFB(buf,9) = sd->status.inventory[index].attribute; // attribute
  3076. WBUFB(buf,10)= sd->status.inventory[index].refine; //refine
  3077. clif_addcards(WBUFP(buf, 11), &sd->status.inventory[index]);
  3078. }
  3079. WFIFOSET(fd,packet_len(cmd));
  3080. }
  3081. /*==========================================
  3082. * アイテム追加成功/失敗
  3083. *------------------------------------------*/
  3084. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3085. {
  3086. int fd;
  3087. nullpo_retv(sd);
  3088. fd = sd->fd;
  3089. WFIFOHEAD(fd,packet_len(0xea));
  3090. WFIFOW(fd,0) = 0xea;
  3091. WFIFOW(fd,2) = index;
  3092. WFIFOB(fd,4) = fail;
  3093. WFIFOSET(fd,packet_len(0xea));
  3094. }
  3095. /*==========================================
  3096. * 取り引きok押し
  3097. *------------------------------------------*/
  3098. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3099. {
  3100. int fd;
  3101. nullpo_retv(sd);
  3102. fd = sd->fd;
  3103. WFIFOHEAD(fd,packet_len(0xec));
  3104. WFIFOW(fd,0) = 0xec;
  3105. WFIFOB(fd,2) = fail; // 0=you 1=the other person
  3106. WFIFOSET(fd,packet_len(0xec));
  3107. }
  3108. /*==========================================
  3109. * 取り引きがキャンセルされました
  3110. *------------------------------------------*/
  3111. void clif_tradecancelled(struct map_session_data* sd)
  3112. {
  3113. int fd;
  3114. nullpo_retv(sd);
  3115. fd = sd->fd;
  3116. WFIFOHEAD(fd,packet_len(0xee));
  3117. WFIFOW(fd,0) = 0xee;
  3118. WFIFOSET(fd,packet_len(0xee));
  3119. }
  3120. /*==========================================
  3121. * 取り引き完了
  3122. *------------------------------------------*/
  3123. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3124. {
  3125. int fd;
  3126. nullpo_retv(sd);
  3127. fd = sd->fd;
  3128. WFIFOHEAD(fd,packet_len(0xf0));
  3129. WFIFOW(fd,0) = 0xf0;
  3130. WFIFOB(fd,2) = fail;
  3131. WFIFOSET(fd,packet_len(0xf0));
  3132. }
  3133. /*==========================================
  3134. * カプラ倉庫のアイテム数を更新
  3135. *------------------------------------------*/
  3136. void clif_updatestorageamount(struct map_session_data* sd, int amount)
  3137. {
  3138. int fd;
  3139. nullpo_retv(sd);
  3140. fd=sd->fd;
  3141. WFIFOHEAD(fd,packet_len(0xf2));
  3142. WFIFOW(fd,0) = 0xf2; // update storage amount
  3143. WFIFOW(fd,2) = amount; //items
  3144. WFIFOW(fd,4) = MAX_STORAGE; //items max
  3145. WFIFOSET(fd,packet_len(0xf2));
  3146. }
  3147. /*==========================================
  3148. * カプラ倉庫にアイテムを追加する
  3149. *------------------------------------------*/
  3150. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  3151. {
  3152. int view,fd;
  3153. nullpo_retv(sd);
  3154. nullpo_retv(i);
  3155. fd=sd->fd;
  3156. view = itemdb_viewid(i->nameid);
  3157. #if PACKETVER < 5
  3158. WFIFOHEAD(fd,packet_len(0xf4));
  3159. WFIFOW(fd, 0) = 0xf4; // Storage item added
  3160. WFIFOW(fd, 2) = index+1; // index
  3161. WFIFOL(fd, 4) = amount; // amount
  3162. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3163. WFIFOB(fd,10) = i->identify; //identify flag
  3164. WFIFOB(fd,11) = i->attribute; // attribute
  3165. WFIFOB(fd,12) = i->refine; //refine
  3166. clif_addcards(WFIFOP(fd,13), i);
  3167. WFIFOSET(fd,packet_len(0xf4));
  3168. #else
  3169. WFIFOHEAD(fd,packet_len(0x1c4));
  3170. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  3171. WFIFOW(fd, 2) = index+1; // index
  3172. WFIFOL(fd, 4) = amount; // amount
  3173. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  3174. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  3175. WFIFOB(fd,11) = i->identify; //identify flag
  3176. WFIFOB(fd,12) = i->attribute; // attribute
  3177. WFIFOB(fd,13) = i->refine; //refine
  3178. clif_addcards(WFIFOP(fd,14), i);
  3179. WFIFOSET(fd,packet_len(0x1c4));
  3180. #endif
  3181. }
  3182. /*==========================================
  3183. *
  3184. *------------------------------------------*/
  3185. void clif_updateguildstorageamount(struct map_session_data* sd, int amount)
  3186. {
  3187. int fd;
  3188. nullpo_retv(sd);
  3189. fd=sd->fd;
  3190. WFIFOHEAD(fd,packet_len(0xf2));
  3191. WFIFOW(fd,0) = 0xf2; // update storage amount
  3192. WFIFOW(fd,2) = amount; //items
  3193. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  3194. WFIFOSET(fd,packet_len(0xf2));
  3195. }
  3196. /*==========================================
  3197. * カプラ倉庫からアイテムを取り去る
  3198. *------------------------------------------*/
  3199. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  3200. {
  3201. int fd;
  3202. nullpo_retv(sd);
  3203. fd=sd->fd;
  3204. WFIFOHEAD(fd,packet_len(0xf6));
  3205. WFIFOW(fd,0)=0xf6; // Storage item removed
  3206. WFIFOW(fd,2)=index+1;
  3207. WFIFOL(fd,4)=amount;
  3208. WFIFOSET(fd,packet_len(0xf6));
  3209. }
  3210. /*==========================================
  3211. * カプラ倉庫を閉じる
  3212. *------------------------------------------*/
  3213. void clif_storageclose(struct map_session_data* sd)
  3214. {
  3215. int fd;
  3216. nullpo_retv(sd);
  3217. fd=sd->fd;
  3218. WFIFOHEAD(fd,packet_len(0xf8));
  3219. WFIFOW(fd,0) = 0xf8; // Storage Closed
  3220. WFIFOSET(fd,packet_len(0xf8));
  3221. }
  3222. /*==========================================
  3223. * PC表示
  3224. *------------------------------------------*/
  3225. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3226. {
  3227. int gmlvl;
  3228. struct block_list *d_bl;
  3229. int i;
  3230. if(dstsd->chatID)
  3231. {
  3232. struct chat_data *cd;
  3233. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  3234. if(cd && cd->usersd[0]==dstsd)
  3235. clif_dispchat(cd,sd->fd);
  3236. }
  3237. if(dstsd->vender_id)
  3238. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3239. if(dstsd->spiritball > 0)
  3240. clif_spiritball_single(sd->fd, dstsd);
  3241. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3242. (sd->state.bg_id && sd->state.bg_id == dstsd->state.bg_id) || //BattleGround
  3243. (battle_config.disp_hpmeter && (gmlvl = pc_isGM(sd)) >= battle_config.disp_hpmeter && gmlvl >= pc_isGM(dstsd)) )
  3244. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3245. // display link (sd - dstsd) to sd
  3246. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  3247. if( i < 5 ) clif_devotion(&sd->bl, sd);
  3248. // display links (dstsd - devotees) to sd
  3249. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  3250. if( i < 5 ) clif_devotion(&dstsd->bl, sd);
  3251. // display link (dstsd - crusader) to sd
  3252. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3253. clif_devotion(d_bl, sd);
  3254. }
  3255. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3256. {
  3257. uint8 buf[128];
  3258. struct unit_data *ud;
  3259. struct view_data *vd;
  3260. int len;
  3261. vd = status_get_viewdata(bl);
  3262. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3263. return;
  3264. ud = unit_bl2ud(bl);
  3265. len = ( ud && ud->walktimer != INVALID_TIMER ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3266. clif_send(buf,len,&sd->bl,SELF);
  3267. if (vd->cloth_color)
  3268. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3269. switch (bl->type)
  3270. {
  3271. case BL_PC:
  3272. {
  3273. TBL_PC* tsd = (TBL_PC*)bl;
  3274. clif_getareachar_pc(sd, tsd);
  3275. if(tsd->state.size==2) // tiny/big players [Valaris]
  3276. clif_specialeffect_single(bl,423,sd->fd);
  3277. else if(tsd->state.size==1)
  3278. clif_specialeffect_single(bl,421,sd->fd);
  3279. if( tsd->state.bg_id && map[tsd->bl.m].flag.battleground )
  3280. clif_sendbgemblem_single(sd->fd,tsd);
  3281. }
  3282. break;
  3283. case BL_MER: // Devotion Effects
  3284. if( ((TBL_MER*)bl)->devotion_flag )
  3285. clif_devotion(bl, sd);
  3286. break;
  3287. case BL_NPC:
  3288. {
  3289. TBL_NPC* nd = (TBL_NPC*)bl;
  3290. if( nd->chat_id )
  3291. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3292. if( nd->size == 2 )
  3293. clif_specialeffect_single(bl,423,sd->fd);
  3294. else if( nd->size == 1 )
  3295. clif_specialeffect_single(bl,421,sd->fd);
  3296. }
  3297. break;
  3298. case BL_MOB:
  3299. {
  3300. TBL_MOB* md = (TBL_MOB*)bl;
  3301. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3302. clif_specialeffect_single(bl,423,sd->fd);
  3303. else if(md->special_state.size==1)
  3304. clif_specialeffect_single(bl,421,sd->fd);
  3305. }
  3306. break;
  3307. case BL_PET:
  3308. if (vd->head_bottom)
  3309. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3310. break;
  3311. }
  3312. }
  3313. //Modifies the type of damage according to status changes [Skotlex]
  3314. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3315. #define clif_calc_delay(type,div,damage,delay) ((delay)==0&&(damage)>0?((div)>1?9:4):type)
  3316. /*==========================================
  3317. * Estimates walk delay based on the damage criteria. [Skotlex]
  3318. *------------------------------------------*/
  3319. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3320. {
  3321. if (type == 4 || type == 9 || damage <=0)
  3322. return 0;
  3323. if (bl->type == BL_PC) {
  3324. if (battle_config.pc_walk_delay_rate != 100)
  3325. delay = delay*battle_config.pc_walk_delay_rate/100;
  3326. } else
  3327. if (battle_config.walk_delay_rate != 100)
  3328. delay = delay*battle_config.walk_delay_rate/100;
  3329. if (div_ > 1) //Multi-hit skills mean higher delays.
  3330. delay += battle_config.multihit_delay*(div_-1);
  3331. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3332. }
  3333. /*==========================================
  3334. * Sends a 'damage' packet (src performs action on dst)
  3335. * R 008a <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.W <div>.W <type>.B <damage2>.W
  3336. * R 02e1 <src ID>.L <dst ID>.L <server tick>.L <src speed>.L <dst speed>.L <damage>.L <div>.W <type>.B <damage2>.L
  3337. *
  3338. * type=00 damage [param1: total damage, param2: div, param3: assassin dual-wield damage]
  3339. * type=01 pick up item
  3340. * type=02 sit down
  3341. * type=03 stand up
  3342. * type=04 reflected/absorbed damage?
  3343. * type=08 double attack
  3344. * type=09 don't display flinch animation (endure)
  3345. * type=0a critical hit
  3346. * type=0b lucky dodge
  3347. *------------------------------------------*/
  3348. 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)
  3349. {
  3350. unsigned char buf[256];
  3351. struct status_change *sc;
  3352. nullpo_ret(src);
  3353. nullpo_ret(dst);
  3354. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3355. sc = status_get_sc(dst);
  3356. if(sc && sc->count) {
  3357. if(sc->data[SC_HALLUCINATION]) {
  3358. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3359. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3360. }
  3361. }
  3362. WBUFW(buf,0)=0x8a;
  3363. WBUFL(buf,2)=src->id;
  3364. WBUFL(buf,6)=dst->id;
  3365. WBUFL(buf,10)=tick;
  3366. WBUFL(buf,14)=sdelay;
  3367. WBUFL(buf,18)=ddelay;
  3368. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3369. WBUFW(buf,22)=damage?div:0;
  3370. WBUFW(buf,27)=damage2?div:0;
  3371. } else {
  3372. WBUFW(buf,22)=min(damage, SHRT_MAX);
  3373. WBUFW(buf,27)=damage2;
  3374. }
  3375. WBUFW(buf,24)=div;
  3376. WBUFB(buf,26)=type;
  3377. if(disguised(dst)) {
  3378. clif_send(buf,packet_len(0x8a),dst,AREA_WOS);
  3379. WBUFL(buf,6) = -dst->id;
  3380. clif_send(buf,packet_len(0x8a),dst,SELF);
  3381. } else
  3382. clif_send(buf,packet_len(0x8a),dst,AREA);
  3383. if(disguised(src)) {
  3384. WBUFL(buf,2) = -src->id;
  3385. if (disguised(dst))
  3386. WBUFL(buf,6) = dst->id;
  3387. if(damage > 0) WBUFW(buf,22) = -1;
  3388. if(damage2 > 0) WBUFW(buf,27) = -1;
  3389. clif_send(buf,packet_len(0x8a),src,SELF);
  3390. }
  3391. //Return adjusted can't walk delay for further processing.
  3392. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3393. }
  3394. /*==========================================
  3395. * src picks up dst
  3396. *------------------------------------------*/
  3397. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3398. {
  3399. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3400. unsigned char buf[32];
  3401. nullpo_retv(src);
  3402. nullpo_retv(dst);
  3403. WBUFW(buf, 0) = 0x8a;
  3404. WBUFL(buf, 2) = src->id;
  3405. WBUFL(buf, 6) = dst->id;
  3406. WBUFB(buf,26) = 1;
  3407. clif_send(buf, packet_len(0x8a), src, AREA);
  3408. }
  3409. /*==========================================
  3410. * inform clients in area that `bl` is sitting
  3411. *------------------------------------------*/
  3412. void clif_sitting(struct block_list* bl)
  3413. {
  3414. unsigned char buf[32];
  3415. nullpo_retv(bl);
  3416. WBUFW(buf, 0) = 0x8a;
  3417. WBUFL(buf, 2) = bl->id;
  3418. WBUFB(buf,26) = 2;
  3419. clif_send(buf, packet_len(0x8a), bl, AREA);
  3420. if(disguised(bl)) {
  3421. WBUFL(buf, 2) = - bl->id;
  3422. clif_send(buf, packet_len(0x8a), bl, SELF);
  3423. }
  3424. }
  3425. /*==========================================
  3426. * inform clients in area that `bl` is standing
  3427. *------------------------------------------*/
  3428. void clif_standing(struct block_list* bl)
  3429. {
  3430. unsigned char buf[32];
  3431. nullpo_retv(bl);
  3432. WBUFW(buf, 0) = 0x8a;
  3433. WBUFL(buf, 2) = bl->id;
  3434. WBUFB(buf,26) = 3;
  3435. clif_send(buf, packet_len(0x8a), bl, AREA);
  3436. if(disguised(bl)) {
  3437. WBUFL(buf, 2) = - bl->id;
  3438. clif_send(buf, packet_len(0x8a), bl, SELF);
  3439. }
  3440. }
  3441. /*==========================================
  3442. * Inform client(s) about a map-cell change
  3443. *------------------------------------------*/
  3444. void clif_changemapcell(int fd, int m, int x, int y, int type, enum send_target target)
  3445. {
  3446. unsigned char buf[32];
  3447. WBUFW(buf,0) = 0x192;
  3448. WBUFW(buf,2) = x;
  3449. WBUFW(buf,4) = y;
  3450. WBUFW(buf,6) = type;
  3451. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3452. if( fd )
  3453. {
  3454. WFIFOHEAD(fd,packet_len(0x192));
  3455. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3456. WFIFOSET(fd,packet_len(0x192));
  3457. }
  3458. else
  3459. {
  3460. struct block_list dummy_bl;
  3461. dummy_bl.type = BL_NUL;
  3462. dummy_bl.x = x;
  3463. dummy_bl.y = y;
  3464. dummy_bl.m = m;
  3465. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3466. }
  3467. }
  3468. /*==========================================
  3469. *
  3470. *------------------------------------------*/
  3471. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3472. {
  3473. int view,fd;
  3474. fd=sd->fd;
  3475. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3476. WFIFOHEAD(fd,packet_len(0x9d));
  3477. WFIFOW(fd,0)=0x9d;
  3478. WFIFOL(fd,2)=fitem->bl.id;
  3479. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3480. WFIFOW(fd,6)=view;
  3481. else
  3482. WFIFOW(fd,6)=fitem->item_data.nameid;
  3483. WFIFOB(fd,8)=fitem->item_data.identify;
  3484. WFIFOW(fd,9)=fitem->bl.x;
  3485. WFIFOW(fd,11)=fitem->bl.y;
  3486. WFIFOW(fd,13)=fitem->item_data.amount;
  3487. WFIFOB(fd,15)=fitem->subx;
  3488. WFIFOB(fd,16)=fitem->suby;
  3489. WFIFOSET(fd,packet_len(0x9d));
  3490. }
  3491. /*==========================================
  3492. * 場所スキルエフェクトが視界に入る
  3493. *------------------------------------------*/
  3494. static void clif_getareachar_skillunit(struct map_session_data *sd, struct skill_unit *unit)
  3495. {
  3496. int fd = sd->fd;
  3497. #if PACKETVER >= 3
  3498. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3499. WFIFOHEAD(fd,packet_len(0x1c9));
  3500. WFIFOW(fd, 0)=0x1c9;
  3501. WFIFOL(fd, 2)=unit->bl.id;
  3502. WFIFOL(fd, 6)=unit->group->src_id;
  3503. WFIFOW(fd,10)=unit->bl.x;
  3504. WFIFOW(fd,12)=unit->bl.y;
  3505. WFIFOB(fd,14)=unit->group->unit_id;
  3506. WFIFOB(fd,15)=1;
  3507. WFIFOB(fd,16)=1;
  3508. safestrncpy((char*)WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3509. WFIFOSET(fd,packet_len(0x1c9));
  3510. return;
  3511. }
  3512. #endif
  3513. WFIFOHEAD(fd,packet_len(0x11f));
  3514. WFIFOW(fd, 0)=0x11f;
  3515. WFIFOL(fd, 2)=unit->bl.id;
  3516. WFIFOL(fd, 6)=unit->group->src_id;
  3517. WFIFOW(fd,10)=unit->bl.x;
  3518. WFIFOW(fd,12)=unit->bl.y;
  3519. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3520. WFIFOB(fd,14)=UNT_DUMMYSKILL; //Use invisible unit id for traps.
  3521. else
  3522. WFIFOB(fd,14)=unit->group->unit_id;
  3523. WFIFOB(fd,15)=1; // ignored by client (always gets set to 1)
  3524. WFIFOSET(fd,packet_len(0x11f));
  3525. if(unit->group->skill_id == WZ_ICEWALL)
  3526. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  3527. }
  3528. /*==========================================
  3529. * 場所スキルエフェクトが視界から消える
  3530. *------------------------------------------*/
  3531. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3532. {
  3533. nullpo_retv(unit);
  3534. WFIFOHEAD(fd,packet_len(0x120));
  3535. WFIFOW(fd, 0)=0x120;
  3536. WFIFOL(fd, 2)=unit->bl.id;
  3537. WFIFOSET(fd,packet_len(0x120));
  3538. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3539. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  3540. }
  3541. /*==========================================
  3542. * 場所スキルエフェクト削除
  3543. *------------------------------------------*/
  3544. void clif_skill_delunit(struct skill_unit *unit)
  3545. {
  3546. unsigned char buf[16];
  3547. nullpo_retv(unit);
  3548. WBUFW(buf, 0)=0x120;
  3549. WBUFL(buf, 2)=unit->bl.id;
  3550. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3551. }
  3552. /*==========================================
  3553. * Sent when an object gets ankle-snared (ZC_SKILL_UPDATE)
  3554. * Only affects units with class [139,153] client-side
  3555. * R 01ac <object id>.l
  3556. *------------------------------------------*/
  3557. void clif_skillunit_update(struct block_list* bl)
  3558. {
  3559. unsigned char buf[6];
  3560. nullpo_retv(bl);
  3561. WBUFW(buf,0) = 0x1ac;
  3562. WBUFL(buf,2) = bl->id;
  3563. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3564. }
  3565. /*==========================================
  3566. *
  3567. *------------------------------------------*/
  3568. int clif_getareachar(struct block_list* bl,va_list ap)
  3569. {
  3570. struct map_session_data *sd;
  3571. nullpo_ret(bl);
  3572. sd=va_arg(ap,struct map_session_data*);
  3573. if (sd == NULL || !sd->fd)
  3574. return 0;
  3575. switch(bl->type){
  3576. case BL_ITEM:
  3577. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3578. break;
  3579. case BL_SKILL:
  3580. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3581. break;
  3582. default:
  3583. if(&sd->bl == bl)
  3584. break;
  3585. clif_getareachar_unit(sd,bl);
  3586. break;
  3587. }
  3588. return 0;
  3589. }
  3590. /*==========================================
  3591. * tbl has gone out of view-size of bl
  3592. *------------------------------------------*/
  3593. int clif_outsight(struct block_list *bl,va_list ap)
  3594. {
  3595. struct block_list *tbl;
  3596. struct view_data *vd;
  3597. TBL_PC *sd, *tsd;
  3598. tbl=va_arg(ap,struct block_list*);
  3599. if(bl == tbl) return 0;
  3600. sd = BL_CAST(BL_PC, bl);
  3601. tsd = BL_CAST(BL_PC, tbl);
  3602. if (tsd && tsd->fd)
  3603. { //tsd has lost sight of the bl object.
  3604. switch(bl->type){
  3605. case BL_PC:
  3606. if (sd->vd.class_ != INVISIBLE_CLASS)
  3607. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  3608. if(sd->chatID){
  3609. struct chat_data *cd;
  3610. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3611. if(cd->usersd[0]==sd)
  3612. clif_dispchat(cd,tsd->fd);
  3613. }
  3614. if(sd->vender_id)
  3615. clif_closevendingboard(bl,tsd->fd);
  3616. break;
  3617. case BL_ITEM:
  3618. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3619. break;
  3620. case BL_SKILL:
  3621. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3622. break;
  3623. default:
  3624. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3625. clif_clearunit_single(bl->id,CLR_OUTSIGHT,tsd->fd);
  3626. break;
  3627. }
  3628. }
  3629. if (sd && sd->fd)
  3630. { //sd is watching tbl go out of view.
  3631. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3632. clif_clearunit_single(tbl->id,CLR_OUTSIGHT,sd->fd);
  3633. }
  3634. return 0;
  3635. }
  3636. /*==========================================
  3637. * tbl has come into view of bl
  3638. *------------------------------------------*/
  3639. int clif_insight(struct block_list *bl,va_list ap)
  3640. {
  3641. struct block_list *tbl;
  3642. TBL_PC *sd, *tsd;
  3643. tbl=va_arg(ap,struct block_list*);
  3644. if (bl == tbl) return 0;
  3645. sd = BL_CAST(BL_PC, bl);
  3646. tsd = BL_CAST(BL_PC, tbl);
  3647. if (tsd && tsd->fd)
  3648. { //Tell tsd that bl entered into his view
  3649. switch(bl->type){
  3650. case BL_ITEM:
  3651. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3652. break;
  3653. case BL_SKILL:
  3654. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3655. break;
  3656. default:
  3657. clif_getareachar_unit(tsd,bl);
  3658. break;
  3659. }
  3660. }
  3661. if (sd && sd->fd)
  3662. { //Tell sd that tbl walked into his view
  3663. clif_getareachar_unit(sd,tbl);
  3664. }
  3665. return 0;
  3666. }
  3667. /*==========================================
  3668. *
  3669. *------------------------------------------
  3670. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3671. {
  3672. int fd,id;
  3673. nullpo_ret(sd);
  3674. fd=sd->fd;
  3675. if( (id=sd->status.skill[skillid].id) <= 0 )
  3676. return 0;
  3677. WFIFOHEAD(fd,packet_len(0x147));
  3678. WFIFOW(fd,0)=0x147;
  3679. WFIFOW(fd,2) = id;
  3680. if(type < 0)
  3681. WFIFOW(fd,4) = skill_get_inf(id);
  3682. else
  3683. WFIFOW(fd,4) = type;
  3684. WFIFOW(fd,6) = 0;
  3685. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3686. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3687. if(range < 0)
  3688. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3689. WFIFOW(fd,12)= range;
  3690. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3691. if(sd->status.skill[skillid].flag ==0)
  3692. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3693. else
  3694. WFIFOB(fd,38) = 0;
  3695. WFIFOSET(fd,packet_len(0x147));
  3696. return 0;
  3697. }*/
  3698. /*==========================================
  3699. * スキルリストを送信する
  3700. *------------------------------------------*/
  3701. int clif_skillinfoblock(struct map_session_data *sd)
  3702. {
  3703. int fd;
  3704. int i,len,id;
  3705. nullpo_ret(sd);
  3706. fd=sd->fd;
  3707. if (!fd) return 0;
  3708. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3709. WFIFOW(fd,0) = 0x10f;
  3710. for ( i = 0, len = 4; i < MAX_SKILL; i++)
  3711. {
  3712. if( (id = sd->status.skill[i].id) != 0 )
  3713. {
  3714. WFIFOW(fd,len) = id;
  3715. if( (id == MO_EXTREMITYFIST && sd->state.combo&1) || (id == TK_JUMPKICK && sd->state.combo&2) )
  3716. WFIFOW(fd,len+2) = INF_SELF_SKILL;
  3717. else
  3718. WFIFOW(fd,len+2) = skill_get_inf(id);
  3719. WFIFOW(fd,len+4) = 0;
  3720. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3721. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3722. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3723. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3724. if(sd->status.skill[i].flag == 0)
  3725. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3726. else
  3727. WFIFOB(fd,len+36) = 0;
  3728. len += 37;
  3729. }
  3730. }
  3731. WFIFOW(fd,2)=len;
  3732. WFIFOSET(fd,len);
  3733. return 1;
  3734. }
  3735. int clif_addskill(struct map_session_data *sd, int id )
  3736. {
  3737. int fd;
  3738. nullpo_ret(sd);
  3739. fd = sd->fd;
  3740. if (!fd) return 0;
  3741. if( sd->status.skill[id].id <= 0 )
  3742. return 0;
  3743. WFIFOHEAD(fd, packet_len(0x111));
  3744. WFIFOW(fd,0) = 0x111;
  3745. WFIFOW(fd,2) = id;
  3746. if( (id == MO_EXTREMITYFIST && sd->state.combo&1) || (id == TK_JUMPKICK && sd->state.combo&2) )
  3747. WFIFOW(fd,4) = INF_SELF_SKILL;
  3748. else
  3749. WFIFOW(fd,4) = skill_get_inf(id);
  3750. WFIFOW(fd,6) = 0;
  3751. WFIFOW(fd,8) = sd->status.skill[id].lv;
  3752. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[id].lv);
  3753. WFIFOW(fd,12)= skill_get_range2(&sd->bl, id,sd->status.skill[id].lv);
  3754. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3755. if( sd->status.skill[id].flag == 0 )
  3756. WFIFOB(fd,38) = (sd->status.skill[id].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3757. else
  3758. WFIFOB(fd,38) = 0;
  3759. WFIFOSET(fd,packet_len(0x111));
  3760. return 1;
  3761. }
  3762. int clif_deleteskill(struct map_session_data *sd, int id)
  3763. {
  3764. #if PACKETVER >= 20081217
  3765. int fd;
  3766. nullpo_ret(sd);
  3767. fd = sd->fd;
  3768. if( !fd ) return 0;
  3769. WFIFOHEAD(fd,packet_len(0x441));
  3770. WFIFOW(fd,0) = 0x441;
  3771. WFIFOW(fd,2) = id;
  3772. WFIFOSET(fd,packet_len(0x441));
  3773. return 1;
  3774. #else
  3775. return clif_skillinfoblock(sd);
  3776. #endif
  3777. }
  3778. /*==========================================
  3779. * スキル割り振り通知
  3780. *------------------------------------------*/
  3781. int clif_skillup(struct map_session_data *sd,int skill_num)
  3782. {
  3783. int fd;
  3784. nullpo_ret(sd);
  3785. fd=sd->fd;
  3786. WFIFOHEAD(fd,packet_len(0x10e));
  3787. WFIFOW(fd,0) = 0x10e;
  3788. WFIFOW(fd,2) = skill_num;
  3789. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3790. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3791. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3792. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3793. WFIFOSET(fd,packet_len(0x10e));
  3794. return 0;
  3795. }
  3796. /*==========================================
  3797. * スキル詠唱エフェクトを送信する
  3798. * pl:
  3799. * 0 = Yellow cast aura
  3800. * 1 = Water elemental cast aura
  3801. * 2 = Earth elemental cast aura
  3802. * 3 = Fire elemental cast aura
  3803. * 4 = Wind elemental cast aura
  3804. * 5 = Poison elemental cast aura
  3805. * 6 = White cast aura
  3806. * ? = like 0
  3807. *------------------------------------------*/
  3808. int clif_skillcasting(struct block_list* bl,
  3809. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int pl, int casttime)
  3810. {
  3811. unsigned char buf[32];
  3812. WBUFW(buf,0) = 0x13e;
  3813. WBUFL(buf,2) = src_id;
  3814. WBUFL(buf,6) = dst_id;
  3815. WBUFW(buf,10) = dst_x;
  3816. WBUFW(buf,12) = dst_y;
  3817. WBUFW(buf,14) = skill_num;
  3818. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3819. WBUFL(buf,20) = casttime;
  3820. if (disguised(bl)) {
  3821. clif_send(buf,packet_len(0x13e), bl, AREA_WOS);
  3822. WBUFL(buf,2) = -src_id;
  3823. clif_send(buf,packet_len(0x13e), bl, SELF);
  3824. } else
  3825. clif_send(buf,packet_len(0x13e), bl, AREA);
  3826. return 0;
  3827. }
  3828. /*==========================================
  3829. *
  3830. *------------------------------------------*/
  3831. int clif_skillcastcancel(struct block_list* bl)
  3832. {
  3833. unsigned char buf[16];
  3834. nullpo_ret(bl);
  3835. WBUFW(buf,0) = 0x1b9;
  3836. WBUFL(buf,2) = bl->id;
  3837. clif_send(buf,packet_len(0x1b9), bl, AREA);
  3838. return 0;
  3839. }
  3840. /// only when type==0:
  3841. /// if(skill_id==NV_BASIC)
  3842. /// btype==0 "skill failed" MsgStringTable[159]
  3843. /// btype==1 "no emotions" MsgStringTable[160]
  3844. /// btype==2 "no sit" MsgStringTable[161]
  3845. /// btype==3 "no chat" MsgStringTable[162]
  3846. /// btype==4 "no party" MsgStringTable[163]
  3847. /// btype==5 "no shout" MsgStringTable[164]
  3848. /// btype==6 "no PKing" MsgStringTable[165]
  3849. /// btype==7 "no alligning" MsgStringTable[383]
  3850. /// btype>=8: ignored
  3851. /// if(skill_id==AL_WARP) "not enough skill level" MsgStringTable[214]
  3852. /// if(skill_id==TF_STEAL) "steal failed" MsgStringTable[205]
  3853. /// if(skill_id==TF_POISON) "envenom failed" MsgStringTable[207]
  3854. /// otherwise "skill failed" MsgStringTable[204]
  3855. /// btype irrelevant
  3856. /// type==1 "insufficient SP" MsgStringTable[202]
  3857. /// type==2 "insufficient HP" MsgStringTable[203]
  3858. /// type==3 "insufficient materials" MsgStringTable[808]
  3859. /// type==4 "there is a delay after using a skill" MsgStringTable[219]
  3860. /// type==5 "insufficient zeny" MsgStringTable[233]
  3861. /// type==6 "wrong weapon" MsgStringTable[239]
  3862. /// type==7 "red gemstone needed" MsgStringTable[246]
  3863. /// type==8 "blue gemstone needed" MsgStringTable[247]
  3864. /// type==9 "overweight" MsgStringTable[580]
  3865. /// type==10 "skill failed" MsgStringTable[285]
  3866. /// type>=11 ignored
  3867. ///
  3868. /// if(success!=0) doesn't display any of the previous messages
  3869. /// Note: when this packet is received an unknown flag is always set to 0,
  3870. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  3871. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3872. {
  3873. int fd;
  3874. if (!sd) { //Since this is the most common nullpo....
  3875. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3876. return 0;
  3877. }
  3878. fd=sd->fd;
  3879. if (!fd) return 0;
  3880. if(battle_config.display_skill_fail&1)
  3881. return 0; //Disable all skill failed messages
  3882. if(type==0x4 && !sd->state.showdelay)
  3883. return 0; //Disable delay failed messages
  3884. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3885. return 0;
  3886. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3887. return 0;
  3888. WFIFOHEAD(fd,packet_len(0x110));
  3889. WFIFOW(fd,0) = 0x110;
  3890. WFIFOW(fd,2) = skill_id;
  3891. WFIFOL(fd,4) = btype;
  3892. WFIFOB(fd,8) = 0;// success?
  3893. WFIFOB(fd,9) = type;
  3894. WFIFOSET(fd,packet_len(0x110));
  3895. return 1;
  3896. }
  3897. /*==========================================
  3898. * skill cooldown display icon
  3899. * R 043d <skill ID>.w <tick>.l
  3900. *------------------------------------------*/
  3901. int clif_skill_cooldown(struct map_session_data *sd, int skillid, unsigned int tick)
  3902. {
  3903. #if PACKETVER>=20081112
  3904. int fd;
  3905. nullpo_ret(sd);
  3906. fd=sd->fd;
  3907. WFIFOHEAD(fd,packet_len(0x043d));
  3908. WFIFOW(fd,0) = 0x043d;
  3909. WFIFOW(fd,2) = skillid;
  3910. WFIFOL(fd,4) = tick;
  3911. WFIFOSET(fd,packet_len(0x043d));
  3912. #endif
  3913. return 0;
  3914. }
  3915. /*==========================================
  3916. * skill attack effect and damage
  3917. * 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
  3918. *------------------------------------------*/
  3919. 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)
  3920. {
  3921. unsigned char buf[64];
  3922. struct status_change *sc;
  3923. nullpo_ret(src);
  3924. nullpo_ret(dst);
  3925. type = clif_calc_delay(type,div,damage,ddelay);
  3926. sc = status_get_sc(dst);
  3927. if(sc && sc->count) {
  3928. if(sc->data[SC_HALLUCINATION] && damage)
  3929. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3930. }
  3931. #if PACKETVER < 3
  3932. WBUFW(buf,0)=0x114;
  3933. WBUFW(buf,2)=skill_id;
  3934. WBUFL(buf,4)=src->id;
  3935. WBUFL(buf,8)=dst->id;
  3936. WBUFL(buf,12)=tick;
  3937. WBUFL(buf,16)=sdelay;
  3938. WBUFL(buf,20)=ddelay;
  3939. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3940. WBUFW(buf,24)=damage?div:0;
  3941. } else {
  3942. WBUFW(buf,24)=damage;
  3943. }
  3944. WBUFW(buf,26)=skill_lv;
  3945. WBUFW(buf,28)=div;
  3946. WBUFB(buf,30)=type;
  3947. if (disguised(dst)) {
  3948. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  3949. WBUFL(buf,8)=-dst->id;
  3950. clif_send(buf,packet_len(0x114),dst,SELF);
  3951. } else
  3952. clif_send(buf,packet_len(0x114),dst,AREA);
  3953. if(disguised(src)) {
  3954. WBUFL(buf,4)=-src->id;
  3955. if (disguised(dst))
  3956. WBUFL(buf,8)=dst->id;
  3957. if(damage > 0)
  3958. WBUFW(buf,24)=-1;
  3959. clif_send(buf,packet_len(0x114),src,SELF);
  3960. }
  3961. #else
  3962. WBUFW(buf,0)=0x1de;
  3963. WBUFW(buf,2)=skill_id;
  3964. WBUFL(buf,4)=src->id;
  3965. WBUFL(buf,8)=dst->id;
  3966. WBUFL(buf,12)=tick;
  3967. WBUFL(buf,16)=sdelay;
  3968. WBUFL(buf,20)=ddelay;
  3969. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3970. WBUFL(buf,24)=damage?div:0;
  3971. } else {
  3972. WBUFL(buf,24)=damage;
  3973. }
  3974. WBUFW(buf,28)=skill_lv;
  3975. WBUFW(buf,30)=div;
  3976. WBUFB(buf,32)=type;
  3977. if (disguised(dst)) {
  3978. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  3979. WBUFL(buf,8)=-dst->id;
  3980. clif_send(buf,packet_len(0x1de),dst,SELF);
  3981. } else
  3982. clif_send(buf,packet_len(0x1de),dst,AREA);
  3983. if(disguised(src)) {
  3984. WBUFL(buf,4)=-src->id;
  3985. if (disguised(dst))
  3986. WBUFL(buf,8)=dst->id;
  3987. if(damage > 0)
  3988. WBUFL(buf,24)=-1;
  3989. clif_send(buf,packet_len(0x1de),src,SELF);
  3990. }
  3991. #endif
  3992. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3993. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3994. }
  3995. /*==========================================
  3996. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3997. *------------------------------------------*/
  3998. /*
  3999. 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)
  4000. {
  4001. unsigned char buf[64];
  4002. struct status_change *sc;
  4003. nullpo_ret(src);
  4004. nullpo_ret(dst);
  4005. type = (type>0)?type:skill_get_hit(skill_id);
  4006. type = clif_calc_delay(type,div,damage,ddelay);
  4007. sc = status_get_sc(dst);
  4008. if(sc && sc->count) {
  4009. if(sc->data[SC_HALLUCINATION] && damage)
  4010. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  4011. }
  4012. WBUFW(buf,0)=0x115;
  4013. WBUFW(buf,2)=skill_id;
  4014. WBUFL(buf,4)=src->id;
  4015. WBUFL(buf,8)=dst->id;
  4016. WBUFL(buf,12)=tick;
  4017. WBUFL(buf,16)=sdelay;
  4018. WBUFL(buf,20)=ddelay;
  4019. WBUFW(buf,24)=dst->x;
  4020. WBUFW(buf,26)=dst->y;
  4021. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  4022. WBUFW(buf,28)=damage?div:0;
  4023. } else {
  4024. WBUFW(buf,28)=damage;
  4025. }
  4026. WBUFW(buf,30)=skill_lv;
  4027. WBUFW(buf,32)=div;
  4028. WBUFB(buf,34)=type;
  4029. clif_send(buf,packet_len(0x115),src,AREA);
  4030. if(disguised(src)) {
  4031. WBUFL(buf,4)=-src->id;
  4032. if(damage > 0)
  4033. WBUFW(buf,28)=-1;
  4034. clif_send(buf,packet_len(0x115),src,SELF);
  4035. }
  4036. if (disguised(dst)) {
  4037. WBUFL(buf,8)=-dst->id;
  4038. if (disguised(src))
  4039. WBUFL(buf,4)=src->id;
  4040. else if(damage > 0)
  4041. WBUFW(buf,28)=-1;
  4042. clif_send(buf,packet_len(0x115),dst,SELF);
  4043. }
  4044. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  4045. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  4046. }
  4047. */
  4048. /*==========================================
  4049. * 支援/回復スキルエフェクト
  4050. *------------------------------------------*/
  4051. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_id,int heal,int fail)
  4052. {
  4053. unsigned char buf[32];
  4054. nullpo_ret(dst);
  4055. WBUFW(buf,0)=0x11a;
  4056. WBUFW(buf,2)=skill_id;
  4057. WBUFW(buf,4)=min(heal, SHRT_MAX);
  4058. WBUFL(buf,6)=dst->id;
  4059. WBUFL(buf,10)=src?src->id:0;
  4060. WBUFB(buf,14)=fail;
  4061. if (disguised(dst)) {
  4062. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  4063. WBUFL(buf,6)=-dst->id;
  4064. clif_send(buf,packet_len(0x11a),dst,SELF);
  4065. } else
  4066. clif_send(buf,packet_len(0x11a),dst,AREA);
  4067. if(src && disguised(src)) {
  4068. WBUFL(buf,10)=-src->id;
  4069. if (disguised(dst))
  4070. WBUFL(buf,6)=dst->id;
  4071. clif_send(buf,packet_len(0x11a),src,SELF);
  4072. }
  4073. return fail;
  4074. }
  4075. /*==========================================
  4076. * 場所スキルエフェクト
  4077. *------------------------------------------*/
  4078. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  4079. {
  4080. unsigned char buf[32];
  4081. nullpo_ret(src);
  4082. WBUFW(buf,0)=0x117;
  4083. WBUFW(buf,2)=skill_id;
  4084. WBUFL(buf,4)=src->id;
  4085. WBUFW(buf,8)=val;
  4086. WBUFW(buf,10)=x;
  4087. WBUFW(buf,12)=y;
  4088. WBUFL(buf,14)=tick;
  4089. if(disguised(src)) {
  4090. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  4091. WBUFL(buf,4)=-src->id;
  4092. clif_send(buf,packet_len(0x117),src,SELF);
  4093. } else
  4094. clif_send(buf,packet_len(0x117),src,AREA);
  4095. return 0;
  4096. }
  4097. /*==========================================
  4098. * 場所スキルエフェクト表示
  4099. *------------------------------------------*/
  4100. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  4101. void clif_skill_setunit(struct skill_unit *unit)
  4102. {
  4103. unsigned char buf[128];
  4104. nullpo_retv(unit);
  4105. #if PACKETVER >= 3
  4106. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4107. WBUFW(buf, 0)=0x1c9;
  4108. WBUFL(buf, 2)=unit->bl.id;
  4109. WBUFL(buf, 6)=unit->group->src_id;
  4110. WBUFW(buf,10)=unit->bl.x;
  4111. WBUFW(buf,12)=unit->bl.y;
  4112. WBUFB(buf,14)=unit->group->unit_id;
  4113. WBUFB(buf,15)=1;
  4114. WBUFB(buf,16)=1;
  4115. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4116. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4117. return;
  4118. }
  4119. #endif
  4120. WBUFW(buf, 0)=0x11f;
  4121. WBUFL(buf, 2)=unit->bl.id;
  4122. WBUFL(buf, 6)=unit->group->src_id;
  4123. WBUFW(buf,10)=unit->bl.x;
  4124. WBUFW(buf,12)=unit->bl.y;
  4125. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4126. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4127. else
  4128. WBUFB(buf,14)=unit->group->unit_id;
  4129. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  4130. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4131. }
  4132. /*==========================================
  4133. * ワープ場所選択
  4134. *------------------------------------------*/
  4135. 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)
  4136. {
  4137. int fd;
  4138. nullpo_retv(sd);
  4139. fd = sd->fd;
  4140. WFIFOHEAD(fd,packet_len(0x11c));
  4141. WFIFOW(fd,0) = 0x11c;
  4142. WFIFOW(fd,2) = skill_num;
  4143. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4144. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4145. else // normal map name
  4146. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4147. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4148. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4149. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4150. WFIFOSET(fd,packet_len(0x11c));
  4151. sd->menuskill_id = skill_num;
  4152. if (skill_num == AL_WARP)
  4153. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4154. else
  4155. sd->menuskill_val = skill_lv;
  4156. }
  4157. /// Memo message.
  4158. /// type=0 : "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  4159. /// type=1 : "Skill Level is not high enough." in color 0x0000FF (red)
  4160. /// type=2 : "You haven't learned Warp." in color 0x0000FF (red)
  4161. ///
  4162. /// @param sd Who receives the message
  4163. /// @param type What message
  4164. void clif_skill_memomessage(struct map_session_data* sd, int type)
  4165. {
  4166. int fd;
  4167. nullpo_retv(sd);
  4168. fd=sd->fd;
  4169. WFIFOHEAD(fd,packet_len(0x11e));
  4170. WFIFOW(fd,0)=0x11e;
  4171. WFIFOB(fd,2)=type;
  4172. WFIFOSET(fd,packet_len(0x11e));
  4173. }
  4174. /// Teleport message.
  4175. /// type=0 : "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  4176. /// type=1 : "Saved point cannot be memorized." in color 0x0000FF (red)
  4177. ///
  4178. /// @param sd Who receives the message
  4179. /// @param type What message
  4180. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  4181. {
  4182. int fd;
  4183. nullpo_retv(sd);
  4184. fd=sd->fd;
  4185. WFIFOHEAD(fd,packet_len(0x189));
  4186. WFIFOW(fd,0)=0x189;
  4187. WFIFOW(fd,2)=type;
  4188. WFIFOSET(fd,packet_len(0x189));
  4189. }
  4190. /*==========================================
  4191. * モンスター情報
  4192. *------------------------------------------*/
  4193. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4194. {
  4195. struct status_data *status;
  4196. unsigned char buf[64];
  4197. int i;//, fix;
  4198. nullpo_ret(sd);
  4199. nullpo_ret(dst);
  4200. if( dst->type != BL_MOB )
  4201. return 0;
  4202. status = status_get_status_data(dst);
  4203. WBUFW(buf, 0)=0x18c;
  4204. WBUFW(buf, 2)=status_get_class(dst);
  4205. WBUFW(buf, 4)=status_get_lv(dst);
  4206. WBUFW(buf, 6)=status->size;
  4207. WBUFL(buf, 8)=status->hp;
  4208. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4209. +(battle_config.estimation_type&2?status->def2:0);
  4210. WBUFW(buf,14)=status->race;
  4211. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4212. +(battle_config.estimation_type&2?status->mdef2:0);
  4213. WBUFW(buf,18)= status->def_ele;
  4214. for(i=0;i<9;i++)
  4215. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  4216. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4217. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4218. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4219. return 0;
  4220. }
  4221. /*==========================================
  4222. * アイテム合成可能リスト
  4223. *------------------------------------------*/
  4224. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  4225. {
  4226. int i,c,view,fd;
  4227. nullpo_ret(sd);
  4228. if(sd->menuskill_id == AM_PHARMACY)
  4229. return 0; //Avoid resending the menu twice or more times...
  4230. fd=sd->fd;
  4231. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4232. WFIFOW(fd, 0)=0x18d;
  4233. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4234. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4235. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4236. WFIFOW(fd,c*8+ 4)= view;
  4237. else
  4238. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4239. WFIFOW(fd,c*8+ 6)= 0x0012;
  4240. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  4241. c++;
  4242. }
  4243. }
  4244. WFIFOW(fd, 2)=c*8+8;
  4245. WFIFOSET(fd,WFIFOW(fd,2));
  4246. if(c > 0) {
  4247. sd->menuskill_id = AM_PHARMACY;
  4248. sd->menuskill_val = trigger;
  4249. return 1;
  4250. }
  4251. return 0;
  4252. }
  4253. /*==========================================
  4254. *
  4255. *------------------------------------------*/
  4256. void clif_cooking_list(struct map_session_data *sd, int trigger)
  4257. {
  4258. int fd;
  4259. int i, c;
  4260. int view;
  4261. nullpo_retv(sd);
  4262. fd = sd->fd;
  4263. WFIFOHEAD(fd, 6 + 2*MAX_SKILL_PRODUCE_DB);
  4264. WFIFOW(fd,0) = 0x25a;
  4265. WFIFOW(fd,4) = 1; // list type
  4266. c = 0;
  4267. for( i = 0; i < MAX_SKILL_PRODUCE_DB; i++ )
  4268. {
  4269. if( !skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) )
  4270. continue;
  4271. if( (view = itemdb_viewid(skill_produce_db[i].nameid)) > 0 )
  4272. WFIFOW(fd, 6+2*c)= view;
  4273. else
  4274. WFIFOW(fd, 6+2*c)= skill_produce_db[i].nameid;
  4275. c++;
  4276. }
  4277. WFIFOW(fd,2) = 6 + 2*c;
  4278. WFIFOSET(fd,WFIFOW(fd,2));
  4279. //TODO: replace with proper solution
  4280. if( c > 0 )
  4281. {
  4282. sd->menuskill_id = AM_PHARMACY;
  4283. sd->menuskill_val = trigger;
  4284. }
  4285. }
  4286. /*==========================================
  4287. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  4288. *------------------------------------------*/
  4289. int clif_status_load(struct block_list *bl,int type, int flag)
  4290. {
  4291. int fd;
  4292. if (type == SI_BLANK) //It shows nothing on the client...
  4293. return 0;
  4294. if (bl->type != BL_PC)
  4295. return 0;
  4296. fd = ((struct map_session_data*)bl)->fd;
  4297. WFIFOHEAD(fd,packet_len(0x196));
  4298. WFIFOW(fd,0)=0x0196;
  4299. WFIFOW(fd,2)=type;
  4300. WFIFOL(fd,4)=bl->id;
  4301. WFIFOB(fd,8)=flag; //Status start
  4302. WFIFOSET(fd, packet_len(0x196));
  4303. return 0;
  4304. }
  4305. /*==========================================
  4306. * 状態異常アイコン/メッセージ表示
  4307. *------------------------------------------*/
  4308. int clif_status_change(struct block_list *bl,int type,int flag,unsigned int tick)
  4309. {
  4310. unsigned char buf[32];
  4311. if (type == SI_BLANK) //It shows nothing on the client...
  4312. return 0;
  4313. nullpo_ret(bl);
  4314. if (type == SI_BLANK || type == SI_MAXIMIZEPOWER || type == SI_RIDING ||
  4315. type == SI_FALCON || type == SI_TRICKDEAD || type == SI_BROKENARMOR ||
  4316. type == SI_BROKENWEAPON || type == SI_WEIGHT50 || type == SI_WEIGHT90 ||
  4317. type == SI_TENSIONRELAX || type == SI_LANDENDOW || type == SI_AUTOBERSERK ||
  4318. type == SI_BUMP || type == SI_READYSTORM || type == SI_READYDOWN ||
  4319. type == SI_READYTURN || type == SI_READYCOUNTER || type == SI_DODGE ||
  4320. type == SI_DEVIL || type == SI_NIGHT || type == SI_INTRAVISION)
  4321. tick=0;
  4322. if( battle_config.display_status_timers && tick>0 )
  4323. WBUFW(buf,0)=0x043f;
  4324. else
  4325. WBUFW(buf,0)=0x0196;
  4326. WBUFW(buf,2)=type;
  4327. WBUFL(buf,4)=bl->id;
  4328. WBUFB(buf,8)=flag;
  4329. if( battle_config.display_status_timers && tick>0 )
  4330. {
  4331. WBUFL(buf,9)=tick;
  4332. WBUFL(buf,13)=0;
  4333. WBUFL(buf,17)=0;
  4334. WBUFL(buf,21)=0;
  4335. }
  4336. clif_send(buf,packet_len(WBUFW(buf,0)),bl,AREA);
  4337. return 0;
  4338. }
  4339. /*==========================================
  4340. * Send message (modified by [Yor])
  4341. *------------------------------------------*/
  4342. int clif_displaymessage(const int fd, const char* mes)
  4343. {
  4344. // invalid pointer?
  4345. nullpo_retr(-1, mes);
  4346. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4347. if (fd == 0)
  4348. return 0;
  4349. else {
  4350. int len_mes = strlen(mes);
  4351. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4352. WFIFOHEAD(fd, 5 + len_mes);
  4353. WFIFOW(fd,0) = 0x8e;
  4354. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  4355. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  4356. WFIFOSET(fd, 5 + len_mes);
  4357. }
  4358. }
  4359. return 0;
  4360. }
  4361. /*==========================================
  4362. * 天の声を送信する
  4363. * Send broadcast message in yellow or blue (without font formatting).
  4364. * S 009A <len>.W <message>.?B
  4365. *------------------------------------------*/
  4366. int clif_broadcast(struct block_list* bl, const char* mes, int len, int type, enum send_target target)
  4367. {
  4368. int lp = type ? 4 : 0;
  4369. unsigned char *buf = (unsigned char*)aMallocA((4 + lp + len)*sizeof(unsigned char));
  4370. WBUFW(buf,0) = 0x9a;
  4371. WBUFW(buf,2) = 4 + lp + len;
  4372. if (type == 0x10) // bc_blue
  4373. WBUFL(buf,4) = 0x65756c62; //If there's "blue" at the beginning of the message, game client will display it in blue instead of yellow.
  4374. else if (type == 0x20) // bc_woe
  4375. WBUFL(buf,4) = 0x73737373; //If there's "ssss", game client will recognize message as 'WoE broadcast'.
  4376. memcpy(WBUFP(buf, 4 + lp), mes, len);
  4377. clif_send(buf, WBUFW(buf,2), bl, target);
  4378. if (buf)
  4379. aFree(buf);
  4380. return 0;
  4381. }
  4382. /*==========================================
  4383. * グローバルメッセージ
  4384. *------------------------------------------*/
  4385. void clif_GlobalMessage(struct block_list* bl, const char* message)
  4386. {
  4387. char buf[100];
  4388. int len;
  4389. nullpo_retv(bl);
  4390. if(!message)
  4391. return;
  4392. len = strlen(message)+1;
  4393. WBUFW(buf,0)=0x8d;
  4394. WBUFW(buf,2)=len+8;
  4395. WBUFL(buf,4)=bl->id;
  4396. strncpy((char *) WBUFP(buf,8),message,len);
  4397. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4398. }
  4399. /*==========================================
  4400. * Send main chat message [LuzZza]
  4401. *------------------------------------------*/
  4402. void clif_MainChatMessage(const char* message)
  4403. {
  4404. char buf[200];
  4405. int len;
  4406. if(!message)
  4407. return;
  4408. len = strlen(message)+1;
  4409. if (len+8 > sizeof(buf)) {
  4410. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4411. len = sizeof(buf)-8;
  4412. }
  4413. WBUFW(buf,0)=0x8d;
  4414. WBUFW(buf,2)=len+8;
  4415. WBUFL(buf,4)=0;
  4416. strncpy((char *) WBUFP(buf,8),message,len);
  4417. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4418. }
  4419. /*==========================================
  4420. * Send broadcast message with font formatting.
  4421. * S 01C3 <len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  4422. * S 040C <len>.W <fontColor>.L <fontType>.W <fontSize>.W <fontAlign>.W <fontY>.W <message>.?B
  4423. *------------------------------------------*/
  4424. int clif_broadcast2(struct block_list* bl, const char* mes, int len, unsigned long fontColor, short fontType, short fontSize, short fontAlign, short fontY, enum send_target target)
  4425. {
  4426. unsigned char *buf = (unsigned char*)aMallocA((16 + len)*sizeof(unsigned char));
  4427. #if PACKETVER < 20080820
  4428. WBUFW(buf,0) = 0x1c3;
  4429. #else
  4430. WBUFW(buf,0) = 0x40c;
  4431. #endif
  4432. WBUFW(buf,2) = len + 16;
  4433. WBUFL(buf,4) = fontColor;
  4434. WBUFW(buf,8) = fontType;
  4435. WBUFW(buf,10) = fontSize;
  4436. WBUFW(buf,12) = fontAlign;
  4437. WBUFW(buf,14) = fontY;
  4438. memcpy(WBUFP(buf,16), mes, len);
  4439. clif_send(buf, WBUFW(buf,2), bl, target);
  4440. if (buf)
  4441. aFree(buf);
  4442. return 0;
  4443. }
  4444. /*==========================================
  4445. * HPSP回復エフェクトを送信する
  4446. *------------------------------------------*/
  4447. int clif_heal(int fd,int type,int val)
  4448. {
  4449. WFIFOHEAD(fd,packet_len(0x13d));
  4450. WFIFOW(fd,0)=0x13d;
  4451. WFIFOW(fd,2)=type;
  4452. WFIFOW(fd,4)=cap_value(val,0,SHRT_MAX);
  4453. WFIFOSET(fd,packet_len(0x13d));
  4454. return 0;
  4455. }
  4456. /*==========================================
  4457. * 復活する
  4458. *------------------------------------------*/
  4459. int clif_resurrection(struct block_list *bl,int type)
  4460. {
  4461. unsigned char buf[16];
  4462. nullpo_ret(bl);
  4463. WBUFW(buf,0)=0x148;
  4464. WBUFL(buf,2)=bl->id;
  4465. WBUFW(buf,6)=type;
  4466. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4467. if (disguised(bl))
  4468. clif_spawn(bl);
  4469. return 0;
  4470. }
  4471. /// Sets the map mode.
  4472. ///
  4473. /// mode=1 : pvp mode
  4474. /// mode=2 : unknown mode (pk?)
  4475. /// mode=3 : gvg mode
  4476. /// mode=4 : message "You are in a PK area. Please beware of sudden attacks." in color 0x9B9BFF (light red)
  4477. /// mode=5 : pvp mode
  4478. /// mode=other : ?
  4479. void clif_set0199(struct map_session_data* sd, int mode)
  4480. {
  4481. int fd;
  4482. nullpo_retv(sd);
  4483. fd=sd->fd;
  4484. WFIFOHEAD(fd,packet_len(0x199));
  4485. WFIFOW(fd,0)=0x199;
  4486. WFIFOW(fd,2)=mode;
  4487. WFIFOSET(fd,packet_len(0x199));
  4488. }
  4489. /// Set the map mode (special)
  4490. /// 19 = battleground
  4491. void clif_set01D6(struct map_session_data* sd, int mode)
  4492. {
  4493. int fd;
  4494. nullpo_retv(sd);
  4495. fd=sd->fd;
  4496. WFIFOHEAD(fd,packet_len(0x1D6));
  4497. WFIFOW(fd,0)=0x1D6;
  4498. WFIFOW(fd,2)=mode;
  4499. WFIFOSET(fd,packet_len(0x1D6));
  4500. }
  4501. /*==========================================
  4502. * PVP実装?(仮)
  4503. *------------------------------------------*/
  4504. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4505. {
  4506. if(type == 2) {
  4507. int fd = sd->fd;
  4508. WFIFOHEAD(fd,packet_len(0x19a));
  4509. WFIFOW(fd,0) = 0x19a;
  4510. WFIFOL(fd,2) = sd->bl.id;
  4511. WFIFOL(fd,6) = pvprank;
  4512. WFIFOL(fd,10) = pvpnum;
  4513. WFIFOSET(fd,packet_len(0x19a));
  4514. } else {
  4515. unsigned char buf[32];
  4516. WBUFW(buf,0) = 0x19a;
  4517. WBUFL(buf,2) = sd->bl.id;
  4518. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4519. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4520. else
  4521. WBUFL(buf,6) = pvprank;
  4522. WBUFL(buf,10) = pvpnum;
  4523. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  4524. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4525. else if(!type)
  4526. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4527. else
  4528. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4529. }
  4530. return 0;
  4531. }
  4532. /*==========================================
  4533. *
  4534. *------------------------------------------*/
  4535. int clif_send0199(int map,int type)
  4536. {
  4537. struct block_list bl;
  4538. unsigned char buf[16];
  4539. bl.id = 0;
  4540. bl.type = BL_NUL;
  4541. bl.m = map;
  4542. WBUFW(buf,0)=0x199;
  4543. WBUFW(buf,2)=type;
  4544. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4545. return 0;
  4546. }
  4547. /*==========================================
  4548. * 精錬エフェクトを送信する
  4549. *------------------------------------------*/
  4550. void clif_refine(int fd, int fail, int index, int val)
  4551. {
  4552. WFIFOHEAD(fd,packet_len(0x188));
  4553. WFIFOW(fd,0)=0x188;
  4554. WFIFOW(fd,2)=fail;
  4555. WFIFOW(fd,4)=index+2;
  4556. WFIFOW(fd,6)=val;
  4557. WFIFOSET(fd,packet_len(0x188));
  4558. }
  4559. /// result=0: "weapon upgrated: %s" MsgStringTable[911] in rgb(0,255,255)
  4560. /// result=1: "weapon upgrated: %s" MsgStringTable[912] in rgb(0,205,205)
  4561. /// result=2: "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4562. /// result=3: "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4563. void clif_upgrademessage(int fd, int result, int item_id)
  4564. {
  4565. WFIFOHEAD(fd,packet_len(0x223));
  4566. WFIFOW(fd,0)=0x223;
  4567. WFIFOL(fd,2)=result;
  4568. WFIFOW(fd,6)=item_id;
  4569. WFIFOSET(fd,packet_len(0x223));
  4570. }
  4571. /*==========================================
  4572. * Wisp/page is transmitted to the destination player
  4573. * R 0097 <len>.w <nick>.24B <message>.?B
  4574. * R 0097 <len>.w <nick>.24B <???>.L <message>.?B
  4575. *------------------------------------------*/
  4576. int clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4577. {
  4578. #if PACKETVER < 20091104
  4579. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4580. WFIFOW(fd,0) = 0x97;
  4581. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4582. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4583. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  4584. WFIFOSET(fd,WFIFOW(fd,2));
  4585. #else
  4586. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 8);
  4587. WFIFOW(fd,0) = 0x97;
  4588. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 8;
  4589. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4590. WFIFOL(fd,28) = 0; // unknown; if nonzero, also displays text above char
  4591. safestrncpy((char*)WFIFOP(fd,32), mes, mes_len);
  4592. WFIFOSET(fd,WFIFOW(fd,2));
  4593. #endif
  4594. return 0;
  4595. }
  4596. /*==========================================
  4597. * Inform the player about the result of his whisper action
  4598. * R 0098 <type>.B
  4599. * 0: success to send wisper
  4600. * 1: target character is not loged in
  4601. * 2: ignored by target
  4602. * 3: everyone ignored by target
  4603. *------------------------------------------*/
  4604. int clif_wis_end(int fd, int flag)
  4605. {
  4606. WFIFOHEAD(fd,packet_len(0x98));
  4607. WFIFOW(fd,0) = 0x98;
  4608. WFIFOW(fd,2) = flag;
  4609. WFIFOSET(fd,packet_len(0x98));
  4610. return 0;
  4611. }
  4612. /*==========================================
  4613. * キャラID名前引き結果を送信する
  4614. *------------------------------------------*/
  4615. int clif_solved_charname(int fd, int charid, const char* name)
  4616. {
  4617. WFIFOHEAD(fd,packet_len(0x194));
  4618. WFIFOW(fd,0)=0x194;
  4619. WFIFOL(fd,2)=charid;
  4620. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  4621. WFIFOSET(fd,packet_len(0x194));
  4622. return 0;
  4623. }
  4624. /*==========================================
  4625. * カードの挿入可能リストを返す
  4626. *------------------------------------------*/
  4627. int clif_use_card(struct map_session_data *sd,int idx)
  4628. {
  4629. int i,c,ep;
  4630. int fd=sd->fd;
  4631. nullpo_ret(sd);
  4632. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4633. return 0;
  4634. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4635. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4636. ep=sd->inventory_data[idx]->equip;
  4637. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4638. WFIFOW(fd,0)=0x017b;
  4639. for(i=c=0;i<MAX_INVENTORY;i++){
  4640. int j;
  4641. if(sd->inventory_data[i] == NULL)
  4642. continue;
  4643. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4644. continue;
  4645. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4646. continue;
  4647. if(sd->status.inventory[i].identify==0 ) //Not identified
  4648. continue;
  4649. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4650. continue;
  4651. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  4652. continue;
  4653. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  4654. if( j == sd->inventory_data[i]->slot ) // No room
  4655. continue;
  4656. WFIFOW(fd,4+c*2)=i+2;
  4657. c++;
  4658. }
  4659. WFIFOW(fd,2)=4+c*2;
  4660. WFIFOSET(fd,WFIFOW(fd,2));
  4661. return 0;
  4662. }
  4663. /*==========================================
  4664. * カードの挿入終了
  4665. *------------------------------------------*/
  4666. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4667. {
  4668. int fd;
  4669. nullpo_ret(sd);
  4670. fd=sd->fd;
  4671. WFIFOHEAD(fd,packet_len(0x17d));
  4672. WFIFOW(fd,0)=0x17d;
  4673. WFIFOW(fd,2)=idx_equip+2;
  4674. WFIFOW(fd,4)=idx_card+2;
  4675. WFIFOB(fd,6)=flag;
  4676. WFIFOSET(fd,packet_len(0x17d));
  4677. return 0;
  4678. }
  4679. /*==========================================
  4680. * 鑑定可能アイテムリスト送信
  4681. *------------------------------------------*/
  4682. int clif_item_identify_list(struct map_session_data *sd)
  4683. {
  4684. int i,c;
  4685. int fd;
  4686. nullpo_ret(sd);
  4687. fd=sd->fd;
  4688. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4689. WFIFOW(fd,0)=0x177;
  4690. for(i=c=0;i<MAX_INVENTORY;i++){
  4691. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4692. WFIFOW(fd,c*2+4)=i+2;
  4693. c++;
  4694. }
  4695. }
  4696. if(c > 0) {
  4697. WFIFOW(fd,2)=c*2+4;
  4698. WFIFOSET(fd,WFIFOW(fd,2));
  4699. sd->menuskill_id = MC_IDENTIFY;
  4700. sd->menuskill_val = c;
  4701. }
  4702. return 0;
  4703. }
  4704. /*==========================================
  4705. * 鑑定結果
  4706. *------------------------------------------*/
  4707. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4708. {
  4709. int fd;
  4710. nullpo_ret(sd);
  4711. fd=sd->fd;
  4712. WFIFOHEAD(fd,packet_len(0x179));
  4713. WFIFOW(fd, 0)=0x179;
  4714. WFIFOW(fd, 2)=idx+2;
  4715. WFIFOB(fd, 4)=flag;
  4716. WFIFOSET(fd,packet_len(0x179));
  4717. return 0;
  4718. }
  4719. /*==========================================
  4720. * 修理可能アイテムリスト送信
  4721. *------------------------------------------*/
  4722. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4723. {
  4724. int i,c;
  4725. int fd;
  4726. int nameid;
  4727. nullpo_ret(sd);
  4728. nullpo_ret(dstsd);
  4729. fd=sd->fd;
  4730. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4731. WFIFOW(fd,0)=0x1fc;
  4732. for(i=c=0;i<MAX_INVENTORY;i++){
  4733. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4734. WFIFOW(fd,c*13+4) = i;
  4735. WFIFOW(fd,c*13+6) = nameid;
  4736. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4737. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4738. WFIFOB(fd,c*13+16)= c;
  4739. c++;
  4740. }
  4741. }
  4742. if(c > 0) {
  4743. WFIFOW(fd,2)=c*13+4;
  4744. WFIFOSET(fd,WFIFOW(fd,2));
  4745. sd->menuskill_id = BS_REPAIRWEAPON;
  4746. sd->menuskill_val = dstsd->bl.id;
  4747. }else
  4748. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4749. return 0;
  4750. }
  4751. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4752. {
  4753. int view,fd;
  4754. nullpo_ret(sd);
  4755. fd=sd->fd;
  4756. WFIFOHEAD(fd,packet_len(0x1fe));
  4757. WFIFOW(fd, 0)=0x1fe;
  4758. if((view = itemdb_viewid(nameid)) > 0)
  4759. WFIFOW(fd, 2)=view;
  4760. else
  4761. WFIFOW(fd, 2)=nameid;
  4762. WFIFOB(fd, 4)=flag;
  4763. WFIFOSET(fd,packet_len(0x1fe));
  4764. return 0;
  4765. }
  4766. /*==========================================
  4767. * Weapon Refining - Taken from jAthena
  4768. *------------------------------------------*/
  4769. int clif_item_refine_list(struct map_session_data *sd)
  4770. {
  4771. int i,c;
  4772. int fd;
  4773. int skilllv;
  4774. int wlv;
  4775. int refine_item[5];
  4776. nullpo_ret(sd);
  4777. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4778. fd=sd->fd;
  4779. refine_item[0] = -1;
  4780. refine_item[1] = pc_search_inventory(sd,1010);
  4781. refine_item[2] = pc_search_inventory(sd,1011);
  4782. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4783. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4784. WFIFOW(fd,0)=0x221;
  4785. for(i=c=0;i<MAX_INVENTORY;i++){
  4786. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4787. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4788. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4789. WFIFOW(fd,c*13+ 4)=i+2;
  4790. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4791. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4792. WFIFOW(fd,c*13+10)=0;
  4793. WFIFOB(fd,c*13+12)=c;
  4794. c++;
  4795. }
  4796. }
  4797. WFIFOW(fd,2)=c*13+4;
  4798. WFIFOSET(fd,WFIFOW(fd,2));
  4799. if (c > 0) {
  4800. sd->menuskill_id = WS_WEAPONREFINE;
  4801. sd->menuskill_val = skilllv;
  4802. }
  4803. return 0;
  4804. }
  4805. /*==========================================
  4806. * アイテムによる一時的なスキル効果
  4807. *------------------------------------------*/
  4808. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  4809. {
  4810. int fd;
  4811. nullpo_ret(sd);
  4812. fd=sd->fd;
  4813. WFIFOHEAD(fd,packet_len(0x147));
  4814. WFIFOW(fd, 0)=0x147;
  4815. WFIFOW(fd, 2)=skillid;
  4816. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4817. WFIFOW(fd, 6)=0;
  4818. WFIFOW(fd, 8)=skilllv;
  4819. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4820. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4821. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  4822. WFIFOB(fd,38)=0;
  4823. WFIFOSET(fd,packet_len(0x147));
  4824. return 0;
  4825. }
  4826. /*==========================================
  4827. * カートにアイテム追加
  4828. *------------------------------------------*/
  4829. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4830. {
  4831. int view,fd;
  4832. unsigned char *buf;
  4833. nullpo_ret(sd);
  4834. fd=sd->fd;
  4835. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4836. return 1;
  4837. #if PACKETVER < 5
  4838. WFIFOHEAD(fd,packet_len(0x124));
  4839. buf=WFIFOP(fd,0);
  4840. WBUFW(buf,0)=0x124;
  4841. WBUFW(buf,2)=n+2;
  4842. WBUFL(buf,4)=amount;
  4843. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4844. WBUFW(buf,8)=view;
  4845. else
  4846. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4847. WBUFB(buf,10)=sd->status.cart[n].identify;
  4848. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4849. WBUFB(buf,12)=sd->status.cart[n].refine;
  4850. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4851. WFIFOSET(fd,packet_len(0x124));
  4852. #else
  4853. WFIFOHEAD(fd,packet_len(0x1c5));
  4854. buf=WFIFOP(fd,0);
  4855. WBUFW(buf,0)=0x1c5;
  4856. WBUFW(buf,2)=n+2;
  4857. WBUFL(buf,4)=amount;
  4858. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4859. WBUFW(buf,8)=view;
  4860. else
  4861. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4862. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  4863. WBUFB(buf,11)=sd->status.cart[n].identify;
  4864. WBUFB(buf,12)=sd->status.cart[n].attribute;
  4865. WBUFB(buf,13)=sd->status.cart[n].refine;
  4866. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  4867. WFIFOSET(fd,packet_len(0x1c5));
  4868. #endif
  4869. return 0;
  4870. }
  4871. /*==========================================
  4872. * カートからアイテム削除
  4873. *------------------------------------------*/
  4874. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4875. {
  4876. int fd;
  4877. nullpo_ret(sd);
  4878. fd=sd->fd;
  4879. WFIFOHEAD(fd,packet_len(0x125));
  4880. WFIFOW(fd,0)=0x125;
  4881. WFIFOW(fd,2)=n+2;
  4882. WFIFOL(fd,4)=amount;
  4883. WFIFOSET(fd,packet_len(0x125));
  4884. return 0;
  4885. }
  4886. /*==========================================
  4887. * Opens the shop creation menu.
  4888. * R 012d <num>.w
  4889. * 'num' is the number of allowed item slots
  4890. *------------------------------------------*/
  4891. void clif_openvendingreq(struct map_session_data* sd, int num)
  4892. {
  4893. int fd;
  4894. nullpo_retv(sd);
  4895. fd = sd->fd;
  4896. WFIFOHEAD(fd,packet_len(0x12d));
  4897. WFIFOW(fd,0) = 0x12d;
  4898. WFIFOW(fd,2) = num;
  4899. WFIFOSET(fd,packet_len(0x12d));
  4900. }
  4901. /*==========================================
  4902. * Displays a vending board to target/area
  4903. * R 0131 <ID>.l <message>.80B
  4904. *------------------------------------------*/
  4905. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  4906. {
  4907. unsigned char buf[128];
  4908. nullpo_retv(bl);
  4909. WBUFW(buf,0) = 0x131;
  4910. WBUFL(buf,2) = bl->id;
  4911. safestrncpy((char*)WBUFP(buf,6), message, 80);
  4912. if( fd ) {
  4913. WFIFOHEAD(fd,packet_len(0x131));
  4914. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  4915. WFIFOSET(fd,packet_len(0x131));
  4916. } else {
  4917. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  4918. }
  4919. }
  4920. /*==========================================
  4921. * Removes a vending board from screen
  4922. *------------------------------------------*/
  4923. void clif_closevendingboard(struct block_list* bl, int fd)
  4924. {
  4925. unsigned char buf[16];
  4926. nullpo_retv(bl);
  4927. WBUFW(buf,0) = 0x132;
  4928. WBUFL(buf,2) = bl->id;
  4929. if( fd ) {
  4930. WFIFOHEAD(fd,packet_len(0x132));
  4931. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  4932. WFIFOSET(fd,packet_len(0x132));
  4933. } else {
  4934. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  4935. }
  4936. }
  4937. /*==========================================
  4938. * Sends a list of items in a shop
  4939. * 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
  4940. * R 0800 <len>.w <ID>.l <ID?>.l {<value>.l <amount>.w <index>.w <type>.B <item ID>.w <identify flag>.B <attribute?>.B <refine>.B <card>.4w}.22B
  4941. *------------------------------------------*/
  4942. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  4943. {
  4944. int i,fd;
  4945. int count;
  4946. struct map_session_data* vsd;
  4947. #if PACKETVER < 20100105
  4948. const int cmd = 0x133;
  4949. const int offset = 8;
  4950. #else
  4951. const int cmd = 0x800;
  4952. const int offset = 12;
  4953. #endif
  4954. nullpo_retv(sd);
  4955. nullpo_retv(vending);
  4956. nullpo_retv(vsd=map_id2sd(id));
  4957. fd = sd->fd;
  4958. count = vsd->vend_num;
  4959. WFIFOHEAD(fd, offset+count*22);
  4960. WFIFOW(fd,0) = cmd;
  4961. WFIFOW(fd,2) = offset+count*22;
  4962. WFIFOL(fd,4) = id;
  4963. #if PACKETVER >= 20100105
  4964. WFIFOL(fd,8) = vsd->status.char_id;
  4965. #endif
  4966. for( i = 0; i < count; i++ )
  4967. {
  4968. int index = vending[i].index;
  4969. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  4970. WFIFOL(fd,offset+ 0+i*22) = vending[i].value;
  4971. WFIFOW(fd,offset+ 4+i*22) = vending[i].amount;
  4972. WFIFOW(fd,offset+ 6+i*22) = vending[i].index + 2;
  4973. WFIFOB(fd,offset+ 8+i*22) = itemtype(data->type);
  4974. WFIFOW(fd,offset+ 9+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  4975. WFIFOB(fd,offset+11+i*22) = vsd->status.cart[index].identify;
  4976. WFIFOB(fd,offset+12+i*22) = vsd->status.cart[index].attribute;
  4977. WFIFOB(fd,offset+13+i*22) = vsd->status.cart[index].refine;
  4978. clif_addcards(WFIFOP(fd,offset+14+i*22), &vsd->status.cart[index]);
  4979. }
  4980. WFIFOSET(fd,WFIFOW(fd,2));
  4981. }
  4982. /*==========================================
  4983. * Shop purchase failure
  4984. * R 0135 <index>.w <amount>.w <fail>.B
  4985. * fail=1 - not enough zeny
  4986. * fail=2 - overweight
  4987. * fail=4 - out of stock
  4988. * fail=5 - "cannot use an npc shop while in a trade"
  4989. *------------------------------------------*/
  4990. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  4991. {
  4992. int fd;
  4993. nullpo_retv(sd);
  4994. fd = sd->fd;
  4995. WFIFOHEAD(fd,packet_len(0x135));
  4996. WFIFOW(fd,0) = 0x135;
  4997. WFIFOW(fd,2) = index+2;
  4998. WFIFOW(fd,4) = amount;
  4999. WFIFOB(fd,6) = fail;
  5000. WFIFOSET(fd,packet_len(0x135));
  5001. }
  5002. /*==========================================
  5003. * Shop creation success
  5004. * 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*
  5005. *------------------------------------------*/
  5006. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  5007. {
  5008. int i,fd;
  5009. int count;
  5010. nullpo_retv(sd);
  5011. fd = sd->fd;
  5012. count = sd->vend_num;
  5013. WFIFOHEAD(fd, 8+count*22);
  5014. WFIFOW(fd,0) = 0x136;
  5015. WFIFOW(fd,2) = 8+count*22;
  5016. WFIFOL(fd,4) = id;
  5017. for( i = 0; i < count; i++ )
  5018. {
  5019. int index = vending[i].index;
  5020. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  5021. WFIFOL(fd, 8+i*22) = vending[i].value;
  5022. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  5023. WFIFOW(fd,14+i*22) = vending[i].amount;
  5024. WFIFOB(fd,16+i*22) = itemtype(data->type);
  5025. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  5026. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  5027. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  5028. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  5029. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  5030. }
  5031. WFIFOSET(fd,WFIFOW(fd,2));
  5032. }
  5033. /*==========================================
  5034. * Inform merchant that someone has bought an item.
  5035. * R 0137 <index>.w <amount>.w
  5036. *------------------------------------------*/
  5037. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  5038. {
  5039. int fd;
  5040. nullpo_retv(sd);
  5041. fd = sd->fd;
  5042. WFIFOHEAD(fd,packet_len(0x137));
  5043. WFIFOW(fd,0) = 0x137;
  5044. WFIFOW(fd,2) = index+2;
  5045. WFIFOW(fd,4) = amount;
  5046. WFIFOSET(fd,packet_len(0x137));
  5047. }
  5048. /// Result of organizing a party.
  5049. /// R 00FA <result>.B
  5050. ///
  5051. /// result=0 : opens party window and shows MsgStringTable[77]="party successfully organized"
  5052. /// result=1 : MsgStringTable[78]="party name already exists"
  5053. /// result=2 : MsgStringTable[79]="already in a party"
  5054. /// result=other : nothing
  5055. int clif_party_created(struct map_session_data *sd,int result)
  5056. {
  5057. int fd;
  5058. nullpo_ret(sd);
  5059. fd=sd->fd;
  5060. WFIFOHEAD(fd,packet_len(0xfa));
  5061. WFIFOW(fd,0)=0xfa;
  5062. WFIFOB(fd,2)=result;
  5063. WFIFOSET(fd,packet_len(0xfa));
  5064. return 0;
  5065. }
  5066. int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  5067. {
  5068. unsigned char buf[96];
  5069. int i;
  5070. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  5071. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  5072. } else {
  5073. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  5074. }
  5075. if (i >= MAX_PARTY) return 0; //Should never happen...
  5076. sd = p->data[i].sd;
  5077. WBUFW(buf, 0) = 0x1e9;
  5078. WBUFL(buf, 2) = sd->status.account_id;
  5079. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  5080. WBUFW(buf,10) = sd->bl.x;
  5081. WBUFW(buf,12) = sd->bl.y;
  5082. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  5083. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  5084. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  5085. mapindex_getmapname_ext(mapindex_id2name(sd->mapindex), (char*)WBUFP(buf,63));
  5086. WBUFB(buf,79) = (p->party.item&1)?1:0;
  5087. WBUFB(buf,80) = (p->party.item&2)?1:0;
  5088. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  5089. return 1;
  5090. }
  5091. /*==========================================
  5092. * Sends party information
  5093. * R 00fb <len>.w <party name>.24B {<ID>.l <nick>.24B <map name>.16B <leader>.B <offline>.B}.46B*
  5094. *------------------------------------------*/
  5095. int clif_party_info(struct party_data* p, struct map_session_data *sd)
  5096. {
  5097. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  5098. struct map_session_data* party_sd = NULL;
  5099. int i, c;
  5100. nullpo_ret(p);
  5101. WBUFW(buf,0) = 0xfb;
  5102. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  5103. for(i = 0, c = 0; i < MAX_PARTY; i++)
  5104. {
  5105. struct party_member* m = &p->party.member[i];
  5106. if(!m->account_id) continue;
  5107. if(party_sd == NULL) party_sd = p->data[i].sd;
  5108. WBUFL(buf,28+c*46) = m->account_id;
  5109. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  5110. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  5111. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  5112. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  5113. c++;
  5114. }
  5115. WBUFW(buf,2) = 28+c*46;
  5116. if(sd) { // send only to self
  5117. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  5118. } else if (party_sd) { // send to whole party
  5119. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  5120. }
  5121. return 0;
  5122. }
  5123. /*==========================================
  5124. * The player's 'party invite' state, sent during login
  5125. * R 02c9 <flag>.B
  5126. *------------------------------------------*/
  5127. void clif_partyinvitationstate(struct map_session_data* sd)
  5128. {
  5129. int fd;
  5130. nullpo_retv(sd);
  5131. fd = sd->fd;
  5132. WFIFOHEAD(fd, packet_len(0x2c9));
  5133. WFIFOW(fd, 0) = 0x2c9;
  5134. WFIFOB(fd, 2) = 0; // not implemented
  5135. WFIFOSET(fd, packet_len(0x2c9));
  5136. }
  5137. /*==========================================
  5138. * パーティ勧誘
  5139. *------------------------------------------*/
  5140. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5141. {
  5142. int fd;
  5143. struct party_data *p;
  5144. nullpo_ret(sd);
  5145. nullpo_ret(tsd);
  5146. fd=tsd->fd;
  5147. if( (p=party_search(sd->status.party_id))==NULL )
  5148. return 0;
  5149. WFIFOHEAD(fd,packet_len(0xfe));
  5150. WFIFOW(fd,0)=0xfe;
  5151. WFIFOL(fd,2)=sd->status.account_id;
  5152. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5153. WFIFOSET(fd,packet_len(0xfe));
  5154. return 0;
  5155. }
  5156. /*==========================================
  5157. * Party invitation result.
  5158. * R 00fd <nick>.24S <flag>.B
  5159. * R 02c5 <nick>.24S <flag>.L
  5160. * Flag values are:
  5161. * 0 -> char is already in a party
  5162. * 1 -> party invite was rejected
  5163. * 2 -> party invite was accepted
  5164. * 3 -> party is full
  5165. * 4 -> char of the same account already joined the party
  5166. *------------------------------------------*/
  5167. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int flag)
  5168. {
  5169. int fd;
  5170. nullpo_retv(sd);
  5171. fd=sd->fd;
  5172. #if PACKETVER < 20070821
  5173. WFIFOHEAD(fd,packet_len(0xfd));
  5174. WFIFOW(fd,0) = 0xfd;
  5175. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5176. WFIFOB(fd,26) = flag;
  5177. WFIFOSET(fd,packet_len(0xfd));
  5178. #else
  5179. WFIFOHEAD(fd,packet_len(0x2c5));
  5180. WFIFOW(fd,0) = 0x2c5;
  5181. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  5182. WFIFOL(fd,26) = flag;
  5183. WFIFOSET(fd,packet_len(0x2c5));
  5184. #endif
  5185. }
  5186. /*==========================================
  5187. * パーティ設定送信
  5188. * flag & 0x001=exp変更ミス
  5189. * 0x010=item変更ミス
  5190. * 0x100=一人にのみ送信
  5191. *------------------------------------------*/
  5192. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5193. {
  5194. unsigned char buf[16];
  5195. #if PACKETVER<20090603
  5196. const int cmd = 0x101;
  5197. #else
  5198. const int cmd = 0x7d8;
  5199. #endif
  5200. nullpo_ret(p);
  5201. if(!sd && flag==0){
  5202. int i;
  5203. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5204. if (i < MAX_PARTY)
  5205. sd = p->data[i].sd;
  5206. }
  5207. if(!sd) return 0;
  5208. WBUFW(buf,0)=cmd;
  5209. // WBUFL(buf,2) // that's how the client reads it, still need to check it's uses [FlavioJS]
  5210. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  5211. WBUFW(buf,4)=0;
  5212. #if PACKETVER>=20090603
  5213. WBUFB(buf,6)=(p->party.item&1)?1:0;
  5214. WBUFB(buf,7)=(p->party.item&2)?1:0;
  5215. #endif
  5216. if(flag==0)
  5217. clif_send(buf,packet_len(cmd),&sd->bl,PARTY);
  5218. else
  5219. clif_send(buf,packet_len(cmd),&sd->bl,SELF);
  5220. return 0;
  5221. }
  5222. /*==========================================
  5223. * パーティ脱退(脱退前に呼ぶこと)
  5224. *------------------------------------------*/
  5225. int clif_party_withdraw(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  5226. {
  5227. unsigned char buf[64];
  5228. int i;
  5229. nullpo_ret(p);
  5230. if(!sd && (flag&0xf0)==0)
  5231. {
  5232. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5233. if (i < MAX_PARTY)
  5234. sd = p->data[i].sd;
  5235. }
  5236. if(!sd) return 0;
  5237. WBUFW(buf,0)=0x105;
  5238. WBUFL(buf,2)=account_id;
  5239. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5240. WBUFB(buf,30)=flag&0x0f;
  5241. if((flag&0xf0)==0)
  5242. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  5243. else
  5244. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  5245. return 0;
  5246. }
  5247. /*==========================================
  5248. * パーティメッセージ送信
  5249. *------------------------------------------*/
  5250. int clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  5251. {
  5252. struct map_session_data *sd;
  5253. int i;
  5254. nullpo_ret(p);
  5255. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  5256. if(i < MAX_PARTY){
  5257. unsigned char buf[1024];
  5258. sd = p->data[i].sd;
  5259. WBUFW(buf,0)=0x109;
  5260. WBUFW(buf,2)=len+8;
  5261. WBUFL(buf,4)=account_id;
  5262. memcpy(WBUFP(buf,8),mes,len);
  5263. clif_send(buf,len+8,&sd->bl,PARTY);
  5264. }
  5265. return 0;
  5266. }
  5267. /*==========================================
  5268. * パーティ座標通知
  5269. *------------------------------------------*/
  5270. int clif_party_xy(struct map_session_data *sd)
  5271. {
  5272. unsigned char buf[16];
  5273. nullpo_ret(sd);
  5274. WBUFW(buf,0)=0x107;
  5275. WBUFL(buf,2)=sd->status.account_id;
  5276. WBUFW(buf,6)=sd->bl.x;
  5277. WBUFW(buf,8)=sd->bl.y;
  5278. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  5279. return 0;
  5280. }
  5281. /*==========================================
  5282. * Sends x/y dot to a single fd. [Skotlex]
  5283. *------------------------------------------*/
  5284. int clif_party_xy_single(int fd, struct map_session_data *sd)
  5285. {
  5286. WFIFOHEAD(fd,packet_len(0x107));
  5287. WFIFOW(fd,0)=0x107;
  5288. WFIFOL(fd,2)=sd->status.account_id;
  5289. WFIFOW(fd,6)=sd->bl.x;
  5290. WFIFOW(fd,8)=sd->bl.y;
  5291. WFIFOSET(fd,packet_len(0x107));
  5292. return 0;
  5293. }
  5294. /*==========================================
  5295. * パーティHP通知
  5296. *------------------------------------------*/
  5297. int clif_party_hp(struct map_session_data *sd)
  5298. {
  5299. unsigned char buf[16];
  5300. #if PACKETVER < 20100126
  5301. const int cmd = 0x106;
  5302. #else
  5303. const int cmd = 0x80e;
  5304. #endif
  5305. nullpo_ret(sd);
  5306. WBUFW(buf,0)=cmd;
  5307. WBUFL(buf,2)=sd->status.account_id;
  5308. #if PACKETVER < 20100126
  5309. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5310. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5311. WBUFW(buf,8) = 100;
  5312. } else {
  5313. WBUFW(buf,6) = sd->battle_status.hp;
  5314. WBUFW(buf,8) = sd->battle_status.max_hp;
  5315. }
  5316. #else
  5317. WBUFL(buf,6) = sd->battle_status.hp;
  5318. WBUFL(buf,10) = sd->battle_status.max_hp;
  5319. #endif
  5320. clif_send(buf,packet_len(cmd),&sd->bl,PARTY_AREA_WOS);
  5321. return 0;
  5322. }
  5323. /*==========================================
  5324. * Sends HP bar to a single fd. [Skotlex]
  5325. *------------------------------------------*/
  5326. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  5327. {
  5328. #if PACKETVER < 20100126
  5329. const int cmd = 0x106;
  5330. #else
  5331. const int cmd = 0x80e;
  5332. #endif
  5333. WFIFOHEAD(fd,packet_len(cmd));
  5334. WFIFOW(fd,0) = cmd;
  5335. WFIFOL(fd,2) = id;
  5336. #if PACKETVER < 20100126
  5337. if( maxhp > SHRT_MAX )
  5338. {// To correctly display the %hp bar. [Skotlex]
  5339. WFIFOW(fd,6) = hp/(maxhp/100);
  5340. WFIFOW(fd,8) = 100;
  5341. } else {
  5342. WFIFOW(fd,6) = hp;
  5343. WFIFOW(fd,8) = maxhp;
  5344. }
  5345. #else
  5346. WFIFOL(fd,6) = hp;
  5347. WFIFOL(fd,10) = maxhp;
  5348. #endif
  5349. WFIFOSET(fd, packet_len(cmd));
  5350. }
  5351. /*==========================================
  5352. *
  5353. *------------------------------------------*/
  5354. int clif_hpmeter_sub(struct block_list *bl, va_list ap)
  5355. {
  5356. struct map_session_data *sd, *tsd;
  5357. int level;
  5358. #if PACKETVER < 20100126
  5359. const int cmd = 0x106;
  5360. #else
  5361. const int cmd = 0x80e;
  5362. #endif
  5363. sd = va_arg(ap, struct map_session_data *);
  5364. tsd = (TBL_PC *)bl;
  5365. nullpo_ret(sd);
  5366. nullpo_ret(tsd);
  5367. if( !tsd->fd || tsd == sd )
  5368. return 0;
  5369. if( (level = pc_isGM(tsd)) < battle_config.disp_hpmeter || level < pc_isGM(sd) )
  5370. return 0;
  5371. WFIFOHEAD(tsd->fd,packet_len(cmd));
  5372. WFIFOW(tsd->fd,0) = cmd;
  5373. WFIFOL(tsd->fd,2) = sd->status.account_id;
  5374. #if PACKETVER < 20100126
  5375. if( sd->battle_status.max_hp > SHRT_MAX )
  5376. { //To correctly display the %hp bar. [Skotlex]
  5377. WFIFOW(tsd->fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5378. WFIFOW(tsd->fd,8) = 100;
  5379. } else {
  5380. WFIFOW(tsd->fd,6) = sd->battle_status.hp;
  5381. WFIFOW(tsd->fd,8) = sd->battle_status.max_hp;
  5382. }
  5383. #else
  5384. WFIFOL(tsd->fd,6) = sd->battle_status.hp;
  5385. WFIFOL(tsd->fd,10) = sd->battle_status.max_hp;
  5386. #endif
  5387. WFIFOSET(tsd->fd,packet_len(cmd));
  5388. return 0;
  5389. }
  5390. /*==========================================
  5391. * GMへ場所とHP通知
  5392. *------------------------------------------*/
  5393. int clif_hpmeter(struct map_session_data *sd)
  5394. {
  5395. nullpo_ret(sd);
  5396. if( battle_config.disp_hpmeter )
  5397. map_foreachinarea(clif_hpmeter_sub, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_PC, sd);
  5398. return 0;
  5399. }
  5400. /*==========================================
  5401. * パーティ場所移動(未使用)
  5402. *------------------------------------------*/
  5403. void clif_party_move(struct party* p, struct map_session_data* sd, int online)
  5404. {
  5405. unsigned char buf[128];
  5406. nullpo_retv(sd);
  5407. nullpo_retv(p);
  5408. WBUFW(buf, 0) = 0x104;
  5409. WBUFL(buf, 2) = sd->status.account_id;
  5410. WBUFL(buf, 6) = 0;
  5411. WBUFW(buf,10) = sd->bl.x;
  5412. WBUFW(buf,12) = sd->bl.y;
  5413. WBUFB(buf,14) = !online;
  5414. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  5415. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  5416. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  5417. clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
  5418. }
  5419. /*==========================================
  5420. * 攻撃するために移動が必要
  5421. *------------------------------------------*/
  5422. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5423. {
  5424. int fd;
  5425. nullpo_ret(sd);
  5426. nullpo_ret(bl);
  5427. fd=sd->fd;
  5428. WFIFOHEAD(fd,packet_len(0x139));
  5429. WFIFOW(fd, 0)=0x139;
  5430. WFIFOL(fd, 2)=bl->id;
  5431. WFIFOW(fd, 6)=bl->x;
  5432. WFIFOW(fd, 8)=bl->y;
  5433. WFIFOW(fd,10)=sd->bl.x;
  5434. WFIFOW(fd,12)=sd->bl.y;
  5435. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5436. WFIFOSET(fd,packet_len(0x139));
  5437. return 0;
  5438. }
  5439. /*==========================================
  5440. * 製造エフェクト
  5441. *------------------------------------------*/
  5442. int clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  5443. {
  5444. int view,fd;
  5445. nullpo_ret(sd);
  5446. fd = sd->fd;
  5447. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  5448. WFIFOHEAD(fd,packet_len(0x18f));
  5449. WFIFOW(fd, 0)=0x18f;
  5450. WFIFOW(fd, 2)=flag;
  5451. if((view = itemdb_viewid(nameid)) > 0)
  5452. WFIFOW(fd, 4)=view;
  5453. else
  5454. WFIFOW(fd, 4)=nameid;
  5455. WFIFOSET(fd,packet_len(0x18f));
  5456. return 0;
  5457. }
  5458. // pet
  5459. int clif_catch_process(struct map_session_data *sd)
  5460. {
  5461. int fd;
  5462. nullpo_ret(sd);
  5463. fd=sd->fd;
  5464. WFIFOHEAD(fd,packet_len(0x19e));
  5465. WFIFOW(fd,0)=0x19e;
  5466. WFIFOSET(fd,packet_len(0x19e));
  5467. return 0;
  5468. }
  5469. int clif_pet_roulette(struct map_session_data *sd,int data)
  5470. {
  5471. int fd;
  5472. nullpo_ret(sd);
  5473. fd=sd->fd;
  5474. WFIFOHEAD(fd,packet_len(0x1a0));
  5475. WFIFOW(fd,0)=0x1a0;
  5476. WFIFOB(fd,2)=data;
  5477. WFIFOSET(fd,packet_len(0x1a0));
  5478. return 0;
  5479. }
  5480. /*==========================================
  5481. * pet卵リスト作成
  5482. *------------------------------------------*/
  5483. int clif_sendegg(struct map_session_data *sd)
  5484. {
  5485. //R 01a6 <len>.w <index>.w*
  5486. int i,n=0,fd;
  5487. nullpo_ret(sd);
  5488. fd=sd->fd;
  5489. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5490. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5491. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5492. return 0;
  5493. }
  5494. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5495. WFIFOW(fd,0)=0x1a6;
  5496. if(sd->status.pet_id <= 0) {
  5497. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5498. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5499. sd->inventory_data[i]->type!=IT_PETEGG ||
  5500. sd->status.inventory[i].amount<=0)
  5501. continue;
  5502. WFIFOW(fd,n*2+4)=i+2;
  5503. n++;
  5504. }
  5505. }
  5506. WFIFOW(fd,2)=4+n*2;
  5507. WFIFOSET(fd,WFIFOW(fd,2));
  5508. sd->menuskill_id = SA_TAMINGMONSTER;
  5509. sd->menuskill_val = -1;
  5510. return 0;
  5511. }
  5512. /*==========================================
  5513. * Sends a specific pet data update.
  5514. * type = 0 -> param = 0 (initial data)
  5515. * type = 1 -> param = intimacy value
  5516. * type = 2 -> param = hungry value
  5517. * type = 3 -> param = accessory id
  5518. * type = 4 -> param = performance number (1-3:normal, 4:special)
  5519. * type = 5 -> param = hairstyle number
  5520. * If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5521. *------------------------------------------*/
  5522. int clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5523. {
  5524. uint8 buf[16];
  5525. nullpo_ret(pd);
  5526. WBUFW(buf,0) = 0x1a4;
  5527. WBUFB(buf,2) = type;
  5528. WBUFL(buf,3) = pd->bl.id;
  5529. WBUFL(buf,7) = param;
  5530. if (sd)
  5531. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5532. else
  5533. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5534. return 0;
  5535. }
  5536. int clif_send_petstatus(struct map_session_data *sd)
  5537. {
  5538. int fd;
  5539. struct s_pet *pet;
  5540. nullpo_ret(sd);
  5541. nullpo_ret(sd->pd);
  5542. fd=sd->fd;
  5543. pet = &sd->pd->pet;
  5544. WFIFOHEAD(fd,packet_len(0x1a2));
  5545. WFIFOW(fd,0)=0x1a2;
  5546. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5547. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5548. WFIFOW(fd,27)=pet->level;
  5549. WFIFOW(fd,29)=pet->hungry;
  5550. WFIFOW(fd,31)=pet->intimate;
  5551. WFIFOW(fd,33)=pet->equip;
  5552. #if PACKETVER >= 20081126
  5553. WFIFOW(fd,35)=pet->class_;
  5554. #endif
  5555. WFIFOSET(fd,packet_len(0x1a2));
  5556. return 0;
  5557. }
  5558. /*==========================================
  5559. *
  5560. *------------------------------------------*/
  5561. int clif_pet_emotion(struct pet_data *pd,int param)
  5562. {
  5563. unsigned char buf[16];
  5564. nullpo_ret(pd);
  5565. memset(buf,0,packet_len(0x1aa));
  5566. WBUFW(buf,0)=0x1aa;
  5567. WBUFL(buf,2)=pd->bl.id;
  5568. if(param >= 100 && pd->petDB->talk_convert_class) {
  5569. if(pd->petDB->talk_convert_class < 0)
  5570. return 0;
  5571. else if(pd->petDB->talk_convert_class > 0) {
  5572. param -= (pd->pet.class_ - 100)*100;
  5573. param += (pd->petDB->talk_convert_class - 100)*100;
  5574. }
  5575. }
  5576. WBUFL(buf,6)=param;
  5577. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5578. return 0;
  5579. }
  5580. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5581. {
  5582. int fd;
  5583. nullpo_ret(sd);
  5584. fd=sd->fd;
  5585. WFIFOHEAD(fd,packet_len(0x1a3));
  5586. WFIFOW(fd,0)=0x1a3;
  5587. WFIFOB(fd,2)=fail;
  5588. WFIFOW(fd,3)=foodid;
  5589. WFIFOSET(fd,packet_len(0x1a3));
  5590. return 0;
  5591. }
  5592. /*==========================================
  5593. * オートスペル リスト送信
  5594. *------------------------------------------*/
  5595. int clif_autospell(struct map_session_data *sd,int skilllv)
  5596. {
  5597. int fd;
  5598. nullpo_ret(sd);
  5599. fd=sd->fd;
  5600. WFIFOHEAD(fd,packet_len(0x1cd));
  5601. WFIFOW(fd, 0)=0x1cd;
  5602. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5603. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5604. else
  5605. WFIFOL(fd,2)= 0x00000000;
  5606. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5607. WFIFOL(fd,6)= MG_COLDBOLT;
  5608. else
  5609. WFIFOL(fd,6)= 0x00000000;
  5610. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5611. WFIFOL(fd,10)= MG_FIREBOLT;
  5612. else
  5613. WFIFOL(fd,10)= 0x00000000;
  5614. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5615. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5616. else
  5617. WFIFOL(fd,14)= 0x00000000;
  5618. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5619. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5620. else
  5621. WFIFOL(fd,18)= 0x00000000;
  5622. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5623. WFIFOL(fd,22)= MG_FIREBALL;
  5624. else
  5625. WFIFOL(fd,22)= 0x00000000;
  5626. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5627. WFIFOL(fd,26)= MG_FROSTDIVER;
  5628. else
  5629. WFIFOL(fd,26)= 0x00000000;
  5630. WFIFOSET(fd,packet_len(0x1cd));
  5631. sd->menuskill_id = SA_AUTOSPELL;
  5632. sd->menuskill_val = skilllv;
  5633. return 0;
  5634. }
  5635. /*==========================================
  5636. * Devotion's visual effect
  5637. * S 01cf <devoter id>.L { <devotee id>.L }[5] <max distance>.W
  5638. *------------------------------------------*/
  5639. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  5640. {
  5641. unsigned char buf[56];
  5642. int i;
  5643. nullpo_retv(src);
  5644. memset(buf,0,packet_len(0x1cf));
  5645. WBUFW(buf,0) = 0x1cf;
  5646. WBUFL(buf,2) = src->id;
  5647. if( src->type == BL_MER )
  5648. {
  5649. struct mercenary_data *md = BL_CAST(BL_MER,src);
  5650. if( md && md->master && md->devotion_flag )
  5651. WBUFL(buf,6) = md->master->bl.id;
  5652. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  5653. }
  5654. else
  5655. {
  5656. struct map_session_data *sd = BL_CAST(BL_PC,src);
  5657. if( sd == NULL )
  5658. return;
  5659. for( i = 0; i < 5; i++ )
  5660. WBUFL(buf,6+4*i) = sd->devotion[i];
  5661. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  5662. }
  5663. if( tsd )
  5664. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  5665. else
  5666. clif_send(buf, packet_len(0x1cf), src, AREA);
  5667. }
  5668. /*==========================================
  5669. * 氣球
  5670. *------------------------------------------*/
  5671. int clif_spiritball(struct map_session_data *sd)
  5672. {
  5673. unsigned char buf[16];
  5674. nullpo_ret(sd);
  5675. WBUFW(buf,0)=0x1d0;
  5676. WBUFL(buf,2)=sd->bl.id;
  5677. WBUFW(buf,6)=sd->spiritball;
  5678. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5679. return 0;
  5680. }
  5681. /*==========================================
  5682. *
  5683. *------------------------------------------*/
  5684. int clif_combo_delay(struct block_list *bl,int wait)
  5685. {
  5686. unsigned char buf[32];
  5687. nullpo_ret(bl);
  5688. WBUFW(buf,0)=0x1d2;
  5689. WBUFL(buf,2)=bl->id;
  5690. WBUFL(buf,6)=wait;
  5691. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5692. return 0;
  5693. }
  5694. /*==========================================
  5695. *白刃取り
  5696. *------------------------------------------*/
  5697. void clif_bladestop(struct block_list *src, int dst_id, int active)
  5698. {
  5699. unsigned char buf[32];
  5700. nullpo_retv(src);
  5701. WBUFW(buf,0)=0x1d1;
  5702. WBUFL(buf,2)=src->id;
  5703. WBUFL(buf,6)=dst_id;
  5704. WBUFL(buf,10)=active;
  5705. clif_send(buf,packet_len(0x1d1),src,AREA);
  5706. }
  5707. /*==========================================
  5708. * MVPエフェクト
  5709. *------------------------------------------*/
  5710. int clif_mvp_effect(struct map_session_data *sd)
  5711. {
  5712. unsigned char buf[16];
  5713. nullpo_ret(sd);
  5714. WBUFW(buf,0)=0x10c;
  5715. WBUFL(buf,2)=sd->bl.id;
  5716. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5717. return 0;
  5718. }
  5719. /*==========================================
  5720. * MVPアイテム所得
  5721. *------------------------------------------*/
  5722. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5723. {
  5724. int view,fd;
  5725. nullpo_ret(sd);
  5726. fd=sd->fd;
  5727. WFIFOHEAD(fd,packet_len(0x10a));
  5728. WFIFOW(fd,0)=0x10a;
  5729. if((view = itemdb_viewid(nameid)) > 0)
  5730. WFIFOW(fd,2)=view;
  5731. else
  5732. WFIFOW(fd,2)=nameid;
  5733. WFIFOSET(fd,packet_len(0x10a));
  5734. return 0;
  5735. }
  5736. /*==========================================
  5737. * MVP経験値所得
  5738. *------------------------------------------*/
  5739. int clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  5740. {
  5741. int fd;
  5742. nullpo_ret(sd);
  5743. fd=sd->fd;
  5744. WFIFOHEAD(fd,packet_len(0x10b));
  5745. WFIFOW(fd,0)=0x10b;
  5746. WFIFOL(fd,2)=cap_value(exp,0,INT_MAX);
  5747. WFIFOSET(fd,packet_len(0x10b));
  5748. return 0;
  5749. }
  5750. /*==========================================
  5751. * Guild creation result
  5752. * R 0167 <flag>.B
  5753. * flag = 0 -> "Guild has been created."
  5754. * flag = 1 -> "You are already in a Guild."
  5755. * flag = 2 -> "That Guild Name already exists."
  5756. * flag = 3 -> "You need the neccessary item to create a Guild."
  5757. *------------------------------------------*/
  5758. int clif_guild_created(struct map_session_data *sd,int flag)
  5759. {
  5760. int fd;
  5761. nullpo_ret(sd);
  5762. fd=sd->fd;
  5763. WFIFOHEAD(fd,packet_len(0x167));
  5764. WFIFOW(fd,0)=0x167;
  5765. WFIFOB(fd,2)=flag;
  5766. WFIFOSET(fd,packet_len(0x167));
  5767. return 0;
  5768. }
  5769. /*==========================================
  5770. * ギルド所属通知
  5771. *------------------------------------------*/
  5772. int clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  5773. {
  5774. int ps,fd;
  5775. nullpo_ret(sd);
  5776. nullpo_ret(g);
  5777. fd=sd->fd;
  5778. ps=guild_getposition(g,sd);
  5779. WFIFOHEAD(fd,packet_len(0x16c));
  5780. memset(WFIFOP(fd,0),0,packet_len(0x16c));
  5781. WFIFOW(fd,0)=0x16c;
  5782. WFIFOL(fd,2)=g->guild_id;
  5783. WFIFOL(fd,6)=g->emblem_id;
  5784. WFIFOL(fd,10)=g->position[ps].mode;
  5785. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5786. WFIFOSET(fd,packet_len(0x16c));
  5787. return 0;
  5788. }
  5789. /*==========================================
  5790. * ギルドメンバログイン通知
  5791. *------------------------------------------*/
  5792. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5793. {
  5794. unsigned char buf[64];
  5795. nullpo_ret(g);
  5796. WBUFW(buf, 0)=0x16d;
  5797. WBUFL(buf, 2)=g->member[idx].account_id;
  5798. WBUFL(buf, 6)=g->member[idx].char_id;
  5799. WBUFL(buf,10)=flag;
  5800. if(g->member[idx].sd==NULL){
  5801. struct map_session_data *sd=guild_getavailablesd(g);
  5802. if(sd!=NULL)
  5803. clif_send(buf,packet_len(0x16d),&sd->bl,GUILD);
  5804. }else
  5805. clif_send(buf,packet_len(0x16d),&g->member[idx].sd->bl,GUILD_WOS);
  5806. return 0;
  5807. }
  5808. // Function `clif_guild_memberlogin_notice` sends info about
  5809. // logins and logouts of a guild member to the rest members.
  5810. // But at the 1st time (after a player login or map changing)
  5811. // the client won't show the message.
  5812. // So I suggest use this function for sending "first-time-info"
  5813. // to some player on entering the game or changing location.
  5814. // At next time the client would always show the message.
  5815. // The function sends all the statuses in the single packet
  5816. // to economize traffic. [LuzZza]
  5817. int clif_guild_send_onlineinfo(struct map_session_data *sd)
  5818. {
  5819. struct guild *g;
  5820. unsigned char buf[14*128];
  5821. int i, count=0, p_len;
  5822. nullpo_ret(sd);
  5823. p_len = packet_len(0x16d);
  5824. if(!(g = guild_search(sd->status.guild_id)))
  5825. return 0;
  5826. for(i=0; i<g->max_member; i++) {
  5827. if(g->member[i].account_id > 0 &&
  5828. g->member[i].account_id != sd->status.account_id) {
  5829. WBUFW(buf,count*p_len) = 0x16d;
  5830. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5831. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5832. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5833. count++;
  5834. }
  5835. }
  5836. clif_send(buf, p_len*count, &sd->bl, SELF);
  5837. return 0;
  5838. }
  5839. /*==========================================
  5840. * ギルドマスター通知(14dへの応答)
  5841. *------------------------------------------*/
  5842. int clif_guild_masterormember(struct map_session_data *sd)
  5843. {
  5844. int fd;
  5845. nullpo_ret(sd);
  5846. fd=sd->fd;
  5847. WFIFOHEAD(fd,packet_len(0x14e));
  5848. WFIFOW(fd,0) = 0x14e;
  5849. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  5850. WFIFOSET(fd,packet_len(0x14e));
  5851. return 0;
  5852. }
  5853. /*==========================================
  5854. * Basic Info (Territories [Valaris])
  5855. *------------------------------------------*/
  5856. int clif_guild_basicinfo(struct map_session_data *sd)
  5857. {
  5858. int fd,i,t;
  5859. struct guild *g;
  5860. struct guild_castle *gc = NULL;
  5861. nullpo_ret(sd);
  5862. fd = sd->fd;
  5863. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5864. return 0;
  5865. WFIFOHEAD(fd,packet_len(0x1b6));
  5866. WFIFOW(fd, 0)=0x1b6;//0x150;
  5867. WFIFOL(fd, 2)=g->guild_id;
  5868. WFIFOL(fd, 6)=g->guild_lv;
  5869. WFIFOL(fd,10)=g->connect_member;
  5870. WFIFOL(fd,14)=g->max_member;
  5871. WFIFOL(fd,18)=g->average_lv;
  5872. WFIFOL(fd,22)=(uint32)cap_value(g->exp,0,INT_MAX);
  5873. WFIFOL(fd,26)=g->next_exp;
  5874. WFIFOL(fd,30)=0; // Tax Points
  5875. WFIFOL(fd,34)=0; // Tendency: (left) Vulgar [-100,100] Famed (right)
  5876. WFIFOL(fd,38)=0; // Tendency: (down) Wicked [-100,100] Righteous (up)
  5877. WFIFOL(fd,42)=g->emblem_id;
  5878. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5879. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5880. for(i = 0, t = 0; i < MAX_GUILDCASTLE; i++)
  5881. {
  5882. gc = guild_castle_search(i);
  5883. if(gc && g->guild_id == gc->guild_id)
  5884. t++;
  5885. }
  5886. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20); // "'N' castles"
  5887. WFIFOSET(fd,packet_len(WFIFOW(fd,0)));
  5888. return 0;
  5889. }
  5890. /*==========================================
  5891. * ギルド同盟/敵対情報
  5892. *------------------------------------------*/
  5893. int clif_guild_allianceinfo(struct map_session_data *sd)
  5894. {
  5895. int fd,i,c;
  5896. struct guild *g;
  5897. nullpo_ret(sd);
  5898. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5899. return 0;
  5900. fd = sd->fd;
  5901. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5902. WFIFOW(fd, 0)=0x14c;
  5903. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5904. struct guild_alliance *a=&g->alliance[i];
  5905. if(a->guild_id>0){
  5906. WFIFOL(fd,c*32+4)=a->opposition;
  5907. WFIFOL(fd,c*32+8)=a->guild_id;
  5908. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5909. c++;
  5910. }
  5911. }
  5912. WFIFOW(fd, 2)=c*32+4;
  5913. WFIFOSET(fd,WFIFOW(fd,2));
  5914. return 0;
  5915. }
  5916. /*==========================================
  5917. * ギルドメンバーリスト
  5918. *------------------------------------------*/
  5919. int clif_guild_memberlist(struct map_session_data *sd)
  5920. {
  5921. int fd;
  5922. int i,c;
  5923. struct guild *g;
  5924. nullpo_ret(sd);
  5925. if( (fd = sd->fd) == 0 )
  5926. return 0;
  5927. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5928. return 0;
  5929. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5930. WFIFOW(fd, 0)=0x154;
  5931. for(i=0,c=0;i<g->max_member;i++){
  5932. struct guild_member *m=&g->member[i];
  5933. if(m->account_id==0)
  5934. continue;
  5935. WFIFOL(fd,c*104+ 4)=m->account_id;
  5936. WFIFOL(fd,c*104+ 8)=m->char_id;
  5937. WFIFOW(fd,c*104+12)=m->hair;
  5938. WFIFOW(fd,c*104+14)=m->hair_color;
  5939. WFIFOW(fd,c*104+16)=m->gender;
  5940. WFIFOW(fd,c*104+18)=m->class_;
  5941. WFIFOW(fd,c*104+20)=m->lv;
  5942. WFIFOL(fd,c*104+22)=(int)cap_value(m->exp,0,INT_MAX);
  5943. WFIFOL(fd,c*104+26)=m->online;
  5944. WFIFOL(fd,c*104+30)=m->position;
  5945. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5946. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5947. c++;
  5948. }
  5949. WFIFOW(fd, 2)=c*104+4;
  5950. WFIFOSET(fd,WFIFOW(fd,2));
  5951. return 0;
  5952. }
  5953. /*==========================================
  5954. * ギルド役職名リスト
  5955. *------------------------------------------*/
  5956. int clif_guild_positionnamelist(struct map_session_data *sd)
  5957. {
  5958. int i,fd;
  5959. struct guild *g;
  5960. nullpo_ret(sd);
  5961. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5962. return 0;
  5963. fd = sd->fd;
  5964. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5965. WFIFOW(fd, 0)=0x166;
  5966. for(i=0;i<MAX_GUILDPOSITION;i++){
  5967. WFIFOL(fd,i*28+4)=i;
  5968. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5969. }
  5970. WFIFOW(fd,2)=i*28+4;
  5971. WFIFOSET(fd,WFIFOW(fd,2));
  5972. return 0;
  5973. }
  5974. /*==========================================
  5975. * ギルド役職情報リスト
  5976. *------------------------------------------*/
  5977. int clif_guild_positioninfolist(struct map_session_data *sd)
  5978. {
  5979. int i,fd;
  5980. struct guild *g;
  5981. nullpo_ret(sd);
  5982. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5983. return 0;
  5984. fd = sd->fd;
  5985. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5986. WFIFOW(fd, 0)=0x160;
  5987. for(i=0;i<MAX_GUILDPOSITION;i++){
  5988. struct guild_position *p=&g->position[i];
  5989. WFIFOL(fd,i*16+ 4)=i;
  5990. WFIFOL(fd,i*16+ 8)=p->mode;
  5991. WFIFOL(fd,i*16+12)=i;
  5992. WFIFOL(fd,i*16+16)=p->exp_mode;
  5993. }
  5994. WFIFOW(fd, 2)=i*16+4;
  5995. WFIFOSET(fd,WFIFOW(fd,2));
  5996. return 0;
  5997. }
  5998. /*==========================================
  5999. * ギルド役職変更通知
  6000. *------------------------------------------*/
  6001. int clif_guild_positionchanged(struct guild *g,int idx)
  6002. {
  6003. struct map_session_data *sd;
  6004. unsigned char buf[128];
  6005. nullpo_ret(g);
  6006. WBUFW(buf, 0)=0x174;
  6007. WBUFW(buf, 2)=44;
  6008. WBUFL(buf, 4)=idx;
  6009. WBUFL(buf, 8)=g->position[idx].mode;
  6010. WBUFL(buf,12)=idx;
  6011. WBUFL(buf,16)=g->position[idx].exp_mode;
  6012. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  6013. if( (sd=guild_getavailablesd(g))!=NULL )
  6014. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6015. return 0;
  6016. }
  6017. /*==========================================
  6018. * ギルドメンバ変更通知
  6019. *------------------------------------------*/
  6020. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  6021. {
  6022. struct map_session_data *sd;
  6023. unsigned char buf[64];
  6024. nullpo_ret(g);
  6025. WBUFW(buf, 0)=0x156;
  6026. WBUFW(buf, 2)=16;
  6027. WBUFL(buf, 4)=g->member[idx].account_id;
  6028. WBUFL(buf, 8)=g->member[idx].char_id;
  6029. WBUFL(buf,12)=g->member[idx].position;
  6030. if( (sd=guild_getavailablesd(g))!=NULL )
  6031. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  6032. return 0;
  6033. }
  6034. /*==========================================
  6035. * ギルドエンブレム送信
  6036. *------------------------------------------*/
  6037. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  6038. {
  6039. int fd;
  6040. nullpo_ret(sd);
  6041. nullpo_ret(g);
  6042. fd = sd->fd;
  6043. if( g->emblem_len <= 0 )
  6044. return 0;
  6045. WFIFOHEAD(fd,g->emblem_len+12);
  6046. WFIFOW(fd,0)=0x152;
  6047. WFIFOW(fd,2)=g->emblem_len+12;
  6048. WFIFOL(fd,4)=g->guild_id;
  6049. WFIFOL(fd,8)=g->emblem_id;
  6050. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  6051. WFIFOSET(fd,WFIFOW(fd,2));
  6052. return 0;
  6053. }
  6054. /// Sends update of the guild id/emblem id to everyone in the area.
  6055. void clif_guild_emblem_area(struct block_list* bl)
  6056. {
  6057. uint8 buf[12];
  6058. nullpo_retv(bl);
  6059. // TODO this packet doesn't force the update of ui components that have the emblem visible
  6060. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  6061. WBUFW(buf,0) = 0x1B4;
  6062. WBUFL(buf,2) = bl->id;
  6063. WBUFL(buf,6) = status_get_guild_id(bl);
  6064. WBUFW(buf,10) = status_get_emblem_id(bl);
  6065. clif_send(buf, 12, bl, AREA_WOS);
  6066. }
  6067. /*==========================================
  6068. * Send guild skills
  6069. *------------------------------------------*/
  6070. int clif_guild_skillinfo(struct map_session_data* sd)
  6071. {
  6072. int fd;
  6073. struct guild* g;
  6074. int i,c;
  6075. nullpo_ret(sd);
  6076. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6077. return 0;
  6078. fd = sd->fd;
  6079. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  6080. WFIFOW(fd,0) = 0x0162;
  6081. WFIFOW(fd,4) = g->skill_point;
  6082. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  6083. {
  6084. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  6085. {
  6086. int id = g->skill[i].id;
  6087. int p = 6 + c*37;
  6088. WFIFOW(fd,p+0) = id;
  6089. WFIFOW(fd,p+2) = skill_get_inf(id);
  6090. WFIFOW(fd,p+4) = 0;
  6091. WFIFOW(fd,p+6) = g->skill[i].lv;
  6092. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  6093. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  6094. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  6095. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  6096. c++;
  6097. }
  6098. }
  6099. WFIFOW(fd,2) = 6 + c*37;
  6100. WFIFOSET(fd,WFIFOW(fd,2));
  6101. return 0;
  6102. }
  6103. /*==========================================
  6104. * Sends guild notice to client
  6105. * R 016f <str1z>.60B <str2z>.120B
  6106. *------------------------------------------*/
  6107. int clif_guild_notice(struct map_session_data* sd, struct guild* g)
  6108. {
  6109. int fd;
  6110. nullpo_ret(sd);
  6111. nullpo_ret(g);
  6112. fd = sd->fd;
  6113. if ( !session_isActive(fd) )
  6114. return 0;
  6115. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  6116. return 0;
  6117. WFIFOHEAD(fd,packet_len(0x16f));
  6118. WFIFOW(fd,0) = 0x16f;
  6119. memcpy(WFIFOP(fd,2), g->mes1, MAX_GUILDMES1);
  6120. memcpy(WFIFOP(fd,62), g->mes2, MAX_GUILDMES2);
  6121. WFIFOSET(fd,packet_len(0x16f));
  6122. return 0;
  6123. }
  6124. /*==========================================
  6125. * ギルドメンバ勧誘
  6126. *------------------------------------------*/
  6127. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6128. {
  6129. int fd;
  6130. nullpo_ret(sd);
  6131. nullpo_ret(g);
  6132. fd=sd->fd;
  6133. WFIFOHEAD(fd,packet_len(0x16a));
  6134. WFIFOW(fd,0)=0x16a;
  6135. WFIFOL(fd,2)=g->guild_id;
  6136. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6137. WFIFOSET(fd,packet_len(0x16a));
  6138. return 0;
  6139. }
  6140. /*==========================================
  6141. * Reply to invite request
  6142. * Flag:
  6143. * 0 = Already in guild.
  6144. * 1 = Offer rejected.
  6145. * 2 = Offer accepted.
  6146. * 3 = Guild full.
  6147. *------------------------------------------*/
  6148. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  6149. {
  6150. int fd;
  6151. nullpo_ret(sd);
  6152. fd=sd->fd;
  6153. WFIFOHEAD(fd,packet_len(0x169));
  6154. WFIFOW(fd,0)=0x169;
  6155. WFIFOB(fd,2)=flag;
  6156. WFIFOSET(fd,packet_len(0x169));
  6157. return 0;
  6158. }
  6159. /*==========================================
  6160. * ギルドメンバ脱退通知
  6161. *------------------------------------------*/
  6162. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6163. {
  6164. unsigned char buf[128];
  6165. nullpo_ret(sd);
  6166. WBUFW(buf, 0)=0x15a;
  6167. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6168. memcpy(WBUFP(buf,26),mes,40);
  6169. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  6170. return 0;
  6171. }
  6172. /*==========================================
  6173. * ギルドメンバ追放通知
  6174. *------------------------------------------*/
  6175. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,int account_id)
  6176. {
  6177. unsigned char buf[128];
  6178. nullpo_ret(sd);
  6179. WBUFW(buf, 0)=0x15c;
  6180. safestrncpy((char*)WBUFP(buf, 2),name,NAME_LENGTH);
  6181. safestrncpy((char*)WBUFP(buf,26),mes,40);
  6182. safestrncpy((char*)WBUFP(buf,66),"",NAME_LENGTH); // account name (not used for security reasons)
  6183. clif_send(buf,packet_len(0x15c),&sd->bl,GUILD_NOBG);
  6184. return 0;
  6185. }
  6186. /*==========================================
  6187. * ギルド追放メンバリスト
  6188. *------------------------------------------*/
  6189. int clif_guild_expulsionlist(struct map_session_data *sd)
  6190. {
  6191. int fd;
  6192. int i,c;
  6193. struct guild *g;
  6194. nullpo_ret(sd);
  6195. if( (g = guild_search(sd->status.guild_id)) == NULL )
  6196. return 0;
  6197. fd = sd->fd;
  6198. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * 88);
  6199. WFIFOW(fd,0)=0x163;
  6200. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  6201. struct guild_expulsion *e=&g->expulsion[i];
  6202. if(e->account_id>0){
  6203. safestrncpy((char*)WFIFOP(fd,4 + c*88),e->name,NAME_LENGTH);
  6204. safestrncpy((char*)WFIFOP(fd,4 + c*88+24),"",24); // account name (not used for security reasons)
  6205. safestrncpy((char*)WFIFOP(fd,4 + c*88+48),e->mes,40);
  6206. c++;
  6207. }
  6208. }
  6209. WFIFOW(fd,2) = 4 + c*88;
  6210. WFIFOSET(fd,WFIFOW(fd,2));
  6211. return 0;
  6212. }
  6213. /*==========================================
  6214. * ギルド会話
  6215. *------------------------------------------*/
  6216. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6217. {
  6218. struct map_session_data *sd;
  6219. unsigned char *buf;
  6220. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  6221. WBUFW(buf, 0) = 0x17f;
  6222. WBUFW(buf, 2) = len + 4;
  6223. memcpy(WBUFP(buf,4), mes, len);
  6224. if ((sd = guild_getavailablesd(g)) != NULL)
  6225. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  6226. if(buf) aFree(buf);
  6227. return 0;
  6228. }
  6229. /*==========================================
  6230. * ギルドスキル割り振り通知
  6231. *------------------------------------------*/
  6232. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  6233. {
  6234. int fd;
  6235. nullpo_ret(sd);
  6236. fd=sd->fd;
  6237. WFIFOHEAD(fd,11);
  6238. WFIFOW(fd,0) = 0x10e;
  6239. WFIFOW(fd,2) = skill_num;
  6240. WFIFOW(fd,4) = lv;
  6241. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  6242. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  6243. WFIFOB(fd,10) = 1;
  6244. WFIFOSET(fd,11);
  6245. return 0;
  6246. }
  6247. /*==========================================
  6248. * ギルド同盟要請
  6249. *------------------------------------------*/
  6250. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6251. {
  6252. int fd;
  6253. nullpo_ret(sd);
  6254. fd=sd->fd;
  6255. WFIFOHEAD(fd,packet_len(0x171));
  6256. WFIFOW(fd,0)=0x171;
  6257. WFIFOL(fd,2)=account_id;
  6258. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6259. WFIFOSET(fd,packet_len(0x171));
  6260. return 0;
  6261. }
  6262. /*==========================================
  6263. * Reply to alliance request.
  6264. * Flag values are:
  6265. * 0: Already allied.
  6266. * 1: You rejected the offer.
  6267. * 2: You accepted the offer.
  6268. * 3: They have too any alliances
  6269. * 4: You have too many alliances.
  6270. *------------------------------------------*/
  6271. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  6272. {
  6273. int fd;
  6274. nullpo_ret(sd);
  6275. fd=sd->fd;
  6276. WFIFOHEAD(fd,packet_len(0x173));
  6277. WFIFOW(fd,0)=0x173;
  6278. WFIFOL(fd,2)=flag;
  6279. WFIFOSET(fd,packet_len(0x173));
  6280. return 0;
  6281. }
  6282. /*==========================================
  6283. * ギルド関係解消通知
  6284. *------------------------------------------*/
  6285. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6286. {
  6287. int fd;
  6288. nullpo_ret(sd);
  6289. fd = sd->fd;
  6290. if (fd <= 0)
  6291. return 0;
  6292. WFIFOHEAD(fd,packet_len(0x184));
  6293. WFIFOW(fd,0)=0x184;
  6294. WFIFOL(fd,2)=guild_id;
  6295. WFIFOL(fd,6)=flag;
  6296. WFIFOSET(fd,packet_len(0x184));
  6297. return 0;
  6298. }
  6299. /*==========================================
  6300. * Reply to opposition request
  6301. * Flag:
  6302. * 0 = Antagonist has been set.
  6303. * 1 = Guild has too many Antagonists.
  6304. * 2 = Already set as an Antagonist.
  6305. *------------------------------------------*/
  6306. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6307. {
  6308. int fd;
  6309. nullpo_ret(sd);
  6310. fd=sd->fd;
  6311. WFIFOHEAD(fd,packet_len(0x181));
  6312. WFIFOW(fd,0)=0x181;
  6313. WFIFOB(fd,2)=flag;
  6314. WFIFOSET(fd,packet_len(0x181));
  6315. return 0;
  6316. }
  6317. /*==========================================
  6318. * ギルド関係追加
  6319. *------------------------------------------*/
  6320. /*int clif_guild_allianceadded(struct guild *g,int idx)
  6321. {
  6322. unsigned char buf[64];
  6323. WBUFW(fd,0)=0x185;
  6324. WBUFL(fd,2)=g->alliance[idx].opposition;
  6325. WBUFL(fd,6)=g->alliance[idx].guild_id;
  6326. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  6327. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  6328. return 0;
  6329. }*/
  6330. /*==========================================
  6331. * ギルド解散通知
  6332. *------------------------------------------*/
  6333. int clif_guild_broken(struct map_session_data *sd,int flag)
  6334. {
  6335. int fd;
  6336. nullpo_ret(sd);
  6337. fd=sd->fd;
  6338. WFIFOHEAD(fd,packet_len(0x15e));
  6339. WFIFOW(fd,0)=0x15e;
  6340. WFIFOL(fd,2)=flag;
  6341. WFIFOSET(fd,packet_len(0x15e));
  6342. return 0;
  6343. }
  6344. /*==========================================
  6345. * エモーション
  6346. *------------------------------------------*/
  6347. void clif_emotion(struct block_list *bl,int type)
  6348. {
  6349. unsigned char buf[8];
  6350. nullpo_retv(bl);
  6351. WBUFW(buf,0)=0xc0;
  6352. WBUFL(buf,2)=bl->id;
  6353. WBUFB(buf,6)=type;
  6354. clif_send(buf,packet_len(0xc0),bl,AREA);
  6355. }
  6356. /*==========================================
  6357. * トーキーボックス
  6358. *------------------------------------------*/
  6359. void clif_talkiebox(struct block_list* bl, const char* talkie)
  6360. {
  6361. unsigned char buf[86];
  6362. nullpo_retv(bl);
  6363. WBUFW(buf,0) = 0x191;
  6364. WBUFL(buf,2) = bl->id;
  6365. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6366. clif_send(buf,packet_len(0x191),bl,AREA);
  6367. }
  6368. /*==========================================
  6369. * 結婚エフェクト
  6370. *------------------------------------------*/
  6371. void clif_wedding_effect(struct block_list *bl)
  6372. {
  6373. unsigned char buf[6];
  6374. nullpo_retv(bl);
  6375. WBUFW(buf,0) = 0x1ea;
  6376. WBUFL(buf,2) = bl->id;
  6377. clif_send(buf, packet_len(0x1ea), bl, AREA);
  6378. }
  6379. /*==========================================
  6380. * ?なたに逢いたい使用時名前叫び
  6381. *------------------------------------------*/
  6382. void clif_callpartner(struct map_session_data *sd)
  6383. {
  6384. unsigned char buf[26];
  6385. const char *p;
  6386. nullpo_retv(sd);
  6387. if(sd->status.partner_id){
  6388. WBUFW(buf,0)=0x1e6;
  6389. p = map_charid2nick(sd->status.partner_id);
  6390. if(p){
  6391. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6392. }else{
  6393. WBUFB(buf,2) = 0;
  6394. }
  6395. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  6396. }
  6397. }
  6398. /*==========================================
  6399. * Marry [DracoRPG]
  6400. *------------------------------------------
  6401. void clif_marriage_process(struct map_session_data *sd)
  6402. {
  6403. int fd;
  6404. nullpo_retv(sd);
  6405. fd=sd->fd;
  6406. WFIFOHEAD(fd,packet_len(0x1e4));
  6407. WFIFOW(fd,0)=0x1e4;
  6408. WFIFOSET(fd,packet_len(0x1e4));
  6409. }
  6410. */
  6411. /*==========================================
  6412. * Notice of divorce
  6413. *------------------------------------------*/
  6414. void clif_divorced(struct map_session_data* sd, const char* name)
  6415. {
  6416. int fd;
  6417. nullpo_retv(sd);
  6418. fd=sd->fd;
  6419. WFIFOHEAD(fd,packet_len(0x205));
  6420. WFIFOW(fd,0)=0x205;
  6421. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6422. WFIFOSET(fd, packet_len(0x205));
  6423. }
  6424. /*==========================================
  6425. *
  6426. *------------------------------------------*/
  6427. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd)
  6428. {
  6429. nullpo_retv(sd);
  6430. WFIFOHEAD(fd,packet_len(0x1e2));
  6431. WFIFOW(fd,0)=0x1e2;
  6432. WFIFOSET(fd, packet_len(0x1e2));
  6433. }
  6434. /*==========================================
  6435. *
  6436. *------------------------------------------*/
  6437. int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  6438. {
  6439. int fd;
  6440. nullpo_ret(sd);
  6441. fd = sd->fd;
  6442. if (!fd || !len) return 0; //Disconnected player.
  6443. WFIFOHEAD(fd, len+5);
  6444. WFIFOW(fd, 0) = 0x17f;
  6445. WFIFOW(fd, 2) = len + 5;
  6446. memcpy(WFIFOP(fd,4), mes, len);
  6447. WFIFOSET(fd, WFIFOW(fd,2));
  6448. return 1;
  6449. }
  6450. /*==========================================
  6451. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6452. *------------------------------------------*/
  6453. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  6454. {
  6455. unsigned char buf[1024];
  6456. if (!len) return;
  6457. WBUFW(buf, 0) = 0x17f;
  6458. WBUFW(buf, 2) = len + 5;
  6459. memcpy(WBUFP(buf,4), mes, len);
  6460. clif_send(buf, WBUFW(buf,2), src, target);
  6461. return;
  6462. }
  6463. /*==========================================
  6464. *
  6465. *------------------------------------------*/
  6466. int clif_GM_kickack(struct map_session_data *sd, int id)
  6467. {
  6468. int fd;
  6469. nullpo_ret(sd);
  6470. fd = sd->fd;
  6471. WFIFOHEAD(fd,packet_len(0xcd));
  6472. WFIFOW(fd,0) = 0xcd;
  6473. WFIFOL(fd,2) = id;
  6474. WFIFOSET(fd, packet_len(0xcd));
  6475. return 0;
  6476. }
  6477. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  6478. {
  6479. int fd = tsd->fd;
  6480. if( fd > 0 )
  6481. clif_authfail_fd(fd, 15);
  6482. else
  6483. map_quit(tsd);
  6484. if( sd )
  6485. clif_GM_kickack(sd,tsd->status.account_id);
  6486. }
  6487. /// Displays various manner-related status messages
  6488. /// R 014a <type>.L
  6489. /// type: 0 - "A manner point has been successfully aligned."
  6490. /// 1 - ?
  6491. /// 2 - ?
  6492. /// 3 - "Chat Block has been applied by GM due to your ill-mannerous action."
  6493. /// 4 - "Automated Chat Block has been applied due to Anti-Spam System."
  6494. /// 5 - "You got a good point from %s."
  6495. void clif_manner_message(struct map_session_data* sd, uint32 type)
  6496. {
  6497. int fd;
  6498. nullpo_retv(sd);
  6499. fd = sd->fd;
  6500. WFIFOHEAD(fd,packet_len(0x14a));
  6501. WFIFOW(fd,0) = 0x14a;
  6502. WFIFOL(fd,2) = type;
  6503. WFIFOSET(fd, packet_len(0x14a));
  6504. }
  6505. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action.
  6506. /// R 014b <type>.B <GM name>.24B
  6507. /// type: 0 - positive (unmute)
  6508. /// 1 - negative (mute)
  6509. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  6510. {
  6511. int fd;
  6512. nullpo_retv(sd);
  6513. nullpo_retv(tsd);
  6514. fd = tsd->fd;
  6515. WFIFOHEAD(fd,packet_len(0x14b));
  6516. WFIFOW(fd,0) = 0x14b;
  6517. WFIFOB(fd,2) = type;
  6518. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6519. WFIFOSET(fd, packet_len(0x14b));
  6520. }
  6521. /*==========================================
  6522. * Wis拒否許可応答
  6523. *------------------------------------------*/
  6524. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6525. {
  6526. int fd;
  6527. nullpo_ret(sd);
  6528. fd=sd->fd;
  6529. WFIFOHEAD(fd,packet_len(0xd1));
  6530. WFIFOW(fd,0)=0xd1;
  6531. WFIFOB(fd,2)=type;
  6532. WFIFOB(fd,3)=flag;
  6533. WFIFOSET(fd,packet_len(0xd1));
  6534. return 0;
  6535. }
  6536. /*==========================================
  6537. * Wis全拒否許可応答
  6538. *------------------------------------------*/
  6539. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6540. {
  6541. int fd;
  6542. nullpo_ret(sd);
  6543. fd=sd->fd;
  6544. WFIFOHEAD(fd,packet_len(0xd2));
  6545. WFIFOW(fd,0)=0xd2;
  6546. WFIFOB(fd,2)=type;
  6547. WFIFOB(fd,3)=flag;
  6548. WFIFOSET(fd,packet_len(0xd2));
  6549. return 0;
  6550. }
  6551. /*==========================================
  6552. * Play a BGM! [Rikter/Yommy]
  6553. *------------------------------------------*/
  6554. void clif_playBGM(struct map_session_data* sd, const char* name)
  6555. {
  6556. int fd;
  6557. nullpo_retv(sd);
  6558. fd = sd->fd;
  6559. WFIFOHEAD(fd,packet_len(0x7fe));
  6560. WFIFOW(fd,0) = 0x7fe;
  6561. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6562. WFIFOSET(fd,packet_len(0x7fe));
  6563. }
  6564. /*==========================================
  6565. * サウンドエフェクト
  6566. *------------------------------------------*/
  6567. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6568. {
  6569. int fd;
  6570. nullpo_retv(sd);
  6571. nullpo_retv(bl);
  6572. fd = sd->fd;
  6573. WFIFOHEAD(fd,packet_len(0x1d3));
  6574. WFIFOW(fd,0) = 0x1d3;
  6575. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6576. WFIFOB(fd,26) = type;
  6577. WFIFOL(fd,27) = 0;
  6578. WFIFOL(fd,31) = bl->id;
  6579. WFIFOSET(fd,packet_len(0x1d3));
  6580. return;
  6581. }
  6582. int clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6583. {
  6584. unsigned char buf[40];
  6585. nullpo_ret(bl);
  6586. WBUFW(buf,0) = 0x1d3;
  6587. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6588. WBUFB(buf,26) = type;
  6589. WBUFL(buf,27) = 0;
  6590. WBUFL(buf,31) = bl->id;
  6591. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6592. return 0;
  6593. }
  6594. // displaying special effects (npcs, weather, etc) [Valaris]
  6595. int clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6596. {
  6597. unsigned char buf[24];
  6598. nullpo_ret(bl);
  6599. memset(buf, 0, packet_len(0x1f3));
  6600. WBUFW(buf,0) = 0x1f3;
  6601. WBUFL(buf,2) = bl->id;
  6602. WBUFL(buf,6) = type;
  6603. clif_send(buf, packet_len(0x1f3), bl, target);
  6604. if (disguised(bl)) {
  6605. WBUFL(buf,2) = -bl->id;
  6606. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6607. }
  6608. return 0;
  6609. }
  6610. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  6611. {
  6612. WFIFOHEAD(fd,10);
  6613. WFIFOW(fd,0) = 0x1f3;
  6614. WFIFOL(fd,2) = bl->id;
  6615. WFIFOL(fd,6) = type;
  6616. WFIFOSET(fd,10);
  6617. }
  6618. /******************************************************
  6619. * W.<packet> W.<LENGTH> L.<ID> L.<COLOR> S.<TEXT>
  6620. * Mob/NPC Color Talk [SnakeDrak]
  6621. ******************************************************/
  6622. int clif_messagecolor(struct block_list* bl, unsigned long color, const char* msg)
  6623. {
  6624. unsigned short msg_len = strlen(msg) + 1;
  6625. uint8 buf[256];
  6626. color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
  6627. nullpo_ret(bl);
  6628. WBUFW(buf,0) = 0x2C1;
  6629. WBUFW(buf,2) = msg_len + 12;
  6630. WBUFL(buf,4) = bl->id;
  6631. WBUFL(buf,8) = color;
  6632. memcpy(WBUFP(buf,12), msg, msg_len);
  6633. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6634. return 0;
  6635. }
  6636. // messages (from mobs/npcs) [Valaris]
  6637. int clif_message(struct block_list* bl, const char* msg)
  6638. {
  6639. unsigned short msg_len = strlen(msg) + 1;
  6640. uint8 buf[256];
  6641. nullpo_ret(bl);
  6642. WBUFW(buf,0) = 0x8d;
  6643. WBUFW(buf,2) = msg_len + 8;
  6644. WBUFL(buf,4) = bl->id;
  6645. memcpy(WBUFP(buf,8), msg, msg_len);
  6646. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6647. return 0;
  6648. }
  6649. // refresh the client's screen, getting rid of any effects
  6650. int clif_refresh(struct map_session_data *sd)
  6651. {
  6652. nullpo_retr(-1, sd);
  6653. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6654. clif_inventorylist(sd);
  6655. if(pc_iscarton(sd)) {
  6656. clif_cartlist(sd);
  6657. clif_updatestatus(sd,SP_CARTINFO);
  6658. }
  6659. clif_updatestatus(sd,SP_WEIGHT);
  6660. clif_updatestatus(sd,SP_MAXWEIGHT);
  6661. clif_updatestatus(sd,SP_STR);
  6662. clif_updatestatus(sd,SP_AGI);
  6663. clif_updatestatus(sd,SP_VIT);
  6664. clif_updatestatus(sd,SP_INT);
  6665. clif_updatestatus(sd,SP_DEX);
  6666. clif_updatestatus(sd,SP_LUK);
  6667. if (sd->spiritball)
  6668. clif_spiritball_single(sd->fd, sd);
  6669. if (sd->vd.cloth_color)
  6670. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6671. if(merc_is_hom_active(sd->hd))
  6672. clif_send_homdata(sd,0,0);
  6673. if( sd->md )
  6674. {
  6675. clif_mercenary_info(sd);
  6676. clif_mercenary_skillblock(sd);
  6677. }
  6678. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6679. clif_weather_check(sd);
  6680. if( sd->chatID )
  6681. chat_leavechat(sd,0);
  6682. if( pc_issit(sd) )
  6683. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  6684. if( pc_isdead(sd) ) //When you refresh, resend the death packet.
  6685. clif_clearunit_single(sd->bl.id,CLR_DEAD,sd->fd);
  6686. else
  6687. clif_changed_dir(&sd->bl, SELF);
  6688. #ifndef TXT_ONLY
  6689. mail_clear(sd);
  6690. #endif
  6691. return 0;
  6692. }
  6693. // updates the object's (bl) name on client
  6694. int clif_charnameack (int fd, struct block_list *bl)
  6695. {
  6696. unsigned char buf[103];
  6697. int cmd = 0x95, i, ps = -1;
  6698. nullpo_ret(bl);
  6699. WBUFW(buf,0) = cmd;
  6700. WBUFL(buf,2) = bl->id;
  6701. switch( bl->type )
  6702. {
  6703. case BL_PC:
  6704. {
  6705. struct map_session_data *ssd = (struct map_session_data *)bl;
  6706. struct party_data *p = NULL;
  6707. struct guild *g = NULL;
  6708. //Requesting your own "shadow" name. [Skotlex]
  6709. if (ssd->fd == fd && ssd->disguise)
  6710. WBUFL(buf,2) = -bl->id;
  6711. if (strlen(ssd->fakename)>1) {
  6712. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6713. break;
  6714. }
  6715. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6716. if (ssd->status.party_id > 0)
  6717. p = party_search(ssd->status.party_id);
  6718. if( ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL )
  6719. {
  6720. 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);
  6721. if( i < g->max_member ) ps = g->member[i].position;
  6722. }
  6723. if (p == NULL && g == NULL)
  6724. break;
  6725. WBUFW(buf, 0) = cmd = 0x195;
  6726. if (p)
  6727. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6728. else
  6729. WBUFB(buf,30) = 0;
  6730. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  6731. {
  6732. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6733. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6734. } else { //Assume no guild.
  6735. WBUFB(buf,54) = 0;
  6736. WBUFB(buf,78) = 0;
  6737. }
  6738. }
  6739. break;
  6740. //[blackhole89]
  6741. case BL_HOM:
  6742. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6743. break;
  6744. case BL_MER:
  6745. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  6746. break;
  6747. case BL_PET:
  6748. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6749. break;
  6750. case BL_NPC:
  6751. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6752. break;
  6753. case BL_MOB:
  6754. {
  6755. struct mob_data *md = (struct mob_data *)bl;
  6756. nullpo_ret(md);
  6757. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6758. if( md->guardian_data && md->guardian_data->guild_id )
  6759. {
  6760. WBUFW(buf, 0) = cmd = 0x195;
  6761. WBUFB(buf,30) = 0;
  6762. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6763. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6764. }
  6765. else if( battle_config.show_mob_info )
  6766. {
  6767. char mobhp[50], *str_p = mobhp;
  6768. WBUFW(buf, 0) = cmd = 0x195;
  6769. if( battle_config.show_mob_info&4 )
  6770. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6771. if( battle_config.show_mob_info&1 )
  6772. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6773. if( battle_config.show_mob_info&2 )
  6774. str_p += sprintf(str_p, "HP: %d%% | ", get_percentage(md->status.hp, md->status.max_hp));
  6775. //Even thought mobhp ain't a name, we send it as one so the client
  6776. //can parse it. [Skotlex]
  6777. if( str_p != mobhp )
  6778. {
  6779. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6780. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6781. WBUFB(buf,54) = 0;
  6782. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6783. }
  6784. }
  6785. }
  6786. break;
  6787. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6788. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6789. // break;
  6790. return 0;
  6791. default:
  6792. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  6793. return 0;
  6794. }
  6795. // if no receipient specified just update nearby clients
  6796. if (fd == 0)
  6797. clif_send(buf, packet_len(cmd), bl, AREA);
  6798. else {
  6799. WFIFOHEAD(fd, packet_len(cmd));
  6800. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  6801. WFIFOSET(fd, packet_len(cmd));
  6802. }
  6803. return 0;
  6804. }
  6805. //Used to update when a char leaves a party/guild. [Skotlex]
  6806. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6807. int clif_charnameupdate (struct map_session_data *ssd)
  6808. {
  6809. unsigned char buf[103];
  6810. int cmd = 0x195, ps = -1, i;
  6811. struct party_data *p = NULL;
  6812. struct guild *g = NULL;
  6813. nullpo_ret(ssd);
  6814. if (strlen(ssd->fakename)>1)
  6815. return 0; //No need to update as the party/guild was not displayed anyway.
  6816. WBUFW(buf,0) = cmd;
  6817. WBUFL(buf,2) = ssd->bl.id;
  6818. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6819. if( ssd->status.party_id > 0 )
  6820. p = party_search(ssd->status.party_id);
  6821. if( ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL )
  6822. {
  6823. 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);
  6824. if( i < g->max_member ) ps = g->member[i].position;
  6825. }
  6826. if( p )
  6827. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6828. else
  6829. WBUFB(buf,30) = 0;
  6830. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  6831. {
  6832. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6833. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6834. }
  6835. else
  6836. {
  6837. WBUFB(buf,54) = 0;
  6838. WBUFB(buf,78) = 0;
  6839. }
  6840. // Update nearby clients
  6841. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  6842. return 0;
  6843. }
  6844. /// Visually moves(instant) a character to x,y. The char moves even
  6845. /// when the target cell isn't walkable. If the char is sitting it
  6846. /// stays that way.
  6847. void clif_slide(struct block_list *bl, int x, int y)
  6848. {
  6849. unsigned char buf[10];
  6850. nullpo_retv(bl);
  6851. WBUFW(buf, 0) = 0x01ff;
  6852. WBUFL(buf, 2) = bl->id;
  6853. WBUFW(buf, 6) = x;
  6854. WBUFW(buf, 8) = y;
  6855. clif_send(buf, packet_len(0x1ff), bl, AREA);
  6856. if( disguised(bl) )
  6857. {
  6858. WBUFL(buf,2) = -bl->id;
  6859. clif_send(buf, packet_len(0x1ff), bl, SELF);
  6860. }
  6861. }
  6862. /*------------------------------------------
  6863. * @me command by lordalfa, rewritten implementation by Skotlex
  6864. *------------------------------------------*/
  6865. int clif_disp_overhead(struct map_session_data *sd, const char* mes)
  6866. {
  6867. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  6868. int len_mes = strlen(mes)+1; //Account for \0
  6869. if (len_mes + 8 >= 256) {
  6870. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6871. len_mes = 247; //Trunk it to avoid problems.
  6872. }
  6873. // send message to others
  6874. WBUFW(buf,0) = 0x8d;
  6875. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6876. WBUFL(buf,4) = sd->bl.id;
  6877. memcpy(WBUFP(buf,8), mes, len_mes);
  6878. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6879. // send back message to the speaker
  6880. WBUFW(buf,0) = 0x8e;
  6881. WBUFW(buf, 2) = len_mes + 4;
  6882. memcpy(WBUFP(buf,4), mes, len_mes);
  6883. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6884. return 0;
  6885. }
  6886. /*==========================
  6887. * Minimap fix [Kevin]
  6888. * Remove dot from minimap
  6889. *--------------------------*/
  6890. int clif_party_xy_remove(struct map_session_data *sd)
  6891. {
  6892. unsigned char buf[16];
  6893. nullpo_ret(sd);
  6894. WBUFW(buf,0)=0x107;
  6895. WBUFL(buf,2)=sd->status.account_id;
  6896. WBUFW(buf,6)=-1;
  6897. WBUFW(buf,8)=-1;
  6898. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6899. return 0;
  6900. }
  6901. //Displays gospel-buff information (thanks to Rayce):
  6902. //Type determines message based on this table:
  6903. /*
  6904. 0x15 End all negative status
  6905. 0x16 Immunity to all status
  6906. 0x17 MaxHP +100%
  6907. 0x18 MaxSP +100%
  6908. 0x19 All stats +20
  6909. 0x1c Enchant weapon with Holy element
  6910. 0x1d Enchant armor with Holy element
  6911. 0x1e DEF +25%
  6912. 0x1f ATK +100%
  6913. 0x20 HIT/Flee +50
  6914. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  6915. */
  6916. void clif_gospel_info(struct map_session_data *sd, int type)
  6917. {
  6918. int fd=sd->fd;
  6919. WFIFOHEAD(fd,packet_len(0x215));
  6920. WFIFOW(fd,0)=0x215;
  6921. WFIFOL(fd,2)=type;
  6922. WFIFOSET(fd, packet_len(0x215));
  6923. }
  6924. /// Multi purpose mission information packet (ZC_STARSKILL).
  6925. /// 0x20e <mapname>.24B <monster_id>.L <star>.B <result>.B
  6926. /// result:
  6927. /// 0 = Star Gladiator %s has designed <mapname>'s as the %s.
  6928. /// star:
  6929. /// 0 = Place of the Sun
  6930. /// 1 = Place of the Moon
  6931. /// 2 = Place of the Stars
  6932. /// 1 = Star Gladiator %s's %s: <mapname>
  6933. /// star:
  6934. /// 0 = Place of the Sun
  6935. /// 1 = Place of the Moon
  6936. /// 2 = Place of the Stars
  6937. /// 10 = Star Gladiator %s has designed <mapname>'s as the %s.
  6938. /// star:
  6939. /// 0 = Target of the Sun
  6940. /// 1 = Target of the Moon
  6941. /// 2 = Target of the Stars
  6942. /// 11 = Star Gladiator %s's %s: <mapname used as monster name>
  6943. /// star:
  6944. /// 0 = Monster of the Sun
  6945. /// 1 = Monster of the Moon
  6946. /// 2 = Monster of the Stars
  6947. /// 20 = [TaeKwon Mission] Target Monster : <mapname used as monster name> (<star>%)
  6948. /// 21 = [Taming Mission] Target Monster : <mapname used as monster name>
  6949. /// 22 = [Collector Rank] Target Item : <monster_id used as item id>
  6950. /// 30 = [Sun, Moon and Stars Angel] Designed places and monsters have been reset.
  6951. /// 40 = Target HP : <monster_id used as HP>
  6952. void clif_starskill(struct map_session_data* sd, const char* mapname, int monster_id, unsigned char star, unsigned char result)
  6953. {
  6954. int fd = sd->fd;
  6955. WFIFOHEAD(fd,packet_len(0x20e));
  6956. WFIFOW(fd,0) = 0x20e;
  6957. safestrncpy((char*)WFIFOP(fd,2), mapname, NAME_LENGTH);
  6958. WFIFOL(fd,26) = monster_id;
  6959. WFIFOB(fd,30) = star;
  6960. WFIFOB(fd,31) = result;
  6961. WFIFOSET(fd,packet_len(0x20e));
  6962. }
  6963. /*==========================================
  6964. * Info about Star Glaldiator save map [Komurka]
  6965. * type: 1: Information, 0: Map registered
  6966. *------------------------------------------*/
  6967. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  6968. {
  6969. char mapname[MAP_NAME_LENGTH_EXT];
  6970. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), mapname);
  6971. clif_starskill(sd, mapname, 0, feel_level, type ? 1 : 0);
  6972. }
  6973. /*==========================================
  6974. * Info about Star Glaldiator hate mob [Komurka]
  6975. * type: 1: Register mob, 0: Information.
  6976. *------------------------------------------*/
  6977. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  6978. {
  6979. if( pcdb_checkid(class_) )
  6980. {
  6981. clif_starskill(sd, job_name(class_), class_, hate_level, type ? 10 : 11);
  6982. }
  6983. else if( mobdb_checkid(class_) )
  6984. {
  6985. clif_starskill(sd, mob_db(class_)->jname, class_, hate_level, type ? 10 : 11);
  6986. }
  6987. else
  6988. {
  6989. ShowWarning("clif_hate_info: Received invalid class %d for this packet (char_id=%d, hate_level=%u, type=%u).\n", class_, sd->status.char_id, (unsigned int)hate_level, (unsigned int)type);
  6990. }
  6991. }
  6992. /*==========================================
  6993. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6994. *------------------------------------------*/
  6995. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  6996. {
  6997. clif_starskill(sd, mob_db(mob_id)->jname, mob_id, progress, 20);
  6998. }
  6999. /*==========================================
  7000. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  7001. *------------------------------------------*/
  7002. void clif_feel_hate_reset(struct map_session_data *sd)
  7003. {
  7004. clif_starskill(sd, "", 0, 0, 30);
  7005. }
  7006. /*==========================================
  7007. * Equip window (un)tick ack
  7008. * R 02d9 <zero>.L <flag>.L
  7009. *------------------------------------------*/
  7010. void clif_equiptickack(struct map_session_data* sd, int flag)
  7011. {
  7012. int fd;
  7013. nullpo_retv(sd);
  7014. fd = sd->fd;
  7015. WFIFOHEAD(fd, packet_len(0x2d9));
  7016. WFIFOW(fd, 0) = 0x2d9;
  7017. WFIFOL(fd, 2) = 0;
  7018. WFIFOL(fd, 6) = flag;
  7019. WFIFOSET(fd, packet_len(0x2d9));
  7020. }
  7021. /*==========================================
  7022. * The player's 'view equip' state, sent during login
  7023. * R 02da <flag>.B
  7024. *------------------------------------------*/
  7025. void clif_equipcheckbox(struct map_session_data* sd)
  7026. {
  7027. int fd;
  7028. nullpo_retv(sd);
  7029. fd = sd->fd;
  7030. WFIFOHEAD(fd, packet_len(0x2da));
  7031. WFIFOW(fd, 0) = 0x2da;
  7032. WFIFOB(fd, 2) = (sd->status.show_equip ? 1 : 0);
  7033. WFIFOSET(fd, packet_len(0x2da));
  7034. }
  7035. /*==========================================
  7036. * Sends info about a player's equipped items
  7037. * 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*
  7038. * for PACKETVER >= 20100629
  7039. * R 002d7 <length>.W <name>.24B <class>.w <hairstyle>.w <bottom-viewid>.w <mid-viewid>.w <up-viewid>.w <haircolor>.w <cloth-dye>.w <gender>.1B {equip item}.28B*
  7040. *------------------------------------------*/
  7041. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  7042. {
  7043. int i, n, fd;
  7044. #if PACKETVER < 20100629
  7045. const int s = 26;
  7046. #else
  7047. const int s = 28;
  7048. #endif
  7049. nullpo_retv(sd);
  7050. nullpo_retv(tsd);
  7051. fd = sd->fd;
  7052. WFIFOHEAD(fd, MAX_INVENTORY * s + 43);
  7053. WFIFOW(fd, 0) = 0x2d7;
  7054. safestrncpy((char*)WFIFOP(fd, 4), tsd->status.name, NAME_LENGTH);
  7055. WFIFOW(fd,28) = tsd->status.class_;
  7056. WFIFOW(fd,30) = tsd->vd.hair_style;
  7057. WFIFOW(fd,32) = tsd->vd.head_bottom;
  7058. WFIFOW(fd,34) = tsd->vd.head_mid;
  7059. WFIFOW(fd,36) = tsd->vd.head_top;
  7060. WFIFOW(fd,38) = tsd->vd.hair_color;
  7061. WFIFOW(fd,40) = tsd->vd.cloth_color;
  7062. WFIFOB(fd,42) = tsd->vd.sex;
  7063. for(i=0,n=0; i < MAX_INVENTORY; i++)
  7064. {
  7065. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  7066. continue;
  7067. if (!itemdb_isequip2(tsd->inventory_data[i])) // Is not equippable
  7068. continue;
  7069. // Inventory position
  7070. WFIFOW(fd, n*s+43) = i + 2;
  7071. // Add refine, identify flag, element, etc.
  7072. clif_item_sub(WFIFOP(fd,0), n*s+45, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  7073. // Add cards
  7074. clif_addcards(WFIFOP(fd, n*s+55), &tsd->status.inventory[i]);
  7075. // Expiration date stuff, if all of those are set to 0 then the client doesn't show anything related (6 bytes)
  7076. WFIFOL(fd, n*s+63) = tsd->status.inventory[i].expire_time;
  7077. WFIFOW(fd, n*s+67) = 0;
  7078. #if PACKETVER >= 20100629
  7079. if (tsd->inventory_data[i]->equip&EQP_HELM)
  7080. WFIFOW(fd, n*s+69) = tsd->inventory_data[i]->look;
  7081. else
  7082. WFIFOW(fd, n*s+69) = 0;
  7083. #endif
  7084. n++;
  7085. }
  7086. WFIFOW(fd, 2) = 43 + n*s; // Set length
  7087. WFIFOSET(fd, WFIFOW(fd, 2));
  7088. }
  7089. /// Display msgstringtable.txt string (ZC_MSG)
  7090. /// R 0291 <message>.W
  7091. void clif_msg(struct map_session_data* sd, unsigned short id)
  7092. {
  7093. int fd;
  7094. nullpo_retv(sd);
  7095. fd = sd->fd;
  7096. WFIFOHEAD(fd, packet_len(0x291));
  7097. WFIFOW(fd, 0) = 0x291;
  7098. WFIFOW(fd, 2) = id; // zero-based msgstringtable.txt index
  7099. WFIFOSET(fd, packet_len(0x291));
  7100. }
  7101. /// View player equip request denied
  7102. void clif_viewequip_fail(struct map_session_data* sd)
  7103. {
  7104. clif_msg(sd, 0x54d);
  7105. }
  7106. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  7107. /// Returns true if the packet was parsed successfully.
  7108. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  7109. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  7110. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  7111. {
  7112. char *text, *name, *message;
  7113. unsigned int packetlen, textlen, namelen, messagelen;
  7114. int fd = sd->fd;
  7115. *name_ = NULL;
  7116. *namelen_ = 0;
  7117. *message_ = NULL;
  7118. *messagelen_ = 0;
  7119. packetlen = RFIFOW(fd,2);
  7120. // basic structure checks
  7121. if( packetlen > RFIFOREST(fd) )
  7122. { // there has to be enough data to read
  7123. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  7124. return false;
  7125. }
  7126. if( packetlen < 4 + 1 )
  7127. { // 4-byte header and at least an empty string is expected
  7128. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  7129. return false;
  7130. }
  7131. text = (char*)RFIFOP(fd,4);
  7132. textlen = packetlen - 4;
  7133. // process <name> part of the packet
  7134. if( format == 0 )
  7135. {// name and message are separated by ' : '
  7136. // validate name
  7137. name = text;
  7138. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  7139. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  7140. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  7141. {
  7142. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  7143. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  7144. set_eof(fd); // Just kick them out to correct it.
  7145. return false;
  7146. }
  7147. message = name + namelen + 3;
  7148. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  7149. }
  7150. else
  7151. {// name has fixed width
  7152. if( textlen < NAME_LENGTH + 1 )
  7153. {
  7154. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  7155. return false;
  7156. }
  7157. // validate name
  7158. name = text;
  7159. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  7160. if( name[namelen] != '\0' )
  7161. { // only restriction is that the name must be zero-terminated
  7162. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  7163. return false;
  7164. }
  7165. message = name + NAME_LENGTH;
  7166. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  7167. }
  7168. if( messagelen != strnlen(message, messagelen)+1 )
  7169. { // the declared length must match real length
  7170. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  7171. return false;
  7172. }
  7173. // verify <message> part of the packet
  7174. if( message[messagelen-1] != '\0' )
  7175. { // message must be zero-terminated
  7176. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  7177. return false;
  7178. }
  7179. if( messagelen > CHAT_SIZE_MAX-1 )
  7180. { // messages mustn't be too long
  7181. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  7182. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  7183. // Neither the official client nor server place any restriction on the length of the data in the packet,
  7184. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  7185. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  7186. return false;
  7187. }
  7188. *name_ = name;
  7189. *namelen_ = namelen;
  7190. *message_ = message;
  7191. *messagelen_ = messagelen;
  7192. return true;
  7193. }
  7194. // ---------------------
  7195. // clif_guess_PacketVer
  7196. // ---------------------
  7197. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  7198. // error codes:
  7199. // 0 - Success
  7200. // 1 - Unknown packet_ver
  7201. // 2 - Invalid account_id
  7202. // 3 - Invalid char_id
  7203. // 4 - Invalid login_id1 (reserved)
  7204. // 5 - Invalid client_tick (reserved)
  7205. // 6 - Invalid sex
  7206. // Only the first 'invalid' error that appears is used.
  7207. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  7208. {
  7209. static int err = 1;
  7210. static int packet_ver = -1;
  7211. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  7212. if (get_previous)
  7213. {//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]
  7214. if( error )
  7215. *error = err;
  7216. return packet_ver;
  7217. }
  7218. //By default, start searching on the default one.
  7219. err = 1;
  7220. packet_ver = clif_config.packet_db_ver;
  7221. cmd = RFIFOW(fd,0);
  7222. packet_len = RFIFOREST(fd);
  7223. #define SET_ERROR(n) \
  7224. if( err == 1 )\
  7225. err = n;\
  7226. //define SET_ERROR
  7227. // FIXME: If the packet is not received at once, this will FAIL.
  7228. // Figure out, when it happens, that only part of the packet is
  7229. // received, or fix the function to be able to deal with that
  7230. // case.
  7231. #define CHECK_PACKET_VER() \
  7232. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  7233. ;/* not wanttoconnection or wrong length */\
  7234. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  7235. { SET_ERROR(2); }/* invalid account_id */\
  7236. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  7237. { SET_ERROR(3); }/* invalid char_id */\
  7238. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  7239. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  7240. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  7241. { SET_ERROR(6); }/* invalid sex */\
  7242. else\
  7243. {\
  7244. err = 0;\
  7245. if( error )\
  7246. *error = 0;\
  7247. return packet_ver;\
  7248. }\
  7249. //define CHECK_PACKET_VER
  7250. CHECK_PACKET_VER();//Default packet version found.
  7251. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  7252. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  7253. CHECK_PACKET_VER();
  7254. }
  7255. if( error )
  7256. *error = err;
  7257. packet_ver = -1;
  7258. return -1;
  7259. #undef SET_ERROR
  7260. #undef CHECK_PACKET_VER
  7261. }
  7262. // ------------
  7263. // clif_parse_*
  7264. // ------------
  7265. // パケット読み取って色々操作
  7266. /*==========================================
  7267. *
  7268. *------------------------------------------*/
  7269. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  7270. {
  7271. struct block_list* bl;
  7272. struct auth_node* node;
  7273. int cmd, account_id, char_id, login_id1, sex;
  7274. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  7275. 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])
  7276. if (sd) {
  7277. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  7278. return;
  7279. }
  7280. // Only valid packet version get here
  7281. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  7282. cmd = RFIFOW(fd,0);
  7283. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7284. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7285. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7286. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7287. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7288. if( packet_ver < 5 || // reject really old client versions
  7289. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  7290. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  7291. {// packet version rejected
  7292. 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));
  7293. WFIFOHEAD(fd,packet_len(0x6a));
  7294. WFIFOW(fd,0) = 0x6a;
  7295. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  7296. WFIFOSET(fd,packet_len(0x6a));
  7297. set_eof(fd);
  7298. return;
  7299. }
  7300. //Check for double login.
  7301. bl = map_id2bl(account_id);
  7302. if(bl && bl->type != BL_PC) {
  7303. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  7304. WFIFOHEAD(fd,packet_len(0x6a));
  7305. WFIFOW(fd,0) = 0x6a;
  7306. WFIFOB(fd,2) = 3; // Rejected by server
  7307. WFIFOSET(fd,packet_len(0x6a));
  7308. set_eof(fd);
  7309. return;
  7310. }
  7311. if (bl ||
  7312. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  7313. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN)))
  7314. {
  7315. clif_authfail_fd(fd, 8); //Still recognizes last connection
  7316. return;
  7317. }
  7318. CREATE(sd, TBL_PC, 1);
  7319. sd->fd = fd;
  7320. sd->packet_ver = packet_ver;
  7321. session[fd]->session_data = sd;
  7322. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7323. #if PACKETVER < 20070521
  7324. WFIFOHEAD(fd,4);
  7325. WFIFOL(fd,0) = sd->bl.id;
  7326. WFIFOSET(fd,4);
  7327. #else
  7328. WFIFOHEAD(fd,packet_len(0x283));
  7329. WFIFOW(fd,0) = 0x283;
  7330. WFIFOL(fd,2) = sd->bl.id;
  7331. WFIFOSET(fd,packet_len(0x283));
  7332. #endif
  7333. chrif_authreq(sd);
  7334. return;
  7335. }
  7336. /*==========================================
  7337. * 007d クライアント側マップ読み込み完了
  7338. * map侵入時に必要なデータを全て送りつける
  7339. *------------------------------------------*/
  7340. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7341. {
  7342. if(sd->bl.prev != NULL)
  7343. return;
  7344. if (!sd->state.active)
  7345. { //Character loading is not complete yet!
  7346. //Let pc_reg_received reinvoke this when ready.
  7347. sd->state.connect_new = 0;
  7348. return;
  7349. }
  7350. if (sd->state.rewarp)
  7351. { //Rewarp player.
  7352. sd->state.rewarp = 0;
  7353. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  7354. return;
  7355. }
  7356. // look
  7357. #if PACKETVER < 4
  7358. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7359. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7360. #else
  7361. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7362. #endif
  7363. if(sd->vd.cloth_color)
  7364. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7365. // item
  7366. pc_checkitem(sd);
  7367. clif_inventorylist(sd);
  7368. // cart
  7369. if(pc_iscarton(sd)) {
  7370. clif_cartlist(sd);
  7371. clif_updatestatus(sd,SP_CARTINFO);
  7372. }
  7373. // weight
  7374. clif_updatestatus(sd,SP_WEIGHT);
  7375. clif_updatestatus(sd,SP_MAXWEIGHT);
  7376. // guild
  7377. // (needs to go before clif_spawn() to show guild emblems correctly)
  7378. if(sd->status.guild_id)
  7379. guild_send_memberinfoshort(sd,1);
  7380. if(battle_config.pc_invincible_time > 0) {
  7381. if(map_flag_gvg(sd->bl.m))
  7382. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7383. else
  7384. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7385. }
  7386. if( map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs )
  7387. map_spawnmobs(sd->bl.m);
  7388. if( map[sd->bl.m].instance_id )
  7389. {
  7390. instance[map[sd->bl.m].instance_id].users++;
  7391. instance_check_idle(map[sd->bl.m].instance_id);
  7392. }
  7393. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  7394. map_addblock(&sd->bl);
  7395. clif_spawn(&sd->bl);
  7396. // Party
  7397. // (needs to go after clif_spawn() to show hp bars correctly)
  7398. if(sd->status.party_id) {
  7399. party_send_movemap(sd);
  7400. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  7401. }
  7402. if( sd->state.bg_id ) clif_bg_hp(sd); // BattleGround System
  7403. if( sd->state.changemap && map[sd->bl.m].flag.battleground )
  7404. {
  7405. clif_set01D6(sd,19); // Battleground Mode
  7406. if( map[sd->bl.m].flag.battleground == 2 )
  7407. clif_bg_updatescore_single(sd);
  7408. }
  7409. if(map[sd->bl.m].flag.pvp) {
  7410. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7411. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  7412. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  7413. sd->pvp_rank = 0;
  7414. sd->pvp_lastusers = 0;
  7415. sd->pvp_point = 5;
  7416. sd->pvp_won = 0;
  7417. sd->pvp_lost = 0;
  7418. }
  7419. clif_set0199(sd,1);
  7420. } else
  7421. // set flag, if it's a duel [LuzZza]
  7422. if(sd->duel_group)
  7423. clif_set0199(sd,1);
  7424. if (map[sd->bl.m].flag.gvg_dungeon)
  7425. clif_set0199(sd,1); //TODO: Figure out the real packet to send here.
  7426. if( map_flag_gvg(sd->bl.m) )
  7427. clif_set0199(sd,3);
  7428. // info about nearby objects
  7429. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  7430. 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);
  7431. // pet
  7432. if( sd->pd )
  7433. {
  7434. if( battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) )
  7435. { //Return the pet to egg. [Skotlex]
  7436. clif_displaymessage(sd->fd, "Pets are not allowed in Guild Wars.");
  7437. pet_menu(sd, 3); //Option 3 is return to egg.
  7438. }
  7439. else
  7440. {
  7441. map_addblock(&sd->pd->bl);
  7442. clif_spawn(&sd->pd->bl);
  7443. clif_send_petdata(sd,sd->pd,0,0);
  7444. clif_send_petstatus(sd);
  7445. // skill_unit_move(&sd->pd->bl,gettick(),1);
  7446. }
  7447. }
  7448. //homunculus [blackhole89]
  7449. if( merc_is_hom_active(sd->hd) )
  7450. {
  7451. map_addblock(&sd->hd->bl);
  7452. clif_spawn(&sd->hd->bl);
  7453. clif_send_homdata(sd,0,0);
  7454. clif_hominfo(sd,sd->hd,1);
  7455. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  7456. clif_homskillinfoblock(sd);
  7457. if( battle_config.hom_setting&0x8 )
  7458. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  7459. if( !(battle_config.hom_setting&0x2) )
  7460. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  7461. }
  7462. if( sd->md )
  7463. {
  7464. map_addblock(&sd->md->bl);
  7465. clif_spawn(&sd->md->bl);
  7466. clif_mercenary_info(sd);
  7467. clif_mercenary_skillblock(sd);
  7468. }
  7469. if(sd->state.connect_new) {
  7470. int lv;
  7471. sd->state.connect_new = 0;
  7472. clif_skillinfoblock(sd);
  7473. clif_hotkeys_send(sd);
  7474. clif_updatestatus(sd,SP_BASEEXP);
  7475. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7476. clif_updatestatus(sd,SP_JOBEXP);
  7477. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7478. clif_updatestatus(sd,SP_SKILLPOINT);
  7479. clif_initialstatus(sd);
  7480. if (sd->sc.option&OPTION_FALCON)
  7481. clif_status_load(&sd->bl, SI_FALCON, 1);
  7482. if (sd->sc.option&OPTION_RIDING)
  7483. clif_status_load(&sd->bl, SI_RIDING, 1);
  7484. if(sd->status.manner < 0)
  7485. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7486. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7487. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7488. if(sd->bl.m == sd->feel_map[0].m
  7489. || sd->bl.m == sd->feel_map[1].m
  7490. || sd->bl.m == sd->feel_map[2].m)
  7491. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7492. }
  7493. if(sd->pd && sd->pd->pet.intimate > 900)
  7494. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7495. if(merc_is_hom_active(sd->hd))
  7496. merc_hom_init_timers(sd->hd);
  7497. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7498. {
  7499. sd->state.night = 1;
  7500. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7501. }
  7502. // Notify everyone that this char logged in [Skotlex].
  7503. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  7504. //Login Event
  7505. npc_script_event(sd, NPCE_LOGIN);
  7506. } else {
  7507. //For some reason the client "loses" these on warp/map-change.
  7508. clif_updatestatus(sd,SP_STR);
  7509. clif_updatestatus(sd,SP_AGI);
  7510. clif_updatestatus(sd,SP_VIT);
  7511. clif_updatestatus(sd,SP_INT);
  7512. clif_updatestatus(sd,SP_DEX);
  7513. clif_updatestatus(sd,SP_LUK);
  7514. // abort currently running script
  7515. sd->state.using_fake_npc = 0;
  7516. sd->state.menu_or_input = 0;
  7517. sd->npc_menu = 0;
  7518. if(sd->npc_id)
  7519. npc_event_dequeue(sd);
  7520. }
  7521. if( sd->state.changemap )
  7522. {// restore information that gets lost on map-change
  7523. #if PACKETVER >= 20070918
  7524. clif_partyinvitationstate(sd);
  7525. clif_equipcheckbox(sd);
  7526. #endif
  7527. if( (battle_config.bg_flee_penalty != 100 || battle_config.gvg_flee_penalty != 100) &&
  7528. (map_flag_gvg(sd->state.pmap) || map_flag_gvg(sd->bl.m) || map[sd->state.pmap].flag.battleground || map[sd->bl.m].flag.battleground) )
  7529. status_calc_bl(&sd->bl, SCB_FLEE); //Refresh flee penalty
  7530. if( night_flag && map[sd->bl.m].flag.nightenabled )
  7531. { //Display night.
  7532. if( !sd->state.night )
  7533. {
  7534. sd->state.night = 1;
  7535. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7536. }
  7537. }
  7538. else if( sd->state.night )
  7539. { //Clear night display.
  7540. sd->state.night = 0;
  7541. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7542. }
  7543. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  7544. {
  7545. char output[128];
  7546. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  7547. clif_broadcast(&sd->bl, output, strlen(output) + 1, 0x10, SELF);
  7548. }
  7549. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  7550. sd->state.changemap = false;
  7551. }
  7552. #ifndef TXT_ONLY
  7553. mail_clear(sd);
  7554. #endif
  7555. if(map[sd->bl.m].flag.loadevent) // Lance
  7556. npc_script_event(sd, NPCE_LOADMAP);
  7557. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7558. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7559. if (sd->sc.opt2) //Client loses these on warp.
  7560. clif_changeoption(&sd->bl);
  7561. clif_weather_check(sd);
  7562. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7563. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7564. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7565. else
  7566. sd->areanpc_id = 0;
  7567. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  7568. if(pc_isdead(sd))
  7569. clif_clearunit_area(&sd->bl, CLR_DEAD);
  7570. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  7571. // else
  7572. // clif_changed_dir(&sd->bl, SELF);
  7573. // Trigger skill effects if you appear standing on them
  7574. if(!battle_config.pc_invincible_time)
  7575. skill_unit_move(&sd->bl,gettick(),1);
  7576. }
  7577. /*==========================================
  7578. *
  7579. *------------------------------------------*/
  7580. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  7581. {
  7582. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7583. WFIFOHEAD(fd, packet_len(0x7f));
  7584. WFIFOW(fd,0)=0x7f;
  7585. WFIFOL(fd,2)=gettick();
  7586. WFIFOSET(fd,packet_len(0x7f));
  7587. // removed until the socket problems are fixed. [FlavioJS]
  7588. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  7589. return;
  7590. }
  7591. void clif_hotkeys_send(struct map_session_data *sd) {
  7592. #ifdef HOTKEY_SAVING
  7593. const int fd = sd->fd;
  7594. int i;
  7595. #if PACKETVER<20090603
  7596. const int cmd = 0x02b9;
  7597. #else
  7598. const int cmd = 0x07d9;
  7599. #endif
  7600. if (!fd) return;
  7601. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  7602. WFIFOW(fd, 0) = cmd;
  7603. for(i = 0; i < MAX_HOTKEYS; i++) {
  7604. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  7605. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  7606. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  7607. }
  7608. WFIFOSET(fd, packet_len(cmd));
  7609. #endif
  7610. }
  7611. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  7612. #ifdef HOTKEY_SAVING
  7613. unsigned short idx;
  7614. int cmd;
  7615. cmd = RFIFOW(fd, 0);
  7616. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  7617. if (idx >= MAX_HOTKEYS) return;
  7618. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  7619. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  7620. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  7621. return;
  7622. #endif
  7623. }
  7624. void clif_progressbar(struct map_session_data * sd, unsigned long color, unsigned int second)
  7625. {
  7626. int fd = sd->fd;
  7627. WFIFOHEAD(fd,packet_len(0x2f0));
  7628. WFIFOW(fd,0) = 0x2f0;
  7629. WFIFOL(fd,2) = color;
  7630. WFIFOL(fd,6) = second;
  7631. WFIFOSET(fd,packet_len(0x2f0));
  7632. }
  7633. void clif_progressbar_abort(struct map_session_data * sd)
  7634. {
  7635. int fd = sd->fd;
  7636. WFIFOHEAD(fd,packet_len(0x2f2));
  7637. WFIFOW(fd,0) = 0x2f2;
  7638. WFIFOSET(fd,packet_len(0x2f2));
  7639. }
  7640. void clif_parse_progressbar(int fd, struct map_session_data * sd)
  7641. {
  7642. if( gettick() < sd->progressbar.timeout && sd->st )
  7643. sd->st->state = END;
  7644. npc_scriptcont(sd, sd->progressbar.npc_id);
  7645. sd->progressbar.npc_id = sd->progressbar.timeout = 0;
  7646. }
  7647. /*==========================================
  7648. *
  7649. *------------------------------------------*/
  7650. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  7651. {
  7652. short x, y;
  7653. int cmd;
  7654. if (pc_isdead(sd)) {
  7655. clif_clearunit_area(&sd->bl, CLR_DEAD);
  7656. return;
  7657. }
  7658. if (sd->sc.opt1 && sd->sc.opt1 == OPT1_STONEWAIT)
  7659. ; //You CAN walk on this OPT1 value.
  7660. else if( sd->progressbar.npc_id )
  7661. clif_progressbar_abort(sd);
  7662. else if (pc_cant_act(sd))
  7663. return;
  7664. if(sd->sc.data[SC_RUN])
  7665. return;
  7666. pc_delinvincibletimer(sd);
  7667. cmd = RFIFOW(fd,0);
  7668. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7669. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7670. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7671. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7672. //Set last idle time... [Skotlex]
  7673. sd->idletime = last_tick;
  7674. unit_walktoxy(&sd->bl, x, y, 4);
  7675. }
  7676. /*==========================================
  7677. *
  7678. *------------------------------------------*/
  7679. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  7680. {
  7681. WFIFOHEAD(fd,packet_len(0x18b));
  7682. WFIFOW(fd,0) = 0x18b;
  7683. /* Rovert's prevent logout option fixed [Valaris] */
  7684. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] &&
  7685. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  7686. {
  7687. set_eof(fd);
  7688. WFIFOW(fd,2)=0;
  7689. } else {
  7690. WFIFOW(fd,2)=1;
  7691. }
  7692. WFIFOSET(fd,packet_len(0x18b));
  7693. }
  7694. /// Requesting unit's name
  7695. /// S 0094 <object id>.l
  7696. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  7697. {
  7698. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7699. struct block_list* bl;
  7700. //struct status_change *sc;
  7701. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  7702. id = sd->bl.id;
  7703. bl = map_id2bl(id);
  7704. if( bl == NULL )
  7705. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  7706. if( sd->bl.m != bl->m || !check_distance_bl(&sd->bl, bl, AREA_SIZE) )
  7707. return; // Block namerequests past view range
  7708. // 'see people in GM hide' cheat detection
  7709. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  7710. sc = status_get_sc(bl);
  7711. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  7712. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  7713. pc_isGM(sd) < battle_config.hack_info_GM_level
  7714. ) {
  7715. char gm_msg[256];
  7716. 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);
  7717. ShowWarning(gm_msg);
  7718. // information is sent to all online GMs
  7719. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7720. return;
  7721. }
  7722. */
  7723. clif_charnameack(fd, bl);
  7724. }
  7725. /*==========================================
  7726. * Validates and processes global messages
  7727. * S 008c/00f3 <packet len>.w <text>.?B (<name> : <message>) 00
  7728. *------------------------------------------*/
  7729. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  7730. {
  7731. const char* text = (char*)RFIFOP(fd,4);
  7732. int textlen = RFIFOW(fd,2) - 4;
  7733. char *name, *message;
  7734. int namelen, messagelen;
  7735. // validate packet and retrieve name and message
  7736. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  7737. return;
  7738. if( is_atcommand(fd, sd, message, 1) )
  7739. return;
  7740. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  7741. return;
  7742. if( battle_config.min_chat_delay )
  7743. { //[Skotlex]
  7744. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7745. return;
  7746. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7747. }
  7748. // send message to others (using the send buffer for temp. storage)
  7749. WFIFOHEAD(fd, 8 + textlen);
  7750. WFIFOW(fd,0) = 0x8d;
  7751. WFIFOW(fd,2) = 8 + textlen;
  7752. WFIFOL(fd,4) = sd->bl.id;
  7753. safestrncpy((char*)WFIFOP(fd,8), text, textlen);
  7754. //FIXME: chat has range of 9 only
  7755. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7756. // send back message to the speaker
  7757. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7758. WFIFOW(fd,0) = 0x8e;
  7759. WFIFOSET(fd, WFIFOW(fd,2));
  7760. #ifdef PCRE_SUPPORT
  7761. // trigger listening npcs
  7762. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  7763. #endif
  7764. // check for special supernovice phrase
  7765. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE )
  7766. {
  7767. unsigned int next = pc_nextbaseexp(sd);
  7768. if( next == 0 ) next = pc_thisbaseexp(sd);
  7769. if( get_percentage(sd->status.base_exp, next)% 10 == 0 ) // 0%, 10%, 20%, ...
  7770. {
  7771. switch (sd->state.snovice_call_flag) {
  7772. case 0:
  7773. if( strstr(message, msg_txt(504)) ) // "Guardian Angel, can you hear my voice? ^^;"
  7774. sd->state.snovice_call_flag++;
  7775. break;
  7776. case 1: {
  7777. char buf[256];
  7778. sprintf(buf, msg_txt(505), sd->status.name);
  7779. if( strstr(message, buf) ) // "My name is %s, and I'm a Super Novice~"
  7780. sd->state.snovice_call_flag++;
  7781. }
  7782. break;
  7783. case 2:
  7784. if( strstr(message, msg_txt(506)) ) // "Please help me~ T.T"
  7785. sd->state.snovice_call_flag++;
  7786. break;
  7787. case 3:
  7788. if( skillnotok(MO_EXPLOSIONSPIRITS,sd) )
  7789. break; //Do not override the noskill mapflag. [Skotlex]
  7790. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7791. sc_start(&sd->bl,status_skill2sc(MO_EXPLOSIONSPIRITS),100,
  7792. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7793. sd->state.snovice_call_flag = 0;
  7794. break;
  7795. }
  7796. }
  7797. }
  7798. // Chat logging type 'O' / Global Chat
  7799. if( log_config.chat&1 || (log_config.chat&2 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  7800. log_chat("O", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7801. return;
  7802. }
  7803. /*==========================================
  7804. * /mm /mapmove (as @rura GM command)
  7805. *------------------------------------------*/
  7806. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  7807. {
  7808. char output[MAP_NAME_LENGTH_EXT+15]; // Max length of a short: ' -6XXXX' -> 7 digits
  7809. char message[MAP_NAME_LENGTH_EXT+15+5]; // "/mm "+output
  7810. char* map_name;
  7811. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7812. return;
  7813. if(pc_isGM(sd) < get_atcommand_level(atcommand_mapmove))
  7814. return;
  7815. map_name = (char*)RFIFOP(fd,2);
  7816. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  7817. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7818. atcommand_mapmove(fd, sd, "@mapmove", output);
  7819. if( log_config.gm && get_atcommand_level(atcommand_mapmove) >= log_config.gm )
  7820. {
  7821. sprintf(message, "/mm %s", output);
  7822. log_atcommand(sd, message);
  7823. }
  7824. return;
  7825. }
  7826. /*==========================================
  7827. *
  7828. *------------------------------------------*/
  7829. void clif_changed_dir(struct block_list *bl, enum send_target target)
  7830. {
  7831. unsigned char buf[64];
  7832. WBUFW(buf,0) = 0x9c;
  7833. WBUFL(buf,2) = bl->id;
  7834. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7835. WBUFB(buf,8) = unit_getdir(bl);
  7836. clif_send(buf, packet_len(0x9c), bl, target);
  7837. if (disguised(bl)) {
  7838. WBUFL(buf,2) = -bl->id;
  7839. WBUFW(buf,6) = 0;
  7840. clif_send(buf, packet_len(0x9c), bl, SELF);
  7841. }
  7842. return;
  7843. }
  7844. /*==========================================
  7845. *
  7846. *------------------------------------------*/
  7847. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  7848. {
  7849. unsigned char headdir, dir;
  7850. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7851. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7852. pc_setdir(sd, dir, headdir);
  7853. clif_changed_dir(&sd->bl, AREA_WOS);
  7854. return;
  7855. }
  7856. /*==========================================
  7857. *
  7858. *------------------------------------------*/
  7859. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  7860. {
  7861. int emoticon = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7862. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7863. if (emoticon == E_MUTE) {// prevent use of the mute emote [Valaris]
  7864. clif_skill_fail(sd, 1, 0, 1);
  7865. return;
  7866. }
  7867. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7868. if (sd->emotionlasttime >= time(NULL)) {
  7869. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7870. clif_skill_fail(sd, 1, 0, 1);
  7871. return;
  7872. }
  7873. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7874. if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6)
  7875. {// re-roll dice
  7876. emoticon = rand()%6+E_DICE1;
  7877. }
  7878. clif_emotion(&sd->bl, emoticon);
  7879. } else
  7880. clif_skill_fail(sd, 1, 0, 1);
  7881. }
  7882. /*==========================================
  7883. *
  7884. *------------------------------------------*/
  7885. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  7886. {
  7887. WFIFOHEAD(fd,packet_len(0xc2));
  7888. WFIFOW(fd,0) = 0xc2;
  7889. WFIFOL(fd,2) = map_getusers();
  7890. WFIFOSET(fd,packet_len(0xc2));
  7891. }
  7892. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7893. {
  7894. if (pc_isdead(sd)) {
  7895. clif_clearunit_area(&sd->bl, CLR_DEAD);
  7896. return;
  7897. }
  7898. if (sd->sc.count &&
  7899. (sd->sc.data[SC_TRICKDEAD] ||
  7900. sd->sc.data[SC_AUTOCOUNTER] ||
  7901. sd->sc.data[SC_BLADESTOP]))
  7902. return;
  7903. pc_stop_walking(sd, 1);
  7904. pc_stop_attack(sd);
  7905. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7906. target_id = sd->bl.id;
  7907. switch(action_type)
  7908. {
  7909. case 0x00: // once attack
  7910. case 0x07: // continuous attack
  7911. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  7912. return;
  7913. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  7914. return;
  7915. if( sd->sc.data[SC_BASILICA] )
  7916. return;
  7917. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7918. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7919. clif_skill_fail(sd, 1, 4, 0);
  7920. return;
  7921. }
  7922. }
  7923. pc_delinvincibletimer(sd);
  7924. sd->idletime = last_tick;
  7925. unit_attack(&sd->bl, target_id, action_type != 0);
  7926. break;
  7927. case 0x02: // sitdown
  7928. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7929. clif_skill_fail(sd, 1, 0, 2);
  7930. break;
  7931. }
  7932. if(pc_issit(sd)) {
  7933. //Bugged client? Just refresh them.
  7934. clif_sitting(&sd->bl);
  7935. return;
  7936. }
  7937. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7938. break;
  7939. if (sd->sc.count && (
  7940. sd->sc.data[SC_DANCING] ||
  7941. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  7942. )) //No sitting during these states either.
  7943. break;
  7944. pc_setsit(sd);
  7945. skill_sit(sd,1);
  7946. clif_sitting(&sd->bl);
  7947. break;
  7948. case 0x03: // standup
  7949. if (!pc_issit(sd)) {
  7950. //Bugged client? Just refresh them.
  7951. clif_standing(&sd->bl);
  7952. return;
  7953. }
  7954. pc_setstand(sd);
  7955. skill_sit(sd,0);
  7956. clif_standing(&sd->bl);
  7957. break;
  7958. }
  7959. }
  7960. /*==========================================
  7961. *
  7962. *------------------------------------------*/
  7963. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  7964. {
  7965. clif_parse_ActionRequest_sub(sd,
  7966. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7967. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7968. gettick()
  7969. );
  7970. }
  7971. /*==========================================
  7972. *
  7973. *------------------------------------------*/
  7974. void clif_parse_Restart(int fd, struct map_session_data *sd)
  7975. {
  7976. switch(RFIFOB(fd,2)) {
  7977. case 0x00:
  7978. pc_respawn(sd,CLR_RESPAWN);
  7979. break;
  7980. case 0x01:
  7981. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7982. if( !sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] && !sd->sc.data[SC_CHASEWALK] &&
  7983. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout) )
  7984. { //Send to char-server for character selection.
  7985. chrif_charselectreq(sd, session[fd]->client_addr);
  7986. } else {
  7987. WFIFOHEAD(fd,packet_len(0x18b));
  7988. WFIFOW(fd,0)=0x18b;
  7989. WFIFOW(fd,2)=1;
  7990. WFIFOSET(fd,packet_len(0x018b));
  7991. }
  7992. break;
  7993. }
  7994. }
  7995. /*==========================================
  7996. * Validates and processes whispered messages
  7997. * S 0096 <packet len>.w <nick>.24B <message>.?B
  7998. *------------------------------------------*/
  7999. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  8000. {
  8001. struct map_session_data* dstsd;
  8002. int i;
  8003. char *target, *message;
  8004. int namelen, messagelen;
  8005. // validate packet and retrieve name and message
  8006. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  8007. return;
  8008. if (is_atcommand(fd, sd, message, 1) )
  8009. return;
  8010. if (sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT))
  8011. return;
  8012. if (battle_config.min_chat_delay)
  8013. { //[Skotlex]
  8014. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  8015. return;
  8016. }
  8017. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8018. }
  8019. // Chat logging type 'W' / Whisper
  8020. if( log_config.chat&1 || (log_config.chat&4 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  8021. log_chat("W", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
  8022. //-------------------------------------------------------//
  8023. // Lordalfa - Paperboy - To whisper NPC commands //
  8024. //-------------------------------------------------------//
  8025. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  8026. {
  8027. char* str = target+4; //Skip the NPC: string part.
  8028. struct npc_data* npc;
  8029. if ((npc = npc_name2id(str)))
  8030. {
  8031. char split_data[10][50];
  8032. char *split;
  8033. char output[256];
  8034. str = message;
  8035. // skip codepage indicator, if detected
  8036. if( str[0] == '|' && strlen(str) >= 4 )
  8037. str += 3;
  8038. for( i = 0; i < 10; ++i )
  8039. {// Splits the message using '#' as separators
  8040. split = strchr(str,'#');
  8041. if( split == NULL )
  8042. { // use the remaining string
  8043. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8044. for( ++i; i < 10; ++i )
  8045. split_data[i][0] = '\0';
  8046. break;
  8047. }
  8048. *split = '\0';
  8049. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  8050. str = split+1;
  8051. }
  8052. for( i = 0; i < 10; ++i )
  8053. {
  8054. sprintf(output, "@whispervar%d$", i);
  8055. set_var(sd,output,(char *) split_data[i]);
  8056. }
  8057. sprintf(output, "%s::OnWhisperGlobal", npc->name);
  8058. npc_event(sd,output,0); // Calls the NPC label
  8059. return;
  8060. }
  8061. }
  8062. // Main chat [LuzZza]
  8063. if(strcmpi(target, main_chat_nick) == 0)
  8064. {
  8065. if(!sd->state.mainchat)
  8066. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  8067. else {
  8068. char output[256];
  8069. snprintf(output, ARRAYLENGTH(output), msg_txt(386), sd->status.name, message);
  8070. intif_broadcast2(output, strlen(output) + 1, 0xFE000000, 0, 0, 0, 0);
  8071. }
  8072. // Chat logging type 'M' / Main Chat
  8073. if( log_config.chat&1 || (log_config.chat&32 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  8074. log_chat("M", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  8075. return;
  8076. }
  8077. // searching destination character
  8078. dstsd = map_nick2sd(target);
  8079. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
  8080. {
  8081. // player is not on this map-server
  8082. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  8083. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  8084. // and if we ask for 'Test', we must not contact 'test' player
  8085. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  8086. intif_wis_message(sd, target, message, messagelen);
  8087. return;
  8088. }
  8089. // if player ignores everyone
  8090. if (dstsd->state.ignoreAll)
  8091. {
  8092. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  8093. clif_wis_end(fd, 1); // 1: target character is not loged in
  8094. else
  8095. clif_wis_end(fd, 3); // 3: everyone ignored by target
  8096. return;
  8097. }
  8098. // if player ignores the source character
  8099. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  8100. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  8101. { // source char present in ignore list
  8102. clif_wis_end(fd, 2); // 2: ignored by target
  8103. return;
  8104. }
  8105. // if player is autotrading
  8106. if( dstsd->state.autotrade == 1 )
  8107. {
  8108. char output[256];
  8109. sprintf(output, "%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  8110. clif_wis_message(fd, wisp_server_name, output, strlen(output) + 1);
  8111. return;
  8112. }
  8113. // notify sender of success
  8114. clif_wis_end(fd, 0); // 0: success to send wisper
  8115. // if player has an auto-away message
  8116. if(dstsd->away_message[0] != '\0')
  8117. {
  8118. char output[256];
  8119. sprintf(output, "%s %s", message, msg_txt(543)); // "(Automessage has been sent)"
  8120. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  8121. if(dstsd->state.autotrade)
  8122. sprintf(output, msg_txt(544), dstsd->away_message); // "Away [AT] - "%s""
  8123. else
  8124. sprintf(output, msg_txt(545), dstsd->away_message); // "Away - "%s""
  8125. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  8126. return;
  8127. }
  8128. // Normal message
  8129. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  8130. return;
  8131. }
  8132. /*==========================================
  8133. * /b /nb
  8134. * S 0099 <packet len>.w <text>.?B 00
  8135. *------------------------------------------*/
  8136. void clif_parse_Broadcast(int fd, struct map_session_data* sd)
  8137. {
  8138. char* msg = (char*)RFIFOP(fd,4);
  8139. unsigned int len = RFIFOW(fd,2)-4;
  8140. int lv;
  8141. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8142. return;
  8143. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_broadcast)) )
  8144. return;
  8145. // as the length varies depending on the command used, just block unreasonably long strings
  8146. mes_len_check(msg, len, CHAT_SIZE_MAX);
  8147. intif_broadcast(msg, len, 0);
  8148. if(log_config.gm && lv >= log_config.gm) {
  8149. char logmsg[CHAT_SIZE_MAX+4];
  8150. sprintf(logmsg, "/b %s", msg);
  8151. log_atcommand(sd, logmsg);
  8152. }
  8153. }
  8154. /*==========================================
  8155. *
  8156. *------------------------------------------*/
  8157. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  8158. {
  8159. struct flooritem_data *fitem;
  8160. int map_object_id;
  8161. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8162. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  8163. do {
  8164. if (pc_isdead(sd)) {
  8165. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8166. break;
  8167. }
  8168. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  8169. break;
  8170. if (pc_cant_act(sd))
  8171. break;
  8172. if(sd->sc.count && (
  8173. sd->sc.data[SC_HIDING] ||
  8174. sd->sc.data[SC_CLOAKING] ||
  8175. sd->sc.data[SC_TRICKDEAD] ||
  8176. sd->sc.data[SC_BLADESTOP] ||
  8177. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM))
  8178. )
  8179. break;
  8180. if (!pc_takeitem(sd, fitem))
  8181. break;
  8182. return;
  8183. } while (0);
  8184. // Client REQUIRES a fail packet or you can no longer pick items.
  8185. clif_additem(sd,0,0,6);
  8186. }
  8187. /*==========================================
  8188. *
  8189. *------------------------------------------*/
  8190. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  8191. {
  8192. int item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8193. int item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8194. for(;;) {
  8195. if (pc_isdead(sd))
  8196. break;
  8197. if (pc_cant_act(sd))
  8198. break;
  8199. if (sd->sc.count && (
  8200. sd->sc.data[SC_AUTOCOUNTER] ||
  8201. sd->sc.data[SC_BLADESTOP] ||
  8202. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  8203. ))
  8204. break;
  8205. if (!pc_dropitem(sd, item_index, item_amount))
  8206. break;
  8207. return;
  8208. }
  8209. //Because the client does not like being ignored.
  8210. clif_dropitem(sd, item_index,0);
  8211. }
  8212. /*==========================================
  8213. *
  8214. *------------------------------------------*/
  8215. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  8216. {
  8217. int n;
  8218. if (pc_isdead(sd)) {
  8219. clif_clearunit_area(&sd->bl, CLR_DEAD);
  8220. return;
  8221. }
  8222. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  8223. return;
  8224. //This flag enables you to use items while in an NPC. [Skotlex]
  8225. if (sd->npc_id) {
  8226. if (sd->npc_id != sd->npc_item_flag)
  8227. return;
  8228. } else
  8229. if (pc_istrading(sd))
  8230. return;
  8231. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  8232. sd->idletime = last_tick;
  8233. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8234. if(n <0 || n >= MAX_INVENTORY)
  8235. return;
  8236. if (!pc_useitem(sd,n))
  8237. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  8238. }
  8239. /*==========================================
  8240. *
  8241. *------------------------------------------*/
  8242. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  8243. {
  8244. int index;
  8245. if(pc_isdead(sd)) {
  8246. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8247. return;
  8248. }
  8249. index = RFIFOW(fd,2)-2;
  8250. if (index < 0 || index >= MAX_INVENTORY)
  8251. return; //Out of bounds check.
  8252. if(sd->npc_id) {
  8253. if (sd->npc_id != sd->npc_item_flag)
  8254. return;
  8255. } else if (sd->state.storage_flag || sd->sc.opt1)
  8256. ; //You can equip/unequip stuff while storage is open/under status changes
  8257. else if (pc_cant_act(sd))
  8258. return;
  8259. if(!sd->status.inventory[index].identify) {
  8260. clif_equipitemack(sd,index,0,0); // fail
  8261. return;
  8262. }
  8263. if(!sd->inventory_data[index])
  8264. return;
  8265. if(sd->inventory_data[index]->type == IT_PETARMOR){
  8266. pet_equipitem(sd,index);
  8267. return;
  8268. }
  8269. //Client doesn't send the position for ammo.
  8270. if(sd->inventory_data[index]->type == IT_AMMO)
  8271. pc_equipitem(sd,index,EQP_AMMO);
  8272. else
  8273. pc_equipitem(sd,index,RFIFOW(fd,4));
  8274. }
  8275. /*==========================================
  8276. *
  8277. *------------------------------------------*/
  8278. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  8279. {
  8280. int index;
  8281. if(pc_isdead(sd)) {
  8282. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8283. return;
  8284. }
  8285. if (sd->state.storage_flag)
  8286. ; //You can equip/unequip stuff while storage is open.
  8287. else if (pc_cant_act(sd))
  8288. return;
  8289. index = RFIFOW(fd,2)-2;
  8290. pc_unequipitem(sd,index,1);
  8291. }
  8292. /*==========================================
  8293. *
  8294. *------------------------------------------*/
  8295. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8296. {
  8297. struct block_list *bl;
  8298. if(pc_isdead(sd)) {
  8299. clif_clearunit_area(&sd->bl,CLR_DEAD);
  8300. return;
  8301. }
  8302. if (pc_cant_act(sd))
  8303. return;
  8304. bl = map_id2bl(RFIFOL(fd,2));
  8305. if (!bl) return;
  8306. switch (bl->type) {
  8307. case BL_MOB:
  8308. case BL_PC:
  8309. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8310. break;
  8311. case BL_NPC:
  8312. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  8313. npc_click(sd,(TBL_NPC*)bl);
  8314. break;
  8315. }
  8316. return;
  8317. }
  8318. /*==========================================
  8319. *
  8320. *------------------------------------------*/
  8321. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8322. {
  8323. if (sd->state.trading)
  8324. return;
  8325. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8326. }
  8327. /// Request to buy chosen items from npc shop
  8328. /// S 00c8 <length>.w {<amount>.w <itemid>.w).4b*
  8329. /// R 00ca <result>.b
  8330. /// result = 00 -> "The deal has successfully completed."
  8331. /// result = 01 -> "You do not have enough zeny."
  8332. /// result = 02 -> "You are over your Weight Limit."
  8333. /// result = 03 -> "Out of the maximum capacity, you have too many items."
  8334. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  8335. {
  8336. int n = (RFIFOW(fd,2)-4) /4;
  8337. unsigned short* item_list = (unsigned short*)RFIFOP(fd,4);
  8338. int result;
  8339. if( sd->state.trading || !sd->npc_shopid )
  8340. result = 1;
  8341. else
  8342. result = npc_buylist(sd,n,item_list);
  8343. sd->npc_shopid = 0; //Clear shop data.
  8344. WFIFOHEAD(fd,packet_len(0xca));
  8345. WFIFOW(fd,0) = 0xca;
  8346. WFIFOB(fd,2) = result;
  8347. WFIFOSET(fd,packet_len(0xca));
  8348. }
  8349. /// Request to sell chosen items to npc shop
  8350. /// R 00c9 <packet len>.W {<index>.W <amount>.W}.4B*
  8351. /// S 00cb <result>.B
  8352. /// result = 00 -> "The deal has successfully completed."
  8353. /// result = 01 -> "The deal has failed."
  8354. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8355. {
  8356. int fail=0,n;
  8357. unsigned short *item_list;
  8358. n = (RFIFOW(fd,2)-4) /4;
  8359. item_list = (unsigned short*)RFIFOP(fd,4);
  8360. if (sd->state.trading || !sd->npc_shopid)
  8361. fail = 1;
  8362. else
  8363. fail = npc_selllist(sd,n,item_list);
  8364. sd->npc_shopid = 0; //Clear shop data.
  8365. WFIFOHEAD(fd,packet_len(0xcb));
  8366. WFIFOW(fd,0)=0xcb;
  8367. WFIFOB(fd,2)=fail;
  8368. WFIFOSET(fd,packet_len(0xcb));
  8369. }
  8370. /*==========================================
  8371. * Chatroom creation request
  8372. * S 00d5 <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  8373. *------------------------------------------*/
  8374. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  8375. {
  8376. int len = RFIFOW(fd,2)-15;
  8377. int limit = RFIFOW(fd,4);
  8378. bool pub = (RFIFOB(fd,6) != 0);
  8379. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  8380. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8381. char s_password[CHATROOM_PASS_SIZE];
  8382. char s_title[CHATROOM_TITLE_SIZE];
  8383. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  8384. return;
  8385. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  8386. clif_skill_fail(sd,1,0,3);
  8387. return;
  8388. }
  8389. if( len <= 0 )
  8390. return; // invalid input
  8391. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8392. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8393. chat_createpcchat(sd, s_title, s_password, limit, pub);
  8394. }
  8395. /*==========================================
  8396. * Chatroom join request
  8397. * S 00d9 <chat ID>.l <passwd>.8B
  8398. *------------------------------------------*/
  8399. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  8400. {
  8401. int chatid = RFIFOL(fd,2);
  8402. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  8403. chat_joinchat(sd,chatid,password);
  8404. }
  8405. /*==========================================
  8406. * Chatroom properties adjustment request
  8407. * S 00de <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  8408. *------------------------------------------*/
  8409. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  8410. {
  8411. int len = RFIFOW(fd,2)-15;
  8412. int limit = RFIFOW(fd,4);
  8413. bool pub = (RFIFOB(fd,6) != 0);
  8414. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  8415. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  8416. char s_password[CHATROOM_PASS_SIZE];
  8417. char s_title[CHATROOM_TITLE_SIZE];
  8418. if( len <= 0 )
  8419. return; // invalid input
  8420. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  8421. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE)); //NOTE: assumes that safestrncpy will not access the len+1'th byte
  8422. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  8423. }
  8424. /*==========================================
  8425. * S 00e0 ?.l <nick>.24B
  8426. *------------------------------------------*/
  8427. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  8428. {
  8429. //TODO: the first argument seems to be the destination position (always 0) [ultramage]
  8430. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8431. }
  8432. /*==========================================
  8433. *
  8434. *------------------------------------------*/
  8435. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8436. {
  8437. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8438. }
  8439. /*==========================================
  8440. * Request to leave the current chatroom
  8441. * S 00e3
  8442. *------------------------------------------*/
  8443. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  8444. {
  8445. chat_leavechat(sd,0);
  8446. }
  8447. //Handles notifying asker and rejecter of what has just ocurred.
  8448. //Type is used to determine the correct msg_txt to use:
  8449. //0:
  8450. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  8451. {
  8452. char *msg, output[256];
  8453. // Your request has been rejected by autoreject option.
  8454. msg = msg_txt(392);
  8455. clif_disp_onlyself(src, msg, strlen(msg));
  8456. //Notice that a request was rejected.
  8457. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  8458. clif_disp_onlyself(target, output, strlen(output));
  8459. }
  8460. /*==========================================
  8461. * 取引要請を相手に送る
  8462. *------------------------------------------*/
  8463. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8464. {
  8465. struct map_session_data *t_sd;
  8466. t_sd = map_id2sd(RFIFOL(fd,2));
  8467. if(!sd->chatID && pc_cant_act(sd))
  8468. return; //You can trade while in a chatroom.
  8469. // @noask [LuzZza]
  8470. if(t_sd && t_sd->state.noask) {
  8471. clif_noask_sub(sd, t_sd, 0);
  8472. return;
  8473. }
  8474. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1)
  8475. {
  8476. clif_skill_fail(sd,1,0,0);
  8477. return;
  8478. }
  8479. trade_traderequest(sd,t_sd);
  8480. }
  8481. /*==========================================
  8482. * 取引要請
  8483. *------------------------------------------*/
  8484. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8485. {
  8486. trade_tradeack(sd,RFIFOB(fd,2));
  8487. }
  8488. /*==========================================
  8489. * アイテム追加
  8490. *------------------------------------------*/
  8491. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8492. {
  8493. short index = RFIFOW(fd,2);
  8494. int amount = RFIFOL(fd,4);
  8495. if( index == 0 )
  8496. trade_tradeaddzeny(sd, amount);
  8497. else
  8498. trade_tradeadditem(sd, index, (short)amount);
  8499. }
  8500. /*==========================================
  8501. * アイテム追加完了(ok押し)
  8502. *------------------------------------------*/
  8503. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8504. {
  8505. trade_tradeok(sd);
  8506. }
  8507. /*==========================================
  8508. * 取引キャンセル
  8509. *------------------------------------------*/
  8510. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8511. {
  8512. trade_tradecancel(sd);
  8513. }
  8514. /*==========================================
  8515. * 取引許諾(trade押し)
  8516. *------------------------------------------*/
  8517. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8518. {
  8519. trade_tradecommit(sd);
  8520. }
  8521. /*==========================================
  8522. *
  8523. *------------------------------------------*/
  8524. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8525. {
  8526. pc_stop_attack(sd);
  8527. }
  8528. /*==========================================
  8529. * カートへアイテムを移す
  8530. *------------------------------------------*/
  8531. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8532. {
  8533. if (pc_istrading(sd))
  8534. return;
  8535. if (!pc_iscarton(sd))
  8536. return;
  8537. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8538. }
  8539. /*==========================================
  8540. * カートからアイテムを出す
  8541. *------------------------------------------*/
  8542. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8543. {
  8544. if (!pc_iscarton(sd))
  8545. return;
  8546. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8547. }
  8548. /*==========================================
  8549. * 付属品(鷹,ペコ,カート)をはずす
  8550. *------------------------------------------*/
  8551. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8552. {
  8553. //Can only remove Cart/Riding/Falcon.
  8554. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  8555. }
  8556. /*==========================================
  8557. * チェンジカート
  8558. *------------------------------------------*/
  8559. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8560. {
  8561. int type;
  8562. if( sd && pc_checkskill(sd, MC_CHANGECART) < 1 )
  8563. return;
  8564. type = (int)RFIFOW(fd,2);
  8565. if( (type == 5 && sd->status.base_level > 90) ||
  8566. (type == 4 && sd->status.base_level > 80) ||
  8567. (type == 3 && sd->status.base_level > 65) ||
  8568. (type == 2 && sd->status.base_level > 40) ||
  8569. (type == 1))
  8570. pc_setcart(sd,type);
  8571. }
  8572. /*==========================================
  8573. * ステータスアップ
  8574. *------------------------------------------*/
  8575. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8576. {
  8577. pc_statusup(sd,RFIFOW(fd,2));
  8578. }
  8579. /*==========================================
  8580. * スキルレベルアップ
  8581. *------------------------------------------*/
  8582. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8583. {
  8584. pc_skillup(sd,RFIFOW(fd,2));
  8585. }
  8586. 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)
  8587. {
  8588. int lv;
  8589. if( !hd )
  8590. return;
  8591. if( skillnotok_hom(skillnum, hd) )
  8592. return;
  8593. if( hd->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8594. target_id = hd->bl.id;
  8595. if( hd->ud.skilltimer != -1 )
  8596. {
  8597. if( skillnum != SA_CASTCANCEL ) return;
  8598. }
  8599. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  8600. return;
  8601. lv = merc_hom_checkskill(hd, skillnum);
  8602. if( skilllv > lv )
  8603. skilllv = lv;
  8604. if( skilllv )
  8605. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  8606. }
  8607. 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)
  8608. {
  8609. int lv;
  8610. if( !md )
  8611. return;
  8612. if( skillnotok_mercenary(skillnum, md) )
  8613. return;
  8614. if( md->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8615. target_id = md->bl.id;
  8616. if( md->ud.skilltimer != INVALID_TIMER )
  8617. {
  8618. if( skillnum != SA_CASTCANCEL ) return;
  8619. }
  8620. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  8621. return;
  8622. lv = mercenary_checkskill(md, skillnum);
  8623. if( skilllv > lv )
  8624. skilllv = lv;
  8625. if( skilllv )
  8626. unit_skilluse_id(&md->bl, target_id, skillnum, skilllv);
  8627. }
  8628. 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)
  8629. {
  8630. int lv;
  8631. if( !md )
  8632. return;
  8633. if( skillnotok_mercenary(skillnum, md) )
  8634. return;
  8635. if( md->ud.skilltimer != INVALID_TIMER )
  8636. return;
  8637. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  8638. {
  8639. clif_skill_fail(md->master, skillnum, 4, 0);
  8640. return;
  8641. }
  8642. if( md->sc.data[SC_BASILICA] )
  8643. return;
  8644. lv = mercenary_checkskill(md, skillnum);
  8645. if( skilllv > lv )
  8646. skilllv = lv;
  8647. if( skilllv )
  8648. unit_skilluse_pos(&md->bl, x, y, skillnum, skilllv);
  8649. }
  8650. /*==========================================
  8651. * スキル使用(ID指定)
  8652. *------------------------------------------*/
  8653. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  8654. {
  8655. short skillnum, skilllv;
  8656. int tmp, target_id;
  8657. unsigned int tick = gettick();
  8658. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8659. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8660. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8661. if( skilllv < 1 ) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8662. tmp = skill_get_inf(skillnum);
  8663. if (tmp&INF_GROUND_SKILL || !tmp)
  8664. return; //Using a ground/passive skill on a target? WRONG.
  8665. if( skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE + MAX_HOMUNSKILL )
  8666. {
  8667. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  8668. return;
  8669. }
  8670. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  8671. {
  8672. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skillnum, skilllv, target_id);
  8673. return;
  8674. }
  8675. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8676. sd->idletime = last_tick;
  8677. if( pc_cant_act(sd) )
  8678. return;
  8679. if( pc_issit(sd) )
  8680. return;
  8681. if( skillnotok(skillnum, sd) )
  8682. return;
  8683. if( sd->bl.id != target_id && (tmp&INF_SELF_SKILL || sd->state.combo) )
  8684. target_id = sd->bl.id; // never trust the client
  8685. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  8686. target_id = sd->bl.id;
  8687. if( sd->ud.skilltimer != -1 )
  8688. {
  8689. if( skillnum != SA_CASTCANCEL )
  8690. return;
  8691. }
  8692. else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  8693. {
  8694. if( sd->skillitem != skillnum )
  8695. {
  8696. clif_skill_fail(sd, skillnum, 4, 0);
  8697. return;
  8698. }
  8699. }
  8700. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8701. return;
  8702. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  8703. return; // On basilica only caster can use Basilica again to stop it.
  8704. if( sd->menuskill_id )
  8705. {
  8706. if( sd->menuskill_id == SA_TAMINGMONSTER )
  8707. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8708. else if( sd->menuskill_id != SA_AUTOSPELL )
  8709. return; //Can't use skills while a menu is open.
  8710. }
  8711. if( sd->skillitem == skillnum )
  8712. {
  8713. if( skilllv != sd->skillitemlv )
  8714. skilllv = sd->skillitemlv;
  8715. if( !(tmp&INF_SELF_SKILL) )
  8716. pc_delinvincibletimer(sd); // Target skills thru items cancel invincibility. [Inkfish]
  8717. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8718. return;
  8719. }
  8720. sd->skillitem = sd->skillitemlv = 0;
  8721. if( skillnum >= GD_SKILLBASE )
  8722. {
  8723. if( sd->state.gmaster_flag )
  8724. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8725. else
  8726. skilllv = 0;
  8727. }
  8728. else
  8729. {
  8730. tmp = pc_checkskill(sd, skillnum);
  8731. if( skilllv > tmp )
  8732. skilllv = tmp;
  8733. }
  8734. pc_delinvincibletimer(sd);
  8735. if( skilllv )
  8736. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8737. }
  8738. /*==========================================
  8739. * スキル使用(場所指定)
  8740. *------------------------------------------*/
  8741. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, short skilllv, short skillnum, short x, short y, int skillmoreinfo)
  8742. {
  8743. int lv;
  8744. unsigned int tick = gettick();
  8745. if( !(skill_get_inf(skillnum)&INF_GROUND_SKILL) )
  8746. return; //Using a target skill on the ground? WRONG.
  8747. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  8748. {
  8749. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skillnum, skilllv, x, y, skillmoreinfo);
  8750. return;
  8751. }
  8752. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8753. sd->idletime = last_tick;
  8754. if( skillnotok(skillnum, sd) )
  8755. return;
  8756. if( skillmoreinfo != -1 )
  8757. {
  8758. if( pc_issit(sd) )
  8759. {
  8760. clif_skill_fail(sd, skillnum, 0, 0);
  8761. return;
  8762. }
  8763. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  8764. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8765. }
  8766. if( sd->ud.skilltimer != -1 )
  8767. return;
  8768. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  8769. {
  8770. if( sd->skillitem != skillnum )
  8771. {
  8772. clif_skill_fail(sd, skillnum, 4, 0);
  8773. return;
  8774. }
  8775. }
  8776. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8777. return;
  8778. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  8779. return; // On basilica only caster can use Basilica again to stop it.
  8780. if( sd->menuskill_id )
  8781. {
  8782. if( sd->menuskill_id == SA_TAMINGMONSTER )
  8783. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8784. else if( sd->menuskill_id != SA_AUTOSPELL )
  8785. return; //Can't use skills while a menu is open.
  8786. }
  8787. pc_delinvincibletimer(sd);
  8788. if( sd->skillitem == skillnum )
  8789. {
  8790. if( skilllv != sd->skillitemlv )
  8791. skilllv = sd->skillitemlv;
  8792. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8793. }
  8794. else
  8795. {
  8796. sd->skillitem = sd->skillitemlv = 0;
  8797. if( (lv = pc_checkskill(sd, skillnum)) > 0 )
  8798. {
  8799. if( skilllv > lv )
  8800. skilllv = lv;
  8801. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8802. }
  8803. }
  8804. }
  8805. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  8806. {
  8807. if (pc_cant_act(sd))
  8808. return;
  8809. if (pc_issit(sd))
  8810. return;
  8811. clif_parse_UseSkillToPosSub(fd, sd,
  8812. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8813. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8814. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8815. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8816. -1 //Skill more info.
  8817. );
  8818. }
  8819. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  8820. {
  8821. if (pc_cant_act(sd))
  8822. return;
  8823. if (pc_issit(sd))
  8824. return;
  8825. clif_parse_UseSkillToPosSub(fd, sd,
  8826. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8827. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8828. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8829. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8830. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8831. );
  8832. }
  8833. /*==========================================
  8834. * スキル使用(map指定)
  8835. *------------------------------------------*/
  8836. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  8837. {
  8838. short skill_num = RFIFOW(fd,2);
  8839. char map_name[MAP_NAME_LENGTH];
  8840. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  8841. if(skill_num != sd->menuskill_id)
  8842. return;
  8843. if( pc_cant_act(sd) )
  8844. {
  8845. sd->menuskill_id = sd->menuskill_val = 0;
  8846. return;
  8847. }
  8848. pc_delinvincibletimer(sd);
  8849. skill_castend_map(sd,skill_num,map_name);
  8850. }
  8851. /*==========================================
  8852. * メモ要求
  8853. *------------------------------------------*/
  8854. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8855. {
  8856. if (!pc_isdead(sd))
  8857. pc_memo(sd,-1);
  8858. }
  8859. /*==========================================
  8860. * アイテム合成
  8861. *------------------------------------------*/
  8862. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8863. {
  8864. if (sd->menuskill_id != AM_PHARMACY)
  8865. return;
  8866. if (pc_istrading(sd)) {
  8867. //Make it fail to avoid shop exploits where you sell something different than you see.
  8868. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8869. sd->menuskill_val = sd->menuskill_id = 0;
  8870. return;
  8871. }
  8872. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8873. sd->menuskill_val = sd->menuskill_id = 0;
  8874. }
  8875. /*==========================================
  8876. *
  8877. *------------------------------------------*/
  8878. void clif_parse_Cooking(int fd,struct map_session_data *sd)
  8879. {
  8880. //int type = RFIFOW(fd,2); // '1' for cooking, but what do other values mean?
  8881. int nameid = RFIFOW(fd,4);
  8882. if( sd->menuskill_id != AM_PHARMACY )
  8883. {
  8884. return;
  8885. }
  8886. if (pc_istrading(sd)) {
  8887. //Make it fail to avoid shop exploits where you sell something different than you see.
  8888. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8889. sd->menuskill_val = sd->menuskill_id = 0;
  8890. return;
  8891. }
  8892. skill_produce_mix(sd,0,nameid,0,0,0,1);
  8893. sd->menuskill_val = sd->menuskill_id = 0;
  8894. }
  8895. /*==========================================
  8896. * 武器修理
  8897. *------------------------------------------*/
  8898. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8899. {
  8900. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8901. return;
  8902. if (pc_istrading(sd)) {
  8903. //Make it fail to avoid shop exploits where you sell something different than you see.
  8904. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8905. sd->menuskill_val = sd->menuskill_id = 0;
  8906. return;
  8907. }
  8908. skill_repairweapon(sd,RFIFOW(fd,2));
  8909. sd->menuskill_val = sd->menuskill_id = 0;
  8910. }
  8911. /*==========================================
  8912. *
  8913. *------------------------------------------*/
  8914. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  8915. {
  8916. int idx;
  8917. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8918. return;
  8919. if (pc_istrading(sd)) {
  8920. //Make it fail to avoid shop exploits where you sell something different than you see.
  8921. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8922. sd->menuskill_val = sd->menuskill_id = 0;
  8923. return;
  8924. }
  8925. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8926. skill_weaponrefine(sd, idx-2);
  8927. sd->menuskill_val = sd->menuskill_id = 0;
  8928. }
  8929. /*==========================================
  8930. *
  8931. *------------------------------------------*/
  8932. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8933. {
  8934. int npc_id = RFIFOL(fd,2);
  8935. uint8 select = RFIFOB(fd,6);
  8936. if( (select > sd->npc_menu && select != 0xff) || select == 0 )
  8937. {
  8938. TBL_NPC* nd = map_id2nd(npc_id);
  8939. 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);
  8940. clif_GM_kick(NULL,sd);
  8941. return;
  8942. }
  8943. sd->npc_menu = select;
  8944. npc_scriptcont(sd,npc_id);
  8945. }
  8946. /*==========================================
  8947. *
  8948. *------------------------------------------*/
  8949. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8950. {
  8951. npc_scriptcont(sd,RFIFOL(fd,2));
  8952. }
  8953. /*==========================================
  8954. * Value entered into a NPC input box.
  8955. * S 0143 <npcID>.l <amount>.l
  8956. *------------------------------------------*/
  8957. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8958. {
  8959. int npcid = RFIFOL(fd,2);
  8960. int amount = (int)RFIFOL(fd,6);
  8961. sd->npc_amount = amount;
  8962. npc_scriptcont(sd, npcid);
  8963. }
  8964. /*==========================================
  8965. * Text entered into a NPC input box.
  8966. * S 01d5 <len>.w <npcID>.l <input>.?B 00
  8967. *------------------------------------------*/
  8968. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  8969. {
  8970. int message_len = RFIFOW(fd,2)-8;
  8971. int npcid = RFIFOL(fd,4);
  8972. const char* message = (char*)RFIFOP(fd,8);
  8973. if( message_len <= 0 )
  8974. return; // invalid input
  8975. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  8976. npc_scriptcont(sd, npcid);
  8977. }
  8978. /*==========================================
  8979. *
  8980. *------------------------------------------*/
  8981. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8982. {
  8983. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8984. return;
  8985. npc_scriptcont(sd,RFIFOL(fd,2));
  8986. }
  8987. /*==========================================
  8988. * アイテム鑑定
  8989. *------------------------------------------*/
  8990. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8991. {
  8992. short idx = RFIFOW(fd,2);
  8993. if (sd->menuskill_id != MC_IDENTIFY)
  8994. return;
  8995. if( idx == -1 )
  8996. {// cancel pressed
  8997. return;
  8998. }
  8999. skill_identify(sd,idx-2);
  9000. sd->menuskill_val = sd->menuskill_id = 0;
  9001. }
  9002. /*==========================================
  9003. * 矢作成
  9004. *------------------------------------------*/
  9005. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  9006. {
  9007. if (sd->menuskill_id != AC_MAKINGARROW)
  9008. return;
  9009. if (pc_istrading(sd)) {
  9010. //Make it fail to avoid shop exploits where you sell something different than you see.
  9011. clif_skill_fail(sd,sd->ud.skillid,0,0);
  9012. sd->menuskill_val = sd->menuskill_id = 0;
  9013. return;
  9014. }
  9015. skill_arrow_create(sd,RFIFOW(fd,2));
  9016. sd->menuskill_val = sd->menuskill_id = 0;
  9017. }
  9018. /*==========================================
  9019. * オートスペル受信
  9020. *------------------------------------------*/
  9021. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  9022. {
  9023. if (sd->menuskill_id != SA_AUTOSPELL)
  9024. return;
  9025. skill_autospell(sd,RFIFOW(fd,2));
  9026. sd->menuskill_val = sd->menuskill_id = 0;
  9027. }
  9028. /*==========================================
  9029. * カード使用
  9030. *------------------------------------------*/
  9031. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  9032. {
  9033. if (sd->state.trading != 0)
  9034. return;
  9035. clif_use_card(sd,RFIFOW(fd,2)-2);
  9036. }
  9037. /*==========================================
  9038. * カード挿入装備選択
  9039. *------------------------------------------*/
  9040. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  9041. {
  9042. if (sd->state.trading != 0)
  9043. return;
  9044. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  9045. }
  9046. /*==========================================
  9047. * 0193 キャラID名前引き
  9048. *------------------------------------------*/
  9049. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  9050. {
  9051. int charid;
  9052. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9053. map_reqnickdb(sd, charid);
  9054. }
  9055. /*==========================================
  9056. * 0197 /resetskill /resetstate
  9057. *------------------------------------------*/
  9058. void clif_parse_ResetChar(int fd, struct map_session_data *sd)
  9059. {
  9060. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9061. return;
  9062. if( pc_isGM(sd) < get_atcommand_level(atcommand_reset) )
  9063. return;
  9064. if( RFIFOW(fd,2) )
  9065. pc_resetskill(sd,1);
  9066. else
  9067. pc_resetstate(sd);
  9068. if( log_config.gm && get_atcommand_level(atcommand_reset) >= log_config.gm )
  9069. log_atcommand(sd, RFIFOW(fd,2) ? "/resetskill" : "/resetstate");
  9070. }
  9071. /*==========================================
  9072. * /lb /nlb
  9073. * S 019c <packet len>.w <text>.?B 00
  9074. *------------------------------------------*/
  9075. void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
  9076. {
  9077. char* msg = (char*)RFIFOP(fd,4);
  9078. unsigned int len = RFIFOW(fd,2)-4;
  9079. int lv;
  9080. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9081. return;
  9082. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_localbroadcast)) )
  9083. return;
  9084. // as the length varies depending on the command used, just block unreasonably long strings
  9085. mes_len_check(msg, len, CHAT_SIZE_MAX);
  9086. clif_broadcast(&sd->bl, msg, len, 0, ALL_SAMEMAP);
  9087. if( log_config.gm && lv >= log_config.gm ) {
  9088. char logmsg[CHAT_SIZE_MAX+5];
  9089. sprintf(logmsg, "/lb %s", msg);
  9090. log_atcommand(sd, logmsg);
  9091. }
  9092. }
  9093. /*==========================================
  9094. * カプラ倉庫へ入れる
  9095. *------------------------------------------*/
  9096. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  9097. {
  9098. int item_index, item_amount;
  9099. if (pc_istrading(sd))
  9100. return;
  9101. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  9102. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9103. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  9104. return;
  9105. if (sd->state.storage_flag == 1)
  9106. storage_storageadd(sd, item_index, item_amount);
  9107. else
  9108. if (sd->state.storage_flag == 2)
  9109. storage_guild_storageadd(sd, item_index, item_amount);
  9110. }
  9111. /*==========================================
  9112. * カプラ倉庫から出す
  9113. *------------------------------------------*/
  9114. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  9115. {
  9116. int item_index, item_amount;
  9117. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  9118. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  9119. if (sd->state.storage_flag == 1)
  9120. storage_storageget(sd, item_index, item_amount);
  9121. else
  9122. if(sd->state.storage_flag == 2)
  9123. storage_guild_storageget(sd, item_index, item_amount);
  9124. }
  9125. /*==========================================
  9126. * カプラ倉庫へカートから入れる
  9127. *------------------------------------------*/
  9128. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  9129. {
  9130. if(sd->vender_id)
  9131. return;
  9132. if (!pc_iscarton(sd))
  9133. return;
  9134. if (sd->state.storage_flag == 1)
  9135. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9136. else
  9137. if (sd->state.storage_flag == 2)
  9138. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  9139. }
  9140. /*==========================================
  9141. * カプラ倉庫から出す
  9142. *------------------------------------------*/
  9143. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  9144. {
  9145. if (sd->vender_id)
  9146. return;
  9147. if (!pc_iscarton(sd))
  9148. return;
  9149. if (sd->state.storage_flag == 1)
  9150. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9151. else
  9152. if (sd->state.storage_flag == 2)
  9153. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  9154. }
  9155. /*==========================================
  9156. * カプラ倉庫を閉じる
  9157. *------------------------------------------*/
  9158. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  9159. {
  9160. if( sd->state.storage_flag == 1 )
  9161. storage_storageclose(sd);
  9162. else
  9163. if( sd->state.storage_flag == 2 )
  9164. storage_guild_storageclose(sd);
  9165. }
  9166. /*==========================================
  9167. * Kafra storage protection password system
  9168. *------------------------------------------*/
  9169. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  9170. {
  9171. //TODO
  9172. }
  9173. /*==========================================
  9174. * Party creation request
  9175. * S 00f9 <party name>.24S
  9176. * S 01e8 <party name>.24S <share flag>.B <share type>.B
  9177. *------------------------------------------*/
  9178. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  9179. {
  9180. char* name = (char*)RFIFOP(fd,2);
  9181. name[NAME_LENGTH-1] = '\0';
  9182. if( map[sd->bl.m].flag.partylock )
  9183. {// Party locked.
  9184. clif_displaymessage(fd, msg_txt(227));
  9185. return;
  9186. }
  9187. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  9188. {
  9189. clif_skill_fail(sd,1,0,4);
  9190. return;
  9191. }
  9192. party_create(sd,name,0,0);
  9193. }
  9194. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  9195. {
  9196. char* name = (char*)RFIFOP(fd,2);
  9197. int item1 = RFIFOB(fd,26);
  9198. int item2 = RFIFOB(fd,27);
  9199. name[NAME_LENGTH-1] = '\0';
  9200. if( map[sd->bl.m].flag.partylock )
  9201. {// Party locked.
  9202. clif_displaymessage(fd, msg_txt(227));
  9203. return;
  9204. }
  9205. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  9206. {
  9207. clif_skill_fail(sd,1,0,4);
  9208. return;
  9209. }
  9210. party_create(sd,name,item1,item2);
  9211. }
  9212. /*==========================================
  9213. * Party invitation request
  9214. * S 00fc <account ID>.L
  9215. * S 02c4 <char name>.24S
  9216. *------------------------------------------*/
  9217. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  9218. {
  9219. struct map_session_data *t_sd;
  9220. if(map[sd->bl.m].flag.partylock)
  9221. {// Party locked.
  9222. clif_displaymessage(fd, msg_txt(227));
  9223. return;
  9224. }
  9225. t_sd = map_id2sd(RFIFOL(fd,2));
  9226. if(t_sd && t_sd->state.noask)
  9227. {// @noask [LuzZza]
  9228. clif_noask_sub(sd, t_sd, 1);
  9229. return;
  9230. }
  9231. party_invite(sd, t_sd);
  9232. }
  9233. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  9234. {
  9235. struct map_session_data *t_sd;
  9236. char *name = (char*)RFIFOP(fd,2);
  9237. name[NAME_LENGTH-1] = '\0';
  9238. if(map[sd->bl.m].flag.partylock)
  9239. {// Party locked.
  9240. clif_displaymessage(fd, msg_txt(227));
  9241. return;
  9242. }
  9243. t_sd = map_nick2sd(name);
  9244. if(t_sd && t_sd->state.noask)
  9245. {// @noask [LuzZza]
  9246. clif_noask_sub(sd, t_sd, 1);
  9247. return;
  9248. }
  9249. party_invite(sd, t_sd);
  9250. }
  9251. /*==========================================
  9252. * Party invitation reply
  9253. * S 00ff <account ID>.L <flag>.L
  9254. * S 02c7 <account ID>.L <flag>.B
  9255. * flag: 0-reject, 1-accept
  9256. *------------------------------------------*/
  9257. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  9258. {
  9259. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9260. }
  9261. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  9262. {
  9263. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9264. }
  9265. /*==========================================
  9266. * パーティ脱退要求
  9267. *------------------------------------------*/
  9268. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  9269. {
  9270. if(map[sd->bl.m].flag.partylock)
  9271. { //Guild locked.
  9272. clif_displaymessage(fd, msg_txt(227));
  9273. return;
  9274. }
  9275. party_leave(sd);
  9276. }
  9277. /*==========================================
  9278. * パーティ除名要求
  9279. *------------------------------------------*/
  9280. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  9281. {
  9282. if(map[sd->bl.m].flag.partylock)
  9283. { //Guild locked.
  9284. clif_displaymessage(fd, msg_txt(227));
  9285. return;
  9286. }
  9287. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  9288. }
  9289. /*==========================================
  9290. * パーティ設定変更要求
  9291. *------------------------------------------*/
  9292. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  9293. {
  9294. struct party_data *p;
  9295. int i;
  9296. if( !sd->status.party_id )
  9297. return;
  9298. p = party_search(sd->status.party_id);
  9299. if( p == NULL )
  9300. return;
  9301. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  9302. if( i == MAX_PARTY )
  9303. return; //Shouldn't happen
  9304. if( !p->party.member[i].leader )
  9305. return;
  9306. #if PACKETVER < 20090603
  9307. //Client can't change the item-field
  9308. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  9309. #else
  9310. party_changeoption(sd, RFIFOL(fd,2), ((RFIFOB(fd,6)?1:0)+(RFIFOB(fd,7)?2:0)));
  9311. #endif
  9312. }
  9313. /*==========================================
  9314. * Validates and processes party messages
  9315. * S 0108 <packet len>.w <text>.?B (<name> : <message>) 00
  9316. *------------------------------------------*/
  9317. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  9318. {
  9319. const char* text = (char*)RFIFOP(fd,4);
  9320. int textlen = RFIFOW(fd,2) - 4;
  9321. char *name, *message;
  9322. int namelen, messagelen;
  9323. // validate packet and retrieve name and message
  9324. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9325. return;
  9326. if( is_atcommand(fd, sd, message, 1) )
  9327. return;
  9328. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  9329. return;
  9330. if( battle_config.min_chat_delay )
  9331. { //[Skotlex]
  9332. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9333. return;
  9334. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9335. }
  9336. party_send_message(sd, text, textlen);
  9337. }
  9338. /*==========================================
  9339. * Changes Party Leader
  9340. * S 07da <account ID>.L
  9341. *------------------------------------------*/
  9342. void clif_parse_PartyChangeLeader(int fd, struct map_session_data* sd)
  9343. {
  9344. party_changeleader(sd, map_id2sd(RFIFOL(fd,2)));
  9345. }
  9346. /*==========================================
  9347. * Party Booking in KRO [Spiria]
  9348. *------------------------------------------*/
  9349. void clif_parse_PartyBookingRegisterReq(int fd, struct map_session_data* sd)
  9350. {
  9351. short level = RFIFOW(fd,2);
  9352. short mapid = RFIFOW(fd,4);
  9353. short job[PARTY_BOOKING_JOBS];
  9354. int i;
  9355. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9356. job[i] = RFIFOB(fd,6+i*2);
  9357. party_booking_register(sd, level, mapid, job);
  9358. }
  9359. /*==========================================
  9360. * flag: 0 - success, 1 - failed
  9361. *------------------------------------------*/
  9362. void clif_PartyBookingRegisterAck(struct map_session_data *sd, int flag)
  9363. {
  9364. int fd = sd->fd;
  9365. WFIFOHEAD(fd,packet_len(0x803));
  9366. WFIFOW(fd,0) = 0x803;
  9367. WFIFOW(fd,2) = flag;
  9368. WFIFOSET(fd,packet_len(0x803));
  9369. }
  9370. void clif_parse_PartyBookingSearchReq(int fd, struct map_session_data* sd)
  9371. {
  9372. short level = RFIFOW(fd,2);
  9373. short mapid = RFIFOW(fd,4);
  9374. short job = RFIFOW(fd,6);
  9375. unsigned long lastindex = RFIFOL(fd,8);
  9376. short resultcount = RFIFOB(fd,12);
  9377. party_booking_search(sd, level, mapid, job, lastindex, resultcount);
  9378. }
  9379. /*==========================================
  9380. * more_result: 0 - no more, 1 - more
  9381. *------------------------------------------*/
  9382. void clif_PartyBookingSearchAck(int fd, struct party_booking_ad_info** results, int count, bool more_result)
  9383. {
  9384. int i, j;
  9385. int size = sizeof(struct party_booking_ad_info); // structure size (48)
  9386. struct party_booking_ad_info *pb_ad;
  9387. WFIFOHEAD(fd,size*count + 5);
  9388. WFIFOW(fd,0) = 0x805;
  9389. WFIFOW(fd,2) = size*count + 5;
  9390. WFIFOB(fd,4) = more_result;
  9391. for(i=0; i<count; i++)
  9392. {
  9393. pb_ad = results[i];
  9394. WFIFOL(fd,i*size+5) = pb_ad->index;
  9395. memcpy(WFIFOP(fd,i*size+9),pb_ad->charname,NAME_LENGTH);
  9396. WFIFOL(fd,i*size+33) = pb_ad->starttime;
  9397. WFIFOW(fd,i*size+37) = pb_ad->p_detail.level;
  9398. WFIFOW(fd,i*size+39) = pb_ad->p_detail.mapid;
  9399. for(j=0; j<PARTY_BOOKING_JOBS; j++)
  9400. WFIFOW(fd,i*size+41+j*2) = pb_ad->p_detail.job[j];
  9401. }
  9402. WFIFOSET(fd,WFIFOW(fd,2));
  9403. }
  9404. void clif_parse_PartyBookingDeleteReq(int fd, struct map_session_data* sd)
  9405. {
  9406. if(party_booking_delete(sd))
  9407. clif_PartyBookingDeleteAck(sd, 0);
  9408. }
  9409. /*==========================================
  9410. * flag: 0 - success, other - failed
  9411. *------------------------------------------*/
  9412. void clif_PartyBookingDeleteAck(struct map_session_data* sd, int flag)
  9413. {
  9414. int fd = sd->fd;
  9415. WFIFOHEAD(fd,packet_len(0x807));
  9416. WFIFOW(fd,0) = 0x807;
  9417. WFIFOW(fd,2) = flag;
  9418. WFIFOSET(fd,packet_len(0x807));
  9419. }
  9420. void clif_parse_PartyBookingUpdateReq(int fd, struct map_session_data* sd)
  9421. {
  9422. short job[PARTY_BOOKING_JOBS];
  9423. int i;
  9424. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9425. job[i] = RFIFOW(fd,2+i*2);
  9426. party_booking_update(sd, job);
  9427. }
  9428. void clif_PartyBookingInsertNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  9429. {
  9430. int i;
  9431. uint8 buf[38+PARTY_BOOKING_JOBS*2];
  9432. if(pb_ad == NULL) return;
  9433. WBUFW(buf,0) = 0x809;
  9434. WBUFL(buf,2) = pb_ad->index;
  9435. memcpy(WBUFP(buf,6),pb_ad->charname,NAME_LENGTH);
  9436. WBUFL(buf,30) = pb_ad->starttime;
  9437. WBUFW(buf,34) = pb_ad->p_detail.level;
  9438. WBUFW(buf,36) = pb_ad->p_detail.mapid;
  9439. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9440. WBUFW(buf,38+i*2) = pb_ad->p_detail.job[i];
  9441. clif_send(buf, packet_len(0x809), &sd->bl, ALL_CLIENT);
  9442. }
  9443. void clif_PartyBookingUpdateNotify(struct map_session_data* sd, struct party_booking_ad_info* pb_ad)
  9444. {
  9445. int i;
  9446. uint8 buf[6+PARTY_BOOKING_JOBS*2];
  9447. if(pb_ad == NULL) return;
  9448. WBUFW(buf,0) = 0x80a;
  9449. WBUFL(buf,2) = pb_ad->index;
  9450. for(i=0; i<PARTY_BOOKING_JOBS; i++)
  9451. WBUFW(buf,6+i*2) = pb_ad->p_detail.job[i];
  9452. clif_send(buf,packet_len(0x80a),&sd->bl,ALL_CLIENT); // Now UPDATE all client.
  9453. }
  9454. void clif_PartyBookingDeleteNotify(struct map_session_data* sd, int index)
  9455. {
  9456. uint8 buf[6];
  9457. WBUFW(buf,0) = 0x80b;
  9458. WBUFL(buf,2) = index;
  9459. clif_send(buf, packet_len(0x80b), &sd->bl, ALL_CLIENT); // Now UPDATE all client.
  9460. }
  9461. /*==========================================
  9462. * 露店閉鎖
  9463. *------------------------------------------*/
  9464. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  9465. {
  9466. vending_closevending(sd);
  9467. }
  9468. /*==========================================
  9469. * 露店アイテムリスト要求
  9470. *------------------------------------------*/
  9471. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  9472. {
  9473. if( sd->npc_id )
  9474. {// using an NPC
  9475. return;
  9476. }
  9477. vending_vendinglistreq(sd,RFIFOL(fd,2));
  9478. }
  9479. /*==========================================
  9480. * Shop item(s) purchase request
  9481. * S 0134 <len>.w <ID>.l {<amount>.w <index>.w}.4B*
  9482. *------------------------------------------*/
  9483. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  9484. {
  9485. int len = (int)RFIFOW(fd,2) - 8;
  9486. int id = (int)RFIFOL(fd,4);
  9487. const uint8* data = (uint8*)RFIFOP(fd,8);
  9488. vending_purchasereq(sd, id, -1, data, len/4);
  9489. }
  9490. /*==========================================
  9491. * Shop item(s) purchase request
  9492. * S 0134/0801 <len>.w <AID>.l <CID>.l {<amount>.w <index>.w}.4B*
  9493. *------------------------------------------*/
  9494. void clif_parse_PurchaseReq2(int fd, struct map_session_data* sd)
  9495. {
  9496. int len = (int)RFIFOW(fd,2) - 12;
  9497. int aid = (int)RFIFOL(fd,4);
  9498. int cid = (int)RFIFOL(fd,8);
  9499. const uint8* data = (uint8*)RFIFOP(fd,12);
  9500. vending_purchasereq(sd, aid, cid, data, len/4);
  9501. }
  9502. /*==========================================
  9503. * Confirm or cancel the shop preparation window
  9504. * S 01b2 <len>.w <message>.80B <flag>.B {<index>.w <amount>.w <value>.l}.8B*
  9505. * flag: 0=cancel, 1=confirm
  9506. *------------------------------------------*/
  9507. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  9508. {
  9509. short len = (short)RFIFOW(fd,2) - 85;
  9510. const char* message = (char*)RFIFOP(fd,4);
  9511. bool flag = (bool)RFIFOB(fd,84);
  9512. const uint8* data = (uint8*)RFIFOP(fd,85);
  9513. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  9514. return;
  9515. if( map[sd->bl.m].flag.novending || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  9516. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open a shop on this map"
  9517. return;
  9518. }
  9519. if( message[0] == '\0' ) // invalid input
  9520. return;
  9521. vending_openvending(sd, message, flag, data, len/8);
  9522. }
  9523. /*==========================================
  9524. * Guild creation request
  9525. * S 0165 <account id>.L <guild name>.24S
  9526. *------------------------------------------*/
  9527. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  9528. {
  9529. char* name = (char*)RFIFOP(fd,6);
  9530. name[NAME_LENGTH-1] = '\0';
  9531. if(map[sd->bl.m].flag.guildlock)
  9532. { //Guild locked.
  9533. clif_displaymessage(fd, msg_txt(228));
  9534. return;
  9535. }
  9536. guild_create(sd, name);
  9537. }
  9538. /*==========================================
  9539. * ギルドマスターかどうか確認
  9540. *------------------------------------------*/
  9541. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  9542. {
  9543. clif_guild_masterormember(sd);
  9544. }
  9545. /*==========================================
  9546. * ギルド情報要求
  9547. *------------------------------------------*/
  9548. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  9549. {
  9550. if( !sd->status.guild_id && !sd->state.bg_id )
  9551. return;
  9552. switch( RFIFOL(fd,2) )
  9553. {
  9554. case 0: // ギルド基本情報、同盟敵対情報
  9555. clif_guild_basicinfo(sd);
  9556. clif_guild_allianceinfo(sd);
  9557. break;
  9558. case 1: // メンバーリスト、役職名リスト
  9559. clif_guild_positionnamelist(sd);
  9560. clif_guild_memberlist(sd);
  9561. break;
  9562. case 2: // 役職名リスト、役職情報リスト
  9563. clif_guild_positionnamelist(sd);
  9564. clif_guild_positioninfolist(sd);
  9565. break;
  9566. case 3: // スキルリスト
  9567. clif_guild_skillinfo(sd);
  9568. break;
  9569. case 4: // 追放リスト
  9570. clif_guild_expulsionlist(sd);
  9571. break;
  9572. default:
  9573. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  9574. break;
  9575. }
  9576. }
  9577. /*==========================================
  9578. * ギルド役職変更
  9579. *------------------------------------------*/
  9580. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  9581. {
  9582. int i;
  9583. if(!sd->state.gmaster_flag)
  9584. return;
  9585. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  9586. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  9587. }
  9588. }
  9589. /*==========================================
  9590. * ギルドメンバ役職変更
  9591. * S 0155 <packet len>.W {<account id>.L <char id>.L <idx>.L}
  9592. *------------------------------------------*/
  9593. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  9594. {
  9595. int i;
  9596. if(!sd->state.gmaster_flag)
  9597. return;
  9598. for(i=4;i<RFIFOW(fd,2);i+=12){
  9599. guild_change_memberposition(sd->status.guild_id,
  9600. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  9601. }
  9602. }
  9603. /*==========================================
  9604. * ギルドエンブレム要求
  9605. *------------------------------------------*/
  9606. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  9607. {
  9608. struct guild* g;
  9609. int guild_id = RFIFOL(fd,2);
  9610. if( (g = guild_search(guild_id)) != NULL )
  9611. clif_guild_emblem(sd,g);
  9612. }
  9613. /*==========================================
  9614. * ギルドエンブレム変更
  9615. * S 0153 <packet len>.W <emblem data>.?B
  9616. *------------------------------------------*/
  9617. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  9618. {
  9619. if(!sd->state.gmaster_flag)
  9620. return;
  9621. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  9622. }
  9623. /*==========================================
  9624. * Guild notice update request
  9625. * S 016E <guildID>.l <msg1>.60B <msg2>.120B
  9626. *------------------------------------------*/
  9627. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  9628. {
  9629. int guild_id = RFIFOL(fd,2);
  9630. char* msg1 = (char*)RFIFOP(fd,6);
  9631. char* msg2 = (char*)RFIFOP(fd,66);
  9632. if(!sd->state.gmaster_flag)
  9633. return;
  9634. // compensate for some client defects when using multilanguage mode
  9635. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  9636. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  9637. if (msg2[0] == '|') msg2[strnlen(msg2, MAX_GUILDMES2)-1] = '\0'; // delete extra space at the end of string
  9638. guild_change_notice(sd, guild_id, msg1, msg2);
  9639. }
  9640. /*==========================================
  9641. * ギルド勧誘
  9642. *------------------------------------------*/
  9643. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  9644. {
  9645. struct map_session_data *t_sd;
  9646. if(map[sd->bl.m].flag.guildlock)
  9647. { //Guild locked.
  9648. clif_displaymessage(fd, msg_txt(228));
  9649. return;
  9650. }
  9651. t_sd = map_id2sd(RFIFOL(fd,2));
  9652. // @noask [LuzZza]
  9653. if(t_sd && t_sd->state.noask) {
  9654. clif_noask_sub(sd, t_sd, 2);
  9655. return;
  9656. }
  9657. guild_invite(sd,t_sd);
  9658. }
  9659. /*==========================================
  9660. * ギルド勧誘返信
  9661. *------------------------------------------*/
  9662. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  9663. {
  9664. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9665. }
  9666. /*==========================================
  9667. * ギルド脱退
  9668. *------------------------------------------*/
  9669. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  9670. {
  9671. if(map[sd->bl.m].flag.guildlock)
  9672. { //Guild locked.
  9673. clif_displaymessage(fd, msg_txt(228));
  9674. return;
  9675. }
  9676. if( sd->state.bg_id )
  9677. {
  9678. clif_displaymessage(fd, "You can't leave battleground guilds.");
  9679. return;
  9680. }
  9681. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9682. }
  9683. /*==========================================
  9684. * Request to expel a member of a guild
  9685. * S 015b <guild_id>.L <account_id>.L <char_id>.L <reason>.40B
  9686. *------------------------------------------*/
  9687. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  9688. {
  9689. if( map[sd->bl.m].flag.guildlock || sd->state.bg_id )
  9690. { // Guild locked.
  9691. clif_displaymessage(fd, msg_txt(228));
  9692. return;
  9693. }
  9694. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9695. }
  9696. /*==========================================
  9697. * Validates and processes guild messages
  9698. * S 017e <packet len>.w <text>.?B (<name> : <message>) 00
  9699. *------------------------------------------*/
  9700. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  9701. {
  9702. const char* text = (char*)RFIFOP(fd,4);
  9703. int textlen = RFIFOW(fd,2) - 4;
  9704. char *name, *message;
  9705. int namelen, messagelen;
  9706. // validate packet and retrieve name and message
  9707. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9708. return;
  9709. if( is_atcommand(fd, sd, message, 1) )
  9710. return;
  9711. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  9712. return;
  9713. if( battle_config.min_chat_delay )
  9714. { //[Skotlex]
  9715. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9716. return;
  9717. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9718. }
  9719. if( sd->state.bg_id )
  9720. bg_send_message(sd, text, textlen);
  9721. else
  9722. guild_send_message(sd, text, textlen);
  9723. }
  9724. /*==========================================
  9725. * ギルド同盟要求
  9726. *------------------------------------------*/
  9727. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  9728. {
  9729. struct map_session_data *t_sd;
  9730. if(!sd->state.gmaster_flag)
  9731. return;
  9732. if(map[sd->bl.m].flag.guildlock)
  9733. { //Guild locked.
  9734. clif_displaymessage(fd, msg_txt(228));
  9735. return;
  9736. }
  9737. t_sd = map_id2sd(RFIFOL(fd,2));
  9738. // @noask [LuzZza]
  9739. if(t_sd && t_sd->state.noask) {
  9740. clif_noask_sub(sd, t_sd, 3);
  9741. return;
  9742. }
  9743. guild_reqalliance(sd,t_sd);
  9744. }
  9745. /*==========================================
  9746. * ギルド同盟要求返信
  9747. *------------------------------------------*/
  9748. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  9749. {
  9750. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9751. }
  9752. /*==========================================
  9753. * ギルド関係解消
  9754. *------------------------------------------*/
  9755. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  9756. {
  9757. if(!sd->state.gmaster_flag)
  9758. return;
  9759. if(map[sd->bl.m].flag.guildlock)
  9760. { //Guild locked.
  9761. clif_displaymessage(fd, msg_txt(228));
  9762. return;
  9763. }
  9764. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9765. }
  9766. /*==========================================
  9767. * ギルド敵対
  9768. *------------------------------------------*/
  9769. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  9770. {
  9771. struct map_session_data *t_sd;
  9772. if(!sd->state.gmaster_flag)
  9773. return;
  9774. if(map[sd->bl.m].flag.guildlock)
  9775. { //Guild locked.
  9776. clif_displaymessage(fd, msg_txt(228));
  9777. return;
  9778. }
  9779. t_sd = map_id2sd(RFIFOL(fd,2));
  9780. // @noask [LuzZza]
  9781. if(t_sd && t_sd->state.noask) {
  9782. clif_noask_sub(sd, t_sd, 4);
  9783. return;
  9784. }
  9785. guild_opposition(sd,t_sd);
  9786. }
  9787. /*==========================================
  9788. * ギルド解散
  9789. *------------------------------------------*/
  9790. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  9791. {
  9792. if( map[sd->bl.m].flag.guildlock )
  9793. { //Guild locked.
  9794. clif_displaymessage(fd, msg_txt(228));
  9795. return;
  9796. }
  9797. guild_break(sd,(char*)RFIFOP(fd,2));
  9798. }
  9799. // pet
  9800. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  9801. {
  9802. pet_menu(sd,RFIFOB(fd,2));
  9803. }
  9804. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  9805. {
  9806. pet_catch_process2(sd,RFIFOL(fd,2));
  9807. }
  9808. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  9809. {
  9810. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  9811. {
  9812. //Forged packet, disconnect them [Kevin]
  9813. clif_authfail_fd(fd, 0);
  9814. return;
  9815. }
  9816. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9817. sd->menuskill_val = sd->menuskill_id = 0;
  9818. }
  9819. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  9820. {
  9821. if(sd->pd)
  9822. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9823. }
  9824. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  9825. {
  9826. pet_change_name(sd,(char*)RFIFOP(fd,2));
  9827. }
  9828. /*==========================================
  9829. * /kill <???>
  9830. * (or right click menu for GM "(name) force to quit")
  9831. * S 00cc <id>.L
  9832. *------------------------------------------*/
  9833. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  9834. {
  9835. struct block_list *target;
  9836. int tid,lv;
  9837. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9838. return;
  9839. tid = RFIFOL(fd,2);
  9840. target = map_id2bl(tid);
  9841. if (!target) {
  9842. clif_GM_kickack(sd, 0);
  9843. return;
  9844. }
  9845. switch (target->type) {
  9846. case BL_PC:
  9847. {
  9848. struct map_session_data *tsd = (struct map_session_data *)target;
  9849. if (pc_isGM(sd) <= pc_isGM(tsd))
  9850. {
  9851. clif_GM_kickack(sd, 0);
  9852. return;
  9853. }
  9854. lv = get_atcommand_level(atcommand_kick);
  9855. if( pc_isGM(sd) < lv )
  9856. {
  9857. clif_GM_kickack(sd, 0);
  9858. return;
  9859. }
  9860. if(log_config.gm && lv >= log_config.gm) {
  9861. char message[256];
  9862. sprintf(message, "/kick %s (%d)", tsd->status.name, tsd->status.char_id);
  9863. log_atcommand(sd, message);
  9864. }
  9865. clif_GM_kick(sd, tsd);
  9866. }
  9867. break;
  9868. case BL_MOB:
  9869. {
  9870. lv = get_atcommand_level(atcommand_killmonster);
  9871. if( pc_isGM(sd) < lv )
  9872. {
  9873. clif_GM_kickack(sd, 0);
  9874. return;
  9875. }
  9876. if(log_config.gm && lv >= log_config.gm) {
  9877. char message[256];
  9878. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9879. log_atcommand(sd, message);
  9880. }
  9881. status_percent_damage(&sd->bl, target, 100, 0, true); // can invalidate 'target'
  9882. }
  9883. break;
  9884. case BL_NPC:
  9885. {
  9886. struct npc_data* nd = (struct npc_data *)target;
  9887. lv = get_atcommand_level(atcommand_unloadnpc);
  9888. if( pc_isGM(sd) < lv )
  9889. {
  9890. clif_GM_kickack(sd, 0);
  9891. return;
  9892. }
  9893. if( log_config.gm && lv >= log_config.gm ) {
  9894. char message[256];
  9895. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9896. log_atcommand(sd, message);
  9897. }
  9898. // copy-pasted from atcommand_unloadnpc
  9899. npc_unload_duplicates(nd);
  9900. npc_unload(nd); // invalidates 'target'
  9901. npc_read_event_script();
  9902. }
  9903. break;
  9904. default:
  9905. clif_GM_kickack(sd, 0);
  9906. }
  9907. }
  9908. /*==========================================
  9909. * /killall
  9910. *------------------------------------------*/
  9911. void clif_parse_GMKickAll(int fd, struct map_session_data* sd)
  9912. {
  9913. is_atcommand(fd, sd, "@kickall", 1);
  9914. }
  9915. /*==========================================
  9916. * /remove <account name>
  9917. * /shift <char name>
  9918. *------------------------------------------*/
  9919. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  9920. {// FIXME: remove is supposed to receive account name for clients prior 20100803RE
  9921. char *player_name;
  9922. int lv;
  9923. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9924. return;
  9925. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_jumpto)) )
  9926. return;
  9927. player_name = (char*)RFIFOP(fd,2);
  9928. player_name[NAME_LENGTH-1] = '\0';
  9929. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9930. if( log_config.gm && lv >= log_config.gm ) {
  9931. char message[NAME_LENGTH+7];
  9932. sprintf(message, "/shift %s", player_name);
  9933. log_atcommand(sd, message);
  9934. }
  9935. }
  9936. /// Warps oneself to the location of the character given by account id ( /remove <account id> ).
  9937. /// R 0843 <account id>.L
  9938. void clif_parse_GMRemove2(int fd, struct map_session_data* sd)
  9939. {
  9940. int account_id, lv;
  9941. struct map_session_data* pl_sd;
  9942. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9943. {
  9944. return;
  9945. }
  9946. if( pc_isGM(sd) < ( lv = get_atcommand_level(atcommand_jumpto) ) )
  9947. {
  9948. return;
  9949. }
  9950. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9951. if( ( pl_sd = map_id2sd(account_id) ) != NULL && pc_isGM(sd) >= pc_isGM(pl_sd) )
  9952. {
  9953. pc_warpto(sd, pl_sd);
  9954. }
  9955. if( log_config.gm && lv >= log_config.gm )
  9956. {
  9957. char message[32];
  9958. sprintf(message, "/remove %d", account_id);
  9959. log_atcommand(sd, message);
  9960. }
  9961. }
  9962. /*==========================================
  9963. * /recall <account name>
  9964. * /summon <char name>
  9965. *------------------------------------------*/
  9966. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  9967. {// FIXME: recall is supposed to receive account name for clients prior 20100803RE
  9968. char *player_name;
  9969. int lv;
  9970. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9971. return;
  9972. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_recall)) )
  9973. return;
  9974. player_name = (char*)RFIFOP(fd,2);
  9975. player_name[NAME_LENGTH-1] = '\0';
  9976. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9977. if( log_config.gm && lv >= log_config.gm ) {
  9978. char message[NAME_LENGTH+8];
  9979. sprintf(message, "/recall %s", player_name);
  9980. log_atcommand(sd, message);
  9981. }
  9982. }
  9983. /// Summons a character given by account id to one's own position ( /recall <account id> )
  9984. /// R 0842 <account id>.L
  9985. void clif_parse_GMRecall2(int fd, struct map_session_data* sd)
  9986. {
  9987. int account_id, lv;
  9988. struct map_session_data* pl_sd;
  9989. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9990. {
  9991. return;
  9992. }
  9993. if( pc_isGM(sd) < ( lv = get_atcommand_level(atcommand_recall) ) )
  9994. {
  9995. return;
  9996. }
  9997. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  9998. if( ( pl_sd = map_id2sd(account_id) ) != NULL && pc_isGM(sd) >= pc_isGM(pl_sd) )
  9999. {
  10000. pc_recall(sd, pl_sd);
  10001. }
  10002. if( log_config.gm && lv >= log_config.gm )
  10003. {
  10004. char message[32];
  10005. sprintf(message, "/recall %d", account_id);
  10006. log_atcommand(sd, message);
  10007. }
  10008. }
  10009. /*==========================================
  10010. * /monster /item
  10011. * R 01F3 <name>.24B
  10012. *------------------------------------------*/
  10013. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  10014. {
  10015. char *monster_item_name;
  10016. char message[NAME_LENGTH+10]; //For logging.
  10017. int level;
  10018. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  10019. return;
  10020. monster_item_name = (char*)RFIFOP(fd,2);
  10021. monster_item_name[NAME_LENGTH-1] = '\0';
  10022. if( mobdb_searchname(monster_item_name) ) {
  10023. if( pc_isGM(sd) < (level=get_atcommand_level(atcommand_monster)) )
  10024. return;
  10025. atcommand_monster(fd, sd, "@monster", monster_item_name); // as @monster
  10026. if( log_config.gm && level >= log_config.gm )
  10027. { //Log action. [Skotlex]
  10028. snprintf(message, sizeof(message)-1, "@spawn %s", monster_item_name);
  10029. log_atcommand(sd, message);
  10030. }
  10031. return;
  10032. }
  10033. if( itemdb_searchname(monster_item_name) == NULL )
  10034. return;
  10035. if( pc_isGM(sd) < (level = get_atcommand_level(atcommand_item)) )
  10036. return;
  10037. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  10038. if( log_config.gm && level >= log_config.gm )
  10039. { //Log action. [Skotlex]
  10040. sprintf(message, "@item %s", monster_item_name);
  10041. log_atcommand(sd, message);
  10042. }
  10043. }
  10044. /*==========================================
  10045. * /hide
  10046. *------------------------------------------*/
  10047. void clif_parse_GMHide(int fd, struct map_session_data *sd)
  10048. {
  10049. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  10050. return;
  10051. if( pc_isGM(sd) < get_atcommand_level(atcommand_hide) )
  10052. return;
  10053. if( sd->sc.option & OPTION_INVISIBLE ) {
  10054. sd->sc.option &= ~OPTION_INVISIBLE;
  10055. if (sd->disguise)
  10056. status_set_viewdata(&sd->bl, sd->disguise);
  10057. else
  10058. status_set_viewdata(&sd->bl, sd->status.class_);
  10059. clif_displaymessage(fd, "Invisible: Off.");
  10060. } else {
  10061. sd->sc.option |= OPTION_INVISIBLE;
  10062. sd->vd.class_ = INVISIBLE_CLASS;
  10063. clif_displaymessage(fd, "Invisible: On.");
  10064. if( log_config.gm && get_atcommand_level(atcommand_hide) >= log_config.gm )
  10065. log_atcommand(sd, "/hide");
  10066. }
  10067. clif_changeoption(&sd->bl);
  10068. }
  10069. /*==========================================
  10070. * GM adjustment of a player's manner value (right-click GM menu)
  10071. * S 0149 <id>.L <type>.B <value>.W
  10072. * type: 0 - positive points
  10073. * 1 - negative points
  10074. * 2 - self mute (+10 minutes)
  10075. *------------------------------------------*/
  10076. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  10077. {
  10078. int id, type, value, level;
  10079. struct map_session_data *dstsd;
  10080. id = RFIFOL(fd,2);
  10081. type = RFIFOB(fd,6);
  10082. value = RFIFOW(fd,7);
  10083. if( type == 0 )
  10084. value = 0 - value;
  10085. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  10086. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  10087. if (type == 2 /* && (pc_isGM(sd) > 0 || sd->bl.id != id)*/)
  10088. return;
  10089. dstsd = map_id2sd(id);
  10090. if( dstsd == NULL )
  10091. return;
  10092. if( (level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(atcommand_mute) )
  10093. {
  10094. clif_manner_message(sd, 0);
  10095. clif_manner_message(dstsd, 5);
  10096. if( dstsd->status.manner < value ) {
  10097. dstsd->status.manner -= value;
  10098. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  10099. } else {
  10100. dstsd->status.manner = 0;
  10101. status_change_end(&dstsd->bl,SC_NOCHAT,-1);
  10102. }
  10103. if( type != 2 )
  10104. clif_GM_silence(sd, dstsd, type);
  10105. }
  10106. }
  10107. /*==========================================
  10108. * GM adjustment of a player's manner value by -60 (using name)
  10109. * /rc <name>
  10110. * S 0212 <name>.24B
  10111. *------------------------------------------*/
  10112. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  10113. {
  10114. char* name = (char*)RFIFOP(fd,2);
  10115. struct map_session_data* dstsd;
  10116. name[23] = '\0';
  10117. dstsd = map_nick2sd(name);
  10118. if( dstsd == NULL )
  10119. return;
  10120. if( pc_isGM(sd) > pc_isGM(dstsd) && pc_isGM(sd) >= get_atcommand_level(atcommand_mute) )
  10121. {
  10122. clif_manner_message(sd, 0);
  10123. clif_manner_message(dstsd, 3);
  10124. dstsd->status.manner -= 60;
  10125. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  10126. clif_GM_silence(sd, dstsd, 1);
  10127. }
  10128. }
  10129. /*==========================================
  10130. * GM requesting account name (for right-click gm menu)
  10131. * S 01df <id>.L
  10132. * R 01e0 <id>.L <name>.24B
  10133. *------------------------------------------*/
  10134. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  10135. {
  10136. int tid;
  10137. tid = RFIFOL(fd,2);
  10138. //TODO: find out if this works for any player or only for authorized GMs
  10139. WFIFOHEAD(fd,packet_len(0x1e0));
  10140. WFIFOW(fd,0) = 0x1e0;
  10141. WFIFOL(fd,2) = tid;
  10142. safestrncpy((char*)WFIFOP(fd,6), "", 24); // insert account name here >_<
  10143. WFIFOSET(fd, packet_len(0x1e0));
  10144. }
  10145. /*==========================================
  10146. * GM single cell type change request
  10147. * /changemaptype <x> <y> <type:0-1>
  10148. * S 0198 <x>.W <y>.W <gat>.W
  10149. *------------------------------------------*/
  10150. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  10151. {
  10152. int x,y,type;
  10153. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  10154. return;
  10155. if( pc_isGM(sd) < 99 ) //TODO: add proper check
  10156. return;
  10157. x = RFIFOW(fd,2);
  10158. y = RFIFOW(fd,4);
  10159. type = RFIFOW(fd,6);
  10160. map_setgatcell(sd->bl.m,x,y,type);
  10161. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  10162. //FIXME: once players leave the map, the client 'forgets' this information.
  10163. }
  10164. /// S 00cf <nick>.24B <type>.B
  10165. /// type: 0 (/ex nick) deny speech from nick
  10166. /// 1 (/in nick) allow speech from nick
  10167. ///
  10168. /// R 00d1 <type>.B <result>.B
  10169. /// type: 0: deny, 1: allow
  10170. /// result: 0: success, 1: fail 2: list full
  10171. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  10172. {
  10173. char output[512];
  10174. char* nick;
  10175. uint8 type;
  10176. int i;
  10177. nick = (char*)RFIFOP(fd,2); // speed up
  10178. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  10179. type = RFIFOB(fd,26);
  10180. WFIFOHEAD(fd,packet_len(0xd1));
  10181. WFIFOW(fd,0) = 0x0d1;
  10182. WFIFOB(fd,2) = type;
  10183. if( type == 0 )
  10184. { // Add name to ignore list (block)
  10185. // Bot-check...
  10186. if (strcmp(wisp_server_name, nick) == 0)
  10187. { // to find possible bot users who automaticaly ignore people
  10188. 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);
  10189. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  10190. WFIFOB(fd,3) = 1; // fail
  10191. WFIFOSET(fd, packet_len(0x0d1));
  10192. return;
  10193. }
  10194. // try to find a free spot, while checking for duplicates at the same time
  10195. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10196. if( i == MAX_IGNORE_LIST )
  10197. {// no space for new entry
  10198. WFIFOB(fd,3) = 2; // fail
  10199. WFIFOSET(fd, packet_len(0x0d1));
  10200. return;
  10201. }
  10202. if( sd->ignore[i].name[0] != '\0' )
  10203. {// name already exists
  10204. WFIFOB(fd,3) = 0; // Aegis reports success.
  10205. WFIFOSET(fd, packet_len(0x0d1));
  10206. return;
  10207. }
  10208. //Insert in position i
  10209. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  10210. WFIFOB(fd,3) = 0; // success
  10211. WFIFOSET(fd, packet_len(0x0d1));
  10212. }
  10213. else
  10214. { // Remove name from ignore list (unblock)
  10215. // find entry
  10216. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  10217. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' )
  10218. { //Not found
  10219. WFIFOB(fd,3) = 1; // fail
  10220. WFIFOSET(fd, packet_len(0x0d1));
  10221. return;
  10222. }
  10223. // move everything one place down to overwrite removed entry
  10224. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  10225. // wipe last entry
  10226. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  10227. WFIFOB(fd,3) = 0; // success
  10228. WFIFOSET(fd, packet_len(0x0d1));
  10229. }
  10230. return;
  10231. }
  10232. /// S 00d0 <type>.B
  10233. /// type: 0 (/exall) deny all speech
  10234. /// 1 (/inall) allow all speech
  10235. ///
  10236. /// R 00d2 <type>.B <fail>.B
  10237. /// type: 0: deny, 1: allow
  10238. /// fail: 0: success, 1: fail
  10239. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  10240. {
  10241. WFIFOHEAD(fd,packet_len(0xd2));
  10242. WFIFOW(fd,0) = 0x0d2;
  10243. WFIFOB(fd,2) = RFIFOB(fd,2);
  10244. if( RFIFOB(fd,2) == 0 )
  10245. {// Deny all
  10246. if( sd->state.ignoreAll ) {
  10247. WFIFOB(fd,3) = 1; // fail
  10248. } else {
  10249. sd->state.ignoreAll = 1;
  10250. WFIFOB(fd,3) = 0; // success
  10251. }
  10252. }
  10253. else
  10254. {//Unblock everyone
  10255. if( sd->state.ignoreAll ) {
  10256. sd->state.ignoreAll = 0;
  10257. WFIFOB(fd,3) = 0; // success
  10258. } else {
  10259. if (sd->ignore[0].name[0] != '\0')
  10260. { //Wipe the ignore list.
  10261. memset(sd->ignore, 0, sizeof(sd->ignore));
  10262. WFIFOB(fd,3) = 0; // success
  10263. } else {
  10264. WFIFOB(fd,3) = 1; // fail
  10265. }
  10266. }
  10267. }
  10268. WFIFOSET(fd, packet_len(0x0d2));
  10269. return;
  10270. }
  10271. /*==========================================
  10272. * Wis拒否リスト
  10273. *------------------------------------------*/
  10274. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  10275. {
  10276. int i;
  10277. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  10278. WFIFOW(fd,0) = 0xd4;
  10279. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  10280. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  10281. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  10282. WFIFOSET(fd, WFIFOW(fd,2));
  10283. return;
  10284. }
  10285. /*==========================================
  10286. * スパノビの/doridoriによるSPR2倍
  10287. *------------------------------------------*/
  10288. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  10289. {
  10290. if (sd->state.doridori) return;
  10291. switch (sd->class_&MAPID_UPPERMASK)
  10292. {
  10293. case MAPID_SOUL_LINKER:
  10294. case MAPID_STAR_GLADIATOR:
  10295. case MAPID_TAEKWON:
  10296. if (!sd->state.rest)
  10297. break;
  10298. case MAPID_SUPER_NOVICE:
  10299. sd->state.doridori=1;
  10300. break;
  10301. }
  10302. return;
  10303. }
  10304. /*==========================================
  10305. * スパノビの爆裂波動
  10306. *------------------------------------------*/
  10307. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  10308. {
  10309. if(sd){
  10310. int nextbaseexp=pc_nextbaseexp(sd);
  10311. if (battle_config.etc_log){
  10312. if(nextbaseexp != 0)
  10313. 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));
  10314. else
  10315. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  10316. }
  10317. 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){
  10318. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  10319. sc_start(&sd->bl,status_skill2sc(MO_EXPLOSIONSPIRITS),100,
  10320. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  10321. }
  10322. }
  10323. return;
  10324. }
  10325. // random notes:
  10326. // 0x214: monster/player info ?
  10327. /*==========================================
  10328. * Friends List
  10329. *------------------------------------------*/
  10330. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  10331. { //Toggles a single friend online/offline [Skotlex]
  10332. int i, fd = sd->fd;
  10333. //Seek friend.
  10334. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  10335. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10336. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  10337. return; //Not found
  10338. WFIFOHEAD(fd,packet_len(0x206));
  10339. WFIFOW(fd, 0) = 0x206;
  10340. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  10341. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  10342. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  10343. WFIFOSET(fd, packet_len(0x206));
  10344. }
  10345. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  10346. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  10347. {
  10348. int account_id, char_id, online;
  10349. account_id = va_arg(ap, int);
  10350. char_id = va_arg(ap, int);
  10351. online = va_arg(ap, int);
  10352. clif_friendslist_toggle(sd, account_id, char_id, online);
  10353. return 0;
  10354. }
  10355. //For sending the whole friends list.
  10356. void clif_friendslist_send(struct map_session_data *sd)
  10357. {
  10358. int i = 0, n, fd = sd->fd;
  10359. // Send friends list
  10360. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  10361. WFIFOW(fd, 0) = 0x201;
  10362. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  10363. {
  10364. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  10365. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  10366. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  10367. }
  10368. if (i) {
  10369. WFIFOW(fd,2) = 4 + 32 * i;
  10370. WFIFOSET(fd, WFIFOW(fd,2));
  10371. }
  10372. for (n = 0; n < i; n++)
  10373. { //Sending the online players
  10374. if (map_charid2sd(sd->status.friends[n].char_id))
  10375. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  10376. }
  10377. }
  10378. /// Reply for add friend request: (success => type 0)
  10379. /// type=0 : MsgStringTable[821]="You have become friends with (%s)."
  10380. /// type=1 : MsgStringTable[822]="(%s) does not want to be friends with you."
  10381. /// type=2 : MsgStringTable[819]="Your Friend List is full."
  10382. /// type=3 : MsgStringTable[820]="(%s)'s Friend List is full."
  10383. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  10384. {
  10385. int fd;
  10386. nullpo_retv(sd);
  10387. fd = sd->fd;
  10388. WFIFOHEAD(fd,packet_len(0x209));
  10389. WFIFOW(fd,0) = 0x209;
  10390. WFIFOW(fd,2) = type;
  10391. if (f_sd)
  10392. {
  10393. WFIFOL(fd,4) = f_sd->status.account_id;
  10394. WFIFOL(fd,8) = f_sd->status.char_id;
  10395. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  10396. }
  10397. WFIFOSET(fd, packet_len(0x209));
  10398. }
  10399. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  10400. {
  10401. struct map_session_data *f_sd;
  10402. int i, f_fd;
  10403. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  10404. // Friend doesn't exist (no player with this name)
  10405. if (f_sd == NULL) {
  10406. clif_displaymessage(fd, msg_txt(3));
  10407. return;
  10408. }
  10409. // @noask [LuzZza]
  10410. if(f_sd->state.noask) {
  10411. clif_noask_sub(sd, f_sd, 5);
  10412. return;
  10413. }
  10414. // Friend already exists
  10415. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  10416. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  10417. clif_displaymessage(fd, "Friend already exists.");
  10418. return;
  10419. }
  10420. }
  10421. if (i == MAX_FRIENDS) {
  10422. //No space, list full.
  10423. clif_friendslist_reqack(sd, f_sd, 2);
  10424. return;
  10425. }
  10426. f_fd = f_sd->fd;
  10427. WFIFOHEAD(f_fd,packet_len(0x207));
  10428. WFIFOW(f_fd,0) = 0x207;
  10429. WFIFOL(f_fd,2) = sd->status.account_id;
  10430. WFIFOL(f_fd,6) = sd->status.char_id;
  10431. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  10432. WFIFOSET(f_fd, packet_len(0x207));
  10433. return;
  10434. }
  10435. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  10436. {
  10437. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  10438. struct map_session_data *f_sd;
  10439. int char_id, account_id;
  10440. char reply;
  10441. account_id = RFIFOL(fd,2);
  10442. char_id = RFIFOL(fd,6);
  10443. reply = RFIFOB(fd,10);
  10444. //printf ("reply: %d %d %d\n", char_id, id, reply);
  10445. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  10446. if (f_sd == NULL)
  10447. return;
  10448. if (reply == 0)
  10449. clif_friendslist_reqack(f_sd, sd, 1);
  10450. else {
  10451. int i;
  10452. // Find an empty slot
  10453. for (i = 0; i < MAX_FRIENDS; i++)
  10454. if (f_sd->status.friends[i].char_id == 0)
  10455. break;
  10456. if (i == MAX_FRIENDS) {
  10457. clif_friendslist_reqack(f_sd, sd, 2);
  10458. return;
  10459. }
  10460. f_sd->status.friends[i].account_id = sd->status.account_id;
  10461. f_sd->status.friends[i].char_id = sd->status.char_id;
  10462. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  10463. clif_friendslist_reqack(f_sd, sd, 0);
  10464. if (battle_config.friend_auto_add) {
  10465. // Also add f_sd to sd's friendlist.
  10466. for (i = 0; i < MAX_FRIENDS; i++) {
  10467. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  10468. return; //No need to add anything.
  10469. if (sd->status.friends[i].char_id == 0)
  10470. break;
  10471. }
  10472. if (i == MAX_FRIENDS) {
  10473. clif_friendslist_reqack(sd, f_sd, 2);
  10474. return;
  10475. }
  10476. sd->status.friends[i].account_id = f_sd->status.account_id;
  10477. sd->status.friends[i].char_id = f_sd->status.char_id;
  10478. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  10479. clif_friendslist_reqack(sd, f_sd, 0);
  10480. }
  10481. }
  10482. return;
  10483. }
  10484. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  10485. {
  10486. // 0x203 </o> <ID to be removed W 4B>
  10487. int account_id, char_id;
  10488. int i, j;
  10489. account_id = RFIFOL(fd,2);
  10490. char_id = RFIFOL(fd,6);
  10491. // Search friend
  10492. for (i = 0; i < MAX_FRIENDS &&
  10493. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  10494. if (i == MAX_FRIENDS) {
  10495. clif_displaymessage(fd, "Name not found in list.");
  10496. return;
  10497. }
  10498. // move all chars down
  10499. for(j = i + 1; j < MAX_FRIENDS; j++)
  10500. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  10501. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  10502. clif_displaymessage(fd, "Friend removed");
  10503. WFIFOHEAD(fd,packet_len(0x20a));
  10504. WFIFOW(fd,0) = 0x20a;
  10505. WFIFOL(fd,2) = account_id;
  10506. WFIFOL(fd,6) = char_id;
  10507. WFIFOSET(fd, packet_len(0x20a));
  10508. // clif_friendslist_send(sd); //This is not needed anymore.
  10509. return;
  10510. }
  10511. /*==========================================
  10512. * /pvpinfo
  10513. *------------------------------------------*/
  10514. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  10515. {
  10516. WFIFOHEAD(fd,packet_len(0x210));
  10517. WFIFOW(fd,0) = 0x210;
  10518. //WFIFOL(fd,2) = 0; // not sure what for yet
  10519. //WFIFOL(fd,6) = 0;
  10520. WFIFOL(fd,10) = sd->pvp_won; // times won
  10521. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  10522. WFIFOL(fd,18) = sd->pvp_point;
  10523. WFIFOSET(fd, packet_len(0x210));
  10524. return;
  10525. }
  10526. /*==========================================
  10527. * /blacksmith
  10528. * S 0217
  10529. *------------------------------------------*/
  10530. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  10531. {
  10532. int i;
  10533. const char* name;
  10534. WFIFOHEAD(fd,packet_len(0x219));
  10535. WFIFOW(fd,0) = 0x219;
  10536. //Packet size limits this list to 10 elements. [Skotlex]
  10537. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10538. if (smith_fame_list[i].id > 0) {
  10539. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  10540. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  10541. {
  10542. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  10543. } else
  10544. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  10545. } else
  10546. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  10547. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  10548. }
  10549. for(;i < 10; i++) { //In case the MAX is less than 10.
  10550. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  10551. WFIFOL(fd, 242 + i * 4) = 0;
  10552. }
  10553. WFIFOSET(fd, packet_len(0x219));
  10554. }
  10555. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  10556. {
  10557. int fd = sd->fd;
  10558. WFIFOHEAD(fd,packet_len(0x21b));
  10559. WFIFOW(fd,0) = 0x21b;
  10560. WFIFOL(fd,2) = points;
  10561. WFIFOL(fd,6) = sd->status.fame;
  10562. WFIFOSET(fd, packet_len(0x21b));
  10563. return 0;
  10564. }
  10565. /*==========================================
  10566. * /alchemist
  10567. * S 0218
  10568. *------------------------------------------*/
  10569. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  10570. {
  10571. int i;
  10572. const char* name;
  10573. WFIFOHEAD(fd,packet_len(0x21a));
  10574. WFIFOW(fd,0) = 0x21a;
  10575. //Packet size limits this list to 10 elements. [Skotlex]
  10576. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10577. if (chemist_fame_list[i].id > 0) {
  10578. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  10579. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  10580. {
  10581. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10582. } else
  10583. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  10584. } else
  10585. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10586. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  10587. }
  10588. for(;i < 10; i++) { //In case the MAX is less than 10.
  10589. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  10590. WFIFOL(fd, 242 + i * 4) = 0;
  10591. }
  10592. WFIFOSET(fd, packet_len(0x21a));
  10593. }
  10594. int clif_fame_alchemist(struct map_session_data *sd, int points)
  10595. {
  10596. int fd = sd->fd;
  10597. WFIFOHEAD(fd,packet_len(0x21c));
  10598. WFIFOW(fd,0) = 0x21c;
  10599. WFIFOL(fd,2) = points;
  10600. WFIFOL(fd,6) = sd->status.fame;
  10601. WFIFOSET(fd, packet_len(0x21c));
  10602. return 0;
  10603. }
  10604. /*==========================================
  10605. * /taekwon
  10606. * S 0225
  10607. *------------------------------------------*/
  10608. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  10609. {
  10610. int i;
  10611. const char* name;
  10612. WFIFOHEAD(fd,packet_len(0x226));
  10613. WFIFOW(fd,0) = 0x226;
  10614. //Packet size limits this list to 10 elements. [Skotlex]
  10615. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10616. if (taekwon_fame_list[i].id > 0) {
  10617. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  10618. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  10619. {
  10620. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10621. } else
  10622. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  10623. } else
  10624. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10625. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  10626. }
  10627. for(;i < 10; i++) { //In case the MAX is less than 10.
  10628. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  10629. WFIFOL(fd, 242 + i * 4) = 0;
  10630. }
  10631. WFIFOSET(fd, packet_len(0x226));
  10632. }
  10633. int clif_fame_taekwon(struct map_session_data *sd, int points)
  10634. {
  10635. int fd = sd->fd;
  10636. WFIFOHEAD(fd,packet_len(0x224));
  10637. WFIFOW(fd,0) = 0x224;
  10638. WFIFOL(fd,2) = points;
  10639. WFIFOL(fd,6) = sd->status.fame;
  10640. WFIFOSET(fd, packet_len(0x224));
  10641. return 0;
  10642. }
  10643. /*==========================================
  10644. * /pk
  10645. * S 0237
  10646. *------------------------------------------*/
  10647. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  10648. {
  10649. int i;
  10650. WFIFOHEAD(fd,packet_len(0x238));
  10651. WFIFOW(fd,0) = 0x238;
  10652. for(i=0;i<10;i++){
  10653. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  10654. WFIFOL(fd,i*4+242) = 0;
  10655. }
  10656. WFIFOSET(fd, packet_len(0x238));
  10657. return;
  10658. }
  10659. /*==========================================
  10660. * SG Feel save OK [Komurka]
  10661. *------------------------------------------*/
  10662. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  10663. {
  10664. int i;
  10665. if (sd->menuskill_id != SG_FEEL)
  10666. return;
  10667. i = sd->menuskill_val-1;
  10668. if (i<0 || i >= MAX_PC_FEELHATE) return; //Bug?
  10669. sd->feel_map[i].index = map_id2index(sd->bl.m);
  10670. sd->feel_map[i].m = sd->bl.m;
  10671. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  10672. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  10673. // clif_misceffect2(&sd->bl, 0x1b0);
  10674. // clif_misceffect2(&sd->bl, 0x21f);
  10675. clif_feel_info(sd, i, 0);
  10676. sd->menuskill_val = sd->menuskill_id = 0;
  10677. }
  10678. /*==========================================
  10679. * Question about Star Glaldiator save map [Komurka]
  10680. *------------------------------------------*/
  10681. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv)
  10682. {
  10683. WFIFOHEAD(fd,packet_len(0x253));
  10684. WFIFOW(fd,0)=0x253;
  10685. WFIFOSET(fd, packet_len(0x253));
  10686. sd->menuskill_id = SG_FEEL;
  10687. sd->menuskill_val = skilllv;
  10688. }
  10689. /*==========================================
  10690. * Homunculus packets
  10691. *------------------------------------------*/
  10692. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  10693. {
  10694. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  10695. }
  10696. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  10697. {
  10698. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  10699. struct block_list *bl = NULL;
  10700. struct unit_data *ud = NULL;
  10701. if( sd->md && sd->md->bl.id == id )
  10702. bl = &sd->md->bl;
  10703. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  10704. bl = &sd->hd->bl; // Moving Homunculus
  10705. else return;
  10706. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  10707. ud = unit_bl2ud(bl);
  10708. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  10709. }
  10710. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd)
  10711. {
  10712. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  10713. struct block_list *bl = NULL;
  10714. short x, y, cmd;
  10715. cmd = RFIFOW(fd,0);
  10716. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 + (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  10717. 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);
  10718. if( sd->md && sd->md->bl.id == id )
  10719. bl = &sd->md->bl; // Moving Mercenary
  10720. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  10721. bl = &sd->hd->bl; // Moving Homunculus
  10722. else return;
  10723. unit_walktoxy(bl, x, y, 4);
  10724. }
  10725. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  10726. {
  10727. struct block_list *bl = NULL;
  10728. int id = RFIFOL(fd,2),
  10729. target_id = RFIFOL(fd,6),
  10730. action_type = RFIFOB(fd,10);
  10731. if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  10732. bl = &sd->hd->bl;
  10733. else if( sd->md && sd->md->bl.id == id )
  10734. bl = &sd->md->bl;
  10735. else return;
  10736. unit_stop_attack(bl);
  10737. unit_attack(bl, target_id, action_type != 0);
  10738. }
  10739. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  10740. { //[orn]
  10741. int cmd;
  10742. cmd = RFIFOW(fd,0);
  10743. if(!merc_is_hom_active(sd->hd))
  10744. return;
  10745. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  10746. }
  10747. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  10748. {
  10749. int item_position = pc_search_inventory(sd, 7621);
  10750. if (item_position < 0)
  10751. return;
  10752. if (sd->sc.data[SC_HELLPOWER]) //Cannot res while under the effect of SC_HELLPOWER.
  10753. return;
  10754. if (!status_revive(&sd->bl, 100, 100))
  10755. return;
  10756. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  10757. pc_delitem(sd, item_position, 1, 0, 1);
  10758. }
  10759. /// /check <string>
  10760. /// S 0213 <string>.24B
  10761. void clif_parse_Check(int fd, struct map_session_data *sd)
  10762. {
  10763. // no info
  10764. }
  10765. #ifndef TXT_ONLY
  10766. /*==========================================
  10767. * MAIL SYSTEM
  10768. * By Zephyrus
  10769. *==========================================*/
  10770. /*------------------------------------------
  10771. * Reply to Set Attachment operation
  10772. * 0 : Successfully attached item to mail
  10773. * 1 : Fail to set the attachment
  10774. *------------------------------------------*/
  10775. static void clif_Mail_setattachment(int fd, int index, uint8 flag)
  10776. {
  10777. WFIFOHEAD(fd,packet_len(0x255));
  10778. WFIFOW(fd,0) = 0x255;
  10779. WFIFOW(fd,2) = index;
  10780. WFIFOB(fd,4) = flag;
  10781. WFIFOSET(fd,packet_len(0x255));
  10782. }
  10783. /*------------------------------------------
  10784. * Reply to Get Attachment operation
  10785. * 0 : Successfully added attachment to Inventory
  10786. * 1 : Fail to set the item to inventory
  10787. * 2 : Weight problems
  10788. *------------------------------------------*/
  10789. void clif_Mail_getattachment(int fd, uint8 flag)
  10790. {
  10791. WFIFOHEAD(fd,packet_len(0x245));
  10792. WFIFOW(fd,0) = 0x245;
  10793. WFIFOB(fd,2) = flag;
  10794. WFIFOSET(fd,packet_len(0x245));
  10795. }
  10796. /*------------------------------------------
  10797. * Send Mail ack
  10798. * 0 : Message Send Ok
  10799. * 1 : Recipient does not exist
  10800. *------------------------------------------*/
  10801. void clif_Mail_send(int fd, bool fail)
  10802. {
  10803. WFIFOHEAD(fd,packet_len(0x249));
  10804. WFIFOW(fd,0) = 0x249;
  10805. WFIFOB(fd,2) = fail;
  10806. WFIFOSET(fd,packet_len(0x249));
  10807. }
  10808. /*------------------------------------------
  10809. * Delete Mail ack
  10810. * 0 : Delete ok
  10811. * 1 : Delete failed
  10812. *------------------------------------------*/
  10813. void clif_Mail_delete(int fd, int mail_id, short fail)
  10814. {
  10815. WFIFOHEAD(fd, packet_len(0x257));
  10816. WFIFOW(fd,0) = 0x257;
  10817. WFIFOL(fd,2) = mail_id;
  10818. WFIFOW(fd,6) = fail;
  10819. WFIFOSET(fd, packet_len(0x257));
  10820. }
  10821. /*------------------------------------------
  10822. * Return Mail ack
  10823. * 0 : Mail returned to the sender
  10824. * 1 : The mail does not exist
  10825. *------------------------------------------*/
  10826. void clif_Mail_return(int fd, int mail_id, short fail)
  10827. {
  10828. WFIFOHEAD(fd,packet_len(0x274));
  10829. WFIFOW(fd,0) = 0x274;
  10830. WFIFOL(fd,2) = mail_id;
  10831. WFIFOW(fd,6) = fail;
  10832. WFIFOSET(fd,packet_len(0x274));
  10833. }
  10834. /*------------------------------------------
  10835. * You have New Mail
  10836. *------------------------------------------*/
  10837. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  10838. {
  10839. WFIFOHEAD(fd,packet_len(0x24a));
  10840. WFIFOW(fd,0) = 0x24a;
  10841. WFIFOL(fd,2) = mail_id;
  10842. safestrncpy((char*)WFIFOP(fd,6), sender, NAME_LENGTH);
  10843. safestrncpy((char*)WFIFOP(fd,30), title, MAIL_TITLE_LENGTH);
  10844. WFIFOSET(fd,packet_len(0x24a));
  10845. }
  10846. /*------------------------------------------
  10847. * Handles Mail Window on Client
  10848. * flag : 0 open | 1 close
  10849. *------------------------------------------*/
  10850. void clif_Mail_window(int fd, int flag)
  10851. {
  10852. WFIFOHEAD(fd,packet_len(0x260));
  10853. WFIFOW(fd,0) = 0x260;
  10854. WFIFOL(fd,2) = flag;
  10855. WFIFOSET(fd,packet_len(0x260));
  10856. }
  10857. /*------------------------------------------
  10858. * Send Inbox Data to Client
  10859. *------------------------------------------*/
  10860. void clif_Mail_refreshinbox(struct map_session_data *sd)
  10861. {
  10862. int fd = sd->fd;
  10863. struct mail_data *md = &sd->mail.inbox;
  10864. struct mail_message *msg;
  10865. int len, i, j;
  10866. len = 8 + (73 * md->amount);
  10867. WFIFOHEAD(fd,len);
  10868. WFIFOW(fd,0) = 0x240;
  10869. WFIFOW(fd,2) = len;
  10870. WFIFOL(fd,4) = md->amount;
  10871. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  10872. {
  10873. msg = &md->msg[i];
  10874. if (msg->id < 1)
  10875. continue;
  10876. WFIFOL(fd,8+73*j) = msg->id;
  10877. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  10878. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD); // 0: unread, 1: read
  10879. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  10880. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  10881. j++;
  10882. }
  10883. WFIFOSET(fd,len);
  10884. if( md->full )
  10885. {
  10886. char output[100];
  10887. sprintf(output, "Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  10888. clif_disp_onlyself(sd, output, strlen(output));
  10889. }
  10890. }
  10891. /*------------------------------------------
  10892. * Client Request Inbox List
  10893. *------------------------------------------*/
  10894. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  10895. {
  10896. struct mail_data* md = &sd->mail.inbox;
  10897. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  10898. intif_Mail_requestinbox(sd->status.char_id, 1);
  10899. else
  10900. clif_Mail_refreshinbox(sd);
  10901. mail_removeitem(sd, 0);
  10902. mail_removezeny(sd, 0);
  10903. }
  10904. /*------------------------------------------
  10905. * Read Message
  10906. *------------------------------------------*/
  10907. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  10908. {
  10909. int i, fd = sd->fd;
  10910. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10911. if( i == MAIL_MAX_INBOX )
  10912. {
  10913. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  10914. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  10915. return;
  10916. }
  10917. else
  10918. {
  10919. struct mail_message *msg = &sd->mail.inbox.msg[i];
  10920. struct item *item = &msg->item;
  10921. struct item_data *data;
  10922. int msg_len = strlen(msg->body), len;
  10923. if( msg_len == 0 ) {
  10924. strcpy(msg->body, "(no message)");
  10925. msg_len = strlen(msg->body);
  10926. }
  10927. len = 101 + msg_len;
  10928. WFIFOHEAD(fd,len);
  10929. WFIFOW(fd,0) = 0x242;
  10930. WFIFOW(fd,2) = len;
  10931. WFIFOL(fd,4) = msg->id;
  10932. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  10933. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  10934. WFIFOL(fd,72) = 0;
  10935. WFIFOL(fd,76) = msg->zeny;
  10936. if( item->nameid && (data = itemdb_search(item->nameid)) != NULL )
  10937. {
  10938. WFIFOL(fd,80) = item->amount;
  10939. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  10940. WFIFOW(fd,86) = data->type;
  10941. WFIFOB(fd,88) = item->identify;
  10942. WFIFOB(fd,89) = item->attribute;
  10943. WFIFOB(fd,90) = item->refine;
  10944. WFIFOW(fd,91) = item->card[0];
  10945. WFIFOW(fd,93) = item->card[1];
  10946. WFIFOW(fd,95) = item->card[2];
  10947. WFIFOW(fd,97) = item->card[3];
  10948. }
  10949. else // no item, set all to zero
  10950. memset(WFIFOP(fd,80), 0x00, 19);
  10951. WFIFOB(fd,99) = (unsigned char)msg_len;
  10952. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  10953. WFIFOSET(fd,len);
  10954. if (msg->status == MAIL_UNREAD) {
  10955. msg->status = MAIL_READ;
  10956. intif_Mail_read(mail_id);
  10957. clif_parse_Mail_refreshinbox(fd, sd);
  10958. }
  10959. }
  10960. }
  10961. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  10962. {
  10963. int mail_id = RFIFOL(fd,2);
  10964. if( mail_id <= 0 )
  10965. return;
  10966. if( mail_invalid_operation(sd) )
  10967. return;
  10968. clif_Mail_read(sd, RFIFOL(fd,2));
  10969. }
  10970. /*------------------------------------------
  10971. * Get Attachment from Message
  10972. *------------------------------------------*/
  10973. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  10974. {
  10975. int mail_id = RFIFOL(fd,2);
  10976. int i;
  10977. bool fail = false;
  10978. if( mail_id <= 0 )
  10979. return;
  10980. if( mail_invalid_operation(sd) )
  10981. return;
  10982. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10983. if( i == MAIL_MAX_INBOX )
  10984. return;
  10985. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  10986. return;
  10987. if( sd->mail.inbox.msg[i].item.nameid > 0 )
  10988. {
  10989. struct item_data *data;
  10990. unsigned int weight;
  10991. if ((data = itemdb_search(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  10992. return;
  10993. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) )
  10994. {
  10995. case ADDITEM_NEW:
  10996. fail = ( pc_inventoryblank(sd) == 0 );
  10997. break;
  10998. case ADDITEM_OVERAMOUNT:
  10999. fail = true;
  11000. }
  11001. if( fail )
  11002. {
  11003. clif_Mail_getattachment(fd, 1);
  11004. return;
  11005. }
  11006. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  11007. if( sd->weight + weight > sd->max_weight )
  11008. {
  11009. clif_Mail_getattachment(fd, 2);
  11010. return;
  11011. }
  11012. }
  11013. sd->mail.inbox.msg[i].zeny = 0;
  11014. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  11015. clif_Mail_read(sd, mail_id);
  11016. intif_Mail_getattach(sd->status.char_id, mail_id);
  11017. }
  11018. /*------------------------------------------
  11019. * Delete Message
  11020. *------------------------------------------*/
  11021. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  11022. {
  11023. int mail_id = RFIFOL(fd,2);
  11024. int i;
  11025. if( mail_id <= 0 )
  11026. return;
  11027. if( mail_invalid_operation(sd) )
  11028. return;
  11029. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11030. if (i < MAIL_MAX_INBOX)
  11031. {
  11032. struct mail_message *msg = &sd->mail.inbox.msg[i];
  11033. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 )
  11034. {// can't delete mail without removing attachment first
  11035. clif_Mail_delete(sd->fd, mail_id, 1);
  11036. return;
  11037. }
  11038. intif_Mail_delete(sd->status.char_id, mail_id);
  11039. }
  11040. }
  11041. /*------------------------------------------
  11042. * Return Mail Message
  11043. *------------------------------------------*/
  11044. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  11045. {
  11046. int mail_id = RFIFOL(fd,2);
  11047. int i;
  11048. if( mail_id <= 0 )
  11049. return;
  11050. if( mail_invalid_operation(sd) )
  11051. return;
  11052. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  11053. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  11054. intif_Mail_return(sd->status.char_id, mail_id);
  11055. else
  11056. clif_Mail_return(sd->fd, mail_id, 1);
  11057. }
  11058. /*------------------------------------------
  11059. * Set Attachment
  11060. *------------------------------------------*/
  11061. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  11062. {
  11063. int idx = RFIFOW(fd,2);
  11064. int amount = RFIFOL(fd,4);
  11065. unsigned char flag;
  11066. if (idx < 0 || amount < 0)
  11067. return;
  11068. flag = mail_setitem(sd, idx, amount);
  11069. clif_Mail_setattachment(fd,idx,flag);
  11070. }
  11071. /*------------------------------------------
  11072. * Mail Window Operation
  11073. * S 0246 <flag>.W
  11074. * 0 : Switch to 'new mail' window, or Close mailbox
  11075. * 1 : ???
  11076. * 2 : Zeny entering start
  11077. *------------------------------------------*/
  11078. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  11079. {
  11080. int flag = RFIFOW(fd,2);
  11081. if (flag == 0 || flag == 1)
  11082. mail_removeitem(sd, 0);
  11083. if (flag == 0 || flag == 2)
  11084. mail_removezeny(sd, 0);
  11085. }
  11086. /*------------------------------------------
  11087. * Send Mail
  11088. * S 0248 <packet len>.w <nick>.24B <title>.40B <body len>.B <message>.?B 00
  11089. *------------------------------------------*/
  11090. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  11091. {
  11092. struct mail_message msg;
  11093. int body_len;
  11094. if( sd->state.trading )
  11095. return;
  11096. if( RFIFOW(fd,2) < 69 ) {
  11097. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  11098. return;
  11099. }
  11100. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 )
  11101. {
  11102. clif_displaymessage(sd->fd,"Cannot send mails too fast!!.");
  11103. clif_Mail_send(fd, true); // fail
  11104. return;
  11105. }
  11106. body_len = RFIFOB(fd,68);
  11107. if (body_len > MAIL_BODY_LENGTH)
  11108. body_len = MAIL_BODY_LENGTH;
  11109. if( !mail_setattachment(sd, &msg) )
  11110. { // Invalid Append condition
  11111. clif_Mail_send(sd->fd, true); // fail
  11112. mail_removeitem(sd,0);
  11113. mail_removezeny(sd,0);
  11114. return;
  11115. }
  11116. msg.id = 0; // id will be assigned by charserver
  11117. msg.send_id = sd->status.char_id;
  11118. msg.dest_id = 0; // will attempt to resolve name
  11119. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  11120. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  11121. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  11122. if (body_len)
  11123. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  11124. else
  11125. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  11126. msg.timestamp = time(NULL);
  11127. if( !intif_Mail_send(sd->status.account_id, &msg) )
  11128. mail_deliveryfail(sd, &msg);
  11129. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  11130. }
  11131. /*==========================================
  11132. * AUCTION SYSTEM
  11133. * By Zephyrus
  11134. *==========================================*/
  11135. void clif_Auction_openwindow(struct map_session_data *sd)
  11136. {
  11137. int fd = sd->fd;
  11138. if( sd->state.storage_flag || sd->vender_id || sd->state.trading )
  11139. return;
  11140. WFIFOHEAD(fd,12);
  11141. WFIFOW(fd,0) = 0x25f;
  11142. WFIFOL(fd,2) = 0;
  11143. WFIFOB(fd,6) = 0xb6;
  11144. WFIFOB(fd,7) = 0x00;
  11145. WFIFOB(fd,8) = 0xa6;
  11146. WFIFOB(fd,9) = 0xde;
  11147. WFIFOW(fd,10) = 0;
  11148. WFIFOSET(fd,12);
  11149. }
  11150. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  11151. {
  11152. int i, fd = sd->fd, len = sizeof(struct auction_data);
  11153. struct auction_data auction;
  11154. struct item_data *item;
  11155. int k;
  11156. WFIFOHEAD(fd,20);
  11157. WFIFOW(fd,0) = 0x252;
  11158. WFIFOW(fd,2) = 12 + (count * 83);
  11159. WFIFOL(fd,4) = pages;
  11160. WFIFOL(fd,8) = count;
  11161. for( i = 0; i < count; i++ )
  11162. {
  11163. memcpy(&auction, RBUFP(buf,i * len), len);
  11164. k = 12 + (i * 83);
  11165. WFIFOL(fd,k) = auction.auction_id;
  11166. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  11167. if( (item = itemdb_search(auction.item.nameid)) != NULL && item->view_id > 0 )
  11168. WFIFOW(fd,28+k) = item->view_id;
  11169. else
  11170. WFIFOW(fd,28+k) = auction.item.nameid;
  11171. WFIFOW(fd,30+k) = auction.type;
  11172. WFIFOW(fd,32+k) = 0; // ??
  11173. WFIFOW(fd,34+k) = auction.item.amount; // Allways 1
  11174. WFIFOB(fd,36+k) = auction.item.identify;
  11175. WFIFOB(fd,37+k) = auction.item.attribute;
  11176. WFIFOB(fd,38+k) = auction.item.refine;
  11177. WFIFOW(fd,39+k) = auction.item.card[0];
  11178. WFIFOW(fd,41+k) = auction.item.card[1];
  11179. WFIFOW(fd,43+k) = auction.item.card[2];
  11180. WFIFOW(fd,45+k) = auction.item.card[3];
  11181. WFIFOL(fd,47+k) = auction.price;
  11182. WFIFOL(fd,51+k) = auction.buynow;
  11183. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  11184. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  11185. }
  11186. WFIFOSET(fd, 12 + (count * 83));
  11187. }
  11188. static void clif_Auction_setitem(int fd, int index, bool fail)
  11189. {
  11190. WFIFOHEAD(fd,packet_len(0x256));
  11191. WFIFOW(fd,0) = 0x256;
  11192. WFIFOW(fd,2) = index;
  11193. WFIFOB(fd,4) = fail;
  11194. WFIFOSET(fd,packet_len(0x256));
  11195. }
  11196. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd)
  11197. {
  11198. if( sd->auction.amount > 0 )
  11199. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  11200. sd->auction.amount = 0;
  11201. }
  11202. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
  11203. {
  11204. int idx = RFIFOW(fd,2) - 2;
  11205. int amount = RFIFOL(fd,4); // Allways 1
  11206. struct item_data *item;
  11207. if( sd->auction.amount > 0 )
  11208. sd->auction.amount = 0;
  11209. if( idx < 0 || idx >= MAX_INVENTORY )
  11210. {
  11211. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  11212. return;
  11213. }
  11214. if( amount != 1 || amount < 0 || amount > sd->status.inventory[idx].amount )
  11215. { // By client, amount is allways set to 1. Maybe this is a future implementation.
  11216. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  11217. return;
  11218. }
  11219. 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) )
  11220. { // Consumible or pets are not allowed
  11221. clif_Auction_setitem(sd->fd, idx, true);
  11222. return;
  11223. }
  11224. if( !pc_candrop(sd, &sd->status.inventory[idx]) || !sd->status.inventory[idx].identify )
  11225. { // Quest Item or something else
  11226. clif_Auction_setitem(sd->fd, idx, true);
  11227. return;
  11228. }
  11229. sd->auction.index = idx;
  11230. sd->auction.amount = amount;
  11231. clif_Auction_setitem(fd, idx + 2, false);
  11232. }
  11233. // 0 = You have failed to bid into the auction
  11234. // 1 = You have successfully bid in the auction
  11235. // 2 = The auction has been canceled
  11236. // 3 = An auction with at least one bidder cannot be canceled
  11237. // 4 = You cannot register more than 5 items in an auction at a time
  11238. // 5 = You do not have enough Zeny to pay the Auction Fee
  11239. // 6 = You have won the auction
  11240. // 7 = You have failed to win the auction
  11241. // 8 = You do not have enough Zeny
  11242. // 9 = You cannot place more than 5 bids at a time
  11243. void clif_Auction_message(int fd, unsigned char flag)
  11244. {
  11245. WFIFOHEAD(fd,3);
  11246. WFIFOW(fd,0) = 0x250;
  11247. WFIFOB(fd,2) = flag;
  11248. WFIFOSET(fd,3);
  11249. }
  11250. // 0 = You have ended the auction
  11251. // 1 = You cannot end the auction
  11252. // 2 = Bid number is incorrect
  11253. void clif_Auction_close(int fd, unsigned char flag)
  11254. {
  11255. WFIFOHEAD(fd,6);
  11256. WFIFOW(fd,0) = 0x25d;
  11257. WFIFOL(fd,2) = flag;
  11258. WFIFOSET(fd,6);
  11259. }
  11260. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  11261. {
  11262. struct auction_data auction;
  11263. struct item_data *item;
  11264. auction.price = RFIFOL(fd,2);
  11265. auction.buynow = RFIFOL(fd,6);
  11266. auction.hours = RFIFOW(fd,10);
  11267. // Invalid Situations...
  11268. if( sd->auction.amount < 1 )
  11269. {
  11270. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  11271. return;
  11272. }
  11273. if( auction.price >= auction.buynow )
  11274. {
  11275. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  11276. return;
  11277. }
  11278. if( auction.hours < 1 || auction.hours > 48 )
  11279. {
  11280. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  11281. return;
  11282. }
  11283. // Auction checks...
  11284. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) )
  11285. {
  11286. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  11287. return;
  11288. }
  11289. if( auction.buynow > battle_config.auction_maximumprice )
  11290. { // Zeny Limits
  11291. auction.buynow = battle_config.auction_maximumprice;
  11292. if( auction.price >= auction.buynow )
  11293. auction.price = auction.buynow - 1;
  11294. }
  11295. auction.auction_id = 0;
  11296. auction.seller_id = sd->status.char_id;
  11297. safestrncpy(auction.seller_name, sd->status.name, NAME_LENGTH);
  11298. auction.buyer_id = 0;
  11299. memset(&auction.buyer_name, '\0', NAME_LENGTH);
  11300. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  11301. {
  11302. clif_Auction_message(fd, 2); // The auction has been canceled
  11303. return;
  11304. }
  11305. if( (item = itemdb_search(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  11306. { // Just in case
  11307. clif_Auction_message(fd, 2); // The auction has been canceled
  11308. return;
  11309. }
  11310. safestrncpy(auction.item_name, item->jname, ITEM_NAME_LENGTH);
  11311. auction.type = item->type;
  11312. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  11313. auction.item.amount = 1;
  11314. auction.timestamp = 0;
  11315. if( !intif_Auction_register(&auction) )
  11316. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  11317. else
  11318. {
  11319. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1, 6);
  11320. sd->auction.amount = 0;
  11321. pc_payzeny(sd, auction.hours * battle_config.auction_feeperhour);
  11322. }
  11323. }
  11324. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd)
  11325. {
  11326. unsigned int auction_id = RFIFOL(fd,2);
  11327. intif_Auction_cancel(sd->status.char_id, auction_id);
  11328. }
  11329. void clif_parse_Auction_close(int fd, struct map_session_data *sd)
  11330. {
  11331. unsigned int auction_id = RFIFOL(fd,2);
  11332. intif_Auction_close(sd->status.char_id, auction_id);
  11333. }
  11334. void clif_parse_Auction_bid(int fd, struct map_session_data *sd)
  11335. {
  11336. unsigned int auction_id = RFIFOL(fd,2);
  11337. int bid = RFIFOL(fd,6);
  11338. if( !pc_can_give_items(pc_isGM(sd)) )
  11339. { //They aren't supposed to give zeny [Inkfish]
  11340. clif_displaymessage(sd->fd, msg_txt(246));
  11341. return;
  11342. }
  11343. if( bid <= 0 )
  11344. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  11345. else if( bid > sd->status.zeny )
  11346. clif_Auction_message(fd, 8); // You do not have enough zeny
  11347. else
  11348. {
  11349. pc_payzeny(sd, bid);
  11350. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  11351. }
  11352. }
  11353. /*------------------------------------------
  11354. * Auction Search
  11355. * S 0251 <search type>.w <search price>.l <search text>.24B <page number>.w
  11356. * Search Type: 0 Armor 1 Weapon 2 Card 3 Misc 4 By Text 5 By Price 6 Sell 7 Buy
  11357. *------------------------------------------*/
  11358. void clif_parse_Auction_search(int fd, struct map_session_data* sd)
  11359. {
  11360. char search_text[NAME_LENGTH];
  11361. short type = RFIFOW(fd,2), page = RFIFOW(fd,32);
  11362. int price = RFIFOL(fd,4);
  11363. clif_parse_Auction_cancelreg(fd, sd);
  11364. safestrncpy(search_text, (char*)RFIFOP(fd,8), NAME_LENGTH);
  11365. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  11366. }
  11367. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  11368. {
  11369. short type = RFIFOW(fd,2) + 6;
  11370. clif_parse_Auction_cancelreg(fd, sd);
  11371. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  11372. }
  11373. #endif
  11374. /*==========================================
  11375. * CASH/POINT SHOP
  11376. *==========================================*/
  11377. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  11378. {
  11379. int fd,i;
  11380. nullpo_retv(sd);
  11381. nullpo_retv(nd);
  11382. fd = sd->fd;
  11383. sd->npc_shopid = nd->bl.id;
  11384. WFIFOHEAD(fd, 200 * 11 + 12);
  11385. WFIFOW(fd,0) = 0x287;
  11386. WFIFOW(fd,2) = 12 + nd->u.shop.count*11;
  11387. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  11388. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  11389. for( i = 0; i < nd->u.shop.count; i++ )
  11390. {
  11391. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  11392. WFIFOL(fd,12+i*11) = nd->u.shop.shop_item[i].value;
  11393. WFIFOL(fd,16+i*11) = nd->u.shop.shop_item[i].value; // Discount Price? Maybe a Discount item
  11394. WFIFOB(fd,20+i*11) = itemtype(id->type);
  11395. WFIFOW(fd,21+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  11396. }
  11397. WFIFOSET(fd,WFIFOW(fd,2));
  11398. }
  11399. /// Cashshop Buy Ack (ZC_PC_CASH_POINT_UPDATE)
  11400. /// S 0289 <cash point>.L <kafra point>.L <error>.W
  11401. ///
  11402. /// @param error
  11403. /// 0: The deal has successfully completed. (ERROR_TYPE_NONE)
  11404. /// 1: The Purchase has failed because the NPC does not exist. (ERROR_TYPE_NPC)
  11405. /// 2: The Purchase has failed because the Kafra Shop System is not working correctly. (ERROR_TYPE_SYSTEM)
  11406. /// 3: You are over your Weight Limit. (ERROR_TYPE_INVENTORY_WEIGHT)
  11407. /// 4: You cannot purchase items while you are in a trade. (ERROR_TYPE_EXCHANGE)
  11408. /// 5: The Purchase has failed because the Item Information was incorrect. (ERROR_TYPE_ITEM_ID)
  11409. /// 6: You do not have enough Kafra Credit Points. (ERROR_TYPE_MONEY)
  11410. /// 7: You can purchase up to 10 items.
  11411. /// 8: Some items could not be purchased.
  11412. void clif_cashshop_ack(struct map_session_data* sd, int error)
  11413. {
  11414. int fd = sd->fd;
  11415. WFIFOHEAD(fd, packet_len(0x289));
  11416. WFIFOW(fd,0) = 0x289;
  11417. WFIFOL(fd,2) = sd->cashPoints;
  11418. WFIFOL(fd,6) = sd->kafraPoints;
  11419. WFIFOW(fd,10) = TOW(error);
  11420. WFIFOSET(fd, packet_len(0x289));
  11421. }
  11422. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
  11423. {
  11424. int fail = 0, amount, points;
  11425. short nameid;
  11426. nullpo_retv(sd);
  11427. nameid = RFIFOW(fd,2);
  11428. amount = RFIFOW(fd,4);
  11429. points = RFIFOL(fd,6); // Not Implemented. Should be 0
  11430. if( sd->state.trading || !sd->npc_shopid )
  11431. fail = 1;
  11432. else
  11433. fail = npc_cashshop_buy(sd, nameid, amount, points);
  11434. clif_cashshop_ack(sd, fail);
  11435. }
  11436. /*==========================================
  11437. * Adoption System
  11438. *==========================================*/
  11439. // 0 : "You cannot adopt more than 1 child."
  11440. // 1 : "You must be at least character level 70 in order to adopt someone."
  11441. // 2 : "You cannot adopt a married person."
  11442. void clif_Adopt_reply(struct map_session_data *sd, int type)
  11443. {
  11444. int fd = sd->fd;
  11445. WFIFOHEAD(fd,6);
  11446. WFIFOW(fd,0) = 0x0216;
  11447. WFIFOL(fd,2) = type;
  11448. WFIFOSET(fd,6);
  11449. }
  11450. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  11451. {
  11452. int fd = sd->fd;
  11453. WFIFOHEAD(fd,34);
  11454. WFIFOW(fd,0) = 0x01f6;
  11455. WFIFOL(fd,2) = src->status.account_id;
  11456. WFIFOL(fd,6) = p_id;
  11457. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  11458. WFIFOSET(fd,34);
  11459. }
  11460. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  11461. {
  11462. struct map_session_data *tsd = map_id2sd(RFIFOL(fd,2)), *p_sd = map_charid2sd(sd->status.partner_id);
  11463. if( pc_can_Adopt(sd, p_sd, tsd) )
  11464. {
  11465. tsd->adopt_invite = sd->status.account_id;
  11466. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  11467. }
  11468. }
  11469. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd)
  11470. {
  11471. int p1_id = RFIFOL(fd,2);
  11472. int p2_id = RFIFOL(fd,6);
  11473. int result = RFIFOL(fd,10);
  11474. struct map_session_data* p1_sd = map_id2sd(p1_id);
  11475. struct map_session_data* p2_sd = map_id2sd(p2_id);
  11476. int pid = sd->adopt_invite;
  11477. sd->adopt_invite = 0;
  11478. if( p1_sd == NULL || p2_sd == NULL )
  11479. return; // Both players need to be online
  11480. if( pid != p1_sd->status.account_id )
  11481. return; // Incorrect values
  11482. if( result == 0 )
  11483. return; // Rejected
  11484. pc_adoption(p1_sd, p2_sd, sd);
  11485. }
  11486. /*==========================================
  11487. * Convex Mirror
  11488. * S 0293 <flag>.b <x>.l <y>.l <Hours>.w <Minutes>.w <unknown>.l <monster name>.40B <unknown>.11B
  11489. *==========================================*/
  11490. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  11491. {
  11492. WFIFOHEAD(fd,70);
  11493. memset(WFIFOP(fd,0),0,70);
  11494. WFIFOW(fd,0) = 0x0293;
  11495. if( md != NULL )
  11496. {
  11497. if( md->bl.prev != NULL )
  11498. { // Boss on This Map
  11499. if( flag )
  11500. {
  11501. WFIFOB(fd,2) = 1;
  11502. WFIFOL(fd,3) = md->bl.x;
  11503. WFIFOL(fd,7) = md->bl.y;
  11504. }
  11505. else
  11506. WFIFOB(fd,2) = 2; // First Time
  11507. }
  11508. else if (md->spawn_timer != -1)
  11509. { // Boss is Dead
  11510. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  11511. unsigned int seconds;
  11512. int hours, minutes;
  11513. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000 + 60;
  11514. hours = seconds / (60 * 60);
  11515. seconds = seconds - (60 * 60 * hours);
  11516. minutes = seconds / 60;
  11517. WFIFOB(fd,2) = 3;
  11518. WFIFOW(fd,11) = hours; // Hours
  11519. WFIFOW(fd,13) = minutes; // Minutes
  11520. }
  11521. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  11522. }
  11523. WFIFOSET(fd,70);
  11524. }
  11525. /*==========================================
  11526. * Requesting equip of a player
  11527. *------------------------------------------*/
  11528. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  11529. {
  11530. int charid = RFIFOL(fd, 2);
  11531. struct map_session_data* tsd = map_id2sd(charid);
  11532. if (!tsd)
  11533. return;
  11534. if( tsd->status.show_equip || (battle_config.gm_viewequip_min_lv && pc_isGM(sd) >= battle_config.gm_viewequip_min_lv) )
  11535. clif_viewequip_ack(sd, tsd);
  11536. else
  11537. clif_viewequip_fail(sd);
  11538. }
  11539. /*==========================================
  11540. * Equip window (un)tick
  11541. * S 02d8 <zero?>.L <flag>.L
  11542. *------------------------------------------*/
  11543. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  11544. {
  11545. bool flag = (bool)RFIFOL(fd,6); // 0=off, 1=on
  11546. sd->status.show_equip = flag;
  11547. clif_equiptickack(sd, flag);
  11548. }
  11549. /*==========================================
  11550. * Questlog System [Kevin] [Inkfish]
  11551. *------------------------------------------*/
  11552. //* 02B1 <packet_len>.W <quest_num>.L { <quest_id>.L <state>.B }.5B*
  11553. void clif_quest_send_list(struct map_session_data * sd)
  11554. {
  11555. int fd = sd->fd;
  11556. int i;
  11557. int len = sd->avail_quests*5+8;
  11558. WFIFOHEAD(fd,len);
  11559. WFIFOW(fd, 0) = 0x02B1;
  11560. WFIFOW(fd, 2) = len;
  11561. WFIFOL(fd, 4) = sd->avail_quests;
  11562. for( i = 0; i < sd->avail_quests; i++ )
  11563. {
  11564. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  11565. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  11566. }
  11567. WFIFOSET(fd, len);
  11568. }
  11569. //* 02B2 <packet_len>.W <quest_num>.L { <quest_id>.L <start time>.L <expire time>.L <num mobs>.W {<mob id>.L <mob count>.W <Mob Name>.24B}.30B[3] }.104B*
  11570. void clif_quest_send_mission(struct map_session_data * sd)
  11571. {
  11572. int fd = sd->fd;
  11573. int i, j;
  11574. int len = sd->avail_quests*104+8;
  11575. struct mob_db *mob;
  11576. WFIFOHEAD(fd, len);
  11577. WFIFOW(fd, 0) = 0x02B2;
  11578. WFIFOW(fd, 2) = len;
  11579. WFIFOL(fd, 4) = sd->avail_quests;
  11580. for( i = 0; i < sd->avail_quests; i++ )
  11581. {
  11582. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  11583. WFIFOL(fd, i*104+12) = sd->quest_log[i].time - quest_db[sd->quest_index[i]].time;
  11584. WFIFOL(fd, i*104+16) = sd->quest_log[i].time;
  11585. WFIFOW(fd, i*104+20) = quest_db[sd->quest_index[i]].num_objectives;
  11586. for( j = 0 ; j < quest_db[sd->quest_index[i]].num_objectives; j++ )
  11587. {
  11588. WFIFOL(fd, i*104+22+j*30) = quest_db[sd->quest_index[i]].mob[j];
  11589. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].count[j];
  11590. mob = mob_db(quest_db[sd->quest_index[i]].mob[j]);
  11591. memcpy(WFIFOP(fd, i*104+28+j*30), mob?mob->jname:"NULL", NAME_LENGTH);
  11592. }
  11593. }
  11594. WFIFOSET(fd, len);
  11595. }
  11596. //* 02B3 <quest_id>.L <state>.B <start time>.L <expire time>.L <num mobs>.W {<mob id>.L <mob count>.W <Mob Name>.24B}.30B[3]
  11597. void clif_quest_add(struct map_session_data * sd, struct quest * qd, int index)
  11598. {
  11599. int fd = sd->fd;
  11600. int i;
  11601. struct mob_db *mob;
  11602. WFIFOHEAD(fd, packet_len(0x02B3));
  11603. WFIFOW(fd, 0) = 0x02B3;
  11604. WFIFOL(fd, 2) = qd->quest_id;
  11605. WFIFOB(fd, 6) = qd->state;
  11606. WFIFOB(fd, 7) = qd->time - quest_db[index].time;
  11607. WFIFOL(fd, 11) = qd->time;
  11608. WFIFOW(fd, 15) = quest_db[index].num_objectives;
  11609. for( i = 0; i < quest_db[index].num_objectives; i++ )
  11610. {
  11611. WFIFOL(fd, i*30+17) = quest_db[index].mob[i];
  11612. WFIFOW(fd, i*30+21) = qd->count[i];
  11613. mob = mob_db(quest_db[index].mob[i]);
  11614. memcpy(WFIFOP(fd, i*30+23), mob?mob->jname:"NULL", NAME_LENGTH);
  11615. }
  11616. WFIFOSET(fd, packet_len(0x02B3));
  11617. }
  11618. //* 02B4 <quest_id>.L
  11619. void clif_quest_delete(struct map_session_data * sd, int quest_id)
  11620. {
  11621. int fd = sd->fd;
  11622. WFIFOHEAD(fd, packet_len(0x02B4));
  11623. WFIFOW(fd, 0) = 0x02B4;
  11624. WFIFOL(fd, 2) = quest_id;
  11625. WFIFOSET(fd, packet_len(0x02B4));
  11626. }
  11627. //* 02b5 <packet_len>.w <mob_num>.w { <quest_id>.d <mob_id>.d <count_total>.w <count_partial>.w }.mob_num
  11628. void clif_quest_update_objective(struct map_session_data * sd, struct quest * qd, int index)
  11629. {
  11630. int fd = sd->fd;
  11631. int i;
  11632. int len = quest_db[index].num_objectives*12+6;
  11633. WFIFOHEAD(fd, len);
  11634. WFIFOW(fd, 0) = 0x02B5;
  11635. WFIFOW(fd, 2) = len;
  11636. WFIFOW(fd, 4) = quest_db[index].num_objectives;
  11637. for( i = 0; i < quest_db[index].num_objectives; i++ )
  11638. {
  11639. WFIFOL(fd, i*12+6) = qd->quest_id;
  11640. WFIFOL(fd, i*12+10) = quest_db[index].mob[i];
  11641. WFIFOW(fd, i*12+14) = quest_db[index].count[i];
  11642. WFIFOW(fd, i*12+16) = qd->count[i];
  11643. }
  11644. WFIFOSET(fd, len);
  11645. }
  11646. //* 02B6 <quest_id>.L <state>.B
  11647. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  11648. {
  11649. quest_update_status(sd, RFIFOL(fd,2), RFIFOB(fd,6)?Q_ACTIVE:Q_INACTIVE);
  11650. }
  11651. //* 02B7 <quest_id>.L <state_to>.B
  11652. void clif_quest_update_status(struct map_session_data * sd, int quest_id, bool active)
  11653. {
  11654. int fd = sd->fd;
  11655. WFIFOHEAD(fd, packet_len(0x02B7));
  11656. WFIFOW(fd, 0) = 0x02B7;
  11657. WFIFOL(fd, 2) = quest_id;
  11658. WFIFOB(fd, 6) = active;
  11659. WFIFOSET(fd, packet_len(0x02B7));
  11660. }
  11661. void clif_quest_show_event(struct map_session_data *sd, struct block_list *bl, short state, short color)
  11662. {
  11663. #if PACKETVER >= 20090218
  11664. int fd = sd->fd;
  11665. WFIFOHEAD(fd, packet_len(0x446));
  11666. WFIFOW(fd, 0) = 0x446;
  11667. WFIFOL(fd, 2) = bl->id;
  11668. WFIFOW(fd, 6) = bl->x;
  11669. WFIFOW(fd, 8) = bl->y;
  11670. WFIFOW(fd, 10) = state;
  11671. WFIFOW(fd, 12) = color;
  11672. WFIFOSET(fd, packet_len(0x446));
  11673. #endif
  11674. }
  11675. /*==========================================
  11676. * Mercenary System
  11677. *==========================================*/
  11678. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  11679. {
  11680. struct mercenary_data *md;
  11681. struct status_data *status;
  11682. int fd;
  11683. if( sd == NULL || (md = sd->md) == NULL )
  11684. return;
  11685. fd = sd->fd;
  11686. status = &md->battle_status;
  11687. WFIFOHEAD(fd,8);
  11688. WFIFOW(fd,0) = 0x02a2;
  11689. WFIFOW(fd,2) = type;
  11690. switch( type )
  11691. {
  11692. case SP_ATK1:
  11693. {
  11694. int atk = rand()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  11695. WFIFOL(fd,4) = cap_value(atk, 0, SHRT_MAX);
  11696. }
  11697. break;
  11698. case SP_MATK1:
  11699. WFIFOL(fd,4) = cap_value(status->matk_max, 0, SHRT_MAX);
  11700. break;
  11701. case SP_HIT:
  11702. WFIFOL(fd,4) = status->hit;
  11703. break;
  11704. case SP_CRITICAL:
  11705. WFIFOL(fd,4) = status->cri/10;
  11706. break;
  11707. case SP_DEF1:
  11708. WFIFOL(fd,4) = status->def;
  11709. break;
  11710. case SP_MDEF1:
  11711. WFIFOL(fd,4) = status->mdef;
  11712. break;
  11713. case SP_MERCFLEE:
  11714. WFIFOL(fd,4) = status->flee;
  11715. break;
  11716. case SP_ASPD:
  11717. WFIFOL(fd,4) = status->amotion;
  11718. break;
  11719. case SP_HP:
  11720. WFIFOL(fd,4) = status->hp;
  11721. break;
  11722. case SP_MAXHP:
  11723. WFIFOL(fd,4) = status->max_hp;
  11724. break;
  11725. case SP_SP:
  11726. WFIFOL(fd,4) = status->sp;
  11727. break;
  11728. case SP_MAXSP:
  11729. WFIFOL(fd,4) = status->max_sp;
  11730. break;
  11731. case SP_MERCKILLS:
  11732. WFIFOL(fd,4) = md->mercenary.kill_count;
  11733. break;
  11734. case SP_MERCFAITH:
  11735. WFIFOL(fd,4) = mercenary_get_faith(md);
  11736. break;
  11737. }
  11738. WFIFOSET(fd,8);
  11739. }
  11740. void clif_mercenary_info(struct map_session_data *sd)
  11741. {
  11742. int fd;
  11743. struct mercenary_data *md;
  11744. struct status_data *status;
  11745. int atk;
  11746. if( sd == NULL || (md = sd->md) == NULL )
  11747. return;
  11748. fd = sd->fd;
  11749. status = &md->battle_status;
  11750. WFIFOHEAD(fd,80);
  11751. WFIFOW(fd,0) = 0x029b;
  11752. WFIFOL(fd,2) = md->bl.id;
  11753. // Mercenary shows ATK as a random value between ATK ~ ATK2
  11754. atk = rand()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  11755. WFIFOW(fd,6) = cap_value(atk, 0, SHRT_MAX);
  11756. WFIFOW(fd,8) = cap_value(status->matk_max, 0, SHRT_MAX);
  11757. WFIFOW(fd,10) = status->hit;
  11758. WFIFOW(fd,12) = status->cri/10;
  11759. WFIFOW(fd,14) = status->def;
  11760. WFIFOW(fd,16) = status->mdef;
  11761. WFIFOW(fd,18) = status->flee;
  11762. WFIFOW(fd,20) = status->amotion;
  11763. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  11764. WFIFOW(fd,46) = md->db->lv;
  11765. WFIFOL(fd,48) = status->hp;
  11766. WFIFOL(fd,52) = status->max_hp;
  11767. WFIFOL(fd,56) = status->sp;
  11768. WFIFOL(fd,60) = status->max_sp;
  11769. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  11770. WFIFOW(fd,68) = mercenary_get_faith(md);
  11771. WFIFOL(fd,70) = mercenary_get_calls(md);
  11772. WFIFOL(fd,74) = md->mercenary.kill_count;
  11773. WFIFOW(fd,78) = md->battle_status.rhw.range;
  11774. WFIFOSET(fd,80);
  11775. }
  11776. void clif_mercenary_skillblock(struct map_session_data *sd)
  11777. {
  11778. struct mercenary_data *md;
  11779. int fd, i, len = 4, id, j;
  11780. if( sd == NULL || (md = sd->md) == NULL )
  11781. return;
  11782. fd = sd->fd;
  11783. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  11784. WFIFOW(fd,0) = 0x029d;
  11785. for( i = 0; i < MAX_MERCSKILL; i++ )
  11786. {
  11787. if( (id = md->db->skill[i].id) == 0 )
  11788. continue;
  11789. j = id - MC_SKILLBASE;
  11790. WFIFOW(fd,len) = id;
  11791. WFIFOW(fd,len+2) = skill_get_inf(id);
  11792. WFIFOW(fd,len+4) = 0;
  11793. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  11794. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  11795. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  11796. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  11797. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  11798. len += 37;
  11799. }
  11800. WFIFOW(fd,2) = len;
  11801. WFIFOSET(fd,len);
  11802. }
  11803. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  11804. {
  11805. int option = RFIFOB(fd,2);
  11806. if( sd->md == NULL )
  11807. return;
  11808. if( option == 2 ) merc_delete(sd->md, 2);
  11809. }
  11810. /*------------------------------------------
  11811. * Mercenary Message
  11812. * 0 = Mercenary soldier's duty hour is over.
  11813. * 1 = Your mercenary soldier has been killed.
  11814. * 2 = Your mercenary soldier has been fired.
  11815. * 3 = Your mercenary soldier has ran away.
  11816. *------------------------------------------*/
  11817. void clif_mercenary_message(struct map_session_data* sd, int message)
  11818. {
  11819. clif_msg(sd, 1266 + message);
  11820. }
  11821. /*------------------------------------------
  11822. * Rental System Messages
  11823. *------------------------------------------*/
  11824. void clif_rental_time(int fd, int nameid, int seconds)
  11825. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  11826. WFIFOHEAD(fd,8);
  11827. WFIFOW(fd,0) = 0x0298;
  11828. WFIFOW(fd,2) = nameid;
  11829. WFIFOL(fd,4) = seconds;
  11830. WFIFOSET(fd,8);
  11831. }
  11832. void clif_rental_expired(int fd, int nameid)
  11833. { // '<ItemName>' item has been deleted from the Inventory
  11834. WFIFOHEAD(fd,6);
  11835. WFIFOW(fd,0) = 0x0299;
  11836. WFIFOW(fd,2) = 0;
  11837. WFIFOW(fd,4) = nameid;
  11838. WFIFOSET(fd,6);
  11839. }
  11840. /*------------------------------------------
  11841. * Book Reading
  11842. *------------------------------------------*/
  11843. void clif_readbook(int fd, int book_id, int page)
  11844. {
  11845. WFIFOHEAD(fd,10);
  11846. WFIFOW(fd,0) = 0x0294;
  11847. WFIFOL(fd,2) = book_id;
  11848. WFIFOL(fd,6) = page;
  11849. WFIFOSET(fd,10);
  11850. }
  11851. /*------------------------------------------
  11852. * BattleGround Packets
  11853. *------------------------------------------*/
  11854. int clif_bg_hp(struct map_session_data *sd)
  11855. {
  11856. unsigned char buf[16];
  11857. #if PACKETVER < 20100126
  11858. const int cmd = 0x106;
  11859. #else
  11860. const int cmd = 0x80e;
  11861. #endif
  11862. nullpo_ret(sd);
  11863. WBUFW(buf,0)=cmd;
  11864. WBUFL(buf,2) = sd->status.account_id;
  11865. #if PACKETVER < 20100126
  11866. if( sd->battle_status.max_hp > SHRT_MAX )
  11867. { // To correctly display the %hp bar. [Skotlex]
  11868. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  11869. WBUFW(buf,8) = 100;
  11870. }
  11871. else
  11872. {
  11873. WBUFW(buf,6) = sd->battle_status.hp;
  11874. WBUFW(buf,8) = sd->battle_status.max_hp;
  11875. }
  11876. #else
  11877. WBUFL(buf,6) = sd->battle_status.hp;
  11878. WBUFL(buf,10) = sd->battle_status.max_hp;
  11879. #endif
  11880. clif_send(buf, packet_len(cmd), &sd->bl, BG_AREA_WOS);
  11881. return 0;
  11882. }
  11883. int clif_bg_xy(struct map_session_data *sd)
  11884. {
  11885. unsigned char buf[10];
  11886. nullpo_ret(sd);
  11887. WBUFW(buf,0)=0x1eb;
  11888. WBUFL(buf,2)=sd->status.account_id;
  11889. WBUFW(buf,6)=sd->bl.x;
  11890. WBUFW(buf,8)=sd->bl.y;
  11891. clif_send(buf, packet_len(0x1eb), &sd->bl, BG_SAMEMAP_WOS);
  11892. return 0;
  11893. }
  11894. int clif_bg_xy_remove(struct map_session_data *sd)
  11895. {
  11896. unsigned char buf[10];
  11897. nullpo_ret(sd);
  11898. WBUFW(buf,0)=0x1eb;
  11899. WBUFL(buf,2)=sd->status.account_id;
  11900. WBUFW(buf,6)=-1;
  11901. WBUFW(buf,8)=-1;
  11902. clif_send(buf,packet_len(0x1eb),&sd->bl,BG_SAMEMAP_WOS);
  11903. return 0;
  11904. }
  11905. int clif_bg_message(struct battleground_data *bg, const char *name, const char *mes, int len)
  11906. {
  11907. struct map_session_data *sd;
  11908. unsigned char *buf;
  11909. if( (sd = bg_getavailablesd(bg)) == NULL )
  11910. return 0;
  11911. buf = (unsigned char*)aMallocA((len + NAME_LENGTH + 8)*sizeof(unsigned char));
  11912. WBUFW(buf,0) = 0x2dc;
  11913. WBUFW(buf,2) = len + NAME_LENGTH + 8;
  11914. WBUFL(buf,4) = sd->state.bg_id;
  11915. memcpy(WBUFP(buf,8), name, NAME_LENGTH);
  11916. memcpy(WBUFP(buf,32), mes, len);
  11917. clif_send(buf,WBUFW(buf,2), &sd->bl, BG);
  11918. if( buf ) aFree(buf);
  11919. return 0;
  11920. }
  11921. /*==========================================
  11922. * Validates and processes battlechat messages [pakpil]
  11923. * S 0x2db <packet len>.w <text>.?B (<name> : <message>) 00
  11924. *------------------------------------------*/
  11925. void clif_parse_BattleChat(int fd, struct map_session_data* sd)
  11926. {
  11927. const char* text = (char*)RFIFOP(fd,4);
  11928. int textlen = RFIFOW(fd,2) - 4;
  11929. char *name, *message;
  11930. int namelen, messagelen;
  11931. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  11932. return;
  11933. if( is_atcommand(fd, sd, message, 1) )
  11934. return;
  11935. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  11936. return;
  11937. if( battle_config.min_chat_delay )
  11938. {
  11939. if( DIFF_TICK(sd->cantalk_tick, gettick()) > 0 )
  11940. return;
  11941. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  11942. }
  11943. bg_send_message(sd, text, textlen);
  11944. }
  11945. int clif_bg_updatescore(int m)
  11946. {
  11947. struct block_list bl;
  11948. unsigned char buf[6];
  11949. bl.id = 0;
  11950. bl.type = BL_NUL;
  11951. bl.m = m;
  11952. WBUFW(buf,0) = 0x2de;
  11953. WBUFW(buf,2) = map[m].bgscore_lion;
  11954. WBUFW(buf,4) = map[m].bgscore_eagle;
  11955. clif_send(buf,6,&bl,ALL_SAMEMAP);
  11956. return 0;
  11957. }
  11958. int clif_bg_updatescore_single(struct map_session_data *sd)
  11959. {
  11960. int fd;
  11961. nullpo_ret(sd);
  11962. fd = sd->fd;
  11963. WFIFOHEAD(fd,6);
  11964. WFIFOW(fd,0) = 0x2de;
  11965. WFIFOW(fd,2) = map[sd->bl.m].bgscore_lion;
  11966. WFIFOW(fd,4) = map[sd->bl.m].bgscore_eagle;
  11967. WFIFOSET(fd,6);
  11968. return 0;
  11969. }
  11970. int clif_sendbgemblem_area(struct map_session_data *sd)
  11971. {
  11972. unsigned char buf[33];
  11973. nullpo_ret(sd);
  11974. WBUFW(buf, 0) = 0x2dd;
  11975. WBUFL(buf,2) = sd->bl.id;
  11976. safestrncpy((char*)WBUFP(buf,6), sd->status.name, NAME_LENGTH); // name don't show in screen.
  11977. WBUFW(buf,30) = sd->state.bg_id;
  11978. clif_send(buf,packet_len(0x2dd), &sd->bl, AREA);
  11979. return 0;
  11980. }
  11981. int clif_sendbgemblem_single(int fd, struct map_session_data *sd)
  11982. {
  11983. nullpo_ret(sd);
  11984. WFIFOHEAD(fd,32);
  11985. WFIFOW(fd,0) = 0x2dd;
  11986. WFIFOL(fd,2) = sd->bl.id;
  11987. safestrncpy((char*)WFIFOP(fd,6), sd->status.name, NAME_LENGTH);
  11988. WFIFOW(fd,30) = sd->state.bg_id;
  11989. WFIFOSET(fd,packet_len(0x2dd));
  11990. return 0;
  11991. }
  11992. /*==========================================
  11993. * Custom Fonts
  11994. * S 0x2ef <account_id>.l <font id>.w
  11995. *------------------------------------------*/
  11996. int clif_font(struct map_session_data *sd)
  11997. {
  11998. unsigned char buf[8];
  11999. nullpo_ret(sd);
  12000. WBUFW(buf,0) = 0x2ef;
  12001. WBUFL(buf,2) = sd->bl.id;
  12002. WBUFW(buf,6) = sd->state.user_font;
  12003. clif_send(buf, packet_len(0x2ef), &sd->bl, AREA);
  12004. return 1;
  12005. }
  12006. /*==========================================
  12007. * Instancing Window
  12008. *------------------------------------------*/
  12009. int clif_instance(int instance_id, int type, int flag)
  12010. {
  12011. struct map_session_data *sd;
  12012. struct party_data *p;
  12013. unsigned char buf[255];
  12014. if( (p = party_search(instance[instance_id].party_id)) == NULL || (sd = party_getavailablesd(p)) == NULL )
  12015. return 0;
  12016. switch( type )
  12017. {
  12018. case 1:
  12019. // S 0x2cb <Instance name>.63B <Standby Position>.W
  12020. // Required to start the instancing information window on Client
  12021. // This window re-appear each "refresh" of client automatically until type 4 is send to client.
  12022. WBUFW(buf,0) = 0x02CB;
  12023. memcpy(WBUFP(buf,2),instance[instance_id].name,61);
  12024. WBUFW(buf,63) = flag;
  12025. clif_send(buf,packet_len(0x02CB),&sd->bl,PARTY);
  12026. break;
  12027. case 2:
  12028. // S 0x2cc <Standby Position>.W
  12029. // To announce Instancing queue creation if no maps available
  12030. WBUFW(buf,0) = 0x02CC;
  12031. WBUFW(buf,2) = flag;
  12032. clif_send(buf,packet_len(0x02CC),&sd->bl,PARTY);
  12033. break;
  12034. case 3:
  12035. case 4:
  12036. // S 0x2cd <Instance Name>.61B <Instance Remaining Time>.L <Instance Noplayers close time>.L
  12037. WBUFW(buf,0) = 0x02CD;
  12038. memcpy(WBUFP(buf,2),instance[instance_id].name,61);
  12039. if( type == 3 )
  12040. {
  12041. WBUFL(buf,63) = (uint32)instance[instance_id].progress_timeout;
  12042. WBUFL(buf,67) = 0;
  12043. }
  12044. else
  12045. {
  12046. WBUFL(buf,63) = 0;
  12047. WBUFL(buf,67) = (uint32)instance[instance_id].idle_timeout;
  12048. }
  12049. clif_send(buf,packet_len(0x02CD),&sd->bl,PARTY);
  12050. break;
  12051. case 5: // R 02CE <message ID>.L
  12052. // S 0x2ce <Message ID>.L
  12053. // 1 = The Memorial Dungeon expired; it has been destroyed
  12054. // 2 = The Memorial Dungeon's entry time limit expired; it has been destroyed
  12055. // 3 = The Memorial Dungeon has been removed.
  12056. // 4 = Just remove the window, maybe party/guild leave
  12057. WBUFW(buf,0) = 0x02CE;
  12058. WBUFL(buf,2) = flag;
  12059. clif_send(buf,packet_len(0x02CE),&sd->bl,PARTY);
  12060. break;
  12061. }
  12062. return 0;
  12063. }
  12064. void clif_instance_join(int fd, int instance_id)
  12065. {
  12066. if( instance[instance_id].idle_timer != INVALID_TIMER )
  12067. {
  12068. WFIFOHEAD(fd,packet_len(0x02CD));
  12069. WFIFOW(fd,0) = 0x02CD;
  12070. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12071. WFIFOL(fd,63) = 0;
  12072. WFIFOL(fd,67) = (uint32)instance[instance_id].idle_timeout;
  12073. WFIFOSET(fd,packet_len(0x02CD));
  12074. }
  12075. else if( instance[instance_id].progress_timer != INVALID_TIMER )
  12076. {
  12077. WFIFOHEAD(fd,packet_len(0x02CD));
  12078. WFIFOW(fd,0) = 0x02CD;
  12079. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12080. WFIFOL(fd,63) = (uint32)instance[instance_id].progress_timeout;;
  12081. WFIFOL(fd,67) = 0;
  12082. WFIFOSET(fd,packet_len(0x02CD));
  12083. }
  12084. else
  12085. {
  12086. WFIFOHEAD(fd,packet_len(0x02CB));
  12087. WFIFOW(fd,0) = 0x02CB;
  12088. memcpy(WFIFOP(fd,2),instance[instance_id].name,61);
  12089. WFIFOW(fd,63) = 0;
  12090. WFIFOSET(fd,packet_len(0x02CB));
  12091. }
  12092. }
  12093. void clif_instance_leave(int fd)
  12094. {
  12095. WFIFOHEAD(fd,packet_len(0x02CE));
  12096. WFIFOW(fd,0) = 0x02ce;
  12097. WFIFOL(fd,2) = 4;
  12098. WFIFOSET(fd,packet_len(0x02CE));
  12099. }
  12100. void clif_party_show_picker(struct map_session_data * sd, struct item * item_data)
  12101. {
  12102. #if PACKETVER >= 20071002
  12103. unsigned char buf[22];
  12104. WBUFW(buf,0)=0x2b8;
  12105. WBUFL(buf,2) = sd->status.account_id;
  12106. WBUFW(buf,6) = item_data->nameid;
  12107. WBUFB(buf,8) = item_data->identify;
  12108. WBUFB(buf,9) = item_data->attribute;
  12109. WBUFB(buf,10) = item_data->refine;
  12110. WBUFW(buf,11) = item_data->card[0];
  12111. WBUFW(buf,13) = item_data->card[1];
  12112. WBUFW(buf,15) = item_data->card[2];
  12113. WBUFW(buf,17) = item_data->card[3];
  12114. //WBUFW(buf,19) = 0; // equip location? 32+2 for left/right hand, 0x8000 for 'throw' (verify this)
  12115. //WBUFB(buf,21) = 0; // item type
  12116. clif_send(buf, packet_len(0x2b8), &sd->bl, PARTY_SAMEMAP_WOS);
  12117. #endif
  12118. }
  12119. // Display gain exp
  12120. // type = 1 -> base_exp
  12121. // type = 2 -> job_exp
  12122. // flag = 0 -> normal exp gain/lost
  12123. // flag = 1 -> quest exp gain/lost
  12124. void clif_displayexp(struct map_session_data *sd, unsigned int exp, char type, bool quest)
  12125. {
  12126. int fd;
  12127. nullpo_retv(sd);
  12128. fd = sd->fd;
  12129. WFIFOHEAD(fd, packet_len(0x7f6));
  12130. WFIFOW(fd,0) = 0x7f6;
  12131. WFIFOL(fd,2) = sd->bl.id;
  12132. WFIFOL(fd,6) = exp;
  12133. WFIFOW(fd,10) = type;
  12134. WFIFOW(fd,12) = quest?1:0;// Normal exp is shown in yellow, quest exp is shown in purple.
  12135. WFIFOSET(fd,packet_len(0x7f6));
  12136. return;
  12137. }
  12138. /// Displays digital clock digits on top of the screen (ZC_SHOWDIGIT).
  12139. /// type:
  12140. /// 0: Displays 'value' for 5 seconds.
  12141. /// 1: Incremental counter (1 tick/second), negated 'value' specifies start value (e.g. using -10 lets the counter start at 10).
  12142. /// 2: Decremental counter (1 tick/second), negated 'value' specifies start value (does not stop when reaching 0, but overflows).
  12143. /// 3: Decremental counter (2 ticks/second), 'value' specifies start value (stops when reaching 0, displays at most 2 digits).
  12144. /// value:
  12145. /// Except for type 3 it is interpreted as seconds for displaying as DD:HH:MM:SS, HH:MM:SS, MM:SS or SS (leftmost '00' is not displayed).
  12146. void clif_showdigit(struct map_session_data* sd, unsigned char type, int value)
  12147. {
  12148. WFIFOHEAD(sd->fd, packet_len(0x1b1));
  12149. WFIFOW(sd->fd,0) = 0x1b1;
  12150. WFIFOB(sd->fd,0) = type;
  12151. WFIFOL(sd->fd,0) = value;
  12152. WFIFOSET(sd->fd, packet_len(0x1b1));
  12153. }
  12154. /*==========================================
  12155. * パケットデバッグ
  12156. *------------------------------------------*/
  12157. void clif_parse_debug(int fd,struct map_session_data *sd)
  12158. {
  12159. int i, cmd, len;
  12160. cmd = RFIFOW(fd,0);
  12161. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  12162. ShowDebug("packet debug 0x%4X\n",cmd);
  12163. ShowMessage("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  12164. for(i=0;i<len;i++){
  12165. if((i&15)==0)
  12166. ShowMessage("\n%04X ",i);
  12167. ShowMessage("%02X ",RFIFOB(fd,i));
  12168. }
  12169. ShowMessage("\n");
  12170. }
  12171. /*==========================================
  12172. * Main client packet processing function
  12173. *------------------------------------------*/
  12174. int clif_parse(int fd)
  12175. {
  12176. int cmd, packet_ver, packet_len, err;
  12177. TBL_PC* sd;
  12178. int pnum;
  12179. //TODO apply delays or disconnect based on packet throughput [FlavioJS]
  12180. // Note: "click masters" can do 80+ clicks in 10 seconds
  12181. for( pnum = 0; pnum < 3; ++pnum )// Limit max packets per cycle to 3 (delay packet spammers) [FlavioJS] -- This actually aids packet spammers, but stuff like /str+ gets slow without it [Ai4rei]
  12182. { // begin main client packet processing loop
  12183. sd = (TBL_PC *)session[fd]->session_data;
  12184. if (session[fd]->flag.eof) {
  12185. if (sd) {
  12186. if (sd->state.autotrade) {
  12187. //Disassociate character from the socket connection.
  12188. session[fd]->session_data = NULL;
  12189. sd->fd = 0;
  12190. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  12191. } else
  12192. if (sd->state.active) {
  12193. // Player logout display [Valaris]
  12194. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  12195. clif_quitsave(fd, sd);
  12196. } else {
  12197. //Unusual logout (during log on/off/map-changer procedure)
  12198. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  12199. map_quit(sd);
  12200. }
  12201. } else {
  12202. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  12203. }
  12204. do_close(fd);
  12205. return 0;
  12206. }
  12207. if (RFIFOREST(fd) < 2)
  12208. return 0;
  12209. cmd = RFIFOW(fd,0);
  12210. // identify client's packet version
  12211. if (sd) {
  12212. packet_ver = sd->packet_ver;
  12213. } else {
  12214. // check authentification packet to know packet version
  12215. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  12216. if( err )
  12217. {// failed to identify packet version
  12218. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  12219. err == 1 ? "" :
  12220. err == 2 ? ", possibly for having an invalid account_id" :
  12221. err == 3 ? ", possibly for having an invalid char_id." :
  12222. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  12223. err == 4 ? ", possibly for having an invalid login_id1." :
  12224. err == 5 ? ", possibly for having an invalid client_tick." :
  12225. */
  12226. err == 6 ? ", possibly for having an invalid sex." :
  12227. ". ERROR invalid error code"));
  12228. WFIFOHEAD(fd,packet_len(0x6a));
  12229. WFIFOW(fd,0) = 0x6a;
  12230. WFIFOB(fd,2) = 3; // Rejected from Server
  12231. WFIFOSET(fd,packet_len(0x6a));
  12232. RFIFOSKIP(fd, RFIFOREST(fd));
  12233. set_eof(fd);
  12234. return 0;
  12235. }
  12236. }
  12237. // filter out invalid / unsupported packets
  12238. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  12239. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  12240. set_eof(fd);
  12241. return 0;
  12242. }
  12243. // determine real packet length
  12244. packet_len = packet_db[packet_ver][cmd].len;
  12245. if (packet_len == -1) { // variable-length packet
  12246. if (RFIFOREST(fd) < 4)
  12247. return 0;
  12248. packet_len = RFIFOW(fd,2);
  12249. if (packet_len < 4 || packet_len > 32768) {
  12250. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  12251. set_eof(fd);
  12252. return 0;
  12253. }
  12254. }
  12255. if ((int)RFIFOREST(fd) < packet_len)
  12256. return 0; // not enough data received to form the packet
  12257. if( packet_db[packet_ver][cmd].func == clif_parse_debug )
  12258. packet_db[packet_ver][cmd].func(fd, sd);
  12259. else
  12260. if( packet_db[packet_ver][cmd].func != NULL )
  12261. {
  12262. if( !sd && packet_db[packet_ver][cmd].func != clif_parse_WantToConnection )
  12263. ; //Only valid packet when there is no session
  12264. else
  12265. if( sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck )
  12266. ; //Only valid packet when player is not on a map
  12267. else
  12268. if( sd && session[sd->fd]->flag.eof )
  12269. ; //No more packets accepted
  12270. else
  12271. packet_db[packet_ver][cmd].func(fd, sd);
  12272. }
  12273. #if DUMP_UNKNOWN_PACKET
  12274. else if (battle_config.error_log)
  12275. {
  12276. int i;
  12277. FILE *fp;
  12278. char packet_txt[256] = "save/packet.txt";
  12279. time_t now;
  12280. dump = 1;
  12281. if ((fp = fopen(packet_txt, "a")) == NULL) {
  12282. ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
  12283. return 1;
  12284. } else {
  12285. time(&now);
  12286. if (sd && sd->state.active) {
  12287. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  12288. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  12289. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  12290. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  12291. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  12292. for(i = 0; i < packet_len; i++) {
  12293. if ((i & 15) == 0)
  12294. fprintf(fp, "\n\t%04X ", i);
  12295. fprintf(fp, "%02X ", RFIFOB(fd,i));
  12296. }
  12297. fprintf(fp, "\n\n");
  12298. fclose(fp);
  12299. }
  12300. }
  12301. #endif
  12302. /* TODO: use utils.c :: dump()
  12303. if (dump) {
  12304. int i;
  12305. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  12306. ShowMessage("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  12307. for(i = 0; i < packet_len; i++) {
  12308. if ((i & 15) == 0)
  12309. ShowMessage("\n%04X ",i);
  12310. ShowMessage("%02X ", RFIFOB(fd,i));
  12311. }
  12312. ShowMessage("\n");
  12313. if (sd && sd->state.active) {
  12314. if (sd->status.name != NULL)
  12315. ShowMessage("\nAccount ID %d, character ID %d, player name %s.\n",
  12316. sd->status.account_id, sd->status.char_id, sd->status.name);
  12317. else
  12318. ShowMessage("\nAccount ID %d.\n", sd->bl.id);
  12319. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  12320. ShowMessage("\nAccount ID %d.\n", sd->bl.id);
  12321. }*/
  12322. RFIFOSKIP(fd, packet_len);
  12323. }; // main loop end
  12324. return 0;
  12325. }
  12326. /*==========================================
  12327. * パケットデータベース読み込み
  12328. *------------------------------------------*/
  12329. static int packetdb_readdb(void)
  12330. {
  12331. FILE *fp;
  12332. char line[1024];
  12333. int ln=0;
  12334. int cmd,i,j,packet_ver;
  12335. int max_cmd=-1;
  12336. int skip_ver = 0;
  12337. int warned = 0;
  12338. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  12339. int packet_len_table[MAX_PACKET_DB] = {
  12340. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12344. //#0x0040
  12345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12347. #if PACKETVER <= 20081217
  12348. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,110, 3, 2,
  12349. #else
  12350. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,114, 3, 2,
  12351. #endif
  12352. #if PACKETVER < 2
  12353. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  12354. #elif PACKETVER < 20071106 // 78-7b 亀島以降 lv99エフェクト用
  12355. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  12356. #elif PACKETVER <= 20081217 // change in 0x78 and 0x7c
  12357. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  12358. #else
  12359. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 44, 2, 6, 6,
  12360. #endif
  12361. //#0x0080
  12362. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  12363. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  12364. #if PACKETVER <= 20100622
  12365. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  12366. #else
  12367. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 9, 4, 7, 0, -1, 6, // 0xaa changed to 9 (was 7)
  12368. #endif
  12369. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  12370. //#0x00C0
  12371. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  12372. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  12373. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  12374. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  12375. //#0x0100
  12376. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  12377. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  12378. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  12379. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  12380. //#0x0140
  12381. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  12382. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  12383. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  12384. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  12385. //#0x0180
  12386. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  12387. #if PACKETVER < 1
  12388. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  12389. #else // 196 comodo以降 状態表示アイコン用
  12390. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  12391. #endif
  12392. #if PACKETVER < 20081126
  12393. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  12394. #else // 0x1a2 changed (35->37)
  12395. 3, 3, 37, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  12396. #endif
  12397. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  12398. //#0x01C0, Set 0x1d5=-1
  12399. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  12400. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  12401. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  12402. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  12403. //#0x0200
  12404. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  12405. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  12406. #if PACKETVER < 20071106
  12407. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  12408. #else // 0x22c changed
  12409. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  12410. #endif
  12411. 12, 26, 9, 11, -1, -1, 10, 2,282, 11, 4, 36, -1, -1, 4, 2,
  12412. //#0x0240
  12413. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  12414. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, 6, 4, -1, 4, 0,
  12415. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12416. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12417. //#0x0280
  12418. 0, 0, 0, 6, 0, 0, 0, 0, 0, 8, 18, 0, 0, 0, 0, 0,
  12419. 0, 4, 0, 70, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12421. 85, -1, -1,107, 6, -1, 7, 7, 22,191, 0, 0, 0, 0, 0, 0,
  12422. //#0x02C0
  12423. 0, 0, 0, 0, 0, 30, 0, 0, 0, 3, 0, 65, 4, 71, 10, 0,
  12424. 0, 0, 0, 0, 29, 0, 6, -1, 10, 10, 3, 0, -1, 32, 6, 0,
  12425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 67, 59, 60, 8,
  12426. 10, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12427. //#0x0300
  12428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12432. //#0x0340
  12433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12437. //#0x0380
  12438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12442. //#0x03C0
  12443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12447. //#0x0400
  12448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 25,
  12452. //#0x0440
  12453. 0, 4, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12457. //#0x0480
  12458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12462. //#0x04C0
  12463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12467. //#0x0500
  12468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  12472. //#0x0540
  12473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12477. //#0x0580
  12478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12482. //#0x05C0
  12483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12487. //#0x0600
  12488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  12492. //#0x0640
  12493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12497. //#0x0680
  12498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12502. //#0x06C0
  12503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12507. //#0x0700
  12508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25,
  12512. //#0x0740
  12513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12517. //#0x0780
  12518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12522. //#0x07C0
  12523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12524. #if PACKETVER < 20090617
  12525. 6, 2, -1, 4, 4, 4, 4, 8, 8,254, 6, 8, 6, 54, 30, 54,
  12526. #else // 0x7d9 changed
  12527. 6, 2, -1, 4, 4, 4, 4, 8, 8,268, 6, 8, 6, 54, 30, 54,
  12528. #endif
  12529. 0, 0, 0, 0, 0, 8, 8, 32, -1, 5, 0, 0, 0, 0, 0, 0,
  12530. 0, 0, 0, 0, 0, 0, 14, -1, -1, -1, 8, 0, 0, 0, 26, 0,
  12531. //#0x0800
  12532. #if PACKETVER < 20091229
  12533. -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 20,
  12534. #else // for Party booking ( PACKETVER >= 20091229 )
  12535. -1, -1, 18, 4, 8, 6, 2, 4, 14, 50, 18, 6, 2, 3, 14, 20,
  12536. #endif
  12537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  12540. };
  12541. struct {
  12542. void (*func)(int, struct map_session_data *);
  12543. char *name;
  12544. } clif_parse_func[]={
  12545. {clif_parse_WantToConnection,"wanttoconnection"},
  12546. {clif_parse_LoadEndAck,"loadendack"},
  12547. {clif_parse_TickSend,"ticksend"},
  12548. {clif_parse_WalkToXY,"walktoxy"},
  12549. {clif_parse_QuitGame,"quitgame"},
  12550. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  12551. {clif_parse_GlobalMessage,"globalmessage"},
  12552. {clif_parse_MapMove,"mapmove"},
  12553. {clif_parse_ChangeDir,"changedir"},
  12554. {clif_parse_Emotion,"emotion"},
  12555. {clif_parse_HowManyConnections,"howmanyconnections"},
  12556. {clif_parse_ActionRequest,"actionrequest"},
  12557. {clif_parse_Restart,"restart"},
  12558. {clif_parse_WisMessage,"wis"},
  12559. {clif_parse_Broadcast,"broadcast"},
  12560. {clif_parse_TakeItem,"takeitem"},
  12561. {clif_parse_DropItem,"dropitem"},
  12562. {clif_parse_UseItem,"useitem"},
  12563. {clif_parse_EquipItem,"equipitem"},
  12564. {clif_parse_UnequipItem,"unequipitem"},
  12565. {clif_parse_NpcClicked,"npcclicked"},
  12566. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  12567. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  12568. {clif_parse_NpcSellListSend,"npcselllistsend"},
  12569. {clif_parse_CreateChatRoom,"createchatroom"},
  12570. {clif_parse_ChatAddMember,"chataddmember"},
  12571. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  12572. {clif_parse_ChangeChatOwner,"changechatowner"},
  12573. {clif_parse_KickFromChat,"kickfromchat"},
  12574. {clif_parse_ChatLeave,"chatleave"},
  12575. {clif_parse_TradeRequest,"traderequest"},
  12576. {clif_parse_TradeAck,"tradeack"},
  12577. {clif_parse_TradeAddItem,"tradeadditem"},
  12578. {clif_parse_TradeOk,"tradeok"},
  12579. {clif_parse_TradeCancel,"tradecancel"},
  12580. {clif_parse_TradeCommit,"tradecommit"},
  12581. {clif_parse_StopAttack,"stopattack"},
  12582. {clif_parse_PutItemToCart,"putitemtocart"},
  12583. {clif_parse_GetItemFromCart,"getitemfromcart"},
  12584. {clif_parse_RemoveOption,"removeoption"},
  12585. {clif_parse_ChangeCart,"changecart"},
  12586. {clif_parse_StatusUp,"statusup"},
  12587. {clif_parse_SkillUp,"skillup"},
  12588. {clif_parse_UseSkillToId,"useskilltoid"},
  12589. {clif_parse_UseSkillToPos,"useskilltopos"},
  12590. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  12591. {clif_parse_UseSkillMap,"useskillmap"},
  12592. {clif_parse_RequestMemo,"requestmemo"},
  12593. {clif_parse_ProduceMix,"producemix"},
  12594. {clif_parse_Cooking,"cooking"},
  12595. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  12596. {clif_parse_NpcNextClicked,"npcnextclicked"},
  12597. {clif_parse_NpcAmountInput,"npcamountinput"},
  12598. {clif_parse_NpcStringInput,"npcstringinput"},
  12599. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  12600. {clif_parse_ItemIdentify,"itemidentify"},
  12601. {clif_parse_SelectArrow,"selectarrow"},
  12602. {clif_parse_AutoSpell,"autospell"},
  12603. {clif_parse_UseCard,"usecard"},
  12604. {clif_parse_InsertCard,"insertcard"},
  12605. {clif_parse_RepairItem,"repairitem"},
  12606. {clif_parse_WeaponRefine,"weaponrefine"},
  12607. {clif_parse_SolveCharName,"solvecharname"},
  12608. {clif_parse_ResetChar,"resetchar"},
  12609. {clif_parse_LocalBroadcast,"localbroadcast"},
  12610. {clif_parse_MoveToKafra,"movetokafra"},
  12611. {clif_parse_MoveFromKafra,"movefromkafra"},
  12612. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  12613. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  12614. {clif_parse_CloseKafra,"closekafra"},
  12615. {clif_parse_CreateParty,"createparty"},
  12616. {clif_parse_CreateParty2,"createparty2"},
  12617. {clif_parse_PartyInvite,"partyinvite"},
  12618. {clif_parse_PartyInvite2,"partyinvite2"},
  12619. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  12620. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  12621. {clif_parse_LeaveParty,"leaveparty"},
  12622. {clif_parse_RemovePartyMember,"removepartymember"},
  12623. {clif_parse_PartyChangeOption,"partychangeoption"},
  12624. {clif_parse_PartyMessage,"partymessage"},
  12625. {clif_parse_PartyChangeLeader,"partychangeleader"},
  12626. {clif_parse_CloseVending,"closevending"},
  12627. {clif_parse_VendingListReq,"vendinglistreq"},
  12628. {clif_parse_PurchaseReq,"purchasereq"},
  12629. {clif_parse_PurchaseReq2,"purchasereq2"},
  12630. {clif_parse_OpenVending,"openvending"},
  12631. {clif_parse_CreateGuild,"createguild"},
  12632. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  12633. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  12634. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  12635. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  12636. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  12637. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  12638. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  12639. {clif_parse_GuildInvite,"guildinvite"},
  12640. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  12641. {clif_parse_GuildLeave,"guildleave"},
  12642. {clif_parse_GuildExpulsion,"guildexpulsion"},
  12643. {clif_parse_GuildMessage,"guildmessage"},
  12644. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  12645. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  12646. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  12647. {clif_parse_GuildOpposition,"guildopposition"},
  12648. {clif_parse_GuildBreak,"guildbreak"},
  12649. {clif_parse_PetMenu,"petmenu"},
  12650. {clif_parse_CatchPet,"catchpet"},
  12651. {clif_parse_SelectEgg,"selectegg"},
  12652. {clif_parse_SendEmotion,"sendemotion"},
  12653. {clif_parse_ChangePetName,"changepetname"},
  12654. {clif_parse_GMKick,"gmkick"},
  12655. {clif_parse_GMHide,"gmhide"},
  12656. {clif_parse_GMReqNoChat,"gmreqnochat"},
  12657. {clif_parse_GMReqAccountName,"gmreqaccname"},
  12658. {clif_parse_GMKickAll,"killall"},
  12659. {clif_parse_GMRecall,"recall"},
  12660. {clif_parse_GMRecall,"summon"},
  12661. {clif_parse_GM_Monster_Item,"itemmonster"},
  12662. {clif_parse_GMShift,"remove"},
  12663. {clif_parse_GMShift,"shift"},
  12664. {clif_parse_GMChangeMapType,"changemaptype"},
  12665. {clif_parse_GMRc,"rc"},
  12666. {clif_parse_GMRecall2,"recall2"},
  12667. {clif_parse_GMRemove2,"remove2"},
  12668. {clif_parse_NoviceDoriDori,"sndoridori"},
  12669. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  12670. {clif_parse_PMIgnore,"wisexin"},
  12671. {clif_parse_PMIgnoreList,"wisexlist"},
  12672. {clif_parse_PMIgnoreAll,"wisall"},
  12673. {clif_parse_FriendsListAdd,"friendslistadd"},
  12674. {clif_parse_FriendsListRemove,"friendslistremove"},
  12675. {clif_parse_FriendsListReply,"friendslistreply"},
  12676. {clif_parse_Blacksmith,"blacksmith"},
  12677. {clif_parse_Alchemist,"alchemist"},
  12678. {clif_parse_Taekwon,"taekwon"},
  12679. {clif_parse_RankingPk,"rankingpk"},
  12680. {clif_parse_FeelSaveOk,"feelsaveok"},
  12681. {clif_parse_debug,"debug"},
  12682. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  12683. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  12684. {clif_parse_HomMoveTo,"hommoveto"},
  12685. {clif_parse_HomAttack,"homattack"},
  12686. {clif_parse_HomMenu,"hommenu"},
  12687. {clif_parse_StoragePassword,"storagepassword"},
  12688. {clif_parse_Hotkey,"hotkey"},
  12689. {clif_parse_AutoRevive,"autorevive"},
  12690. {clif_parse_Check,"check"},
  12691. {clif_parse_Adopt_request,"adoptrequest"},
  12692. {clif_parse_Adopt_reply,"adoptreply"},
  12693. #ifndef TXT_ONLY
  12694. // MAIL SYSTEM
  12695. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  12696. {clif_parse_Mail_read,"mailread"},
  12697. {clif_parse_Mail_getattach,"mailgetattach"},
  12698. {clif_parse_Mail_delete,"maildelete"},
  12699. {clif_parse_Mail_return,"mailreturn"},
  12700. {clif_parse_Mail_setattach,"mailsetattach"},
  12701. {clif_parse_Mail_winopen,"mailwinopen"},
  12702. {clif_parse_Mail_send,"mailsend"},
  12703. // AUCTION SYSTEM
  12704. {clif_parse_Auction_search,"auctionsearch"},
  12705. {clif_parse_Auction_buysell,"auctionbuysell"},
  12706. {clif_parse_Auction_setitem,"auctionsetitem"},
  12707. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  12708. {clif_parse_Auction_register,"auctionregister"},
  12709. {clif_parse_Auction_cancel,"auctioncancel"},
  12710. {clif_parse_Auction_close,"auctionclose"},
  12711. {clif_parse_Auction_bid,"auctionbid"},
  12712. // Quest Log System
  12713. {clif_parse_questStateAck,"queststate"},
  12714. #endif
  12715. {clif_parse_cashshop_buy,"cashshopbuy"},
  12716. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  12717. {clif_parse_EquipTick,"equiptickbox"},
  12718. {clif_parse_BattleChat,"battlechat"},
  12719. {clif_parse_mercenary_action,"mermenu"},
  12720. {clif_parse_progressbar,"progressbar"},
  12721. #if PACKETVER >= 20091229
  12722. {clif_parse_PartyBookingRegisterReq,"bookingregreq"},
  12723. {clif_parse_PartyBookingSearchReq,"bookingsearchreq"},
  12724. {clif_parse_PartyBookingUpdateReq,"bookingupdatereq"},
  12725. {clif_parse_PartyBookingDeleteReq,"bookingdelreq"},
  12726. #endif
  12727. {NULL,NULL}
  12728. };
  12729. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  12730. memset(packet_db,0,sizeof(packet_db));
  12731. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  12732. packet_len(i) = packet_len_table[i];
  12733. sprintf(line, "%s/packet_db.txt", db_path);
  12734. if( (fp=fopen(line,"r"))==NULL ){
  12735. ShowFatalError("can't read %s\n", line);
  12736. exit(EXIT_FAILURE);
  12737. }
  12738. clif_config.packet_db_ver = MAX_PACKET_VER;
  12739. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  12740. while( fgets(line, sizeof(line), fp) )
  12741. {
  12742. ln++;
  12743. if(line[0]=='/' && line[1]=='/')
  12744. continue;
  12745. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  12746. {
  12747. if(strcmpi(w1,"packet_ver")==0) {
  12748. int prev_ver = packet_ver;
  12749. skip_ver = 0;
  12750. packet_ver = atoi(w2);
  12751. if ( packet_ver > MAX_PACKET_VER )
  12752. { //Check to avoid overflowing. [Skotlex]
  12753. if( (warned&1) == 0 )
  12754. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  12755. warned &= 1;
  12756. skip_ver = 1;
  12757. }
  12758. else if( packet_ver < 0 )
  12759. {
  12760. if( (warned&2) == 0 )
  12761. ShowWarning("Negative packet versions are not supported.\n");
  12762. warned &= 2;
  12763. skip_ver = 1;
  12764. }
  12765. else if( packet_ver == SERVER )
  12766. {
  12767. if( (warned&4) == 0 )
  12768. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  12769. warned &= 4;
  12770. skip_ver = 1;
  12771. }
  12772. if( skip_ver )
  12773. {
  12774. ShowWarning("Skipping packet version %d.\n", packet_ver);
  12775. packet_ver = prev_ver;
  12776. continue;
  12777. }
  12778. // copy from previous version into new version and continue
  12779. // - indicating all following packets should be read into the newer version
  12780. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  12781. continue;
  12782. } else if(strcmpi(w1,"packet_db_ver")==0) {
  12783. if(strcmpi(w2,"default")==0) //This is the preferred version.
  12784. clif_config.packet_db_ver = MAX_PACKET_VER;
  12785. else // to manually set the packet DB version
  12786. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  12787. continue;
  12788. }
  12789. }
  12790. if( skip_ver != 0 )
  12791. continue; // Skipping current packet version
  12792. memset(str,0,sizeof(str));
  12793. for(j=0,p=line;j<4 && p; ++j)
  12794. {
  12795. str[j]=p;
  12796. p=strchr(p,',');
  12797. if(p) *p++=0;
  12798. }
  12799. if(str[0]==NULL)
  12800. continue;
  12801. cmd=strtol(str[0],(char **)NULL,0);
  12802. if(max_cmd < cmd)
  12803. max_cmd = cmd;
  12804. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  12805. continue;
  12806. if(str[1]==NULL){
  12807. ShowError("packet_db: packet len error\n");
  12808. continue;
  12809. }
  12810. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  12811. if(str[2]==NULL){
  12812. packet_db[packet_ver][cmd].func = NULL;
  12813. ln++;
  12814. continue;
  12815. }
  12816. // look up processing function by name
  12817. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  12818. if( j < ARRAYLENGTH(clif_parse_func) )
  12819. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  12820. // set the identifying cmd for the packet_db version
  12821. if (strcmp(str[2],"wanttoconnection")==0)
  12822. clif_config.connect_cmd[packet_ver] = cmd;
  12823. if(str[3]==NULL){
  12824. ShowError("packet_db: packet error\n");
  12825. exit(EXIT_FAILURE);
  12826. }
  12827. for(j=0,p2=str[3];p2;j++){
  12828. short k;
  12829. str2[j]=p2;
  12830. p2=strchr(p2,':');
  12831. if(p2) *p2++=0;
  12832. k = atoi(str2[j]);
  12833. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  12834. packet_db[packet_ver][cmd].pos[j] = k;
  12835. }
  12836. }
  12837. fclose(fp);
  12838. if(max_cmd > MAX_PACKET_DB)
  12839. {
  12840. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  12841. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  12842. }
  12843. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  12844. { //Locate the nearest version that we still support. [Skotlex]
  12845. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  12846. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  12847. }
  12848. 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);
  12849. return 0;
  12850. }
  12851. /*==========================================
  12852. *
  12853. *------------------------------------------*/
  12854. int do_init_clif(void)
  12855. {
  12856. clif_config.packet_db_ver = -1; // the main packet version of the DB
  12857. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  12858. memset(packet_db,0,sizeof(packet_db));
  12859. //Using the packet_db file is the only way to set up packets now [Skotlex]
  12860. packetdb_readdb();
  12861. set_defaultparse(clif_parse);
  12862. if( make_listen_bind(bind_ip,map_port) == -1 )
  12863. {
  12864. ShowFatalError("can't bind game port\n");
  12865. exit(EXIT_FAILURE);
  12866. }
  12867. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  12868. add_timer_func_list(clif_delayquit, "clif_delayquit");
  12869. return 0;
  12870. }