clif.c 330 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397
  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.active && !(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.active )
  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. return 0;
  218. WFIFOHEAD(fd, len);
  219. if (WFIFOP(fd,0) == buf) {
  220. ShowError("WARNING: Invalid use of clif_send function\n");
  221. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  222. ShowError(" Please correct your code.\n");
  223. // don't send to not move the pointer of the packet for next sessions in the loop
  224. //WFIFOSET(fd,0);//## TODO is this ok?
  225. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  226. return 0;
  227. }
  228. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  229. memcpy(WFIFOP(fd,0), buf, len);
  230. WFIFOSET(fd,len);
  231. }
  232. return 0;
  233. }
  234. /*==========================================
  235. *
  236. *------------------------------------------*/
  237. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  238. {
  239. int i;
  240. struct map_session_data *sd;
  241. struct party_data *p = NULL;
  242. struct guild *g = NULL;
  243. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  244. if( type != ALL_CLIENT && type != CHAT_MAINCHAT )
  245. nullpo_retr(0, bl);
  246. sd = BL_CAST(BL_PC, bl);
  247. switch(type) {
  248. case ALL_CLIENT: //All player clients.
  249. for (i = 0; i < fd_max; i++) {
  250. if (session[i] && session[i]->func_parse == clif_parse &&
  251. (sd = (struct map_session_data *)session[i]->session_data) != NULL &&
  252. sd->state.active &&
  253. packet_db[sd->packet_ver][RBUFW(buf,0)].len)
  254. { // packet must exist for the client version
  255. WFIFOHEAD(i, len);
  256. memcpy(WFIFOP(i,0), buf, len);
  257. WFIFOSET(i,len);
  258. }
  259. }
  260. break;
  261. case ALL_SAMEMAP: //All players on the same map
  262. for(i = 0; i < fd_max; i++) {
  263. if (session[i] && session[i]->func_parse == clif_parse &&
  264. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  265. sd->state.active && sd->bl.m == bl->m &&
  266. packet_db[sd->packet_ver][RBUFW(buf,0)].len)
  267. { // packet must exist for the client version
  268. WFIFOHEAD(i,len);
  269. memcpy(WFIFOP(i,0), buf, len);
  270. WFIFOSET(i,len);
  271. }
  272. }
  273. break;
  274. case AREA:
  275. case AREA_WOSC:
  276. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  277. clif_send (buf, len, bl, SELF);
  278. case AREA_WOC:
  279. case AREA_WOS:
  280. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  281. BL_PC, buf, len, bl, type);
  282. break;
  283. case AREA_CHAT_WOC:
  284. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  285. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  286. break;
  287. case CHAT:
  288. case CHAT_WOS:
  289. {
  290. struct chat_data *cd;
  291. if (sd) {
  292. cd = (struct chat_data*)map_id2bl(sd->chatID);
  293. } else if (bl->type == BL_CHAT) {
  294. cd = (struct chat_data*)bl;
  295. } else break;
  296. if (cd == NULL)
  297. break;
  298. for(i = 0; i < cd->users; i++) {
  299. if (type == CHAT_WOS && cd->usersd[i] == sd)
  300. continue;
  301. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  302. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  303. {
  304. WFIFOHEAD(fd,len);
  305. memcpy(WFIFOP(fd,0), buf, len);
  306. WFIFOSET(fd,len);
  307. }
  308. }
  309. }
  310. }
  311. break;
  312. case CHAT_MAINCHAT: //[LuzZza]
  313. for(i=1; i<fd_max; i++) {
  314. if (session[i] && session[i]->func_parse == clif_parse &&
  315. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  316. sd->state.active && sd->state.mainchat && !sd->chatID)
  317. {
  318. WFIFOHEAD(i,len);
  319. memcpy(WFIFOP(i,0), buf, len);
  320. WFIFOSET(i, len);
  321. }
  322. }
  323. break;
  324. case PARTY_AREA:
  325. case PARTY_AREA_WOS:
  326. x0 = bl->x - AREA_SIZE;
  327. y0 = bl->y - AREA_SIZE;
  328. x1 = bl->x + AREA_SIZE;
  329. y1 = bl->y + AREA_SIZE;
  330. case PARTY:
  331. case PARTY_WOS:
  332. case PARTY_SAMEMAP:
  333. case PARTY_SAMEMAP_WOS:
  334. if (sd && sd->status.party_id)
  335. p = party_search(sd->status.party_id);
  336. if (p) {
  337. for(i=0;i<MAX_PARTY;i++){
  338. if( (sd = p->data[i].sd) == NULL )
  339. continue;
  340. if( !(fd=sd->fd) )
  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) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  347. continue;
  348. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  349. { // 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.active && sd->partyspy == p->party.party_id &&
  361. packet_db[sd->packet_ver][RBUFW(buf,0)].len)
  362. { // packet must exist for the client version
  363. WFIFOHEAD(i,len);
  364. memcpy(WFIFOP(i,0), buf, len);
  365. WFIFOSET(i,len);
  366. }
  367. }
  368. }
  369. break;
  370. case DUEL:
  371. case DUEL_WOS:
  372. if (!sd || !sd->duel_group) break; //Invalid usage.
  373. x0 = sd->duel_group; //Here we use x0 to store the duel group. [Skotlex]
  374. for (i = 0; i < fd_max; i++) {
  375. if (session[i] && session[i]->func_parse == clif_parse &&
  376. (sd = (struct map_session_data *)session[i]->session_data) != NULL &&
  377. sd->state.active && sd->duel_group == x0) {
  378. if (type == DUEL_WOS && bl->id == sd->bl.id)
  379. continue;
  380. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) {
  381. WFIFOHEAD(i, len);
  382. memcpy(WFIFOP(i,0), buf, len);
  383. WFIFOSET(i,len);
  384. }
  385. }
  386. }
  387. break;
  388. case SELF:
  389. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  390. WFIFOHEAD(fd,len);
  391. memcpy(WFIFOP(fd,0), buf, len);
  392. WFIFOSET(fd,len);
  393. }
  394. break;
  395. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  396. case GUILD_AREA:
  397. case GUILD_AREA_WOS:
  398. x0 = bl->x - AREA_SIZE;
  399. y0 = bl->y - AREA_SIZE;
  400. x1 = bl->x + AREA_SIZE;
  401. y1 = bl->y + AREA_SIZE;
  402. case GUILD_SAMEMAP:
  403. case GUILD_SAMEMAP_WOS:
  404. case GUILD:
  405. case GUILD_WOS:
  406. if (sd && sd->status.guild_id)
  407. g = guild_search(sd->status.guild_id);
  408. if (g) {
  409. for(i = 0; i < g->max_member; i++) {
  410. if( (sd = g->member[i].sd) != NULL )
  411. {
  412. if( !(fd=sd->fd) )
  413. continue;
  414. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  415. continue;
  416. if( type != GUILD && type != GUILD_WOS && sd->bl.m != bl->m )
  417. continue;
  418. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  419. continue;
  420. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  421. { // packet must exist for the client version
  422. WFIFOHEAD(fd,len);
  423. memcpy(WFIFOP(fd,0), buf, len);
  424. WFIFOSET(fd,len);
  425. }
  426. }
  427. }
  428. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  429. break;
  430. for (i = 1; i < fd_max; i++){ // guildspy [Syrus22]
  431. if (session[i] && session[i]->func_parse == clif_parse &&
  432. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  433. sd->state.active && sd->guildspy == g->guild_id &&
  434. packet_db[sd->packet_ver][RBUFW(buf,0)].len)
  435. { // packet must exist for the client version
  436. WFIFOHEAD(i,len);
  437. memcpy(WFIFOP(i,0), buf, len);
  438. WFIFOSET(i,len);
  439. }
  440. }
  441. }
  442. break;
  443. default:
  444. ShowError("clif_send: Unrecognized type %d\n",type);
  445. return -1;
  446. }
  447. return 0;
  448. }
  449. //
  450. // パケット作って送信
  451. //
  452. /*==========================================
  453. *
  454. *------------------------------------------*/
  455. int clif_authok(struct map_session_data *sd)
  456. {
  457. int fd;
  458. if (!sd->fd)
  459. return 0;
  460. fd = sd->fd;
  461. WFIFOHEAD(fd, packet_len(0x73));
  462. WFIFOW(fd, 0) = 0x73;
  463. WFIFOL(fd, 2) = gettick();
  464. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  465. WFIFOB(fd, 9) = 5; // ignored
  466. WFIFOB(fd,10) = 5; // ignored
  467. WFIFOSET(fd,packet_len(0x73));
  468. return 0;
  469. }
  470. /*==========================================
  471. * Authentication failed/disconnect client.
  472. *------------------------------------------
  473. * The client closes it's socket and displays a message according to type:
  474. * 1 - server closed -> MsgStringTable[4]
  475. * 2 - ID already logged in -> MsgStringTable[5]
  476. * 3 - timeout/too much lag -> MsgStringTable[241]
  477. * 4 - server full -> MsgStringTable[264]
  478. * 5 - underaged -> MsgStringTable[305]
  479. * 8 - Server sill recognizes last connection -> MsgStringTable[441]
  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 - respawned
  567. * 3 - teleported / logged out
  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 - respawned
  584. * 3 - teleported / logged out
  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. sd = BL_CAST(BL_PC, bl);
  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. sd = BL_CAST(BL_PC, bl);
  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.active && 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 (!battle_config.prevent_logout ||
  1180. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1181. map_quit(sd);
  1182. else if (sd->fd)
  1183. { //Disassociate session from player (session is deleted after this function was called)
  1184. //And set a timer to make him quit later.
  1185. session[sd->fd]->session_data = NULL;
  1186. sd->fd = 0;
  1187. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1188. }
  1189. }
  1190. /*==========================================
  1191. *
  1192. *------------------------------------------*/
  1193. static int clif_waitclose(int tid, unsigned int tick, int id, int data)
  1194. {
  1195. if (session[id] && session[id]->func_parse == clif_parse) //Avoid disconnecting non-players, as pointed out by End of Exam [Skotlex]
  1196. set_eof(id);
  1197. return 0;
  1198. }
  1199. /*==========================================
  1200. *
  1201. *------------------------------------------*/
  1202. void clif_setwaitclose(int fd)
  1203. {
  1204. // if player is not already in the game (double connection probably)
  1205. if (session[fd]->session_data == NULL) {
  1206. // limited timer, just to send information.
  1207. add_timer(gettick() + 1000, clif_waitclose, fd, 0);
  1208. } else
  1209. add_timer(gettick() + 5000, clif_waitclose, fd, 0);
  1210. }
  1211. /*==========================================
  1212. *
  1213. *------------------------------------------*/
  1214. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1215. {
  1216. int fd;
  1217. nullpo_retv(sd);
  1218. fd = sd->fd;
  1219. WFIFOHEAD(fd,packet_len(0x91));
  1220. WFIFOW(fd,0) = 0x91;
  1221. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1222. WFIFOW(fd,18) = x;
  1223. WFIFOW(fd,20) = y;
  1224. WFIFOSET(fd,packet_len(0x91));
  1225. }
  1226. /*==========================================
  1227. * Tells the client to connect to another map-server
  1228. *------------------------------------------*/
  1229. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1230. {
  1231. int fd;
  1232. nullpo_retv(sd);
  1233. fd = sd->fd;
  1234. WFIFOHEAD(fd,packet_len(0x92));
  1235. WFIFOW(fd,0) = 0x92;
  1236. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1237. WFIFOW(fd,18) = x;
  1238. WFIFOW(fd,20) = y;
  1239. WFIFOL(fd,22) = htonl(ip);
  1240. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1241. WFIFOSET(fd,packet_len(0x92));
  1242. }
  1243. int clif_blown(struct block_list *bl)
  1244. {
  1245. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1246. // return clif_fixpos(bl);
  1247. return clif_slide(bl, bl->x, bl->y);
  1248. }
  1249. /*==========================================
  1250. *
  1251. *------------------------------------------*/
  1252. int clif_fixpos(struct block_list *bl)
  1253. {
  1254. unsigned char buf[16];
  1255. nullpo_retr(0, bl);
  1256. WBUFW(buf,0)=0x88;
  1257. WBUFL(buf,2)=bl->id;
  1258. WBUFW(buf,6)=bl->x;
  1259. WBUFW(buf,8)=bl->y;
  1260. clif_send(buf, packet_len(0x88), bl, AREA);
  1261. if (disguised(bl)) {
  1262. WBUFL(buf,2)=-bl->id;
  1263. clif_send(buf, packet_len(0x88), bl, SELF);
  1264. }
  1265. return 0;
  1266. }
  1267. /*==========================================
  1268. *
  1269. *------------------------------------------*/
  1270. int clif_npcbuysell(struct map_session_data* sd, int id)
  1271. {
  1272. int fd;
  1273. nullpo_retr(0, sd);
  1274. fd=sd->fd;
  1275. WFIFOHEAD(fd, packet_len(0xc4));
  1276. WFIFOW(fd,0)=0xc4;
  1277. WFIFOL(fd,2)=id;
  1278. WFIFOSET(fd,packet_len(0xc4));
  1279. return 0;
  1280. }
  1281. /*==========================================
  1282. *
  1283. *------------------------------------------*/
  1284. int clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1285. {
  1286. int fd,i;
  1287. nullpo_retr(0, sd);
  1288. nullpo_retr(0, nd);
  1289. fd = sd->fd;
  1290. WFIFOHEAD(fd, 200 * 11 + 4);
  1291. WFIFOW(fd,0) = 0xc6;
  1292. WFIFOW(fd,2) = 4 + nd->u.shop.count*11;
  1293. for( i = 0; i < nd->u.shop.count; i++ )
  1294. {
  1295. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  1296. int val = nd->u.shop.shop_item[i].value;
  1297. WFIFOL(fd,4+i*11) = val;
  1298. if (!id->flag.value_notdc)
  1299. val = pc_modifybuyvalue(sd,val);
  1300. WFIFOL(fd,8+i*11) = val;
  1301. WFIFOB(fd,12+i*11) = itemtype(id->type);
  1302. WFIFOW(fd,13+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1303. }
  1304. WFIFOSET(fd,WFIFOW(fd,2));
  1305. return 0;
  1306. }
  1307. /*==========================================
  1308. *
  1309. *------------------------------------------*/
  1310. int clif_selllist(struct map_session_data *sd)
  1311. {
  1312. int fd,i,c=0,val;
  1313. nullpo_retr(0, sd);
  1314. fd=sd->fd;
  1315. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1316. WFIFOW(fd,0)=0xc7;
  1317. for(i=0;i<MAX_INVENTORY;i++) {
  1318. if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
  1319. if (!itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)))
  1320. continue;
  1321. val=sd->inventory_data[i]->value_sell;
  1322. if (val < 0)
  1323. continue;
  1324. WFIFOW(fd,4+c*10)=i+2;
  1325. WFIFOL(fd,6+c*10)=val;
  1326. if (!sd->inventory_data[i]->flag.value_notoc)
  1327. val=pc_modifysellvalue(sd,val);
  1328. WFIFOL(fd,10+c*10)=val;
  1329. c++;
  1330. }
  1331. }
  1332. WFIFOW(fd,2)=c*10+4;
  1333. WFIFOSET(fd,WFIFOW(fd,2));
  1334. return 0;
  1335. }
  1336. /*==========================================
  1337. *
  1338. *------------------------------------------*/
  1339. int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1340. {
  1341. int fd = sd->fd;
  1342. int slen = strlen(mes) + 9;
  1343. WFIFOHEAD(fd, slen);
  1344. WFIFOW(fd,0)=0xb4;
  1345. WFIFOW(fd,2)=slen;
  1346. WFIFOL(fd,4)=npcid;
  1347. strcpy((char*)WFIFOP(fd,8),mes);
  1348. WFIFOSET(fd,WFIFOW(fd,2));
  1349. return 0;
  1350. }
  1351. /*==========================================
  1352. *
  1353. *------------------------------------------*/
  1354. int clif_scriptnext(struct map_session_data *sd,int npcid)
  1355. {
  1356. int fd;
  1357. nullpo_retr(0, sd);
  1358. fd=sd->fd;
  1359. WFIFOHEAD(fd, packet_len(0xb5));
  1360. WFIFOW(fd,0)=0xb5;
  1361. WFIFOL(fd,2)=npcid;
  1362. WFIFOSET(fd,packet_len(0xb5));
  1363. return 0;
  1364. }
  1365. /*==========================================
  1366. *
  1367. *------------------------------------------*/
  1368. int clif_scriptclose(struct map_session_data *sd, int npcid)
  1369. {
  1370. int fd;
  1371. nullpo_retr(0, sd);
  1372. fd=sd->fd;
  1373. WFIFOHEAD(fd, packet_len(0xb6));
  1374. WFIFOW(fd,0)=0xb6;
  1375. WFIFOL(fd,2)=npcid;
  1376. WFIFOSET(fd,packet_len(0xb6));
  1377. return 0;
  1378. }
  1379. /*==========================================
  1380. *
  1381. *------------------------------------------*/
  1382. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1383. {
  1384. unsigned char *buf;
  1385. int fd = sd->fd;
  1386. sd->state.using_fake_npc = 1;
  1387. WFIFOHEAD(fd, packet_len(0x78));
  1388. buf = WFIFOP(fd,0);
  1389. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1390. WBUFW(buf,0)=0x78;
  1391. #if PACKETVER >=9
  1392. WBUFB(buf,2) = 0; //Unknown bit
  1393. buf = WFIFOP(fd,1);
  1394. #endif
  1395. WBUFL(buf,2)=npcid;
  1396. WBUFW(buf,14)=111;
  1397. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1398. WBUFB(buf,49)=5;
  1399. WBUFB(buf,50)=5;
  1400. WFIFOSET(fd, packet_len(0x78));
  1401. return;
  1402. }
  1403. /*==========================================
  1404. *
  1405. *------------------------------------------*/
  1406. int clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1407. {
  1408. int fd = sd->fd;
  1409. int slen = strlen(mes) + 8;
  1410. struct block_list *bl = NULL;
  1411. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1412. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1413. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1414. clif_sendfakenpc(sd, npcid);
  1415. WFIFOHEAD(fd, slen);
  1416. WFIFOW(fd,0)=0xb7;
  1417. WFIFOW(fd,2)=slen;
  1418. WFIFOL(fd,4)=npcid;
  1419. strcpy((char*)WFIFOP(fd,8),mes);
  1420. WFIFOSET(fd,WFIFOW(fd,2));
  1421. return 0;
  1422. }
  1423. /*==========================================
  1424. *
  1425. *------------------------------------------*/
  1426. int clif_scriptinput(struct map_session_data *sd, int npcid)
  1427. {
  1428. int fd;
  1429. struct block_list *bl = NULL;
  1430. nullpo_retr(0, sd);
  1431. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1432. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1433. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1434. clif_sendfakenpc(sd, npcid);
  1435. fd=sd->fd;
  1436. WFIFOHEAD(fd, packet_len(0x142));
  1437. WFIFOW(fd,0)=0x142;
  1438. WFIFOL(fd,2)=npcid;
  1439. WFIFOSET(fd,packet_len(0x142));
  1440. return 0;
  1441. }
  1442. /*==========================================
  1443. *
  1444. *------------------------------------------*/
  1445. int clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1446. {
  1447. int fd;
  1448. struct block_list *bl = NULL;
  1449. nullpo_retr(0, sd);
  1450. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1451. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1452. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1453. clif_sendfakenpc(sd, npcid);
  1454. fd=sd->fd;
  1455. WFIFOHEAD(fd, packet_len(0x1d4));
  1456. WFIFOW(fd,0)=0x1d4;
  1457. WFIFOL(fd,2)=npcid;
  1458. WFIFOSET(fd,packet_len(0x1d4));
  1459. return 0;
  1460. }
  1461. /// npc_id is ignored in the client
  1462. /// type=2 : Remove viewpoint
  1463. /// type=other : Show viewpoint
  1464. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1465. {
  1466. int fd;
  1467. nullpo_retr(0, sd);
  1468. fd=sd->fd;
  1469. WFIFOHEAD(fd, packet_len(0x144));
  1470. WFIFOW(fd,0)=0x144;
  1471. WFIFOL(fd,2)=npc_id;
  1472. WFIFOL(fd,6)=type;
  1473. WFIFOL(fd,10)=x;
  1474. WFIFOL(fd,14)=y;
  1475. WFIFOB(fd,18)=id;
  1476. WFIFOL(fd,19)=color;
  1477. WFIFOSET(fd,packet_len(0x144));
  1478. return 0;
  1479. }
  1480. /*==========================================
  1481. *
  1482. *------------------------------------------*/
  1483. int clif_cutin(struct map_session_data* sd, const char* image, int type)
  1484. {
  1485. int fd;
  1486. nullpo_retr(0, sd);
  1487. fd=sd->fd;
  1488. WFIFOHEAD(fd, packet_len(0x1b3));
  1489. WFIFOW(fd,0)=0x1b3;
  1490. strncpy((char*)WFIFOP(fd,2),image,64);
  1491. WFIFOB(fd,66)=type;
  1492. WFIFOSET(fd,packet_len(0x1b3));
  1493. return 0;
  1494. }
  1495. /*==========================================
  1496. * Fills in card data from the given item and into the buffer. [Skotlex]
  1497. *------------------------------------------*/
  1498. static void clif_addcards(unsigned char* buf, struct item* item)
  1499. {
  1500. int i=0,j;
  1501. if( item == NULL ) { //Blank data
  1502. WBUFW(buf,0) = 0;
  1503. WBUFW(buf,2) = 0;
  1504. WBUFW(buf,4) = 0;
  1505. WBUFW(buf,6) = 0;
  1506. return;
  1507. }
  1508. if( item->card[0] == CARD0_PET ) { //pet eggs
  1509. WBUFW(buf,0) = 0;
  1510. WBUFW(buf,2) = 0;
  1511. WBUFW(buf,4) = 0;
  1512. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1513. return;
  1514. }
  1515. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1516. WBUFW(buf,0) = item->card[0];
  1517. WBUFW(buf,2) = item->card[1];
  1518. WBUFW(buf,4) = item->card[2];
  1519. WBUFW(buf,6) = item->card[3];
  1520. return;
  1521. }
  1522. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1523. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1524. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1525. //Normal items.
  1526. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1527. WBUFW(buf,0) = j;
  1528. else
  1529. WBUFW(buf,0) = item->card[i];
  1530. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1531. WBUFW(buf,2) = j;
  1532. else
  1533. WBUFW(buf,2) = item->card[i];
  1534. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1535. WBUFW(buf,4) = j;
  1536. else
  1537. WBUFW(buf,4) = item->card[i];
  1538. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1539. WBUFW(buf,6) = j;
  1540. else
  1541. WBUFW(buf,6) = item->card[i];
  1542. }
  1543. /*==========================================
  1544. *
  1545. *------------------------------------------*/
  1546. int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1547. {
  1548. int fd;
  1549. nullpo_retr(0, sd);
  1550. fd = sd->fd;
  1551. if (!session_isActive(fd)) //Sasuke-
  1552. return 0;
  1553. WFIFOHEAD(fd,packet_len(0xa0));
  1554. if(fail) {
  1555. WFIFOW(fd,0)=0xa0;
  1556. WFIFOW(fd,2)=n+2;
  1557. WFIFOW(fd,4)=amount;
  1558. WFIFOW(fd,6)=0;
  1559. WFIFOB(fd,8)=0;
  1560. WFIFOB(fd,9)=0;
  1561. WFIFOB(fd,10)=0;
  1562. WFIFOW(fd,11)=0;
  1563. WFIFOW(fd,13)=0;
  1564. WFIFOW(fd,15)=0;
  1565. WFIFOW(fd,17)=0;
  1566. WFIFOW(fd,19)=0;
  1567. WFIFOB(fd,21)=0;
  1568. WFIFOB(fd,22)=fail;
  1569. } else {
  1570. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1571. return 1;
  1572. WFIFOW(fd,0)=0xa0;
  1573. WFIFOW(fd,2)=n+2;
  1574. WFIFOW(fd,4)=amount;
  1575. if (sd->inventory_data[n]->view_id > 0)
  1576. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1577. else
  1578. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1579. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1580. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1581. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1582. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1583. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1584. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1585. WFIFOB(fd,22)=fail;
  1586. }
  1587. WFIFOSET(fd,packet_len(0xa0));
  1588. return 0;
  1589. }
  1590. /*==========================================
  1591. *
  1592. *------------------------------------------*/
  1593. int clif_delitem(struct map_session_data *sd,int n,int amount)
  1594. {
  1595. int fd;
  1596. nullpo_retr(0, sd);
  1597. fd=sd->fd;
  1598. WFIFOHEAD(fd, packet_len(0xaf));
  1599. WFIFOW(fd,0)=0xaf;
  1600. WFIFOW(fd,2)=n+2;
  1601. WFIFOW(fd,4)=amount;
  1602. WFIFOSET(fd,packet_len(0xaf));
  1603. return 0;
  1604. }
  1605. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1606. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1607. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1608. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1609. {
  1610. if (id->view_id > 0)
  1611. WBUFW(buf,n)=id->view_id;
  1612. else
  1613. WBUFW(buf,n)=i->nameid;
  1614. WBUFB(buf,n+2)=itemtype(id->type);
  1615. WBUFB(buf,n+3)=i->identify;
  1616. if (equip >= 0) { //Equippable item
  1617. WBUFW(buf,n+4)=equip;
  1618. WBUFW(buf,n+6)=i->equip;
  1619. WBUFB(buf,n+8)=i->attribute;
  1620. WBUFB(buf,n+9)=i->refine;
  1621. } else { //Stackable item.
  1622. WBUFW(buf,n+4)=i->amount;
  1623. if (equip == -2 && id->equip == EQP_AMMO)
  1624. WBUFW(buf,n+6)=EQP_AMMO;
  1625. else
  1626. WBUFW(buf,n+6)=0;
  1627. }
  1628. }
  1629. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1630. void clif_inventorylist(struct map_session_data *sd)
  1631. {
  1632. int i,n,ne,fd = sd->fd,arrow=-1;
  1633. unsigned char *buf;
  1634. unsigned char bufe[MAX_INVENTORY*20+4];
  1635. #if PACKETVER < 5
  1636. const int s = 10; //Entry size.
  1637. #else
  1638. const int s = 18;
  1639. #endif
  1640. WFIFOHEAD(fd, MAX_INVENTORY * s + 4);
  1641. buf = WFIFOP(fd,0);
  1642. for(i=0,n=0,ne=0;i<MAX_INVENTORY;i++){
  1643. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1644. continue;
  1645. if(!itemdb_isstackable2(sd->inventory_data[i]))
  1646. { //Non-stackable (Equippable)
  1647. WBUFW(bufe,ne*20+4)=i+2;
  1648. clif_item_sub(bufe, ne*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1649. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.inventory[i]);
  1650. ne++;
  1651. } else { //Stackable.
  1652. WBUFW(buf,n*s+4)=i+2;
  1653. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1654. if (sd->inventory_data[i]->equip == EQP_AMMO &&
  1655. sd->status.inventory[i].equip)
  1656. arrow=i;
  1657. #if PACKETVER >= 5
  1658. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1659. #endif
  1660. n++;
  1661. }
  1662. }
  1663. if (n) {
  1664. #if PACKETVER < 5
  1665. WBUFW(buf,0)=0xa3;
  1666. #else
  1667. WBUFW(buf,0)=0x1ee;
  1668. #endif
  1669. WBUFW(buf,2)=4+n*s;
  1670. WFIFOSET(fd,WFIFOW(fd,2));
  1671. }
  1672. if(arrow >= 0)
  1673. clif_arrowequip(sd,arrow);
  1674. if(ne){
  1675. WBUFW(bufe,0)=0xa4;
  1676. WBUFW(bufe,2)=4+ne*20;
  1677. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1678. }
  1679. }
  1680. //Required when items break/get-repaired. Only sends equippable item list.
  1681. void clif_equiplist(struct map_session_data *sd)
  1682. {
  1683. int i,n,fd = sd->fd;
  1684. unsigned char *buf;
  1685. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  1686. buf = WFIFOP(fd,0);
  1687. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1688. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1689. continue;
  1690. if(itemdb_isstackable2(sd->inventory_data[i]))
  1691. continue;
  1692. //Equippable
  1693. WBUFW(buf,n*20+4)=i+2;
  1694. clif_item_sub(buf, n*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1695. clif_addcards(WBUFP(buf, n*20+16), &sd->status.inventory[i]);
  1696. n++;
  1697. }
  1698. if (n) {
  1699. WBUFW(buf,0)=0xa4;
  1700. WBUFW(buf,2)=4+n*20;
  1701. WFIFOSET(fd,WFIFOW(fd,2));
  1702. }
  1703. }
  1704. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1705. void clif_storagelist(struct map_session_data *sd,struct storage *stor)
  1706. {
  1707. struct item_data *id;
  1708. int i,n,ne,fd=sd->fd;
  1709. unsigned char *buf;
  1710. unsigned char bufe[MAX_STORAGE*20+4];
  1711. #if PACKETVER < 5
  1712. const int s = 10; //Entry size.
  1713. #else
  1714. const int s = 18;
  1715. #endif
  1716. WFIFOHEAD(fd,MAX_STORAGE * s + 4);
  1717. buf = WFIFOP(fd,0);
  1718. for(i=0,n=0,ne=0;i<MAX_STORAGE;i++){
  1719. if(stor->storage_[i].nameid<=0)
  1720. continue;
  1721. id = itemdb_search(stor->storage_[i].nameid);
  1722. if(!itemdb_isstackable2(id))
  1723. { //Equippable
  1724. WBUFW(bufe,ne*20+4)=i+1;
  1725. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  1726. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  1727. ne++;
  1728. } else { //Stackable
  1729. WBUFW(buf,n*s+4)=i+1;
  1730. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  1731. #if PACKETVER >= 5
  1732. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  1733. #endif
  1734. n++;
  1735. }
  1736. }
  1737. if(n){
  1738. #if PACKETVER < 5
  1739. WBUFW(buf,0)=0xa5;
  1740. #else
  1741. WBUFW(buf,0)=0x1f0;
  1742. #endif
  1743. WBUFW(buf,2)=4+n*s;
  1744. WFIFOSET(fd,WFIFOW(fd,2));
  1745. }
  1746. if(ne){
  1747. WBUFW(bufe,0)=0xa6;
  1748. WBUFW(bufe,2)=4+ne*20;
  1749. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1750. }
  1751. }
  1752. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1753. void clif_guildstoragelist(struct map_session_data *sd,struct guild_storage *stor)
  1754. {
  1755. struct item_data *id;
  1756. int i,n,ne,fd=sd->fd;
  1757. unsigned char *buf;
  1758. unsigned char bufe[MAX_GUILD_STORAGE*20+4];
  1759. #if PACKETVER < 5
  1760. const int s = 10; //Entry size.
  1761. #else
  1762. const int s = 18;
  1763. #endif
  1764. WFIFOHEAD(fd,MAX_GUILD_STORAGE * s + 4);
  1765. buf = WFIFOP(fd,0);
  1766. for(i=0,n=0,ne=0;i<MAX_GUILD_STORAGE;i++){
  1767. if(stor->storage_[i].nameid<=0)
  1768. continue;
  1769. id = itemdb_search(stor->storage_[i].nameid);
  1770. if(!itemdb_isstackable2(id))
  1771. { //Equippable
  1772. WBUFW(bufe,ne*20+4)=i+1;
  1773. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  1774. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  1775. ne++;
  1776. } else { //Stackable
  1777. WBUFW(buf,n*s+4)=i+1;
  1778. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  1779. #if PACKETVER >= 5
  1780. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  1781. #endif
  1782. n++;
  1783. }
  1784. }
  1785. if(n){
  1786. #if PACKETVER < 5
  1787. WBUFW(buf,0)=0xa5;
  1788. #else
  1789. WBUFW(buf,0)=0x1f0;
  1790. #endif
  1791. WBUFW(buf,2)=4+n*s;
  1792. WFIFOSET(fd,WFIFOW(fd,2));
  1793. }
  1794. if(ne){
  1795. WBUFW(bufe,0)=0xa6;
  1796. WBUFW(bufe,2)=4+ne*20;
  1797. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1798. }
  1799. }
  1800. void clif_cartlist(struct map_session_data *sd)
  1801. {
  1802. struct item_data *id;
  1803. int i,n,ne,fd=sd->fd;
  1804. unsigned char *buf;
  1805. unsigned char bufe[MAX_CART*20+4];
  1806. #if PACKETVER < 5
  1807. const int s = 10; //Entry size.
  1808. #else
  1809. const int s = 18;
  1810. #endif
  1811. WFIFOHEAD(fd, MAX_CART * s + 4);
  1812. buf = WFIFOP(fd,0);
  1813. for(i=0,n=0,ne=0;i<MAX_CART;i++){
  1814. if(sd->status.cart[i].nameid<=0)
  1815. continue;
  1816. id = itemdb_search(sd->status.cart[i].nameid);
  1817. if(!itemdb_isstackable2(id))
  1818. { //Equippable
  1819. WBUFW(bufe,ne*20+4)=i+2;
  1820. clif_item_sub(bufe, ne*20+6, &sd->status.cart[i], id, id->equip);
  1821. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.cart[i]);
  1822. ne++;
  1823. } else { //Stackable
  1824. WBUFW(buf,n*s+4)=i+2;
  1825. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  1826. #if PACKETVER >= 5
  1827. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  1828. #endif
  1829. n++;
  1830. }
  1831. }
  1832. if(n){
  1833. #if PACKETVER < 5
  1834. WBUFW(buf,0)=0x123;
  1835. #else
  1836. WBUFW(buf,0)=0x1ef;
  1837. #endif
  1838. WBUFW(buf,2)=4+n*s;
  1839. WFIFOSET(fd,WFIFOW(fd,2));
  1840. }
  1841. if(ne){
  1842. WBUFW(bufe,0)=0x122;
  1843. WBUFW(bufe,2)=4+ne*20;
  1844. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1845. }
  1846. return;
  1847. }
  1848. /// Client behaviour:
  1849. /// Closes the cart storage and removes all it's items from memory.
  1850. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  1851. void clif_clearcart(int fd)
  1852. {
  1853. WFIFOHEAD(fd, packet_len(0x12b));
  1854. WFIFOW(fd,0) = 0x12b;
  1855. }
  1856. // Guild XY locators [Valaris]
  1857. int clif_guild_xy(struct map_session_data *sd)
  1858. {
  1859. unsigned char buf[10];
  1860. nullpo_retr(0, sd);
  1861. WBUFW(buf,0)=0x1eb;
  1862. WBUFL(buf,2)=sd->status.account_id;
  1863. WBUFW(buf,6)=sd->bl.x;
  1864. WBUFW(buf,8)=sd->bl.y;
  1865. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  1866. return 0;
  1867. }
  1868. /*==========================================
  1869. * Sends x/y dot to a single fd. [Skotlex]
  1870. *------------------------------------------*/
  1871. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  1872. {
  1873. WFIFOHEAD(fd,packet_len(0x1eb));
  1874. WFIFOW(fd,0)=0x1eb;
  1875. WFIFOL(fd,2)=sd->status.account_id;
  1876. WFIFOW(fd,6)=sd->bl.x;
  1877. WFIFOW(fd,8)=sd->bl.y;
  1878. WFIFOSET(fd,packet_len(0x1eb));
  1879. return 0;
  1880. }
  1881. // Guild XY locators [Valaris]
  1882. int clif_guild_xy_remove(struct map_session_data *sd)
  1883. {
  1884. unsigned char buf[10];
  1885. nullpo_retr(0, sd);
  1886. WBUFW(buf,0)=0x1eb;
  1887. WBUFL(buf,2)=sd->status.account_id;
  1888. WBUFW(buf,6)=-1;
  1889. WBUFW(buf,8)=-1;
  1890. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  1891. return 0;
  1892. }
  1893. /*==========================================
  1894. * ステータスを送りつける
  1895. * 表示専用数字はこの中で計算して送る
  1896. *------------------------------------------*/
  1897. int clif_updatestatus(struct map_session_data *sd,int type)
  1898. {
  1899. int fd,len=8;
  1900. nullpo_retr(0, sd);
  1901. fd=sd->fd;
  1902. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  1903. return 0;
  1904. WFIFOHEAD(fd, 14);
  1905. WFIFOW(fd,0)=0xb0;
  1906. WFIFOW(fd,2)=type;
  1907. switch(type){
  1908. // 00b0
  1909. case SP_WEIGHT:
  1910. pc_updateweightstatus(sd);
  1911. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  1912. WFIFOW(fd,2)=type;
  1913. WFIFOL(fd,4)=sd->weight;
  1914. break;
  1915. case SP_MAXWEIGHT:
  1916. WFIFOL(fd,4)=sd->max_weight;
  1917. break;
  1918. case SP_SPEED:
  1919. WFIFOL(fd,4)=sd->battle_status.speed;
  1920. break;
  1921. case SP_BASELEVEL:
  1922. WFIFOL(fd,4)=sd->status.base_level;
  1923. break;
  1924. case SP_JOBLEVEL:
  1925. WFIFOL(fd,4)=sd->status.job_level;
  1926. break;
  1927. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  1928. WFIFOL(fd,4)=sd->status.karma;
  1929. break;
  1930. case SP_MANNER:
  1931. WFIFOL(fd,4)=sd->status.manner;
  1932. break;
  1933. case SP_STATUSPOINT:
  1934. WFIFOL(fd,4)=sd->status.status_point;
  1935. break;
  1936. case SP_SKILLPOINT:
  1937. WFIFOL(fd,4)=sd->status.skill_point;
  1938. break;
  1939. case SP_HIT:
  1940. WFIFOL(fd,4)=sd->battle_status.hit;
  1941. break;
  1942. case SP_FLEE1:
  1943. WFIFOL(fd,4)=sd->battle_status.flee;
  1944. break;
  1945. case SP_FLEE2:
  1946. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  1947. break;
  1948. case SP_MAXHP:
  1949. WFIFOL(fd,4)=sd->battle_status.max_hp;
  1950. break;
  1951. case SP_MAXSP:
  1952. WFIFOL(fd,4)=sd->battle_status.max_sp;
  1953. break;
  1954. case SP_HP:
  1955. WFIFOL(fd,4)=sd->battle_status.hp;
  1956. if (battle_config.disp_hpmeter)
  1957. clif_hpmeter(sd);
  1958. if (!battle_config.party_hp_mode && sd->status.party_id)
  1959. clif_party_hp(sd);
  1960. break;
  1961. case SP_SP:
  1962. WFIFOL(fd,4)=sd->battle_status.sp;
  1963. break;
  1964. case SP_ASPD:
  1965. WFIFOL(fd,4)=sd->battle_status.amotion;
  1966. break;
  1967. case SP_ATK1:
  1968. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw.atk;
  1969. break;
  1970. case SP_DEF1:
  1971. WFIFOL(fd,4)=sd->battle_status.def;
  1972. break;
  1973. case SP_MDEF1:
  1974. WFIFOL(fd,4)=sd->battle_status.mdef;
  1975. break;
  1976. case SP_ATK2:
  1977. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2;
  1978. break;
  1979. case SP_DEF2:
  1980. WFIFOL(fd,4)=sd->battle_status.def2;
  1981. break;
  1982. case SP_MDEF2:
  1983. //negative check (in case you have something like Berserk active)
  1984. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  1985. if (len < 0) len = 0;
  1986. WFIFOL(fd,4)= len;
  1987. len = 8;
  1988. break;
  1989. case SP_CRITICAL:
  1990. WFIFOL(fd,4)=sd->battle_status.cri/10;
  1991. break;
  1992. case SP_MATK1:
  1993. WFIFOL(fd,4)=sd->battle_status.matk_max;
  1994. break;
  1995. case SP_MATK2:
  1996. WFIFOL(fd,4)=sd->battle_status.matk_min;
  1997. break;
  1998. case SP_ZENY:
  1999. WFIFOW(fd,0)=0xb1;
  2000. WFIFOL(fd,4)=sd->status.zeny - sd->mail.zeny;
  2001. break;
  2002. case SP_BASEEXP:
  2003. WFIFOW(fd,0)=0xb1;
  2004. WFIFOL(fd,4)=sd->status.base_exp;
  2005. break;
  2006. case SP_JOBEXP:
  2007. WFIFOW(fd,0)=0xb1;
  2008. WFIFOL(fd,4)=sd->status.job_exp;
  2009. break;
  2010. case SP_NEXTBASEEXP:
  2011. WFIFOW(fd,0)=0xb1;
  2012. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2013. break;
  2014. case SP_NEXTJOBEXP:
  2015. WFIFOW(fd,0)=0xb1;
  2016. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2017. break;
  2018. // 00be 終了
  2019. case SP_USTR:
  2020. case SP_UAGI:
  2021. case SP_UVIT:
  2022. case SP_UINT:
  2023. case SP_UDEX:
  2024. case SP_ULUK:
  2025. WFIFOW(fd,0)=0xbe;
  2026. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2027. len=5;
  2028. break;
  2029. // 013a 終了
  2030. case SP_ATTACKRANGE:
  2031. WFIFOW(fd,0)=0x13a;
  2032. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2033. len=4;
  2034. break;
  2035. // 0141 終了
  2036. case SP_STR:
  2037. WFIFOW(fd,0)=0x141;
  2038. WFIFOL(fd,2)=type;
  2039. WFIFOL(fd,6)=sd->status.str;
  2040. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2041. len=14;
  2042. break;
  2043. case SP_AGI:
  2044. WFIFOW(fd,0)=0x141;
  2045. WFIFOL(fd,2)=type;
  2046. WFIFOL(fd,6)=sd->status.agi;
  2047. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2048. len=14;
  2049. break;
  2050. case SP_VIT:
  2051. WFIFOW(fd,0)=0x141;
  2052. WFIFOL(fd,2)=type;
  2053. WFIFOL(fd,6)=sd->status.vit;
  2054. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2055. len=14;
  2056. break;
  2057. case SP_INT:
  2058. WFIFOW(fd,0)=0x141;
  2059. WFIFOL(fd,2)=type;
  2060. WFIFOL(fd,6)=sd->status.int_;
  2061. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2062. len=14;
  2063. break;
  2064. case SP_DEX:
  2065. WFIFOW(fd,0)=0x141;
  2066. WFIFOL(fd,2)=type;
  2067. WFIFOL(fd,6)=sd->status.dex;
  2068. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2069. len=14;
  2070. break;
  2071. case SP_LUK:
  2072. WFIFOW(fd,0)=0x141;
  2073. WFIFOL(fd,2)=type;
  2074. WFIFOL(fd,6)=sd->status.luk;
  2075. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2076. len=14;
  2077. break;
  2078. case SP_CARTINFO:
  2079. WFIFOW(fd,0)=0x121;
  2080. WFIFOW(fd,2)=sd->cart_num;
  2081. WFIFOW(fd,4)=MAX_CART;
  2082. WFIFOL(fd,6)=sd->cart_weight;
  2083. WFIFOL(fd,10)=battle_config.max_cart_weight;
  2084. len=14;
  2085. break;
  2086. default:
  2087. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2088. return 1;
  2089. }
  2090. WFIFOSET(fd,len);
  2091. return 0;
  2092. }
  2093. int clif_changestatus(struct block_list *bl,int type,int val)
  2094. {
  2095. unsigned char buf[12];
  2096. struct map_session_data *sd = NULL;
  2097. nullpo_retr(0, bl);
  2098. if(bl->type == BL_PC)
  2099. sd = (struct map_session_data *)bl;
  2100. if(sd){
  2101. WBUFW(buf,0)=0x1ab;
  2102. WBUFL(buf,2)=bl->id;
  2103. WBUFW(buf,6)=type;
  2104. switch(type){
  2105. case SP_MANNER:
  2106. WBUFL(buf,8)=val;
  2107. break;
  2108. default:
  2109. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2110. return 1;
  2111. }
  2112. clif_send(buf,packet_len(0x1ab),bl,AREA_WOS);
  2113. }
  2114. return 0;
  2115. }
  2116. /*==========================================
  2117. *
  2118. *------------------------------------------*/
  2119. void clif_changelook(struct block_list *bl,int type,int val)
  2120. {
  2121. unsigned char buf[16];
  2122. struct map_session_data* sd = NULL;
  2123. struct view_data* vd;
  2124. nullpo_retv(bl);
  2125. sd = BL_CAST(BL_PC, bl);
  2126. vd = status_get_viewdata(bl);
  2127. //nullpo_ret(vd);
  2128. if( vd ) //temp hack to let Warp Portal change appearance
  2129. switch(type)
  2130. {
  2131. case LOOK_WEAPON:
  2132. if (sd)
  2133. {
  2134. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2135. val = vd->weapon;
  2136. }
  2137. else vd->weapon = val;
  2138. break;
  2139. case LOOK_SHIELD:
  2140. if (sd)
  2141. {
  2142. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2143. val = vd->shield;
  2144. }
  2145. else vd->shield = val;
  2146. break;
  2147. case LOOK_BASE:
  2148. vd->class_ = val;
  2149. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2150. vd->weapon = vd->shield = 0;
  2151. if (vd->cloth_color && (
  2152. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2153. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2154. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2155. ))
  2156. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2157. break;
  2158. case LOOK_HAIR:
  2159. vd->hair_style = val;
  2160. break;
  2161. case LOOK_HEAD_BOTTOM:
  2162. vd->head_bottom = val;
  2163. break;
  2164. case LOOK_HEAD_TOP:
  2165. vd->head_top = val;
  2166. break;
  2167. case LOOK_HEAD_MID:
  2168. vd->head_mid = val;
  2169. break;
  2170. case LOOK_HAIR_COLOR:
  2171. vd->hair_color = val;
  2172. break;
  2173. case LOOK_CLOTHES_COLOR:
  2174. if (val && (
  2175. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2176. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2177. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2178. ))
  2179. val = 0;
  2180. vd->cloth_color = val;
  2181. break;
  2182. case LOOK_SHOES:
  2183. #if PACKETVER > 3
  2184. if (sd) {
  2185. int n;
  2186. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2187. if(sd->inventory_data[n]->view_id > 0)
  2188. val = sd->inventory_data[n]->view_id;
  2189. else
  2190. val = sd->status.inventory[n].nameid;
  2191. }
  2192. val = 0;
  2193. }
  2194. #endif
  2195. //Shoes? No packet uses this....
  2196. break;
  2197. }
  2198. #if PACKETVER < 4
  2199. WBUFW(buf,0)=0xc3;
  2200. WBUFL(buf,2)=bl->id;
  2201. WBUFB(buf,6)=type;
  2202. WBUFB(buf,7)=val;
  2203. clif_send(buf,packet_len(0xc3),bl,AREA);
  2204. #else
  2205. WBUFW(buf,0)=0x1d7;
  2206. WBUFL(buf,2)=bl->id;
  2207. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2208. WBUFB(buf,6)=LOOK_WEAPON;
  2209. WBUFW(buf,7)=vd->weapon;
  2210. WBUFW(buf,9)=vd->shield;
  2211. } else {
  2212. WBUFB(buf,6)=type;
  2213. WBUFW(buf,7)=val;
  2214. WBUFW(buf,9)=0;
  2215. }
  2216. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2217. #endif
  2218. }
  2219. //Sends a change-base-look packet required for traps as they are triggered.
  2220. void clif_changetraplook(struct block_list *bl,int val)
  2221. {
  2222. unsigned char buf[32];
  2223. #if PACKETVER < 4
  2224. WBUFW(buf,0)=0xc3;
  2225. WBUFL(buf,2)=bl->id;
  2226. WBUFB(buf,6)=LOOK_BASE;
  2227. WBUFB(buf,7)=val;
  2228. clif_send(buf,packet_len(0xc3),bl,AREA);
  2229. #else
  2230. WBUFW(buf,0)=0x1d7;
  2231. WBUFL(buf,2)=bl->id;
  2232. WBUFB(buf,6)=LOOK_BASE;
  2233. WBUFW(buf,7)=val;
  2234. WBUFW(buf,9)=0;
  2235. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2236. #endif
  2237. }
  2238. //For the stupid cloth-dye bug. Resends the given view data
  2239. //to the area specified by bl.
  2240. void clif_refreshlook(struct block_list *bl,int id,int type,int val,int area)
  2241. {
  2242. unsigned char buf[32];
  2243. #if PACKETVER < 4
  2244. WBUFW(buf,0)=0xc3;
  2245. WBUFL(buf,2)=id;
  2246. WBUFB(buf,6)=type;
  2247. WBUFB(buf,7)=val;
  2248. clif_send(buf,packet_len(0xc3),bl,area);
  2249. #else
  2250. WBUFW(buf,0)=0x1d7;
  2251. WBUFL(buf,2)=id;
  2252. WBUFB(buf,6)=type;
  2253. WBUFW(buf,7)=val;
  2254. WBUFW(buf,9)=0;
  2255. clif_send(buf,packet_len(0x1d7),bl,area);
  2256. #endif
  2257. return;
  2258. }
  2259. /*==========================================
  2260. *
  2261. *------------------------------------------*/
  2262. int clif_initialstatus(struct map_session_data *sd)
  2263. {
  2264. int fd;
  2265. unsigned char *buf;
  2266. nullpo_retr(0, sd);
  2267. fd=sd->fd;
  2268. WFIFOHEAD(fd,packet_len(0xbd));
  2269. buf=WFIFOP(fd,0);
  2270. WBUFW(buf,0)=0xbd;
  2271. WBUFW(buf,2)=min(sd->status.status_point, SHRT_MAX);
  2272. WBUFB(buf,4)=min(sd->status.str, UCHAR_MAX);
  2273. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2274. WBUFB(buf,6)=min(sd->status.agi, UCHAR_MAX);
  2275. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2276. WBUFB(buf,8)=min(sd->status.vit, UCHAR_MAX);
  2277. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2278. WBUFB(buf,10)=min(sd->status.int_, UCHAR_MAX);
  2279. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2280. WBUFB(buf,12)=min(sd->status.dex, UCHAR_MAX);
  2281. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2282. WBUFB(buf,14)=min(sd->status.luk, UCHAR_MAX);
  2283. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2284. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw.atk;
  2285. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2; //atk bonus
  2286. WBUFW(buf,20) = sd->battle_status.matk_max;
  2287. WBUFW(buf,22) = sd->battle_status.matk_min;
  2288. WBUFW(buf,24) = sd->battle_status.def; // def
  2289. WBUFW(buf,26) = sd->battle_status.def2;
  2290. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2291. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2292. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2293. WBUFW(buf,30) = fd;
  2294. fd = sd->fd;
  2295. WBUFW(buf,32) = sd->battle_status.hit;
  2296. WBUFW(buf,34) = sd->battle_status.flee;
  2297. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2298. WBUFW(buf,38) = sd->battle_status.cri/10;
  2299. WBUFW(buf,40) = sd->status.karma;
  2300. WBUFW(buf,42) = sd->status.manner;
  2301. WFIFOSET(fd,packet_len(0xbd));
  2302. clif_updatestatus(sd,SP_STR);
  2303. clif_updatestatus(sd,SP_AGI);
  2304. clif_updatestatus(sd,SP_VIT);
  2305. clif_updatestatus(sd,SP_INT);
  2306. clif_updatestatus(sd,SP_DEX);
  2307. clif_updatestatus(sd,SP_LUK);
  2308. clif_updatestatus(sd,SP_ATTACKRANGE);
  2309. clif_updatestatus(sd,SP_ASPD);
  2310. return 0;
  2311. }
  2312. /*==========================================
  2313. *矢装備
  2314. *------------------------------------------*/
  2315. int clif_arrowequip(struct map_session_data *sd,int val)
  2316. {
  2317. int fd;
  2318. nullpo_retr(0, sd);
  2319. pc_stop_attack(sd); // [Valaris]
  2320. fd=sd->fd;
  2321. WFIFOHEAD(fd, packet_len(0x013c));
  2322. WFIFOW(fd,0)=0x013c;
  2323. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2324. WFIFOSET(fd,packet_len(0x013c));
  2325. return 0;
  2326. }
  2327. /// Ammunition action message.
  2328. /// type=0 : MsgStringTable[242]="Please equip the proper ammunition first."
  2329. /// type=1 : MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2330. /// type=2 : MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2331. /// type=3 : assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2332. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2333. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2334. int clif_arrow_fail(struct map_session_data *sd,int type)
  2335. {
  2336. int fd;
  2337. nullpo_retr(0, sd);
  2338. fd=sd->fd;
  2339. WFIFOHEAD(fd, packet_len(0x013b));
  2340. WFIFOW(fd,0)=0x013b;
  2341. WFIFOW(fd,2)=type;
  2342. WFIFOSET(fd,packet_len(0x013b));
  2343. return 0;
  2344. }
  2345. /*==========================================
  2346. * 作成可能 矢リスト送信
  2347. *------------------------------------------*/
  2348. int clif_arrow_create_list(struct map_session_data *sd)
  2349. {
  2350. int i, c, j;
  2351. int fd;
  2352. nullpo_retr(0, sd);
  2353. fd = sd->fd;
  2354. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2355. WFIFOW(fd,0) = 0x1ad;
  2356. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2357. if (skill_arrow_db[i].nameid > 0 &&
  2358. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2359. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2360. {
  2361. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2362. WFIFOW(fd,c*2+4) = j;
  2363. else
  2364. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2365. c++;
  2366. }
  2367. }
  2368. WFIFOW(fd,2) = c*2+4;
  2369. WFIFOSET(fd, WFIFOW(fd,2));
  2370. if (c > 0) {
  2371. sd->menuskill_id = AC_MAKINGARROW;
  2372. sd->menuskill_val = c;
  2373. }
  2374. return 0;
  2375. }
  2376. /*==========================================
  2377. *
  2378. *------------------------------------------*/
  2379. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2380. {
  2381. int fd;
  2382. nullpo_retr(0, sd);
  2383. fd=sd->fd;
  2384. WFIFOHEAD(fd,packet_len(0xbc));
  2385. WFIFOW(fd,0)=0xbc;
  2386. WFIFOW(fd,2)=type;
  2387. WFIFOB(fd,4)=ok;
  2388. WFIFOB(fd,5)=val;
  2389. WFIFOSET(fd,packet_len(0xbc));
  2390. return 0;
  2391. }
  2392. /*==========================================
  2393. *
  2394. *------------------------------------------*/
  2395. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2396. {
  2397. int fd;
  2398. nullpo_retr(0, sd);
  2399. fd=sd->fd;
  2400. WFIFOHEAD(fd,packet_len(0xaa));
  2401. WFIFOW(fd,0)=0xaa;
  2402. WFIFOW(fd,2)=n+2;
  2403. WFIFOW(fd,4)=pos;
  2404. WFIFOB(fd,6)=ok;
  2405. WFIFOSET(fd,packet_len(0xaa));
  2406. return 0;
  2407. }
  2408. /*==========================================
  2409. *
  2410. *------------------------------------------*/
  2411. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2412. {
  2413. int fd;
  2414. nullpo_retr(0, sd);
  2415. fd=sd->fd;
  2416. WFIFOHEAD(fd,packet_len(0xac));
  2417. WFIFOW(fd,0)=0xac;
  2418. WFIFOW(fd,2)=n+2;
  2419. WFIFOW(fd,4)=pos;
  2420. WFIFOB(fd,6)=ok;
  2421. WFIFOSET(fd,packet_len(0xac));
  2422. return 0;
  2423. }
  2424. /*==========================================
  2425. *
  2426. *------------------------------------------*/
  2427. int clif_misceffect(struct block_list* bl,int type)
  2428. {
  2429. unsigned char buf[32];
  2430. nullpo_retr(0, bl);
  2431. WBUFW(buf,0) = 0x19b;
  2432. WBUFL(buf,2) = bl->id;
  2433. WBUFL(buf,6) = type;
  2434. clif_send(buf,packet_len(0x19b),bl,AREA);
  2435. return 0;
  2436. }
  2437. int clif_misceffect2(struct block_list *bl, int type)
  2438. {
  2439. unsigned char buf[24];
  2440. nullpo_retr(0, bl);
  2441. memset(buf, 0, packet_len(0x1f3));
  2442. WBUFW(buf,0) = 0x1f3;
  2443. WBUFL(buf,2) = bl->id;
  2444. WBUFL(buf,6) = type;
  2445. clif_send(buf, packet_len(0x1f3), bl, AREA);
  2446. return 0;
  2447. }
  2448. /*==========================================
  2449. * 表示オプション変更
  2450. *------------------------------------------*/
  2451. int clif_changeoption(struct block_list* bl)
  2452. {
  2453. unsigned char buf[32];
  2454. struct status_change *sc;
  2455. nullpo_retr(0, bl);
  2456. sc = status_get_sc(bl);
  2457. if (!sc) return 0; //How can an option change if there's no sc?
  2458. #if PACKETVER >= 7
  2459. WBUFW(buf,0) = 0x229;
  2460. WBUFL(buf,2) = bl->id;
  2461. WBUFW(buf,6) = sc->opt1;
  2462. WBUFW(buf,8) = sc->opt2;
  2463. WBUFL(buf,10) = sc->option;
  2464. WBUFB(buf,14) = 0; // PK???
  2465. if(disguised(bl)) {
  2466. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2467. WBUFL(buf,2) = -bl->id;
  2468. clif_send(buf,packet_len(0x229),bl,SELF);
  2469. WBUFL(buf,2) = bl->id;
  2470. WBUFL(buf,10) = OPTION_INVISIBLE;
  2471. clif_send(buf,packet_len(0x229),bl,SELF);
  2472. } else
  2473. clif_send(buf,packet_len(0x229),bl,AREA);
  2474. #else
  2475. WBUFW(buf,0) = 0x119;
  2476. WBUFL(buf,2) = bl->id;
  2477. WBUFW(buf,6) = sc->opt1;
  2478. WBUFW(buf,8) = sc->opt2;
  2479. WBUFW(buf,10) = sc->option;
  2480. WBUFB(buf,12) = 0; // ??
  2481. if(disguised(bl)) {
  2482. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2483. WBUFL(buf,2) = -bl->id;
  2484. clif_send(buf,packet_len(0x119),bl,SELF);
  2485. WBUFL(buf,2) = bl->id;
  2486. WBUFW(buf,10) = OPTION_INVISIBLE;
  2487. clif_send(buf,packet_len(0x119),bl,SELF);
  2488. } else
  2489. clif_send(buf,packet_len(0x119),bl,AREA);
  2490. #endif
  2491. return 0;
  2492. }
  2493. int clif_changeoption2(struct block_list* bl)
  2494. {
  2495. unsigned char buf[20];
  2496. struct status_change *sc;
  2497. sc = status_get_sc(bl);
  2498. if (!sc) return 0; //How can an option change if there's no sc?
  2499. WBUFW(buf,0) = 0x28a;
  2500. WBUFL(buf,2) = bl->id;
  2501. WBUFL(buf,6) = sc->option;
  2502. WBUFL(buf,10) = clif_setlevel(status_get_lv(bl));
  2503. WBUFL(buf,14) = sc->opt3;
  2504. if(disguised(bl)) {
  2505. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  2506. WBUFL(buf,2) = -bl->id;
  2507. clif_send(buf,packet_len(0x28a),bl,SELF);
  2508. WBUFL(buf,2) = bl->id;
  2509. WBUFL(buf,6) = OPTION_INVISIBLE;
  2510. clif_send(buf,packet_len(0x28a),bl,SELF);
  2511. } else
  2512. clif_send(buf,packet_len(0x28a),bl,AREA);
  2513. return 0;
  2514. }
  2515. /*==========================================
  2516. *
  2517. *------------------------------------------*/
  2518. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2519. {
  2520. nullpo_retr(0, sd);
  2521. if(!ok) {
  2522. int fd=sd->fd;
  2523. WFIFOHEAD(fd,packet_len(0xa8));
  2524. WFIFOW(fd,0)=0xa8;
  2525. WFIFOW(fd,2)=index+2;
  2526. WFIFOW(fd,4)=amount;
  2527. WFIFOB(fd,6)=ok;
  2528. WFIFOSET(fd,packet_len(0xa8));
  2529. }
  2530. else {
  2531. #if PACKETVER < 3
  2532. int fd=sd->fd;
  2533. WFIFOHEAD(fd,packet_len(0xa8));
  2534. WFIFOW(fd,0)=0xa8;
  2535. WFIFOW(fd,2)=index+2;
  2536. WFIFOW(fd,4)=amount;
  2537. WFIFOB(fd,6)=ok;
  2538. WFIFOSET(fd,packet_len(0xa8));
  2539. #else
  2540. unsigned char buf[32];
  2541. WBUFW(buf,0)=0x1c8;
  2542. WBUFW(buf,2)=index+2;
  2543. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2544. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2545. else
  2546. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2547. WBUFL(buf,6)=sd->bl.id;
  2548. WBUFW(buf,10)=amount;
  2549. WBUFB(buf,12)=ok;
  2550. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2551. #endif
  2552. }
  2553. return 0;
  2554. }
  2555. /*==========================================
  2556. * Inform client whether chatroom creation was successful or not
  2557. * R 00d6 <fail>.B
  2558. *------------------------------------------*/
  2559. void clif_createchat(struct map_session_data* sd, int fail)
  2560. {
  2561. int fd;
  2562. nullpo_retv(sd);
  2563. fd = sd->fd;
  2564. WFIFOHEAD(fd,packet_len(0xd6));
  2565. WFIFOW(fd,0) = 0xd6;
  2566. WFIFOB(fd,2) = fail;
  2567. WFIFOSET(fd,packet_len(0xd6));
  2568. }
  2569. /*==========================================
  2570. * Display a chat above the owner
  2571. * R 00d7 <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <type>.B <title>.?B
  2572. *------------------------------------------*/
  2573. int clif_dispchat(struct chat_data* cd, int fd)
  2574. {
  2575. unsigned char buf[128];
  2576. uint8 type;
  2577. if( cd == NULL || cd->owner == NULL )
  2578. return 1;
  2579. // type - 0: private, 1: public, 2: npc, 3: non-clickable
  2580. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  2581. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  2582. : 1;
  2583. WBUFW(buf, 0) = 0xd7;
  2584. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2585. WBUFL(buf, 4) = cd->owner->id;
  2586. WBUFL(buf, 8) = cd->bl.id;
  2587. WBUFW(buf,12) = cd->limit;
  2588. WBUFW(buf,14) = cd->users;
  2589. WBUFB(buf,16) = type;
  2590. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2591. if( fd ) {
  2592. WFIFOHEAD(fd,WBUFW(buf,2));
  2593. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2594. WFIFOSET(fd,WBUFW(buf,2));
  2595. } else {
  2596. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  2597. }
  2598. return 0;
  2599. }
  2600. /*==========================================
  2601. * Chatroom properties adjustment
  2602. * R 00df <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <pub>.B <title>.?B
  2603. *------------------------------------------*/
  2604. int clif_changechatstatus(struct chat_data* cd)
  2605. {
  2606. unsigned char buf[128];
  2607. if( cd == NULL || cd->usersd[0] == NULL )
  2608. return 1;
  2609. WBUFW(buf, 0) = 0xdf;
  2610. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2611. WBUFL(buf, 4) = cd->usersd[0]->bl.id;
  2612. WBUFL(buf, 8) = cd->bl.id;
  2613. WBUFW(buf,12) = cd->limit;
  2614. WBUFW(buf,14) = cd->users;
  2615. WBUFB(buf,16) = cd->pub;
  2616. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2617. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2618. return 0;
  2619. }
  2620. /*==========================================
  2621. *
  2622. *------------------------------------------*/
  2623. int clif_clearchat(struct chat_data *cd,int fd)
  2624. {
  2625. unsigned char buf[32];
  2626. nullpo_retr(0, cd);
  2627. WBUFW(buf,0) = 0xd8;
  2628. WBUFL(buf,2) = cd->bl.id;
  2629. if( fd ) {
  2630. WFIFOHEAD(fd,packet_len(0xd8));
  2631. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2632. WFIFOSET(fd,packet_len(0xd8));
  2633. } else {
  2634. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  2635. }
  2636. return 0;
  2637. }
  2638. /*==========================================
  2639. *
  2640. *------------------------------------------*/
  2641. int clif_joinchatfail(struct map_session_data *sd,int fail)
  2642. {
  2643. int fd;
  2644. nullpo_retr(0, sd);
  2645. fd = sd->fd;
  2646. WFIFOHEAD(fd,packet_len(0xda));
  2647. WFIFOW(fd,0) = 0xda;
  2648. WFIFOB(fd,2) = fail;
  2649. WFIFOSET(fd,packet_len(0xda));
  2650. return 0;
  2651. }
  2652. /*==========================================
  2653. *
  2654. *------------------------------------------*/
  2655. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2656. {
  2657. int fd;
  2658. int i;
  2659. nullpo_retr(0, sd);
  2660. nullpo_retr(0, cd);
  2661. fd = sd->fd;
  2662. if (!session_isActive(fd))
  2663. return 0;
  2664. WFIFOHEAD(fd, 8 + (28*cd->users));
  2665. WFIFOW(fd, 0) = 0xdb;
  2666. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2667. WFIFOL(fd, 4) = cd->bl.id;
  2668. for (i = 0; i < cd->users; i++) {
  2669. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  2670. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2671. }
  2672. WFIFOSET(fd, WFIFOW(fd, 2));
  2673. return 0;
  2674. }
  2675. /*==========================================
  2676. *
  2677. *------------------------------------------*/
  2678. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2679. {
  2680. unsigned char buf[32];
  2681. nullpo_retr(0, sd);
  2682. nullpo_retr(0, cd);
  2683. WBUFW(buf, 0) = 0x0dc;
  2684. WBUFW(buf, 2) = cd->users;
  2685. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2686. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  2687. return 0;
  2688. }
  2689. /*==========================================
  2690. * Announce the new owner
  2691. * R 00e1 <index>.l <nick>.24B
  2692. *------------------------------------------*/
  2693. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  2694. {
  2695. unsigned char buf[64];
  2696. nullpo_retv(sd);
  2697. nullpo_retv(cd);
  2698. //FIXME: this announces a swap between positions 0 and 1 (probably not what we want) [ultramage]
  2699. //FIXME: aegis sends obviously incorrect packets; need to figure out what to send to display it correctly :X
  2700. //TODO: is it just owner swap, or can it do general-purpose reordering?
  2701. WBUFW(buf, 0) = 0xe1;
  2702. WBUFL(buf, 2) = 1;
  2703. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2704. WBUFW(buf,30) = 0xe1;
  2705. WBUFL(buf,32) = 0;
  2706. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2707. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  2708. }
  2709. /*==========================================
  2710. * Notify about user leaving the chatroom
  2711. * R 00dd <index>.w <nick>.24B <flag>.B
  2712. *------------------------------------------*/
  2713. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  2714. {
  2715. unsigned char buf[32];
  2716. nullpo_retv(sd);
  2717. nullpo_retv(cd);
  2718. WBUFW(buf, 0) = 0xdd;
  2719. WBUFW(buf, 2) = cd->users-1;
  2720. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2721. WBUFB(buf,28) = flag; // 0: left, 1: was kicked
  2722. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  2723. }
  2724. /*==========================================
  2725. * Opens a trade request window from char 'name'
  2726. * R 00e5 <nick>.24B
  2727. * R 01f4 <nick>.24B <charid>.L <baselvl>.W
  2728. *------------------------------------------*/
  2729. void clif_traderequest(struct map_session_data* sd, const char* name)
  2730. {
  2731. int fd = sd->fd;
  2732. #if PACKETVER < 6
  2733. WFIFOHEAD(fd,packet_len(0xe5));
  2734. WFIFOW(fd,0) = 0xe5;
  2735. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2736. WFIFOSET(fd,packet_len(0xe5));
  2737. #else
  2738. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2739. if( !tsd ) return;
  2740. WFIFOHEAD(fd,packet_len(0x1f4));
  2741. WFIFOW(fd,0) = 0x1f4;
  2742. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2743. WFIFOL(fd,26) = tsd->status.char_id;
  2744. WFIFOW(fd,30) = clif_setlevel(tsd->status.base_level);
  2745. WFIFOSET(fd,packet_len(0x1f4));
  2746. #endif
  2747. }
  2748. /*==========================================
  2749. * Reply to a trade-request.
  2750. * R 00e7 <type>.B
  2751. * R 01f5 <type>.B <charid>.L <baselvl>.W
  2752. * Type:
  2753. * 0: Char is too far
  2754. * 1: Character does not exist
  2755. * 2: Trade failed
  2756. * 3: Accept
  2757. * 4: Cancel
  2758. *------------------------------------------*/
  2759. void clif_tradestart(struct map_session_data* sd, uint8 type)
  2760. {
  2761. int fd = sd->fd;
  2762. #if PACKETVER < 6
  2763. WFIFOHEAD(fd,packet_len(0xe7));
  2764. WFIFOW(fd,0) = 0xe7;
  2765. WFIFOB(fd,2) = type;
  2766. WFIFOSET(fd,packet_len(0xe7));
  2767. #else
  2768. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2769. if( !tsd ) return;
  2770. WFIFOHEAD(fd,packet_len(0x1f5));
  2771. WFIFOW(fd,0) = 0x1f5;
  2772. WFIFOB(fd,2) = type;
  2773. WFIFOL(fd,3) = tsd->status.char_id;
  2774. WFIFOW(fd,7) = clif_setlevel(tsd->status.base_level);
  2775. WFIFOSET(fd,packet_len(0x1f5));
  2776. #endif
  2777. }
  2778. /*==========================================
  2779. * 相手方からのアイテム追加
  2780. *------------------------------------------*/
  2781. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  2782. {
  2783. int fd;
  2784. nullpo_retv(sd);
  2785. nullpo_retv(tsd);
  2786. fd = tsd->fd;
  2787. WFIFOHEAD(fd,packet_len(0xe9));
  2788. WFIFOW(fd,0) = 0xe9;
  2789. WFIFOL(fd,2) = amount;
  2790. if( index == 0 )
  2791. {
  2792. WFIFOW(fd,6) = 0; // type id
  2793. WFIFOB(fd,8) = 0; //identify flag
  2794. WFIFOB(fd,9) = 0; // attribute
  2795. WFIFOB(fd,10)= 0; //refine
  2796. WFIFOW(fd,11)= 0; //card (4w)
  2797. WFIFOW(fd,13)= 0; //card (4w)
  2798. WFIFOW(fd,15)= 0; //card (4w)
  2799. WFIFOW(fd,17)= 0; //card (4w)
  2800. }
  2801. else
  2802. {
  2803. index -= 2; //index fix
  2804. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2805. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  2806. else
  2807. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  2808. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  2809. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  2810. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  2811. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  2812. }
  2813. WFIFOSET(fd,packet_len(0xe9));
  2814. }
  2815. /*==========================================
  2816. * アイテム追加成功/失敗
  2817. *------------------------------------------*/
  2818. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  2819. {
  2820. int fd;
  2821. nullpo_retv(sd);
  2822. fd = sd->fd;
  2823. WFIFOHEAD(fd,packet_len(0xea));
  2824. WFIFOW(fd,0) = 0xea;
  2825. WFIFOW(fd,2) = index;
  2826. WFIFOB(fd,4) = fail;
  2827. WFIFOSET(fd,packet_len(0xea));
  2828. }
  2829. /*==========================================
  2830. * 取り引きok押し
  2831. *------------------------------------------*/
  2832. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  2833. {
  2834. int fd;
  2835. nullpo_retv(sd);
  2836. fd = sd->fd;
  2837. WFIFOHEAD(fd,packet_len(0xec));
  2838. WFIFOW(fd,0) = 0xec;
  2839. WFIFOB(fd,2) = fail; // 0=you 1=the other person
  2840. WFIFOSET(fd,packet_len(0xec));
  2841. }
  2842. /*==========================================
  2843. * 取り引きがキャンセルされました
  2844. *------------------------------------------*/
  2845. void clif_tradecancelled(struct map_session_data* sd)
  2846. {
  2847. int fd;
  2848. nullpo_retv(sd);
  2849. fd = sd->fd;
  2850. WFIFOHEAD(fd,packet_len(0xee));
  2851. WFIFOW(fd,0) = 0xee;
  2852. WFIFOSET(fd,packet_len(0xee));
  2853. }
  2854. /*==========================================
  2855. * 取り引き完了
  2856. *------------------------------------------*/
  2857. void clif_tradecompleted(struct map_session_data* sd, int fail)
  2858. {
  2859. int fd;
  2860. nullpo_retv(sd);
  2861. fd = sd->fd;
  2862. WFIFOHEAD(fd,packet_len(0xf0));
  2863. WFIFOW(fd,0) = 0xf0;
  2864. WFIFOB(fd,2) = fail;
  2865. WFIFOSET(fd,packet_len(0xf0));
  2866. }
  2867. /*==========================================
  2868. * カプラ倉庫のアイテム数を更新
  2869. *------------------------------------------*/
  2870. int clif_updatestorageamount(struct map_session_data *sd,struct storage *stor)
  2871. {
  2872. int fd;
  2873. nullpo_retr(0, sd);
  2874. nullpo_retr(0, stor);
  2875. fd=sd->fd;
  2876. WFIFOHEAD(fd,packet_len(0xf2));
  2877. WFIFOW(fd,0) = 0xf2; // update storage amount
  2878. WFIFOW(fd,2) = stor->storage_amount; //items
  2879. WFIFOW(fd,4) = MAX_STORAGE; //items max
  2880. WFIFOSET(fd,packet_len(0xf2));
  2881. return 0;
  2882. }
  2883. /*==========================================
  2884. * カプラ倉庫にアイテムを追加する
  2885. *------------------------------------------*/
  2886. int clif_storageitemadded(struct map_session_data *sd,struct storage *stor,int index,int amount)
  2887. {
  2888. int view,fd;
  2889. nullpo_retr(0, sd);
  2890. nullpo_retr(0, stor);
  2891. fd=sd->fd;
  2892. WFIFOHEAD(fd,packet_len(0xf4));
  2893. WFIFOW(fd,0) =0xf4; // Storage item added
  2894. WFIFOW(fd,2) =index+1; // index
  2895. WFIFOL(fd,4) =amount; // amount
  2896. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  2897. WFIFOW(fd,8) =view;
  2898. else
  2899. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  2900. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  2901. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  2902. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  2903. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  2904. WFIFOSET(fd,packet_len(0xf4));
  2905. return 0;
  2906. }
  2907. /*==========================================
  2908. *
  2909. *------------------------------------------*/
  2910. int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor)
  2911. {
  2912. int fd;
  2913. nullpo_retr(0, sd);
  2914. nullpo_retr(0, stor);
  2915. fd=sd->fd;
  2916. WFIFOHEAD(fd,packet_len(0xf2));
  2917. WFIFOW(fd,0) = 0xf2; // update storage amount
  2918. WFIFOW(fd,2) = stor->storage_amount; //items
  2919. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  2920. WFIFOSET(fd,packet_len(0xf2));
  2921. return 0;
  2922. }
  2923. /*==========================================
  2924. *
  2925. *------------------------------------------*/
  2926. int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount)
  2927. {
  2928. int view,fd;
  2929. nullpo_retr(0, sd);
  2930. nullpo_retr(0, stor);
  2931. fd=sd->fd;
  2932. WFIFOHEAD(fd,packet_len(0xf4));
  2933. WFIFOW(fd,0) =0xf4; // Storage item added
  2934. WFIFOW(fd,2) =index+1; // index
  2935. WFIFOL(fd,4) =amount; // amount
  2936. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  2937. WFIFOW(fd,8) =view;
  2938. else
  2939. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  2940. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  2941. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  2942. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  2943. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  2944. WFIFOSET(fd,packet_len(0xf4));
  2945. return 0;
  2946. }
  2947. /*==========================================
  2948. * カプラ倉庫からアイテムを取り去る
  2949. *------------------------------------------*/
  2950. int clif_storageitemremoved(struct map_session_data *sd,int index,int amount)
  2951. {
  2952. int fd;
  2953. nullpo_retr(0, sd);
  2954. fd=sd->fd;
  2955. WFIFOHEAD(fd,packet_len(0xf6));
  2956. WFIFOW(fd,0)=0xf6; // Storage item removed
  2957. WFIFOW(fd,2)=index+1;
  2958. WFIFOL(fd,4)=amount;
  2959. WFIFOSET(fd,packet_len(0xf6));
  2960. return 0;
  2961. }
  2962. /*==========================================
  2963. * カプラ倉庫を閉じる
  2964. *------------------------------------------*/
  2965. int clif_storageclose(struct map_session_data *sd)
  2966. {
  2967. int fd;
  2968. nullpo_retr(0, sd);
  2969. fd=sd->fd;
  2970. WFIFOHEAD(fd,packet_len(0xf8));
  2971. WFIFOW(fd,0)=0xf8; // Storage Closed
  2972. WFIFOSET(fd,packet_len(0xf8));
  2973. return 0;
  2974. }
  2975. /*==========================================
  2976. * PC表示
  2977. *------------------------------------------*/
  2978. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  2979. {
  2980. int gmlvl;
  2981. int i;
  2982. if(dstsd->chatID)
  2983. {
  2984. struct chat_data *cd;
  2985. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  2986. if(cd && cd->usersd[0]==dstsd)
  2987. clif_dispchat(cd,sd->fd);
  2988. }
  2989. if(dstsd->vender_id)
  2990. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  2991. if(dstsd->spiritball > 0)
  2992. clif_spiritball_single(sd->fd, dstsd);
  2993. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  2994. (battle_config.disp_hpmeter && (gmlvl = pc_isGM(sd)) >= battle_config.disp_hpmeter && gmlvl >= pc_isGM(dstsd))
  2995. )
  2996. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  2997. // display links to devoted chars for crusader
  2998. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  2999. if( i < 5 ) clif_devotion(sd, sd);
  3000. // display links to devoted chars for others
  3001. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  3002. if( i < 5 ) clif_devotion(dstsd, sd);
  3003. // pvp circle for duel [LuzZza]
  3004. //if(dstsd->duel_group)
  3005. // clif_specialeffect(&dstsd->bl, 159, 4);
  3006. }
  3007. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3008. {
  3009. uint8 buf[128];
  3010. struct unit_data *ud;
  3011. struct view_data *vd;
  3012. int len;
  3013. vd = status_get_viewdata(bl);
  3014. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3015. return;
  3016. ud = unit_bl2ud(bl);
  3017. len = ( ud && ud->walktimer != -1 ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3018. clif_send(buf,len,&sd->bl,SELF);
  3019. if (vd->cloth_color)
  3020. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3021. switch (bl->type)
  3022. {
  3023. case BL_PC:
  3024. {
  3025. TBL_PC* tsd = (TBL_PC*)bl;
  3026. clif_getareachar_pc(sd, tsd);
  3027. if(tsd->state.size==2) // tiny/big players [Valaris]
  3028. clif_specialeffect_single(bl,423,sd->fd);
  3029. else if(tsd->state.size==1)
  3030. clif_specialeffect_single(bl,421,sd->fd);
  3031. }
  3032. break;
  3033. case BL_NPC:
  3034. {
  3035. TBL_NPC* nd = (TBL_NPC*)bl;
  3036. if( nd->chat_id )
  3037. clif_dispchat((struct chat_data*)map_id2bl(nd->chat_id),sd->fd);
  3038. }
  3039. break;
  3040. case BL_MOB:
  3041. {
  3042. TBL_MOB* md = (TBL_MOB*)bl;
  3043. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3044. clif_specialeffect_single(bl,423,sd->fd);
  3045. else if(md->special_state.size==1)
  3046. clif_specialeffect_single(bl,421,sd->fd);
  3047. }
  3048. break;
  3049. case BL_PET:
  3050. if (vd->head_bottom)
  3051. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3052. break;
  3053. }
  3054. }
  3055. /*==========================================
  3056. * Estimates walk delay based on the damage criteria. [Skotlex]
  3057. *------------------------------------------*/
  3058. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3059. {
  3060. if (type == 4 || type == 9 || damage <=0)
  3061. return 0;
  3062. if (bl->type == BL_PC) {
  3063. if (battle_config.pc_walk_delay_rate != 100)
  3064. delay = delay*battle_config.pc_walk_delay_rate/100;
  3065. } else
  3066. if (battle_config.walk_delay_rate != 100)
  3067. delay = delay*battle_config.walk_delay_rate/100;
  3068. if (div_ > 1) //Multi-hit skills mean higher delays.
  3069. delay += battle_config.multihit_delay*(div_-1);
  3070. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3071. }
  3072. /*==========================================
  3073. * Sends a 'damage' packet (src performs action on dst)
  3074. * 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
  3075. *
  3076. * type=00 damage [param1: total damage, param2: div, param3: assassin dual-wield damage]
  3077. * type=01 pick up item
  3078. * type=02 sit down
  3079. * type=03 stand up
  3080. * type=04 reflected/absorbed damage?
  3081. * type=08 double attack
  3082. * type=09 don't display flinch animation (endure)
  3083. * type=0a critical hit
  3084. * type=0b lucky dodge
  3085. *------------------------------------------*/
  3086. 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)
  3087. {
  3088. unsigned char buf[256];
  3089. struct status_change *sc;
  3090. nullpo_retr(0, src);
  3091. nullpo_retr(0, dst);
  3092. sc = status_get_sc(dst);
  3093. if(sc && sc->count) {
  3094. if(type != 4 && dst->type == BL_PC && sc->data[SC_ENDURE] && !map_flag_gvg(dst->m))
  3095. type = 9;
  3096. if(sc->data[SC_HALLUCINATION]) {
  3097. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3098. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3099. }
  3100. }
  3101. WBUFW(buf,0)=0x8a;
  3102. WBUFL(buf,2)=src->id;
  3103. WBUFL(buf,6)=dst->id;
  3104. WBUFL(buf,10)=tick;
  3105. WBUFL(buf,14)=sdelay;
  3106. WBUFL(buf,18)=ddelay;
  3107. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3108. WBUFW(buf,22)=damage?div:0;
  3109. WBUFW(buf,27)=damage2?div:0;
  3110. } else {
  3111. WBUFW(buf,22)=min(damage, SHRT_MAX);
  3112. WBUFW(buf,27)=damage2;
  3113. }
  3114. WBUFW(buf,24)=div;
  3115. WBUFB(buf,26)=type;
  3116. if(disguised(dst)) {
  3117. clif_send(buf,packet_len(0x8a),dst,AREA_WOS);
  3118. WBUFL(buf,6) = -dst->id;
  3119. clif_send(buf,packet_len(0x8a),dst,SELF);
  3120. } else
  3121. clif_send(buf,packet_len(0x8a),dst,AREA);
  3122. if(disguised(src)) {
  3123. WBUFL(buf,2) = -src->id;
  3124. if (disguised(dst))
  3125. WBUFL(buf,6) = dst->id;
  3126. if(damage > 0) WBUFW(buf,22) = -1;
  3127. if(damage2 > 0) WBUFW(buf,27) = -1;
  3128. clif_send(buf,packet_len(0x8a),src,SELF);
  3129. }
  3130. //Return adjusted can't walk delay for further processing.
  3131. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3132. }
  3133. /*==========================================
  3134. * src picks up dst
  3135. *------------------------------------------*/
  3136. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3137. {
  3138. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3139. unsigned char buf[32];
  3140. nullpo_retv(src);
  3141. nullpo_retv(dst);
  3142. WBUFW(buf, 0) = 0x8a;
  3143. WBUFL(buf, 2) = src->id;
  3144. WBUFL(buf, 6) = dst->id;
  3145. WBUFB(buf,26) = 1;
  3146. clif_send(buf, packet_len(0x8a), src, AREA);
  3147. }
  3148. /*==========================================
  3149. * inform clients in area that `bl` is sitting
  3150. *------------------------------------------*/
  3151. void clif_sitting(struct block_list* bl)
  3152. {
  3153. unsigned char buf[32];
  3154. nullpo_retv(bl);
  3155. WBUFW(buf, 0) = 0x8a;
  3156. WBUFL(buf, 2) = bl->id;
  3157. WBUFB(buf,26) = 2;
  3158. clif_send(buf, packet_len(0x8a), bl, AREA);
  3159. if(disguised(bl)) {
  3160. WBUFL(buf, 2) = - bl->id;
  3161. clif_send(buf, packet_len(0x8a), bl, SELF);
  3162. }
  3163. }
  3164. /*==========================================
  3165. * inform clients in area that `bl` is standing
  3166. *------------------------------------------*/
  3167. void clif_standing(struct block_list* bl)
  3168. {
  3169. unsigned char buf[32];
  3170. nullpo_retv(bl);
  3171. WBUFW(buf, 0) = 0x8a;
  3172. WBUFL(buf, 2) = bl->id;
  3173. WBUFB(buf,26) = 3;
  3174. clif_send(buf, packet_len(0x8a), bl, AREA);
  3175. if(disguised(bl)) {
  3176. WBUFL(buf, 2) = - bl->id;
  3177. clif_send(buf, packet_len(0x8a), bl, SELF);
  3178. }
  3179. }
  3180. /*==========================================
  3181. * Inform client(s) about a map-cell change
  3182. *------------------------------------------*/
  3183. void clif_changemapcell(int fd, int m, int x, int y, int type, enum send_target target)
  3184. {
  3185. unsigned char buf[32];
  3186. WBUFW(buf,0) = 0x192;
  3187. WBUFW(buf,2) = x;
  3188. WBUFW(buf,4) = y;
  3189. WBUFW(buf,6) = type;
  3190. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3191. if( fd )
  3192. {
  3193. WFIFOHEAD(fd,packet_len(0x192));
  3194. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3195. WFIFOSET(fd,packet_len(0x192));
  3196. }
  3197. else
  3198. {
  3199. struct block_list dummy_bl;
  3200. dummy_bl.type = BL_NUL;
  3201. dummy_bl.x = x;
  3202. dummy_bl.y = y;
  3203. dummy_bl.m = m;
  3204. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3205. }
  3206. }
  3207. /*==========================================
  3208. *
  3209. *------------------------------------------*/
  3210. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3211. {
  3212. int view,fd;
  3213. fd=sd->fd;
  3214. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3215. WFIFOHEAD(fd,packet_len(0x9d));
  3216. WFIFOW(fd,0)=0x9d;
  3217. WFIFOL(fd,2)=fitem->bl.id;
  3218. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3219. WFIFOW(fd,6)=view;
  3220. else
  3221. WFIFOW(fd,6)=fitem->item_data.nameid;
  3222. WFIFOB(fd,8)=fitem->item_data.identify;
  3223. WFIFOW(fd,9)=fitem->bl.x;
  3224. WFIFOW(fd,11)=fitem->bl.y;
  3225. WFIFOW(fd,13)=fitem->item_data.amount;
  3226. WFIFOB(fd,15)=fitem->subx;
  3227. WFIFOB(fd,16)=fitem->suby;
  3228. WFIFOSET(fd,packet_len(0x9d));
  3229. }
  3230. /*==========================================
  3231. * 場所スキルエフェクトが視界に入る
  3232. *------------------------------------------*/
  3233. static void clif_getareachar_skillunit(struct map_session_data *sd, struct skill_unit *unit)
  3234. {
  3235. int fd = sd->fd;
  3236. #if PACKETVER >= 3
  3237. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3238. WFIFOHEAD(fd,packet_len(0x1c9));
  3239. WFIFOW(fd, 0)=0x1c9;
  3240. WFIFOL(fd, 2)=unit->bl.id;
  3241. WFIFOL(fd, 6)=unit->group->src_id;
  3242. WFIFOW(fd,10)=unit->bl.x;
  3243. WFIFOW(fd,12)=unit->bl.y;
  3244. WFIFOB(fd,14)=unit->group->unit_id;
  3245. WFIFOB(fd,15)=1;
  3246. WFIFOB(fd,16)=1;
  3247. safestrncpy((char*)WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3248. WFIFOSET(fd,packet_len(0x1c9));
  3249. return;
  3250. }
  3251. #endif
  3252. WFIFOHEAD(fd,packet_len(0x11f));
  3253. WFIFOW(fd, 0)=0x11f;
  3254. WFIFOL(fd, 2)=unit->bl.id;
  3255. WFIFOL(fd, 6)=unit->group->src_id;
  3256. WFIFOW(fd,10)=unit->bl.x;
  3257. WFIFOW(fd,12)=unit->bl.y;
  3258. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3259. WFIFOB(fd,14)=UNT_ATTACK_SKILLS; //Use invisible unit id for traps.
  3260. else
  3261. WFIFOB(fd,14)=unit->group->unit_id;
  3262. WFIFOB(fd,15)=1; // ignored by client (always gets set to 1)
  3263. WFIFOSET(fd,packet_len(0x11f));
  3264. if(unit->group->skill_id == WZ_ICEWALL)
  3265. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  3266. }
  3267. /*==========================================
  3268. * 場所スキルエフェクトが視界から消える
  3269. *------------------------------------------*/
  3270. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3271. {
  3272. nullpo_retv(unit);
  3273. WFIFOHEAD(fd,packet_len(0x120));
  3274. WFIFOW(fd, 0)=0x120;
  3275. WFIFOL(fd, 2)=unit->bl.id;
  3276. WFIFOSET(fd,packet_len(0x120));
  3277. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3278. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  3279. }
  3280. /*==========================================
  3281. * 場所スキルエフェクト削除
  3282. *------------------------------------------*/
  3283. void clif_skill_delunit(struct skill_unit *unit)
  3284. {
  3285. unsigned char buf[16];
  3286. nullpo_retv(unit);
  3287. WBUFW(buf, 0)=0x120;
  3288. WBUFL(buf, 2)=unit->bl.id;
  3289. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3290. }
  3291. /*==========================================
  3292. * Unknown... trap related?
  3293. * Sent when an object gets ankle-snared
  3294. * Only affects units with class [139,153] client-side
  3295. * R 01ac <object id>.l
  3296. *------------------------------------------*/
  3297. void clif_01ac(struct block_list* bl)
  3298. {
  3299. unsigned char buf[6];
  3300. nullpo_retv(bl);
  3301. WBUFW(buf,0) = 0x1ac;
  3302. WBUFL(buf,2) = bl->id;
  3303. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3304. }
  3305. /*==========================================
  3306. *
  3307. *------------------------------------------*/
  3308. int clif_getareachar(struct block_list* bl,va_list ap)
  3309. {
  3310. struct map_session_data *sd;
  3311. nullpo_retr(0, bl);
  3312. nullpo_retr(0, ap);
  3313. sd=va_arg(ap,struct map_session_data*);
  3314. if (sd == NULL || !sd->fd)
  3315. return 0;
  3316. switch(bl->type){
  3317. case BL_ITEM:
  3318. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3319. break;
  3320. case BL_SKILL:
  3321. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3322. break;
  3323. default:
  3324. if(&sd->bl == bl)
  3325. break;
  3326. clif_getareachar_unit(sd,bl);
  3327. break;
  3328. }
  3329. return 0;
  3330. }
  3331. /*==========================================
  3332. * tbl has gone out of view-size of bl
  3333. *------------------------------------------*/
  3334. int clif_outsight(struct block_list *bl,va_list ap)
  3335. {
  3336. struct block_list *tbl;
  3337. struct view_data *vd;
  3338. TBL_PC *sd, *tsd;
  3339. tbl=va_arg(ap,struct block_list*);
  3340. if(bl == tbl) return 0;
  3341. sd = BL_CAST(BL_PC, bl);
  3342. tsd = BL_CAST(BL_PC, tbl);
  3343. if (tsd && tsd->fd)
  3344. { //tsd has lost sight of the bl object.
  3345. switch(bl->type){
  3346. case BL_PC:
  3347. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS)
  3348. clif_clearunit_single(bl->id,0,tsd->fd);
  3349. if(sd->chatID){
  3350. struct chat_data *cd;
  3351. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3352. if(cd->usersd[0]==sd)
  3353. clif_dispchat(cd,tsd->fd);
  3354. }
  3355. if(sd->vender_id)
  3356. clif_closevendingboard(bl,tsd->fd);
  3357. break;
  3358. case BL_ITEM:
  3359. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3360. break;
  3361. case BL_SKILL:
  3362. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3363. break;
  3364. default:
  3365. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3366. clif_clearunit_single(bl->id,0,tsd->fd);
  3367. break;
  3368. }
  3369. }
  3370. if (sd && sd->fd)
  3371. { //sd is watching tbl go out of view.
  3372. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3373. clif_clearunit_single(tbl->id,0,sd->fd);
  3374. }
  3375. return 0;
  3376. }
  3377. /*==========================================
  3378. * tbl has come into view of bl
  3379. *------------------------------------------*/
  3380. int clif_insight(struct block_list *bl,va_list ap)
  3381. {
  3382. struct block_list *tbl;
  3383. TBL_PC *sd, *tsd;
  3384. tbl=va_arg(ap,struct block_list*);
  3385. if (bl == tbl) return 0;
  3386. sd = BL_CAST(BL_PC, bl);
  3387. tsd = BL_CAST(BL_PC, tbl);
  3388. if (tsd && tsd->fd)
  3389. { //Tell tsd that bl entered into his view
  3390. switch(bl->type){
  3391. case BL_ITEM:
  3392. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3393. break;
  3394. case BL_SKILL:
  3395. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3396. break;
  3397. default:
  3398. clif_getareachar_unit(tsd,bl);
  3399. break;
  3400. }
  3401. }
  3402. if (sd && sd->fd)
  3403. { //Tell sd that tbl walked into his view
  3404. clif_getareachar_unit(sd,tbl);
  3405. }
  3406. return 0;
  3407. }
  3408. /*==========================================
  3409. *
  3410. *------------------------------------------*/
  3411. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3412. {
  3413. int fd,id;
  3414. nullpo_retr(0, sd);
  3415. fd=sd->fd;
  3416. if( (id=sd->status.skill[skillid].id) <= 0 )
  3417. return 0;
  3418. WFIFOHEAD(fd,packet_len(0x147));
  3419. WFIFOW(fd,0)=0x147;
  3420. WFIFOW(fd,2) = id;
  3421. if(type < 0)
  3422. WFIFOW(fd,4) = skill_get_inf(id);
  3423. else
  3424. WFIFOW(fd,4) = type;
  3425. WFIFOW(fd,6) = 0;
  3426. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3427. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3428. if(range < 0)
  3429. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3430. WFIFOW(fd,12)= range;
  3431. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3432. if(sd->status.skill[skillid].flag ==0)
  3433. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3434. else
  3435. WFIFOB(fd,38) = 0;
  3436. WFIFOSET(fd,packet_len(0x147));
  3437. return 0;
  3438. }
  3439. /*==========================================
  3440. * スキルリストを送信する
  3441. *------------------------------------------*/
  3442. int clif_skillinfoblock(struct map_session_data *sd)
  3443. {
  3444. int fd;
  3445. int i,c,len,id;
  3446. nullpo_retr(0, sd);
  3447. fd=sd->fd;
  3448. if (!fd) return 0;
  3449. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3450. WFIFOW(fd,0) = 0x10f;
  3451. for ( i = 0, c = 0, len = 4; i < MAX_SKILL; i++)
  3452. {
  3453. if( (id = sd->status.skill[i].id) != 0 )
  3454. {
  3455. WFIFOW(fd,len) = id;
  3456. WFIFOW(fd,len+2) = skill_get_inf(id);
  3457. WFIFOW(fd,len+4) = 0;
  3458. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3459. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3460. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3461. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3462. if(sd->status.skill[i].flag == 0)
  3463. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3464. else
  3465. WFIFOB(fd,len+36) = 0;
  3466. len += 37;
  3467. c++;
  3468. }
  3469. }
  3470. WFIFOW(fd,2)=len;
  3471. WFIFOSET(fd,len);
  3472. return 1;
  3473. }
  3474. /*==========================================
  3475. * スキル割り振り通知
  3476. *------------------------------------------*/
  3477. int clif_skillup(struct map_session_data *sd,int skill_num)
  3478. {
  3479. int fd;
  3480. nullpo_retr(0, sd);
  3481. fd=sd->fd;
  3482. WFIFOHEAD(fd,packet_len(0x10e));
  3483. WFIFOW(fd,0) = 0x10e;
  3484. WFIFOW(fd,2) = skill_num;
  3485. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3486. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3487. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3488. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3489. WFIFOSET(fd,packet_len(0x10e));
  3490. return 0;
  3491. }
  3492. /*==========================================
  3493. * スキル詠唱エフェクトを送信する
  3494. *------------------------------------------*/
  3495. int clif_skillcasting(struct block_list* bl,
  3496. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int pl, int casttime)
  3497. {
  3498. unsigned char buf[32];
  3499. WBUFW(buf,0) = 0x13e;
  3500. WBUFL(buf,2) = src_id;
  3501. WBUFL(buf,6) = dst_id;
  3502. WBUFW(buf,10) = dst_x;
  3503. WBUFW(buf,12) = dst_y;
  3504. WBUFW(buf,14) = skill_num;
  3505. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3506. WBUFL(buf,20) = casttime;
  3507. if (disguised(bl)) {
  3508. clif_send(buf,packet_len(0x13e), bl, AREA_WOS);
  3509. WBUFL(buf,2) = -src_id;
  3510. clif_send(buf,packet_len(0x13e), bl, SELF);
  3511. } else
  3512. clif_send(buf,packet_len(0x13e), bl, AREA);
  3513. return 0;
  3514. }
  3515. /*==========================================
  3516. *
  3517. *------------------------------------------*/
  3518. int clif_skillcastcancel(struct block_list* bl)
  3519. {
  3520. unsigned char buf[16];
  3521. nullpo_retr(0, bl);
  3522. WBUFW(buf,0) = 0x1b9;
  3523. WBUFL(buf,2) = bl->id;
  3524. clif_send(buf,packet_len(0x1b9), bl, AREA);
  3525. return 0;
  3526. }
  3527. /// only when type==0:
  3528. /// if(skill_id==NV_BASIC)
  3529. /// btype==0 "skill failed" MsgStringTable[159]
  3530. /// btype==1 "no emotions" MsgStringTable[160]
  3531. /// btype==2 "no sit" MsgStringTable[161]
  3532. /// btype==3 "no chat" MsgStringTable[162]
  3533. /// btype==4 "no party" MsgStringTable[163]
  3534. /// btype==5 "no shout" MsgStringTable[164]
  3535. /// btype==6 "no PKing" MsgStringTable[165]
  3536. /// btype==7 "no alligning" MsgStringTable[383]
  3537. /// btype>=8: ignored
  3538. /// if(skill_id==AL_WARP) "not enough skill level" MsgStringTable[214]
  3539. /// if(skill_id==TF_STEAL) "steal failed" MsgStringTable[205]
  3540. /// if(skill_id==TF_POISON) "envenom failed" MsgStringTable[207]
  3541. /// otherwise "skill failed" MsgStringTable[204]
  3542. /// btype irrelevant
  3543. /// type==1 "insufficient SP" MsgStringTable[202]
  3544. /// type==2 "insufficient HP" MsgStringTable[203]
  3545. /// type==3 "insufficient materials" MsgStringTable[808]
  3546. /// type==4 "there is a delay after using a skill" MsgStringTable[219]
  3547. /// type==5 "insufficient zeny" MsgStringTable[233]
  3548. /// type==6 "wrong weapon" MsgStringTable[239]
  3549. /// type==7 "red gemstone needed" MsgStringTable[246]
  3550. /// type==8 "blue gemstone needed" MsgStringTable[247]
  3551. /// type==9 "overweight" MsgStringTable[580]
  3552. /// type==10 "skill failed" MsgStringTable[285]
  3553. /// type>=11 ignored
  3554. ///
  3555. /// if(success!=0) doesn't display any of the previous messages
  3556. /// Note: when this packet is received an unknown flag is always set to 0,
  3557. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  3558. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3559. {
  3560. int fd;
  3561. if (!sd) { //Since this is the most common nullpo....
  3562. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3563. return 0;
  3564. }
  3565. fd=sd->fd;
  3566. if (!fd) return 0;
  3567. if(battle_config.display_skill_fail&1)
  3568. return 0; //Disable all skill failed messages
  3569. if(type==0x4 && !sd->state.showdelay)
  3570. return 0; //Disable delay failed messages
  3571. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3572. return 0;
  3573. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3574. return 0;
  3575. WFIFOHEAD(fd,packet_len(0x110));
  3576. WFIFOW(fd,0) = 0x110;
  3577. WFIFOW(fd,2) = skill_id;
  3578. WFIFOL(fd,4) = btype;
  3579. WFIFOB(fd,8) = 0;// success?
  3580. WFIFOB(fd,9) = type;
  3581. WFIFOSET(fd,packet_len(0x110));
  3582. return 1;
  3583. }
  3584. /*==========================================
  3585. * skill attack effect and damage
  3586. * 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
  3587. *------------------------------------------*/
  3588. 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)
  3589. {
  3590. unsigned char buf[64];
  3591. struct status_change *sc;
  3592. nullpo_retr(0, src);
  3593. nullpo_retr(0, dst);
  3594. sc = status_get_sc(dst);
  3595. if(sc && sc->count) {
  3596. if(type != 4 && dst->type == BL_PC && sc->data[SC_ENDURE] && !map_flag_gvg(dst->m))
  3597. type = 9;
  3598. if(sc->data[SC_HALLUCINATION] && damage)
  3599. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3600. }
  3601. #if PACKETVER < 3
  3602. WBUFW(buf,0)=0x114;
  3603. WBUFW(buf,2)=skill_id;
  3604. WBUFL(buf,4)=src->id;
  3605. WBUFL(buf,8)=dst->id;
  3606. WBUFL(buf,12)=tick;
  3607. WBUFL(buf,16)=sdelay;
  3608. WBUFL(buf,20)=ddelay;
  3609. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3610. WBUFW(buf,24)=damage?div:0;
  3611. } else {
  3612. WBUFW(buf,24)=damage;
  3613. }
  3614. WBUFW(buf,26)=skill_lv;
  3615. WBUFW(buf,28)=div;
  3616. WBUFB(buf,30)=type;
  3617. if (disguised(dst)) {
  3618. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  3619. WBUFL(buf,8)=-dst->id;
  3620. clif_send(buf,packet_len(0x114),dst,SELF);
  3621. } else
  3622. clif_send(buf,packet_len(0x114),dst,AREA);
  3623. if(disguised(src)) {
  3624. WBUFL(buf,4)=-src->id;
  3625. if (disguised(dst))
  3626. WBUFL(buf,8)=dst->id;
  3627. if(damage > 0)
  3628. WBUFW(buf,24)=-1;
  3629. clif_send(buf,packet_len(0x114),src,SELF);
  3630. }
  3631. #else
  3632. WBUFW(buf,0)=0x1de;
  3633. WBUFW(buf,2)=skill_id;
  3634. WBUFL(buf,4)=src->id;
  3635. WBUFL(buf,8)=dst->id;
  3636. WBUFL(buf,12)=tick;
  3637. WBUFL(buf,16)=sdelay;
  3638. WBUFL(buf,20)=ddelay;
  3639. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3640. WBUFL(buf,24)=damage?div:0;
  3641. } else {
  3642. WBUFL(buf,24)=damage;
  3643. }
  3644. WBUFW(buf,28)=skill_lv;
  3645. WBUFW(buf,30)=div;
  3646. WBUFB(buf,32)=type;
  3647. if (disguised(dst)) {
  3648. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  3649. WBUFL(buf,8)=-dst->id;
  3650. clif_send(buf,packet_len(0x1de),dst,SELF);
  3651. } else
  3652. clif_send(buf,packet_len(0x1de),dst,AREA);
  3653. if(disguised(src)) {
  3654. WBUFL(buf,4)=-src->id;
  3655. if (disguised(dst))
  3656. WBUFL(buf,8)=dst->id;
  3657. if(damage > 0)
  3658. WBUFL(buf,24)=-1;
  3659. clif_send(buf,packet_len(0x1de),src,SELF);
  3660. }
  3661. #endif
  3662. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3663. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3664. }
  3665. /*==========================================
  3666. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3667. *------------------------------------------*/
  3668. /*
  3669. 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)
  3670. {
  3671. unsigned char buf[64];
  3672. struct status_change *sc;
  3673. nullpo_retr(0, src);
  3674. nullpo_retr(0, dst);
  3675. type = (type>0)?type:skill_get_hit(skill_id);
  3676. type = clif_calc_delay(type, ddelay);
  3677. sc = status_get_sc(dst);
  3678. if(sc && sc->count) {
  3679. if(sc->data[SC_HALLUCINATION] && damage)
  3680. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3681. }
  3682. WBUFW(buf,0)=0x115;
  3683. WBUFW(buf,2)=skill_id;
  3684. WBUFL(buf,4)=src->id;
  3685. WBUFL(buf,8)=dst->id;
  3686. WBUFL(buf,12)=tick;
  3687. WBUFL(buf,16)=sdelay;
  3688. WBUFL(buf,20)=ddelay;
  3689. WBUFW(buf,24)=dst->x;
  3690. WBUFW(buf,26)=dst->y;
  3691. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3692. WBUFW(buf,28)=damage?div:0;
  3693. } else {
  3694. WBUFW(buf,28)=damage;
  3695. }
  3696. WBUFW(buf,30)=skill_lv;
  3697. WBUFW(buf,32)=div;
  3698. WBUFB(buf,34)=type;
  3699. clif_send(buf,packet_len(0x115),src,AREA);
  3700. if(disguised(src)) {
  3701. WBUFL(buf,4)=-src->id;
  3702. if(damage > 0)
  3703. WBUFW(buf,28)=-1;
  3704. clif_send(buf,packet_len(0x115),src,SELF);
  3705. }
  3706. if (disguised(dst)) {
  3707. WBUFL(buf,8)=-dst->id;
  3708. if (disguised(src))
  3709. WBUFL(buf,4)=src->id;
  3710. else if(damage > 0)
  3711. WBUFW(buf,28)=-1;
  3712. clif_send(buf,packet_len(0x115),dst,SELF);
  3713. }
  3714. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3715. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3716. }
  3717. */
  3718. /*==========================================
  3719. * 支援/回復スキルエフェクト
  3720. *------------------------------------------*/
  3721. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_id,int heal,int fail)
  3722. {
  3723. unsigned char buf[32];
  3724. nullpo_retr(0, dst);
  3725. WBUFW(buf,0)=0x11a;
  3726. WBUFW(buf,2)=skill_id;
  3727. WBUFW(buf,4)=min(heal, SHRT_MAX);
  3728. WBUFL(buf,6)=dst->id;
  3729. WBUFL(buf,10)=src?src->id:0;
  3730. WBUFB(buf,14)=fail;
  3731. if (disguised(dst)) {
  3732. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  3733. WBUFL(buf,6)=-dst->id;
  3734. clif_send(buf,packet_len(0x11a),dst,SELF);
  3735. } else
  3736. clif_send(buf,packet_len(0x11a),dst,AREA);
  3737. if(src && disguised(src)) {
  3738. WBUFL(buf,10)=-src->id;
  3739. if (disguised(dst))
  3740. WBUFL(buf,6)=dst->id;
  3741. clif_send(buf,packet_len(0x11a),src,SELF);
  3742. }
  3743. return fail;
  3744. }
  3745. /*==========================================
  3746. * 場所スキルエフェクト
  3747. *------------------------------------------*/
  3748. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  3749. {
  3750. unsigned char buf[32];
  3751. nullpo_retr(0, src);
  3752. WBUFW(buf,0)=0x117;
  3753. WBUFW(buf,2)=skill_id;
  3754. WBUFL(buf,4)=src->id;
  3755. WBUFW(buf,8)=val;
  3756. WBUFW(buf,10)=x;
  3757. WBUFW(buf,12)=y;
  3758. WBUFL(buf,14)=tick;
  3759. if(disguised(src)) {
  3760. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  3761. WBUFL(buf,4)=-src->id;
  3762. clif_send(buf,packet_len(0x117),src,SELF);
  3763. } else
  3764. clif_send(buf,packet_len(0x117),src,AREA);
  3765. return 0;
  3766. }
  3767. /*==========================================
  3768. * 場所スキルエフェクト表示
  3769. *------------------------------------------*/
  3770. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  3771. void clif_skill_setunit(struct skill_unit *unit)
  3772. {
  3773. unsigned char buf[128];
  3774. nullpo_retv(unit);
  3775. #if PACKETVER >= 3
  3776. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3777. WBUFW(buf, 0)=0x1c9;
  3778. WBUFL(buf, 2)=unit->bl.id;
  3779. WBUFL(buf, 6)=unit->group->src_id;
  3780. WBUFW(buf,10)=unit->bl.x;
  3781. WBUFW(buf,12)=unit->bl.y;
  3782. WBUFB(buf,14)=unit->group->unit_id;
  3783. WBUFB(buf,15)=1;
  3784. WBUFB(buf,16)=1;
  3785. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  3786. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  3787. return;
  3788. }
  3789. #endif
  3790. WBUFW(buf, 0)=0x11f;
  3791. WBUFL(buf, 2)=unit->bl.id;
  3792. WBUFL(buf, 6)=unit->group->src_id;
  3793. WBUFW(buf,10)=unit->bl.x;
  3794. WBUFW(buf,12)=unit->bl.y;
  3795. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  3796. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  3797. else
  3798. WBUFB(buf,14)=unit->group->unit_id;
  3799. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  3800. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  3801. }
  3802. /*==========================================
  3803. * ワープ場所選択
  3804. *------------------------------------------*/
  3805. 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)
  3806. {
  3807. int fd;
  3808. nullpo_retv(sd);
  3809. fd = sd->fd;
  3810. WFIFOHEAD(fd,packet_len(0x11c));
  3811. WFIFOW(fd,0) = 0x11c;
  3812. WFIFOW(fd,2) = skill_num;
  3813. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  3814. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  3815. else // normal map name
  3816. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  3817. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  3818. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  3819. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  3820. WFIFOSET(fd,packet_len(0x11c));
  3821. sd->menuskill_id = skill_num;
  3822. if (skill_num == AL_WARP)
  3823. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  3824. else
  3825. sd->menuskill_val = skill_lv;
  3826. }
  3827. /// Memo message.
  3828. /// type=0 : "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  3829. /// type=1 : "Skill Level is not high enough." in color 0x0000FF (red)
  3830. /// type=2 : "You haven't learned Warp." in color 0x0000FF (red)
  3831. ///
  3832. /// @param sd Who receives the message
  3833. /// @param type What message
  3834. void clif_skill_memomessage(struct map_session_data* sd, int type)
  3835. {
  3836. int fd;
  3837. nullpo_retv(sd);
  3838. fd=sd->fd;
  3839. WFIFOHEAD(fd,packet_len(0x11e));
  3840. WFIFOW(fd,0)=0x11e;
  3841. WFIFOB(fd,2)=type;
  3842. WFIFOSET(fd,packet_len(0x11e));
  3843. }
  3844. /// Teleport message.
  3845. /// type=0 : "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  3846. /// type=1 : "Saved point cannot be memorized." in color 0x0000FF (red)
  3847. ///
  3848. /// @param sd Who receives the message
  3849. /// @param type What message
  3850. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  3851. {
  3852. int fd;
  3853. nullpo_retv(sd);
  3854. fd=sd->fd;
  3855. WFIFOHEAD(fd,packet_len(0x189));
  3856. WFIFOW(fd,0)=0x189;
  3857. WFIFOW(fd,2)=type;
  3858. WFIFOSET(fd,packet_len(0x189));
  3859. }
  3860. /*==========================================
  3861. * モンスター情報
  3862. *------------------------------------------*/
  3863. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  3864. {
  3865. struct status_data *status;
  3866. unsigned char buf[64];
  3867. int i;//, fix;
  3868. nullpo_retr(0, sd);
  3869. nullpo_retr(0, dst);
  3870. if(dst->type!=BL_MOB )
  3871. return 0;
  3872. status = status_get_status_data(dst);
  3873. WBUFW(buf, 0)=0x18c;
  3874. WBUFW(buf, 2)=status_get_class(dst);
  3875. WBUFW(buf, 4)=status_get_lv(dst);
  3876. WBUFW(buf, 6)=status->size;
  3877. WBUFL(buf, 8)=status->hp;
  3878. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  3879. +(battle_config.estimation_type&2?status->def2:0);
  3880. WBUFW(buf,14)=status->race;
  3881. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  3882. +(battle_config.estimation_type&2?status->mdef2:0);
  3883. WBUFW(buf,18)= status->def_ele;
  3884. for(i=0;i<9;i++)
  3885. WBUFB(buf,20+i)= (unsigned char)battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv);
  3886. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  3887. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv))<0?0:fix);
  3888. clif_send(buf,packet_len(0x18c),&sd->bl,
  3889. sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  3890. return 0;
  3891. }
  3892. /*==========================================
  3893. * アイテム合成可能リスト
  3894. *------------------------------------------*/
  3895. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  3896. {
  3897. int i,c,view,fd;
  3898. nullpo_retr(0, sd);
  3899. if(sd->menuskill_id == AM_PHARMACY)
  3900. return 0; //Avoid resending the menu twice or more times...
  3901. fd=sd->fd;
  3902. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  3903. WFIFOW(fd, 0)=0x18d;
  3904. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  3905. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  3906. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  3907. WFIFOW(fd,c*8+ 4)= view;
  3908. else
  3909. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  3910. WFIFOW(fd,c*8+ 6)= 0x0012;
  3911. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  3912. c++;
  3913. }
  3914. }
  3915. WFIFOW(fd, 2)=c*8+8;
  3916. WFIFOSET(fd,WFIFOW(fd,2));
  3917. if(c > 0) {
  3918. sd->menuskill_id = AM_PHARMACY;
  3919. sd->menuskill_val = trigger;
  3920. return 1;
  3921. }
  3922. return 0;
  3923. }
  3924. /*==========================================
  3925. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  3926. *------------------------------------------*/
  3927. int clif_status_load(struct block_list *bl,int type, int flag)
  3928. {
  3929. int fd;
  3930. if (type == SI_BLANK) //It shows nothing on the client...
  3931. return 0;
  3932. if (bl->type != BL_PC)
  3933. return 0;
  3934. fd = ((struct map_session_data*)bl)->fd;
  3935. WFIFOHEAD(fd,packet_len(0x196));
  3936. WFIFOW(fd,0)=0x0196;
  3937. WFIFOW(fd,2)=type;
  3938. WFIFOL(fd,4)=bl->id;
  3939. WFIFOB(fd,8)=flag; //Status start
  3940. WFIFOSET(fd, packet_len(0x196));
  3941. return 0;
  3942. }
  3943. /*==========================================
  3944. * 状態異常アイコン/メッセージ表示
  3945. *------------------------------------------*/
  3946. int clif_status_change(struct block_list *bl,int type,int flag)
  3947. {
  3948. unsigned char buf[16];
  3949. if (type == SI_BLANK) //It shows nothing on the client...
  3950. return 0;
  3951. nullpo_retr(0, bl);
  3952. WBUFW(buf,0)=0x0196;
  3953. WBUFW(buf,2)=type;
  3954. WBUFL(buf,4)=bl->id;
  3955. WBUFB(buf,8)=flag;
  3956. clif_send(buf,packet_len(0x196),bl,AREA);
  3957. return 0;
  3958. }
  3959. /*==========================================
  3960. * Send message (modified by [Yor])
  3961. *------------------------------------------*/
  3962. int clif_displaymessage(const int fd, const char* mes)
  3963. {
  3964. // invalid pointer?
  3965. nullpo_retr(-1, mes);
  3966. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  3967. if (fd == 0)
  3968. return 0;
  3969. else {
  3970. int len_mes = strlen(mes);
  3971. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  3972. WFIFOHEAD(fd, 5 + len_mes);
  3973. WFIFOW(fd,0) = 0x8e;
  3974. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  3975. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  3976. WFIFOSET(fd, 5 + len_mes);
  3977. }
  3978. }
  3979. return 0;
  3980. }
  3981. /*==========================================
  3982. * 天の声を送信する
  3983. *------------------------------------------*/
  3984. int clif_GMmessage(struct block_list* bl, const char* mes, int len, int flag)
  3985. {
  3986. unsigned char *buf;
  3987. int lp;
  3988. lp = (flag & 0x10) ? 8 : 4;
  3989. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  3990. WBUFW(buf,0) = 0x9a;
  3991. WBUFW(buf,2) = len + lp;
  3992. WBUFL(buf,4) = 0x65756c62; //"blue":
  3993. memcpy(WBUFP(buf,lp), mes, len);
  3994. flag &= 0x07;
  3995. clif_send(buf, WBUFW(buf,2), bl,
  3996. (flag == 1) ? ALL_SAMEMAP :
  3997. (flag == 2) ? AREA :
  3998. (flag == 3) ? SELF :
  3999. ALL_CLIENT);
  4000. if(buf) aFree(buf);
  4001. if(use_irc && irc_announce_flag && !flag)
  4002. irc_announce(mes);
  4003. return 0;
  4004. }
  4005. /*==========================================
  4006. * グローバルメッセージ
  4007. *------------------------------------------*/
  4008. void clif_GlobalMessage(struct block_list* bl, const char* message)
  4009. {
  4010. char buf[100];
  4011. int len;
  4012. nullpo_retv(bl);
  4013. if(!message)
  4014. return;
  4015. len = strlen(message)+1;
  4016. WBUFW(buf,0)=0x8d;
  4017. WBUFW(buf,2)=len+8;
  4018. WBUFL(buf,4)=bl->id;
  4019. strncpy((char *) WBUFP(buf,8),message,len);
  4020. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4021. }
  4022. /*==========================================
  4023. * Send main chat message [LuzZza]
  4024. *------------------------------------------*/
  4025. void clif_MainChatMessage(const char* message)
  4026. {
  4027. char buf[200];
  4028. int len;
  4029. if(!message)
  4030. return;
  4031. len = strlen(message)+1;
  4032. if (len+8 > sizeof(buf)) {
  4033. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4034. len = sizeof(buf)-8;
  4035. }
  4036. WBUFW(buf,0)=0x8d;
  4037. WBUFW(buf,2)=len+8;
  4038. WBUFL(buf,4)=0;
  4039. strncpy((char *) WBUFP(buf,8),message,len);
  4040. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4041. }
  4042. /*==========================================
  4043. * Does an announce message in the given color.
  4044. *------------------------------------------*/
  4045. int clif_announce(struct block_list* bl, const char* mes, int len, unsigned long color, int flag)
  4046. {
  4047. unsigned char *buf;
  4048. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4049. WBUFW(buf,0) = 0x1c3;
  4050. WBUFW(buf,2) = len + 16;
  4051. WBUFL(buf,4) = color;
  4052. WBUFW(buf,8) = 0x190; //Font style? Type?
  4053. WBUFW(buf,10) = 0x0c; //12? Font size?
  4054. WBUFL(buf,12) = 0; //Unknown!
  4055. memcpy(WBUFP(buf,16), mes, len);
  4056. flag &= 0x07;
  4057. clif_send(buf, WBUFW(buf,2), bl,
  4058. (flag == 1) ? ALL_SAMEMAP :
  4059. (flag == 2) ? AREA :
  4060. (flag == 3) ? SELF :
  4061. ALL_CLIENT);
  4062. if(buf) aFree(buf);
  4063. return 0;
  4064. }
  4065. /*==========================================
  4066. * HPSP回復エフェクトを送信する
  4067. *------------------------------------------*/
  4068. int clif_heal(int fd,int type,int val)
  4069. {
  4070. WFIFOHEAD(fd,packet_len(0x13d));
  4071. WFIFOW(fd,0)=0x13d;
  4072. WFIFOW(fd,2)=type;
  4073. WFIFOW(fd,4)=cap_value(val,0,SHRT_MAX);
  4074. WFIFOSET(fd,packet_len(0x13d));
  4075. return 0;
  4076. }
  4077. /*==========================================
  4078. * 復活する
  4079. *------------------------------------------*/
  4080. int clif_resurrection(struct block_list *bl,int type)
  4081. {
  4082. unsigned char buf[16];
  4083. nullpo_retr(0, bl);
  4084. WBUFW(buf,0)=0x148;
  4085. WBUFL(buf,2)=bl->id;
  4086. WBUFW(buf,6)=type;
  4087. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4088. if (disguised(bl))
  4089. clif_spawn(bl);
  4090. return 0;
  4091. }
  4092. /// Sets the map mode.
  4093. ///
  4094. /// mode=1 : pvp mode
  4095. /// mode=2 : unknown mode (pk?)
  4096. /// mode=3 : gvg mode
  4097. /// mode=4 : message "You are in a PK area. Please beware of sudden attacks." in color 0x9B9BFF (light red)
  4098. /// mode=5 : pvp mode
  4099. /// mode=other : ?
  4100. void clif_set0199(struct map_session_data* sd, int mode)
  4101. {
  4102. int fd;
  4103. nullpo_retv(sd);
  4104. fd=sd->fd;
  4105. WFIFOHEAD(fd,packet_len(0x199));
  4106. WFIFOW(fd,0)=0x199;
  4107. WFIFOW(fd,2)=mode;
  4108. WFIFOSET(fd,packet_len(0x199));
  4109. }
  4110. #if 0
  4111. /// Set the map mode?
  4112. /// Differs from the behaviour of clif_set0199 with unknown consequences.
  4113. void clif_set01D6(struct map_session_data* sd, int mode)
  4114. {
  4115. int fd;
  4116. nullpo_retv(sd);
  4117. fd=sd->fd;
  4118. WFIFOHEAD(fd,packet_len(0x1D6));
  4119. WFIFOW(fd,0)=0x1D6;
  4120. WFIFOW(fd,2)=mode;
  4121. WFIFOSET(fd,packet_len(0x1D6));
  4122. }
  4123. #endif
  4124. /*==========================================
  4125. * PVP実装?(仮)
  4126. *------------------------------------------*/
  4127. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4128. {
  4129. if(type == 2) {
  4130. int fd = sd->fd;
  4131. WFIFOHEAD(fd,packet_len(0x19a));
  4132. WFIFOW(fd,0) = 0x19a;
  4133. WFIFOL(fd,2) = sd->bl.id;
  4134. WFIFOL(fd,6) = pvprank;
  4135. WFIFOL(fd,10) = pvpnum;
  4136. WFIFOSET(fd,packet_len(0x19a));
  4137. } else {
  4138. unsigned char buf[32];
  4139. WBUFW(buf,0) = 0x19a;
  4140. WBUFL(buf,2) = sd->bl.id;
  4141. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4142. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4143. else
  4144. WBUFL(buf,6) = pvprank;
  4145. WBUFL(buf,10) = pvpnum;
  4146. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  4147. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4148. else if(!type)
  4149. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4150. else
  4151. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4152. }
  4153. return 0;
  4154. }
  4155. /*==========================================
  4156. *
  4157. *------------------------------------------*/
  4158. int clif_send0199(int map,int type)
  4159. {
  4160. struct block_list bl;
  4161. unsigned char buf[16];
  4162. bl.id = 0;
  4163. bl.type = BL_NUL;
  4164. bl.m = map;
  4165. WBUFW(buf,0)=0x199;
  4166. WBUFW(buf,2)=type;
  4167. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4168. return 0;
  4169. }
  4170. /*==========================================
  4171. * 精錬エフェクトを送信する
  4172. *------------------------------------------*/
  4173. void clif_refine(int fd, int fail, int index, int val)
  4174. {
  4175. WFIFOHEAD(fd,packet_len(0x188));
  4176. WFIFOW(fd,0)=0x188;
  4177. WFIFOW(fd,2)=fail;
  4178. WFIFOW(fd,4)=index+2;
  4179. WFIFOW(fd,6)=val;
  4180. WFIFOSET(fd,packet_len(0x188));
  4181. }
  4182. /// result=0: "weapon upgrated: %s" MsgStringTable[911] in rgb(0,255,255)
  4183. /// result=1: "weapon upgrated: %s" MsgStringTable[912] in rgb(0,205,205)
  4184. /// result=2: "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4185. /// result=3: "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4186. void clif_upgrademessage(int fd, int result, int item_id)
  4187. {
  4188. WFIFOHEAD(fd,packet_len(0x223));
  4189. WFIFOW(fd,0)=0x223;
  4190. WFIFOL(fd,2)=result;
  4191. WFIFOW(fd,6)=item_id;
  4192. WFIFOSET(fd,packet_len(0x223));
  4193. }
  4194. /*==========================================
  4195. * Wisp/page is transmitted to the destination player
  4196. * R 0097 <len>.w <nick>.24B <message>.?B
  4197. *------------------------------------------*/
  4198. int clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4199. {
  4200. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4201. WFIFOW(fd,0) = 0x97;
  4202. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4203. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4204. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  4205. WFIFOSET(fd,WFIFOW(fd,2));
  4206. return 0;
  4207. }
  4208. /*==========================================
  4209. * Inform the player about the result of his whisper action
  4210. * R 0098 <type>.B
  4211. * 0: success to send wisper
  4212. * 1: target character is not loged in
  4213. * 2: ignored by target
  4214. * 3: everyone ignored by target
  4215. *------------------------------------------*/
  4216. int clif_wis_end(int fd, int flag)
  4217. {
  4218. WFIFOHEAD(fd,packet_len(0x98));
  4219. WFIFOW(fd,0) = 0x98;
  4220. WFIFOW(fd,2) = flag;
  4221. WFIFOSET(fd,packet_len(0x98));
  4222. return 0;
  4223. }
  4224. /*==========================================
  4225. * キャラID名前引き結果を送信する
  4226. *------------------------------------------*/
  4227. int clif_solved_charname(int fd, int charid, const char* name)
  4228. {
  4229. WFIFOHEAD(fd,packet_len(0x194));
  4230. WFIFOW(fd,0)=0x194;
  4231. WFIFOL(fd,2)=charid;
  4232. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  4233. WFIFOSET(fd,packet_len(0x194));
  4234. return 0;
  4235. }
  4236. /*==========================================
  4237. * カードの挿入可能リストを返す
  4238. *------------------------------------------*/
  4239. int clif_use_card(struct map_session_data *sd,int idx)
  4240. {
  4241. int i,c,ep;
  4242. int fd=sd->fd;
  4243. nullpo_retr(0, sd);
  4244. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4245. return 0;
  4246. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4247. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4248. ep=sd->inventory_data[idx]->equip;
  4249. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4250. WFIFOW(fd,0)=0x017b;
  4251. for(i=c=0;i<MAX_INVENTORY;i++){
  4252. int j;
  4253. if(sd->inventory_data[i] == NULL)
  4254. continue;
  4255. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4256. continue;
  4257. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4258. continue;
  4259. if(sd->status.inventory[i].identify==0 ) //Not identified
  4260. continue;
  4261. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4262. continue;
  4263. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_HAND_L) //Shield card won't go on left weapon.
  4264. continue;
  4265. for(j=0;j<sd->inventory_data[i]->slot;j++){
  4266. if( sd->status.inventory[i].card[j]==0 )
  4267. break;
  4268. }
  4269. if(j==sd->inventory_data[i]->slot) // No room
  4270. continue;
  4271. WFIFOW(fd,4+c*2)=i+2;
  4272. c++;
  4273. }
  4274. WFIFOW(fd,2)=4+c*2;
  4275. WFIFOSET(fd,WFIFOW(fd,2));
  4276. return 0;
  4277. }
  4278. /*==========================================
  4279. * カードの挿入終了
  4280. *------------------------------------------*/
  4281. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4282. {
  4283. int fd;
  4284. nullpo_retr(0, sd);
  4285. fd=sd->fd;
  4286. WFIFOHEAD(fd,packet_len(0x17d));
  4287. WFIFOW(fd,0)=0x17d;
  4288. WFIFOW(fd,2)=idx_equip+2;
  4289. WFIFOW(fd,4)=idx_card+2;
  4290. WFIFOB(fd,6)=flag;
  4291. WFIFOSET(fd,packet_len(0x17d));
  4292. return 0;
  4293. }
  4294. /*==========================================
  4295. * 鑑定可能アイテムリスト送信
  4296. *------------------------------------------*/
  4297. int clif_item_identify_list(struct map_session_data *sd)
  4298. {
  4299. int i,c;
  4300. int fd;
  4301. nullpo_retr(0, sd);
  4302. fd=sd->fd;
  4303. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4304. WFIFOW(fd,0)=0x177;
  4305. for(i=c=0;i<MAX_INVENTORY;i++){
  4306. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4307. WFIFOW(fd,c*2+4)=i+2;
  4308. c++;
  4309. }
  4310. }
  4311. if(c > 0) {
  4312. WFIFOW(fd,2)=c*2+4;
  4313. WFIFOSET(fd,WFIFOW(fd,2));
  4314. sd->menuskill_id = MC_IDENTIFY;
  4315. sd->menuskill_val = c;
  4316. }
  4317. return 0;
  4318. }
  4319. /*==========================================
  4320. * 鑑定結果
  4321. *------------------------------------------*/
  4322. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4323. {
  4324. int fd;
  4325. nullpo_retr(0, sd);
  4326. fd=sd->fd;
  4327. WFIFOHEAD(fd,packet_len(0x179));
  4328. WFIFOW(fd, 0)=0x179;
  4329. WFIFOW(fd, 2)=idx+2;
  4330. WFIFOB(fd, 4)=flag;
  4331. WFIFOSET(fd,packet_len(0x179));
  4332. return 0;
  4333. }
  4334. /*==========================================
  4335. * 修理可能アイテムリスト送信
  4336. *------------------------------------------*/
  4337. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4338. {
  4339. int i,c;
  4340. int fd;
  4341. int nameid;
  4342. nullpo_retr(0, sd);
  4343. nullpo_retr(0, dstsd);
  4344. fd=sd->fd;
  4345. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4346. WFIFOW(fd,0)=0x1fc;
  4347. for(i=c=0;i<MAX_INVENTORY;i++){
  4348. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4349. WFIFOW(fd,c*13+4) = i;
  4350. WFIFOW(fd,c*13+6) = nameid;
  4351. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4352. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4353. WFIFOB(fd,c*13+16)= c;
  4354. c++;
  4355. }
  4356. }
  4357. if(c > 0) {
  4358. WFIFOW(fd,2)=c*13+4;
  4359. WFIFOSET(fd,WFIFOW(fd,2));
  4360. sd->menuskill_id = BS_REPAIRWEAPON;
  4361. sd->menuskill_val = dstsd->bl.id;
  4362. }else
  4363. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4364. return 0;
  4365. }
  4366. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4367. {
  4368. int view,fd;
  4369. nullpo_retr(0, sd);
  4370. fd=sd->fd;
  4371. WFIFOHEAD(fd,packet_len(0x1fe));
  4372. WFIFOW(fd, 0)=0x1fe;
  4373. if((view = itemdb_viewid(nameid)) > 0)
  4374. WFIFOW(fd, 2)=view;
  4375. else
  4376. WFIFOW(fd, 2)=nameid;
  4377. WFIFOB(fd, 4)=flag;
  4378. WFIFOSET(fd,packet_len(0x1fe));
  4379. return 0;
  4380. }
  4381. /*==========================================
  4382. * Weapon Refining - Taken from jAthena
  4383. *------------------------------------------*/
  4384. int clif_item_refine_list(struct map_session_data *sd)
  4385. {
  4386. int i,c;
  4387. int fd;
  4388. int skilllv;
  4389. int wlv;
  4390. int refine_item[5];
  4391. nullpo_retr(0, sd);
  4392. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4393. fd=sd->fd;
  4394. refine_item[0] = -1;
  4395. refine_item[1] = pc_search_inventory(sd,1010);
  4396. refine_item[2] = pc_search_inventory(sd,1011);
  4397. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4398. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4399. WFIFOW(fd,0)=0x221;
  4400. for(i=c=0;i<MAX_INVENTORY;i++){
  4401. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4402. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4403. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4404. WFIFOW(fd,c*13+ 4)=i+2;
  4405. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4406. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4407. WFIFOW(fd,c*13+10)=0;
  4408. WFIFOB(fd,c*13+12)=c;
  4409. c++;
  4410. }
  4411. }
  4412. WFIFOW(fd,2)=c*13+4;
  4413. WFIFOSET(fd,WFIFOW(fd,2));
  4414. if (c > 0) {
  4415. sd->menuskill_id = WS_WEAPONREFINE;
  4416. sd->menuskill_val = skilllv;
  4417. }
  4418. return 0;
  4419. }
  4420. /*==========================================
  4421. * アイテムによる一時的なスキル効果
  4422. *------------------------------------------*/
  4423. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  4424. {
  4425. int fd;
  4426. nullpo_retr(0, sd);
  4427. fd=sd->fd;
  4428. WFIFOHEAD(fd,packet_len(0x147));
  4429. WFIFOW(fd, 0)=0x147;
  4430. WFIFOW(fd, 2)=skillid;
  4431. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4432. WFIFOW(fd, 6)=0;
  4433. WFIFOW(fd, 8)=skilllv;
  4434. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4435. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4436. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  4437. WFIFOB(fd,38)=0;
  4438. WFIFOSET(fd,packet_len(0x147));
  4439. return 0;
  4440. }
  4441. /*==========================================
  4442. * カートにアイテム追加
  4443. *------------------------------------------*/
  4444. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4445. {
  4446. int view,fd;
  4447. unsigned char *buf;
  4448. nullpo_retr(0, sd);
  4449. fd=sd->fd;
  4450. WFIFOHEAD(fd,packet_len(0x124));
  4451. buf=WFIFOP(fd,0);
  4452. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4453. return 1;
  4454. WBUFW(buf,0)=0x124;
  4455. WBUFW(buf,2)=n+2;
  4456. WBUFL(buf,4)=amount;
  4457. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4458. WBUFW(buf,8)=view;
  4459. else
  4460. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4461. WBUFB(buf,10)=sd->status.cart[n].identify;
  4462. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4463. WBUFB(buf,12)=sd->status.cart[n].refine;
  4464. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4465. WFIFOSET(fd,packet_len(0x124));
  4466. return 0;
  4467. }
  4468. /*==========================================
  4469. * カートからアイテム削除
  4470. *------------------------------------------*/
  4471. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4472. {
  4473. int fd;
  4474. nullpo_retr(0, sd);
  4475. fd=sd->fd;
  4476. WFIFOHEAD(fd,packet_len(0x125));
  4477. WFIFOW(fd,0)=0x125;
  4478. WFIFOW(fd,2)=n+2;
  4479. WFIFOL(fd,4)=amount;
  4480. WFIFOSET(fd,packet_len(0x125));
  4481. return 0;
  4482. }
  4483. /*==========================================
  4484. * Opens the shop creation menu.
  4485. * R 012d <num>.w
  4486. * 'num' is the number of allowed item slots
  4487. *------------------------------------------*/
  4488. void clif_openvendingreq(struct map_session_data* sd, int num)
  4489. {
  4490. int fd;
  4491. nullpo_retv(sd);
  4492. fd = sd->fd;
  4493. WFIFOHEAD(fd,packet_len(0x12d));
  4494. WFIFOW(fd,0) = 0x12d;
  4495. WFIFOW(fd,2) = num;
  4496. WFIFOSET(fd,packet_len(0x12d));
  4497. }
  4498. /*==========================================
  4499. * Displays a vending board to target/area
  4500. * R 0131 <ID>.l <message>.80B
  4501. *------------------------------------------*/
  4502. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  4503. {
  4504. unsigned char buf[128];
  4505. nullpo_retv(bl);
  4506. WBUFW(buf,0) = 0x131;
  4507. WBUFL(buf,2) = bl->id;
  4508. safestrncpy((char*)WBUFP(buf,6), message, 80);
  4509. if( fd ) {
  4510. WFIFOHEAD(fd,packet_len(0x131));
  4511. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  4512. WFIFOSET(fd,packet_len(0x131));
  4513. } else {
  4514. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  4515. }
  4516. }
  4517. /*==========================================
  4518. * Removes a vending board from screen
  4519. *------------------------------------------*/
  4520. void clif_closevendingboard(struct block_list* bl, int fd)
  4521. {
  4522. unsigned char buf[16];
  4523. nullpo_retv(bl);
  4524. WBUFW(buf,0) = 0x132;
  4525. WBUFL(buf,2) = bl->id;
  4526. if( fd ) {
  4527. WFIFOHEAD(fd,packet_len(0x132));
  4528. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  4529. WFIFOSET(fd,packet_len(0x132));
  4530. } else {
  4531. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  4532. }
  4533. }
  4534. /*==========================================
  4535. * Sends a list of items in a shop
  4536. * 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
  4537. *------------------------------------------*/
  4538. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  4539. {
  4540. int i,fd;
  4541. int count;
  4542. struct map_session_data* vsd;
  4543. nullpo_retv(sd);
  4544. nullpo_retv(vending);
  4545. nullpo_retv(vsd=map_id2sd(id));
  4546. fd = sd->fd;
  4547. count = vsd->vend_num;
  4548. WFIFOHEAD(fd, 8+count*22);
  4549. WFIFOW(fd,0) = 0x133;
  4550. WFIFOW(fd,2) = 8+count*22;
  4551. WFIFOL(fd,4) = id;
  4552. for( i = 0; i < count; i++ )
  4553. {
  4554. int index = vending[i].index;
  4555. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  4556. WFIFOL(fd, 8+i*22) = vending[i].value;
  4557. WFIFOW(fd,12+i*22) = vending[i].amount;
  4558. WFIFOW(fd,14+i*22) = vending[i].index + 2;
  4559. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4560. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  4561. WFIFOB(fd,19+i*22) = vsd->status.cart[index].identify;
  4562. WFIFOB(fd,20+i*22) = vsd->status.cart[index].attribute;
  4563. WFIFOB(fd,21+i*22) = vsd->status.cart[index].refine;
  4564. clif_addcards(WFIFOP(fd, 22+i*22), &vsd->status.cart[index]);
  4565. }
  4566. WFIFOSET(fd,WFIFOW(fd,2));
  4567. }
  4568. /*==========================================
  4569. * Shop purchase failure
  4570. * R 0135 <index>.w <amount>.w <fail>.B
  4571. * fail=1 - not enough zeny
  4572. * fail=2 - overweight
  4573. * fail=4 - out of stock
  4574. * fail=5 - "cannot use an npc shop while in a trade"
  4575. *------------------------------------------*/
  4576. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  4577. {
  4578. int fd;
  4579. nullpo_retv(sd);
  4580. fd = sd->fd;
  4581. WFIFOHEAD(fd,packet_len(0x135));
  4582. WFIFOW(fd,0) = 0x135;
  4583. WFIFOW(fd,2) = index+2;
  4584. WFIFOW(fd,4) = amount;
  4585. WFIFOB(fd,6) = fail;
  4586. WFIFOSET(fd,packet_len(0x135));
  4587. }
  4588. /*==========================================
  4589. * Shop creation success
  4590. * 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*
  4591. *------------------------------------------*/
  4592. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  4593. {
  4594. int i,fd;
  4595. int count;
  4596. nullpo_retv(sd);
  4597. fd = sd->fd;
  4598. count = sd->vend_num;
  4599. WFIFOHEAD(fd, 8+count*22);
  4600. WFIFOW(fd,0) = 0x136;
  4601. WFIFOW(fd,2) = 8+count*22;
  4602. WFIFOL(fd,4) = id;
  4603. for( i = 0; i < count; i++ )
  4604. {
  4605. int index = vending[i].index;
  4606. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  4607. WFIFOL(fd, 8+i*22) = vending[i].value;
  4608. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  4609. WFIFOW(fd,14+i*22) = vending[i].amount;
  4610. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4611. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  4612. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  4613. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  4614. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  4615. clif_addcards(WFIFOP(fd,22+count*22), &sd->status.cart[index]);
  4616. }
  4617. WFIFOSET(fd,WFIFOW(fd,2));
  4618. }
  4619. /*==========================================
  4620. * Inform merchant that someone has bought an item.
  4621. * R 0137 <index>.w <amount>.w
  4622. *------------------------------------------*/
  4623. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  4624. {
  4625. int fd;
  4626. nullpo_retv(sd);
  4627. fd = sd->fd;
  4628. WFIFOHEAD(fd,packet_len(0x137));
  4629. WFIFOW(fd,0) = 0x137;
  4630. WFIFOW(fd,2) = index+2;
  4631. WFIFOW(fd,4) = amount;
  4632. WFIFOSET(fd,packet_len(0x137));
  4633. }
  4634. /// Result of organizing a party.
  4635. /// R 00FA <result>.B
  4636. ///
  4637. /// result=0 : opens party window and shows MsgStringTable[77]="party successfully organized"
  4638. /// result=1 : MsgStringTable[78]="party name already exists"
  4639. /// result=2 : MsgStringTable[79]="already in a party"
  4640. /// result=other : nothing
  4641. int clif_party_created(struct map_session_data *sd,int result)
  4642. {
  4643. int fd;
  4644. nullpo_retr(0, sd);
  4645. fd=sd->fd;
  4646. WFIFOHEAD(fd,packet_len(0xfa));
  4647. WFIFOW(fd,0)=0xfa;
  4648. WFIFOB(fd,2)=result;
  4649. WFIFOSET(fd,packet_len(0xfa));
  4650. return 0;
  4651. }
  4652. int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  4653. {
  4654. unsigned char buf[96];
  4655. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  4656. int i;
  4657. for (i=0; i<MAX_PARTY && !p->data[i].sd; i++);
  4658. if (i >= MAX_PARTY) return 0; //Should never happen...
  4659. sd = p->data[i].sd;
  4660. }
  4661. WBUFW(buf, 0) = 0x1e9;
  4662. WBUFL(buf, 2) = sd->status.account_id;
  4663. WBUFL(buf, 6) = 0; //Apparently setting this to 1 makes you adoptable.
  4664. WBUFW(buf,10) = sd->bl.x;
  4665. WBUFW(buf,12) = sd->bl.y;
  4666. WBUFB(buf,14) = 0; //Unconfirmed byte, could be online/offline.
  4667. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  4668. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  4669. mapindex_getmapname_ext(mapindex_id2name(sd->mapindex), (char*)WBUFP(buf,63));
  4670. WBUFB(buf,79) = (p->party.item&1)?1:0;
  4671. WBUFB(buf,80) = (p->party.item&2)?1:0;
  4672. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  4673. return 1;
  4674. }
  4675. /*==========================================
  4676. * Sends party information
  4677. * R 00fb <len>.w <party name>.24B {<ID>.l <nick>.24B <map name>.16B <leader>.B <offline>.B}.46B*
  4678. *------------------------------------------*/
  4679. int clif_party_info(struct party_data* p, struct map_session_data *sd)
  4680. {
  4681. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  4682. struct map_session_data* party_sd = NULL;
  4683. int i, c;
  4684. nullpo_retr(0, p);
  4685. WBUFW(buf,0) = 0xfb;
  4686. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  4687. for(i = 0, c = 0; i < MAX_PARTY; i++)
  4688. {
  4689. struct party_member* m = &p->party.member[i];
  4690. if(!m->account_id) continue;
  4691. if(party_sd == NULL) party_sd = p->data[i].sd;
  4692. WBUFL(buf,28+c*46) = m->account_id;
  4693. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  4694. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  4695. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  4696. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  4697. c++;
  4698. }
  4699. WBUFW(buf,2) = 28+c*46;
  4700. if(sd) { // send only to self
  4701. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  4702. } else if (party_sd) { // send to whole party
  4703. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  4704. }
  4705. return 0;
  4706. }
  4707. /*==========================================
  4708. * パーティ勧誘
  4709. *------------------------------------------*/
  4710. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  4711. {
  4712. int fd;
  4713. struct party_data *p;
  4714. nullpo_retr(0, sd);
  4715. nullpo_retr(0, tsd);
  4716. fd=tsd->fd;
  4717. if( (p=party_search(sd->status.party_id))==NULL )
  4718. return 0;
  4719. WFIFOHEAD(fd,packet_len(0xfe));
  4720. WFIFOW(fd,0)=0xfe;
  4721. WFIFOL(fd,2)=sd->status.account_id;
  4722. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  4723. WFIFOSET(fd,packet_len(0xfe));
  4724. return 0;
  4725. }
  4726. /*==========================================
  4727. * Party invitation result. Flag values are:
  4728. * 0 -> char is already in a party
  4729. * 1 -> party invite was rejected
  4730. * 2 -> party invite was accepted
  4731. * 3 -> party is full
  4732. * 4 -> char of the same account already joined the party
  4733. *------------------------------------------*/
  4734. int clif_party_inviteack(struct map_session_data* sd, const char* nick, int flag)
  4735. {
  4736. int fd;
  4737. nullpo_retr(0, sd);
  4738. fd=sd->fd;
  4739. WFIFOHEAD(fd,packet_len(0xfd));
  4740. WFIFOW(fd,0)=0xfd;
  4741. memcpy(WFIFOP(fd,2),nick,NAME_LENGTH);
  4742. WFIFOB(fd,26)=flag;
  4743. WFIFOSET(fd,packet_len(0xfd));
  4744. return 0;
  4745. }
  4746. /*==========================================
  4747. * パーティ設定送信
  4748. * flag & 0x001=exp変更ミス
  4749. * 0x010=item変更ミス
  4750. * 0x100=一人にのみ送信
  4751. *------------------------------------------*/
  4752. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  4753. {
  4754. unsigned char buf[16];
  4755. nullpo_retr(0, p);
  4756. if(!sd && flag==0){
  4757. int i;
  4758. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4759. if (i < MAX_PARTY)
  4760. sd = p->data[i].sd;
  4761. }
  4762. if(!sd) return 0;
  4763. WBUFW(buf,0)=0x101;
  4764. // WBUFL(buf,2) // that's how the client reads it, still need to check it's uses [FlavioJS]
  4765. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  4766. WBUFW(buf,4)=0;
  4767. if(flag==0)
  4768. clif_send(buf,packet_len(0x101),&sd->bl,PARTY);
  4769. else
  4770. clif_send(buf,packet_len(0x101),&sd->bl,SELF);
  4771. return 0;
  4772. }
  4773. /*==========================================
  4774. * パーティ脱退(脱退前に呼ぶこと)
  4775. *------------------------------------------*/
  4776. int clif_party_leaved(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  4777. {
  4778. unsigned char buf[64];
  4779. int i;
  4780. nullpo_retr(0, p);
  4781. if(!sd && (flag&0xf0)==0)
  4782. {
  4783. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4784. if (i < MAX_PARTY)
  4785. sd = p->data[i].sd;
  4786. }
  4787. if(!sd) return 0;
  4788. WBUFW(buf,0)=0x105;
  4789. WBUFL(buf,2)=account_id;
  4790. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  4791. WBUFB(buf,30)=flag&0x0f;
  4792. if((flag&0xf0)==0)
  4793. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  4794. else
  4795. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  4796. return 0;
  4797. }
  4798. /*==========================================
  4799. * パーティメッセージ送信
  4800. *------------------------------------------*/
  4801. int clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  4802. {
  4803. struct map_session_data *sd;
  4804. int i;
  4805. nullpo_retr(0, p);
  4806. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  4807. if(i < MAX_PARTY){
  4808. unsigned char buf[1024];
  4809. sd = p->data[i].sd;
  4810. WBUFW(buf,0)=0x109;
  4811. WBUFW(buf,2)=len+8;
  4812. WBUFL(buf,4)=account_id;
  4813. memcpy(WBUFP(buf,8),mes,len);
  4814. clif_send(buf,len+8,&sd->bl,PARTY);
  4815. }
  4816. return 0;
  4817. }
  4818. /*==========================================
  4819. * パーティ座標通知
  4820. *------------------------------------------*/
  4821. int clif_party_xy(struct map_session_data *sd)
  4822. {
  4823. unsigned char buf[16];
  4824. nullpo_retr(0, sd);
  4825. WBUFW(buf,0)=0x107;
  4826. WBUFL(buf,2)=sd->status.account_id;
  4827. WBUFW(buf,6)=sd->bl.x;
  4828. WBUFW(buf,8)=sd->bl.y;
  4829. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  4830. return 0;
  4831. }
  4832. /*==========================================
  4833. * Sends x/y dot to a single fd. [Skotlex]
  4834. *------------------------------------------*/
  4835. int clif_party_xy_single(int fd, struct map_session_data *sd)
  4836. {
  4837. WFIFOHEAD(fd,packet_len(0x107));
  4838. WFIFOW(fd,0)=0x107;
  4839. WFIFOL(fd,2)=sd->status.account_id;
  4840. WFIFOW(fd,6)=sd->bl.x;
  4841. WFIFOW(fd,8)=sd->bl.y;
  4842. WFIFOSET(fd,packet_len(0x107));
  4843. return 0;
  4844. }
  4845. /*==========================================
  4846. * パーティHP通知
  4847. *------------------------------------------*/
  4848. int clif_party_hp(struct map_session_data *sd)
  4849. {
  4850. unsigned char buf[16];
  4851. nullpo_retr(0, sd);
  4852. WBUFW(buf,0)=0x106;
  4853. WBUFL(buf,2)=sd->status.account_id;
  4854. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  4855. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  4856. WBUFW(buf,8) = 100;
  4857. } else {
  4858. WBUFW(buf,6) = sd->battle_status.hp;
  4859. WBUFW(buf,8) = sd->battle_status.max_hp;
  4860. }
  4861. clif_send(buf,packet_len(0x106),&sd->bl,PARTY_AREA_WOS);
  4862. return 0;
  4863. }
  4864. /*==========================================
  4865. * Sends HP bar to a single fd. [Skotlex]
  4866. *------------------------------------------*/
  4867. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  4868. {
  4869. WFIFOHEAD(fd,packet_len(0x106));
  4870. WFIFOW(fd,0) = 0x106;
  4871. WFIFOL(fd,2) = id;
  4872. if( maxhp > SHRT_MAX )
  4873. {// To correctly display the %hp bar. [Skotlex]
  4874. WFIFOW(fd,6) = hp/(maxhp/100);
  4875. WFIFOW(fd,8) = 100;
  4876. } else {
  4877. WFIFOW(fd,6) = hp;
  4878. WFIFOW(fd,8) = maxhp;
  4879. }
  4880. WFIFOSET(fd, packet_len(0x106));
  4881. }
  4882. /*==========================================
  4883. * GMへ場所とHP通知
  4884. *------------------------------------------*/
  4885. int clif_hpmeter(struct map_session_data *sd)
  4886. {
  4887. struct map_session_data *sd2;
  4888. unsigned char buf[16];
  4889. int i, x0, y0, x1, y1;
  4890. int level;
  4891. nullpo_retr(0, sd);
  4892. x0 = sd->bl.x - AREA_SIZE;
  4893. y0 = sd->bl.y - AREA_SIZE;
  4894. x1 = sd->bl.x + AREA_SIZE;
  4895. y1 = sd->bl.y + AREA_SIZE;
  4896. WBUFW(buf,0) = 0x106;
  4897. WBUFL(buf,2) = sd->status.account_id;
  4898. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  4899. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  4900. WBUFW(buf,8) = 100;
  4901. } else {
  4902. WBUFW(buf,6) = sd->battle_status.hp;
  4903. WBUFW(buf,8) = sd->battle_status.max_hp;
  4904. }
  4905. for (i = 0; i < fd_max; i++) {
  4906. if (session[i] && session[i]->func_parse == clif_parse &&
  4907. (sd2 = (struct map_session_data*)session[i]->session_data) &&
  4908. sd != sd2 && sd2->state.active) {
  4909. if (sd2->bl.m != sd->bl.m ||
  4910. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  4911. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  4912. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  4913. level < pc_isGM(sd))
  4914. continue;
  4915. WFIFOHEAD (i, packet_len(0x106));
  4916. memcpy (WFIFOP(i,0), buf, packet_len(0x106));
  4917. WFIFOSET (i, packet_len(0x106));
  4918. }
  4919. }
  4920. return 0;
  4921. }
  4922. /*==========================================
  4923. * パーティ場所移動(未使用)
  4924. *------------------------------------------*/
  4925. void clif_party_move(struct party* p, struct map_session_data* sd, int online)
  4926. {
  4927. unsigned char buf[128];
  4928. nullpo_retv(sd);
  4929. nullpo_retv(p);
  4930. WBUFW(buf, 0) = 0x104;
  4931. WBUFL(buf, 2) = sd->status.account_id;
  4932. WBUFL(buf, 6) = 0;
  4933. WBUFW(buf,10) = sd->bl.x;
  4934. WBUFW(buf,12) = sd->bl.y;
  4935. WBUFB(buf,14) = !online;
  4936. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  4937. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  4938. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  4939. clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
  4940. }
  4941. /*==========================================
  4942. * 攻撃するために移動が必要
  4943. *------------------------------------------*/
  4944. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  4945. {
  4946. int fd;
  4947. nullpo_retr(0, sd);
  4948. nullpo_retr(0, bl);
  4949. fd=sd->fd;
  4950. WFIFOHEAD(fd,packet_len(0x139));
  4951. WFIFOW(fd, 0)=0x139;
  4952. WFIFOL(fd, 2)=bl->id;
  4953. WFIFOW(fd, 6)=bl->x;
  4954. WFIFOW(fd, 8)=bl->y;
  4955. WFIFOW(fd,10)=sd->bl.x;
  4956. WFIFOW(fd,12)=sd->bl.y;
  4957. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  4958. WFIFOSET(fd,packet_len(0x139));
  4959. return 0;
  4960. }
  4961. /*==========================================
  4962. * 製造エフェクト
  4963. *------------------------------------------*/
  4964. int clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  4965. {
  4966. int view,fd;
  4967. nullpo_retr(0, sd);
  4968. fd = sd->fd;
  4969. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  4970. WFIFOHEAD(fd,packet_len(0x18f));
  4971. WFIFOW(fd, 0)=0x18f;
  4972. WFIFOW(fd, 2)=flag;
  4973. if((view = itemdb_viewid(nameid)) > 0)
  4974. WFIFOW(fd, 4)=view;
  4975. else
  4976. WFIFOW(fd, 4)=nameid;
  4977. WFIFOSET(fd,packet_len(0x18f));
  4978. return 0;
  4979. }
  4980. // pet
  4981. int clif_catch_process(struct map_session_data *sd)
  4982. {
  4983. int fd;
  4984. nullpo_retr(0, sd);
  4985. fd=sd->fd;
  4986. WFIFOHEAD(fd,packet_len(0x19e));
  4987. WFIFOW(fd,0)=0x19e;
  4988. WFIFOSET(fd,packet_len(0x19e));
  4989. return 0;
  4990. }
  4991. int clif_pet_roulette(struct map_session_data *sd,int data)
  4992. {
  4993. int fd;
  4994. nullpo_retr(0, sd);
  4995. fd=sd->fd;
  4996. WFIFOHEAD(fd,packet_len(0x1a0));
  4997. WFIFOW(fd,0)=0x1a0;
  4998. WFIFOB(fd,2)=data;
  4999. WFIFOSET(fd,packet_len(0x1a0));
  5000. return 0;
  5001. }
  5002. /*==========================================
  5003. * pet卵リスト作成
  5004. *------------------------------------------*/
  5005. int clif_sendegg(struct map_session_data *sd)
  5006. {
  5007. //R 01a6 <len>.w <index>.w*
  5008. int i,n=0,fd;
  5009. nullpo_retr(0, sd);
  5010. fd=sd->fd;
  5011. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5012. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5013. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5014. return 0;
  5015. }
  5016. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5017. WFIFOW(fd,0)=0x1a6;
  5018. if(sd->status.pet_id <= 0) {
  5019. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5020. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5021. sd->inventory_data[i]->type!=IT_PETEGG ||
  5022. sd->status.inventory[i].amount<=0)
  5023. continue;
  5024. WFIFOW(fd,n*2+4)=i+2;
  5025. n++;
  5026. }
  5027. }
  5028. WFIFOW(fd,2)=4+n*2;
  5029. WFIFOSET(fd,WFIFOW(fd,2));
  5030. sd->menuskill_id = SA_TAMINGMONSTER;
  5031. sd->menuskill_val = -1;
  5032. return 0;
  5033. }
  5034. /*==========================================
  5035. * Sends a specific pet data update.
  5036. * type = 0 -> param = 0 (initial data)
  5037. * type = 1 -> param = intimacy value
  5038. * type = 2 -> param = hungry value
  5039. * type = 3 -> param = accessory id
  5040. * type = 4 -> param = performance number (1-3:normal, 4:special)
  5041. * type = 5 -> param = hairstyle number
  5042. * If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5043. *------------------------------------------*/
  5044. int clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5045. {
  5046. uint8 buf[16];
  5047. nullpo_retr(0, pd);
  5048. WBUFW(buf,0) = 0x1a4;
  5049. WBUFB(buf,2) = type;
  5050. WBUFL(buf,3) = pd->bl.id;
  5051. WBUFL(buf,7) = param;
  5052. if (sd)
  5053. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5054. else
  5055. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5056. return 0;
  5057. }
  5058. int clif_send_petstatus(struct map_session_data *sd)
  5059. {
  5060. int fd;
  5061. struct s_pet *pet;
  5062. nullpo_retr(0, sd);
  5063. nullpo_retr(0, sd->pd);
  5064. fd=sd->fd;
  5065. pet = &sd->pd->pet;
  5066. WFIFOHEAD(fd,packet_len(0x1a2));
  5067. WFIFOW(fd,0)=0x1a2;
  5068. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5069. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5070. WFIFOW(fd,27)=pet->level;
  5071. WFIFOW(fd,29)=pet->hungry;
  5072. WFIFOW(fd,31)=pet->intimate;
  5073. WFIFOW(fd,33)=pet->equip;
  5074. WFIFOSET(fd,packet_len(0x1a2));
  5075. return 0;
  5076. }
  5077. /*==========================================
  5078. *
  5079. *------------------------------------------*/
  5080. int clif_pet_emotion(struct pet_data *pd,int param)
  5081. {
  5082. unsigned char buf[16];
  5083. nullpo_retr(0, pd);
  5084. memset(buf,0,packet_len(0x1aa));
  5085. WBUFW(buf,0)=0x1aa;
  5086. WBUFL(buf,2)=pd->bl.id;
  5087. if(param >= 100 && pd->petDB->talk_convert_class) {
  5088. if(pd->petDB->talk_convert_class < 0)
  5089. return 0;
  5090. else if(pd->petDB->talk_convert_class > 0) {
  5091. param -= (pd->pet.class_ - 100)*100;
  5092. param += (pd->petDB->talk_convert_class - 100)*100;
  5093. }
  5094. }
  5095. WBUFL(buf,6)=param;
  5096. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5097. return 0;
  5098. }
  5099. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5100. {
  5101. int fd;
  5102. nullpo_retr(0, sd);
  5103. fd=sd->fd;
  5104. WFIFOHEAD(fd,packet_len(0x1a3));
  5105. WFIFOW(fd,0)=0x1a3;
  5106. WFIFOB(fd,2)=fail;
  5107. WFIFOW(fd,3)=foodid;
  5108. WFIFOSET(fd,packet_len(0x1a3));
  5109. return 0;
  5110. }
  5111. /*==========================================
  5112. * オートスペル リスト送信
  5113. *------------------------------------------*/
  5114. int clif_autospell(struct map_session_data *sd,int skilllv)
  5115. {
  5116. int fd;
  5117. nullpo_retr(0, sd);
  5118. fd=sd->fd;
  5119. WFIFOHEAD(fd,packet_len(0x1cd));
  5120. WFIFOW(fd, 0)=0x1cd;
  5121. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5122. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5123. else
  5124. WFIFOL(fd,2)= 0x00000000;
  5125. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5126. WFIFOL(fd,6)= MG_COLDBOLT;
  5127. else
  5128. WFIFOL(fd,6)= 0x00000000;
  5129. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5130. WFIFOL(fd,10)= MG_FIREBOLT;
  5131. else
  5132. WFIFOL(fd,10)= 0x00000000;
  5133. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5134. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5135. else
  5136. WFIFOL(fd,14)= 0x00000000;
  5137. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5138. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5139. else
  5140. WFIFOL(fd,18)= 0x00000000;
  5141. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5142. WFIFOL(fd,22)= MG_FIREBALL;
  5143. else
  5144. WFIFOL(fd,22)= 0x00000000;
  5145. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5146. WFIFOL(fd,26)= MG_FROSTDIVER;
  5147. else
  5148. WFIFOL(fd,26)= 0x00000000;
  5149. WFIFOSET(fd,packet_len(0x1cd));
  5150. sd->menuskill_id = SA_AUTOSPELL;
  5151. sd->menuskill_val = skilllv;
  5152. return 0;
  5153. }
  5154. /*==========================================
  5155. * Devotion's visual effect
  5156. * S 01cf <devoter id>.L { <devotee id>.L }[5] <max distance>.W
  5157. *------------------------------------------*/
  5158. void clif_devotion(struct map_session_data *sd, struct map_session_data *tsd)
  5159. {
  5160. unsigned char buf[56];
  5161. int i;
  5162. nullpo_retv(sd);
  5163. WBUFW(buf,0) = 0x1cf;
  5164. WBUFL(buf,2) = sd->bl.id;
  5165. for( i = 0; i < 5; i++ )
  5166. WBUFL(buf,6+4*i) = sd->devotion[i];
  5167. WBUFW(buf,26) = skill_get_range2(&sd->bl,CR_DEVOTION,pc_checkskill(sd,CR_DEVOTION)); // ignored
  5168. if( tsd )
  5169. clif_send(buf,packet_len(0x1cf),&tsd->bl,SELF);
  5170. else
  5171. clif_send(buf,packet_len(0x1cf),&sd->bl,AREA);
  5172. }
  5173. /*==========================================
  5174. * 氣球
  5175. *------------------------------------------*/
  5176. int clif_spiritball(struct map_session_data *sd)
  5177. {
  5178. unsigned char buf[16];
  5179. nullpo_retr(0, sd);
  5180. WBUFW(buf,0)=0x1d0;
  5181. WBUFL(buf,2)=sd->bl.id;
  5182. WBUFW(buf,6)=sd->spiritball;
  5183. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5184. return 0;
  5185. }
  5186. /*==========================================
  5187. *
  5188. *------------------------------------------*/
  5189. int clif_combo_delay(struct block_list *bl,int wait)
  5190. {
  5191. unsigned char buf[32];
  5192. nullpo_retr(0, bl);
  5193. WBUFW(buf,0)=0x1d2;
  5194. WBUFL(buf,2)=bl->id;
  5195. WBUFL(buf,6)=wait;
  5196. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5197. return 0;
  5198. }
  5199. /*==========================================
  5200. *白刃取り
  5201. *------------------------------------------*/
  5202. int clif_bladestop(struct block_list *src,struct block_list *dst,
  5203. int _bool)
  5204. {
  5205. unsigned char buf[32];
  5206. nullpo_retr(0, src);
  5207. nullpo_retr(0, dst);
  5208. WBUFW(buf,0)=0x1d1;
  5209. WBUFL(buf,2)=src->id;
  5210. WBUFL(buf,6)=dst->id;
  5211. WBUFL(buf,10)=_bool;
  5212. clif_send(buf,packet_len(0x1d1),src,AREA);
  5213. return 0;
  5214. }
  5215. /*==========================================
  5216. * MVPエフェクト
  5217. *------------------------------------------*/
  5218. int clif_mvp_effect(struct map_session_data *sd)
  5219. {
  5220. unsigned char buf[16];
  5221. nullpo_retr(0, sd);
  5222. WBUFW(buf,0)=0x10c;
  5223. WBUFL(buf,2)=sd->bl.id;
  5224. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5225. return 0;
  5226. }
  5227. /*==========================================
  5228. * MVPアイテム所得
  5229. *------------------------------------------*/
  5230. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5231. {
  5232. int view,fd;
  5233. nullpo_retr(0, sd);
  5234. fd=sd->fd;
  5235. WFIFOHEAD(fd,packet_len(0x10a));
  5236. WFIFOW(fd,0)=0x10a;
  5237. if((view = itemdb_viewid(nameid)) > 0)
  5238. WFIFOW(fd,2)=view;
  5239. else
  5240. WFIFOW(fd,2)=nameid;
  5241. WFIFOSET(fd,packet_len(0x10a));
  5242. return 0;
  5243. }
  5244. /*==========================================
  5245. * MVP経験値所得
  5246. *------------------------------------------*/
  5247. int clif_mvp_exp(struct map_session_data *sd,unsigned long exp)
  5248. {
  5249. int fd;
  5250. nullpo_retr(0, sd);
  5251. fd=sd->fd;
  5252. WFIFOHEAD(fd,packet_len(0x10b));
  5253. WFIFOW(fd,0)=0x10b;
  5254. WFIFOL(fd,2)=exp;
  5255. WFIFOSET(fd,packet_len(0x10b));
  5256. return 0;
  5257. }
  5258. /*==========================================
  5259. * ギルド作成可否通知
  5260. *------------------------------------------*/
  5261. int clif_guild_created(struct map_session_data *sd,int flag)
  5262. {
  5263. int fd;
  5264. nullpo_retr(0, sd);
  5265. fd=sd->fd;
  5266. WFIFOHEAD(fd,packet_len(0x167));
  5267. WFIFOW(fd,0)=0x167;
  5268. WFIFOB(fd,2)=flag;
  5269. WFIFOSET(fd,packet_len(0x167));
  5270. return 0;
  5271. }
  5272. /*==========================================
  5273. * ギルド所属通知
  5274. *------------------------------------------*/
  5275. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  5276. {
  5277. int ps,fd;
  5278. nullpo_retr(0, sd);
  5279. nullpo_retr(0, g);
  5280. fd=sd->fd;
  5281. ps=guild_getposition(g,sd);
  5282. WFIFOHEAD(fd,packet_len(0x16c));
  5283. memset(WFIFOP(fd,0),0,packet_len(0x16c));
  5284. WFIFOW(fd,0)=0x16c;
  5285. WFIFOL(fd,2)=g->guild_id;
  5286. WFIFOL(fd,6)=g->emblem_id;
  5287. WFIFOL(fd,10)=g->position[ps].mode;
  5288. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5289. WFIFOSET(fd,packet_len(0x16c));
  5290. return 0;
  5291. }
  5292. /*==========================================
  5293. * ギルドメンバログイン通知
  5294. *------------------------------------------*/
  5295. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5296. {
  5297. unsigned char buf[64];
  5298. nullpo_retr(0, g);
  5299. WBUFW(buf, 0)=0x16d;
  5300. WBUFL(buf, 2)=g->member[idx].account_id;
  5301. WBUFL(buf, 6)=g->member[idx].char_id;
  5302. WBUFL(buf,10)=flag;
  5303. if(g->member[idx].sd==NULL){
  5304. struct map_session_data *sd=guild_getavailablesd(g);
  5305. if(sd!=NULL)
  5306. clif_send(buf,packet_len(0x16d),&sd->bl,GUILD);
  5307. }else
  5308. clif_send(buf,packet_len(0x16d),&g->member[idx].sd->bl,GUILD_WOS);
  5309. return 0;
  5310. }
  5311. // Function `clif_guild_memberlogin_notice` sends info about
  5312. // logins and logouts of a guild member to the rest members.
  5313. // But at the 1st time (after a player login or map changing)
  5314. // the client won't show the message.
  5315. // So I suggest use this function for sending "first-time-info"
  5316. // to some player on entering the game or changing location.
  5317. // At next time the client would always show the message.
  5318. // The function sends all the statuses in the single packet
  5319. // to economize traffic. [LuzZza]
  5320. int clif_guild_send_onlineinfo(struct map_session_data *sd)
  5321. {
  5322. struct guild *g;
  5323. unsigned char buf[14*128];
  5324. int i, count=0, p_len;
  5325. nullpo_retr(0, sd);
  5326. p_len = packet_len(0x16d);
  5327. if(!(g = guild_search(sd->status.guild_id)))
  5328. return 0;
  5329. for(i=0; i<g->max_member; i++) {
  5330. if(g->member[i].account_id > 0 &&
  5331. g->member[i].account_id != sd->status.account_id) {
  5332. WBUFW(buf,count*p_len) = 0x16d;
  5333. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5334. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5335. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5336. count++;
  5337. }
  5338. }
  5339. clif_send(buf, p_len*count, &sd->bl, SELF);
  5340. return 0;
  5341. }
  5342. /*==========================================
  5343. * ギルドマスター通知(14dへの応答)
  5344. *------------------------------------------*/
  5345. int clif_guild_masterormember(struct map_session_data *sd)
  5346. {
  5347. int fd;
  5348. nullpo_retr(0, sd);
  5349. fd=sd->fd;
  5350. WFIFOHEAD(fd,packet_len(0x14e));
  5351. WFIFOW(fd,0) = 0x14e;
  5352. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  5353. WFIFOSET(fd,packet_len(0x14e));
  5354. return 0;
  5355. }
  5356. /*==========================================
  5357. * Basic Info (Territories [Valaris])
  5358. *------------------------------------------*/
  5359. int clif_guild_basicinfo(struct map_session_data *sd)
  5360. {
  5361. int fd,i,t;
  5362. struct guild *g;
  5363. struct guild_castle *gc=NULL;
  5364. nullpo_retr(0, sd);
  5365. fd=sd->fd;
  5366. g=guild_search(sd->status.guild_id);
  5367. if(g==NULL)
  5368. return 0;
  5369. WFIFOHEAD(fd,packet_len(0x1b6));
  5370. WFIFOW(fd, 0)=0x1b6;//0x150;
  5371. WFIFOL(fd, 2)=g->guild_id;
  5372. WFIFOL(fd, 6)=g->guild_lv;
  5373. WFIFOL(fd,10)=g->connect_member;
  5374. WFIFOL(fd,14)=g->max_member;
  5375. WFIFOL(fd,18)=g->average_lv;
  5376. WFIFOL(fd,22)=g->exp;
  5377. WFIFOL(fd,26)=g->next_exp;
  5378. WFIFOL(fd,30)=0; // Tax Points
  5379. WFIFOL(fd,34)=0; // Tendency: (left) Vulgar [-100,100] Famed (right)
  5380. WFIFOL(fd,38)=0; // Tendency: (down) Wicked [-100,100] Righteous (up)
  5381. WFIFOL(fd,42)=g->emblem_id;
  5382. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5383. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5384. for(i = 0, t = 0; i < MAX_GUILDCASTLE; i++)
  5385. {
  5386. gc = guild_castle_search(i);
  5387. if(gc && g->guild_id == gc->guild_id)
  5388. t++;
  5389. }
  5390. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20); // "'N' castles"
  5391. WFIFOSET(fd,packet_len(WFIFOW(fd,0)));
  5392. return 0;
  5393. }
  5394. /*==========================================
  5395. * ギルド同盟/敵対情報
  5396. *------------------------------------------*/
  5397. int clif_guild_allianceinfo(struct map_session_data *sd)
  5398. {
  5399. int fd,i,c;
  5400. struct guild *g;
  5401. nullpo_retr(0, sd);
  5402. fd=sd->fd;
  5403. g=guild_search(sd->status.guild_id);
  5404. if(g==NULL)
  5405. return 0;
  5406. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5407. WFIFOW(fd, 0)=0x14c;
  5408. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5409. struct guild_alliance *a=&g->alliance[i];
  5410. if(a->guild_id>0){
  5411. WFIFOL(fd,c*32+4)=a->opposition;
  5412. WFIFOL(fd,c*32+8)=a->guild_id;
  5413. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5414. c++;
  5415. }
  5416. }
  5417. WFIFOW(fd, 2)=c*32+4;
  5418. WFIFOSET(fd,WFIFOW(fd,2));
  5419. return 0;
  5420. }
  5421. /*==========================================
  5422. * ギルドメンバーリスト
  5423. *------------------------------------------*/
  5424. int clif_guild_memberlist(struct map_session_data *sd)
  5425. {
  5426. int fd;
  5427. int i,c;
  5428. struct guild *g;
  5429. nullpo_retr(0, sd);
  5430. fd=sd->fd;
  5431. if (!fd)
  5432. return 0;
  5433. g=guild_search(sd->status.guild_id);
  5434. if(g==NULL)
  5435. return 0;
  5436. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5437. WFIFOW(fd, 0)=0x154;
  5438. for(i=0,c=0;i<g->max_member;i++){
  5439. struct guild_member *m=&g->member[i];
  5440. if(m->account_id==0)
  5441. continue;
  5442. WFIFOL(fd,c*104+ 4)=m->account_id;
  5443. WFIFOL(fd,c*104+ 8)=m->char_id;
  5444. WFIFOW(fd,c*104+12)=m->hair;
  5445. WFIFOW(fd,c*104+14)=m->hair_color;
  5446. WFIFOW(fd,c*104+16)=m->gender;
  5447. WFIFOW(fd,c*104+18)=m->class_;
  5448. WFIFOW(fd,c*104+20)=m->lv;
  5449. WFIFOL(fd,c*104+22)=m->exp;
  5450. WFIFOL(fd,c*104+26)=m->online;
  5451. WFIFOL(fd,c*104+30)=m->position;
  5452. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5453. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5454. c++;
  5455. }
  5456. WFIFOW(fd, 2)=c*104+4;
  5457. WFIFOSET(fd,WFIFOW(fd,2));
  5458. return 0;
  5459. }
  5460. /*==========================================
  5461. * ギルド役職名リスト
  5462. *------------------------------------------*/
  5463. int clif_guild_positionnamelist(struct map_session_data *sd)
  5464. {
  5465. int i,fd;
  5466. struct guild *g;
  5467. nullpo_retr(0, sd);
  5468. fd=sd->fd;
  5469. g=guild_search(sd->status.guild_id);
  5470. if(g==NULL)
  5471. return 0;
  5472. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5473. WFIFOW(fd, 0)=0x166;
  5474. for(i=0;i<MAX_GUILDPOSITION;i++){
  5475. WFIFOL(fd,i*28+4)=i;
  5476. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5477. }
  5478. WFIFOW(fd,2)=i*28+4;
  5479. WFIFOSET(fd,WFIFOW(fd,2));
  5480. return 0;
  5481. }
  5482. /*==========================================
  5483. * ギルド役職情報リスト
  5484. *------------------------------------------*/
  5485. int clif_guild_positioninfolist(struct map_session_data *sd)
  5486. {
  5487. int i,fd;
  5488. struct guild *g;
  5489. nullpo_retr(0, sd);
  5490. fd=sd->fd;
  5491. g=guild_search(sd->status.guild_id);
  5492. if(g==NULL)
  5493. return 0;
  5494. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5495. WFIFOW(fd, 0)=0x160;
  5496. for(i=0;i<MAX_GUILDPOSITION;i++){
  5497. struct guild_position *p=&g->position[i];
  5498. WFIFOL(fd,i*16+ 4)=i;
  5499. WFIFOL(fd,i*16+ 8)=p->mode;
  5500. WFIFOL(fd,i*16+12)=i;
  5501. WFIFOL(fd,i*16+16)=p->exp_mode;
  5502. }
  5503. WFIFOW(fd, 2)=i*16+4;
  5504. WFIFOSET(fd,WFIFOW(fd,2));
  5505. return 0;
  5506. }
  5507. /*==========================================
  5508. * ギルド役職変更通知
  5509. *------------------------------------------*/
  5510. int clif_guild_positionchanged(struct guild *g,int idx)
  5511. {
  5512. struct map_session_data *sd;
  5513. unsigned char buf[128];
  5514. nullpo_retr(0, g);
  5515. WBUFW(buf, 0)=0x174;
  5516. WBUFW(buf, 2)=44;
  5517. WBUFL(buf, 4)=idx;
  5518. WBUFL(buf, 8)=g->position[idx].mode;
  5519. WBUFL(buf,12)=idx;
  5520. WBUFL(buf,16)=g->position[idx].exp_mode;
  5521. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  5522. if( (sd=guild_getavailablesd(g))!=NULL )
  5523. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5524. return 0;
  5525. }
  5526. /*==========================================
  5527. * ギルドメンバ変更通知
  5528. *------------------------------------------*/
  5529. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  5530. {
  5531. struct map_session_data *sd;
  5532. unsigned char buf[64];
  5533. nullpo_retr(0, g);
  5534. WBUFW(buf, 0)=0x156;
  5535. WBUFW(buf, 2)=16;
  5536. WBUFL(buf, 4)=g->member[idx].account_id;
  5537. WBUFL(buf, 8)=g->member[idx].char_id;
  5538. WBUFL(buf,12)=g->member[idx].position;
  5539. if( (sd=guild_getavailablesd(g))!=NULL )
  5540. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5541. return 0;
  5542. }
  5543. /*==========================================
  5544. * ギルドエンブレム送信
  5545. *------------------------------------------*/
  5546. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  5547. {
  5548. int fd;
  5549. nullpo_retr(0, sd);
  5550. nullpo_retr(0, g);
  5551. fd=sd->fd;
  5552. if(g->emblem_len<=0)
  5553. return 0;
  5554. WFIFOHEAD(fd,g->emblem_len+12);
  5555. WFIFOW(fd,0)=0x152;
  5556. WFIFOW(fd,2)=g->emblem_len+12;
  5557. WFIFOL(fd,4)=g->guild_id;
  5558. WFIFOL(fd,8)=g->emblem_id;
  5559. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  5560. WFIFOSET(fd,WFIFOW(fd,2));
  5561. return 0;
  5562. }
  5563. /*==========================================
  5564. * Send guild skills
  5565. *------------------------------------------*/
  5566. int clif_guild_skillinfo(struct map_session_data* sd)
  5567. {
  5568. int fd;
  5569. struct guild* g;
  5570. int i,c;
  5571. nullpo_retr(0, sd);
  5572. fd = sd->fd;
  5573. g = guild_search(sd->status.guild_id);
  5574. if(g == NULL)
  5575. return 0;
  5576. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  5577. WFIFOW(fd,0) = 0x0162;
  5578. WFIFOW(fd,4) = g->skill_point;
  5579. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  5580. {
  5581. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  5582. {
  5583. int id = g->skill[i].id;
  5584. int p = 6 + c*37;
  5585. WFIFOW(fd,p+0) = id;
  5586. WFIFOW(fd,p+2) = skill_get_inf(id);
  5587. WFIFOW(fd,p+4) = 0;
  5588. WFIFOW(fd,p+6) = g->skill[i].lv;
  5589. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  5590. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  5591. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  5592. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  5593. c++;
  5594. }
  5595. }
  5596. WFIFOW(fd,2) = 6 + c*37;
  5597. WFIFOSET(fd,WFIFOW(fd,2));
  5598. return 0;
  5599. }
  5600. /*==========================================
  5601. * Sends guild notice to client
  5602. * R 016f <str1z>.60B <str2z>.120B
  5603. *------------------------------------------*/
  5604. int clif_guild_notice(struct map_session_data* sd, struct guild* g)
  5605. {
  5606. int fd;
  5607. nullpo_retr(0, sd);
  5608. nullpo_retr(0, g);
  5609. fd = sd->fd;
  5610. if ( !session_isActive(fd) )
  5611. return 0;
  5612. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  5613. return 0;
  5614. WFIFOHEAD(fd,packet_len(0x16f));
  5615. WFIFOW(fd,0) = 0x16f;
  5616. memcpy(WFIFOP(fd,2), g->mes1, 60);
  5617. memcpy(WFIFOP(fd,62), g->mes2, 120);
  5618. WFIFOSET(fd,packet_len(0x16f));
  5619. return 0;
  5620. }
  5621. /*==========================================
  5622. * ギルドメンバ勧誘
  5623. *------------------------------------------*/
  5624. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  5625. {
  5626. int fd;
  5627. nullpo_retr(0, sd);
  5628. nullpo_retr(0, g);
  5629. fd=sd->fd;
  5630. WFIFOHEAD(fd,packet_len(0x16a));
  5631. WFIFOW(fd,0)=0x16a;
  5632. WFIFOL(fd,2)=g->guild_id;
  5633. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  5634. WFIFOSET(fd,packet_len(0x16a));
  5635. return 0;
  5636. }
  5637. /*==========================================
  5638. * ギルドメンバ勧誘結果
  5639. *------------------------------------------*/
  5640. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  5641. {
  5642. int fd;
  5643. nullpo_retr(0, sd);
  5644. fd=sd->fd;
  5645. WFIFOHEAD(fd,packet_len(0x169));
  5646. WFIFOW(fd,0)=0x169;
  5647. WFIFOB(fd,2)=flag;
  5648. WFIFOSET(fd,packet_len(0x169));
  5649. return 0;
  5650. }
  5651. /*==========================================
  5652. * ギルドメンバ脱退通知
  5653. *------------------------------------------*/
  5654. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  5655. {
  5656. unsigned char buf[128];
  5657. nullpo_retr(0, sd);
  5658. WBUFW(buf, 0)=0x15a;
  5659. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5660. memcpy(WBUFP(buf,26),mes,40);
  5661. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD);
  5662. return 0;
  5663. }
  5664. /*==========================================
  5665. * ギルドメンバ追放通知
  5666. *------------------------------------------*/
  5667. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,int account_id)
  5668. {
  5669. unsigned char buf[128];
  5670. nullpo_retr(0, sd);
  5671. WBUFW(buf, 0)=0x15c;
  5672. safestrncpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5673. safestrncpy(WBUFP(buf,26),mes,40);
  5674. safestrncpy(WBUFP(buf,66),"",NAME_LENGTH); // account name (not used for security reasons)
  5675. clif_send(buf,packet_len(0x15c),&sd->bl,GUILD);
  5676. return 0;
  5677. }
  5678. /*==========================================
  5679. * ギルド追放メンバリスト
  5680. *------------------------------------------*/
  5681. int clif_guild_expulsionlist(struct map_session_data *sd)
  5682. {
  5683. int fd;
  5684. int i,c;
  5685. struct guild *g;
  5686. nullpo_retr(0, sd);
  5687. fd=sd->fd;
  5688. g=guild_search(sd->status.guild_id);
  5689. if(g==NULL)
  5690. return 0;
  5691. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * 88);
  5692. WFIFOW(fd,0)=0x163;
  5693. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  5694. struct guild_expulsion *e=&g->expulsion[i];
  5695. if(e->account_id>0){
  5696. safestrncpy(WFIFOP(fd,4 + c*88),e->name,NAME_LENGTH);
  5697. safestrncpy(WFIFOP(fd,4 + c*88+24),"",24); // account name (not used for security reasons)
  5698. safestrncpy(WFIFOP(fd,4 + c*88+48),e->mes,40);
  5699. c++;
  5700. }
  5701. }
  5702. WFIFOW(fd,2) = 4 + c*88;
  5703. WFIFOSET(fd,WFIFOW(fd,2));
  5704. return 0;
  5705. }
  5706. /*==========================================
  5707. * ギルド会話
  5708. *------------------------------------------*/
  5709. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  5710. {
  5711. struct map_session_data *sd;
  5712. unsigned char *buf;
  5713. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  5714. WBUFW(buf, 0) = 0x17f;
  5715. WBUFW(buf, 2) = len + 4;
  5716. memcpy(WBUFP(buf,4), mes, len);
  5717. if ((sd = guild_getavailablesd(g)) != NULL)
  5718. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  5719. if(buf) aFree(buf);
  5720. return 0;
  5721. }
  5722. /*==========================================
  5723. * ギルドスキル割り振り通知
  5724. *------------------------------------------*/
  5725. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  5726. {
  5727. int fd;
  5728. nullpo_retr(0, sd);
  5729. fd=sd->fd;
  5730. WFIFOHEAD(fd,11);
  5731. WFIFOW(fd,0) = 0x10e;
  5732. WFIFOW(fd,2) = skill_num;
  5733. WFIFOW(fd,4) = lv;
  5734. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  5735. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  5736. WFIFOB(fd,10) = 1;
  5737. WFIFOSET(fd,11);
  5738. return 0;
  5739. }
  5740. /*==========================================
  5741. * ギルド同盟要請
  5742. *------------------------------------------*/
  5743. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  5744. {
  5745. int fd;
  5746. nullpo_retr(0, sd);
  5747. fd=sd->fd;
  5748. WFIFOHEAD(fd,packet_len(0x171));
  5749. WFIFOW(fd,0)=0x171;
  5750. WFIFOL(fd,2)=account_id;
  5751. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  5752. WFIFOSET(fd,packet_len(0x171));
  5753. return 0;
  5754. }
  5755. /*==========================================
  5756. * Reply to alliance request.
  5757. * Flag values are:
  5758. * 0: Already allied.
  5759. * 1: You rejected the offer.
  5760. * 2: You accepted the offer.
  5761. * 3: They have too any alliances
  5762. * 4: You have too many alliances.
  5763. *------------------------------------------*/
  5764. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  5765. {
  5766. int fd;
  5767. nullpo_retr(0, sd);
  5768. fd=sd->fd;
  5769. WFIFOHEAD(fd,packet_len(0x173));
  5770. WFIFOW(fd,0)=0x173;
  5771. WFIFOL(fd,2)=flag;
  5772. WFIFOSET(fd,packet_len(0x173));
  5773. return 0;
  5774. }
  5775. /*==========================================
  5776. * ギルド関係解消通知
  5777. *------------------------------------------*/
  5778. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  5779. {
  5780. int fd;
  5781. nullpo_retr(0, sd);
  5782. fd = sd->fd;
  5783. if (fd <= 0)
  5784. return 0;
  5785. WFIFOHEAD(fd,packet_len(0x184));
  5786. WFIFOW(fd,0)=0x184;
  5787. WFIFOL(fd,2)=guild_id;
  5788. WFIFOL(fd,6)=flag;
  5789. WFIFOSET(fd,packet_len(0x184));
  5790. return 0;
  5791. }
  5792. /*==========================================
  5793. * ギルド敵対結果
  5794. *------------------------------------------*/
  5795. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  5796. {
  5797. int fd;
  5798. nullpo_retr(0, sd);
  5799. fd=sd->fd;
  5800. WFIFOHEAD(fd,packet_len(0x181));
  5801. WFIFOW(fd,0)=0x181;
  5802. WFIFOB(fd,2)=flag;
  5803. WFIFOSET(fd,packet_len(0x181));
  5804. return 0;
  5805. }
  5806. /*==========================================
  5807. * ギルド関係追加
  5808. *------------------------------------------*/
  5809. /*int clif_guild_allianceadded(struct guild *g,int idx)
  5810. {
  5811. unsigned char buf[64];
  5812. WBUFW(fd,0)=0x185;
  5813. WBUFL(fd,2)=g->alliance[idx].opposition;
  5814. WBUFL(fd,6)=g->alliance[idx].guild_id;
  5815. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  5816. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  5817. return 0;
  5818. }*/
  5819. /*==========================================
  5820. * ギルド解散通知
  5821. *------------------------------------------*/
  5822. int clif_guild_broken(struct map_session_data *sd,int flag)
  5823. {
  5824. int fd;
  5825. nullpo_retr(0, sd);
  5826. fd=sd->fd;
  5827. WFIFOHEAD(fd,packet_len(0x15e));
  5828. WFIFOW(fd,0)=0x15e;
  5829. WFIFOL(fd,2)=flag;
  5830. WFIFOSET(fd,packet_len(0x15e));
  5831. return 0;
  5832. }
  5833. /*==========================================
  5834. * エモーション
  5835. *------------------------------------------*/
  5836. void clif_emotion(struct block_list *bl,int type)
  5837. {
  5838. unsigned char buf[8];
  5839. nullpo_retv(bl);
  5840. WBUFW(buf,0)=0xc0;
  5841. WBUFL(buf,2)=bl->id;
  5842. WBUFB(buf,6)=type;
  5843. clif_send(buf,packet_len(0xc0),bl,AREA);
  5844. }
  5845. /*==========================================
  5846. * トーキーボックス
  5847. *------------------------------------------*/
  5848. void clif_talkiebox(struct block_list* bl, const char* talkie)
  5849. {
  5850. unsigned char buf[86];
  5851. nullpo_retv(bl);
  5852. WBUFW(buf,0) = 0x191;
  5853. WBUFL(buf,2) = bl->id;
  5854. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  5855. clif_send(buf,packet_len(0x191),bl,AREA);
  5856. }
  5857. /*==========================================
  5858. * 結婚エフェクト
  5859. *------------------------------------------*/
  5860. void clif_wedding_effect(struct block_list *bl)
  5861. {
  5862. unsigned char buf[6];
  5863. nullpo_retv(bl);
  5864. WBUFW(buf,0) = 0x1ea;
  5865. WBUFL(buf,2) = bl->id;
  5866. clif_send(buf, packet_len(0x1ea), bl, AREA);
  5867. }
  5868. /*==========================================
  5869. * あなたに逢いたい使用時名前叫び
  5870. *------------------------------------------
  5871. void clif_callpartner(struct map_session_data *sd)
  5872. {
  5873. unsigned char buf[26];
  5874. char *p;
  5875. nullpo_retv(sd);
  5876. if(sd->status.partner_id){
  5877. WBUFW(buf,0)=0x1e6;
  5878. p = map_charid2nick(sd->status.partner_id);
  5879. if(p){
  5880. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  5881. }else{
  5882. map_reqchariddb(sd,sd->status.partner_id);
  5883. chrif_searchcharid(sd->status.partner_id);
  5884. WBUFB(buf,2) = 0;
  5885. }
  5886. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  5887. }
  5888. return;
  5889. }
  5890. */
  5891. /*==========================================
  5892. * Adopt baby [Celest]
  5893. *------------------------------------------*/
  5894. void clif_adopt_process(struct map_session_data *sd)
  5895. {
  5896. int fd;
  5897. nullpo_retv(sd);
  5898. fd=sd->fd;
  5899. WFIFOHEAD(fd,packet_len(0x1f8));
  5900. WFIFOW(fd,0)=0x1f8;
  5901. WFIFOSET(fd,packet_len(0x1f8));
  5902. }
  5903. /*==========================================
  5904. * Marry [DracoRPG]
  5905. *------------------------------------------*/
  5906. void clif_marriage_process(struct map_session_data *sd)
  5907. {
  5908. int fd;
  5909. nullpo_retv(sd);
  5910. fd=sd->fd;
  5911. WFIFOHEAD(fd,packet_len(0x1e4));
  5912. WFIFOW(fd,0)=0x1e4;
  5913. WFIFOSET(fd,packet_len(0x1e4));
  5914. }
  5915. /*==========================================
  5916. * Notice of divorce
  5917. *------------------------------------------*/
  5918. void clif_divorced(struct map_session_data* sd, const char* name)
  5919. {
  5920. int fd;
  5921. nullpo_retv(sd);
  5922. fd=sd->fd;
  5923. WFIFOHEAD(fd,packet_len(0x205));
  5924. WFIFOW(fd,0)=0x205;
  5925. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  5926. WFIFOSET(fd, packet_len(0x205));
  5927. }
  5928. /*==========================================
  5929. *
  5930. *------------------------------------------*/
  5931. void clif_parse_ReqAdopt(int fd, struct map_session_data *sd)
  5932. {
  5933. nullpo_retv(sd);
  5934. WFIFOHEAD(fd,packet_len(0x1f6));
  5935. WFIFOW(fd,0)=0x1f6;
  5936. WFIFOSET(fd, packet_len(0x1f6));
  5937. }
  5938. /*==========================================
  5939. *
  5940. *------------------------------------------*/
  5941. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd)
  5942. {
  5943. nullpo_retv(sd);
  5944. WFIFOHEAD(fd,packet_len(0x1e2));
  5945. WFIFOW(fd,0)=0x1e2;
  5946. WFIFOSET(fd, packet_len(0x1e2));
  5947. }
  5948. /*==========================================
  5949. *
  5950. *------------------------------------------*/
  5951. int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  5952. {
  5953. int fd;
  5954. nullpo_retr(0, sd);
  5955. fd = sd->fd;
  5956. if (!fd || !len) return 0; //Disconnected player.
  5957. WFIFOHEAD(fd, len+5);
  5958. WFIFOW(fd, 0) = 0x17f;
  5959. WFIFOW(fd, 2) = len + 5;
  5960. memcpy(WFIFOP(fd,4), mes, len);
  5961. WFIFOSET(fd, WFIFOW(fd,2));
  5962. return 1;
  5963. }
  5964. /*==========================================
  5965. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  5966. *------------------------------------------*/
  5967. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  5968. {
  5969. unsigned char buf[1024];
  5970. if (!len) return;
  5971. WBUFW(buf, 0) = 0x17f;
  5972. WBUFW(buf, 2) = len + 5;
  5973. memcpy(WBUFP(buf,4), mes, len);
  5974. clif_send(buf, WBUFW(buf,2), src, target);
  5975. return;
  5976. }
  5977. /*==========================================
  5978. *
  5979. *------------------------------------------*/
  5980. int clif_GM_kickack(struct map_session_data *sd, int id)
  5981. {
  5982. int fd;
  5983. nullpo_retr(0, sd);
  5984. fd = sd->fd;
  5985. WFIFOHEAD(fd,packet_len(0xcd));
  5986. WFIFOW(fd,0) = 0xcd;
  5987. WFIFOL(fd,2) = id;
  5988. WFIFOSET(fd, packet_len(0xcd));
  5989. return 0;
  5990. }
  5991. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  5992. {
  5993. int fd = tsd->fd;
  5994. if( fd > 0 )
  5995. clif_authfail_fd(fd, 15);
  5996. else
  5997. map_quit(tsd);
  5998. if( sd )
  5999. clif_GM_kickack(sd,tsd->status.account_id);
  6000. }
  6001. /// Displays various manner-related status messages
  6002. /// R 014a <type>.L
  6003. /// type: 0 - "A manner point has been successfully aligned."
  6004. /// 1 - ?
  6005. /// 2 - ?
  6006. /// 3 - "Chat Block has been applied by GM due to your ill-mannerous action."
  6007. /// 4 - "Automated Chat Block has been applied due to Anti-Spam System."
  6008. /// 5 - "You got a good point from %s."
  6009. void clif_manner_message(struct map_session_data* sd, uint32 type)
  6010. {
  6011. int fd;
  6012. nullpo_retv(sd);
  6013. fd = sd->fd;
  6014. WFIFOHEAD(fd,packet_len(0x14a));
  6015. WFIFOW(fd,0) = 0x14a;
  6016. WFIFOL(fd,2) = type;
  6017. WFIFOSET(fd, packet_len(0x14a));
  6018. }
  6019. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action.
  6020. /// R 014b <type>.B <GM name>.24B
  6021. /// type: 0 - positive (unmute)
  6022. /// 1 - negative (mute)
  6023. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  6024. {
  6025. int fd;
  6026. nullpo_retv(sd);
  6027. nullpo_retv(tsd);
  6028. fd = tsd->fd;
  6029. WFIFOHEAD(fd,packet_len(0x14b));
  6030. WFIFOW(fd,0) = 0x14b;
  6031. WFIFOB(fd,2) = type;
  6032. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6033. WFIFOSET(fd, packet_len(0x14b));
  6034. }
  6035. /*==========================================
  6036. *
  6037. *------------------------------------------*/
  6038. int clif_timedout(struct map_session_data *sd)
  6039. {
  6040. nullpo_retr(0, sd);
  6041. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' timed out.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id);
  6042. clif_authfail_fd(sd->fd,3); // Even if player is not on we still send anyway
  6043. clif_setwaitclose(sd->fd); // Set session to EOF
  6044. return 0;
  6045. }
  6046. /*==========================================
  6047. * Wis拒否許可応答
  6048. *------------------------------------------*/
  6049. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6050. {
  6051. int fd;
  6052. nullpo_retr(0, sd);
  6053. fd=sd->fd;
  6054. WFIFOHEAD(fd,packet_len(0xd1));
  6055. WFIFOW(fd,0)=0xd1;
  6056. WFIFOB(fd,2)=type;
  6057. WFIFOB(fd,3)=flag;
  6058. WFIFOSET(fd,packet_len(0xd1));
  6059. return 0;
  6060. }
  6061. /*==========================================
  6062. * Wis全拒否許可応答
  6063. *------------------------------------------*/
  6064. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6065. {
  6066. int fd;
  6067. nullpo_retr(0, sd);
  6068. fd=sd->fd;
  6069. WFIFOHEAD(fd,packet_len(0xd2));
  6070. WFIFOW(fd,0)=0xd2;
  6071. WFIFOB(fd,2)=type;
  6072. WFIFOB(fd,3)=flag;
  6073. WFIFOSET(fd,packet_len(0xd2));
  6074. return 0;
  6075. }
  6076. /*==========================================
  6077. * サウンドエフェクト
  6078. *------------------------------------------*/
  6079. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6080. {
  6081. int fd;
  6082. nullpo_retv(sd);
  6083. nullpo_retv(bl);
  6084. fd = sd->fd;
  6085. WFIFOHEAD(fd,packet_len(0x1d3));
  6086. WFIFOW(fd,0) = 0x1d3;
  6087. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6088. WFIFOB(fd,26) = type;
  6089. WFIFOL(fd,27) = 0;
  6090. WFIFOL(fd,31) = bl->id;
  6091. WFIFOSET(fd,packet_len(0x1d3));
  6092. return;
  6093. }
  6094. int clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6095. {
  6096. unsigned char buf[40];
  6097. nullpo_retr(0, bl);
  6098. WBUFW(buf,0) = 0x1d3;
  6099. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6100. WBUFB(buf,26) = type;
  6101. WBUFL(buf,27) = 0;
  6102. WBUFL(buf,31) = bl->id;
  6103. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6104. return 0;
  6105. }
  6106. // displaying special effects (npcs, weather, etc) [Valaris]
  6107. int clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6108. {
  6109. unsigned char buf[24];
  6110. nullpo_retr(0, bl);
  6111. memset(buf, 0, packet_len(0x1f3));
  6112. WBUFW(buf,0) = 0x1f3;
  6113. WBUFL(buf,2) = bl->id;
  6114. WBUFL(buf,6) = type;
  6115. clif_send(buf, packet_len(0x1f3), bl, target);
  6116. if (disguised(bl)) {
  6117. WBUFL(buf,2) = -bl->id;
  6118. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6119. }
  6120. return 0;
  6121. }
  6122. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  6123. {
  6124. WFIFOHEAD(fd,10);
  6125. WFIFOW(fd,0) = 0x1f3;
  6126. WFIFOL(fd,2) = bl->id;
  6127. WFIFOL(fd,6) = type;
  6128. WFIFOSET(fd,10);
  6129. }
  6130. // messages (from mobs/npcs) [Valaris]
  6131. int clif_message(struct block_list* bl, const char* msg)
  6132. {
  6133. unsigned short msg_len = strlen(msg) + 1;
  6134. uint8 buf[256];
  6135. nullpo_retr(0, bl);
  6136. WBUFW(buf,0) = 0x8d;
  6137. WBUFW(buf,2) = msg_len + 8;
  6138. WBUFL(buf,4) = bl->id;
  6139. memcpy(WBUFP(buf,8), msg, msg_len);
  6140. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6141. return 0;
  6142. }
  6143. // refresh the client's screen, getting rid of any effects
  6144. int clif_refresh(struct map_session_data *sd)
  6145. {
  6146. nullpo_retr(-1, sd);
  6147. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6148. clif_inventorylist(sd);
  6149. if(pc_iscarton(sd)) {
  6150. clif_cartlist(sd);
  6151. clif_updatestatus(sd,SP_CARTINFO);
  6152. }
  6153. clif_updatestatus(sd,SP_WEIGHT);
  6154. clif_updatestatus(sd,SP_MAXWEIGHT);
  6155. clif_updatestatus(sd,SP_STR);
  6156. clif_updatestatus(sd,SP_AGI);
  6157. clif_updatestatus(sd,SP_VIT);
  6158. clif_updatestatus(sd,SP_INT);
  6159. clif_updatestatus(sd,SP_DEX);
  6160. clif_updatestatus(sd,SP_LUK);
  6161. if (sd->spiritball)
  6162. clif_spiritball_single(sd->fd, sd);
  6163. if (sd->vd.cloth_color)
  6164. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6165. if(merc_is_hom_active(sd->hd))
  6166. clif_send_homdata(sd,0,0);
  6167. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6168. clif_weather_check(sd);
  6169. #ifndef TXT_ONLY
  6170. mail_clear(sd);
  6171. #endif
  6172. return 0;
  6173. }
  6174. // updates the object's (bl) name on client
  6175. int clif_charnameack (int fd, struct block_list *bl)
  6176. {
  6177. unsigned char buf[103];
  6178. int cmd = 0x95;
  6179. nullpo_retr(0, bl);
  6180. WBUFW(buf,0) = cmd;
  6181. WBUFL(buf,2) = bl->id;
  6182. switch(bl->type) {
  6183. case BL_PC:
  6184. {
  6185. struct map_session_data *ssd = (struct map_session_data *)bl;
  6186. struct party_data *p = NULL;
  6187. struct guild *g = NULL;
  6188. //Requesting your own "shadow" name. [Skotlex]
  6189. if (ssd->fd == fd && ssd->disguise)
  6190. WBUFL(buf,2) = -bl->id;
  6191. if (strlen(ssd->fakename)>1) {
  6192. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6193. break;
  6194. }
  6195. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6196. if (ssd->status.party_id > 0)
  6197. p = party_search(ssd->status.party_id);
  6198. if (ssd->status.guild_id > 0)
  6199. g = guild_search(ssd->status.guild_id);
  6200. if (p == NULL && g == NULL)
  6201. break;
  6202. WBUFW(buf, 0) = cmd = 0x195;
  6203. if (p)
  6204. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6205. else
  6206. WBUFB(buf,30) = 0;
  6207. if (g)
  6208. {
  6209. int i, ps = -1;
  6210. for(i = 0; i < g->max_member; i++) {
  6211. if (g->member[i].account_id == ssd->status.account_id &&
  6212. g->member[i].char_id == ssd->status.char_id )
  6213. {
  6214. ps = g->member[i].position;
  6215. break;
  6216. }
  6217. }
  6218. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6219. {
  6220. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6221. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6222. } else { //Assume no guild.
  6223. WBUFB(buf,54) = 0;
  6224. WBUFB(buf,78) = 0;
  6225. }
  6226. } else {
  6227. WBUFB(buf,54) = 0;
  6228. WBUFB(buf,78) = 0;
  6229. }
  6230. }
  6231. break;
  6232. //[blackhole89]
  6233. case BL_HOM:
  6234. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6235. break;
  6236. case BL_PET:
  6237. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6238. break;
  6239. case BL_NPC:
  6240. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6241. break;
  6242. case BL_MOB:
  6243. {
  6244. struct mob_data *md = (struct mob_data *)bl;
  6245. nullpo_retr(0, md);
  6246. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6247. if (md->guardian_data && md->guardian_data->guild_id) {
  6248. WBUFW(buf, 0) = cmd = 0x195;
  6249. WBUFB(buf,30) = 0;
  6250. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6251. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6252. } else if (battle_config.show_mob_info) {
  6253. char mobhp[50], *str_p = mobhp;
  6254. WBUFW(buf, 0) = cmd = 0x195;
  6255. if (battle_config.show_mob_info&4)
  6256. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6257. if (battle_config.show_mob_info&1)
  6258. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6259. if (battle_config.show_mob_info&2)
  6260. str_p += sprintf(str_p, "HP: %d%% | ", status_calc_life(md->status.hp, md->status.max_hp));
  6261. //Even thought mobhp ain't a name, we send it as one so the client
  6262. //can parse it. [Skotlex]
  6263. if (str_p != mobhp) {
  6264. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6265. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6266. WBUFB(buf,54) = 0;
  6267. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6268. }
  6269. }
  6270. }
  6271. break;
  6272. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6273. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6274. // break;
  6275. return 0;
  6276. default:
  6277. ShowError("clif_parse_GetCharNameRequest : bad type %d(%d)\n", bl->type, bl->id);
  6278. return 0;
  6279. }
  6280. // if no receipient specified just update nearby clients
  6281. if (fd == 0)
  6282. clif_send(buf, packet_len(cmd), bl, AREA);
  6283. else {
  6284. WFIFOHEAD(fd, packet_len(cmd));
  6285. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  6286. WFIFOSET(fd, packet_len(cmd));
  6287. }
  6288. return 0;
  6289. }
  6290. //Used to update when a char leaves a party/guild. [Skotlex]
  6291. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6292. int clif_charnameupdate (struct map_session_data *ssd)
  6293. {
  6294. unsigned char buf[103];
  6295. int cmd = 0x195;
  6296. struct party_data *p = NULL;
  6297. struct guild *g = NULL;
  6298. nullpo_retr(0, ssd);
  6299. if (strlen(ssd->fakename)>1)
  6300. return 0; //No need to update as the party/guild was not displayed anyway.
  6301. WBUFW(buf,0) = cmd;
  6302. WBUFL(buf,2) = ssd->bl.id;
  6303. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6304. if (ssd->status.party_id > 0)
  6305. p = party_search(ssd->status.party_id);
  6306. if (ssd->status.guild_id > 0)
  6307. g = guild_search(ssd->status.guild_id);
  6308. if (p)
  6309. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6310. else
  6311. WBUFB(buf,30) = 0;
  6312. if (g)
  6313. {
  6314. int i, ps = -1;
  6315. for(i = 0; i < g->max_member; i++) {
  6316. if (g->member[i].account_id == ssd->status.account_id &&
  6317. g->member[i].char_id == ssd->status.char_id )
  6318. {
  6319. ps = g->member[i].position;
  6320. break;
  6321. }
  6322. }
  6323. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6324. {
  6325. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6326. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6327. } else { //Assume no guild.
  6328. WBUFB(buf,54) = 0;
  6329. WBUFB(buf,78) = 0;
  6330. }
  6331. } else {
  6332. WBUFB(buf,54) = 0;
  6333. WBUFB(buf,78) = 0;
  6334. }
  6335. // Update nearby clients
  6336. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  6337. return 0;
  6338. }
  6339. int clif_slide(struct block_list *bl, int x, int y){
  6340. unsigned char buf[10];
  6341. nullpo_retr(0, bl);
  6342. WBUFW(buf, 0) = 0x01ff;
  6343. WBUFL(buf, 2) = bl->id;
  6344. WBUFW(buf, 6) = x;
  6345. WBUFW(buf, 8) = y;
  6346. clif_send(buf, packet_len(0x1ff), bl, AREA);
  6347. return 0;
  6348. }
  6349. /*------------------------------------------
  6350. * @me command by lordalfa, rewritten implementation by Skotlex
  6351. *------------------------------------------*/
  6352. int clif_disp_overhead(struct map_session_data *sd, const char* mes)
  6353. {
  6354. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  6355. int len_mes = strlen(mes)+1; //Account for \0
  6356. if (len_mes + 8 >= 256) {
  6357. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6358. len_mes = 247; //Trunk it to avoid problems.
  6359. }
  6360. // send message to others
  6361. WBUFW(buf,0) = 0x8d;
  6362. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6363. WBUFL(buf,4) = sd->bl.id;
  6364. memcpy(WBUFP(buf,8), mes, len_mes);
  6365. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6366. // send back message to the speaker
  6367. WBUFW(buf,0) = 0x8e;
  6368. WBUFW(buf, 2) = len_mes + 4;
  6369. memcpy(WBUFP(buf,4), mes, len_mes);
  6370. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6371. return 0;
  6372. }
  6373. /*==========================
  6374. * Minimap fix [Kevin]
  6375. * Remove dot from minimap
  6376. *--------------------------*/
  6377. int clif_party_xy_remove(struct map_session_data *sd)
  6378. {
  6379. unsigned char buf[16];
  6380. nullpo_retr(0, sd);
  6381. WBUFW(buf,0)=0x107;
  6382. WBUFL(buf,2)=sd->status.account_id;
  6383. WBUFW(buf,6)=-1;
  6384. WBUFW(buf,8)=-1;
  6385. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6386. return 0;
  6387. }
  6388. //Displays gospel-buff information (thanks to Rayce):
  6389. //Type determines message based on this table:
  6390. /*
  6391. 0x15 End all negative status
  6392. 0x16 Immunity to all status
  6393. 0x17 MaxHP +100%
  6394. 0x18 MaxSP +100%
  6395. 0x19 All stats +20
  6396. 0x1c Enchant weapon with Holy element
  6397. 0x1d Enchant armor with Holy element
  6398. 0x1e DEF +25%
  6399. 0x1f ATK +100%
  6400. 0x20 HIT/Flee +50
  6401. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  6402. */
  6403. void clif_gospel_info(struct map_session_data *sd, int type)
  6404. {
  6405. int fd=sd->fd;
  6406. WFIFOHEAD(fd,packet_len(0x215));
  6407. WFIFOW(fd,0)=0x215;
  6408. WFIFOL(fd,2)=type;
  6409. WFIFOSET(fd, packet_len(0x215));
  6410. }
  6411. /*==========================================
  6412. * Info about Star Glaldiator save map [Komurka]
  6413. * type: 1: Information, 0: Map registered
  6414. *------------------------------------------*/
  6415. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  6416. {
  6417. int fd=sd->fd;
  6418. WFIFOHEAD(fd,packet_len(0x20e));
  6419. WFIFOW(fd,0) = 0x20e;
  6420. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), (char*)WFIFOP(fd,2));
  6421. WFIFOL(fd,26) = sd->bl.id;
  6422. WFIFOB(fd,30) = feel_level;
  6423. WFIFOB(fd,31) = type?1:0;
  6424. WFIFOSET(fd,packet_len(0x20e));
  6425. }
  6426. /*==========================================
  6427. * Info about Star Glaldiator hate mob [Komurka]
  6428. * type: 1: Register mob, 0: Information.
  6429. *------------------------------------------*/
  6430. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  6431. {
  6432. int fd=sd->fd;
  6433. WFIFOHEAD(fd,packet_len(0x20e));
  6434. WFIFOW(fd,0)=0x20e;
  6435. if (pcdb_checkid(class_))
  6436. strncpy((char*)WFIFOP(fd,2),job_name(class_), NAME_LENGTH);
  6437. else if (mobdb_checkid(class_))
  6438. strncpy((char*)WFIFOP(fd,2),mob_db(class_)->jname, NAME_LENGTH);
  6439. else //Really shouldn't happen...
  6440. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  6441. WFIFOL(fd,26)=sd->bl.id;
  6442. WFIFOB(fd,30)=hate_level;
  6443. WFIFOB(fd,31)=type?10:11; //Register/Info
  6444. WFIFOSET(fd, packet_len(0x20e));
  6445. }
  6446. /*==========================================
  6447. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6448. *------------------------------------------*/
  6449. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  6450. {
  6451. int fd=sd->fd;
  6452. WFIFOHEAD(fd,packet_len(0x20e));
  6453. WFIFOW(fd,0)=0x20e;
  6454. strncpy((char*)WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6455. WFIFOL(fd,26)=mob_id;
  6456. WFIFOB(fd,30)=progress; //Message to display
  6457. WFIFOB(fd,31)=20;
  6458. WFIFOSET(fd, packet_len(0x20e));
  6459. }
  6460. /*==========================================
  6461. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  6462. *------------------------------------------*/
  6463. void clif_feel_hate_reset(struct map_session_data *sd)
  6464. {
  6465. int fd=sd->fd;
  6466. WFIFOHEAD(fd,packet_len(0x20e));
  6467. WFIFOW(fd,0)=0x20e;
  6468. memset(WFIFOP(fd,2), 0, NAME_LENGTH); //Blank name as all was reset.
  6469. WFIFOL(fd,26)=sd->bl.id;
  6470. WFIFOB(fd,30)=0; //Feel/hate level: irrelevant
  6471. WFIFOB(fd,31)=30;
  6472. WFIFOSET(fd, packet_len(0x20e));
  6473. }
  6474. /*==========================================
  6475. * Equip window (un)tick ack
  6476. * R 02d9 <zero>.L <flag>.L
  6477. *------------------------------------------*/
  6478. void clif_equiptickack(struct map_session_data* sd, int flag)
  6479. {
  6480. int fd;
  6481. nullpo_retv(sd);
  6482. fd = sd->fd;
  6483. WFIFOHEAD(fd, packet_len(0x2d9));
  6484. WFIFOW(fd, 0) = 0x2d9;
  6485. WFIFOL(fd, 2) = 0;
  6486. WFIFOL(fd, 6) = flag;
  6487. WFIFOSET(fd, packet_len(0x2d9));
  6488. }
  6489. /*==========================================
  6490. * The player's 'view equip' state, sent during login
  6491. * R 02da <flag>.B
  6492. *------------------------------------------*/
  6493. void clif_equipcheckbox(struct map_session_data* sd)
  6494. {
  6495. int fd;
  6496. nullpo_retv(sd);
  6497. fd = sd->fd;
  6498. WFIFOHEAD(fd, packet_len(0x2da));
  6499. WFIFOW(fd, 0) = 0x2da;
  6500. WFIFOW(fd, 2) = (sd->status.show_equip ? 1 : 0);
  6501. WFIFOSET(fd, packet_len(0x2da));
  6502. }
  6503. /*==========================================
  6504. * Sends info about a player's equipped items
  6505. * R 002d7 <length>.W <name>.24B <class>.w <hairstyle>.w <up-viewid>.w <mid-viewid>.w <low-viewid>.w <haircolor>.w <cloth-dye>.w <gender>.1B {equip item}.26B*
  6506. *------------------------------------------*/
  6507. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  6508. {
  6509. int i, n, fd;
  6510. nullpo_retv(sd);
  6511. nullpo_retv(tsd);
  6512. fd = sd->fd;
  6513. WFIFOHEAD(fd, MAX_INVENTORY * 26 + 43);
  6514. WFIFOW(fd, 0) = 0x2d7;
  6515. safestrncpy((char*)WFIFOP(fd, 4), tsd->status.name, NAME_LENGTH);
  6516. WFIFOW(fd,28) = tsd->status.class_;
  6517. WFIFOW(fd,30) = tsd->vd.hair_style;
  6518. WFIFOW(fd,32) = tsd->vd.head_top;
  6519. WFIFOW(fd,34) = tsd->vd.head_mid;
  6520. WFIFOW(fd,36) = tsd->vd.head_bottom;
  6521. WFIFOW(fd,38) = tsd->vd.hair_color;
  6522. WFIFOW(fd,40) = tsd->vd.cloth_color;
  6523. WFIFOB(fd,42) = tsd->vd.sex;
  6524. for(i=0,n=0; i < MAX_INVENTORY; i++)
  6525. {
  6526. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  6527. continue;
  6528. if (itemdb_isstackable2(tsd->inventory_data[i])) // Is not equippable
  6529. continue;
  6530. // Inventory position
  6531. WFIFOW(fd, n*26+43) = i + 2;
  6532. // Add refine, identify flag, element, etc.
  6533. clif_item_sub(WFIFOP(fd,0), n*26+45, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  6534. // Add cards
  6535. clif_addcards(WFIFOP(fd, n*26+55), &tsd->status.inventory[i]);
  6536. // Expiration date stuff, if all of those are set to 0 then the client doesn't show anything related (6 bytes)
  6537. memset(WFIFOP(fd, n*26+63), 0, 6);
  6538. n++;
  6539. }
  6540. WFIFOW(fd, 2) = 43 + n*26; // Set length
  6541. WFIFOSET(fd, WFIFOW(fd, 2));
  6542. }
  6543. /*==========================================
  6544. * View player equip request denied
  6545. * R 0291 <message>.W
  6546. * TODO: this looks like a general-purpose packet to print msgstringtable entries.
  6547. *------------------------------------------*/
  6548. void clif_viewequip_fail(struct map_session_data* sd)
  6549. {
  6550. int fd;
  6551. nullpo_retv(sd);
  6552. fd = sd->fd;
  6553. WFIFOHEAD(fd, packet_len(0x291));
  6554. WFIFOW(fd, 0) = 0x291;
  6555. WFIFOW(fd, 2) = 0x54d; // This controls which message is displayed. 0x54d is the correct one. Maybe it's used for something else too?
  6556. WFIFOSET(fd, packet_len(0x291));
  6557. }
  6558. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  6559. /// Returns true if the packet was parsed successfully.
  6560. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  6561. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  6562. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  6563. {
  6564. char *text, *name, *message;
  6565. unsigned int packetlen, textlen, namelen, messagelen;
  6566. int fd = sd->fd;
  6567. *name_ = NULL;
  6568. *namelen_ = 0;
  6569. *message_ = NULL;
  6570. *messagelen_ = 0;
  6571. packetlen = RFIFOW(fd,2);
  6572. // basic structure checks
  6573. if( packetlen > RFIFOREST(fd) )
  6574. { // there has to be enough data to read
  6575. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6576. return false;
  6577. }
  6578. if( packetlen < 4 + 1 )
  6579. { // 4-byte header and at least an empty string is expected
  6580. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  6581. return false;
  6582. }
  6583. text = (char*)RFIFOP(fd,4);
  6584. textlen = packetlen - 4;
  6585. // process <name> part of the packet
  6586. if( format == 0 )
  6587. {// name and message are separated by ' : '
  6588. // validate name
  6589. name = text;
  6590. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  6591. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  6592. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  6593. {
  6594. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  6595. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  6596. clif_setwaitclose(fd); // Just kick them out to correct it.
  6597. return false;
  6598. }
  6599. message = name + namelen + 3;
  6600. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  6601. }
  6602. else
  6603. {// name has fixed width
  6604. if( textlen < NAME_LENGTH + 1 )
  6605. {
  6606. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6607. return false;
  6608. }
  6609. // validate name
  6610. name = text;
  6611. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  6612. if( name[namelen] != '\0' )
  6613. { // only restriction is that the name must be zero-terminated
  6614. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  6615. return false;
  6616. }
  6617. message = name + NAME_LENGTH;
  6618. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  6619. }
  6620. if( messagelen != strnlen(message, messagelen)+1 )
  6621. { // the declared length must match real length
  6622. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  6623. return false;
  6624. }
  6625. // verify <message> part of the packet
  6626. if( message[messagelen-1] != '\0' )
  6627. { // message must be zero-terminated
  6628. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  6629. return false;
  6630. }
  6631. if( messagelen > CHAT_SIZE_MAX )
  6632. { // messages mustn't be too long
  6633. // Normally you can only enter CHATBOX_SIZE-1 chars into the chat box, but Frost Joke / Dazzler's text can be longer.
  6634. // Neither the official client nor server place any restriction on the length of the text in the packet,
  6635. // but we'll only allow reasonably long strings here. This also makes sure all strings fit into the `chatlog` table.
  6636. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX, message);
  6637. return false;
  6638. }
  6639. *name_ = name;
  6640. *namelen_ = namelen;
  6641. *message_ = message;
  6642. *messagelen_ = messagelen;
  6643. return true;
  6644. }
  6645. // ---------------------
  6646. // clif_guess_PacketVer
  6647. // ---------------------
  6648. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  6649. // error codes:
  6650. // 0 - Success
  6651. // 1 - Unknown packet_ver
  6652. // 2 - Invalid account_id
  6653. // 3 - Invalid char_id
  6654. // 4 - Invalid login_id1 (reserved)
  6655. // 5 - Invalid client_tick (reserved)
  6656. // 6 - Invalid sex
  6657. // Only the first 'invalid' error that appears is used.
  6658. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  6659. {
  6660. static int err = 1;
  6661. static int packet_ver = -1;
  6662. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  6663. if (get_previous)
  6664. {//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]
  6665. if( error )
  6666. *error = err;
  6667. return packet_ver;
  6668. }
  6669. //By default, start searching on the default one.
  6670. err = 1;
  6671. packet_ver = clif_config.packet_db_ver;
  6672. cmd = RFIFOW(fd,0);
  6673. packet_len = RFIFOREST(fd);
  6674. #define SET_ERROR(n) \
  6675. if( err == 1 )\
  6676. err = n;\
  6677. //define SET_ERROR
  6678. #define CHECK_PACKET_VER() \
  6679. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  6680. ;/* not wanttoconnection or wrong length */\
  6681. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > max_account_id )\
  6682. { SET_ERROR(2); }/* invalid account_id */\
  6683. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 || value > max_char_id )\
  6684. { SET_ERROR(3); }/* invalid char_id */\
  6685. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  6686. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  6687. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  6688. { SET_ERROR(6); }/* invalid sex */\
  6689. else\
  6690. {\
  6691. err = 0;\
  6692. if( error )\
  6693. *error = 0;\
  6694. return packet_ver;\
  6695. }\
  6696. //define CHECK_PACKET_VER
  6697. CHECK_PACKET_VER();//Default packet version found.
  6698. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  6699. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  6700. CHECK_PACKET_VER();
  6701. }
  6702. if( error )
  6703. *error = err;
  6704. packet_ver = -1;
  6705. return -1;
  6706. #undef SET_ERROR
  6707. #undef CHECK_PACKET_VER
  6708. }
  6709. // ------------
  6710. // clif_parse_*
  6711. // ------------
  6712. // パケット読み取って色々操作
  6713. /*==========================================
  6714. *
  6715. *------------------------------------------*/
  6716. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  6717. {
  6718. struct block_list* bl;
  6719. struct auth_node* node;
  6720. int cmd, account_id, char_id, login_id1, sex;
  6721. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  6722. 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])
  6723. if (sd) {
  6724. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  6725. return;
  6726. }
  6727. // Only valid packet version get here
  6728. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  6729. cmd = RFIFOW(fd,0);
  6730. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  6731. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  6732. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  6733. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  6734. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  6735. if( packet_ver < 5 || // reject really old client versions
  6736. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  6737. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  6738. {// packet version rejected
  6739. 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));
  6740. WFIFOHEAD(fd,packet_len(0x6a));
  6741. WFIFOW(fd,0) = 0x6a;
  6742. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  6743. WFIFOSET(fd,packet_len(0x6a));
  6744. clif_setwaitclose(fd);
  6745. return;
  6746. }
  6747. //Check for double login.
  6748. bl = map_id2bl(account_id);
  6749. if(bl && bl->type != BL_PC) {
  6750. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  6751. WFIFOHEAD(fd,packet_len(0x6a));
  6752. WFIFOW(fd,0) = 0x6a;
  6753. WFIFOB(fd,2) = 3; // Rejected by server
  6754. WFIFOSET(fd,packet_len(0x6a));
  6755. clif_setwaitclose(fd);
  6756. return;
  6757. }
  6758. if (bl ||
  6759. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  6760. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN))) {
  6761. sd = BL_CAST(BL_PC, bl);
  6762. if (!sd)
  6763. ; //We have another char with the same account logging in/out.
  6764. else //Already connected player.
  6765. if (sd->fd)
  6766. clif_authfail_fd(sd->fd, 2); //someone else logged in
  6767. else
  6768. if(sd->state.autotrade)
  6769. map_quit(sd);// kick autotrading character
  6770. //Else do not kick character, it could be on its 10 sec penalty for Alt+F4
  6771. clif_authfail_fd(fd, 8); //Still recognizes last connection
  6772. return;
  6773. }
  6774. CREATE(sd, TBL_PC, 1);
  6775. sd->fd = fd;
  6776. sd->packet_ver = packet_ver;
  6777. session[fd]->session_data = sd;
  6778. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  6779. #if PACKETVER < 8
  6780. WFIFOHEAD(fd,4);
  6781. WFIFOL(fd,0) = sd->bl.id;
  6782. WFIFOSET(fd,4);
  6783. #else
  6784. WFIFOHEAD(fd,packet_len(0x283));
  6785. WFIFOW(fd,0) = 0x283;
  6786. WFIFOL(fd,2) = sd->bl.id;
  6787. WFIFOSET(fd,packet_len(0x283));
  6788. #endif
  6789. chrif_authreq(sd);
  6790. return;
  6791. }
  6792. /*==========================================
  6793. * 007d クライアント側マップ読み込み完了
  6794. * map侵入時に必要なデータを全て送りつける
  6795. *------------------------------------------*/
  6796. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  6797. {
  6798. if(sd->bl.prev != NULL)
  6799. return;
  6800. if (!sd->state.active)
  6801. { //Character loading is not complete yet!
  6802. //Let pc_reg_received reinvoke this when ready.
  6803. sd->state.connect_new = 0;
  6804. return;
  6805. }
  6806. if (sd->state.rewarp)
  6807. { //Rewarp player.
  6808. sd->state.rewarp = 0;
  6809. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  6810. return;
  6811. }
  6812. // look
  6813. #if PACKETVER < 4
  6814. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  6815. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  6816. #else
  6817. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  6818. #endif
  6819. if(sd->vd.cloth_color)
  6820. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6821. // item
  6822. pc_checkitem(sd);
  6823. clif_inventorylist(sd);
  6824. // cart
  6825. if(pc_iscarton(sd)) {
  6826. clif_cartlist(sd);
  6827. clif_updatestatus(sd,SP_CARTINFO);
  6828. }
  6829. // weight
  6830. clif_updatestatus(sd,SP_WEIGHT);
  6831. clif_updatestatus(sd,SP_MAXWEIGHT);
  6832. // guild
  6833. // (needs to go before clif_spawn() to show guild emblems correctly)
  6834. if(sd->status.guild_id)
  6835. guild_send_memberinfoshort(sd,1);
  6836. if(battle_config.pc_invincible_time > 0) {
  6837. if(map_flag_gvg(sd->bl.m))
  6838. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  6839. else
  6840. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  6841. }
  6842. if (map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs) //Skotlex
  6843. map_spawnmobs(sd->bl.m);
  6844. map_addblock(&sd->bl);
  6845. clif_spawn(&sd->bl);
  6846. // Party
  6847. // (needs to go after clif_spawn() to show hp bars correctly)
  6848. if(sd->status.party_id) {
  6849. party_send_movemap(sd);
  6850. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  6851. }
  6852. if(map[sd->bl.m].flag.pvp) {
  6853. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  6854. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  6855. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  6856. sd->pvp_rank = 0;
  6857. sd->pvp_lastusers = 0;
  6858. sd->pvp_point = 5;
  6859. sd->pvp_won = 0;
  6860. sd->pvp_lost = 0;
  6861. }
  6862. clif_set0199(sd,1);
  6863. } else
  6864. // set flag, if it's a duel [LuzZza]
  6865. if(sd->duel_group)
  6866. clif_set0199(sd,1);
  6867. if (map[sd->bl.m].flag.gvg_dungeon)
  6868. {
  6869. clif_set0199(sd,1); //TODO: Figure out the real packet to send here.
  6870. if (!sd->pvp_point)
  6871. {
  6872. sd->pvp_point = 5; //Need to die twice to be warped out.
  6873. sd->pvp_won = 0;
  6874. sd->pvp_lost = 0;
  6875. }
  6876. }
  6877. if(map_flag_gvg(sd->bl.m))
  6878. clif_set0199(sd,3);
  6879. // info about nearby objects
  6880. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  6881. 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);
  6882. //TODO: merge it with the code below
  6883. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) && sd->pd)
  6884. { //Return the pet to egg. [Skotlex]
  6885. clif_displaymessage(sd->fd, "Pets are not allowed in Guild Wars.");
  6886. pet_menu(sd, 3); //Option 3 is return to egg.
  6887. }
  6888. // pet
  6889. if(sd->pd) {
  6890. map_addblock(&sd->pd->bl);
  6891. clif_spawn(&sd->pd->bl);
  6892. clif_send_petdata(sd,sd->pd,0,0);
  6893. clif_send_petstatus(sd);
  6894. // skill_unit_move(&sd->pd->bl,gettick(),1);
  6895. }
  6896. //homunculus [blackhole89]
  6897. if(merc_is_hom_active(sd->hd)) {
  6898. map_addblock(&sd->hd->bl);
  6899. clif_spawn(&sd->hd->bl);
  6900. clif_send_homdata(sd,0,0);
  6901. clif_hominfo(sd,sd->hd,1);
  6902. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  6903. clif_homskillinfoblock(sd);
  6904. if (battle_config.hom_setting&0x8)
  6905. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  6906. if (!(battle_config.hom_setting&0x2))
  6907. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  6908. }
  6909. if(sd->state.connect_new) {
  6910. int lv;
  6911. sd->state.connect_new = 0;
  6912. clif_skillinfoblock(sd);
  6913. clif_hotkeys_send(sd);
  6914. clif_updatestatus(sd,SP_NEXTBASEEXP);
  6915. clif_updatestatus(sd,SP_NEXTJOBEXP);
  6916. clif_updatestatus(sd,SP_SKILLPOINT);
  6917. clif_initialstatus(sd);
  6918. if (sd->sc.option&OPTION_FALCON)
  6919. clif_status_load(&sd->bl, SI_FALCON, 1);
  6920. if (sd->sc.option&OPTION_RIDING)
  6921. clif_status_load(&sd->bl, SI_RIDING, 1);
  6922. if(sd->status.manner < 0)
  6923. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  6924. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  6925. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  6926. if(sd->bl.m == sd->feel_map[0].m
  6927. || sd->bl.m == sd->feel_map[1].m
  6928. || sd->bl.m == sd->feel_map[2].m)
  6929. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  6930. }
  6931. if(sd->pd && sd->pd->pet.intimate > 900)
  6932. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  6933. if(merc_is_hom_active(sd->hd))
  6934. merc_hom_init_timers(sd->hd);
  6935. if (night_flag && map[sd->bl.m].flag.nightenabled)
  6936. {
  6937. sd->state.night = 1;
  6938. clif_status_load(&sd->bl, SI_NIGHT, 1);
  6939. }
  6940. #if PACKETVER >= 9
  6941. clif_equipcheckbox(sd);
  6942. #endif
  6943. // Notify everyone that this char logged in [Skotlex].
  6944. clif_foreachclient(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  6945. //Login Event
  6946. npc_script_event(sd, NPCE_LOGIN);
  6947. } else {
  6948. //For some reason the client "loses" these on map-change.
  6949. clif_updatestatus(sd,SP_STR);
  6950. clif_updatestatus(sd,SP_AGI);
  6951. clif_updatestatus(sd,SP_VIT);
  6952. clif_updatestatus(sd,SP_INT);
  6953. clif_updatestatus(sd,SP_DEX);
  6954. clif_updatestatus(sd,SP_LUK);
  6955. sd->state.using_fake_npc = 0;
  6956. //New 'night' effect by dynamix [Skotlex]
  6957. if (night_flag && map[sd->bl.m].flag.nightenabled)
  6958. { //Display night.
  6959. if (!sd->state.night) {
  6960. sd->state.night = 1;
  6961. clif_status_load(&sd->bl, SI_NIGHT, 1);
  6962. }
  6963. } else if (sd->state.night) { //Clear night display.
  6964. sd->state.night = 0;
  6965. clif_status_load(&sd->bl, SI_NIGHT, 0);
  6966. }
  6967. if(sd->npc_id)
  6968. npc_event_dequeue(sd);
  6969. #ifndef TXT_ONLY
  6970. mail_clear(sd);
  6971. #endif
  6972. }
  6973. if(map[sd->bl.m].flag.loadevent) // Lance
  6974. npc_script_event(sd, NPCE_LOADMAP);
  6975. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  6976. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  6977. if (sd->sc.opt2) //Client loses these on warp.
  6978. clif_changeoption(&sd->bl);
  6979. clif_weather_check(sd);
  6980. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  6981. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  6982. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  6983. else
  6984. sd->areanpc_id = 0;
  6985. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  6986. if(pc_isdead(sd))
  6987. clif_clearunit_area(&sd->bl, 1);
  6988. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  6989. // else
  6990. // clif_changed_dir(&sd->bl, SELF);
  6991. // Trigger skill effects if you appear standing on them
  6992. if(!battle_config.pc_invincible_time)
  6993. skill_unit_move(&sd->bl,gettick(),1);
  6994. }
  6995. /*==========================================
  6996. *
  6997. *------------------------------------------*/
  6998. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  6999. {
  7000. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7001. WFIFOHEAD(fd, packet_len(0x7f));
  7002. WFIFOW(fd,0)=0x7f;
  7003. WFIFOL(fd,2)=gettick();
  7004. WFIFOSET(fd,packet_len(0x7f));
  7005. // removed until the socket problems are fixed. [FlavioJS]
  7006. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  7007. return;
  7008. }
  7009. void clif_hotkeys_send(struct map_session_data *sd) {
  7010. #ifdef HOTKEY_SAVING
  7011. const int fd = sd->fd;
  7012. int i;
  7013. if (!fd) return;
  7014. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  7015. WFIFOW(fd, 0) = 0x02b9;
  7016. for(i = 0; i < MAX_HOTKEYS; i++) {
  7017. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  7018. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  7019. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  7020. }
  7021. WFIFOSET(fd, packet_len(0x02b9));
  7022. #endif
  7023. }
  7024. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  7025. #ifdef HOTKEY_SAVING
  7026. unsigned short idx;
  7027. int cmd;
  7028. cmd = RFIFOW(fd, 0);
  7029. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  7030. if (idx >= MAX_HOTKEYS) return;
  7031. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  7032. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  7033. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  7034. return;
  7035. #endif
  7036. }
  7037. /*==========================================
  7038. *
  7039. *------------------------------------------*/
  7040. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  7041. {
  7042. short x, y;
  7043. int cmd;
  7044. if (pc_isdead(sd)) {
  7045. clif_clearunit_area(&sd->bl, 1);
  7046. return;
  7047. }
  7048. if (sd->sc.opt1 && sd->sc.opt1 == OPT1_STONEWAIT)
  7049. ; //You CAN walk on this OPT1 value.
  7050. else if (pc_cant_act(sd))
  7051. return;
  7052. if(sd->sc.data[SC_RUN])
  7053. return;
  7054. pc_delinvincibletimer(sd);
  7055. cmd = RFIFOW(fd,0);
  7056. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7057. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7058. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7059. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7060. //Set last idle time... [Skotlex]
  7061. sd->idletime = last_tick;
  7062. unit_walktoxy(&sd->bl, x, y, 4);
  7063. }
  7064. /*==========================================
  7065. *
  7066. *------------------------------------------*/
  7067. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  7068. {
  7069. WFIFOHEAD(fd,packet_len(0x18b));
  7070. WFIFOW(fd,0) = 0x18b;
  7071. /* Rovert's prevent logout option fixed [Valaris] */
  7072. if (!sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] &&
  7073. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7074. ) {
  7075. clif_setwaitclose(fd);
  7076. WFIFOW(fd,2)=0;
  7077. } else {
  7078. WFIFOW(fd,2)=1;
  7079. }
  7080. WFIFOSET(fd,packet_len(0x18b));
  7081. }
  7082. /*==========================================
  7083. *
  7084. *------------------------------------------*/
  7085. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  7086. {
  7087. int account_id;
  7088. struct block_list* bl;
  7089. struct status_change *sc;
  7090. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7091. if(account_id<0 && -account_id == sd->bl.id) // for disguises [Valaris]
  7092. account_id= sd->bl.id;
  7093. bl = map_id2bl(account_id);
  7094. //Is this possible? Lagged clients could request names of already gone mobs/players. [Skotlex]
  7095. if (!bl) return;
  7096. sc = status_get_sc(bl);
  7097. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  7098. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  7099. pc_isGM(sd) < battle_config.hack_info_GM_level
  7100. ) {
  7101. //GM characters (with client side GM enabled are able to see invisible stuff) [Lance]
  7102. //Asked name of invisible player, this shouldn't be possible!
  7103. //Possible bot? Thanks to veider and qspirit
  7104. //FIXME: Still isn't perfected as clients keep asking for this on legitimate situations.
  7105. char gm_msg[256];
  7106. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requested the name of an invisible target.\n", sd->status.name, sd->status.account_id);
  7107. ShowWarning(gm_msg);
  7108. // information is sended to all online GM
  7109. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7110. return;
  7111. }
  7112. clif_charnameack(fd, bl);
  7113. }
  7114. /*==========================================
  7115. * Validates and processes global messages
  7116. * S 008c/00f3 <packet len>.w <text>.?B (<name> : <message>) 00
  7117. *------------------------------------------*/
  7118. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  7119. {
  7120. const char* text = (char*)RFIFOP(fd,4);
  7121. int textlen = RFIFOW(fd,2) - 4;
  7122. char *name, *message;
  7123. int namelen, messagelen;
  7124. // validate packet and retrieve name and message
  7125. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  7126. return;
  7127. if( is_atcommand(fd, sd, message) || is_charcommand(fd, sd, message) )
  7128. return;
  7129. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  7130. return;
  7131. if( battle_config.min_chat_delay )
  7132. { //[Skotlex]
  7133. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7134. return;
  7135. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7136. }
  7137. // send message to others (using the send buffer for temp. storage)
  7138. WFIFOHEAD(fd, 8 + textlen);
  7139. WFIFOW(fd,0) = 0x8d;
  7140. WFIFOW(fd,2) = 8 + textlen;
  7141. WFIFOL(fd,4) = sd->bl.id;
  7142. safestrncpy((char*)WFIFOP(fd,8), text, textlen);
  7143. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7144. // send back message to the speaker
  7145. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7146. WFIFOW(fd,0) = 0x8e;
  7147. WFIFOSET(fd, WFIFOW(fd,2));
  7148. #ifdef PCRE_SUPPORT
  7149. // trigger listening mobs/npcs
  7150. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  7151. map_foreachinrange(mob_chat_sub, &sd->bl, AREA_SIZE, BL_MOB, text, textlen, &sd->bl);
  7152. #endif
  7153. // check for special supernovice phrase
  7154. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE )
  7155. {
  7156. int next = pc_nextbaseexp(sd);
  7157. if( next > 0 && (sd->status.base_exp * 1000 / next)% 100 == 0 ) { // 0%, 10%, 20%, ...
  7158. switch (sd->state.snovice_call_flag) {
  7159. case 0:
  7160. if( strstr(message, msg_txt(504)) ) // "Guardian Angel, can you hear my voice? ^^;"
  7161. sd->state.snovice_call_flag++;
  7162. break;
  7163. case 1: {
  7164. char buf[256];
  7165. sprintf(buf, msg_txt(505), sd->status.name);
  7166. if( strstr(message, buf) ) // "My name is %s, and I'm a Super Novice~"
  7167. sd->state.snovice_call_flag++;
  7168. }
  7169. break;
  7170. case 2:
  7171. if( strstr(message, msg_txt(506)) ) // "Please help me~ T.T"
  7172. sd->state.snovice_call_flag++;
  7173. break;
  7174. case 3:
  7175. if( skillnotok(MO_EXPLOSIONSPIRITS,sd) )
  7176. break; //Do not override the noskill mapflag. [Skotlex]
  7177. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7178. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  7179. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7180. sd->state.snovice_call_flag = 0;
  7181. break;
  7182. }
  7183. }
  7184. }
  7185. // Chat logging type 'O' / Global Chat
  7186. if( log_config.chat&1 || (log_config.chat&2 && !(agit_flag && log_config.chat&64)) )
  7187. log_chat("O", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7188. return;
  7189. }
  7190. /*==========================================
  7191. * /mm /mapmove (as @rura GM command)
  7192. *------------------------------------------*/
  7193. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  7194. {
  7195. char output[MAP_NAME_LENGTH_EXT+15]; // Max length of a short: ' -6XXXX' -> 7 digits
  7196. char message[MAP_NAME_LENGTH_EXT+15+5]; // "/mm "+output
  7197. char* map_name;
  7198. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7199. return;
  7200. if(pc_isGM(sd) < get_atcommand_level(atcommand_mapmove))
  7201. return;
  7202. map_name = (char*)RFIFOP(fd,2);
  7203. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  7204. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7205. atcommand_mapmove(fd, sd, "@mapmove", output);
  7206. if( log_config.gm && get_atcommand_level(atcommand_mapmove) >= log_config.gm )
  7207. {
  7208. sprintf(message, "/mm %s", output);
  7209. log_atcommand(sd, message);
  7210. }
  7211. return;
  7212. }
  7213. /*==========================================
  7214. *
  7215. *------------------------------------------*/
  7216. void clif_changed_dir(struct block_list *bl, int type)
  7217. {
  7218. unsigned char buf[64];
  7219. WBUFW(buf,0) = 0x9c;
  7220. WBUFL(buf,2) = bl->id;
  7221. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7222. WBUFB(buf,8) = unit_getdir(bl);
  7223. clif_send(buf, packet_len(0x9c), bl, type);
  7224. if (disguised(bl)) {
  7225. WBUFL(buf,2) = -bl->id;
  7226. WBUFW(buf,6) = 0;
  7227. clif_send(buf, packet_len(0x9c), bl, SELF);
  7228. }
  7229. return;
  7230. }
  7231. /*==========================================
  7232. *
  7233. *------------------------------------------*/
  7234. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  7235. {
  7236. unsigned char headdir, dir;
  7237. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7238. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7239. pc_setdir(sd, dir, headdir);
  7240. clif_changed_dir(&sd->bl, AREA_WOS);
  7241. return;
  7242. }
  7243. /*==========================================
  7244. *
  7245. *------------------------------------------*/
  7246. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  7247. {
  7248. unsigned char buf[64];
  7249. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7250. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7251. clif_skill_fail(sd, 1, 0, 1);
  7252. return;
  7253. }
  7254. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7255. if (sd->emotionlasttime >= time(NULL)) {
  7256. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7257. clif_skill_fail(sd, 1, 0, 1);
  7258. return;
  7259. }
  7260. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7261. WBUFW(buf,0) = 0xc0;
  7262. WBUFL(buf,2) = sd->bl.id;
  7263. WBUFB(buf,6) = RFIFOB(fd,2);
  7264. clif_send(buf, packet_len(0xc0), &sd->bl, AREA);
  7265. } else
  7266. clif_skill_fail(sd, 1, 0, 1);
  7267. }
  7268. /*==========================================
  7269. *
  7270. *------------------------------------------*/
  7271. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  7272. {
  7273. WFIFOHEAD(fd,packet_len(0xc2));
  7274. WFIFOW(fd,0) = 0xc2;
  7275. WFIFOL(fd,2) = map_getusers();
  7276. WFIFOSET(fd,packet_len(0xc2));
  7277. }
  7278. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7279. {
  7280. if (pc_isdead(sd)) {
  7281. clif_clearunit_area(&sd->bl, 1);
  7282. return;
  7283. }
  7284. if (sd->sc.count &&
  7285. (sd->sc.data[SC_TRICKDEAD] ||
  7286. sd->sc.data[SC_AUTOCOUNTER] ||
  7287. sd->sc.data[SC_BLADESTOP]))
  7288. return;
  7289. pc_stop_walking(sd, 1);
  7290. pc_stop_attack(sd);
  7291. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7292. target_id = sd->bl.id;
  7293. switch(action_type)
  7294. {
  7295. case 0x00: // once attack
  7296. case 0x07: // continuous attack
  7297. if (pc_cant_act(sd) || sd->sc.option&OPTION_HIDE)
  7298. return;
  7299. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  7300. return;
  7301. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7302. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7303. clif_skill_fail(sd, 1, 4, 0);
  7304. return;
  7305. }
  7306. }
  7307. pc_delinvincibletimer(sd);
  7308. sd->idletime = last_tick;
  7309. unit_attack(&sd->bl, target_id, action_type != 0);
  7310. break;
  7311. case 0x02: // sitdown
  7312. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7313. clif_skill_fail(sd, 1, 0, 2);
  7314. break;
  7315. }
  7316. if(pc_issit(sd)) {
  7317. //Bugged client? Just refresh them.
  7318. clif_sitting(&sd->bl);
  7319. return;
  7320. }
  7321. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7322. break;
  7323. if (sd->sc.count && (
  7324. sd->sc.data[SC_DANCING] ||
  7325. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  7326. )) //No sitting during these states either.
  7327. break;
  7328. pc_setsit(sd);
  7329. skill_sit(sd,1);
  7330. clif_sitting(&sd->bl);
  7331. break;
  7332. case 0x03: // standup
  7333. if (!pc_issit(sd)) {
  7334. //Bugged client? Just refresh them.
  7335. clif_standing(&sd->bl);
  7336. return;
  7337. }
  7338. pc_setstand(sd);
  7339. skill_sit(sd,0);
  7340. clif_standing(&sd->bl);
  7341. break;
  7342. }
  7343. }
  7344. /*==========================================
  7345. *
  7346. *------------------------------------------*/
  7347. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  7348. {
  7349. clif_parse_ActionRequest_sub(sd,
  7350. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7351. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7352. gettick()
  7353. );
  7354. }
  7355. /*==========================================
  7356. *
  7357. *------------------------------------------*/
  7358. void clif_parse_Restart(int fd, struct map_session_data *sd)
  7359. {
  7360. switch(RFIFOB(fd,2)) {
  7361. case 0x00:
  7362. pc_respawn(sd,2);
  7363. break;
  7364. case 0x01:
  7365. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7366. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7367. { //Send to char-server for character selection.
  7368. chrif_charselectreq(sd, session[fd]->client_addr);
  7369. } else {
  7370. WFIFOHEAD(fd,packet_len(0x18b));
  7371. WFIFOW(fd,0)=0x18b;
  7372. WFIFOW(fd,2)=1;
  7373. WFIFOSET(fd,packet_len(0x018b));
  7374. }
  7375. break;
  7376. }
  7377. }
  7378. /*==========================================
  7379. * Validates and processes whispered messages
  7380. * S 0096 <packet len>.w <nick>.23B 00 <message>.?B
  7381. *------------------------------------------*/
  7382. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  7383. {
  7384. struct map_session_data* dstsd;
  7385. int i;
  7386. char *target, *message;
  7387. int namelen, messagelen;
  7388. // validate packet and retrieve name and message
  7389. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  7390. return;
  7391. if (is_atcommand(fd, sd, message) || is_charcommand(fd, sd, message) )
  7392. return;
  7393. if (sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT))
  7394. return;
  7395. if (battle_config.min_chat_delay)
  7396. { //[Skotlex]
  7397. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  7398. return;
  7399. }
  7400. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7401. }
  7402. // Chat logging type 'W' / Whisper
  7403. if( log_config.chat&1 || (log_config.chat&4 && !(agit_flag && log_config.chat&64)) )
  7404. log_chat("W", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
  7405. //-------------------------------------------------------//
  7406. // Lordalfa - Paperboy - To whisper NPC commands //
  7407. //-------------------------------------------------------//
  7408. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  7409. {
  7410. char* str = target+4; //Skip the NPC: string part.
  7411. struct npc_data* npc;
  7412. if ((npc = npc_name2id(str)))
  7413. {
  7414. char split_data[10][50];
  7415. char *split;
  7416. char output[256];
  7417. str = message;
  7418. for( i = 0; i < 10; ++i )
  7419. {// Splits the message using '#' as separators
  7420. split = strchr(str,'#');
  7421. if( split == NULL )
  7422. { // use the remaining string
  7423. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7424. for( ++i; i < 10; ++i )
  7425. split_data[i][0] = '\0';
  7426. break;
  7427. }
  7428. *split = '\0';
  7429. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7430. str = split+1;
  7431. }
  7432. for( i = 0; i < 10; ++i )
  7433. {
  7434. sprintf(output, "@whispervar%d$", i);
  7435. set_var(sd,output,(char *) split_data[i]);
  7436. }
  7437. sprintf(output, "%s::OnWhisperGlobal", npc->name);
  7438. npc_event(sd,output,0); // Calls the NPC label
  7439. return;
  7440. }
  7441. }
  7442. // Main chat [LuzZza]
  7443. if(strcmpi(target, main_chat_nick) == 0)
  7444. {
  7445. if(!sd->state.mainchat)
  7446. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7447. else {
  7448. char output[256];
  7449. snprintf(output, ARRAYLENGTH(output), msg_txt(386), sd->status.name, message);
  7450. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7451. }
  7452. // Chat logging type 'M' / Main Chat
  7453. if( log_config.chat&1 || (log_config.chat&32 && !(agit_flag && log_config.chat&64)) )
  7454. log_chat("M", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7455. return;
  7456. }
  7457. // searching destination character
  7458. dstsd = map_nick2sd(target);
  7459. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
  7460. {
  7461. // player is not on this map-server
  7462. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7463. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7464. // and if we ask for 'Test', we must not contact 'test' player
  7465. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7466. intif_wis_message(sd, target, message, messagelen);
  7467. return;
  7468. }
  7469. // if player ignores everyone
  7470. if (dstsd->state.ignoreAll)
  7471. {
  7472. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7473. clif_wis_end(fd, 1); // 1: target character is not loged in
  7474. else
  7475. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7476. return;
  7477. }
  7478. // if player ignores the source character
  7479. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  7480. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  7481. { // source char present in ignore list
  7482. clif_wis_end(fd, 2); // 2: ignored by target
  7483. return;
  7484. }
  7485. // notify sender of success
  7486. clif_wis_end(fd, 0); // 0: success to send wisper
  7487. // if player has an auto-away message
  7488. if(dstsd->away_message[0] != '\0')
  7489. {
  7490. char output[256];
  7491. sprintf(output, "%s %s", message, msg_txt(543)); // "(Automessage has been sent)"
  7492. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  7493. if(dstsd->state.autotrade)
  7494. sprintf(output, msg_txt(544), dstsd->away_message); // "Away [AT] - "%s""
  7495. else
  7496. sprintf(output, msg_txt(545), dstsd->away_message); // "Away - "%s""
  7497. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  7498. return;
  7499. }
  7500. // Normal message
  7501. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  7502. return;
  7503. }
  7504. /*==========================================
  7505. * /b /nb
  7506. * S 0099 <packet len>.w <text>.?B 00
  7507. *------------------------------------------*/
  7508. void clif_parse_GMmessage(int fd, struct map_session_data* sd)
  7509. {
  7510. char* msg = (char*)RFIFOP(fd,4);
  7511. unsigned int len = RFIFOW(fd,2)-4;
  7512. int lv;
  7513. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  7514. return;
  7515. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_broadcast)) )
  7516. return;
  7517. // as the length varies depending on the command used, just block unreasonably long strings
  7518. mes_len_check(msg, len, CHAT_SIZE_MAX);
  7519. intif_GMmessage(msg, len, 0);
  7520. if(log_config.gm && lv >= log_config.gm) {
  7521. char logmsg[CHAT_SIZE_MAX+4];
  7522. sprintf(logmsg, "/b %s", msg);
  7523. log_atcommand(sd, logmsg);
  7524. }
  7525. }
  7526. /*==========================================
  7527. *
  7528. *------------------------------------------*/
  7529. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  7530. {
  7531. struct flooritem_data *fitem;
  7532. int map_object_id;
  7533. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7534. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  7535. do {
  7536. if (pc_isdead(sd)) {
  7537. clif_clearunit_area(&sd->bl, 1);
  7538. break;
  7539. }
  7540. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  7541. break;
  7542. if (pc_cant_act(sd))
  7543. break;
  7544. if(sd->sc.count && (
  7545. sd->sc.data[SC_HIDING] ||
  7546. sd->sc.data[SC_CLOAKING] ||
  7547. sd->sc.data[SC_TRICKDEAD] ||
  7548. sd->sc.data[SC_BLADESTOP] ||
  7549. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM))
  7550. )
  7551. break;
  7552. if (!pc_takeitem(sd, fitem))
  7553. break;
  7554. return;
  7555. } while (0);
  7556. // Client REQUIRES a fail packet or you can no longer pick items.
  7557. clif_additem(sd,0,0,6);
  7558. }
  7559. /*==========================================
  7560. *
  7561. *------------------------------------------*/
  7562. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  7563. {
  7564. int item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7565. int item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7566. do {
  7567. if (pc_isdead(sd))
  7568. break;
  7569. if (pc_cant_act(sd))
  7570. break;
  7571. if (sd->sc.count && (
  7572. sd->sc.data[SC_HIDING] ||
  7573. sd->sc.data[SC_AUTOCOUNTER] ||
  7574. sd->sc.data[SC_BLADESTOP] ||
  7575. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  7576. ))
  7577. break;
  7578. if (!pc_dropitem(sd, item_index, item_amount))
  7579. break;
  7580. return;
  7581. } while (0);
  7582. //Because the client does not like being ignored.
  7583. clif_delitem(sd, item_index,0);
  7584. }
  7585. /*==========================================
  7586. *
  7587. *------------------------------------------*/
  7588. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  7589. {
  7590. int n;
  7591. if (pc_isdead(sd)) {
  7592. clif_clearunit_area(&sd->bl, 1);
  7593. return;
  7594. }
  7595. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  7596. return;
  7597. //This flag enables you to use items while in an NPC. [Skotlex]
  7598. if (sd->npc_id) {
  7599. if (sd->npc_id != sd->npc_item_flag)
  7600. return;
  7601. } else
  7602. if (pc_istrading(sd))
  7603. return;
  7604. pc_delinvincibletimer(sd);
  7605. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  7606. sd->idletime = last_tick;
  7607. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7608. if(n <0 || n >= MAX_INVENTORY)
  7609. return;
  7610. if (!pc_useitem(sd,n))
  7611. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  7612. }
  7613. /*==========================================
  7614. *
  7615. *------------------------------------------*/
  7616. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  7617. {
  7618. int index;
  7619. if(pc_isdead(sd)) {
  7620. clif_clearunit_area(&sd->bl,1);
  7621. return;
  7622. }
  7623. index = RFIFOW(fd,2)-2;
  7624. if (index < 0 || index >= MAX_INVENTORY)
  7625. return; //Out of bounds check.
  7626. if(sd->npc_id) {
  7627. if (sd->npc_id != sd->npc_item_flag)
  7628. return;
  7629. } else if (sd->state.storage_flag || sd->sc.opt1)
  7630. ; //You can equip/unequip stuff while storage is open/under status changes
  7631. else if (pc_cant_act(sd))
  7632. return;
  7633. if(!sd->status.inventory[index].identify) {
  7634. clif_equipitemack(sd,index,0,0); // fail
  7635. return;
  7636. }
  7637. if(!sd->inventory_data[index])
  7638. return;
  7639. if(sd->inventory_data[index]->type == IT_PETARMOR){
  7640. pet_equipitem(sd,index);
  7641. return;
  7642. }
  7643. //Client doesn't send the position for ammo.
  7644. if(sd->inventory_data[index]->type == IT_AMMO)
  7645. pc_equipitem(sd,index,EQP_AMMO);
  7646. else
  7647. pc_equipitem(sd,index,RFIFOW(fd,4));
  7648. }
  7649. /*==========================================
  7650. *
  7651. *------------------------------------------*/
  7652. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  7653. {
  7654. int index;
  7655. if(pc_isdead(sd)) {
  7656. clif_clearunit_area(&sd->bl,1);
  7657. return;
  7658. }
  7659. if (sd->state.storage_flag)
  7660. ; //You can equip/unequip stuff while storage is open.
  7661. else if (pc_cant_act(sd))
  7662. return;
  7663. index = RFIFOW(fd,2)-2;
  7664. pc_unequipitem(sd,index,1);
  7665. }
  7666. /*==========================================
  7667. *
  7668. *------------------------------------------*/
  7669. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  7670. {
  7671. struct block_list *bl;
  7672. if(pc_isdead(sd)) {
  7673. clif_clearunit_area(&sd->bl,1);
  7674. return;
  7675. }
  7676. if (pc_cant_act(sd))
  7677. return;
  7678. bl = map_id2bl(RFIFOL(fd,2));
  7679. if (!bl) return;
  7680. switch (bl->type) {
  7681. case BL_MOB:
  7682. if (!((TBL_MOB *)bl)->nd || !mob_script_callback((TBL_MOB *)bl, &sd->bl, CALLBACK_NPCCLICK))
  7683. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7684. break;
  7685. case BL_PC:
  7686. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7687. break;
  7688. case BL_NPC:
  7689. npc_click(sd,(TBL_NPC*)bl);
  7690. break;
  7691. }
  7692. return;
  7693. }
  7694. /*==========================================
  7695. *
  7696. *------------------------------------------*/
  7697. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  7698. {
  7699. if (sd->state.trading)
  7700. return;
  7701. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  7702. }
  7703. /*==========================================
  7704. *
  7705. *------------------------------------------*/
  7706. void clif_parse_NpcBuyListSend(int fd,struct map_session_data *sd)
  7707. {
  7708. int fail=0,n;
  7709. unsigned short *item_list;
  7710. n = (RFIFOW(fd,2)-4) /4;
  7711. item_list = (unsigned short*)RFIFOP(fd,4);
  7712. if (sd->state.trading|| !sd->npc_shopid)
  7713. fail = 1;
  7714. else
  7715. fail = npc_buylist(sd,n,item_list);
  7716. sd->npc_shopid = 0; //Clear shop data.
  7717. WFIFOHEAD(fd,packet_len(0xca));
  7718. WFIFOW(fd,0)=0xca;
  7719. WFIFOB(fd,2)=fail;
  7720. WFIFOSET(fd,packet_len(0xca));
  7721. }
  7722. /*==========================================
  7723. *
  7724. *------------------------------------------*/
  7725. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  7726. {
  7727. int fail=0,n;
  7728. unsigned short *item_list;
  7729. n = (RFIFOW(fd,2)-4) /4;
  7730. item_list = (unsigned short*)RFIFOP(fd,4);
  7731. if (sd->state.trading || !sd->npc_shopid)
  7732. fail = 1;
  7733. else
  7734. fail = npc_selllist(sd,n,item_list);
  7735. sd->npc_shopid = 0; //Clear shop data.
  7736. WFIFOHEAD(fd,packet_len(0xcb));
  7737. WFIFOW(fd,0)=0xcb;
  7738. WFIFOB(fd,2)=fail;
  7739. WFIFOSET(fd,packet_len(0xcb));
  7740. }
  7741. /*==========================================
  7742. * Chatroom creation request
  7743. * S 00d5 <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7744. *------------------------------------------*/
  7745. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  7746. {
  7747. int len = RFIFOW(fd,2)-15;
  7748. int limit = RFIFOW(fd,4);
  7749. bool pub = (RFIFOB(fd,6) != 0);
  7750. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  7751. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7752. char s_title[CHATROOM_TITLE_SIZE];
  7753. char s_password[CHATROOM_PASS_SIZE];
  7754. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  7755. return;
  7756. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  7757. clif_skill_fail(sd,1,0,3);
  7758. return;
  7759. }
  7760. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7761. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7762. chat_createpcchat(sd, s_title, s_password, limit, pub);
  7763. }
  7764. /*==========================================
  7765. * Chatroom join request
  7766. * S 00d9 <chat ID>.l <passwd>.8B
  7767. *------------------------------------------*/
  7768. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  7769. {
  7770. int chatid = RFIFOL(fd,2);
  7771. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  7772. chat_joinchat(sd,chatid,password);
  7773. }
  7774. /*==========================================
  7775. * Chatroom properties adjustment request
  7776. * S 00de <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7777. *------------------------------------------*/
  7778. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  7779. {
  7780. int len = RFIFOW(fd,2)-15;
  7781. int limit = RFIFOW(fd,4);
  7782. bool pub = (RFIFOB(fd,6) != 0);
  7783. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  7784. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7785. char s_title[CHATROOM_TITLE_SIZE];
  7786. char s_password[CHATROOM_PASS_SIZE];
  7787. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7788. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7789. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  7790. }
  7791. /*==========================================
  7792. * S 00e0 ?.l <nick>.24B
  7793. *------------------------------------------*/
  7794. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  7795. {
  7796. //TODO: the first argument seems to be the destination position (always 0) [ultramage]
  7797. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  7798. }
  7799. /*==========================================
  7800. *
  7801. *------------------------------------------*/
  7802. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  7803. {
  7804. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  7805. }
  7806. /*==========================================
  7807. * Request to leave the current chatroom
  7808. * S 00e3
  7809. *------------------------------------------*/
  7810. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  7811. {
  7812. chat_leavechat(sd,0);
  7813. }
  7814. //Handles notifying asker and rejecter of what has just ocurred.
  7815. //Type is used to determine the correct msg_txt to use:
  7816. //0:
  7817. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  7818. {
  7819. char *msg, output[256];
  7820. // Your request has been rejected by autoreject option.
  7821. msg = msg_txt(392);
  7822. clif_disp_onlyself(src, msg, strlen(msg));
  7823. //Notice that a request was rejected.
  7824. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  7825. clif_disp_onlyself(target, output, strlen(output));
  7826. }
  7827. /*==========================================
  7828. * 取引要請を相手に送る
  7829. *------------------------------------------*/
  7830. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  7831. {
  7832. struct map_session_data *t_sd;
  7833. t_sd = map_id2sd(RFIFOL(fd,2));
  7834. if(!sd->chatID && pc_cant_act(sd))
  7835. return; //You can trade while in a chatroom.
  7836. // @noask [LuzZza]
  7837. if(t_sd && t_sd->state.noask) {
  7838. clif_noask_sub(sd, t_sd, 0);
  7839. return;
  7840. }
  7841. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 1){
  7842. trade_traderequest(sd,t_sd);
  7843. } else
  7844. clif_skill_fail(sd,1,0,0);
  7845. }
  7846. /*==========================================
  7847. * 取引要請
  7848. *------------------------------------------*/
  7849. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  7850. {
  7851. trade_tradeack(sd,RFIFOB(fd,2));
  7852. }
  7853. /*==========================================
  7854. * アイテム追加
  7855. *------------------------------------------*/
  7856. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  7857. {
  7858. short index = RFIFOW(fd,2);
  7859. int amount = RFIFOL(fd,4);
  7860. if( index == 0 )
  7861. trade_tradeaddzeny(sd, amount);
  7862. else
  7863. trade_tradeadditem(sd, index, (short)amount);
  7864. }
  7865. /*==========================================
  7866. * アイテム追加完了(ok押し)
  7867. *------------------------------------------*/
  7868. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  7869. {
  7870. trade_tradeok(sd);
  7871. }
  7872. /*==========================================
  7873. * 取引キャンセル
  7874. *------------------------------------------*/
  7875. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  7876. {
  7877. trade_tradecancel(sd);
  7878. }
  7879. /*==========================================
  7880. * 取引許諾(trade押し)
  7881. *------------------------------------------*/
  7882. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  7883. {
  7884. trade_tradecommit(sd);
  7885. }
  7886. /*==========================================
  7887. *
  7888. *------------------------------------------*/
  7889. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  7890. {
  7891. pc_stop_attack(sd);
  7892. }
  7893. /*==========================================
  7894. * カートへアイテムを移す
  7895. *------------------------------------------*/
  7896. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  7897. {
  7898. if (pc_istrading(sd))
  7899. return;
  7900. if (!pc_iscarton(sd))
  7901. return;
  7902. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  7903. }
  7904. /*==========================================
  7905. * カートからアイテムを出す
  7906. *------------------------------------------*/
  7907. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  7908. {
  7909. if (!pc_iscarton(sd))
  7910. return;
  7911. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  7912. }
  7913. /*==========================================
  7914. * 付属品(鷹,ペコ,カート)をはずす
  7915. *------------------------------------------*/
  7916. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  7917. {
  7918. //Can only remove Cart/Riding/Falcon.
  7919. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  7920. }
  7921. /*==========================================
  7922. * チェンジカート
  7923. *------------------------------------------*/
  7924. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  7925. {
  7926. int type;
  7927. type = (int)RFIFOW(fd,2);
  7928. if( (type == 5 && sd->status.base_level > 90) ||
  7929. (type == 4 && sd->status.base_level > 80) ||
  7930. (type == 3 && sd->status.base_level > 65) ||
  7931. (type == 2 && sd->status.base_level > 40) )
  7932. pc_setcart(sd,type);
  7933. }
  7934. /*==========================================
  7935. * ステータスアップ
  7936. *------------------------------------------*/
  7937. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  7938. {
  7939. pc_statusup(sd,RFIFOW(fd,2));
  7940. }
  7941. /*==========================================
  7942. * スキルレベルアップ
  7943. *------------------------------------------*/
  7944. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  7945. {
  7946. pc_skillup(sd,RFIFOW(fd,2));
  7947. }
  7948. 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)
  7949. {
  7950. int lv;
  7951. if (!hd)
  7952. return;
  7953. if (skillnotok_hom(skillnum, hd)) //[orn]
  7954. return;
  7955. if (hd->bl.id != target_id &&
  7956. skill_get_inf(skillnum)&INF_SELF_SKILL)
  7957. target_id = hd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  7958. if (hd->ud.skilltimer != -1) {
  7959. if (skillnum != SA_CASTCANCEL)
  7960. return;
  7961. } else if (DIFF_TICK(tick, hd->ud.canact_tick) < 0)
  7962. return;
  7963. lv = merc_hom_checkskill(hd, skillnum);
  7964. if (skilllv > lv)
  7965. skilllv = lv;
  7966. if (skilllv)
  7967. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  7968. }
  7969. /*==========================================
  7970. * スキル使用(ID指定)
  7971. *------------------------------------------*/
  7972. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  7973. {
  7974. short skillnum, skilllv;
  7975. int tmp, target_id;
  7976. unsigned int tick = gettick();
  7977. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7978. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7979. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  7980. if (skilllv < 1) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  7981. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  7982. sd->idletime = last_tick;
  7983. tmp = skill_get_inf(skillnum);
  7984. if (tmp&INF_GROUND_SKILL || !tmp)
  7985. return; //Using a ground/passive skill on a target? WRONG.
  7986. if (skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE+MAX_HOMUNSKILL) {
  7987. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  7988. return;
  7989. }
  7990. if (pc_cant_act(sd))
  7991. return;
  7992. if (pc_issit(sd))
  7993. return;
  7994. if (skillnotok(skillnum, sd))
  7995. return;
  7996. if (sd->bl.id != target_id && !sd->state.skill_flag && tmp&INF_SELF_SKILL)
  7997. target_id = sd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  7998. if (sd->ud.skilltimer != -1) {
  7999. if (skillnum != SA_CASTCANCEL)
  8000. return;
  8001. } else if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8002. clif_skill_fail(sd, skillnum, 4, 0);
  8003. return;
  8004. }
  8005. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  8006. return;
  8007. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8008. target_id = sd->bl.id;
  8009. if(sd->menuskill_id)
  8010. {
  8011. if (sd->menuskill_id == SA_TAMINGMONSTER)
  8012. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8013. else
  8014. if (sd->menuskill_id != SA_AUTOSPELL)
  8015. return; //Can't use skills while a menu is open.
  8016. }
  8017. if (sd->skillitem == skillnum) {
  8018. if (skilllv != sd->skillitemlv)
  8019. skilllv = sd->skillitemlv;
  8020. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8021. return;
  8022. }
  8023. sd->skillitem = sd->skillitemlv = 0;
  8024. if (skillnum == MO_EXTREMITYFIST) {
  8025. if ((!sd->sc.data[SC_COMBO] ||
  8026. (sd->sc.data[SC_COMBO]->val1 != MO_COMBOFINISH &&
  8027. sd->sc.data[SC_COMBO]->val1 != CH_TIGERFIST &&
  8028. sd->sc.data[SC_COMBO]->val1 != CH_CHAINCRUSH))) {
  8029. if (!sd->state.skill_flag ) {
  8030. sd->state.skill_flag = 1;
  8031. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8032. return;
  8033. } else if (sd->bl.id == target_id) {
  8034. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8035. return;
  8036. }
  8037. }
  8038. }
  8039. if (skillnum == TK_JUMPKICK) {
  8040. if (!sd->sc.data[SC_COMBO] || sd->sc.data[SC_COMBO]->val1 != TK_JUMPKICK) {
  8041. if (!sd->state.skill_flag ) {
  8042. sd->state.skill_flag = 1;
  8043. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8044. return;
  8045. } else if (sd->bl.id == target_id) {
  8046. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8047. return;
  8048. }
  8049. }
  8050. }
  8051. if (skillnum >= GD_SKILLBASE) {
  8052. if (sd->state.gmaster_flag)
  8053. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8054. else
  8055. skilllv = 0;
  8056. } else {
  8057. tmp = pc_checkskill(sd, skillnum);
  8058. if (skilllv > tmp)
  8059. skilllv = tmp;
  8060. }
  8061. pc_delinvincibletimer(sd);
  8062. if (skilllv)
  8063. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8064. if (sd->state.skill_flag)
  8065. sd->state.skill_flag = 0;
  8066. }
  8067. /*==========================================
  8068. * スキル使用(場所指定)
  8069. *------------------------------------------*/
  8070. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, short skilllv, short skillnum, short x, short y, int skillmoreinfo)
  8071. {
  8072. int lv;
  8073. unsigned int tick = gettick();
  8074. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8075. sd->idletime = last_tick;
  8076. if (skillnotok(skillnum, sd))
  8077. return;
  8078. if (!(skill_get_inf(skillnum)&INF_GROUND_SKILL))
  8079. return; //Using a target skill on the ground? WRONG.
  8080. if (skillmoreinfo != -1) {
  8081. if (pc_issit(sd)) {
  8082. clif_skill_fail(sd, skillnum, 0, 0);
  8083. return;
  8084. }
  8085. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  8086. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8087. }
  8088. if (sd->ud.skilltimer != -1)
  8089. return;
  8090. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0)
  8091. {
  8092. clif_skill_fail(sd, skillnum, 4, 0);
  8093. return;
  8094. }
  8095. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  8096. return;
  8097. if(sd->menuskill_id)
  8098. {
  8099. if (sd->menuskill_id == SA_TAMINGMONSTER)
  8100. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8101. else
  8102. if (sd->menuskill_id != SA_AUTOSPELL)
  8103. return; //Can't use skills while a menu is open.
  8104. }
  8105. pc_delinvincibletimer(sd);
  8106. if (sd->skillitem == skillnum) {
  8107. if (skilllv != sd->skillitemlv)
  8108. skilllv = sd->skillitemlv;
  8109. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8110. } else {
  8111. sd->skillitem = sd->skillitemlv = 0;
  8112. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8113. if (skilllv > lv)
  8114. skilllv = lv;
  8115. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8116. }
  8117. }
  8118. }
  8119. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  8120. {
  8121. if (pc_cant_act(sd))
  8122. return;
  8123. if (pc_issit(sd))
  8124. return;
  8125. clif_parse_UseSkillToPosSub(fd, sd,
  8126. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8127. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8128. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8129. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8130. -1 //Skill more info.
  8131. );
  8132. }
  8133. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  8134. {
  8135. if (pc_cant_act(sd))
  8136. return;
  8137. if (pc_issit(sd))
  8138. return;
  8139. clif_parse_UseSkillToPosSub(fd, sd,
  8140. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8141. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8142. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8143. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8144. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8145. );
  8146. }
  8147. /*==========================================
  8148. * スキル使用(map指定)
  8149. *------------------------------------------*/
  8150. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  8151. {
  8152. short skill_num = RFIFOW(fd,2);
  8153. char map_name[MAP_NAME_LENGTH];
  8154. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  8155. if(skill_num != sd->menuskill_id)
  8156. return;
  8157. if (pc_cant_act(sd))
  8158. {
  8159. sd->menuskill_id = sd->menuskill_val = 0;
  8160. return;
  8161. }
  8162. pc_delinvincibletimer(sd);
  8163. skill_castend_map(sd,skill_num,map_name);
  8164. }
  8165. /*==========================================
  8166. * メモ要求
  8167. *------------------------------------------*/
  8168. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8169. {
  8170. if (!pc_isdead(sd))
  8171. pc_memo(sd,-1);
  8172. }
  8173. /*==========================================
  8174. * アイテム合成
  8175. *------------------------------------------*/
  8176. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8177. {
  8178. if (sd->menuskill_id != AM_PHARMACY)
  8179. return;
  8180. if (pc_istrading(sd)) {
  8181. //Make it fail to avoid shop exploits where you sell something different than you see.
  8182. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8183. sd->menuskill_val = sd->menuskill_id = 0;
  8184. return;
  8185. }
  8186. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8187. sd->menuskill_val = sd->menuskill_id = 0;
  8188. }
  8189. /*==========================================
  8190. * 武器修理
  8191. *------------------------------------------*/
  8192. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8193. {
  8194. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8195. return;
  8196. if (pc_istrading(sd)) {
  8197. //Make it fail to avoid shop exploits where you sell something different than you see.
  8198. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8199. sd->menuskill_val = sd->menuskill_id = 0;
  8200. return;
  8201. }
  8202. skill_repairweapon(sd,RFIFOW(fd,2));
  8203. sd->menuskill_val = sd->menuskill_id = 0;
  8204. }
  8205. /*==========================================
  8206. *
  8207. *------------------------------------------*/
  8208. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  8209. {
  8210. int idx;
  8211. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8212. return;
  8213. if (pc_istrading(sd)) {
  8214. //Make it fail to avoid shop exploits where you sell something different than you see.
  8215. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8216. sd->menuskill_val = sd->menuskill_id = 0;
  8217. return;
  8218. }
  8219. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8220. skill_weaponrefine(sd, idx-2);
  8221. sd->menuskill_val = sd->menuskill_id = 0;
  8222. }
  8223. /*==========================================
  8224. *
  8225. *------------------------------------------*/
  8226. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8227. {
  8228. uint8 select;
  8229. select = RFIFOB(fd,6);
  8230. if((select > sd->npc_menu && select != 0xff) || !select){
  8231. ShowWarning("Hack on NPC Select Menu: %s (AID: %d)!\n",sd->status.name,sd->bl.id);
  8232. clif_GM_kick(NULL,sd);
  8233. } else {
  8234. sd->npc_menu=select;
  8235. npc_scriptcont(sd,RFIFOL(fd,2));
  8236. }
  8237. }
  8238. /*==========================================
  8239. *
  8240. *------------------------------------------*/
  8241. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8242. {
  8243. npc_scriptcont(sd,RFIFOL(fd,2));
  8244. }
  8245. /*==========================================
  8246. * Value entered into a NPC input box.
  8247. * S 0143 <npcID>.l <amount>.l
  8248. *------------------------------------------*/
  8249. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8250. {
  8251. int npcid = RFIFOL(fd,2);
  8252. int amount = (int)RFIFOL(fd,6);
  8253. sd->npc_amount = amount;
  8254. npc_scriptcont(sd, npcid);
  8255. }
  8256. /*==========================================
  8257. * Text entered into a NPC input box.
  8258. * S 01d5 <len>.w <npcID>.l <input>.?B 00
  8259. *------------------------------------------*/
  8260. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  8261. {
  8262. int message_len = RFIFOW(fd,2)-8;
  8263. int npcid = RFIFOL(fd,4);
  8264. const char* message = (char*)RFIFOP(fd,8);
  8265. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  8266. npc_scriptcont(sd, npcid);
  8267. }
  8268. /*==========================================
  8269. *
  8270. *------------------------------------------*/
  8271. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8272. {
  8273. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8274. return;
  8275. npc_scriptcont(sd,RFIFOL(fd,2));
  8276. }
  8277. /*==========================================
  8278. * アイテム鑑定
  8279. *------------------------------------------*/
  8280. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8281. {
  8282. if (sd->menuskill_id != MC_IDENTIFY)
  8283. return;
  8284. skill_identify(sd,RFIFOW(fd,2)-2);
  8285. sd->menuskill_val = sd->menuskill_id = 0;
  8286. }
  8287. /*==========================================
  8288. * 矢作成
  8289. *------------------------------------------*/
  8290. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8291. {
  8292. if (sd->menuskill_id != AC_MAKINGARROW)
  8293. return;
  8294. if (pc_istrading(sd)) {
  8295. //Make it fail to avoid shop exploits where you sell something different than you see.
  8296. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8297. sd->menuskill_val = sd->menuskill_id = 0;
  8298. return;
  8299. }
  8300. skill_arrow_create(sd,RFIFOW(fd,2));
  8301. sd->menuskill_val = sd->menuskill_id = 0;
  8302. }
  8303. /*==========================================
  8304. * オートスペル受信
  8305. *------------------------------------------*/
  8306. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8307. {
  8308. if (sd->menuskill_id != SA_AUTOSPELL)
  8309. return;
  8310. skill_autospell(sd,RFIFOW(fd,2));
  8311. sd->menuskill_val = sd->menuskill_id = 0;
  8312. }
  8313. /*==========================================
  8314. * カード使用
  8315. *------------------------------------------*/
  8316. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8317. {
  8318. if (sd->state.trading != 0)
  8319. return;
  8320. clif_use_card(sd,RFIFOW(fd,2)-2);
  8321. }
  8322. /*==========================================
  8323. * カード挿入装備選択
  8324. *------------------------------------------*/
  8325. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8326. {
  8327. if (sd->state.trading != 0)
  8328. return;
  8329. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8330. }
  8331. /*==========================================
  8332. * 0193 キャラID名前引き
  8333. *------------------------------------------*/
  8334. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  8335. {
  8336. int charid;
  8337. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8338. map_reqnickdb(sd, charid);
  8339. }
  8340. /*==========================================
  8341. * 0197 /resetskill /resetstate
  8342. *------------------------------------------*/
  8343. void clif_parse_ResetChar(int fd, struct map_session_data *sd)
  8344. {
  8345. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8346. return;
  8347. if( pc_isGM(sd) < get_atcommand_level(atcommand_reset) )
  8348. return;
  8349. if( RFIFOW(fd,2) )
  8350. pc_resetskill(sd,1);
  8351. else
  8352. pc_resetstate(sd);
  8353. if( log_config.gm && get_atcommand_level(atcommand_reset) >= log_config.gm )
  8354. log_atcommand(sd, RFIFOW(fd,2) ? "/resetskill" : "/resetstate");
  8355. }
  8356. /*==========================================
  8357. * /lb /nlb
  8358. * S 019c <packet len>.w <text>.?B 00
  8359. *------------------------------------------*/
  8360. void clif_parse_LGMmessage(int fd, struct map_session_data* sd)
  8361. {
  8362. char* msg = (char*)RFIFOP(fd,4);
  8363. unsigned int len = RFIFOW(fd,2)-4;
  8364. int lv;
  8365. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8366. return;
  8367. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_localbroadcast)) )
  8368. return;
  8369. // as the length varies depending on the command used, just block unreasonably long strings
  8370. mes_len_check(msg, len, CHAT_SIZE_MAX);
  8371. clif_GMmessage(&sd->bl, msg, len, 1);
  8372. if( log_config.gm && lv >= log_config.gm ) {
  8373. char logmsg[CHAT_SIZE_MAX+5];
  8374. sprintf(logmsg, "/lb %s", msg);
  8375. log_atcommand(sd, logmsg);
  8376. }
  8377. }
  8378. /*==========================================
  8379. * カプラ倉庫へ入れる
  8380. *------------------------------------------*/
  8381. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  8382. {
  8383. int item_index, item_amount;
  8384. if (pc_istrading(sd))
  8385. return;
  8386. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8387. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8388. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  8389. return;
  8390. if (sd->state.storage_flag == 1)
  8391. storage_storageadd(sd, item_index, item_amount);
  8392. else if (sd->state.storage_flag == 2)
  8393. storage_guild_storageadd(sd, item_index, item_amount);
  8394. }
  8395. /*==========================================
  8396. * カプラ倉庫から出す
  8397. *------------------------------------------*/
  8398. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  8399. {
  8400. int item_index, item_amount;
  8401. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8402. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8403. if (sd->state.storage_flag == 1)
  8404. storage_storageget(sd, item_index, item_amount);
  8405. else if(sd->state.storage_flag == 2)
  8406. storage_guild_storageget(sd, item_index, item_amount);
  8407. }
  8408. /*==========================================
  8409. * カプラ倉庫へカートから入れる
  8410. *------------------------------------------*/
  8411. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  8412. {
  8413. if(sd->vender_id)
  8414. return;
  8415. if (!pc_iscarton(sd))
  8416. return;
  8417. if (sd->state.storage_flag == 1)
  8418. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8419. else if (sd->state.storage_flag == 2)
  8420. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8421. }
  8422. /*==========================================
  8423. * カプラ倉庫から出す
  8424. *------------------------------------------*/
  8425. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  8426. {
  8427. if (sd->vender_id)
  8428. return;
  8429. if (!pc_iscarton(sd))
  8430. return;
  8431. if (sd->state.storage_flag == 1)
  8432. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8433. else if (sd->state.storage_flag == 2)
  8434. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8435. }
  8436. /*==========================================
  8437. * カプラ倉庫を閉じる
  8438. *------------------------------------------*/
  8439. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  8440. {
  8441. if (sd->state.storage_flag == 1)
  8442. storage_storageclose(sd);
  8443. else if (sd->state.storage_flag == 2)
  8444. storage_guild_storageclose(sd);
  8445. }
  8446. /*==========================================
  8447. * Kafra storage protection password system
  8448. *------------------------------------------*/
  8449. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  8450. {
  8451. //TODO
  8452. }
  8453. /*==========================================
  8454. * パーティを作る
  8455. *------------------------------------------*/
  8456. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  8457. {
  8458. if(map[sd->bl.m].flag.partylock)
  8459. { //Guild locked.
  8460. clif_displaymessage(fd, msg_txt(227));
  8461. return;
  8462. }
  8463. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7) {
  8464. party_create(sd,(char*)RFIFOP(fd,2),0,0);
  8465. } else
  8466. clif_skill_fail(sd,1,0,4);
  8467. }
  8468. /*==========================================
  8469. * パーティを作る
  8470. *------------------------------------------*/
  8471. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  8472. {
  8473. if(map[sd->bl.m].flag.partylock)
  8474. { //Guild locked.
  8475. clif_displaymessage(fd, msg_txt(227));
  8476. return;
  8477. }
  8478. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7)
  8479. party_create(sd,(char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27));
  8480. else
  8481. clif_skill_fail(sd,1,0,4);
  8482. }
  8483. /*==========================================
  8484. * パーティに勧誘
  8485. *------------------------------------------*/
  8486. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  8487. {
  8488. struct map_session_data *t_sd;
  8489. if(map[sd->bl.m].flag.partylock)
  8490. { //Guild locked.
  8491. clif_displaymessage(fd, msg_txt(227));
  8492. return;
  8493. }
  8494. t_sd = map_id2sd(RFIFOL(fd,2));
  8495. // @noask [LuzZza]
  8496. if(t_sd && t_sd->state.noask) {
  8497. clif_noask_sub(sd, t_sd, 1);
  8498. return;
  8499. }
  8500. party_invite(sd, t_sd);
  8501. }
  8502. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  8503. {
  8504. struct map_session_data *t_sd;
  8505. char *name = (char*)RFIFOP(fd,2);
  8506. name[NAME_LENGTH]='\0';
  8507. if(map[sd->bl.m].flag.partylock)
  8508. { //Guild locked.
  8509. clif_displaymessage(fd, msg_txt(227));
  8510. return;
  8511. }
  8512. t_sd = map_nick2sd(name);
  8513. // @noask [LuzZza]
  8514. if(t_sd && t_sd->state.noask) {
  8515. clif_noask_sub(sd, t_sd, 1);
  8516. return;
  8517. }
  8518. party_invite(sd, t_sd);
  8519. }
  8520. /*==========================================
  8521. * パーティ勧誘返答
  8522. *------------------------------------------*/
  8523. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  8524. {
  8525. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  8526. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8527. } else {
  8528. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8529. clif_skill_fail(sd,1,0,4);
  8530. }
  8531. }
  8532. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  8533. {
  8534. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  8535. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8536. } else {
  8537. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8538. clif_skill_fail(sd,1,0,4);
  8539. }
  8540. }
  8541. /*==========================================
  8542. * パーティ脱退要求
  8543. *------------------------------------------*/
  8544. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  8545. {
  8546. if(map[sd->bl.m].flag.partylock)
  8547. { //Guild locked.
  8548. clif_displaymessage(fd, msg_txt(227));
  8549. return;
  8550. }
  8551. party_leave(sd);
  8552. }
  8553. /*==========================================
  8554. * パーティ除名要求
  8555. *------------------------------------------*/
  8556. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  8557. {
  8558. if(map[sd->bl.m].flag.partylock)
  8559. { //Guild locked.
  8560. clif_displaymessage(fd, msg_txt(227));
  8561. return;
  8562. }
  8563. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8564. }
  8565. /*==========================================
  8566. * パーティ設定変更要求
  8567. *------------------------------------------*/
  8568. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  8569. {
  8570. struct party_data *p;
  8571. if(!sd->status.party_id)
  8572. return;
  8573. p = party_search(sd->status.party_id);
  8574. if (!p) return;
  8575. //The client no longer can change the item-field, therefore it always
  8576. //comes as zero. Here, resend the item data as it is.
  8577. // party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  8578. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  8579. }
  8580. /*==========================================
  8581. * Validates and processes party messages
  8582. * S 0108 <packet len>.w <text>.?B (<name> : <message>) 00
  8583. *------------------------------------------*/
  8584. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  8585. {
  8586. const char* text = (char*)RFIFOP(fd,4);
  8587. int textlen = RFIFOW(fd,2) - 4;
  8588. char *name, *message;
  8589. int namelen, messagelen;
  8590. // validate packet and retrieve name and message
  8591. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8592. return;
  8593. if( is_atcommand(fd, sd, message) || is_charcommand(fd, sd, message) )
  8594. return;
  8595. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8596. return;
  8597. if( battle_config.min_chat_delay )
  8598. { //[Skotlex]
  8599. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8600. return;
  8601. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8602. }
  8603. party_send_message(sd, text, textlen);
  8604. }
  8605. /*==========================================
  8606. * 露店閉鎖
  8607. *------------------------------------------*/
  8608. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  8609. {
  8610. vending_closevending(sd);
  8611. }
  8612. /*==========================================
  8613. * 露店アイテムリスト要求
  8614. *------------------------------------------*/
  8615. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  8616. {
  8617. vending_vendinglistreq(sd,RFIFOL(fd,2));
  8618. if( sd->npc_id )
  8619. npc_event_dequeue(sd);
  8620. }
  8621. /*==========================================
  8622. * Shop item(s) purchase request
  8623. * S 0134 <len>.w <ID>.l {<amount>.w <index>.w}.4B*
  8624. *------------------------------------------*/
  8625. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  8626. {
  8627. int len = (int)RFIFOW(fd,2) - 8;
  8628. int id = (int)RFIFOL(fd,4);
  8629. const uint8* data = (uint8*)RFIFOP(fd,8);
  8630. vending_purchasereq(sd, id, data, len/4);
  8631. }
  8632. /*==========================================
  8633. * Confirm or cancel the shop preparation window
  8634. * S 01b2 <len>.w <message>.80B <flag>.B {<index>.w <amount>.w <value>.l}.8B*
  8635. * flag: 0=cancel, 1=confirm
  8636. *------------------------------------------*/
  8637. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  8638. {
  8639. short len = (short)RFIFOW(fd,2) - 85;
  8640. const char* message = (char*)RFIFOP(fd,4);
  8641. bool flag = (bool)RFIFOB(fd,84);
  8642. const uint8* data = (uint8*)RFIFOP(fd,85);
  8643. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  8644. return;
  8645. if( map[sd->bl.m].flag.novending || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  8646. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open shop on this map"
  8647. return;
  8648. }
  8649. if( message[0] == '\0' ) // invalid input
  8650. return;
  8651. vending_openvending(sd, message, flag, data, len/8);
  8652. }
  8653. /*==========================================
  8654. * ギルドを作る
  8655. *------------------------------------------*/
  8656. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  8657. {
  8658. if(map[sd->bl.m].flag.guildlock)
  8659. { //Guild locked.
  8660. clif_displaymessage(fd, msg_txt(228));
  8661. return;
  8662. }
  8663. guild_create(sd, (char*)RFIFOP(fd,6));
  8664. }
  8665. /*==========================================
  8666. * ギルドマスターかどうか確認
  8667. *------------------------------------------*/
  8668. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  8669. {
  8670. clif_guild_masterormember(sd);
  8671. }
  8672. /*==========================================
  8673. * ギルド情報要求
  8674. *------------------------------------------*/
  8675. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  8676. {
  8677. if (!sd->status.guild_id)
  8678. return;
  8679. switch(RFIFOL(fd,2)){
  8680. case 0: // ギルド基本情報、同盟敵対情報
  8681. clif_guild_basicinfo(sd);
  8682. clif_guild_allianceinfo(sd);
  8683. break;
  8684. case 1: // メンバーリスト、役職名リスト
  8685. clif_guild_positionnamelist(sd);
  8686. clif_guild_memberlist(sd);
  8687. break;
  8688. case 2: // 役職名リスト、役職情報リスト
  8689. clif_guild_positionnamelist(sd);
  8690. clif_guild_positioninfolist(sd);
  8691. break;
  8692. case 3: // スキルリスト
  8693. clif_guild_skillinfo(sd);
  8694. break;
  8695. case 4: // 追放リスト
  8696. clif_guild_expulsionlist(sd);
  8697. break;
  8698. default:
  8699. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  8700. break;
  8701. }
  8702. }
  8703. /*==========================================
  8704. * ギルド役職変更
  8705. *------------------------------------------*/
  8706. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  8707. {
  8708. int i;
  8709. if(!sd->state.gmaster_flag)
  8710. return;
  8711. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  8712. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  8713. }
  8714. }
  8715. /*==========================================
  8716. * ギルドメンバ役職変更
  8717. *------------------------------------------*/
  8718. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  8719. {
  8720. int i;
  8721. if(!sd->state.gmaster_flag)
  8722. return;
  8723. for(i=4;i<RFIFOW(fd,2);i+=12){
  8724. guild_change_memberposition(sd->status.guild_id,
  8725. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  8726. }
  8727. }
  8728. /*==========================================
  8729. * ギルドエンブレム要求
  8730. *------------------------------------------*/
  8731. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  8732. {
  8733. struct guild* g = guild_search(RFIFOL(fd,2));
  8734. if(g!=NULL)
  8735. clif_guild_emblem(sd,g);
  8736. }
  8737. /*==========================================
  8738. * ギルドエンブレム変更
  8739. *------------------------------------------*/
  8740. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  8741. {
  8742. if(!sd->state.gmaster_flag)
  8743. return;
  8744. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  8745. }
  8746. /*==========================================
  8747. * Guild notice update request
  8748. * S 016E <guildID>.l <msg1>.60B <msg2>.120B
  8749. *------------------------------------------*/
  8750. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  8751. {
  8752. int guild_id = RFIFOL(fd,2);
  8753. char* msg1 = (char*)RFIFOP(fd,6);
  8754. char* msg2 = (char*)RFIFOP(fd,66);
  8755. if(!sd->state.gmaster_flag)
  8756. return;
  8757. // compensate for some client defects when using multilanguage mode
  8758. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  8759. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  8760. if (msg2[0] == '|') msg2[strnlen(msg2, 120)-1] = '\0'; // delete extra space at the end of string
  8761. guild_change_notice(sd, guild_id, msg1, msg2);
  8762. }
  8763. /*==========================================
  8764. * ギルド勧誘
  8765. *------------------------------------------*/
  8766. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  8767. {
  8768. struct map_session_data *t_sd;
  8769. if(map[sd->bl.m].flag.guildlock)
  8770. { //Guild locked.
  8771. clif_displaymessage(fd, msg_txt(228));
  8772. return;
  8773. }
  8774. t_sd = map_id2sd(RFIFOL(fd,2));
  8775. // @noask [LuzZza]
  8776. if(t_sd && t_sd->state.noask) {
  8777. clif_noask_sub(sd, t_sd, 2);
  8778. return;
  8779. }
  8780. guild_invite(sd,t_sd);
  8781. }
  8782. /*==========================================
  8783. * ギルド勧誘返信
  8784. *------------------------------------------*/
  8785. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  8786. {
  8787. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8788. }
  8789. /*==========================================
  8790. * ギルド脱退
  8791. *------------------------------------------*/
  8792. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  8793. {
  8794. if(map[sd->bl.m].flag.guildlock)
  8795. { //Guild locked.
  8796. clif_displaymessage(fd, msg_txt(228));
  8797. return;
  8798. }
  8799. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8800. }
  8801. /*==========================================
  8802. * Request to expel a member of a guild
  8803. * S 015b <guild_id>.L <account_id>.L <char_id>.L <reason>.39B 00
  8804. *------------------------------------------*/
  8805. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  8806. {
  8807. if(map[sd->bl.m].flag.guildlock)
  8808. { //Guild locked.
  8809. clif_displaymessage(fd, msg_txt(228));
  8810. return;
  8811. }
  8812. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  8813. }
  8814. /*==========================================
  8815. * Validates and processes guild messages
  8816. * S 017e <packet len>.w <text>.?B (<name> : <message>) 00
  8817. *------------------------------------------*/
  8818. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  8819. {
  8820. const char* text = (char*)RFIFOP(fd,4);
  8821. int textlen = RFIFOW(fd,2) - 4;
  8822. char *name, *message;
  8823. int namelen, messagelen;
  8824. // validate packet and retrieve name and message
  8825. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8826. return;
  8827. if( is_atcommand(fd, sd, message) || is_charcommand(fd, sd, message) )
  8828. return;
  8829. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8830. return;
  8831. if( battle_config.min_chat_delay )
  8832. { //[Skotlex]
  8833. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8834. return;
  8835. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8836. }
  8837. guild_send_message(sd, text, textlen);
  8838. }
  8839. /*==========================================
  8840. * ギルド同盟要求
  8841. *------------------------------------------*/
  8842. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  8843. {
  8844. struct map_session_data *t_sd;
  8845. if(!sd->state.gmaster_flag)
  8846. return;
  8847. if(map[sd->bl.m].flag.guildlock)
  8848. { //Guild locked.
  8849. clif_displaymessage(fd, msg_txt(228));
  8850. return;
  8851. }
  8852. t_sd = map_id2sd(RFIFOL(fd,2));
  8853. // @noask [LuzZza]
  8854. if(t_sd && t_sd->state.noask) {
  8855. clif_noask_sub(sd, t_sd, 3);
  8856. return;
  8857. }
  8858. guild_reqalliance(sd,t_sd);
  8859. }
  8860. /*==========================================
  8861. * ギルド同盟要求返信
  8862. *------------------------------------------*/
  8863. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  8864. {
  8865. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8866. }
  8867. /*==========================================
  8868. * ギルド関係解消
  8869. *------------------------------------------*/
  8870. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  8871. {
  8872. if(!sd->state.gmaster_flag)
  8873. return;
  8874. if(map[sd->bl.m].flag.guildlock)
  8875. { //Guild locked.
  8876. clif_displaymessage(fd, msg_txt(228));
  8877. return;
  8878. }
  8879. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8880. }
  8881. /*==========================================
  8882. * ギルド敵対
  8883. *------------------------------------------*/
  8884. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  8885. {
  8886. struct map_session_data *t_sd;
  8887. if(!sd->state.gmaster_flag)
  8888. return;
  8889. if(map[sd->bl.m].flag.guildlock)
  8890. { //Guild locked.
  8891. clif_displaymessage(fd, msg_txt(228));
  8892. return;
  8893. }
  8894. t_sd = map_id2sd(RFIFOL(fd,2));
  8895. // @noask [LuzZza]
  8896. if(t_sd && t_sd->state.noask) {
  8897. clif_noask_sub(sd, t_sd, 4);
  8898. return;
  8899. }
  8900. guild_opposition(sd,t_sd);
  8901. }
  8902. /*==========================================
  8903. * ギルド解散
  8904. *------------------------------------------*/
  8905. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  8906. {
  8907. if(map[sd->bl.m].flag.guildlock)
  8908. { //Guild locked.
  8909. clif_displaymessage(fd, msg_txt(228));
  8910. return;
  8911. }
  8912. guild_break(sd,(char*)RFIFOP(fd,2));
  8913. }
  8914. // pet
  8915. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  8916. {
  8917. pet_menu(sd,RFIFOB(fd,2));
  8918. }
  8919. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  8920. {
  8921. pet_catch_process2(sd,RFIFOL(fd,2));
  8922. }
  8923. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  8924. {
  8925. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  8926. return;
  8927. pet_select_egg(sd,RFIFOW(fd,2)-2);
  8928. sd->menuskill_val = sd->menuskill_id = 0;
  8929. }
  8930. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  8931. {
  8932. if(sd->pd)
  8933. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  8934. }
  8935. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  8936. {
  8937. pet_change_name(sd,(char*)RFIFOP(fd,2));
  8938. }
  8939. /*==========================================
  8940. * /kill <???>
  8941. * (or right click menu for GM "(name) force to quit")
  8942. * S 00cc <id>.L
  8943. *------------------------------------------*/
  8944. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  8945. {
  8946. struct block_list *target;
  8947. int tid,lv;
  8948. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8949. return;
  8950. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_kick)) )
  8951. return;
  8952. tid = RFIFOL(fd,2);
  8953. target = map_id2bl(tid);
  8954. if (!target) {
  8955. clif_GM_kickack(sd, 0);
  8956. return;
  8957. }
  8958. switch (target->type) {
  8959. case BL_PC:
  8960. {
  8961. struct map_session_data *tsd = (struct map_session_data *)target;
  8962. if (pc_isGM(sd) <= pc_isGM(tsd)) {
  8963. clif_GM_kickack(sd, 0);
  8964. return;
  8965. }
  8966. clif_GM_kick(sd, tsd);
  8967. if(log_config.gm && lv >= log_config.gm) {
  8968. char message[256];
  8969. sprintf(message, "/kick %s (%d)", tsd->status.name, tsd->status.char_id);
  8970. log_atcommand(sd, message);
  8971. }
  8972. }
  8973. break;
  8974. case BL_MOB:
  8975. status_percent_damage(&sd->bl, target, 100, 0, true);
  8976. if(log_config.gm && lv >= log_config.gm) {
  8977. char message[256];
  8978. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  8979. log_atcommand(sd, message);
  8980. }
  8981. break;
  8982. case BL_NPC:
  8983. {
  8984. struct npc_data* nd = (struct npc_data *)target;
  8985. lv = get_atcommand_level(atcommand_unloadnpc);
  8986. if( pc_isGM(sd) < lv )
  8987. return;
  8988. npc_unload(nd);
  8989. if( log_config.gm && lv >= log_config.gm ) {
  8990. char message[256];
  8991. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  8992. log_atcommand(sd, message);
  8993. }
  8994. }
  8995. break;
  8996. default:
  8997. clif_GM_kickack(sd, 0);
  8998. }
  8999. }
  9000. /*==========================================
  9001. * /killall
  9002. *------------------------------------------*/
  9003. void clif_parse_GMKickAll(int fd, struct map_session_data* sd)
  9004. {
  9005. is_atcommand(fd, sd, "@kickall");
  9006. }
  9007. /*==========================================
  9008. * /shift <name>
  9009. *------------------------------------------*/
  9010. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  9011. {
  9012. char *player_name;
  9013. int lv;
  9014. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9015. return;
  9016. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_jumpto)) )
  9017. return;
  9018. player_name = (char*)RFIFOP(fd,2);
  9019. player_name[NAME_LENGTH-1] = '\0';
  9020. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9021. if( log_config.gm && lv >= log_config.gm ) {
  9022. char message[NAME_LENGTH+7];
  9023. sprintf(message, "/shift %s", player_name);
  9024. log_atcommand(sd, message);
  9025. }
  9026. }
  9027. /*==========================================
  9028. * /recall <name>
  9029. *------------------------------------------*/
  9030. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  9031. {
  9032. char *player_name;
  9033. int lv;
  9034. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9035. return;
  9036. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_recall)) )
  9037. return;
  9038. player_name = (char*)RFIFOP(fd,2);
  9039. player_name[NAME_LENGTH-1] = '\0';
  9040. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9041. if( log_config.gm && lv >= log_config.gm ) {
  9042. char message[NAME_LENGTH+8];
  9043. sprintf(message, "/recall %s", player_name);
  9044. log_atcommand(sd, message);
  9045. }
  9046. }
  9047. /*==========================================
  9048. * /monster /item
  9049. *------------------------------------------*/
  9050. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  9051. {
  9052. char *monster_item_name;
  9053. char message[NAME_LENGTH+10]; //For logging.
  9054. int level;
  9055. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9056. return;
  9057. monster_item_name = (char*)RFIFOP(fd,2);
  9058. monster_item_name[NAME_LENGTH-1] = '\0';
  9059. if( mobdb_searchname(monster_item_name) ) {
  9060. if( pc_isGM(sd) < (level=get_atcommand_level(atcommand_monster)) )
  9061. return;
  9062. atcommand_monster(fd, sd, "@monster", monster_item_name); // as @monster
  9063. if( log_config.gm && level >= log_config.gm )
  9064. { //Log action. [Skotlex]
  9065. snprintf(message, sizeof(message)-1, "@spawn %s", monster_item_name);
  9066. log_atcommand(sd, message);
  9067. }
  9068. return;
  9069. }
  9070. if( itemdb_searchname(monster_item_name) == NULL )
  9071. return;
  9072. if( pc_isGM(sd) < (level = get_atcommand_level(atcommand_item)) )
  9073. return;
  9074. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9075. if( log_config.gm && level >= log_config.gm )
  9076. { //Log action. [Skotlex]
  9077. sprintf(message, "@item %s", monster_item_name);
  9078. log_atcommand(sd, message);
  9079. }
  9080. }
  9081. /*==========================================
  9082. * /hide
  9083. *------------------------------------------*/
  9084. void clif_parse_GMHide(int fd, struct map_session_data *sd)
  9085. {
  9086. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9087. return;
  9088. if( pc_isGM(sd) < get_atcommand_level(atcommand_hide) )
  9089. return;
  9090. if( sd->sc.option & OPTION_INVISIBLE ) {
  9091. sd->sc.option &= ~OPTION_INVISIBLE;
  9092. if (sd->disguise)
  9093. status_set_viewdata(&sd->bl, sd->disguise);
  9094. else
  9095. status_set_viewdata(&sd->bl, sd->status.class_);
  9096. clif_displaymessage(fd, "Invisible: Off.");
  9097. } else {
  9098. sd->sc.option |= OPTION_INVISIBLE;
  9099. sd->vd.class_ = INVISIBLE_CLASS;
  9100. clif_displaymessage(fd, "Invisible: On.");
  9101. if( log_config.gm && get_atcommand_level(atcommand_hide) >= log_config.gm )
  9102. log_atcommand(sd, "/hide");
  9103. }
  9104. clif_changeoption(&sd->bl);
  9105. }
  9106. /*==========================================
  9107. * GM adjustment of a player's manner value (right-click GM menu)
  9108. * S 0149 <id>.L <type>.B <value>.W
  9109. * type: 0 - positive points
  9110. * 1 - negative points
  9111. * 2 - self mute (+10 minutes)
  9112. *------------------------------------------*/
  9113. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9114. {
  9115. int id, type, value, level;
  9116. struct map_session_data *dstsd;
  9117. id = RFIFOL(fd,2);
  9118. type = RFIFOB(fd,6);
  9119. value = RFIFOW(fd,7);
  9120. if( type == 0 )
  9121. value = 0 - value;
  9122. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  9123. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  9124. if (type == 2 /* && (pc_isGM(sd) > 0 || sd->bl.id != id)*/)
  9125. return;
  9126. dstsd = map_id2sd(id);
  9127. if( dstsd == NULL )
  9128. return;
  9129. if( (level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(atcommand_mute) )
  9130. {
  9131. clif_manner_message(sd, 0);
  9132. clif_manner_message(dstsd, 5);
  9133. if( dstsd->status.manner < value ) {
  9134. dstsd->status.manner -= value;
  9135. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  9136. } else {
  9137. dstsd->status.manner = 0;
  9138. status_change_end(&dstsd->bl,SC_NOCHAT,-1);
  9139. }
  9140. if( type != 2 )
  9141. clif_GM_silence(sd, dstsd, type);
  9142. }
  9143. }
  9144. /*==========================================
  9145. * GM adjustment of a player's manner value by -60 (using name)
  9146. * /rc <name>
  9147. * S 0212 <name>.24B
  9148. *------------------------------------------*/
  9149. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  9150. {
  9151. char* name = (char*)RFIFOP(fd,2);
  9152. struct map_session_data* dstsd;
  9153. name[23] = '\0';
  9154. dstsd = map_nick2sd(name);
  9155. if( dstsd == NULL )
  9156. return;
  9157. if( pc_isGM(sd) > pc_isGM(dstsd) && pc_isGM(sd) >= get_atcommand_level(atcommand_mute) )
  9158. {
  9159. clif_manner_message(sd, 0);
  9160. clif_manner_message(dstsd, 3);
  9161. dstsd->status.manner -= 60;
  9162. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  9163. clif_GM_silence(sd, dstsd, 1);
  9164. }
  9165. }
  9166. /*==========================================
  9167. * GM requesting account name (for right-click gm menu)
  9168. * S 01df <id>.L
  9169. * R 01e0 <id>.L <name>.24B
  9170. *------------------------------------------*/
  9171. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  9172. {
  9173. int tid;
  9174. tid = RFIFOL(fd,2);
  9175. //TODO: find out if this works for any player or only for authorized GMs
  9176. WFIFOHEAD(fd,packet_len(0x1e0));
  9177. WFIFOW(fd,0) = 0x1e0;
  9178. WFIFOL(fd,2) = tid;
  9179. safestrncpy((char*)WFIFOP(fd,6), "", 24); // insert account name here >_<
  9180. WFIFOSET(fd, packet_len(0x1e0));
  9181. }
  9182. /*==========================================
  9183. * GM single cell type change request
  9184. * /changemaptype <x> <y> <type>
  9185. * S 0198 <x>.W <y>.W <gat>.W
  9186. *------------------------------------------*/
  9187. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  9188. {
  9189. int x,y,type;
  9190. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9191. return;
  9192. if( pc_isGM(sd) < 99 ) //TODO: add proper check
  9193. return;
  9194. x = RFIFOW(fd,2);
  9195. y = RFIFOW(fd,4);
  9196. type = RFIFOW(fd,6);
  9197. map_setgatcell(sd->bl.m,x,y,type);
  9198. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  9199. //FIXME: once players leave the map, the client 'forgets' this information.
  9200. }
  9201. /// S 00cf <nick>.24B <type>.B
  9202. /// type: 0 (/ex nick) deny speech from nick
  9203. /// 1 (/in nick) allow speech from nick
  9204. ///
  9205. /// R 00d1 <type>.B <result>.B
  9206. /// type: 0: deny, 1: allow
  9207. /// result: 0: success, 1: fail 2: list full
  9208. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  9209. {
  9210. char output[512];
  9211. char* nick;
  9212. uint8 type;
  9213. int i;
  9214. nick = (char*)RFIFOP(fd,2); // speed up
  9215. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  9216. type = RFIFOB(fd,26);
  9217. WFIFOHEAD(fd,packet_len(0xd1));
  9218. WFIFOW(fd,0) = 0x0d1;
  9219. WFIFOB(fd,2) = type;
  9220. if( type == 0 )
  9221. { // Add name to ignore list (block)
  9222. // Bot-check...
  9223. if (strcmp(wisp_server_name, nick) == 0)
  9224. { // to find possible bot users who automaticaly ignore people
  9225. 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);
  9226. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9227. WFIFOB(fd,3) = 1; // fail
  9228. WFIFOSET(fd, packet_len(0x0d1));
  9229. return;
  9230. }
  9231. // try to find a free spot, while checking for duplicates at the same time
  9232. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  9233. if( i == MAX_IGNORE_LIST )
  9234. {// no space for new entry
  9235. WFIFOB(fd,3) = 2; // fail
  9236. WFIFOSET(fd, packet_len(0x0d1));
  9237. return;
  9238. }
  9239. if( sd->ignore[i].name[0] != '\0' )
  9240. {// name already exists
  9241. WFIFOB(fd,3) = 0; // Aegis reports success.
  9242. WFIFOSET(fd, packet_len(0x0d1));
  9243. return;
  9244. }
  9245. //Insert in position i
  9246. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  9247. WFIFOB(fd,3) = 0; // success
  9248. WFIFOSET(fd, packet_len(0x0d1));
  9249. }
  9250. else
  9251. { // Remove name from ignore list (unblock)
  9252. // find entry
  9253. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  9254. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' )
  9255. { //Not found
  9256. WFIFOB(fd,3) = 1; // fail
  9257. WFIFOSET(fd, packet_len(0x0d1));
  9258. return;
  9259. }
  9260. // move everything one place down to overwrite removed entry
  9261. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  9262. // wipe last entry
  9263. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  9264. WFIFOB(fd,3) = 0; // success
  9265. WFIFOSET(fd, packet_len(0x0d1));
  9266. }
  9267. return;
  9268. }
  9269. /// S 00d0 <type>.B
  9270. /// type: 0 (/exall) deny all speech
  9271. /// 1 (/inall) allow all speech
  9272. ///
  9273. /// R 00d2 <type>.B <fail>.B
  9274. /// type: 0: deny, 1: allow
  9275. /// fail: 0: success, 1: fail
  9276. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  9277. {
  9278. WFIFOHEAD(fd,packet_len(0xd2));
  9279. WFIFOW(fd,0) = 0x0d2;
  9280. WFIFOB(fd,2) = RFIFOB(fd,2);
  9281. if( RFIFOB(fd,2) == 0 )
  9282. {// Deny all
  9283. if( sd->state.ignoreAll ) {
  9284. WFIFOB(fd,3) = 1; // fail
  9285. } else {
  9286. sd->state.ignoreAll = 1;
  9287. WFIFOB(fd,3) = 0; // success
  9288. }
  9289. }
  9290. else
  9291. {//Unblock everyone
  9292. if( sd->state.ignoreAll ) {
  9293. sd->state.ignoreAll = 0;
  9294. WFIFOB(fd,3) = 0; // success
  9295. } else {
  9296. if (sd->ignore[0].name[0] != '\0')
  9297. { //Wipe the ignore list.
  9298. memset(sd->ignore, 0, sizeof(sd->ignore));
  9299. WFIFOB(fd,3) = 0; // success
  9300. } else {
  9301. WFIFOB(fd,3) = 1; // fail
  9302. }
  9303. }
  9304. }
  9305. WFIFOSET(fd, packet_len(0x0d2));
  9306. return;
  9307. }
  9308. /*==========================================
  9309. * Wis拒否リスト
  9310. *------------------------------------------*/
  9311. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9312. {
  9313. int i;
  9314. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  9315. WFIFOW(fd,0) = 0xd4;
  9316. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9317. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  9318. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  9319. WFIFOSET(fd, WFIFOW(fd,2));
  9320. return;
  9321. }
  9322. /*==========================================
  9323. * スパノビの/doridoriによるSPR2倍
  9324. *------------------------------------------*/
  9325. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  9326. {
  9327. if (sd->state.doridori) return;
  9328. switch (sd->class_&MAPID_UPPERMASK)
  9329. {
  9330. case MAPID_SOUL_LINKER:
  9331. case MAPID_STAR_GLADIATOR:
  9332. case MAPID_TAEKWON:
  9333. if (!sd->state.rest)
  9334. break;
  9335. case MAPID_SUPER_NOVICE:
  9336. sd->state.doridori=1;
  9337. break;
  9338. }
  9339. return;
  9340. }
  9341. /*==========================================
  9342. * スパノビの爆裂波動
  9343. *------------------------------------------*/
  9344. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9345. {
  9346. if(sd){
  9347. int nextbaseexp=pc_nextbaseexp(sd);
  9348. if (battle_config.etc_log){
  9349. if(nextbaseexp != 0)
  9350. 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));
  9351. else
  9352. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9353. }
  9354. 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){
  9355. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9356. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  9357. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9358. }
  9359. }
  9360. return;
  9361. }
  9362. // random notes:
  9363. // 0x214: monster/player info ?
  9364. /*==========================================
  9365. * Friends List
  9366. *------------------------------------------*/
  9367. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9368. { //Toggles a single friend online/offline [Skotlex]
  9369. int i, fd = sd->fd;
  9370. //Seek friend.
  9371. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9372. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9373. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9374. return; //Not found
  9375. WFIFOHEAD(fd,packet_len(0x206));
  9376. WFIFOW(fd, 0) = 0x206;
  9377. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  9378. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  9379. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9380. WFIFOSET(fd, packet_len(0x206));
  9381. }
  9382. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9383. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9384. {
  9385. int account_id, char_id, online;
  9386. account_id = va_arg(ap, int);
  9387. char_id = va_arg(ap, int);
  9388. online = va_arg(ap, int);
  9389. clif_friendslist_toggle(sd, account_id, char_id, online);
  9390. return 0;
  9391. }
  9392. //For sending the whole friends list.
  9393. void clif_friendslist_send(struct map_session_data *sd)
  9394. {
  9395. int i = 0, n, fd = sd->fd;
  9396. // Send friends list
  9397. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  9398. WFIFOW(fd, 0) = 0x201;
  9399. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9400. {
  9401. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9402. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9403. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9404. }
  9405. if (i) {
  9406. WFIFOW(fd,2) = 4 + 32 * i;
  9407. WFIFOSET(fd, WFIFOW(fd,2));
  9408. }
  9409. for (n = 0; n < i; n++)
  9410. { //Sending the online players
  9411. if (map_charid2sd(sd->status.friends[n].char_id))
  9412. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9413. }
  9414. }
  9415. /// Reply for add friend request: (success => type 0)
  9416. /// type=0 : MsgStringTable[821]="You have become friends with (%s)."
  9417. /// type=1 : MsgStringTable[822]="(%s) does not want to be friends with you."
  9418. /// type=2 : MsgStringTable[819]="Your Friend List is full."
  9419. /// type=3 : MsgStringTable[820]="(%s)'s Friend List is full."
  9420. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9421. {
  9422. int fd;
  9423. nullpo_retv(sd);
  9424. fd = sd->fd;
  9425. WFIFOHEAD(fd,packet_len(0x209));
  9426. WFIFOW(fd,0) = 0x209;
  9427. WFIFOW(fd,2) = type;
  9428. if (f_sd)
  9429. {
  9430. WFIFOW(fd,4) = f_sd->status.account_id;
  9431. WFIFOW(fd,8) = f_sd->status.char_id;
  9432. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9433. }
  9434. WFIFOSET(fd, packet_len(0x209));
  9435. }
  9436. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  9437. {
  9438. struct map_session_data *f_sd;
  9439. int i, f_fd;
  9440. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9441. // Friend doesn't exist (no player with this name)
  9442. if (f_sd == NULL) {
  9443. clif_displaymessage(fd, msg_txt(3));
  9444. return;
  9445. }
  9446. // @noask [LuzZza]
  9447. if(f_sd->state.noask) {
  9448. clif_noask_sub(sd, f_sd, 5);
  9449. return;
  9450. }
  9451. // Friend already exists
  9452. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9453. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9454. clif_displaymessage(fd, "Friend already exists.");
  9455. return;
  9456. }
  9457. }
  9458. if (i == MAX_FRIENDS) {
  9459. //No space, list full.
  9460. clif_friendslist_reqack(sd, f_sd, 2);
  9461. return;
  9462. }
  9463. f_fd = f_sd->fd;
  9464. WFIFOHEAD(f_fd,packet_len(0x207));
  9465. WFIFOW(f_fd,0) = 0x207;
  9466. WFIFOL(f_fd,2) = sd->status.account_id;
  9467. WFIFOL(f_fd,6) = sd->status.char_id;
  9468. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9469. WFIFOSET(f_fd, packet_len(0x207));
  9470. return;
  9471. }
  9472. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  9473. {
  9474. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9475. struct map_session_data *f_sd;
  9476. int char_id, account_id;
  9477. char reply;
  9478. account_id = RFIFOL(fd,2);
  9479. char_id = RFIFOL(fd,6);
  9480. reply = RFIFOB(fd,10);
  9481. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9482. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9483. if (f_sd == NULL)
  9484. return;
  9485. if (reply == 0)
  9486. clif_friendslist_reqack(f_sd, sd, 1);
  9487. else {
  9488. int i;
  9489. // Find an empty slot
  9490. for (i = 0; i < MAX_FRIENDS; i++)
  9491. if (f_sd->status.friends[i].char_id == 0)
  9492. break;
  9493. if (i == MAX_FRIENDS) {
  9494. clif_friendslist_reqack(f_sd, sd, 2);
  9495. return;
  9496. }
  9497. f_sd->status.friends[i].account_id = sd->status.account_id;
  9498. f_sd->status.friends[i].char_id = sd->status.char_id;
  9499. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9500. clif_friendslist_reqack(f_sd, sd, 0);
  9501. if (battle_config.friend_auto_add) {
  9502. // Also add f_sd to sd's friendlist.
  9503. for (i = 0; i < MAX_FRIENDS; i++) {
  9504. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  9505. return; //No need to add anything.
  9506. if (sd->status.friends[i].char_id == 0)
  9507. break;
  9508. }
  9509. if (i == MAX_FRIENDS) {
  9510. clif_friendslist_reqack(sd, f_sd, 2);
  9511. return;
  9512. }
  9513. sd->status.friends[i].account_id = f_sd->status.account_id;
  9514. sd->status.friends[i].char_id = f_sd->status.char_id;
  9515. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  9516. clif_friendslist_reqack(sd, f_sd, 0);
  9517. }
  9518. }
  9519. return;
  9520. }
  9521. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  9522. {
  9523. // 0x203 </o> <ID to be removed W 4B>
  9524. int account_id, char_id;
  9525. int i, j;
  9526. account_id = RFIFOL(fd,2);
  9527. char_id = RFIFOL(fd,6);
  9528. // Search friend
  9529. for (i = 0; i < MAX_FRIENDS &&
  9530. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9531. if (i == MAX_FRIENDS) {
  9532. clif_displaymessage(fd, "Name not found in list.");
  9533. return;
  9534. }
  9535. // move all chars down
  9536. for(j = i + 1; j < MAX_FRIENDS; j++)
  9537. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9538. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9539. clif_displaymessage(fd, "Friend removed");
  9540. WFIFOHEAD(fd,packet_len(0x20a));
  9541. WFIFOW(fd,0) = 0x20a;
  9542. WFIFOL(fd,2) = account_id;
  9543. WFIFOL(fd,6) = char_id;
  9544. WFIFOSET(fd, packet_len(0x20a));
  9545. // clif_friendslist_send(sd); //This is not needed anymore.
  9546. return;
  9547. }
  9548. /*==========================================
  9549. * /pvpinfo
  9550. *------------------------------------------*/
  9551. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  9552. {
  9553. WFIFOHEAD(fd,packet_len(0x210));
  9554. WFIFOW(fd,0) = 0x210;
  9555. //WFIFOL(fd,2) = 0; // not sure what for yet
  9556. //WFIFOL(fd,6) = 0;
  9557. WFIFOL(fd,10) = sd->pvp_won; // times won
  9558. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  9559. WFIFOL(fd,18) = sd->pvp_point;
  9560. WFIFOSET(fd, packet_len(0x210));
  9561. return;
  9562. }
  9563. /*==========================================
  9564. * /blacksmith
  9565. *------------------------------------------*/
  9566. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  9567. {
  9568. int i;
  9569. const char* name;
  9570. WFIFOHEAD(fd,packet_len(0x219));
  9571. WFIFOW(fd,0) = 0x219;
  9572. //Packet size limits this list to 10 elements. [Skotlex]
  9573. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9574. if (smith_fame_list[i].id > 0) {
  9575. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  9576. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  9577. {
  9578. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  9579. } else
  9580. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  9581. } else
  9582. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  9583. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  9584. }
  9585. for(;i < 10; i++) { //In case the MAX is less than 10.
  9586. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  9587. WFIFOL(fd, 242 + i * 4) = 0;
  9588. }
  9589. WFIFOSET(fd, packet_len(0x219));
  9590. }
  9591. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  9592. {
  9593. int fd = sd->fd;
  9594. WFIFOHEAD(fd,packet_len(0x21b));
  9595. WFIFOW(fd,0) = 0x21b;
  9596. WFIFOL(fd,2) = points;
  9597. WFIFOL(fd,6) = sd->status.fame;
  9598. WFIFOSET(fd, packet_len(0x21b));
  9599. return 0;
  9600. }
  9601. /*==========================================
  9602. * /alchemist
  9603. *------------------------------------------*/
  9604. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  9605. {
  9606. int i;
  9607. const char* name;
  9608. WFIFOHEAD(fd,packet_len(0x21a));
  9609. WFIFOW(fd,0) = 0x21a;
  9610. //Packet size limits this list to 10 elements. [Skotlex]
  9611. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9612. if (chemist_fame_list[i].id > 0) {
  9613. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  9614. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  9615. {
  9616. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9617. } else
  9618. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  9619. } else
  9620. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9621. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  9622. }
  9623. for(;i < 10; i++) { //In case the MAX is less than 10.
  9624. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9625. WFIFOL(fd, 242 + i * 4) = 0;
  9626. }
  9627. WFIFOSET(fd, packet_len(0x21a));
  9628. }
  9629. int clif_fame_alchemist(struct map_session_data *sd, int points)
  9630. {
  9631. int fd = sd->fd;
  9632. WFIFOHEAD(fd,packet_len(0x21c));
  9633. WFIFOW(fd,0) = 0x21c;
  9634. WFIFOL(fd,2) = points;
  9635. WFIFOL(fd,6) = sd->status.fame;
  9636. WFIFOSET(fd, packet_len(0x21c));
  9637. return 0;
  9638. }
  9639. /*==========================================
  9640. * /taekwon
  9641. *------------------------------------------*/
  9642. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  9643. {
  9644. int i;
  9645. const char* name;
  9646. WFIFOHEAD(fd,packet_len(0x226));
  9647. WFIFOW(fd,0) = 0x226;
  9648. //Packet size limits this list to 10 elements. [Skotlex]
  9649. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9650. if (taekwon_fame_list[i].id > 0) {
  9651. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  9652. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  9653. {
  9654. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9655. } else
  9656. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  9657. } else
  9658. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9659. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  9660. }
  9661. for(;i < 10; i++) { //In case the MAX is less than 10.
  9662. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9663. WFIFOL(fd, 242 + i * 4) = 0;
  9664. }
  9665. WFIFOSET(fd, packet_len(0x226));
  9666. }
  9667. int clif_fame_taekwon(struct map_session_data *sd, int points)
  9668. {
  9669. int fd = sd->fd;
  9670. WFIFOHEAD(fd,packet_len(0x224));
  9671. WFIFOW(fd,0) = 0x224;
  9672. WFIFOL(fd,2) = points;
  9673. WFIFOL(fd,6) = sd->status.fame;
  9674. WFIFOSET(fd, packet_len(0x224));
  9675. return 0;
  9676. }
  9677. /*==========================================
  9678. * PK Ranking table?
  9679. *------------------------------------------*/
  9680. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  9681. {
  9682. int i;
  9683. WFIFOHEAD(fd,packet_len(0x238));
  9684. WFIFOW(fd,0) = 0x238;
  9685. for(i=0;i<10;i++){
  9686. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  9687. WFIFOL(fd,i*4+242) = 0;
  9688. }
  9689. WFIFOSET(fd, packet_len(0x238));
  9690. return;
  9691. }
  9692. /*==========================================
  9693. * SG Feel save OK [Komurka]
  9694. *------------------------------------------*/
  9695. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  9696. {
  9697. int i;
  9698. if (sd->menuskill_id != SG_FEEL)
  9699. return;
  9700. i = sd->menuskill_val-1;
  9701. if (i<0 || i > 2) return; //Bug?
  9702. sd->feel_map[i].index = map_id2index(sd->bl.m);
  9703. sd->feel_map[i].m = sd->bl.m;
  9704. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  9705. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  9706. // clif_misceffect2(&sd->bl, 0x1b0);
  9707. // clif_misceffect2(&sd->bl, 0x21f);
  9708. clif_feel_info(sd, i, 0);
  9709. sd->menuskill_val = sd->menuskill_id = 0;
  9710. }
  9711. /*==========================================
  9712. * Question about Star Glaldiator save map [Komurka]
  9713. *------------------------------------------*/
  9714. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv)
  9715. {
  9716. WFIFOHEAD(fd,packet_len(0x253));
  9717. WFIFOW(fd,0)=0x253;
  9718. WFIFOSET(fd, packet_len(0x253));
  9719. sd->menuskill_id = SG_FEEL;
  9720. sd->menuskill_val = skilllv;
  9721. }
  9722. void clif_parse_AdoptRequest(int fd,struct map_session_data *sd)
  9723. {
  9724. //TODO: add somewhere the adopt code, checks for exploits, etc, etc.
  9725. //Missing packets are the client's reply packets to the adopt request one.
  9726. //[Skotlex]
  9727. int account_id;
  9728. struct map_session_data *sd2;
  9729. account_id = RFIFOL(fd,2);
  9730. sd2 = map_id2sd(account_id);
  9731. if(sd2 && sd2->fd && sd2 != sd && sd2->status.party_id == sd->status.party_id) { //FIXME: No checks whatsoever are in place yet!
  9732. fd = sd2->fd;
  9733. WFIFOHEAD(fd,packet_len(0x1f9));
  9734. WFIFOW(fd,0)=0x1f9;
  9735. WFIFOSET(fd, packet_len(0x1f9));
  9736. }
  9737. }
  9738. /*==========================================
  9739. * Homunculus packets
  9740. *------------------------------------------*/
  9741. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  9742. {
  9743. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  9744. }
  9745. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  9746. {
  9747. if(!merc_is_hom_active(sd->hd))
  9748. return;
  9749. unit_walktoxy(&sd->hd->bl, sd->bl.x,sd->bl.y-1, 4);
  9750. }
  9751. void clif_parse_HomMoveTo(int fd,struct map_session_data *sd)
  9752. {
  9753. short x,y,cmd;
  9754. if(!merc_is_hom_active(sd->hd))
  9755. return;
  9756. cmd = RFIFOW(fd,0);
  9757. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  9758. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  9759. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  9760. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  9761. unit_walktoxy(&(sd->hd->bl),x,y,4);
  9762. }
  9763. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  9764. { //[orn]
  9765. if(!merc_is_hom_active(sd->hd))
  9766. return;
  9767. unit_attack(&sd->hd->bl,RFIFOL(fd,6),0) ;
  9768. }
  9769. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  9770. { //[orn]
  9771. int cmd;
  9772. cmd = RFIFOW(fd,0);
  9773. if(!merc_is_hom_active(sd->hd))
  9774. return;
  9775. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  9776. }
  9777. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  9778. {
  9779. int item_position = pc_search_inventory(sd, 7621);
  9780. if (item_position < 0)
  9781. return;
  9782. if (!status_revive(&sd->bl, 100, 100))
  9783. return;
  9784. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  9785. pc_delitem(sd, item_position, 1, 0);
  9786. }
  9787. /// /check <string>
  9788. /// S 0213 <string>.24B
  9789. void clif_parse_Check(int fd, struct map_session_data *sd)
  9790. {
  9791. // no info
  9792. }
  9793. #ifndef TXT_ONLY
  9794. /*==========================================
  9795. * MAIL SYSTEM
  9796. * By Zephyrus
  9797. *==========================================*/
  9798. /*------------------------------------------
  9799. * Reply to Set Attachment operation
  9800. * 0 : Successfully attached item to mail
  9801. * 1 : Fail to set the attachment
  9802. *------------------------------------------*/
  9803. static void clif_Mail_setattachment(int fd, int index, uint8 flag)
  9804. {
  9805. WFIFOHEAD(fd,packet_len(0x255));
  9806. WFIFOW(fd,0) = 0x255;
  9807. WFIFOW(fd,2) = index;
  9808. WFIFOB(fd,4) = flag;
  9809. WFIFOSET(fd,packet_len(0x255));
  9810. }
  9811. /*------------------------------------------
  9812. * Reply to Get Attachment operation
  9813. * 0 : Successfully added attachment to Inventory
  9814. * 1 : Fail to set the item to inventory
  9815. * 2 : Weight problems
  9816. *------------------------------------------*/
  9817. void clif_Mail_getattachment(int fd, uint8 flag)
  9818. {
  9819. WFIFOHEAD(fd,packet_len(0x245));
  9820. WFIFOW(fd,0) = 0x245;
  9821. WFIFOB(fd,2) = flag;
  9822. WFIFOSET(fd,packet_len(0x245));
  9823. }
  9824. /*------------------------------------------
  9825. * Send Mail ack
  9826. * 0 : Message Send Ok
  9827. * 1 : Recipient does not exist
  9828. *------------------------------------------*/
  9829. void clif_Mail_send(int fd, bool fail)
  9830. {
  9831. WFIFOHEAD(fd,packet_len(0x249));
  9832. WFIFOW(fd,0) = 0x249;
  9833. WFIFOB(fd,2) = fail;
  9834. WFIFOSET(fd,packet_len(0x249));
  9835. }
  9836. /*------------------------------------------
  9837. * Delete Mail ack
  9838. * 0 : Delete ok
  9839. * 1 : Delete failed
  9840. *------------------------------------------*/
  9841. void clif_Mail_delete(int fd, int mail_id, short fail)
  9842. {
  9843. WFIFOHEAD(fd, packet_len(0x257));
  9844. WFIFOW(fd,0) = 0x257;
  9845. WFIFOL(fd,2) = mail_id;
  9846. WFIFOW(fd,6) = fail;
  9847. WFIFOSET(fd, packet_len(0x257));
  9848. }
  9849. /*------------------------------------------
  9850. * Return Mail ack
  9851. * 0 : Mail returned to the sender
  9852. * 1 : The mail does not exist
  9853. *------------------------------------------*/
  9854. void clif_Mail_return(int fd, int mail_id, short fail)
  9855. {
  9856. WFIFOHEAD(fd,packet_len(0x274));
  9857. WFIFOW(fd,0) = 0x274;
  9858. WFIFOL(fd,2) = mail_id;
  9859. WFIFOW(fd,6) = fail;
  9860. WFIFOSET(fd,packet_len(0x274));
  9861. }
  9862. /*------------------------------------------
  9863. * You have New Mail
  9864. *------------------------------------------*/
  9865. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  9866. {
  9867. WFIFOHEAD(fd,packet_len(0x24a));
  9868. WFIFOW(fd,0) = 0x24a;
  9869. WFIFOL(fd,2) = mail_id;
  9870. safestrncpy((char*)WFIFOP(fd,6), sender, NAME_LENGTH);
  9871. safestrncpy((char*)WFIFOP(fd,30), title, MAIL_TITLE_LENGTH);
  9872. WFIFOSET(fd,packet_len(0x24a));
  9873. }
  9874. /*------------------------------------------
  9875. * Handles Mail Window on Client
  9876. * flag : 0 open | 1 close
  9877. *------------------------------------------*/
  9878. void clif_Mail_window(int fd, int flag)
  9879. {
  9880. WFIFOHEAD(fd,packet_len(0x260));
  9881. WFIFOW(fd,0) = 0x260;
  9882. WFIFOL(fd,2) = flag;
  9883. WFIFOSET(fd,packet_len(0x260));
  9884. }
  9885. /*------------------------------------------
  9886. * Send Inbox Data to Client
  9887. *------------------------------------------*/
  9888. void clif_Mail_refreshinbox(struct map_session_data *sd)
  9889. {
  9890. int fd = sd->fd;
  9891. struct mail_data *md = &sd->mail.inbox;
  9892. struct mail_message *msg;
  9893. int len, i, j;
  9894. len = 8 + (73 * md->amount);
  9895. WFIFOHEAD(fd,len);
  9896. WFIFOW(fd,0) = 0x240;
  9897. WFIFOW(fd,2) = len;
  9898. WFIFOL(fd,4) = md->amount;
  9899. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  9900. {
  9901. msg = &md->msg[i];
  9902. if (msg->id < 1)
  9903. continue;
  9904. WFIFOL(fd,8+73*j) = msg->id;
  9905. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  9906. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD); // 0: unread, 1: read
  9907. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  9908. WFIFOL(fd,77+73*j) = msg->timestamp;
  9909. j++;
  9910. }
  9911. WFIFOSET(fd,len);
  9912. }
  9913. /*------------------------------------------
  9914. * Client Request Inbox List
  9915. *------------------------------------------*/
  9916. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  9917. {
  9918. struct mail_data* md = &sd->mail.inbox;
  9919. if( md->amount < MAIL_MAX_INBOX && (md->full || md->changed) )
  9920. intif_Mail_requestinbox(sd->status.char_id, 1);
  9921. else
  9922. clif_Mail_refreshinbox(sd);
  9923. mail_removeitem(sd, 0);
  9924. mail_removezeny(sd, 0);
  9925. }
  9926. /*------------------------------------------
  9927. * Read Message
  9928. *------------------------------------------*/
  9929. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  9930. {
  9931. int i, fd = sd->fd;
  9932. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  9933. if( i == MAIL_MAX_INBOX )
  9934. {
  9935. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  9936. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  9937. return;
  9938. }
  9939. else
  9940. {
  9941. struct mail_message *msg = &sd->mail.inbox.msg[i];
  9942. struct item *item = &msg->item;
  9943. struct item_data *data;
  9944. int msg_len = strlen(msg->body), len;
  9945. if( msg_len == 0 ) {
  9946. strcpy(msg->body, "(no message)");
  9947. msg_len = strlen(msg->body);
  9948. }
  9949. len = 101 + msg_len;
  9950. WFIFOHEAD(fd,len);
  9951. WFIFOW(fd,0) = 0x242;
  9952. WFIFOW(fd,2) = len;
  9953. WFIFOL(fd,4) = msg->id;
  9954. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  9955. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  9956. WFIFOL(fd,72) = 0;
  9957. WFIFOL(fd,76) = msg->zeny;
  9958. if( item->nameid && (data = itemdb_search(item->nameid)) != NULL )
  9959. {
  9960. WFIFOL(fd,80) = item->amount;
  9961. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  9962. WFIFOW(fd,86) = data->type;
  9963. WFIFOB(fd,88) = item->identify;
  9964. WFIFOB(fd,89) = item->attribute;
  9965. WFIFOB(fd,90) = item->refine;
  9966. WFIFOW(fd,91) = item->card[0];
  9967. WFIFOW(fd,93) = item->card[1];
  9968. WFIFOW(fd,95) = item->card[2];
  9969. WFIFOW(fd,97) = item->card[3];
  9970. }
  9971. else // no item, set all to zero
  9972. memset(WFIFOP(fd,80), 0x00, 19);
  9973. WFIFOB(fd,99) = (unsigned char)msg_len;
  9974. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  9975. WFIFOSET(fd,len);
  9976. if (msg->status == MAIL_UNREAD) {
  9977. msg->status = MAIL_READ;
  9978. intif_Mail_read(mail_id);
  9979. clif_parse_Mail_refreshinbox(fd, sd);
  9980. }
  9981. }
  9982. }
  9983. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  9984. {
  9985. clif_Mail_read(sd, RFIFOL(fd,2));
  9986. }
  9987. /*------------------------------------------
  9988. * Get Attachment from Message
  9989. *------------------------------------------*/
  9990. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  9991. {
  9992. int i, mail_id = RFIFOL(fd,2);
  9993. bool fail = false;
  9994. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  9995. if( i == MAIL_MAX_INBOX )
  9996. return;
  9997. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  9998. return;
  9999. if( sd->mail.inbox.msg[i].item.nameid > 0 )
  10000. {
  10001. struct item_data *data;
  10002. unsigned int weight;
  10003. if ((data = itemdb_search(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  10004. return;
  10005. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) )
  10006. {
  10007. case ADDITEM_NEW:
  10008. fail = ( pc_inventoryblank(sd) == 0 );
  10009. break;
  10010. case ADDITEM_OVERAMOUNT:
  10011. fail = true;
  10012. }
  10013. if( fail )
  10014. {
  10015. clif_Mail_getattachment(fd, 1);
  10016. return;
  10017. }
  10018. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  10019. if( weight > sd->max_weight - sd->weight )
  10020. {
  10021. clif_Mail_getattachment(fd, 2);
  10022. return;
  10023. }
  10024. }
  10025. sd->mail.inbox.msg[i].zeny = 0;
  10026. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  10027. clif_Mail_read(sd, mail_id);
  10028. intif_Mail_getattach(sd->status.char_id, mail_id);
  10029. }
  10030. /*------------------------------------------
  10031. * Delete Message
  10032. *------------------------------------------*/
  10033. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  10034. {
  10035. int i, mail_id = RFIFOL(fd,2);
  10036. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10037. if (i < MAIL_MAX_INBOX)
  10038. {
  10039. struct mail_message *msg = &sd->mail.inbox.msg[i];
  10040. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 )
  10041. {// can't delete mail without removing attachment first
  10042. clif_Mail_delete(sd->fd, mail_id, 1);
  10043. return;
  10044. }
  10045. intif_Mail_delete(sd->status.char_id, mail_id);
  10046. }
  10047. }
  10048. /*------------------------------------------
  10049. * Return Mail Message
  10050. *------------------------------------------*/
  10051. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  10052. {
  10053. int i, mail_id = RFIFOL(fd,2);
  10054. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10055. if (i < MAIL_MAX_INBOX)
  10056. intif_Mail_return(sd->status.char_id, mail_id);
  10057. else
  10058. clif_Mail_return(sd->fd, mail_id, 1);
  10059. }
  10060. /*------------------------------------------
  10061. * Set Attachment
  10062. *------------------------------------------*/
  10063. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  10064. {
  10065. int idx = RFIFOW(fd,2);
  10066. int amount = RFIFOL(fd,4);
  10067. unsigned char flag;
  10068. if (idx < 0 || amount < 0)
  10069. return;
  10070. flag = mail_setitem(sd, idx, amount);
  10071. if (idx > 0)
  10072. clif_Mail_setattachment(fd,idx,flag);
  10073. }
  10074. /*------------------------------------------
  10075. * Mail Window Operation
  10076. * 0 : Switch to 'new mail' window, or Close mailbox
  10077. * 1 : ???
  10078. * 2 : ???
  10079. *------------------------------------------*/
  10080. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  10081. {
  10082. int flag = RFIFOW(fd,2);
  10083. if (flag == 0 || flag == 1)
  10084. mail_removeitem(sd, 0);
  10085. if (flag == 0 || flag == 2)
  10086. mail_removezeny(sd, 0);
  10087. }
  10088. /*------------------------------------------
  10089. * Send Mail
  10090. * S 0248 <packet len>.w <nick>.24B <title>.40B <body len>.B <message>.?B 00
  10091. *------------------------------------------*/
  10092. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  10093. {
  10094. struct mail_message msg;
  10095. int body_len;
  10096. if( sd->state.trading )
  10097. return;
  10098. if( RFIFOW(fd,2) < 69 ) {
  10099. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  10100. return;
  10101. }
  10102. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 )
  10103. {
  10104. clif_displaymessage(sd->fd,"Cannot send mails too fast!!.");
  10105. clif_Mail_send(fd, 1); // fail
  10106. return;
  10107. }
  10108. body_len = RFIFOB(fd,68);
  10109. if (body_len > MAIL_BODY_LENGTH)
  10110. body_len = MAIL_BODY_LENGTH;
  10111. if( !mail_setattachment(sd, &msg) )
  10112. { // Invalid Append condition
  10113. clif_Mail_send(sd->fd, 1); // fail
  10114. mail_removeitem(sd,0);
  10115. mail_removezeny(sd,0);
  10116. return;
  10117. }
  10118. msg.id = 0; // id will be assigned by charserver
  10119. msg.send_id = sd->status.char_id;
  10120. msg.dest_id = 0; // will attempt to resolve name
  10121. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  10122. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  10123. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  10124. if (body_len)
  10125. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  10126. else
  10127. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  10128. msg.timestamp = (int)mail_calctimes();
  10129. if( !intif_Mail_send(sd->status.account_id, &msg) )
  10130. mail_deliveryfail(sd, &msg);
  10131. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  10132. }
  10133. #endif
  10134. /*==========================================
  10135. * CASH/POINT SHOP
  10136. *==========================================*/
  10137. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  10138. {
  10139. int fd,i;
  10140. nullpo_retv(sd);
  10141. nullpo_retv(nd);
  10142. fd = sd->fd;
  10143. sd->npc_shopid = nd->bl.id;
  10144. WFIFOHEAD(fd, 200 * 11 + 12);
  10145. WFIFOW(fd,0) = 0x287;
  10146. WFIFOW(fd,2) = 12 + nd->u.shop.count*11;
  10147. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  10148. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  10149. for( i = 0; i < nd->u.shop.count; i++ )
  10150. {
  10151. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  10152. WFIFOL(fd,12+i*11) = nd->u.shop.shop_item[i].value;
  10153. WFIFOL(fd,16+i*11) = nd->u.shop.shop_item[i].value; // Discount Price? Maybe a Discount item
  10154. WFIFOB(fd,20+i*11) = itemtype(id->type);
  10155. WFIFOW(fd,21+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  10156. }
  10157. WFIFOSET(fd,WFIFOW(fd,2));
  10158. }
  10159. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
  10160. {
  10161. int fail = 0, amount, points;
  10162. short nameid;
  10163. struct npc_data *nd;
  10164. nullpo_retv(sd);
  10165. nd = (struct npc_data *)map_id2bl(sd->npc_shopid);
  10166. nameid = RFIFOW(fd,2);
  10167. amount = RFIFOW(fd,4);
  10168. points = RFIFOL(fd,6); // Not Implemented. Should be 0
  10169. fail = npc_cashshop_buy(sd, nameid, amount, points);
  10170. WFIFOHEAD(fd,12);
  10171. WFIFOW(fd,0) = 0x289;
  10172. WFIFOL(fd,2) = sd->cashPoints;
  10173. WFIFOL(fd,6) = sd->kafraPoints;
  10174. WFIFOW(fd,10) = fail;
  10175. WFIFOSET(fd,12);
  10176. }
  10177. /*==========================================
  10178. * AUCTIONS SYSTEM
  10179. *==========================================*/
  10180. void clif_Auction_openwindow(struct map_session_data *sd)
  10181. {
  10182. int fd = sd->fd;
  10183. WFIFOHEAD(fd,12);
  10184. WFIFOW(fd,0) = 0x25f;
  10185. WFIFOL(fd,2) = 0;
  10186. WFIFOB(fd,6) = 0xb6;
  10187. WFIFOB(fd,7) = 0x00;
  10188. WFIFOB(fd,8) = 0xa6;
  10189. WFIFOB(fd,9) = 0xde;
  10190. WFIFOW(fd,10) = 0;
  10191. WFIFOSET(fd,12);
  10192. }
  10193. /*==========================================
  10194. * Requesting equip of a player
  10195. *------------------------------------------*/
  10196. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  10197. {
  10198. int charid = RFIFOL(fd, 2);
  10199. struct map_session_data* tsd = map_id2sd(charid);
  10200. if (!tsd)
  10201. return;
  10202. if( tsd->status.show_equip )
  10203. clif_viewequip_ack(sd, tsd);
  10204. else
  10205. clif_viewequip_fail(sd);
  10206. }
  10207. /*==========================================
  10208. * Equip window (un)tick
  10209. * S 02d8 <zero?>.L <flag>.L
  10210. *------------------------------------------*/
  10211. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  10212. {
  10213. bool flag = (bool)RFIFOL(fd,6); // 0=off, 1=on
  10214. sd->status.show_equip = flag;
  10215. clif_equiptickack(sd, flag);
  10216. }
  10217. /*==========================================
  10218. * パケットデバッグ
  10219. *------------------------------------------*/
  10220. void clif_parse_debug(int fd,struct map_session_data *sd)
  10221. {
  10222. int i, cmd, len;
  10223. cmd = RFIFOW(fd,0);
  10224. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  10225. ShowDebug("packet debug 0x%4X\n",cmd);
  10226. ShowMessage("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10227. for(i=0;i<len;i++){
  10228. if((i&15)==0)
  10229. ShowMessage("\n%04X ",i);
  10230. ShowMessage("%02X ",RFIFOB(fd,i));
  10231. }
  10232. ShowMessage("\n");
  10233. }
  10234. /*==========================================
  10235. * Main client packet processing function
  10236. *------------------------------------------*/
  10237. int clif_parse(int fd)
  10238. {
  10239. int cmd, packet_ver, packet_len, err;
  10240. TBL_PC* sd;
  10241. int pnum;
  10242. //TODO apply deplays or disconnect based on packet throughput [FlavioJS]
  10243. // Note: "click masters" can do 80+ clicks in 10 seconds
  10244. for( pnum = 0; pnum < 3; ++pnum )// Limit max packets per cycle to 3 (delay packet spammers) [FlavioJS]
  10245. { // begin main client packet processing loop
  10246. sd = (TBL_PC *)session[fd]->session_data;
  10247. if (session[fd]->flag.eof) {
  10248. if (sd) {
  10249. if (sd->state.autotrade) {
  10250. //Disassociate character from the socket connection.
  10251. session[fd]->session_data = NULL;
  10252. sd->fd = 0;
  10253. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  10254. } else
  10255. if (sd->state.active) {
  10256. // Player logout display [Valaris]
  10257. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  10258. clif_quitsave(fd, sd);
  10259. } else {
  10260. //Unusual logout (during log on/off/map-changer procedure)
  10261. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  10262. map_quit(sd);
  10263. }
  10264. } else {
  10265. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  10266. }
  10267. do_close(fd);
  10268. return 0;
  10269. }
  10270. if (RFIFOREST(fd) < 2)
  10271. return 0;
  10272. cmd = RFIFOW(fd,0);
  10273. // identify client's packet version
  10274. if (sd) {
  10275. packet_ver = sd->packet_ver;
  10276. } else {
  10277. // check authentification packet to know packet version
  10278. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  10279. if( err )
  10280. {// failed to identify packet version
  10281. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  10282. err == 1 ? "" :
  10283. err == 2 ? ", possibly for having an invalid account_id" :
  10284. err == 3 ? ", possibly for having an invalid char_id." :
  10285. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  10286. err == 4 ? ", possibly for having an invalid login_id1." :
  10287. err == 5 ? ", possibly for having an invalid client_tick." :
  10288. */
  10289. err == 6 ? ", possibly for having an invalid sex." :
  10290. ". ERROR invalid error code"));
  10291. WFIFOHEAD(fd,packet_len(0x6a));
  10292. WFIFOW(fd,0) = 0x6a;
  10293. WFIFOB(fd,2) = 3; // Rejected from Server
  10294. WFIFOSET(fd,packet_len(0x6a));
  10295. RFIFOSKIP(fd, RFIFOREST(fd));
  10296. clif_setwaitclose(fd);
  10297. return 0;
  10298. }
  10299. }
  10300. // filter out invalid / unsupported packets
  10301. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  10302. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  10303. set_eof(fd);
  10304. return 0;
  10305. }
  10306. // determine real packet length
  10307. packet_len = packet_db[packet_ver][cmd].len;
  10308. if (packet_len == -1) { // variable-length packet
  10309. if (RFIFOREST(fd) < 4)
  10310. return 0;
  10311. packet_len = RFIFOW(fd,2);
  10312. if (packet_len < 4 || packet_len > 32768) {
  10313. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  10314. set_eof(fd);
  10315. return 0;
  10316. }
  10317. }
  10318. if ((int)RFIFOREST(fd) < packet_len)
  10319. return 0; // not enough data received to form the packet
  10320. if (packet_db[packet_ver][cmd].func) {
  10321. if (sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck)
  10322. ; //Only valid packet when player is not on a map is the finish-loading packet.
  10323. else
  10324. if ((sd && sd->state.active)
  10325. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  10326. || packet_db[packet_ver][cmd].func == clif_parse_debug
  10327. ) //Only execute the function when there's an active sd (except for debug/wanttoconnect packets)
  10328. packet_db[packet_ver][cmd].func(fd, sd);
  10329. }
  10330. #if DUMP_UNKNOWN_PACKET
  10331. else if (battle_config.error_log)
  10332. {
  10333. int i;
  10334. FILE *fp;
  10335. char packet_txt[256] = "save/packet.txt";
  10336. time_t now;
  10337. dump = 1;
  10338. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10339. ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
  10340. return 1;
  10341. } else {
  10342. time(&now);
  10343. if (sd && sd->state.active) {
  10344. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  10345. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10346. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10347. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10348. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10349. for(i = 0; i < packet_len; i++) {
  10350. if ((i & 15) == 0)
  10351. fprintf(fp, "\n\t%04X ", i);
  10352. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10353. }
  10354. fprintf(fp, "\n\n");
  10355. fclose(fp);
  10356. }
  10357. }
  10358. #endif
  10359. /* TODO: use utils.c :: dump()
  10360. if (dump) {
  10361. int i;
  10362. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10363. ShowMessage("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10364. for(i = 0; i < packet_len; i++) {
  10365. if ((i & 15) == 0)
  10366. ShowMessage("\n%04X ",i);
  10367. ShowMessage("%02X ", RFIFOB(fd,i));
  10368. }
  10369. ShowMessage("\n");
  10370. if (sd && sd->state.active) {
  10371. if (sd->status.name != NULL)
  10372. ShowMessage("\nAccount ID %d, character ID %d, player name %s.\n",
  10373. sd->status.account_id, sd->status.char_id, sd->status.name);
  10374. else
  10375. ShowMessage("\nAccount ID %d.\n", sd->bl.id);
  10376. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10377. ShowMessage("\nAccount ID %d.\n", sd->bl.id);
  10378. }*/
  10379. RFIFOSKIP(fd, packet_len);
  10380. }; // main loop end
  10381. return 0;
  10382. }
  10383. /*==========================================
  10384. * パケットデータベース読み込み
  10385. *------------------------------------------*/
  10386. static int packetdb_readdb(void)
  10387. {
  10388. FILE *fp;
  10389. char line[1024];
  10390. int ln=0;
  10391. int cmd,i,j,packet_ver;
  10392. int max_cmd=-1;
  10393. int skip_ver = 0;
  10394. int warned = 0;
  10395. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  10396. int packet_len_table[MAX_PACKET_DB] = {
  10397. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10401. //#0x0040
  10402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10404. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  10405. #if PACKETVER < 2
  10406. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  10407. #elif PACKETVER < 9 // 78-7b 亀島以降 lv99エフェクト用
  10408. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  10409. #else // change in 0x78 and 0x7c
  10410. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  10411. #endif
  10412. //#0x0080
  10413. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  10414. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  10415. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  10416. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  10417. //#0x00C0
  10418. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  10419. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  10420. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  10421. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  10422. //#0x0100
  10423. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  10424. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  10425. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  10426. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  10427. //#0x0140
  10428. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  10429. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  10430. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  10431. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  10432. //#0x0180
  10433. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  10434. #if PACKETVER < 1
  10435. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10436. #else // 196 comodo以降 状態表示アイコン用
  10437. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10438. #endif
  10439. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  10440. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  10441. //#0x01C0, Set 0x1d5=-1
  10442. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  10443. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  10444. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  10445. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  10446. //#0x0200
  10447. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  10448. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  10449. #if PACKETVER < 9
  10450. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  10451. #else // 0x22c changed
  10452. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  10453. #endif
  10454. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1, -1, 4, 2,
  10455. //#0x0240
  10456. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  10457. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4, -1, 4, 0,
  10458. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10459. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10460. //#0x0280
  10461. 0, 0, 0, 6, 0, 0, 0, 0, 0, 8, 18, 0, 0, 0, 0, 0,
  10462. 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10464. 0, 0, 0, 0, 0, 0, 0, 0, 0,191, 0, 0, 0, 0, 0, 0,
  10465. //#0x02C0
  10466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10467. 0, 0, 0, 0, 0, 0, 6, -1, 10, 10, 0, 0, 0, 0, 0, 0,
  10468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10470. };
  10471. struct {
  10472. void (*func)(int, struct map_session_data *);
  10473. char *name;
  10474. } clif_parse_func[]={
  10475. {clif_parse_WantToConnection,"wanttoconnection"},
  10476. {clif_parse_LoadEndAck,"loadendack"},
  10477. {clif_parse_TickSend,"ticksend"},
  10478. {clif_parse_WalkToXY,"walktoxy"},
  10479. {clif_parse_QuitGame,"quitgame"},
  10480. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  10481. {clif_parse_GlobalMessage,"globalmessage"},
  10482. {clif_parse_MapMove,"mapmove"},
  10483. {clif_parse_ChangeDir,"changedir"},
  10484. {clif_parse_Emotion,"emotion"},
  10485. {clif_parse_HowManyConnections,"howmanyconnections"},
  10486. {clif_parse_ActionRequest,"actionrequest"},
  10487. {clif_parse_Restart,"restart"},
  10488. {clif_parse_WisMessage,"wis"},
  10489. {clif_parse_GMmessage,"gmmessage"},
  10490. {clif_parse_TakeItem,"takeitem"},
  10491. {clif_parse_DropItem,"dropitem"},
  10492. {clif_parse_UseItem,"useitem"},
  10493. {clif_parse_EquipItem,"equipitem"},
  10494. {clif_parse_UnequipItem,"unequipitem"},
  10495. {clif_parse_NpcClicked,"npcclicked"},
  10496. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  10497. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  10498. {clif_parse_NpcSellListSend,"npcselllistsend"},
  10499. {clif_parse_CreateChatRoom,"createchatroom"},
  10500. {clif_parse_ChatAddMember,"chataddmember"},
  10501. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  10502. {clif_parse_ChangeChatOwner,"changechatowner"},
  10503. {clif_parse_KickFromChat,"kickfromchat"},
  10504. {clif_parse_ChatLeave,"chatleave"},
  10505. {clif_parse_TradeRequest,"traderequest"},
  10506. {clif_parse_TradeAck,"tradeack"},
  10507. {clif_parse_TradeAddItem,"tradeadditem"},
  10508. {clif_parse_TradeOk,"tradeok"},
  10509. {clif_parse_TradeCancel,"tradecancel"},
  10510. {clif_parse_TradeCommit,"tradecommit"},
  10511. {clif_parse_StopAttack,"stopattack"},
  10512. {clif_parse_PutItemToCart,"putitemtocart"},
  10513. {clif_parse_GetItemFromCart,"getitemfromcart"},
  10514. {clif_parse_RemoveOption,"removeoption"},
  10515. {clif_parse_ChangeCart,"changecart"},
  10516. {clif_parse_StatusUp,"statusup"},
  10517. {clif_parse_SkillUp,"skillup"},
  10518. {clif_parse_UseSkillToId,"useskilltoid"},
  10519. {clif_parse_UseSkillToPos,"useskilltopos"},
  10520. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  10521. {clif_parse_UseSkillMap,"useskillmap"},
  10522. {clif_parse_RequestMemo,"requestmemo"},
  10523. {clif_parse_ProduceMix,"producemix"},
  10524. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  10525. {clif_parse_NpcNextClicked,"npcnextclicked"},
  10526. {clif_parse_NpcAmountInput,"npcamountinput"},
  10527. {clif_parse_NpcStringInput,"npcstringinput"},
  10528. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  10529. {clif_parse_ItemIdentify,"itemidentify"},
  10530. {clif_parse_SelectArrow,"selectarrow"},
  10531. {clif_parse_AutoSpell,"autospell"},
  10532. {clif_parse_UseCard,"usecard"},
  10533. {clif_parse_InsertCard,"insertcard"},
  10534. {clif_parse_RepairItem,"repairitem"},
  10535. {clif_parse_WeaponRefine,"weaponrefine"},
  10536. {clif_parse_SolveCharName,"solvecharname"},
  10537. {clif_parse_ResetChar,"resetchar"},
  10538. {clif_parse_LGMmessage,"lgmmessage"},
  10539. {clif_parse_MoveToKafra,"movetokafra"},
  10540. {clif_parse_MoveFromKafra,"movefromkafra"},
  10541. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  10542. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  10543. {clif_parse_CloseKafra,"closekafra"},
  10544. {clif_parse_CreateParty,"createparty"},
  10545. {clif_parse_CreateParty2,"createparty2"},
  10546. {clif_parse_PartyInvite,"partyinvite"},
  10547. {clif_parse_PartyInvite2,"partyinvite2"},
  10548. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  10549. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  10550. {clif_parse_LeaveParty,"leaveparty"},
  10551. {clif_parse_RemovePartyMember,"removepartymember"},
  10552. {clif_parse_PartyChangeOption,"partychangeoption"},
  10553. {clif_parse_PartyMessage,"partymessage"},
  10554. {clif_parse_CloseVending,"closevending"},
  10555. {clif_parse_VendingListReq,"vendinglistreq"},
  10556. {clif_parse_PurchaseReq,"purchasereq"},
  10557. {clif_parse_OpenVending,"openvending"},
  10558. {clif_parse_CreateGuild,"createguild"},
  10559. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  10560. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  10561. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  10562. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  10563. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  10564. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  10565. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  10566. {clif_parse_GuildInvite,"guildinvite"},
  10567. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  10568. {clif_parse_GuildLeave,"guildleave"},
  10569. {clif_parse_GuildExpulsion,"guildexpulsion"},
  10570. {clif_parse_GuildMessage,"guildmessage"},
  10571. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  10572. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  10573. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  10574. {clif_parse_GuildOpposition,"guildopposition"},
  10575. {clif_parse_GuildBreak,"guildbreak"},
  10576. {clif_parse_PetMenu,"petmenu"},
  10577. {clif_parse_CatchPet,"catchpet"},
  10578. {clif_parse_SelectEgg,"selectegg"},
  10579. {clif_parse_SendEmotion,"sendemotion"},
  10580. {clif_parse_ChangePetName,"changepetname"},
  10581. {clif_parse_GMKick,"gmkick"},
  10582. {clif_parse_GMHide,"gmhide"},
  10583. {clif_parse_GMReqNoChat,"gmreqnochat"},
  10584. {clif_parse_GMReqAccountName,"gmreqaccname"},
  10585. {clif_parse_GMKickAll,"killall"},
  10586. {clif_parse_GMRecall,"recall"},
  10587. {clif_parse_GMRecall,"summon"},
  10588. {clif_parse_GM_Monster_Item,"itemmonster"},
  10589. {clif_parse_GMShift,"remove"},
  10590. {clif_parse_GMShift,"shift"},
  10591. {clif_parse_GMChangeMapType,"changemaptype"},
  10592. {clif_parse_GMRc,"rc"},
  10593. {clif_parse_NoviceDoriDori,"sndoridori"},
  10594. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  10595. {clif_parse_PMIgnore,"wisexin"},
  10596. {clif_parse_PMIgnoreList,"wisexlist"},
  10597. {clif_parse_PMIgnoreAll,"wisall"},
  10598. {clif_parse_FriendsListAdd,"friendslistadd"},
  10599. {clif_parse_FriendsListRemove,"friendslistremove"},
  10600. {clif_parse_FriendsListReply,"friendslistreply"},
  10601. {clif_parse_Blacksmith,"blacksmith"},
  10602. {clif_parse_Alchemist,"alchemist"},
  10603. {clif_parse_Taekwon,"taekwon"},
  10604. {clif_parse_RankingPk,"rankingpk"},
  10605. {clif_parse_FeelSaveOk,"feelsaveok"},
  10606. {clif_parse_AdoptRequest,"adopt"},
  10607. {clif_parse_debug,"debug"},
  10608. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  10609. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  10610. {clif_parse_HomMoveTo,"hommoveto"},
  10611. {clif_parse_HomAttack,"homattack"},
  10612. {clif_parse_HomMenu,"hommenu"},
  10613. {clif_parse_StoragePassword,"storagepassword"},
  10614. {clif_parse_Hotkey,"hotkey"},
  10615. {clif_parse_AutoRevive,"autorevive"},
  10616. {clif_parse_Check,"check"},
  10617. #ifndef TXT_ONLY
  10618. // MAIL SYSTEM
  10619. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  10620. {clif_parse_Mail_read,"mailread"},
  10621. {clif_parse_Mail_getattach,"mailgetattach"},
  10622. {clif_parse_Mail_delete,"maildelete"},
  10623. {clif_parse_Mail_return,"mailreturn"},
  10624. {clif_parse_Mail_setattach,"mailsetattach"},
  10625. {clif_parse_Mail_winopen,"mailwinopen"},
  10626. {clif_parse_Mail_send,"mailsend"},
  10627. #endif
  10628. {clif_parse_cashshop_buy,"cashshopbuy"},
  10629. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  10630. {clif_parse_EquipTick,"equiptickbox"},
  10631. {NULL,NULL}
  10632. };
  10633. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  10634. memset(packet_db,0,sizeof(packet_db));
  10635. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  10636. packet_len(i) = packet_len_table[i];
  10637. sprintf(line, "%s/packet_db.txt", db_path);
  10638. if( (fp=fopen(line,"r"))==NULL ){
  10639. ShowFatalError("can't read %s\n", line);
  10640. exit(EXIT_FAILURE);
  10641. }
  10642. clif_config.packet_db_ver = MAX_PACKET_VER;
  10643. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  10644. while( fgets(line, sizeof(line), fp) )
  10645. {
  10646. ln++;
  10647. if(line[0]=='/' && line[1]=='/')
  10648. continue;
  10649. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  10650. {
  10651. if(strcmpi(w1,"packet_ver")==0) {
  10652. int prev_ver = packet_ver;
  10653. skip_ver = 0;
  10654. packet_ver = atoi(w2);
  10655. if ( packet_ver > MAX_PACKET_VER )
  10656. { //Check to avoid overflowing. [Skotlex]
  10657. if( (warned&1) == 0 )
  10658. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  10659. warned &= 1;
  10660. skip_ver = 1;
  10661. }
  10662. else if( packet_ver < 0 )
  10663. {
  10664. if( (warned&2) == 0 )
  10665. ShowWarning("Negative packet versions are not supported.\n");
  10666. warned &= 2;
  10667. skip_ver = 1;
  10668. }
  10669. else if( packet_ver == SERVER )
  10670. {
  10671. if( (warned&4) == 0 )
  10672. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  10673. warned &= 4;
  10674. skip_ver = 1;
  10675. }
  10676. if( skip_ver )
  10677. {
  10678. ShowWarning("Skipping packet version %d.\n", packet_ver);
  10679. packet_ver = prev_ver;
  10680. continue;
  10681. }
  10682. // copy from previous version into new version and continue
  10683. // - indicating all following packets should be read into the newer version
  10684. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  10685. continue;
  10686. } else if(strcmpi(w1,"packet_db_ver")==0) {
  10687. if(strcmpi(w2,"default")==0) //This is the preferred version.
  10688. clif_config.packet_db_ver = MAX_PACKET_VER;
  10689. else // to manually set the packet DB version
  10690. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  10691. continue;
  10692. }
  10693. }
  10694. if( skip_ver != 0 )
  10695. continue; // Skipping current packet version
  10696. memset(str,0,sizeof(str));
  10697. for(j=0,p=line;j<4 && p; ++j)
  10698. {
  10699. str[j]=p;
  10700. p=strchr(p,',');
  10701. if(p) *p++=0;
  10702. }
  10703. if(str[0]==NULL)
  10704. continue;
  10705. cmd=strtol(str[0],(char **)NULL,0);
  10706. if(max_cmd < cmd)
  10707. max_cmd = cmd;
  10708. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  10709. continue;
  10710. if(str[1]==NULL){
  10711. ShowError("packet_db: packet len error\n");
  10712. continue;
  10713. }
  10714. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  10715. if(str[2]==NULL){
  10716. packet_db[packet_ver][cmd].func = NULL;
  10717. ln++;
  10718. continue;
  10719. }
  10720. // look up processing function by name
  10721. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  10722. if( j < ARRAYLENGTH(clif_parse_func) )
  10723. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  10724. // set the identifying cmd for the packet_db version
  10725. if (strcmp(str[2],"wanttoconnection")==0)
  10726. clif_config.connect_cmd[packet_ver] = cmd;
  10727. if(str[3]==NULL){
  10728. ShowError("packet_db: packet error\n");
  10729. exit(EXIT_FAILURE);
  10730. }
  10731. for(j=0,p2=str[3];p2;j++){
  10732. short k;
  10733. str2[j]=p2;
  10734. p2=strchr(p2,':');
  10735. if(p2) *p2++=0;
  10736. k = atoi(str2[j]);
  10737. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  10738. packet_db[packet_ver][cmd].pos[j] = k;
  10739. }
  10740. }
  10741. fclose(fp);
  10742. if(max_cmd > MAX_PACKET_DB)
  10743. {
  10744. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  10745. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  10746. }
  10747. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  10748. { //Locate the nearest version that we still support. [Skotlex]
  10749. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  10750. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  10751. }
  10752. 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);
  10753. return 0;
  10754. }
  10755. /*==========================================
  10756. *
  10757. *------------------------------------------*/
  10758. int do_init_clif(void)
  10759. {
  10760. clif_config.packet_db_ver = -1; // the main packet version of the DB
  10761. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  10762. memset(packet_db,0,sizeof(packet_db));
  10763. //Using the packet_db file is the only way to set up packets now [Skotlex]
  10764. packetdb_readdb();
  10765. set_defaultparse(clif_parse);
  10766. if( make_listen_bind(bind_ip,map_port) == -1 )
  10767. {
  10768. ShowFatalError("can't bind game port\n");
  10769. exit(EXIT_FAILURE);
  10770. }
  10771. add_timer_func_list(clif_waitclose, "clif_waitclose");
  10772. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  10773. add_timer_func_list(clif_delayquit, "clif_delayquit");
  10774. return 0;
  10775. }