clif.c 319 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968
  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. static void clif_hpmeter_single(int fd, struct map_session_data *sd);
  89. /*==========================================
  90. * map鯖のip設定
  91. *------------------------------------------*/
  92. int clif_setip(const char* ip)
  93. {
  94. char ip_str[16];
  95. map_ip = host2ip(ip);
  96. if (!map_ip) {
  97. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  98. return 0;
  99. }
  100. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  101. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  102. return 1;
  103. }
  104. void clif_setbindip(const char* ip)
  105. {
  106. char ip_str[16];
  107. bind_ip = host2ip(ip);
  108. if (bind_ip) {
  109. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  110. } else {
  111. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  112. }
  113. }
  114. /*==========================================
  115. * map鯖のport設定
  116. *------------------------------------------*/
  117. void clif_setport(uint16 port)
  118. {
  119. map_port = port;
  120. }
  121. /*==========================================
  122. * map鯖のip読み出し
  123. *------------------------------------------*/
  124. uint32 clif_getip(void)
  125. {
  126. return map_ip;
  127. }
  128. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  129. uint32 clif_refresh_ip(void)
  130. {
  131. uint32 new_ip;
  132. new_ip = host2ip(map_ip_str);
  133. if (new_ip && new_ip != map_ip) {
  134. map_ip = new_ip;
  135. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  136. return map_ip;
  137. }
  138. return 0;
  139. }
  140. /*==========================================
  141. * map鯖のport読み出し
  142. *------------------------------------------*/
  143. uint16 clif_getport(void)
  144. {
  145. return map_port;
  146. }
  147. /*==========================================
  148. * Counts connected players.
  149. *------------------------------------------*/
  150. int clif_countusers(void)
  151. {
  152. int users = 0, i;
  153. struct map_session_data *sd;
  154. for(i = 0; i < fd_max; i++) {
  155. if (session[i] && session[i]->func_parse == clif_parse &&
  156. (sd = (struct map_session_data*)session[i]->session_data) &&
  157. sd->state.auth && !(battle_config.hide_GM_session && pc_isGM(sd)))
  158. users++;
  159. }
  160. return users;
  161. }
  162. /*==========================================
  163. * 全てのclientに対してfunc()実行
  164. *------------------------------------------*/
  165. int clif_foreachclient(int (*func)(struct map_session_data*, va_list),...) //recoded by sasuke, bug when player count gets higher [Kevin]
  166. {
  167. int i;
  168. va_list ap;
  169. struct map_session_data *sd;
  170. va_start(ap,func);
  171. for(i = 0; i < fd_max; i++) {
  172. if ( session[i] && session[i]->func_parse == clif_parse) {
  173. sd = (struct map_session_data*)session[i]->session_data;
  174. if ( sd && sd->state.auth && !sd->state.waitingdisconnect )
  175. func(sd, ap);
  176. }
  177. }
  178. va_end(ap);
  179. return 0;
  180. }
  181. /*==========================================
  182. * clif_sendでAREA*指定時用
  183. *------------------------------------------*/
  184. int clif_send_sub(struct block_list *bl, va_list ap)
  185. {
  186. struct block_list *src_bl;
  187. struct map_session_data *sd;
  188. unsigned char *buf;
  189. int len, type, fd;
  190. nullpo_retr(0, bl);
  191. nullpo_retr(0, ap);
  192. nullpo_retr(0, sd = (struct map_session_data *)bl);
  193. fd = sd->fd;
  194. if (!fd) //Don't send to disconnected clients.
  195. return 0;
  196. buf = va_arg(ap,unsigned char*);
  197. len = va_arg(ap,int);
  198. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  199. type = va_arg(ap,int);
  200. switch(type)
  201. {
  202. case AREA_WOS:
  203. if (bl == src_bl)
  204. return 0;
  205. break;
  206. case AREA_WOC:
  207. if (sd->chatID || bl == src_bl)
  208. return 0;
  209. break;
  210. case AREA_WOSC:
  211. {
  212. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  213. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  214. return 0;
  215. }
  216. break;
  217. }
  218. if (session[fd] != NULL) {
  219. WFIFOHEAD(fd, len);
  220. if (WFIFOP(fd,0) == buf) {
  221. printf("WARNING: Invalid use of clif_send function\n");
  222. printf(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  223. printf(" Please correct your code.\n");
  224. // don't send to not move the pointer of the packet for next sessions in the loop
  225. WFIFOSET(fd,0);//## TODO is this ok?
  226. } else {
  227. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  228. memcpy(WFIFOP(fd,0), buf, len);
  229. WFIFOSET(fd,len);
  230. }
  231. }
  232. }
  233. return 0;
  234. }
  235. /*==========================================
  236. *
  237. *------------------------------------------*/
  238. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  239. {
  240. int i;
  241. struct map_session_data *sd = NULL;
  242. struct party_data *p = NULL;
  243. struct guild *g = NULL;
  244. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  245. if (type != ALL_CLIENT &&
  246. type != CHAT_MAINCHAT) {
  247. nullpo_retr(0, bl);
  248. if (bl->type == BL_PC) {
  249. sd = (struct map_session_data *)bl;
  250. }
  251. }
  252. switch(type) {
  253. case ALL_CLIENT: //All player clients.
  254. for (i = 0; i < fd_max; i++) {
  255. if (session[i] && session[i]->func_parse == clif_parse &&
  256. (sd = (struct map_session_data *)session[i]->session_data) != NULL&&
  257. sd->state.auth) {
  258. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  259. WFIFOHEAD(i, len);
  260. memcpy(WFIFOP(i,0), buf, len);
  261. WFIFOSET(i,len);
  262. }
  263. }
  264. }
  265. break;
  266. case ALL_SAMEMAP: //All players on the same map
  267. for(i = 0; i < fd_max; i++) {
  268. if (session[i] && session[i]->func_parse == clif_parse &&
  269. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  270. sd->state.auth && sd->bl.m == bl->m) {
  271. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  272. WFIFOHEAD(i,len);
  273. memcpy(WFIFOP(i,0), buf, len);
  274. WFIFOSET(i,len);
  275. }
  276. }
  277. }
  278. break;
  279. case AREA:
  280. case AREA_WOSC:
  281. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  282. clif_send (buf, len, bl, SELF);
  283. case AREA_WOC:
  284. case AREA_WOS:
  285. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  286. BL_PC, buf, len, bl, type);
  287. break;
  288. case AREA_CHAT_WOC:
  289. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  290. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  291. break;
  292. case CHAT:
  293. case CHAT_WOS:
  294. {
  295. struct chat_data *cd;
  296. if (sd) {
  297. cd = (struct chat_data*)map_id2bl(sd->chatID);
  298. } else if (bl->type == BL_CHAT) {
  299. cd = (struct chat_data*)bl;
  300. } else break;
  301. if (cd == NULL)
  302. break;
  303. for(i = 0; i < cd->users; i++) {
  304. if (type == CHAT_WOS && cd->usersd[i] == sd)
  305. continue;
  306. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  307. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  308. {
  309. WFIFOHEAD(fd,len);
  310. memcpy(WFIFOP(fd,0), buf, len);
  311. WFIFOSET(fd,len);
  312. }
  313. }
  314. }
  315. }
  316. break;
  317. case CHAT_MAINCHAT: //[LuzZza]
  318. for(i=1; i<fd_max; i++) {
  319. if (session[i] && session[i]->func_parse == clif_parse &&
  320. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  321. sd->state.mainchat && !sd->chatID && (fd=sd->fd))
  322. {
  323. WFIFOHEAD(fd,len);
  324. memcpy(WFIFOP(fd,0), buf, len);
  325. WFIFOSET(fd, len);
  326. }
  327. }
  328. break;
  329. case PARTY_AREA:
  330. case PARTY_AREA_WOS:
  331. x0 = bl->x - AREA_SIZE;
  332. y0 = bl->y - AREA_SIZE;
  333. x1 = bl->x + AREA_SIZE;
  334. y1 = bl->y + AREA_SIZE;
  335. case PARTY:
  336. case PARTY_WOS:
  337. case PARTY_SAMEMAP:
  338. case PARTY_SAMEMAP_WOS:
  339. if (sd && sd->status.party_id)
  340. p = party_search(sd->status.party_id);
  341. if (p) {
  342. for(i=0;i<MAX_PARTY;i++){
  343. if ((sd = p->data[i].sd) == NULL)
  344. continue;
  345. if (!(fd=sd->fd) || session[fd] == NULL || sd->state.auth == 0
  346. || session[fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  347. continue;
  348. if (sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS))
  349. continue;
  350. if (type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m)
  351. continue;
  352. if ((type == PARTY_AREA || type == PARTY_AREA_WOS) &&
  353. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  354. continue;
  355. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  356. WFIFOHEAD(fd,len);
  357. memcpy(WFIFOP(fd,0), buf, len);
  358. WFIFOSET(fd,len);
  359. }
  360. }
  361. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  362. break;
  363. for (i = 1; i < fd_max; i++){ // partyspy [Syrus22]
  364. if (session[i] && session[i]->func_parse == clif_parse &&
  365. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  366. sd->state.auth && (fd=sd->fd) && sd->partyspy == p->party.party_id)
  367. {
  368. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  369. WFIFOHEAD(fd,len);
  370. memcpy(WFIFOP(fd,0), buf, len);
  371. WFIFOSET(fd,len);
  372. }
  373. }
  374. }
  375. }
  376. break;
  377. case DUEL:
  378. case DUEL_WOS:
  379. if (!sd || !sd->duel_group) break; //Invalid usage.
  380. x0 = sd->duel_group; //Here we use x0 to store the duel group. [Skotlex]
  381. for (i = 0; i < fd_max; i++) {
  382. if (session[i] && session[i]->func_parse == clif_parse &&
  383. (sd = (struct map_session_data *)session[i]->session_data) != NULL &&
  384. sd->state.auth && sd->duel_group == x0) {
  385. if (type == DUEL_WOS && bl->id == sd->bl.id)
  386. continue;
  387. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) {
  388. WFIFOHEAD(i, len);
  389. memcpy(WFIFOP(i,0), buf, len);
  390. WFIFOSET(i,len);
  391. }
  392. }
  393. }
  394. break;
  395. case SELF:
  396. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  397. WFIFOHEAD(fd,len);
  398. memcpy(WFIFOP(fd,0), buf, len);
  399. WFIFOSET(fd,len);
  400. }
  401. break;
  402. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  403. case GUILD_AREA:
  404. case GUILD_AREA_WOS:
  405. x0 = bl->x - AREA_SIZE;
  406. y0 = bl->y - AREA_SIZE;
  407. x1 = bl->x + AREA_SIZE;
  408. y1 = bl->y + AREA_SIZE;
  409. case GUILD_SAMEMAP:
  410. case GUILD_SAMEMAP_WOS:
  411. case GUILD:
  412. case GUILD_WOS:
  413. if (sd && sd->status.guild_id)
  414. g = guild_search(sd->status.guild_id);
  415. if (g) {
  416. for(i = 0; i < g->max_member; i++) {
  417. if ((sd = g->member[i].sd) != NULL) {
  418. if (!(fd=sd->fd) || session[fd] == NULL || sd->state.auth == 0
  419. || session[fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  420. continue;
  421. if (sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS))
  422. continue;
  423. if (type != GUILD && type != GUILD_WOS && sd->bl.m != bl->m)
  424. continue;
  425. if ((type == GUILD_AREA || type == GUILD_AREA_WOS) &&
  426. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  427. continue;
  428. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  429. WFIFOHEAD(fd,len);
  430. memcpy(WFIFOP(fd,0), buf, len);
  431. WFIFOSET(fd,len);
  432. }
  433. }
  434. }
  435. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  436. break;
  437. for (i = 1; i < fd_max; i++){ // guildspy [Syrus22]
  438. if (session[i] && session[i]->func_parse == clif_parse &&
  439. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  440. sd->state.auth && (fd=sd->fd) && sd->guildspy == g->guild_id) {
  441. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  442. WFIFOHEAD(fd,len);
  443. memcpy(WFIFOP(fd,0), buf, len);
  444. WFIFOSET(fd,len);
  445. }
  446. }
  447. }
  448. }
  449. break;
  450. default:
  451. if (battle_config.error_log)
  452. ShowError("clif_send: Unrecognized type %d\n",type);
  453. return -1;
  454. }
  455. return 0;
  456. }
  457. //
  458. // パケット作って送信
  459. //
  460. /*==========================================
  461. *
  462. *------------------------------------------*/
  463. int clif_authok(struct map_session_data *sd)
  464. {
  465. int fd;
  466. if (!sd->fd)
  467. return 0;
  468. fd = sd->fd;
  469. WFIFOHEAD(fd, packet_len(0x73));
  470. WFIFOW(fd, 0) = 0x73;
  471. WFIFOL(fd, 2) = gettick();
  472. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  473. WFIFOB(fd, 9) = 5; // ignored
  474. WFIFOB(fd,10) = 5; // ignored
  475. WFIFOSET(fd,packet_len(0x73));
  476. return 0;
  477. }
  478. /*==========================================
  479. * Authentication failed/disconnect client.
  480. *------------------------------------------
  481. * The client closes it's socket and displays a message according to type:
  482. * 1 - server closed -> MsgStringTable[4]
  483. * 2 - ID already logged in -> MsgStringTable[5]
  484. * 3 - timeout/too much lag -> MsgStringTable[241]
  485. * 4 - server full -> MsgStringTable[264]
  486. * 5 - underaged -> MsgStringTable[305]
  487. * 9 - too many connections from this ip -> MsgStringTable[529]
  488. * 10 - out of available time paid for -> MsgStringTable[530]
  489. * 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  490. * other - disconnected -> MsgStringTable[3]
  491. */
  492. int clif_authfail_fd(int fd, int type)
  493. {
  494. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  495. return 0;
  496. WFIFOHEAD(fd, packet_len(0x81));
  497. WFIFOW(fd,0) = 0x81;
  498. WFIFOB(fd,2) = type;
  499. WFIFOSET(fd,packet_len(0x81));
  500. clif_setwaitclose(fd);
  501. return 0;
  502. }
  503. /*==========================================
  504. * Used to know which is the max valid account/char id [Skotlex]
  505. *------------------------------------------*/
  506. void clif_updatemaxid(int account_id, int char_id)
  507. {
  508. max_account_id = account_id;
  509. max_char_id = char_id;
  510. }
  511. /*==========================================
  512. *
  513. *------------------------------------------*/
  514. int clif_charselectok(int id)
  515. {
  516. struct map_session_data* sd;
  517. int fd;
  518. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  519. return 1;
  520. fd = sd->fd;
  521. WFIFOHEAD(fd,packet_len(0xb3));
  522. WFIFOW(fd,0) = 0xb3;
  523. WFIFOB(fd,2) = 1;
  524. WFIFOSET(fd,packet_len(0xb3));
  525. return 0;
  526. }
  527. /*==========================================
  528. * Makes an item appear on the ground
  529. * 009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  530. *------------------------------------------*/
  531. int clif_dropflooritem(struct flooritem_data* fitem)
  532. {
  533. uint8 buf[17];
  534. int view;
  535. nullpo_retr(0, fitem);
  536. if (fitem->item_data.nameid <= 0)
  537. return 0;
  538. WBUFW(buf, 0) = 0x9e;
  539. WBUFL(buf, 2) = fitem->bl.id;
  540. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  541. WBUFB(buf, 8) = fitem->item_data.identify;
  542. WBUFW(buf, 9) = fitem->bl.x;
  543. WBUFW(buf,11) = fitem->bl.y;
  544. WBUFB(buf,13) = fitem->subx;
  545. WBUFB(buf,14) = fitem->suby;
  546. WBUFW(buf,15) = fitem->item_data.amount;
  547. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  548. return 0;
  549. }
  550. /*==========================================
  551. *
  552. *------------------------------------------*/
  553. int clif_clearflooritem(struct flooritem_data *fitem, int fd)
  554. {
  555. unsigned char buf[16];
  556. nullpo_retr(0, fitem);
  557. WBUFW(buf,0) = 0xa1;
  558. WBUFL(buf,2) = fitem->bl.id;
  559. if (fd == 0) {
  560. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  561. } else {
  562. WFIFOHEAD(fd,packet_len(0xa1));
  563. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  564. WFIFOSET(fd,packet_len(0xa1));
  565. }
  566. return 0;
  567. }
  568. /*==========================================
  569. * make a unit (char, npc, mob, homun) disappear to one client
  570. * id : the id of the unit
  571. * type: 0 - moved out of sight
  572. * 1 - died
  573. * 2 - logged out
  574. * 3 - teleported / winged away
  575. * fd : the target client
  576. *------------------------------------------*/
  577. int clif_clearunit_single(int id, uint8 type, int fd)
  578. {
  579. WFIFOHEAD(fd, packet_len(0x80));
  580. WFIFOW(fd,0) = 0x80;
  581. WFIFOL(fd,2) = id;
  582. WFIFOB(fd,6) = type;
  583. WFIFOSET(fd, packet_len(0x80));
  584. return 0;
  585. }
  586. /*==========================================
  587. * make a unit (char, npc, mob, homun) disappear to all clients in area
  588. * type: 0 - moved out of sight
  589. * 1 - died
  590. * 2 - logged out
  591. * 3 - teleported / winged away
  592. *------------------------------------------*/
  593. int clif_clearunit_area(struct block_list* bl, uint8 type)
  594. {
  595. unsigned char buf[16];
  596. nullpo_retr(0, bl);
  597. WBUFW(buf,0) = 0x80;
  598. WBUFL(buf,2) = bl->id;
  599. WBUFB(buf,6) = type;
  600. clif_send(buf, packet_len(0x80), bl, type == 1 ? AREA : AREA_WOS);
  601. if(disguised(bl)) {
  602. WBUFL(buf,2) = -bl->id;
  603. clif_send(buf, packet_len(0x80), bl, SELF);
  604. }
  605. return 0;
  606. }
  607. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, int data)
  608. {
  609. struct block_list *bl = (struct block_list *)id;
  610. clif_clearunit_area(bl, 0);
  611. aFree(bl);
  612. return 0;
  613. }
  614. int clif_clearunit_delayed(struct block_list* bl, unsigned int tick)
  615. {
  616. struct block_list *tbl;
  617. tbl = aMalloc(sizeof (struct block_list));
  618. memcpy (tbl, bl, sizeof (struct block_list));
  619. add_timer(tick, clif_clearunit_delayed_sub, (int)tbl, 0);
  620. return 0;
  621. }
  622. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  623. {
  624. #if PACKETVER > 3
  625. struct item_data *id;
  626. #endif
  627. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  628. {
  629. *rhand = *lhand = 0;
  630. return;
  631. }
  632. #if PACKETVER < 4
  633. *rhand = sd->status.weapon;
  634. *lhand = sd->status.shield;
  635. #else
  636. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  637. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  638. {
  639. id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  640. if (id->view_id > 0)
  641. *rhand = id->view_id;
  642. else
  643. *rhand = id->nameid;
  644. } else
  645. *rhand = 0;
  646. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  647. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  648. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  649. {
  650. id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  651. if (id->view_id > 0)
  652. *lhand = id->view_id;
  653. else
  654. *lhand = id->nameid;
  655. } else
  656. *lhand = 0;
  657. #endif
  658. }
  659. /*==========================================
  660. *
  661. *------------------------------------------*/
  662. static int clif_set0078(struct block_list* bl, unsigned char* buf)
  663. {
  664. struct status_change* sc;
  665. struct view_data* vd;
  666. int guild_id, emblem_id, dir, lv;
  667. nullpo_retr(0, bl);
  668. sc = status_get_sc(bl);
  669. vd = status_get_viewdata(bl);
  670. guild_id = status_get_guild_id(bl);
  671. emblem_id = status_get_emblem_id(bl);
  672. dir = unit_getdir(bl);
  673. lv = status_get_lv(bl);
  674. if(pcdb_checkid(vd->class_))
  675. {
  676. struct map_session_data* sd;
  677. BL_CAST(BL_PC, bl, sd);
  678. #if PACKETVER >= 7
  679. memset(buf,0,packet_len(0x22a));
  680. WBUFW(buf,0)=0x22a;
  681. WBUFL(buf,2)=bl->id;
  682. WBUFW(buf,6)=status_get_speed(bl);
  683. if (sc) {
  684. WBUFW(buf,8)=sc->opt1;
  685. WBUFW(buf,10)=sc->opt2;
  686. WBUFL(buf,12)=sc->option;
  687. WBUFL(buf,44)=sc->opt3;
  688. }
  689. WBUFW(buf,16)=vd->class_;
  690. WBUFW(buf,18)=vd->hair_style;
  691. WBUFW(buf,20)=vd->weapon;
  692. WBUFW(buf,22)=vd->shield;
  693. WBUFW(buf,24)=vd->head_bottom;
  694. WBUFW(buf,26)=vd->head_top;
  695. WBUFW(buf,28)=vd->head_mid;
  696. WBUFW(buf,30)=vd->hair_color;
  697. WBUFW(buf,32)=vd->cloth_color;
  698. WBUFW(buf,34)=sd?sd->head_dir:0;
  699. WBUFL(buf,36)=guild_id;
  700. WBUFW(buf,40)=emblem_id;
  701. if (sd) {
  702. WBUFW(buf,42)=sd->status.manner;
  703. WBUFB(buf,48)=sd->status.karma;
  704. }
  705. WBUFB(buf,49)=vd->sex;
  706. WBUFPOS(buf,50,bl->x,bl->y,dir);
  707. WBUFB(buf,53)=5;
  708. WBUFB(buf,54)=5;
  709. WBUFB(buf,55)=vd->dead_sit;
  710. WBUFW(buf,56)=clif_setlevel(lv);
  711. return packet_len(0x22a);
  712. #elif PACKETVER > 3
  713. memset(buf,0,packet_len(0x1d8));
  714. WBUFW(buf,0)=0x1d8;
  715. WBUFL(buf,2)=bl->id;
  716. WBUFW(buf,6)=status_get_speed(bl);
  717. if (sc) {
  718. WBUFW(buf,8)=sc->opt1;
  719. WBUFW(buf,10)=sc->opt2;
  720. WBUFW(buf,12)=sc->option;
  721. WBUFW(buf,42)=sc->opt3;
  722. }
  723. WBUFW(buf,14)=vd->class_;
  724. WBUFW(buf,16)=vd->hair_style;
  725. WBUFW(buf,18)=vd->weapon;
  726. WBUFW(buf,20)=vd->shield;
  727. WBUFW(buf,22)=vd->head_bottom;
  728. WBUFW(buf,24)=vd->head_top;
  729. WBUFW(buf,26)=vd->head_mid;
  730. WBUFW(buf,28)=vd->hair_color;
  731. WBUFW(buf,30)=vd->cloth_color;
  732. WBUFW(buf,32)=sd?sd->head_dir:0;
  733. WBUFL(buf,34)=guild_id;
  734. WBUFW(buf,38)=emblem_id;
  735. if (sd) {
  736. WBUFW(buf,40)=sd->status.manner;
  737. WBUFB(buf,44)=sd->status.karma;
  738. }
  739. WBUFB(buf,45)=vd->sex;
  740. WBUFPOS(buf,46,bl->x,bl->y,dir);
  741. WBUFB(buf,49)=5;
  742. WBUFB(buf,50)=5;
  743. WBUFB(buf,51)=vd->dead_sit;
  744. WBUFW(buf,52)=clif_setlevel(lv);
  745. return packet_len(0x1d8);
  746. #else
  747. memset(buf,0,packet_len(0x78));
  748. WBUFW(buf,0)=0x78;
  749. WBUFL(buf,2)=bl->id;
  750. WBUFW(buf,6)=status_get_speed(bl);
  751. if (sc) {
  752. WBUFW(buf,8)=sc->opt1;
  753. WBUFW(buf,10)=sc->opt2;
  754. WBUFW(buf,12)=sc->option;
  755. WBUFW(buf,42)=sc->opt3;
  756. }
  757. WBUFW(buf,14)=vd->class_;
  758. WBUFW(buf,16)=vd->hair_style;
  759. WBUFW(buf,18)=vd->weapon;
  760. WBUFW(buf,20)=vd->head_bottom;
  761. WBUFW(buf,22)=vd->shield;
  762. WBUFW(buf,24)=vd->head_top;
  763. WBUFW(buf,26)=vd->head_mid;
  764. WBUFW(buf,28)=vd->hair_color;
  765. WBUFW(buf,30)=vd->cloth_color;
  766. WBUFW(buf,32)=sd?sd->head_dir:0;
  767. WBUFL(buf,34)=guild_id;
  768. WBUFW(buf,38)=emblem_id;
  769. if (sd) {
  770. WBUFW(buf,40)=sd->status.manner;
  771. WBUFB(buf,44)=sd->status.karma;
  772. }
  773. WBUFB(buf,45)=vd->sex;
  774. WBUFPOS(buf,46,bl->x,bl->y,dir);
  775. WBUFB(buf,49)=5;
  776. WBUFB(buf,50)=5;
  777. WBUFB(buf,51)=vd->dead_sit;
  778. WBUFW(buf,52)=clif_setlevel(lv);
  779. return packet_len(0x78);
  780. #endif
  781. }
  782. //Non-player sprites need just a few fields filled.
  783. memset(buf,0,packet_len(0x78));
  784. WBUFW(buf,0)=0x78;
  785. WBUFL(buf,2)=bl->id;
  786. WBUFW(buf,6)=status_get_speed(bl);
  787. if (sc) {
  788. WBUFW(buf,8)=sc->opt1;
  789. WBUFW(buf,10)=sc->opt2;
  790. WBUFW(buf,12)=sc->option;
  791. WBUFW(buf,42)=sc->opt3;
  792. }
  793. WBUFW(buf,14)=vd->class_;
  794. WBUFW(buf,16)=vd->hair_style; //Required for pets (removes attack cursor)
  795. //18W: Weapon
  796. WBUFW(buf,20)=vd->head_bottom; //Pet armor (ignored by client)
  797. if (bl->type == BL_NPC && vd->class_ == FLAG_CLASS)
  798. { //The hell, why flags work like this?
  799. WBUFL(buf,22)=emblem_id;
  800. WBUFL(buf,26)=guild_id;
  801. }
  802. //22W: shield
  803. //24W: Head top
  804. //26W: Head mid
  805. //28W: Hair color
  806. //30W: Clothes color
  807. //32W: Head dir
  808. WBUFL(buf,34)=guild_id;
  809. WBUFW(buf,38)=emblem_id;
  810. //40W: Manner
  811. //44B: Karma
  812. //45B: Sex
  813. WBUFPOS(buf,46,bl->x,bl->y,dir);
  814. //49B: ???
  815. //50B: ???
  816. //51B: Sit/Stand
  817. WBUFW(buf,52)=clif_setlevel(lv);
  818. return packet_len(0x78);
  819. }
  820. /*==========================================
  821. * Prepares 'unit walking' packet
  822. *------------------------------------------*/
  823. static int clif_set007b(struct block_list *bl, struct view_data *vd, struct unit_data *ud, unsigned char *buf)
  824. {
  825. struct status_change *sc;
  826. int guild_id, emblem_id, lv;
  827. nullpo_retr(0, bl);
  828. sc = status_get_sc(bl);
  829. guild_id = status_get_guild_id(bl);
  830. emblem_id = status_get_emblem_id(bl);
  831. lv = status_get_lv(bl);
  832. if(pcdb_checkid(vd->class_))
  833. {
  834. struct map_session_data* sd;
  835. BL_CAST(BL_PC, bl, sd);
  836. #if PACKETVER >= 7
  837. memset(buf,0,packet_len(0x22c));
  838. WBUFW(buf,0)=0x22c;
  839. WBUFL(buf,2)=bl->id;
  840. WBUFW(buf,6)=status_get_speed(bl);
  841. if (sc) {
  842. WBUFW(buf,8)= sc->opt1;
  843. WBUFW(buf,10)= sc->opt2;
  844. WBUFL(buf,12)= sc->option;
  845. WBUFL(buf,48)= sc->opt3;
  846. }
  847. WBUFW(buf,16)=vd->class_;
  848. WBUFW(buf,18)=vd->hair_style;
  849. WBUFW(buf,20)=vd->weapon;
  850. WBUFW(buf,22)=vd->shield;
  851. WBUFW(buf,24)=vd->head_bottom;
  852. WBUFL(buf,26)=gettick();
  853. WBUFW(buf,30)=vd->head_top;
  854. WBUFW(buf,32)=vd->head_mid;
  855. WBUFW(buf,34)=vd->hair_color;
  856. WBUFW(buf,36)=vd->cloth_color;
  857. WBUFW(buf,38)=sd?sd->head_dir:0;
  858. WBUFL(buf,40)=guild_id;
  859. WBUFW(buf,44)=emblem_id;
  860. if (sd) {
  861. WBUFW(buf,46)=sd->status.manner;
  862. WBUFB(buf,52)=sd->status.karma;
  863. }
  864. WBUFB(buf,53)=vd->sex;
  865. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  866. WBUFB(buf,60)=5;
  867. WBUFB(buf,61)=5;
  868. WBUFW(buf,62)=clif_setlevel(lv);
  869. return packet_len(0x22c);
  870. #elif PACKETVER > 3
  871. memset(buf,0,packet_len(0x1da));
  872. WBUFW(buf,0)=0x1da;
  873. WBUFL(buf,2)=bl->id;
  874. WBUFW(buf,6)=status_get_speed(bl);
  875. if (sc) {
  876. WBUFW(buf,8)=sc->opt1;
  877. WBUFW(buf,10)=sc->opt2;
  878. WBUFW(buf,12)=sc->option;
  879. WBUFW(buf,46)=sc->opt3;
  880. }
  881. WBUFW(buf,14)=vd->class_;
  882. WBUFW(buf,16)=vd->hair_style;
  883. WBUFW(buf,18)=vd->weapon;
  884. WBUFW(buf,20)=vd->shield;
  885. WBUFW(buf,22)=vd->head_bottom;
  886. WBUFL(buf,24)=gettick();
  887. WBUFW(buf,28)=vd->head_top;
  888. WBUFW(buf,30)=vd->head_mid;
  889. WBUFW(buf,32)=vd->hair_color;
  890. WBUFW(buf,34)=vd->cloth_color;
  891. WBUFW(buf,36)=sd?sd->head_dir:0;
  892. WBUFL(buf,38)=guild_id;
  893. WBUFW(buf,42)=emblem_id;
  894. if (sd) {
  895. WBUFW(buf,44)=sd->status.manner;
  896. WBUFB(buf,48)=sd->status.karma;
  897. }
  898. WBUFB(buf,49)=vd->sex;
  899. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  900. WBUFB(buf,56)=5;
  901. WBUFB(buf,57)=5;
  902. WBUFW(buf,58)=clif_setlevel(lv);
  903. return packet_len(0x1da);
  904. #else
  905. memset(buf,0,packet_len(0x7b));
  906. WBUFW(buf,0)=0x7b;
  907. WBUFL(buf,2)=bl->id;
  908. WBUFW(buf,6)=status_get_speed(bl);
  909. if (sc) {
  910. WBUFW(buf,8)=sc->opt1;
  911. WBUFW(buf,10)=sc->opt2;
  912. WBUFW(buf,12)=sc->option;
  913. WBUFW(buf,46)=sc->opt3;
  914. }
  915. WBUFW(buf,14)=vd->class_;
  916. WBUFW(buf,16)=vd->hair_style;
  917. WBUFW(buf,18)=vd->weapon;
  918. WBUFW(buf,20)=vd->head_bottom;
  919. WBUFL(buf,22)=gettick();
  920. WBUFW(buf,26)=vd->shield;
  921. WBUFW(buf,28)=vd->head_top;
  922. WBUFW(buf,30)=vd->head_mid;
  923. WBUFW(buf,32)=vd->hair_color;
  924. WBUFW(buf,34)=vd->cloth_color;
  925. WBUFW(buf,36)=sd?sd->head_dir:0;
  926. WBUFL(buf,38)=guild_id;
  927. WBUFW(buf,42)=emblem_id;
  928. if (sd) {
  929. WBUFW(buf,44)=sd->status.manner;
  930. WBUFB(buf,48)=sd->status.karma;
  931. }
  932. WBUFB(buf,49)=vd->sex;
  933. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  934. WBUFB(buf,56)=5;
  935. WBUFB(buf,57)=5;
  936. WBUFW(buf,58)=clif_setlevel(lv);
  937. return packet_len(0x7b);
  938. #endif
  939. }
  940. //Non-player sprites only require a few fields.
  941. #if PACKETVER >= 7
  942. memset(buf,0,packet_len(0x22c));
  943. WBUFW(buf,0)=0x22c;
  944. WBUFL(buf,2)=bl->id;
  945. WBUFW(buf,6)=status_get_speed(bl);
  946. if (sc) {
  947. WBUFW(buf,8)=sc->opt1;
  948. WBUFW(buf,10)=sc->opt2;
  949. WBUFL(buf,12)=sc->option;
  950. WBUFL(buf,48)=sc->opt3;
  951. }
  952. WBUFW(buf,16)=vd->class_;
  953. WBUFW(buf,18)=vd->hair_style; //Required for pets (removes attack cursor)
  954. //20L: Weapon/Shield
  955. WBUFW(buf,24)=vd->head_bottom; //Pet armor
  956. WBUFL(buf,26)=gettick();
  957. //30W: Head top
  958. //32W: Head mid
  959. //34W: Hair color
  960. //36W: Cloth color
  961. //38W: Head dir
  962. WBUFL(buf,40)=guild_id;
  963. WBUFW(buf,44)=emblem_id;
  964. //46W: Manner
  965. //52B: Karma
  966. //53B: Sex
  967. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  968. //60B: ???
  969. //61B: ???
  970. WBUFW(buf,62)=clif_setlevel(lv);
  971. return packet_len(0x22c);
  972. #else
  973. memset(buf,0,packet_len(0x7b));
  974. WBUFW(buf,0)=0x7b;
  975. WBUFL(buf,2)=bl->id;
  976. WBUFW(buf,6)=status_get_speed(bl);
  977. if (sc) {
  978. WBUFW(buf,8)=sc->opt1;
  979. WBUFW(buf,10)=sc->opt2;
  980. WBUFW(buf,12)=sc->option;
  981. WBUFW(buf,46)=sc->opt3;
  982. }
  983. WBUFW(buf,14)=vd->class_;
  984. WBUFW(buf,16)=vd->hair_style; //Required for pets (removes attack cursor)
  985. //18W: Weapon
  986. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  987. WBUFL(buf,22)=gettick();
  988. //26W: Shield
  989. //28W: Head top
  990. //30W: Head mid
  991. //32W: Hair color
  992. //34W: Cloth color
  993. //36W: Head dir
  994. WBUFL(buf,38)=guild_id;
  995. WBUFW(buf,42)=emblem_id;
  996. //44W: Manner
  997. //46W: Opt3
  998. //48B: Karma
  999. //49B: Sex
  1000. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1001. WBUFB(buf,56)=5;
  1002. WBUFB(buf,57)=5;
  1003. WBUFW(buf,58)=clif_setlevel(lv);
  1004. return packet_len(0x7b);
  1005. #endif
  1006. }
  1007. //Modifies the buffer for disguise characters and sends it to self.
  1008. //Flag = 0: change id to negative, buf will have disguise data.
  1009. //Flag = 1: change id to positive, class and option to make your own char invisible.
  1010. //Luckily, the offsets that need to be changed are the same in packets 0x78, 0x7b, 0x1d8 and 0x1da
  1011. //But no longer holds true for those packet of PACKETVER 7.
  1012. static void clif_setdisguise(struct map_session_data *sd, unsigned char *buf,int len, int flag)
  1013. {
  1014. if (flag) {
  1015. WBUFL(buf,2)=sd->bl.id;
  1016. #if PACKETVER >= 7
  1017. switch (WBUFW(buf,0)) {
  1018. case 0x22c:
  1019. case 0x22b:
  1020. case 0x22a:
  1021. WBUFL(buf,12)=OPTION_INVISIBLE;
  1022. WBUFW(buf,16)=sd->status.class_;
  1023. break;
  1024. default:
  1025. #endif
  1026. WBUFW(buf,12)=OPTION_INVISIBLE;
  1027. WBUFW(buf,14)=sd->status.class_;
  1028. #if PACKETVER >= 7
  1029. break;
  1030. }
  1031. #endif
  1032. } else {
  1033. WBUFL(buf,2)=-sd->bl.id;
  1034. }
  1035. clif_send(buf, len, &sd->bl, SELF);
  1036. }
  1037. /*==========================================
  1038. * クラスチェンジ typeはMobの場合は1で他は0?
  1039. *------------------------------------------*/
  1040. int clif_class_change(struct block_list *bl,int class_,int type)
  1041. {
  1042. unsigned char buf[16];
  1043. nullpo_retr(0, bl);
  1044. if(!pcdb_checkid(class_)) {
  1045. WBUFW(buf,0)=0x1b0;
  1046. WBUFL(buf,2)=bl->id;
  1047. WBUFB(buf,6)=type;
  1048. WBUFL(buf,7)=class_;
  1049. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1050. }
  1051. return 0;
  1052. }
  1053. /*==========================================
  1054. *
  1055. *------------------------------------------*/
  1056. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1057. {
  1058. WFIFOHEAD(fd, packet_len(0x1e1));
  1059. WFIFOW(fd,0)=0x1e1;
  1060. WFIFOL(fd,2)=sd->bl.id;
  1061. WFIFOW(fd,6)=sd->spiritball;
  1062. WFIFOSET(fd, packet_len(0x1e1));
  1063. }
  1064. // new and improved weather display [Valaris]
  1065. static void clif_weather_sub(int fd, int id, int type)
  1066. {
  1067. WFIFOHEAD(fd,packet_len(0x1f3));
  1068. WFIFOW(fd,0) = 0x1f3;
  1069. WFIFOL(fd,2) = id;
  1070. WFIFOL(fd,6) = type;
  1071. WFIFOSET(fd,packet_len(0x1f3));
  1072. }
  1073. /*==========================================
  1074. *
  1075. *------------------------------------------*/
  1076. static void clif_weather_check(struct map_session_data *sd)
  1077. {
  1078. int m = sd->bl.m, fd = sd->fd;
  1079. if (map[m].flag.snow
  1080. || map[m].flag.clouds
  1081. || map[m].flag.fog
  1082. || map[m].flag.fireworks
  1083. || map[m].flag.sakura
  1084. || map[m].flag.leaves
  1085. || map[m].flag.rain
  1086. || map[m].flag.clouds2)
  1087. {
  1088. if (map[m].flag.snow)
  1089. clif_weather_sub(fd, sd->bl.id, 162);
  1090. if (map[m].flag.clouds)
  1091. clif_weather_sub(fd, sd->bl.id, 233);
  1092. if (map[m].flag.clouds2)
  1093. clif_weather_sub(fd, sd->bl.id, 516);
  1094. if (map[m].flag.fog)
  1095. clif_weather_sub(fd, sd->bl.id, 515);
  1096. if (map[m].flag.fireworks) {
  1097. clif_weather_sub(fd, sd->bl.id, 297);
  1098. clif_weather_sub(fd, sd->bl.id, 299);
  1099. clif_weather_sub(fd, sd->bl.id, 301);
  1100. }
  1101. if (map[m].flag.sakura)
  1102. clif_weather_sub(fd, sd->bl.id, 163);
  1103. if (map[m].flag.leaves)
  1104. clif_weather_sub(fd, sd->bl.id, 333);
  1105. if (map[m].flag.rain)
  1106. clif_weather_sub(fd, sd->bl.id, 161);
  1107. }
  1108. }
  1109. int clif_weather(int m)
  1110. {
  1111. int i;
  1112. struct map_session_data *sd=NULL;
  1113. for(i = 0; i < fd_max; i++) {
  1114. if (session[i] && session[i]->func_parse == clif_parse &&
  1115. (sd = session[i]->session_data) != NULL &&
  1116. sd->state.auth && sd->bl.m == m) {
  1117. clif_weather_check(sd);
  1118. }
  1119. }
  1120. return 0;
  1121. }
  1122. int clif_spawn(struct block_list *bl)
  1123. {
  1124. unsigned char buf[128];
  1125. struct view_data *vd;
  1126. nullpo_retr(0, bl);
  1127. vd = status_get_viewdata(bl);
  1128. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1129. return 0;
  1130. if (pcdb_checkid(vd->class_))
  1131. { // player spawn packet
  1132. clif_set0078(bl, buf);
  1133. switch(WBUFW(buf,0))
  1134. {
  1135. case 0x78: //Convert to 0x79
  1136. WBUFW(buf, 0) = 0x79;
  1137. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1138. clif_send(buf, packet_len(0x79), bl, AREA_WOS);
  1139. if (disguised(bl))
  1140. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x79), 0);
  1141. break;
  1142. #if PACKETVER > 3
  1143. case 0x1d8: //Convert to 0x1d9
  1144. WBUFW(buf, 0) = 0x1d9;
  1145. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1146. clif_send(buf, packet_len(0x1d9), bl, AREA_WOS);
  1147. if (disguised(bl))
  1148. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x1d9), 0);
  1149. break;
  1150. #endif
  1151. #if PACKETVER >= 7
  1152. case 0x22a: //Convert to 0x22b
  1153. WBUFW(buf, 0) = 0x22b;
  1154. WBUFW(buf,55) = WBUFW(buf,56); //Lv is placed on offset 56
  1155. clif_send(buf, packet_len(0x22b), bl, AREA_WOS);
  1156. if (disguised(bl))
  1157. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x22b), 0);
  1158. break;
  1159. #endif
  1160. }
  1161. } else { // npc/mob/pet/homun spawn packet
  1162. struct status_change *sc = status_get_sc(bl);
  1163. memset(buf,0,sizeof(buf));
  1164. WBUFW(buf,0)=0x7c;
  1165. WBUFL(buf,2)=bl->id;
  1166. WBUFW(buf,6)=status_get_speed(bl);
  1167. if (sc) {
  1168. WBUFW(buf,8)=sc->opt1;
  1169. WBUFW(buf,10)=sc->opt2;
  1170. WBUFW(buf,12)=sc->option;
  1171. }
  1172. WBUFW(buf,14)=vd->hair_style; //Required for pets (removes attack cursor)
  1173. //16W: Weapon
  1174. WBUFW(buf,18)=vd->head_bottom; //Pet armor (ignored by client)
  1175. WBUFW(buf,20)=vd->class_;
  1176. //22W: Shield
  1177. //24W: Head top
  1178. //26W: Head mid
  1179. //28W: Hair color
  1180. //30W: Cloth color
  1181. //32W: Head dir
  1182. //34B: karma
  1183. //35B: Sex
  1184. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  1185. //39B: ???
  1186. //40B: ???
  1187. clif_send(buf,packet_len(0x7c),bl,AREA_WOS);
  1188. if (disguised(bl)) {
  1189. WBUFL(buf,2)=-bl->id;
  1190. clif_send(buf,packet_len(0x7c),bl,SELF);
  1191. }
  1192. }
  1193. if (vd->cloth_color)
  1194. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1195. switch (bl->type)
  1196. {
  1197. case BL_PC:
  1198. {
  1199. TBL_PC *sd = ((TBL_PC*)bl);
  1200. if (sd->spiritball > 0)
  1201. clif_spiritball(sd);
  1202. if(sd->state.size==2) // tiny/big players [Valaris]
  1203. clif_specialeffect(bl,423,AREA);
  1204. else if(sd->state.size==1)
  1205. clif_specialeffect(bl,421,AREA);
  1206. }
  1207. break;
  1208. case BL_MOB:
  1209. {
  1210. TBL_MOB *md = ((TBL_MOB*)bl);
  1211. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1212. clif_specialeffect(&md->bl,423,AREA);
  1213. else if(md->special_state.size==1)
  1214. clif_specialeffect(&md->bl,421,AREA);
  1215. }
  1216. break;
  1217. case BL_PET:
  1218. if (vd->head_bottom)
  1219. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  1220. break;
  1221. }
  1222. return 0;
  1223. }
  1224. //[orn]
  1225. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1226. {
  1227. struct status_data *status;
  1228. unsigned char buf[128];
  1229. nullpo_retr(0, hd);
  1230. status = &hd->battle_status;
  1231. memset(buf,0,packet_len(0x22e));
  1232. WBUFW(buf,0)=0x22e;
  1233. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1234. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1235. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1236. WBUFW(buf,27)=hd->homunculus.level;
  1237. WBUFW(buf,29)=hd->homunculus.hunger;
  1238. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1239. WBUFW(buf,33)=0; // equip id
  1240. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, SHRT_MAX);
  1241. WBUFW(buf,37)=cap_value(status->matk_max, 0, SHRT_MAX);
  1242. WBUFW(buf,39)=status->hit;
  1243. if (battle_config.hom_setting&0x10)
  1244. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1245. else
  1246. WBUFW(buf,41)=status->cri/10;
  1247. WBUFW(buf,43)=status->def + status->vit ;
  1248. WBUFW(buf,45)=status->mdef;
  1249. WBUFW(buf,47)=status->flee;
  1250. WBUFW(buf,49)=(flag)?0:status->amotion;
  1251. if (status->max_hp > SHRT_MAX) {
  1252. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1253. WBUFW(buf,53) = 100;
  1254. } else {
  1255. WBUFW(buf,51)=status->hp;
  1256. WBUFW(buf,53)=status->max_hp;
  1257. }
  1258. if (status->max_sp > SHRT_MAX) {
  1259. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1260. WBUFW(buf,57) = 100;
  1261. } else {
  1262. WBUFW(buf,55)=status->sp;
  1263. WBUFW(buf,57)=status->max_sp;
  1264. }
  1265. WBUFL(buf,59)=hd->homunculus.exp;
  1266. WBUFL(buf,63)=hd->exp_next;
  1267. WBUFW(buf,67)=hd->homunculus.skillpts;
  1268. WBUFW(buf,69)=1; // FIXME: Attackable? When exactly is a homun not attackable? [Skotlex]
  1269. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1270. return 0;
  1271. }
  1272. void clif_send_homdata(struct map_session_data *sd, int type, int param)
  1273. { //[orn]
  1274. int fd = sd->fd;
  1275. WFIFOHEAD(fd, packet_len(0x230));
  1276. nullpo_retv(sd->hd);
  1277. WFIFOW(fd,0)=0x230;
  1278. WFIFOW(fd,2)=type;
  1279. WFIFOL(fd,4)=sd->hd->bl.id;
  1280. WFIFOL(fd,8)=param;
  1281. WFIFOSET(fd,packet_len(0x230));
  1282. return;
  1283. }
  1284. int clif_homskillinfoblock(struct map_session_data *sd)
  1285. { //[orn]
  1286. struct homun_data *hd;
  1287. int fd = sd->fd;
  1288. int i,j,len=4,id;
  1289. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1290. hd = sd->hd;
  1291. if ( !hd )
  1292. return 0 ;
  1293. WFIFOW(fd,0)=0x235;
  1294. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1295. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1296. j = id - HM_SKILLBASE - 1 ;
  1297. WFIFOW(fd,len ) = id ;
  1298. WFIFOW(fd,len+2) = skill_get_inf(id) ;
  1299. WFIFOW(fd,len+4) = 0 ;
  1300. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv ;
  1301. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv) ;
  1302. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv) ;
  1303. strncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH) ;
  1304. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1305. len+=37;
  1306. }
  1307. }
  1308. WFIFOW(fd,2)=len;
  1309. WFIFOSET(fd,len);
  1310. return 0;
  1311. }
  1312. void clif_homskillup(struct map_session_data *sd, int skill_num)
  1313. { //[orn]
  1314. struct homun_data *hd;
  1315. int fd=sd->fd, skillid;
  1316. WFIFOHEAD(fd, packet_len(0x239));
  1317. nullpo_retv(sd);
  1318. skillid = skill_num - HM_SKILLBASE - 1;
  1319. hd=sd->hd;
  1320. WFIFOW(fd,0) = 0x239;
  1321. WFIFOW(fd,2) = skill_num;
  1322. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1323. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1324. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1325. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1326. WFIFOSET(fd,packet_len(0x239));
  1327. return;
  1328. }
  1329. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1330. {
  1331. int fd=sd->fd;
  1332. WFIFOHEAD(fd,packet_len(0x22f));
  1333. WFIFOW(fd,0)=0x22f;
  1334. WFIFOB(fd,2)=fail;
  1335. WFIFOW(fd,3)=foodid;
  1336. WFIFOSET(fd,packet_len(0x22f));
  1337. return 0;
  1338. }
  1339. /*==========================================
  1340. *
  1341. *------------------------------------------*/
  1342. int clif_walkok(struct map_session_data *sd)
  1343. {
  1344. int fd=sd->fd;
  1345. WFIFOHEAD(fd, packet_len(0x87));
  1346. WFIFOW(fd,0)=0x87;
  1347. WFIFOL(fd,2)=gettick();
  1348. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1349. WFIFOSET(fd,packet_len(0x87));
  1350. return 0;
  1351. }
  1352. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1353. {
  1354. unsigned char buf[256];
  1355. int len;
  1356. len = clif_set007b(bl,vd,ud,buf);
  1357. clif_send(buf,len,bl,AREA_WOS);
  1358. if (disguised(bl))
  1359. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  1360. if(vd->cloth_color)
  1361. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1362. switch(bl->type)
  1363. {
  1364. case BL_PC:
  1365. {
  1366. TBL_PC *sd = ((TBL_PC*)bl);
  1367. // clif_movepc(sd);
  1368. if(sd->state.size==2) // tiny/big players [Valaris]
  1369. clif_specialeffect(&sd->bl,423,AREA);
  1370. else if(sd->state.size==1)
  1371. clif_specialeffect(&sd->bl,421,AREA);
  1372. }
  1373. break;
  1374. case BL_MOB:
  1375. {
  1376. TBL_MOB *md = ((TBL_MOB*)bl);
  1377. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1378. clif_specialeffect(&md->bl,423,AREA);
  1379. else if(md->special_state.size==1)
  1380. clif_specialeffect(&md->bl,421,AREA);
  1381. }
  1382. break;
  1383. }
  1384. return;
  1385. }
  1386. /// Move the unit (does nothing if the client has no info about the unit)
  1387. /// Note: unit must not be self
  1388. void clif_move(struct unit_data *ud)
  1389. {
  1390. unsigned char buf[16];
  1391. struct view_data* vd;
  1392. struct block_list* bl = ud->bl;
  1393. vd = status_get_viewdata(bl);
  1394. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1395. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1396. if (ud->state.speed_changed) {
  1397. // Since we don't know how to update the speed of other objects,
  1398. // use the old walk packet to update the data.
  1399. ud->state.speed_changed = 0;
  1400. clif_move2(bl, vd, ud);
  1401. return;
  1402. }
  1403. WBUFW(buf,0)=0x86;
  1404. WBUFL(buf,2)=bl->id;
  1405. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1406. WBUFL(buf,12)=gettick();
  1407. clif_send(buf, 16, bl, AREA_WOS);
  1408. if (disguised(bl))
  1409. clif_setdisguise((TBL_PC*)bl, buf, 16, 0);
  1410. }
  1411. /*==========================================
  1412. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1413. *------------------------------------------*/
  1414. static int clif_delayquit(int tid, unsigned int tick, int id, int data)
  1415. {
  1416. struct map_session_data *sd = NULL;
  1417. //Remove player from map server
  1418. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1419. map_quit(sd);
  1420. return 0;
  1421. }
  1422. /*==========================================
  1423. *
  1424. *------------------------------------------*/
  1425. void clif_quitsave(int fd,struct map_session_data *sd)
  1426. {
  1427. if (sd->state.waitingdisconnect || //Was already waiting to be disconnected.
  1428. !battle_config.prevent_logout ||
  1429. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1430. map_quit(sd);
  1431. else if (sd->fd)
  1432. { //Disassociate session from player (session is deleted after this function was called)
  1433. //And set a timer to make him quit later.
  1434. session[sd->fd]->session_data = NULL;
  1435. sd->fd = 0;
  1436. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1437. }
  1438. }
  1439. /*==========================================
  1440. *
  1441. *------------------------------------------*/
  1442. static int clif_waitclose(int tid, unsigned int tick, int id, int data)
  1443. {
  1444. if (session[id] && session[id]->func_parse == clif_parse) //Avoid disconnecting non-players, as pointed out by End of Exam [Skotlex]
  1445. set_eof(id);
  1446. return 0;
  1447. }
  1448. /*==========================================
  1449. *
  1450. *------------------------------------------*/
  1451. void clif_setwaitclose(int fd)
  1452. {
  1453. struct map_session_data *sd;
  1454. // if player is not already in the game (double connection probably)
  1455. if ((sd = (struct map_session_data*)session[fd]->session_data) == NULL) {
  1456. // limited timer, just to send information.
  1457. add_timer(gettick() + 1000, clif_waitclose, fd, 0);
  1458. } else
  1459. add_timer(gettick() + 5000, clif_waitclose, fd, 0);
  1460. }
  1461. /*==========================================
  1462. *
  1463. *------------------------------------------*/
  1464. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1465. {
  1466. int fd;
  1467. nullpo_retv(sd);
  1468. fd = sd->fd;
  1469. WFIFOHEAD(fd,packet_len(0x91));
  1470. WFIFOW(fd,0) = 0x91;
  1471. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1472. WFIFOW(fd,18) = x;
  1473. WFIFOW(fd,20) = y;
  1474. WFIFOSET(fd,packet_len(0x91));
  1475. }
  1476. /*==========================================
  1477. * Tells the client to connect to another map-server
  1478. *------------------------------------------*/
  1479. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1480. {
  1481. int fd;
  1482. nullpo_retv(sd);
  1483. fd = sd->fd;
  1484. WFIFOHEAD(fd,packet_len(0x92));
  1485. WFIFOW(fd,0) = 0x92;
  1486. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1487. WFIFOW(fd,18) = x;
  1488. WFIFOW(fd,20) = y;
  1489. WFIFOL(fd,22) = htonl(ip);
  1490. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1491. WFIFOSET(fd,packet_len(0x92));
  1492. }
  1493. int clif_blown(struct block_list *bl)
  1494. {
  1495. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1496. // return clif_fixpos(bl);
  1497. return clif_slide(bl, bl->x, bl->y);
  1498. }
  1499. /*==========================================
  1500. *
  1501. *------------------------------------------*/
  1502. int clif_fixpos(struct block_list *bl)
  1503. {
  1504. unsigned char buf[16];
  1505. nullpo_retr(0, bl);
  1506. WBUFW(buf,0)=0x88;
  1507. WBUFL(buf,2)=bl->id;
  1508. WBUFW(buf,6)=bl->x;
  1509. WBUFW(buf,8)=bl->y;
  1510. clif_send(buf, packet_len(0x88), bl, AREA);
  1511. if (disguised(bl)) {
  1512. WBUFL(buf,2)=-bl->id;
  1513. clif_send(buf, packet_len(0x88), bl, SELF);
  1514. }
  1515. return 0;
  1516. }
  1517. /*==========================================
  1518. *
  1519. *------------------------------------------*/
  1520. int clif_npcbuysell(struct map_session_data* sd, int id)
  1521. {
  1522. int fd;
  1523. nullpo_retr(0, sd);
  1524. fd=sd->fd;
  1525. WFIFOHEAD(fd, packet_len(0xc4));
  1526. WFIFOW(fd,0)=0xc4;
  1527. WFIFOL(fd,2)=id;
  1528. WFIFOSET(fd,packet_len(0xc4));
  1529. return 0;
  1530. }
  1531. /*==========================================
  1532. *
  1533. *------------------------------------------*/
  1534. int clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1535. {
  1536. struct item_data *id;
  1537. int fd,i,val;
  1538. nullpo_retr(0, sd);
  1539. nullpo_retr(0, nd);
  1540. fd=sd->fd;
  1541. WFIFOHEAD(fd, 200 * 11 + 4);
  1542. WFIFOW(fd,0)=0xc6;
  1543. for(i=0;nd->u.shop_item[i].nameid > 0;i++){
  1544. id = itemdb_search(nd->u.shop_item[i].nameid);
  1545. val=nd->u.shop_item[i].value;
  1546. WFIFOL(fd,4+i*11)=val;
  1547. if (!id->flag.value_notdc)
  1548. val=pc_modifybuyvalue(sd,val);
  1549. WFIFOL(fd,8+i*11)=val;
  1550. WFIFOB(fd,12+i*11)=itemtype(id->type);
  1551. if (id->view_id > 0)
  1552. WFIFOW(fd,13+i*11)=id->view_id;
  1553. else
  1554. WFIFOW(fd,13+i*11)=nd->u.shop_item[i].nameid;
  1555. }
  1556. WFIFOW(fd,2)=i*11+4;
  1557. WFIFOSET(fd,WFIFOW(fd,2));
  1558. return 0;
  1559. }
  1560. /*==========================================
  1561. *
  1562. *------------------------------------------*/
  1563. int clif_selllist(struct map_session_data *sd)
  1564. {
  1565. int fd,i,c=0,val;
  1566. nullpo_retr(0, sd);
  1567. fd=sd->fd;
  1568. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1569. WFIFOW(fd,0)=0xc7;
  1570. for(i=0;i<MAX_INVENTORY;i++) {
  1571. if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
  1572. if (!itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)))
  1573. continue;
  1574. val=sd->inventory_data[i]->value_sell;
  1575. if (val < 0)
  1576. continue;
  1577. WFIFOW(fd,4+c*10)=i+2;
  1578. WFIFOL(fd,6+c*10)=val;
  1579. if (!sd->inventory_data[i]->flag.value_notoc)
  1580. val=pc_modifysellvalue(sd,val);
  1581. WFIFOL(fd,10+c*10)=val;
  1582. c++;
  1583. }
  1584. }
  1585. WFIFOW(fd,2)=c*10+4;
  1586. WFIFOSET(fd,WFIFOW(fd,2));
  1587. return 0;
  1588. }
  1589. /*==========================================
  1590. *
  1591. *------------------------------------------*/
  1592. int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1593. {
  1594. int fd = sd->fd;
  1595. int slen = strlen(mes) + 9;
  1596. WFIFOHEAD(fd, slen);
  1597. WFIFOW(fd,0)=0xb4;
  1598. WFIFOW(fd,2)=slen;
  1599. WFIFOL(fd,4)=npcid;
  1600. strcpy((char*)WFIFOP(fd,8),mes);
  1601. WFIFOSET(fd,WFIFOW(fd,2));
  1602. return 0;
  1603. }
  1604. /*==========================================
  1605. *
  1606. *------------------------------------------*/
  1607. int clif_scriptnext(struct map_session_data *sd,int npcid)
  1608. {
  1609. int fd;
  1610. nullpo_retr(0, sd);
  1611. fd=sd->fd;
  1612. WFIFOHEAD(fd, packet_len(0xb5));
  1613. WFIFOW(fd,0)=0xb5;
  1614. WFIFOL(fd,2)=npcid;
  1615. WFIFOSET(fd,packet_len(0xb5));
  1616. return 0;
  1617. }
  1618. /*==========================================
  1619. *
  1620. *------------------------------------------*/
  1621. int clif_scriptclose(struct map_session_data *sd, int npcid)
  1622. {
  1623. int fd;
  1624. nullpo_retr(0, sd);
  1625. fd=sd->fd;
  1626. WFIFOHEAD(fd, packet_len(0xb6));
  1627. WFIFOW(fd,0)=0xb6;
  1628. WFIFOL(fd,2)=npcid;
  1629. WFIFOSET(fd,packet_len(0xb6));
  1630. return 0;
  1631. }
  1632. /*==========================================
  1633. *
  1634. *------------------------------------------*/
  1635. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1636. {
  1637. int fd = sd->fd;
  1638. WFIFOHEAD(fd, packet_len(0x78));
  1639. sd->state.using_fake_npc = 1;
  1640. memset(WFIFOP(fd,0), 0, packet_len(0x78));
  1641. WFIFOW(fd,0)=0x78;
  1642. WFIFOL(fd,2)=npcid;
  1643. WFIFOW(fd,14)=111;
  1644. WFIFOPOS(fd,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1645. WFIFOB(fd,49)=5;
  1646. WFIFOB(fd,50)=5;
  1647. WFIFOSET(fd, packet_len(0x78));
  1648. return;
  1649. }
  1650. /*==========================================
  1651. *
  1652. *------------------------------------------*/
  1653. int clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1654. {
  1655. int fd = sd->fd;
  1656. int slen = strlen(mes) + 8;
  1657. struct block_list *bl = NULL;
  1658. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1659. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1660. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1661. clif_sendfakenpc(sd, npcid);
  1662. WFIFOHEAD(fd, slen);
  1663. WFIFOW(fd,0)=0xb7;
  1664. WFIFOW(fd,2)=slen;
  1665. WFIFOL(fd,4)=npcid;
  1666. strcpy((char*)WFIFOP(fd,8),mes);
  1667. WFIFOSET(fd,WFIFOW(fd,2));
  1668. return 0;
  1669. }
  1670. /*==========================================
  1671. *
  1672. *------------------------------------------*/
  1673. int clif_scriptinput(struct map_session_data *sd, int npcid)
  1674. {
  1675. int fd;
  1676. struct block_list *bl = NULL;
  1677. nullpo_retr(0, sd);
  1678. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1679. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1680. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1681. clif_sendfakenpc(sd, npcid);
  1682. fd=sd->fd;
  1683. WFIFOHEAD(fd, packet_len(0x142));
  1684. WFIFOW(fd,0)=0x142;
  1685. WFIFOL(fd,2)=npcid;
  1686. WFIFOSET(fd,packet_len(0x142));
  1687. return 0;
  1688. }
  1689. /*==========================================
  1690. *
  1691. *------------------------------------------*/
  1692. int clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1693. {
  1694. int fd;
  1695. struct block_list *bl = NULL;
  1696. nullpo_retr(0, sd);
  1697. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1698. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1699. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1700. clif_sendfakenpc(sd, npcid);
  1701. fd=sd->fd;
  1702. WFIFOHEAD(fd, packet_len(0x1d4));
  1703. WFIFOW(fd,0)=0x1d4;
  1704. WFIFOL(fd,2)=npcid;
  1705. WFIFOSET(fd,packet_len(0x1d4));
  1706. return 0;
  1707. }
  1708. /// npc_id is ignored in the client
  1709. /// type=2 : Remove viewpoint
  1710. /// type=other : Show viewpoint
  1711. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1712. {
  1713. int fd;
  1714. nullpo_retr(0, sd);
  1715. fd=sd->fd;
  1716. WFIFOHEAD(fd, packet_len(0x144));
  1717. WFIFOW(fd,0)=0x144;
  1718. WFIFOL(fd,2)=npc_id;
  1719. WFIFOL(fd,6)=type;
  1720. WFIFOL(fd,10)=x;
  1721. WFIFOL(fd,14)=y;
  1722. WFIFOB(fd,18)=id;
  1723. WFIFOL(fd,19)=color;
  1724. WFIFOSET(fd,packet_len(0x144));
  1725. return 0;
  1726. }
  1727. /*==========================================
  1728. *
  1729. *------------------------------------------*/
  1730. int clif_cutin(struct map_session_data* sd, const char* image, int type)
  1731. {
  1732. int fd;
  1733. nullpo_retr(0, sd);
  1734. fd=sd->fd;
  1735. WFIFOHEAD(fd, packet_len(0x1b3));
  1736. WFIFOW(fd,0)=0x1b3;
  1737. strncpy((char*)WFIFOP(fd,2),image,64);
  1738. WFIFOB(fd,66)=type;
  1739. WFIFOSET(fd,packet_len(0x1b3));
  1740. return 0;
  1741. }
  1742. /*==========================================
  1743. * Fills in card data from the given item and into the buffer. [Skotlex]
  1744. *------------------------------------------*/
  1745. static void clif_addcards(unsigned char* buf, struct item* item)
  1746. {
  1747. int i=0,j;
  1748. if( item == NULL ) { //Blank data
  1749. WBUFW(buf,0) = 0;
  1750. WBUFW(buf,2) = 0;
  1751. WBUFW(buf,4) = 0;
  1752. WBUFW(buf,6) = 0;
  1753. return;
  1754. }
  1755. if( item->card[0] == CARD0_PET ) { //pet eggs
  1756. WBUFW(buf,0) = 0;
  1757. WBUFW(buf,2) = 0;
  1758. WBUFW(buf,4) = 0;
  1759. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1760. return;
  1761. }
  1762. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1763. WBUFW(buf,0) = item->card[0];
  1764. WBUFW(buf,2) = item->card[1];
  1765. WBUFW(buf,4) = item->card[2];
  1766. WBUFW(buf,6) = item->card[3];
  1767. return;
  1768. }
  1769. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1770. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1771. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1772. //Normal items.
  1773. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1774. WBUFW(buf,0) = j;
  1775. else
  1776. WBUFW(buf,0) = item->card[i];
  1777. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1778. WBUFW(buf,2) = j;
  1779. else
  1780. WBUFW(buf,2) = item->card[i];
  1781. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1782. WBUFW(buf,4) = j;
  1783. else
  1784. WBUFW(buf,4) = item->card[i];
  1785. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1786. WBUFW(buf,6) = j;
  1787. else
  1788. WBUFW(buf,6) = item->card[i];
  1789. }
  1790. /*==========================================
  1791. *
  1792. *------------------------------------------*/
  1793. int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1794. {
  1795. int fd;
  1796. nullpo_retr(0, sd);
  1797. fd = sd->fd;
  1798. if (!session_isActive(fd)) //Sasuke-
  1799. return 0;
  1800. WFIFOHEAD(fd,packet_len(0xa0));
  1801. if(fail) {
  1802. WFIFOW(fd,0)=0xa0;
  1803. WFIFOW(fd,2)=n+2;
  1804. WFIFOW(fd,4)=amount;
  1805. WFIFOW(fd,6)=0;
  1806. WFIFOB(fd,8)=0;
  1807. WFIFOB(fd,9)=0;
  1808. WFIFOB(fd,10)=0;
  1809. WFIFOW(fd,11)=0;
  1810. WFIFOW(fd,13)=0;
  1811. WFIFOW(fd,15)=0;
  1812. WFIFOW(fd,17)=0;
  1813. WFIFOW(fd,19)=0;
  1814. WFIFOB(fd,21)=0;
  1815. WFIFOB(fd,22)=fail;
  1816. } else {
  1817. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1818. return 1;
  1819. WFIFOW(fd,0)=0xa0;
  1820. WFIFOW(fd,2)=n+2;
  1821. WFIFOW(fd,4)=amount;
  1822. if (sd->inventory_data[n]->view_id > 0)
  1823. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1824. else
  1825. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1826. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1827. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1828. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1829. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1830. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1831. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1832. WFIFOB(fd,22)=fail;
  1833. }
  1834. WFIFOSET(fd,packet_len(0xa0));
  1835. return 0;
  1836. }
  1837. /*==========================================
  1838. *
  1839. *------------------------------------------*/
  1840. int clif_delitem(struct map_session_data *sd,int n,int amount)
  1841. {
  1842. int fd;
  1843. nullpo_retr(0, sd);
  1844. fd=sd->fd;
  1845. WFIFOHEAD(fd, packet_len(0xaf));
  1846. WFIFOW(fd,0)=0xaf;
  1847. WFIFOW(fd,2)=n+2;
  1848. WFIFOW(fd,4)=amount;
  1849. WFIFOSET(fd,packet_len(0xaf));
  1850. return 0;
  1851. }
  1852. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1853. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1854. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1855. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1856. {
  1857. if (id->view_id > 0)
  1858. WBUFW(buf,n)=id->view_id;
  1859. else
  1860. WBUFW(buf,n)=i->nameid;
  1861. WBUFB(buf,n+2)=itemtype(id->type);
  1862. WBUFB(buf,n+3)=i->identify;
  1863. if (equip >= 0) { //Equippable item
  1864. WBUFW(buf,n+4)=equip;
  1865. WBUFW(buf,n+6)=i->equip;
  1866. WBUFB(buf,n+8)=i->attribute;
  1867. WBUFB(buf,n+9)=i->refine;
  1868. } else { //Stackable item.
  1869. WBUFW(buf,n+4)=i->amount;
  1870. if (equip == -2 && id->equip == EQP_AMMO)
  1871. WBUFW(buf,n+6)=EQP_AMMO;
  1872. else
  1873. WBUFW(buf,n+6)=0;
  1874. }
  1875. }
  1876. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1877. void clif_inventorylist(struct map_session_data *sd)
  1878. {
  1879. int i,n,ne,fd = sd->fd,arrow=-1;
  1880. unsigned char *buf;
  1881. unsigned char bufe[MAX_INVENTORY*20+4];
  1882. #if PACKETVER < 5
  1883. const int s = 10; //Entry size.
  1884. #else
  1885. const int s = 18;
  1886. #endif
  1887. WFIFOHEAD(fd, MAX_INVENTORY * s + 4);
  1888. buf = WFIFOP(fd,0);
  1889. for(i=0,n=0,ne=0;i<MAX_INVENTORY;i++){
  1890. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1891. continue;
  1892. if(!itemdb_isstackable2(sd->inventory_data[i]))
  1893. { //Non-stackable (Equippable)
  1894. WBUFW(bufe,ne*20+4)=i+2;
  1895. clif_item_sub(bufe, ne*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1896. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.inventory[i]);
  1897. ne++;
  1898. } else { //Stackable.
  1899. WBUFW(buf,n*s+4)=i+2;
  1900. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1901. if (sd->inventory_data[i]->equip == EQP_AMMO &&
  1902. sd->status.inventory[i].equip)
  1903. arrow=i;
  1904. #if PACKETVER >= 5
  1905. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1906. #endif
  1907. n++;
  1908. }
  1909. }
  1910. if (n) {
  1911. #if PACKETVER < 5
  1912. WBUFW(buf,0)=0xa3;
  1913. #else
  1914. WBUFW(buf,0)=0x1ee;
  1915. #endif
  1916. WBUFW(buf,2)=4+n*s;
  1917. WFIFOSET(fd,WFIFOW(fd,2));
  1918. }
  1919. if(arrow >= 0)
  1920. clif_arrowequip(sd,arrow);
  1921. if(ne){
  1922. WBUFW(bufe,0)=0xa4;
  1923. WBUFW(bufe,2)=4+ne*20;
  1924. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1925. }
  1926. }
  1927. //Required when items break/get-repaired. Only sends equippable item list.
  1928. void clif_equiplist(struct map_session_data *sd)
  1929. {
  1930. int i,n,fd = sd->fd;
  1931. unsigned char *buf;
  1932. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  1933. buf = WFIFOP(fd,0);
  1934. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1935. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1936. continue;
  1937. if(itemdb_isstackable2(sd->inventory_data[i]))
  1938. continue;
  1939. //Equippable
  1940. WBUFW(buf,n*20+4)=i+2;
  1941. clif_item_sub(buf, n*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1942. clif_addcards(WBUFP(buf, n*20+16), &sd->status.inventory[i]);
  1943. n++;
  1944. }
  1945. if (n) {
  1946. WBUFW(buf,0)=0xa4;
  1947. WBUFW(buf,2)=4+n*20;
  1948. WFIFOSET(fd,WFIFOW(fd,2));
  1949. }
  1950. }
  1951. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1952. void clif_storagelist(struct map_session_data *sd,struct storage *stor)
  1953. {
  1954. struct item_data *id;
  1955. int i,n,ne,fd=sd->fd;
  1956. unsigned char *buf;
  1957. unsigned char bufe[MAX_STORAGE*20+4];
  1958. #if PACKETVER < 5
  1959. const int s = 10; //Entry size.
  1960. #else
  1961. const int s = 18;
  1962. #endif
  1963. WFIFOHEAD(fd,MAX_STORAGE * s + 4);
  1964. buf = WFIFOP(fd,0);
  1965. for(i=0,n=0,ne=0;i<MAX_STORAGE;i++){
  1966. if(stor->storage_[i].nameid<=0)
  1967. continue;
  1968. id = itemdb_search(stor->storage_[i].nameid);
  1969. if(!itemdb_isstackable2(id))
  1970. { //Equippable
  1971. WBUFW(bufe,ne*20+4)=i+1;
  1972. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  1973. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  1974. ne++;
  1975. } else { //Stackable
  1976. WBUFW(buf,n*s+4)=i+1;
  1977. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  1978. #if PACKETVER >= 5
  1979. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  1980. #endif
  1981. n++;
  1982. }
  1983. }
  1984. if(n){
  1985. #if PACKETVER < 5
  1986. WBUFW(buf,0)=0xa5;
  1987. #else
  1988. WBUFW(buf,0)=0x1f0;
  1989. #endif
  1990. WBUFW(buf,2)=4+n*s;
  1991. WFIFOSET(fd,WFIFOW(fd,2));
  1992. }
  1993. if(ne){
  1994. WBUFW(bufe,0)=0xa6;
  1995. WBUFW(bufe,2)=4+ne*20;
  1996. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1997. }
  1998. }
  1999. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  2000. void clif_guildstoragelist(struct map_session_data *sd,struct guild_storage *stor)
  2001. {
  2002. struct item_data *id;
  2003. int i,n,ne,fd=sd->fd;
  2004. unsigned char *buf;
  2005. unsigned char bufe[MAX_GUILD_STORAGE*20+4];
  2006. #if PACKETVER < 5
  2007. const int s = 10; //Entry size.
  2008. #else
  2009. const int s = 18;
  2010. #endif
  2011. WFIFOHEAD(fd,MAX_GUILD_STORAGE * s + 4);
  2012. buf = WFIFOP(fd,0);
  2013. for(i=0,n=0,ne=0;i<MAX_GUILD_STORAGE;i++){
  2014. if(stor->storage_[i].nameid<=0)
  2015. continue;
  2016. id = itemdb_search(stor->storage_[i].nameid);
  2017. if(!itemdb_isstackable2(id))
  2018. { //Equippable
  2019. WBUFW(bufe,ne*20+4)=i+1;
  2020. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  2021. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  2022. ne++;
  2023. } else { //Stackable
  2024. WBUFW(buf,n*s+4)=i+1;
  2025. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  2026. #if PACKETVER >= 5
  2027. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  2028. #endif
  2029. n++;
  2030. }
  2031. }
  2032. if(n){
  2033. #if PACKETVER < 5
  2034. WBUFW(buf,0)=0xa5;
  2035. #else
  2036. WBUFW(buf,0)=0x1f0;
  2037. #endif
  2038. WBUFW(buf,2)=4+n*s;
  2039. WFIFOSET(fd,WFIFOW(fd,2));
  2040. }
  2041. if(ne){
  2042. WBUFW(bufe,0)=0xa6;
  2043. WBUFW(bufe,2)=4+ne*20;
  2044. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2045. }
  2046. }
  2047. void clif_cartlist(struct map_session_data *sd)
  2048. {
  2049. struct item_data *id;
  2050. int i,n,ne,fd=sd->fd;
  2051. unsigned char *buf;
  2052. unsigned char bufe[MAX_CART*20+4];
  2053. #if PACKETVER < 5
  2054. const int s = 10; //Entry size.
  2055. #else
  2056. const int s = 18;
  2057. #endif
  2058. WFIFOHEAD(fd, MAX_CART * s + 4);
  2059. buf = WFIFOP(fd,0);
  2060. for(i=0,n=0,ne=0;i<MAX_CART;i++){
  2061. if(sd->status.cart[i].nameid<=0)
  2062. continue;
  2063. id = itemdb_search(sd->status.cart[i].nameid);
  2064. if(!itemdb_isstackable2(id))
  2065. { //Equippable
  2066. WBUFW(bufe,ne*20+4)=i+2;
  2067. clif_item_sub(bufe, ne*20+6, &sd->status.cart[i], id, id->equip);
  2068. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.cart[i]);
  2069. ne++;
  2070. } else { //Stackable
  2071. WBUFW(buf,n*s+4)=i+2;
  2072. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  2073. #if PACKETVER >= 5
  2074. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  2075. #endif
  2076. n++;
  2077. }
  2078. }
  2079. if(n){
  2080. #if PACKETVER < 5
  2081. WBUFW(buf,0)=0x123;
  2082. #else
  2083. WBUFW(buf,0)=0x1ef;
  2084. #endif
  2085. WBUFW(buf,2)=4+n*s;
  2086. WFIFOSET(fd,WFIFOW(fd,2));
  2087. }
  2088. if(ne){
  2089. WBUFW(bufe,0)=0x122;
  2090. WBUFW(bufe,2)=4+ne*20;
  2091. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2092. }
  2093. return;
  2094. }
  2095. /// Client behaviour:
  2096. /// Closes the cart storage and removes all it's items from memory.
  2097. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2098. void clif_clearcart(int fd)
  2099. {
  2100. WFIFOHEAD(fd, packet_len(0x12b));
  2101. WFIFOW(fd,0) = 0x12b;
  2102. }
  2103. // Guild XY locators [Valaris]
  2104. int clif_guild_xy(struct map_session_data *sd)
  2105. {
  2106. unsigned char buf[10];
  2107. nullpo_retr(0, sd);
  2108. WBUFW(buf,0)=0x1eb;
  2109. WBUFL(buf,2)=sd->status.account_id;
  2110. WBUFW(buf,6)=sd->bl.x;
  2111. WBUFW(buf,8)=sd->bl.y;
  2112. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2113. return 0;
  2114. }
  2115. /*==========================================
  2116. * Sends x/y dot to a single fd. [Skotlex]
  2117. *------------------------------------------*/
  2118. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  2119. {
  2120. WFIFOHEAD(fd,packet_len(0x1eb));
  2121. WFIFOW(fd,0)=0x1eb;
  2122. WFIFOL(fd,2)=sd->status.account_id;
  2123. WFIFOW(fd,6)=sd->bl.x;
  2124. WFIFOW(fd,8)=sd->bl.y;
  2125. WFIFOSET(fd,packet_len(0x1eb));
  2126. return 0;
  2127. }
  2128. // Guild XY locators [Valaris]
  2129. int clif_guild_xy_remove(struct map_session_data *sd)
  2130. {
  2131. unsigned char buf[10];
  2132. nullpo_retr(0, sd);
  2133. WBUFW(buf,0)=0x1eb;
  2134. WBUFL(buf,2)=sd->status.account_id;
  2135. WBUFW(buf,6)=-1;
  2136. WBUFW(buf,8)=-1;
  2137. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2138. return 0;
  2139. }
  2140. /*==========================================
  2141. * ステータスを送りつける
  2142. * 表示専用数字はこの中で計算して送る
  2143. *------------------------------------------*/
  2144. int clif_updatestatus(struct map_session_data *sd,int type)
  2145. {
  2146. int fd,len=8;
  2147. nullpo_retr(0, sd);
  2148. fd=sd->fd;
  2149. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2150. return 0;
  2151. WFIFOHEAD(fd, 14);
  2152. WFIFOW(fd,0)=0xb0;
  2153. WFIFOW(fd,2)=type;
  2154. switch(type){
  2155. // 00b0
  2156. case SP_WEIGHT:
  2157. pc_updateweightstatus(sd);
  2158. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2159. WFIFOW(fd,2)=type;
  2160. WFIFOL(fd,4)=sd->weight;
  2161. break;
  2162. case SP_MAXWEIGHT:
  2163. WFIFOL(fd,4)=sd->max_weight;
  2164. break;
  2165. case SP_SPEED:
  2166. WFIFOL(fd,4)=sd->battle_status.speed;
  2167. break;
  2168. case SP_BASELEVEL:
  2169. WFIFOL(fd,4)=sd->status.base_level;
  2170. break;
  2171. case SP_JOBLEVEL:
  2172. WFIFOL(fd,4)=sd->status.job_level;
  2173. break;
  2174. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2175. WFIFOL(fd,4)=sd->status.karma;
  2176. break;
  2177. case SP_MANNER:
  2178. WFIFOL(fd,4)=sd->status.manner;
  2179. clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
  2180. break;
  2181. case SP_STATUSPOINT:
  2182. WFIFOL(fd,4)=sd->status.status_point;
  2183. break;
  2184. case SP_SKILLPOINT:
  2185. WFIFOL(fd,4)=sd->status.skill_point;
  2186. break;
  2187. case SP_HIT:
  2188. WFIFOL(fd,4)=sd->battle_status.hit;
  2189. break;
  2190. case SP_FLEE1:
  2191. WFIFOL(fd,4)=sd->battle_status.flee;
  2192. break;
  2193. case SP_FLEE2:
  2194. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2195. break;
  2196. case SP_MAXHP:
  2197. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2198. break;
  2199. case SP_MAXSP:
  2200. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2201. break;
  2202. case SP_HP:
  2203. WFIFOL(fd,4)=sd->battle_status.hp;
  2204. if (battle_config.disp_hpmeter)
  2205. clif_hpmeter(sd);
  2206. if (!battle_config.party_hp_mode && sd->status.party_id)
  2207. clif_party_hp(sd);
  2208. break;
  2209. case SP_SP:
  2210. WFIFOL(fd,4)=sd->battle_status.sp;
  2211. break;
  2212. case SP_ASPD:
  2213. WFIFOL(fd,4)=sd->battle_status.amotion;
  2214. break;
  2215. case SP_ATK1:
  2216. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw->atk;
  2217. break;
  2218. case SP_DEF1:
  2219. WFIFOL(fd,4)=sd->battle_status.def;
  2220. break;
  2221. case SP_MDEF1:
  2222. WFIFOL(fd,4)=sd->battle_status.mdef;
  2223. break;
  2224. case SP_ATK2:
  2225. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw->atk2;
  2226. break;
  2227. case SP_DEF2:
  2228. WFIFOL(fd,4)=sd->battle_status.def2;
  2229. break;
  2230. case SP_MDEF2:
  2231. //negative check (in case you have something like Berserk active)
  2232. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2233. if (len < 0) len = 0;
  2234. WFIFOL(fd,4)= len;
  2235. len = 8;
  2236. break;
  2237. case SP_CRITICAL:
  2238. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2239. break;
  2240. case SP_MATK1:
  2241. WFIFOL(fd,4)=sd->battle_status.matk_max;
  2242. break;
  2243. case SP_MATK2:
  2244. WFIFOL(fd,4)=sd->battle_status.matk_min;
  2245. break;
  2246. case SP_ZENY:
  2247. WFIFOW(fd,0)=0xb1;
  2248. WFIFOL(fd,4)=sd->status.zeny;
  2249. break;
  2250. case SP_BASEEXP:
  2251. WFIFOW(fd,0)=0xb1;
  2252. WFIFOL(fd,4)=sd->status.base_exp;
  2253. break;
  2254. case SP_JOBEXP:
  2255. WFIFOW(fd,0)=0xb1;
  2256. WFIFOL(fd,4)=sd->status.job_exp;
  2257. break;
  2258. case SP_NEXTBASEEXP:
  2259. WFIFOW(fd,0)=0xb1;
  2260. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2261. break;
  2262. case SP_NEXTJOBEXP:
  2263. WFIFOW(fd,0)=0xb1;
  2264. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2265. break;
  2266. // 00be 終了
  2267. case SP_USTR:
  2268. case SP_UAGI:
  2269. case SP_UVIT:
  2270. case SP_UINT:
  2271. case SP_UDEX:
  2272. case SP_ULUK:
  2273. WFIFOW(fd,0)=0xbe;
  2274. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2275. len=5;
  2276. break;
  2277. // 013a 終了
  2278. case SP_ATTACKRANGE:
  2279. WFIFOW(fd,0)=0x13a;
  2280. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2281. len=4;
  2282. break;
  2283. // 0141 終了
  2284. case SP_STR:
  2285. WFIFOW(fd,0)=0x141;
  2286. WFIFOL(fd,2)=type;
  2287. WFIFOL(fd,6)=sd->status.str;
  2288. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2289. len=14;
  2290. break;
  2291. case SP_AGI:
  2292. WFIFOW(fd,0)=0x141;
  2293. WFIFOL(fd,2)=type;
  2294. WFIFOL(fd,6)=sd->status.agi;
  2295. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2296. len=14;
  2297. break;
  2298. case SP_VIT:
  2299. WFIFOW(fd,0)=0x141;
  2300. WFIFOL(fd,2)=type;
  2301. WFIFOL(fd,6)=sd->status.vit;
  2302. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2303. len=14;
  2304. break;
  2305. case SP_INT:
  2306. WFIFOW(fd,0)=0x141;
  2307. WFIFOL(fd,2)=type;
  2308. WFIFOL(fd,6)=sd->status.int_;
  2309. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2310. len=14;
  2311. break;
  2312. case SP_DEX:
  2313. WFIFOW(fd,0)=0x141;
  2314. WFIFOL(fd,2)=type;
  2315. WFIFOL(fd,6)=sd->status.dex;
  2316. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2317. len=14;
  2318. break;
  2319. case SP_LUK:
  2320. WFIFOW(fd,0)=0x141;
  2321. WFIFOL(fd,2)=type;
  2322. WFIFOL(fd,6)=sd->status.luk;
  2323. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2324. len=14;
  2325. break;
  2326. case SP_CARTINFO:
  2327. WFIFOW(fd,0)=0x121;
  2328. WFIFOW(fd,2)=sd->cart_num;
  2329. WFIFOW(fd,4)=MAX_CART;
  2330. WFIFOL(fd,6)=sd->cart_weight;
  2331. WFIFOL(fd,10)=battle_config.max_cart_weight;
  2332. len=14;
  2333. break;
  2334. default:
  2335. if(battle_config.error_log)
  2336. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2337. return 1;
  2338. }
  2339. WFIFOSET(fd,len);
  2340. return 0;
  2341. }
  2342. int clif_changestatus(struct block_list *bl,int type,int val)
  2343. {
  2344. unsigned char buf[12];
  2345. struct map_session_data *sd = NULL;
  2346. nullpo_retr(0, bl);
  2347. if(bl->type == BL_PC)
  2348. sd = (struct map_session_data *)bl;
  2349. if(sd){
  2350. WBUFW(buf,0)=0x1ab;
  2351. WBUFL(buf,2)=bl->id;
  2352. WBUFW(buf,6)=type;
  2353. switch(type){
  2354. case SP_MANNER:
  2355. WBUFL(buf,8)=val;
  2356. break;
  2357. default:
  2358. if(battle_config.error_log)
  2359. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2360. return 1;
  2361. }
  2362. clif_send(buf,packet_len(0x1ab),bl,AREA_WOS);
  2363. }
  2364. return 0;
  2365. }
  2366. /*==========================================
  2367. *
  2368. *------------------------------------------*/
  2369. int clif_changelook(struct block_list *bl,int type,int val)
  2370. {
  2371. unsigned char buf[32];
  2372. struct map_session_data *sd = NULL;
  2373. struct view_data *vd;
  2374. vd = status_get_viewdata(bl);
  2375. nullpo_retr(0, vd);
  2376. BL_CAST(BL_PC, bl, sd);
  2377. switch(type) {
  2378. case LOOK_WEAPON:
  2379. if (sd)
  2380. {
  2381. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2382. val = vd->weapon;
  2383. }
  2384. else vd->weapon = val;
  2385. break;
  2386. case LOOK_SHIELD:
  2387. if (sd)
  2388. {
  2389. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2390. val = vd->shield;
  2391. }
  2392. else vd->shield = val;
  2393. break;
  2394. case LOOK_BASE:
  2395. vd->class_ = val;
  2396. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2397. vd->weapon = vd->shield = 0;
  2398. if (vd->cloth_color && (
  2399. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2400. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2401. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2402. ))
  2403. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2404. break;
  2405. case LOOK_HAIR:
  2406. vd->hair_style = val;
  2407. break;
  2408. case LOOK_HEAD_BOTTOM:
  2409. vd->head_bottom = val;
  2410. break;
  2411. case LOOK_HEAD_TOP:
  2412. vd->head_top = val;
  2413. break;
  2414. case LOOK_HEAD_MID:
  2415. vd->head_mid = val;
  2416. break;
  2417. case LOOK_HAIR_COLOR:
  2418. vd->hair_color = val;
  2419. break;
  2420. case LOOK_CLOTHES_COLOR:
  2421. if (val && (
  2422. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2423. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2424. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2425. ))
  2426. val = 0;
  2427. vd->cloth_color = val;
  2428. break;
  2429. case LOOK_SHOES:
  2430. #if PACKETVER > 3
  2431. if (sd) {
  2432. int n;
  2433. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2434. if(sd->inventory_data[n]->view_id > 0)
  2435. val = sd->inventory_data[n]->view_id;
  2436. else
  2437. val = sd->status.inventory[n].nameid;
  2438. }
  2439. val = 0;
  2440. }
  2441. #endif
  2442. //Shoes? No packet uses this....
  2443. break;
  2444. }
  2445. #if PACKETVER < 4
  2446. WBUFW(buf,0)=0xc3;
  2447. WBUFL(buf,2)=bl->id;
  2448. WBUFB(buf,6)=type;
  2449. WBUFB(buf,7)=val;
  2450. clif_send(buf,packet_len(0xc3),bl,AREA);
  2451. #else
  2452. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2453. WBUFW(buf,0)=0x1d7;
  2454. WBUFL(buf,2)=bl->id;
  2455. WBUFB(buf,6)=LOOK_WEAPON;
  2456. WBUFW(buf,7)=vd->weapon;
  2457. WBUFW(buf,9)=vd->shield;
  2458. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2459. }
  2460. else
  2461. {
  2462. WBUFW(buf,0)=0x1d7;
  2463. WBUFL(buf,2)=bl->id;
  2464. WBUFB(buf,6)=type;
  2465. WBUFW(buf,7)=val;
  2466. WBUFW(buf,9)=0;
  2467. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2468. }
  2469. #endif
  2470. return 0;
  2471. }
  2472. //Sends a change-base-look packet required for traps as they are triggered.
  2473. void clif_changetraplook(struct block_list *bl,int val)
  2474. {
  2475. unsigned char buf[32];
  2476. #if PACKETVER < 4
  2477. WBUFW(buf,0)=0xc3;
  2478. WBUFL(buf,2)=bl->id;
  2479. WBUFB(buf,6)=LOOK_BASE;
  2480. WBUFB(buf,7)=val;
  2481. clif_send(buf,packet_len(0xc3),bl,AREA);
  2482. #else
  2483. WBUFW(buf,0)=0x1d7;
  2484. WBUFL(buf,2)=bl->id;
  2485. WBUFB(buf,6)=LOOK_BASE;
  2486. WBUFW(buf,7)=val;
  2487. WBUFW(buf,9)=0;
  2488. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2489. #endif
  2490. }
  2491. //For the stupid cloth-dye bug. Resends the given view data
  2492. //to the area specified by bl.
  2493. void clif_refreshlook(struct block_list *bl,int id,int type,int val,int area)
  2494. {
  2495. unsigned char buf[32];
  2496. #if PACKETVER < 4
  2497. WBUFW(buf,0)=0xc3;
  2498. WBUFL(buf,2)=id;
  2499. WBUFB(buf,6)=type;
  2500. WBUFB(buf,7)=val;
  2501. clif_send(buf,packet_len(0xc3),bl,area);
  2502. #else
  2503. WBUFW(buf,0)=0x1d7;
  2504. WBUFL(buf,2)=id;
  2505. WBUFB(buf,6)=type;
  2506. WBUFW(buf,7)=val;
  2507. WBUFW(buf,9)=0;
  2508. clif_send(buf,packet_len(0x1d7),bl,area);
  2509. #endif
  2510. return;
  2511. }
  2512. /*==========================================
  2513. *
  2514. *------------------------------------------*/
  2515. int clif_initialstatus(struct map_session_data *sd)
  2516. {
  2517. int fd;
  2518. unsigned char *buf;
  2519. nullpo_retr(0, sd);
  2520. fd=sd->fd;
  2521. WFIFOHEAD(fd,packet_len(0xbd));
  2522. buf=WFIFOP(fd,0);
  2523. WBUFW(buf,0)=0xbd;
  2524. WBUFW(buf,2)=min(sd->status.status_point, SHRT_MAX);
  2525. WBUFB(buf,4)=min(sd->status.str, UCHAR_MAX);
  2526. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2527. WBUFB(buf,6)=min(sd->status.agi, UCHAR_MAX);
  2528. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2529. WBUFB(buf,8)=min(sd->status.vit, UCHAR_MAX);
  2530. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2531. WBUFB(buf,10)=min(sd->status.int_, UCHAR_MAX);
  2532. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2533. WBUFB(buf,12)=min(sd->status.dex, UCHAR_MAX);
  2534. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2535. WBUFB(buf,14)=min(sd->status.luk, UCHAR_MAX);
  2536. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2537. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw->atk;
  2538. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw->atk2; //atk bonus
  2539. WBUFW(buf,20) = sd->battle_status.matk_max;
  2540. WBUFW(buf,22) = sd->battle_status.matk_min;
  2541. WBUFW(buf,24) = sd->battle_status.def; // def
  2542. WBUFW(buf,26) = sd->battle_status.def2;
  2543. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2544. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2545. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2546. WBUFW(buf,30) = fd;
  2547. fd = sd->fd;
  2548. WBUFW(buf,32) = sd->battle_status.hit;
  2549. WBUFW(buf,34) = sd->battle_status.flee;
  2550. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2551. WBUFW(buf,38) = sd->battle_status.cri/10;
  2552. WBUFW(buf,40) = sd->status.karma;
  2553. WBUFW(buf,42) = sd->status.manner;
  2554. WFIFOSET(fd,packet_len(0xbd));
  2555. clif_updatestatus(sd,SP_STR);
  2556. clif_updatestatus(sd,SP_AGI);
  2557. clif_updatestatus(sd,SP_VIT);
  2558. clif_updatestatus(sd,SP_INT);
  2559. clif_updatestatus(sd,SP_DEX);
  2560. clif_updatestatus(sd,SP_LUK);
  2561. clif_updatestatus(sd,SP_ATTACKRANGE);
  2562. clif_updatestatus(sd,SP_ASPD);
  2563. return 0;
  2564. }
  2565. /*==========================================
  2566. *矢装備
  2567. *------------------------------------------*/
  2568. int clif_arrowequip(struct map_session_data *sd,int val)
  2569. {
  2570. int fd;
  2571. nullpo_retr(0, sd);
  2572. pc_stop_attack(sd); // [Valaris]
  2573. fd=sd->fd;
  2574. WFIFOHEAD(fd, packet_len(0x013c));
  2575. WFIFOW(fd,0)=0x013c;
  2576. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2577. WFIFOSET(fd,packet_len(0x013c));
  2578. return 0;
  2579. }
  2580. /// Ammunition action message.
  2581. /// type=0 : MsgStringTable[242]="Please equip the proper ammunition first."
  2582. /// type=1 : MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2583. /// type=2 : MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2584. /// type=3 : assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2585. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2586. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2587. int clif_arrow_fail(struct map_session_data *sd,int type)
  2588. {
  2589. int fd;
  2590. nullpo_retr(0, sd);
  2591. fd=sd->fd;
  2592. WFIFOHEAD(fd, packet_len(0x013b));
  2593. WFIFOW(fd,0)=0x013b;
  2594. WFIFOW(fd,2)=type;
  2595. WFIFOSET(fd,packet_len(0x013b));
  2596. return 0;
  2597. }
  2598. /*==========================================
  2599. * 作成可能 矢リスト送信
  2600. *------------------------------------------*/
  2601. int clif_arrow_create_list(struct map_session_data *sd)
  2602. {
  2603. int i, c, j;
  2604. int fd;
  2605. nullpo_retr(0, sd);
  2606. fd = sd->fd;
  2607. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2608. WFIFOW(fd,0) = 0x1ad;
  2609. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2610. if (skill_arrow_db[i].nameid > 0 &&
  2611. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2612. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2613. {
  2614. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2615. WFIFOW(fd,c*2+4) = j;
  2616. else
  2617. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2618. c++;
  2619. }
  2620. }
  2621. WFIFOW(fd,2) = c*2+4;
  2622. WFIFOSET(fd, WFIFOW(fd,2));
  2623. if (c > 0) {
  2624. sd->menuskill_id = AC_MAKINGARROW;
  2625. sd->menuskill_val = c;
  2626. }
  2627. return 0;
  2628. }
  2629. /*==========================================
  2630. *
  2631. *------------------------------------------*/
  2632. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2633. {
  2634. int fd;
  2635. nullpo_retr(0, sd);
  2636. fd=sd->fd;
  2637. WFIFOHEAD(fd,packet_len(0xbc));
  2638. WFIFOW(fd,0)=0xbc;
  2639. WFIFOW(fd,2)=type;
  2640. WFIFOB(fd,4)=ok;
  2641. WFIFOB(fd,5)=val;
  2642. WFIFOSET(fd,packet_len(0xbc));
  2643. return 0;
  2644. }
  2645. /*==========================================
  2646. *
  2647. *------------------------------------------*/
  2648. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2649. {
  2650. int fd;
  2651. nullpo_retr(0, sd);
  2652. fd=sd->fd;
  2653. WFIFOHEAD(fd,packet_len(0xaa));
  2654. WFIFOW(fd,0)=0xaa;
  2655. WFIFOW(fd,2)=n+2;
  2656. WFIFOW(fd,4)=pos;
  2657. WFIFOB(fd,6)=ok;
  2658. WFIFOSET(fd,packet_len(0xaa));
  2659. return 0;
  2660. }
  2661. /*==========================================
  2662. *
  2663. *------------------------------------------*/
  2664. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2665. {
  2666. int fd;
  2667. nullpo_retr(0, sd);
  2668. fd=sd->fd;
  2669. WFIFOHEAD(fd,packet_len(0xac));
  2670. WFIFOW(fd,0)=0xac;
  2671. WFIFOW(fd,2)=n+2;
  2672. WFIFOW(fd,4)=pos;
  2673. WFIFOB(fd,6)=ok;
  2674. WFIFOSET(fd,packet_len(0xac));
  2675. return 0;
  2676. }
  2677. /*==========================================
  2678. *
  2679. *------------------------------------------*/
  2680. int clif_misceffect(struct block_list* bl,int type)
  2681. {
  2682. unsigned char buf[32];
  2683. nullpo_retr(0, bl);
  2684. WBUFW(buf,0) = 0x19b;
  2685. WBUFL(buf,2) = bl->id;
  2686. WBUFL(buf,6) = type;
  2687. clif_send(buf,packet_len(0x19b),bl,AREA);
  2688. return 0;
  2689. }
  2690. int clif_misceffect2(struct block_list *bl, int type)
  2691. {
  2692. unsigned char buf[24];
  2693. nullpo_retr(0, bl);
  2694. memset(buf, 0, packet_len(0x1f3));
  2695. WBUFW(buf,0) = 0x1f3;
  2696. WBUFL(buf,2) = bl->id;
  2697. WBUFL(buf,6) = type;
  2698. clif_send(buf, packet_len(0x1f3), bl, AREA);
  2699. return 0;
  2700. }
  2701. /*==========================================
  2702. * 表示オプション変更
  2703. *------------------------------------------*/
  2704. int clif_changeoption(struct block_list* bl)
  2705. {
  2706. unsigned char buf[32];
  2707. struct status_change *sc;
  2708. nullpo_retr(0, bl);
  2709. sc = status_get_sc(bl);
  2710. if (!sc) return 0; //How can an option change if there's no sc?
  2711. #if PACKETVER >= 7
  2712. WBUFW(buf,0) = 0x229;
  2713. WBUFL(buf,2) = bl->id;
  2714. WBUFW(buf,6) = sc->opt1;
  2715. WBUFW(buf,8) = sc->opt2;
  2716. WBUFL(buf,10) = sc->option;
  2717. WBUFB(buf,14) = 0; // PK???
  2718. if(disguised(bl)) {
  2719. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2720. WBUFL(buf,2) = -bl->id;
  2721. clif_send(buf,packet_len(0x229),bl,SELF);
  2722. WBUFL(buf,2) = bl->id;
  2723. WBUFL(buf,10) = OPTION_INVISIBLE;
  2724. clif_send(buf,packet_len(0x229),bl,SELF);
  2725. } else
  2726. clif_send(buf,packet_len(0x229),bl,AREA);
  2727. #else
  2728. WBUFW(buf,0) = 0x119;
  2729. WBUFL(buf,2) = bl->id;
  2730. WBUFW(buf,6) = sc->opt1;
  2731. WBUFW(buf,8) = sc->opt2;
  2732. WBUFW(buf,10) = sc->option;
  2733. WBUFB(buf,12) = 0; // ??
  2734. if(disguised(bl)) {
  2735. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2736. WBUFL(buf,2) = -bl->id;
  2737. clif_send(buf,packet_len(0x119),bl,SELF);
  2738. WBUFL(buf,2) = bl->id;
  2739. WBUFW(buf,10) = OPTION_INVISIBLE;
  2740. clif_send(buf,packet_len(0x119),bl,SELF);
  2741. } else
  2742. clif_send(buf,packet_len(0x119),bl,AREA);
  2743. #endif
  2744. return 0;
  2745. }
  2746. int clif_changeoption2(struct block_list* bl)
  2747. {
  2748. unsigned char buf[20];
  2749. struct status_change *sc;
  2750. sc = status_get_sc(bl);
  2751. if (!sc) return 0; //How can an option change if there's no sc?
  2752. WBUFW(buf,0) = 0x28a;
  2753. WBUFL(buf,2) = bl->id;
  2754. WBUFL(buf,6) = sc->option;
  2755. WBUFL(buf,10) = clif_setlevel(status_get_lv(bl));
  2756. WBUFL(buf,14) = sc->opt3;
  2757. if(disguised(bl)) {
  2758. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  2759. WBUFL(buf,2) = -bl->id;
  2760. clif_send(buf,packet_len(0x28a),bl,SELF);
  2761. WBUFL(buf,2) = bl->id;
  2762. WBUFL(buf,6) = OPTION_INVISIBLE;
  2763. clif_send(buf,packet_len(0x28a),bl,SELF);
  2764. } else
  2765. clif_send(buf,packet_len(0x28a),bl,AREA);
  2766. return 0;
  2767. }
  2768. /*==========================================
  2769. *
  2770. *------------------------------------------*/
  2771. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2772. {
  2773. nullpo_retr(0, sd);
  2774. if(!ok) {
  2775. int fd=sd->fd;
  2776. WFIFOHEAD(fd,packet_len(0xa8));
  2777. WFIFOW(fd,0)=0xa8;
  2778. WFIFOW(fd,2)=index+2;
  2779. WFIFOW(fd,4)=amount;
  2780. WFIFOB(fd,6)=ok;
  2781. WFIFOSET(fd,packet_len(0xa8));
  2782. }
  2783. else {
  2784. #if PACKETVER < 3
  2785. int fd=sd->fd;
  2786. WFIFOHEAD(fd,packet_len(0xa8));
  2787. WFIFOW(fd,0)=0xa8;
  2788. WFIFOW(fd,2)=index+2;
  2789. WFIFOW(fd,4)=amount;
  2790. WFIFOB(fd,6)=ok;
  2791. WFIFOSET(fd,packet_len(0xa8));
  2792. #else
  2793. unsigned char buf[32];
  2794. WBUFW(buf,0)=0x1c8;
  2795. WBUFW(buf,2)=index+2;
  2796. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2797. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2798. else
  2799. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2800. WBUFL(buf,6)=sd->bl.id;
  2801. WBUFW(buf,10)=amount;
  2802. WBUFB(buf,12)=ok;
  2803. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2804. #endif
  2805. }
  2806. return 0;
  2807. }
  2808. /*==========================================
  2809. * Inform client whether chatroom creation was successful or not
  2810. * R 00d6 <fail>.B
  2811. *------------------------------------------*/
  2812. void clif_createchat(struct map_session_data* sd, int fail)
  2813. {
  2814. int fd;
  2815. nullpo_retv(sd);
  2816. fd = sd->fd;
  2817. WFIFOHEAD(fd,packet_len(0xd6));
  2818. WFIFOW(fd,0) = 0xd6;
  2819. WFIFOB(fd,2) = fail;
  2820. WFIFOSET(fd,packet_len(0xd6));
  2821. }
  2822. /*==========================================
  2823. * Display a chat above the owner
  2824. * R 00d7 <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <type>.B <title>.?B
  2825. *------------------------------------------*/
  2826. int clif_dispchat(struct chat_data* cd, int fd)
  2827. {
  2828. unsigned char buf[128];
  2829. uint8 type;
  2830. if( cd == NULL || cd->owner == NULL )
  2831. return 1;
  2832. // type - 0: private, 1: public, 2: npc, 3: non-clickable
  2833. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  2834. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  2835. : 1;
  2836. WBUFW(buf, 0) = 0xd7;
  2837. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2838. WBUFL(buf, 4) = cd->owner->id;
  2839. WBUFL(buf, 8) = cd->bl.id;
  2840. WBUFW(buf,12) = cd->limit;
  2841. WBUFW(buf,14) = cd->users;
  2842. WBUFB(buf,16) = type;
  2843. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2844. if( fd ) {
  2845. WFIFOHEAD(fd,WBUFW(buf,2));
  2846. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2847. WFIFOSET(fd,WBUFW(buf,2));
  2848. } else {
  2849. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  2850. }
  2851. return 0;
  2852. }
  2853. /*==========================================
  2854. * Chatroom properties adjustment
  2855. * R 00df <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <pub>.B <title>.?B
  2856. *------------------------------------------*/
  2857. int clif_changechatstatus(struct chat_data* cd)
  2858. {
  2859. unsigned char buf[128];
  2860. if( cd == NULL || cd->usersd[0] == NULL )
  2861. return 1;
  2862. WBUFW(buf, 0) = 0xdf;
  2863. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2864. WBUFL(buf, 4) = cd->usersd[0]->bl.id;
  2865. WBUFL(buf, 8) = cd->bl.id;
  2866. WBUFW(buf,12) = cd->limit;
  2867. WBUFW(buf,14) = cd->users;
  2868. WBUFB(buf,16) = cd->pub;
  2869. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2870. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2871. return 0;
  2872. }
  2873. /*==========================================
  2874. *
  2875. *------------------------------------------*/
  2876. int clif_clearchat(struct chat_data *cd,int fd)
  2877. {
  2878. unsigned char buf[32];
  2879. nullpo_retr(0, cd);
  2880. WBUFW(buf,0) = 0xd8;
  2881. WBUFL(buf,2) = cd->bl.id;
  2882. if( fd ) {
  2883. WFIFOHEAD(fd,packet_len(0xd8));
  2884. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2885. WFIFOSET(fd,packet_len(0xd8));
  2886. } else {
  2887. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  2888. }
  2889. return 0;
  2890. }
  2891. /*==========================================
  2892. *
  2893. *------------------------------------------*/
  2894. int clif_joinchatfail(struct map_session_data *sd,int fail)
  2895. {
  2896. int fd;
  2897. nullpo_retr(0, sd);
  2898. fd = sd->fd;
  2899. WFIFOHEAD(fd,packet_len(0xda));
  2900. WFIFOW(fd,0) = 0xda;
  2901. WFIFOB(fd,2) = fail;
  2902. WFIFOSET(fd,packet_len(0xda));
  2903. return 0;
  2904. }
  2905. /*==========================================
  2906. *
  2907. *------------------------------------------*/
  2908. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2909. {
  2910. int fd;
  2911. int i;
  2912. nullpo_retr(0, sd);
  2913. nullpo_retr(0, cd);
  2914. fd = sd->fd;
  2915. if (!session_isActive(fd))
  2916. return 0;
  2917. WFIFOHEAD(fd, 8 + (28*cd->users));
  2918. WFIFOW(fd, 0) = 0xdb;
  2919. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2920. WFIFOL(fd, 4) = cd->bl.id;
  2921. for (i = 0; i < cd->users; i++) {
  2922. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  2923. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2924. }
  2925. WFIFOSET(fd, WFIFOW(fd, 2));
  2926. return 0;
  2927. }
  2928. /*==========================================
  2929. *
  2930. *------------------------------------------*/
  2931. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2932. {
  2933. unsigned char buf[32];
  2934. nullpo_retr(0, sd);
  2935. nullpo_retr(0, cd);
  2936. WBUFW(buf, 0) = 0x0dc;
  2937. WBUFW(buf, 2) = cd->users;
  2938. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2939. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  2940. return 0;
  2941. }
  2942. /*==========================================
  2943. * Announce the new owner
  2944. * R 00e1 <index>.l <nick>.24B
  2945. *------------------------------------------*/
  2946. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  2947. {
  2948. unsigned char buf[64];
  2949. nullpo_retv(sd);
  2950. nullpo_retv(cd);
  2951. //FIXME: this announces a swap between positions 0 and 1 (probably not what we want) [ultramage]
  2952. //FIXME: aegis sends obviously incorrect packets; need to figure out what to send to display it correctly :X
  2953. //TODO: is it just owner swap, or can it do general-purpose reordering?
  2954. WBUFW(buf, 0) = 0xe1;
  2955. WBUFL(buf, 2) = 1;
  2956. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2957. WBUFW(buf,30) = 0xe1;
  2958. WBUFL(buf,32) = 0;
  2959. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2960. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  2961. }
  2962. /*==========================================
  2963. * Notify about user leaving the chatroom
  2964. * R 00dd <index>.w <nick>.24B <flag>.B
  2965. *------------------------------------------*/
  2966. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  2967. {
  2968. unsigned char buf[32];
  2969. nullpo_retv(sd);
  2970. nullpo_retv(cd);
  2971. WBUFW(buf, 0) = 0xdd;
  2972. WBUFW(buf, 2) = cd->users-1;
  2973. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2974. WBUFB(buf,28) = flag; // 0: left, 1: was kicked
  2975. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  2976. }
  2977. /*==========================================
  2978. * Opens a trade request window from char 'name'
  2979. * R 00e5 <nick>.24B
  2980. *------------------------------------------*/
  2981. void clif_traderequest(struct map_session_data* sd, const char* name)
  2982. {
  2983. int fd;
  2984. nullpo_retv(sd);
  2985. fd = sd->fd;
  2986. WFIFOHEAD(fd,packet_len(0xe5));
  2987. WFIFOW(fd,0) = 0xe5;
  2988. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2989. WFIFOSET(fd,packet_len(0xe5));
  2990. }
  2991. /*==========================================
  2992. * 取り引き要求応答
  2993. *------------------------------------------*/
  2994. void clif_tradestart(struct map_session_data* sd, int type)
  2995. {
  2996. int fd;
  2997. nullpo_retv(sd);
  2998. fd = sd->fd;
  2999. WFIFOHEAD(fd,packet_len(0xe7));
  3000. WFIFOW(fd,0) = 0xe7;
  3001. WFIFOB(fd,2) = type;
  3002. WFIFOSET(fd,packet_len(0xe7));
  3003. }
  3004. /*==========================================
  3005. * 相手方からのアイテム追加
  3006. *------------------------------------------*/
  3007. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  3008. {
  3009. int fd;
  3010. nullpo_retv(sd);
  3011. nullpo_retv(tsd);
  3012. fd = tsd->fd;
  3013. WFIFOHEAD(fd,packet_len(0xe9));
  3014. WFIFOW(fd,0) = 0xe9;
  3015. WFIFOL(fd,2) = amount;
  3016. if( index == 0 )
  3017. {
  3018. WFIFOW(fd,6) = 0; // type id
  3019. WFIFOB(fd,8) = 0; //identify flag
  3020. WFIFOB(fd,9) = 0; // attribute
  3021. WFIFOB(fd,10)= 0; //refine
  3022. WFIFOW(fd,11)= 0; //card (4w)
  3023. WFIFOW(fd,13)= 0; //card (4w)
  3024. WFIFOW(fd,15)= 0; //card (4w)
  3025. WFIFOW(fd,17)= 0; //card (4w)
  3026. }
  3027. else
  3028. {
  3029. index -= 2; //index fix
  3030. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  3031. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  3032. else
  3033. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  3034. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  3035. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  3036. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  3037. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  3038. }
  3039. WFIFOSET(fd,packet_len(0xe9));
  3040. }
  3041. /*==========================================
  3042. * アイテム追加成功/失敗
  3043. *------------------------------------------*/
  3044. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  3045. {
  3046. int fd;
  3047. nullpo_retv(sd);
  3048. fd = sd->fd;
  3049. WFIFOHEAD(fd,packet_len(0xea));
  3050. WFIFOW(fd,0) = 0xea;
  3051. WFIFOW(fd,2) = index;
  3052. WFIFOB(fd,4) = fail;
  3053. WFIFOSET(fd,packet_len(0xea));
  3054. }
  3055. /*==========================================
  3056. * 取り引きok押し
  3057. *------------------------------------------*/
  3058. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  3059. {
  3060. int fd;
  3061. nullpo_retv(sd);
  3062. fd = sd->fd;
  3063. WFIFOHEAD(fd,packet_len(0xec));
  3064. WFIFOW(fd,0) = 0xec;
  3065. WFIFOB(fd,2) = fail; // 0=you 1=the other person
  3066. WFIFOSET(fd,packet_len(0xec));
  3067. }
  3068. /*==========================================
  3069. * 取り引きがキャンセルされました
  3070. *------------------------------------------*/
  3071. void clif_tradecancelled(struct map_session_data* sd)
  3072. {
  3073. int fd;
  3074. nullpo_retv(sd);
  3075. fd = sd->fd;
  3076. WFIFOHEAD(fd,packet_len(0xee));
  3077. WFIFOW(fd,0) = 0xee;
  3078. WFIFOSET(fd,packet_len(0xee));
  3079. }
  3080. /*==========================================
  3081. * 取り引き完了
  3082. *------------------------------------------*/
  3083. void clif_tradecompleted(struct map_session_data* sd, int fail)
  3084. {
  3085. int fd;
  3086. nullpo_retv(sd);
  3087. fd = sd->fd;
  3088. WFIFOHEAD(fd,packet_len(0xf0));
  3089. WFIFOW(fd,0) = 0xf0;
  3090. WFIFOB(fd,2) = fail;
  3091. WFIFOSET(fd,packet_len(0xf0));
  3092. }
  3093. /*==========================================
  3094. * カプラ倉庫のアイテム数を更新
  3095. *------------------------------------------*/
  3096. int clif_updatestorageamount(struct map_session_data *sd,struct storage *stor)
  3097. {
  3098. int fd;
  3099. nullpo_retr(0, sd);
  3100. nullpo_retr(0, stor);
  3101. fd=sd->fd;
  3102. WFIFOHEAD(fd,packet_len(0xf2));
  3103. WFIFOW(fd,0) = 0xf2; // update storage amount
  3104. WFIFOW(fd,2) = stor->storage_amount; //items
  3105. WFIFOW(fd,4) = MAX_STORAGE; //items max
  3106. WFIFOSET(fd,packet_len(0xf2));
  3107. return 0;
  3108. }
  3109. /*==========================================
  3110. * カプラ倉庫にアイテムを追加する
  3111. *------------------------------------------*/
  3112. int clif_storageitemadded(struct map_session_data *sd,struct storage *stor,int index,int amount)
  3113. {
  3114. int view,fd;
  3115. nullpo_retr(0, sd);
  3116. nullpo_retr(0, stor);
  3117. fd=sd->fd;
  3118. WFIFOHEAD(fd,packet_len(0xf4));
  3119. WFIFOW(fd,0) =0xf4; // Storage item added
  3120. WFIFOW(fd,2) =index+1; // index
  3121. WFIFOL(fd,4) =amount; // amount
  3122. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3123. WFIFOW(fd,8) =view;
  3124. else
  3125. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3126. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3127. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3128. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3129. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3130. WFIFOSET(fd,packet_len(0xf4));
  3131. return 0;
  3132. }
  3133. /*==========================================
  3134. *
  3135. *------------------------------------------*/
  3136. int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor)
  3137. {
  3138. int fd;
  3139. nullpo_retr(0, sd);
  3140. nullpo_retr(0, stor);
  3141. fd=sd->fd;
  3142. WFIFOHEAD(fd,packet_len(0xf2));
  3143. WFIFOW(fd,0) = 0xf2; // update storage amount
  3144. WFIFOW(fd,2) = stor->storage_amount; //items
  3145. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  3146. WFIFOSET(fd,packet_len(0xf2));
  3147. return 0;
  3148. }
  3149. /*==========================================
  3150. *
  3151. *------------------------------------------*/
  3152. int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount)
  3153. {
  3154. int view,fd;
  3155. nullpo_retr(0, sd);
  3156. nullpo_retr(0, stor);
  3157. fd=sd->fd;
  3158. WFIFOHEAD(fd,packet_len(0xf4));
  3159. WFIFOW(fd,0) =0xf4; // Storage item added
  3160. WFIFOW(fd,2) =index+1; // index
  3161. WFIFOL(fd,4) =amount; // amount
  3162. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3163. WFIFOW(fd,8) =view;
  3164. else
  3165. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3166. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3167. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3168. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3169. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3170. WFIFOSET(fd,packet_len(0xf4));
  3171. return 0;
  3172. }
  3173. /*==========================================
  3174. * カプラ倉庫からアイテムを取り去る
  3175. *------------------------------------------*/
  3176. int clif_storageitemremoved(struct map_session_data *sd,int index,int amount)
  3177. {
  3178. int fd;
  3179. nullpo_retr(0, sd);
  3180. fd=sd->fd;
  3181. WFIFOHEAD(fd,packet_len(0xf6));
  3182. WFIFOW(fd,0)=0xf6; // Storage item removed
  3183. WFIFOW(fd,2)=index+1;
  3184. WFIFOL(fd,4)=amount;
  3185. WFIFOSET(fd,packet_len(0xf6));
  3186. return 0;
  3187. }
  3188. /*==========================================
  3189. * カプラ倉庫を閉じる
  3190. *------------------------------------------*/
  3191. int clif_storageclose(struct map_session_data *sd)
  3192. {
  3193. int fd;
  3194. nullpo_retr(0, sd);
  3195. fd=sd->fd;
  3196. WFIFOHEAD(fd,packet_len(0xf8));
  3197. WFIFOW(fd,0)=0xf8; // Storage Closed
  3198. WFIFOSET(fd,packet_len(0xf8));
  3199. return 0;
  3200. }
  3201. //
  3202. // callback系 ?
  3203. //
  3204. /*==========================================
  3205. * PC表示
  3206. *------------------------------------------*/
  3207. void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3208. {
  3209. int len;
  3210. if(dstsd->chatID)
  3211. {
  3212. struct chat_data *cd;
  3213. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  3214. if(cd && cd->usersd[0]==dstsd)
  3215. clif_dispchat(cd,sd->fd);
  3216. }
  3217. if(dstsd->vender_id)
  3218. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3219. if(dstsd->spiritball > 0)
  3220. clif_spiritball_single(sd->fd, dstsd);
  3221. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3222. (battle_config.disp_hpmeter && (len = pc_isGM(sd)) >= battle_config.disp_hpmeter && len >= pc_isGM(dstsd))
  3223. )
  3224. clif_hpmeter_single(sd->fd, dstsd);
  3225. if(dstsd->status.manner < 0)
  3226. clif_changestatus(&dstsd->bl,SP_MANNER,dstsd->status.manner);
  3227. // pvp circle for duel [LuzZza]
  3228. /*
  3229. if(dstsd->duel_group)
  3230. clif_specialeffect(&dstsd->bl, 159, 4);
  3231. */
  3232. }
  3233. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3234. {
  3235. struct unit_data *ud;
  3236. struct view_data *vd;
  3237. int len, fd = sd->fd;
  3238. vd = status_get_viewdata(bl);
  3239. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3240. return;
  3241. ud = unit_bl2ud(bl);
  3242. if (ud && ud->walktimer != -1)
  3243. {
  3244. #if PACKETVER >= 7
  3245. WFIFOHEAD(fd, packet_len(0x22c));
  3246. #elif PACKETVER > 3
  3247. WFIFOHEAD(fd, packet_len(0x1da));
  3248. #else
  3249. WFIFOHEAD(fd, packet_len(0x7b));
  3250. #endif
  3251. len = clif_set007b(bl,vd,ud,WFIFOP(fd,0));
  3252. WFIFOSET(fd,len);
  3253. } else {
  3254. #if PACKETVER >= 7
  3255. WFIFOHEAD(fd,packet_len(0x22a));
  3256. #elif PACKETVER > 3
  3257. WFIFOHEAD(fd,packet_len(0x1d8));
  3258. #else
  3259. WFIFOHEAD(fd,packet_len(0x78));
  3260. #endif
  3261. len = clif_set0078(bl,WFIFOP(fd,0));
  3262. WFIFOSET(fd,len);
  3263. }
  3264. if (vd->cloth_color)
  3265. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3266. switch (bl->type)
  3267. { // FIXME: 'AREA' causes unneccessary spam since this should be 1:1 communication [ultramage]
  3268. case BL_PC:
  3269. {
  3270. TBL_PC* tsd = (TBL_PC*)bl;
  3271. clif_getareachar_pc(sd, tsd);
  3272. if(tsd->state.size==2) // tiny/big players [Valaris]
  3273. clif_specialeffect(bl,423,AREA);
  3274. else if(tsd->state.size==1)
  3275. clif_specialeffect(bl,421,AREA);
  3276. }
  3277. break;
  3278. case BL_NPC:
  3279. {
  3280. if(((TBL_NPC*)bl)->chat_id)
  3281. clif_dispchat((struct chat_data*)map_id2bl(((TBL_NPC*)bl)->chat_id),sd->fd);
  3282. }
  3283. break;
  3284. case BL_MOB:
  3285. {
  3286. TBL_MOB* md = (TBL_MOB*)bl;
  3287. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3288. clif_specialeffect(bl,423,AREA);
  3289. else if(md->special_state.size==1)
  3290. clif_specialeffect(bl,421,AREA);
  3291. }
  3292. break;
  3293. case BL_PET:
  3294. if (vd->head_bottom)
  3295. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3296. break;
  3297. }
  3298. }
  3299. //Modifies the type of damage according to status changes [Skotlex]
  3300. #define clif_calc_delay(type,delay) (type==1||type==4||type==0x0a)?type:(delay==0?9:type)
  3301. /*==========================================
  3302. * Estimates walk delay based on the damage criteria. [Skotlex]
  3303. *------------------------------------------*/
  3304. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3305. {
  3306. if (type == 4 || type == 9 || damage <=0)
  3307. return 0;
  3308. if (bl->type == BL_PC) {
  3309. if (battle_config.pc_walk_delay_rate != 100)
  3310. delay = delay*battle_config.pc_walk_delay_rate/100;
  3311. } else
  3312. if (battle_config.walk_delay_rate != 100)
  3313. delay = delay*battle_config.walk_delay_rate/100;
  3314. if (div_ > 1) //Multi-hit skills mean higher delays.
  3315. delay += battle_config.multihit_delay*(div_-1);
  3316. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3317. }
  3318. /*==========================================
  3319. * Sends a 'damage' packet (src performs action on dst)
  3320. * 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
  3321. *
  3322. * type=00 damage [param1: total damage, param2: div, param3: assassin dual-wield damage]
  3323. * type=01 pick up item
  3324. * type=02 sit down
  3325. * type=03 stand up
  3326. * type=04 reflected/absorbed damage?
  3327. * type=08 double attack
  3328. * type=09 don't display flinch animation (endure)
  3329. * type=0a critical hit
  3330. * type=0b lucky dodge
  3331. *------------------------------------------*/
  3332. 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)
  3333. {
  3334. unsigned char buf[256];
  3335. struct status_change *sc;
  3336. nullpo_retr(0, src);
  3337. nullpo_retr(0, dst);
  3338. type = clif_calc_delay(type, ddelay); //Type defaults to 0 for normal attacks.
  3339. sc = status_get_sc(dst);
  3340. if(sc && sc->count) {
  3341. if(sc->data[SC_HALLUCINATION].timer != -1) {
  3342. if(damage > 0) damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3343. if(damage2 > 0) damage2 = damage2*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3344. }
  3345. }
  3346. WBUFW(buf,0)=0x8a;
  3347. WBUFL(buf,2)=src->id;
  3348. WBUFL(buf,6)=dst->id;
  3349. WBUFL(buf,10)=tick;
  3350. WBUFL(buf,14)=sdelay;
  3351. WBUFL(buf,18)=ddelay;
  3352. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3353. WBUFW(buf,22)=damage?div:0;
  3354. WBUFW(buf,27)=damage2?div:0;
  3355. } else {
  3356. WBUFW(buf,22)=min(damage, SHRT_MAX);
  3357. WBUFW(buf,27)=damage2;
  3358. }
  3359. WBUFW(buf,24)=div;
  3360. WBUFB(buf,26)=type;
  3361. clif_send(buf,packet_len(0x8a),src,AREA);
  3362. if(disguised(src)) {
  3363. WBUFL(buf,2) = -src->id;
  3364. if(damage > 0) WBUFW(buf,22) = -1;
  3365. if(damage2 > 0) WBUFW(buf,27) = -1;
  3366. clif_send(buf,packet_len(0x8a),src,SELF);
  3367. }
  3368. if (disguised(dst)) {
  3369. WBUFL(buf,6) = -dst->id;
  3370. if (disguised(src)) WBUFL(buf,2) = src->id;
  3371. else {
  3372. if(damage > 0) WBUFW(buf,22) = -1;
  3373. if(damage2 > 0) WBUFW(buf,27) = -1;
  3374. }
  3375. clif_send(buf,packet_len(0x8a),dst,SELF);
  3376. }
  3377. //Return adjusted can't walk delay for further processing.
  3378. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3379. }
  3380. /*==========================================
  3381. * src picks up dst
  3382. *------------------------------------------*/
  3383. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3384. {
  3385. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3386. unsigned char buf[32];
  3387. nullpo_retv(src);
  3388. nullpo_retv(dst);
  3389. WBUFW(buf, 0) = 0x8a;
  3390. WBUFL(buf, 2) = src->id;
  3391. WBUFL(buf, 6) = dst->id;
  3392. WBUFB(buf,26) = 1;
  3393. clif_send(buf, packet_len(0x8a), src, AREA);
  3394. }
  3395. /*==========================================
  3396. * inform clients in area that `bl` is sitting
  3397. *------------------------------------------*/
  3398. void clif_sitting(struct block_list* bl)
  3399. {
  3400. unsigned char buf[32];
  3401. nullpo_retv(bl);
  3402. WBUFW(buf, 0) = 0x8a;
  3403. WBUFL(buf, 2) = bl->id;
  3404. WBUFB(buf,26) = 2;
  3405. clif_send(buf, packet_len(0x8a), bl, AREA);
  3406. if(disguised(bl)) {
  3407. WBUFL(buf, 2) = - bl->id;
  3408. clif_send(buf, packet_len(0x8a), bl, SELF);
  3409. }
  3410. }
  3411. /*==========================================
  3412. * inform clients in area that `bl` is standing
  3413. *------------------------------------------*/
  3414. void clif_standing(struct block_list* bl)
  3415. {
  3416. unsigned char buf[32];
  3417. nullpo_retv(bl);
  3418. WBUFW(buf, 0) = 0x8a;
  3419. WBUFL(buf, 2) = bl->id;
  3420. WBUFB(buf,26) = 3;
  3421. clif_send(buf, packet_len(0x8a), bl, AREA);
  3422. if(disguised(bl)) {
  3423. WBUFL(buf, 2) = - bl->id;
  3424. clif_send(buf, packet_len(0x8a), bl, SELF);
  3425. }
  3426. }
  3427. /*==========================================
  3428. *
  3429. *------------------------------------------*/
  3430. void clif_changemapcell(int fd, short m, short x, short y, int type)
  3431. {
  3432. unsigned char buf[32];
  3433. WBUFW(buf,0) = 0x192;
  3434. WBUFW(buf,2) = x;
  3435. WBUFW(buf,4) = y;
  3436. WBUFW(buf,6) = type;
  3437. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3438. if (fd == 0) {
  3439. struct block_list bl;
  3440. bl.type = BL_NUL;
  3441. bl.m = m;
  3442. bl.x = x;
  3443. bl.y = y;
  3444. clif_send(buf,packet_len(0x192),&bl,AREA);
  3445. } else {
  3446. WFIFOHEAD(fd,packet_len(0x192));
  3447. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3448. WFIFOSET(fd,packet_len(0x192));
  3449. }
  3450. }
  3451. /*==========================================
  3452. *
  3453. *------------------------------------------*/
  3454. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3455. {
  3456. int view,fd;
  3457. fd=sd->fd;
  3458. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3459. WFIFOHEAD(fd,packet_len(0x9d));
  3460. WFIFOW(fd,0)=0x9d;
  3461. WFIFOL(fd,2)=fitem->bl.id;
  3462. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3463. WFIFOW(fd,6)=view;
  3464. else
  3465. WFIFOW(fd,6)=fitem->item_data.nameid;
  3466. WFIFOB(fd,8)=fitem->item_data.identify;
  3467. WFIFOW(fd,9)=fitem->bl.x;
  3468. WFIFOW(fd,11)=fitem->bl.y;
  3469. WFIFOW(fd,13)=fitem->item_data.amount;
  3470. WFIFOB(fd,15)=fitem->subx;
  3471. WFIFOB(fd,16)=fitem->suby;
  3472. WFIFOSET(fd,packet_len(0x9d));
  3473. }
  3474. /*==========================================
  3475. * 場所スキルエフェクトが視界に入る
  3476. *------------------------------------------*/
  3477. static void clif_getareachar_skillunit(struct map_session_data *sd, struct skill_unit *unit)
  3478. {
  3479. int fd = sd->fd;
  3480. #if PACKETVER >= 3
  3481. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3482. WFIFOHEAD(fd,packet_len(0x1c9));
  3483. WFIFOW(fd, 0)=0x1c9;
  3484. WFIFOL(fd, 2)=unit->bl.id;
  3485. WFIFOL(fd, 6)=unit->group->src_id;
  3486. WFIFOW(fd,10)=unit->bl.x;
  3487. WFIFOW(fd,12)=unit->bl.y;
  3488. WFIFOB(fd,14)=unit->group->unit_id;
  3489. WFIFOB(fd,15)=1;
  3490. WFIFOB(fd,16)=1;
  3491. safestrncpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3492. WFIFOSET(fd,packet_len(0x1c9));
  3493. return;
  3494. }
  3495. #endif
  3496. WFIFOHEAD(fd,packet_len(0x11f));
  3497. WFIFOW(fd, 0)=0x11f;
  3498. WFIFOL(fd, 2)=unit->bl.id;
  3499. WFIFOL(fd, 6)=unit->group->src_id;
  3500. WFIFOW(fd,10)=unit->bl.x;
  3501. WFIFOW(fd,12)=unit->bl.y;
  3502. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3503. WFIFOB(fd,14)=UNT_ATTACK_SKILLS; //Use invisible unit id for traps.
  3504. else
  3505. WFIFOB(fd,14)=unit->group->unit_id;
  3506. WFIFOB(fd,15)=0;
  3507. WFIFOSET(fd,packet_len(0x11f));
  3508. if(unit->group->skill_id == WZ_ICEWALL)
  3509. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3510. }
  3511. /*==========================================
  3512. * 場所スキルエフェクトが視界から消える
  3513. *------------------------------------------*/
  3514. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3515. {
  3516. nullpo_retv(unit);
  3517. WFIFOHEAD(fd,packet_len(0x120));
  3518. WFIFOW(fd, 0)=0x120;
  3519. WFIFOL(fd, 2)=unit->bl.id;
  3520. WFIFOSET(fd,packet_len(0x120));
  3521. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3522. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2);
  3523. }
  3524. /*==========================================
  3525. * Unknown... trap related?
  3526. * Only affects units with class [139,153] client-side
  3527. *------------------------------------------*/
  3528. int clif_01ac(struct block_list *bl)
  3529. {
  3530. unsigned char buf[32];
  3531. nullpo_retr(0, bl);
  3532. WBUFW(buf, 0) = 0x1ac;
  3533. WBUFL(buf, 2) = bl->id;
  3534. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3535. return 0;
  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 jemstone needed" MsgStringTable[246]
  3782. /// type==8 "blue jemstone 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. * スキル攻撃エフェクト&ダメージ
  3818. *------------------------------------------*/
  3819. int clif_skill_damage(struct block_list *src,struct block_list *dst,
  3820. 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. type = (type>0)?type:skill_get_hit(skill_id);
  3827. type = clif_calc_delay(type, ddelay);
  3828. sc = status_get_sc(dst);
  3829. if(sc && sc->count) {
  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. int clif_skill_damage2(struct block_list *src,struct block_list *dst,
  3903. 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. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_id,int heal,int fail)
  3955. {
  3956. unsigned char buf[32];
  3957. nullpo_retr(0, dst);
  3958. WBUFW(buf,0)=0x11a;
  3959. WBUFW(buf,2)=skill_id;
  3960. WBUFW(buf,4)=min(heal, SHRT_MAX);
  3961. WBUFL(buf,6)=dst->id;
  3962. WBUFL(buf,10)=src?src->id:0;
  3963. WBUFB(buf,14)=fail;
  3964. clif_send(buf,packet_len(0x11a),dst,AREA);
  3965. if (disguised(dst)) {
  3966. WBUFL(buf,6)=-dst->id;
  3967. clif_send(buf,packet_len(0x115),dst,SELF);
  3968. }
  3969. if(src && disguised(src)) {
  3970. WBUFL(buf,10)=-src->id;
  3971. if (disguised(dst))
  3972. WBUFL(buf,6)=dst->id;
  3973. clif_send(buf,packet_len(0x115),src,SELF);
  3974. }
  3975. return fail;
  3976. }
  3977. /*==========================================
  3978. * 場所スキルエフェクト
  3979. *------------------------------------------*/
  3980. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  3981. {
  3982. unsigned char buf[32];
  3983. nullpo_retr(0, src);
  3984. WBUFW(buf,0)=0x117;
  3985. WBUFW(buf,2)=skill_id;
  3986. WBUFL(buf,4)=src->id;
  3987. WBUFW(buf,8)=val;
  3988. WBUFW(buf,10)=x;
  3989. WBUFW(buf,12)=y;
  3990. WBUFL(buf,14)=tick;
  3991. clif_send(buf,packet_len(0x117),src,AREA);
  3992. if(disguised(src)) {
  3993. WBUFL(buf,4)=-src->id;
  3994. clif_send(buf,packet_len(0x117),src,SELF);
  3995. }
  3996. return 0;
  3997. }
  3998. /*==========================================
  3999. * 場所スキルエフェクト表示
  4000. *------------------------------------------*/
  4001. void clif_skill_setunit(struct skill_unit *unit)
  4002. {
  4003. unsigned char buf[128];
  4004. nullpo_retv(unit);
  4005. #if PACKETVER >= 3
  4006. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4007. WBUFW(buf, 0)=0x1c9;
  4008. WBUFL(buf, 2)=unit->bl.id;
  4009. WBUFL(buf, 6)=unit->group->src_id;
  4010. WBUFW(buf,10)=unit->bl.x;
  4011. WBUFW(buf,12)=unit->bl.y;
  4012. WBUFB(buf,14)=unit->group->unit_id;
  4013. WBUFB(buf,15)=1;
  4014. WBUFB(buf,16)=1;
  4015. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4016. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4017. return;
  4018. }
  4019. #endif
  4020. WBUFW(buf, 0)=0x11f;
  4021. WBUFL(buf, 2)=unit->bl.id;
  4022. WBUFL(buf, 6)=unit->group->src_id;
  4023. WBUFW(buf,10)=unit->bl.x;
  4024. WBUFW(buf,12)=unit->bl.y;
  4025. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  4026. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4027. else
  4028. WBUFB(buf,14)=unit->group->unit_id;
  4029. WBUFB(buf,15)=0;
  4030. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4031. }
  4032. /*==========================================
  4033. * 場所スキルエフェクト削除
  4034. *------------------------------------------*/
  4035. void clif_skill_delunit(struct skill_unit *unit)
  4036. {
  4037. unsigned char buf[16];
  4038. nullpo_retv(unit);
  4039. WBUFW(buf, 0)=0x120;
  4040. WBUFL(buf, 2)=unit->bl.id;
  4041. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4042. }
  4043. /*==========================================
  4044. * ワープ場所選択
  4045. *------------------------------------------*/
  4046. void clif_skill_warppoint(struct map_session_data* sd, int skill_num, int skill_lv, int map1, int map2, int map3, int map4)
  4047. {
  4048. int fd;
  4049. nullpo_retv(sd);
  4050. fd = sd->fd;
  4051. WFIFOHEAD(fd,packet_len(0x11c));
  4052. WFIFOW(fd,0) = 0x11c;
  4053. WFIFOW(fd,2) = skill_num;
  4054. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  4055. if (map1 == -1) strcpy((char*)WFIFOP(fd,4), "Random");
  4056. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  4057. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  4058. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  4059. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  4060. WFIFOSET(fd,packet_len(0x11c));
  4061. sd->menuskill_id = skill_num;
  4062. if (skill_num == AL_WARP)
  4063. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4064. else
  4065. sd->menuskill_val = skill_lv;
  4066. }
  4067. /*==========================================
  4068. * メモ応答
  4069. *------------------------------------------*/
  4070. int clif_skill_memo(struct map_session_data *sd,int flag)
  4071. {
  4072. int fd;
  4073. nullpo_retr(0, sd);
  4074. fd=sd->fd;
  4075. WFIFOHEAD(fd,packet_len(0x11e));
  4076. WFIFOW(fd,0)=0x11e;
  4077. WFIFOB(fd,2)=flag;
  4078. WFIFOSET(fd,packet_len(0x11e));
  4079. return 0;
  4080. }
  4081. int clif_skill_teleportmessage(struct map_session_data *sd,int flag)
  4082. {
  4083. int fd;
  4084. nullpo_retr(0, sd);
  4085. fd=sd->fd;
  4086. WFIFOHEAD(fd,packet_len(0x189));
  4087. WFIFOW(fd,0)=0x189;
  4088. WFIFOW(fd,2)=flag;
  4089. WFIFOSET(fd,packet_len(0x189));
  4090. return 0;
  4091. }
  4092. /*==========================================
  4093. * モンスター情報
  4094. *------------------------------------------*/
  4095. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4096. {
  4097. struct status_data *status;
  4098. unsigned char buf[64];
  4099. int i;//, fix;
  4100. nullpo_retr(0, sd);
  4101. nullpo_retr(0, dst);
  4102. if(dst->type!=BL_MOB )
  4103. return 0;
  4104. status = status_get_status_data(dst);
  4105. WBUFW(buf, 0)=0x18c;
  4106. WBUFW(buf, 2)=status_get_class(dst);
  4107. WBUFW(buf, 4)=status_get_lv(dst);
  4108. WBUFW(buf, 6)=status->size;
  4109. WBUFL(buf, 8)=status->hp;
  4110. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4111. +(battle_config.estimation_type&2?status->def2:0);
  4112. WBUFW(buf,14)=status->race;
  4113. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4114. +(battle_config.estimation_type&2?status->mdef2:0);
  4115. WBUFW(buf,18)= status->def_ele;
  4116. for(i=0;i<9;i++)
  4117. WBUFB(buf,20+i)= (unsigned char)battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv);
  4118. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4119. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4120. clif_send(buf,packet_len(0x18c),&sd->bl,
  4121. sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4122. return 0;
  4123. }
  4124. /*==========================================
  4125. * アイテム合成可能リスト
  4126. *------------------------------------------*/
  4127. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  4128. {
  4129. int i,c,view,fd;
  4130. nullpo_retr(0, sd);
  4131. if(sd->menuskill_id == AM_PHARMACY)
  4132. return 0; //Avoid resending the menu twice or more times...
  4133. fd=sd->fd;
  4134. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4135. WFIFOW(fd, 0)=0x18d;
  4136. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4137. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4138. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4139. WFIFOW(fd,c*8+ 4)= view;
  4140. else
  4141. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4142. WFIFOW(fd,c*8+ 6)= 0x0012;
  4143. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  4144. c++;
  4145. }
  4146. }
  4147. WFIFOW(fd, 2)=c*8+8;
  4148. WFIFOSET(fd,WFIFOW(fd,2));
  4149. if(c > 0) {
  4150. sd->menuskill_id = AM_PHARMACY;
  4151. sd->menuskill_val = trigger;
  4152. return 1;
  4153. }
  4154. return 0;
  4155. }
  4156. /*==========================================
  4157. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  4158. *------------------------------------------*/
  4159. int clif_status_load(struct block_list *bl,int type, int flag)
  4160. {
  4161. int fd;
  4162. if (type == SI_BLANK) //It shows nothing on the client...
  4163. return 0;
  4164. if (bl->type != BL_PC)
  4165. return 0;
  4166. fd = ((struct map_session_data*)bl)->fd;
  4167. WFIFOHEAD(fd,packet_len(0x196));
  4168. WFIFOW(fd,0)=0x0196;
  4169. WFIFOW(fd,2)=type;
  4170. WFIFOL(fd,4)=bl->id;
  4171. WFIFOB(fd,8)=flag; //Status start
  4172. WFIFOSET(fd, packet_len(0x196));
  4173. return 0;
  4174. }
  4175. /*==========================================
  4176. * 状態異常アイコン/メッセージ表示
  4177. *------------------------------------------*/
  4178. int clif_status_change(struct block_list *bl,int type,int flag)
  4179. {
  4180. unsigned char buf[16];
  4181. if (type == SI_BLANK) //It shows nothing on the client...
  4182. return 0;
  4183. nullpo_retr(0, bl);
  4184. WBUFW(buf,0)=0x0196;
  4185. WBUFW(buf,2)=type;
  4186. WBUFL(buf,4)=bl->id;
  4187. WBUFB(buf,8)=flag;
  4188. clif_send(buf,packet_len(0x196),bl,AREA);
  4189. return 0;
  4190. }
  4191. /*==========================================
  4192. * Send message (modified by [Yor])
  4193. *------------------------------------------*/
  4194. int clif_displaymessage(const int fd, const char* mes)
  4195. {
  4196. // invalid pointer?
  4197. nullpo_retr(-1, mes);
  4198. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4199. if (fd == 0)
  4200. return 0;
  4201. else {
  4202. int len_mes = strlen(mes);
  4203. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4204. WFIFOHEAD(fd, 5 + len_mes);
  4205. WFIFOW(fd,0) = 0x8e;
  4206. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  4207. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  4208. WFIFOSET(fd, 5 + len_mes);
  4209. }
  4210. }
  4211. return 0;
  4212. }
  4213. /*==========================================
  4214. * 天の声を送信する
  4215. *------------------------------------------*/
  4216. int clif_GMmessage(struct block_list* bl, const char* mes, int len, int flag)
  4217. {
  4218. unsigned char *buf;
  4219. int lp;
  4220. lp = (flag & 0x10) ? 8 : 4;
  4221. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  4222. WBUFW(buf,0) = 0x9a;
  4223. WBUFW(buf,2) = len + lp;
  4224. WBUFL(buf,4) = 0x65756c62; //"blue":
  4225. memcpy(WBUFP(buf,lp), mes, len);
  4226. flag &= 0x07;
  4227. clif_send(buf, WBUFW(buf,2), bl,
  4228. (flag == 1) ? ALL_SAMEMAP :
  4229. (flag == 2) ? AREA :
  4230. (flag == 3) ? SELF :
  4231. ALL_CLIENT);
  4232. if(buf) aFree(buf);
  4233. if(use_irc && irc_announce_flag && !flag)
  4234. irc_announce(mes);
  4235. return 0;
  4236. }
  4237. /*==========================================
  4238. * グローバルメッセージ
  4239. *------------------------------------------*/
  4240. void clif_GlobalMessage(struct block_list* bl, const char* message)
  4241. {
  4242. char buf[100];
  4243. int len;
  4244. nullpo_retv(bl);
  4245. if(!message)
  4246. return;
  4247. len = strlen(message)+1;
  4248. WBUFW(buf,0)=0x8d;
  4249. WBUFW(buf,2)=len+8;
  4250. WBUFL(buf,4)=bl->id;
  4251. strncpy((char *) WBUFP(buf,8),message,len);
  4252. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4253. }
  4254. /*==========================================
  4255. * Send main chat message [LuzZza]
  4256. *------------------------------------------*/
  4257. void clif_MainChatMessage(const char* message)
  4258. {
  4259. char buf[200];
  4260. int len;
  4261. if(!message)
  4262. return;
  4263. len = strlen(message)+1;
  4264. if (len+8 > sizeof(buf)) {
  4265. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4266. len = sizeof(buf)-8;
  4267. }
  4268. WBUFW(buf,0)=0x8d;
  4269. WBUFW(buf,2)=len+8;
  4270. WBUFL(buf,4)=0;
  4271. strncpy((char *) WBUFP(buf,8),message,len);
  4272. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4273. }
  4274. /*==========================================
  4275. * Does an announce message in the given color.
  4276. *------------------------------------------*/
  4277. int clif_announce(struct block_list* bl, const char* mes, int len, unsigned long color, int flag)
  4278. {
  4279. unsigned char *buf;
  4280. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4281. WBUFW(buf,0) = 0x1c3;
  4282. WBUFW(buf,2) = len + 16;
  4283. WBUFL(buf,4) = color;
  4284. WBUFW(buf,8) = 0x190; //Font style? Type?
  4285. WBUFW(buf,10) = 0x0c; //12? Font size?
  4286. WBUFL(buf,12) = 0; //Unknown!
  4287. memcpy(WBUFP(buf,16), mes, len);
  4288. flag &= 0x07;
  4289. clif_send(buf, WBUFW(buf,2), bl,
  4290. (flag == 1) ? ALL_SAMEMAP :
  4291. (flag == 2) ? AREA :
  4292. (flag == 3) ? SELF :
  4293. ALL_CLIENT);
  4294. if(buf) aFree(buf);
  4295. return 0;
  4296. }
  4297. /*==========================================
  4298. * HPSP回復エフェクトを送信する
  4299. *------------------------------------------*/
  4300. int clif_heal(int fd,int type,int val)
  4301. {
  4302. WFIFOHEAD(fd,packet_len(0x13d));
  4303. WFIFOW(fd,0)=0x13d;
  4304. WFIFOW(fd,2)=type;
  4305. WFIFOW(fd,4)=cap_value(val,0,SHRT_MAX);
  4306. WFIFOSET(fd,packet_len(0x13d));
  4307. return 0;
  4308. }
  4309. /*==========================================
  4310. * 復活する
  4311. *------------------------------------------*/
  4312. int clif_resurrection(struct block_list *bl,int type)
  4313. {
  4314. unsigned char buf[16];
  4315. nullpo_retr(0, bl);
  4316. WBUFW(buf,0)=0x148;
  4317. WBUFL(buf,2)=bl->id;
  4318. WBUFW(buf,6)=type;
  4319. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4320. if (disguised(bl))
  4321. clif_spawn(bl);
  4322. return 0;
  4323. }
  4324. /*==========================================
  4325. * PVP実装?(仮)
  4326. *------------------------------------------*/
  4327. int clif_set0199(int fd,int type)
  4328. {
  4329. WFIFOHEAD(fd,packet_len(0x199));
  4330. WFIFOW(fd,0)=0x199;
  4331. WFIFOW(fd,2)=type;
  4332. WFIFOSET(fd,packet_len(0x199));
  4333. return 0;
  4334. }
  4335. /*==========================================
  4336. * PVP実装?(仮)
  4337. *------------------------------------------*/
  4338. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4339. {
  4340. int fd = sd->fd;
  4341. if(type == 2) {
  4342. WFIFOHEAD(fd,packet_len(0x19a));
  4343. WFIFOW(fd,0) = 0x19a;
  4344. WFIFOL(fd,2) = sd->bl.id;
  4345. WFIFOL(fd,6) = pvprank;
  4346. WFIFOL(fd,10) = pvpnum;
  4347. WFIFOSET(fd,packet_len(0x19a));
  4348. } else {
  4349. unsigned char buf[32];
  4350. WBUFW(buf,0) = 0x19a;
  4351. WBUFL(buf,2) = sd->bl.id;
  4352. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4353. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4354. else
  4355. WBUFL(buf,6) = pvprank;
  4356. WBUFL(buf,10) = pvpnum;
  4357. if(sd->sc.option&OPTION_INVISIBLE)
  4358. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4359. else if(!type)
  4360. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4361. else
  4362. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4363. }
  4364. return 0;
  4365. }
  4366. /*==========================================
  4367. *
  4368. *------------------------------------------*/
  4369. int clif_send0199(int map,int type)
  4370. {
  4371. struct block_list bl;
  4372. unsigned char buf[16];
  4373. bl.id = 0;
  4374. bl.type = BL_NUL;
  4375. bl.m = map;
  4376. WBUFW(buf,0)=0x199;
  4377. WBUFW(buf,2)=type;
  4378. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4379. return 0;
  4380. }
  4381. /*==========================================
  4382. * 精錬エフェクトを送信する
  4383. *------------------------------------------*/
  4384. void clif_refine(int fd, int fail, int index, int val)
  4385. {
  4386. WFIFOHEAD(fd,packet_len(0x188));
  4387. WFIFOW(fd,0)=0x188;
  4388. WFIFOW(fd,2)=fail;
  4389. WFIFOW(fd,4)=index+2;
  4390. WFIFOW(fd,6)=val;
  4391. WFIFOSET(fd,packet_len(0x188));
  4392. }
  4393. /// result=0: "weapon upgrated: %s" MsgStringTable[911] in rgb(0,255,255)
  4394. /// result=1: "weapon upgrated: %s" MsgStringTable[912] in rgb(0,205,205)
  4395. /// result=2: "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4396. /// result=3: "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4397. void clif_upgrademessage(int fd, int result, int item_id)
  4398. {
  4399. WFIFOHEAD(fd,packet_len(0x223));
  4400. WFIFOW(fd,0)=0x223;
  4401. WFIFOL(fd,2)=result;
  4402. WFIFOW(fd,6)=item_id;
  4403. WFIFOSET(fd,packet_len(0x223));
  4404. }
  4405. /*==========================================
  4406. * Wisp/page is transmitted to the destination player
  4407. *------------------------------------------*/
  4408. int clif_wis_message(int fd, const char* nick, const char* mes, int mes_len) // R 0097 <len>.w <nick>.24B <message>.?B
  4409. {
  4410. // printf("clif_wis_message(%d, %s, %s)\n", fd, nick, mes);
  4411. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4412. WFIFOW(fd,0) = 0x97;
  4413. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4414. memcpy(WFIFOP(fd,4), nick, NAME_LENGTH);
  4415. memcpy(WFIFOP(fd,28), mes, mes_len);
  4416. WFIFOSET(fd,WFIFOW(fd,2));
  4417. return 0;
  4418. }
  4419. /*==========================================
  4420. * Inform the player about the result of his whisper action
  4421. * R 0098 <type>.B
  4422. * 0: success to send wisper
  4423. * 1: target character is not loged in
  4424. * 2: ignored by target
  4425. * 3: everyone ignored by target
  4426. *------------------------------------------*/
  4427. int clif_wis_end(int fd, int flag)
  4428. {
  4429. WFIFOHEAD(fd,packet_len(0x98));
  4430. WFIFOW(fd,0) = 0x98;
  4431. WFIFOW(fd,2) = flag;
  4432. WFIFOSET(fd,packet_len(0x98));
  4433. return 0;
  4434. }
  4435. /*==========================================
  4436. * キャラID名前引き結果を送信する
  4437. *------------------------------------------*/
  4438. int clif_solved_charname(int fd, int charid, const char* name)
  4439. {
  4440. WFIFOHEAD(fd,packet_len(0x194));
  4441. WFIFOW(fd,0)=0x194;
  4442. WFIFOL(fd,2)=charid;
  4443. safestrncpy(WFIFOP(fd,6), name, NAME_LENGTH);
  4444. WFIFOSET(fd,packet_len(0x194));
  4445. return 0;
  4446. }
  4447. /*==========================================
  4448. * カードの挿入可能リストを返す
  4449. *------------------------------------------*/
  4450. int clif_use_card(struct map_session_data *sd,int idx)
  4451. {
  4452. int i,c,ep;
  4453. int fd=sd->fd;
  4454. nullpo_retr(0, sd);
  4455. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4456. return 0;
  4457. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4458. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4459. ep=sd->inventory_data[idx]->equip;
  4460. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4461. WFIFOW(fd,0)=0x017b;
  4462. for(i=c=0;i<MAX_INVENTORY;i++){
  4463. int j;
  4464. if(sd->inventory_data[i] == NULL)
  4465. continue;
  4466. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4467. continue;
  4468. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4469. continue;
  4470. if(sd->status.inventory[i].identify==0 ) //Not identified
  4471. continue;
  4472. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4473. continue;
  4474. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_HAND_L) //Shield card won't go on left weapon.
  4475. continue;
  4476. for(j=0;j<sd->inventory_data[i]->slot;j++){
  4477. if( sd->status.inventory[i].card[j]==0 )
  4478. break;
  4479. }
  4480. if(j==sd->inventory_data[i]->slot) // No room
  4481. continue;
  4482. WFIFOW(fd,4+c*2)=i+2;
  4483. c++;
  4484. }
  4485. WFIFOW(fd,2)=4+c*2;
  4486. WFIFOSET(fd,WFIFOW(fd,2));
  4487. return 0;
  4488. }
  4489. /*==========================================
  4490. * カードの挿入終了
  4491. *------------------------------------------*/
  4492. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4493. {
  4494. int fd;
  4495. nullpo_retr(0, sd);
  4496. fd=sd->fd;
  4497. WFIFOHEAD(fd,packet_len(0x17d));
  4498. WFIFOW(fd,0)=0x17d;
  4499. WFIFOW(fd,2)=idx_equip+2;
  4500. WFIFOW(fd,4)=idx_card+2;
  4501. WFIFOB(fd,6)=flag;
  4502. WFIFOSET(fd,packet_len(0x17d));
  4503. return 0;
  4504. }
  4505. /*==========================================
  4506. * 鑑定可能アイテムリスト送信
  4507. *------------------------------------------*/
  4508. int clif_item_identify_list(struct map_session_data *sd)
  4509. {
  4510. int i,c;
  4511. int fd;
  4512. nullpo_retr(0, sd);
  4513. fd=sd->fd;
  4514. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4515. WFIFOW(fd,0)=0x177;
  4516. for(i=c=0;i<MAX_INVENTORY;i++){
  4517. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4518. WFIFOW(fd,c*2+4)=i+2;
  4519. c++;
  4520. }
  4521. }
  4522. if(c > 0) {
  4523. WFIFOW(fd,2)=c*2+4;
  4524. WFIFOSET(fd,WFIFOW(fd,2));
  4525. sd->menuskill_id = MC_IDENTIFY;
  4526. sd->menuskill_val = c;
  4527. }
  4528. return 0;
  4529. }
  4530. /*==========================================
  4531. * 鑑定結果
  4532. *------------------------------------------*/
  4533. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4534. {
  4535. int fd;
  4536. nullpo_retr(0, sd);
  4537. fd=sd->fd;
  4538. WFIFOHEAD(fd,packet_len(0x179));
  4539. WFIFOW(fd, 0)=0x179;
  4540. WFIFOW(fd, 2)=idx+2;
  4541. WFIFOB(fd, 4)=flag;
  4542. WFIFOSET(fd,packet_len(0x179));
  4543. return 0;
  4544. }
  4545. /*==========================================
  4546. * 修理可能アイテムリスト送信
  4547. *------------------------------------------*/
  4548. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4549. {
  4550. int i,c;
  4551. int fd;
  4552. int nameid;
  4553. nullpo_retr(0, sd);
  4554. nullpo_retr(0, dstsd);
  4555. fd=sd->fd;
  4556. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4557. WFIFOW(fd,0)=0x1fc;
  4558. for(i=c=0;i<MAX_INVENTORY;i++){
  4559. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4560. WFIFOW(fd,c*13+4) = i;
  4561. WFIFOW(fd,c*13+6) = nameid;
  4562. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4563. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4564. WFIFOB(fd,c*13+16)= c;
  4565. c++;
  4566. }
  4567. }
  4568. if(c > 0) {
  4569. WFIFOW(fd,2)=c*13+4;
  4570. WFIFOSET(fd,WFIFOW(fd,2));
  4571. sd->menuskill_id = BS_REPAIRWEAPON;
  4572. sd->menuskill_val = dstsd->bl.id;
  4573. }else
  4574. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4575. return 0;
  4576. }
  4577. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4578. {
  4579. int view,fd;
  4580. nullpo_retr(0, sd);
  4581. fd=sd->fd;
  4582. WFIFOHEAD(fd,packet_len(0x1fe));
  4583. WFIFOW(fd, 0)=0x1fe;
  4584. if((view = itemdb_viewid(nameid)) > 0)
  4585. WFIFOW(fd, 2)=view;
  4586. else
  4587. WFIFOW(fd, 2)=nameid;
  4588. WFIFOB(fd, 4)=flag;
  4589. WFIFOSET(fd,packet_len(0x1fe));
  4590. return 0;
  4591. }
  4592. /*==========================================
  4593. * Weapon Refining - Taken from jAthena
  4594. *------------------------------------------*/
  4595. int clif_item_refine_list(struct map_session_data *sd)
  4596. {
  4597. int i,c;
  4598. int fd;
  4599. int skilllv;
  4600. int wlv;
  4601. int refine_item[5];
  4602. nullpo_retr(0, sd);
  4603. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4604. fd=sd->fd;
  4605. refine_item[0] = -1;
  4606. refine_item[1] = pc_search_inventory(sd,1010);
  4607. refine_item[2] = pc_search_inventory(sd,1011);
  4608. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4609. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4610. WFIFOW(fd,0)=0x221;
  4611. for(i=c=0;i<MAX_INVENTORY;i++){
  4612. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4613. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4614. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4615. WFIFOW(fd,c*13+ 4)=i+2;
  4616. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4617. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4618. WFIFOW(fd,c*13+10)=0;
  4619. WFIFOB(fd,c*13+12)=c;
  4620. c++;
  4621. }
  4622. }
  4623. WFIFOW(fd,2)=c*13+4;
  4624. WFIFOSET(fd,WFIFOW(fd,2));
  4625. if (c > 0) {
  4626. sd->menuskill_id = WS_WEAPONREFINE;
  4627. sd->menuskill_val = skilllv;
  4628. }
  4629. return 0;
  4630. }
  4631. /*==========================================
  4632. * アイテムによる一時的なスキル効果
  4633. *------------------------------------------*/
  4634. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  4635. {
  4636. int fd;
  4637. nullpo_retr(0, sd);
  4638. fd=sd->fd;
  4639. WFIFOHEAD(fd,packet_len(0x147));
  4640. WFIFOW(fd, 0)=0x147;
  4641. WFIFOW(fd, 2)=skillid;
  4642. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4643. WFIFOW(fd, 6)=0;
  4644. WFIFOW(fd, 8)=skilllv;
  4645. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4646. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4647. strncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  4648. WFIFOB(fd,38)=0;
  4649. WFIFOSET(fd,packet_len(0x147));
  4650. return 0;
  4651. }
  4652. /*==========================================
  4653. * カートにアイテム追加
  4654. *------------------------------------------*/
  4655. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4656. {
  4657. int view,fd;
  4658. unsigned char *buf;
  4659. nullpo_retr(0, sd);
  4660. fd=sd->fd;
  4661. WFIFOHEAD(fd,packet_len(0x124));
  4662. buf=WFIFOP(fd,0);
  4663. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4664. return 1;
  4665. WBUFW(buf,0)=0x124;
  4666. WBUFW(buf,2)=n+2;
  4667. WBUFL(buf,4)=amount;
  4668. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4669. WBUFW(buf,8)=view;
  4670. else
  4671. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4672. WBUFB(buf,10)=sd->status.cart[n].identify;
  4673. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4674. WBUFB(buf,12)=sd->status.cart[n].refine;
  4675. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4676. WFIFOSET(fd,packet_len(0x124));
  4677. return 0;
  4678. }
  4679. /*==========================================
  4680. * カートからアイテム削除
  4681. *------------------------------------------*/
  4682. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4683. {
  4684. int fd;
  4685. nullpo_retr(0, sd);
  4686. fd=sd->fd;
  4687. WFIFOHEAD(fd,packet_len(0x125));
  4688. WFIFOW(fd,0)=0x125;
  4689. WFIFOW(fd,2)=n+2;
  4690. WFIFOL(fd,4)=amount;
  4691. WFIFOSET(fd,packet_len(0x125));
  4692. return 0;
  4693. }
  4694. /*==========================================
  4695. * Opens the shop creation menu.
  4696. * R 012d <num>.w
  4697. * 'num' is the number of allowed item slots
  4698. *------------------------------------------*/
  4699. void clif_openvendingreq(struct map_session_data* sd, int num)
  4700. {
  4701. int fd;
  4702. nullpo_retv(sd);
  4703. fd = sd->fd;
  4704. WFIFOHEAD(fd,packet_len(0x12d));
  4705. WFIFOW(fd,0) = 0x12d;
  4706. WFIFOW(fd,2) = num;
  4707. WFIFOSET(fd,packet_len(0x12d));
  4708. }
  4709. /*==========================================
  4710. * Displays a vending board to target/area
  4711. * R 0131 <ID>.l <message>.80B
  4712. *------------------------------------------*/
  4713. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  4714. {
  4715. unsigned char buf[128];
  4716. nullpo_retv(bl);
  4717. WBUFW(buf,0) = 0x131;
  4718. WBUFL(buf,2) = bl->id;
  4719. safestrncpy((char*)WBUFP(buf,6), message, 80);
  4720. if( fd ) {
  4721. WFIFOHEAD(fd,packet_len(0x131));
  4722. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  4723. WFIFOSET(fd,packet_len(0x131));
  4724. } else {
  4725. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  4726. }
  4727. }
  4728. /*==========================================
  4729. * Removes a vending board from screen
  4730. *------------------------------------------*/
  4731. void clif_closevendingboard(struct block_list* bl, int fd)
  4732. {
  4733. unsigned char buf[16];
  4734. nullpo_retv(bl);
  4735. WBUFW(buf,0) = 0x132;
  4736. WBUFL(buf,2) = bl->id;
  4737. if( fd ) {
  4738. WFIFOHEAD(fd,packet_len(0x132));
  4739. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  4740. WFIFOSET(fd,packet_len(0x132));
  4741. } else {
  4742. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  4743. }
  4744. }
  4745. /*==========================================
  4746. * Sends a list of items in a shop
  4747. * 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
  4748. *------------------------------------------*/
  4749. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  4750. {
  4751. int i,fd;
  4752. int count;
  4753. struct map_session_data* vsd;
  4754. nullpo_retv(sd);
  4755. nullpo_retv(vending);
  4756. nullpo_retv(vsd=map_id2sd(id));
  4757. fd = sd->fd;
  4758. count = vsd->vend_num;
  4759. WFIFOHEAD(fd, 8+count*22);
  4760. WFIFOW(fd,0) = 0x133;
  4761. WFIFOW(fd,2) = 8+count*22;
  4762. WFIFOL(fd,4) = id;
  4763. for( i = 0; i < count; i++ )
  4764. {
  4765. int index = vending[i].index;
  4766. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  4767. WFIFOL(fd, 8+i*22) = vending[i].value;
  4768. WFIFOW(fd,12+i*22) = vending[i].amount;
  4769. WFIFOW(fd,14+i*22) = vending[i].index + 2;
  4770. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4771. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  4772. WFIFOB(fd,19+i*22) = vsd->status.cart[index].identify;
  4773. WFIFOB(fd,20+i*22) = vsd->status.cart[index].attribute;
  4774. WFIFOB(fd,21+i*22) = vsd->status.cart[index].refine;
  4775. clif_addcards(WFIFOP(fd, 22+i*22), &vsd->status.cart[index]);
  4776. }
  4777. WFIFOSET(fd,WFIFOW(fd,2));
  4778. }
  4779. /*==========================================
  4780. * Shop purchase failure
  4781. * R 0135 <index>.w <amount>.w <fail>.B
  4782. * fail=1 - not enough zeny
  4783. * fail=2 - overweight
  4784. * fail=4 - out of stock
  4785. * fail=5 - "cannot use an npc shop while in a trade"
  4786. *------------------------------------------*/
  4787. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  4788. {
  4789. int fd;
  4790. nullpo_retv(sd);
  4791. fd = sd->fd;
  4792. WFIFOHEAD(fd,packet_len(0x135));
  4793. WFIFOW(fd,0) = 0x135;
  4794. WFIFOW(fd,2) = index+2;
  4795. WFIFOW(fd,4) = amount;
  4796. WFIFOB(fd,6) = fail;
  4797. WFIFOSET(fd,packet_len(0x135));
  4798. }
  4799. /*==========================================
  4800. * Shop creation success
  4801. * 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*
  4802. *------------------------------------------*/
  4803. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  4804. {
  4805. int i,fd;
  4806. int count;
  4807. nullpo_retv(sd);
  4808. fd = sd->fd;
  4809. count = sd->vend_num;
  4810. WFIFOHEAD(fd, 8+count*22);
  4811. WFIFOW(fd,0) = 0x136;
  4812. WFIFOW(fd,2) = 8+count*22;
  4813. WFIFOL(fd,4) = id;
  4814. for( i = 0; i < count; i++ )
  4815. {
  4816. int index = vending[i].index;
  4817. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  4818. WFIFOL(fd, 8+i*22) = vending[i].value;
  4819. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  4820. WFIFOW(fd,14+i*22) = vending[i].amount;
  4821. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4822. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  4823. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  4824. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  4825. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  4826. clif_addcards(WFIFOP(fd,22+count*22), &sd->status.cart[index]);
  4827. }
  4828. WFIFOSET(fd,WFIFOW(fd,2));
  4829. }
  4830. /*==========================================
  4831. * Inform merchant that someone has bought an item.
  4832. * R 0137 <index>.w <amount>.w
  4833. *------------------------------------------*/
  4834. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  4835. {
  4836. int fd;
  4837. nullpo_retv(sd);
  4838. fd = sd->fd;
  4839. WFIFOHEAD(fd,packet_len(0x137));
  4840. WFIFOW(fd,0) = 0x137;
  4841. WFIFOW(fd,2) = index+2;
  4842. WFIFOW(fd,4) = amount;
  4843. WFIFOSET(fd,packet_len(0x137));
  4844. }
  4845. /*==========================================
  4846. * パーティ作成完了
  4847. *------------------------------------------*/
  4848. int clif_party_created(struct map_session_data *sd,int flag)
  4849. {
  4850. int fd;
  4851. nullpo_retr(0, sd);
  4852. fd=sd->fd;
  4853. WFIFOHEAD(fd,packet_len(0xfa));
  4854. WFIFOW(fd,0)=0xfa;
  4855. WFIFOB(fd,2)=flag;
  4856. WFIFOSET(fd,packet_len(0xfa));
  4857. return 0;
  4858. }
  4859. int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  4860. {
  4861. unsigned char buf[96];
  4862. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  4863. int i;
  4864. for (i=0; i<MAX_PARTY && !p->data[i].sd; i++);
  4865. if (i >= MAX_PARTY) return 0; //Should never happen...
  4866. sd = p->data[i].sd;
  4867. }
  4868. WBUFW(buf, 0) = 0x1e9;
  4869. WBUFL(buf, 2) = sd->status.account_id;
  4870. WBUFL(buf, 6) = 0; //Apparently setting this to 1 makes you adoptable.
  4871. WBUFW(buf,10) = sd->bl.x;
  4872. WBUFW(buf,12) = sd->bl.y;
  4873. WBUFB(buf,14) = 0; //Unconfirmed byte, could be online/offline.
  4874. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  4875. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  4876. mapindex_getmapname_ext(mapindex_id2name(sd->mapindex), (char*)WBUFP(buf,63));
  4877. WBUFB(buf,79) = (p->party.item&1)?1:0;
  4878. WBUFB(buf,80) = (p->party.item&2)?1:0;
  4879. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  4880. return 1;
  4881. }
  4882. /*==========================================
  4883. * Sends party information
  4884. * R 00fb <len>.w <party name>.24B {<ID>.l <nick>.24B <map name>.16B <leader>.B <offline>.B}.46B*
  4885. *------------------------------------------*/
  4886. int clif_party_info(struct party_data* p, struct map_session_data *sd)
  4887. {
  4888. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  4889. struct map_session_data* party_sd = NULL;
  4890. int i, c;
  4891. nullpo_retr(0, p);
  4892. WBUFW(buf,0) = 0xfb;
  4893. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  4894. for(i = 0, c = 0; i < MAX_PARTY; i++)
  4895. {
  4896. struct party_member* m = &p->party.member[i];
  4897. if(!m->account_id) continue;
  4898. if(party_sd == NULL) party_sd = p->data[i].sd;
  4899. WBUFL(buf,28+c*46) = m->account_id;
  4900. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  4901. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  4902. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  4903. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  4904. c++;
  4905. }
  4906. WBUFW(buf,2) = 28+c*46;
  4907. if(sd) { // send only to self
  4908. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  4909. } else if (party_sd) { // send to whole party
  4910. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  4911. }
  4912. return 0;
  4913. }
  4914. /*==========================================
  4915. * パーティ勧誘
  4916. *------------------------------------------*/
  4917. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  4918. {
  4919. int fd;
  4920. struct party_data *p;
  4921. nullpo_retr(0, sd);
  4922. nullpo_retr(0, tsd);
  4923. fd=tsd->fd;
  4924. if( (p=party_search(sd->status.party_id))==NULL )
  4925. return 0;
  4926. WFIFOHEAD(fd,packet_len(0xfe));
  4927. WFIFOW(fd,0)=0xfe;
  4928. WFIFOL(fd,2)=sd->status.account_id;
  4929. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  4930. WFIFOSET(fd,packet_len(0xfe));
  4931. return 0;
  4932. }
  4933. /*==========================================
  4934. * Party invitation result. Flag values are:
  4935. * 0 -> char is already in a party
  4936. * 1 -> party invite was rejected
  4937. * 2 -> party invite was accepted
  4938. * 3 -> party is full
  4939. * 4 -> char of the same account already joined the party
  4940. *------------------------------------------*/
  4941. int clif_party_inviteack(struct map_session_data* sd, const char* nick, int flag)
  4942. {
  4943. int fd;
  4944. nullpo_retr(0, sd);
  4945. fd=sd->fd;
  4946. WFIFOHEAD(fd,packet_len(0xfd));
  4947. WFIFOW(fd,0)=0xfd;
  4948. memcpy(WFIFOP(fd,2),nick,NAME_LENGTH);
  4949. WFIFOB(fd,26)=flag;
  4950. WFIFOSET(fd,packet_len(0xfd));
  4951. return 0;
  4952. }
  4953. /*==========================================
  4954. * パーティ設定送信
  4955. * flag & 0x001=exp変更ミス
  4956. * 0x010=item変更ミス
  4957. * 0x100=一人にのみ送信
  4958. *------------------------------------------*/
  4959. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  4960. {
  4961. unsigned char buf[16];
  4962. nullpo_retr(0, p);
  4963. if(!sd && flag==0){
  4964. int i;
  4965. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4966. if (i < MAX_PARTY)
  4967. sd = p->data[i].sd;
  4968. }
  4969. if(!sd) return 0;
  4970. WBUFW(buf,0)=0x101;
  4971. // WBUFL(buf,2) // that's how the client reads it, still need to check it's uses [FlavioJS]
  4972. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  4973. WBUFW(buf,4)=0;
  4974. if(flag==0)
  4975. clif_send(buf,packet_len(0x101),&sd->bl,PARTY);
  4976. else
  4977. clif_send(buf,packet_len(0x101),&sd->bl,SELF);
  4978. return 0;
  4979. }
  4980. /*==========================================
  4981. * パーティ脱退(脱退前に呼ぶこと)
  4982. *------------------------------------------*/
  4983. int clif_party_leaved(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  4984. {
  4985. unsigned char buf[64];
  4986. int i;
  4987. nullpo_retr(0, p);
  4988. if(!sd && (flag&0xf0)==0)
  4989. {
  4990. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4991. if (i < MAX_PARTY)
  4992. sd = p->data[i].sd;
  4993. }
  4994. if(!sd) return 0;
  4995. WBUFW(buf,0)=0x105;
  4996. WBUFL(buf,2)=account_id;
  4997. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  4998. WBUFB(buf,30)=flag&0x0f;
  4999. if((flag&0xf0)==0)
  5000. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  5001. else
  5002. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  5003. return 0;
  5004. }
  5005. /*==========================================
  5006. * パーティメッセージ送信
  5007. *------------------------------------------*/
  5008. int clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  5009. {
  5010. struct map_session_data *sd;
  5011. int i;
  5012. nullpo_retr(0, p);
  5013. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  5014. if(i < MAX_PARTY){
  5015. unsigned char buf[1024];
  5016. sd = p->data[i].sd;
  5017. WBUFW(buf,0)=0x109;
  5018. WBUFW(buf,2)=len+8;
  5019. WBUFL(buf,4)=account_id;
  5020. memcpy(WBUFP(buf,8),mes,len);
  5021. clif_send(buf,len+8,&sd->bl,PARTY);
  5022. }
  5023. return 0;
  5024. }
  5025. /*==========================================
  5026. * パーティ座標通知
  5027. *------------------------------------------*/
  5028. int clif_party_xy(struct map_session_data *sd)
  5029. {
  5030. unsigned char buf[16];
  5031. nullpo_retr(0, sd);
  5032. WBUFW(buf,0)=0x107;
  5033. WBUFL(buf,2)=sd->status.account_id;
  5034. WBUFW(buf,6)=sd->bl.x;
  5035. WBUFW(buf,8)=sd->bl.y;
  5036. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  5037. return 0;
  5038. }
  5039. /*==========================================
  5040. * Sends x/y dot to a single fd. [Skotlex]
  5041. *------------------------------------------*/
  5042. int clif_party_xy_single(int fd, struct map_session_data *sd)
  5043. {
  5044. WFIFOHEAD(fd,packet_len(0x107));
  5045. WFIFOW(fd,0)=0x107;
  5046. WFIFOL(fd,2)=sd->status.account_id;
  5047. WFIFOW(fd,6)=sd->bl.x;
  5048. WFIFOW(fd,8)=sd->bl.y;
  5049. WFIFOSET(fd,packet_len(0x107));
  5050. return 0;
  5051. }
  5052. /*==========================================
  5053. * パーティHP通知
  5054. *------------------------------------------*/
  5055. int clif_party_hp(struct map_session_data *sd)
  5056. {
  5057. unsigned char buf[16];
  5058. nullpo_retr(0, sd);
  5059. WBUFW(buf,0)=0x106;
  5060. WBUFL(buf,2)=sd->status.account_id;
  5061. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5062. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5063. WBUFW(buf,8) = 100;
  5064. } else {
  5065. WBUFW(buf,6) = sd->battle_status.hp;
  5066. WBUFW(buf,8) = sd->battle_status.max_hp;
  5067. }
  5068. clif_send(buf,packet_len(0x106),&sd->bl,PARTY_AREA_WOS);
  5069. return 0;
  5070. }
  5071. /*==========================================
  5072. * Sends HP bar to a single fd. [Skotlex]
  5073. *------------------------------------------*/
  5074. static void clif_hpmeter_single(int fd, struct map_session_data *sd)
  5075. {
  5076. WFIFOHEAD(fd,packet_len(0x106));
  5077. WFIFOW(fd,0) = 0x106;
  5078. WFIFOL(fd,2) = sd->status.account_id;
  5079. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5080. WFIFOW(fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5081. WFIFOW(fd,8) = 100;
  5082. } else {
  5083. WFIFOW(fd,6) = sd->battle_status.hp;
  5084. WFIFOW(fd,8) = sd->battle_status.max_hp;
  5085. }
  5086. WFIFOSET (fd, packet_len(0x106));
  5087. }
  5088. /*==========================================
  5089. * GMへ場所とHP通知
  5090. *------------------------------------------*/
  5091. int clif_hpmeter(struct map_session_data *sd)
  5092. {
  5093. struct map_session_data *sd2;
  5094. unsigned char buf[16];
  5095. int i, x0, y0, x1, y1;
  5096. int level;
  5097. nullpo_retr(0, sd);
  5098. x0 = sd->bl.x - AREA_SIZE;
  5099. y0 = sd->bl.y - AREA_SIZE;
  5100. x1 = sd->bl.x + AREA_SIZE;
  5101. y1 = sd->bl.y + AREA_SIZE;
  5102. WBUFW(buf,0) = 0x106;
  5103. WBUFL(buf,2) = sd->status.account_id;
  5104. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5105. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5106. WBUFW(buf,8) = 100;
  5107. } else {
  5108. WBUFW(buf,6) = sd->battle_status.hp;
  5109. WBUFW(buf,8) = sd->battle_status.max_hp;
  5110. }
  5111. for (i = 0; i < fd_max; i++) {
  5112. if (session[i] && session[i]->func_parse == clif_parse &&
  5113. (sd2 = (struct map_session_data*)session[i]->session_data) &&
  5114. sd != sd2 && sd2->state.auth) {
  5115. if (sd2->bl.m != sd->bl.m ||
  5116. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  5117. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  5118. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  5119. level < pc_isGM(sd))
  5120. continue;
  5121. WFIFOHEAD (i, packet_len(0x106));
  5122. memcpy (WFIFOP(i,0), buf, packet_len(0x106));
  5123. WFIFOSET (i, packet_len(0x106));
  5124. }
  5125. }
  5126. return 0;
  5127. }
  5128. /*==========================================
  5129. * パーティ場所移動(未使用)
  5130. *------------------------------------------*/
  5131. void clif_party_move(struct party* p, struct map_session_data* sd, int online)
  5132. {
  5133. unsigned char buf[128];
  5134. nullpo_retv(sd);
  5135. nullpo_retv(p);
  5136. WBUFW(buf, 0) = 0x104;
  5137. WBUFL(buf, 2) = sd->status.account_id;
  5138. WBUFL(buf, 6) = 0;
  5139. WBUFW(buf,10) = sd->bl.x;
  5140. WBUFW(buf,12) = sd->bl.y;
  5141. WBUFB(buf,14) = !online;
  5142. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  5143. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  5144. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  5145. clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
  5146. }
  5147. /*==========================================
  5148. * 攻撃するために移動が必要
  5149. *------------------------------------------*/
  5150. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5151. {
  5152. int fd;
  5153. nullpo_retr(0, sd);
  5154. nullpo_retr(0, bl);
  5155. fd=sd->fd;
  5156. WFIFOHEAD(fd,packet_len(0x139));
  5157. WFIFOW(fd, 0)=0x139;
  5158. WFIFOL(fd, 2)=bl->id;
  5159. WFIFOW(fd, 6)=bl->x;
  5160. WFIFOW(fd, 8)=bl->y;
  5161. WFIFOW(fd,10)=sd->bl.x;
  5162. WFIFOW(fd,12)=sd->bl.y;
  5163. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5164. WFIFOSET(fd,packet_len(0x139));
  5165. return 0;
  5166. }
  5167. /*==========================================
  5168. * 製造エフェクト
  5169. *------------------------------------------*/
  5170. int clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  5171. {
  5172. int fd;
  5173. nullpo_retr(0, sd);
  5174. fd = sd->fd;
  5175. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  5176. WFIFOHEAD(fd,packet_len(0x18f));
  5177. WFIFOW(fd, 0)=0x18f;
  5178. WFIFOW(fd, 2)=flag;
  5179. WFIFOW(fd, 4)=(itemdb_viewid(nameid)||nameid);
  5180. WFIFOSET(fd,packet_len(0x18f));
  5181. return 0;
  5182. }
  5183. // pet
  5184. int clif_catch_process(struct map_session_data *sd)
  5185. {
  5186. int fd;
  5187. nullpo_retr(0, sd);
  5188. fd=sd->fd;
  5189. WFIFOHEAD(fd,packet_len(0x19e));
  5190. WFIFOW(fd,0)=0x19e;
  5191. WFIFOSET(fd,packet_len(0x19e));
  5192. return 0;
  5193. }
  5194. int clif_pet_roulette(struct map_session_data *sd,int data)
  5195. {
  5196. int fd;
  5197. nullpo_retr(0, sd);
  5198. fd=sd->fd;
  5199. WFIFOHEAD(fd,packet_len(0x1a0));
  5200. WFIFOW(fd,0)=0x1a0;
  5201. WFIFOB(fd,2)=data;
  5202. WFIFOSET(fd,packet_len(0x1a0));
  5203. return 0;
  5204. }
  5205. /*==========================================
  5206. * pet卵リスト作成
  5207. *------------------------------------------*/
  5208. int clif_sendegg(struct map_session_data *sd)
  5209. {
  5210. //R 01a6 <len>.w <index>.w*
  5211. int i,n=0,fd;
  5212. nullpo_retr(0, sd);
  5213. fd=sd->fd;
  5214. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5215. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5216. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5217. return 0;
  5218. }
  5219. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5220. WFIFOW(fd,0)=0x1a6;
  5221. if(sd->status.pet_id <= 0) {
  5222. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5223. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5224. sd->inventory_data[i]->type!=IT_PETEGG ||
  5225. sd->status.inventory[i].amount<=0)
  5226. continue;
  5227. WFIFOW(fd,n*2+4)=i+2;
  5228. n++;
  5229. }
  5230. }
  5231. WFIFOW(fd,2)=4+n*2;
  5232. WFIFOSET(fd,WFIFOW(fd,2));
  5233. sd->menuskill_id = SA_TAMINGMONSTER;
  5234. sd->menuskill_val = -1;
  5235. return 0;
  5236. }
  5237. /*==========================================
  5238. * Sends a specific pet data update.
  5239. * type = 0 -> param = 0 (initial data)
  5240. * type = 1 -> param = intimacy value
  5241. * type = 2 -> param = hungry value
  5242. * type = 3 -> param = accessory id
  5243. * type = 4 -> param = performance number (1-3:normal, 4:special)
  5244. * type = 5 -> param = hairstyle number
  5245. * If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5246. *------------------------------------------*/
  5247. int clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5248. {
  5249. uint8 buf[16];
  5250. nullpo_retr(0, pd);
  5251. WBUFW(buf,0) = 0x1a4;
  5252. WBUFB(buf,2) = type;
  5253. WBUFL(buf,3) = pd->bl.id;
  5254. WBUFL(buf,7) = param;
  5255. if (sd)
  5256. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5257. else
  5258. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5259. return 0;
  5260. }
  5261. int clif_send_petstatus(struct map_session_data *sd)
  5262. {
  5263. int fd;
  5264. struct s_pet *pet;
  5265. nullpo_retr(0, sd);
  5266. nullpo_retr(0, sd->pd);
  5267. fd=sd->fd;
  5268. pet = &sd->pd->pet;
  5269. WFIFOHEAD(fd,packet_len(0x1a2));
  5270. WFIFOW(fd,0)=0x1a2;
  5271. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5272. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5273. WFIFOW(fd,27)=pet->level;
  5274. WFIFOW(fd,29)=pet->hungry;
  5275. WFIFOW(fd,31)=pet->intimate;
  5276. WFIFOW(fd,33)=pet->equip;
  5277. WFIFOSET(fd,packet_len(0x1a2));
  5278. return 0;
  5279. }
  5280. /*==========================================
  5281. *
  5282. *------------------------------------------*/
  5283. int clif_pet_emotion(struct pet_data *pd,int param)
  5284. {
  5285. unsigned char buf[16];
  5286. nullpo_retr(0, pd);
  5287. memset(buf,0,packet_len(0x1aa));
  5288. WBUFW(buf,0)=0x1aa;
  5289. WBUFL(buf,2)=pd->bl.id;
  5290. if(param >= 100 && pd->petDB->talk_convert_class) {
  5291. if(pd->petDB->talk_convert_class < 0)
  5292. return 0;
  5293. else if(pd->petDB->talk_convert_class > 0) {
  5294. param -= (pd->pet.class_ - 100)*100;
  5295. param += (pd->petDB->talk_convert_class - 100)*100;
  5296. }
  5297. }
  5298. WBUFL(buf,6)=param;
  5299. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5300. return 0;
  5301. }
  5302. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5303. {
  5304. int fd;
  5305. nullpo_retr(0, sd);
  5306. fd=sd->fd;
  5307. WFIFOHEAD(fd,packet_len(0x1a3));
  5308. WFIFOW(fd,0)=0x1a3;
  5309. WFIFOB(fd,2)=fail;
  5310. WFIFOW(fd,3)=foodid;
  5311. WFIFOSET(fd,packet_len(0x1a3));
  5312. return 0;
  5313. }
  5314. /*==========================================
  5315. * オートスペル リスト送信
  5316. *------------------------------------------*/
  5317. int clif_autospell(struct map_session_data *sd,int skilllv)
  5318. {
  5319. int fd;
  5320. nullpo_retr(0, sd);
  5321. fd=sd->fd;
  5322. WFIFOHEAD(fd,packet_len(0x1cd));
  5323. WFIFOW(fd, 0)=0x1cd;
  5324. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5325. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5326. else
  5327. WFIFOL(fd,2)= 0x00000000;
  5328. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5329. WFIFOL(fd,6)= MG_COLDBOLT;
  5330. else
  5331. WFIFOL(fd,6)= 0x00000000;
  5332. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5333. WFIFOL(fd,10)= MG_FIREBOLT;
  5334. else
  5335. WFIFOL(fd,10)= 0x00000000;
  5336. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5337. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5338. else
  5339. WFIFOL(fd,14)= 0x00000000;
  5340. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5341. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5342. else
  5343. WFIFOL(fd,18)= 0x00000000;
  5344. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5345. WFIFOL(fd,22)= MG_FIREBALL;
  5346. else
  5347. WFIFOL(fd,22)= 0x00000000;
  5348. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5349. WFIFOL(fd,26)= MG_FROSTDIVER;
  5350. else
  5351. WFIFOL(fd,26)= 0x00000000;
  5352. WFIFOSET(fd,packet_len(0x1cd));
  5353. sd->menuskill_id = SA_AUTOSPELL;
  5354. sd->menuskill_val = skilllv;
  5355. return 0;
  5356. }
  5357. /*==========================================
  5358. * ディボーションの青い糸
  5359. *------------------------------------------*/
  5360. int clif_devotion(struct map_session_data *sd)
  5361. {
  5362. unsigned char buf[56];
  5363. int i,n;
  5364. nullpo_retr(0, sd);
  5365. WBUFW(buf,0)=0x1cf;
  5366. WBUFL(buf,2)=sd->bl.id;
  5367. for(i=0,n=0;i<5;i++) {
  5368. if (!sd->devotion[i])
  5369. continue;
  5370. WBUFL(buf,6+4*n)=sd->devotion[i];
  5371. n++;
  5372. }
  5373. for(;n<5;n++)
  5374. WBUFL(buf,6+4*n)=0;
  5375. WBUFB(buf,26)=8;
  5376. WBUFB(buf,27)=0;
  5377. clif_send(buf,packet_len(0x1cf),&sd->bl,AREA);
  5378. return 0;
  5379. }
  5380. int clif_marionette(struct block_list *src, struct block_list *target)
  5381. {
  5382. unsigned char buf[56];
  5383. int n;
  5384. WBUFW(buf,0)=0x1cf;
  5385. WBUFL(buf,2)=src->id;
  5386. for(n=0;n<5;n++)
  5387. WBUFL(buf,6+4*n)=0;
  5388. if (target) //The target goes on the second slot.
  5389. WBUFL(buf,6+4) = target->id;
  5390. WBUFB(buf,26)=8;
  5391. WBUFB(buf,27)=0;
  5392. clif_send(buf,packet_len(0x1cf),src,AREA);
  5393. return 0;
  5394. }
  5395. /*==========================================
  5396. * 氣球
  5397. *------------------------------------------*/
  5398. int clif_spiritball(struct map_session_data *sd)
  5399. {
  5400. unsigned char buf[16];
  5401. nullpo_retr(0, sd);
  5402. WBUFW(buf,0)=0x1d0;
  5403. WBUFL(buf,2)=sd->bl.id;
  5404. WBUFW(buf,6)=sd->spiritball;
  5405. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5406. return 0;
  5407. }
  5408. /*==========================================
  5409. *
  5410. *------------------------------------------*/
  5411. int clif_combo_delay(struct block_list *bl,int wait)
  5412. {
  5413. unsigned char buf[32];
  5414. nullpo_retr(0, bl);
  5415. WBUFW(buf,0)=0x1d2;
  5416. WBUFL(buf,2)=bl->id;
  5417. WBUFL(buf,6)=wait;
  5418. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5419. return 0;
  5420. }
  5421. /*==========================================
  5422. *白刃取り
  5423. *------------------------------------------*/
  5424. int clif_bladestop(struct block_list *src,struct block_list *dst,
  5425. int _bool)
  5426. {
  5427. unsigned char buf[32];
  5428. nullpo_retr(0, src);
  5429. nullpo_retr(0, dst);
  5430. WBUFW(buf,0)=0x1d1;
  5431. WBUFL(buf,2)=src->id;
  5432. WBUFL(buf,6)=dst->id;
  5433. WBUFL(buf,10)=_bool;
  5434. clif_send(buf,packet_len(0x1d1),src,AREA);
  5435. return 0;
  5436. }
  5437. /*==========================================
  5438. * MVPエフェクト
  5439. *------------------------------------------*/
  5440. int clif_mvp_effect(struct map_session_data *sd)
  5441. {
  5442. unsigned char buf[16];
  5443. nullpo_retr(0, sd);
  5444. WBUFW(buf,0)=0x10c;
  5445. WBUFL(buf,2)=sd->bl.id;
  5446. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5447. return 0;
  5448. }
  5449. /*==========================================
  5450. * MVPアイテム所得
  5451. *------------------------------------------*/
  5452. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5453. {
  5454. int view,fd;
  5455. nullpo_retr(0, sd);
  5456. fd=sd->fd;
  5457. WFIFOHEAD(fd,packet_len(0x10a));
  5458. WFIFOW(fd,0)=0x10a;
  5459. if((view = itemdb_viewid(nameid)) > 0)
  5460. WFIFOW(fd,2)=view;
  5461. else
  5462. WFIFOW(fd,2)=nameid;
  5463. WFIFOSET(fd,packet_len(0x10a));
  5464. return 0;
  5465. }
  5466. /*==========================================
  5467. * MVP経験値所得
  5468. *------------------------------------------*/
  5469. int clif_mvp_exp(struct map_session_data *sd,unsigned long exp)
  5470. {
  5471. int fd;
  5472. nullpo_retr(0, sd);
  5473. fd=sd->fd;
  5474. WFIFOHEAD(fd,packet_len(0x10b));
  5475. WFIFOW(fd,0)=0x10b;
  5476. WFIFOL(fd,2)=exp;
  5477. WFIFOSET(fd,packet_len(0x10b));
  5478. return 0;
  5479. }
  5480. /*==========================================
  5481. * ギルド作成可否通知
  5482. *------------------------------------------*/
  5483. int clif_guild_created(struct map_session_data *sd,int flag)
  5484. {
  5485. int fd;
  5486. nullpo_retr(0, sd);
  5487. fd=sd->fd;
  5488. WFIFOHEAD(fd,packet_len(0x167));
  5489. WFIFOW(fd,0)=0x167;
  5490. WFIFOB(fd,2)=flag;
  5491. WFIFOSET(fd,packet_len(0x167));
  5492. return 0;
  5493. }
  5494. /*==========================================
  5495. * ギルド所属通知
  5496. *------------------------------------------*/
  5497. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  5498. {
  5499. int ps,fd;
  5500. nullpo_retr(0, sd);
  5501. nullpo_retr(0, g);
  5502. fd=sd->fd;
  5503. ps=guild_getposition(sd,g);
  5504. WFIFOHEAD(fd,packet_len(0x16c));
  5505. memset(WFIFOP(fd,0),0,packet_len(0x16c));
  5506. WFIFOW(fd,0)=0x16c;
  5507. WFIFOL(fd,2)=g->guild_id;
  5508. WFIFOL(fd,6)=g->emblem_id;
  5509. WFIFOL(fd,10)=g->position[ps].mode;
  5510. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5511. WFIFOSET(fd,packet_len(0x16c));
  5512. return 0;
  5513. }
  5514. /*==========================================
  5515. * ギルドメンバログイン通知
  5516. *------------------------------------------*/
  5517. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5518. {
  5519. unsigned char buf[64];
  5520. nullpo_retr(0, g);
  5521. WBUFW(buf, 0)=0x16d;
  5522. WBUFL(buf, 2)=g->member[idx].account_id;
  5523. WBUFL(buf, 6)=g->member[idx].char_id;
  5524. WBUFL(buf,10)=flag;
  5525. if(g->member[idx].sd==NULL){
  5526. struct map_session_data *sd=guild_getavailablesd(g);
  5527. if(sd!=NULL)
  5528. clif_send(buf,packet_len(0x16d),&sd->bl,GUILD);
  5529. }else
  5530. clif_send(buf,packet_len(0x16d),&g->member[idx].sd->bl,GUILD_WOS);
  5531. return 0;
  5532. }
  5533. // Function `clif_guild_memberlogin_notice` sends info about
  5534. // logins and logouts of a guild member to the rest members.
  5535. // But at the 1st time (after a player login or map changing)
  5536. // the client won't show the message.
  5537. // So I suggest use this function for sending "first-time-info"
  5538. // to some player on entering the game or changing location.
  5539. // At next time the client would always show the message.
  5540. // The function sends all the statuses in the single packet
  5541. // to economize traffic. [LuzZza]
  5542. int clif_guild_send_onlineinfo(struct map_session_data *sd)
  5543. {
  5544. struct guild *g;
  5545. unsigned char buf[14*128];
  5546. int i, count=0, p_len;
  5547. nullpo_retr(0, sd);
  5548. p_len = packet_len(0x16d);
  5549. if(!(g = guild_search(sd->status.guild_id)))
  5550. return 0;
  5551. for(i=0; i<g->max_member; i++) {
  5552. if(g->member[i].account_id > 0 &&
  5553. g->member[i].account_id != sd->status.account_id) {
  5554. WBUFW(buf,count*p_len) = 0x16d;
  5555. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5556. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5557. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5558. count++;
  5559. }
  5560. }
  5561. clif_send(buf, p_len*count, &sd->bl, SELF);
  5562. return 0;
  5563. }
  5564. /*==========================================
  5565. * ギルドマスター通知(14dへの応答)
  5566. *------------------------------------------*/
  5567. int clif_guild_masterormember(struct map_session_data *sd)
  5568. {
  5569. int fd;
  5570. nullpo_retr(0, sd);
  5571. fd=sd->fd;
  5572. WFIFOHEAD(fd,packet_len(0x14e));
  5573. WFIFOW(fd,0) = 0x14e;
  5574. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  5575. WFIFOSET(fd,packet_len(0x14e));
  5576. return 0;
  5577. }
  5578. /*==========================================
  5579. * Basic Info (Territories [Valaris])
  5580. *------------------------------------------*/
  5581. int clif_guild_basicinfo(struct map_session_data *sd)
  5582. {
  5583. int fd,i,t;
  5584. struct guild *g;
  5585. struct guild_castle *gc=NULL;
  5586. nullpo_retr(0, sd);
  5587. fd=sd->fd;
  5588. g=guild_search(sd->status.guild_id);
  5589. if(g==NULL)
  5590. return 0;
  5591. WFIFOHEAD(fd,packet_len(0x1b6));
  5592. WFIFOW(fd, 0)=0x1b6;//0x150;
  5593. WFIFOL(fd, 2)=g->guild_id;
  5594. WFIFOL(fd, 6)=g->guild_lv;
  5595. WFIFOL(fd,10)=g->connect_member;
  5596. WFIFOL(fd,14)=g->max_member;
  5597. WFIFOL(fd,18)=g->average_lv;
  5598. WFIFOL(fd,22)=g->exp;
  5599. WFIFOL(fd,26)=g->next_exp;
  5600. WFIFOL(fd,30)=0; // Tax Points
  5601. WFIFOL(fd,34)=0; // Tendency: (left) Vulgar [-100,100] Famed (right)
  5602. WFIFOL(fd,38)=0; // Tendency: (down) Wicked [-100,100] Righteous (up)
  5603. WFIFOL(fd,42)=g->emblem_id;
  5604. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5605. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5606. for(i = 0, t = 0; i < MAX_GUILDCASTLE; i++)
  5607. {
  5608. gc = guild_castle_search(i);
  5609. if(gc && g->guild_id == gc->guild_id)
  5610. t++;
  5611. }
  5612. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20); // "'N' castles"
  5613. WFIFOSET(fd,packet_len(WFIFOW(fd,0)));
  5614. return 0;
  5615. }
  5616. /*==========================================
  5617. * ギルド同盟/敵対情報
  5618. *------------------------------------------*/
  5619. int clif_guild_allianceinfo(struct map_session_data *sd)
  5620. {
  5621. int fd,i,c;
  5622. struct guild *g;
  5623. nullpo_retr(0, sd);
  5624. fd=sd->fd;
  5625. g=guild_search(sd->status.guild_id);
  5626. if(g==NULL)
  5627. return 0;
  5628. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5629. WFIFOW(fd, 0)=0x14c;
  5630. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5631. struct guild_alliance *a=&g->alliance[i];
  5632. if(a->guild_id>0){
  5633. WFIFOL(fd,c*32+4)=a->opposition;
  5634. WFIFOL(fd,c*32+8)=a->guild_id;
  5635. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5636. c++;
  5637. }
  5638. }
  5639. WFIFOW(fd, 2)=c*32+4;
  5640. WFIFOSET(fd,WFIFOW(fd,2));
  5641. return 0;
  5642. }
  5643. /*==========================================
  5644. * ギルドメンバーリスト
  5645. *------------------------------------------*/
  5646. int clif_guild_memberlist(struct map_session_data *sd)
  5647. {
  5648. int fd;
  5649. int i,c;
  5650. struct guild *g;
  5651. nullpo_retr(0, sd);
  5652. fd=sd->fd;
  5653. if (!fd)
  5654. return 0;
  5655. g=guild_search(sd->status.guild_id);
  5656. if(g==NULL)
  5657. return 0;
  5658. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5659. WFIFOW(fd, 0)=0x154;
  5660. for(i=0,c=0;i<g->max_member;i++){
  5661. struct guild_member *m=&g->member[i];
  5662. if(m->account_id==0)
  5663. continue;
  5664. WFIFOL(fd,c*104+ 4)=m->account_id;
  5665. WFIFOL(fd,c*104+ 8)=m->char_id;
  5666. WFIFOW(fd,c*104+12)=m->hair;
  5667. WFIFOW(fd,c*104+14)=m->hair_color;
  5668. WFIFOW(fd,c*104+16)=m->gender;
  5669. WFIFOW(fd,c*104+18)=m->class_;
  5670. WFIFOW(fd,c*104+20)=m->lv;
  5671. WFIFOL(fd,c*104+22)=m->exp;
  5672. WFIFOL(fd,c*104+26)=m->online;
  5673. WFIFOL(fd,c*104+30)=m->position;
  5674. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5675. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5676. c++;
  5677. }
  5678. WFIFOW(fd, 2)=c*104+4;
  5679. WFIFOSET(fd,WFIFOW(fd,2));
  5680. return 0;
  5681. }
  5682. /*==========================================
  5683. * ギルド役職名リスト
  5684. *------------------------------------------*/
  5685. int clif_guild_positionnamelist(struct map_session_data *sd)
  5686. {
  5687. int i,fd;
  5688. struct guild *g;
  5689. nullpo_retr(0, sd);
  5690. fd=sd->fd;
  5691. g=guild_search(sd->status.guild_id);
  5692. if(g==NULL)
  5693. return 0;
  5694. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5695. WFIFOW(fd, 0)=0x166;
  5696. for(i=0;i<MAX_GUILDPOSITION;i++){
  5697. WFIFOL(fd,i*28+4)=i;
  5698. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5699. }
  5700. WFIFOW(fd,2)=i*28+4;
  5701. WFIFOSET(fd,WFIFOW(fd,2));
  5702. return 0;
  5703. }
  5704. /*==========================================
  5705. * ギルド役職情報リスト
  5706. *------------------------------------------*/
  5707. int clif_guild_positioninfolist(struct map_session_data *sd)
  5708. {
  5709. int i,fd;
  5710. struct guild *g;
  5711. nullpo_retr(0, sd);
  5712. fd=sd->fd;
  5713. g=guild_search(sd->status.guild_id);
  5714. if(g==NULL)
  5715. return 0;
  5716. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5717. WFIFOW(fd, 0)=0x160;
  5718. for(i=0;i<MAX_GUILDPOSITION;i++){
  5719. struct guild_position *p=&g->position[i];
  5720. WFIFOL(fd,i*16+ 4)=i;
  5721. WFIFOL(fd,i*16+ 8)=p->mode;
  5722. WFIFOL(fd,i*16+12)=i;
  5723. WFIFOL(fd,i*16+16)=p->exp_mode;
  5724. }
  5725. WFIFOW(fd, 2)=i*16+4;
  5726. WFIFOSET(fd,WFIFOW(fd,2));
  5727. return 0;
  5728. }
  5729. /*==========================================
  5730. * ギルド役職変更通知
  5731. *------------------------------------------*/
  5732. int clif_guild_positionchanged(struct guild *g,int idx)
  5733. {
  5734. struct map_session_data *sd;
  5735. unsigned char buf[128];
  5736. nullpo_retr(0, g);
  5737. WBUFW(buf, 0)=0x174;
  5738. WBUFW(buf, 2)=44;
  5739. WBUFL(buf, 4)=idx;
  5740. WBUFL(buf, 8)=g->position[idx].mode;
  5741. WBUFL(buf,12)=idx;
  5742. WBUFL(buf,16)=g->position[idx].exp_mode;
  5743. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  5744. if( (sd=guild_getavailablesd(g))!=NULL )
  5745. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5746. return 0;
  5747. }
  5748. /*==========================================
  5749. * ギルドメンバ変更通知
  5750. *------------------------------------------*/
  5751. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  5752. {
  5753. struct map_session_data *sd;
  5754. unsigned char buf[64];
  5755. nullpo_retr(0, g);
  5756. WBUFW(buf, 0)=0x156;
  5757. WBUFW(buf, 2)=16;
  5758. WBUFL(buf, 4)=g->member[idx].account_id;
  5759. WBUFL(buf, 8)=g->member[idx].char_id;
  5760. WBUFL(buf,12)=g->member[idx].position;
  5761. if( (sd=guild_getavailablesd(g))!=NULL )
  5762. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5763. return 0;
  5764. }
  5765. /*==========================================
  5766. * ギルドエンブレム送信
  5767. *------------------------------------------*/
  5768. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  5769. {
  5770. int fd;
  5771. nullpo_retr(0, sd);
  5772. nullpo_retr(0, g);
  5773. fd=sd->fd;
  5774. if(g->emblem_len<=0)
  5775. return 0;
  5776. WFIFOHEAD(fd,g->emblem_len+12);
  5777. WFIFOW(fd,0)=0x152;
  5778. WFIFOW(fd,2)=g->emblem_len+12;
  5779. WFIFOL(fd,4)=g->guild_id;
  5780. WFIFOL(fd,8)=g->emblem_id;
  5781. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  5782. WFIFOSET(fd,WFIFOW(fd,2));
  5783. return 0;
  5784. }
  5785. /*==========================================
  5786. * Send guild skills
  5787. *------------------------------------------*/
  5788. int clif_guild_skillinfo(struct map_session_data* sd)
  5789. {
  5790. int fd;
  5791. struct guild* g;
  5792. int i,c;
  5793. nullpo_retr(0, sd);
  5794. fd = sd->fd;
  5795. g = guild_search(sd->status.guild_id);
  5796. if(g == NULL)
  5797. return 0;
  5798. WFIFOHEAD(fd, MAX_GUILDSKILL * 37 + 6);
  5799. WFIFOW(fd,0) = 0x0162;
  5800. WFIFOW(fd,4) = g->skill_point;
  5801. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  5802. {
  5803. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  5804. {
  5805. int id = g->skill[i].id;
  5806. WFIFOW(fd,c*37+ 6) = id;
  5807. WFIFOW(fd,c*37+ 8) = skill_get_inf(id);
  5808. WFIFOW(fd,c*37+10) = 0;
  5809. WFIFOW(fd,c*37+12) = g->skill[i].lv;
  5810. WFIFOW(fd,c*37+14) = skill_get_sp(id, g->skill[i].lv);
  5811. WFIFOW(fd,c*37+16) = skill_get_range(id, g->skill[i].lv);
  5812. strncpy((char*)WFIFOP(fd,c*37+18), skill_get_name(id), NAME_LENGTH);
  5813. WFIFOB(fd,c*37+42)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  5814. c++;
  5815. }
  5816. }
  5817. WFIFOW(fd,2) = c*37 + 6;
  5818. WFIFOSET(fd,WFIFOW(fd,2));
  5819. return 0;
  5820. }
  5821. /*==========================================
  5822. * Sends guild notice to client
  5823. * R 016f <str1z>.60B <str2z>.120B
  5824. *------------------------------------------*/
  5825. int clif_guild_notice(struct map_session_data* sd, struct guild* g)
  5826. {
  5827. int fd;
  5828. nullpo_retr(0, sd);
  5829. nullpo_retr(0, g);
  5830. fd = sd->fd;
  5831. if ( !session_isActive(fd) )
  5832. return 0;
  5833. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  5834. return 0;
  5835. WFIFOHEAD(fd,packet_len(0x16f));
  5836. WFIFOW(fd,0) = 0x16f;
  5837. memcpy(WFIFOP(fd,2), g->mes1, 60);
  5838. memcpy(WFIFOP(fd,62), g->mes2, 120);
  5839. WFIFOSET(fd,packet_len(0x16f));
  5840. return 0;
  5841. }
  5842. /*==========================================
  5843. * ギルドメンバ勧誘
  5844. *------------------------------------------*/
  5845. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  5846. {
  5847. int fd;
  5848. nullpo_retr(0, sd);
  5849. nullpo_retr(0, g);
  5850. fd=sd->fd;
  5851. WFIFOHEAD(fd,packet_len(0x16a));
  5852. WFIFOW(fd,0)=0x16a;
  5853. WFIFOL(fd,2)=g->guild_id;
  5854. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  5855. WFIFOSET(fd,packet_len(0x16a));
  5856. return 0;
  5857. }
  5858. /*==========================================
  5859. * ギルドメンバ勧誘結果
  5860. *------------------------------------------*/
  5861. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  5862. {
  5863. int fd;
  5864. nullpo_retr(0, sd);
  5865. fd=sd->fd;
  5866. WFIFOHEAD(fd,packet_len(0x169));
  5867. WFIFOW(fd,0)=0x169;
  5868. WFIFOB(fd,2)=flag;
  5869. WFIFOSET(fd,packet_len(0x169));
  5870. return 0;
  5871. }
  5872. /*==========================================
  5873. * ギルドメンバ脱退通知
  5874. *------------------------------------------*/
  5875. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  5876. {
  5877. unsigned char buf[128];
  5878. nullpo_retr(0, sd);
  5879. WBUFW(buf, 0)=0x15a;
  5880. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5881. memcpy(WBUFP(buf,26),mes,40);
  5882. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD);
  5883. return 0;
  5884. }
  5885. /*==========================================
  5886. * ギルドメンバ追放通知
  5887. *------------------------------------------*/
  5888. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,
  5889. int account_id)
  5890. {
  5891. unsigned char buf[128];
  5892. nullpo_retr(0, sd);
  5893. WBUFW(buf, 0)=0x15c;
  5894. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5895. memcpy(WBUFP(buf,26),mes,40);
  5896. memcpy(WBUFP(buf,66),"dummy",NAME_LENGTH);
  5897. clif_send(buf,packet_len(0x15c),&sd->bl,GUILD);
  5898. return 0;
  5899. }
  5900. /*==========================================
  5901. * ギルド追放メンバリスト
  5902. *------------------------------------------*/
  5903. int clif_guild_expulsionlist(struct map_session_data *sd)
  5904. {
  5905. int fd;
  5906. int i,c;
  5907. struct guild *g;
  5908. nullpo_retr(0, sd);
  5909. fd=sd->fd;
  5910. g=guild_search(sd->status.guild_id);
  5911. if(g==NULL)
  5912. return 0;
  5913. WFIFOHEAD(fd,MAX_GUILDEXPULSION * 88 + 4);
  5914. WFIFOW(fd,0)=0x163;
  5915. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  5916. struct guild_expulsion *e=&g->expulsion[i];
  5917. if(e->account_id>0){
  5918. memcpy(WFIFOP(fd,c*88+ 4),e->name,NAME_LENGTH);
  5919. memcpy(WFIFOP(fd,c*88+28),e->acc,24);
  5920. memcpy(WFIFOP(fd,c*88+52),e->mes,44);
  5921. c++;
  5922. }
  5923. }
  5924. WFIFOW(fd,2)=c*88+4;
  5925. WFIFOSET(fd,WFIFOW(fd,2));
  5926. return 0;
  5927. }
  5928. /*==========================================
  5929. * ギルド会話
  5930. *------------------------------------------*/
  5931. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  5932. {
  5933. struct map_session_data *sd;
  5934. unsigned char *buf;
  5935. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  5936. WBUFW(buf, 0) = 0x17f;
  5937. WBUFW(buf, 2) = len + 4;
  5938. memcpy(WBUFP(buf,4), mes, len);
  5939. if ((sd = guild_getavailablesd(g)) != NULL)
  5940. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  5941. if(buf) aFree(buf);
  5942. return 0;
  5943. }
  5944. /*==========================================
  5945. * ギルドスキル割り振り通知
  5946. *------------------------------------------*/
  5947. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  5948. {
  5949. int fd;
  5950. nullpo_retr(0, sd);
  5951. fd=sd->fd;
  5952. WFIFOHEAD(fd,11);
  5953. WFIFOW(fd,0) = 0x10e;
  5954. WFIFOW(fd,2) = skill_num;
  5955. WFIFOW(fd,4) = lv;
  5956. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  5957. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  5958. WFIFOB(fd,10) = 1;
  5959. WFIFOSET(fd,11);
  5960. return 0;
  5961. }
  5962. /*==========================================
  5963. * ギルド同盟要請
  5964. *------------------------------------------*/
  5965. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  5966. {
  5967. int fd;
  5968. nullpo_retr(0, sd);
  5969. fd=sd->fd;
  5970. WFIFOHEAD(fd,packet_len(0x171));
  5971. WFIFOW(fd,0)=0x171;
  5972. WFIFOL(fd,2)=account_id;
  5973. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  5974. WFIFOSET(fd,packet_len(0x171));
  5975. return 0;
  5976. }
  5977. /*==========================================
  5978. * Reply to alliance request.
  5979. * Flag values are:
  5980. * 0: Already allied.
  5981. * 1: You rejected the offer.
  5982. * 2: You accepted the offer.
  5983. * 3: They have too any alliances
  5984. * 4: You have too many alliances.
  5985. *------------------------------------------*/
  5986. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  5987. {
  5988. int fd;
  5989. nullpo_retr(0, sd);
  5990. fd=sd->fd;
  5991. WFIFOHEAD(fd,packet_len(0x173));
  5992. WFIFOW(fd,0)=0x173;
  5993. WFIFOL(fd,2)=flag;
  5994. WFIFOSET(fd,packet_len(0x173));
  5995. return 0;
  5996. }
  5997. /*==========================================
  5998. * ギルド関係解消通知
  5999. *------------------------------------------*/
  6000. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6001. {
  6002. int fd;
  6003. nullpo_retr(0, sd);
  6004. fd = sd->fd;
  6005. if (fd <= 0)
  6006. return 0;
  6007. WFIFOHEAD(fd,packet_len(0x184));
  6008. WFIFOW(fd,0)=0x184;
  6009. WFIFOL(fd,2)=guild_id;
  6010. WFIFOL(fd,6)=flag;
  6011. WFIFOSET(fd,packet_len(0x184));
  6012. return 0;
  6013. }
  6014. /*==========================================
  6015. * ギルド敵対結果
  6016. *------------------------------------------*/
  6017. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6018. {
  6019. int fd;
  6020. nullpo_retr(0, sd);
  6021. fd=sd->fd;
  6022. WFIFOHEAD(fd,packet_len(0x181));
  6023. WFIFOW(fd,0)=0x181;
  6024. WFIFOB(fd,2)=flag;
  6025. WFIFOSET(fd,packet_len(0x181));
  6026. return 0;
  6027. }
  6028. /*==========================================
  6029. * ギルド関係追加
  6030. *------------------------------------------*/
  6031. /*int clif_guild_allianceadded(struct guild *g,int idx)
  6032. {
  6033. unsigned char buf[64];
  6034. WBUFW(fd,0)=0x185;
  6035. WBUFL(fd,2)=g->alliance[idx].opposition;
  6036. WBUFL(fd,6)=g->alliance[idx].guild_id;
  6037. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  6038. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  6039. return 0;
  6040. }*/
  6041. /*==========================================
  6042. * ギルド解散通知
  6043. *------------------------------------------*/
  6044. int clif_guild_broken(struct map_session_data *sd,int flag)
  6045. {
  6046. int fd;
  6047. nullpo_retr(0, sd);
  6048. fd=sd->fd;
  6049. WFIFOHEAD(fd,packet_len(0x15e));
  6050. WFIFOW(fd,0)=0x15e;
  6051. WFIFOL(fd,2)=flag;
  6052. WFIFOSET(fd,packet_len(0x15e));
  6053. return 0;
  6054. }
  6055. /*==========================================
  6056. * エモーション
  6057. *------------------------------------------*/
  6058. void clif_emotion(struct block_list *bl,int type)
  6059. {
  6060. unsigned char buf[8];
  6061. nullpo_retv(bl);
  6062. WBUFW(buf,0)=0xc0;
  6063. WBUFL(buf,2)=bl->id;
  6064. WBUFB(buf,6)=type;
  6065. clif_send(buf,packet_len(0xc0),bl,AREA);
  6066. }
  6067. /*==========================================
  6068. * トーキーボックス
  6069. *------------------------------------------*/
  6070. void clif_talkiebox(struct block_list* bl, const char* talkie)
  6071. {
  6072. unsigned char buf[86];
  6073. nullpo_retv(bl);
  6074. WBUFW(buf,0)=0x191;
  6075. WBUFL(buf,2)=bl->id;
  6076. memcpy(WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6077. clif_send(buf,packet_len(0x191),bl,AREA);
  6078. }
  6079. /*==========================================
  6080. * 結婚エフェクト
  6081. *------------------------------------------*/
  6082. void clif_wedding_effect(struct block_list *bl)
  6083. {
  6084. unsigned char buf[6];
  6085. nullpo_retv(bl);
  6086. WBUFW(buf,0) = 0x1ea;
  6087. WBUFL(buf,2) = bl->id;
  6088. clif_send(buf, packet_len(0x1ea), bl, AREA);
  6089. }
  6090. /*==========================================
  6091. * あなたに逢いたい使用時名前叫び
  6092. *------------------------------------------
  6093. void clif_callpartner(struct map_session_data *sd)
  6094. {
  6095. unsigned char buf[26];
  6096. char *p;
  6097. nullpo_retv(sd);
  6098. if(sd->status.partner_id){
  6099. WBUFW(buf,0)=0x1e6;
  6100. p = map_charid2nick(sd->status.partner_id);
  6101. if(p){
  6102. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6103. }else{
  6104. map_reqchariddb(sd,sd->status.partner_id);
  6105. chrif_searchcharid(sd->status.partner_id);
  6106. WBUFB(buf,2) = 0;
  6107. }
  6108. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  6109. }
  6110. return;
  6111. }
  6112. */
  6113. /*==========================================
  6114. * Adopt baby [Celest]
  6115. *------------------------------------------*/
  6116. void clif_adopt_process(struct map_session_data *sd)
  6117. {
  6118. int fd;
  6119. nullpo_retv(sd);
  6120. fd=sd->fd;
  6121. WFIFOHEAD(fd,packet_len(0x1f8));
  6122. WFIFOW(fd,0)=0x1f8;
  6123. WFIFOSET(fd,packet_len(0x1f8));
  6124. }
  6125. /*==========================================
  6126. * Marry [DracoRPG]
  6127. *------------------------------------------*/
  6128. void clif_marriage_process(struct map_session_data *sd)
  6129. {
  6130. int fd;
  6131. nullpo_retv(sd);
  6132. fd=sd->fd;
  6133. WFIFOHEAD(fd,packet_len(0x1e4));
  6134. WFIFOW(fd,0)=0x1e4;
  6135. WFIFOSET(fd,packet_len(0x1e4));
  6136. }
  6137. /*==========================================
  6138. * Notice of divorce
  6139. *------------------------------------------*/
  6140. void clif_divorced(struct map_session_data* sd, const char* name)
  6141. {
  6142. int fd;
  6143. nullpo_retv(sd);
  6144. fd=sd->fd;
  6145. WFIFOHEAD(fd,packet_len(0x205));
  6146. WFIFOW(fd,0)=0x205;
  6147. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6148. WFIFOSET(fd, packet_len(0x205));
  6149. }
  6150. /*==========================================
  6151. *
  6152. *------------------------------------------*/
  6153. void clif_parse_ReqAdopt(int fd, struct map_session_data *sd)
  6154. {
  6155. nullpo_retv(sd);
  6156. WFIFOHEAD(fd,packet_len(0x1f6));
  6157. WFIFOW(fd,0)=0x1f6;
  6158. WFIFOSET(fd, packet_len(0x1f6));
  6159. }
  6160. /*==========================================
  6161. *
  6162. *------------------------------------------*/
  6163. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd)
  6164. {
  6165. nullpo_retv(sd);
  6166. WFIFOHEAD(fd,packet_len(0x1e2));
  6167. WFIFOW(fd,0)=0x1e2;
  6168. WFIFOSET(fd, packet_len(0x1e2));
  6169. }
  6170. /*==========================================
  6171. *
  6172. *------------------------------------------*/
  6173. int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  6174. {
  6175. int fd;
  6176. nullpo_retr(0, sd);
  6177. fd = sd->fd;
  6178. if (!fd || !len) return 0; //Disconnected player.
  6179. WFIFOHEAD(fd, len+5);
  6180. WFIFOW(fd, 0) = 0x17f;
  6181. WFIFOW(fd, 2) = len + 5;
  6182. memcpy(WFIFOP(fd,4), mes, len);
  6183. WFIFOSET(fd, WFIFOW(fd,2));
  6184. return 1;
  6185. }
  6186. /*==========================================
  6187. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6188. *------------------------------------------*/
  6189. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  6190. {
  6191. unsigned char buf[1024];
  6192. if (!len) return;
  6193. WBUFW(buf, 0) = 0x17f;
  6194. WBUFW(buf, 2) = len + 5;
  6195. memcpy(WBUFP(buf,4), mes, len);
  6196. clif_send(buf, WBUFW(buf,2), src, target);
  6197. return;
  6198. }
  6199. /*==========================================
  6200. *
  6201. *------------------------------------------*/
  6202. int clif_GM_kickack(struct map_session_data *sd, int id)
  6203. {
  6204. int fd;
  6205. nullpo_retr(0, sd);
  6206. fd = sd->fd;
  6207. WFIFOHEAD(fd,packet_len(0xcd));
  6208. WFIFOW(fd,0) = 0xcd;
  6209. WFIFOL(fd,2) = id;
  6210. WFIFOSET(fd, packet_len(0xcd));
  6211. return 0;
  6212. }
  6213. void clif_parse_QuitGame(int fd,struct map_session_data *sd);
  6214. int clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd,int type)
  6215. {
  6216. int fd = tsd->fd;
  6217. WFIFOHEAD(fd,packet_len(0x18b));
  6218. if(type)
  6219. clif_GM_kickack(sd,tsd->status.account_id);
  6220. if (!fd) {
  6221. map_quit(tsd);
  6222. return 0;
  6223. }
  6224. WFIFOW(fd,0) = 0x18b;
  6225. WFIFOW(fd,2) = 0;
  6226. WFIFOSET(fd,packet_len(0x18b));
  6227. clif_setwaitclose(fd);
  6228. return 0;
  6229. }
  6230. int clif_GM_silence(struct map_session_data *sd, struct map_session_data *tsd, int type)
  6231. {
  6232. int fd;
  6233. nullpo_retr(0, sd);
  6234. nullpo_retr(0, tsd);
  6235. fd = tsd->fd;
  6236. if (fd <= 0)
  6237. return 0;
  6238. WFIFOHEAD(fd,packet_len(0x14b));
  6239. WFIFOW(fd,0) = 0x14b;
  6240. WFIFOB(fd,2) = 0;
  6241. memcpy(WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6242. WFIFOSET(fd, packet_len(0x14b));
  6243. return 0;
  6244. }
  6245. /*==========================================
  6246. *
  6247. *------------------------------------------*/
  6248. int clif_timedout(struct map_session_data *sd)
  6249. {
  6250. nullpo_retr(0, sd);
  6251. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' timed out.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id);
  6252. clif_authfail_fd(sd->fd,3); // Even if player is not on we still send anyway
  6253. clif_setwaitclose(sd->fd); // Set session to EOF
  6254. return 0;
  6255. }
  6256. /*==========================================
  6257. * Wis拒否許可応答
  6258. *------------------------------------------*/
  6259. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6260. {
  6261. int fd;
  6262. nullpo_retr(0, sd);
  6263. fd=sd->fd;
  6264. WFIFOHEAD(fd,packet_len(0xd1));
  6265. WFIFOW(fd,0)=0xd1;
  6266. WFIFOB(fd,2)=type;
  6267. WFIFOB(fd,3)=flag;
  6268. WFIFOSET(fd,packet_len(0xd1));
  6269. return 0;
  6270. }
  6271. /*==========================================
  6272. * Wis全拒否許可応答
  6273. *------------------------------------------*/
  6274. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6275. {
  6276. int fd;
  6277. nullpo_retr(0, sd);
  6278. fd=sd->fd;
  6279. WFIFOHEAD(fd,packet_len(0xd2));
  6280. WFIFOW(fd,0)=0xd2;
  6281. WFIFOB(fd,2)=type;
  6282. WFIFOB(fd,3)=flag;
  6283. WFIFOSET(fd,packet_len(0xd2));
  6284. return 0;
  6285. }
  6286. /*==========================================
  6287. * サウンドエフェクト
  6288. *------------------------------------------*/
  6289. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6290. {
  6291. int fd;
  6292. nullpo_retv(sd);
  6293. nullpo_retv(bl);
  6294. fd = sd->fd;
  6295. WFIFOHEAD(fd,packet_len(0x1d3));
  6296. WFIFOW(fd,0) = 0x1d3;
  6297. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6298. WFIFOB(fd,26) = type;
  6299. WFIFOL(fd,27) = 0;
  6300. WFIFOL(fd,31) = bl->id;
  6301. WFIFOSET(fd,packet_len(0x1d3));
  6302. return;
  6303. }
  6304. int clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6305. {
  6306. unsigned char buf[40];
  6307. nullpo_retr(0, bl);
  6308. WBUFW(buf,0) = 0x1d3;
  6309. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6310. WBUFB(buf,26) = type;
  6311. WBUFL(buf,27) = 0;
  6312. WBUFL(buf,31) = bl->id;
  6313. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6314. return 0;
  6315. }
  6316. // displaying special effects (npcs, weather, etc) [Valaris]
  6317. int clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6318. {
  6319. unsigned char buf[24];
  6320. nullpo_retr(0, bl);
  6321. memset(buf, 0, packet_len(0x1f3));
  6322. WBUFW(buf,0) = 0x1f3;
  6323. WBUFL(buf,2) = bl->id;
  6324. WBUFL(buf,6) = type;
  6325. clif_send(buf, packet_len(0x1f3), bl, target);
  6326. if (disguised(bl)) {
  6327. WBUFL(buf,2) = -bl->id;
  6328. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6329. }
  6330. return 0;
  6331. }
  6332. // refresh the client's screen, getting rid of any effects
  6333. int clif_refresh(struct map_session_data *sd)
  6334. {
  6335. nullpo_retr(-1, sd);
  6336. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6337. clif_inventorylist(sd);
  6338. if(pc_iscarton(sd)) {
  6339. clif_cartlist(sd);
  6340. clif_updatestatus(sd,SP_CARTINFO);
  6341. }
  6342. clif_updatestatus(sd,SP_MAXWEIGHT);
  6343. clif_updatestatus(sd,SP_WEIGHT);
  6344. clif_updatestatus(sd,SP_STR);
  6345. clif_updatestatus(sd,SP_AGI);
  6346. clif_updatestatus(sd,SP_VIT);
  6347. clif_updatestatus(sd,SP_INT);
  6348. clif_updatestatus(sd,SP_DEX);
  6349. clif_updatestatus(sd,SP_LUK);
  6350. if (sd->spiritball)
  6351. clif_spiritball_single(sd->fd, sd);
  6352. if (sd->vd.cloth_color)
  6353. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6354. if(merc_is_hom_active(sd->hd))
  6355. clif_send_homdata(sd,0,0);
  6356. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6357. clif_weather_check(sd);
  6358. return 0;
  6359. }
  6360. // updates the object's (bl) name on client
  6361. int clif_charnameack (int fd, struct block_list *bl)
  6362. {
  6363. unsigned char buf[103];
  6364. int cmd = 0x95;
  6365. nullpo_retr(0, bl);
  6366. WBUFW(buf,0) = cmd;
  6367. WBUFL(buf,2) = bl->id;
  6368. switch(bl->type) {
  6369. case BL_PC:
  6370. {
  6371. struct map_session_data *ssd = (struct map_session_data *)bl;
  6372. struct party_data *p = NULL;
  6373. struct guild *g = NULL;
  6374. //Requesting your own "shadow" name. [Skotlex]
  6375. if (ssd->fd == fd && ssd->disguise)
  6376. WBUFL(buf,2) = -bl->id;
  6377. if (strlen(ssd->fakename)>1) {
  6378. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6379. break;
  6380. }
  6381. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6382. if (ssd->status.party_id > 0)
  6383. p = party_search(ssd->status.party_id);
  6384. if (ssd->status.guild_id > 0)
  6385. g = guild_search(ssd->status.guild_id);
  6386. if (p == NULL && g == NULL)
  6387. break;
  6388. WBUFW(buf, 0) = cmd = 0x195;
  6389. if (p)
  6390. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6391. else
  6392. WBUFB(buf,30) = 0;
  6393. if (g)
  6394. {
  6395. int i, ps = -1;
  6396. for(i = 0; i < g->max_member; i++) {
  6397. if (g->member[i].account_id == ssd->status.account_id &&
  6398. g->member[i].char_id == ssd->status.char_id )
  6399. {
  6400. ps = g->member[i].position;
  6401. break;
  6402. }
  6403. }
  6404. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6405. {
  6406. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6407. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6408. } else { //Assume no guild.
  6409. WBUFB(buf,54) = 0;
  6410. WBUFB(buf,78) = 0;
  6411. }
  6412. } else {
  6413. WBUFB(buf,54) = 0;
  6414. WBUFB(buf,78) = 0;
  6415. }
  6416. }
  6417. break;
  6418. //[blackhole89]
  6419. case BL_HOM:
  6420. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6421. break;
  6422. case BL_PET:
  6423. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6424. break;
  6425. case BL_NPC:
  6426. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6427. break;
  6428. case BL_MOB:
  6429. {
  6430. struct mob_data *md = (struct mob_data *)bl;
  6431. nullpo_retr(0, md);
  6432. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6433. if (md->guardian_data && md->guardian_data->guild_id) {
  6434. WBUFW(buf, 0) = cmd = 0x195;
  6435. WBUFB(buf,30) = 0;
  6436. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6437. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6438. } else if (battle_config.show_mob_info) {
  6439. char mobhp[50], *str_p = mobhp;
  6440. WBUFW(buf, 0) = cmd = 0x195;
  6441. if (battle_config.show_mob_info&4)
  6442. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6443. if (battle_config.show_mob_info&1)
  6444. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6445. if (battle_config.show_mob_info&2)
  6446. str_p += sprintf(str_p, "HP: %d%% | ",
  6447. md->status.max_hp > 10000?
  6448. md->status.hp/(md->status.max_hp/100):
  6449. 100*md->status.hp/md->status.max_hp);
  6450. //Even thought mobhp ain't a name, we send it as one so the client
  6451. //can parse it. [Skotlex]
  6452. if (str_p != mobhp) {
  6453. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6454. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6455. WBUFB(buf,54) = 0;
  6456. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6457. }
  6458. }
  6459. }
  6460. break;
  6461. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6462. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6463. // break;
  6464. return 0;
  6465. default:
  6466. if (battle_config.error_log)
  6467. ShowError("clif_parse_GetCharNameRequest : bad type %d(%d)\n", bl->type, bl->id);
  6468. return 0;
  6469. }
  6470. // if no receipient specified just update nearby clients
  6471. if (fd == 0)
  6472. clif_send(buf, packet_len(cmd), bl, AREA);
  6473. else {
  6474. WFIFOHEAD(fd, packet_len(cmd));
  6475. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  6476. WFIFOSET(fd, packet_len(cmd));
  6477. }
  6478. return 0;
  6479. }
  6480. //Used to update when a char leaves a party/guild. [Skotlex]
  6481. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6482. int clif_charnameupdate (struct map_session_data *ssd)
  6483. {
  6484. unsigned char buf[103];
  6485. int cmd = 0x195;
  6486. struct party_data *p = NULL;
  6487. struct guild *g = NULL;
  6488. nullpo_retr(0, ssd);
  6489. if (strlen(ssd->fakename)>1)
  6490. return 0; //No need to update as the party/guild was not displayed anyway.
  6491. WBUFW(buf,0) = cmd;
  6492. WBUFL(buf,2) = ssd->bl.id;
  6493. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6494. if (ssd->status.party_id > 0)
  6495. p = party_search(ssd->status.party_id);
  6496. if (ssd->status.guild_id > 0)
  6497. g = guild_search(ssd->status.guild_id);
  6498. if (p)
  6499. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6500. else
  6501. WBUFB(buf,30) = 0;
  6502. if (g)
  6503. {
  6504. int i, ps = -1;
  6505. for(i = 0; i < g->max_member; i++) {
  6506. if (g->member[i].account_id == ssd->status.account_id &&
  6507. g->member[i].char_id == ssd->status.char_id )
  6508. {
  6509. ps = g->member[i].position;
  6510. break;
  6511. }
  6512. }
  6513. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6514. {
  6515. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6516. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6517. } else { //Assume no guild.
  6518. WBUFB(buf,54) = 0;
  6519. WBUFB(buf,78) = 0;
  6520. }
  6521. } else {
  6522. WBUFB(buf,54) = 0;
  6523. WBUFB(buf,78) = 0;
  6524. }
  6525. // Update nearby clients
  6526. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  6527. return 0;
  6528. }
  6529. int clif_slide(struct block_list *bl, int x, int y){
  6530. unsigned char buf[10];
  6531. nullpo_retr(0, bl);
  6532. WBUFW(buf, 0) = 0x01ff;
  6533. WBUFL(buf, 2) = bl->id;
  6534. WBUFW(buf, 6) = x;
  6535. WBUFW(buf, 8) = y;
  6536. clif_send(buf, packet_len(0x1ff), bl, AREA);
  6537. return 0;
  6538. }
  6539. /*------------------------------------------
  6540. * @me command by lordalfa, rewritten implementation by Skotlex
  6541. *------------------------------------------*/
  6542. int clif_disp_overhead(struct map_session_data *sd, const char* mes)
  6543. {
  6544. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  6545. int len_mes = strlen(mes)+1; //Account for \0
  6546. if (len_mes + 8 >= 256) {
  6547. if (battle_config.error_log)
  6548. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6549. len_mes = 247; //Trunk it to avoid problems.
  6550. }
  6551. // send message to others
  6552. WBUFW(buf,0) = 0x8d;
  6553. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6554. WBUFL(buf,4) = sd->bl.id;
  6555. memcpy(WBUFP(buf,8), mes, len_mes);
  6556. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6557. // send back message to the speaker
  6558. WBUFW(buf,0) = 0x8e;
  6559. WBUFW(buf, 2) = len_mes + 4;
  6560. memcpy(WBUFP(buf,4), mes, len_mes);
  6561. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6562. return 0;
  6563. }
  6564. /*==========================
  6565. * Minimap fix [Kevin]
  6566. * Remove dot from minimap
  6567. *--------------------------*/
  6568. int clif_party_xy_remove(struct map_session_data *sd)
  6569. {
  6570. unsigned char buf[16];
  6571. nullpo_retr(0, sd);
  6572. WBUFW(buf,0)=0x107;
  6573. WBUFL(buf,2)=sd->status.account_id;
  6574. WBUFW(buf,6)=-1;
  6575. WBUFW(buf,8)=-1;
  6576. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6577. return 0;
  6578. }
  6579. //Displays gospel-buff information (thanks to Rayce):
  6580. //Type determines message based on this table:
  6581. /*
  6582. 0x15 End all negative status
  6583. 0x16 Immunity to all status
  6584. 0x17 MaxHP +100%
  6585. 0x18 MaxSP +100%
  6586. 0x19 All stats +20
  6587. 0x1c Enchant weapon with Holy element
  6588. 0x1d Enchant armor with Holy element
  6589. 0x1e DEF +25%
  6590. 0x1f ATK +100%
  6591. 0x20 HIT/Flee +50
  6592. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  6593. */
  6594. void clif_gospel_info(struct map_session_data *sd, int type)
  6595. {
  6596. int fd=sd->fd;
  6597. WFIFOHEAD(fd,packet_len(0x215));
  6598. WFIFOW(fd,0)=0x215;
  6599. WFIFOL(fd,2)=type;
  6600. WFIFOSET(fd, packet_len(0x215));
  6601. }
  6602. /*==========================================
  6603. * Info about Star Glaldiator save map [Komurka]
  6604. * type: 1: Information, 0: Map registered
  6605. *------------------------------------------*/
  6606. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  6607. {
  6608. int fd=sd->fd;
  6609. WFIFOHEAD(fd,packet_len(0x20e));
  6610. WFIFOW(fd,0) = 0x20e;
  6611. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), (char*)WFIFOP(fd,2));
  6612. WFIFOL(fd,26) = sd->bl.id;
  6613. WFIFOB(fd,30) = feel_level;
  6614. WFIFOB(fd,31) = type?1:0;
  6615. WFIFOSET(fd,packet_len(0x20e));
  6616. }
  6617. /*==========================================
  6618. * Info about Star Glaldiator hate mob [Komurka]
  6619. * type: 1: Register mob, 0: Information.
  6620. *------------------------------------------*/
  6621. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  6622. {
  6623. int fd=sd->fd;
  6624. WFIFOHEAD(fd,packet_len(0x20e));
  6625. WFIFOW(fd,0)=0x20e;
  6626. if (pcdb_checkid(class_))
  6627. strncpy((char*)WFIFOP(fd,2),job_name(class_), NAME_LENGTH);
  6628. else if (mobdb_checkid(class_))
  6629. strncpy((char*)WFIFOP(fd,2),mob_db(class_)->jname, NAME_LENGTH);
  6630. else //Really shouldn't happen...
  6631. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  6632. WFIFOL(fd,26)=sd->bl.id;
  6633. WFIFOB(fd,30)=hate_level;
  6634. WFIFOB(fd,31)=type?10:11; //Register/Info
  6635. WFIFOSET(fd, packet_len(0x20e));
  6636. }
  6637. /*==========================================
  6638. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6639. *------------------------------------------*/
  6640. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  6641. {
  6642. int fd=sd->fd;
  6643. WFIFOHEAD(fd,packet_len(0x20e));
  6644. WFIFOW(fd,0)=0x20e;
  6645. strncpy((char*)WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6646. WFIFOL(fd,26)=mob_id;
  6647. WFIFOB(fd,30)=progress; //Message to display
  6648. WFIFOB(fd,31)=20;
  6649. WFIFOSET(fd, packet_len(0x20e));
  6650. }
  6651. /*==========================================
  6652. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  6653. *------------------------------------------*/
  6654. void clif_feel_hate_reset(struct map_session_data *sd)
  6655. {
  6656. int fd=sd->fd;
  6657. WFIFOHEAD(fd,packet_len(0x20e));
  6658. WFIFOW(fd,0)=0x20e;
  6659. memset(WFIFOP(fd,2), 0, NAME_LENGTH); //Blank name as all was reset.
  6660. WFIFOL(fd,26)=sd->bl.id;
  6661. WFIFOB(fd,30)=0; //Feel/hate level: irrelevant
  6662. WFIFOB(fd,31)=30;
  6663. WFIFOSET(fd, packet_len(0x20e));
  6664. }
  6665. // ---------------------
  6666. // clif_guess_PacketVer
  6667. // ---------------------
  6668. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  6669. // error codes:
  6670. // 0 - Success
  6671. // 1 - Unknown packet_ver
  6672. // 2 - Invalid account_id
  6673. // 3 - Invalid char_id
  6674. // 4 - Invalid login_id1 (reserved)
  6675. // 5 - Invalid client_tick (reserved)
  6676. // 6 - Invalid sex
  6677. // Only the first 'invalid' error that appears is used.
  6678. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  6679. {
  6680. static int err = 1;
  6681. static int packet_ver = -1;
  6682. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  6683. if (get_previous)
  6684. {//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]
  6685. if( error )
  6686. *error = err;
  6687. return packet_ver;
  6688. }
  6689. //By default, start searching on the default one.
  6690. err = 1;
  6691. packet_ver = clif_config.packet_db_ver;
  6692. cmd = RFIFOW(fd,0);
  6693. packet_len = RFIFOREST(fd);
  6694. #define SET_ERROR(n) \
  6695. if( err == 1 )\
  6696. err = n;\
  6697. //define SET_ERROR
  6698. #define CHECK_PACKET_VER() \
  6699. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  6700. ;/* not wanttoconnection or wrong length */\
  6701. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > max_account_id )\
  6702. { SET_ERROR(2); }/* invalid account_id */\
  6703. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 || value > max_char_id )\
  6704. { SET_ERROR(3); }/* invalid char_id */\
  6705. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  6706. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  6707. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  6708. { SET_ERROR(6); }/* invalid sex */\
  6709. else\
  6710. {\
  6711. err = 0;\
  6712. if( error )\
  6713. *error = 0;\
  6714. return packet_ver;\
  6715. }\
  6716. //define CHECK_PACKET_VER
  6717. CHECK_PACKET_VER();//Default packet version found.
  6718. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  6719. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  6720. CHECK_PACKET_VER();
  6721. }
  6722. if( error )
  6723. *error = err;
  6724. packet_ver = -1;
  6725. return -1;
  6726. #undef SET_ERROR
  6727. #undef CHECK_PACKET_VER
  6728. }
  6729. // ------------
  6730. // clif_parse_*
  6731. // ------------
  6732. // パケット読み取って色々操作
  6733. /*==========================================
  6734. *
  6735. *------------------------------------------*/
  6736. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  6737. {
  6738. int cmd, account_id, char_id, login_id1, sex;
  6739. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  6740. 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])
  6741. if (sd) {
  6742. if (battle_config.error_log)
  6743. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)?\n");
  6744. return;
  6745. }
  6746. // Only valid packet version get here
  6747. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  6748. cmd = RFIFOW(fd,0);
  6749. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  6750. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  6751. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  6752. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  6753. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  6754. if( packet_ver < 5 || // reject really old client versions
  6755. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  6756. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  6757. {// packet version rejected
  6758. 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));
  6759. WFIFOHEAD(fd,packet_len(0x6a));
  6760. WFIFOW(fd,0) = 0x6a;
  6761. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  6762. WFIFOSET(fd,packet_len(0x6a));
  6763. clif_setwaitclose(fd);
  6764. return;
  6765. } else
  6766. {// packet version accepted
  6767. struct block_list* bl;
  6768. if( (bl=map_id2bl(account_id)) != NULL && bl->type != BL_PC )
  6769. {// non-player object already has that id
  6770. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  6771. WFIFOHEAD(fd,packet_len(0x6a));
  6772. WFIFOW(fd,0) = 0x6a;
  6773. WFIFOB(fd,2) = 3; // Rejected by server
  6774. WFIFOSET(fd,packet_len(0x6a));
  6775. clif_setwaitclose(fd);
  6776. return;
  6777. }
  6778. }
  6779. CREATE(sd, TBL_PC, 1);
  6780. sd->fd = fd;
  6781. sd->packet_ver = packet_ver;
  6782. session[fd]->session_data = sd;
  6783. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  6784. WFIFOHEAD(fd,4);
  6785. WFIFOL(fd,0) = sd->bl.id;
  6786. WFIFOSET(fd,4);
  6787. chrif_authreq(sd);
  6788. return;
  6789. }
  6790. /*==========================================
  6791. * 007d クライアント側マップ読み込み完了
  6792. * map侵入時に必要なデータを全て送りつける
  6793. *------------------------------------------*/
  6794. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  6795. {
  6796. if(sd->bl.prev != NULL)
  6797. return;
  6798. if (!sd->state.auth)
  6799. { //Character loading is not complete yet!
  6800. //Let pc_reg_received reinvoke this when ready.
  6801. sd->state.connect_new = 0;
  6802. return;
  6803. }
  6804. if (sd->state.rewarp)
  6805. { //Rewarp player.
  6806. sd->state.rewarp = 0;
  6807. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  6808. return;
  6809. }
  6810. // look
  6811. #if PACKETVER < 4
  6812. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  6813. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  6814. #else
  6815. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  6816. #endif
  6817. if(sd->vd.cloth_color)
  6818. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6819. // item
  6820. pc_checkitem(sd);
  6821. clif_inventorylist(sd);
  6822. // cart
  6823. if(pc_iscarton(sd)) {
  6824. clif_cartlist(sd);
  6825. clif_updatestatus(sd,SP_CARTINFO);
  6826. }
  6827. // weight max, now
  6828. clif_updatestatus(sd,SP_MAXWEIGHT);
  6829. clif_updatestatus(sd,SP_WEIGHT);
  6830. if(battle_config.pc_invincible_time > 0) {
  6831. if(map_flag_gvg(sd->bl.m))
  6832. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  6833. else
  6834. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  6835. }
  6836. map_addblock(&sd->bl); // ブロック登録
  6837. clif_spawn(&sd->bl); // spawn
  6838. // Party
  6839. if(sd->status.party_id) {
  6840. party_send_movemap(sd);
  6841. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  6842. }
  6843. // guild
  6844. if(sd->status.guild_id)
  6845. guild_send_memberinfoshort(sd,1);
  6846. if(map[sd->bl.m].flag.pvp) {
  6847. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  6848. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  6849. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  6850. sd->pvp_rank = 0;
  6851. sd->pvp_lastusers = 0;
  6852. sd->pvp_point = 5;
  6853. sd->pvp_won = 0;
  6854. sd->pvp_lost = 0;
  6855. }
  6856. clif_set0199(fd,1);
  6857. } else
  6858. // set flag, if it's a duel [LuzZza]
  6859. if(sd->duel_group)
  6860. clif_set0199(fd,1);
  6861. if (map[sd->bl.m].flag.gvg_dungeon)
  6862. {
  6863. clif_set0199(fd,1); //TODO: Figure out the real packet to send here.
  6864. if (!sd->pvp_point)
  6865. {
  6866. sd->pvp_point = 5; //Need to die twice to be warped out.
  6867. sd->pvp_won = 0;
  6868. sd->pvp_lost = 0;
  6869. }
  6870. }
  6871. if(map_flag_gvg(sd->bl.m))
  6872. clif_set0199(fd,3);
  6873. map_foreachinarea(clif_getareachar, sd->bl.m,
  6874. sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE,
  6875. BL_ALL, sd);
  6876. // pet
  6877. if(sd->pd) {
  6878. map_addblock(&sd->pd->bl);
  6879. clif_spawn(&sd->pd->bl);
  6880. clif_send_petdata(sd,sd->pd,0,0);
  6881. clif_send_petstatus(sd);
  6882. // skill_unit_move(&sd->pd->bl,gettick(),1);
  6883. }
  6884. //homunculus [blackhole89]
  6885. if(merc_is_hom_active(sd->hd)) {
  6886. map_addblock(&sd->hd->bl);
  6887. clif_spawn(&sd->hd->bl);
  6888. clif_hominfo(sd,sd->hd,1);
  6889. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  6890. clif_send_homdata(sd,0,0);
  6891. clif_homskillinfoblock(sd);
  6892. if (battle_config.hom_setting&0x8)
  6893. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  6894. if (!(battle_config.hom_setting&0x2))
  6895. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  6896. }
  6897. if(sd->state.connect_new) {
  6898. int lv;
  6899. sd->state.connect_new = 0;
  6900. clif_skillinfoblock(sd);
  6901. clif_hotkeys_send(sd);
  6902. clif_updatestatus(sd,SP_NEXTBASEEXP);
  6903. clif_updatestatus(sd,SP_NEXTJOBEXP);
  6904. clif_updatestatus(sd,SP_SKILLPOINT);
  6905. clif_initialstatus(sd);
  6906. if (sd->sc.option&OPTION_FALCON)
  6907. clif_status_load(&sd->bl, SI_FALCON, 1);
  6908. if (sd->sc.option&OPTION_RIDING)
  6909. clif_status_load(&sd->bl, SI_RIDING, 1);
  6910. if(sd->status.manner < 0)
  6911. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  6912. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  6913. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  6914. if(sd->bl.m == sd->feel_map[0].m
  6915. || sd->bl.m == sd->feel_map[1].m
  6916. || sd->bl.m == sd->feel_map[2].m)
  6917. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  6918. }
  6919. if(sd->pd && sd->pd->pet.intimate > 900)
  6920. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  6921. if(merc_is_hom_active(sd->hd))
  6922. merc_hom_init_timers(sd->hd);
  6923. if (night_flag && map[sd->bl.m].flag.nightenabled)
  6924. {
  6925. sd->state.night = 1;
  6926. clif_status_load(&sd->bl, SI_NIGHT, 1);
  6927. }
  6928. // Notify everyone that this char logged in [Skotlex].
  6929. clif_foreachclient(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  6930. //Login Event
  6931. npc_script_event(sd, NPCE_LOGIN);
  6932. } else {
  6933. //For some reason the client "loses" these on map-change.
  6934. clif_updatestatus(sd,SP_STR);
  6935. clif_updatestatus(sd,SP_AGI);
  6936. clif_updatestatus(sd,SP_VIT);
  6937. clif_updatestatus(sd,SP_INT);
  6938. clif_updatestatus(sd,SP_DEX);
  6939. clif_updatestatus(sd,SP_LUK);
  6940. sd->state.using_fake_npc = 0;
  6941. //New 'night' effect by dynamix [Skotlex]
  6942. if (night_flag && map[sd->bl.m].flag.nightenabled)
  6943. { //Display night.
  6944. if (!sd->state.night) {
  6945. sd->state.night = 1;
  6946. clif_status_load(&sd->bl, SI_NIGHT, 1);
  6947. }
  6948. } else if (sd->state.night) { //Clear night display.
  6949. sd->state.night = 0;
  6950. clif_status_load(&sd->bl, SI_NIGHT, 0);
  6951. }
  6952. if(sd->npc_id)
  6953. npc_event_dequeue(sd);
  6954. }
  6955. // Lance
  6956. if(sd->state.event_loadmap && map[sd->bl.m].flag.loadevent){
  6957. pc_setregstr(sd, add_str("@maploaded$"), map[sd->bl.m].name);
  6958. npc_script_event(sd, NPCE_LOADMAP);
  6959. }
  6960. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  6961. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  6962. if (sd->sc.opt2) //Client loses these on warp.
  6963. clif_changeoption(&sd->bl);
  6964. clif_weather_check(sd);
  6965. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  6966. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  6967. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  6968. else
  6969. sd->areanpc_id = 0;
  6970. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  6971. if(pc_isdead(sd))
  6972. clif_clearunit_area(&sd->bl, 1);
  6973. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  6974. // else
  6975. // clif_changed_dir(&sd->bl, SELF);
  6976. // Trigger skill effects if you appear standing on them
  6977. if(!battle_config.pc_invincible_time)
  6978. skill_unit_move(&sd->bl,gettick(),1);
  6979. }
  6980. /*==========================================
  6981. *
  6982. *------------------------------------------*/
  6983. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  6984. {
  6985. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  6986. WFIFOHEAD(fd, packet_len(0x7f));
  6987. WFIFOW(fd,0)=0x7f;
  6988. WFIFOL(fd,2)=gettick();
  6989. WFIFOSET(fd,packet_len(0x7f));
  6990. // removed until the socket problems are fixed. [FlavioJS]
  6991. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  6992. return;
  6993. }
  6994. void clif_hotkeys_send(struct map_session_data *sd) {
  6995. #ifdef HOTKEY_SAVING
  6996. const int fd = sd->fd;
  6997. int i;
  6998. if (!fd) return;
  6999. WFIFOHEAD(fd, 2+HOTKEY_SAVING*7);
  7000. WFIFOW(fd, 0) = 0x02b9;
  7001. for(i = 0; i < HOTKEY_SAVING; i++) {
  7002. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  7003. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  7004. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  7005. }
  7006. WFIFOSET(fd, packet_len(0x02b9));
  7007. #endif
  7008. }
  7009. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  7010. #ifdef HOTKEY_SAVING
  7011. unsigned short idx;
  7012. int cmd;
  7013. cmd = RFIFOW(fd, 0);
  7014. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  7015. if (idx >= HOTKEY_SAVING) return;
  7016. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  7017. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  7018. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  7019. return;
  7020. #endif
  7021. }
  7022. /*==========================================
  7023. *
  7024. *------------------------------------------*/
  7025. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  7026. {
  7027. int x, y;
  7028. int cmd;
  7029. if (pc_isdead(sd)) {
  7030. clif_clearunit_area(&sd->bl, 1);
  7031. return;
  7032. }
  7033. if (sd->sc.opt1 && sd->sc.opt1 == OPT1_STONEWAIT)
  7034. ; //You CAN walk on this OPT1 value.
  7035. else if (pc_cant_act(sd))
  7036. return;
  7037. if(sd->sc.count && sd->sc.data[SC_RUN].timer != -1)
  7038. return;
  7039. pc_delinvincibletimer(sd);
  7040. cmd = RFIFOW(fd,0);
  7041. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7042. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7043. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7044. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7045. //Set last idle time... [Skotlex]
  7046. sd->idletime = last_tick;
  7047. unit_walktoxy(&sd->bl, x, y, 4);
  7048. }
  7049. /*==========================================
  7050. *
  7051. *------------------------------------------*/
  7052. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  7053. {
  7054. WFIFOHEAD(fd,packet_len(0x18b));
  7055. WFIFOW(fd,0) = 0x18b;
  7056. /* Rovert's prevent logout option fixed [Valaris] */
  7057. if (sd->sc.data[SC_CLOAKING].timer==-1 && sd->sc.data[SC_HIDING].timer==-1 &&
  7058. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7059. ) {
  7060. clif_setwaitclose(fd);
  7061. WFIFOW(fd,2)=0;
  7062. } else {
  7063. WFIFOW(fd,2)=1;
  7064. }
  7065. WFIFOSET(fd,packet_len(0x18b));
  7066. }
  7067. /*==========================================
  7068. *
  7069. *------------------------------------------*/
  7070. void check_fake_id(int fd, struct map_session_data *sd, int target_id)
  7071. {
  7072. // if player asks for the fake player (only bot and modified client can see a hiden player)
  7073. /* if (target_id == server_char_id) {
  7074. char message_to_gm[strlen(msg_txt(536)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7075. sprintf(message_to_gm, msg_txt(536), sd->status.name, sd->status.account_id); // Character '%s' (account: %d) try to use a bot (it tries to detect a fake player).
  7076. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7077. // if we block people
  7078. if (battle_config.ban_bot < 0) {
  7079. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7080. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7081. // message about the ban
  7082. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7083. // if we ban people
  7084. } else if (battle_config.ban_bot > 0) {
  7085. chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, 0, battle_config.ban_bot, 0); // type: 2 - ban (year, month, day, hour, minute, second)
  7086. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7087. // message about the ban
  7088. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7089. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7090. // message about the ban
  7091. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7092. }
  7093. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7094. // send this info cause the bot ask until get an answer, damn spam
  7095. memset(WPACKETP(0), 0, packet_len(0x95));
  7096. WPACKETW(0) = 0x95;
  7097. WPACKETL(2) = server_char_id;
  7098. strncpy(WPACKETP(6), sd->status.name, 24);
  7099. SENDPACKET(fd, packet_len(0x95));
  7100. // take fake player out of screen
  7101. WPACKETW(0) = 0x80;
  7102. WPACKETL(2) = server_char_id;
  7103. WPACKETB(6) = 0;
  7104. SENDPACKET(fd, packet_len(0x80));
  7105. // take fake mob out of screen
  7106. WPACKETW(0) = 0x80;
  7107. WPACKETL(2) = server_fake_mob_id;
  7108. WPACKETB(6) = 0;
  7109. SENDPACKET(fd, packet_len(0x80));
  7110. }
  7111. // if player asks for the fake mob (only bot and modified client can see a hiden mob)
  7112. if (target_id == server_fake_mob_id) {
  7113. int fake_mob;
  7114. char message_to_gm[strlen(msg_txt(537)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7115. sprintf(message_to_gm, msg_txt(537), sd->status.name, sd->status.account_id); // Character '%s' (account: %d) try to use a bot (it tries to detect a fake mob).
  7116. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7117. // if we block people
  7118. if (battle_config.ban_bot < 0) {
  7119. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7120. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7121. // message about the ban
  7122. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7123. // if we ban people
  7124. } else if (battle_config.ban_bot > 0) {
  7125. chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, 0, battle_config.ban_bot, 0); // type: 2 - ban (year, month, day, hour, minute, second)
  7126. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7127. // message about the ban
  7128. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7129. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7130. // message about the ban
  7131. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7132. }
  7133. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7134. // send this info cause the bot ask until get an answer, damn spam
  7135. memset(WPACKETP(0), 0, packet_len(0x95));
  7136. WPACKETW(0) = 0x95;
  7137. WPACKETL(2) = server_fake_mob_id;
  7138. fake_mob = fake_mob_list[(sd->bl.m + sd->fd + sd->status.char_id) % (sizeof(fake_mob_list) / sizeof(fake_mob_list[0]))]; // never same mob
  7139. if (!mobdb_checkid(fake_mob))
  7140. fake_mob = 1002; // poring (default)
  7141. strncpy(WPACKETP(6), mob_db[fake_mob].name, 24);
  7142. SENDPACKET(fd, packet_len(0x95));
  7143. // take fake mob out of screen
  7144. WPACKETW(0) = 0x80;
  7145. WPACKETL(2) = server_fake_mob_id;
  7146. WPACKETB(6) = 0;
  7147. SENDPACKET(fd, packet_len(0x80));
  7148. // take fake player out of screen
  7149. WPACKETW(0) = 0x80;
  7150. WPACKETL(2) = server_char_id;
  7151. WPACKETB(6) = 0;
  7152. SENDPACKET(fd, packet_len(0x80));
  7153. }
  7154. */
  7155. return;
  7156. }
  7157. /*==========================================
  7158. *
  7159. *------------------------------------------*/
  7160. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  7161. {
  7162. int account_id;
  7163. struct block_list* bl;
  7164. struct status_change *sc;
  7165. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7166. if(account_id<0 && -account_id == sd->bl.id) // for disguises [Valaris]
  7167. account_id= sd->bl.id;
  7168. bl = map_id2bl(account_id);
  7169. //Is this possible? Lagged clients could request names of already gone mobs/players. [Skotlex]
  7170. if (!bl) return;
  7171. sc = status_get_sc(bl);
  7172. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  7173. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  7174. pc_isGM(sd) < battle_config.hack_info_GM_level
  7175. ) {
  7176. //GM characters (with client side GM enabled are able to see invisible stuff) [Lance]
  7177. //Asked name of invisible player, this shouldn't be possible!
  7178. //Possible bot? Thanks to veider and qspirit
  7179. //FIXME: Still isn't perfected as clients keep asking for this on legitimate situations.
  7180. char gm_msg[256];
  7181. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requested the name of an invisible target.", sd->status.name, sd->status.account_id);
  7182. ShowWarning(gm_msg);
  7183. // information is sended to all online GM
  7184. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7185. return;
  7186. }
  7187. clif_charnameack(fd, bl);
  7188. }
  7189. /*==========================================
  7190. * Validates and processes global messages
  7191. * S 008c/00f3 <packet len>.w <text>.?B (<name> : <message>)
  7192. *------------------------------------------*/
  7193. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  7194. {
  7195. const char *text, *name, *message;
  7196. unsigned int packetlen, textlen, namelen, messagelen;
  7197. packetlen = RFIFOW(fd,2);
  7198. // basic structure checks
  7199. if( packetlen > RFIFOREST(fd) )
  7200. { // there has to be enough data to read
  7201. ShowWarning("clif_parse_GlobalMessage: Received malformed packet from player '%s' (length is incorrect)!", sd->status.name);
  7202. return;
  7203. }
  7204. if( packetlen < 4 + 1 )
  7205. { // 4-byte header and at least an empty string is expected
  7206. ShowWarning("clif_parse_GlobalMessage: Received malformed packet from player '%s' (no message data)!", sd->status.name);
  7207. return;
  7208. }
  7209. text = (char*)RFIFOP(fd,4);
  7210. textlen = packetlen - 4;
  7211. name = text;
  7212. namelen = strnlen(sd->status.name, NAME_LENGTH - 1);
  7213. // verify <name> part of the packet
  7214. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  7215. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  7216. {
  7217. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  7218. ShowWarning("clif_parse_GlobalMessage: Player '%s' sent a message using an incorrect name! Forcing a relog...", sd->status.name);
  7219. clif_setwaitclose(fd); // Just kick them out to correct it.
  7220. return;
  7221. }
  7222. message = text + namelen + 3;
  7223. messagelen = textlen - namelen - 3 - 1; // this should be the message length
  7224. // verify <message> part of the packet
  7225. if( message[messagelen] != '\0' )
  7226. { // message must be zero-terminated
  7227. ShowWarning("clif_parse_GlobalMessage: Player '%s' sent an unterminated string!", sd->status.name);
  7228. return;
  7229. }
  7230. if( messagelen != strnlen(message, messagelen+1) )
  7231. { // the declared length must match real length
  7232. ShowWarning("clif_parse_GlobalMessage: Received malformed packet from player '%s' (length is incorrect)!", sd->status.name);
  7233. return;
  7234. }
  7235. if( messagelen > CHATBOX_SIZE )
  7236. { // messages mustn't be too long
  7237. int i;
  7238. // special case here - allow some more freedom for frost joke & dazzler
  7239. // TODO:? You could use a state flag when FrostJoke/Scream is used, and unset it once the skill triggers. [Skotlex]
  7240. ARR_FIND( 0, MAX_SKILLTIMERSKILL, i, sd->ud.skilltimerskill[i] == 0 || sd->ud.skilltimerskill[i]->skill_id == BA_FROSTJOKE || sd->ud.skilltimerskill[i]->skill_id == DC_SCREAM );
  7241. if( i == MAX_SKILLTIMERSKILL || !sd->ud.skilltimerskill[i])
  7242. { // normal message, too long
  7243. ShowWarning("clif_parse_GlobalMessage: Player '%s' sent a message too long ('%.*s')!", sd->status.name, CHATBOX_SIZE, message);
  7244. return;
  7245. }
  7246. if( messagelen > 255 )
  7247. { // frost joke/dazzler, but still too long
  7248. ShowWarning("clif_parse_GlobalMessage: Player '%s' sent a message too long ('%.*s')!", sd->status.name, 255, message);
  7249. return;
  7250. }
  7251. }
  7252. if( is_atcommand(fd, sd, text) != AtCommand_None || is_charcommand(fd, sd, text) != CharCommand_None )
  7253. return;
  7254. if( sd->sc.data[SC_BERSERK].timer != -1 || (sd->sc.data[SC_NOCHAT].timer != -1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT) )
  7255. return;
  7256. if( battle_config.min_chat_delay )
  7257. { //[Skotlex]
  7258. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7259. return;
  7260. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7261. }
  7262. // send message to others
  7263. WFIFOHEAD(fd, 8 + textlen);
  7264. WFIFOW(fd,0) = 0x8d;
  7265. WFIFOW(fd,2) = 8 + textlen;
  7266. WFIFOL(fd,4) = sd->bl.id;
  7267. safestrncpy((char*)WFIFOP(fd,8), text, textlen);
  7268. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7269. // send back message to the speaker
  7270. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), packetlen);
  7271. WFIFOW(fd,0) = 0x8e;
  7272. WFIFOSET(fd, WFIFOW(fd,2));
  7273. #ifdef PCRE_SUPPORT
  7274. // trigger listening mobs/npcs
  7275. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  7276. map_foreachinrange(mob_chat_sub, &sd->bl, AREA_SIZE, BL_MOB, text, textlen, &sd->bl);
  7277. #endif
  7278. // check for special supernovice phrase
  7279. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE )
  7280. {
  7281. int next = pc_nextbaseexp(sd);
  7282. if( next > 0 && (sd->status.base_exp * 1000 / next)% 100 == 0 ) { // 0%, 10%, 20%, ...
  7283. switch (sd->state.snovice_call_flag) {
  7284. case 0:
  7285. if( strstr(message, msg_txt(504)) ) // "Guardian Angel, can you hear my voice? ^^;"
  7286. sd->state.snovice_call_flag++;
  7287. break;
  7288. case 1: {
  7289. char buf[256];
  7290. sprintf(buf, msg_txt(505), sd->status.name);
  7291. if( strstr(message, buf) ) // "My name is %s, and I'm a Super Novice~"
  7292. sd->state.snovice_call_flag++;
  7293. }
  7294. break;
  7295. case 2:
  7296. if( strstr(message, msg_txt(506)) ) // "Please help me~ T.T"
  7297. sd->state.snovice_call_flag++;
  7298. break;
  7299. case 3:
  7300. if( skillnotok(MO_EXPLOSIONSPIRITS,sd) )
  7301. break; //Do not override the noskill mapflag. [Skotlex]
  7302. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7303. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  7304. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7305. sd->state.snovice_call_flag = 0;
  7306. break;
  7307. }
  7308. }
  7309. }
  7310. // Chat logging type 'O' / Global Chat
  7311. if( log_config.chat&1 || (log_config.chat&2 && !(agit_flag && log_config.chat&64)) )
  7312. log_chat("O", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7313. return;
  7314. }
  7315. int clif_message(struct block_list *bl, const char* msg)
  7316. {
  7317. unsigned short msg_len = strlen(msg) + 1;
  7318. unsigned char buf[256];
  7319. nullpo_retr(0, bl);
  7320. WBUFW(buf, 0) = 0x8d;
  7321. WBUFW(buf, 2) = msg_len + 8;
  7322. WBUFL(buf, 4) = bl->id;
  7323. memcpy(WBUFP(buf, 8), msg, msg_len);
  7324. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC); // by Gengar
  7325. return 0;
  7326. }
  7327. /*==========================================
  7328. * /mm /mapmove (as @rura GM command)
  7329. *------------------------------------------*/
  7330. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  7331. {
  7332. char output[MAP_NAME_LENGTH_EXT+15]; // Max length of a short: ' -6XXXX' -> 7 digits
  7333. char message[MAP_NAME_LENGTH_EXT+15+5]; // "/mm "+output
  7334. char* map_name;
  7335. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7336. return;
  7337. if(pc_isGM(sd) < get_atcommand_level(AtCommand_MapMove))
  7338. return;
  7339. map_name = (char*)RFIFOP(fd,2);
  7340. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  7341. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7342. atcommand_rura(fd, sd, "@rura", output);
  7343. if(log_config.gm && get_atcommand_level(AtCommand_MapMove) >= log_config.gm)
  7344. {
  7345. sprintf(message, "/mm %s", output);
  7346. log_atcommand(sd, message);
  7347. }
  7348. return;
  7349. }
  7350. /*==========================================
  7351. *
  7352. *------------------------------------------*/
  7353. void clif_changed_dir(struct block_list *bl, int type)
  7354. {
  7355. unsigned char buf[64];
  7356. WBUFW(buf,0) = 0x9c;
  7357. WBUFL(buf,2) = bl->id;
  7358. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7359. WBUFB(buf,8) = unit_getdir(bl);
  7360. clif_send(buf, packet_len(0x9c), bl, type);
  7361. if (disguised(bl)) {
  7362. WBUFL(buf,2) = -bl->id;
  7363. WBUFW(buf,6) = 0;
  7364. clif_send(buf, packet_len(0x9c), bl, SELF);
  7365. }
  7366. return;
  7367. }
  7368. /*==========================================
  7369. *
  7370. *------------------------------------------*/
  7371. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  7372. {
  7373. unsigned char headdir, dir;
  7374. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7375. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7376. pc_setdir(sd, dir, headdir);
  7377. clif_changed_dir(&sd->bl, AREA_WOS);
  7378. return;
  7379. }
  7380. /*==========================================
  7381. *
  7382. *------------------------------------------*/
  7383. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  7384. {
  7385. unsigned char buf[64];
  7386. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7387. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7388. clif_skill_fail(sd, 1, 0, 1);
  7389. return;
  7390. }
  7391. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7392. if (sd->emotionlasttime >= time(NULL)) {
  7393. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7394. clif_skill_fail(sd, 1, 0, 1);
  7395. return;
  7396. }
  7397. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7398. WBUFW(buf,0) = 0xc0;
  7399. WBUFL(buf,2) = sd->bl.id;
  7400. WBUFB(buf,6) = RFIFOB(fd,2);
  7401. clif_send(buf, packet_len(0xc0), &sd->bl, AREA);
  7402. } else
  7403. clif_skill_fail(sd, 1, 0, 1);
  7404. }
  7405. /*==========================================
  7406. *
  7407. *------------------------------------------*/
  7408. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  7409. {
  7410. WFIFOHEAD(fd,packet_len(0xc2));
  7411. WFIFOW(fd,0) = 0xc2;
  7412. WFIFOL(fd,2) = map_getusers();
  7413. WFIFOSET(fd,packet_len(0xc2));
  7414. }
  7415. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7416. {
  7417. if (pc_isdead(sd)) {
  7418. clif_clearunit_area(&sd->bl, 1);
  7419. return;
  7420. }
  7421. if (sd->sc.count &&
  7422. (sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  7423. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  7424. sd->sc.data[SC_BLADESTOP].timer != -1))
  7425. return;
  7426. pc_stop_walking(sd, 1);
  7427. pc_stop_attack(sd);
  7428. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7429. target_id = sd->bl.id;
  7430. switch(action_type)
  7431. {
  7432. case 0x00: // once attack
  7433. case 0x07: // continuous attack
  7434. if (pc_cant_act(sd) || sd->sc.option&OPTION_HIDE)
  7435. return;
  7436. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  7437. return;
  7438. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7439. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7440. clif_skill_fail(sd, 1, 4, 0);
  7441. return;
  7442. }
  7443. }
  7444. pc_delinvincibletimer(sd);
  7445. sd->idletime = last_tick;
  7446. unit_attack(&sd->bl, target_id, action_type != 0);
  7447. break;
  7448. case 0x02: // sitdown
  7449. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7450. clif_skill_fail(sd, 1, 0, 2);
  7451. break;
  7452. }
  7453. if(pc_issit(sd)) {
  7454. //Bugged client? Just refresh them.
  7455. clif_sitting(&sd->bl);
  7456. return;
  7457. }
  7458. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7459. break;
  7460. if (sd->sc.count && (
  7461. sd->sc.data[SC_DANCING].timer != -1 ||
  7462. (sd->sc.data[SC_GRAVITATION].timer != -1 && sd->sc.data[SC_GRAVITATION].val3 == BCT_SELF)
  7463. )) //No sitting during these states either.
  7464. break;
  7465. pc_setsit(sd);
  7466. skill_sit(sd,1);
  7467. clif_sitting(&sd->bl);
  7468. break;
  7469. case 0x03: // standup
  7470. if (!pc_issit(sd)) {
  7471. //Bugged client? Just refresh them.
  7472. clif_standing(&sd->bl);
  7473. return;
  7474. }
  7475. pc_setstand(sd);
  7476. skill_sit(sd,0);
  7477. clif_standing(&sd->bl);
  7478. break;
  7479. }
  7480. }
  7481. /*==========================================
  7482. *
  7483. *------------------------------------------*/
  7484. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  7485. {
  7486. clif_parse_ActionRequest_sub(sd,
  7487. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7488. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7489. gettick()
  7490. );
  7491. }
  7492. /*==========================================
  7493. *
  7494. *------------------------------------------*/
  7495. void clif_parse_Restart(int fd, struct map_session_data *sd)
  7496. {
  7497. switch(RFIFOB(fd,2)) {
  7498. case 0x00:
  7499. if (!pc_isdead(sd))
  7500. break;
  7501. pc_setstand(sd);
  7502. pc_setrestartvalue(sd, 3);
  7503. if (pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, 2))
  7504. clif_resurrection(&sd->bl, 1); //If warping fails, send a normal stand up packet.
  7505. break;
  7506. case 0x01:
  7507. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7508. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7509. { //Send to char-server for character selection.
  7510. chrif_charselectreq(sd, session[fd]->client_addr);
  7511. } else {
  7512. WFIFOHEAD(fd,packet_len(0x18b));
  7513. WFIFOW(fd,0)=0x18b;
  7514. WFIFOW(fd,2)=1;
  7515. WFIFOSET(fd,packet_len(0x018b));
  7516. }
  7517. break;
  7518. }
  7519. }
  7520. /*==========================================
  7521. * Transmission of a wisp (S 0096 <len>.w <nick>.24B <message>.?B)
  7522. *------------------------------------------*/
  7523. void clif_parse_Wis(int fd, struct map_session_data* sd)
  7524. {
  7525. char *command, *msg;
  7526. struct map_session_data *dstsd;
  7527. int i=0;
  7528. struct npc_data *npc;
  7529. char split_data[10][50];
  7530. char target[NAME_LENGTH+1];
  7531. char output[256];
  7532. unsigned int len;
  7533. len = RFIFOW(fd,2); //Packet length
  7534. if (len < 28)
  7535. { //Invalid packet, specified size is less than minimum! [Skotlex]
  7536. ShowWarning("Hack on Whisper: %s (AID/CID: %d:%d)!\n", sd->status.name, sd->status.account_id, sd->status.char_id);
  7537. clif_setwaitclose(fd);
  7538. return;
  7539. }
  7540. if (len == 28) return; //Not sure if client really lets you send a blank line.
  7541. len-=28; //Message length
  7542. // 24+3+(RFIFOW(fd,2)-28)+1 <- last 1 is '\0'
  7543. command = (char*)aMallocA((NAME_LENGTH+4+len) * sizeof(char));
  7544. //No need for out of memory checks, malloc.c aborts the map when that happens.
  7545. msg = command;
  7546. msg+= sprintf(command, "%s : ", sd->status.name);
  7547. memcpy(msg, RFIFOP(fd, 28), len);
  7548. mes_len_check(msg, len, CHATBOX_SIZE);
  7549. if ((is_charcommand(fd, sd, command) != CharCommand_None) || (is_atcommand(fd, sd, command) != AtCommand_None)) {
  7550. aFree(command);
  7551. return;
  7552. }
  7553. if (sd->sc.count &&
  7554. (sd->sc.data[SC_BERSERK].timer!=-1 ||
  7555. (sd->sc.data[SC_NOCHAT].timer != -1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT))) {
  7556. aFree(command);
  7557. return;
  7558. }
  7559. if (battle_config.min_chat_delay)
  7560. { //[Skotlex]
  7561. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  7562. aFree(command);
  7563. return;
  7564. }
  7565. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7566. }
  7567. memcpy(&target,RFIFOP(fd, 4),NAME_LENGTH);
  7568. target[NAME_LENGTH]='\0';
  7569. // Chat logging type 'W' / Whisper
  7570. if( log_config.chat&1 || (log_config.chat&4 && !(agit_flag && log_config.chat&64)) )
  7571. log_chat("W", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, msg);
  7572. //-------------------------------------------------------//
  7573. // Lordalfa - Paperboy - To whisper NPC commands //
  7574. //-------------------------------------------------------//
  7575. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) >4)) {
  7576. char *str= target+4; //Skip the NPC: string part.
  7577. if ((npc = npc_name2id(str)))
  7578. {
  7579. char *split;
  7580. str = msg;
  7581. for( i=0; i < 10; ++i )
  7582. {// Splits the message using '#' as separators
  7583. split = strchr(str,'#');
  7584. if( split == NULL )
  7585. { // use the remaining string
  7586. strncpy(split_data[i], str, sizeof(split_data[0])/sizeof(char));
  7587. split_data[i][sizeof(split_data[0])/sizeof(char)-1] = '\0';
  7588. for( ++i; i < 10; ++i )
  7589. split_data[i][0] = '\0';
  7590. break;
  7591. }
  7592. *split = '\0';
  7593. strncpy(split_data[i], str, sizeof(split_data[0])/sizeof(char));
  7594. split_data[i][sizeof(split_data[0])/sizeof(char)-1] = '\0';
  7595. str = split+1;
  7596. }
  7597. for (i=0;i<10;i++)
  7598. {
  7599. sprintf(output, "@whispervar%d$", i);
  7600. set_var(sd,output,(char *) split_data[i]);
  7601. }
  7602. sprintf(output, "%s::OnWhisperGlobal", npc->name);
  7603. npc_event(sd,output,0); // Calls the NPC label
  7604. aFree(command);
  7605. return;
  7606. }
  7607. }
  7608. // Main chat [LuzZza]
  7609. if(strcmpi(target, main_chat_nick) == 0) {
  7610. if(!sd->state.mainchat)
  7611. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7612. else {
  7613. snprintf(output, sizeof(output)/sizeof(char), msg_txt(386), sd->status.name, msg);
  7614. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7615. }
  7616. aFree(command);
  7617. return;
  7618. }
  7619. // searching destination character
  7620. dstsd = map_nick2sd(target);
  7621. // player is not on this map-server
  7622. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7623. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7624. // and if we ask for 'Test', we must not contact 'test' player
  7625. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7626. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
  7627. { // send message to inter-server
  7628. intif_wis_message(sd, target, msg, len);
  7629. aFree(command);
  7630. return;
  7631. }
  7632. // player is on this map-server
  7633. if (dstsd->fd == fd) {
  7634. // if you send to your self, don't send anything to others
  7635. // but, normally, it's impossible!
  7636. clif_wis_message(fd, wisp_server_name,
  7637. "You can not page yourself. Sorry.",
  7638. strlen("You can not page yourself. Sorry.") + 1);
  7639. aFree(command);
  7640. return;
  7641. }
  7642. // otherwise, send message and answer immediately
  7643. if (dstsd->state.ignoreAll) {
  7644. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7645. clif_wis_end(fd, 1); // 1: target character is not loged in
  7646. else
  7647. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7648. aFree(command);
  7649. return;
  7650. }
  7651. // if player ignore the source character
  7652. for(i = 0; i < MAX_IGNORE_LIST &&
  7653. dstsd->ignore[i].name[0] != '\0' &&
  7654. strcmp(dstsd->ignore[i].name, sd->status.name) != 0
  7655. ; i++);
  7656. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  7657. { //Ignored
  7658. clif_wis_end(fd, 2); // 2: ignored by target
  7659. aFree(command);
  7660. return;
  7661. }
  7662. // if source player not found in ignore list
  7663. if(dstsd->away_message[0] != '\0') { // Send away automessage [LuzZza]
  7664. //(Automessage has been sent)
  7665. sprintf(output, "%s %s", msg, msg_txt(543));
  7666. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  7667. clif_wis_end(fd, 0); // 0: success to send wisper
  7668. if(dstsd->state.autotrade)
  7669. //"Away [AT] - \"%s\""
  7670. sprintf(output, msg_txt(544), dstsd->away_message);
  7671. else
  7672. //"Away - \"%s\""
  7673. sprintf(output, msg_txt(545), dstsd->away_message);
  7674. aFree(command);
  7675. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  7676. return;
  7677. }
  7678. // Normal message
  7679. clif_wis_message(dstsd->fd, sd->status.name, msg, len);
  7680. clif_wis_end(fd, 0); // 0: success to send wisper
  7681. aFree(command);
  7682. return;
  7683. }
  7684. /*==========================================
  7685. * /b
  7686. *------------------------------------------*/
  7687. void clif_parse_GMmessage(int fd, struct map_session_data *sd)
  7688. {
  7689. char* mes;
  7690. int size, lv;
  7691. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7692. return;
  7693. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_Broadcast)))
  7694. return;
  7695. size = RFIFOW(fd,2)-4;
  7696. mes = (char*)RFIFOP(fd,4);
  7697. mes_len_check(mes, size, CHAT_SIZE);
  7698. intif_GMmessage(mes, size, 0);
  7699. if(log_config.gm && lv >= log_config.gm) {
  7700. char message[CHAT_SIZE+4];
  7701. sprintf(message, "/b %s", mes);
  7702. log_atcommand(sd, message);
  7703. }
  7704. }
  7705. /*==========================================
  7706. *
  7707. *------------------------------------------*/
  7708. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  7709. {
  7710. struct flooritem_data *fitem;
  7711. int map_object_id;
  7712. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7713. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  7714. do {
  7715. if (pc_isdead(sd)) {
  7716. clif_clearunit_area(&sd->bl, 1);
  7717. break;
  7718. }
  7719. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  7720. break;
  7721. if (pc_cant_act(sd))
  7722. break;
  7723. //Disable cloaking/chasewalking characters from looting [Skotlex]
  7724. if(pc_iscloaking(sd) || pc_ischasewalk(sd))
  7725. break;
  7726. if(sd->sc.count && (
  7727. sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  7728. sd->sc.data[SC_BLADESTOP].timer != -1 ||
  7729. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOITEM))
  7730. )
  7731. break;
  7732. if (!pc_takeitem(sd, fitem))
  7733. break;
  7734. return;
  7735. } while (0);
  7736. // Client REQUIRES a fail packet or you can no longer pick items.
  7737. clif_additem(sd,0,0,6);
  7738. }
  7739. /*==========================================
  7740. *
  7741. *------------------------------------------*/
  7742. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  7743. {
  7744. int item_index, item_amount;
  7745. if (pc_isdead(sd)) {
  7746. clif_clearunit_area(&sd->bl, 1);
  7747. return;
  7748. }
  7749. if (pc_cant_act(sd))
  7750. return;
  7751. if (sd->sc.count && (
  7752. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  7753. sd->sc.data[SC_BLADESTOP].timer != -1 ||
  7754. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOITEM)
  7755. ))
  7756. return;
  7757. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7758. item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7759. if (!pc_dropitem(sd, item_index, item_amount))
  7760. //Because the client does not likes being ignored.
  7761. clif_delitem(sd, item_index,0);
  7762. }
  7763. /*==========================================
  7764. *
  7765. *------------------------------------------*/
  7766. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  7767. {
  7768. int n;
  7769. if (pc_isdead(sd)) {
  7770. clif_clearunit_area(&sd->bl, 1);
  7771. return;
  7772. }
  7773. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  7774. return;
  7775. //This flag enables you to use items while in an NPC. [Skotlex]
  7776. if (sd->npc_id) {
  7777. if (sd->npc_id != sd->npc_item_flag)
  7778. return;
  7779. } else
  7780. if (pc_istrading(sd))
  7781. return;
  7782. pc_delinvincibletimer(sd);
  7783. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  7784. sd->idletime = last_tick;
  7785. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7786. if(n <0 || n >= MAX_INVENTORY)
  7787. return;
  7788. if (!pc_useitem(sd,n))
  7789. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  7790. }
  7791. /*==========================================
  7792. *
  7793. *------------------------------------------*/
  7794. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  7795. {
  7796. int index;
  7797. if(pc_isdead(sd)) {
  7798. clif_clearunit_area(&sd->bl,1);
  7799. return;
  7800. }
  7801. index = RFIFOW(fd,2)-2;
  7802. if (index < 0 || index >= MAX_INVENTORY)
  7803. return; //Out of bounds check.
  7804. if(sd->npc_id) {
  7805. if (sd->npc_id != sd->npc_item_flag)
  7806. return;
  7807. } else if (sd->state.storage_flag || sd->sc.opt1)
  7808. ; //You can equip/unequip stuff while storage is open/under status changes
  7809. else if (pc_cant_act(sd))
  7810. return;
  7811. if(sd->sc.data[SC_BLADESTOP].timer!=-1 || sd->sc.data[SC_BERSERK].timer!=-1 )
  7812. return;
  7813. if(!sd->status.inventory[index].identify) {
  7814. clif_equipitemack(sd,index,0,0); // fail
  7815. return;
  7816. }
  7817. if(!sd->inventory_data[index])
  7818. return;
  7819. if(sd->inventory_data[index]->type == IT_PETARMOR){
  7820. pet_equipitem(sd,index);
  7821. return;
  7822. }
  7823. //Client doesn't send the position for ammo.
  7824. if(sd->inventory_data[index]->type == IT_AMMO)
  7825. pc_equipitem(sd,index,EQP_AMMO);
  7826. else
  7827. pc_equipitem(sd,index,RFIFOW(fd,4));
  7828. }
  7829. /*==========================================
  7830. *
  7831. *------------------------------------------*/
  7832. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  7833. {
  7834. int index;
  7835. if(pc_isdead(sd)) {
  7836. clif_clearunit_area(&sd->bl,1);
  7837. return;
  7838. }
  7839. if (sd->state.storage_flag)
  7840. ; //You can equip/unequip stuff while storage is open.
  7841. else if (pc_cant_act(sd))
  7842. return;
  7843. index = RFIFOW(fd,2)-2;
  7844. pc_unequipitem(sd,index,1);
  7845. }
  7846. /*==========================================
  7847. *
  7848. *------------------------------------------*/
  7849. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  7850. {
  7851. struct block_list *bl;
  7852. if(pc_isdead(sd)) {
  7853. clif_clearunit_area(&sd->bl,1);
  7854. return;
  7855. }
  7856. if (pc_cant_act(sd))
  7857. return;
  7858. bl = map_id2bl(RFIFOL(fd,2));
  7859. if (!bl) return;
  7860. switch (bl->type) {
  7861. case BL_MOB:
  7862. if (!((TBL_MOB *)bl)->nd || !mob_script_callback((TBL_MOB *)bl, &sd->bl, CALLBACK_NPCCLICK))
  7863. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7864. break;
  7865. case BL_PC:
  7866. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7867. break;
  7868. case BL_NPC:
  7869. npc_click(sd,(TBL_NPC*)bl);
  7870. break;
  7871. }
  7872. return;
  7873. }
  7874. /*==========================================
  7875. *
  7876. *------------------------------------------*/
  7877. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  7878. {
  7879. if (sd->state.trading)
  7880. return;
  7881. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  7882. }
  7883. /*==========================================
  7884. *
  7885. *------------------------------------------*/
  7886. void clif_parse_NpcBuyListSend(int fd,struct map_session_data *sd)
  7887. {
  7888. int fail=0,n;
  7889. unsigned short *item_list;
  7890. n = (RFIFOW(fd,2)-4) /4;
  7891. item_list = (unsigned short*)RFIFOP(fd,4);
  7892. if (sd->state.trading|| !sd->npc_shopid)
  7893. fail = 1;
  7894. else
  7895. fail = npc_buylist(sd,n,item_list);
  7896. sd->npc_shopid = 0; //Clear shop data.
  7897. WFIFOHEAD(fd,packet_len(0xca));
  7898. WFIFOW(fd,0)=0xca;
  7899. WFIFOB(fd,2)=fail;
  7900. WFIFOSET(fd,packet_len(0xca));
  7901. }
  7902. /*==========================================
  7903. *
  7904. *------------------------------------------*/
  7905. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  7906. {
  7907. int fail=0,n;
  7908. unsigned short *item_list;
  7909. n = (RFIFOW(fd,2)-4) /4;
  7910. item_list = (unsigned short*)RFIFOP(fd,4);
  7911. if (sd->state.trading || !sd->npc_shopid)
  7912. fail = 1;
  7913. else
  7914. fail = npc_selllist(sd,n,item_list);
  7915. sd->npc_shopid = 0; //Clear shop data.
  7916. WFIFOHEAD(fd,packet_len(0xcb));
  7917. WFIFOW(fd,0)=0xcb;
  7918. WFIFOB(fd,2)=fail;
  7919. WFIFOSET(fd,packet_len(0xcb));
  7920. }
  7921. /*==========================================
  7922. * Chatroom creation request
  7923. * S 00d5 <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7924. *------------------------------------------*/
  7925. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  7926. {
  7927. int len = RFIFOW(fd,2)-15;
  7928. int limit = RFIFOW(fd,4);
  7929. bool pub = (RFIFOB(fd,6) != 0);
  7930. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  7931. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7932. char s_title[CHATROOM_TITLE_SIZE];
  7933. char s_password[CHATROOM_PASS_SIZE];
  7934. if (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOROOM)
  7935. return;
  7936. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  7937. clif_skill_fail(sd,1,0,3);
  7938. return;
  7939. }
  7940. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7941. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7942. chat_createpcchat(sd, s_title, s_password, limit, pub);
  7943. }
  7944. /*==========================================
  7945. * Chatroom join request
  7946. * S 00d9 <chat ID>.l <passwd>.8B
  7947. *------------------------------------------*/
  7948. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  7949. {
  7950. int chatid = RFIFOL(fd,2);
  7951. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  7952. chat_joinchat(sd,chatid,password);
  7953. }
  7954. /*==========================================
  7955. * Chatroom properties adjustment request
  7956. * S 00de <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7957. *------------------------------------------*/
  7958. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  7959. {
  7960. int len = RFIFOW(fd,2)-15;
  7961. int limit = RFIFOW(fd,4);
  7962. bool pub = (RFIFOB(fd,6) != 0);
  7963. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  7964. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7965. char s_title[CHATROOM_TITLE_SIZE];
  7966. char s_password[CHATROOM_PASS_SIZE];
  7967. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7968. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7969. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  7970. }
  7971. /*==========================================
  7972. * S 00e0 ?.l <nick>.24B
  7973. *------------------------------------------*/
  7974. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  7975. {
  7976. //TODO: the first argument seems to be the destination position (always 0) [ultramage]
  7977. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  7978. }
  7979. /*==========================================
  7980. *
  7981. *------------------------------------------*/
  7982. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  7983. {
  7984. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  7985. }
  7986. /*==========================================
  7987. * Request to leave the current chatroom
  7988. * S 00e3
  7989. *------------------------------------------*/
  7990. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  7991. {
  7992. chat_leavechat(sd,0);
  7993. }
  7994. //Handles notifying asker and rejecter of what has just ocurred.
  7995. //Type is used to determine the correct msg_txt to use:
  7996. //0:
  7997. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  7998. {
  7999. char *msg, output[256];
  8000. // Your request has been rejected by autoreject option.
  8001. msg = msg_txt(392);
  8002. clif_disp_onlyself(src, msg, strlen(msg));
  8003. //Notice that a request was rejected.
  8004. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  8005. clif_disp_onlyself(target, output, strlen(output));
  8006. }
  8007. /*==========================================
  8008. * 取引要請を相手に送る
  8009. *------------------------------------------*/
  8010. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8011. {
  8012. struct map_session_data *t_sd;
  8013. t_sd = map_id2sd(RFIFOL(fd,2));
  8014. if(!sd->chatID && pc_cant_act(sd))
  8015. return; //You can trade while in a chatroom.
  8016. // @noask [LuzZza]
  8017. if(t_sd && t_sd->state.noask) {
  8018. clif_noask_sub(sd, t_sd, 0);
  8019. return;
  8020. }
  8021. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 1){
  8022. trade_traderequest(sd,t_sd);
  8023. } else
  8024. clif_skill_fail(sd,1,0,0);
  8025. }
  8026. /*==========================================
  8027. * 取引要請
  8028. *------------------------------------------*/
  8029. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8030. {
  8031. trade_tradeack(sd,RFIFOB(fd,2));
  8032. }
  8033. /*==========================================
  8034. * アイテム追加
  8035. *------------------------------------------*/
  8036. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8037. {
  8038. int index = RFIFOW(fd,2);
  8039. int amount = RFIFOL(fd,4);
  8040. if( index == 0 )
  8041. trade_tradeaddzeny(sd, amount);
  8042. else
  8043. trade_tradeadditem(sd, index, amount);
  8044. }
  8045. /*==========================================
  8046. * アイテム追加完了(ok押し)
  8047. *------------------------------------------*/
  8048. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8049. {
  8050. trade_tradeok(sd);
  8051. }
  8052. /*==========================================
  8053. * 取引キャンセル
  8054. *------------------------------------------*/
  8055. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8056. {
  8057. trade_tradecancel(sd);
  8058. }
  8059. /*==========================================
  8060. * 取引許諾(trade押し)
  8061. *------------------------------------------*/
  8062. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8063. {
  8064. trade_tradecommit(sd);
  8065. }
  8066. /*==========================================
  8067. *
  8068. *------------------------------------------*/
  8069. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8070. {
  8071. pc_stop_attack(sd);
  8072. }
  8073. /*==========================================
  8074. * カートへアイテムを移す
  8075. *------------------------------------------*/
  8076. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8077. {
  8078. if (pc_istrading(sd))
  8079. return;
  8080. if (!pc_iscarton(sd))
  8081. return;
  8082. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8083. }
  8084. /*==========================================
  8085. * カートからアイテムを出す
  8086. *------------------------------------------*/
  8087. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8088. {
  8089. if (!pc_iscarton(sd))
  8090. return;
  8091. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8092. }
  8093. /*==========================================
  8094. * 付属品(鷹,ペコ,カート)をはずす
  8095. *------------------------------------------*/
  8096. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8097. {
  8098. //Can only remove Cart/Riding/Falcon.
  8099. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  8100. }
  8101. /*==========================================
  8102. * チェンジカート
  8103. *------------------------------------------*/
  8104. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8105. {
  8106. int type;
  8107. type = (int)RFIFOW(fd,2);
  8108. if( (type == 5 && sd->status.base_level <= 90) ||
  8109. (type == 4 && sd->status.base_level <= 80) ||
  8110. (type == 3 && sd->status.base_level <= 65) ||
  8111. (type == 2 && sd->status.base_level <= 40) ||
  8112. pc_setcart(sd,type) )
  8113. {
  8114. LOG_SUSPICIOUS(sd,"clif_parse_ChangeCart");
  8115. }
  8116. }
  8117. /*==========================================
  8118. * ステータスアップ
  8119. *------------------------------------------*/
  8120. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8121. {
  8122. pc_statusup(sd,RFIFOW(fd,2));
  8123. }
  8124. /*==========================================
  8125. * スキルレベルアップ
  8126. *------------------------------------------*/
  8127. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8128. {
  8129. pc_skillup(sd,RFIFOW(fd,2));
  8130. }
  8131. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, int skillnum, int skilllv, int target_id)
  8132. {
  8133. int lv;
  8134. if (!hd)
  8135. return;
  8136. if (skillnotok_hom(skillnum, hd)) //[orn]
  8137. return;
  8138. if (hd->bl.id != target_id &&
  8139. skill_get_inf(skillnum)&INF_SELF_SKILL)
  8140. target_id = hd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8141. if (hd->ud.skilltimer != -1) {
  8142. if (skillnum != SA_CASTCANCEL)
  8143. return;
  8144. } else if (DIFF_TICK(tick, hd->ud.canact_tick) < 0)
  8145. return;
  8146. lv = merc_hom_checkskill(hd, skillnum);
  8147. if (skilllv > lv)
  8148. skilllv = lv;
  8149. if (skilllv)
  8150. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  8151. }
  8152. /*==========================================
  8153. * スキル使用(ID指定)
  8154. *------------------------------------------*/
  8155. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  8156. {
  8157. int skillnum, skilllv, tmp, target_id;
  8158. unsigned int tick = gettick();
  8159. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8160. if (skilllv < 1) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8161. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8162. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8163. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8164. sd->idletime = last_tick;
  8165. tmp = skill_get_inf(skillnum);
  8166. if (tmp&INF_GROUND_SKILL || !tmp)
  8167. return; //Using a ground/passive skill on a target? WRONG.
  8168. if (skillnum >= HM_SKILLBASE && skillnum <= HM_SKILLBASE+MAX_HOMUNSKILL) {
  8169. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  8170. return;
  8171. }
  8172. if (pc_cant_act(sd))
  8173. return;
  8174. if (pc_issit(sd))
  8175. return;
  8176. if (skillnotok(skillnum, sd))
  8177. return;
  8178. if (sd->bl.id != target_id && !sd->state.skill_flag && tmp&INF_SELF_SKILL)
  8179. target_id = sd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8180. if (sd->ud.skilltimer != -1) {
  8181. if (skillnum != SA_CASTCANCEL)
  8182. return;
  8183. } else if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8184. clif_skill_fail(sd, skillnum, 4, 0);
  8185. return;
  8186. }
  8187. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  8188. return;
  8189. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8190. target_id = sd->bl.id;
  8191. if(sd->menuskill_id)
  8192. {
  8193. if (sd->menuskill_id == SA_TAMINGMONSTER)
  8194. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8195. else
  8196. if (sd->menuskill_id != SA_AUTOSPELL)
  8197. return; //Can't use skills while a menu is open.
  8198. }
  8199. if (sd->skillitem == skillnum) {
  8200. if (skilllv != sd->skillitemlv)
  8201. skilllv = sd->skillitemlv;
  8202. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8203. return;
  8204. }
  8205. sd->skillitem = sd->skillitemlv = 0;
  8206. if (skillnum == MO_EXTREMITYFIST) {
  8207. if ((sd->sc.data[SC_COMBO].timer == -1 ||
  8208. (sd->sc.data[SC_COMBO].val1 != MO_COMBOFINISH &&
  8209. sd->sc.data[SC_COMBO].val1 != CH_TIGERFIST &&
  8210. sd->sc.data[SC_COMBO].val1 != CH_CHAINCRUSH))) {
  8211. if (!sd->state.skill_flag ) {
  8212. sd->state.skill_flag = 1;
  8213. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8214. return;
  8215. } else if (sd->bl.id == target_id) {
  8216. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8217. return;
  8218. }
  8219. }
  8220. }
  8221. if (skillnum == TK_JUMPKICK) {
  8222. if (sd->sc.data[SC_COMBO].timer == -1 ||
  8223. sd->sc.data[SC_COMBO].val1 != TK_JUMPKICK) {
  8224. if (!sd->state.skill_flag ) {
  8225. sd->state.skill_flag = 1;
  8226. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8227. return;
  8228. } else if (sd->bl.id == target_id) {
  8229. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8230. return;
  8231. }
  8232. }
  8233. }
  8234. if (skillnum >= GD_SKILLBASE) {
  8235. if (sd->state.gmaster_flag)
  8236. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8237. else
  8238. skilllv = 0;
  8239. } else {
  8240. tmp = pc_checkskill(sd, skillnum);
  8241. if (skilllv > tmp)
  8242. skilllv = tmp;
  8243. }
  8244. pc_delinvincibletimer(sd);
  8245. if (skilllv)
  8246. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8247. if (sd->state.skill_flag)
  8248. sd->state.skill_flag = 0;
  8249. }
  8250. /*==========================================
  8251. * スキル使用(場所指定)
  8252. *------------------------------------------*/
  8253. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, int skilllv, int skillnum, int x, int y, int skillmoreinfo)
  8254. {
  8255. int lv;
  8256. unsigned int tick = gettick();
  8257. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8258. sd->idletime = last_tick;
  8259. if (skillnotok(skillnum, sd))
  8260. return;
  8261. if (!(skill_get_inf(skillnum)&INF_GROUND_SKILL))
  8262. return; //Using a target skill on the ground? WRONG.
  8263. if (skillmoreinfo != -1) {
  8264. if (pc_issit(sd)) {
  8265. clif_skill_fail(sd, skillnum, 0, 0);
  8266. return;
  8267. }
  8268. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  8269. memcpy(sd->message, RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8270. sd->message[MESSAGE_SIZE-1] = '\0'; //Overflow protection [Skotlex]
  8271. }
  8272. if (sd->ud.skilltimer != -1)
  8273. return;
  8274. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0)
  8275. {
  8276. clif_skill_fail(sd, skillnum, 4, 0);
  8277. return;
  8278. }
  8279. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  8280. return;
  8281. if(sd->menuskill_id)
  8282. {
  8283. if (sd->menuskill_id == SA_TAMINGMONSTER)
  8284. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8285. else
  8286. if (sd->menuskill_id != SA_AUTOSPELL)
  8287. return; //Can't use skills while a menu is open.
  8288. }
  8289. pc_delinvincibletimer(sd);
  8290. if (sd->skillitem == skillnum) {
  8291. if (skilllv != sd->skillitemlv)
  8292. skilllv = sd->skillitemlv;
  8293. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8294. } else {
  8295. sd->skillitem = sd->skillitemlv = 0;
  8296. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8297. if (skilllv > lv)
  8298. skilllv = lv;
  8299. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8300. }
  8301. }
  8302. }
  8303. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  8304. {
  8305. if (pc_cant_act(sd))
  8306. return;
  8307. if (pc_issit(sd))
  8308. return;
  8309. clif_parse_UseSkillToPosSub(fd, sd,
  8310. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8311. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8312. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8313. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8314. -1 //Skill more info.
  8315. );
  8316. }
  8317. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  8318. {
  8319. if (pc_cant_act(sd))
  8320. return;
  8321. if (pc_issit(sd))
  8322. return;
  8323. clif_parse_UseSkillToPosSub(fd, sd,
  8324. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8325. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8326. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8327. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8328. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8329. );
  8330. }
  8331. /*==========================================
  8332. * スキル使用(map指定)
  8333. *------------------------------------------*/
  8334. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  8335. {
  8336. int skill_num = RFIFOW(fd,2);
  8337. char map_name[MAP_NAME_LENGTH];
  8338. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  8339. if(skill_num != sd->menuskill_id)
  8340. return;
  8341. if (pc_cant_act(sd))
  8342. {
  8343. sd->menuskill_id = sd->menuskill_val = 0;
  8344. return;
  8345. }
  8346. pc_delinvincibletimer(sd);
  8347. skill_castend_map(sd,skill_num,map_name);
  8348. }
  8349. /*==========================================
  8350. * メモ要求
  8351. *------------------------------------------*/
  8352. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8353. {
  8354. if (!pc_isdead(sd))
  8355. pc_memo(sd,-1);
  8356. }
  8357. /*==========================================
  8358. * アイテム合成
  8359. *------------------------------------------*/
  8360. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8361. {
  8362. if (sd->menuskill_id != AM_PHARMACY)
  8363. return;
  8364. if (pc_istrading(sd)) {
  8365. //Make it fail to avoid shop exploits where you sell something different than you see.
  8366. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8367. sd->menuskill_val = sd->menuskill_id = 0;
  8368. return;
  8369. }
  8370. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8371. sd->menuskill_val = sd->menuskill_id = 0;
  8372. }
  8373. /*==========================================
  8374. * 武器修理
  8375. *------------------------------------------*/
  8376. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8377. {
  8378. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8379. return;
  8380. if (pc_istrading(sd)) {
  8381. //Make it fail to avoid shop exploits where you sell something different than you see.
  8382. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8383. sd->menuskill_val = sd->menuskill_id = 0;
  8384. return;
  8385. }
  8386. skill_repairweapon(sd,RFIFOW(fd,2));
  8387. sd->menuskill_val = sd->menuskill_id = 0;
  8388. }
  8389. /*==========================================
  8390. *
  8391. *------------------------------------------*/
  8392. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  8393. {
  8394. int idx;
  8395. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8396. return;
  8397. if (pc_istrading(sd)) {
  8398. //Make it fail to avoid shop exploits where you sell something different than you see.
  8399. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8400. sd->menuskill_val = sd->menuskill_id = 0;
  8401. return;
  8402. }
  8403. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8404. skill_weaponrefine(sd, idx-2);
  8405. sd->menuskill_val = sd->menuskill_id = 0;
  8406. }
  8407. /*==========================================
  8408. *
  8409. *------------------------------------------*/
  8410. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8411. {
  8412. uint8 select;
  8413. select = RFIFOB(fd,6);
  8414. if((select > sd->npc_menu && select != 0xff) || !select){
  8415. ShowWarning("Hack on NPC Select Menu: %s (AID: %d)!\n",sd->status.name,sd->bl.id);
  8416. clif_GM_kick(sd,sd,0);
  8417. } else {
  8418. sd->npc_menu=select;
  8419. npc_scriptcont(sd,RFIFOL(fd,2));
  8420. }
  8421. }
  8422. /*==========================================
  8423. *
  8424. *------------------------------------------*/
  8425. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8426. {
  8427. npc_scriptcont(sd,RFIFOL(fd,2));
  8428. }
  8429. /*==========================================
  8430. *
  8431. *------------------------------------------*/
  8432. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8433. {
  8434. sd->npc_amount=(int)RFIFOL(fd,6);
  8435. npc_scriptcont(sd,RFIFOL(fd,2));
  8436. }
  8437. /*==========================================
  8438. *
  8439. *------------------------------------------*/
  8440. void clif_parse_NpcStringInput(int fd,struct map_session_data *sd)
  8441. {
  8442. short message_len;
  8443. message_len = RFIFOW(fd,2)-7;
  8444. if(message_len < 1)
  8445. return; //Blank message?
  8446. if(message_len >= sizeof(sd->npc_str)){
  8447. ShowWarning("clif: input string too long !\n");
  8448. message_len = sizeof(sd->npc_str);
  8449. }
  8450. // Exploit prevention if crafted packets (without null) is being sent. [Lance]
  8451. memcpy(sd->npc_str,RFIFOP(fd,8),message_len);
  8452. sd->npc_str[message_len-1]=0;
  8453. npc_scriptcont(sd,RFIFOL(fd,4));
  8454. }
  8455. /*==========================================
  8456. *
  8457. *------------------------------------------*/
  8458. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8459. {
  8460. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8461. return;
  8462. npc_scriptcont(sd,RFIFOL(fd,2));
  8463. }
  8464. /*==========================================
  8465. * アイテム鑑定
  8466. *------------------------------------------*/
  8467. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8468. {
  8469. if (sd->menuskill_id != MC_IDENTIFY)
  8470. return;
  8471. skill_identify(sd,RFIFOW(fd,2)-2);
  8472. sd->menuskill_val = sd->menuskill_id = 0;
  8473. }
  8474. /*==========================================
  8475. * 矢作成
  8476. *------------------------------------------*/
  8477. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8478. {
  8479. if (sd->menuskill_id != AC_MAKINGARROW)
  8480. return;
  8481. if (pc_istrading(sd)) {
  8482. //Make it fail to avoid shop exploits where you sell something different than you see.
  8483. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8484. sd->menuskill_val = sd->menuskill_id = 0;
  8485. return;
  8486. }
  8487. skill_arrow_create(sd,RFIFOW(fd,2));
  8488. sd->menuskill_val = sd->menuskill_id = 0;
  8489. }
  8490. /*==========================================
  8491. * オートスペル受信
  8492. *------------------------------------------*/
  8493. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8494. {
  8495. if (sd->menuskill_id != SA_AUTOSPELL)
  8496. return;
  8497. skill_autospell(sd,RFIFOW(fd,2));
  8498. sd->menuskill_val = sd->menuskill_id = 0;
  8499. }
  8500. /*==========================================
  8501. * カード使用
  8502. *------------------------------------------*/
  8503. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8504. {
  8505. if (sd->state.trading != 0)
  8506. return;
  8507. clif_use_card(sd,RFIFOW(fd,2)-2);
  8508. }
  8509. /*==========================================
  8510. * カード挿入装備選択
  8511. *------------------------------------------*/
  8512. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8513. {
  8514. if (sd->state.trading != 0)
  8515. return;
  8516. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8517. }
  8518. /*==========================================
  8519. * 0193 キャラID名前引き
  8520. *------------------------------------------*/
  8521. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  8522. {
  8523. int charid;
  8524. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8525. map_reqnickdb(sd, charid);
  8526. }
  8527. /*==========================================
  8528. * 0197 /resetskill /resetstate
  8529. *------------------------------------------*/
  8530. void clif_parse_ResetChar(int fd, struct map_session_data *sd)
  8531. {
  8532. if (battle_config.atc_gmonly && !pc_isGM(sd))
  8533. return;
  8534. if (pc_isGM(sd) < get_atcommand_level(AtCommand_ResetState))
  8535. return;
  8536. if (RFIFOW(fd,2))
  8537. pc_resetskill(sd,1);
  8538. else
  8539. pc_resetstate(sd);
  8540. if(log_config.gm && get_atcommand_level(AtCommand_ResetState >= log_config.gm))
  8541. log_atcommand(sd, RFIFOW(fd,2) ? "/resetskill" : "/resetstate");
  8542. }
  8543. /*==========================================
  8544. * 019c /lb等
  8545. *------------------------------------------*/
  8546. void clif_parse_LGMmessage(int fd, struct map_session_data *sd)
  8547. {
  8548. unsigned char buf[CHAT_SIZE+4];
  8549. char *mes;
  8550. int len, lv;
  8551. if (battle_config.atc_gmonly && !pc_isGM(sd))
  8552. return;
  8553. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_LocalBroadcast)))
  8554. return;
  8555. len = RFIFOW(fd,2) - 4;
  8556. mes = (char*)RFIFOP(fd,4);
  8557. mes_len_check(mes, len, CHAT_SIZE);
  8558. WBUFW(buf,0) = 0x9a;
  8559. WBUFW(buf,2) = len+4;
  8560. memcpy(WBUFP(buf,4), mes, len);
  8561. clif_send(buf, WBUFW(buf,2), &sd->bl, ALL_SAMEMAP);
  8562. if(log_config.gm && lv >= log_config.gm) {
  8563. char message[CHAT_SIZE+5];
  8564. sprintf(message, "/lb %s", mes);
  8565. log_atcommand(sd, message);
  8566. }
  8567. }
  8568. /*==========================================
  8569. * カプラ倉庫へ入れる
  8570. *------------------------------------------*/
  8571. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  8572. {
  8573. int item_index, item_amount;
  8574. if (pc_istrading(sd))
  8575. return;
  8576. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8577. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8578. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  8579. return;
  8580. if (sd->state.storage_flag == 1)
  8581. storage_storageadd(sd, item_index, item_amount);
  8582. else if (sd->state.storage_flag == 2)
  8583. storage_guild_storageadd(sd, item_index, item_amount);
  8584. }
  8585. /*==========================================
  8586. * カプラ倉庫から出す
  8587. *------------------------------------------*/
  8588. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  8589. {
  8590. int item_index, item_amount;
  8591. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8592. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8593. if (sd->state.storage_flag == 1)
  8594. storage_storageget(sd, item_index, item_amount);
  8595. else if(sd->state.storage_flag == 2)
  8596. storage_guild_storageget(sd, item_index, item_amount);
  8597. }
  8598. /*==========================================
  8599. * カプラ倉庫へカートから入れる
  8600. *------------------------------------------*/
  8601. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  8602. {
  8603. if(sd->vender_id)
  8604. return;
  8605. if (!pc_iscarton(sd))
  8606. return;
  8607. if (sd->state.storage_flag == 1)
  8608. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8609. else if (sd->state.storage_flag == 2)
  8610. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8611. }
  8612. /*==========================================
  8613. * カプラ倉庫から出す
  8614. *------------------------------------------*/
  8615. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  8616. {
  8617. if (sd->vender_id)
  8618. return;
  8619. if (!pc_iscarton(sd))
  8620. return;
  8621. if (sd->state.storage_flag == 1)
  8622. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8623. else if (sd->state.storage_flag == 2)
  8624. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8625. }
  8626. /*==========================================
  8627. * カプラ倉庫を閉じる
  8628. *------------------------------------------*/
  8629. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  8630. {
  8631. if (sd->state.storage_flag == 1)
  8632. storage_storageclose(sd);
  8633. else if (sd->state.storage_flag == 2)
  8634. storage_guild_storageclose(sd);
  8635. }
  8636. /*==========================================
  8637. * Kafra storage protection password system
  8638. *------------------------------------------*/
  8639. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  8640. {
  8641. //TODO
  8642. }
  8643. /*==========================================
  8644. * パーティを作る
  8645. *------------------------------------------*/
  8646. void clif_parse_CreateParty(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. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7) {
  8654. party_create(sd,(char*)RFIFOP(fd,2),0,0);
  8655. } else
  8656. clif_skill_fail(sd,1,0,4);
  8657. }
  8658. /*==========================================
  8659. * パーティを作る
  8660. *------------------------------------------*/
  8661. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  8662. {
  8663. if(map[sd->bl.m].flag.partylock)
  8664. { //Guild locked.
  8665. clif_displaymessage(fd, msg_txt(227));
  8666. return;
  8667. }
  8668. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7)
  8669. party_create(sd,(char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27));
  8670. else
  8671. clif_skill_fail(sd,1,0,4);
  8672. }
  8673. /*==========================================
  8674. * パーティに勧誘
  8675. *------------------------------------------*/
  8676. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  8677. {
  8678. struct map_session_data *t_sd;
  8679. if(map[sd->bl.m].flag.partylock)
  8680. { //Guild locked.
  8681. clif_displaymessage(fd, msg_txt(227));
  8682. return;
  8683. }
  8684. t_sd = map_id2sd(RFIFOL(fd,2));
  8685. // @noask [LuzZza]
  8686. if(t_sd && t_sd->state.noask) {
  8687. clif_noask_sub(sd, t_sd, 1);
  8688. return;
  8689. }
  8690. party_invite(sd, t_sd);
  8691. }
  8692. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  8693. {
  8694. struct map_session_data *t_sd;
  8695. char *name = RFIFOP(fd,2);
  8696. name[NAME_LENGTH]='\0';
  8697. if(map[sd->bl.m].flag.partylock)
  8698. { //Guild locked.
  8699. clif_displaymessage(fd, msg_txt(227));
  8700. return;
  8701. }
  8702. t_sd = map_nick2sd(name);
  8703. // @noask [LuzZza]
  8704. if(t_sd && t_sd->state.noask) {
  8705. clif_noask_sub(sd, t_sd, 1);
  8706. return;
  8707. }
  8708. party_invite(sd, t_sd);
  8709. }
  8710. /*==========================================
  8711. * パーティ勧誘返答
  8712. *------------------------------------------*/
  8713. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  8714. {
  8715. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  8716. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8717. } else {
  8718. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8719. clif_skill_fail(sd,1,0,4);
  8720. }
  8721. }
  8722. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  8723. {
  8724. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  8725. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8726. } else {
  8727. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8728. clif_skill_fail(sd,1,0,4);
  8729. }
  8730. }
  8731. /*==========================================
  8732. * パーティ脱退要求
  8733. *------------------------------------------*/
  8734. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  8735. {
  8736. if(map[sd->bl.m].flag.partylock)
  8737. { //Guild locked.
  8738. clif_displaymessage(fd, msg_txt(227));
  8739. return;
  8740. }
  8741. party_leave(sd);
  8742. }
  8743. /*==========================================
  8744. * パーティ除名要求
  8745. *------------------------------------------*/
  8746. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  8747. {
  8748. if(map[sd->bl.m].flag.partylock)
  8749. { //Guild locked.
  8750. clif_displaymessage(fd, msg_txt(227));
  8751. return;
  8752. }
  8753. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8754. }
  8755. /*==========================================
  8756. * パーティ設定変更要求
  8757. *------------------------------------------*/
  8758. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  8759. {
  8760. struct party_data *p;
  8761. if(!sd->status.party_id)
  8762. return;
  8763. p = party_search(sd->status.party_id);
  8764. if (!p) return;
  8765. //The client no longer can change the item-field, therefore it always
  8766. //comes as zero. Here, resend the item data as it is.
  8767. // party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  8768. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  8769. }
  8770. /*==========================================
  8771. * パーティメッセージ送信要求
  8772. *------------------------------------------*/
  8773. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  8774. {
  8775. char* message;
  8776. int len;
  8777. len = RFIFOW(fd,2) - 4;
  8778. message = (char*)RFIFOP(fd,4);
  8779. mes_len_check(message, len, CHAT_SIZE);
  8780. if (is_charcommand(fd, sd, message) != CharCommand_None || is_atcommand(fd, sd, message) != AtCommand_None)
  8781. return;
  8782. if (sd->sc.data[SC_BERSERK].timer!=-1 || (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT))
  8783. return;
  8784. if (battle_config.min_chat_delay)
  8785. { //[Skotlex]
  8786. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8787. return;
  8788. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8789. }
  8790. party_send_message(sd, message, len);
  8791. }
  8792. /*==========================================
  8793. * 露店閉鎖
  8794. *------------------------------------------*/
  8795. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  8796. {
  8797. vending_closevending(sd);
  8798. }
  8799. /*==========================================
  8800. * 露店アイテムリスト要求
  8801. *------------------------------------------*/
  8802. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  8803. {
  8804. vending_vendinglistreq(sd,RFIFOL(fd,2));
  8805. if( sd->npc_id )
  8806. npc_event_dequeue(sd);
  8807. }
  8808. /*==========================================
  8809. * Shop item(s) purchase request
  8810. * S 0134 <len>.w <ID>.l {<amount>.w <index>.w}.4B*
  8811. *------------------------------------------*/
  8812. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  8813. {
  8814. int len = (int)RFIFOW(fd,2) - 8;
  8815. int id = (int)RFIFOL(fd,4);
  8816. const uint8* data = (uint8*)RFIFOP(fd,8);
  8817. vending_purchasereq(sd, id, data, len/4);
  8818. }
  8819. /*==========================================
  8820. * Confirm or cancel the shop preparation window
  8821. * S 01b2 <len>.w <message>.80B <flag>.B {<index>.w <amount>.w <value>.l}.8B*
  8822. * flag: 0=cancel, 1=confirm
  8823. *------------------------------------------*/
  8824. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  8825. {
  8826. short len = (short)RFIFOW(fd,2) - 85;
  8827. const char* message = (char*)RFIFOP(fd,4);
  8828. bool flag = (bool)RFIFOB(fd,84);
  8829. const uint8* data = (uint8*)RFIFOP(fd,85);
  8830. if (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOROOM)
  8831. return;
  8832. if (map[sd->bl.m].flag.novending) {
  8833. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open shop on this map"
  8834. return;
  8835. }
  8836. if( message[0] == '\0' ) // invalid input
  8837. return;
  8838. vending_openvending(sd, message, flag, data, len/8);
  8839. }
  8840. /*==========================================
  8841. * ギルドを作る
  8842. *------------------------------------------*/
  8843. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  8844. {
  8845. if(map[sd->bl.m].flag.guildlock)
  8846. { //Guild locked.
  8847. clif_displaymessage(fd, msg_txt(228));
  8848. return;
  8849. }
  8850. guild_create(sd, (char*)RFIFOP(fd,6));
  8851. }
  8852. /*==========================================
  8853. * ギルドマスターかどうか確認
  8854. *------------------------------------------*/
  8855. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  8856. {
  8857. clif_guild_masterormember(sd);
  8858. }
  8859. /*==========================================
  8860. * ギルド情報要求
  8861. *------------------------------------------*/
  8862. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  8863. {
  8864. if (!sd->status.guild_id)
  8865. return;
  8866. switch(RFIFOL(fd,2)){
  8867. case 0: // ギルド基本情報、同盟敵対情報
  8868. clif_guild_basicinfo(sd);
  8869. clif_guild_allianceinfo(sd);
  8870. break;
  8871. case 1: // メンバーリスト、役職名リスト
  8872. clif_guild_positionnamelist(sd);
  8873. clif_guild_memberlist(sd);
  8874. break;
  8875. case 2: // 役職名リスト、役職情報リスト
  8876. clif_guild_positionnamelist(sd);
  8877. clif_guild_positioninfolist(sd);
  8878. break;
  8879. case 3: // スキルリスト
  8880. clif_guild_skillinfo(sd);
  8881. break;
  8882. case 4: // 追放リスト
  8883. clif_guild_expulsionlist(sd);
  8884. break;
  8885. default:
  8886. if (battle_config.error_log)
  8887. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  8888. break;
  8889. }
  8890. }
  8891. /*==========================================
  8892. * ギルド役職変更
  8893. *------------------------------------------*/
  8894. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  8895. {
  8896. int i;
  8897. if(!sd->state.gmaster_flag)
  8898. return;
  8899. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  8900. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  8901. }
  8902. }
  8903. /*==========================================
  8904. * ギルドメンバ役職変更
  8905. *------------------------------------------*/
  8906. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  8907. {
  8908. int i;
  8909. if(!sd->state.gmaster_flag)
  8910. return;
  8911. for(i=4;i<RFIFOW(fd,2);i+=12){
  8912. guild_change_memberposition(sd->status.guild_id,
  8913. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  8914. }
  8915. }
  8916. /*==========================================
  8917. * ギルドエンブレム要求
  8918. *------------------------------------------*/
  8919. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  8920. {
  8921. struct guild* g = guild_search(RFIFOL(fd,2));
  8922. if(g!=NULL)
  8923. clif_guild_emblem(sd,g);
  8924. }
  8925. /*==========================================
  8926. * ギルドエンブレム変更
  8927. *------------------------------------------*/
  8928. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  8929. {
  8930. if(!sd->state.gmaster_flag)
  8931. return;
  8932. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  8933. }
  8934. /*==========================================
  8935. * Guild notice update request
  8936. * S 016E <guildID>.l <msg1>.60B <msg2>.120B
  8937. *------------------------------------------*/
  8938. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  8939. {
  8940. int guild_id = RFIFOL(fd,2);
  8941. char* msg1 = (char*)RFIFOP(fd,6);
  8942. char* msg2 = (char*)RFIFOP(fd,66);
  8943. if(!sd->state.gmaster_flag)
  8944. return;
  8945. // compensate for some client defects when using multilanguage mode
  8946. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  8947. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  8948. if (msg2[0] == '|') msg2[strnlen(msg2, 120)-1] = '\0'; // delete extra space at the end of string
  8949. guild_change_notice(sd, guild_id, msg1, msg2);
  8950. }
  8951. /*==========================================
  8952. * ギルド勧誘
  8953. *------------------------------------------*/
  8954. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  8955. {
  8956. struct map_session_data *t_sd;
  8957. if(map[sd->bl.m].flag.guildlock)
  8958. { //Guild locked.
  8959. clif_displaymessage(fd, msg_txt(228));
  8960. return;
  8961. }
  8962. t_sd = map_id2sd(RFIFOL(fd,2));
  8963. // @noask [LuzZza]
  8964. if(t_sd && t_sd->state.noask) {
  8965. clif_noask_sub(sd, t_sd, 2);
  8966. return;
  8967. }
  8968. guild_invite(sd,t_sd);
  8969. }
  8970. /*==========================================
  8971. * ギルド勧誘返信
  8972. *------------------------------------------*/
  8973. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  8974. {
  8975. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8976. }
  8977. /*==========================================
  8978. * ギルド脱退
  8979. *------------------------------------------*/
  8980. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  8981. {
  8982. if(map[sd->bl.m].flag.guildlock)
  8983. { //Guild locked.
  8984. clif_displaymessage(fd, msg_txt(228));
  8985. return;
  8986. }
  8987. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8988. }
  8989. /*==========================================
  8990. * ギルド追放
  8991. *------------------------------------------*/
  8992. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  8993. {
  8994. if(map[sd->bl.m].flag.guildlock)
  8995. { //Guild locked.
  8996. clif_displaymessage(fd, msg_txt(228));
  8997. return;
  8998. }
  8999. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9000. }
  9001. /*==========================================
  9002. * ギルド会話
  9003. *------------------------------------------*/
  9004. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  9005. {
  9006. char* message;
  9007. int len;
  9008. len = RFIFOW(fd,2) - 4;
  9009. message = (char*)RFIFOP(fd,4);
  9010. mes_len_check(message, len, CHAT_SIZE);
  9011. if (is_charcommand(fd, sd, message) != CharCommand_None || is_atcommand(fd, sd, message) != AtCommand_None)
  9012. return;
  9013. if (sd->sc.data[SC_BERSERK].timer!=-1 || (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT))
  9014. return;
  9015. if (battle_config.min_chat_delay)
  9016. { //[Skotlex]
  9017. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9018. return;
  9019. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9020. }
  9021. guild_send_message(sd, message, len);
  9022. }
  9023. /*==========================================
  9024. * ギルド同盟要求
  9025. *------------------------------------------*/
  9026. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  9027. {
  9028. struct map_session_data *t_sd;
  9029. if(!sd->state.gmaster_flag)
  9030. return;
  9031. if(map[sd->bl.m].flag.guildlock)
  9032. { //Guild locked.
  9033. clif_displaymessage(fd, msg_txt(228));
  9034. return;
  9035. }
  9036. t_sd = map_id2sd(RFIFOL(fd,2));
  9037. // @noask [LuzZza]
  9038. if(t_sd && t_sd->state.noask) {
  9039. clif_noask_sub(sd, t_sd, 3);
  9040. return;
  9041. }
  9042. guild_reqalliance(sd,t_sd);
  9043. }
  9044. /*==========================================
  9045. * ギルド同盟要求返信
  9046. *------------------------------------------*/
  9047. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  9048. {
  9049. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9050. }
  9051. /*==========================================
  9052. * ギルド関係解消
  9053. *------------------------------------------*/
  9054. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  9055. {
  9056. if(!sd->state.gmaster_flag)
  9057. return;
  9058. if(map[sd->bl.m].flag.guildlock)
  9059. { //Guild locked.
  9060. clif_displaymessage(fd, msg_txt(228));
  9061. return;
  9062. }
  9063. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9064. }
  9065. /*==========================================
  9066. * ギルド敵対
  9067. *------------------------------------------*/
  9068. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  9069. {
  9070. struct map_session_data *t_sd;
  9071. if(!sd->state.gmaster_flag)
  9072. return;
  9073. if(map[sd->bl.m].flag.guildlock)
  9074. { //Guild locked.
  9075. clif_displaymessage(fd, msg_txt(228));
  9076. return;
  9077. }
  9078. t_sd = map_id2sd(RFIFOL(fd,2));
  9079. // @noask [LuzZza]
  9080. if(t_sd && t_sd->state.noask) {
  9081. clif_noask_sub(sd, t_sd, 4);
  9082. return;
  9083. }
  9084. guild_opposition(sd,t_sd);
  9085. }
  9086. /*==========================================
  9087. * ギルド解散
  9088. *------------------------------------------*/
  9089. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  9090. {
  9091. if(map[sd->bl.m].flag.guildlock)
  9092. { //Guild locked.
  9093. clif_displaymessage(fd, msg_txt(228));
  9094. return;
  9095. }
  9096. guild_break(sd,(char*)RFIFOP(fd,2));
  9097. }
  9098. // pet
  9099. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  9100. {
  9101. pet_menu(sd,RFIFOB(fd,2));
  9102. }
  9103. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  9104. {
  9105. pet_catch_process2(sd,RFIFOL(fd,2));
  9106. }
  9107. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  9108. {
  9109. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  9110. return;
  9111. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9112. sd->menuskill_val = sd->menuskill_id = 0;
  9113. }
  9114. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  9115. {
  9116. if(sd->pd)
  9117. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9118. }
  9119. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  9120. {
  9121. pet_change_name(sd,(char*)RFIFOP(fd,2));
  9122. }
  9123. // Kick (right click menu for GM "(name) force to quit")
  9124. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  9125. {
  9126. struct block_list *target;
  9127. int tid,lv;
  9128. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9129. return;
  9130. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_Kick)))
  9131. return;
  9132. tid = RFIFOL(fd,2);
  9133. target = map_id2bl(tid);
  9134. if (!target) {
  9135. clif_GM_kickack(sd, 0);
  9136. return;
  9137. }
  9138. switch (target->type) {
  9139. case BL_PC:
  9140. {
  9141. struct map_session_data *tsd = (struct map_session_data *)target;
  9142. if (pc_isGM(sd) <= pc_isGM(tsd)) {
  9143. clif_GM_kickack(sd, 0);
  9144. return;
  9145. }
  9146. clif_GM_kick(sd, tsd, 1);
  9147. if(log_config.gm && lv >= log_config.gm) {
  9148. char message[NAME_LENGTH+6];
  9149. sprintf(message, "/kick %d", tsd->status.char_id);
  9150. log_atcommand(sd, message);
  9151. }
  9152. break;
  9153. }
  9154. case BL_MOB:
  9155. status_percent_damage(&sd->bl, target, 100, 0);
  9156. if(log_config.gm && lv >= log_config.gm) {
  9157. char message[NAME_LENGTH+16];
  9158. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9159. log_atcommand(sd, message);
  9160. }
  9161. break;
  9162. default:
  9163. clif_GM_kickack(sd, 0);
  9164. }
  9165. }
  9166. /*==========================================
  9167. * /shift
  9168. *------------------------------------------*/
  9169. void clif_parse_Shift(int fd, struct map_session_data *sd)
  9170. {
  9171. char *player_name;
  9172. int lv;
  9173. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9174. return;
  9175. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_JumpTo)))
  9176. return;
  9177. player_name = (char*)RFIFOP(fd,2);
  9178. player_name[NAME_LENGTH-1] = '\0';
  9179. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9180. if(log_config.gm && lv >= log_config.gm) {
  9181. char message[NAME_LENGTH+7];
  9182. sprintf(message, "/shift %s", player_name);
  9183. log_atcommand(sd, message);
  9184. }
  9185. return;
  9186. }
  9187. /*==========================================
  9188. * /recall
  9189. *------------------------------------------*/
  9190. void clif_parse_Recall(int fd, struct map_session_data *sd)
  9191. {
  9192. char *player_name;
  9193. int lv;
  9194. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9195. return;
  9196. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_Recall)))
  9197. return;
  9198. player_name = (char*)RFIFOP(fd,2);
  9199. player_name[NAME_LENGTH-1] = '\0';
  9200. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9201. if(log_config.gm && lv >= log_config.gm) {
  9202. char message[NAME_LENGTH+8];
  9203. sprintf(message, "/recall %s", player_name);
  9204. log_atcommand(sd, message);
  9205. }
  9206. return;
  9207. }
  9208. /*==========================================
  9209. * /monster /item
  9210. *------------------------------------------*/
  9211. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  9212. {
  9213. char *monster_item_name;
  9214. char message[NAME_LENGTH+10]; //For logging.
  9215. int level;
  9216. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9217. return;
  9218. monster_item_name = (char*)RFIFOP(fd,2);
  9219. monster_item_name[NAME_LENGTH-1] = '\0';
  9220. if (mobdb_searchname(monster_item_name)) {
  9221. if (pc_isGM(sd) < (level=get_atcommand_level(AtCommand_Spawn)))
  9222. return;
  9223. atcommand_monster(fd, sd, "@spawn", monster_item_name); // as @spawn
  9224. if(log_config.gm && level >= log_config.gm)
  9225. { //Log action. [Skotlex]
  9226. snprintf(message, sizeof(message)-1, "@spawn %s", monster_item_name);
  9227. log_atcommand(sd, message);
  9228. }
  9229. return;
  9230. }
  9231. if (itemdb_searchname(monster_item_name) == NULL)
  9232. return;
  9233. if (pc_isGM(sd) < (level = get_atcommand_level(AtCommand_Item)))
  9234. return;
  9235. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9236. if(log_config.gm && level >= log_config.gm)
  9237. { //Log action. [Skotlex]
  9238. sprintf(message, "@item %s", monster_item_name);
  9239. log_atcommand(sd, message);
  9240. }
  9241. }
  9242. /*==========================================
  9243. * /hide
  9244. *------------------------------------------*/
  9245. void clif_parse_GMHide(int fd, struct map_session_data *sd)
  9246. {
  9247. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9248. return;
  9249. if (pc_isGM(sd) < get_atcommand_level(AtCommand_Hide))
  9250. return;
  9251. if (sd->sc.option & OPTION_INVISIBLE) {
  9252. sd->sc.option &= ~OPTION_INVISIBLE;
  9253. if (sd->disguise)
  9254. status_set_viewdata(&sd->bl, sd->disguise);
  9255. else
  9256. status_set_viewdata(&sd->bl, sd->status.class_);
  9257. clif_displaymessage(fd, "Invisible: Off.");
  9258. } else {
  9259. sd->sc.option |= OPTION_INVISIBLE;
  9260. sd->vd.class_ = INVISIBLE_CLASS;
  9261. clif_displaymessage(fd, "Invisible: On.");
  9262. if(log_config.gm && get_atcommand_level(AtCommand_Hide) >= log_config.gm)
  9263. log_atcommand(sd, "/hide");
  9264. }
  9265. clif_changeoption(&sd->bl);
  9266. }
  9267. /*==========================================
  9268. * GMによるチャット禁止時間付与
  9269. *------------------------------------------*/
  9270. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9271. {
  9272. int type, limit, level;
  9273. struct block_list *bl;
  9274. struct map_session_data *dstsd;
  9275. bl = map_id2bl(RFIFOL(fd,2));
  9276. if (!bl || bl->type != BL_PC)
  9277. return;
  9278. dstsd =(struct map_session_data *)bl;
  9279. type = RFIFOB(fd,6);
  9280. limit = RFIFOW(fd,7);
  9281. if (type == 0)
  9282. limit = 0 - limit;
  9283. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  9284. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  9285. if (type == 2/* && sd->bl.id != dstsd->bl.id*/)
  9286. return;
  9287. if (
  9288. ((level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(AtCommand_Mute))
  9289. || (type == 2 && !level))
  9290. {
  9291. clif_GM_silence(sd, dstsd, ((type == 2) ? 1 : type));
  9292. dstsd->status.manner -= limit;
  9293. if(dstsd->status.manner < 0)
  9294. sc_start(bl,SC_NOCHAT,100,0,0);
  9295. else
  9296. {
  9297. dstsd->status.manner = 0;
  9298. status_change_end(bl,SC_NOCHAT,-1);
  9299. }
  9300. }
  9301. return;
  9302. }
  9303. /*==========================================
  9304. * GMによるチャット禁止時間参照(?)
  9305. *------------------------------------------*/
  9306. void clif_parse_GMReqNoChatCount(int fd, struct map_session_data *sd)
  9307. {
  9308. int tid;
  9309. tid = RFIFOL(fd,2);
  9310. WFIFOHEAD(fd,packet_len(0x1e0));
  9311. WFIFOW(fd,0) = 0x1e0;
  9312. WFIFOL(fd,2) = tid;
  9313. sprintf((char*)WFIFOP(fd,6),"%d",tid);
  9314. WFIFOSET(fd, packet_len(0x1e0));
  9315. return;
  9316. }
  9317. static int pstrcmp(const void *a, const void *b)
  9318. {
  9319. char *name1 = (char *)a;
  9320. char *name2 = (char *)b;
  9321. if (name1[0] && name2[0])
  9322. return strcmp(name1, name2);
  9323. //Since names are sorted in ascending order, send blank entries to the bottom.
  9324. if (name1[0])
  9325. return -1;
  9326. if (name2[0])
  9327. return 1;
  9328. return 0;
  9329. }
  9330. void clif_parse_PMIgnore(int fd, struct map_session_data *sd)
  9331. {
  9332. char output[512];
  9333. char *nick; // S 00cf <nick>.24B <type>.B: 00 (/ex nick) deny speech from nick, 01 (/in nick) allow speech from nick
  9334. int i;
  9335. memset(output, '\0', sizeof(output));
  9336. nick = (char*)RFIFOP(fd,2); // speed up
  9337. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name have at maximum 23 characters
  9338. WFIFOHEAD(fd,packet_len(0xd1));
  9339. WFIFOW(fd,0) = 0x0d1; // R 00d1 <type>.B <result>.B: type: 0: deny, 1: allow, result: 0: success, 1: fail 2: list full
  9340. WFIFOB(fd,2) = RFIFOB(fd,26);
  9341. if (RFIFOB(fd,26) == 0)
  9342. { // Add name to ignore list (block)
  9343. // Bot-check...
  9344. if (strcmp(wisp_server_name, nick) == 0)
  9345. { // to find possible bot users who automaticaly ignore people
  9346. 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);
  9347. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9348. WFIFOB(fd,3) = 1; // fail
  9349. WFIFOSET(fd, packet_len(0x0d1));
  9350. return;
  9351. }
  9352. // try to find a free spot, while checking for duplicates at the same time
  9353. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0' && strcmp(sd->ignore[i].name, nick) != 0; i++);
  9354. if (i == MAX_IGNORE_LIST) { // no space for new entry
  9355. WFIFOB(fd,3) = 2; // fail
  9356. WFIFOSET(fd, packet_len(0x0d1));
  9357. return;
  9358. }
  9359. if(sd->ignore[i].name[0] != '\0') { // name already exists
  9360. WFIFOB(fd,3) = 0; // Aegis reports success.
  9361. WFIFOSET(fd, packet_len(0x0d1));
  9362. return;
  9363. }
  9364. //Insert in position i
  9365. memcpy(sd->ignore[i].name, nick, NAME_LENGTH);
  9366. WFIFOB(fd,3) = 0; // success
  9367. WFIFOSET(fd, packet_len(0x0d1));
  9368. //Sort the ignore list.
  9369. //FIXME: why not just use a simple shift-and-insert scheme instead? [ultramage]
  9370. qsort (sd->ignore[0].name, MAX_IGNORE_LIST, sizeof(sd->ignore[0].name), pstrcmp);
  9371. }
  9372. else
  9373. { // Remove name from ignore list (unblock)
  9374. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0' && strcmp(sd->ignore[i].name, nick) != 0; i++);
  9375. if (i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0') { //Not found
  9376. WFIFOB(fd,3) = 1; // fail
  9377. WFIFOSET(fd, packet_len(0x0d1));
  9378. return;
  9379. }
  9380. //Move everything one place down to overwrite removed entry.
  9381. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  9382. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  9383. WFIFOB(fd,3) = 0; // success
  9384. WFIFOSET(fd, packet_len(0x0d1));
  9385. }
  9386. //for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9387. // ShowDebug("Ignored player: '%s'\n", sd->ignore[i].name);
  9388. return;
  9389. }
  9390. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  9391. {
  9392. //printf("Ignore all: state: %d\n", RFIFOB(fd,2));
  9393. // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9394. // S 00d0 <type>len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech
  9395. WFIFOHEAD(fd,packet_len(0xd2));
  9396. WFIFOW(fd,0) = 0x0d2;
  9397. WFIFOB(fd,2) = RFIFOB(fd,2);
  9398. if (RFIFOB(fd,2) == 0) { //Deny all
  9399. if (sd->state.ignoreAll) {
  9400. WFIFOB(fd,3) = 1; // fail
  9401. WFIFOSET(fd, packet_len(0x0d2));
  9402. return;
  9403. }
  9404. sd->state.ignoreAll = 1;
  9405. WFIFOB(fd,3) = 0; // success
  9406. WFIFOSET(fd, packet_len(0x0d2));
  9407. return;
  9408. }
  9409. //Unblock everyone
  9410. if (!sd->state.ignoreAll) {
  9411. if (sd->ignore[0].name[0] != '\0')
  9412. { //Wipe the ignore list.
  9413. memset(sd->ignore, 0, sizeof(sd->ignore));
  9414. WFIFOB(fd,3) = 0;
  9415. WFIFOSET(fd, packet_len(0x0d2));
  9416. return;
  9417. }
  9418. WFIFOB(fd,3) = 1; // fail
  9419. WFIFOSET(fd, packet_len(0x0d2));
  9420. return;
  9421. }
  9422. sd->state.ignoreAll = 0;
  9423. WFIFOB(fd,3) = 0; // success
  9424. WFIFOSET(fd, packet_len(0x0d2));
  9425. return;
  9426. }
  9427. /*==========================================
  9428. * Wis拒否リスト
  9429. *------------------------------------------*/
  9430. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9431. {
  9432. int i;
  9433. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  9434. WFIFOW(fd,0) = 0xd4;
  9435. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9436. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  9437. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  9438. WFIFOSET(fd, WFIFOW(fd,2));
  9439. return;
  9440. }
  9441. /*==========================================
  9442. * スパノビの/doridoriによるSPR2倍
  9443. *------------------------------------------*/
  9444. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  9445. {
  9446. if (sd->state.doridori) return;
  9447. switch (sd->class_&MAPID_UPPERMASK)
  9448. {
  9449. case MAPID_SOUL_LINKER:
  9450. case MAPID_STAR_GLADIATOR:
  9451. case MAPID_TAEKWON:
  9452. if (!sd->state.rest)
  9453. break;
  9454. case MAPID_SUPER_NOVICE:
  9455. sd->state.doridori=1;
  9456. break;
  9457. }
  9458. return;
  9459. }
  9460. /*==========================================
  9461. * スパノビの爆裂波動
  9462. *------------------------------------------*/
  9463. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9464. {
  9465. if(sd){
  9466. int nextbaseexp=pc_nextbaseexp(sd);
  9467. if (battle_config.etc_log){
  9468. if(nextbaseexp != 0)
  9469. 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));
  9470. else
  9471. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9472. }
  9473. 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){
  9474. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9475. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  9476. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9477. }
  9478. }
  9479. return;
  9480. }
  9481. // random notes:
  9482. // 0x214: monster/player info ?
  9483. /*==========================================
  9484. * Friends List
  9485. *------------------------------------------*/
  9486. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9487. { //Toggles a single friend online/offline [Skotlex]
  9488. int i, fd = sd->fd;
  9489. //Seek friend.
  9490. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9491. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9492. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9493. return; //Not found
  9494. WFIFOHEAD(fd,packet_len(0x206));
  9495. WFIFOW(fd, 0) = 0x206;
  9496. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  9497. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  9498. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9499. WFIFOSET(fd, packet_len(0x206));
  9500. }
  9501. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9502. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9503. {
  9504. int account_id, char_id, online;
  9505. account_id = va_arg(ap, int);
  9506. char_id = va_arg(ap, int);
  9507. online = va_arg(ap, int);
  9508. clif_friendslist_toggle(sd, account_id, char_id, online);
  9509. return 0;
  9510. }
  9511. //For sending the whole friends list.
  9512. void clif_friendslist_send(struct map_session_data *sd)
  9513. {
  9514. int i = 0, n, fd = sd->fd;
  9515. // Send friends list
  9516. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  9517. WFIFOW(fd, 0) = 0x201;
  9518. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9519. {
  9520. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9521. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9522. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9523. }
  9524. if (i) {
  9525. WFIFOW(fd,2) = 4 + 32 * i;
  9526. WFIFOSET(fd, WFIFOW(fd,2));
  9527. }
  9528. for (n = 0; n < i; n++)
  9529. { //Sending the online players
  9530. if (map_charid2sd(sd->status.friends[n].char_id))
  9531. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9532. }
  9533. }
  9534. /// Reply for add friend request: (success => type 0)
  9535. /// type=0 : MsgStringTable[821]="You have become friends with (%s)."
  9536. /// type=1 : MsgStringTable[822]="(%s) does not want to be friends with you."
  9537. /// type=2 : MsgStringTable[819]="Your Friend List is full."
  9538. /// type=3 : MsgStringTable[820]="(%s)'s Friend List is full."
  9539. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9540. {
  9541. int fd;
  9542. nullpo_retv(sd);
  9543. fd = sd->fd;
  9544. WFIFOHEAD(fd,packet_len(0x209));
  9545. WFIFOW(fd,0) = 0x209;
  9546. WFIFOW(fd,2) = type;
  9547. if (f_sd)
  9548. {
  9549. WFIFOW(fd,4) = f_sd->status.account_id;
  9550. WFIFOW(fd,8) = f_sd->status.char_id;
  9551. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9552. }
  9553. WFIFOSET(fd, packet_len(0x209));
  9554. }
  9555. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  9556. {
  9557. struct map_session_data *f_sd;
  9558. int i, f_fd;
  9559. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9560. // Friend doesn't exist (no player with this name)
  9561. if (f_sd == NULL) {
  9562. clif_displaymessage(fd, msg_txt(3));
  9563. return;
  9564. }
  9565. // @noask [LuzZza]
  9566. if(f_sd->state.noask) {
  9567. clif_noask_sub(sd, f_sd, 5);
  9568. return;
  9569. }
  9570. // Friend already exists
  9571. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9572. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9573. clif_displaymessage(fd, "Friend already exists.");
  9574. return;
  9575. }
  9576. }
  9577. if (i == MAX_FRIENDS) {
  9578. //No space, list full.
  9579. clif_friendslist_reqack(sd, f_sd, 2);
  9580. return;
  9581. }
  9582. f_fd = f_sd->fd;
  9583. WFIFOHEAD(f_fd,packet_len(0x207));
  9584. WFIFOW(f_fd,0) = 0x207;
  9585. WFIFOL(f_fd,2) = sd->status.account_id;
  9586. WFIFOL(f_fd,6) = sd->status.char_id;
  9587. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9588. WFIFOSET(f_fd, packet_len(0x207));
  9589. return;
  9590. }
  9591. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  9592. {
  9593. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9594. struct map_session_data *f_sd;
  9595. int char_id, account_id;
  9596. char reply;
  9597. account_id = RFIFOL(fd,2);
  9598. char_id = RFIFOL(fd,6);
  9599. reply = RFIFOB(fd,10);
  9600. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9601. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9602. if (f_sd == NULL)
  9603. return;
  9604. if (reply == 0)
  9605. clif_friendslist_reqack(f_sd, sd, 1);
  9606. else {
  9607. int i;
  9608. // Find an empty slot
  9609. for (i = 0; i < MAX_FRIENDS; i++)
  9610. if (f_sd->status.friends[i].char_id == 0)
  9611. break;
  9612. if (i == MAX_FRIENDS) {
  9613. clif_friendslist_reqack(f_sd, sd, 2);
  9614. return;
  9615. }
  9616. f_sd->status.friends[i].account_id = sd->status.account_id;
  9617. f_sd->status.friends[i].char_id = sd->status.char_id;
  9618. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9619. clif_friendslist_reqack(f_sd, sd, 0);
  9620. if (battle_config.friend_auto_add) {
  9621. // Also add f_sd to sd's friendlist.
  9622. for (i = 0; i < MAX_FRIENDS; i++) {
  9623. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  9624. return; //No need to add anything.
  9625. if (sd->status.friends[i].char_id == 0)
  9626. break;
  9627. }
  9628. if (i == MAX_FRIENDS) {
  9629. clif_friendslist_reqack(sd, f_sd, 2);
  9630. return;
  9631. }
  9632. sd->status.friends[i].account_id = f_sd->status.account_id;
  9633. sd->status.friends[i].char_id = f_sd->status.char_id;
  9634. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  9635. clif_friendslist_reqack(sd, f_sd, 0);
  9636. }
  9637. }
  9638. return;
  9639. }
  9640. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  9641. {
  9642. // 0x203 </o> <ID to be removed W 4B>
  9643. int account_id, char_id;
  9644. int i, j;
  9645. account_id = RFIFOL(fd,2);
  9646. char_id = RFIFOL(fd,6);
  9647. // Search friend
  9648. for (i = 0; i < MAX_FRIENDS &&
  9649. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9650. if (i == MAX_FRIENDS) {
  9651. clif_displaymessage(fd, "Name not found in list.");
  9652. return;
  9653. }
  9654. // move all chars down
  9655. for(j = i + 1; j < MAX_FRIENDS; j++)
  9656. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9657. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9658. clif_displaymessage(fd, "Friend removed");
  9659. WFIFOHEAD(fd,packet_len(0x20a));
  9660. WFIFOW(fd,0) = 0x20a;
  9661. WFIFOL(fd,2) = account_id;
  9662. WFIFOL(fd,6) = char_id;
  9663. WFIFOSET(fd, packet_len(0x20a));
  9664. // clif_friendslist_send(sd); //This is not needed anymore.
  9665. return;
  9666. }
  9667. /*==========================================
  9668. * /killall
  9669. *------------------------------------------*/
  9670. void clif_parse_GMKillAll(int fd, struct map_session_data* sd)
  9671. {
  9672. char message[50];
  9673. strncpy(message,sd->status.name, NAME_LENGTH);
  9674. is_atcommand(fd, sd, strcat(message," : @kickall"));
  9675. return;
  9676. }
  9677. /*==========================================
  9678. * /pvpinfo
  9679. *------------------------------------------*/
  9680. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  9681. {
  9682. WFIFOHEAD(fd,packet_len(0x210));
  9683. WFIFOW(fd,0) = 0x210;
  9684. //WFIFOL(fd,2) = 0; // not sure what for yet
  9685. //WFIFOL(fd,6) = 0;
  9686. WFIFOL(fd,10) = sd->pvp_won; // times won
  9687. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  9688. WFIFOL(fd,18) = sd->pvp_point;
  9689. WFIFOSET(fd, packet_len(0x210));
  9690. return;
  9691. }
  9692. /*==========================================
  9693. * /blacksmith
  9694. *------------------------------------------*/
  9695. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  9696. {
  9697. int i;
  9698. const char* name;
  9699. WFIFOHEAD(fd,packet_len(0x219));
  9700. WFIFOW(fd,0) = 0x219;
  9701. //Packet size limits this list to 10 elements. [Skotlex]
  9702. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9703. if (smith_fame_list[i].id > 0) {
  9704. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  9705. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  9706. {
  9707. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  9708. } else
  9709. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  9710. } else
  9711. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  9712. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  9713. }
  9714. for(;i < 10; i++) { //In case the MAX is less than 10.
  9715. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  9716. WFIFOL(fd, 242 + i * 4) = 0;
  9717. }
  9718. WFIFOSET(fd, packet_len(0x219));
  9719. }
  9720. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  9721. {
  9722. int fd = sd->fd;
  9723. WFIFOHEAD(fd,packet_len(0x21b));
  9724. WFIFOW(fd,0) = 0x21b;
  9725. WFIFOL(fd,2) = points;
  9726. WFIFOL(fd,6) = sd->status.fame;
  9727. WFIFOSET(fd, packet_len(0x21b));
  9728. return 0;
  9729. }
  9730. /*==========================================
  9731. * /alchemist
  9732. *------------------------------------------*/
  9733. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  9734. {
  9735. int i;
  9736. const char* name;
  9737. WFIFOHEAD(fd,packet_len(0x21a));
  9738. WFIFOW(fd,0) = 0x21a;
  9739. //Packet size limits this list to 10 elements. [Skotlex]
  9740. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9741. if (chemist_fame_list[i].id > 0) {
  9742. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  9743. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  9744. {
  9745. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9746. } else
  9747. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  9748. } else
  9749. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9750. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  9751. }
  9752. for(;i < 10; i++) { //In case the MAX is less than 10.
  9753. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9754. WFIFOL(fd, 242 + i * 4) = 0;
  9755. }
  9756. WFIFOSET(fd, packet_len(0x21a));
  9757. }
  9758. int clif_fame_alchemist(struct map_session_data *sd, int points)
  9759. {
  9760. int fd = sd->fd;
  9761. WFIFOHEAD(fd,packet_len(0x21c));
  9762. WFIFOW(fd,0) = 0x21c;
  9763. WFIFOL(fd,2) = points;
  9764. WFIFOL(fd,6) = sd->status.fame;
  9765. WFIFOSET(fd, packet_len(0x21c));
  9766. return 0;
  9767. }
  9768. /*==========================================
  9769. * /taekwon
  9770. *------------------------------------------*/
  9771. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  9772. {
  9773. int i;
  9774. const char* name;
  9775. WFIFOHEAD(fd,packet_len(0x226));
  9776. WFIFOW(fd,0) = 0x226;
  9777. //Packet size limits this list to 10 elements. [Skotlex]
  9778. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9779. if (taekwon_fame_list[i].id > 0) {
  9780. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  9781. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  9782. {
  9783. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9784. } else
  9785. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  9786. } else
  9787. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9788. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  9789. }
  9790. for(;i < 10; i++) { //In case the MAX is less than 10.
  9791. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9792. WFIFOL(fd, 242 + i * 4) = 0;
  9793. }
  9794. WFIFOSET(fd, packet_len(0x226));
  9795. }
  9796. int clif_fame_taekwon(struct map_session_data *sd, int points)
  9797. {
  9798. int fd = sd->fd;
  9799. WFIFOHEAD(fd,packet_len(0x224));
  9800. WFIFOW(fd,0) = 0x224;
  9801. WFIFOL(fd,2) = points;
  9802. WFIFOL(fd,6) = sd->status.fame;
  9803. WFIFOSET(fd, packet_len(0x224));
  9804. return 0;
  9805. }
  9806. /*==========================================
  9807. * PK Ranking table?
  9808. *------------------------------------------*/
  9809. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  9810. {
  9811. int i;
  9812. WFIFOHEAD(fd,packet_len(0x238));
  9813. WFIFOW(fd,0) = 0x238;
  9814. for(i=0;i<10;i++){
  9815. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  9816. WFIFOL(fd,i*4+242) = 0;
  9817. }
  9818. WFIFOSET(fd, packet_len(0x238));
  9819. return;
  9820. }
  9821. /*==========================================
  9822. * SG Feel save OK [Komurka]
  9823. *------------------------------------------*/
  9824. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  9825. {
  9826. char feel_var[3][NAME_LENGTH] = {"PC_FEEL_SUN","PC_FEEL_MOON","PC_FEEL_STAR"};
  9827. int i;
  9828. if (sd->menuskill_id != SG_FEEL)
  9829. return;
  9830. i = sd->menuskill_val-1;
  9831. if (i<0 || i > 2) return; //Bug?
  9832. sd->feel_map[i].index = map[sd->bl.m].index;
  9833. sd->feel_map[i].m = sd->bl.m;
  9834. pc_setglobalreg(sd,feel_var[i],map[sd->bl.m].index);
  9835. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  9836. // clif_misceffect2(&sd->bl, 0x1b0);
  9837. // clif_misceffect2(&sd->bl, 0x21f);
  9838. clif_feel_info(sd, i, 0);
  9839. sd->menuskill_val = sd->menuskill_id = 0;
  9840. }
  9841. /*==========================================
  9842. * Question about Star Glaldiator save map [Komurka]
  9843. *------------------------------------------*/
  9844. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv)
  9845. {
  9846. WFIFOHEAD(fd,packet_len(0x253));
  9847. WFIFOW(fd,0)=0x253;
  9848. WFIFOSET(fd, packet_len(0x253));
  9849. sd->menuskill_id = SG_FEEL;
  9850. sd->menuskill_val = skilllv;
  9851. }
  9852. void clif_parse_AdoptRequest(int fd,struct map_session_data *sd)
  9853. {
  9854. //TODO: add somewhere the adopt code, checks for exploits, etc, etc.
  9855. //Missing packets are the client's reply packets to the adopt request one.
  9856. //[Skotlex]
  9857. int account_id;
  9858. struct map_session_data *sd2;
  9859. account_id = RFIFOL(fd,2);
  9860. sd2 = map_id2sd(account_id);
  9861. if(sd2 && sd2->fd && sd2 != sd && sd2->status.party_id == sd->status.party_id) { //FIXME: No checks whatsoever are in place yet!
  9862. fd = sd2->fd;
  9863. WFIFOHEAD(fd,packet_len(0x1f9));
  9864. WFIFOW(fd,0)=0x1f9;
  9865. WFIFOSET(fd, packet_len(0x1f9));
  9866. }
  9867. }
  9868. /*==========================================
  9869. * Homunculus packets
  9870. *------------------------------------------*/
  9871. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  9872. {
  9873. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  9874. }
  9875. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  9876. { //[orn]
  9877. nullpo_retv(sd);
  9878. if(!merc_is_hom_active(sd->hd))
  9879. return;
  9880. unit_walktoxy(&sd->hd->bl, sd->bl.x,sd->bl.y-1, 4);
  9881. }
  9882. void clif_parse_HomMoveTo(int fd,struct map_session_data *sd)
  9883. { //[orn]
  9884. int x,y,cmd;
  9885. nullpo_retv(sd);
  9886. if(!merc_is_hom_active(sd->hd))
  9887. return;
  9888. cmd = RFIFOW(fd,0);
  9889. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  9890. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  9891. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  9892. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  9893. unit_walktoxy(&(sd->hd->bl),x,y,4);
  9894. }
  9895. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  9896. { //[orn]
  9897. if(!merc_is_hom_active(sd->hd))
  9898. return;
  9899. unit_attack(&sd->hd->bl,RFIFOL(fd,6),0) ;
  9900. }
  9901. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  9902. { //[orn]
  9903. int cmd;
  9904. cmd = RFIFOW(fd,0);
  9905. if(!merc_is_hom_active(sd->hd))
  9906. return;
  9907. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  9908. }
  9909. // [Zephyrus Code Modifications]
  9910. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  9911. {
  9912. int item_position;
  9913. nullpo_retv(sd);
  9914. item_position = pc_search_inventory(sd, 7621);
  9915. if (item_position < 0)
  9916. return;
  9917. if (!status_revive(&sd->bl, 100, 100))
  9918. return;
  9919. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  9920. pc_delitem(sd, item_position, 1, 0);
  9921. }
  9922. /*==========================================
  9923. * パケットデバッグ
  9924. *------------------------------------------*/
  9925. void clif_parse_debug(int fd,struct map_session_data *sd)
  9926. {
  9927. int i, cmd, len;
  9928. cmd = RFIFOW(fd,0);
  9929. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  9930. ShowDebug("packet debug 0x%4X\n",cmd);
  9931. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  9932. for(i=0;i<len;i++){
  9933. if((i&15)==0)
  9934. printf("\n%04X ",i);
  9935. printf("%02X ",RFIFOB(fd,i));
  9936. }
  9937. printf("\n");
  9938. }
  9939. /*==========================================
  9940. * Main client packet processing function
  9941. *------------------------------------------*/
  9942. int clif_parse(int fd)
  9943. {
  9944. int cmd, packet_ver, packet_len, err;
  9945. TBL_PC* sd;
  9946. int pnum;
  9947. //TODO apply deplays or disconnect based on packet throughput [FlavioJS]
  9948. // Note: "click masters" can do 80+ clicks in 10 seconds
  9949. for( pnum = 0; pnum < 3; ++pnum )// Limit max packets per cycle to 3 (delay packet spammers) [FlavioJS]
  9950. { // begin main client packet processing loop
  9951. sd = (TBL_PC *)session[fd]->session_data;
  9952. if (session[fd]->eof) {
  9953. if (sd) {
  9954. if (sd->state.autotrade) {
  9955. //Disassociate character from the socket connection.
  9956. session[fd]->session_data = NULL;
  9957. sd->fd = 0;
  9958. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  9959. } else
  9960. if (sd->state.auth) {
  9961. // Player logout display [Valaris]
  9962. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  9963. clif_quitsave(fd, sd);
  9964. } else {
  9965. ShowInfo("Player AID:%d/CID:%d (not authenticated) logged off.\n", sd->bl.id, sd->status.char_id);
  9966. map_quit(sd);
  9967. }
  9968. } else {
  9969. uint32 ip = session[fd]->client_addr;
  9970. ShowInfo("Closed connection from '"CL_WHITE"%d.%d.%d.%d"CL_RESET"'.\n", CONVIP(ip));
  9971. }
  9972. do_close(fd);
  9973. return 0;
  9974. }
  9975. if (RFIFOREST(fd) < 2)
  9976. return 0;
  9977. cmd = RFIFOW(fd,0);
  9978. // identify client's packet version
  9979. if (sd) {
  9980. packet_ver = sd->packet_ver;
  9981. } else {
  9982. // check authentification packet to know packet version
  9983. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  9984. if( err )
  9985. {// failed to identify packet version
  9986. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  9987. err == 1 ? "" :
  9988. err == 2 ? ", possibly for having an invalid account_id" :
  9989. err == 3 ? ", possibly for having an invalid char_id." :
  9990. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  9991. err == 4 ? ", possibly for having an invalid login_id1." :
  9992. err == 5 ? ", possibly for having an invalid client_tick." :
  9993. */
  9994. err == 6 ? ", possibly for having an invalid sex." :
  9995. ". ERROR invalid error code"));
  9996. WFIFOHEAD(fd,packet_len(0x6a));
  9997. WFIFOW(fd,0) = 0x6a;
  9998. WFIFOB(fd,2) = 3; // Rejected from Server
  9999. WFIFOSET(fd,packet_len(0x6a));
  10000. RFIFOSKIP(fd, RFIFOREST(fd));
  10001. clif_setwaitclose(fd);
  10002. return 0;
  10003. }
  10004. }
  10005. // filter out invalid / unsupported packets
  10006. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  10007. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  10008. set_eof(fd);
  10009. return 0;
  10010. }
  10011. // determine real packet length
  10012. packet_len = packet_db[packet_ver][cmd].len;
  10013. if (packet_len == -1) { // variable-length packet
  10014. if (RFIFOREST(fd) < 4)
  10015. return 0;
  10016. packet_len = RFIFOW(fd,2);
  10017. if (packet_len < 4 || packet_len > 32768) {
  10018. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  10019. set_eof(fd);
  10020. return 0;
  10021. }
  10022. }
  10023. if ((int)RFIFOREST(fd) < packet_len)
  10024. return 0; // not enough data received to form the packet
  10025. if (sd && sd->state.waitingdisconnect == 1) {
  10026. // 切断待ちの場合パケットを処理しない
  10027. } else if (packet_db[packet_ver][cmd].func) {
  10028. if (sd && sd->bl.prev == NULL &&
  10029. packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck)
  10030. ; //Only valid packet when player is not on a map is the finish-loading packet.
  10031. else
  10032. if (sd
  10033. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  10034. || packet_db[packet_ver][cmd].func == clif_parse_debug
  10035. ) //Only execute the function when there's an sd (except for debug/wanttoconnect packets)
  10036. packet_db[packet_ver][cmd].func(fd, sd);
  10037. }
  10038. #if DUMP_UNKNOWN_PACKET
  10039. else if (battle_config.error_log)
  10040. {
  10041. int i;
  10042. FILE *fp;
  10043. char packet_txt[256] = "save/packet.txt";
  10044. time_t now;
  10045. dump = 1;
  10046. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10047. ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
  10048. return 1;
  10049. } else {
  10050. time(&now);
  10051. if (sd && sd->state.auth) {
  10052. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  10053. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10054. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10055. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10056. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10057. for(i = 0; i < packet_len; i++) {
  10058. if ((i & 15) == 0)
  10059. fprintf(fp, "\n\t%04X ", i);
  10060. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10061. }
  10062. fprintf(fp, "\n\n");
  10063. fclose(fp);
  10064. }
  10065. }
  10066. #endif
  10067. /* TODO: use utils.c :: dump()
  10068. if (dump) {
  10069. int i;
  10070. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10071. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10072. for(i = 0; i < packet_len; i++) {
  10073. if ((i & 15) == 0)
  10074. printf("\n%04X ",i);
  10075. printf("%02X ", RFIFOB(fd,i));
  10076. }
  10077. printf("\n");
  10078. if (sd && sd->state.auth) {
  10079. if (sd->status.name != NULL)
  10080. printf("\nAccount ID %d, character ID %d, player name %s.\n",
  10081. sd->status.account_id, sd->status.char_id, sd->status.name);
  10082. else
  10083. printf("\nAccount ID %d.\n", sd->bl.id);
  10084. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10085. printf("\nAccount ID %d.\n", sd->bl.id);
  10086. }*/
  10087. RFIFOSKIP(fd, packet_len);
  10088. }; // main loop end
  10089. return 0;
  10090. }
  10091. /*==========================================
  10092. * パケットデータベース読み込み
  10093. *------------------------------------------*/
  10094. static int packetdb_readdb(void)
  10095. {
  10096. FILE *fp;
  10097. char line[1024];
  10098. int ln=0;
  10099. int cmd,i,j,k,packet_ver;
  10100. int max_cmd=-1;
  10101. int skip_ver = 0;
  10102. int warned = 0;
  10103. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  10104. int packet_len_table[MAX_PACKET_DB] = {
  10105. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10109. //#0x0040
  10110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10112. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  10113. #if PACKETVER < 2
  10114. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  10115. #else // 78-7b 亀島以降 lv99エフェクト用
  10116. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  10117. #endif
  10118. //#0x0080
  10119. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  10120. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  10121. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  10122. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  10123. //#0x00C0
  10124. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  10125. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  10126. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  10127. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  10128. //#0x0100
  10129. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  10130. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  10131. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  10132. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  10133. //#0x0140
  10134. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  10135. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  10136. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  10137. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  10138. //#0x0180
  10139. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  10140. #if PACKETVER < 1
  10141. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10142. #else // 196 comodo以降 状態表示アイコン用
  10143. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10144. #endif
  10145. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  10146. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  10147. //#0x01C0, Set 0x1d5=-1
  10148. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  10149. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  10150. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  10151. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  10152. //#0x0200
  10153. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  10154. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  10155. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  10156. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1, -1, 4, 2,
  10157. //#0x0240
  10158. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  10159. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4, -1, 4, 0,
  10160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10162. //#0x0280
  10163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0,
  10164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10166. 0, 0, 0, 0, 0, 0, 0, 0, 0,191, 0, 0, 0, 0, 0, 0,
  10167. //#0x02C0
  10168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10172. };
  10173. struct {
  10174. void (*func)(int, struct map_session_data *);
  10175. char *name;
  10176. } clif_parse_func[]={
  10177. {clif_parse_WantToConnection,"wanttoconnection"},
  10178. {clif_parse_LoadEndAck,"loadendack"},
  10179. {clif_parse_TickSend,"ticksend"},
  10180. {clif_parse_WalkToXY,"walktoxy"},
  10181. {clif_parse_QuitGame,"quitgame"},
  10182. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  10183. {clif_parse_GlobalMessage,"globalmessage"},
  10184. {clif_parse_MapMove,"mapmove"},
  10185. {clif_parse_ChangeDir,"changedir"},
  10186. {clif_parse_Emotion,"emotion"},
  10187. {clif_parse_HowManyConnections,"howmanyconnections"},
  10188. {clif_parse_ActionRequest,"actionrequest"},
  10189. {clif_parse_Restart,"restart"},
  10190. {clif_parse_Wis,"wis"},
  10191. {clif_parse_GMmessage,"gmmessage"},
  10192. {clif_parse_TakeItem,"takeitem"},
  10193. {clif_parse_DropItem,"dropitem"},
  10194. {clif_parse_UseItem,"useitem"},
  10195. {clif_parse_EquipItem,"equipitem"},
  10196. {clif_parse_UnequipItem,"unequipitem"},
  10197. {clif_parse_NpcClicked,"npcclicked"},
  10198. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  10199. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  10200. {clif_parse_NpcSellListSend,"npcselllistsend"},
  10201. {clif_parse_CreateChatRoom,"createchatroom"},
  10202. {clif_parse_ChatAddMember,"chataddmember"},
  10203. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  10204. {clif_parse_ChangeChatOwner,"changechatowner"},
  10205. {clif_parse_KickFromChat,"kickfromchat"},
  10206. {clif_parse_ChatLeave,"chatleave"},
  10207. {clif_parse_TradeRequest,"traderequest"},
  10208. {clif_parse_TradeAck,"tradeack"},
  10209. {clif_parse_TradeAddItem,"tradeadditem"},
  10210. {clif_parse_TradeOk,"tradeok"},
  10211. {clif_parse_TradeCancel,"tradecancel"},
  10212. {clif_parse_TradeCommit,"tradecommit"},
  10213. {clif_parse_StopAttack,"stopattack"},
  10214. {clif_parse_PutItemToCart,"putitemtocart"},
  10215. {clif_parse_GetItemFromCart,"getitemfromcart"},
  10216. {clif_parse_RemoveOption,"removeoption"},
  10217. {clif_parse_ChangeCart,"changecart"},
  10218. {clif_parse_StatusUp,"statusup"},
  10219. {clif_parse_SkillUp,"skillup"},
  10220. {clif_parse_UseSkillToId,"useskilltoid"},
  10221. {clif_parse_UseSkillToPos,"useskilltopos"},
  10222. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  10223. {clif_parse_UseSkillMap,"useskillmap"},
  10224. {clif_parse_RequestMemo,"requestmemo"},
  10225. {clif_parse_ProduceMix,"producemix"},
  10226. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  10227. {clif_parse_NpcNextClicked,"npcnextclicked"},
  10228. {clif_parse_NpcAmountInput,"npcamountinput"},
  10229. {clif_parse_NpcStringInput,"npcstringinput"},
  10230. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  10231. {clif_parse_ItemIdentify,"itemidentify"},
  10232. {clif_parse_SelectArrow,"selectarrow"},
  10233. {clif_parse_AutoSpell,"autospell"},
  10234. {clif_parse_UseCard,"usecard"},
  10235. {clif_parse_InsertCard,"insertcard"},
  10236. {clif_parse_RepairItem,"repairitem"},
  10237. {clif_parse_WeaponRefine,"weaponrefine"},
  10238. {clif_parse_SolveCharName,"solvecharname"},
  10239. {clif_parse_ResetChar,"resetchar"},
  10240. {clif_parse_LGMmessage,"lgmmessage"},
  10241. {clif_parse_MoveToKafra,"movetokafra"},
  10242. {clif_parse_MoveFromKafra,"movefromkafra"},
  10243. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  10244. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  10245. {clif_parse_CloseKafra,"closekafra"},
  10246. {clif_parse_CreateParty,"createparty"},
  10247. {clif_parse_CreateParty2,"createparty2"},
  10248. {clif_parse_PartyInvite,"partyinvite"},
  10249. {clif_parse_PartyInvite2,"partyinvite2"},
  10250. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  10251. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  10252. {clif_parse_LeaveParty,"leaveparty"},
  10253. {clif_parse_RemovePartyMember,"removepartymember"},
  10254. {clif_parse_PartyChangeOption,"partychangeoption"},
  10255. {clif_parse_PartyMessage,"partymessage"},
  10256. {clif_parse_CloseVending,"closevending"},
  10257. {clif_parse_VendingListReq,"vendinglistreq"},
  10258. {clif_parse_PurchaseReq,"purchasereq"},
  10259. {clif_parse_OpenVending,"openvending"},
  10260. {clif_parse_CreateGuild,"createguild"},
  10261. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  10262. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  10263. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  10264. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  10265. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  10266. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  10267. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  10268. {clif_parse_GuildInvite,"guildinvite"},
  10269. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  10270. {clif_parse_GuildLeave,"guildleave"},
  10271. {clif_parse_GuildExpulsion,"guildexplusion"},
  10272. {clif_parse_GuildMessage,"guildmessage"},
  10273. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  10274. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  10275. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  10276. {clif_parse_GuildOpposition,"guildopposition"},
  10277. {clif_parse_GuildBreak,"guildbreak"},
  10278. {clif_parse_PetMenu,"petmenu"},
  10279. {clif_parse_CatchPet,"catchpet"},
  10280. {clif_parse_SelectEgg,"selectegg"},
  10281. {clif_parse_SendEmotion,"sendemotion"},
  10282. {clif_parse_ChangePetName,"changepetname"},
  10283. {clif_parse_GMKick,"gmkick"},
  10284. {clif_parse_GMHide,"gmhide"},
  10285. {clif_parse_GMReqNoChat,"gmreqnochat"},
  10286. {clif_parse_GMReqNoChatCount,"gmreqnochatcount"},
  10287. {clif_parse_NoviceDoriDori,"sndoridori"},
  10288. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  10289. {clif_parse_PMIgnore,"wisexin"},
  10290. {clif_parse_PMIgnoreList,"wisexlist"},
  10291. {clif_parse_PMIgnoreAll,"wisall"},
  10292. {clif_parse_FriendsListAdd,"friendslistadd"},
  10293. {clif_parse_FriendsListRemove,"friendslistremove"},
  10294. {clif_parse_FriendsListReply,"friendslistreply"},
  10295. {clif_parse_GMKillAll,"killall"},
  10296. {clif_parse_Recall,"summon"},
  10297. {clif_parse_GM_Monster_Item,"itemmonster"},
  10298. {clif_parse_Shift,"shift"},
  10299. {clif_parse_Blacksmith,"blacksmith"},
  10300. {clif_parse_Alchemist,"alchemist"},
  10301. {clif_parse_Taekwon,"taekwon"},
  10302. {clif_parse_RankingPk,"rankingpk"},
  10303. {clif_parse_FeelSaveOk,"feelsaveok"},
  10304. {clif_parse_AdoptRequest,"adopt"},
  10305. {clif_parse_debug,"debug"},
  10306. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  10307. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  10308. {clif_parse_HomMoveTo,"hommoveto"},
  10309. {clif_parse_HomAttack,"homattack"},
  10310. {clif_parse_HomMenu,"hommenu"},
  10311. {clif_parse_StoragePassword,"storagepassword"},
  10312. {clif_parse_Hotkey,"hotkey"},
  10313. {clif_parse_AutoRevive,"autorevive"},
  10314. {NULL,NULL}
  10315. };
  10316. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  10317. memset(packet_db,0,sizeof(packet_db));
  10318. for( i = 0; i < sizeof(packet_len_table)/sizeof(packet_len_table[0]); ++i )
  10319. packet_len(i) = packet_len_table[i];
  10320. sprintf(line, "%s/packet_db.txt", db_path);
  10321. if( (fp=fopen(line,"r"))==NULL ){
  10322. ShowFatalError("can't read %s\n", line);
  10323. exit(1);
  10324. }
  10325. clif_config.packet_db_ver = MAX_PACKET_VER;
  10326. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  10327. while( fgets(line, sizeof(line), fp) )
  10328. {
  10329. ln++;
  10330. if(line[0]=='/' && line[1]=='/')
  10331. continue;
  10332. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  10333. {
  10334. if(strcmpi(w1,"packet_ver")==0) {
  10335. int prev_ver = packet_ver;
  10336. skip_ver = 0;
  10337. packet_ver = atoi(w2);
  10338. if ( packet_ver > MAX_PACKET_VER )
  10339. { //Check to avoid overflowing. [Skotlex]
  10340. if( (warned&1) == 0 )
  10341. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  10342. warned &= 1;
  10343. skip_ver = 1;
  10344. }
  10345. else if( packet_ver < 0 )
  10346. {
  10347. if( (warned&2) == 0 )
  10348. ShowWarning("Negative packet versions are not supported.\n");
  10349. warned &= 2;
  10350. skip_ver = 1;
  10351. }
  10352. else if( packet_ver == SERVER )
  10353. {
  10354. if( (warned&4) == 0 )
  10355. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  10356. warned &= 4;
  10357. skip_ver = 1;
  10358. }
  10359. if( skip_ver )
  10360. {
  10361. ShowWarning("Skipping packet version %d.\n", packet_ver);
  10362. packet_ver = prev_ver;
  10363. continue;
  10364. }
  10365. // copy from previous version into new version and continue
  10366. // - indicating all following packets should be read into the newer version
  10367. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  10368. continue;
  10369. } else if(strcmpi(w1,"packet_db_ver")==0) {
  10370. if(strcmpi(w2,"default")==0) //This is the preferred version.
  10371. clif_config.packet_db_ver = MAX_PACKET_VER;
  10372. else // to manually set the packet DB version
  10373. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  10374. continue;
  10375. }
  10376. }
  10377. if( skip_ver != 0 )
  10378. continue; // Skipping current packet version
  10379. memset(str,0,sizeof(str));
  10380. for(j=0,p=line;j<4 && p; ++j)
  10381. {
  10382. str[j]=p;
  10383. p=strchr(p,',');
  10384. if(p) *p++=0;
  10385. }
  10386. if(str[0]==NULL)
  10387. continue;
  10388. cmd=strtol(str[0],(char **)NULL,0);
  10389. if(max_cmd < cmd)
  10390. max_cmd = cmd;
  10391. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  10392. continue;
  10393. if(str[1]==NULL){
  10394. ShowError("packet_db: packet len error\n");
  10395. continue;
  10396. }
  10397. k = atoi(str[1]);
  10398. packet_db[packet_ver][cmd].len = k;
  10399. if(str[2]==NULL){
  10400. packet_db[packet_ver][cmd].func = NULL;
  10401. ln++;
  10402. continue;
  10403. }
  10404. for(j=0;j<sizeof(clif_parse_func)/sizeof(clif_parse_func[0]);j++){
  10405. if(clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0)
  10406. {
  10407. if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func)
  10408. { //If we are updating a function, we need to zero up the previous one. [Skotlex]
  10409. for(i=0;i<=MAX_PACKET_DB;i++){
  10410. if (packet_db[packet_ver][i].func == clif_parse_func[j].func)
  10411. {
  10412. memset(&packet_db[packet_ver][i], 0, sizeof(struct s_packet_db));
  10413. break;
  10414. }
  10415. }
  10416. }
  10417. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  10418. break;
  10419. }
  10420. }
  10421. // set the identifying cmd for the packet_db version
  10422. if (strcmp(str[2],"wanttoconnection")==0)
  10423. clif_config.connect_cmd[packet_ver] = cmd;
  10424. if(str[3]==NULL){
  10425. ShowError("packet_db: packet error\n");
  10426. exit(1);
  10427. }
  10428. for(j=0,p2=str[3];p2;j++){
  10429. str2[j]=p2;
  10430. p2=strchr(p2,':');
  10431. if(p2) *p2++=0;
  10432. k = atoi(str2[j]);
  10433. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  10434. packet_db[packet_ver][cmd].pos[j] = k;
  10435. }
  10436. }
  10437. fclose(fp);
  10438. if(max_cmd > MAX_PACKET_DB)
  10439. {
  10440. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  10441. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  10442. }
  10443. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  10444. { //Locate the nearest version that we still support. [Skotlex]
  10445. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  10446. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  10447. }
  10448. 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);
  10449. return 0;
  10450. }
  10451. /*==========================================
  10452. *
  10453. *------------------------------------------*/
  10454. int do_init_clif(void)
  10455. {
  10456. clif_config.packet_db_ver = -1; // the main packet version of the DB
  10457. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  10458. memset(packet_db,0,sizeof(packet_db));
  10459. //Using the packet_db file is the only way to set up packets now [Skotlex]
  10460. packetdb_readdb();
  10461. set_defaultparse(clif_parse);
  10462. if (!make_listen_bind(bind_ip,map_port)) {
  10463. ShowFatalError("can't bind game port\n");
  10464. exit(1);
  10465. }
  10466. add_timer_func_list(clif_waitclose, "clif_waitclose");
  10467. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  10468. add_timer_func_list(clif_delayquit, "clif_delayquit");
  10469. return 0;
  10470. }