clif.c 338 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712
  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 "charcommand.h"
  25. #include "intif.h"
  26. #include "battle.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 "mercenary.h" //[orn]
  34. #include "log.h"
  35. #include "irc.h"
  36. #include "clif.h"
  37. #include "mail.h"
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include <stdarg.h>
  42. #include <time.h>
  43. #define DUMP_UNKNOWN_PACKET 0
  44. struct Clif_Config {
  45. int packet_db_ver; //Preferred packet version.
  46. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  47. } clif_config;
  48. struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
  49. //Converts item type in case of pet eggs.
  50. #define itemtype(a) (a == IT_PETEGG)?IT_WEAPON:a
  51. #define WBUFPOS(p,pos,x,y,dir) \
  52. do { \
  53. uint8 *__p = (p); \
  54. __p+=(pos); \
  55. __p[0] = (uint8)((x)>>2); \
  56. __p[1] = (uint8)(((x)<<6) | (((y)>>4)&0x3f)); \
  57. __p[2] = (uint8)(((y)<<4) | ((dir)&0xf)); \
  58. } while(0)
  59. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  60. #define WBUFPOS2(p,pos,x0,y0,x1,y1,sx0,sy0) \
  61. do { \
  62. uint8 *__p = (p); \
  63. __p+=(pos); \
  64. __p[0]=(uint8)((x0)>>2); \
  65. __p[1]=(uint8)(((x0)<<6) | (((y0)>>4)&0x3f)); \
  66. __p[2]=(uint8)(((y0)<<4) | (((x1)>>6)&0x0f)); \
  67. __p[3]=(uint8)(((x1)<<2) | (((y1)>>8)&0x03)); \
  68. __p[4]=(uint8)(y1); \
  69. __p[5]=(uint8)(((sx0)<<4) | ((sy0)&0x0f)); \
  70. } while(0)
  71. #define WFIFOPOS(fd,pos,x,y,dir) WBUFPOS(WFIFOP(fd,pos),0,x,y,dir)
  72. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1,sx0,sy0) WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1,sx0,sy0)
  73. //To idenfity disguised characters.
  74. #define disguised(bl) ((bl)->type==BL_PC && ((TBL_PC*)bl)->disguise)
  75. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex\]
  76. #define mes_len_check(mes, len, max) if (len > max) { mes[max-1] = '\0'; len = max; } else mes[len-1] = '\0';
  77. static char map_ip_str[128];
  78. static uint32 map_ip;
  79. static uint32 bind_ip = INADDR_ANY;
  80. static uint16 map_port = 5121;
  81. int map_fd;
  82. //These two will be used to verify the incoming player's validity.
  83. //It helps identify their client packet version correctly. [Skotlex]
  84. static int max_account_id = DEFAULT_MAX_ACCOUNT_ID;
  85. static int max_char_id = DEFAULT_MAX_CHAR_ID;
  86. int clif_parse (int fd);
  87. /*==========================================
  88. * map鯖のip設定
  89. *------------------------------------------*/
  90. int clif_setip(const char* ip)
  91. {
  92. char ip_str[16];
  93. map_ip = host2ip(ip);
  94. if (!map_ip) {
  95. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  96. return 0;
  97. }
  98. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  99. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  100. return 1;
  101. }
  102. void clif_setbindip(const char* ip)
  103. {
  104. char ip_str[16];
  105. bind_ip = host2ip(ip);
  106. if (bind_ip) {
  107. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  108. } else {
  109. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  110. }
  111. }
  112. /*==========================================
  113. * map鯖のport設定
  114. *------------------------------------------*/
  115. void clif_setport(uint16 port)
  116. {
  117. map_port = port;
  118. }
  119. /*==========================================
  120. * map鯖のip読み出し
  121. *------------------------------------------*/
  122. uint32 clif_getip(void)
  123. {
  124. return map_ip;
  125. }
  126. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  127. uint32 clif_refresh_ip(void)
  128. {
  129. uint32 new_ip;
  130. new_ip = host2ip(map_ip_str);
  131. if (new_ip && new_ip != map_ip) {
  132. map_ip = new_ip;
  133. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  134. return map_ip;
  135. }
  136. return 0;
  137. }
  138. /*==========================================
  139. * map鯖のport読み出し
  140. *------------------------------------------*/
  141. uint16 clif_getport(void)
  142. {
  143. return map_port;
  144. }
  145. /*==========================================
  146. * 全てのclientに対してfunc()実行
  147. *------------------------------------------*/
  148. int clif_foreachclient(int (*func)(struct map_session_data*, va_list),...) //recoded by sasuke, bug when player count gets higher [Kevin]
  149. {
  150. int i;
  151. va_list ap;
  152. struct map_session_data *sd;
  153. va_start(ap,func);
  154. for(i = 0; i < fd_max; i++) {
  155. if ( session[i] && session[i]->func_parse == clif_parse) {
  156. sd = (struct map_session_data*)session[i]->session_data;
  157. if ( sd && sd->state.active )
  158. func(sd, ap);
  159. }
  160. }
  161. va_end(ap);
  162. return 0;
  163. }
  164. /*==========================================
  165. * clif_sendでAREA*指定時用
  166. *------------------------------------------*/
  167. int clif_send_sub(struct block_list *bl, va_list ap)
  168. {
  169. struct block_list *src_bl;
  170. struct map_session_data *sd;
  171. unsigned char *buf;
  172. int len, type, fd;
  173. nullpo_retr(0, bl);
  174. nullpo_retr(0, ap);
  175. nullpo_retr(0, sd = (struct map_session_data *)bl);
  176. fd = sd->fd;
  177. if (!fd) //Don't send to disconnected clients.
  178. return 0;
  179. buf = va_arg(ap,unsigned char*);
  180. len = va_arg(ap,int);
  181. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  182. type = va_arg(ap,int);
  183. switch(type)
  184. {
  185. case AREA_WOS:
  186. if (bl == src_bl)
  187. return 0;
  188. break;
  189. case AREA_WOC:
  190. if (sd->chatID || bl == src_bl)
  191. return 0;
  192. break;
  193. case AREA_WOSC:
  194. {
  195. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  196. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  197. return 0;
  198. }
  199. break;
  200. }
  201. if (session[fd] == NULL)
  202. return 0;
  203. WFIFOHEAD(fd, len);
  204. if (WFIFOP(fd,0) == buf) {
  205. ShowError("WARNING: Invalid use of clif_send function\n");
  206. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  207. ShowError(" Please correct your code.\n");
  208. // don't send to not move the pointer of the packet for next sessions in the loop
  209. //WFIFOSET(fd,0);//## TODO is this ok?
  210. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  211. return 0;
  212. }
  213. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  214. memcpy(WFIFOP(fd,0), buf, len);
  215. WFIFOSET(fd,len);
  216. }
  217. return 0;
  218. }
  219. /*==========================================
  220. *
  221. *------------------------------------------*/
  222. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  223. {
  224. int i;
  225. struct map_session_data *sd;
  226. struct party_data *p = NULL;
  227. struct guild *g = NULL;
  228. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  229. if( type != ALL_CLIENT && type != CHAT_MAINCHAT )
  230. nullpo_retr(0, bl);
  231. sd = BL_CAST(BL_PC, bl);
  232. switch(type) {
  233. case ALL_CLIENT: //All player clients.
  234. for (i = 0; i < fd_max; i++) {
  235. if (session[i] && session[i]->func_parse == clif_parse &&
  236. (sd = (struct map_session_data *)session[i]->session_data) != NULL &&
  237. sd->state.active &&
  238. packet_db[sd->packet_ver][RBUFW(buf,0)].len)
  239. { // packet must exist for the client version
  240. WFIFOHEAD(i, len);
  241. memcpy(WFIFOP(i,0), buf, len);
  242. WFIFOSET(i,len);
  243. }
  244. }
  245. break;
  246. case ALL_SAMEMAP: //All players on the same map
  247. for(i = 0; i < fd_max; i++) {
  248. if (session[i] && session[i]->func_parse == clif_parse &&
  249. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  250. sd->state.active && sd->bl.m == bl->m &&
  251. packet_db[sd->packet_ver][RBUFW(buf,0)].len)
  252. { // packet must exist for the client version
  253. WFIFOHEAD(i,len);
  254. memcpy(WFIFOP(i,0), buf, len);
  255. WFIFOSET(i,len);
  256. }
  257. }
  258. break;
  259. case AREA:
  260. case AREA_WOSC:
  261. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  262. clif_send (buf, len, bl, SELF);
  263. case AREA_WOC:
  264. case AREA_WOS:
  265. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  266. BL_PC, buf, len, bl, type);
  267. break;
  268. case AREA_CHAT_WOC:
  269. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  270. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  271. break;
  272. case CHAT:
  273. case CHAT_WOS:
  274. {
  275. struct chat_data *cd;
  276. if (sd) {
  277. cd = (struct chat_data*)map_id2bl(sd->chatID);
  278. } else if (bl->type == BL_CHAT) {
  279. cd = (struct chat_data*)bl;
  280. } else break;
  281. if (cd == NULL)
  282. break;
  283. for(i = 0; i < cd->users; i++) {
  284. if (type == CHAT_WOS && cd->usersd[i] == sd)
  285. continue;
  286. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  287. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  288. {
  289. WFIFOHEAD(fd,len);
  290. memcpy(WFIFOP(fd,0), buf, len);
  291. WFIFOSET(fd,len);
  292. }
  293. }
  294. }
  295. }
  296. break;
  297. case CHAT_MAINCHAT: //[LuzZza]
  298. for(i=1; i<fd_max; i++) {
  299. if (session[i] && session[i]->func_parse == clif_parse &&
  300. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  301. sd->state.active && sd->state.mainchat && !sd->chatID)
  302. {
  303. WFIFOHEAD(i,len);
  304. memcpy(WFIFOP(i,0), buf, len);
  305. WFIFOSET(i, len);
  306. }
  307. }
  308. break;
  309. case PARTY_AREA:
  310. case PARTY_AREA_WOS:
  311. x0 = bl->x - AREA_SIZE;
  312. y0 = bl->y - AREA_SIZE;
  313. x1 = bl->x + AREA_SIZE;
  314. y1 = bl->y + AREA_SIZE;
  315. case PARTY:
  316. case PARTY_WOS:
  317. case PARTY_SAMEMAP:
  318. case PARTY_SAMEMAP_WOS:
  319. if (sd && sd->status.party_id)
  320. p = party_search(sd->status.party_id);
  321. if (p) {
  322. for(i=0;i<MAX_PARTY;i++){
  323. if( (sd = p->data[i].sd) == NULL )
  324. continue;
  325. if( !(fd=sd->fd) )
  326. continue;
  327. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  328. continue;
  329. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  330. continue;
  331. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  332. continue;
  333. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  334. { // packet must exist for the client version
  335. WFIFOHEAD(fd,len);
  336. memcpy(WFIFOP(fd,0), buf, len);
  337. WFIFOSET(fd,len);
  338. }
  339. }
  340. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  341. break;
  342. for (i = 1; i < fd_max; i++){ // partyspy [Syrus22]
  343. if (session[i] && session[i]->func_parse == clif_parse &&
  344. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  345. sd->state.active && sd->partyspy == p->party.party_id &&
  346. packet_db[sd->packet_ver][RBUFW(buf,0)].len)
  347. { // packet must exist for the client version
  348. WFIFOHEAD(i,len);
  349. memcpy(WFIFOP(i,0), buf, len);
  350. WFIFOSET(i,len);
  351. }
  352. }
  353. }
  354. break;
  355. case DUEL:
  356. case DUEL_WOS:
  357. if (!sd || !sd->duel_group) break; //Invalid usage.
  358. x0 = sd->duel_group; //Here we use x0 to store the duel group. [Skotlex]
  359. for (i = 0; i < fd_max; i++) {
  360. if (session[i] && session[i]->func_parse == clif_parse &&
  361. (sd = (struct map_session_data *)session[i]->session_data) != NULL &&
  362. sd->state.active && sd->duel_group == x0) {
  363. if (type == DUEL_WOS && bl->id == sd->bl.id)
  364. continue;
  365. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) {
  366. WFIFOHEAD(i, len);
  367. memcpy(WFIFOP(i,0), buf, len);
  368. WFIFOSET(i,len);
  369. }
  370. }
  371. }
  372. break;
  373. case SELF:
  374. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  375. WFIFOHEAD(fd,len);
  376. memcpy(WFIFOP(fd,0), buf, len);
  377. WFIFOSET(fd,len);
  378. }
  379. break;
  380. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  381. case GUILD_AREA:
  382. case GUILD_AREA_WOS:
  383. x0 = bl->x - AREA_SIZE;
  384. y0 = bl->y - AREA_SIZE;
  385. x1 = bl->x + AREA_SIZE;
  386. y1 = bl->y + AREA_SIZE;
  387. case GUILD_SAMEMAP:
  388. case GUILD_SAMEMAP_WOS:
  389. case GUILD:
  390. case GUILD_WOS:
  391. if (sd && sd->status.guild_id)
  392. g = guild_search(sd->status.guild_id);
  393. if (g) {
  394. for(i = 0; i < g->max_member; i++) {
  395. if( (sd = g->member[i].sd) != NULL )
  396. {
  397. if( !(fd=sd->fd) )
  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_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. for (i = 1; i < fd_max; i++){ // guildspy [Syrus22]
  416. if (session[i] && session[i]->func_parse == clif_parse &&
  417. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  418. sd->state.active && sd->guildspy == g->guild_id &&
  419. packet_db[sd->packet_ver][RBUFW(buf,0)].len)
  420. { // packet must exist for the client version
  421. WFIFOHEAD(i,len);
  422. memcpy(WFIFOP(i,0), buf, len);
  423. WFIFOSET(i,len);
  424. }
  425. }
  426. }
  427. break;
  428. default:
  429. ShowError("clif_send: Unrecognized type %d\n",type);
  430. return -1;
  431. }
  432. return 0;
  433. }
  434. //
  435. // パケット作って送信
  436. //
  437. /*==========================================
  438. *
  439. *------------------------------------------*/
  440. int clif_authok(struct map_session_data *sd)
  441. {
  442. int fd;
  443. if (!sd->fd)
  444. return 0;
  445. fd = sd->fd;
  446. WFIFOHEAD(fd, packet_len(0x73));
  447. WFIFOW(fd, 0) = 0x73;
  448. WFIFOL(fd, 2) = gettick();
  449. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  450. WFIFOB(fd, 9) = 5; // ignored
  451. WFIFOB(fd,10) = 5; // ignored
  452. WFIFOSET(fd,packet_len(0x73));
  453. return 0;
  454. }
  455. /*==========================================
  456. * Authentication failed/disconnect client.
  457. *------------------------------------------
  458. * The client closes it's socket and displays a message according to type:
  459. * 1 - server closed -> MsgStringTable[4]
  460. * 2 - ID already logged in -> MsgStringTable[5]
  461. * 3 - timeout/too much lag -> MsgStringTable[241]
  462. * 4 - server full -> MsgStringTable[264]
  463. * 5 - underaged -> MsgStringTable[305]
  464. * 8 - Server sill recognizes last connection -> MsgStringTable[441]
  465. * 9 - too many connections from this ip -> MsgStringTable[529]
  466. * 10 - out of available time paid for -> MsgStringTable[530]
  467. * 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  468. * other - disconnected -> MsgStringTable[3]
  469. */
  470. int clif_authfail_fd(int fd, int type)
  471. {
  472. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  473. return 0;
  474. WFIFOHEAD(fd, packet_len(0x81));
  475. WFIFOW(fd,0) = 0x81;
  476. WFIFOB(fd,2) = type;
  477. WFIFOSET(fd,packet_len(0x81));
  478. clif_setwaitclose(fd);
  479. return 0;
  480. }
  481. /*==========================================
  482. * Used to know which is the max valid account/char id [Skotlex]
  483. *------------------------------------------*/
  484. void clif_updatemaxid(int account_id, int char_id)
  485. {
  486. max_account_id = account_id;
  487. max_char_id = char_id;
  488. }
  489. /*==========================================
  490. *
  491. *------------------------------------------*/
  492. int clif_charselectok(int id)
  493. {
  494. struct map_session_data* sd;
  495. int fd;
  496. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  497. return 1;
  498. fd = sd->fd;
  499. WFIFOHEAD(fd,packet_len(0xb3));
  500. WFIFOW(fd,0) = 0xb3;
  501. WFIFOB(fd,2) = 1;
  502. WFIFOSET(fd,packet_len(0xb3));
  503. return 0;
  504. }
  505. /*==========================================
  506. * Makes an item appear on the ground
  507. * 009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  508. *------------------------------------------*/
  509. int clif_dropflooritem(struct flooritem_data* fitem)
  510. {
  511. uint8 buf[17];
  512. int view;
  513. nullpo_retr(0, fitem);
  514. if (fitem->item_data.nameid <= 0)
  515. return 0;
  516. WBUFW(buf, 0) = 0x9e;
  517. WBUFL(buf, 2) = fitem->bl.id;
  518. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  519. WBUFB(buf, 8) = fitem->item_data.identify;
  520. WBUFW(buf, 9) = fitem->bl.x;
  521. WBUFW(buf,11) = fitem->bl.y;
  522. WBUFB(buf,13) = fitem->subx;
  523. WBUFB(buf,14) = fitem->suby;
  524. WBUFW(buf,15) = fitem->item_data.amount;
  525. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  526. return 0;
  527. }
  528. /*==========================================
  529. *
  530. *------------------------------------------*/
  531. int clif_clearflooritem(struct flooritem_data *fitem, int fd)
  532. {
  533. unsigned char buf[16];
  534. nullpo_retr(0, fitem);
  535. WBUFW(buf,0) = 0xa1;
  536. WBUFL(buf,2) = fitem->bl.id;
  537. if (fd == 0) {
  538. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  539. } else {
  540. WFIFOHEAD(fd,packet_len(0xa1));
  541. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  542. WFIFOSET(fd,packet_len(0xa1));
  543. }
  544. return 0;
  545. }
  546. /*==========================================
  547. * make a unit (char, npc, mob, homun) disappear to one client
  548. * id : the id of the unit
  549. * type: 0 - moved out of sight
  550. * 1 - died
  551. * 2 - respawned
  552. * 3 - teleported / logged out
  553. * fd : the target client
  554. *------------------------------------------*/
  555. int clif_clearunit_single(int id, uint8 type, int fd)
  556. {
  557. WFIFOHEAD(fd, packet_len(0x80));
  558. WFIFOW(fd,0) = 0x80;
  559. WFIFOL(fd,2) = id;
  560. WFIFOB(fd,6) = type;
  561. WFIFOSET(fd, packet_len(0x80));
  562. return 0;
  563. }
  564. /*==========================================
  565. * make a unit (char, npc, mob, homun) disappear to all clients in area
  566. * type: 0 - moved out of sight
  567. * 1 - died
  568. * 2 - respawned
  569. * 3 - teleported / logged out
  570. *------------------------------------------*/
  571. int clif_clearunit_area(struct block_list* bl, uint8 type)
  572. {
  573. unsigned char buf[16];
  574. nullpo_retr(0, bl);
  575. WBUFW(buf,0) = 0x80;
  576. WBUFL(buf,2) = bl->id;
  577. WBUFB(buf,6) = type;
  578. clif_send(buf, packet_len(0x80), bl, type == 1 ? AREA : AREA_WOS);
  579. if(disguised(bl)) {
  580. WBUFL(buf,2) = -bl->id;
  581. clif_send(buf, packet_len(0x80), bl, SELF);
  582. }
  583. return 0;
  584. }
  585. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, int data)
  586. {
  587. struct block_list *bl = (struct block_list *)id;
  588. clif_clearunit_area(bl, 0);
  589. aFree(bl);
  590. return 0;
  591. }
  592. int clif_clearunit_delayed(struct block_list* bl, unsigned int tick)
  593. {
  594. struct block_list *tbl;
  595. tbl = aMalloc(sizeof (struct block_list));
  596. memcpy (tbl, bl, sizeof (struct block_list));
  597. add_timer(tick, clif_clearunit_delayed_sub, (int)tbl, 0);
  598. return 0;
  599. }
  600. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  601. {
  602. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  603. {
  604. *rhand = *lhand = 0;
  605. return;
  606. }
  607. #if PACKETVER < 4
  608. *rhand = sd->status.weapon;
  609. *lhand = sd->status.shield;
  610. #else
  611. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  612. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  613. {
  614. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  615. if (id->view_id > 0)
  616. *rhand = id->view_id;
  617. else
  618. *rhand = id->nameid;
  619. } else
  620. *rhand = 0;
  621. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  622. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  623. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  624. {
  625. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  626. if (id->view_id > 0)
  627. *lhand = id->view_id;
  628. else
  629. *lhand = id->nameid;
  630. } else
  631. *lhand = 0;
  632. #endif
  633. }
  634. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  635. static int clif_setlevel(int lv)
  636. {
  637. if( lv < battle_config.max_lv )
  638. return lv;
  639. if( lv < battle_config.aura_lv )
  640. return battle_config.max_lv - 1;
  641. return battle_config.max_lv;
  642. }
  643. /*==========================================
  644. * Prepares 'unit standing/spawning' packet
  645. *------------------------------------------*/
  646. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  647. {
  648. struct map_session_data* sd;
  649. struct status_change* sc = status_get_sc(bl);
  650. struct view_data* vd = status_get_viewdata(bl);
  651. unsigned char *buf = WBUFP(buffer,0);
  652. bool type = !pcdb_checkid(vd->class_);
  653. #if PACKETVER >= 7
  654. unsigned short offset = 0;
  655. #endif
  656. sd = BL_CAST(BL_PC, bl);
  657. if(type)
  658. WBUFW(buf,0) = spawn?0x7c:0x78;
  659. else
  660. #if PACKETVER < 4
  661. WBUFW(buf,0) = spawn?0x79:0x78;
  662. #elif PACKETVER < 7
  663. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  664. #else
  665. WBUFW(buf,0) = spawn?0x22b:0x22a;
  666. #endif
  667. #if PACKETVER >= 9
  668. if (type) {
  669. // shift payload 1 byte to the right for mob packets
  670. WBUFB(buf,2) = 0; // padding?
  671. offset++;
  672. buf = WBUFP(buffer,offset);
  673. }
  674. #endif
  675. WBUFL(buf, 2) = bl->id;
  676. WBUFW(buf, 6) = status_get_speed(bl);
  677. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  678. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  679. if (type&&spawn) { //uses an older and different packet structure
  680. WBUFW(buf,12) = (sc)? sc->option : 0;
  681. WBUFW(buf,14) = vd->hair_style;
  682. WBUFW(buf,16) = vd->weapon;
  683. WBUFW(buf,18) = vd->head_bottom;
  684. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  685. WBUFW(buf,22) = vd->shield;
  686. } else {
  687. #if PACKETVER >= 7
  688. if (!type) {
  689. WBUFL(buf,12) = (sc)? sc->option : 0;
  690. offset+=2;
  691. buf = WBUFP(buffer,offset); //Shift 2 bytes to the right for the rest of fields
  692. } else
  693. #endif
  694. WBUFW(buf,12) = (sc)? sc->option : 0;
  695. WBUFW(buf,14) = vd->class_;
  696. WBUFW(buf,16) = vd->hair_style;
  697. WBUFW(buf,18) = vd->weapon;
  698. #if PACKETVER < 4
  699. WBUFW(buf,20) = vd->head_bottom;
  700. WBUFW(buf,22) = vd->shield;
  701. #else
  702. WBUFW(buf,20) = vd->shield;
  703. WBUFW(buf,22) = vd->head_bottom;
  704. #endif
  705. }
  706. WBUFW(buf,24) = vd->head_top;
  707. WBUFW(buf,26) = vd->head_mid;
  708. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  709. { //The hell, why flags work like this?
  710. WBUFL(buf,22) = status_get_emblem_id(bl);
  711. WBUFL(buf,26) = status_get_guild_id(bl);
  712. }
  713. WBUFW(buf,28) = vd->hair_color;
  714. WBUFW(buf,30) = vd->cloth_color;
  715. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  716. if (type&&spawn) { //End of packet 0x7c
  717. WBUFB(buf,34) = 0; // karma
  718. WBUFB(buf,35) = vd->sex;
  719. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  720. WBUFB(buf,39) = 0;
  721. WBUFB(buf,40) = 0;
  722. return packet_len(0x7c);
  723. }
  724. WBUFL(buf,34) = status_get_guild_id(bl);
  725. WBUFW(buf,38) = status_get_emblem_id(bl);
  726. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  727. #if PACKETVER >= 7
  728. if (!type) {
  729. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  730. offset+=2;
  731. buf = WBUFP(buffer,offset); //Shift additional 2 bytes...
  732. } else
  733. #endif
  734. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  735. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  736. WBUFB(buf,45) = vd->sex;
  737. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  738. WBUFB(buf,49) = (sd)? 5 : 0;
  739. WBUFB(buf,50) = (sd)? 5 : 0;
  740. if (spawn) {
  741. WBUFW(buf,51) = clif_setlevel(status_get_lv(bl));
  742. } else {
  743. WBUFB(buf,51) = vd->dead_sit;
  744. WBUFW(buf,52) = clif_setlevel(status_get_lv(bl));
  745. }
  746. return packet_len(WBUFW(buffer,0));
  747. }
  748. /*==========================================
  749. * Prepares 'unit walking' packet
  750. *------------------------------------------*/
  751. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  752. {
  753. struct map_session_data* sd;
  754. struct status_change* sc = status_get_sc(bl);
  755. struct view_data* vd = status_get_viewdata(bl);
  756. unsigned char* buf = WBUFP(buffer,0);
  757. #if PACKETVER >= 7
  758. unsigned short offset = 0;
  759. #endif
  760. sd = BL_CAST(BL_PC, bl);
  761. #if PACKETVER < 4
  762. WBUFW(buf, 0) = 0x7b;
  763. #elif PACKETVER < 7
  764. WBUFW(buf, 0) = 0x1da;
  765. #else
  766. WBUFW(buf, 0) = 0x22c;
  767. #endif
  768. #if PACKETVER >= 9
  769. WBUFB(buf, 2) = 0; // padding?
  770. offset++;
  771. buf = WBUFP(buf,offset);
  772. #endif
  773. WBUFL(buf, 2) = bl->id;
  774. WBUFW(buf, 6) = status_get_speed(bl);
  775. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  776. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  777. #if PACKETVER < 7
  778. WBUFW(buf,12) = (sc)? sc->option : 0;
  779. #else
  780. WBUFL(buf,12) = (sc)? sc->option : 0;
  781. offset+=2; //Shift the rest of elements by 2 bytes.
  782. buf = WBUFP(buffer,offset);
  783. #endif
  784. WBUFW(buf,14) = vd->class_;
  785. WBUFW(buf,16) = vd->hair_style;
  786. WBUFW(buf,18) = vd->weapon;
  787. #if PACKETVER < 4
  788. WBUFW(buf,20) = vd->head_bottom;
  789. WBUFL(buf,22) = gettick();
  790. WBUFW(buf,26) = vd->shield;
  791. #else
  792. WBUFW(buf,20) = vd->shield;
  793. WBUFW(buf,22) = vd->head_bottom;
  794. WBUFL(buf,24) = gettick();
  795. #endif
  796. WBUFW(buf,28) = vd->head_top;
  797. WBUFW(buf,30) = vd->head_mid;
  798. WBUFW(buf,32) = vd->hair_color;
  799. WBUFW(buf,34) = vd->cloth_color;
  800. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  801. WBUFL(buf,38) = status_get_guild_id(bl);
  802. WBUFW(buf,42) = status_get_emblem_id(bl);
  803. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  804. #if PACKETVER < 7
  805. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  806. #else
  807. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  808. offset+=2; //Shift the rest of elements by 2 bytes.
  809. buf = WBUFP(buffer,offset);
  810. #endif
  811. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  812. WBUFB(buf,49) = vd->sex;
  813. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  814. WBUFB(buf,56) = (sd)? 5 : 0;
  815. WBUFB(buf,57) = (sd)? 5 : 0;
  816. WBUFW(buf,58) = clif_setlevel(status_get_lv(bl));
  817. return packet_len(WBUFW(buffer,0));
  818. }
  819. //Modifies the buffer for disguise characters and sends it to self.
  820. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  821. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  822. {
  823. #if PACKETVER >= 9
  824. WBUFL(buf,3)=-bl->id;
  825. #else
  826. WBUFL(buf,2)=-bl->id;
  827. #endif
  828. clif_send(buf, len, bl, SELF);
  829. }
  830. /*==========================================
  831. * クラスチェンジ typeはMobの場合は1で他は0?
  832. *------------------------------------------*/
  833. int clif_class_change(struct block_list *bl,int class_,int type)
  834. {
  835. unsigned char buf[16];
  836. nullpo_retr(0, bl);
  837. if(!pcdb_checkid(class_)) {
  838. WBUFW(buf,0)=0x1b0;
  839. WBUFL(buf,2)=bl->id;
  840. WBUFB(buf,6)=type;
  841. WBUFL(buf,7)=class_;
  842. clif_send(buf,packet_len(0x1b0),bl,AREA);
  843. }
  844. return 0;
  845. }
  846. /*==========================================
  847. *
  848. *------------------------------------------*/
  849. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  850. {
  851. WFIFOHEAD(fd, packet_len(0x1e1));
  852. WFIFOW(fd,0)=0x1e1;
  853. WFIFOL(fd,2)=sd->bl.id;
  854. WFIFOW(fd,6)=sd->spiritball;
  855. WFIFOSET(fd, packet_len(0x1e1));
  856. }
  857. // new and improved weather display [Valaris]
  858. static void clif_weather_sub(int fd, int id, int type)
  859. {
  860. WFIFOHEAD(fd,packet_len(0x1f3));
  861. WFIFOW(fd,0) = 0x1f3;
  862. WFIFOL(fd,2) = id;
  863. WFIFOL(fd,6) = type;
  864. WFIFOSET(fd,packet_len(0x1f3));
  865. }
  866. /*==========================================
  867. *
  868. *------------------------------------------*/
  869. static void clif_weather_check(struct map_session_data *sd)
  870. {
  871. int m = sd->bl.m, fd = sd->fd;
  872. if (map[m].flag.snow
  873. || map[m].flag.clouds
  874. || map[m].flag.fog
  875. || map[m].flag.fireworks
  876. || map[m].flag.sakura
  877. || map[m].flag.leaves
  878. || map[m].flag.rain
  879. || map[m].flag.clouds2)
  880. {
  881. if (map[m].flag.snow)
  882. clif_weather_sub(fd, sd->bl.id, 162);
  883. if (map[m].flag.clouds)
  884. clif_weather_sub(fd, sd->bl.id, 233);
  885. if (map[m].flag.clouds2)
  886. clif_weather_sub(fd, sd->bl.id, 516);
  887. if (map[m].flag.fog)
  888. clif_weather_sub(fd, sd->bl.id, 515);
  889. if (map[m].flag.fireworks) {
  890. clif_weather_sub(fd, sd->bl.id, 297);
  891. clif_weather_sub(fd, sd->bl.id, 299);
  892. clif_weather_sub(fd, sd->bl.id, 301);
  893. }
  894. if (map[m].flag.sakura)
  895. clif_weather_sub(fd, sd->bl.id, 163);
  896. if (map[m].flag.leaves)
  897. clif_weather_sub(fd, sd->bl.id, 333);
  898. if (map[m].flag.rain)
  899. clif_weather_sub(fd, sd->bl.id, 161);
  900. }
  901. }
  902. int clif_weather(int m)
  903. {
  904. int i;
  905. struct map_session_data *sd=NULL;
  906. for(i = 0; i < fd_max; i++) {
  907. if (session[i] && session[i]->func_parse == clif_parse &&
  908. (sd = session[i]->session_data) != NULL &&
  909. sd->state.active && sd->bl.m == m) {
  910. clif_weather_check(sd);
  911. }
  912. }
  913. return 0;
  914. }
  915. int clif_spawn(struct block_list *bl)
  916. {
  917. unsigned char buf[128];
  918. struct view_data *vd;
  919. int len;
  920. vd = status_get_viewdata(bl);
  921. if( !vd || vd->class_ == INVISIBLE_CLASS )
  922. return 0;
  923. len = clif_set_unit_idle(bl, buf,true);
  924. clif_send(buf, len, bl, AREA_WOS);
  925. if (disguised(bl))
  926. clif_setdisguise(bl, buf, len);
  927. if (vd->cloth_color)
  928. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  929. switch (bl->type)
  930. {
  931. case BL_PC:
  932. {
  933. TBL_PC *sd = ((TBL_PC*)bl);
  934. if (sd->spiritball > 0)
  935. clif_spiritball(sd);
  936. if(sd->state.size==2) // tiny/big players [Valaris]
  937. clif_specialeffect(bl,423,AREA);
  938. else if(sd->state.size==1)
  939. clif_specialeffect(bl,421,AREA);
  940. }
  941. break;
  942. case BL_MOB:
  943. {
  944. TBL_MOB *md = ((TBL_MOB*)bl);
  945. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  946. clif_specialeffect(&md->bl,423,AREA);
  947. else if(md->special_state.size==1)
  948. clif_specialeffect(&md->bl,421,AREA);
  949. }
  950. break;
  951. case BL_PET:
  952. if (vd->head_bottom)
  953. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  954. break;
  955. }
  956. return 0;
  957. }
  958. //[orn]
  959. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  960. {
  961. struct status_data *status;
  962. unsigned char buf[128];
  963. nullpo_retr(0, hd);
  964. status = &hd->battle_status;
  965. memset(buf,0,packet_len(0x22e));
  966. WBUFW(buf,0)=0x22e;
  967. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  968. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  969. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  970. WBUFW(buf,27)=hd->homunculus.level;
  971. WBUFW(buf,29)=hd->homunculus.hunger;
  972. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  973. WBUFW(buf,33)=0; // equip id
  974. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, SHRT_MAX);
  975. WBUFW(buf,37)=cap_value(status->matk_max, 0, SHRT_MAX);
  976. WBUFW(buf,39)=status->hit;
  977. if (battle_config.hom_setting&0x10)
  978. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  979. else
  980. WBUFW(buf,41)=status->cri/10;
  981. WBUFW(buf,43)=status->def + status->vit ;
  982. WBUFW(buf,45)=status->mdef;
  983. WBUFW(buf,47)=status->flee;
  984. WBUFW(buf,49)=(flag)?0:status->amotion;
  985. if (status->max_hp > SHRT_MAX) {
  986. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  987. WBUFW(buf,53) = 100;
  988. } else {
  989. WBUFW(buf,51)=status->hp;
  990. WBUFW(buf,53)=status->max_hp;
  991. }
  992. if (status->max_sp > SHRT_MAX) {
  993. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  994. WBUFW(buf,57) = 100;
  995. } else {
  996. WBUFW(buf,55)=status->sp;
  997. WBUFW(buf,57)=status->max_sp;
  998. }
  999. WBUFL(buf,59)=hd->homunculus.exp;
  1000. WBUFL(buf,63)=hd->exp_next;
  1001. WBUFW(buf,67)=hd->homunculus.skillpts;
  1002. WBUFW(buf,69)=2; // FIXME: undocumented flag, seems to be '2' all the time [ultramage]
  1003. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1004. return 0;
  1005. }
  1006. void clif_send_homdata(struct map_session_data *sd, int type, int param)
  1007. { //[orn]
  1008. int fd = sd->fd;
  1009. WFIFOHEAD(fd, packet_len(0x230));
  1010. nullpo_retv(sd->hd);
  1011. WFIFOW(fd,0)=0x230;
  1012. WFIFOW(fd,2)=type;
  1013. WFIFOL(fd,4)=sd->hd->bl.id;
  1014. WFIFOL(fd,8)=param;
  1015. WFIFOSET(fd,packet_len(0x230));
  1016. return;
  1017. }
  1018. int clif_homskillinfoblock(struct map_session_data *sd)
  1019. { //[orn]
  1020. struct homun_data *hd;
  1021. int fd = sd->fd;
  1022. int i,j,len=4,id;
  1023. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1024. hd = sd->hd;
  1025. if ( !hd )
  1026. return 0 ;
  1027. WFIFOW(fd,0)=0x235;
  1028. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1029. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1030. j = id - HM_SKILLBASE ;
  1031. WFIFOW(fd,len ) = id ;
  1032. WFIFOW(fd,len+2) = skill_get_inf(id) ;
  1033. WFIFOW(fd,len+4) = 0 ;
  1034. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv ;
  1035. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv) ;
  1036. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv) ;
  1037. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH) ;
  1038. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1039. len+=37;
  1040. }
  1041. }
  1042. WFIFOW(fd,2)=len;
  1043. WFIFOSET(fd,len);
  1044. return 0;
  1045. }
  1046. void clif_homskillup(struct map_session_data *sd, int skill_num)
  1047. { //[orn]
  1048. struct homun_data *hd;
  1049. int fd=sd->fd, skillid;
  1050. WFIFOHEAD(fd, packet_len(0x239));
  1051. nullpo_retv(sd);
  1052. skillid = skill_num - HM_SKILLBASE;
  1053. hd=sd->hd;
  1054. WFIFOW(fd,0) = 0x239;
  1055. WFIFOW(fd,2) = skill_num;
  1056. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1057. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1058. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1059. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1060. WFIFOSET(fd,packet_len(0x239));
  1061. return;
  1062. }
  1063. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1064. {
  1065. int fd=sd->fd;
  1066. WFIFOHEAD(fd,packet_len(0x22f));
  1067. WFIFOW(fd,0)=0x22f;
  1068. WFIFOB(fd,2)=fail;
  1069. WFIFOW(fd,3)=foodid;
  1070. WFIFOSET(fd,packet_len(0x22f));
  1071. return 0;
  1072. }
  1073. /*==========================================
  1074. *
  1075. *------------------------------------------*/
  1076. int clif_walkok(struct map_session_data *sd)
  1077. {
  1078. int fd=sd->fd;
  1079. WFIFOHEAD(fd, packet_len(0x87));
  1080. WFIFOW(fd,0)=0x87;
  1081. WFIFOL(fd,2)=gettick();
  1082. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1083. WFIFOSET(fd,packet_len(0x87));
  1084. return 0;
  1085. }
  1086. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1087. {
  1088. uint8 buf[128];
  1089. int len;
  1090. len = clif_set_unit_walking(bl,ud,buf);
  1091. clif_send(buf,len,bl,AREA_WOS);
  1092. if (disguised(bl))
  1093. clif_setdisguise(bl, buf, len);
  1094. if(vd->cloth_color)
  1095. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1096. switch(bl->type)
  1097. {
  1098. case BL_PC:
  1099. {
  1100. TBL_PC *sd = ((TBL_PC*)bl);
  1101. // clif_movepc(sd);
  1102. if(sd->state.size==2) // tiny/big players [Valaris]
  1103. clif_specialeffect(&sd->bl,423,AREA);
  1104. else if(sd->state.size==1)
  1105. clif_specialeffect(&sd->bl,421,AREA);
  1106. }
  1107. break;
  1108. case BL_MOB:
  1109. {
  1110. TBL_MOB *md = ((TBL_MOB*)bl);
  1111. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1112. clif_specialeffect(&md->bl,423,AREA);
  1113. else if(md->special_state.size==1)
  1114. clif_specialeffect(&md->bl,421,AREA);
  1115. }
  1116. break;
  1117. }
  1118. return;
  1119. }
  1120. /// Move the unit (does nothing if the client has no info about the unit)
  1121. /// Note: unit must not be self
  1122. void clif_move(struct unit_data *ud)
  1123. {
  1124. unsigned char buf[16];
  1125. struct view_data* vd;
  1126. struct block_list* bl = ud->bl;
  1127. vd = status_get_viewdata(bl);
  1128. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1129. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1130. if (ud->state.speed_changed) {
  1131. // Since we don't know how to update the speed of other objects,
  1132. // use the old walk packet to update the data.
  1133. ud->state.speed_changed = 0;
  1134. clif_move2(bl, vd, ud);
  1135. return;
  1136. }
  1137. WBUFW(buf,0)=0x86;
  1138. WBUFL(buf,2)=bl->id;
  1139. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1140. WBUFL(buf,12)=gettick();
  1141. clif_send(buf, 16, bl, AREA_WOS);
  1142. if (disguised(bl))
  1143. {
  1144. WBUFL(buf,2)=-bl->id;
  1145. clif_send(buf, 16, bl, SELF);
  1146. }
  1147. }
  1148. /*==========================================
  1149. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1150. *------------------------------------------*/
  1151. static int clif_delayquit(int tid, unsigned int tick, int id, int data)
  1152. {
  1153. struct map_session_data *sd = NULL;
  1154. //Remove player from map server
  1155. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1156. map_quit(sd);
  1157. return 0;
  1158. }
  1159. /*==========================================
  1160. *
  1161. *------------------------------------------*/
  1162. void clif_quitsave(int fd,struct map_session_data *sd)
  1163. {
  1164. if (!battle_config.prevent_logout ||
  1165. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1166. map_quit(sd);
  1167. else if (sd->fd)
  1168. { //Disassociate session from player (session is deleted after this function was called)
  1169. //And set a timer to make him quit later.
  1170. session[sd->fd]->session_data = NULL;
  1171. sd->fd = 0;
  1172. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1173. }
  1174. }
  1175. /*==========================================
  1176. *
  1177. *------------------------------------------*/
  1178. static int clif_waitclose(int tid, unsigned int tick, int id, int data)
  1179. {
  1180. if (session[id] && session[id]->func_parse == clif_parse) //Avoid disconnecting non-players, as pointed out by End of Exam [Skotlex]
  1181. set_eof(id);
  1182. return 0;
  1183. }
  1184. /*==========================================
  1185. *
  1186. *------------------------------------------*/
  1187. void clif_setwaitclose(int fd)
  1188. {
  1189. // if player is not already in the game (double connection probably)
  1190. if (session[fd]->session_data == NULL) {
  1191. // limited timer, just to send information.
  1192. add_timer(gettick() + 1000, clif_waitclose, fd, 0);
  1193. } else
  1194. add_timer(gettick() + 5000, clif_waitclose, fd, 0);
  1195. }
  1196. /*==========================================
  1197. *
  1198. *------------------------------------------*/
  1199. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1200. {
  1201. int fd;
  1202. nullpo_retv(sd);
  1203. fd = sd->fd;
  1204. WFIFOHEAD(fd,packet_len(0x91));
  1205. WFIFOW(fd,0) = 0x91;
  1206. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1207. WFIFOW(fd,18) = x;
  1208. WFIFOW(fd,20) = y;
  1209. WFIFOSET(fd,packet_len(0x91));
  1210. }
  1211. /*==========================================
  1212. * Tells the client to connect to another map-server
  1213. *------------------------------------------*/
  1214. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1215. {
  1216. int fd;
  1217. nullpo_retv(sd);
  1218. fd = sd->fd;
  1219. WFIFOHEAD(fd,packet_len(0x92));
  1220. WFIFOW(fd,0) = 0x92;
  1221. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1222. WFIFOW(fd,18) = x;
  1223. WFIFOW(fd,20) = y;
  1224. WFIFOL(fd,22) = htonl(ip);
  1225. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1226. WFIFOSET(fd,packet_len(0x92));
  1227. }
  1228. int clif_blown(struct block_list *bl)
  1229. {
  1230. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1231. // return clif_fixpos(bl);
  1232. return clif_slide(bl, bl->x, bl->y);
  1233. }
  1234. /*==========================================
  1235. *
  1236. *------------------------------------------*/
  1237. int clif_fixpos(struct block_list *bl)
  1238. {
  1239. unsigned char buf[16];
  1240. nullpo_retr(0, bl);
  1241. WBUFW(buf,0)=0x88;
  1242. WBUFL(buf,2)=bl->id;
  1243. WBUFW(buf,6)=bl->x;
  1244. WBUFW(buf,8)=bl->y;
  1245. clif_send(buf, packet_len(0x88), bl, AREA);
  1246. if (disguised(bl)) {
  1247. WBUFL(buf,2)=-bl->id;
  1248. clif_send(buf, packet_len(0x88), bl, SELF);
  1249. }
  1250. return 0;
  1251. }
  1252. /*==========================================
  1253. *
  1254. *------------------------------------------*/
  1255. int clif_npcbuysell(struct map_session_data* sd, int id)
  1256. {
  1257. int fd;
  1258. nullpo_retr(0, sd);
  1259. fd=sd->fd;
  1260. WFIFOHEAD(fd, packet_len(0xc4));
  1261. WFIFOW(fd,0)=0xc4;
  1262. WFIFOL(fd,2)=id;
  1263. WFIFOSET(fd,packet_len(0xc4));
  1264. return 0;
  1265. }
  1266. /*==========================================
  1267. *
  1268. *------------------------------------------*/
  1269. int clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1270. {
  1271. int fd,i;
  1272. nullpo_retr(0, sd);
  1273. nullpo_retr(0, nd);
  1274. fd = sd->fd;
  1275. WFIFOHEAD(fd, 200 * 11 + 4);
  1276. WFIFOW(fd,0) = 0xc6;
  1277. WFIFOW(fd,2) = 4 + nd->u.shop.count*11;
  1278. for( i = 0; i < nd->u.shop.count; i++ )
  1279. {
  1280. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  1281. int val = nd->u.shop.shop_item[i].value;
  1282. WFIFOL(fd,4+i*11) = val;
  1283. if (!id->flag.value_notdc)
  1284. val = pc_modifybuyvalue(sd,val);
  1285. WFIFOL(fd,8+i*11) = val;
  1286. WFIFOB(fd,12+i*11) = itemtype(id->type);
  1287. WFIFOW(fd,13+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1288. }
  1289. WFIFOSET(fd,WFIFOW(fd,2));
  1290. return 0;
  1291. }
  1292. /*==========================================
  1293. *
  1294. *------------------------------------------*/
  1295. int clif_selllist(struct map_session_data *sd)
  1296. {
  1297. int fd,i,c=0,val;
  1298. nullpo_retr(0, sd);
  1299. fd=sd->fd;
  1300. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1301. WFIFOW(fd,0)=0xc7;
  1302. for(i=0;i<MAX_INVENTORY;i++) {
  1303. if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
  1304. if (!itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)))
  1305. continue;
  1306. val=sd->inventory_data[i]->value_sell;
  1307. if (val < 0)
  1308. continue;
  1309. WFIFOW(fd,4+c*10)=i+2;
  1310. WFIFOL(fd,6+c*10)=val;
  1311. if (!sd->inventory_data[i]->flag.value_notoc)
  1312. val=pc_modifysellvalue(sd,val);
  1313. WFIFOL(fd,10+c*10)=val;
  1314. c++;
  1315. }
  1316. }
  1317. WFIFOW(fd,2)=c*10+4;
  1318. WFIFOSET(fd,WFIFOW(fd,2));
  1319. return 0;
  1320. }
  1321. /*==========================================
  1322. *
  1323. *------------------------------------------*/
  1324. int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1325. {
  1326. int fd = sd->fd;
  1327. int slen = strlen(mes) + 9;
  1328. WFIFOHEAD(fd, slen);
  1329. WFIFOW(fd,0)=0xb4;
  1330. WFIFOW(fd,2)=slen;
  1331. WFIFOL(fd,4)=npcid;
  1332. strcpy((char*)WFIFOP(fd,8),mes);
  1333. WFIFOSET(fd,WFIFOW(fd,2));
  1334. return 0;
  1335. }
  1336. /*==========================================
  1337. *
  1338. *------------------------------------------*/
  1339. int clif_scriptnext(struct map_session_data *sd,int npcid)
  1340. {
  1341. int fd;
  1342. nullpo_retr(0, sd);
  1343. fd=sd->fd;
  1344. WFIFOHEAD(fd, packet_len(0xb5));
  1345. WFIFOW(fd,0)=0xb5;
  1346. WFIFOL(fd,2)=npcid;
  1347. WFIFOSET(fd,packet_len(0xb5));
  1348. return 0;
  1349. }
  1350. /*==========================================
  1351. *
  1352. *------------------------------------------*/
  1353. int clif_scriptclose(struct map_session_data *sd, int npcid)
  1354. {
  1355. int fd;
  1356. nullpo_retr(0, sd);
  1357. fd=sd->fd;
  1358. WFIFOHEAD(fd, packet_len(0xb6));
  1359. WFIFOW(fd,0)=0xb6;
  1360. WFIFOL(fd,2)=npcid;
  1361. WFIFOSET(fd,packet_len(0xb6));
  1362. return 0;
  1363. }
  1364. /*==========================================
  1365. *
  1366. *------------------------------------------*/
  1367. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1368. {
  1369. unsigned char *buf;
  1370. int fd = sd->fd;
  1371. sd->state.using_fake_npc = 1;
  1372. WFIFOHEAD(fd, packet_len(0x78));
  1373. buf = WFIFOP(fd,0);
  1374. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1375. WBUFW(buf,0)=0x78;
  1376. #if PACKETVER >=9
  1377. WBUFB(buf,2) = 0; //Unknown bit
  1378. buf = WFIFOP(fd,1);
  1379. #endif
  1380. WBUFL(buf,2)=npcid;
  1381. WBUFW(buf,14)=111;
  1382. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1383. WBUFB(buf,49)=5;
  1384. WBUFB(buf,50)=5;
  1385. WFIFOSET(fd, packet_len(0x78));
  1386. return;
  1387. }
  1388. /*==========================================
  1389. *
  1390. *------------------------------------------*/
  1391. int clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1392. {
  1393. int fd = sd->fd;
  1394. int slen = strlen(mes) + 8;
  1395. struct block_list *bl = NULL;
  1396. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1397. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1398. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1399. clif_sendfakenpc(sd, npcid);
  1400. WFIFOHEAD(fd, slen);
  1401. WFIFOW(fd,0)=0xb7;
  1402. WFIFOW(fd,2)=slen;
  1403. WFIFOL(fd,4)=npcid;
  1404. strcpy((char*)WFIFOP(fd,8),mes);
  1405. WFIFOSET(fd,WFIFOW(fd,2));
  1406. return 0;
  1407. }
  1408. /*==========================================
  1409. *
  1410. *------------------------------------------*/
  1411. int clif_scriptinput(struct map_session_data *sd, int npcid)
  1412. {
  1413. int fd;
  1414. struct block_list *bl = NULL;
  1415. nullpo_retr(0, sd);
  1416. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1417. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1418. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1419. clif_sendfakenpc(sd, npcid);
  1420. fd=sd->fd;
  1421. WFIFOHEAD(fd, packet_len(0x142));
  1422. WFIFOW(fd,0)=0x142;
  1423. WFIFOL(fd,2)=npcid;
  1424. WFIFOSET(fd,packet_len(0x142));
  1425. return 0;
  1426. }
  1427. /*==========================================
  1428. *
  1429. *------------------------------------------*/
  1430. int clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1431. {
  1432. int fd;
  1433. struct block_list *bl = NULL;
  1434. nullpo_retr(0, sd);
  1435. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1436. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1437. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1438. clif_sendfakenpc(sd, npcid);
  1439. fd=sd->fd;
  1440. WFIFOHEAD(fd, packet_len(0x1d4));
  1441. WFIFOW(fd,0)=0x1d4;
  1442. WFIFOL(fd,2)=npcid;
  1443. WFIFOSET(fd,packet_len(0x1d4));
  1444. return 0;
  1445. }
  1446. /// npc_id is ignored in the client
  1447. /// type=2 : Remove viewpoint
  1448. /// type=other : Show viewpoint
  1449. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1450. {
  1451. int fd;
  1452. nullpo_retr(0, sd);
  1453. fd=sd->fd;
  1454. WFIFOHEAD(fd, packet_len(0x144));
  1455. WFIFOW(fd,0)=0x144;
  1456. WFIFOL(fd,2)=npc_id;
  1457. WFIFOL(fd,6)=type;
  1458. WFIFOL(fd,10)=x;
  1459. WFIFOL(fd,14)=y;
  1460. WFIFOB(fd,18)=id;
  1461. WFIFOL(fd,19)=color;
  1462. WFIFOSET(fd,packet_len(0x144));
  1463. return 0;
  1464. }
  1465. /*==========================================
  1466. *
  1467. *------------------------------------------*/
  1468. int clif_cutin(struct map_session_data* sd, const char* image, int type)
  1469. {
  1470. int fd;
  1471. nullpo_retr(0, sd);
  1472. fd=sd->fd;
  1473. WFIFOHEAD(fd, packet_len(0x1b3));
  1474. WFIFOW(fd,0)=0x1b3;
  1475. strncpy((char*)WFIFOP(fd,2),image,64);
  1476. WFIFOB(fd,66)=type;
  1477. WFIFOSET(fd,packet_len(0x1b3));
  1478. return 0;
  1479. }
  1480. /*==========================================
  1481. * Fills in card data from the given item and into the buffer. [Skotlex]
  1482. *------------------------------------------*/
  1483. static void clif_addcards(unsigned char* buf, struct item* item)
  1484. {
  1485. int i=0,j;
  1486. if( item == NULL ) { //Blank data
  1487. WBUFW(buf,0) = 0;
  1488. WBUFW(buf,2) = 0;
  1489. WBUFW(buf,4) = 0;
  1490. WBUFW(buf,6) = 0;
  1491. return;
  1492. }
  1493. if( item->card[0] == CARD0_PET ) { //pet eggs
  1494. WBUFW(buf,0) = 0;
  1495. WBUFW(buf,2) = 0;
  1496. WBUFW(buf,4) = 0;
  1497. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1498. return;
  1499. }
  1500. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1501. WBUFW(buf,0) = item->card[0];
  1502. WBUFW(buf,2) = item->card[1];
  1503. WBUFW(buf,4) = item->card[2];
  1504. WBUFW(buf,6) = item->card[3];
  1505. return;
  1506. }
  1507. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1508. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1509. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1510. //Normal items.
  1511. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1512. WBUFW(buf,0) = j;
  1513. else
  1514. WBUFW(buf,0) = item->card[i];
  1515. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1516. WBUFW(buf,2) = j;
  1517. else
  1518. WBUFW(buf,2) = item->card[i];
  1519. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1520. WBUFW(buf,4) = j;
  1521. else
  1522. WBUFW(buf,4) = item->card[i];
  1523. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1524. WBUFW(buf,6) = j;
  1525. else
  1526. WBUFW(buf,6) = item->card[i];
  1527. }
  1528. /*==========================================
  1529. *
  1530. *------------------------------------------*/
  1531. int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1532. {
  1533. int fd;
  1534. nullpo_retr(0, sd);
  1535. fd = sd->fd;
  1536. if (!session_isActive(fd)) //Sasuke-
  1537. return 0;
  1538. WFIFOHEAD(fd,packet_len(0xa0));
  1539. if(fail) {
  1540. WFIFOW(fd,0)=0xa0;
  1541. WFIFOW(fd,2)=n+2;
  1542. WFIFOW(fd,4)=amount;
  1543. WFIFOW(fd,6)=0;
  1544. WFIFOB(fd,8)=0;
  1545. WFIFOB(fd,9)=0;
  1546. WFIFOB(fd,10)=0;
  1547. WFIFOW(fd,11)=0;
  1548. WFIFOW(fd,13)=0;
  1549. WFIFOW(fd,15)=0;
  1550. WFIFOW(fd,17)=0;
  1551. WFIFOW(fd,19)=0;
  1552. WFIFOB(fd,21)=0;
  1553. WFIFOB(fd,22)=fail;
  1554. } else {
  1555. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1556. return 1;
  1557. WFIFOW(fd,0)=0xa0;
  1558. WFIFOW(fd,2)=n+2;
  1559. WFIFOW(fd,4)=amount;
  1560. if (sd->inventory_data[n]->view_id > 0)
  1561. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1562. else
  1563. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1564. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1565. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1566. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1567. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1568. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1569. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1570. WFIFOB(fd,22)=fail;
  1571. }
  1572. WFIFOSET(fd,packet_len(0xa0));
  1573. return 0;
  1574. }
  1575. /*==========================================
  1576. *
  1577. *------------------------------------------*/
  1578. int clif_delitem(struct map_session_data *sd,int n,int amount)
  1579. {
  1580. int fd;
  1581. nullpo_retr(0, sd);
  1582. fd=sd->fd;
  1583. WFIFOHEAD(fd, packet_len(0xaf));
  1584. WFIFOW(fd,0)=0xaf;
  1585. WFIFOW(fd,2)=n+2;
  1586. WFIFOW(fd,4)=amount;
  1587. WFIFOSET(fd,packet_len(0xaf));
  1588. return 0;
  1589. }
  1590. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1591. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1592. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1593. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1594. {
  1595. if (id->view_id > 0)
  1596. WBUFW(buf,n)=id->view_id;
  1597. else
  1598. WBUFW(buf,n)=i->nameid;
  1599. WBUFB(buf,n+2)=itemtype(id->type);
  1600. WBUFB(buf,n+3)=i->identify;
  1601. if (equip >= 0) { //Equippable item
  1602. WBUFW(buf,n+4)=equip;
  1603. WBUFW(buf,n+6)=i->equip;
  1604. WBUFB(buf,n+8)=i->attribute;
  1605. WBUFB(buf,n+9)=i->refine;
  1606. } else { //Stackable item.
  1607. WBUFW(buf,n+4)=i->amount;
  1608. if (equip == -2 && id->equip == EQP_AMMO)
  1609. WBUFW(buf,n+6)=EQP_AMMO;
  1610. else
  1611. WBUFW(buf,n+6)=0;
  1612. }
  1613. }
  1614. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1615. void clif_inventorylist(struct map_session_data *sd)
  1616. {
  1617. int i,n,ne,fd = sd->fd,arrow=-1;
  1618. unsigned char *buf;
  1619. unsigned char bufe[MAX_INVENTORY*20+4];
  1620. #if PACKETVER < 5
  1621. const int s = 10; //Entry size.
  1622. #else
  1623. const int s = 18;
  1624. #endif
  1625. WFIFOHEAD(fd, MAX_INVENTORY * s + 4);
  1626. buf = WFIFOP(fd,0);
  1627. for(i=0,n=0,ne=0;i<MAX_INVENTORY;i++){
  1628. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1629. continue;
  1630. if(!itemdb_isstackable2(sd->inventory_data[i]))
  1631. { //Non-stackable (Equippable)
  1632. WBUFW(bufe,ne*20+4)=i+2;
  1633. clif_item_sub(bufe, ne*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1634. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.inventory[i]);
  1635. ne++;
  1636. } else { //Stackable.
  1637. WBUFW(buf,n*s+4)=i+2;
  1638. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1639. if (sd->inventory_data[i]->equip == EQP_AMMO &&
  1640. sd->status.inventory[i].equip)
  1641. arrow=i;
  1642. #if PACKETVER >= 5
  1643. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1644. #endif
  1645. n++;
  1646. }
  1647. }
  1648. if (n) {
  1649. #if PACKETVER < 5
  1650. WBUFW(buf,0)=0xa3;
  1651. #else
  1652. WBUFW(buf,0)=0x1ee;
  1653. #endif
  1654. WBUFW(buf,2)=4+n*s;
  1655. WFIFOSET(fd,WFIFOW(fd,2));
  1656. }
  1657. if(arrow >= 0)
  1658. clif_arrowequip(sd,arrow);
  1659. if(ne){
  1660. WBUFW(bufe,0)=0xa4;
  1661. WBUFW(bufe,2)=4+ne*20;
  1662. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1663. }
  1664. }
  1665. //Required when items break/get-repaired. Only sends equippable item list.
  1666. void clif_equiplist(struct map_session_data *sd)
  1667. {
  1668. int i,n,fd = sd->fd;
  1669. unsigned char *buf;
  1670. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  1671. buf = WFIFOP(fd,0);
  1672. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1673. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1674. continue;
  1675. if(itemdb_isstackable2(sd->inventory_data[i]))
  1676. continue;
  1677. //Equippable
  1678. WBUFW(buf,n*20+4)=i+2;
  1679. clif_item_sub(buf, n*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1680. clif_addcards(WBUFP(buf, n*20+16), &sd->status.inventory[i]);
  1681. n++;
  1682. }
  1683. if (n) {
  1684. WBUFW(buf,0)=0xa4;
  1685. WBUFW(buf,2)=4+n*20;
  1686. WFIFOSET(fd,WFIFOW(fd,2));
  1687. }
  1688. }
  1689. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1690. void clif_storagelist(struct map_session_data *sd,struct storage *stor)
  1691. {
  1692. struct item_data *id;
  1693. int i,n,ne,fd=sd->fd;
  1694. unsigned char *buf;
  1695. unsigned char bufe[MAX_STORAGE*20+4];
  1696. #if PACKETVER < 5
  1697. const int s = 10; //Entry size.
  1698. #else
  1699. const int s = 18;
  1700. #endif
  1701. WFIFOHEAD(fd,MAX_STORAGE * s + 4);
  1702. buf = WFIFOP(fd,0);
  1703. for(i=0,n=0,ne=0;i<MAX_STORAGE;i++){
  1704. if(stor->storage_[i].nameid<=0)
  1705. continue;
  1706. id = itemdb_search(stor->storage_[i].nameid);
  1707. if(!itemdb_isstackable2(id))
  1708. { //Equippable
  1709. WBUFW(bufe,ne*20+4)=i+1;
  1710. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  1711. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  1712. ne++;
  1713. } else { //Stackable
  1714. WBUFW(buf,n*s+4)=i+1;
  1715. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  1716. #if PACKETVER >= 5
  1717. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  1718. #endif
  1719. n++;
  1720. }
  1721. }
  1722. if(n){
  1723. #if PACKETVER < 5
  1724. WBUFW(buf,0)=0xa5;
  1725. #else
  1726. WBUFW(buf,0)=0x1f0;
  1727. #endif
  1728. WBUFW(buf,2)=4+n*s;
  1729. WFIFOSET(fd,WFIFOW(fd,2));
  1730. }
  1731. if(ne){
  1732. WBUFW(bufe,0)=0xa6;
  1733. WBUFW(bufe,2)=4+ne*20;
  1734. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1735. }
  1736. }
  1737. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1738. void clif_guildstoragelist(struct map_session_data *sd,struct guild_storage *stor)
  1739. {
  1740. struct item_data *id;
  1741. int i,n,ne,fd=sd->fd;
  1742. unsigned char *buf;
  1743. unsigned char bufe[MAX_GUILD_STORAGE*20+4];
  1744. #if PACKETVER < 5
  1745. const int s = 10; //Entry size.
  1746. #else
  1747. const int s = 18;
  1748. #endif
  1749. WFIFOHEAD(fd,MAX_GUILD_STORAGE * s + 4);
  1750. buf = WFIFOP(fd,0);
  1751. for(i=0,n=0,ne=0;i<MAX_GUILD_STORAGE;i++){
  1752. if(stor->storage_[i].nameid<=0)
  1753. continue;
  1754. id = itemdb_search(stor->storage_[i].nameid);
  1755. if(!itemdb_isstackable2(id))
  1756. { //Equippable
  1757. WBUFW(bufe,ne*20+4)=i+1;
  1758. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  1759. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  1760. ne++;
  1761. } else { //Stackable
  1762. WBUFW(buf,n*s+4)=i+1;
  1763. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  1764. #if PACKETVER >= 5
  1765. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  1766. #endif
  1767. n++;
  1768. }
  1769. }
  1770. if(n){
  1771. #if PACKETVER < 5
  1772. WBUFW(buf,0)=0xa5;
  1773. #else
  1774. WBUFW(buf,0)=0x1f0;
  1775. #endif
  1776. WBUFW(buf,2)=4+n*s;
  1777. WFIFOSET(fd,WFIFOW(fd,2));
  1778. }
  1779. if(ne){
  1780. WBUFW(bufe,0)=0xa6;
  1781. WBUFW(bufe,2)=4+ne*20;
  1782. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1783. }
  1784. }
  1785. void clif_cartlist(struct map_session_data *sd)
  1786. {
  1787. struct item_data *id;
  1788. int i,n,ne,fd=sd->fd;
  1789. unsigned char *buf;
  1790. unsigned char bufe[MAX_CART*20+4];
  1791. #if PACKETVER < 5
  1792. const int s = 10; //Entry size.
  1793. #else
  1794. const int s = 18;
  1795. #endif
  1796. WFIFOHEAD(fd, MAX_CART * s + 4);
  1797. buf = WFIFOP(fd,0);
  1798. for(i=0,n=0,ne=0;i<MAX_CART;i++){
  1799. if(sd->status.cart[i].nameid<=0)
  1800. continue;
  1801. id = itemdb_search(sd->status.cart[i].nameid);
  1802. if(!itemdb_isstackable2(id))
  1803. { //Equippable
  1804. WBUFW(bufe,ne*20+4)=i+2;
  1805. clif_item_sub(bufe, ne*20+6, &sd->status.cart[i], id, id->equip);
  1806. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.cart[i]);
  1807. ne++;
  1808. } else { //Stackable
  1809. WBUFW(buf,n*s+4)=i+2;
  1810. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  1811. #if PACKETVER >= 5
  1812. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  1813. #endif
  1814. n++;
  1815. }
  1816. }
  1817. if(n){
  1818. #if PACKETVER < 5
  1819. WBUFW(buf,0)=0x123;
  1820. #else
  1821. WBUFW(buf,0)=0x1ef;
  1822. #endif
  1823. WBUFW(buf,2)=4+n*s;
  1824. WFIFOSET(fd,WFIFOW(fd,2));
  1825. }
  1826. if(ne){
  1827. WBUFW(bufe,0)=0x122;
  1828. WBUFW(bufe,2)=4+ne*20;
  1829. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1830. }
  1831. return;
  1832. }
  1833. /// Client behaviour:
  1834. /// Closes the cart storage and removes all it's items from memory.
  1835. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  1836. void clif_clearcart(int fd)
  1837. {
  1838. WFIFOHEAD(fd, packet_len(0x12b));
  1839. WFIFOW(fd,0) = 0x12b;
  1840. }
  1841. // Guild XY locators [Valaris]
  1842. int clif_guild_xy(struct map_session_data *sd)
  1843. {
  1844. unsigned char buf[10];
  1845. nullpo_retr(0, sd);
  1846. WBUFW(buf,0)=0x1eb;
  1847. WBUFL(buf,2)=sd->status.account_id;
  1848. WBUFW(buf,6)=sd->bl.x;
  1849. WBUFW(buf,8)=sd->bl.y;
  1850. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  1851. return 0;
  1852. }
  1853. /*==========================================
  1854. * Sends x/y dot to a single fd. [Skotlex]
  1855. *------------------------------------------*/
  1856. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  1857. {
  1858. WFIFOHEAD(fd,packet_len(0x1eb));
  1859. WFIFOW(fd,0)=0x1eb;
  1860. WFIFOL(fd,2)=sd->status.account_id;
  1861. WFIFOW(fd,6)=sd->bl.x;
  1862. WFIFOW(fd,8)=sd->bl.y;
  1863. WFIFOSET(fd,packet_len(0x1eb));
  1864. return 0;
  1865. }
  1866. // Guild XY locators [Valaris]
  1867. int clif_guild_xy_remove(struct map_session_data *sd)
  1868. {
  1869. unsigned char buf[10];
  1870. nullpo_retr(0, sd);
  1871. WBUFW(buf,0)=0x1eb;
  1872. WBUFL(buf,2)=sd->status.account_id;
  1873. WBUFW(buf,6)=-1;
  1874. WBUFW(buf,8)=-1;
  1875. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  1876. return 0;
  1877. }
  1878. /*==========================================
  1879. * ステータスを送りつける
  1880. * 表示専用数字はこの中で計算して送る
  1881. *------------------------------------------*/
  1882. int clif_updatestatus(struct map_session_data *sd,int type)
  1883. {
  1884. int fd,len=8;
  1885. nullpo_retr(0, sd);
  1886. fd=sd->fd;
  1887. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  1888. return 0;
  1889. WFIFOHEAD(fd, 14);
  1890. WFIFOW(fd,0)=0xb0;
  1891. WFIFOW(fd,2)=type;
  1892. switch(type){
  1893. // 00b0
  1894. case SP_WEIGHT:
  1895. pc_updateweightstatus(sd);
  1896. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  1897. WFIFOW(fd,2)=type;
  1898. WFIFOL(fd,4)=sd->weight;
  1899. break;
  1900. case SP_MAXWEIGHT:
  1901. WFIFOL(fd,4)=sd->max_weight;
  1902. break;
  1903. case SP_SPEED:
  1904. WFIFOL(fd,4)=sd->battle_status.speed;
  1905. break;
  1906. case SP_BASELEVEL:
  1907. WFIFOL(fd,4)=sd->status.base_level;
  1908. break;
  1909. case SP_JOBLEVEL:
  1910. WFIFOL(fd,4)=sd->status.job_level;
  1911. break;
  1912. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  1913. WFIFOL(fd,4)=sd->status.karma;
  1914. break;
  1915. case SP_MANNER:
  1916. WFIFOL(fd,4)=sd->status.manner;
  1917. break;
  1918. case SP_STATUSPOINT:
  1919. WFIFOL(fd,4)=sd->status.status_point;
  1920. break;
  1921. case SP_SKILLPOINT:
  1922. WFIFOL(fd,4)=sd->status.skill_point;
  1923. break;
  1924. case SP_HIT:
  1925. WFIFOL(fd,4)=sd->battle_status.hit;
  1926. break;
  1927. case SP_FLEE1:
  1928. WFIFOL(fd,4)=sd->battle_status.flee;
  1929. break;
  1930. case SP_FLEE2:
  1931. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  1932. break;
  1933. case SP_MAXHP:
  1934. WFIFOL(fd,4)=sd->battle_status.max_hp;
  1935. break;
  1936. case SP_MAXSP:
  1937. WFIFOL(fd,4)=sd->battle_status.max_sp;
  1938. break;
  1939. case SP_HP:
  1940. WFIFOL(fd,4)=sd->battle_status.hp;
  1941. if (battle_config.disp_hpmeter)
  1942. clif_hpmeter(sd);
  1943. if (!battle_config.party_hp_mode && sd->status.party_id)
  1944. clif_party_hp(sd);
  1945. break;
  1946. case SP_SP:
  1947. WFIFOL(fd,4)=sd->battle_status.sp;
  1948. break;
  1949. case SP_ASPD:
  1950. WFIFOL(fd,4)=sd->battle_status.amotion;
  1951. break;
  1952. case SP_ATK1:
  1953. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw.atk;
  1954. break;
  1955. case SP_DEF1:
  1956. WFIFOL(fd,4)=sd->battle_status.def;
  1957. break;
  1958. case SP_MDEF1:
  1959. WFIFOL(fd,4)=sd->battle_status.mdef;
  1960. break;
  1961. case SP_ATK2:
  1962. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2;
  1963. break;
  1964. case SP_DEF2:
  1965. WFIFOL(fd,4)=sd->battle_status.def2;
  1966. break;
  1967. case SP_MDEF2:
  1968. //negative check (in case you have something like Berserk active)
  1969. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  1970. if (len < 0) len = 0;
  1971. WFIFOL(fd,4)= len;
  1972. len = 8;
  1973. break;
  1974. case SP_CRITICAL:
  1975. WFIFOL(fd,4)=sd->battle_status.cri/10;
  1976. break;
  1977. case SP_MATK1:
  1978. WFIFOL(fd,4)=sd->battle_status.matk_max;
  1979. break;
  1980. case SP_MATK2:
  1981. WFIFOL(fd,4)=sd->battle_status.matk_min;
  1982. break;
  1983. case SP_ZENY:
  1984. WFIFOW(fd,0)=0xb1;
  1985. WFIFOL(fd,4)=sd->status.zeny - sd->mail.zeny;
  1986. break;
  1987. case SP_BASEEXP:
  1988. WFIFOW(fd,0)=0xb1;
  1989. WFIFOL(fd,4)=sd->status.base_exp;
  1990. break;
  1991. case SP_JOBEXP:
  1992. WFIFOW(fd,0)=0xb1;
  1993. WFIFOL(fd,4)=sd->status.job_exp;
  1994. break;
  1995. case SP_NEXTBASEEXP:
  1996. WFIFOW(fd,0)=0xb1;
  1997. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  1998. break;
  1999. case SP_NEXTJOBEXP:
  2000. WFIFOW(fd,0)=0xb1;
  2001. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2002. break;
  2003. // 00be 終了
  2004. case SP_USTR:
  2005. case SP_UAGI:
  2006. case SP_UVIT:
  2007. case SP_UINT:
  2008. case SP_UDEX:
  2009. case SP_ULUK:
  2010. WFIFOW(fd,0)=0xbe;
  2011. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2012. len=5;
  2013. break;
  2014. // 013a 終了
  2015. case SP_ATTACKRANGE:
  2016. WFIFOW(fd,0)=0x13a;
  2017. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2018. len=4;
  2019. break;
  2020. // 0141 終了
  2021. case SP_STR:
  2022. WFIFOW(fd,0)=0x141;
  2023. WFIFOL(fd,2)=type;
  2024. WFIFOL(fd,6)=sd->status.str;
  2025. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2026. len=14;
  2027. break;
  2028. case SP_AGI:
  2029. WFIFOW(fd,0)=0x141;
  2030. WFIFOL(fd,2)=type;
  2031. WFIFOL(fd,6)=sd->status.agi;
  2032. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2033. len=14;
  2034. break;
  2035. case SP_VIT:
  2036. WFIFOW(fd,0)=0x141;
  2037. WFIFOL(fd,2)=type;
  2038. WFIFOL(fd,6)=sd->status.vit;
  2039. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2040. len=14;
  2041. break;
  2042. case SP_INT:
  2043. WFIFOW(fd,0)=0x141;
  2044. WFIFOL(fd,2)=type;
  2045. WFIFOL(fd,6)=sd->status.int_;
  2046. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2047. len=14;
  2048. break;
  2049. case SP_DEX:
  2050. WFIFOW(fd,0)=0x141;
  2051. WFIFOL(fd,2)=type;
  2052. WFIFOL(fd,6)=sd->status.dex;
  2053. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2054. len=14;
  2055. break;
  2056. case SP_LUK:
  2057. WFIFOW(fd,0)=0x141;
  2058. WFIFOL(fd,2)=type;
  2059. WFIFOL(fd,6)=sd->status.luk;
  2060. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2061. len=14;
  2062. break;
  2063. case SP_CARTINFO:
  2064. WFIFOW(fd,0)=0x121;
  2065. WFIFOW(fd,2)=sd->cart_num;
  2066. WFIFOW(fd,4)=MAX_CART;
  2067. WFIFOL(fd,6)=sd->cart_weight;
  2068. WFIFOL(fd,10)=battle_config.max_cart_weight;
  2069. len=14;
  2070. break;
  2071. default:
  2072. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2073. return 1;
  2074. }
  2075. WFIFOSET(fd,len);
  2076. return 0;
  2077. }
  2078. int clif_changestatus(struct block_list *bl,int type,int val)
  2079. {
  2080. unsigned char buf[12];
  2081. struct map_session_data *sd = NULL;
  2082. nullpo_retr(0, bl);
  2083. if(bl->type == BL_PC)
  2084. sd = (struct map_session_data *)bl;
  2085. if(sd){
  2086. WBUFW(buf,0)=0x1ab;
  2087. WBUFL(buf,2)=bl->id;
  2088. WBUFW(buf,6)=type;
  2089. switch(type){
  2090. case SP_MANNER:
  2091. WBUFL(buf,8)=val;
  2092. break;
  2093. default:
  2094. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2095. return 1;
  2096. }
  2097. clif_send(buf,packet_len(0x1ab),bl,AREA_WOS);
  2098. }
  2099. return 0;
  2100. }
  2101. /*==========================================
  2102. *
  2103. *------------------------------------------*/
  2104. void clif_changelook(struct block_list *bl,int type,int val)
  2105. {
  2106. unsigned char buf[16];
  2107. struct map_session_data* sd = NULL;
  2108. struct view_data* vd;
  2109. nullpo_retv(bl);
  2110. sd = BL_CAST(BL_PC, bl);
  2111. vd = status_get_viewdata(bl);
  2112. //nullpo_ret(vd);
  2113. if( vd ) //temp hack to let Warp Portal change appearance
  2114. switch(type)
  2115. {
  2116. case LOOK_WEAPON:
  2117. if (sd)
  2118. {
  2119. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2120. val = vd->weapon;
  2121. }
  2122. else vd->weapon = val;
  2123. break;
  2124. case LOOK_SHIELD:
  2125. if (sd)
  2126. {
  2127. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2128. val = vd->shield;
  2129. }
  2130. else vd->shield = val;
  2131. break;
  2132. case LOOK_BASE:
  2133. vd->class_ = val;
  2134. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2135. vd->weapon = vd->shield = 0;
  2136. if (vd->cloth_color && (
  2137. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2138. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2139. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2140. ))
  2141. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2142. break;
  2143. case LOOK_HAIR:
  2144. vd->hair_style = val;
  2145. break;
  2146. case LOOK_HEAD_BOTTOM:
  2147. vd->head_bottom = val;
  2148. break;
  2149. case LOOK_HEAD_TOP:
  2150. vd->head_top = val;
  2151. break;
  2152. case LOOK_HEAD_MID:
  2153. vd->head_mid = val;
  2154. break;
  2155. case LOOK_HAIR_COLOR:
  2156. vd->hair_color = val;
  2157. break;
  2158. case LOOK_CLOTHES_COLOR:
  2159. if (val && (
  2160. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2161. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2162. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2163. ))
  2164. val = 0;
  2165. vd->cloth_color = val;
  2166. break;
  2167. case LOOK_SHOES:
  2168. #if PACKETVER > 3
  2169. if (sd) {
  2170. int n;
  2171. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2172. if(sd->inventory_data[n]->view_id > 0)
  2173. val = sd->inventory_data[n]->view_id;
  2174. else
  2175. val = sd->status.inventory[n].nameid;
  2176. }
  2177. val = 0;
  2178. }
  2179. #endif
  2180. //Shoes? No packet uses this....
  2181. break;
  2182. }
  2183. #if PACKETVER < 4
  2184. WBUFW(buf,0)=0xc3;
  2185. WBUFL(buf,2)=bl->id;
  2186. WBUFB(buf,6)=type;
  2187. WBUFB(buf,7)=val;
  2188. clif_send(buf,packet_len(0xc3),bl,AREA);
  2189. #else
  2190. WBUFW(buf,0)=0x1d7;
  2191. WBUFL(buf,2)=bl->id;
  2192. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2193. WBUFB(buf,6)=LOOK_WEAPON;
  2194. WBUFW(buf,7)=vd->weapon;
  2195. WBUFW(buf,9)=vd->shield;
  2196. } else {
  2197. WBUFB(buf,6)=type;
  2198. WBUFW(buf,7)=val;
  2199. WBUFW(buf,9)=0;
  2200. }
  2201. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2202. #endif
  2203. }
  2204. //Sends a change-base-look packet required for traps as they are triggered.
  2205. void clif_changetraplook(struct block_list *bl,int val)
  2206. {
  2207. unsigned char buf[32];
  2208. #if PACKETVER < 4
  2209. WBUFW(buf,0)=0xc3;
  2210. WBUFL(buf,2)=bl->id;
  2211. WBUFB(buf,6)=LOOK_BASE;
  2212. WBUFB(buf,7)=val;
  2213. clif_send(buf,packet_len(0xc3),bl,AREA);
  2214. #else
  2215. WBUFW(buf,0)=0x1d7;
  2216. WBUFL(buf,2)=bl->id;
  2217. WBUFB(buf,6)=LOOK_BASE;
  2218. WBUFW(buf,7)=val;
  2219. WBUFW(buf,9)=0;
  2220. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2221. #endif
  2222. }
  2223. //For the stupid cloth-dye bug. Resends the given view data
  2224. //to the area specified by bl.
  2225. void clif_refreshlook(struct block_list *bl,int id,int type,int val,int area)
  2226. {
  2227. unsigned char buf[32];
  2228. #if PACKETVER < 4
  2229. WBUFW(buf,0)=0xc3;
  2230. WBUFL(buf,2)=id;
  2231. WBUFB(buf,6)=type;
  2232. WBUFB(buf,7)=val;
  2233. clif_send(buf,packet_len(0xc3),bl,area);
  2234. #else
  2235. WBUFW(buf,0)=0x1d7;
  2236. WBUFL(buf,2)=id;
  2237. WBUFB(buf,6)=type;
  2238. WBUFW(buf,7)=val;
  2239. WBUFW(buf,9)=0;
  2240. clif_send(buf,packet_len(0x1d7),bl,area);
  2241. #endif
  2242. return;
  2243. }
  2244. /*==========================================
  2245. *
  2246. *------------------------------------------*/
  2247. int clif_initialstatus(struct map_session_data *sd)
  2248. {
  2249. int fd;
  2250. unsigned char *buf;
  2251. nullpo_retr(0, sd);
  2252. fd=sd->fd;
  2253. WFIFOHEAD(fd,packet_len(0xbd));
  2254. buf=WFIFOP(fd,0);
  2255. WBUFW(buf,0)=0xbd;
  2256. WBUFW(buf,2)=min(sd->status.status_point, SHRT_MAX);
  2257. WBUFB(buf,4)=min(sd->status.str, UCHAR_MAX);
  2258. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2259. WBUFB(buf,6)=min(sd->status.agi, UCHAR_MAX);
  2260. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2261. WBUFB(buf,8)=min(sd->status.vit, UCHAR_MAX);
  2262. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2263. WBUFB(buf,10)=min(sd->status.int_, UCHAR_MAX);
  2264. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2265. WBUFB(buf,12)=min(sd->status.dex, UCHAR_MAX);
  2266. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2267. WBUFB(buf,14)=min(sd->status.luk, UCHAR_MAX);
  2268. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2269. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw.atk;
  2270. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2; //atk bonus
  2271. WBUFW(buf,20) = sd->battle_status.matk_max;
  2272. WBUFW(buf,22) = sd->battle_status.matk_min;
  2273. WBUFW(buf,24) = sd->battle_status.def; // def
  2274. WBUFW(buf,26) = sd->battle_status.def2;
  2275. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2276. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2277. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2278. WBUFW(buf,30) = fd;
  2279. fd = sd->fd;
  2280. WBUFW(buf,32) = sd->battle_status.hit;
  2281. WBUFW(buf,34) = sd->battle_status.flee;
  2282. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2283. WBUFW(buf,38) = sd->battle_status.cri/10;
  2284. WBUFW(buf,40) = sd->status.karma;
  2285. WBUFW(buf,42) = sd->status.manner;
  2286. WFIFOSET(fd,packet_len(0xbd));
  2287. clif_updatestatus(sd,SP_STR);
  2288. clif_updatestatus(sd,SP_AGI);
  2289. clif_updatestatus(sd,SP_VIT);
  2290. clif_updatestatus(sd,SP_INT);
  2291. clif_updatestatus(sd,SP_DEX);
  2292. clif_updatestatus(sd,SP_LUK);
  2293. clif_updatestatus(sd,SP_ATTACKRANGE);
  2294. clif_updatestatus(sd,SP_ASPD);
  2295. return 0;
  2296. }
  2297. /*==========================================
  2298. *矢装備
  2299. *------------------------------------------*/
  2300. int clif_arrowequip(struct map_session_data *sd,int val)
  2301. {
  2302. int fd;
  2303. nullpo_retr(0, sd);
  2304. pc_stop_attack(sd); // [Valaris]
  2305. fd=sd->fd;
  2306. WFIFOHEAD(fd, packet_len(0x013c));
  2307. WFIFOW(fd,0)=0x013c;
  2308. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2309. WFIFOSET(fd,packet_len(0x013c));
  2310. return 0;
  2311. }
  2312. /// Ammunition action message.
  2313. /// type=0 : MsgStringTable[242]="Please equip the proper ammunition first."
  2314. /// type=1 : MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2315. /// type=2 : MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2316. /// type=3 : assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2317. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2318. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2319. int clif_arrow_fail(struct map_session_data *sd,int type)
  2320. {
  2321. int fd;
  2322. nullpo_retr(0, sd);
  2323. fd=sd->fd;
  2324. WFIFOHEAD(fd, packet_len(0x013b));
  2325. WFIFOW(fd,0)=0x013b;
  2326. WFIFOW(fd,2)=type;
  2327. WFIFOSET(fd,packet_len(0x013b));
  2328. return 0;
  2329. }
  2330. /*==========================================
  2331. * 作成可能 矢リスト送信
  2332. *------------------------------------------*/
  2333. int clif_arrow_create_list(struct map_session_data *sd)
  2334. {
  2335. int i, c, j;
  2336. int fd;
  2337. nullpo_retr(0, sd);
  2338. fd = sd->fd;
  2339. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2340. WFIFOW(fd,0) = 0x1ad;
  2341. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2342. if (skill_arrow_db[i].nameid > 0 &&
  2343. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2344. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2345. {
  2346. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2347. WFIFOW(fd,c*2+4) = j;
  2348. else
  2349. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2350. c++;
  2351. }
  2352. }
  2353. WFIFOW(fd,2) = c*2+4;
  2354. WFIFOSET(fd, WFIFOW(fd,2));
  2355. if (c > 0) {
  2356. sd->menuskill_id = AC_MAKINGARROW;
  2357. sd->menuskill_val = c;
  2358. }
  2359. return 0;
  2360. }
  2361. /*==========================================
  2362. *
  2363. *------------------------------------------*/
  2364. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2365. {
  2366. int fd;
  2367. nullpo_retr(0, sd);
  2368. fd=sd->fd;
  2369. WFIFOHEAD(fd,packet_len(0xbc));
  2370. WFIFOW(fd,0)=0xbc;
  2371. WFIFOW(fd,2)=type;
  2372. WFIFOB(fd,4)=ok;
  2373. WFIFOB(fd,5)=val;
  2374. WFIFOSET(fd,packet_len(0xbc));
  2375. return 0;
  2376. }
  2377. /*==========================================
  2378. *
  2379. *------------------------------------------*/
  2380. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2381. {
  2382. int fd;
  2383. nullpo_retr(0, sd);
  2384. fd=sd->fd;
  2385. WFIFOHEAD(fd,packet_len(0xaa));
  2386. WFIFOW(fd,0)=0xaa;
  2387. WFIFOW(fd,2)=n+2;
  2388. WFIFOW(fd,4)=pos;
  2389. WFIFOB(fd,6)=ok;
  2390. WFIFOSET(fd,packet_len(0xaa));
  2391. return 0;
  2392. }
  2393. /*==========================================
  2394. *
  2395. *------------------------------------------*/
  2396. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2397. {
  2398. int fd;
  2399. nullpo_retr(0, sd);
  2400. fd=sd->fd;
  2401. WFIFOHEAD(fd,packet_len(0xac));
  2402. WFIFOW(fd,0)=0xac;
  2403. WFIFOW(fd,2)=n+2;
  2404. WFIFOW(fd,4)=pos;
  2405. WFIFOB(fd,6)=ok;
  2406. WFIFOSET(fd,packet_len(0xac));
  2407. return 0;
  2408. }
  2409. /*==========================================
  2410. *
  2411. *------------------------------------------*/
  2412. int clif_misceffect(struct block_list* bl,int type)
  2413. {
  2414. unsigned char buf[32];
  2415. nullpo_retr(0, bl);
  2416. WBUFW(buf,0) = 0x19b;
  2417. WBUFL(buf,2) = bl->id;
  2418. WBUFL(buf,6) = type;
  2419. clif_send(buf,packet_len(0x19b),bl,AREA);
  2420. return 0;
  2421. }
  2422. int clif_misceffect2(struct block_list *bl, int type)
  2423. {
  2424. unsigned char buf[24];
  2425. nullpo_retr(0, bl);
  2426. memset(buf, 0, packet_len(0x1f3));
  2427. WBUFW(buf,0) = 0x1f3;
  2428. WBUFL(buf,2) = bl->id;
  2429. WBUFL(buf,6) = type;
  2430. clif_send(buf, packet_len(0x1f3), bl, AREA);
  2431. return 0;
  2432. }
  2433. /*==========================================
  2434. * 表示オプション変更
  2435. *------------------------------------------*/
  2436. int clif_changeoption(struct block_list* bl)
  2437. {
  2438. unsigned char buf[32];
  2439. struct status_change *sc;
  2440. nullpo_retr(0, bl);
  2441. sc = status_get_sc(bl);
  2442. if (!sc) return 0; //How can an option change if there's no sc?
  2443. #if PACKETVER >= 7
  2444. WBUFW(buf,0) = 0x229;
  2445. WBUFL(buf,2) = bl->id;
  2446. WBUFW(buf,6) = sc->opt1;
  2447. WBUFW(buf,8) = sc->opt2;
  2448. WBUFL(buf,10) = sc->option;
  2449. WBUFB(buf,14) = 0; // PK???
  2450. if(disguised(bl)) {
  2451. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2452. WBUFL(buf,2) = -bl->id;
  2453. clif_send(buf,packet_len(0x229),bl,SELF);
  2454. WBUFL(buf,2) = bl->id;
  2455. WBUFL(buf,10) = OPTION_INVISIBLE;
  2456. clif_send(buf,packet_len(0x229),bl,SELF);
  2457. } else
  2458. clif_send(buf,packet_len(0x229),bl,AREA);
  2459. #else
  2460. WBUFW(buf,0) = 0x119;
  2461. WBUFL(buf,2) = bl->id;
  2462. WBUFW(buf,6) = sc->opt1;
  2463. WBUFW(buf,8) = sc->opt2;
  2464. WBUFW(buf,10) = sc->option;
  2465. WBUFB(buf,12) = 0; // ??
  2466. if(disguised(bl)) {
  2467. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2468. WBUFL(buf,2) = -bl->id;
  2469. clif_send(buf,packet_len(0x119),bl,SELF);
  2470. WBUFL(buf,2) = bl->id;
  2471. WBUFW(buf,10) = OPTION_INVISIBLE;
  2472. clif_send(buf,packet_len(0x119),bl,SELF);
  2473. } else
  2474. clif_send(buf,packet_len(0x119),bl,AREA);
  2475. #endif
  2476. return 0;
  2477. }
  2478. int clif_changeoption2(struct block_list* bl)
  2479. {
  2480. unsigned char buf[20];
  2481. struct status_change *sc;
  2482. sc = status_get_sc(bl);
  2483. if (!sc) return 0; //How can an option change if there's no sc?
  2484. WBUFW(buf,0) = 0x28a;
  2485. WBUFL(buf,2) = bl->id;
  2486. WBUFL(buf,6) = sc->option;
  2487. WBUFL(buf,10) = clif_setlevel(status_get_lv(bl));
  2488. WBUFL(buf,14) = sc->opt3;
  2489. if(disguised(bl)) {
  2490. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  2491. WBUFL(buf,2) = -bl->id;
  2492. clif_send(buf,packet_len(0x28a),bl,SELF);
  2493. WBUFL(buf,2) = bl->id;
  2494. WBUFL(buf,6) = OPTION_INVISIBLE;
  2495. clif_send(buf,packet_len(0x28a),bl,SELF);
  2496. } else
  2497. clif_send(buf,packet_len(0x28a),bl,AREA);
  2498. return 0;
  2499. }
  2500. /*==========================================
  2501. *
  2502. *------------------------------------------*/
  2503. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2504. {
  2505. nullpo_retr(0, sd);
  2506. if(!ok) {
  2507. int fd=sd->fd;
  2508. WFIFOHEAD(fd,packet_len(0xa8));
  2509. WFIFOW(fd,0)=0xa8;
  2510. WFIFOW(fd,2)=index+2;
  2511. WFIFOW(fd,4)=amount;
  2512. WFIFOB(fd,6)=ok;
  2513. WFIFOSET(fd,packet_len(0xa8));
  2514. }
  2515. else {
  2516. #if PACKETVER < 3
  2517. int fd=sd->fd;
  2518. WFIFOHEAD(fd,packet_len(0xa8));
  2519. WFIFOW(fd,0)=0xa8;
  2520. WFIFOW(fd,2)=index+2;
  2521. WFIFOW(fd,4)=amount;
  2522. WFIFOB(fd,6)=ok;
  2523. WFIFOSET(fd,packet_len(0xa8));
  2524. #else
  2525. unsigned char buf[32];
  2526. WBUFW(buf,0)=0x1c8;
  2527. WBUFW(buf,2)=index+2;
  2528. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2529. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2530. else
  2531. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2532. WBUFL(buf,6)=sd->bl.id;
  2533. WBUFW(buf,10)=amount;
  2534. WBUFB(buf,12)=ok;
  2535. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2536. #endif
  2537. }
  2538. return 0;
  2539. }
  2540. /*==========================================
  2541. * Inform client whether chatroom creation was successful or not
  2542. * R 00d6 <fail>.B
  2543. *------------------------------------------*/
  2544. void clif_createchat(struct map_session_data* sd, int fail)
  2545. {
  2546. int fd;
  2547. nullpo_retv(sd);
  2548. fd = sd->fd;
  2549. WFIFOHEAD(fd,packet_len(0xd6));
  2550. WFIFOW(fd,0) = 0xd6;
  2551. WFIFOB(fd,2) = fail;
  2552. WFIFOSET(fd,packet_len(0xd6));
  2553. }
  2554. /*==========================================
  2555. * Display a chat above the owner
  2556. * R 00d7 <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <type>.B <title>.?B
  2557. *------------------------------------------*/
  2558. int clif_dispchat(struct chat_data* cd, int fd)
  2559. {
  2560. unsigned char buf[128];
  2561. uint8 type;
  2562. if( cd == NULL || cd->owner == NULL )
  2563. return 1;
  2564. // type - 0: private, 1: public, 2: npc, 3: non-clickable
  2565. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  2566. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  2567. : 1;
  2568. WBUFW(buf, 0) = 0xd7;
  2569. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2570. WBUFL(buf, 4) = cd->owner->id;
  2571. WBUFL(buf, 8) = cd->bl.id;
  2572. WBUFW(buf,12) = cd->limit;
  2573. WBUFW(buf,14) = cd->users;
  2574. WBUFB(buf,16) = type;
  2575. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2576. if( fd ) {
  2577. WFIFOHEAD(fd,WBUFW(buf,2));
  2578. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2579. WFIFOSET(fd,WBUFW(buf,2));
  2580. } else {
  2581. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  2582. }
  2583. return 0;
  2584. }
  2585. /*==========================================
  2586. * Chatroom properties adjustment
  2587. * R 00df <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <pub>.B <title>.?B
  2588. *------------------------------------------*/
  2589. int clif_changechatstatus(struct chat_data* cd)
  2590. {
  2591. unsigned char buf[128];
  2592. if( cd == NULL || cd->usersd[0] == NULL )
  2593. return 1;
  2594. WBUFW(buf, 0) = 0xdf;
  2595. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2596. WBUFL(buf, 4) = cd->usersd[0]->bl.id;
  2597. WBUFL(buf, 8) = cd->bl.id;
  2598. WBUFW(buf,12) = cd->limit;
  2599. WBUFW(buf,14) = cd->users;
  2600. WBUFB(buf,16) = cd->pub;
  2601. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2602. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2603. return 0;
  2604. }
  2605. /*==========================================
  2606. *
  2607. *------------------------------------------*/
  2608. int clif_clearchat(struct chat_data *cd,int fd)
  2609. {
  2610. unsigned char buf[32];
  2611. nullpo_retr(0, cd);
  2612. WBUFW(buf,0) = 0xd8;
  2613. WBUFL(buf,2) = cd->bl.id;
  2614. if( fd ) {
  2615. WFIFOHEAD(fd,packet_len(0xd8));
  2616. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2617. WFIFOSET(fd,packet_len(0xd8));
  2618. } else {
  2619. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  2620. }
  2621. return 0;
  2622. }
  2623. /*==========================================
  2624. *
  2625. *------------------------------------------*/
  2626. int clif_joinchatfail(struct map_session_data *sd,int fail)
  2627. {
  2628. int fd;
  2629. nullpo_retr(0, sd);
  2630. fd = sd->fd;
  2631. WFIFOHEAD(fd,packet_len(0xda));
  2632. WFIFOW(fd,0) = 0xda;
  2633. WFIFOB(fd,2) = fail;
  2634. WFIFOSET(fd,packet_len(0xda));
  2635. return 0;
  2636. }
  2637. /*==========================================
  2638. *
  2639. *------------------------------------------*/
  2640. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2641. {
  2642. int fd;
  2643. int i;
  2644. nullpo_retr(0, sd);
  2645. nullpo_retr(0, cd);
  2646. fd = sd->fd;
  2647. if (!session_isActive(fd))
  2648. return 0;
  2649. WFIFOHEAD(fd, 8 + (28*cd->users));
  2650. WFIFOW(fd, 0) = 0xdb;
  2651. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2652. WFIFOL(fd, 4) = cd->bl.id;
  2653. for (i = 0; i < cd->users; i++) {
  2654. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  2655. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2656. }
  2657. WFIFOSET(fd, WFIFOW(fd, 2));
  2658. return 0;
  2659. }
  2660. /*==========================================
  2661. *
  2662. *------------------------------------------*/
  2663. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2664. {
  2665. unsigned char buf[32];
  2666. nullpo_retr(0, sd);
  2667. nullpo_retr(0, cd);
  2668. WBUFW(buf, 0) = 0x0dc;
  2669. WBUFW(buf, 2) = cd->users;
  2670. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2671. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  2672. return 0;
  2673. }
  2674. /*==========================================
  2675. * Announce the new owner
  2676. * R 00e1 <index>.l <nick>.24B
  2677. *------------------------------------------*/
  2678. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  2679. {
  2680. unsigned char buf[64];
  2681. nullpo_retv(sd);
  2682. nullpo_retv(cd);
  2683. //FIXME: this announces a swap between positions 0 and 1 (probably not what we want) [ultramage]
  2684. //FIXME: aegis sends obviously incorrect packets; need to figure out what to send to display it correctly :X
  2685. //TODO: is it just owner swap, or can it do general-purpose reordering?
  2686. WBUFW(buf, 0) = 0xe1;
  2687. WBUFL(buf, 2) = 1;
  2688. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2689. WBUFW(buf,30) = 0xe1;
  2690. WBUFL(buf,32) = 0;
  2691. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2692. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  2693. }
  2694. /*==========================================
  2695. * Notify about user leaving the chatroom
  2696. * R 00dd <index>.w <nick>.24B <flag>.B
  2697. *------------------------------------------*/
  2698. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  2699. {
  2700. unsigned char buf[32];
  2701. nullpo_retv(sd);
  2702. nullpo_retv(cd);
  2703. WBUFW(buf, 0) = 0xdd;
  2704. WBUFW(buf, 2) = cd->users-1;
  2705. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2706. WBUFB(buf,28) = flag; // 0: left, 1: was kicked
  2707. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  2708. }
  2709. /*==========================================
  2710. * Opens a trade request window from char 'name'
  2711. * R 00e5 <nick>.24B
  2712. * R 01f4 <nick>.24B <charid>.L <baselvl>.W
  2713. *------------------------------------------*/
  2714. void clif_traderequest(struct map_session_data* sd, const char* name)
  2715. {
  2716. int fd = sd->fd;
  2717. #if PACKETVER < 6
  2718. WFIFOHEAD(fd,packet_len(0xe5));
  2719. WFIFOW(fd,0) = 0xe5;
  2720. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2721. WFIFOSET(fd,packet_len(0xe5));
  2722. #else
  2723. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2724. if( !tsd ) return;
  2725. WFIFOHEAD(fd,packet_len(0x1f4));
  2726. WFIFOW(fd,0) = 0x1f4;
  2727. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2728. WFIFOL(fd,26) = tsd->status.char_id;
  2729. WFIFOW(fd,30) = clif_setlevel(tsd->status.base_level);
  2730. WFIFOSET(fd,packet_len(0x1f4));
  2731. #endif
  2732. }
  2733. /*==========================================
  2734. * Reply to a trade-request.
  2735. * R 00e7 <type>.B
  2736. * R 01f5 <type>.B <charid>.L <baselvl>.W
  2737. * Type:
  2738. * 0: Char is too far
  2739. * 1: Character does not exist
  2740. * 2: Trade failed
  2741. * 3: Accept
  2742. * 4: Cancel
  2743. *------------------------------------------*/
  2744. void clif_tradestart(struct map_session_data* sd, uint8 type)
  2745. {
  2746. int fd = sd->fd;
  2747. #if PACKETVER < 6
  2748. WFIFOHEAD(fd,packet_len(0xe7));
  2749. WFIFOW(fd,0) = 0xe7;
  2750. WFIFOB(fd,2) = type;
  2751. WFIFOSET(fd,packet_len(0xe7));
  2752. #else
  2753. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2754. if( !tsd ) return;
  2755. WFIFOHEAD(fd,packet_len(0x1f5));
  2756. WFIFOW(fd,0) = 0x1f5;
  2757. WFIFOB(fd,2) = type;
  2758. WFIFOL(fd,3) = tsd->status.char_id;
  2759. WFIFOW(fd,7) = clif_setlevel(tsd->status.base_level);
  2760. WFIFOSET(fd,packet_len(0x1f5));
  2761. #endif
  2762. }
  2763. /*==========================================
  2764. * 相手方からのアイテム追加
  2765. *------------------------------------------*/
  2766. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  2767. {
  2768. int fd;
  2769. nullpo_retv(sd);
  2770. nullpo_retv(tsd);
  2771. fd = tsd->fd;
  2772. WFIFOHEAD(fd,packet_len(0xe9));
  2773. WFIFOW(fd,0) = 0xe9;
  2774. WFIFOL(fd,2) = amount;
  2775. if( index == 0 )
  2776. {
  2777. WFIFOW(fd,6) = 0; // type id
  2778. WFIFOB(fd,8) = 0; //identify flag
  2779. WFIFOB(fd,9) = 0; // attribute
  2780. WFIFOB(fd,10)= 0; //refine
  2781. WFIFOW(fd,11)= 0; //card (4w)
  2782. WFIFOW(fd,13)= 0; //card (4w)
  2783. WFIFOW(fd,15)= 0; //card (4w)
  2784. WFIFOW(fd,17)= 0; //card (4w)
  2785. }
  2786. else
  2787. {
  2788. index -= 2; //index fix
  2789. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2790. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  2791. else
  2792. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  2793. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  2794. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  2795. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  2796. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  2797. }
  2798. WFIFOSET(fd,packet_len(0xe9));
  2799. }
  2800. /*==========================================
  2801. * アイテム追加成功/失敗
  2802. *------------------------------------------*/
  2803. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  2804. {
  2805. int fd;
  2806. nullpo_retv(sd);
  2807. fd = sd->fd;
  2808. WFIFOHEAD(fd,packet_len(0xea));
  2809. WFIFOW(fd,0) = 0xea;
  2810. WFIFOW(fd,2) = index;
  2811. WFIFOB(fd,4) = fail;
  2812. WFIFOSET(fd,packet_len(0xea));
  2813. }
  2814. /*==========================================
  2815. * 取り引きok押し
  2816. *------------------------------------------*/
  2817. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  2818. {
  2819. int fd;
  2820. nullpo_retv(sd);
  2821. fd = sd->fd;
  2822. WFIFOHEAD(fd,packet_len(0xec));
  2823. WFIFOW(fd,0) = 0xec;
  2824. WFIFOB(fd,2) = fail; // 0=you 1=the other person
  2825. WFIFOSET(fd,packet_len(0xec));
  2826. }
  2827. /*==========================================
  2828. * 取り引きがキャンセルされました
  2829. *------------------------------------------*/
  2830. void clif_tradecancelled(struct map_session_data* sd)
  2831. {
  2832. int fd;
  2833. nullpo_retv(sd);
  2834. fd = sd->fd;
  2835. WFIFOHEAD(fd,packet_len(0xee));
  2836. WFIFOW(fd,0) = 0xee;
  2837. WFIFOSET(fd,packet_len(0xee));
  2838. }
  2839. /*==========================================
  2840. * 取り引き完了
  2841. *------------------------------------------*/
  2842. void clif_tradecompleted(struct map_session_data* sd, int fail)
  2843. {
  2844. int fd;
  2845. nullpo_retv(sd);
  2846. fd = sd->fd;
  2847. WFIFOHEAD(fd,packet_len(0xf0));
  2848. WFIFOW(fd,0) = 0xf0;
  2849. WFIFOB(fd,2) = fail;
  2850. WFIFOSET(fd,packet_len(0xf0));
  2851. }
  2852. /*==========================================
  2853. * カプラ倉庫のアイテム数を更新
  2854. *------------------------------------------*/
  2855. int clif_updatestorageamount(struct map_session_data *sd,struct storage *stor)
  2856. {
  2857. int fd;
  2858. nullpo_retr(0, sd);
  2859. nullpo_retr(0, stor);
  2860. fd=sd->fd;
  2861. WFIFOHEAD(fd,packet_len(0xf2));
  2862. WFIFOW(fd,0) = 0xf2; // update storage amount
  2863. WFIFOW(fd,2) = stor->storage_amount; //items
  2864. WFIFOW(fd,4) = MAX_STORAGE; //items max
  2865. WFIFOSET(fd,packet_len(0xf2));
  2866. return 0;
  2867. }
  2868. /*==========================================
  2869. * カプラ倉庫にアイテムを追加する
  2870. *------------------------------------------*/
  2871. int clif_storageitemadded(struct map_session_data *sd,struct storage *stor,int index,int amount)
  2872. {
  2873. int view,fd;
  2874. nullpo_retr(0, sd);
  2875. nullpo_retr(0, stor);
  2876. fd=sd->fd;
  2877. WFIFOHEAD(fd,packet_len(0xf4));
  2878. WFIFOW(fd,0) =0xf4; // Storage item added
  2879. WFIFOW(fd,2) =index+1; // index
  2880. WFIFOL(fd,4) =amount; // amount
  2881. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  2882. WFIFOW(fd,8) =view;
  2883. else
  2884. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  2885. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  2886. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  2887. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  2888. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  2889. WFIFOSET(fd,packet_len(0xf4));
  2890. return 0;
  2891. }
  2892. /*==========================================
  2893. *
  2894. *------------------------------------------*/
  2895. int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor)
  2896. {
  2897. int fd;
  2898. nullpo_retr(0, sd);
  2899. nullpo_retr(0, stor);
  2900. fd=sd->fd;
  2901. WFIFOHEAD(fd,packet_len(0xf2));
  2902. WFIFOW(fd,0) = 0xf2; // update storage amount
  2903. WFIFOW(fd,2) = stor->storage_amount; //items
  2904. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  2905. WFIFOSET(fd,packet_len(0xf2));
  2906. return 0;
  2907. }
  2908. /*==========================================
  2909. *
  2910. *------------------------------------------*/
  2911. int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount)
  2912. {
  2913. int view,fd;
  2914. nullpo_retr(0, sd);
  2915. nullpo_retr(0, stor);
  2916. fd=sd->fd;
  2917. WFIFOHEAD(fd,packet_len(0xf4));
  2918. WFIFOW(fd,0) =0xf4; // Storage item added
  2919. WFIFOW(fd,2) =index+1; // index
  2920. WFIFOL(fd,4) =amount; // amount
  2921. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  2922. WFIFOW(fd,8) =view;
  2923. else
  2924. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  2925. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  2926. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  2927. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  2928. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  2929. WFIFOSET(fd,packet_len(0xf4));
  2930. return 0;
  2931. }
  2932. /*==========================================
  2933. * カプラ倉庫からアイテムを取り去る
  2934. *------------------------------------------*/
  2935. int clif_storageitemremoved(struct map_session_data *sd,int index,int amount)
  2936. {
  2937. int fd;
  2938. nullpo_retr(0, sd);
  2939. fd=sd->fd;
  2940. WFIFOHEAD(fd,packet_len(0xf6));
  2941. WFIFOW(fd,0)=0xf6; // Storage item removed
  2942. WFIFOW(fd,2)=index+1;
  2943. WFIFOL(fd,4)=amount;
  2944. WFIFOSET(fd,packet_len(0xf6));
  2945. return 0;
  2946. }
  2947. /*==========================================
  2948. * カプラ倉庫を閉じる
  2949. *------------------------------------------*/
  2950. int clif_storageclose(struct map_session_data *sd)
  2951. {
  2952. int fd;
  2953. nullpo_retr(0, sd);
  2954. fd=sd->fd;
  2955. WFIFOHEAD(fd,packet_len(0xf8));
  2956. WFIFOW(fd,0)=0xf8; // Storage Closed
  2957. WFIFOSET(fd,packet_len(0xf8));
  2958. return 0;
  2959. }
  2960. /*==========================================
  2961. * PC表示
  2962. *------------------------------------------*/
  2963. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  2964. {
  2965. int gmlvl;
  2966. int i;
  2967. if(dstsd->chatID)
  2968. {
  2969. struct chat_data *cd;
  2970. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  2971. if(cd && cd->usersd[0]==dstsd)
  2972. clif_dispchat(cd,sd->fd);
  2973. }
  2974. if(dstsd->vender_id)
  2975. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  2976. if(dstsd->spiritball > 0)
  2977. clif_spiritball_single(sd->fd, dstsd);
  2978. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  2979. (battle_config.disp_hpmeter && (gmlvl = pc_isGM(sd)) >= battle_config.disp_hpmeter && gmlvl >= pc_isGM(dstsd))
  2980. )
  2981. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  2982. // display links to devoted chars for crusader
  2983. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  2984. if( i < 5 ) clif_devotion(sd, sd);
  2985. // display links to devoted chars for others
  2986. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  2987. if( i < 5 ) clif_devotion(dstsd, sd);
  2988. // pvp circle for duel [LuzZza]
  2989. //if(dstsd->duel_group)
  2990. // clif_specialeffect(&dstsd->bl, 159, 4);
  2991. }
  2992. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  2993. {
  2994. uint8 buf[128];
  2995. struct unit_data *ud;
  2996. struct view_data *vd;
  2997. int len;
  2998. vd = status_get_viewdata(bl);
  2999. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3000. return;
  3001. ud = unit_bl2ud(bl);
  3002. len = ( ud && ud->walktimer != -1 ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3003. clif_send(buf,len,&sd->bl,SELF);
  3004. if (vd->cloth_color)
  3005. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3006. switch (bl->type)
  3007. {
  3008. case BL_PC:
  3009. {
  3010. TBL_PC* tsd = (TBL_PC*)bl;
  3011. clif_getareachar_pc(sd, tsd);
  3012. if(tsd->state.size==2) // tiny/big players [Valaris]
  3013. clif_specialeffect_single(bl,423,sd->fd);
  3014. else if(tsd->state.size==1)
  3015. clif_specialeffect_single(bl,421,sd->fd);
  3016. }
  3017. break;
  3018. case BL_NPC:
  3019. {
  3020. TBL_NPC* nd = (TBL_NPC*)bl;
  3021. if( nd->chat_id )
  3022. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3023. }
  3024. break;
  3025. case BL_MOB:
  3026. {
  3027. TBL_MOB* md = (TBL_MOB*)bl;
  3028. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3029. clif_specialeffect_single(bl,423,sd->fd);
  3030. else if(md->special_state.size==1)
  3031. clif_specialeffect_single(bl,421,sd->fd);
  3032. }
  3033. break;
  3034. case BL_PET:
  3035. if (vd->head_bottom)
  3036. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3037. break;
  3038. }
  3039. }
  3040. //Modifies the type of damage according to status changes [Skotlex]
  3041. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3042. #define clif_calc_delay(type,div,damage,delay) ((delay)==0&&(damage)>0?((div)>1?9:4):type)
  3043. /*==========================================
  3044. * Estimates walk delay based on the damage criteria. [Skotlex]
  3045. *------------------------------------------*/
  3046. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3047. {
  3048. if (type == 4 || type == 9 || damage <=0)
  3049. return 0;
  3050. if (bl->type == BL_PC) {
  3051. if (battle_config.pc_walk_delay_rate != 100)
  3052. delay = delay*battle_config.pc_walk_delay_rate/100;
  3053. } else
  3054. if (battle_config.walk_delay_rate != 100)
  3055. delay = delay*battle_config.walk_delay_rate/100;
  3056. if (div_ > 1) //Multi-hit skills mean higher delays.
  3057. delay += battle_config.multihit_delay*(div_-1);
  3058. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3059. }
  3060. /*==========================================
  3061. * Sends a 'damage' packet (src performs action on dst)
  3062. * R 008a <src ID>.l <dst ID>.l <server tick>.l <src speed>.l <dst speed>.l <param1>.w <param2>.w <type>.B <param3>.w
  3063. *
  3064. * type=00 damage [param1: total damage, param2: div, param3: assassin dual-wield damage]
  3065. * type=01 pick up item
  3066. * type=02 sit down
  3067. * type=03 stand up
  3068. * type=04 reflected/absorbed damage?
  3069. * type=08 double attack
  3070. * type=09 don't display flinch animation (endure)
  3071. * type=0a critical hit
  3072. * type=0b lucky dodge
  3073. *------------------------------------------*/
  3074. 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)
  3075. {
  3076. unsigned char buf[256];
  3077. struct status_change *sc;
  3078. nullpo_retr(0, src);
  3079. nullpo_retr(0, dst);
  3080. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3081. sc = status_get_sc(dst);
  3082. if(sc && sc->count) {
  3083. if(sc->data[SC_HALLUCINATION]) {
  3084. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3085. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3086. }
  3087. }
  3088. WBUFW(buf,0)=0x8a;
  3089. WBUFL(buf,2)=src->id;
  3090. WBUFL(buf,6)=dst->id;
  3091. WBUFL(buf,10)=tick;
  3092. WBUFL(buf,14)=sdelay;
  3093. WBUFL(buf,18)=ddelay;
  3094. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3095. WBUFW(buf,22)=damage?div:0;
  3096. WBUFW(buf,27)=damage2?div:0;
  3097. } else {
  3098. WBUFW(buf,22)=min(damage, SHRT_MAX);
  3099. WBUFW(buf,27)=damage2;
  3100. }
  3101. WBUFW(buf,24)=div;
  3102. WBUFB(buf,26)=type;
  3103. if(disguised(dst)) {
  3104. clif_send(buf,packet_len(0x8a),dst,AREA_WOS);
  3105. WBUFL(buf,6) = -dst->id;
  3106. clif_send(buf,packet_len(0x8a),dst,SELF);
  3107. } else
  3108. clif_send(buf,packet_len(0x8a),dst,AREA);
  3109. if(disguised(src)) {
  3110. WBUFL(buf,2) = -src->id;
  3111. if (disguised(dst))
  3112. WBUFL(buf,6) = dst->id;
  3113. if(damage > 0) WBUFW(buf,22) = -1;
  3114. if(damage2 > 0) WBUFW(buf,27) = -1;
  3115. clif_send(buf,packet_len(0x8a),src,SELF);
  3116. }
  3117. //Return adjusted can't walk delay for further processing.
  3118. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3119. }
  3120. /*==========================================
  3121. * src picks up dst
  3122. *------------------------------------------*/
  3123. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3124. {
  3125. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3126. unsigned char buf[32];
  3127. nullpo_retv(src);
  3128. nullpo_retv(dst);
  3129. WBUFW(buf, 0) = 0x8a;
  3130. WBUFL(buf, 2) = src->id;
  3131. WBUFL(buf, 6) = dst->id;
  3132. WBUFB(buf,26) = 1;
  3133. clif_send(buf, packet_len(0x8a), src, AREA);
  3134. }
  3135. /*==========================================
  3136. * inform clients in area that `bl` is sitting
  3137. *------------------------------------------*/
  3138. void clif_sitting(struct block_list* bl)
  3139. {
  3140. unsigned char buf[32];
  3141. nullpo_retv(bl);
  3142. WBUFW(buf, 0) = 0x8a;
  3143. WBUFL(buf, 2) = bl->id;
  3144. WBUFB(buf,26) = 2;
  3145. clif_send(buf, packet_len(0x8a), bl, AREA);
  3146. if(disguised(bl)) {
  3147. WBUFL(buf, 2) = - bl->id;
  3148. clif_send(buf, packet_len(0x8a), bl, SELF);
  3149. }
  3150. }
  3151. /*==========================================
  3152. * inform clients in area that `bl` is standing
  3153. *------------------------------------------*/
  3154. void clif_standing(struct block_list* bl)
  3155. {
  3156. unsigned char buf[32];
  3157. nullpo_retv(bl);
  3158. WBUFW(buf, 0) = 0x8a;
  3159. WBUFL(buf, 2) = bl->id;
  3160. WBUFB(buf,26) = 3;
  3161. clif_send(buf, packet_len(0x8a), bl, AREA);
  3162. if(disguised(bl)) {
  3163. WBUFL(buf, 2) = - bl->id;
  3164. clif_send(buf, packet_len(0x8a), bl, SELF);
  3165. }
  3166. }
  3167. /*==========================================
  3168. * Inform client(s) about a map-cell change
  3169. *------------------------------------------*/
  3170. void clif_changemapcell(int fd, int m, int x, int y, int type, enum send_target target)
  3171. {
  3172. unsigned char buf[32];
  3173. WBUFW(buf,0) = 0x192;
  3174. WBUFW(buf,2) = x;
  3175. WBUFW(buf,4) = y;
  3176. WBUFW(buf,6) = type;
  3177. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3178. if( fd )
  3179. {
  3180. WFIFOHEAD(fd,packet_len(0x192));
  3181. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3182. WFIFOSET(fd,packet_len(0x192));
  3183. }
  3184. else
  3185. {
  3186. struct block_list dummy_bl;
  3187. dummy_bl.type = BL_NUL;
  3188. dummy_bl.x = x;
  3189. dummy_bl.y = y;
  3190. dummy_bl.m = m;
  3191. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3192. }
  3193. }
  3194. /*==========================================
  3195. *
  3196. *------------------------------------------*/
  3197. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3198. {
  3199. int view,fd;
  3200. fd=sd->fd;
  3201. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3202. WFIFOHEAD(fd,packet_len(0x9d));
  3203. WFIFOW(fd,0)=0x9d;
  3204. WFIFOL(fd,2)=fitem->bl.id;
  3205. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3206. WFIFOW(fd,6)=view;
  3207. else
  3208. WFIFOW(fd,6)=fitem->item_data.nameid;
  3209. WFIFOB(fd,8)=fitem->item_data.identify;
  3210. WFIFOW(fd,9)=fitem->bl.x;
  3211. WFIFOW(fd,11)=fitem->bl.y;
  3212. WFIFOW(fd,13)=fitem->item_data.amount;
  3213. WFIFOB(fd,15)=fitem->subx;
  3214. WFIFOB(fd,16)=fitem->suby;
  3215. WFIFOSET(fd,packet_len(0x9d));
  3216. }
  3217. /*==========================================
  3218. * 場所スキルエフェクトが視界に入る
  3219. *------------------------------------------*/
  3220. static void clif_getareachar_skillunit(struct map_session_data *sd, struct skill_unit *unit)
  3221. {
  3222. int fd = sd->fd;
  3223. #if PACKETVER >= 3
  3224. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3225. WFIFOHEAD(fd,packet_len(0x1c9));
  3226. WFIFOW(fd, 0)=0x1c9;
  3227. WFIFOL(fd, 2)=unit->bl.id;
  3228. WFIFOL(fd, 6)=unit->group->src_id;
  3229. WFIFOW(fd,10)=unit->bl.x;
  3230. WFIFOW(fd,12)=unit->bl.y;
  3231. WFIFOB(fd,14)=unit->group->unit_id;
  3232. WFIFOB(fd,15)=1;
  3233. WFIFOB(fd,16)=1;
  3234. safestrncpy((char*)WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3235. WFIFOSET(fd,packet_len(0x1c9));
  3236. return;
  3237. }
  3238. #endif
  3239. WFIFOHEAD(fd,packet_len(0x11f));
  3240. WFIFOW(fd, 0)=0x11f;
  3241. WFIFOL(fd, 2)=unit->bl.id;
  3242. WFIFOL(fd, 6)=unit->group->src_id;
  3243. WFIFOW(fd,10)=unit->bl.x;
  3244. WFIFOW(fd,12)=unit->bl.y;
  3245. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3246. WFIFOB(fd,14)=UNT_ATTACK_SKILLS; //Use invisible unit id for traps.
  3247. else
  3248. WFIFOB(fd,14)=unit->group->unit_id;
  3249. WFIFOB(fd,15)=1; // ignored by client (always gets set to 1)
  3250. WFIFOSET(fd,packet_len(0x11f));
  3251. if(unit->group->skill_id == WZ_ICEWALL)
  3252. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  3253. }
  3254. /*==========================================
  3255. * 場所スキルエフェクトが視界から消える
  3256. *------------------------------------------*/
  3257. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3258. {
  3259. nullpo_retv(unit);
  3260. WFIFOHEAD(fd,packet_len(0x120));
  3261. WFIFOW(fd, 0)=0x120;
  3262. WFIFOL(fd, 2)=unit->bl.id;
  3263. WFIFOSET(fd,packet_len(0x120));
  3264. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3265. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  3266. }
  3267. /*==========================================
  3268. * 場所スキルエフェクト削除
  3269. *------------------------------------------*/
  3270. void clif_skill_delunit(struct skill_unit *unit)
  3271. {
  3272. unsigned char buf[16];
  3273. nullpo_retv(unit);
  3274. WBUFW(buf, 0)=0x120;
  3275. WBUFL(buf, 2)=unit->bl.id;
  3276. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3277. }
  3278. /*==========================================
  3279. * Unknown... trap related?
  3280. * Sent when an object gets ankle-snared
  3281. * Only affects units with class [139,153] client-side
  3282. * R 01ac <object id>.l
  3283. *------------------------------------------*/
  3284. void clif_01ac(struct block_list* bl)
  3285. {
  3286. unsigned char buf[6];
  3287. nullpo_retv(bl);
  3288. WBUFW(buf,0) = 0x1ac;
  3289. WBUFL(buf,2) = bl->id;
  3290. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3291. }
  3292. /*==========================================
  3293. *
  3294. *------------------------------------------*/
  3295. int clif_getareachar(struct block_list* bl,va_list ap)
  3296. {
  3297. struct map_session_data *sd;
  3298. nullpo_retr(0, bl);
  3299. nullpo_retr(0, ap);
  3300. sd=va_arg(ap,struct map_session_data*);
  3301. if (sd == NULL || !sd->fd)
  3302. return 0;
  3303. switch(bl->type){
  3304. case BL_ITEM:
  3305. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3306. break;
  3307. case BL_SKILL:
  3308. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3309. break;
  3310. default:
  3311. if(&sd->bl == bl)
  3312. break;
  3313. clif_getareachar_unit(sd,bl);
  3314. break;
  3315. }
  3316. return 0;
  3317. }
  3318. /*==========================================
  3319. * tbl has gone out of view-size of bl
  3320. *------------------------------------------*/
  3321. int clif_outsight(struct block_list *bl,va_list ap)
  3322. {
  3323. struct block_list *tbl;
  3324. struct view_data *vd;
  3325. TBL_PC *sd, *tsd;
  3326. tbl=va_arg(ap,struct block_list*);
  3327. if(bl == tbl) return 0;
  3328. sd = BL_CAST(BL_PC, bl);
  3329. tsd = BL_CAST(BL_PC, tbl);
  3330. if (tsd && tsd->fd)
  3331. { //tsd has lost sight of the bl object.
  3332. switch(bl->type){
  3333. case BL_PC:
  3334. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS)
  3335. clif_clearunit_single(bl->id,0,tsd->fd);
  3336. if(sd->chatID){
  3337. struct chat_data *cd;
  3338. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3339. if(cd->usersd[0]==sd)
  3340. clif_dispchat(cd,tsd->fd);
  3341. }
  3342. if(sd->vender_id)
  3343. clif_closevendingboard(bl,tsd->fd);
  3344. break;
  3345. case BL_ITEM:
  3346. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3347. break;
  3348. case BL_SKILL:
  3349. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3350. break;
  3351. default:
  3352. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3353. clif_clearunit_single(bl->id,0,tsd->fd);
  3354. break;
  3355. }
  3356. }
  3357. if (sd && sd->fd)
  3358. { //sd is watching tbl go out of view.
  3359. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3360. clif_clearunit_single(tbl->id,0,sd->fd);
  3361. }
  3362. return 0;
  3363. }
  3364. /*==========================================
  3365. * tbl has come into view of bl
  3366. *------------------------------------------*/
  3367. int clif_insight(struct block_list *bl,va_list ap)
  3368. {
  3369. struct block_list *tbl;
  3370. TBL_PC *sd, *tsd;
  3371. tbl=va_arg(ap,struct block_list*);
  3372. if (bl == tbl) return 0;
  3373. sd = BL_CAST(BL_PC, bl);
  3374. tsd = BL_CAST(BL_PC, tbl);
  3375. if (tsd && tsd->fd)
  3376. { //Tell tsd that bl entered into his view
  3377. switch(bl->type){
  3378. case BL_ITEM:
  3379. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3380. break;
  3381. case BL_SKILL:
  3382. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3383. break;
  3384. default:
  3385. clif_getareachar_unit(tsd,bl);
  3386. break;
  3387. }
  3388. }
  3389. if (sd && sd->fd)
  3390. { //Tell sd that tbl walked into his view
  3391. clif_getareachar_unit(sd,tbl);
  3392. }
  3393. return 0;
  3394. }
  3395. /*==========================================
  3396. *
  3397. *------------------------------------------*/
  3398. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3399. {
  3400. int fd,id;
  3401. nullpo_retr(0, sd);
  3402. fd=sd->fd;
  3403. if( (id=sd->status.skill[skillid].id) <= 0 )
  3404. return 0;
  3405. WFIFOHEAD(fd,packet_len(0x147));
  3406. WFIFOW(fd,0)=0x147;
  3407. WFIFOW(fd,2) = id;
  3408. if(type < 0)
  3409. WFIFOW(fd,4) = skill_get_inf(id);
  3410. else
  3411. WFIFOW(fd,4) = type;
  3412. WFIFOW(fd,6) = 0;
  3413. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3414. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3415. if(range < 0)
  3416. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3417. WFIFOW(fd,12)= range;
  3418. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3419. if(sd->status.skill[skillid].flag ==0)
  3420. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3421. else
  3422. WFIFOB(fd,38) = 0;
  3423. WFIFOSET(fd,packet_len(0x147));
  3424. return 0;
  3425. }
  3426. /*==========================================
  3427. * スキルリストを送信する
  3428. *------------------------------------------*/
  3429. int clif_skillinfoblock(struct map_session_data *sd)
  3430. {
  3431. int fd;
  3432. int i,c,len,id;
  3433. nullpo_retr(0, sd);
  3434. fd=sd->fd;
  3435. if (!fd) return 0;
  3436. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3437. WFIFOW(fd,0) = 0x10f;
  3438. for ( i = 0, c = 0, len = 4; i < MAX_SKILL; i++)
  3439. {
  3440. if( (id = sd->status.skill[i].id) != 0 )
  3441. {
  3442. WFIFOW(fd,len) = id;
  3443. WFIFOW(fd,len+2) = skill_get_inf(id);
  3444. WFIFOW(fd,len+4) = 0;
  3445. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3446. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3447. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3448. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3449. if(sd->status.skill[i].flag == 0)
  3450. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3451. else
  3452. WFIFOB(fd,len+36) = 0;
  3453. len += 37;
  3454. c++;
  3455. }
  3456. }
  3457. WFIFOW(fd,2)=len;
  3458. WFIFOSET(fd,len);
  3459. return 1;
  3460. }
  3461. /*==========================================
  3462. * スキル割り振り通知
  3463. *------------------------------------------*/
  3464. int clif_skillup(struct map_session_data *sd,int skill_num)
  3465. {
  3466. int fd;
  3467. nullpo_retr(0, sd);
  3468. fd=sd->fd;
  3469. WFIFOHEAD(fd,packet_len(0x10e));
  3470. WFIFOW(fd,0) = 0x10e;
  3471. WFIFOW(fd,2) = skill_num;
  3472. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3473. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3474. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3475. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3476. WFIFOSET(fd,packet_len(0x10e));
  3477. return 0;
  3478. }
  3479. /*==========================================
  3480. * スキル詠唱エフェクトを送信する
  3481. *------------------------------------------*/
  3482. int clif_skillcasting(struct block_list* bl,
  3483. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int pl, int casttime)
  3484. {
  3485. unsigned char buf[32];
  3486. WBUFW(buf,0) = 0x13e;
  3487. WBUFL(buf,2) = src_id;
  3488. WBUFL(buf,6) = dst_id;
  3489. WBUFW(buf,10) = dst_x;
  3490. WBUFW(buf,12) = dst_y;
  3491. WBUFW(buf,14) = skill_num;
  3492. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3493. WBUFL(buf,20) = casttime;
  3494. if (disguised(bl)) {
  3495. clif_send(buf,packet_len(0x13e), bl, AREA_WOS);
  3496. WBUFL(buf,2) = -src_id;
  3497. clif_send(buf,packet_len(0x13e), bl, SELF);
  3498. } else
  3499. clif_send(buf,packet_len(0x13e), bl, AREA);
  3500. return 0;
  3501. }
  3502. /*==========================================
  3503. *
  3504. *------------------------------------------*/
  3505. int clif_skillcastcancel(struct block_list* bl)
  3506. {
  3507. unsigned char buf[16];
  3508. nullpo_retr(0, bl);
  3509. WBUFW(buf,0) = 0x1b9;
  3510. WBUFL(buf,2) = bl->id;
  3511. clif_send(buf,packet_len(0x1b9), bl, AREA);
  3512. return 0;
  3513. }
  3514. /// only when type==0:
  3515. /// if(skill_id==NV_BASIC)
  3516. /// btype==0 "skill failed" MsgStringTable[159]
  3517. /// btype==1 "no emotions" MsgStringTable[160]
  3518. /// btype==2 "no sit" MsgStringTable[161]
  3519. /// btype==3 "no chat" MsgStringTable[162]
  3520. /// btype==4 "no party" MsgStringTable[163]
  3521. /// btype==5 "no shout" MsgStringTable[164]
  3522. /// btype==6 "no PKing" MsgStringTable[165]
  3523. /// btype==7 "no alligning" MsgStringTable[383]
  3524. /// btype>=8: ignored
  3525. /// if(skill_id==AL_WARP) "not enough skill level" MsgStringTable[214]
  3526. /// if(skill_id==TF_STEAL) "steal failed" MsgStringTable[205]
  3527. /// if(skill_id==TF_POISON) "envenom failed" MsgStringTable[207]
  3528. /// otherwise "skill failed" MsgStringTable[204]
  3529. /// btype irrelevant
  3530. /// type==1 "insufficient SP" MsgStringTable[202]
  3531. /// type==2 "insufficient HP" MsgStringTable[203]
  3532. /// type==3 "insufficient materials" MsgStringTable[808]
  3533. /// type==4 "there is a delay after using a skill" MsgStringTable[219]
  3534. /// type==5 "insufficient zeny" MsgStringTable[233]
  3535. /// type==6 "wrong weapon" MsgStringTable[239]
  3536. /// type==7 "red gemstone needed" MsgStringTable[246]
  3537. /// type==8 "blue gemstone needed" MsgStringTable[247]
  3538. /// type==9 "overweight" MsgStringTable[580]
  3539. /// type==10 "skill failed" MsgStringTable[285]
  3540. /// type>=11 ignored
  3541. ///
  3542. /// if(success!=0) doesn't display any of the previous messages
  3543. /// Note: when this packet is received an unknown flag is always set to 0,
  3544. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  3545. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3546. {
  3547. int fd;
  3548. if (!sd) { //Since this is the most common nullpo....
  3549. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3550. return 0;
  3551. }
  3552. fd=sd->fd;
  3553. if (!fd) return 0;
  3554. if(battle_config.display_skill_fail&1)
  3555. return 0; //Disable all skill failed messages
  3556. if(type==0x4 && !sd->state.showdelay)
  3557. return 0; //Disable delay failed messages
  3558. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3559. return 0;
  3560. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3561. return 0;
  3562. WFIFOHEAD(fd,packet_len(0x110));
  3563. WFIFOW(fd,0) = 0x110;
  3564. WFIFOW(fd,2) = skill_id;
  3565. WFIFOL(fd,4) = btype;
  3566. WFIFOB(fd,8) = 0;// success?
  3567. WFIFOB(fd,9) = type;
  3568. WFIFOSET(fd,packet_len(0x110));
  3569. return 1;
  3570. }
  3571. /*==========================================
  3572. * skill attack effect and damage
  3573. * 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
  3574. *------------------------------------------*/
  3575. 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)
  3576. {
  3577. unsigned char buf[64];
  3578. struct status_change *sc;
  3579. nullpo_retr(0, src);
  3580. nullpo_retr(0, dst);
  3581. type = clif_calc_delay(type,div,damage,ddelay);
  3582. sc = status_get_sc(dst);
  3583. if(sc && sc->count) {
  3584. if(sc->data[SC_HALLUCINATION] && damage)
  3585. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3586. }
  3587. #if PACKETVER < 3
  3588. WBUFW(buf,0)=0x114;
  3589. WBUFW(buf,2)=skill_id;
  3590. WBUFL(buf,4)=src->id;
  3591. WBUFL(buf,8)=dst->id;
  3592. WBUFL(buf,12)=tick;
  3593. WBUFL(buf,16)=sdelay;
  3594. WBUFL(buf,20)=ddelay;
  3595. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3596. WBUFW(buf,24)=damage?div:0;
  3597. } else {
  3598. WBUFW(buf,24)=damage;
  3599. }
  3600. WBUFW(buf,26)=skill_lv;
  3601. WBUFW(buf,28)=div;
  3602. WBUFB(buf,30)=type;
  3603. if (disguised(dst)) {
  3604. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  3605. WBUFL(buf,8)=-dst->id;
  3606. clif_send(buf,packet_len(0x114),dst,SELF);
  3607. } else
  3608. clif_send(buf,packet_len(0x114),dst,AREA);
  3609. if(disguised(src)) {
  3610. WBUFL(buf,4)=-src->id;
  3611. if (disguised(dst))
  3612. WBUFL(buf,8)=dst->id;
  3613. if(damage > 0)
  3614. WBUFW(buf,24)=-1;
  3615. clif_send(buf,packet_len(0x114),src,SELF);
  3616. }
  3617. #else
  3618. WBUFW(buf,0)=0x1de;
  3619. WBUFW(buf,2)=skill_id;
  3620. WBUFL(buf,4)=src->id;
  3621. WBUFL(buf,8)=dst->id;
  3622. WBUFL(buf,12)=tick;
  3623. WBUFL(buf,16)=sdelay;
  3624. WBUFL(buf,20)=ddelay;
  3625. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3626. WBUFL(buf,24)=damage?div:0;
  3627. } else {
  3628. WBUFL(buf,24)=damage;
  3629. }
  3630. WBUFW(buf,28)=skill_lv;
  3631. WBUFW(buf,30)=div;
  3632. WBUFB(buf,32)=type;
  3633. if (disguised(dst)) {
  3634. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  3635. WBUFL(buf,8)=-dst->id;
  3636. clif_send(buf,packet_len(0x1de),dst,SELF);
  3637. } else
  3638. clif_send(buf,packet_len(0x1de),dst,AREA);
  3639. if(disguised(src)) {
  3640. WBUFL(buf,4)=-src->id;
  3641. if (disguised(dst))
  3642. WBUFL(buf,8)=dst->id;
  3643. if(damage > 0)
  3644. WBUFL(buf,24)=-1;
  3645. clif_send(buf,packet_len(0x1de),src,SELF);
  3646. }
  3647. #endif
  3648. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3649. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3650. }
  3651. /*==========================================
  3652. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3653. *------------------------------------------*/
  3654. /*
  3655. 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)
  3656. {
  3657. unsigned char buf[64];
  3658. struct status_change *sc;
  3659. nullpo_retr(0, src);
  3660. nullpo_retr(0, dst);
  3661. type = (type>0)?type:skill_get_hit(skill_id);
  3662. type = clif_calc_delay(type,div,damage,ddelay);
  3663. sc = status_get_sc(dst);
  3664. if(sc && sc->count) {
  3665. if(sc->data[SC_HALLUCINATION] && damage)
  3666. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3667. }
  3668. WBUFW(buf,0)=0x115;
  3669. WBUFW(buf,2)=skill_id;
  3670. WBUFL(buf,4)=src->id;
  3671. WBUFL(buf,8)=dst->id;
  3672. WBUFL(buf,12)=tick;
  3673. WBUFL(buf,16)=sdelay;
  3674. WBUFL(buf,20)=ddelay;
  3675. WBUFW(buf,24)=dst->x;
  3676. WBUFW(buf,26)=dst->y;
  3677. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3678. WBUFW(buf,28)=damage?div:0;
  3679. } else {
  3680. WBUFW(buf,28)=damage;
  3681. }
  3682. WBUFW(buf,30)=skill_lv;
  3683. WBUFW(buf,32)=div;
  3684. WBUFB(buf,34)=type;
  3685. clif_send(buf,packet_len(0x115),src,AREA);
  3686. if(disguised(src)) {
  3687. WBUFL(buf,4)=-src->id;
  3688. if(damage > 0)
  3689. WBUFW(buf,28)=-1;
  3690. clif_send(buf,packet_len(0x115),src,SELF);
  3691. }
  3692. if (disguised(dst)) {
  3693. WBUFL(buf,8)=-dst->id;
  3694. if (disguised(src))
  3695. WBUFL(buf,4)=src->id;
  3696. else if(damage > 0)
  3697. WBUFW(buf,28)=-1;
  3698. clif_send(buf,packet_len(0x115),dst,SELF);
  3699. }
  3700. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3701. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3702. }
  3703. */
  3704. /*==========================================
  3705. * 支援/回復スキルエフェクト
  3706. *------------------------------------------*/
  3707. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_id,int heal,int fail)
  3708. {
  3709. unsigned char buf[32];
  3710. nullpo_retr(0, dst);
  3711. WBUFW(buf,0)=0x11a;
  3712. WBUFW(buf,2)=skill_id;
  3713. WBUFW(buf,4)=min(heal, SHRT_MAX);
  3714. WBUFL(buf,6)=dst->id;
  3715. WBUFL(buf,10)=src?src->id:0;
  3716. WBUFB(buf,14)=fail;
  3717. if (disguised(dst)) {
  3718. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  3719. WBUFL(buf,6)=-dst->id;
  3720. clif_send(buf,packet_len(0x11a),dst,SELF);
  3721. } else
  3722. clif_send(buf,packet_len(0x11a),dst,AREA);
  3723. if(src && disguised(src)) {
  3724. WBUFL(buf,10)=-src->id;
  3725. if (disguised(dst))
  3726. WBUFL(buf,6)=dst->id;
  3727. clif_send(buf,packet_len(0x11a),src,SELF);
  3728. }
  3729. return fail;
  3730. }
  3731. /*==========================================
  3732. * 場所スキルエフェクト
  3733. *------------------------------------------*/
  3734. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  3735. {
  3736. unsigned char buf[32];
  3737. nullpo_retr(0, src);
  3738. WBUFW(buf,0)=0x117;
  3739. WBUFW(buf,2)=skill_id;
  3740. WBUFL(buf,4)=src->id;
  3741. WBUFW(buf,8)=val;
  3742. WBUFW(buf,10)=x;
  3743. WBUFW(buf,12)=y;
  3744. WBUFL(buf,14)=tick;
  3745. if(disguised(src)) {
  3746. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  3747. WBUFL(buf,4)=-src->id;
  3748. clif_send(buf,packet_len(0x117),src,SELF);
  3749. } else
  3750. clif_send(buf,packet_len(0x117),src,AREA);
  3751. return 0;
  3752. }
  3753. /*==========================================
  3754. * 場所スキルエフェクト表示
  3755. *------------------------------------------*/
  3756. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  3757. void clif_skill_setunit(struct skill_unit *unit)
  3758. {
  3759. unsigned char buf[128];
  3760. nullpo_retv(unit);
  3761. #if PACKETVER >= 3
  3762. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3763. WBUFW(buf, 0)=0x1c9;
  3764. WBUFL(buf, 2)=unit->bl.id;
  3765. WBUFL(buf, 6)=unit->group->src_id;
  3766. WBUFW(buf,10)=unit->bl.x;
  3767. WBUFW(buf,12)=unit->bl.y;
  3768. WBUFB(buf,14)=unit->group->unit_id;
  3769. WBUFB(buf,15)=1;
  3770. WBUFB(buf,16)=1;
  3771. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  3772. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  3773. return;
  3774. }
  3775. #endif
  3776. WBUFW(buf, 0)=0x11f;
  3777. WBUFL(buf, 2)=unit->bl.id;
  3778. WBUFL(buf, 6)=unit->group->src_id;
  3779. WBUFW(buf,10)=unit->bl.x;
  3780. WBUFW(buf,12)=unit->bl.y;
  3781. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  3782. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  3783. else
  3784. WBUFB(buf,14)=unit->group->unit_id;
  3785. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  3786. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  3787. }
  3788. /*==========================================
  3789. * ワープ場所選択
  3790. *------------------------------------------*/
  3791. 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)
  3792. {
  3793. int fd;
  3794. nullpo_retv(sd);
  3795. fd = sd->fd;
  3796. WFIFOHEAD(fd,packet_len(0x11c));
  3797. WFIFOW(fd,0) = 0x11c;
  3798. WFIFOW(fd,2) = skill_num;
  3799. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  3800. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  3801. else // normal map name
  3802. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  3803. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  3804. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  3805. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  3806. WFIFOSET(fd,packet_len(0x11c));
  3807. sd->menuskill_id = skill_num;
  3808. if (skill_num == AL_WARP)
  3809. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  3810. else
  3811. sd->menuskill_val = skill_lv;
  3812. }
  3813. /// Memo message.
  3814. /// type=0 : "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  3815. /// type=1 : "Skill Level is not high enough." in color 0x0000FF (red)
  3816. /// type=2 : "You haven't learned Warp." in color 0x0000FF (red)
  3817. ///
  3818. /// @param sd Who receives the message
  3819. /// @param type What message
  3820. void clif_skill_memomessage(struct map_session_data* sd, int type)
  3821. {
  3822. int fd;
  3823. nullpo_retv(sd);
  3824. fd=sd->fd;
  3825. WFIFOHEAD(fd,packet_len(0x11e));
  3826. WFIFOW(fd,0)=0x11e;
  3827. WFIFOB(fd,2)=type;
  3828. WFIFOSET(fd,packet_len(0x11e));
  3829. }
  3830. /// Teleport message.
  3831. /// type=0 : "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  3832. /// type=1 : "Saved point cannot be memorized." in color 0x0000FF (red)
  3833. ///
  3834. /// @param sd Who receives the message
  3835. /// @param type What message
  3836. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  3837. {
  3838. int fd;
  3839. nullpo_retv(sd);
  3840. fd=sd->fd;
  3841. WFIFOHEAD(fd,packet_len(0x189));
  3842. WFIFOW(fd,0)=0x189;
  3843. WFIFOW(fd,2)=type;
  3844. WFIFOSET(fd,packet_len(0x189));
  3845. }
  3846. /*==========================================
  3847. * モンスター情報
  3848. *------------------------------------------*/
  3849. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  3850. {
  3851. struct status_data *status;
  3852. unsigned char buf[64];
  3853. int i;//, fix;
  3854. nullpo_retr(0, sd);
  3855. nullpo_retr(0, dst);
  3856. if(dst->type!=BL_MOB )
  3857. return 0;
  3858. status = status_get_status_data(dst);
  3859. WBUFW(buf, 0)=0x18c;
  3860. WBUFW(buf, 2)=status_get_class(dst);
  3861. WBUFW(buf, 4)=status_get_lv(dst);
  3862. WBUFW(buf, 6)=status->size;
  3863. WBUFL(buf, 8)=status->hp;
  3864. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  3865. +(battle_config.estimation_type&2?status->def2:0);
  3866. WBUFW(buf,14)=status->race;
  3867. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  3868. +(battle_config.estimation_type&2?status->mdef2:0);
  3869. WBUFW(buf,18)= status->def_ele;
  3870. for(i=0;i<9;i++)
  3871. WBUFB(buf,20+i)= (unsigned char)battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv);
  3872. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  3873. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv))<0?0:fix);
  3874. clif_send(buf,packet_len(0x18c),&sd->bl,
  3875. sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  3876. return 0;
  3877. }
  3878. /*==========================================
  3879. * アイテム合成可能リスト
  3880. *------------------------------------------*/
  3881. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  3882. {
  3883. int i,c,view,fd;
  3884. nullpo_retr(0, sd);
  3885. if(sd->menuskill_id == AM_PHARMACY)
  3886. return 0; //Avoid resending the menu twice or more times...
  3887. fd=sd->fd;
  3888. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  3889. WFIFOW(fd, 0)=0x18d;
  3890. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  3891. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  3892. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  3893. WFIFOW(fd,c*8+ 4)= view;
  3894. else
  3895. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  3896. WFIFOW(fd,c*8+ 6)= 0x0012;
  3897. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  3898. c++;
  3899. }
  3900. }
  3901. WFIFOW(fd, 2)=c*8+8;
  3902. WFIFOSET(fd,WFIFOW(fd,2));
  3903. if(c > 0) {
  3904. sd->menuskill_id = AM_PHARMACY;
  3905. sd->menuskill_val = trigger;
  3906. return 1;
  3907. }
  3908. return 0;
  3909. }
  3910. /*==========================================
  3911. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  3912. *------------------------------------------*/
  3913. int clif_status_load(struct block_list *bl,int type, int flag)
  3914. {
  3915. int fd;
  3916. if (type == SI_BLANK) //It shows nothing on the client...
  3917. return 0;
  3918. if (bl->type != BL_PC)
  3919. return 0;
  3920. fd = ((struct map_session_data*)bl)->fd;
  3921. WFIFOHEAD(fd,packet_len(0x196));
  3922. WFIFOW(fd,0)=0x0196;
  3923. WFIFOW(fd,2)=type;
  3924. WFIFOL(fd,4)=bl->id;
  3925. WFIFOB(fd,8)=flag; //Status start
  3926. WFIFOSET(fd, packet_len(0x196));
  3927. return 0;
  3928. }
  3929. /*==========================================
  3930. * 状態異常アイコン/メッセージ表示
  3931. *------------------------------------------*/
  3932. int clif_status_change(struct block_list *bl,int type,int flag)
  3933. {
  3934. unsigned char buf[16];
  3935. if (type == SI_BLANK) //It shows nothing on the client...
  3936. return 0;
  3937. nullpo_retr(0, bl);
  3938. WBUFW(buf,0)=0x0196;
  3939. WBUFW(buf,2)=type;
  3940. WBUFL(buf,4)=bl->id;
  3941. WBUFB(buf,8)=flag;
  3942. clif_send(buf,packet_len(0x196),bl,AREA);
  3943. return 0;
  3944. }
  3945. /*==========================================
  3946. * Send message (modified by [Yor])
  3947. *------------------------------------------*/
  3948. int clif_displaymessage(const int fd, const char* mes)
  3949. {
  3950. // invalid pointer?
  3951. nullpo_retr(-1, mes);
  3952. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  3953. if (fd == 0)
  3954. return 0;
  3955. else {
  3956. int len_mes = strlen(mes);
  3957. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  3958. WFIFOHEAD(fd, 5 + len_mes);
  3959. WFIFOW(fd,0) = 0x8e;
  3960. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  3961. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  3962. WFIFOSET(fd, 5 + len_mes);
  3963. }
  3964. }
  3965. return 0;
  3966. }
  3967. /*==========================================
  3968. * 天の声を送信する
  3969. *------------------------------------------*/
  3970. int clif_GMmessage(struct block_list* bl, const char* mes, int len, int flag)
  3971. {
  3972. unsigned char *buf;
  3973. int lp;
  3974. lp = (flag & 0x10) ? 8 : 4;
  3975. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  3976. WBUFW(buf,0) = 0x9a;
  3977. WBUFW(buf,2) = len + lp;
  3978. WBUFL(buf,4) = 0x65756c62; //"blue":
  3979. memcpy(WBUFP(buf,lp), mes, len);
  3980. flag &= 0x07;
  3981. clif_send(buf, WBUFW(buf,2), bl,
  3982. (flag == 1) ? ALL_SAMEMAP :
  3983. (flag == 2) ? AREA :
  3984. (flag == 3) ? SELF :
  3985. ALL_CLIENT);
  3986. if(buf) aFree(buf);
  3987. if(use_irc && irc_announce_flag && !flag)
  3988. irc_announce(mes);
  3989. return 0;
  3990. }
  3991. /*==========================================
  3992. * グローバルメッセージ
  3993. *------------------------------------------*/
  3994. void clif_GlobalMessage(struct block_list* bl, const char* message)
  3995. {
  3996. char buf[100];
  3997. int len;
  3998. nullpo_retv(bl);
  3999. if(!message)
  4000. return;
  4001. len = strlen(message)+1;
  4002. WBUFW(buf,0)=0x8d;
  4003. WBUFW(buf,2)=len+8;
  4004. WBUFL(buf,4)=bl->id;
  4005. strncpy((char *) WBUFP(buf,8),message,len);
  4006. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4007. }
  4008. /*==========================================
  4009. * Send main chat message [LuzZza]
  4010. *------------------------------------------*/
  4011. void clif_MainChatMessage(const char* message)
  4012. {
  4013. char buf[200];
  4014. int len;
  4015. if(!message)
  4016. return;
  4017. len = strlen(message)+1;
  4018. if (len+8 > sizeof(buf)) {
  4019. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4020. len = sizeof(buf)-8;
  4021. }
  4022. WBUFW(buf,0)=0x8d;
  4023. WBUFW(buf,2)=len+8;
  4024. WBUFL(buf,4)=0;
  4025. strncpy((char *) WBUFP(buf,8),message,len);
  4026. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4027. }
  4028. /*==========================================
  4029. * Does an announce message in the given color.
  4030. *------------------------------------------*/
  4031. int clif_announce(struct block_list* bl, const char* mes, int len, unsigned long color, int flag)
  4032. {
  4033. unsigned char *buf;
  4034. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4035. WBUFW(buf,0) = 0x1c3;
  4036. WBUFW(buf,2) = len + 16;
  4037. WBUFL(buf,4) = color;
  4038. WBUFW(buf,8) = 0x190; //Font style? Type?
  4039. WBUFW(buf,10) = 0x0c; //12? Font size?
  4040. WBUFL(buf,12) = 0; //Unknown!
  4041. memcpy(WBUFP(buf,16), mes, len);
  4042. flag &= 0x07;
  4043. clif_send(buf, WBUFW(buf,2), bl,
  4044. (flag == 1) ? ALL_SAMEMAP :
  4045. (flag == 2) ? AREA :
  4046. (flag == 3) ? SELF :
  4047. ALL_CLIENT);
  4048. if(buf) aFree(buf);
  4049. return 0;
  4050. }
  4051. /*==========================================
  4052. * HPSP回復エフェクトを送信する
  4053. *------------------------------------------*/
  4054. int clif_heal(int fd,int type,int val)
  4055. {
  4056. WFIFOHEAD(fd,packet_len(0x13d));
  4057. WFIFOW(fd,0)=0x13d;
  4058. WFIFOW(fd,2)=type;
  4059. WFIFOW(fd,4)=cap_value(val,0,SHRT_MAX);
  4060. WFIFOSET(fd,packet_len(0x13d));
  4061. return 0;
  4062. }
  4063. /*==========================================
  4064. * 復活する
  4065. *------------------------------------------*/
  4066. int clif_resurrection(struct block_list *bl,int type)
  4067. {
  4068. unsigned char buf[16];
  4069. nullpo_retr(0, bl);
  4070. WBUFW(buf,0)=0x148;
  4071. WBUFL(buf,2)=bl->id;
  4072. WBUFW(buf,6)=type;
  4073. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4074. if (disguised(bl))
  4075. clif_spawn(bl);
  4076. return 0;
  4077. }
  4078. /// Sets the map mode.
  4079. ///
  4080. /// mode=1 : pvp mode
  4081. /// mode=2 : unknown mode (pk?)
  4082. /// mode=3 : gvg mode
  4083. /// mode=4 : message "You are in a PK area. Please beware of sudden attacks." in color 0x9B9BFF (light red)
  4084. /// mode=5 : pvp mode
  4085. /// mode=other : ?
  4086. void clif_set0199(struct map_session_data* sd, int mode)
  4087. {
  4088. int fd;
  4089. nullpo_retv(sd);
  4090. fd=sd->fd;
  4091. WFIFOHEAD(fd,packet_len(0x199));
  4092. WFIFOW(fd,0)=0x199;
  4093. WFIFOW(fd,2)=mode;
  4094. WFIFOSET(fd,packet_len(0x199));
  4095. }
  4096. #if 0
  4097. /// Set the map mode?
  4098. /// Differs from the behaviour of clif_set0199 with unknown consequences.
  4099. void clif_set01D6(struct map_session_data* sd, int mode)
  4100. {
  4101. int fd;
  4102. nullpo_retv(sd);
  4103. fd=sd->fd;
  4104. WFIFOHEAD(fd,packet_len(0x1D6));
  4105. WFIFOW(fd,0)=0x1D6;
  4106. WFIFOW(fd,2)=mode;
  4107. WFIFOSET(fd,packet_len(0x1D6));
  4108. }
  4109. #endif
  4110. /*==========================================
  4111. * PVP実装?(仮)
  4112. *------------------------------------------*/
  4113. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4114. {
  4115. if(type == 2) {
  4116. int fd = sd->fd;
  4117. WFIFOHEAD(fd,packet_len(0x19a));
  4118. WFIFOW(fd,0) = 0x19a;
  4119. WFIFOL(fd,2) = sd->bl.id;
  4120. WFIFOL(fd,6) = pvprank;
  4121. WFIFOL(fd,10) = pvpnum;
  4122. WFIFOSET(fd,packet_len(0x19a));
  4123. } else {
  4124. unsigned char buf[32];
  4125. WBUFW(buf,0) = 0x19a;
  4126. WBUFL(buf,2) = sd->bl.id;
  4127. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4128. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4129. else
  4130. WBUFL(buf,6) = pvprank;
  4131. WBUFL(buf,10) = pvpnum;
  4132. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  4133. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4134. else if(!type)
  4135. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4136. else
  4137. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4138. }
  4139. return 0;
  4140. }
  4141. /*==========================================
  4142. *
  4143. *------------------------------------------*/
  4144. int clif_send0199(int map,int type)
  4145. {
  4146. struct block_list bl;
  4147. unsigned char buf[16];
  4148. bl.id = 0;
  4149. bl.type = BL_NUL;
  4150. bl.m = map;
  4151. WBUFW(buf,0)=0x199;
  4152. WBUFW(buf,2)=type;
  4153. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4154. return 0;
  4155. }
  4156. /*==========================================
  4157. * 精錬エフェクトを送信する
  4158. *------------------------------------------*/
  4159. void clif_refine(int fd, int fail, int index, int val)
  4160. {
  4161. WFIFOHEAD(fd,packet_len(0x188));
  4162. WFIFOW(fd,0)=0x188;
  4163. WFIFOW(fd,2)=fail;
  4164. WFIFOW(fd,4)=index+2;
  4165. WFIFOW(fd,6)=val;
  4166. WFIFOSET(fd,packet_len(0x188));
  4167. }
  4168. /// result=0: "weapon upgrated: %s" MsgStringTable[911] in rgb(0,255,255)
  4169. /// result=1: "weapon upgrated: %s" MsgStringTable[912] in rgb(0,205,205)
  4170. /// result=2: "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4171. /// result=3: "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4172. void clif_upgrademessage(int fd, int result, int item_id)
  4173. {
  4174. WFIFOHEAD(fd,packet_len(0x223));
  4175. WFIFOW(fd,0)=0x223;
  4176. WFIFOL(fd,2)=result;
  4177. WFIFOW(fd,6)=item_id;
  4178. WFIFOSET(fd,packet_len(0x223));
  4179. }
  4180. /*==========================================
  4181. * Wisp/page is transmitted to the destination player
  4182. * R 0097 <len>.w <nick>.24B <message>.?B
  4183. *------------------------------------------*/
  4184. int clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4185. {
  4186. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4187. WFIFOW(fd,0) = 0x97;
  4188. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4189. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4190. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  4191. WFIFOSET(fd,WFIFOW(fd,2));
  4192. return 0;
  4193. }
  4194. /*==========================================
  4195. * Inform the player about the result of his whisper action
  4196. * R 0098 <type>.B
  4197. * 0: success to send wisper
  4198. * 1: target character is not loged in
  4199. * 2: ignored by target
  4200. * 3: everyone ignored by target
  4201. *------------------------------------------*/
  4202. int clif_wis_end(int fd, int flag)
  4203. {
  4204. WFIFOHEAD(fd,packet_len(0x98));
  4205. WFIFOW(fd,0) = 0x98;
  4206. WFIFOW(fd,2) = flag;
  4207. WFIFOSET(fd,packet_len(0x98));
  4208. return 0;
  4209. }
  4210. /*==========================================
  4211. * キャラID名前引き結果を送信する
  4212. *------------------------------------------*/
  4213. int clif_solved_charname(int fd, int charid, const char* name)
  4214. {
  4215. WFIFOHEAD(fd,packet_len(0x194));
  4216. WFIFOW(fd,0)=0x194;
  4217. WFIFOL(fd,2)=charid;
  4218. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  4219. WFIFOSET(fd,packet_len(0x194));
  4220. return 0;
  4221. }
  4222. /*==========================================
  4223. * カードの挿入可能リストを返す
  4224. *------------------------------------------*/
  4225. int clif_use_card(struct map_session_data *sd,int idx)
  4226. {
  4227. int i,c,ep;
  4228. int fd=sd->fd;
  4229. nullpo_retr(0, sd);
  4230. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4231. return 0;
  4232. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4233. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4234. ep=sd->inventory_data[idx]->equip;
  4235. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4236. WFIFOW(fd,0)=0x017b;
  4237. for(i=c=0;i<MAX_INVENTORY;i++){
  4238. int j;
  4239. if(sd->inventory_data[i] == NULL)
  4240. continue;
  4241. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4242. continue;
  4243. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4244. continue;
  4245. if(sd->status.inventory[i].identify==0 ) //Not identified
  4246. continue;
  4247. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4248. continue;
  4249. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_HAND_L) //Shield card won't go on left weapon.
  4250. continue;
  4251. for(j=0;j<sd->inventory_data[i]->slot;j++){
  4252. if( sd->status.inventory[i].card[j]==0 )
  4253. break;
  4254. }
  4255. if(j==sd->inventory_data[i]->slot) // No room
  4256. continue;
  4257. WFIFOW(fd,4+c*2)=i+2;
  4258. c++;
  4259. }
  4260. WFIFOW(fd,2)=4+c*2;
  4261. WFIFOSET(fd,WFIFOW(fd,2));
  4262. return 0;
  4263. }
  4264. /*==========================================
  4265. * カードの挿入終了
  4266. *------------------------------------------*/
  4267. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4268. {
  4269. int fd;
  4270. nullpo_retr(0, sd);
  4271. fd=sd->fd;
  4272. WFIFOHEAD(fd,packet_len(0x17d));
  4273. WFIFOW(fd,0)=0x17d;
  4274. WFIFOW(fd,2)=idx_equip+2;
  4275. WFIFOW(fd,4)=idx_card+2;
  4276. WFIFOB(fd,6)=flag;
  4277. WFIFOSET(fd,packet_len(0x17d));
  4278. return 0;
  4279. }
  4280. /*==========================================
  4281. * 鑑定可能アイテムリスト送信
  4282. *------------------------------------------*/
  4283. int clif_item_identify_list(struct map_session_data *sd)
  4284. {
  4285. int i,c;
  4286. int fd;
  4287. nullpo_retr(0, sd);
  4288. fd=sd->fd;
  4289. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4290. WFIFOW(fd,0)=0x177;
  4291. for(i=c=0;i<MAX_INVENTORY;i++){
  4292. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4293. WFIFOW(fd,c*2+4)=i+2;
  4294. c++;
  4295. }
  4296. }
  4297. if(c > 0) {
  4298. WFIFOW(fd,2)=c*2+4;
  4299. WFIFOSET(fd,WFIFOW(fd,2));
  4300. sd->menuskill_id = MC_IDENTIFY;
  4301. sd->menuskill_val = c;
  4302. }
  4303. return 0;
  4304. }
  4305. /*==========================================
  4306. * 鑑定結果
  4307. *------------------------------------------*/
  4308. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4309. {
  4310. int fd;
  4311. nullpo_retr(0, sd);
  4312. fd=sd->fd;
  4313. WFIFOHEAD(fd,packet_len(0x179));
  4314. WFIFOW(fd, 0)=0x179;
  4315. WFIFOW(fd, 2)=idx+2;
  4316. WFIFOB(fd, 4)=flag;
  4317. WFIFOSET(fd,packet_len(0x179));
  4318. return 0;
  4319. }
  4320. /*==========================================
  4321. * 修理可能アイテムリスト送信
  4322. *------------------------------------------*/
  4323. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4324. {
  4325. int i,c;
  4326. int fd;
  4327. int nameid;
  4328. nullpo_retr(0, sd);
  4329. nullpo_retr(0, dstsd);
  4330. fd=sd->fd;
  4331. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4332. WFIFOW(fd,0)=0x1fc;
  4333. for(i=c=0;i<MAX_INVENTORY;i++){
  4334. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4335. WFIFOW(fd,c*13+4) = i;
  4336. WFIFOW(fd,c*13+6) = nameid;
  4337. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4338. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4339. WFIFOB(fd,c*13+16)= c;
  4340. c++;
  4341. }
  4342. }
  4343. if(c > 0) {
  4344. WFIFOW(fd,2)=c*13+4;
  4345. WFIFOSET(fd,WFIFOW(fd,2));
  4346. sd->menuskill_id = BS_REPAIRWEAPON;
  4347. sd->menuskill_val = dstsd->bl.id;
  4348. }else
  4349. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4350. return 0;
  4351. }
  4352. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4353. {
  4354. int view,fd;
  4355. nullpo_retr(0, sd);
  4356. fd=sd->fd;
  4357. WFIFOHEAD(fd,packet_len(0x1fe));
  4358. WFIFOW(fd, 0)=0x1fe;
  4359. if((view = itemdb_viewid(nameid)) > 0)
  4360. WFIFOW(fd, 2)=view;
  4361. else
  4362. WFIFOW(fd, 2)=nameid;
  4363. WFIFOB(fd, 4)=flag;
  4364. WFIFOSET(fd,packet_len(0x1fe));
  4365. return 0;
  4366. }
  4367. /*==========================================
  4368. * Weapon Refining - Taken from jAthena
  4369. *------------------------------------------*/
  4370. int clif_item_refine_list(struct map_session_data *sd)
  4371. {
  4372. int i,c;
  4373. int fd;
  4374. int skilllv;
  4375. int wlv;
  4376. int refine_item[5];
  4377. nullpo_retr(0, sd);
  4378. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4379. fd=sd->fd;
  4380. refine_item[0] = -1;
  4381. refine_item[1] = pc_search_inventory(sd,1010);
  4382. refine_item[2] = pc_search_inventory(sd,1011);
  4383. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4384. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4385. WFIFOW(fd,0)=0x221;
  4386. for(i=c=0;i<MAX_INVENTORY;i++){
  4387. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4388. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4389. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4390. WFIFOW(fd,c*13+ 4)=i+2;
  4391. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4392. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4393. WFIFOW(fd,c*13+10)=0;
  4394. WFIFOB(fd,c*13+12)=c;
  4395. c++;
  4396. }
  4397. }
  4398. WFIFOW(fd,2)=c*13+4;
  4399. WFIFOSET(fd,WFIFOW(fd,2));
  4400. if (c > 0) {
  4401. sd->menuskill_id = WS_WEAPONREFINE;
  4402. sd->menuskill_val = skilllv;
  4403. }
  4404. return 0;
  4405. }
  4406. /*==========================================
  4407. * アイテムによる一時的なスキル効果
  4408. *------------------------------------------*/
  4409. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  4410. {
  4411. int fd;
  4412. nullpo_retr(0, sd);
  4413. fd=sd->fd;
  4414. WFIFOHEAD(fd,packet_len(0x147));
  4415. WFIFOW(fd, 0)=0x147;
  4416. WFIFOW(fd, 2)=skillid;
  4417. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4418. WFIFOW(fd, 6)=0;
  4419. WFIFOW(fd, 8)=skilllv;
  4420. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4421. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4422. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  4423. WFIFOB(fd,38)=0;
  4424. WFIFOSET(fd,packet_len(0x147));
  4425. return 0;
  4426. }
  4427. /*==========================================
  4428. * カートにアイテム追加
  4429. *------------------------------------------*/
  4430. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4431. {
  4432. int view,fd;
  4433. unsigned char *buf;
  4434. nullpo_retr(0, sd);
  4435. fd=sd->fd;
  4436. WFIFOHEAD(fd,packet_len(0x124));
  4437. buf=WFIFOP(fd,0);
  4438. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4439. return 1;
  4440. WBUFW(buf,0)=0x124;
  4441. WBUFW(buf,2)=n+2;
  4442. WBUFL(buf,4)=amount;
  4443. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4444. WBUFW(buf,8)=view;
  4445. else
  4446. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4447. WBUFB(buf,10)=sd->status.cart[n].identify;
  4448. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4449. WBUFB(buf,12)=sd->status.cart[n].refine;
  4450. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4451. WFIFOSET(fd,packet_len(0x124));
  4452. return 0;
  4453. }
  4454. /*==========================================
  4455. * カートからアイテム削除
  4456. *------------------------------------------*/
  4457. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4458. {
  4459. int fd;
  4460. nullpo_retr(0, sd);
  4461. fd=sd->fd;
  4462. WFIFOHEAD(fd,packet_len(0x125));
  4463. WFIFOW(fd,0)=0x125;
  4464. WFIFOW(fd,2)=n+2;
  4465. WFIFOL(fd,4)=amount;
  4466. WFIFOSET(fd,packet_len(0x125));
  4467. return 0;
  4468. }
  4469. /*==========================================
  4470. * Opens the shop creation menu.
  4471. * R 012d <num>.w
  4472. * 'num' is the number of allowed item slots
  4473. *------------------------------------------*/
  4474. void clif_openvendingreq(struct map_session_data* sd, int num)
  4475. {
  4476. int fd;
  4477. nullpo_retv(sd);
  4478. fd = sd->fd;
  4479. WFIFOHEAD(fd,packet_len(0x12d));
  4480. WFIFOW(fd,0) = 0x12d;
  4481. WFIFOW(fd,2) = num;
  4482. WFIFOSET(fd,packet_len(0x12d));
  4483. }
  4484. /*==========================================
  4485. * Displays a vending board to target/area
  4486. * R 0131 <ID>.l <message>.80B
  4487. *------------------------------------------*/
  4488. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  4489. {
  4490. unsigned char buf[128];
  4491. nullpo_retv(bl);
  4492. WBUFW(buf,0) = 0x131;
  4493. WBUFL(buf,2) = bl->id;
  4494. safestrncpy((char*)WBUFP(buf,6), message, 80);
  4495. if( fd ) {
  4496. WFIFOHEAD(fd,packet_len(0x131));
  4497. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  4498. WFIFOSET(fd,packet_len(0x131));
  4499. } else {
  4500. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  4501. }
  4502. }
  4503. /*==========================================
  4504. * Removes a vending board from screen
  4505. *------------------------------------------*/
  4506. void clif_closevendingboard(struct block_list* bl, int fd)
  4507. {
  4508. unsigned char buf[16];
  4509. nullpo_retv(bl);
  4510. WBUFW(buf,0) = 0x132;
  4511. WBUFL(buf,2) = bl->id;
  4512. if( fd ) {
  4513. WFIFOHEAD(fd,packet_len(0x132));
  4514. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  4515. WFIFOSET(fd,packet_len(0x132));
  4516. } else {
  4517. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  4518. }
  4519. }
  4520. /*==========================================
  4521. * Sends a list of items in a shop
  4522. * 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
  4523. *------------------------------------------*/
  4524. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  4525. {
  4526. int i,fd;
  4527. int count;
  4528. struct map_session_data* vsd;
  4529. nullpo_retv(sd);
  4530. nullpo_retv(vending);
  4531. nullpo_retv(vsd=map_id2sd(id));
  4532. fd = sd->fd;
  4533. count = vsd->vend_num;
  4534. WFIFOHEAD(fd, 8+count*22);
  4535. WFIFOW(fd,0) = 0x133;
  4536. WFIFOW(fd,2) = 8+count*22;
  4537. WFIFOL(fd,4) = id;
  4538. for( i = 0; i < count; i++ )
  4539. {
  4540. int index = vending[i].index;
  4541. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  4542. WFIFOL(fd, 8+i*22) = vending[i].value;
  4543. WFIFOW(fd,12+i*22) = vending[i].amount;
  4544. WFIFOW(fd,14+i*22) = vending[i].index + 2;
  4545. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4546. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  4547. WFIFOB(fd,19+i*22) = vsd->status.cart[index].identify;
  4548. WFIFOB(fd,20+i*22) = vsd->status.cart[index].attribute;
  4549. WFIFOB(fd,21+i*22) = vsd->status.cart[index].refine;
  4550. clif_addcards(WFIFOP(fd, 22+i*22), &vsd->status.cart[index]);
  4551. }
  4552. WFIFOSET(fd,WFIFOW(fd,2));
  4553. }
  4554. /*==========================================
  4555. * Shop purchase failure
  4556. * R 0135 <index>.w <amount>.w <fail>.B
  4557. * fail=1 - not enough zeny
  4558. * fail=2 - overweight
  4559. * fail=4 - out of stock
  4560. * fail=5 - "cannot use an npc shop while in a trade"
  4561. *------------------------------------------*/
  4562. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  4563. {
  4564. int fd;
  4565. nullpo_retv(sd);
  4566. fd = sd->fd;
  4567. WFIFOHEAD(fd,packet_len(0x135));
  4568. WFIFOW(fd,0) = 0x135;
  4569. WFIFOW(fd,2) = index+2;
  4570. WFIFOW(fd,4) = amount;
  4571. WFIFOB(fd,6) = fail;
  4572. WFIFOSET(fd,packet_len(0x135));
  4573. }
  4574. /*==========================================
  4575. * Shop creation success
  4576. * 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*
  4577. *------------------------------------------*/
  4578. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  4579. {
  4580. int i,fd;
  4581. int count;
  4582. nullpo_retv(sd);
  4583. fd = sd->fd;
  4584. count = sd->vend_num;
  4585. WFIFOHEAD(fd, 8+count*22);
  4586. WFIFOW(fd,0) = 0x136;
  4587. WFIFOW(fd,2) = 8+count*22;
  4588. WFIFOL(fd,4) = id;
  4589. for( i = 0; i < count; i++ )
  4590. {
  4591. int index = vending[i].index;
  4592. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  4593. WFIFOL(fd, 8+i*22) = vending[i].value;
  4594. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  4595. WFIFOW(fd,14+i*22) = vending[i].amount;
  4596. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4597. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  4598. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  4599. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  4600. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  4601. clif_addcards(WFIFOP(fd,22+count*22), &sd->status.cart[index]);
  4602. }
  4603. WFIFOSET(fd,WFIFOW(fd,2));
  4604. }
  4605. /*==========================================
  4606. * Inform merchant that someone has bought an item.
  4607. * R 0137 <index>.w <amount>.w
  4608. *------------------------------------------*/
  4609. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  4610. {
  4611. int fd;
  4612. nullpo_retv(sd);
  4613. fd = sd->fd;
  4614. WFIFOHEAD(fd,packet_len(0x137));
  4615. WFIFOW(fd,0) = 0x137;
  4616. WFIFOW(fd,2) = index+2;
  4617. WFIFOW(fd,4) = amount;
  4618. WFIFOSET(fd,packet_len(0x137));
  4619. }
  4620. /// Result of organizing a party.
  4621. /// R 00FA <result>.B
  4622. ///
  4623. /// result=0 : opens party window and shows MsgStringTable[77]="party successfully organized"
  4624. /// result=1 : MsgStringTable[78]="party name already exists"
  4625. /// result=2 : MsgStringTable[79]="already in a party"
  4626. /// result=other : nothing
  4627. int clif_party_created(struct map_session_data *sd,int result)
  4628. {
  4629. int fd;
  4630. nullpo_retr(0, sd);
  4631. fd=sd->fd;
  4632. WFIFOHEAD(fd,packet_len(0xfa));
  4633. WFIFOW(fd,0)=0xfa;
  4634. WFIFOB(fd,2)=result;
  4635. WFIFOSET(fd,packet_len(0xfa));
  4636. return 0;
  4637. }
  4638. int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  4639. {
  4640. unsigned char buf[96];
  4641. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  4642. int i;
  4643. for (i=0; i<MAX_PARTY && !p->data[i].sd; i++);
  4644. if (i >= MAX_PARTY) return 0; //Should never happen...
  4645. sd = p->data[i].sd;
  4646. }
  4647. WBUFW(buf, 0) = 0x1e9;
  4648. WBUFL(buf, 2) = sd->status.account_id;
  4649. WBUFL(buf, 6) = 0;
  4650. WBUFW(buf,10) = sd->bl.x;
  4651. WBUFW(buf,12) = sd->bl.y;
  4652. WBUFB(buf,14) = 0; //Unconfirmed byte, could be online/offline.
  4653. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  4654. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  4655. mapindex_getmapname_ext(mapindex_id2name(sd->mapindex), (char*)WBUFP(buf,63));
  4656. WBUFB(buf,79) = (p->party.item&1)?1:0;
  4657. WBUFB(buf,80) = (p->party.item&2)?1:0;
  4658. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  4659. return 1;
  4660. }
  4661. /*==========================================
  4662. * Sends party information
  4663. * R 00fb <len>.w <party name>.24B {<ID>.l <nick>.24B <map name>.16B <leader>.B <offline>.B}.46B*
  4664. *------------------------------------------*/
  4665. int clif_party_info(struct party_data* p, struct map_session_data *sd)
  4666. {
  4667. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  4668. struct map_session_data* party_sd = NULL;
  4669. int i, c;
  4670. nullpo_retr(0, p);
  4671. WBUFW(buf,0) = 0xfb;
  4672. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  4673. for(i = 0, c = 0; i < MAX_PARTY; i++)
  4674. {
  4675. struct party_member* m = &p->party.member[i];
  4676. if(!m->account_id) continue;
  4677. if(party_sd == NULL) party_sd = p->data[i].sd;
  4678. WBUFL(buf,28+c*46) = m->account_id;
  4679. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  4680. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  4681. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  4682. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  4683. c++;
  4684. }
  4685. WBUFW(buf,2) = 28+c*46;
  4686. if(sd) { // send only to self
  4687. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  4688. } else if (party_sd) { // send to whole party
  4689. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  4690. }
  4691. return 0;
  4692. }
  4693. /*==========================================
  4694. * パーティ勧誘
  4695. *------------------------------------------*/
  4696. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  4697. {
  4698. int fd;
  4699. struct party_data *p;
  4700. nullpo_retr(0, sd);
  4701. nullpo_retr(0, tsd);
  4702. fd=tsd->fd;
  4703. if( (p=party_search(sd->status.party_id))==NULL )
  4704. return 0;
  4705. WFIFOHEAD(fd,packet_len(0xfe));
  4706. WFIFOW(fd,0)=0xfe;
  4707. WFIFOL(fd,2)=sd->status.account_id;
  4708. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  4709. WFIFOSET(fd,packet_len(0xfe));
  4710. return 0;
  4711. }
  4712. /*==========================================
  4713. * Party invitation result. Flag values are:
  4714. * 0 -> char is already in a party
  4715. * 1 -> party invite was rejected
  4716. * 2 -> party invite was accepted
  4717. * 3 -> party is full
  4718. * 4 -> char of the same account already joined the party
  4719. *------------------------------------------*/
  4720. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int flag)
  4721. {
  4722. int fd;
  4723. nullpo_retv(sd);
  4724. fd=sd->fd;
  4725. WFIFOHEAD(fd,packet_len(0xfd));
  4726. WFIFOW(fd,0) = 0xfd;
  4727. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  4728. WFIFOB(fd,26) = flag;
  4729. WFIFOSET(fd,packet_len(0xfd));
  4730. }
  4731. /*==========================================
  4732. * パーティ設定送信
  4733. * flag & 0x001=exp変更ミス
  4734. * 0x010=item変更ミス
  4735. * 0x100=一人にのみ送信
  4736. *------------------------------------------*/
  4737. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  4738. {
  4739. unsigned char buf[16];
  4740. nullpo_retr(0, p);
  4741. if(!sd && flag==0){
  4742. int i;
  4743. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4744. if (i < MAX_PARTY)
  4745. sd = p->data[i].sd;
  4746. }
  4747. if(!sd) return 0;
  4748. WBUFW(buf,0)=0x101;
  4749. // WBUFL(buf,2) // that's how the client reads it, still need to check it's uses [FlavioJS]
  4750. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  4751. WBUFW(buf,4)=0;
  4752. if(flag==0)
  4753. clif_send(buf,packet_len(0x101),&sd->bl,PARTY);
  4754. else
  4755. clif_send(buf,packet_len(0x101),&sd->bl,SELF);
  4756. return 0;
  4757. }
  4758. /*==========================================
  4759. * パーティ脱退(脱退前に呼ぶこと)
  4760. *------------------------------------------*/
  4761. int clif_party_leaved(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  4762. {
  4763. unsigned char buf[64];
  4764. int i;
  4765. nullpo_retr(0, p);
  4766. if(!sd && (flag&0xf0)==0)
  4767. {
  4768. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4769. if (i < MAX_PARTY)
  4770. sd = p->data[i].sd;
  4771. }
  4772. if(!sd) return 0;
  4773. WBUFW(buf,0)=0x105;
  4774. WBUFL(buf,2)=account_id;
  4775. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  4776. WBUFB(buf,30)=flag&0x0f;
  4777. if((flag&0xf0)==0)
  4778. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  4779. else
  4780. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  4781. return 0;
  4782. }
  4783. /*==========================================
  4784. * パーティメッセージ送信
  4785. *------------------------------------------*/
  4786. int clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  4787. {
  4788. struct map_session_data *sd;
  4789. int i;
  4790. nullpo_retr(0, p);
  4791. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  4792. if(i < MAX_PARTY){
  4793. unsigned char buf[1024];
  4794. sd = p->data[i].sd;
  4795. WBUFW(buf,0)=0x109;
  4796. WBUFW(buf,2)=len+8;
  4797. WBUFL(buf,4)=account_id;
  4798. memcpy(WBUFP(buf,8),mes,len);
  4799. clif_send(buf,len+8,&sd->bl,PARTY);
  4800. }
  4801. return 0;
  4802. }
  4803. /*==========================================
  4804. * パーティ座標通知
  4805. *------------------------------------------*/
  4806. int clif_party_xy(struct map_session_data *sd)
  4807. {
  4808. unsigned char buf[16];
  4809. nullpo_retr(0, sd);
  4810. WBUFW(buf,0)=0x107;
  4811. WBUFL(buf,2)=sd->status.account_id;
  4812. WBUFW(buf,6)=sd->bl.x;
  4813. WBUFW(buf,8)=sd->bl.y;
  4814. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  4815. return 0;
  4816. }
  4817. /*==========================================
  4818. * Sends x/y dot to a single fd. [Skotlex]
  4819. *------------------------------------------*/
  4820. int clif_party_xy_single(int fd, struct map_session_data *sd)
  4821. {
  4822. WFIFOHEAD(fd,packet_len(0x107));
  4823. WFIFOW(fd,0)=0x107;
  4824. WFIFOL(fd,2)=sd->status.account_id;
  4825. WFIFOW(fd,6)=sd->bl.x;
  4826. WFIFOW(fd,8)=sd->bl.y;
  4827. WFIFOSET(fd,packet_len(0x107));
  4828. return 0;
  4829. }
  4830. /*==========================================
  4831. * パーティHP通知
  4832. *------------------------------------------*/
  4833. int clif_party_hp(struct map_session_data *sd)
  4834. {
  4835. unsigned char buf[16];
  4836. nullpo_retr(0, sd);
  4837. WBUFW(buf,0)=0x106;
  4838. WBUFL(buf,2)=sd->status.account_id;
  4839. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  4840. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  4841. WBUFW(buf,8) = 100;
  4842. } else {
  4843. WBUFW(buf,6) = sd->battle_status.hp;
  4844. WBUFW(buf,8) = sd->battle_status.max_hp;
  4845. }
  4846. clif_send(buf,packet_len(0x106),&sd->bl,PARTY_AREA_WOS);
  4847. return 0;
  4848. }
  4849. /*==========================================
  4850. * Sends HP bar to a single fd. [Skotlex]
  4851. *------------------------------------------*/
  4852. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  4853. {
  4854. WFIFOHEAD(fd,packet_len(0x106));
  4855. WFIFOW(fd,0) = 0x106;
  4856. WFIFOL(fd,2) = id;
  4857. if( maxhp > SHRT_MAX )
  4858. {// To correctly display the %hp bar. [Skotlex]
  4859. WFIFOW(fd,6) = hp/(maxhp/100);
  4860. WFIFOW(fd,8) = 100;
  4861. } else {
  4862. WFIFOW(fd,6) = hp;
  4863. WFIFOW(fd,8) = maxhp;
  4864. }
  4865. WFIFOSET(fd, packet_len(0x106));
  4866. }
  4867. /*==========================================
  4868. * GMへ場所とHP通知
  4869. *------------------------------------------*/
  4870. int clif_hpmeter(struct map_session_data *sd)
  4871. {
  4872. struct map_session_data *sd2;
  4873. unsigned char buf[16];
  4874. int i, x0, y0, x1, y1;
  4875. int level;
  4876. nullpo_retr(0, sd);
  4877. x0 = sd->bl.x - AREA_SIZE;
  4878. y0 = sd->bl.y - AREA_SIZE;
  4879. x1 = sd->bl.x + AREA_SIZE;
  4880. y1 = sd->bl.y + AREA_SIZE;
  4881. WBUFW(buf,0) = 0x106;
  4882. WBUFL(buf,2) = sd->status.account_id;
  4883. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  4884. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  4885. WBUFW(buf,8) = 100;
  4886. } else {
  4887. WBUFW(buf,6) = sd->battle_status.hp;
  4888. WBUFW(buf,8) = sd->battle_status.max_hp;
  4889. }
  4890. for (i = 0; i < fd_max; i++) {
  4891. if (session[i] && session[i]->func_parse == clif_parse &&
  4892. (sd2 = (struct map_session_data*)session[i]->session_data) &&
  4893. sd != sd2 && sd2->state.active) {
  4894. if (sd2->bl.m != sd->bl.m ||
  4895. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  4896. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  4897. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  4898. level < pc_isGM(sd))
  4899. continue;
  4900. WFIFOHEAD (i, packet_len(0x106));
  4901. memcpy (WFIFOP(i,0), buf, packet_len(0x106));
  4902. WFIFOSET (i, packet_len(0x106));
  4903. }
  4904. }
  4905. return 0;
  4906. }
  4907. /*==========================================
  4908. * パーティ場所移動(未使用)
  4909. *------------------------------------------*/
  4910. void clif_party_move(struct party* p, struct map_session_data* sd, int online)
  4911. {
  4912. unsigned char buf[128];
  4913. nullpo_retv(sd);
  4914. nullpo_retv(p);
  4915. WBUFW(buf, 0) = 0x104;
  4916. WBUFL(buf, 2) = sd->status.account_id;
  4917. WBUFL(buf, 6) = 0;
  4918. WBUFW(buf,10) = sd->bl.x;
  4919. WBUFW(buf,12) = sd->bl.y;
  4920. WBUFB(buf,14) = !online;
  4921. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  4922. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  4923. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  4924. clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
  4925. }
  4926. /*==========================================
  4927. * 攻撃するために移動が必要
  4928. *------------------------------------------*/
  4929. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  4930. {
  4931. int fd;
  4932. nullpo_retr(0, sd);
  4933. nullpo_retr(0, bl);
  4934. fd=sd->fd;
  4935. WFIFOHEAD(fd,packet_len(0x139));
  4936. WFIFOW(fd, 0)=0x139;
  4937. WFIFOL(fd, 2)=bl->id;
  4938. WFIFOW(fd, 6)=bl->x;
  4939. WFIFOW(fd, 8)=bl->y;
  4940. WFIFOW(fd,10)=sd->bl.x;
  4941. WFIFOW(fd,12)=sd->bl.y;
  4942. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  4943. WFIFOSET(fd,packet_len(0x139));
  4944. return 0;
  4945. }
  4946. /*==========================================
  4947. * 製造エフェクト
  4948. *------------------------------------------*/
  4949. int clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  4950. {
  4951. int view,fd;
  4952. nullpo_retr(0, sd);
  4953. fd = sd->fd;
  4954. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  4955. WFIFOHEAD(fd,packet_len(0x18f));
  4956. WFIFOW(fd, 0)=0x18f;
  4957. WFIFOW(fd, 2)=flag;
  4958. if((view = itemdb_viewid(nameid)) > 0)
  4959. WFIFOW(fd, 4)=view;
  4960. else
  4961. WFIFOW(fd, 4)=nameid;
  4962. WFIFOSET(fd,packet_len(0x18f));
  4963. return 0;
  4964. }
  4965. // pet
  4966. int clif_catch_process(struct map_session_data *sd)
  4967. {
  4968. int fd;
  4969. nullpo_retr(0, sd);
  4970. fd=sd->fd;
  4971. WFIFOHEAD(fd,packet_len(0x19e));
  4972. WFIFOW(fd,0)=0x19e;
  4973. WFIFOSET(fd,packet_len(0x19e));
  4974. return 0;
  4975. }
  4976. int clif_pet_roulette(struct map_session_data *sd,int data)
  4977. {
  4978. int fd;
  4979. nullpo_retr(0, sd);
  4980. fd=sd->fd;
  4981. WFIFOHEAD(fd,packet_len(0x1a0));
  4982. WFIFOW(fd,0)=0x1a0;
  4983. WFIFOB(fd,2)=data;
  4984. WFIFOSET(fd,packet_len(0x1a0));
  4985. return 0;
  4986. }
  4987. /*==========================================
  4988. * pet卵リスト作成
  4989. *------------------------------------------*/
  4990. int clif_sendegg(struct map_session_data *sd)
  4991. {
  4992. //R 01a6 <len>.w <index>.w*
  4993. int i,n=0,fd;
  4994. nullpo_retr(0, sd);
  4995. fd=sd->fd;
  4996. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  4997. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  4998. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  4999. return 0;
  5000. }
  5001. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5002. WFIFOW(fd,0)=0x1a6;
  5003. if(sd->status.pet_id <= 0) {
  5004. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5005. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5006. sd->inventory_data[i]->type!=IT_PETEGG ||
  5007. sd->status.inventory[i].amount<=0)
  5008. continue;
  5009. WFIFOW(fd,n*2+4)=i+2;
  5010. n++;
  5011. }
  5012. }
  5013. WFIFOW(fd,2)=4+n*2;
  5014. WFIFOSET(fd,WFIFOW(fd,2));
  5015. sd->menuskill_id = SA_TAMINGMONSTER;
  5016. sd->menuskill_val = -1;
  5017. return 0;
  5018. }
  5019. /*==========================================
  5020. * Sends a specific pet data update.
  5021. * type = 0 -> param = 0 (initial data)
  5022. * type = 1 -> param = intimacy value
  5023. * type = 2 -> param = hungry value
  5024. * type = 3 -> param = accessory id
  5025. * type = 4 -> param = performance number (1-3:normal, 4:special)
  5026. * type = 5 -> param = hairstyle number
  5027. * If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5028. *------------------------------------------*/
  5029. int clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5030. {
  5031. uint8 buf[16];
  5032. nullpo_retr(0, pd);
  5033. WBUFW(buf,0) = 0x1a4;
  5034. WBUFB(buf,2) = type;
  5035. WBUFL(buf,3) = pd->bl.id;
  5036. WBUFL(buf,7) = param;
  5037. if (sd)
  5038. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5039. else
  5040. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5041. return 0;
  5042. }
  5043. int clif_send_petstatus(struct map_session_data *sd)
  5044. {
  5045. int fd;
  5046. struct s_pet *pet;
  5047. nullpo_retr(0, sd);
  5048. nullpo_retr(0, sd->pd);
  5049. fd=sd->fd;
  5050. pet = &sd->pd->pet;
  5051. WFIFOHEAD(fd,packet_len(0x1a2));
  5052. WFIFOW(fd,0)=0x1a2;
  5053. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5054. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5055. WFIFOW(fd,27)=pet->level;
  5056. WFIFOW(fd,29)=pet->hungry;
  5057. WFIFOW(fd,31)=pet->intimate;
  5058. WFIFOW(fd,33)=pet->equip;
  5059. WFIFOSET(fd,packet_len(0x1a2));
  5060. return 0;
  5061. }
  5062. /*==========================================
  5063. *
  5064. *------------------------------------------*/
  5065. int clif_pet_emotion(struct pet_data *pd,int param)
  5066. {
  5067. unsigned char buf[16];
  5068. nullpo_retr(0, pd);
  5069. memset(buf,0,packet_len(0x1aa));
  5070. WBUFW(buf,0)=0x1aa;
  5071. WBUFL(buf,2)=pd->bl.id;
  5072. if(param >= 100 && pd->petDB->talk_convert_class) {
  5073. if(pd->petDB->talk_convert_class < 0)
  5074. return 0;
  5075. else if(pd->petDB->talk_convert_class > 0) {
  5076. param -= (pd->pet.class_ - 100)*100;
  5077. param += (pd->petDB->talk_convert_class - 100)*100;
  5078. }
  5079. }
  5080. WBUFL(buf,6)=param;
  5081. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5082. return 0;
  5083. }
  5084. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5085. {
  5086. int fd;
  5087. nullpo_retr(0, sd);
  5088. fd=sd->fd;
  5089. WFIFOHEAD(fd,packet_len(0x1a3));
  5090. WFIFOW(fd,0)=0x1a3;
  5091. WFIFOB(fd,2)=fail;
  5092. WFIFOW(fd,3)=foodid;
  5093. WFIFOSET(fd,packet_len(0x1a3));
  5094. return 0;
  5095. }
  5096. /*==========================================
  5097. * オートスペル リスト送信
  5098. *------------------------------------------*/
  5099. int clif_autospell(struct map_session_data *sd,int skilllv)
  5100. {
  5101. int fd;
  5102. nullpo_retr(0, sd);
  5103. fd=sd->fd;
  5104. WFIFOHEAD(fd,packet_len(0x1cd));
  5105. WFIFOW(fd, 0)=0x1cd;
  5106. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5107. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5108. else
  5109. WFIFOL(fd,2)= 0x00000000;
  5110. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5111. WFIFOL(fd,6)= MG_COLDBOLT;
  5112. else
  5113. WFIFOL(fd,6)= 0x00000000;
  5114. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5115. WFIFOL(fd,10)= MG_FIREBOLT;
  5116. else
  5117. WFIFOL(fd,10)= 0x00000000;
  5118. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5119. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5120. else
  5121. WFIFOL(fd,14)= 0x00000000;
  5122. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5123. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5124. else
  5125. WFIFOL(fd,18)= 0x00000000;
  5126. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5127. WFIFOL(fd,22)= MG_FIREBALL;
  5128. else
  5129. WFIFOL(fd,22)= 0x00000000;
  5130. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5131. WFIFOL(fd,26)= MG_FROSTDIVER;
  5132. else
  5133. WFIFOL(fd,26)= 0x00000000;
  5134. WFIFOSET(fd,packet_len(0x1cd));
  5135. sd->menuskill_id = SA_AUTOSPELL;
  5136. sd->menuskill_val = skilllv;
  5137. return 0;
  5138. }
  5139. /*==========================================
  5140. * Devotion's visual effect
  5141. * S 01cf <devoter id>.L { <devotee id>.L }[5] <max distance>.W
  5142. *------------------------------------------*/
  5143. void clif_devotion(struct map_session_data *sd, struct map_session_data *tsd)
  5144. {
  5145. unsigned char buf[56];
  5146. int i;
  5147. nullpo_retv(sd);
  5148. WBUFW(buf,0) = 0x1cf;
  5149. WBUFL(buf,2) = sd->bl.id;
  5150. for( i = 0; i < 5; i++ )
  5151. WBUFL(buf,6+4*i) = sd->devotion[i];
  5152. WBUFW(buf,26) = skill_get_range2(&sd->bl,CR_DEVOTION,pc_checkskill(sd,CR_DEVOTION)); // ignored
  5153. if( tsd )
  5154. clif_send(buf,packet_len(0x1cf),&tsd->bl,SELF);
  5155. else
  5156. clif_send(buf,packet_len(0x1cf),&sd->bl,AREA);
  5157. }
  5158. /*==========================================
  5159. * 氣球
  5160. *------------------------------------------*/
  5161. int clif_spiritball(struct map_session_data *sd)
  5162. {
  5163. unsigned char buf[16];
  5164. nullpo_retr(0, sd);
  5165. WBUFW(buf,0)=0x1d0;
  5166. WBUFL(buf,2)=sd->bl.id;
  5167. WBUFW(buf,6)=sd->spiritball;
  5168. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5169. return 0;
  5170. }
  5171. /*==========================================
  5172. *
  5173. *------------------------------------------*/
  5174. int clif_combo_delay(struct block_list *bl,int wait)
  5175. {
  5176. unsigned char buf[32];
  5177. nullpo_retr(0, bl);
  5178. WBUFW(buf,0)=0x1d2;
  5179. WBUFL(buf,2)=bl->id;
  5180. WBUFL(buf,6)=wait;
  5181. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5182. return 0;
  5183. }
  5184. /*==========================================
  5185. *白刃取り
  5186. *------------------------------------------*/
  5187. int clif_bladestop(struct block_list *src,struct block_list *dst,
  5188. int _bool)
  5189. {
  5190. unsigned char buf[32];
  5191. nullpo_retr(0, src);
  5192. nullpo_retr(0, dst);
  5193. WBUFW(buf,0)=0x1d1;
  5194. WBUFL(buf,2)=src->id;
  5195. WBUFL(buf,6)=dst->id;
  5196. WBUFL(buf,10)=_bool;
  5197. clif_send(buf,packet_len(0x1d1),src,AREA);
  5198. return 0;
  5199. }
  5200. /*==========================================
  5201. * MVPエフェクト
  5202. *------------------------------------------*/
  5203. int clif_mvp_effect(struct map_session_data *sd)
  5204. {
  5205. unsigned char buf[16];
  5206. nullpo_retr(0, sd);
  5207. WBUFW(buf,0)=0x10c;
  5208. WBUFL(buf,2)=sd->bl.id;
  5209. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5210. return 0;
  5211. }
  5212. /*==========================================
  5213. * MVPアイテム所得
  5214. *------------------------------------------*/
  5215. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5216. {
  5217. int view,fd;
  5218. nullpo_retr(0, sd);
  5219. fd=sd->fd;
  5220. WFIFOHEAD(fd,packet_len(0x10a));
  5221. WFIFOW(fd,0)=0x10a;
  5222. if((view = itemdb_viewid(nameid)) > 0)
  5223. WFIFOW(fd,2)=view;
  5224. else
  5225. WFIFOW(fd,2)=nameid;
  5226. WFIFOSET(fd,packet_len(0x10a));
  5227. return 0;
  5228. }
  5229. /*==========================================
  5230. * MVP経験値所得
  5231. *------------------------------------------*/
  5232. int clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  5233. {
  5234. int fd;
  5235. nullpo_retr(0, sd);
  5236. fd=sd->fd;
  5237. WFIFOHEAD(fd,packet_len(0x10b));
  5238. WFIFOW(fd,0)=0x10b;
  5239. WFIFOL(fd,2)=cap_value(exp,0,INT_MAX);
  5240. WFIFOSET(fd,packet_len(0x10b));
  5241. return 0;
  5242. }
  5243. /*==========================================
  5244. * ギルド作成可否通知
  5245. *------------------------------------------*/
  5246. int clif_guild_created(struct map_session_data *sd,int flag)
  5247. {
  5248. int fd;
  5249. nullpo_retr(0, sd);
  5250. fd=sd->fd;
  5251. WFIFOHEAD(fd,packet_len(0x167));
  5252. WFIFOW(fd,0)=0x167;
  5253. WFIFOB(fd,2)=flag;
  5254. WFIFOSET(fd,packet_len(0x167));
  5255. return 0;
  5256. }
  5257. /*==========================================
  5258. * ギルド所属通知
  5259. *------------------------------------------*/
  5260. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  5261. {
  5262. int ps,fd;
  5263. nullpo_retr(0, sd);
  5264. nullpo_retr(0, g);
  5265. fd=sd->fd;
  5266. ps=guild_getposition(g,sd);
  5267. WFIFOHEAD(fd,packet_len(0x16c));
  5268. memset(WFIFOP(fd,0),0,packet_len(0x16c));
  5269. WFIFOW(fd,0)=0x16c;
  5270. WFIFOL(fd,2)=g->guild_id;
  5271. WFIFOL(fd,6)=g->emblem_id;
  5272. WFIFOL(fd,10)=g->position[ps].mode;
  5273. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5274. WFIFOSET(fd,packet_len(0x16c));
  5275. return 0;
  5276. }
  5277. /*==========================================
  5278. * ギルドメンバログイン通知
  5279. *------------------------------------------*/
  5280. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5281. {
  5282. unsigned char buf[64];
  5283. nullpo_retr(0, g);
  5284. WBUFW(buf, 0)=0x16d;
  5285. WBUFL(buf, 2)=g->member[idx].account_id;
  5286. WBUFL(buf, 6)=g->member[idx].char_id;
  5287. WBUFL(buf,10)=flag;
  5288. if(g->member[idx].sd==NULL){
  5289. struct map_session_data *sd=guild_getavailablesd(g);
  5290. if(sd!=NULL)
  5291. clif_send(buf,packet_len(0x16d),&sd->bl,GUILD);
  5292. }else
  5293. clif_send(buf,packet_len(0x16d),&g->member[idx].sd->bl,GUILD_WOS);
  5294. return 0;
  5295. }
  5296. // Function `clif_guild_memberlogin_notice` sends info about
  5297. // logins and logouts of a guild member to the rest members.
  5298. // But at the 1st time (after a player login or map changing)
  5299. // the client won't show the message.
  5300. // So I suggest use this function for sending "first-time-info"
  5301. // to some player on entering the game or changing location.
  5302. // At next time the client would always show the message.
  5303. // The function sends all the statuses in the single packet
  5304. // to economize traffic. [LuzZza]
  5305. int clif_guild_send_onlineinfo(struct map_session_data *sd)
  5306. {
  5307. struct guild *g;
  5308. unsigned char buf[14*128];
  5309. int i, count=0, p_len;
  5310. nullpo_retr(0, sd);
  5311. p_len = packet_len(0x16d);
  5312. if(!(g = guild_search(sd->status.guild_id)))
  5313. return 0;
  5314. for(i=0; i<g->max_member; i++) {
  5315. if(g->member[i].account_id > 0 &&
  5316. g->member[i].account_id != sd->status.account_id) {
  5317. WBUFW(buf,count*p_len) = 0x16d;
  5318. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5319. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5320. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5321. count++;
  5322. }
  5323. }
  5324. clif_send(buf, p_len*count, &sd->bl, SELF);
  5325. return 0;
  5326. }
  5327. /*==========================================
  5328. * ギルドマスター通知(14dへの応答)
  5329. *------------------------------------------*/
  5330. int clif_guild_masterormember(struct map_session_data *sd)
  5331. {
  5332. int fd;
  5333. nullpo_retr(0, sd);
  5334. fd=sd->fd;
  5335. WFIFOHEAD(fd,packet_len(0x14e));
  5336. WFIFOW(fd,0) = 0x14e;
  5337. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  5338. WFIFOSET(fd,packet_len(0x14e));
  5339. return 0;
  5340. }
  5341. /*==========================================
  5342. * Basic Info (Territories [Valaris])
  5343. *------------------------------------------*/
  5344. int clif_guild_basicinfo(struct map_session_data *sd)
  5345. {
  5346. int fd,i,t;
  5347. struct guild *g;
  5348. struct guild_castle *gc=NULL;
  5349. nullpo_retr(0, sd);
  5350. fd=sd->fd;
  5351. g=guild_search(sd->status.guild_id);
  5352. if(g==NULL)
  5353. return 0;
  5354. WFIFOHEAD(fd,packet_len(0x1b6));
  5355. WFIFOW(fd, 0)=0x1b6;//0x150;
  5356. WFIFOL(fd, 2)=g->guild_id;
  5357. WFIFOL(fd, 6)=g->guild_lv;
  5358. WFIFOL(fd,10)=g->connect_member;
  5359. WFIFOL(fd,14)=g->max_member;
  5360. WFIFOL(fd,18)=g->average_lv;
  5361. WFIFOL(fd,22)=g->exp;
  5362. WFIFOL(fd,26)=g->next_exp;
  5363. WFIFOL(fd,30)=0; // Tax Points
  5364. WFIFOL(fd,34)=0; // Tendency: (left) Vulgar [-100,100] Famed (right)
  5365. WFIFOL(fd,38)=0; // Tendency: (down) Wicked [-100,100] Righteous (up)
  5366. WFIFOL(fd,42)=g->emblem_id;
  5367. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5368. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5369. for(i = 0, t = 0; i < MAX_GUILDCASTLE; i++)
  5370. {
  5371. gc = guild_castle_search(i);
  5372. if(gc && g->guild_id == gc->guild_id)
  5373. t++;
  5374. }
  5375. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20); // "'N' castles"
  5376. WFIFOSET(fd,packet_len(WFIFOW(fd,0)));
  5377. return 0;
  5378. }
  5379. /*==========================================
  5380. * ギルド同盟/敵対情報
  5381. *------------------------------------------*/
  5382. int clif_guild_allianceinfo(struct map_session_data *sd)
  5383. {
  5384. int fd,i,c;
  5385. struct guild *g;
  5386. nullpo_retr(0, sd);
  5387. fd=sd->fd;
  5388. g=guild_search(sd->status.guild_id);
  5389. if(g==NULL)
  5390. return 0;
  5391. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5392. WFIFOW(fd, 0)=0x14c;
  5393. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5394. struct guild_alliance *a=&g->alliance[i];
  5395. if(a->guild_id>0){
  5396. WFIFOL(fd,c*32+4)=a->opposition;
  5397. WFIFOL(fd,c*32+8)=a->guild_id;
  5398. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5399. c++;
  5400. }
  5401. }
  5402. WFIFOW(fd, 2)=c*32+4;
  5403. WFIFOSET(fd,WFIFOW(fd,2));
  5404. return 0;
  5405. }
  5406. /*==========================================
  5407. * ギルドメンバーリスト
  5408. *------------------------------------------*/
  5409. int clif_guild_memberlist(struct map_session_data *sd)
  5410. {
  5411. int fd;
  5412. int i,c;
  5413. struct guild *g;
  5414. nullpo_retr(0, sd);
  5415. fd=sd->fd;
  5416. if (!fd)
  5417. return 0;
  5418. g=guild_search(sd->status.guild_id);
  5419. if(g==NULL)
  5420. return 0;
  5421. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5422. WFIFOW(fd, 0)=0x154;
  5423. for(i=0,c=0;i<g->max_member;i++){
  5424. struct guild_member *m=&g->member[i];
  5425. if(m->account_id==0)
  5426. continue;
  5427. WFIFOL(fd,c*104+ 4)=m->account_id;
  5428. WFIFOL(fd,c*104+ 8)=m->char_id;
  5429. WFIFOW(fd,c*104+12)=m->hair;
  5430. WFIFOW(fd,c*104+14)=m->hair_color;
  5431. WFIFOW(fd,c*104+16)=m->gender;
  5432. WFIFOW(fd,c*104+18)=m->class_;
  5433. WFIFOW(fd,c*104+20)=m->lv;
  5434. WFIFOL(fd,c*104+22)=m->exp;
  5435. WFIFOL(fd,c*104+26)=m->online;
  5436. WFIFOL(fd,c*104+30)=m->position;
  5437. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5438. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5439. c++;
  5440. }
  5441. WFIFOW(fd, 2)=c*104+4;
  5442. WFIFOSET(fd,WFIFOW(fd,2));
  5443. return 0;
  5444. }
  5445. /*==========================================
  5446. * ギルド役職名リスト
  5447. *------------------------------------------*/
  5448. int clif_guild_positionnamelist(struct map_session_data *sd)
  5449. {
  5450. int i,fd;
  5451. struct guild *g;
  5452. nullpo_retr(0, sd);
  5453. fd=sd->fd;
  5454. g=guild_search(sd->status.guild_id);
  5455. if(g==NULL)
  5456. return 0;
  5457. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5458. WFIFOW(fd, 0)=0x166;
  5459. for(i=0;i<MAX_GUILDPOSITION;i++){
  5460. WFIFOL(fd,i*28+4)=i;
  5461. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5462. }
  5463. WFIFOW(fd,2)=i*28+4;
  5464. WFIFOSET(fd,WFIFOW(fd,2));
  5465. return 0;
  5466. }
  5467. /*==========================================
  5468. * ギルド役職情報リスト
  5469. *------------------------------------------*/
  5470. int clif_guild_positioninfolist(struct map_session_data *sd)
  5471. {
  5472. int i,fd;
  5473. struct guild *g;
  5474. nullpo_retr(0, sd);
  5475. fd=sd->fd;
  5476. g=guild_search(sd->status.guild_id);
  5477. if(g==NULL)
  5478. return 0;
  5479. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5480. WFIFOW(fd, 0)=0x160;
  5481. for(i=0;i<MAX_GUILDPOSITION;i++){
  5482. struct guild_position *p=&g->position[i];
  5483. WFIFOL(fd,i*16+ 4)=i;
  5484. WFIFOL(fd,i*16+ 8)=p->mode;
  5485. WFIFOL(fd,i*16+12)=i;
  5486. WFIFOL(fd,i*16+16)=p->exp_mode;
  5487. }
  5488. WFIFOW(fd, 2)=i*16+4;
  5489. WFIFOSET(fd,WFIFOW(fd,2));
  5490. return 0;
  5491. }
  5492. /*==========================================
  5493. * ギルド役職変更通知
  5494. *------------------------------------------*/
  5495. int clif_guild_positionchanged(struct guild *g,int idx)
  5496. {
  5497. struct map_session_data *sd;
  5498. unsigned char buf[128];
  5499. nullpo_retr(0, g);
  5500. WBUFW(buf, 0)=0x174;
  5501. WBUFW(buf, 2)=44;
  5502. WBUFL(buf, 4)=idx;
  5503. WBUFL(buf, 8)=g->position[idx].mode;
  5504. WBUFL(buf,12)=idx;
  5505. WBUFL(buf,16)=g->position[idx].exp_mode;
  5506. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  5507. if( (sd=guild_getavailablesd(g))!=NULL )
  5508. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5509. return 0;
  5510. }
  5511. /*==========================================
  5512. * ギルドメンバ変更通知
  5513. *------------------------------------------*/
  5514. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  5515. {
  5516. struct map_session_data *sd;
  5517. unsigned char buf[64];
  5518. nullpo_retr(0, g);
  5519. WBUFW(buf, 0)=0x156;
  5520. WBUFW(buf, 2)=16;
  5521. WBUFL(buf, 4)=g->member[idx].account_id;
  5522. WBUFL(buf, 8)=g->member[idx].char_id;
  5523. WBUFL(buf,12)=g->member[idx].position;
  5524. if( (sd=guild_getavailablesd(g))!=NULL )
  5525. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5526. return 0;
  5527. }
  5528. /*==========================================
  5529. * ギルドエンブレム送信
  5530. *------------------------------------------*/
  5531. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  5532. {
  5533. int fd;
  5534. nullpo_retr(0, sd);
  5535. nullpo_retr(0, g);
  5536. fd=sd->fd;
  5537. if(g->emblem_len<=0)
  5538. return 0;
  5539. WFIFOHEAD(fd,g->emblem_len+12);
  5540. WFIFOW(fd,0)=0x152;
  5541. WFIFOW(fd,2)=g->emblem_len+12;
  5542. WFIFOL(fd,4)=g->guild_id;
  5543. WFIFOL(fd,8)=g->emblem_id;
  5544. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  5545. WFIFOSET(fd,WFIFOW(fd,2));
  5546. return 0;
  5547. }
  5548. /*==========================================
  5549. * Send guild skills
  5550. *------------------------------------------*/
  5551. int clif_guild_skillinfo(struct map_session_data* sd)
  5552. {
  5553. int fd;
  5554. struct guild* g;
  5555. int i,c;
  5556. nullpo_retr(0, sd);
  5557. fd = sd->fd;
  5558. g = guild_search(sd->status.guild_id);
  5559. if(g == NULL)
  5560. return 0;
  5561. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  5562. WFIFOW(fd,0) = 0x0162;
  5563. WFIFOW(fd,4) = g->skill_point;
  5564. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  5565. {
  5566. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  5567. {
  5568. int id = g->skill[i].id;
  5569. int p = 6 + c*37;
  5570. WFIFOW(fd,p+0) = id;
  5571. WFIFOW(fd,p+2) = skill_get_inf(id);
  5572. WFIFOW(fd,p+4) = 0;
  5573. WFIFOW(fd,p+6) = g->skill[i].lv;
  5574. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  5575. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  5576. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  5577. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  5578. c++;
  5579. }
  5580. }
  5581. WFIFOW(fd,2) = 6 + c*37;
  5582. WFIFOSET(fd,WFIFOW(fd,2));
  5583. return 0;
  5584. }
  5585. /*==========================================
  5586. * Sends guild notice to client
  5587. * R 016f <str1z>.60B <str2z>.120B
  5588. *------------------------------------------*/
  5589. int clif_guild_notice(struct map_session_data* sd, struct guild* g)
  5590. {
  5591. int fd;
  5592. nullpo_retr(0, sd);
  5593. nullpo_retr(0, g);
  5594. fd = sd->fd;
  5595. if ( !session_isActive(fd) )
  5596. return 0;
  5597. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  5598. return 0;
  5599. WFIFOHEAD(fd,packet_len(0x16f));
  5600. WFIFOW(fd,0) = 0x16f;
  5601. memcpy(WFIFOP(fd,2), g->mes1, 60);
  5602. memcpy(WFIFOP(fd,62), g->mes2, 120);
  5603. WFIFOSET(fd,packet_len(0x16f));
  5604. return 0;
  5605. }
  5606. /*==========================================
  5607. * ギルドメンバ勧誘
  5608. *------------------------------------------*/
  5609. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  5610. {
  5611. int fd;
  5612. nullpo_retr(0, sd);
  5613. nullpo_retr(0, g);
  5614. fd=sd->fd;
  5615. WFIFOHEAD(fd,packet_len(0x16a));
  5616. WFIFOW(fd,0)=0x16a;
  5617. WFIFOL(fd,2)=g->guild_id;
  5618. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  5619. WFIFOSET(fd,packet_len(0x16a));
  5620. return 0;
  5621. }
  5622. /*==========================================
  5623. * ギルドメンバ勧誘結果
  5624. *------------------------------------------*/
  5625. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  5626. {
  5627. int fd;
  5628. nullpo_retr(0, sd);
  5629. fd=sd->fd;
  5630. WFIFOHEAD(fd,packet_len(0x169));
  5631. WFIFOW(fd,0)=0x169;
  5632. WFIFOB(fd,2)=flag;
  5633. WFIFOSET(fd,packet_len(0x169));
  5634. return 0;
  5635. }
  5636. /*==========================================
  5637. * ギルドメンバ脱退通知
  5638. *------------------------------------------*/
  5639. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  5640. {
  5641. unsigned char buf[128];
  5642. nullpo_retr(0, sd);
  5643. WBUFW(buf, 0)=0x15a;
  5644. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5645. memcpy(WBUFP(buf,26),mes,40);
  5646. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD);
  5647. return 0;
  5648. }
  5649. /*==========================================
  5650. * ギルドメンバ追放通知
  5651. *------------------------------------------*/
  5652. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,int account_id)
  5653. {
  5654. unsigned char buf[128];
  5655. nullpo_retr(0, sd);
  5656. WBUFW(buf, 0)=0x15c;
  5657. safestrncpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5658. safestrncpy(WBUFP(buf,26),mes,40);
  5659. safestrncpy(WBUFP(buf,66),"",NAME_LENGTH); // account name (not used for security reasons)
  5660. clif_send(buf,packet_len(0x15c),&sd->bl,GUILD);
  5661. return 0;
  5662. }
  5663. /*==========================================
  5664. * ギルド追放メンバリスト
  5665. *------------------------------------------*/
  5666. int clif_guild_expulsionlist(struct map_session_data *sd)
  5667. {
  5668. int fd;
  5669. int i,c;
  5670. struct guild *g;
  5671. nullpo_retr(0, sd);
  5672. fd=sd->fd;
  5673. g=guild_search(sd->status.guild_id);
  5674. if(g==NULL)
  5675. return 0;
  5676. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * 88);
  5677. WFIFOW(fd,0)=0x163;
  5678. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  5679. struct guild_expulsion *e=&g->expulsion[i];
  5680. if(e->account_id>0){
  5681. safestrncpy(WFIFOP(fd,4 + c*88),e->name,NAME_LENGTH);
  5682. safestrncpy(WFIFOP(fd,4 + c*88+24),"",24); // account name (not used for security reasons)
  5683. safestrncpy(WFIFOP(fd,4 + c*88+48),e->mes,40);
  5684. c++;
  5685. }
  5686. }
  5687. WFIFOW(fd,2) = 4 + c*88;
  5688. WFIFOSET(fd,WFIFOW(fd,2));
  5689. return 0;
  5690. }
  5691. /*==========================================
  5692. * ギルド会話
  5693. *------------------------------------------*/
  5694. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  5695. {
  5696. struct map_session_data *sd;
  5697. unsigned char *buf;
  5698. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  5699. WBUFW(buf, 0) = 0x17f;
  5700. WBUFW(buf, 2) = len + 4;
  5701. memcpy(WBUFP(buf,4), mes, len);
  5702. if ((sd = guild_getavailablesd(g)) != NULL)
  5703. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  5704. if(buf) aFree(buf);
  5705. return 0;
  5706. }
  5707. /*==========================================
  5708. * ギルドスキル割り振り通知
  5709. *------------------------------------------*/
  5710. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  5711. {
  5712. int fd;
  5713. nullpo_retr(0, sd);
  5714. fd=sd->fd;
  5715. WFIFOHEAD(fd,11);
  5716. WFIFOW(fd,0) = 0x10e;
  5717. WFIFOW(fd,2) = skill_num;
  5718. WFIFOW(fd,4) = lv;
  5719. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  5720. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  5721. WFIFOB(fd,10) = 1;
  5722. WFIFOSET(fd,11);
  5723. return 0;
  5724. }
  5725. /*==========================================
  5726. * ギルド同盟要請
  5727. *------------------------------------------*/
  5728. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  5729. {
  5730. int fd;
  5731. nullpo_retr(0, sd);
  5732. fd=sd->fd;
  5733. WFIFOHEAD(fd,packet_len(0x171));
  5734. WFIFOW(fd,0)=0x171;
  5735. WFIFOL(fd,2)=account_id;
  5736. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  5737. WFIFOSET(fd,packet_len(0x171));
  5738. return 0;
  5739. }
  5740. /*==========================================
  5741. * Reply to alliance request.
  5742. * Flag values are:
  5743. * 0: Already allied.
  5744. * 1: You rejected the offer.
  5745. * 2: You accepted the offer.
  5746. * 3: They have too any alliances
  5747. * 4: You have too many alliances.
  5748. *------------------------------------------*/
  5749. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  5750. {
  5751. int fd;
  5752. nullpo_retr(0, sd);
  5753. fd=sd->fd;
  5754. WFIFOHEAD(fd,packet_len(0x173));
  5755. WFIFOW(fd,0)=0x173;
  5756. WFIFOL(fd,2)=flag;
  5757. WFIFOSET(fd,packet_len(0x173));
  5758. return 0;
  5759. }
  5760. /*==========================================
  5761. * ギルド関係解消通知
  5762. *------------------------------------------*/
  5763. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  5764. {
  5765. int fd;
  5766. nullpo_retr(0, sd);
  5767. fd = sd->fd;
  5768. if (fd <= 0)
  5769. return 0;
  5770. WFIFOHEAD(fd,packet_len(0x184));
  5771. WFIFOW(fd,0)=0x184;
  5772. WFIFOL(fd,2)=guild_id;
  5773. WFIFOL(fd,6)=flag;
  5774. WFIFOSET(fd,packet_len(0x184));
  5775. return 0;
  5776. }
  5777. /*==========================================
  5778. * ギルド敵対結果
  5779. *------------------------------------------*/
  5780. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  5781. {
  5782. int fd;
  5783. nullpo_retr(0, sd);
  5784. fd=sd->fd;
  5785. WFIFOHEAD(fd,packet_len(0x181));
  5786. WFIFOW(fd,0)=0x181;
  5787. WFIFOB(fd,2)=flag;
  5788. WFIFOSET(fd,packet_len(0x181));
  5789. return 0;
  5790. }
  5791. /*==========================================
  5792. * ギルド関係追加
  5793. *------------------------------------------*/
  5794. /*int clif_guild_allianceadded(struct guild *g,int idx)
  5795. {
  5796. unsigned char buf[64];
  5797. WBUFW(fd,0)=0x185;
  5798. WBUFL(fd,2)=g->alliance[idx].opposition;
  5799. WBUFL(fd,6)=g->alliance[idx].guild_id;
  5800. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  5801. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  5802. return 0;
  5803. }*/
  5804. /*==========================================
  5805. * ギルド解散通知
  5806. *------------------------------------------*/
  5807. int clif_guild_broken(struct map_session_data *sd,int flag)
  5808. {
  5809. int fd;
  5810. nullpo_retr(0, sd);
  5811. fd=sd->fd;
  5812. WFIFOHEAD(fd,packet_len(0x15e));
  5813. WFIFOW(fd,0)=0x15e;
  5814. WFIFOL(fd,2)=flag;
  5815. WFIFOSET(fd,packet_len(0x15e));
  5816. return 0;
  5817. }
  5818. /*==========================================
  5819. * エモーション
  5820. *------------------------------------------*/
  5821. void clif_emotion(struct block_list *bl,int type)
  5822. {
  5823. unsigned char buf[8];
  5824. nullpo_retv(bl);
  5825. WBUFW(buf,0)=0xc0;
  5826. WBUFL(buf,2)=bl->id;
  5827. WBUFB(buf,6)=type;
  5828. clif_send(buf,packet_len(0xc0),bl,AREA);
  5829. }
  5830. /*==========================================
  5831. * トーキーボックス
  5832. *------------------------------------------*/
  5833. void clif_talkiebox(struct block_list* bl, const char* talkie)
  5834. {
  5835. unsigned char buf[86];
  5836. nullpo_retv(bl);
  5837. WBUFW(buf,0) = 0x191;
  5838. WBUFL(buf,2) = bl->id;
  5839. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  5840. clif_send(buf,packet_len(0x191),bl,AREA);
  5841. }
  5842. /*==========================================
  5843. * 結婚エフェクト
  5844. *------------------------------------------*/
  5845. void clif_wedding_effect(struct block_list *bl)
  5846. {
  5847. unsigned char buf[6];
  5848. nullpo_retv(bl);
  5849. WBUFW(buf,0) = 0x1ea;
  5850. WBUFL(buf,2) = bl->id;
  5851. clif_send(buf, packet_len(0x1ea), bl, AREA);
  5852. }
  5853. /*==========================================
  5854. * あなたに逢いたい使用時名前叫び
  5855. *------------------------------------------
  5856. void clif_callpartner(struct map_session_data *sd)
  5857. {
  5858. unsigned char buf[26];
  5859. char *p;
  5860. nullpo_retv(sd);
  5861. if(sd->status.partner_id){
  5862. WBUFW(buf,0)=0x1e6;
  5863. p = map_charid2nick(sd->status.partner_id);
  5864. if(p){
  5865. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  5866. }else{
  5867. map_reqchariddb(sd,sd->status.partner_id);
  5868. chrif_searchcharid(sd->status.partner_id);
  5869. WBUFB(buf,2) = 0;
  5870. }
  5871. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  5872. }
  5873. return;
  5874. }
  5875. */
  5876. /*==========================================
  5877. * Marry [DracoRPG]
  5878. *------------------------------------------*/
  5879. void clif_marriage_process(struct map_session_data *sd)
  5880. {
  5881. int fd;
  5882. nullpo_retv(sd);
  5883. fd=sd->fd;
  5884. WFIFOHEAD(fd,packet_len(0x1e4));
  5885. WFIFOW(fd,0)=0x1e4;
  5886. WFIFOSET(fd,packet_len(0x1e4));
  5887. }
  5888. /*==========================================
  5889. * Notice of divorce
  5890. *------------------------------------------*/
  5891. void clif_divorced(struct map_session_data* sd, const char* name)
  5892. {
  5893. int fd;
  5894. nullpo_retv(sd);
  5895. fd=sd->fd;
  5896. WFIFOHEAD(fd,packet_len(0x205));
  5897. WFIFOW(fd,0)=0x205;
  5898. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  5899. WFIFOSET(fd, packet_len(0x205));
  5900. }
  5901. /*==========================================
  5902. *
  5903. *------------------------------------------*/
  5904. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd)
  5905. {
  5906. nullpo_retv(sd);
  5907. WFIFOHEAD(fd,packet_len(0x1e2));
  5908. WFIFOW(fd,0)=0x1e2;
  5909. WFIFOSET(fd, packet_len(0x1e2));
  5910. }
  5911. /*==========================================
  5912. *
  5913. *------------------------------------------*/
  5914. int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  5915. {
  5916. int fd;
  5917. nullpo_retr(0, sd);
  5918. fd = sd->fd;
  5919. if (!fd || !len) return 0; //Disconnected player.
  5920. WFIFOHEAD(fd, len+5);
  5921. WFIFOW(fd, 0) = 0x17f;
  5922. WFIFOW(fd, 2) = len + 5;
  5923. memcpy(WFIFOP(fd,4), mes, len);
  5924. WFIFOSET(fd, WFIFOW(fd,2));
  5925. return 1;
  5926. }
  5927. /*==========================================
  5928. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  5929. *------------------------------------------*/
  5930. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  5931. {
  5932. unsigned char buf[1024];
  5933. if (!len) return;
  5934. WBUFW(buf, 0) = 0x17f;
  5935. WBUFW(buf, 2) = len + 5;
  5936. memcpy(WBUFP(buf,4), mes, len);
  5937. clif_send(buf, WBUFW(buf,2), src, target);
  5938. return;
  5939. }
  5940. /*==========================================
  5941. *
  5942. *------------------------------------------*/
  5943. int clif_GM_kickack(struct map_session_data *sd, int id)
  5944. {
  5945. int fd;
  5946. nullpo_retr(0, sd);
  5947. fd = sd->fd;
  5948. WFIFOHEAD(fd,packet_len(0xcd));
  5949. WFIFOW(fd,0) = 0xcd;
  5950. WFIFOL(fd,2) = id;
  5951. WFIFOSET(fd, packet_len(0xcd));
  5952. return 0;
  5953. }
  5954. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  5955. {
  5956. int fd = tsd->fd;
  5957. if( fd > 0 )
  5958. clif_authfail_fd(fd, 15);
  5959. else
  5960. map_quit(tsd);
  5961. if( sd )
  5962. clif_GM_kickack(sd,tsd->status.account_id);
  5963. }
  5964. /// Displays various manner-related status messages
  5965. /// R 014a <type>.L
  5966. /// type: 0 - "A manner point has been successfully aligned."
  5967. /// 1 - ?
  5968. /// 2 - ?
  5969. /// 3 - "Chat Block has been applied by GM due to your ill-mannerous action."
  5970. /// 4 - "Automated Chat Block has been applied due to Anti-Spam System."
  5971. /// 5 - "You got a good point from %s."
  5972. void clif_manner_message(struct map_session_data* sd, uint32 type)
  5973. {
  5974. int fd;
  5975. nullpo_retv(sd);
  5976. fd = sd->fd;
  5977. WFIFOHEAD(fd,packet_len(0x14a));
  5978. WFIFOW(fd,0) = 0x14a;
  5979. WFIFOL(fd,2) = type;
  5980. WFIFOSET(fd, packet_len(0x14a));
  5981. }
  5982. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action.
  5983. /// R 014b <type>.B <GM name>.24B
  5984. /// type: 0 - positive (unmute)
  5985. /// 1 - negative (mute)
  5986. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  5987. {
  5988. int fd;
  5989. nullpo_retv(sd);
  5990. nullpo_retv(tsd);
  5991. fd = tsd->fd;
  5992. WFIFOHEAD(fd,packet_len(0x14b));
  5993. WFIFOW(fd,0) = 0x14b;
  5994. WFIFOB(fd,2) = type;
  5995. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  5996. WFIFOSET(fd, packet_len(0x14b));
  5997. }
  5998. /*==========================================
  5999. *
  6000. *------------------------------------------*/
  6001. int clif_timedout(struct map_session_data *sd)
  6002. {
  6003. nullpo_retr(0, sd);
  6004. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' timed out.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id);
  6005. clif_authfail_fd(sd->fd,3); // Even if player is not on we still send anyway
  6006. clif_setwaitclose(sd->fd); // Set session to EOF
  6007. return 0;
  6008. }
  6009. /*==========================================
  6010. * Wis拒否許可応答
  6011. *------------------------------------------*/
  6012. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6013. {
  6014. int fd;
  6015. nullpo_retr(0, sd);
  6016. fd=sd->fd;
  6017. WFIFOHEAD(fd,packet_len(0xd1));
  6018. WFIFOW(fd,0)=0xd1;
  6019. WFIFOB(fd,2)=type;
  6020. WFIFOB(fd,3)=flag;
  6021. WFIFOSET(fd,packet_len(0xd1));
  6022. return 0;
  6023. }
  6024. /*==========================================
  6025. * Wis全拒否許可応答
  6026. *------------------------------------------*/
  6027. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6028. {
  6029. int fd;
  6030. nullpo_retr(0, sd);
  6031. fd=sd->fd;
  6032. WFIFOHEAD(fd,packet_len(0xd2));
  6033. WFIFOW(fd,0)=0xd2;
  6034. WFIFOB(fd,2)=type;
  6035. WFIFOB(fd,3)=flag;
  6036. WFIFOSET(fd,packet_len(0xd2));
  6037. return 0;
  6038. }
  6039. /*==========================================
  6040. * サウンドエフェクト
  6041. *------------------------------------------*/
  6042. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6043. {
  6044. int fd;
  6045. nullpo_retv(sd);
  6046. nullpo_retv(bl);
  6047. fd = sd->fd;
  6048. WFIFOHEAD(fd,packet_len(0x1d3));
  6049. WFIFOW(fd,0) = 0x1d3;
  6050. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6051. WFIFOB(fd,26) = type;
  6052. WFIFOL(fd,27) = 0;
  6053. WFIFOL(fd,31) = bl->id;
  6054. WFIFOSET(fd,packet_len(0x1d3));
  6055. return;
  6056. }
  6057. int clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6058. {
  6059. unsigned char buf[40];
  6060. nullpo_retr(0, bl);
  6061. WBUFW(buf,0) = 0x1d3;
  6062. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6063. WBUFB(buf,26) = type;
  6064. WBUFL(buf,27) = 0;
  6065. WBUFL(buf,31) = bl->id;
  6066. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6067. return 0;
  6068. }
  6069. // displaying special effects (npcs, weather, etc) [Valaris]
  6070. int clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6071. {
  6072. unsigned char buf[24];
  6073. nullpo_retr(0, bl);
  6074. memset(buf, 0, packet_len(0x1f3));
  6075. WBUFW(buf,0) = 0x1f3;
  6076. WBUFL(buf,2) = bl->id;
  6077. WBUFL(buf,6) = type;
  6078. clif_send(buf, packet_len(0x1f3), bl, target);
  6079. if (disguised(bl)) {
  6080. WBUFL(buf,2) = -bl->id;
  6081. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6082. }
  6083. return 0;
  6084. }
  6085. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  6086. {
  6087. WFIFOHEAD(fd,10);
  6088. WFIFOW(fd,0) = 0x1f3;
  6089. WFIFOL(fd,2) = bl->id;
  6090. WFIFOL(fd,6) = type;
  6091. WFIFOSET(fd,10);
  6092. }
  6093. // messages (from mobs/npcs) [Valaris]
  6094. int clif_message(struct block_list* bl, const char* msg)
  6095. {
  6096. unsigned short msg_len = strlen(msg) + 1;
  6097. uint8 buf[256];
  6098. nullpo_retr(0, bl);
  6099. WBUFW(buf,0) = 0x8d;
  6100. WBUFW(buf,2) = msg_len + 8;
  6101. WBUFL(buf,4) = bl->id;
  6102. memcpy(WBUFP(buf,8), msg, msg_len);
  6103. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6104. return 0;
  6105. }
  6106. // refresh the client's screen, getting rid of any effects
  6107. int clif_refresh(struct map_session_data *sd)
  6108. {
  6109. nullpo_retr(-1, sd);
  6110. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6111. clif_inventorylist(sd);
  6112. if(pc_iscarton(sd)) {
  6113. clif_cartlist(sd);
  6114. clif_updatestatus(sd,SP_CARTINFO);
  6115. }
  6116. clif_updatestatus(sd,SP_WEIGHT);
  6117. clif_updatestatus(sd,SP_MAXWEIGHT);
  6118. clif_updatestatus(sd,SP_STR);
  6119. clif_updatestatus(sd,SP_AGI);
  6120. clif_updatestatus(sd,SP_VIT);
  6121. clif_updatestatus(sd,SP_INT);
  6122. clif_updatestatus(sd,SP_DEX);
  6123. clif_updatestatus(sd,SP_LUK);
  6124. if (sd->spiritball)
  6125. clif_spiritball_single(sd->fd, sd);
  6126. if (sd->vd.cloth_color)
  6127. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6128. if(merc_is_hom_active(sd->hd))
  6129. clif_send_homdata(sd,0,0);
  6130. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6131. clif_weather_check(sd);
  6132. #ifndef TXT_ONLY
  6133. mail_clear(sd);
  6134. #endif
  6135. return 0;
  6136. }
  6137. // updates the object's (bl) name on client
  6138. int clif_charnameack (int fd, struct block_list *bl)
  6139. {
  6140. unsigned char buf[103];
  6141. int cmd = 0x95;
  6142. nullpo_retr(0, bl);
  6143. WBUFW(buf,0) = cmd;
  6144. WBUFL(buf,2) = bl->id;
  6145. switch(bl->type) {
  6146. case BL_PC:
  6147. {
  6148. struct map_session_data *ssd = (struct map_session_data *)bl;
  6149. struct party_data *p = NULL;
  6150. struct guild *g = NULL;
  6151. //Requesting your own "shadow" name. [Skotlex]
  6152. if (ssd->fd == fd && ssd->disguise)
  6153. WBUFL(buf,2) = -bl->id;
  6154. if (strlen(ssd->fakename)>1) {
  6155. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6156. break;
  6157. }
  6158. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6159. if (ssd->status.party_id > 0)
  6160. p = party_search(ssd->status.party_id);
  6161. if (ssd->status.guild_id > 0)
  6162. g = guild_search(ssd->status.guild_id);
  6163. if (p == NULL && g == NULL)
  6164. break;
  6165. WBUFW(buf, 0) = cmd = 0x195;
  6166. if (p)
  6167. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6168. else
  6169. WBUFB(buf,30) = 0;
  6170. if (g)
  6171. {
  6172. int i, ps = -1;
  6173. for(i = 0; i < g->max_member; i++) {
  6174. if (g->member[i].account_id == ssd->status.account_id &&
  6175. g->member[i].char_id == ssd->status.char_id )
  6176. {
  6177. ps = g->member[i].position;
  6178. break;
  6179. }
  6180. }
  6181. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6182. {
  6183. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6184. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6185. } else { //Assume no guild.
  6186. WBUFB(buf,54) = 0;
  6187. WBUFB(buf,78) = 0;
  6188. }
  6189. } else {
  6190. WBUFB(buf,54) = 0;
  6191. WBUFB(buf,78) = 0;
  6192. }
  6193. }
  6194. break;
  6195. //[blackhole89]
  6196. case BL_HOM:
  6197. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6198. break;
  6199. case BL_PET:
  6200. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6201. break;
  6202. case BL_NPC:
  6203. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6204. break;
  6205. case BL_MOB:
  6206. {
  6207. struct mob_data *md = (struct mob_data *)bl;
  6208. nullpo_retr(0, md);
  6209. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6210. if (md->guardian_data && md->guardian_data->guild_id) {
  6211. WBUFW(buf, 0) = cmd = 0x195;
  6212. WBUFB(buf,30) = 0;
  6213. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6214. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6215. } else if (battle_config.show_mob_info) {
  6216. char mobhp[50], *str_p = mobhp;
  6217. WBUFW(buf, 0) = cmd = 0x195;
  6218. if (battle_config.show_mob_info&4)
  6219. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6220. if (battle_config.show_mob_info&1)
  6221. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6222. if (battle_config.show_mob_info&2)
  6223. str_p += sprintf(str_p, "HP: %d%% | ", status_calc_life(md->status.hp, md->status.max_hp));
  6224. //Even thought mobhp ain't a name, we send it as one so the client
  6225. //can parse it. [Skotlex]
  6226. if (str_p != mobhp) {
  6227. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6228. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6229. WBUFB(buf,54) = 0;
  6230. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6231. }
  6232. }
  6233. }
  6234. break;
  6235. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6236. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6237. // break;
  6238. return 0;
  6239. default:
  6240. ShowError("clif_parse_GetCharNameRequest : bad type %d(%d)\n", bl->type, bl->id);
  6241. return 0;
  6242. }
  6243. // if no receipient specified just update nearby clients
  6244. if (fd == 0)
  6245. clif_send(buf, packet_len(cmd), bl, AREA);
  6246. else {
  6247. WFIFOHEAD(fd, packet_len(cmd));
  6248. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  6249. WFIFOSET(fd, packet_len(cmd));
  6250. }
  6251. return 0;
  6252. }
  6253. //Used to update when a char leaves a party/guild. [Skotlex]
  6254. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6255. int clif_charnameupdate (struct map_session_data *ssd)
  6256. {
  6257. unsigned char buf[103];
  6258. int cmd = 0x195;
  6259. struct party_data *p = NULL;
  6260. struct guild *g = NULL;
  6261. nullpo_retr(0, ssd);
  6262. if (strlen(ssd->fakename)>1)
  6263. return 0; //No need to update as the party/guild was not displayed anyway.
  6264. WBUFW(buf,0) = cmd;
  6265. WBUFL(buf,2) = ssd->bl.id;
  6266. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6267. if (ssd->status.party_id > 0)
  6268. p = party_search(ssd->status.party_id);
  6269. if (ssd->status.guild_id > 0)
  6270. g = guild_search(ssd->status.guild_id);
  6271. if (p)
  6272. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6273. else
  6274. WBUFB(buf,30) = 0;
  6275. if (g)
  6276. {
  6277. int i, ps = -1;
  6278. for(i = 0; i < g->max_member; i++) {
  6279. if (g->member[i].account_id == ssd->status.account_id &&
  6280. g->member[i].char_id == ssd->status.char_id )
  6281. {
  6282. ps = g->member[i].position;
  6283. break;
  6284. }
  6285. }
  6286. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6287. {
  6288. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6289. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6290. } else { //Assume no guild.
  6291. WBUFB(buf,54) = 0;
  6292. WBUFB(buf,78) = 0;
  6293. }
  6294. } else {
  6295. WBUFB(buf,54) = 0;
  6296. WBUFB(buf,78) = 0;
  6297. }
  6298. // Update nearby clients
  6299. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  6300. return 0;
  6301. }
  6302. int clif_slide(struct block_list *bl, int x, int y){
  6303. unsigned char buf[10];
  6304. nullpo_retr(0, bl);
  6305. WBUFW(buf, 0) = 0x01ff;
  6306. WBUFL(buf, 2) = bl->id;
  6307. WBUFW(buf, 6) = x;
  6308. WBUFW(buf, 8) = y;
  6309. clif_send(buf, packet_len(0x1ff), bl, AREA);
  6310. return 0;
  6311. }
  6312. /*------------------------------------------
  6313. * @me command by lordalfa, rewritten implementation by Skotlex
  6314. *------------------------------------------*/
  6315. int clif_disp_overhead(struct map_session_data *sd, const char* mes)
  6316. {
  6317. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  6318. int len_mes = strlen(mes)+1; //Account for \0
  6319. if (len_mes + 8 >= 256) {
  6320. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6321. len_mes = 247; //Trunk it to avoid problems.
  6322. }
  6323. // send message to others
  6324. WBUFW(buf,0) = 0x8d;
  6325. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6326. WBUFL(buf,4) = sd->bl.id;
  6327. memcpy(WBUFP(buf,8), mes, len_mes);
  6328. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6329. // send back message to the speaker
  6330. WBUFW(buf,0) = 0x8e;
  6331. WBUFW(buf, 2) = len_mes + 4;
  6332. memcpy(WBUFP(buf,4), mes, len_mes);
  6333. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6334. return 0;
  6335. }
  6336. /*==========================
  6337. * Minimap fix [Kevin]
  6338. * Remove dot from minimap
  6339. *--------------------------*/
  6340. int clif_party_xy_remove(struct map_session_data *sd)
  6341. {
  6342. unsigned char buf[16];
  6343. nullpo_retr(0, sd);
  6344. WBUFW(buf,0)=0x107;
  6345. WBUFL(buf,2)=sd->status.account_id;
  6346. WBUFW(buf,6)=-1;
  6347. WBUFW(buf,8)=-1;
  6348. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6349. return 0;
  6350. }
  6351. //Displays gospel-buff information (thanks to Rayce):
  6352. //Type determines message based on this table:
  6353. /*
  6354. 0x15 End all negative status
  6355. 0x16 Immunity to all status
  6356. 0x17 MaxHP +100%
  6357. 0x18 MaxSP +100%
  6358. 0x19 All stats +20
  6359. 0x1c Enchant weapon with Holy element
  6360. 0x1d Enchant armor with Holy element
  6361. 0x1e DEF +25%
  6362. 0x1f ATK +100%
  6363. 0x20 HIT/Flee +50
  6364. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  6365. */
  6366. void clif_gospel_info(struct map_session_data *sd, int type)
  6367. {
  6368. int fd=sd->fd;
  6369. WFIFOHEAD(fd,packet_len(0x215));
  6370. WFIFOW(fd,0)=0x215;
  6371. WFIFOL(fd,2)=type;
  6372. WFIFOSET(fd, packet_len(0x215));
  6373. }
  6374. /*==========================================
  6375. * Info about Star Glaldiator save map [Komurka]
  6376. * type: 1: Information, 0: Map registered
  6377. *------------------------------------------*/
  6378. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  6379. {
  6380. int fd=sd->fd;
  6381. WFIFOHEAD(fd,packet_len(0x20e));
  6382. WFIFOW(fd,0) = 0x20e;
  6383. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), (char*)WFIFOP(fd,2));
  6384. WFIFOL(fd,26) = sd->bl.id;
  6385. WFIFOB(fd,30) = feel_level;
  6386. WFIFOB(fd,31) = type?1:0;
  6387. WFIFOSET(fd,packet_len(0x20e));
  6388. }
  6389. /*==========================================
  6390. * Info about Star Glaldiator hate mob [Komurka]
  6391. * type: 1: Register mob, 0: Information.
  6392. *------------------------------------------*/
  6393. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  6394. {
  6395. int fd=sd->fd;
  6396. WFIFOHEAD(fd,packet_len(0x20e));
  6397. WFIFOW(fd,0)=0x20e;
  6398. if (pcdb_checkid(class_))
  6399. strncpy((char*)WFIFOP(fd,2),job_name(class_), NAME_LENGTH);
  6400. else if (mobdb_checkid(class_))
  6401. strncpy((char*)WFIFOP(fd,2),mob_db(class_)->jname, NAME_LENGTH);
  6402. else //Really shouldn't happen...
  6403. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  6404. WFIFOL(fd,26)=sd->bl.id;
  6405. WFIFOB(fd,30)=hate_level;
  6406. WFIFOB(fd,31)=type?10:11; //Register/Info
  6407. WFIFOSET(fd, packet_len(0x20e));
  6408. }
  6409. /*==========================================
  6410. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6411. *------------------------------------------*/
  6412. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  6413. {
  6414. int fd=sd->fd;
  6415. WFIFOHEAD(fd,packet_len(0x20e));
  6416. WFIFOW(fd,0)=0x20e;
  6417. strncpy((char*)WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6418. WFIFOL(fd,26)=mob_id;
  6419. WFIFOB(fd,30)=progress; //Message to display
  6420. WFIFOB(fd,31)=20;
  6421. WFIFOSET(fd, packet_len(0x20e));
  6422. }
  6423. /*==========================================
  6424. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  6425. *------------------------------------------*/
  6426. void clif_feel_hate_reset(struct map_session_data *sd)
  6427. {
  6428. int fd=sd->fd;
  6429. WFIFOHEAD(fd,packet_len(0x20e));
  6430. WFIFOW(fd,0)=0x20e;
  6431. memset(WFIFOP(fd,2), 0, NAME_LENGTH); //Blank name as all was reset.
  6432. WFIFOL(fd,26)=sd->bl.id;
  6433. WFIFOB(fd,30)=0; //Feel/hate level: irrelevant
  6434. WFIFOB(fd,31)=30;
  6435. WFIFOSET(fd, packet_len(0x20e));
  6436. }
  6437. /*==========================================
  6438. * Equip window (un)tick ack
  6439. * R 02d9 <zero>.L <flag>.L
  6440. *------------------------------------------*/
  6441. void clif_equiptickack(struct map_session_data* sd, int flag)
  6442. {
  6443. int fd;
  6444. nullpo_retv(sd);
  6445. fd = sd->fd;
  6446. WFIFOHEAD(fd, packet_len(0x2d9));
  6447. WFIFOW(fd, 0) = 0x2d9;
  6448. WFIFOL(fd, 2) = 0;
  6449. WFIFOL(fd, 6) = flag;
  6450. WFIFOSET(fd, packet_len(0x2d9));
  6451. }
  6452. /*==========================================
  6453. * The player's 'view equip' state, sent during login
  6454. * R 02da <flag>.B
  6455. *------------------------------------------*/
  6456. void clif_equipcheckbox(struct map_session_data* sd)
  6457. {
  6458. int fd;
  6459. nullpo_retv(sd);
  6460. fd = sd->fd;
  6461. WFIFOHEAD(fd, packet_len(0x2da));
  6462. WFIFOW(fd, 0) = 0x2da;
  6463. WFIFOW(fd, 2) = (sd->status.show_equip ? 1 : 0);
  6464. WFIFOSET(fd, packet_len(0x2da));
  6465. }
  6466. /*==========================================
  6467. * Sends info about a player's equipped items
  6468. * 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*
  6469. *------------------------------------------*/
  6470. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  6471. {
  6472. int i, n, fd;
  6473. nullpo_retv(sd);
  6474. nullpo_retv(tsd);
  6475. fd = sd->fd;
  6476. WFIFOHEAD(fd, MAX_INVENTORY * 26 + 43);
  6477. WFIFOW(fd, 0) = 0x2d7;
  6478. safestrncpy((char*)WFIFOP(fd, 4), tsd->status.name, NAME_LENGTH);
  6479. WFIFOW(fd,28) = tsd->status.class_;
  6480. WFIFOW(fd,30) = tsd->vd.hair_style;
  6481. WFIFOW(fd,32) = tsd->vd.head_top;
  6482. WFIFOW(fd,34) = tsd->vd.head_mid;
  6483. WFIFOW(fd,36) = tsd->vd.head_bottom;
  6484. WFIFOW(fd,38) = tsd->vd.hair_color;
  6485. WFIFOW(fd,40) = tsd->vd.cloth_color;
  6486. WFIFOB(fd,42) = tsd->vd.sex;
  6487. for(i=0,n=0; i < MAX_INVENTORY; i++)
  6488. {
  6489. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  6490. continue;
  6491. if (itemdb_isstackable2(tsd->inventory_data[i])) // Is not equippable
  6492. continue;
  6493. // Inventory position
  6494. WFIFOW(fd, n*26+43) = i + 2;
  6495. // Add refine, identify flag, element, etc.
  6496. clif_item_sub(WFIFOP(fd,0), n*26+45, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  6497. // Add cards
  6498. clif_addcards(WFIFOP(fd, n*26+55), &tsd->status.inventory[i]);
  6499. // Expiration date stuff, if all of those are set to 0 then the client doesn't show anything related (6 bytes)
  6500. memset(WFIFOP(fd, n*26+63), 0, 6);
  6501. n++;
  6502. }
  6503. WFIFOW(fd, 2) = 43 + n*26; // Set length
  6504. WFIFOSET(fd, WFIFOW(fd, 2));
  6505. }
  6506. /*==========================================
  6507. * View player equip request denied
  6508. * R 0291 <message>.W
  6509. * TODO: this looks like a general-purpose packet to print msgstringtable entries.
  6510. *------------------------------------------*/
  6511. void clif_viewequip_fail(struct map_session_data* sd)
  6512. {
  6513. int fd;
  6514. nullpo_retv(sd);
  6515. fd = sd->fd;
  6516. WFIFOHEAD(fd, packet_len(0x291));
  6517. WFIFOW(fd, 0) = 0x291;
  6518. WFIFOW(fd, 2) = 0x54d; // This controls which message is displayed. 0x54d is the correct one. Maybe it's used for something else too?
  6519. WFIFOSET(fd, packet_len(0x291));
  6520. }
  6521. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  6522. /// Returns true if the packet was parsed successfully.
  6523. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  6524. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  6525. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  6526. {
  6527. char *text, *name, *message;
  6528. unsigned int packetlen, textlen, namelen, messagelen;
  6529. int fd = sd->fd;
  6530. *name_ = NULL;
  6531. *namelen_ = 0;
  6532. *message_ = NULL;
  6533. *messagelen_ = 0;
  6534. packetlen = RFIFOW(fd,2);
  6535. // basic structure checks
  6536. if( packetlen > RFIFOREST(fd) )
  6537. { // there has to be enough data to read
  6538. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6539. return false;
  6540. }
  6541. if( packetlen < 4 + 1 )
  6542. { // 4-byte header and at least an empty string is expected
  6543. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  6544. return false;
  6545. }
  6546. text = (char*)RFIFOP(fd,4);
  6547. textlen = packetlen - 4;
  6548. // process <name> part of the packet
  6549. if( format == 0 )
  6550. {// name and message are separated by ' : '
  6551. // validate name
  6552. name = text;
  6553. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  6554. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  6555. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  6556. {
  6557. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  6558. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  6559. clif_setwaitclose(fd); // Just kick them out to correct it.
  6560. return false;
  6561. }
  6562. message = name + namelen + 3;
  6563. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  6564. }
  6565. else
  6566. {// name has fixed width
  6567. if( textlen < NAME_LENGTH + 1 )
  6568. {
  6569. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6570. return false;
  6571. }
  6572. // validate name
  6573. name = text;
  6574. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  6575. if( name[namelen] != '\0' )
  6576. { // only restriction is that the name must be zero-terminated
  6577. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  6578. return false;
  6579. }
  6580. message = name + NAME_LENGTH;
  6581. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  6582. }
  6583. if( messagelen != strnlen(message, messagelen)+1 )
  6584. { // the declared length must match real length
  6585. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  6586. return false;
  6587. }
  6588. // verify <message> part of the packet
  6589. if( message[messagelen-1] != '\0' )
  6590. { // message must be zero-terminated
  6591. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  6592. return false;
  6593. }
  6594. if( messagelen > CHAT_SIZE_MAX )
  6595. { // messages mustn't be too long
  6596. // Normally you can only enter CHATBOX_SIZE-1 chars into the chat box, but Frost Joke / Dazzler's text can be longer.
  6597. // Neither the official client nor server place any restriction on the length of the text in the packet,
  6598. // but we'll only allow reasonably long strings here. This also makes sure all strings fit into the `chatlog` table.
  6599. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX, message);
  6600. return false;
  6601. }
  6602. *name_ = name;
  6603. *namelen_ = namelen;
  6604. *message_ = message;
  6605. *messagelen_ = messagelen;
  6606. return true;
  6607. }
  6608. // ---------------------
  6609. // clif_guess_PacketVer
  6610. // ---------------------
  6611. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  6612. // error codes:
  6613. // 0 - Success
  6614. // 1 - Unknown packet_ver
  6615. // 2 - Invalid account_id
  6616. // 3 - Invalid char_id
  6617. // 4 - Invalid login_id1 (reserved)
  6618. // 5 - Invalid client_tick (reserved)
  6619. // 6 - Invalid sex
  6620. // Only the first 'invalid' error that appears is used.
  6621. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  6622. {
  6623. static int err = 1;
  6624. static int packet_ver = -1;
  6625. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  6626. if (get_previous)
  6627. {//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]
  6628. if( error )
  6629. *error = err;
  6630. return packet_ver;
  6631. }
  6632. //By default, start searching on the default one.
  6633. err = 1;
  6634. packet_ver = clif_config.packet_db_ver;
  6635. cmd = RFIFOW(fd,0);
  6636. packet_len = RFIFOREST(fd);
  6637. #define SET_ERROR(n) \
  6638. if( err == 1 )\
  6639. err = n;\
  6640. //define SET_ERROR
  6641. #define CHECK_PACKET_VER() \
  6642. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  6643. ;/* not wanttoconnection or wrong length */\
  6644. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > max_account_id )\
  6645. { SET_ERROR(2); }/* invalid account_id */\
  6646. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 || value > max_char_id )\
  6647. { SET_ERROR(3); }/* invalid char_id */\
  6648. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  6649. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  6650. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  6651. { SET_ERROR(6); }/* invalid sex */\
  6652. else\
  6653. {\
  6654. err = 0;\
  6655. if( error )\
  6656. *error = 0;\
  6657. return packet_ver;\
  6658. }\
  6659. //define CHECK_PACKET_VER
  6660. CHECK_PACKET_VER();//Default packet version found.
  6661. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  6662. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  6663. CHECK_PACKET_VER();
  6664. }
  6665. if( error )
  6666. *error = err;
  6667. packet_ver = -1;
  6668. return -1;
  6669. #undef SET_ERROR
  6670. #undef CHECK_PACKET_VER
  6671. }
  6672. // ------------
  6673. // clif_parse_*
  6674. // ------------
  6675. // パケット読み取って色々操作
  6676. /*==========================================
  6677. *
  6678. *------------------------------------------*/
  6679. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  6680. {
  6681. struct block_list* bl;
  6682. struct auth_node* node;
  6683. int cmd, account_id, char_id, login_id1, sex;
  6684. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  6685. 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])
  6686. if (sd) {
  6687. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  6688. return;
  6689. }
  6690. // Only valid packet version get here
  6691. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  6692. cmd = RFIFOW(fd,0);
  6693. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  6694. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  6695. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  6696. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  6697. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  6698. if( packet_ver < 5 || // reject really old client versions
  6699. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  6700. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  6701. {// packet version rejected
  6702. 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));
  6703. WFIFOHEAD(fd,packet_len(0x6a));
  6704. WFIFOW(fd,0) = 0x6a;
  6705. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  6706. WFIFOSET(fd,packet_len(0x6a));
  6707. clif_setwaitclose(fd);
  6708. return;
  6709. }
  6710. //Check for double login.
  6711. bl = map_id2bl(account_id);
  6712. if(bl && bl->type != BL_PC) {
  6713. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  6714. WFIFOHEAD(fd,packet_len(0x6a));
  6715. WFIFOW(fd,0) = 0x6a;
  6716. WFIFOB(fd,2) = 3; // Rejected by server
  6717. WFIFOSET(fd,packet_len(0x6a));
  6718. clif_setwaitclose(fd);
  6719. return;
  6720. }
  6721. if (bl ||
  6722. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  6723. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN))) {
  6724. sd = BL_CAST(BL_PC, bl);
  6725. if (!sd)
  6726. ; //We have another char with the same account logging in/out.
  6727. else //Already connected player.
  6728. if (sd->fd)
  6729. clif_authfail_fd(sd->fd, 2); //someone else logged in
  6730. else
  6731. if(sd->state.autotrade)
  6732. map_quit(sd);// kick autotrading character
  6733. //Else do not kick character, it could be on its 10 sec penalty for Alt+F4
  6734. clif_authfail_fd(fd, 8); //Still recognizes last connection
  6735. return;
  6736. }
  6737. CREATE(sd, TBL_PC, 1);
  6738. sd->fd = fd;
  6739. sd->packet_ver = packet_ver;
  6740. session[fd]->session_data = sd;
  6741. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  6742. #if PACKETVER < 8
  6743. WFIFOHEAD(fd,4);
  6744. WFIFOL(fd,0) = sd->bl.id;
  6745. WFIFOSET(fd,4);
  6746. #else
  6747. WFIFOHEAD(fd,packet_len(0x283));
  6748. WFIFOW(fd,0) = 0x283;
  6749. WFIFOL(fd,2) = sd->bl.id;
  6750. WFIFOSET(fd,packet_len(0x283));
  6751. #endif
  6752. chrif_authreq(sd);
  6753. return;
  6754. }
  6755. /*==========================================
  6756. * 007d クライアント側マップ読み込み完了
  6757. * map侵入時に必要なデータを全て送りつける
  6758. *------------------------------------------*/
  6759. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  6760. {
  6761. if(sd->bl.prev != NULL)
  6762. return;
  6763. if (!sd->state.active)
  6764. { //Character loading is not complete yet!
  6765. //Let pc_reg_received reinvoke this when ready.
  6766. sd->state.connect_new = 0;
  6767. return;
  6768. }
  6769. if (sd->state.rewarp)
  6770. { //Rewarp player.
  6771. sd->state.rewarp = 0;
  6772. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  6773. return;
  6774. }
  6775. // look
  6776. #if PACKETVER < 4
  6777. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  6778. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  6779. #else
  6780. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  6781. #endif
  6782. if(sd->vd.cloth_color)
  6783. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6784. // item
  6785. pc_checkitem(sd);
  6786. clif_inventorylist(sd);
  6787. // cart
  6788. if(pc_iscarton(sd)) {
  6789. clif_cartlist(sd);
  6790. clif_updatestatus(sd,SP_CARTINFO);
  6791. }
  6792. // weight
  6793. clif_updatestatus(sd,SP_WEIGHT);
  6794. clif_updatestatus(sd,SP_MAXWEIGHT);
  6795. // guild
  6796. // (needs to go before clif_spawn() to show guild emblems correctly)
  6797. if(sd->status.guild_id)
  6798. guild_send_memberinfoshort(sd,1);
  6799. if(battle_config.pc_invincible_time > 0) {
  6800. if(map_flag_gvg(sd->bl.m))
  6801. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  6802. else
  6803. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  6804. }
  6805. if (map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs) //Skotlex
  6806. map_spawnmobs(sd->bl.m);
  6807. map_addblock(&sd->bl);
  6808. clif_spawn(&sd->bl);
  6809. // Party
  6810. // (needs to go after clif_spawn() to show hp bars correctly)
  6811. if(sd->status.party_id) {
  6812. party_send_movemap(sd);
  6813. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  6814. }
  6815. if(map[sd->bl.m].flag.pvp) {
  6816. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  6817. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  6818. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  6819. sd->pvp_rank = 0;
  6820. sd->pvp_lastusers = 0;
  6821. sd->pvp_point = 5;
  6822. sd->pvp_won = 0;
  6823. sd->pvp_lost = 0;
  6824. }
  6825. clif_set0199(sd,1);
  6826. } else
  6827. // set flag, if it's a duel [LuzZza]
  6828. if(sd->duel_group)
  6829. clif_set0199(sd,1);
  6830. if (map[sd->bl.m].flag.gvg_dungeon)
  6831. {
  6832. clif_set0199(sd,1); //TODO: Figure out the real packet to send here.
  6833. if (!sd->pvp_point)
  6834. {
  6835. sd->pvp_point = 5; //Need to die twice to be warped out.
  6836. sd->pvp_won = 0;
  6837. sd->pvp_lost = 0;
  6838. }
  6839. }
  6840. if(map_flag_gvg(sd->bl.m))
  6841. clif_set0199(sd,3);
  6842. // info about nearby objects
  6843. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  6844. 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);
  6845. //TODO: merge it with the code below
  6846. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) && sd->pd)
  6847. { //Return the pet to egg. [Skotlex]
  6848. clif_displaymessage(sd->fd, "Pets are not allowed in Guild Wars.");
  6849. pet_menu(sd, 3); //Option 3 is return to egg.
  6850. }
  6851. // pet
  6852. if(sd->pd) {
  6853. map_addblock(&sd->pd->bl);
  6854. clif_spawn(&sd->pd->bl);
  6855. clif_send_petdata(sd,sd->pd,0,0);
  6856. clif_send_petstatus(sd);
  6857. // skill_unit_move(&sd->pd->bl,gettick(),1);
  6858. }
  6859. //homunculus [blackhole89]
  6860. if(merc_is_hom_active(sd->hd)) {
  6861. map_addblock(&sd->hd->bl);
  6862. clif_spawn(&sd->hd->bl);
  6863. clif_send_homdata(sd,0,0);
  6864. clif_hominfo(sd,sd->hd,1);
  6865. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  6866. clif_homskillinfoblock(sd);
  6867. if (battle_config.hom_setting&0x8)
  6868. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  6869. if (!(battle_config.hom_setting&0x2))
  6870. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  6871. }
  6872. if(sd->state.connect_new) {
  6873. int lv;
  6874. sd->state.connect_new = 0;
  6875. clif_skillinfoblock(sd);
  6876. clif_hotkeys_send(sd);
  6877. clif_updatestatus(sd,SP_NEXTBASEEXP);
  6878. clif_updatestatus(sd,SP_NEXTJOBEXP);
  6879. clif_updatestatus(sd,SP_SKILLPOINT);
  6880. clif_initialstatus(sd);
  6881. if (sd->sc.option&OPTION_FALCON)
  6882. clif_status_load(&sd->bl, SI_FALCON, 1);
  6883. if (sd->sc.option&OPTION_RIDING)
  6884. clif_status_load(&sd->bl, SI_RIDING, 1);
  6885. if(sd->status.manner < 0)
  6886. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  6887. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  6888. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  6889. if(sd->bl.m == sd->feel_map[0].m
  6890. || sd->bl.m == sd->feel_map[1].m
  6891. || sd->bl.m == sd->feel_map[2].m)
  6892. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  6893. }
  6894. if(sd->pd && sd->pd->pet.intimate > 900)
  6895. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  6896. if(merc_is_hom_active(sd->hd))
  6897. merc_hom_init_timers(sd->hd);
  6898. if (night_flag && map[sd->bl.m].flag.nightenabled)
  6899. {
  6900. sd->state.night = 1;
  6901. clif_status_load(&sd->bl, SI_NIGHT, 1);
  6902. }
  6903. #if PACKETVER >= 9
  6904. clif_equipcheckbox(sd);
  6905. #endif
  6906. // Notify everyone that this char logged in [Skotlex].
  6907. clif_foreachclient(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  6908. //Login Event
  6909. npc_script_event(sd, NPCE_LOGIN);
  6910. mob_barricade_get(sd);
  6911. } else {
  6912. //For some reason the client "loses" these on map-change.
  6913. clif_updatestatus(sd,SP_STR);
  6914. clif_updatestatus(sd,SP_AGI);
  6915. clif_updatestatus(sd,SP_VIT);
  6916. clif_updatestatus(sd,SP_INT);
  6917. clif_updatestatus(sd,SP_DEX);
  6918. clif_updatestatus(sd,SP_LUK);
  6919. }
  6920. if( sd->state.changemap )
  6921. {
  6922. if (night_flag && map[sd->bl.m].flag.nightenabled)
  6923. { //Display night.
  6924. if( !sd->state.night )
  6925. {
  6926. sd->state.night = 1;
  6927. clif_status_load(&sd->bl, SI_NIGHT, 1);
  6928. }
  6929. }
  6930. else if( sd->state.night )
  6931. { //Clear night display.
  6932. sd->state.night = 0;
  6933. clif_status_load(&sd->bl, SI_NIGHT, 0);
  6934. }
  6935. mob_barricade_get(sd);
  6936. sd->state.changemap = false;
  6937. }
  6938. sd->state.using_fake_npc = 0;
  6939. if(sd->npc_id)
  6940. npc_event_dequeue(sd);
  6941. #ifndef TXT_ONLY
  6942. mail_clear(sd);
  6943. #endif
  6944. if(map[sd->bl.m].flag.loadevent) // Lance
  6945. npc_script_event(sd, NPCE_LOADMAP);
  6946. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  6947. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  6948. if (sd->sc.opt2) //Client loses these on warp.
  6949. clif_changeoption(&sd->bl);
  6950. clif_weather_check(sd);
  6951. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  6952. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  6953. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  6954. else
  6955. sd->areanpc_id = 0;
  6956. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  6957. if(pc_isdead(sd))
  6958. clif_clearunit_area(&sd->bl, 1);
  6959. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  6960. // else
  6961. // clif_changed_dir(&sd->bl, SELF);
  6962. // Trigger skill effects if you appear standing on them
  6963. if(!battle_config.pc_invincible_time)
  6964. skill_unit_move(&sd->bl,gettick(),1);
  6965. }
  6966. /*==========================================
  6967. *
  6968. *------------------------------------------*/
  6969. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  6970. {
  6971. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  6972. WFIFOHEAD(fd, packet_len(0x7f));
  6973. WFIFOW(fd,0)=0x7f;
  6974. WFIFOL(fd,2)=gettick();
  6975. WFIFOSET(fd,packet_len(0x7f));
  6976. // removed until the socket problems are fixed. [FlavioJS]
  6977. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  6978. return;
  6979. }
  6980. void clif_hotkeys_send(struct map_session_data *sd) {
  6981. #ifdef HOTKEY_SAVING
  6982. const int fd = sd->fd;
  6983. int i;
  6984. if (!fd) return;
  6985. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  6986. WFIFOW(fd, 0) = 0x02b9;
  6987. for(i = 0; i < MAX_HOTKEYS; i++) {
  6988. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  6989. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  6990. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  6991. }
  6992. WFIFOSET(fd, packet_len(0x02b9));
  6993. #endif
  6994. }
  6995. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  6996. #ifdef HOTKEY_SAVING
  6997. unsigned short idx;
  6998. int cmd;
  6999. cmd = RFIFOW(fd, 0);
  7000. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  7001. if (idx >= MAX_HOTKEYS) return;
  7002. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  7003. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  7004. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  7005. return;
  7006. #endif
  7007. }
  7008. /*==========================================
  7009. *
  7010. *------------------------------------------*/
  7011. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  7012. {
  7013. short x, y;
  7014. int cmd;
  7015. if (pc_isdead(sd)) {
  7016. clif_clearunit_area(&sd->bl, 1);
  7017. return;
  7018. }
  7019. if (sd->sc.opt1 && sd->sc.opt1 == OPT1_STONEWAIT)
  7020. ; //You CAN walk on this OPT1 value.
  7021. else if (pc_cant_act(sd))
  7022. return;
  7023. if(sd->sc.data[SC_RUN])
  7024. return;
  7025. pc_delinvincibletimer(sd);
  7026. cmd = RFIFOW(fd,0);
  7027. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7028. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7029. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7030. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7031. //Set last idle time... [Skotlex]
  7032. sd->idletime = last_tick;
  7033. unit_walktoxy(&sd->bl, x, y, 4);
  7034. }
  7035. /*==========================================
  7036. *
  7037. *------------------------------------------*/
  7038. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  7039. {
  7040. WFIFOHEAD(fd,packet_len(0x18b));
  7041. WFIFOW(fd,0) = 0x18b;
  7042. /* Rovert's prevent logout option fixed [Valaris] */
  7043. if (!sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] &&
  7044. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7045. ) {
  7046. clif_setwaitclose(fd);
  7047. WFIFOW(fd,2)=0;
  7048. } else {
  7049. WFIFOW(fd,2)=1;
  7050. }
  7051. WFIFOSET(fd,packet_len(0x18b));
  7052. }
  7053. /*==========================================
  7054. *
  7055. *------------------------------------------*/
  7056. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  7057. {
  7058. int account_id;
  7059. struct block_list* bl;
  7060. struct status_change *sc;
  7061. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7062. if(account_id<0 && -account_id == sd->bl.id) // for disguises [Valaris]
  7063. account_id= sd->bl.id;
  7064. bl = map_id2bl(account_id);
  7065. //Is this possible? Lagged clients could request names of already gone mobs/players. [Skotlex]
  7066. if (!bl) return;
  7067. sc = status_get_sc(bl);
  7068. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  7069. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  7070. pc_isGM(sd) < battle_config.hack_info_GM_level
  7071. ) {
  7072. //GM characters (with client side GM enabled are able to see invisible stuff) [Lance]
  7073. //Asked name of invisible player, this shouldn't be possible!
  7074. //Possible bot? Thanks to veider and qspirit
  7075. //FIXME: Still isn't perfected as clients keep asking for this on legitimate situations.
  7076. char gm_msg[256];
  7077. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requested the name of an invisible target.\n", sd->status.name, sd->status.account_id);
  7078. ShowWarning(gm_msg);
  7079. // information is sended to all online GM
  7080. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7081. return;
  7082. }
  7083. clif_charnameack(fd, bl);
  7084. }
  7085. /*==========================================
  7086. * Validates and processes global messages
  7087. * S 008c/00f3 <packet len>.w <text>.?B (<name> : <message>) 00
  7088. *------------------------------------------*/
  7089. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  7090. {
  7091. const char* text = (char*)RFIFOP(fd,4);
  7092. int textlen = RFIFOW(fd,2) - 4;
  7093. char *name, *message;
  7094. int namelen, messagelen;
  7095. // validate packet and retrieve name and message
  7096. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  7097. return;
  7098. if( is_atcommand(fd, sd, message) || is_charcommand(fd, sd, message) )
  7099. return;
  7100. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  7101. return;
  7102. if( battle_config.min_chat_delay )
  7103. { //[Skotlex]
  7104. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7105. return;
  7106. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7107. }
  7108. // send message to others (using the send buffer for temp. storage)
  7109. WFIFOHEAD(fd, 8 + textlen);
  7110. WFIFOW(fd,0) = 0x8d;
  7111. WFIFOW(fd,2) = 8 + textlen;
  7112. WFIFOL(fd,4) = sd->bl.id;
  7113. safestrncpy((char*)WFIFOP(fd,8), text, textlen);
  7114. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7115. // send back message to the speaker
  7116. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7117. WFIFOW(fd,0) = 0x8e;
  7118. WFIFOSET(fd, WFIFOW(fd,2));
  7119. #ifdef PCRE_SUPPORT
  7120. // trigger listening mobs/npcs
  7121. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  7122. map_foreachinrange(mob_chat_sub, &sd->bl, AREA_SIZE, BL_MOB, text, textlen, &sd->bl);
  7123. #endif
  7124. // check for special supernovice phrase
  7125. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE )
  7126. {
  7127. int next = pc_nextbaseexp(sd);
  7128. if( next > 0 && (sd->status.base_exp * 1000 / next)% 100 == 0 ) { // 0%, 10%, 20%, ...
  7129. switch (sd->state.snovice_call_flag) {
  7130. case 0:
  7131. if( strstr(message, msg_txt(504)) ) // "Guardian Angel, can you hear my voice? ^^;"
  7132. sd->state.snovice_call_flag++;
  7133. break;
  7134. case 1: {
  7135. char buf[256];
  7136. sprintf(buf, msg_txt(505), sd->status.name);
  7137. if( strstr(message, buf) ) // "My name is %s, and I'm a Super Novice~"
  7138. sd->state.snovice_call_flag++;
  7139. }
  7140. break;
  7141. case 2:
  7142. if( strstr(message, msg_txt(506)) ) // "Please help me~ T.T"
  7143. sd->state.snovice_call_flag++;
  7144. break;
  7145. case 3:
  7146. if( skillnotok(MO_EXPLOSIONSPIRITS,sd) )
  7147. break; //Do not override the noskill mapflag. [Skotlex]
  7148. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7149. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  7150. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7151. sd->state.snovice_call_flag = 0;
  7152. break;
  7153. }
  7154. }
  7155. }
  7156. // Chat logging type 'O' / Global Chat
  7157. if( log_config.chat&1 || (log_config.chat&2 && !(agit_flag && log_config.chat&64)) )
  7158. log_chat("O", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7159. return;
  7160. }
  7161. /*==========================================
  7162. * /mm /mapmove (as @rura GM command)
  7163. *------------------------------------------*/
  7164. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  7165. {
  7166. char output[MAP_NAME_LENGTH_EXT+15]; // Max length of a short: ' -6XXXX' -> 7 digits
  7167. char message[MAP_NAME_LENGTH_EXT+15+5]; // "/mm "+output
  7168. char* map_name;
  7169. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7170. return;
  7171. if(pc_isGM(sd) < get_atcommand_level(atcommand_mapmove))
  7172. return;
  7173. map_name = (char*)RFIFOP(fd,2);
  7174. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  7175. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7176. atcommand_mapmove(fd, sd, "@mapmove", output);
  7177. if( log_config.gm && get_atcommand_level(atcommand_mapmove) >= log_config.gm )
  7178. {
  7179. sprintf(message, "/mm %s", output);
  7180. log_atcommand(sd, message);
  7181. }
  7182. return;
  7183. }
  7184. /*==========================================
  7185. *
  7186. *------------------------------------------*/
  7187. void clif_changed_dir(struct block_list *bl, int type)
  7188. {
  7189. unsigned char buf[64];
  7190. WBUFW(buf,0) = 0x9c;
  7191. WBUFL(buf,2) = bl->id;
  7192. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7193. WBUFB(buf,8) = unit_getdir(bl);
  7194. clif_send(buf, packet_len(0x9c), bl, type);
  7195. if (disguised(bl)) {
  7196. WBUFL(buf,2) = -bl->id;
  7197. WBUFW(buf,6) = 0;
  7198. clif_send(buf, packet_len(0x9c), bl, SELF);
  7199. }
  7200. return;
  7201. }
  7202. /*==========================================
  7203. *
  7204. *------------------------------------------*/
  7205. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  7206. {
  7207. unsigned char headdir, dir;
  7208. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7209. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7210. pc_setdir(sd, dir, headdir);
  7211. clif_changed_dir(&sd->bl, AREA_WOS);
  7212. return;
  7213. }
  7214. /*==========================================
  7215. *
  7216. *------------------------------------------*/
  7217. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  7218. {
  7219. unsigned char buf[64];
  7220. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7221. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7222. clif_skill_fail(sd, 1, 0, 1);
  7223. return;
  7224. }
  7225. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7226. if (sd->emotionlasttime >= time(NULL)) {
  7227. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7228. clif_skill_fail(sd, 1, 0, 1);
  7229. return;
  7230. }
  7231. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7232. WBUFW(buf,0) = 0xc0;
  7233. WBUFL(buf,2) = sd->bl.id;
  7234. WBUFB(buf,6) = RFIFOB(fd,2);
  7235. clif_send(buf, packet_len(0xc0), &sd->bl, AREA);
  7236. } else
  7237. clif_skill_fail(sd, 1, 0, 1);
  7238. }
  7239. /*==========================================
  7240. *
  7241. *------------------------------------------*/
  7242. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  7243. {
  7244. WFIFOHEAD(fd,packet_len(0xc2));
  7245. WFIFOW(fd,0) = 0xc2;
  7246. WFIFOL(fd,2) = map_getusers();
  7247. WFIFOSET(fd,packet_len(0xc2));
  7248. }
  7249. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7250. {
  7251. if (pc_isdead(sd)) {
  7252. clif_clearunit_area(&sd->bl, 1);
  7253. return;
  7254. }
  7255. if (sd->sc.count &&
  7256. (sd->sc.data[SC_TRICKDEAD] ||
  7257. sd->sc.data[SC_AUTOCOUNTER] ||
  7258. sd->sc.data[SC_BLADESTOP]))
  7259. return;
  7260. pc_stop_walking(sd, 1);
  7261. pc_stop_attack(sd);
  7262. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7263. target_id = sd->bl.id;
  7264. switch(action_type)
  7265. {
  7266. case 0x00: // once attack
  7267. case 0x07: // continuous attack
  7268. if (pc_cant_act(sd) || sd->sc.option&OPTION_HIDE)
  7269. return;
  7270. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  7271. return;
  7272. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7273. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7274. clif_skill_fail(sd, 1, 4, 0);
  7275. return;
  7276. }
  7277. }
  7278. pc_delinvincibletimer(sd);
  7279. sd->idletime = last_tick;
  7280. unit_attack(&sd->bl, target_id, action_type != 0);
  7281. break;
  7282. case 0x02: // sitdown
  7283. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7284. clif_skill_fail(sd, 1, 0, 2);
  7285. break;
  7286. }
  7287. if(pc_issit(sd)) {
  7288. //Bugged client? Just refresh them.
  7289. clif_sitting(&sd->bl);
  7290. return;
  7291. }
  7292. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7293. break;
  7294. if (sd->sc.count && (
  7295. sd->sc.data[SC_DANCING] ||
  7296. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  7297. )) //No sitting during these states either.
  7298. break;
  7299. pc_setsit(sd);
  7300. skill_sit(sd,1);
  7301. clif_sitting(&sd->bl);
  7302. break;
  7303. case 0x03: // standup
  7304. if (!pc_issit(sd)) {
  7305. //Bugged client? Just refresh them.
  7306. clif_standing(&sd->bl);
  7307. return;
  7308. }
  7309. pc_setstand(sd);
  7310. skill_sit(sd,0);
  7311. clif_standing(&sd->bl);
  7312. break;
  7313. }
  7314. }
  7315. /*==========================================
  7316. *
  7317. *------------------------------------------*/
  7318. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  7319. {
  7320. clif_parse_ActionRequest_sub(sd,
  7321. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7322. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7323. gettick()
  7324. );
  7325. }
  7326. /*==========================================
  7327. *
  7328. *------------------------------------------*/
  7329. void clif_parse_Restart(int fd, struct map_session_data *sd)
  7330. {
  7331. switch(RFIFOB(fd,2)) {
  7332. case 0x00:
  7333. pc_respawn(sd,2);
  7334. break;
  7335. case 0x01:
  7336. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7337. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7338. { //Send to char-server for character selection.
  7339. chrif_charselectreq(sd, session[fd]->client_addr);
  7340. } else {
  7341. WFIFOHEAD(fd,packet_len(0x18b));
  7342. WFIFOW(fd,0)=0x18b;
  7343. WFIFOW(fd,2)=1;
  7344. WFIFOSET(fd,packet_len(0x018b));
  7345. }
  7346. break;
  7347. }
  7348. }
  7349. /*==========================================
  7350. * Validates and processes whispered messages
  7351. * S 0096 <packet len>.w <nick>.23B 00 <message>.?B
  7352. *------------------------------------------*/
  7353. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  7354. {
  7355. struct map_session_data* dstsd;
  7356. int i;
  7357. char *target, *message;
  7358. int namelen, messagelen;
  7359. // validate packet and retrieve name and message
  7360. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  7361. return;
  7362. if (is_atcommand(fd, sd, message) || is_charcommand(fd, sd, message) )
  7363. return;
  7364. if (sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT))
  7365. return;
  7366. if (battle_config.min_chat_delay)
  7367. { //[Skotlex]
  7368. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  7369. return;
  7370. }
  7371. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7372. }
  7373. // Chat logging type 'W' / Whisper
  7374. if( log_config.chat&1 || (log_config.chat&4 && !(agit_flag && log_config.chat&64)) )
  7375. log_chat("W", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
  7376. //-------------------------------------------------------//
  7377. // Lordalfa - Paperboy - To whisper NPC commands //
  7378. //-------------------------------------------------------//
  7379. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  7380. {
  7381. char* str = target+4; //Skip the NPC: string part.
  7382. struct npc_data* npc;
  7383. if ((npc = npc_name2id(str)))
  7384. {
  7385. char split_data[10][50];
  7386. char *split;
  7387. char output[256];
  7388. str = message;
  7389. for( i = 0; i < 10; ++i )
  7390. {// Splits the message using '#' as separators
  7391. split = strchr(str,'#');
  7392. if( split == NULL )
  7393. { // use the remaining string
  7394. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7395. for( ++i; i < 10; ++i )
  7396. split_data[i][0] = '\0';
  7397. break;
  7398. }
  7399. *split = '\0';
  7400. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7401. str = split+1;
  7402. }
  7403. for( i = 0; i < 10; ++i )
  7404. {
  7405. sprintf(output, "@whispervar%d$", i);
  7406. set_var(sd,output,(char *) split_data[i]);
  7407. }
  7408. sprintf(output, "%s::OnWhisperGlobal", npc->name);
  7409. npc_event(sd,output,0); // Calls the NPC label
  7410. return;
  7411. }
  7412. }
  7413. // Main chat [LuzZza]
  7414. if(strcmpi(target, main_chat_nick) == 0)
  7415. {
  7416. if(!sd->state.mainchat)
  7417. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7418. else {
  7419. char output[256];
  7420. snprintf(output, ARRAYLENGTH(output), msg_txt(386), sd->status.name, message);
  7421. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7422. }
  7423. // Chat logging type 'M' / Main Chat
  7424. if( log_config.chat&1 || (log_config.chat&32 && !(agit_flag && log_config.chat&64)) )
  7425. log_chat("M", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7426. return;
  7427. }
  7428. // searching destination character
  7429. dstsd = map_nick2sd(target);
  7430. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
  7431. {
  7432. // player is not on this map-server
  7433. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7434. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7435. // and if we ask for 'Test', we must not contact 'test' player
  7436. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7437. intif_wis_message(sd, target, message, messagelen);
  7438. return;
  7439. }
  7440. // if player ignores everyone
  7441. if (dstsd->state.ignoreAll)
  7442. {
  7443. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7444. clif_wis_end(fd, 1); // 1: target character is not loged in
  7445. else
  7446. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7447. return;
  7448. }
  7449. // if player ignores the source character
  7450. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  7451. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  7452. { // source char present in ignore list
  7453. clif_wis_end(fd, 2); // 2: ignored by target
  7454. return;
  7455. }
  7456. // notify sender of success
  7457. clif_wis_end(fd, 0); // 0: success to send wisper
  7458. // if player has an auto-away message
  7459. if(dstsd->away_message[0] != '\0')
  7460. {
  7461. char output[256];
  7462. sprintf(output, "%s %s", message, msg_txt(543)); // "(Automessage has been sent)"
  7463. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  7464. if(dstsd->state.autotrade)
  7465. sprintf(output, msg_txt(544), dstsd->away_message); // "Away [AT] - "%s""
  7466. else
  7467. sprintf(output, msg_txt(545), dstsd->away_message); // "Away - "%s""
  7468. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  7469. return;
  7470. }
  7471. // Normal message
  7472. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  7473. return;
  7474. }
  7475. /*==========================================
  7476. * /b /nb
  7477. * S 0099 <packet len>.w <text>.?B 00
  7478. *------------------------------------------*/
  7479. void clif_parse_GMmessage(int fd, struct map_session_data* sd)
  7480. {
  7481. char* msg = (char*)RFIFOP(fd,4);
  7482. unsigned int len = RFIFOW(fd,2)-4;
  7483. int lv;
  7484. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  7485. return;
  7486. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_broadcast)) )
  7487. return;
  7488. // as the length varies depending on the command used, just block unreasonably long strings
  7489. mes_len_check(msg, len, CHAT_SIZE_MAX);
  7490. intif_GMmessage(msg, len, 0);
  7491. if(log_config.gm && lv >= log_config.gm) {
  7492. char logmsg[CHAT_SIZE_MAX+4];
  7493. sprintf(logmsg, "/b %s", msg);
  7494. log_atcommand(sd, logmsg);
  7495. }
  7496. }
  7497. /*==========================================
  7498. *
  7499. *------------------------------------------*/
  7500. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  7501. {
  7502. struct flooritem_data *fitem;
  7503. int map_object_id;
  7504. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7505. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  7506. do {
  7507. if (pc_isdead(sd)) {
  7508. clif_clearunit_area(&sd->bl, 1);
  7509. break;
  7510. }
  7511. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  7512. break;
  7513. if (pc_cant_act(sd))
  7514. break;
  7515. if(sd->sc.count && (
  7516. sd->sc.data[SC_HIDING] ||
  7517. sd->sc.data[SC_CLOAKING] ||
  7518. sd->sc.data[SC_TRICKDEAD] ||
  7519. sd->sc.data[SC_BLADESTOP] ||
  7520. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM))
  7521. )
  7522. break;
  7523. if (!pc_takeitem(sd, fitem))
  7524. break;
  7525. return;
  7526. } while (0);
  7527. // Client REQUIRES a fail packet or you can no longer pick items.
  7528. clif_additem(sd,0,0,6);
  7529. }
  7530. /*==========================================
  7531. *
  7532. *------------------------------------------*/
  7533. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  7534. {
  7535. int item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7536. int item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7537. do {
  7538. if (pc_isdead(sd))
  7539. break;
  7540. if (pc_cant_act(sd))
  7541. break;
  7542. if (sd->sc.count && (
  7543. sd->sc.data[SC_HIDING] ||
  7544. sd->sc.data[SC_AUTOCOUNTER] ||
  7545. sd->sc.data[SC_BLADESTOP] ||
  7546. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  7547. ))
  7548. break;
  7549. if (!pc_dropitem(sd, item_index, item_amount))
  7550. break;
  7551. return;
  7552. } while (0);
  7553. //Because the client does not like being ignored.
  7554. clif_delitem(sd, item_index,0);
  7555. }
  7556. /*==========================================
  7557. *
  7558. *------------------------------------------*/
  7559. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  7560. {
  7561. int n;
  7562. if (pc_isdead(sd)) {
  7563. clif_clearunit_area(&sd->bl, 1);
  7564. return;
  7565. }
  7566. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  7567. return;
  7568. //This flag enables you to use items while in an NPC. [Skotlex]
  7569. if (sd->npc_id) {
  7570. if (sd->npc_id != sd->npc_item_flag)
  7571. return;
  7572. } else
  7573. if (pc_istrading(sd))
  7574. return;
  7575. pc_delinvincibletimer(sd);
  7576. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  7577. sd->idletime = last_tick;
  7578. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7579. if(n <0 || n >= MAX_INVENTORY)
  7580. return;
  7581. if (!pc_useitem(sd,n))
  7582. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  7583. }
  7584. /*==========================================
  7585. *
  7586. *------------------------------------------*/
  7587. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  7588. {
  7589. int index;
  7590. if(pc_isdead(sd)) {
  7591. clif_clearunit_area(&sd->bl,1);
  7592. return;
  7593. }
  7594. index = RFIFOW(fd,2)-2;
  7595. if (index < 0 || index >= MAX_INVENTORY)
  7596. return; //Out of bounds check.
  7597. if(sd->npc_id) {
  7598. if (sd->npc_id != sd->npc_item_flag)
  7599. return;
  7600. } else if (sd->state.storage_flag || sd->sc.opt1)
  7601. ; //You can equip/unequip stuff while storage is open/under status changes
  7602. else if (pc_cant_act(sd))
  7603. return;
  7604. if(!sd->status.inventory[index].identify) {
  7605. clif_equipitemack(sd,index,0,0); // fail
  7606. return;
  7607. }
  7608. if(!sd->inventory_data[index])
  7609. return;
  7610. if(sd->inventory_data[index]->type == IT_PETARMOR){
  7611. pet_equipitem(sd,index);
  7612. return;
  7613. }
  7614. //Client doesn't send the position for ammo.
  7615. if(sd->inventory_data[index]->type == IT_AMMO)
  7616. pc_equipitem(sd,index,EQP_AMMO);
  7617. else
  7618. pc_equipitem(sd,index,RFIFOW(fd,4));
  7619. }
  7620. /*==========================================
  7621. *
  7622. *------------------------------------------*/
  7623. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  7624. {
  7625. int index;
  7626. if(pc_isdead(sd)) {
  7627. clif_clearunit_area(&sd->bl,1);
  7628. return;
  7629. }
  7630. if (sd->state.storage_flag)
  7631. ; //You can equip/unequip stuff while storage is open.
  7632. else if (pc_cant_act(sd))
  7633. return;
  7634. index = RFIFOW(fd,2)-2;
  7635. pc_unequipitem(sd,index,1);
  7636. }
  7637. /*==========================================
  7638. *
  7639. *------------------------------------------*/
  7640. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  7641. {
  7642. struct block_list *bl;
  7643. if(pc_isdead(sd)) {
  7644. clif_clearunit_area(&sd->bl,1);
  7645. return;
  7646. }
  7647. if (pc_cant_act(sd))
  7648. return;
  7649. bl = map_id2bl(RFIFOL(fd,2));
  7650. if (!bl) return;
  7651. switch (bl->type) {
  7652. case BL_MOB:
  7653. if (!((TBL_MOB *)bl)->nd || !mob_script_callback((TBL_MOB *)bl, &sd->bl, CALLBACK_NPCCLICK))
  7654. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7655. break;
  7656. case BL_PC:
  7657. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7658. break;
  7659. case BL_NPC:
  7660. npc_click(sd,(TBL_NPC*)bl);
  7661. break;
  7662. }
  7663. return;
  7664. }
  7665. /*==========================================
  7666. *
  7667. *------------------------------------------*/
  7668. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  7669. {
  7670. if (sd->state.trading)
  7671. return;
  7672. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  7673. }
  7674. /*==========================================
  7675. *
  7676. *------------------------------------------*/
  7677. void clif_parse_NpcBuyListSend(int fd,struct map_session_data *sd)
  7678. {
  7679. int fail=0,n;
  7680. unsigned short *item_list;
  7681. n = (RFIFOW(fd,2)-4) /4;
  7682. item_list = (unsigned short*)RFIFOP(fd,4);
  7683. if (sd->state.trading|| !sd->npc_shopid)
  7684. fail = 1;
  7685. else
  7686. fail = npc_buylist(sd,n,item_list);
  7687. sd->npc_shopid = 0; //Clear shop data.
  7688. WFIFOHEAD(fd,packet_len(0xca));
  7689. WFIFOW(fd,0)=0xca;
  7690. WFIFOB(fd,2)=fail;
  7691. WFIFOSET(fd,packet_len(0xca));
  7692. }
  7693. /*==========================================
  7694. *
  7695. *------------------------------------------*/
  7696. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  7697. {
  7698. int fail=0,n;
  7699. unsigned short *item_list;
  7700. n = (RFIFOW(fd,2)-4) /4;
  7701. item_list = (unsigned short*)RFIFOP(fd,4);
  7702. if (sd->state.trading || !sd->npc_shopid)
  7703. fail = 1;
  7704. else
  7705. fail = npc_selllist(sd,n,item_list);
  7706. sd->npc_shopid = 0; //Clear shop data.
  7707. WFIFOHEAD(fd,packet_len(0xcb));
  7708. WFIFOW(fd,0)=0xcb;
  7709. WFIFOB(fd,2)=fail;
  7710. WFIFOSET(fd,packet_len(0xcb));
  7711. }
  7712. /*==========================================
  7713. * Chatroom creation request
  7714. * S 00d5 <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7715. *------------------------------------------*/
  7716. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  7717. {
  7718. int len = RFIFOW(fd,2)-15;
  7719. int limit = RFIFOW(fd,4);
  7720. bool pub = (RFIFOB(fd,6) != 0);
  7721. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  7722. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7723. char s_title[CHATROOM_TITLE_SIZE];
  7724. char s_password[CHATROOM_PASS_SIZE];
  7725. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  7726. return;
  7727. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  7728. clif_skill_fail(sd,1,0,3);
  7729. return;
  7730. }
  7731. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7732. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7733. chat_createpcchat(sd, s_title, s_password, limit, pub);
  7734. }
  7735. /*==========================================
  7736. * Chatroom join request
  7737. * S 00d9 <chat ID>.l <passwd>.8B
  7738. *------------------------------------------*/
  7739. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  7740. {
  7741. int chatid = RFIFOL(fd,2);
  7742. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  7743. chat_joinchat(sd,chatid,password);
  7744. }
  7745. /*==========================================
  7746. * Chatroom properties adjustment request
  7747. * S 00de <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7748. *------------------------------------------*/
  7749. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  7750. {
  7751. int len = RFIFOW(fd,2)-15;
  7752. int limit = RFIFOW(fd,4);
  7753. bool pub = (RFIFOB(fd,6) != 0);
  7754. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  7755. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7756. char s_title[CHATROOM_TITLE_SIZE];
  7757. char s_password[CHATROOM_PASS_SIZE];
  7758. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7759. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7760. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  7761. }
  7762. /*==========================================
  7763. * S 00e0 ?.l <nick>.24B
  7764. *------------------------------------------*/
  7765. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  7766. {
  7767. //TODO: the first argument seems to be the destination position (always 0) [ultramage]
  7768. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  7769. }
  7770. /*==========================================
  7771. *
  7772. *------------------------------------------*/
  7773. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  7774. {
  7775. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  7776. }
  7777. /*==========================================
  7778. * Request to leave the current chatroom
  7779. * S 00e3
  7780. *------------------------------------------*/
  7781. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  7782. {
  7783. chat_leavechat(sd,0);
  7784. }
  7785. //Handles notifying asker and rejecter of what has just ocurred.
  7786. //Type is used to determine the correct msg_txt to use:
  7787. //0:
  7788. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  7789. {
  7790. char *msg, output[256];
  7791. // Your request has been rejected by autoreject option.
  7792. msg = msg_txt(392);
  7793. clif_disp_onlyself(src, msg, strlen(msg));
  7794. //Notice that a request was rejected.
  7795. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  7796. clif_disp_onlyself(target, output, strlen(output));
  7797. }
  7798. /*==========================================
  7799. * 取引要請を相手に送る
  7800. *------------------------------------------*/
  7801. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  7802. {
  7803. struct map_session_data *t_sd;
  7804. t_sd = map_id2sd(RFIFOL(fd,2));
  7805. if(!sd->chatID && pc_cant_act(sd))
  7806. return; //You can trade while in a chatroom.
  7807. // @noask [LuzZza]
  7808. if(t_sd && t_sd->state.noask) {
  7809. clif_noask_sub(sd, t_sd, 0);
  7810. return;
  7811. }
  7812. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 1){
  7813. trade_traderequest(sd,t_sd);
  7814. } else
  7815. clif_skill_fail(sd,1,0,0);
  7816. }
  7817. /*==========================================
  7818. * 取引要請
  7819. *------------------------------------------*/
  7820. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  7821. {
  7822. trade_tradeack(sd,RFIFOB(fd,2));
  7823. }
  7824. /*==========================================
  7825. * アイテム追加
  7826. *------------------------------------------*/
  7827. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  7828. {
  7829. short index = RFIFOW(fd,2);
  7830. int amount = RFIFOL(fd,4);
  7831. if( index == 0 )
  7832. trade_tradeaddzeny(sd, amount);
  7833. else
  7834. trade_tradeadditem(sd, index, (short)amount);
  7835. }
  7836. /*==========================================
  7837. * アイテム追加完了(ok押し)
  7838. *------------------------------------------*/
  7839. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  7840. {
  7841. trade_tradeok(sd);
  7842. }
  7843. /*==========================================
  7844. * 取引キャンセル
  7845. *------------------------------------------*/
  7846. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  7847. {
  7848. trade_tradecancel(sd);
  7849. }
  7850. /*==========================================
  7851. * 取引許諾(trade押し)
  7852. *------------------------------------------*/
  7853. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  7854. {
  7855. trade_tradecommit(sd);
  7856. }
  7857. /*==========================================
  7858. *
  7859. *------------------------------------------*/
  7860. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  7861. {
  7862. pc_stop_attack(sd);
  7863. }
  7864. /*==========================================
  7865. * カートへアイテムを移す
  7866. *------------------------------------------*/
  7867. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  7868. {
  7869. if (pc_istrading(sd))
  7870. return;
  7871. if (!pc_iscarton(sd))
  7872. return;
  7873. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  7874. }
  7875. /*==========================================
  7876. * カートからアイテムを出す
  7877. *------------------------------------------*/
  7878. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  7879. {
  7880. if (!pc_iscarton(sd))
  7881. return;
  7882. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  7883. }
  7884. /*==========================================
  7885. * 付属品(鷹,ペコ,カート)をはずす
  7886. *------------------------------------------*/
  7887. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  7888. {
  7889. //Can only remove Cart/Riding/Falcon.
  7890. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  7891. }
  7892. /*==========================================
  7893. * チェンジカート
  7894. *------------------------------------------*/
  7895. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  7896. {
  7897. int type;
  7898. type = (int)RFIFOW(fd,2);
  7899. if( (type == 5 && sd->status.base_level > 90) ||
  7900. (type == 4 && sd->status.base_level > 80) ||
  7901. (type == 3 && sd->status.base_level > 65) ||
  7902. (type == 2 && sd->status.base_level > 40) )
  7903. pc_setcart(sd,type);
  7904. }
  7905. /*==========================================
  7906. * ステータスアップ
  7907. *------------------------------------------*/
  7908. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  7909. {
  7910. pc_statusup(sd,RFIFOW(fd,2));
  7911. }
  7912. /*==========================================
  7913. * スキルレベルアップ
  7914. *------------------------------------------*/
  7915. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  7916. {
  7917. pc_skillup(sd,RFIFOW(fd,2));
  7918. }
  7919. 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)
  7920. {
  7921. int lv;
  7922. if (!hd)
  7923. return;
  7924. if (skillnotok_hom(skillnum, hd)) //[orn]
  7925. return;
  7926. if (hd->bl.id != target_id &&
  7927. skill_get_inf(skillnum)&INF_SELF_SKILL)
  7928. target_id = hd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  7929. if (hd->ud.skilltimer != -1) {
  7930. if (skillnum != SA_CASTCANCEL)
  7931. return;
  7932. } else if (DIFF_TICK(tick, hd->ud.canact_tick) < 0)
  7933. return;
  7934. lv = merc_hom_checkskill(hd, skillnum);
  7935. if (skilllv > lv)
  7936. skilllv = lv;
  7937. if (skilllv)
  7938. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  7939. }
  7940. /*==========================================
  7941. * スキル使用(ID指定)
  7942. *------------------------------------------*/
  7943. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  7944. {
  7945. short skillnum, skilllv;
  7946. int tmp, target_id;
  7947. unsigned int tick = gettick();
  7948. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7949. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7950. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  7951. if (skilllv < 1) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  7952. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  7953. sd->idletime = last_tick;
  7954. tmp = skill_get_inf(skillnum);
  7955. if (tmp&INF_GROUND_SKILL || !tmp)
  7956. return; //Using a ground/passive skill on a target? WRONG.
  7957. if (skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE+MAX_HOMUNSKILL) {
  7958. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  7959. return;
  7960. }
  7961. if (pc_cant_act(sd))
  7962. return;
  7963. if (pc_issit(sd))
  7964. return;
  7965. if (skillnotok(skillnum, sd))
  7966. return;
  7967. if (sd->bl.id != target_id && !sd->state.skill_flag && tmp&INF_SELF_SKILL)
  7968. target_id = sd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  7969. if (sd->ud.skilltimer != -1) {
  7970. if (skillnum != SA_CASTCANCEL)
  7971. return;
  7972. } else if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7973. clif_skill_fail(sd, skillnum, 4, 0);
  7974. return;
  7975. }
  7976. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  7977. return;
  7978. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7979. target_id = sd->bl.id;
  7980. if(sd->menuskill_id)
  7981. {
  7982. if (sd->menuskill_id == SA_TAMINGMONSTER)
  7983. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  7984. else
  7985. if (sd->menuskill_id != SA_AUTOSPELL)
  7986. return; //Can't use skills while a menu is open.
  7987. }
  7988. if (sd->skillitem == skillnum) {
  7989. if (skilllv != sd->skillitemlv)
  7990. skilllv = sd->skillitemlv;
  7991. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  7992. return;
  7993. }
  7994. sd->skillitem = sd->skillitemlv = 0;
  7995. if (skillnum == MO_EXTREMITYFIST) {
  7996. if ((!sd->sc.data[SC_COMBO] ||
  7997. (sd->sc.data[SC_COMBO]->val1 != MO_COMBOFINISH &&
  7998. sd->sc.data[SC_COMBO]->val1 != CH_TIGERFIST &&
  7999. sd->sc.data[SC_COMBO]->val1 != CH_CHAINCRUSH))) {
  8000. if (!sd->state.skill_flag ) {
  8001. sd->state.skill_flag = 1;
  8002. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8003. return;
  8004. } else if (sd->bl.id == target_id) {
  8005. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8006. return;
  8007. }
  8008. }
  8009. }
  8010. if (skillnum == TK_JUMPKICK) {
  8011. if (!sd->sc.data[SC_COMBO] || sd->sc.data[SC_COMBO]->val1 != TK_JUMPKICK) {
  8012. if (!sd->state.skill_flag ) {
  8013. sd->state.skill_flag = 1;
  8014. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8015. return;
  8016. } else if (sd->bl.id == target_id) {
  8017. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8018. return;
  8019. }
  8020. }
  8021. }
  8022. if (skillnum >= GD_SKILLBASE) {
  8023. if (sd->state.gmaster_flag)
  8024. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8025. else
  8026. skilllv = 0;
  8027. } else {
  8028. tmp = pc_checkskill(sd, skillnum);
  8029. if (skilllv > tmp)
  8030. skilllv = tmp;
  8031. }
  8032. pc_delinvincibletimer(sd);
  8033. if (skilllv)
  8034. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8035. if (sd->state.skill_flag)
  8036. sd->state.skill_flag = 0;
  8037. }
  8038. /*==========================================
  8039. * スキル使用(場所指定)
  8040. *------------------------------------------*/
  8041. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, short skilllv, short skillnum, short x, short y, int skillmoreinfo)
  8042. {
  8043. int lv;
  8044. unsigned int tick = gettick();
  8045. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8046. sd->idletime = last_tick;
  8047. if (skillnotok(skillnum, sd))
  8048. return;
  8049. if (!(skill_get_inf(skillnum)&INF_GROUND_SKILL))
  8050. return; //Using a target skill on the ground? WRONG.
  8051. if (skillmoreinfo != -1) {
  8052. if (pc_issit(sd)) {
  8053. clif_skill_fail(sd, skillnum, 0, 0);
  8054. return;
  8055. }
  8056. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  8057. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8058. }
  8059. if (sd->ud.skilltimer != -1)
  8060. return;
  8061. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0)
  8062. {
  8063. clif_skill_fail(sd, skillnum, 4, 0);
  8064. return;
  8065. }
  8066. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  8067. return;
  8068. if(sd->menuskill_id)
  8069. {
  8070. if (sd->menuskill_id == SA_TAMINGMONSTER)
  8071. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8072. else
  8073. if (sd->menuskill_id != SA_AUTOSPELL)
  8074. return; //Can't use skills while a menu is open.
  8075. }
  8076. pc_delinvincibletimer(sd);
  8077. if (sd->skillitem == skillnum) {
  8078. if (skilllv != sd->skillitemlv)
  8079. skilllv = sd->skillitemlv;
  8080. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8081. } else {
  8082. sd->skillitem = sd->skillitemlv = 0;
  8083. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8084. if (skilllv > lv)
  8085. skilllv = lv;
  8086. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8087. }
  8088. }
  8089. }
  8090. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  8091. {
  8092. if (pc_cant_act(sd))
  8093. return;
  8094. if (pc_issit(sd))
  8095. return;
  8096. clif_parse_UseSkillToPosSub(fd, sd,
  8097. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8098. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8099. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8100. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8101. -1 //Skill more info.
  8102. );
  8103. }
  8104. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  8105. {
  8106. if (pc_cant_act(sd))
  8107. return;
  8108. if (pc_issit(sd))
  8109. return;
  8110. clif_parse_UseSkillToPosSub(fd, sd,
  8111. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8112. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8113. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8114. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8115. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8116. );
  8117. }
  8118. /*==========================================
  8119. * スキル使用(map指定)
  8120. *------------------------------------------*/
  8121. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  8122. {
  8123. short skill_num = RFIFOW(fd,2);
  8124. char map_name[MAP_NAME_LENGTH];
  8125. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  8126. if(skill_num != sd->menuskill_id)
  8127. return;
  8128. if (pc_cant_act(sd))
  8129. {
  8130. sd->menuskill_id = sd->menuskill_val = 0;
  8131. return;
  8132. }
  8133. pc_delinvincibletimer(sd);
  8134. skill_castend_map(sd,skill_num,map_name);
  8135. }
  8136. /*==========================================
  8137. * メモ要求
  8138. *------------------------------------------*/
  8139. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8140. {
  8141. if (!pc_isdead(sd))
  8142. pc_memo(sd,-1);
  8143. }
  8144. /*==========================================
  8145. * アイテム合成
  8146. *------------------------------------------*/
  8147. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8148. {
  8149. if (sd->menuskill_id != AM_PHARMACY)
  8150. return;
  8151. if (pc_istrading(sd)) {
  8152. //Make it fail to avoid shop exploits where you sell something different than you see.
  8153. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8154. sd->menuskill_val = sd->menuskill_id = 0;
  8155. return;
  8156. }
  8157. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8158. sd->menuskill_val = sd->menuskill_id = 0;
  8159. }
  8160. /*==========================================
  8161. * 武器修理
  8162. *------------------------------------------*/
  8163. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8164. {
  8165. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8166. return;
  8167. if (pc_istrading(sd)) {
  8168. //Make it fail to avoid shop exploits where you sell something different than you see.
  8169. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8170. sd->menuskill_val = sd->menuskill_id = 0;
  8171. return;
  8172. }
  8173. skill_repairweapon(sd,RFIFOW(fd,2));
  8174. sd->menuskill_val = sd->menuskill_id = 0;
  8175. }
  8176. /*==========================================
  8177. *
  8178. *------------------------------------------*/
  8179. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  8180. {
  8181. int idx;
  8182. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8183. return;
  8184. if (pc_istrading(sd)) {
  8185. //Make it fail to avoid shop exploits where you sell something different than you see.
  8186. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8187. sd->menuskill_val = sd->menuskill_id = 0;
  8188. return;
  8189. }
  8190. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8191. skill_weaponrefine(sd, idx-2);
  8192. sd->menuskill_val = sd->menuskill_id = 0;
  8193. }
  8194. /*==========================================
  8195. *
  8196. *------------------------------------------*/
  8197. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8198. {
  8199. uint8 select;
  8200. select = RFIFOB(fd,6);
  8201. if((select > sd->npc_menu && select != 0xff) || !select){
  8202. ShowWarning("Hack on NPC Select Menu: %s (AID: %d)!\n",sd->status.name,sd->bl.id);
  8203. clif_GM_kick(NULL,sd);
  8204. } else {
  8205. sd->npc_menu=select;
  8206. npc_scriptcont(sd,RFIFOL(fd,2));
  8207. }
  8208. }
  8209. /*==========================================
  8210. *
  8211. *------------------------------------------*/
  8212. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8213. {
  8214. npc_scriptcont(sd,RFIFOL(fd,2));
  8215. }
  8216. /*==========================================
  8217. * Value entered into a NPC input box.
  8218. * S 0143 <npcID>.l <amount>.l
  8219. *------------------------------------------*/
  8220. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8221. {
  8222. int npcid = RFIFOL(fd,2);
  8223. int amount = (int)RFIFOL(fd,6);
  8224. sd->npc_amount = amount;
  8225. npc_scriptcont(sd, npcid);
  8226. }
  8227. /*==========================================
  8228. * Text entered into a NPC input box.
  8229. * S 01d5 <len>.w <npcID>.l <input>.?B 00
  8230. *------------------------------------------*/
  8231. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  8232. {
  8233. int message_len = RFIFOW(fd,2)-8;
  8234. int npcid = RFIFOL(fd,4);
  8235. const char* message = (char*)RFIFOP(fd,8);
  8236. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  8237. npc_scriptcont(sd, npcid);
  8238. }
  8239. /*==========================================
  8240. *
  8241. *------------------------------------------*/
  8242. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8243. {
  8244. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8245. return;
  8246. npc_scriptcont(sd,RFIFOL(fd,2));
  8247. }
  8248. /*==========================================
  8249. * アイテム鑑定
  8250. *------------------------------------------*/
  8251. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8252. {
  8253. if (sd->menuskill_id != MC_IDENTIFY)
  8254. return;
  8255. skill_identify(sd,RFIFOW(fd,2)-2);
  8256. sd->menuskill_val = sd->menuskill_id = 0;
  8257. }
  8258. /*==========================================
  8259. * 矢作成
  8260. *------------------------------------------*/
  8261. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8262. {
  8263. if (sd->menuskill_id != AC_MAKINGARROW)
  8264. return;
  8265. if (pc_istrading(sd)) {
  8266. //Make it fail to avoid shop exploits where you sell something different than you see.
  8267. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8268. sd->menuskill_val = sd->menuskill_id = 0;
  8269. return;
  8270. }
  8271. skill_arrow_create(sd,RFIFOW(fd,2));
  8272. sd->menuskill_val = sd->menuskill_id = 0;
  8273. }
  8274. /*==========================================
  8275. * オートスペル受信
  8276. *------------------------------------------*/
  8277. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8278. {
  8279. if (sd->menuskill_id != SA_AUTOSPELL)
  8280. return;
  8281. skill_autospell(sd,RFIFOW(fd,2));
  8282. sd->menuskill_val = sd->menuskill_id = 0;
  8283. }
  8284. /*==========================================
  8285. * カード使用
  8286. *------------------------------------------*/
  8287. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8288. {
  8289. if (sd->state.trading != 0)
  8290. return;
  8291. clif_use_card(sd,RFIFOW(fd,2)-2);
  8292. }
  8293. /*==========================================
  8294. * カード挿入装備選択
  8295. *------------------------------------------*/
  8296. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8297. {
  8298. if (sd->state.trading != 0)
  8299. return;
  8300. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8301. }
  8302. /*==========================================
  8303. * 0193 キャラID名前引き
  8304. *------------------------------------------*/
  8305. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  8306. {
  8307. int charid;
  8308. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8309. map_reqnickdb(sd, charid);
  8310. }
  8311. /*==========================================
  8312. * 0197 /resetskill /resetstate
  8313. *------------------------------------------*/
  8314. void clif_parse_ResetChar(int fd, struct map_session_data *sd)
  8315. {
  8316. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8317. return;
  8318. if( pc_isGM(sd) < get_atcommand_level(atcommand_reset) )
  8319. return;
  8320. if( RFIFOW(fd,2) )
  8321. pc_resetskill(sd,1);
  8322. else
  8323. pc_resetstate(sd);
  8324. if( log_config.gm && get_atcommand_level(atcommand_reset) >= log_config.gm )
  8325. log_atcommand(sd, RFIFOW(fd,2) ? "/resetskill" : "/resetstate");
  8326. }
  8327. /*==========================================
  8328. * /lb /nlb
  8329. * S 019c <packet len>.w <text>.?B 00
  8330. *------------------------------------------*/
  8331. void clif_parse_LGMmessage(int fd, struct map_session_data* sd)
  8332. {
  8333. char* msg = (char*)RFIFOP(fd,4);
  8334. unsigned int len = RFIFOW(fd,2)-4;
  8335. int lv;
  8336. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8337. return;
  8338. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_localbroadcast)) )
  8339. return;
  8340. // as the length varies depending on the command used, just block unreasonably long strings
  8341. mes_len_check(msg, len, CHAT_SIZE_MAX);
  8342. clif_GMmessage(&sd->bl, msg, len, 1);
  8343. if( log_config.gm && lv >= log_config.gm ) {
  8344. char logmsg[CHAT_SIZE_MAX+5];
  8345. sprintf(logmsg, "/lb %s", msg);
  8346. log_atcommand(sd, logmsg);
  8347. }
  8348. }
  8349. /*==========================================
  8350. * カプラ倉庫へ入れる
  8351. *------------------------------------------*/
  8352. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  8353. {
  8354. int item_index, item_amount;
  8355. if (pc_istrading(sd))
  8356. return;
  8357. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8358. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8359. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  8360. return;
  8361. if (sd->state.storage_flag == 1)
  8362. storage_storageadd(sd, item_index, item_amount);
  8363. else if (sd->state.storage_flag == 2)
  8364. storage_guild_storageadd(sd, item_index, item_amount);
  8365. }
  8366. /*==========================================
  8367. * カプラ倉庫から出す
  8368. *------------------------------------------*/
  8369. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  8370. {
  8371. int item_index, item_amount;
  8372. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8373. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8374. if (sd->state.storage_flag == 1)
  8375. storage_storageget(sd, item_index, item_amount);
  8376. else if(sd->state.storage_flag == 2)
  8377. storage_guild_storageget(sd, item_index, item_amount);
  8378. }
  8379. /*==========================================
  8380. * カプラ倉庫へカートから入れる
  8381. *------------------------------------------*/
  8382. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  8383. {
  8384. if(sd->vender_id)
  8385. return;
  8386. if (!pc_iscarton(sd))
  8387. return;
  8388. if (sd->state.storage_flag == 1)
  8389. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8390. else if (sd->state.storage_flag == 2)
  8391. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8392. }
  8393. /*==========================================
  8394. * カプラ倉庫から出す
  8395. *------------------------------------------*/
  8396. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  8397. {
  8398. if (sd->vender_id)
  8399. return;
  8400. if (!pc_iscarton(sd))
  8401. return;
  8402. if (sd->state.storage_flag == 1)
  8403. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8404. else if (sd->state.storage_flag == 2)
  8405. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8406. }
  8407. /*==========================================
  8408. * カプラ倉庫を閉じる
  8409. *------------------------------------------*/
  8410. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  8411. {
  8412. if (sd->state.storage_flag == 1)
  8413. storage_storageclose(sd);
  8414. else if (sd->state.storage_flag == 2)
  8415. storage_guild_storageclose(sd);
  8416. }
  8417. /*==========================================
  8418. * Kafra storage protection password system
  8419. *------------------------------------------*/
  8420. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  8421. {
  8422. //TODO
  8423. }
  8424. /*==========================================
  8425. * パーティを作る
  8426. *------------------------------------------*/
  8427. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  8428. {
  8429. if(map[sd->bl.m].flag.partylock)
  8430. { //Guild locked.
  8431. clif_displaymessage(fd, msg_txt(227));
  8432. return;
  8433. }
  8434. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7) {
  8435. party_create(sd,(char*)RFIFOP(fd,2),0,0);
  8436. } else
  8437. clif_skill_fail(sd,1,0,4);
  8438. }
  8439. /*==========================================
  8440. * パーティを作る
  8441. *------------------------------------------*/
  8442. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  8443. {
  8444. if(map[sd->bl.m].flag.partylock)
  8445. { //Guild locked.
  8446. clif_displaymessage(fd, msg_txt(227));
  8447. return;
  8448. }
  8449. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7)
  8450. party_create(sd,(char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27));
  8451. else
  8452. clif_skill_fail(sd,1,0,4);
  8453. }
  8454. /*==========================================
  8455. * パーティに勧誘
  8456. *------------------------------------------*/
  8457. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  8458. {
  8459. struct map_session_data *t_sd;
  8460. if(map[sd->bl.m].flag.partylock)
  8461. { //Guild locked.
  8462. clif_displaymessage(fd, msg_txt(227));
  8463. return;
  8464. }
  8465. t_sd = map_id2sd(RFIFOL(fd,2));
  8466. // @noask [LuzZza]
  8467. if(t_sd && t_sd->state.noask) {
  8468. clif_noask_sub(sd, t_sd, 1);
  8469. return;
  8470. }
  8471. party_invite(sd, t_sd);
  8472. }
  8473. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  8474. {
  8475. struct map_session_data *t_sd;
  8476. char *name = (char*)RFIFOP(fd,2);
  8477. name[NAME_LENGTH]='\0';
  8478. if(map[sd->bl.m].flag.partylock)
  8479. { //Guild locked.
  8480. clif_displaymessage(fd, msg_txt(227));
  8481. return;
  8482. }
  8483. t_sd = map_nick2sd(name);
  8484. // @noask [LuzZza]
  8485. if(t_sd && t_sd->state.noask) {
  8486. clif_noask_sub(sd, t_sd, 1);
  8487. return;
  8488. }
  8489. party_invite(sd, t_sd);
  8490. }
  8491. /*==========================================
  8492. * Party invitation reply
  8493. * S 00ff <account ID>.L <flag>.L
  8494. * S 02c7 <account ID>.L <flag>.B
  8495. * flag: 0-reject, 1-accept
  8496. *------------------------------------------*/
  8497. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  8498. {
  8499. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 5 )
  8500. {
  8501. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8502. clif_skill_fail(sd,1,0,4);
  8503. return;
  8504. }
  8505. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8506. }
  8507. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  8508. {
  8509. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 5 )
  8510. {
  8511. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8512. clif_skill_fail(sd,1,0,4);
  8513. return;
  8514. }
  8515. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8516. }
  8517. /*==========================================
  8518. * パーティ脱退要求
  8519. *------------------------------------------*/
  8520. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  8521. {
  8522. if(map[sd->bl.m].flag.partylock)
  8523. { //Guild locked.
  8524. clif_displaymessage(fd, msg_txt(227));
  8525. return;
  8526. }
  8527. party_leave(sd);
  8528. }
  8529. /*==========================================
  8530. * パーティ除名要求
  8531. *------------------------------------------*/
  8532. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  8533. {
  8534. if(map[sd->bl.m].flag.partylock)
  8535. { //Guild locked.
  8536. clif_displaymessage(fd, msg_txt(227));
  8537. return;
  8538. }
  8539. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8540. }
  8541. /*==========================================
  8542. * パーティ設定変更要求
  8543. *------------------------------------------*/
  8544. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  8545. {
  8546. struct party_data *p;
  8547. int i;
  8548. if( !sd->status.party_id )
  8549. return;
  8550. p = party_search(sd->status.party_id);
  8551. if( p == NULL )
  8552. return;
  8553. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  8554. if( i == MAX_PARTY )
  8555. return; //Shouldn't happen
  8556. if( !p->party.member[i].leader )
  8557. return;
  8558. //The client no longer can change the item-field, therefore it always
  8559. //comes as zero. Here, resend the item data as it is.
  8560. // party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  8561. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  8562. }
  8563. /*==========================================
  8564. * Validates and processes party messages
  8565. * S 0108 <packet len>.w <text>.?B (<name> : <message>) 00
  8566. *------------------------------------------*/
  8567. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  8568. {
  8569. const char* text = (char*)RFIFOP(fd,4);
  8570. int textlen = RFIFOW(fd,2) - 4;
  8571. char *name, *message;
  8572. int namelen, messagelen;
  8573. // validate packet and retrieve name and message
  8574. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8575. return;
  8576. if( is_atcommand(fd, sd, message) || is_charcommand(fd, sd, message) )
  8577. return;
  8578. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8579. return;
  8580. if( battle_config.min_chat_delay )
  8581. { //[Skotlex]
  8582. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8583. return;
  8584. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8585. }
  8586. party_send_message(sd, text, textlen);
  8587. }
  8588. /*==========================================
  8589. * 露店閉鎖
  8590. *------------------------------------------*/
  8591. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  8592. {
  8593. vending_closevending(sd);
  8594. }
  8595. /*==========================================
  8596. * 露店アイテムリスト要求
  8597. *------------------------------------------*/
  8598. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  8599. {
  8600. vending_vendinglistreq(sd,RFIFOL(fd,2));
  8601. if( sd->npc_id )
  8602. npc_event_dequeue(sd);
  8603. }
  8604. /*==========================================
  8605. * Shop item(s) purchase request
  8606. * S 0134 <len>.w <ID>.l {<amount>.w <index>.w}.4B*
  8607. *------------------------------------------*/
  8608. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  8609. {
  8610. int len = (int)RFIFOW(fd,2) - 8;
  8611. int id = (int)RFIFOL(fd,4);
  8612. const uint8* data = (uint8*)RFIFOP(fd,8);
  8613. vending_purchasereq(sd, id, data, len/4);
  8614. }
  8615. /*==========================================
  8616. * Confirm or cancel the shop preparation window
  8617. * S 01b2 <len>.w <message>.80B <flag>.B {<index>.w <amount>.w <value>.l}.8B*
  8618. * flag: 0=cancel, 1=confirm
  8619. *------------------------------------------*/
  8620. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  8621. {
  8622. short len = (short)RFIFOW(fd,2) - 85;
  8623. const char* message = (char*)RFIFOP(fd,4);
  8624. bool flag = (bool)RFIFOB(fd,84);
  8625. const uint8* data = (uint8*)RFIFOP(fd,85);
  8626. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  8627. return;
  8628. if( map[sd->bl.m].flag.novending || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  8629. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open shop on this map"
  8630. return;
  8631. }
  8632. if( message[0] == '\0' ) // invalid input
  8633. return;
  8634. vending_openvending(sd, message, flag, data, len/8);
  8635. }
  8636. /*==========================================
  8637. * ギルドを作る
  8638. *------------------------------------------*/
  8639. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  8640. {
  8641. if(map[sd->bl.m].flag.guildlock)
  8642. { //Guild locked.
  8643. clif_displaymessage(fd, msg_txt(228));
  8644. return;
  8645. }
  8646. guild_create(sd, (char*)RFIFOP(fd,6));
  8647. }
  8648. /*==========================================
  8649. * ギルドマスターかどうか確認
  8650. *------------------------------------------*/
  8651. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  8652. {
  8653. clif_guild_masterormember(sd);
  8654. }
  8655. /*==========================================
  8656. * ギルド情報要求
  8657. *------------------------------------------*/
  8658. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  8659. {
  8660. if (!sd->status.guild_id)
  8661. return;
  8662. switch(RFIFOL(fd,2)){
  8663. case 0: // ギルド基本情報、同盟敵対情報
  8664. clif_guild_basicinfo(sd);
  8665. clif_guild_allianceinfo(sd);
  8666. break;
  8667. case 1: // メンバーリスト、役職名リスト
  8668. clif_guild_positionnamelist(sd);
  8669. clif_guild_memberlist(sd);
  8670. break;
  8671. case 2: // 役職名リスト、役職情報リスト
  8672. clif_guild_positionnamelist(sd);
  8673. clif_guild_positioninfolist(sd);
  8674. break;
  8675. case 3: // スキルリスト
  8676. clif_guild_skillinfo(sd);
  8677. break;
  8678. case 4: // 追放リスト
  8679. clif_guild_expulsionlist(sd);
  8680. break;
  8681. default:
  8682. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  8683. break;
  8684. }
  8685. }
  8686. /*==========================================
  8687. * ギルド役職変更
  8688. *------------------------------------------*/
  8689. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  8690. {
  8691. int i;
  8692. if(!sd->state.gmaster_flag)
  8693. return;
  8694. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  8695. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  8696. }
  8697. }
  8698. /*==========================================
  8699. * ギルドメンバ役職変更
  8700. *------------------------------------------*/
  8701. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  8702. {
  8703. int i;
  8704. if(!sd->state.gmaster_flag)
  8705. return;
  8706. for(i=4;i<RFIFOW(fd,2);i+=12){
  8707. guild_change_memberposition(sd->status.guild_id,
  8708. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  8709. }
  8710. }
  8711. /*==========================================
  8712. * ギルドエンブレム要求
  8713. *------------------------------------------*/
  8714. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  8715. {
  8716. struct guild* g = guild_search(RFIFOL(fd,2));
  8717. if(g!=NULL)
  8718. clif_guild_emblem(sd,g);
  8719. }
  8720. /*==========================================
  8721. * ギルドエンブレム変更
  8722. *------------------------------------------*/
  8723. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  8724. {
  8725. if(!sd->state.gmaster_flag)
  8726. return;
  8727. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  8728. }
  8729. /*==========================================
  8730. * Guild notice update request
  8731. * S 016E <guildID>.l <msg1>.60B <msg2>.120B
  8732. *------------------------------------------*/
  8733. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  8734. {
  8735. int guild_id = RFIFOL(fd,2);
  8736. char* msg1 = (char*)RFIFOP(fd,6);
  8737. char* msg2 = (char*)RFIFOP(fd,66);
  8738. if(!sd->state.gmaster_flag)
  8739. return;
  8740. // compensate for some client defects when using multilanguage mode
  8741. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  8742. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  8743. if (msg2[0] == '|') msg2[strnlen(msg2, 120)-1] = '\0'; // delete extra space at the end of string
  8744. guild_change_notice(sd, guild_id, msg1, msg2);
  8745. }
  8746. /*==========================================
  8747. * ギルド勧誘
  8748. *------------------------------------------*/
  8749. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  8750. {
  8751. struct map_session_data *t_sd;
  8752. if(map[sd->bl.m].flag.guildlock)
  8753. { //Guild locked.
  8754. clif_displaymessage(fd, msg_txt(228));
  8755. return;
  8756. }
  8757. t_sd = map_id2sd(RFIFOL(fd,2));
  8758. // @noask [LuzZza]
  8759. if(t_sd && t_sd->state.noask) {
  8760. clif_noask_sub(sd, t_sd, 2);
  8761. return;
  8762. }
  8763. guild_invite(sd,t_sd);
  8764. }
  8765. /*==========================================
  8766. * ギルド勧誘返信
  8767. *------------------------------------------*/
  8768. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  8769. {
  8770. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8771. }
  8772. /*==========================================
  8773. * ギルド脱退
  8774. *------------------------------------------*/
  8775. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  8776. {
  8777. if(map[sd->bl.m].flag.guildlock)
  8778. { //Guild locked.
  8779. clif_displaymessage(fd, msg_txt(228));
  8780. return;
  8781. }
  8782. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8783. }
  8784. /*==========================================
  8785. * Request to expel a member of a guild
  8786. * S 015b <guild_id>.L <account_id>.L <char_id>.L <reason>.39B 00
  8787. *------------------------------------------*/
  8788. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  8789. {
  8790. if(map[sd->bl.m].flag.guildlock)
  8791. { //Guild locked.
  8792. clif_displaymessage(fd, msg_txt(228));
  8793. return;
  8794. }
  8795. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8796. }
  8797. /*==========================================
  8798. * Validates and processes guild messages
  8799. * S 017e <packet len>.w <text>.?B (<name> : <message>) 00
  8800. *------------------------------------------*/
  8801. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  8802. {
  8803. const char* text = (char*)RFIFOP(fd,4);
  8804. int textlen = RFIFOW(fd,2) - 4;
  8805. char *name, *message;
  8806. int namelen, messagelen;
  8807. // validate packet and retrieve name and message
  8808. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8809. return;
  8810. if( is_atcommand(fd, sd, message) || is_charcommand(fd, sd, message) )
  8811. return;
  8812. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8813. return;
  8814. if( battle_config.min_chat_delay )
  8815. { //[Skotlex]
  8816. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8817. return;
  8818. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8819. }
  8820. guild_send_message(sd, text, textlen);
  8821. }
  8822. /*==========================================
  8823. * ギルド同盟要求
  8824. *------------------------------------------*/
  8825. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  8826. {
  8827. struct map_session_data *t_sd;
  8828. if(!sd->state.gmaster_flag)
  8829. return;
  8830. if(map[sd->bl.m].flag.guildlock)
  8831. { //Guild locked.
  8832. clif_displaymessage(fd, msg_txt(228));
  8833. return;
  8834. }
  8835. t_sd = map_id2sd(RFIFOL(fd,2));
  8836. // @noask [LuzZza]
  8837. if(t_sd && t_sd->state.noask) {
  8838. clif_noask_sub(sd, t_sd, 3);
  8839. return;
  8840. }
  8841. guild_reqalliance(sd,t_sd);
  8842. }
  8843. /*==========================================
  8844. * ギルド同盟要求返信
  8845. *------------------------------------------*/
  8846. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  8847. {
  8848. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8849. }
  8850. /*==========================================
  8851. * ギルド関係解消
  8852. *------------------------------------------*/
  8853. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  8854. {
  8855. if(!sd->state.gmaster_flag)
  8856. return;
  8857. if(map[sd->bl.m].flag.guildlock)
  8858. { //Guild locked.
  8859. clif_displaymessage(fd, msg_txt(228));
  8860. return;
  8861. }
  8862. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8863. }
  8864. /*==========================================
  8865. * ギルド敵対
  8866. *------------------------------------------*/
  8867. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  8868. {
  8869. struct map_session_data *t_sd;
  8870. if(!sd->state.gmaster_flag)
  8871. return;
  8872. if(map[sd->bl.m].flag.guildlock)
  8873. { //Guild locked.
  8874. clif_displaymessage(fd, msg_txt(228));
  8875. return;
  8876. }
  8877. t_sd = map_id2sd(RFIFOL(fd,2));
  8878. // @noask [LuzZza]
  8879. if(t_sd && t_sd->state.noask) {
  8880. clif_noask_sub(sd, t_sd, 4);
  8881. return;
  8882. }
  8883. guild_opposition(sd,t_sd);
  8884. }
  8885. /*==========================================
  8886. * ギルド解散
  8887. *------------------------------------------*/
  8888. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  8889. {
  8890. if(map[sd->bl.m].flag.guildlock)
  8891. { //Guild locked.
  8892. clif_displaymessage(fd, msg_txt(228));
  8893. return;
  8894. }
  8895. guild_break(sd,(char*)RFIFOP(fd,2));
  8896. }
  8897. // pet
  8898. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  8899. {
  8900. pet_menu(sd,RFIFOB(fd,2));
  8901. }
  8902. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  8903. {
  8904. pet_catch_process2(sd,RFIFOL(fd,2));
  8905. }
  8906. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  8907. {
  8908. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  8909. return;
  8910. pet_select_egg(sd,RFIFOW(fd,2)-2);
  8911. sd->menuskill_val = sd->menuskill_id = 0;
  8912. }
  8913. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  8914. {
  8915. if(sd->pd)
  8916. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  8917. }
  8918. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  8919. {
  8920. pet_change_name(sd,(char*)RFIFOP(fd,2));
  8921. }
  8922. /*==========================================
  8923. * /kill <???>
  8924. * (or right click menu for GM "(name) force to quit")
  8925. * S 00cc <id>.L
  8926. *------------------------------------------*/
  8927. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  8928. {
  8929. struct block_list *target;
  8930. int tid,lv;
  8931. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8932. return;
  8933. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_kick)) )
  8934. return;
  8935. tid = RFIFOL(fd,2);
  8936. target = map_id2bl(tid);
  8937. if (!target) {
  8938. clif_GM_kickack(sd, 0);
  8939. return;
  8940. }
  8941. switch (target->type) {
  8942. case BL_PC:
  8943. {
  8944. struct map_session_data *tsd = (struct map_session_data *)target;
  8945. if (pc_isGM(sd) <= pc_isGM(tsd)) {
  8946. clif_GM_kickack(sd, 0);
  8947. return;
  8948. }
  8949. clif_GM_kick(sd, tsd);
  8950. if(log_config.gm && lv >= log_config.gm) {
  8951. char message[256];
  8952. sprintf(message, "/kick %s (%d)", tsd->status.name, tsd->status.char_id);
  8953. log_atcommand(sd, message);
  8954. }
  8955. }
  8956. break;
  8957. case BL_MOB:
  8958. status_percent_damage(&sd->bl, target, 100, 0, true);
  8959. if(log_config.gm && lv >= log_config.gm) {
  8960. char message[256];
  8961. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  8962. log_atcommand(sd, message);
  8963. }
  8964. break;
  8965. case BL_NPC:
  8966. {
  8967. struct npc_data* nd = (struct npc_data *)target;
  8968. lv = get_atcommand_level(atcommand_unloadnpc);
  8969. if( pc_isGM(sd) < lv )
  8970. return;
  8971. npc_unload(nd);
  8972. if( log_config.gm && lv >= log_config.gm ) {
  8973. char message[256];
  8974. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  8975. log_atcommand(sd, message);
  8976. }
  8977. }
  8978. break;
  8979. default:
  8980. clif_GM_kickack(sd, 0);
  8981. }
  8982. }
  8983. /*==========================================
  8984. * /killall
  8985. *------------------------------------------*/
  8986. void clif_parse_GMKickAll(int fd, struct map_session_data* sd)
  8987. {
  8988. is_atcommand(fd, sd, "@kickall");
  8989. }
  8990. /*==========================================
  8991. * /shift <name>
  8992. *------------------------------------------*/
  8993. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  8994. {
  8995. char *player_name;
  8996. int lv;
  8997. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8998. return;
  8999. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_jumpto)) )
  9000. return;
  9001. player_name = (char*)RFIFOP(fd,2);
  9002. player_name[NAME_LENGTH-1] = '\0';
  9003. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9004. if( log_config.gm && lv >= log_config.gm ) {
  9005. char message[NAME_LENGTH+7];
  9006. sprintf(message, "/shift %s", player_name);
  9007. log_atcommand(sd, message);
  9008. }
  9009. }
  9010. /*==========================================
  9011. * /recall <name>
  9012. *------------------------------------------*/
  9013. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  9014. {
  9015. char *player_name;
  9016. int lv;
  9017. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9018. return;
  9019. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_recall)) )
  9020. return;
  9021. player_name = (char*)RFIFOP(fd,2);
  9022. player_name[NAME_LENGTH-1] = '\0';
  9023. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9024. if( log_config.gm && lv >= log_config.gm ) {
  9025. char message[NAME_LENGTH+8];
  9026. sprintf(message, "/recall %s", player_name);
  9027. log_atcommand(sd, message);
  9028. }
  9029. }
  9030. /*==========================================
  9031. * /monster /item
  9032. *------------------------------------------*/
  9033. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  9034. {
  9035. char *monster_item_name;
  9036. char message[NAME_LENGTH+10]; //For logging.
  9037. int level;
  9038. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9039. return;
  9040. monster_item_name = (char*)RFIFOP(fd,2);
  9041. monster_item_name[NAME_LENGTH-1] = '\0';
  9042. if( mobdb_searchname(monster_item_name) ) {
  9043. if( pc_isGM(sd) < (level=get_atcommand_level(atcommand_monster)) )
  9044. return;
  9045. atcommand_monster(fd, sd, "@monster", monster_item_name); // as @monster
  9046. if( log_config.gm && level >= log_config.gm )
  9047. { //Log action. [Skotlex]
  9048. snprintf(message, sizeof(message)-1, "@spawn %s", monster_item_name);
  9049. log_atcommand(sd, message);
  9050. }
  9051. return;
  9052. }
  9053. if( itemdb_searchname(monster_item_name) == NULL )
  9054. return;
  9055. if( pc_isGM(sd) < (level = get_atcommand_level(atcommand_item)) )
  9056. return;
  9057. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9058. if( log_config.gm && level >= log_config.gm )
  9059. { //Log action. [Skotlex]
  9060. sprintf(message, "@item %s", monster_item_name);
  9061. log_atcommand(sd, message);
  9062. }
  9063. }
  9064. /*==========================================
  9065. * /hide
  9066. *------------------------------------------*/
  9067. void clif_parse_GMHide(int fd, struct map_session_data *sd)
  9068. {
  9069. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9070. return;
  9071. if( pc_isGM(sd) < get_atcommand_level(atcommand_hide) )
  9072. return;
  9073. if( sd->sc.option & OPTION_INVISIBLE ) {
  9074. sd->sc.option &= ~OPTION_INVISIBLE;
  9075. if (sd->disguise)
  9076. status_set_viewdata(&sd->bl, sd->disguise);
  9077. else
  9078. status_set_viewdata(&sd->bl, sd->status.class_);
  9079. clif_displaymessage(fd, "Invisible: Off.");
  9080. } else {
  9081. sd->sc.option |= OPTION_INVISIBLE;
  9082. sd->vd.class_ = INVISIBLE_CLASS;
  9083. clif_displaymessage(fd, "Invisible: On.");
  9084. if( log_config.gm && get_atcommand_level(atcommand_hide) >= log_config.gm )
  9085. log_atcommand(sd, "/hide");
  9086. }
  9087. clif_changeoption(&sd->bl);
  9088. }
  9089. /*==========================================
  9090. * GM adjustment of a player's manner value (right-click GM menu)
  9091. * S 0149 <id>.L <type>.B <value>.W
  9092. * type: 0 - positive points
  9093. * 1 - negative points
  9094. * 2 - self mute (+10 minutes)
  9095. *------------------------------------------*/
  9096. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9097. {
  9098. int id, type, value, level;
  9099. struct map_session_data *dstsd;
  9100. id = RFIFOL(fd,2);
  9101. type = RFIFOB(fd,6);
  9102. value = RFIFOW(fd,7);
  9103. if( type == 0 )
  9104. value = 0 - value;
  9105. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  9106. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  9107. if (type == 2 /* && (pc_isGM(sd) > 0 || sd->bl.id != id)*/)
  9108. return;
  9109. dstsd = map_id2sd(id);
  9110. if( dstsd == NULL )
  9111. return;
  9112. if( (level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(atcommand_mute) )
  9113. {
  9114. clif_manner_message(sd, 0);
  9115. clif_manner_message(dstsd, 5);
  9116. if( dstsd->status.manner < value ) {
  9117. dstsd->status.manner -= value;
  9118. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  9119. } else {
  9120. dstsd->status.manner = 0;
  9121. status_change_end(&dstsd->bl,SC_NOCHAT,-1);
  9122. }
  9123. if( type != 2 )
  9124. clif_GM_silence(sd, dstsd, type);
  9125. }
  9126. }
  9127. /*==========================================
  9128. * GM adjustment of a player's manner value by -60 (using name)
  9129. * /rc <name>
  9130. * S 0212 <name>.24B
  9131. *------------------------------------------*/
  9132. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  9133. {
  9134. char* name = (char*)RFIFOP(fd,2);
  9135. struct map_session_data* dstsd;
  9136. name[23] = '\0';
  9137. dstsd = map_nick2sd(name);
  9138. if( dstsd == NULL )
  9139. return;
  9140. if( pc_isGM(sd) > pc_isGM(dstsd) && pc_isGM(sd) >= get_atcommand_level(atcommand_mute) )
  9141. {
  9142. clif_manner_message(sd, 0);
  9143. clif_manner_message(dstsd, 3);
  9144. dstsd->status.manner -= 60;
  9145. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  9146. clif_GM_silence(sd, dstsd, 1);
  9147. }
  9148. }
  9149. /*==========================================
  9150. * GM requesting account name (for right-click gm menu)
  9151. * S 01df <id>.L
  9152. * R 01e0 <id>.L <name>.24B
  9153. *------------------------------------------*/
  9154. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  9155. {
  9156. int tid;
  9157. tid = RFIFOL(fd,2);
  9158. //TODO: find out if this works for any player or only for authorized GMs
  9159. WFIFOHEAD(fd,packet_len(0x1e0));
  9160. WFIFOW(fd,0) = 0x1e0;
  9161. WFIFOL(fd,2) = tid;
  9162. safestrncpy((char*)WFIFOP(fd,6), "", 24); // insert account name here >_<
  9163. WFIFOSET(fd, packet_len(0x1e0));
  9164. }
  9165. /*==========================================
  9166. * GM single cell type change request
  9167. * /changemaptype <x> <y> <type>
  9168. * S 0198 <x>.W <y>.W <gat>.W
  9169. *------------------------------------------*/
  9170. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  9171. {
  9172. int x,y,type;
  9173. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9174. return;
  9175. if( pc_isGM(sd) < 99 ) //TODO: add proper check
  9176. return;
  9177. x = RFIFOW(fd,2);
  9178. y = RFIFOW(fd,4);
  9179. type = RFIFOW(fd,6);
  9180. map_setgatcell(sd->bl.m,x,y,type);
  9181. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  9182. //FIXME: once players leave the map, the client 'forgets' this information.
  9183. }
  9184. /// S 00cf <nick>.24B <type>.B
  9185. /// type: 0 (/ex nick) deny speech from nick
  9186. /// 1 (/in nick) allow speech from nick
  9187. ///
  9188. /// R 00d1 <type>.B <result>.B
  9189. /// type: 0: deny, 1: allow
  9190. /// result: 0: success, 1: fail 2: list full
  9191. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  9192. {
  9193. char output[512];
  9194. char* nick;
  9195. uint8 type;
  9196. int i;
  9197. nick = (char*)RFIFOP(fd,2); // speed up
  9198. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  9199. type = RFIFOB(fd,26);
  9200. WFIFOHEAD(fd,packet_len(0xd1));
  9201. WFIFOW(fd,0) = 0x0d1;
  9202. WFIFOB(fd,2) = type;
  9203. if( type == 0 )
  9204. { // Add name to ignore list (block)
  9205. // Bot-check...
  9206. if (strcmp(wisp_server_name, nick) == 0)
  9207. { // to find possible bot users who automaticaly ignore people
  9208. 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);
  9209. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9210. WFIFOB(fd,3) = 1; // fail
  9211. WFIFOSET(fd, packet_len(0x0d1));
  9212. return;
  9213. }
  9214. // try to find a free spot, while checking for duplicates at the same time
  9215. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  9216. if( i == MAX_IGNORE_LIST )
  9217. {// no space for new entry
  9218. WFIFOB(fd,3) = 2; // fail
  9219. WFIFOSET(fd, packet_len(0x0d1));
  9220. return;
  9221. }
  9222. if( sd->ignore[i].name[0] != '\0' )
  9223. {// name already exists
  9224. WFIFOB(fd,3) = 0; // Aegis reports success.
  9225. WFIFOSET(fd, packet_len(0x0d1));
  9226. return;
  9227. }
  9228. //Insert in position i
  9229. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  9230. WFIFOB(fd,3) = 0; // success
  9231. WFIFOSET(fd, packet_len(0x0d1));
  9232. }
  9233. else
  9234. { // Remove name from ignore list (unblock)
  9235. // find entry
  9236. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  9237. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' )
  9238. { //Not found
  9239. WFIFOB(fd,3) = 1; // fail
  9240. WFIFOSET(fd, packet_len(0x0d1));
  9241. return;
  9242. }
  9243. // move everything one place down to overwrite removed entry
  9244. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  9245. // wipe last entry
  9246. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  9247. WFIFOB(fd,3) = 0; // success
  9248. WFIFOSET(fd, packet_len(0x0d1));
  9249. }
  9250. return;
  9251. }
  9252. /// S 00d0 <type>.B
  9253. /// type: 0 (/exall) deny all speech
  9254. /// 1 (/inall) allow all speech
  9255. ///
  9256. /// R 00d2 <type>.B <fail>.B
  9257. /// type: 0: deny, 1: allow
  9258. /// fail: 0: success, 1: fail
  9259. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  9260. {
  9261. WFIFOHEAD(fd,packet_len(0xd2));
  9262. WFIFOW(fd,0) = 0x0d2;
  9263. WFIFOB(fd,2) = RFIFOB(fd,2);
  9264. if( RFIFOB(fd,2) == 0 )
  9265. {// Deny all
  9266. if( sd->state.ignoreAll ) {
  9267. WFIFOB(fd,3) = 1; // fail
  9268. } else {
  9269. sd->state.ignoreAll = 1;
  9270. WFIFOB(fd,3) = 0; // success
  9271. }
  9272. }
  9273. else
  9274. {//Unblock everyone
  9275. if( sd->state.ignoreAll ) {
  9276. sd->state.ignoreAll = 0;
  9277. WFIFOB(fd,3) = 0; // success
  9278. } else {
  9279. if (sd->ignore[0].name[0] != '\0')
  9280. { //Wipe the ignore list.
  9281. memset(sd->ignore, 0, sizeof(sd->ignore));
  9282. WFIFOB(fd,3) = 0; // success
  9283. } else {
  9284. WFIFOB(fd,3) = 1; // fail
  9285. }
  9286. }
  9287. }
  9288. WFIFOSET(fd, packet_len(0x0d2));
  9289. return;
  9290. }
  9291. /*==========================================
  9292. * Wis拒否リスト
  9293. *------------------------------------------*/
  9294. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9295. {
  9296. int i;
  9297. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  9298. WFIFOW(fd,0) = 0xd4;
  9299. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9300. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  9301. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  9302. WFIFOSET(fd, WFIFOW(fd,2));
  9303. return;
  9304. }
  9305. /*==========================================
  9306. * スパノビの/doridoriによるSPR2倍
  9307. *------------------------------------------*/
  9308. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  9309. {
  9310. if (sd->state.doridori) return;
  9311. switch (sd->class_&MAPID_UPPERMASK)
  9312. {
  9313. case MAPID_SOUL_LINKER:
  9314. case MAPID_STAR_GLADIATOR:
  9315. case MAPID_TAEKWON:
  9316. if (!sd->state.rest)
  9317. break;
  9318. case MAPID_SUPER_NOVICE:
  9319. sd->state.doridori=1;
  9320. break;
  9321. }
  9322. return;
  9323. }
  9324. /*==========================================
  9325. * スパノビの爆裂波動
  9326. *------------------------------------------*/
  9327. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9328. {
  9329. if(sd){
  9330. int nextbaseexp=pc_nextbaseexp(sd);
  9331. if (battle_config.etc_log){
  9332. if(nextbaseexp != 0)
  9333. 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));
  9334. else
  9335. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9336. }
  9337. 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){
  9338. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9339. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  9340. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9341. }
  9342. }
  9343. return;
  9344. }
  9345. // random notes:
  9346. // 0x214: monster/player info ?
  9347. /*==========================================
  9348. * Friends List
  9349. *------------------------------------------*/
  9350. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9351. { //Toggles a single friend online/offline [Skotlex]
  9352. int i, fd = sd->fd;
  9353. //Seek friend.
  9354. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9355. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9356. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9357. return; //Not found
  9358. WFIFOHEAD(fd,packet_len(0x206));
  9359. WFIFOW(fd, 0) = 0x206;
  9360. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  9361. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  9362. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9363. WFIFOSET(fd, packet_len(0x206));
  9364. }
  9365. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9366. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9367. {
  9368. int account_id, char_id, online;
  9369. account_id = va_arg(ap, int);
  9370. char_id = va_arg(ap, int);
  9371. online = va_arg(ap, int);
  9372. clif_friendslist_toggle(sd, account_id, char_id, online);
  9373. return 0;
  9374. }
  9375. //For sending the whole friends list.
  9376. void clif_friendslist_send(struct map_session_data *sd)
  9377. {
  9378. int i = 0, n, fd = sd->fd;
  9379. // Send friends list
  9380. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  9381. WFIFOW(fd, 0) = 0x201;
  9382. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9383. {
  9384. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9385. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9386. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9387. }
  9388. if (i) {
  9389. WFIFOW(fd,2) = 4 + 32 * i;
  9390. WFIFOSET(fd, WFIFOW(fd,2));
  9391. }
  9392. for (n = 0; n < i; n++)
  9393. { //Sending the online players
  9394. if (map_charid2sd(sd->status.friends[n].char_id))
  9395. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9396. }
  9397. }
  9398. /// Reply for add friend request: (success => type 0)
  9399. /// type=0 : MsgStringTable[821]="You have become friends with (%s)."
  9400. /// type=1 : MsgStringTable[822]="(%s) does not want to be friends with you."
  9401. /// type=2 : MsgStringTable[819]="Your Friend List is full."
  9402. /// type=3 : MsgStringTable[820]="(%s)'s Friend List is full."
  9403. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9404. {
  9405. int fd;
  9406. nullpo_retv(sd);
  9407. fd = sd->fd;
  9408. WFIFOHEAD(fd,packet_len(0x209));
  9409. WFIFOW(fd,0) = 0x209;
  9410. WFIFOW(fd,2) = type;
  9411. if (f_sd)
  9412. {
  9413. WFIFOW(fd,4) = f_sd->status.account_id;
  9414. WFIFOW(fd,8) = f_sd->status.char_id;
  9415. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9416. }
  9417. WFIFOSET(fd, packet_len(0x209));
  9418. }
  9419. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  9420. {
  9421. struct map_session_data *f_sd;
  9422. int i, f_fd;
  9423. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9424. // Friend doesn't exist (no player with this name)
  9425. if (f_sd == NULL) {
  9426. clif_displaymessage(fd, msg_txt(3));
  9427. return;
  9428. }
  9429. // @noask [LuzZza]
  9430. if(f_sd->state.noask) {
  9431. clif_noask_sub(sd, f_sd, 5);
  9432. return;
  9433. }
  9434. // Friend already exists
  9435. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9436. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9437. clif_displaymessage(fd, "Friend already exists.");
  9438. return;
  9439. }
  9440. }
  9441. if (i == MAX_FRIENDS) {
  9442. //No space, list full.
  9443. clif_friendslist_reqack(sd, f_sd, 2);
  9444. return;
  9445. }
  9446. f_fd = f_sd->fd;
  9447. WFIFOHEAD(f_fd,packet_len(0x207));
  9448. WFIFOW(f_fd,0) = 0x207;
  9449. WFIFOL(f_fd,2) = sd->status.account_id;
  9450. WFIFOL(f_fd,6) = sd->status.char_id;
  9451. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9452. WFIFOSET(f_fd, packet_len(0x207));
  9453. return;
  9454. }
  9455. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  9456. {
  9457. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9458. struct map_session_data *f_sd;
  9459. int char_id, account_id;
  9460. char reply;
  9461. account_id = RFIFOL(fd,2);
  9462. char_id = RFIFOL(fd,6);
  9463. reply = RFIFOB(fd,10);
  9464. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9465. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9466. if (f_sd == NULL)
  9467. return;
  9468. if (reply == 0)
  9469. clif_friendslist_reqack(f_sd, sd, 1);
  9470. else {
  9471. int i;
  9472. // Find an empty slot
  9473. for (i = 0; i < MAX_FRIENDS; i++)
  9474. if (f_sd->status.friends[i].char_id == 0)
  9475. break;
  9476. if (i == MAX_FRIENDS) {
  9477. clif_friendslist_reqack(f_sd, sd, 2);
  9478. return;
  9479. }
  9480. f_sd->status.friends[i].account_id = sd->status.account_id;
  9481. f_sd->status.friends[i].char_id = sd->status.char_id;
  9482. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9483. clif_friendslist_reqack(f_sd, sd, 0);
  9484. if (battle_config.friend_auto_add) {
  9485. // Also add f_sd to sd's friendlist.
  9486. for (i = 0; i < MAX_FRIENDS; i++) {
  9487. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  9488. return; //No need to add anything.
  9489. if (sd->status.friends[i].char_id == 0)
  9490. break;
  9491. }
  9492. if (i == MAX_FRIENDS) {
  9493. clif_friendslist_reqack(sd, f_sd, 2);
  9494. return;
  9495. }
  9496. sd->status.friends[i].account_id = f_sd->status.account_id;
  9497. sd->status.friends[i].char_id = f_sd->status.char_id;
  9498. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  9499. clif_friendslist_reqack(sd, f_sd, 0);
  9500. }
  9501. }
  9502. return;
  9503. }
  9504. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  9505. {
  9506. // 0x203 </o> <ID to be removed W 4B>
  9507. int account_id, char_id;
  9508. int i, j;
  9509. account_id = RFIFOL(fd,2);
  9510. char_id = RFIFOL(fd,6);
  9511. // Search friend
  9512. for (i = 0; i < MAX_FRIENDS &&
  9513. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9514. if (i == MAX_FRIENDS) {
  9515. clif_displaymessage(fd, "Name not found in list.");
  9516. return;
  9517. }
  9518. // move all chars down
  9519. for(j = i + 1; j < MAX_FRIENDS; j++)
  9520. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9521. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9522. clif_displaymessage(fd, "Friend removed");
  9523. WFIFOHEAD(fd,packet_len(0x20a));
  9524. WFIFOW(fd,0) = 0x20a;
  9525. WFIFOL(fd,2) = account_id;
  9526. WFIFOL(fd,6) = char_id;
  9527. WFIFOSET(fd, packet_len(0x20a));
  9528. // clif_friendslist_send(sd); //This is not needed anymore.
  9529. return;
  9530. }
  9531. /*==========================================
  9532. * /pvpinfo
  9533. *------------------------------------------*/
  9534. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  9535. {
  9536. WFIFOHEAD(fd,packet_len(0x210));
  9537. WFIFOW(fd,0) = 0x210;
  9538. //WFIFOL(fd,2) = 0; // not sure what for yet
  9539. //WFIFOL(fd,6) = 0;
  9540. WFIFOL(fd,10) = sd->pvp_won; // times won
  9541. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  9542. WFIFOL(fd,18) = sd->pvp_point;
  9543. WFIFOSET(fd, packet_len(0x210));
  9544. return;
  9545. }
  9546. /*==========================================
  9547. * /blacksmith
  9548. *------------------------------------------*/
  9549. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  9550. {
  9551. int i;
  9552. const char* name;
  9553. WFIFOHEAD(fd,packet_len(0x219));
  9554. WFIFOW(fd,0) = 0x219;
  9555. //Packet size limits this list to 10 elements. [Skotlex]
  9556. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9557. if (smith_fame_list[i].id > 0) {
  9558. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  9559. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  9560. {
  9561. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  9562. } else
  9563. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  9564. } else
  9565. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  9566. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  9567. }
  9568. for(;i < 10; i++) { //In case the MAX is less than 10.
  9569. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  9570. WFIFOL(fd, 242 + i * 4) = 0;
  9571. }
  9572. WFIFOSET(fd, packet_len(0x219));
  9573. }
  9574. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  9575. {
  9576. int fd = sd->fd;
  9577. WFIFOHEAD(fd,packet_len(0x21b));
  9578. WFIFOW(fd,0) = 0x21b;
  9579. WFIFOL(fd,2) = points;
  9580. WFIFOL(fd,6) = sd->status.fame;
  9581. WFIFOSET(fd, packet_len(0x21b));
  9582. return 0;
  9583. }
  9584. /*==========================================
  9585. * /alchemist
  9586. *------------------------------------------*/
  9587. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  9588. {
  9589. int i;
  9590. const char* name;
  9591. WFIFOHEAD(fd,packet_len(0x21a));
  9592. WFIFOW(fd,0) = 0x21a;
  9593. //Packet size limits this list to 10 elements. [Skotlex]
  9594. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9595. if (chemist_fame_list[i].id > 0) {
  9596. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  9597. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  9598. {
  9599. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9600. } else
  9601. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  9602. } else
  9603. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9604. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  9605. }
  9606. for(;i < 10; i++) { //In case the MAX is less than 10.
  9607. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9608. WFIFOL(fd, 242 + i * 4) = 0;
  9609. }
  9610. WFIFOSET(fd, packet_len(0x21a));
  9611. }
  9612. int clif_fame_alchemist(struct map_session_data *sd, int points)
  9613. {
  9614. int fd = sd->fd;
  9615. WFIFOHEAD(fd,packet_len(0x21c));
  9616. WFIFOW(fd,0) = 0x21c;
  9617. WFIFOL(fd,2) = points;
  9618. WFIFOL(fd,6) = sd->status.fame;
  9619. WFIFOSET(fd, packet_len(0x21c));
  9620. return 0;
  9621. }
  9622. /*==========================================
  9623. * /taekwon
  9624. *------------------------------------------*/
  9625. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  9626. {
  9627. int i;
  9628. const char* name;
  9629. WFIFOHEAD(fd,packet_len(0x226));
  9630. WFIFOW(fd,0) = 0x226;
  9631. //Packet size limits this list to 10 elements. [Skotlex]
  9632. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9633. if (taekwon_fame_list[i].id > 0) {
  9634. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  9635. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  9636. {
  9637. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9638. } else
  9639. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  9640. } else
  9641. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9642. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  9643. }
  9644. for(;i < 10; i++) { //In case the MAX is less than 10.
  9645. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9646. WFIFOL(fd, 242 + i * 4) = 0;
  9647. }
  9648. WFIFOSET(fd, packet_len(0x226));
  9649. }
  9650. int clif_fame_taekwon(struct map_session_data *sd, int points)
  9651. {
  9652. int fd = sd->fd;
  9653. WFIFOHEAD(fd,packet_len(0x224));
  9654. WFIFOW(fd,0) = 0x224;
  9655. WFIFOL(fd,2) = points;
  9656. WFIFOL(fd,6) = sd->status.fame;
  9657. WFIFOSET(fd, packet_len(0x224));
  9658. return 0;
  9659. }
  9660. /*==========================================
  9661. * PK Ranking table?
  9662. *------------------------------------------*/
  9663. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  9664. {
  9665. int i;
  9666. WFIFOHEAD(fd,packet_len(0x238));
  9667. WFIFOW(fd,0) = 0x238;
  9668. for(i=0;i<10;i++){
  9669. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  9670. WFIFOL(fd,i*4+242) = 0;
  9671. }
  9672. WFIFOSET(fd, packet_len(0x238));
  9673. return;
  9674. }
  9675. /*==========================================
  9676. * SG Feel save OK [Komurka]
  9677. *------------------------------------------*/
  9678. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  9679. {
  9680. int i;
  9681. if (sd->menuskill_id != SG_FEEL)
  9682. return;
  9683. i = sd->menuskill_val-1;
  9684. if (i<0 || i > 2) return; //Bug?
  9685. sd->feel_map[i].index = map_id2index(sd->bl.m);
  9686. sd->feel_map[i].m = sd->bl.m;
  9687. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  9688. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  9689. // clif_misceffect2(&sd->bl, 0x1b0);
  9690. // clif_misceffect2(&sd->bl, 0x21f);
  9691. clif_feel_info(sd, i, 0);
  9692. sd->menuskill_val = sd->menuskill_id = 0;
  9693. }
  9694. /*==========================================
  9695. * Question about Star Glaldiator save map [Komurka]
  9696. *------------------------------------------*/
  9697. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv)
  9698. {
  9699. WFIFOHEAD(fd,packet_len(0x253));
  9700. WFIFOW(fd,0)=0x253;
  9701. WFIFOSET(fd, packet_len(0x253));
  9702. sd->menuskill_id = SG_FEEL;
  9703. sd->menuskill_val = skilllv;
  9704. }
  9705. /*==========================================
  9706. * Homunculus packets
  9707. *------------------------------------------*/
  9708. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  9709. {
  9710. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  9711. }
  9712. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  9713. {
  9714. if(!merc_is_hom_active(sd->hd))
  9715. return;
  9716. unit_walktoxy(&sd->hd->bl, sd->bl.x,sd->bl.y-1, 4);
  9717. }
  9718. void clif_parse_HomMoveTo(int fd,struct map_session_data *sd)
  9719. {
  9720. short x,y,cmd;
  9721. if(!merc_is_hom_active(sd->hd))
  9722. return;
  9723. cmd = RFIFOW(fd,0);
  9724. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  9725. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  9726. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  9727. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  9728. unit_walktoxy(&(sd->hd->bl),x,y,4);
  9729. }
  9730. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  9731. { //[orn]
  9732. if(!merc_is_hom_active(sd->hd))
  9733. return;
  9734. unit_attack(&sd->hd->bl,RFIFOL(fd,6),0) ;
  9735. }
  9736. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  9737. { //[orn]
  9738. int cmd;
  9739. cmd = RFIFOW(fd,0);
  9740. if(!merc_is_hom_active(sd->hd))
  9741. return;
  9742. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  9743. }
  9744. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  9745. {
  9746. int item_position = pc_search_inventory(sd, 7621);
  9747. if (item_position < 0)
  9748. return;
  9749. if (!status_revive(&sd->bl, 100, 100))
  9750. return;
  9751. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  9752. pc_delitem(sd, item_position, 1, 0);
  9753. }
  9754. /// /check <string>
  9755. /// S 0213 <string>.24B
  9756. void clif_parse_Check(int fd, struct map_session_data *sd)
  9757. {
  9758. // no info
  9759. }
  9760. #ifndef TXT_ONLY
  9761. /*==========================================
  9762. * MAIL SYSTEM
  9763. * By Zephyrus
  9764. *==========================================*/
  9765. /*------------------------------------------
  9766. * Reply to Set Attachment operation
  9767. * 0 : Successfully attached item to mail
  9768. * 1 : Fail to set the attachment
  9769. *------------------------------------------*/
  9770. static void clif_Mail_setattachment(int fd, int index, uint8 flag)
  9771. {
  9772. WFIFOHEAD(fd,packet_len(0x255));
  9773. WFIFOW(fd,0) = 0x255;
  9774. WFIFOW(fd,2) = index;
  9775. WFIFOB(fd,4) = flag;
  9776. WFIFOSET(fd,packet_len(0x255));
  9777. }
  9778. /*------------------------------------------
  9779. * Reply to Get Attachment operation
  9780. * 0 : Successfully added attachment to Inventory
  9781. * 1 : Fail to set the item to inventory
  9782. * 2 : Weight problems
  9783. *------------------------------------------*/
  9784. void clif_Mail_getattachment(int fd, uint8 flag)
  9785. {
  9786. WFIFOHEAD(fd,packet_len(0x245));
  9787. WFIFOW(fd,0) = 0x245;
  9788. WFIFOB(fd,2) = flag;
  9789. WFIFOSET(fd,packet_len(0x245));
  9790. }
  9791. /*------------------------------------------
  9792. * Send Mail ack
  9793. * 0 : Message Send Ok
  9794. * 1 : Recipient does not exist
  9795. *------------------------------------------*/
  9796. void clif_Mail_send(int fd, bool fail)
  9797. {
  9798. WFIFOHEAD(fd,packet_len(0x249));
  9799. WFIFOW(fd,0) = 0x249;
  9800. WFIFOB(fd,2) = fail;
  9801. WFIFOSET(fd,packet_len(0x249));
  9802. }
  9803. /*------------------------------------------
  9804. * Delete Mail ack
  9805. * 0 : Delete ok
  9806. * 1 : Delete failed
  9807. *------------------------------------------*/
  9808. void clif_Mail_delete(int fd, int mail_id, short fail)
  9809. {
  9810. WFIFOHEAD(fd, packet_len(0x257));
  9811. WFIFOW(fd,0) = 0x257;
  9812. WFIFOL(fd,2) = mail_id;
  9813. WFIFOW(fd,6) = fail;
  9814. WFIFOSET(fd, packet_len(0x257));
  9815. }
  9816. /*------------------------------------------
  9817. * Return Mail ack
  9818. * 0 : Mail returned to the sender
  9819. * 1 : The mail does not exist
  9820. *------------------------------------------*/
  9821. void clif_Mail_return(int fd, int mail_id, short fail)
  9822. {
  9823. WFIFOHEAD(fd,packet_len(0x274));
  9824. WFIFOW(fd,0) = 0x274;
  9825. WFIFOL(fd,2) = mail_id;
  9826. WFIFOW(fd,6) = fail;
  9827. WFIFOSET(fd,packet_len(0x274));
  9828. }
  9829. /*------------------------------------------
  9830. * You have New Mail
  9831. *------------------------------------------*/
  9832. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  9833. {
  9834. WFIFOHEAD(fd,packet_len(0x24a));
  9835. WFIFOW(fd,0) = 0x24a;
  9836. WFIFOL(fd,2) = mail_id;
  9837. safestrncpy((char*)WFIFOP(fd,6), sender, NAME_LENGTH);
  9838. safestrncpy((char*)WFIFOP(fd,30), title, MAIL_TITLE_LENGTH);
  9839. WFIFOSET(fd,packet_len(0x24a));
  9840. }
  9841. /*------------------------------------------
  9842. * Handles Mail Window on Client
  9843. * flag : 0 open | 1 close
  9844. *------------------------------------------*/
  9845. void clif_Mail_window(int fd, int flag)
  9846. {
  9847. WFIFOHEAD(fd,packet_len(0x260));
  9848. WFIFOW(fd,0) = 0x260;
  9849. WFIFOL(fd,2) = flag;
  9850. WFIFOSET(fd,packet_len(0x260));
  9851. }
  9852. /*------------------------------------------
  9853. * Send Inbox Data to Client
  9854. *------------------------------------------*/
  9855. void clif_Mail_refreshinbox(struct map_session_data *sd)
  9856. {
  9857. int fd = sd->fd;
  9858. struct mail_data *md = &sd->mail.inbox;
  9859. struct mail_message *msg;
  9860. int len, i, j;
  9861. len = 8 + (73 * md->amount);
  9862. WFIFOHEAD(fd,len);
  9863. WFIFOW(fd,0) = 0x240;
  9864. WFIFOW(fd,2) = len;
  9865. WFIFOL(fd,4) = md->amount;
  9866. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  9867. {
  9868. msg = &md->msg[i];
  9869. if (msg->id < 1)
  9870. continue;
  9871. WFIFOL(fd,8+73*j) = msg->id;
  9872. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  9873. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD); // 0: unread, 1: read
  9874. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  9875. WFIFOL(fd,77+73*j) = msg->timestamp;
  9876. j++;
  9877. }
  9878. WFIFOSET(fd,len);
  9879. if( md->full )
  9880. {
  9881. char output[100];
  9882. sprintf(output, "Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  9883. clif_disp_onlyself(sd, output, strlen(output));
  9884. }
  9885. }
  9886. /*------------------------------------------
  9887. * Client Request Inbox List
  9888. *------------------------------------------*/
  9889. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  9890. {
  9891. struct mail_data* md = &sd->mail.inbox;
  9892. if( md->amount < MAIL_MAX_INBOX && (md->full || md->changed) )
  9893. intif_Mail_requestinbox(sd->status.char_id, 1);
  9894. else
  9895. clif_Mail_refreshinbox(sd);
  9896. mail_removeitem(sd, 0);
  9897. mail_removezeny(sd, 0);
  9898. }
  9899. /*------------------------------------------
  9900. * Read Message
  9901. *------------------------------------------*/
  9902. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  9903. {
  9904. int i, fd = sd->fd;
  9905. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  9906. if( i == MAIL_MAX_INBOX )
  9907. {
  9908. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  9909. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  9910. return;
  9911. }
  9912. else
  9913. {
  9914. struct mail_message *msg = &sd->mail.inbox.msg[i];
  9915. struct item *item = &msg->item;
  9916. struct item_data *data;
  9917. int msg_len = strlen(msg->body), len;
  9918. if( msg_len == 0 ) {
  9919. strcpy(msg->body, "(no message)");
  9920. msg_len = strlen(msg->body);
  9921. }
  9922. len = 101 + msg_len;
  9923. WFIFOHEAD(fd,len);
  9924. WFIFOW(fd,0) = 0x242;
  9925. WFIFOW(fd,2) = len;
  9926. WFIFOL(fd,4) = msg->id;
  9927. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  9928. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  9929. WFIFOL(fd,72) = 0;
  9930. WFIFOL(fd,76) = msg->zeny;
  9931. if( item->nameid && (data = itemdb_search(item->nameid)) != NULL )
  9932. {
  9933. WFIFOL(fd,80) = item->amount;
  9934. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  9935. WFIFOW(fd,86) = data->type;
  9936. WFIFOB(fd,88) = item->identify;
  9937. WFIFOB(fd,89) = item->attribute;
  9938. WFIFOB(fd,90) = item->refine;
  9939. WFIFOW(fd,91) = item->card[0];
  9940. WFIFOW(fd,93) = item->card[1];
  9941. WFIFOW(fd,95) = item->card[2];
  9942. WFIFOW(fd,97) = item->card[3];
  9943. }
  9944. else // no item, set all to zero
  9945. memset(WFIFOP(fd,80), 0x00, 19);
  9946. WFIFOB(fd,99) = (unsigned char)msg_len;
  9947. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  9948. WFIFOSET(fd,len);
  9949. if (msg->status == MAIL_UNREAD) {
  9950. msg->status = MAIL_READ;
  9951. intif_Mail_read(mail_id);
  9952. clif_parse_Mail_refreshinbox(fd, sd);
  9953. }
  9954. }
  9955. }
  9956. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  9957. {
  9958. if( mail_invalid_operation(sd) )
  9959. return;
  9960. clif_Mail_read(sd, RFIFOL(fd,2));
  9961. }
  9962. /*------------------------------------------
  9963. * Get Attachment from Message
  9964. *------------------------------------------*/
  9965. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  9966. {
  9967. int i, mail_id = RFIFOL(fd,2);
  9968. bool fail = false;
  9969. if( mail_invalid_operation(sd) )
  9970. return;
  9971. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  9972. if( i == MAIL_MAX_INBOX )
  9973. return;
  9974. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  9975. return;
  9976. if( sd->mail.inbox.msg[i].item.nameid > 0 )
  9977. {
  9978. struct item_data *data;
  9979. unsigned int weight;
  9980. if ((data = itemdb_search(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  9981. return;
  9982. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) )
  9983. {
  9984. case ADDITEM_NEW:
  9985. fail = ( pc_inventoryblank(sd) == 0 );
  9986. break;
  9987. case ADDITEM_OVERAMOUNT:
  9988. fail = true;
  9989. }
  9990. if( fail )
  9991. {
  9992. clif_Mail_getattachment(fd, 1);
  9993. return;
  9994. }
  9995. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  9996. if( weight > sd->max_weight - sd->weight )
  9997. {
  9998. clif_Mail_getattachment(fd, 2);
  9999. return;
  10000. }
  10001. }
  10002. sd->mail.inbox.msg[i].zeny = 0;
  10003. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  10004. clif_Mail_read(sd, mail_id);
  10005. intif_Mail_getattach(sd->status.char_id, mail_id);
  10006. }
  10007. /*------------------------------------------
  10008. * Delete Message
  10009. *------------------------------------------*/
  10010. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  10011. {
  10012. int i, mail_id = RFIFOL(fd,2);
  10013. if( mail_invalid_operation(sd) )
  10014. return;
  10015. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10016. if (i < MAIL_MAX_INBOX)
  10017. {
  10018. struct mail_message *msg = &sd->mail.inbox.msg[i];
  10019. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 )
  10020. {// can't delete mail without removing attachment first
  10021. clif_Mail_delete(sd->fd, mail_id, 1);
  10022. return;
  10023. }
  10024. intif_Mail_delete(sd->status.char_id, mail_id);
  10025. }
  10026. }
  10027. /*------------------------------------------
  10028. * Return Mail Message
  10029. *------------------------------------------*/
  10030. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  10031. {
  10032. int i, mail_id = RFIFOL(fd,2);
  10033. if( mail_invalid_operation(sd) )
  10034. return;
  10035. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10036. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  10037. intif_Mail_return(sd->status.char_id, mail_id);
  10038. else
  10039. clif_Mail_return(sd->fd, mail_id, 1);
  10040. }
  10041. /*------------------------------------------
  10042. * Set Attachment
  10043. *------------------------------------------*/
  10044. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  10045. {
  10046. int idx = RFIFOW(fd,2);
  10047. int amount = RFIFOL(fd,4);
  10048. unsigned char flag;
  10049. if (idx < 0 || amount < 0)
  10050. return;
  10051. flag = mail_setitem(sd, idx, amount);
  10052. clif_Mail_setattachment(fd,idx,flag);
  10053. }
  10054. /*------------------------------------------
  10055. * Mail Window Operation
  10056. * 0 : Switch to 'new mail' window, or Close mailbox
  10057. * 1 : ???
  10058. * 2 : ???
  10059. *------------------------------------------*/
  10060. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  10061. {
  10062. int flag = RFIFOW(fd,2);
  10063. if (flag == 0 || flag == 1)
  10064. mail_removeitem(sd, 0);
  10065. if (flag == 0 || flag == 2)
  10066. mail_removezeny(sd, 0);
  10067. }
  10068. /*------------------------------------------
  10069. * Send Mail
  10070. * S 0248 <packet len>.w <nick>.24B <title>.40B <body len>.B <message>.?B 00
  10071. *------------------------------------------*/
  10072. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  10073. {
  10074. struct mail_message msg;
  10075. int body_len;
  10076. if( sd->state.trading )
  10077. return;
  10078. if( RFIFOW(fd,2) < 69 ) {
  10079. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  10080. return;
  10081. }
  10082. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 )
  10083. {
  10084. clif_displaymessage(sd->fd,"Cannot send mails too fast!!.");
  10085. clif_Mail_send(fd, true); // fail
  10086. return;
  10087. }
  10088. body_len = RFIFOB(fd,68);
  10089. if (body_len > MAIL_BODY_LENGTH)
  10090. body_len = MAIL_BODY_LENGTH;
  10091. if( !mail_setattachment(sd, &msg) )
  10092. { // Invalid Append condition
  10093. clif_Mail_send(sd->fd, true); // fail
  10094. mail_removeitem(sd,0);
  10095. mail_removezeny(sd,0);
  10096. return;
  10097. }
  10098. msg.id = 0; // id will be assigned by charserver
  10099. msg.send_id = sd->status.char_id;
  10100. msg.dest_id = 0; // will attempt to resolve name
  10101. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  10102. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  10103. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  10104. if (body_len)
  10105. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  10106. else
  10107. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  10108. msg.timestamp = calc_times();
  10109. if( !intif_Mail_send(sd->status.account_id, &msg) )
  10110. mail_deliveryfail(sd, &msg);
  10111. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  10112. }
  10113. /*==========================================
  10114. * AUCTION SYSTEM
  10115. * By Zephyrus
  10116. *==========================================*/
  10117. void clif_Auction_openwindow(struct map_session_data *sd)
  10118. {
  10119. int fd = sd->fd;
  10120. if( sd->state.storage_flag || sd->vender_id || sd->state.trading )
  10121. return;
  10122. WFIFOHEAD(fd,12);
  10123. WFIFOW(fd,0) = 0x25f;
  10124. WFIFOL(fd,2) = 0;
  10125. WFIFOB(fd,6) = 0xb6;
  10126. WFIFOB(fd,7) = 0x00;
  10127. WFIFOB(fd,8) = 0xa6;
  10128. WFIFOB(fd,9) = 0xde;
  10129. WFIFOW(fd,10) = 0;
  10130. WFIFOSET(fd,12);
  10131. }
  10132. void clif_Auction_results(struct map_session_data *sd, short count, short pages, unsigned char *buf)
  10133. {
  10134. int i, fd = sd->fd, len = sizeof(struct auction_data);
  10135. struct auction_data auction;
  10136. struct item_data *item;
  10137. int k;
  10138. WFIFOHEAD(fd,20);
  10139. WFIFOW(fd,0) = 0x252;
  10140. WFIFOW(fd,2) = 12 + (count * 83);
  10141. WFIFOL(fd,4) = pages;
  10142. WFIFOL(fd,8) = count;
  10143. for( i = 0; i < count; i++ )
  10144. {
  10145. memcpy(&auction, RBUFP(buf,i * len), len);
  10146. k = 12 + (i * 83);
  10147. WFIFOL(fd,k) = auction.auction_id;
  10148. safestrncpy(WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  10149. if( (item = itemdb_search(auction.item.nameid)) != NULL && item->view_id > 0 )
  10150. WFIFOW(fd,28+k) = item->view_id;
  10151. else
  10152. WFIFOW(fd,28+k) = auction.item.nameid;
  10153. WFIFOW(fd,30+k) = auction.type;
  10154. WFIFOW(fd,32+k) = 0; // ??
  10155. WFIFOW(fd,34+k) = auction.item.amount; // Allways 1
  10156. WFIFOB(fd,36+k) = auction.item.identify;
  10157. WFIFOB(fd,37+k) = auction.item.attribute;
  10158. WFIFOB(fd,38+k) = auction.item.refine;
  10159. WFIFOW(fd,39+k) = auction.item.card[0];
  10160. WFIFOW(fd,41+k) = auction.item.card[1];
  10161. WFIFOW(fd,43+k) = auction.item.card[2];
  10162. WFIFOW(fd,45+k) = auction.item.card[3];
  10163. WFIFOL(fd,47+k) = auction.price;
  10164. WFIFOL(fd,51+k) = auction.buynow;
  10165. safestrncpy(WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  10166. WFIFOL(fd,79+k) = auction.timestamp;
  10167. }
  10168. WFIFOSET(fd, 12 + (count * 83));
  10169. }
  10170. static void clif_Auction_setitem(int fd, int index, bool fail)
  10171. {
  10172. WFIFOHEAD(fd,packet_len(0x256));
  10173. WFIFOW(fd,0) = 0x256;
  10174. WFIFOW(fd,2) = index;
  10175. WFIFOB(fd,4) = fail;
  10176. WFIFOSET(fd,packet_len(0x256));
  10177. }
  10178. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd)
  10179. {
  10180. if( sd->auction.amount > 0 )
  10181. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  10182. sd->auction.amount = 0;
  10183. }
  10184. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
  10185. {
  10186. int idx = RFIFOW(fd,2) - 2;
  10187. int amount = RFIFOL(fd,4); // Allways 1
  10188. struct item_data *item;
  10189. if( sd->auction.amount > 0 )
  10190. sd->auction.amount = 0;
  10191. if( idx < 0 || idx >= MAX_INVENTORY )
  10192. {
  10193. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  10194. return;
  10195. }
  10196. if( amount != 1 || amount < 0 || amount > sd->status.inventory[idx].amount )
  10197. { // By client, amount is allways set to 1. Maybe this is a future implementation.
  10198. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  10199. return;
  10200. }
  10201. 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) )
  10202. { // Consumible or pets are not allowed
  10203. clif_Auction_setitem(sd->fd, idx, true);
  10204. return;
  10205. }
  10206. if( !pc_candrop(sd, &sd->status.inventory[idx]) || !sd->status.inventory[idx].identify )
  10207. { // Quest Item or something else
  10208. clif_Auction_setitem(sd->fd, idx, true);
  10209. return;
  10210. }
  10211. sd->auction.index = idx;
  10212. sd->auction.amount = amount;
  10213. clif_Auction_setitem(fd, idx + 2, false);
  10214. }
  10215. // 0 = You have failed to bid into the auction
  10216. // 1 = You have successfully bid in the auction
  10217. // 2 = The auction has been canceled
  10218. // 3 = An auction with at least one bidder cannot be canceled
  10219. // 4 = You cannot register more than 5 items in an auction at a time
  10220. // 5 = You do not have enough Zeny to pay the Auction Fee
  10221. // 6 = You have won the auction
  10222. // 7 = You have failed to win the auction
  10223. // 8 = You do not have enough Zeny
  10224. // 9 = You cannot place more than 5 bids at a time
  10225. void clif_Auction_message(int fd, unsigned char flag)
  10226. {
  10227. WFIFOHEAD(fd,3);
  10228. WFIFOW(fd,0) = 0x250;
  10229. WFIFOB(fd,2) = flag;
  10230. WFIFOSET(fd,3);
  10231. }
  10232. // 0 = You have ended the auction
  10233. // 1 = You cannot end the auction
  10234. // 2 = Bid number is incorrect
  10235. void clif_Auction_close(int fd, unsigned char flag)
  10236. {
  10237. WFIFOHEAD(fd,6);
  10238. WFIFOW(fd,0) = 0x25d;
  10239. WFIFOL(fd,2) = flag;
  10240. WFIFOSET(fd,6);
  10241. }
  10242. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  10243. {
  10244. struct auction_data auction;
  10245. struct item_data *item;
  10246. auction.price = RFIFOL(fd,2);
  10247. auction.buynow = RFIFOL(fd,6);
  10248. auction.hours = RFIFOW(fd,10);
  10249. // Invalid Situations...
  10250. if( sd->auction.amount < 1 )
  10251. {
  10252. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  10253. return;
  10254. }
  10255. if( auction.price >= auction.buynow )
  10256. {
  10257. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  10258. return;
  10259. }
  10260. if( auction.hours < 1 || auction.hours > 48 )
  10261. {
  10262. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  10263. return;
  10264. }
  10265. // Auction checks...
  10266. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) )
  10267. {
  10268. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  10269. return;
  10270. }
  10271. if( auction.buynow > battle_config.auction_maximumprice )
  10272. { // Zeny Limits
  10273. auction.buynow = battle_config.auction_maximumprice;
  10274. if( auction.price >= auction.buynow )
  10275. auction.price = auction.buynow - 1;
  10276. }
  10277. auction.auction_id = 0;
  10278. auction.seller_id = sd->status.char_id;
  10279. safestrncpy(auction.seller_name, sd->status.name, NAME_LENGTH);
  10280. auction.buyer_id = 0;
  10281. memset(&auction.buyer_name, '\0', NAME_LENGTH);
  10282. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  10283. {
  10284. clif_Auction_message(fd, 2); // The auction has been canceled
  10285. return;
  10286. }
  10287. if( (item = itemdb_search(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  10288. { // Just in case
  10289. clif_Auction_message(fd, 2); // The auction has been canceled
  10290. return;
  10291. }
  10292. safestrncpy(auction.item_name, item->jname, ITEM_NAME_LENGTH);
  10293. auction.type = item->type;
  10294. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  10295. auction.item.amount = 1;
  10296. auction.timestamp = 0;
  10297. if( !intif_Auction_register(&auction) )
  10298. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  10299. else
  10300. {
  10301. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1);
  10302. sd->auction.amount = 0;
  10303. pc_payzeny(sd, auction.hours * battle_config.auction_feeperhour);
  10304. }
  10305. }
  10306. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd)
  10307. {
  10308. unsigned int auction_id = RFIFOL(fd,2);
  10309. intif_Auction_cancel(sd->status.char_id, auction_id);
  10310. }
  10311. void clif_parse_Auction_close(int fd, struct map_session_data *sd)
  10312. {
  10313. unsigned int auction_id = RFIFOL(fd,2);
  10314. intif_Auction_close(sd->status.char_id, auction_id);
  10315. }
  10316. void clif_parse_Auction_bid(int fd, struct map_session_data *sd)
  10317. {
  10318. unsigned int auction_id = RFIFOL(fd,2);
  10319. int bid = RFIFOL(fd,6);
  10320. if( bid <= 0 )
  10321. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  10322. else if( bid > sd->status.zeny )
  10323. clif_Auction_message(fd, 8); // You do not have enough zeny
  10324. else
  10325. {
  10326. pc_payzeny(sd, bid);
  10327. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  10328. }
  10329. }
  10330. /*------------------------------------------
  10331. * Auction Search
  10332. * S 0251 <search type>.w <search price>.l <search text>.24B <page number>.w
  10333. * Search Type: 0 Armor 1 Weapon 2 Card 3 Misc 4 By Text 5 By Price 6 Sell 7 Buy
  10334. *------------------------------------------*/
  10335. void clif_parse_Auction_search(int fd, struct map_session_data* sd)
  10336. {
  10337. char search_text[NAME_LENGTH];
  10338. short type = RFIFOW(fd,2), page = RFIFOW(fd,32);
  10339. int price = RFIFOL(fd,4);
  10340. clif_parse_Auction_cancelreg(fd, sd);
  10341. safestrncpy(search_text, (char*)RFIFOP(fd,8), NAME_LENGTH);
  10342. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  10343. }
  10344. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  10345. {
  10346. short type = RFIFOW(fd,2) + 6;
  10347. clif_parse_Auction_cancelreg(fd, sd);
  10348. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  10349. }
  10350. #endif
  10351. /*==========================================
  10352. * CASH/POINT SHOP
  10353. *==========================================*/
  10354. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  10355. {
  10356. int fd,i;
  10357. nullpo_retv(sd);
  10358. nullpo_retv(nd);
  10359. fd = sd->fd;
  10360. sd->npc_shopid = nd->bl.id;
  10361. WFIFOHEAD(fd, 200 * 11 + 12);
  10362. WFIFOW(fd,0) = 0x287;
  10363. WFIFOW(fd,2) = 12 + nd->u.shop.count*11;
  10364. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  10365. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  10366. for( i = 0; i < nd->u.shop.count; i++ )
  10367. {
  10368. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  10369. WFIFOL(fd,12+i*11) = nd->u.shop.shop_item[i].value;
  10370. WFIFOL(fd,16+i*11) = nd->u.shop.shop_item[i].value; // Discount Price? Maybe a Discount item
  10371. WFIFOB(fd,20+i*11) = itemtype(id->type);
  10372. WFIFOW(fd,21+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  10373. }
  10374. WFIFOSET(fd,WFIFOW(fd,2));
  10375. }
  10376. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
  10377. {
  10378. int fail = 0, amount, points;
  10379. short nameid;
  10380. struct npc_data *nd;
  10381. nullpo_retv(sd);
  10382. nd = (struct npc_data *)map_id2bl(sd->npc_shopid);
  10383. nameid = RFIFOW(fd,2);
  10384. amount = RFIFOW(fd,4);
  10385. points = RFIFOL(fd,6); // Not Implemented. Should be 0
  10386. fail = npc_cashshop_buy(sd, nameid, amount, points);
  10387. WFIFOHEAD(fd,12);
  10388. WFIFOW(fd,0) = 0x289;
  10389. WFIFOL(fd,2) = sd->cashPoints;
  10390. WFIFOL(fd,6) = sd->kafraPoints;
  10391. WFIFOW(fd,10) = fail;
  10392. WFIFOSET(fd,12);
  10393. }
  10394. /*==========================================
  10395. * Adoption System
  10396. *==========================================*/
  10397. // 0 : You cannot adopt more that 1 son
  10398. // 1 : You should be at least lvl 70 to adopt
  10399. // 2 : You cannot adopt a married player
  10400. void clif_Adopt_reply(struct map_session_data *sd, int type)
  10401. {
  10402. int fd = sd->fd;
  10403. WFIFOHEAD(fd,6);
  10404. WFIFOW(fd,0) = 0x0216;
  10405. WFIFOL(fd,2) = type;
  10406. WFIFOSET(fd,6);
  10407. }
  10408. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  10409. {
  10410. int fd = sd->fd;
  10411. WFIFOSET(fd,34);
  10412. WFIFOW(fd,0) = 0x01f6;
  10413. WFIFOL(fd,2) = src->status.account_id;
  10414. WFIFOL(fd,6) = p_id;
  10415. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  10416. WFIFOSET(fd,34);
  10417. }
  10418. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  10419. {
  10420. struct map_session_data *tsd = map_id2sd(RFIFOL(fd,2)), *p_sd = map_charid2sd(sd->status.partner_id);
  10421. if( pc_can_Adopt(sd, tsd, p_sd) )
  10422. {
  10423. tsd->adopt_invite = sd->status.account_id;
  10424. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  10425. }
  10426. }
  10427. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd)
  10428. {
  10429. struct map_session_data *p1_sd = map_id2sd(RFIFOL(fd,2)), *p2_sd = map_id2sd(RFIFOL(fd,6));
  10430. int result = RFIFOL(fd,10), pid = sd->adopt_invite;
  10431. sd->adopt_invite = 0;
  10432. if( pid != p1_sd->status.account_id )
  10433. return; // Not the same sender
  10434. if( pc_can_Adopt(p1_sd, p2_sd, sd) )
  10435. {
  10436. // Lets do the adoption!!
  10437. }
  10438. }
  10439. /*==========================================
  10440. * Requesting equip of a player
  10441. *------------------------------------------*/
  10442. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  10443. {
  10444. int charid = RFIFOL(fd, 2);
  10445. struct map_session_data* tsd = map_id2sd(charid);
  10446. if (!tsd)
  10447. return;
  10448. if( tsd->status.show_equip )
  10449. clif_viewequip_ack(sd, tsd);
  10450. else
  10451. clif_viewequip_fail(sd);
  10452. }
  10453. /*==========================================
  10454. * Equip window (un)tick
  10455. * S 02d8 <zero?>.L <flag>.L
  10456. *------------------------------------------*/
  10457. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  10458. {
  10459. bool flag = (bool)RFIFOL(fd,6); // 0=off, 1=on
  10460. sd->status.show_equip = flag;
  10461. clif_equiptickack(sd, flag);
  10462. }
  10463. /*==========================================
  10464. * パケットデバッグ
  10465. *------------------------------------------*/
  10466. void clif_parse_debug(int fd,struct map_session_data *sd)
  10467. {
  10468. int i, cmd, len;
  10469. cmd = RFIFOW(fd,0);
  10470. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  10471. ShowDebug("packet debug 0x%4X\n",cmd);
  10472. ShowMessage("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10473. for(i=0;i<len;i++){
  10474. if((i&15)==0)
  10475. ShowMessage("\n%04X ",i);
  10476. ShowMessage("%02X ",RFIFOB(fd,i));
  10477. }
  10478. ShowMessage("\n");
  10479. }
  10480. /*==========================================
  10481. * Main client packet processing function
  10482. *------------------------------------------*/
  10483. int clif_parse(int fd)
  10484. {
  10485. int cmd, packet_ver, packet_len, err;
  10486. TBL_PC* sd;
  10487. int pnum;
  10488. //TODO apply deplays or disconnect based on packet throughput [FlavioJS]
  10489. // Note: "click masters" can do 80+ clicks in 10 seconds
  10490. for( pnum = 0; pnum < 3; ++pnum )// Limit max packets per cycle to 3 (delay packet spammers) [FlavioJS]
  10491. { // begin main client packet processing loop
  10492. sd = (TBL_PC *)session[fd]->session_data;
  10493. if (session[fd]->flag.eof) {
  10494. if (sd) {
  10495. if (sd->state.autotrade) {
  10496. //Disassociate character from the socket connection.
  10497. session[fd]->session_data = NULL;
  10498. sd->fd = 0;
  10499. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  10500. } else
  10501. if (sd->state.active) {
  10502. // Player logout display [Valaris]
  10503. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  10504. clif_quitsave(fd, sd);
  10505. } else {
  10506. //Unusual logout (during log on/off/map-changer procedure)
  10507. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  10508. map_quit(sd);
  10509. }
  10510. } else {
  10511. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  10512. }
  10513. do_close(fd);
  10514. return 0;
  10515. }
  10516. if (RFIFOREST(fd) < 2)
  10517. return 0;
  10518. cmd = RFIFOW(fd,0);
  10519. // identify client's packet version
  10520. if (sd) {
  10521. packet_ver = sd->packet_ver;
  10522. } else {
  10523. // check authentification packet to know packet version
  10524. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  10525. if( err )
  10526. {// failed to identify packet version
  10527. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  10528. err == 1 ? "" :
  10529. err == 2 ? ", possibly for having an invalid account_id" :
  10530. err == 3 ? ", possibly for having an invalid char_id." :
  10531. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  10532. err == 4 ? ", possibly for having an invalid login_id1." :
  10533. err == 5 ? ", possibly for having an invalid client_tick." :
  10534. */
  10535. err == 6 ? ", possibly for having an invalid sex." :
  10536. ". ERROR invalid error code"));
  10537. WFIFOHEAD(fd,packet_len(0x6a));
  10538. WFIFOW(fd,0) = 0x6a;
  10539. WFIFOB(fd,2) = 3; // Rejected from Server
  10540. WFIFOSET(fd,packet_len(0x6a));
  10541. RFIFOSKIP(fd, RFIFOREST(fd));
  10542. clif_setwaitclose(fd);
  10543. return 0;
  10544. }
  10545. }
  10546. // filter out invalid / unsupported packets
  10547. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  10548. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  10549. set_eof(fd);
  10550. return 0;
  10551. }
  10552. // determine real packet length
  10553. packet_len = packet_db[packet_ver][cmd].len;
  10554. if (packet_len == -1) { // variable-length packet
  10555. if (RFIFOREST(fd) < 4)
  10556. return 0;
  10557. packet_len = RFIFOW(fd,2);
  10558. if (packet_len < 4 || packet_len > 32768) {
  10559. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  10560. set_eof(fd);
  10561. return 0;
  10562. }
  10563. }
  10564. if ((int)RFIFOREST(fd) < packet_len)
  10565. return 0; // not enough data received to form the packet
  10566. if (packet_db[packet_ver][cmd].func) {
  10567. if (sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck)
  10568. ; //Only valid packet when player is not on a map is the finish-loading packet.
  10569. else
  10570. if ((sd && sd->state.active)
  10571. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  10572. || packet_db[packet_ver][cmd].func == clif_parse_debug
  10573. ) //Only execute the function when there's an active sd (except for debug/wanttoconnect packets)
  10574. packet_db[packet_ver][cmd].func(fd, sd);
  10575. }
  10576. #if DUMP_UNKNOWN_PACKET
  10577. else if (battle_config.error_log)
  10578. {
  10579. int i;
  10580. FILE *fp;
  10581. char packet_txt[256] = "save/packet.txt";
  10582. time_t now;
  10583. dump = 1;
  10584. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10585. ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
  10586. return 1;
  10587. } else {
  10588. time(&now);
  10589. if (sd && sd->state.active) {
  10590. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  10591. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10592. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10593. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10594. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10595. for(i = 0; i < packet_len; i++) {
  10596. if ((i & 15) == 0)
  10597. fprintf(fp, "\n\t%04X ", i);
  10598. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10599. }
  10600. fprintf(fp, "\n\n");
  10601. fclose(fp);
  10602. }
  10603. }
  10604. #endif
  10605. /* TODO: use utils.c :: dump()
  10606. if (dump) {
  10607. int i;
  10608. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10609. ShowMessage("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10610. for(i = 0; i < packet_len; i++) {
  10611. if ((i & 15) == 0)
  10612. ShowMessage("\n%04X ",i);
  10613. ShowMessage("%02X ", RFIFOB(fd,i));
  10614. }
  10615. ShowMessage("\n");
  10616. if (sd && sd->state.active) {
  10617. if (sd->status.name != NULL)
  10618. ShowMessage("\nAccount ID %d, character ID %d, player name %s.\n",
  10619. sd->status.account_id, sd->status.char_id, sd->status.name);
  10620. else
  10621. ShowMessage("\nAccount ID %d.\n", sd->bl.id);
  10622. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10623. ShowMessage("\nAccount ID %d.\n", sd->bl.id);
  10624. }*/
  10625. RFIFOSKIP(fd, packet_len);
  10626. }; // main loop end
  10627. return 0;
  10628. }
  10629. /*==========================================
  10630. * パケットデータベース読み込み
  10631. *------------------------------------------*/
  10632. static int packetdb_readdb(void)
  10633. {
  10634. FILE *fp;
  10635. char line[1024];
  10636. int ln=0;
  10637. int cmd,i,j,packet_ver;
  10638. int max_cmd=-1;
  10639. int skip_ver = 0;
  10640. int warned = 0;
  10641. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  10642. int packet_len_table[MAX_PACKET_DB] = {
  10643. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10647. //#0x0040
  10648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10650. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  10651. #if PACKETVER < 2
  10652. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  10653. #elif PACKETVER < 9 // 78-7b 亀島以降 lv99エフェクト用
  10654. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  10655. #else // change in 0x78 and 0x7c
  10656. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  10657. #endif
  10658. //#0x0080
  10659. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  10660. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  10661. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  10662. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  10663. //#0x00C0
  10664. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  10665. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  10666. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  10667. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  10668. //#0x0100
  10669. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  10670. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  10671. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  10672. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  10673. //#0x0140
  10674. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  10675. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  10676. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  10677. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  10678. //#0x0180
  10679. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  10680. #if PACKETVER < 1
  10681. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10682. #else // 196 comodo以降 状態表示アイコン用
  10683. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10684. #endif
  10685. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  10686. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  10687. //#0x01C0, Set 0x1d5=-1
  10688. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  10689. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  10690. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  10691. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  10692. //#0x0200
  10693. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  10694. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  10695. #if PACKETVER < 9
  10696. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  10697. #else // 0x22c changed
  10698. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  10699. #endif
  10700. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1, -1, 4, 2,
  10701. //#0x0240
  10702. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  10703. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4, -1, 4, 0,
  10704. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10705. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10706. //#0x0280
  10707. 0, 0, 0, 6, 0, 0, 0, 0, 0, 8, 18, 0, 0, 0, 0, 0,
  10708. 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10710. 0, 0, 0, 0, 0, 0, 0, 0, 0,191, 0, 0, 0, 0, 0, 0,
  10711. //#0x02C0
  10712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10713. 0, 0, 0, 0, 0, 0, 6, -1, 10, 10, 0, 0, 0, 0, 0, 0,
  10714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10716. };
  10717. struct {
  10718. void (*func)(int, struct map_session_data *);
  10719. char *name;
  10720. } clif_parse_func[]={
  10721. {clif_parse_WantToConnection,"wanttoconnection"},
  10722. {clif_parse_LoadEndAck,"loadendack"},
  10723. {clif_parse_TickSend,"ticksend"},
  10724. {clif_parse_WalkToXY,"walktoxy"},
  10725. {clif_parse_QuitGame,"quitgame"},
  10726. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  10727. {clif_parse_GlobalMessage,"globalmessage"},
  10728. {clif_parse_MapMove,"mapmove"},
  10729. {clif_parse_ChangeDir,"changedir"},
  10730. {clif_parse_Emotion,"emotion"},
  10731. {clif_parse_HowManyConnections,"howmanyconnections"},
  10732. {clif_parse_ActionRequest,"actionrequest"},
  10733. {clif_parse_Restart,"restart"},
  10734. {clif_parse_WisMessage,"wis"},
  10735. {clif_parse_GMmessage,"gmmessage"},
  10736. {clif_parse_TakeItem,"takeitem"},
  10737. {clif_parse_DropItem,"dropitem"},
  10738. {clif_parse_UseItem,"useitem"},
  10739. {clif_parse_EquipItem,"equipitem"},
  10740. {clif_parse_UnequipItem,"unequipitem"},
  10741. {clif_parse_NpcClicked,"npcclicked"},
  10742. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  10743. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  10744. {clif_parse_NpcSellListSend,"npcselllistsend"},
  10745. {clif_parse_CreateChatRoom,"createchatroom"},
  10746. {clif_parse_ChatAddMember,"chataddmember"},
  10747. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  10748. {clif_parse_ChangeChatOwner,"changechatowner"},
  10749. {clif_parse_KickFromChat,"kickfromchat"},
  10750. {clif_parse_ChatLeave,"chatleave"},
  10751. {clif_parse_TradeRequest,"traderequest"},
  10752. {clif_parse_TradeAck,"tradeack"},
  10753. {clif_parse_TradeAddItem,"tradeadditem"},
  10754. {clif_parse_TradeOk,"tradeok"},
  10755. {clif_parse_TradeCancel,"tradecancel"},
  10756. {clif_parse_TradeCommit,"tradecommit"},
  10757. {clif_parse_StopAttack,"stopattack"},
  10758. {clif_parse_PutItemToCart,"putitemtocart"},
  10759. {clif_parse_GetItemFromCart,"getitemfromcart"},
  10760. {clif_parse_RemoveOption,"removeoption"},
  10761. {clif_parse_ChangeCart,"changecart"},
  10762. {clif_parse_StatusUp,"statusup"},
  10763. {clif_parse_SkillUp,"skillup"},
  10764. {clif_parse_UseSkillToId,"useskilltoid"},
  10765. {clif_parse_UseSkillToPos,"useskilltopos"},
  10766. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  10767. {clif_parse_UseSkillMap,"useskillmap"},
  10768. {clif_parse_RequestMemo,"requestmemo"},
  10769. {clif_parse_ProduceMix,"producemix"},
  10770. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  10771. {clif_parse_NpcNextClicked,"npcnextclicked"},
  10772. {clif_parse_NpcAmountInput,"npcamountinput"},
  10773. {clif_parse_NpcStringInput,"npcstringinput"},
  10774. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  10775. {clif_parse_ItemIdentify,"itemidentify"},
  10776. {clif_parse_SelectArrow,"selectarrow"},
  10777. {clif_parse_AutoSpell,"autospell"},
  10778. {clif_parse_UseCard,"usecard"},
  10779. {clif_parse_InsertCard,"insertcard"},
  10780. {clif_parse_RepairItem,"repairitem"},
  10781. {clif_parse_WeaponRefine,"weaponrefine"},
  10782. {clif_parse_SolveCharName,"solvecharname"},
  10783. {clif_parse_ResetChar,"resetchar"},
  10784. {clif_parse_LGMmessage,"lgmmessage"},
  10785. {clif_parse_MoveToKafra,"movetokafra"},
  10786. {clif_parse_MoveFromKafra,"movefromkafra"},
  10787. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  10788. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  10789. {clif_parse_CloseKafra,"closekafra"},
  10790. {clif_parse_CreateParty,"createparty"},
  10791. {clif_parse_CreateParty2,"createparty2"},
  10792. {clif_parse_PartyInvite,"partyinvite"},
  10793. {clif_parse_PartyInvite2,"partyinvite2"},
  10794. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  10795. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  10796. {clif_parse_LeaveParty,"leaveparty"},
  10797. {clif_parse_RemovePartyMember,"removepartymember"},
  10798. {clif_parse_PartyChangeOption,"partychangeoption"},
  10799. {clif_parse_PartyMessage,"partymessage"},
  10800. {clif_parse_CloseVending,"closevending"},
  10801. {clif_parse_VendingListReq,"vendinglistreq"},
  10802. {clif_parse_PurchaseReq,"purchasereq"},
  10803. {clif_parse_OpenVending,"openvending"},
  10804. {clif_parse_CreateGuild,"createguild"},
  10805. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  10806. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  10807. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  10808. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  10809. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  10810. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  10811. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  10812. {clif_parse_GuildInvite,"guildinvite"},
  10813. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  10814. {clif_parse_GuildLeave,"guildleave"},
  10815. {clif_parse_GuildExpulsion,"guildexpulsion"},
  10816. {clif_parse_GuildMessage,"guildmessage"},
  10817. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  10818. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  10819. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  10820. {clif_parse_GuildOpposition,"guildopposition"},
  10821. {clif_parse_GuildBreak,"guildbreak"},
  10822. {clif_parse_PetMenu,"petmenu"},
  10823. {clif_parse_CatchPet,"catchpet"},
  10824. {clif_parse_SelectEgg,"selectegg"},
  10825. {clif_parse_SendEmotion,"sendemotion"},
  10826. {clif_parse_ChangePetName,"changepetname"},
  10827. {clif_parse_GMKick,"gmkick"},
  10828. {clif_parse_GMHide,"gmhide"},
  10829. {clif_parse_GMReqNoChat,"gmreqnochat"},
  10830. {clif_parse_GMReqAccountName,"gmreqaccname"},
  10831. {clif_parse_GMKickAll,"killall"},
  10832. {clif_parse_GMRecall,"recall"},
  10833. {clif_parse_GMRecall,"summon"},
  10834. {clif_parse_GM_Monster_Item,"itemmonster"},
  10835. {clif_parse_GMShift,"remove"},
  10836. {clif_parse_GMShift,"shift"},
  10837. {clif_parse_GMChangeMapType,"changemaptype"},
  10838. {clif_parse_GMRc,"rc"},
  10839. {clif_parse_NoviceDoriDori,"sndoridori"},
  10840. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  10841. {clif_parse_PMIgnore,"wisexin"},
  10842. {clif_parse_PMIgnoreList,"wisexlist"},
  10843. {clif_parse_PMIgnoreAll,"wisall"},
  10844. {clif_parse_FriendsListAdd,"friendslistadd"},
  10845. {clif_parse_FriendsListRemove,"friendslistremove"},
  10846. {clif_parse_FriendsListReply,"friendslistreply"},
  10847. {clif_parse_Blacksmith,"blacksmith"},
  10848. {clif_parse_Alchemist,"alchemist"},
  10849. {clif_parse_Taekwon,"taekwon"},
  10850. {clif_parse_RankingPk,"rankingpk"},
  10851. {clif_parse_FeelSaveOk,"feelsaveok"},
  10852. {clif_parse_debug,"debug"},
  10853. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  10854. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  10855. {clif_parse_HomMoveTo,"hommoveto"},
  10856. {clif_parse_HomAttack,"homattack"},
  10857. {clif_parse_HomMenu,"hommenu"},
  10858. {clif_parse_StoragePassword,"storagepassword"},
  10859. {clif_parse_Hotkey,"hotkey"},
  10860. {clif_parse_AutoRevive,"autorevive"},
  10861. {clif_parse_Check,"check"},
  10862. {clif_parse_Adopt_request,"adoptrequest"},
  10863. {clif_parse_Adopt_reply,"adoptreply"},
  10864. #ifndef TXT_ONLY
  10865. // MAIL SYSTEM
  10866. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  10867. {clif_parse_Mail_read,"mailread"},
  10868. {clif_parse_Mail_getattach,"mailgetattach"},
  10869. {clif_parse_Mail_delete,"maildelete"},
  10870. {clif_parse_Mail_return,"mailreturn"},
  10871. {clif_parse_Mail_setattach,"mailsetattach"},
  10872. {clif_parse_Mail_winopen,"mailwinopen"},
  10873. {clif_parse_Mail_send,"mailsend"},
  10874. // AUCTION SYSTEM
  10875. {clif_parse_Auction_search,"auctionsearch"},
  10876. {clif_parse_Auction_buysell,"auctionbuysell"},
  10877. {clif_parse_Auction_setitem,"auctionsetitem"},
  10878. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  10879. {clif_parse_Auction_register,"auctionregister"},
  10880. {clif_parse_Auction_cancel,"auctioncancel"},
  10881. {clif_parse_Auction_close,"auctionclose"},
  10882. {clif_parse_Auction_bid,"auctionbid"},
  10883. #endif
  10884. {clif_parse_cashshop_buy,"cashshopbuy"},
  10885. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  10886. {clif_parse_EquipTick,"equiptickbox"},
  10887. {NULL,NULL}
  10888. };
  10889. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  10890. memset(packet_db,0,sizeof(packet_db));
  10891. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  10892. packet_len(i) = packet_len_table[i];
  10893. sprintf(line, "%s/packet_db.txt", db_path);
  10894. if( (fp=fopen(line,"r"))==NULL ){
  10895. ShowFatalError("can't read %s\n", line);
  10896. exit(EXIT_FAILURE);
  10897. }
  10898. clif_config.packet_db_ver = MAX_PACKET_VER;
  10899. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  10900. while( fgets(line, sizeof(line), fp) )
  10901. {
  10902. ln++;
  10903. if(line[0]=='/' && line[1]=='/')
  10904. continue;
  10905. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  10906. {
  10907. if(strcmpi(w1,"packet_ver")==0) {
  10908. int prev_ver = packet_ver;
  10909. skip_ver = 0;
  10910. packet_ver = atoi(w2);
  10911. if ( packet_ver > MAX_PACKET_VER )
  10912. { //Check to avoid overflowing. [Skotlex]
  10913. if( (warned&1) == 0 )
  10914. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  10915. warned &= 1;
  10916. skip_ver = 1;
  10917. }
  10918. else if( packet_ver < 0 )
  10919. {
  10920. if( (warned&2) == 0 )
  10921. ShowWarning("Negative packet versions are not supported.\n");
  10922. warned &= 2;
  10923. skip_ver = 1;
  10924. }
  10925. else if( packet_ver == SERVER )
  10926. {
  10927. if( (warned&4) == 0 )
  10928. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  10929. warned &= 4;
  10930. skip_ver = 1;
  10931. }
  10932. if( skip_ver )
  10933. {
  10934. ShowWarning("Skipping packet version %d.\n", packet_ver);
  10935. packet_ver = prev_ver;
  10936. continue;
  10937. }
  10938. // copy from previous version into new version and continue
  10939. // - indicating all following packets should be read into the newer version
  10940. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  10941. continue;
  10942. } else if(strcmpi(w1,"packet_db_ver")==0) {
  10943. if(strcmpi(w2,"default")==0) //This is the preferred version.
  10944. clif_config.packet_db_ver = MAX_PACKET_VER;
  10945. else // to manually set the packet DB version
  10946. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  10947. continue;
  10948. }
  10949. }
  10950. if( skip_ver != 0 )
  10951. continue; // Skipping current packet version
  10952. memset(str,0,sizeof(str));
  10953. for(j=0,p=line;j<4 && p; ++j)
  10954. {
  10955. str[j]=p;
  10956. p=strchr(p,',');
  10957. if(p) *p++=0;
  10958. }
  10959. if(str[0]==NULL)
  10960. continue;
  10961. cmd=strtol(str[0],(char **)NULL,0);
  10962. if(max_cmd < cmd)
  10963. max_cmd = cmd;
  10964. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  10965. continue;
  10966. if(str[1]==NULL){
  10967. ShowError("packet_db: packet len error\n");
  10968. continue;
  10969. }
  10970. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  10971. if(str[2]==NULL){
  10972. packet_db[packet_ver][cmd].func = NULL;
  10973. ln++;
  10974. continue;
  10975. }
  10976. // look up processing function by name
  10977. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  10978. if( j < ARRAYLENGTH(clif_parse_func) )
  10979. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  10980. // set the identifying cmd for the packet_db version
  10981. if (strcmp(str[2],"wanttoconnection")==0)
  10982. clif_config.connect_cmd[packet_ver] = cmd;
  10983. if(str[3]==NULL){
  10984. ShowError("packet_db: packet error\n");
  10985. exit(EXIT_FAILURE);
  10986. }
  10987. for(j=0,p2=str[3];p2;j++){
  10988. short k;
  10989. str2[j]=p2;
  10990. p2=strchr(p2,':');
  10991. if(p2) *p2++=0;
  10992. k = atoi(str2[j]);
  10993. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  10994. packet_db[packet_ver][cmd].pos[j] = k;
  10995. }
  10996. }
  10997. fclose(fp);
  10998. if(max_cmd > MAX_PACKET_DB)
  10999. {
  11000. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  11001. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  11002. }
  11003. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  11004. { //Locate the nearest version that we still support. [Skotlex]
  11005. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  11006. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  11007. }
  11008. 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);
  11009. return 0;
  11010. }
  11011. /*==========================================
  11012. *
  11013. *------------------------------------------*/
  11014. int do_init_clif(void)
  11015. {
  11016. clif_config.packet_db_ver = -1; // the main packet version of the DB
  11017. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  11018. memset(packet_db,0,sizeof(packet_db));
  11019. //Using the packet_db file is the only way to set up packets now [Skotlex]
  11020. packetdb_readdb();
  11021. set_defaultparse(clif_parse);
  11022. if( make_listen_bind(bind_ip,map_port) == -1 )
  11023. {
  11024. ShowFatalError("can't bind game port\n");
  11025. exit(EXIT_FAILURE);
  11026. }
  11027. add_timer_func_list(clif_waitclose, "clif_waitclose");
  11028. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  11029. add_timer_func_list(clif_delayquit, "clif_delayquit");
  11030. return 0;
  11031. }