clif.c 315 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878
  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 <stdio.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <stdarg.h>
  41. #include <time.h>
  42. #define DUMP_UNKNOWN_PACKET 0
  43. struct Clif_Config {
  44. int packet_db_ver; //Preferred packet version.
  45. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  46. } clif_config;
  47. struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
  48. //Converts item type in case of pet eggs.
  49. #define itemtype(a) (a == IT_PETEGG)?IT_WEAPON:a
  50. #define WBUFPOS(p,pos,x,y,dir) \
  51. do { \
  52. uint8 *__p = (p); \
  53. __p+=(pos); \
  54. __p[0] = (uint8)((x)>>2); \
  55. __p[1] = (uint8)(((x)<<6) | (((y)>>4)&0x3f)); \
  56. __p[2] = (uint8)(((y)<<4) | ((dir)&0xf)); \
  57. } while(0)
  58. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  59. #define WBUFPOS2(p,pos,x0,y0,x1,y1,sx0,sy0) \
  60. do { \
  61. uint8 *__p = (p); \
  62. __p+=(pos); \
  63. __p[0]=(uint8)((x0)>>2); \
  64. __p[1]=(uint8)(((x0)<<6) | (((y0)>>4)&0x3f)); \
  65. __p[2]=(uint8)(((y0)<<4) | (((x1)>>6)&0x0f)); \
  66. __p[3]=(uint8)(((x1)<<2) | (((y1)>>8)&0x03)); \
  67. __p[4]=(uint8)(y1); \
  68. __p[5]=(uint8)(((sx0)<<4) | ((sy0)&0x0f)); \
  69. } while(0)
  70. #define WFIFOPOS(fd,pos,x,y,dir) WBUFPOS(WFIFOP(fd,pos),0,x,y,dir)
  71. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1,sx0,sy0) WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1,sx0,sy0)
  72. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  73. #define clif_setlevel(lv) (lv<battle_config.max_lv?lv:battle_config.max_lv-(lv<battle_config.aura_lv?1:0));
  74. //To idenfity disguised characters.
  75. #define disguised(bl) ((bl)->type==BL_PC && ((TBL_PC*)bl)->disguise)
  76. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex\]
  77. #define mes_len_check(mes, len, max) if (len > max) { mes[max-1] = '\0'; len = max; } else mes[len-1] = '\0';
  78. static char map_ip_str[128];
  79. static uint32 map_ip;
  80. static uint32 bind_ip = INADDR_ANY;
  81. static uint16 map_port = 5121;
  82. int map_fd;
  83. //These two will be used to verify the incoming player's validity.
  84. //It helps identify their client packet version correctly. [Skotlex]
  85. static int max_account_id = DEFAULT_MAX_ACCOUNT_ID;
  86. static int max_char_id = DEFAULT_MAX_CHAR_ID;
  87. int clif_parse (int fd);
  88. /*==========================================
  89. * map鯖のip設定
  90. *------------------------------------------*/
  91. int clif_setip(const char* ip)
  92. {
  93. char ip_str[16];
  94. map_ip = host2ip(ip);
  95. if (!map_ip) {
  96. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  97. return 0;
  98. }
  99. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  100. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  101. return 1;
  102. }
  103. void clif_setbindip(const char* ip)
  104. {
  105. char ip_str[16];
  106. bind_ip = host2ip(ip);
  107. if (bind_ip) {
  108. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  109. } else {
  110. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  111. }
  112. }
  113. /*==========================================
  114. * map鯖のport設定
  115. *------------------------------------------*/
  116. void clif_setport(uint16 port)
  117. {
  118. map_port = port;
  119. }
  120. /*==========================================
  121. * map鯖のip読み出し
  122. *------------------------------------------*/
  123. uint32 clif_getip(void)
  124. {
  125. return map_ip;
  126. }
  127. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  128. uint32 clif_refresh_ip(void)
  129. {
  130. uint32 new_ip;
  131. new_ip = host2ip(map_ip_str);
  132. if (new_ip && new_ip != map_ip) {
  133. map_ip = new_ip;
  134. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  135. return map_ip;
  136. }
  137. return 0;
  138. }
  139. /*==========================================
  140. * map鯖のport読み出し
  141. *------------------------------------------*/
  142. uint16 clif_getport(void)
  143. {
  144. return map_port;
  145. }
  146. /*==========================================
  147. * Counts connected players.
  148. *------------------------------------------*/
  149. int clif_countusers(void)
  150. {
  151. int users = 0, i;
  152. struct map_session_data *sd;
  153. for(i = 0; i < fd_max; i++) {
  154. if (session[i] && session[i]->func_parse == clif_parse &&
  155. (sd = (struct map_session_data*)session[i]->session_data) &&
  156. sd->state.auth && !(battle_config.hide_GM_session && pc_isGM(sd)))
  157. users++;
  158. }
  159. return users;
  160. }
  161. /*==========================================
  162. * 全てのclientに対してfunc()実行
  163. *------------------------------------------*/
  164. int clif_foreachclient(int (*func)(struct map_session_data*, va_list),...) //recoded by sasuke, bug when player count gets higher [Kevin]
  165. {
  166. int i;
  167. va_list ap;
  168. struct map_session_data *sd;
  169. va_start(ap,func);
  170. for(i = 0; i < fd_max; i++) {
  171. if ( session[i] && session[i]->func_parse == clif_parse) {
  172. sd = (struct map_session_data*)session[i]->session_data;
  173. if ( sd && sd->state.auth && !sd->state.waitingdisconnect )
  174. func(sd, ap);
  175. }
  176. }
  177. va_end(ap);
  178. return 0;
  179. }
  180. /*==========================================
  181. * clif_sendでAREA*指定時用
  182. *------------------------------------------*/
  183. int clif_send_sub(struct block_list *bl, va_list ap)
  184. {
  185. struct block_list *src_bl;
  186. struct map_session_data *sd;
  187. unsigned char *buf;
  188. int len, type, fd;
  189. nullpo_retr(0, bl);
  190. nullpo_retr(0, ap);
  191. nullpo_retr(0, sd = (struct map_session_data *)bl);
  192. fd = sd->fd;
  193. if (!fd) //Don't send to disconnected clients.
  194. return 0;
  195. buf = va_arg(ap,unsigned char*);
  196. len = va_arg(ap,int);
  197. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  198. type = va_arg(ap,int);
  199. switch(type)
  200. {
  201. case AREA_WOS:
  202. if (bl == src_bl)
  203. return 0;
  204. break;
  205. case AREA_WOC:
  206. if (sd->chatID || bl == src_bl)
  207. return 0;
  208. break;
  209. case AREA_WOSC:
  210. {
  211. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  212. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  213. return 0;
  214. }
  215. break;
  216. }
  217. if (session[fd] != NULL) {
  218. WFIFOHEAD(fd, len);
  219. if (WFIFOP(fd,0) == buf) {
  220. printf("WARNING: Invalid use of clif_send function\n");
  221. printf(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  222. printf(" Please correct your code.\n");
  223. // don't send to not move the pointer of the packet for next sessions in the loop
  224. WFIFOSET(fd,0);//## TODO is this ok?
  225. } else {
  226. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  227. memcpy(WFIFOP(fd,0), buf, len);
  228. WFIFOSET(fd,len);
  229. }
  230. }
  231. }
  232. return 0;
  233. }
  234. /*==========================================
  235. *
  236. *------------------------------------------*/
  237. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  238. {
  239. int i;
  240. struct map_session_data *sd;
  241. struct party_data *p = NULL;
  242. struct guild *g = NULL;
  243. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  244. if( type != ALL_CLIENT && type != CHAT_MAINCHAT )
  245. nullpo_retr(0, bl);
  246. BL_CAST(BL_PC, bl, sd);
  247. switch(type) {
  248. case ALL_CLIENT: //All player clients.
  249. for (i = 0; i < fd_max; i++) {
  250. if (session[i] && session[i]->func_parse == clif_parse &&
  251. (sd = (struct map_session_data *)session[i]->session_data) != NULL&&
  252. sd->state.auth) {
  253. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  254. WFIFOHEAD(i, len);
  255. memcpy(WFIFOP(i,0), buf, len);
  256. WFIFOSET(i,len);
  257. }
  258. }
  259. }
  260. break;
  261. case ALL_SAMEMAP: //All players on the same map
  262. for(i = 0; i < fd_max; i++) {
  263. if (session[i] && session[i]->func_parse == clif_parse &&
  264. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  265. sd->state.auth && sd->bl.m == bl->m) {
  266. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  267. WFIFOHEAD(i,len);
  268. memcpy(WFIFOP(i,0), buf, len);
  269. WFIFOSET(i,len);
  270. }
  271. }
  272. }
  273. break;
  274. case AREA:
  275. case AREA_WOSC:
  276. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  277. clif_send (buf, len, bl, SELF);
  278. case AREA_WOC:
  279. case AREA_WOS:
  280. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  281. BL_PC, buf, len, bl, type);
  282. break;
  283. case AREA_CHAT_WOC:
  284. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  285. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  286. break;
  287. case CHAT:
  288. case CHAT_WOS:
  289. {
  290. struct chat_data *cd;
  291. if (sd) {
  292. cd = (struct chat_data*)map_id2bl(sd->chatID);
  293. } else if (bl->type == BL_CHAT) {
  294. cd = (struct chat_data*)bl;
  295. } else break;
  296. if (cd == NULL)
  297. break;
  298. for(i = 0; i < cd->users; i++) {
  299. if (type == CHAT_WOS && cd->usersd[i] == sd)
  300. continue;
  301. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  302. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  303. {
  304. WFIFOHEAD(fd,len);
  305. memcpy(WFIFOP(fd,0), buf, len);
  306. WFIFOSET(fd,len);
  307. }
  308. }
  309. }
  310. }
  311. break;
  312. case CHAT_MAINCHAT: //[LuzZza]
  313. for(i=1; i<fd_max; i++) {
  314. if (session[i] && session[i]->func_parse == clif_parse &&
  315. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  316. sd->state.mainchat && !sd->chatID && (fd=sd->fd))
  317. {
  318. WFIFOHEAD(fd,len);
  319. memcpy(WFIFOP(fd,0), buf, len);
  320. WFIFOSET(fd, len);
  321. }
  322. }
  323. break;
  324. case PARTY_AREA:
  325. case PARTY_AREA_WOS:
  326. x0 = bl->x - AREA_SIZE;
  327. y0 = bl->y - AREA_SIZE;
  328. x1 = bl->x + AREA_SIZE;
  329. y1 = bl->y + AREA_SIZE;
  330. case PARTY:
  331. case PARTY_WOS:
  332. case PARTY_SAMEMAP:
  333. case PARTY_SAMEMAP_WOS:
  334. if (sd && sd->status.party_id)
  335. p = party_search(sd->status.party_id);
  336. if (p) {
  337. for(i=0;i<MAX_PARTY;i++){
  338. if ((sd = p->data[i].sd) == NULL)
  339. continue;
  340. if (!(fd=sd->fd) || session[fd] == NULL || sd->state.auth == 0
  341. || session[fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  342. continue;
  343. if (sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS))
  344. continue;
  345. if (type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m)
  346. continue;
  347. if ((type == PARTY_AREA || type == PARTY_AREA_WOS) &&
  348. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  349. continue;
  350. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  351. WFIFOHEAD(fd,len);
  352. memcpy(WFIFOP(fd,0), buf, len);
  353. WFIFOSET(fd,len);
  354. }
  355. }
  356. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  357. break;
  358. for (i = 1; i < fd_max; i++){ // partyspy [Syrus22]
  359. if (session[i] && session[i]->func_parse == clif_parse &&
  360. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  361. sd->state.auth && (fd=sd->fd) && sd->partyspy == p->party.party_id)
  362. {
  363. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  364. WFIFOHEAD(fd,len);
  365. memcpy(WFIFOP(fd,0), buf, len);
  366. WFIFOSET(fd,len);
  367. }
  368. }
  369. }
  370. }
  371. break;
  372. case DUEL:
  373. case DUEL_WOS:
  374. if (!sd || !sd->duel_group) break; //Invalid usage.
  375. x0 = sd->duel_group; //Here we use x0 to store the duel group. [Skotlex]
  376. for (i = 0; i < fd_max; i++) {
  377. if (session[i] && session[i]->func_parse == clif_parse &&
  378. (sd = (struct map_session_data *)session[i]->session_data) != NULL &&
  379. sd->state.auth && sd->duel_group == x0) {
  380. if (type == DUEL_WOS && bl->id == sd->bl.id)
  381. continue;
  382. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) {
  383. WFIFOHEAD(i, len);
  384. memcpy(WFIFOP(i,0), buf, len);
  385. WFIFOSET(i,len);
  386. }
  387. }
  388. }
  389. break;
  390. case SELF:
  391. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  392. WFIFOHEAD(fd,len);
  393. memcpy(WFIFOP(fd,0), buf, len);
  394. WFIFOSET(fd,len);
  395. }
  396. break;
  397. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  398. case GUILD_AREA:
  399. case GUILD_AREA_WOS:
  400. x0 = bl->x - AREA_SIZE;
  401. y0 = bl->y - AREA_SIZE;
  402. x1 = bl->x + AREA_SIZE;
  403. y1 = bl->y + AREA_SIZE;
  404. case GUILD_SAMEMAP:
  405. case GUILD_SAMEMAP_WOS:
  406. case GUILD:
  407. case GUILD_WOS:
  408. if (sd && sd->status.guild_id)
  409. g = guild_search(sd->status.guild_id);
  410. if (g) {
  411. for(i = 0; i < g->max_member; i++) {
  412. if ((sd = g->member[i].sd) != NULL) {
  413. if (!(fd=sd->fd) || session[fd] == NULL || sd->state.auth == 0
  414. || session[fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  415. continue;
  416. if (sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS))
  417. continue;
  418. if (type != GUILD && type != GUILD_WOS && sd->bl.m != bl->m)
  419. continue;
  420. if ((type == GUILD_AREA || type == GUILD_AREA_WOS) &&
  421. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  422. continue;
  423. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  424. WFIFOHEAD(fd,len);
  425. memcpy(WFIFOP(fd,0), buf, len);
  426. WFIFOSET(fd,len);
  427. }
  428. }
  429. }
  430. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  431. break;
  432. for (i = 1; i < fd_max; i++){ // guildspy [Syrus22]
  433. if (session[i] && session[i]->func_parse == clif_parse &&
  434. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  435. sd->state.auth && (fd=sd->fd) && sd->guildspy == g->guild_id) {
  436. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  437. WFIFOHEAD(fd,len);
  438. memcpy(WFIFOP(fd,0), buf, len);
  439. WFIFOSET(fd,len);
  440. }
  441. }
  442. }
  443. }
  444. break;
  445. default:
  446. if (battle_config.error_log)
  447. ShowError("clif_send: Unrecognized type %d\n",type);
  448. return -1;
  449. }
  450. return 0;
  451. }
  452. //
  453. // パケット作って送信
  454. //
  455. /*==========================================
  456. *
  457. *------------------------------------------*/
  458. int clif_authok(struct map_session_data *sd)
  459. {
  460. int fd;
  461. if (!sd->fd)
  462. return 0;
  463. fd = sd->fd;
  464. WFIFOHEAD(fd, packet_len(0x73));
  465. WFIFOW(fd, 0) = 0x73;
  466. WFIFOL(fd, 2) = gettick();
  467. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  468. WFIFOB(fd, 9) = 5; // ignored
  469. WFIFOB(fd,10) = 5; // ignored
  470. WFIFOSET(fd,packet_len(0x73));
  471. return 0;
  472. }
  473. /*==========================================
  474. * Authentication failed/disconnect client.
  475. *------------------------------------------
  476. * The client closes it's socket and displays a message according to type:
  477. * 1 - server closed -> MsgStringTable[4]
  478. * 2 - ID already logged in -> MsgStringTable[5]
  479. * 3 - timeout/too much lag -> MsgStringTable[241]
  480. * 4 - server full -> MsgStringTable[264]
  481. * 5 - underaged -> MsgStringTable[305]
  482. * 9 - too many connections from this ip -> MsgStringTable[529]
  483. * 10 - out of available time paid for -> MsgStringTable[530]
  484. * 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  485. * other - disconnected -> MsgStringTable[3]
  486. */
  487. int clif_authfail_fd(int fd, int type)
  488. {
  489. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  490. return 0;
  491. WFIFOHEAD(fd, packet_len(0x81));
  492. WFIFOW(fd,0) = 0x81;
  493. WFIFOB(fd,2) = type;
  494. WFIFOSET(fd,packet_len(0x81));
  495. clif_setwaitclose(fd);
  496. return 0;
  497. }
  498. /*==========================================
  499. * Used to know which is the max valid account/char id [Skotlex]
  500. *------------------------------------------*/
  501. void clif_updatemaxid(int account_id, int char_id)
  502. {
  503. max_account_id = account_id;
  504. max_char_id = char_id;
  505. }
  506. /*==========================================
  507. *
  508. *------------------------------------------*/
  509. int clif_charselectok(int id)
  510. {
  511. struct map_session_data* sd;
  512. int fd;
  513. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  514. return 1;
  515. fd = sd->fd;
  516. WFIFOHEAD(fd,packet_len(0xb3));
  517. WFIFOW(fd,0) = 0xb3;
  518. WFIFOB(fd,2) = 1;
  519. WFIFOSET(fd,packet_len(0xb3));
  520. return 0;
  521. }
  522. /*==========================================
  523. * Makes an item appear on the ground
  524. * 009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  525. *------------------------------------------*/
  526. int clif_dropflooritem(struct flooritem_data* fitem)
  527. {
  528. uint8 buf[17];
  529. int view;
  530. nullpo_retr(0, fitem);
  531. if (fitem->item_data.nameid <= 0)
  532. return 0;
  533. WBUFW(buf, 0) = 0x9e;
  534. WBUFL(buf, 2) = fitem->bl.id;
  535. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  536. WBUFB(buf, 8) = fitem->item_data.identify;
  537. WBUFW(buf, 9) = fitem->bl.x;
  538. WBUFW(buf,11) = fitem->bl.y;
  539. WBUFB(buf,13) = fitem->subx;
  540. WBUFB(buf,14) = fitem->suby;
  541. WBUFW(buf,15) = fitem->item_data.amount;
  542. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  543. return 0;
  544. }
  545. /*==========================================
  546. *
  547. *------------------------------------------*/
  548. int clif_clearflooritem(struct flooritem_data *fitem, int fd)
  549. {
  550. unsigned char buf[16];
  551. nullpo_retr(0, fitem);
  552. WBUFW(buf,0) = 0xa1;
  553. WBUFL(buf,2) = fitem->bl.id;
  554. if (fd == 0) {
  555. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  556. } else {
  557. WFIFOHEAD(fd,packet_len(0xa1));
  558. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  559. WFIFOSET(fd,packet_len(0xa1));
  560. }
  561. return 0;
  562. }
  563. /*==========================================
  564. * make a unit (char, npc, mob, homun) disappear to one client
  565. * id : the id of the unit
  566. * type: 0 - moved out of sight
  567. * 1 - died
  568. * 2 - logged out
  569. * 3 - teleported / winged away
  570. * fd : the target client
  571. *------------------------------------------*/
  572. int clif_clearunit_single(int id, uint8 type, int fd)
  573. {
  574. WFIFOHEAD(fd, packet_len(0x80));
  575. WFIFOW(fd,0) = 0x80;
  576. WFIFOL(fd,2) = id;
  577. WFIFOB(fd,6) = type;
  578. WFIFOSET(fd, packet_len(0x80));
  579. return 0;
  580. }
  581. /*==========================================
  582. * make a unit (char, npc, mob, homun) disappear to all clients in area
  583. * type: 0 - moved out of sight
  584. * 1 - died
  585. * 2 - logged out
  586. * 3 - teleported / winged away
  587. *------------------------------------------*/
  588. int clif_clearunit_area(struct block_list* bl, uint8 type)
  589. {
  590. unsigned char buf[16];
  591. nullpo_retr(0, bl);
  592. WBUFW(buf,0) = 0x80;
  593. WBUFL(buf,2) = bl->id;
  594. WBUFB(buf,6) = type;
  595. clif_send(buf, packet_len(0x80), bl, type == 1 ? AREA : AREA_WOS);
  596. if(disguised(bl)) {
  597. WBUFL(buf,2) = -bl->id;
  598. clif_send(buf, packet_len(0x80), bl, SELF);
  599. }
  600. return 0;
  601. }
  602. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, int data)
  603. {
  604. struct block_list *bl = (struct block_list *)id;
  605. clif_clearunit_area(bl, 0);
  606. aFree(bl);
  607. return 0;
  608. }
  609. int clif_clearunit_delayed(struct block_list* bl, unsigned int tick)
  610. {
  611. struct block_list *tbl;
  612. tbl = aMalloc(sizeof (struct block_list));
  613. memcpy (tbl, bl, sizeof (struct block_list));
  614. add_timer(tick, clif_clearunit_delayed_sub, (int)tbl, 0);
  615. return 0;
  616. }
  617. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  618. {
  619. #if PACKETVER > 3
  620. struct item_data *id;
  621. #endif
  622. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  623. {
  624. *rhand = *lhand = 0;
  625. return;
  626. }
  627. #if PACKETVER < 4
  628. *rhand = sd->status.weapon;
  629. *lhand = sd->status.shield;
  630. #else
  631. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  632. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  633. {
  634. id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  635. if (id->view_id > 0)
  636. *rhand = id->view_id;
  637. else
  638. *rhand = id->nameid;
  639. } else
  640. *rhand = 0;
  641. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  642. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  643. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  644. {
  645. id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  646. if (id->view_id > 0)
  647. *lhand = id->view_id;
  648. else
  649. *lhand = id->nameid;
  650. } else
  651. *lhand = 0;
  652. #endif
  653. }
  654. /*==========================================
  655. *
  656. *------------------------------------------*/
  657. static int clif_set0078(struct block_list* bl, unsigned char* buf)
  658. {
  659. struct status_change* sc;
  660. struct view_data* vd;
  661. int guild_id, emblem_id, dir, lv;
  662. nullpo_retr(0, bl);
  663. sc = status_get_sc(bl);
  664. vd = status_get_viewdata(bl);
  665. guild_id = status_get_guild_id(bl);
  666. emblem_id = status_get_emblem_id(bl);
  667. dir = unit_getdir(bl);
  668. lv = status_get_lv(bl);
  669. if(pcdb_checkid(vd->class_))
  670. {
  671. struct map_session_data* sd;
  672. BL_CAST(BL_PC, bl, sd);
  673. #if PACKETVER >= 7
  674. memset(buf,0,packet_len(0x22a));
  675. WBUFW(buf,0)=0x22a;
  676. WBUFL(buf,2)=bl->id;
  677. WBUFW(buf,6)=status_get_speed(bl);
  678. if (sc) {
  679. WBUFW(buf,8)=sc->opt1;
  680. WBUFW(buf,10)=sc->opt2;
  681. WBUFL(buf,12)=sc->option;
  682. WBUFL(buf,44)=sc->opt3;
  683. }
  684. WBUFW(buf,16)=vd->class_;
  685. WBUFW(buf,18)=vd->hair_style;
  686. WBUFW(buf,20)=vd->weapon;
  687. WBUFW(buf,22)=vd->shield;
  688. WBUFW(buf,24)=vd->head_bottom;
  689. WBUFW(buf,26)=vd->head_top;
  690. WBUFW(buf,28)=vd->head_mid;
  691. WBUFW(buf,30)=vd->hair_color;
  692. WBUFW(buf,32)=vd->cloth_color;
  693. WBUFW(buf,34)=sd?sd->head_dir:0;
  694. WBUFL(buf,36)=guild_id;
  695. WBUFW(buf,40)=emblem_id;
  696. if (sd) {
  697. WBUFW(buf,42)=sd->status.manner;
  698. WBUFB(buf,48)=sd->status.karma;
  699. }
  700. WBUFB(buf,49)=vd->sex;
  701. WBUFPOS(buf,50,bl->x,bl->y,dir);
  702. WBUFB(buf,53)=5;
  703. WBUFB(buf,54)=5;
  704. WBUFB(buf,55)=vd->dead_sit;
  705. WBUFW(buf,56)=clif_setlevel(lv);
  706. return packet_len(0x22a);
  707. #elif PACKETVER > 3
  708. memset(buf,0,packet_len(0x1d8));
  709. WBUFW(buf,0)=0x1d8;
  710. WBUFL(buf,2)=bl->id;
  711. WBUFW(buf,6)=status_get_speed(bl);
  712. if (sc) {
  713. WBUFW(buf,8)=sc->opt1;
  714. WBUFW(buf,10)=sc->opt2;
  715. WBUFW(buf,12)=sc->option;
  716. WBUFW(buf,42)=sc->opt3;
  717. }
  718. WBUFW(buf,14)=vd->class_;
  719. WBUFW(buf,16)=vd->hair_style;
  720. WBUFW(buf,18)=vd->weapon;
  721. WBUFW(buf,20)=vd->shield;
  722. WBUFW(buf,22)=vd->head_bottom;
  723. WBUFW(buf,24)=vd->head_top;
  724. WBUFW(buf,26)=vd->head_mid;
  725. WBUFW(buf,28)=vd->hair_color;
  726. WBUFW(buf,30)=vd->cloth_color;
  727. WBUFW(buf,32)=sd?sd->head_dir:0;
  728. WBUFL(buf,34)=guild_id;
  729. WBUFW(buf,38)=emblem_id;
  730. if (sd) {
  731. WBUFW(buf,40)=sd->status.manner;
  732. WBUFB(buf,44)=sd->status.karma;
  733. }
  734. WBUFB(buf,45)=vd->sex;
  735. WBUFPOS(buf,46,bl->x,bl->y,dir);
  736. WBUFB(buf,49)=5;
  737. WBUFB(buf,50)=5;
  738. WBUFB(buf,51)=vd->dead_sit;
  739. WBUFW(buf,52)=clif_setlevel(lv);
  740. return packet_len(0x1d8);
  741. #else
  742. memset(buf,0,packet_len(0x78));
  743. WBUFW(buf,0)=0x78;
  744. WBUFL(buf,2)=bl->id;
  745. WBUFW(buf,6)=status_get_speed(bl);
  746. if (sc) {
  747. WBUFW(buf,8)=sc->opt1;
  748. WBUFW(buf,10)=sc->opt2;
  749. WBUFW(buf,12)=sc->option;
  750. WBUFW(buf,42)=sc->opt3;
  751. }
  752. WBUFW(buf,14)=vd->class_;
  753. WBUFW(buf,16)=vd->hair_style;
  754. WBUFW(buf,18)=vd->weapon;
  755. WBUFW(buf,20)=vd->head_bottom;
  756. WBUFW(buf,22)=vd->shield;
  757. WBUFW(buf,24)=vd->head_top;
  758. WBUFW(buf,26)=vd->head_mid;
  759. WBUFW(buf,28)=vd->hair_color;
  760. WBUFW(buf,30)=vd->cloth_color;
  761. WBUFW(buf,32)=sd?sd->head_dir:0;
  762. WBUFL(buf,34)=guild_id;
  763. WBUFW(buf,38)=emblem_id;
  764. if (sd) {
  765. WBUFW(buf,40)=sd->status.manner;
  766. WBUFB(buf,44)=sd->status.karma;
  767. }
  768. WBUFB(buf,45)=vd->sex;
  769. WBUFPOS(buf,46,bl->x,bl->y,dir);
  770. WBUFB(buf,49)=5;
  771. WBUFB(buf,50)=5;
  772. WBUFB(buf,51)=vd->dead_sit;
  773. WBUFW(buf,52)=clif_setlevel(lv);
  774. return packet_len(0x78);
  775. #endif
  776. }
  777. //Non-player sprites need just a few fields filled.
  778. memset(buf,0,packet_len(0x78));
  779. WBUFW(buf,0)=0x78;
  780. WBUFL(buf,2)=bl->id;
  781. WBUFW(buf,6)=status_get_speed(bl);
  782. if (sc) {
  783. WBUFW(buf,8)=sc->opt1;
  784. WBUFW(buf,10)=sc->opt2;
  785. WBUFW(buf,12)=sc->option;
  786. WBUFW(buf,42)=sc->opt3;
  787. }
  788. WBUFW(buf,14)=vd->class_;
  789. WBUFW(buf,16)=vd->hair_style; //Required for pets (removes attack cursor)
  790. //18W: Weapon
  791. WBUFW(buf,20)=vd->head_bottom; //Pet armor (ignored by client)
  792. if (bl->type == BL_NPC && vd->class_ == FLAG_CLASS)
  793. { //The hell, why flags work like this?
  794. WBUFL(buf,22)=emblem_id;
  795. WBUFL(buf,26)=guild_id;
  796. }
  797. //22W: shield
  798. //24W: Head top
  799. //26W: Head mid
  800. //28W: Hair color
  801. //30W: Clothes color
  802. //32W: Head dir
  803. WBUFL(buf,34)=guild_id;
  804. WBUFW(buf,38)=emblem_id;
  805. //40W: Manner
  806. //44B: Karma
  807. //45B: Sex
  808. WBUFPOS(buf,46,bl->x,bl->y,dir);
  809. //49B: ???
  810. //50B: ???
  811. //51B: Sit/Stand
  812. WBUFW(buf,52)=clif_setlevel(lv);
  813. return packet_len(0x78);
  814. }
  815. /*==========================================
  816. * Prepares 'unit walking' packet
  817. *------------------------------------------*/
  818. static int clif_set007b(struct block_list *bl, struct view_data *vd, struct unit_data *ud, unsigned char *buf)
  819. {
  820. struct status_change *sc;
  821. int guild_id, emblem_id, lv;
  822. nullpo_retr(0, bl);
  823. sc = status_get_sc(bl);
  824. guild_id = status_get_guild_id(bl);
  825. emblem_id = status_get_emblem_id(bl);
  826. lv = status_get_lv(bl);
  827. if(pcdb_checkid(vd->class_))
  828. {
  829. struct map_session_data* sd;
  830. BL_CAST(BL_PC, bl, sd);
  831. #if PACKETVER >= 7
  832. memset(buf,0,packet_len(0x22c));
  833. WBUFW(buf,0)=0x22c;
  834. WBUFL(buf,2)=bl->id;
  835. WBUFW(buf,6)=status_get_speed(bl);
  836. if (sc) {
  837. WBUFW(buf,8)= sc->opt1;
  838. WBUFW(buf,10)= sc->opt2;
  839. WBUFL(buf,12)= sc->option;
  840. WBUFL(buf,48)= sc->opt3;
  841. }
  842. WBUFW(buf,16)=vd->class_;
  843. WBUFW(buf,18)=vd->hair_style;
  844. WBUFW(buf,20)=vd->weapon;
  845. WBUFW(buf,22)=vd->shield;
  846. WBUFW(buf,24)=vd->head_bottom;
  847. WBUFL(buf,26)=gettick();
  848. WBUFW(buf,30)=vd->head_top;
  849. WBUFW(buf,32)=vd->head_mid;
  850. WBUFW(buf,34)=vd->hair_color;
  851. WBUFW(buf,36)=vd->cloth_color;
  852. WBUFW(buf,38)=sd?sd->head_dir:0;
  853. WBUFL(buf,40)=guild_id;
  854. WBUFW(buf,44)=emblem_id;
  855. if (sd) {
  856. WBUFW(buf,46)=sd->status.manner;
  857. WBUFB(buf,52)=sd->status.karma;
  858. }
  859. WBUFB(buf,53)=vd->sex;
  860. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  861. WBUFB(buf,60)=5;
  862. WBUFB(buf,61)=5;
  863. WBUFW(buf,62)=clif_setlevel(lv);
  864. return packet_len(0x22c);
  865. #elif PACKETVER > 3
  866. memset(buf,0,packet_len(0x1da));
  867. WBUFW(buf,0)=0x1da;
  868. WBUFL(buf,2)=bl->id;
  869. WBUFW(buf,6)=status_get_speed(bl);
  870. if (sc) {
  871. WBUFW(buf,8)=sc->opt1;
  872. WBUFW(buf,10)=sc->opt2;
  873. WBUFW(buf,12)=sc->option;
  874. WBUFW(buf,46)=sc->opt3;
  875. }
  876. WBUFW(buf,14)=vd->class_;
  877. WBUFW(buf,16)=vd->hair_style;
  878. WBUFW(buf,18)=vd->weapon;
  879. WBUFW(buf,20)=vd->shield;
  880. WBUFW(buf,22)=vd->head_bottom;
  881. WBUFL(buf,24)=gettick();
  882. WBUFW(buf,28)=vd->head_top;
  883. WBUFW(buf,30)=vd->head_mid;
  884. WBUFW(buf,32)=vd->hair_color;
  885. WBUFW(buf,34)=vd->cloth_color;
  886. WBUFW(buf,36)=sd?sd->head_dir:0;
  887. WBUFL(buf,38)=guild_id;
  888. WBUFW(buf,42)=emblem_id;
  889. if (sd) {
  890. WBUFW(buf,44)=sd->status.manner;
  891. WBUFB(buf,48)=sd->status.karma;
  892. }
  893. WBUFB(buf,49)=vd->sex;
  894. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  895. WBUFB(buf,56)=5;
  896. WBUFB(buf,57)=5;
  897. WBUFW(buf,58)=clif_setlevel(lv);
  898. return packet_len(0x1da);
  899. #else
  900. memset(buf,0,packet_len(0x7b));
  901. WBUFW(buf,0)=0x7b;
  902. WBUFL(buf,2)=bl->id;
  903. WBUFW(buf,6)=status_get_speed(bl);
  904. if (sc) {
  905. WBUFW(buf,8)=sc->opt1;
  906. WBUFW(buf,10)=sc->opt2;
  907. WBUFW(buf,12)=sc->option;
  908. WBUFW(buf,46)=sc->opt3;
  909. }
  910. WBUFW(buf,14)=vd->class_;
  911. WBUFW(buf,16)=vd->hair_style;
  912. WBUFW(buf,18)=vd->weapon;
  913. WBUFW(buf,20)=vd->head_bottom;
  914. WBUFL(buf,22)=gettick();
  915. WBUFW(buf,26)=vd->shield;
  916. WBUFW(buf,28)=vd->head_top;
  917. WBUFW(buf,30)=vd->head_mid;
  918. WBUFW(buf,32)=vd->hair_color;
  919. WBUFW(buf,34)=vd->cloth_color;
  920. WBUFW(buf,36)=sd?sd->head_dir:0;
  921. WBUFL(buf,38)=guild_id;
  922. WBUFW(buf,42)=emblem_id;
  923. if (sd) {
  924. WBUFW(buf,44)=sd->status.manner;
  925. WBUFB(buf,48)=sd->status.karma;
  926. }
  927. WBUFB(buf,49)=vd->sex;
  928. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  929. WBUFB(buf,56)=5;
  930. WBUFB(buf,57)=5;
  931. WBUFW(buf,58)=clif_setlevel(lv);
  932. return packet_len(0x7b);
  933. #endif
  934. }
  935. //Non-player sprites only require a few fields.
  936. #if PACKETVER >= 7
  937. memset(buf,0,packet_len(0x22c));
  938. WBUFW(buf,0)=0x22c;
  939. WBUFL(buf,2)=bl->id;
  940. WBUFW(buf,6)=status_get_speed(bl);
  941. if (sc) {
  942. WBUFW(buf,8)=sc->opt1;
  943. WBUFW(buf,10)=sc->opt2;
  944. WBUFL(buf,12)=sc->option;
  945. WBUFL(buf,48)=sc->opt3;
  946. }
  947. WBUFW(buf,16)=vd->class_;
  948. WBUFW(buf,18)=vd->hair_style; //Required for pets (removes attack cursor)
  949. //20L: Weapon/Shield
  950. WBUFW(buf,24)=vd->head_bottom; //Pet armor
  951. WBUFL(buf,26)=gettick();
  952. //30W: Head top
  953. //32W: Head mid
  954. //34W: Hair color
  955. //36W: Cloth color
  956. //38W: Head dir
  957. WBUFL(buf,40)=guild_id;
  958. WBUFW(buf,44)=emblem_id;
  959. //46W: Manner
  960. //52B: Karma
  961. //53B: Sex
  962. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  963. //60B: ???
  964. //61B: ???
  965. WBUFW(buf,62)=clif_setlevel(lv);
  966. return packet_len(0x22c);
  967. #else
  968. memset(buf,0,packet_len(0x7b));
  969. WBUFW(buf,0)=0x7b;
  970. WBUFL(buf,2)=bl->id;
  971. WBUFW(buf,6)=status_get_speed(bl);
  972. if (sc) {
  973. WBUFW(buf,8)=sc->opt1;
  974. WBUFW(buf,10)=sc->opt2;
  975. WBUFW(buf,12)=sc->option;
  976. WBUFW(buf,46)=sc->opt3;
  977. }
  978. WBUFW(buf,14)=vd->class_;
  979. WBUFW(buf,16)=vd->hair_style; //Required for pets (removes attack cursor)
  980. //18W: Weapon
  981. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  982. WBUFL(buf,22)=gettick();
  983. //26W: Shield
  984. //28W: Head top
  985. //30W: Head mid
  986. //32W: Hair color
  987. //34W: Cloth color
  988. //36W: Head dir
  989. WBUFL(buf,38)=guild_id;
  990. WBUFW(buf,42)=emblem_id;
  991. //44W: Manner
  992. //46W: Opt3
  993. //48B: Karma
  994. //49B: Sex
  995. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  996. WBUFB(buf,56)=5;
  997. WBUFB(buf,57)=5;
  998. WBUFW(buf,58)=clif_setlevel(lv);
  999. return packet_len(0x7b);
  1000. #endif
  1001. }
  1002. //Modifies the buffer for disguise characters and sends it to self.
  1003. //Flag = 0: change id to negative, buf will have disguise data.
  1004. //Flag = 1: change id to positive, class and option to make your own char invisible.
  1005. //Luckily, the offsets that need to be changed are the same in packets 0x78, 0x7b, 0x1d8 and 0x1da
  1006. //But no longer holds true for those packet of PACKETVER 7.
  1007. static void clif_setdisguise(struct map_session_data *sd, unsigned char *buf,int len, int flag)
  1008. {
  1009. if (flag) {
  1010. WBUFL(buf,2)=sd->bl.id;
  1011. #if PACKETVER >= 7
  1012. switch (WBUFW(buf,0)) {
  1013. case 0x22c:
  1014. case 0x22b:
  1015. case 0x22a:
  1016. WBUFL(buf,12)=OPTION_INVISIBLE;
  1017. WBUFW(buf,16)=sd->status.class_;
  1018. break;
  1019. default:
  1020. #endif
  1021. WBUFW(buf,12)=OPTION_INVISIBLE;
  1022. WBUFW(buf,14)=sd->status.class_;
  1023. #if PACKETVER >= 7
  1024. break;
  1025. }
  1026. #endif
  1027. } else {
  1028. WBUFL(buf,2)=-sd->bl.id;
  1029. }
  1030. clif_send(buf, len, &sd->bl, SELF);
  1031. }
  1032. /*==========================================
  1033. * クラスチェンジ typeはMobの場合は1で他は0?
  1034. *------------------------------------------*/
  1035. int clif_class_change(struct block_list *bl,int class_,int type)
  1036. {
  1037. unsigned char buf[16];
  1038. nullpo_retr(0, bl);
  1039. if(!pcdb_checkid(class_)) {
  1040. WBUFW(buf,0)=0x1b0;
  1041. WBUFL(buf,2)=bl->id;
  1042. WBUFB(buf,6)=type;
  1043. WBUFL(buf,7)=class_;
  1044. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1045. }
  1046. return 0;
  1047. }
  1048. /*==========================================
  1049. *
  1050. *------------------------------------------*/
  1051. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1052. {
  1053. WFIFOHEAD(fd, packet_len(0x1e1));
  1054. WFIFOW(fd,0)=0x1e1;
  1055. WFIFOL(fd,2)=sd->bl.id;
  1056. WFIFOW(fd,6)=sd->spiritball;
  1057. WFIFOSET(fd, packet_len(0x1e1));
  1058. }
  1059. // new and improved weather display [Valaris]
  1060. static void clif_weather_sub(int fd, int id, int type)
  1061. {
  1062. WFIFOHEAD(fd,packet_len(0x1f3));
  1063. WFIFOW(fd,0) = 0x1f3;
  1064. WFIFOL(fd,2) = id;
  1065. WFIFOL(fd,6) = type;
  1066. WFIFOSET(fd,packet_len(0x1f3));
  1067. }
  1068. /*==========================================
  1069. *
  1070. *------------------------------------------*/
  1071. static void clif_weather_check(struct map_session_data *sd)
  1072. {
  1073. int m = sd->bl.m, fd = sd->fd;
  1074. if (map[m].flag.snow
  1075. || map[m].flag.clouds
  1076. || map[m].flag.fog
  1077. || map[m].flag.fireworks
  1078. || map[m].flag.sakura
  1079. || map[m].flag.leaves
  1080. || map[m].flag.rain
  1081. || map[m].flag.clouds2)
  1082. {
  1083. if (map[m].flag.snow)
  1084. clif_weather_sub(fd, sd->bl.id, 162);
  1085. if (map[m].flag.clouds)
  1086. clif_weather_sub(fd, sd->bl.id, 233);
  1087. if (map[m].flag.clouds2)
  1088. clif_weather_sub(fd, sd->bl.id, 516);
  1089. if (map[m].flag.fog)
  1090. clif_weather_sub(fd, sd->bl.id, 515);
  1091. if (map[m].flag.fireworks) {
  1092. clif_weather_sub(fd, sd->bl.id, 297);
  1093. clif_weather_sub(fd, sd->bl.id, 299);
  1094. clif_weather_sub(fd, sd->bl.id, 301);
  1095. }
  1096. if (map[m].flag.sakura)
  1097. clif_weather_sub(fd, sd->bl.id, 163);
  1098. if (map[m].flag.leaves)
  1099. clif_weather_sub(fd, sd->bl.id, 333);
  1100. if (map[m].flag.rain)
  1101. clif_weather_sub(fd, sd->bl.id, 161);
  1102. }
  1103. }
  1104. int clif_weather(int m)
  1105. {
  1106. int i;
  1107. struct map_session_data *sd=NULL;
  1108. for(i = 0; i < fd_max; i++) {
  1109. if (session[i] && session[i]->func_parse == clif_parse &&
  1110. (sd = session[i]->session_data) != NULL &&
  1111. sd->state.auth && sd->bl.m == m) {
  1112. clif_weather_check(sd);
  1113. }
  1114. }
  1115. return 0;
  1116. }
  1117. int clif_spawn(struct block_list *bl)
  1118. {
  1119. unsigned char buf[128];
  1120. struct view_data *vd;
  1121. nullpo_retr(0, bl);
  1122. vd = status_get_viewdata(bl);
  1123. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1124. return 0;
  1125. if (pcdb_checkid(vd->class_))
  1126. { // player spawn packet
  1127. clif_set0078(bl, buf);
  1128. switch(WBUFW(buf,0))
  1129. {
  1130. case 0x78: //Convert to 0x79
  1131. WBUFW(buf, 0) = 0x79;
  1132. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1133. clif_send(buf, packet_len(0x79), bl, AREA_WOS);
  1134. if (disguised(bl))
  1135. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x79), 0);
  1136. break;
  1137. #if PACKETVER > 3
  1138. case 0x1d8: //Convert to 0x1d9
  1139. WBUFW(buf, 0) = 0x1d9;
  1140. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1141. clif_send(buf, packet_len(0x1d9), bl, AREA_WOS);
  1142. if (disguised(bl))
  1143. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x1d9), 0);
  1144. break;
  1145. #endif
  1146. #if PACKETVER >= 7
  1147. case 0x22a: //Convert to 0x22b
  1148. WBUFW(buf, 0) = 0x22b;
  1149. WBUFW(buf,55) = WBUFW(buf,56); //Lv is placed on offset 56
  1150. clif_send(buf, packet_len(0x22b), bl, AREA_WOS);
  1151. if (disguised(bl))
  1152. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x22b), 0);
  1153. break;
  1154. #endif
  1155. }
  1156. } else { // npc/mob/pet/homun spawn packet
  1157. struct status_change *sc = status_get_sc(bl);
  1158. memset(buf,0,sizeof(buf));
  1159. WBUFW(buf,0)=0x7c;
  1160. WBUFL(buf,2)=bl->id;
  1161. WBUFW(buf,6)=status_get_speed(bl);
  1162. if (sc) {
  1163. WBUFW(buf,8)=sc->opt1;
  1164. WBUFW(buf,10)=sc->opt2;
  1165. WBUFW(buf,12)=sc->option;
  1166. }
  1167. WBUFW(buf,14)=vd->hair_style; //Required for pets (removes attack cursor)
  1168. //16W: Weapon
  1169. WBUFW(buf,18)=vd->head_bottom; //Pet armor (ignored by client)
  1170. WBUFW(buf,20)=vd->class_;
  1171. //22W: Shield
  1172. //24W: Head top
  1173. //26W: Head mid
  1174. //28W: Hair color
  1175. //30W: Cloth color
  1176. //32W: Head dir
  1177. //34B: karma
  1178. //35B: Sex
  1179. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  1180. //39B: ???
  1181. //40B: ???
  1182. clif_send(buf,packet_len(0x7c),bl,AREA_WOS);
  1183. if (disguised(bl)) {
  1184. WBUFL(buf,2)=-bl->id;
  1185. clif_send(buf,packet_len(0x7c),bl,SELF);
  1186. }
  1187. }
  1188. if (vd->cloth_color)
  1189. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1190. switch (bl->type)
  1191. {
  1192. case BL_PC:
  1193. {
  1194. TBL_PC *sd = ((TBL_PC*)bl);
  1195. if (sd->spiritball > 0)
  1196. clif_spiritball(sd);
  1197. if(sd->state.size==2) // tiny/big players [Valaris]
  1198. clif_specialeffect(bl,423,AREA);
  1199. else if(sd->state.size==1)
  1200. clif_specialeffect(bl,421,AREA);
  1201. }
  1202. break;
  1203. case BL_MOB:
  1204. {
  1205. TBL_MOB *md = ((TBL_MOB*)bl);
  1206. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1207. clif_specialeffect(&md->bl,423,AREA);
  1208. else if(md->special_state.size==1)
  1209. clif_specialeffect(&md->bl,421,AREA);
  1210. }
  1211. break;
  1212. case BL_PET:
  1213. if (vd->head_bottom)
  1214. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1215. break;
  1216. }
  1217. return 0;
  1218. }
  1219. //[orn]
  1220. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1221. {
  1222. struct status_data *status;
  1223. unsigned char buf[128];
  1224. nullpo_retr(0, hd);
  1225. status = &hd->battle_status;
  1226. memset(buf,0,packet_len(0x22e));
  1227. WBUFW(buf,0)=0x22e;
  1228. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1229. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1230. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1231. WBUFW(buf,27)=hd->homunculus.level;
  1232. WBUFW(buf,29)=hd->homunculus.hunger;
  1233. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1234. WBUFW(buf,33)=0; // equip id
  1235. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, SHRT_MAX);
  1236. WBUFW(buf,37)=cap_value(status->matk_max, 0, SHRT_MAX);
  1237. WBUFW(buf,39)=status->hit;
  1238. if (battle_config.hom_setting&0x10)
  1239. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1240. else
  1241. WBUFW(buf,41)=status->cri/10;
  1242. WBUFW(buf,43)=status->def + status->vit ;
  1243. WBUFW(buf,45)=status->mdef;
  1244. WBUFW(buf,47)=status->flee;
  1245. WBUFW(buf,49)=(flag)?0:status->amotion;
  1246. if (status->max_hp > SHRT_MAX) {
  1247. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1248. WBUFW(buf,53) = 100;
  1249. } else {
  1250. WBUFW(buf,51)=status->hp;
  1251. WBUFW(buf,53)=status->max_hp;
  1252. }
  1253. if (status->max_sp > SHRT_MAX) {
  1254. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1255. WBUFW(buf,57) = 100;
  1256. } else {
  1257. WBUFW(buf,55)=status->sp;
  1258. WBUFW(buf,57)=status->max_sp;
  1259. }
  1260. WBUFL(buf,59)=hd->homunculus.exp;
  1261. WBUFL(buf,63)=hd->exp_next;
  1262. WBUFW(buf,67)=hd->homunculus.skillpts;
  1263. WBUFW(buf,69)=1; // FIXME: Attackable? When exactly is a homun not attackable? [Skotlex]
  1264. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1265. return 0;
  1266. }
  1267. void clif_send_homdata(struct map_session_data *sd, int type, int param)
  1268. { //[orn]
  1269. int fd = sd->fd;
  1270. WFIFOHEAD(fd, packet_len(0x230));
  1271. nullpo_retv(sd->hd);
  1272. WFIFOW(fd,0)=0x230;
  1273. WFIFOW(fd,2)=type;
  1274. WFIFOL(fd,4)=sd->hd->bl.id;
  1275. WFIFOL(fd,8)=param;
  1276. WFIFOSET(fd,packet_len(0x230));
  1277. return;
  1278. }
  1279. int clif_homskillinfoblock(struct map_session_data *sd)
  1280. { //[orn]
  1281. struct homun_data *hd;
  1282. int fd = sd->fd;
  1283. int i,j,len=4,id;
  1284. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1285. hd = sd->hd;
  1286. if ( !hd )
  1287. return 0 ;
  1288. WFIFOW(fd,0)=0x235;
  1289. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1290. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1291. j = id - HM_SKILLBASE - 1 ;
  1292. WFIFOW(fd,len ) = id ;
  1293. WFIFOW(fd,len+2) = skill_get_inf(id) ;
  1294. WFIFOW(fd,len+4) = 0 ;
  1295. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv ;
  1296. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv) ;
  1297. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv) ;
  1298. strncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH) ;
  1299. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1300. len+=37;
  1301. }
  1302. }
  1303. WFIFOW(fd,2)=len;
  1304. WFIFOSET(fd,len);
  1305. return 0;
  1306. }
  1307. void clif_homskillup(struct map_session_data *sd, int skill_num)
  1308. { //[orn]
  1309. struct homun_data *hd;
  1310. int fd=sd->fd, skillid;
  1311. WFIFOHEAD(fd, packet_len(0x239));
  1312. nullpo_retv(sd);
  1313. skillid = skill_num - HM_SKILLBASE - 1;
  1314. hd=sd->hd;
  1315. WFIFOW(fd,0) = 0x239;
  1316. WFIFOW(fd,2) = skill_num;
  1317. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1318. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1319. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1320. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1321. WFIFOSET(fd,packet_len(0x239));
  1322. return;
  1323. }
  1324. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1325. {
  1326. int fd=sd->fd;
  1327. WFIFOHEAD(fd,packet_len(0x22f));
  1328. WFIFOW(fd,0)=0x22f;
  1329. WFIFOB(fd,2)=fail;
  1330. WFIFOW(fd,3)=foodid;
  1331. WFIFOSET(fd,packet_len(0x22f));
  1332. return 0;
  1333. }
  1334. /*==========================================
  1335. *
  1336. *------------------------------------------*/
  1337. int clif_walkok(struct map_session_data *sd)
  1338. {
  1339. int fd=sd->fd;
  1340. WFIFOHEAD(fd, packet_len(0x87));
  1341. WFIFOW(fd,0)=0x87;
  1342. WFIFOL(fd,2)=gettick();
  1343. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1344. WFIFOSET(fd,packet_len(0x87));
  1345. return 0;
  1346. }
  1347. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1348. {
  1349. unsigned char buf[256];
  1350. int len;
  1351. len = clif_set007b(bl,vd,ud,buf);
  1352. clif_send(buf,len,bl,AREA_WOS);
  1353. if (disguised(bl))
  1354. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  1355. if(vd->cloth_color)
  1356. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1357. switch(bl->type)
  1358. {
  1359. case BL_PC:
  1360. {
  1361. TBL_PC *sd = ((TBL_PC*)bl);
  1362. // clif_movepc(sd);
  1363. if(sd->state.size==2) // tiny/big players [Valaris]
  1364. clif_specialeffect(&sd->bl,423,AREA);
  1365. else if(sd->state.size==1)
  1366. clif_specialeffect(&sd->bl,421,AREA);
  1367. }
  1368. break;
  1369. case BL_MOB:
  1370. {
  1371. TBL_MOB *md = ((TBL_MOB*)bl);
  1372. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1373. clif_specialeffect(&md->bl,423,AREA);
  1374. else if(md->special_state.size==1)
  1375. clif_specialeffect(&md->bl,421,AREA);
  1376. }
  1377. break;
  1378. }
  1379. return;
  1380. }
  1381. /// Move the unit (does nothing if the client has no info about the unit)
  1382. /// Note: unit must not be self
  1383. void clif_move(struct unit_data *ud)
  1384. {
  1385. unsigned char buf[16];
  1386. struct view_data* vd;
  1387. struct block_list* bl = ud->bl;
  1388. vd = status_get_viewdata(bl);
  1389. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1390. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1391. if (ud->state.speed_changed) {
  1392. // Since we don't know how to update the speed of other objects,
  1393. // use the old walk packet to update the data.
  1394. ud->state.speed_changed = 0;
  1395. clif_move2(bl, vd, ud);
  1396. return;
  1397. }
  1398. WBUFW(buf,0)=0x86;
  1399. WBUFL(buf,2)=bl->id;
  1400. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1401. WBUFL(buf,12)=gettick();
  1402. clif_send(buf, 16, bl, AREA_WOS);
  1403. if (disguised(bl))
  1404. clif_setdisguise((TBL_PC*)bl, buf, 16, 0);
  1405. }
  1406. /*==========================================
  1407. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1408. *------------------------------------------*/
  1409. static int clif_delayquit(int tid, unsigned int tick, int id, int data)
  1410. {
  1411. struct map_session_data *sd = NULL;
  1412. //Remove player from map server
  1413. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1414. map_quit(sd);
  1415. return 0;
  1416. }
  1417. /*==========================================
  1418. *
  1419. *------------------------------------------*/
  1420. void clif_quitsave(int fd,struct map_session_data *sd)
  1421. {
  1422. if (sd->state.waitingdisconnect || //Was already waiting to be disconnected.
  1423. !battle_config.prevent_logout ||
  1424. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1425. map_quit(sd);
  1426. else if (sd->fd)
  1427. { //Disassociate session from player (session is deleted after this function was called)
  1428. //And set a timer to make him quit later.
  1429. session[sd->fd]->session_data = NULL;
  1430. sd->fd = 0;
  1431. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1432. }
  1433. }
  1434. /*==========================================
  1435. *
  1436. *------------------------------------------*/
  1437. static int clif_waitclose(int tid, unsigned int tick, int id, int data)
  1438. {
  1439. if (session[id] && session[id]->func_parse == clif_parse) //Avoid disconnecting non-players, as pointed out by End of Exam [Skotlex]
  1440. set_eof(id);
  1441. return 0;
  1442. }
  1443. /*==========================================
  1444. *
  1445. *------------------------------------------*/
  1446. void clif_setwaitclose(int fd)
  1447. {
  1448. struct map_session_data *sd;
  1449. // if player is not already in the game (double connection probably)
  1450. if ((sd = (struct map_session_data*)session[fd]->session_data) == NULL) {
  1451. // limited timer, just to send information.
  1452. add_timer(gettick() + 1000, clif_waitclose, fd, 0);
  1453. } else
  1454. add_timer(gettick() + 5000, clif_waitclose, fd, 0);
  1455. }
  1456. /*==========================================
  1457. *
  1458. *------------------------------------------*/
  1459. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1460. {
  1461. int fd;
  1462. nullpo_retv(sd);
  1463. fd = sd->fd;
  1464. WFIFOHEAD(fd,packet_len(0x91));
  1465. WFIFOW(fd,0) = 0x91;
  1466. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1467. WFIFOW(fd,18) = x;
  1468. WFIFOW(fd,20) = y;
  1469. WFIFOSET(fd,packet_len(0x91));
  1470. }
  1471. /*==========================================
  1472. * Tells the client to connect to another map-server
  1473. *------------------------------------------*/
  1474. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1475. {
  1476. int fd;
  1477. nullpo_retv(sd);
  1478. fd = sd->fd;
  1479. WFIFOHEAD(fd,packet_len(0x92));
  1480. WFIFOW(fd,0) = 0x92;
  1481. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1482. WFIFOW(fd,18) = x;
  1483. WFIFOW(fd,20) = y;
  1484. WFIFOL(fd,22) = htonl(ip);
  1485. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1486. WFIFOSET(fd,packet_len(0x92));
  1487. }
  1488. int clif_blown(struct block_list *bl)
  1489. {
  1490. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1491. // return clif_fixpos(bl);
  1492. return clif_slide(bl, bl->x, bl->y);
  1493. }
  1494. /*==========================================
  1495. *
  1496. *------------------------------------------*/
  1497. int clif_fixpos(struct block_list *bl)
  1498. {
  1499. unsigned char buf[16];
  1500. nullpo_retr(0, bl);
  1501. WBUFW(buf,0)=0x88;
  1502. WBUFL(buf,2)=bl->id;
  1503. WBUFW(buf,6)=bl->x;
  1504. WBUFW(buf,8)=bl->y;
  1505. clif_send(buf, packet_len(0x88), bl, AREA);
  1506. if (disguised(bl)) {
  1507. WBUFL(buf,2)=-bl->id;
  1508. clif_send(buf, packet_len(0x88), bl, SELF);
  1509. }
  1510. return 0;
  1511. }
  1512. /*==========================================
  1513. *
  1514. *------------------------------------------*/
  1515. int clif_npcbuysell(struct map_session_data* sd, int id)
  1516. {
  1517. int fd;
  1518. nullpo_retr(0, sd);
  1519. fd=sd->fd;
  1520. WFIFOHEAD(fd, packet_len(0xc4));
  1521. WFIFOW(fd,0)=0xc4;
  1522. WFIFOL(fd,2)=id;
  1523. WFIFOSET(fd,packet_len(0xc4));
  1524. return 0;
  1525. }
  1526. /*==========================================
  1527. *
  1528. *------------------------------------------*/
  1529. int clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1530. {
  1531. struct item_data *id;
  1532. int fd,i,val;
  1533. nullpo_retr(0, sd);
  1534. nullpo_retr(0, nd);
  1535. fd=sd->fd;
  1536. WFIFOHEAD(fd, 200 * 11 + 4);
  1537. WFIFOW(fd,0)=0xc6;
  1538. for(i=0;nd->u.shop_item[i].nameid > 0;i++){
  1539. id = itemdb_search(nd->u.shop_item[i].nameid);
  1540. val=nd->u.shop_item[i].value;
  1541. WFIFOL(fd,4+i*11)=val;
  1542. if (!id->flag.value_notdc)
  1543. val=pc_modifybuyvalue(sd,val);
  1544. WFIFOL(fd,8+i*11)=val;
  1545. WFIFOB(fd,12+i*11)=itemtype(id->type);
  1546. if (id->view_id > 0)
  1547. WFIFOW(fd,13+i*11)=id->view_id;
  1548. else
  1549. WFIFOW(fd,13+i*11)=nd->u.shop_item[i].nameid;
  1550. }
  1551. WFIFOW(fd,2)=i*11+4;
  1552. WFIFOSET(fd,WFIFOW(fd,2));
  1553. return 0;
  1554. }
  1555. /*==========================================
  1556. *
  1557. *------------------------------------------*/
  1558. int clif_selllist(struct map_session_data *sd)
  1559. {
  1560. int fd,i,c=0,val;
  1561. nullpo_retr(0, sd);
  1562. fd=sd->fd;
  1563. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1564. WFIFOW(fd,0)=0xc7;
  1565. for(i=0;i<MAX_INVENTORY;i++) {
  1566. if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
  1567. if (!itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)))
  1568. continue;
  1569. val=sd->inventory_data[i]->value_sell;
  1570. if (val < 0)
  1571. continue;
  1572. WFIFOW(fd,4+c*10)=i+2;
  1573. WFIFOL(fd,6+c*10)=val;
  1574. if (!sd->inventory_data[i]->flag.value_notoc)
  1575. val=pc_modifysellvalue(sd,val);
  1576. WFIFOL(fd,10+c*10)=val;
  1577. c++;
  1578. }
  1579. }
  1580. WFIFOW(fd,2)=c*10+4;
  1581. WFIFOSET(fd,WFIFOW(fd,2));
  1582. return 0;
  1583. }
  1584. /*==========================================
  1585. *
  1586. *------------------------------------------*/
  1587. int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1588. {
  1589. int fd = sd->fd;
  1590. int slen = strlen(mes) + 9;
  1591. WFIFOHEAD(fd, slen);
  1592. WFIFOW(fd,0)=0xb4;
  1593. WFIFOW(fd,2)=slen;
  1594. WFIFOL(fd,4)=npcid;
  1595. strcpy((char*)WFIFOP(fd,8),mes);
  1596. WFIFOSET(fd,WFIFOW(fd,2));
  1597. return 0;
  1598. }
  1599. /*==========================================
  1600. *
  1601. *------------------------------------------*/
  1602. int clif_scriptnext(struct map_session_data *sd,int npcid)
  1603. {
  1604. int fd;
  1605. nullpo_retr(0, sd);
  1606. fd=sd->fd;
  1607. WFIFOHEAD(fd, packet_len(0xb5));
  1608. WFIFOW(fd,0)=0xb5;
  1609. WFIFOL(fd,2)=npcid;
  1610. WFIFOSET(fd,packet_len(0xb5));
  1611. return 0;
  1612. }
  1613. /*==========================================
  1614. *
  1615. *------------------------------------------*/
  1616. int clif_scriptclose(struct map_session_data *sd, int npcid)
  1617. {
  1618. int fd;
  1619. nullpo_retr(0, sd);
  1620. fd=sd->fd;
  1621. WFIFOHEAD(fd, packet_len(0xb6));
  1622. WFIFOW(fd,0)=0xb6;
  1623. WFIFOL(fd,2)=npcid;
  1624. WFIFOSET(fd,packet_len(0xb6));
  1625. return 0;
  1626. }
  1627. /*==========================================
  1628. *
  1629. *------------------------------------------*/
  1630. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1631. {
  1632. int fd = sd->fd;
  1633. WFIFOHEAD(fd, packet_len(0x78));
  1634. sd->state.using_fake_npc = 1;
  1635. memset(WFIFOP(fd,0), 0, packet_len(0x78));
  1636. WFIFOW(fd,0)=0x78;
  1637. WFIFOL(fd,2)=npcid;
  1638. WFIFOW(fd,14)=111;
  1639. WFIFOPOS(fd,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1640. WFIFOB(fd,49)=5;
  1641. WFIFOB(fd,50)=5;
  1642. WFIFOSET(fd, packet_len(0x78));
  1643. return;
  1644. }
  1645. /*==========================================
  1646. *
  1647. *------------------------------------------*/
  1648. int clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1649. {
  1650. int fd = sd->fd;
  1651. int slen = strlen(mes) + 8;
  1652. struct block_list *bl = NULL;
  1653. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1654. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1655. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1656. clif_sendfakenpc(sd, npcid);
  1657. WFIFOHEAD(fd, slen);
  1658. WFIFOW(fd,0)=0xb7;
  1659. WFIFOW(fd,2)=slen;
  1660. WFIFOL(fd,4)=npcid;
  1661. strcpy((char*)WFIFOP(fd,8),mes);
  1662. WFIFOSET(fd,WFIFOW(fd,2));
  1663. return 0;
  1664. }
  1665. /*==========================================
  1666. *
  1667. *------------------------------------------*/
  1668. int clif_scriptinput(struct map_session_data *sd, int npcid)
  1669. {
  1670. int fd;
  1671. struct block_list *bl = NULL;
  1672. nullpo_retr(0, sd);
  1673. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1674. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1675. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1676. clif_sendfakenpc(sd, npcid);
  1677. fd=sd->fd;
  1678. WFIFOHEAD(fd, packet_len(0x142));
  1679. WFIFOW(fd,0)=0x142;
  1680. WFIFOL(fd,2)=npcid;
  1681. WFIFOSET(fd,packet_len(0x142));
  1682. return 0;
  1683. }
  1684. /*==========================================
  1685. *
  1686. *------------------------------------------*/
  1687. int clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1688. {
  1689. int fd;
  1690. struct block_list *bl = NULL;
  1691. nullpo_retr(0, sd);
  1692. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1693. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1694. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1695. clif_sendfakenpc(sd, npcid);
  1696. fd=sd->fd;
  1697. WFIFOHEAD(fd, packet_len(0x1d4));
  1698. WFIFOW(fd,0)=0x1d4;
  1699. WFIFOL(fd,2)=npcid;
  1700. WFIFOSET(fd,packet_len(0x1d4));
  1701. return 0;
  1702. }
  1703. /// npc_id is ignored in the client
  1704. /// type=2 : Remove viewpoint
  1705. /// type=other : Show viewpoint
  1706. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1707. {
  1708. int fd;
  1709. nullpo_retr(0, sd);
  1710. fd=sd->fd;
  1711. WFIFOHEAD(fd, packet_len(0x144));
  1712. WFIFOW(fd,0)=0x144;
  1713. WFIFOL(fd,2)=npc_id;
  1714. WFIFOL(fd,6)=type;
  1715. WFIFOL(fd,10)=x;
  1716. WFIFOL(fd,14)=y;
  1717. WFIFOB(fd,18)=id;
  1718. WFIFOL(fd,19)=color;
  1719. WFIFOSET(fd,packet_len(0x144));
  1720. return 0;
  1721. }
  1722. /*==========================================
  1723. *
  1724. *------------------------------------------*/
  1725. int clif_cutin(struct map_session_data* sd, const char* image, int type)
  1726. {
  1727. int fd;
  1728. nullpo_retr(0, sd);
  1729. fd=sd->fd;
  1730. WFIFOHEAD(fd, packet_len(0x1b3));
  1731. WFIFOW(fd,0)=0x1b3;
  1732. strncpy((char*)WFIFOP(fd,2),image,64);
  1733. WFIFOB(fd,66)=type;
  1734. WFIFOSET(fd,packet_len(0x1b3));
  1735. return 0;
  1736. }
  1737. /*==========================================
  1738. * Fills in card data from the given item and into the buffer. [Skotlex]
  1739. *------------------------------------------*/
  1740. static void clif_addcards(unsigned char* buf, struct item* item)
  1741. {
  1742. int i=0,j;
  1743. if( item == NULL ) { //Blank data
  1744. WBUFW(buf,0) = 0;
  1745. WBUFW(buf,2) = 0;
  1746. WBUFW(buf,4) = 0;
  1747. WBUFW(buf,6) = 0;
  1748. return;
  1749. }
  1750. if( item->card[0] == CARD0_PET ) { //pet eggs
  1751. WBUFW(buf,0) = 0;
  1752. WBUFW(buf,2) = 0;
  1753. WBUFW(buf,4) = 0;
  1754. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1755. return;
  1756. }
  1757. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1758. WBUFW(buf,0) = item->card[0];
  1759. WBUFW(buf,2) = item->card[1];
  1760. WBUFW(buf,4) = item->card[2];
  1761. WBUFW(buf,6) = item->card[3];
  1762. return;
  1763. }
  1764. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1765. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1766. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1767. //Normal items.
  1768. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1769. WBUFW(buf,0) = j;
  1770. else
  1771. WBUFW(buf,0) = item->card[i];
  1772. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1773. WBUFW(buf,2) = j;
  1774. else
  1775. WBUFW(buf,2) = item->card[i];
  1776. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1777. WBUFW(buf,4) = j;
  1778. else
  1779. WBUFW(buf,4) = item->card[i];
  1780. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1781. WBUFW(buf,6) = j;
  1782. else
  1783. WBUFW(buf,6) = item->card[i];
  1784. }
  1785. /*==========================================
  1786. *
  1787. *------------------------------------------*/
  1788. int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1789. {
  1790. int fd;
  1791. nullpo_retr(0, sd);
  1792. fd = sd->fd;
  1793. if (!session_isActive(fd)) //Sasuke-
  1794. return 0;
  1795. WFIFOHEAD(fd,packet_len(0xa0));
  1796. if(fail) {
  1797. WFIFOW(fd,0)=0xa0;
  1798. WFIFOW(fd,2)=n+2;
  1799. WFIFOW(fd,4)=amount;
  1800. WFIFOW(fd,6)=0;
  1801. WFIFOB(fd,8)=0;
  1802. WFIFOB(fd,9)=0;
  1803. WFIFOB(fd,10)=0;
  1804. WFIFOW(fd,11)=0;
  1805. WFIFOW(fd,13)=0;
  1806. WFIFOW(fd,15)=0;
  1807. WFIFOW(fd,17)=0;
  1808. WFIFOW(fd,19)=0;
  1809. WFIFOB(fd,21)=0;
  1810. WFIFOB(fd,22)=fail;
  1811. } else {
  1812. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1813. return 1;
  1814. WFIFOW(fd,0)=0xa0;
  1815. WFIFOW(fd,2)=n+2;
  1816. WFIFOW(fd,4)=amount;
  1817. if (sd->inventory_data[n]->view_id > 0)
  1818. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1819. else
  1820. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1821. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1822. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1823. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1824. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1825. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1826. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1827. WFIFOB(fd,22)=fail;
  1828. }
  1829. WFIFOSET(fd,packet_len(0xa0));
  1830. return 0;
  1831. }
  1832. /*==========================================
  1833. *
  1834. *------------------------------------------*/
  1835. int clif_delitem(struct map_session_data *sd,int n,int amount)
  1836. {
  1837. int fd;
  1838. nullpo_retr(0, sd);
  1839. fd=sd->fd;
  1840. WFIFOHEAD(fd, packet_len(0xaf));
  1841. WFIFOW(fd,0)=0xaf;
  1842. WFIFOW(fd,2)=n+2;
  1843. WFIFOW(fd,4)=amount;
  1844. WFIFOSET(fd,packet_len(0xaf));
  1845. return 0;
  1846. }
  1847. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1848. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1849. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1850. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1851. {
  1852. if (id->view_id > 0)
  1853. WBUFW(buf,n)=id->view_id;
  1854. else
  1855. WBUFW(buf,n)=i->nameid;
  1856. WBUFB(buf,n+2)=itemtype(id->type);
  1857. WBUFB(buf,n+3)=i->identify;
  1858. if (equip >= 0) { //Equippable item
  1859. WBUFW(buf,n+4)=equip;
  1860. WBUFW(buf,n+6)=i->equip;
  1861. WBUFB(buf,n+8)=i->attribute;
  1862. WBUFB(buf,n+9)=i->refine;
  1863. } else { //Stackable item.
  1864. WBUFW(buf,n+4)=i->amount;
  1865. if (equip == -2 && id->equip == EQP_AMMO)
  1866. WBUFW(buf,n+6)=EQP_AMMO;
  1867. else
  1868. WBUFW(buf,n+6)=0;
  1869. }
  1870. }
  1871. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1872. void clif_inventorylist(struct map_session_data *sd)
  1873. {
  1874. int i,n,ne,fd = sd->fd,arrow=-1;
  1875. unsigned char *buf;
  1876. unsigned char bufe[MAX_INVENTORY*20+4];
  1877. #if PACKETVER < 5
  1878. const int s = 10; //Entry size.
  1879. #else
  1880. const int s = 18;
  1881. #endif
  1882. WFIFOHEAD(fd, MAX_INVENTORY * s + 4);
  1883. buf = WFIFOP(fd,0);
  1884. for(i=0,n=0,ne=0;i<MAX_INVENTORY;i++){
  1885. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1886. continue;
  1887. if(!itemdb_isstackable2(sd->inventory_data[i]))
  1888. { //Non-stackable (Equippable)
  1889. WBUFW(bufe,ne*20+4)=i+2;
  1890. clif_item_sub(bufe, ne*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1891. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.inventory[i]);
  1892. ne++;
  1893. } else { //Stackable.
  1894. WBUFW(buf,n*s+4)=i+2;
  1895. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1896. if (sd->inventory_data[i]->equip == EQP_AMMO &&
  1897. sd->status.inventory[i].equip)
  1898. arrow=i;
  1899. #if PACKETVER >= 5
  1900. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1901. #endif
  1902. n++;
  1903. }
  1904. }
  1905. if (n) {
  1906. #if PACKETVER < 5
  1907. WBUFW(buf,0)=0xa3;
  1908. #else
  1909. WBUFW(buf,0)=0x1ee;
  1910. #endif
  1911. WBUFW(buf,2)=4+n*s;
  1912. WFIFOSET(fd,WFIFOW(fd,2));
  1913. }
  1914. if(arrow >= 0)
  1915. clif_arrowequip(sd,arrow);
  1916. if(ne){
  1917. WBUFW(bufe,0)=0xa4;
  1918. WBUFW(bufe,2)=4+ne*20;
  1919. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1920. }
  1921. }
  1922. //Required when items break/get-repaired. Only sends equippable item list.
  1923. void clif_equiplist(struct map_session_data *sd)
  1924. {
  1925. int i,n,fd = sd->fd;
  1926. unsigned char *buf;
  1927. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  1928. buf = WFIFOP(fd,0);
  1929. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1930. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1931. continue;
  1932. if(itemdb_isstackable2(sd->inventory_data[i]))
  1933. continue;
  1934. //Equippable
  1935. WBUFW(buf,n*20+4)=i+2;
  1936. clif_item_sub(buf, n*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1937. clif_addcards(WBUFP(buf, n*20+16), &sd->status.inventory[i]);
  1938. n++;
  1939. }
  1940. if (n) {
  1941. WBUFW(buf,0)=0xa4;
  1942. WBUFW(buf,2)=4+n*20;
  1943. WFIFOSET(fd,WFIFOW(fd,2));
  1944. }
  1945. }
  1946. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1947. void clif_storagelist(struct map_session_data *sd,struct storage *stor)
  1948. {
  1949. struct item_data *id;
  1950. int i,n,ne,fd=sd->fd;
  1951. unsigned char *buf;
  1952. unsigned char bufe[MAX_STORAGE*20+4];
  1953. #if PACKETVER < 5
  1954. const int s = 10; //Entry size.
  1955. #else
  1956. const int s = 18;
  1957. #endif
  1958. WFIFOHEAD(fd,MAX_STORAGE * s + 4);
  1959. buf = WFIFOP(fd,0);
  1960. for(i=0,n=0,ne=0;i<MAX_STORAGE;i++){
  1961. if(stor->storage_[i].nameid<=0)
  1962. continue;
  1963. id = itemdb_search(stor->storage_[i].nameid);
  1964. if(!itemdb_isstackable2(id))
  1965. { //Equippable
  1966. WBUFW(bufe,ne*20+4)=i+1;
  1967. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  1968. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  1969. ne++;
  1970. } else { //Stackable
  1971. WBUFW(buf,n*s+4)=i+1;
  1972. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  1973. #if PACKETVER >= 5
  1974. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  1975. #endif
  1976. n++;
  1977. }
  1978. }
  1979. if(n){
  1980. #if PACKETVER < 5
  1981. WBUFW(buf,0)=0xa5;
  1982. #else
  1983. WBUFW(buf,0)=0x1f0;
  1984. #endif
  1985. WBUFW(buf,2)=4+n*s;
  1986. WFIFOSET(fd,WFIFOW(fd,2));
  1987. }
  1988. if(ne){
  1989. WBUFW(bufe,0)=0xa6;
  1990. WBUFW(bufe,2)=4+ne*20;
  1991. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1992. }
  1993. }
  1994. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1995. void clif_guildstoragelist(struct map_session_data *sd,struct guild_storage *stor)
  1996. {
  1997. struct item_data *id;
  1998. int i,n,ne,fd=sd->fd;
  1999. unsigned char *buf;
  2000. unsigned char bufe[MAX_GUILD_STORAGE*20+4];
  2001. #if PACKETVER < 5
  2002. const int s = 10; //Entry size.
  2003. #else
  2004. const int s = 18;
  2005. #endif
  2006. WFIFOHEAD(fd,MAX_GUILD_STORAGE * s + 4);
  2007. buf = WFIFOP(fd,0);
  2008. for(i=0,n=0,ne=0;i<MAX_GUILD_STORAGE;i++){
  2009. if(stor->storage_[i].nameid<=0)
  2010. continue;
  2011. id = itemdb_search(stor->storage_[i].nameid);
  2012. if(!itemdb_isstackable2(id))
  2013. { //Equippable
  2014. WBUFW(bufe,ne*20+4)=i+1;
  2015. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  2016. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  2017. ne++;
  2018. } else { //Stackable
  2019. WBUFW(buf,n*s+4)=i+1;
  2020. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  2021. #if PACKETVER >= 5
  2022. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  2023. #endif
  2024. n++;
  2025. }
  2026. }
  2027. if(n){
  2028. #if PACKETVER < 5
  2029. WBUFW(buf,0)=0xa5;
  2030. #else
  2031. WBUFW(buf,0)=0x1f0;
  2032. #endif
  2033. WBUFW(buf,2)=4+n*s;
  2034. WFIFOSET(fd,WFIFOW(fd,2));
  2035. }
  2036. if(ne){
  2037. WBUFW(bufe,0)=0xa6;
  2038. WBUFW(bufe,2)=4+ne*20;
  2039. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2040. }
  2041. }
  2042. void clif_cartlist(struct map_session_data *sd)
  2043. {
  2044. struct item_data *id;
  2045. int i,n,ne,fd=sd->fd;
  2046. unsigned char *buf;
  2047. unsigned char bufe[MAX_CART*20+4];
  2048. #if PACKETVER < 5
  2049. const int s = 10; //Entry size.
  2050. #else
  2051. const int s = 18;
  2052. #endif
  2053. WFIFOHEAD(fd, MAX_CART * s + 4);
  2054. buf = WFIFOP(fd,0);
  2055. for(i=0,n=0,ne=0;i<MAX_CART;i++){
  2056. if(sd->status.cart[i].nameid<=0)
  2057. continue;
  2058. id = itemdb_search(sd->status.cart[i].nameid);
  2059. if(!itemdb_isstackable2(id))
  2060. { //Equippable
  2061. WBUFW(bufe,ne*20+4)=i+2;
  2062. clif_item_sub(bufe, ne*20+6, &sd->status.cart[i], id, id->equip);
  2063. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.cart[i]);
  2064. ne++;
  2065. } else { //Stackable
  2066. WBUFW(buf,n*s+4)=i+2;
  2067. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  2068. #if PACKETVER >= 5
  2069. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  2070. #endif
  2071. n++;
  2072. }
  2073. }
  2074. if(n){
  2075. #if PACKETVER < 5
  2076. WBUFW(buf,0)=0x123;
  2077. #else
  2078. WBUFW(buf,0)=0x1ef;
  2079. #endif
  2080. WBUFW(buf,2)=4+n*s;
  2081. WFIFOSET(fd,WFIFOW(fd,2));
  2082. }
  2083. if(ne){
  2084. WBUFW(bufe,0)=0x122;
  2085. WBUFW(bufe,2)=4+ne*20;
  2086. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2087. }
  2088. return;
  2089. }
  2090. /// Client behaviour:
  2091. /// Closes the cart storage and removes all it's items from memory.
  2092. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2093. void clif_clearcart(int fd)
  2094. {
  2095. WFIFOHEAD(fd, packet_len(0x12b));
  2096. WFIFOW(fd,0) = 0x12b;
  2097. }
  2098. // Guild XY locators [Valaris]
  2099. int clif_guild_xy(struct map_session_data *sd)
  2100. {
  2101. unsigned char buf[10];
  2102. nullpo_retr(0, sd);
  2103. WBUFW(buf,0)=0x1eb;
  2104. WBUFL(buf,2)=sd->status.account_id;
  2105. WBUFW(buf,6)=sd->bl.x;
  2106. WBUFW(buf,8)=sd->bl.y;
  2107. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2108. return 0;
  2109. }
  2110. /*==========================================
  2111. * Sends x/y dot to a single fd. [Skotlex]
  2112. *------------------------------------------*/
  2113. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  2114. {
  2115. WFIFOHEAD(fd,packet_len(0x1eb));
  2116. WFIFOW(fd,0)=0x1eb;
  2117. WFIFOL(fd,2)=sd->status.account_id;
  2118. WFIFOW(fd,6)=sd->bl.x;
  2119. WFIFOW(fd,8)=sd->bl.y;
  2120. WFIFOSET(fd,packet_len(0x1eb));
  2121. return 0;
  2122. }
  2123. // Guild XY locators [Valaris]
  2124. int clif_guild_xy_remove(struct map_session_data *sd)
  2125. {
  2126. unsigned char buf[10];
  2127. nullpo_retr(0, sd);
  2128. WBUFW(buf,0)=0x1eb;
  2129. WBUFL(buf,2)=sd->status.account_id;
  2130. WBUFW(buf,6)=-1;
  2131. WBUFW(buf,8)=-1;
  2132. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2133. return 0;
  2134. }
  2135. /*==========================================
  2136. * ステータスを送りつける
  2137. * 表示専用数字はこの中で計算して送る
  2138. *------------------------------------------*/
  2139. int clif_updatestatus(struct map_session_data *sd,int type)
  2140. {
  2141. int fd,len=8;
  2142. nullpo_retr(0, sd);
  2143. fd=sd->fd;
  2144. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2145. return 0;
  2146. WFIFOHEAD(fd, 14);
  2147. WFIFOW(fd,0)=0xb0;
  2148. WFIFOW(fd,2)=type;
  2149. switch(type){
  2150. // 00b0
  2151. case SP_WEIGHT:
  2152. pc_updateweightstatus(sd);
  2153. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2154. WFIFOW(fd,2)=type;
  2155. WFIFOL(fd,4)=sd->weight;
  2156. break;
  2157. case SP_MAXWEIGHT:
  2158. WFIFOL(fd,4)=sd->max_weight;
  2159. break;
  2160. case SP_SPEED:
  2161. WFIFOL(fd,4)=sd->battle_status.speed;
  2162. break;
  2163. case SP_BASELEVEL:
  2164. WFIFOL(fd,4)=sd->status.base_level;
  2165. break;
  2166. case SP_JOBLEVEL:
  2167. WFIFOL(fd,4)=sd->status.job_level;
  2168. break;
  2169. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2170. WFIFOL(fd,4)=sd->status.karma;
  2171. break;
  2172. case SP_MANNER:
  2173. WFIFOL(fd,4)=sd->status.manner;
  2174. clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
  2175. break;
  2176. case SP_STATUSPOINT:
  2177. WFIFOL(fd,4)=sd->status.status_point;
  2178. break;
  2179. case SP_SKILLPOINT:
  2180. WFIFOL(fd,4)=sd->status.skill_point;
  2181. break;
  2182. case SP_HIT:
  2183. WFIFOL(fd,4)=sd->battle_status.hit;
  2184. break;
  2185. case SP_FLEE1:
  2186. WFIFOL(fd,4)=sd->battle_status.flee;
  2187. break;
  2188. case SP_FLEE2:
  2189. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2190. break;
  2191. case SP_MAXHP:
  2192. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2193. break;
  2194. case SP_MAXSP:
  2195. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2196. break;
  2197. case SP_HP:
  2198. WFIFOL(fd,4)=sd->battle_status.hp;
  2199. if (battle_config.disp_hpmeter)
  2200. clif_hpmeter(sd);
  2201. if (!battle_config.party_hp_mode && sd->status.party_id)
  2202. clif_party_hp(sd);
  2203. break;
  2204. case SP_SP:
  2205. WFIFOL(fd,4)=sd->battle_status.sp;
  2206. break;
  2207. case SP_ASPD:
  2208. WFIFOL(fd,4)=sd->battle_status.amotion;
  2209. break;
  2210. case SP_ATK1:
  2211. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw->atk;
  2212. break;
  2213. case SP_DEF1:
  2214. WFIFOL(fd,4)=sd->battle_status.def;
  2215. break;
  2216. case SP_MDEF1:
  2217. WFIFOL(fd,4)=sd->battle_status.mdef;
  2218. break;
  2219. case SP_ATK2:
  2220. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw->atk2;
  2221. break;
  2222. case SP_DEF2:
  2223. WFIFOL(fd,4)=sd->battle_status.def2;
  2224. break;
  2225. case SP_MDEF2:
  2226. //negative check (in case you have something like Berserk active)
  2227. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2228. if (len < 0) len = 0;
  2229. WFIFOL(fd,4)= len;
  2230. len = 8;
  2231. break;
  2232. case SP_CRITICAL:
  2233. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2234. break;
  2235. case SP_MATK1:
  2236. WFIFOL(fd,4)=sd->battle_status.matk_max;
  2237. break;
  2238. case SP_MATK2:
  2239. WFIFOL(fd,4)=sd->battle_status.matk_min;
  2240. break;
  2241. case SP_ZENY:
  2242. WFIFOW(fd,0)=0xb1;
  2243. WFIFOL(fd,4)=sd->status.zeny;
  2244. break;
  2245. case SP_BASEEXP:
  2246. WFIFOW(fd,0)=0xb1;
  2247. WFIFOL(fd,4)=sd->status.base_exp;
  2248. break;
  2249. case SP_JOBEXP:
  2250. WFIFOW(fd,0)=0xb1;
  2251. WFIFOL(fd,4)=sd->status.job_exp;
  2252. break;
  2253. case SP_NEXTBASEEXP:
  2254. WFIFOW(fd,0)=0xb1;
  2255. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2256. break;
  2257. case SP_NEXTJOBEXP:
  2258. WFIFOW(fd,0)=0xb1;
  2259. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2260. break;
  2261. // 00be 終了
  2262. case SP_USTR:
  2263. case SP_UAGI:
  2264. case SP_UVIT:
  2265. case SP_UINT:
  2266. case SP_UDEX:
  2267. case SP_ULUK:
  2268. WFIFOW(fd,0)=0xbe;
  2269. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2270. len=5;
  2271. break;
  2272. // 013a 終了
  2273. case SP_ATTACKRANGE:
  2274. WFIFOW(fd,0)=0x13a;
  2275. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2276. len=4;
  2277. break;
  2278. // 0141 終了
  2279. case SP_STR:
  2280. WFIFOW(fd,0)=0x141;
  2281. WFIFOL(fd,2)=type;
  2282. WFIFOL(fd,6)=sd->status.str;
  2283. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2284. len=14;
  2285. break;
  2286. case SP_AGI:
  2287. WFIFOW(fd,0)=0x141;
  2288. WFIFOL(fd,2)=type;
  2289. WFIFOL(fd,6)=sd->status.agi;
  2290. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2291. len=14;
  2292. break;
  2293. case SP_VIT:
  2294. WFIFOW(fd,0)=0x141;
  2295. WFIFOL(fd,2)=type;
  2296. WFIFOL(fd,6)=sd->status.vit;
  2297. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2298. len=14;
  2299. break;
  2300. case SP_INT:
  2301. WFIFOW(fd,0)=0x141;
  2302. WFIFOL(fd,2)=type;
  2303. WFIFOL(fd,6)=sd->status.int_;
  2304. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2305. len=14;
  2306. break;
  2307. case SP_DEX:
  2308. WFIFOW(fd,0)=0x141;
  2309. WFIFOL(fd,2)=type;
  2310. WFIFOL(fd,6)=sd->status.dex;
  2311. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2312. len=14;
  2313. break;
  2314. case SP_LUK:
  2315. WFIFOW(fd,0)=0x141;
  2316. WFIFOL(fd,2)=type;
  2317. WFIFOL(fd,6)=sd->status.luk;
  2318. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2319. len=14;
  2320. break;
  2321. case SP_CARTINFO:
  2322. WFIFOW(fd,0)=0x121;
  2323. WFIFOW(fd,2)=sd->cart_num;
  2324. WFIFOW(fd,4)=MAX_CART;
  2325. WFIFOL(fd,6)=sd->cart_weight;
  2326. WFIFOL(fd,10)=battle_config.max_cart_weight;
  2327. len=14;
  2328. break;
  2329. default:
  2330. if(battle_config.error_log)
  2331. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2332. return 1;
  2333. }
  2334. WFIFOSET(fd,len);
  2335. return 0;
  2336. }
  2337. int clif_changestatus(struct block_list *bl,int type,int val)
  2338. {
  2339. unsigned char buf[12];
  2340. struct map_session_data *sd = NULL;
  2341. nullpo_retr(0, bl);
  2342. if(bl->type == BL_PC)
  2343. sd = (struct map_session_data *)bl;
  2344. if(sd){
  2345. WBUFW(buf,0)=0x1ab;
  2346. WBUFL(buf,2)=bl->id;
  2347. WBUFW(buf,6)=type;
  2348. switch(type){
  2349. case SP_MANNER:
  2350. WBUFL(buf,8)=val;
  2351. break;
  2352. default:
  2353. if(battle_config.error_log)
  2354. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2355. return 1;
  2356. }
  2357. clif_send(buf,packet_len(0x1ab),bl,AREA_WOS);
  2358. }
  2359. return 0;
  2360. }
  2361. /*==========================================
  2362. *
  2363. *------------------------------------------*/
  2364. void clif_changelook(struct block_list *bl,int type,int val)
  2365. {
  2366. unsigned char buf[16];
  2367. struct map_session_data* sd = NULL;
  2368. struct view_data* vd;
  2369. nullpo_retv(bl);
  2370. BL_CAST(BL_PC, bl, sd);
  2371. vd = status_get_viewdata(bl);
  2372. //nullpo_ret(vd);
  2373. if( vd ) //temp hack to let Warp Portal change appearance
  2374. switch(type)
  2375. {
  2376. case LOOK_WEAPON:
  2377. if (sd)
  2378. {
  2379. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2380. val = vd->weapon;
  2381. }
  2382. else vd->weapon = val;
  2383. break;
  2384. case LOOK_SHIELD:
  2385. if (sd)
  2386. {
  2387. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2388. val = vd->shield;
  2389. }
  2390. else vd->shield = val;
  2391. break;
  2392. case LOOK_BASE:
  2393. vd->class_ = val;
  2394. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2395. vd->weapon = vd->shield = 0;
  2396. if (vd->cloth_color && (
  2397. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2398. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2399. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2400. ))
  2401. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2402. break;
  2403. case LOOK_HAIR:
  2404. vd->hair_style = val;
  2405. break;
  2406. case LOOK_HEAD_BOTTOM:
  2407. vd->head_bottom = val;
  2408. break;
  2409. case LOOK_HEAD_TOP:
  2410. vd->head_top = val;
  2411. break;
  2412. case LOOK_HEAD_MID:
  2413. vd->head_mid = val;
  2414. break;
  2415. case LOOK_HAIR_COLOR:
  2416. vd->hair_color = val;
  2417. break;
  2418. case LOOK_CLOTHES_COLOR:
  2419. if (val && (
  2420. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2421. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2422. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2423. ))
  2424. val = 0;
  2425. vd->cloth_color = val;
  2426. break;
  2427. case LOOK_SHOES:
  2428. #if PACKETVER > 3
  2429. if (sd) {
  2430. int n;
  2431. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2432. if(sd->inventory_data[n]->view_id > 0)
  2433. val = sd->inventory_data[n]->view_id;
  2434. else
  2435. val = sd->status.inventory[n].nameid;
  2436. }
  2437. val = 0;
  2438. }
  2439. #endif
  2440. //Shoes? No packet uses this....
  2441. break;
  2442. }
  2443. #if PACKETVER < 4
  2444. WBUFW(buf,0)=0xc3;
  2445. WBUFL(buf,2)=bl->id;
  2446. WBUFB(buf,6)=type;
  2447. WBUFB(buf,7)=val;
  2448. clif_send(buf,packet_len(0xc3),bl,AREA);
  2449. #else
  2450. WBUFW(buf,0)=0x1d7;
  2451. WBUFL(buf,2)=bl->id;
  2452. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2453. WBUFB(buf,6)=LOOK_WEAPON;
  2454. WBUFW(buf,7)=vd->weapon;
  2455. WBUFW(buf,9)=vd->shield;
  2456. } else {
  2457. WBUFB(buf,6)=type;
  2458. WBUFW(buf,7)=val;
  2459. WBUFW(buf,9)=0;
  2460. }
  2461. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2462. #endif
  2463. }
  2464. //Sends a change-base-look packet required for traps as they are triggered.
  2465. void clif_changetraplook(struct block_list *bl,int val)
  2466. {
  2467. unsigned char buf[32];
  2468. #if PACKETVER < 4
  2469. WBUFW(buf,0)=0xc3;
  2470. WBUFL(buf,2)=bl->id;
  2471. WBUFB(buf,6)=LOOK_BASE;
  2472. WBUFB(buf,7)=val;
  2473. clif_send(buf,packet_len(0xc3),bl,AREA);
  2474. #else
  2475. WBUFW(buf,0)=0x1d7;
  2476. WBUFL(buf,2)=bl->id;
  2477. WBUFB(buf,6)=LOOK_BASE;
  2478. WBUFW(buf,7)=val;
  2479. WBUFW(buf,9)=0;
  2480. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2481. #endif
  2482. }
  2483. //For the stupid cloth-dye bug. Resends the given view data
  2484. //to the area specified by bl.
  2485. void clif_refreshlook(struct block_list *bl,int id,int type,int val,int area)
  2486. {
  2487. unsigned char buf[32];
  2488. #if PACKETVER < 4
  2489. WBUFW(buf,0)=0xc3;
  2490. WBUFL(buf,2)=id;
  2491. WBUFB(buf,6)=type;
  2492. WBUFB(buf,7)=val;
  2493. clif_send(buf,packet_len(0xc3),bl,area);
  2494. #else
  2495. WBUFW(buf,0)=0x1d7;
  2496. WBUFL(buf,2)=id;
  2497. WBUFB(buf,6)=type;
  2498. WBUFW(buf,7)=val;
  2499. WBUFW(buf,9)=0;
  2500. clif_send(buf,packet_len(0x1d7),bl,area);
  2501. #endif
  2502. return;
  2503. }
  2504. /*==========================================
  2505. *
  2506. *------------------------------------------*/
  2507. int clif_initialstatus(struct map_session_data *sd)
  2508. {
  2509. int fd;
  2510. unsigned char *buf;
  2511. nullpo_retr(0, sd);
  2512. fd=sd->fd;
  2513. WFIFOHEAD(fd,packet_len(0xbd));
  2514. buf=WFIFOP(fd,0);
  2515. WBUFW(buf,0)=0xbd;
  2516. WBUFW(buf,2)=min(sd->status.status_point, SHRT_MAX);
  2517. WBUFB(buf,4)=min(sd->status.str, UCHAR_MAX);
  2518. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2519. WBUFB(buf,6)=min(sd->status.agi, UCHAR_MAX);
  2520. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2521. WBUFB(buf,8)=min(sd->status.vit, UCHAR_MAX);
  2522. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2523. WBUFB(buf,10)=min(sd->status.int_, UCHAR_MAX);
  2524. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2525. WBUFB(buf,12)=min(sd->status.dex, UCHAR_MAX);
  2526. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2527. WBUFB(buf,14)=min(sd->status.luk, UCHAR_MAX);
  2528. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2529. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw->atk;
  2530. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw->atk2; //atk bonus
  2531. WBUFW(buf,20) = sd->battle_status.matk_max;
  2532. WBUFW(buf,22) = sd->battle_status.matk_min;
  2533. WBUFW(buf,24) = sd->battle_status.def; // def
  2534. WBUFW(buf,26) = sd->battle_status.def2;
  2535. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2536. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2537. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2538. WBUFW(buf,30) = fd;
  2539. fd = sd->fd;
  2540. WBUFW(buf,32) = sd->battle_status.hit;
  2541. WBUFW(buf,34) = sd->battle_status.flee;
  2542. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2543. WBUFW(buf,38) = sd->battle_status.cri/10;
  2544. WBUFW(buf,40) = sd->status.karma;
  2545. WBUFW(buf,42) = sd->status.manner;
  2546. WFIFOSET(fd,packet_len(0xbd));
  2547. clif_updatestatus(sd,SP_STR);
  2548. clif_updatestatus(sd,SP_AGI);
  2549. clif_updatestatus(sd,SP_VIT);
  2550. clif_updatestatus(sd,SP_INT);
  2551. clif_updatestatus(sd,SP_DEX);
  2552. clif_updatestatus(sd,SP_LUK);
  2553. clif_updatestatus(sd,SP_ATTACKRANGE);
  2554. clif_updatestatus(sd,SP_ASPD);
  2555. return 0;
  2556. }
  2557. /*==========================================
  2558. *矢装備
  2559. *------------------------------------------*/
  2560. int clif_arrowequip(struct map_session_data *sd,int val)
  2561. {
  2562. int fd;
  2563. nullpo_retr(0, sd);
  2564. pc_stop_attack(sd); // [Valaris]
  2565. fd=sd->fd;
  2566. WFIFOHEAD(fd, packet_len(0x013c));
  2567. WFIFOW(fd,0)=0x013c;
  2568. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2569. WFIFOSET(fd,packet_len(0x013c));
  2570. return 0;
  2571. }
  2572. /// Ammunition action message.
  2573. /// type=0 : MsgStringTable[242]="Please equip the proper ammunition first."
  2574. /// type=1 : MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2575. /// type=2 : MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2576. /// type=3 : assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2577. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2578. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2579. int clif_arrow_fail(struct map_session_data *sd,int type)
  2580. {
  2581. int fd;
  2582. nullpo_retr(0, sd);
  2583. fd=sd->fd;
  2584. WFIFOHEAD(fd, packet_len(0x013b));
  2585. WFIFOW(fd,0)=0x013b;
  2586. WFIFOW(fd,2)=type;
  2587. WFIFOSET(fd,packet_len(0x013b));
  2588. return 0;
  2589. }
  2590. /*==========================================
  2591. * 作成可能 矢リスト送信
  2592. *------------------------------------------*/
  2593. int clif_arrow_create_list(struct map_session_data *sd)
  2594. {
  2595. int i, c, j;
  2596. int fd;
  2597. nullpo_retr(0, sd);
  2598. fd = sd->fd;
  2599. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2600. WFIFOW(fd,0) = 0x1ad;
  2601. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2602. if (skill_arrow_db[i].nameid > 0 &&
  2603. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2604. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2605. {
  2606. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2607. WFIFOW(fd,c*2+4) = j;
  2608. else
  2609. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2610. c++;
  2611. }
  2612. }
  2613. WFIFOW(fd,2) = c*2+4;
  2614. WFIFOSET(fd, WFIFOW(fd,2));
  2615. if (c > 0) {
  2616. sd->menuskill_id = AC_MAKINGARROW;
  2617. sd->menuskill_val = c;
  2618. }
  2619. return 0;
  2620. }
  2621. /*==========================================
  2622. *
  2623. *------------------------------------------*/
  2624. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2625. {
  2626. int fd;
  2627. nullpo_retr(0, sd);
  2628. fd=sd->fd;
  2629. WFIFOHEAD(fd,packet_len(0xbc));
  2630. WFIFOW(fd,0)=0xbc;
  2631. WFIFOW(fd,2)=type;
  2632. WFIFOB(fd,4)=ok;
  2633. WFIFOB(fd,5)=val;
  2634. WFIFOSET(fd,packet_len(0xbc));
  2635. return 0;
  2636. }
  2637. /*==========================================
  2638. *
  2639. *------------------------------------------*/
  2640. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2641. {
  2642. int fd;
  2643. nullpo_retr(0, sd);
  2644. fd=sd->fd;
  2645. WFIFOHEAD(fd,packet_len(0xaa));
  2646. WFIFOW(fd,0)=0xaa;
  2647. WFIFOW(fd,2)=n+2;
  2648. WFIFOW(fd,4)=pos;
  2649. WFIFOB(fd,6)=ok;
  2650. WFIFOSET(fd,packet_len(0xaa));
  2651. return 0;
  2652. }
  2653. /*==========================================
  2654. *
  2655. *------------------------------------------*/
  2656. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2657. {
  2658. int fd;
  2659. nullpo_retr(0, sd);
  2660. fd=sd->fd;
  2661. WFIFOHEAD(fd,packet_len(0xac));
  2662. WFIFOW(fd,0)=0xac;
  2663. WFIFOW(fd,2)=n+2;
  2664. WFIFOW(fd,4)=pos;
  2665. WFIFOB(fd,6)=ok;
  2666. WFIFOSET(fd,packet_len(0xac));
  2667. return 0;
  2668. }
  2669. /*==========================================
  2670. *
  2671. *------------------------------------------*/
  2672. int clif_misceffect(struct block_list* bl,int type)
  2673. {
  2674. unsigned char buf[32];
  2675. nullpo_retr(0, bl);
  2676. WBUFW(buf,0) = 0x19b;
  2677. WBUFL(buf,2) = bl->id;
  2678. WBUFL(buf,6) = type;
  2679. clif_send(buf,packet_len(0x19b),bl,AREA);
  2680. return 0;
  2681. }
  2682. int clif_misceffect2(struct block_list *bl, int type)
  2683. {
  2684. unsigned char buf[24];
  2685. nullpo_retr(0, bl);
  2686. memset(buf, 0, packet_len(0x1f3));
  2687. WBUFW(buf,0) = 0x1f3;
  2688. WBUFL(buf,2) = bl->id;
  2689. WBUFL(buf,6) = type;
  2690. clif_send(buf, packet_len(0x1f3), bl, AREA);
  2691. return 0;
  2692. }
  2693. /*==========================================
  2694. * 表示オプション変更
  2695. *------------------------------------------*/
  2696. int clif_changeoption(struct block_list* bl)
  2697. {
  2698. unsigned char buf[32];
  2699. struct status_change *sc;
  2700. nullpo_retr(0, bl);
  2701. sc = status_get_sc(bl);
  2702. if (!sc) return 0; //How can an option change if there's no sc?
  2703. #if PACKETVER >= 7
  2704. WBUFW(buf,0) = 0x229;
  2705. WBUFL(buf,2) = bl->id;
  2706. WBUFW(buf,6) = sc->opt1;
  2707. WBUFW(buf,8) = sc->opt2;
  2708. WBUFL(buf,10) = sc->option;
  2709. WBUFB(buf,14) = 0; // PK???
  2710. if(disguised(bl)) {
  2711. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2712. WBUFL(buf,2) = -bl->id;
  2713. clif_send(buf,packet_len(0x229),bl,SELF);
  2714. WBUFL(buf,2) = bl->id;
  2715. WBUFL(buf,10) = OPTION_INVISIBLE;
  2716. clif_send(buf,packet_len(0x229),bl,SELF);
  2717. } else
  2718. clif_send(buf,packet_len(0x229),bl,AREA);
  2719. #else
  2720. WBUFW(buf,0) = 0x119;
  2721. WBUFL(buf,2) = bl->id;
  2722. WBUFW(buf,6) = sc->opt1;
  2723. WBUFW(buf,8) = sc->opt2;
  2724. WBUFW(buf,10) = sc->option;
  2725. WBUFB(buf,12) = 0; // ??
  2726. if(disguised(bl)) {
  2727. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2728. WBUFL(buf,2) = -bl->id;
  2729. clif_send(buf,packet_len(0x119),bl,SELF);
  2730. WBUFL(buf,2) = bl->id;
  2731. WBUFW(buf,10) = OPTION_INVISIBLE;
  2732. clif_send(buf,packet_len(0x119),bl,SELF);
  2733. } else
  2734. clif_send(buf,packet_len(0x119),bl,AREA);
  2735. #endif
  2736. return 0;
  2737. }
  2738. int clif_changeoption2(struct block_list* bl)
  2739. {
  2740. unsigned char buf[20];
  2741. struct status_change *sc;
  2742. sc = status_get_sc(bl);
  2743. if (!sc) return 0; //How can an option change if there's no sc?
  2744. WBUFW(buf,0) = 0x28a;
  2745. WBUFL(buf,2) = bl->id;
  2746. WBUFL(buf,6) = sc->option;
  2747. WBUFL(buf,10) = clif_setlevel(status_get_lv(bl));
  2748. WBUFL(buf,14) = sc->opt3;
  2749. if(disguised(bl)) {
  2750. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  2751. WBUFL(buf,2) = -bl->id;
  2752. clif_send(buf,packet_len(0x28a),bl,SELF);
  2753. WBUFL(buf,2) = bl->id;
  2754. WBUFL(buf,6) = OPTION_INVISIBLE;
  2755. clif_send(buf,packet_len(0x28a),bl,SELF);
  2756. } else
  2757. clif_send(buf,packet_len(0x28a),bl,AREA);
  2758. return 0;
  2759. }
  2760. /*==========================================
  2761. *
  2762. *------------------------------------------*/
  2763. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2764. {
  2765. nullpo_retr(0, sd);
  2766. if(!ok) {
  2767. int fd=sd->fd;
  2768. WFIFOHEAD(fd,packet_len(0xa8));
  2769. WFIFOW(fd,0)=0xa8;
  2770. WFIFOW(fd,2)=index+2;
  2771. WFIFOW(fd,4)=amount;
  2772. WFIFOB(fd,6)=ok;
  2773. WFIFOSET(fd,packet_len(0xa8));
  2774. }
  2775. else {
  2776. #if PACKETVER < 3
  2777. int fd=sd->fd;
  2778. WFIFOHEAD(fd,packet_len(0xa8));
  2779. WFIFOW(fd,0)=0xa8;
  2780. WFIFOW(fd,2)=index+2;
  2781. WFIFOW(fd,4)=amount;
  2782. WFIFOB(fd,6)=ok;
  2783. WFIFOSET(fd,packet_len(0xa8));
  2784. #else
  2785. unsigned char buf[32];
  2786. WBUFW(buf,0)=0x1c8;
  2787. WBUFW(buf,2)=index+2;
  2788. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2789. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2790. else
  2791. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2792. WBUFL(buf,6)=sd->bl.id;
  2793. WBUFW(buf,10)=amount;
  2794. WBUFB(buf,12)=ok;
  2795. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2796. #endif
  2797. }
  2798. return 0;
  2799. }
  2800. /*==========================================
  2801. * Inform client whether chatroom creation was successful or not
  2802. * R 00d6 <fail>.B
  2803. *------------------------------------------*/
  2804. void clif_createchat(struct map_session_data* sd, int fail)
  2805. {
  2806. int fd;
  2807. nullpo_retv(sd);
  2808. fd = sd->fd;
  2809. WFIFOHEAD(fd,packet_len(0xd6));
  2810. WFIFOW(fd,0) = 0xd6;
  2811. WFIFOB(fd,2) = fail;
  2812. WFIFOSET(fd,packet_len(0xd6));
  2813. }
  2814. /*==========================================
  2815. * Display a chat above the owner
  2816. * R 00d7 <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <type>.B <title>.?B
  2817. *------------------------------------------*/
  2818. int clif_dispchat(struct chat_data* cd, int fd)
  2819. {
  2820. unsigned char buf[128];
  2821. uint8 type;
  2822. if( cd == NULL || cd->owner == NULL )
  2823. return 1;
  2824. // type - 0: private, 1: public, 2: npc, 3: non-clickable
  2825. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  2826. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  2827. : 1;
  2828. WBUFW(buf, 0) = 0xd7;
  2829. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2830. WBUFL(buf, 4) = cd->owner->id;
  2831. WBUFL(buf, 8) = cd->bl.id;
  2832. WBUFW(buf,12) = cd->limit;
  2833. WBUFW(buf,14) = cd->users;
  2834. WBUFB(buf,16) = type;
  2835. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2836. if( fd ) {
  2837. WFIFOHEAD(fd,WBUFW(buf,2));
  2838. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2839. WFIFOSET(fd,WBUFW(buf,2));
  2840. } else {
  2841. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  2842. }
  2843. return 0;
  2844. }
  2845. /*==========================================
  2846. * Chatroom properties adjustment
  2847. * R 00df <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <pub>.B <title>.?B
  2848. *------------------------------------------*/
  2849. int clif_changechatstatus(struct chat_data* cd)
  2850. {
  2851. unsigned char buf[128];
  2852. if( cd == NULL || cd->usersd[0] == NULL )
  2853. return 1;
  2854. WBUFW(buf, 0) = 0xdf;
  2855. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2856. WBUFL(buf, 4) = cd->usersd[0]->bl.id;
  2857. WBUFL(buf, 8) = cd->bl.id;
  2858. WBUFW(buf,12) = cd->limit;
  2859. WBUFW(buf,14) = cd->users;
  2860. WBUFB(buf,16) = cd->pub;
  2861. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2862. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2863. return 0;
  2864. }
  2865. /*==========================================
  2866. *
  2867. *------------------------------------------*/
  2868. int clif_clearchat(struct chat_data *cd,int fd)
  2869. {
  2870. unsigned char buf[32];
  2871. nullpo_retr(0, cd);
  2872. WBUFW(buf,0) = 0xd8;
  2873. WBUFL(buf,2) = cd->bl.id;
  2874. if( fd ) {
  2875. WFIFOHEAD(fd,packet_len(0xd8));
  2876. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2877. WFIFOSET(fd,packet_len(0xd8));
  2878. } else {
  2879. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  2880. }
  2881. return 0;
  2882. }
  2883. /*==========================================
  2884. *
  2885. *------------------------------------------*/
  2886. int clif_joinchatfail(struct map_session_data *sd,int fail)
  2887. {
  2888. int fd;
  2889. nullpo_retr(0, sd);
  2890. fd = sd->fd;
  2891. WFIFOHEAD(fd,packet_len(0xda));
  2892. WFIFOW(fd,0) = 0xda;
  2893. WFIFOB(fd,2) = fail;
  2894. WFIFOSET(fd,packet_len(0xda));
  2895. return 0;
  2896. }
  2897. /*==========================================
  2898. *
  2899. *------------------------------------------*/
  2900. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2901. {
  2902. int fd;
  2903. int i;
  2904. nullpo_retr(0, sd);
  2905. nullpo_retr(0, cd);
  2906. fd = sd->fd;
  2907. if (!session_isActive(fd))
  2908. return 0;
  2909. WFIFOHEAD(fd, 8 + (28*cd->users));
  2910. WFIFOW(fd, 0) = 0xdb;
  2911. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2912. WFIFOL(fd, 4) = cd->bl.id;
  2913. for (i = 0; i < cd->users; i++) {
  2914. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  2915. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2916. }
  2917. WFIFOSET(fd, WFIFOW(fd, 2));
  2918. return 0;
  2919. }
  2920. /*==========================================
  2921. *
  2922. *------------------------------------------*/
  2923. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2924. {
  2925. unsigned char buf[32];
  2926. nullpo_retr(0, sd);
  2927. nullpo_retr(0, cd);
  2928. WBUFW(buf, 0) = 0x0dc;
  2929. WBUFW(buf, 2) = cd->users;
  2930. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2931. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  2932. return 0;
  2933. }
  2934. /*==========================================
  2935. * Announce the new owner
  2936. * R 00e1 <index>.l <nick>.24B
  2937. *------------------------------------------*/
  2938. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  2939. {
  2940. unsigned char buf[64];
  2941. nullpo_retv(sd);
  2942. nullpo_retv(cd);
  2943. //FIXME: this announces a swap between positions 0 and 1 (probably not what we want) [ultramage]
  2944. //FIXME: aegis sends obviously incorrect packets; need to figure out what to send to display it correctly :X
  2945. //TODO: is it just owner swap, or can it do general-purpose reordering?
  2946. WBUFW(buf, 0) = 0xe1;
  2947. WBUFL(buf, 2) = 1;
  2948. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2949. WBUFW(buf,30) = 0xe1;
  2950. WBUFL(buf,32) = 0;
  2951. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2952. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  2953. }
  2954. /*==========================================
  2955. * Notify about user leaving the chatroom
  2956. * R 00dd <index>.w <nick>.24B <flag>.B
  2957. *------------------------------------------*/
  2958. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  2959. {
  2960. unsigned char buf[32];
  2961. nullpo_retv(sd);
  2962. nullpo_retv(cd);
  2963. WBUFW(buf, 0) = 0xdd;
  2964. WBUFW(buf, 2) = cd->users-1;
  2965. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2966. WBUFB(buf,28) = flag; // 0: left, 1: was kicked
  2967. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  2968. }
  2969. /*==========================================
  2970. * Opens a trade request window from char 'name'
  2971. * R 00e5 <nick>.24B
  2972. *------------------------------------------*/
  2973. void clif_traderequest(struct map_session_data* sd, const char* name)
  2974. {
  2975. int fd;
  2976. nullpo_retv(sd);
  2977. fd = sd->fd;
  2978. WFIFOHEAD(fd,packet_len(0xe5));
  2979. WFIFOW(fd,0) = 0xe5;
  2980. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2981. WFIFOSET(fd,packet_len(0xe5));
  2982. }
  2983. /*==========================================
  2984. * 取り引き要求応答
  2985. *------------------------------------------*/
  2986. void clif_tradestart(struct map_session_data* sd, int type)
  2987. {
  2988. int fd;
  2989. nullpo_retv(sd);
  2990. fd = sd->fd;
  2991. WFIFOHEAD(fd,packet_len(0xe7));
  2992. WFIFOW(fd,0) = 0xe7;
  2993. WFIFOB(fd,2) = type;
  2994. WFIFOSET(fd,packet_len(0xe7));
  2995. }
  2996. /*==========================================
  2997. * 相手方からのアイテム追加
  2998. *------------------------------------------*/
  2999. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3000. {
  3001. int fd;
  3002. nullpo_retv(sd);
  3003. nullpo_retv(tsd);
  3004. fd = tsd->fd;
  3005. WFIFOHEAD(fd,packet_len(0xe9));
  3006. WFIFOW(fd,0) = 0xe9;
  3007. WFIFOL(fd,2) = amount;
  3008. if( index == 0 )
  3009. {
  3010. WFIFOW(fd,6) = 0; // type id
  3011. WFIFOB(fd,8) = 0; //identify flag
  3012. WFIFOB(fd,9) = 0; // attribute
  3013. WFIFOB(fd,10)= 0; //refine
  3014. WFIFOW(fd,11)= 0; //card (4w)
  3015. WFIFOW(fd,13)= 0; //card (4w)
  3016. WFIFOW(fd,15)= 0; //card (4w)
  3017. WFIFOW(fd,17)= 0; //card (4w)
  3018. }
  3019. else
  3020. {
  3021. index -= 2; //index fix
  3022. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3023. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  3024. else
  3025. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  3026. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  3027. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  3028. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  3029. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  3030. }
  3031. WFIFOSET(fd,packet_len(0xe9));
  3032. }
  3033. /*==========================================
  3034. * アイテム追加成功/失敗
  3035. *------------------------------------------*/
  3036. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3037. {
  3038. int fd;
  3039. nullpo_retv(sd);
  3040. fd = sd->fd;
  3041. WFIFOHEAD(fd,packet_len(0xea));
  3042. WFIFOW(fd,0) = 0xea;
  3043. WFIFOW(fd,2) = index;
  3044. WFIFOB(fd,4) = fail;
  3045. WFIFOSET(fd,packet_len(0xea));
  3046. }
  3047. /*==========================================
  3048. * 取り引きok押し
  3049. *------------------------------------------*/
  3050. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3051. {
  3052. int fd;
  3053. nullpo_retv(sd);
  3054. fd = sd->fd;
  3055. WFIFOHEAD(fd,packet_len(0xec));
  3056. WFIFOW(fd,0) = 0xec;
  3057. WFIFOB(fd,2) = fail; // 0=you 1=the other person
  3058. WFIFOSET(fd,packet_len(0xec));
  3059. }
  3060. /*==========================================
  3061. * 取り引きがキャンセルされました
  3062. *------------------------------------------*/
  3063. void clif_tradecancelled(struct map_session_data* sd)
  3064. {
  3065. int fd;
  3066. nullpo_retv(sd);
  3067. fd = sd->fd;
  3068. WFIFOHEAD(fd,packet_len(0xee));
  3069. WFIFOW(fd,0) = 0xee;
  3070. WFIFOSET(fd,packet_len(0xee));
  3071. }
  3072. /*==========================================
  3073. * 取り引き完了
  3074. *------------------------------------------*/
  3075. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3076. {
  3077. int fd;
  3078. nullpo_retv(sd);
  3079. fd = sd->fd;
  3080. WFIFOHEAD(fd,packet_len(0xf0));
  3081. WFIFOW(fd,0) = 0xf0;
  3082. WFIFOB(fd,2) = fail;
  3083. WFIFOSET(fd,packet_len(0xf0));
  3084. }
  3085. /*==========================================
  3086. * カプラ倉庫のアイテム数を更新
  3087. *------------------------------------------*/
  3088. int clif_updatestorageamount(struct map_session_data *sd,struct storage *stor)
  3089. {
  3090. int fd;
  3091. nullpo_retr(0, sd);
  3092. nullpo_retr(0, stor);
  3093. fd=sd->fd;
  3094. WFIFOHEAD(fd,packet_len(0xf2));
  3095. WFIFOW(fd,0) = 0xf2; // update storage amount
  3096. WFIFOW(fd,2) = stor->storage_amount; //items
  3097. WFIFOW(fd,4) = MAX_STORAGE; //items max
  3098. WFIFOSET(fd,packet_len(0xf2));
  3099. return 0;
  3100. }
  3101. /*==========================================
  3102. * カプラ倉庫にアイテムを追加する
  3103. *------------------------------------------*/
  3104. int clif_storageitemadded(struct map_session_data *sd,struct storage *stor,int index,int amount)
  3105. {
  3106. int view,fd;
  3107. nullpo_retr(0, sd);
  3108. nullpo_retr(0, stor);
  3109. fd=sd->fd;
  3110. WFIFOHEAD(fd,packet_len(0xf4));
  3111. WFIFOW(fd,0) =0xf4; // Storage item added
  3112. WFIFOW(fd,2) =index+1; // index
  3113. WFIFOL(fd,4) =amount; // amount
  3114. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3115. WFIFOW(fd,8) =view;
  3116. else
  3117. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3118. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3119. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3120. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3121. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3122. WFIFOSET(fd,packet_len(0xf4));
  3123. return 0;
  3124. }
  3125. /*==========================================
  3126. *
  3127. *------------------------------------------*/
  3128. int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor)
  3129. {
  3130. int fd;
  3131. nullpo_retr(0, sd);
  3132. nullpo_retr(0, stor);
  3133. fd=sd->fd;
  3134. WFIFOHEAD(fd,packet_len(0xf2));
  3135. WFIFOW(fd,0) = 0xf2; // update storage amount
  3136. WFIFOW(fd,2) = stor->storage_amount; //items
  3137. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  3138. WFIFOSET(fd,packet_len(0xf2));
  3139. return 0;
  3140. }
  3141. /*==========================================
  3142. *
  3143. *------------------------------------------*/
  3144. int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount)
  3145. {
  3146. int view,fd;
  3147. nullpo_retr(0, sd);
  3148. nullpo_retr(0, stor);
  3149. fd=sd->fd;
  3150. WFIFOHEAD(fd,packet_len(0xf4));
  3151. WFIFOW(fd,0) =0xf4; // Storage item added
  3152. WFIFOW(fd,2) =index+1; // index
  3153. WFIFOL(fd,4) =amount; // amount
  3154. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3155. WFIFOW(fd,8) =view;
  3156. else
  3157. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3158. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3159. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3160. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3161. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3162. WFIFOSET(fd,packet_len(0xf4));
  3163. return 0;
  3164. }
  3165. /*==========================================
  3166. * カプラ倉庫からアイテムを取り去る
  3167. *------------------------------------------*/
  3168. int clif_storageitemremoved(struct map_session_data *sd,int index,int amount)
  3169. {
  3170. int fd;
  3171. nullpo_retr(0, sd);
  3172. fd=sd->fd;
  3173. WFIFOHEAD(fd,packet_len(0xf6));
  3174. WFIFOW(fd,0)=0xf6; // Storage item removed
  3175. WFIFOW(fd,2)=index+1;
  3176. WFIFOL(fd,4)=amount;
  3177. WFIFOSET(fd,packet_len(0xf6));
  3178. return 0;
  3179. }
  3180. /*==========================================
  3181. * カプラ倉庫を閉じる
  3182. *------------------------------------------*/
  3183. int clif_storageclose(struct map_session_data *sd)
  3184. {
  3185. int fd;
  3186. nullpo_retr(0, sd);
  3187. fd=sd->fd;
  3188. WFIFOHEAD(fd,packet_len(0xf8));
  3189. WFIFOW(fd,0)=0xf8; // Storage Closed
  3190. WFIFOSET(fd,packet_len(0xf8));
  3191. return 0;
  3192. }
  3193. //
  3194. // callback系 ?
  3195. //
  3196. /*==========================================
  3197. * PC表示
  3198. *------------------------------------------*/
  3199. void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3200. {
  3201. int len;
  3202. if(dstsd->chatID)
  3203. {
  3204. struct chat_data *cd;
  3205. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  3206. if(cd && cd->usersd[0]==dstsd)
  3207. clif_dispchat(cd,sd->fd);
  3208. }
  3209. if(dstsd->vender_id)
  3210. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3211. if(dstsd->spiritball > 0)
  3212. clif_spiritball_single(sd->fd, dstsd);
  3213. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3214. (battle_config.disp_hpmeter && (len = pc_isGM(sd)) >= battle_config.disp_hpmeter && len >= pc_isGM(dstsd))
  3215. )
  3216. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  3217. if(dstsd->status.manner < 0)
  3218. clif_changestatus(&dstsd->bl,SP_MANNER,dstsd->status.manner);
  3219. // pvp circle for duel [LuzZza]
  3220. /*
  3221. if(dstsd->duel_group)
  3222. clif_specialeffect(&dstsd->bl, 159, 4);
  3223. */
  3224. }
  3225. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3226. {
  3227. struct unit_data *ud;
  3228. struct view_data *vd;
  3229. int len, fd = sd->fd;
  3230. vd = status_get_viewdata(bl);
  3231. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3232. return;
  3233. ud = unit_bl2ud(bl);
  3234. if (ud && ud->walktimer != -1)
  3235. {
  3236. #if PACKETVER >= 7
  3237. WFIFOHEAD(fd, packet_len(0x22c));
  3238. #elif PACKETVER > 3
  3239. WFIFOHEAD(fd, packet_len(0x1da));
  3240. #else
  3241. WFIFOHEAD(fd, packet_len(0x7b));
  3242. #endif
  3243. len = clif_set007b(bl,vd,ud,WFIFOP(fd,0));
  3244. WFIFOSET(fd,len);
  3245. } else {
  3246. #if PACKETVER >= 7
  3247. WFIFOHEAD(fd,packet_len(0x22a));
  3248. #elif PACKETVER > 3
  3249. WFIFOHEAD(fd,packet_len(0x1d8));
  3250. #else
  3251. WFIFOHEAD(fd,packet_len(0x78));
  3252. #endif
  3253. len = clif_set0078(bl,WFIFOP(fd,0));
  3254. WFIFOSET(fd,len);
  3255. }
  3256. if (vd->cloth_color)
  3257. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3258. switch (bl->type)
  3259. { // FIXME: 'AREA' causes unneccessary spam since this should be 1:1 communication [ultramage]
  3260. case BL_PC:
  3261. {
  3262. TBL_PC* tsd = (TBL_PC*)bl;
  3263. clif_getareachar_pc(sd, tsd);
  3264. if(tsd->state.size==2) // tiny/big players [Valaris]
  3265. clif_specialeffect(bl,423,AREA);
  3266. else if(tsd->state.size==1)
  3267. clif_specialeffect(bl,421,AREA);
  3268. }
  3269. break;
  3270. case BL_NPC:
  3271. {
  3272. if(((TBL_NPC*)bl)->chat_id)
  3273. clif_dispchat((struct chat_data*)map_id2bl(((TBL_NPC*)bl)->chat_id),sd->fd);
  3274. }
  3275. break;
  3276. case BL_MOB:
  3277. {
  3278. TBL_MOB* md = (TBL_MOB*)bl;
  3279. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3280. clif_specialeffect(bl,423,AREA);
  3281. else if(md->special_state.size==1)
  3282. clif_specialeffect(bl,421,AREA);
  3283. }
  3284. break;
  3285. case BL_PET:
  3286. if (vd->head_bottom)
  3287. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3288. break;
  3289. }
  3290. }
  3291. /*==========================================
  3292. * Estimates walk delay based on the damage criteria. [Skotlex]
  3293. *------------------------------------------*/
  3294. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3295. {
  3296. if (type == 4 || type == 9 || damage <=0)
  3297. return 0;
  3298. if (bl->type == BL_PC) {
  3299. if (battle_config.pc_walk_delay_rate != 100)
  3300. delay = delay*battle_config.pc_walk_delay_rate/100;
  3301. } else
  3302. if (battle_config.walk_delay_rate != 100)
  3303. delay = delay*battle_config.walk_delay_rate/100;
  3304. if (div_ > 1) //Multi-hit skills mean higher delays.
  3305. delay += battle_config.multihit_delay*(div_-1);
  3306. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3307. }
  3308. /*==========================================
  3309. * Sends a 'damage' packet (src performs action on dst)
  3310. * 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
  3311. *
  3312. * type=00 damage [param1: total damage, param2: div, param3: assassin dual-wield damage]
  3313. * type=01 pick up item
  3314. * type=02 sit down
  3315. * type=03 stand up
  3316. * type=04 reflected/absorbed damage?
  3317. * type=08 double attack
  3318. * type=09 don't display flinch animation (endure)
  3319. * type=0a critical hit
  3320. * type=0b lucky dodge
  3321. *------------------------------------------*/
  3322. 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)
  3323. {
  3324. unsigned char buf[256];
  3325. struct status_change *sc;
  3326. nullpo_retr(0, src);
  3327. nullpo_retr(0, dst);
  3328. sc = status_get_sc(dst);
  3329. if(sc && sc->count) {
  3330. if(type != 4 && dst->type == BL_PC && sc->data[SC_ENDURE].timer != -1 && !map_flag_gvg(dst->m))
  3331. type = 9;
  3332. if(sc->data[SC_HALLUCINATION].timer != -1) {
  3333. if(damage > 0) damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3334. if(damage2 > 0) damage2 = damage2*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3335. }
  3336. }
  3337. WBUFW(buf,0)=0x8a;
  3338. WBUFL(buf,2)=src->id;
  3339. WBUFL(buf,6)=dst->id;
  3340. WBUFL(buf,10)=tick;
  3341. WBUFL(buf,14)=sdelay;
  3342. WBUFL(buf,18)=ddelay;
  3343. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3344. WBUFW(buf,22)=damage?div:0;
  3345. WBUFW(buf,27)=damage2?div:0;
  3346. } else {
  3347. WBUFW(buf,22)=min(damage, SHRT_MAX);
  3348. WBUFW(buf,27)=damage2;
  3349. }
  3350. WBUFW(buf,24)=div;
  3351. WBUFB(buf,26)=type;
  3352. clif_send(buf,packet_len(0x8a),src,AREA);
  3353. if(disguised(src)) {
  3354. WBUFL(buf,2) = -src->id;
  3355. if(damage > 0) WBUFW(buf,22) = -1;
  3356. if(damage2 > 0) WBUFW(buf,27) = -1;
  3357. clif_send(buf,packet_len(0x8a),src,SELF);
  3358. }
  3359. if (disguised(dst)) {
  3360. WBUFL(buf,6) = -dst->id;
  3361. if (disguised(src)) WBUFL(buf,2) = src->id;
  3362. else {
  3363. if(damage > 0) WBUFW(buf,22) = -1;
  3364. if(damage2 > 0) WBUFW(buf,27) = -1;
  3365. }
  3366. clif_send(buf,packet_len(0x8a),dst,SELF);
  3367. }
  3368. //Return adjusted can't walk delay for further processing.
  3369. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3370. }
  3371. /*==========================================
  3372. * src picks up dst
  3373. *------------------------------------------*/
  3374. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3375. {
  3376. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3377. unsigned char buf[32];
  3378. nullpo_retv(src);
  3379. nullpo_retv(dst);
  3380. WBUFW(buf, 0) = 0x8a;
  3381. WBUFL(buf, 2) = src->id;
  3382. WBUFL(buf, 6) = dst->id;
  3383. WBUFB(buf,26) = 1;
  3384. clif_send(buf, packet_len(0x8a), src, AREA);
  3385. }
  3386. /*==========================================
  3387. * inform clients in area that `bl` is sitting
  3388. *------------------------------------------*/
  3389. void clif_sitting(struct block_list* bl)
  3390. {
  3391. unsigned char buf[32];
  3392. nullpo_retv(bl);
  3393. WBUFW(buf, 0) = 0x8a;
  3394. WBUFL(buf, 2) = bl->id;
  3395. WBUFB(buf,26) = 2;
  3396. clif_send(buf, packet_len(0x8a), bl, AREA);
  3397. if(disguised(bl)) {
  3398. WBUFL(buf, 2) = - bl->id;
  3399. clif_send(buf, packet_len(0x8a), bl, SELF);
  3400. }
  3401. }
  3402. /*==========================================
  3403. * inform clients in area that `bl` is standing
  3404. *------------------------------------------*/
  3405. void clif_standing(struct block_list* bl)
  3406. {
  3407. unsigned char buf[32];
  3408. nullpo_retv(bl);
  3409. WBUFW(buf, 0) = 0x8a;
  3410. WBUFL(buf, 2) = bl->id;
  3411. WBUFB(buf,26) = 3;
  3412. clif_send(buf, packet_len(0x8a), bl, AREA);
  3413. if(disguised(bl)) {
  3414. WBUFL(buf, 2) = - bl->id;
  3415. clif_send(buf, packet_len(0x8a), bl, SELF);
  3416. }
  3417. }
  3418. /*==========================================
  3419. * Inform client(s) about a map-cell change
  3420. *------------------------------------------*/
  3421. void clif_changemapcell(int fd, struct block_list* pos, int type, enum send_target target)
  3422. {
  3423. unsigned char buf[32];
  3424. nullpo_retv(pos);
  3425. WBUFW(buf,0) = 0x192;
  3426. WBUFW(buf,2) = pos->x;
  3427. WBUFW(buf,4) = pos->y;
  3428. WBUFW(buf,6) = type;
  3429. mapindex_getmapname_ext(map[pos->m].name,(char*)WBUFP(buf,8));
  3430. if( fd )
  3431. {
  3432. WFIFOHEAD(fd,packet_len(0x192));
  3433. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3434. WFIFOSET(fd,packet_len(0x192));
  3435. }
  3436. else
  3437. clif_send(buf,packet_len(0x192),pos,target);
  3438. }
  3439. /*==========================================
  3440. *
  3441. *------------------------------------------*/
  3442. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3443. {
  3444. int view,fd;
  3445. fd=sd->fd;
  3446. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3447. WFIFOHEAD(fd,packet_len(0x9d));
  3448. WFIFOW(fd,0)=0x9d;
  3449. WFIFOL(fd,2)=fitem->bl.id;
  3450. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3451. WFIFOW(fd,6)=view;
  3452. else
  3453. WFIFOW(fd,6)=fitem->item_data.nameid;
  3454. WFIFOB(fd,8)=fitem->item_data.identify;
  3455. WFIFOW(fd,9)=fitem->bl.x;
  3456. WFIFOW(fd,11)=fitem->bl.y;
  3457. WFIFOW(fd,13)=fitem->item_data.amount;
  3458. WFIFOB(fd,15)=fitem->subx;
  3459. WFIFOB(fd,16)=fitem->suby;
  3460. WFIFOSET(fd,packet_len(0x9d));
  3461. }
  3462. /*==========================================
  3463. * 場所スキルエフェクトが視界に入る
  3464. *------------------------------------------*/
  3465. static void clif_getareachar_skillunit(struct map_session_data *sd, struct skill_unit *unit)
  3466. {
  3467. int fd = sd->fd;
  3468. #if PACKETVER >= 3
  3469. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3470. WFIFOHEAD(fd,packet_len(0x1c9));
  3471. WFIFOW(fd, 0)=0x1c9;
  3472. WFIFOL(fd, 2)=unit->bl.id;
  3473. WFIFOL(fd, 6)=unit->group->src_id;
  3474. WFIFOW(fd,10)=unit->bl.x;
  3475. WFIFOW(fd,12)=unit->bl.y;
  3476. WFIFOB(fd,14)=unit->group->unit_id;
  3477. WFIFOB(fd,15)=1;
  3478. WFIFOB(fd,16)=1;
  3479. safestrncpy((char*)WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3480. WFIFOSET(fd,packet_len(0x1c9));
  3481. return;
  3482. }
  3483. #endif
  3484. WFIFOHEAD(fd,packet_len(0x11f));
  3485. WFIFOW(fd, 0)=0x11f;
  3486. WFIFOL(fd, 2)=unit->bl.id;
  3487. WFIFOL(fd, 6)=unit->group->src_id;
  3488. WFIFOW(fd,10)=unit->bl.x;
  3489. WFIFOW(fd,12)=unit->bl.y;
  3490. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3491. WFIFOB(fd,14)=UNT_ATTACK_SKILLS; //Use invisible unit id for traps.
  3492. else
  3493. WFIFOB(fd,14)=unit->group->unit_id;
  3494. WFIFOB(fd,15)=1; // ignored by client (always gets set to 1)
  3495. WFIFOSET(fd,packet_len(0x11f));
  3496. if(unit->group->skill_id == WZ_ICEWALL)
  3497. clif_changemapcell(fd,&unit->bl,5,SELF);
  3498. }
  3499. /*==========================================
  3500. * 場所スキルエフェクトが視界から消える
  3501. *------------------------------------------*/
  3502. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3503. {
  3504. nullpo_retv(unit);
  3505. WFIFOHEAD(fd,packet_len(0x120));
  3506. WFIFOW(fd, 0)=0x120;
  3507. WFIFOL(fd, 2)=unit->bl.id;
  3508. WFIFOSET(fd,packet_len(0x120));
  3509. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3510. clif_changemapcell(fd,&unit->bl,unit->val2,SELF);
  3511. }
  3512. /*==========================================
  3513. * 場所スキルエフェクト削除
  3514. *------------------------------------------*/
  3515. void clif_skill_delunit(struct skill_unit *unit)
  3516. {
  3517. unsigned char buf[16];
  3518. nullpo_retv(unit);
  3519. WBUFW(buf, 0)=0x120;
  3520. WBUFL(buf, 2)=unit->bl.id;
  3521. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3522. }
  3523. /*==========================================
  3524. * Unknown... trap related?
  3525. * Sent when an object gets ankle-snared
  3526. * Only affects units with class [139,153] client-side
  3527. * R 01ac <object id>.l
  3528. *------------------------------------------*/
  3529. void clif_01ac(struct block_list* bl)
  3530. {
  3531. unsigned char buf[6];
  3532. nullpo_retv(bl);
  3533. WBUFW(buf,0) = 0x1ac;
  3534. WBUFL(buf,2) = bl->id;
  3535. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3536. }
  3537. /*==========================================
  3538. *
  3539. *------------------------------------------*/
  3540. int clif_getareachar(struct block_list* bl,va_list ap)
  3541. {
  3542. struct map_session_data *sd;
  3543. nullpo_retr(0, bl);
  3544. nullpo_retr(0, ap);
  3545. sd=va_arg(ap,struct map_session_data*);
  3546. if (sd == NULL || !sd->fd || session[sd->fd] == NULL)
  3547. return 0;
  3548. switch(bl->type){
  3549. case BL_ITEM:
  3550. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3551. break;
  3552. case BL_SKILL:
  3553. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3554. break;
  3555. default:
  3556. if(&sd->bl == bl)
  3557. break;
  3558. clif_getareachar_unit(sd,bl);
  3559. break;
  3560. }
  3561. return 0;
  3562. }
  3563. /*==========================================
  3564. * tbl has gone out of view-size of bl
  3565. *------------------------------------------*/
  3566. int clif_outsight(struct block_list *bl,va_list ap)
  3567. {
  3568. struct block_list *tbl;
  3569. struct view_data *vd;
  3570. TBL_PC *sd, *tsd;
  3571. tbl=va_arg(ap,struct block_list*);
  3572. if(bl == tbl) return 0;
  3573. BL_CAST(BL_PC, bl, sd);
  3574. BL_CAST(BL_PC, tbl, tsd);
  3575. if (tsd && tsd->fd)
  3576. { //tsd has lost sight of the bl object.
  3577. switch(bl->type){
  3578. case BL_PC:
  3579. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS)
  3580. clif_clearunit_single(bl->id,0,tsd->fd);
  3581. if(sd->chatID){
  3582. struct chat_data *cd;
  3583. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3584. if(cd->usersd[0]==sd)
  3585. clif_dispchat(cd,tsd->fd);
  3586. }
  3587. if(sd->vender_id)
  3588. clif_closevendingboard(bl,tsd->fd);
  3589. break;
  3590. case BL_ITEM:
  3591. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3592. break;
  3593. case BL_SKILL:
  3594. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3595. break;
  3596. default:
  3597. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3598. clif_clearunit_single(bl->id,0,tsd->fd);
  3599. break;
  3600. }
  3601. }
  3602. if (sd && sd->fd)
  3603. { //sd is watching tbl go out of view.
  3604. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3605. clif_clearunit_single(tbl->id,0,sd->fd);
  3606. }
  3607. return 0;
  3608. }
  3609. /*==========================================
  3610. * tbl has come into view of bl
  3611. *------------------------------------------*/
  3612. int clif_insight(struct block_list *bl,va_list ap)
  3613. {
  3614. struct block_list *tbl;
  3615. TBL_PC *sd, *tsd;
  3616. tbl=va_arg(ap,struct block_list*);
  3617. if (bl == tbl) return 0;
  3618. BL_CAST(BL_PC, bl, sd);
  3619. BL_CAST(BL_PC, tbl, tsd);
  3620. if (tsd && tsd->fd)
  3621. { //Tell tsd that bl entered into his view
  3622. switch(bl->type){
  3623. case BL_ITEM:
  3624. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3625. break;
  3626. case BL_SKILL:
  3627. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3628. break;
  3629. default:
  3630. clif_getareachar_unit(tsd,bl);
  3631. break;
  3632. }
  3633. }
  3634. if (sd && sd->fd)
  3635. { //Tell sd that tbl walked into his view
  3636. clif_getareachar_unit(sd,tbl);
  3637. }
  3638. return 0;
  3639. }
  3640. /*==========================================
  3641. *
  3642. *------------------------------------------*/
  3643. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3644. {
  3645. int fd,id;
  3646. nullpo_retr(0, sd);
  3647. fd=sd->fd;
  3648. if( (id=sd->status.skill[skillid].id) <= 0 )
  3649. return 0;
  3650. WFIFOHEAD(fd,packet_len(0x147));
  3651. WFIFOW(fd,0)=0x147;
  3652. WFIFOW(fd,2) = id;
  3653. if(type < 0)
  3654. WFIFOW(fd,4) = skill_get_inf(id);
  3655. else
  3656. WFIFOW(fd,4) = type;
  3657. WFIFOW(fd,6) = 0;
  3658. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3659. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3660. if(range < 0)
  3661. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3662. WFIFOW(fd,12)= range;
  3663. strncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3664. if(sd->status.skill[skillid].flag ==0)
  3665. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3666. else
  3667. WFIFOB(fd,38) = 0;
  3668. WFIFOSET(fd,packet_len(0x147));
  3669. return 0;
  3670. }
  3671. /*==========================================
  3672. * スキルリストを送信する
  3673. *------------------------------------------*/
  3674. int clif_skillinfoblock(struct map_session_data *sd)
  3675. {
  3676. int fd;
  3677. int i,c,len,id;
  3678. nullpo_retr(0, sd);
  3679. fd=sd->fd;
  3680. if (!fd) return 0;
  3681. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3682. WFIFOW(fd,0) = 0x10f;
  3683. for ( i = 0, c = 0, len = 4; i < MAX_SKILL; i++)
  3684. {
  3685. if( (id = sd->status.skill[i].id) != 0 )
  3686. {
  3687. WFIFOW(fd,len) = id;
  3688. WFIFOW(fd,len+2) = skill_get_inf(id);
  3689. WFIFOW(fd,len+4) = 0;
  3690. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3691. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3692. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3693. strncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3694. if(sd->status.skill[i].flag == 0)
  3695. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3696. else
  3697. WFIFOB(fd,len+36) = 0;
  3698. len += 37;
  3699. c++;
  3700. }
  3701. }
  3702. WFIFOW(fd,2)=len;
  3703. WFIFOSET(fd,len);
  3704. return 1;
  3705. }
  3706. /*==========================================
  3707. * スキル割り振り通知
  3708. *------------------------------------------*/
  3709. int clif_skillup(struct map_session_data *sd,int skill_num)
  3710. {
  3711. int fd;
  3712. nullpo_retr(0, sd);
  3713. fd=sd->fd;
  3714. WFIFOHEAD(fd,packet_len(0x10e));
  3715. WFIFOW(fd,0) = 0x10e;
  3716. WFIFOW(fd,2) = skill_num;
  3717. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3718. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3719. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3720. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3721. WFIFOSET(fd,packet_len(0x10e));
  3722. return 0;
  3723. }
  3724. /*==========================================
  3725. * スキル詠唱エフェクトを送信する
  3726. *------------------------------------------*/
  3727. int clif_skillcasting(struct block_list* bl,
  3728. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int pl, int casttime)
  3729. {
  3730. unsigned char buf[32];
  3731. WBUFW(buf,0) = 0x13e;
  3732. WBUFL(buf,2) = src_id;
  3733. WBUFL(buf,6) = dst_id;
  3734. WBUFW(buf,10) = dst_x;
  3735. WBUFW(buf,12) = dst_y;
  3736. WBUFW(buf,14) = skill_num;
  3737. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3738. WBUFL(buf,20) = casttime;
  3739. clif_send(buf,packet_len(0x13e), bl, AREA);
  3740. if (disguised(bl)) {
  3741. WBUFL(buf,2) = -src_id;
  3742. WBUFL(buf,20) = 0;
  3743. clif_send(buf,packet_len(0x13e), bl, SELF);
  3744. }
  3745. return 0;
  3746. }
  3747. /*==========================================
  3748. *
  3749. *------------------------------------------*/
  3750. int clif_skillcastcancel(struct block_list* bl)
  3751. {
  3752. unsigned char buf[16];
  3753. nullpo_retr(0, bl);
  3754. WBUFW(buf,0) = 0x1b9;
  3755. WBUFL(buf,2) = bl->id;
  3756. clif_send(buf,packet_len(0x1b9), bl, AREA);
  3757. return 0;
  3758. }
  3759. /// only when type==0:
  3760. /// if(skill_id==NV_BASIC)
  3761. /// btype==0 "skill failed" MsgStringTable[159]
  3762. /// btype==1 "no emotions" MsgStringTable[160]
  3763. /// btype==2 "no sit" MsgStringTable[161]
  3764. /// btype==3 "no chat" MsgStringTable[162]
  3765. /// btype==4 "no party" MsgStringTable[163]
  3766. /// btype==5 "no shout" MsgStringTable[164]
  3767. /// btype==6 "no PKing" MsgStringTable[165]
  3768. /// btype==7 "no alligning" MsgStringTable[383]
  3769. /// btype>=8: ignored
  3770. /// if(skill_id==AL_WARP) "not enough skill level" MsgStringTable[214]
  3771. /// if(skill_id==TF_STEAL) "steal failed" MsgStringTable[205]
  3772. /// if(skill_id==TF_POISON) "envenom failed" MsgStringTable[207]
  3773. /// otherwise "skill failed" MsgStringTable[204]
  3774. /// btype irrelevant
  3775. /// type==1 "insufficient SP" MsgStringTable[202]
  3776. /// type==2 "insufficient HP" MsgStringTable[203]
  3777. /// type==3 "insufficient materials" MsgStringTable[808]
  3778. /// type==4 "there is a delay after using a skill" MsgStringTable[219]
  3779. /// type==5 "insufficient zeny" MsgStringTable[233]
  3780. /// type==6 "wrong weapon" MsgStringTable[239]
  3781. /// type==7 "red gemstone needed" MsgStringTable[246]
  3782. /// type==8 "blue gemstone needed" MsgStringTable[247]
  3783. /// type==9 "overweight" MsgStringTable[580]
  3784. /// type==10 "skill failed" MsgStringTable[285]
  3785. /// type>=11 ignored
  3786. ///
  3787. /// if(success!=0) doesn't display any of the previous messages
  3788. /// Note: when this packet is received an unknown flag is always set to 0,
  3789. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  3790. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3791. {
  3792. int fd;
  3793. if (!sd) { //Since this is the most common nullpo....
  3794. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3795. return 0;
  3796. }
  3797. fd=sd->fd;
  3798. if (!fd) return 0;
  3799. if(battle_config.display_skill_fail&1)
  3800. return 0; //Disable all skill failed messages
  3801. if(type==0x4 && !sd->state.showdelay)
  3802. return 0; //Disable delay failed messages
  3803. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3804. return 0;
  3805. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3806. return 0;
  3807. WFIFOHEAD(fd,packet_len(0x110));
  3808. WFIFOW(fd,0) = 0x110;
  3809. WFIFOW(fd,2) = skill_id;
  3810. WFIFOL(fd,4) = btype;
  3811. WFIFOB(fd,8) = 0;// success?
  3812. WFIFOB(fd,9) = type;
  3813. WFIFOSET(fd,packet_len(0x110));
  3814. return 1;
  3815. }
  3816. /*==========================================
  3817. * skill attack effect and damage
  3818. * 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
  3819. *------------------------------------------*/
  3820. 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)
  3821. {
  3822. unsigned char buf[64];
  3823. struct status_change *sc;
  3824. nullpo_retr(0, src);
  3825. nullpo_retr(0, dst);
  3826. sc = status_get_sc(dst);
  3827. if(sc && sc->count) {
  3828. if(type != 4 && dst->type == BL_PC && sc->data[SC_ENDURE].timer != -1 && !map_flag_gvg(dst->m))
  3829. type = 9;
  3830. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  3831. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3832. }
  3833. #if PACKETVER < 3
  3834. WBUFW(buf,0)=0x114;
  3835. WBUFW(buf,2)=skill_id;
  3836. WBUFL(buf,4)=src->id;
  3837. WBUFL(buf,8)=dst->id;
  3838. WBUFL(buf,12)=tick;
  3839. WBUFL(buf,16)=sdelay;
  3840. WBUFL(buf,20)=ddelay;
  3841. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3842. WBUFW(buf,24)=damage?div:0;
  3843. } else {
  3844. WBUFW(buf,24)=damage;
  3845. }
  3846. WBUFW(buf,26)=skill_lv;
  3847. WBUFW(buf,28)=div;
  3848. WBUFB(buf,30)=type;
  3849. clif_send(buf,packet_len(0x114),src,AREA);
  3850. if(disguised(src)) {
  3851. WBUFL(buf,4)=-src->id;
  3852. if(damage > 0)
  3853. WBUFW(buf,24)=-1;
  3854. clif_send(buf,packet_len(0x114),src,SELF);
  3855. }
  3856. if (disguised(dst)) {
  3857. WBUFL(buf,8)=-dst->id;
  3858. if (disguised(src))
  3859. WBUFL(buf,4)=src->id;
  3860. else if(damage > 0)
  3861. WBUFW(buf,24)=-1;
  3862. clif_send(buf,packet_len(0x114),dst,SELF);
  3863. }
  3864. #else
  3865. WBUFW(buf,0)=0x1de;
  3866. WBUFW(buf,2)=skill_id;
  3867. WBUFL(buf,4)=src->id;
  3868. WBUFL(buf,8)=dst->id;
  3869. WBUFL(buf,12)=tick;
  3870. WBUFL(buf,16)=sdelay;
  3871. WBUFL(buf,20)=ddelay;
  3872. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3873. WBUFL(buf,24)=damage?div:0;
  3874. } else {
  3875. WBUFL(buf,24)=damage;
  3876. }
  3877. WBUFW(buf,28)=skill_lv;
  3878. WBUFW(buf,30)=div;
  3879. WBUFB(buf,32)=type;
  3880. clif_send(buf,packet_len(0x1de),src,AREA);
  3881. if(disguised(src)) {
  3882. WBUFL(buf,4)=-src->id;
  3883. if(damage > 0)
  3884. WBUFL(buf,24)=-1;
  3885. clif_send(buf,packet_len(0x1de),src,SELF);
  3886. }
  3887. if (disguised(dst)) {
  3888. WBUFL(buf,8)=-dst->id;
  3889. if (disguised(src))
  3890. WBUFL(buf,4)=src->id;
  3891. else if(damage > 0)
  3892. WBUFL(buf,24)=-1;
  3893. clif_send(buf,packet_len(0x1de),dst,SELF);
  3894. }
  3895. #endif
  3896. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3897. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3898. }
  3899. /*==========================================
  3900. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3901. *------------------------------------------*/
  3902. /*
  3903. 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)
  3904. {
  3905. unsigned char buf[64];
  3906. struct status_change *sc;
  3907. nullpo_retr(0, src);
  3908. nullpo_retr(0, dst);
  3909. type = (type>0)?type:skill_get_hit(skill_id);
  3910. type = clif_calc_delay(type, ddelay);
  3911. sc = status_get_sc(dst);
  3912. if(sc && sc->count) {
  3913. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  3914. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3915. }
  3916. WBUFW(buf,0)=0x115;
  3917. WBUFW(buf,2)=skill_id;
  3918. WBUFL(buf,4)=src->id;
  3919. WBUFL(buf,8)=dst->id;
  3920. WBUFL(buf,12)=tick;
  3921. WBUFL(buf,16)=sdelay;
  3922. WBUFL(buf,20)=ddelay;
  3923. WBUFW(buf,24)=dst->x;
  3924. WBUFW(buf,26)=dst->y;
  3925. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3926. WBUFW(buf,28)=damage?div:0;
  3927. } else {
  3928. WBUFW(buf,28)=damage;
  3929. }
  3930. WBUFW(buf,30)=skill_lv;
  3931. WBUFW(buf,32)=div;
  3932. WBUFB(buf,34)=type;
  3933. clif_send(buf,packet_len(0x115),src,AREA);
  3934. if(disguised(src)) {
  3935. WBUFL(buf,4)=-src->id;
  3936. if(damage > 0)
  3937. WBUFW(buf,28)=-1;
  3938. clif_send(buf,packet_len(0x115),src,SELF);
  3939. }
  3940. if (disguised(dst)) {
  3941. WBUFL(buf,8)=-dst->id;
  3942. if (disguised(src))
  3943. WBUFL(buf,4)=src->id;
  3944. else if(damage > 0)
  3945. WBUFW(buf,28)=-1;
  3946. clif_send(buf,packet_len(0x115),dst,SELF);
  3947. }
  3948. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3949. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3950. }
  3951. */
  3952. /*==========================================
  3953. * 支援/回復スキルエフェクト
  3954. *------------------------------------------*/
  3955. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_id,int heal,int fail)
  3956. {
  3957. unsigned char buf[32];
  3958. nullpo_retr(0, dst);
  3959. WBUFW(buf,0)=0x11a;
  3960. WBUFW(buf,2)=skill_id;
  3961. WBUFW(buf,4)=min(heal, SHRT_MAX);
  3962. WBUFL(buf,6)=dst->id;
  3963. WBUFL(buf,10)=src?src->id:0;
  3964. WBUFB(buf,14)=fail;
  3965. clif_send(buf,packet_len(0x11a),dst,AREA);
  3966. if (disguised(dst)) {
  3967. WBUFL(buf,6)=-dst->id;
  3968. clif_send(buf,packet_len(0x11a),dst,SELF);
  3969. }
  3970. if(src && disguised(src)) {
  3971. WBUFL(buf,10)=-src->id;
  3972. if (disguised(dst))
  3973. WBUFL(buf,6)=dst->id;
  3974. clif_send(buf,packet_len(0x11a),src,SELF);
  3975. }
  3976. return fail;
  3977. }
  3978. /*==========================================
  3979. * 場所スキルエフェクト
  3980. *------------------------------------------*/
  3981. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  3982. {
  3983. unsigned char buf[32];
  3984. nullpo_retr(0, src);
  3985. WBUFW(buf,0)=0x117;
  3986. WBUFW(buf,2)=skill_id;
  3987. WBUFL(buf,4)=src->id;
  3988. WBUFW(buf,8)=val;
  3989. WBUFW(buf,10)=x;
  3990. WBUFW(buf,12)=y;
  3991. WBUFL(buf,14)=tick;
  3992. clif_send(buf,packet_len(0x117),src,AREA);
  3993. if(disguised(src)) {
  3994. WBUFL(buf,4)=-src->id;
  3995. clif_send(buf,packet_len(0x117),src,SELF);
  3996. }
  3997. return 0;
  3998. }
  3999. /*==========================================
  4000. * 場所スキルエフェクト表示
  4001. *------------------------------------------*/
  4002. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  4003. void clif_skill_setunit(struct skill_unit *unit)
  4004. {
  4005. unsigned char buf[128];
  4006. nullpo_retv(unit);
  4007. #if PACKETVER >= 3
  4008. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4009. WBUFW(buf, 0)=0x1c9;
  4010. WBUFL(buf, 2)=unit->bl.id;
  4011. WBUFL(buf, 6)=unit->group->src_id;
  4012. WBUFW(buf,10)=unit->bl.x;
  4013. WBUFW(buf,12)=unit->bl.y;
  4014. WBUFB(buf,14)=unit->group->unit_id;
  4015. WBUFB(buf,15)=1;
  4016. WBUFB(buf,16)=1;
  4017. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4018. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4019. return;
  4020. }
  4021. #endif
  4022. WBUFW(buf, 0)=0x11f;
  4023. WBUFL(buf, 2)=unit->bl.id;
  4024. WBUFL(buf, 6)=unit->group->src_id;
  4025. WBUFW(buf,10)=unit->bl.x;
  4026. WBUFW(buf,12)=unit->bl.y;
  4027. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4028. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4029. else
  4030. WBUFB(buf,14)=unit->group->unit_id;
  4031. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  4032. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4033. }
  4034. /*==========================================
  4035. * ワープ場所選択
  4036. *------------------------------------------*/
  4037. 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)
  4038. {
  4039. int fd;
  4040. nullpo_retv(sd);
  4041. fd = sd->fd;
  4042. WFIFOHEAD(fd,packet_len(0x11c));
  4043. WFIFOW(fd,0) = 0x11c;
  4044. WFIFOW(fd,2) = skill_num;
  4045. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4046. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  4047. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4048. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4049. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4050. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4051. WFIFOSET(fd,packet_len(0x11c));
  4052. sd->menuskill_id = skill_num;
  4053. if (skill_num == AL_WARP)
  4054. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4055. else
  4056. sd->menuskill_val = skill_lv;
  4057. }
  4058. /*==========================================
  4059. * メモ応答
  4060. *------------------------------------------*/
  4061. int clif_skill_memo(struct map_session_data *sd,int flag)
  4062. {
  4063. int fd;
  4064. nullpo_retr(0, sd);
  4065. fd=sd->fd;
  4066. WFIFOHEAD(fd,packet_len(0x11e));
  4067. WFIFOW(fd,0)=0x11e;
  4068. WFIFOB(fd,2)=flag;
  4069. WFIFOSET(fd,packet_len(0x11e));
  4070. return 0;
  4071. }
  4072. int clif_skill_teleportmessage(struct map_session_data *sd,int flag)
  4073. {
  4074. int fd;
  4075. nullpo_retr(0, sd);
  4076. fd=sd->fd;
  4077. WFIFOHEAD(fd,packet_len(0x189));
  4078. WFIFOW(fd,0)=0x189;
  4079. WFIFOW(fd,2)=flag;
  4080. WFIFOSET(fd,packet_len(0x189));
  4081. return 0;
  4082. }
  4083. /*==========================================
  4084. * モンスター情報
  4085. *------------------------------------------*/
  4086. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4087. {
  4088. struct status_data *status;
  4089. unsigned char buf[64];
  4090. int i;//, fix;
  4091. nullpo_retr(0, sd);
  4092. nullpo_retr(0, dst);
  4093. if(dst->type!=BL_MOB )
  4094. return 0;
  4095. status = status_get_status_data(dst);
  4096. WBUFW(buf, 0)=0x18c;
  4097. WBUFW(buf, 2)=status_get_class(dst);
  4098. WBUFW(buf, 4)=status_get_lv(dst);
  4099. WBUFW(buf, 6)=status->size;
  4100. WBUFL(buf, 8)=status->hp;
  4101. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4102. +(battle_config.estimation_type&2?status->def2:0);
  4103. WBUFW(buf,14)=status->race;
  4104. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4105. +(battle_config.estimation_type&2?status->mdef2:0);
  4106. WBUFW(buf,18)= status->def_ele;
  4107. for(i=0;i<9;i++)
  4108. WBUFB(buf,20+i)= (unsigned char)battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv);
  4109. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4110. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4111. clif_send(buf,packet_len(0x18c),&sd->bl,
  4112. sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4113. return 0;
  4114. }
  4115. /*==========================================
  4116. * アイテム合成可能リスト
  4117. *------------------------------------------*/
  4118. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  4119. {
  4120. int i,c,view,fd;
  4121. nullpo_retr(0, sd);
  4122. if(sd->menuskill_id == AM_PHARMACY)
  4123. return 0; //Avoid resending the menu twice or more times...
  4124. fd=sd->fd;
  4125. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4126. WFIFOW(fd, 0)=0x18d;
  4127. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4128. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4129. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4130. WFIFOW(fd,c*8+ 4)= view;
  4131. else
  4132. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4133. WFIFOW(fd,c*8+ 6)= 0x0012;
  4134. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  4135. c++;
  4136. }
  4137. }
  4138. WFIFOW(fd, 2)=c*8+8;
  4139. WFIFOSET(fd,WFIFOW(fd,2));
  4140. if(c > 0) {
  4141. sd->menuskill_id = AM_PHARMACY;
  4142. sd->menuskill_val = trigger;
  4143. return 1;
  4144. }
  4145. return 0;
  4146. }
  4147. /*==========================================
  4148. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  4149. *------------------------------------------*/
  4150. int clif_status_load(struct block_list *bl,int type, int flag)
  4151. {
  4152. int fd;
  4153. if (type == SI_BLANK) //It shows nothing on the client...
  4154. return 0;
  4155. if (bl->type != BL_PC)
  4156. return 0;
  4157. fd = ((struct map_session_data*)bl)->fd;
  4158. WFIFOHEAD(fd,packet_len(0x196));
  4159. WFIFOW(fd,0)=0x0196;
  4160. WFIFOW(fd,2)=type;
  4161. WFIFOL(fd,4)=bl->id;
  4162. WFIFOB(fd,8)=flag; //Status start
  4163. WFIFOSET(fd, packet_len(0x196));
  4164. return 0;
  4165. }
  4166. /*==========================================
  4167. * 状態異常アイコン/メッセージ表示
  4168. *------------------------------------------*/
  4169. int clif_status_change(struct block_list *bl,int type,int flag)
  4170. {
  4171. unsigned char buf[16];
  4172. if (type == SI_BLANK) //It shows nothing on the client...
  4173. return 0;
  4174. nullpo_retr(0, bl);
  4175. WBUFW(buf,0)=0x0196;
  4176. WBUFW(buf,2)=type;
  4177. WBUFL(buf,4)=bl->id;
  4178. WBUFB(buf,8)=flag;
  4179. clif_send(buf,packet_len(0x196),bl,AREA);
  4180. return 0;
  4181. }
  4182. /*==========================================
  4183. * Send message (modified by [Yor])
  4184. *------------------------------------------*/
  4185. int clif_displaymessage(const int fd, const char* mes)
  4186. {
  4187. // invalid pointer?
  4188. nullpo_retr(-1, mes);
  4189. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4190. if (fd == 0)
  4191. return 0;
  4192. else {
  4193. int len_mes = strlen(mes);
  4194. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4195. WFIFOHEAD(fd, 5 + len_mes);
  4196. WFIFOW(fd,0) = 0x8e;
  4197. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  4198. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  4199. WFIFOSET(fd, 5 + len_mes);
  4200. }
  4201. }
  4202. return 0;
  4203. }
  4204. /*==========================================
  4205. * 天の声を送信する
  4206. *------------------------------------------*/
  4207. int clif_GMmessage(struct block_list* bl, const char* mes, int len, int flag)
  4208. {
  4209. unsigned char *buf;
  4210. int lp;
  4211. lp = (flag & 0x10) ? 8 : 4;
  4212. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  4213. WBUFW(buf,0) = 0x9a;
  4214. WBUFW(buf,2) = len + lp;
  4215. WBUFL(buf,4) = 0x65756c62; //"blue":
  4216. memcpy(WBUFP(buf,lp), mes, len);
  4217. flag &= 0x07;
  4218. clif_send(buf, WBUFW(buf,2), bl,
  4219. (flag == 1) ? ALL_SAMEMAP :
  4220. (flag == 2) ? AREA :
  4221. (flag == 3) ? SELF :
  4222. ALL_CLIENT);
  4223. if(buf) aFree(buf);
  4224. if(use_irc && irc_announce_flag && !flag)
  4225. irc_announce(mes);
  4226. return 0;
  4227. }
  4228. /*==========================================
  4229. * グローバルメッセージ
  4230. *------------------------------------------*/
  4231. void clif_GlobalMessage(struct block_list* bl, const char* message)
  4232. {
  4233. char buf[100];
  4234. int len;
  4235. nullpo_retv(bl);
  4236. if(!message)
  4237. return;
  4238. len = strlen(message)+1;
  4239. WBUFW(buf,0)=0x8d;
  4240. WBUFW(buf,2)=len+8;
  4241. WBUFL(buf,4)=bl->id;
  4242. strncpy((char *) WBUFP(buf,8),message,len);
  4243. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4244. }
  4245. /*==========================================
  4246. * Send main chat message [LuzZza]
  4247. *------------------------------------------*/
  4248. void clif_MainChatMessage(const char* message)
  4249. {
  4250. char buf[200];
  4251. int len;
  4252. if(!message)
  4253. return;
  4254. len = strlen(message)+1;
  4255. if (len+8 > sizeof(buf)) {
  4256. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4257. len = sizeof(buf)-8;
  4258. }
  4259. WBUFW(buf,0)=0x8d;
  4260. WBUFW(buf,2)=len+8;
  4261. WBUFL(buf,4)=0;
  4262. strncpy((char *) WBUFP(buf,8),message,len);
  4263. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4264. }
  4265. /*==========================================
  4266. * Does an announce message in the given color.
  4267. *------------------------------------------*/
  4268. int clif_announce(struct block_list* bl, const char* mes, int len, unsigned long color, int flag)
  4269. {
  4270. unsigned char *buf;
  4271. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4272. WBUFW(buf,0) = 0x1c3;
  4273. WBUFW(buf,2) = len + 16;
  4274. WBUFL(buf,4) = color;
  4275. WBUFW(buf,8) = 0x190; //Font style? Type?
  4276. WBUFW(buf,10) = 0x0c; //12? Font size?
  4277. WBUFL(buf,12) = 0; //Unknown!
  4278. memcpy(WBUFP(buf,16), mes, len);
  4279. flag &= 0x07;
  4280. clif_send(buf, WBUFW(buf,2), bl,
  4281. (flag == 1) ? ALL_SAMEMAP :
  4282. (flag == 2) ? AREA :
  4283. (flag == 3) ? SELF :
  4284. ALL_CLIENT);
  4285. if(buf) aFree(buf);
  4286. return 0;
  4287. }
  4288. /*==========================================
  4289. * HPSP回復エフェクトを送信する
  4290. *------------------------------------------*/
  4291. int clif_heal(int fd,int type,int val)
  4292. {
  4293. WFIFOHEAD(fd,packet_len(0x13d));
  4294. WFIFOW(fd,0)=0x13d;
  4295. WFIFOW(fd,2)=type;
  4296. WFIFOW(fd,4)=cap_value(val,0,SHRT_MAX);
  4297. WFIFOSET(fd,packet_len(0x13d));
  4298. return 0;
  4299. }
  4300. /*==========================================
  4301. * 復活する
  4302. *------------------------------------------*/
  4303. int clif_resurrection(struct block_list *bl,int type)
  4304. {
  4305. unsigned char buf[16];
  4306. nullpo_retr(0, bl);
  4307. WBUFW(buf,0)=0x148;
  4308. WBUFL(buf,2)=bl->id;
  4309. WBUFW(buf,6)=type;
  4310. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4311. if (disguised(bl))
  4312. clif_spawn(bl);
  4313. return 0;
  4314. }
  4315. /*==========================================
  4316. * PVP実装?(仮)
  4317. *------------------------------------------*/
  4318. int clif_set0199(int fd,int type)
  4319. {
  4320. WFIFOHEAD(fd,packet_len(0x199));
  4321. WFIFOW(fd,0)=0x199;
  4322. WFIFOW(fd,2)=type;
  4323. WFIFOSET(fd,packet_len(0x199));
  4324. return 0;
  4325. }
  4326. /*==========================================
  4327. * PVP実装?(仮)
  4328. *------------------------------------------*/
  4329. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4330. {
  4331. int fd = sd->fd;
  4332. if(type == 2) {
  4333. WFIFOHEAD(fd,packet_len(0x19a));
  4334. WFIFOW(fd,0) = 0x19a;
  4335. WFIFOL(fd,2) = sd->bl.id;
  4336. WFIFOL(fd,6) = pvprank;
  4337. WFIFOL(fd,10) = pvpnum;
  4338. WFIFOSET(fd,packet_len(0x19a));
  4339. } else {
  4340. unsigned char buf[32];
  4341. WBUFW(buf,0) = 0x19a;
  4342. WBUFL(buf,2) = sd->bl.id;
  4343. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4344. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4345. else
  4346. WBUFL(buf,6) = pvprank;
  4347. WBUFL(buf,10) = pvpnum;
  4348. if(sd->sc.option&OPTION_INVISIBLE)
  4349. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4350. else if(!type)
  4351. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4352. else
  4353. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4354. }
  4355. return 0;
  4356. }
  4357. /*==========================================
  4358. *
  4359. *------------------------------------------*/
  4360. int clif_send0199(int map,int type)
  4361. {
  4362. struct block_list bl;
  4363. unsigned char buf[16];
  4364. bl.id = 0;
  4365. bl.type = BL_NUL;
  4366. bl.m = map;
  4367. WBUFW(buf,0)=0x199;
  4368. WBUFW(buf,2)=type;
  4369. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4370. return 0;
  4371. }
  4372. /*==========================================
  4373. * 精錬エフェクトを送信する
  4374. *------------------------------------------*/
  4375. void clif_refine(int fd, int fail, int index, int val)
  4376. {
  4377. WFIFOHEAD(fd,packet_len(0x188));
  4378. WFIFOW(fd,0)=0x188;
  4379. WFIFOW(fd,2)=fail;
  4380. WFIFOW(fd,4)=index+2;
  4381. WFIFOW(fd,6)=val;
  4382. WFIFOSET(fd,packet_len(0x188));
  4383. }
  4384. /// result=0: "weapon upgrated: %s" MsgStringTable[911] in rgb(0,255,255)
  4385. /// result=1: "weapon upgrated: %s" MsgStringTable[912] in rgb(0,205,205)
  4386. /// result=2: "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4387. /// result=3: "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4388. void clif_upgrademessage(int fd, int result, int item_id)
  4389. {
  4390. WFIFOHEAD(fd,packet_len(0x223));
  4391. WFIFOW(fd,0)=0x223;
  4392. WFIFOL(fd,2)=result;
  4393. WFIFOW(fd,6)=item_id;
  4394. WFIFOSET(fd,packet_len(0x223));
  4395. }
  4396. /*==========================================
  4397. * Wisp/page is transmitted to the destination player
  4398. * R 0097 <len>.w <nick>.24B <message>.?B
  4399. *------------------------------------------*/
  4400. int clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4401. {
  4402. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4403. WFIFOW(fd,0) = 0x97;
  4404. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4405. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4406. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  4407. WFIFOSET(fd,WFIFOW(fd,2));
  4408. return 0;
  4409. }
  4410. /*==========================================
  4411. * Inform the player about the result of his whisper action
  4412. * R 0098 <type>.B
  4413. * 0: success to send wisper
  4414. * 1: target character is not loged in
  4415. * 2: ignored by target
  4416. * 3: everyone ignored by target
  4417. *------------------------------------------*/
  4418. int clif_wis_end(int fd, int flag)
  4419. {
  4420. WFIFOHEAD(fd,packet_len(0x98));
  4421. WFIFOW(fd,0) = 0x98;
  4422. WFIFOW(fd,2) = flag;
  4423. WFIFOSET(fd,packet_len(0x98));
  4424. return 0;
  4425. }
  4426. /*==========================================
  4427. * キャラID名前引き結果を送信する
  4428. *------------------------------------------*/
  4429. int clif_solved_charname(int fd, int charid, const char* name)
  4430. {
  4431. WFIFOHEAD(fd,packet_len(0x194));
  4432. WFIFOW(fd,0)=0x194;
  4433. WFIFOL(fd,2)=charid;
  4434. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  4435. WFIFOSET(fd,packet_len(0x194));
  4436. return 0;
  4437. }
  4438. /*==========================================
  4439. * カードの挿入可能リストを返す
  4440. *------------------------------------------*/
  4441. int clif_use_card(struct map_session_data *sd,int idx)
  4442. {
  4443. int i,c,ep;
  4444. int fd=sd->fd;
  4445. nullpo_retr(0, sd);
  4446. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4447. return 0;
  4448. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4449. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4450. ep=sd->inventory_data[idx]->equip;
  4451. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4452. WFIFOW(fd,0)=0x017b;
  4453. for(i=c=0;i<MAX_INVENTORY;i++){
  4454. int j;
  4455. if(sd->inventory_data[i] == NULL)
  4456. continue;
  4457. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4458. continue;
  4459. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4460. continue;
  4461. if(sd->status.inventory[i].identify==0 ) //Not identified
  4462. continue;
  4463. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4464. continue;
  4465. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_HAND_L) //Shield card won't go on left weapon.
  4466. continue;
  4467. for(j=0;j<sd->inventory_data[i]->slot;j++){
  4468. if( sd->status.inventory[i].card[j]==0 )
  4469. break;
  4470. }
  4471. if(j==sd->inventory_data[i]->slot) // No room
  4472. continue;
  4473. WFIFOW(fd,4+c*2)=i+2;
  4474. c++;
  4475. }
  4476. WFIFOW(fd,2)=4+c*2;
  4477. WFIFOSET(fd,WFIFOW(fd,2));
  4478. return 0;
  4479. }
  4480. /*==========================================
  4481. * カードの挿入終了
  4482. *------------------------------------------*/
  4483. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4484. {
  4485. int fd;
  4486. nullpo_retr(0, sd);
  4487. fd=sd->fd;
  4488. WFIFOHEAD(fd,packet_len(0x17d));
  4489. WFIFOW(fd,0)=0x17d;
  4490. WFIFOW(fd,2)=idx_equip+2;
  4491. WFIFOW(fd,4)=idx_card+2;
  4492. WFIFOB(fd,6)=flag;
  4493. WFIFOSET(fd,packet_len(0x17d));
  4494. return 0;
  4495. }
  4496. /*==========================================
  4497. * 鑑定可能アイテムリスト送信
  4498. *------------------------------------------*/
  4499. int clif_item_identify_list(struct map_session_data *sd)
  4500. {
  4501. int i,c;
  4502. int fd;
  4503. nullpo_retr(0, sd);
  4504. fd=sd->fd;
  4505. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4506. WFIFOW(fd,0)=0x177;
  4507. for(i=c=0;i<MAX_INVENTORY;i++){
  4508. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4509. WFIFOW(fd,c*2+4)=i+2;
  4510. c++;
  4511. }
  4512. }
  4513. if(c > 0) {
  4514. WFIFOW(fd,2)=c*2+4;
  4515. WFIFOSET(fd,WFIFOW(fd,2));
  4516. sd->menuskill_id = MC_IDENTIFY;
  4517. sd->menuskill_val = c;
  4518. }
  4519. return 0;
  4520. }
  4521. /*==========================================
  4522. * 鑑定結果
  4523. *------------------------------------------*/
  4524. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4525. {
  4526. int fd;
  4527. nullpo_retr(0, sd);
  4528. fd=sd->fd;
  4529. WFIFOHEAD(fd,packet_len(0x179));
  4530. WFIFOW(fd, 0)=0x179;
  4531. WFIFOW(fd, 2)=idx+2;
  4532. WFIFOB(fd, 4)=flag;
  4533. WFIFOSET(fd,packet_len(0x179));
  4534. return 0;
  4535. }
  4536. /*==========================================
  4537. * 修理可能アイテムリスト送信
  4538. *------------------------------------------*/
  4539. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4540. {
  4541. int i,c;
  4542. int fd;
  4543. int nameid;
  4544. nullpo_retr(0, sd);
  4545. nullpo_retr(0, dstsd);
  4546. fd=sd->fd;
  4547. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4548. WFIFOW(fd,0)=0x1fc;
  4549. for(i=c=0;i<MAX_INVENTORY;i++){
  4550. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4551. WFIFOW(fd,c*13+4) = i;
  4552. WFIFOW(fd,c*13+6) = nameid;
  4553. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4554. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4555. WFIFOB(fd,c*13+16)= c;
  4556. c++;
  4557. }
  4558. }
  4559. if(c > 0) {
  4560. WFIFOW(fd,2)=c*13+4;
  4561. WFIFOSET(fd,WFIFOW(fd,2));
  4562. sd->menuskill_id = BS_REPAIRWEAPON;
  4563. sd->menuskill_val = dstsd->bl.id;
  4564. }else
  4565. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4566. return 0;
  4567. }
  4568. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4569. {
  4570. int view,fd;
  4571. nullpo_retr(0, sd);
  4572. fd=sd->fd;
  4573. WFIFOHEAD(fd,packet_len(0x1fe));
  4574. WFIFOW(fd, 0)=0x1fe;
  4575. if((view = itemdb_viewid(nameid)) > 0)
  4576. WFIFOW(fd, 2)=view;
  4577. else
  4578. WFIFOW(fd, 2)=nameid;
  4579. WFIFOB(fd, 4)=flag;
  4580. WFIFOSET(fd,packet_len(0x1fe));
  4581. return 0;
  4582. }
  4583. /*==========================================
  4584. * Weapon Refining - Taken from jAthena
  4585. *------------------------------------------*/
  4586. int clif_item_refine_list(struct map_session_data *sd)
  4587. {
  4588. int i,c;
  4589. int fd;
  4590. int skilllv;
  4591. int wlv;
  4592. int refine_item[5];
  4593. nullpo_retr(0, sd);
  4594. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4595. fd=sd->fd;
  4596. refine_item[0] = -1;
  4597. refine_item[1] = pc_search_inventory(sd,1010);
  4598. refine_item[2] = pc_search_inventory(sd,1011);
  4599. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4600. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4601. WFIFOW(fd,0)=0x221;
  4602. for(i=c=0;i<MAX_INVENTORY;i++){
  4603. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4604. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4605. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4606. WFIFOW(fd,c*13+ 4)=i+2;
  4607. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4608. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4609. WFIFOW(fd,c*13+10)=0;
  4610. WFIFOB(fd,c*13+12)=c;
  4611. c++;
  4612. }
  4613. }
  4614. WFIFOW(fd,2)=c*13+4;
  4615. WFIFOSET(fd,WFIFOW(fd,2));
  4616. if (c > 0) {
  4617. sd->menuskill_id = WS_WEAPONREFINE;
  4618. sd->menuskill_val = skilllv;
  4619. }
  4620. return 0;
  4621. }
  4622. /*==========================================
  4623. * アイテムによる一時的なスキル効果
  4624. *------------------------------------------*/
  4625. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  4626. {
  4627. int fd;
  4628. nullpo_retr(0, sd);
  4629. fd=sd->fd;
  4630. WFIFOHEAD(fd,packet_len(0x147));
  4631. WFIFOW(fd, 0)=0x147;
  4632. WFIFOW(fd, 2)=skillid;
  4633. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4634. WFIFOW(fd, 6)=0;
  4635. WFIFOW(fd, 8)=skilllv;
  4636. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4637. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4638. strncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  4639. WFIFOB(fd,38)=0;
  4640. WFIFOSET(fd,packet_len(0x147));
  4641. return 0;
  4642. }
  4643. /*==========================================
  4644. * カートにアイテム追加
  4645. *------------------------------------------*/
  4646. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4647. {
  4648. int view,fd;
  4649. unsigned char *buf;
  4650. nullpo_retr(0, sd);
  4651. fd=sd->fd;
  4652. WFIFOHEAD(fd,packet_len(0x124));
  4653. buf=WFIFOP(fd,0);
  4654. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4655. return 1;
  4656. WBUFW(buf,0)=0x124;
  4657. WBUFW(buf,2)=n+2;
  4658. WBUFL(buf,4)=amount;
  4659. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4660. WBUFW(buf,8)=view;
  4661. else
  4662. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4663. WBUFB(buf,10)=sd->status.cart[n].identify;
  4664. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4665. WBUFB(buf,12)=sd->status.cart[n].refine;
  4666. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4667. WFIFOSET(fd,packet_len(0x124));
  4668. return 0;
  4669. }
  4670. /*==========================================
  4671. * カートからアイテム削除
  4672. *------------------------------------------*/
  4673. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4674. {
  4675. int fd;
  4676. nullpo_retr(0, sd);
  4677. fd=sd->fd;
  4678. WFIFOHEAD(fd,packet_len(0x125));
  4679. WFIFOW(fd,0)=0x125;
  4680. WFIFOW(fd,2)=n+2;
  4681. WFIFOL(fd,4)=amount;
  4682. WFIFOSET(fd,packet_len(0x125));
  4683. return 0;
  4684. }
  4685. /*==========================================
  4686. * Opens the shop creation menu.
  4687. * R 012d <num>.w
  4688. * 'num' is the number of allowed item slots
  4689. *------------------------------------------*/
  4690. void clif_openvendingreq(struct map_session_data* sd, int num)
  4691. {
  4692. int fd;
  4693. nullpo_retv(sd);
  4694. fd = sd->fd;
  4695. WFIFOHEAD(fd,packet_len(0x12d));
  4696. WFIFOW(fd,0) = 0x12d;
  4697. WFIFOW(fd,2) = num;
  4698. WFIFOSET(fd,packet_len(0x12d));
  4699. }
  4700. /*==========================================
  4701. * Displays a vending board to target/area
  4702. * R 0131 <ID>.l <message>.80B
  4703. *------------------------------------------*/
  4704. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  4705. {
  4706. unsigned char buf[128];
  4707. nullpo_retv(bl);
  4708. WBUFW(buf,0) = 0x131;
  4709. WBUFL(buf,2) = bl->id;
  4710. safestrncpy((char*)WBUFP(buf,6), message, 80);
  4711. if( fd ) {
  4712. WFIFOHEAD(fd,packet_len(0x131));
  4713. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  4714. WFIFOSET(fd,packet_len(0x131));
  4715. } else {
  4716. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  4717. }
  4718. }
  4719. /*==========================================
  4720. * Removes a vending board from screen
  4721. *------------------------------------------*/
  4722. void clif_closevendingboard(struct block_list* bl, int fd)
  4723. {
  4724. unsigned char buf[16];
  4725. nullpo_retv(bl);
  4726. WBUFW(buf,0) = 0x132;
  4727. WBUFL(buf,2) = bl->id;
  4728. if( fd ) {
  4729. WFIFOHEAD(fd,packet_len(0x132));
  4730. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  4731. WFIFOSET(fd,packet_len(0x132));
  4732. } else {
  4733. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  4734. }
  4735. }
  4736. /*==========================================
  4737. * Sends a list of items in a shop
  4738. * 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
  4739. *------------------------------------------*/
  4740. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  4741. {
  4742. int i,fd;
  4743. int count;
  4744. struct map_session_data* vsd;
  4745. nullpo_retv(sd);
  4746. nullpo_retv(vending);
  4747. nullpo_retv(vsd=map_id2sd(id));
  4748. fd = sd->fd;
  4749. count = vsd->vend_num;
  4750. WFIFOHEAD(fd, 8+count*22);
  4751. WFIFOW(fd,0) = 0x133;
  4752. WFIFOW(fd,2) = 8+count*22;
  4753. WFIFOL(fd,4) = id;
  4754. for( i = 0; i < count; i++ )
  4755. {
  4756. int index = vending[i].index;
  4757. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  4758. WFIFOL(fd, 8+i*22) = vending[i].value;
  4759. WFIFOW(fd,12+i*22) = vending[i].amount;
  4760. WFIFOW(fd,14+i*22) = vending[i].index + 2;
  4761. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4762. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  4763. WFIFOB(fd,19+i*22) = vsd->status.cart[index].identify;
  4764. WFIFOB(fd,20+i*22) = vsd->status.cart[index].attribute;
  4765. WFIFOB(fd,21+i*22) = vsd->status.cart[index].refine;
  4766. clif_addcards(WFIFOP(fd, 22+i*22), &vsd->status.cart[index]);
  4767. }
  4768. WFIFOSET(fd,WFIFOW(fd,2));
  4769. }
  4770. /*==========================================
  4771. * Shop purchase failure
  4772. * R 0135 <index>.w <amount>.w <fail>.B
  4773. * fail=1 - not enough zeny
  4774. * fail=2 - overweight
  4775. * fail=4 - out of stock
  4776. * fail=5 - "cannot use an npc shop while in a trade"
  4777. *------------------------------------------*/
  4778. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  4779. {
  4780. int fd;
  4781. nullpo_retv(sd);
  4782. fd = sd->fd;
  4783. WFIFOHEAD(fd,packet_len(0x135));
  4784. WFIFOW(fd,0) = 0x135;
  4785. WFIFOW(fd,2) = index+2;
  4786. WFIFOW(fd,4) = amount;
  4787. WFIFOB(fd,6) = fail;
  4788. WFIFOSET(fd,packet_len(0x135));
  4789. }
  4790. /*==========================================
  4791. * Shop creation success
  4792. * 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*
  4793. *------------------------------------------*/
  4794. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  4795. {
  4796. int i,fd;
  4797. int count;
  4798. nullpo_retv(sd);
  4799. fd = sd->fd;
  4800. count = sd->vend_num;
  4801. WFIFOHEAD(fd, 8+count*22);
  4802. WFIFOW(fd,0) = 0x136;
  4803. WFIFOW(fd,2) = 8+count*22;
  4804. WFIFOL(fd,4) = id;
  4805. for( i = 0; i < count; i++ )
  4806. {
  4807. int index = vending[i].index;
  4808. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  4809. WFIFOL(fd, 8+i*22) = vending[i].value;
  4810. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  4811. WFIFOW(fd,14+i*22) = vending[i].amount;
  4812. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4813. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  4814. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  4815. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  4816. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  4817. clif_addcards(WFIFOP(fd,22+count*22), &sd->status.cart[index]);
  4818. }
  4819. WFIFOSET(fd,WFIFOW(fd,2));
  4820. }
  4821. /*==========================================
  4822. * Inform merchant that someone has bought an item.
  4823. * R 0137 <index>.w <amount>.w
  4824. *------------------------------------------*/
  4825. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  4826. {
  4827. int fd;
  4828. nullpo_retv(sd);
  4829. fd = sd->fd;
  4830. WFIFOHEAD(fd,packet_len(0x137));
  4831. WFIFOW(fd,0) = 0x137;
  4832. WFIFOW(fd,2) = index+2;
  4833. WFIFOW(fd,4) = amount;
  4834. WFIFOSET(fd,packet_len(0x137));
  4835. }
  4836. /// Result of organizing a party.
  4837. /// S 00FA <result>.B
  4838. ///
  4839. /// result=0 : opens party window and shows MsgStringTable[77]="party successfully organized"
  4840. /// result=1 : MsgStringTable[78]="party name already exists"
  4841. /// result=2 : MsgStringTable[79]="already in a party"
  4842. /// result=other : nothing
  4843. int clif_party_created(struct map_session_data *sd,int result)
  4844. {
  4845. int fd;
  4846. nullpo_retr(0, sd);
  4847. fd=sd->fd;
  4848. WFIFOHEAD(fd,packet_len(0xfa));
  4849. WFIFOW(fd,0)=0xfa;
  4850. WFIFOB(fd,2)=result;
  4851. WFIFOSET(fd,packet_len(0xfa));
  4852. return 0;
  4853. }
  4854. int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  4855. {
  4856. unsigned char buf[96];
  4857. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  4858. int i;
  4859. for (i=0; i<MAX_PARTY && !p->data[i].sd; i++);
  4860. if (i >= MAX_PARTY) return 0; //Should never happen...
  4861. sd = p->data[i].sd;
  4862. }
  4863. WBUFW(buf, 0) = 0x1e9;
  4864. WBUFL(buf, 2) = sd->status.account_id;
  4865. WBUFL(buf, 6) = 0; //Apparently setting this to 1 makes you adoptable.
  4866. WBUFW(buf,10) = sd->bl.x;
  4867. WBUFW(buf,12) = sd->bl.y;
  4868. WBUFB(buf,14) = 0; //Unconfirmed byte, could be online/offline.
  4869. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  4870. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  4871. mapindex_getmapname_ext(mapindex_id2name(sd->mapindex), (char*)WBUFP(buf,63));
  4872. WBUFB(buf,79) = (p->party.item&1)?1:0;
  4873. WBUFB(buf,80) = (p->party.item&2)?1:0;
  4874. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  4875. return 1;
  4876. }
  4877. /*==========================================
  4878. * Sends party information
  4879. * R 00fb <len>.w <party name>.24B {<ID>.l <nick>.24B <map name>.16B <leader>.B <offline>.B}.46B*
  4880. *------------------------------------------*/
  4881. int clif_party_info(struct party_data* p, struct map_session_data *sd)
  4882. {
  4883. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  4884. struct map_session_data* party_sd = NULL;
  4885. int i, c;
  4886. nullpo_retr(0, p);
  4887. WBUFW(buf,0) = 0xfb;
  4888. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  4889. for(i = 0, c = 0; i < MAX_PARTY; i++)
  4890. {
  4891. struct party_member* m = &p->party.member[i];
  4892. if(!m->account_id) continue;
  4893. if(party_sd == NULL) party_sd = p->data[i].sd;
  4894. WBUFL(buf,28+c*46) = m->account_id;
  4895. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  4896. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  4897. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  4898. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  4899. c++;
  4900. }
  4901. WBUFW(buf,2) = 28+c*46;
  4902. if(sd) { // send only to self
  4903. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  4904. } else if (party_sd) { // send to whole party
  4905. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  4906. }
  4907. return 0;
  4908. }
  4909. /*==========================================
  4910. * パーティ勧誘
  4911. *------------------------------------------*/
  4912. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  4913. {
  4914. int fd;
  4915. struct party_data *p;
  4916. nullpo_retr(0, sd);
  4917. nullpo_retr(0, tsd);
  4918. fd=tsd->fd;
  4919. if( (p=party_search(sd->status.party_id))==NULL )
  4920. return 0;
  4921. WFIFOHEAD(fd,packet_len(0xfe));
  4922. WFIFOW(fd,0)=0xfe;
  4923. WFIFOL(fd,2)=sd->status.account_id;
  4924. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  4925. WFIFOSET(fd,packet_len(0xfe));
  4926. return 0;
  4927. }
  4928. /*==========================================
  4929. * Party invitation result. Flag values are:
  4930. * 0 -> char is already in a party
  4931. * 1 -> party invite was rejected
  4932. * 2 -> party invite was accepted
  4933. * 3 -> party is full
  4934. * 4 -> char of the same account already joined the party
  4935. *------------------------------------------*/
  4936. int clif_party_inviteack(struct map_session_data* sd, const char* nick, int flag)
  4937. {
  4938. int fd;
  4939. nullpo_retr(0, sd);
  4940. fd=sd->fd;
  4941. WFIFOHEAD(fd,packet_len(0xfd));
  4942. WFIFOW(fd,0)=0xfd;
  4943. memcpy(WFIFOP(fd,2),nick,NAME_LENGTH);
  4944. WFIFOB(fd,26)=flag;
  4945. WFIFOSET(fd,packet_len(0xfd));
  4946. return 0;
  4947. }
  4948. /*==========================================
  4949. * パーティ設定送信
  4950. * flag & 0x001=exp変更ミス
  4951. * 0x010=item変更ミス
  4952. * 0x100=一人にのみ送信
  4953. *------------------------------------------*/
  4954. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  4955. {
  4956. unsigned char buf[16];
  4957. nullpo_retr(0, p);
  4958. if(!sd && flag==0){
  4959. int i;
  4960. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4961. if (i < MAX_PARTY)
  4962. sd = p->data[i].sd;
  4963. }
  4964. if(!sd) return 0;
  4965. WBUFW(buf,0)=0x101;
  4966. // WBUFL(buf,2) // that's how the client reads it, still need to check it's uses [FlavioJS]
  4967. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  4968. WBUFW(buf,4)=0;
  4969. if(flag==0)
  4970. clif_send(buf,packet_len(0x101),&sd->bl,PARTY);
  4971. else
  4972. clif_send(buf,packet_len(0x101),&sd->bl,SELF);
  4973. return 0;
  4974. }
  4975. /*==========================================
  4976. * パーティ脱退(脱退前に呼ぶこと)
  4977. *------------------------------------------*/
  4978. int clif_party_leaved(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  4979. {
  4980. unsigned char buf[64];
  4981. int i;
  4982. nullpo_retr(0, p);
  4983. if(!sd && (flag&0xf0)==0)
  4984. {
  4985. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4986. if (i < MAX_PARTY)
  4987. sd = p->data[i].sd;
  4988. }
  4989. if(!sd) return 0;
  4990. WBUFW(buf,0)=0x105;
  4991. WBUFL(buf,2)=account_id;
  4992. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  4993. WBUFB(buf,30)=flag&0x0f;
  4994. if((flag&0xf0)==0)
  4995. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  4996. else
  4997. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  4998. return 0;
  4999. }
  5000. /*==========================================
  5001. * パーティメッセージ送信
  5002. *------------------------------------------*/
  5003. int clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  5004. {
  5005. struct map_session_data *sd;
  5006. int i;
  5007. nullpo_retr(0, p);
  5008. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  5009. if(i < MAX_PARTY){
  5010. unsigned char buf[1024];
  5011. sd = p->data[i].sd;
  5012. WBUFW(buf,0)=0x109;
  5013. WBUFW(buf,2)=len+8;
  5014. WBUFL(buf,4)=account_id;
  5015. memcpy(WBUFP(buf,8),mes,len);
  5016. clif_send(buf,len+8,&sd->bl,PARTY);
  5017. }
  5018. return 0;
  5019. }
  5020. /*==========================================
  5021. * パーティ座標通知
  5022. *------------------------------------------*/
  5023. int clif_party_xy(struct map_session_data *sd)
  5024. {
  5025. unsigned char buf[16];
  5026. nullpo_retr(0, sd);
  5027. WBUFW(buf,0)=0x107;
  5028. WBUFL(buf,2)=sd->status.account_id;
  5029. WBUFW(buf,6)=sd->bl.x;
  5030. WBUFW(buf,8)=sd->bl.y;
  5031. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  5032. return 0;
  5033. }
  5034. /*==========================================
  5035. * Sends x/y dot to a single fd. [Skotlex]
  5036. *------------------------------------------*/
  5037. int clif_party_xy_single(int fd, struct map_session_data *sd)
  5038. {
  5039. WFIFOHEAD(fd,packet_len(0x107));
  5040. WFIFOW(fd,0)=0x107;
  5041. WFIFOL(fd,2)=sd->status.account_id;
  5042. WFIFOW(fd,6)=sd->bl.x;
  5043. WFIFOW(fd,8)=sd->bl.y;
  5044. WFIFOSET(fd,packet_len(0x107));
  5045. return 0;
  5046. }
  5047. /*==========================================
  5048. * パーティHP通知
  5049. *------------------------------------------*/
  5050. int clif_party_hp(struct map_session_data *sd)
  5051. {
  5052. unsigned char buf[16];
  5053. nullpo_retr(0, sd);
  5054. WBUFW(buf,0)=0x106;
  5055. WBUFL(buf,2)=sd->status.account_id;
  5056. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5057. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5058. WBUFW(buf,8) = 100;
  5059. } else {
  5060. WBUFW(buf,6) = sd->battle_status.hp;
  5061. WBUFW(buf,8) = sd->battle_status.max_hp;
  5062. }
  5063. clif_send(buf,packet_len(0x106),&sd->bl,PARTY_AREA_WOS);
  5064. return 0;
  5065. }
  5066. /*==========================================
  5067. * Sends HP bar to a single fd. [Skotlex]
  5068. *------------------------------------------*/
  5069. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  5070. {
  5071. WFIFOHEAD(fd,packet_len(0x106));
  5072. WFIFOW(fd,0) = 0x106;
  5073. WFIFOL(fd,2) = id;
  5074. if( maxhp > SHRT_MAX )
  5075. {// To correctly display the %hp bar. [Skotlex]
  5076. WFIFOW(fd,6) = hp/(maxhp/100);
  5077. WFIFOW(fd,8) = 100;
  5078. } else {
  5079. WFIFOW(fd,6) = hp;
  5080. WFIFOW(fd,8) = maxhp;
  5081. }
  5082. WFIFOSET(fd, packet_len(0x106));
  5083. }
  5084. /*==========================================
  5085. * GMへ場所とHP通知
  5086. *------------------------------------------*/
  5087. int clif_hpmeter(struct map_session_data *sd)
  5088. {
  5089. struct map_session_data *sd2;
  5090. unsigned char buf[16];
  5091. int i, x0, y0, x1, y1;
  5092. int level;
  5093. nullpo_retr(0, sd);
  5094. x0 = sd->bl.x - AREA_SIZE;
  5095. y0 = sd->bl.y - AREA_SIZE;
  5096. x1 = sd->bl.x + AREA_SIZE;
  5097. y1 = sd->bl.y + AREA_SIZE;
  5098. WBUFW(buf,0) = 0x106;
  5099. WBUFL(buf,2) = sd->status.account_id;
  5100. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5101. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5102. WBUFW(buf,8) = 100;
  5103. } else {
  5104. WBUFW(buf,6) = sd->battle_status.hp;
  5105. WBUFW(buf,8) = sd->battle_status.max_hp;
  5106. }
  5107. for (i = 0; i < fd_max; i++) {
  5108. if (session[i] && session[i]->func_parse == clif_parse &&
  5109. (sd2 = (struct map_session_data*)session[i]->session_data) &&
  5110. sd != sd2 && sd2->state.auth) {
  5111. if (sd2->bl.m != sd->bl.m ||
  5112. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  5113. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  5114. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  5115. level < pc_isGM(sd))
  5116. continue;
  5117. WFIFOHEAD (i, packet_len(0x106));
  5118. memcpy (WFIFOP(i,0), buf, packet_len(0x106));
  5119. WFIFOSET (i, packet_len(0x106));
  5120. }
  5121. }
  5122. return 0;
  5123. }
  5124. /*==========================================
  5125. * パーティ場所移動(未使用)
  5126. *------------------------------------------*/
  5127. void clif_party_move(struct party* p, struct map_session_data* sd, int online)
  5128. {
  5129. unsigned char buf[128];
  5130. nullpo_retv(sd);
  5131. nullpo_retv(p);
  5132. WBUFW(buf, 0) = 0x104;
  5133. WBUFL(buf, 2) = sd->status.account_id;
  5134. WBUFL(buf, 6) = 0;
  5135. WBUFW(buf,10) = sd->bl.x;
  5136. WBUFW(buf,12) = sd->bl.y;
  5137. WBUFB(buf,14) = !online;
  5138. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  5139. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  5140. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  5141. clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
  5142. }
  5143. /*==========================================
  5144. * 攻撃するために移動が必要
  5145. *------------------------------------------*/
  5146. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5147. {
  5148. int fd;
  5149. nullpo_retr(0, sd);
  5150. nullpo_retr(0, bl);
  5151. fd=sd->fd;
  5152. WFIFOHEAD(fd,packet_len(0x139));
  5153. WFIFOW(fd, 0)=0x139;
  5154. WFIFOL(fd, 2)=bl->id;
  5155. WFIFOW(fd, 6)=bl->x;
  5156. WFIFOW(fd, 8)=bl->y;
  5157. WFIFOW(fd,10)=sd->bl.x;
  5158. WFIFOW(fd,12)=sd->bl.y;
  5159. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5160. WFIFOSET(fd,packet_len(0x139));
  5161. return 0;
  5162. }
  5163. /*==========================================
  5164. * 製造エフェクト
  5165. *------------------------------------------*/
  5166. int clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  5167. {
  5168. int fd;
  5169. nullpo_retr(0, sd);
  5170. fd = sd->fd;
  5171. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  5172. WFIFOHEAD(fd,packet_len(0x18f));
  5173. WFIFOW(fd, 0)=0x18f;
  5174. WFIFOW(fd, 2)=flag;
  5175. WFIFOW(fd, 4)=(itemdb_viewid(nameid)||nameid);
  5176. WFIFOSET(fd,packet_len(0x18f));
  5177. return 0;
  5178. }
  5179. // pet
  5180. int clif_catch_process(struct map_session_data *sd)
  5181. {
  5182. int fd;
  5183. nullpo_retr(0, sd);
  5184. fd=sd->fd;
  5185. WFIFOHEAD(fd,packet_len(0x19e));
  5186. WFIFOW(fd,0)=0x19e;
  5187. WFIFOSET(fd,packet_len(0x19e));
  5188. return 0;
  5189. }
  5190. int clif_pet_roulette(struct map_session_data *sd,int data)
  5191. {
  5192. int fd;
  5193. nullpo_retr(0, sd);
  5194. fd=sd->fd;
  5195. WFIFOHEAD(fd,packet_len(0x1a0));
  5196. WFIFOW(fd,0)=0x1a0;
  5197. WFIFOB(fd,2)=data;
  5198. WFIFOSET(fd,packet_len(0x1a0));
  5199. return 0;
  5200. }
  5201. /*==========================================
  5202. * pet卵リスト作成
  5203. *------------------------------------------*/
  5204. int clif_sendegg(struct map_session_data *sd)
  5205. {
  5206. //R 01a6 <len>.w <index>.w*
  5207. int i,n=0,fd;
  5208. nullpo_retr(0, sd);
  5209. fd=sd->fd;
  5210. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5211. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5212. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5213. return 0;
  5214. }
  5215. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5216. WFIFOW(fd,0)=0x1a6;
  5217. if(sd->status.pet_id <= 0) {
  5218. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5219. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5220. sd->inventory_data[i]->type!=IT_PETEGG ||
  5221. sd->status.inventory[i].amount<=0)
  5222. continue;
  5223. WFIFOW(fd,n*2+4)=i+2;
  5224. n++;
  5225. }
  5226. }
  5227. WFIFOW(fd,2)=4+n*2;
  5228. WFIFOSET(fd,WFIFOW(fd,2));
  5229. sd->menuskill_id = SA_TAMINGMONSTER;
  5230. sd->menuskill_val = -1;
  5231. return 0;
  5232. }
  5233. /*==========================================
  5234. * Sends a specific pet data update.
  5235. * type = 0 -> param = 0 (initial data)
  5236. * type = 1 -> param = intimacy value
  5237. * type = 2 -> param = hungry value
  5238. * type = 3 -> param = accessory id
  5239. * type = 4 -> param = performance number (1-3:normal, 4:special)
  5240. * type = 5 -> param = hairstyle number
  5241. * If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5242. *------------------------------------------*/
  5243. int clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5244. {
  5245. uint8 buf[16];
  5246. nullpo_retr(0, pd);
  5247. WBUFW(buf,0) = 0x1a4;
  5248. WBUFB(buf,2) = type;
  5249. WBUFL(buf,3) = pd->bl.id;
  5250. WBUFL(buf,7) = param;
  5251. if (sd)
  5252. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5253. else
  5254. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5255. return 0;
  5256. }
  5257. int clif_send_petstatus(struct map_session_data *sd)
  5258. {
  5259. int fd;
  5260. struct s_pet *pet;
  5261. nullpo_retr(0, sd);
  5262. nullpo_retr(0, sd->pd);
  5263. fd=sd->fd;
  5264. pet = &sd->pd->pet;
  5265. WFIFOHEAD(fd,packet_len(0x1a2));
  5266. WFIFOW(fd,0)=0x1a2;
  5267. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5268. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5269. WFIFOW(fd,27)=pet->level;
  5270. WFIFOW(fd,29)=pet->hungry;
  5271. WFIFOW(fd,31)=pet->intimate;
  5272. WFIFOW(fd,33)=pet->equip;
  5273. WFIFOSET(fd,packet_len(0x1a2));
  5274. return 0;
  5275. }
  5276. /*==========================================
  5277. *
  5278. *------------------------------------------*/
  5279. int clif_pet_emotion(struct pet_data *pd,int param)
  5280. {
  5281. unsigned char buf[16];
  5282. nullpo_retr(0, pd);
  5283. memset(buf,0,packet_len(0x1aa));
  5284. WBUFW(buf,0)=0x1aa;
  5285. WBUFL(buf,2)=pd->bl.id;
  5286. if(param >= 100 && pd->petDB->talk_convert_class) {
  5287. if(pd->petDB->talk_convert_class < 0)
  5288. return 0;
  5289. else if(pd->petDB->talk_convert_class > 0) {
  5290. param -= (pd->pet.class_ - 100)*100;
  5291. param += (pd->petDB->talk_convert_class - 100)*100;
  5292. }
  5293. }
  5294. WBUFL(buf,6)=param;
  5295. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5296. return 0;
  5297. }
  5298. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5299. {
  5300. int fd;
  5301. nullpo_retr(0, sd);
  5302. fd=sd->fd;
  5303. WFIFOHEAD(fd,packet_len(0x1a3));
  5304. WFIFOW(fd,0)=0x1a3;
  5305. WFIFOB(fd,2)=fail;
  5306. WFIFOW(fd,3)=foodid;
  5307. WFIFOSET(fd,packet_len(0x1a3));
  5308. return 0;
  5309. }
  5310. /*==========================================
  5311. * オートスペル リスト送信
  5312. *------------------------------------------*/
  5313. int clif_autospell(struct map_session_data *sd,int skilllv)
  5314. {
  5315. int fd;
  5316. nullpo_retr(0, sd);
  5317. fd=sd->fd;
  5318. WFIFOHEAD(fd,packet_len(0x1cd));
  5319. WFIFOW(fd, 0)=0x1cd;
  5320. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5321. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5322. else
  5323. WFIFOL(fd,2)= 0x00000000;
  5324. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5325. WFIFOL(fd,6)= MG_COLDBOLT;
  5326. else
  5327. WFIFOL(fd,6)= 0x00000000;
  5328. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5329. WFIFOL(fd,10)= MG_FIREBOLT;
  5330. else
  5331. WFIFOL(fd,10)= 0x00000000;
  5332. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5333. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5334. else
  5335. WFIFOL(fd,14)= 0x00000000;
  5336. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5337. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5338. else
  5339. WFIFOL(fd,18)= 0x00000000;
  5340. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5341. WFIFOL(fd,22)= MG_FIREBALL;
  5342. else
  5343. WFIFOL(fd,22)= 0x00000000;
  5344. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5345. WFIFOL(fd,26)= MG_FROSTDIVER;
  5346. else
  5347. WFIFOL(fd,26)= 0x00000000;
  5348. WFIFOSET(fd,packet_len(0x1cd));
  5349. sd->menuskill_id = SA_AUTOSPELL;
  5350. sd->menuskill_val = skilllv;
  5351. return 0;
  5352. }
  5353. /*==========================================
  5354. * ディボーションの青い糸
  5355. *------------------------------------------*/
  5356. int clif_devotion(struct map_session_data *sd)
  5357. {
  5358. unsigned char buf[56];
  5359. int i,n;
  5360. nullpo_retr(0, sd);
  5361. WBUFW(buf,0)=0x1cf;
  5362. WBUFL(buf,2)=sd->bl.id;
  5363. for(i=0,n=0;i<5;i++) {
  5364. if (!sd->devotion[i])
  5365. continue;
  5366. WBUFL(buf,6+4*n)=sd->devotion[i];
  5367. n++;
  5368. }
  5369. for(;n<5;n++)
  5370. WBUFL(buf,6+4*n)=0;
  5371. WBUFB(buf,26)=8;
  5372. WBUFB(buf,27)=0;
  5373. clif_send(buf,packet_len(0x1cf),&sd->bl,AREA);
  5374. return 0;
  5375. }
  5376. int clif_marionette(struct block_list *src, struct block_list *target)
  5377. {
  5378. unsigned char buf[56];
  5379. int n;
  5380. WBUFW(buf,0)=0x1cf;
  5381. WBUFL(buf,2)=src->id;
  5382. for(n=0;n<5;n++)
  5383. WBUFL(buf,6+4*n)=0;
  5384. if (target) //The target goes on the second slot.
  5385. WBUFL(buf,6+4) = target->id;
  5386. WBUFB(buf,26)=8;
  5387. WBUFB(buf,27)=0;
  5388. clif_send(buf,packet_len(0x1cf),src,AREA);
  5389. return 0;
  5390. }
  5391. /*==========================================
  5392. * 氣球
  5393. *------------------------------------------*/
  5394. int clif_spiritball(struct map_session_data *sd)
  5395. {
  5396. unsigned char buf[16];
  5397. nullpo_retr(0, sd);
  5398. WBUFW(buf,0)=0x1d0;
  5399. WBUFL(buf,2)=sd->bl.id;
  5400. WBUFW(buf,6)=sd->spiritball;
  5401. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5402. return 0;
  5403. }
  5404. /*==========================================
  5405. *
  5406. *------------------------------------------*/
  5407. int clif_combo_delay(struct block_list *bl,int wait)
  5408. {
  5409. unsigned char buf[32];
  5410. nullpo_retr(0, bl);
  5411. WBUFW(buf,0)=0x1d2;
  5412. WBUFL(buf,2)=bl->id;
  5413. WBUFL(buf,6)=wait;
  5414. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5415. return 0;
  5416. }
  5417. /*==========================================
  5418. *白刃取り
  5419. *------------------------------------------*/
  5420. int clif_bladestop(struct block_list *src,struct block_list *dst,
  5421. int _bool)
  5422. {
  5423. unsigned char buf[32];
  5424. nullpo_retr(0, src);
  5425. nullpo_retr(0, dst);
  5426. WBUFW(buf,0)=0x1d1;
  5427. WBUFL(buf,2)=src->id;
  5428. WBUFL(buf,6)=dst->id;
  5429. WBUFL(buf,10)=_bool;
  5430. clif_send(buf,packet_len(0x1d1),src,AREA);
  5431. return 0;
  5432. }
  5433. /*==========================================
  5434. * MVPエフェクト
  5435. *------------------------------------------*/
  5436. int clif_mvp_effect(struct map_session_data *sd)
  5437. {
  5438. unsigned char buf[16];
  5439. nullpo_retr(0, sd);
  5440. WBUFW(buf,0)=0x10c;
  5441. WBUFL(buf,2)=sd->bl.id;
  5442. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5443. return 0;
  5444. }
  5445. /*==========================================
  5446. * MVPアイテム所得
  5447. *------------------------------------------*/
  5448. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5449. {
  5450. int view,fd;
  5451. nullpo_retr(0, sd);
  5452. fd=sd->fd;
  5453. WFIFOHEAD(fd,packet_len(0x10a));
  5454. WFIFOW(fd,0)=0x10a;
  5455. if((view = itemdb_viewid(nameid)) > 0)
  5456. WFIFOW(fd,2)=view;
  5457. else
  5458. WFIFOW(fd,2)=nameid;
  5459. WFIFOSET(fd,packet_len(0x10a));
  5460. return 0;
  5461. }
  5462. /*==========================================
  5463. * MVP経験値所得
  5464. *------------------------------------------*/
  5465. int clif_mvp_exp(struct map_session_data *sd,unsigned long exp)
  5466. {
  5467. int fd;
  5468. nullpo_retr(0, sd);
  5469. fd=sd->fd;
  5470. WFIFOHEAD(fd,packet_len(0x10b));
  5471. WFIFOW(fd,0)=0x10b;
  5472. WFIFOL(fd,2)=exp;
  5473. WFIFOSET(fd,packet_len(0x10b));
  5474. return 0;
  5475. }
  5476. /*==========================================
  5477. * ギルド作成可否通知
  5478. *------------------------------------------*/
  5479. int clif_guild_created(struct map_session_data *sd,int flag)
  5480. {
  5481. int fd;
  5482. nullpo_retr(0, sd);
  5483. fd=sd->fd;
  5484. WFIFOHEAD(fd,packet_len(0x167));
  5485. WFIFOW(fd,0)=0x167;
  5486. WFIFOB(fd,2)=flag;
  5487. WFIFOSET(fd,packet_len(0x167));
  5488. return 0;
  5489. }
  5490. /*==========================================
  5491. * ギルド所属通知
  5492. *------------------------------------------*/
  5493. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  5494. {
  5495. int ps,fd;
  5496. nullpo_retr(0, sd);
  5497. nullpo_retr(0, g);
  5498. fd=sd->fd;
  5499. ps=guild_getposition(sd,g);
  5500. WFIFOHEAD(fd,packet_len(0x16c));
  5501. memset(WFIFOP(fd,0),0,packet_len(0x16c));
  5502. WFIFOW(fd,0)=0x16c;
  5503. WFIFOL(fd,2)=g->guild_id;
  5504. WFIFOL(fd,6)=g->emblem_id;
  5505. WFIFOL(fd,10)=g->position[ps].mode;
  5506. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5507. WFIFOSET(fd,packet_len(0x16c));
  5508. return 0;
  5509. }
  5510. /*==========================================
  5511. * ギルドメンバログイン通知
  5512. *------------------------------------------*/
  5513. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5514. {
  5515. unsigned char buf[64];
  5516. nullpo_retr(0, g);
  5517. WBUFW(buf, 0)=0x16d;
  5518. WBUFL(buf, 2)=g->member[idx].account_id;
  5519. WBUFL(buf, 6)=g->member[idx].char_id;
  5520. WBUFL(buf,10)=flag;
  5521. if(g->member[idx].sd==NULL){
  5522. struct map_session_data *sd=guild_getavailablesd(g);
  5523. if(sd!=NULL)
  5524. clif_send(buf,packet_len(0x16d),&sd->bl,GUILD);
  5525. }else
  5526. clif_send(buf,packet_len(0x16d),&g->member[idx].sd->bl,GUILD_WOS);
  5527. return 0;
  5528. }
  5529. // Function `clif_guild_memberlogin_notice` sends info about
  5530. // logins and logouts of a guild member to the rest members.
  5531. // But at the 1st time (after a player login or map changing)
  5532. // the client won't show the message.
  5533. // So I suggest use this function for sending "first-time-info"
  5534. // to some player on entering the game or changing location.
  5535. // At next time the client would always show the message.
  5536. // The function sends all the statuses in the single packet
  5537. // to economize traffic. [LuzZza]
  5538. int clif_guild_send_onlineinfo(struct map_session_data *sd)
  5539. {
  5540. struct guild *g;
  5541. unsigned char buf[14*128];
  5542. int i, count=0, p_len;
  5543. nullpo_retr(0, sd);
  5544. p_len = packet_len(0x16d);
  5545. if(!(g = guild_search(sd->status.guild_id)))
  5546. return 0;
  5547. for(i=0; i<g->max_member; i++) {
  5548. if(g->member[i].account_id > 0 &&
  5549. g->member[i].account_id != sd->status.account_id) {
  5550. WBUFW(buf,count*p_len) = 0x16d;
  5551. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5552. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5553. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5554. count++;
  5555. }
  5556. }
  5557. clif_send(buf, p_len*count, &sd->bl, SELF);
  5558. return 0;
  5559. }
  5560. /*==========================================
  5561. * ギルドマスター通知(14dへの応答)
  5562. *------------------------------------------*/
  5563. int clif_guild_masterormember(struct map_session_data *sd)
  5564. {
  5565. int fd;
  5566. nullpo_retr(0, sd);
  5567. fd=sd->fd;
  5568. WFIFOHEAD(fd,packet_len(0x14e));
  5569. WFIFOW(fd,0) = 0x14e;
  5570. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  5571. WFIFOSET(fd,packet_len(0x14e));
  5572. return 0;
  5573. }
  5574. /*==========================================
  5575. * Basic Info (Territories [Valaris])
  5576. *------------------------------------------*/
  5577. int clif_guild_basicinfo(struct map_session_data *sd)
  5578. {
  5579. int fd,i,t;
  5580. struct guild *g;
  5581. struct guild_castle *gc=NULL;
  5582. nullpo_retr(0, sd);
  5583. fd=sd->fd;
  5584. g=guild_search(sd->status.guild_id);
  5585. if(g==NULL)
  5586. return 0;
  5587. WFIFOHEAD(fd,packet_len(0x1b6));
  5588. WFIFOW(fd, 0)=0x1b6;//0x150;
  5589. WFIFOL(fd, 2)=g->guild_id;
  5590. WFIFOL(fd, 6)=g->guild_lv;
  5591. WFIFOL(fd,10)=g->connect_member;
  5592. WFIFOL(fd,14)=g->max_member;
  5593. WFIFOL(fd,18)=g->average_lv;
  5594. WFIFOL(fd,22)=g->exp;
  5595. WFIFOL(fd,26)=g->next_exp;
  5596. WFIFOL(fd,30)=0; // Tax Points
  5597. WFIFOL(fd,34)=0; // Tendency: (left) Vulgar [-100,100] Famed (right)
  5598. WFIFOL(fd,38)=0; // Tendency: (down) Wicked [-100,100] Righteous (up)
  5599. WFIFOL(fd,42)=g->emblem_id;
  5600. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5601. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5602. for(i = 0, t = 0; i < MAX_GUILDCASTLE; i++)
  5603. {
  5604. gc = guild_castle_search(i);
  5605. if(gc && g->guild_id == gc->guild_id)
  5606. t++;
  5607. }
  5608. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20); // "'N' castles"
  5609. WFIFOSET(fd,packet_len(WFIFOW(fd,0)));
  5610. return 0;
  5611. }
  5612. /*==========================================
  5613. * ギルド同盟/敵対情報
  5614. *------------------------------------------*/
  5615. int clif_guild_allianceinfo(struct map_session_data *sd)
  5616. {
  5617. int fd,i,c;
  5618. struct guild *g;
  5619. nullpo_retr(0, sd);
  5620. fd=sd->fd;
  5621. g=guild_search(sd->status.guild_id);
  5622. if(g==NULL)
  5623. return 0;
  5624. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5625. WFIFOW(fd, 0)=0x14c;
  5626. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5627. struct guild_alliance *a=&g->alliance[i];
  5628. if(a->guild_id>0){
  5629. WFIFOL(fd,c*32+4)=a->opposition;
  5630. WFIFOL(fd,c*32+8)=a->guild_id;
  5631. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5632. c++;
  5633. }
  5634. }
  5635. WFIFOW(fd, 2)=c*32+4;
  5636. WFIFOSET(fd,WFIFOW(fd,2));
  5637. return 0;
  5638. }
  5639. /*==========================================
  5640. * ギルドメンバーリスト
  5641. *------------------------------------------*/
  5642. int clif_guild_memberlist(struct map_session_data *sd)
  5643. {
  5644. int fd;
  5645. int i,c;
  5646. struct guild *g;
  5647. nullpo_retr(0, sd);
  5648. fd=sd->fd;
  5649. if (!fd)
  5650. return 0;
  5651. g=guild_search(sd->status.guild_id);
  5652. if(g==NULL)
  5653. return 0;
  5654. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5655. WFIFOW(fd, 0)=0x154;
  5656. for(i=0,c=0;i<g->max_member;i++){
  5657. struct guild_member *m=&g->member[i];
  5658. if(m->account_id==0)
  5659. continue;
  5660. WFIFOL(fd,c*104+ 4)=m->account_id;
  5661. WFIFOL(fd,c*104+ 8)=m->char_id;
  5662. WFIFOW(fd,c*104+12)=m->hair;
  5663. WFIFOW(fd,c*104+14)=m->hair_color;
  5664. WFIFOW(fd,c*104+16)=m->gender;
  5665. WFIFOW(fd,c*104+18)=m->class_;
  5666. WFIFOW(fd,c*104+20)=m->lv;
  5667. WFIFOL(fd,c*104+22)=m->exp;
  5668. WFIFOL(fd,c*104+26)=m->online;
  5669. WFIFOL(fd,c*104+30)=m->position;
  5670. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5671. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5672. c++;
  5673. }
  5674. WFIFOW(fd, 2)=c*104+4;
  5675. WFIFOSET(fd,WFIFOW(fd,2));
  5676. return 0;
  5677. }
  5678. /*==========================================
  5679. * ギルド役職名リスト
  5680. *------------------------------------------*/
  5681. int clif_guild_positionnamelist(struct map_session_data *sd)
  5682. {
  5683. int i,fd;
  5684. struct guild *g;
  5685. nullpo_retr(0, sd);
  5686. fd=sd->fd;
  5687. g=guild_search(sd->status.guild_id);
  5688. if(g==NULL)
  5689. return 0;
  5690. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5691. WFIFOW(fd, 0)=0x166;
  5692. for(i=0;i<MAX_GUILDPOSITION;i++){
  5693. WFIFOL(fd,i*28+4)=i;
  5694. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5695. }
  5696. WFIFOW(fd,2)=i*28+4;
  5697. WFIFOSET(fd,WFIFOW(fd,2));
  5698. return 0;
  5699. }
  5700. /*==========================================
  5701. * ギルド役職情報リスト
  5702. *------------------------------------------*/
  5703. int clif_guild_positioninfolist(struct map_session_data *sd)
  5704. {
  5705. int i,fd;
  5706. struct guild *g;
  5707. nullpo_retr(0, sd);
  5708. fd=sd->fd;
  5709. g=guild_search(sd->status.guild_id);
  5710. if(g==NULL)
  5711. return 0;
  5712. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5713. WFIFOW(fd, 0)=0x160;
  5714. for(i=0;i<MAX_GUILDPOSITION;i++){
  5715. struct guild_position *p=&g->position[i];
  5716. WFIFOL(fd,i*16+ 4)=i;
  5717. WFIFOL(fd,i*16+ 8)=p->mode;
  5718. WFIFOL(fd,i*16+12)=i;
  5719. WFIFOL(fd,i*16+16)=p->exp_mode;
  5720. }
  5721. WFIFOW(fd, 2)=i*16+4;
  5722. WFIFOSET(fd,WFIFOW(fd,2));
  5723. return 0;
  5724. }
  5725. /*==========================================
  5726. * ギルド役職変更通知
  5727. *------------------------------------------*/
  5728. int clif_guild_positionchanged(struct guild *g,int idx)
  5729. {
  5730. struct map_session_data *sd;
  5731. unsigned char buf[128];
  5732. nullpo_retr(0, g);
  5733. WBUFW(buf, 0)=0x174;
  5734. WBUFW(buf, 2)=44;
  5735. WBUFL(buf, 4)=idx;
  5736. WBUFL(buf, 8)=g->position[idx].mode;
  5737. WBUFL(buf,12)=idx;
  5738. WBUFL(buf,16)=g->position[idx].exp_mode;
  5739. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  5740. if( (sd=guild_getavailablesd(g))!=NULL )
  5741. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5742. return 0;
  5743. }
  5744. /*==========================================
  5745. * ギルドメンバ変更通知
  5746. *------------------------------------------*/
  5747. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  5748. {
  5749. struct map_session_data *sd;
  5750. unsigned char buf[64];
  5751. nullpo_retr(0, g);
  5752. WBUFW(buf, 0)=0x156;
  5753. WBUFW(buf, 2)=16;
  5754. WBUFL(buf, 4)=g->member[idx].account_id;
  5755. WBUFL(buf, 8)=g->member[idx].char_id;
  5756. WBUFL(buf,12)=g->member[idx].position;
  5757. if( (sd=guild_getavailablesd(g))!=NULL )
  5758. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5759. return 0;
  5760. }
  5761. /*==========================================
  5762. * ギルドエンブレム送信
  5763. *------------------------------------------*/
  5764. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  5765. {
  5766. int fd;
  5767. nullpo_retr(0, sd);
  5768. nullpo_retr(0, g);
  5769. fd=sd->fd;
  5770. if(g->emblem_len<=0)
  5771. return 0;
  5772. WFIFOHEAD(fd,g->emblem_len+12);
  5773. WFIFOW(fd,0)=0x152;
  5774. WFIFOW(fd,2)=g->emblem_len+12;
  5775. WFIFOL(fd,4)=g->guild_id;
  5776. WFIFOL(fd,8)=g->emblem_id;
  5777. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  5778. WFIFOSET(fd,WFIFOW(fd,2));
  5779. return 0;
  5780. }
  5781. /*==========================================
  5782. * Send guild skills
  5783. *------------------------------------------*/
  5784. int clif_guild_skillinfo(struct map_session_data* sd)
  5785. {
  5786. int fd;
  5787. struct guild* g;
  5788. int i,c;
  5789. nullpo_retr(0, sd);
  5790. fd = sd->fd;
  5791. g = guild_search(sd->status.guild_id);
  5792. if(g == NULL)
  5793. return 0;
  5794. WFIFOHEAD(fd, MAX_GUILDSKILL * 37 + 6);
  5795. WFIFOW(fd,0) = 0x0162;
  5796. WFIFOW(fd,4) = g->skill_point;
  5797. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  5798. {
  5799. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  5800. {
  5801. int id = g->skill[i].id;
  5802. WFIFOW(fd,c*37+ 6) = id;
  5803. WFIFOW(fd,c*37+ 8) = skill_get_inf(id);
  5804. WFIFOW(fd,c*37+10) = 0;
  5805. WFIFOW(fd,c*37+12) = g->skill[i].lv;
  5806. WFIFOW(fd,c*37+14) = skill_get_sp(id, g->skill[i].lv);
  5807. WFIFOW(fd,c*37+16) = skill_get_range(id, g->skill[i].lv);
  5808. strncpy((char*)WFIFOP(fd,c*37+18), skill_get_name(id), NAME_LENGTH);
  5809. WFIFOB(fd,c*37+42)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  5810. c++;
  5811. }
  5812. }
  5813. WFIFOW(fd,2) = c*37 + 6;
  5814. WFIFOSET(fd,WFIFOW(fd,2));
  5815. return 0;
  5816. }
  5817. /*==========================================
  5818. * Sends guild notice to client
  5819. * R 016f <str1z>.60B <str2z>.120B
  5820. *------------------------------------------*/
  5821. int clif_guild_notice(struct map_session_data* sd, struct guild* g)
  5822. {
  5823. int fd;
  5824. nullpo_retr(0, sd);
  5825. nullpo_retr(0, g);
  5826. fd = sd->fd;
  5827. if ( !session_isActive(fd) )
  5828. return 0;
  5829. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  5830. return 0;
  5831. WFIFOHEAD(fd,packet_len(0x16f));
  5832. WFIFOW(fd,0) = 0x16f;
  5833. memcpy(WFIFOP(fd,2), g->mes1, 60);
  5834. memcpy(WFIFOP(fd,62), g->mes2, 120);
  5835. WFIFOSET(fd,packet_len(0x16f));
  5836. return 0;
  5837. }
  5838. /*==========================================
  5839. * ギルドメンバ勧誘
  5840. *------------------------------------------*/
  5841. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  5842. {
  5843. int fd;
  5844. nullpo_retr(0, sd);
  5845. nullpo_retr(0, g);
  5846. fd=sd->fd;
  5847. WFIFOHEAD(fd,packet_len(0x16a));
  5848. WFIFOW(fd,0)=0x16a;
  5849. WFIFOL(fd,2)=g->guild_id;
  5850. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  5851. WFIFOSET(fd,packet_len(0x16a));
  5852. return 0;
  5853. }
  5854. /*==========================================
  5855. * ギルドメンバ勧誘結果
  5856. *------------------------------------------*/
  5857. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  5858. {
  5859. int fd;
  5860. nullpo_retr(0, sd);
  5861. fd=sd->fd;
  5862. WFIFOHEAD(fd,packet_len(0x169));
  5863. WFIFOW(fd,0)=0x169;
  5864. WFIFOB(fd,2)=flag;
  5865. WFIFOSET(fd,packet_len(0x169));
  5866. return 0;
  5867. }
  5868. /*==========================================
  5869. * ギルドメンバ脱退通知
  5870. *------------------------------------------*/
  5871. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  5872. {
  5873. unsigned char buf[128];
  5874. nullpo_retr(0, sd);
  5875. WBUFW(buf, 0)=0x15a;
  5876. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5877. memcpy(WBUFP(buf,26),mes,40);
  5878. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD);
  5879. return 0;
  5880. }
  5881. /*==========================================
  5882. * ギルドメンバ追放通知
  5883. *------------------------------------------*/
  5884. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,
  5885. int account_id)
  5886. {
  5887. unsigned char buf[128];
  5888. nullpo_retr(0, sd);
  5889. WBUFW(buf, 0)=0x15c;
  5890. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5891. memcpy(WBUFP(buf,26),mes,40);
  5892. memcpy(WBUFP(buf,66),"dummy",NAME_LENGTH);
  5893. clif_send(buf,packet_len(0x15c),&sd->bl,GUILD);
  5894. return 0;
  5895. }
  5896. /*==========================================
  5897. * ギルド追放メンバリスト
  5898. *------------------------------------------*/
  5899. int clif_guild_expulsionlist(struct map_session_data *sd)
  5900. {
  5901. int fd;
  5902. int i,c;
  5903. struct guild *g;
  5904. nullpo_retr(0, sd);
  5905. fd=sd->fd;
  5906. g=guild_search(sd->status.guild_id);
  5907. if(g==NULL)
  5908. return 0;
  5909. WFIFOHEAD(fd,MAX_GUILDEXPULSION * 88 + 4);
  5910. WFIFOW(fd,0)=0x163;
  5911. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  5912. struct guild_expulsion *e=&g->expulsion[i];
  5913. if(e->account_id>0){
  5914. memcpy(WFIFOP(fd,c*88+ 4),e->name,NAME_LENGTH);
  5915. memcpy(WFIFOP(fd,c*88+28),e->acc,24);
  5916. memcpy(WFIFOP(fd,c*88+52),e->mes,44);
  5917. c++;
  5918. }
  5919. }
  5920. WFIFOW(fd,2)=c*88+4;
  5921. WFIFOSET(fd,WFIFOW(fd,2));
  5922. return 0;
  5923. }
  5924. /*==========================================
  5925. * ギルド会話
  5926. *------------------------------------------*/
  5927. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  5928. {
  5929. struct map_session_data *sd;
  5930. unsigned char *buf;
  5931. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  5932. WBUFW(buf, 0) = 0x17f;
  5933. WBUFW(buf, 2) = len + 4;
  5934. memcpy(WBUFP(buf,4), mes, len);
  5935. if ((sd = guild_getavailablesd(g)) != NULL)
  5936. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  5937. if(buf) aFree(buf);
  5938. return 0;
  5939. }
  5940. /*==========================================
  5941. * ギルドスキル割り振り通知
  5942. *------------------------------------------*/
  5943. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  5944. {
  5945. int fd;
  5946. nullpo_retr(0, sd);
  5947. fd=sd->fd;
  5948. WFIFOHEAD(fd,11);
  5949. WFIFOW(fd,0) = 0x10e;
  5950. WFIFOW(fd,2) = skill_num;
  5951. WFIFOW(fd,4) = lv;
  5952. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  5953. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  5954. WFIFOB(fd,10) = 1;
  5955. WFIFOSET(fd,11);
  5956. return 0;
  5957. }
  5958. /*==========================================
  5959. * ギルド同盟要請
  5960. *------------------------------------------*/
  5961. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  5962. {
  5963. int fd;
  5964. nullpo_retr(0, sd);
  5965. fd=sd->fd;
  5966. WFIFOHEAD(fd,packet_len(0x171));
  5967. WFIFOW(fd,0)=0x171;
  5968. WFIFOL(fd,2)=account_id;
  5969. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  5970. WFIFOSET(fd,packet_len(0x171));
  5971. return 0;
  5972. }
  5973. /*==========================================
  5974. * Reply to alliance request.
  5975. * Flag values are:
  5976. * 0: Already allied.
  5977. * 1: You rejected the offer.
  5978. * 2: You accepted the offer.
  5979. * 3: They have too any alliances
  5980. * 4: You have too many alliances.
  5981. *------------------------------------------*/
  5982. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  5983. {
  5984. int fd;
  5985. nullpo_retr(0, sd);
  5986. fd=sd->fd;
  5987. WFIFOHEAD(fd,packet_len(0x173));
  5988. WFIFOW(fd,0)=0x173;
  5989. WFIFOL(fd,2)=flag;
  5990. WFIFOSET(fd,packet_len(0x173));
  5991. return 0;
  5992. }
  5993. /*==========================================
  5994. * ギルド関係解消通知
  5995. *------------------------------------------*/
  5996. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  5997. {
  5998. int fd;
  5999. nullpo_retr(0, sd);
  6000. fd = sd->fd;
  6001. if (fd <= 0)
  6002. return 0;
  6003. WFIFOHEAD(fd,packet_len(0x184));
  6004. WFIFOW(fd,0)=0x184;
  6005. WFIFOL(fd,2)=guild_id;
  6006. WFIFOL(fd,6)=flag;
  6007. WFIFOSET(fd,packet_len(0x184));
  6008. return 0;
  6009. }
  6010. /*==========================================
  6011. * ギルド敵対結果
  6012. *------------------------------------------*/
  6013. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6014. {
  6015. int fd;
  6016. nullpo_retr(0, sd);
  6017. fd=sd->fd;
  6018. WFIFOHEAD(fd,packet_len(0x181));
  6019. WFIFOW(fd,0)=0x181;
  6020. WFIFOB(fd,2)=flag;
  6021. WFIFOSET(fd,packet_len(0x181));
  6022. return 0;
  6023. }
  6024. /*==========================================
  6025. * ギルド関係追加
  6026. *------------------------------------------*/
  6027. /*int clif_guild_allianceadded(struct guild *g,int idx)
  6028. {
  6029. unsigned char buf[64];
  6030. WBUFW(fd,0)=0x185;
  6031. WBUFL(fd,2)=g->alliance[idx].opposition;
  6032. WBUFL(fd,6)=g->alliance[idx].guild_id;
  6033. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  6034. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  6035. return 0;
  6036. }*/
  6037. /*==========================================
  6038. * ギルド解散通知
  6039. *------------------------------------------*/
  6040. int clif_guild_broken(struct map_session_data *sd,int flag)
  6041. {
  6042. int fd;
  6043. nullpo_retr(0, sd);
  6044. fd=sd->fd;
  6045. WFIFOHEAD(fd,packet_len(0x15e));
  6046. WFIFOW(fd,0)=0x15e;
  6047. WFIFOL(fd,2)=flag;
  6048. WFIFOSET(fd,packet_len(0x15e));
  6049. return 0;
  6050. }
  6051. /*==========================================
  6052. * エモーション
  6053. *------------------------------------------*/
  6054. void clif_emotion(struct block_list *bl,int type)
  6055. {
  6056. unsigned char buf[8];
  6057. nullpo_retv(bl);
  6058. WBUFW(buf,0)=0xc0;
  6059. WBUFL(buf,2)=bl->id;
  6060. WBUFB(buf,6)=type;
  6061. clif_send(buf,packet_len(0xc0),bl,AREA);
  6062. }
  6063. /*==========================================
  6064. * トーキーボックス
  6065. *------------------------------------------*/
  6066. void clif_talkiebox(struct block_list* bl, const char* talkie)
  6067. {
  6068. unsigned char buf[86];
  6069. nullpo_retv(bl);
  6070. WBUFW(buf,0) = 0x191;
  6071. WBUFL(buf,2) = bl->id;
  6072. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6073. clif_send(buf,packet_len(0x191),bl,AREA);
  6074. }
  6075. /*==========================================
  6076. * 結婚エフェクト
  6077. *------------------------------------------*/
  6078. void clif_wedding_effect(struct block_list *bl)
  6079. {
  6080. unsigned char buf[6];
  6081. nullpo_retv(bl);
  6082. WBUFW(buf,0) = 0x1ea;
  6083. WBUFL(buf,2) = bl->id;
  6084. clif_send(buf, packet_len(0x1ea), bl, AREA);
  6085. }
  6086. /*==========================================
  6087. * あなたに逢いたい使用時名前叫び
  6088. *------------------------------------------
  6089. void clif_callpartner(struct map_session_data *sd)
  6090. {
  6091. unsigned char buf[26];
  6092. char *p;
  6093. nullpo_retv(sd);
  6094. if(sd->status.partner_id){
  6095. WBUFW(buf,0)=0x1e6;
  6096. p = map_charid2nick(sd->status.partner_id);
  6097. if(p){
  6098. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6099. }else{
  6100. map_reqchariddb(sd,sd->status.partner_id);
  6101. chrif_searchcharid(sd->status.partner_id);
  6102. WBUFB(buf,2) = 0;
  6103. }
  6104. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  6105. }
  6106. return;
  6107. }
  6108. */
  6109. /*==========================================
  6110. * Adopt baby [Celest]
  6111. *------------------------------------------*/
  6112. void clif_adopt_process(struct map_session_data *sd)
  6113. {
  6114. int fd;
  6115. nullpo_retv(sd);
  6116. fd=sd->fd;
  6117. WFIFOHEAD(fd,packet_len(0x1f8));
  6118. WFIFOW(fd,0)=0x1f8;
  6119. WFIFOSET(fd,packet_len(0x1f8));
  6120. }
  6121. /*==========================================
  6122. * Marry [DracoRPG]
  6123. *------------------------------------------*/
  6124. void clif_marriage_process(struct map_session_data *sd)
  6125. {
  6126. int fd;
  6127. nullpo_retv(sd);
  6128. fd=sd->fd;
  6129. WFIFOHEAD(fd,packet_len(0x1e4));
  6130. WFIFOW(fd,0)=0x1e4;
  6131. WFIFOSET(fd,packet_len(0x1e4));
  6132. }
  6133. /*==========================================
  6134. * Notice of divorce
  6135. *------------------------------------------*/
  6136. void clif_divorced(struct map_session_data* sd, const char* name)
  6137. {
  6138. int fd;
  6139. nullpo_retv(sd);
  6140. fd=sd->fd;
  6141. WFIFOHEAD(fd,packet_len(0x205));
  6142. WFIFOW(fd,0)=0x205;
  6143. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6144. WFIFOSET(fd, packet_len(0x205));
  6145. }
  6146. /*==========================================
  6147. *
  6148. *------------------------------------------*/
  6149. void clif_parse_ReqAdopt(int fd, struct map_session_data *sd)
  6150. {
  6151. nullpo_retv(sd);
  6152. WFIFOHEAD(fd,packet_len(0x1f6));
  6153. WFIFOW(fd,0)=0x1f6;
  6154. WFIFOSET(fd, packet_len(0x1f6));
  6155. }
  6156. /*==========================================
  6157. *
  6158. *------------------------------------------*/
  6159. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd)
  6160. {
  6161. nullpo_retv(sd);
  6162. WFIFOHEAD(fd,packet_len(0x1e2));
  6163. WFIFOW(fd,0)=0x1e2;
  6164. WFIFOSET(fd, packet_len(0x1e2));
  6165. }
  6166. /*==========================================
  6167. *
  6168. *------------------------------------------*/
  6169. int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  6170. {
  6171. int fd;
  6172. nullpo_retr(0, sd);
  6173. fd = sd->fd;
  6174. if (!fd || !len) return 0; //Disconnected player.
  6175. WFIFOHEAD(fd, len+5);
  6176. WFIFOW(fd, 0) = 0x17f;
  6177. WFIFOW(fd, 2) = len + 5;
  6178. memcpy(WFIFOP(fd,4), mes, len);
  6179. WFIFOSET(fd, WFIFOW(fd,2));
  6180. return 1;
  6181. }
  6182. /*==========================================
  6183. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6184. *------------------------------------------*/
  6185. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  6186. {
  6187. unsigned char buf[1024];
  6188. if (!len) return;
  6189. WBUFW(buf, 0) = 0x17f;
  6190. WBUFW(buf, 2) = len + 5;
  6191. memcpy(WBUFP(buf,4), mes, len);
  6192. clif_send(buf, WBUFW(buf,2), src, target);
  6193. return;
  6194. }
  6195. /*==========================================
  6196. *
  6197. *------------------------------------------*/
  6198. int clif_GM_kickack(struct map_session_data *sd, int id)
  6199. {
  6200. int fd;
  6201. nullpo_retr(0, sd);
  6202. fd = sd->fd;
  6203. WFIFOHEAD(fd,packet_len(0xcd));
  6204. WFIFOW(fd,0) = 0xcd;
  6205. WFIFOL(fd,2) = id;
  6206. WFIFOSET(fd, packet_len(0xcd));
  6207. return 0;
  6208. }
  6209. void clif_parse_QuitGame(int fd,struct map_session_data *sd);
  6210. int clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd,int type)
  6211. {
  6212. int fd = tsd->fd;
  6213. WFIFOHEAD(fd,packet_len(0x18b));
  6214. if(type)
  6215. clif_GM_kickack(sd,tsd->status.account_id);
  6216. if (!fd) {
  6217. map_quit(tsd);
  6218. return 0;
  6219. }
  6220. WFIFOW(fd,0) = 0x18b;
  6221. WFIFOW(fd,2) = 0;
  6222. WFIFOSET(fd,packet_len(0x18b));
  6223. clif_setwaitclose(fd);
  6224. return 0;
  6225. }
  6226. int clif_GM_silence(struct map_session_data *sd, struct map_session_data *tsd, int type)
  6227. {
  6228. int fd;
  6229. nullpo_retr(0, sd);
  6230. nullpo_retr(0, tsd);
  6231. fd = tsd->fd;
  6232. if (fd <= 0)
  6233. return 0;
  6234. WFIFOHEAD(fd,packet_len(0x14b));
  6235. WFIFOW(fd,0) = 0x14b;
  6236. WFIFOB(fd,2) = 0;
  6237. memcpy(WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6238. WFIFOSET(fd, packet_len(0x14b));
  6239. return 0;
  6240. }
  6241. /*==========================================
  6242. *
  6243. *------------------------------------------*/
  6244. int clif_timedout(struct map_session_data *sd)
  6245. {
  6246. nullpo_retr(0, sd);
  6247. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' timed out.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id);
  6248. clif_authfail_fd(sd->fd,3); // Even if player is not on we still send anyway
  6249. clif_setwaitclose(sd->fd); // Set session to EOF
  6250. return 0;
  6251. }
  6252. /*==========================================
  6253. * Wis拒否許可応答
  6254. *------------------------------------------*/
  6255. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6256. {
  6257. int fd;
  6258. nullpo_retr(0, sd);
  6259. fd=sd->fd;
  6260. WFIFOHEAD(fd,packet_len(0xd1));
  6261. WFIFOW(fd,0)=0xd1;
  6262. WFIFOB(fd,2)=type;
  6263. WFIFOB(fd,3)=flag;
  6264. WFIFOSET(fd,packet_len(0xd1));
  6265. return 0;
  6266. }
  6267. /*==========================================
  6268. * Wis全拒否許可応答
  6269. *------------------------------------------*/
  6270. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6271. {
  6272. int fd;
  6273. nullpo_retr(0, sd);
  6274. fd=sd->fd;
  6275. WFIFOHEAD(fd,packet_len(0xd2));
  6276. WFIFOW(fd,0)=0xd2;
  6277. WFIFOB(fd,2)=type;
  6278. WFIFOB(fd,3)=flag;
  6279. WFIFOSET(fd,packet_len(0xd2));
  6280. return 0;
  6281. }
  6282. /*==========================================
  6283. * サウンドエフェクト
  6284. *------------------------------------------*/
  6285. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6286. {
  6287. int fd;
  6288. nullpo_retv(sd);
  6289. nullpo_retv(bl);
  6290. fd = sd->fd;
  6291. WFIFOHEAD(fd,packet_len(0x1d3));
  6292. WFIFOW(fd,0) = 0x1d3;
  6293. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6294. WFIFOB(fd,26) = type;
  6295. WFIFOL(fd,27) = 0;
  6296. WFIFOL(fd,31) = bl->id;
  6297. WFIFOSET(fd,packet_len(0x1d3));
  6298. return;
  6299. }
  6300. int clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6301. {
  6302. unsigned char buf[40];
  6303. nullpo_retr(0, bl);
  6304. WBUFW(buf,0) = 0x1d3;
  6305. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6306. WBUFB(buf,26) = type;
  6307. WBUFL(buf,27) = 0;
  6308. WBUFL(buf,31) = bl->id;
  6309. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6310. return 0;
  6311. }
  6312. // displaying special effects (npcs, weather, etc) [Valaris]
  6313. int clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6314. {
  6315. unsigned char buf[24];
  6316. nullpo_retr(0, bl);
  6317. memset(buf, 0, packet_len(0x1f3));
  6318. WBUFW(buf,0) = 0x1f3;
  6319. WBUFL(buf,2) = bl->id;
  6320. WBUFL(buf,6) = type;
  6321. clif_send(buf, packet_len(0x1f3), bl, target);
  6322. if (disguised(bl)) {
  6323. WBUFL(buf,2) = -bl->id;
  6324. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6325. }
  6326. return 0;
  6327. }
  6328. // messages (from mobs/npcs) [Valaris]
  6329. int clif_message(struct block_list* bl, const char* msg)
  6330. {
  6331. unsigned short msg_len = strlen(msg) + 1;
  6332. uint8 buf[256];
  6333. nullpo_retr(0, bl);
  6334. WBUFW(buf,0) = 0x8d;
  6335. WBUFW(buf,2) = msg_len + 8;
  6336. WBUFL(buf,4) = bl->id;
  6337. memcpy(WBUFP(buf,8), msg, msg_len);
  6338. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6339. return 0;
  6340. }
  6341. // refresh the client's screen, getting rid of any effects
  6342. int clif_refresh(struct map_session_data *sd)
  6343. {
  6344. nullpo_retr(-1, sd);
  6345. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6346. clif_inventorylist(sd);
  6347. if(pc_iscarton(sd)) {
  6348. clif_cartlist(sd);
  6349. clif_updatestatus(sd,SP_CARTINFO);
  6350. }
  6351. clif_updatestatus(sd,SP_MAXWEIGHT);
  6352. clif_updatestatus(sd,SP_WEIGHT);
  6353. clif_updatestatus(sd,SP_STR);
  6354. clif_updatestatus(sd,SP_AGI);
  6355. clif_updatestatus(sd,SP_VIT);
  6356. clif_updatestatus(sd,SP_INT);
  6357. clif_updatestatus(sd,SP_DEX);
  6358. clif_updatestatus(sd,SP_LUK);
  6359. if (sd->spiritball)
  6360. clif_spiritball_single(sd->fd, sd);
  6361. if (sd->vd.cloth_color)
  6362. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6363. if(merc_is_hom_active(sd->hd))
  6364. clif_send_homdata(sd,0,0);
  6365. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6366. clif_weather_check(sd);
  6367. return 0;
  6368. }
  6369. // updates the object's (bl) name on client
  6370. int clif_charnameack (int fd, struct block_list *bl)
  6371. {
  6372. unsigned char buf[103];
  6373. int cmd = 0x95;
  6374. nullpo_retr(0, bl);
  6375. WBUFW(buf,0) = cmd;
  6376. WBUFL(buf,2) = bl->id;
  6377. switch(bl->type) {
  6378. case BL_PC:
  6379. {
  6380. struct map_session_data *ssd = (struct map_session_data *)bl;
  6381. struct party_data *p = NULL;
  6382. struct guild *g = NULL;
  6383. //Requesting your own "shadow" name. [Skotlex]
  6384. if (ssd->fd == fd && ssd->disguise)
  6385. WBUFL(buf,2) = -bl->id;
  6386. if (strlen(ssd->fakename)>1) {
  6387. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6388. break;
  6389. }
  6390. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6391. if (ssd->status.party_id > 0)
  6392. p = party_search(ssd->status.party_id);
  6393. if (ssd->status.guild_id > 0)
  6394. g = guild_search(ssd->status.guild_id);
  6395. if (p == NULL && g == NULL)
  6396. break;
  6397. WBUFW(buf, 0) = cmd = 0x195;
  6398. if (p)
  6399. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6400. else
  6401. WBUFB(buf,30) = 0;
  6402. if (g)
  6403. {
  6404. int i, ps = -1;
  6405. for(i = 0; i < g->max_member; i++) {
  6406. if (g->member[i].account_id == ssd->status.account_id &&
  6407. g->member[i].char_id == ssd->status.char_id )
  6408. {
  6409. ps = g->member[i].position;
  6410. break;
  6411. }
  6412. }
  6413. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6414. {
  6415. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6416. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6417. } else { //Assume no guild.
  6418. WBUFB(buf,54) = 0;
  6419. WBUFB(buf,78) = 0;
  6420. }
  6421. } else {
  6422. WBUFB(buf,54) = 0;
  6423. WBUFB(buf,78) = 0;
  6424. }
  6425. }
  6426. break;
  6427. //[blackhole89]
  6428. case BL_HOM:
  6429. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6430. break;
  6431. case BL_PET:
  6432. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6433. break;
  6434. case BL_NPC:
  6435. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6436. break;
  6437. case BL_MOB:
  6438. {
  6439. struct mob_data *md = (struct mob_data *)bl;
  6440. nullpo_retr(0, md);
  6441. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6442. if (md->guardian_data && md->guardian_data->guild_id) {
  6443. WBUFW(buf, 0) = cmd = 0x195;
  6444. WBUFB(buf,30) = 0;
  6445. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6446. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6447. } else if (battle_config.show_mob_info) {
  6448. char mobhp[50], *str_p = mobhp;
  6449. WBUFW(buf, 0) = cmd = 0x195;
  6450. if (battle_config.show_mob_info&4)
  6451. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6452. if (battle_config.show_mob_info&1)
  6453. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6454. if (battle_config.show_mob_info&2)
  6455. str_p += sprintf(str_p, "HP: %d%% | ",
  6456. md->status.max_hp > 10000?
  6457. md->status.hp/(md->status.max_hp/100):
  6458. 100*md->status.hp/md->status.max_hp);
  6459. //Even thought mobhp ain't a name, we send it as one so the client
  6460. //can parse it. [Skotlex]
  6461. if (str_p != mobhp) {
  6462. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6463. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6464. WBUFB(buf,54) = 0;
  6465. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6466. }
  6467. }
  6468. }
  6469. break;
  6470. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6471. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6472. // break;
  6473. return 0;
  6474. default:
  6475. if (battle_config.error_log)
  6476. ShowError("clif_parse_GetCharNameRequest : bad type %d(%d)\n", bl->type, bl->id);
  6477. return 0;
  6478. }
  6479. // if no receipient specified just update nearby clients
  6480. if (fd == 0)
  6481. clif_send(buf, packet_len(cmd), bl, AREA);
  6482. else {
  6483. WFIFOHEAD(fd, packet_len(cmd));
  6484. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  6485. WFIFOSET(fd, packet_len(cmd));
  6486. }
  6487. return 0;
  6488. }
  6489. //Used to update when a char leaves a party/guild. [Skotlex]
  6490. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6491. int clif_charnameupdate (struct map_session_data *ssd)
  6492. {
  6493. unsigned char buf[103];
  6494. int cmd = 0x195;
  6495. struct party_data *p = NULL;
  6496. struct guild *g = NULL;
  6497. nullpo_retr(0, ssd);
  6498. if (strlen(ssd->fakename)>1)
  6499. return 0; //No need to update as the party/guild was not displayed anyway.
  6500. WBUFW(buf,0) = cmd;
  6501. WBUFL(buf,2) = ssd->bl.id;
  6502. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6503. if (ssd->status.party_id > 0)
  6504. p = party_search(ssd->status.party_id);
  6505. if (ssd->status.guild_id > 0)
  6506. g = guild_search(ssd->status.guild_id);
  6507. if (p)
  6508. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6509. else
  6510. WBUFB(buf,30) = 0;
  6511. if (g)
  6512. {
  6513. int i, ps = -1;
  6514. for(i = 0; i < g->max_member; i++) {
  6515. if (g->member[i].account_id == ssd->status.account_id &&
  6516. g->member[i].char_id == ssd->status.char_id )
  6517. {
  6518. ps = g->member[i].position;
  6519. break;
  6520. }
  6521. }
  6522. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6523. {
  6524. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6525. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6526. } else { //Assume no guild.
  6527. WBUFB(buf,54) = 0;
  6528. WBUFB(buf,78) = 0;
  6529. }
  6530. } else {
  6531. WBUFB(buf,54) = 0;
  6532. WBUFB(buf,78) = 0;
  6533. }
  6534. // Update nearby clients
  6535. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  6536. return 0;
  6537. }
  6538. int clif_slide(struct block_list *bl, int x, int y){
  6539. unsigned char buf[10];
  6540. nullpo_retr(0, bl);
  6541. WBUFW(buf, 0) = 0x01ff;
  6542. WBUFL(buf, 2) = bl->id;
  6543. WBUFW(buf, 6) = x;
  6544. WBUFW(buf, 8) = y;
  6545. clif_send(buf, packet_len(0x1ff), bl, AREA);
  6546. return 0;
  6547. }
  6548. /*------------------------------------------
  6549. * @me command by lordalfa, rewritten implementation by Skotlex
  6550. *------------------------------------------*/
  6551. int clif_disp_overhead(struct map_session_data *sd, const char* mes)
  6552. {
  6553. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  6554. int len_mes = strlen(mes)+1; //Account for \0
  6555. if (len_mes + 8 >= 256) {
  6556. if (battle_config.error_log)
  6557. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6558. len_mes = 247; //Trunk it to avoid problems.
  6559. }
  6560. // send message to others
  6561. WBUFW(buf,0) = 0x8d;
  6562. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6563. WBUFL(buf,4) = sd->bl.id;
  6564. memcpy(WBUFP(buf,8), mes, len_mes);
  6565. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6566. // send back message to the speaker
  6567. WBUFW(buf,0) = 0x8e;
  6568. WBUFW(buf, 2) = len_mes + 4;
  6569. memcpy(WBUFP(buf,4), mes, len_mes);
  6570. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6571. return 0;
  6572. }
  6573. /*==========================
  6574. * Minimap fix [Kevin]
  6575. * Remove dot from minimap
  6576. *--------------------------*/
  6577. int clif_party_xy_remove(struct map_session_data *sd)
  6578. {
  6579. unsigned char buf[16];
  6580. nullpo_retr(0, sd);
  6581. WBUFW(buf,0)=0x107;
  6582. WBUFL(buf,2)=sd->status.account_id;
  6583. WBUFW(buf,6)=-1;
  6584. WBUFW(buf,8)=-1;
  6585. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6586. return 0;
  6587. }
  6588. //Displays gospel-buff information (thanks to Rayce):
  6589. //Type determines message based on this table:
  6590. /*
  6591. 0x15 End all negative status
  6592. 0x16 Immunity to all status
  6593. 0x17 MaxHP +100%
  6594. 0x18 MaxSP +100%
  6595. 0x19 All stats +20
  6596. 0x1c Enchant weapon with Holy element
  6597. 0x1d Enchant armor with Holy element
  6598. 0x1e DEF +25%
  6599. 0x1f ATK +100%
  6600. 0x20 HIT/Flee +50
  6601. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  6602. */
  6603. void clif_gospel_info(struct map_session_data *sd, int type)
  6604. {
  6605. int fd=sd->fd;
  6606. WFIFOHEAD(fd,packet_len(0x215));
  6607. WFIFOW(fd,0)=0x215;
  6608. WFIFOL(fd,2)=type;
  6609. WFIFOSET(fd, packet_len(0x215));
  6610. }
  6611. /*==========================================
  6612. * Info about Star Glaldiator save map [Komurka]
  6613. * type: 1: Information, 0: Map registered
  6614. *------------------------------------------*/
  6615. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  6616. {
  6617. int fd=sd->fd;
  6618. WFIFOHEAD(fd,packet_len(0x20e));
  6619. WFIFOW(fd,0) = 0x20e;
  6620. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), (char*)WFIFOP(fd,2));
  6621. WFIFOL(fd,26) = sd->bl.id;
  6622. WFIFOB(fd,30) = feel_level;
  6623. WFIFOB(fd,31) = type?1:0;
  6624. WFIFOSET(fd,packet_len(0x20e));
  6625. }
  6626. /*==========================================
  6627. * Info about Star Glaldiator hate mob [Komurka]
  6628. * type: 1: Register mob, 0: Information.
  6629. *------------------------------------------*/
  6630. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  6631. {
  6632. int fd=sd->fd;
  6633. WFIFOHEAD(fd,packet_len(0x20e));
  6634. WFIFOW(fd,0)=0x20e;
  6635. if (pcdb_checkid(class_))
  6636. strncpy((char*)WFIFOP(fd,2),job_name(class_), NAME_LENGTH);
  6637. else if (mobdb_checkid(class_))
  6638. strncpy((char*)WFIFOP(fd,2),mob_db(class_)->jname, NAME_LENGTH);
  6639. else //Really shouldn't happen...
  6640. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  6641. WFIFOL(fd,26)=sd->bl.id;
  6642. WFIFOB(fd,30)=hate_level;
  6643. WFIFOB(fd,31)=type?10:11; //Register/Info
  6644. WFIFOSET(fd, packet_len(0x20e));
  6645. }
  6646. /*==========================================
  6647. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6648. *------------------------------------------*/
  6649. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  6650. {
  6651. int fd=sd->fd;
  6652. WFIFOHEAD(fd,packet_len(0x20e));
  6653. WFIFOW(fd,0)=0x20e;
  6654. strncpy((char*)WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6655. WFIFOL(fd,26)=mob_id;
  6656. WFIFOB(fd,30)=progress; //Message to display
  6657. WFIFOB(fd,31)=20;
  6658. WFIFOSET(fd, packet_len(0x20e));
  6659. }
  6660. /*==========================================
  6661. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  6662. *------------------------------------------*/
  6663. void clif_feel_hate_reset(struct map_session_data *sd)
  6664. {
  6665. int fd=sd->fd;
  6666. WFIFOHEAD(fd,packet_len(0x20e));
  6667. WFIFOW(fd,0)=0x20e;
  6668. memset(WFIFOP(fd,2), 0, NAME_LENGTH); //Blank name as all was reset.
  6669. WFIFOL(fd,26)=sd->bl.id;
  6670. WFIFOB(fd,30)=0; //Feel/hate level: irrelevant
  6671. WFIFOB(fd,31)=30;
  6672. WFIFOSET(fd, packet_len(0x20e));
  6673. }
  6674. /// Validates one global/guild/party/whisper message packet to and tries to recognize its components.
  6675. /// Returns true if the packet was parsed successfully.
  6676. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  6677. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  6678. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  6679. {
  6680. char *text, *name, *message;
  6681. unsigned int packetlen, textlen, namelen, messagelen;
  6682. int fd = sd->fd;
  6683. *name_ = NULL;
  6684. *namelen_ = 0;
  6685. *message_ = NULL;
  6686. *messagelen_ = 0;
  6687. packetlen = RFIFOW(fd,2);
  6688. // basic structure checks
  6689. if( packetlen > RFIFOREST(fd) )
  6690. { // there has to be enough data to read
  6691. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6692. return false;
  6693. }
  6694. if( packetlen < 4 + 1 )
  6695. { // 4-byte header and at least an empty string is expected
  6696. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  6697. return false;
  6698. }
  6699. text = (char*)RFIFOP(fd,4);
  6700. textlen = packetlen - 4;
  6701. // process <name> part of the packet
  6702. if( format == 0 )
  6703. {// name and message are separated by ' : '
  6704. // validate name
  6705. name = text;
  6706. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  6707. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  6708. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  6709. {
  6710. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  6711. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  6712. clif_setwaitclose(fd); // Just kick them out to correct it.
  6713. return false;
  6714. }
  6715. message = name + namelen + 3;
  6716. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  6717. }
  6718. else
  6719. {// name has fixed width
  6720. if( textlen < NAME_LENGTH + 1 )
  6721. {
  6722. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6723. return false;
  6724. }
  6725. // validate name
  6726. name = text;
  6727. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  6728. if( name[namelen] != '\0' )
  6729. { // only restriction is that the name must be zero-terminated
  6730. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  6731. return false;
  6732. }
  6733. message = name + NAME_LENGTH;
  6734. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  6735. }
  6736. if( messagelen != strnlen(message, messagelen)+1 )
  6737. { // the declared length must match real length
  6738. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  6739. return false;
  6740. }
  6741. // verify <message> part of the packet
  6742. if( message[messagelen-1] != '\0' )
  6743. { // message must be zero-terminated
  6744. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  6745. return false;
  6746. }
  6747. if( messagelen > CHAT_SIZE_MAX )
  6748. { // messages mustn't be too long
  6749. // Normally you can only enter CHATBOX_SIZE-1 chars into the chat box, but Frost Joke / Dazzler's text can be longer.
  6750. // Neither the official client nor server place any restriction on the length of the text in the packet,
  6751. // but we'll only allow reasonably long strings here. This also makes sure all strings fit into the `chatlog` table.
  6752. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX, message);
  6753. return false;
  6754. }
  6755. *name_ = name;
  6756. *namelen_ = namelen;
  6757. *message_ = message;
  6758. *messagelen_ = messagelen;
  6759. return true;
  6760. }
  6761. // ---------------------
  6762. // clif_guess_PacketVer
  6763. // ---------------------
  6764. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  6765. // error codes:
  6766. // 0 - Success
  6767. // 1 - Unknown packet_ver
  6768. // 2 - Invalid account_id
  6769. // 3 - Invalid char_id
  6770. // 4 - Invalid login_id1 (reserved)
  6771. // 5 - Invalid client_tick (reserved)
  6772. // 6 - Invalid sex
  6773. // Only the first 'invalid' error that appears is used.
  6774. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  6775. {
  6776. static int err = 1;
  6777. static int packet_ver = -1;
  6778. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  6779. if (get_previous)
  6780. {//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]
  6781. if( error )
  6782. *error = err;
  6783. return packet_ver;
  6784. }
  6785. //By default, start searching on the default one.
  6786. err = 1;
  6787. packet_ver = clif_config.packet_db_ver;
  6788. cmd = RFIFOW(fd,0);
  6789. packet_len = RFIFOREST(fd);
  6790. #define SET_ERROR(n) \
  6791. if( err == 1 )\
  6792. err = n;\
  6793. //define SET_ERROR
  6794. #define CHECK_PACKET_VER() \
  6795. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  6796. ;/* not wanttoconnection or wrong length */\
  6797. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > max_account_id )\
  6798. { SET_ERROR(2); }/* invalid account_id */\
  6799. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 || value > max_char_id )\
  6800. { SET_ERROR(3); }/* invalid char_id */\
  6801. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  6802. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  6803. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  6804. { SET_ERROR(6); }/* invalid sex */\
  6805. else\
  6806. {\
  6807. err = 0;\
  6808. if( error )\
  6809. *error = 0;\
  6810. return packet_ver;\
  6811. }\
  6812. //define CHECK_PACKET_VER
  6813. CHECK_PACKET_VER();//Default packet version found.
  6814. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  6815. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  6816. CHECK_PACKET_VER();
  6817. }
  6818. if( error )
  6819. *error = err;
  6820. packet_ver = -1;
  6821. return -1;
  6822. #undef SET_ERROR
  6823. #undef CHECK_PACKET_VER
  6824. }
  6825. // ------------
  6826. // clif_parse_*
  6827. // ------------
  6828. // パケット読み取って色々操作
  6829. /*==========================================
  6830. *
  6831. *------------------------------------------*/
  6832. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  6833. {
  6834. int cmd, account_id, char_id, login_id1, sex;
  6835. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  6836. 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])
  6837. if (sd) {
  6838. if (battle_config.error_log)
  6839. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)?\n");
  6840. return;
  6841. }
  6842. // Only valid packet version get here
  6843. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  6844. cmd = RFIFOW(fd,0);
  6845. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  6846. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  6847. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  6848. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  6849. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  6850. if( packet_ver < 5 || // reject really old client versions
  6851. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  6852. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  6853. {// packet version rejected
  6854. 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));
  6855. WFIFOHEAD(fd,packet_len(0x6a));
  6856. WFIFOW(fd,0) = 0x6a;
  6857. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  6858. WFIFOSET(fd,packet_len(0x6a));
  6859. clif_setwaitclose(fd);
  6860. return;
  6861. } else
  6862. {// packet version accepted
  6863. struct block_list* bl;
  6864. if( (bl=map_id2bl(account_id)) != NULL && bl->type != BL_PC )
  6865. {// non-player object already has that id
  6866. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  6867. WFIFOHEAD(fd,packet_len(0x6a));
  6868. WFIFOW(fd,0) = 0x6a;
  6869. WFIFOB(fd,2) = 3; // Rejected by server
  6870. WFIFOSET(fd,packet_len(0x6a));
  6871. clif_setwaitclose(fd);
  6872. return;
  6873. }
  6874. }
  6875. CREATE(sd, TBL_PC, 1);
  6876. sd->fd = fd;
  6877. sd->packet_ver = packet_ver;
  6878. session[fd]->session_data = sd;
  6879. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  6880. WFIFOHEAD(fd,4);
  6881. WFIFOL(fd,0) = sd->bl.id;
  6882. WFIFOSET(fd,4);
  6883. chrif_authreq(sd);
  6884. return;
  6885. }
  6886. /*==========================================
  6887. * 007d クライアント側マップ読み込み完了
  6888. * map侵入時に必要なデータを全て送りつける
  6889. *------------------------------------------*/
  6890. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  6891. {
  6892. if(sd->bl.prev != NULL)
  6893. return;
  6894. if (!sd->state.auth)
  6895. { //Character loading is not complete yet!
  6896. //Let pc_reg_received reinvoke this when ready.
  6897. sd->state.connect_new = 0;
  6898. return;
  6899. }
  6900. if (sd->state.rewarp)
  6901. { //Rewarp player.
  6902. sd->state.rewarp = 0;
  6903. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  6904. return;
  6905. }
  6906. // look
  6907. #if PACKETVER < 4
  6908. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  6909. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  6910. #else
  6911. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  6912. #endif
  6913. if(sd->vd.cloth_color)
  6914. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6915. // item
  6916. pc_checkitem(sd);
  6917. clif_inventorylist(sd);
  6918. // cart
  6919. if(pc_iscarton(sd)) {
  6920. clif_cartlist(sd);
  6921. clif_updatestatus(sd,SP_CARTINFO);
  6922. }
  6923. // weight max, now
  6924. clif_updatestatus(sd,SP_MAXWEIGHT);
  6925. clif_updatestatus(sd,SP_WEIGHT);
  6926. // guild
  6927. // (needs to go before clif_spawn() to show guild emblems correctly)
  6928. if(sd->status.guild_id)
  6929. guild_send_memberinfoshort(sd,1);
  6930. if(battle_config.pc_invincible_time > 0) {
  6931. if(map_flag_gvg(sd->bl.m))
  6932. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  6933. else
  6934. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  6935. }
  6936. map_addblock(&sd->bl);
  6937. clif_spawn(&sd->bl);
  6938. // Party
  6939. // (needs to go after clif_spawn() to show hp bars correctly)
  6940. if(sd->status.party_id) {
  6941. party_send_movemap(sd);
  6942. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  6943. }
  6944. if(map[sd->bl.m].flag.pvp) {
  6945. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  6946. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  6947. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  6948. sd->pvp_rank = 0;
  6949. sd->pvp_lastusers = 0;
  6950. sd->pvp_point = 5;
  6951. sd->pvp_won = 0;
  6952. sd->pvp_lost = 0;
  6953. }
  6954. clif_set0199(fd,1);
  6955. } else
  6956. // set flag, if it's a duel [LuzZza]
  6957. if(sd->duel_group)
  6958. clif_set0199(fd,1);
  6959. if (map[sd->bl.m].flag.gvg_dungeon)
  6960. {
  6961. clif_set0199(fd,1); //TODO: Figure out the real packet to send here.
  6962. if (!sd->pvp_point)
  6963. {
  6964. sd->pvp_point = 5; //Need to die twice to be warped out.
  6965. sd->pvp_won = 0;
  6966. sd->pvp_lost = 0;
  6967. }
  6968. }
  6969. if(map_flag_gvg(sd->bl.m))
  6970. clif_set0199(fd,3);
  6971. map_foreachinarea(clif_getareachar, sd->bl.m,
  6972. sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE,
  6973. BL_ALL, sd);
  6974. // pet
  6975. if(sd->pd) {
  6976. map_addblock(&sd->pd->bl);
  6977. clif_spawn(&sd->pd->bl);
  6978. clif_send_petdata(sd,sd->pd,0,0);
  6979. clif_send_petstatus(sd);
  6980. // skill_unit_move(&sd->pd->bl,gettick(),1);
  6981. }
  6982. //homunculus [blackhole89]
  6983. if(merc_is_hom_active(sd->hd)) {
  6984. map_addblock(&sd->hd->bl);
  6985. clif_spawn(&sd->hd->bl);
  6986. clif_hominfo(sd,sd->hd,1);
  6987. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  6988. clif_send_homdata(sd,0,0);
  6989. clif_homskillinfoblock(sd);
  6990. if (battle_config.hom_setting&0x8)
  6991. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  6992. if (!(battle_config.hom_setting&0x2))
  6993. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  6994. }
  6995. if(sd->state.connect_new) {
  6996. int lv;
  6997. sd->state.connect_new = 0;
  6998. clif_skillinfoblock(sd);
  6999. clif_hotkeys_send(sd);
  7000. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7001. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7002. clif_updatestatus(sd,SP_SKILLPOINT);
  7003. clif_initialstatus(sd);
  7004. if (sd->sc.option&OPTION_FALCON)
  7005. clif_status_load(&sd->bl, SI_FALCON, 1);
  7006. if (sd->sc.option&OPTION_RIDING)
  7007. clif_status_load(&sd->bl, SI_RIDING, 1);
  7008. if(sd->status.manner < 0)
  7009. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7010. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7011. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7012. if(sd->bl.m == sd->feel_map[0].m
  7013. || sd->bl.m == sd->feel_map[1].m
  7014. || sd->bl.m == sd->feel_map[2].m)
  7015. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7016. }
  7017. if(sd->pd && sd->pd->pet.intimate > 900)
  7018. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7019. if(merc_is_hom_active(sd->hd))
  7020. merc_hom_init_timers(sd->hd);
  7021. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7022. {
  7023. sd->state.night = 1;
  7024. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7025. }
  7026. // Notify everyone that this char logged in [Skotlex].
  7027. clif_foreachclient(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  7028. //Login Event
  7029. npc_script_event(sd, NPCE_LOGIN);
  7030. } else {
  7031. //For some reason the client "loses" these on map-change.
  7032. clif_updatestatus(sd,SP_STR);
  7033. clif_updatestatus(sd,SP_AGI);
  7034. clif_updatestatus(sd,SP_VIT);
  7035. clif_updatestatus(sd,SP_INT);
  7036. clif_updatestatus(sd,SP_DEX);
  7037. clif_updatestatus(sd,SP_LUK);
  7038. sd->state.using_fake_npc = 0;
  7039. //New 'night' effect by dynamix [Skotlex]
  7040. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7041. { //Display night.
  7042. if (!sd->state.night) {
  7043. sd->state.night = 1;
  7044. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7045. }
  7046. } else if (sd->state.night) { //Clear night display.
  7047. sd->state.night = 0;
  7048. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7049. }
  7050. if(sd->npc_id)
  7051. npc_event_dequeue(sd);
  7052. }
  7053. // Lance
  7054. if(sd->state.event_loadmap && map[sd->bl.m].flag.loadevent){
  7055. pc_setregstr(sd, add_str("@maploaded$"), map[sd->bl.m].name);
  7056. npc_script_event(sd, NPCE_LOADMAP);
  7057. }
  7058. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7059. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7060. if (sd->sc.opt2) //Client loses these on warp.
  7061. clif_changeoption(&sd->bl);
  7062. clif_weather_check(sd);
  7063. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7064. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7065. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7066. else
  7067. sd->areanpc_id = 0;
  7068. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  7069. if(pc_isdead(sd))
  7070. clif_clearunit_area(&sd->bl, 1);
  7071. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  7072. // else
  7073. // clif_changed_dir(&sd->bl, SELF);
  7074. // Trigger skill effects if you appear standing on them
  7075. if(!battle_config.pc_invincible_time)
  7076. skill_unit_move(&sd->bl,gettick(),1);
  7077. }
  7078. /*==========================================
  7079. *
  7080. *------------------------------------------*/
  7081. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  7082. {
  7083. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7084. WFIFOHEAD(fd, packet_len(0x7f));
  7085. WFIFOW(fd,0)=0x7f;
  7086. WFIFOL(fd,2)=gettick();
  7087. WFIFOSET(fd,packet_len(0x7f));
  7088. // removed until the socket problems are fixed. [FlavioJS]
  7089. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  7090. return;
  7091. }
  7092. void clif_hotkeys_send(struct map_session_data *sd) {
  7093. #ifdef HOTKEY_SAVING
  7094. const int fd = sd->fd;
  7095. int i;
  7096. if (!fd) return;
  7097. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  7098. WFIFOW(fd, 0) = 0x02b9;
  7099. for(i = 0; i < MAX_HOTKEYS; i++) {
  7100. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  7101. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  7102. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  7103. }
  7104. WFIFOSET(fd, packet_len(0x02b9));
  7105. #endif
  7106. }
  7107. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  7108. #ifdef HOTKEY_SAVING
  7109. unsigned short idx;
  7110. int cmd;
  7111. cmd = RFIFOW(fd, 0);
  7112. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  7113. if (idx >= MAX_HOTKEYS) return;
  7114. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  7115. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  7116. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  7117. return;
  7118. #endif
  7119. }
  7120. /*==========================================
  7121. *
  7122. *------------------------------------------*/
  7123. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  7124. {
  7125. short x, y;
  7126. int cmd;
  7127. if (pc_isdead(sd)) {
  7128. clif_clearunit_area(&sd->bl, 1);
  7129. return;
  7130. }
  7131. if (sd->sc.opt1 && sd->sc.opt1 == OPT1_STONEWAIT)
  7132. ; //You CAN walk on this OPT1 value.
  7133. else if (pc_cant_act(sd))
  7134. return;
  7135. if(sd->sc.count && sd->sc.data[SC_RUN].timer != -1)
  7136. return;
  7137. pc_delinvincibletimer(sd);
  7138. cmd = RFIFOW(fd,0);
  7139. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7140. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7141. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7142. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7143. //Set last idle time... [Skotlex]
  7144. sd->idletime = last_tick;
  7145. unit_walktoxy(&sd->bl, x, y, 4);
  7146. }
  7147. /*==========================================
  7148. *
  7149. *------------------------------------------*/
  7150. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  7151. {
  7152. WFIFOHEAD(fd,packet_len(0x18b));
  7153. WFIFOW(fd,0) = 0x18b;
  7154. /* Rovert's prevent logout option fixed [Valaris] */
  7155. if (sd->sc.data[SC_CLOAKING].timer==-1 && sd->sc.data[SC_HIDING].timer==-1 &&
  7156. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7157. ) {
  7158. clif_setwaitclose(fd);
  7159. WFIFOW(fd,2)=0;
  7160. } else {
  7161. WFIFOW(fd,2)=1;
  7162. }
  7163. WFIFOSET(fd,packet_len(0x18b));
  7164. }
  7165. /*==========================================
  7166. *
  7167. *------------------------------------------*/
  7168. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  7169. {
  7170. int account_id;
  7171. struct block_list* bl;
  7172. struct status_change *sc;
  7173. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7174. if(account_id<0 && -account_id == sd->bl.id) // for disguises [Valaris]
  7175. account_id= sd->bl.id;
  7176. bl = map_id2bl(account_id);
  7177. //Is this possible? Lagged clients could request names of already gone mobs/players. [Skotlex]
  7178. if (!bl) return;
  7179. sc = status_get_sc(bl);
  7180. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  7181. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  7182. pc_isGM(sd) < battle_config.hack_info_GM_level
  7183. ) {
  7184. //GM characters (with client side GM enabled are able to see invisible stuff) [Lance]
  7185. //Asked name of invisible player, this shouldn't be possible!
  7186. //Possible bot? Thanks to veider and qspirit
  7187. //FIXME: Still isn't perfected as clients keep asking for this on legitimate situations.
  7188. char gm_msg[256];
  7189. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requested the name of an invisible target.", sd->status.name, sd->status.account_id);
  7190. ShowWarning(gm_msg);
  7191. // information is sended to all online GM
  7192. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7193. return;
  7194. }
  7195. clif_charnameack(fd, bl);
  7196. }
  7197. /*==========================================
  7198. * Validates and processes global messages
  7199. * S 008c/00f3 <packet len>.w <text>.?B (<name> : <message>) 00
  7200. *------------------------------------------*/
  7201. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  7202. {
  7203. const char* text = (char*)RFIFOP(fd,4);
  7204. int textlen = RFIFOW(fd,2) - 4;
  7205. char *name, *message;
  7206. int namelen, messagelen;
  7207. // validate packet and retrieve name and message
  7208. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  7209. return;
  7210. if( is_atcommand(fd, sd, message) != AtCommand_None || is_charcommand(fd, sd, message) != CharCommand_None )
  7211. return;
  7212. if( sd->sc.data[SC_BERSERK].timer != -1 || (sd->sc.data[SC_NOCHAT].timer != -1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT) )
  7213. return;
  7214. if( battle_config.min_chat_delay )
  7215. { //[Skotlex]
  7216. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7217. return;
  7218. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7219. }
  7220. // send message to others (using the send buffer for temp. storage)
  7221. WFIFOHEAD(fd, 8 + textlen);
  7222. WFIFOW(fd,0) = 0x8d;
  7223. WFIFOW(fd,2) = 8 + textlen;
  7224. WFIFOL(fd,4) = sd->bl.id;
  7225. safestrncpy((char*)WFIFOP(fd,8), text, textlen);
  7226. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7227. // send back message to the speaker
  7228. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7229. WFIFOW(fd,0) = 0x8e;
  7230. WFIFOSET(fd, WFIFOW(fd,2));
  7231. #ifdef PCRE_SUPPORT
  7232. // trigger listening mobs/npcs
  7233. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  7234. map_foreachinrange(mob_chat_sub, &sd->bl, AREA_SIZE, BL_MOB, text, textlen, &sd->bl);
  7235. #endif
  7236. // check for special supernovice phrase
  7237. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE )
  7238. {
  7239. int next = pc_nextbaseexp(sd);
  7240. if( next > 0 && (sd->status.base_exp * 1000 / next)% 100 == 0 ) { // 0%, 10%, 20%, ...
  7241. switch (sd->state.snovice_call_flag) {
  7242. case 0:
  7243. if( strstr(message, msg_txt(504)) ) // "Guardian Angel, can you hear my voice? ^^;"
  7244. sd->state.snovice_call_flag++;
  7245. break;
  7246. case 1: {
  7247. char buf[256];
  7248. sprintf(buf, msg_txt(505), sd->status.name);
  7249. if( strstr(message, buf) ) // "My name is %s, and I'm a Super Novice~"
  7250. sd->state.snovice_call_flag++;
  7251. }
  7252. break;
  7253. case 2:
  7254. if( strstr(message, msg_txt(506)) ) // "Please help me~ T.T"
  7255. sd->state.snovice_call_flag++;
  7256. break;
  7257. case 3:
  7258. if( skillnotok(MO_EXPLOSIONSPIRITS,sd) )
  7259. break; //Do not override the noskill mapflag. [Skotlex]
  7260. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7261. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  7262. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7263. sd->state.snovice_call_flag = 0;
  7264. break;
  7265. }
  7266. }
  7267. }
  7268. // Chat logging type 'O' / Global Chat
  7269. if( log_config.chat&1 || (log_config.chat&2 && !(agit_flag && log_config.chat&64)) )
  7270. log_chat("O", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7271. return;
  7272. }
  7273. /*==========================================
  7274. * /mm /mapmove (as @rura GM command)
  7275. *------------------------------------------*/
  7276. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  7277. {
  7278. char output[MAP_NAME_LENGTH_EXT+15]; // Max length of a short: ' -6XXXX' -> 7 digits
  7279. char message[MAP_NAME_LENGTH_EXT+15+5]; // "/mm "+output
  7280. char* map_name;
  7281. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7282. return;
  7283. if(pc_isGM(sd) < get_atcommand_level(AtCommand_MapMove))
  7284. return;
  7285. map_name = (char*)RFIFOP(fd,2);
  7286. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  7287. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7288. atcommand_rura(fd, sd, "@rura", output);
  7289. if(log_config.gm && get_atcommand_level(AtCommand_MapMove) >= log_config.gm)
  7290. {
  7291. sprintf(message, "/mm %s", output);
  7292. log_atcommand(sd, message);
  7293. }
  7294. return;
  7295. }
  7296. /*==========================================
  7297. *
  7298. *------------------------------------------*/
  7299. void clif_changed_dir(struct block_list *bl, int type)
  7300. {
  7301. unsigned char buf[64];
  7302. WBUFW(buf,0) = 0x9c;
  7303. WBUFL(buf,2) = bl->id;
  7304. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7305. WBUFB(buf,8) = unit_getdir(bl);
  7306. clif_send(buf, packet_len(0x9c), bl, type);
  7307. if (disguised(bl)) {
  7308. WBUFL(buf,2) = -bl->id;
  7309. WBUFW(buf,6) = 0;
  7310. clif_send(buf, packet_len(0x9c), bl, SELF);
  7311. }
  7312. return;
  7313. }
  7314. /*==========================================
  7315. *
  7316. *------------------------------------------*/
  7317. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  7318. {
  7319. unsigned char headdir, dir;
  7320. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7321. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7322. pc_setdir(sd, dir, headdir);
  7323. clif_changed_dir(&sd->bl, AREA_WOS);
  7324. return;
  7325. }
  7326. /*==========================================
  7327. *
  7328. *------------------------------------------*/
  7329. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  7330. {
  7331. unsigned char buf[64];
  7332. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7333. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7334. clif_skill_fail(sd, 1, 0, 1);
  7335. return;
  7336. }
  7337. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7338. if (sd->emotionlasttime >= time(NULL)) {
  7339. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7340. clif_skill_fail(sd, 1, 0, 1);
  7341. return;
  7342. }
  7343. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7344. WBUFW(buf,0) = 0xc0;
  7345. WBUFL(buf,2) = sd->bl.id;
  7346. WBUFB(buf,6) = RFIFOB(fd,2);
  7347. clif_send(buf, packet_len(0xc0), &sd->bl, AREA);
  7348. } else
  7349. clif_skill_fail(sd, 1, 0, 1);
  7350. }
  7351. /*==========================================
  7352. *
  7353. *------------------------------------------*/
  7354. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  7355. {
  7356. WFIFOHEAD(fd,packet_len(0xc2));
  7357. WFIFOW(fd,0) = 0xc2;
  7358. WFIFOL(fd,2) = map_getusers();
  7359. WFIFOSET(fd,packet_len(0xc2));
  7360. }
  7361. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7362. {
  7363. if (pc_isdead(sd)) {
  7364. clif_clearunit_area(&sd->bl, 1);
  7365. return;
  7366. }
  7367. if (sd->sc.count &&
  7368. (sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  7369. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  7370. sd->sc.data[SC_BLADESTOP].timer != -1))
  7371. return;
  7372. pc_stop_walking(sd, 1);
  7373. pc_stop_attack(sd);
  7374. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7375. target_id = sd->bl.id;
  7376. switch(action_type)
  7377. {
  7378. case 0x00: // once attack
  7379. case 0x07: // continuous attack
  7380. if (pc_cant_act(sd) || sd->sc.option&OPTION_HIDE)
  7381. return;
  7382. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  7383. return;
  7384. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7385. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7386. clif_skill_fail(sd, 1, 4, 0);
  7387. return;
  7388. }
  7389. }
  7390. pc_delinvincibletimer(sd);
  7391. sd->idletime = last_tick;
  7392. unit_attack(&sd->bl, target_id, action_type != 0);
  7393. break;
  7394. case 0x02: // sitdown
  7395. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7396. clif_skill_fail(sd, 1, 0, 2);
  7397. break;
  7398. }
  7399. if(pc_issit(sd)) {
  7400. //Bugged client? Just refresh them.
  7401. clif_sitting(&sd->bl);
  7402. return;
  7403. }
  7404. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7405. break;
  7406. if (sd->sc.count && (
  7407. sd->sc.data[SC_DANCING].timer != -1 ||
  7408. (sd->sc.data[SC_GRAVITATION].timer != -1 && sd->sc.data[SC_GRAVITATION].val3 == BCT_SELF)
  7409. )) //No sitting during these states either.
  7410. break;
  7411. pc_setsit(sd);
  7412. skill_sit(sd,1);
  7413. clif_sitting(&sd->bl);
  7414. break;
  7415. case 0x03: // standup
  7416. if (!pc_issit(sd)) {
  7417. //Bugged client? Just refresh them.
  7418. clif_standing(&sd->bl);
  7419. return;
  7420. }
  7421. pc_setstand(sd);
  7422. skill_sit(sd,0);
  7423. clif_standing(&sd->bl);
  7424. break;
  7425. }
  7426. }
  7427. /*==========================================
  7428. *
  7429. *------------------------------------------*/
  7430. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  7431. {
  7432. clif_parse_ActionRequest_sub(sd,
  7433. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7434. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7435. gettick()
  7436. );
  7437. }
  7438. /*==========================================
  7439. *
  7440. *------------------------------------------*/
  7441. void clif_parse_Restart(int fd, struct map_session_data *sd)
  7442. {
  7443. switch(RFIFOB(fd,2)) {
  7444. case 0x00:
  7445. if (!pc_isdead(sd))
  7446. break;
  7447. pc_setstand(sd);
  7448. pc_setrestartvalue(sd, 3);
  7449. if (pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, 2))
  7450. clif_resurrection(&sd->bl, 1); //If warping fails, send a normal stand up packet.
  7451. break;
  7452. case 0x01:
  7453. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7454. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7455. { //Send to char-server for character selection.
  7456. chrif_charselectreq(sd, session[fd]->client_addr);
  7457. } else {
  7458. WFIFOHEAD(fd,packet_len(0x18b));
  7459. WFIFOW(fd,0)=0x18b;
  7460. WFIFOW(fd,2)=1;
  7461. WFIFOSET(fd,packet_len(0x018b));
  7462. }
  7463. break;
  7464. }
  7465. }
  7466. /*==========================================
  7467. * Validates and processes whispered messages
  7468. * S 0096 <packet len>.w <nick>.23B 00 <message>.?B
  7469. *------------------------------------------*/
  7470. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  7471. {
  7472. struct map_session_data* dstsd;
  7473. int i;
  7474. char *target, *message;
  7475. int namelen, messagelen;
  7476. // validate packet and retrieve name and message
  7477. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  7478. return;
  7479. if (is_atcommand(fd, sd, message) != AtCommand_None || is_charcommand(fd, sd, message) != CharCommand_None )
  7480. return;
  7481. if (sd->sc.data[SC_BERSERK].timer!=-1 || (sd->sc.data[SC_NOCHAT].timer != -1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT))
  7482. return;
  7483. if (battle_config.min_chat_delay)
  7484. { //[Skotlex]
  7485. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  7486. return;
  7487. }
  7488. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7489. }
  7490. // Chat logging type 'W' / Whisper
  7491. if( log_config.chat&1 || (log_config.chat&4 && !(agit_flag && log_config.chat&64)) )
  7492. log_chat("W", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
  7493. //-------------------------------------------------------//
  7494. // Lordalfa - Paperboy - To whisper NPC commands //
  7495. //-------------------------------------------------------//
  7496. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  7497. {
  7498. char* str = target+4; //Skip the NPC: string part.
  7499. struct npc_data* npc;
  7500. if ((npc = npc_name2id(str)))
  7501. {
  7502. char split_data[10][50];
  7503. char *split;
  7504. char output[256];
  7505. str = message;
  7506. for( i = 0; i < 10; ++i )
  7507. {// Splits the message using '#' as separators
  7508. split = strchr(str,'#');
  7509. if( split == NULL )
  7510. { // use the remaining string
  7511. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7512. for( ++i; i < 10; ++i )
  7513. split_data[i][0] = '\0';
  7514. break;
  7515. }
  7516. *split = '\0';
  7517. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7518. str = split+1;
  7519. }
  7520. for( i = 0; i < 10; ++i )
  7521. {
  7522. sprintf(output, "@whispervar%d$", i);
  7523. set_var(sd,output,(char *) split_data[i]);
  7524. }
  7525. sprintf(output, "%s::OnWhisperGlobal", npc->name);
  7526. npc_event(sd,output,0); // Calls the NPC label
  7527. return;
  7528. }
  7529. }
  7530. // Main chat [LuzZza]
  7531. if(strcmpi(target, main_chat_nick) == 0)
  7532. {
  7533. if(!sd->state.mainchat)
  7534. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7535. else {
  7536. char output[256];
  7537. snprintf(output, ARRAYLENGTH(output), msg_txt(386), sd->status.name, message);
  7538. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7539. }
  7540. return;
  7541. }
  7542. // searching destination character
  7543. dstsd = map_nick2sd(target);
  7544. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
  7545. {
  7546. // player is not on this map-server
  7547. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7548. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7549. // and if we ask for 'Test', we must not contact 'test' player
  7550. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7551. intif_wis_message(sd, target, message, messagelen);
  7552. return;
  7553. }
  7554. // if player ignores everyone
  7555. if (dstsd->state.ignoreAll)
  7556. {
  7557. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7558. clif_wis_end(fd, 1); // 1: target character is not loged in
  7559. else
  7560. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7561. return;
  7562. }
  7563. // if player ignores the source character
  7564. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  7565. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  7566. { // source char present in ignore list
  7567. clif_wis_end(fd, 2); // 2: ignored by target
  7568. return;
  7569. }
  7570. // notify sender of success
  7571. clif_wis_end(fd, 0); // 0: success to send wisper
  7572. // if player has an auto-away message
  7573. if(dstsd->away_message[0] != '\0')
  7574. {
  7575. char output[256];
  7576. sprintf(output, "%s %s", message, msg_txt(543)); // "(Automessage has been sent)"
  7577. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  7578. if(dstsd->state.autotrade)
  7579. sprintf(output, msg_txt(544), dstsd->away_message); // "Away [AT] - "%s""
  7580. else
  7581. sprintf(output, msg_txt(545), dstsd->away_message); // "Away - "%s""
  7582. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  7583. return;
  7584. }
  7585. // Normal message
  7586. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  7587. return;
  7588. }
  7589. /*==========================================
  7590. * /b /nb
  7591. * S 0099 <packet len>.w <text>.?B 00
  7592. *------------------------------------------*/
  7593. void clif_parse_GMmessage(int fd, struct map_session_data* sd)
  7594. {
  7595. char* msg = (char*)RFIFOP(fd,4);
  7596. unsigned int len = RFIFOW(fd,2)-4;
  7597. int lv;
  7598. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7599. return;
  7600. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_Broadcast)))
  7601. return;
  7602. // as the length varies depending on the command used, just block unreasonably long strings
  7603. mes_len_check(msg, len, CHAT_SIZE_MAX);
  7604. intif_GMmessage(msg, len, 0);
  7605. if(log_config.gm && lv >= log_config.gm) {
  7606. char logmsg[CHAT_SIZE_MAX+4];
  7607. sprintf(logmsg, "/b %s", msg);
  7608. log_atcommand(sd, logmsg);
  7609. }
  7610. }
  7611. /*==========================================
  7612. *
  7613. *------------------------------------------*/
  7614. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  7615. {
  7616. struct flooritem_data *fitem;
  7617. int map_object_id;
  7618. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7619. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  7620. do {
  7621. if (pc_isdead(sd)) {
  7622. clif_clearunit_area(&sd->bl, 1);
  7623. break;
  7624. }
  7625. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  7626. break;
  7627. if (pc_cant_act(sd))
  7628. break;
  7629. //Disable cloaking/chasewalking characters from looting [Skotlex]
  7630. if(pc_iscloaking(sd) || pc_ischasewalk(sd))
  7631. break;
  7632. if(sd->sc.count && (
  7633. sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  7634. sd->sc.data[SC_BLADESTOP].timer != -1 ||
  7635. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOITEM))
  7636. )
  7637. break;
  7638. if (!pc_takeitem(sd, fitem))
  7639. break;
  7640. return;
  7641. } while (0);
  7642. // Client REQUIRES a fail packet or you can no longer pick items.
  7643. clif_additem(sd,0,0,6);
  7644. }
  7645. /*==========================================
  7646. *
  7647. *------------------------------------------*/
  7648. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  7649. {
  7650. int item_index, item_amount;
  7651. if (pc_isdead(sd)) {
  7652. clif_clearunit_area(&sd->bl, 1);
  7653. return;
  7654. }
  7655. if (pc_cant_act(sd))
  7656. return;
  7657. if (sd->sc.count && (
  7658. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  7659. sd->sc.data[SC_BLADESTOP].timer != -1 ||
  7660. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOITEM)
  7661. ))
  7662. return;
  7663. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7664. item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7665. if (!pc_dropitem(sd, item_index, item_amount))
  7666. //Because the client does not likes being ignored.
  7667. clif_delitem(sd, item_index,0);
  7668. }
  7669. /*==========================================
  7670. *
  7671. *------------------------------------------*/
  7672. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  7673. {
  7674. int n;
  7675. if (pc_isdead(sd)) {
  7676. clif_clearunit_area(&sd->bl, 1);
  7677. return;
  7678. }
  7679. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  7680. return;
  7681. //This flag enables you to use items while in an NPC. [Skotlex]
  7682. if (sd->npc_id) {
  7683. if (sd->npc_id != sd->npc_item_flag)
  7684. return;
  7685. } else
  7686. if (pc_istrading(sd))
  7687. return;
  7688. pc_delinvincibletimer(sd);
  7689. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  7690. sd->idletime = last_tick;
  7691. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7692. if(n <0 || n >= MAX_INVENTORY)
  7693. return;
  7694. if (!pc_useitem(sd,n))
  7695. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  7696. }
  7697. /*==========================================
  7698. *
  7699. *------------------------------------------*/
  7700. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  7701. {
  7702. int index;
  7703. if(pc_isdead(sd)) {
  7704. clif_clearunit_area(&sd->bl,1);
  7705. return;
  7706. }
  7707. index = RFIFOW(fd,2)-2;
  7708. if (index < 0 || index >= MAX_INVENTORY)
  7709. return; //Out of bounds check.
  7710. if(sd->npc_id) {
  7711. if (sd->npc_id != sd->npc_item_flag)
  7712. return;
  7713. } else if (sd->state.storage_flag || sd->sc.opt1)
  7714. ; //You can equip/unequip stuff while storage is open/under status changes
  7715. else if (pc_cant_act(sd))
  7716. return;
  7717. if(sd->sc.data[SC_BLADESTOP].timer!=-1 || sd->sc.data[SC_BERSERK].timer!=-1 )
  7718. return;
  7719. if(!sd->status.inventory[index].identify) {
  7720. clif_equipitemack(sd,index,0,0); // fail
  7721. return;
  7722. }
  7723. if(!sd->inventory_data[index])
  7724. return;
  7725. if(sd->inventory_data[index]->type == IT_PETARMOR){
  7726. pet_equipitem(sd,index);
  7727. return;
  7728. }
  7729. //Client doesn't send the position for ammo.
  7730. if(sd->inventory_data[index]->type == IT_AMMO)
  7731. pc_equipitem(sd,index,EQP_AMMO);
  7732. else
  7733. pc_equipitem(sd,index,RFIFOW(fd,4));
  7734. }
  7735. /*==========================================
  7736. *
  7737. *------------------------------------------*/
  7738. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  7739. {
  7740. int index;
  7741. if(pc_isdead(sd)) {
  7742. clif_clearunit_area(&sd->bl,1);
  7743. return;
  7744. }
  7745. if (sd->state.storage_flag)
  7746. ; //You can equip/unequip stuff while storage is open.
  7747. else if (pc_cant_act(sd))
  7748. return;
  7749. index = RFIFOW(fd,2)-2;
  7750. pc_unequipitem(sd,index,1);
  7751. }
  7752. /*==========================================
  7753. *
  7754. *------------------------------------------*/
  7755. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  7756. {
  7757. struct block_list *bl;
  7758. if(pc_isdead(sd)) {
  7759. clif_clearunit_area(&sd->bl,1);
  7760. return;
  7761. }
  7762. if (pc_cant_act(sd))
  7763. return;
  7764. bl = map_id2bl(RFIFOL(fd,2));
  7765. if (!bl) return;
  7766. switch (bl->type) {
  7767. case BL_MOB:
  7768. if (!((TBL_MOB *)bl)->nd || !mob_script_callback((TBL_MOB *)bl, &sd->bl, CALLBACK_NPCCLICK))
  7769. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7770. break;
  7771. case BL_PC:
  7772. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7773. break;
  7774. case BL_NPC:
  7775. npc_click(sd,(TBL_NPC*)bl);
  7776. break;
  7777. }
  7778. return;
  7779. }
  7780. /*==========================================
  7781. *
  7782. *------------------------------------------*/
  7783. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  7784. {
  7785. if (sd->state.trading)
  7786. return;
  7787. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  7788. }
  7789. /*==========================================
  7790. *
  7791. *------------------------------------------*/
  7792. void clif_parse_NpcBuyListSend(int fd,struct map_session_data *sd)
  7793. {
  7794. int fail=0,n;
  7795. unsigned short *item_list;
  7796. n = (RFIFOW(fd,2)-4) /4;
  7797. item_list = (unsigned short*)RFIFOP(fd,4);
  7798. if (sd->state.trading|| !sd->npc_shopid)
  7799. fail = 1;
  7800. else
  7801. fail = npc_buylist(sd,n,item_list);
  7802. sd->npc_shopid = 0; //Clear shop data.
  7803. WFIFOHEAD(fd,packet_len(0xca));
  7804. WFIFOW(fd,0)=0xca;
  7805. WFIFOB(fd,2)=fail;
  7806. WFIFOSET(fd,packet_len(0xca));
  7807. }
  7808. /*==========================================
  7809. *
  7810. *------------------------------------------*/
  7811. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  7812. {
  7813. int fail=0,n;
  7814. unsigned short *item_list;
  7815. n = (RFIFOW(fd,2)-4) /4;
  7816. item_list = (unsigned short*)RFIFOP(fd,4);
  7817. if (sd->state.trading || !sd->npc_shopid)
  7818. fail = 1;
  7819. else
  7820. fail = npc_selllist(sd,n,item_list);
  7821. sd->npc_shopid = 0; //Clear shop data.
  7822. WFIFOHEAD(fd,packet_len(0xcb));
  7823. WFIFOW(fd,0)=0xcb;
  7824. WFIFOB(fd,2)=fail;
  7825. WFIFOSET(fd,packet_len(0xcb));
  7826. }
  7827. /*==========================================
  7828. * Chatroom creation request
  7829. * S 00d5 <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7830. *------------------------------------------*/
  7831. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  7832. {
  7833. int len = RFIFOW(fd,2)-15;
  7834. int limit = RFIFOW(fd,4);
  7835. bool pub = (RFIFOB(fd,6) != 0);
  7836. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  7837. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7838. char s_title[CHATROOM_TITLE_SIZE];
  7839. char s_password[CHATROOM_PASS_SIZE];
  7840. if (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOROOM)
  7841. return;
  7842. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  7843. clif_skill_fail(sd,1,0,3);
  7844. return;
  7845. }
  7846. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7847. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7848. chat_createpcchat(sd, s_title, s_password, limit, pub);
  7849. }
  7850. /*==========================================
  7851. * Chatroom join request
  7852. * S 00d9 <chat ID>.l <passwd>.8B
  7853. *------------------------------------------*/
  7854. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  7855. {
  7856. int chatid = RFIFOL(fd,2);
  7857. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  7858. chat_joinchat(sd,chatid,password);
  7859. }
  7860. /*==========================================
  7861. * Chatroom properties adjustment request
  7862. * S 00de <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7863. *------------------------------------------*/
  7864. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  7865. {
  7866. int len = RFIFOW(fd,2)-15;
  7867. int limit = RFIFOW(fd,4);
  7868. bool pub = (RFIFOB(fd,6) != 0);
  7869. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  7870. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7871. char s_title[CHATROOM_TITLE_SIZE];
  7872. char s_password[CHATROOM_PASS_SIZE];
  7873. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7874. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7875. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  7876. }
  7877. /*==========================================
  7878. * S 00e0 ?.l <nick>.24B
  7879. *------------------------------------------*/
  7880. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  7881. {
  7882. //TODO: the first argument seems to be the destination position (always 0) [ultramage]
  7883. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  7884. }
  7885. /*==========================================
  7886. *
  7887. *------------------------------------------*/
  7888. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  7889. {
  7890. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  7891. }
  7892. /*==========================================
  7893. * Request to leave the current chatroom
  7894. * S 00e3
  7895. *------------------------------------------*/
  7896. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  7897. {
  7898. chat_leavechat(sd,0);
  7899. }
  7900. //Handles notifying asker and rejecter of what has just ocurred.
  7901. //Type is used to determine the correct msg_txt to use:
  7902. //0:
  7903. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  7904. {
  7905. char *msg, output[256];
  7906. // Your request has been rejected by autoreject option.
  7907. msg = msg_txt(392);
  7908. clif_disp_onlyself(src, msg, strlen(msg));
  7909. //Notice that a request was rejected.
  7910. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  7911. clif_disp_onlyself(target, output, strlen(output));
  7912. }
  7913. /*==========================================
  7914. * 取引要請を相手に送る
  7915. *------------------------------------------*/
  7916. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  7917. {
  7918. struct map_session_data *t_sd;
  7919. t_sd = map_id2sd(RFIFOL(fd,2));
  7920. if(!sd->chatID && pc_cant_act(sd))
  7921. return; //You can trade while in a chatroom.
  7922. // @noask [LuzZza]
  7923. if(t_sd && t_sd->state.noask) {
  7924. clif_noask_sub(sd, t_sd, 0);
  7925. return;
  7926. }
  7927. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 1){
  7928. trade_traderequest(sd,t_sd);
  7929. } else
  7930. clif_skill_fail(sd,1,0,0);
  7931. }
  7932. /*==========================================
  7933. * 取引要請
  7934. *------------------------------------------*/
  7935. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  7936. {
  7937. trade_tradeack(sd,RFIFOB(fd,2));
  7938. }
  7939. /*==========================================
  7940. * アイテム追加
  7941. *------------------------------------------*/
  7942. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  7943. {
  7944. short index = RFIFOW(fd,2);
  7945. int amount = RFIFOL(fd,4);
  7946. if( index == 0 )
  7947. trade_tradeaddzeny(sd, amount);
  7948. else
  7949. trade_tradeadditem(sd, index, (short)amount);
  7950. }
  7951. /*==========================================
  7952. * アイテム追加完了(ok押し)
  7953. *------------------------------------------*/
  7954. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  7955. {
  7956. trade_tradeok(sd);
  7957. }
  7958. /*==========================================
  7959. * 取引キャンセル
  7960. *------------------------------------------*/
  7961. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  7962. {
  7963. trade_tradecancel(sd);
  7964. }
  7965. /*==========================================
  7966. * 取引許諾(trade押し)
  7967. *------------------------------------------*/
  7968. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  7969. {
  7970. trade_tradecommit(sd);
  7971. }
  7972. /*==========================================
  7973. *
  7974. *------------------------------------------*/
  7975. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  7976. {
  7977. pc_stop_attack(sd);
  7978. }
  7979. /*==========================================
  7980. * カートへアイテムを移す
  7981. *------------------------------------------*/
  7982. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  7983. {
  7984. if (pc_istrading(sd))
  7985. return;
  7986. if (!pc_iscarton(sd))
  7987. return;
  7988. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  7989. }
  7990. /*==========================================
  7991. * カートからアイテムを出す
  7992. *------------------------------------------*/
  7993. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  7994. {
  7995. if (!pc_iscarton(sd))
  7996. return;
  7997. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  7998. }
  7999. /*==========================================
  8000. * 付属品(鷹,ペコ,カート)をはずす
  8001. *------------------------------------------*/
  8002. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8003. {
  8004. //Can only remove Cart/Riding/Falcon.
  8005. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  8006. }
  8007. /*==========================================
  8008. * チェンジカート
  8009. *------------------------------------------*/
  8010. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8011. {
  8012. int type;
  8013. type = (int)RFIFOW(fd,2);
  8014. if( (type == 5 && sd->status.base_level <= 90) ||
  8015. (type == 4 && sd->status.base_level <= 80) ||
  8016. (type == 3 && sd->status.base_level <= 65) ||
  8017. (type == 2 && sd->status.base_level <= 40) ||
  8018. pc_setcart(sd,type) )
  8019. {
  8020. LOG_SUSPICIOUS(sd,"clif_parse_ChangeCart");
  8021. }
  8022. }
  8023. /*==========================================
  8024. * ステータスアップ
  8025. *------------------------------------------*/
  8026. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8027. {
  8028. pc_statusup(sd,RFIFOW(fd,2));
  8029. }
  8030. /*==========================================
  8031. * スキルレベルアップ
  8032. *------------------------------------------*/
  8033. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8034. {
  8035. pc_skillup(sd,RFIFOW(fd,2));
  8036. }
  8037. 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)
  8038. {
  8039. int lv;
  8040. if (!hd)
  8041. return;
  8042. if (skillnotok_hom(skillnum, hd)) //[orn]
  8043. return;
  8044. if (hd->bl.id != target_id &&
  8045. skill_get_inf(skillnum)&INF_SELF_SKILL)
  8046. target_id = hd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8047. if (hd->ud.skilltimer != -1) {
  8048. if (skillnum != SA_CASTCANCEL)
  8049. return;
  8050. } else if (DIFF_TICK(tick, hd->ud.canact_tick) < 0)
  8051. return;
  8052. lv = merc_hom_checkskill(hd, skillnum);
  8053. if (skilllv > lv)
  8054. skilllv = lv;
  8055. if (skilllv)
  8056. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  8057. }
  8058. /*==========================================
  8059. * スキル使用(ID指定)
  8060. *------------------------------------------*/
  8061. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  8062. {
  8063. short skillnum, skilllv;
  8064. int tmp, target_id;
  8065. unsigned int tick = gettick();
  8066. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8067. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8068. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8069. if (skilllv < 1) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8070. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8071. sd->idletime = last_tick;
  8072. tmp = skill_get_inf(skillnum);
  8073. if (tmp&INF_GROUND_SKILL || !tmp)
  8074. return; //Using a ground/passive skill on a target? WRONG.
  8075. if (skillnum >= HM_SKILLBASE && skillnum <= HM_SKILLBASE+MAX_HOMUNSKILL) {
  8076. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  8077. return;
  8078. }
  8079. if (pc_cant_act(sd))
  8080. return;
  8081. if (pc_issit(sd))
  8082. return;
  8083. if (skillnotok(skillnum, sd))
  8084. return;
  8085. if (sd->bl.id != target_id && !sd->state.skill_flag && tmp&INF_SELF_SKILL)
  8086. target_id = sd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8087. if (sd->ud.skilltimer != -1) {
  8088. if (skillnum != SA_CASTCANCEL)
  8089. return;
  8090. } else if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8091. clif_skill_fail(sd, skillnum, 4, 0);
  8092. return;
  8093. }
  8094. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  8095. return;
  8096. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8097. target_id = sd->bl.id;
  8098. if(sd->menuskill_id)
  8099. {
  8100. if (sd->menuskill_id == SA_TAMINGMONSTER)
  8101. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8102. else
  8103. if (sd->menuskill_id != SA_AUTOSPELL)
  8104. return; //Can't use skills while a menu is open.
  8105. }
  8106. if (sd->skillitem == skillnum) {
  8107. if (skilllv != sd->skillitemlv)
  8108. skilllv = sd->skillitemlv;
  8109. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8110. return;
  8111. }
  8112. sd->skillitem = sd->skillitemlv = 0;
  8113. if (skillnum == MO_EXTREMITYFIST) {
  8114. if ((sd->sc.data[SC_COMBO].timer == -1 ||
  8115. (sd->sc.data[SC_COMBO].val1 != MO_COMBOFINISH &&
  8116. sd->sc.data[SC_COMBO].val1 != CH_TIGERFIST &&
  8117. sd->sc.data[SC_COMBO].val1 != CH_CHAINCRUSH))) {
  8118. if (!sd->state.skill_flag ) {
  8119. sd->state.skill_flag = 1;
  8120. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8121. return;
  8122. } else if (sd->bl.id == target_id) {
  8123. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8124. return;
  8125. }
  8126. }
  8127. }
  8128. if (skillnum == TK_JUMPKICK) {
  8129. if (sd->sc.data[SC_COMBO].timer == -1 ||
  8130. sd->sc.data[SC_COMBO].val1 != TK_JUMPKICK) {
  8131. if (!sd->state.skill_flag ) {
  8132. sd->state.skill_flag = 1;
  8133. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8134. return;
  8135. } else if (sd->bl.id == target_id) {
  8136. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8137. return;
  8138. }
  8139. }
  8140. }
  8141. if (skillnum >= GD_SKILLBASE) {
  8142. if (sd->state.gmaster_flag)
  8143. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8144. else
  8145. skilllv = 0;
  8146. } else {
  8147. tmp = pc_checkskill(sd, skillnum);
  8148. if (skilllv > tmp)
  8149. skilllv = tmp;
  8150. }
  8151. pc_delinvincibletimer(sd);
  8152. if (skilllv)
  8153. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8154. if (sd->state.skill_flag)
  8155. sd->state.skill_flag = 0;
  8156. }
  8157. /*==========================================
  8158. * スキル使用(場所指定)
  8159. *------------------------------------------*/
  8160. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, short skilllv, short skillnum, short x, short y, int skillmoreinfo)
  8161. {
  8162. int lv;
  8163. unsigned int tick = gettick();
  8164. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8165. sd->idletime = last_tick;
  8166. if (skillnotok(skillnum, sd))
  8167. return;
  8168. if (!(skill_get_inf(skillnum)&INF_GROUND_SKILL))
  8169. return; //Using a target skill on the ground? WRONG.
  8170. if (skillmoreinfo != -1) {
  8171. if (pc_issit(sd)) {
  8172. clif_skill_fail(sd, skillnum, 0, 0);
  8173. return;
  8174. }
  8175. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  8176. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8177. }
  8178. if (sd->ud.skilltimer != -1)
  8179. return;
  8180. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0)
  8181. {
  8182. clif_skill_fail(sd, skillnum, 4, 0);
  8183. return;
  8184. }
  8185. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  8186. return;
  8187. if(sd->menuskill_id)
  8188. {
  8189. if (sd->menuskill_id == SA_TAMINGMONSTER)
  8190. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8191. else
  8192. if (sd->menuskill_id != SA_AUTOSPELL)
  8193. return; //Can't use skills while a menu is open.
  8194. }
  8195. pc_delinvincibletimer(sd);
  8196. if (sd->skillitem == skillnum) {
  8197. if (skilllv != sd->skillitemlv)
  8198. skilllv = sd->skillitemlv;
  8199. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8200. } else {
  8201. sd->skillitem = sd->skillitemlv = 0;
  8202. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8203. if (skilllv > lv)
  8204. skilllv = lv;
  8205. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8206. }
  8207. }
  8208. }
  8209. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  8210. {
  8211. if (pc_cant_act(sd))
  8212. return;
  8213. if (pc_issit(sd))
  8214. return;
  8215. clif_parse_UseSkillToPosSub(fd, sd,
  8216. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8217. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8218. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8219. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8220. -1 //Skill more info.
  8221. );
  8222. }
  8223. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  8224. {
  8225. if (pc_cant_act(sd))
  8226. return;
  8227. if (pc_issit(sd))
  8228. return;
  8229. clif_parse_UseSkillToPosSub(fd, sd,
  8230. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8231. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8232. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8233. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8234. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8235. );
  8236. }
  8237. /*==========================================
  8238. * スキル使用(map指定)
  8239. *------------------------------------------*/
  8240. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  8241. {
  8242. short skill_num = RFIFOW(fd,2);
  8243. char map_name[MAP_NAME_LENGTH];
  8244. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  8245. if(skill_num != sd->menuskill_id)
  8246. return;
  8247. if (pc_cant_act(sd))
  8248. {
  8249. sd->menuskill_id = sd->menuskill_val = 0;
  8250. return;
  8251. }
  8252. pc_delinvincibletimer(sd);
  8253. skill_castend_map(sd,skill_num,map_name);
  8254. }
  8255. /*==========================================
  8256. * メモ要求
  8257. *------------------------------------------*/
  8258. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8259. {
  8260. if (!pc_isdead(sd))
  8261. pc_memo(sd,-1);
  8262. }
  8263. /*==========================================
  8264. * アイテム合成
  8265. *------------------------------------------*/
  8266. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8267. {
  8268. if (sd->menuskill_id != AM_PHARMACY)
  8269. return;
  8270. if (pc_istrading(sd)) {
  8271. //Make it fail to avoid shop exploits where you sell something different than you see.
  8272. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8273. sd->menuskill_val = sd->menuskill_id = 0;
  8274. return;
  8275. }
  8276. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8277. sd->menuskill_val = sd->menuskill_id = 0;
  8278. }
  8279. /*==========================================
  8280. * 武器修理
  8281. *------------------------------------------*/
  8282. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8283. {
  8284. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8285. return;
  8286. if (pc_istrading(sd)) {
  8287. //Make it fail to avoid shop exploits where you sell something different than you see.
  8288. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8289. sd->menuskill_val = sd->menuskill_id = 0;
  8290. return;
  8291. }
  8292. skill_repairweapon(sd,RFIFOW(fd,2));
  8293. sd->menuskill_val = sd->menuskill_id = 0;
  8294. }
  8295. /*==========================================
  8296. *
  8297. *------------------------------------------*/
  8298. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  8299. {
  8300. int idx;
  8301. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8302. return;
  8303. if (pc_istrading(sd)) {
  8304. //Make it fail to avoid shop exploits where you sell something different than you see.
  8305. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8306. sd->menuskill_val = sd->menuskill_id = 0;
  8307. return;
  8308. }
  8309. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8310. skill_weaponrefine(sd, idx-2);
  8311. sd->menuskill_val = sd->menuskill_id = 0;
  8312. }
  8313. /*==========================================
  8314. *
  8315. *------------------------------------------*/
  8316. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8317. {
  8318. uint8 select;
  8319. select = RFIFOB(fd,6);
  8320. if((select > sd->npc_menu && select != 0xff) || !select){
  8321. ShowWarning("Hack on NPC Select Menu: %s (AID: %d)!\n",sd->status.name,sd->bl.id);
  8322. clif_GM_kick(sd,sd,0);
  8323. } else {
  8324. sd->npc_menu=select;
  8325. npc_scriptcont(sd,RFIFOL(fd,2));
  8326. }
  8327. }
  8328. /*==========================================
  8329. *
  8330. *------------------------------------------*/
  8331. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8332. {
  8333. npc_scriptcont(sd,RFIFOL(fd,2));
  8334. }
  8335. /*==========================================
  8336. * Value entered into a NPC input box.
  8337. * S 0143 <npcID>.l <amount>.l
  8338. *------------------------------------------*/
  8339. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8340. {
  8341. int npcid = RFIFOL(fd,2);
  8342. int amount = (int)RFIFOL(fd,6);
  8343. sd->npc_amount = amount;
  8344. npc_scriptcont(sd, npcid);
  8345. }
  8346. /*==========================================
  8347. * Text entered into a NPC input box.
  8348. * S 01d5 <len>.w <npcID>.l <input>.?B 00
  8349. *------------------------------------------*/
  8350. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  8351. {
  8352. int message_len = RFIFOW(fd,2)-8;
  8353. int npcid = RFIFOL(fd,4);
  8354. const char* message = (char*)RFIFOP(fd,8);
  8355. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  8356. npc_scriptcont(sd, npcid);
  8357. }
  8358. /*==========================================
  8359. *
  8360. *------------------------------------------*/
  8361. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8362. {
  8363. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8364. return;
  8365. npc_scriptcont(sd,RFIFOL(fd,2));
  8366. }
  8367. /*==========================================
  8368. * アイテム鑑定
  8369. *------------------------------------------*/
  8370. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8371. {
  8372. if (sd->menuskill_id != MC_IDENTIFY)
  8373. return;
  8374. skill_identify(sd,RFIFOW(fd,2)-2);
  8375. sd->menuskill_val = sd->menuskill_id = 0;
  8376. }
  8377. /*==========================================
  8378. * 矢作成
  8379. *------------------------------------------*/
  8380. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8381. {
  8382. if (sd->menuskill_id != AC_MAKINGARROW)
  8383. return;
  8384. if (pc_istrading(sd)) {
  8385. //Make it fail to avoid shop exploits where you sell something different than you see.
  8386. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8387. sd->menuskill_val = sd->menuskill_id = 0;
  8388. return;
  8389. }
  8390. skill_arrow_create(sd,RFIFOW(fd,2));
  8391. sd->menuskill_val = sd->menuskill_id = 0;
  8392. }
  8393. /*==========================================
  8394. * オートスペル受信
  8395. *------------------------------------------*/
  8396. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8397. {
  8398. if (sd->menuskill_id != SA_AUTOSPELL)
  8399. return;
  8400. skill_autospell(sd,RFIFOW(fd,2));
  8401. sd->menuskill_val = sd->menuskill_id = 0;
  8402. }
  8403. /*==========================================
  8404. * カード使用
  8405. *------------------------------------------*/
  8406. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8407. {
  8408. if (sd->state.trading != 0)
  8409. return;
  8410. clif_use_card(sd,RFIFOW(fd,2)-2);
  8411. }
  8412. /*==========================================
  8413. * カード挿入装備選択
  8414. *------------------------------------------*/
  8415. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8416. {
  8417. if (sd->state.trading != 0)
  8418. return;
  8419. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8420. }
  8421. /*==========================================
  8422. * 0193 キャラID名前引き
  8423. *------------------------------------------*/
  8424. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  8425. {
  8426. int charid;
  8427. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8428. map_reqnickdb(sd, charid);
  8429. }
  8430. /*==========================================
  8431. * 0197 /resetskill /resetstate
  8432. *------------------------------------------*/
  8433. void clif_parse_ResetChar(int fd, struct map_session_data *sd)
  8434. {
  8435. if (battle_config.atc_gmonly && !pc_isGM(sd))
  8436. return;
  8437. if (pc_isGM(sd) < get_atcommand_level(AtCommand_ResetState))
  8438. return;
  8439. if (RFIFOW(fd,2))
  8440. pc_resetskill(sd,1);
  8441. else
  8442. pc_resetstate(sd);
  8443. if(log_config.gm && get_atcommand_level(AtCommand_ResetState >= log_config.gm))
  8444. log_atcommand(sd, RFIFOW(fd,2) ? "/resetskill" : "/resetstate");
  8445. }
  8446. /*==========================================
  8447. * /lb /nlb
  8448. * S 019c <packet len>.w <text>.?B 00
  8449. *------------------------------------------*/
  8450. void clif_parse_LGMmessage(int fd, struct map_session_data* sd)
  8451. {
  8452. char* msg = (char*)RFIFOP(fd,4);
  8453. unsigned int len = RFIFOW(fd,2)-4;
  8454. int lv;
  8455. if (battle_config.atc_gmonly && !pc_isGM(sd))
  8456. return;
  8457. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_LocalBroadcast)))
  8458. return;
  8459. // as the length varies depending on the command used, just block unreasonably long strings
  8460. mes_len_check(msg, len, CHAT_SIZE_MAX);
  8461. clif_GMmessage(&sd->bl, msg, len, 1);
  8462. if(log_config.gm && lv >= log_config.gm) {
  8463. char logmsg[CHAT_SIZE_MAX+5];
  8464. sprintf(logmsg, "/lb %s", msg);
  8465. log_atcommand(sd, logmsg);
  8466. }
  8467. }
  8468. /*==========================================
  8469. * カプラ倉庫へ入れる
  8470. *------------------------------------------*/
  8471. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  8472. {
  8473. int item_index, item_amount;
  8474. if (pc_istrading(sd))
  8475. return;
  8476. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8477. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8478. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  8479. return;
  8480. if (sd->state.storage_flag == 1)
  8481. storage_storageadd(sd, item_index, item_amount);
  8482. else if (sd->state.storage_flag == 2)
  8483. storage_guild_storageadd(sd, item_index, item_amount);
  8484. }
  8485. /*==========================================
  8486. * カプラ倉庫から出す
  8487. *------------------------------------------*/
  8488. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  8489. {
  8490. int item_index, item_amount;
  8491. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8492. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8493. if (sd->state.storage_flag == 1)
  8494. storage_storageget(sd, item_index, item_amount);
  8495. else if(sd->state.storage_flag == 2)
  8496. storage_guild_storageget(sd, item_index, item_amount);
  8497. }
  8498. /*==========================================
  8499. * カプラ倉庫へカートから入れる
  8500. *------------------------------------------*/
  8501. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  8502. {
  8503. if(sd->vender_id)
  8504. return;
  8505. if (!pc_iscarton(sd))
  8506. return;
  8507. if (sd->state.storage_flag == 1)
  8508. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8509. else if (sd->state.storage_flag == 2)
  8510. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8511. }
  8512. /*==========================================
  8513. * カプラ倉庫から出す
  8514. *------------------------------------------*/
  8515. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  8516. {
  8517. if (sd->vender_id)
  8518. return;
  8519. if (!pc_iscarton(sd))
  8520. return;
  8521. if (sd->state.storage_flag == 1)
  8522. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8523. else if (sd->state.storage_flag == 2)
  8524. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8525. }
  8526. /*==========================================
  8527. * カプラ倉庫を閉じる
  8528. *------------------------------------------*/
  8529. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  8530. {
  8531. if (sd->state.storage_flag == 1)
  8532. storage_storageclose(sd);
  8533. else if (sd->state.storage_flag == 2)
  8534. storage_guild_storageclose(sd);
  8535. }
  8536. /*==========================================
  8537. * Kafra storage protection password system
  8538. *------------------------------------------*/
  8539. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  8540. {
  8541. //TODO
  8542. }
  8543. /*==========================================
  8544. * パーティを作る
  8545. *------------------------------------------*/
  8546. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  8547. {
  8548. if(map[sd->bl.m].flag.partylock)
  8549. { //Guild locked.
  8550. clif_displaymessage(fd, msg_txt(227));
  8551. return;
  8552. }
  8553. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7) {
  8554. party_create(sd,(char*)RFIFOP(fd,2),0,0);
  8555. } else
  8556. clif_skill_fail(sd,1,0,4);
  8557. }
  8558. /*==========================================
  8559. * パーティを作る
  8560. *------------------------------------------*/
  8561. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  8562. {
  8563. if(map[sd->bl.m].flag.partylock)
  8564. { //Guild locked.
  8565. clif_displaymessage(fd, msg_txt(227));
  8566. return;
  8567. }
  8568. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7)
  8569. party_create(sd,(char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27));
  8570. else
  8571. clif_skill_fail(sd,1,0,4);
  8572. }
  8573. /*==========================================
  8574. * パーティに勧誘
  8575. *------------------------------------------*/
  8576. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  8577. {
  8578. struct map_session_data *t_sd;
  8579. if(map[sd->bl.m].flag.partylock)
  8580. { //Guild locked.
  8581. clif_displaymessage(fd, msg_txt(227));
  8582. return;
  8583. }
  8584. t_sd = map_id2sd(RFIFOL(fd,2));
  8585. // @noask [LuzZza]
  8586. if(t_sd && t_sd->state.noask) {
  8587. clif_noask_sub(sd, t_sd, 1);
  8588. return;
  8589. }
  8590. party_invite(sd, t_sd);
  8591. }
  8592. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  8593. {
  8594. struct map_session_data *t_sd;
  8595. char *name = (char*)RFIFOP(fd,2);
  8596. name[NAME_LENGTH]='\0';
  8597. if(map[sd->bl.m].flag.partylock)
  8598. { //Guild locked.
  8599. clif_displaymessage(fd, msg_txt(227));
  8600. return;
  8601. }
  8602. t_sd = map_nick2sd(name);
  8603. // @noask [LuzZza]
  8604. if(t_sd && t_sd->state.noask) {
  8605. clif_noask_sub(sd, t_sd, 1);
  8606. return;
  8607. }
  8608. party_invite(sd, t_sd);
  8609. }
  8610. /*==========================================
  8611. * パーティ勧誘返答
  8612. *------------------------------------------*/
  8613. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  8614. {
  8615. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  8616. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8617. } else {
  8618. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8619. clif_skill_fail(sd,1,0,4);
  8620. }
  8621. }
  8622. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  8623. {
  8624. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  8625. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8626. } else {
  8627. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8628. clif_skill_fail(sd,1,0,4);
  8629. }
  8630. }
  8631. /*==========================================
  8632. * パーティ脱退要求
  8633. *------------------------------------------*/
  8634. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  8635. {
  8636. if(map[sd->bl.m].flag.partylock)
  8637. { //Guild locked.
  8638. clif_displaymessage(fd, msg_txt(227));
  8639. return;
  8640. }
  8641. party_leave(sd);
  8642. }
  8643. /*==========================================
  8644. * パーティ除名要求
  8645. *------------------------------------------*/
  8646. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  8647. {
  8648. if(map[sd->bl.m].flag.partylock)
  8649. { //Guild locked.
  8650. clif_displaymessage(fd, msg_txt(227));
  8651. return;
  8652. }
  8653. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8654. }
  8655. /*==========================================
  8656. * パーティ設定変更要求
  8657. *------------------------------------------*/
  8658. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  8659. {
  8660. struct party_data *p;
  8661. if(!sd->status.party_id)
  8662. return;
  8663. p = party_search(sd->status.party_id);
  8664. if (!p) return;
  8665. //The client no longer can change the item-field, therefore it always
  8666. //comes as zero. Here, resend the item data as it is.
  8667. // party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  8668. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  8669. }
  8670. /*==========================================
  8671. * Validates and processes party messages
  8672. * S 0108 <packet len>.w <text>.?B (<name> : <message>) 00
  8673. *------------------------------------------*/
  8674. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  8675. {
  8676. const char* text = (char*)RFIFOP(fd,4);
  8677. int textlen = RFIFOW(fd,2) - 4;
  8678. char *name, *message;
  8679. int namelen, messagelen;
  8680. // validate packet and retrieve name and message
  8681. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8682. return;
  8683. if (is_charcommand(fd, sd, message) != CharCommand_None || is_atcommand(fd, sd, message) != AtCommand_None)
  8684. return;
  8685. if (sd->sc.data[SC_BERSERK].timer!=-1 || (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT))
  8686. return;
  8687. if (battle_config.min_chat_delay)
  8688. { //[Skotlex]
  8689. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8690. return;
  8691. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8692. }
  8693. party_send_message(sd, text, textlen);
  8694. }
  8695. /*==========================================
  8696. * 露店閉鎖
  8697. *------------------------------------------*/
  8698. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  8699. {
  8700. vending_closevending(sd);
  8701. }
  8702. /*==========================================
  8703. * 露店アイテムリスト要求
  8704. *------------------------------------------*/
  8705. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  8706. {
  8707. vending_vendinglistreq(sd,RFIFOL(fd,2));
  8708. if( sd->npc_id )
  8709. npc_event_dequeue(sd);
  8710. }
  8711. /*==========================================
  8712. * Shop item(s) purchase request
  8713. * S 0134 <len>.w <ID>.l {<amount>.w <index>.w}.4B*
  8714. *------------------------------------------*/
  8715. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  8716. {
  8717. int len = (int)RFIFOW(fd,2) - 8;
  8718. int id = (int)RFIFOL(fd,4);
  8719. const uint8* data = (uint8*)RFIFOP(fd,8);
  8720. vending_purchasereq(sd, id, data, len/4);
  8721. }
  8722. /*==========================================
  8723. * Confirm or cancel the shop preparation window
  8724. * S 01b2 <len>.w <message>.80B <flag>.B {<index>.w <amount>.w <value>.l}.8B*
  8725. * flag: 0=cancel, 1=confirm
  8726. *------------------------------------------*/
  8727. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  8728. {
  8729. short len = (short)RFIFOW(fd,2) - 85;
  8730. const char* message = (char*)RFIFOP(fd,4);
  8731. bool flag = (bool)RFIFOB(fd,84);
  8732. const uint8* data = (uint8*)RFIFOP(fd,85);
  8733. if (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOROOM)
  8734. return;
  8735. if (map[sd->bl.m].flag.novending) {
  8736. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open shop on this map"
  8737. return;
  8738. }
  8739. if( message[0] == '\0' ) // invalid input
  8740. return;
  8741. vending_openvending(sd, message, flag, data, len/8);
  8742. }
  8743. /*==========================================
  8744. * ギルドを作る
  8745. *------------------------------------------*/
  8746. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  8747. {
  8748. if(map[sd->bl.m].flag.guildlock)
  8749. { //Guild locked.
  8750. clif_displaymessage(fd, msg_txt(228));
  8751. return;
  8752. }
  8753. guild_create(sd, (char*)RFIFOP(fd,6));
  8754. }
  8755. /*==========================================
  8756. * ギルドマスターかどうか確認
  8757. *------------------------------------------*/
  8758. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  8759. {
  8760. clif_guild_masterormember(sd);
  8761. }
  8762. /*==========================================
  8763. * ギルド情報要求
  8764. *------------------------------------------*/
  8765. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  8766. {
  8767. if (!sd->status.guild_id)
  8768. return;
  8769. switch(RFIFOL(fd,2)){
  8770. case 0: // ギルド基本情報、同盟敵対情報
  8771. clif_guild_basicinfo(sd);
  8772. clif_guild_allianceinfo(sd);
  8773. break;
  8774. case 1: // メンバーリスト、役職名リスト
  8775. clif_guild_positionnamelist(sd);
  8776. clif_guild_memberlist(sd);
  8777. break;
  8778. case 2: // 役職名リスト、役職情報リスト
  8779. clif_guild_positionnamelist(sd);
  8780. clif_guild_positioninfolist(sd);
  8781. break;
  8782. case 3: // スキルリスト
  8783. clif_guild_skillinfo(sd);
  8784. break;
  8785. case 4: // 追放リスト
  8786. clif_guild_expulsionlist(sd);
  8787. break;
  8788. default:
  8789. if (battle_config.error_log)
  8790. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  8791. break;
  8792. }
  8793. }
  8794. /*==========================================
  8795. * ギルド役職変更
  8796. *------------------------------------------*/
  8797. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  8798. {
  8799. int i;
  8800. if(!sd->state.gmaster_flag)
  8801. return;
  8802. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  8803. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  8804. }
  8805. }
  8806. /*==========================================
  8807. * ギルドメンバ役職変更
  8808. *------------------------------------------*/
  8809. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  8810. {
  8811. int i;
  8812. if(!sd->state.gmaster_flag)
  8813. return;
  8814. for(i=4;i<RFIFOW(fd,2);i+=12){
  8815. guild_change_memberposition(sd->status.guild_id,
  8816. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  8817. }
  8818. }
  8819. /*==========================================
  8820. * ギルドエンブレム要求
  8821. *------------------------------------------*/
  8822. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  8823. {
  8824. struct guild* g = guild_search(RFIFOL(fd,2));
  8825. if(g!=NULL)
  8826. clif_guild_emblem(sd,g);
  8827. }
  8828. /*==========================================
  8829. * ギルドエンブレム変更
  8830. *------------------------------------------*/
  8831. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  8832. {
  8833. if(!sd->state.gmaster_flag)
  8834. return;
  8835. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  8836. }
  8837. /*==========================================
  8838. * Guild notice update request
  8839. * S 016E <guildID>.l <msg1>.60B <msg2>.120B
  8840. *------------------------------------------*/
  8841. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  8842. {
  8843. int guild_id = RFIFOL(fd,2);
  8844. char* msg1 = (char*)RFIFOP(fd,6);
  8845. char* msg2 = (char*)RFIFOP(fd,66);
  8846. if(!sd->state.gmaster_flag)
  8847. return;
  8848. // compensate for some client defects when using multilanguage mode
  8849. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  8850. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  8851. if (msg2[0] == '|') msg2[strnlen(msg2, 120)-1] = '\0'; // delete extra space at the end of string
  8852. guild_change_notice(sd, guild_id, msg1, msg2);
  8853. }
  8854. /*==========================================
  8855. * ギルド勧誘
  8856. *------------------------------------------*/
  8857. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  8858. {
  8859. struct map_session_data *t_sd;
  8860. if(map[sd->bl.m].flag.guildlock)
  8861. { //Guild locked.
  8862. clif_displaymessage(fd, msg_txt(228));
  8863. return;
  8864. }
  8865. t_sd = map_id2sd(RFIFOL(fd,2));
  8866. // @noask [LuzZza]
  8867. if(t_sd && t_sd->state.noask) {
  8868. clif_noask_sub(sd, t_sd, 2);
  8869. return;
  8870. }
  8871. guild_invite(sd,t_sd);
  8872. }
  8873. /*==========================================
  8874. * ギルド勧誘返信
  8875. *------------------------------------------*/
  8876. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  8877. {
  8878. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8879. }
  8880. /*==========================================
  8881. * ギルド脱退
  8882. *------------------------------------------*/
  8883. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  8884. {
  8885. if(map[sd->bl.m].flag.guildlock)
  8886. { //Guild locked.
  8887. clif_displaymessage(fd, msg_txt(228));
  8888. return;
  8889. }
  8890. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8891. }
  8892. /*==========================================
  8893. * ギルド追放
  8894. *------------------------------------------*/
  8895. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  8896. {
  8897. if(map[sd->bl.m].flag.guildlock)
  8898. { //Guild locked.
  8899. clif_displaymessage(fd, msg_txt(228));
  8900. return;
  8901. }
  8902. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8903. }
  8904. /*==========================================
  8905. * Validates and processes guild messages
  8906. * S 017e <packet len>.w <text>.?B (<name> : <message>) 00
  8907. *------------------------------------------*/
  8908. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  8909. {
  8910. const char* text = (char*)RFIFOP(fd,4);
  8911. int textlen = RFIFOW(fd,2) - 4;
  8912. char *name, *message;
  8913. int namelen, messagelen;
  8914. // validate packet and retrieve name and message
  8915. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8916. return;
  8917. if (is_charcommand(fd, sd, message) != CharCommand_None || is_atcommand(fd, sd, message) != AtCommand_None)
  8918. return;
  8919. if (sd->sc.data[SC_BERSERK].timer!=-1 || (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT))
  8920. return;
  8921. if (battle_config.min_chat_delay)
  8922. { //[Skotlex]
  8923. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8924. return;
  8925. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8926. }
  8927. guild_send_message(sd, text, textlen);
  8928. }
  8929. /*==========================================
  8930. * ギルド同盟要求
  8931. *------------------------------------------*/
  8932. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  8933. {
  8934. struct map_session_data *t_sd;
  8935. if(!sd->state.gmaster_flag)
  8936. return;
  8937. if(map[sd->bl.m].flag.guildlock)
  8938. { //Guild locked.
  8939. clif_displaymessage(fd, msg_txt(228));
  8940. return;
  8941. }
  8942. t_sd = map_id2sd(RFIFOL(fd,2));
  8943. // @noask [LuzZza]
  8944. if(t_sd && t_sd->state.noask) {
  8945. clif_noask_sub(sd, t_sd, 3);
  8946. return;
  8947. }
  8948. guild_reqalliance(sd,t_sd);
  8949. }
  8950. /*==========================================
  8951. * ギルド同盟要求返信
  8952. *------------------------------------------*/
  8953. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  8954. {
  8955. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8956. }
  8957. /*==========================================
  8958. * ギルド関係解消
  8959. *------------------------------------------*/
  8960. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  8961. {
  8962. if(!sd->state.gmaster_flag)
  8963. return;
  8964. if(map[sd->bl.m].flag.guildlock)
  8965. { //Guild locked.
  8966. clif_displaymessage(fd, msg_txt(228));
  8967. return;
  8968. }
  8969. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8970. }
  8971. /*==========================================
  8972. * ギルド敵対
  8973. *------------------------------------------*/
  8974. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  8975. {
  8976. struct map_session_data *t_sd;
  8977. if(!sd->state.gmaster_flag)
  8978. return;
  8979. if(map[sd->bl.m].flag.guildlock)
  8980. { //Guild locked.
  8981. clif_displaymessage(fd, msg_txt(228));
  8982. return;
  8983. }
  8984. t_sd = map_id2sd(RFIFOL(fd,2));
  8985. // @noask [LuzZza]
  8986. if(t_sd && t_sd->state.noask) {
  8987. clif_noask_sub(sd, t_sd, 4);
  8988. return;
  8989. }
  8990. guild_opposition(sd,t_sd);
  8991. }
  8992. /*==========================================
  8993. * ギルド解散
  8994. *------------------------------------------*/
  8995. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  8996. {
  8997. if(map[sd->bl.m].flag.guildlock)
  8998. { //Guild locked.
  8999. clif_displaymessage(fd, msg_txt(228));
  9000. return;
  9001. }
  9002. guild_break(sd,(char*)RFIFOP(fd,2));
  9003. }
  9004. // pet
  9005. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  9006. {
  9007. pet_menu(sd,RFIFOB(fd,2));
  9008. }
  9009. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  9010. {
  9011. pet_catch_process2(sd,RFIFOL(fd,2));
  9012. }
  9013. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  9014. {
  9015. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  9016. return;
  9017. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9018. sd->menuskill_val = sd->menuskill_id = 0;
  9019. }
  9020. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  9021. {
  9022. if(sd->pd)
  9023. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9024. }
  9025. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  9026. {
  9027. pet_change_name(sd,(char*)RFIFOP(fd,2));
  9028. }
  9029. // Kick (right click menu for GM "(name) force to quit")
  9030. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  9031. {
  9032. struct block_list *target;
  9033. int tid,lv;
  9034. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9035. return;
  9036. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_Kick)))
  9037. return;
  9038. tid = RFIFOL(fd,2);
  9039. target = map_id2bl(tid);
  9040. if (!target) {
  9041. clif_GM_kickack(sd, 0);
  9042. return;
  9043. }
  9044. switch (target->type) {
  9045. case BL_PC:
  9046. {
  9047. struct map_session_data *tsd = (struct map_session_data *)target;
  9048. if (pc_isGM(sd) <= pc_isGM(tsd)) {
  9049. clif_GM_kickack(sd, 0);
  9050. return;
  9051. }
  9052. clif_GM_kick(sd, tsd, 1);
  9053. if(log_config.gm && lv >= log_config.gm) {
  9054. char message[NAME_LENGTH+6];
  9055. sprintf(message, "/kick %d", tsd->status.char_id);
  9056. log_atcommand(sd, message);
  9057. }
  9058. break;
  9059. }
  9060. case BL_MOB:
  9061. status_percent_damage(&sd->bl, target, 100, 0);
  9062. if(log_config.gm && lv >= log_config.gm) {
  9063. char message[NAME_LENGTH+16];
  9064. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9065. log_atcommand(sd, message);
  9066. }
  9067. break;
  9068. default:
  9069. clif_GM_kickack(sd, 0);
  9070. }
  9071. }
  9072. /*==========================================
  9073. * /shift
  9074. *------------------------------------------*/
  9075. void clif_parse_Shift(int fd, struct map_session_data *sd)
  9076. {
  9077. char *player_name;
  9078. int lv;
  9079. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9080. return;
  9081. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_JumpTo)))
  9082. return;
  9083. player_name = (char*)RFIFOP(fd,2);
  9084. player_name[NAME_LENGTH-1] = '\0';
  9085. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9086. if(log_config.gm && lv >= log_config.gm) {
  9087. char message[NAME_LENGTH+7];
  9088. sprintf(message, "/shift %s", player_name);
  9089. log_atcommand(sd, message);
  9090. }
  9091. return;
  9092. }
  9093. /*==========================================
  9094. * /recall
  9095. *------------------------------------------*/
  9096. void clif_parse_Recall(int fd, struct map_session_data *sd)
  9097. {
  9098. char *player_name;
  9099. int lv;
  9100. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9101. return;
  9102. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_Recall)))
  9103. return;
  9104. player_name = (char*)RFIFOP(fd,2);
  9105. player_name[NAME_LENGTH-1] = '\0';
  9106. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9107. if(log_config.gm && lv >= log_config.gm) {
  9108. char message[NAME_LENGTH+8];
  9109. sprintf(message, "/recall %s", player_name);
  9110. log_atcommand(sd, message);
  9111. }
  9112. return;
  9113. }
  9114. /*==========================================
  9115. * /monster /item
  9116. *------------------------------------------*/
  9117. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  9118. {
  9119. char *monster_item_name;
  9120. char message[NAME_LENGTH+10]; //For logging.
  9121. int level;
  9122. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9123. return;
  9124. monster_item_name = (char*)RFIFOP(fd,2);
  9125. monster_item_name[NAME_LENGTH-1] = '\0';
  9126. if (mobdb_searchname(monster_item_name)) {
  9127. if (pc_isGM(sd) < (level=get_atcommand_level(AtCommand_Spawn)))
  9128. return;
  9129. atcommand_monster(fd, sd, "@spawn", monster_item_name); // as @spawn
  9130. if(log_config.gm && level >= log_config.gm)
  9131. { //Log action. [Skotlex]
  9132. snprintf(message, sizeof(message)-1, "@spawn %s", monster_item_name);
  9133. log_atcommand(sd, message);
  9134. }
  9135. return;
  9136. }
  9137. if (itemdb_searchname(monster_item_name) == NULL)
  9138. return;
  9139. if (pc_isGM(sd) < (level = get_atcommand_level(AtCommand_Item)))
  9140. return;
  9141. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9142. if(log_config.gm && level >= log_config.gm)
  9143. { //Log action. [Skotlex]
  9144. sprintf(message, "@item %s", monster_item_name);
  9145. log_atcommand(sd, message);
  9146. }
  9147. }
  9148. /*==========================================
  9149. * /hide
  9150. *------------------------------------------*/
  9151. void clif_parse_GMHide(int fd, struct map_session_data *sd)
  9152. {
  9153. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9154. return;
  9155. if (pc_isGM(sd) < get_atcommand_level(AtCommand_Hide))
  9156. return;
  9157. if (sd->sc.option & OPTION_INVISIBLE) {
  9158. sd->sc.option &= ~OPTION_INVISIBLE;
  9159. if (sd->disguise)
  9160. status_set_viewdata(&sd->bl, sd->disguise);
  9161. else
  9162. status_set_viewdata(&sd->bl, sd->status.class_);
  9163. clif_displaymessage(fd, "Invisible: Off.");
  9164. } else {
  9165. sd->sc.option |= OPTION_INVISIBLE;
  9166. sd->vd.class_ = INVISIBLE_CLASS;
  9167. clif_displaymessage(fd, "Invisible: On.");
  9168. if(log_config.gm && get_atcommand_level(AtCommand_Hide) >= log_config.gm)
  9169. log_atcommand(sd, "/hide");
  9170. }
  9171. clif_changeoption(&sd->bl);
  9172. }
  9173. /*==========================================
  9174. * GMによるチャット禁止時間付与
  9175. *------------------------------------------*/
  9176. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9177. {
  9178. int type, limit, level;
  9179. struct block_list *bl;
  9180. struct map_session_data *dstsd;
  9181. bl = map_id2bl(RFIFOL(fd,2));
  9182. if (!bl || bl->type != BL_PC)
  9183. return;
  9184. dstsd =(struct map_session_data *)bl;
  9185. type = RFIFOB(fd,6);
  9186. limit = RFIFOW(fd,7);
  9187. if (type == 0)
  9188. limit = 0 - limit;
  9189. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  9190. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  9191. if (type == 2/* && sd->bl.id != dstsd->bl.id*/)
  9192. return;
  9193. if (
  9194. ((level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(AtCommand_Mute))
  9195. || (type == 2 && !level))
  9196. {
  9197. clif_GM_silence(sd, dstsd, ((type == 2) ? 1 : type));
  9198. dstsd->status.manner -= limit;
  9199. if(dstsd->status.manner < 0)
  9200. sc_start(bl,SC_NOCHAT,100,0,0);
  9201. else
  9202. {
  9203. dstsd->status.manner = 0;
  9204. status_change_end(bl,SC_NOCHAT,-1);
  9205. }
  9206. }
  9207. return;
  9208. }
  9209. /*==========================================
  9210. * GMによるチャット禁止時間参照(?)
  9211. *------------------------------------------*/
  9212. void clif_parse_GMReqNoChatCount(int fd, struct map_session_data *sd)
  9213. {
  9214. int tid;
  9215. tid = RFIFOL(fd,2);
  9216. WFIFOHEAD(fd,packet_len(0x1e0));
  9217. WFIFOW(fd,0) = 0x1e0;
  9218. WFIFOL(fd,2) = tid;
  9219. sprintf((char*)WFIFOP(fd,6),"%d",tid);
  9220. WFIFOSET(fd, packet_len(0x1e0));
  9221. return;
  9222. }
  9223. static int pstrcmp(const void *a, const void *b)
  9224. {
  9225. char *name1 = (char *)a;
  9226. char *name2 = (char *)b;
  9227. if (name1[0] && name2[0])
  9228. return strcmp(name1, name2);
  9229. //Since names are sorted in ascending order, send blank entries to the bottom.
  9230. if (name1[0])
  9231. return -1;
  9232. if (name2[0])
  9233. return 1;
  9234. return 0;
  9235. }
  9236. void clif_parse_PMIgnore(int fd, struct map_session_data *sd)
  9237. {
  9238. char output[512];
  9239. char *nick; // S 00cf <nick>.24B <type>.B: 00 (/ex nick) deny speech from nick, 01 (/in nick) allow speech from nick
  9240. int i;
  9241. memset(output, '\0', sizeof(output));
  9242. nick = (char*)RFIFOP(fd,2); // speed up
  9243. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name have at maximum 23 characters
  9244. WFIFOHEAD(fd,packet_len(0xd1));
  9245. WFIFOW(fd,0) = 0x0d1; // R 00d1 <type>.B <result>.B: type: 0: deny, 1: allow, result: 0: success, 1: fail 2: list full
  9246. WFIFOB(fd,2) = RFIFOB(fd,26);
  9247. if (RFIFOB(fd,26) == 0)
  9248. { // Add name to ignore list (block)
  9249. // Bot-check...
  9250. if (strcmp(wisp_server_name, nick) == 0)
  9251. { // to find possible bot users who automaticaly ignore people
  9252. 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);
  9253. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9254. WFIFOB(fd,3) = 1; // fail
  9255. WFIFOSET(fd, packet_len(0x0d1));
  9256. return;
  9257. }
  9258. // try to find a free spot, while checking for duplicates at the same time
  9259. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0' && strcmp(sd->ignore[i].name, nick) != 0; i++);
  9260. if (i == MAX_IGNORE_LIST) { // no space for new entry
  9261. WFIFOB(fd,3) = 2; // fail
  9262. WFIFOSET(fd, packet_len(0x0d1));
  9263. return;
  9264. }
  9265. if(sd->ignore[i].name[0] != '\0') { // name already exists
  9266. WFIFOB(fd,3) = 0; // Aegis reports success.
  9267. WFIFOSET(fd, packet_len(0x0d1));
  9268. return;
  9269. }
  9270. //Insert in position i
  9271. memcpy(sd->ignore[i].name, nick, NAME_LENGTH);
  9272. WFIFOB(fd,3) = 0; // success
  9273. WFIFOSET(fd, packet_len(0x0d1));
  9274. //Sort the ignore list.
  9275. //FIXME: why not just use a simple shift-and-insert scheme instead? [ultramage]
  9276. qsort (sd->ignore[0].name, MAX_IGNORE_LIST, sizeof(sd->ignore[0].name), pstrcmp);
  9277. }
  9278. else
  9279. { // Remove name from ignore list (unblock)
  9280. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0' && strcmp(sd->ignore[i].name, nick) != 0; i++);
  9281. if (i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0') { //Not found
  9282. WFIFOB(fd,3) = 1; // fail
  9283. WFIFOSET(fd, packet_len(0x0d1));
  9284. return;
  9285. }
  9286. //Move everything one place down to overwrite removed entry.
  9287. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  9288. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  9289. WFIFOB(fd,3) = 0; // success
  9290. WFIFOSET(fd, packet_len(0x0d1));
  9291. }
  9292. //for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9293. // ShowDebug("Ignored player: '%s'\n", sd->ignore[i].name);
  9294. return;
  9295. }
  9296. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  9297. {
  9298. //printf("Ignore all: state: %d\n", RFIFOB(fd,2));
  9299. // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9300. // S 00d0 <type>len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech
  9301. WFIFOHEAD(fd,packet_len(0xd2));
  9302. WFIFOW(fd,0) = 0x0d2;
  9303. WFIFOB(fd,2) = RFIFOB(fd,2);
  9304. if (RFIFOB(fd,2) == 0) { //Deny all
  9305. if (sd->state.ignoreAll) {
  9306. WFIFOB(fd,3) = 1; // fail
  9307. WFIFOSET(fd, packet_len(0x0d2));
  9308. return;
  9309. }
  9310. sd->state.ignoreAll = 1;
  9311. WFIFOB(fd,3) = 0; // success
  9312. WFIFOSET(fd, packet_len(0x0d2));
  9313. return;
  9314. }
  9315. //Unblock everyone
  9316. if (!sd->state.ignoreAll) {
  9317. if (sd->ignore[0].name[0] != '\0')
  9318. { //Wipe the ignore list.
  9319. memset(sd->ignore, 0, sizeof(sd->ignore));
  9320. WFIFOB(fd,3) = 0;
  9321. WFIFOSET(fd, packet_len(0x0d2));
  9322. return;
  9323. }
  9324. WFIFOB(fd,3) = 1; // fail
  9325. WFIFOSET(fd, packet_len(0x0d2));
  9326. return;
  9327. }
  9328. sd->state.ignoreAll = 0;
  9329. WFIFOB(fd,3) = 0; // success
  9330. WFIFOSET(fd, packet_len(0x0d2));
  9331. return;
  9332. }
  9333. /*==========================================
  9334. * Wis拒否リスト
  9335. *------------------------------------------*/
  9336. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9337. {
  9338. int i;
  9339. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  9340. WFIFOW(fd,0) = 0xd4;
  9341. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9342. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  9343. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  9344. WFIFOSET(fd, WFIFOW(fd,2));
  9345. return;
  9346. }
  9347. /*==========================================
  9348. * スパノビの/doridoriによるSPR2倍
  9349. *------------------------------------------*/
  9350. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  9351. {
  9352. if (sd->state.doridori) return;
  9353. switch (sd->class_&MAPID_UPPERMASK)
  9354. {
  9355. case MAPID_SOUL_LINKER:
  9356. case MAPID_STAR_GLADIATOR:
  9357. case MAPID_TAEKWON:
  9358. if (!sd->state.rest)
  9359. break;
  9360. case MAPID_SUPER_NOVICE:
  9361. sd->state.doridori=1;
  9362. break;
  9363. }
  9364. return;
  9365. }
  9366. /*==========================================
  9367. * スパノビの爆裂波動
  9368. *------------------------------------------*/
  9369. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9370. {
  9371. if(sd){
  9372. int nextbaseexp=pc_nextbaseexp(sd);
  9373. if (battle_config.etc_log){
  9374. if(nextbaseexp != 0)
  9375. 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));
  9376. else
  9377. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9378. }
  9379. 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){
  9380. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9381. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  9382. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9383. }
  9384. }
  9385. return;
  9386. }
  9387. // random notes:
  9388. // 0x214: monster/player info ?
  9389. /*==========================================
  9390. * Friends List
  9391. *------------------------------------------*/
  9392. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9393. { //Toggles a single friend online/offline [Skotlex]
  9394. int i, fd = sd->fd;
  9395. //Seek friend.
  9396. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9397. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9398. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9399. return; //Not found
  9400. WFIFOHEAD(fd,packet_len(0x206));
  9401. WFIFOW(fd, 0) = 0x206;
  9402. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  9403. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  9404. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9405. WFIFOSET(fd, packet_len(0x206));
  9406. }
  9407. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9408. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9409. {
  9410. int account_id, char_id, online;
  9411. account_id = va_arg(ap, int);
  9412. char_id = va_arg(ap, int);
  9413. online = va_arg(ap, int);
  9414. clif_friendslist_toggle(sd, account_id, char_id, online);
  9415. return 0;
  9416. }
  9417. //For sending the whole friends list.
  9418. void clif_friendslist_send(struct map_session_data *sd)
  9419. {
  9420. int i = 0, n, fd = sd->fd;
  9421. // Send friends list
  9422. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  9423. WFIFOW(fd, 0) = 0x201;
  9424. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9425. {
  9426. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9427. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9428. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9429. }
  9430. if (i) {
  9431. WFIFOW(fd,2) = 4 + 32 * i;
  9432. WFIFOSET(fd, WFIFOW(fd,2));
  9433. }
  9434. for (n = 0; n < i; n++)
  9435. { //Sending the online players
  9436. if (map_charid2sd(sd->status.friends[n].char_id))
  9437. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9438. }
  9439. }
  9440. /// Reply for add friend request: (success => type 0)
  9441. /// type=0 : MsgStringTable[821]="You have become friends with (%s)."
  9442. /// type=1 : MsgStringTable[822]="(%s) does not want to be friends with you."
  9443. /// type=2 : MsgStringTable[819]="Your Friend List is full."
  9444. /// type=3 : MsgStringTable[820]="(%s)'s Friend List is full."
  9445. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9446. {
  9447. int fd;
  9448. nullpo_retv(sd);
  9449. fd = sd->fd;
  9450. WFIFOHEAD(fd,packet_len(0x209));
  9451. WFIFOW(fd,0) = 0x209;
  9452. WFIFOW(fd,2) = type;
  9453. if (f_sd)
  9454. {
  9455. WFIFOW(fd,4) = f_sd->status.account_id;
  9456. WFIFOW(fd,8) = f_sd->status.char_id;
  9457. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9458. }
  9459. WFIFOSET(fd, packet_len(0x209));
  9460. }
  9461. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  9462. {
  9463. struct map_session_data *f_sd;
  9464. int i, f_fd;
  9465. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9466. // Friend doesn't exist (no player with this name)
  9467. if (f_sd == NULL) {
  9468. clif_displaymessage(fd, msg_txt(3));
  9469. return;
  9470. }
  9471. // @noask [LuzZza]
  9472. if(f_sd->state.noask) {
  9473. clif_noask_sub(sd, f_sd, 5);
  9474. return;
  9475. }
  9476. // Friend already exists
  9477. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9478. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9479. clif_displaymessage(fd, "Friend already exists.");
  9480. return;
  9481. }
  9482. }
  9483. if (i == MAX_FRIENDS) {
  9484. //No space, list full.
  9485. clif_friendslist_reqack(sd, f_sd, 2);
  9486. return;
  9487. }
  9488. f_fd = f_sd->fd;
  9489. WFIFOHEAD(f_fd,packet_len(0x207));
  9490. WFIFOW(f_fd,0) = 0x207;
  9491. WFIFOL(f_fd,2) = sd->status.account_id;
  9492. WFIFOL(f_fd,6) = sd->status.char_id;
  9493. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9494. WFIFOSET(f_fd, packet_len(0x207));
  9495. return;
  9496. }
  9497. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  9498. {
  9499. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9500. struct map_session_data *f_sd;
  9501. int char_id, account_id;
  9502. char reply;
  9503. account_id = RFIFOL(fd,2);
  9504. char_id = RFIFOL(fd,6);
  9505. reply = RFIFOB(fd,10);
  9506. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9507. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9508. if (f_sd == NULL)
  9509. return;
  9510. if (reply == 0)
  9511. clif_friendslist_reqack(f_sd, sd, 1);
  9512. else {
  9513. int i;
  9514. // Find an empty slot
  9515. for (i = 0; i < MAX_FRIENDS; i++)
  9516. if (f_sd->status.friends[i].char_id == 0)
  9517. break;
  9518. if (i == MAX_FRIENDS) {
  9519. clif_friendslist_reqack(f_sd, sd, 2);
  9520. return;
  9521. }
  9522. f_sd->status.friends[i].account_id = sd->status.account_id;
  9523. f_sd->status.friends[i].char_id = sd->status.char_id;
  9524. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9525. clif_friendslist_reqack(f_sd, sd, 0);
  9526. if (battle_config.friend_auto_add) {
  9527. // Also add f_sd to sd's friendlist.
  9528. for (i = 0; i < MAX_FRIENDS; i++) {
  9529. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  9530. return; //No need to add anything.
  9531. if (sd->status.friends[i].char_id == 0)
  9532. break;
  9533. }
  9534. if (i == MAX_FRIENDS) {
  9535. clif_friendslist_reqack(sd, f_sd, 2);
  9536. return;
  9537. }
  9538. sd->status.friends[i].account_id = f_sd->status.account_id;
  9539. sd->status.friends[i].char_id = f_sd->status.char_id;
  9540. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  9541. clif_friendslist_reqack(sd, f_sd, 0);
  9542. }
  9543. }
  9544. return;
  9545. }
  9546. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  9547. {
  9548. // 0x203 </o> <ID to be removed W 4B>
  9549. int account_id, char_id;
  9550. int i, j;
  9551. account_id = RFIFOL(fd,2);
  9552. char_id = RFIFOL(fd,6);
  9553. // Search friend
  9554. for (i = 0; i < MAX_FRIENDS &&
  9555. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9556. if (i == MAX_FRIENDS) {
  9557. clif_displaymessage(fd, "Name not found in list.");
  9558. return;
  9559. }
  9560. // move all chars down
  9561. for(j = i + 1; j < MAX_FRIENDS; j++)
  9562. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9563. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9564. clif_displaymessage(fd, "Friend removed");
  9565. WFIFOHEAD(fd,packet_len(0x20a));
  9566. WFIFOW(fd,0) = 0x20a;
  9567. WFIFOL(fd,2) = account_id;
  9568. WFIFOL(fd,6) = char_id;
  9569. WFIFOSET(fd, packet_len(0x20a));
  9570. // clif_friendslist_send(sd); //This is not needed anymore.
  9571. return;
  9572. }
  9573. /*==========================================
  9574. * /killall
  9575. *------------------------------------------*/
  9576. void clif_parse_GMKillAll(int fd, struct map_session_data* sd)
  9577. {
  9578. is_atcommand(fd, sd, "@kickall");
  9579. }
  9580. /*==========================================
  9581. * /pvpinfo
  9582. *------------------------------------------*/
  9583. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  9584. {
  9585. WFIFOHEAD(fd,packet_len(0x210));
  9586. WFIFOW(fd,0) = 0x210;
  9587. //WFIFOL(fd,2) = 0; // not sure what for yet
  9588. //WFIFOL(fd,6) = 0;
  9589. WFIFOL(fd,10) = sd->pvp_won; // times won
  9590. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  9591. WFIFOL(fd,18) = sd->pvp_point;
  9592. WFIFOSET(fd, packet_len(0x210));
  9593. return;
  9594. }
  9595. /*==========================================
  9596. * /blacksmith
  9597. *------------------------------------------*/
  9598. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  9599. {
  9600. int i;
  9601. const char* name;
  9602. WFIFOHEAD(fd,packet_len(0x219));
  9603. WFIFOW(fd,0) = 0x219;
  9604. //Packet size limits this list to 10 elements. [Skotlex]
  9605. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9606. if (smith_fame_list[i].id > 0) {
  9607. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  9608. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  9609. {
  9610. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  9611. } else
  9612. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  9613. } else
  9614. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  9615. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  9616. }
  9617. for(;i < 10; i++) { //In case the MAX is less than 10.
  9618. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  9619. WFIFOL(fd, 242 + i * 4) = 0;
  9620. }
  9621. WFIFOSET(fd, packet_len(0x219));
  9622. }
  9623. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  9624. {
  9625. int fd = sd->fd;
  9626. WFIFOHEAD(fd,packet_len(0x21b));
  9627. WFIFOW(fd,0) = 0x21b;
  9628. WFIFOL(fd,2) = points;
  9629. WFIFOL(fd,6) = sd->status.fame;
  9630. WFIFOSET(fd, packet_len(0x21b));
  9631. return 0;
  9632. }
  9633. /*==========================================
  9634. * /alchemist
  9635. *------------------------------------------*/
  9636. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  9637. {
  9638. int i;
  9639. const char* name;
  9640. WFIFOHEAD(fd,packet_len(0x21a));
  9641. WFIFOW(fd,0) = 0x21a;
  9642. //Packet size limits this list to 10 elements. [Skotlex]
  9643. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9644. if (chemist_fame_list[i].id > 0) {
  9645. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  9646. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  9647. {
  9648. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9649. } else
  9650. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  9651. } else
  9652. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9653. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  9654. }
  9655. for(;i < 10; i++) { //In case the MAX is less than 10.
  9656. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9657. WFIFOL(fd, 242 + i * 4) = 0;
  9658. }
  9659. WFIFOSET(fd, packet_len(0x21a));
  9660. }
  9661. int clif_fame_alchemist(struct map_session_data *sd, int points)
  9662. {
  9663. int fd = sd->fd;
  9664. WFIFOHEAD(fd,packet_len(0x21c));
  9665. WFIFOW(fd,0) = 0x21c;
  9666. WFIFOL(fd,2) = points;
  9667. WFIFOL(fd,6) = sd->status.fame;
  9668. WFIFOSET(fd, packet_len(0x21c));
  9669. return 0;
  9670. }
  9671. /*==========================================
  9672. * /taekwon
  9673. *------------------------------------------*/
  9674. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  9675. {
  9676. int i;
  9677. const char* name;
  9678. WFIFOHEAD(fd,packet_len(0x226));
  9679. WFIFOW(fd,0) = 0x226;
  9680. //Packet size limits this list to 10 elements. [Skotlex]
  9681. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9682. if (taekwon_fame_list[i].id > 0) {
  9683. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  9684. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  9685. {
  9686. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9687. } else
  9688. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  9689. } else
  9690. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9691. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  9692. }
  9693. for(;i < 10; i++) { //In case the MAX is less than 10.
  9694. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9695. WFIFOL(fd, 242 + i * 4) = 0;
  9696. }
  9697. WFIFOSET(fd, packet_len(0x226));
  9698. }
  9699. int clif_fame_taekwon(struct map_session_data *sd, int points)
  9700. {
  9701. int fd = sd->fd;
  9702. WFIFOHEAD(fd,packet_len(0x224));
  9703. WFIFOW(fd,0) = 0x224;
  9704. WFIFOL(fd,2) = points;
  9705. WFIFOL(fd,6) = sd->status.fame;
  9706. WFIFOSET(fd, packet_len(0x224));
  9707. return 0;
  9708. }
  9709. /*==========================================
  9710. * PK Ranking table?
  9711. *------------------------------------------*/
  9712. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  9713. {
  9714. int i;
  9715. WFIFOHEAD(fd,packet_len(0x238));
  9716. WFIFOW(fd,0) = 0x238;
  9717. for(i=0;i<10;i++){
  9718. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  9719. WFIFOL(fd,i*4+242) = 0;
  9720. }
  9721. WFIFOSET(fd, packet_len(0x238));
  9722. return;
  9723. }
  9724. /*==========================================
  9725. * SG Feel save OK [Komurka]
  9726. *------------------------------------------*/
  9727. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  9728. {
  9729. char feel_var[3][NAME_LENGTH] = {"PC_FEEL_SUN","PC_FEEL_MOON","PC_FEEL_STAR"};
  9730. int i;
  9731. if (sd->menuskill_id != SG_FEEL)
  9732. return;
  9733. i = sd->menuskill_val-1;
  9734. if (i<0 || i > 2) return; //Bug?
  9735. sd->feel_map[i].index = map[sd->bl.m].index;
  9736. sd->feel_map[i].m = sd->bl.m;
  9737. pc_setglobalreg(sd,feel_var[i],map[sd->bl.m].index);
  9738. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  9739. // clif_misceffect2(&sd->bl, 0x1b0);
  9740. // clif_misceffect2(&sd->bl, 0x21f);
  9741. clif_feel_info(sd, i, 0);
  9742. sd->menuskill_val = sd->menuskill_id = 0;
  9743. }
  9744. /*==========================================
  9745. * Question about Star Glaldiator save map [Komurka]
  9746. *------------------------------------------*/
  9747. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv)
  9748. {
  9749. WFIFOHEAD(fd,packet_len(0x253));
  9750. WFIFOW(fd,0)=0x253;
  9751. WFIFOSET(fd, packet_len(0x253));
  9752. sd->menuskill_id = SG_FEEL;
  9753. sd->menuskill_val = skilllv;
  9754. }
  9755. void clif_parse_AdoptRequest(int fd,struct map_session_data *sd)
  9756. {
  9757. //TODO: add somewhere the adopt code, checks for exploits, etc, etc.
  9758. //Missing packets are the client's reply packets to the adopt request one.
  9759. //[Skotlex]
  9760. int account_id;
  9761. struct map_session_data *sd2;
  9762. account_id = RFIFOL(fd,2);
  9763. sd2 = map_id2sd(account_id);
  9764. if(sd2 && sd2->fd && sd2 != sd && sd2->status.party_id == sd->status.party_id) { //FIXME: No checks whatsoever are in place yet!
  9765. fd = sd2->fd;
  9766. WFIFOHEAD(fd,packet_len(0x1f9));
  9767. WFIFOW(fd,0)=0x1f9;
  9768. WFIFOSET(fd, packet_len(0x1f9));
  9769. }
  9770. }
  9771. /*==========================================
  9772. * Homunculus packets
  9773. *------------------------------------------*/
  9774. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  9775. {
  9776. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  9777. }
  9778. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  9779. { //[orn]
  9780. nullpo_retv(sd);
  9781. if(!merc_is_hom_active(sd->hd))
  9782. return;
  9783. unit_walktoxy(&sd->hd->bl, sd->bl.x,sd->bl.y-1, 4);
  9784. }
  9785. void clif_parse_HomMoveTo(int fd,struct map_session_data *sd)
  9786. { //[orn]
  9787. short x,y,cmd;
  9788. nullpo_retv(sd);
  9789. if(!merc_is_hom_active(sd->hd))
  9790. return;
  9791. cmd = RFIFOW(fd,0);
  9792. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  9793. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  9794. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  9795. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  9796. unit_walktoxy(&(sd->hd->bl),x,y,4);
  9797. }
  9798. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  9799. { //[orn]
  9800. if(!merc_is_hom_active(sd->hd))
  9801. return;
  9802. unit_attack(&sd->hd->bl,RFIFOL(fd,6),0) ;
  9803. }
  9804. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  9805. { //[orn]
  9806. int cmd;
  9807. cmd = RFIFOW(fd,0);
  9808. if(!merc_is_hom_active(sd->hd))
  9809. return;
  9810. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  9811. }
  9812. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  9813. {
  9814. int item_position;
  9815. nullpo_retv(sd);
  9816. item_position = pc_search_inventory(sd, 7621);
  9817. if (item_position < 0)
  9818. return;
  9819. if (!status_revive(&sd->bl, 100, 100))
  9820. return;
  9821. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  9822. pc_delitem(sd, item_position, 1, 0);
  9823. }
  9824. /*==========================================
  9825. * パケットデバッグ
  9826. *------------------------------------------*/
  9827. void clif_parse_debug(int fd,struct map_session_data *sd)
  9828. {
  9829. int i, cmd, len;
  9830. cmd = RFIFOW(fd,0);
  9831. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  9832. ShowDebug("packet debug 0x%4X\n",cmd);
  9833. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  9834. for(i=0;i<len;i++){
  9835. if((i&15)==0)
  9836. printf("\n%04X ",i);
  9837. printf("%02X ",RFIFOB(fd,i));
  9838. }
  9839. printf("\n");
  9840. }
  9841. /*==========================================
  9842. * Main client packet processing function
  9843. *------------------------------------------*/
  9844. int clif_parse(int fd)
  9845. {
  9846. int cmd, packet_ver, packet_len, err;
  9847. TBL_PC* sd;
  9848. int pnum;
  9849. //TODO apply deplays or disconnect based on packet throughput [FlavioJS]
  9850. // Note: "click masters" can do 80+ clicks in 10 seconds
  9851. for( pnum = 0; pnum < 3; ++pnum )// Limit max packets per cycle to 3 (delay packet spammers) [FlavioJS]
  9852. { // begin main client packet processing loop
  9853. sd = (TBL_PC *)session[fd]->session_data;
  9854. if (session[fd]->eof) {
  9855. if (sd) {
  9856. if (sd->state.autotrade) {
  9857. //Disassociate character from the socket connection.
  9858. session[fd]->session_data = NULL;
  9859. sd->fd = 0;
  9860. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  9861. } else
  9862. if (sd->state.auth) {
  9863. // Player logout display [Valaris]
  9864. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  9865. clif_quitsave(fd, sd);
  9866. } else {
  9867. ShowInfo("Player AID:%d/CID:%d (not authenticated) logged off.\n", sd->bl.id, sd->status.char_id);
  9868. map_quit(sd);
  9869. }
  9870. } else {
  9871. uint32 ip = session[fd]->client_addr;
  9872. ShowInfo("Closed connection from '"CL_WHITE"%d.%d.%d.%d"CL_RESET"'.\n", CONVIP(ip));
  9873. }
  9874. do_close(fd);
  9875. return 0;
  9876. }
  9877. if (RFIFOREST(fd) < 2)
  9878. return 0;
  9879. cmd = RFIFOW(fd,0);
  9880. // identify client's packet version
  9881. if (sd) {
  9882. packet_ver = sd->packet_ver;
  9883. } else {
  9884. // check authentification packet to know packet version
  9885. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  9886. if( err )
  9887. {// failed to identify packet version
  9888. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  9889. err == 1 ? "" :
  9890. err == 2 ? ", possibly for having an invalid account_id" :
  9891. err == 3 ? ", possibly for having an invalid char_id." :
  9892. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  9893. err == 4 ? ", possibly for having an invalid login_id1." :
  9894. err == 5 ? ", possibly for having an invalid client_tick." :
  9895. */
  9896. err == 6 ? ", possibly for having an invalid sex." :
  9897. ". ERROR invalid error code"));
  9898. WFIFOHEAD(fd,packet_len(0x6a));
  9899. WFIFOW(fd,0) = 0x6a;
  9900. WFIFOB(fd,2) = 3; // Rejected from Server
  9901. WFIFOSET(fd,packet_len(0x6a));
  9902. RFIFOSKIP(fd, RFIFOREST(fd));
  9903. clif_setwaitclose(fd);
  9904. return 0;
  9905. }
  9906. }
  9907. // filter out invalid / unsupported packets
  9908. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  9909. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  9910. set_eof(fd);
  9911. return 0;
  9912. }
  9913. // determine real packet length
  9914. packet_len = packet_db[packet_ver][cmd].len;
  9915. if (packet_len == -1) { // variable-length packet
  9916. if (RFIFOREST(fd) < 4)
  9917. return 0;
  9918. packet_len = RFIFOW(fd,2);
  9919. if (packet_len < 4 || packet_len > 32768) {
  9920. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  9921. set_eof(fd);
  9922. return 0;
  9923. }
  9924. }
  9925. if ((int)RFIFOREST(fd) < packet_len)
  9926. return 0; // not enough data received to form the packet
  9927. if (sd && sd->state.waitingdisconnect == 1) {
  9928. // 切断待ちの場合パケットを処理しない
  9929. } else if (packet_db[packet_ver][cmd].func) {
  9930. if (sd && sd->bl.prev == NULL &&
  9931. packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck)
  9932. ; //Only valid packet when player is not on a map is the finish-loading packet.
  9933. else
  9934. if (sd
  9935. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  9936. || packet_db[packet_ver][cmd].func == clif_parse_debug
  9937. ) //Only execute the function when there's an sd (except for debug/wanttoconnect packets)
  9938. packet_db[packet_ver][cmd].func(fd, sd);
  9939. }
  9940. #if DUMP_UNKNOWN_PACKET
  9941. else if (battle_config.error_log)
  9942. {
  9943. int i;
  9944. FILE *fp;
  9945. char packet_txt[256] = "save/packet.txt";
  9946. time_t now;
  9947. dump = 1;
  9948. if ((fp = fopen(packet_txt, "a")) == NULL) {
  9949. ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
  9950. return 1;
  9951. } else {
  9952. time(&now);
  9953. if (sd && sd->state.auth) {
  9954. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  9955. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  9956. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  9957. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  9958. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  9959. for(i = 0; i < packet_len; i++) {
  9960. if ((i & 15) == 0)
  9961. fprintf(fp, "\n\t%04X ", i);
  9962. fprintf(fp, "%02X ", RFIFOB(fd,i));
  9963. }
  9964. fprintf(fp, "\n\n");
  9965. fclose(fp);
  9966. }
  9967. }
  9968. #endif
  9969. /* TODO: use utils.c :: dump()
  9970. if (dump) {
  9971. int i;
  9972. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  9973. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  9974. for(i = 0; i < packet_len; i++) {
  9975. if ((i & 15) == 0)
  9976. printf("\n%04X ",i);
  9977. printf("%02X ", RFIFOB(fd,i));
  9978. }
  9979. printf("\n");
  9980. if (sd && sd->state.auth) {
  9981. if (sd->status.name != NULL)
  9982. printf("\nAccount ID %d, character ID %d, player name %s.\n",
  9983. sd->status.account_id, sd->status.char_id, sd->status.name);
  9984. else
  9985. printf("\nAccount ID %d.\n", sd->bl.id);
  9986. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  9987. printf("\nAccount ID %d.\n", sd->bl.id);
  9988. }*/
  9989. RFIFOSKIP(fd, packet_len);
  9990. }; // main loop end
  9991. return 0;
  9992. }
  9993. /*==========================================
  9994. * パケットデータベース読み込み
  9995. *------------------------------------------*/
  9996. static int packetdb_readdb(void)
  9997. {
  9998. FILE *fp;
  9999. char line[1024];
  10000. int ln=0;
  10001. int cmd,i,j,packet_ver;
  10002. int max_cmd=-1;
  10003. int skip_ver = 0;
  10004. int warned = 0;
  10005. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  10006. int packet_len_table[MAX_PACKET_DB] = {
  10007. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10011. //#0x0040
  10012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10014. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  10015. #if PACKETVER < 2
  10016. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  10017. #else // 78-7b 亀島以降 lv99エフェクト用
  10018. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  10019. #endif
  10020. //#0x0080
  10021. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  10022. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  10023. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  10024. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  10025. //#0x00C0
  10026. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  10027. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  10028. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  10029. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  10030. //#0x0100
  10031. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  10032. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  10033. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  10034. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  10035. //#0x0140
  10036. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  10037. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  10038. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  10039. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  10040. //#0x0180
  10041. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  10042. #if PACKETVER < 1
  10043. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10044. #else // 196 comodo以降 状態表示アイコン用
  10045. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10046. #endif
  10047. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  10048. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  10049. //#0x01C0, Set 0x1d5=-1
  10050. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  10051. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  10052. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  10053. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  10054. //#0x0200
  10055. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  10056. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  10057. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  10058. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1, -1, 4, 2,
  10059. //#0x0240
  10060. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  10061. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4, -1, 4, 0,
  10062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10064. //#0x0280
  10065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0,
  10066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10068. 0, 0, 0, 0, 0, 0, 0, 0, 0,191, 0, 0, 0, 0, 0, 0,
  10069. //#0x02C0
  10070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10074. };
  10075. struct {
  10076. void (*func)(int, struct map_session_data *);
  10077. char *name;
  10078. } clif_parse_func[]={
  10079. {clif_parse_WantToConnection,"wanttoconnection"},
  10080. {clif_parse_LoadEndAck,"loadendack"},
  10081. {clif_parse_TickSend,"ticksend"},
  10082. {clif_parse_WalkToXY,"walktoxy"},
  10083. {clif_parse_QuitGame,"quitgame"},
  10084. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  10085. {clif_parse_GlobalMessage,"globalmessage"},
  10086. {clif_parse_MapMove,"mapmove"},
  10087. {clif_parse_ChangeDir,"changedir"},
  10088. {clif_parse_Emotion,"emotion"},
  10089. {clif_parse_HowManyConnections,"howmanyconnections"},
  10090. {clif_parse_ActionRequest,"actionrequest"},
  10091. {clif_parse_Restart,"restart"},
  10092. {clif_parse_WisMessage,"wis"},
  10093. {clif_parse_GMmessage,"gmmessage"},
  10094. {clif_parse_TakeItem,"takeitem"},
  10095. {clif_parse_DropItem,"dropitem"},
  10096. {clif_parse_UseItem,"useitem"},
  10097. {clif_parse_EquipItem,"equipitem"},
  10098. {clif_parse_UnequipItem,"unequipitem"},
  10099. {clif_parse_NpcClicked,"npcclicked"},
  10100. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  10101. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  10102. {clif_parse_NpcSellListSend,"npcselllistsend"},
  10103. {clif_parse_CreateChatRoom,"createchatroom"},
  10104. {clif_parse_ChatAddMember,"chataddmember"},
  10105. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  10106. {clif_parse_ChangeChatOwner,"changechatowner"},
  10107. {clif_parse_KickFromChat,"kickfromchat"},
  10108. {clif_parse_ChatLeave,"chatleave"},
  10109. {clif_parse_TradeRequest,"traderequest"},
  10110. {clif_parse_TradeAck,"tradeack"},
  10111. {clif_parse_TradeAddItem,"tradeadditem"},
  10112. {clif_parse_TradeOk,"tradeok"},
  10113. {clif_parse_TradeCancel,"tradecancel"},
  10114. {clif_parse_TradeCommit,"tradecommit"},
  10115. {clif_parse_StopAttack,"stopattack"},
  10116. {clif_parse_PutItemToCart,"putitemtocart"},
  10117. {clif_parse_GetItemFromCart,"getitemfromcart"},
  10118. {clif_parse_RemoveOption,"removeoption"},
  10119. {clif_parse_ChangeCart,"changecart"},
  10120. {clif_parse_StatusUp,"statusup"},
  10121. {clif_parse_SkillUp,"skillup"},
  10122. {clif_parse_UseSkillToId,"useskilltoid"},
  10123. {clif_parse_UseSkillToPos,"useskilltopos"},
  10124. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  10125. {clif_parse_UseSkillMap,"useskillmap"},
  10126. {clif_parse_RequestMemo,"requestmemo"},
  10127. {clif_parse_ProduceMix,"producemix"},
  10128. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  10129. {clif_parse_NpcNextClicked,"npcnextclicked"},
  10130. {clif_parse_NpcAmountInput,"npcamountinput"},
  10131. {clif_parse_NpcStringInput,"npcstringinput"},
  10132. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  10133. {clif_parse_ItemIdentify,"itemidentify"},
  10134. {clif_parse_SelectArrow,"selectarrow"},
  10135. {clif_parse_AutoSpell,"autospell"},
  10136. {clif_parse_UseCard,"usecard"},
  10137. {clif_parse_InsertCard,"insertcard"},
  10138. {clif_parse_RepairItem,"repairitem"},
  10139. {clif_parse_WeaponRefine,"weaponrefine"},
  10140. {clif_parse_SolveCharName,"solvecharname"},
  10141. {clif_parse_ResetChar,"resetchar"},
  10142. {clif_parse_LGMmessage,"lgmmessage"},
  10143. {clif_parse_MoveToKafra,"movetokafra"},
  10144. {clif_parse_MoveFromKafra,"movefromkafra"},
  10145. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  10146. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  10147. {clif_parse_CloseKafra,"closekafra"},
  10148. {clif_parse_CreateParty,"createparty"},
  10149. {clif_parse_CreateParty2,"createparty2"},
  10150. {clif_parse_PartyInvite,"partyinvite"},
  10151. {clif_parse_PartyInvite2,"partyinvite2"},
  10152. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  10153. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  10154. {clif_parse_LeaveParty,"leaveparty"},
  10155. {clif_parse_RemovePartyMember,"removepartymember"},
  10156. {clif_parse_PartyChangeOption,"partychangeoption"},
  10157. {clif_parse_PartyMessage,"partymessage"},
  10158. {clif_parse_CloseVending,"closevending"},
  10159. {clif_parse_VendingListReq,"vendinglistreq"},
  10160. {clif_parse_PurchaseReq,"purchasereq"},
  10161. {clif_parse_OpenVending,"openvending"},
  10162. {clif_parse_CreateGuild,"createguild"},
  10163. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  10164. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  10165. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  10166. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  10167. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  10168. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  10169. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  10170. {clif_parse_GuildInvite,"guildinvite"},
  10171. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  10172. {clif_parse_GuildLeave,"guildleave"},
  10173. {clif_parse_GuildExpulsion,"guildexplusion"},
  10174. {clif_parse_GuildMessage,"guildmessage"},
  10175. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  10176. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  10177. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  10178. {clif_parse_GuildOpposition,"guildopposition"},
  10179. {clif_parse_GuildBreak,"guildbreak"},
  10180. {clif_parse_PetMenu,"petmenu"},
  10181. {clif_parse_CatchPet,"catchpet"},
  10182. {clif_parse_SelectEgg,"selectegg"},
  10183. {clif_parse_SendEmotion,"sendemotion"},
  10184. {clif_parse_ChangePetName,"changepetname"},
  10185. {clif_parse_GMKick,"gmkick"},
  10186. {clif_parse_GMHide,"gmhide"},
  10187. {clif_parse_GMReqNoChat,"gmreqnochat"},
  10188. {clif_parse_GMReqNoChatCount,"gmreqnochatcount"},
  10189. {clif_parse_NoviceDoriDori,"sndoridori"},
  10190. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  10191. {clif_parse_PMIgnore,"wisexin"},
  10192. {clif_parse_PMIgnoreList,"wisexlist"},
  10193. {clif_parse_PMIgnoreAll,"wisall"},
  10194. {clif_parse_FriendsListAdd,"friendslistadd"},
  10195. {clif_parse_FriendsListRemove,"friendslistremove"},
  10196. {clif_parse_FriendsListReply,"friendslistreply"},
  10197. {clif_parse_GMKillAll,"killall"},
  10198. {clif_parse_Recall,"summon"},
  10199. {clif_parse_GM_Monster_Item,"itemmonster"},
  10200. {clif_parse_Shift,"shift"},
  10201. {clif_parse_Blacksmith,"blacksmith"},
  10202. {clif_parse_Alchemist,"alchemist"},
  10203. {clif_parse_Taekwon,"taekwon"},
  10204. {clif_parse_RankingPk,"rankingpk"},
  10205. {clif_parse_FeelSaveOk,"feelsaveok"},
  10206. {clif_parse_AdoptRequest,"adopt"},
  10207. {clif_parse_debug,"debug"},
  10208. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  10209. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  10210. {clif_parse_HomMoveTo,"hommoveto"},
  10211. {clif_parse_HomAttack,"homattack"},
  10212. {clif_parse_HomMenu,"hommenu"},
  10213. {clif_parse_StoragePassword,"storagepassword"},
  10214. {clif_parse_Hotkey,"hotkey"},
  10215. {clif_parse_AutoRevive,"autorevive"},
  10216. {NULL,NULL}
  10217. };
  10218. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  10219. memset(packet_db,0,sizeof(packet_db));
  10220. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  10221. packet_len(i) = packet_len_table[i];
  10222. sprintf(line, "%s/packet_db.txt", db_path);
  10223. if( (fp=fopen(line,"r"))==NULL ){
  10224. ShowFatalError("can't read %s\n", line);
  10225. exit(EXIT_FAILURE);
  10226. }
  10227. clif_config.packet_db_ver = MAX_PACKET_VER;
  10228. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  10229. while( fgets(line, sizeof(line), fp) )
  10230. {
  10231. ln++;
  10232. if(line[0]=='/' && line[1]=='/')
  10233. continue;
  10234. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  10235. {
  10236. if(strcmpi(w1,"packet_ver")==0) {
  10237. int prev_ver = packet_ver;
  10238. skip_ver = 0;
  10239. packet_ver = atoi(w2);
  10240. if ( packet_ver > MAX_PACKET_VER )
  10241. { //Check to avoid overflowing. [Skotlex]
  10242. if( (warned&1) == 0 )
  10243. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  10244. warned &= 1;
  10245. skip_ver = 1;
  10246. }
  10247. else if( packet_ver < 0 )
  10248. {
  10249. if( (warned&2) == 0 )
  10250. ShowWarning("Negative packet versions are not supported.\n");
  10251. warned &= 2;
  10252. skip_ver = 1;
  10253. }
  10254. else if( packet_ver == SERVER )
  10255. {
  10256. if( (warned&4) == 0 )
  10257. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  10258. warned &= 4;
  10259. skip_ver = 1;
  10260. }
  10261. if( skip_ver )
  10262. {
  10263. ShowWarning("Skipping packet version %d.\n", packet_ver);
  10264. packet_ver = prev_ver;
  10265. continue;
  10266. }
  10267. // copy from previous version into new version and continue
  10268. // - indicating all following packets should be read into the newer version
  10269. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  10270. continue;
  10271. } else if(strcmpi(w1,"packet_db_ver")==0) {
  10272. if(strcmpi(w2,"default")==0) //This is the preferred version.
  10273. clif_config.packet_db_ver = MAX_PACKET_VER;
  10274. else // to manually set the packet DB version
  10275. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  10276. continue;
  10277. }
  10278. }
  10279. if( skip_ver != 0 )
  10280. continue; // Skipping current packet version
  10281. memset(str,0,sizeof(str));
  10282. for(j=0,p=line;j<4 && p; ++j)
  10283. {
  10284. str[j]=p;
  10285. p=strchr(p,',');
  10286. if(p) *p++=0;
  10287. }
  10288. if(str[0]==NULL)
  10289. continue;
  10290. cmd=strtol(str[0],(char **)NULL,0);
  10291. if(max_cmd < cmd)
  10292. max_cmd = cmd;
  10293. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  10294. continue;
  10295. if(str[1]==NULL){
  10296. ShowError("packet_db: packet len error\n");
  10297. continue;
  10298. }
  10299. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  10300. if(str[2]==NULL){
  10301. packet_db[packet_ver][cmd].func = NULL;
  10302. ln++;
  10303. continue;
  10304. }
  10305. for(j=0;j<ARRAYLENGTH(clif_parse_func);j++){
  10306. if(clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0)
  10307. {
  10308. if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func)
  10309. { //If we are updating a function, we need to zero up the previous one. [Skotlex]
  10310. for(i=0;i<=MAX_PACKET_DB;i++){
  10311. if (packet_db[packet_ver][i].func == clif_parse_func[j].func)
  10312. {
  10313. memset(&packet_db[packet_ver][i], 0, sizeof(struct s_packet_db));
  10314. break;
  10315. }
  10316. }
  10317. }
  10318. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  10319. break;
  10320. }
  10321. }
  10322. // set the identifying cmd for the packet_db version
  10323. if (strcmp(str[2],"wanttoconnection")==0)
  10324. clif_config.connect_cmd[packet_ver] = cmd;
  10325. if(str[3]==NULL){
  10326. ShowError("packet_db: packet error\n");
  10327. exit(EXIT_FAILURE);
  10328. }
  10329. for(j=0,p2=str[3];p2;j++){
  10330. short k;
  10331. str2[j]=p2;
  10332. p2=strchr(p2,':');
  10333. if(p2) *p2++=0;
  10334. k = atoi(str2[j]);
  10335. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  10336. packet_db[packet_ver][cmd].pos[j] = k;
  10337. }
  10338. }
  10339. fclose(fp);
  10340. if(max_cmd > MAX_PACKET_DB)
  10341. {
  10342. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  10343. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  10344. }
  10345. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  10346. { //Locate the nearest version that we still support. [Skotlex]
  10347. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  10348. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  10349. }
  10350. 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);
  10351. return 0;
  10352. }
  10353. /*==========================================
  10354. *
  10355. *------------------------------------------*/
  10356. int do_init_clif(void)
  10357. {
  10358. clif_config.packet_db_ver = -1; // the main packet version of the DB
  10359. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  10360. memset(packet_db,0,sizeof(packet_db));
  10361. //Using the packet_db file is the only way to set up packets now [Skotlex]
  10362. packetdb_readdb();
  10363. set_defaultparse(clif_parse);
  10364. if (!make_listen_bind(bind_ip,map_port)) {
  10365. ShowFatalError("can't bind game port\n");
  10366. exit(EXIT_FAILURE);
  10367. }
  10368. add_timer_func_list(clif_waitclose, "clif_waitclose");
  10369. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  10370. add_timer_func_list(clif_delayquit, "clif_delayquit");
  10371. return 0;
  10372. }