clif.c 360 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576
  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 "intif.h"
  25. #include "battle.h"
  26. #include "battleground.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 "homunculus.h"
  34. #include "mercenary.h"
  35. #include "log.h"
  36. #include "clif.h"
  37. #include "mail.h"
  38. #include "quest.h"
  39. #include <stdio.h>
  40. #include <stdlib.h>
  41. #include <string.h>
  42. #include <stdarg.h>
  43. #include <time.h>
  44. #define DUMP_UNKNOWN_PACKET 0
  45. struct Clif_Config {
  46. int packet_db_ver; //Preferred packet version.
  47. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  48. } clif_config;
  49. struct s_packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB + 1];
  50. //Converts item type in case of pet eggs.
  51. #define itemtype(a) (a == IT_PETEGG)?IT_WEAPON:a
  52. #define WBUFPOS(p,pos,x,y,dir) \
  53. do { \
  54. uint8 *__p = (p); \
  55. __p+=(pos); \
  56. __p[0] = (uint8)((x)>>2); \
  57. __p[1] = (uint8)(((x)<<6) | (((y)>>4)&0x3f)); \
  58. __p[2] = (uint8)(((y)<<4) | ((dir)&0xf)); \
  59. } while(0)
  60. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  61. #define WBUFPOS2(p,pos,x0,y0,x1,y1,sx0,sy0) \
  62. do { \
  63. uint8 *__p = (p); \
  64. __p+=(pos); \
  65. __p[0]=(uint8)((x0)>>2); \
  66. __p[1]=(uint8)(((x0)<<6) | (((y0)>>4)&0x3f)); \
  67. __p[2]=(uint8)(((y0)<<4) | (((x1)>>6)&0x0f)); \
  68. __p[3]=(uint8)(((x1)<<2) | (((y1)>>8)&0x03)); \
  69. __p[4]=(uint8)(y1); \
  70. __p[5]=(uint8)(((sx0)<<4) | ((sy0)&0x0f)); \
  71. } while(0)
  72. #define WFIFOPOS(fd,pos,x,y,dir) WBUFPOS(WFIFOP(fd,pos),0,x,y,dir)
  73. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1,sx0,sy0) WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1,sx0,sy0)
  74. //To idenfity disguised characters.
  75. #define disguised(bl) ((bl)->type==BL_PC && ((TBL_PC*)bl)->disguise)
  76. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex\]
  77. #define mes_len_check(mes, len, max) if (len > max) { mes[max-1] = '\0'; len = max; } else mes[len-1] = '\0';
  78. static char map_ip_str[128];
  79. static uint32 map_ip;
  80. static uint32 bind_ip = INADDR_ANY;
  81. static uint16 map_port = 5121;
  82. int map_fd;
  83. int clif_parse (int fd);
  84. /*==========================================
  85. * map鯖のip設定
  86. *------------------------------------------*/
  87. int clif_setip(const char* ip)
  88. {
  89. char ip_str[16];
  90. map_ip = host2ip(ip);
  91. if (!map_ip) {
  92. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  93. return 0;
  94. }
  95. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  96. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(map_ip, ip_str));
  97. return 1;
  98. }
  99. void clif_setbindip(const char* ip)
  100. {
  101. char ip_str[16];
  102. bind_ip = host2ip(ip);
  103. if (bind_ip) {
  104. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip2str(bind_ip, ip_str));
  105. } else {
  106. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  107. }
  108. }
  109. /*==========================================
  110. * map鯖のport設定
  111. *------------------------------------------*/
  112. void clif_setport(uint16 port)
  113. {
  114. map_port = port;
  115. }
  116. /*==========================================
  117. * map鯖のip読み出し
  118. *------------------------------------------*/
  119. uint32 clif_getip(void)
  120. {
  121. return map_ip;
  122. }
  123. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it returns 0.
  124. uint32 clif_refresh_ip(void)
  125. {
  126. uint32 new_ip;
  127. new_ip = host2ip(map_ip_str);
  128. if (new_ip && new_ip != map_ip) {
  129. map_ip = new_ip;
  130. ShowInfo("Updating IP resolution of [%s].\n", map_ip_str);
  131. return map_ip;
  132. }
  133. return 0;
  134. }
  135. /*==========================================
  136. * map鯖のport読み出し
  137. *------------------------------------------*/
  138. uint16 clif_getport(void)
  139. {
  140. return map_port;
  141. }
  142. /*==========================================
  143. * clif_sendでAREA*指定時用
  144. *------------------------------------------*/
  145. int clif_send_sub(struct block_list *bl, va_list ap)
  146. {
  147. struct block_list *src_bl;
  148. struct map_session_data *sd;
  149. unsigned char *buf;
  150. int len, type, fd;
  151. nullpo_retr(0, bl);
  152. nullpo_retr(0, sd = (struct map_session_data *)bl);
  153. fd = sd->fd;
  154. if (!fd) //Don't send to disconnected clients.
  155. return 0;
  156. buf = va_arg(ap,unsigned char*);
  157. len = va_arg(ap,int);
  158. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  159. type = va_arg(ap,int);
  160. switch(type)
  161. {
  162. case AREA_WOS:
  163. if (bl == src_bl)
  164. return 0;
  165. break;
  166. case AREA_WOC:
  167. if (sd->chatID || bl == src_bl)
  168. return 0;
  169. break;
  170. case AREA_WOSC:
  171. {
  172. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  173. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  174. return 0;
  175. }
  176. break;
  177. }
  178. if (session[fd] == NULL)
  179. return 0;
  180. WFIFOHEAD(fd, len);
  181. if (WFIFOP(fd,0) == buf) {
  182. ShowError("WARNING: Invalid use of clif_send function\n");
  183. ShowError(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  184. ShowError(" Please correct your code.\n");
  185. // don't send to not move the pointer of the packet for next sessions in the loop
  186. //WFIFOSET(fd,0);//## TODO is this ok?
  187. //NO. It is not ok. There is the chance WFIFOSET actually sends the buffer data, and shifts elements around, which will corrupt the buffer.
  188. return 0;
  189. }
  190. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  191. memcpy(WFIFOP(fd,0), buf, len);
  192. WFIFOSET(fd,len);
  193. }
  194. return 0;
  195. }
  196. /*==========================================
  197. *
  198. *------------------------------------------*/
  199. int clif_send(const uint8* buf, int len, struct block_list* bl, enum send_target type)
  200. {
  201. int i;
  202. struct map_session_data *sd, *tsd;
  203. struct party_data *p = NULL;
  204. struct guild *g = NULL;
  205. struct battleground_data *bg = NULL;
  206. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  207. struct s_mapiterator* iter;
  208. if( type != ALL_CLIENT && type != CHAT_MAINCHAT )
  209. nullpo_retr(0, bl);
  210. sd = BL_CAST(BL_PC, bl);
  211. switch(type) {
  212. case ALL_CLIENT: //All player clients.
  213. iter = mapit_getallusers();
  214. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  215. {
  216. if( packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  217. { // packet must exist for the client version
  218. WFIFOHEAD(tsd->fd, len);
  219. memcpy(WFIFOP(tsd->fd,0), buf, len);
  220. WFIFOSET(tsd->fd,len);
  221. }
  222. }
  223. mapit_free(iter);
  224. break;
  225. case ALL_SAMEMAP: //All players on the same map
  226. iter = mapit_getallusers();
  227. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  228. {
  229. if( bl->m == tsd->bl.m && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  230. { // packet must exist for the client version
  231. WFIFOHEAD(tsd->fd, len);
  232. memcpy(WFIFOP(tsd->fd,0), buf, len);
  233. WFIFOSET(tsd->fd,len);
  234. }
  235. }
  236. mapit_free(iter);
  237. break;
  238. case AREA:
  239. case AREA_WOSC:
  240. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  241. clif_send (buf, len, bl, SELF);
  242. case AREA_WOC:
  243. case AREA_WOS:
  244. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  245. BL_PC, buf, len, bl, type);
  246. break;
  247. case AREA_CHAT_WOC:
  248. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  249. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  250. break;
  251. case CHAT:
  252. case CHAT_WOS:
  253. {
  254. struct chat_data *cd;
  255. if (sd) {
  256. cd = (struct chat_data*)map_id2bl(sd->chatID);
  257. } else if (bl->type == BL_CHAT) {
  258. cd = (struct chat_data*)bl;
  259. } else break;
  260. if (cd == NULL)
  261. break;
  262. for(i = 0; i < cd->users; i++) {
  263. if (type == CHAT_WOS && cd->usersd[i] == sd)
  264. continue;
  265. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  266. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  267. {
  268. WFIFOHEAD(fd,len);
  269. memcpy(WFIFOP(fd,0), buf, len);
  270. WFIFOSET(fd,len);
  271. }
  272. }
  273. }
  274. }
  275. break;
  276. case CHAT_MAINCHAT: //[LuzZza]
  277. iter = mapit_getallusers();
  278. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  279. {
  280. if( tsd->state.mainchat && tsd->chatID == 0 && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  281. { // packet must exist for the client version
  282. WFIFOHEAD(tsd->fd, len);
  283. memcpy(WFIFOP(tsd->fd,0), buf, len);
  284. WFIFOSET(tsd->fd,len);
  285. }
  286. }
  287. mapit_free(iter);
  288. break;
  289. case PARTY_AREA:
  290. case PARTY_AREA_WOS:
  291. x0 = bl->x - AREA_SIZE;
  292. y0 = bl->y - AREA_SIZE;
  293. x1 = bl->x + AREA_SIZE;
  294. y1 = bl->y + AREA_SIZE;
  295. case PARTY:
  296. case PARTY_WOS:
  297. case PARTY_SAMEMAP:
  298. case PARTY_SAMEMAP_WOS:
  299. if (sd && sd->status.party_id)
  300. p = party_search(sd->status.party_id);
  301. if (p) {
  302. for(i=0;i<MAX_PARTY;i++){
  303. if( (sd = p->data[i].sd) == NULL )
  304. continue;
  305. if( !(fd=sd->fd) )
  306. continue;
  307. if( sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS) )
  308. continue;
  309. if( type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m )
  310. continue;
  311. if( (type == PARTY_AREA || type == PARTY_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  312. continue;
  313. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  314. { // packet must exist for the client version
  315. WFIFOHEAD(fd,len);
  316. memcpy(WFIFOP(fd,0), buf, len);
  317. WFIFOSET(fd,len);
  318. }
  319. }
  320. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  321. break;
  322. iter = mapit_getallusers();
  323. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  324. {
  325. if( tsd->partyspy == p->party.party_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  326. { // packet must exist for the client version
  327. WFIFOHEAD(tsd->fd, len);
  328. memcpy(WFIFOP(tsd->fd,0), buf, len);
  329. WFIFOSET(tsd->fd,len);
  330. }
  331. }
  332. mapit_free(iter);
  333. }
  334. break;
  335. case DUEL:
  336. case DUEL_WOS:
  337. if (!sd || !sd->duel_group) break; //Invalid usage.
  338. iter = mapit_getallusers();
  339. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  340. {
  341. if( type == DUEL_WOS && bl->id == tsd->bl.id )
  342. continue;
  343. if( sd->duel_group == tsd->duel_group && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  344. { // packet must exist for the client version
  345. WFIFOHEAD(tsd->fd, len);
  346. memcpy(WFIFOP(tsd->fd,0), buf, len);
  347. WFIFOSET(tsd->fd,len);
  348. }
  349. }
  350. mapit_free(iter);
  351. break;
  352. case SELF:
  353. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  354. WFIFOHEAD(fd,len);
  355. memcpy(WFIFOP(fd,0), buf, len);
  356. WFIFOSET(fd,len);
  357. }
  358. break;
  359. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  360. case GUILD_AREA:
  361. case GUILD_AREA_WOS:
  362. x0 = bl->x - AREA_SIZE;
  363. y0 = bl->y - AREA_SIZE;
  364. x1 = bl->x + AREA_SIZE;
  365. y1 = bl->y + AREA_SIZE;
  366. case GUILD_SAMEMAP:
  367. case GUILD_SAMEMAP_WOS:
  368. case GUILD:
  369. case GUILD_WOS:
  370. case GUILD_NOBG:
  371. if (sd && sd->status.guild_id)
  372. g = guild_search(sd->status.guild_id);
  373. if (g) {
  374. for(i = 0; i < g->max_member; i++) {
  375. if( (sd = g->member[i].sd) != NULL )
  376. {
  377. if( !(fd=sd->fd) )
  378. continue;
  379. if( type == GUILD_NOBG && sd->state.bg_id )
  380. continue;
  381. if( sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS) )
  382. continue;
  383. if( type != GUILD && type != GUILD_NOBG && type != GUILD_WOS && sd->bl.m != bl->m )
  384. continue;
  385. if( (type == GUILD_AREA || type == GUILD_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  386. continue;
  387. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  388. { // packet must exist for the client version
  389. WFIFOHEAD(fd,len);
  390. memcpy(WFIFOP(fd,0), buf, len);
  391. WFIFOSET(fd,len);
  392. }
  393. }
  394. }
  395. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  396. break;
  397. iter = mapit_getallusers();
  398. while( (tsd = (TBL_PC*)mapit_next(iter)) != NULL )
  399. {
  400. if( tsd->guildspy == g->guild_id && packet_db[tsd->packet_ver][RBUFW(buf,0)].len )
  401. { // packet must exist for the client version
  402. WFIFOHEAD(tsd->fd, len);
  403. memcpy(WFIFOP(tsd->fd,0), buf, len);
  404. WFIFOSET(tsd->fd,len);
  405. }
  406. }
  407. mapit_free(iter);
  408. }
  409. break;
  410. case BG_AREA:
  411. case BG_AREA_WOS:
  412. x0 = bl->x - AREA_SIZE;
  413. y0 = bl->y - AREA_SIZE;
  414. x1 = bl->x + AREA_SIZE;
  415. y1 = bl->y + AREA_SIZE;
  416. case BG_SAMEMAP:
  417. case BG_SAMEMAP_WOS:
  418. case BG:
  419. case BG_WOS:
  420. if( sd && sd->state.bg_id && (bg = bg_team_search(sd->state.bg_id)) != NULL )
  421. {
  422. for( i = 0; i < MAX_BG_MEMBERS; i++ )
  423. {
  424. if( (sd = bg->members[i].sd) == NULL || !(fd = sd->fd) )
  425. continue;
  426. if( sd->bl.id == bl->id && (type == BG_WOS || type == BG_SAMEMAP_WOS || type == BG_AREA_WOS) )
  427. continue;
  428. if( type != BG && type != BG_WOS && sd->bl.m != bl->m )
  429. continue;
  430. if( (type == BG_AREA || type == BG_AREA_WOS) && (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1) )
  431. continue;
  432. if( packet_db[sd->packet_ver][RBUFW(buf,0)].len )
  433. { // packet must exist for the client version
  434. WFIFOHEAD(fd,len);
  435. memcpy(WFIFOP(fd,0), buf, len);
  436. WFIFOSET(fd,len);
  437. }
  438. }
  439. }
  440. break;
  441. default:
  442. ShowError("clif_send: Unrecognized type %d\n",type);
  443. return -1;
  444. }
  445. return 0;
  446. }
  447. //
  448. // パケット作って送信
  449. //
  450. /*==========================================
  451. *
  452. *------------------------------------------*/
  453. int clif_authok(struct map_session_data *sd)
  454. {
  455. int fd;
  456. if (!sd->fd)
  457. return 0;
  458. fd = sd->fd;
  459. WFIFOHEAD(fd, packet_len(0x73));
  460. WFIFOW(fd, 0) = 0x73;
  461. WFIFOL(fd, 2) = gettick();
  462. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  463. WFIFOB(fd, 9) = 5; // ignored
  464. WFIFOB(fd,10) = 5; // ignored
  465. WFIFOSET(fd,packet_len(0x73));
  466. return 0;
  467. }
  468. /*==========================================
  469. * Authentication failed/disconnect client.
  470. *------------------------------------------
  471. * The client closes it's socket and displays a message according to type:
  472. * 1 - server closed -> MsgStringTable[4]
  473. * 2 - ID already logged in -> MsgStringTable[5]
  474. * 3 - timeout/too much lag -> MsgStringTable[241]
  475. * 4 - server full -> MsgStringTable[264]
  476. * 5 - underaged -> MsgStringTable[305]
  477. * 8 - Server sill recognizes last connection -> MsgStringTable[441]
  478. * 9 - too many connections from this ip -> MsgStringTable[529]
  479. * 10 - out of available time paid for -> MsgStringTable[530]
  480. * 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  481. * other - disconnected -> MsgStringTable[3]
  482. */
  483. int clif_authfail_fd(int fd, int type)
  484. {
  485. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  486. return 0;
  487. WFIFOHEAD(fd, packet_len(0x81));
  488. WFIFOW(fd,0) = 0x81;
  489. WFIFOB(fd,2) = type;
  490. WFIFOSET(fd,packet_len(0x81));
  491. set_eof(fd);
  492. return 0;
  493. }
  494. /*==========================================
  495. *
  496. *------------------------------------------*/
  497. int clif_charselectok(int id)
  498. {
  499. struct map_session_data* sd;
  500. int fd;
  501. if ((sd = map_id2sd(id)) == NULL || !sd->fd)
  502. return 1;
  503. fd = sd->fd;
  504. WFIFOHEAD(fd,packet_len(0xb3));
  505. WFIFOW(fd,0) = 0xb3;
  506. WFIFOB(fd,2) = 1;
  507. WFIFOSET(fd,packet_len(0xb3));
  508. return 0;
  509. }
  510. /*==========================================
  511. * Makes an item appear on the ground
  512. * 009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  513. *------------------------------------------*/
  514. int clif_dropflooritem(struct flooritem_data* fitem)
  515. {
  516. uint8 buf[17];
  517. int view;
  518. nullpo_retr(0, fitem);
  519. if (fitem->item_data.nameid <= 0)
  520. return 0;
  521. WBUFW(buf, 0) = 0x9e;
  522. WBUFL(buf, 2) = fitem->bl.id;
  523. WBUFW(buf, 6) = ((view = itemdb_viewid(fitem->item_data.nameid)) > 0) ? view : fitem->item_data.nameid;
  524. WBUFB(buf, 8) = fitem->item_data.identify;
  525. WBUFW(buf, 9) = fitem->bl.x;
  526. WBUFW(buf,11) = fitem->bl.y;
  527. WBUFB(buf,13) = fitem->subx;
  528. WBUFB(buf,14) = fitem->suby;
  529. WBUFW(buf,15) = fitem->item_data.amount;
  530. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  531. return 0;
  532. }
  533. /*==========================================
  534. *
  535. *------------------------------------------*/
  536. int clif_clearflooritem(struct flooritem_data *fitem, int fd)
  537. {
  538. unsigned char buf[16];
  539. nullpo_retr(0, fitem);
  540. WBUFW(buf,0) = 0xa1;
  541. WBUFL(buf,2) = fitem->bl.id;
  542. if (fd == 0) {
  543. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  544. } else {
  545. WFIFOHEAD(fd,packet_len(0xa1));
  546. memcpy(WFIFOP(fd,0), buf, packet_len(0xa1));
  547. WFIFOSET(fd,packet_len(0xa1));
  548. }
  549. return 0;
  550. }
  551. /*==========================================
  552. * make a unit (char, npc, mob, homun) disappear to one client
  553. * id : the id of the unit
  554. * type: 0 - moved out of sight
  555. * 1 - died
  556. * 2 - respawned
  557. * 3 - teleported / logged out
  558. * fd : the target client
  559. *------------------------------------------*/
  560. int clif_clearunit_single(int id, uint8 type, int fd)
  561. {
  562. WFIFOHEAD(fd, packet_len(0x80));
  563. WFIFOW(fd,0) = 0x80;
  564. WFIFOL(fd,2) = id;
  565. WFIFOB(fd,6) = type;
  566. WFIFOSET(fd, packet_len(0x80));
  567. return 0;
  568. }
  569. /*==========================================
  570. * make a unit (char, npc, mob, homun) disappear to all clients in area
  571. * type: 0 - moved out of sight
  572. * 1 - died
  573. * 2 - respawned
  574. * 3 - teleported / logged out
  575. *------------------------------------------*/
  576. int clif_clearunit_area(struct block_list* bl, uint8 type)
  577. {
  578. unsigned char buf[16];
  579. nullpo_retr(0, bl);
  580. WBUFW(buf,0) = 0x80;
  581. WBUFL(buf,2) = bl->id;
  582. WBUFB(buf,6) = type;
  583. clif_send(buf, packet_len(0x80), bl, type == 1 ? AREA : AREA_WOS);
  584. if(disguised(bl)) {
  585. WBUFL(buf,2) = -bl->id;
  586. clif_send(buf, packet_len(0x80), bl, SELF);
  587. }
  588. return 0;
  589. }
  590. static int clif_clearunit_delayed_sub(int tid, unsigned int tick, int id, intptr data)
  591. {
  592. struct block_list *bl = (struct block_list *)data;
  593. clif_clearunit_area(bl, 0);
  594. aFree(bl);
  595. return 0;
  596. }
  597. int clif_clearunit_delayed(struct block_list* bl, unsigned int tick)
  598. {
  599. struct block_list *tbl;
  600. tbl = (struct block_list*)aMalloc(sizeof (struct block_list));
  601. memcpy (tbl, bl, sizeof (struct block_list));
  602. add_timer(tick, clif_clearunit_delayed_sub, 0, (intptr)tbl);
  603. return 0;
  604. }
  605. void clif_get_weapon_view(struct map_session_data* sd, unsigned short *rhand, unsigned short *lhand)
  606. {
  607. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER))
  608. {
  609. *rhand = *lhand = 0;
  610. return;
  611. }
  612. #if PACKETVER < 4
  613. *rhand = sd->status.weapon;
  614. *lhand = sd->status.shield;
  615. #else
  616. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  617. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  618. {
  619. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  620. if (id->view_id > 0)
  621. *rhand = id->view_id;
  622. else
  623. *rhand = id->nameid;
  624. } else
  625. *rhand = 0;
  626. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  627. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  628. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  629. {
  630. struct item_data* id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  631. if (id->view_id > 0)
  632. *lhand = id->view_id;
  633. else
  634. *lhand = id->nameid;
  635. } else
  636. *lhand = 0;
  637. #endif
  638. }
  639. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  640. static int clif_setlevel(int lv)
  641. {
  642. if( lv < battle_config.max_lv )
  643. return lv;
  644. if( lv < battle_config.aura_lv )
  645. return battle_config.max_lv - 1;
  646. return battle_config.max_lv;
  647. }
  648. /*==========================================
  649. * Prepares 'unit standing/spawning' packet
  650. *------------------------------------------*/
  651. static int clif_set_unit_idle(struct block_list* bl, unsigned char* buffer, bool spawn)
  652. {
  653. struct map_session_data* sd;
  654. struct status_change* sc = status_get_sc(bl);
  655. struct view_data* vd = status_get_viewdata(bl);
  656. unsigned char *buf = WBUFP(buffer,0);
  657. bool type = !pcdb_checkid(vd->class_);
  658. #if PACKETVER >= 7
  659. unsigned short offset = 0;
  660. #endif
  661. sd = BL_CAST(BL_PC, bl);
  662. if(type)
  663. WBUFW(buf,0) = spawn?0x7c:0x78;
  664. else
  665. #if PACKETVER < 4
  666. WBUFW(buf,0) = spawn?0x79:0x78;
  667. #elif PACKETVER < 7
  668. WBUFW(buf,0) = spawn?0x1d9:0x1d8;
  669. #else
  670. WBUFW(buf,0) = spawn?0x22b:0x22a;
  671. #endif
  672. #if PACKETVER >= 20071106
  673. if (type) {
  674. // shift payload 1 byte to the right for mob packets
  675. WBUFB(buf,2) = 0; // padding?
  676. offset++;
  677. buf = WBUFP(buffer,offset);
  678. }
  679. #endif
  680. WBUFL(buf, 2) = bl->id;
  681. WBUFW(buf, 6) = status_get_speed(bl);
  682. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  683. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  684. if (type&&spawn) { //uses an older and different packet structure
  685. WBUFW(buf,12) = (sc)? sc->option : 0;
  686. WBUFW(buf,14) = vd->hair_style;
  687. WBUFW(buf,16) = vd->weapon;
  688. WBUFW(buf,18) = vd->head_bottom;
  689. WBUFW(buf,20) = vd->class_; //Pet armor (ignored by client)
  690. WBUFW(buf,22) = vd->shield;
  691. } else {
  692. #if PACKETVER >= 7
  693. if (!type) {
  694. WBUFL(buf,12) = (sc)? sc->option : 0;
  695. offset+=2;
  696. buf = WBUFP(buffer,offset); //Shift 2 bytes to the right for the rest of fields
  697. } else
  698. #endif
  699. WBUFW(buf,12) = (sc)? sc->option : 0;
  700. WBUFW(buf,14) = vd->class_;
  701. WBUFW(buf,16) = vd->hair_style;
  702. WBUFW(buf,18) = vd->weapon;
  703. #if PACKETVER < 4
  704. WBUFW(buf,20) = vd->head_bottom;
  705. WBUFW(buf,22) = vd->shield;
  706. #else
  707. WBUFW(buf,20) = vd->shield;
  708. WBUFW(buf,22) = vd->head_bottom;
  709. #endif
  710. }
  711. WBUFW(buf,24) = vd->head_top;
  712. WBUFW(buf,26) = vd->head_mid;
  713. if( bl->type == BL_NPC && vd->class_ == FLAG_CLASS )
  714. { //The hell, why flags work like this?
  715. WBUFL(buf,22) = clif_bg_emblem_id(bl);
  716. WBUFL(buf,26) = clif_bg_guild_id(bl);
  717. }
  718. WBUFW(buf,28) = vd->hair_color;
  719. WBUFW(buf,30) = vd->cloth_color;
  720. WBUFW(buf,32) = (sd)? sd->head_dir : 0;
  721. if (type&&spawn) { //End of packet 0x7c
  722. WBUFB(buf,34) = 0; // karma
  723. WBUFB(buf,35) = vd->sex;
  724. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  725. WBUFB(buf,39) = 0;
  726. WBUFB(buf,40) = 0;
  727. return packet_len(0x7c);
  728. }
  729. WBUFL(buf,34) = clif_bg_guild_id(bl);
  730. WBUFW(buf,38) = clif_bg_emblem_id(bl);
  731. WBUFW(buf,40) = (sd)? sd->status.manner : 0;
  732. #if PACKETVER >= 7
  733. if (!type) {
  734. WBUFL(buf,42) = (sc)? sc->opt3 : 0;
  735. offset+=2;
  736. buf = WBUFP(buffer,offset); //Shift additional 2 bytes...
  737. } else
  738. #endif
  739. WBUFW(buf,42) = (sc)? sc->opt3 : 0;
  740. WBUFB(buf,44) = (sd)? sd->status.karma : 0;
  741. WBUFB(buf,45) = vd->sex;
  742. WBUFPOS(buf,46,bl->x,bl->y,unit_getdir(bl));
  743. WBUFB(buf,49) = (sd)? 5 : 0;
  744. WBUFB(buf,50) = (sd)? 5 : 0;
  745. if (spawn) {
  746. WBUFW(buf,51) = clif_setlevel(status_get_lv(bl));
  747. } else {
  748. WBUFB(buf,51) = vd->dead_sit;
  749. WBUFW(buf,52) = clif_setlevel(status_get_lv(bl));
  750. }
  751. return packet_len(WBUFW(buffer,0));
  752. }
  753. /*==========================================
  754. * Prepares 'unit walking' packet
  755. *------------------------------------------*/
  756. static int clif_set_unit_walking(struct block_list* bl, struct unit_data* ud, unsigned char* buffer)
  757. {
  758. struct map_session_data* sd;
  759. struct status_change* sc = status_get_sc(bl);
  760. struct view_data* vd = status_get_viewdata(bl);
  761. unsigned char* buf = WBUFP(buffer,0);
  762. #if PACKETVER >= 7
  763. unsigned short offset = 0;
  764. #endif
  765. sd = BL_CAST(BL_PC, bl);
  766. #if PACKETVER < 4
  767. WBUFW(buf, 0) = 0x7b;
  768. #elif PACKETVER < 7
  769. WBUFW(buf, 0) = 0x1da;
  770. #else
  771. WBUFW(buf, 0) = 0x22c;
  772. #endif
  773. #if PACKETVER >= 20071106
  774. WBUFB(buf, 2) = 0; // padding?
  775. offset++;
  776. buf = WBUFP(buf,offset);
  777. #endif
  778. WBUFL(buf, 2) = bl->id;
  779. WBUFW(buf, 6) = status_get_speed(bl);
  780. WBUFW(buf, 8) = (sc)? sc->opt1 : 0;
  781. WBUFW(buf,10) = (sc)? sc->opt2 : 0;
  782. #if PACKETVER < 7
  783. WBUFW(buf,12) = (sc)? sc->option : 0;
  784. #else
  785. WBUFL(buf,12) = (sc)? sc->option : 0;
  786. offset+=2; //Shift the rest of elements by 2 bytes.
  787. buf = WBUFP(buffer,offset);
  788. #endif
  789. WBUFW(buf,14) = vd->class_;
  790. WBUFW(buf,16) = vd->hair_style;
  791. WBUFW(buf,18) = vd->weapon;
  792. #if PACKETVER < 4
  793. WBUFW(buf,20) = vd->head_bottom;
  794. WBUFL(buf,22) = gettick();
  795. WBUFW(buf,26) = vd->shield;
  796. #else
  797. WBUFW(buf,20) = vd->shield;
  798. WBUFW(buf,22) = vd->head_bottom;
  799. WBUFL(buf,24) = gettick();
  800. #endif
  801. WBUFW(buf,28) = vd->head_top;
  802. WBUFW(buf,30) = vd->head_mid;
  803. WBUFW(buf,32) = vd->hair_color;
  804. WBUFW(buf,34) = vd->cloth_color;
  805. WBUFW(buf,36) = (sd)? sd->head_dir : 0;
  806. WBUFL(buf,38) = clif_bg_guild_id(bl);
  807. WBUFW(buf,42) = clif_bg_emblem_id(bl);
  808. WBUFW(buf,44) = (sd)? sd->status.manner : 0;
  809. #if PACKETVER < 7
  810. WBUFW(buf,46) = (sc)? sc->opt3 : 0;
  811. #else
  812. WBUFL(buf,46) = (sc)? sc->opt3 : 0;
  813. offset+=2; //Shift the rest of elements by 2 bytes.
  814. buf = WBUFP(buffer,offset);
  815. #endif
  816. WBUFB(buf,48) = (sd)? sd->status.karma : 0;
  817. WBUFB(buf,49) = vd->sex;
  818. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  819. WBUFB(buf,56) = (sd)? 5 : 0;
  820. WBUFB(buf,57) = (sd)? 5 : 0;
  821. WBUFW(buf,58) = clif_setlevel(status_get_lv(bl));
  822. return packet_len(WBUFW(buffer,0));
  823. }
  824. //Modifies the buffer for disguise characters and sends it to self.
  825. //Used for spawn/walk packets, where the ID offset changes for packetver >=9
  826. static void clif_setdisguise(struct block_list *bl, unsigned char *buf,int len)
  827. {
  828. #if PACKETVER >= 20071106
  829. WBUFL(buf,3)=-bl->id;
  830. #else
  831. WBUFL(buf,2)=-bl->id;
  832. #endif
  833. clif_send(buf, len, bl, SELF);
  834. }
  835. /*==========================================
  836. * クラスチェンジ typeはMobの場合は1で他は0?
  837. *------------------------------------------*/
  838. int clif_class_change(struct block_list *bl,int class_,int type)
  839. {
  840. unsigned char buf[16];
  841. nullpo_retr(0, bl);
  842. if(!pcdb_checkid(class_)) {
  843. WBUFW(buf,0)=0x1b0;
  844. WBUFL(buf,2)=bl->id;
  845. WBUFB(buf,6)=type;
  846. WBUFL(buf,7)=class_;
  847. clif_send(buf,packet_len(0x1b0),bl,AREA);
  848. }
  849. return 0;
  850. }
  851. /*==========================================
  852. *
  853. *------------------------------------------*/
  854. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  855. {
  856. WFIFOHEAD(fd, packet_len(0x1e1));
  857. WFIFOW(fd,0)=0x1e1;
  858. WFIFOL(fd,2)=sd->bl.id;
  859. WFIFOW(fd,6)=sd->spiritball;
  860. WFIFOSET(fd, packet_len(0x1e1));
  861. }
  862. // new and improved weather display [Valaris]
  863. static void clif_weather_sub(int fd, int id, int type)
  864. {
  865. WFIFOHEAD(fd,packet_len(0x1f3));
  866. WFIFOW(fd,0) = 0x1f3;
  867. WFIFOL(fd,2) = id;
  868. WFIFOL(fd,6) = type;
  869. WFIFOSET(fd,packet_len(0x1f3));
  870. }
  871. /*==========================================
  872. *
  873. *------------------------------------------*/
  874. static void clif_weather_check(struct map_session_data *sd)
  875. {
  876. int m = sd->bl.m, fd = sd->fd;
  877. if (map[m].flag.snow
  878. || map[m].flag.clouds
  879. || map[m].flag.fog
  880. || map[m].flag.fireworks
  881. || map[m].flag.sakura
  882. || map[m].flag.leaves
  883. || map[m].flag.rain
  884. || map[m].flag.clouds2)
  885. {
  886. if (map[m].flag.snow)
  887. clif_weather_sub(fd, sd->bl.id, 162);
  888. if (map[m].flag.clouds)
  889. clif_weather_sub(fd, sd->bl.id, 233);
  890. if (map[m].flag.clouds2)
  891. clif_weather_sub(fd, sd->bl.id, 516);
  892. if (map[m].flag.fog)
  893. clif_weather_sub(fd, sd->bl.id, 515);
  894. if (map[m].flag.fireworks) {
  895. clif_weather_sub(fd, sd->bl.id, 297);
  896. clif_weather_sub(fd, sd->bl.id, 299);
  897. clif_weather_sub(fd, sd->bl.id, 301);
  898. }
  899. if (map[m].flag.sakura)
  900. clif_weather_sub(fd, sd->bl.id, 163);
  901. if (map[m].flag.leaves)
  902. clif_weather_sub(fd, sd->bl.id, 333);
  903. if (map[m].flag.rain)
  904. clif_weather_sub(fd, sd->bl.id, 161);
  905. }
  906. }
  907. void clif_weather(int m)
  908. {
  909. struct s_mapiterator* iter;
  910. struct map_session_data *sd=NULL;
  911. iter = mapit_getallusers();
  912. for( sd = (struct map_session_data*)mapit_first(iter); mapit_exists(iter); sd = (struct map_session_data*)mapit_next(iter) )
  913. {
  914. if( sd->bl.m == m )
  915. clif_weather_check(sd);
  916. }
  917. mapit_free(iter);
  918. }
  919. int clif_spawn(struct block_list *bl)
  920. {
  921. unsigned char buf[128];
  922. struct view_data *vd;
  923. int len;
  924. vd = status_get_viewdata(bl);
  925. if( !vd || vd->class_ == INVISIBLE_CLASS )
  926. return 0;
  927. len = clif_set_unit_idle(bl, buf,true);
  928. clif_send(buf, len, bl, AREA_WOS);
  929. if (disguised(bl))
  930. clif_setdisguise(bl, buf, len);
  931. if (vd->cloth_color)
  932. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  933. switch (bl->type)
  934. {
  935. case BL_PC:
  936. {
  937. TBL_PC *sd = ((TBL_PC*)bl);
  938. if (sd->spiritball > 0)
  939. clif_spiritball(sd);
  940. if(sd->state.size==2) // tiny/big players [Valaris]
  941. clif_specialeffect(bl,423,AREA);
  942. else if(sd->state.size==1)
  943. clif_specialeffect(bl,421,AREA);
  944. }
  945. break;
  946. case BL_MOB:
  947. {
  948. TBL_MOB *md = ((TBL_MOB*)bl);
  949. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  950. clif_specialeffect(&md->bl,423,AREA);
  951. else if(md->special_state.size==1)
  952. clif_specialeffect(&md->bl,421,AREA);
  953. }
  954. break;
  955. case BL_NPC:
  956. {
  957. TBL_NPC *nd = ((TBL_NPC*)bl);
  958. if( nd->size == 2 )
  959. clif_specialeffect(&nd->bl,423,AREA);
  960. else if( nd->size == 1 )
  961. clif_specialeffect(&nd->bl,421,AREA);
  962. }
  963. break;
  964. case BL_PET:
  965. if (vd->head_bottom)
  966. clif_pet_equip_area((TBL_PET*)bl); // needed to display pet equip properly
  967. break;
  968. }
  969. return 0;
  970. }
  971. //[orn]
  972. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  973. {
  974. struct status_data *status;
  975. unsigned char buf[128];
  976. nullpo_retr(0, hd);
  977. status = &hd->battle_status;
  978. memset(buf,0,packet_len(0x22e));
  979. WBUFW(buf,0)=0x22e;
  980. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  981. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  982. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  983. WBUFW(buf,27)=hd->homunculus.level;
  984. WBUFW(buf,29)=hd->homunculus.hunger;
  985. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  986. WBUFW(buf,33)=0; // equip id
  987. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, SHRT_MAX);
  988. WBUFW(buf,37)=cap_value(status->matk_max, 0, SHRT_MAX);
  989. WBUFW(buf,39)=status->hit;
  990. if (battle_config.hom_setting&0x10)
  991. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  992. else
  993. WBUFW(buf,41)=status->cri/10;
  994. WBUFW(buf,43)=status->def + status->vit ;
  995. WBUFW(buf,45)=status->mdef;
  996. WBUFW(buf,47)=status->flee;
  997. WBUFW(buf,49)=(flag)?0:status->amotion;
  998. if (status->max_hp > SHRT_MAX) {
  999. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1000. WBUFW(buf,53) = 100;
  1001. } else {
  1002. WBUFW(buf,51)=status->hp;
  1003. WBUFW(buf,53)=status->max_hp;
  1004. }
  1005. if (status->max_sp > SHRT_MAX) {
  1006. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1007. WBUFW(buf,57) = 100;
  1008. } else {
  1009. WBUFW(buf,55)=status->sp;
  1010. WBUFW(buf,57)=status->max_sp;
  1011. }
  1012. WBUFL(buf,59)=hd->homunculus.exp;
  1013. WBUFL(buf,63)=hd->exp_next;
  1014. WBUFW(buf,67)=hd->homunculus.skillpts;
  1015. WBUFW(buf,69)=2; // FIXME: undocumented flag, seems to be '2' all the time [ultramage]
  1016. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1017. return 0;
  1018. }
  1019. void clif_send_homdata(struct map_session_data *sd, int type, int param)
  1020. { //[orn]
  1021. int fd = sd->fd;
  1022. WFIFOHEAD(fd, packet_len(0x230));
  1023. nullpo_retv(sd->hd);
  1024. WFIFOW(fd,0)=0x230;
  1025. WFIFOW(fd,2)=type;
  1026. WFIFOL(fd,4)=sd->hd->bl.id;
  1027. WFIFOL(fd,8)=param;
  1028. WFIFOSET(fd,packet_len(0x230));
  1029. return;
  1030. }
  1031. int clif_homskillinfoblock(struct map_session_data *sd)
  1032. { //[orn]
  1033. struct homun_data *hd;
  1034. int fd = sd->fd;
  1035. int i,j,len=4,id;
  1036. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1037. hd = sd->hd;
  1038. if ( !hd )
  1039. return 0 ;
  1040. WFIFOW(fd,0)=0x235;
  1041. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1042. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1043. j = id - HM_SKILLBASE;
  1044. WFIFOW(fd,len ) = id;
  1045. WFIFOW(fd,len+2) = skill_get_inf(id);
  1046. WFIFOW(fd,len+4) = 0;
  1047. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv;
  1048. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv);
  1049. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv);
  1050. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  1051. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1052. len+=37;
  1053. }
  1054. }
  1055. WFIFOW(fd,2)=len;
  1056. WFIFOSET(fd,len);
  1057. return 0;
  1058. }
  1059. void clif_homskillup(struct map_session_data *sd, int skill_num)
  1060. { //[orn]
  1061. struct homun_data *hd;
  1062. int fd=sd->fd, skillid;
  1063. WFIFOHEAD(fd, packet_len(0x239));
  1064. nullpo_retv(sd);
  1065. skillid = skill_num - HM_SKILLBASE;
  1066. hd=sd->hd;
  1067. WFIFOW(fd,0) = 0x239;
  1068. WFIFOW(fd,2) = skill_num;
  1069. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1070. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1071. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1072. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1073. WFIFOSET(fd,packet_len(0x239));
  1074. return;
  1075. }
  1076. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1077. {
  1078. int fd=sd->fd;
  1079. WFIFOHEAD(fd,packet_len(0x22f));
  1080. WFIFOW(fd,0)=0x22f;
  1081. WFIFOB(fd,2)=fail;
  1082. WFIFOW(fd,3)=foodid;
  1083. WFIFOSET(fd,packet_len(0x22f));
  1084. return 0;
  1085. }
  1086. /*==========================================
  1087. *
  1088. *------------------------------------------*/
  1089. int clif_walkok(struct map_session_data *sd)
  1090. {
  1091. int fd=sd->fd;
  1092. WFIFOHEAD(fd, packet_len(0x87));
  1093. WFIFOW(fd,0)=0x87;
  1094. WFIFOL(fd,2)=gettick();
  1095. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1096. WFIFOSET(fd,packet_len(0x87));
  1097. return 0;
  1098. }
  1099. static void clif_move2(struct block_list *bl, struct view_data *vd, struct unit_data *ud)
  1100. {
  1101. uint8 buf[128];
  1102. int len;
  1103. len = clif_set_unit_walking(bl,ud,buf);
  1104. clif_send(buf,len,bl,AREA_WOS);
  1105. if (disguised(bl))
  1106. clif_setdisguise(bl, buf, len);
  1107. if(vd->cloth_color)
  1108. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1109. switch(bl->type)
  1110. {
  1111. case BL_PC:
  1112. {
  1113. TBL_PC *sd = ((TBL_PC*)bl);
  1114. // clif_movepc(sd);
  1115. if(sd->state.size==2) // tiny/big players [Valaris]
  1116. clif_specialeffect(&sd->bl,423,AREA);
  1117. else if(sd->state.size==1)
  1118. clif_specialeffect(&sd->bl,421,AREA);
  1119. }
  1120. break;
  1121. case BL_MOB:
  1122. {
  1123. TBL_MOB *md = ((TBL_MOB*)bl);
  1124. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1125. clif_specialeffect(&md->bl,423,AREA);
  1126. else if(md->special_state.size==1)
  1127. clif_specialeffect(&md->bl,421,AREA);
  1128. }
  1129. break;
  1130. }
  1131. return;
  1132. }
  1133. /// Move the unit (does nothing if the client has no info about the unit)
  1134. /// Note: unit must not be self
  1135. void clif_move(struct unit_data *ud)
  1136. {
  1137. unsigned char buf[16];
  1138. struct view_data* vd;
  1139. struct block_list* bl = ud->bl;
  1140. vd = status_get_viewdata(bl);
  1141. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1142. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1143. if (ud->state.speed_changed) {
  1144. // Since we don't know how to update the speed of other objects,
  1145. // use the old walk packet to update the data.
  1146. ud->state.speed_changed = 0;
  1147. clif_move2(bl, vd, ud);
  1148. return;
  1149. }
  1150. WBUFW(buf,0)=0x86;
  1151. WBUFL(buf,2)=bl->id;
  1152. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1153. WBUFL(buf,12)=gettick();
  1154. clif_send(buf, 16, bl, AREA_WOS);
  1155. if (disguised(bl))
  1156. {
  1157. WBUFL(buf,2)=-bl->id;
  1158. clif_send(buf, 16, bl, SELF);
  1159. }
  1160. }
  1161. /*==========================================
  1162. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1163. *------------------------------------------*/
  1164. static int clif_delayquit(int tid, unsigned int tick, int id, intptr data)
  1165. {
  1166. struct map_session_data *sd = NULL;
  1167. //Remove player from map server
  1168. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1169. map_quit(sd);
  1170. return 0;
  1171. }
  1172. /*==========================================
  1173. *
  1174. *------------------------------------------*/
  1175. void clif_quitsave(int fd,struct map_session_data *sd)
  1176. {
  1177. if (!battle_config.prevent_logout ||
  1178. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1179. map_quit(sd);
  1180. else if (sd->fd)
  1181. { //Disassociate session from player (session is deleted after this function was called)
  1182. //And set a timer to make him quit later.
  1183. session[sd->fd]->session_data = NULL;
  1184. sd->fd = 0;
  1185. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1186. }
  1187. }
  1188. /*==========================================
  1189. *
  1190. *------------------------------------------*/
  1191. void clif_changemap(struct map_session_data *sd, short map, int x, int y)
  1192. {
  1193. int fd;
  1194. nullpo_retv(sd);
  1195. fd = sd->fd;
  1196. WFIFOHEAD(fd,packet_len(0x91));
  1197. WFIFOW(fd,0) = 0x91;
  1198. mapindex_getmapname_ext(mapindex_id2name(map), (char*)WFIFOP(fd,2));
  1199. WFIFOW(fd,18) = x;
  1200. WFIFOW(fd,20) = y;
  1201. WFIFOSET(fd,packet_len(0x91));
  1202. }
  1203. /*==========================================
  1204. * Tells the client to connect to another map-server
  1205. *------------------------------------------*/
  1206. void clif_changemapserver(struct map_session_data* sd, unsigned short map_index, int x, int y, uint32 ip, uint16 port)
  1207. {
  1208. int fd;
  1209. nullpo_retv(sd);
  1210. fd = sd->fd;
  1211. WFIFOHEAD(fd,packet_len(0x92));
  1212. WFIFOW(fd,0) = 0x92;
  1213. mapindex_getmapname_ext(mapindex_id2name(map_index), (char*)WFIFOP(fd,2));
  1214. WFIFOW(fd,18) = x;
  1215. WFIFOW(fd,20) = y;
  1216. WFIFOL(fd,22) = htonl(ip);
  1217. WFIFOW(fd,26) = ntows(htons(port)); // [!] LE byte order here [!]
  1218. WFIFOSET(fd,packet_len(0x92));
  1219. }
  1220. void clif_blown(struct block_list *bl)
  1221. {
  1222. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1223. // clif_fixpos(bl);
  1224. clif_slide(bl, bl->x, bl->y);
  1225. }
  1226. /*==========================================
  1227. *
  1228. *------------------------------------------*/
  1229. void clif_fixpos(struct block_list *bl)
  1230. {
  1231. unsigned char buf[10];
  1232. nullpo_retv(bl);
  1233. WBUFW(buf,0) = 0x88;
  1234. WBUFL(buf,2) = bl->id;
  1235. WBUFW(buf,6) = bl->x;
  1236. WBUFW(buf,8) = bl->y;
  1237. clif_send(buf, packet_len(0x88), bl, AREA);
  1238. if( disguised(bl) )
  1239. {
  1240. WBUFL(buf,2) = -bl->id;
  1241. clif_send(buf, packet_len(0x88), bl, SELF);
  1242. }
  1243. }
  1244. /*==========================================
  1245. *
  1246. *------------------------------------------*/
  1247. int clif_npcbuysell(struct map_session_data* sd, int id)
  1248. {
  1249. int fd;
  1250. nullpo_retr(0, sd);
  1251. fd=sd->fd;
  1252. WFIFOHEAD(fd, packet_len(0xc4));
  1253. WFIFOW(fd,0)=0xc4;
  1254. WFIFOL(fd,2)=id;
  1255. WFIFOSET(fd,packet_len(0xc4));
  1256. return 0;
  1257. }
  1258. /*==========================================
  1259. *
  1260. *------------------------------------------*/
  1261. int clif_buylist(struct map_session_data *sd, struct npc_data *nd)
  1262. {
  1263. int fd,i,c;
  1264. nullpo_retr(0, sd);
  1265. nullpo_retr(0, nd);
  1266. fd = sd->fd;
  1267. WFIFOHEAD(fd, 4 + nd->u.shop.count * 11);
  1268. WFIFOW(fd,0) = 0xc6;
  1269. c = 0;
  1270. for( i = 0; i < nd->u.shop.count; i++ )
  1271. {
  1272. struct item_data* id = itemdb_exists(nd->u.shop.shop_item[i].nameid);
  1273. int val = nd->u.shop.shop_item[i].value;
  1274. if( id == NULL )
  1275. continue;
  1276. WFIFOL(fd, 4+c*11) = val;
  1277. if (!id->flag.value_notdc)
  1278. val = pc_modifybuyvalue(sd,val);
  1279. WFIFOL(fd, 8+c*11) = val;
  1280. WFIFOB(fd,12+c*11) = itemtype(id->type);
  1281. WFIFOW(fd,13+c*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  1282. c++;
  1283. }
  1284. WFIFOW(fd,2) = 4 + c*11;
  1285. WFIFOSET(fd,WFIFOW(fd,2));
  1286. return 0;
  1287. }
  1288. /*==========================================
  1289. *
  1290. *------------------------------------------*/
  1291. int clif_selllist(struct map_session_data *sd)
  1292. {
  1293. int fd,i,c=0,val;
  1294. nullpo_retr(0, sd);
  1295. fd=sd->fd;
  1296. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1297. WFIFOW(fd,0)=0xc7;
  1298. for( i = 0; i < MAX_INVENTORY; i++ )
  1299. {
  1300. if( sd->status.inventory[i].nameid > 0 && sd->inventory_data[i] )
  1301. {
  1302. if( !itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)) )
  1303. continue;
  1304. if( sd->status.inventory[i].expire_time )
  1305. continue; // Cannot Sell Rental Items
  1306. val=sd->inventory_data[i]->value_sell;
  1307. if( val < 0 )
  1308. continue;
  1309. WFIFOW(fd,4+c*10)=i+2;
  1310. WFIFOL(fd,6+c*10)=val;
  1311. if( !sd->inventory_data[i]->flag.value_notoc )
  1312. val=pc_modifysellvalue(sd,val);
  1313. WFIFOL(fd,10+c*10)=val;
  1314. c++;
  1315. }
  1316. }
  1317. WFIFOW(fd,2)=c*10+4;
  1318. WFIFOSET(fd,WFIFOW(fd,2));
  1319. return 0;
  1320. }
  1321. /*==========================================
  1322. *
  1323. *------------------------------------------*/
  1324. int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes)
  1325. {
  1326. int fd = sd->fd;
  1327. int slen = strlen(mes) + 9;
  1328. WFIFOHEAD(fd, slen);
  1329. WFIFOW(fd,0)=0xb4;
  1330. WFIFOW(fd,2)=slen;
  1331. WFIFOL(fd,4)=npcid;
  1332. strcpy((char*)WFIFOP(fd,8),mes);
  1333. WFIFOSET(fd,WFIFOW(fd,2));
  1334. return 0;
  1335. }
  1336. /*==========================================
  1337. *
  1338. *------------------------------------------*/
  1339. int clif_scriptnext(struct map_session_data *sd,int npcid)
  1340. {
  1341. int fd;
  1342. nullpo_retr(0, sd);
  1343. fd=sd->fd;
  1344. WFIFOHEAD(fd, packet_len(0xb5));
  1345. WFIFOW(fd,0)=0xb5;
  1346. WFIFOL(fd,2)=npcid;
  1347. WFIFOSET(fd,packet_len(0xb5));
  1348. return 0;
  1349. }
  1350. /*==========================================
  1351. *
  1352. *------------------------------------------*/
  1353. int clif_scriptclose(struct map_session_data *sd, int npcid)
  1354. {
  1355. int fd;
  1356. nullpo_retr(0, sd);
  1357. fd=sd->fd;
  1358. WFIFOHEAD(fd, packet_len(0xb6));
  1359. WFIFOW(fd,0)=0xb6;
  1360. WFIFOL(fd,2)=npcid;
  1361. WFIFOSET(fd,packet_len(0xb6));
  1362. return 0;
  1363. }
  1364. /*==========================================
  1365. *
  1366. *------------------------------------------*/
  1367. void clif_sendfakenpc(struct map_session_data *sd, int npcid)
  1368. {
  1369. unsigned char *buf;
  1370. int fd = sd->fd;
  1371. sd->state.using_fake_npc = 1;
  1372. WFIFOHEAD(fd, packet_len(0x78));
  1373. buf = WFIFOP(fd,0);
  1374. memset(WBUFP(buf,0), 0, packet_len(0x78));
  1375. WBUFW(buf,0)=0x78;
  1376. #if PACKETVER >= 20071106
  1377. WBUFB(buf,2) = 0; //Unknown bit
  1378. buf = WFIFOP(fd,1);
  1379. #endif
  1380. WBUFL(buf,2)=npcid;
  1381. WBUFW(buf,14)=111;
  1382. WBUFPOS(buf,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1383. WBUFB(buf,49)=5;
  1384. WBUFB(buf,50)=5;
  1385. WFIFOSET(fd, packet_len(0x78));
  1386. return;
  1387. }
  1388. /*==========================================
  1389. *
  1390. *------------------------------------------*/
  1391. int clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes)
  1392. {
  1393. int fd = sd->fd;
  1394. int slen = strlen(mes) + 8;
  1395. struct block_list *bl = NULL;
  1396. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1397. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1398. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1399. clif_sendfakenpc(sd, npcid);
  1400. WFIFOHEAD(fd, slen);
  1401. WFIFOW(fd,0)=0xb7;
  1402. WFIFOW(fd,2)=slen;
  1403. WFIFOL(fd,4)=npcid;
  1404. strcpy((char*)WFIFOP(fd,8),mes);
  1405. WFIFOSET(fd,WFIFOW(fd,2));
  1406. return 0;
  1407. }
  1408. /*==========================================
  1409. *
  1410. *------------------------------------------*/
  1411. int clif_scriptinput(struct map_session_data *sd, int npcid)
  1412. {
  1413. int fd;
  1414. struct block_list *bl = NULL;
  1415. nullpo_retr(0, sd);
  1416. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1417. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1418. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1419. clif_sendfakenpc(sd, npcid);
  1420. fd=sd->fd;
  1421. WFIFOHEAD(fd, packet_len(0x142));
  1422. WFIFOW(fd,0)=0x142;
  1423. WFIFOL(fd,2)=npcid;
  1424. WFIFOSET(fd,packet_len(0x142));
  1425. return 0;
  1426. }
  1427. /*==========================================
  1428. *
  1429. *------------------------------------------*/
  1430. int clif_scriptinputstr(struct map_session_data *sd, int npcid)
  1431. {
  1432. int fd;
  1433. struct block_list *bl = NULL;
  1434. nullpo_retr(0, sd);
  1435. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1436. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1437. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1438. clif_sendfakenpc(sd, npcid);
  1439. fd=sd->fd;
  1440. WFIFOHEAD(fd, packet_len(0x1d4));
  1441. WFIFOW(fd,0)=0x1d4;
  1442. WFIFOL(fd,2)=npcid;
  1443. WFIFOSET(fd,packet_len(0x1d4));
  1444. return 0;
  1445. }
  1446. /// npc_id is ignored in the client
  1447. /// type=2 : Remove viewpoint
  1448. /// type=other : Show viewpoint
  1449. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color)
  1450. {
  1451. int fd;
  1452. nullpo_retr(0, sd);
  1453. fd=sd->fd;
  1454. WFIFOHEAD(fd, packet_len(0x144));
  1455. WFIFOW(fd,0)=0x144;
  1456. WFIFOL(fd,2)=npc_id;
  1457. WFIFOL(fd,6)=type;
  1458. WFIFOL(fd,10)=x;
  1459. WFIFOL(fd,14)=y;
  1460. WFIFOB(fd,18)=id;
  1461. WFIFOL(fd,19)=color;
  1462. WFIFOSET(fd,packet_len(0x144));
  1463. return 0;
  1464. }
  1465. /*==========================================
  1466. *
  1467. *------------------------------------------*/
  1468. int clif_cutin(struct map_session_data* sd, const char* image, int type)
  1469. {
  1470. int fd;
  1471. nullpo_retr(0, sd);
  1472. fd=sd->fd;
  1473. WFIFOHEAD(fd, packet_len(0x1b3));
  1474. WFIFOW(fd,0)=0x1b3;
  1475. strncpy((char*)WFIFOP(fd,2),image,64);
  1476. WFIFOB(fd,66)=type;
  1477. WFIFOSET(fd,packet_len(0x1b3));
  1478. return 0;
  1479. }
  1480. /*==========================================
  1481. * Fills in card data from the given item and into the buffer. [Skotlex]
  1482. *------------------------------------------*/
  1483. static void clif_addcards(unsigned char* buf, struct item* item)
  1484. {
  1485. int i=0,j;
  1486. if( item == NULL ) { //Blank data
  1487. WBUFW(buf,0) = 0;
  1488. WBUFW(buf,2) = 0;
  1489. WBUFW(buf,4) = 0;
  1490. WBUFW(buf,6) = 0;
  1491. return;
  1492. }
  1493. if( item->card[0] == CARD0_PET ) { //pet eggs
  1494. WBUFW(buf,0) = 0;
  1495. WBUFW(buf,2) = 0;
  1496. WBUFW(buf,4) = 0;
  1497. WBUFW(buf,6) = item->card[3]; //Pet renamed flag.
  1498. return;
  1499. }
  1500. if( item->card[0] == CARD0_FORGE || item->card[0] == CARD0_CREATE ) { //Forged/created items
  1501. WBUFW(buf,0) = item->card[0];
  1502. WBUFW(buf,2) = item->card[1];
  1503. WBUFW(buf,4) = item->card[2];
  1504. WBUFW(buf,6) = item->card[3];
  1505. return;
  1506. }
  1507. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1508. if( MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4 )
  1509. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1510. //Normal items.
  1511. if( item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1512. WBUFW(buf,0) = j;
  1513. else
  1514. WBUFW(buf,0) = item->card[i];
  1515. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1516. WBUFW(buf,2) = j;
  1517. else
  1518. WBUFW(buf,2) = item->card[i];
  1519. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1520. WBUFW(buf,4) = j;
  1521. else
  1522. WBUFW(buf,4) = item->card[i];
  1523. if( item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0 )
  1524. WBUFW(buf,6) = j;
  1525. else
  1526. WBUFW(buf,6) = item->card[i];
  1527. }
  1528. /*==========================================
  1529. *
  1530. *------------------------------------------*/
  1531. int clif_additem(struct map_session_data *sd, int n, int amount, int fail)
  1532. {
  1533. int fd;
  1534. nullpo_retr(0, sd);
  1535. fd = sd->fd;
  1536. if (!session_isActive(fd)) //Sasuke-
  1537. return 0;
  1538. WFIFOHEAD(fd,packet_len(0xa0));
  1539. if(fail) {
  1540. WFIFOW(fd,0)=0xa0;
  1541. WFIFOW(fd,2)=n+2;
  1542. WFIFOW(fd,4)=amount;
  1543. WFIFOW(fd,6)=0;
  1544. WFIFOB(fd,8)=0;
  1545. WFIFOB(fd,9)=0;
  1546. WFIFOB(fd,10)=0;
  1547. WFIFOW(fd,11)=0;
  1548. WFIFOW(fd,13)=0;
  1549. WFIFOW(fd,15)=0;
  1550. WFIFOW(fd,17)=0;
  1551. WFIFOW(fd,19)=0;
  1552. WFIFOB(fd,21)=0;
  1553. WFIFOB(fd,22)=fail;
  1554. } else {
  1555. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1556. return 1;
  1557. WFIFOW(fd,0)=0xa0;
  1558. WFIFOW(fd,2)=n+2;
  1559. WFIFOW(fd,4)=amount;
  1560. if (sd->inventory_data[n]->view_id > 0)
  1561. WFIFOW(fd,6)=sd->inventory_data[n]->view_id;
  1562. else
  1563. WFIFOW(fd,6)=sd->status.inventory[n].nameid;
  1564. WFIFOB(fd,8)=sd->status.inventory[n].identify;
  1565. WFIFOB(fd,9)=sd->status.inventory[n].attribute;
  1566. WFIFOB(fd,10)=sd->status.inventory[n].refine;
  1567. clif_addcards(WFIFOP(fd,11), &sd->status.inventory[n]);
  1568. WFIFOW(fd,19)=pc_equippoint(sd,n);
  1569. WFIFOB(fd,21)=itemtype(sd->inventory_data[n]->type);
  1570. WFIFOB(fd,22)=fail;
  1571. }
  1572. WFIFOSET(fd,packet_len(0xa0));
  1573. return 0;
  1574. }
  1575. /*==========================================
  1576. *
  1577. *------------------------------------------*/
  1578. int clif_delitem(struct map_session_data *sd,int n,int amount)
  1579. {
  1580. int fd;
  1581. nullpo_retr(0, sd);
  1582. fd=sd->fd;
  1583. WFIFOHEAD(fd, packet_len(0xaf));
  1584. WFIFOW(fd,0)=0xaf;
  1585. WFIFOW(fd,2)=n+2;
  1586. WFIFOW(fd,4)=amount;
  1587. WFIFOSET(fd,packet_len(0xaf));
  1588. return 0;
  1589. }
  1590. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1591. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1592. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1593. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1594. {
  1595. if (id->view_id > 0)
  1596. WBUFW(buf,n)=id->view_id;
  1597. else
  1598. WBUFW(buf,n)=i->nameid;
  1599. WBUFB(buf,n+2)=itemtype(id->type);
  1600. WBUFB(buf,n+3)=i->identify;
  1601. if (equip >= 0) { //Equippable item
  1602. WBUFW(buf,n+4)=equip;
  1603. WBUFW(buf,n+6)=i->equip;
  1604. WBUFB(buf,n+8)=i->attribute;
  1605. WBUFB(buf,n+9)=i->refine;
  1606. } else { //Stackable item.
  1607. WBUFW(buf,n+4)=i->amount;
  1608. if (equip == -2 && id->equip == EQP_AMMO)
  1609. WBUFW(buf,n+6)=EQP_AMMO;
  1610. else
  1611. WBUFW(buf,n+6)=0;
  1612. }
  1613. }
  1614. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1615. void clif_inventorylist(struct map_session_data *sd)
  1616. {
  1617. int i,n,ne,fd = sd->fd,arrow=-1;
  1618. unsigned char *buf;
  1619. unsigned char bufe[MAX_INVENTORY*20+4];
  1620. #if PACKETVER < 5
  1621. const int s = 10; //Entry size.
  1622. #else
  1623. const int s = 18;
  1624. #endif
  1625. WFIFOHEAD(fd, MAX_INVENTORY * s + 4);
  1626. buf = WFIFOP(fd,0);
  1627. for(i=0,n=0,ne=0;i<MAX_INVENTORY;i++){
  1628. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1629. continue;
  1630. if(!itemdb_isstackable2(sd->inventory_data[i]))
  1631. { //Non-stackable (Equippable)
  1632. WBUFW(bufe,ne*20+4)=i+2;
  1633. clif_item_sub(bufe, ne*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1634. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.inventory[i]);
  1635. ne++;
  1636. } else { //Stackable.
  1637. WBUFW(buf,n*s+4)=i+2;
  1638. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1639. if (sd->inventory_data[i]->equip == EQP_AMMO &&
  1640. sd->status.inventory[i].equip)
  1641. arrow=i;
  1642. #if PACKETVER >= 5
  1643. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1644. #endif
  1645. n++;
  1646. }
  1647. }
  1648. if (n) {
  1649. #if PACKETVER < 5
  1650. WBUFW(buf,0)=0xa3;
  1651. #else
  1652. WBUFW(buf,0)=0x1ee;
  1653. #endif
  1654. WBUFW(buf,2)=4+n*s;
  1655. WFIFOSET(fd,WFIFOW(fd,2));
  1656. }
  1657. if(arrow >= 0)
  1658. clif_arrowequip(sd,arrow);
  1659. if(ne){
  1660. WBUFW(bufe,0)=0xa4;
  1661. WBUFW(bufe,2)=4+ne*20;
  1662. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1663. }
  1664. }
  1665. //Required when items break/get-repaired. Only sends equippable item list.
  1666. void clif_equiplist(struct map_session_data *sd)
  1667. {
  1668. int i,n,fd = sd->fd;
  1669. unsigned char *buf;
  1670. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  1671. buf = WFIFOP(fd,0);
  1672. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1673. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1674. continue;
  1675. if(itemdb_isstackable2(sd->inventory_data[i]))
  1676. continue;
  1677. //Equippable
  1678. WBUFW(buf,n*20+4)=i+2;
  1679. clif_item_sub(buf, n*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1680. clif_addcards(WBUFP(buf, n*20+16), &sd->status.inventory[i]);
  1681. n++;
  1682. }
  1683. if (n) {
  1684. WBUFW(buf,0)=0xa4;
  1685. WBUFW(buf,2)=4+n*20;
  1686. WFIFOSET(fd,WFIFOW(fd,2));
  1687. }
  1688. }
  1689. void clif_storagelist(struct map_session_data* sd, struct storage_data* stor)
  1690. {
  1691. struct item_data *id;
  1692. int i,n,ne,fd=sd->fd;
  1693. unsigned char *buf;
  1694. unsigned char bufe[MAX_STORAGE*20+4];
  1695. #if PACKETVER < 5
  1696. const int s = 10; //Entry size.
  1697. #else
  1698. const int s = 18;
  1699. #endif
  1700. WFIFOHEAD(fd,MAX_STORAGE * s + 4);
  1701. buf = WFIFOP(fd,0);
  1702. for(i=0,n=0,ne=0;i<MAX_STORAGE;i++){
  1703. if(stor->items[i].nameid<=0)
  1704. continue;
  1705. id = itemdb_search(stor->items[i].nameid);
  1706. if(!itemdb_isstackable2(id))
  1707. { //Equippable
  1708. WBUFW(bufe,ne*20+4)=i+1;
  1709. clif_item_sub(bufe, ne*20+6, &stor->items[i], id, id->equip);
  1710. clif_addcards(WBUFP(bufe, ne*20+16), &stor->items[i]);
  1711. ne++;
  1712. } else { //Stackable
  1713. WBUFW(buf,n*s+4)=i+1;
  1714. clif_item_sub(buf, n*s+6, &stor->items[i], id,-1);
  1715. #if PACKETVER >= 5
  1716. clif_addcards(WBUFP(buf,n*s+14), &stor->items[i]);
  1717. #endif
  1718. n++;
  1719. }
  1720. }
  1721. if(n){
  1722. #if PACKETVER < 5
  1723. WBUFW(buf,0)=0xa5;
  1724. #else
  1725. WBUFW(buf,0)=0x1f0;
  1726. #endif
  1727. WBUFW(buf,2)=4+n*s;
  1728. WFIFOSET(fd,WFIFOW(fd,2));
  1729. }
  1730. if(ne){
  1731. WBUFW(bufe,0)=0xa6;
  1732. WBUFW(bufe,2)=4+ne*20;
  1733. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1734. }
  1735. }
  1736. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1737. void clif_guildstoragelist(struct map_session_data *sd,struct guild_storage *stor)
  1738. {
  1739. struct item_data *id;
  1740. int i,n,ne,fd=sd->fd;
  1741. unsigned char *buf;
  1742. unsigned char bufe[MAX_GUILD_STORAGE*20+4];
  1743. #if PACKETVER < 5
  1744. const int s = 10; //Entry size.
  1745. #else
  1746. const int s = 18;
  1747. #endif
  1748. WFIFOHEAD(fd,MAX_GUILD_STORAGE * s + 4);
  1749. buf = WFIFOP(fd,0);
  1750. for(i=0,n=0,ne=0;i<MAX_GUILD_STORAGE;i++){
  1751. if(stor->storage_[i].nameid<=0)
  1752. continue;
  1753. id = itemdb_search(stor->storage_[i].nameid);
  1754. if(!itemdb_isstackable2(id))
  1755. { //Equippable
  1756. WBUFW(bufe,ne*20+4)=i+1;
  1757. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  1758. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  1759. ne++;
  1760. } else { //Stackable
  1761. WBUFW(buf,n*s+4)=i+1;
  1762. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  1763. #if PACKETVER >= 5
  1764. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  1765. #endif
  1766. n++;
  1767. }
  1768. }
  1769. if(n){
  1770. #if PACKETVER < 5
  1771. WBUFW(buf,0)=0xa5;
  1772. #else
  1773. WBUFW(buf,0)=0x1f0;
  1774. #endif
  1775. WBUFW(buf,2)=4+n*s;
  1776. WFIFOSET(fd,WFIFOW(fd,2));
  1777. }
  1778. if(ne){
  1779. WBUFW(bufe,0)=0xa6;
  1780. WBUFW(bufe,2)=4+ne*20;
  1781. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1782. }
  1783. }
  1784. void clif_cartlist(struct map_session_data *sd)
  1785. {
  1786. struct item_data *id;
  1787. int i,n,ne,fd=sd->fd;
  1788. unsigned char *buf;
  1789. unsigned char bufe[MAX_CART*20+4];
  1790. #if PACKETVER < 5
  1791. const int s = 10; //Entry size.
  1792. #else
  1793. const int s = 18;
  1794. #endif
  1795. WFIFOHEAD(fd, MAX_CART * s + 4);
  1796. buf = WFIFOP(fd,0);
  1797. for(i=0,n=0,ne=0;i<MAX_CART;i++){
  1798. if(sd->status.cart[i].nameid<=0)
  1799. continue;
  1800. id = itemdb_search(sd->status.cart[i].nameid);
  1801. if(!itemdb_isstackable2(id))
  1802. { //Equippable
  1803. WBUFW(bufe,ne*20+4)=i+2;
  1804. clif_item_sub(bufe, ne*20+6, &sd->status.cart[i], id, id->equip);
  1805. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.cart[i]);
  1806. ne++;
  1807. } else { //Stackable
  1808. WBUFW(buf,n*s+4)=i+2;
  1809. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  1810. #if PACKETVER >= 5
  1811. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  1812. #endif
  1813. n++;
  1814. }
  1815. }
  1816. if(n){
  1817. #if PACKETVER < 5
  1818. WBUFW(buf,0)=0x123;
  1819. #else
  1820. WBUFW(buf,0)=0x1ef;
  1821. #endif
  1822. WBUFW(buf,2)=4+n*s;
  1823. WFIFOSET(fd,WFIFOW(fd,2));
  1824. }
  1825. if(ne){
  1826. WBUFW(bufe,0)=0x122;
  1827. WBUFW(bufe,2)=4+ne*20;
  1828. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1829. }
  1830. return;
  1831. }
  1832. /// Client behaviour:
  1833. /// Closes the cart storage and removes all it's items from memory.
  1834. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  1835. void clif_clearcart(int fd)
  1836. {
  1837. WFIFOHEAD(fd, packet_len(0x12b));
  1838. WFIFOW(fd,0) = 0x12b;
  1839. }
  1840. // Guild XY locators [Valaris]
  1841. int clif_guild_xy(struct map_session_data *sd)
  1842. {
  1843. unsigned char buf[10];
  1844. nullpo_retr(0, sd);
  1845. WBUFW(buf,0)=0x1eb;
  1846. WBUFL(buf,2)=sd->status.account_id;
  1847. WBUFW(buf,6)=sd->bl.x;
  1848. WBUFW(buf,8)=sd->bl.y;
  1849. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  1850. return 0;
  1851. }
  1852. /*==========================================
  1853. * Sends x/y dot to a single fd. [Skotlex]
  1854. *------------------------------------------*/
  1855. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  1856. {
  1857. if( sd->state.bg_id )
  1858. return 0;
  1859. WFIFOHEAD(fd,packet_len(0x1eb));
  1860. WFIFOW(fd,0)=0x1eb;
  1861. WFIFOL(fd,2)=sd->status.account_id;
  1862. WFIFOW(fd,6)=sd->bl.x;
  1863. WFIFOW(fd,8)=sd->bl.y;
  1864. WFIFOSET(fd,packet_len(0x1eb));
  1865. return 0;
  1866. }
  1867. // Guild XY locators [Valaris]
  1868. int clif_guild_xy_remove(struct map_session_data *sd)
  1869. {
  1870. unsigned char buf[10];
  1871. nullpo_retr(0, sd);
  1872. WBUFW(buf,0)=0x1eb;
  1873. WBUFL(buf,2)=sd->status.account_id;
  1874. WBUFW(buf,6)=-1;
  1875. WBUFW(buf,8)=-1;
  1876. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  1877. return 0;
  1878. }
  1879. /*==========================================
  1880. * ステータスを送りつける
  1881. * 表示専用数字はこの中で計算して送る
  1882. *------------------------------------------*/
  1883. int clif_updatestatus(struct map_session_data *sd,int type)
  1884. {
  1885. int fd,len=8;
  1886. nullpo_retr(0, sd);
  1887. fd=sd->fd;
  1888. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  1889. return 0;
  1890. WFIFOHEAD(fd, 14);
  1891. WFIFOW(fd,0)=0xb0;
  1892. WFIFOW(fd,2)=type;
  1893. switch(type){
  1894. // 00b0
  1895. case SP_WEIGHT:
  1896. pc_updateweightstatus(sd);
  1897. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  1898. WFIFOW(fd,2)=type;
  1899. WFIFOL(fd,4)=sd->weight;
  1900. break;
  1901. case SP_MAXWEIGHT:
  1902. WFIFOL(fd,4)=sd->max_weight;
  1903. break;
  1904. case SP_SPEED:
  1905. WFIFOL(fd,4)=sd->battle_status.speed;
  1906. break;
  1907. case SP_BASELEVEL:
  1908. WFIFOL(fd,4)=sd->status.base_level;
  1909. break;
  1910. case SP_JOBLEVEL:
  1911. WFIFOL(fd,4)=sd->status.job_level;
  1912. break;
  1913. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  1914. WFIFOL(fd,4)=sd->status.karma;
  1915. break;
  1916. case SP_MANNER:
  1917. WFIFOL(fd,4)=sd->status.manner;
  1918. break;
  1919. case SP_STATUSPOINT:
  1920. WFIFOL(fd,4)=sd->status.status_point;
  1921. break;
  1922. case SP_SKILLPOINT:
  1923. WFIFOL(fd,4)=sd->status.skill_point;
  1924. break;
  1925. case SP_HIT:
  1926. WFIFOL(fd,4)=sd->battle_status.hit;
  1927. break;
  1928. case SP_FLEE1:
  1929. WFIFOL(fd,4)=sd->battle_status.flee;
  1930. break;
  1931. case SP_FLEE2:
  1932. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  1933. break;
  1934. case SP_MAXHP:
  1935. WFIFOL(fd,4)=sd->battle_status.max_hp;
  1936. break;
  1937. case SP_MAXSP:
  1938. WFIFOL(fd,4)=sd->battle_status.max_sp;
  1939. break;
  1940. case SP_HP:
  1941. WFIFOL(fd,4)=sd->battle_status.hp;
  1942. if( battle_config.disp_hpmeter )
  1943. clif_hpmeter(sd);
  1944. if( !battle_config.party_hp_mode && sd->status.party_id )
  1945. clif_party_hp(sd);
  1946. if( sd->state.bg_id )
  1947. clif_bg_hp(sd);
  1948. break;
  1949. case SP_SP:
  1950. WFIFOL(fd,4)=sd->battle_status.sp;
  1951. break;
  1952. case SP_ASPD:
  1953. WFIFOL(fd,4)=sd->battle_status.amotion;
  1954. break;
  1955. case SP_ATK1:
  1956. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw.atk;
  1957. break;
  1958. case SP_DEF1:
  1959. WFIFOL(fd,4)=sd->battle_status.def;
  1960. break;
  1961. case SP_MDEF1:
  1962. WFIFOL(fd,4)=sd->battle_status.mdef;
  1963. break;
  1964. case SP_ATK2:
  1965. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2;
  1966. break;
  1967. case SP_DEF2:
  1968. WFIFOL(fd,4)=sd->battle_status.def2;
  1969. break;
  1970. case SP_MDEF2:
  1971. //negative check (in case you have something like Berserk active)
  1972. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  1973. if (len < 0) len = 0;
  1974. WFIFOL(fd,4)= len;
  1975. len = 8;
  1976. break;
  1977. case SP_CRITICAL:
  1978. WFIFOL(fd,4)=sd->battle_status.cri/10;
  1979. break;
  1980. case SP_MATK1:
  1981. WFIFOL(fd,4)=sd->battle_status.matk_max;
  1982. break;
  1983. case SP_MATK2:
  1984. WFIFOL(fd,4)=sd->battle_status.matk_min;
  1985. break;
  1986. case SP_ZENY:
  1987. WFIFOW(fd,0)=0xb1;
  1988. WFIFOL(fd,4)=sd->status.zeny;
  1989. break;
  1990. case SP_BASEEXP:
  1991. WFIFOW(fd,0)=0xb1;
  1992. WFIFOL(fd,4)=sd->status.base_exp;
  1993. break;
  1994. case SP_JOBEXP:
  1995. WFIFOW(fd,0)=0xb1;
  1996. WFIFOL(fd,4)=sd->status.job_exp;
  1997. break;
  1998. case SP_NEXTBASEEXP:
  1999. WFIFOW(fd,0)=0xb1;
  2000. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2001. break;
  2002. case SP_NEXTJOBEXP:
  2003. WFIFOW(fd,0)=0xb1;
  2004. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2005. break;
  2006. // 00be 終了
  2007. case SP_USTR:
  2008. case SP_UAGI:
  2009. case SP_UVIT:
  2010. case SP_UINT:
  2011. case SP_UDEX:
  2012. case SP_ULUK:
  2013. WFIFOW(fd,0)=0xbe;
  2014. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2015. len=5;
  2016. break;
  2017. // 013a 終了
  2018. case SP_ATTACKRANGE:
  2019. WFIFOW(fd,0)=0x13a;
  2020. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2021. len=4;
  2022. break;
  2023. // 0141 終了
  2024. case SP_STR:
  2025. WFIFOW(fd,0)=0x141;
  2026. WFIFOL(fd,2)=type;
  2027. WFIFOL(fd,6)=sd->status.str;
  2028. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2029. len=14;
  2030. break;
  2031. case SP_AGI:
  2032. WFIFOW(fd,0)=0x141;
  2033. WFIFOL(fd,2)=type;
  2034. WFIFOL(fd,6)=sd->status.agi;
  2035. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2036. len=14;
  2037. break;
  2038. case SP_VIT:
  2039. WFIFOW(fd,0)=0x141;
  2040. WFIFOL(fd,2)=type;
  2041. WFIFOL(fd,6)=sd->status.vit;
  2042. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2043. len=14;
  2044. break;
  2045. case SP_INT:
  2046. WFIFOW(fd,0)=0x141;
  2047. WFIFOL(fd,2)=type;
  2048. WFIFOL(fd,6)=sd->status.int_;
  2049. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2050. len=14;
  2051. break;
  2052. case SP_DEX:
  2053. WFIFOW(fd,0)=0x141;
  2054. WFIFOL(fd,2)=type;
  2055. WFIFOL(fd,6)=sd->status.dex;
  2056. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2057. len=14;
  2058. break;
  2059. case SP_LUK:
  2060. WFIFOW(fd,0)=0x141;
  2061. WFIFOL(fd,2)=type;
  2062. WFIFOL(fd,6)=sd->status.luk;
  2063. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2064. len=14;
  2065. break;
  2066. case SP_CARTINFO:
  2067. WFIFOW(fd,0)=0x121;
  2068. WFIFOW(fd,2)=sd->cart_num;
  2069. WFIFOW(fd,4)=MAX_CART;
  2070. WFIFOL(fd,6)=sd->cart_weight;
  2071. WFIFOL(fd,10)=battle_config.max_cart_weight;
  2072. len=14;
  2073. break;
  2074. default:
  2075. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2076. return 1;
  2077. }
  2078. WFIFOSET(fd,len);
  2079. return 0;
  2080. }
  2081. int clif_changestatus(struct block_list *bl,int type,int val)
  2082. {
  2083. unsigned char buf[12];
  2084. struct map_session_data *sd = NULL;
  2085. nullpo_retr(0, bl);
  2086. if(bl->type == BL_PC)
  2087. sd = (struct map_session_data *)bl;
  2088. if(sd){
  2089. WBUFW(buf,0)=0x1ab;
  2090. WBUFL(buf,2)=bl->id;
  2091. WBUFW(buf,6)=type;
  2092. switch(type){
  2093. case SP_MANNER:
  2094. WBUFL(buf,8)=val;
  2095. break;
  2096. default:
  2097. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2098. return 1;
  2099. }
  2100. clif_send(buf,packet_len(0x1ab),bl,AREA_WOS);
  2101. }
  2102. return 0;
  2103. }
  2104. /*==========================================
  2105. *
  2106. *------------------------------------------*/
  2107. void clif_changelook(struct block_list *bl,int type,int val)
  2108. {
  2109. unsigned char buf[16];
  2110. struct map_session_data* sd = NULL;
  2111. struct status_change* sc;
  2112. struct view_data* vd;
  2113. enum send_target target = AREA;
  2114. nullpo_retv(bl);
  2115. sd = BL_CAST(BL_PC, bl);
  2116. sc = status_get_sc(bl);
  2117. vd = status_get_viewdata(bl);
  2118. //nullpo_ret(vd);
  2119. if( vd ) //temp hack to let Warp Portal change appearance
  2120. switch(type)
  2121. {
  2122. case LOOK_WEAPON:
  2123. if (sd)
  2124. {
  2125. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2126. val = vd->weapon;
  2127. }
  2128. else vd->weapon = val;
  2129. break;
  2130. case LOOK_SHIELD:
  2131. if (sd)
  2132. {
  2133. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2134. val = vd->shield;
  2135. }
  2136. else vd->shield = val;
  2137. break;
  2138. case LOOK_BASE:
  2139. vd->class_ = val;
  2140. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS || vd->class_ == JOB_SUMMER)
  2141. vd->weapon = vd->shield = 0;
  2142. if (vd->cloth_color && (
  2143. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2144. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2145. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2146. ))
  2147. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2148. break;
  2149. case LOOK_HAIR:
  2150. vd->hair_style = val;
  2151. break;
  2152. case LOOK_HEAD_BOTTOM:
  2153. vd->head_bottom = val;
  2154. break;
  2155. case LOOK_HEAD_TOP:
  2156. vd->head_top = val;
  2157. break;
  2158. case LOOK_HEAD_MID:
  2159. vd->head_mid = val;
  2160. break;
  2161. case LOOK_HAIR_COLOR:
  2162. vd->hair_color = val;
  2163. break;
  2164. case LOOK_CLOTHES_COLOR:
  2165. if (val && (
  2166. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2167. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette) ||
  2168. (vd->class_ == JOB_SUMMER && battle_config.summer_ignorepalette)
  2169. ))
  2170. val = 0;
  2171. vd->cloth_color = val;
  2172. break;
  2173. case LOOK_SHOES:
  2174. #if PACKETVER > 3
  2175. if (sd) {
  2176. int n;
  2177. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2178. if(sd->inventory_data[n]->view_id > 0)
  2179. val = sd->inventory_data[n]->view_id;
  2180. else
  2181. val = sd->status.inventory[n].nameid;
  2182. }
  2183. val = 0;
  2184. }
  2185. #endif
  2186. //Shoes? No packet uses this....
  2187. break;
  2188. }
  2189. // prevent leaking the presence of GM-hidden objects
  2190. if( sc && sc->option&OPTION_INVISIBLE )
  2191. target = SELF;
  2192. #if PACKETVER < 4
  2193. WBUFW(buf,0)=0xc3;
  2194. WBUFL(buf,2)=bl->id;
  2195. WBUFB(buf,6)=type;
  2196. WBUFB(buf,7)=val;
  2197. clif_send(buf,packet_len(0xc3),bl,target);
  2198. #else
  2199. WBUFW(buf,0)=0x1d7;
  2200. WBUFL(buf,2)=bl->id;
  2201. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2202. WBUFB(buf,6)=LOOK_WEAPON;
  2203. WBUFW(buf,7)=vd->weapon;
  2204. WBUFW(buf,9)=vd->shield;
  2205. } else {
  2206. WBUFB(buf,6)=type;
  2207. WBUFW(buf,7)=val;
  2208. WBUFW(buf,9)=0;
  2209. }
  2210. clif_send(buf,packet_len(0x1d7),bl,target);
  2211. #endif
  2212. }
  2213. //Sends a change-base-look packet required for traps as they are triggered.
  2214. void clif_changetraplook(struct block_list *bl,int val)
  2215. {
  2216. unsigned char buf[32];
  2217. #if PACKETVER < 4
  2218. WBUFW(buf,0)=0xc3;
  2219. WBUFL(buf,2)=bl->id;
  2220. WBUFB(buf,6)=LOOK_BASE;
  2221. WBUFB(buf,7)=val;
  2222. clif_send(buf,packet_len(0xc3),bl,AREA);
  2223. #else
  2224. WBUFW(buf,0)=0x1d7;
  2225. WBUFL(buf,2)=bl->id;
  2226. WBUFB(buf,6)=LOOK_BASE;
  2227. WBUFW(buf,7)=val;
  2228. WBUFW(buf,9)=0;
  2229. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2230. #endif
  2231. }
  2232. //For the stupid cloth-dye bug. Resends the given view data to the area specified by bl.
  2233. void clif_refreshlook(struct block_list *bl,int id,int type,int val,enum send_target target)
  2234. {
  2235. unsigned char buf[32];
  2236. #if PACKETVER < 4
  2237. WBUFW(buf,0)=0xc3;
  2238. WBUFL(buf,2)=id;
  2239. WBUFB(buf,6)=type;
  2240. WBUFB(buf,7)=val;
  2241. clif_send(buf,packet_len(0xc3),bl,target);
  2242. #else
  2243. WBUFW(buf,0)=0x1d7;
  2244. WBUFL(buf,2)=id;
  2245. WBUFB(buf,6)=type;
  2246. WBUFW(buf,7)=val;
  2247. WBUFW(buf,9)=0;
  2248. clif_send(buf,packet_len(0x1d7),bl,target);
  2249. #endif
  2250. return;
  2251. }
  2252. /*==========================================
  2253. *
  2254. *------------------------------------------*/
  2255. int clif_initialstatus(struct map_session_data *sd)
  2256. {
  2257. int fd;
  2258. unsigned char *buf;
  2259. nullpo_retr(0, sd);
  2260. fd=sd->fd;
  2261. WFIFOHEAD(fd,packet_len(0xbd));
  2262. buf=WFIFOP(fd,0);
  2263. WBUFW(buf,0)=0xbd;
  2264. WBUFW(buf,2)=min(sd->status.status_point, SHRT_MAX);
  2265. WBUFB(buf,4)=min(sd->status.str, UCHAR_MAX);
  2266. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2267. WBUFB(buf,6)=min(sd->status.agi, UCHAR_MAX);
  2268. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2269. WBUFB(buf,8)=min(sd->status.vit, UCHAR_MAX);
  2270. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2271. WBUFB(buf,10)=min(sd->status.int_, UCHAR_MAX);
  2272. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2273. WBUFB(buf,12)=min(sd->status.dex, UCHAR_MAX);
  2274. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2275. WBUFB(buf,14)=min(sd->status.luk, UCHAR_MAX);
  2276. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2277. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw.atk;
  2278. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw.atk2; //atk bonus
  2279. WBUFW(buf,20) = sd->battle_status.matk_max;
  2280. WBUFW(buf,22) = sd->battle_status.matk_min;
  2281. WBUFW(buf,24) = sd->battle_status.def; // def
  2282. WBUFW(buf,26) = sd->battle_status.def2;
  2283. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2284. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2285. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2286. WBUFW(buf,30) = fd;
  2287. fd = sd->fd;
  2288. WBUFW(buf,32) = sd->battle_status.hit;
  2289. WBUFW(buf,34) = sd->battle_status.flee;
  2290. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2291. WBUFW(buf,38) = sd->battle_status.cri/10;
  2292. WBUFW(buf,40) = sd->status.karma;
  2293. WBUFW(buf,42) = sd->status.manner;
  2294. WFIFOSET(fd,packet_len(0xbd));
  2295. clif_updatestatus(sd,SP_STR);
  2296. clif_updatestatus(sd,SP_AGI);
  2297. clif_updatestatus(sd,SP_VIT);
  2298. clif_updatestatus(sd,SP_INT);
  2299. clif_updatestatus(sd,SP_DEX);
  2300. clif_updatestatus(sd,SP_LUK);
  2301. clif_updatestatus(sd,SP_ATTACKRANGE);
  2302. clif_updatestatus(sd,SP_ASPD);
  2303. return 0;
  2304. }
  2305. /*==========================================
  2306. *矢装備
  2307. *------------------------------------------*/
  2308. int clif_arrowequip(struct map_session_data *sd,int val)
  2309. {
  2310. int fd;
  2311. nullpo_retr(0, sd);
  2312. pc_stop_attack(sd); // [Valaris]
  2313. fd=sd->fd;
  2314. WFIFOHEAD(fd, packet_len(0x013c));
  2315. WFIFOW(fd,0)=0x013c;
  2316. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2317. WFIFOSET(fd,packet_len(0x013c));
  2318. return 0;
  2319. }
  2320. /// Ammunition action message.
  2321. /// type=0 : MsgStringTable[242]="Please equip the proper ammunition first."
  2322. /// type=1 : MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2323. /// type=2 : MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2324. /// type=3 : assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2325. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2326. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2327. int clif_arrow_fail(struct map_session_data *sd,int type)
  2328. {
  2329. int fd;
  2330. nullpo_retr(0, sd);
  2331. fd=sd->fd;
  2332. WFIFOHEAD(fd, packet_len(0x013b));
  2333. WFIFOW(fd,0)=0x013b;
  2334. WFIFOW(fd,2)=type;
  2335. WFIFOSET(fd,packet_len(0x013b));
  2336. return 0;
  2337. }
  2338. /*==========================================
  2339. * 作成可能 矢リスト送信
  2340. *------------------------------------------*/
  2341. int clif_arrow_create_list(struct map_session_data *sd)
  2342. {
  2343. int i, c, j;
  2344. int fd;
  2345. nullpo_retr(0, sd);
  2346. fd = sd->fd;
  2347. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2348. WFIFOW(fd,0) = 0x1ad;
  2349. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2350. if (skill_arrow_db[i].nameid > 0 &&
  2351. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2352. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2353. {
  2354. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2355. WFIFOW(fd,c*2+4) = j;
  2356. else
  2357. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2358. c++;
  2359. }
  2360. }
  2361. WFIFOW(fd,2) = c*2+4;
  2362. WFIFOSET(fd, WFIFOW(fd,2));
  2363. if (c > 0) {
  2364. sd->menuskill_id = AC_MAKINGARROW;
  2365. sd->menuskill_val = c;
  2366. }
  2367. return 0;
  2368. }
  2369. /*==========================================
  2370. *
  2371. *------------------------------------------*/
  2372. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2373. {
  2374. int fd;
  2375. nullpo_retr(0, sd);
  2376. fd=sd->fd;
  2377. WFIFOHEAD(fd,packet_len(0xbc));
  2378. WFIFOW(fd,0)=0xbc;
  2379. WFIFOW(fd,2)=type;
  2380. WFIFOB(fd,4)=ok;
  2381. WFIFOB(fd,5)=cap_value(val,0,UCHAR_MAX);
  2382. WFIFOSET(fd,packet_len(0xbc));
  2383. return 0;
  2384. }
  2385. /*==========================================
  2386. *
  2387. *------------------------------------------*/
  2388. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2389. {
  2390. int fd;
  2391. nullpo_retr(0, sd);
  2392. fd=sd->fd;
  2393. WFIFOHEAD(fd,packet_len(0xaa));
  2394. WFIFOW(fd,0)=0xaa;
  2395. WFIFOW(fd,2)=n+2;
  2396. WFIFOW(fd,4)=pos;
  2397. WFIFOB(fd,6)=ok;
  2398. WFIFOSET(fd,packet_len(0xaa));
  2399. return 0;
  2400. }
  2401. /*==========================================
  2402. *
  2403. *------------------------------------------*/
  2404. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2405. {
  2406. int fd;
  2407. nullpo_retr(0, sd);
  2408. fd=sd->fd;
  2409. WFIFOHEAD(fd,packet_len(0xac));
  2410. WFIFOW(fd,0)=0xac;
  2411. WFIFOW(fd,2)=n+2;
  2412. WFIFOW(fd,4)=pos;
  2413. WFIFOB(fd,6)=ok;
  2414. WFIFOSET(fd,packet_len(0xac));
  2415. return 0;
  2416. }
  2417. /*==========================================
  2418. *
  2419. *------------------------------------------*/
  2420. int clif_misceffect(struct block_list* bl,int type)
  2421. {
  2422. unsigned char buf[32];
  2423. nullpo_retr(0, bl);
  2424. WBUFW(buf,0) = 0x19b;
  2425. WBUFL(buf,2) = bl->id;
  2426. WBUFL(buf,6) = type;
  2427. clif_send(buf,packet_len(0x19b),bl,AREA);
  2428. return 0;
  2429. }
  2430. int clif_misceffect2(struct block_list *bl, int type)
  2431. {
  2432. unsigned char buf[24];
  2433. nullpo_retr(0, bl);
  2434. memset(buf, 0, packet_len(0x1f3));
  2435. WBUFW(buf,0) = 0x1f3;
  2436. WBUFL(buf,2) = bl->id;
  2437. WBUFL(buf,6) = type;
  2438. clif_send(buf, packet_len(0x1f3), bl, AREA);
  2439. return 0;
  2440. }
  2441. /*==========================================
  2442. * 表示オプション変更
  2443. *------------------------------------------*/
  2444. int clif_changeoption(struct block_list* bl)
  2445. {
  2446. unsigned char buf[32];
  2447. struct status_change *sc;
  2448. nullpo_retr(0, bl);
  2449. sc = status_get_sc(bl);
  2450. if (!sc) return 0; //How can an option change if there's no sc?
  2451. #if PACKETVER >= 7
  2452. WBUFW(buf,0) = 0x229;
  2453. WBUFL(buf,2) = bl->id;
  2454. WBUFW(buf,6) = sc->opt1;
  2455. WBUFW(buf,8) = sc->opt2;
  2456. WBUFL(buf,10) = sc->option;
  2457. WBUFB(buf,14) = 0; // PK???
  2458. if(disguised(bl)) {
  2459. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2460. WBUFL(buf,2) = -bl->id;
  2461. clif_send(buf,packet_len(0x229),bl,SELF);
  2462. WBUFL(buf,2) = bl->id;
  2463. WBUFL(buf,10) = OPTION_INVISIBLE;
  2464. clif_send(buf,packet_len(0x229),bl,SELF);
  2465. } else
  2466. clif_send(buf,packet_len(0x229),bl,AREA);
  2467. #else
  2468. WBUFW(buf,0) = 0x119;
  2469. WBUFL(buf,2) = bl->id;
  2470. WBUFW(buf,6) = sc->opt1;
  2471. WBUFW(buf,8) = sc->opt2;
  2472. WBUFW(buf,10) = sc->option;
  2473. WBUFB(buf,12) = 0; // ??
  2474. if(disguised(bl)) {
  2475. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2476. WBUFL(buf,2) = -bl->id;
  2477. clif_send(buf,packet_len(0x119),bl,SELF);
  2478. WBUFL(buf,2) = bl->id;
  2479. WBUFW(buf,10) = OPTION_INVISIBLE;
  2480. clif_send(buf,packet_len(0x119),bl,SELF);
  2481. } else
  2482. clif_send(buf,packet_len(0x119),bl,AREA);
  2483. #endif
  2484. return 0;
  2485. }
  2486. int clif_changeoption2(struct block_list* bl)
  2487. {
  2488. unsigned char buf[20];
  2489. struct status_change *sc;
  2490. sc = status_get_sc(bl);
  2491. if (!sc) return 0; //How can an option change if there's no sc?
  2492. WBUFW(buf,0) = 0x28a;
  2493. WBUFL(buf,2) = bl->id;
  2494. WBUFL(buf,6) = sc->option;
  2495. WBUFL(buf,10) = clif_setlevel(status_get_lv(bl));
  2496. WBUFL(buf,14) = sc->opt3;
  2497. if(disguised(bl)) {
  2498. clif_send(buf,packet_len(0x28a),bl,AREA_WOS);
  2499. WBUFL(buf,2) = -bl->id;
  2500. clif_send(buf,packet_len(0x28a),bl,SELF);
  2501. WBUFL(buf,2) = bl->id;
  2502. WBUFL(buf,6) = OPTION_INVISIBLE;
  2503. clif_send(buf,packet_len(0x28a),bl,SELF);
  2504. } else
  2505. clif_send(buf,packet_len(0x28a),bl,AREA);
  2506. return 0;
  2507. }
  2508. /*==========================================
  2509. *
  2510. *------------------------------------------*/
  2511. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2512. {
  2513. nullpo_retr(0, sd);
  2514. if(!ok) {
  2515. int fd=sd->fd;
  2516. WFIFOHEAD(fd,packet_len(0xa8));
  2517. WFIFOW(fd,0)=0xa8;
  2518. WFIFOW(fd,2)=index+2;
  2519. WFIFOW(fd,4)=amount;
  2520. WFIFOB(fd,6)=ok;
  2521. WFIFOSET(fd,packet_len(0xa8));
  2522. }
  2523. else {
  2524. #if PACKETVER < 3
  2525. int fd=sd->fd;
  2526. WFIFOHEAD(fd,packet_len(0xa8));
  2527. WFIFOW(fd,0)=0xa8;
  2528. WFIFOW(fd,2)=index+2;
  2529. WFIFOW(fd,4)=amount;
  2530. WFIFOB(fd,6)=ok;
  2531. WFIFOSET(fd,packet_len(0xa8));
  2532. #else
  2533. unsigned char buf[32];
  2534. WBUFW(buf,0)=0x1c8;
  2535. WBUFW(buf,2)=index+2;
  2536. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2537. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2538. else
  2539. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2540. WBUFL(buf,6)=sd->bl.id;
  2541. WBUFW(buf,10)=amount;
  2542. WBUFB(buf,12)=ok;
  2543. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2544. #endif
  2545. }
  2546. return 0;
  2547. }
  2548. /*==========================================
  2549. * Inform client whether chatroom creation was successful or not
  2550. * R 00d6 <fail>.B
  2551. *------------------------------------------*/
  2552. void clif_createchat(struct map_session_data* sd, int fail)
  2553. {
  2554. int fd;
  2555. nullpo_retv(sd);
  2556. fd = sd->fd;
  2557. WFIFOHEAD(fd,packet_len(0xd6));
  2558. WFIFOW(fd,0) = 0xd6;
  2559. WFIFOB(fd,2) = fail;
  2560. WFIFOSET(fd,packet_len(0xd6));
  2561. }
  2562. /*==========================================
  2563. * Display a chat above the owner
  2564. * R 00d7 <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <type>.B <title>.?B
  2565. *------------------------------------------*/
  2566. int clif_dispchat(struct chat_data* cd, int fd)
  2567. {
  2568. unsigned char buf[128];
  2569. uint8 type;
  2570. if( cd == NULL || cd->owner == NULL )
  2571. return 1;
  2572. // type - 0: private, 1: public, 2: npc, 3: non-clickable
  2573. type = (cd->owner->type == BL_PC ) ? (cd->pub) ? 1 : 0
  2574. : (cd->owner->type == BL_NPC) ? (cd->limit) ? 2 : 3
  2575. : 1;
  2576. WBUFW(buf, 0) = 0xd7;
  2577. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2578. WBUFL(buf, 4) = cd->owner->id;
  2579. WBUFL(buf, 8) = cd->bl.id;
  2580. WBUFW(buf,12) = cd->limit;
  2581. WBUFW(buf,14) = cd->users;
  2582. WBUFB(buf,16) = type;
  2583. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2584. if( fd ) {
  2585. WFIFOHEAD(fd,WBUFW(buf,2));
  2586. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2587. WFIFOSET(fd,WBUFW(buf,2));
  2588. } else {
  2589. clif_send(buf,WBUFW(buf,2),cd->owner,AREA_WOSC);
  2590. }
  2591. return 0;
  2592. }
  2593. /*==========================================
  2594. * Chatroom properties adjustment
  2595. * R 00df <len>.w <owner ID>.l <chat ID>.l <limit>.w <users>.w <pub>.B <title>.?B
  2596. *------------------------------------------*/
  2597. int clif_changechatstatus(struct chat_data* cd)
  2598. {
  2599. unsigned char buf[128];
  2600. if( cd == NULL || cd->usersd[0] == NULL )
  2601. return 1;
  2602. WBUFW(buf, 0) = 0xdf;
  2603. WBUFW(buf, 2) = 17 + strlen(cd->title);
  2604. WBUFL(buf, 4) = cd->usersd[0]->bl.id;
  2605. WBUFL(buf, 8) = cd->bl.id;
  2606. WBUFW(buf,12) = cd->limit;
  2607. WBUFW(buf,14) = cd->users;
  2608. WBUFB(buf,16) = cd->pub;
  2609. strncpy((char*)WBUFP(buf,17), cd->title, strlen(cd->title)); // not zero-terminated
  2610. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2611. return 0;
  2612. }
  2613. /*==========================================
  2614. *
  2615. *------------------------------------------*/
  2616. int clif_clearchat(struct chat_data *cd,int fd)
  2617. {
  2618. unsigned char buf[32];
  2619. nullpo_retr(0, cd);
  2620. WBUFW(buf,0) = 0xd8;
  2621. WBUFL(buf,2) = cd->bl.id;
  2622. if( fd ) {
  2623. WFIFOHEAD(fd,packet_len(0xd8));
  2624. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2625. WFIFOSET(fd,packet_len(0xd8));
  2626. } else {
  2627. clif_send(buf,packet_len(0xd8),cd->owner,AREA_WOSC);
  2628. }
  2629. return 0;
  2630. }
  2631. /*==========================================
  2632. *
  2633. *------------------------------------------*/
  2634. int clif_joinchatfail(struct map_session_data *sd,int fail)
  2635. {
  2636. int fd;
  2637. nullpo_retr(0, sd);
  2638. fd = sd->fd;
  2639. WFIFOHEAD(fd,packet_len(0xda));
  2640. WFIFOW(fd,0) = 0xda;
  2641. WFIFOB(fd,2) = fail;
  2642. WFIFOSET(fd,packet_len(0xda));
  2643. return 0;
  2644. }
  2645. /*==========================================
  2646. *
  2647. *------------------------------------------*/
  2648. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2649. {
  2650. int fd;
  2651. int i;
  2652. nullpo_retr(0, sd);
  2653. nullpo_retr(0, cd);
  2654. fd = sd->fd;
  2655. if (!session_isActive(fd))
  2656. return 0;
  2657. WFIFOHEAD(fd, 8 + (28*cd->users));
  2658. WFIFOW(fd, 0) = 0xdb;
  2659. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2660. WFIFOL(fd, 4) = cd->bl.id;
  2661. for (i = 0; i < cd->users; i++) {
  2662. WFIFOL(fd, 8+i*28) = (i != 0 || cd->owner->type == BL_NPC);
  2663. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2664. }
  2665. WFIFOSET(fd, WFIFOW(fd, 2));
  2666. return 0;
  2667. }
  2668. /*==========================================
  2669. *
  2670. *------------------------------------------*/
  2671. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2672. {
  2673. unsigned char buf[32];
  2674. nullpo_retr(0, sd);
  2675. nullpo_retr(0, cd);
  2676. WBUFW(buf, 0) = 0x0dc;
  2677. WBUFW(buf, 2) = cd->users;
  2678. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2679. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  2680. return 0;
  2681. }
  2682. /*==========================================
  2683. * Announce the new owner
  2684. * R 00e1 <index>.l <nick>.24B
  2685. *------------------------------------------*/
  2686. void clif_changechatowner(struct chat_data* cd, struct map_session_data* sd)
  2687. {
  2688. unsigned char buf[64];
  2689. nullpo_retv(sd);
  2690. nullpo_retv(cd);
  2691. //FIXME: this announces a swap between positions 0 and 1 (probably not what we want) [ultramage]
  2692. //FIXME: aegis sends obviously incorrect packets; need to figure out what to send to display it correctly :X
  2693. //TODO: is it just owner swap, or can it do general-purpose reordering?
  2694. WBUFW(buf, 0) = 0xe1;
  2695. WBUFL(buf, 2) = 1;
  2696. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2697. WBUFW(buf,30) = 0xe1;
  2698. WBUFL(buf,32) = 0;
  2699. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2700. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  2701. }
  2702. /*==========================================
  2703. * Notify about user leaving the chatroom
  2704. * R 00dd <index>.w <nick>.24B <flag>.B
  2705. *------------------------------------------*/
  2706. void clif_leavechat(struct chat_data* cd, struct map_session_data* sd, bool flag)
  2707. {
  2708. unsigned char buf[32];
  2709. nullpo_retv(sd);
  2710. nullpo_retv(cd);
  2711. WBUFW(buf, 0) = 0xdd;
  2712. WBUFW(buf, 2) = cd->users-1;
  2713. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2714. WBUFB(buf,28) = flag; // 0: left, 1: was kicked
  2715. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  2716. }
  2717. /*==========================================
  2718. * Opens a trade request window from char 'name'
  2719. * R 00e5 <nick>.24B
  2720. * R 01f4 <nick>.24B <charid>.L <baselvl>.W
  2721. *------------------------------------------*/
  2722. void clif_traderequest(struct map_session_data* sd, const char* name)
  2723. {
  2724. int fd = sd->fd;
  2725. #if PACKETVER < 6
  2726. WFIFOHEAD(fd,packet_len(0xe5));
  2727. WFIFOW(fd,0) = 0xe5;
  2728. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2729. WFIFOSET(fd,packet_len(0xe5));
  2730. #else
  2731. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2732. if( !tsd ) return;
  2733. WFIFOHEAD(fd,packet_len(0x1f4));
  2734. WFIFOW(fd,0) = 0x1f4;
  2735. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  2736. WFIFOL(fd,26) = tsd->status.char_id;
  2737. WFIFOW(fd,30) = clif_setlevel(tsd->status.base_level);
  2738. WFIFOSET(fd,packet_len(0x1f4));
  2739. #endif
  2740. }
  2741. /*==========================================
  2742. * Reply to a trade-request.
  2743. * R 00e7 <type>.B
  2744. * R 01f5 <type>.B <charid>.L <baselvl>.W
  2745. * Type:
  2746. * 0: Char is too far
  2747. * 1: Character does not exist
  2748. * 2: Trade failed
  2749. * 3: Accept
  2750. * 4: Cancel
  2751. *------------------------------------------*/
  2752. void clif_tradestart(struct map_session_data* sd, uint8 type)
  2753. {
  2754. int fd = sd->fd;
  2755. #if PACKETVER < 6
  2756. WFIFOHEAD(fd,packet_len(0xe7));
  2757. WFIFOW(fd,0) = 0xe7;
  2758. WFIFOB(fd,2) = type;
  2759. WFIFOSET(fd,packet_len(0xe7));
  2760. #else
  2761. struct map_session_data* tsd = map_id2sd(sd->trade_partner);
  2762. if( !tsd ) return;
  2763. WFIFOHEAD(fd,packet_len(0x1f5));
  2764. WFIFOW(fd,0) = 0x1f5;
  2765. WFIFOB(fd,2) = type;
  2766. WFIFOL(fd,3) = tsd->status.char_id;
  2767. WFIFOW(fd,7) = clif_setlevel(tsd->status.base_level);
  2768. WFIFOSET(fd,packet_len(0x1f5));
  2769. #endif
  2770. }
  2771. /*==========================================
  2772. * 相手方からのアイテム追加
  2773. *------------------------------------------*/
  2774. void clif_tradeadditem(struct map_session_data* sd, struct map_session_data* tsd, int index, int amount)
  2775. {
  2776. int fd;
  2777. nullpo_retv(sd);
  2778. nullpo_retv(tsd);
  2779. fd = tsd->fd;
  2780. WFIFOHEAD(fd,packet_len(0xe9));
  2781. WFIFOW(fd,0) = 0xe9;
  2782. WFIFOL(fd,2) = amount;
  2783. if( index == 0 )
  2784. {
  2785. WFIFOW(fd,6) = 0; // type id
  2786. WFIFOB(fd,8) = 0; //identify flag
  2787. WFIFOB(fd,9) = 0; // attribute
  2788. WFIFOB(fd,10)= 0; //refine
  2789. WFIFOW(fd,11)= 0; //card (4w)
  2790. WFIFOW(fd,13)= 0; //card (4w)
  2791. WFIFOW(fd,15)= 0; //card (4w)
  2792. WFIFOW(fd,17)= 0; //card (4w)
  2793. }
  2794. else
  2795. {
  2796. index -= 2; //index fix
  2797. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2798. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  2799. else
  2800. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  2801. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  2802. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  2803. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  2804. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  2805. }
  2806. WFIFOSET(fd,packet_len(0xe9));
  2807. }
  2808. /*==========================================
  2809. * アイテム追加成功/失敗
  2810. *------------------------------------------*/
  2811. void clif_tradeitemok(struct map_session_data* sd, int index, int fail)
  2812. {
  2813. int fd;
  2814. nullpo_retv(sd);
  2815. fd = sd->fd;
  2816. WFIFOHEAD(fd,packet_len(0xea));
  2817. WFIFOW(fd,0) = 0xea;
  2818. WFIFOW(fd,2) = index;
  2819. WFIFOB(fd,4) = fail;
  2820. WFIFOSET(fd,packet_len(0xea));
  2821. }
  2822. /*==========================================
  2823. * 取り引きok押し
  2824. *------------------------------------------*/
  2825. void clif_tradedeal_lock(struct map_session_data* sd, int fail)
  2826. {
  2827. int fd;
  2828. nullpo_retv(sd);
  2829. fd = sd->fd;
  2830. WFIFOHEAD(fd,packet_len(0xec));
  2831. WFIFOW(fd,0) = 0xec;
  2832. WFIFOB(fd,2) = fail; // 0=you 1=the other person
  2833. WFIFOSET(fd,packet_len(0xec));
  2834. }
  2835. /*==========================================
  2836. * 取り引きがキャンセルされました
  2837. *------------------------------------------*/
  2838. void clif_tradecancelled(struct map_session_data* sd)
  2839. {
  2840. int fd;
  2841. nullpo_retv(sd);
  2842. fd = sd->fd;
  2843. WFIFOHEAD(fd,packet_len(0xee));
  2844. WFIFOW(fd,0) = 0xee;
  2845. WFIFOSET(fd,packet_len(0xee));
  2846. }
  2847. /*==========================================
  2848. * 取り引き完了
  2849. *------------------------------------------*/
  2850. void clif_tradecompleted(struct map_session_data* sd, int fail)
  2851. {
  2852. int fd;
  2853. nullpo_retv(sd);
  2854. fd = sd->fd;
  2855. WFIFOHEAD(fd,packet_len(0xf0));
  2856. WFIFOW(fd,0) = 0xf0;
  2857. WFIFOB(fd,2) = fail;
  2858. WFIFOSET(fd,packet_len(0xf0));
  2859. }
  2860. /*==========================================
  2861. * カプラ倉庫のアイテム数を更新
  2862. *------------------------------------------*/
  2863. void clif_updatestorageamount(struct map_session_data* sd, int amount)
  2864. {
  2865. int fd;
  2866. nullpo_retv(sd);
  2867. fd=sd->fd;
  2868. WFIFOHEAD(fd,packet_len(0xf2));
  2869. WFIFOW(fd,0) = 0xf2; // update storage amount
  2870. WFIFOW(fd,2) = amount; //items
  2871. WFIFOW(fd,4) = MAX_STORAGE; //items max
  2872. WFIFOSET(fd,packet_len(0xf2));
  2873. }
  2874. /*==========================================
  2875. * カプラ倉庫にアイテムを追加する
  2876. *------------------------------------------*/
  2877. void clif_storageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  2878. {
  2879. int view,fd;
  2880. nullpo_retv(sd);
  2881. nullpo_retv(i);
  2882. fd=sd->fd;
  2883. view = itemdb_viewid(i->nameid);
  2884. #if PACKETVER < 5
  2885. WFIFOHEAD(fd,packet_len(0xf4));
  2886. WFIFOW(fd, 0) = 0xf4; // Storage item added
  2887. WFIFOW(fd, 2) = index+1; // index
  2888. WFIFOL(fd, 4) = amount; // amount
  2889. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  2890. WFIFOB(fd,10) = i->identify; //identify flag
  2891. WFIFOB(fd,11) = i->attribute; // attribute
  2892. WFIFOB(fd,12) = i->refine; //refine
  2893. clif_addcards(WFIFOP(fd,13), i);
  2894. WFIFOSET(fd,packet_len(0xf4));
  2895. #else
  2896. WFIFOHEAD(fd,packet_len(0x1c4));
  2897. WFIFOW(fd, 0) = 0x1c4; // Storage item added
  2898. WFIFOW(fd, 2) = index+1; // index
  2899. WFIFOL(fd, 4) = amount; // amount
  2900. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  2901. WFIFOB(fd,10) = itemdb_type(i->nameid); //type
  2902. WFIFOB(fd,11) = i->identify; //identify flag
  2903. WFIFOB(fd,12) = i->attribute; // attribute
  2904. WFIFOB(fd,13) = i->refine; //refine
  2905. clif_addcards(WFIFOP(fd,14), i);
  2906. WFIFOSET(fd,packet_len(0x1c4));
  2907. #endif
  2908. }
  2909. /*==========================================
  2910. *
  2911. *------------------------------------------*/
  2912. void clif_updateguildstorageamount(struct map_session_data* sd, int amount)
  2913. {
  2914. int fd;
  2915. nullpo_retv(sd);
  2916. fd=sd->fd;
  2917. WFIFOHEAD(fd,packet_len(0xf2));
  2918. WFIFOW(fd,0) = 0xf2; // update storage amount
  2919. WFIFOW(fd,2) = amount; //items
  2920. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  2921. WFIFOSET(fd,packet_len(0xf2));
  2922. }
  2923. /*==========================================
  2924. *
  2925. *------------------------------------------*/
  2926. void clif_guildstorageitemadded(struct map_session_data* sd, struct item* i, int index, int amount)
  2927. {
  2928. int view,fd;
  2929. nullpo_retv(sd);
  2930. nullpo_retv(i);
  2931. fd=sd->fd;
  2932. view = itemdb_viewid(i->nameid);
  2933. WFIFOHEAD(fd,packet_len(0xf4));
  2934. WFIFOW(fd, 0) = 0xf4; // Storage item added
  2935. WFIFOW(fd, 2) = index+1; // index
  2936. WFIFOL(fd, 4) = amount; // amount
  2937. WFIFOW(fd, 8) = ( view > 0 ) ? view : i->nameid; // id
  2938. WFIFOB(fd,10) = i->identify; //identify flag
  2939. WFIFOB(fd,11) = i->attribute; // attribute
  2940. WFIFOB(fd,12) = i->refine; //refine
  2941. clif_addcards(WFIFOP(fd,13), i);
  2942. WFIFOSET(fd,packet_len(0xf4));
  2943. }
  2944. /*==========================================
  2945. * カプラ倉庫からアイテムを取り去る
  2946. *------------------------------------------*/
  2947. void clif_storageitemremoved(struct map_session_data* sd, int index, int amount)
  2948. {
  2949. int fd;
  2950. nullpo_retv(sd);
  2951. fd=sd->fd;
  2952. WFIFOHEAD(fd,packet_len(0xf6));
  2953. WFIFOW(fd,0)=0xf6; // Storage item removed
  2954. WFIFOW(fd,2)=index+1;
  2955. WFIFOL(fd,4)=amount;
  2956. WFIFOSET(fd,packet_len(0xf6));
  2957. }
  2958. /*==========================================
  2959. * カプラ倉庫を閉じる
  2960. *------------------------------------------*/
  2961. void clif_storageclose(struct map_session_data* sd)
  2962. {
  2963. int fd;
  2964. nullpo_retv(sd);
  2965. fd=sd->fd;
  2966. WFIFOHEAD(fd,packet_len(0xf8));
  2967. WFIFOW(fd,0) = 0xf8; // Storage Closed
  2968. WFIFOSET(fd,packet_len(0xf8));
  2969. }
  2970. /*==========================================
  2971. * PC表示
  2972. *------------------------------------------*/
  2973. static void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  2974. {
  2975. int gmlvl;
  2976. struct block_list *d_bl;
  2977. int i;
  2978. if(dstsd->chatID)
  2979. {
  2980. struct chat_data *cd;
  2981. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  2982. if(cd && cd->usersd[0]==dstsd)
  2983. clif_dispchat(cd,sd->fd);
  2984. }
  2985. if(dstsd->vender_id)
  2986. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  2987. if(dstsd->spiritball > 0)
  2988. clif_spiritball_single(sd->fd, dstsd);
  2989. if( (sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  2990. (sd->state.bg_id && sd->state.bg_id == dstsd->state.bg_id) || //BattleGround
  2991. (battle_config.disp_hpmeter && (gmlvl = pc_isGM(sd)) >= battle_config.disp_hpmeter && gmlvl >= pc_isGM(dstsd)) )
  2992. clif_hpmeter_single(sd->fd, dstsd->bl.id, dstsd->battle_status.hp, dstsd->battle_status.max_hp);
  2993. // display link (sd - dstsd) to sd
  2994. ARR_FIND( 0, 5, i, sd->devotion[i] == dstsd->bl.id );
  2995. if( i < 5 ) clif_devotion(&sd->bl, sd);
  2996. // display links (dstsd - devotees) to sd
  2997. ARR_FIND( 0, 5, i, dstsd->devotion[i] > 0 );
  2998. if( i < 5 ) clif_devotion(&dstsd->bl, sd);
  2999. // display link (dstsd - crusader) to sd
  3000. if( dstsd->sc.data[SC_DEVOTION] && (d_bl = map_id2bl(dstsd->sc.data[SC_DEVOTION]->val1)) != NULL )
  3001. clif_devotion(d_bl, sd);
  3002. }
  3003. void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl)
  3004. {
  3005. uint8 buf[128];
  3006. struct unit_data *ud;
  3007. struct view_data *vd;
  3008. int len;
  3009. vd = status_get_viewdata(bl);
  3010. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3011. return;
  3012. ud = unit_bl2ud(bl);
  3013. len = ( ud && ud->walktimer != -1 ) ? clif_set_unit_walking(bl,ud,buf) : clif_set_unit_idle(bl,buf,false);
  3014. clif_send(buf,len,&sd->bl,SELF);
  3015. if (vd->cloth_color)
  3016. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3017. switch (bl->type)
  3018. {
  3019. case BL_PC:
  3020. {
  3021. TBL_PC* tsd = (TBL_PC*)bl;
  3022. clif_getareachar_pc(sd, tsd);
  3023. if(tsd->state.size==2) // tiny/big players [Valaris]
  3024. clif_specialeffect_single(bl,423,sd->fd);
  3025. else if(tsd->state.size==1)
  3026. clif_specialeffect_single(bl,421,sd->fd);
  3027. }
  3028. break;
  3029. case BL_MER: // Devotion Effects
  3030. if( ((TBL_MER*)bl)->devotion_flag )
  3031. clif_devotion(bl, sd);
  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. if( nd->size == 2 )
  3039. clif_specialeffect_single(bl,423,sd->fd);
  3040. else if( nd->size == 1 )
  3041. clif_specialeffect_single(bl,421,sd->fd);
  3042. }
  3043. break;
  3044. case BL_MOB:
  3045. {
  3046. TBL_MOB* md = (TBL_MOB*)bl;
  3047. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3048. clif_specialeffect_single(bl,423,sd->fd);
  3049. else if(md->special_state.size==1)
  3050. clif_specialeffect_single(bl,421,sd->fd);
  3051. }
  3052. break;
  3053. case BL_PET:
  3054. if (vd->head_bottom)
  3055. clif_pet_equip(sd, (TBL_PET*)bl); // needed to display pet equip properly
  3056. break;
  3057. }
  3058. }
  3059. //Modifies the type of damage according to status changes [Skotlex]
  3060. //Aegis data specifies that: 4 endure against single hit sources, 9 against multi-hit.
  3061. #define clif_calc_delay(type,div,damage,delay) ((delay)==0&&(damage)>0?((div)>1?9:4):type)
  3062. /*==========================================
  3063. * Estimates walk delay based on the damage criteria. [Skotlex]
  3064. *------------------------------------------*/
  3065. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_)
  3066. {
  3067. if (type == 4 || type == 9 || damage <=0)
  3068. return 0;
  3069. if (bl->type == BL_PC) {
  3070. if (battle_config.pc_walk_delay_rate != 100)
  3071. delay = delay*battle_config.pc_walk_delay_rate/100;
  3072. } else
  3073. if (battle_config.walk_delay_rate != 100)
  3074. delay = delay*battle_config.walk_delay_rate/100;
  3075. if (div_ > 1) //Multi-hit skills mean higher delays.
  3076. delay += battle_config.multihit_delay*(div_-1);
  3077. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3078. }
  3079. /*==========================================
  3080. * Sends a 'damage' packet (src performs action on dst)
  3081. * 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
  3082. *
  3083. * type=00 damage [param1: total damage, param2: div, param3: assassin dual-wield damage]
  3084. * type=01 pick up item
  3085. * type=02 sit down
  3086. * type=03 stand up
  3087. * type=04 reflected/absorbed damage?
  3088. * type=08 double attack
  3089. * type=09 don't display flinch animation (endure)
  3090. * type=0a critical hit
  3091. * type=0b lucky dodge
  3092. *------------------------------------------*/
  3093. 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)
  3094. {
  3095. unsigned char buf[256];
  3096. struct status_change *sc;
  3097. nullpo_retr(0, src);
  3098. nullpo_retr(0, dst);
  3099. type = clif_calc_delay(type,div,damage+damage2,ddelay);
  3100. sc = status_get_sc(dst);
  3101. if(sc && sc->count) {
  3102. if(sc->data[SC_HALLUCINATION]) {
  3103. if(damage) damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3104. if(damage2) damage2 = damage2*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3105. }
  3106. }
  3107. WBUFW(buf,0)=0x8a;
  3108. WBUFL(buf,2)=src->id;
  3109. WBUFL(buf,6)=dst->id;
  3110. WBUFL(buf,10)=tick;
  3111. WBUFL(buf,14)=sdelay;
  3112. WBUFL(buf,18)=ddelay;
  3113. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3114. WBUFW(buf,22)=damage?div:0;
  3115. WBUFW(buf,27)=damage2?div:0;
  3116. } else {
  3117. WBUFW(buf,22)=min(damage, SHRT_MAX);
  3118. WBUFW(buf,27)=damage2;
  3119. }
  3120. WBUFW(buf,24)=div;
  3121. WBUFB(buf,26)=type;
  3122. if(disguised(dst)) {
  3123. clif_send(buf,packet_len(0x8a),dst,AREA_WOS);
  3124. WBUFL(buf,6) = -dst->id;
  3125. clif_send(buf,packet_len(0x8a),dst,SELF);
  3126. } else
  3127. clif_send(buf,packet_len(0x8a),dst,AREA);
  3128. if(disguised(src)) {
  3129. WBUFL(buf,2) = -src->id;
  3130. if (disguised(dst))
  3131. WBUFL(buf,6) = dst->id;
  3132. if(damage > 0) WBUFW(buf,22) = -1;
  3133. if(damage2 > 0) WBUFW(buf,27) = -1;
  3134. clif_send(buf,packet_len(0x8a),src,SELF);
  3135. }
  3136. //Return adjusted can't walk delay for further processing.
  3137. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3138. }
  3139. /*==========================================
  3140. * src picks up dst
  3141. *------------------------------------------*/
  3142. void clif_takeitem(struct block_list* src, struct block_list* dst)
  3143. {
  3144. //clif_damage(src,dst,0,0,0,0,0,1,0);
  3145. unsigned char buf[32];
  3146. nullpo_retv(src);
  3147. nullpo_retv(dst);
  3148. WBUFW(buf, 0) = 0x8a;
  3149. WBUFL(buf, 2) = src->id;
  3150. WBUFL(buf, 6) = dst->id;
  3151. WBUFB(buf,26) = 1;
  3152. clif_send(buf, packet_len(0x8a), src, AREA);
  3153. }
  3154. /*==========================================
  3155. * inform clients in area that `bl` is sitting
  3156. *------------------------------------------*/
  3157. void clif_sitting(struct block_list* bl)
  3158. {
  3159. unsigned char buf[32];
  3160. nullpo_retv(bl);
  3161. WBUFW(buf, 0) = 0x8a;
  3162. WBUFL(buf, 2) = bl->id;
  3163. WBUFB(buf,26) = 2;
  3164. clif_send(buf, packet_len(0x8a), bl, AREA);
  3165. if(disguised(bl)) {
  3166. WBUFL(buf, 2) = - bl->id;
  3167. clif_send(buf, packet_len(0x8a), bl, SELF);
  3168. }
  3169. }
  3170. /*==========================================
  3171. * inform clients in area that `bl` is standing
  3172. *------------------------------------------*/
  3173. void clif_standing(struct block_list* bl)
  3174. {
  3175. unsigned char buf[32];
  3176. nullpo_retv(bl);
  3177. WBUFW(buf, 0) = 0x8a;
  3178. WBUFL(buf, 2) = bl->id;
  3179. WBUFB(buf,26) = 3;
  3180. clif_send(buf, packet_len(0x8a), bl, AREA);
  3181. if(disguised(bl)) {
  3182. WBUFL(buf, 2) = - bl->id;
  3183. clif_send(buf, packet_len(0x8a), bl, SELF);
  3184. }
  3185. }
  3186. /*==========================================
  3187. * Inform client(s) about a map-cell change
  3188. *------------------------------------------*/
  3189. void clif_changemapcell(int fd, int m, int x, int y, int type, enum send_target target)
  3190. {
  3191. unsigned char buf[32];
  3192. WBUFW(buf,0) = 0x192;
  3193. WBUFW(buf,2) = x;
  3194. WBUFW(buf,4) = y;
  3195. WBUFW(buf,6) = type;
  3196. mapindex_getmapname_ext(map[m].name,(char*)WBUFP(buf,8));
  3197. if( fd )
  3198. {
  3199. WFIFOHEAD(fd,packet_len(0x192));
  3200. memcpy(WFIFOP(fd,0), buf, packet_len(0x192));
  3201. WFIFOSET(fd,packet_len(0x192));
  3202. }
  3203. else
  3204. {
  3205. struct block_list dummy_bl;
  3206. dummy_bl.type = BL_NUL;
  3207. dummy_bl.x = x;
  3208. dummy_bl.y = y;
  3209. dummy_bl.m = m;
  3210. clif_send(buf,packet_len(0x192),&dummy_bl,target);
  3211. }
  3212. }
  3213. /*==========================================
  3214. *
  3215. *------------------------------------------*/
  3216. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3217. {
  3218. int view,fd;
  3219. fd=sd->fd;
  3220. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3221. WFIFOHEAD(fd,packet_len(0x9d));
  3222. WFIFOW(fd,0)=0x9d;
  3223. WFIFOL(fd,2)=fitem->bl.id;
  3224. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3225. WFIFOW(fd,6)=view;
  3226. else
  3227. WFIFOW(fd,6)=fitem->item_data.nameid;
  3228. WFIFOB(fd,8)=fitem->item_data.identify;
  3229. WFIFOW(fd,9)=fitem->bl.x;
  3230. WFIFOW(fd,11)=fitem->bl.y;
  3231. WFIFOW(fd,13)=fitem->item_data.amount;
  3232. WFIFOB(fd,15)=fitem->subx;
  3233. WFIFOB(fd,16)=fitem->suby;
  3234. WFIFOSET(fd,packet_len(0x9d));
  3235. }
  3236. /*==========================================
  3237. * 場所スキルエフェクトが視界に入る
  3238. *------------------------------------------*/
  3239. static void clif_getareachar_skillunit(struct map_session_data *sd, struct skill_unit *unit)
  3240. {
  3241. int fd = sd->fd;
  3242. #if PACKETVER >= 3
  3243. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3244. WFIFOHEAD(fd,packet_len(0x1c9));
  3245. WFIFOW(fd, 0)=0x1c9;
  3246. WFIFOL(fd, 2)=unit->bl.id;
  3247. WFIFOL(fd, 6)=unit->group->src_id;
  3248. WFIFOW(fd,10)=unit->bl.x;
  3249. WFIFOW(fd,12)=unit->bl.y;
  3250. WFIFOB(fd,14)=unit->group->unit_id;
  3251. WFIFOB(fd,15)=1;
  3252. WFIFOB(fd,16)=1;
  3253. safestrncpy((char*)WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3254. WFIFOSET(fd,packet_len(0x1c9));
  3255. return;
  3256. }
  3257. #endif
  3258. WFIFOHEAD(fd,packet_len(0x11f));
  3259. WFIFOW(fd, 0)=0x11f;
  3260. WFIFOL(fd, 2)=unit->bl.id;
  3261. WFIFOL(fd, 6)=unit->group->src_id;
  3262. WFIFOW(fd,10)=unit->bl.x;
  3263. WFIFOW(fd,12)=unit->bl.y;
  3264. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3265. WFIFOB(fd,14)=UNT_ATTACK_SKILLS; //Use invisible unit id for traps.
  3266. else
  3267. WFIFOB(fd,14)=unit->group->unit_id;
  3268. WFIFOB(fd,15)=1; // ignored by client (always gets set to 1)
  3269. WFIFOSET(fd,packet_len(0x11f));
  3270. if(unit->group->skill_id == WZ_ICEWALL)
  3271. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,5,SELF);
  3272. }
  3273. /*==========================================
  3274. * 場所スキルエフェクトが視界から消える
  3275. *------------------------------------------*/
  3276. static void clif_clearchar_skillunit(struct skill_unit *unit, int fd)
  3277. {
  3278. nullpo_retv(unit);
  3279. WFIFOHEAD(fd,packet_len(0x120));
  3280. WFIFOW(fd, 0)=0x120;
  3281. WFIFOL(fd, 2)=unit->bl.id;
  3282. WFIFOSET(fd,packet_len(0x120));
  3283. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3284. clif_changemapcell(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2,SELF);
  3285. }
  3286. /*==========================================
  3287. * 場所スキルエフェクト削除
  3288. *------------------------------------------*/
  3289. void clif_skill_delunit(struct skill_unit *unit)
  3290. {
  3291. unsigned char buf[16];
  3292. nullpo_retv(unit);
  3293. WBUFW(buf, 0)=0x120;
  3294. WBUFL(buf, 2)=unit->bl.id;
  3295. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  3296. }
  3297. /*==========================================
  3298. * Unknown... trap related?
  3299. * Sent when an object gets ankle-snared
  3300. * Only affects units with class [139,153] client-side
  3301. * R 01ac <object id>.l
  3302. *------------------------------------------*/
  3303. void clif_01ac(struct block_list* bl)
  3304. {
  3305. unsigned char buf[6];
  3306. nullpo_retv(bl);
  3307. WBUFW(buf,0) = 0x1ac;
  3308. WBUFL(buf,2) = bl->id;
  3309. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3310. }
  3311. /*==========================================
  3312. *
  3313. *------------------------------------------*/
  3314. int clif_getareachar(struct block_list* bl,va_list ap)
  3315. {
  3316. struct map_session_data *sd;
  3317. nullpo_retr(0, bl);
  3318. sd=va_arg(ap,struct map_session_data*);
  3319. if (sd == NULL || !sd->fd)
  3320. return 0;
  3321. switch(bl->type){
  3322. case BL_ITEM:
  3323. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3324. break;
  3325. case BL_SKILL:
  3326. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3327. break;
  3328. default:
  3329. if(&sd->bl == bl)
  3330. break;
  3331. clif_getareachar_unit(sd,bl);
  3332. break;
  3333. }
  3334. return 0;
  3335. }
  3336. /*==========================================
  3337. * tbl has gone out of view-size of bl
  3338. *------------------------------------------*/
  3339. int clif_outsight(struct block_list *bl,va_list ap)
  3340. {
  3341. struct block_list *tbl;
  3342. struct view_data *vd;
  3343. TBL_PC *sd, *tsd;
  3344. tbl=va_arg(ap,struct block_list*);
  3345. if(bl == tbl) return 0;
  3346. sd = BL_CAST(BL_PC, bl);
  3347. tsd = BL_CAST(BL_PC, tbl);
  3348. if (tsd && tsd->fd)
  3349. { //tsd has lost sight of the bl object.
  3350. switch(bl->type){
  3351. case BL_PC:
  3352. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS)
  3353. clif_clearunit_single(bl->id,0,tsd->fd);
  3354. if(sd->chatID){
  3355. struct chat_data *cd;
  3356. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3357. if(cd->usersd[0]==sd)
  3358. clif_dispchat(cd,tsd->fd);
  3359. }
  3360. if(sd->vender_id)
  3361. clif_closevendingboard(bl,tsd->fd);
  3362. break;
  3363. case BL_ITEM:
  3364. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3365. break;
  3366. case BL_SKILL:
  3367. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3368. break;
  3369. default:
  3370. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3371. clif_clearunit_single(bl->id,0,tsd->fd);
  3372. break;
  3373. }
  3374. }
  3375. if (sd && sd->fd)
  3376. { //sd is watching tbl go out of view.
  3377. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3378. clif_clearunit_single(tbl->id,0,sd->fd);
  3379. }
  3380. return 0;
  3381. }
  3382. /*==========================================
  3383. * tbl has come into view of bl
  3384. *------------------------------------------*/
  3385. int clif_insight(struct block_list *bl,va_list ap)
  3386. {
  3387. struct block_list *tbl;
  3388. TBL_PC *sd, *tsd;
  3389. tbl=va_arg(ap,struct block_list*);
  3390. if (bl == tbl) return 0;
  3391. sd = BL_CAST(BL_PC, bl);
  3392. tsd = BL_CAST(BL_PC, tbl);
  3393. if (tsd && tsd->fd)
  3394. { //Tell tsd that bl entered into his view
  3395. switch(bl->type){
  3396. case BL_ITEM:
  3397. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3398. break;
  3399. case BL_SKILL:
  3400. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3401. break;
  3402. default:
  3403. clif_getareachar_unit(tsd,bl);
  3404. break;
  3405. }
  3406. }
  3407. if (sd && sd->fd)
  3408. { //Tell sd that tbl walked into his view
  3409. clif_getareachar_unit(sd,tbl);
  3410. }
  3411. return 0;
  3412. }
  3413. /*==========================================
  3414. *
  3415. *------------------------------------------*/
  3416. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3417. {
  3418. int fd,id;
  3419. nullpo_retr(0, sd);
  3420. fd=sd->fd;
  3421. if( (id=sd->status.skill[skillid].id) <= 0 )
  3422. return 0;
  3423. WFIFOHEAD(fd,packet_len(0x147));
  3424. WFIFOW(fd,0)=0x147;
  3425. WFIFOW(fd,2) = id;
  3426. if(type < 0)
  3427. WFIFOW(fd,4) = skill_get_inf(id);
  3428. else
  3429. WFIFOW(fd,4) = type;
  3430. WFIFOW(fd,6) = 0;
  3431. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3432. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3433. if(range < 0)
  3434. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3435. WFIFOW(fd,12)= range;
  3436. safestrncpy((char*)WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3437. if(sd->status.skill[skillid].flag ==0)
  3438. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3439. else
  3440. WFIFOB(fd,38) = 0;
  3441. WFIFOSET(fd,packet_len(0x147));
  3442. return 0;
  3443. }
  3444. /*==========================================
  3445. * スキルリストを送信する
  3446. *------------------------------------------*/
  3447. int clif_skillinfoblock(struct map_session_data *sd)
  3448. {
  3449. int fd;
  3450. int i,c,len,id;
  3451. nullpo_retr(0, sd);
  3452. fd=sd->fd;
  3453. if (!fd) return 0;
  3454. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3455. WFIFOW(fd,0) = 0x10f;
  3456. for ( i = 0, c = 0, len = 4; i < MAX_SKILL; i++)
  3457. {
  3458. if( (id = sd->status.skill[i].id) != 0 )
  3459. {
  3460. WFIFOW(fd,len) = id;
  3461. WFIFOW(fd,len+2) = skill_get_inf(id);
  3462. WFIFOW(fd,len+4) = 0;
  3463. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3464. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3465. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3466. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3467. if(sd->status.skill[i].flag == 0)
  3468. WFIFOB(fd,len+36) = (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3469. else
  3470. WFIFOB(fd,len+36) = 0;
  3471. len += 37;
  3472. c++;
  3473. }
  3474. }
  3475. WFIFOW(fd,2)=len;
  3476. WFIFOSET(fd,len);
  3477. return 1;
  3478. }
  3479. /*==========================================
  3480. * スキル割り振り通知
  3481. *------------------------------------------*/
  3482. int clif_skillup(struct map_session_data *sd,int skill_num)
  3483. {
  3484. int fd;
  3485. nullpo_retr(0, sd);
  3486. fd=sd->fd;
  3487. WFIFOHEAD(fd,packet_len(0x10e));
  3488. WFIFOW(fd,0) = 0x10e;
  3489. WFIFOW(fd,2) = skill_num;
  3490. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3491. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3492. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3493. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3494. WFIFOSET(fd,packet_len(0x10e));
  3495. return 0;
  3496. }
  3497. /*==========================================
  3498. * スキル詠唱エフェクトを送信する
  3499. *------------------------------------------*/
  3500. int clif_skillcasting(struct block_list* bl,
  3501. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int pl, int casttime)
  3502. {
  3503. unsigned char buf[32];
  3504. WBUFW(buf,0) = 0x13e;
  3505. WBUFL(buf,2) = src_id;
  3506. WBUFL(buf,6) = dst_id;
  3507. WBUFW(buf,10) = dst_x;
  3508. WBUFW(buf,12) = dst_y;
  3509. WBUFW(buf,14) = skill_num;
  3510. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3511. WBUFL(buf,20) = casttime;
  3512. if (disguised(bl)) {
  3513. clif_send(buf,packet_len(0x13e), bl, AREA_WOS);
  3514. WBUFL(buf,2) = -src_id;
  3515. clif_send(buf,packet_len(0x13e), bl, SELF);
  3516. } else
  3517. clif_send(buf,packet_len(0x13e), bl, AREA);
  3518. return 0;
  3519. }
  3520. /*==========================================
  3521. *
  3522. *------------------------------------------*/
  3523. int clif_skillcastcancel(struct block_list* bl)
  3524. {
  3525. unsigned char buf[16];
  3526. nullpo_retr(0, bl);
  3527. WBUFW(buf,0) = 0x1b9;
  3528. WBUFL(buf,2) = bl->id;
  3529. clif_send(buf,packet_len(0x1b9), bl, AREA);
  3530. return 0;
  3531. }
  3532. /// only when type==0:
  3533. /// if(skill_id==NV_BASIC)
  3534. /// btype==0 "skill failed" MsgStringTable[159]
  3535. /// btype==1 "no emotions" MsgStringTable[160]
  3536. /// btype==2 "no sit" MsgStringTable[161]
  3537. /// btype==3 "no chat" MsgStringTable[162]
  3538. /// btype==4 "no party" MsgStringTable[163]
  3539. /// btype==5 "no shout" MsgStringTable[164]
  3540. /// btype==6 "no PKing" MsgStringTable[165]
  3541. /// btype==7 "no alligning" MsgStringTable[383]
  3542. /// btype>=8: ignored
  3543. /// if(skill_id==AL_WARP) "not enough skill level" MsgStringTable[214]
  3544. /// if(skill_id==TF_STEAL) "steal failed" MsgStringTable[205]
  3545. /// if(skill_id==TF_POISON) "envenom failed" MsgStringTable[207]
  3546. /// otherwise "skill failed" MsgStringTable[204]
  3547. /// btype irrelevant
  3548. /// type==1 "insufficient SP" MsgStringTable[202]
  3549. /// type==2 "insufficient HP" MsgStringTable[203]
  3550. /// type==3 "insufficient materials" MsgStringTable[808]
  3551. /// type==4 "there is a delay after using a skill" MsgStringTable[219]
  3552. /// type==5 "insufficient zeny" MsgStringTable[233]
  3553. /// type==6 "wrong weapon" MsgStringTable[239]
  3554. /// type==7 "red gemstone needed" MsgStringTable[246]
  3555. /// type==8 "blue gemstone needed" MsgStringTable[247]
  3556. /// type==9 "overweight" MsgStringTable[580]
  3557. /// type==10 "skill failed" MsgStringTable[285]
  3558. /// type>=11 ignored
  3559. ///
  3560. /// if(success!=0) doesn't display any of the previous messages
  3561. /// Note: when this packet is received an unknown flag is always set to 0,
  3562. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  3563. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3564. {
  3565. int fd;
  3566. if (!sd) { //Since this is the most common nullpo....
  3567. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3568. return 0;
  3569. }
  3570. fd=sd->fd;
  3571. if (!fd) return 0;
  3572. if(battle_config.display_skill_fail&1)
  3573. return 0; //Disable all skill failed messages
  3574. if(type==0x4 && !sd->state.showdelay)
  3575. return 0; //Disable delay failed messages
  3576. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3577. return 0;
  3578. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3579. return 0;
  3580. WFIFOHEAD(fd,packet_len(0x110));
  3581. WFIFOW(fd,0) = 0x110;
  3582. WFIFOW(fd,2) = skill_id;
  3583. WFIFOL(fd,4) = btype;
  3584. WFIFOB(fd,8) = 0;// success?
  3585. WFIFOB(fd,9) = type;
  3586. WFIFOSET(fd,packet_len(0x110));
  3587. return 1;
  3588. }
  3589. /*==========================================
  3590. * skill attack effect and damage
  3591. * 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
  3592. *------------------------------------------*/
  3593. 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)
  3594. {
  3595. unsigned char buf[64];
  3596. struct status_change *sc;
  3597. nullpo_retr(0, src);
  3598. nullpo_retr(0, dst);
  3599. type = clif_calc_delay(type,div,damage,ddelay);
  3600. sc = status_get_sc(dst);
  3601. if(sc && sc->count) {
  3602. if(sc->data[SC_HALLUCINATION] && damage)
  3603. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3604. }
  3605. #if PACKETVER < 3
  3606. WBUFW(buf,0)=0x114;
  3607. WBUFW(buf,2)=skill_id;
  3608. WBUFL(buf,4)=src->id;
  3609. WBUFL(buf,8)=dst->id;
  3610. WBUFL(buf,12)=tick;
  3611. WBUFL(buf,16)=sdelay;
  3612. WBUFL(buf,20)=ddelay;
  3613. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3614. WBUFW(buf,24)=damage?div:0;
  3615. } else {
  3616. WBUFW(buf,24)=damage;
  3617. }
  3618. WBUFW(buf,26)=skill_lv;
  3619. WBUFW(buf,28)=div;
  3620. WBUFB(buf,30)=type;
  3621. if (disguised(dst)) {
  3622. clif_send(buf,packet_len(0x114),dst,AREA_WOS);
  3623. WBUFL(buf,8)=-dst->id;
  3624. clif_send(buf,packet_len(0x114),dst,SELF);
  3625. } else
  3626. clif_send(buf,packet_len(0x114),dst,AREA);
  3627. if(disguised(src)) {
  3628. WBUFL(buf,4)=-src->id;
  3629. if (disguised(dst))
  3630. WBUFL(buf,8)=dst->id;
  3631. if(damage > 0)
  3632. WBUFW(buf,24)=-1;
  3633. clif_send(buf,packet_len(0x114),src,SELF);
  3634. }
  3635. #else
  3636. WBUFW(buf,0)=0x1de;
  3637. WBUFW(buf,2)=skill_id;
  3638. WBUFL(buf,4)=src->id;
  3639. WBUFL(buf,8)=dst->id;
  3640. WBUFL(buf,12)=tick;
  3641. WBUFL(buf,16)=sdelay;
  3642. WBUFL(buf,20)=ddelay;
  3643. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3644. WBUFL(buf,24)=damage?div:0;
  3645. } else {
  3646. WBUFL(buf,24)=damage;
  3647. }
  3648. WBUFW(buf,28)=skill_lv;
  3649. WBUFW(buf,30)=div;
  3650. WBUFB(buf,32)=type;
  3651. if (disguised(dst)) {
  3652. clif_send(buf,packet_len(0x1de),dst,AREA_WOS);
  3653. WBUFL(buf,8)=-dst->id;
  3654. clif_send(buf,packet_len(0x1de),dst,SELF);
  3655. } else
  3656. clif_send(buf,packet_len(0x1de),dst,AREA);
  3657. if(disguised(src)) {
  3658. WBUFL(buf,4)=-src->id;
  3659. if (disguised(dst))
  3660. WBUFL(buf,8)=dst->id;
  3661. if(damage > 0)
  3662. WBUFL(buf,24)=-1;
  3663. clif_send(buf,packet_len(0x1de),src,SELF);
  3664. }
  3665. #endif
  3666. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3667. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3668. }
  3669. /*==========================================
  3670. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3671. *------------------------------------------*/
  3672. /*
  3673. 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)
  3674. {
  3675. unsigned char buf[64];
  3676. struct status_change *sc;
  3677. nullpo_retr(0, src);
  3678. nullpo_retr(0, dst);
  3679. type = (type>0)?type:skill_get_hit(skill_id);
  3680. type = clif_calc_delay(type,div,damage,ddelay);
  3681. sc = status_get_sc(dst);
  3682. if(sc && sc->count) {
  3683. if(sc->data[SC_HALLUCINATION] && damage)
  3684. damage = damage*(sc->data[SC_HALLUCINATION]->val2) + rand()%100;
  3685. }
  3686. WBUFW(buf,0)=0x115;
  3687. WBUFW(buf,2)=skill_id;
  3688. WBUFL(buf,4)=src->id;
  3689. WBUFL(buf,8)=dst->id;
  3690. WBUFL(buf,12)=tick;
  3691. WBUFL(buf,16)=sdelay;
  3692. WBUFL(buf,20)=ddelay;
  3693. WBUFW(buf,24)=dst->x;
  3694. WBUFW(buf,26)=dst->y;
  3695. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3696. WBUFW(buf,28)=damage?div:0;
  3697. } else {
  3698. WBUFW(buf,28)=damage;
  3699. }
  3700. WBUFW(buf,30)=skill_lv;
  3701. WBUFW(buf,32)=div;
  3702. WBUFB(buf,34)=type;
  3703. clif_send(buf,packet_len(0x115),src,AREA);
  3704. if(disguised(src)) {
  3705. WBUFL(buf,4)=-src->id;
  3706. if(damage > 0)
  3707. WBUFW(buf,28)=-1;
  3708. clif_send(buf,packet_len(0x115),src,SELF);
  3709. }
  3710. if (disguised(dst)) {
  3711. WBUFL(buf,8)=-dst->id;
  3712. if (disguised(src))
  3713. WBUFL(buf,4)=src->id;
  3714. else if(damage > 0)
  3715. WBUFW(buf,28)=-1;
  3716. clif_send(buf,packet_len(0x115),dst,SELF);
  3717. }
  3718. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3719. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3720. }
  3721. */
  3722. /*==========================================
  3723. * 支援/回復スキルエフェクト
  3724. *------------------------------------------*/
  3725. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,int skill_id,int heal,int fail)
  3726. {
  3727. unsigned char buf[32];
  3728. nullpo_retr(0, dst);
  3729. WBUFW(buf,0)=0x11a;
  3730. WBUFW(buf,2)=skill_id;
  3731. WBUFW(buf,4)=min(heal, SHRT_MAX);
  3732. WBUFL(buf,6)=dst->id;
  3733. WBUFL(buf,10)=src?src->id:0;
  3734. WBUFB(buf,14)=fail;
  3735. if (disguised(dst)) {
  3736. clif_send(buf,packet_len(0x11a),dst,AREA_WOS);
  3737. WBUFL(buf,6)=-dst->id;
  3738. clif_send(buf,packet_len(0x11a),dst,SELF);
  3739. } else
  3740. clif_send(buf,packet_len(0x11a),dst,AREA);
  3741. if(src && disguised(src)) {
  3742. WBUFL(buf,10)=-src->id;
  3743. if (disguised(dst))
  3744. WBUFL(buf,6)=dst->id;
  3745. clif_send(buf,packet_len(0x11a),src,SELF);
  3746. }
  3747. return fail;
  3748. }
  3749. /*==========================================
  3750. * 場所スキルエフェクト
  3751. *------------------------------------------*/
  3752. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  3753. {
  3754. unsigned char buf[32];
  3755. nullpo_retr(0, src);
  3756. WBUFW(buf,0)=0x117;
  3757. WBUFW(buf,2)=skill_id;
  3758. WBUFL(buf,4)=src->id;
  3759. WBUFW(buf,8)=val;
  3760. WBUFW(buf,10)=x;
  3761. WBUFW(buf,12)=y;
  3762. WBUFL(buf,14)=tick;
  3763. if(disguised(src)) {
  3764. clif_send(buf,packet_len(0x117),src,AREA_WOS);
  3765. WBUFL(buf,4)=-src->id;
  3766. clif_send(buf,packet_len(0x117),src,SELF);
  3767. } else
  3768. clif_send(buf,packet_len(0x117),src,AREA);
  3769. return 0;
  3770. }
  3771. /*==========================================
  3772. * 場所スキルエフェクト表示
  3773. *------------------------------------------*/
  3774. //FIXME: this is just an AREA version of clif_getareachar_skillunit()
  3775. void clif_skill_setunit(struct skill_unit *unit)
  3776. {
  3777. unsigned char buf[128];
  3778. nullpo_retv(unit);
  3779. #if PACKETVER >= 3
  3780. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3781. WBUFW(buf, 0)=0x1c9;
  3782. WBUFL(buf, 2)=unit->bl.id;
  3783. WBUFL(buf, 6)=unit->group->src_id;
  3784. WBUFW(buf,10)=unit->bl.x;
  3785. WBUFW(buf,12)=unit->bl.y;
  3786. WBUFB(buf,14)=unit->group->unit_id;
  3787. WBUFB(buf,15)=1;
  3788. WBUFB(buf,16)=1;
  3789. safestrncpy((char*)WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  3790. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  3791. return;
  3792. }
  3793. #endif
  3794. WBUFW(buf, 0)=0x11f;
  3795. WBUFL(buf, 2)=unit->bl.id;
  3796. WBUFL(buf, 6)=unit->group->src_id;
  3797. WBUFW(buf,10)=unit->bl.x;
  3798. WBUFW(buf,12)=unit->bl.y;
  3799. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE)
  3800. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  3801. else
  3802. WBUFB(buf,14)=unit->group->unit_id;
  3803. WBUFB(buf,15)=1; // ignored by client (always gets set to 1)
  3804. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  3805. }
  3806. /*==========================================
  3807. * ワープ場所選択
  3808. *------------------------------------------*/
  3809. 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)
  3810. {
  3811. int fd;
  3812. nullpo_retv(sd);
  3813. fd = sd->fd;
  3814. WFIFOHEAD(fd,packet_len(0x11c));
  3815. WFIFOW(fd,0) = 0x11c;
  3816. WFIFOW(fd,2) = skill_num;
  3817. memset(WFIFOP(fd,4), 0x00, 4*MAP_NAME_LENGTH_EXT);
  3818. if (map1 == (unsigned short)-1) strcpy((char*)WFIFOP(fd,4), "Random");
  3819. else // normal map name
  3820. if (map1 > 0) mapindex_getmapname_ext(mapindex_id2name(map1), (char*)WFIFOP(fd,4));
  3821. if (map2 > 0) mapindex_getmapname_ext(mapindex_id2name(map2), (char*)WFIFOP(fd,20));
  3822. if (map3 > 0) mapindex_getmapname_ext(mapindex_id2name(map3), (char*)WFIFOP(fd,36));
  3823. if (map4 > 0) mapindex_getmapname_ext(mapindex_id2name(map4), (char*)WFIFOP(fd,52));
  3824. WFIFOSET(fd,packet_len(0x11c));
  3825. sd->menuskill_id = skill_num;
  3826. if (skill_num == AL_WARP)
  3827. sd->menuskill_val = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  3828. else
  3829. sd->menuskill_val = skill_lv;
  3830. }
  3831. /// Memo message.
  3832. /// type=0 : "Saved location as a Memo Point for Warp skill." in color 0xFFFF00 (cyan)
  3833. /// type=1 : "Skill Level is not high enough." in color 0x0000FF (red)
  3834. /// type=2 : "You haven't learned Warp." in color 0x0000FF (red)
  3835. ///
  3836. /// @param sd Who receives the message
  3837. /// @param type What message
  3838. void clif_skill_memomessage(struct map_session_data* sd, int type)
  3839. {
  3840. int fd;
  3841. nullpo_retv(sd);
  3842. fd=sd->fd;
  3843. WFIFOHEAD(fd,packet_len(0x11e));
  3844. WFIFOW(fd,0)=0x11e;
  3845. WFIFOB(fd,2)=type;
  3846. WFIFOSET(fd,packet_len(0x11e));
  3847. }
  3848. /// Teleport message.
  3849. /// type=0 : "Unable to Teleport in this area" in color 0xFFFF00 (cyan)
  3850. /// type=1 : "Saved point cannot be memorized." in color 0x0000FF (red)
  3851. ///
  3852. /// @param sd Who receives the message
  3853. /// @param type What message
  3854. void clif_skill_teleportmessage(struct map_session_data *sd, int type)
  3855. {
  3856. int fd;
  3857. nullpo_retv(sd);
  3858. fd=sd->fd;
  3859. WFIFOHEAD(fd,packet_len(0x189));
  3860. WFIFOW(fd,0)=0x189;
  3861. WFIFOW(fd,2)=type;
  3862. WFIFOSET(fd,packet_len(0x189));
  3863. }
  3864. /*==========================================
  3865. * モンスター情報
  3866. *------------------------------------------*/
  3867. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  3868. {
  3869. struct status_data *status;
  3870. unsigned char buf[64];
  3871. int i;//, fix;
  3872. nullpo_retr(0, sd);
  3873. nullpo_retr(0, dst);
  3874. if( dst->type != BL_MOB )
  3875. return 0;
  3876. status = status_get_status_data(dst);
  3877. WBUFW(buf, 0)=0x18c;
  3878. WBUFW(buf, 2)=status_get_class(dst);
  3879. WBUFW(buf, 4)=status_get_lv(dst);
  3880. WBUFW(buf, 6)=status->size;
  3881. WBUFL(buf, 8)=status->hp;
  3882. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  3883. +(battle_config.estimation_type&2?status->def2:0);
  3884. WBUFW(buf,14)=status->race;
  3885. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  3886. +(battle_config.estimation_type&2?status->mdef2:0);
  3887. WBUFW(buf,18)= status->def_ele;
  3888. for(i=0;i<9;i++)
  3889. WBUFB(buf,20+i)= (unsigned char)battle_attr_ratio(i+1,status->def_ele, status->ele_lv);
  3890. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  3891. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_ratio(i+1,status->def_ele, status->ele_lv))<0?0:fix);
  3892. clif_send(buf,packet_len(0x18c),&sd->bl,sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  3893. return 0;
  3894. }
  3895. /*==========================================
  3896. * アイテム合成可能リスト
  3897. *------------------------------------------*/
  3898. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  3899. {
  3900. int i,c,view,fd;
  3901. nullpo_retr(0, sd);
  3902. if(sd->menuskill_id == AM_PHARMACY)
  3903. return 0; //Avoid resending the menu twice or more times...
  3904. fd=sd->fd;
  3905. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  3906. WFIFOW(fd, 0)=0x18d;
  3907. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  3908. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  3909. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  3910. WFIFOW(fd,c*8+ 4)= view;
  3911. else
  3912. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  3913. WFIFOW(fd,c*8+ 6)= 0x0012;
  3914. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  3915. c++;
  3916. }
  3917. }
  3918. WFIFOW(fd, 2)=c*8+8;
  3919. WFIFOSET(fd,WFIFOW(fd,2));
  3920. if(c > 0) {
  3921. sd->menuskill_id = AM_PHARMACY;
  3922. sd->menuskill_val = trigger;
  3923. return 1;
  3924. }
  3925. return 0;
  3926. }
  3927. /*==========================================
  3928. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  3929. *------------------------------------------*/
  3930. int clif_status_load(struct block_list *bl,int type, int flag)
  3931. {
  3932. int fd;
  3933. if (type == SI_BLANK) //It shows nothing on the client...
  3934. return 0;
  3935. if (bl->type != BL_PC)
  3936. return 0;
  3937. fd = ((struct map_session_data*)bl)->fd;
  3938. WFIFOHEAD(fd,packet_len(0x196));
  3939. WFIFOW(fd,0)=0x0196;
  3940. WFIFOW(fd,2)=type;
  3941. WFIFOL(fd,4)=bl->id;
  3942. WFIFOB(fd,8)=flag; //Status start
  3943. WFIFOSET(fd, packet_len(0x196));
  3944. return 0;
  3945. }
  3946. /*==========================================
  3947. * 状態異常アイコン/メッセージ表示
  3948. *------------------------------------------*/
  3949. int clif_status_change(struct block_list *bl,int type,int flag)
  3950. {
  3951. unsigned char buf[16];
  3952. if (type == SI_BLANK) //It shows nothing on the client...
  3953. return 0;
  3954. nullpo_retr(0, bl);
  3955. WBUFW(buf,0)=0x0196;
  3956. WBUFW(buf,2)=type;
  3957. WBUFL(buf,4)=bl->id;
  3958. WBUFB(buf,8)=flag;
  3959. clif_send(buf,packet_len(0x196),bl,AREA);
  3960. return 0;
  3961. }
  3962. /*==========================================
  3963. * Send message (modified by [Yor])
  3964. *------------------------------------------*/
  3965. int clif_displaymessage(const int fd, const char* mes)
  3966. {
  3967. // invalid pointer?
  3968. nullpo_retr(-1, mes);
  3969. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  3970. if (fd == 0)
  3971. return 0;
  3972. else {
  3973. int len_mes = strlen(mes);
  3974. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  3975. WFIFOHEAD(fd, 5 + len_mes);
  3976. WFIFOW(fd,0) = 0x8e;
  3977. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  3978. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  3979. WFIFOSET(fd, 5 + len_mes);
  3980. }
  3981. }
  3982. return 0;
  3983. }
  3984. /*==========================================
  3985. * 天の声を送信する
  3986. *------------------------------------------*/
  3987. int clif_GMmessage(struct block_list* bl, const char* mes, int len, int flag)
  3988. {
  3989. unsigned char *buf;
  3990. int lp;
  3991. lp = (flag & 0x10) ? 8 : 4;
  3992. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  3993. WBUFW(buf,0) = 0x9a;
  3994. WBUFW(buf,2) = len + lp;
  3995. WBUFL(buf,4) = 0x65756c62; //"blue":
  3996. memcpy(WBUFP(buf,lp), mes, len);
  3997. flag &= 0x07;
  3998. clif_send(buf, WBUFW(buf,2), bl,
  3999. (flag == 1) ? ALL_SAMEMAP :
  4000. (flag == 2) ? AREA :
  4001. (flag == 3) ? SELF :
  4002. ALL_CLIENT);
  4003. if(buf) aFree(buf);
  4004. return 0;
  4005. }
  4006. /*==========================================
  4007. * グローバルメッセージ
  4008. *------------------------------------------*/
  4009. void clif_GlobalMessage(struct block_list* bl, const char* message)
  4010. {
  4011. char buf[100];
  4012. int len;
  4013. nullpo_retv(bl);
  4014. if(!message)
  4015. return;
  4016. len = strlen(message)+1;
  4017. WBUFW(buf,0)=0x8d;
  4018. WBUFW(buf,2)=len+8;
  4019. WBUFL(buf,4)=bl->id;
  4020. strncpy((char *) WBUFP(buf,8),message,len);
  4021. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4022. }
  4023. /*==========================================
  4024. * Send main chat message [LuzZza]
  4025. *------------------------------------------*/
  4026. void clif_MainChatMessage(const char* message)
  4027. {
  4028. char buf[200];
  4029. int len;
  4030. if(!message)
  4031. return;
  4032. len = strlen(message)+1;
  4033. if (len+8 > sizeof(buf)) {
  4034. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4035. len = sizeof(buf)-8;
  4036. }
  4037. WBUFW(buf,0)=0x8d;
  4038. WBUFW(buf,2)=len+8;
  4039. WBUFL(buf,4)=0;
  4040. strncpy((char *) WBUFP(buf,8),message,len);
  4041. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4042. }
  4043. /*==========================================
  4044. * Does an announce message in the given color.
  4045. *------------------------------------------*/
  4046. int clif_announce(struct block_list* bl, const char* mes, int len, unsigned long color, int flag)
  4047. {
  4048. return clif_announce_ex(bl, mes, len, color, flag, 12);
  4049. }
  4050. int clif_announce_ex(struct block_list* bl, const char* mes, int len, unsigned long color, int flag, int size)
  4051. {
  4052. unsigned char *buf;
  4053. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4054. WBUFW(buf,0) = 0x1c3;
  4055. WBUFW(buf,2) = len + 16;
  4056. WBUFL(buf,4) = color;
  4057. WBUFW(buf,8) = 0x190; //Font style? Type?
  4058. WBUFW(buf,10) = size; // Font size
  4059. WBUFL(buf,12) = 0; //Unknown!
  4060. memcpy(WBUFP(buf,16), mes, len);
  4061. flag &= 0x07;
  4062. clif_send(buf, WBUFW(buf,2), bl,
  4063. (flag == 1) ? ALL_SAMEMAP :
  4064. (flag == 2) ? AREA :
  4065. (flag == 3) ? SELF :
  4066. ALL_CLIENT);
  4067. if(buf) aFree(buf);
  4068. return 0;
  4069. }
  4070. /*==========================================
  4071. * HPSP回復エフェクトを送信する
  4072. *------------------------------------------*/
  4073. int clif_heal(int fd,int type,int val)
  4074. {
  4075. WFIFOHEAD(fd,packet_len(0x13d));
  4076. WFIFOW(fd,0)=0x13d;
  4077. WFIFOW(fd,2)=type;
  4078. WFIFOW(fd,4)=cap_value(val,0,SHRT_MAX);
  4079. WFIFOSET(fd,packet_len(0x13d));
  4080. return 0;
  4081. }
  4082. /*==========================================
  4083. * 復活する
  4084. *------------------------------------------*/
  4085. int clif_resurrection(struct block_list *bl,int type)
  4086. {
  4087. unsigned char buf[16];
  4088. nullpo_retr(0, bl);
  4089. WBUFW(buf,0)=0x148;
  4090. WBUFL(buf,2)=bl->id;
  4091. WBUFW(buf,6)=type;
  4092. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4093. if (disguised(bl))
  4094. clif_spawn(bl);
  4095. return 0;
  4096. }
  4097. /// Sets the map mode.
  4098. ///
  4099. /// mode=1 : pvp mode
  4100. /// mode=2 : unknown mode (pk?)
  4101. /// mode=3 : gvg mode
  4102. /// mode=4 : message "You are in a PK area. Please beware of sudden attacks." in color 0x9B9BFF (light red)
  4103. /// mode=5 : pvp mode
  4104. /// mode=other : ?
  4105. void clif_set0199(struct map_session_data* sd, int mode)
  4106. {
  4107. int fd;
  4108. nullpo_retv(sd);
  4109. fd=sd->fd;
  4110. WFIFOHEAD(fd,packet_len(0x199));
  4111. WFIFOW(fd,0)=0x199;
  4112. WFIFOW(fd,2)=mode;
  4113. WFIFOSET(fd,packet_len(0x199));
  4114. }
  4115. #if 0
  4116. /// Set the map mode?
  4117. /// Differs from the behaviour of clif_set0199 with unknown consequences.
  4118. void clif_set01D6(struct map_session_data* sd, int mode)
  4119. {
  4120. int fd;
  4121. nullpo_retv(sd);
  4122. fd=sd->fd;
  4123. WFIFOHEAD(fd,packet_len(0x1D6));
  4124. WFIFOW(fd,0)=0x1D6;
  4125. WFIFOW(fd,2)=mode;
  4126. WFIFOSET(fd,packet_len(0x1D6));
  4127. }
  4128. #endif
  4129. /*==========================================
  4130. * PVP実装?(仮)
  4131. *------------------------------------------*/
  4132. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4133. {
  4134. if(type == 2) {
  4135. int fd = sd->fd;
  4136. WFIFOHEAD(fd,packet_len(0x19a));
  4137. WFIFOW(fd,0) = 0x19a;
  4138. WFIFOL(fd,2) = sd->bl.id;
  4139. WFIFOL(fd,6) = pvprank;
  4140. WFIFOL(fd,10) = pvpnum;
  4141. WFIFOSET(fd,packet_len(0x19a));
  4142. } else {
  4143. unsigned char buf[32];
  4144. WBUFW(buf,0) = 0x19a;
  4145. WBUFL(buf,2) = sd->bl.id;
  4146. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4147. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4148. else
  4149. WBUFL(buf,6) = pvprank;
  4150. WBUFL(buf,10) = pvpnum;
  4151. if(sd->sc.option&OPTION_INVISIBLE || sd->disguise) //Causes crashes when a 'mob' with pvp info dies.
  4152. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4153. else if(!type)
  4154. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4155. else
  4156. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4157. }
  4158. return 0;
  4159. }
  4160. /*==========================================
  4161. *
  4162. *------------------------------------------*/
  4163. int clif_send0199(int map,int type)
  4164. {
  4165. struct block_list bl;
  4166. unsigned char buf[16];
  4167. bl.id = 0;
  4168. bl.type = BL_NUL;
  4169. bl.m = map;
  4170. WBUFW(buf,0)=0x199;
  4171. WBUFW(buf,2)=type;
  4172. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4173. return 0;
  4174. }
  4175. /*==========================================
  4176. * 精錬エフェクトを送信する
  4177. *------------------------------------------*/
  4178. void clif_refine(int fd, int fail, int index, int val)
  4179. {
  4180. WFIFOHEAD(fd,packet_len(0x188));
  4181. WFIFOW(fd,0)=0x188;
  4182. WFIFOW(fd,2)=fail;
  4183. WFIFOW(fd,4)=index+2;
  4184. WFIFOW(fd,6)=val;
  4185. WFIFOSET(fd,packet_len(0x188));
  4186. }
  4187. /// result=0: "weapon upgrated: %s" MsgStringTable[911] in rgb(0,255,255)
  4188. /// result=1: "weapon upgrated: %s" MsgStringTable[912] in rgb(0,205,205)
  4189. /// result=2: "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4190. /// result=3: "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4191. void clif_upgrademessage(int fd, int result, int item_id)
  4192. {
  4193. WFIFOHEAD(fd,packet_len(0x223));
  4194. WFIFOW(fd,0)=0x223;
  4195. WFIFOL(fd,2)=result;
  4196. WFIFOW(fd,6)=item_id;
  4197. WFIFOSET(fd,packet_len(0x223));
  4198. }
  4199. /*==========================================
  4200. * Wisp/page is transmitted to the destination player
  4201. * R 0097 <len>.w <nick>.24B <message>.?B
  4202. *------------------------------------------*/
  4203. int clif_wis_message(int fd, const char* nick, const char* mes, int mes_len)
  4204. {
  4205. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4206. WFIFOW(fd,0) = 0x97;
  4207. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4208. safestrncpy((char*)WFIFOP(fd,4), nick, NAME_LENGTH);
  4209. safestrncpy((char*)WFIFOP(fd,28), mes, mes_len);
  4210. WFIFOSET(fd,WFIFOW(fd,2));
  4211. return 0;
  4212. }
  4213. /*==========================================
  4214. * Inform the player about the result of his whisper action
  4215. * R 0098 <type>.B
  4216. * 0: success to send wisper
  4217. * 1: target character is not loged in
  4218. * 2: ignored by target
  4219. * 3: everyone ignored by target
  4220. *------------------------------------------*/
  4221. int clif_wis_end(int fd, int flag)
  4222. {
  4223. WFIFOHEAD(fd,packet_len(0x98));
  4224. WFIFOW(fd,0) = 0x98;
  4225. WFIFOW(fd,2) = flag;
  4226. WFIFOSET(fd,packet_len(0x98));
  4227. return 0;
  4228. }
  4229. /*==========================================
  4230. * キャラID名前引き結果を送信する
  4231. *------------------------------------------*/
  4232. int clif_solved_charname(int fd, int charid, const char* name)
  4233. {
  4234. WFIFOHEAD(fd,packet_len(0x194));
  4235. WFIFOW(fd,0)=0x194;
  4236. WFIFOL(fd,2)=charid;
  4237. safestrncpy((char*)WFIFOP(fd,6), name, NAME_LENGTH);
  4238. WFIFOSET(fd,packet_len(0x194));
  4239. return 0;
  4240. }
  4241. /*==========================================
  4242. * カードの挿入可能リストを返す
  4243. *------------------------------------------*/
  4244. int clif_use_card(struct map_session_data *sd,int idx)
  4245. {
  4246. int i,c,ep;
  4247. int fd=sd->fd;
  4248. nullpo_retr(0, sd);
  4249. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4250. return 0;
  4251. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4252. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4253. ep=sd->inventory_data[idx]->equip;
  4254. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4255. WFIFOW(fd,0)=0x017b;
  4256. for(i=c=0;i<MAX_INVENTORY;i++){
  4257. int j;
  4258. if(sd->inventory_data[i] == NULL)
  4259. continue;
  4260. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4261. continue;
  4262. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4263. continue;
  4264. if(sd->status.inventory[i].identify==0 ) //Not identified
  4265. continue;
  4266. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4267. continue;
  4268. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_SHIELD) //Shield card won't go on left weapon.
  4269. continue;
  4270. ARR_FIND( 0, sd->inventory_data[i]->slot, j, sd->status.inventory[i].card[j] == 0 );
  4271. if( j == sd->inventory_data[i]->slot ) // No room
  4272. continue;
  4273. WFIFOW(fd,4+c*2)=i+2;
  4274. c++;
  4275. }
  4276. WFIFOW(fd,2)=4+c*2;
  4277. WFIFOSET(fd,WFIFOW(fd,2));
  4278. return 0;
  4279. }
  4280. /*==========================================
  4281. * カードの挿入終了
  4282. *------------------------------------------*/
  4283. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4284. {
  4285. int fd;
  4286. nullpo_retr(0, sd);
  4287. fd=sd->fd;
  4288. WFIFOHEAD(fd,packet_len(0x17d));
  4289. WFIFOW(fd,0)=0x17d;
  4290. WFIFOW(fd,2)=idx_equip+2;
  4291. WFIFOW(fd,4)=idx_card+2;
  4292. WFIFOB(fd,6)=flag;
  4293. WFIFOSET(fd,packet_len(0x17d));
  4294. return 0;
  4295. }
  4296. /*==========================================
  4297. * 鑑定可能アイテムリスト送信
  4298. *------------------------------------------*/
  4299. int clif_item_identify_list(struct map_session_data *sd)
  4300. {
  4301. int i,c;
  4302. int fd;
  4303. nullpo_retr(0, sd);
  4304. fd=sd->fd;
  4305. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4306. WFIFOW(fd,0)=0x177;
  4307. for(i=c=0;i<MAX_INVENTORY;i++){
  4308. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4309. WFIFOW(fd,c*2+4)=i+2;
  4310. c++;
  4311. }
  4312. }
  4313. if(c > 0) {
  4314. WFIFOW(fd,2)=c*2+4;
  4315. WFIFOSET(fd,WFIFOW(fd,2));
  4316. sd->menuskill_id = MC_IDENTIFY;
  4317. sd->menuskill_val = c;
  4318. }
  4319. return 0;
  4320. }
  4321. /*==========================================
  4322. * 鑑定結果
  4323. *------------------------------------------*/
  4324. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4325. {
  4326. int fd;
  4327. nullpo_retr(0, sd);
  4328. fd=sd->fd;
  4329. WFIFOHEAD(fd,packet_len(0x179));
  4330. WFIFOW(fd, 0)=0x179;
  4331. WFIFOW(fd, 2)=idx+2;
  4332. WFIFOB(fd, 4)=flag;
  4333. WFIFOSET(fd,packet_len(0x179));
  4334. return 0;
  4335. }
  4336. /*==========================================
  4337. * 修理可能アイテムリスト送信
  4338. *------------------------------------------*/
  4339. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4340. {
  4341. int i,c;
  4342. int fd;
  4343. int nameid;
  4344. nullpo_retr(0, sd);
  4345. nullpo_retr(0, dstsd);
  4346. fd=sd->fd;
  4347. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4348. WFIFOW(fd,0)=0x1fc;
  4349. for(i=c=0;i<MAX_INVENTORY;i++){
  4350. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4351. WFIFOW(fd,c*13+4) = i;
  4352. WFIFOW(fd,c*13+6) = nameid;
  4353. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4354. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4355. WFIFOB(fd,c*13+16)= c;
  4356. c++;
  4357. }
  4358. }
  4359. if(c > 0) {
  4360. WFIFOW(fd,2)=c*13+4;
  4361. WFIFOSET(fd,WFIFOW(fd,2));
  4362. sd->menuskill_id = BS_REPAIRWEAPON;
  4363. sd->menuskill_val = dstsd->bl.id;
  4364. }else
  4365. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4366. return 0;
  4367. }
  4368. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4369. {
  4370. int view,fd;
  4371. nullpo_retr(0, sd);
  4372. fd=sd->fd;
  4373. WFIFOHEAD(fd,packet_len(0x1fe));
  4374. WFIFOW(fd, 0)=0x1fe;
  4375. if((view = itemdb_viewid(nameid)) > 0)
  4376. WFIFOW(fd, 2)=view;
  4377. else
  4378. WFIFOW(fd, 2)=nameid;
  4379. WFIFOB(fd, 4)=flag;
  4380. WFIFOSET(fd,packet_len(0x1fe));
  4381. return 0;
  4382. }
  4383. /*==========================================
  4384. * Weapon Refining - Taken from jAthena
  4385. *------------------------------------------*/
  4386. int clif_item_refine_list(struct map_session_data *sd)
  4387. {
  4388. int i,c;
  4389. int fd;
  4390. int skilllv;
  4391. int wlv;
  4392. int refine_item[5];
  4393. nullpo_retr(0, sd);
  4394. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4395. fd=sd->fd;
  4396. refine_item[0] = -1;
  4397. refine_item[1] = pc_search_inventory(sd,1010);
  4398. refine_item[2] = pc_search_inventory(sd,1011);
  4399. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4400. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4401. WFIFOW(fd,0)=0x221;
  4402. for(i=c=0;i<MAX_INVENTORY;i++){
  4403. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4404. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4405. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4406. WFIFOW(fd,c*13+ 4)=i+2;
  4407. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4408. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4409. WFIFOW(fd,c*13+10)=0;
  4410. WFIFOB(fd,c*13+12)=c;
  4411. c++;
  4412. }
  4413. }
  4414. WFIFOW(fd,2)=c*13+4;
  4415. WFIFOSET(fd,WFIFOW(fd,2));
  4416. if (c > 0) {
  4417. sd->menuskill_id = WS_WEAPONREFINE;
  4418. sd->menuskill_val = skilllv;
  4419. }
  4420. return 0;
  4421. }
  4422. /*==========================================
  4423. * アイテムによる一時的なスキル効果
  4424. *------------------------------------------*/
  4425. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  4426. {
  4427. int fd;
  4428. nullpo_retr(0, sd);
  4429. fd=sd->fd;
  4430. WFIFOHEAD(fd,packet_len(0x147));
  4431. WFIFOW(fd, 0)=0x147;
  4432. WFIFOW(fd, 2)=skillid;
  4433. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4434. WFIFOW(fd, 6)=0;
  4435. WFIFOW(fd, 8)=skilllv;
  4436. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4437. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4438. safestrncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  4439. WFIFOB(fd,38)=0;
  4440. WFIFOSET(fd,packet_len(0x147));
  4441. return 0;
  4442. }
  4443. /*==========================================
  4444. * カートにアイテム追加
  4445. *------------------------------------------*/
  4446. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4447. {
  4448. int view,fd;
  4449. unsigned char *buf;
  4450. nullpo_retr(0, sd);
  4451. fd=sd->fd;
  4452. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4453. return 1;
  4454. #if PACKETVER < 5
  4455. WFIFOHEAD(fd,packet_len(0x124));
  4456. buf=WFIFOP(fd,0);
  4457. WBUFW(buf,0)=0x124;
  4458. WBUFW(buf,2)=n+2;
  4459. WBUFL(buf,4)=amount;
  4460. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4461. WBUFW(buf,8)=view;
  4462. else
  4463. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4464. WBUFB(buf,10)=sd->status.cart[n].identify;
  4465. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4466. WBUFB(buf,12)=sd->status.cart[n].refine;
  4467. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4468. WFIFOSET(fd,packet_len(0x124));
  4469. #else
  4470. WFIFOHEAD(fd,packet_len(0x1c5));
  4471. buf=WFIFOP(fd,0);
  4472. WBUFW(buf,0)=0x1c5;
  4473. WBUFW(buf,2)=n+2;
  4474. WBUFL(buf,4)=amount;
  4475. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4476. WBUFW(buf,8)=view;
  4477. else
  4478. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4479. WBUFB(buf,10)=itemdb_type(sd->status.cart[n].nameid);
  4480. WBUFB(buf,11)=sd->status.cart[n].identify;
  4481. WBUFB(buf,12)=sd->status.cart[n].attribute;
  4482. WBUFB(buf,13)=sd->status.cart[n].refine;
  4483. clif_addcards(WBUFP(buf,14), &sd->status.cart[n]);
  4484. WFIFOSET(fd,packet_len(0x1c5));
  4485. #endif
  4486. return 0;
  4487. }
  4488. /*==========================================
  4489. * カートからアイテム削除
  4490. *------------------------------------------*/
  4491. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4492. {
  4493. int fd;
  4494. nullpo_retr(0, sd);
  4495. fd=sd->fd;
  4496. WFIFOHEAD(fd,packet_len(0x125));
  4497. WFIFOW(fd,0)=0x125;
  4498. WFIFOW(fd,2)=n+2;
  4499. WFIFOL(fd,4)=amount;
  4500. WFIFOSET(fd,packet_len(0x125));
  4501. return 0;
  4502. }
  4503. /*==========================================
  4504. * Opens the shop creation menu.
  4505. * R 012d <num>.w
  4506. * 'num' is the number of allowed item slots
  4507. *------------------------------------------*/
  4508. void clif_openvendingreq(struct map_session_data* sd, int num)
  4509. {
  4510. int fd;
  4511. nullpo_retv(sd);
  4512. fd = sd->fd;
  4513. WFIFOHEAD(fd,packet_len(0x12d));
  4514. WFIFOW(fd,0) = 0x12d;
  4515. WFIFOW(fd,2) = num;
  4516. WFIFOSET(fd,packet_len(0x12d));
  4517. }
  4518. /*==========================================
  4519. * Displays a vending board to target/area
  4520. * R 0131 <ID>.l <message>.80B
  4521. *------------------------------------------*/
  4522. void clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  4523. {
  4524. unsigned char buf[128];
  4525. nullpo_retv(bl);
  4526. WBUFW(buf,0) = 0x131;
  4527. WBUFL(buf,2) = bl->id;
  4528. safestrncpy((char*)WBUFP(buf,6), message, 80);
  4529. if( fd ) {
  4530. WFIFOHEAD(fd,packet_len(0x131));
  4531. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  4532. WFIFOSET(fd,packet_len(0x131));
  4533. } else {
  4534. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  4535. }
  4536. }
  4537. /*==========================================
  4538. * Removes a vending board from screen
  4539. *------------------------------------------*/
  4540. void clif_closevendingboard(struct block_list* bl, int fd)
  4541. {
  4542. unsigned char buf[16];
  4543. nullpo_retv(bl);
  4544. WBUFW(buf,0) = 0x132;
  4545. WBUFL(buf,2) = bl->id;
  4546. if( fd ) {
  4547. WFIFOHEAD(fd,packet_len(0x132));
  4548. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  4549. WFIFOSET(fd,packet_len(0x132));
  4550. } else {
  4551. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  4552. }
  4553. }
  4554. /*==========================================
  4555. * Sends a list of items in a shop
  4556. * 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
  4557. *------------------------------------------*/
  4558. void clif_vendinglist(struct map_session_data* sd, int id, struct s_vending* vending)
  4559. {
  4560. int i,fd;
  4561. int count;
  4562. struct map_session_data* vsd;
  4563. nullpo_retv(sd);
  4564. nullpo_retv(vending);
  4565. nullpo_retv(vsd=map_id2sd(id));
  4566. fd = sd->fd;
  4567. count = vsd->vend_num;
  4568. WFIFOHEAD(fd, 8+count*22);
  4569. WFIFOW(fd,0) = 0x133;
  4570. WFIFOW(fd,2) = 8+count*22;
  4571. WFIFOL(fd,4) = id;
  4572. for( i = 0; i < count; i++ )
  4573. {
  4574. int index = vending[i].index;
  4575. struct item_data* data = itemdb_search(vsd->status.cart[index].nameid);
  4576. WFIFOL(fd, 8+i*22) = vending[i].value;
  4577. WFIFOW(fd,12+i*22) = vending[i].amount;
  4578. WFIFOW(fd,14+i*22) = vending[i].index + 2;
  4579. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4580. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : vsd->status.cart[index].nameid;
  4581. WFIFOB(fd,19+i*22) = vsd->status.cart[index].identify;
  4582. WFIFOB(fd,20+i*22) = vsd->status.cart[index].attribute;
  4583. WFIFOB(fd,21+i*22) = vsd->status.cart[index].refine;
  4584. clif_addcards(WFIFOP(fd, 22+i*22), &vsd->status.cart[index]);
  4585. }
  4586. WFIFOSET(fd,WFIFOW(fd,2));
  4587. }
  4588. /*==========================================
  4589. * Shop purchase failure
  4590. * R 0135 <index>.w <amount>.w <fail>.B
  4591. * fail=1 - not enough zeny
  4592. * fail=2 - overweight
  4593. * fail=4 - out of stock
  4594. * fail=5 - "cannot use an npc shop while in a trade"
  4595. *------------------------------------------*/
  4596. void clif_buyvending(struct map_session_data* sd, int index, int amount, int fail)
  4597. {
  4598. int fd;
  4599. nullpo_retv(sd);
  4600. fd = sd->fd;
  4601. WFIFOHEAD(fd,packet_len(0x135));
  4602. WFIFOW(fd,0) = 0x135;
  4603. WFIFOW(fd,2) = index+2;
  4604. WFIFOW(fd,4) = amount;
  4605. WFIFOB(fd,6) = fail;
  4606. WFIFOSET(fd,packet_len(0x135));
  4607. }
  4608. /*==========================================
  4609. * Shop creation success
  4610. * 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*
  4611. *------------------------------------------*/
  4612. void clif_openvending(struct map_session_data* sd, int id, struct s_vending* vending)
  4613. {
  4614. int i,fd;
  4615. int count;
  4616. nullpo_retv(sd);
  4617. fd = sd->fd;
  4618. count = sd->vend_num;
  4619. WFIFOHEAD(fd, 8+count*22);
  4620. WFIFOW(fd,0) = 0x136;
  4621. WFIFOW(fd,2) = 8+count*22;
  4622. WFIFOL(fd,4) = id;
  4623. for( i = 0; i < count; i++ )
  4624. {
  4625. int index = vending[i].index;
  4626. struct item_data* data = itemdb_search(sd->status.cart[index].nameid);
  4627. WFIFOL(fd, 8+i*22) = vending[i].value;
  4628. WFIFOW(fd,12+i*22) = vending[i].index + 2;
  4629. WFIFOW(fd,14+i*22) = vending[i].amount;
  4630. WFIFOB(fd,16+i*22) = itemtype(data->type);
  4631. WFIFOW(fd,17+i*22) = ( data->view_id > 0 ) ? data->view_id : sd->status.cart[index].nameid;
  4632. WFIFOB(fd,19+i*22) = sd->status.cart[index].identify;
  4633. WFIFOB(fd,20+i*22) = sd->status.cart[index].attribute;
  4634. WFIFOB(fd,21+i*22) = sd->status.cart[index].refine;
  4635. clif_addcards(WFIFOP(fd,22+i*22), &sd->status.cart[index]);
  4636. }
  4637. WFIFOSET(fd,WFIFOW(fd,2));
  4638. }
  4639. /*==========================================
  4640. * Inform merchant that someone has bought an item.
  4641. * R 0137 <index>.w <amount>.w
  4642. *------------------------------------------*/
  4643. void clif_vendingreport(struct map_session_data* sd, int index, int amount)
  4644. {
  4645. int fd;
  4646. nullpo_retv(sd);
  4647. fd = sd->fd;
  4648. WFIFOHEAD(fd,packet_len(0x137));
  4649. WFIFOW(fd,0) = 0x137;
  4650. WFIFOW(fd,2) = index+2;
  4651. WFIFOW(fd,4) = amount;
  4652. WFIFOSET(fd,packet_len(0x137));
  4653. }
  4654. /// Result of organizing a party.
  4655. /// R 00FA <result>.B
  4656. ///
  4657. /// result=0 : opens party window and shows MsgStringTable[77]="party successfully organized"
  4658. /// result=1 : MsgStringTable[78]="party name already exists"
  4659. /// result=2 : MsgStringTable[79]="already in a party"
  4660. /// result=other : nothing
  4661. int clif_party_created(struct map_session_data *sd,int result)
  4662. {
  4663. int fd;
  4664. nullpo_retr(0, sd);
  4665. fd=sd->fd;
  4666. WFIFOHEAD(fd,packet_len(0xfa));
  4667. WFIFOW(fd,0)=0xfa;
  4668. WFIFOB(fd,2)=result;
  4669. WFIFOSET(fd,packet_len(0xfa));
  4670. return 0;
  4671. }
  4672. int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  4673. {
  4674. unsigned char buf[96];
  4675. int i;
  4676. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  4677. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd != 0 );
  4678. } else {
  4679. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  4680. }
  4681. if (i >= MAX_PARTY) return 0; //Should never happen...
  4682. sd = p->data[i].sd;
  4683. WBUFW(buf, 0) = 0x1e9;
  4684. WBUFL(buf, 2) = sd->status.account_id;
  4685. WBUFL(buf, 6) = (p->party.member[i].leader)?0:1;
  4686. WBUFW(buf,10) = sd->bl.x;
  4687. WBUFW(buf,12) = sd->bl.y;
  4688. WBUFB(buf,14) = (p->party.member[i].online)?0:1;
  4689. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  4690. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  4691. mapindex_getmapname_ext(mapindex_id2name(sd->mapindex), (char*)WBUFP(buf,63));
  4692. WBUFB(buf,79) = (p->party.item&1)?1:0;
  4693. WBUFB(buf,80) = (p->party.item&2)?1:0;
  4694. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  4695. return 1;
  4696. }
  4697. /*==========================================
  4698. * Sends party information
  4699. * R 00fb <len>.w <party name>.24B {<ID>.l <nick>.24B <map name>.16B <leader>.B <offline>.B}.46B*
  4700. *------------------------------------------*/
  4701. int clif_party_info(struct party_data* p, struct map_session_data *sd)
  4702. {
  4703. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH_EXT+1+1)*MAX_PARTY];
  4704. struct map_session_data* party_sd = NULL;
  4705. int i, c;
  4706. nullpo_retr(0, p);
  4707. WBUFW(buf,0) = 0xfb;
  4708. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  4709. for(i = 0, c = 0; i < MAX_PARTY; i++)
  4710. {
  4711. struct party_member* m = &p->party.member[i];
  4712. if(!m->account_id) continue;
  4713. if(party_sd == NULL) party_sd = p->data[i].sd;
  4714. WBUFL(buf,28+c*46) = m->account_id;
  4715. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  4716. mapindex_getmapname_ext(mapindex_id2name(m->map), (char*)WBUFP(buf,28+c*46+28));
  4717. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  4718. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  4719. c++;
  4720. }
  4721. WBUFW(buf,2) = 28+c*46;
  4722. if(sd) { // send only to self
  4723. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  4724. } else if (party_sd) { // send to whole party
  4725. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  4726. }
  4727. return 0;
  4728. }
  4729. /*==========================================
  4730. * パーティ勧誘
  4731. *------------------------------------------*/
  4732. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  4733. {
  4734. int fd;
  4735. struct party_data *p;
  4736. nullpo_retr(0, sd);
  4737. nullpo_retr(0, tsd);
  4738. fd=tsd->fd;
  4739. if( (p=party_search(sd->status.party_id))==NULL )
  4740. return 0;
  4741. WFIFOHEAD(fd,packet_len(0xfe));
  4742. WFIFOW(fd,0)=0xfe;
  4743. WFIFOL(fd,2)=sd->status.account_id;
  4744. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  4745. WFIFOSET(fd,packet_len(0xfe));
  4746. return 0;
  4747. }
  4748. /*==========================================
  4749. * Party invitation result.
  4750. * R 00fd <nick>.24S <flag>.B
  4751. * R 02c5 <nick>.24S <flag>.L
  4752. * Flag values are:
  4753. * 0 -> char is already in a party
  4754. * 1 -> party invite was rejected
  4755. * 2 -> party invite was accepted
  4756. * 3 -> party is full
  4757. * 4 -> char of the same account already joined the party
  4758. *------------------------------------------*/
  4759. void clif_party_inviteack(struct map_session_data* sd, const char* nick, int flag)
  4760. {
  4761. int fd;
  4762. nullpo_retv(sd);
  4763. fd=sd->fd;
  4764. #if PACKETVER < 20070821
  4765. WFIFOHEAD(fd,packet_len(0xfd));
  4766. WFIFOW(fd,0) = 0xfd;
  4767. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  4768. WFIFOB(fd,26) = flag;
  4769. WFIFOSET(fd,packet_len(0xfd));
  4770. #else
  4771. WFIFOHEAD(fd,packet_len(0x2c5));
  4772. WFIFOW(fd,0) = 0x2c5;
  4773. safestrncpy((char*)WFIFOP(fd,2),nick,NAME_LENGTH);
  4774. WFIFOL(fd,26) = flag;
  4775. WFIFOSET(fd,packet_len(0x2c5));
  4776. #endif
  4777. }
  4778. /*==========================================
  4779. * パーティ設定送信
  4780. * flag & 0x001=exp変更ミス
  4781. * 0x010=item変更ミス
  4782. * 0x100=一人にのみ送信
  4783. *------------------------------------------*/
  4784. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  4785. {
  4786. unsigned char buf[16];
  4787. nullpo_retr(0, p);
  4788. if(!sd && flag==0){
  4789. int i;
  4790. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4791. if (i < MAX_PARTY)
  4792. sd = p->data[i].sd;
  4793. }
  4794. if(!sd) return 0;
  4795. WBUFW(buf,0)=0x101;
  4796. // WBUFL(buf,2) // that's how the client reads it, still need to check it's uses [FlavioJS]
  4797. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  4798. WBUFW(buf,4)=0;
  4799. if(flag==0)
  4800. clif_send(buf,packet_len(0x101),&sd->bl,PARTY);
  4801. else
  4802. clif_send(buf,packet_len(0x101),&sd->bl,SELF);
  4803. return 0;
  4804. }
  4805. /*==========================================
  4806. * パーティ脱退(脱退前に呼ぶこと)
  4807. *------------------------------------------*/
  4808. int clif_party_leaved(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  4809. {
  4810. unsigned char buf[64];
  4811. int i;
  4812. nullpo_retr(0, p);
  4813. if(!sd && (flag&0xf0)==0)
  4814. {
  4815. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  4816. if (i < MAX_PARTY)
  4817. sd = p->data[i].sd;
  4818. }
  4819. if(!sd) return 0;
  4820. WBUFW(buf,0)=0x105;
  4821. WBUFL(buf,2)=account_id;
  4822. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  4823. WBUFB(buf,30)=flag&0x0f;
  4824. if((flag&0xf0)==0)
  4825. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  4826. else
  4827. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  4828. return 0;
  4829. }
  4830. /*==========================================
  4831. * パーティメッセージ送信
  4832. *------------------------------------------*/
  4833. int clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  4834. {
  4835. struct map_session_data *sd;
  4836. int i;
  4837. nullpo_retr(0, p);
  4838. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  4839. if(i < MAX_PARTY){
  4840. unsigned char buf[1024];
  4841. sd = p->data[i].sd;
  4842. WBUFW(buf,0)=0x109;
  4843. WBUFW(buf,2)=len+8;
  4844. WBUFL(buf,4)=account_id;
  4845. memcpy(WBUFP(buf,8),mes,len);
  4846. clif_send(buf,len+8,&sd->bl,PARTY);
  4847. }
  4848. return 0;
  4849. }
  4850. /*==========================================
  4851. * パーティ座標通知
  4852. *------------------------------------------*/
  4853. int clif_party_xy(struct map_session_data *sd)
  4854. {
  4855. unsigned char buf[16];
  4856. nullpo_retr(0, sd);
  4857. WBUFW(buf,0)=0x107;
  4858. WBUFL(buf,2)=sd->status.account_id;
  4859. WBUFW(buf,6)=sd->bl.x;
  4860. WBUFW(buf,8)=sd->bl.y;
  4861. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  4862. return 0;
  4863. }
  4864. /*==========================================
  4865. * Sends x/y dot to a single fd. [Skotlex]
  4866. *------------------------------------------*/
  4867. int clif_party_xy_single(int fd, struct map_session_data *sd)
  4868. {
  4869. WFIFOHEAD(fd,packet_len(0x107));
  4870. WFIFOW(fd,0)=0x107;
  4871. WFIFOL(fd,2)=sd->status.account_id;
  4872. WFIFOW(fd,6)=sd->bl.x;
  4873. WFIFOW(fd,8)=sd->bl.y;
  4874. WFIFOSET(fd,packet_len(0x107));
  4875. return 0;
  4876. }
  4877. /*==========================================
  4878. * パーティHP通知
  4879. *------------------------------------------*/
  4880. int clif_party_hp(struct map_session_data *sd)
  4881. {
  4882. unsigned char buf[16];
  4883. nullpo_retr(0, sd);
  4884. WBUFW(buf,0)=0x106;
  4885. WBUFL(buf,2)=sd->status.account_id;
  4886. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  4887. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  4888. WBUFW(buf,8) = 100;
  4889. } else {
  4890. WBUFW(buf,6) = sd->battle_status.hp;
  4891. WBUFW(buf,8) = sd->battle_status.max_hp;
  4892. }
  4893. clif_send(buf,packet_len(0x106),&sd->bl,PARTY_AREA_WOS);
  4894. return 0;
  4895. }
  4896. /*==========================================
  4897. * Sends HP bar to a single fd. [Skotlex]
  4898. *------------------------------------------*/
  4899. void clif_hpmeter_single(int fd, int id, unsigned int hp, unsigned int maxhp)
  4900. {
  4901. WFIFOHEAD(fd,packet_len(0x106));
  4902. WFIFOW(fd,0) = 0x106;
  4903. WFIFOL(fd,2) = id;
  4904. if( maxhp > SHRT_MAX )
  4905. {// To correctly display the %hp bar. [Skotlex]
  4906. WFIFOW(fd,6) = hp/(maxhp/100);
  4907. WFIFOW(fd,8) = 100;
  4908. } else {
  4909. WFIFOW(fd,6) = hp;
  4910. WFIFOW(fd,8) = maxhp;
  4911. }
  4912. WFIFOSET(fd, packet_len(0x106));
  4913. }
  4914. /*==========================================
  4915. * GMへ場所とHP通知
  4916. *------------------------------------------*/
  4917. int clif_hpmeter(struct map_session_data *sd)
  4918. {
  4919. struct map_session_data *sd2;
  4920. unsigned char buf[16];
  4921. int i, x0, y0, x1, y1;
  4922. int level;
  4923. nullpo_retr(0, sd);
  4924. x0 = sd->bl.x - AREA_SIZE;
  4925. y0 = sd->bl.y - AREA_SIZE;
  4926. x1 = sd->bl.x + AREA_SIZE;
  4927. y1 = sd->bl.y + AREA_SIZE;
  4928. WBUFW(buf,0) = 0x106;
  4929. WBUFL(buf,2) = sd->status.account_id;
  4930. if( sd->battle_status.max_hp > SHRT_MAX )
  4931. { //To correctly display the %hp bar. [Skotlex]
  4932. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  4933. WBUFW(buf,8) = 100;
  4934. }
  4935. else
  4936. {
  4937. WBUFW(buf,6) = sd->battle_status.hp;
  4938. WBUFW(buf,8) = sd->battle_status.max_hp;
  4939. }
  4940. //TODO: replace with map_foreachinarea?
  4941. for( i = 0; i < fd_max; i++ )
  4942. {
  4943. if( session[i] && session[i]->func_parse == clif_parse && (sd2 = (struct map_session_data*)session[i]->session_data) && sd != sd2 && sd2->state.active )
  4944. {
  4945. if( sd2->bl.m != sd->bl.m || sd2->bl.x < x0 || sd2->bl.y < y0 || sd2->bl.x > x1 || sd2->bl.y > y1 )
  4946. continue; // Not in the Visual Area
  4947. if( battle_config.disp_hpmeter && (level = pc_isGM(sd2)) >= battle_config.disp_hpmeter && level >= pc_isGM(sd) )
  4948. {
  4949. WFIFOHEAD(i,packet_len(0x106));
  4950. memcpy(WFIFOP(i,0),buf,packet_len(0x106));
  4951. WFIFOSET(i,packet_len(0x106));
  4952. }
  4953. }
  4954. }
  4955. return 0;
  4956. }
  4957. /*==========================================
  4958. * パーティ場所移動(未使用)
  4959. *------------------------------------------*/
  4960. void clif_party_move(struct party* p, struct map_session_data* sd, int online)
  4961. {
  4962. unsigned char buf[128];
  4963. nullpo_retv(sd);
  4964. nullpo_retv(p);
  4965. WBUFW(buf, 0) = 0x104;
  4966. WBUFL(buf, 2) = sd->status.account_id;
  4967. WBUFL(buf, 6) = 0;
  4968. WBUFW(buf,10) = sd->bl.x;
  4969. WBUFW(buf,12) = sd->bl.y;
  4970. WBUFB(buf,14) = !online;
  4971. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  4972. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  4973. mapindex_getmapname_ext(map[sd->bl.m].name, (char*)WBUFP(buf,63));
  4974. clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
  4975. }
  4976. /*==========================================
  4977. * 攻撃するために移動が必要
  4978. *------------------------------------------*/
  4979. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  4980. {
  4981. int fd;
  4982. nullpo_retr(0, sd);
  4983. nullpo_retr(0, bl);
  4984. fd=sd->fd;
  4985. WFIFOHEAD(fd,packet_len(0x139));
  4986. WFIFOW(fd, 0)=0x139;
  4987. WFIFOL(fd, 2)=bl->id;
  4988. WFIFOW(fd, 6)=bl->x;
  4989. WFIFOW(fd, 8)=bl->y;
  4990. WFIFOW(fd,10)=sd->bl.x;
  4991. WFIFOW(fd,12)=sd->bl.y;
  4992. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  4993. WFIFOSET(fd,packet_len(0x139));
  4994. return 0;
  4995. }
  4996. /*==========================================
  4997. * 製造エフェクト
  4998. *------------------------------------------*/
  4999. int clif_produceeffect(struct map_session_data* sd,int flag,int nameid)
  5000. {
  5001. int view,fd;
  5002. nullpo_retr(0, sd);
  5003. fd = sd->fd;
  5004. clif_solved_charname(fd, sd->status.char_id, sd->status.name);
  5005. WFIFOHEAD(fd,packet_len(0x18f));
  5006. WFIFOW(fd, 0)=0x18f;
  5007. WFIFOW(fd, 2)=flag;
  5008. if((view = itemdb_viewid(nameid)) > 0)
  5009. WFIFOW(fd, 4)=view;
  5010. else
  5011. WFIFOW(fd, 4)=nameid;
  5012. WFIFOSET(fd,packet_len(0x18f));
  5013. return 0;
  5014. }
  5015. // pet
  5016. int clif_catch_process(struct map_session_data *sd)
  5017. {
  5018. int fd;
  5019. nullpo_retr(0, sd);
  5020. fd=sd->fd;
  5021. WFIFOHEAD(fd,packet_len(0x19e));
  5022. WFIFOW(fd,0)=0x19e;
  5023. WFIFOSET(fd,packet_len(0x19e));
  5024. return 0;
  5025. }
  5026. int clif_pet_roulette(struct map_session_data *sd,int data)
  5027. {
  5028. int fd;
  5029. nullpo_retr(0, sd);
  5030. fd=sd->fd;
  5031. WFIFOHEAD(fd,packet_len(0x1a0));
  5032. WFIFOW(fd,0)=0x1a0;
  5033. WFIFOB(fd,2)=data;
  5034. WFIFOSET(fd,packet_len(0x1a0));
  5035. return 0;
  5036. }
  5037. /*==========================================
  5038. * pet卵リスト作成
  5039. *------------------------------------------*/
  5040. int clif_sendegg(struct map_session_data *sd)
  5041. {
  5042. //R 01a6 <len>.w <index>.w*
  5043. int i,n=0,fd;
  5044. nullpo_retr(0, sd);
  5045. fd=sd->fd;
  5046. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5047. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5048. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5049. return 0;
  5050. }
  5051. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5052. WFIFOW(fd,0)=0x1a6;
  5053. if(sd->status.pet_id <= 0) {
  5054. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5055. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5056. sd->inventory_data[i]->type!=IT_PETEGG ||
  5057. sd->status.inventory[i].amount<=0)
  5058. continue;
  5059. WFIFOW(fd,n*2+4)=i+2;
  5060. n++;
  5061. }
  5062. }
  5063. WFIFOW(fd,2)=4+n*2;
  5064. WFIFOSET(fd,WFIFOW(fd,2));
  5065. sd->menuskill_id = SA_TAMINGMONSTER;
  5066. sd->menuskill_val = -1;
  5067. return 0;
  5068. }
  5069. /*==========================================
  5070. * Sends a specific pet data update.
  5071. * type = 0 -> param = 0 (initial data)
  5072. * type = 1 -> param = intimacy value
  5073. * type = 2 -> param = hungry value
  5074. * type = 3 -> param = accessory id
  5075. * type = 4 -> param = performance number (1-3:normal, 4:special)
  5076. * type = 5 -> param = hairstyle number
  5077. * If sd is null, the update is sent to nearby objects, otherwise it is sent only to that player.
  5078. *------------------------------------------*/
  5079. int clif_send_petdata(struct map_session_data* sd, struct pet_data* pd, int type, int param)
  5080. {
  5081. uint8 buf[16];
  5082. nullpo_retr(0, pd);
  5083. WBUFW(buf,0) = 0x1a4;
  5084. WBUFB(buf,2) = type;
  5085. WBUFL(buf,3) = pd->bl.id;
  5086. WBUFL(buf,7) = param;
  5087. if (sd)
  5088. clif_send(buf, packet_len(0x1a4), &sd->bl, SELF);
  5089. else
  5090. clif_send(buf, packet_len(0x1a4), &pd->bl, AREA);
  5091. return 0;
  5092. }
  5093. int clif_send_petstatus(struct map_session_data *sd)
  5094. {
  5095. int fd;
  5096. struct s_pet *pet;
  5097. nullpo_retr(0, sd);
  5098. nullpo_retr(0, sd->pd);
  5099. fd=sd->fd;
  5100. pet = &sd->pd->pet;
  5101. WFIFOHEAD(fd,packet_len(0x1a2));
  5102. WFIFOW(fd,0)=0x1a2;
  5103. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5104. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5105. WFIFOW(fd,27)=pet->level;
  5106. WFIFOW(fd,29)=pet->hungry;
  5107. WFIFOW(fd,31)=pet->intimate;
  5108. WFIFOW(fd,33)=pet->equip;
  5109. WFIFOSET(fd,packet_len(0x1a2));
  5110. return 0;
  5111. }
  5112. /*==========================================
  5113. *
  5114. *------------------------------------------*/
  5115. int clif_pet_emotion(struct pet_data *pd,int param)
  5116. {
  5117. unsigned char buf[16];
  5118. nullpo_retr(0, pd);
  5119. memset(buf,0,packet_len(0x1aa));
  5120. WBUFW(buf,0)=0x1aa;
  5121. WBUFL(buf,2)=pd->bl.id;
  5122. if(param >= 100 && pd->petDB->talk_convert_class) {
  5123. if(pd->petDB->talk_convert_class < 0)
  5124. return 0;
  5125. else if(pd->petDB->talk_convert_class > 0) {
  5126. param -= (pd->pet.class_ - 100)*100;
  5127. param += (pd->petDB->talk_convert_class - 100)*100;
  5128. }
  5129. }
  5130. WBUFL(buf,6)=param;
  5131. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5132. return 0;
  5133. }
  5134. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5135. {
  5136. int fd;
  5137. nullpo_retr(0, sd);
  5138. fd=sd->fd;
  5139. WFIFOHEAD(fd,packet_len(0x1a3));
  5140. WFIFOW(fd,0)=0x1a3;
  5141. WFIFOB(fd,2)=fail;
  5142. WFIFOW(fd,3)=foodid;
  5143. WFIFOSET(fd,packet_len(0x1a3));
  5144. return 0;
  5145. }
  5146. /*==========================================
  5147. * オートスペル リスト送信
  5148. *------------------------------------------*/
  5149. int clif_autospell(struct map_session_data *sd,int skilllv)
  5150. {
  5151. int fd;
  5152. nullpo_retr(0, sd);
  5153. fd=sd->fd;
  5154. WFIFOHEAD(fd,packet_len(0x1cd));
  5155. WFIFOW(fd, 0)=0x1cd;
  5156. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5157. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5158. else
  5159. WFIFOL(fd,2)= 0x00000000;
  5160. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5161. WFIFOL(fd,6)= MG_COLDBOLT;
  5162. else
  5163. WFIFOL(fd,6)= 0x00000000;
  5164. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5165. WFIFOL(fd,10)= MG_FIREBOLT;
  5166. else
  5167. WFIFOL(fd,10)= 0x00000000;
  5168. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5169. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5170. else
  5171. WFIFOL(fd,14)= 0x00000000;
  5172. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5173. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5174. else
  5175. WFIFOL(fd,18)= 0x00000000;
  5176. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5177. WFIFOL(fd,22)= MG_FIREBALL;
  5178. else
  5179. WFIFOL(fd,22)= 0x00000000;
  5180. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5181. WFIFOL(fd,26)= MG_FROSTDIVER;
  5182. else
  5183. WFIFOL(fd,26)= 0x00000000;
  5184. WFIFOSET(fd,packet_len(0x1cd));
  5185. sd->menuskill_id = SA_AUTOSPELL;
  5186. sd->menuskill_val = skilllv;
  5187. return 0;
  5188. }
  5189. /*==========================================
  5190. * Devotion's visual effect
  5191. * S 01cf <devoter id>.L { <devotee id>.L }[5] <max distance>.W
  5192. *------------------------------------------*/
  5193. void clif_devotion(struct block_list *src, struct map_session_data *tsd)
  5194. {
  5195. unsigned char buf[56];
  5196. int i;
  5197. nullpo_retv(src);
  5198. memset(buf,0,packet_len(0x1cf));
  5199. WBUFW(buf,0) = 0x1cf;
  5200. WBUFL(buf,2) = src->id;
  5201. if( src->type == BL_MER )
  5202. {
  5203. struct mercenary_data *md = BL_CAST(BL_MER,src);
  5204. if( md && md->master && md->devotion_flag )
  5205. WBUFL(buf,6) = md->master->bl.id;
  5206. WBUFW(buf,26) = skill_get_range2(src, ML_DEVOTION, mercenary_checkskill(md, ML_DEVOTION));
  5207. }
  5208. else
  5209. {
  5210. struct map_session_data *sd = BL_CAST(BL_PC,src);
  5211. if( sd == NULL )
  5212. return;
  5213. for( i = 0; i < 5; i++ )
  5214. WBUFL(buf,6+4*i) = sd->devotion[i];
  5215. WBUFW(buf,26) = skill_get_range2(src, CR_DEVOTION, pc_checkskill(sd, CR_DEVOTION));
  5216. }
  5217. if( tsd )
  5218. clif_send(buf, packet_len(0x1cf), &tsd->bl, SELF);
  5219. else
  5220. clif_send(buf, packet_len(0x1cf), src, AREA);
  5221. }
  5222. /*==========================================
  5223. * 氣球
  5224. *------------------------------------------*/
  5225. int clif_spiritball(struct map_session_data *sd)
  5226. {
  5227. unsigned char buf[16];
  5228. nullpo_retr(0, sd);
  5229. WBUFW(buf,0)=0x1d0;
  5230. WBUFL(buf,2)=sd->bl.id;
  5231. WBUFW(buf,6)=sd->spiritball;
  5232. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5233. return 0;
  5234. }
  5235. /*==========================================
  5236. *
  5237. *------------------------------------------*/
  5238. int clif_combo_delay(struct block_list *bl,int wait)
  5239. {
  5240. unsigned char buf[32];
  5241. nullpo_retr(0, bl);
  5242. WBUFW(buf,0)=0x1d2;
  5243. WBUFL(buf,2)=bl->id;
  5244. WBUFL(buf,6)=wait;
  5245. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5246. return 0;
  5247. }
  5248. /*==========================================
  5249. *白刃取り
  5250. *------------------------------------------*/
  5251. void clif_bladestop(struct block_list *src, int dst_id, int active)
  5252. {
  5253. unsigned char buf[32];
  5254. nullpo_retv(src);
  5255. WBUFW(buf,0)=0x1d1;
  5256. WBUFL(buf,2)=src->id;
  5257. WBUFL(buf,6)=dst_id;
  5258. WBUFL(buf,10)=active;
  5259. clif_send(buf,packet_len(0x1d1),src,AREA);
  5260. }
  5261. /*==========================================
  5262. * MVPエフェクト
  5263. *------------------------------------------*/
  5264. int clif_mvp_effect(struct map_session_data *sd)
  5265. {
  5266. unsigned char buf[16];
  5267. nullpo_retr(0, sd);
  5268. WBUFW(buf,0)=0x10c;
  5269. WBUFL(buf,2)=sd->bl.id;
  5270. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5271. return 0;
  5272. }
  5273. /*==========================================
  5274. * MVPアイテム所得
  5275. *------------------------------------------*/
  5276. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5277. {
  5278. int view,fd;
  5279. nullpo_retr(0, sd);
  5280. fd=sd->fd;
  5281. WFIFOHEAD(fd,packet_len(0x10a));
  5282. WFIFOW(fd,0)=0x10a;
  5283. if((view = itemdb_viewid(nameid)) > 0)
  5284. WFIFOW(fd,2)=view;
  5285. else
  5286. WFIFOW(fd,2)=nameid;
  5287. WFIFOSET(fd,packet_len(0x10a));
  5288. return 0;
  5289. }
  5290. /*==========================================
  5291. * MVP経験値所得
  5292. *------------------------------------------*/
  5293. int clif_mvp_exp(struct map_session_data *sd, unsigned int exp)
  5294. {
  5295. int fd;
  5296. nullpo_retr(0, sd);
  5297. fd=sd->fd;
  5298. WFIFOHEAD(fd,packet_len(0x10b));
  5299. WFIFOW(fd,0)=0x10b;
  5300. WFIFOL(fd,2)=cap_value(exp,0,INT_MAX);
  5301. WFIFOSET(fd,packet_len(0x10b));
  5302. return 0;
  5303. }
  5304. /*==========================================
  5305. * Guild creation result
  5306. * R 0167 <flag>.B
  5307. * flag = 0 -> "Guild has been created."
  5308. * flag = 1 -> "You are already in a Guild."
  5309. * flag = 2 -> "That Guild Name already exists."
  5310. * flag = 3 -> "You need the neccessary item to create a Guild."
  5311. *------------------------------------------*/
  5312. int clif_guild_created(struct map_session_data *sd,int flag)
  5313. {
  5314. int fd;
  5315. nullpo_retr(0, sd);
  5316. fd=sd->fd;
  5317. WFIFOHEAD(fd,packet_len(0x167));
  5318. WFIFOW(fd,0)=0x167;
  5319. WFIFOB(fd,2)=flag;
  5320. WFIFOSET(fd,packet_len(0x167));
  5321. return 0;
  5322. }
  5323. /*==========================================
  5324. * ギルド所属通知
  5325. *------------------------------------------*/
  5326. int clif_guild_belonginfo(struct map_session_data *sd, struct guild *g)
  5327. {
  5328. int ps,fd;
  5329. nullpo_retr(0, sd);
  5330. if( sd->state.bg_id )
  5331. return clif_bg_belonginfo(sd);
  5332. nullpo_retr(0, g);
  5333. fd=sd->fd;
  5334. ps=guild_getposition(g,sd);
  5335. WFIFOHEAD(fd,packet_len(0x16c));
  5336. memset(WFIFOP(fd,0),0,packet_len(0x16c));
  5337. WFIFOW(fd,0)=0x16c;
  5338. WFIFOL(fd,2)=g->guild_id;
  5339. WFIFOL(fd,6)=g->emblem_id;
  5340. WFIFOL(fd,10)=g->position[ps].mode;
  5341. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5342. WFIFOSET(fd,packet_len(0x16c));
  5343. return 0;
  5344. }
  5345. /*==========================================
  5346. * ギルドメンバログイン通知
  5347. *------------------------------------------*/
  5348. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5349. {
  5350. unsigned char buf[64];
  5351. nullpo_retr(0, g);
  5352. WBUFW(buf, 0)=0x16d;
  5353. WBUFL(buf, 2)=g->member[idx].account_id;
  5354. WBUFL(buf, 6)=g->member[idx].char_id;
  5355. WBUFL(buf,10)=flag;
  5356. if(g->member[idx].sd==NULL){
  5357. struct map_session_data *sd=guild_getavailablesd(g);
  5358. if(sd!=NULL)
  5359. clif_send(buf,packet_len(0x16d),&sd->bl,GUILD);
  5360. }else
  5361. clif_send(buf,packet_len(0x16d),&g->member[idx].sd->bl,GUILD_WOS);
  5362. return 0;
  5363. }
  5364. // Function `clif_guild_memberlogin_notice` sends info about
  5365. // logins and logouts of a guild member to the rest members.
  5366. // But at the 1st time (after a player login or map changing)
  5367. // the client won't show the message.
  5368. // So I suggest use this function for sending "first-time-info"
  5369. // to some player on entering the game or changing location.
  5370. // At next time the client would always show the message.
  5371. // The function sends all the statuses in the single packet
  5372. // to economize traffic. [LuzZza]
  5373. int clif_guild_send_onlineinfo(struct map_session_data *sd)
  5374. {
  5375. struct guild *g;
  5376. unsigned char buf[14*128];
  5377. int i, count=0, p_len;
  5378. nullpo_retr(0, sd);
  5379. p_len = packet_len(0x16d);
  5380. if(!(g = guild_search(sd->status.guild_id)))
  5381. return 0;
  5382. for(i=0; i<g->max_member; i++) {
  5383. if(g->member[i].account_id > 0 &&
  5384. g->member[i].account_id != sd->status.account_id) {
  5385. WBUFW(buf,count*p_len) = 0x16d;
  5386. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5387. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5388. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5389. count++;
  5390. }
  5391. }
  5392. clif_send(buf, p_len*count, &sd->bl, SELF);
  5393. return 0;
  5394. }
  5395. /*==========================================
  5396. * ギルドマスター通知(14dへの応答)
  5397. *------------------------------------------*/
  5398. int clif_guild_masterormember(struct map_session_data *sd)
  5399. {
  5400. int fd;
  5401. nullpo_retr(0, sd);
  5402. fd=sd->fd;
  5403. WFIFOHEAD(fd,packet_len(0x14e));
  5404. WFIFOW(fd,0) = 0x14e;
  5405. WFIFOL(fd,2) = (sd->state.gmaster_flag) ? 0xd7 : 0x57;
  5406. WFIFOSET(fd,packet_len(0x14e));
  5407. return 0;
  5408. }
  5409. /*==========================================
  5410. * Basic Info (Territories [Valaris])
  5411. *------------------------------------------*/
  5412. int clif_guild_basicinfo(struct map_session_data *sd)
  5413. {
  5414. int fd,i,t;
  5415. struct guild *g;
  5416. struct guild_castle *gc = NULL;
  5417. struct battleground_data *bg = NULL;
  5418. nullpo_retr(0, sd);
  5419. fd = sd->fd;
  5420. if( sd->state.bg_id && (g = bg_guild_get(sd->state.bg_id)) != NULL )
  5421. bg = bg_team_search(sd->state.bg_id);
  5422. else
  5423. g = guild_search(sd->status.guild_id);
  5424. if( g == NULL )
  5425. return 0;
  5426. WFIFOHEAD(fd,packet_len(0x1b6));
  5427. WFIFOW(fd, 0)=0x1b6;//0x150;
  5428. WFIFOL(fd, 2)=g->guild_id;
  5429. WFIFOL(fd, 6)=g->guild_lv;
  5430. WFIFOL(fd,10)=bg?bg->count:g->connect_member;
  5431. WFIFOL(fd,14)=g->max_member;
  5432. WFIFOL(fd,18)=g->average_lv;
  5433. WFIFOL(fd,22)=g->exp;
  5434. WFIFOL(fd,26)=g->next_exp;
  5435. WFIFOL(fd,30)=0; // Tax Points
  5436. WFIFOL(fd,34)=0; // Tendency: (left) Vulgar [-100,100] Famed (right)
  5437. WFIFOL(fd,38)=0; // Tendency: (down) Wicked [-100,100] Righteous (up)
  5438. WFIFOL(fd,42)=g->emblem_id;
  5439. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5440. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5441. for(i = 0, t = 0; i < MAX_GUILDCASTLE; i++)
  5442. {
  5443. gc = guild_castle_search(i);
  5444. if(gc && g->guild_id == gc->guild_id)
  5445. t++;
  5446. }
  5447. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20); // "'N' castles"
  5448. WFIFOSET(fd,packet_len(WFIFOW(fd,0)));
  5449. return 0;
  5450. }
  5451. /*==========================================
  5452. * ギルド同盟/敵対情報
  5453. *------------------------------------------*/
  5454. int clif_guild_allianceinfo(struct map_session_data *sd)
  5455. {
  5456. int fd,i,c;
  5457. struct guild *g;
  5458. nullpo_retr(0, sd);
  5459. if( !sd->state.bg_id || (g = bg_guild_get(sd->state.bg_id)) == NULL )
  5460. g = guild_search(sd->status.guild_id);
  5461. if( g == NULL )
  5462. return 0;
  5463. fd = sd->fd;
  5464. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5465. WFIFOW(fd, 0)=0x14c;
  5466. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5467. struct guild_alliance *a=&g->alliance[i];
  5468. if(a->guild_id>0){
  5469. WFIFOL(fd,c*32+4)=a->opposition;
  5470. WFIFOL(fd,c*32+8)=a->guild_id;
  5471. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5472. c++;
  5473. }
  5474. }
  5475. WFIFOW(fd, 2)=c*32+4;
  5476. WFIFOSET(fd,WFIFOW(fd,2));
  5477. return 0;
  5478. }
  5479. /*==========================================
  5480. * ギルドメンバーリスト
  5481. *------------------------------------------*/
  5482. int clif_guild_memberlist(struct map_session_data *sd)
  5483. {
  5484. int fd;
  5485. int i,c;
  5486. struct guild *g;
  5487. nullpo_retr(0, sd);
  5488. if( (fd = sd->fd) == 0 )
  5489. return 0;
  5490. if( sd->state.bg_id )
  5491. return clif_bg_memberlist(sd);
  5492. if( (g = guild_search(sd->status.guild_id)) == NULL )
  5493. return 0;
  5494. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5495. WFIFOW(fd, 0)=0x154;
  5496. for(i=0,c=0;i<g->max_member;i++){
  5497. struct guild_member *m=&g->member[i];
  5498. if(m->account_id==0)
  5499. continue;
  5500. WFIFOL(fd,c*104+ 4)=m->account_id;
  5501. WFIFOL(fd,c*104+ 8)=m->char_id;
  5502. WFIFOW(fd,c*104+12)=m->hair;
  5503. WFIFOW(fd,c*104+14)=m->hair_color;
  5504. WFIFOW(fd,c*104+16)=m->gender;
  5505. WFIFOW(fd,c*104+18)=m->class_;
  5506. WFIFOW(fd,c*104+20)=m->lv;
  5507. WFIFOL(fd,c*104+22)=m->exp;
  5508. WFIFOL(fd,c*104+26)=m->online;
  5509. WFIFOL(fd,c*104+30)=m->position;
  5510. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5511. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5512. c++;
  5513. }
  5514. WFIFOW(fd, 2)=c*104+4;
  5515. WFIFOSET(fd,WFIFOW(fd,2));
  5516. return 0;
  5517. }
  5518. /*==========================================
  5519. * ギルド役職名リスト
  5520. *------------------------------------------*/
  5521. int clif_guild_positionnamelist(struct map_session_data *sd)
  5522. {
  5523. int i,fd;
  5524. struct guild *g;
  5525. nullpo_retr(0, sd);
  5526. if( !sd->state.bg_id || (g = bg_guild_get(sd->state.bg_id)) == NULL )
  5527. g = guild_search(sd->status.guild_id);
  5528. if( g == NULL )
  5529. return 0;
  5530. fd = sd->fd;
  5531. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5532. WFIFOW(fd, 0)=0x166;
  5533. for(i=0;i<MAX_GUILDPOSITION;i++){
  5534. WFIFOL(fd,i*28+4)=i;
  5535. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5536. }
  5537. WFIFOW(fd,2)=i*28+4;
  5538. WFIFOSET(fd,WFIFOW(fd,2));
  5539. return 0;
  5540. }
  5541. /*==========================================
  5542. * ギルド役職情報リスト
  5543. *------------------------------------------*/
  5544. int clif_guild_positioninfolist(struct map_session_data *sd)
  5545. {
  5546. int i,fd;
  5547. struct guild *g;
  5548. nullpo_retr(0, sd);
  5549. if( !sd->state.bg_id || (g = bg_guild_get(sd->state.bg_id)) == NULL )
  5550. g = guild_search(sd->status.guild_id);
  5551. if( g == NULL )
  5552. return 0;
  5553. fd = sd->fd;
  5554. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5555. WFIFOW(fd, 0)=0x160;
  5556. for(i=0;i<MAX_GUILDPOSITION;i++){
  5557. struct guild_position *p=&g->position[i];
  5558. WFIFOL(fd,i*16+ 4)=i;
  5559. WFIFOL(fd,i*16+ 8)=p->mode;
  5560. WFIFOL(fd,i*16+12)=i;
  5561. WFIFOL(fd,i*16+16)=p->exp_mode;
  5562. }
  5563. WFIFOW(fd, 2)=i*16+4;
  5564. WFIFOSET(fd,WFIFOW(fd,2));
  5565. return 0;
  5566. }
  5567. /*==========================================
  5568. * ギルド役職変更通知
  5569. *------------------------------------------*/
  5570. int clif_guild_positionchanged(struct guild *g,int idx)
  5571. {
  5572. struct map_session_data *sd;
  5573. unsigned char buf[128];
  5574. nullpo_retr(0, g);
  5575. WBUFW(buf, 0)=0x174;
  5576. WBUFW(buf, 2)=44;
  5577. WBUFL(buf, 4)=idx;
  5578. WBUFL(buf, 8)=g->position[idx].mode;
  5579. WBUFL(buf,12)=idx;
  5580. WBUFL(buf,16)=g->position[idx].exp_mode;
  5581. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  5582. if( (sd=guild_getavailablesd(g))!=NULL )
  5583. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5584. return 0;
  5585. }
  5586. /*==========================================
  5587. * ギルドメンバ変更通知
  5588. *------------------------------------------*/
  5589. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  5590. {
  5591. struct map_session_data *sd;
  5592. unsigned char buf[64];
  5593. nullpo_retr(0, g);
  5594. WBUFW(buf, 0)=0x156;
  5595. WBUFW(buf, 2)=16;
  5596. WBUFL(buf, 4)=g->member[idx].account_id;
  5597. WBUFL(buf, 8)=g->member[idx].char_id;
  5598. WBUFL(buf,12)=g->member[idx].position;
  5599. if( (sd=guild_getavailablesd(g))!=NULL )
  5600. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5601. return 0;
  5602. }
  5603. /*==========================================
  5604. * ギルドエンブレム送信
  5605. *------------------------------------------*/
  5606. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  5607. {
  5608. int fd;
  5609. nullpo_retr(0, sd);
  5610. nullpo_retr(0, g);
  5611. fd = sd->fd;
  5612. if( g->emblem_len <= 0 )
  5613. return 0;
  5614. WFIFOHEAD(fd,g->emblem_len+12);
  5615. WFIFOW(fd,0)=0x152;
  5616. WFIFOW(fd,2)=g->emblem_len+12;
  5617. WFIFOL(fd,4)=g->guild_id;
  5618. WFIFOL(fd,8)=g->emblem_id;
  5619. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  5620. WFIFOSET(fd,WFIFOW(fd,2));
  5621. return 0;
  5622. }
  5623. /// Sends update of the guild id/emblem id to everyone in the area.
  5624. void clif_guild_emblem_area(struct block_list* bl)
  5625. {
  5626. uint8 buf[12];
  5627. nullpo_retv(bl);
  5628. // TODO this packet doesn't force the update of ui components that have the emblem visible
  5629. // (emblem in the flag npcs and emblem over the head in agit maps) [FlavioJS]
  5630. WBUFW(buf,0) = 0x1B4;
  5631. WBUFL(buf,2) = bl->id;
  5632. WBUFL(buf,6) = clif_bg_guild_id(bl);
  5633. WBUFW(buf,10) = clif_bg_emblem_id(bl);
  5634. clif_send(buf, 12, bl, AREA_WOS);
  5635. }
  5636. /*==========================================
  5637. * Send guild skills
  5638. *------------------------------------------*/
  5639. int clif_guild_skillinfo(struct map_session_data* sd)
  5640. {
  5641. int fd;
  5642. struct guild* g;
  5643. int i,c;
  5644. nullpo_retr(0, sd);
  5645. if( !sd->state.bg_id || (g = bg_guild_get(sd->state.bg_id)) == NULL )
  5646. g = guild_search(sd->status.guild_id);
  5647. if( g == NULL )
  5648. return 0;
  5649. fd = sd->fd;
  5650. WFIFOHEAD(fd, 6 + MAX_GUILDSKILL*37);
  5651. WFIFOW(fd,0) = 0x0162;
  5652. WFIFOW(fd,4) = g->skill_point;
  5653. for(i = 0, c = 0; i < MAX_GUILDSKILL; i++)
  5654. {
  5655. if(g->skill[i].id > 0 && guild_check_skill_require(g, g->skill[i].id))
  5656. {
  5657. int id = g->skill[i].id;
  5658. int p = 6 + c*37;
  5659. WFIFOW(fd,p+0) = id;
  5660. WFIFOW(fd,p+2) = skill_get_inf(id);
  5661. WFIFOW(fd,p+4) = 0;
  5662. WFIFOW(fd,p+6) = g->skill[i].lv;
  5663. WFIFOW(fd,p+8) = skill_get_sp(id, g->skill[i].lv);
  5664. WFIFOW(fd,p+10) = skill_get_range(id, g->skill[i].lv);
  5665. safestrncpy((char*)WFIFOP(fd,p+12), skill_get_name(id), NAME_LENGTH);
  5666. WFIFOB(fd,p+36)= (g->skill[i].lv < guild_skill_get_max(id) && sd == g->member[0].sd) ? 1 : 0;
  5667. c++;
  5668. }
  5669. }
  5670. WFIFOW(fd,2) = 6 + c*37;
  5671. WFIFOSET(fd,WFIFOW(fd,2));
  5672. return 0;
  5673. }
  5674. /*==========================================
  5675. * Sends guild notice to client
  5676. * R 016f <str1z>.60B <str2z>.120B
  5677. *------------------------------------------*/
  5678. int clif_guild_notice(struct map_session_data* sd, struct guild* g)
  5679. {
  5680. int fd;
  5681. nullpo_retr(0, sd);
  5682. nullpo_retr(0, g);
  5683. fd = sd->fd;
  5684. if ( !session_isActive(fd) )
  5685. return 0;
  5686. if(g->mes1[0] == '\0' && g->mes2[0] == '\0')
  5687. return 0;
  5688. WFIFOHEAD(fd,packet_len(0x16f));
  5689. WFIFOW(fd,0) = 0x16f;
  5690. memcpy(WFIFOP(fd,2), g->mes1, 60);
  5691. memcpy(WFIFOP(fd,62), g->mes2, 120);
  5692. WFIFOSET(fd,packet_len(0x16f));
  5693. return 0;
  5694. }
  5695. /*==========================================
  5696. * ギルドメンバ勧誘
  5697. *------------------------------------------*/
  5698. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  5699. {
  5700. int fd;
  5701. nullpo_retr(0, sd);
  5702. nullpo_retr(0, g);
  5703. fd=sd->fd;
  5704. WFIFOHEAD(fd,packet_len(0x16a));
  5705. WFIFOW(fd,0)=0x16a;
  5706. WFIFOL(fd,2)=g->guild_id;
  5707. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  5708. WFIFOSET(fd,packet_len(0x16a));
  5709. return 0;
  5710. }
  5711. /*==========================================
  5712. * ギルドメンバ勧誘結果
  5713. *------------------------------------------*/
  5714. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  5715. {
  5716. int fd;
  5717. nullpo_retr(0, sd);
  5718. fd=sd->fd;
  5719. WFIFOHEAD(fd,packet_len(0x169));
  5720. WFIFOW(fd,0)=0x169;
  5721. WFIFOB(fd,2)=flag;
  5722. WFIFOSET(fd,packet_len(0x169));
  5723. return 0;
  5724. }
  5725. /*==========================================
  5726. * ギルドメンバ脱退通知
  5727. *------------------------------------------*/
  5728. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  5729. {
  5730. unsigned char buf[128];
  5731. nullpo_retr(0, sd);
  5732. WBUFW(buf, 0)=0x15a;
  5733. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  5734. memcpy(WBUFP(buf,26),mes,40);
  5735. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD_NOBG);
  5736. return 0;
  5737. }
  5738. /*==========================================
  5739. * ギルドメンバ追放通知
  5740. *------------------------------------------*/
  5741. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,int account_id)
  5742. {
  5743. unsigned char buf[128];
  5744. nullpo_retr(0, sd);
  5745. WBUFW(buf, 0)=0x15c;
  5746. safestrncpy((char*)WBUFP(buf, 2),name,NAME_LENGTH);
  5747. safestrncpy((char*)WBUFP(buf,26),mes,40);
  5748. safestrncpy((char*)WBUFP(buf,66),"",NAME_LENGTH); // account name (not used for security reasons)
  5749. clif_send(buf,packet_len(0x15c),&sd->bl,GUILD_NOBG);
  5750. return 0;
  5751. }
  5752. /*==========================================
  5753. * ギルド追放メンバリスト
  5754. *------------------------------------------*/
  5755. int clif_guild_expulsionlist(struct map_session_data *sd)
  5756. {
  5757. int fd;
  5758. int i,c;
  5759. struct guild *g;
  5760. nullpo_retr(0, sd);
  5761. if( !sd->state.bg_id || (g = bg_guild_get(sd->state.bg_id)) == NULL )
  5762. g = guild_search(sd->status.guild_id);
  5763. if( g == NULL )
  5764. return 0;
  5765. fd = sd->fd;
  5766. WFIFOHEAD(fd,4 + MAX_GUILDEXPULSION * 88);
  5767. WFIFOW(fd,0)=0x163;
  5768. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  5769. struct guild_expulsion *e=&g->expulsion[i];
  5770. if(e->account_id>0){
  5771. safestrncpy((char*)WFIFOP(fd,4 + c*88),e->name,NAME_LENGTH);
  5772. safestrncpy((char*)WFIFOP(fd,4 + c*88+24),"",24); // account name (not used for security reasons)
  5773. safestrncpy((char*)WFIFOP(fd,4 + c*88+48),e->mes,40);
  5774. c++;
  5775. }
  5776. }
  5777. WFIFOW(fd,2) = 4 + c*88;
  5778. WFIFOSET(fd,WFIFOW(fd,2));
  5779. return 0;
  5780. }
  5781. /*==========================================
  5782. * ギルド会話
  5783. *------------------------------------------*/
  5784. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  5785. {
  5786. struct map_session_data *sd;
  5787. unsigned char *buf;
  5788. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  5789. WBUFW(buf, 0) = 0x17f;
  5790. WBUFW(buf, 2) = len + 4;
  5791. memcpy(WBUFP(buf,4), mes, len);
  5792. if ((sd = guild_getavailablesd(g)) != NULL)
  5793. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD_NOBG);
  5794. if(buf) aFree(buf);
  5795. return 0;
  5796. }
  5797. /*==========================================
  5798. * ギルドスキル割り振り通知
  5799. *------------------------------------------*/
  5800. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  5801. {
  5802. int fd;
  5803. nullpo_retr(0, sd);
  5804. fd=sd->fd;
  5805. WFIFOHEAD(fd,11);
  5806. WFIFOW(fd,0) = 0x10e;
  5807. WFIFOW(fd,2) = skill_num;
  5808. WFIFOW(fd,4) = lv;
  5809. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  5810. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  5811. WFIFOB(fd,10) = 1;
  5812. WFIFOSET(fd,11);
  5813. return 0;
  5814. }
  5815. /*==========================================
  5816. * ギルド同盟要請
  5817. *------------------------------------------*/
  5818. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  5819. {
  5820. int fd;
  5821. nullpo_retr(0, sd);
  5822. fd=sd->fd;
  5823. WFIFOHEAD(fd,packet_len(0x171));
  5824. WFIFOW(fd,0)=0x171;
  5825. WFIFOL(fd,2)=account_id;
  5826. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  5827. WFIFOSET(fd,packet_len(0x171));
  5828. return 0;
  5829. }
  5830. /*==========================================
  5831. * Reply to alliance request.
  5832. * Flag values are:
  5833. * 0: Already allied.
  5834. * 1: You rejected the offer.
  5835. * 2: You accepted the offer.
  5836. * 3: They have too any alliances
  5837. * 4: You have too many alliances.
  5838. *------------------------------------------*/
  5839. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  5840. {
  5841. int fd;
  5842. nullpo_retr(0, sd);
  5843. fd=sd->fd;
  5844. WFIFOHEAD(fd,packet_len(0x173));
  5845. WFIFOW(fd,0)=0x173;
  5846. WFIFOL(fd,2)=flag;
  5847. WFIFOSET(fd,packet_len(0x173));
  5848. return 0;
  5849. }
  5850. /*==========================================
  5851. * ギルド関係解消通知
  5852. *------------------------------------------*/
  5853. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  5854. {
  5855. int fd;
  5856. nullpo_retr(0, sd);
  5857. fd = sd->fd;
  5858. if (fd <= 0)
  5859. return 0;
  5860. WFIFOHEAD(fd,packet_len(0x184));
  5861. WFIFOW(fd,0)=0x184;
  5862. WFIFOL(fd,2)=guild_id;
  5863. WFIFOL(fd,6)=flag;
  5864. WFIFOSET(fd,packet_len(0x184));
  5865. return 0;
  5866. }
  5867. /*==========================================
  5868. * ギルド敵対結果
  5869. *------------------------------------------*/
  5870. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  5871. {
  5872. int fd;
  5873. nullpo_retr(0, sd);
  5874. fd=sd->fd;
  5875. WFIFOHEAD(fd,packet_len(0x181));
  5876. WFIFOW(fd,0)=0x181;
  5877. WFIFOB(fd,2)=flag;
  5878. WFIFOSET(fd,packet_len(0x181));
  5879. return 0;
  5880. }
  5881. /*==========================================
  5882. * ギルド関係追加
  5883. *------------------------------------------*/
  5884. /*int clif_guild_allianceadded(struct guild *g,int idx)
  5885. {
  5886. unsigned char buf[64];
  5887. WBUFW(fd,0)=0x185;
  5888. WBUFL(fd,2)=g->alliance[idx].opposition;
  5889. WBUFL(fd,6)=g->alliance[idx].guild_id;
  5890. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  5891. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  5892. return 0;
  5893. }*/
  5894. /*==========================================
  5895. * ギルド解散通知
  5896. *------------------------------------------*/
  5897. int clif_guild_broken(struct map_session_data *sd,int flag)
  5898. {
  5899. int fd;
  5900. nullpo_retr(0, sd);
  5901. fd=sd->fd;
  5902. WFIFOHEAD(fd,packet_len(0x15e));
  5903. WFIFOW(fd,0)=0x15e;
  5904. WFIFOL(fd,2)=flag;
  5905. WFIFOSET(fd,packet_len(0x15e));
  5906. return 0;
  5907. }
  5908. /*==========================================
  5909. * エモーション
  5910. *------------------------------------------*/
  5911. void clif_emotion(struct block_list *bl,int type)
  5912. {
  5913. unsigned char buf[8];
  5914. nullpo_retv(bl);
  5915. WBUFW(buf,0)=0xc0;
  5916. WBUFL(buf,2)=bl->id;
  5917. WBUFB(buf,6)=type;
  5918. clif_send(buf,packet_len(0xc0),bl,AREA);
  5919. }
  5920. /*==========================================
  5921. * トーキーボックス
  5922. *------------------------------------------*/
  5923. void clif_talkiebox(struct block_list* bl, const char* talkie)
  5924. {
  5925. unsigned char buf[86];
  5926. nullpo_retv(bl);
  5927. WBUFW(buf,0) = 0x191;
  5928. WBUFL(buf,2) = bl->id;
  5929. safestrncpy((char*)WBUFP(buf,6),talkie,MESSAGE_SIZE);
  5930. clif_send(buf,packet_len(0x191),bl,AREA);
  5931. }
  5932. /*==========================================
  5933. * 結婚エフェクト
  5934. *------------------------------------------*/
  5935. void clif_wedding_effect(struct block_list *bl)
  5936. {
  5937. unsigned char buf[6];
  5938. nullpo_retv(bl);
  5939. WBUFW(buf,0) = 0x1ea;
  5940. WBUFL(buf,2) = bl->id;
  5941. clif_send(buf, packet_len(0x1ea), bl, AREA);
  5942. }
  5943. /*==========================================
  5944. * � なたに逢いたい使用時名前叫び
  5945. *------------------------------------------
  5946. void clif_callpartner(struct map_session_data *sd)
  5947. {
  5948. unsigned char buf[26];
  5949. char *p;
  5950. nullpo_retv(sd);
  5951. if(sd->status.partner_id){
  5952. WBUFW(buf,0)=0x1e6;
  5953. p = map_charid2nick(sd->status.partner_id);
  5954. if(p){
  5955. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  5956. }else{
  5957. map_reqchariddb(sd,sd->status.partner_id);
  5958. chrif_searchcharid(sd->status.partner_id);
  5959. WBUFB(buf,2) = 0;
  5960. }
  5961. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  5962. }
  5963. return;
  5964. }
  5965. */
  5966. /*==========================================
  5967. * Marry [DracoRPG]
  5968. *------------------------------------------
  5969. void clif_marriage_process(struct map_session_data *sd)
  5970. {
  5971. int fd;
  5972. nullpo_retv(sd);
  5973. fd=sd->fd;
  5974. WFIFOHEAD(fd,packet_len(0x1e4));
  5975. WFIFOW(fd,0)=0x1e4;
  5976. WFIFOSET(fd,packet_len(0x1e4));
  5977. }
  5978. */
  5979. /*==========================================
  5980. * Notice of divorce
  5981. *------------------------------------------*/
  5982. void clif_divorced(struct map_session_data* sd, const char* name)
  5983. {
  5984. int fd;
  5985. nullpo_retv(sd);
  5986. fd=sd->fd;
  5987. WFIFOHEAD(fd,packet_len(0x205));
  5988. WFIFOW(fd,0)=0x205;
  5989. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  5990. WFIFOSET(fd, packet_len(0x205));
  5991. }
  5992. /*==========================================
  5993. *
  5994. *------------------------------------------*/
  5995. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd)
  5996. {
  5997. nullpo_retv(sd);
  5998. WFIFOHEAD(fd,packet_len(0x1e2));
  5999. WFIFOW(fd,0)=0x1e2;
  6000. WFIFOSET(fd, packet_len(0x1e2));
  6001. }
  6002. /*==========================================
  6003. *
  6004. *------------------------------------------*/
  6005. int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  6006. {
  6007. int fd;
  6008. nullpo_retr(0, sd);
  6009. fd = sd->fd;
  6010. if (!fd || !len) return 0; //Disconnected player.
  6011. WFIFOHEAD(fd, len+5);
  6012. WFIFOW(fd, 0) = 0x17f;
  6013. WFIFOW(fd, 2) = len + 5;
  6014. memcpy(WFIFOP(fd,4), mes, len);
  6015. WFIFOSET(fd, WFIFOW(fd,2));
  6016. return 1;
  6017. }
  6018. /*==========================================
  6019. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6020. *------------------------------------------*/
  6021. void clif_disp_message(struct block_list* src, const char* mes, int len, enum send_target target)
  6022. {
  6023. unsigned char buf[1024];
  6024. if (!len) return;
  6025. WBUFW(buf, 0) = 0x17f;
  6026. WBUFW(buf, 2) = len + 5;
  6027. memcpy(WBUFP(buf,4), mes, len);
  6028. clif_send(buf, WBUFW(buf,2), src, target);
  6029. return;
  6030. }
  6031. /*==========================================
  6032. *
  6033. *------------------------------------------*/
  6034. int clif_GM_kickack(struct map_session_data *sd, int id)
  6035. {
  6036. int fd;
  6037. nullpo_retr(0, sd);
  6038. fd = sd->fd;
  6039. WFIFOHEAD(fd,packet_len(0xcd));
  6040. WFIFOW(fd,0) = 0xcd;
  6041. WFIFOL(fd,2) = id;
  6042. WFIFOSET(fd, packet_len(0xcd));
  6043. return 0;
  6044. }
  6045. void clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd)
  6046. {
  6047. int fd = tsd->fd;
  6048. if( fd > 0 )
  6049. clif_authfail_fd(fd, 15);
  6050. else
  6051. map_quit(tsd);
  6052. if( sd )
  6053. clif_GM_kickack(sd,tsd->status.account_id);
  6054. }
  6055. /// Displays various manner-related status messages
  6056. /// R 014a <type>.L
  6057. /// type: 0 - "A manner point has been successfully aligned."
  6058. /// 1 - ?
  6059. /// 2 - ?
  6060. /// 3 - "Chat Block has been applied by GM due to your ill-mannerous action."
  6061. /// 4 - "Automated Chat Block has been applied due to Anti-Spam System."
  6062. /// 5 - "You got a good point from %s."
  6063. void clif_manner_message(struct map_session_data* sd, uint32 type)
  6064. {
  6065. int fd;
  6066. nullpo_retv(sd);
  6067. fd = sd->fd;
  6068. WFIFOHEAD(fd,packet_len(0x14a));
  6069. WFIFOW(fd,0) = 0x14a;
  6070. WFIFOL(fd,2) = type;
  6071. WFIFOSET(fd, packet_len(0x14a));
  6072. }
  6073. /// Followup to 0x14a type 3/5, informs who did the manner adjustment action.
  6074. /// R 014b <type>.B <GM name>.24B
  6075. /// type: 0 - positive (unmute)
  6076. /// 1 - negative (mute)
  6077. void clif_GM_silence(struct map_session_data* sd, struct map_session_data* tsd, uint8 type)
  6078. {
  6079. int fd;
  6080. nullpo_retv(sd);
  6081. nullpo_retv(tsd);
  6082. fd = tsd->fd;
  6083. WFIFOHEAD(fd,packet_len(0x14b));
  6084. WFIFOW(fd,0) = 0x14b;
  6085. WFIFOB(fd,2) = type;
  6086. safestrncpy((char*)WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6087. WFIFOSET(fd, packet_len(0x14b));
  6088. }
  6089. /*==========================================
  6090. * Wis拒否許可応答
  6091. *------------------------------------------*/
  6092. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6093. {
  6094. int fd;
  6095. nullpo_retr(0, sd);
  6096. fd=sd->fd;
  6097. WFIFOHEAD(fd,packet_len(0xd1));
  6098. WFIFOW(fd,0)=0xd1;
  6099. WFIFOB(fd,2)=type;
  6100. WFIFOB(fd,3)=flag;
  6101. WFIFOSET(fd,packet_len(0xd1));
  6102. return 0;
  6103. }
  6104. /*==========================================
  6105. * Wis全拒否許可応答
  6106. *------------------------------------------*/
  6107. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6108. {
  6109. int fd;
  6110. nullpo_retr(0, sd);
  6111. fd=sd->fd;
  6112. WFIFOHEAD(fd,packet_len(0xd2));
  6113. WFIFOW(fd,0)=0xd2;
  6114. WFIFOB(fd,2)=type;
  6115. WFIFOB(fd,3)=flag;
  6116. WFIFOSET(fd,packet_len(0xd2));
  6117. return 0;
  6118. }
  6119. /*==========================================
  6120. * サウンドエフェクト
  6121. *------------------------------------------*/
  6122. void clif_soundeffect(struct map_session_data* sd, struct block_list* bl, const char* name, int type)
  6123. {
  6124. int fd;
  6125. nullpo_retv(sd);
  6126. nullpo_retv(bl);
  6127. fd = sd->fd;
  6128. WFIFOHEAD(fd,packet_len(0x1d3));
  6129. WFIFOW(fd,0) = 0x1d3;
  6130. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  6131. WFIFOB(fd,26) = type;
  6132. WFIFOL(fd,27) = 0;
  6133. WFIFOL(fd,31) = bl->id;
  6134. WFIFOSET(fd,packet_len(0x1d3));
  6135. return;
  6136. }
  6137. int clif_soundeffectall(struct block_list* bl, const char* name, int type, enum send_target coverage)
  6138. {
  6139. unsigned char buf[40];
  6140. nullpo_retr(0, bl);
  6141. WBUFW(buf,0) = 0x1d3;
  6142. safestrncpy((char*)WBUFP(buf,2), name, NAME_LENGTH);
  6143. WBUFB(buf,26) = type;
  6144. WBUFL(buf,27) = 0;
  6145. WBUFL(buf,31) = bl->id;
  6146. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6147. return 0;
  6148. }
  6149. // displaying special effects (npcs, weather, etc) [Valaris]
  6150. int clif_specialeffect(struct block_list* bl, int type, enum send_target target)
  6151. {
  6152. unsigned char buf[24];
  6153. nullpo_retr(0, bl);
  6154. memset(buf, 0, packet_len(0x1f3));
  6155. WBUFW(buf,0) = 0x1f3;
  6156. WBUFL(buf,2) = bl->id;
  6157. WBUFL(buf,6) = type;
  6158. clif_send(buf, packet_len(0x1f3), bl, target);
  6159. if (disguised(bl)) {
  6160. WBUFL(buf,2) = -bl->id;
  6161. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6162. }
  6163. return 0;
  6164. }
  6165. void clif_specialeffect_single(struct block_list* bl, int type, int fd)
  6166. {
  6167. WFIFOHEAD(fd,10);
  6168. WFIFOW(fd,0) = 0x1f3;
  6169. WFIFOL(fd,2) = bl->id;
  6170. WFIFOL(fd,6) = type;
  6171. WFIFOSET(fd,10);
  6172. }
  6173. // messages (from mobs/npcs) [Valaris]
  6174. int clif_message(struct block_list* bl, const char* msg)
  6175. {
  6176. unsigned short msg_len = strlen(msg) + 1;
  6177. uint8 buf[256];
  6178. nullpo_retr(0, bl);
  6179. WBUFW(buf,0) = 0x8d;
  6180. WBUFW(buf,2) = msg_len + 8;
  6181. WBUFL(buf,4) = bl->id;
  6182. memcpy(WBUFP(buf,8), msg, msg_len);
  6183. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC);
  6184. return 0;
  6185. }
  6186. // refresh the client's screen, getting rid of any effects
  6187. int clif_refresh(struct map_session_data *sd)
  6188. {
  6189. nullpo_retr(-1, sd);
  6190. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6191. clif_inventorylist(sd);
  6192. if(pc_iscarton(sd)) {
  6193. clif_cartlist(sd);
  6194. clif_updatestatus(sd,SP_CARTINFO);
  6195. }
  6196. clif_updatestatus(sd,SP_WEIGHT);
  6197. clif_updatestatus(sd,SP_MAXWEIGHT);
  6198. clif_updatestatus(sd,SP_STR);
  6199. clif_updatestatus(sd,SP_AGI);
  6200. clif_updatestatus(sd,SP_VIT);
  6201. clif_updatestatus(sd,SP_INT);
  6202. clif_updatestatus(sd,SP_DEX);
  6203. clif_updatestatus(sd,SP_LUK);
  6204. if (sd->spiritball)
  6205. clif_spiritball_single(sd->fd, sd);
  6206. if (sd->vd.cloth_color)
  6207. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6208. if(merc_is_hom_active(sd->hd))
  6209. clif_send_homdata(sd,0,0);
  6210. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6211. clif_weather_check(sd);
  6212. if( pc_issit(sd) )
  6213. clif_sitting(&sd->bl); // FIXME: just send to self, not area
  6214. if( pc_isdead(sd) ) //When you refresh, resend the death packet.
  6215. clif_clearunit_single(sd->bl.id,1,sd->fd);
  6216. #ifndef TXT_ONLY
  6217. mail_clear(sd);
  6218. #endif
  6219. return 0;
  6220. }
  6221. // updates the object's (bl) name on client
  6222. int clif_charnameack (int fd, struct block_list *bl)
  6223. {
  6224. unsigned char buf[103];
  6225. int cmd = 0x95, i, ps = -1;
  6226. nullpo_retr(0, bl);
  6227. WBUFW(buf,0) = cmd;
  6228. WBUFL(buf,2) = bl->id;
  6229. switch( bl->type )
  6230. {
  6231. case BL_PC:
  6232. {
  6233. struct map_session_data *ssd = (struct map_session_data *)bl;
  6234. struct party_data *p = NULL;
  6235. struct guild *g = NULL;
  6236. //Requesting your own "shadow" name. [Skotlex]
  6237. if (ssd->fd == fd && ssd->disguise)
  6238. WBUFL(buf,2) = -bl->id;
  6239. if (strlen(ssd->fakename)>1) {
  6240. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6241. break;
  6242. }
  6243. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6244. if (ssd->status.party_id > 0)
  6245. p = party_search(ssd->status.party_id);
  6246. if (ssd->state.bg_id > 0)
  6247. {
  6248. g = bg_guild_get(ssd->state.bg_id);
  6249. ps = 0;
  6250. }
  6251. else if( ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL )
  6252. {
  6253. ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id);
  6254. if( i < g->max_member ) ps = g->member[i].position;
  6255. }
  6256. if (p == NULL && g == NULL)
  6257. break;
  6258. WBUFW(buf, 0) = cmd = 0x195;
  6259. if (p)
  6260. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6261. else
  6262. WBUFB(buf,30) = 0;
  6263. if (g && ps >= 0 && ps < MAX_GUILDPOSITION)
  6264. {
  6265. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6266. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6267. } else { //Assume no guild.
  6268. WBUFB(buf,54) = 0;
  6269. WBUFB(buf,78) = 0;
  6270. }
  6271. }
  6272. break;
  6273. //[blackhole89]
  6274. case BL_HOM:
  6275. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6276. break;
  6277. case BL_MER:
  6278. memcpy(WBUFP(buf,6), ((TBL_MER*)bl)->db->name, NAME_LENGTH);
  6279. break;
  6280. case BL_PET:
  6281. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6282. break;
  6283. case BL_NPC:
  6284. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6285. break;
  6286. case BL_MOB:
  6287. {
  6288. struct mob_data *md = (struct mob_data *)bl;
  6289. struct guild *g;
  6290. struct battleground_data *bg;
  6291. nullpo_retr(0, md);
  6292. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6293. if( md->guardian_data && md->guardian_data->guild_id )
  6294. {
  6295. WBUFW(buf, 0) = cmd = 0x195;
  6296. WBUFB(buf,30) = 0;
  6297. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6298. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6299. }
  6300. else if( md->state.bg_id && (bg = bg_team_search(md->state.bg_id)) != NULL && (g = bg->g) != NULL )
  6301. {
  6302. WBUFW(buf, 0) = cmd = 0x195;
  6303. WBUFB(buf,30) = 0;
  6304. memcpy(WBUFP(buf,54), g->name, NAME_LENGTH);
  6305. memcpy(WBUFP(buf,78), g->position[0].name, NAME_LENGTH);
  6306. }
  6307. else if( battle_config.show_mob_info )
  6308. {
  6309. char mobhp[50], *str_p = mobhp;
  6310. WBUFW(buf, 0) = cmd = 0x195;
  6311. if( battle_config.show_mob_info&4 )
  6312. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6313. if( battle_config.show_mob_info&1 )
  6314. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6315. if( battle_config.show_mob_info&2 )
  6316. str_p += sprintf(str_p, "HP: %d%% | ", get_percentage(md->status.hp, md->status.max_hp));
  6317. //Even thought mobhp ain't a name, we send it as one so the client
  6318. //can parse it. [Skotlex]
  6319. if( str_p != mobhp )
  6320. {
  6321. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6322. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6323. WBUFB(buf,54) = 0;
  6324. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6325. }
  6326. }
  6327. }
  6328. break;
  6329. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6330. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6331. // break;
  6332. return 0;
  6333. default:
  6334. ShowError("clif_charnameack: bad type %d(%d)\n", bl->type, bl->id);
  6335. return 0;
  6336. }
  6337. // if no receipient specified just update nearby clients
  6338. if (fd == 0)
  6339. clif_send(buf, packet_len(cmd), bl, AREA);
  6340. else {
  6341. WFIFOHEAD(fd, packet_len(cmd));
  6342. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  6343. WFIFOSET(fd, packet_len(cmd));
  6344. }
  6345. return 0;
  6346. }
  6347. //Used to update when a char leaves a party/guild. [Skotlex]
  6348. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6349. int clif_charnameupdate (struct map_session_data *ssd)
  6350. {
  6351. unsigned char buf[103];
  6352. int cmd = 0x195, ps = -1, i;
  6353. struct party_data *p = NULL;
  6354. struct guild *g = NULL;
  6355. nullpo_retr(0, ssd);
  6356. if (strlen(ssd->fakename)>1)
  6357. return 0; //No need to update as the party/guild was not displayed anyway.
  6358. WBUFW(buf,0) = cmd;
  6359. WBUFL(buf,2) = ssd->bl.id;
  6360. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6361. if( ssd->status.party_id > 0 )
  6362. p = party_search(ssd->status.party_id);
  6363. if( ssd->state.bg_id > 0 )
  6364. {
  6365. g = bg_guild_get(ssd->state.bg_id);
  6366. ps = 0;
  6367. }
  6368. else if( ssd->status.guild_id > 0 && (g = guild_search(ssd->status.guild_id)) != NULL )
  6369. {
  6370. ARR_FIND(0, g->max_member, i, g->member[i].account_id == ssd->status.account_id && g->member[i].char_id == ssd->status.char_id);
  6371. if( i < g->max_member ) ps = g->member[i].position;
  6372. }
  6373. if( p )
  6374. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6375. else
  6376. WBUFB(buf,30) = 0;
  6377. if( g && ps >= 0 && ps < MAX_GUILDPOSITION )
  6378. {
  6379. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6380. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6381. }
  6382. else
  6383. {
  6384. WBUFB(buf,54) = 0;
  6385. WBUFB(buf,78) = 0;
  6386. }
  6387. // Update nearby clients
  6388. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  6389. return 0;
  6390. }
  6391. void clif_slide(struct block_list *bl, int x, int y)
  6392. {
  6393. unsigned char buf[10];
  6394. nullpo_retv(bl);
  6395. WBUFW(buf, 0) = 0x01ff;
  6396. WBUFL(buf, 2) = bl->id;
  6397. WBUFW(buf, 6) = x;
  6398. WBUFW(buf, 8) = y;
  6399. clif_send(buf, packet_len(0x1ff), bl, AREA);
  6400. if( disguised(bl) )
  6401. {
  6402. WBUFL(buf,2) = -bl->id;
  6403. clif_send(buf, packet_len(0x1ff), bl, SELF);
  6404. }
  6405. }
  6406. /*------------------------------------------
  6407. * @me command by lordalfa, rewritten implementation by Skotlex
  6408. *------------------------------------------*/
  6409. int clif_disp_overhead(struct map_session_data *sd, const char* mes)
  6410. {
  6411. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  6412. int len_mes = strlen(mes)+1; //Account for \0
  6413. if (len_mes + 8 >= 256) {
  6414. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6415. len_mes = 247; //Trunk it to avoid problems.
  6416. }
  6417. // send message to others
  6418. WBUFW(buf,0) = 0x8d;
  6419. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6420. WBUFL(buf,4) = sd->bl.id;
  6421. memcpy(WBUFP(buf,8), mes, len_mes);
  6422. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6423. // send back message to the speaker
  6424. WBUFW(buf,0) = 0x8e;
  6425. WBUFW(buf, 2) = len_mes + 4;
  6426. memcpy(WBUFP(buf,4), mes, len_mes);
  6427. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6428. return 0;
  6429. }
  6430. /*==========================
  6431. * Minimap fix [Kevin]
  6432. * Remove dot from minimap
  6433. *--------------------------*/
  6434. int clif_party_xy_remove(struct map_session_data *sd)
  6435. {
  6436. unsigned char buf[16];
  6437. nullpo_retr(0, sd);
  6438. WBUFW(buf,0)=0x107;
  6439. WBUFL(buf,2)=sd->status.account_id;
  6440. WBUFW(buf,6)=-1;
  6441. WBUFW(buf,8)=-1;
  6442. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6443. return 0;
  6444. }
  6445. //Displays gospel-buff information (thanks to Rayce):
  6446. //Type determines message based on this table:
  6447. /*
  6448. 0x15 End all negative status
  6449. 0x16 Immunity to all status
  6450. 0x17 MaxHP +100%
  6451. 0x18 MaxSP +100%
  6452. 0x19 All stats +20
  6453. 0x1c Enchant weapon with Holy element
  6454. 0x1d Enchant armor with Holy element
  6455. 0x1e DEF +25%
  6456. 0x1f ATK +100%
  6457. 0x20 HIT/Flee +50
  6458. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  6459. */
  6460. void clif_gospel_info(struct map_session_data *sd, int type)
  6461. {
  6462. int fd=sd->fd;
  6463. WFIFOHEAD(fd,packet_len(0x215));
  6464. WFIFOW(fd,0)=0x215;
  6465. WFIFOL(fd,2)=type;
  6466. WFIFOSET(fd, packet_len(0x215));
  6467. }
  6468. /*==========================================
  6469. * Info about Star Glaldiator save map [Komurka]
  6470. * type: 1: Information, 0: Map registered
  6471. *------------------------------------------*/
  6472. void clif_feel_info(struct map_session_data* sd, unsigned char feel_level, unsigned char type)
  6473. {
  6474. int fd=sd->fd;
  6475. WFIFOHEAD(fd,packet_len(0x20e));
  6476. WFIFOW(fd,0) = 0x20e;
  6477. mapindex_getmapname_ext(mapindex_id2name(sd->feel_map[feel_level].index), (char*)WFIFOP(fd,2));
  6478. WFIFOL(fd,26) = sd->bl.id;
  6479. WFIFOB(fd,30) = feel_level;
  6480. WFIFOB(fd,31) = type?1:0;
  6481. WFIFOSET(fd,packet_len(0x20e));
  6482. }
  6483. /*==========================================
  6484. * Info about Star Glaldiator hate mob [Komurka]
  6485. * type: 1: Register mob, 0: Information.
  6486. *------------------------------------------*/
  6487. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  6488. {
  6489. int fd=sd->fd;
  6490. WFIFOHEAD(fd,packet_len(0x20e));
  6491. WFIFOW(fd,0)=0x20e;
  6492. if (pcdb_checkid(class_))
  6493. strncpy((char*)WFIFOP(fd,2),job_name(class_), NAME_LENGTH);
  6494. else if (mobdb_checkid(class_))
  6495. strncpy((char*)WFIFOP(fd,2),mob_db(class_)->jname, NAME_LENGTH);
  6496. else //Really shouldn't happen...
  6497. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  6498. WFIFOL(fd,26)=sd->bl.id;
  6499. WFIFOB(fd,30)=hate_level;
  6500. WFIFOB(fd,31)=type?10:11; //Register/Info
  6501. WFIFOSET(fd, packet_len(0x20e));
  6502. }
  6503. /*==========================================
  6504. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6505. *------------------------------------------*/
  6506. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  6507. {
  6508. int fd=sd->fd;
  6509. WFIFOHEAD(fd,packet_len(0x20e));
  6510. WFIFOW(fd,0)=0x20e;
  6511. strncpy((char*)WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6512. WFIFOL(fd,26)=mob_id;
  6513. WFIFOB(fd,30)=progress; //Message to display
  6514. WFIFOB(fd,31)=20;
  6515. WFIFOSET(fd, packet_len(0x20e));
  6516. }
  6517. /*==========================================
  6518. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  6519. *------------------------------------------*/
  6520. void clif_feel_hate_reset(struct map_session_data *sd)
  6521. {
  6522. int fd=sd->fd;
  6523. WFIFOHEAD(fd,packet_len(0x20e));
  6524. WFIFOW(fd,0)=0x20e;
  6525. memset(WFIFOP(fd,2), 0, NAME_LENGTH); //Blank name as all was reset.
  6526. WFIFOL(fd,26)=sd->bl.id;
  6527. WFIFOB(fd,30)=0; //Feel/hate level: irrelevant
  6528. WFIFOB(fd,31)=30;
  6529. WFIFOSET(fd, packet_len(0x20e));
  6530. }
  6531. /*==========================================
  6532. * Equip window (un)tick ack
  6533. * R 02d9 <zero>.L <flag>.L
  6534. *------------------------------------------*/
  6535. void clif_equiptickack(struct map_session_data* sd, int flag)
  6536. {
  6537. int fd;
  6538. nullpo_retv(sd);
  6539. fd = sd->fd;
  6540. WFIFOHEAD(fd, packet_len(0x2d9));
  6541. WFIFOW(fd, 0) = 0x2d9;
  6542. WFIFOL(fd, 2) = 0;
  6543. WFIFOL(fd, 6) = flag;
  6544. WFIFOSET(fd, packet_len(0x2d9));
  6545. }
  6546. /*==========================================
  6547. * The player's 'view equip' state, sent during login
  6548. * R 02da <flag>.B
  6549. *------------------------------------------*/
  6550. void clif_equipcheckbox(struct map_session_data* sd)
  6551. {
  6552. int fd;
  6553. nullpo_retv(sd);
  6554. fd = sd->fd;
  6555. WFIFOHEAD(fd, packet_len(0x2da));
  6556. WFIFOW(fd, 0) = 0x2da;
  6557. WFIFOW(fd, 2) = (sd->status.show_equip ? 1 : 0);
  6558. WFIFOSET(fd, packet_len(0x2da));
  6559. }
  6560. /*==========================================
  6561. * Sends info about a player's equipped items
  6562. * 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*
  6563. *------------------------------------------*/
  6564. void clif_viewequip_ack(struct map_session_data* sd, struct map_session_data* tsd)
  6565. {
  6566. int i, n, fd;
  6567. nullpo_retv(sd);
  6568. nullpo_retv(tsd);
  6569. fd = sd->fd;
  6570. WFIFOHEAD(fd, MAX_INVENTORY * 26 + 43);
  6571. WFIFOW(fd, 0) = 0x2d7;
  6572. safestrncpy((char*)WFIFOP(fd, 4), tsd->status.name, NAME_LENGTH);
  6573. WFIFOW(fd,28) = tsd->status.class_;
  6574. WFIFOW(fd,30) = tsd->vd.hair_style;
  6575. WFIFOW(fd,32) = tsd->vd.head_top;
  6576. WFIFOW(fd,34) = tsd->vd.head_mid;
  6577. WFIFOW(fd,36) = tsd->vd.head_bottom;
  6578. WFIFOW(fd,38) = tsd->vd.hair_color;
  6579. WFIFOW(fd,40) = tsd->vd.cloth_color;
  6580. WFIFOB(fd,42) = tsd->vd.sex;
  6581. for(i=0,n=0; i < MAX_INVENTORY; i++)
  6582. {
  6583. if (tsd->status.inventory[i].nameid <= 0 || tsd->inventory_data[i] == NULL) // Item doesn't exist
  6584. continue;
  6585. if (itemdb_isstackable2(tsd->inventory_data[i])) // Is not equippable
  6586. continue;
  6587. // Inventory position
  6588. WFIFOW(fd, n*26+43) = i + 2;
  6589. // Add refine, identify flag, element, etc.
  6590. clif_item_sub(WFIFOP(fd,0), n*26+45, &tsd->status.inventory[i], tsd->inventory_data[i], pc_equippoint(tsd, i));
  6591. // Add cards
  6592. clif_addcards(WFIFOP(fd, n*26+55), &tsd->status.inventory[i]);
  6593. // Expiration date stuff, if all of those are set to 0 then the client doesn't show anything related (6 bytes)
  6594. memset(WFIFOP(fd, n*26+63), 0, 6);
  6595. n++;
  6596. }
  6597. WFIFOW(fd, 2) = 43 + n*26; // Set length
  6598. WFIFOSET(fd, WFIFOW(fd, 2));
  6599. }
  6600. /*==========================================
  6601. * View player equip request denied
  6602. * R 0291 <message>.W
  6603. * TODO: this looks like a general-purpose packet to print msgstringtable entries.
  6604. *------------------------------------------*/
  6605. void clif_viewequip_fail(struct map_session_data* sd)
  6606. {
  6607. int fd;
  6608. nullpo_retv(sd);
  6609. fd = sd->fd;
  6610. WFIFOHEAD(fd, packet_len(0x291));
  6611. WFIFOW(fd, 0) = 0x291;
  6612. WFIFOW(fd, 2) = 0x54d; // This controls which message is displayed. 0x54d is the correct one. Maybe it's used for something else too?
  6613. WFIFOSET(fd, packet_len(0x291));
  6614. }
  6615. /// Validates one global/guild/party/whisper message packet and tries to recognize its components.
  6616. /// Returns true if the packet was parsed successfully.
  6617. /// Formats: 0 - <packet id>.w <packet len>.w (<name> : <message>).?B 00
  6618. /// 1 - <packet id>.w <packet len>.w <name>.24B <message>.?B 00
  6619. static bool clif_process_message(struct map_session_data* sd, int format, char** name_, int* namelen_, char** message_, int* messagelen_)
  6620. {
  6621. char *text, *name, *message;
  6622. unsigned int packetlen, textlen, namelen, messagelen;
  6623. int fd = sd->fd;
  6624. *name_ = NULL;
  6625. *namelen_ = 0;
  6626. *message_ = NULL;
  6627. *messagelen_ = 0;
  6628. packetlen = RFIFOW(fd,2);
  6629. // basic structure checks
  6630. if( packetlen > RFIFOREST(fd) )
  6631. { // there has to be enough data to read
  6632. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6633. return false;
  6634. }
  6635. if( packetlen < 4 + 1 )
  6636. { // 4-byte header and at least an empty string is expected
  6637. ShowWarning("clif_process_message: Received malformed packet from player '%s' (no message data)!\n", sd->status.name);
  6638. return false;
  6639. }
  6640. text = (char*)RFIFOP(fd,4);
  6641. textlen = packetlen - 4;
  6642. // process <name> part of the packet
  6643. if( format == 0 )
  6644. {// name and message are separated by ' : '
  6645. // validate name
  6646. name = text;
  6647. namelen = strnlen(sd->status.name, NAME_LENGTH-1); // name length (w/o zero byte)
  6648. if( strncmp(name, sd->status.name, namelen) || // the text must start with the speaker's name
  6649. name[namelen] != ' ' || name[namelen+1] != ':' || name[namelen+2] != ' ' ) // followed by ' : '
  6650. {
  6651. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  6652. ShowWarning("clif_process_message: Player '%s' sent a message using an incorrect name! Forcing a relog...\n", sd->status.name);
  6653. set_eof(fd); // Just kick them out to correct it.
  6654. return false;
  6655. }
  6656. message = name + namelen + 3;
  6657. messagelen = textlen - namelen - 3; // this should be the message length (w/ zero byte included)
  6658. }
  6659. else
  6660. {// name has fixed width
  6661. if( textlen < NAME_LENGTH + 1 )
  6662. {
  6663. ShowWarning("clif_process_message: Received malformed packet from player '%s' (packet length is incorrect)!\n", sd->status.name);
  6664. return false;
  6665. }
  6666. // validate name
  6667. name = text;
  6668. namelen = strnlen(name, NAME_LENGTH-1); // name length (w/o zero byte)
  6669. if( name[namelen] != '\0' )
  6670. { // only restriction is that the name must be zero-terminated
  6671. ShowWarning("clif_process_message: Player '%s' sent an unterminated name!\n", sd->status.name);
  6672. return false;
  6673. }
  6674. message = name + NAME_LENGTH;
  6675. messagelen = textlen - NAME_LENGTH; // this should be the message length (w/ zero byte included)
  6676. }
  6677. if( messagelen != strnlen(message, messagelen)+1 )
  6678. { // the declared length must match real length
  6679. ShowWarning("clif_process_message: Received malformed packet from player '%s' (length is incorrect)!\n", sd->status.name);
  6680. return false;
  6681. }
  6682. // verify <message> part of the packet
  6683. if( message[messagelen-1] != '\0' )
  6684. { // message must be zero-terminated
  6685. ShowWarning("clif_process_message: Player '%s' sent an unterminated message string!\n", sd->status.name);
  6686. return false;
  6687. }
  6688. if( messagelen > CHAT_SIZE_MAX-1 )
  6689. { // messages mustn't be too long
  6690. // Normally you can only enter CHATBOX_SIZE-1 letters into the chat box, but Frost Joke / Dazzler's text can be longer.
  6691. // Also, the physical size of strings that use multibyte encoding can go multiple times over the chatbox capacity.
  6692. // Neither the official client nor server place any restriction on the length of the data in the packet,
  6693. // but we'll only allow reasonably long strings here. This also makes sure that they fit into the `chatlog` table.
  6694. ShowWarning("clif_process_message: Player '%s' sent a message too long ('%.*s')!\n", sd->status.name, CHAT_SIZE_MAX-1, message);
  6695. return false;
  6696. }
  6697. *name_ = name;
  6698. *namelen_ = namelen;
  6699. *message_ = message;
  6700. *messagelen_ = messagelen;
  6701. return true;
  6702. }
  6703. // ---------------------
  6704. // clif_guess_PacketVer
  6705. // ---------------------
  6706. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  6707. // error codes:
  6708. // 0 - Success
  6709. // 1 - Unknown packet_ver
  6710. // 2 - Invalid account_id
  6711. // 3 - Invalid char_id
  6712. // 4 - Invalid login_id1 (reserved)
  6713. // 5 - Invalid client_tick (reserved)
  6714. // 6 - Invalid sex
  6715. // Only the first 'invalid' error that appears is used.
  6716. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  6717. {
  6718. static int err = 1;
  6719. static int packet_ver = -1;
  6720. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  6721. if (get_previous)
  6722. {//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]
  6723. if( error )
  6724. *error = err;
  6725. return packet_ver;
  6726. }
  6727. //By default, start searching on the default one.
  6728. err = 1;
  6729. packet_ver = clif_config.packet_db_ver;
  6730. cmd = RFIFOW(fd,0);
  6731. packet_len = RFIFOREST(fd);
  6732. #define SET_ERROR(n) \
  6733. if( err == 1 )\
  6734. err = n;\
  6735. //define SET_ERROR
  6736. #define CHECK_PACKET_VER() \
  6737. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  6738. ;/* not wanttoconnection or wrong length */\
  6739. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > END_ACCOUNT_NUM )\
  6740. { SET_ERROR(2); }/* invalid account_id */\
  6741. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 )\
  6742. { SET_ERROR(3); }/* invalid char_id */\
  6743. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  6744. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  6745. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  6746. { SET_ERROR(6); }/* invalid sex */\
  6747. else\
  6748. {\
  6749. err = 0;\
  6750. if( error )\
  6751. *error = 0;\
  6752. return packet_ver;\
  6753. }\
  6754. //define CHECK_PACKET_VER
  6755. CHECK_PACKET_VER();//Default packet version found.
  6756. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  6757. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  6758. CHECK_PACKET_VER();
  6759. }
  6760. if( error )
  6761. *error = err;
  6762. packet_ver = -1;
  6763. return -1;
  6764. #undef SET_ERROR
  6765. #undef CHECK_PACKET_VER
  6766. }
  6767. // ------------
  6768. // clif_parse_*
  6769. // ------------
  6770. // パケット読み取って色々操作
  6771. /*==========================================
  6772. *
  6773. *------------------------------------------*/
  6774. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  6775. {
  6776. struct block_list* bl;
  6777. struct auth_node* node;
  6778. int cmd, account_id, char_id, login_id1, sex;
  6779. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  6780. 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])
  6781. if (sd) {
  6782. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)\n");
  6783. return;
  6784. }
  6785. // Only valid packet version get here
  6786. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  6787. cmd = RFIFOW(fd,0);
  6788. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  6789. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  6790. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  6791. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  6792. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  6793. if( packet_ver < 5 || // reject really old client versions
  6794. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  6795. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  6796. {// packet version rejected
  6797. 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));
  6798. WFIFOHEAD(fd,packet_len(0x6a));
  6799. WFIFOW(fd,0) = 0x6a;
  6800. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  6801. WFIFOSET(fd,packet_len(0x6a));
  6802. set_eof(fd);
  6803. return;
  6804. }
  6805. //Check for double login.
  6806. bl = map_id2bl(account_id);
  6807. if(bl && bl->type != BL_PC) {
  6808. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  6809. WFIFOHEAD(fd,packet_len(0x6a));
  6810. WFIFOW(fd,0) = 0x6a;
  6811. WFIFOB(fd,2) = 3; // Rejected by server
  6812. WFIFOSET(fd,packet_len(0x6a));
  6813. set_eof(fd);
  6814. return;
  6815. }
  6816. if (bl ||
  6817. ((node=chrif_search(account_id)) && //An already existing node is valid only if it is for this login.
  6818. !(node->account_id == account_id && node->char_id == char_id && node->state == ST_LOGIN))) {
  6819. sd = BL_CAST(BL_PC, bl);
  6820. if (!sd)
  6821. ; //We have another char with the same account logging in/out.
  6822. else //Already connected player.
  6823. if (sd->fd)
  6824. clif_authfail_fd(sd->fd, 2); //someone else logged in
  6825. else
  6826. if(sd->state.autotrade)
  6827. map_quit(sd);// kick autotrading character
  6828. //Else do not kick character, it could be on its 10 sec penalty for Alt+F4
  6829. clif_authfail_fd(fd, 8); //Still recognizes last connection
  6830. return;
  6831. }
  6832. CREATE(sd, TBL_PC, 1);
  6833. sd->fd = fd;
  6834. sd->packet_ver = packet_ver;
  6835. session[fd]->session_data = sd;
  6836. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  6837. #if PACKETVER < 20070521
  6838. WFIFOHEAD(fd,4);
  6839. WFIFOL(fd,0) = sd->bl.id;
  6840. WFIFOSET(fd,4);
  6841. #else
  6842. WFIFOHEAD(fd,packet_len(0x283));
  6843. WFIFOW(fd,0) = 0x283;
  6844. WFIFOL(fd,2) = sd->bl.id;
  6845. WFIFOSET(fd,packet_len(0x283));
  6846. #endif
  6847. chrif_authreq(sd);
  6848. return;
  6849. }
  6850. /*==========================================
  6851. * 007d クライアント側マップ読み込み完了
  6852. * map侵入時に必要なデータを全て送りつける
  6853. *------------------------------------------*/
  6854. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  6855. {
  6856. if(sd->bl.prev != NULL)
  6857. return;
  6858. if (!sd->state.active)
  6859. { //Character loading is not complete yet!
  6860. //Let pc_reg_received reinvoke this when ready.
  6861. sd->state.connect_new = 0;
  6862. return;
  6863. }
  6864. if (sd->state.rewarp)
  6865. { //Rewarp player.
  6866. sd->state.rewarp = 0;
  6867. clif_changemap(sd, sd->mapindex, sd->bl.x, sd->bl.y);
  6868. return;
  6869. }
  6870. // look
  6871. #if PACKETVER < 4
  6872. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  6873. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  6874. #else
  6875. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  6876. #endif
  6877. if(sd->vd.cloth_color)
  6878. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  6879. // item
  6880. pc_checkitem(sd);
  6881. clif_inventorylist(sd);
  6882. // cart
  6883. if(pc_iscarton(sd)) {
  6884. clif_cartlist(sd);
  6885. clif_updatestatus(sd,SP_CARTINFO);
  6886. }
  6887. // weight
  6888. clif_updatestatus(sd,SP_WEIGHT);
  6889. clif_updatestatus(sd,SP_MAXWEIGHT);
  6890. // guild
  6891. // (needs to go before clif_spawn() to show guild emblems correctly)
  6892. if(sd->status.guild_id)
  6893. guild_send_memberinfoshort(sd,1);
  6894. if(battle_config.pc_invincible_time > 0) {
  6895. if(map_flag_gvg(sd->bl.m))
  6896. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  6897. else
  6898. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  6899. }
  6900. if (map[sd->bl.m].users++ == 0 && battle_config.dynamic_mobs) //Skotlex
  6901. map_spawnmobs(sd->bl.m);
  6902. sd->state.debug_remove_map = 0; // temporary state to track double remove_map's [FlavioJS]
  6903. map_addblock(&sd->bl);
  6904. clif_spawn(&sd->bl);
  6905. // Party
  6906. // (needs to go after clif_spawn() to show hp bars correctly)
  6907. if(sd->status.party_id) {
  6908. party_send_movemap(sd);
  6909. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  6910. }
  6911. if( sd->state.bg_id )
  6912. clif_bg_hp(sd); // BattleGround System
  6913. if(map[sd->bl.m].flag.pvp) {
  6914. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  6915. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  6916. sd->pvp_timer = add_timer(gettick()+200, pc_calc_pvprank_timer, sd->bl.id, 0);
  6917. sd->pvp_rank = 0;
  6918. sd->pvp_lastusers = 0;
  6919. sd->pvp_point = 5;
  6920. sd->pvp_won = 0;
  6921. sd->pvp_lost = 0;
  6922. }
  6923. clif_set0199(sd,1);
  6924. } else
  6925. // set flag, if it's a duel [LuzZza]
  6926. if(sd->duel_group)
  6927. clif_set0199(sd,1);
  6928. if (map[sd->bl.m].flag.gvg_dungeon)
  6929. {
  6930. clif_set0199(sd,1); //TODO: Figure out the real packet to send here.
  6931. if (!sd->pvp_point)
  6932. {
  6933. sd->pvp_point = 5; //Need to die twice to be warped out.
  6934. sd->pvp_won = 0;
  6935. sd->pvp_lost = 0;
  6936. }
  6937. }
  6938. if( map_flag_gvg(sd->bl.m) || map[sd->bl.m].flag.battleground )
  6939. {
  6940. clif_set0199(sd,3);
  6941. if( battle_config.gvg_flee_penalty != 100 || battle_config.bg_flee_penalty != 100 )
  6942. status_calc_bl(&sd->bl, SCB_FLEE); //Apply flee penalty
  6943. }
  6944. // info about nearby objects
  6945. // must use foreachinarea (CIRCULAR_AREA interferes with foreachinrange)
  6946. 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);
  6947. //TODO: merge it with the code below
  6948. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m) && sd->pd)
  6949. { //Return the pet to egg. [Skotlex]
  6950. clif_displaymessage(sd->fd, "Pets are not allowed in Guild Wars.");
  6951. pet_menu(sd, 3); //Option 3 is return to egg.
  6952. }
  6953. // pet
  6954. if(sd->pd) {
  6955. map_addblock(&sd->pd->bl);
  6956. clif_spawn(&sd->pd->bl);
  6957. clif_send_petdata(sd,sd->pd,0,0);
  6958. clif_send_petstatus(sd);
  6959. // skill_unit_move(&sd->pd->bl,gettick(),1);
  6960. }
  6961. //homunculus [blackhole89]
  6962. if( merc_is_hom_active(sd->hd) )
  6963. {
  6964. map_addblock(&sd->hd->bl);
  6965. clif_spawn(&sd->hd->bl);
  6966. clif_send_homdata(sd,0,0);
  6967. clif_hominfo(sd,sd->hd,1);
  6968. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  6969. clif_homskillinfoblock(sd);
  6970. if( battle_config.hom_setting&0x8 )
  6971. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  6972. if( !(battle_config.hom_setting&0x2) )
  6973. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  6974. }
  6975. if( sd->md )
  6976. {
  6977. map_addblock(&sd->md->bl);
  6978. clif_spawn(&sd->md->bl);
  6979. clif_mercenary_info(sd);
  6980. clif_mercenary_skillblock(sd);
  6981. }
  6982. if(sd->state.connect_new) {
  6983. int lv;
  6984. sd->state.connect_new = 0;
  6985. clif_skillinfoblock(sd);
  6986. clif_hotkeys_send(sd);
  6987. clif_updatestatus(sd,SP_NEXTBASEEXP);
  6988. clif_updatestatus(sd,SP_NEXTJOBEXP);
  6989. clif_updatestatus(sd,SP_SKILLPOINT);
  6990. clif_initialstatus(sd);
  6991. if (sd->sc.option&OPTION_FALCON)
  6992. clif_status_load(&sd->bl, SI_FALCON, 1);
  6993. if (sd->sc.option&OPTION_RIDING)
  6994. clif_status_load(&sd->bl, SI_RIDING, 1);
  6995. if(sd->status.manner < 0)
  6996. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  6997. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  6998. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  6999. if(sd->bl.m == sd->feel_map[0].m
  7000. || sd->bl.m == sd->feel_map[1].m
  7001. || sd->bl.m == sd->feel_map[2].m)
  7002. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7003. }
  7004. if(sd->pd && sd->pd->pet.intimate > 900)
  7005. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7006. if(merc_is_hom_active(sd->hd))
  7007. merc_hom_init_timers(sd->hd);
  7008. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7009. {
  7010. sd->state.night = 1;
  7011. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7012. }
  7013. #if PACKETVER >= 20070918
  7014. clif_equipcheckbox(sd);
  7015. #endif
  7016. // Notify everyone that this char logged in [Skotlex].
  7017. map_foreachpc(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  7018. //Login Event
  7019. npc_script_event(sd, NPCE_LOGIN);
  7020. } else {
  7021. //For some reason the client "loses" these on warp/map-change.
  7022. clif_updatestatus(sd,SP_STR);
  7023. clif_updatestatus(sd,SP_AGI);
  7024. clif_updatestatus(sd,SP_VIT);
  7025. clif_updatestatus(sd,SP_INT);
  7026. clif_updatestatus(sd,SP_DEX);
  7027. clif_updatestatus(sd,SP_LUK);
  7028. // abort currently running script
  7029. sd->state.using_fake_npc = 0;
  7030. sd->state.menu_or_input = 0;
  7031. sd->npc_menu = 0;
  7032. if(sd->npc_id)
  7033. npc_event_dequeue(sd);
  7034. }
  7035. if( sd->state.changemap )
  7036. {// restore information that gets lost on map-change
  7037. if( night_flag && map[sd->bl.m].flag.nightenabled )
  7038. { //Display night.
  7039. if( !sd->state.night )
  7040. {
  7041. sd->state.night = 1;
  7042. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7043. }
  7044. }
  7045. else if( sd->state.night )
  7046. { //Clear night display.
  7047. sd->state.night = 0;
  7048. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7049. }
  7050. if( map[sd->bl.m].flag.allowks && !map_flag_ks(sd->bl.m) )
  7051. {
  7052. char output[128];
  7053. sprintf(output, "[ Kill Steal Protection Disable. KS is allowed in this map ]");
  7054. clif_announce(&sd->bl, output, strlen(output) + 1, 0x00CC66, 3);
  7055. }
  7056. map_iwall_get(sd); // Updates Walls Info on this Map to Client
  7057. sd->state.changemap = false;
  7058. }
  7059. #ifndef TXT_ONLY
  7060. mail_clear(sd);
  7061. #endif
  7062. quest_pc_login(sd);
  7063. if(map[sd->bl.m].flag.loadevent) // Lance
  7064. npc_script_event(sd, NPCE_LOADMAP);
  7065. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7066. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7067. if (sd->sc.opt2) //Client loses these on warp.
  7068. clif_changeoption(&sd->bl);
  7069. clif_weather_check(sd);
  7070. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7071. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7072. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7073. else
  7074. sd->areanpc_id = 0;
  7075. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  7076. if(pc_isdead(sd))
  7077. clif_clearunit_area(&sd->bl, 1);
  7078. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  7079. // else
  7080. // clif_changed_dir(&sd->bl, SELF);
  7081. // Trigger skill effects if you appear standing on them
  7082. if(!battle_config.pc_invincible_time)
  7083. skill_unit_move(&sd->bl,gettick(),1);
  7084. }
  7085. /*==========================================
  7086. *
  7087. *------------------------------------------*/
  7088. void clif_parse_TickSend(int fd, struct map_session_data *sd)
  7089. {
  7090. sd->client_tick = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7091. WFIFOHEAD(fd, packet_len(0x7f));
  7092. WFIFOW(fd,0)=0x7f;
  7093. WFIFOL(fd,2)=gettick();
  7094. WFIFOSET(fd,packet_len(0x7f));
  7095. // removed until the socket problems are fixed. [FlavioJS]
  7096. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  7097. return;
  7098. }
  7099. void clif_hotkeys_send(struct map_session_data *sd) {
  7100. #ifdef HOTKEY_SAVING
  7101. const int fd = sd->fd;
  7102. int i;
  7103. if (!fd) return;
  7104. WFIFOHEAD(fd, 2+MAX_HOTKEYS*7);
  7105. WFIFOW(fd, 0) = 0x02b9;
  7106. for(i = 0; i < MAX_HOTKEYS; i++) {
  7107. WFIFOB(fd, 2 + 0 + i * 7) = sd->status.hotkeys[i].type; // type: 0: item, 1: skill
  7108. WFIFOL(fd, 2 + 1 + i * 7) = sd->status.hotkeys[i].id; // item or skill ID
  7109. WFIFOW(fd, 2 + 5 + i * 7) = sd->status.hotkeys[i].lv; // skill level
  7110. }
  7111. WFIFOSET(fd, packet_len(0x02b9));
  7112. #endif
  7113. }
  7114. void clif_parse_Hotkey(int fd, struct map_session_data *sd) {
  7115. #ifdef HOTKEY_SAVING
  7116. unsigned short idx;
  7117. int cmd;
  7118. cmd = RFIFOW(fd, 0);
  7119. idx = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[0]);
  7120. if (idx >= MAX_HOTKEYS) return;
  7121. sd->status.hotkeys[idx].type = RFIFOB(fd, packet_db[sd->packet_ver][cmd].pos[1]);
  7122. sd->status.hotkeys[idx].id = RFIFOL(fd, packet_db[sd->packet_ver][cmd].pos[2]);
  7123. sd->status.hotkeys[idx].lv = RFIFOW(fd, packet_db[sd->packet_ver][cmd].pos[3]);
  7124. return;
  7125. #endif
  7126. }
  7127. /*==========================================
  7128. *
  7129. *------------------------------------------*/
  7130. void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
  7131. {
  7132. short x, y;
  7133. int cmd;
  7134. if (pc_isdead(sd)) {
  7135. clif_clearunit_area(&sd->bl, 1);
  7136. return;
  7137. }
  7138. if (sd->sc.opt1 && sd->sc.opt1 == OPT1_STONEWAIT)
  7139. ; //You CAN walk on this OPT1 value.
  7140. else if (pc_cant_act(sd))
  7141. return;
  7142. if(sd->sc.data[SC_RUN])
  7143. return;
  7144. pc_delinvincibletimer(sd);
  7145. cmd = RFIFOW(fd,0);
  7146. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7147. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7148. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7149. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7150. //Set last idle time... [Skotlex]
  7151. sd->idletime = last_tick;
  7152. unit_walktoxy(&sd->bl, x, y, 4);
  7153. }
  7154. /*==========================================
  7155. *
  7156. *------------------------------------------*/
  7157. void clif_parse_QuitGame(int fd, struct map_session_data *sd)
  7158. {
  7159. WFIFOHEAD(fd,packet_len(0x18b));
  7160. WFIFOW(fd,0) = 0x18b;
  7161. /* Rovert's prevent logout option fixed [Valaris] */
  7162. if (!sd->sc.data[SC_CLOAKING] && !sd->sc.data[SC_HIDING] &&
  7163. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7164. ) {
  7165. set_eof(fd);
  7166. WFIFOW(fd,2)=0;
  7167. } else {
  7168. WFIFOW(fd,2)=1;
  7169. }
  7170. WFIFOSET(fd,packet_len(0x18b));
  7171. }
  7172. /// Requesting unit's name
  7173. /// S 0094 <object id>.l
  7174. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
  7175. {
  7176. int id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7177. struct block_list* bl;
  7178. //struct status_change *sc;
  7179. if( id < 0 && -id == sd->bl.id ) // for disguises [Valaris]
  7180. id = sd->bl.id;
  7181. bl = map_id2bl(id);
  7182. if( bl == NULL )
  7183. return; // Lagged clients could request names of already gone mobs/players. [Skotlex]
  7184. // 'see people in GM hide' cheat detection
  7185. /* disabled due to false positives (network lag + request name of char that's about to hide = race condition)
  7186. sc = status_get_sc(bl);
  7187. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  7188. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  7189. pc_isGM(sd) < battle_config.hack_info_GM_level
  7190. ) {
  7191. char gm_msg[256];
  7192. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requested the name of an invisible target (id: %d).\n", sd->status.name, sd->status.account_id, id);
  7193. ShowWarning(gm_msg);
  7194. // information is sent to all online GMs
  7195. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7196. return;
  7197. }
  7198. */
  7199. clif_charnameack(fd, bl);
  7200. }
  7201. /*==========================================
  7202. * Validates and processes global messages
  7203. * S 008c/00f3 <packet len>.w <text>.?B (<name> : <message>) 00
  7204. *------------------------------------------*/
  7205. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  7206. {
  7207. const char* text = (char*)RFIFOP(fd,4);
  7208. int textlen = RFIFOW(fd,2) - 4;
  7209. char *name, *message;
  7210. int namelen, messagelen;
  7211. // validate packet and retrieve name and message
  7212. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  7213. return;
  7214. if( is_atcommand(fd, sd, message, 1) )
  7215. return;
  7216. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  7217. return;
  7218. if( battle_config.min_chat_delay )
  7219. { //[Skotlex]
  7220. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7221. return;
  7222. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7223. }
  7224. // send message to others (using the send buffer for temp. storage)
  7225. WFIFOHEAD(fd, 8 + textlen);
  7226. WFIFOW(fd,0) = 0x8d;
  7227. WFIFOW(fd,2) = 8 + textlen;
  7228. WFIFOL(fd,4) = sd->bl.id;
  7229. safestrncpy((char*)WFIFOP(fd,8), text, textlen);
  7230. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7231. // send back message to the speaker
  7232. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), RFIFOW(fd,2));
  7233. WFIFOW(fd,0) = 0x8e;
  7234. WFIFOSET(fd, WFIFOW(fd,2));
  7235. #ifdef PCRE_SUPPORT
  7236. // trigger listening npcs
  7237. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, text, textlen, &sd->bl);
  7238. #endif
  7239. // check for special supernovice phrase
  7240. if( (sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE )
  7241. {
  7242. unsigned int next = pc_nextbaseexp(sd);
  7243. if( next == 0 ) next = pc_thisbaseexp(sd);
  7244. if( get_percentage(sd->status.base_exp, next)% 10 == 0 ) // 0%, 10%, 20%, ...
  7245. {
  7246. switch (sd->state.snovice_call_flag) {
  7247. case 0:
  7248. if( strstr(message, msg_txt(504)) ) // "Guardian Angel, can you hear my voice? ^^;"
  7249. sd->state.snovice_call_flag++;
  7250. break;
  7251. case 1: {
  7252. char buf[256];
  7253. sprintf(buf, msg_txt(505), sd->status.name);
  7254. if( strstr(message, buf) ) // "My name is %s, and I'm a Super Novice~"
  7255. sd->state.snovice_call_flag++;
  7256. }
  7257. break;
  7258. case 2:
  7259. if( strstr(message, msg_txt(506)) ) // "Please help me~ T.T"
  7260. sd->state.snovice_call_flag++;
  7261. break;
  7262. case 3:
  7263. if( skillnotok(MO_EXPLOSIONSPIRITS,sd) )
  7264. break; //Do not override the noskill mapflag. [Skotlex]
  7265. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7266. sc_start(&sd->bl,status_skill2sc(MO_EXPLOSIONSPIRITS),100,
  7267. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7268. sd->state.snovice_call_flag = 0;
  7269. break;
  7270. }
  7271. }
  7272. }
  7273. // Chat logging type 'O' / Global Chat
  7274. if( log_config.chat&1 || (log_config.chat&2 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  7275. log_chat("O", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7276. return;
  7277. }
  7278. /*==========================================
  7279. * /mm /mapmove (as @rura GM command)
  7280. *------------------------------------------*/
  7281. void clif_parse_MapMove(int fd, struct map_session_data *sd)
  7282. {
  7283. char output[MAP_NAME_LENGTH_EXT+15]; // Max length of a short: ' -6XXXX' -> 7 digits
  7284. char message[MAP_NAME_LENGTH_EXT+15+5]; // "/mm "+output
  7285. char* map_name;
  7286. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7287. return;
  7288. if(pc_isGM(sd) < get_atcommand_level(atcommand_mapmove))
  7289. return;
  7290. map_name = (char*)RFIFOP(fd,2);
  7291. map_name[MAP_NAME_LENGTH_EXT-1]='\0';
  7292. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7293. atcommand_mapmove(fd, sd, "@mapmove", output);
  7294. if( log_config.gm && get_atcommand_level(atcommand_mapmove) >= log_config.gm )
  7295. {
  7296. sprintf(message, "/mm %s", output);
  7297. log_atcommand(sd, message);
  7298. }
  7299. return;
  7300. }
  7301. /*==========================================
  7302. *
  7303. *------------------------------------------*/
  7304. void clif_changed_dir(struct block_list *bl, enum send_target target)
  7305. {
  7306. unsigned char buf[64];
  7307. WBUFW(buf,0) = 0x9c;
  7308. WBUFL(buf,2) = bl->id;
  7309. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7310. WBUFB(buf,8) = unit_getdir(bl);
  7311. clif_send(buf, packet_len(0x9c), bl, target);
  7312. if (disguised(bl)) {
  7313. WBUFL(buf,2) = -bl->id;
  7314. WBUFW(buf,6) = 0;
  7315. clif_send(buf, packet_len(0x9c), bl, SELF);
  7316. }
  7317. return;
  7318. }
  7319. /*==========================================
  7320. *
  7321. *------------------------------------------*/
  7322. void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
  7323. {
  7324. unsigned char headdir, dir;
  7325. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7326. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7327. pc_setdir(sd, dir, headdir);
  7328. clif_changed_dir(&sd->bl, AREA_WOS);
  7329. return;
  7330. }
  7331. /*==========================================
  7332. *
  7333. *------------------------------------------*/
  7334. void clif_parse_Emotion(int fd, struct map_session_data *sd)
  7335. {
  7336. unsigned char buf[64];
  7337. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7338. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7339. clif_skill_fail(sd, 1, 0, 1);
  7340. return;
  7341. }
  7342. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7343. if (sd->emotionlasttime >= time(NULL)) {
  7344. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7345. clif_skill_fail(sd, 1, 0, 1);
  7346. return;
  7347. }
  7348. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7349. WBUFW(buf,0) = 0xc0;
  7350. WBUFL(buf,2) = sd->bl.id;
  7351. WBUFB(buf,6) = RFIFOB(fd,2);
  7352. clif_send(buf, packet_len(0xc0), &sd->bl, AREA);
  7353. } else
  7354. clif_skill_fail(sd, 1, 0, 1);
  7355. }
  7356. /*==========================================
  7357. *
  7358. *------------------------------------------*/
  7359. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd)
  7360. {
  7361. WFIFOHEAD(fd,packet_len(0xc2));
  7362. WFIFOW(fd,0) = 0xc2;
  7363. WFIFOL(fd,2) = map_getusers();
  7364. WFIFOSET(fd,packet_len(0xc2));
  7365. }
  7366. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7367. {
  7368. if (pc_isdead(sd)) {
  7369. clif_clearunit_area(&sd->bl, 1);
  7370. return;
  7371. }
  7372. if (sd->sc.count &&
  7373. (sd->sc.data[SC_TRICKDEAD] ||
  7374. sd->sc.data[SC_AUTOCOUNTER] ||
  7375. sd->sc.data[SC_BLADESTOP]))
  7376. return;
  7377. pc_stop_walking(sd, 1);
  7378. pc_stop_attack(sd);
  7379. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7380. target_id = sd->bl.id;
  7381. switch(action_type)
  7382. {
  7383. case 0x00: // once attack
  7384. case 0x07: // continuous attack
  7385. if( pc_cant_act(sd) || sd->sc.option&OPTION_HIDE )
  7386. return;
  7387. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  7388. return;
  7389. if( sd->sc.data[SC_BASILICA] )
  7390. return;
  7391. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7392. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7393. clif_skill_fail(sd, 1, 4, 0);
  7394. return;
  7395. }
  7396. }
  7397. pc_delinvincibletimer(sd);
  7398. sd->idletime = last_tick;
  7399. unit_attack(&sd->bl, target_id, action_type != 0);
  7400. break;
  7401. case 0x02: // sitdown
  7402. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7403. clif_skill_fail(sd, 1, 0, 2);
  7404. break;
  7405. }
  7406. if(pc_issit(sd)) {
  7407. //Bugged client? Just refresh them.
  7408. clif_sitting(&sd->bl);
  7409. return;
  7410. }
  7411. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7412. break;
  7413. if (sd->sc.count && (
  7414. sd->sc.data[SC_DANCING] ||
  7415. (sd->sc.data[SC_GRAVITATION] && sd->sc.data[SC_GRAVITATION]->val3 == BCT_SELF)
  7416. )) //No sitting during these states either.
  7417. break;
  7418. pc_setsit(sd);
  7419. skill_sit(sd,1);
  7420. clif_sitting(&sd->bl);
  7421. break;
  7422. case 0x03: // standup
  7423. if (!pc_issit(sd)) {
  7424. //Bugged client? Just refresh them.
  7425. clif_standing(&sd->bl);
  7426. return;
  7427. }
  7428. pc_setstand(sd);
  7429. skill_sit(sd,0);
  7430. clif_standing(&sd->bl);
  7431. break;
  7432. }
  7433. }
  7434. /*==========================================
  7435. *
  7436. *------------------------------------------*/
  7437. void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
  7438. {
  7439. clif_parse_ActionRequest_sub(sd,
  7440. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7441. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7442. gettick()
  7443. );
  7444. }
  7445. /*==========================================
  7446. *
  7447. *------------------------------------------*/
  7448. void clif_parse_Restart(int fd, struct map_session_data *sd)
  7449. {
  7450. switch(RFIFOB(fd,2)) {
  7451. case 0x00:
  7452. pc_respawn(sd,2);
  7453. break;
  7454. case 0x01:
  7455. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7456. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7457. { //Send to char-server for character selection.
  7458. chrif_charselectreq(sd, session[fd]->client_addr);
  7459. } else {
  7460. WFIFOHEAD(fd,packet_len(0x18b));
  7461. WFIFOW(fd,0)=0x18b;
  7462. WFIFOW(fd,2)=1;
  7463. WFIFOSET(fd,packet_len(0x018b));
  7464. }
  7465. break;
  7466. }
  7467. }
  7468. /*==========================================
  7469. * Validates and processes whispered messages
  7470. * S 0096 <packet len>.w <nick>.23B 00 <message>.?B
  7471. *------------------------------------------*/
  7472. void clif_parse_WisMessage(int fd, struct map_session_data* sd)
  7473. {
  7474. struct map_session_data* dstsd;
  7475. int i;
  7476. char *target, *message;
  7477. int namelen, messagelen;
  7478. // validate packet and retrieve name and message
  7479. if( !clif_process_message(sd, 1, &target, &namelen, &message, &messagelen) )
  7480. return;
  7481. if (is_atcommand(fd, sd, message, 1) )
  7482. return;
  7483. if (sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT))
  7484. return;
  7485. if (battle_config.min_chat_delay)
  7486. { //[Skotlex]
  7487. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  7488. return;
  7489. }
  7490. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7491. }
  7492. // Chat logging type 'W' / Whisper
  7493. if( log_config.chat&1 || (log_config.chat&4 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  7494. log_chat("W", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
  7495. //-------------------------------------------------------//
  7496. // Lordalfa - Paperboy - To whisper NPC commands //
  7497. //-------------------------------------------------------//
  7498. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) > 4))
  7499. {
  7500. char* str = target+4; //Skip the NPC: string part.
  7501. struct npc_data* npc;
  7502. if ((npc = npc_name2id(str)))
  7503. {
  7504. char split_data[10][50];
  7505. char *split;
  7506. char output[256];
  7507. str = message;
  7508. for( i = 0; i < 10; ++i )
  7509. {// Splits the message using '#' as separators
  7510. split = strchr(str,'#');
  7511. if( split == NULL )
  7512. { // use the remaining string
  7513. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7514. for( ++i; i < 10; ++i )
  7515. split_data[i][0] = '\0';
  7516. break;
  7517. }
  7518. *split = '\0';
  7519. safestrncpy(split_data[i], str, ARRAYLENGTH(split_data[i]));
  7520. str = split+1;
  7521. }
  7522. for( i = 0; i < 10; ++i )
  7523. {
  7524. sprintf(output, "@whispervar%d$", i);
  7525. set_var(sd,output,(char *) split_data[i]);
  7526. }
  7527. sprintf(output, "%s::OnWhisperGlobal", npc->name);
  7528. npc_event(sd,output,0); // Calls the NPC label
  7529. return;
  7530. }
  7531. }
  7532. // Main chat [LuzZza]
  7533. if(strcmpi(target, main_chat_nick) == 0)
  7534. {
  7535. if(!sd->state.mainchat)
  7536. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7537. else {
  7538. char output[256];
  7539. snprintf(output, ARRAYLENGTH(output), msg_txt(386), sd->status.name, message);
  7540. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7541. }
  7542. // Chat logging type 'M' / Main Chat
  7543. if( log_config.chat&1 || (log_config.chat&32 && !((agit_flag || agit2_flag) && log_config.chat&64)) )
  7544. log_chat("M", 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, message);
  7545. return;
  7546. }
  7547. // searching destination character
  7548. dstsd = map_nick2sd(target);
  7549. if (dstsd == NULL || strcmp(dstsd->status.name, target) != 0)
  7550. {
  7551. // player is not on this map-server
  7552. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7553. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7554. // and if we ask for 'Test', we must not contact 'test' player
  7555. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7556. intif_wis_message(sd, target, message, messagelen);
  7557. return;
  7558. }
  7559. // if player ignores everyone
  7560. if (dstsd->state.ignoreAll)
  7561. {
  7562. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7563. clif_wis_end(fd, 1); // 1: target character is not loged in
  7564. else
  7565. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7566. return;
  7567. }
  7568. // if player ignores the source character
  7569. ARR_FIND(0, MAX_IGNORE_LIST, i, dstsd->ignore[i].name[0] == '\0' || strcmp(dstsd->ignore[i].name, sd->status.name) == 0);
  7570. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  7571. { // source char present in ignore list
  7572. clif_wis_end(fd, 2); // 2: ignored by target
  7573. return;
  7574. }
  7575. // if player is autotrading
  7576. if( dstsd->state.autotrade == 1 )
  7577. {
  7578. char output[256];
  7579. sprintf(output, "%s is in autotrade mode and cannot receive whispered messages.", dstsd->status.name);
  7580. clif_wis_message(fd, sd->status.name, output, strlen(output) + 1);
  7581. return;
  7582. }
  7583. // notify sender of success
  7584. clif_wis_end(fd, 0); // 0: success to send wisper
  7585. // if player has an auto-away message
  7586. if(dstsd->away_message[0] != '\0')
  7587. {
  7588. char output[256];
  7589. sprintf(output, "%s %s", message, msg_txt(543)); // "(Automessage has been sent)"
  7590. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  7591. if(dstsd->state.autotrade)
  7592. sprintf(output, msg_txt(544), dstsd->away_message); // "Away [AT] - "%s""
  7593. else
  7594. sprintf(output, msg_txt(545), dstsd->away_message); // "Away - "%s""
  7595. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  7596. return;
  7597. }
  7598. // Normal message
  7599. clif_wis_message(dstsd->fd, sd->status.name, message, messagelen);
  7600. return;
  7601. }
  7602. /*==========================================
  7603. * /b /nb
  7604. * S 0099 <packet len>.w <text>.?B 00
  7605. *------------------------------------------*/
  7606. void clif_parse_GMmessage(int fd, struct map_session_data* sd)
  7607. {
  7608. char* msg = (char*)RFIFOP(fd,4);
  7609. unsigned int len = RFIFOW(fd,2)-4;
  7610. int lv;
  7611. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  7612. return;
  7613. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_broadcast)) )
  7614. return;
  7615. // as the length varies depending on the command used, just block unreasonably long strings
  7616. mes_len_check(msg, len, CHAT_SIZE_MAX);
  7617. intif_GMmessage(msg, len, 0);
  7618. if(log_config.gm && lv >= log_config.gm) {
  7619. char logmsg[CHAT_SIZE_MAX+4];
  7620. sprintf(logmsg, "/b %s", msg);
  7621. log_atcommand(sd, logmsg);
  7622. }
  7623. }
  7624. /*==========================================
  7625. *
  7626. *------------------------------------------*/
  7627. void clif_parse_TakeItem(int fd, struct map_session_data *sd)
  7628. {
  7629. struct flooritem_data *fitem;
  7630. int map_object_id;
  7631. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7632. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  7633. do {
  7634. if (pc_isdead(sd)) {
  7635. clif_clearunit_area(&sd->bl, 1);
  7636. break;
  7637. }
  7638. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  7639. break;
  7640. if (pc_cant_act(sd))
  7641. break;
  7642. if(sd->sc.count && (
  7643. sd->sc.data[SC_HIDING] ||
  7644. sd->sc.data[SC_CLOAKING] ||
  7645. sd->sc.data[SC_TRICKDEAD] ||
  7646. sd->sc.data[SC_BLADESTOP] ||
  7647. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM))
  7648. )
  7649. break;
  7650. if (!pc_takeitem(sd, fitem))
  7651. break;
  7652. return;
  7653. } while (0);
  7654. // Client REQUIRES a fail packet or you can no longer pick items.
  7655. clif_additem(sd,0,0,6);
  7656. }
  7657. /*==========================================
  7658. *
  7659. *------------------------------------------*/
  7660. void clif_parse_DropItem(int fd, struct map_session_data *sd)
  7661. {
  7662. int item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7663. int item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7664. do {
  7665. if (pc_isdead(sd))
  7666. break;
  7667. if (pc_cant_act(sd))
  7668. break;
  7669. if (sd->sc.count && (
  7670. sd->sc.data[SC_HIDING] ||
  7671. sd->sc.data[SC_AUTOCOUNTER] ||
  7672. sd->sc.data[SC_BLADESTOP] ||
  7673. (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOITEM)
  7674. ))
  7675. break;
  7676. if (!pc_dropitem(sd, item_index, item_amount))
  7677. break;
  7678. return;
  7679. } while (0);
  7680. //Because the client does not like being ignored.
  7681. clif_delitem(sd, item_index,0);
  7682. }
  7683. /*==========================================
  7684. *
  7685. *------------------------------------------*/
  7686. void clif_parse_UseItem(int fd, struct map_session_data *sd)
  7687. {
  7688. int n;
  7689. if (pc_isdead(sd)) {
  7690. clif_clearunit_area(&sd->bl, 1);
  7691. return;
  7692. }
  7693. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  7694. return;
  7695. //This flag enables you to use items while in an NPC. [Skotlex]
  7696. if (sd->npc_id) {
  7697. if (sd->npc_id != sd->npc_item_flag)
  7698. return;
  7699. } else
  7700. if (pc_istrading(sd))
  7701. return;
  7702. pc_delinvincibletimer(sd);
  7703. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  7704. sd->idletime = last_tick;
  7705. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7706. if(n <0 || n >= MAX_INVENTORY)
  7707. return;
  7708. if (!pc_useitem(sd,n))
  7709. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  7710. }
  7711. /*==========================================
  7712. *
  7713. *------------------------------------------*/
  7714. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  7715. {
  7716. int index;
  7717. if(pc_isdead(sd)) {
  7718. clif_clearunit_area(&sd->bl,1);
  7719. return;
  7720. }
  7721. index = RFIFOW(fd,2)-2;
  7722. if (index < 0 || index >= MAX_INVENTORY)
  7723. return; //Out of bounds check.
  7724. if(sd->npc_id) {
  7725. if (sd->npc_id != sd->npc_item_flag)
  7726. return;
  7727. } else if (sd->state.storage_flag || sd->sc.opt1)
  7728. ; //You can equip/unequip stuff while storage is open/under status changes
  7729. else if (pc_cant_act(sd))
  7730. return;
  7731. if(!sd->status.inventory[index].identify) {
  7732. clif_equipitemack(sd,index,0,0); // fail
  7733. return;
  7734. }
  7735. if(!sd->inventory_data[index])
  7736. return;
  7737. if(sd->inventory_data[index]->type == IT_PETARMOR){
  7738. pet_equipitem(sd,index);
  7739. return;
  7740. }
  7741. //Client doesn't send the position for ammo.
  7742. if(sd->inventory_data[index]->type == IT_AMMO)
  7743. pc_equipitem(sd,index,EQP_AMMO);
  7744. else
  7745. pc_equipitem(sd,index,RFIFOW(fd,4));
  7746. }
  7747. /*==========================================
  7748. *
  7749. *------------------------------------------*/
  7750. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  7751. {
  7752. int index;
  7753. if(pc_isdead(sd)) {
  7754. clif_clearunit_area(&sd->bl,1);
  7755. return;
  7756. }
  7757. if (sd->state.storage_flag)
  7758. ; //You can equip/unequip stuff while storage is open.
  7759. else if (pc_cant_act(sd))
  7760. return;
  7761. index = RFIFOW(fd,2)-2;
  7762. pc_unequipitem(sd,index,1);
  7763. }
  7764. /*==========================================
  7765. *
  7766. *------------------------------------------*/
  7767. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  7768. {
  7769. struct block_list *bl;
  7770. if(pc_isdead(sd)) {
  7771. clif_clearunit_area(&sd->bl,1);
  7772. return;
  7773. }
  7774. if (pc_cant_act(sd))
  7775. return;
  7776. bl = map_id2bl(RFIFOL(fd,2));
  7777. if (!bl) return;
  7778. switch (bl->type) {
  7779. case BL_MOB:
  7780. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7781. break;
  7782. case BL_PC:
  7783. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  7784. break;
  7785. case BL_NPC:
  7786. if( bl->m != -1 )// the user can't click floating npcs directly (hack attempt)
  7787. npc_click(sd,(TBL_NPC*)bl);
  7788. break;
  7789. }
  7790. return;
  7791. }
  7792. /*==========================================
  7793. *
  7794. *------------------------------------------*/
  7795. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  7796. {
  7797. if (sd->state.trading)
  7798. return;
  7799. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  7800. }
  7801. /// Request to buy chosen items from npc shop
  7802. /// S 00c8 <length>.w {<amount>.w <itemid>.w).4b*
  7803. /// R 00ca <result>.b
  7804. /// result = 00 -> "The deal has successfully completed."
  7805. /// result = 01 -> "You do not have enough zeny."
  7806. /// result = 02 -> "You are over your Weight Limit."
  7807. /// result = 03 -> "Out of the maximum capacity, you have too many items."
  7808. void clif_parse_NpcBuyListSend(int fd, struct map_session_data* sd)
  7809. {
  7810. int n = (RFIFOW(fd,2)-4) /4;
  7811. unsigned short* item_list = (unsigned short*)RFIFOP(fd,4);
  7812. int result;
  7813. if( sd->state.trading || !sd->npc_shopid )
  7814. result = 1;
  7815. else
  7816. result = npc_buylist(sd,n,item_list);
  7817. sd->npc_shopid = 0; //Clear shop data.
  7818. WFIFOHEAD(fd,packet_len(0xca));
  7819. WFIFOW(fd,0) = 0xca;
  7820. WFIFOB(fd,2) = result;
  7821. WFIFOSET(fd,packet_len(0xca));
  7822. }
  7823. /*==========================================
  7824. *
  7825. *------------------------------------------*/
  7826. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  7827. {
  7828. int fail=0,n;
  7829. unsigned short *item_list;
  7830. n = (RFIFOW(fd,2)-4) /4;
  7831. item_list = (unsigned short*)RFIFOP(fd,4);
  7832. if (sd->state.trading || !sd->npc_shopid)
  7833. fail = 1;
  7834. else
  7835. fail = npc_selllist(sd,n,item_list);
  7836. sd->npc_shopid = 0; //Clear shop data.
  7837. WFIFOHEAD(fd,packet_len(0xcb));
  7838. WFIFOW(fd,0)=0xcb;
  7839. WFIFOB(fd,2)=fail;
  7840. WFIFOSET(fd,packet_len(0xcb));
  7841. }
  7842. /*==========================================
  7843. * Chatroom creation request
  7844. * S 00d5 <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7845. *------------------------------------------*/
  7846. void clif_parse_CreateChatRoom(int fd, struct map_session_data* sd)
  7847. {
  7848. int len = RFIFOW(fd,2)-15;
  7849. int limit = RFIFOW(fd,4);
  7850. bool pub = (RFIFOB(fd,6) != 0);
  7851. const char* password = (char*)RFIFOP(fd,7); //not zero-terminated
  7852. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7853. char s_title[CHATROOM_TITLE_SIZE];
  7854. char s_password[CHATROOM_PASS_SIZE];
  7855. if (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)
  7856. return;
  7857. if(battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 4) {
  7858. clif_skill_fail(sd,1,0,3);
  7859. return;
  7860. }
  7861. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7862. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7863. chat_createpcchat(sd, s_title, s_password, limit, pub);
  7864. }
  7865. /*==========================================
  7866. * Chatroom join request
  7867. * S 00d9 <chat ID>.l <passwd>.8B
  7868. *------------------------------------------*/
  7869. void clif_parse_ChatAddMember(int fd, struct map_session_data* sd)
  7870. {
  7871. int chatid = RFIFOL(fd,2);
  7872. const char* password = (char*)RFIFOP(fd,6); // not zero-terminated
  7873. chat_joinchat(sd,chatid,password);
  7874. }
  7875. /*==========================================
  7876. * Chatroom properties adjustment request
  7877. * S 00de <len>.w <limit>.w <pub>.B <passwd>.8B <title>.?B
  7878. *------------------------------------------*/
  7879. void clif_parse_ChatRoomStatusChange(int fd, struct map_session_data* sd)
  7880. {
  7881. int len = RFIFOW(fd,2)-15;
  7882. int limit = RFIFOW(fd,4);
  7883. bool pub = (RFIFOB(fd,6) != 0);
  7884. const char* password = (char*)RFIFOP(fd,7); // not zero-terminated
  7885. const char* title = (char*)RFIFOP(fd,15); // not zero-terminated
  7886. char s_title[CHATROOM_TITLE_SIZE];
  7887. char s_password[CHATROOM_PASS_SIZE];
  7888. safestrncpy(s_title, title, min(len+1,CHATROOM_TITLE_SIZE));
  7889. safestrncpy(s_password, password, CHATROOM_PASS_SIZE);
  7890. chat_changechatstatus(sd, s_title, s_password, limit, pub);
  7891. }
  7892. /*==========================================
  7893. * S 00e0 ?.l <nick>.24B
  7894. *------------------------------------------*/
  7895. void clif_parse_ChangeChatOwner(int fd, struct map_session_data* sd)
  7896. {
  7897. //TODO: the first argument seems to be the destination position (always 0) [ultramage]
  7898. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  7899. }
  7900. /*==========================================
  7901. *
  7902. *------------------------------------------*/
  7903. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  7904. {
  7905. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  7906. }
  7907. /*==========================================
  7908. * Request to leave the current chatroom
  7909. * S 00e3
  7910. *------------------------------------------*/
  7911. void clif_parse_ChatLeave(int fd, struct map_session_data* sd)
  7912. {
  7913. chat_leavechat(sd,0);
  7914. }
  7915. //Handles notifying asker and rejecter of what has just ocurred.
  7916. //Type is used to determine the correct msg_txt to use:
  7917. //0:
  7918. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  7919. {
  7920. char *msg, output[256];
  7921. // Your request has been rejected by autoreject option.
  7922. msg = msg_txt(392);
  7923. clif_disp_onlyself(src, msg, strlen(msg));
  7924. //Notice that a request was rejected.
  7925. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  7926. clif_disp_onlyself(target, output, strlen(output));
  7927. }
  7928. /*==========================================
  7929. * 取引要請を相手に送る
  7930. *------------------------------------------*/
  7931. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  7932. {
  7933. struct map_session_data *t_sd;
  7934. t_sd = map_id2sd(RFIFOL(fd,2));
  7935. if(!sd->chatID && pc_cant_act(sd))
  7936. return; //You can trade while in a chatroom.
  7937. // @noask [LuzZza]
  7938. if(t_sd && t_sd->state.noask) {
  7939. clif_noask_sub(sd, t_sd, 0);
  7940. return;
  7941. }
  7942. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 1)
  7943. {
  7944. clif_skill_fail(sd,1,0,0);
  7945. return;
  7946. }
  7947. trade_traderequest(sd,t_sd);
  7948. }
  7949. /*==========================================
  7950. * 取引要請
  7951. *------------------------------------------*/
  7952. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  7953. {
  7954. trade_tradeack(sd,RFIFOB(fd,2));
  7955. }
  7956. /*==========================================
  7957. * アイテム追加
  7958. *------------------------------------------*/
  7959. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  7960. {
  7961. short index = RFIFOW(fd,2);
  7962. int amount = RFIFOL(fd,4);
  7963. if( index == 0 )
  7964. trade_tradeaddzeny(sd, amount);
  7965. else
  7966. trade_tradeadditem(sd, index, (short)amount);
  7967. }
  7968. /*==========================================
  7969. * アイテム追加完了(ok押し)
  7970. *------------------------------------------*/
  7971. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  7972. {
  7973. trade_tradeok(sd);
  7974. }
  7975. /*==========================================
  7976. * 取引キャンセル
  7977. *------------------------------------------*/
  7978. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  7979. {
  7980. trade_tradecancel(sd);
  7981. }
  7982. /*==========================================
  7983. * 取引許諾(trade押し)
  7984. *------------------------------------------*/
  7985. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  7986. {
  7987. trade_tradecommit(sd);
  7988. }
  7989. /*==========================================
  7990. *
  7991. *------------------------------------------*/
  7992. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  7993. {
  7994. pc_stop_attack(sd);
  7995. }
  7996. /*==========================================
  7997. * カートへアイテムを移す
  7998. *------------------------------------------*/
  7999. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8000. {
  8001. if (pc_istrading(sd))
  8002. return;
  8003. if (!pc_iscarton(sd))
  8004. return;
  8005. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8006. }
  8007. /*==========================================
  8008. * カートからアイテムを出す
  8009. *------------------------------------------*/
  8010. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8011. {
  8012. if (!pc_iscarton(sd))
  8013. return;
  8014. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8015. }
  8016. /*==========================================
  8017. * 付属品(鷹,ペコ,カート)をはずす
  8018. *------------------------------------------*/
  8019. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8020. {
  8021. //Can only remove Cart/Riding/Falcon.
  8022. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  8023. }
  8024. /*==========================================
  8025. * チェンジカート
  8026. *------------------------------------------*/
  8027. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8028. {
  8029. int type;
  8030. type = (int)RFIFOW(fd,2);
  8031. if( (type == 5 && sd->status.base_level > 90) ||
  8032. (type == 4 && sd->status.base_level > 80) ||
  8033. (type == 3 && sd->status.base_level > 65) ||
  8034. (type == 2 && sd->status.base_level > 40) ||
  8035. (type == 1))
  8036. pc_setcart(sd,type);
  8037. }
  8038. /*==========================================
  8039. * ステータスアップ
  8040. *------------------------------------------*/
  8041. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8042. {
  8043. pc_statusup(sd,RFIFOW(fd,2));
  8044. }
  8045. /*==========================================
  8046. * スキルレベルアップ
  8047. *------------------------------------------*/
  8048. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8049. {
  8050. pc_skillup(sd,RFIFOW(fd,2));
  8051. }
  8052. 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)
  8053. {
  8054. int lv;
  8055. if( !hd )
  8056. return;
  8057. if( skillnotok_hom(skillnum, hd) )
  8058. return;
  8059. if( hd->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8060. target_id = hd->bl.id;
  8061. if( hd->ud.skilltimer != -1 )
  8062. {
  8063. if( skillnum != SA_CASTCANCEL ) return;
  8064. }
  8065. else if( DIFF_TICK(tick, hd->ud.canact_tick) < 0 )
  8066. return;
  8067. lv = merc_hom_checkskill(hd, skillnum);
  8068. if( skilllv > lv )
  8069. skilllv = lv;
  8070. if( skilllv )
  8071. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  8072. }
  8073. static void clif_parse_UseSkillToId_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, short skillnum, short skilllv, int target_id)
  8074. {
  8075. int lv;
  8076. if( !md )
  8077. return;
  8078. if( skillnotok_mercenary(skillnum, md) )
  8079. return;
  8080. if( md->bl.id != target_id && skill_get_inf(skillnum)&INF_SELF_SKILL )
  8081. target_id = md->bl.id;
  8082. if( md->ud.skilltimer != INVALID_TIMER )
  8083. {
  8084. if( skillnum != SA_CASTCANCEL ) return;
  8085. }
  8086. else if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  8087. return;
  8088. lv = mercenary_checkskill(md, skillnum);
  8089. if( skilllv > lv )
  8090. skilllv = lv;
  8091. if( skilllv )
  8092. unit_skilluse_id(&md->bl, target_id, skillnum, skilllv);
  8093. }
  8094. static void clif_parse_UseSkillToPos_mercenary(struct mercenary_data *md, struct map_session_data *sd, unsigned int tick, short skillnum, short skilllv, short x, short y, int skillmoreinfo)
  8095. {
  8096. int lv;
  8097. if( !md )
  8098. return;
  8099. if( skillnotok_mercenary(skillnum, md) )
  8100. return;
  8101. if( md->ud.skilltimer != INVALID_TIMER )
  8102. return;
  8103. if( DIFF_TICK(tick, md->ud.canact_tick) < 0 )
  8104. {
  8105. clif_skill_fail(md->master, skillnum, 4, 0);
  8106. return;
  8107. }
  8108. if( md->sc.data[SC_BASILICA] )
  8109. return;
  8110. lv = mercenary_checkskill(md, skillnum);
  8111. if( skilllv > lv )
  8112. skilllv = lv;
  8113. if( skilllv )
  8114. unit_skilluse_pos(&md->bl, x, y, skillnum, skilllv);
  8115. }
  8116. /*==========================================
  8117. * スキル使用(ID指定)
  8118. *------------------------------------------*/
  8119. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
  8120. {
  8121. short skillnum, skilllv;
  8122. int tmp, target_id;
  8123. unsigned int tick = gettick();
  8124. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8125. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8126. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8127. if( skilllv < 1 ) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8128. tmp = skill_get_inf(skillnum);
  8129. if (tmp&INF_GROUND_SKILL || !tmp)
  8130. return; //Using a ground/passive skill on a target? WRONG.
  8131. if( skillnum >= HM_SKILLBASE && skillnum < HM_SKILLBASE + MAX_HOMUNSKILL )
  8132. {
  8133. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  8134. return;
  8135. }
  8136. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  8137. {
  8138. clif_parse_UseSkillToId_mercenary(sd->md, sd, tick, skillnum, skilllv, target_id);
  8139. return;
  8140. }
  8141. // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8142. sd->idletime = last_tick;
  8143. if( pc_cant_act(sd) )
  8144. return;
  8145. if( pc_issit(sd) )
  8146. return;
  8147. if( skillnotok(skillnum, sd) )
  8148. return;
  8149. if( sd->bl.id != target_id && !sd->state.skill_flag && tmp&INF_SELF_SKILL )
  8150. target_id = sd->bl.id; // never trust the client
  8151. if( target_id < 0 && -target_id == sd->bl.id ) // for disguises [Valaris]
  8152. target_id = sd->bl.id;
  8153. if( sd->ud.skilltimer != -1 )
  8154. {
  8155. if( skillnum != SA_CASTCANCEL )
  8156. return;
  8157. }
  8158. else if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  8159. {
  8160. clif_skill_fail(sd, skillnum, 4, 0);
  8161. return;
  8162. }
  8163. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8164. return;
  8165. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  8166. return; // On basilica only caster can use Basilica again to stop it.
  8167. if( sd->menuskill_id )
  8168. {
  8169. if( sd->menuskill_id == SA_TAMINGMONSTER )
  8170. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8171. else if( sd->menuskill_id != SA_AUTOSPELL )
  8172. return; //Can't use skills while a menu is open.
  8173. }
  8174. if( sd->skillitem == skillnum )
  8175. {
  8176. if( skilllv != sd->skillitemlv )
  8177. skilllv = sd->skillitemlv;
  8178. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8179. return;
  8180. }
  8181. sd->skillitem = sd->skillitemlv = 0;
  8182. if( skillnum == MO_EXTREMITYFIST )
  8183. {
  8184. if( (!sd->sc.data[SC_COMBO] ||
  8185. (sd->sc.data[SC_COMBO]->val1 != MO_COMBOFINISH &&
  8186. sd->sc.data[SC_COMBO]->val1 != CH_TIGERFIST &&
  8187. sd->sc.data[SC_COMBO]->val1 != CH_CHAINCRUSH))) {
  8188. if( !sd->state.skill_flag )
  8189. {
  8190. sd->state.skill_flag = 1;
  8191. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8192. return;
  8193. } else if( sd->bl.id == target_id )
  8194. {
  8195. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8196. return;
  8197. }
  8198. }
  8199. }
  8200. if( skillnum == TK_JUMPKICK )
  8201. {
  8202. if( !sd->sc.data[SC_COMBO] || sd->sc.data[SC_COMBO]->val1 != TK_JUMPKICK )
  8203. {
  8204. if( !sd->state.skill_flag )
  8205. {
  8206. sd->state.skill_flag = 1;
  8207. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8208. return;
  8209. }
  8210. else if( sd->bl.id == target_id )
  8211. {
  8212. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8213. return;
  8214. }
  8215. }
  8216. }
  8217. if( skillnum >= GD_SKILLBASE )
  8218. {
  8219. if( sd->state.gmaster_flag )
  8220. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8221. else
  8222. skilllv = 0;
  8223. }
  8224. else
  8225. {
  8226. tmp = pc_checkskill(sd, skillnum);
  8227. if( skilllv > tmp )
  8228. skilllv = tmp;
  8229. }
  8230. pc_delinvincibletimer(sd);
  8231. if( skilllv )
  8232. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8233. if( sd->state.skill_flag )
  8234. sd->state.skill_flag = 0;
  8235. }
  8236. /*==========================================
  8237. * スキル使用(場所指定)
  8238. *------------------------------------------*/
  8239. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, short skilllv, short skillnum, short x, short y, int skillmoreinfo)
  8240. {
  8241. int lv;
  8242. unsigned int tick = gettick();
  8243. if( !(skill_get_inf(skillnum)&INF_GROUND_SKILL) )
  8244. return; //Using a target skill on the ground? WRONG.
  8245. if( skillnum >= MC_SKILLBASE && skillnum < MC_SKILLBASE + MAX_MERCSKILL )
  8246. {
  8247. clif_parse_UseSkillToPos_mercenary(sd->md, sd, tick, skillnum, skilllv, x, y, skillmoreinfo);
  8248. return;
  8249. }
  8250. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8251. sd->idletime = last_tick;
  8252. if( skillnotok(skillnum, sd) )
  8253. return;
  8254. if( skillmoreinfo != -1 )
  8255. {
  8256. if( pc_issit(sd) )
  8257. {
  8258. clif_skill_fail(sd, skillnum, 0, 0);
  8259. return;
  8260. }
  8261. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  8262. safestrncpy(sd->message, (char*)RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8263. }
  8264. if( sd->ud.skilltimer != -1 )
  8265. return;
  8266. if( DIFF_TICK(tick, sd->ud.canact_tick) < 0 )
  8267. {
  8268. clif_skill_fail(sd, skillnum, 4, 0);
  8269. return;
  8270. }
  8271. if( sd->sc.option&(OPTION_WEDDING|OPTION_XMAS|OPTION_SUMMER) )
  8272. return;
  8273. if( sd->sc.data[SC_BASILICA] && (skillnum != HP_BASILICA || sd->sc.data[SC_BASILICA]->val4 != sd->bl.id) )
  8274. return; // On basilica only caster can use Basilica again to stop it.
  8275. if( sd->menuskill_id )
  8276. {
  8277. if( sd->menuskill_id == SA_TAMINGMONSTER )
  8278. sd->menuskill_id = sd->menuskill_val = 0; //Cancel pet capture.
  8279. else if( sd->menuskill_id != SA_AUTOSPELL )
  8280. return; //Can't use skills while a menu is open.
  8281. }
  8282. pc_delinvincibletimer(sd);
  8283. if( sd->skillitem == skillnum )
  8284. {
  8285. if( skilllv != sd->skillitemlv )
  8286. skilllv = sd->skillitemlv;
  8287. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8288. }
  8289. else
  8290. {
  8291. sd->skillitem = sd->skillitemlv = 0;
  8292. if( (lv = pc_checkskill(sd, skillnum)) > 0 )
  8293. {
  8294. if( skilllv > lv )
  8295. skilllv = lv;
  8296. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8297. }
  8298. }
  8299. }
  8300. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd)
  8301. {
  8302. if (pc_cant_act(sd))
  8303. return;
  8304. if (pc_issit(sd))
  8305. return;
  8306. clif_parse_UseSkillToPosSub(fd, sd,
  8307. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8308. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8309. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8310. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8311. -1 //Skill more info.
  8312. );
  8313. }
  8314. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd)
  8315. {
  8316. if (pc_cant_act(sd))
  8317. return;
  8318. if (pc_issit(sd))
  8319. return;
  8320. clif_parse_UseSkillToPosSub(fd, sd,
  8321. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8322. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8323. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8324. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8325. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8326. );
  8327. }
  8328. /*==========================================
  8329. * スキル使用(map指定)
  8330. *------------------------------------------*/
  8331. void clif_parse_UseSkillMap(int fd, struct map_session_data* sd)
  8332. {
  8333. short skill_num = RFIFOW(fd,2);
  8334. char map_name[MAP_NAME_LENGTH];
  8335. mapindex_getmapname((char*)RFIFOP(fd,4), map_name);
  8336. if(skill_num != sd->menuskill_id)
  8337. return;
  8338. if( pc_cant_act(sd) )
  8339. {
  8340. sd->menuskill_id = sd->menuskill_val = 0;
  8341. return;
  8342. }
  8343. pc_delinvincibletimer(sd);
  8344. skill_castend_map(sd,skill_num,map_name);
  8345. }
  8346. /*==========================================
  8347. * メモ要求
  8348. *------------------------------------------*/
  8349. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8350. {
  8351. if (!pc_isdead(sd))
  8352. pc_memo(sd,-1);
  8353. }
  8354. /*==========================================
  8355. * アイテム合成
  8356. *------------------------------------------*/
  8357. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8358. {
  8359. if (sd->menuskill_id != AM_PHARMACY)
  8360. return;
  8361. if (pc_istrading(sd)) {
  8362. //Make it fail to avoid shop exploits where you sell something different than you see.
  8363. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8364. sd->menuskill_val = sd->menuskill_id = 0;
  8365. return;
  8366. }
  8367. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8368. sd->menuskill_val = sd->menuskill_id = 0;
  8369. }
  8370. /*==========================================
  8371. * 武器修理
  8372. *------------------------------------------*/
  8373. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8374. {
  8375. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8376. return;
  8377. if (pc_istrading(sd)) {
  8378. //Make it fail to avoid shop exploits where you sell something different than you see.
  8379. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8380. sd->menuskill_val = sd->menuskill_id = 0;
  8381. return;
  8382. }
  8383. skill_repairweapon(sd,RFIFOW(fd,2));
  8384. sd->menuskill_val = sd->menuskill_id = 0;
  8385. }
  8386. /*==========================================
  8387. *
  8388. *------------------------------------------*/
  8389. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd)
  8390. {
  8391. int idx;
  8392. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8393. return;
  8394. if (pc_istrading(sd)) {
  8395. //Make it fail to avoid shop exploits where you sell something different than you see.
  8396. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8397. sd->menuskill_val = sd->menuskill_id = 0;
  8398. return;
  8399. }
  8400. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8401. skill_weaponrefine(sd, idx-2);
  8402. sd->menuskill_val = sd->menuskill_id = 0;
  8403. }
  8404. /*==========================================
  8405. *
  8406. *------------------------------------------*/
  8407. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8408. {
  8409. uint8 select;
  8410. select = RFIFOB(fd,6);
  8411. if((select > sd->npc_menu && select != 0xff) || !select){
  8412. ShowWarning("Hack on NPC Select Menu: %s (AID: %d)!\n",sd->status.name,sd->bl.id);
  8413. clif_GM_kick(NULL,sd);
  8414. } else {
  8415. sd->npc_menu=select;
  8416. npc_scriptcont(sd,RFIFOL(fd,2));
  8417. }
  8418. }
  8419. /*==========================================
  8420. *
  8421. *------------------------------------------*/
  8422. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8423. {
  8424. npc_scriptcont(sd,RFIFOL(fd,2));
  8425. }
  8426. /*==========================================
  8427. * Value entered into a NPC input box.
  8428. * S 0143 <npcID>.l <amount>.l
  8429. *------------------------------------------*/
  8430. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8431. {
  8432. int npcid = RFIFOL(fd,2);
  8433. int amount = (int)RFIFOL(fd,6);
  8434. sd->npc_amount = amount;
  8435. npc_scriptcont(sd, npcid);
  8436. }
  8437. /*==========================================
  8438. * Text entered into a NPC input box.
  8439. * S 01d5 <len>.w <npcID>.l <input>.?B 00
  8440. *------------------------------------------*/
  8441. void clif_parse_NpcStringInput(int fd, struct map_session_data* sd)
  8442. {
  8443. int message_len = RFIFOW(fd,2)-8;
  8444. int npcid = RFIFOL(fd,4);
  8445. const char* message = (char*)RFIFOP(fd,8);
  8446. safestrncpy(sd->npc_str, message, min(message_len,CHATBOX_SIZE));
  8447. npc_scriptcont(sd, npcid);
  8448. }
  8449. /*==========================================
  8450. *
  8451. *------------------------------------------*/
  8452. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8453. {
  8454. if (!sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8455. return;
  8456. npc_scriptcont(sd,RFIFOL(fd,2));
  8457. }
  8458. /*==========================================
  8459. * アイテム鑑定
  8460. *------------------------------------------*/
  8461. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8462. {
  8463. if (sd->menuskill_id != MC_IDENTIFY)
  8464. return;
  8465. skill_identify(sd,RFIFOW(fd,2)-2);
  8466. sd->menuskill_val = sd->menuskill_id = 0;
  8467. }
  8468. /*==========================================
  8469. * 矢作成
  8470. *------------------------------------------*/
  8471. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8472. {
  8473. if (sd->menuskill_id != AC_MAKINGARROW)
  8474. return;
  8475. if (pc_istrading(sd)) {
  8476. //Make it fail to avoid shop exploits where you sell something different than you see.
  8477. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8478. sd->menuskill_val = sd->menuskill_id = 0;
  8479. return;
  8480. }
  8481. skill_arrow_create(sd,RFIFOW(fd,2));
  8482. sd->menuskill_val = sd->menuskill_id = 0;
  8483. }
  8484. /*==========================================
  8485. * オートスペル受信
  8486. *------------------------------------------*/
  8487. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8488. {
  8489. if (sd->menuskill_id != SA_AUTOSPELL)
  8490. return;
  8491. skill_autospell(sd,RFIFOW(fd,2));
  8492. sd->menuskill_val = sd->menuskill_id = 0;
  8493. }
  8494. /*==========================================
  8495. * カード使用
  8496. *------------------------------------------*/
  8497. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8498. {
  8499. if (sd->state.trading != 0)
  8500. return;
  8501. clif_use_card(sd,RFIFOW(fd,2)-2);
  8502. }
  8503. /*==========================================
  8504. * カード挿入装備選択
  8505. *------------------------------------------*/
  8506. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8507. {
  8508. if (sd->state.trading != 0)
  8509. return;
  8510. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8511. }
  8512. /*==========================================
  8513. * 0193 キャラID名前引き
  8514. *------------------------------------------*/
  8515. void clif_parse_SolveCharName(int fd, struct map_session_data *sd)
  8516. {
  8517. int charid;
  8518. charid = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8519. map_reqnickdb(sd, charid);
  8520. }
  8521. /*==========================================
  8522. * 0197 /resetskill /resetstate
  8523. *------------------------------------------*/
  8524. void clif_parse_ResetChar(int fd, struct map_session_data *sd)
  8525. {
  8526. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8527. return;
  8528. if( pc_isGM(sd) < get_atcommand_level(atcommand_reset) )
  8529. return;
  8530. if( RFIFOW(fd,2) )
  8531. pc_resetskill(sd,1);
  8532. else
  8533. pc_resetstate(sd);
  8534. if( log_config.gm && get_atcommand_level(atcommand_reset) >= log_config.gm )
  8535. log_atcommand(sd, RFIFOW(fd,2) ? "/resetskill" : "/resetstate");
  8536. }
  8537. /*==========================================
  8538. * /lb /nlb
  8539. * S 019c <packet len>.w <text>.?B 00
  8540. *------------------------------------------*/
  8541. void clif_parse_LGMmessage(int fd, struct map_session_data* sd)
  8542. {
  8543. char* msg = (char*)RFIFOP(fd,4);
  8544. unsigned int len = RFIFOW(fd,2)-4;
  8545. int lv;
  8546. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  8547. return;
  8548. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_localbroadcast)) )
  8549. return;
  8550. // as the length varies depending on the command used, just block unreasonably long strings
  8551. mes_len_check(msg, len, CHAT_SIZE_MAX);
  8552. clif_GMmessage(&sd->bl, msg, len, 1);
  8553. if( log_config.gm && lv >= log_config.gm ) {
  8554. char logmsg[CHAT_SIZE_MAX+5];
  8555. sprintf(logmsg, "/lb %s", msg);
  8556. log_atcommand(sd, logmsg);
  8557. }
  8558. }
  8559. /*==========================================
  8560. * カプラ倉庫へ入れる
  8561. *------------------------------------------*/
  8562. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd)
  8563. {
  8564. int item_index, item_amount;
  8565. if (pc_istrading(sd))
  8566. return;
  8567. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8568. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8569. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  8570. return;
  8571. if (sd->state.storage_flag == 1)
  8572. storage_storageadd(sd, item_index, item_amount);
  8573. else
  8574. if (sd->state.storage_flag == 2)
  8575. storage_guild_storageadd(sd, item_index, item_amount);
  8576. }
  8577. /*==========================================
  8578. * カプラ倉庫から出す
  8579. *------------------------------------------*/
  8580. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd)
  8581. {
  8582. int item_index, item_amount;
  8583. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8584. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8585. if (sd->state.storage_flag == 1)
  8586. storage_storageget(sd, item_index, item_amount);
  8587. else
  8588. if(sd->state.storage_flag == 2)
  8589. storage_guild_storageget(sd, item_index, item_amount);
  8590. }
  8591. /*==========================================
  8592. * カプラ倉庫へカートから入れる
  8593. *------------------------------------------*/
  8594. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd)
  8595. {
  8596. if(sd->vender_id)
  8597. return;
  8598. if (!pc_iscarton(sd))
  8599. return;
  8600. if (sd->state.storage_flag == 1)
  8601. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8602. else
  8603. if (sd->state.storage_flag == 2)
  8604. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8605. }
  8606. /*==========================================
  8607. * カプラ倉庫から出す
  8608. *------------------------------------------*/
  8609. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd)
  8610. {
  8611. if (sd->vender_id)
  8612. return;
  8613. if (!pc_iscarton(sd))
  8614. return;
  8615. if (sd->state.storage_flag == 1)
  8616. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8617. else
  8618. if (sd->state.storage_flag == 2)
  8619. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8620. }
  8621. /*==========================================
  8622. * カプラ倉庫を閉じる
  8623. *------------------------------------------*/
  8624. void clif_parse_CloseKafra(int fd, struct map_session_data *sd)
  8625. {
  8626. if( sd->state.storage_flag == 1 )
  8627. storage_storageclose(sd);
  8628. else
  8629. if( sd->state.storage_flag == 2 )
  8630. storage_guild_storageclose(sd);
  8631. }
  8632. /*==========================================
  8633. * Kafra storage protection password system
  8634. *------------------------------------------*/
  8635. void clif_parse_StoragePassword(int fd, struct map_session_data *sd)
  8636. {
  8637. //TODO
  8638. }
  8639. /*==========================================
  8640. * Party creation request
  8641. * S 00f9 <party name>.24S
  8642. * S 01e8 <party name>.24S <item1>.B <item2>.B
  8643. *------------------------------------------*/
  8644. void clif_parse_CreateParty(int fd, struct map_session_data *sd)
  8645. {
  8646. char* name = (char*)RFIFOP(fd,2);
  8647. name[NAME_LENGTH-1] = '\0';
  8648. if( map[sd->bl.m].flag.partylock )
  8649. {// Party locked.
  8650. clif_displaymessage(fd, msg_txt(227));
  8651. return;
  8652. }
  8653. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  8654. {
  8655. clif_skill_fail(sd,1,0,4);
  8656. return;
  8657. }
  8658. party_create(sd,name,0,0);
  8659. }
  8660. void clif_parse_CreateParty2(int fd, struct map_session_data *sd)
  8661. {
  8662. char* name = (char*)RFIFOP(fd,2);
  8663. int item1 = RFIFOB(fd,26);
  8664. int item2 = RFIFOB(fd,27);
  8665. name[NAME_LENGTH-1] = '\0';
  8666. if( map[sd->bl.m].flag.partylock )
  8667. {// Party locked.
  8668. clif_displaymessage(fd, msg_txt(227));
  8669. return;
  8670. }
  8671. if( battle_config.basic_skill_check && pc_checkskill(sd,NV_BASIC) < 7 )
  8672. {
  8673. clif_skill_fail(sd,1,0,4);
  8674. return;
  8675. }
  8676. party_create(sd,name,item1,item2);
  8677. }
  8678. /*==========================================
  8679. * Party invitation request
  8680. * S 00fc <account ID>.L
  8681. * S 02c4 <char name>.24S
  8682. *------------------------------------------*/
  8683. void clif_parse_PartyInvite(int fd, struct map_session_data *sd)
  8684. {
  8685. struct map_session_data *t_sd;
  8686. if(map[sd->bl.m].flag.partylock)
  8687. {// Party locked.
  8688. clif_displaymessage(fd, msg_txt(227));
  8689. return;
  8690. }
  8691. t_sd = map_id2sd(RFIFOL(fd,2));
  8692. if(t_sd && t_sd->state.noask)
  8693. {// @noask [LuzZza]
  8694. clif_noask_sub(sd, t_sd, 1);
  8695. return;
  8696. }
  8697. party_invite(sd, t_sd);
  8698. }
  8699. void clif_parse_PartyInvite2(int fd, struct map_session_data *sd)
  8700. {
  8701. struct map_session_data *t_sd;
  8702. char *name = (char*)RFIFOP(fd,2);
  8703. name[NAME_LENGTH-1] = '\0';
  8704. if(map[sd->bl.m].flag.partylock)
  8705. {// Party locked.
  8706. clif_displaymessage(fd, msg_txt(227));
  8707. return;
  8708. }
  8709. t_sd = map_nick2sd(name);
  8710. if(t_sd && t_sd->state.noask)
  8711. {// @noask [LuzZza]
  8712. clif_noask_sub(sd, t_sd, 1);
  8713. return;
  8714. }
  8715. party_invite(sd, t_sd);
  8716. }
  8717. /*==========================================
  8718. * Party invitation reply
  8719. * S 00ff <account ID>.L <flag>.L
  8720. * S 02c7 <account ID>.L <flag>.B
  8721. * flag: 0-reject, 1-accept
  8722. *------------------------------------------*/
  8723. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd)
  8724. {
  8725. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8726. }
  8727. void clif_parse_ReplyPartyInvite2(int fd,struct map_session_data *sd)
  8728. {
  8729. party_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8730. }
  8731. /*==========================================
  8732. * パーティ脱退要求
  8733. *------------------------------------------*/
  8734. void clif_parse_LeaveParty(int fd, struct map_session_data *sd)
  8735. {
  8736. if(map[sd->bl.m].flag.partylock)
  8737. { //Guild locked.
  8738. clif_displaymessage(fd, msg_txt(227));
  8739. return;
  8740. }
  8741. party_leave(sd);
  8742. }
  8743. /*==========================================
  8744. * パーティ除名要求
  8745. *------------------------------------------*/
  8746. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd)
  8747. {
  8748. if(map[sd->bl.m].flag.partylock)
  8749. { //Guild locked.
  8750. clif_displaymessage(fd, msg_txt(227));
  8751. return;
  8752. }
  8753. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8754. }
  8755. /*==========================================
  8756. * パーティ設定変更要求
  8757. *------------------------------------------*/
  8758. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd)
  8759. {
  8760. struct party_data *p;
  8761. int i;
  8762. if( !sd->status.party_id )
  8763. return;
  8764. p = party_search(sd->status.party_id);
  8765. if( p == NULL )
  8766. return;
  8767. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  8768. if( i == MAX_PARTY )
  8769. return; //Shouldn't happen
  8770. if( !p->party.member[i].leader )
  8771. return;
  8772. //The client no longer can change the item-field, therefore it always
  8773. //comes as zero. Here, resend the item data as it is.
  8774. // party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  8775. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  8776. }
  8777. /*==========================================
  8778. * Validates and processes party messages
  8779. * S 0108 <packet len>.w <text>.?B (<name> : <message>) 00
  8780. *------------------------------------------*/
  8781. void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
  8782. {
  8783. const char* text = (char*)RFIFOP(fd,4);
  8784. int textlen = RFIFOW(fd,2) - 4;
  8785. char *name, *message;
  8786. int namelen, messagelen;
  8787. // validate packet and retrieve name and message
  8788. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  8789. return;
  8790. if( is_atcommand(fd, sd, message, 1) )
  8791. return;
  8792. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  8793. return;
  8794. if( battle_config.min_chat_delay )
  8795. { //[Skotlex]
  8796. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  8797. return;
  8798. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  8799. }
  8800. party_send_message(sd, text, textlen);
  8801. }
  8802. /*==========================================
  8803. * 露店閉鎖
  8804. *------------------------------------------*/
  8805. void clif_parse_CloseVending(int fd, struct map_session_data* sd)
  8806. {
  8807. vending_closevending(sd);
  8808. }
  8809. /*==========================================
  8810. * 露店アイテムリスト要求
  8811. *------------------------------------------*/
  8812. void clif_parse_VendingListReq(int fd, struct map_session_data* sd)
  8813. {
  8814. vending_vendinglistreq(sd,RFIFOL(fd,2));
  8815. if( sd->npc_id )
  8816. npc_event_dequeue(sd);
  8817. }
  8818. /*==========================================
  8819. * Shop item(s) purchase request
  8820. * S 0134 <len>.w <ID>.l {<amount>.w <index>.w}.4B*
  8821. *------------------------------------------*/
  8822. void clif_parse_PurchaseReq(int fd, struct map_session_data* sd)
  8823. {
  8824. int len = (int)RFIFOW(fd,2) - 8;
  8825. int id = (int)RFIFOL(fd,4);
  8826. const uint8* data = (uint8*)RFIFOP(fd,8);
  8827. vending_purchasereq(sd, id, data, len/4);
  8828. }
  8829. /*==========================================
  8830. * Confirm or cancel the shop preparation window
  8831. * S 01b2 <len>.w <message>.80B <flag>.B {<index>.w <amount>.w <value>.l}.8B*
  8832. * flag: 0=cancel, 1=confirm
  8833. *------------------------------------------*/
  8834. void clif_parse_OpenVending(int fd, struct map_session_data* sd)
  8835. {
  8836. short len = (short)RFIFOW(fd,2) - 85;
  8837. const char* message = (char*)RFIFOP(fd,4);
  8838. bool flag = (bool)RFIFOB(fd,84);
  8839. const uint8* data = (uint8*)RFIFOP(fd,85);
  8840. if( sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM )
  8841. return;
  8842. if( map[sd->bl.m].flag.novending || map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNOVENDING) ) {
  8843. clif_displaymessage (sd->fd, msg_txt(276)); // "You can't open a shop on this map"
  8844. return;
  8845. }
  8846. if( message[0] == '\0' ) // invalid input
  8847. return;
  8848. vending_openvending(sd, message, flag, data, len/8);
  8849. }
  8850. /*==========================================
  8851. * Guild creation request
  8852. * S 0165 <account id>.L <guild name>.24S
  8853. *------------------------------------------*/
  8854. void clif_parse_CreateGuild(int fd,struct map_session_data *sd)
  8855. {
  8856. char* name = (char*)RFIFOP(fd,6);
  8857. name[NAME_LENGTH-1] = '\0';
  8858. if(map[sd->bl.m].flag.guildlock)
  8859. { //Guild locked.
  8860. clif_displaymessage(fd, msg_txt(228));
  8861. return;
  8862. }
  8863. guild_create(sd, name);
  8864. }
  8865. /*==========================================
  8866. * ギルドマスターかどうか確認
  8867. *------------------------------------------*/
  8868. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd)
  8869. {
  8870. clif_guild_masterormember(sd);
  8871. }
  8872. /*==========================================
  8873. * ギルド情報要求
  8874. *------------------------------------------*/
  8875. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd)
  8876. {
  8877. if( !sd->status.guild_id && !sd->state.bg_id )
  8878. return;
  8879. switch( RFIFOL(fd,2) )
  8880. {
  8881. case 0: // ギルド基本情報、同盟敵対情報
  8882. clif_guild_basicinfo(sd);
  8883. clif_guild_allianceinfo(sd);
  8884. break;
  8885. case 1: // メンバーリスト、役職名リスト
  8886. clif_guild_positionnamelist(sd);
  8887. clif_guild_memberlist(sd);
  8888. break;
  8889. case 2: // 役職名リスト、役職情報リスト
  8890. clif_guild_positionnamelist(sd);
  8891. clif_guild_positioninfolist(sd);
  8892. break;
  8893. case 3: // スキルリスト
  8894. clif_guild_skillinfo(sd);
  8895. break;
  8896. case 4: // 追放リスト
  8897. clif_guild_expulsionlist(sd);
  8898. break;
  8899. default:
  8900. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  8901. break;
  8902. }
  8903. }
  8904. /*==========================================
  8905. * ギルド役職変更
  8906. *------------------------------------------*/
  8907. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd)
  8908. {
  8909. int i;
  8910. if(!sd->state.gmaster_flag)
  8911. return;
  8912. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  8913. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  8914. }
  8915. }
  8916. /*==========================================
  8917. * ギルドメンバ役職変更
  8918. *------------------------------------------*/
  8919. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd)
  8920. {
  8921. int i;
  8922. if(!sd->state.gmaster_flag)
  8923. return;
  8924. for(i=4;i<RFIFOW(fd,2);i+=12){
  8925. guild_change_memberposition(sd->status.guild_id,
  8926. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  8927. }
  8928. }
  8929. /*==========================================
  8930. * ギルドエンブレム要求
  8931. *------------------------------------------*/
  8932. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd)
  8933. {
  8934. struct guild* g;
  8935. int guild_id = RFIFOL(fd,2);
  8936. if( (g = guild_search(guild_id)) != NULL )
  8937. clif_guild_emblem(sd,g);
  8938. else if( guild_id == battle_config.bg_guild_id1 )
  8939. clif_bg_emblem(sd, &bg_guild[0]);
  8940. else if( guild_id == battle_config.bg_guild_id2 )
  8941. clif_bg_emblem(sd, &bg_guild[1]);
  8942. }
  8943. /*==========================================
  8944. * ギルドエンブレム変更
  8945. *------------------------------------------*/
  8946. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd)
  8947. {
  8948. if(!sd->state.gmaster_flag)
  8949. return;
  8950. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  8951. }
  8952. /*==========================================
  8953. * Guild notice update request
  8954. * S 016E <guildID>.l <msg1>.60B <msg2>.120B
  8955. *------------------------------------------*/
  8956. void clif_parse_GuildChangeNotice(int fd, struct map_session_data* sd)
  8957. {
  8958. int guild_id = RFIFOL(fd,2);
  8959. char* msg1 = (char*)RFIFOP(fd,6);
  8960. char* msg2 = (char*)RFIFOP(fd,66);
  8961. if(!sd->state.gmaster_flag)
  8962. return;
  8963. // compensate for some client defects when using multilanguage mode
  8964. if (msg1[0] == '|' && msg1[3] == '|') msg1+= 3; // skip duplicate marker
  8965. if (msg2[0] == '|' && msg2[3] == '|') msg2+= 3; // skip duplicate marker
  8966. if (msg2[0] == '|') msg2[strnlen(msg2, 120)-1] = '\0'; // delete extra space at the end of string
  8967. guild_change_notice(sd, guild_id, msg1, msg2);
  8968. }
  8969. /*==========================================
  8970. * ギルド勧誘
  8971. *------------------------------------------*/
  8972. void clif_parse_GuildInvite(int fd,struct map_session_data *sd)
  8973. {
  8974. struct map_session_data *t_sd;
  8975. if(map[sd->bl.m].flag.guildlock)
  8976. { //Guild locked.
  8977. clif_displaymessage(fd, msg_txt(228));
  8978. return;
  8979. }
  8980. t_sd = map_id2sd(RFIFOL(fd,2));
  8981. // @noask [LuzZza]
  8982. if(t_sd && t_sd->state.noask) {
  8983. clif_noask_sub(sd, t_sd, 2);
  8984. return;
  8985. }
  8986. guild_invite(sd,t_sd);
  8987. }
  8988. /*==========================================
  8989. * ギルド勧誘返信
  8990. *------------------------------------------*/
  8991. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd)
  8992. {
  8993. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8994. }
  8995. /*==========================================
  8996. * ギルド脱退
  8997. *------------------------------------------*/
  8998. void clif_parse_GuildLeave(int fd,struct map_session_data *sd)
  8999. {
  9000. if(map[sd->bl.m].flag.guildlock)
  9001. { //Guild locked.
  9002. clif_displaymessage(fd, msg_txt(228));
  9003. return;
  9004. }
  9005. if( sd->state.bg_id )
  9006. {
  9007. clif_displaymessage(fd, "You can't leave battleground guilds.");
  9008. return;
  9009. }
  9010. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9011. }
  9012. /*==========================================
  9013. * Request to expel a member of a guild
  9014. * S 015b <guild_id>.L <account_id>.L <char_id>.L <reason>.39B 00
  9015. *------------------------------------------*/
  9016. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd)
  9017. {
  9018. if( map[sd->bl.m].flag.guildlock || sd->state.bg_id )
  9019. { // Guild locked.
  9020. clif_displaymessage(fd, msg_txt(228));
  9021. return;
  9022. }
  9023. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9024. }
  9025. /*==========================================
  9026. * Validates and processes guild messages
  9027. * S 017e <packet len>.w <text>.?B (<name> : <message>) 00
  9028. *------------------------------------------*/
  9029. void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
  9030. {
  9031. const char* text = (char*)RFIFOP(fd,4);
  9032. int textlen = RFIFOW(fd,2) - 4;
  9033. char *name, *message;
  9034. int namelen, messagelen;
  9035. // validate packet and retrieve name and message
  9036. if( !clif_process_message(sd, 0, &name, &namelen, &message, &messagelen) )
  9037. return;
  9038. if( is_atcommand(fd, sd, message, 1) )
  9039. return;
  9040. if( sd->sc.data[SC_BERSERK] || (sd->sc.data[SC_NOCHAT] && sd->sc.data[SC_NOCHAT]->val1&MANNER_NOCHAT) )
  9041. return;
  9042. if( battle_config.min_chat_delay )
  9043. { //[Skotlex]
  9044. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9045. return;
  9046. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9047. }
  9048. if( sd->state.bg_id )
  9049. bg_send_message(sd, text, textlen);
  9050. else
  9051. guild_send_message(sd, text, textlen);
  9052. }
  9053. /*==========================================
  9054. * ギルド同盟要求
  9055. *------------------------------------------*/
  9056. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd)
  9057. {
  9058. struct map_session_data *t_sd;
  9059. if(!sd->state.gmaster_flag)
  9060. return;
  9061. if(map[sd->bl.m].flag.guildlock)
  9062. { //Guild locked.
  9063. clif_displaymessage(fd, msg_txt(228));
  9064. return;
  9065. }
  9066. t_sd = map_id2sd(RFIFOL(fd,2));
  9067. // @noask [LuzZza]
  9068. if(t_sd && t_sd->state.noask) {
  9069. clif_noask_sub(sd, t_sd, 3);
  9070. return;
  9071. }
  9072. guild_reqalliance(sd,t_sd);
  9073. }
  9074. /*==========================================
  9075. * ギルド同盟要求返信
  9076. *------------------------------------------*/
  9077. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd)
  9078. {
  9079. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9080. }
  9081. /*==========================================
  9082. * ギルド関係解消
  9083. *------------------------------------------*/
  9084. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd)
  9085. {
  9086. if(!sd->state.gmaster_flag)
  9087. return;
  9088. if(map[sd->bl.m].flag.guildlock)
  9089. { //Guild locked.
  9090. clif_displaymessage(fd, msg_txt(228));
  9091. return;
  9092. }
  9093. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9094. }
  9095. /*==========================================
  9096. * ギルド敵対
  9097. *------------------------------------------*/
  9098. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd)
  9099. {
  9100. struct map_session_data *t_sd;
  9101. if(!sd->state.gmaster_flag)
  9102. return;
  9103. if(map[sd->bl.m].flag.guildlock)
  9104. { //Guild locked.
  9105. clif_displaymessage(fd, msg_txt(228));
  9106. return;
  9107. }
  9108. t_sd = map_id2sd(RFIFOL(fd,2));
  9109. // @noask [LuzZza]
  9110. if(t_sd && t_sd->state.noask) {
  9111. clif_noask_sub(sd, t_sd, 4);
  9112. return;
  9113. }
  9114. guild_opposition(sd,t_sd);
  9115. }
  9116. /*==========================================
  9117. * ギルド解散
  9118. *------------------------------------------*/
  9119. void clif_parse_GuildBreak(int fd, struct map_session_data *sd)
  9120. {
  9121. if( map[sd->bl.m].flag.guildlock )
  9122. { //Guild locked.
  9123. clif_displaymessage(fd, msg_txt(228));
  9124. return;
  9125. }
  9126. guild_break(sd,(char*)RFIFOP(fd,2));
  9127. }
  9128. // pet
  9129. void clif_parse_PetMenu(int fd, struct map_session_data *sd)
  9130. {
  9131. pet_menu(sd,RFIFOB(fd,2));
  9132. }
  9133. void clif_parse_CatchPet(int fd, struct map_session_data *sd)
  9134. {
  9135. pet_catch_process2(sd,RFIFOL(fd,2));
  9136. }
  9137. void clif_parse_SelectEgg(int fd, struct map_session_data *sd)
  9138. {
  9139. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_val != -1)
  9140. {
  9141. //Forged packet, disconnect them [Kevin]
  9142. clif_authfail_fd(fd, 0);
  9143. return;
  9144. }
  9145. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9146. sd->menuskill_val = sd->menuskill_id = 0;
  9147. }
  9148. void clif_parse_SendEmotion(int fd, struct map_session_data *sd)
  9149. {
  9150. if(sd->pd)
  9151. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9152. }
  9153. void clif_parse_ChangePetName(int fd, struct map_session_data *sd)
  9154. {
  9155. pet_change_name(sd,(char*)RFIFOP(fd,2));
  9156. }
  9157. /*==========================================
  9158. * /kill <???>
  9159. * (or right click menu for GM "(name) force to quit")
  9160. * S 00cc <id>.L
  9161. *------------------------------------------*/
  9162. void clif_parse_GMKick(int fd, struct map_session_data *sd)
  9163. {
  9164. struct block_list *target;
  9165. int tid,lv;
  9166. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9167. return;
  9168. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_kick)) )
  9169. return;
  9170. tid = RFIFOL(fd,2);
  9171. target = map_id2bl(tid);
  9172. if (!target) {
  9173. clif_GM_kickack(sd, 0);
  9174. return;
  9175. }
  9176. switch (target->type) {
  9177. case BL_PC:
  9178. {
  9179. struct map_session_data *tsd = (struct map_session_data *)target;
  9180. if (pc_isGM(sd) <= pc_isGM(tsd)) {
  9181. clif_GM_kickack(sd, 0);
  9182. return;
  9183. }
  9184. clif_GM_kick(sd, tsd);
  9185. if(log_config.gm && lv >= log_config.gm) {
  9186. char message[256];
  9187. sprintf(message, "/kick %s (%d)", tsd->status.name, tsd->status.char_id);
  9188. log_atcommand(sd, message);
  9189. }
  9190. }
  9191. break;
  9192. case BL_MOB:
  9193. status_percent_damage(&sd->bl, target, 100, 0, true);
  9194. if(log_config.gm && lv >= log_config.gm) {
  9195. char message[256];
  9196. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9197. log_atcommand(sd, message);
  9198. }
  9199. break;
  9200. case BL_NPC:
  9201. {
  9202. struct npc_data* nd = (struct npc_data *)target;
  9203. lv = get_atcommand_level(atcommand_unloadnpc);
  9204. if( pc_isGM(sd) < lv )
  9205. return;
  9206. // copy-pasted from atcommand_unloadnpc
  9207. npc_unload_duplicates(nd);
  9208. npc_unload(nd);
  9209. npc_read_event_script();
  9210. if( log_config.gm && lv >= log_config.gm ) {
  9211. char message[256];
  9212. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9213. log_atcommand(sd, message);
  9214. }
  9215. }
  9216. break;
  9217. default:
  9218. clif_GM_kickack(sd, 0);
  9219. }
  9220. }
  9221. /*==========================================
  9222. * /killall
  9223. *------------------------------------------*/
  9224. void clif_parse_GMKickAll(int fd, struct map_session_data* sd)
  9225. {
  9226. is_atcommand(fd, sd, "@kickall", 1);
  9227. }
  9228. /*==========================================
  9229. * /shift <name>
  9230. *------------------------------------------*/
  9231. void clif_parse_GMShift(int fd, struct map_session_data *sd)
  9232. {
  9233. char *player_name;
  9234. int lv;
  9235. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9236. return;
  9237. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_jumpto)) )
  9238. return;
  9239. player_name = (char*)RFIFOP(fd,2);
  9240. player_name[NAME_LENGTH-1] = '\0';
  9241. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9242. if( log_config.gm && lv >= log_config.gm ) {
  9243. char message[NAME_LENGTH+7];
  9244. sprintf(message, "/shift %s", player_name);
  9245. log_atcommand(sd, message);
  9246. }
  9247. }
  9248. /*==========================================
  9249. * /recall <name>
  9250. *------------------------------------------*/
  9251. void clif_parse_GMRecall(int fd, struct map_session_data *sd)
  9252. {
  9253. char *player_name;
  9254. int lv;
  9255. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9256. return;
  9257. if( pc_isGM(sd) < (lv=get_atcommand_level(atcommand_recall)) )
  9258. return;
  9259. player_name = (char*)RFIFOP(fd,2);
  9260. player_name[NAME_LENGTH-1] = '\0';
  9261. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9262. if( log_config.gm && lv >= log_config.gm ) {
  9263. char message[NAME_LENGTH+8];
  9264. sprintf(message, "/recall %s", player_name);
  9265. log_atcommand(sd, message);
  9266. }
  9267. }
  9268. /*==========================================
  9269. * /monster /item
  9270. *------------------------------------------*/
  9271. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd)
  9272. {
  9273. char *monster_item_name;
  9274. char message[NAME_LENGTH+10]; //For logging.
  9275. int level;
  9276. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9277. return;
  9278. monster_item_name = (char*)RFIFOP(fd,2);
  9279. monster_item_name[NAME_LENGTH-1] = '\0';
  9280. if( mobdb_searchname(monster_item_name) ) {
  9281. if( pc_isGM(sd) < (level=get_atcommand_level(atcommand_monster)) )
  9282. return;
  9283. atcommand_monster(fd, sd, "@monster", monster_item_name); // as @monster
  9284. if( log_config.gm && level >= log_config.gm )
  9285. { //Log action. [Skotlex]
  9286. snprintf(message, sizeof(message)-1, "@spawn %s", monster_item_name);
  9287. log_atcommand(sd, message);
  9288. }
  9289. return;
  9290. }
  9291. if( itemdb_searchname(monster_item_name) == NULL )
  9292. return;
  9293. if( pc_isGM(sd) < (level = get_atcommand_level(atcommand_item)) )
  9294. return;
  9295. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9296. if( log_config.gm && level >= log_config.gm )
  9297. { //Log action. [Skotlex]
  9298. sprintf(message, "@item %s", monster_item_name);
  9299. log_atcommand(sd, message);
  9300. }
  9301. }
  9302. /*==========================================
  9303. * /hide
  9304. *------------------------------------------*/
  9305. void clif_parse_GMHide(int fd, struct map_session_data *sd)
  9306. {
  9307. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9308. return;
  9309. if( pc_isGM(sd) < get_atcommand_level(atcommand_hide) )
  9310. return;
  9311. if( sd->sc.option & OPTION_INVISIBLE ) {
  9312. sd->sc.option &= ~OPTION_INVISIBLE;
  9313. if (sd->disguise)
  9314. status_set_viewdata(&sd->bl, sd->disguise);
  9315. else
  9316. status_set_viewdata(&sd->bl, sd->status.class_);
  9317. clif_displaymessage(fd, "Invisible: Off.");
  9318. } else {
  9319. sd->sc.option |= OPTION_INVISIBLE;
  9320. sd->vd.class_ = INVISIBLE_CLASS;
  9321. clif_displaymessage(fd, "Invisible: On.");
  9322. if( log_config.gm && get_atcommand_level(atcommand_hide) >= log_config.gm )
  9323. log_atcommand(sd, "/hide");
  9324. }
  9325. clif_changeoption(&sd->bl);
  9326. }
  9327. /*==========================================
  9328. * GM adjustment of a player's manner value (right-click GM menu)
  9329. * S 0149 <id>.L <type>.B <value>.W
  9330. * type: 0 - positive points
  9331. * 1 - negative points
  9332. * 2 - self mute (+10 minutes)
  9333. *------------------------------------------*/
  9334. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9335. {
  9336. int id, type, value, level;
  9337. struct map_session_data *dstsd;
  9338. id = RFIFOL(fd,2);
  9339. type = RFIFOB(fd,6);
  9340. value = RFIFOW(fd,7);
  9341. if( type == 0 )
  9342. value = 0 - value;
  9343. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  9344. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  9345. if (type == 2 /* && (pc_isGM(sd) > 0 || sd->bl.id != id)*/)
  9346. return;
  9347. dstsd = map_id2sd(id);
  9348. if( dstsd == NULL )
  9349. return;
  9350. if( (level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(atcommand_mute) )
  9351. {
  9352. clif_manner_message(sd, 0);
  9353. clif_manner_message(dstsd, 5);
  9354. if( dstsd->status.manner < value ) {
  9355. dstsd->status.manner -= value;
  9356. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  9357. } else {
  9358. dstsd->status.manner = 0;
  9359. status_change_end(&dstsd->bl,SC_NOCHAT,-1);
  9360. }
  9361. if( type != 2 )
  9362. clif_GM_silence(sd, dstsd, type);
  9363. }
  9364. }
  9365. /*==========================================
  9366. * GM adjustment of a player's manner value by -60 (using name)
  9367. * /rc <name>
  9368. * S 0212 <name>.24B
  9369. *------------------------------------------*/
  9370. void clif_parse_GMRc(int fd, struct map_session_data* sd)
  9371. {
  9372. char* name = (char*)RFIFOP(fd,2);
  9373. struct map_session_data* dstsd;
  9374. name[23] = '\0';
  9375. dstsd = map_nick2sd(name);
  9376. if( dstsd == NULL )
  9377. return;
  9378. if( pc_isGM(sd) > pc_isGM(dstsd) && pc_isGM(sd) >= get_atcommand_level(atcommand_mute) )
  9379. {
  9380. clif_manner_message(sd, 0);
  9381. clif_manner_message(dstsd, 3);
  9382. dstsd->status.manner -= 60;
  9383. sc_start(&dstsd->bl,SC_NOCHAT,100,0,0);
  9384. clif_GM_silence(sd, dstsd, 1);
  9385. }
  9386. }
  9387. /*==========================================
  9388. * GM requesting account name (for right-click gm menu)
  9389. * S 01df <id>.L
  9390. * R 01e0 <id>.L <name>.24B
  9391. *------------------------------------------*/
  9392. void clif_parse_GMReqAccountName(int fd, struct map_session_data *sd)
  9393. {
  9394. int tid;
  9395. tid = RFIFOL(fd,2);
  9396. //TODO: find out if this works for any player or only for authorized GMs
  9397. WFIFOHEAD(fd,packet_len(0x1e0));
  9398. WFIFOW(fd,0) = 0x1e0;
  9399. WFIFOL(fd,2) = tid;
  9400. safestrncpy((char*)WFIFOP(fd,6), "", 24); // insert account name here >_<
  9401. WFIFOSET(fd, packet_len(0x1e0));
  9402. }
  9403. /*==========================================
  9404. * GM single cell type change request
  9405. * /changemaptype <x> <y> <type>
  9406. * S 0198 <x>.W <y>.W <gat>.W
  9407. *------------------------------------------*/
  9408. void clif_parse_GMChangeMapType(int fd, struct map_session_data *sd)
  9409. {
  9410. int x,y,type;
  9411. if( battle_config.atc_gmonly && !pc_isGM(sd) )
  9412. return;
  9413. if( pc_isGM(sd) < 99 ) //TODO: add proper check
  9414. return;
  9415. x = RFIFOW(fd,2);
  9416. y = RFIFOW(fd,4);
  9417. type = RFIFOW(fd,6);
  9418. map_setgatcell(sd->bl.m,x,y,type);
  9419. clif_changemapcell(0,sd->bl.m,x,y,type,ALL_SAMEMAP);
  9420. //FIXME: once players leave the map, the client 'forgets' this information.
  9421. }
  9422. /// S 00cf <nick>.24B <type>.B
  9423. /// type: 0 (/ex nick) deny speech from nick
  9424. /// 1 (/in nick) allow speech from nick
  9425. ///
  9426. /// R 00d1 <type>.B <result>.B
  9427. /// type: 0: deny, 1: allow
  9428. /// result: 0: success, 1: fail 2: list full
  9429. void clif_parse_PMIgnore(int fd, struct map_session_data* sd)
  9430. {
  9431. char output[512];
  9432. char* nick;
  9433. uint8 type;
  9434. int i;
  9435. nick = (char*)RFIFOP(fd,2); // speed up
  9436. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name has at most 23 characters
  9437. type = RFIFOB(fd,26);
  9438. WFIFOHEAD(fd,packet_len(0xd1));
  9439. WFIFOW(fd,0) = 0x0d1;
  9440. WFIFOB(fd,2) = type;
  9441. if( type == 0 )
  9442. { // Add name to ignore list (block)
  9443. // Bot-check...
  9444. if (strcmp(wisp_server_name, nick) == 0)
  9445. { // to find possible bot users who automaticaly ignore people
  9446. 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);
  9447. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9448. WFIFOB(fd,3) = 1; // fail
  9449. WFIFOSET(fd, packet_len(0x0d1));
  9450. return;
  9451. }
  9452. // try to find a free spot, while checking for duplicates at the same time
  9453. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  9454. if( i == MAX_IGNORE_LIST )
  9455. {// no space for new entry
  9456. WFIFOB(fd,3) = 2; // fail
  9457. WFIFOSET(fd, packet_len(0x0d1));
  9458. return;
  9459. }
  9460. if( sd->ignore[i].name[0] != '\0' )
  9461. {// name already exists
  9462. WFIFOB(fd,3) = 0; // Aegis reports success.
  9463. WFIFOSET(fd, packet_len(0x0d1));
  9464. return;
  9465. }
  9466. //Insert in position i
  9467. safestrncpy(sd->ignore[i].name, nick, NAME_LENGTH);
  9468. WFIFOB(fd,3) = 0; // success
  9469. WFIFOSET(fd, packet_len(0x0d1));
  9470. }
  9471. else
  9472. { // Remove name from ignore list (unblock)
  9473. // find entry
  9474. ARR_FIND( 0, MAX_IGNORE_LIST, i, sd->ignore[i].name[0] == '\0' || strcmp(sd->ignore[i].name, nick) == 0 );
  9475. if( i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0' )
  9476. { //Not found
  9477. WFIFOB(fd,3) = 1; // fail
  9478. WFIFOSET(fd, packet_len(0x0d1));
  9479. return;
  9480. }
  9481. // move everything one place down to overwrite removed entry
  9482. memmove(sd->ignore[i].name, sd->ignore[i+1].name, (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  9483. // wipe last entry
  9484. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  9485. WFIFOB(fd,3) = 0; // success
  9486. WFIFOSET(fd, packet_len(0x0d1));
  9487. }
  9488. return;
  9489. }
  9490. /// S 00d0 <type>.B
  9491. /// type: 0 (/exall) deny all speech
  9492. /// 1 (/inall) allow all speech
  9493. ///
  9494. /// R 00d2 <type>.B <fail>.B
  9495. /// type: 0: deny, 1: allow
  9496. /// fail: 0: success, 1: fail
  9497. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
  9498. {
  9499. WFIFOHEAD(fd,packet_len(0xd2));
  9500. WFIFOW(fd,0) = 0x0d2;
  9501. WFIFOB(fd,2) = RFIFOB(fd,2);
  9502. if( RFIFOB(fd,2) == 0 )
  9503. {// Deny all
  9504. if( sd->state.ignoreAll ) {
  9505. WFIFOB(fd,3) = 1; // fail
  9506. } else {
  9507. sd->state.ignoreAll = 1;
  9508. WFIFOB(fd,3) = 0; // success
  9509. }
  9510. }
  9511. else
  9512. {//Unblock everyone
  9513. if( sd->state.ignoreAll ) {
  9514. sd->state.ignoreAll = 0;
  9515. WFIFOB(fd,3) = 0; // success
  9516. } else {
  9517. if (sd->ignore[0].name[0] != '\0')
  9518. { //Wipe the ignore list.
  9519. memset(sd->ignore, 0, sizeof(sd->ignore));
  9520. WFIFOB(fd,3) = 0; // success
  9521. } else {
  9522. WFIFOB(fd,3) = 1; // fail
  9523. }
  9524. }
  9525. }
  9526. WFIFOSET(fd, packet_len(0x0d2));
  9527. return;
  9528. }
  9529. /*==========================================
  9530. * Wis拒否リスト
  9531. *------------------------------------------*/
  9532. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9533. {
  9534. int i;
  9535. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  9536. WFIFOW(fd,0) = 0xd4;
  9537. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9538. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  9539. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  9540. WFIFOSET(fd, WFIFOW(fd,2));
  9541. return;
  9542. }
  9543. /*==========================================
  9544. * スパノビの/doridoriによるSPR2倍
  9545. *------------------------------------------*/
  9546. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd)
  9547. {
  9548. if (sd->state.doridori) return;
  9549. switch (sd->class_&MAPID_UPPERMASK)
  9550. {
  9551. case MAPID_SOUL_LINKER:
  9552. case MAPID_STAR_GLADIATOR:
  9553. case MAPID_TAEKWON:
  9554. if (!sd->state.rest)
  9555. break;
  9556. case MAPID_SUPER_NOVICE:
  9557. sd->state.doridori=1;
  9558. break;
  9559. }
  9560. return;
  9561. }
  9562. /*==========================================
  9563. * スパノビの爆裂波動
  9564. *------------------------------------------*/
  9565. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9566. {
  9567. if(sd){
  9568. int nextbaseexp=pc_nextbaseexp(sd);
  9569. if (battle_config.etc_log){
  9570. if(nextbaseexp != 0)
  9571. 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));
  9572. else
  9573. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9574. }
  9575. 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){
  9576. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9577. sc_start(&sd->bl,status_skill2sc(MO_EXPLOSIONSPIRITS),100,
  9578. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9579. }
  9580. }
  9581. return;
  9582. }
  9583. // random notes:
  9584. // 0x214: monster/player info ?
  9585. /*==========================================
  9586. * Friends List
  9587. *------------------------------------------*/
  9588. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9589. { //Toggles a single friend online/offline [Skotlex]
  9590. int i, fd = sd->fd;
  9591. //Seek friend.
  9592. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9593. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9594. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9595. return; //Not found
  9596. WFIFOHEAD(fd,packet_len(0x206));
  9597. WFIFOW(fd, 0) = 0x206;
  9598. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  9599. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  9600. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9601. WFIFOSET(fd, packet_len(0x206));
  9602. }
  9603. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9604. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9605. {
  9606. int account_id, char_id, online;
  9607. account_id = va_arg(ap, int);
  9608. char_id = va_arg(ap, int);
  9609. online = va_arg(ap, int);
  9610. clif_friendslist_toggle(sd, account_id, char_id, online);
  9611. return 0;
  9612. }
  9613. //For sending the whole friends list.
  9614. void clif_friendslist_send(struct map_session_data *sd)
  9615. {
  9616. int i = 0, n, fd = sd->fd;
  9617. // Send friends list
  9618. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  9619. WFIFOW(fd, 0) = 0x201;
  9620. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9621. {
  9622. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9623. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9624. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9625. }
  9626. if (i) {
  9627. WFIFOW(fd,2) = 4 + 32 * i;
  9628. WFIFOSET(fd, WFIFOW(fd,2));
  9629. }
  9630. for (n = 0; n < i; n++)
  9631. { //Sending the online players
  9632. if (map_charid2sd(sd->status.friends[n].char_id))
  9633. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9634. }
  9635. }
  9636. /// Reply for add friend request: (success => type 0)
  9637. /// type=0 : MsgStringTable[821]="You have become friends with (%s)."
  9638. /// type=1 : MsgStringTable[822]="(%s) does not want to be friends with you."
  9639. /// type=2 : MsgStringTable[819]="Your Friend List is full."
  9640. /// type=3 : MsgStringTable[820]="(%s)'s Friend List is full."
  9641. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9642. {
  9643. int fd;
  9644. nullpo_retv(sd);
  9645. fd = sd->fd;
  9646. WFIFOHEAD(fd,packet_len(0x209));
  9647. WFIFOW(fd,0) = 0x209;
  9648. WFIFOW(fd,2) = type;
  9649. if (f_sd)
  9650. {
  9651. WFIFOL(fd,4) = f_sd->status.account_id;
  9652. WFIFOL(fd,8) = f_sd->status.char_id;
  9653. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9654. }
  9655. WFIFOSET(fd, packet_len(0x209));
  9656. }
  9657. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
  9658. {
  9659. struct map_session_data *f_sd;
  9660. int i, f_fd;
  9661. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9662. // Friend doesn't exist (no player with this name)
  9663. if (f_sd == NULL) {
  9664. clif_displaymessage(fd, msg_txt(3));
  9665. return;
  9666. }
  9667. // @noask [LuzZza]
  9668. if(f_sd->state.noask) {
  9669. clif_noask_sub(sd, f_sd, 5);
  9670. return;
  9671. }
  9672. // Friend already exists
  9673. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9674. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9675. clif_displaymessage(fd, "Friend already exists.");
  9676. return;
  9677. }
  9678. }
  9679. if (i == MAX_FRIENDS) {
  9680. //No space, list full.
  9681. clif_friendslist_reqack(sd, f_sd, 2);
  9682. return;
  9683. }
  9684. f_fd = f_sd->fd;
  9685. WFIFOHEAD(f_fd,packet_len(0x207));
  9686. WFIFOW(f_fd,0) = 0x207;
  9687. WFIFOL(f_fd,2) = sd->status.account_id;
  9688. WFIFOL(f_fd,6) = sd->status.char_id;
  9689. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9690. WFIFOSET(f_fd, packet_len(0x207));
  9691. return;
  9692. }
  9693. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
  9694. {
  9695. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9696. struct map_session_data *f_sd;
  9697. int char_id, account_id;
  9698. char reply;
  9699. account_id = RFIFOL(fd,2);
  9700. char_id = RFIFOL(fd,6);
  9701. reply = RFIFOB(fd,10);
  9702. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9703. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9704. if (f_sd == NULL)
  9705. return;
  9706. if (reply == 0)
  9707. clif_friendslist_reqack(f_sd, sd, 1);
  9708. else {
  9709. int i;
  9710. // Find an empty slot
  9711. for (i = 0; i < MAX_FRIENDS; i++)
  9712. if (f_sd->status.friends[i].char_id == 0)
  9713. break;
  9714. if (i == MAX_FRIENDS) {
  9715. clif_friendslist_reqack(f_sd, sd, 2);
  9716. return;
  9717. }
  9718. f_sd->status.friends[i].account_id = sd->status.account_id;
  9719. f_sd->status.friends[i].char_id = sd->status.char_id;
  9720. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9721. clif_friendslist_reqack(f_sd, sd, 0);
  9722. if (battle_config.friend_auto_add) {
  9723. // Also add f_sd to sd's friendlist.
  9724. for (i = 0; i < MAX_FRIENDS; i++) {
  9725. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  9726. return; //No need to add anything.
  9727. if (sd->status.friends[i].char_id == 0)
  9728. break;
  9729. }
  9730. if (i == MAX_FRIENDS) {
  9731. clif_friendslist_reqack(sd, f_sd, 2);
  9732. return;
  9733. }
  9734. sd->status.friends[i].account_id = f_sd->status.account_id;
  9735. sd->status.friends[i].char_id = f_sd->status.char_id;
  9736. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  9737. clif_friendslist_reqack(sd, f_sd, 0);
  9738. }
  9739. }
  9740. return;
  9741. }
  9742. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd)
  9743. {
  9744. // 0x203 </o> <ID to be removed W 4B>
  9745. int account_id, char_id;
  9746. int i, j;
  9747. account_id = RFIFOL(fd,2);
  9748. char_id = RFIFOL(fd,6);
  9749. // Search friend
  9750. for (i = 0; i < MAX_FRIENDS &&
  9751. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9752. if (i == MAX_FRIENDS) {
  9753. clif_displaymessage(fd, "Name not found in list.");
  9754. return;
  9755. }
  9756. // move all chars down
  9757. for(j = i + 1; j < MAX_FRIENDS; j++)
  9758. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9759. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9760. clif_displaymessage(fd, "Friend removed");
  9761. WFIFOHEAD(fd,packet_len(0x20a));
  9762. WFIFOW(fd,0) = 0x20a;
  9763. WFIFOL(fd,2) = account_id;
  9764. WFIFOL(fd,6) = char_id;
  9765. WFIFOSET(fd, packet_len(0x20a));
  9766. // clif_friendslist_send(sd); //This is not needed anymore.
  9767. return;
  9768. }
  9769. /*==========================================
  9770. * /pvpinfo
  9771. *------------------------------------------*/
  9772. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  9773. {
  9774. WFIFOHEAD(fd,packet_len(0x210));
  9775. WFIFOW(fd,0) = 0x210;
  9776. //WFIFOL(fd,2) = 0; // not sure what for yet
  9777. //WFIFOL(fd,6) = 0;
  9778. WFIFOL(fd,10) = sd->pvp_won; // times won
  9779. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  9780. WFIFOL(fd,18) = sd->pvp_point;
  9781. WFIFOSET(fd, packet_len(0x210));
  9782. return;
  9783. }
  9784. /*==========================================
  9785. * /blacksmith
  9786. *------------------------------------------*/
  9787. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  9788. {
  9789. int i;
  9790. const char* name;
  9791. WFIFOHEAD(fd,packet_len(0x219));
  9792. WFIFOW(fd,0) = 0x219;
  9793. //Packet size limits this list to 10 elements. [Skotlex]
  9794. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9795. if (smith_fame_list[i].id > 0) {
  9796. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  9797. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  9798. {
  9799. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  9800. } else
  9801. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  9802. } else
  9803. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  9804. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  9805. }
  9806. for(;i < 10; i++) { //In case the MAX is less than 10.
  9807. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  9808. WFIFOL(fd, 242 + i * 4) = 0;
  9809. }
  9810. WFIFOSET(fd, packet_len(0x219));
  9811. }
  9812. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  9813. {
  9814. int fd = sd->fd;
  9815. WFIFOHEAD(fd,packet_len(0x21b));
  9816. WFIFOW(fd,0) = 0x21b;
  9817. WFIFOL(fd,2) = points;
  9818. WFIFOL(fd,6) = sd->status.fame;
  9819. WFIFOSET(fd, packet_len(0x21b));
  9820. return 0;
  9821. }
  9822. /*==========================================
  9823. * /alchemist
  9824. *------------------------------------------*/
  9825. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  9826. {
  9827. int i;
  9828. const char* name;
  9829. WFIFOHEAD(fd,packet_len(0x21a));
  9830. WFIFOW(fd,0) = 0x21a;
  9831. //Packet size limits this list to 10 elements. [Skotlex]
  9832. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9833. if (chemist_fame_list[i].id > 0) {
  9834. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  9835. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  9836. {
  9837. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9838. } else
  9839. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  9840. } else
  9841. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9842. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  9843. }
  9844. for(;i < 10; i++) { //In case the MAX is less than 10.
  9845. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9846. WFIFOL(fd, 242 + i * 4) = 0;
  9847. }
  9848. WFIFOSET(fd, packet_len(0x21a));
  9849. }
  9850. int clif_fame_alchemist(struct map_session_data *sd, int points)
  9851. {
  9852. int fd = sd->fd;
  9853. WFIFOHEAD(fd,packet_len(0x21c));
  9854. WFIFOW(fd,0) = 0x21c;
  9855. WFIFOL(fd,2) = points;
  9856. WFIFOL(fd,6) = sd->status.fame;
  9857. WFIFOSET(fd, packet_len(0x21c));
  9858. return 0;
  9859. }
  9860. /*==========================================
  9861. * /taekwon
  9862. *------------------------------------------*/
  9863. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  9864. {
  9865. int i;
  9866. const char* name;
  9867. WFIFOHEAD(fd,packet_len(0x226));
  9868. WFIFOW(fd,0) = 0x226;
  9869. //Packet size limits this list to 10 elements. [Skotlex]
  9870. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9871. if (taekwon_fame_list[i].id > 0) {
  9872. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  9873. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  9874. {
  9875. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  9876. } else
  9877. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  9878. } else
  9879. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  9880. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  9881. }
  9882. for(;i < 10; i++) { //In case the MAX is less than 10.
  9883. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  9884. WFIFOL(fd, 242 + i * 4) = 0;
  9885. }
  9886. WFIFOSET(fd, packet_len(0x226));
  9887. }
  9888. int clif_fame_taekwon(struct map_session_data *sd, int points)
  9889. {
  9890. int fd = sd->fd;
  9891. WFIFOHEAD(fd,packet_len(0x224));
  9892. WFIFOW(fd,0) = 0x224;
  9893. WFIFOL(fd,2) = points;
  9894. WFIFOL(fd,6) = sd->status.fame;
  9895. WFIFOSET(fd, packet_len(0x224));
  9896. return 0;
  9897. }
  9898. /*==========================================
  9899. * PK Ranking table?
  9900. *------------------------------------------*/
  9901. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  9902. {
  9903. int i;
  9904. WFIFOHEAD(fd,packet_len(0x238));
  9905. WFIFOW(fd,0) = 0x238;
  9906. for(i=0;i<10;i++){
  9907. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  9908. WFIFOL(fd,i*4+242) = 0;
  9909. }
  9910. WFIFOSET(fd, packet_len(0x238));
  9911. return;
  9912. }
  9913. /*==========================================
  9914. * SG Feel save OK [Komurka]
  9915. *------------------------------------------*/
  9916. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  9917. {
  9918. int i;
  9919. if (sd->menuskill_id != SG_FEEL)
  9920. return;
  9921. i = sd->menuskill_val-1;
  9922. if (i<0 || i > 2) return; //Bug?
  9923. sd->feel_map[i].index = map_id2index(sd->bl.m);
  9924. sd->feel_map[i].m = sd->bl.m;
  9925. pc_setglobalreg(sd,sg_info[i].feel_var,sd->feel_map[i].index);
  9926. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  9927. // clif_misceffect2(&sd->bl, 0x1b0);
  9928. // clif_misceffect2(&sd->bl, 0x21f);
  9929. clif_feel_info(sd, i, 0);
  9930. sd->menuskill_val = sd->menuskill_id = 0;
  9931. }
  9932. /*==========================================
  9933. * Question about Star Glaldiator save map [Komurka]
  9934. *------------------------------------------*/
  9935. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv)
  9936. {
  9937. WFIFOHEAD(fd,packet_len(0x253));
  9938. WFIFOW(fd,0)=0x253;
  9939. WFIFOSET(fd, packet_len(0x253));
  9940. sd->menuskill_id = SG_FEEL;
  9941. sd->menuskill_val = skilllv;
  9942. }
  9943. /*==========================================
  9944. * Homunculus packets
  9945. *------------------------------------------*/
  9946. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd)
  9947. {
  9948. merc_hom_change_name(sd,(char*)RFIFOP(fd,2));
  9949. }
  9950. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd)
  9951. {
  9952. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  9953. struct block_list *bl = NULL;
  9954. struct unit_data *ud = NULL;
  9955. if( sd->md && sd->md->bl.id == id )
  9956. bl = &sd->md->bl;
  9957. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  9958. bl = &sd->hd->bl; // Moving Homunculus
  9959. else return;
  9960. unit_calc_pos(bl, sd->bl.x, sd->bl.y, sd->ud.dir);
  9961. ud = unit_bl2ud(bl);
  9962. unit_walktoxy(bl, ud->to_x, ud->to_y, 4);
  9963. }
  9964. void clif_parse_HomMoveTo(int fd, struct map_session_data *sd)
  9965. {
  9966. int id = RFIFOL(fd,2); // Mercenary or Homunculus
  9967. struct block_list *bl = NULL;
  9968. short x, y, cmd;
  9969. cmd = RFIFOW(fd,0);
  9970. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 + (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  9971. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) + (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  9972. if( sd->md && sd->md->bl.id == id )
  9973. bl = &sd->md->bl; // Moving Mercenary
  9974. else if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  9975. bl = &sd->hd->bl; // Moving Homunculus
  9976. else return;
  9977. unit_walktoxy(bl, x, y, 4);
  9978. }
  9979. void clif_parse_HomAttack(int fd,struct map_session_data *sd)
  9980. {
  9981. struct block_list *bl = NULL;
  9982. int id = RFIFOL(fd,2),
  9983. target_id = RFIFOL(fd,6),
  9984. action_type = RFIFOB(fd,10);
  9985. if( merc_is_hom_active(sd->hd) && sd->hd->bl.id == id )
  9986. bl = &sd->hd->bl;
  9987. else if( sd->md && sd->md->bl.id == id )
  9988. bl = &sd->md->bl;
  9989. else return;
  9990. unit_stop_walking(bl, 1);
  9991. unit_stop_attack(bl);
  9992. unit_attack(bl, target_id, action_type != 0);
  9993. }
  9994. void clif_parse_HomMenu(int fd, struct map_session_data *sd)
  9995. { //[orn]
  9996. int cmd;
  9997. cmd = RFIFOW(fd,0);
  9998. if(!merc_is_hom_active(sd->hd))
  9999. return;
  10000. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  10001. }
  10002. void clif_parse_AutoRevive(int fd, struct map_session_data *sd)
  10003. {
  10004. int item_position = pc_search_inventory(sd, 7621);
  10005. if (item_position < 0)
  10006. return;
  10007. if (!status_revive(&sd->bl, 100, 100))
  10008. return;
  10009. clif_skill_nodamage(&sd->bl,&sd->bl,ALL_RESURRECTION,4,1);
  10010. pc_delitem(sd, item_position, 1, 0);
  10011. }
  10012. /// /check <string>
  10013. /// S 0213 <string>.24B
  10014. void clif_parse_Check(int fd, struct map_session_data *sd)
  10015. {
  10016. // no info
  10017. }
  10018. #ifndef TXT_ONLY
  10019. /*==========================================
  10020. * MAIL SYSTEM
  10021. * By Zephyrus
  10022. *==========================================*/
  10023. /*------------------------------------------
  10024. * Reply to Set Attachment operation
  10025. * 0 : Successfully attached item to mail
  10026. * 1 : Fail to set the attachment
  10027. *------------------------------------------*/
  10028. static void clif_Mail_setattachment(int fd, int index, uint8 flag)
  10029. {
  10030. WFIFOHEAD(fd,packet_len(0x255));
  10031. WFIFOW(fd,0) = 0x255;
  10032. WFIFOW(fd,2) = index;
  10033. WFIFOB(fd,4) = flag;
  10034. WFIFOSET(fd,packet_len(0x255));
  10035. }
  10036. /*------------------------------------------
  10037. * Reply to Get Attachment operation
  10038. * 0 : Successfully added attachment to Inventory
  10039. * 1 : Fail to set the item to inventory
  10040. * 2 : Weight problems
  10041. *------------------------------------------*/
  10042. void clif_Mail_getattachment(int fd, uint8 flag)
  10043. {
  10044. WFIFOHEAD(fd,packet_len(0x245));
  10045. WFIFOW(fd,0) = 0x245;
  10046. WFIFOB(fd,2) = flag;
  10047. WFIFOSET(fd,packet_len(0x245));
  10048. }
  10049. /*------------------------------------------
  10050. * Send Mail ack
  10051. * 0 : Message Send Ok
  10052. * 1 : Recipient does not exist
  10053. *------------------------------------------*/
  10054. void clif_Mail_send(int fd, bool fail)
  10055. {
  10056. WFIFOHEAD(fd,packet_len(0x249));
  10057. WFIFOW(fd,0) = 0x249;
  10058. WFIFOB(fd,2) = fail;
  10059. WFIFOSET(fd,packet_len(0x249));
  10060. }
  10061. /*------------------------------------------
  10062. * Delete Mail ack
  10063. * 0 : Delete ok
  10064. * 1 : Delete failed
  10065. *------------------------------------------*/
  10066. void clif_Mail_delete(int fd, int mail_id, short fail)
  10067. {
  10068. WFIFOHEAD(fd, packet_len(0x257));
  10069. WFIFOW(fd,0) = 0x257;
  10070. WFIFOL(fd,2) = mail_id;
  10071. WFIFOW(fd,6) = fail;
  10072. WFIFOSET(fd, packet_len(0x257));
  10073. }
  10074. /*------------------------------------------
  10075. * Return Mail ack
  10076. * 0 : Mail returned to the sender
  10077. * 1 : The mail does not exist
  10078. *------------------------------------------*/
  10079. void clif_Mail_return(int fd, int mail_id, short fail)
  10080. {
  10081. WFIFOHEAD(fd,packet_len(0x274));
  10082. WFIFOW(fd,0) = 0x274;
  10083. WFIFOL(fd,2) = mail_id;
  10084. WFIFOW(fd,6) = fail;
  10085. WFIFOSET(fd,packet_len(0x274));
  10086. }
  10087. /*------------------------------------------
  10088. * You have New Mail
  10089. *------------------------------------------*/
  10090. void clif_Mail_new(int fd, int mail_id, const char *sender, const char *title)
  10091. {
  10092. WFIFOHEAD(fd,packet_len(0x24a));
  10093. WFIFOW(fd,0) = 0x24a;
  10094. WFIFOL(fd,2) = mail_id;
  10095. safestrncpy((char*)WFIFOP(fd,6), sender, NAME_LENGTH);
  10096. safestrncpy((char*)WFIFOP(fd,30), title, MAIL_TITLE_LENGTH);
  10097. WFIFOSET(fd,packet_len(0x24a));
  10098. }
  10099. /*------------------------------------------
  10100. * Handles Mail Window on Client
  10101. * flag : 0 open | 1 close
  10102. *------------------------------------------*/
  10103. void clif_Mail_window(int fd, int flag)
  10104. {
  10105. WFIFOHEAD(fd,packet_len(0x260));
  10106. WFIFOW(fd,0) = 0x260;
  10107. WFIFOL(fd,2) = flag;
  10108. WFIFOSET(fd,packet_len(0x260));
  10109. }
  10110. /*------------------------------------------
  10111. * Send Inbox Data to Client
  10112. *------------------------------------------*/
  10113. void clif_Mail_refreshinbox(struct map_session_data *sd)
  10114. {
  10115. int fd = sd->fd;
  10116. struct mail_data *md = &sd->mail.inbox;
  10117. struct mail_message *msg;
  10118. int len, i, j;
  10119. len = 8 + (73 * md->amount);
  10120. WFIFOHEAD(fd,len);
  10121. WFIFOW(fd,0) = 0x240;
  10122. WFIFOW(fd,2) = len;
  10123. WFIFOL(fd,4) = md->amount;
  10124. for( i = j = 0; i < MAIL_MAX_INBOX && j < md->amount; i++ )
  10125. {
  10126. msg = &md->msg[i];
  10127. if (msg->id < 1)
  10128. continue;
  10129. WFIFOL(fd,8+73*j) = msg->id;
  10130. memcpy(WFIFOP(fd,12+73*j), msg->title, MAIL_TITLE_LENGTH);
  10131. WFIFOB(fd,52+73*j) = (msg->status != MAIL_UNREAD); // 0: unread, 1: read
  10132. memcpy(WFIFOP(fd,53+73*j), msg->send_name, NAME_LENGTH);
  10133. WFIFOL(fd,77+73*j) = (uint32)msg->timestamp;
  10134. j++;
  10135. }
  10136. WFIFOSET(fd,len);
  10137. if( md->full )
  10138. {
  10139. char output[100];
  10140. sprintf(output, "Inbox is full (Max %d). Delete some mails.", MAIL_MAX_INBOX);
  10141. clif_disp_onlyself(sd, output, strlen(output));
  10142. }
  10143. }
  10144. /*------------------------------------------
  10145. * Client Request Inbox List
  10146. *------------------------------------------*/
  10147. void clif_parse_Mail_refreshinbox(int fd, struct map_session_data *sd)
  10148. {
  10149. struct mail_data* md = &sd->mail.inbox;
  10150. if( md->amount < MAIL_MAX_INBOX && (md->full || sd->mail.changed) )
  10151. intif_Mail_requestinbox(sd->status.char_id, 1);
  10152. else
  10153. clif_Mail_refreshinbox(sd);
  10154. mail_removeitem(sd, 0);
  10155. mail_removezeny(sd, 0);
  10156. }
  10157. /*------------------------------------------
  10158. * Read Message
  10159. *------------------------------------------*/
  10160. void clif_Mail_read(struct map_session_data *sd, int mail_id)
  10161. {
  10162. int i, fd = sd->fd;
  10163. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10164. if( i == MAIL_MAX_INBOX )
  10165. {
  10166. clif_Mail_return(sd->fd, mail_id, 1); // Mail doesn't exist
  10167. ShowWarning("clif_parse_Mail_read: char '%s' trying to read a message not the inbox.\n", sd->status.name);
  10168. return;
  10169. }
  10170. else
  10171. {
  10172. struct mail_message *msg = &sd->mail.inbox.msg[i];
  10173. struct item *item = &msg->item;
  10174. struct item_data *data;
  10175. int msg_len = strlen(msg->body), len;
  10176. if( msg_len == 0 ) {
  10177. strcpy(msg->body, "(no message)");
  10178. msg_len = strlen(msg->body);
  10179. }
  10180. len = 101 + msg_len;
  10181. WFIFOHEAD(fd,len);
  10182. WFIFOW(fd,0) = 0x242;
  10183. WFIFOW(fd,2) = len;
  10184. WFIFOL(fd,4) = msg->id;
  10185. safestrncpy((char*)WFIFOP(fd,8), msg->title, MAIL_TITLE_LENGTH + 1);
  10186. safestrncpy((char*)WFIFOP(fd,48), msg->send_name, NAME_LENGTH + 1);
  10187. WFIFOL(fd,72) = 0;
  10188. WFIFOL(fd,76) = msg->zeny;
  10189. if( item->nameid && (data = itemdb_search(item->nameid)) != NULL )
  10190. {
  10191. WFIFOL(fd,80) = item->amount;
  10192. WFIFOW(fd,84) = (data->view_id)?data->view_id:item->nameid;
  10193. WFIFOW(fd,86) = data->type;
  10194. WFIFOB(fd,88) = item->identify;
  10195. WFIFOB(fd,89) = item->attribute;
  10196. WFIFOB(fd,90) = item->refine;
  10197. WFIFOW(fd,91) = item->card[0];
  10198. WFIFOW(fd,93) = item->card[1];
  10199. WFIFOW(fd,95) = item->card[2];
  10200. WFIFOW(fd,97) = item->card[3];
  10201. }
  10202. else // no item, set all to zero
  10203. memset(WFIFOP(fd,80), 0x00, 19);
  10204. WFIFOB(fd,99) = (unsigned char)msg_len;
  10205. safestrncpy((char*)WFIFOP(fd,100), msg->body, msg_len + 1);
  10206. WFIFOSET(fd,len);
  10207. if (msg->status == MAIL_UNREAD) {
  10208. msg->status = MAIL_READ;
  10209. intif_Mail_read(mail_id);
  10210. clif_parse_Mail_refreshinbox(fd, sd);
  10211. }
  10212. }
  10213. }
  10214. void clif_parse_Mail_read(int fd, struct map_session_data *sd)
  10215. {
  10216. if( mail_invalid_operation(sd) )
  10217. return;
  10218. clif_Mail_read(sd, RFIFOL(fd,2));
  10219. }
  10220. /*------------------------------------------
  10221. * Get Attachment from Message
  10222. *------------------------------------------*/
  10223. void clif_parse_Mail_getattach(int fd, struct map_session_data *sd)
  10224. {
  10225. int i, mail_id = RFIFOL(fd,2);
  10226. bool fail = false;
  10227. if( mail_invalid_operation(sd) )
  10228. return;
  10229. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10230. if( i == MAIL_MAX_INBOX )
  10231. return;
  10232. if( sd->mail.inbox.msg[i].zeny < 1 && (sd->mail.inbox.msg[i].item.nameid < 1 || sd->mail.inbox.msg[i].item.amount < 1) )
  10233. return;
  10234. if( sd->mail.inbox.msg[i].item.nameid > 0 )
  10235. {
  10236. struct item_data *data;
  10237. unsigned int weight;
  10238. if ((data = itemdb_search(sd->mail.inbox.msg[i].item.nameid)) == NULL)
  10239. return;
  10240. switch( pc_checkadditem(sd, data->nameid, sd->mail.inbox.msg[i].item.amount) )
  10241. {
  10242. case ADDITEM_NEW:
  10243. fail = ( pc_inventoryblank(sd) == 0 );
  10244. break;
  10245. case ADDITEM_OVERAMOUNT:
  10246. fail = true;
  10247. }
  10248. if( fail )
  10249. {
  10250. clif_Mail_getattachment(fd, 1);
  10251. return;
  10252. }
  10253. weight = data->weight * sd->mail.inbox.msg[i].item.amount;
  10254. if( weight > sd->max_weight - sd->weight )
  10255. {
  10256. clif_Mail_getattachment(fd, 2);
  10257. return;
  10258. }
  10259. }
  10260. sd->mail.inbox.msg[i].zeny = 0;
  10261. memset(&sd->mail.inbox.msg[i].item, 0, sizeof(struct item));
  10262. clif_Mail_read(sd, mail_id);
  10263. intif_Mail_getattach(sd->status.char_id, mail_id);
  10264. }
  10265. /*------------------------------------------
  10266. * Delete Message
  10267. *------------------------------------------*/
  10268. void clif_parse_Mail_delete(int fd, struct map_session_data *sd)
  10269. {
  10270. int i, mail_id = RFIFOL(fd,2);
  10271. if( mail_invalid_operation(sd) )
  10272. return;
  10273. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10274. if (i < MAIL_MAX_INBOX)
  10275. {
  10276. struct mail_message *msg = &sd->mail.inbox.msg[i];
  10277. if( (msg->item.nameid > 0 && msg->item.amount > 0) || msg->zeny > 0 )
  10278. {// can't delete mail without removing attachment first
  10279. clif_Mail_delete(sd->fd, mail_id, 1);
  10280. return;
  10281. }
  10282. intif_Mail_delete(sd->status.char_id, mail_id);
  10283. }
  10284. }
  10285. /*------------------------------------------
  10286. * Return Mail Message
  10287. *------------------------------------------*/
  10288. void clif_parse_Mail_return(int fd, struct map_session_data *sd)
  10289. {
  10290. int i, mail_id = RFIFOL(fd,2);
  10291. if( mail_invalid_operation(sd) )
  10292. return;
  10293. ARR_FIND(0, MAIL_MAX_INBOX, i, sd->mail.inbox.msg[i].id == mail_id);
  10294. if( i < MAIL_MAX_INBOX && sd->mail.inbox.msg[i].send_id != 0 )
  10295. intif_Mail_return(sd->status.char_id, mail_id);
  10296. else
  10297. clif_Mail_return(sd->fd, mail_id, 1);
  10298. }
  10299. /*------------------------------------------
  10300. * Set Attachment
  10301. *------------------------------------------*/
  10302. void clif_parse_Mail_setattach(int fd, struct map_session_data *sd)
  10303. {
  10304. int idx = RFIFOW(fd,2);
  10305. int amount = RFIFOL(fd,4);
  10306. unsigned char flag;
  10307. if (idx < 0 || amount < 0)
  10308. return;
  10309. flag = mail_setitem(sd, idx, amount);
  10310. clif_Mail_setattachment(fd,idx,flag);
  10311. }
  10312. /*------------------------------------------
  10313. * Mail Window Operation
  10314. * 0 : Switch to 'new mail' window, or Close mailbox
  10315. * 1 : ???
  10316. * 2 : ???
  10317. *------------------------------------------*/
  10318. void clif_parse_Mail_winopen(int fd, struct map_session_data *sd)
  10319. {
  10320. int flag = RFIFOW(fd,2);
  10321. if (flag == 0 || flag == 1)
  10322. mail_removeitem(sd, 0);
  10323. if (flag == 0 || flag == 2)
  10324. mail_removezeny(sd, 0);
  10325. }
  10326. /*------------------------------------------
  10327. * Send Mail
  10328. * S 0248 <packet len>.w <nick>.24B <title>.40B <body len>.B <message>.?B 00
  10329. *------------------------------------------*/
  10330. void clif_parse_Mail_send(int fd, struct map_session_data *sd)
  10331. {
  10332. struct mail_message msg;
  10333. int body_len;
  10334. if( sd->state.trading )
  10335. return;
  10336. if( RFIFOW(fd,2) < 69 ) {
  10337. ShowWarning("Invalid Msg Len from account %d.\n", sd->status.account_id);
  10338. return;
  10339. }
  10340. if( DIFF_TICK(sd->cansendmail_tick, gettick()) > 0 )
  10341. {
  10342. clif_displaymessage(sd->fd,"Cannot send mails too fast!!.");
  10343. clif_Mail_send(fd, true); // fail
  10344. return;
  10345. }
  10346. body_len = RFIFOB(fd,68);
  10347. if (body_len > MAIL_BODY_LENGTH)
  10348. body_len = MAIL_BODY_LENGTH;
  10349. if( !mail_setattachment(sd, &msg) )
  10350. { // Invalid Append condition
  10351. clif_Mail_send(sd->fd, true); // fail
  10352. mail_removeitem(sd,0);
  10353. mail_removezeny(sd,0);
  10354. return;
  10355. }
  10356. msg.id = 0; // id will be assigned by charserver
  10357. msg.send_id = sd->status.char_id;
  10358. msg.dest_id = 0; // will attempt to resolve name
  10359. safestrncpy(msg.send_name, sd->status.name, NAME_LENGTH);
  10360. safestrncpy(msg.dest_name, (char*)RFIFOP(fd,4), NAME_LENGTH);
  10361. safestrncpy(msg.title, (char*)RFIFOP(fd,28), MAIL_TITLE_LENGTH);
  10362. if (body_len)
  10363. safestrncpy(msg.body, (char*)RFIFOP(fd,69), body_len + 1);
  10364. else
  10365. memset(msg.body, 0x00, MAIL_BODY_LENGTH);
  10366. msg.timestamp = time(NULL);
  10367. if( !intif_Mail_send(sd->status.account_id, &msg) )
  10368. mail_deliveryfail(sd, &msg);
  10369. sd->cansendmail_tick = gettick() + 1000; // 1 Second flood Protection
  10370. }
  10371. /*==========================================
  10372. * AUCTION SYSTEM
  10373. * By Zephyrus
  10374. *==========================================*/
  10375. void clif_Auction_openwindow(struct map_session_data *sd)
  10376. {
  10377. int fd = sd->fd;
  10378. if( sd->state.storage_flag || sd->vender_id || sd->state.trading )
  10379. return;
  10380. WFIFOHEAD(fd,12);
  10381. WFIFOW(fd,0) = 0x25f;
  10382. WFIFOL(fd,2) = 0;
  10383. WFIFOB(fd,6) = 0xb6;
  10384. WFIFOB(fd,7) = 0x00;
  10385. WFIFOB(fd,8) = 0xa6;
  10386. WFIFOB(fd,9) = 0xde;
  10387. WFIFOW(fd,10) = 0;
  10388. WFIFOSET(fd,12);
  10389. }
  10390. void clif_Auction_results(struct map_session_data *sd, short count, short pages, uint8 *buf)
  10391. {
  10392. int i, fd = sd->fd, len = sizeof(struct auction_data);
  10393. struct auction_data auction;
  10394. struct item_data *item;
  10395. int k;
  10396. WFIFOHEAD(fd,20);
  10397. WFIFOW(fd,0) = 0x252;
  10398. WFIFOW(fd,2) = 12 + (count * 83);
  10399. WFIFOL(fd,4) = pages;
  10400. WFIFOL(fd,8) = count;
  10401. for( i = 0; i < count; i++ )
  10402. {
  10403. memcpy(&auction, RBUFP(buf,i * len), len);
  10404. k = 12 + (i * 83);
  10405. WFIFOL(fd,k) = auction.auction_id;
  10406. safestrncpy((char*)WFIFOP(fd,4+k), auction.seller_name, NAME_LENGTH);
  10407. if( (item = itemdb_search(auction.item.nameid)) != NULL && item->view_id > 0 )
  10408. WFIFOW(fd,28+k) = item->view_id;
  10409. else
  10410. WFIFOW(fd,28+k) = auction.item.nameid;
  10411. WFIFOW(fd,30+k) = auction.type;
  10412. WFIFOW(fd,32+k) = 0; // ??
  10413. WFIFOW(fd,34+k) = auction.item.amount; // Allways 1
  10414. WFIFOB(fd,36+k) = auction.item.identify;
  10415. WFIFOB(fd,37+k) = auction.item.attribute;
  10416. WFIFOB(fd,38+k) = auction.item.refine;
  10417. WFIFOW(fd,39+k) = auction.item.card[0];
  10418. WFIFOW(fd,41+k) = auction.item.card[1];
  10419. WFIFOW(fd,43+k) = auction.item.card[2];
  10420. WFIFOW(fd,45+k) = auction.item.card[3];
  10421. WFIFOL(fd,47+k) = auction.price;
  10422. WFIFOL(fd,51+k) = auction.buynow;
  10423. safestrncpy((char*)WFIFOP(fd,55+k), auction.buyer_name, NAME_LENGTH);
  10424. WFIFOL(fd,79+k) = (uint32)auction.timestamp;
  10425. }
  10426. WFIFOSET(fd, 12 + (count * 83));
  10427. }
  10428. static void clif_Auction_setitem(int fd, int index, bool fail)
  10429. {
  10430. WFIFOHEAD(fd,packet_len(0x256));
  10431. WFIFOW(fd,0) = 0x256;
  10432. WFIFOW(fd,2) = index;
  10433. WFIFOB(fd,4) = fail;
  10434. WFIFOSET(fd,packet_len(0x256));
  10435. }
  10436. void clif_parse_Auction_cancelreg(int fd, struct map_session_data *sd)
  10437. {
  10438. if( sd->auction.amount > 0 )
  10439. clif_additem(sd, sd->auction.index, sd->auction.amount, 0);
  10440. sd->auction.amount = 0;
  10441. }
  10442. void clif_parse_Auction_setitem(int fd, struct map_session_data *sd)
  10443. {
  10444. int idx = RFIFOW(fd,2) - 2;
  10445. int amount = RFIFOL(fd,4); // Allways 1
  10446. struct item_data *item;
  10447. if( sd->auction.amount > 0 )
  10448. sd->auction.amount = 0;
  10449. if( idx < 0 || idx >= MAX_INVENTORY )
  10450. {
  10451. ShowWarning("Character %s trying to set invalid item index in auctions.\n", sd->status.name);
  10452. return;
  10453. }
  10454. if( amount != 1 || amount < 0 || amount > sd->status.inventory[idx].amount )
  10455. { // By client, amount is allways set to 1. Maybe this is a future implementation.
  10456. ShowWarning("Character %s trying to set invalid amount in auctions.\n", sd->status.name);
  10457. return;
  10458. }
  10459. if( (item = itemdb_search(sd->status.inventory[idx].nameid)) != NULL && !(item->type == IT_ARMOR || item->type == IT_PETARMOR || item->type == IT_WEAPON || item->type == IT_CARD || item->type == IT_ETC) )
  10460. { // Consumible or pets are not allowed
  10461. clif_Auction_setitem(sd->fd, idx, true);
  10462. return;
  10463. }
  10464. if( !pc_candrop(sd, &sd->status.inventory[idx]) || !sd->status.inventory[idx].identify || sd->status.inventory[idx].expire_time )
  10465. { // Quest Item or something else
  10466. clif_Auction_setitem(sd->fd, idx, true);
  10467. return;
  10468. }
  10469. sd->auction.index = idx;
  10470. sd->auction.amount = amount;
  10471. clif_Auction_setitem(fd, idx + 2, false);
  10472. }
  10473. // 0 = You have failed to bid into the auction
  10474. // 1 = You have successfully bid in the auction
  10475. // 2 = The auction has been canceled
  10476. // 3 = An auction with at least one bidder cannot be canceled
  10477. // 4 = You cannot register more than 5 items in an auction at a time
  10478. // 5 = You do not have enough Zeny to pay the Auction Fee
  10479. // 6 = You have won the auction
  10480. // 7 = You have failed to win the auction
  10481. // 8 = You do not have enough Zeny
  10482. // 9 = You cannot place more than 5 bids at a time
  10483. void clif_Auction_message(int fd, unsigned char flag)
  10484. {
  10485. WFIFOHEAD(fd,3);
  10486. WFIFOW(fd,0) = 0x250;
  10487. WFIFOB(fd,2) = flag;
  10488. WFIFOSET(fd,3);
  10489. }
  10490. // 0 = You have ended the auction
  10491. // 1 = You cannot end the auction
  10492. // 2 = Bid number is incorrect
  10493. void clif_Auction_close(int fd, unsigned char flag)
  10494. {
  10495. WFIFOHEAD(fd,6);
  10496. WFIFOW(fd,0) = 0x25d;
  10497. WFIFOL(fd,2) = flag;
  10498. WFIFOSET(fd,6);
  10499. }
  10500. void clif_parse_Auction_register(int fd, struct map_session_data *sd)
  10501. {
  10502. struct auction_data auction;
  10503. struct item_data *item;
  10504. auction.price = RFIFOL(fd,2);
  10505. auction.buynow = RFIFOL(fd,6);
  10506. auction.hours = RFIFOW(fd,10);
  10507. // Invalid Situations...
  10508. if( sd->auction.amount < 1 )
  10509. {
  10510. ShowWarning("Character %s trying to register auction without item.\n", sd->status.name);
  10511. return;
  10512. }
  10513. if( auction.price >= auction.buynow )
  10514. {
  10515. ShowWarning("Character %s trying to alter auction prices.\n", sd->status.name);
  10516. return;
  10517. }
  10518. if( auction.hours < 1 || auction.hours > 48 )
  10519. {
  10520. ShowWarning("Character %s trying to enter an invalid time for auction.\n", sd->status.name);
  10521. return;
  10522. }
  10523. // Auction checks...
  10524. if( sd->status.zeny < (auction.hours * battle_config.auction_feeperhour) )
  10525. {
  10526. clif_Auction_message(fd, 5); // You do not have enough zeny to pay the Auction Fee.
  10527. return;
  10528. }
  10529. if( auction.buynow > battle_config.auction_maximumprice )
  10530. { // Zeny Limits
  10531. auction.buynow = battle_config.auction_maximumprice;
  10532. if( auction.price >= auction.buynow )
  10533. auction.price = auction.buynow - 1;
  10534. }
  10535. auction.auction_id = 0;
  10536. auction.seller_id = sd->status.char_id;
  10537. safestrncpy(auction.seller_name, sd->status.name, NAME_LENGTH);
  10538. auction.buyer_id = 0;
  10539. memset(&auction.buyer_name, '\0', NAME_LENGTH);
  10540. if( sd->status.inventory[sd->auction.index].nameid == 0 || sd->status.inventory[sd->auction.index].amount < sd->auction.amount )
  10541. {
  10542. clif_Auction_message(fd, 2); // The auction has been canceled
  10543. return;
  10544. }
  10545. if( (item = itemdb_search(sd->status.inventory[sd->auction.index].nameid)) == NULL )
  10546. { // Just in case
  10547. clif_Auction_message(fd, 2); // The auction has been canceled
  10548. return;
  10549. }
  10550. safestrncpy(auction.item_name, item->jname, ITEM_NAME_LENGTH);
  10551. auction.type = item->type;
  10552. memcpy(&auction.item, &sd->status.inventory[sd->auction.index], sizeof(struct item));
  10553. auction.item.amount = 1;
  10554. auction.timestamp = 0;
  10555. if( !intif_Auction_register(&auction) )
  10556. clif_Auction_message(fd, 4); // No Char Server? lets say something to the client
  10557. else
  10558. {
  10559. pc_delitem(sd, sd->auction.index, sd->auction.amount, 1);
  10560. sd->auction.amount = 0;
  10561. pc_payzeny(sd, auction.hours * battle_config.auction_feeperhour);
  10562. }
  10563. }
  10564. void clif_parse_Auction_cancel(int fd, struct map_session_data *sd)
  10565. {
  10566. unsigned int auction_id = RFIFOL(fd,2);
  10567. intif_Auction_cancel(sd->status.char_id, auction_id);
  10568. }
  10569. void clif_parse_Auction_close(int fd, struct map_session_data *sd)
  10570. {
  10571. unsigned int auction_id = RFIFOL(fd,2);
  10572. intif_Auction_close(sd->status.char_id, auction_id);
  10573. }
  10574. void clif_parse_Auction_bid(int fd, struct map_session_data *sd)
  10575. {
  10576. unsigned int auction_id = RFIFOL(fd,2);
  10577. int bid = RFIFOL(fd,6);
  10578. if( bid <= 0 )
  10579. clif_Auction_message(fd, 0); // You have failed to bid into the auction
  10580. else if( bid > sd->status.zeny )
  10581. clif_Auction_message(fd, 8); // You do not have enough zeny
  10582. else
  10583. {
  10584. pc_payzeny(sd, bid);
  10585. intif_Auction_bid(sd->status.char_id, sd->status.name, auction_id, bid);
  10586. }
  10587. }
  10588. /*------------------------------------------
  10589. * Auction Search
  10590. * S 0251 <search type>.w <search price>.l <search text>.24B <page number>.w
  10591. * Search Type: 0 Armor 1 Weapon 2 Card 3 Misc 4 By Text 5 By Price 6 Sell 7 Buy
  10592. *------------------------------------------*/
  10593. void clif_parse_Auction_search(int fd, struct map_session_data* sd)
  10594. {
  10595. char search_text[NAME_LENGTH];
  10596. short type = RFIFOW(fd,2), page = RFIFOW(fd,32);
  10597. int price = RFIFOL(fd,4);
  10598. clif_parse_Auction_cancelreg(fd, sd);
  10599. safestrncpy(search_text, (char*)RFIFOP(fd,8), NAME_LENGTH);
  10600. intif_Auction_requestlist(sd->status.char_id, type, price, search_text, page);
  10601. }
  10602. void clif_parse_Auction_buysell(int fd, struct map_session_data* sd)
  10603. {
  10604. short type = RFIFOW(fd,2) + 6;
  10605. clif_parse_Auction_cancelreg(fd, sd);
  10606. intif_Auction_requestlist(sd->status.char_id, type, 0, "", 1);
  10607. }
  10608. #endif
  10609. /*==========================================
  10610. * CASH/POINT SHOP
  10611. *==========================================*/
  10612. void clif_cashshop_show(struct map_session_data *sd, struct npc_data *nd)
  10613. {
  10614. int fd,i;
  10615. nullpo_retv(sd);
  10616. nullpo_retv(nd);
  10617. fd = sd->fd;
  10618. sd->npc_shopid = nd->bl.id;
  10619. WFIFOHEAD(fd, 200 * 11 + 12);
  10620. WFIFOW(fd,0) = 0x287;
  10621. WFIFOW(fd,2) = 12 + nd->u.shop.count*11;
  10622. WFIFOL(fd,4) = sd->cashPoints; // Cash Points
  10623. WFIFOL(fd,8) = sd->kafraPoints; // Kafra Points
  10624. for( i = 0; i < nd->u.shop.count; i++ )
  10625. {
  10626. struct item_data* id = itemdb_search(nd->u.shop.shop_item[i].nameid);
  10627. WFIFOL(fd,12+i*11) = nd->u.shop.shop_item[i].value;
  10628. WFIFOL(fd,16+i*11) = nd->u.shop.shop_item[i].value; // Discount Price? Maybe a Discount item
  10629. WFIFOB(fd,20+i*11) = itemtype(id->type);
  10630. WFIFOW(fd,21+i*11) = ( id->view_id > 0 ) ? id->view_id : id->nameid;
  10631. }
  10632. WFIFOSET(fd,WFIFOW(fd,2));
  10633. }
  10634. void clif_parse_cashshop_buy(int fd, struct map_session_data *sd)
  10635. {
  10636. int fail = 0, amount, points;
  10637. short nameid;
  10638. struct npc_data *nd;
  10639. nullpo_retv(sd);
  10640. nd = (struct npc_data *)map_id2bl(sd->npc_shopid);
  10641. nameid = RFIFOW(fd,2);
  10642. amount = RFIFOW(fd,4);
  10643. points = RFIFOL(fd,6); // Not Implemented. Should be 0
  10644. if( sd->state.trading || !sd->npc_shopid )
  10645. fail = 1;
  10646. else
  10647. fail = npc_cashshop_buy(sd, nameid, amount, points);
  10648. WFIFOHEAD(fd,12);
  10649. WFIFOW(fd,0) = 0x289;
  10650. WFIFOL(fd,2) = sd->cashPoints;
  10651. WFIFOL(fd,6) = sd->kafraPoints;
  10652. WFIFOW(fd,10) = fail;
  10653. WFIFOSET(fd,12);
  10654. }
  10655. /*==========================================
  10656. * Adoption System
  10657. *==========================================*/
  10658. // 0 : "You cannot adopt more than 1 child."
  10659. // 1 : "You must be at least character level 70 in order to adopt someone."
  10660. // 2 : "You cannot adopt a married person."
  10661. void clif_Adopt_reply(struct map_session_data *sd, int type)
  10662. {
  10663. int fd = sd->fd;
  10664. WFIFOHEAD(fd,6);
  10665. WFIFOW(fd,0) = 0x0216;
  10666. WFIFOL(fd,2) = type;
  10667. WFIFOSET(fd,6);
  10668. }
  10669. void clif_Adopt_request(struct map_session_data *sd, struct map_session_data *src, int p_id)
  10670. {
  10671. int fd = sd->fd;
  10672. WFIFOHEAD(fd,34);
  10673. WFIFOW(fd,0) = 0x01f6;
  10674. WFIFOL(fd,2) = src->status.account_id;
  10675. WFIFOL(fd,6) = p_id;
  10676. memcpy(WFIFOP(fd,10), src->status.name, NAME_LENGTH);
  10677. WFIFOSET(fd,34);
  10678. }
  10679. void clif_parse_Adopt_request(int fd, struct map_session_data *sd)
  10680. {
  10681. struct map_session_data *tsd = map_id2sd(RFIFOL(fd,2)), *p_sd = map_charid2sd(sd->status.partner_id);
  10682. if( pc_can_Adopt(sd, p_sd, tsd) )
  10683. {
  10684. tsd->adopt_invite = sd->status.account_id;
  10685. clif_Adopt_request(tsd, sd, p_sd->status.account_id);
  10686. }
  10687. }
  10688. void clif_parse_Adopt_reply(int fd, struct map_session_data *sd)
  10689. {
  10690. int p1_id = RFIFOL(fd,2);
  10691. int p2_id = RFIFOL(fd,6);
  10692. int result = RFIFOL(fd,10);
  10693. struct map_session_data* p1_sd = map_id2sd(p1_id);
  10694. struct map_session_data* p2_sd = map_id2sd(p2_id);
  10695. int pid = sd->adopt_invite;
  10696. sd->adopt_invite = 0;
  10697. if( p1_sd == NULL || p2_sd == NULL )
  10698. return; // Both players need to be online
  10699. if( pid != p1_sd->status.account_id )
  10700. return; // Incorrect values
  10701. if( result == 0 )
  10702. return; // Rejected
  10703. pc_adoption(p1_sd, p2_sd, sd);
  10704. }
  10705. /*==========================================
  10706. * Convex Mirror
  10707. * S 0293 <flag>.b <x>.l <y>.l <Hours>.w <Minutes>.w <unknown>.l <monster name>.40B <unknown>.11B
  10708. *==========================================*/
  10709. void clif_bossmapinfo(int fd, struct mob_data *md, short flag)
  10710. {
  10711. WFIFOHEAD(fd,70);
  10712. memset(WFIFOP(fd,0),0,70);
  10713. WFIFOW(fd,0) = 0x0293;
  10714. if( md != NULL )
  10715. {
  10716. if( md->bl.prev != NULL )
  10717. { // Boss on This Map
  10718. if( flag )
  10719. {
  10720. WFIFOB(fd,2) = 1;
  10721. WFIFOL(fd,3) = md->bl.x;
  10722. WFIFOL(fd,7) = md->bl.y;
  10723. }
  10724. else
  10725. WFIFOB(fd,2) = 2; // First Time
  10726. }
  10727. else
  10728. { // Boss is Dead
  10729. const struct TimerData * timer_data = get_timer(md->spawn_timer);
  10730. unsigned int seconds;
  10731. int hours, minutes;
  10732. seconds = DIFF_TICK(timer_data->tick, gettick()) / 1000;
  10733. hours = seconds / (60 * 60);
  10734. seconds = seconds - (60 * 60 * hours);
  10735. minutes = seconds / 60;
  10736. WFIFOB(fd,2) = 3;
  10737. WFIFOW(fd,11) = hours; // Hours
  10738. WFIFOW(fd,13) = minutes; // Minutes
  10739. }
  10740. safestrncpy((char*)WFIFOP(fd,19), md->db->jname, NAME_LENGTH);
  10741. }
  10742. WFIFOSET(fd,70);
  10743. }
  10744. /*==========================================
  10745. * Requesting equip of a player
  10746. *------------------------------------------*/
  10747. void clif_parse_ViewPlayerEquip(int fd, struct map_session_data* sd)
  10748. {
  10749. int charid = RFIFOL(fd, 2);
  10750. struct map_session_data* tsd = map_id2sd(charid);
  10751. if (!tsd)
  10752. return;
  10753. if( tsd->status.show_equip || (battle_config.gm_viewequip_min_lv && pc_isGM(sd) >= battle_config.gm_viewequip_min_lv) )
  10754. clif_viewequip_ack(sd, tsd);
  10755. else
  10756. clif_viewequip_fail(sd);
  10757. }
  10758. /*==========================================
  10759. * Equip window (un)tick
  10760. * S 02d8 <zero?>.L <flag>.L
  10761. *------------------------------------------*/
  10762. void clif_parse_EquipTick(int fd, struct map_session_data* sd)
  10763. {
  10764. bool flag = (bool)RFIFOL(fd,6); // 0=off, 1=on
  10765. sd->status.show_equip = flag;
  10766. clif_equiptickack(sd, flag);
  10767. }
  10768. /*==========================================
  10769. * Questlog System [Kevin]
  10770. * 02B5 <packet_len>.W <ignored>.L { }.10B* <-- UNKOWN PACKET
  10771. * 02B6 <quest_id>.L <state>.B
  10772. *------------------------------------------*/
  10773. void clif_parse_questStateAck(int fd, struct map_session_data * sd)
  10774. {
  10775. }
  10776. //Send simple list of quests upon login
  10777. //* 02B1 <packet_len>.W <ignored>.L { <quest_id>.L <state>.B }.5B*
  10778. void clif_send_questlog(struct map_session_data * sd)
  10779. {
  10780. int fd = sd->fd;
  10781. int i;
  10782. WFIFOHEAD(fd,sd->num_quests*5+8);
  10783. WFIFOW(fd, 0) = 0x02B1;
  10784. WFIFOW(fd, 2) = sd->num_quests*5+8;
  10785. for(i=0; i<MAX_QUEST; i++)
  10786. {
  10787. if(!sd->quest_log[i].quest_id)
  10788. continue;
  10789. WFIFOL(fd, i*5+8) = sd->quest_log[i].quest_id;
  10790. WFIFOB(fd, i*5+12) = sd->quest_log[i].state;
  10791. }
  10792. WFIFOSET(fd, WFIFOW(fd, 2));
  10793. }
  10794. //Send objective info on login
  10795. //* 02B2 <packet_len>.W <ignored>.L { <quest_id>.L <ignored>.L <time>.L <num mobs>.W {<ignored>.L <mob count>.W <Mob Name>.24B}.30B[3] }.104B*
  10796. void clif_send_questlog_info(struct map_session_data * sd)
  10797. {
  10798. int fd = sd->fd;
  10799. int i, j;
  10800. WFIFOHEAD(fd,sd->num_quests*104+8);
  10801. WFIFOW(fd, 0) = 0x02B2;
  10802. WFIFOW(fd, 2) = sd->num_quests*104+8;
  10803. for(i=0; i<MAX_QUEST; i++)
  10804. {
  10805. if(!sd->quest_log[i].quest_id)
  10806. continue;
  10807. WFIFOL(fd, i*104+8) = sd->quest_log[i].quest_id;
  10808. // I have no idea what the time field does [Kevin]
  10809. WFIFOL(fd, i*104+16) = 0;
  10810. WFIFOW(fd, i*104+20) = sd->quest_log[i].num_objectives;
  10811. for(j=0; j<sd->quest_log[i].num_objectives; j++)
  10812. {
  10813. WFIFOW(fd, i*104+26+j*30) = sd->quest_log[i].objectives[j].count;
  10814. memcpy(WFIFOP(fd, i*104+28+j*30), sd->quest_log[i].objectives[j].name, NAME_LENGTH);
  10815. }
  10816. }
  10817. WFIFOSET(fd, WFIFOW(fd, 2));
  10818. }
  10819. //Send info when objective info needs an update
  10820. //* 02B3 <quest_id>.L <state>.B <ignored>.L <time>.L <num mobs>.W {<ignored>.L <mob count>.W <Mob Name>.24B}.30B[3]
  10821. void clif_send_quest_info(struct map_session_data * sd, struct quest * qd)
  10822. {
  10823. int fd = sd->fd;
  10824. int i;
  10825. WFIFOHEAD(fd,qd->num_objectives*30+17);
  10826. WFIFOW(fd, 0) = 0x02B3;
  10827. WFIFOL(fd, 2) = qd->quest_id;
  10828. WFIFOB(fd, 6) = qd->state;
  10829. //Same time value thing
  10830. WFIFOW(fd, 11) = 0;
  10831. WFIFOW(fd, 15) = qd->num_objectives;
  10832. for(i=0; i<qd->num_objectives; i++)
  10833. {
  10834. WFIFOW(fd, i*30+21) = qd->objectives[i].count;
  10835. memcpy(WFIFOP(fd, i*30+23), qd->objectives[i].name, NAME_LENGTH);
  10836. }
  10837. WFIFOSET(fd, qd->num_objectives*30+17);
  10838. }
  10839. //Send delete msg
  10840. //* 02B4 <quest_id>.L
  10841. void clif_send_quest_delete(struct map_session_data * sd, int quest_id)
  10842. {
  10843. int fd = sd->fd;
  10844. WFIFOHEAD(fd, 6);
  10845. WFIFOW(fd, 0) = 0x02B4;
  10846. WFIFOL(fd, 2) = quest_id;
  10847. WFIFOSET(fd, 6);
  10848. }
  10849. //Change active state of the quest
  10850. //* 02B7 <quest_id>.L <state_to>.B
  10851. void clif_send_quest_status(struct map_session_data * sd, int quest_id, bool active)
  10852. {
  10853. int fd = sd->fd;
  10854. WFIFOHEAD(fd, 7);
  10855. WFIFOW(fd, 0) = 0x02B7;
  10856. WFIFOL(fd, 2) = quest_id;
  10857. WFIFOB(fd, 6) = active?1:0;
  10858. WFIFOSET(fd, 7);
  10859. }
  10860. /*==========================================
  10861. * Mercenary System
  10862. *==========================================*/
  10863. void clif_mercenary_updatestatus(struct map_session_data *sd, int type)
  10864. {
  10865. struct mercenary_data *md;
  10866. struct status_data *status;
  10867. int fd;
  10868. if( sd == NULL || (md = sd->md) == NULL )
  10869. return;
  10870. fd = sd->fd;
  10871. status = &md->battle_status;
  10872. WFIFOHEAD(fd,8);
  10873. WFIFOW(fd,0) = 0x02a2;
  10874. WFIFOW(fd,2) = type;
  10875. switch( type )
  10876. {
  10877. case SP_ATK1:
  10878. {
  10879. int atk = rand()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  10880. WFIFOL(fd,4) = cap_value(atk, 0, SHRT_MAX);
  10881. }
  10882. break;
  10883. case SP_MATK1:
  10884. WFIFOL(fd,4) = cap_value(status->matk_max, 0, SHRT_MAX);
  10885. break;
  10886. case SP_HIT:
  10887. WFIFOL(fd,4) = status->hit;
  10888. break;
  10889. case SP_CRITICAL:
  10890. WFIFOL(fd,4) = status->cri/10;
  10891. break;
  10892. case SP_DEF1:
  10893. WFIFOL(fd,4) = status->def;
  10894. break;
  10895. case SP_MDEF1:
  10896. WFIFOL(fd,4) = status->mdef;
  10897. break;
  10898. case SP_MERCFLEE:
  10899. WFIFOL(fd,4) = status->flee;
  10900. break;
  10901. case SP_ASPD:
  10902. WFIFOL(fd,4) = status->amotion;
  10903. break;
  10904. case SP_HP:
  10905. WFIFOL(fd,4) = status->hp;
  10906. break;
  10907. case SP_MAXHP:
  10908. WFIFOL(fd,4) = status->max_hp;
  10909. break;
  10910. case SP_SP:
  10911. WFIFOL(fd,4) = status->sp;
  10912. break;
  10913. case SP_MAXSP:
  10914. WFIFOL(fd,4) = status->max_sp;
  10915. break;
  10916. case SP_MERCKILLS:
  10917. WFIFOL(fd,4) = md->mercenary.kill_count;
  10918. break;
  10919. case SP_MERCFAITH:
  10920. WFIFOL(fd,4) = mercenary_get_faith(md);
  10921. break;
  10922. }
  10923. WFIFOSET(fd,8);
  10924. }
  10925. void clif_mercenary_info(struct map_session_data *sd)
  10926. {
  10927. int fd;
  10928. struct mercenary_data *md;
  10929. struct status_data *status;
  10930. int atk;
  10931. if( sd == NULL || (md = sd->md) == NULL )
  10932. return;
  10933. fd = sd->fd;
  10934. status = &md->battle_status;
  10935. WFIFOHEAD(fd,80);
  10936. WFIFOW(fd,0) = 0x029b;
  10937. WFIFOL(fd,2) = md->bl.id;
  10938. // Mercenary shows ATK as a random value between ATK ~ ATK2
  10939. atk = rand()%(status->rhw.atk2 - status->rhw.atk + 1) + status->rhw.atk;
  10940. WFIFOW(fd,6) = cap_value(atk, 0, SHRT_MAX);
  10941. WFIFOW(fd,8) = cap_value(status->matk_max, 0, SHRT_MAX);
  10942. WFIFOW(fd,10) = status->hit;
  10943. WFIFOW(fd,12) = status->cri/10;
  10944. WFIFOW(fd,14) = status->def;
  10945. WFIFOW(fd,16) = status->mdef;
  10946. WFIFOW(fd,18) = status->flee;
  10947. WFIFOW(fd,20) = status->amotion;
  10948. safestrncpy((char*)WFIFOP(fd,22), md->db->name, NAME_LENGTH);
  10949. WFIFOW(fd,46) = md->db->lv;
  10950. WFIFOL(fd,48) = status->hp;
  10951. WFIFOL(fd,52) = status->max_hp;
  10952. WFIFOL(fd,56) = status->sp;
  10953. WFIFOL(fd,60) = status->max_sp;
  10954. WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
  10955. WFIFOW(fd,68) = mercenary_get_faith(md);
  10956. WFIFOL(fd,70) = mercenary_get_calls(md);
  10957. WFIFOL(fd,74) = md->mercenary.kill_count;
  10958. WFIFOW(fd,78) = md->battle_status.rhw.range;
  10959. WFIFOSET(fd,80);
  10960. }
  10961. void clif_mercenary_skillblock(struct map_session_data *sd)
  10962. {
  10963. struct mercenary_data *md;
  10964. int fd, i, len = 4, id, j;
  10965. if( sd == NULL || (md = sd->md) == NULL )
  10966. return;
  10967. fd = sd->fd;
  10968. WFIFOHEAD(fd,4+37*MAX_MERCSKILL);
  10969. WFIFOW(fd,0) = 0x029d;
  10970. for( i = 0; i < MAX_MERCSKILL; i++ )
  10971. {
  10972. if( (id = md->db->skill[i].id) == 0 )
  10973. continue;
  10974. j = id - MC_SKILLBASE;
  10975. WFIFOW(fd,len) = id;
  10976. WFIFOW(fd,len+2) = skill_get_inf(id);
  10977. WFIFOW(fd,len+4) = 0;
  10978. WFIFOW(fd,len+6) = md->db->skill[j].lv;
  10979. WFIFOW(fd,len+8) = skill_get_sp(id, md->db->skill[j].lv);
  10980. WFIFOW(fd,len+10) = skill_get_range2(&md->bl, id, md->db->skill[j].lv);
  10981. safestrncpy((char*)WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  10982. WFIFOB(fd,len+36) = 0; // Skillable for Mercenary?
  10983. len += 37;
  10984. }
  10985. WFIFOW(fd,2) = len;
  10986. WFIFOSET(fd,len);
  10987. }
  10988. void clif_parse_mercenary_action(int fd, struct map_session_data* sd)
  10989. {
  10990. int option = RFIFOB(fd,2);
  10991. if( sd->md == NULL )
  10992. return;
  10993. if( option == 2 ) merc_delete(sd->md, 2);
  10994. }
  10995. /*------------------------------------------
  10996. * Mercenary Message
  10997. * 0 = Mercenary soldier's duty hour is over.
  10998. * 1 = Your mercenary soldier has been killed.
  10999. * 2 = Your mercenary soldier has been fired.
  11000. * 3 = Your mercenary soldier has ran away.
  11001. *------------------------------------------*/
  11002. void clif_mercenary_message(int fd, int message)
  11003. {
  11004. WFIFOHEAD(fd,4);
  11005. WFIFOW(fd,0) = 0x0291;
  11006. WFIFOW(fd,2) = 1266 + message;
  11007. WFIFOSET(fd,4);
  11008. }
  11009. /*------------------------------------------
  11010. * Rental System Messages
  11011. *------------------------------------------*/
  11012. void clif_rental_time(int fd, int nameid, int seconds)
  11013. { // '<ItemName>' item will disappear in <seconds/60> minutes.
  11014. WFIFOHEAD(fd,8);
  11015. WFIFOW(fd,0) = 0x0298;
  11016. WFIFOW(fd,2) = nameid;
  11017. WFIFOL(fd,4) = seconds;
  11018. WFIFOSET(fd,8);
  11019. }
  11020. void clif_rental_expired(int fd, int nameid)
  11021. { // '<ItemName>' item has been deleted from the Inventory
  11022. WFIFOHEAD(fd,6);
  11023. WFIFOW(fd,0) = 0x0299;
  11024. WFIFOW(fd,2) = 0;
  11025. WFIFOW(fd,4) = nameid;
  11026. WFIFOSET(fd,6);
  11027. }
  11028. /*------------------------------------------
  11029. * Book Reading
  11030. *------------------------------------------*/
  11031. void clif_readbook(int fd, int book_id, int page)
  11032. {
  11033. WFIFOHEAD(fd,10);
  11034. WFIFOW(fd,0) = 0x0294;
  11035. WFIFOL(fd,2) = book_id;
  11036. WFIFOL(fd,6) = page;
  11037. WFIFOSET(fd,10);
  11038. }
  11039. /*------------------------------------------
  11040. * BattleGround Packets
  11041. *------------------------------------------*/
  11042. int clif_bg_hp(struct map_session_data *sd)
  11043. {
  11044. unsigned char buf[16];
  11045. nullpo_retr(0, sd);
  11046. WBUFW(buf,0)=0x106;
  11047. WBUFL(buf,2) = sd->status.account_id;
  11048. if( sd->battle_status.max_hp > SHRT_MAX )
  11049. { // To correctly display the %hp bar. [Skotlex]
  11050. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  11051. WBUFW(buf,8) = 100;
  11052. }
  11053. else
  11054. {
  11055. WBUFW(buf,6) = sd->battle_status.hp;
  11056. WBUFW(buf,8) = sd->battle_status.max_hp;
  11057. }
  11058. clif_send(buf, packet_len(0x106), &sd->bl, BG_AREA_WOS);
  11059. return 0;
  11060. }
  11061. int clif_bg_xy(struct map_session_data *sd)
  11062. {
  11063. unsigned char buf[10];
  11064. nullpo_retr(0, sd);
  11065. WBUFW(buf,0)=0x1eb;
  11066. WBUFL(buf,2)=sd->status.account_id;
  11067. WBUFW(buf,6)=sd->bl.x;
  11068. WBUFW(buf,8)=sd->bl.y;
  11069. clif_send(buf, packet_len(0x1eb), &sd->bl, BG_SAMEMAP_WOS);
  11070. return 0;
  11071. }
  11072. int clif_bg_xy_remove(struct map_session_data *sd)
  11073. {
  11074. unsigned char buf[10];
  11075. nullpo_retr(0, sd);
  11076. WBUFW(buf,0)=0x1eb;
  11077. WBUFL(buf,2)=sd->status.account_id;
  11078. WBUFW(buf,6)=-1;
  11079. WBUFW(buf,8)=-1;
  11080. clif_send(buf,packet_len(0x1eb),&sd->bl,BG_SAMEMAP_WOS);
  11081. return 0;
  11082. }
  11083. int clif_bg_belonginfo(struct map_session_data *sd)
  11084. {
  11085. int fd;
  11086. struct guild *g;
  11087. nullpo_retr(0, sd);
  11088. if( !sd->state.bg_id || (g = bg_guild_get(sd->state.bg_id)) == NULL )
  11089. return 0;
  11090. fd = sd->fd;
  11091. WFIFOHEAD(fd,packet_len(0x16c));
  11092. memset(WFIFOP(fd,0),0,packet_len(0x16c));
  11093. WFIFOW(fd,0) = 0x16c;
  11094. WFIFOL(fd,2) = g->guild_id;
  11095. WFIFOL(fd,6) = g->emblem_id;
  11096. WFIFOL(fd,10) = 0;
  11097. memcpy(WFIFOP(fd,19), g->name, NAME_LENGTH);
  11098. WFIFOSET(fd,packet_len(0x16c));
  11099. return 1;
  11100. }
  11101. int clif_bg_guild_id(struct block_list *bl)
  11102. {
  11103. struct battleground_data *bg;
  11104. int bg_id;
  11105. nullpo_retr(0, bl);
  11106. if( (bg_id = bg_team_get_id(bl)) > 0 && (bg = bg_team_search(bg_id)) != NULL && bg->g )
  11107. return bg->g->guild_id;
  11108. else
  11109. return status_get_guild_id(bl);
  11110. }
  11111. int clif_bg_emblem_id(struct block_list *bl)
  11112. {
  11113. struct battleground_data *bg;
  11114. int bg_id;
  11115. nullpo_retr(0, bl);
  11116. if( (bg_id = bg_team_get_id(bl)) > 0 && (bg = bg_team_search(bg_id)) != NULL && bg->g )
  11117. return bg->g->emblem_id;
  11118. else
  11119. return status_get_emblem_id(bl);
  11120. }
  11121. int clif_bg_emblem(struct map_session_data *sd, struct guild *g)
  11122. {
  11123. int fd;
  11124. nullpo_retr(0, sd);
  11125. nullpo_retr(0, g);
  11126. fd = sd->fd;
  11127. if( g->emblem_len <= 0 )
  11128. return 0;
  11129. WFIFOHEAD(fd,g->emblem_len+12);
  11130. WFIFOW(fd,0)=0x152;
  11131. WFIFOW(fd,2)=g->emblem_len+12;
  11132. WFIFOL(fd,4)=g->guild_id;
  11133. WFIFOL(fd,8)=g->emblem_id;
  11134. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  11135. WFIFOSET(fd,WFIFOW(fd,2));
  11136. return 0;
  11137. }
  11138. int clif_bg_memberlist(struct map_session_data *sd)
  11139. {
  11140. int fd, i, c;
  11141. struct battleground_data *bg;
  11142. struct map_session_data *psd;
  11143. nullpo_retr(0, sd);
  11144. if( (fd = sd->fd) == 0 )
  11145. return 0;
  11146. if( !sd->state.bg_id || (bg = bg_team_search(sd->state.bg_id)) == NULL )
  11147. return 0;
  11148. WFIFOHEAD(fd,bg->count * 104 + 4);
  11149. WFIFOW(fd,0) = 0x154;
  11150. for( i = 0, c = 0; i < bg->count; i++ )
  11151. {
  11152. if( (psd = bg->members[i].sd) == NULL )
  11153. continue;
  11154. WFIFOL(fd,c*104+ 4) = psd->status.account_id;
  11155. WFIFOL(fd,c*104+ 8) = psd->status.char_id;
  11156. WFIFOW(fd,c*104+12) = psd->status.hair;
  11157. WFIFOW(fd,c*104+14) = psd->status.hair_color;
  11158. WFIFOW(fd,c*104+16) = psd->status.sex;
  11159. WFIFOW(fd,c*104+18) = psd->status.class_;
  11160. WFIFOW(fd,c*104+20) = psd->status.base_level;
  11161. WFIFOL(fd,c*104+22) = 0;
  11162. WFIFOL(fd,c*104+26) = 1;
  11163. WFIFOL(fd,c*104+30) = c;
  11164. memset(WFIFOP(fd,c*104+34),0,50);
  11165. memcpy(WFIFOP(fd,c*104+84),psd->status.name,NAME_LENGTH);
  11166. c++;
  11167. }
  11168. WFIFOW(fd, 2)=c*104+4;
  11169. WFIFOSET(fd,WFIFOW(fd,2));
  11170. return 0;
  11171. }
  11172. int clif_bg_leave(struct map_session_data *sd, const char *name, const char *mes)
  11173. {
  11174. unsigned char buf[128];
  11175. nullpo_retr(0, sd);
  11176. WBUFW(buf,0)=0x15a;
  11177. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  11178. memcpy(WBUFP(buf,26),mes,40);
  11179. clif_send(buf,packet_len(0x15a),&sd->bl,BG);
  11180. return 0;
  11181. }
  11182. int clif_bg_leave_single(struct map_session_data *sd, const char *name, const char *mes)
  11183. {
  11184. int fd;
  11185. nullpo_retr(0, sd);
  11186. fd = sd->fd;
  11187. WFIFOHEAD(fd,66);
  11188. WFIFOW(fd,0) = 0x15a;
  11189. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  11190. memcpy(WFIFOP(fd,26), mes, 40);
  11191. WFIFOSET(fd,66);
  11192. return 0;
  11193. }
  11194. int clif_bg_message(struct battleground_data *bg, int account_id, const char *mes, int len)
  11195. {
  11196. struct map_session_data *sd;
  11197. unsigned char *buf;
  11198. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  11199. WBUFW(buf, 0) = 0x17f;
  11200. WBUFW(buf, 2) = len + 4;
  11201. memcpy(WBUFP(buf,4), mes, len);
  11202. if( (sd = bg_getavailablesd(bg)) != NULL )
  11203. clif_send(buf, WBUFW(buf,2), &sd->bl, BG);
  11204. if( buf ) aFree(buf);
  11205. return 0;
  11206. }
  11207. int clif_bg_expulsion_single(struct map_session_data *sd, const char *name, const char *mes)
  11208. {
  11209. int fd;
  11210. nullpo_retr(0, sd);
  11211. fd = sd->fd;
  11212. WFIFOHEAD(fd, 90);
  11213. WFIFOW(fd,0) = 0x15c;
  11214. safestrncpy((char*)WFIFOP(fd,2), name, NAME_LENGTH);
  11215. safestrncpy((char*)WFIFOP(fd,26), mes, 40);
  11216. safestrncpy((char*)WFIFOP(fd,66), "", NAME_LENGTH);
  11217. WFIFOSET(fd,90);
  11218. return 0;
  11219. }
  11220. /*==========================================
  11221. * パケットデバッグ
  11222. *------------------------------------------*/
  11223. void clif_parse_debug(int fd,struct map_session_data *sd)
  11224. {
  11225. int i, cmd, len;
  11226. cmd = RFIFOW(fd,0);
  11227. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  11228. ShowDebug("packet debug 0x%4X\n",cmd);
  11229. ShowMessage("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  11230. for(i=0;i<len;i++){
  11231. if((i&15)==0)
  11232. ShowMessage("\n%04X ",i);
  11233. ShowMessage("%02X ",RFIFOB(fd,i));
  11234. }
  11235. ShowMessage("\n");
  11236. }
  11237. /*==========================================
  11238. * Main client packet processing function
  11239. *------------------------------------------*/
  11240. int clif_parse(int fd)
  11241. {
  11242. int cmd, packet_ver, packet_len, err;
  11243. TBL_PC* sd;
  11244. int pnum;
  11245. //TODO apply deplays or disconnect based on packet throughput [FlavioJS]
  11246. // Note: "click masters" can do 80+ clicks in 10 seconds
  11247. for( pnum = 0; pnum < 3; ++pnum )// Limit max packets per cycle to 3 (delay packet spammers) [FlavioJS]
  11248. { // begin main client packet processing loop
  11249. sd = (TBL_PC *)session[fd]->session_data;
  11250. if (session[fd]->flag.eof) {
  11251. if (sd) {
  11252. if (sd->state.autotrade) {
  11253. //Disassociate character from the socket connection.
  11254. session[fd]->session_data = NULL;
  11255. sd->fd = 0;
  11256. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  11257. } else
  11258. if (sd->state.active) {
  11259. // Player logout display [Valaris]
  11260. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n", (pc_isGM(sd))?"GM ":"", sd->status.name);
  11261. clif_quitsave(fd, sd);
  11262. } else {
  11263. //Unusual logout (during log on/off/map-changer procedure)
  11264. ShowInfo("Player AID:%d/CID:%d logged off.\n", sd->status.account_id, sd->status.char_id);
  11265. map_quit(sd);
  11266. }
  11267. } else {
  11268. ShowInfo("Closed connection from '"CL_WHITE"%s"CL_RESET"'.\n", ip2str(session[fd]->client_addr, NULL));
  11269. }
  11270. do_close(fd);
  11271. return 0;
  11272. }
  11273. if (RFIFOREST(fd) < 2)
  11274. return 0;
  11275. cmd = RFIFOW(fd,0);
  11276. // identify client's packet version
  11277. if (sd) {
  11278. packet_ver = sd->packet_ver;
  11279. } else {
  11280. // check authentification packet to know packet version
  11281. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  11282. if( err )
  11283. {// failed to identify packet version
  11284. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  11285. err == 1 ? "" :
  11286. err == 2 ? ", possibly for having an invalid account_id" :
  11287. err == 3 ? ", possibly for having an invalid char_id." :
  11288. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  11289. err == 4 ? ", possibly for having an invalid login_id1." :
  11290. err == 5 ? ", possibly for having an invalid client_tick." :
  11291. */
  11292. err == 6 ? ", possibly for having an invalid sex." :
  11293. ". ERROR invalid error code"));
  11294. WFIFOHEAD(fd,packet_len(0x6a));
  11295. WFIFOW(fd,0) = 0x6a;
  11296. WFIFOB(fd,2) = 3; // Rejected from Server
  11297. WFIFOSET(fd,packet_len(0x6a));
  11298. RFIFOSKIP(fd, RFIFOREST(fd));
  11299. set_eof(fd);
  11300. return 0;
  11301. }
  11302. }
  11303. // filter out invalid / unsupported packets
  11304. if (cmd > MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) {
  11305. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  11306. set_eof(fd);
  11307. return 0;
  11308. }
  11309. // determine real packet length
  11310. packet_len = packet_db[packet_ver][cmd].len;
  11311. if (packet_len == -1) { // variable-length packet
  11312. if (RFIFOREST(fd) < 4)
  11313. return 0;
  11314. packet_len = RFIFOW(fd,2);
  11315. if (packet_len < 4 || packet_len > 32768) {
  11316. ShowWarning("clif_parse: Received packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  11317. set_eof(fd);
  11318. return 0;
  11319. }
  11320. }
  11321. if ((int)RFIFOREST(fd) < packet_len)
  11322. return 0; // not enough data received to form the packet
  11323. if (packet_db[packet_ver][cmd].func) {
  11324. if (sd && sd->bl.prev == NULL && packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck)
  11325. ; //Only valid packet when player is not on a map is the finish-loading packet.
  11326. else
  11327. if ((sd && sd->state.active)
  11328. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  11329. || packet_db[packet_ver][cmd].func == clif_parse_debug
  11330. ) //Only execute the function when there's an active sd (except for debug/wanttoconnect packets)
  11331. packet_db[packet_ver][cmd].func(fd, sd);
  11332. }
  11333. #if DUMP_UNKNOWN_PACKET
  11334. else if (battle_config.error_log)
  11335. {
  11336. int i;
  11337. FILE *fp;
  11338. char packet_txt[256] = "save/packet.txt";
  11339. time_t now;
  11340. dump = 1;
  11341. if ((fp = fopen(packet_txt, "a")) == NULL) {
  11342. ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
  11343. return 1;
  11344. } else {
  11345. time(&now);
  11346. if (sd && sd->state.active) {
  11347. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  11348. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  11349. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  11350. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  11351. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  11352. for(i = 0; i < packet_len; i++) {
  11353. if ((i & 15) == 0)
  11354. fprintf(fp, "\n\t%04X ", i);
  11355. fprintf(fp, "%02X ", RFIFOB(fd,i));
  11356. }
  11357. fprintf(fp, "\n\n");
  11358. fclose(fp);
  11359. }
  11360. }
  11361. #endif
  11362. /* TODO: use utils.c :: dump()
  11363. if (dump) {
  11364. int i;
  11365. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  11366. ShowMessage("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  11367. for(i = 0; i < packet_len; i++) {
  11368. if ((i & 15) == 0)
  11369. ShowMessage("\n%04X ",i);
  11370. ShowMessage("%02X ", RFIFOB(fd,i));
  11371. }
  11372. ShowMessage("\n");
  11373. if (sd && sd->state.active) {
  11374. if (sd->status.name != NULL)
  11375. ShowMessage("\nAccount ID %d, character ID %d, player name %s.\n",
  11376. sd->status.account_id, sd->status.char_id, sd->status.name);
  11377. else
  11378. ShowMessage("\nAccount ID %d.\n", sd->bl.id);
  11379. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  11380. ShowMessage("\nAccount ID %d.\n", sd->bl.id);
  11381. }*/
  11382. RFIFOSKIP(fd, packet_len);
  11383. }; // main loop end
  11384. return 0;
  11385. }
  11386. /*==========================================
  11387. * パケットデータベース読み込み
  11388. *------------------------------------------*/
  11389. static int packetdb_readdb(void)
  11390. {
  11391. FILE *fp;
  11392. char line[1024];
  11393. int ln=0;
  11394. int cmd,i,j,packet_ver;
  11395. int max_cmd=-1;
  11396. int skip_ver = 0;
  11397. int warned = 0;
  11398. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  11399. int packet_len_table[MAX_PACKET_DB] = {
  11400. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11404. //#0x0040
  11405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11407. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  11408. #if PACKETVER < 2
  11409. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  11410. #elif PACKETVER < 20071106 // 78-7b 亀島以降 lv99エフェクト用
  11411. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  11412. #else // change in 0x78 and 0x7c
  11413. 3, 28, 19, 11, 3, -1, 9, 5, 55, 53, 58, 60, 42, 2, 6, 6,
  11414. #endif
  11415. //#0x0080
  11416. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  11417. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  11418. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  11419. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  11420. //#0x00C0
  11421. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  11422. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  11423. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  11424. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  11425. //#0x0100
  11426. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  11427. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  11428. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  11429. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  11430. //#0x0140
  11431. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  11432. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  11433. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  11434. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  11435. //#0x0180
  11436. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  11437. #if PACKETVER < 1
  11438. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  11439. #else // 196 comodo以降 状態表示アイコン用
  11440. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  11441. #endif
  11442. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  11443. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  11444. //#0x01C0, Set 0x1d5=-1
  11445. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  11446. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  11447. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  11448. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  11449. //#0x0200
  11450. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  11451. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282, 10, 10, -1, -1, 66,
  11452. #if PACKETVER < 20071106
  11453. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  11454. #else // 0x22c changed
  11455. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 65, 5, 71, 5,
  11456. #endif
  11457. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1, -1, 4, 2,
  11458. //#0x0240
  11459. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8, 12, 4, 10,
  11460. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4, -1, 4, 0,
  11461. 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11462. 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11463. //#0x0280
  11464. 0, 0, 0, 6, 0, 0, 0, 0, 0, 8, 18, 0, 0, 0, 0, 0,
  11465. 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11467. 0, 0, 0, 0, 0, 0, 0, 0, 0,191, 0, 0, 0, 0, 0, 0,
  11468. //#0x02C0
  11469. 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11470. 0, 0, 0, 0, 0, 0, 6, -1, 10, 10, 0, 0, 0, 0, 0, 0,
  11471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  11473. };
  11474. struct {
  11475. void (*func)(int, struct map_session_data *);
  11476. char *name;
  11477. } clif_parse_func[]={
  11478. {clif_parse_WantToConnection,"wanttoconnection"},
  11479. {clif_parse_LoadEndAck,"loadendack"},
  11480. {clif_parse_TickSend,"ticksend"},
  11481. {clif_parse_WalkToXY,"walktoxy"},
  11482. {clif_parse_QuitGame,"quitgame"},
  11483. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  11484. {clif_parse_GlobalMessage,"globalmessage"},
  11485. {clif_parse_MapMove,"mapmove"},
  11486. {clif_parse_ChangeDir,"changedir"},
  11487. {clif_parse_Emotion,"emotion"},
  11488. {clif_parse_HowManyConnections,"howmanyconnections"},
  11489. {clif_parse_ActionRequest,"actionrequest"},
  11490. {clif_parse_Restart,"restart"},
  11491. {clif_parse_WisMessage,"wis"},
  11492. {clif_parse_GMmessage,"gmmessage"},
  11493. {clif_parse_TakeItem,"takeitem"},
  11494. {clif_parse_DropItem,"dropitem"},
  11495. {clif_parse_UseItem,"useitem"},
  11496. {clif_parse_EquipItem,"equipitem"},
  11497. {clif_parse_UnequipItem,"unequipitem"},
  11498. {clif_parse_NpcClicked,"npcclicked"},
  11499. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  11500. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  11501. {clif_parse_NpcSellListSend,"npcselllistsend"},
  11502. {clif_parse_CreateChatRoom,"createchatroom"},
  11503. {clif_parse_ChatAddMember,"chataddmember"},
  11504. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  11505. {clif_parse_ChangeChatOwner,"changechatowner"},
  11506. {clif_parse_KickFromChat,"kickfromchat"},
  11507. {clif_parse_ChatLeave,"chatleave"},
  11508. {clif_parse_TradeRequest,"traderequest"},
  11509. {clif_parse_TradeAck,"tradeack"},
  11510. {clif_parse_TradeAddItem,"tradeadditem"},
  11511. {clif_parse_TradeOk,"tradeok"},
  11512. {clif_parse_TradeCancel,"tradecancel"},
  11513. {clif_parse_TradeCommit,"tradecommit"},
  11514. {clif_parse_StopAttack,"stopattack"},
  11515. {clif_parse_PutItemToCart,"putitemtocart"},
  11516. {clif_parse_GetItemFromCart,"getitemfromcart"},
  11517. {clif_parse_RemoveOption,"removeoption"},
  11518. {clif_parse_ChangeCart,"changecart"},
  11519. {clif_parse_StatusUp,"statusup"},
  11520. {clif_parse_SkillUp,"skillup"},
  11521. {clif_parse_UseSkillToId,"useskilltoid"},
  11522. {clif_parse_UseSkillToPos,"useskilltopos"},
  11523. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  11524. {clif_parse_UseSkillMap,"useskillmap"},
  11525. {clif_parse_RequestMemo,"requestmemo"},
  11526. {clif_parse_ProduceMix,"producemix"},
  11527. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  11528. {clif_parse_NpcNextClicked,"npcnextclicked"},
  11529. {clif_parse_NpcAmountInput,"npcamountinput"},
  11530. {clif_parse_NpcStringInput,"npcstringinput"},
  11531. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  11532. {clif_parse_ItemIdentify,"itemidentify"},
  11533. {clif_parse_SelectArrow,"selectarrow"},
  11534. {clif_parse_AutoSpell,"autospell"},
  11535. {clif_parse_UseCard,"usecard"},
  11536. {clif_parse_InsertCard,"insertcard"},
  11537. {clif_parse_RepairItem,"repairitem"},
  11538. {clif_parse_WeaponRefine,"weaponrefine"},
  11539. {clif_parse_SolveCharName,"solvecharname"},
  11540. {clif_parse_ResetChar,"resetchar"},
  11541. {clif_parse_LGMmessage,"lgmmessage"},
  11542. {clif_parse_MoveToKafra,"movetokafra"},
  11543. {clif_parse_MoveFromKafra,"movefromkafra"},
  11544. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  11545. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  11546. {clif_parse_CloseKafra,"closekafra"},
  11547. {clif_parse_CreateParty,"createparty"},
  11548. {clif_parse_CreateParty2,"createparty2"},
  11549. {clif_parse_PartyInvite,"partyinvite"},
  11550. {clif_parse_PartyInvite2,"partyinvite2"},
  11551. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  11552. {clif_parse_ReplyPartyInvite2,"replypartyinvite2"},
  11553. {clif_parse_LeaveParty,"leaveparty"},
  11554. {clif_parse_RemovePartyMember,"removepartymember"},
  11555. {clif_parse_PartyChangeOption,"partychangeoption"},
  11556. {clif_parse_PartyMessage,"partymessage"},
  11557. {clif_parse_CloseVending,"closevending"},
  11558. {clif_parse_VendingListReq,"vendinglistreq"},
  11559. {clif_parse_PurchaseReq,"purchasereq"},
  11560. {clif_parse_OpenVending,"openvending"},
  11561. {clif_parse_CreateGuild,"createguild"},
  11562. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  11563. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  11564. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  11565. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  11566. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  11567. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  11568. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  11569. {clif_parse_GuildInvite,"guildinvite"},
  11570. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  11571. {clif_parse_GuildLeave,"guildleave"},
  11572. {clif_parse_GuildExpulsion,"guildexpulsion"},
  11573. {clif_parse_GuildMessage,"guildmessage"},
  11574. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  11575. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  11576. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  11577. {clif_parse_GuildOpposition,"guildopposition"},
  11578. {clif_parse_GuildBreak,"guildbreak"},
  11579. {clif_parse_PetMenu,"petmenu"},
  11580. {clif_parse_CatchPet,"catchpet"},
  11581. {clif_parse_SelectEgg,"selectegg"},
  11582. {clif_parse_SendEmotion,"sendemotion"},
  11583. {clif_parse_ChangePetName,"changepetname"},
  11584. {clif_parse_GMKick,"gmkick"},
  11585. {clif_parse_GMHide,"gmhide"},
  11586. {clif_parse_GMReqNoChat,"gmreqnochat"},
  11587. {clif_parse_GMReqAccountName,"gmreqaccname"},
  11588. {clif_parse_GMKickAll,"killall"},
  11589. {clif_parse_GMRecall,"recall"},
  11590. {clif_parse_GMRecall,"summon"},
  11591. {clif_parse_GM_Monster_Item,"itemmonster"},
  11592. {clif_parse_GMShift,"remove"},
  11593. {clif_parse_GMShift,"shift"},
  11594. {clif_parse_GMChangeMapType,"changemaptype"},
  11595. {clif_parse_GMRc,"rc"},
  11596. {clif_parse_NoviceDoriDori,"sndoridori"},
  11597. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  11598. {clif_parse_PMIgnore,"wisexin"},
  11599. {clif_parse_PMIgnoreList,"wisexlist"},
  11600. {clif_parse_PMIgnoreAll,"wisall"},
  11601. {clif_parse_FriendsListAdd,"friendslistadd"},
  11602. {clif_parse_FriendsListRemove,"friendslistremove"},
  11603. {clif_parse_FriendsListReply,"friendslistreply"},
  11604. {clif_parse_Blacksmith,"blacksmith"},
  11605. {clif_parse_Alchemist,"alchemist"},
  11606. {clif_parse_Taekwon,"taekwon"},
  11607. {clif_parse_RankingPk,"rankingpk"},
  11608. {clif_parse_FeelSaveOk,"feelsaveok"},
  11609. {clif_parse_debug,"debug"},
  11610. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  11611. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  11612. {clif_parse_HomMoveTo,"hommoveto"},
  11613. {clif_parse_HomAttack,"homattack"},
  11614. {clif_parse_HomMenu,"hommenu"},
  11615. {clif_parse_StoragePassword,"storagepassword"},
  11616. {clif_parse_Hotkey,"hotkey"},
  11617. {clif_parse_AutoRevive,"autorevive"},
  11618. {clif_parse_Check,"check"},
  11619. {clif_parse_Adopt_request,"adoptrequest"},
  11620. {clif_parse_Adopt_reply,"adoptreply"},
  11621. #ifndef TXT_ONLY
  11622. // MAIL SYSTEM
  11623. {clif_parse_Mail_refreshinbox,"mailrefresh"},
  11624. {clif_parse_Mail_read,"mailread"},
  11625. {clif_parse_Mail_getattach,"mailgetattach"},
  11626. {clif_parse_Mail_delete,"maildelete"},
  11627. {clif_parse_Mail_return,"mailreturn"},
  11628. {clif_parse_Mail_setattach,"mailsetattach"},
  11629. {clif_parse_Mail_winopen,"mailwinopen"},
  11630. {clif_parse_Mail_send,"mailsend"},
  11631. // AUCTION SYSTEM
  11632. {clif_parse_Auction_search,"auctionsearch"},
  11633. {clif_parse_Auction_buysell,"auctionbuysell"},
  11634. {clif_parse_Auction_setitem,"auctionsetitem"},
  11635. {clif_parse_Auction_cancelreg,"auctioncancelreg"},
  11636. {clif_parse_Auction_register,"auctionregister"},
  11637. {clif_parse_Auction_cancel,"auctioncancel"},
  11638. {clif_parse_Auction_close,"auctionclose"},
  11639. {clif_parse_Auction_bid,"auctionbid"},
  11640. #endif
  11641. {clif_parse_cashshop_buy,"cashshopbuy"},
  11642. {clif_parse_ViewPlayerEquip,"viewplayerequip"},
  11643. {clif_parse_EquipTick,"equiptickbox"},
  11644. {clif_parse_mercenary_action,"mermenu"},
  11645. {NULL,NULL}
  11646. };
  11647. // initialize packet_db[SERVER] from hardcoded packet_len_table[] values
  11648. memset(packet_db,0,sizeof(packet_db));
  11649. for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i )
  11650. packet_len(i) = packet_len_table[i];
  11651. sprintf(line, "%s/packet_db.txt", db_path);
  11652. if( (fp=fopen(line,"r"))==NULL ){
  11653. ShowFatalError("can't read %s\n", line);
  11654. exit(EXIT_FAILURE);
  11655. }
  11656. clif_config.packet_db_ver = MAX_PACKET_VER;
  11657. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  11658. while( fgets(line, sizeof(line), fp) )
  11659. {
  11660. ln++;
  11661. if(line[0]=='/' && line[1]=='/')
  11662. continue;
  11663. if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
  11664. {
  11665. if(strcmpi(w1,"packet_ver")==0) {
  11666. int prev_ver = packet_ver;
  11667. skip_ver = 0;
  11668. packet_ver = atoi(w2);
  11669. if ( packet_ver > MAX_PACKET_VER )
  11670. { //Check to avoid overflowing. [Skotlex]
  11671. if( (warned&1) == 0 )
  11672. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  11673. warned &= 1;
  11674. skip_ver = 1;
  11675. }
  11676. else if( packet_ver < 0 )
  11677. {
  11678. if( (warned&2) == 0 )
  11679. ShowWarning("Negative packet versions are not supported.\n");
  11680. warned &= 2;
  11681. skip_ver = 1;
  11682. }
  11683. else if( packet_ver == SERVER )
  11684. {
  11685. if( (warned&4) == 0 )
  11686. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  11687. warned &= 4;
  11688. skip_ver = 1;
  11689. }
  11690. if( skip_ver )
  11691. {
  11692. ShowWarning("Skipping packet version %d.\n", packet_ver);
  11693. packet_ver = prev_ver;
  11694. continue;
  11695. }
  11696. // copy from previous version into new version and continue
  11697. // - indicating all following packets should be read into the newer version
  11698. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  11699. continue;
  11700. } else if(strcmpi(w1,"packet_db_ver")==0) {
  11701. if(strcmpi(w2,"default")==0) //This is the preferred version.
  11702. clif_config.packet_db_ver = MAX_PACKET_VER;
  11703. else // to manually set the packet DB version
  11704. clif_config.packet_db_ver = cap_value(atoi(w2), 0, MAX_PACKET_VER);
  11705. continue;
  11706. }
  11707. }
  11708. if( skip_ver != 0 )
  11709. continue; // Skipping current packet version
  11710. memset(str,0,sizeof(str));
  11711. for(j=0,p=line;j<4 && p; ++j)
  11712. {
  11713. str[j]=p;
  11714. p=strchr(p,',');
  11715. if(p) *p++=0;
  11716. }
  11717. if(str[0]==NULL)
  11718. continue;
  11719. cmd=strtol(str[0],(char **)NULL,0);
  11720. if(max_cmd < cmd)
  11721. max_cmd = cmd;
  11722. if(cmd <= 0 || cmd > MAX_PACKET_DB)
  11723. continue;
  11724. if(str[1]==NULL){
  11725. ShowError("packet_db: packet len error\n");
  11726. continue;
  11727. }
  11728. packet_db[packet_ver][cmd].len = (short)atoi(str[1]);
  11729. if(str[2]==NULL){
  11730. packet_db[packet_ver][cmd].func = NULL;
  11731. ln++;
  11732. continue;
  11733. }
  11734. // look up processing function by name
  11735. ARR_FIND( 0, ARRAYLENGTH(clif_parse_func), j, clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0 );
  11736. if( j < ARRAYLENGTH(clif_parse_func) )
  11737. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  11738. // set the identifying cmd for the packet_db version
  11739. if (strcmp(str[2],"wanttoconnection")==0)
  11740. clif_config.connect_cmd[packet_ver] = cmd;
  11741. if(str[3]==NULL){
  11742. ShowError("packet_db: packet error\n");
  11743. exit(EXIT_FAILURE);
  11744. }
  11745. for(j=0,p2=str[3];p2;j++){
  11746. short k;
  11747. str2[j]=p2;
  11748. p2=strchr(p2,':');
  11749. if(p2) *p2++=0;
  11750. k = atoi(str2[j]);
  11751. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  11752. packet_db[packet_ver][cmd].pos[j] = k;
  11753. }
  11754. }
  11755. fclose(fp);
  11756. if(max_cmd > MAX_PACKET_DB)
  11757. {
  11758. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  11759. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  11760. }
  11761. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  11762. { //Locate the nearest version that we still support. [Skotlex]
  11763. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  11764. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  11765. }
  11766. 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);
  11767. return 0;
  11768. }
  11769. /*==========================================
  11770. *
  11771. *------------------------------------------*/
  11772. int do_init_clif(void)
  11773. {
  11774. clif_config.packet_db_ver = -1; // the main packet version of the DB
  11775. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  11776. memset(packet_db,0,sizeof(packet_db));
  11777. //Using the packet_db file is the only way to set up packets now [Skotlex]
  11778. packetdb_readdb();
  11779. set_defaultparse(clif_parse);
  11780. if( make_listen_bind(bind_ip,map_port) == -1 )
  11781. {
  11782. ShowFatalError("can't bind game port\n");
  11783. exit(EXIT_FAILURE);
  11784. }
  11785. add_timer_func_list(clif_clearunit_delayed_sub, "clif_clearunit_delayed_sub");
  11786. add_timer_func_list(clif_delayquit, "clif_delayquit");
  11787. return 0;
  11788. }