clif.c 322 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "../common/cbasetypes.h"
  4. #include "../common/socket.h"
  5. #include "../common/timer.h"
  6. #include "../common/malloc.h"
  7. #include "../common/version.h"
  8. #include "../common/nullpo.h"
  9. #include "../common/showmsg.h"
  10. #include "../common/strlib.h"
  11. #include "../common/utils.h"
  12. #include "map.h"
  13. #include "chrif.h"
  14. #include "pc.h"
  15. #include "status.h"
  16. #include "npc.h"
  17. #include "itemdb.h"
  18. #include "chat.h"
  19. #include "trade.h"
  20. #include "storage.h"
  21. #include "script.h"
  22. #include "skill.h"
  23. #include "atcommand.h"
  24. #include "charcommand.h"
  25. #include "intif.h"
  26. #include "battle.h"
  27. #include "mob.h"
  28. #include "party.h"
  29. #include "unit.h"
  30. #include "guild.h"
  31. #include "vending.h"
  32. #include "pet.h"
  33. #include "mercenary.h" //[orn]
  34. #include "log.h"
  35. #include "irc.h"
  36. #include "clif.h"
  37. #include "mail.h"
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include <stdarg.h>
  42. #include <time.h>
  43. #define DUMP_UNKNOWN_PACKET 0
  44. struct Clif_Config {
  45. int packet_db_ver; //Preferred packet version.
  46. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  47. } clif_config;
  48. struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
  49. //Converts item type in case of pet eggs.
  50. #define itemtype(a) (a == IT_PETEGG)?IT_WEAPON:a
  51. #define WBUFPOS(p,pos,x,y,dir) \
  52. do { \
  53. uint8 *__p = (p); \
  54. __p+=(pos); \
  55. __p[0] = (uint8)((x)>>2); \
  56. __p[1] = (uint8)(((x)<<6) | (((y)>>4)&0x3f)); \
  57. __p[2] = (uint8)(((y)<<4) | ((dir)&0xf)); \
  58. } while(0)
  59. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  60. #define WBUFPOS2(p,pos,x0,y0,x1,y1,sx0,sy0) \
  61. do { \
  62. uint8 *__p = (p); \
  63. __p+=(pos); \
  64. __p[0]=(uint8)((x0)>>2); \
  65. __p[1]=(uint8)(((x0)<<6) | (((y0)>>4)&0x3f)); \
  66. __p[2]=(uint8)(((y0)<<4) | (((x1)>>6)&0x0f)); \
  67. __p[3]=(uint8)(((x1)<<2) | (((y1)>>8)&0x03)); \
  68. __p[4]=(uint8)(y1); \
  69. __p[5]=(uint8)(((sx0)<<4) | ((sy0)&0x0f)); \
  70. } while(0)
  71. #define WFIFOPOS(fd,pos,x,y,dir) WBUFPOS(WFIFOP(fd,pos),0,x,y,dir)
  72. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1,sx0,sy0) WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1,sx0,sy0)
  73. //To idenfity disguised characters.
  74. #define disguised(bl) ((bl)->type==BL_PC && ((TBL_PC*)bl)->disguise)
  75. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex\]
  76. #define mes_len_check(mes, len, max) if (len > max) { mes[max-1] = '\0'; len = max; } else mes[len-1] = '\0';
  77. static char map_ip_str[128];
  78. static uint32 map_ip;
  79. static uint32 bind_ip = INADDR_ANY;
  80. static uint16 map_port = 5121;
  81. int map_fd;
  82. //These two will be used to verify the incoming player's validity.
  83. //It helps identify their client packet version correctly. [Skotlex]
  84. static int max_account_id = DEFAULT_MAX_ACCOUNT_ID;
  85. static int max_char_id = DEFAULT_MAX_CHAR_ID;
  86. int clif_parse (int fd);
  87. /*==========================================
  88. * map鯖のip設定
  89. *------------------------------------------*/
  90. int clif_setip(const char* ip)
  91. {
  92. char ip_str[16];
  93. map_ip = host2ip(ip);
  94. if (!map_ip) {
  95. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  96. return 0;
  97. }
  98. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  99. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  100. return 1;
  101. }
  102. void clif_setbindip(const char* ip)
  103. {
  104. char ip_str[16];
  105. bind_ip = host2ip(ip);
  106. if (bind_ip) {
  107. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  108. } else {
  109. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  110. }
  111. }
  112. /*==========================================
  113. * map鯖のport設定
  114. *------------------------------------------*/
  115. void clif_setport(uint16 port)
  116. {
  117. map_port = port;
  118. }
  119. /*==========================================
  120. * map鯖のip読み出し
  121. *------------------------------------------*/
  122. uint32 clif_getip(void)
  123. {
  124. return map_ip;
  125. }
  126. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  127. uint32 clif_refresh_ip(void)
  128. {
  129. uint32 new_ip;
  130. new_ip = host2ip(map_ip_str);
  131. if (new_ip && new_ip != map_ip) {
  132. map_ip = new_ip;
  133. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  134. return map_ip;
  135. }
  136. return 0;
  137. }
  138. /*==========================================
  139. * map鯖のport読み出し
  140. *------------------------------------------*/
  141. uint16 clif_getport(void)
  142. {
  143. return map_port;
  144. }
  145. /*==========================================
  146. * Counts connected players.
  147. *------------------------------------------*/
  148. int clif_countusers(void)
  149. {
  150. int users = 0, i;
  151. struct map_session_data *sd;
  152. for(i = 0; i < fd_max; i++) {
  153. if (session[i] && session[i]->func_parse == clif_parse &&
  154. (sd = (struct map_session_data*)session[i]->session_data) &&
  155. sd->state.auth && !(battle_config.hide_GM_session && pc_isGM(sd)))
  156. users++;
  157. }
  158. return users;
  159. }
  160. /*==========================================
  161. * 全てのclientに対してfunc()実行
  162. *------------------------------------------*/
  163. int clif_foreachclient(int (*func)(struct map_session_data*, va_list),...) //recoded by sasuke, bug when player count gets higher [Kevin]
  164. {
  165. int i;
  166. va_list ap;
  167. struct map_session_data *sd;
  168. va_start(ap,func);
  169. for(i = 0; i < fd_max; i++) {
  170. if ( session[i] && session[i]->func_parse == clif_parse) {
  171. sd = (struct map_session_data*)session[i]->session_data;
  172. if ( sd && sd->state.auth && !sd->state.waitingdisconnect )
  173. func(sd, ap);
  174. }
  175. }
  176. va_end(ap);
  177. return 0;
  178. }
  179. /*==========================================
  180. * clif_sendでAREA*指定時用
  181. *------------------------------------------*/
  182. int clif_send_sub(struct block_list *bl, va_list ap)
  183. {
  184. struct block_list *src_bl;
  185. struct map_session_data *sd;
  186. unsigned char *buf;
  187. int len, type, fd;
  188. nullpo_retr(0, bl);
  189. nullpo_retr(0, ap);
  190. nullpo_retr(0, sd = (struct map_session_data *)bl);
  191. fd = sd->fd;
  192. if (!fd) //Don't send to disconnected clients.
  193. return 0;
  194. buf = va_arg(ap,unsigned char*);
  195. len = va_arg(ap,int);
  196. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  197. type = va_arg(ap,int);
  198. switch(type)
  199. {
  200. case AREA_WOS:
  201. if (bl == src_bl)
  202. return 0;
  203. break;
  204. case AREA_WOC:
  205. if (sd->chatID || bl == src_bl)
  206. return 0;
  207. break;
  208. case AREA_WOSC:
  209. {
  210. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  211. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  212. return 0;
  213. }
  214. break;
  215. }
  216. if (session[fd] != NULL) {
  217. WFIFOHEAD(fd, len);
  218. if (WFIFOP(fd,0) == buf) {
  219. ShowError("WARNING: Invalid use of clif_send function\n");
  220. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  221. ShowError(" Please correct your code.\n");
  222. // don't send to not move the pointer of the packet for next sessions in the loop
  223. WFIFOSET(fd,0);//## TODO is this ok?
  224. } else {
  225. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  226. memcpy(WFIFOP(fd,0), buf, len);
  227. WFIFOSET(fd,len);
  228. }
  229. }
  230. }
  231. return 0;
  232. }
  233. /*==========================================
  234. *
  235. *------------------------------------------*/
  236. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  237. {
  238. int i;
  239. struct map_session_data *sd;
  240. struct party_data *p = NULL;
  241. struct guild *g = NULL;
  242. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  243. if( type != ALL_CLIENT && type != CHAT_MAINCHAT )
  244. nullpo_retr(0, bl);
  245. BL_CAST(BL_PC, bl, sd);
  246. switch(type) {
  247. case ALL_CLIENT: //All player clients.
  248. for (i = 0; i < fd_max; i++) {
  249. if (session[i] && session[i]->func_parse == clif_parse &&
  250. (sd = (struct map_session_data *)session[i]->session_data) != NULL&&
  251. sd->state.auth) {
  252. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  253. WFIFOHEAD(i, len);
  254. memcpy(WFIFOP(i,0), buf, len);
  255. WFIFOSET(i,len);
  256. }
  257. }
  258. }
  259. break;
  260. case ALL_SAMEMAP: //All players on the same map
  261. for(i = 0; i < fd_max; i++) {
  262. if (session[i] && session[i]->func_parse == clif_parse &&
  263. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  264. sd->state.auth && sd->bl.m == bl->m) {
  265. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  266. WFIFOHEAD(i,len);
  267. memcpy(WFIFOP(i,0), buf, len);
  268. WFIFOSET(i,len);
  269. }
  270. }
  271. }
  272. break;
  273. case AREA:
  274. case AREA_WOSC:
  275. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  276. clif_send (buf, len, bl, SELF);
  277. case AREA_WOC:
  278. case AREA_WOS:
  279. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  280. BL_PC, buf, len, bl, type);
  281. break;
  282. case AREA_CHAT_WOC:
  283. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  284. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  285. break;
  286. case CHAT:
  287. case CHAT_WOS:
  288. {
  289. struct chat_data *cd;
  290. if (sd) {
  291. cd = (struct chat_data*)map_id2bl(sd->chatID);
  292. } else if (bl->type == BL_CHAT) {
  293. cd = (struct chat_data*)bl;
  294. } else break;
  295. if (cd == NULL)
  296. break;
  297. for(i = 0; i < cd->users; i++) {
  298. if (type == CHAT_WOS && cd->usersd[i] == sd)
  299. continue;
  300. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  301. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  302. {
  303. WFIFOHEAD(fd,len);
  304. memcpy(WFIFOP(fd,0), buf, len);
  305. WFIFOSET(fd,len);
  306. }
  307. }
  308. }
  309. }
  310. break;
  311. case CHAT_MAINCHAT: //[LuzZza]
  312. for(i=1; i<fd_max; i++) {
  313. if (session[i] && session[i]->func_parse == clif_parse &&
  314. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  315. sd->state.mainchat && !sd->chatID && (fd=sd->fd))
  316. {
  317. WFIFOHEAD(fd,len);
  318. memcpy(WFIFOP(fd,0), buf, len);
  319. WFIFOSET(fd, len);
  320. }
  321. }
  322. break;
  323. case PARTY_AREA:
  324. case PARTY_AREA_WOS:
  325. x0 = bl->x - AREA_SIZE;
  326. y0 = bl->y - AREA_SIZE;
  327. x1 = bl->x + AREA_SIZE;
  328. y1 = bl->y + AREA_SIZE;
  329. case PARTY:
  330. case PARTY_WOS:
  331. case PARTY_SAMEMAP:
  332. case PARTY_SAMEMAP_WOS:
  333. if (sd && sd->status.party_id)
  334. p = party_search(sd->status.party_id);
  335. if (p) {
  336. for(i=0;i<MAX_PARTY;i++){
  337. if ((sd = p->data[i].sd) == NULL)
  338. continue;
  339. if (!(fd=sd->fd) || session[fd] == NULL || sd->state.auth == 0
  340. || session[fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  341. continue;
  342. if (sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS))
  343. continue;
  344. if (type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m)
  345. continue;
  346. if ((type == PARTY_AREA || type == PARTY_AREA_WOS) &&
  347. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  348. continue;
  349. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  350. WFIFOHEAD(fd,len);
  351. memcpy(WFIFOP(fd,0), buf, len);
  352. WFIFOSET(fd,len);
  353. }
  354. }
  355. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  356. break;
  357. for (i = 1; i < fd_max; i++){ // partyspy [Syrus22]
  358. if (session[i] && session[i]->func_parse == clif_parse &&
  359. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  360. sd->state.auth && (fd=sd->fd) && sd->partyspy == p->party.party_id)
  361. {
  362. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  363. WFIFOHEAD(fd,len);
  364. memcpy(WFIFOP(fd,0), buf, len);
  365. WFIFOSET(fd,len);
  366. }
  367. }
  368. }
  369. }
  370. break;
  371. case DUEL:
  372. case DUEL_WOS:
  373. if (!sd || !sd->duel_group) break; //Invalid usage.
  374. x0 = sd->duel_group; //Here we use x0 to store the duel group. [Skotlex]
  375. for (i = 0; i < fd_max; i++) {
  376. if (session[i] && session[i]->func_parse == clif_parse &&
  377. (sd = (struct map_session_data *)session[i]->session_data) != NULL &&
  378. sd->state.auth && sd->duel_group == x0) {
  379. if (type == DUEL_WOS && bl->id == sd->bl.id)
  380. continue;
  381. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) {
  382. WFIFOHEAD(i, len);
  383. memcpy(WFIFOP(i,0), buf, len);
  384. WFIFOSET(i,len);
  385. }
  386. }
  387. }
  388. break;
  389. case SELF:
  390. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  391. WFIFOHEAD(fd,len);
  392. memcpy(WFIFOP(fd,0), buf, len);
  393. WFIFOSET(fd,len);
  394. }
  395. break;
  396. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  397. case GUILD_AREA:
  398. case GUILD_AREA_WOS:
  399. x0 = bl->x - AREA_SIZE;
  400. y0 = bl->y - AREA_SIZE;
  401. x1 = bl->x + AREA_SIZE;
  402. y1 = bl->y + AREA_SIZE;
  403. case GUILD_SAMEMAP:
  404. case GUILD_SAMEMAP_WOS:
  405. case GUILD:
  406. case GUILD_WOS:
  407. if (sd && sd->status.guild_id)
  408. g = guild_search(sd->status.guild_id);
  409. if (g) {
  410. for(i = 0; i < g->max_member; i++) {
  411. if ((sd = g->member[i].sd) != NULL) {
  412. if (!(fd=sd->fd) || session[fd] == NULL || sd->state.auth == 0
  413. || session[fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  414. continue;
  415. if (sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS))
  416. continue;
  417. if (type != GUILD && type != GUILD_WOS && sd->bl.m != bl->m)
  418. continue;
  419. if ((type == GUILD_AREA || type == GUILD_AREA_WOS) &&
  420. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  421. continue;
  422. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  423. WFIFOHEAD(fd,len);
  424. memcpy(WFIFOP(fd,0), buf, len);
  425. WFIFOSET(fd,len);
  426. }
  427. }
  428. }
  429. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  430. break;
  431. for (i = 1; i < fd_max; i++){ // guildspy [Syrus22]
  432. if (session[i] && session[i]->func_parse == clif_parse &&
  433. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  434. sd->state.auth && (fd=sd->fd) && sd->guildspy == g->guild_id) {
  435. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  436. WFIFOHEAD(fd,len);
  437. memcpy(WFIFOP(fd,0), buf, len);
  438. WFIFOSET(fd,len);
  439. }
  440. }
  441. }
  442. }
  443. break;
  444. default:
  445. ShowError("clif_send: Unrecognized type %d\n",type);
  446. return -1;
  447. }
  448. return 0;
  449. }
  450. //
  451. // パケット作って送信
  452. //
  453. /*==========================================
  454. *
  455. *------------------------------------------*/
  456. int clif_authok(struct map_session_data *sd)
  457. {
  458. int fd;
  459. if (!sd->fd)
  460. return 0;
  461. fd = sd->fd;
  462. WFIFOHEAD(fd, packet_len(0x73));
  463. WFIFOW(fd, 0) = 0x73;
  464. WFIFOL(fd, 2) = gettick();
  465. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  466. WFIFOB(fd, 9) = 5; // ignored
  467. WFIFOB(fd,10) = 5; // ignored
  468. WFIFOSET(fd,packet_len(0x73));
  469. return 0;
  470. }
  471. /*==========================================
  472. * Authentication failed/disconnect client.
  473. *------------------------------------------
  474. * The client closes it's socket and displays a message according to type:
  475. * 1 - server closed -> MsgStringTable[4]
  476. * 2 - ID already logged in -> MsgStringTable[5]
  477. * 3 - timeout/too much lag -> MsgStringTable[241]
  478. * 4 - server full -> MsgStringTable[264]
  479. * 5 - underaged -> MsgStringTable[305]
  480. * 9 - too many connections from this ip -> MsgStringTable[529]
  481. * 10 - out of available time paid for -> MsgStringTable[530]
  482. * 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  483. * other - disconnected -> MsgStringTable[3]
  484. */
  485. int clif_authfail_fd(int fd, int type)
  486. {
  487. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  488. return 0;
  489. WFIFOHEAD(fd, packet_len(0x81));
  490. WFIFOW(fd,0) = 0x81;
  491. WFIFOB(fd,2) = type;
  492. WFIFOSET(fd,packet_len(0x81));
  493. clif_setwaitclose(fd);
  494. return 0;
  495. }
  496. /*==========================================
  497. * Used to know which is the max valid account/char id [Skotlex]
  498. *------------------------------------------*/
  499. void clif_updatemaxid(int account_id, int char_id)
  500. {
  501. max_account_id = account_id;
  502. max_char_id = char_id;
  503. }
  504. /*==========================================
  505. *
  506. *------------------------------------------*/
  507. int clif_charselectok(int id)
  508. {
  509. struct map_session_data* sd;
  510. int fd;
  511. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  512. return 1;
  513. fd = sd->fd;
  514. WFIFOHEAD(fd,packet_len(0xb3));
  515. WFIFOW(fd,0) = 0xb3;
  516. WFIFOB(fd,2) = 1;
  517. WFIFOSET(fd,packet_len(0xb3));
  518. return 0;
  519. }
  520. /*==========================================
  521. * Makes an item appear on the ground
  522. * 009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  523. *------------------------------------------*/
  524. int clif_dropflooritem(struct flooritem_data* fitem)
  525. {
  526. uint8 buf[17];
  527. int view;
  528. nullpo_retr(0, fitem);
  529. if (fitem->item_data.nameid <= 0)
  530. return 0;
  531. WBUFW(buf, 0) = 0x9e;
  532. WBUFL(buf, 2) = fitem->bl.id;
  533. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  534. WBUFB(buf, 8) = fitem->item_data.identify;
  535. WBUFW(buf, 9) = fitem->bl.x;
  536. WBUFW(buf,11) = fitem->bl.y;
  537. WBUFB(buf,13) = fitem->subx;
  538. WBUFB(buf,14) = fitem->suby;
  539. WBUFW(buf,15) = fitem->item_data.amount;
  540. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  541. return 0;
  542. }
  543. /*==========================================
  544. *
  545. *------------------------------------------*/
  546. int clif_clearflooritem(struct flooritem_data *fitem, int fd)
  547. {
  548. unsigned char buf[16];
  549. nullpo_retr(0, fitem);
  550. WBUFW(buf,0) = 0xa1;
  551. WBUFL(buf,2) = fitem->bl.id;
  552. if (fd == 0) {
  553. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  554. } else {
  555. WFIFOHEAD(fd,packet_len(0xa1));
  556. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  557. WFIFOSET(fd,packet_len(0xa1));
  558. }
  559. return 0;
  560. }
  561. /*==========================================
  562. * make a unit (char, npc, mob, homun) disappear to one client
  563. * id : the id of the unit
  564. * type: 0 - moved out of sight
  565. * 1 - died
  566. * 2 - logged out
  567. * 3 - teleported / winged away
  568. * fd : the target client
  569. *------------------------------------------*/
  570. int clif_clearunit_single(int id, uint8 type, int fd)
  571. {
  572. WFIFOHEAD(fd, packet_len(0x80));
  573. WFIFOW(fd,0) = 0x80;
  574. WFIFOL(fd,2) = id;
  575. WFIFOB(fd,6) = type;
  576. WFIFOSET(fd, packet_len(0x80));
  577. return 0;
  578. }
  579. /*==========================================
  580. * make a unit (char, npc, mob, homun) disappear to all clients in area
  581. * type: 0 - moved out of sight
  582. * 1 - died
  583. * 2 - logged out
  584. * 3 - teleported / winged away
  585. *------------------------------------------*/
  586. int clif_clearunit_area(struct block_list* bl, uint8 type)
  587. {
  588. unsigned char buf[16];
  589. nullpo_retr(0, bl);
  590. WBUFW(buf,0) = 0x80;
  591. WBUFL(buf,2) = bl->id;
  592. WBUFB(buf,6) = type;
  593. clif_send(buf, packet_len(0x80), bl, type == 1 ? AREA : AREA_WOS);
  594. if(disguised(bl)) {
  595. WBUFL(buf,2) = -bl->id;
  596. clif_send(buf, packet_len(0x80), bl, SELF);
  597. }
  598. return 0;
  599. }
  600. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, int data)
  601. {
  602. struct block_list *bl = (struct block_list *)id;
  603. clif_clearunit_area(bl, 0);
  604. aFree(bl);
  605. return 0;
  606. }
  607. int clif_clearunit_delayed(struct block_list* bl, unsigned int tick)
  608. {
  609. struct block_list *tbl;
  610. tbl = aMalloc(sizeof (struct block_list));
  611. memcpy (tbl, bl, sizeof (struct block_list));
  612. add_timer(tick, clif_clearunit_delayed_sub, (int)tbl, 0);
  613. return 0;
  614. }
  615. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  616. {
  617. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  618. {
  619. *rhand = *lhand = 0;
  620. return;
  621. }
  622. #if PACKETVER < 4
  623. *rhand = sd->status.weapon;
  624. *lhand = sd->status.shield;
  625. #else
  626. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  627. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  628. {
  629. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  630. if (id->view_id > 0)
  631. *rhand = id->view_id;
  632. else
  633. *rhand = id->nameid;
  634. } else
  635. *rhand = 0;
  636. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  637. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  638. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  639. {
  640. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  641. if (id->view_id > 0)
  642. *lhand = id->view_id;
  643. else
  644. *lhand = id->nameid;
  645. } else
  646. *lhand = 0;
  647. #endif
  648. }
  649. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  650. static int clif_setlevel(int lv)
  651. {
  652. if( lv < battle_config.max_lv )
  653. return lv;
  654. if( lv < battle_config.aura_lv )
  655. return battle_config.max_lv - 1;
  656. return battle_config.max_lv;
  657. }
  658. /*==========================================
  659. * Prepares 'unit standing/spawning' packet
  660. *------------------------------------------*/
  661. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  662. {
  663. struct map_session_data* sd;
  664. struct status_change* sc = status_get_sc(bl);
  665. struct view_data* vd = status_get_viewdata(bl);
  666. unsigned char *buf = WBUFP(buffer,0);
  667. bool type = !pcdb_checkid(vd->class_);
  668. #if PACKETVER >= 7
  669. unsigned short offset = 0;
  670. #endif
  671. BL_CAST(BL_PC, bl, sd);
  672. if(type)
  673. WBUFW(buf,0) = spawn?0x7c:0x78;
  674. else
  675. #if PACKETVER < 4
  676. WBUFW(buf,0) = spawn?0x79:0x78;
  677. #elif PACKETVER < 7
  678. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  679. #else
  680. WBUFW(buf,0) = spawn?0x22b:0x22a;
  681. #endif
  682. #if PACKETVER >= 9
  683. if (type) {
  684. // shift payload 1 byte to the right for mob packets
  685. WBUFB(buf,2) = 0; // padding?
  686. offset++;
  687. buf = WBUFP(buffer,offset);
  688. }
  689. #endif
  690. WBUFL(buf, 2) = bl->id;
  691. WBUFW(buf, 6) = status_get_speed(bl);
  692. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  693. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  694. if (type&&spawn) { //uses an older and different packet structure
  695. WBUFW(buf,12) = (sc)? sc->option : 0;
  696. WBUFW(buf,14) = vd->hair_style;
  697. WBUFW(buf,16) = vd->weapon;
  698. WBUFW(buf,18) = vd->head_bottom;
  699. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  700. WBUFW(buf,22) = vd->shield;
  701. } else {
  702. #if PACKETVER >= 7
  703. if (!type) {
  704. WBUFL(buf,12) = (sc)? sc->option : 0;
  705. offset+=2;
  706. buf = WBUFP(buffer,offset); //Shift 2 bytes to the right for the rest of fields
  707. } else
  708. #endif
  709. WBUFW(buf,12) = (sc)? sc->option : 0;
  710. WBUFW(buf,14) = vd->class_;
  711. WBUFW(buf,16) = vd->hair_style;
  712. WBUFW(buf,18) = vd->weapon;
  713. #if PACKETVER < 4
  714. WBUFW(buf,20) = vd->head_bottom;
  715. WBUFW(buf,22) = vd->shield;
  716. #else
  717. WBUFW(buf,20) = vd->shield;
  718. WBUFW(buf,22) = vd->head_bottom;
  719. #endif
  720. }
  721. WBUFW(buf,24) = vd->head_top;
  722. WBUFW(buf,26) = vd->head_mid;
  723. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  724. { //The hell, why flags work like this?
  725. WBUFL(buf,22) = status_get_emblem_id(bl);
  726. WBUFL(buf,26) = status_get_guild_id(bl);
  727. }
  728. WBUFW(buf,28) = vd->hair_color;
  729. WBUFW(buf,30) = vd->cloth_color;
  730. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  731. if (type&&spawn) { //End of packet 0x7c
  732. WBUFB(buf,34) = 0; // karma
  733. WBUFB(buf,35) = vd->sex;
  734. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  735. WBUFB(buf,39) = 0;
  736. WBUFB(buf,40) = 0;
  737. return packet_len(0x7c);
  738. }
  739. WBUFL(buf,34) = status_get_guild_id(bl);
  740. WBUFW(buf,38) = status_get_emblem_id(bl);
  741. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  742. #if PACKETVER >= 7
  743. if (!type) {
  744. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  745. offset+=2;
  746. buf = WBUFP(buffer,offset); //Shift additional 2 bytes...
  747. } else
  748. #endif
  749. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  750. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  751. WBUFB(buf,45) = vd->sex;
  752. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  753. WBUFB(buf,49) = (sd)? 5 : 0;
  754. WBUFB(buf,50) = (sd)? 5 : 0;
  755. if (spawn) {
  756. WBUFW(buf,51) = clif_setlevel(status_get_lv(bl));
  757. } else {
  758. WBUFB(buf,51) = vd->dead_sit;
  759. WBUFW(buf,52) = clif_setlevel(status_get_lv(bl));
  760. }
  761. return packet_len(WBUFW(buffer,0));
  762. }
  763. /*==========================================
  764. * Prepares 'unit walking' packet
  765. *------------------------------------------*/
  766. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  767. {
  768. struct map_session_data* sd;
  769. struct status_change* sc = status_get_sc(bl);
  770. struct view_data* vd = status_get_viewdata(bl);
  771. unsigned char* buf = WBUFP(buffer,0);
  772. #if PACKETVER >= 7
  773. unsigned short offset = 0;
  774. #endif
  775. BL_CAST(BL_PC, bl, sd);
  776. #if PACKETVER < 4
  777. WBUFW(buf, 0) = 0x7b;
  778. #elif PACKETVER < 7
  779. WBUFW(buf, 0) = 0x1da;
  780. #else
  781. WBUFW(buf, 0) = 0x22c;
  782. #endif
  783. #if PACKETVER >= 9
  784. WBUFB(buf, 2) = 0; // padding?
  785. offset++;
  786. buf = WBUFP(buf,offset);
  787. #endif
  788. WBUFL(buf, 2) = bl->id;
  789. WBUFW(buf, 6) = status_get_speed(bl);
  790. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  791. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  792. #if PACKETVER < 7
  793. WBUFW(buf,12) = (sc)? sc->option : 0;
  794. #else
  795. WBUFL(buf,12) = (sc)? sc->option : 0;
  796. offset+=2; //Shift the rest of elements by 2 bytes.
  797. buf = WBUFP(buffer,offset);
  798. #endif
  799. WBUFW(buf,14) = vd->class_;
  800. WBUFW(buf,16) = vd->hair_style;
  801. WBUFW(buf,18) = vd->weapon;
  802. #if PACKETVER < 4
  803. WBUFW(buf,20) = vd->head_bottom;
  804. WBUFL(buf,22) = gettick();
  805. WBUFW(buf,26) = vd->shield;
  806. #else
  807. WBUFW(buf,20) = vd->shield;
  808. WBUFW(buf,22) = vd->head_bottom;
  809. WBUFL(buf,24) = gettick();
  810. #endif
  811. WBUFW(buf,28) = vd->head_top;
  812. WBUFW(buf,30) = vd->head_mid;
  813. WBUFW(buf,32) = vd->hair_color;
  814. WBUFW(buf,34) = vd->cloth_color;
  815. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  816. WBUFL(buf,38) = status_get_guild_id(bl);
  817. WBUFW(buf,42) = status_get_emblem_id(bl);
  818. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  819. #if PACKETVER < 7
  820. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  821. #else
  822. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  823. offset+=2; //Shift the rest of elements by 2 bytes.
  824. buf = WBUFP(buffer,offset);
  825. #endif
  826. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  827. WBUFB(buf,49) = vd->sex;
  828. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  829. WBUFB(buf,56) = (sd)? 5 : 0;
  830. WBUFB(buf,57) = (sd)? 5 : 0;
  831. WBUFW(buf,58) = clif_setlevel(status_get_lv(bl));
  832. return packet_len(WBUFW(buffer,0));
  833. }
  834. //Modifies the buffer for disguise characters and sends it to self.
  835. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  836. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  837. {
  838. #if PACKETVER >= 9
  839. WBUFL(buf,3)=-bl->id;
  840. #else
  841. WBUFL(buf,2)=-bl->id;
  842. #endif
  843. clif_send(buf, len, bl, SELF);
  844. }
  845. /*==========================================
  846. * クラスチェンジ typeはMobの場合は1で他は0?
  847. *------------------------------------------*/
  848. int clif_class_change(struct block_list *bl,int class_,int type)
  849. {
  850. unsigned char buf[16];
  851. nullpo_retr(0, bl);
  852. if(!pcdb_checkid(class_)) {
  853. WBUFW(buf,0)=0x1b0;
  854. WBUFL(buf,2)=bl->id;
  855. WBUFB(buf,6)=type;
  856. WBUFL(buf,7)=class_;
  857. clif_send(buf,packet_len(0x1b0),bl,AREA);
  858. }
  859. return 0;
  860. }
  861. /*==========================================
  862. *
  863. *------------------------------------------*/
  864. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  865. {
  866. WFIFOHEAD(fd, packet_len(0x1e1));
  867. WFIFOW(fd,0)=0x1e1;
  868. WFIFOL(fd,2)=sd->bl.id;
  869. WFIFOW(fd,6)=sd->spiritball;
  870. WFIFOSET(fd, packet_len(0x1e1));
  871. }
  872. // new and improved weather display [Valaris]
  873. static void clif_weather_sub(int fd, int id, int type)
  874. {
  875. WFIFOHEAD(fd,packet_len(0x1f3));
  876. WFIFOW(fd,0) = 0x1f3;
  877. WFIFOL(fd,2) = id;
  878. WFIFOL(fd,6) = type;
  879. WFIFOSET(fd,packet_len(0x1f3));
  880. }
  881. /*==========================================
  882. *
  883. *------------------------------------------*/
  884. static void clif_weather_check(struct map_session_data *sd)
  885. {
  886. int m = sd->bl.m, fd = sd->fd;
  887. if (map[m].flag.snow
  888. || map[m].flag.clouds
  889. || map[m].flag.fog
  890. || map[m].flag.fireworks
  891. || map[m].flag.sakura
  892. || map[m].flag.leaves
  893. || map[m].flag.rain
  894. || map[m].flag.clouds2)
  895. {
  896. if (map[m].flag.snow)
  897. clif_weather_sub(fd, sd->bl.id, 162);
  898. if (map[m].flag.clouds)
  899. clif_weather_sub(fd, sd->bl.id, 233);
  900. if (map[m].flag.clouds2)
  901. clif_weather_sub(fd, sd->bl.id, 516);
  902. if (map[m].flag.fog)
  903. clif_weather_sub(fd, sd->bl.id, 515);
  904. if (map[m].flag.fireworks) {
  905. clif_weather_sub(fd, sd->bl.id, 297);
  906. clif_weather_sub(fd, sd->bl.id, 299);
  907. clif_weather_sub(fd, sd->bl.id, 301);
  908. }
  909. if (map[m].flag.sakura)
  910. clif_weather_sub(fd, sd->bl.id, 163);
  911. if (map[m].flag.leaves)
  912. clif_weather_sub(fd, sd->bl.id, 333);
  913. if (map[m].flag.rain)
  914. clif_weather_sub(fd, sd->bl.id, 161);
  915. }
  916. }
  917. int clif_weather(int m)
  918. {
  919. int i;
  920. struct map_session_data *sd=NULL;
  921. for(i = 0; i < fd_max; i++) {
  922. if (session[i] && session[i]->func_parse == clif_parse &&
  923. (sd = session[i]->session_data) != NULL &&
  924. sd->state.auth && sd->bl.m == m) {
  925. clif_weather_check(sd);
  926. }
  927. }
  928. return 0;
  929. }
  930. int clif_spawn(struct block_list *bl)
  931. {
  932. unsigned char buf[128];
  933. struct view_data *vd;
  934. int len;
  935. vd = status_get_viewdata(bl);
  936. if( !vd || vd->class_ == INVISIBLE_CLASS )
  937. return 0;
  938. len = clif_set_unit_idle(bl, buf,true);
  939. clif_send(buf, len, bl, AREA_WOS);
  940. if (disguised(bl))
  941. clif_setdisguise(bl, buf, len);
  942. if (vd->cloth_color)
  943. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  944. switch (bl->type)
  945. {
  946. case BL_PC:
  947. {
  948. TBL_PC *sd = ((TBL_PC*)bl);
  949. if (sd->spiritball > 0)
  950. clif_spiritball(sd);
  951. if(sd->state.size==2) // tiny/big players [Valaris]
  952. clif_specialeffect(bl,423,AREA);
  953. else if(sd->state.size==1)
  954. clif_specialeffect(bl,421,AREA);
  955. }
  956. break;
  957. case BL_MOB:
  958. {
  959. TBL_MOB *md = ((TBL_MOB*)bl);
  960. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  961. clif_specialeffect(&md->bl,423,AREA);
  962. else if(md->special_state.size==1)
  963. clif_specialeffect(&md->bl,421,AREA);
  964. }
  965. break;
  966. case BL_PET:
  967. if (vd->head_bottom)
  968. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  969. break;
  970. }
  971. return 0;
  972. }
  973. //[orn]
  974. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  975. {
  976. struct status_data *status;
  977. unsigned char buf[128];
  978. nullpo_retr(0, hd);
  979. status = &hd->battle_status;
  980. memset(buf,0,packet_len(0x22e));
  981. WBUFW(buf,0)=0x22e;
  982. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  983. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  984. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  985. WBUFW(buf,27)=hd->homunculus.level;
  986. WBUFW(buf,29)=hd->homunculus.hunger;
  987. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  988. WBUFW(buf,33)=0; // equip id
  989. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, SHRT_MAX);
  990. WBUFW(buf,37)=cap_value(status->matk_max, 0, SHRT_MAX);
  991. WBUFW(buf,39)=status->hit;
  992. if (battle_config.hom_setting&0x10)
  993. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  994. else
  995. WBUFW(buf,41)=status->cri/10;
  996. WBUFW(buf,43)=status->def + status->vit ;
  997. WBUFW(buf,45)=status->mdef;
  998. WBUFW(buf,47)=status->flee;
  999. WBUFW(buf,49)=(flag)?0:status->amotion;
  1000. if (status->max_hp > SHRT_MAX) {
  1001. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1002. WBUFW(buf,53) = 100;
  1003. } else {
  1004. WBUFW(buf,51)=status->hp;
  1005. WBUFW(buf,53)=status->max_hp;
  1006. }
  1007. if (status->max_sp > SHRT_MAX) {
  1008. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1009. WBUFW(buf,57) = 100;
  1010. } else {
  1011. WBUFW(buf,55)=status->sp;
  1012. WBUFW(buf,57)=status->max_sp;
  1013. }
  1014. WBUFL(buf,59)=hd->homunculus.exp;
  1015. WBUFL(buf,63)=hd->exp_next;
  1016. WBUFW(buf,67)=hd->homunculus.skillpts;
  1017. WBUFW(buf,69)=2; // FIXME: undocumented flag, seems to be '2' all the time [ultramage]
  1018. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1019. return 0;
  1020. }
  1021. void clif_send_homdata(struct map_session_data *sd, int type, int param)
  1022. { //[orn]
  1023. int fd = sd->fd;
  1024. WFIFOHEAD(fd, packet_len(0x230));
  1025. nullpo_retv(sd->hd);
  1026. WFIFOW(fd,0)=0x230;
  1027. WFIFOW(fd,2)=type;
  1028. WFIFOL(fd,4)=sd->hd->bl.id;
  1029. WFIFOL(fd,8)=param;
  1030. WFIFOSET(fd,packet_len(0x230));
  1031. return;
  1032. }
  1033. int clif_homskillinfoblock(struct map_session_data *sd)
  1034. { //[orn]
  1035. struct homun_data *hd;
  1036. int fd = sd->fd;
  1037. int i,j,len=4,id;
  1038. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1039. hd = sd->hd;
  1040. if ( !hd )
  1041. return 0 ;
  1042. WFIFOW(fd,0)=0x235;
  1043. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1044. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1045. j = id - HM_SKILLBASE ;
  1046. WFIFOW(fd,len ) = id ;
  1047. WFIFOW(fd,len+2) = skill_get_inf(id) ;
  1048. WFIFOW(fd,len+4) = 0 ;
  1049. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv ;
  1050. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv) ;
  1051. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv) ;
  1052. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH) ;
  1053. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1054. len+=37;
  1055. }
  1056. }
  1057. WFIFOW(fd,2)=len;
  1058. WFIFOSET(fd,len);
  1059. return 0;
  1060. }
  1061. void clif_homskillup(struct map_session_data *sd, int skill_num)
  1062. { //[orn]
  1063. struct homun_data *hd;
  1064. int fd=sd->fd, skillid;
  1065. WFIFOHEAD(fd, packet_len(0x239));
  1066. nullpo_retv(sd);
  1067. skillid = skill_num - HM_SKILLBASE;
  1068. hd=sd->hd;
  1069. WFIFOW(fd,0) = 0x239;
  1070. WFIFOW(fd,2) = skill_num;
  1071. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1072. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1073. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1074. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1075. WFIFOSET(fd,packet_len(0x239));
  1076. return;
  1077. }
  1078. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1079. {
  1080. int fd=sd->fd;
  1081. WFIFOHEAD(fd,packet_len(0x22f));
  1082. WFIFOW(fd,0)=0x22f;
  1083. WFIFOB(fd,2)=fail;
  1084. WFIFOW(fd,3)=foodid;
  1085. WFIFOSET(fd,packet_len(0x22f));
  1086. return 0;
  1087. }
  1088. /*==========================================
  1089. *
  1090. *------------------------------------------*/
  1091. int clif_walkok(struct map_session_data *sd)
  1092. {
  1093. int fd=sd->fd;
  1094. WFIFOHEAD(fd, packet_len(0x87));
  1095. WFIFOW(fd,0)=0x87;
  1096. WFIFOL(fd,2)=gettick();
  1097. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1098. WFIFOSET(fd,packet_len(0x87));
  1099. return 0;
  1100. }
  1101. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1102. {
  1103. uint8 buf[128];
  1104. int len;
  1105. len = clif_set_unit_walking(bl,ud,buf);
  1106. clif_send(buf,len,bl,AREA_WOS);
  1107. if (disguised(bl))
  1108. clif_setdisguise(bl, buf, len);
  1109. if(vd->cloth_color)
  1110. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1111. switch(bl->type)
  1112. {
  1113. case BL_PC:
  1114. {
  1115. TBL_PC *sd = ((TBL_PC*)bl);
  1116. // clif_movepc(sd);
  1117. if(sd->state.size==2) // tiny/big players [Valaris]
  1118. clif_specialeffect(&sd->bl,423,AREA);
  1119. else if(sd->state.size==1)
  1120. clif_specialeffect(&sd->bl,421,AREA);
  1121. }
  1122. break;
  1123. case BL_MOB:
  1124. {
  1125. TBL_MOB *md = ((TBL_MOB*)bl);
  1126. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1127. clif_specialeffect(&md->bl,423,AREA);
  1128. else if(md->special_state.size==1)
  1129. clif_specialeffect(&md->bl,421,AREA);
  1130. }
  1131. break;
  1132. }
  1133. return;
  1134. }
  1135. /// Move the unit (does nothing if the client has no info about the unit)
  1136. /// Note: unit must not be self
  1137. void clif_move(struct unit_data *ud)
  1138. {
  1139. unsigned char buf[16];
  1140. struct view_data* vd;
  1141. struct block_list* bl = ud->bl;
  1142. vd = status_get_viewdata(bl);
  1143. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1144. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1145. if (ud->state.speed_changed) {
  1146. // Since we don't know how to update the speed of other objects,
  1147. // use the old walk packet to update the data.
  1148. ud->state.speed_changed = 0;
  1149. clif_move2(bl, vd, ud);
  1150. return;
  1151. }
  1152. WBUFW(buf,0)=0x86;
  1153. WBUFL(buf,2)=bl->id;
  1154. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1155. WBUFL(buf,12)=gettick();
  1156. clif_send(buf, 16, bl, AREA_WOS);
  1157. if (disguised(bl))
  1158. {
  1159. WBUFL(buf,2)=-bl->id;
  1160. clif_send(buf, 16, bl, SELF);
  1161. }
  1162. }
  1163. /*==========================================
  1164. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1165. *------------------------------------------*/
  1166. static int clif_delayquit(int tid, unsigned int tick, int id, int data)
  1167. {
  1168. struct map_session_data *sd = NULL;
  1169. //Remove player from map server
  1170. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1171. map_quit(sd);
  1172. return 0;
  1173. }
  1174. /*==========================================
  1175. *
  1176. *------------------------------------------*/
  1177. void clif_quitsave(int fd,struct map_session_data *sd)
  1178. {
  1179. if (sd->state.waitingdisconnect || //Was already waiting to be disconnected.
  1180. !battle_config.prevent_logout ||
  1181. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1182. map_quit(sd);
  1183. else if (sd->fd)
  1184. { //Disassociate session from player (session is deleted after this function was called)
  1185. //And set a timer to make him quit later.
  1186. session[sd->fd]->session_data = NULL;
  1187. sd->fd = 0;
  1188. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1189. }
  1190. }
  1191. /*==========================================
  1192. *
  1193. *------------------------------------------*/
  1194. static int clif_waitclose(int tid, unsigned int tick, int id, int data)
  1195. {
  1196. if (session[id] && session[id]->func_parse == clif_parse) //Avoid disconnecting non-players, as pointed out by End of Exam [Skotlex]
  1197. set_eof(id);
  1198. return 0;
  1199. }
  1200. /*==========================================
  1201. *
  1202. *------------------------------------------*/
  1203. void clif_setwaitclose(int fd)
  1204. {
  1205. struct map_session_data *sd;
  1206. // if player is not already in the game (double connection probably)
  1207. if ((sd = (struct map_session_data*)session[fd]->session_data) == NULL) {
  1208. // limited timer, just to send information.
  1209. add_timer(gettick() + 1000, clif_waitclose, fd, 0);
  1210. } else
  1211. add_timer(gettick() + 5000, clif_waitclose, fd, 0);
  1212. }
  1213. /*==========================================
  1214. *
  1215. *------------------------------------------*/
  1216. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1217. {
  1218. int fd;
  1219. nullpo_retv(sd);
  1220. fd = sd->fd;
  1221. WFIFOHEAD(fd,packet_len(0x91));
  1222. WFIFOW(fd,0) = 0x91;
  1223. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1224. WFIFOW(fd,18) = x;
  1225. WFIFOW(fd,20) = y;
  1226. WFIFOSET(fd,packet_len(0x91));
  1227. }
  1228. /*==========================================
  1229. * Tells the client to connect to another map-server
  1230. *------------------------------------------*/
  1231. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1232. {
  1233. int fd;
  1234. nullpo_retv(sd);
  1235. fd = sd->fd;
  1236. WFIFOHEAD(fd,packet_len(0x92));
  1237. WFIFOW(fd,0) = 0x92;
  1238. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1239. WFIFOW(fd,18) = x;
  1240. WFIFOW(fd,20) = y;
  1241. WFIFOL(fd,22) = htonl(ip);
  1242. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1243. WFIFOSET(fd,packet_len(0x92));
  1244. }
  1245. int clif_blown(struct block_list *bl)
  1246. {
  1247. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1248. // return clif_fixpos(bl);
  1249. return clif_slide(bl, bl->x, bl->y);
  1250. }
  1251. /*==========================================
  1252. *
  1253. *------------------------------------------*/
  1254. int clif_fixpos(struct block_list *bl)
  1255. {
  1256. unsigned char buf[16];
  1257. nullpo_retr(0, bl);
  1258. WBUFW(buf,0)=0x88;
  1259. WBUFL(buf,2)=bl->id;
  1260. WBUFW(buf,6)=bl->x;
  1261. WBUFW(buf,8)=bl->y;
  1262. clif_send(buf, packet_len(0x88), bl, AREA);
  1263. if (disguised(bl)) {
  1264. WBUFL(buf,2)=-bl->id;
  1265. clif_send(buf, packet_len(0x88), bl, SELF);
  1266. }
  1267. return 0;
  1268. }
  1269. /*==========================================
  1270. *
  1271. *------------------------------------------*/
  1272. int clif_npcbuysell(struct map_session_data* sd, int id)
  1273. {
  1274. int fd;
  1275. nullpo_retr(0, sd);
  1276. fd=sd->fd;
  1277. WFIFOHEAD(fd, packet_len(0xc4));
  1278. WFIFOW(fd,0)=0xc4;
  1279. WFIFOL(fd,2)=id;
  1280. WFIFOSET(fd,packet_len(0xc4));
  1281. return 0;
  1282. }
  1283. /*==========================================
  1284. *
  1285. *------------------------------------------*/
  1286. int clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1287. {
  1288. int fd,i;
  1289. nullpo_retr(0, sd);
  1290. nullpo_retr(0, nd);
  1291. fd = sd->fd;
  1292. WFIFOHEAD(fd, 200 * 11 + 4);
  1293. WFIFOW(fd,0) = 0xc6;
  1294. WFIFOW(fd,2) = 4 + nd->u.shop.count*11;
  1295. for( i = 0; i < nd->u.shop.count; i++ )
  1296. {
  1297. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  1298. int val = nd->u.shop.shop_item[i].value;
  1299. WFIFOL(fd,4+i*11) = val;
  1300. if (!id->flag.value_notdc)
  1301. val = pc_modifybuyvalue(sd,val);
  1302. WFIFOL(fd,8+i*11) = val;
  1303. WFIFOB(fd,12+i*11) = itemtype(id->type);
  1304. WFIFOW(fd,13+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1305. }
  1306. WFIFOSET(fd,WFIFOW(fd,2));
  1307. return 0;
  1308. }
  1309. /*==========================================
  1310. *
  1311. *------------------------------------------*/
  1312. int clif_selllist(struct map_session_data *sd)
  1313. {
  1314. int fd,i,c=0,val;
  1315. nullpo_retr(0, sd);
  1316. fd=sd->fd;
  1317. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1318. WFIFOW(fd,0)=0xc7;
  1319. for(i=0;i<MAX_INVENTORY;i++) {
  1320. if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
  1321. if (!itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)))
  1322. continue;
  1323. val=sd->inventory_data[i]->value_sell;
  1324. if (val < 0)
  1325. continue;
  1326. WFIFOW(fd,4+c*10)=i+2;
  1327. WFIFOL(fd,6+c*10)=val;
  1328. if (!sd->inventory_data[i]->flag.value_notoc)
  1329. val=pc_modifysellvalue(sd,val);
  1330. WFIFOL(fd,10+c*10)=val;
  1331. c++;
  1332. }
  1333. }
  1334. WFIFOW(fd,2)=c*10+4;
  1335. WFIFOSET(fd,WFIFOW(fd,2));
  1336. return 0;
  1337. }
  1338. /*==========================================
  1339. *
  1340. *------------------------------------------*/
  1341. int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1342. {
  1343. int fd = sd->fd;
  1344. int slen = strlen(mes) + 9;
  1345. WFIFOHEAD(fd, slen);
  1346. WFIFOW(fd,0)=0xb4;
  1347. WFIFOW(fd,2)=slen;
  1348. WFIFOL(fd,4)=npcid;
  1349. strcpy((char*)WFIFOP(fd,8),mes);
  1350. WFIFOSET(fd,WFIFOW(fd,2));
  1351. return 0;
  1352. }
  1353. /*==========================================
  1354. *
  1355. *------------------------------------------*/
  1356. int clif_scriptnext(struct map_session_data *sd,int npcid)
  1357. {
  1358. int fd;
  1359. nullpo_retr(0, sd);
  1360. fd=sd->fd;
  1361. WFIFOHEAD(fd, packet_len(0xb5));
  1362. WFIFOW(fd,0)=0xb5;
  1363. WFIFOL(fd,2)=npcid;
  1364. WFIFOSET(fd,packet_len(0xb5));
  1365. return 0;
  1366. }
  1367. /*==========================================
  1368. *
  1369. *------------------------------------------*/
  1370. int clif_scriptclose(struct map_session_data *sd, int npcid)
  1371. {
  1372. int fd;
  1373. nullpo_retr(0, sd);
  1374. fd=sd->fd;
  1375. WFIFOHEAD(fd, packet_len(0xb6));
  1376. WFIFOW(fd,0)=0xb6;
  1377. WFIFOL(fd,2)=npcid;
  1378. WFIFOSET(fd,packet_len(0xb6));
  1379. return 0;
  1380. }
  1381. /*==========================================
  1382. *
  1383. *------------------------------------------*/
  1384. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1385. {
  1386. unsigned char *buf;
  1387. int fd = sd->fd;
  1388. sd->state.using_fake_npc = 1;
  1389. WFIFOHEAD(fd, packet_len(0x78));
  1390. buf = WFIFOP(fd,0);
  1391. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1392. WBUFW(buf,0)=0x78;
  1393. #if PACKETVER >=9
  1394. WBUFB(buf,2) = 0; //Unknown bit
  1395. buf = WFIFOP(fd,1);
  1396. #endif
  1397. WBUFL(buf,2)=npcid;
  1398. WBUFW(buf,14)=111;
  1399. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1400. WBUFB(buf,49)=5;
  1401. WBUFB(buf,50)=5;
  1402. WFIFOSET(fd, packet_len(0x78));
  1403. return;
  1404. }
  1405. /*==========================================
  1406. *
  1407. *------------------------------------------*/
  1408. int clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1409. {
  1410. int fd = sd->fd;
  1411. int slen = strlen(mes) + 8;
  1412. struct block_list *bl = NULL;
  1413. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1414. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1415. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1416. clif_sendfakenpc(sd, npcid);
  1417. WFIFOHEAD(fd, slen);
  1418. WFIFOW(fd,0)=0xb7;
  1419. WFIFOW(fd,2)=slen;
  1420. WFIFOL(fd,4)=npcid;
  1421. strcpy((char*)WFIFOP(fd,8),mes);
  1422. WFIFOSET(fd,WFIFOW(fd,2));
  1423. return 0;
  1424. }
  1425. /*==========================================
  1426. *
  1427. *------------------------------------------*/
  1428. int clif_scriptinput(struct map_session_data *sd, int npcid)
  1429. {
  1430. int fd;
  1431. struct block_list *bl = NULL;
  1432. nullpo_retr(0, sd);
  1433. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1434. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1435. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1436. clif_sendfakenpc(sd, npcid);
  1437. fd=sd->fd;
  1438. WFIFOHEAD(fd, packet_len(0x142));
  1439. WFIFOW(fd,0)=0x142;
  1440. WFIFOL(fd,2)=npcid;
  1441. WFIFOSET(fd,packet_len(0x142));
  1442. return 0;
  1443. }
  1444. /*==========================================
  1445. *
  1446. *------------------------------------------*/
  1447. int clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1448. {
  1449. int fd;
  1450. struct block_list *bl = NULL;
  1451. nullpo_retr(0, sd);
  1452. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1453. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1454. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1455. clif_sendfakenpc(sd, npcid);
  1456. fd=sd->fd;
  1457. WFIFOHEAD(fd, packet_len(0x1d4));
  1458. WFIFOW(fd,0)=0x1d4;
  1459. WFIFOL(fd,2)=npcid;
  1460. WFIFOSET(fd,packet_len(0x1d4));
  1461. return 0;
  1462. }
  1463. /// npc_id is ignored in the client
  1464. /// type=2 : Remove viewpoint
  1465. /// type=other : Show viewpoint
  1466. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1467. {
  1468. int fd;
  1469. nullpo_retr(0, sd);
  1470. fd=sd->fd;
  1471. WFIFOHEAD(fd, packet_len(0x144));
  1472. WFIFOW(fd,0)=0x144;
  1473. WFIFOL(fd,2)=npc_id;
  1474. WFIFOL(fd,6)=type;
  1475. WFIFOL(fd,10)=x;
  1476. WFIFOL(fd,14)=y;
  1477. WFIFOB(fd,18)=id;
  1478. WFIFOL(fd,19)=color;
  1479. WFIFOSET(fd,packet_len(0x144));
  1480. return 0;
  1481. }
  1482. /*==========================================
  1483. *
  1484. *------------------------------------------*/
  1485. int clif_cutin(struct map_session_data* sd, const char* image, int type)
  1486. {
  1487. int fd;
  1488. nullpo_retr(0, sd);
  1489. fd=sd->fd;
  1490. WFIFOHEAD(fd, packet_len(0x1b3));
  1491. WFIFOW(fd,0)=0x1b3;
  1492. strncpy((char*)WFIFOP(fd,2),image,64);
  1493. WFIFOB(fd,66)=type;
  1494. WFIFOSET(fd,packet_len(0x1b3));
  1495. return 0;
  1496. }
  1497. /*==========================================
  1498. * Fills in card data from the given item and into the buffer. [Skotlex]
  1499. *------------------------------------------*/
  1500. static void clif_addcards(unsigned char* buf, struct item* item)
  1501. {
  1502. int i=0,j;
  1503. if( item == NULL ) { //Blank data
  1504. WBUFW(buf,0) = 0;
  1505. WBUFW(buf,2) = 0;
  1506. WBUFW(buf,4) = 0;
  1507. WBUFW(buf,6) = 0;
  1508. return;
  1509. }
  1510. if( item->card[0] == CARD0_PET ) { //pet eggs
  1511. WBUFW(buf,0) = 0;
  1512. WBUFW(buf,2) = 0;
  1513. WBUFW(buf,4) = 0;
  1514. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1515. return;
  1516. }
  1517. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1518. WBUFW(buf,0) = item->card[0];
  1519. WBUFW(buf,2) = item->card[1];
  1520. WBUFW(buf,4) = item->card[2];
  1521. WBUFW(buf,6) = item->card[3];
  1522. return;
  1523. }
  1524. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1525. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1526. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1527. //Normal items.
  1528. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1529. WBUFW(buf,0) = j;
  1530. else
  1531. WBUFW(buf,0) = item->card[i];
  1532. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1533. WBUFW(buf,2) = j;
  1534. else
  1535. WBUFW(buf,2) = item->card[i];
  1536. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1537. WBUFW(buf,4) = j;
  1538. else
  1539. WBUFW(buf,4) = item->card[i];
  1540. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1541. WBUFW(buf,6) = j;
  1542. else
  1543. WBUFW(buf,6) = item->card[i];
  1544. }
  1545. /*==========================================
  1546. *
  1547. *------------------------------------------*/
  1548. int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1549. {
  1550. int fd;
  1551. nullpo_retr(0, sd);
  1552. fd = sd->fd;
  1553. if (!session_isActive(fd)) //Sasuke-
  1554. return 0;
  1555. WFIFOHEAD(fd,packet_len(0xa0));
  1556. if(fail) {
  1557. WFIFOW(fd,0)=0xa0;
  1558. WFIFOW(fd,2)=n+2;
  1559. WFIFOW(fd,4)=amount;
  1560. WFIFOW(fd,6)=0;
  1561. WFIFOB(fd,8)=0;
  1562. WFIFOB(fd,9)=0;
  1563. WFIFOB(fd,10)=0;
  1564. WFIFOW(fd,11)=0;
  1565. WFIFOW(fd,13)=0;
  1566. WFIFOW(fd,15)=0;
  1567. WFIFOW(fd,17)=0;
  1568. WFIFOW(fd,19)=0;
  1569. WFIFOB(fd,21)=0;
  1570. WFIFOB(fd,22)=fail;
  1571. } else {
  1572. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1573. return 1;
  1574. WFIFOW(fd,0)=0xa0;
  1575. WFIFOW(fd,2)=n+2;
  1576. WFIFOW(fd,4)=amount;
  1577. if (sd->inventory_data[n]->view_id > 0)
  1578. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1579. else
  1580. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1581. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1582. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1583. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1584. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1585. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1586. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1587. WFIFOB(fd,22)=fail;
  1588. }
  1589. WFIFOSET(fd,packet_len(0xa0));
  1590. return 0;
  1591. }
  1592. /*==========================================
  1593. *
  1594. *------------------------------------------*/
  1595. int clif_delitem(struct map_session_data *sd,int n,int amount)
  1596. {
  1597. int fd;
  1598. nullpo_retr(0, sd);
  1599. fd=sd->fd;
  1600. WFIFOHEAD(fd, packet_len(0xaf));
  1601. WFIFOW(fd,0)=0xaf;
  1602. WFIFOW(fd,2)=n+2;
  1603. WFIFOW(fd,4)=amount;
  1604. WFIFOSET(fd,packet_len(0xaf));
  1605. return 0;
  1606. }
  1607. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1608. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1609. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1610. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1611. {
  1612. if (id->view_id > 0)
  1613. WBUFW(buf,n)=id->view_id;
  1614. else
  1615. WBUFW(buf,n)=i->nameid;
  1616. WBUFB(buf,n+2)=itemtype(id->type);
  1617. WBUFB(buf,n+3)=i->identify;
  1618. if (equip >= 0) { //Equippable item
  1619. WBUFW(buf,n+4)=equip;
  1620. WBUFW(buf,n+6)=i->equip;
  1621. WBUFB(buf,n+8)=i->attribute;
  1622. WBUFB(buf,n+9)=i->refine;
  1623. } else { //Stackable item.
  1624. WBUFW(buf,n+4)=i->amount;
  1625. if (equip == -2 && id->equip == EQP_AMMO)
  1626. WBUFW(buf,n+6)=EQP_AMMO;
  1627. else
  1628. WBUFW(buf,n+6)=0;
  1629. }
  1630. }
  1631. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1632. void clif_inventorylist(struct map_session_data *sd)
  1633. {
  1634. int i,n,ne,fd = sd->fd,arrow=-1;
  1635. unsigned char *buf;
  1636. unsigned char bufe[MAX_INVENTORY*20+4];
  1637. #if PACKETVER < 5
  1638. const int s = 10; //Entry size.
  1639. #else
  1640. const int s = 18;
  1641. #endif
  1642. WFIFOHEAD(fd, MAX_INVENTORY * s + 4);
  1643. buf = WFIFOP(fd,0);
  1644. for(i=0,n=0,ne=0;i<MAX_INVENTORY;i++){
  1645. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1646. continue;
  1647. if(!itemdb_isstackable2(sd->inventory_data[i]))
  1648. { //Non-stackable (Equippable)
  1649. WBUFW(bufe,ne*20+4)=i+2;
  1650. clif_item_sub(bufe, ne*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1651. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.inventory[i]);
  1652. ne++;
  1653. } else { //Stackable.
  1654. WBUFW(buf,n*s+4)=i+2;
  1655. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1656. if (sd->inventory_data[i]->equip == EQP_AMMO &&
  1657. sd->status.inventory[i].equip)
  1658. arrow=i;
  1659. #if PACKETVER >= 5
  1660. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1661. #endif
  1662. n++;
  1663. }
  1664. }
  1665. if (n) {
  1666. #if PACKETVER < 5
  1667. WBUFW(buf,0)=0xa3;
  1668. #else
  1669. WBUFW(buf,0)=0x1ee;
  1670. #endif
  1671. WBUFW(buf,2)=4+n*s;
  1672. WFIFOSET(fd,WFIFOW(fd,2));
  1673. }
  1674. if(arrow >= 0)
  1675. clif_arrowequip(sd,arrow);
  1676. if(ne){
  1677. WBUFW(bufe,0)=0xa4;
  1678. WBUFW(bufe,2)=4+ne*20;
  1679. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1680. }
  1681. }
  1682. //Required when items break/get-repaired. Only sends equippable item list.
  1683. void clif_equiplist(struct map_session_data *sd)
  1684. {
  1685. int i,n,fd = sd->fd;
  1686. unsigned char *buf;
  1687. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  1688. buf = WFIFOP(fd,0);
  1689. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1690. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1691. continue;
  1692. if(itemdb_isstackable2(sd->inventory_data[i]))
  1693. continue;
  1694. //Equippable
  1695. WBUFW(buf,n*20+4)=i+2;
  1696. clif_item_sub(buf, n*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1697. clif_addcards(WBUFP(buf, n*20+16), &sd->status.inventory[i]);
  1698. n++;
  1699. }
  1700. if (n) {
  1701. WBUFW(buf,0)=0xa4;
  1702. WBUFW(buf,2)=4+n*20;
  1703. WFIFOSET(fd,WFIFOW(fd,2));
  1704. }
  1705. }
  1706. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1707. void clif_storagelist(struct map_session_data *sd,struct storage *stor)
  1708. {
  1709. struct item_data *id;
  1710. int i,n,ne,fd=sd->fd;
  1711. unsigned char *buf;
  1712. unsigned char bufe[MAX_STORAGE*20+4];
  1713. #if PACKETVER < 5
  1714. const int s = 10; //Entry size.
  1715. #else
  1716. const int s = 18;
  1717. #endif
  1718. WFIFOHEAD(fd,MAX_STORAGE * s + 4);
  1719. buf = WFIFOP(fd,0);
  1720. for(i=0,n=0,ne=0;i<MAX_STORAGE;i++){
  1721. if(stor->storage_[i].nameid<=0)
  1722. continue;
  1723. id = itemdb_search(stor->storage_[i].nameid);
  1724. if(!itemdb_isstackable2(id))
  1725. { //Equippable
  1726. WBUFW(bufe,ne*20+4)=i+1;
  1727. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  1728. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  1729. ne++;
  1730. } else { //Stackable
  1731. WBUFW(buf,n*s+4)=i+1;
  1732. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  1733. #if PACKETVER >= 5
  1734. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  1735. #endif
  1736. n++;
  1737. }
  1738. }
  1739. if(n){
  1740. #if PACKETVER < 5
  1741. WBUFW(buf,0)=0xa5;
  1742. #else
  1743. WBUFW(buf,0)=0x1f0;
  1744. #endif
  1745. WBUFW(buf,2)=4+n*s;
  1746. WFIFOSET(fd,WFIFOW(fd,2));
  1747. }
  1748. if(ne){
  1749. WBUFW(bufe,0)=0xa6;
  1750. WBUFW(bufe,2)=4+ne*20;
  1751. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1752. }
  1753. }
  1754. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1755. void clif_guildstoragelist(struct map_session_data *sd,struct guild_storage *stor)
  1756. {
  1757. struct item_data *id;
  1758. int i,n,ne,fd=sd->fd;
  1759. unsigned char *buf;
  1760. unsigned char bufe[MAX_GUILD_STORAGE*20+4];
  1761. #if PACKETVER < 5
  1762. const int s = 10; //Entry size.
  1763. #else
  1764. const int s = 18;
  1765. #endif
  1766. WFIFOHEAD(fd,MAX_GUILD_STORAGE * s + 4);
  1767. buf = WFIFOP(fd,0);
  1768. for(i=0,n=0,ne=0;i<MAX_GUILD_STORAGE;i++){
  1769. if(stor->storage_[i].nameid<=0)
  1770. continue;
  1771. id = itemdb_search(stor->storage_[i].nameid);
  1772. if(!itemdb_isstackable2(id))
  1773. { //Equippable
  1774. WBUFW(bufe,ne*20+4)=i+1;
  1775. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  1776. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  1777. ne++;
  1778. } else { //Stackable
  1779. WBUFW(buf,n*s+4)=i+1;
  1780. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  1781. #if PACKETVER >= 5
  1782. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  1783. #endif
  1784. n++;
  1785. }
  1786. }
  1787. if(n){
  1788. #if PACKETVER < 5
  1789. WBUFW(buf,0)=0xa5;
  1790. #else
  1791. WBUFW(buf,0)=0x1f0;
  1792. #endif
  1793. WBUFW(buf,2)=4+n*s;
  1794. WFIFOSET(fd,WFIFOW(fd,2));
  1795. }
  1796. if(ne){
  1797. WBUFW(bufe,0)=0xa6;
  1798. WBUFW(bufe,2)=4+ne*20;
  1799. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1800. }
  1801. }
  1802. void clif_cartlist(struct map_session_data *sd)
  1803. {
  1804. struct item_data *id;
  1805. int i,n,ne,fd=sd->fd;
  1806. unsigned char *buf;
  1807. unsigned char bufe[MAX_CART*20+4];
  1808. #if PACKETVER < 5
  1809. const int s = 10; //Entry size.
  1810. #else
  1811. const int s = 18;
  1812. #endif
  1813. WFIFOHEAD(fd, MAX_CART * s + 4);
  1814. buf = WFIFOP(fd,0);
  1815. for(i=0,n=0,ne=0;i<MAX_CART;i++){
  1816. if(sd->status.cart[i].nameid<=0)
  1817. continue;
  1818. id = itemdb_search(sd->status.cart[i].nameid);
  1819. if(!itemdb_isstackable2(id))
  1820. { //Equippable
  1821. WBUFW(bufe,ne*20+4)=i+2;
  1822. clif_item_sub(bufe, ne*20+6, &sd->status.cart[i], id, id->equip);
  1823. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.cart[i]);
  1824. ne++;
  1825. } else { //Stackable
  1826. WBUFW(buf,n*s+4)=i+2;
  1827. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  1828. #if PACKETVER >= 5
  1829. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  1830. #endif
  1831. n++;
  1832. }
  1833. }
  1834. if(n){
  1835. #if PACKETVER < 5
  1836. WBUFW(buf,0)=0x123;
  1837. #else
  1838. WBUFW(buf,0)=0x1ef;
  1839. #endif
  1840. WBUFW(buf,2)=4+n*s;
  1841. WFIFOSET(fd,WFIFOW(fd,2));
  1842. }
  1843. if(ne){
  1844. WBUFW(bufe,0)=0x122;
  1845. WBUFW(bufe,2)=4+ne*20;
  1846. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1847. }
  1848. return;
  1849. }
  1850. /// Client behaviour:
  1851. /// Closes the cart storage and removes all it's items from memory.
  1852. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  1853. void clif_clearcart(int fd)
  1854. {
  1855. WFIFOHEAD(fd, packet_len(0x12b));
  1856. WFIFOW(fd,0) = 0x12b;
  1857. }
  1858. // Guild XY locators [Valaris]
  1859. int clif_guild_xy(struct map_session_data *sd)
  1860. {
  1861. unsigned char buf[10];
  1862. nullpo_retr(0, sd);
  1863. WBUFW(buf,0)=0x1eb;
  1864. WBUFL(buf,2)=sd->status.account_id;
  1865. WBUFW(buf,6)=sd->bl.x;
  1866. WBUFW(buf,8)=sd->bl.y;
  1867. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  1868. return 0;
  1869. }
  1870. /*==========================================
  1871. * Sends x/y dot to a single fd. [Skotlex]
  1872. *------------------------------------------*/
  1873. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  1874. {
  1875. WFIFOHEAD(fd,packet_len(0x1eb));
  1876. WFIFOW(fd,0)=0x1eb;
  1877. WFIFOL(fd,2)=sd->status.account_id;
  1878. WFIFOW(fd,6)=sd->bl.x;
  1879. WFIFOW(fd,8)=sd->bl.y;
  1880. WFIFOSET(fd,packet_len(0x1eb));
  1881. return 0;
  1882. }
  1883. // Guild XY locators [Valaris]
  1884. int clif_guild_xy_remove(struct map_session_data *sd)
  1885. {
  1886. unsigned char buf[10];
  1887. nullpo_retr(0, sd);
  1888. WBUFW(buf,0)=0x1eb;
  1889. WBUFL(buf,2)=sd->status.account_id;
  1890. WBUFW(buf,6)=-1;
  1891. WBUFW(buf,8)=-1;
  1892. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  1893. return 0;
  1894. }
  1895. /*==========================================
  1896. * ステータスを送りつける
  1897. * 表示専用数字はこの中で計算して送る
  1898. *------------------------------------------*/
  1899. int clif_updatestatus(struct map_session_data *sd,int type)
  1900. {
  1901. int fd,len=8;
  1902. nullpo_retr(0, sd);
  1903. fd=sd->fd;
  1904. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  1905. return 0;
  1906. WFIFOHEAD(fd, 14);
  1907. WFIFOW(fd,0)=0xb0;
  1908. WFIFOW(fd,2)=type;
  1909. switch(type){
  1910. // 00b0
  1911. case SP_WEIGHT:
  1912. pc_updateweightstatus(sd);
  1913. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  1914. WFIFOW(fd,2)=type;
  1915. WFIFOL(fd,4)=sd->weight;
  1916. break;
  1917. case SP_MAXWEIGHT:
  1918. WFIFOL(fd,4)=sd->max_weight;
  1919. break;
  1920. case SP_SPEED:
  1921. WFIFOL(fd,4)=sd->battle_status.speed;
  1922. break;
  1923. case SP_BASELEVEL:
  1924. WFIFOL(fd,4)=sd->status.base_level;
  1925. break;
  1926. case SP_JOBLEVEL:
  1927. WFIFOL(fd,4)=sd->status.job_level;
  1928. break;
  1929. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  1930. WFIFOL(fd,4)=sd->status.karma;
  1931. break;
  1932. case SP_MANNER:
  1933. WFIFOL(fd,4)=sd->status.manner;
  1934. clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
  1935. break;
  1936. case SP_STATUSPOINT:
  1937. WFIFOL(fd,4)=sd->status.status_point;
  1938. break;
  1939. case SP_SKILLPOINT:
  1940. WFIFOL(fd,4)=sd->status.skill_point;
  1941. break;
  1942. case SP_HIT:
  1943. WFIFOL(fd,4)=sd->battle_status.hit;
  1944. break;
  1945. case SP_FLEE1:
  1946. WFIFOL(fd,4)=sd->battle_status.flee;
  1947. break;
  1948. case SP_FLEE2:
  1949. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  1950. break;
  1951. case SP_MAXHP:
  1952. WFIFOL(fd,4)=sd->battle_status.max_hp;
  1953. break;
  1954. case SP_MAXSP:
  1955. WFIFOL(fd,4)=sd->battle_status.max_sp;
  1956. break;
  1957. case SP_HP:
  1958. WFIFOL(fd,4)=sd->battle_status.hp;
  1959. if (battle_config.disp_hpmeter)
  1960. clif_hpmeter(sd);
  1961. if (!battle_config.party_hp_mode && sd->status.party_id)
  1962. clif_party_hp(sd);
  1963. break;
  1964. case SP_SP:
  1965. WFIFOL(fd,4)=sd->battle_status.sp;
  1966. break;
  1967. case SP_ASPD:
  1968. WFIFOL(fd,4)=sd->battle_status.amotion;
  1969. break;
  1970. case SP_ATK1:
  1971. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw.atk;
  1972. break;
  1973. case SP_DEF1:
  1974. WFIFOL(fd,4)=sd->battle_status.def;
  1975. break;
  1976. case SP_MDEF1:
  1977. WFIFOL(fd,4)=sd->battle_status.mdef;
  1978. break;
  1979. case SP_ATK2:
  1980. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2;
  1981. break;
  1982. case SP_DEF2:
  1983. WFIFOL(fd,4)=sd->battle_status.def2;
  1984. break;
  1985. case SP_MDEF2:
  1986. //negative check (in case you have something like Berserk active)
  1987. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  1988. if (len < 0) len = 0;
  1989. WFIFOL(fd,4)= len;
  1990. len = 8;
  1991. break;
  1992. case SP_CRITICAL:
  1993. WFIFOL(fd,4)=sd->battle_status.cri/10;
  1994. break;
  1995. case SP_MATK1:
  1996. WFIFOL(fd,4)=sd->battle_status.matk_max;
  1997. break;
  1998. case SP_MATK2:
  1999. WFIFOL(fd,4)=sd->battle_status.matk_min;
  2000. break;
  2001. case SP_ZENY:
  2002. WFIFOW(fd,0)=0xb1;
  2003. WFIFOL(fd,4)=sd->status.zeny - sd->mail.zeny;
  2004. break;
  2005. case SP_BASEEXP:
  2006. WFIFOW(fd,0)=0xb1;
  2007. WFIFOL(fd,4)=sd->status.base_exp;
  2008. break;
  2009. case SP_JOBEXP:
  2010. WFIFOW(fd,0)=0xb1;
  2011. WFIFOL(fd,4)=sd->status.job_exp;
  2012. break;
  2013. case SP_NEXTBASEEXP:
  2014. WFIFOW(fd,0)=0xb1;
  2015. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2016. break;
  2017. case SP_NEXTJOBEXP:
  2018. WFIFOW(fd,0)=0xb1;
  2019. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2020. break;
  2021. // 00be 終了
  2022. case SP_USTR:
  2023. case SP_UAGI:
  2024. case SP_UVIT:
  2025. case SP_UINT:
  2026. case SP_UDEX:
  2027. case SP_ULUK:
  2028. WFIFOW(fd,0)=0xbe;
  2029. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2030. len=5;
  2031. break;
  2032. // 013a 終了
  2033. case SP_ATTACKRANGE:
  2034. WFIFOW(fd,0)=0x13a;
  2035. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2036. len=4;
  2037. break;
  2038. // 0141 終了
  2039. case SP_STR:
  2040. WFIFOW(fd,0)=0x141;
  2041. WFIFOL(fd,2)=type;
  2042. WFIFOL(fd,6)=sd->status.str;
  2043. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2044. len=14;
  2045. break;
  2046. case SP_AGI:
  2047. WFIFOW(fd,0)=0x141;
  2048. WFIFOL(fd,2)=type;
  2049. WFIFOL(fd,6)=sd->status.agi;
  2050. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2051. len=14;
  2052. break;
  2053. case SP_VIT:
  2054. WFIFOW(fd,0)=0x141;
  2055. WFIFOL(fd,2)=type;
  2056. WFIFOL(fd,6)=sd->status.vit;
  2057. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2058. len=14;
  2059. break;
  2060. case SP_INT:
  2061. WFIFOW(fd,0)=0x141;
  2062. WFIFOL(fd,2)=type;
  2063. WFIFOL(fd,6)=sd->status.int_;
  2064. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2065. len=14;
  2066. break;
  2067. case SP_DEX:
  2068. WFIFOW(fd,0)=0x141;
  2069. WFIFOL(fd,2)=type;
  2070. WFIFOL(fd,6)=sd->status.dex;
  2071. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2072. len=14;
  2073. break;
  2074. case SP_LUK:
  2075. WFIFOW(fd,0)=0x141;
  2076. WFIFOL(fd,2)=type;
  2077. WFIFOL(fd,6)=sd->status.luk;
  2078. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2079. len=14;
  2080. break;
  2081. case SP_CARTINFO:
  2082. WFIFOW(fd,0)=0x121;
  2083. WFIFOW(fd,2)=sd->cart_num;
  2084. WFIFOW(fd,4)=MAX_CART;
  2085. WFIFOL(fd,6)=sd->cart_weight;
  2086. WFIFOL(fd,10)=battle_config.max_cart_weight;
  2087. len=14;
  2088. break;
  2089. default:
  2090. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2091. return 1;
  2092. }
  2093. WFIFOSET(fd,len);
  2094. return 0;
  2095. }
  2096. int clif_changestatus(struct block_list *bl,int type,int val)
  2097. {
  2098. unsigned char buf[12];
  2099. struct map_session_data *sd = NULL;
  2100. nullpo_retr(0, bl);
  2101. if(bl->type == BL_PC)
  2102. sd = (struct map_session_data *)bl;
  2103. if(sd){
  2104. WBUFW(buf,0)=0x1ab;
  2105. WBUFL(buf,2)=bl->id;
  2106. WBUFW(buf,6)=type;
  2107. switch(type){
  2108. case SP_MANNER:
  2109. WBUFL(buf,8)=val;
  2110. break;
  2111. default:
  2112. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2113. return 1;
  2114. }
  2115. clif_send(buf,packet_len(0x1ab),bl,AREA_WOS);
  2116. }
  2117. return 0;
  2118. }
  2119. /*==========================================
  2120. *
  2121. *------------------------------------------*/
  2122. void clif_changelook(struct block_list *bl,int type,int val)
  2123. {
  2124. unsigned char buf[16];
  2125. struct map_session_data* sd = NULL;
  2126. struct view_data* vd;
  2127. nullpo_retv(bl);
  2128. BL_CAST(BL_PC, bl, sd);
  2129. vd = status_get_viewdata(bl);
  2130. //nullpo_ret(vd);
  2131. if( vd ) //temp hack to let Warp Portal change appearance
  2132. switch(type)
  2133. {
  2134. case LOOK_WEAPON:
  2135. if (sd)
  2136. {
  2137. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2138. val = vd->weapon;
  2139. }
  2140. else vd->weapon = val;
  2141. break;
  2142. case LOOK_SHIELD:
  2143. if (sd)
  2144. {
  2145. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2146. val = vd->shield;
  2147. }
  2148. else vd->shield = val;
  2149. break;
  2150. case LOOK_BASE:
  2151. vd->class_ = val;
  2152. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2153. vd->weapon = vd->shield = 0;
  2154. if (vd->cloth_color && (
  2155. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2156. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2157. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2158. ))
  2159. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2160. break;
  2161. case LOOK_HAIR:
  2162. vd->hair_style = val;
  2163. break;
  2164. case LOOK_HEAD_BOTTOM:
  2165. vd->head_bottom = val;
  2166. break;
  2167. case LOOK_HEAD_TOP:
  2168. vd->head_top = val;
  2169. break;
  2170. case LOOK_HEAD_MID:
  2171. vd->head_mid = val;
  2172. break;
  2173. case LOOK_HAIR_COLOR:
  2174. vd->hair_color = val;
  2175. break;
  2176. case LOOK_CLOTHES_COLOR:
  2177. if (val && (
  2178. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2179. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2180. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2181. ))
  2182. val = 0;
  2183. vd->cloth_color = val;
  2184. break;
  2185. case LOOK_SHOES:
  2186. #if PACKETVER > 3
  2187. if (sd) {
  2188. int n;
  2189. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2190. if(sd->inventory_data[n]->view_id > 0)
  2191. val = sd->inventory_data[n]->view_id;
  2192. else
  2193. val = sd->status.inventory[n].nameid;
  2194. }
  2195. val = 0;
  2196. }
  2197. #endif
  2198. //Shoes? No packet uses this....
  2199. break;
  2200. }
  2201. #if PACKETVER < 4
  2202. WBUFW(buf,0)=0xc3;
  2203. WBUFL(buf,2)=bl->id;
  2204. WBUFB(buf,6)=type;
  2205. WBUFB(buf,7)=val;
  2206. clif_send(buf,packet_len(0xc3),bl,AREA);
  2207. #else
  2208. WBUFW(buf,0)=0x1d7;
  2209. WBUFL(buf,2)=bl->id;
  2210. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2211. WBUFB(buf,6)=LOOK_WEAPON;
  2212. WBUFW(buf,7)=vd->weapon;
  2213. WBUFW(buf,9)=vd->shield;
  2214. } else {
  2215. WBUFB(buf,6)=type;
  2216. WBUFW(buf,7)=val;
  2217. WBUFW(buf,9)=0;
  2218. }
  2219. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2220. #endif
  2221. }
  2222. //Sends a change-base-look packet required for traps as they are triggered.
  2223. void clif_changetraplook(struct block_list *bl,int val)
  2224. {
  2225. unsigned char buf[32];
  2226. #if PACKETVER < 4
  2227. WBUFW(buf,0)=0xc3;
  2228. WBUFL(buf,2)=bl->id;
  2229. WBUFB(buf,6)=LOOK_BASE;
  2230. WBUFB(buf,7)=val;
  2231. clif_send(buf,packet_len(0xc3),bl,AREA);
  2232. #else
  2233. WBUFW(buf,0)=0x1d7;
  2234. WBUFL(buf,2)=bl->id;
  2235. WBUFB(buf,6)=LOOK_BASE;
  2236. WBUFW(buf,7)=val;
  2237. WBUFW(buf,9)=0;
  2238. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2239. #endif
  2240. }
  2241. //For the stupid cloth-dye bug. Resends the given view data
  2242. //to the area specified by bl.
  2243. void clif_refreshlook(struct block_list *bl,int id,int type,int val,int area)
  2244. {
  2245. unsigned char buf[32];
  2246. #if PACKETVER < 4
  2247. WBUFW(buf,0)=0xc3;
  2248. WBUFL(buf,2)=id;
  2249. WBUFB(buf,6)=type;
  2250. WBUFB(buf,7)=val;
  2251. clif_send(buf,packet_len(0xc3),bl,area);
  2252. #else
  2253. WBUFW(buf,0)=0x1d7;
  2254. WBUFL(buf,2)=id;
  2255. WBUFB(buf,6)=type;
  2256. WBUFW(buf,7)=val;
  2257. WBUFW(buf,9)=0;
  2258. clif_send(buf,packet_len(0x1d7),bl,area);
  2259. #endif
  2260. return;
  2261. }
  2262. /*==========================================
  2263. *
  2264. *------------------------------------------*/
  2265. int clif_initialstatus(struct map_session_data *sd)
  2266. {
  2267. int fd;
  2268. unsigned char *buf;
  2269. nullpo_retr(0, sd);
  2270. fd=sd->fd;
  2271. WFIFOHEAD(fd,packet_len(0xbd));
  2272. buf=WFIFOP(fd,0);
  2273. WBUFW(buf,0)=0xbd;
  2274. WBUFW(buf,2)=min(sd->status.status_point, SHRT_MAX);
  2275. WBUFB(buf,4)=min(sd->status.str, UCHAR_MAX);
  2276. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2277. WBUFB(buf,6)=min(sd->status.agi, UCHAR_MAX);
  2278. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2279. WBUFB(buf,8)=min(sd->status.vit, UCHAR_MAX);
  2280. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2281. WBUFB(buf,10)=min(sd->status.int_, UCHAR_MAX);
  2282. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2283. WBUFB(buf,12)=min(sd->status.dex, UCHAR_MAX);
  2284. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2285. WBUFB(buf,14)=min(sd->status.luk, UCHAR_MAX);
  2286. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2287. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw.atk;
  2288. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2; //atk bonus
  2289. WBUFW(buf,20) = sd->battle_status.matk_max;
  2290. WBUFW(buf,22) = sd->battle_status.matk_min;
  2291. WBUFW(buf,24) = sd->battle_status.def; // def
  2292. WBUFW(buf,26) = sd->battle_status.def2;
  2293. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2294. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2295. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2296. WBUFW(buf,30) = fd;
  2297. fd = sd->fd;
  2298. WBUFW(buf,32) = sd->battle_status.hit;
  2299. WBUFW(buf,34) = sd->battle_status.flee;
  2300. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2301. WBUFW(buf,38) = sd->battle_status.cri/10;
  2302. WBUFW(buf,40) = sd->status.karma;
  2303. WBUFW(buf,42) = sd->status.manner;
  2304. WFIFOSET(fd,packet_len(0xbd));
  2305. clif_updatestatus(sd,SP_STR);
  2306. clif_updatestatus(sd,SP_AGI);
  2307. clif_updatestatus(sd,SP_VIT);
  2308. clif_updatestatus(sd,SP_INT);
  2309. clif_updatestatus(sd,SP_DEX);
  2310. clif_updatestatus(sd,SP_LUK);
  2311. clif_updatestatus(sd,SP_ATTACKRANGE);
  2312. clif_updatestatus(sd,SP_ASPD);
  2313. return 0;
  2314. }
  2315. /*==========================================
  2316. *矢装備
  2317. *------------------------------------------*/
  2318. int clif_arrowequip(struct map_session_data *sd,int val)
  2319. {
  2320. int fd;
  2321. nullpo_retr(0, sd);
  2322. pc_stop_attack(sd); // [Valaris]
  2323. fd=sd->fd;
  2324. WFIFOHEAD(fd, packet_len(0x013c));
  2325. WFIFOW(fd,0)=0x013c;
  2326. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2327. WFIFOSET(fd,packet_len(0x013c));
  2328. return 0;
  2329. }
  2330. /// Ammunition action message.
  2331. /// type=0 : MsgStringTable[242]="Please equip the proper ammunition first."
  2332. /// type=1 : MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2333. /// type=2 : MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2334. /// type=3 : assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2335. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2336. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2337. int clif_arrow_fail(struct map_session_data *sd,int type)
  2338. {
  2339. int fd;
  2340. nullpo_retr(0, sd);
  2341. fd=sd->fd;
  2342. WFIFOHEAD(fd, packet_len(0x013b));
  2343. WFIFOW(fd,0)=0x013b;
  2344. WFIFOW(fd,2)=type;
  2345. WFIFOSET(fd,packet_len(0x013b));
  2346. return 0;
  2347. }
  2348. /*==========================================
  2349. * 作成可能 矢リスト送信
  2350. *------------------------------------------*/
  2351. int clif_arrow_create_list(struct map_session_data *sd)
  2352. {
  2353. int i, c, j;
  2354. int fd;
  2355. nullpo_retr(0, sd);
  2356. fd = sd->fd;
  2357. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2358. WFIFOW(fd,0) = 0x1ad;
  2359. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2360. if (skill_arrow_db[i].nameid > 0 &&
  2361. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2362. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2363. {
  2364. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2365. WFIFOW(fd,c*2+4) = j;
  2366. else
  2367. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2368. c++;
  2369. }
  2370. }
  2371. WFIFOW(fd,2) = c*2+4;
  2372. WFIFOSET(fd, WFIFOW(fd,2));
  2373. if (c > 0) {
  2374. sd->menuskill_id = AC_MAKINGARROW;
  2375. sd->menuskill_val = c;
  2376. }
  2377. return 0;
  2378. }
  2379. /*==========================================
  2380. *
  2381. *------------------------------------------*/
  2382. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2383. {
  2384. int fd;
  2385. nullpo_retr(0, sd);
  2386. fd=sd->fd;
  2387. WFIFOHEAD(fd,packet_len(0xbc));
  2388. WFIFOW(fd,0)=0xbc;
  2389. WFIFOW(fd,2)=type;
  2390. WFIFOB(fd,4)=ok;
  2391. WFIFOB(fd,5)=val;
  2392. WFIFOSET(fd,packet_len(0xbc));
  2393. return 0;
  2394. }
  2395. /*==========================================
  2396. *
  2397. *------------------------------------------*/
  2398. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2399. {
  2400. int fd;
  2401. nullpo_retr(0, sd);
  2402. fd=sd->fd;
  2403. WFIFOHEAD(fd,packet_len(0xaa));
  2404. WFIFOW(fd,0)=0xaa;
  2405. WFIFOW(fd,2)=n+2;
  2406. WFIFOW(fd,4)=pos;
  2407. WFIFOB(fd,6)=ok;
  2408. WFIFOSET(fd,packet_len(0xaa));
  2409. return 0;
  2410. }
  2411. /*==========================================
  2412. *
  2413. *------------------------------------------*/
  2414. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2415. {
  2416. int fd;
  2417. nullpo_retr(0, sd);
  2418. fd=sd->fd;
  2419. WFIFOHEAD(fd,packet_len(0xac));
  2420. WFIFOW(fd,0)=0xac;
  2421. WFIFOW(fd,2)=n+2;
  2422. WFIFOW(fd,4)=pos;
  2423. WFIFOB(fd,6)=ok;
  2424. WFIFOSET(fd,packet_len(0xac));
  2425. return 0;
  2426. }
  2427. /*==========================================
  2428. *
  2429. *------------------------------------------*/
  2430. int clif_misceffect(struct block_list* bl,int type)
  2431. {
  2432. unsigned char buf[32];
  2433. nullpo_retr(0, bl);
  2434. WBUFW(buf,0) = 0x19b;
  2435. WBUFL(buf,2) = bl->id;
  2436. WBUFL(buf,6) = type;
  2437. clif_send(buf,packet_len(0x19b),bl,AREA);
  2438. return 0;
  2439. }
  2440. int clif_misceffect2(struct block_list *bl, int type)
  2441. {
  2442. unsigned char buf[24];
  2443. nullpo_retr(0, bl);
  2444. memset(buf, 0, packet_len(0x1f3));
  2445. WBUFW(buf,0) = 0x1f3;
  2446. WBUFL(buf,2) = bl->id;
  2447. WBUFL(buf,6) = type;
  2448. clif_send(buf, packet_len(0x1f3), bl, AREA);
  2449. return 0;
  2450. }
  2451. /*==========================================
  2452. * 表示オプション変更
  2453. *------------------------------------------*/
  2454. int clif_changeoption(struct block_list* bl)
  2455. {
  2456. unsigned char buf[32];
  2457. struct status_change *sc;
  2458. nullpo_retr(0, bl);
  2459. sc = status_get_sc(bl);
  2460. if (!sc) return 0; //How can an option change if there's no sc?
  2461. #if PACKETVER >= 7
  2462. WBUFW(buf,0) = 0x229;
  2463. WBUFL(buf,2) = bl->id;
  2464. WBUFW(buf,6) = sc->opt1;
  2465. WBUFW(buf,8) = sc->opt2;
  2466. WBUFL(buf,10) = sc->option;
  2467. WBUFB(buf,14) = 0; // PK???
  2468. if(disguised(bl)) {
  2469. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2470. WBUFL(buf,2) = -bl->id;
  2471. clif_send(buf,packet_len(0x229),bl,SELF);
  2472. WBUFL(buf,2) = bl->id;
  2473. WBUFL(buf,10) = OPTION_INVISIBLE;
  2474. clif_send(buf,packet_len(0x229),bl,SELF);
  2475. } else
  2476. clif_send(buf,packet_len(0x229),bl,AREA);
  2477. #else
  2478. WBUFW(buf,0) = 0x119;
  2479. WBUFL(buf,2) = bl->id;
  2480. WBUFW(buf,6) = sc->opt1;
  2481. WBUFW(buf,8) = sc->opt2;
  2482. WBUFW(buf,10) = sc->option;
  2483. WBUFB(buf,12) = 0; // ??
  2484. if(disguised(bl)) {
  2485. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2486. WBUFL(buf,2) = -bl->id;
  2487. clif_send(buf,packet_len(0x119),bl,SELF);
  2488. WBUFL(buf,2) = bl->id;
  2489. WBUFW(buf,10) = OPTION_INVISIBLE;
  2490. clif_send(buf,packet_len(0x119),bl,SELF);
  2491. } else
  2492. clif_send(buf,packet_len(0x119),bl,AREA);
  2493. #endif
  2494. return 0;
  2495. }
  2496. int clif_changeoption2(struct block_list* bl)
  2497. {
  2498. unsigned char buf[20];
  2499. struct status_change *sc;
  2500. sc = status_get_sc(bl);
  2501. if (!sc) return 0; //How can an option change if there's no sc?
  2502. WBUFW(buf,0) = 0x28a;
  2503. WBUFL(buf,2) = bl->id;
  2504. WBUFL(buf,6) = sc->option;
  2505. WBUFL(buf,10) = clif_setlevel(status_get_lv(bl));
  2506. WBUFL(buf,14) = sc->opt3;
  2507. if(disguised(bl)) {
  2508. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  2509. WBUFL(buf,2) = -bl->id;
  2510. clif_send(buf,packet_len(0x28a),bl,SELF);
  2511. WBUFL(buf,2) = bl->id;
  2512. WBUFL(buf,6) = OPTION_INVISIBLE;
  2513. clif_send(buf,packet_len(0x28a),bl,SELF);
  2514. } else
  2515. clif_send(buf,packet_len(0x28a),bl,AREA);
  2516. return 0;
  2517. }
  2518. /*==========================================
  2519. *
  2520. *------------------------------------------*/
  2521. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2522. {
  2523. nullpo_retr(0, sd);
  2524. if(!ok) {
  2525. int fd=sd->fd;
  2526. WFIFOHEAD(fd,packet_len(0xa8));
  2527. WFIFOW(fd,0)=0xa8;
  2528. WFIFOW(fd,2)=index+2;
  2529. WFIFOW(fd,4)=amount;
  2530. WFIFOB(fd,6)=ok;
  2531. WFIFOSET(fd,packet_len(0xa8));
  2532. }
  2533. else {
  2534. #if PACKETVER < 3
  2535. int fd=sd->fd;
  2536. WFIFOHEAD(fd,packet_len(0xa8));
  2537. WFIFOW(fd,0)=0xa8;
  2538. WFIFOW(fd,2)=index+2;
  2539. WFIFOW(fd,4)=amount;
  2540. WFIFOB(fd,6)=ok;
  2541. WFIFOSET(fd,packet_len(0xa8));
  2542. #else
  2543. unsigned char buf[32];
  2544. WBUFW(buf,0)=0x1c8;
  2545. WBUFW(buf,2)=index+2;
  2546. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2547. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2548. else
  2549. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2550. WBUFL(buf,6)=sd->bl.id;
  2551. WBUFW(buf,10)=amount;
  2552. WBUFB(buf,12)=ok;
  2553. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2554. #endif
  2555. }
  2556. return 0;
  2557. }
  2558. /*==========================================
  2559. * Inform client whether chatroom creation was successful or not
  2560. * R 00d6 <fail>.B
  2561. *------------------------------------------*/
  2562. void clif_createchat(struct map_session_data* sd, int fail)
  2563. {
  2564. int fd;
  2565. nullpo_retv(sd);
  2566. fd = sd->fd;
  2567. WFIFOHEAD(fd,packet_len(0xd6));
  2568. WFIFOW(fd,0) = 0xd6;
  2569. WFIFOB(fd,2) = fail;
  2570. WFIFOSET(fd,packet_len(0xd6));
  2571. }
  2572. /*==========================================
  2573. * Display a chat above the owner
  2574. * R 00d7 <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <type>.B <title>.?B
  2575. *------------------------------------------*/
  2576. int clif_dispchat(struct chat_data* cd, int fd)
  2577. {
  2578. unsigned char buf[128];
  2579. uint8 type;
  2580. if( cd == NULL || cd->owner == NULL )
  2581. return 1;
  2582. // type - 0: private, 1: public, 2: npc, 3: non-clickable
  2583. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  2584. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  2585. : 1;
  2586. WBUFW(buf, 0) = 0xd7;
  2587. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2588. WBUFL(buf, 4) = cd->owner->id;
  2589. WBUFL(buf, 8) = cd->bl.id;
  2590. WBUFW(buf,12) = cd->limit;
  2591. WBUFW(buf,14) = cd->users;
  2592. WBUFB(buf,16) = type;
  2593. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2594. if( fd ) {
  2595. WFIFOHEAD(fd,WBUFW(buf,2));
  2596. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2597. WFIFOSET(fd,WBUFW(buf,2));
  2598. } else {
  2599. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  2600. }
  2601. return 0;
  2602. }
  2603. /*==========================================
  2604. * Chatroom properties adjustment
  2605. * R 00df <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <pub>.B <title>.?B
  2606. *------------------------------------------*/
  2607. int clif_changechatstatus(struct chat_data* cd)
  2608. {
  2609. unsigned char buf[128];
  2610. if( cd == NULL || cd->usersd[0] == NULL )
  2611. return 1;
  2612. WBUFW(buf, 0) = 0xdf;
  2613. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2614. WBUFL(buf, 4) = cd->usersd[0]->bl.id;
  2615. WBUFL(buf, 8) = cd->bl.id;
  2616. WBUFW(buf,12) = cd->limit;
  2617. WBUFW(buf,14) = cd->users;
  2618. WBUFB(buf,16) = cd->pub;
  2619. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2620. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2621. return 0;
  2622. }
  2623. /*==========================================
  2624. *
  2625. *------------------------------------------*/
  2626. int clif_clearchat(struct chat_data *cd,int fd)
  2627. {
  2628. unsigned char buf[32];
  2629. nullpo_retr(0, cd);
  2630. WBUFW(buf,0) = 0xd8;
  2631. WBUFL(buf,2) = cd->bl.id;
  2632. if( fd ) {
  2633. WFIFOHEAD(fd,packet_len(0xd8));
  2634. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2635. WFIFOSET(fd,packet_len(0xd8));
  2636. } else {
  2637. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  2638. }
  2639. return 0;
  2640. }
  2641. /*==========================================
  2642. *
  2643. *------------------------------------------*/
  2644. int clif_joinchatfail(struct map_session_data *sd,int fail)
  2645. {
  2646. int fd;
  2647. nullpo_retr(0, sd);
  2648. fd = sd->fd;
  2649. WFIFOHEAD(fd,packet_len(0xda));
  2650. WFIFOW(fd,0) = 0xda;
  2651. WFIFOB(fd,2) = fail;
  2652. WFIFOSET(fd,packet_len(0xda));
  2653. return 0;
  2654. }
  2655. /*==========================================
  2656. *
  2657. *------------------------------------------*/
  2658. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2659. {
  2660. int fd;
  2661. int i;
  2662. nullpo_retr(0, sd);
  2663. nullpo_retr(0, cd);
  2664. fd = sd->fd;
  2665. if (!session_isActive(fd))
  2666. return 0;
  2667. WFIFOHEAD(fd, 8 + (28*cd->users));
  2668. WFIFOW(fd, 0) = 0xdb;
  2669. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2670. WFIFOL(fd, 4) = cd->bl.id;
  2671. for (i = 0; i < cd->users; i++) {
  2672. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  2673. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2674. }
  2675. WFIFOSET(fd, WFIFOW(fd, 2));
  2676. return 0;
  2677. }
  2678. /*==========================================
  2679. *
  2680. *------------------------------------------*/
  2681. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2682. {
  2683. unsigned char buf[32];
  2684. nullpo_retr(0, sd);
  2685. nullpo_retr(0, cd);
  2686. WBUFW(buf, 0) = 0x0dc;
  2687. WBUFW(buf, 2) = cd->users;
  2688. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2689. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  2690. return 0;
  2691. }
  2692. /*==========================================
  2693. * Announce the new owner
  2694. * R 00e1 <index>.l <nick>.24B
  2695. *------------------------------------------*/
  2696. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  2697. {
  2698. unsigned char buf[64];
  2699. nullpo_retv(sd);
  2700. nullpo_retv(cd);
  2701. //FIXME: this announces a swap between positions 0 and 1 (probably not what we want) [ultramage]
  2702. //FIXME: aegis sends obviously incorrect packets; need to figure out what to send to display it correctly :X
  2703. //TODO: is it just owner swap, or can it do general-purpose reordering?
  2704. WBUFW(buf, 0) = 0xe1;
  2705. WBUFL(buf, 2) = 1;
  2706. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2707. WBUFW(buf,30) = 0xe1;
  2708. WBUFL(buf,32) = 0;
  2709. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2710. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  2711. }
  2712. /*==========================================
  2713. * Notify about user leaving the chatroom
  2714. * R 00dd <index>.w <nick>.24B <flag>.B
  2715. *------------------------------------------*/
  2716. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  2717. {
  2718. unsigned char buf[32];
  2719. nullpo_retv(sd);
  2720. nullpo_retv(cd);
  2721. WBUFW(buf, 0) = 0xdd;
  2722. WBUFW(buf, 2) = cd->users-1;
  2723. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2724. WBUFB(buf,28) = flag; // 0: left, 1: was kicked
  2725. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  2726. }
  2727. /*==========================================
  2728. * Opens a trade request window from char 'name'
  2729. * R 00e5 <nick>.24B
  2730. * R 01f4 <nick>.24B <charid>.L <baselvl>.W
  2731. *------------------------------------------*/
  2732. void clif_traderequest(struct map_session_data* sd, const char* name)
  2733. {
  2734. int fd = sd->fd;
  2735. #if PACKETVER < 6
  2736. WFIFOHEAD(fd,packet_len(0xe5));
  2737. WFIFOW(fd,0) = 0xe5;
  2738. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2739. WFIFOSET(fd,packet_len(0xe5));
  2740. #else
  2741. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2742. if( !tsd ) return;
  2743. WFIFOHEAD(fd,packet_len(0x1f4));
  2744. WFIFOW(fd,0) = 0x1f4;
  2745. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2746. WFIFOL(fd,26) = tsd->status.char_id;
  2747. WFIFOW(fd,30) = clif_setlevel(tsd->status.base_level);
  2748. WFIFOSET(fd,packet_len(0x1f4));
  2749. #endif
  2750. }
  2751. /*==========================================
  2752. * Reply to a trade-request.
  2753. * R 00e7 <type>.B
  2754. * R 01f5 <type>.B <charid>.L <baselvl>.W
  2755. * Type:
  2756. * 0: Char is too far
  2757. * 1: Character does not exist
  2758. * 2: Trade failed
  2759. * 3: Accept
  2760. * 4: Cancel
  2761. *------------------------------------------*/
  2762. void clif_tradestart(struct map_session_data* sd, uint8 type)
  2763. {
  2764. int fd = sd->fd;
  2765. #if PACKETVER < 6
  2766. WFIFOHEAD(fd,packet_len(0xe7));
  2767. WFIFOW(fd,0) = 0xe7;
  2768. WFIFOB(fd,2) = type;
  2769. WFIFOSET(fd,packet_len(0xe7));
  2770. #else
  2771. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2772. if( !tsd ) return;
  2773. WFIFOHEAD(fd,packet_len(0x1f5));
  2774. WFIFOW(fd,0) = 0x1f5;
  2775. WFIFOB(fd,2) = type;
  2776. WFIFOL(fd,3) = tsd->status.char_id;
  2777. WFIFOW(fd,7) = clif_setlevel(tsd->status.base_level);
  2778. WFIFOSET(fd,packet_len(0x1f5));
  2779. #endif
  2780. }
  2781. /*==========================================
  2782. * 相手方からのアイテム追加
  2783. *------------------------------------------*/
  2784. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  2785. {
  2786. int fd;
  2787. nullpo_retv(sd);
  2788. nullpo_retv(tsd);
  2789. fd = tsd->fd;
  2790. WFIFOHEAD(fd,packet_len(0xe9));
  2791. WFIFOW(fd,0) = 0xe9;
  2792. WFIFOL(fd,2) = amount;
  2793. if( index == 0 )
  2794. {
  2795. WFIFOW(fd,6) = 0; // type id
  2796. WFIFOB(fd,8) = 0; //identify flag
  2797. WFIFOB(fd,9) = 0; // attribute
  2798. WFIFOB(fd,10)= 0; //refine
  2799. WFIFOW(fd,11)= 0; //card (4w)
  2800. WFIFOW(fd,13)= 0; //card (4w)
  2801. WFIFOW(fd,15)= 0; //card (4w)
  2802. WFIFOW(fd,17)= 0; //card (4w)
  2803. }
  2804. else
  2805. {
  2806. index -= 2; //index fix
  2807. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2808. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  2809. else
  2810. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  2811. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  2812. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  2813. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  2814. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  2815. }
  2816. WFIFOSET(fd,packet_len(0xe9));
  2817. }
  2818. /*==========================================
  2819. * アイテム追加成功/失敗
  2820. *------------------------------------------*/
  2821. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  2822. {
  2823. int fd;
  2824. nullpo_retv(sd);
  2825. fd = sd->fd;
  2826. WFIFOHEAD(fd,packet_len(0xea));
  2827. WFIFOW(fd,0) = 0xea;
  2828. WFIFOW(fd,2) = index;
  2829. WFIFOB(fd,4) = fail;
  2830. WFIFOSET(fd,packet_len(0xea));
  2831. }
  2832. /*==========================================
  2833. * 取り引きok押し
  2834. *------------------------------------------*/
  2835. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  2836. {
  2837. int fd;
  2838. nullpo_retv(sd);
  2839. fd = sd->fd;
  2840. WFIFOHEAD(fd,packet_len(0xec));
  2841. WFIFOW(fd,0) = 0xec;
  2842. WFIFOB(fd,2) = fail; // 0=you 1=the other person
  2843. WFIFOSET(fd,packet_len(0xec));
  2844. }
  2845. /*==========================================
  2846. * 取り引きがキャンセルされました
  2847. *------------------------------------------*/
  2848. void clif_tradecancelled(struct map_session_data* sd)
  2849. {
  2850. int fd;
  2851. nullpo_retv(sd);
  2852. fd = sd->fd;
  2853. WFIFOHEAD(fd,packet_len(0xee));
  2854. WFIFOW(fd,0) = 0xee;
  2855. WFIFOSET(fd,packet_len(0xee));
  2856. }
  2857. /*==========================================
  2858. * 取り引き完了
  2859. *------------------------------------------*/
  2860. void clif_tradecompleted(struct map_session_data* sd, int fail)
  2861. {
  2862. int fd;
  2863. nullpo_retv(sd);
  2864. fd = sd->fd;
  2865. WFIFOHEAD(fd,packet_len(0xf0));
  2866. WFIFOW(fd,0) = 0xf0;
  2867. WFIFOB(fd,2) = fail;
  2868. WFIFOSET(fd,packet_len(0xf0));
  2869. }
  2870. /*==========================================
  2871. * カプラ倉庫のアイテム数を更新
  2872. *------------------------------------------*/
  2873. int clif_updatestorageamount(struct map_session_data *sd,struct storage *stor)
  2874. {
  2875. int fd;
  2876. nullpo_retr(0, sd);
  2877. nullpo_retr(0, stor);
  2878. fd=sd->fd;
  2879. WFIFOHEAD(fd,packet_len(0xf2));
  2880. WFIFOW(fd,0) = 0xf2; // update storage amount
  2881. WFIFOW(fd,2) = stor->storage_amount; //items
  2882. WFIFOW(fd,4) = MAX_STORAGE; //items max
  2883. WFIFOSET(fd,packet_len(0xf2));
  2884. return 0;
  2885. }
  2886. /*==========================================
  2887. * カプラ倉庫にアイテムを追加する
  2888. *------------------------------------------*/
  2889. int clif_storageitemadded(struct map_session_data *sd,struct storage *stor,int index,int amount)
  2890. {
  2891. int view,fd;
  2892. nullpo_retr(0, sd);
  2893. nullpo_retr(0, stor);
  2894. fd=sd->fd;
  2895. WFIFOHEAD(fd,packet_len(0xf4));
  2896. WFIFOW(fd,0) =0xf4; // Storage item added
  2897. WFIFOW(fd,2) =index+1; // index
  2898. WFIFOL(fd,4) =amount; // amount
  2899. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  2900. WFIFOW(fd,8) =view;
  2901. else
  2902. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  2903. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  2904. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  2905. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  2906. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  2907. WFIFOSET(fd,packet_len(0xf4));
  2908. return 0;
  2909. }
  2910. /*==========================================
  2911. *
  2912. *------------------------------------------*/
  2913. int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor)
  2914. {
  2915. int fd;
  2916. nullpo_retr(0, sd);
  2917. nullpo_retr(0, stor);
  2918. fd=sd->fd;
  2919. WFIFOHEAD(fd,packet_len(0xf2));
  2920. WFIFOW(fd,0) = 0xf2; // update storage amount
  2921. WFIFOW(fd,2) = stor->storage_amount; //items
  2922. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  2923. WFIFOSET(fd,packet_len(0xf2));
  2924. return 0;
  2925. }
  2926. /*==========================================
  2927. *
  2928. *------------------------------------------*/
  2929. int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount)
  2930. {
  2931. int view,fd;
  2932. nullpo_retr(0, sd);
  2933. nullpo_retr(0, stor);
  2934. fd=sd->fd;
  2935. WFIFOHEAD(fd,packet_len(0xf4));
  2936. WFIFOW(fd,0) =0xf4; // Storage item added
  2937. WFIFOW(fd,2) =index+1; // index
  2938. WFIFOL(fd,4) =amount; // amount
  2939. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  2940. WFIFOW(fd,8) =view;
  2941. else
  2942. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  2943. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  2944. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  2945. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  2946. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  2947. WFIFOSET(fd,packet_len(0xf4));
  2948. return 0;
  2949. }
  2950. /*==========================================
  2951. * カプラ倉庫からアイテムを取り去る
  2952. *------------------------------------------*/
  2953. int clif_storageitemremoved(struct map_session_data *sd,int index,int amount)
  2954. {
  2955. int fd;
  2956. nullpo_retr(0, sd);
  2957. fd=sd->fd;
  2958. WFIFOHEAD(fd,packet_len(0xf6));
  2959. WFIFOW(fd,0)=0xf6; // Storage item removed
  2960. WFIFOW(fd,2)=index+1;
  2961. WFIFOL(fd,4)=amount;
  2962. WFIFOSET(fd,packet_len(0xf6));
  2963. return 0;
  2964. }
  2965. /*==========================================
  2966. * カプラ倉庫を閉じる
  2967. *------------------------------------------*/
  2968. int clif_storageclose(struct map_session_data *sd)
  2969. {
  2970. int fd;
  2971. nullpo_retr(0, sd);
  2972. fd=sd->fd;
  2973. WFIFOHEAD(fd,packet_len(0xf8));
  2974. WFIFOW(fd,0)=0xf8; // Storage Closed
  2975. WFIFOSET(fd,packet_len(0xf8));
  2976. return 0;
  2977. }
  2978. /*==========================================
  2979. * PC表示
  2980. *------------------------------------------*/
  2981. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  2982. {
  2983. int len;
  2984. if(dstsd->chatID)
  2985. {
  2986. struct chat_data *cd;
  2987. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  2988. if(cd && cd->usersd[0]==dstsd)
  2989. clif_dispchat(cd,sd->fd);
  2990. }
  2991. if(dstsd->vender_id)
  2992. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  2993. if(dstsd->spiritball > 0)
  2994. clif_spiritball_single(sd->fd, dstsd);
  2995. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  2996. (battle_config.disp_hpmeter && (len = pc_isGM(sd)) >= battle_config.disp_hpmeter && len >= pc_isGM(dstsd))
  2997. )
  2998. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  2999. if(dstsd->status.manner < 0)
  3000. clif_changestatus(&dstsd->bl,SP_MANNER,dstsd->status.manner);
  3001. // pvp circle for duel [LuzZza]
  3002. //if(dstsd->duel_group)
  3003. // clif_specialeffect(&dstsd->bl, 159, 4);
  3004. }
  3005. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3006. {
  3007. uint8 buf[128];
  3008. struct unit_data *ud;
  3009. struct view_data *vd;
  3010. int len;
  3011. vd = status_get_viewdata(bl);
  3012. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3013. return;
  3014. ud = unit_bl2ud(bl);
  3015. len = ( ud && ud->walktimer != -1 ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3016. clif_send(buf,len,&sd->bl,SELF);
  3017. if (vd->cloth_color)
  3018. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3019. switch (bl->type)
  3020. { // FIXME: 'AREA' causes unneccessary spam since this should be 1:1 communication [ultramage]
  3021. case BL_PC:
  3022. {
  3023. TBL_PC* tsd = (TBL_PC*)bl;
  3024. clif_getareachar_pc(sd, tsd);
  3025. if(tsd->state.size==2) // tiny/big players [Valaris]
  3026. clif_specialeffect(bl,423,AREA);
  3027. else if(tsd->state.size==1)
  3028. clif_specialeffect(bl,421,AREA);
  3029. }
  3030. break;
  3031. case BL_NPC:
  3032. {
  3033. TBL_NPC* nd = (TBL_NPC*)bl;
  3034. if( nd->chat_id )
  3035. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3036. }
  3037. break;
  3038. case BL_MOB:
  3039. {
  3040. TBL_MOB* md = (TBL_MOB*)bl;
  3041. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3042. clif_specialeffect(bl,423,AREA);
  3043. else if(md->special_state.size==1)
  3044. clif_specialeffect(bl,421,AREA);
  3045. }
  3046. break;
  3047. case BL_PET:
  3048. if (vd->head_bottom)
  3049. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3050. break;
  3051. }
  3052. }
  3053. /*==========================================
  3054. * Estimates walk delay based on the damage criteria. [Skotlex]
  3055. *------------------------------------------*/
  3056. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3057. {
  3058. if (type == 4 || type == 9 || damage <=0)
  3059. return 0;
  3060. if (bl->type == BL_PC) {
  3061. if (battle_config.pc_walk_delay_rate != 100)
  3062. delay = delay*battle_config.pc_walk_delay_rate/100;
  3063. } else
  3064. if (battle_config.walk_delay_rate != 100)
  3065. delay = delay*battle_config.walk_delay_rate/100;
  3066. if (div_ > 1) //Multi-hit skills mean higher delays.
  3067. delay += battle_config.multihit_delay*(div_-1);
  3068. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3069. }
  3070. /*==========================================
  3071. * Sends a 'damage' packet (src performs action on dst)
  3072. * 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
  3073. *
  3074. * type=00 damage [param1: total damage, param2: div, param3: assassin dual-wield damage]
  3075. * type=01 pick up item
  3076. * type=02 sit down
  3077. * type=03 stand up
  3078. * type=04 reflected/absorbed damage?
  3079. * type=08 double attack
  3080. * type=09 don't display flinch animation (endure)
  3081. * type=0a critical hit
  3082. * type=0b lucky dodge
  3083. *------------------------------------------*/
  3084. 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)
  3085. {
  3086. unsigned char buf[256];
  3087. struct status_change *sc;
  3088. nullpo_retr(0, src);
  3089. nullpo_retr(0, dst);
  3090. sc = status_get_sc(dst);
  3091. if(sc && sc->count) {
  3092. if(type != 4 && dst->type == BL_PC && sc->data[SC_ENDURE] && !map_flag_gvg(dst->m))
  3093. type = 9;
  3094. if(sc->data[SC_HALLUCINATION]) {
  3095. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3096. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3097. }
  3098. }
  3099. WBUFW(buf,0)=0x8a;
  3100. WBUFL(buf,2)=src->id;
  3101. WBUFL(buf,6)=dst->id;
  3102. WBUFL(buf,10)=tick;
  3103. WBUFL(buf,14)=sdelay;
  3104. WBUFL(buf,18)=ddelay;
  3105. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3106. WBUFW(buf,22)=damage?div:0;
  3107. WBUFW(buf,27)=damage2?div:0;
  3108. } else {
  3109. WBUFW(buf,22)=min(damage, SHRT_MAX);
  3110. WBUFW(buf,27)=damage2;
  3111. }
  3112. WBUFW(buf,24)=div;
  3113. WBUFB(buf,26)=type;
  3114. if(disguised(dst)) {
  3115. clif_send(buf,packet_len(0x8a),dst,AREA_WOS);
  3116. WBUFL(buf,6) = -dst->id;
  3117. clif_send(buf,packet_len(0x8a),dst,SELF);
  3118. } else
  3119. clif_send(buf,packet_len(0x8a),dst,AREA);
  3120. if(disguised(src)) {
  3121. WBUFL(buf,2) = -src->id;
  3122. if (disguised(dst))
  3123. WBUFL(buf,6) = dst->id;
  3124. if(damage > 0) WBUFW(buf,22) = -1;
  3125. if(damage2 > 0) WBUFW(buf,27) = -1;
  3126. clif_send(buf,packet_len(0x8a),src,SELF);
  3127. }
  3128. //Return adjusted can't walk delay for further processing.
  3129. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3130. }
  3131. /*==========================================
  3132. * src picks up dst
  3133. *------------------------------------------*/
  3134. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3135. {
  3136. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3137. unsigned char buf[32];
  3138. nullpo_retv(src);
  3139. nullpo_retv(dst);
  3140. WBUFW(buf, 0) = 0x8a;
  3141. WBUFL(buf, 2) = src->id;
  3142. WBUFL(buf, 6) = dst->id;
  3143. WBUFB(buf,26) = 1;
  3144. clif_send(buf, packet_len(0x8a), src, AREA);
  3145. }
  3146. /*==========================================
  3147. * inform clients in area that `bl` is sitting
  3148. *------------------------------------------*/
  3149. void clif_sitting(struct block_list* bl)
  3150. {
  3151. unsigned char buf[32];
  3152. nullpo_retv(bl);
  3153. WBUFW(buf, 0) = 0x8a;
  3154. WBUFL(buf, 2) = bl->id;
  3155. WBUFB(buf,26) = 2;
  3156. clif_send(buf, packet_len(0x8a), bl, AREA);
  3157. if(disguised(bl)) {
  3158. WBUFL(buf, 2) = - bl->id;
  3159. clif_send(buf, packet_len(0x8a), bl, SELF);
  3160. }
  3161. }
  3162. /*==========================================
  3163. * inform clients in area that `bl` is standing
  3164. *------------------------------------------*/
  3165. void clif_standing(struct block_list* bl)
  3166. {
  3167. unsigned char buf[32];
  3168. nullpo_retv(bl);
  3169. WBUFW(buf, 0) = 0x8a;
  3170. WBUFL(buf, 2) = bl->id;
  3171. WBUFB(buf,26) = 3;
  3172. clif_send(buf, packet_len(0x8a), bl, AREA);
  3173. if(disguised(bl)) {
  3174. WBUFL(buf, 2) = - bl->id;
  3175. clif_send(buf, packet_len(0x8a), bl, SELF);
  3176. }
  3177. }
  3178. /*==========================================
  3179. * Inform client(s) about a map-cell change
  3180. *------------------------------------------*/
  3181. void clif_changemapcell(int fd, struct block_list* pos, int type, enum send_target target)
  3182. {
  3183. unsigned char buf[32];
  3184. nullpo_retv(pos);
  3185. WBUFW(buf,0) = 0x192;
  3186. WBUFW(buf,2) = pos->x;
  3187. WBUFW(buf,4) = pos->y;
  3188. WBUFW(buf,6) = type;
  3189. mapindex_getmapname_ext(map[pos->m].name,(char*)WBUFP(buf,8));
  3190. if( fd )
  3191. {
  3192. WFIFOHEAD(fd,packet_len(0x192));
  3193. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3194. WFIFOSET(fd,packet_len(0x192));
  3195. }
  3196. else
  3197. clif_send(buf,packet_len(0x192),pos,target);
  3198. }
  3199. /*==========================================
  3200. *
  3201. *------------------------------------------*/
  3202. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3203. {
  3204. int view,fd;
  3205. fd=sd->fd;
  3206. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3207. WFIFOHEAD(fd,packet_len(0x9d));
  3208. WFIFOW(fd,0)=0x9d;
  3209. WFIFOL(fd,2)=fitem->bl.id;
  3210. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3211. WFIFOW(fd,6)=view;
  3212. else
  3213. WFIFOW(fd,6)=fitem->item_data.nameid;
  3214. WFIFOB(fd,8)=fitem->item_data.identify;
  3215. WFIFOW(fd,9)=fitem->bl.x;
  3216. WFIFOW(fd,11)=fitem->bl.y;
  3217. WFIFOW(fd,13)=fitem->item_data.amount;
  3218. WFIFOB(fd,15)=fitem->subx;
  3219. WFIFOB(fd,16)=fitem->suby;
  3220. WFIFOSET(fd,packet_len(0x9d));
  3221. }
  3222. /*==========================================
  3223. * 場所スキルエフェクトが視界に入る
  3224. *------------------------------------------*/
  3225. static void clif_getareachar_skillunit(struct map_session_data *sd, struct skill_unit *unit)
  3226. {
  3227. int fd = sd->fd;
  3228. #if PACKETVER >= 3
  3229. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3230. WFIFOHEAD(fd,packet_len(0x1c9));
  3231. WFIFOW(fd, 0)=0x1c9;
  3232. WFIFOL(fd, 2)=unit->bl.id;
  3233. WFIFOL(fd, 6)=unit->group->src_id;
  3234. WFIFOW(fd,10)=unit->bl.x;
  3235. WFIFOW(fd,12)=unit->bl.y;
  3236. WFIFOB(fd,14)=unit->group->unit_id;
  3237. WFIFOB(fd,15)=1;
  3238. WFIFOB(fd,16)=1;
  3239. safestrncpy((char*)WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3240. WFIFOSET(fd,packet_len(0x1c9));
  3241. return;
  3242. }
  3243. #endif
  3244. WFIFOHEAD(fd,packet_len(0x11f));
  3245. WFIFOW(fd, 0)=0x11f;
  3246. WFIFOL(fd, 2)=unit->bl.id;
  3247. WFIFOL(fd, 6)=unit->group->src_id;
  3248. WFIFOW(fd,10)=unit->bl.x;
  3249. WFIFOW(fd,12)=unit->bl.y;
  3250. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3251. WFIFOB(fd,14)=UNT_ATTACK_SKILLS; //Use invisible unit id for traps.
  3252. else
  3253. WFIFOB(fd,14)=unit->group->unit_id;
  3254. WFIFOB(fd,15)=1; // ignored by client (always gets set to 1)
  3255. WFIFOSET(fd,packet_len(0x11f));
  3256. if(unit->group->skill_id == WZ_ICEWALL)
  3257. clif_changemapcell(fd,&unit->bl,5,SELF);
  3258. }
  3259. /*==========================================
  3260. * 場所スキルエフェクトが視界から消える
  3261. *------------------------------------------*/
  3262. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3263. {
  3264. nullpo_retv(unit);
  3265. WFIFOHEAD(fd,packet_len(0x120));
  3266. WFIFOW(fd, 0)=0x120;
  3267. WFIFOL(fd, 2)=unit->bl.id;
  3268. WFIFOSET(fd,packet_len(0x120));
  3269. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3270. clif_changemapcell(fd,&unit->bl,unit->val2,SELF);
  3271. }
  3272. /*==========================================
  3273. * 場所スキルエフェクト削除
  3274. *------------------------------------------*/
  3275. void clif_skill_delunit(struct skill_unit *unit)
  3276. {
  3277. unsigned char buf[16];
  3278. nullpo_retv(unit);
  3279. WBUFW(buf, 0)=0x120;
  3280. WBUFL(buf, 2)=unit->bl.id;
  3281. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3282. }
  3283. /*==========================================
  3284. * Unknown... trap related?
  3285. * Sent when an object gets ankle-snared
  3286. * Only affects units with class [139,153] client-side
  3287. * R 01ac <object id>.l
  3288. *------------------------------------------*/
  3289. void clif_01ac(struct block_list* bl)
  3290. {
  3291. unsigned char buf[6];
  3292. nullpo_retv(bl);
  3293. WBUFW(buf,0) = 0x1ac;
  3294. WBUFL(buf,2) = bl->id;
  3295. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3296. }
  3297. /*==========================================
  3298. *
  3299. *------------------------------------------*/
  3300. int clif_getareachar(struct block_list* bl,va_list ap)
  3301. {
  3302. struct map_session_data *sd;
  3303. nullpo_retr(0, bl);
  3304. nullpo_retr(0, ap);
  3305. sd=va_arg(ap,struct map_session_data*);
  3306. if (sd == NULL || !sd->fd || session[sd->fd] == NULL)
  3307. return 0;
  3308. switch(bl->type){
  3309. case BL_ITEM:
  3310. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3311. break;
  3312. case BL_SKILL:
  3313. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3314. break;
  3315. default:
  3316. if(&sd->bl == bl)
  3317. break;
  3318. clif_getareachar_unit(sd,bl);
  3319. break;
  3320. }
  3321. return 0;
  3322. }
  3323. /*==========================================
  3324. * tbl has gone out of view-size of bl
  3325. *------------------------------------------*/
  3326. int clif_outsight(struct block_list *bl,va_list ap)
  3327. {
  3328. struct block_list *tbl;
  3329. struct view_data *vd;
  3330. TBL_PC *sd, *tsd;
  3331. tbl=va_arg(ap,struct block_list*);
  3332. if(bl == tbl) return 0;
  3333. BL_CAST(BL_PC, bl, sd);
  3334. BL_CAST(BL_PC, tbl, tsd);
  3335. if (tsd && tsd->fd)
  3336. { //tsd has lost sight of the bl object.
  3337. switch(bl->type){
  3338. case BL_PC:
  3339. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS)
  3340. clif_clearunit_single(bl->id,0,tsd->fd);
  3341. if(sd->chatID){
  3342. struct chat_data *cd;
  3343. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3344. if(cd->usersd[0]==sd)
  3345. clif_dispchat(cd,tsd->fd);
  3346. }
  3347. if(sd->vender_id)
  3348. clif_closevendingboard(bl,tsd->fd);
  3349. break;
  3350. case BL_ITEM:
  3351. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3352. break;
  3353. case BL_SKILL:
  3354. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3355. break;
  3356. default:
  3357. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3358. clif_clearunit_single(bl->id,0,tsd->fd);
  3359. break;
  3360. }
  3361. }
  3362. if (sd && sd->fd)
  3363. { //sd is watching tbl go out of view.
  3364. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3365. clif_clearunit_single(tbl->id,0,sd->fd);
  3366. }
  3367. return 0;
  3368. }
  3369. /*==========================================
  3370. * tbl has come into view of bl
  3371. *------------------------------------------*/
  3372. int clif_insight(struct block_list *bl,va_list ap)
  3373. {
  3374. struct block_list *tbl;
  3375. TBL_PC *sd, *tsd;
  3376. tbl=va_arg(ap,struct block_list*);
  3377. if (bl == tbl) return 0;
  3378. BL_CAST(BL_PC, bl, sd);
  3379. BL_CAST(BL_PC, tbl, tsd);
  3380. if (tsd && tsd->fd)
  3381. { //Tell tsd that bl entered into his view
  3382. switch(bl->type){
  3383. case BL_ITEM:
  3384. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3385. break;
  3386. case BL_SKILL:
  3387. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3388. break;
  3389. default:
  3390. clif_getareachar_unit(tsd,bl);
  3391. break;
  3392. }
  3393. }
  3394. if (sd && sd->fd)
  3395. { //Tell sd that tbl walked into his view
  3396. clif_getareachar_unit(sd,tbl);
  3397. }
  3398. return 0;
  3399. }
  3400. /*==========================================
  3401. *
  3402. *------------------------------------------*/
  3403. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3404. {
  3405. int fd,id;
  3406. nullpo_retr(0, sd);
  3407. fd=sd->fd;
  3408. if( (id=sd->status.skill[skillid].id) <= 0 )
  3409. return 0;
  3410. WFIFOHEAD(fd,packet_len(0x147));
  3411. WFIFOW(fd,0)=0x147;
  3412. WFIFOW(fd,2) = id;
  3413. if(type < 0)
  3414. WFIFOW(fd,4) = skill_get_inf(id);
  3415. else
  3416. WFIFOW(fd,4) = type;
  3417. WFIFOW(fd,6) = 0;
  3418. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3419. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3420. if(range < 0)
  3421. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3422. WFIFOW(fd,12)= range;
  3423. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3424. if(sd->status.skill[skillid].flag ==0)
  3425. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3426. else
  3427. WFIFOB(fd,38) = 0;
  3428. WFIFOSET(fd,packet_len(0x147));
  3429. return 0;
  3430. }
  3431. /*==========================================
  3432. * スキルリストを送信する
  3433. *------------------------------------------*/
  3434. int clif_skillinfoblock(struct map_session_data *sd)
  3435. {
  3436. int fd;
  3437. int i,c,len,id;
  3438. nullpo_retr(0, sd);
  3439. fd=sd->fd;
  3440. if (!fd) return 0;
  3441. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3442. WFIFOW(fd,0) = 0x10f;
  3443. for ( i = 0, c = 0, len = 4; i < MAX_SKILL; i++)
  3444. {
  3445. if( (id = sd->status.skill[i].id) != 0 )
  3446. {
  3447. WFIFOW(fd,len) = id;
  3448. WFIFOW(fd,len+2) = skill_get_inf(id);
  3449. WFIFOW(fd,len+4) = 0;
  3450. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3451. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3452. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3453. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3454. if(sd->status.skill[i].flag == 0)
  3455. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3456. else
  3457. WFIFOB(fd,len+36) = 0;
  3458. len += 37;
  3459. c++;
  3460. }
  3461. }
  3462. WFIFOW(fd,2)=len;
  3463. WFIFOSET(fd,len);
  3464. return 1;
  3465. }
  3466. /*==========================================
  3467. * スキル割り振り通知
  3468. *------------------------------------------*/
  3469. int clif_skillup(struct map_session_data *sd,int skill_num)
  3470. {
  3471. int fd;
  3472. nullpo_retr(0, sd);
  3473. fd=sd->fd;
  3474. WFIFOHEAD(fd,packet_len(0x10e));
  3475. WFIFOW(fd,0) = 0x10e;
  3476. WFIFOW(fd,2) = skill_num;
  3477. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3478. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3479. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3480. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3481. WFIFOSET(fd,packet_len(0x10e));
  3482. return 0;
  3483. }
  3484. /*==========================================
  3485. * スキル詠唱エフェクトを送信する
  3486. *------------------------------------------*/
  3487. int clif_skillcasting(struct block_list* bl,
  3488. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int pl, int casttime)
  3489. {
  3490. unsigned char buf[32];
  3491. WBUFW(buf,0) = 0x13e;
  3492. WBUFL(buf,2) = src_id;
  3493. WBUFL(buf,6) = dst_id;
  3494. WBUFW(buf,10) = dst_x;
  3495. WBUFW(buf,12) = dst_y;
  3496. WBUFW(buf,14) = skill_num;
  3497. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3498. WBUFL(buf,20) = casttime;
  3499. if (disguised(bl)) {
  3500. clif_send(buf,packet_len(0x13e), bl, AREA_WOS);
  3501. WBUFL(buf,2) = -src_id;
  3502. clif_send(buf,packet_len(0x13e), bl, SELF);
  3503. } else
  3504. clif_send(buf,packet_len(0x13e), bl, AREA);
  3505. return 0;
  3506. }
  3507. /*==========================================
  3508. *
  3509. *------------------------------------------*/
  3510. int clif_skillcastcancel(struct block_list* bl)
  3511. {
  3512. unsigned char buf[16];
  3513. nullpo_retr(0, bl);
  3514. WBUFW(buf,0) = 0x1b9;
  3515. WBUFL(buf,2) = bl->id;
  3516. clif_send(buf,packet_len(0x1b9), bl, AREA);
  3517. return 0;
  3518. }
  3519. /// only when type==0:
  3520. /// if(skill_id==NV_BASIC)
  3521. /// btype==0 "skill failed" MsgStringTable[159]
  3522. /// btype==1 "no emotions" MsgStringTable[160]
  3523. /// btype==2 "no sit" MsgStringTable[161]
  3524. /// btype==3 "no chat" MsgStringTable[162]
  3525. /// btype==4 "no party" MsgStringTable[163]
  3526. /// btype==5 "no shout" MsgStringTable[164]
  3527. /// btype==6 "no PKing" MsgStringTable[165]
  3528. /// btype==7 "no alligning" MsgStringTable[383]
  3529. /// btype>=8: ignored
  3530. /// if(skill_id==AL_WARP) "not enough skill level" MsgStringTable[214]
  3531. /// if(skill_id==TF_STEAL) "steal failed" MsgStringTable[205]
  3532. /// if(skill_id==TF_POISON) "envenom failed" MsgStringTable[207]
  3533. /// otherwise "skill failed" MsgStringTable[204]
  3534. /// btype irrelevant
  3535. /// type==1 "insufficient SP" MsgStringTable[202]
  3536. /// type==2 "insufficient HP" MsgStringTable[203]
  3537. /// type==3 "insufficient materials" MsgStringTable[808]
  3538. /// type==4 "there is a delay after using a skill" MsgStringTable[219]
  3539. /// type==5 "insufficient zeny" MsgStringTable[233]
  3540. /// type==6 "wrong weapon" MsgStringTable[239]
  3541. /// type==7 "red gemstone needed" MsgStringTable[246]
  3542. /// type==8 "blue gemstone needed" MsgStringTable[247]
  3543. /// type==9 "overweight" MsgStringTable[580]
  3544. /// type==10 "skill failed" MsgStringTable[285]
  3545. /// type>=11 ignored
  3546. ///
  3547. /// if(success!=0) doesn't display any of the previous messages
  3548. /// Note: when this packet is received an unknown flag is always set to 0,
  3549. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  3550. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3551. {
  3552. int fd;
  3553. if (!sd) { //Since this is the most common nullpo....
  3554. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3555. return 0;
  3556. }
  3557. fd=sd->fd;
  3558. if (!fd) return 0;
  3559. if(battle_config.display_skill_fail&1)
  3560. return 0; //Disable all skill failed messages
  3561. if(type==0x4 && !sd->state.showdelay)
  3562. return 0; //Disable delay failed messages
  3563. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3564. return 0;
  3565. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3566. return 0;
  3567. WFIFOHEAD(fd,packet_len(0x110));
  3568. WFIFOW(fd,0) = 0x110;
  3569. WFIFOW(fd,2) = skill_id;
  3570. WFIFOL(fd,4) = btype;
  3571. WFIFOB(fd,8) = 0;// success?
  3572. WFIFOB(fd,9) = type;
  3573. WFIFOSET(fd,packet_len(0x110));
  3574. return 1;
  3575. }
  3576. /*==========================================
  3577. * skill attack effect and damage
  3578. * R 01de <skill ID>.w <src ID>.l <dst ID>.l <tick>.l <src delay>.l <dst delay>.l <damage>.l <skillv>.w <div>.w <type>.B
  3579. *------------------------------------------*/
  3580. int clif_skill_damage(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3581. {
  3582. unsigned char buf[64];
  3583. struct status_change *sc;
  3584. nullpo_retr(0, src);
  3585. nullpo_retr(0, dst);
  3586. sc = status_get_sc(dst);
  3587. if(sc && sc->count) {
  3588. if(type != 4 && dst->type == BL_PC && sc->data[SC_ENDURE] && !map_flag_gvg(dst->m))
  3589. type = 9;
  3590. if(sc->data[SC_HALLUCINATION] && damage)
  3591. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3592. }
  3593. #if PACKETVER < 3
  3594. WBUFW(buf,0)=0x114;
  3595. WBUFW(buf,2)=skill_id;
  3596. WBUFL(buf,4)=src->id;
  3597. WBUFL(buf,8)=dst->id;
  3598. WBUFL(buf,12)=tick;
  3599. WBUFL(buf,16)=sdelay;
  3600. WBUFL(buf,20)=ddelay;
  3601. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3602. WBUFW(buf,24)=damage?div:0;
  3603. } else {
  3604. WBUFW(buf,24)=damage;
  3605. }
  3606. WBUFW(buf,26)=skill_lv;
  3607. WBUFW(buf,28)=div;
  3608. WBUFB(buf,30)=type;
  3609. if (disguised(dst)) {
  3610. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  3611. WBUFL(buf,8)=-dst->id;
  3612. clif_send(buf,packet_len(0x114),dst,SELF);
  3613. } else
  3614. clif_send(buf,packet_len(0x114),dst,AREA);
  3615. if(disguised(src)) {
  3616. WBUFL(buf,4)=-src->id;
  3617. if (disguised(dst))
  3618. WBUFL(buf,8)=dst->id;
  3619. if(damage > 0)
  3620. WBUFW(buf,24)=-1;
  3621. clif_send(buf,packet_len(0x114),src,SELF);
  3622. }
  3623. #else
  3624. WBUFW(buf,0)=0x1de;
  3625. WBUFW(buf,2)=skill_id;
  3626. WBUFL(buf,4)=src->id;
  3627. WBUFL(buf,8)=dst->id;
  3628. WBUFL(buf,12)=tick;
  3629. WBUFL(buf,16)=sdelay;
  3630. WBUFL(buf,20)=ddelay;
  3631. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3632. WBUFL(buf,24)=damage?div:0;
  3633. } else {
  3634. WBUFL(buf,24)=damage;
  3635. }
  3636. WBUFW(buf,28)=skill_lv;
  3637. WBUFW(buf,30)=div;
  3638. WBUFB(buf,32)=type;
  3639. if (disguised(dst)) {
  3640. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  3641. WBUFL(buf,8)=-dst->id;
  3642. clif_send(buf,packet_len(0x1de),dst,SELF);
  3643. } else
  3644. clif_send(buf,packet_len(0x1de),dst,AREA);
  3645. if(disguised(src)) {
  3646. WBUFL(buf,4)=-src->id;
  3647. if (disguised(dst))
  3648. WBUFL(buf,8)=dst->id;
  3649. if(damage > 0)
  3650. WBUFL(buf,24)=-1;
  3651. clif_send(buf,packet_len(0x1de),src,SELF);
  3652. }
  3653. #endif
  3654. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3655. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3656. }
  3657. /*==========================================
  3658. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3659. *------------------------------------------*/
  3660. /*
  3661. int clif_skill_damage2(struct block_list *src,struct block_list *dst,unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3662. {
  3663. unsigned char buf[64];
  3664. struct status_change *sc;
  3665. nullpo_retr(0, src);
  3666. nullpo_retr(0, dst);
  3667. type = (type>0)?type:skill_get_hit(skill_id);
  3668. type = clif_calc_delay(type, ddelay);
  3669. sc = status_get_sc(dst);
  3670. if(sc && sc->count) {
  3671. if(sc->data[SC_HALLUCINATION] && damage)
  3672. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3673. }
  3674. WBUFW(buf,0)=0x115;
  3675. WBUFW(buf,2)=skill_id;
  3676. WBUFL(buf,4)=src->id;
  3677. WBUFL(buf,8)=dst->id;
  3678. WBUFL(buf,12)=tick;
  3679. WBUFL(buf,16)=sdelay;
  3680. WBUFL(buf,20)=ddelay;
  3681. WBUFW(buf,24)=dst->x;
  3682. WBUFW(buf,26)=dst->y;
  3683. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3684. WBUFW(buf,28)=damage?div:0;
  3685. } else {
  3686. WBUFW(buf,28)=damage;
  3687. }
  3688. WBUFW(buf,30)=skill_lv;
  3689. WBUFW(buf,32)=div;
  3690. WBUFB(buf,34)=type;
  3691. clif_send(buf,packet_len(0x115),src,AREA);
  3692. if(disguised(src)) {
  3693. WBUFL(buf,4)=-src->id;
  3694. if(damage > 0)
  3695. WBUFW(buf,28)=-1;
  3696. clif_send(buf,packet_len(0x115),src,SELF);
  3697. }
  3698. if (disguised(dst)) {
  3699. WBUFL(buf,8)=-dst->id;
  3700. if (disguised(src))
  3701. WBUFL(buf,4)=src->id;
  3702. else if(damage > 0)
  3703. WBUFW(buf,28)=-1;
  3704. clif_send(buf,packet_len(0x115),dst,SELF);
  3705. }
  3706. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3707. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3708. }
  3709. */
  3710. /*==========================================
  3711. * 支援/回復スキルエフェクト
  3712. *------------------------------------------*/
  3713. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_id,int heal,int fail)
  3714. {
  3715. unsigned char buf[32];
  3716. nullpo_retr(0, dst);
  3717. WBUFW(buf,0)=0x11a;
  3718. WBUFW(buf,2)=skill_id;
  3719. WBUFW(buf,4)=min(heal, SHRT_MAX);
  3720. WBUFL(buf,6)=dst->id;
  3721. WBUFL(buf,10)=src?src->id:0;
  3722. WBUFB(buf,14)=fail;
  3723. if (disguised(dst)) {
  3724. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  3725. WBUFL(buf,6)=-dst->id;
  3726. clif_send(buf,packet_len(0x11a),dst,SELF);
  3727. } else
  3728. clif_send(buf,packet_len(0x11a),dst,AREA);
  3729. if(src && disguised(src)) {
  3730. WBUFL(buf,10)=-src->id;
  3731. if (disguised(dst))
  3732. WBUFL(buf,6)=dst->id;
  3733. clif_send(buf,packet_len(0x11a),src,SELF);
  3734. }
  3735. return fail;
  3736. }
  3737. /*==========================================
  3738. * 場所スキルエフェクト
  3739. *------------------------------------------*/
  3740. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  3741. {
  3742. unsigned char buf[32];
  3743. nullpo_retr(0, src);
  3744. WBUFW(buf,0)=0x117;
  3745. WBUFW(buf,2)=skill_id;
  3746. WBUFL(buf,4)=src->id;
  3747. WBUFW(buf,8)=val;
  3748. WBUFW(buf,10)=x;
  3749. WBUFW(buf,12)=y;
  3750. WBUFL(buf,14)=tick;
  3751. if(disguised(src)) {
  3752. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  3753. WBUFL(buf,4)=-src->id;
  3754. clif_send(buf,packet_len(0x117),src,SELF);
  3755. } else
  3756. clif_send(buf,packet_len(0x117),src,AREA);
  3757. return 0;
  3758. }
  3759. /*==========================================
  3760. * 場所スキルエフェクト表示
  3761. *------------------------------------------*/
  3762. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  3763. void clif_skill_setunit(struct skill_unit *unit)
  3764. {
  3765. unsigned char buf[128];
  3766. nullpo_retv(unit);
  3767. #if PACKETVER >= 3
  3768. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3769. WBUFW(buf, 0)=0x1c9;
  3770. WBUFL(buf, 2)=unit->bl.id;
  3771. WBUFL(buf, 6)=unit->group->src_id;
  3772. WBUFW(buf,10)=unit->bl.x;
  3773. WBUFW(buf,12)=unit->bl.y;
  3774. WBUFB(buf,14)=unit->group->unit_id;
  3775. WBUFB(buf,15)=1;
  3776. WBUFB(buf,16)=1;
  3777. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  3778. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  3779. return;
  3780. }
  3781. #endif
  3782. WBUFW(buf, 0)=0x11f;
  3783. WBUFL(buf, 2)=unit->bl.id;
  3784. WBUFL(buf, 6)=unit->group->src_id;
  3785. WBUFW(buf,10)=unit->bl.x;
  3786. WBUFW(buf,12)=unit->bl.y;
  3787. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  3788. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  3789. else
  3790. WBUFB(buf,14)=unit->group->unit_id;
  3791. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  3792. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  3793. }
  3794. /*==========================================
  3795. * ワープ場所選択
  3796. *------------------------------------------*/
  3797. void clif_skill_warppoint(struct map_session_data* sd, short skill_num, short skill_lv, unsigned short map1, unsigned short map2, unsigned short map3, unsigned short map4)
  3798. {
  3799. int fd;
  3800. nullpo_retv(sd);
  3801. fd = sd->fd;
  3802. WFIFOHEAD(fd,packet_len(0x11c));
  3803. WFIFOW(fd,0) = 0x11c;
  3804. WFIFOW(fd,2) = skill_num;
  3805. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  3806. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  3807. else // normal map name
  3808. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  3809. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  3810. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  3811. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  3812. WFIFOSET(fd,packet_len(0x11c));
  3813. sd->menuskill_id = skill_num;
  3814. if (skill_num == AL_WARP)
  3815. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  3816. else
  3817. sd->menuskill_val = skill_lv;
  3818. }
  3819. /// Memo message.
  3820. /// type=0 : "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  3821. /// type=1 : "Skill Level is not high enough." in color 0x0000FF (red)
  3822. /// type=2 : "You haven't learned Warp." in color 0x0000FF (red)
  3823. ///
  3824. /// @param sd Who receives the message
  3825. /// @param type What message
  3826. void clif_skill_memomessage(struct map_session_data* sd, int type)
  3827. {
  3828. int fd;
  3829. nullpo_retv(sd);
  3830. fd=sd->fd;
  3831. WFIFOHEAD(fd,packet_len(0x11e));
  3832. WFIFOW(fd,0)=0x11e;
  3833. WFIFOB(fd,2)=type;
  3834. WFIFOSET(fd,packet_len(0x11e));
  3835. }
  3836. /// Teleport message.
  3837. /// type=0 : "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  3838. /// type=1 : "Saved point cannot be memorized." in color 0x0000FF (red)
  3839. ///
  3840. /// @param sd Who receives the message
  3841. /// @param type What message
  3842. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  3843. {
  3844. int fd;
  3845. nullpo_retv(sd);
  3846. fd=sd->fd;
  3847. WFIFOHEAD(fd,packet_len(0x189));
  3848. WFIFOW(fd,0)=0x189;
  3849. WFIFOW(fd,2)=type;
  3850. WFIFOSET(fd,packet_len(0x189));
  3851. }
  3852. /*==========================================
  3853. * モンスター情報
  3854. *------------------------------------------*/
  3855. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  3856. {
  3857. struct status_data *status;
  3858. unsigned char buf[64];
  3859. int i;//, fix;
  3860. nullpo_retr(0, sd);
  3861. nullpo_retr(0, dst);
  3862. if(dst->type!=BL_MOB )
  3863. return 0;
  3864. status = status_get_status_data(dst);
  3865. WBUFW(buf, 0)=0x18c;
  3866. WBUFW(buf, 2)=status_get_class(dst);
  3867. WBUFW(buf, 4)=status_get_lv(dst);
  3868. WBUFW(buf, 6)=status->size;
  3869. WBUFL(buf, 8)=status->hp;
  3870. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  3871. +(battle_config.estimation_type&2?status->def2:0);
  3872. WBUFW(buf,14)=status->race;
  3873. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  3874. +(battle_config.estimation_type&2?status->mdef2:0);
  3875. WBUFW(buf,18)= status->def_ele;
  3876. for(i=0;i<9;i++)
  3877. WBUFB(buf,20+i)= (unsigned char)battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv);
  3878. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  3879. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv))<0?0:fix);
  3880. clif_send(buf,packet_len(0x18c),&sd->bl,
  3881. sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  3882. return 0;
  3883. }
  3884. /*==========================================
  3885. * アイテム合成可能リスト
  3886. *------------------------------------------*/
  3887. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  3888. {
  3889. int i,c,view,fd;
  3890. nullpo_retr(0, sd);
  3891. if(sd->menuskill_id == AM_PHARMACY)
  3892. return 0; //Avoid resending the menu twice or more times...
  3893. fd=sd->fd;
  3894. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  3895. WFIFOW(fd, 0)=0x18d;
  3896. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  3897. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  3898. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  3899. WFIFOW(fd,c*8+ 4)= view;
  3900. else
  3901. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  3902. WFIFOW(fd,c*8+ 6)= 0x0012;
  3903. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  3904. c++;
  3905. }
  3906. }
  3907. WFIFOW(fd, 2)=c*8+8;
  3908. WFIFOSET(fd,WFIFOW(fd,2));
  3909. if(c > 0) {
  3910. sd->menuskill_id = AM_PHARMACY;
  3911. sd->menuskill_val = trigger;
  3912. return 1;
  3913. }
  3914. return 0;
  3915. }
  3916. /*==========================================
  3917. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  3918. *------------------------------------------*/
  3919. int clif_status_load(struct block_list *bl,int type, int flag)
  3920. {
  3921. int fd;
  3922. if (type == SI_BLANK) //It shows nothing on the client...
  3923. return 0;
  3924. if (bl->type != BL_PC)
  3925. return 0;
  3926. fd = ((struct map_session_data*)bl)->fd;
  3927. WFIFOHEAD(fd,packet_len(0x196));
  3928. WFIFOW(fd,0)=0x0196;
  3929. WFIFOW(fd,2)=type;
  3930. WFIFOL(fd,4)=bl->id;
  3931. WFIFOB(fd,8)=flag; //Status start
  3932. WFIFOSET(fd, packet_len(0x196));
  3933. return 0;
  3934. }
  3935. /*==========================================
  3936. * 状態異常アイコン/メッセージ表示
  3937. *------------------------------------------*/
  3938. int clif_status_change(struct block_list *bl,int type,int flag)
  3939. {
  3940. unsigned char buf[16];
  3941. if (type == SI_BLANK) //It shows nothing on the client...
  3942. return 0;
  3943. nullpo_retr(0, bl);
  3944. WBUFW(buf,0)=0x0196;
  3945. WBUFW(buf,2)=type;
  3946. WBUFL(buf,4)=bl->id;
  3947. WBUFB(buf,8)=flag;
  3948. clif_send(buf,packet_len(0x196),bl,AREA);
  3949. return 0;
  3950. }
  3951. /*==========================================
  3952. * Send message (modified by [Yor])
  3953. *------------------------------------------*/
  3954. int clif_displaymessage(const int fd, const char* mes)
  3955. {
  3956. // invalid pointer?
  3957. nullpo_retr(-1, mes);
  3958. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  3959. if (fd == 0)
  3960. return 0;
  3961. else {
  3962. int len_mes = strlen(mes);
  3963. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  3964. WFIFOHEAD(fd, 5 + len_mes);
  3965. WFIFOW(fd,0) = 0x8e;
  3966. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  3967. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  3968. WFIFOSET(fd, 5 + len_mes);
  3969. }
  3970. }
  3971. return 0;
  3972. }
  3973. /*==========================================
  3974. * 天の声を送信する
  3975. *------------------------------------------*/
  3976. int clif_GMmessage(struct block_list* bl, const char* mes, int len, int flag)
  3977. {
  3978. unsigned char *buf;
  3979. int lp;
  3980. lp = (flag & 0x10) ? 8 : 4;
  3981. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  3982. WBUFW(buf,0) = 0x9a;
  3983. WBUFW(buf,2) = len + lp;
  3984. WBUFL(buf,4) = 0x65756c62; //"blue":
  3985. memcpy(WBUFP(buf,lp), mes, len);
  3986. flag &= 0x07;
  3987. clif_send(buf, WBUFW(buf,2), bl,
  3988. (flag == 1) ? ALL_SAMEMAP :
  3989. (flag == 2) ? AREA :
  3990. (flag == 3) ? SELF :
  3991. ALL_CLIENT);
  3992. if(buf) aFree(buf);
  3993. if(use_irc && irc_announce_flag && !flag)
  3994. irc_announce(mes);
  3995. return 0;
  3996. }
  3997. /*==========================================
  3998. * グローバルメッセージ
  3999. *------------------------------------------*/
  4000. void clif_GlobalMessage(struct block_list* bl, const char* message)
  4001. {
  4002. char buf[100];
  4003. int len;
  4004. nullpo_retv(bl);
  4005. if(!message)
  4006. return;
  4007. len = strlen(message)+1;
  4008. WBUFW(buf,0)=0x8d;
  4009. WBUFW(buf,2)=len+8;
  4010. WBUFL(buf,4)=bl->id;
  4011. strncpy((char *) WBUFP(buf,8),message,len);
  4012. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4013. }
  4014. /*==========================================
  4015. * Send main chat message [LuzZza]
  4016. *------------------------------------------*/
  4017. void clif_MainChatMessage(const char* message)
  4018. {
  4019. char buf[200];
  4020. int len;
  4021. if(!message)
  4022. return;
  4023. len = strlen(message)+1;
  4024. if (len+8 > sizeof(buf)) {
  4025. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4026. len = sizeof(buf)-8;
  4027. }
  4028. WBUFW(buf,0)=0x8d;
  4029. WBUFW(buf,2)=len+8;
  4030. WBUFL(buf,4)=0;
  4031. strncpy((char *) WBUFP(buf,8),message,len);
  4032. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4033. }
  4034. /*==========================================
  4035. * Does an announce message in the given color.
  4036. *------------------------------------------*/
  4037. int clif_announce(struct block_list* bl, const char* mes, int len, unsigned long color, int flag)
  4038. {
  4039. unsigned char *buf;
  4040. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4041. WBUFW(buf,0) = 0x1c3;
  4042. WBUFW(buf,2) = len + 16;
  4043. WBUFL(buf,4) = color;
  4044. WBUFW(buf,8) = 0x190; //Font style? Type?
  4045. WBUFW(buf,10) = 0x0c; //12? Font size?
  4046. WBUFL(buf,12) = 0; //Unknown!
  4047. memcpy(WBUFP(buf,16), mes, len);
  4048. flag &= 0x07;
  4049. clif_send(buf, WBUFW(buf,2), bl,
  4050. (flag == 1) ? ALL_SAMEMAP :
  4051. (flag == 2) ? AREA :
  4052. (flag == 3) ? SELF :
  4053. ALL_CLIENT);
  4054. if(buf) aFree(buf);
  4055. return 0;
  4056. }
  4057. /*==========================================
  4058. * HPSP回復エフェクトを送信する
  4059. *------------------------------------------*/
  4060. int clif_heal(int fd,int type,int val)
  4061. {
  4062. WFIFOHEAD(fd,packet_len(0x13d));
  4063. WFIFOW(fd,0)=0x13d;
  4064. WFIFOW(fd,2)=type;
  4065. WFIFOW(fd,4)=cap_value(val,0,SHRT_MAX);
  4066. WFIFOSET(fd,packet_len(0x13d));
  4067. return 0;
  4068. }
  4069. /*==========================================
  4070. * 復活する
  4071. *------------------------------------------*/
  4072. int clif_resurrection(struct block_list *bl,int type)
  4073. {
  4074. unsigned char buf[16];
  4075. nullpo_retr(0, bl);
  4076. WBUFW(buf,0)=0x148;
  4077. WBUFL(buf,2)=bl->id;
  4078. WBUFW(buf,6)=type;
  4079. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4080. if (disguised(bl))
  4081. clif_spawn(bl);
  4082. return 0;
  4083. }
  4084. /// Sets the map mode.
  4085. ///
  4086. /// mode=1 : pvp mode
  4087. /// mode=2 : unknown mode (pk?)
  4088. /// mode=3 : gvg mode
  4089. /// mode=4 : message "You are in a PK area. Please beware of sudden attacks." in color 0x9B9BFF (light red)
  4090. /// mode=5 : pvp mode
  4091. /// mode=other : ?
  4092. void clif_set0199(struct map_session_data* sd, int mode)
  4093. {
  4094. int fd;
  4095. nullpo_retv(sd);
  4096. fd=sd->fd;
  4097. WFIFOHEAD(fd,packet_len(0x199));
  4098. WFIFOW(fd,0)=0x199;
  4099. WFIFOW(fd,2)=mode;
  4100. WFIFOSET(fd,packet_len(0x199));
  4101. }
  4102. #if 0
  4103. /// Set the map mode?
  4104. /// Differs from the behaviour of clif_set0199 with unknown consequences.
  4105. void clif_set01D6(struct map_session_data* sd, int mode)
  4106. {
  4107. int fd;
  4108. nullpo_retv(sd);
  4109. fd=sd->fd;
  4110. WFIFOHEAD(fd,packet_len(0x1D6));
  4111. WFIFOW(fd,0)=0x1D6;
  4112. WFIFOW(fd,2)=mode;
  4113. WFIFOSET(fd,packet_len(0x1D6));
  4114. }
  4115. #endif
  4116. /*==========================================
  4117. * PVP実装?(仮)
  4118. *------------------------------------------*/
  4119. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4120. {
  4121. if(type == 2) {
  4122. int fd = sd->fd;
  4123. WFIFOHEAD(fd,packet_len(0x19a));
  4124. WFIFOW(fd,0) = 0x19a;
  4125. WFIFOL(fd,2) = sd->bl.id;
  4126. WFIFOL(fd,6) = pvprank;
  4127. WFIFOL(fd,10) = pvpnum;
  4128. WFIFOSET(fd,packet_len(0x19a));
  4129. } else {
  4130. unsigned char buf[32];
  4131. WBUFW(buf,0) = 0x19a;
  4132. WBUFL(buf,2) = sd->bl.id;
  4133. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4134. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4135. else
  4136. WBUFL(buf,6) = pvprank;
  4137. WBUFL(buf,10) = pvpnum;
  4138. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  4139. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4140. else if(!type)
  4141. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4142. else
  4143. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4144. }
  4145. return 0;
  4146. }
  4147. /*==========================================
  4148. *
  4149. *------------------------------------------*/
  4150. int clif_send0199(int map,int type)
  4151. {
  4152. struct block_list bl;
  4153. unsigned char buf[16];
  4154. bl.id = 0;
  4155. bl.type = BL_NUL;
  4156. bl.m = map;
  4157. WBUFW(buf,0)=0x199;
  4158. WBUFW(buf,2)=type;
  4159. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4160. return 0;
  4161. }
  4162. /*==========================================
  4163. * 精錬エフェクトを送信する
  4164. *------------------------------------------*/
  4165. void clif_refine(int fd, int fail, int index, int val)
  4166. {
  4167. WFIFOHEAD(fd,packet_len(0x188));
  4168. WFIFOW(fd,0)=0x188;
  4169. WFIFOW(fd,2)=fail;
  4170. WFIFOW(fd,4)=index+2;
  4171. WFIFOW(fd,6)=val;
  4172. WFIFOSET(fd,packet_len(0x188));
  4173. }
  4174. /// result=0: "weapon upgrated: %s" MsgStringTable[911] in rgb(0,255,255)
  4175. /// result=1: "weapon upgrated: %s" MsgStringTable[912] in rgb(0,205,205)
  4176. /// result=2: "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4177. /// result=3: "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4178. void clif_upgrademessage(int fd, int result, int item_id)
  4179. {
  4180. WFIFOHEAD(fd,packet_len(0x223));
  4181. WFIFOW(fd,0)=0x223;
  4182. WFIFOL(fd,2)=result;
  4183. WFIFOW(fd,6)=item_id;
  4184. WFIFOSET(fd,packet_len(0x223));
  4185. }
  4186. /*==========================================
  4187. * Wisp/page is transmitted to the destination player
  4188. * R 0097 <len>.w <nick>.24B <message>.?B
  4189. *------------------------------------------*/
  4190. int clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4191. {
  4192. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4193. WFIFOW(fd,0) = 0x97;
  4194. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4195. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4196. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  4197. WFIFOSET(fd,WFIFOW(fd,2));
  4198. return 0;
  4199. }
  4200. /*==========================================
  4201. * Inform the player about the result of his whisper action
  4202. * R 0098 <type>.B
  4203. * 0: success to send wisper
  4204. * 1: target character is not loged in
  4205. * 2: ignored by target
  4206. * 3: everyone ignored by target
  4207. *------------------------------------------*/
  4208. int clif_wis_end(int fd, int flag)
  4209. {
  4210. WFIFOHEAD(fd,packet_len(0x98));
  4211. WFIFOW(fd,0) = 0x98;
  4212. WFIFOW(fd,2) = flag;
  4213. WFIFOSET(fd,packet_len(0x98));
  4214. return 0;
  4215. }
  4216. /*==========================================
  4217. * キャラID名前引き結果を送信する
  4218. *------------------------------------------*/
  4219. int clif_solved_charname(int fd, int charid, const char* name)
  4220. {
  4221. WFIFOHEAD(fd,packet_len(0x194));
  4222. WFIFOW(fd,0)=0x194;
  4223. WFIFOL(fd,2)=charid;
  4224. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  4225. WFIFOSET(fd,packet_len(0x194));
  4226. return 0;
  4227. }
  4228. /*==========================================
  4229. * カードの挿入可能リストを返す
  4230. *------------------------------------------*/
  4231. int clif_use_card(struct map_session_data *sd,int idx)
  4232. {
  4233. int i,c,ep;
  4234. int fd=sd->fd;
  4235. nullpo_retr(0, sd);
  4236. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4237. return 0;
  4238. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4239. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4240. ep=sd->inventory_data[idx]->equip;
  4241. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4242. WFIFOW(fd,0)=0x017b;
  4243. for(i=c=0;i<MAX_INVENTORY;i++){
  4244. int j;
  4245. if(sd->inventory_data[i] == NULL)
  4246. continue;
  4247. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4248. continue;
  4249. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4250. continue;
  4251. if(sd->status.inventory[i].identify==0 ) //Not identified
  4252. continue;
  4253. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4254. continue;
  4255. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_HAND_L) //Shield card won't go on left weapon.
  4256. continue;
  4257. for(j=0;j<sd->inventory_data[i]->slot;j++){
  4258. if( sd->status.inventory[i].card[j]==0 )
  4259. break;
  4260. }
  4261. if(j==sd->inventory_data[i]->slot) // No room
  4262. continue;
  4263. WFIFOW(fd,4+c*2)=i+2;
  4264. c++;
  4265. }
  4266. WFIFOW(fd,2)=4+c*2;
  4267. WFIFOSET(fd,WFIFOW(fd,2));
  4268. return 0;
  4269. }
  4270. /*==========================================
  4271. * カードの挿入終了
  4272. *------------------------------------------*/
  4273. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4274. {
  4275. int fd;
  4276. nullpo_retr(0, sd);
  4277. fd=sd->fd;
  4278. WFIFOHEAD(fd,packet_len(0x17d));
  4279. WFIFOW(fd,0)=0x17d;
  4280. WFIFOW(fd,2)=idx_equip+2;
  4281. WFIFOW(fd,4)=idx_card+2;
  4282. WFIFOB(fd,6)=flag;
  4283. WFIFOSET(fd,packet_len(0x17d));
  4284. return 0;
  4285. }
  4286. /*==========================================
  4287. * 鑑定可能アイテムリスト送信
  4288. *------------------------------------------*/
  4289. int clif_item_identify_list(struct map_session_data *sd)
  4290. {
  4291. int i,c;
  4292. int fd;
  4293. nullpo_retr(0, sd);
  4294. fd=sd->fd;
  4295. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4296. WFIFOW(fd,0)=0x177;
  4297. for(i=c=0;i<MAX_INVENTORY;i++){
  4298. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4299. WFIFOW(fd,c*2+4)=i+2;
  4300. c++;
  4301. }
  4302. }
  4303. if(c > 0) {
  4304. WFIFOW(fd,2)=c*2+4;
  4305. WFIFOSET(fd,WFIFOW(fd,2));
  4306. sd->menuskill_id = MC_IDENTIFY;
  4307. sd->menuskill_val = c;
  4308. }
  4309. return 0;
  4310. }
  4311. /*==========================================
  4312. * 鑑定結果
  4313. *------------------------------------------*/
  4314. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4315. {
  4316. int fd;
  4317. nullpo_retr(0, sd);
  4318. fd=sd->fd;
  4319. WFIFOHEAD(fd,packet_len(0x179));
  4320. WFIFOW(fd, 0)=0x179;
  4321. WFIFOW(fd, 2)=idx+2;
  4322. WFIFOB(fd, 4)=flag;
  4323. WFIFOSET(fd,packet_len(0x179));
  4324. return 0;
  4325. }
  4326. /*==========================================
  4327. * 修理可能アイテムリスト送信
  4328. *------------------------------------------*/
  4329. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4330. {
  4331. int i,c;
  4332. int fd;
  4333. int nameid;
  4334. nullpo_retr(0, sd);
  4335. nullpo_retr(0, dstsd);
  4336. fd=sd->fd;
  4337. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4338. WFIFOW(fd,0)=0x1fc;
  4339. for(i=c=0;i<MAX_INVENTORY;i++){
  4340. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4341. WFIFOW(fd,c*13+4) = i;
  4342. WFIFOW(fd,c*13+6) = nameid;
  4343. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4344. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4345. WFIFOB(fd,c*13+16)= c;
  4346. c++;
  4347. }
  4348. }
  4349. if(c > 0) {
  4350. WFIFOW(fd,2)=c*13+4;
  4351. WFIFOSET(fd,WFIFOW(fd,2));
  4352. sd->menuskill_id = BS_REPAIRWEAPON;
  4353. sd->menuskill_val = dstsd->bl.id;
  4354. }else
  4355. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4356. return 0;
  4357. }
  4358. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4359. {
  4360. int view,fd;
  4361. nullpo_retr(0, sd);
  4362. fd=sd->fd;
  4363. WFIFOHEAD(fd,packet_len(0x1fe));
  4364. WFIFOW(fd, 0)=0x1fe;
  4365. if((view = itemdb_viewid(nameid)) > 0)
  4366. WFIFOW(fd, 2)=view;
  4367. else
  4368. WFIFOW(fd, 2)=nameid;
  4369. WFIFOB(fd, 4)=flag;
  4370. WFIFOSET(fd,packet_len(0x1fe));
  4371. return 0;
  4372. }
  4373. /*==========================================
  4374. * Weapon Refining - Taken from jAthena
  4375. *------------------------------------------*/
  4376. int clif_item_refine_list(struct map_session_data *sd)
  4377. {
  4378. int i,c;
  4379. int fd;
  4380. int skilllv;
  4381. int wlv;
  4382. int refine_item[5];
  4383. nullpo_retr(0, sd);
  4384. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4385. fd=sd->fd;
  4386. refine_item[0] = -1;
  4387. refine_item[1] = pc_search_inventory(sd,1010);
  4388. refine_item[2] = pc_search_inventory(sd,1011);
  4389. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4390. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4391. WFIFOW(fd,0)=0x221;
  4392. for(i=c=0;i<MAX_INVENTORY;i++){
  4393. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4394. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4395. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4396. WFIFOW(fd,c*13+ 4)=i+2;
  4397. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4398. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4399. WFIFOW(fd,c*13+10)=0;
  4400. WFIFOB(fd,c*13+12)=c;
  4401. c++;
  4402. }
  4403. }
  4404. WFIFOW(fd,2)=c*13+4;
  4405. WFIFOSET(fd,WFIFOW(fd,2));
  4406. if (c > 0) {
  4407. sd->menuskill_id = WS_WEAPONREFINE;
  4408. sd->menuskill_val = skilllv;
  4409. }
  4410. return 0;
  4411. }
  4412. /*==========================================
  4413. * アイテムによる一時的なスキル効果
  4414. *------------------------------------------*/
  4415. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  4416. {
  4417. int fd;
  4418. nullpo_retr(0, sd);
  4419. fd=sd->fd;
  4420. WFIFOHEAD(fd,packet_len(0x147));
  4421. WFIFOW(fd, 0)=0x147;
  4422. WFIFOW(fd, 2)=skillid;
  4423. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4424. WFIFOW(fd, 6)=0;
  4425. WFIFOW(fd, 8)=skilllv;
  4426. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4427. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4428. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  4429. WFIFOB(fd,38)=0;
  4430. WFIFOSET(fd,packet_len(0x147));
  4431. return 0;
  4432. }
  4433. /*==========================================
  4434. * カートにアイテム追加
  4435. *------------------------------------------*/
  4436. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4437. {
  4438. int view,fd;
  4439. unsigned char *buf;
  4440. nullpo_retr(0, sd);
  4441. fd=sd->fd;
  4442. WFIFOHEAD(fd,packet_len(0x124));
  4443. buf=WFIFOP(fd,0);
  4444. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4445. return 1;
  4446. WBUFW(buf,0)=0x124;
  4447. WBUFW(buf,2)=n+2;
  4448. WBUFL(buf,4)=amount;
  4449. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4450. WBUFW(buf,8)=view;
  4451. else
  4452. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4453. WBUFB(buf,10)=sd->status.cart[n].identify;
  4454. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4455. WBUFB(buf,12)=sd->status.cart[n].refine;
  4456. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4457. WFIFOSET(fd,packet_len(0x124));
  4458. return 0;
  4459. }
  4460. /*==========================================
  4461. * カートからアイテム削除
  4462. *------------------------------------------*/
  4463. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4464. {
  4465. int fd;
  4466. nullpo_retr(0, sd);
  4467. fd=sd->fd;
  4468. WFIFOHEAD(fd,packet_len(0x125));
  4469. WFIFOW(fd,0)=0x125;
  4470. WFIFOW(fd,2)=n+2;
  4471. WFIFOL(fd,4)=amount;
  4472. WFIFOSET(fd,packet_len(0x125));
  4473. return 0;
  4474. }
  4475. /*==========================================
  4476. * Opens the shop creation menu.
  4477. * R 012d <num>.w
  4478. * 'num' is the number of allowed item slots
  4479. *------------------------------------------*/
  4480. void clif_openvendingreq(struct map_session_data* sd, int num)
  4481. {
  4482. int fd;
  4483. nullpo_retv(sd);
  4484. fd = sd->fd;
  4485. WFIFOHEAD(fd,packet_len(0x12d));
  4486. WFIFOW(fd,0) = 0x12d;
  4487. WFIFOW(fd,2) = num;
  4488. WFIFOSET(fd,packet_len(0x12d));
  4489. }
  4490. /*==========================================
  4491. * Displays a vending board to target/area
  4492. * R 0131 <ID>.l <message>.80B
  4493. *------------------------------------------*/
  4494. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  4495. {
  4496. unsigned char buf[128];
  4497. nullpo_retv(bl);
  4498. WBUFW(buf,0) = 0x131;
  4499. WBUFL(buf,2) = bl->id;
  4500. safestrncpy((char*)WBUFP(buf,6), message, 80);
  4501. if( fd ) {
  4502. WFIFOHEAD(fd,packet_len(0x131));
  4503. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  4504. WFIFOSET(fd,packet_len(0x131));
  4505. } else {
  4506. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  4507. }
  4508. }
  4509. /*==========================================
  4510. * Removes a vending board from screen
  4511. *------------------------------------------*/
  4512. void clif_closevendingboard(struct block_list* bl, int fd)
  4513. {
  4514. unsigned char buf[16];
  4515. nullpo_retv(bl);
  4516. WBUFW(buf,0) = 0x132;
  4517. WBUFL(buf,2) = bl->id;
  4518. if( fd ) {
  4519. WFIFOHEAD(fd,packet_len(0x132));
  4520. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  4521. WFIFOSET(fd,packet_len(0x132));
  4522. } else {
  4523. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  4524. }
  4525. }
  4526. /*==========================================
  4527. * Sends a list of items in a shop
  4528. * 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
  4529. *------------------------------------------*/
  4530. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  4531. {
  4532. int i,fd;
  4533. int count;
  4534. struct map_session_data* vsd;
  4535. nullpo_retv(sd);
  4536. nullpo_retv(vending);
  4537. nullpo_retv(vsd=map_id2sd(id));
  4538. fd = sd->fd;
  4539. count = vsd->vend_num;
  4540. WFIFOHEAD(fd, 8+count*22);
  4541. WFIFOW(fd,0) = 0x133;
  4542. WFIFOW(fd,2) = 8+count*22;
  4543. WFIFOL(fd,4) = id;
  4544. for( i = 0; i < count; i++ )
  4545. {
  4546. int index = vending[i].index;
  4547. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  4548. WFIFOL(fd, 8+i*22) = vending[i].value;
  4549. WFIFOW(fd,12+i*22) = vending[i].amount;
  4550. WFIFOW(fd,14+i*22) = vending[i].index + 2;
  4551. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4552. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  4553. WFIFOB(fd,19+i*22) = vsd->status.cart[index].identify;
  4554. WFIFOB(fd,20+i*22) = vsd->status.cart[index].attribute;
  4555. WFIFOB(fd,21+i*22) = vsd->status.cart[index].refine;
  4556. clif_addcards(WFIFOP(fd, 22+i*22), &vsd->status.cart[index]);
  4557. }
  4558. WFIFOSET(fd,WFIFOW(fd,2));
  4559. }
  4560. /*==========================================
  4561. * Shop purchase failure
  4562. * R 0135 <index>.w <amount>.w <fail>.B
  4563. * fail=1 - not enough zeny
  4564. * fail=2 - overweight
  4565. * fail=4 - out of stock
  4566. * fail=5 - "cannot use an npc shop while in a trade"
  4567. *------------------------------------------*/
  4568. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  4569. {
  4570. int fd;
  4571. nullpo_retv(sd);
  4572. fd = sd->fd;
  4573. WFIFOHEAD(fd,packet_len(0x135));
  4574. WFIFOW(fd,0) = 0x135;
  4575. WFIFOW(fd,2) = index+2;
  4576. WFIFOW(fd,4) = amount;
  4577. WFIFOB(fd,6) = fail;
  4578. WFIFOSET(fd,packet_len(0x135));
  4579. }
  4580. /*==========================================
  4581. * Shop creation success
  4582. * 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*
  4583. *------------------------------------------*/
  4584. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  4585. {
  4586. int i,fd;
  4587. int count;
  4588. nullpo_retv(sd);
  4589. fd = sd->fd;
  4590. count = sd->vend_num;
  4591. WFIFOHEAD(fd, 8+count*22);
  4592. WFIFOW(fd,0) = 0x136;
  4593. WFIFOW(fd,2) = 8+count*22;
  4594. WFIFOL(fd,4) = id;
  4595. for( i = 0; i < count; i++ )
  4596. {
  4597. int index = vending[i].index;
  4598. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  4599. WFIFOL(fd, 8+i*22) = vending[i].value;
  4600. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  4601. WFIFOW(fd,14+i*22) = vending[i].amount;
  4602. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4603. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  4604. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  4605. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  4606. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  4607. clif_addcards(WFIFOP(fd,22+count*22), &sd->status.cart[index]);
  4608. }
  4609. WFIFOSET(fd,WFIFOW(fd,2));
  4610. }
  4611. /*==========================================
  4612. * Inform merchant that someone has bought an item.
  4613. * R 0137 <index>.w <amount>.w
  4614. *------------------------------------------*/
  4615. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  4616. {
  4617. int fd;
  4618. nullpo_retv(sd);
  4619. fd = sd->fd;
  4620. WFIFOHEAD(fd,packet_len(0x137));
  4621. WFIFOW(fd,0) = 0x137;
  4622. WFIFOW(fd,2) = index+2;
  4623. WFIFOW(fd,4) = amount;
  4624. WFIFOSET(fd,packet_len(0x137));
  4625. }
  4626. /// Result of organizing a party.
  4627. /// S 00FA <result>.B
  4628. ///
  4629. /// result=0 : opens party window and shows MsgStringTable[77]="party successfully organized"
  4630. /// result=1 : MsgStringTable[78]="party name already exists"
  4631. /// result=2 : MsgStringTable[79]="already in a party"
  4632. /// result=other : nothing
  4633. int clif_party_created(struct map_session_data *sd,int result)
  4634. {
  4635. int fd;
  4636. nullpo_retr(0, sd);
  4637. fd=sd->fd;
  4638. WFIFOHEAD(fd,packet_len(0xfa));
  4639. WFIFOW(fd,0)=0xfa;
  4640. WFIFOB(fd,2)=result;
  4641. WFIFOSET(fd,packet_len(0xfa));
  4642. return 0;
  4643. }
  4644. int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  4645. {
  4646. unsigned char buf[96];
  4647. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  4648. int i;
  4649. for (i=0; i<MAX_PARTY && !p->data[i].sd; i++);
  4650. if (i >= MAX_PARTY) return 0; //Should never happen...
  4651. sd = p->data[i].sd;
  4652. }
  4653. WBUFW(buf, 0) = 0x1e9;
  4654. WBUFL(buf, 2) = sd->status.account_id;
  4655. WBUFL(buf, 6) = 0; //Apparently setting this to 1 makes you adoptable.
  4656. WBUFW(buf,10) = sd->bl.x;
  4657. WBUFW(buf,12) = sd->bl.y;
  4658. WBUFB(buf,14) = 0; //Unconfirmed byte, could be online/offline.
  4659. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  4660. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  4661. mapindex_getmapname_ext(mapindex_id2name(sd->mapindex), (char*)WBUFP(buf,63));
  4662. WBUFB(buf,79) = (p->party.item&1)?1:0;
  4663. WBUFB(buf,80) = (p->party.item&2)?1:0;
  4664. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  4665. return 1;
  4666. }
  4667. /*==========================================
  4668. * Sends party information
  4669. * R 00fb <len>.w <party name>.24B {<ID>.l <nick>.24B <map name>.16B <leader>.B <offline>.B}.46B*
  4670. *------------------------------------------*/
  4671. int clif_party_info(struct party_data* p, struct map_session_data *sd)
  4672. {
  4673. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  4674. struct map_session_data* party_sd = NULL;
  4675. int i, c;
  4676. nullpo_retr(0, p);
  4677. WBUFW(buf,0) = 0xfb;
  4678. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  4679. for(i = 0, c = 0; i < MAX_PARTY; i++)
  4680. {
  4681. struct party_member* m = &p->party.member[i];
  4682. if(!m->account_id) continue;
  4683. if(party_sd == NULL) party_sd = p->data[i].sd;
  4684. WBUFL(buf,28+c*46) = m->account_id;
  4685. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  4686. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  4687. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  4688. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  4689. c++;
  4690. }
  4691. WBUFW(buf,2) = 28+c*46;
  4692. if(sd) { // send only to self
  4693. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  4694. } else if (party_sd) { // send to whole party
  4695. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  4696. }
  4697. return 0;
  4698. }
  4699. /*==========================================
  4700. * パーティ勧誘
  4701. *------------------------------------------*/
  4702. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  4703. {
  4704. int fd;
  4705. struct party_data *p;
  4706. nullpo_retr(0, sd);
  4707. nullpo_retr(0, tsd);
  4708. fd=tsd->fd;
  4709. if( (p=party_search(sd->status.party_id))==NULL )
  4710. return 0;
  4711. WFIFOHEAD(fd,packet_len(0xfe));
  4712. WFIFOW(fd,0)=0xfe;
  4713. WFIFOL(fd,2)=sd->status.account_id;
  4714. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  4715. WFIFOSET(fd,packet_len(0xfe));
  4716. return 0;
  4717. }
  4718. /*==========================================
  4719. * Party invitation result. Flag values are:
  4720. * 0 -> char is already in a party
  4721. * 1 -> party invite was rejected
  4722. * 2 -> party invite was accepted
  4723. * 3 -> party is full
  4724. * 4 -> char of the same account already joined the party
  4725. *------------------------------------------*/
  4726. int clif_party_inviteack(struct map_session_data* sd, const char* nick, int flag)
  4727. {
  4728. int fd;
  4729. nullpo_retr(0, sd);
  4730. fd=sd->fd;
  4731. WFIFOHEAD(fd,packet_len(0xfd));
  4732. WFIFOW(fd,0)=0xfd;
  4733. memcpy(WFIFOP(fd,2),nick,NAME_LENGTH);
  4734. WFIFOB(fd,26)=flag;
  4735. WFIFOSET(fd,packet_len(0xfd));
  4736. return 0;
  4737. }
  4738. /*==========================================
  4739. * パーティ設定送信
  4740. * flag & 0x001=exp変更ミス
  4741. * 0x010=item変更ミス
  4742. * 0x100=一人にのみ送信
  4743. *------------------------------------------*/
  4744. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  4745. {
  4746. unsigned char buf[16];
  4747. nullpo_retr(0, p);
  4748. if(!sd && flag==0){
  4749. int i;
  4750. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4751. if (i < MAX_PARTY)
  4752. sd = p->data[i].sd;
  4753. }
  4754. if(!sd) return 0;
  4755. WBUFW(buf,0)=0x101;
  4756. // WBUFL(buf,2) // that's how the client reads it, still need to check it's uses [FlavioJS]
  4757. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  4758. WBUFW(buf,4)=0;
  4759. if(flag==0)
  4760. clif_send(buf,packet_len(0x101),&sd->bl,PARTY);
  4761. else
  4762. clif_send(buf,packet_len(0x101),&sd->bl,SELF);
  4763. return 0;
  4764. }
  4765. /*==========================================
  4766. * パーティ脱退(脱退前に呼ぶこと)
  4767. *------------------------------------------*/
  4768. int clif_party_leaved(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  4769. {
  4770. unsigned char buf[64];
  4771. int i;
  4772. nullpo_retr(0, p);
  4773. if(!sd && (flag&0xf0)==0)
  4774. {
  4775. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4776. if (i < MAX_PARTY)
  4777. sd = p->data[i].sd;
  4778. }
  4779. if(!sd) return 0;
  4780. WBUFW(buf,0)=0x105;
  4781. WBUFL(buf,2)=account_id;
  4782. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  4783. WBUFB(buf,30)=flag&0x0f;
  4784. if((flag&0xf0)==0)
  4785. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  4786. else
  4787. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  4788. return 0;
  4789. }
  4790. /*==========================================
  4791. * パーティメッセージ送信
  4792. *------------------------------------------*/
  4793. int clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  4794. {
  4795. struct map_session_data *sd;
  4796. int i;
  4797. nullpo_retr(0, p);
  4798. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  4799. if(i < MAX_PARTY){
  4800. unsigned char buf[1024];
  4801. sd = p->data[i].sd;
  4802. WBUFW(buf,0)=0x109;
  4803. WBUFW(buf,2)=len+8;
  4804. WBUFL(buf,4)=account_id;
  4805. memcpy(WBUFP(buf,8),mes,len);
  4806. clif_send(buf,len+8,&sd->bl,PARTY);
  4807. }
  4808. return 0;
  4809. }
  4810. /*==========================================
  4811. * パーティ座標通知
  4812. *------------------------------------------*/
  4813. int clif_party_xy(struct map_session_data *sd)
  4814. {
  4815. unsigned char buf[16];
  4816. nullpo_retr(0, sd);
  4817. WBUFW(buf,0)=0x107;
  4818. WBUFL(buf,2)=sd->status.account_id;
  4819. WBUFW(buf,6)=sd->bl.x;
  4820. WBUFW(buf,8)=sd->bl.y;
  4821. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  4822. return 0;
  4823. }
  4824. /*==========================================
  4825. * Sends x/y dot to a single fd. [Skotlex]
  4826. *------------------------------------------*/
  4827. int clif_party_xy_single(int fd, struct map_session_data *sd)
  4828. {
  4829. WFIFOHEAD(fd,packet_len(0x107));
  4830. WFIFOW(fd,0)=0x107;
  4831. WFIFOL(fd,2)=sd->status.account_id;
  4832. WFIFOW(fd,6)=sd->bl.x;
  4833. WFIFOW(fd,8)=sd->bl.y;
  4834. WFIFOSET(fd,packet_len(0x107));
  4835. return 0;
  4836. }
  4837. /*==========================================
  4838. * パーティHP通知
  4839. *------------------------------------------*/
  4840. int clif_party_hp(struct map_session_data *sd)
  4841. {
  4842. unsigned char buf[16];
  4843. nullpo_retr(0, sd);
  4844. WBUFW(buf,0)=0x106;
  4845. WBUFL(buf,2)=sd->status.account_id;
  4846. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  4847. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  4848. WBUFW(buf,8) = 100;
  4849. } else {
  4850. WBUFW(buf,6) = sd->battle_status.hp;
  4851. WBUFW(buf,8) = sd->battle_status.max_hp;
  4852. }
  4853. clif_send(buf,packet_len(0x106),&sd->bl,PARTY_AREA_WOS);
  4854. return 0;
  4855. }
  4856. /*==========================================
  4857. * Sends HP bar to a single fd. [Skotlex]
  4858. *------------------------------------------*/
  4859. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  4860. {
  4861. WFIFOHEAD(fd,packet_len(0x106));
  4862. WFIFOW(fd,0) = 0x106;
  4863. WFIFOL(fd,2) = id;
  4864. if( maxhp > SHRT_MAX )
  4865. {// To correctly display the %hp bar. [Skotlex]
  4866. WFIFOW(fd,6) = hp/(maxhp/100);
  4867. WFIFOW(fd,8) = 100;
  4868. } else {
  4869. WFIFOW(fd,6) = hp;
  4870. WFIFOW(fd,8) = maxhp;
  4871. }
  4872. WFIFOSET(fd, packet_len(0x106));
  4873. }
  4874. /*==========================================
  4875. * GMへ場所とHP通知
  4876. *------------------------------------------*/
  4877. int clif_hpmeter(struct map_session_data *sd)
  4878. {
  4879. struct map_session_data *sd2;
  4880. unsigned char buf[16];
  4881. int i, x0, y0, x1, y1;
  4882. int level;
  4883. nullpo_retr(0, sd);
  4884. x0 = sd->bl.x - AREA_SIZE;
  4885. y0 = sd->bl.y - AREA_SIZE;
  4886. x1 = sd->bl.x + AREA_SIZE;
  4887. y1 = sd->bl.y + AREA_SIZE;
  4888. WBUFW(buf,0) = 0x106;
  4889. WBUFL(buf,2) = sd->status.account_id;
  4890. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  4891. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  4892. WBUFW(buf,8) = 100;
  4893. } else {
  4894. WBUFW(buf,6) = sd->battle_status.hp;
  4895. WBUFW(buf,8) = sd->battle_status.max_hp;
  4896. }
  4897. for (i = 0; i < fd_max; i++) {
  4898. if (session[i] && session[i]->func_parse == clif_parse &&
  4899. (sd2 = (struct map_session_data*)session[i]->session_data) &&
  4900. sd != sd2 && sd2->state.auth) {
  4901. if (sd2->bl.m != sd->bl.m ||
  4902. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  4903. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  4904. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  4905. level < pc_isGM(sd))
  4906. continue;
  4907. WFIFOHEAD (i, packet_len(0x106));
  4908. memcpy (WFIFOP(i,0), buf, packet_len(0x106));
  4909. WFIFOSET (i, packet_len(0x106));
  4910. }
  4911. }
  4912. return 0;
  4913. }
  4914. /*==========================================
  4915. * パーティ場所移動(未使用)
  4916. *------------------------------------------*/
  4917. void clif_party_move(struct party* p, struct map_session_data* sd, int online)
  4918. {
  4919. unsigned char buf[128];
  4920. nullpo_retv(sd);
  4921. nullpo_retv(p);
  4922. WBUFW(buf, 0) = 0x104;
  4923. WBUFL(buf, 2) = sd->status.account_id;
  4924. WBUFL(buf, 6) = 0;
  4925. WBUFW(buf,10) = sd->bl.x;
  4926. WBUFW(buf,12) = sd->bl.y;
  4927. WBUFB(buf,14) = !online;
  4928. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  4929. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  4930. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  4931. clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
  4932. }
  4933. /*==========================================
  4934. * 攻撃するために移動が必要
  4935. *------------------------------------------*/
  4936. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  4937. {
  4938. int fd;
  4939. nullpo_retr(0, sd);
  4940. nullpo_retr(0, bl);
  4941. fd=sd->fd;
  4942. WFIFOHEAD(fd,packet_len(0x139));
  4943. WFIFOW(fd, 0)=0x139;
  4944. WFIFOL(fd, 2)=bl->id;
  4945. WFIFOW(fd, 6)=bl->x;
  4946. WFIFOW(fd, 8)=bl->y;
  4947. WFIFOW(fd,10)=sd->bl.x;
  4948. WFIFOW(fd,12)=sd->bl.y;
  4949. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  4950. WFIFOSET(fd,packet_len(0x139));
  4951. return 0;
  4952. }
  4953. /*==========================================
  4954. * 製造エフェクト
  4955. *------------------------------------------*/
  4956. int clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  4957. {
  4958. int view,fd;
  4959. nullpo_retr(0, sd);
  4960. fd = sd->fd;
  4961. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  4962. WFIFOHEAD(fd,packet_len(0x18f));
  4963. WFIFOW(fd, 0)=0x18f;
  4964. WFIFOW(fd, 2)=flag;
  4965. if((view = itemdb_viewid(nameid)) > 0)
  4966. WFIFOW(fd, 4)=view;
  4967. else
  4968. WFIFOW(fd, 4)=nameid;
  4969. WFIFOSET(fd,packet_len(0x18f));
  4970. return 0;
  4971. }
  4972. // pet
  4973. int clif_catch_process(struct map_session_data *sd)
  4974. {
  4975. int fd;
  4976. nullpo_retr(0, sd);
  4977. fd=sd->fd;
  4978. WFIFOHEAD(fd,packet_len(0x19e));
  4979. WFIFOW(fd,0)=0x19e;
  4980. WFIFOSET(fd,packet_len(0x19e));
  4981. return 0;
  4982. }
  4983. int clif_pet_roulette(struct map_session_data *sd,int data)
  4984. {
  4985. int fd;
  4986. nullpo_retr(0, sd);
  4987. fd=sd->fd;
  4988. WFIFOHEAD(fd,packet_len(0x1a0));
  4989. WFIFOW(fd,0)=0x1a0;
  4990. WFIFOB(fd,2)=data;
  4991. WFIFOSET(fd,packet_len(0x1a0));
  4992. return 0;
  4993. }
  4994. /*==========================================
  4995. * pet卵リスト作成
  4996. *------------------------------------------*/
  4997. int clif_sendegg(struct map_session_data *sd)
  4998. {
  4999. //R 01a6 <len>.w <index>.w*
  5000. int i,n=0,fd;
  5001. nullpo_retr(0, sd);
  5002. fd=sd->fd;
  5003. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5004. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5005. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5006. return 0;
  5007. }
  5008. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5009. WFIFOW(fd,0)=0x1a6;
  5010. if(sd->status.pet_id <= 0) {
  5011. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5012. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5013. sd->inventory_data[i]->type!=IT_PETEGG ||
  5014. sd->status.inventory[i].amount<=0)
  5015. continue;
  5016. WFIFOW(fd,n*2+4)=i+2;
  5017. n++;
  5018. }
  5019. }
  5020. WFIFOW(fd,2)=4+n*2;
  5021. WFIFOSET(fd,WFIFOW(fd,2));
  5022. sd->menuskill_id = SA_TAMINGMONSTER;
  5023. sd->menuskill_val = -1;
  5024. return 0;
  5025. }
  5026. /*==========================================
  5027. * Sends a specific pet data update.
  5028. * type = 0 -> param = 0 (initial data)
  5029. * type = 1 -> param = intimacy value
  5030. * type = 2 -> param = hungry value
  5031. * type = 3 -> param = accessory id
  5032. * type = 4 -> param = performance number (1-3:normal, 4:special)
  5033. * type = 5 -> param = hairstyle number
  5034. * If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5035. *------------------------------------------*/
  5036. int clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5037. {
  5038. uint8 buf[16];
  5039. nullpo_retr(0, pd);
  5040. WBUFW(buf,0) = 0x1a4;
  5041. WBUFB(buf,2) = type;
  5042. WBUFL(buf,3) = pd->bl.id;
  5043. WBUFL(buf,7) = param;
  5044. if (sd)
  5045. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5046. else
  5047. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5048. return 0;
  5049. }
  5050. int clif_send_petstatus(struct map_session_data *sd)
  5051. {
  5052. int fd;
  5053. struct s_pet *pet;
  5054. nullpo_retr(0, sd);
  5055. nullpo_retr(0, sd->pd);
  5056. fd=sd->fd;
  5057. pet = &sd->pd->pet;
  5058. WFIFOHEAD(fd,packet_len(0x1a2));
  5059. WFIFOW(fd,0)=0x1a2;
  5060. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5061. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5062. WFIFOW(fd,27)=pet->level;
  5063. WFIFOW(fd,29)=pet->hungry;
  5064. WFIFOW(fd,31)=pet->intimate;
  5065. WFIFOW(fd,33)=pet->equip;
  5066. WFIFOSET(fd,packet_len(0x1a2));
  5067. return 0;
  5068. }
  5069. /*==========================================
  5070. *
  5071. *------------------------------------------*/
  5072. int clif_pet_emotion(struct pet_data *pd,int param)
  5073. {
  5074. unsigned char buf[16];
  5075. nullpo_retr(0, pd);
  5076. memset(buf,0,packet_len(0x1aa));
  5077. WBUFW(buf,0)=0x1aa;
  5078. WBUFL(buf,2)=pd->bl.id;
  5079. if(param >= 100 && pd->petDB->talk_convert_class) {
  5080. if(pd->petDB->talk_convert_class < 0)
  5081. return 0;
  5082. else if(pd->petDB->talk_convert_class > 0) {
  5083. param -= (pd->pet.class_ - 100)*100;
  5084. param += (pd->petDB->talk_convert_class - 100)*100;
  5085. }
  5086. }
  5087. WBUFL(buf,6)=param;
  5088. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5089. return 0;
  5090. }
  5091. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5092. {
  5093. int fd;
  5094. nullpo_retr(0, sd);
  5095. fd=sd->fd;
  5096. WFIFOHEAD(fd,packet_len(0x1a3));
  5097. WFIFOW(fd,0)=0x1a3;
  5098. WFIFOB(fd,2)=fail;
  5099. WFIFOW(fd,3)=foodid;
  5100. WFIFOSET(fd,packet_len(0x1a3));
  5101. return 0;
  5102. }
  5103. /*==========================================
  5104. * オートスペル リスト送信
  5105. *------------------------------------------*/
  5106. int clif_autospell(struct map_session_data *sd,int skilllv)
  5107. {
  5108. int fd;
  5109. nullpo_retr(0, sd);
  5110. fd=sd->fd;
  5111. WFIFOHEAD(fd,packet_len(0x1cd));
  5112. WFIFOW(fd, 0)=0x1cd;
  5113. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5114. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5115. else
  5116. WFIFOL(fd,2)= 0x00000000;
  5117. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5118. WFIFOL(fd,6)= MG_COLDBOLT;
  5119. else
  5120. WFIFOL(fd,6)= 0x00000000;
  5121. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5122. WFIFOL(fd,10)= MG_FIREBOLT;
  5123. else
  5124. WFIFOL(fd,10)= 0x00000000;
  5125. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5126. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5127. else
  5128. WFIFOL(fd,14)= 0x00000000;
  5129. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5130. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5131. else
  5132. WFIFOL(fd,18)= 0x00000000;
  5133. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5134. WFIFOL(fd,22)= MG_FIREBALL;
  5135. else
  5136. WFIFOL(fd,22)= 0x00000000;
  5137. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5138. WFIFOL(fd,26)= MG_FROSTDIVER;
  5139. else
  5140. WFIFOL(fd,26)= 0x00000000;
  5141. WFIFOSET(fd,packet_len(0x1cd));
  5142. sd->menuskill_id = SA_AUTOSPELL;
  5143. sd->menuskill_val = skilllv;
  5144. return 0;
  5145. }
  5146. /*==========================================
  5147. * ディボーションの青い糸
  5148. *------------------------------------------*/
  5149. int clif_devotion(struct map_session_data *sd)
  5150. {
  5151. unsigned char buf[56];
  5152. int i,n;
  5153. nullpo_retr(0, sd);
  5154. WBUFW(buf,0)=0x1cf;
  5155. WBUFL(buf,2)=sd->bl.id;
  5156. for(i=0,n=0;i<5;i++) {
  5157. if (!sd->devotion[i])
  5158. continue;
  5159. WBUFL(buf,6+4*n)=sd->devotion[i];
  5160. n++;
  5161. }
  5162. for(;n<5;n++)
  5163. WBUFL(buf,6+4*n)=0;
  5164. WBUFB(buf,26)=8;
  5165. WBUFB(buf,27)=0;
  5166. clif_send(buf,packet_len(0x1cf),&sd->bl,AREA);
  5167. return 0;
  5168. }
  5169. int clif_marionette(struct block_list *src, struct block_list *target)
  5170. {
  5171. unsigned char buf[56];
  5172. int n;
  5173. WBUFW(buf,0)=0x1cf;
  5174. WBUFL(buf,2)=src->id;
  5175. for(n=0;n<5;n++)
  5176. WBUFL(buf,6+4*n)=0;
  5177. if (target) //The target goes on the second slot.
  5178. WBUFL(buf,6+4) = target->id;
  5179. WBUFB(buf,26)=8;
  5180. WBUFB(buf,27)=0;
  5181. clif_send(buf,packet_len(0x1cf),src,AREA);
  5182. return 0;
  5183. }
  5184. /*==========================================
  5185. * 氣球
  5186. *------------------------------------------*/
  5187. int clif_spiritball(struct map_session_data *sd)
  5188. {
  5189. unsigned char buf[16];
  5190. nullpo_retr(0, sd);
  5191. WBUFW(buf,0)=0x1d0;
  5192. WBUFL(buf,2)=sd->bl.id;
  5193. WBUFW(buf,6)=sd->spiritball;
  5194. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5195. return 0;
  5196. }
  5197. /*==========================================
  5198. *
  5199. *------------------------------------------*/
  5200. int clif_combo_delay(struct block_list *bl,int wait)
  5201. {
  5202. unsigned char buf[32];
  5203. nullpo_retr(0, bl);
  5204. WBUFW(buf,0)=0x1d2;
  5205. WBUFL(buf,2)=bl->id;
  5206. WBUFL(buf,6)=wait;
  5207. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5208. return 0;
  5209. }
  5210. /*==========================================
  5211. *白刃取り
  5212. *------------------------------------------*/
  5213. int clif_bladestop(struct block_list *src,struct block_list *dst,
  5214. int _bool)
  5215. {
  5216. unsigned char buf[32];
  5217. nullpo_retr(0, src);
  5218. nullpo_retr(0, dst);
  5219. WBUFW(buf,0)=0x1d1;
  5220. WBUFL(buf,2)=src->id;
  5221. WBUFL(buf,6)=dst->id;
  5222. WBUFL(buf,10)=_bool;
  5223. clif_send(buf,packet_len(0x1d1),src,AREA);
  5224. return 0;
  5225. }
  5226. /*==========================================
  5227. * MVPエフェクト
  5228. *------------------------------------------*/
  5229. int clif_mvp_effect(struct map_session_data *sd)
  5230. {
  5231. unsigned char buf[16];
  5232. nullpo_retr(0, sd);
  5233. WBUFW(buf,0)=0x10c;
  5234. WBUFL(buf,2)=sd->bl.id;
  5235. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5236. return 0;
  5237. }
  5238. /*==========================================
  5239. * MVPアイテム所得
  5240. *------------------------------------------*/
  5241. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5242. {
  5243. int view,fd;
  5244. nullpo_retr(0, sd);
  5245. fd=sd->fd;
  5246. WFIFOHEAD(fd,packet_len(0x10a));
  5247. WFIFOW(fd,0)=0x10a;
  5248. if((view = itemdb_viewid(nameid)) > 0)
  5249. WFIFOW(fd,2)=view;
  5250. else
  5251. WFIFOW(fd,2)=nameid;
  5252. WFIFOSET(fd,packet_len(0x10a));
  5253. return 0;
  5254. }
  5255. /*==========================================
  5256. * MVP経験値所得
  5257. *------------------------------------------*/
  5258. int clif_mvp_exp(struct map_session_data *sd,unsigned long exp)
  5259. {
  5260. int fd;
  5261. nullpo_retr(0, sd);
  5262. fd=sd->fd;
  5263. WFIFOHEAD(fd,packet_len(0x10b));
  5264. WFIFOW(fd,0)=0x10b;
  5265. WFIFOL(fd,2)=exp;
  5266. WFIFOSET(fd,packet_len(0x10b));
  5267. return 0;
  5268. }
  5269. /*==========================================
  5270. * ギルド作成可否通知
  5271. *------------------------------------------*/
  5272. int clif_guild_created(struct map_session_data *sd,int flag)
  5273. {
  5274. int fd;
  5275. nullpo_retr(0, sd);
  5276. fd=sd->fd;
  5277. WFIFOHEAD(fd,packet_len(0x167));
  5278. WFIFOW(fd,0)=0x167;
  5279. WFIFOB(fd,2)=flag;
  5280. WFIFOSET(fd,packet_len(0x167));
  5281. return 0;
  5282. }
  5283. /*==========================================
  5284. * ギルド所属通知
  5285. *------------------------------------------*/
  5286. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  5287. {
  5288. int ps,fd;
  5289. nullpo_retr(0, sd);
  5290. nullpo_retr(0, g);
  5291. fd=sd->fd;
  5292. ps=guild_getposition(g,sd);
  5293. WFIFOHEAD(fd,packet_len(0x16c));
  5294. memset(WFIFOP(fd,0),0,packet_len(0x16c));
  5295. WFIFOW(fd,0)=0x16c;
  5296. WFIFOL(fd,2)=g->guild_id;
  5297. WFIFOL(fd,6)=g->emblem_id;
  5298. WFIFOL(fd,10)=g->position[ps].mode;
  5299. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5300. WFIFOSET(fd,packet_len(0x16c));
  5301. return 0;
  5302. }
  5303. /*==========================================
  5304. * ギルドメンバログイン通知
  5305. *------------------------------------------*/
  5306. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5307. {
  5308. unsigned char buf[64];
  5309. nullpo_retr(0, g);
  5310. WBUFW(buf, 0)=0x16d;
  5311. WBUFL(buf, 2)=g->member[idx].account_id;
  5312. WBUFL(buf, 6)=g->member[idx].char_id;
  5313. WBUFL(buf,10)=flag;
  5314. if(g->member[idx].sd==NULL){
  5315. struct map_session_data *sd=guild_getavailablesd(g);
  5316. if(sd!=NULL)
  5317. clif_send(buf,packet_len(0x16d),&sd->bl,GUILD);
  5318. }else
  5319. clif_send(buf,packet_len(0x16d),&g->member[idx].sd->bl,GUILD_WOS);
  5320. return 0;
  5321. }
  5322. // Function `clif_guild_memberlogin_notice` sends info about
  5323. // logins and logouts of a guild member to the rest members.
  5324. // But at the 1st time (after a player login or map changing)
  5325. // the client won't show the message.
  5326. // So I suggest use this function for sending "first-time-info"
  5327. // to some player on entering the game or changing location.
  5328. // At next time the client would always show the message.
  5329. // The function sends all the statuses in the single packet
  5330. // to economize traffic. [LuzZza]
  5331. int clif_guild_send_onlineinfo(struct map_session_data *sd)
  5332. {
  5333. struct guild *g;
  5334. unsigned char buf[14*128];
  5335. int i, count=0, p_len;
  5336. nullpo_retr(0, sd);
  5337. p_len = packet_len(0x16d);
  5338. if(!(g = guild_search(sd->status.guild_id)))
  5339. return 0;
  5340. for(i=0; i<g->max_member; i++) {
  5341. if(g->member[i].account_id > 0 &&
  5342. g->member[i].account_id != sd->status.account_id) {
  5343. WBUFW(buf,count*p_len) = 0x16d;
  5344. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5345. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5346. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5347. count++;
  5348. }
  5349. }
  5350. clif_send(buf, p_len*count, &sd->bl, SELF);
  5351. return 0;
  5352. }
  5353. /*==========================================
  5354. * ギルドマスター通知(14dへの応答)
  5355. *------------------------------------------*/
  5356. int clif_guild_masterormember(struct map_session_data *sd)
  5357. {
  5358. int fd;
  5359. nullpo_retr(0, sd);
  5360. fd=sd->fd;
  5361. WFIFOHEAD(fd,packet_len(0x14e));
  5362. WFIFOW(fd,0) = 0x14e;
  5363. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  5364. WFIFOSET(fd,packet_len(0x14e));
  5365. return 0;
  5366. }
  5367. /*==========================================
  5368. * Basic Info (Territories [Valaris])
  5369. *------------------------------------------*/
  5370. int clif_guild_basicinfo(struct map_session_data *sd)
  5371. {
  5372. int fd,i,t;
  5373. struct guild *g;
  5374. struct guild_castle *gc=NULL;
  5375. nullpo_retr(0, sd);
  5376. fd=sd->fd;
  5377. g=guild_search(sd->status.guild_id);
  5378. if(g==NULL)
  5379. return 0;
  5380. WFIFOHEAD(fd,packet_len(0x1b6));
  5381. WFIFOW(fd, 0)=0x1b6;//0x150;
  5382. WFIFOL(fd, 2)=g->guild_id;
  5383. WFIFOL(fd, 6)=g->guild_lv;
  5384. WFIFOL(fd,10)=g->connect_member;
  5385. WFIFOL(fd,14)=g->max_member;
  5386. WFIFOL(fd,18)=g->average_lv;
  5387. WFIFOL(fd,22)=g->exp;
  5388. WFIFOL(fd,26)=g->next_exp;
  5389. WFIFOL(fd,30)=0; // Tax Points
  5390. WFIFOL(fd,34)=0; // Tendency: (left) Vulgar [-100,100] Famed (right)
  5391. WFIFOL(fd,38)=0; // Tendency: (down) Wicked [-100,100] Righteous (up)
  5392. WFIFOL(fd,42)=g->emblem_id;
  5393. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5394. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5395. for(i = 0, t = 0; i < MAX_GUILDCASTLE; i++)
  5396. {
  5397. gc = guild_castle_search(i);
  5398. if(gc && g->guild_id == gc->guild_id)
  5399. t++;
  5400. }
  5401. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20); // "'N' castles"
  5402. WFIFOSET(fd,packet_len(WFIFOW(fd,0)));
  5403. return 0;
  5404. }
  5405. /*==========================================
  5406. * ギルド同盟/敵対情報
  5407. *------------------------------------------*/
  5408. int clif_guild_allianceinfo(struct map_session_data *sd)
  5409. {
  5410. int fd,i,c;
  5411. struct guild *g;
  5412. nullpo_retr(0, sd);
  5413. fd=sd->fd;
  5414. g=guild_search(sd->status.guild_id);
  5415. if(g==NULL)
  5416. return 0;
  5417. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5418. WFIFOW(fd, 0)=0x14c;
  5419. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5420. struct guild_alliance *a=&g->alliance[i];
  5421. if(a->guild_id>0){
  5422. WFIFOL(fd,c*32+4)=a->opposition;
  5423. WFIFOL(fd,c*32+8)=a->guild_id;
  5424. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5425. c++;
  5426. }
  5427. }
  5428. WFIFOW(fd, 2)=c*32+4;
  5429. WFIFOSET(fd,WFIFOW(fd,2));
  5430. return 0;
  5431. }
  5432. /*==========================================
  5433. * ギルドメンバーリスト
  5434. *------------------------------------------*/
  5435. int clif_guild_memberlist(struct map_session_data *sd)
  5436. {
  5437. int fd;
  5438. int i,c;
  5439. struct guild *g;
  5440. nullpo_retr(0, sd);
  5441. fd=sd->fd;
  5442. if (!fd)
  5443. return 0;
  5444. g=guild_search(sd->status.guild_id);
  5445. if(g==NULL)
  5446. return 0;
  5447. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5448. WFIFOW(fd, 0)=0x154;
  5449. for(i=0,c=0;i<g->max_member;i++){
  5450. struct guild_member *m=&g->member[i];
  5451. if(m->account_id==0)
  5452. continue;
  5453. WFIFOL(fd,c*104+ 4)=m->account_id;
  5454. WFIFOL(fd,c*104+ 8)=m->char_id;
  5455. WFIFOW(fd,c*104+12)=m->hair;
  5456. WFIFOW(fd,c*104+14)=m->hair_color;
  5457. WFIFOW(fd,c*104+16)=m->gender;
  5458. WFIFOW(fd,c*104+18)=m->class_;
  5459. WFIFOW(fd,c*104+20)=m->lv;
  5460. WFIFOL(fd,c*104+22)=m->exp;
  5461. WFIFOL(fd,c*104+26)=m->online;
  5462. WFIFOL(fd,c*104+30)=m->position;
  5463. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5464. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5465. c++;
  5466. }
  5467. WFIFOW(fd, 2)=c*104+4;
  5468. WFIFOSET(fd,WFIFOW(fd,2));
  5469. return 0;
  5470. }
  5471. /*==========================================
  5472. * ギルド役職名リスト
  5473. *------------------------------------------*/
  5474. int clif_guild_positionnamelist(struct map_session_data *sd)
  5475. {
  5476. int i,fd;
  5477. struct guild *g;
  5478. nullpo_retr(0, sd);
  5479. fd=sd->fd;
  5480. g=guild_search(sd->status.guild_id);
  5481. if(g==NULL)
  5482. return 0;
  5483. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5484. WFIFOW(fd, 0)=0x166;
  5485. for(i=0;i<MAX_GUILDPOSITION;i++){
  5486. WFIFOL(fd,i*28+4)=i;
  5487. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5488. }
  5489. WFIFOW(fd,2)=i*28+4;
  5490. WFIFOSET(fd,WFIFOW(fd,2));
  5491. return 0;
  5492. }
  5493. /*==========================================
  5494. * ギルド役職情報リスト
  5495. *------------------------------------------*/
  5496. int clif_guild_positioninfolist(struct map_session_data *sd)
  5497. {
  5498. int i,fd;
  5499. struct guild *g;
  5500. nullpo_retr(0, sd);
  5501. fd=sd->fd;
  5502. g=guild_search(sd->status.guild_id);
  5503. if(g==NULL)
  5504. return 0;
  5505. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5506. WFIFOW(fd, 0)=0x160;
  5507. for(i=0;i<MAX_GUILDPOSITION;i++){
  5508. struct guild_position *p=&g->position[i];
  5509. WFIFOL(fd,i*16+ 4)=i;
  5510. WFIFOL(fd,i*16+ 8)=p->mode;
  5511. WFIFOL(fd,i*16+12)=i;
  5512. WFIFOL(fd,i*16+16)=p->exp_mode;
  5513. }
  5514. WFIFOW(fd, 2)=i*16+4;
  5515. WFIFOSET(fd,WFIFOW(fd,2));
  5516. return 0;
  5517. }
  5518. /*==========================================
  5519. * ギルド役職変更通知
  5520. *------------------------------------------*/
  5521. int clif_guild_positionchanged(struct guild *g,int idx)
  5522. {
  5523. struct map_session_data *sd;
  5524. unsigned char buf[128];
  5525. nullpo_retr(0, g);
  5526. WBUFW(buf, 0)=0x174;
  5527. WBUFW(buf, 2)=44;
  5528. WBUFL(buf, 4)=idx;
  5529. WBUFL(buf, 8)=g->position[idx].mode;
  5530. WBUFL(buf,12)=idx;
  5531. WBUFL(buf,16)=g->position[idx].exp_mode;
  5532. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  5533. if( (sd=guild_getavailablesd(g))!=NULL )
  5534. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5535. return 0;
  5536. }
  5537. /*==========================================
  5538. * ギルドメンバ変更通知
  5539. *------------------------------------------*/
  5540. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  5541. {
  5542. struct map_session_data *sd;
  5543. unsigned char buf[64];
  5544. nullpo_retr(0, g);
  5545. WBUFW(buf, 0)=0x156;
  5546. WBUFW(buf, 2)=16;
  5547. WBUFL(buf, 4)=g->member[idx].account_id;
  5548. WBUFL(buf, 8)=g->member[idx].char_id;
  5549. WBUFL(buf,12)=g->member[idx].position;
  5550. if( (sd=guild_getavailablesd(g))!=NULL )
  5551. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5552. return 0;
  5553. }
  5554. /*==========================================
  5555. * ギルドエンブレム送信
  5556. *------------------------------------------*/
  5557. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  5558. {
  5559. int fd;
  5560. nullpo_retr(0, sd);
  5561. nullpo_retr(0, g);
  5562. fd=sd->fd;
  5563. if(g->emblem_len<=0)
  5564. return 0;
  5565. WFIFOHEAD(fd,g->emblem_len+12);
  5566. WFIFOW(fd,0)=0x152;
  5567. WFIFOW(fd,2)=g->emblem_len+12;
  5568. WFIFOL(fd,4)=g->guild_id;
  5569. WFIFOL(fd,8)=g->emblem_id;
  5570. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  5571. WFIFOSET(fd,WFIFOW(fd,2));
  5572. return 0;
  5573. }
  5574. /*==========================================
  5575. * Send guild skills
  5576. *------------------------------------------*/
  5577. int clif_guild_skillinfo(struct map_session_data* sd)
  5578. {
  5579. int fd;
  5580. struct guild* g;
  5581. int i,c;
  5582. nullpo_retr(0, sd);
  5583. fd = sd->fd;
  5584. g = guild_search(sd->status.guild_id);
  5585. if(g == NULL)
  5586. return 0;
  5587. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  5588. WFIFOW(fd,0) = 0x0162;
  5589. WFIFOW(fd,4) = g->skill_point;
  5590. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  5591. {
  5592. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  5593. {
  5594. int id = g->skill[i].id;
  5595. int p = 6 + c*37;
  5596. WFIFOW(fd,p+0) = id;
  5597. WFIFOW(fd,p+2) = skill_get_inf(id);
  5598. WFIFOW(fd,p+4) = 0;
  5599. WFIFOW(fd,p+6) = g->skill[i].lv;
  5600. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  5601. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  5602. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  5603. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  5604. c++;
  5605. }
  5606. }
  5607. WFIFOW(fd,2) = 6 + c*37;
  5608. WFIFOSET(fd,WFIFOW(fd,2));
  5609. return 0;
  5610. }
  5611. /*==========================================
  5612. * Sends guild notice to client
  5613. * R 016f <str1z>.60B <str2z>.120B
  5614. *------------------------------------------*/
  5615. int clif_guild_notice(struct map_session_data* sd, struct guild* g)
  5616. {
  5617. int fd;
  5618. nullpo_retr(0, sd);
  5619. nullpo_retr(0, g);
  5620. fd = sd->fd;
  5621. if ( !session_isActive(fd) )
  5622. return 0;
  5623. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  5624. return 0;
  5625. WFIFOHEAD(fd,packet_len(0x16f));
  5626. WFIFOW(fd,0) = 0x16f;
  5627. memcpy(WFIFOP(fd,2), g->mes1, 60);
  5628. memcpy(WFIFOP(fd,62), g->mes2, 120);
  5629. WFIFOSET(fd,packet_len(0x16f));
  5630. return 0;
  5631. }
  5632. /*==========================================
  5633. * ギルドメンバ勧誘
  5634. *------------------------------------------*/
  5635. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  5636. {
  5637. int fd;
  5638. nullpo_retr(0, sd);
  5639. nullpo_retr(0, g);
  5640. fd=sd->fd;
  5641. WFIFOHEAD(fd,packet_len(0x16a));
  5642. WFIFOW(fd,0)=0x16a;
  5643. WFIFOL(fd,2)=g->guild_id;
  5644. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  5645. WFIFOSET(fd,packet_len(0x16a));
  5646. return 0;
  5647. }
  5648. /*==========================================
  5649. * ギルドメンバ勧誘結果
  5650. *------------------------------------------*/
  5651. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  5652. {
  5653. int fd;
  5654. nullpo_retr(0, sd);
  5655. fd=sd->fd;
  5656. WFIFOHEAD(fd,packet_len(0x169));
  5657. WFIFOW(fd,0)=0x169;
  5658. WFIFOB(fd,2)=flag;
  5659. WFIFOSET(fd,packet_len(0x169));
  5660. return 0;
  5661. }
  5662. /*==========================================
  5663. * ギルドメンバ脱退通知
  5664. *------------------------------------------*/
  5665. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  5666. {
  5667. unsigned char buf[128];
  5668. nullpo_retr(0, sd);
  5669. WBUFW(buf, 0)=0x15a;
  5670. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5671. memcpy(WBUFP(buf,26),mes,40);
  5672. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD);
  5673. return 0;
  5674. }
  5675. /*==========================================
  5676. * ギルドメンバ追放通知
  5677. *------------------------------------------*/
  5678. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,int account_id)
  5679. {
  5680. unsigned char buf[128];
  5681. nullpo_retr(0, sd);
  5682. WBUFW(buf, 0)=0x15c;
  5683. safestrncpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5684. safestrncpy(WBUFP(buf,26),mes,40);
  5685. safestrncpy(WBUFP(buf,66),"",NAME_LENGTH); // account name (not used for security reasons)
  5686. clif_send(buf,packet_len(0x15c),&sd->bl,GUILD);
  5687. return 0;
  5688. }
  5689. /*==========================================
  5690. * ギルド追放メンバリスト
  5691. *------------------------------------------*/
  5692. int clif_guild_expulsionlist(struct map_session_data *sd)
  5693. {
  5694. int fd;
  5695. int i,c;
  5696. struct guild *g;
  5697. nullpo_retr(0, sd);
  5698. fd=sd->fd;
  5699. g=guild_search(sd->status.guild_id);
  5700. if(g==NULL)
  5701. return 0;
  5702. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * 88);
  5703. WFIFOW(fd,0)=0x163;
  5704. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  5705. struct guild_expulsion *e=&g->expulsion[i];
  5706. if(e->account_id>0){
  5707. safestrncpy(WFIFOP(fd,4 + c*88),e->name,NAME_LENGTH);
  5708. safestrncpy(WFIFOP(fd,4 + c*88+24),"",24); // account name (not used for security reasons)
  5709. safestrncpy(WFIFOP(fd,4 + c*88+48),e->mes,40);
  5710. c++;
  5711. }
  5712. }
  5713. WFIFOW(fd,2) = 4 + c*88;
  5714. WFIFOSET(fd,WFIFOW(fd,2));
  5715. return 0;
  5716. }
  5717. /*==========================================
  5718. * ギルド会話
  5719. *------------------------------------------*/
  5720. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  5721. {
  5722. struct map_session_data *sd;
  5723. unsigned char *buf;
  5724. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  5725. WBUFW(buf, 0) = 0x17f;
  5726. WBUFW(buf, 2) = len + 4;
  5727. memcpy(WBUFP(buf,4), mes, len);
  5728. if ((sd = guild_getavailablesd(g)) != NULL)
  5729. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  5730. if(buf) aFree(buf);
  5731. return 0;
  5732. }
  5733. /*==========================================
  5734. * ギルドスキル割り振り通知
  5735. *------------------------------------------*/
  5736. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  5737. {
  5738. int fd;
  5739. nullpo_retr(0, sd);
  5740. fd=sd->fd;
  5741. WFIFOHEAD(fd,11);
  5742. WFIFOW(fd,0) = 0x10e;
  5743. WFIFOW(fd,2) = skill_num;
  5744. WFIFOW(fd,4) = lv;
  5745. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  5746. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  5747. WFIFOB(fd,10) = 1;
  5748. WFIFOSET(fd,11);
  5749. return 0;
  5750. }
  5751. /*==========================================
  5752. * ギルド同盟要請
  5753. *------------------------------------------*/
  5754. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  5755. {
  5756. int fd;
  5757. nullpo_retr(0, sd);
  5758. fd=sd->fd;
  5759. WFIFOHEAD(fd,packet_len(0x171));
  5760. WFIFOW(fd,0)=0x171;
  5761. WFIFOL(fd,2)=account_id;
  5762. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  5763. WFIFOSET(fd,packet_len(0x171));
  5764. return 0;
  5765. }
  5766. /*==========================================
  5767. * Reply to alliance request.
  5768. * Flag values are:
  5769. * 0: Already allied.
  5770. * 1: You rejected the offer.
  5771. * 2: You accepted the offer.
  5772. * 3: They have too any alliances
  5773. * 4: You have too many alliances.
  5774. *------------------------------------------*/
  5775. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  5776. {
  5777. int fd;
  5778. nullpo_retr(0, sd);
  5779. fd=sd->fd;
  5780. WFIFOHEAD(fd,packet_len(0x173));
  5781. WFIFOW(fd,0)=0x173;
  5782. WFIFOL(fd,2)=flag;
  5783. WFIFOSET(fd,packet_len(0x173));
  5784. return 0;
  5785. }
  5786. /*==========================================
  5787. * ギルド関係解消通知
  5788. *------------------------------------------*/
  5789. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  5790. {
  5791. int fd;
  5792. nullpo_retr(0, sd);
  5793. fd = sd->fd;
  5794. if (fd <= 0)
  5795. return 0;
  5796. WFIFOHEAD(fd,packet_len(0x184));
  5797. WFIFOW(fd,0)=0x184;
  5798. WFIFOL(fd,2)=guild_id;
  5799. WFIFOL(fd,6)=flag;
  5800. WFIFOSET(fd,packet_len(0x184));
  5801. return 0;
  5802. }
  5803. /*==========================================
  5804. * ギルド敵対結果
  5805. *------------------------------------------*/
  5806. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  5807. {
  5808. int fd;
  5809. nullpo_retr(0, sd);
  5810. fd=sd->fd;
  5811. WFIFOHEAD(fd,packet_len(0x181));
  5812. WFIFOW(fd,0)=0x181;
  5813. WFIFOB(fd,2)=flag;
  5814. WFIFOSET(fd,packet_len(0x181));
  5815. return 0;
  5816. }
  5817. /*==========================================
  5818. * ギルド関係追加
  5819. *------------------------------------------*/
  5820. /*int clif_guild_allianceadded(struct guild *g,int idx)
  5821. {
  5822. unsigned char buf[64];
  5823. WBUFW(fd,0)=0x185;
  5824. WBUFL(fd,2)=g->alliance[idx].opposition;
  5825. WBUFL(fd,6)=g->alliance[idx].guild_id;
  5826. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  5827. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  5828. return 0;
  5829. }*/
  5830. /*==========================================
  5831. * ギルド解散通知
  5832. *------------------------------------------*/
  5833. int clif_guild_broken(struct map_session_data *sd,int flag)
  5834. {
  5835. int fd;
  5836. nullpo_retr(0, sd);
  5837. fd=sd->fd;
  5838. WFIFOHEAD(fd,packet_len(0x15e));
  5839. WFIFOW(fd,0)=0x15e;
  5840. WFIFOL(fd,2)=flag;
  5841. WFIFOSET(fd,packet_len(0x15e));
  5842. return 0;
  5843. }
  5844. /*==========================================
  5845. * エモーション
  5846. *------------------------------------------*/
  5847. void clif_emotion(struct block_list *bl,int type)
  5848. {
  5849. unsigned char buf[8];
  5850. nullpo_retv(bl);
  5851. WBUFW(buf,0)=0xc0;
  5852. WBUFL(buf,2)=bl->id;
  5853. WBUFB(buf,6)=type;
  5854. clif_send(buf,packet_len(0xc0),bl,AREA);
  5855. }
  5856. /*==========================================
  5857. * トーキーボックス
  5858. *------------------------------------------*/
  5859. void clif_talkiebox(struct block_list* bl, const char* talkie)
  5860. {
  5861. unsigned char buf[86];
  5862. nullpo_retv(bl);
  5863. WBUFW(buf,0) = 0x191;
  5864. WBUFL(buf,2) = bl->id;
  5865. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  5866. clif_send(buf,packet_len(0x191),bl,AREA);
  5867. }
  5868. /*==========================================
  5869. * 結婚エフェクト
  5870. *------------------------------------------*/
  5871. void clif_wedding_effect(struct block_list *bl)
  5872. {
  5873. unsigned char buf[6];
  5874. nullpo_retv(bl);
  5875. WBUFW(buf,0) = 0x1ea;
  5876. WBUFL(buf,2) = bl->id;
  5877. clif_send(buf, packet_len(0x1ea), bl, AREA);
  5878. }
  5879. /*==========================================
  5880. * あなたに逢いたい使用時名前叫び
  5881. *------------------------------------------
  5882. void clif_callpartner(struct map_session_data *sd)
  5883. {
  5884. unsigned char buf[26];
  5885. char *p;
  5886. nullpo_retv(sd);
  5887. if(sd->status.partner_id){
  5888. WBUFW(buf,0)=0x1e6;
  5889. p = map_charid2nick(sd->status.partner_id);
  5890. if(p){
  5891. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  5892. }else{
  5893. map_reqchariddb(sd,sd->status.partner_id);
  5894. chrif_searchcharid(sd->status.partner_id);
  5895. WBUFB(buf,2) = 0;
  5896. }
  5897. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  5898. }
  5899. return;
  5900. }
  5901. */
  5902. /*==========================================
  5903. * Adopt baby [Celest]
  5904. *------------------------------------------*/
  5905. void clif_adopt_process(struct map_session_data *sd)
  5906. {
  5907. int fd;
  5908. nullpo_retv(sd);
  5909. fd=sd->fd;
  5910. WFIFOHEAD(fd,packet_len(0x1f8));
  5911. WFIFOW(fd,0)=0x1f8;
  5912. WFIFOSET(fd,packet_len(0x1f8));
  5913. }
  5914. /*==========================================
  5915. * Marry [DracoRPG]
  5916. *------------------------------------------*/
  5917. void clif_marriage_process(struct map_session_data *sd)
  5918. {
  5919. int fd;
  5920. nullpo_retv(sd);
  5921. fd=sd->fd;
  5922. WFIFOHEAD(fd,packet_len(0x1e4));
  5923. WFIFOW(fd,0)=0x1e4;
  5924. WFIFOSET(fd,packet_len(0x1e4));
  5925. }
  5926. /*==========================================
  5927. * Notice of divorce
  5928. *------------------------------------------*/
  5929. void clif_divorced(struct map_session_data* sd, const char* name)
  5930. {
  5931. int fd;
  5932. nullpo_retv(sd);
  5933. fd=sd->fd;
  5934. WFIFOHEAD(fd,packet_len(0x205));
  5935. WFIFOW(fd,0)=0x205;
  5936. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  5937. WFIFOSET(fd, packet_len(0x205));
  5938. }
  5939. /*==========================================
  5940. *
  5941. *------------------------------------------*/
  5942. void clif_parse_ReqAdopt(int fd, struct map_session_data *sd)
  5943. {
  5944. nullpo_retv(sd);
  5945. WFIFOHEAD(fd,packet_len(0x1f6));
  5946. WFIFOW(fd,0)=0x1f6;
  5947. WFIFOSET(fd, packet_len(0x1f6));
  5948. }
  5949. /*==========================================
  5950. *
  5951. *------------------------------------------*/
  5952. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd)
  5953. {
  5954. nullpo_retv(sd);
  5955. WFIFOHEAD(fd,packet_len(0x1e2));
  5956. WFIFOW(fd,0)=0x1e2;
  5957. WFIFOSET(fd, packet_len(0x1e2));
  5958. }
  5959. /*==========================================
  5960. *
  5961. *------------------------------------------*/
  5962. int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  5963. {
  5964. int fd;
  5965. nullpo_retr(0, sd);
  5966. fd = sd->fd;
  5967. if (!fd || !len) return 0; //Disconnected player.
  5968. WFIFOHEAD(fd, len+5);
  5969. WFIFOW(fd, 0) = 0x17f;
  5970. WFIFOW(fd, 2) = len + 5;
  5971. memcpy(WFIFOP(fd,4), mes, len);
  5972. WFIFOSET(fd, WFIFOW(fd,2));
  5973. return 1;
  5974. }
  5975. /*==========================================
  5976. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  5977. *------------------------------------------*/
  5978. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  5979. {
  5980. unsigned char buf[1024];
  5981. if (!len) return;
  5982. WBUFW(buf, 0) = 0x17f;
  5983. WBUFW(buf, 2) = len + 5;
  5984. memcpy(WBUFP(buf,4), mes, len);
  5985. clif_send(buf, WBUFW(buf,2), src, target);
  5986. return;
  5987. }
  5988. /*==========================================
  5989. *
  5990. *------------------------------------------*/
  5991. int clif_GM_kickack(struct map_session_data *sd, int id)
  5992. {
  5993. int fd;
  5994. nullpo_retr(0, sd);
  5995. fd = sd->fd;
  5996. WFIFOHEAD(fd,packet_len(0xcd));
  5997. WFIFOW(fd,0) = 0xcd;
  5998. WFIFOL(fd,2) = id;
  5999. WFIFOSET(fd, packet_len(0xcd));
  6000. return 0;
  6001. }
  6002. void clif_parse_QuitGame(int fd,struct map_session_data *sd);
  6003. int clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd,int type)
  6004. {
  6005. int fd = tsd->fd;
  6006. WFIFOHEAD(fd,packet_len(0x18b));
  6007. if(type)
  6008. clif_GM_kickack(sd,tsd->status.account_id);
  6009. if (!fd) {
  6010. map_quit(tsd);
  6011. return 0;
  6012. }
  6013. WFIFOW(fd,0) = 0x18b;
  6014. WFIFOW(fd,2) = 0;
  6015. WFIFOSET(fd,packet_len(0x18b));
  6016. clif_setwaitclose(fd);
  6017. return 0;
  6018. }
  6019. int clif_GM_silence(struct map_session_data *sd, struct map_session_data *tsd, int type)
  6020. {
  6021. int fd;
  6022. nullpo_retr(0, sd);
  6023. nullpo_retr(0, tsd);
  6024. fd = tsd->fd;
  6025. if (fd <= 0)
  6026. return 0;
  6027. WFIFOHEAD(fd,packet_len(0x14b));
  6028. WFIFOW(fd,0) = 0x14b;
  6029. WFIFOB(fd,2) = 0;
  6030. memcpy(WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6031. WFIFOSET(fd, packet_len(0x14b));
  6032. return 0;
  6033. }
  6034. /*==========================================
  6035. *
  6036. *------------------------------------------*/
  6037. int clif_timedout(struct map_session_data *sd)
  6038. {
  6039. nullpo_retr(0, sd);
  6040. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' timed out.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id);
  6041. clif_authfail_fd(sd->fd,3); // Even if player is not on we still send anyway
  6042. clif_setwaitclose(sd->fd); // Set session to EOF
  6043. return 0;
  6044. }
  6045. /*==========================================
  6046. * Wis拒否許可応答
  6047. *------------------------------------------*/
  6048. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6049. {
  6050. int fd;
  6051. nullpo_retr(0, sd);
  6052. fd=sd->fd;
  6053. WFIFOHEAD(fd,packet_len(0xd1));
  6054. WFIFOW(fd,0)=0xd1;
  6055. WFIFOB(fd,2)=type;
  6056. WFIFOB(fd,3)=flag;
  6057. WFIFOSET(fd,packet_len(0xd1));
  6058. return 0;
  6059. }
  6060. /*==========================================
  6061. * Wis全拒否許可応答
  6062. *------------------------------------------*/
  6063. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6064. {
  6065. int fd;
  6066. nullpo_retr(0, sd);
  6067. fd=sd->fd;
  6068. WFIFOHEAD(fd,packet_len(0xd2));
  6069. WFIFOW(fd,0)=0xd2;
  6070. WFIFOB(fd,2)=type;
  6071. WFIFOB(fd,3)=flag;
  6072. WFIFOSET(fd,packet_len(0xd2));
  6073. return 0;
  6074. }
  6075. /*==========================================
  6076. * サウンドエフェクト
  6077. *------------------------------------------*/
  6078. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6079. {
  6080. int fd;
  6081. nullpo_retv(sd);
  6082. nullpo_retv(bl);
  6083. fd = sd->fd;
  6084. WFIFOHEAD(fd,packet_len(0x1d3));
  6085. WFIFOW(fd,0) = 0x1d3;
  6086. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6087. WFIFOB(fd,26) = type;
  6088. WFIFOL(fd,27) = 0;
  6089. WFIFOL(fd,31) = bl->id;
  6090. WFIFOSET(fd,packet_len(0x1d3));
  6091. return;
  6092. }
  6093. int clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6094. {
  6095. unsigned char buf[40];
  6096. nullpo_retr(0, bl);
  6097. WBUFW(buf,0) = 0x1d3;
  6098. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6099. WBUFB(buf,26) = type;
  6100. WBUFL(buf,27) = 0;
  6101. WBUFL(buf,31) = bl->id;
  6102. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6103. return 0;
  6104. }
  6105. // displaying special effects (npcs, weather, etc) [Valaris]
  6106. int clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6107. {
  6108. unsigned char buf[24];
  6109. nullpo_retr(0, bl);
  6110. memset(buf, 0, packet_len(0x1f3));
  6111. WBUFW(buf,0) = 0x1f3;
  6112. WBUFL(buf,2) = bl->id;
  6113. WBUFL(buf,6) = type;
  6114. clif_send(buf, packet_len(0x1f3), bl, target);
  6115. if (disguised(bl)) {
  6116. WBUFL(buf,2) = -bl->id;
  6117. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6118. }
  6119. return 0;
  6120. }
  6121. // messages (from mobs/npcs) [Valaris]
  6122. int clif_message(struct block_list* bl, const char* msg)
  6123. {
  6124. unsigned short msg_len = strlen(msg) + 1;
  6125. uint8 buf[256];
  6126. nullpo_retr(0, bl);
  6127. WBUFW(buf,0) = 0x8d;
  6128. WBUFW(buf,2) = msg_len + 8;
  6129. WBUFL(buf,4) = bl->id;
  6130. memcpy(WBUFP(buf,8), msg, msg_len);
  6131. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6132. return 0;
  6133. }
  6134. // refresh the client's screen, getting rid of any effects
  6135. int clif_refresh(struct map_session_data *sd)
  6136. {
  6137. nullpo_retr(-1, sd);
  6138. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6139. clif_inventorylist(sd);
  6140. if(pc_iscarton(sd)) {
  6141. clif_cartlist(sd);
  6142. clif_updatestatus(sd,SP_CARTINFO);
  6143. }
  6144. clif_updatestatus(sd,SP_WEIGHT);
  6145. clif_updatestatus(sd,SP_MAXWEIGHT);
  6146. clif_updatestatus(sd,SP_STR);
  6147. clif_updatestatus(sd,SP_AGI);
  6148. clif_updatestatus(sd,SP_VIT);
  6149. clif_updatestatus(sd,SP_INT);
  6150. clif_updatestatus(sd,SP_DEX);
  6151. clif_updatestatus(sd,SP_LUK);
  6152. if (sd->spiritball)
  6153. clif_spiritball_single(sd->fd, sd);
  6154. if (sd->vd.cloth_color)
  6155. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6156. if(merc_is_hom_active(sd->hd))
  6157. clif_send_homdata(sd,0,0);
  6158. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6159. clif_weather_check(sd);
  6160. #ifndef TXT_ONLY
  6161. mail_clear(sd);
  6162. #endif
  6163. return 0;
  6164. }
  6165. // updates the object's (bl) name on client
  6166. int clif_charnameack (int fd, struct block_list *bl)
  6167. {
  6168. unsigned char buf[103];
  6169. int cmd = 0x95;
  6170. nullpo_retr(0, bl);
  6171. WBUFW(buf,0) = cmd;
  6172. WBUFL(buf,2) = bl->id;
  6173. switch(bl->type) {
  6174. case BL_PC:
  6175. {
  6176. struct map_session_data *ssd = (struct map_session_data *)bl;
  6177. struct party_data *p = NULL;
  6178. struct guild *g = NULL;
  6179. //Requesting your own "shadow" name. [Skotlex]
  6180. if (ssd->fd == fd && ssd->disguise)
  6181. WBUFL(buf,2) = -bl->id;
  6182. if (strlen(ssd->fakename)>1) {
  6183. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6184. break;
  6185. }
  6186. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6187. if (ssd->status.party_id > 0)
  6188. p = party_search(ssd->status.party_id);
  6189. if (ssd->status.guild_id > 0)
  6190. g = guild_search(ssd->status.guild_id);
  6191. if (p == NULL && g == NULL)
  6192. break;
  6193. WBUFW(buf, 0) = cmd = 0x195;
  6194. if (p)
  6195. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6196. else
  6197. WBUFB(buf,30) = 0;
  6198. if (g)
  6199. {
  6200. int i, ps = -1;
  6201. for(i = 0; i < g->max_member; i++) {
  6202. if (g->member[i].account_id == ssd->status.account_id &&
  6203. g->member[i].char_id == ssd->status.char_id )
  6204. {
  6205. ps = g->member[i].position;
  6206. break;
  6207. }
  6208. }
  6209. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6210. {
  6211. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6212. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6213. } else { //Assume no guild.
  6214. WBUFB(buf,54) = 0;
  6215. WBUFB(buf,78) = 0;
  6216. }
  6217. } else {
  6218. WBUFB(buf,54) = 0;
  6219. WBUFB(buf,78) = 0;
  6220. }
  6221. }
  6222. break;
  6223. //[blackhole89]
  6224. case BL_HOM:
  6225. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6226. break;
  6227. case BL_PET:
  6228. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6229. break;
  6230. case BL_NPC:
  6231. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6232. break;
  6233. case BL_MOB:
  6234. {
  6235. struct mob_data *md = (struct mob_data *)bl;
  6236. nullpo_retr(0, md);
  6237. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6238. if (md->guardian_data && md->guardian_data->guild_id) {
  6239. WBUFW(buf, 0) = cmd = 0x195;
  6240. WBUFB(buf,30) = 0;
  6241. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6242. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6243. } else if (battle_config.show_mob_info) {
  6244. char mobhp[50], *str_p = mobhp;
  6245. WBUFW(buf, 0) = cmd = 0x195;
  6246. if (battle_config.show_mob_info&4)
  6247. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6248. if (battle_config.show_mob_info&1)
  6249. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6250. if (battle_config.show_mob_info&2)
  6251. str_p += sprintf(str_p, "HP: %d%% | ",
  6252. md->status.max_hp > 10000?
  6253. md->status.hp/(md->status.max_hp/100):
  6254. 100*md->status.hp/md->status.max_hp);
  6255. //Even thought mobhp ain't a name, we send it as one so the client
  6256. //can parse it. [Skotlex]
  6257. if (str_p != mobhp) {
  6258. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6259. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6260. WBUFB(buf,54) = 0;
  6261. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6262. }
  6263. }
  6264. }
  6265. break;
  6266. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6267. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6268. // break;
  6269. return 0;
  6270. default:
  6271. ShowError("clif_parse_GetCharNameRequest : bad type %d(%d)\n", bl->type, bl->id);
  6272. return 0;
  6273. }
  6274. // if no receipient specified just update nearby clients
  6275. if (fd == 0)
  6276. clif_send(buf, packet_len(cmd), bl, AREA);
  6277. else {
  6278. WFIFOHEAD(fd, packet_len(cmd));
  6279. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  6280. WFIFOSET(fd, packet_len(cmd));
  6281. }
  6282. return 0;
  6283. }
  6284. //Used to update when a char leaves a party/guild. [Skotlex]
  6285. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6286. int clif_charnameupdate (struct map_session_data *ssd)
  6287. {
  6288. unsigned char buf[103];
  6289. int cmd = 0x195;
  6290. struct party_data *p = NULL;
  6291. struct guild *g = NULL;
  6292. nullpo_retr(0, ssd);
  6293. if (strlen(ssd->fakename)>1)
  6294. return 0; //No need to update as the party/guild was not displayed anyway.
  6295. WBUFW(buf,0) = cmd;
  6296. WBUFL(buf,2) = ssd->bl.id;
  6297. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6298. if (ssd->status.party_id > 0)
  6299. p = party_search(ssd->status.party_id);
  6300. if (ssd->status.guild_id > 0)
  6301. g = guild_search(ssd->status.guild_id);
  6302. if (p)
  6303. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6304. else
  6305. WBUFB(buf,30) = 0;
  6306. if (g)
  6307. {
  6308. int i, ps = -1;
  6309. for(i = 0; i < g->max_member; i++) {
  6310. if (g->member[i].account_id == ssd->status.account_id &&
  6311. g->member[i].char_id == ssd->status.char_id )
  6312. {
  6313. ps = g->member[i].position;
  6314. break;
  6315. }
  6316. }
  6317. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6318. {
  6319. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6320. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6321. } else { //Assume no guild.
  6322. WBUFB(buf,54) = 0;
  6323. WBUFB(buf,78) = 0;
  6324. }
  6325. } else {
  6326. WBUFB(buf,54) = 0;
  6327. WBUFB(buf,78) = 0;
  6328. }
  6329. // Update nearby clients
  6330. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  6331. return 0;
  6332. }
  6333. int clif_slide(struct block_list *bl, int x, int y){
  6334. unsigned char buf[10];
  6335. nullpo_retr(0, bl);
  6336. WBUFW(buf, 0) = 0x01ff;
  6337. WBUFL(buf, 2) = bl->id;
  6338. WBUFW(buf, 6) = x;
  6339. WBUFW(buf, 8) = y;
  6340. clif_send(buf, packet_len(0x1ff), bl, AREA);
  6341. return 0;
  6342. }
  6343. /*------------------------------------------
  6344. * @me command by lordalfa, rewritten implementation by Skotlex
  6345. *------------------------------------------*/
  6346. int clif_disp_overhead(struct map_session_data *sd, const char* mes)
  6347. {
  6348. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  6349. int len_mes = strlen(mes)+1; //Account for \0
  6350. if (len_mes + 8 >= 256) {
  6351. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6352. len_mes = 247; //Trunk it to avoid problems.
  6353. }
  6354. // send message to others
  6355. WBUFW(buf,0) = 0x8d;
  6356. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6357. WBUFL(buf,4) = sd->bl.id;
  6358. memcpy(WBUFP(buf,8), mes, len_mes);
  6359. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6360. // send back message to the speaker
  6361. WBUFW(buf,0) = 0x8e;
  6362. WBUFW(buf, 2) = len_mes + 4;
  6363. memcpy(WBUFP(buf,4), mes, len_mes);
  6364. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6365. return 0;
  6366. }
  6367. /*==========================
  6368. * Minimap fix [Kevin]
  6369. * Remove dot from minimap
  6370. *--------------------------*/
  6371. int clif_party_xy_remove(struct map_session_data *sd)
  6372. {
  6373. unsigned char buf[16];
  6374. nullpo_retr(0, sd);
  6375. WBUFW(buf,0)=0x107;
  6376. WBUFL(buf,2)=sd->status.account_id;
  6377. WBUFW(buf,6)=-1;
  6378. WBUFW(buf,8)=-1;
  6379. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6380. return 0;
  6381. }
  6382. //Displays gospel-buff information (thanks to Rayce):
  6383. //Type determines message based on this table:
  6384. /*
  6385. 0x15 End all negative status
  6386. 0x16 Immunity to all status
  6387. 0x17 MaxHP +100%
  6388. 0x18 MaxSP +100%
  6389. 0x19 All stats +20
  6390. 0x1c Enchant weapon with Holy element
  6391. 0x1d Enchant armor with Holy element
  6392. 0x1e DEF +25%
  6393. 0x1f ATK +100%
  6394. 0x20 HIT/Flee +50
  6395. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  6396. */
  6397. void clif_gospel_info(struct map_session_data *sd, int type)
  6398. {
  6399. int fd=sd->fd;
  6400. WFIFOHEAD(fd,packet_len(0x215));
  6401. WFIFOW(fd,0)=0x215;
  6402. WFIFOL(fd,2)=type;
  6403. WFIFOSET(fd, packet_len(0x215));
  6404. }
  6405. /*==========================================
  6406. * Info about Star Glaldiator save map [Komurka]
  6407. * type: 1: Information, 0: Map registered
  6408. *------------------------------------------*/
  6409. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  6410. {
  6411. int fd=sd->fd;
  6412. WFIFOHEAD(fd,packet_len(0x20e));
  6413. WFIFOW(fd,0) = 0x20e;
  6414. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), (char*)WFIFOP(fd,2));
  6415. WFIFOL(fd,26) = sd->bl.id;
  6416. WFIFOB(fd,30) = feel_level;
  6417. WFIFOB(fd,31) = type?1:0;
  6418. WFIFOSET(fd,packet_len(0x20e));
  6419. }
  6420. /*==========================================
  6421. * Info about Star Glaldiator hate mob [Komurka]
  6422. * type: 1: Register mob, 0: Information.
  6423. *------------------------------------------*/
  6424. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  6425. {
  6426. int fd=sd->fd;
  6427. WFIFOHEAD(fd,packet_len(0x20e));
  6428. WFIFOW(fd,0)=0x20e;
  6429. if (pcdb_checkid(class_))
  6430. strncpy((char*)WFIFOP(fd,2),job_name(class_), NAME_LENGTH);
  6431. else if (mobdb_checkid(class_))
  6432. strncpy((char*)WFIFOP(fd,2),mob_db(class_)->jname, NAME_LENGTH);
  6433. else //Really shouldn't happen...
  6434. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  6435. WFIFOL(fd,26)=sd->bl.id;
  6436. WFIFOB(fd,30)=hate_level;
  6437. WFIFOB(fd,31)=type?10:11; //Register/Info
  6438. WFIFOSET(fd, packet_len(0x20e));
  6439. }
  6440. /*==========================================
  6441. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6442. *------------------------------------------*/
  6443. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  6444. {
  6445. int fd=sd->fd;
  6446. WFIFOHEAD(fd,packet_len(0x20e));
  6447. WFIFOW(fd,0)=0x20e;
  6448. strncpy((char*)WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6449. WFIFOL(fd,26)=mob_id;
  6450. WFIFOB(fd,30)=progress; //Message to display
  6451. WFIFOB(fd,31)=20;
  6452. WFIFOSET(fd, packet_len(0x20e));
  6453. }
  6454. /*==========================================
  6455. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  6456. *------------------------------------------*/
  6457. void clif_feel_hate_reset(struct map_session_data *sd)
  6458. {
  6459. int fd=sd->fd;
  6460. WFIFOHEAD(fd,packet_len(0x20e));
  6461. WFIFOW(fd,0)=0x20e;
  6462. memset(WFIFOP(fd,2), 0, NAME_LENGTH); //Blank name as all was reset.
  6463. WFIFOL(fd,26)=sd->bl.id;
  6464. WFIFOB(fd,30)=0; //Feel/hate level: irrelevant
  6465. WFIFOB(fd,31)=30;
  6466. WFIFOSET(fd, packet_len(0x20e));
  6467. }
  6468. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  6469. /// Returns true if the packet was parsed successfully.
  6470. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  6471. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  6472. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  6473. {
  6474. char *text, *name, *message;
  6475. unsigned int packetlen, textlen, namelen, messagelen;
  6476. int fd = sd->fd;
  6477. *name_ = NULL;
  6478. *namelen_ = 0;
  6479. *message_ = NULL;
  6480. *messagelen_ = 0;
  6481. packetlen = RFIFOW(fd,2);
  6482. // basic structure checks
  6483. if( packetlen > RFIFOREST(fd) )
  6484. { // there has to be enough data to read
  6485. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6486. return false;
  6487. }
  6488. if( packetlen < 4 + 1 )
  6489. { // 4-byte header and at least an empty string is expected
  6490. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  6491. return false;
  6492. }
  6493. text = (char*)RFIFOP(fd,4);
  6494. textlen = packetlen - 4;
  6495. // process <name> part of the packet
  6496. if( format == 0 )
  6497. {// name and message are separated by ' : '
  6498. // validate name
  6499. name = text;
  6500. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  6501. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  6502. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  6503. {
  6504. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  6505. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  6506. clif_setwaitclose(fd); // Just kick them out to correct it.
  6507. return false;
  6508. }
  6509. message = name + namelen + 3;
  6510. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  6511. }
  6512. else
  6513. {// name has fixed width
  6514. if( textlen < NAME_LENGTH + 1 )
  6515. {
  6516. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6517. return false;
  6518. }
  6519. // validate name
  6520. name = text;
  6521. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  6522. if( name[namelen] != '\0' )
  6523. { // only restriction is that the name must be zero-terminated
  6524. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  6525. return false;
  6526. }
  6527. message = name + NAME_LENGTH;
  6528. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  6529. }
  6530. if( messagelen != strnlen(message, messagelen)+1 )
  6531. { // the declared length must match real length
  6532. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  6533. return false;
  6534. }
  6535. // verify <message> part of the packet
  6536. if( message[messagelen-1] != '\0' )
  6537. { // message must be zero-terminated
  6538. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  6539. return false;
  6540. }
  6541. if( messagelen > CHAT_SIZE_MAX )
  6542. { // messages mustn't be too long
  6543. // Normally you can only enter CHATBOX_SIZE-1 chars into the chat box, but Frost Joke / Dazzler's text can be longer.
  6544. // Neither the official client nor server place any restriction on the length of the text in the packet,
  6545. // but we'll only allow reasonably long strings here. This also makes sure all strings fit into the `chatlog` table.
  6546. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX, message);
  6547. return false;
  6548. }
  6549. *name_ = name;
  6550. *namelen_ = namelen;
  6551. *message_ = message;
  6552. *messagelen_ = messagelen;
  6553. return true;
  6554. }
  6555. // ---------------------
  6556. // clif_guess_PacketVer
  6557. // ---------------------
  6558. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  6559. // error codes:
  6560. // 0 - Success
  6561. // 1 - Unknown packet_ver
  6562. // 2 - Invalid account_id
  6563. // 3 - Invalid char_id
  6564. // 4 - Invalid login_id1 (reserved)
  6565. // 5 - Invalid client_tick (reserved)
  6566. // 6 - Invalid sex
  6567. // Only the first 'invalid' error that appears is used.
  6568. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  6569. {
  6570. static int err = 1;
  6571. static int packet_ver = -1;
  6572. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  6573. if (get_previous)
  6574. {//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]
  6575. if( error )
  6576. *error = err;
  6577. return packet_ver;
  6578. }
  6579. //By default, start searching on the default one.
  6580. err = 1;
  6581. packet_ver = clif_config.packet_db_ver;
  6582. cmd = RFIFOW(fd,0);
  6583. packet_len = RFIFOREST(fd);
  6584. #define SET_ERROR(n) \
  6585. if( err == 1 )\
  6586. err = n;\
  6587. //define SET_ERROR
  6588. #define CHECK_PACKET_VER() \
  6589. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  6590. ;/* not wanttoconnection or wrong length */\
  6591. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > max_account_id )\
  6592. { SET_ERROR(2); }/* invalid account_id */\
  6593. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 || value > max_char_id )\
  6594. { SET_ERROR(3); }/* invalid char_id */\
  6595. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  6596. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  6597. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  6598. { SET_ERROR(6); }/* invalid sex */\
  6599. else\
  6600. {\
  6601. err = 0;\
  6602. if( error )\
  6603. *error = 0;\
  6604. return packet_ver;\
  6605. }\
  6606. //define CHECK_PACKET_VER
  6607. CHECK_PACKET_VER();//Default packet version found.
  6608. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  6609. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  6610. CHECK_PACKET_VER();
  6611. }
  6612. if( error )
  6613. *error = err;
  6614. packet_ver = -1;
  6615. return -1;
  6616. #undef SET_ERROR
  6617. #undef CHECK_PACKET_VER
  6618. }
  6619. // ------------
  6620. // clif_parse_*
  6621. // ------------
  6622. // パケット読み取って色々操作
  6623. /*==========================================
  6624. *
  6625. *------------------------------------------*/
  6626. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  6627. {
  6628. int cmd, account_id, char_id, login_id1, sex;
  6629. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  6630. 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])
  6631. if (sd) {
  6632. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)?\n");
  6633. return;
  6634. }
  6635. // Only valid packet version get here
  6636. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  6637. cmd = RFIFOW(fd,0);
  6638. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  6639. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  6640. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  6641. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  6642. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  6643. if( packet_ver < 5 || // reject really old client versions
  6644. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  6645. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  6646. {// packet version rejected
  6647. 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));
  6648. WFIFOHEAD(fd,packet_len(0x6a));
  6649. WFIFOW(fd,0) = 0x6a;
  6650. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  6651. WFIFOSET(fd,packet_len(0x6a));
  6652. clif_setwaitclose(fd);
  6653. return;
  6654. } else if( map_knowsaccount(account_id) )
  6655. {// double login
  6656. ShowError("clif_parse_WantToConnection: double login attempt AID/CID: %d/%d, rejecting...\n", account_id, char_id);
  6657. WFIFOHEAD(fd,packet_len(0x6a));
  6658. WFIFOW(fd,0) = 0x6a;
  6659. WFIFOB(fd,2) = 3; // Rejected by server
  6660. WFIFOSET(fd,packet_len(0x6a));
  6661. clif_setwaitclose(fd);
  6662. return;
  6663. }
  6664. else
  6665. {// packet version accepted
  6666. struct block_list* bl;
  6667. if( (bl=map_id2bl(account_id)) != NULL && bl->type != BL_PC )
  6668. {// non-player object already has that id
  6669. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  6670. WFIFOHEAD(fd,packet_len(0x6a));
  6671. WFIFOW(fd,0) = 0x6a;
  6672. WFIFOB(fd,2) = 3; // Rejected by server
  6673. WFIFOSET(fd,packet_len(0x6a));
  6674. clif_setwaitclose(fd);
  6675. return;
  6676. }
  6677. }
  6678. CREATE(sd, TBL_PC, 1);
  6679. sd->fd = fd;
  6680. sd->packet_ver = packet_ver;
  6681. session[fd]->session_data = sd;
  6682. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  6683. #if PACKETVER < 8
  6684. WFIFOHEAD(fd,4);
  6685. WFIFOL(fd,0) = sd->bl.id;
  6686. WFIFOSET(fd,4);
  6687. #else
  6688. WFIFOHEAD(fd,packet_len(0x283));
  6689. WFIFOW(fd,0) = 0x283;
  6690. WFIFOL(fd,2) = sd->bl.id;
  6691. WFIFOSET(fd,packet_len(0x283));
  6692. #endif
  6693. chrif_authreq(sd);
  6694. return;
  6695. }
  6696. /*==========================================
  6697. * 007d クライアント側マップ読み込み完了
  6698. * map侵入時に必要なデータを全て送りつける
  6699. *------------------------------------------*/
  6700. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  6701. {
  6702. if(sd->bl.prev != NULL)
  6703. return;
  6704. if (!sd->state.auth)
  6705. { //Character loading is not complete yet!
  6706. //Let pc_reg_received reinvoke this when ready.
  6707. sd->state.connect_new = 0;
  6708. return;
  6709. }
  6710. if (sd->state.rewarp)
  6711. { //Rewarp player.
  6712. sd->state.rewarp = 0;
  6713. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  6714. return;
  6715. }
  6716. // look
  6717. #if PACKETVER < 4
  6718. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  6719. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  6720. #else
  6721. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  6722. #endif
  6723. if(sd->vd.cloth_color)
  6724. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6725. // item
  6726. pc_checkitem(sd);
  6727. clif_inventorylist(sd);
  6728. // cart
  6729. if(pc_iscarton(sd)) {
  6730. clif_cartlist(sd);
  6731. clif_updatestatus(sd,SP_CARTINFO);
  6732. }
  6733. // weight
  6734. clif_updatestatus(sd,SP_WEIGHT);
  6735. clif_updatestatus(sd,SP_MAXWEIGHT);
  6736. // guild
  6737. // (needs to go before clif_spawn() to show guild emblems correctly)
  6738. if(sd->status.guild_id)
  6739. guild_send_memberinfoshort(sd,1);
  6740. if(battle_config.pc_invincible_time > 0) {
  6741. if(map_flag_gvg(sd->bl.m))
  6742. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  6743. else
  6744. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  6745. }
  6746. if (map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs) //Skotlex
  6747. map_spawnmobs(sd->bl.m);
  6748. map_addblock(&sd->bl);
  6749. clif_spawn(&sd->bl);
  6750. // Party
  6751. // (needs to go after clif_spawn() to show hp bars correctly)
  6752. if(sd->status.party_id) {
  6753. party_send_movemap(sd);
  6754. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  6755. }
  6756. if(map[sd->bl.m].flag.pvp) {
  6757. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  6758. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  6759. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  6760. sd->pvp_rank = 0;
  6761. sd->pvp_lastusers = 0;
  6762. sd->pvp_point = 5;
  6763. sd->pvp_won = 0;
  6764. sd->pvp_lost = 0;
  6765. }
  6766. clif_set0199(sd,1);
  6767. } else
  6768. // set flag, if it's a duel [LuzZza]
  6769. if(sd->duel_group)
  6770. clif_set0199(sd,1);
  6771. if (map[sd->bl.m].flag.gvg_dungeon)
  6772. {
  6773. clif_set0199(sd,1); //TODO: Figure out the real packet to send here.
  6774. if (!sd->pvp_point)
  6775. {
  6776. sd->pvp_point = 5; //Need to die twice to be warped out.
  6777. sd->pvp_won = 0;
  6778. sd->pvp_lost = 0;
  6779. }
  6780. }
  6781. if(map_flag_gvg(sd->bl.m))
  6782. clif_set0199(sd,3);
  6783. // info about nearby objects
  6784. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  6785. map_foreachinarea(clif_getareachar, sd->bl.m, sd->bl.x-AREA_SIZE, sd->bl.y-AREA_SIZE, sd->bl.x+AREA_SIZE, sd->bl.y+AREA_SIZE, BL_ALL, sd);
  6786. //TODO: merge it with the code below
  6787. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) && sd->pd)
  6788. { //Return the pet to egg. [Skotlex]
  6789. clif_displaymessage(sd->fd, "Pets are not allowed in Guild Wars.");
  6790. pet_menu(sd, 3); //Option 3 is return to egg.
  6791. }
  6792. // pet
  6793. if(sd->pd) {
  6794. map_addblock(&sd->pd->bl);
  6795. clif_spawn(&sd->pd->bl);
  6796. clif_send_petdata(sd,sd->pd,0,0);
  6797. clif_send_petstatus(sd);
  6798. // skill_unit_move(&sd->pd->bl,gettick(),1);
  6799. }
  6800. //homunculus [blackhole89]
  6801. if(merc_is_hom_active(sd->hd)) {
  6802. map_addblock(&sd->hd->bl);
  6803. clif_spawn(&sd->hd->bl);
  6804. clif_send_homdata(sd,0,0);
  6805. clif_hominfo(sd,sd->hd,1);
  6806. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  6807. clif_homskillinfoblock(sd);
  6808. if (battle_config.hom_setting&0x8)
  6809. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  6810. if (!(battle_config.hom_setting&0x2))
  6811. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  6812. }
  6813. if(sd->state.connect_new) {
  6814. int lv;
  6815. sd->state.connect_new = 0;
  6816. clif_skillinfoblock(sd);
  6817. clif_hotkeys_send(sd);
  6818. clif_updatestatus(sd,SP_NEXTBASEEXP);
  6819. clif_updatestatus(sd,SP_NEXTJOBEXP);
  6820. clif_updatestatus(sd,SP_SKILLPOINT);
  6821. clif_initialstatus(sd);
  6822. if (sd->sc.option&OPTION_FALCON)
  6823. clif_status_load(&sd->bl, SI_FALCON, 1);
  6824. if (sd->sc.option&OPTION_RIDING)
  6825. clif_status_load(&sd->bl, SI_RIDING, 1);
  6826. if(sd->status.manner < 0)
  6827. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  6828. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  6829. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  6830. if(sd->bl.m == sd->feel_map[0].m
  6831. || sd->bl.m == sd->feel_map[1].m
  6832. || sd->bl.m == sd->feel_map[2].m)
  6833. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  6834. }
  6835. if(sd->pd && sd->pd->pet.intimate > 900)
  6836. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  6837. if(merc_is_hom_active(sd->hd))
  6838. merc_hom_init_timers(sd->hd);
  6839. if (night_flag && map[sd->bl.m].flag.nightenabled)
  6840. {
  6841. sd->state.night = 1;
  6842. clif_status_load(&sd->bl, SI_NIGHT, 1);
  6843. }
  6844. // Notify everyone that this char logged in [Skotlex].
  6845. clif_foreachclient(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  6846. //Login Event
  6847. npc_script_event(sd, NPCE_LOGIN);
  6848. } else {
  6849. //For some reason the client "loses" these on map-change.
  6850. clif_updatestatus(sd,SP_STR);
  6851. clif_updatestatus(sd,SP_AGI);
  6852. clif_updatestatus(sd,SP_VIT);
  6853. clif_updatestatus(sd,SP_INT);
  6854. clif_updatestatus(sd,SP_DEX);
  6855. clif_updatestatus(sd,SP_LUK);
  6856. sd->state.using_fake_npc = 0;
  6857. //New 'night' effect by dynamix [Skotlex]
  6858. if (night_flag && map[sd->bl.m].flag.nightenabled)
  6859. { //Display night.
  6860. if (!sd->state.night) {
  6861. sd->state.night = 1;
  6862. clif_status_load(&sd->bl, SI_NIGHT, 1);
  6863. }
  6864. } else if (sd->state.night) { //Clear night display.
  6865. sd->state.night = 0;
  6866. clif_status_load(&sd->bl, SI_NIGHT, 0);
  6867. }
  6868. if(sd->npc_id)
  6869. npc_event_dequeue(sd);
  6870. #ifndef TXT_ONLY
  6871. mail_clear(sd);
  6872. #endif
  6873. }
  6874. if(map[sd->bl.m].flag.loadevent) // Lance
  6875. npc_script_event(sd, NPCE_LOADMAP);
  6876. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  6877. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  6878. if (sd->sc.opt2) //Client loses these on warp.
  6879. clif_changeoption(&sd->bl);
  6880. clif_weather_check(sd);
  6881. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  6882. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  6883. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  6884. else
  6885. sd->areanpc_id = 0;
  6886. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  6887. if(pc_isdead(sd))
  6888. clif_clearunit_area(&sd->bl, 1);
  6889. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  6890. // else
  6891. // clif_changed_dir(&sd->bl, SELF);
  6892. // Trigger skill effects if you appear standing on them
  6893. if(!battle_config.pc_invincible_time)
  6894. skill_unit_move(&sd->bl,gettick(),1);
  6895. }
  6896. /*==========================================
  6897. *
  6898. *------------------------------------------*/
  6899. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  6900. {
  6901. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  6902. WFIFOHEAD(fd, packet_len(0x7f));
  6903. WFIFOW(fd,0)=0x7f;
  6904. WFIFOL(fd,2)=gettick();
  6905. WFIFOSET(fd,packet_len(0x7f));
  6906. // removed until the socket problems are fixed. [FlavioJS]
  6907. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  6908. return;
  6909. }
  6910. void clif_hotkeys_send(struct map_session_data *sd) {
  6911. #ifdef HOTKEY_SAVING
  6912. const int fd = sd->fd;
  6913. int i;
  6914. if (!fd) return;
  6915. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  6916. WFIFOW(fd, 0) = 0x02b9;
  6917. for(i = 0; i < MAX_HOTKEYS; i++) {
  6918. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  6919. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  6920. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  6921. }
  6922. WFIFOSET(fd, packet_len(0x02b9));
  6923. #endif
  6924. }
  6925. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  6926. #ifdef HOTKEY_SAVING
  6927. unsigned short idx;
  6928. int cmd;
  6929. cmd = RFIFOW(fd, 0);
  6930. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  6931. if (idx >= MAX_HOTKEYS) return;
  6932. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  6933. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  6934. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  6935. return;
  6936. #endif
  6937. }
  6938. /*==========================================
  6939. *
  6940. *------------------------------------------*/
  6941. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  6942. {
  6943. short x, y;
  6944. int cmd;
  6945. if (pc_isdead(sd)) {
  6946. clif_clearunit_area(&sd->bl, 1);
  6947. return;
  6948. }
  6949. if (sd->sc.opt1 && sd->sc.opt1 == OPT1_STONEWAIT)
  6950. ; //You CAN walk on this OPT1 value.
  6951. else if (pc_cant_act(sd))
  6952. return;
  6953. if(sd->sc.data[SC_RUN])
  6954. return;
  6955. pc_delinvincibletimer(sd);
  6956. cmd = RFIFOW(fd,0);
  6957. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  6958. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  6959. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  6960. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  6961. //Set last idle time... [Skotlex]
  6962. sd->idletime = last_tick;
  6963. unit_walktoxy(&sd->bl, x, y, 4);
  6964. }
  6965. /*==========================================
  6966. *
  6967. *------------------------------------------*/
  6968. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  6969. {
  6970. WFIFOHEAD(fd,packet_len(0x18b));
  6971. WFIFOW(fd,0) = 0x18b;
  6972. /* Rovert's prevent logout option fixed [Valaris] */
  6973. if (!sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] &&
  6974. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  6975. ) {
  6976. clif_setwaitclose(fd);
  6977. WFIFOW(fd,2)=0;
  6978. } else {
  6979. WFIFOW(fd,2)=1;
  6980. }
  6981. WFIFOSET(fd,packet_len(0x18b));
  6982. }
  6983. /*==========================================
  6984. *
  6985. *------------------------------------------*/
  6986. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  6987. {
  6988. int account_id;
  6989. struct block_list* bl;
  6990. struct status_change *sc;
  6991. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  6992. if(account_id<0 && -account_id == sd->bl.id) // for disguises [Valaris]
  6993. account_id= sd->bl.id;
  6994. bl = map_id2bl(account_id);
  6995. //Is this possible? Lagged clients could request names of already gone mobs/players. [Skotlex]
  6996. if (!bl) return;
  6997. sc = status_get_sc(bl);
  6998. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  6999. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  7000. pc_isGM(sd) < battle_config.hack_info_GM_level
  7001. ) {
  7002. //GM characters (with client side GM enabled are able to see invisible stuff) [Lance]
  7003. //Asked name of invisible player, this shouldn't be possible!
  7004. //Possible bot? Thanks to veider and qspirit
  7005. //FIXME: Still isn't perfected as clients keep asking for this on legitimate situations.
  7006. char gm_msg[256];
  7007. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requested the name of an invisible target.", sd->status.name, sd->status.account_id);
  7008. ShowWarning(gm_msg);
  7009. // information is sended to all online GM
  7010. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7011. return;
  7012. }
  7013. clif_charnameack(fd, bl);
  7014. }
  7015. /*==========================================
  7016. * Validates and processes global messages
  7017. * S 008c/00f3 <packet len>.w <text>.?B (<name> : <message>) 00
  7018. *------------------------------------------*/
  7019. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  7020. {
  7021. const char* text = (char*)RFIFOP(fd,4);
  7022. int textlen = RFIFOW(fd,2) - 4;
  7023. char *name, *message;
  7024. int namelen, messagelen;
  7025. // validate packet and retrieve name and message
  7026. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  7027. return;
  7028. if( is_atcommand(fd, sd, message) || is_charcommand(fd, sd, message) )
  7029. return;
  7030. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  7031. return;
  7032. if( battle_config.min_chat_delay )
  7033. { //[Skotlex]
  7034. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7035. return;
  7036. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7037. }
  7038. // send message to others (using the send buffer for temp. storage)
  7039. WFIFOHEAD(fd, 8 + textlen);
  7040. WFIFOW(fd,0) = 0x8d;
  7041. WFIFOW(fd,2) = 8 + textlen;
  7042. WFIFOL(fd,4) = sd->bl.id;
  7043. safestrncpy((char*)WFIFOP(fd,8), text, textlen);
  7044. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7045. // send back message to the speaker
  7046. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7047. WFIFOW(fd,0) = 0x8e;
  7048. WFIFOSET(fd, WFIFOW(fd,2));
  7049. #ifdef PCRE_SUPPORT
  7050. // trigger listening mobs/npcs
  7051. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  7052. map_foreachinrange(mob_chat_sub, &sd->bl, AREA_SIZE, BL_MOB, text, textlen, &sd->bl);
  7053. #endif
  7054. // check for special supernovice phrase
  7055. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE )
  7056. {
  7057. int next = pc_nextbaseexp(sd);
  7058. if( next > 0 && (sd->status.base_exp * 1000 / next)% 100 == 0 ) { // 0%, 10%, 20%, ...
  7059. switch (sd->state.snovice_call_flag) {
  7060. case 0:
  7061. if( strstr(message, msg_txt(504)) ) // "Guardian Angel, can you hear my voice? ^^;"
  7062. sd->state.snovice_call_flag++;
  7063. break;
  7064. case 1: {
  7065. char buf[256];
  7066. sprintf(buf, msg_txt(505), sd->status.name);
  7067. if( strstr(message, buf) ) // "My name is %s, and I'm a Super Novice~"
  7068. sd->state.snovice_call_flag++;
  7069. }
  7070. break;
  7071. case 2:
  7072. if( strstr(message, msg_txt(506)) ) // "Please help me~ T.T"
  7073. sd->state.snovice_call_flag++;
  7074. break;
  7075. case 3:
  7076. if( skillnotok(MO_EXPLOSIONSPIRITS,sd) )
  7077. break; //Do not override the noskill mapflag. [Skotlex]
  7078. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7079. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  7080. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7081. sd->state.snovice_call_flag = 0;
  7082. break;
  7083. }
  7084. }
  7085. }
  7086. // Chat logging type 'O' / Global Chat
  7087. if( log_config.chat&1 || (log_config.chat&2 && !(agit_flag && log_config.chat&64)) )
  7088. log_chat("O", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7089. return;
  7090. }
  7091. /*==========================================
  7092. * /mm /mapmove (as @rura GM command)
  7093. *------------------------------------------*/
  7094. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  7095. {
  7096. char output[MAP_NAME_LENGTH_EXT+15]; // Max length of a short: ' -6XXXX' -> 7 digits
  7097. char message[MAP_NAME_LENGTH_EXT+15+5]; // "/mm "+output
  7098. char* map_name;
  7099. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7100. return;
  7101. if(pc_isGM(sd) < get_atcommand_level(atcommand_mapmove))
  7102. return;
  7103. map_name = (char*)RFIFOP(fd,2);
  7104. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  7105. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7106. atcommand_mapmove(fd, sd, "@mapmove", output);
  7107. if( log_config.gm && get_atcommand_level(atcommand_mapmove) >= log_config.gm )
  7108. {
  7109. sprintf(message, "/mm %s", output);
  7110. log_atcommand(sd, message);
  7111. }
  7112. return;
  7113. }
  7114. /*==========================================
  7115. *
  7116. *------------------------------------------*/
  7117. void clif_changed_dir(struct block_list *bl, int type)
  7118. {
  7119. unsigned char buf[64];
  7120. WBUFW(buf,0) = 0x9c;
  7121. WBUFL(buf,2) = bl->id;
  7122. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7123. WBUFB(buf,8) = unit_getdir(bl);
  7124. clif_send(buf, packet_len(0x9c), bl, type);
  7125. if (disguised(bl)) {
  7126. WBUFL(buf,2) = -bl->id;
  7127. WBUFW(buf,6) = 0;
  7128. clif_send(buf, packet_len(0x9c), bl, SELF);
  7129. }
  7130. return;
  7131. }
  7132. /*==========================================
  7133. *
  7134. *------------------------------------------*/
  7135. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  7136. {
  7137. unsigned char headdir, dir;
  7138. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7139. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7140. pc_setdir(sd, dir, headdir);
  7141. clif_changed_dir(&sd->bl, AREA_WOS);
  7142. return;
  7143. }
  7144. /*==========================================
  7145. *
  7146. *------------------------------------------*/
  7147. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  7148. {
  7149. unsigned char buf[64];
  7150. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7151. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7152. clif_skill_fail(sd, 1, 0, 1);
  7153. return;
  7154. }
  7155. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7156. if (sd->emotionlasttime >= time(NULL)) {
  7157. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7158. clif_skill_fail(sd, 1, 0, 1);
  7159. return;
  7160. }
  7161. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7162. WBUFW(buf,0) = 0xc0;
  7163. WBUFL(buf,2) = sd->bl.id;
  7164. WBUFB(buf,6) = RFIFOB(fd,2);
  7165. clif_send(buf, packet_len(0xc0), &sd->bl, AREA);
  7166. } else
  7167. clif_skill_fail(sd, 1, 0, 1);
  7168. }
  7169. /*==========================================
  7170. *
  7171. *------------------------------------------*/
  7172. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  7173. {
  7174. WFIFOHEAD(fd,packet_len(0xc2));
  7175. WFIFOW(fd,0) = 0xc2;
  7176. WFIFOL(fd,2) = map_getusers();
  7177. WFIFOSET(fd,packet_len(0xc2));
  7178. }
  7179. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7180. {
  7181. if (pc_isdead(sd)) {
  7182. clif_clearunit_area(&sd->bl, 1);
  7183. return;
  7184. }
  7185. if (sd->sc.count &&
  7186. (sd->sc.data[SC_TRICKDEAD] ||
  7187. sd->sc.data[SC_AUTOCOUNTER] ||
  7188. sd->sc.data[SC_BLADESTOP]))
  7189. return;
  7190. pc_stop_walking(sd, 1);
  7191. pc_stop_attack(sd);
  7192. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7193. target_id = sd->bl.id;
  7194. switch(action_type)
  7195. {
  7196. case 0x00: // once attack
  7197. case 0x07: // continuous attack
  7198. if (pc_cant_act(sd) || sd->sc.option&OPTION_HIDE)
  7199. return;
  7200. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  7201. return;
  7202. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7203. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7204. clif_skill_fail(sd, 1, 4, 0);
  7205. return;
  7206. }
  7207. }
  7208. pc_delinvincibletimer(sd);
  7209. sd->idletime = last_tick;
  7210. unit_attack(&sd->bl, target_id, action_type != 0);
  7211. break;
  7212. case 0x02: // sitdown
  7213. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7214. clif_skill_fail(sd, 1, 0, 2);
  7215. break;
  7216. }
  7217. if(pc_issit(sd)) {
  7218. //Bugged client? Just refresh them.
  7219. clif_sitting(&sd->bl);
  7220. return;
  7221. }
  7222. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7223. break;
  7224. if (sd->sc.count && (
  7225. sd->sc.data[SC_DANCING] ||
  7226. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  7227. )) //No sitting during these states either.
  7228. break;
  7229. pc_setsit(sd);
  7230. skill_sit(sd,1);
  7231. clif_sitting(&sd->bl);
  7232. break;
  7233. case 0x03: // standup
  7234. if (!pc_issit(sd)) {
  7235. //Bugged client? Just refresh them.
  7236. clif_standing(&sd->bl);
  7237. return;
  7238. }
  7239. pc_setstand(sd);
  7240. skill_sit(sd,0);
  7241. clif_standing(&sd->bl);
  7242. break;
  7243. }
  7244. }
  7245. /*==========================================
  7246. *
  7247. *------------------------------------------*/
  7248. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  7249. {
  7250. clif_parse_ActionRequest_sub(sd,
  7251. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7252. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7253. gettick()
  7254. );
  7255. }
  7256. /*==========================================
  7257. *
  7258. *------------------------------------------*/
  7259. void clif_parse_Restart(int fd, struct map_session_data *sd)
  7260. {
  7261. switch(RFIFOB(fd,2)) {
  7262. case 0x00:
  7263. if (!pc_isdead(sd))
  7264. break;
  7265. pc_setstand(sd);
  7266. pc_setrestartvalue(sd, 3);
  7267. if (pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, 2))
  7268. clif_resurrection(&sd->bl, 1); //If warping fails, send a normal stand up packet.
  7269. break;
  7270. case 0x01:
  7271. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7272. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7273. { //Send to char-server for character selection.
  7274. chrif_charselectreq(sd, session[fd]->client_addr);
  7275. } else {
  7276. WFIFOHEAD(fd,packet_len(0x18b));
  7277. WFIFOW(fd,0)=0x18b;
  7278. WFIFOW(fd,2)=1;
  7279. WFIFOSET(fd,packet_len(0x018b));
  7280. }
  7281. break;
  7282. }
  7283. }
  7284. /*==========================================
  7285. * Validates and processes whispered messages
  7286. * S 0096 <packet len>.w <nick>.23B 00 <message>.?B
  7287. *------------------------------------------*/
  7288. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  7289. {
  7290. struct map_session_data* dstsd;
  7291. int i;
  7292. char *target, *message;
  7293. int namelen, messagelen;
  7294. // validate packet and retrieve name and message
  7295. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  7296. return;
  7297. if (is_atcommand(fd, sd, message) || is_charcommand(fd, sd, message) )
  7298. return;
  7299. if (sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT))
  7300. return;
  7301. if (battle_config.min_chat_delay)
  7302. { //[Skotlex]
  7303. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  7304. return;
  7305. }
  7306. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7307. }
  7308. // Chat logging type 'W' / Whisper
  7309. if( log_config.chat&1 || (log_config.chat&4 && !(agit_flag && log_config.chat&64)) )
  7310. log_chat("W", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
  7311. //-------------------------------------------------------//
  7312. // Lordalfa - Paperboy - To whisper NPC commands //
  7313. //-------------------------------------------------------//
  7314. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  7315. {
  7316. char* str = target+4; //Skip the NPC: string part.
  7317. struct npc_data* npc;
  7318. if ((npc = npc_name2id(str)))
  7319. {
  7320. char split_data[10][50];
  7321. char *split;
  7322. char output[256];
  7323. str = message;
  7324. for( i = 0; i < 10; ++i )
  7325. {// Splits the message using '#' as separators
  7326. split = strchr(str,'#');
  7327. if( split == NULL )
  7328. { // use the remaining string
  7329. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7330. for( ++i; i < 10; ++i )
  7331. split_data[i][0] = '\0';
  7332. break;
  7333. }
  7334. *split = '\0';
  7335. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7336. str = split+1;
  7337. }
  7338. for( i = 0; i < 10; ++i )
  7339. {
  7340. sprintf(output, "@whispervar%d$", i);
  7341. set_var(sd,output,(char *) split_data[i]);
  7342. }
  7343. sprintf(output, "%s::OnWhisperGlobal", npc->name);
  7344. npc_event(sd,output,0); // Calls the NPC label
  7345. return;
  7346. }
  7347. }
  7348. // Main chat [LuzZza]
  7349. if(strcmpi(target, main_chat_nick) == 0)
  7350. {
  7351. if(!sd->state.mainchat)
  7352. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7353. else {
  7354. char output[256];
  7355. snprintf(output, ARRAYLENGTH(output), msg_txt(386), sd->status.name, message);
  7356. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7357. }
  7358. return;
  7359. }
  7360. // searching destination character
  7361. dstsd = map_nick2sd(target);
  7362. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
  7363. {
  7364. // player is not on this map-server
  7365. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7366. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7367. // and if we ask for 'Test', we must not contact 'test' player
  7368. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7369. intif_wis_message(sd, target, message, messagelen);
  7370. return;
  7371. }
  7372. // if player ignores everyone
  7373. if (dstsd->state.ignoreAll)
  7374. {
  7375. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7376. clif_wis_end(fd, 1); // 1: target character is not loged in
  7377. else
  7378. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7379. return;
  7380. }
  7381. // if player ignores the source character
  7382. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  7383. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  7384. { // source char present in ignore list
  7385. clif_wis_end(fd, 2); // 2: ignored by target
  7386. return;
  7387. }
  7388. // notify sender of success
  7389. clif_wis_end(fd, 0); // 0: success to send wisper
  7390. // if player has an auto-away message
  7391. if(dstsd->away_message[0] != '\0')
  7392. {
  7393. char output[256];
  7394. sprintf(output, "%s %s", message, msg_txt(543)); // "(Automessage has been sent)"
  7395. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  7396. if(dstsd->state.autotrade)
  7397. sprintf(output, msg_txt(544), dstsd->away_message); // "Away [AT] - "%s""
  7398. else
  7399. sprintf(output, msg_txt(545), dstsd->away_message); // "Away - "%s""
  7400. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  7401. return;
  7402. }
  7403. // Normal message
  7404. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  7405. return;
  7406. }
  7407. /*==========================================
  7408. * /b /nb
  7409. * S 0099 <packet len>.w <text>.?B 00
  7410. *------------------------------------------*/
  7411. void clif_parse_GMmessage(int fd, struct map_session_data* sd)
  7412. {
  7413. char* msg = (char*)RFIFOP(fd,4);
  7414. unsigned int len = RFIFOW(fd,2)-4;
  7415. int lv;
  7416. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  7417. return;
  7418. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_broadcast)) )
  7419. return;
  7420. // as the length varies depending on the command used, just block unreasonably long strings
  7421. mes_len_check(msg, len, CHAT_SIZE_MAX);
  7422. intif_GMmessage(msg, len, 0);
  7423. if(log_config.gm && lv >= log_config.gm) {
  7424. char logmsg[CHAT_SIZE_MAX+4];
  7425. sprintf(logmsg, "/b %s", msg);
  7426. log_atcommand(sd, logmsg);
  7427. }
  7428. }
  7429. /*==========================================
  7430. *
  7431. *------------------------------------------*/
  7432. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  7433. {
  7434. struct flooritem_data *fitem;
  7435. int map_object_id;
  7436. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7437. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  7438. do {
  7439. if (pc_isdead(sd)) {
  7440. clif_clearunit_area(&sd->bl, 1);
  7441. break;
  7442. }
  7443. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  7444. break;
  7445. if (pc_cant_act(sd))
  7446. break;
  7447. //Disable cloaking/chasewalking characters from looting [Skotlex]
  7448. if(pc_iscloaking(sd) || pc_ischasewalk(sd))
  7449. break;
  7450. if(sd->sc.count && (
  7451. sd->sc.data[SC_TRICKDEAD] ||
  7452. sd->sc.data[SC_BLADESTOP] ||
  7453. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM))
  7454. )
  7455. break;
  7456. if (!pc_takeitem(sd, fitem))
  7457. break;
  7458. return;
  7459. } while (0);
  7460. // Client REQUIRES a fail packet or you can no longer pick items.
  7461. clif_additem(sd,0,0,6);
  7462. }
  7463. /*==========================================
  7464. *
  7465. *------------------------------------------*/
  7466. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  7467. {
  7468. int item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7469. int item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7470. do {
  7471. if (pc_isdead(sd))
  7472. break;
  7473. if (pc_cant_act(sd))
  7474. break;
  7475. if (sd->sc.count && (
  7476. sd->sc.data[SC_AUTOCOUNTER] ||
  7477. sd->sc.data[SC_BLADESTOP] ||
  7478. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  7479. ))
  7480. break;
  7481. if (!pc_dropitem(sd, item_index, item_amount))
  7482. break;
  7483. return;
  7484. } while (0);
  7485. //Because the client does not like being ignored.
  7486. clif_delitem(sd, item_index,0);
  7487. }
  7488. /*==========================================
  7489. *
  7490. *------------------------------------------*/
  7491. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  7492. {
  7493. int n;
  7494. if (pc_isdead(sd)) {
  7495. clif_clearunit_area(&sd->bl, 1);
  7496. return;
  7497. }
  7498. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  7499. return;
  7500. //This flag enables you to use items while in an NPC. [Skotlex]
  7501. if (sd->npc_id) {
  7502. if (sd->npc_id != sd->npc_item_flag)
  7503. return;
  7504. } else
  7505. if (pc_istrading(sd))
  7506. return;
  7507. pc_delinvincibletimer(sd);
  7508. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  7509. sd->idletime = last_tick;
  7510. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7511. if(n <0 || n >= MAX_INVENTORY)
  7512. return;
  7513. if (!pc_useitem(sd,n))
  7514. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  7515. }
  7516. /*==========================================
  7517. *
  7518. *------------------------------------------*/
  7519. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  7520. {
  7521. int index;
  7522. if(pc_isdead(sd)) {
  7523. clif_clearunit_area(&sd->bl,1);
  7524. return;
  7525. }
  7526. index = RFIFOW(fd,2)-2;
  7527. if (index < 0 || index >= MAX_INVENTORY)
  7528. return; //Out of bounds check.
  7529. if(sd->npc_id) {
  7530. if (sd->npc_id != sd->npc_item_flag)
  7531. return;
  7532. } else if (sd->state.storage_flag || sd->sc.opt1)
  7533. ; //You can equip/unequip stuff while storage is open/under status changes
  7534. else if (pc_cant_act(sd))
  7535. return;
  7536. if(!sd->status.inventory[index].identify) {
  7537. clif_equipitemack(sd,index,0,0); // fail
  7538. return;
  7539. }
  7540. if(!sd->inventory_data[index])
  7541. return;
  7542. if(sd->inventory_data[index]->type == IT_PETARMOR){
  7543. pet_equipitem(sd,index);
  7544. return;
  7545. }
  7546. //Client doesn't send the position for ammo.
  7547. if(sd->inventory_data[index]->type == IT_AMMO)
  7548. pc_equipitem(sd,index,EQP_AMMO);
  7549. else
  7550. pc_equipitem(sd,index,RFIFOW(fd,4));
  7551. }
  7552. /*==========================================
  7553. *
  7554. *------------------------------------------*/
  7555. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  7556. {
  7557. int index;
  7558. if(pc_isdead(sd)) {
  7559. clif_clearunit_area(&sd->bl,1);
  7560. return;
  7561. }
  7562. if (sd->state.storage_flag)
  7563. ; //You can equip/unequip stuff while storage is open.
  7564. else if (pc_cant_act(sd))
  7565. return;
  7566. index = RFIFOW(fd,2)-2;
  7567. pc_unequipitem(sd,index,1);
  7568. }
  7569. /*==========================================
  7570. *
  7571. *------------------------------------------*/
  7572. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  7573. {
  7574. struct block_list *bl;
  7575. if(pc_isdead(sd)) {
  7576. clif_clearunit_area(&sd->bl,1);
  7577. return;
  7578. }
  7579. if (pc_cant_act(sd))
  7580. return;
  7581. bl = map_id2bl(RFIFOL(fd,2));
  7582. if (!bl) return;
  7583. switch (bl->type) {
  7584. case BL_MOB:
  7585. if (!((TBL_MOB *)bl)->nd || !mob_script_callback((TBL_MOB *)bl, &sd->bl, CALLBACK_NPCCLICK))
  7586. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7587. break;
  7588. case BL_PC:
  7589. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7590. break;
  7591. case BL_NPC:
  7592. npc_click(sd,(TBL_NPC*)bl);
  7593. break;
  7594. }
  7595. return;
  7596. }
  7597. /*==========================================
  7598. *
  7599. *------------------------------------------*/
  7600. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  7601. {
  7602. if (sd->state.trading)
  7603. return;
  7604. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  7605. }
  7606. /*==========================================
  7607. *
  7608. *------------------------------------------*/
  7609. void clif_parse_NpcBuyListSend(int fd,struct map_session_data *sd)
  7610. {
  7611. int fail=0,n;
  7612. unsigned short *item_list;
  7613. n = (RFIFOW(fd,2)-4) /4;
  7614. item_list = (unsigned short*)RFIFOP(fd,4);
  7615. if (sd->state.trading|| !sd->npc_shopid)
  7616. fail = 1;
  7617. else
  7618. fail = npc_buylist(sd,n,item_list);
  7619. sd->npc_shopid = 0; //Clear shop data.
  7620. WFIFOHEAD(fd,packet_len(0xca));
  7621. WFIFOW(fd,0)=0xca;
  7622. WFIFOB(fd,2)=fail;
  7623. WFIFOSET(fd,packet_len(0xca));
  7624. }
  7625. /*==========================================
  7626. *
  7627. *------------------------------------------*/
  7628. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  7629. {
  7630. int fail=0,n;
  7631. unsigned short *item_list;
  7632. n = (RFIFOW(fd,2)-4) /4;
  7633. item_list = (unsigned short*)RFIFOP(fd,4);
  7634. if (sd->state.trading || !sd->npc_shopid)
  7635. fail = 1;
  7636. else
  7637. fail = npc_selllist(sd,n,item_list);
  7638. sd->npc_shopid = 0; //Clear shop data.
  7639. WFIFOHEAD(fd,packet_len(0xcb));
  7640. WFIFOW(fd,0)=0xcb;
  7641. WFIFOB(fd,2)=fail;
  7642. WFIFOSET(fd,packet_len(0xcb));
  7643. }
  7644. /*==========================================
  7645. * Chatroom creation request
  7646. * S 00d5 <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7647. *------------------------------------------*/
  7648. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  7649. {
  7650. int len = RFIFOW(fd,2)-15;
  7651. int limit = RFIFOW(fd,4);
  7652. bool pub = (RFIFOB(fd,6) != 0);
  7653. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  7654. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7655. char s_title[CHATROOM_TITLE_SIZE];
  7656. char s_password[CHATROOM_PASS_SIZE];
  7657. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  7658. return;
  7659. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  7660. clif_skill_fail(sd,1,0,3);
  7661. return;
  7662. }
  7663. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7664. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7665. chat_createpcchat(sd, s_title, s_password, limit, pub);
  7666. }
  7667. /*==========================================
  7668. * Chatroom join request
  7669. * S 00d9 <chat ID>.l <passwd>.8B
  7670. *------------------------------------------*/
  7671. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  7672. {
  7673. int chatid = RFIFOL(fd,2);
  7674. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  7675. chat_joinchat(sd,chatid,password);
  7676. }
  7677. /*==========================================
  7678. * Chatroom properties adjustment request
  7679. * S 00de <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7680. *------------------------------------------*/
  7681. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  7682. {
  7683. int len = RFIFOW(fd,2)-15;
  7684. int limit = RFIFOW(fd,4);
  7685. bool pub = (RFIFOB(fd,6) != 0);
  7686. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  7687. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7688. char s_title[CHATROOM_TITLE_SIZE];
  7689. char s_password[CHATROOM_PASS_SIZE];
  7690. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7691. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7692. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  7693. }
  7694. /*==========================================
  7695. * S 00e0 ?.l <nick>.24B
  7696. *------------------------------------------*/
  7697. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  7698. {
  7699. //TODO: the first argument seems to be the destination position (always 0) [ultramage]
  7700. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  7701. }
  7702. /*==========================================
  7703. *
  7704. *------------------------------------------*/
  7705. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  7706. {
  7707. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  7708. }
  7709. /*==========================================
  7710. * Request to leave the current chatroom
  7711. * S 00e3
  7712. *------------------------------------------*/
  7713. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  7714. {
  7715. chat_leavechat(sd,0);
  7716. }
  7717. //Handles notifying asker and rejecter of what has just ocurred.
  7718. //Type is used to determine the correct msg_txt to use:
  7719. //0:
  7720. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  7721. {
  7722. char *msg, output[256];
  7723. // Your request has been rejected by autoreject option.
  7724. msg = msg_txt(392);
  7725. clif_disp_onlyself(src, msg, strlen(msg));
  7726. //Notice that a request was rejected.
  7727. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  7728. clif_disp_onlyself(target, output, strlen(output));
  7729. }
  7730. /*==========================================
  7731. * 取引要請を相手に送る
  7732. *------------------------------------------*/
  7733. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  7734. {
  7735. struct map_session_data *t_sd;
  7736. t_sd = map_id2sd(RFIFOL(fd,2));
  7737. if(!sd->chatID && pc_cant_act(sd))
  7738. return; //You can trade while in a chatroom.
  7739. // @noask [LuzZza]
  7740. if(t_sd && t_sd->state.noask) {
  7741. clif_noask_sub(sd, t_sd, 0);
  7742. return;
  7743. }
  7744. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 1){
  7745. trade_traderequest(sd,t_sd);
  7746. } else
  7747. clif_skill_fail(sd,1,0,0);
  7748. }
  7749. /*==========================================
  7750. * 取引要請
  7751. *------------------------------------------*/
  7752. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  7753. {
  7754. trade_tradeack(sd,RFIFOB(fd,2));
  7755. }
  7756. /*==========================================
  7757. * アイテム追加
  7758. *------------------------------------------*/
  7759. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  7760. {
  7761. short index = RFIFOW(fd,2);
  7762. int amount = RFIFOL(fd,4);
  7763. if( index == 0 )
  7764. trade_tradeaddzeny(sd, amount);
  7765. else
  7766. trade_tradeadditem(sd, index, (short)amount);
  7767. }
  7768. /*==========================================
  7769. * アイテム追加完了(ok押し)
  7770. *------------------------------------------*/
  7771. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  7772. {
  7773. trade_tradeok(sd);
  7774. }
  7775. /*==========================================
  7776. * 取引キャンセル
  7777. *------------------------------------------*/
  7778. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  7779. {
  7780. trade_tradecancel(sd);
  7781. }
  7782. /*==========================================
  7783. * 取引許諾(trade押し)
  7784. *------------------------------------------*/
  7785. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  7786. {
  7787. trade_tradecommit(sd);
  7788. }
  7789. /*==========================================
  7790. *
  7791. *------------------------------------------*/
  7792. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  7793. {
  7794. pc_stop_attack(sd);
  7795. }
  7796. /*==========================================
  7797. * カートへアイテムを移す
  7798. *------------------------------------------*/
  7799. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  7800. {
  7801. if (pc_istrading(sd))
  7802. return;
  7803. if (!pc_iscarton(sd))
  7804. return;
  7805. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  7806. }
  7807. /*==========================================
  7808. * カートからアイテムを出す
  7809. *------------------------------------------*/
  7810. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  7811. {
  7812. if (!pc_iscarton(sd))
  7813. return;
  7814. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  7815. }
  7816. /*==========================================
  7817. * 付属品(鷹,ペコ,カート)をはずす
  7818. *------------------------------------------*/
  7819. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  7820. {
  7821. //Can only remove Cart/Riding/Falcon.
  7822. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  7823. }
  7824. /*==========================================
  7825. * チェンジカート
  7826. *------------------------------------------*/
  7827. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  7828. {
  7829. int type;
  7830. type = (int)RFIFOW(fd,2);
  7831. if( (type == 5 && sd->status.base_level <= 90) ||
  7832. (type == 4 && sd->status.base_level <= 80) ||
  7833. (type == 3 && sd->status.base_level <= 65) ||
  7834. (type == 2 && sd->status.base_level <= 40) ||
  7835. pc_setcart(sd,type) )
  7836. {
  7837. LOG_SUSPICIOUS(sd,"clif_parse_ChangeCart");
  7838. }
  7839. }
  7840. /*==========================================
  7841. * ステータスアップ
  7842. *------------------------------------------*/
  7843. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  7844. {
  7845. pc_statusup(sd,RFIFOW(fd,2));
  7846. }
  7847. /*==========================================
  7848. * スキルレベルアップ
  7849. *------------------------------------------*/
  7850. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  7851. {
  7852. pc_skillup(sd,RFIFOW(fd,2));
  7853. }
  7854. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, short skillnum, short skilllv, int target_id)
  7855. {
  7856. int lv;
  7857. if (!hd)
  7858. return;
  7859. if (skillnotok_hom(skillnum, hd)) //[orn]
  7860. return;
  7861. if (hd->bl.id != target_id &&
  7862. skill_get_inf(skillnum)&INF_SELF_SKILL)
  7863. target_id = hd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  7864. if (hd->ud.skilltimer != -1) {
  7865. if (skillnum != SA_CASTCANCEL)
  7866. return;
  7867. } else if (DIFF_TICK(tick, hd->ud.canact_tick) < 0)
  7868. return;
  7869. lv = merc_hom_checkskill(hd, skillnum);
  7870. if (skilllv > lv)
  7871. skilllv = lv;
  7872. if (skilllv)
  7873. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  7874. }
  7875. /*==========================================
  7876. * スキル使用(ID指定)
  7877. *------------------------------------------*/
  7878. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  7879. {
  7880. short skillnum, skilllv;
  7881. int tmp, target_id;
  7882. unsigned int tick = gettick();
  7883. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7884. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7885. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  7886. if (skilllv < 1) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  7887. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  7888. sd->idletime = last_tick;
  7889. tmp = skill_get_inf(skillnum);
  7890. if (tmp&INF_GROUND_SKILL || !tmp)
  7891. return; //Using a ground/passive skill on a target? WRONG.
  7892. if (skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE+MAX_HOMUNSKILL) {
  7893. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  7894. return;
  7895. }
  7896. if (pc_cant_act(sd))
  7897. return;
  7898. if (pc_issit(sd))
  7899. return;
  7900. if (skillnotok(skillnum, sd))
  7901. return;
  7902. if (sd->bl.id != target_id && !sd->state.skill_flag && tmp&INF_SELF_SKILL)
  7903. target_id = sd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  7904. if (sd->ud.skilltimer != -1) {
  7905. if (skillnum != SA_CASTCANCEL)
  7906. return;
  7907. } else if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7908. clif_skill_fail(sd, skillnum, 4, 0);
  7909. return;
  7910. }
  7911. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  7912. return;
  7913. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7914. target_id = sd->bl.id;
  7915. if(sd->menuskill_id)
  7916. {
  7917. if (sd->menuskill_id == SA_TAMINGMONSTER)
  7918. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  7919. else
  7920. if (sd->menuskill_id != SA_AUTOSPELL)
  7921. return; //Can't use skills while a menu is open.
  7922. }
  7923. if (sd->skillitem == skillnum) {
  7924. if (skilllv != sd->skillitemlv)
  7925. skilllv = sd->skillitemlv;
  7926. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  7927. return;
  7928. }
  7929. sd->skillitem = sd->skillitemlv = 0;
  7930. if (skillnum == MO_EXTREMITYFIST) {
  7931. if ((!sd->sc.data[SC_COMBO] ||
  7932. (sd->sc.data[SC_COMBO]->val1 != MO_COMBOFINISH &&
  7933. sd->sc.data[SC_COMBO]->val1 != CH_TIGERFIST &&
  7934. sd->sc.data[SC_COMBO]->val1 != CH_CHAINCRUSH))) {
  7935. if (!sd->state.skill_flag ) {
  7936. sd->state.skill_flag = 1;
  7937. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  7938. return;
  7939. } else if (sd->bl.id == target_id) {
  7940. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  7941. return;
  7942. }
  7943. }
  7944. }
  7945. if (skillnum == TK_JUMPKICK) {
  7946. if (!sd->sc.data[SC_COMBO] || sd->sc.data[SC_COMBO]->val1 != TK_JUMPKICK) {
  7947. if (!sd->state.skill_flag ) {
  7948. sd->state.skill_flag = 1;
  7949. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  7950. return;
  7951. } else if (sd->bl.id == target_id) {
  7952. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  7953. return;
  7954. }
  7955. }
  7956. }
  7957. if (skillnum >= GD_SKILLBASE) {
  7958. if (sd->state.gmaster_flag)
  7959. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  7960. else
  7961. skilllv = 0;
  7962. } else {
  7963. tmp = pc_checkskill(sd, skillnum);
  7964. if (skilllv > tmp)
  7965. skilllv = tmp;
  7966. }
  7967. pc_delinvincibletimer(sd);
  7968. if (skilllv)
  7969. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  7970. if (sd->state.skill_flag)
  7971. sd->state.skill_flag = 0;
  7972. }
  7973. /*==========================================
  7974. * スキル使用(場所指定)
  7975. *------------------------------------------*/
  7976. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, short skilllv, short skillnum, short x, short y, int skillmoreinfo)
  7977. {
  7978. int lv;
  7979. unsigned int tick = gettick();
  7980. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  7981. sd->idletime = last_tick;
  7982. if (skillnotok(skillnum, sd))
  7983. return;
  7984. if (!(skill_get_inf(skillnum)&INF_GROUND_SKILL))
  7985. return; //Using a target skill on the ground? WRONG.
  7986. if (skillmoreinfo != -1) {
  7987. if (pc_issit(sd)) {
  7988. clif_skill_fail(sd, skillnum, 0, 0);
  7989. return;
  7990. }
  7991. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  7992. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  7993. }
  7994. if (sd->ud.skilltimer != -1)
  7995. return;
  7996. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0)
  7997. {
  7998. clif_skill_fail(sd, skillnum, 4, 0);
  7999. return;
  8000. }
  8001. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  8002. return;
  8003. if(sd->menuskill_id)
  8004. {
  8005. if (sd->menuskill_id == SA_TAMINGMONSTER)
  8006. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8007. else
  8008. if (sd->menuskill_id != SA_AUTOSPELL)
  8009. return; //Can't use skills while a menu is open.
  8010. }
  8011. pc_delinvincibletimer(sd);
  8012. if (sd->skillitem == skillnum) {
  8013. if (skilllv != sd->skillitemlv)
  8014. skilllv = sd->skillitemlv;
  8015. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8016. } else {
  8017. sd->skillitem = sd->skillitemlv = 0;
  8018. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8019. if (skilllv > lv)
  8020. skilllv = lv;
  8021. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8022. }
  8023. }
  8024. }
  8025. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  8026. {
  8027. if (pc_cant_act(sd))
  8028. return;
  8029. if (pc_issit(sd))
  8030. return;
  8031. clif_parse_UseSkillToPosSub(fd, sd,
  8032. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8033. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8034. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8035. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8036. -1 //Skill more info.
  8037. );
  8038. }
  8039. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  8040. {
  8041. if (pc_cant_act(sd))
  8042. return;
  8043. if (pc_issit(sd))
  8044. return;
  8045. clif_parse_UseSkillToPosSub(fd, sd,
  8046. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8047. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8048. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8049. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8050. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8051. );
  8052. }
  8053. /*==========================================
  8054. * スキル使用(map指定)
  8055. *------------------------------------------*/
  8056. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  8057. {
  8058. short skill_num = RFIFOW(fd,2);
  8059. char map_name[MAP_NAME_LENGTH];
  8060. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  8061. if(skill_num != sd->menuskill_id)
  8062. return;
  8063. if (pc_cant_act(sd))
  8064. {
  8065. sd->menuskill_id = sd->menuskill_val = 0;
  8066. return;
  8067. }
  8068. pc_delinvincibletimer(sd);
  8069. skill_castend_map(sd,skill_num,map_name);
  8070. }
  8071. /*==========================================
  8072. * メモ要求
  8073. *------------------------------------------*/
  8074. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8075. {
  8076. if (!pc_isdead(sd))
  8077. pc_memo(sd,-1);
  8078. }
  8079. /*==========================================
  8080. * アイテム合成
  8081. *------------------------------------------*/
  8082. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8083. {
  8084. if (sd->menuskill_id != AM_PHARMACY)
  8085. return;
  8086. if (pc_istrading(sd)) {
  8087. //Make it fail to avoid shop exploits where you sell something different than you see.
  8088. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8089. sd->menuskill_val = sd->menuskill_id = 0;
  8090. return;
  8091. }
  8092. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8093. sd->menuskill_val = sd->menuskill_id = 0;
  8094. }
  8095. /*==========================================
  8096. * 武器修理
  8097. *------------------------------------------*/
  8098. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8099. {
  8100. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8101. return;
  8102. if (pc_istrading(sd)) {
  8103. //Make it fail to avoid shop exploits where you sell something different than you see.
  8104. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8105. sd->menuskill_val = sd->menuskill_id = 0;
  8106. return;
  8107. }
  8108. skill_repairweapon(sd,RFIFOW(fd,2));
  8109. sd->menuskill_val = sd->menuskill_id = 0;
  8110. }
  8111. /*==========================================
  8112. *
  8113. *------------------------------------------*/
  8114. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  8115. {
  8116. int idx;
  8117. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8118. return;
  8119. if (pc_istrading(sd)) {
  8120. //Make it fail to avoid shop exploits where you sell something different than you see.
  8121. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8122. sd->menuskill_val = sd->menuskill_id = 0;
  8123. return;
  8124. }
  8125. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8126. skill_weaponrefine(sd, idx-2);
  8127. sd->menuskill_val = sd->menuskill_id = 0;
  8128. }
  8129. /*==========================================
  8130. *
  8131. *------------------------------------------*/
  8132. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8133. {
  8134. uint8 select;
  8135. select = RFIFOB(fd,6);
  8136. if((select > sd->npc_menu && select != 0xff) || !select){
  8137. ShowWarning("Hack on NPC Select Menu: %s (AID: %d)!\n",sd->status.name,sd->bl.id);
  8138. clif_GM_kick(sd,sd,0);
  8139. } else {
  8140. sd->npc_menu=select;
  8141. npc_scriptcont(sd,RFIFOL(fd,2));
  8142. }
  8143. }
  8144. /*==========================================
  8145. *
  8146. *------------------------------------------*/
  8147. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8148. {
  8149. npc_scriptcont(sd,RFIFOL(fd,2));
  8150. }
  8151. /*==========================================
  8152. * Value entered into a NPC input box.
  8153. * S 0143 <npcID>.l <amount>.l
  8154. *------------------------------------------*/
  8155. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8156. {
  8157. int npcid = RFIFOL(fd,2);
  8158. int amount = (int)RFIFOL(fd,6);
  8159. sd->npc_amount = amount;
  8160. npc_scriptcont(sd, npcid);
  8161. }
  8162. /*==========================================
  8163. * Text entered into a NPC input box.
  8164. * S 01d5 <len>.w <npcID>.l <input>.?B 00
  8165. *------------------------------------------*/
  8166. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  8167. {
  8168. int message_len = RFIFOW(fd,2)-8;
  8169. int npcid = RFIFOL(fd,4);
  8170. const char* message = (char*)RFIFOP(fd,8);
  8171. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  8172. npc_scriptcont(sd, npcid);
  8173. }
  8174. /*==========================================
  8175. *
  8176. *------------------------------------------*/
  8177. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8178. {
  8179. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8180. return;
  8181. npc_scriptcont(sd,RFIFOL(fd,2));
  8182. }
  8183. /*==========================================
  8184. * アイテム鑑定
  8185. *------------------------------------------*/
  8186. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8187. {
  8188. if (sd->menuskill_id != MC_IDENTIFY)
  8189. return;
  8190. skill_identify(sd,RFIFOW(fd,2)-2);
  8191. sd->menuskill_val = sd->menuskill_id = 0;
  8192. }
  8193. /*==========================================
  8194. * 矢作成
  8195. *------------------------------------------*/
  8196. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8197. {
  8198. if (sd->menuskill_id != AC_MAKINGARROW)
  8199. return;
  8200. if (pc_istrading(sd)) {
  8201. //Make it fail to avoid shop exploits where you sell something different than you see.
  8202. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8203. sd->menuskill_val = sd->menuskill_id = 0;
  8204. return;
  8205. }
  8206. skill_arrow_create(sd,RFIFOW(fd,2));
  8207. sd->menuskill_val = sd->menuskill_id = 0;
  8208. }
  8209. /*==========================================
  8210. * オートスペル受信
  8211. *------------------------------------------*/
  8212. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8213. {
  8214. if (sd->menuskill_id != SA_AUTOSPELL)
  8215. return;
  8216. skill_autospell(sd,RFIFOW(fd,2));
  8217. sd->menuskill_val = sd->menuskill_id = 0;
  8218. }
  8219. /*==========================================
  8220. * カード使用
  8221. *------------------------------------------*/
  8222. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8223. {
  8224. if (sd->state.trading != 0)
  8225. return;
  8226. clif_use_card(sd,RFIFOW(fd,2)-2);
  8227. }
  8228. /*==========================================
  8229. * カード挿入装備選択
  8230. *------------------------------------------*/
  8231. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8232. {
  8233. if (sd->state.trading != 0)
  8234. return;
  8235. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8236. }
  8237. /*==========================================
  8238. * 0193 キャラID名前引き
  8239. *------------------------------------------*/
  8240. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  8241. {
  8242. int charid;
  8243. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8244. map_reqnickdb(sd, charid);
  8245. }
  8246. /*==========================================
  8247. * 0197 /resetskill /resetstate
  8248. *------------------------------------------*/
  8249. void clif_parse_ResetChar(int fd, struct map_session_data *sd)
  8250. {
  8251. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8252. return;
  8253. if( pc_isGM(sd) < get_atcommand_level(atcommand_reset) )
  8254. return;
  8255. if( RFIFOW(fd,2) )
  8256. pc_resetskill(sd,1);
  8257. else
  8258. pc_resetstate(sd);
  8259. if( log_config.gm && get_atcommand_level(atcommand_reset) >= log_config.gm )
  8260. log_atcommand(sd, RFIFOW(fd,2) ? "/resetskill" : "/resetstate");
  8261. }
  8262. /*==========================================
  8263. * /lb /nlb
  8264. * S 019c <packet len>.w <text>.?B 00
  8265. *------------------------------------------*/
  8266. void clif_parse_LGMmessage(int fd, struct map_session_data* sd)
  8267. {
  8268. char* msg = (char*)RFIFOP(fd,4);
  8269. unsigned int len = RFIFOW(fd,2)-4;
  8270. int lv;
  8271. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8272. return;
  8273. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_localbroadcast)) )
  8274. return;
  8275. // as the length varies depending on the command used, just block unreasonably long strings
  8276. mes_len_check(msg, len, CHAT_SIZE_MAX);
  8277. clif_GMmessage(&sd->bl, msg, len, 1);
  8278. if( log_config.gm && lv >= log_config.gm ) {
  8279. char logmsg[CHAT_SIZE_MAX+5];
  8280. sprintf(logmsg, "/lb %s", msg);
  8281. log_atcommand(sd, logmsg);
  8282. }
  8283. }
  8284. /*==========================================
  8285. * カプラ倉庫へ入れる
  8286. *------------------------------------------*/
  8287. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  8288. {
  8289. int item_index, item_amount;
  8290. if (pc_istrading(sd))
  8291. return;
  8292. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8293. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8294. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  8295. return;
  8296. if (sd->state.storage_flag == 1)
  8297. storage_storageadd(sd, item_index, item_amount);
  8298. else if (sd->state.storage_flag == 2)
  8299. storage_guild_storageadd(sd, item_index, item_amount);
  8300. }
  8301. /*==========================================
  8302. * カプラ倉庫から出す
  8303. *------------------------------------------*/
  8304. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  8305. {
  8306. int item_index, item_amount;
  8307. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8308. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8309. if (sd->state.storage_flag == 1)
  8310. storage_storageget(sd, item_index, item_amount);
  8311. else if(sd->state.storage_flag == 2)
  8312. storage_guild_storageget(sd, item_index, item_amount);
  8313. }
  8314. /*==========================================
  8315. * カプラ倉庫へカートから入れる
  8316. *------------------------------------------*/
  8317. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  8318. {
  8319. if(sd->vender_id)
  8320. return;
  8321. if (!pc_iscarton(sd))
  8322. return;
  8323. if (sd->state.storage_flag == 1)
  8324. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8325. else if (sd->state.storage_flag == 2)
  8326. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8327. }
  8328. /*==========================================
  8329. * カプラ倉庫から出す
  8330. *------------------------------------------*/
  8331. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  8332. {
  8333. if (sd->vender_id)
  8334. return;
  8335. if (!pc_iscarton(sd))
  8336. return;
  8337. if (sd->state.storage_flag == 1)
  8338. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8339. else if (sd->state.storage_flag == 2)
  8340. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8341. }
  8342. /*==========================================
  8343. * カプラ倉庫を閉じる
  8344. *------------------------------------------*/
  8345. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  8346. {
  8347. if (sd->state.storage_flag == 1)
  8348. storage_storageclose(sd);
  8349. else if (sd->state.storage_flag == 2)
  8350. storage_guild_storageclose(sd);
  8351. }
  8352. /*==========================================
  8353. * Kafra storage protection password system
  8354. *------------------------------------------*/
  8355. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  8356. {
  8357. //TODO
  8358. }
  8359. /*==========================================
  8360. * パーティを作る
  8361. *------------------------------------------*/
  8362. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  8363. {
  8364. if(map[sd->bl.m].flag.partylock)
  8365. { //Guild locked.
  8366. clif_displaymessage(fd, msg_txt(227));
  8367. return;
  8368. }
  8369. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7) {
  8370. party_create(sd,(char*)RFIFOP(fd,2),0,0);
  8371. } else
  8372. clif_skill_fail(sd,1,0,4);
  8373. }
  8374. /*==========================================
  8375. * パーティを作る
  8376. *------------------------------------------*/
  8377. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  8378. {
  8379. if(map[sd->bl.m].flag.partylock)
  8380. { //Guild locked.
  8381. clif_displaymessage(fd, msg_txt(227));
  8382. return;
  8383. }
  8384. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7)
  8385. party_create(sd,(char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27));
  8386. else
  8387. clif_skill_fail(sd,1,0,4);
  8388. }
  8389. /*==========================================
  8390. * パーティに勧誘
  8391. *------------------------------------------*/
  8392. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  8393. {
  8394. struct map_session_data *t_sd;
  8395. if(map[sd->bl.m].flag.partylock)
  8396. { //Guild locked.
  8397. clif_displaymessage(fd, msg_txt(227));
  8398. return;
  8399. }
  8400. t_sd = map_id2sd(RFIFOL(fd,2));
  8401. // @noask [LuzZza]
  8402. if(t_sd && t_sd->state.noask) {
  8403. clif_noask_sub(sd, t_sd, 1);
  8404. return;
  8405. }
  8406. party_invite(sd, t_sd);
  8407. }
  8408. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  8409. {
  8410. struct map_session_data *t_sd;
  8411. char *name = (char*)RFIFOP(fd,2);
  8412. name[NAME_LENGTH]='\0';
  8413. if(map[sd->bl.m].flag.partylock)
  8414. { //Guild locked.
  8415. clif_displaymessage(fd, msg_txt(227));
  8416. return;
  8417. }
  8418. t_sd = map_nick2sd(name);
  8419. // @noask [LuzZza]
  8420. if(t_sd && t_sd->state.noask) {
  8421. clif_noask_sub(sd, t_sd, 1);
  8422. return;
  8423. }
  8424. party_invite(sd, t_sd);
  8425. }
  8426. /*==========================================
  8427. * パーティ勧誘返答
  8428. *------------------------------------------*/
  8429. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  8430. {
  8431. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  8432. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8433. } else {
  8434. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8435. clif_skill_fail(sd,1,0,4);
  8436. }
  8437. }
  8438. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  8439. {
  8440. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  8441. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8442. } else {
  8443. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8444. clif_skill_fail(sd,1,0,4);
  8445. }
  8446. }
  8447. /*==========================================
  8448. * パーティ脱退要求
  8449. *------------------------------------------*/
  8450. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  8451. {
  8452. if(map[sd->bl.m].flag.partylock)
  8453. { //Guild locked.
  8454. clif_displaymessage(fd, msg_txt(227));
  8455. return;
  8456. }
  8457. party_leave(sd);
  8458. }
  8459. /*==========================================
  8460. * パーティ除名要求
  8461. *------------------------------------------*/
  8462. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  8463. {
  8464. if(map[sd->bl.m].flag.partylock)
  8465. { //Guild locked.
  8466. clif_displaymessage(fd, msg_txt(227));
  8467. return;
  8468. }
  8469. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8470. }
  8471. /*==========================================
  8472. * パーティ設定変更要求
  8473. *------------------------------------------*/
  8474. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  8475. {
  8476. struct party_data *p;
  8477. if(!sd->status.party_id)
  8478. return;
  8479. p = party_search(sd->status.party_id);
  8480. if (!p) return;
  8481. //The client no longer can change the item-field, therefore it always
  8482. //comes as zero. Here, resend the item data as it is.
  8483. // party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  8484. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  8485. }
  8486. /*==========================================
  8487. * Validates and processes party messages
  8488. * S 0108 <packet len>.w <text>.?B (<name> : <message>) 00
  8489. *------------------------------------------*/
  8490. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  8491. {
  8492. const char* text = (char*)RFIFOP(fd,4);
  8493. int textlen = RFIFOW(fd,2) - 4;
  8494. char *name, *message;
  8495. int namelen, messagelen;
  8496. // validate packet and retrieve name and message
  8497. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8498. return;
  8499. if( is_atcommand(fd, sd, message) || is_charcommand(fd, sd, message) )
  8500. return;
  8501. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8502. return;
  8503. if( battle_config.min_chat_delay )
  8504. { //[Skotlex]
  8505. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8506. return;
  8507. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8508. }
  8509. party_send_message(sd, text, textlen);
  8510. }
  8511. /*==========================================
  8512. * 露店閉鎖
  8513. *------------------------------------------*/
  8514. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  8515. {
  8516. vending_closevending(sd);
  8517. }
  8518. /*==========================================
  8519. * 露店アイテムリスト要求
  8520. *------------------------------------------*/
  8521. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  8522. {
  8523. vending_vendinglistreq(sd,RFIFOL(fd,2));
  8524. if( sd->npc_id )
  8525. npc_event_dequeue(sd);
  8526. }
  8527. /*==========================================
  8528. * Shop item(s) purchase request
  8529. * S 0134 <len>.w <ID>.l {<amount>.w <index>.w}.4B*
  8530. *------------------------------------------*/
  8531. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  8532. {
  8533. int len = (int)RFIFOW(fd,2) - 8;
  8534. int id = (int)RFIFOL(fd,4);
  8535. const uint8* data = (uint8*)RFIFOP(fd,8);
  8536. vending_purchasereq(sd, id, data, len/4);
  8537. }
  8538. /*==========================================
  8539. * Confirm or cancel the shop preparation window
  8540. * S 01b2 <len>.w <message>.80B <flag>.B {<index>.w <amount>.w <value>.l}.8B*
  8541. * flag: 0=cancel, 1=confirm
  8542. *------------------------------------------*/
  8543. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  8544. {
  8545. short len = (short)RFIFOW(fd,2) - 85;
  8546. const char* message = (char*)RFIFOP(fd,4);
  8547. bool flag = (bool)RFIFOB(fd,84);
  8548. const uint8* data = (uint8*)RFIFOP(fd,85);
  8549. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  8550. return;
  8551. if( map[sd->bl.m].flag.novending || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  8552. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open shop on this map"
  8553. return;
  8554. }
  8555. if( message[0] == '\0' ) // invalid input
  8556. return;
  8557. vending_openvending(sd, message, flag, data, len/8);
  8558. }
  8559. /*==========================================
  8560. * ギルドを作る
  8561. *------------------------------------------*/
  8562. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  8563. {
  8564. if(map[sd->bl.m].flag.guildlock)
  8565. { //Guild locked.
  8566. clif_displaymessage(fd, msg_txt(228));
  8567. return;
  8568. }
  8569. guild_create(sd, (char*)RFIFOP(fd,6));
  8570. }
  8571. /*==========================================
  8572. * ギルドマスターかどうか確認
  8573. *------------------------------------------*/
  8574. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  8575. {
  8576. clif_guild_masterormember(sd);
  8577. }
  8578. /*==========================================
  8579. * ギルド情報要求
  8580. *------------------------------------------*/
  8581. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  8582. {
  8583. if (!sd->status.guild_id)
  8584. return;
  8585. switch(RFIFOL(fd,2)){
  8586. case 0: // ギルド基本情報、同盟敵対情報
  8587. clif_guild_basicinfo(sd);
  8588. clif_guild_allianceinfo(sd);
  8589. break;
  8590. case 1: // メンバーリスト、役職名リスト
  8591. clif_guild_positionnamelist(sd);
  8592. clif_guild_memberlist(sd);
  8593. break;
  8594. case 2: // 役職名リスト、役職情報リスト
  8595. clif_guild_positionnamelist(sd);
  8596. clif_guild_positioninfolist(sd);
  8597. break;
  8598. case 3: // スキルリスト
  8599. clif_guild_skillinfo(sd);
  8600. break;
  8601. case 4: // 追放リスト
  8602. clif_guild_expulsionlist(sd);
  8603. break;
  8604. default:
  8605. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  8606. break;
  8607. }
  8608. }
  8609. /*==========================================
  8610. * ギルド役職変更
  8611. *------------------------------------------*/
  8612. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  8613. {
  8614. int i;
  8615. if(!sd->state.gmaster_flag)
  8616. return;
  8617. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  8618. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  8619. }
  8620. }
  8621. /*==========================================
  8622. * ギルドメンバ役職変更
  8623. *------------------------------------------*/
  8624. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  8625. {
  8626. int i;
  8627. if(!sd->state.gmaster_flag)
  8628. return;
  8629. for(i=4;i<RFIFOW(fd,2);i+=12){
  8630. guild_change_memberposition(sd->status.guild_id,
  8631. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  8632. }
  8633. }
  8634. /*==========================================
  8635. * ギルドエンブレム要求
  8636. *------------------------------------------*/
  8637. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  8638. {
  8639. struct guild* g = guild_search(RFIFOL(fd,2));
  8640. if(g!=NULL)
  8641. clif_guild_emblem(sd,g);
  8642. }
  8643. /*==========================================
  8644. * ギルドエンブレム変更
  8645. *------------------------------------------*/
  8646. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  8647. {
  8648. if(!sd->state.gmaster_flag)
  8649. return;
  8650. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  8651. }
  8652. /*==========================================
  8653. * Guild notice update request
  8654. * S 016E <guildID>.l <msg1>.60B <msg2>.120B
  8655. *------------------------------------------*/
  8656. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  8657. {
  8658. int guild_id = RFIFOL(fd,2);
  8659. char* msg1 = (char*)RFIFOP(fd,6);
  8660. char* msg2 = (char*)RFIFOP(fd,66);
  8661. if(!sd->state.gmaster_flag)
  8662. return;
  8663. // compensate for some client defects when using multilanguage mode
  8664. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  8665. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  8666. if (msg2[0] == '|') msg2[strnlen(msg2, 120)-1] = '\0'; // delete extra space at the end of string
  8667. guild_change_notice(sd, guild_id, msg1, msg2);
  8668. }
  8669. /*==========================================
  8670. * ギルド勧誘
  8671. *------------------------------------------*/
  8672. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  8673. {
  8674. struct map_session_data *t_sd;
  8675. if(map[sd->bl.m].flag.guildlock)
  8676. { //Guild locked.
  8677. clif_displaymessage(fd, msg_txt(228));
  8678. return;
  8679. }
  8680. t_sd = map_id2sd(RFIFOL(fd,2));
  8681. // @noask [LuzZza]
  8682. if(t_sd && t_sd->state.noask) {
  8683. clif_noask_sub(sd, t_sd, 2);
  8684. return;
  8685. }
  8686. guild_invite(sd,t_sd);
  8687. }
  8688. /*==========================================
  8689. * ギルド勧誘返信
  8690. *------------------------------------------*/
  8691. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  8692. {
  8693. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8694. }
  8695. /*==========================================
  8696. * ギルド脱退
  8697. *------------------------------------------*/
  8698. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  8699. {
  8700. if(map[sd->bl.m].flag.guildlock)
  8701. { //Guild locked.
  8702. clif_displaymessage(fd, msg_txt(228));
  8703. return;
  8704. }
  8705. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8706. }
  8707. /*==========================================
  8708. * Request to expel a member of a guild
  8709. * S 015b <guild_id>.L <account_id>.L <char_id>.L <reason>.39B 00
  8710. *------------------------------------------*/
  8711. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  8712. {
  8713. if(map[sd->bl.m].flag.guildlock)
  8714. { //Guild locked.
  8715. clif_displaymessage(fd, msg_txt(228));
  8716. return;
  8717. }
  8718. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8719. }
  8720. /*==========================================
  8721. * Validates and processes guild messages
  8722. * S 017e <packet len>.w <text>.?B (<name> : <message>) 00
  8723. *------------------------------------------*/
  8724. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  8725. {
  8726. const char* text = (char*)RFIFOP(fd,4);
  8727. int textlen = RFIFOW(fd,2) - 4;
  8728. char *name, *message;
  8729. int namelen, messagelen;
  8730. // validate packet and retrieve name and message
  8731. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8732. return;
  8733. if( is_atcommand(fd, sd, message) || is_charcommand(fd, sd, message) )
  8734. return;
  8735. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8736. return;
  8737. if( battle_config.min_chat_delay )
  8738. { //[Skotlex]
  8739. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8740. return;
  8741. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8742. }
  8743. guild_send_message(sd, text, textlen);
  8744. }
  8745. /*==========================================
  8746. * ギルド同盟要求
  8747. *------------------------------------------*/
  8748. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  8749. {
  8750. struct map_session_data *t_sd;
  8751. if(!sd->state.gmaster_flag)
  8752. return;
  8753. if(map[sd->bl.m].flag.guildlock)
  8754. { //Guild locked.
  8755. clif_displaymessage(fd, msg_txt(228));
  8756. return;
  8757. }
  8758. t_sd = map_id2sd(RFIFOL(fd,2));
  8759. // @noask [LuzZza]
  8760. if(t_sd && t_sd->state.noask) {
  8761. clif_noask_sub(sd, t_sd, 3);
  8762. return;
  8763. }
  8764. guild_reqalliance(sd,t_sd);
  8765. }
  8766. /*==========================================
  8767. * ギルド同盟要求返信
  8768. *------------------------------------------*/
  8769. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  8770. {
  8771. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8772. }
  8773. /*==========================================
  8774. * ギルド関係解消
  8775. *------------------------------------------*/
  8776. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  8777. {
  8778. if(!sd->state.gmaster_flag)
  8779. return;
  8780. if(map[sd->bl.m].flag.guildlock)
  8781. { //Guild locked.
  8782. clif_displaymessage(fd, msg_txt(228));
  8783. return;
  8784. }
  8785. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8786. }
  8787. /*==========================================
  8788. * ギルド敵対
  8789. *------------------------------------------*/
  8790. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  8791. {
  8792. struct map_session_data *t_sd;
  8793. if(!sd->state.gmaster_flag)
  8794. return;
  8795. if(map[sd->bl.m].flag.guildlock)
  8796. { //Guild locked.
  8797. clif_displaymessage(fd, msg_txt(228));
  8798. return;
  8799. }
  8800. t_sd = map_id2sd(RFIFOL(fd,2));
  8801. // @noask [LuzZza]
  8802. if(t_sd && t_sd->state.noask) {
  8803. clif_noask_sub(sd, t_sd, 4);
  8804. return;
  8805. }
  8806. guild_opposition(sd,t_sd);
  8807. }
  8808. /*==========================================
  8809. * ギルド解散
  8810. *------------------------------------------*/
  8811. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  8812. {
  8813. if(map[sd->bl.m].flag.guildlock)
  8814. { //Guild locked.
  8815. clif_displaymessage(fd, msg_txt(228));
  8816. return;
  8817. }
  8818. guild_break(sd,(char*)RFIFOP(fd,2));
  8819. }
  8820. // pet
  8821. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  8822. {
  8823. pet_menu(sd,RFIFOB(fd,2));
  8824. }
  8825. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  8826. {
  8827. pet_catch_process2(sd,RFIFOL(fd,2));
  8828. }
  8829. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  8830. {
  8831. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  8832. return;
  8833. pet_select_egg(sd,RFIFOW(fd,2)-2);
  8834. sd->menuskill_val = sd->menuskill_id = 0;
  8835. }
  8836. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  8837. {
  8838. if(sd->pd)
  8839. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  8840. }
  8841. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  8842. {
  8843. pet_change_name(sd,(char*)RFIFOP(fd,2));
  8844. }
  8845. // Kick (right click menu for GM "(name) force to quit")
  8846. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  8847. {
  8848. struct block_list *target;
  8849. int tid,lv;
  8850. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8851. return;
  8852. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_kick)) )
  8853. return;
  8854. tid = RFIFOL(fd,2);
  8855. target = map_id2bl(tid);
  8856. if (!target) {
  8857. clif_GM_kickack(sd, 0);
  8858. return;
  8859. }
  8860. switch (target->type) {
  8861. case BL_PC:
  8862. {
  8863. struct map_session_data *tsd = (struct map_session_data *)target;
  8864. if (pc_isGM(sd) <= pc_isGM(tsd)) {
  8865. clif_GM_kickack(sd, 0);
  8866. return;
  8867. }
  8868. clif_GM_kick(sd, tsd, 1);
  8869. if(log_config.gm && lv >= log_config.gm) {
  8870. char message[NAME_LENGTH+6];
  8871. sprintf(message, "/kick %d", tsd->status.char_id);
  8872. log_atcommand(sd, message);
  8873. }
  8874. break;
  8875. }
  8876. case BL_MOB:
  8877. status_percent_damage(&sd->bl, target, 100, 0);
  8878. if(log_config.gm && lv >= log_config.gm) {
  8879. char message[NAME_LENGTH+16];
  8880. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  8881. log_atcommand(sd, message);
  8882. }
  8883. break;
  8884. default:
  8885. clif_GM_kickack(sd, 0);
  8886. }
  8887. }
  8888. /*==========================================
  8889. * /shift
  8890. *------------------------------------------*/
  8891. void clif_parse_Shift(int fd, struct map_session_data *sd)
  8892. {
  8893. char *player_name;
  8894. int lv;
  8895. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8896. return;
  8897. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_jumpto)) )
  8898. return;
  8899. player_name = (char*)RFIFOP(fd,2);
  8900. player_name[NAME_LENGTH-1] = '\0';
  8901. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  8902. if( log_config.gm && lv >= log_config.gm ) {
  8903. char message[NAME_LENGTH+7];
  8904. sprintf(message, "/shift %s", player_name);
  8905. log_atcommand(sd, message);
  8906. }
  8907. return;
  8908. }
  8909. /*==========================================
  8910. * /recall
  8911. *------------------------------------------*/
  8912. void clif_parse_Recall(int fd, struct map_session_data *sd)
  8913. {
  8914. char *player_name;
  8915. int lv;
  8916. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8917. return;
  8918. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_recall)) )
  8919. return;
  8920. player_name = (char*)RFIFOP(fd,2);
  8921. player_name[NAME_LENGTH-1] = '\0';
  8922. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  8923. if( log_config.gm && lv >= log_config.gm ) {
  8924. char message[NAME_LENGTH+8];
  8925. sprintf(message, "/recall %s", player_name);
  8926. log_atcommand(sd, message);
  8927. }
  8928. return;
  8929. }
  8930. /*==========================================
  8931. * /monster /item
  8932. *------------------------------------------*/
  8933. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  8934. {
  8935. char *monster_item_name;
  8936. char message[NAME_LENGTH+10]; //For logging.
  8937. int level;
  8938. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8939. return;
  8940. monster_item_name = (char*)RFIFOP(fd,2);
  8941. monster_item_name[NAME_LENGTH-1] = '\0';
  8942. if( mobdb_searchname(monster_item_name) ) {
  8943. if( pc_isGM(sd) < (level=get_atcommand_level(atcommand_monster)) )
  8944. return;
  8945. atcommand_monster(fd, sd, "@monster", monster_item_name); // as @monster
  8946. if( log_config.gm && level >= log_config.gm )
  8947. { //Log action. [Skotlex]
  8948. snprintf(message, sizeof(message)-1, "@spawn %s", monster_item_name);
  8949. log_atcommand(sd, message);
  8950. }
  8951. return;
  8952. }
  8953. if( itemdb_searchname(monster_item_name) == NULL )
  8954. return;
  8955. if( pc_isGM(sd) < (level = get_atcommand_level(atcommand_item)) )
  8956. return;
  8957. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  8958. if( log_config.gm && level >= log_config.gm )
  8959. { //Log action. [Skotlex]
  8960. sprintf(message, "@item %s", monster_item_name);
  8961. log_atcommand(sd, message);
  8962. }
  8963. }
  8964. /*==========================================
  8965. * /hide
  8966. *------------------------------------------*/
  8967. void clif_parse_GMHide(int fd, struct map_session_data *sd)
  8968. {
  8969. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8970. return;
  8971. if( pc_isGM(sd) < get_atcommand_level(atcommand_hide) )
  8972. return;
  8973. if( sd->sc.option & OPTION_INVISIBLE ) {
  8974. sd->sc.option &= ~OPTION_INVISIBLE;
  8975. if (sd->disguise)
  8976. status_set_viewdata(&sd->bl, sd->disguise);
  8977. else
  8978. status_set_viewdata(&sd->bl, sd->status.class_);
  8979. clif_displaymessage(fd, "Invisible: Off.");
  8980. } else {
  8981. sd->sc.option |= OPTION_INVISIBLE;
  8982. sd->vd.class_ = INVISIBLE_CLASS;
  8983. clif_displaymessage(fd, "Invisible: On.");
  8984. if( log_config.gm && get_atcommand_level(atcommand_hide) >= log_config.gm )
  8985. log_atcommand(sd, "/hide");
  8986. }
  8987. clif_changeoption(&sd->bl);
  8988. }
  8989. /*==========================================
  8990. * GMによるチャット禁止時間付与
  8991. *------------------------------------------*/
  8992. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  8993. {
  8994. int type, limit, level;
  8995. struct block_list *bl;
  8996. struct map_session_data *dstsd;
  8997. bl = map_id2bl(RFIFOL(fd,2));
  8998. if (!bl || bl->type != BL_PC)
  8999. return;
  9000. dstsd =(struct map_session_data *)bl;
  9001. type = RFIFOB(fd,6);
  9002. limit = RFIFOW(fd,7);
  9003. if (type == 0)
  9004. limit = 0 - limit;
  9005. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  9006. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  9007. if (type == 2/* && sd->bl.id != dstsd->bl.id*/)
  9008. return;
  9009. if (
  9010. ((level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(atcommand_mute))
  9011. || (type == 2 && !level))
  9012. {
  9013. clif_GM_silence(sd, dstsd, ((type == 2) ? 1 : type));
  9014. dstsd->status.manner -= limit;
  9015. if(dstsd->status.manner < 0)
  9016. sc_start(bl,SC_NOCHAT,100,0,0);
  9017. else
  9018. {
  9019. dstsd->status.manner = 0;
  9020. status_change_end(bl,SC_NOCHAT,-1);
  9021. }
  9022. }
  9023. return;
  9024. }
  9025. /*==========================================
  9026. * GMによるチャット禁止時間参照(?)
  9027. *------------------------------------------*/
  9028. void clif_parse_GMReqNoChatCount(int fd, struct map_session_data *sd)
  9029. {
  9030. int tid;
  9031. tid = RFIFOL(fd,2);
  9032. WFIFOHEAD(fd,packet_len(0x1e0));
  9033. WFIFOW(fd,0) = 0x1e0;
  9034. WFIFOL(fd,2) = tid;
  9035. sprintf((char*)WFIFOP(fd,6),"%d",tid);
  9036. WFIFOSET(fd, packet_len(0x1e0));
  9037. return;
  9038. }
  9039. static int pstrcmp(const void *a, const void *b)
  9040. {
  9041. char *name1 = (char *)a;
  9042. char *name2 = (char *)b;
  9043. if (name1[0] && name2[0])
  9044. return strcmp(name1, name2);
  9045. //Since names are sorted in ascending order, send blank entries to the bottom.
  9046. if (name1[0])
  9047. return -1;
  9048. if (name2[0])
  9049. return 1;
  9050. return 0;
  9051. }
  9052. void clif_parse_PMIgnore(int fd, struct map_session_data *sd)
  9053. {
  9054. char output[512];
  9055. char *nick; // S 00cf <nick>.24B <type>.B: 00 (/ex nick) deny speech from nick, 01 (/in nick) allow speech from nick
  9056. int i;
  9057. memset(output, '\0', sizeof(output));
  9058. nick = (char*)RFIFOP(fd,2); // speed up
  9059. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name have at maximum 23 characters
  9060. WFIFOHEAD(fd,packet_len(0xd1));
  9061. WFIFOW(fd,0) = 0x0d1; // R 00d1 <type>.B <result>.B: type: 0: deny, 1: allow, result: 0: success, 1: fail 2: list full
  9062. WFIFOB(fd,2) = RFIFOB(fd,26);
  9063. if (RFIFOB(fd,26) == 0)
  9064. { // Add name to ignore list (block)
  9065. // Bot-check...
  9066. if (strcmp(wisp_server_name, nick) == 0)
  9067. { // to find possible bot users who automaticaly ignore people
  9068. 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);
  9069. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9070. WFIFOB(fd,3) = 1; // fail
  9071. WFIFOSET(fd, packet_len(0x0d1));
  9072. return;
  9073. }
  9074. // try to find a free spot, while checking for duplicates at the same time
  9075. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0' && strcmp(sd->ignore[i].name, nick) != 0; i++);
  9076. if (i == MAX_IGNORE_LIST) { // no space for new entry
  9077. WFIFOB(fd,3) = 2; // fail
  9078. WFIFOSET(fd, packet_len(0x0d1));
  9079. return;
  9080. }
  9081. if(sd->ignore[i].name[0] != '\0') { // name already exists
  9082. WFIFOB(fd,3) = 0; // Aegis reports success.
  9083. WFIFOSET(fd, packet_len(0x0d1));
  9084. return;
  9085. }
  9086. //Insert in position i
  9087. memcpy(sd->ignore[i].name, nick, NAME_LENGTH);
  9088. WFIFOB(fd,3) = 0; // success
  9089. WFIFOSET(fd, packet_len(0x0d1));
  9090. //Sort the ignore list.
  9091. //FIXME: why not just use a simple shift-and-insert scheme instead? [ultramage]
  9092. qsort (sd->ignore[0].name, MAX_IGNORE_LIST, sizeof(sd->ignore[0].name), pstrcmp);
  9093. }
  9094. else
  9095. { // Remove name from ignore list (unblock)
  9096. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0' && strcmp(sd->ignore[i].name, nick) != 0; i++);
  9097. if (i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0') { //Not found
  9098. WFIFOB(fd,3) = 1; // fail
  9099. WFIFOSET(fd, packet_len(0x0d1));
  9100. return;
  9101. }
  9102. //Move everything one place down to overwrite removed entry.
  9103. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  9104. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  9105. WFIFOB(fd,3) = 0; // success
  9106. WFIFOSET(fd, packet_len(0x0d1));
  9107. }
  9108. //for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9109. // ShowDebug("Ignored player: '%s'\n", sd->ignore[i].name);
  9110. return;
  9111. }
  9112. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  9113. {
  9114. //printf("Ignore all: state: %d\n", RFIFOB(fd,2));
  9115. // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9116. // S 00d0 <type>len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech
  9117. WFIFOHEAD(fd,packet_len(0xd2));
  9118. WFIFOW(fd,0) = 0x0d2;
  9119. WFIFOB(fd,2) = RFIFOB(fd,2);
  9120. if (RFIFOB(fd,2) == 0) { //Deny all
  9121. if (sd->state.ignoreAll) {
  9122. WFIFOB(fd,3) = 1; // fail
  9123. WFIFOSET(fd, packet_len(0x0d2));
  9124. return;
  9125. }
  9126. sd->state.ignoreAll = 1;
  9127. WFIFOB(fd,3) = 0; // success
  9128. WFIFOSET(fd, packet_len(0x0d2));
  9129. return;
  9130. }
  9131. //Unblock everyone
  9132. if (!sd->state.ignoreAll) {
  9133. if (sd->ignore[0].name[0] != '\0')
  9134. { //Wipe the ignore list.
  9135. memset(sd->ignore, 0, sizeof(sd->ignore));
  9136. WFIFOB(fd,3) = 0;
  9137. WFIFOSET(fd, packet_len(0x0d2));
  9138. return;
  9139. }
  9140. WFIFOB(fd,3) = 1; // fail
  9141. WFIFOSET(fd, packet_len(0x0d2));
  9142. return;
  9143. }
  9144. sd->state.ignoreAll = 0;
  9145. WFIFOB(fd,3) = 0; // success
  9146. WFIFOSET(fd, packet_len(0x0d2));
  9147. return;
  9148. }
  9149. /*==========================================
  9150. * Wis拒否リスト
  9151. *------------------------------------------*/
  9152. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9153. {
  9154. int i;
  9155. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  9156. WFIFOW(fd,0) = 0xd4;
  9157. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9158. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  9159. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  9160. WFIFOSET(fd, WFIFOW(fd,2));
  9161. return;
  9162. }
  9163. /*==========================================
  9164. * スパノビの/doridoriによるSPR2倍
  9165. *------------------------------------------*/
  9166. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  9167. {
  9168. if (sd->state.doridori) return;
  9169. switch (sd->class_&MAPID_UPPERMASK)
  9170. {
  9171. case MAPID_SOUL_LINKER:
  9172. case MAPID_STAR_GLADIATOR:
  9173. case MAPID_TAEKWON:
  9174. if (!sd->state.rest)
  9175. break;
  9176. case MAPID_SUPER_NOVICE:
  9177. sd->state.doridori=1;
  9178. break;
  9179. }
  9180. return;
  9181. }
  9182. /*==========================================
  9183. * スパノビの爆裂波動
  9184. *------------------------------------------*/
  9185. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9186. {
  9187. if(sd){
  9188. int nextbaseexp=pc_nextbaseexp(sd);
  9189. if (battle_config.etc_log){
  9190. if(nextbaseexp != 0)
  9191. 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));
  9192. else
  9193. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9194. }
  9195. 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){
  9196. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9197. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  9198. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9199. }
  9200. }
  9201. return;
  9202. }
  9203. // random notes:
  9204. // 0x214: monster/player info ?
  9205. /*==========================================
  9206. * Friends List
  9207. *------------------------------------------*/
  9208. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9209. { //Toggles a single friend online/offline [Skotlex]
  9210. int i, fd = sd->fd;
  9211. //Seek friend.
  9212. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9213. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9214. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9215. return; //Not found
  9216. WFIFOHEAD(fd,packet_len(0x206));
  9217. WFIFOW(fd, 0) = 0x206;
  9218. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  9219. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  9220. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9221. WFIFOSET(fd, packet_len(0x206));
  9222. }
  9223. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9224. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9225. {
  9226. int account_id, char_id, online;
  9227. account_id = va_arg(ap, int);
  9228. char_id = va_arg(ap, int);
  9229. online = va_arg(ap, int);
  9230. clif_friendslist_toggle(sd, account_id, char_id, online);
  9231. return 0;
  9232. }
  9233. //For sending the whole friends list.
  9234. void clif_friendslist_send(struct map_session_data *sd)
  9235. {
  9236. int i = 0, n, fd = sd->fd;
  9237. // Send friends list
  9238. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  9239. WFIFOW(fd, 0) = 0x201;
  9240. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9241. {
  9242. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9243. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9244. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9245. }
  9246. if (i) {
  9247. WFIFOW(fd,2) = 4 + 32 * i;
  9248. WFIFOSET(fd, WFIFOW(fd,2));
  9249. }
  9250. for (n = 0; n < i; n++)
  9251. { //Sending the online players
  9252. if (map_charid2sd(sd->status.friends[n].char_id))
  9253. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9254. }
  9255. }
  9256. /// Reply for add friend request: (success => type 0)
  9257. /// type=0 : MsgStringTable[821]="You have become friends with (%s)."
  9258. /// type=1 : MsgStringTable[822]="(%s) does not want to be friends with you."
  9259. /// type=2 : MsgStringTable[819]="Your Friend List is full."
  9260. /// type=3 : MsgStringTable[820]="(%s)'s Friend List is full."
  9261. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9262. {
  9263. int fd;
  9264. nullpo_retv(sd);
  9265. fd = sd->fd;
  9266. WFIFOHEAD(fd,packet_len(0x209));
  9267. WFIFOW(fd,0) = 0x209;
  9268. WFIFOW(fd,2) = type;
  9269. if (f_sd)
  9270. {
  9271. WFIFOW(fd,4) = f_sd->status.account_id;
  9272. WFIFOW(fd,8) = f_sd->status.char_id;
  9273. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9274. }
  9275. WFIFOSET(fd, packet_len(0x209));
  9276. }
  9277. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  9278. {
  9279. struct map_session_data *f_sd;
  9280. int i, f_fd;
  9281. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9282. // Friend doesn't exist (no player with this name)
  9283. if (f_sd == NULL) {
  9284. clif_displaymessage(fd, msg_txt(3));
  9285. return;
  9286. }
  9287. // @noask [LuzZza]
  9288. if(f_sd->state.noask) {
  9289. clif_noask_sub(sd, f_sd, 5);
  9290. return;
  9291. }
  9292. // Friend already exists
  9293. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9294. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9295. clif_displaymessage(fd, "Friend already exists.");
  9296. return;
  9297. }
  9298. }
  9299. if (i == MAX_FRIENDS) {
  9300. //No space, list full.
  9301. clif_friendslist_reqack(sd, f_sd, 2);
  9302. return;
  9303. }
  9304. f_fd = f_sd->fd;
  9305. WFIFOHEAD(f_fd,packet_len(0x207));
  9306. WFIFOW(f_fd,0) = 0x207;
  9307. WFIFOL(f_fd,2) = sd->status.account_id;
  9308. WFIFOL(f_fd,6) = sd->status.char_id;
  9309. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9310. WFIFOSET(f_fd, packet_len(0x207));
  9311. return;
  9312. }
  9313. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  9314. {
  9315. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9316. struct map_session_data *f_sd;
  9317. int char_id, account_id;
  9318. char reply;
  9319. account_id = RFIFOL(fd,2);
  9320. char_id = RFIFOL(fd,6);
  9321. reply = RFIFOB(fd,10);
  9322. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9323. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9324. if (f_sd == NULL)
  9325. return;
  9326. if (reply == 0)
  9327. clif_friendslist_reqack(f_sd, sd, 1);
  9328. else {
  9329. int i;
  9330. // Find an empty slot
  9331. for (i = 0; i < MAX_FRIENDS; i++)
  9332. if (f_sd->status.friends[i].char_id == 0)
  9333. break;
  9334. if (i == MAX_FRIENDS) {
  9335. clif_friendslist_reqack(f_sd, sd, 2);
  9336. return;
  9337. }
  9338. f_sd->status.friends[i].account_id = sd->status.account_id;
  9339. f_sd->status.friends[i].char_id = sd->status.char_id;
  9340. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9341. clif_friendslist_reqack(f_sd, sd, 0);
  9342. if (battle_config.friend_auto_add) {
  9343. // Also add f_sd to sd's friendlist.
  9344. for (i = 0; i < MAX_FRIENDS; i++) {
  9345. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  9346. return; //No need to add anything.
  9347. if (sd->status.friends[i].char_id == 0)
  9348. break;
  9349. }
  9350. if (i == MAX_FRIENDS) {
  9351. clif_friendslist_reqack(sd, f_sd, 2);
  9352. return;
  9353. }
  9354. sd->status.friends[i].account_id = f_sd->status.account_id;
  9355. sd->status.friends[i].char_id = f_sd->status.char_id;
  9356. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  9357. clif_friendslist_reqack(sd, f_sd, 0);
  9358. }
  9359. }
  9360. return;
  9361. }
  9362. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  9363. {
  9364. // 0x203 </o> <ID to be removed W 4B>
  9365. int account_id, char_id;
  9366. int i, j;
  9367. account_id = RFIFOL(fd,2);
  9368. char_id = RFIFOL(fd,6);
  9369. // Search friend
  9370. for (i = 0; i < MAX_FRIENDS &&
  9371. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9372. if (i == MAX_FRIENDS) {
  9373. clif_displaymessage(fd, "Name not found in list.");
  9374. return;
  9375. }
  9376. // move all chars down
  9377. for(j = i + 1; j < MAX_FRIENDS; j++)
  9378. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9379. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9380. clif_displaymessage(fd, "Friend removed");
  9381. WFIFOHEAD(fd,packet_len(0x20a));
  9382. WFIFOW(fd,0) = 0x20a;
  9383. WFIFOL(fd,2) = account_id;
  9384. WFIFOL(fd,6) = char_id;
  9385. WFIFOSET(fd, packet_len(0x20a));
  9386. // clif_friendslist_send(sd); //This is not needed anymore.
  9387. return;
  9388. }
  9389. /*==========================================
  9390. * /killall
  9391. *------------------------------------------*/
  9392. void clif_parse_GMKillAll(int fd, struct map_session_data* sd)
  9393. {
  9394. is_atcommand(fd, sd, "@kickall");
  9395. }
  9396. /*==========================================
  9397. * /pvpinfo
  9398. *------------------------------------------*/
  9399. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  9400. {
  9401. WFIFOHEAD(fd,packet_len(0x210));
  9402. WFIFOW(fd,0) = 0x210;
  9403. //WFIFOL(fd,2) = 0; // not sure what for yet
  9404. //WFIFOL(fd,6) = 0;
  9405. WFIFOL(fd,10) = sd->pvp_won; // times won
  9406. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  9407. WFIFOL(fd,18) = sd->pvp_point;
  9408. WFIFOSET(fd, packet_len(0x210));
  9409. return;
  9410. }
  9411. /*==========================================
  9412. * /blacksmith
  9413. *------------------------------------------*/
  9414. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  9415. {
  9416. int i;
  9417. const char* name;
  9418. WFIFOHEAD(fd,packet_len(0x219));
  9419. WFIFOW(fd,0) = 0x219;
  9420. //Packet size limits this list to 10 elements. [Skotlex]
  9421. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9422. if (smith_fame_list[i].id > 0) {
  9423. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  9424. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  9425. {
  9426. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  9427. } else
  9428. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  9429. } else
  9430. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  9431. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  9432. }
  9433. for(;i < 10; i++) { //In case the MAX is less than 10.
  9434. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  9435. WFIFOL(fd, 242 + i * 4) = 0;
  9436. }
  9437. WFIFOSET(fd, packet_len(0x219));
  9438. }
  9439. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  9440. {
  9441. int fd = sd->fd;
  9442. WFIFOHEAD(fd,packet_len(0x21b));
  9443. WFIFOW(fd,0) = 0x21b;
  9444. WFIFOL(fd,2) = points;
  9445. WFIFOL(fd,6) = sd->status.fame;
  9446. WFIFOSET(fd, packet_len(0x21b));
  9447. return 0;
  9448. }
  9449. /*==========================================
  9450. * /alchemist
  9451. *------------------------------------------*/
  9452. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  9453. {
  9454. int i;
  9455. const char* name;
  9456. WFIFOHEAD(fd,packet_len(0x21a));
  9457. WFIFOW(fd,0) = 0x21a;
  9458. //Packet size limits this list to 10 elements. [Skotlex]
  9459. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9460. if (chemist_fame_list[i].id > 0) {
  9461. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  9462. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  9463. {
  9464. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9465. } else
  9466. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  9467. } else
  9468. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9469. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  9470. }
  9471. for(;i < 10; i++) { //In case the MAX is less than 10.
  9472. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9473. WFIFOL(fd, 242 + i * 4) = 0;
  9474. }
  9475. WFIFOSET(fd, packet_len(0x21a));
  9476. }
  9477. int clif_fame_alchemist(struct map_session_data *sd, int points)
  9478. {
  9479. int fd = sd->fd;
  9480. WFIFOHEAD(fd,packet_len(0x21c));
  9481. WFIFOW(fd,0) = 0x21c;
  9482. WFIFOL(fd,2) = points;
  9483. WFIFOL(fd,6) = sd->status.fame;
  9484. WFIFOSET(fd, packet_len(0x21c));
  9485. return 0;
  9486. }
  9487. /*==========================================
  9488. * /taekwon
  9489. *------------------------------------------*/
  9490. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  9491. {
  9492. int i;
  9493. const char* name;
  9494. WFIFOHEAD(fd,packet_len(0x226));
  9495. WFIFOW(fd,0) = 0x226;
  9496. //Packet size limits this list to 10 elements. [Skotlex]
  9497. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9498. if (taekwon_fame_list[i].id > 0) {
  9499. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  9500. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  9501. {
  9502. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9503. } else
  9504. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  9505. } else
  9506. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9507. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  9508. }
  9509. for(;i < 10; i++) { //In case the MAX is less than 10.
  9510. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9511. WFIFOL(fd, 242 + i * 4) = 0;
  9512. }
  9513. WFIFOSET(fd, packet_len(0x226));
  9514. }
  9515. int clif_fame_taekwon(struct map_session_data *sd, int points)
  9516. {
  9517. int fd = sd->fd;
  9518. WFIFOHEAD(fd,packet_len(0x224));
  9519. WFIFOW(fd,0) = 0x224;
  9520. WFIFOL(fd,2) = points;
  9521. WFIFOL(fd,6) = sd->status.fame;
  9522. WFIFOSET(fd, packet_len(0x224));
  9523. return 0;
  9524. }
  9525. /*==========================================
  9526. * PK Ranking table?
  9527. *------------------------------------------*/
  9528. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  9529. {
  9530. int i;
  9531. WFIFOHEAD(fd,packet_len(0x238));
  9532. WFIFOW(fd,0) = 0x238;
  9533. for(i=0;i<10;i++){
  9534. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  9535. WFIFOL(fd,i*4+242) = 0;
  9536. }
  9537. WFIFOSET(fd, packet_len(0x238));
  9538. return;
  9539. }
  9540. /*==========================================
  9541. * SG Feel save OK [Komurka]
  9542. *------------------------------------------*/
  9543. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  9544. {
  9545. int i;
  9546. if (sd->menuskill_id != SG_FEEL)
  9547. return;
  9548. i = sd->menuskill_val-1;
  9549. if (i<0 || i > 2) return; //Bug?
  9550. sd->feel_map[i].index = map_id2index(sd->bl.m);
  9551. sd->feel_map[i].m = sd->bl.m;
  9552. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  9553. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  9554. // clif_misceffect2(&sd->bl, 0x1b0);
  9555. // clif_misceffect2(&sd->bl, 0x21f);
  9556. clif_feel_info(sd, i, 0);
  9557. sd->menuskill_val = sd->menuskill_id = 0;
  9558. }
  9559. /*==========================================
  9560. * Question about Star Glaldiator save map [Komurka]
  9561. *------------------------------------------*/
  9562. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv)
  9563. {
  9564. WFIFOHEAD(fd,packet_len(0x253));
  9565. WFIFOW(fd,0)=0x253;
  9566. WFIFOSET(fd, packet_len(0x253));
  9567. sd->menuskill_id = SG_FEEL;
  9568. sd->menuskill_val = skilllv;
  9569. }
  9570. void clif_parse_AdoptRequest(int fd,struct map_session_data *sd)
  9571. {
  9572. //TODO: add somewhere the adopt code, checks for exploits, etc, etc.
  9573. //Missing packets are the client's reply packets to the adopt request one.
  9574. //[Skotlex]
  9575. int account_id;
  9576. struct map_session_data *sd2;
  9577. account_id = RFIFOL(fd,2);
  9578. sd2 = map_id2sd(account_id);
  9579. if(sd2 && sd2->fd && sd2 != sd && sd2->status.party_id == sd->status.party_id) { //FIXME: No checks whatsoever are in place yet!
  9580. fd = sd2->fd;
  9581. WFIFOHEAD(fd,packet_len(0x1f9));
  9582. WFIFOW(fd,0)=0x1f9;
  9583. WFIFOSET(fd, packet_len(0x1f9));
  9584. }
  9585. }
  9586. /*==========================================
  9587. * Homunculus packets
  9588. *------------------------------------------*/
  9589. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  9590. {
  9591. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  9592. }
  9593. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  9594. {
  9595. if(!merc_is_hom_active(sd->hd))
  9596. return;
  9597. unit_walktoxy(&sd->hd->bl, sd->bl.x,sd->bl.y-1, 4);
  9598. }
  9599. void clif_parse_HomMoveTo(int fd,struct map_session_data *sd)
  9600. {
  9601. short x,y,cmd;
  9602. if(!merc_is_hom_active(sd->hd))
  9603. return;
  9604. cmd = RFIFOW(fd,0);
  9605. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  9606. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  9607. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  9608. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  9609. unit_walktoxy(&(sd->hd->bl),x,y,4);
  9610. }
  9611. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  9612. { //[orn]
  9613. if(!merc_is_hom_active(sd->hd))
  9614. return;
  9615. unit_attack(&sd->hd->bl,RFIFOL(fd,6),0) ;
  9616. }
  9617. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  9618. { //[orn]
  9619. int cmd;
  9620. cmd = RFIFOW(fd,0);
  9621. if(!merc_is_hom_active(sd->hd))
  9622. return;
  9623. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  9624. }
  9625. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  9626. {
  9627. int item_position = pc_search_inventory(sd, 7621);
  9628. if (item_position < 0)
  9629. return;
  9630. if (!status_revive(&sd->bl, 100, 100))
  9631. return;
  9632. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  9633. pc_delitem(sd, item_position, 1, 0);
  9634. }
  9635. #ifndef TXT_ONLY
  9636. /*==========================================
  9637. * MAIL SYSTEM
  9638. * By Zephyrus
  9639. *==========================================*/
  9640. /*------------------------------------------
  9641. * Reply to Set Attachment operation
  9642. * 0 : Successfully attached item to mail
  9643. * 1 : Fail to set the attachment
  9644. *------------------------------------------*/
  9645. static void clif_Mail_setattachment(int fd, int index, uint8 flag)
  9646. {
  9647. WFIFOHEAD(fd,packet_len(0x255));
  9648. WFIFOW(fd,0) = 0x255;
  9649. WFIFOW(fd,2) = index;
  9650. WFIFOB(fd,4) = flag;
  9651. WFIFOSET(fd,packet_len(0x255));
  9652. }
  9653. /*------------------------------------------
  9654. * Reply to Get Attachment operation
  9655. * 0 : Successfully added attachment to Inventory
  9656. * 1 : Fail to set the item to inventory
  9657. * 2 : Weight problems
  9658. *------------------------------------------*/
  9659. void clif_Mail_getattachment(int fd, uint8 flag)
  9660. {
  9661. WFIFOHEAD(fd,packet_len(0x245));
  9662. WFIFOW(fd,0) = 0x245;
  9663. WFIFOB(fd,2) = flag;
  9664. WFIFOSET(fd,packet_len(0x245));
  9665. }
  9666. /*------------------------------------------
  9667. * Send Mail ack
  9668. * 0 : Message Send Ok
  9669. * 1 : Recipient does not exist
  9670. *------------------------------------------*/
  9671. void clif_Mail_send(int fd, bool fail)
  9672. {
  9673. WFIFOHEAD(fd,packet_len(0x249));
  9674. WFIFOW(fd,0) = 0x249;
  9675. WFIFOB(fd,2) = fail;
  9676. WFIFOSET(fd,packet_len(0x249));
  9677. }
  9678. /*------------------------------------------
  9679. * Delete Mail ack
  9680. * 0 : Delete ok
  9681. * 1 : Delete failed
  9682. *------------------------------------------*/
  9683. void clif_Mail_delete(int fd, int mail_id, short fail)
  9684. {
  9685. WFIFOHEAD(fd, packet_len(0x257));
  9686. WFIFOW(fd,0) = 0x257;
  9687. WFIFOL(fd,2) = mail_id;
  9688. WFIFOW(fd,6) = fail;
  9689. WFIFOSET(fd, packet_len(0x257));
  9690. }
  9691. /*------------------------------------------
  9692. * Return Mail ack
  9693. * 0 : Mail returned to the sender
  9694. * 1 : The mail does not exist
  9695. *------------------------------------------*/
  9696. void clif_Mail_return(int fd, int mail_id, short fail)
  9697. {
  9698. WFIFOHEAD(fd,packet_len(0x274));
  9699. WFIFOW(fd,0) = 0x274;
  9700. WFIFOL(fd,2) = mail_id;
  9701. WFIFOW(fd,6) = fail;
  9702. WFIFOSET(fd,packet_len(0x274));
  9703. }
  9704. /*------------------------------------------
  9705. * You have New Mail
  9706. *------------------------------------------*/
  9707. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  9708. {
  9709. WFIFOHEAD(fd,packet_len(0x24a));
  9710. WFIFOW(fd,0) = 0x24a;
  9711. WFIFOL(fd,2) = mail_id;
  9712. safestrncpy((char*)WFIFOP(fd,6), sender, NAME_LENGTH);
  9713. safestrncpy((char*)WFIFOP(fd,30), title, MAIL_TITLE_LENGTH);
  9714. WFIFOSET(fd,packet_len(0x24a));
  9715. }
  9716. /*------------------------------------------
  9717. * Opens Mail Window on Client
  9718. *------------------------------------------*/
  9719. void clif_Mail_openmail(int fd)
  9720. {
  9721. WFIFOHEAD(fd,packet_len(0x260));
  9722. WFIFOW(fd,0) = 0x260;
  9723. WFIFOL(fd,2) = 0;
  9724. WFIFOSET(fd,packet_len(0x260));
  9725. }
  9726. /*------------------------------------------
  9727. * Send Inbox Data to Client
  9728. *------------------------------------------*/
  9729. void clif_Mail_refreshinbox(struct map_session_data *sd)
  9730. {
  9731. int fd = sd->fd;
  9732. struct mail_data *md = &sd->mail.inbox;
  9733. struct mail_message *msg;
  9734. int len, i, j;
  9735. len = 8 + (73 * md->amount);
  9736. WFIFOHEAD(fd,len);
  9737. WFIFOW(fd,0) = 0x240;
  9738. WFIFOW(fd,2) = len;
  9739. WFIFOL(fd,4) = md->amount;
  9740. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  9741. {
  9742. msg = &md->msg[i];
  9743. if (msg->id < 1)
  9744. continue;
  9745. WFIFOL(fd,8+73*j) = msg->id;
  9746. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  9747. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD); // 0: unread, 1: read
  9748. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  9749. WFIFOL(fd,77+73*j) = msg->timestamp;
  9750. j++;
  9751. }
  9752. WFIFOSET(fd,len);
  9753. }
  9754. /*------------------------------------------
  9755. * Client Request Inbox List
  9756. *------------------------------------------*/
  9757. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  9758. {
  9759. struct mail_data* md = &sd->mail.inbox;
  9760. if( md->amount < MAIL_MAX_INBOX && (md->full || md->changed) )
  9761. intif_Mail_requestinbox(sd->status.char_id, 1);
  9762. else
  9763. clif_Mail_refreshinbox(sd);
  9764. mail_removeitem(sd, 0);
  9765. mail_removezeny(sd, 0);
  9766. }
  9767. /*------------------------------------------
  9768. * Read Message
  9769. *------------------------------------------*/
  9770. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  9771. {
  9772. int i, fd = sd->fd;
  9773. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  9774. if( i == MAIL_MAX_INBOX )
  9775. {
  9776. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  9777. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  9778. return;
  9779. }
  9780. else
  9781. {
  9782. struct mail_message *msg = &sd->mail.inbox.msg[i];
  9783. struct item *item = &msg->item;
  9784. struct item_data *data;
  9785. int msg_len = strlen(msg->body), len;
  9786. if( msg_len == 0 ) {
  9787. strcpy(msg->body, "(no message)");
  9788. msg_len = strlen(msg->body);
  9789. }
  9790. len = 101 + msg_len;
  9791. WFIFOHEAD(fd,len);
  9792. WFIFOW(fd,0) = 0x242;
  9793. WFIFOW(fd,2) = len;
  9794. WFIFOL(fd,4) = msg->id;
  9795. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  9796. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  9797. WFIFOL(fd,72) = 0;
  9798. WFIFOL(fd,76) = msg->zeny;
  9799. if( item->nameid && (data = itemdb_search(item->nameid)) != NULL )
  9800. {
  9801. WFIFOL(fd,80) = item->amount;
  9802. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  9803. WFIFOW(fd,86) = data->type;
  9804. WFIFOB(fd,88) = item->identify;
  9805. WFIFOB(fd,89) = item->attribute;
  9806. WFIFOB(fd,90) = item->refine;
  9807. WFIFOW(fd,91) = item->card[0];
  9808. WFIFOW(fd,93) = item->card[1];
  9809. WFIFOW(fd,95) = item->card[2];
  9810. WFIFOW(fd,97) = item->card[3];
  9811. }
  9812. else // no item, set all to zero
  9813. memset(WFIFOP(fd,80), 0x00, 19);
  9814. WFIFOB(fd,99) = (unsigned char)msg_len;
  9815. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  9816. WFIFOSET(fd,len);
  9817. if (msg->status == MAIL_UNREAD) {
  9818. msg->status = MAIL_READ;
  9819. intif_Mail_read(mail_id);
  9820. clif_parse_Mail_refreshinbox(fd, sd);
  9821. }
  9822. }
  9823. }
  9824. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  9825. {
  9826. clif_Mail_read(sd, RFIFOL(fd,2));
  9827. }
  9828. /*------------------------------------------
  9829. * Get Attachment from Message
  9830. *------------------------------------------*/
  9831. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  9832. {
  9833. int i, mail_id = RFIFOL(fd,2);
  9834. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  9835. if( i == MAIL_MAX_INBOX )
  9836. return;
  9837. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  9838. return;
  9839. if( sd->mail.inbox.msg[i].item.nameid > 0 )
  9840. {
  9841. struct item_data *data;
  9842. unsigned int weight;
  9843. if ((data = itemdb_search(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  9844. return;
  9845. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  9846. if (weight > sd->max_weight - sd->weight)
  9847. {
  9848. clif_Mail_getattachment(fd, 2);
  9849. return;
  9850. }
  9851. }
  9852. sd->mail.inbox.msg[i].zeny = 0;
  9853. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  9854. clif_Mail_read(sd, mail_id);
  9855. intif_Mail_getattach(sd->status.char_id, mail_id);
  9856. }
  9857. /*------------------------------------------
  9858. * Delete Message
  9859. *------------------------------------------*/
  9860. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  9861. {
  9862. int i, mail_id = RFIFOL(fd,2);
  9863. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  9864. if (i < MAIL_MAX_INBOX)
  9865. {
  9866. struct mail_message *msg = &sd->mail.inbox.msg[i];
  9867. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 )
  9868. {// can't delete mail without removing attachment first
  9869. clif_Mail_delete(sd->fd, mail_id, 1);
  9870. return;
  9871. }
  9872. intif_Mail_delete(sd->status.char_id, mail_id);
  9873. }
  9874. }
  9875. /*------------------------------------------
  9876. * Return Mail Message
  9877. *------------------------------------------*/
  9878. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  9879. {
  9880. int i, mail_id = RFIFOL(fd,2);
  9881. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  9882. if (i < MAIL_MAX_INBOX)
  9883. intif_Mail_return(sd->status.char_id, mail_id);
  9884. else
  9885. clif_Mail_return(sd->fd, mail_id, 1);
  9886. }
  9887. /*------------------------------------------
  9888. * Set Attachment
  9889. *------------------------------------------*/
  9890. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  9891. {
  9892. int idx = RFIFOW(fd,2);
  9893. int amount = RFIFOL(fd,4);
  9894. unsigned char flag;
  9895. if (idx < 0 || amount < 0)
  9896. return;
  9897. flag = mail_setitem(sd, idx, amount);
  9898. if (idx > 0)
  9899. clif_Mail_setattachment(fd,idx,flag);
  9900. }
  9901. /*------------------------------------------
  9902. * Mail Window Operation
  9903. * 0 : Switch to 'new mail' window, or Close mailbox
  9904. * 1 : ???
  9905. * 2 : ???
  9906. *------------------------------------------*/
  9907. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  9908. {
  9909. int flag = RFIFOW(fd,2);
  9910. if (flag == 0 || flag == 1)
  9911. mail_removeitem(sd, 0);
  9912. if (flag == 0 || flag == 2)
  9913. mail_removezeny(sd, 0);
  9914. }
  9915. /*------------------------------------------
  9916. * Send Mail
  9917. * S 0248 <packet len>.w <nick>.24B <title>.40B <body len>.B <message>.?B 00
  9918. *------------------------------------------*/
  9919. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  9920. {
  9921. struct mail_message msg;
  9922. int body_len;
  9923. if( sd->state.trading )
  9924. return;
  9925. if( RFIFOW(fd,2) < 69 ) {
  9926. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  9927. return;
  9928. }
  9929. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 )
  9930. {
  9931. clif_displaymessage(sd->fd,"Cannot send mails too fast!!.");
  9932. clif_Mail_send(fd, 1); // fail
  9933. return;
  9934. }
  9935. body_len = RFIFOB(fd,68);
  9936. if (body_len > MAIL_BODY_LENGTH)
  9937. body_len = MAIL_BODY_LENGTH;
  9938. if( !mail_setattachment(sd, &msg) )
  9939. { // Invalid Append condition
  9940. clif_Mail_send(sd->fd, 1); // fail
  9941. mail_removeitem(sd,0);
  9942. mail_removezeny(sd,0);
  9943. return;
  9944. }
  9945. msg.id = 0; // id will be assigned by charserver
  9946. msg.send_id = sd->status.char_id;
  9947. msg.dest_id = 0; // will attempt to resolve name
  9948. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  9949. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  9950. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  9951. if (body_len)
  9952. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  9953. else
  9954. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  9955. msg.timestamp = (int)mail_calctimes();
  9956. if( !intif_Mail_send(sd->status.account_id, &msg) )
  9957. mail_deliveryfail(sd, &msg);
  9958. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  9959. }
  9960. #endif
  9961. /*==========================================
  9962. * パケットデバッグ
  9963. *------------------------------------------*/
  9964. void clif_parse_debug(int fd,struct map_session_data *sd)
  9965. {
  9966. int i, cmd, len;
  9967. cmd = RFIFOW(fd,0);
  9968. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  9969. ShowDebug("packet debug 0x%4X\n",cmd);
  9970. ShowMessage("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  9971. for(i=0;i<len;i++){
  9972. if((i&15)==0)
  9973. ShowMessage("\n%04X ",i);
  9974. ShowMessage("%02X ",RFIFOB(fd,i));
  9975. }
  9976. ShowMessage("\n");
  9977. }
  9978. /*==========================================
  9979. * Main client packet processing function
  9980. *------------------------------------------*/
  9981. int clif_parse(int fd)
  9982. {
  9983. int cmd, packet_ver, packet_len, err;
  9984. TBL_PC* sd;
  9985. int pnum;
  9986. //TODO apply deplays or disconnect based on packet throughput [FlavioJS]
  9987. // Note: "click masters" can do 80+ clicks in 10 seconds
  9988. for( pnum = 0; pnum < 3; ++pnum )// Limit max packets per cycle to 3 (delay packet spammers) [FlavioJS]
  9989. { // begin main client packet processing loop
  9990. sd = (TBL_PC *)session[fd]->session_data;
  9991. if (session[fd]->flag.eof) {
  9992. if (sd) {
  9993. if (sd->state.autotrade) {
  9994. //Disassociate character from the socket connection.
  9995. session[fd]->session_data = NULL;
  9996. sd->fd = 0;
  9997. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  9998. } else
  9999. if (sd->state.auth) {
  10000. // Player logout display [Valaris]
  10001. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  10002. clif_quitsave(fd, sd);
  10003. } else {
  10004. ShowInfo("Player AID:%d/CID:%d (not authenticated) logged off.\n", sd->bl.id, sd->status.char_id);
  10005. map_quit(sd);
  10006. }
  10007. } else {
  10008. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  10009. }
  10010. do_close(fd);
  10011. return 0;
  10012. }
  10013. if (RFIFOREST(fd) < 2)
  10014. return 0;
  10015. cmd = RFIFOW(fd,0);
  10016. // identify client's packet version
  10017. if (sd) {
  10018. packet_ver = sd->packet_ver;
  10019. } else {
  10020. // check authentification packet to know packet version
  10021. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  10022. if( err )
  10023. {// failed to identify packet version
  10024. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  10025. err == 1 ? "" :
  10026. err == 2 ? ", possibly for having an invalid account_id" :
  10027. err == 3 ? ", possibly for having an invalid char_id." :
  10028. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  10029. err == 4 ? ", possibly for having an invalid login_id1." :
  10030. err == 5 ? ", possibly for having an invalid client_tick." :
  10031. */
  10032. err == 6 ? ", possibly for having an invalid sex." :
  10033. ". ERROR invalid error code"));
  10034. WFIFOHEAD(fd,packet_len(0x6a));
  10035. WFIFOW(fd,0) = 0x6a;
  10036. WFIFOB(fd,2) = 3; // Rejected from Server
  10037. WFIFOSET(fd,packet_len(0x6a));
  10038. RFIFOSKIP(fd, RFIFOREST(fd));
  10039. clif_setwaitclose(fd);
  10040. return 0;
  10041. }
  10042. }
  10043. // filter out invalid / unsupported packets
  10044. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  10045. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  10046. set_eof(fd);
  10047. return 0;
  10048. }
  10049. // determine real packet length
  10050. packet_len = packet_db[packet_ver][cmd].len;
  10051. if (packet_len == -1) { // variable-length packet
  10052. if (RFIFOREST(fd) < 4)
  10053. return 0;
  10054. packet_len = RFIFOW(fd,2);
  10055. if (packet_len < 4 || packet_len > 32768) {
  10056. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  10057. set_eof(fd);
  10058. return 0;
  10059. }
  10060. }
  10061. if ((int)RFIFOREST(fd) < packet_len)
  10062. return 0; // not enough data received to form the packet
  10063. if (sd && sd->state.waitingdisconnect == 1) {
  10064. // 切断待ちの場合パケットを処理しない
  10065. } else
  10066. if (packet_db[packet_ver][cmd].func) {
  10067. if (sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck)
  10068. ; //Only valid packet when player is not on a map is the finish-loading packet.
  10069. else
  10070. if (sd
  10071. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  10072. || packet_db[packet_ver][cmd].func == clif_parse_debug
  10073. ) //Only execute the function when there's an sd (except for debug/wanttoconnect packets)
  10074. packet_db[packet_ver][cmd].func(fd, sd);
  10075. }
  10076. #if DUMP_UNKNOWN_PACKET
  10077. else if (battle_config.error_log)
  10078. {
  10079. int i;
  10080. FILE *fp;
  10081. char packet_txt[256] = "save/packet.txt";
  10082. time_t now;
  10083. dump = 1;
  10084. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10085. ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
  10086. return 1;
  10087. } else {
  10088. time(&now);
  10089. if (sd && sd->state.auth) {
  10090. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  10091. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10092. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10093. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10094. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10095. for(i = 0; i < packet_len; i++) {
  10096. if ((i & 15) == 0)
  10097. fprintf(fp, "\n\t%04X ", i);
  10098. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10099. }
  10100. fprintf(fp, "\n\n");
  10101. fclose(fp);
  10102. }
  10103. }
  10104. #endif
  10105. /* TODO: use utils.c :: dump()
  10106. if (dump) {
  10107. int i;
  10108. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10109. ShowMessage("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10110. for(i = 0; i < packet_len; i++) {
  10111. if ((i & 15) == 0)
  10112. ShowMessage("\n%04X ",i);
  10113. ShowMessage("%02X ", RFIFOB(fd,i));
  10114. }
  10115. ShowMessage("\n");
  10116. if (sd && sd->state.auth) {
  10117. if (sd->status.name != NULL)
  10118. ShowMessage("\nAccount ID %d, character ID %d, player name %s.\n",
  10119. sd->status.account_id, sd->status.char_id, sd->status.name);
  10120. else
  10121. ShowMessage("\nAccount ID %d.\n", sd->bl.id);
  10122. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10123. ShowMessage("\nAccount ID %d.\n", sd->bl.id);
  10124. }*/
  10125. RFIFOSKIP(fd, packet_len);
  10126. }; // main loop end
  10127. return 0;
  10128. }
  10129. /*==========================================
  10130. * パケットデータベース読み込み
  10131. *------------------------------------------*/
  10132. static int packetdb_readdb(void)
  10133. {
  10134. FILE *fp;
  10135. char line[1024];
  10136. int ln=0;
  10137. int cmd,i,j,packet_ver;
  10138. int max_cmd=-1;
  10139. int skip_ver = 0;
  10140. int warned = 0;
  10141. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  10142. int packet_len_table[MAX_PACKET_DB] = {
  10143. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10147. //#0x0040
  10148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10150. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  10151. #if PACKETVER < 2
  10152. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  10153. #elif PACKETVER < 9 // 78-7b 亀島以降 lv99エフェクト用
  10154. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  10155. #else // change in 0x78 and 0x7c
  10156. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  10157. #endif
  10158. //#0x0080
  10159. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  10160. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  10161. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  10162. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  10163. //#0x00C0
  10164. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  10165. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  10166. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  10167. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  10168. //#0x0100
  10169. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  10170. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  10171. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  10172. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  10173. //#0x0140
  10174. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  10175. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  10176. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  10177. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  10178. //#0x0180
  10179. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  10180. #if PACKETVER < 1
  10181. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10182. #else // 196 comodo以降 状態表示アイコン用
  10183. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10184. #endif
  10185. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  10186. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  10187. //#0x01C0, Set 0x1d5=-1
  10188. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  10189. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  10190. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  10191. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  10192. //#0x0200
  10193. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  10194. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  10195. #if PACKETVER < 9
  10196. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  10197. #else // 0x22c changed
  10198. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  10199. #endif
  10200. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1, -1, 4, 2,
  10201. //#0x0240
  10202. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  10203. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4, -1, 4, 0,
  10204. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10205. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10206. //#0x0280
  10207. 0, 0, 0, 6, 0, 0, 0, 0, 0, 8, 18, 0, 0, 0, 0, 0,
  10208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10210. 0, 0, 0, 0, 0, 0, 0, 0, 0,191, 0, 0, 0, 0, 0, 0,
  10211. //#0x02C0
  10212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10216. };
  10217. struct {
  10218. void (*func)(int, struct map_session_data *);
  10219. char *name;
  10220. } clif_parse_func[]={
  10221. {clif_parse_WantToConnection,"wanttoconnection"},
  10222. {clif_parse_LoadEndAck,"loadendack"},
  10223. {clif_parse_TickSend,"ticksend"},
  10224. {clif_parse_WalkToXY,"walktoxy"},
  10225. {clif_parse_QuitGame,"quitgame"},
  10226. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  10227. {clif_parse_GlobalMessage,"globalmessage"},
  10228. {clif_parse_MapMove,"mapmove"},
  10229. {clif_parse_ChangeDir,"changedir"},
  10230. {clif_parse_Emotion,"emotion"},
  10231. {clif_parse_HowManyConnections,"howmanyconnections"},
  10232. {clif_parse_ActionRequest,"actionrequest"},
  10233. {clif_parse_Restart,"restart"},
  10234. {clif_parse_WisMessage,"wis"},
  10235. {clif_parse_GMmessage,"gmmessage"},
  10236. {clif_parse_TakeItem,"takeitem"},
  10237. {clif_parse_DropItem,"dropitem"},
  10238. {clif_parse_UseItem,"useitem"},
  10239. {clif_parse_EquipItem,"equipitem"},
  10240. {clif_parse_UnequipItem,"unequipitem"},
  10241. {clif_parse_NpcClicked,"npcclicked"},
  10242. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  10243. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  10244. {clif_parse_NpcSellListSend,"npcselllistsend"},
  10245. {clif_parse_CreateChatRoom,"createchatroom"},
  10246. {clif_parse_ChatAddMember,"chataddmember"},
  10247. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  10248. {clif_parse_ChangeChatOwner,"changechatowner"},
  10249. {clif_parse_KickFromChat,"kickfromchat"},
  10250. {clif_parse_ChatLeave,"chatleave"},
  10251. {clif_parse_TradeRequest,"traderequest"},
  10252. {clif_parse_TradeAck,"tradeack"},
  10253. {clif_parse_TradeAddItem,"tradeadditem"},
  10254. {clif_parse_TradeOk,"tradeok"},
  10255. {clif_parse_TradeCancel,"tradecancel"},
  10256. {clif_parse_TradeCommit,"tradecommit"},
  10257. {clif_parse_StopAttack,"stopattack"},
  10258. {clif_parse_PutItemToCart,"putitemtocart"},
  10259. {clif_parse_GetItemFromCart,"getitemfromcart"},
  10260. {clif_parse_RemoveOption,"removeoption"},
  10261. {clif_parse_ChangeCart,"changecart"},
  10262. {clif_parse_StatusUp,"statusup"},
  10263. {clif_parse_SkillUp,"skillup"},
  10264. {clif_parse_UseSkillToId,"useskilltoid"},
  10265. {clif_parse_UseSkillToPos,"useskilltopos"},
  10266. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  10267. {clif_parse_UseSkillMap,"useskillmap"},
  10268. {clif_parse_RequestMemo,"requestmemo"},
  10269. {clif_parse_ProduceMix,"producemix"},
  10270. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  10271. {clif_parse_NpcNextClicked,"npcnextclicked"},
  10272. {clif_parse_NpcAmountInput,"npcamountinput"},
  10273. {clif_parse_NpcStringInput,"npcstringinput"},
  10274. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  10275. {clif_parse_ItemIdentify,"itemidentify"},
  10276. {clif_parse_SelectArrow,"selectarrow"},
  10277. {clif_parse_AutoSpell,"autospell"},
  10278. {clif_parse_UseCard,"usecard"},
  10279. {clif_parse_InsertCard,"insertcard"},
  10280. {clif_parse_RepairItem,"repairitem"},
  10281. {clif_parse_WeaponRefine,"weaponrefine"},
  10282. {clif_parse_SolveCharName,"solvecharname"},
  10283. {clif_parse_ResetChar,"resetchar"},
  10284. {clif_parse_LGMmessage,"lgmmessage"},
  10285. {clif_parse_MoveToKafra,"movetokafra"},
  10286. {clif_parse_MoveFromKafra,"movefromkafra"},
  10287. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  10288. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  10289. {clif_parse_CloseKafra,"closekafra"},
  10290. {clif_parse_CreateParty,"createparty"},
  10291. {clif_parse_CreateParty2,"createparty2"},
  10292. {clif_parse_PartyInvite,"partyinvite"},
  10293. {clif_parse_PartyInvite2,"partyinvite2"},
  10294. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  10295. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  10296. {clif_parse_LeaveParty,"leaveparty"},
  10297. {clif_parse_RemovePartyMember,"removepartymember"},
  10298. {clif_parse_PartyChangeOption,"partychangeoption"},
  10299. {clif_parse_PartyMessage,"partymessage"},
  10300. {clif_parse_CloseVending,"closevending"},
  10301. {clif_parse_VendingListReq,"vendinglistreq"},
  10302. {clif_parse_PurchaseReq,"purchasereq"},
  10303. {clif_parse_OpenVending,"openvending"},
  10304. {clif_parse_CreateGuild,"createguild"},
  10305. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  10306. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  10307. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  10308. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  10309. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  10310. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  10311. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  10312. {clif_parse_GuildInvite,"guildinvite"},
  10313. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  10314. {clif_parse_GuildLeave,"guildleave"},
  10315. {clif_parse_GuildExpulsion,"guildexpulsion"},
  10316. {clif_parse_GuildMessage,"guildmessage"},
  10317. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  10318. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  10319. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  10320. {clif_parse_GuildOpposition,"guildopposition"},
  10321. {clif_parse_GuildBreak,"guildbreak"},
  10322. {clif_parse_PetMenu,"petmenu"},
  10323. {clif_parse_CatchPet,"catchpet"},
  10324. {clif_parse_SelectEgg,"selectegg"},
  10325. {clif_parse_SendEmotion,"sendemotion"},
  10326. {clif_parse_ChangePetName,"changepetname"},
  10327. {clif_parse_GMKick,"gmkick"},
  10328. {clif_parse_GMHide,"gmhide"},
  10329. {clif_parse_GMReqNoChat,"gmreqnochat"},
  10330. {clif_parse_GMReqNoChatCount,"gmreqnochatcount"},
  10331. {clif_parse_NoviceDoriDori,"sndoridori"},
  10332. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  10333. {clif_parse_PMIgnore,"wisexin"},
  10334. {clif_parse_PMIgnoreList,"wisexlist"},
  10335. {clif_parse_PMIgnoreAll,"wisall"},
  10336. {clif_parse_FriendsListAdd,"friendslistadd"},
  10337. {clif_parse_FriendsListRemove,"friendslistremove"},
  10338. {clif_parse_FriendsListReply,"friendslistreply"},
  10339. {clif_parse_GMKillAll,"killall"},
  10340. {clif_parse_Recall,"summon"},
  10341. {clif_parse_GM_Monster_Item,"itemmonster"},
  10342. {clif_parse_Shift,"shift"},
  10343. {clif_parse_Blacksmith,"blacksmith"},
  10344. {clif_parse_Alchemist,"alchemist"},
  10345. {clif_parse_Taekwon,"taekwon"},
  10346. {clif_parse_RankingPk,"rankingpk"},
  10347. {clif_parse_FeelSaveOk,"feelsaveok"},
  10348. {clif_parse_AdoptRequest,"adopt"},
  10349. {clif_parse_debug,"debug"},
  10350. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  10351. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  10352. {clif_parse_HomMoveTo,"hommoveto"},
  10353. {clif_parse_HomAttack,"homattack"},
  10354. {clif_parse_HomMenu,"hommenu"},
  10355. {clif_parse_StoragePassword,"storagepassword"},
  10356. {clif_parse_Hotkey,"hotkey"},
  10357. {clif_parse_AutoRevive,"autorevive"},
  10358. #ifndef TXT_ONLY
  10359. // MAIL SYSTEM
  10360. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  10361. {clif_parse_Mail_read,"mailread"},
  10362. {clif_parse_Mail_getattach,"mailgetattach"},
  10363. {clif_parse_Mail_delete,"maildelete"},
  10364. {clif_parse_Mail_return,"mailreturn"},
  10365. {clif_parse_Mail_setattach,"mailsetattach"},
  10366. {clif_parse_Mail_winopen,"mailwinopen"},
  10367. {clif_parse_Mail_send,"mailsend"},
  10368. #endif
  10369. {NULL,NULL}
  10370. };
  10371. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  10372. memset(packet_db,0,sizeof(packet_db));
  10373. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  10374. packet_len(i) = packet_len_table[i];
  10375. sprintf(line, "%s/packet_db.txt", db_path);
  10376. if( (fp=fopen(line,"r"))==NULL ){
  10377. ShowFatalError("can't read %s\n", line);
  10378. exit(EXIT_FAILURE);
  10379. }
  10380. clif_config.packet_db_ver = MAX_PACKET_VER;
  10381. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  10382. while( fgets(line, sizeof(line), fp) )
  10383. {
  10384. ln++;
  10385. if(line[0]=='/' && line[1]=='/')
  10386. continue;
  10387. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  10388. {
  10389. if(strcmpi(w1,"packet_ver")==0) {
  10390. int prev_ver = packet_ver;
  10391. skip_ver = 0;
  10392. packet_ver = atoi(w2);
  10393. if ( packet_ver > MAX_PACKET_VER )
  10394. { //Check to avoid overflowing. [Skotlex]
  10395. if( (warned&1) == 0 )
  10396. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  10397. warned &= 1;
  10398. skip_ver = 1;
  10399. }
  10400. else if( packet_ver < 0 )
  10401. {
  10402. if( (warned&2) == 0 )
  10403. ShowWarning("Negative packet versions are not supported.\n");
  10404. warned &= 2;
  10405. skip_ver = 1;
  10406. }
  10407. else if( packet_ver == SERVER )
  10408. {
  10409. if( (warned&4) == 0 )
  10410. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  10411. warned &= 4;
  10412. skip_ver = 1;
  10413. }
  10414. if( skip_ver )
  10415. {
  10416. ShowWarning("Skipping packet version %d.\n", packet_ver);
  10417. packet_ver = prev_ver;
  10418. continue;
  10419. }
  10420. // copy from previous version into new version and continue
  10421. // - indicating all following packets should be read into the newer version
  10422. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  10423. continue;
  10424. } else if(strcmpi(w1,"packet_db_ver")==0) {
  10425. if(strcmpi(w2,"default")==0) //This is the preferred version.
  10426. clif_config.packet_db_ver = MAX_PACKET_VER;
  10427. else // to manually set the packet DB version
  10428. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  10429. continue;
  10430. }
  10431. }
  10432. if( skip_ver != 0 )
  10433. continue; // Skipping current packet version
  10434. memset(str,0,sizeof(str));
  10435. for(j=0,p=line;j<4 && p; ++j)
  10436. {
  10437. str[j]=p;
  10438. p=strchr(p,',');
  10439. if(p) *p++=0;
  10440. }
  10441. if(str[0]==NULL)
  10442. continue;
  10443. cmd=strtol(str[0],(char **)NULL,0);
  10444. if(max_cmd < cmd)
  10445. max_cmd = cmd;
  10446. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  10447. continue;
  10448. if(str[1]==NULL){
  10449. ShowError("packet_db: packet len error\n");
  10450. continue;
  10451. }
  10452. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  10453. if(str[2]==NULL){
  10454. packet_db[packet_ver][cmd].func = NULL;
  10455. ln++;
  10456. continue;
  10457. }
  10458. for(j=0;j<ARRAYLENGTH(clif_parse_func);j++){
  10459. if(clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0)
  10460. {
  10461. if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func)
  10462. { //If we are updating a function, we need to zero up the previous one. [Skotlex]
  10463. for(i=0;i<=MAX_PACKET_DB;i++){
  10464. if (packet_db[packet_ver][i].func == clif_parse_func[j].func)
  10465. {
  10466. memset(&packet_db[packet_ver][i], 0, sizeof(struct s_packet_db));
  10467. break;
  10468. }
  10469. }
  10470. }
  10471. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  10472. break;
  10473. }
  10474. }
  10475. // set the identifying cmd for the packet_db version
  10476. if (strcmp(str[2],"wanttoconnection")==0)
  10477. clif_config.connect_cmd[packet_ver] = cmd;
  10478. if(str[3]==NULL){
  10479. ShowError("packet_db: packet error\n");
  10480. exit(EXIT_FAILURE);
  10481. }
  10482. for(j=0,p2=str[3];p2;j++){
  10483. short k;
  10484. str2[j]=p2;
  10485. p2=strchr(p2,':');
  10486. if(p2) *p2++=0;
  10487. k = atoi(str2[j]);
  10488. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  10489. packet_db[packet_ver][cmd].pos[j] = k;
  10490. }
  10491. }
  10492. fclose(fp);
  10493. if(max_cmd > MAX_PACKET_DB)
  10494. {
  10495. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  10496. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  10497. }
  10498. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  10499. { //Locate the nearest version that we still support. [Skotlex]
  10500. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  10501. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  10502. }
  10503. 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);
  10504. return 0;
  10505. }
  10506. /*==========================================
  10507. *
  10508. *------------------------------------------*/
  10509. int do_init_clif(void)
  10510. {
  10511. clif_config.packet_db_ver = -1; // the main packet version of the DB
  10512. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  10513. memset(packet_db,0,sizeof(packet_db));
  10514. //Using the packet_db file is the only way to set up packets now [Skotlex]
  10515. packetdb_readdb();
  10516. set_defaultparse(clif_parse);
  10517. if( make_listen_bind(bind_ip,map_port) == -1 )
  10518. {
  10519. ShowFatalError("can't bind game port\n");
  10520. exit(EXIT_FAILURE);
  10521. }
  10522. add_timer_func_list(clif_waitclose, "clif_waitclose");
  10523. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  10524. add_timer_func_list(clif_delayquit, "clif_delayquit");
  10525. return 0;
  10526. }