clif.c 320 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #define DUMP_UNKNOWN_PACKET 0
  4. #define DUMP_ALL_PACKETS 0
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdarg.h>
  10. #include <time.h>
  11. #include "../common/cbasetypes.h"
  12. #include "../common/socket.h"
  13. #include "../common/timer.h"
  14. #include "../common/malloc.h"
  15. #include "../common/version.h"
  16. #include "../common/nullpo.h"
  17. #include "../common/showmsg.h"
  18. #include "../common/strlib.h"
  19. #include "map.h"
  20. #include "chrif.h"
  21. #include "clif.h"
  22. #include "pc.h"
  23. #include "status.h"
  24. #include "npc.h"
  25. #include "itemdb.h"
  26. #include "chat.h"
  27. #include "trade.h"
  28. #include "storage.h"
  29. #include "script.h"
  30. #include "skill.h"
  31. #include "atcommand.h"
  32. #include "charcommand.h"
  33. #include "intif.h"
  34. #include "battle.h"
  35. #include "mob.h"
  36. #include "party.h"
  37. #include "unit.h"
  38. #include "guild.h"
  39. #include "vending.h"
  40. #include "pet.h"
  41. #include "mercenary.h" //[orn]
  42. #include "log.h"
  43. #include "irc.h"
  44. struct Clif_Config {
  45. int packet_db_ver; //Preferred packet version.
  46. int connect_cmd[MAX_PACKET_VER + 1]; //Store the connect command for all versions. [Skotlex]
  47. } clif_config;
  48. struct packet_db packet_db[MAX_PACKET_VER + 1][MAX_PACKET_DB];
  49. //Converts item type in case of pet eggs.
  50. #define itemtype(a) (a == 7)?4:a
  51. #define WBUFPOS(p,pos,x,y,dir) \
  52. do { \
  53. uint8 *__p = (p); \
  54. __p+=(pos); \
  55. __p[0] = (uint8)((x)>>2); \
  56. __p[1] = (uint8)(((x)<<6) | (((y)>>4)&0x3f)); \
  57. __p[2] = (uint8)(((y)<<4) | ((dir)&0xf)); \
  58. } while(0)
  59. // client-side: x0+=sx0*0.0625-0.5 and y0+=sy0*0.0625-0.5
  60. #define WBUFPOS2(p,pos,x0,y0,x1,y1,sx0,sy0) \
  61. do { \
  62. uint8 *__p = (p); \
  63. __p+=(pos); \
  64. __p[0]=(uint8)((x0)>>2); \
  65. __p[1]=(uint8)(((x0)<<6) | (((y0)>>4)&0x3f)); \
  66. __p[2]=(uint8)(((y0)<<4) | (((x1)>>6)&0x0f)); \
  67. __p[3]=(uint8)(((x1)<<2) | (((y1)>>8)&0x03)); \
  68. __p[4]=(uint8)(y1); \
  69. __p[5]=(uint8)(((sx0)<<4) | ((sy0)&0x0f)); \
  70. } while(0)
  71. #define WFIFOPOS(fd,pos,x,y,dir) WBUFPOS(WFIFOP(fd,pos),0,x,y,dir)
  72. #define WFIFOPOS2(fd,pos,x0,y0,x1,y1,sx0,sy0) WBUFPOS2(WFIFOP(fd,pos),0,x0,y0,x1,y1,sx0,sy0)
  73. //To make the assignation of the level based on limits clearer/easier. [Skotlex]
  74. #define clif_setlevel(lv) (lv<battle_config.max_lv?lv:battle_config.max_lv-(lv<battle_config.aura_lv?1:0));
  75. //Removed sd->npc_shopid because there is no packet sent from the client when you cancel a buy!
  76. //Quick check to know if the player shouldn't be "busy" with something else to deny action requests. [Skotlex]
  77. #define clif_cant_act(sd) (sd->npc_id || sd->vender_id || sd->chatID || sd->sc.opt1 || sd->state.trading || sd->state.storage_flag)
  78. // Checks if SD is in a trade/shop (where messing with the inventory can cause problems/exploits)
  79. #define clif_trading(sd) (sd->npc_id || sd->vender_id || sd->state.trading )
  80. //To idenfity disguised characters.
  81. #define disguised(bl) (bl->type==BL_PC && ((TBL_PC*)bl)->disguise)
  82. //Guarantees that the given string does not exceeds the allowed size, as well as making sure it's null terminated. [Skotlex\]
  83. #define mes_len_check(mes, len, max) if (len > max) { mes[max-1] = '\0'; len = max; } else mes[len-1] = '\0';
  84. static char map_ip_str[128];
  85. static in_addr_t map_ip;
  86. static in_addr_t bind_ip = INADDR_ANY;
  87. static int map_port = 5121;
  88. int map_fd;
  89. //These two will be used to verify the incoming player's validity.
  90. //It helps identify their client packet version correctly. [Skotlex]
  91. static int max_account_id = DEFAULT_MAX_ACCOUNT_ID;
  92. static int max_char_id = DEFAULT_MAX_CHAR_ID;
  93. int clif_parse (int fd);
  94. static void clif_hpmeter_single(int fd, struct map_session_data *sd);
  95. /*==========================================
  96. * map鯖のip設定
  97. *------------------------------------------
  98. */
  99. int clif_setip(const char* ip)
  100. {
  101. char ip_str[16];
  102. map_ip = resolve_hostbyname(ip,NULL,ip_str);
  103. if (!map_ip) {
  104. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  105. return 0;
  106. }
  107. strncpy(map_ip_str, ip, sizeof(map_ip_str));
  108. ShowInfo("Map Server IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%s"CL_RESET"'.\n", ip, ip_str);
  109. return 1;
  110. }
  111. void clif_setbindip(const char* ip)
  112. {
  113. unsigned char ip_str[4];
  114. bind_ip = resolve_hostbyname(ip,ip_str,NULL);
  115. if (bind_ip) {
  116. ShowInfo("Map Server Bind IP Address : '"CL_WHITE"%s"CL_RESET"' -> '"CL_WHITE"%d.%d.%d.%d"CL_RESET"'.\n", ip, ip_str[0], ip_str[1], ip_str[2], ip_str[3]);
  117. } else {
  118. ShowWarning("Failed to Resolve Map Server Address! (%s)\n", ip);
  119. }
  120. }
  121. /*==========================================
  122. * map鯖のport設定
  123. *------------------------------------------
  124. */
  125. void clif_setport(int port)
  126. {
  127. map_port = port;
  128. }
  129. /*==========================================
  130. * map鯖のip読み出し
  131. *------------------------------------------
  132. */
  133. in_addr_t clif_getip(void)
  134. {
  135. return map_ip;
  136. }
  137. //Returns the ip casted as a basic type, to avoid needing to include the socket/net related libs by calling modules.
  138. unsigned long clif_getip_long(void)
  139. {
  140. return (unsigned long)map_ip;
  141. }
  142. //Refreshes map_server ip, returns the new ip if the ip changed, otherwise it
  143. //returns 0.
  144. unsigned long clif_refresh_ip(void) {
  145. in_addr_t new_ip;
  146. new_ip = resolve_hostbyname(map_ip_str, NULL, NULL);
  147. if (new_ip && new_ip != map_ip) {
  148. map_ip = new_ip;
  149. ShowInfo("Updating IP resolution of [%s].\n",map_ip_str);
  150. return (unsigned long)map_ip;
  151. }
  152. return 0;
  153. }
  154. /*==========================================
  155. * map鯖のport読み出し
  156. *------------------------------------------
  157. */
  158. int clif_getport(void)
  159. {
  160. return map_port;
  161. }
  162. /*==========================================
  163. * Counts connected players.
  164. *------------------------------------------
  165. */
  166. int clif_countusers(void)
  167. {
  168. int users = 0, i;
  169. struct map_session_data *sd;
  170. for(i = 0; i < fd_max; i++) {
  171. if (session[i] && session[i]->func_parse == clif_parse &&
  172. (sd = (struct map_session_data*)session[i]->session_data) &&
  173. sd->state.auth && !(battle_config.hide_GM_session && pc_isGM(sd)))
  174. users++;
  175. }
  176. return users;
  177. }
  178. /*==========================================
  179. * 全てのclientに対してfunc()実行
  180. *------------------------------------------
  181. */
  182. int clif_foreachclient(int (*func)(struct map_session_data*, va_list),...) //recoded by sasuke, bug when player count gets higher [Kevin]
  183. {
  184. int i;
  185. va_list ap;
  186. struct map_session_data *sd;
  187. va_start(ap,func);
  188. for(i = 0; i < fd_max; i++) {
  189. if ( session[i] && session[i]->func_parse == clif_parse) {
  190. sd = (struct map_session_data*)session[i]->session_data;
  191. if ( sd && sd->state.auth && !sd->state.waitingdisconnect )
  192. func(sd, ap);
  193. }
  194. }
  195. va_end(ap);
  196. return 0;
  197. }
  198. /*==========================================
  199. * clif_sendでAREA*指定時用
  200. *------------------------------------------
  201. */
  202. int clif_send_sub(struct block_list *bl, va_list ap)
  203. {
  204. struct block_list *src_bl;
  205. struct map_session_data *sd;
  206. unsigned char *buf;
  207. int len, type, fd;
  208. nullpo_retr(0, bl);
  209. nullpo_retr(0, ap);
  210. nullpo_retr(0, sd = (struct map_session_data *)bl);
  211. fd = sd->fd;
  212. if (!fd) //Don't send to disconnected clients.
  213. return 0;
  214. buf = va_arg(ap,unsigned char*);
  215. len = va_arg(ap,int);
  216. nullpo_retr(0, src_bl = va_arg(ap,struct block_list*));
  217. type = va_arg(ap,int);
  218. switch(type) {
  219. case AREA_WOS:
  220. if (bl == src_bl)
  221. return 0;
  222. break;
  223. case AREA_WOC:
  224. if (sd->chatID || bl == src_bl)
  225. return 0;
  226. break;
  227. case AREA_WOSC:
  228. {
  229. struct map_session_data *ssd = (struct map_session_data *)src_bl;
  230. if (ssd && (src_bl->type == BL_PC) && sd->chatID && (sd->chatID == ssd->chatID))
  231. return 0;
  232. }
  233. break;
  234. }
  235. if (session[fd] != NULL) {
  236. WFIFOHEAD(fd, len);
  237. if (WFIFOP(fd,0) == buf) {
  238. printf("WARNING: Invalid use of clif_send function\n");
  239. printf(" Packet x%4x use a WFIFO of a player instead of to use a buffer.\n", WBUFW(buf,0));
  240. printf(" Please correct your code.\n");
  241. // don't send to not move the pointer of the packet for next sessions in the loop
  242. WFIFOSET(fd,0);//## TODO is this ok?
  243. } else {
  244. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  245. memcpy(WFIFOP(fd,0), buf, len);
  246. WFIFOSET(fd,len);
  247. }
  248. }
  249. }
  250. return 0;
  251. }
  252. /*==========================================
  253. *
  254. *------------------------------------------
  255. */
  256. int clif_send (const unsigned char *buf, int len, struct block_list *bl, int type) {
  257. int i;
  258. struct map_session_data *sd = NULL;
  259. struct party_data *p = NULL;
  260. struct guild *g = NULL;
  261. int x0 = 0, x1 = 0, y0 = 0, y1 = 0, fd;
  262. if (type != ALL_CLIENT &&
  263. type != CHAT_MAINCHAT) {
  264. nullpo_retr(0, bl);
  265. if (bl->type == BL_PC) {
  266. sd = (struct map_session_data *)bl;
  267. }
  268. }
  269. switch(type) {
  270. case ALL_CLIENT: //All player clients.
  271. for (i = 0; i < fd_max; i++) {
  272. if (session[i] && session[i]->func_parse == clif_parse &&
  273. (sd = (struct map_session_data *)session[i]->session_data) != NULL&&
  274. sd->state.auth) {
  275. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  276. WFIFOHEAD(i, len);
  277. memcpy(WFIFOP(i,0), buf, len);
  278. WFIFOSET(i,len);
  279. }
  280. }
  281. }
  282. break;
  283. case ALL_SAMEMAP: //All players on the same map
  284. for(i = 0; i < fd_max; i++) {
  285. if (session[i] && session[i]->func_parse == clif_parse &&
  286. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  287. sd->state.auth && sd->bl.m == bl->m) {
  288. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  289. WFIFOHEAD(i,len);
  290. memcpy(WFIFOP(i,0), buf, len);
  291. WFIFOSET(i,len);
  292. }
  293. }
  294. }
  295. break;
  296. case AREA:
  297. case AREA_WOSC:
  298. if (sd && bl->prev == NULL) //Otherwise source misses the packet.[Skotlex]
  299. clif_send (buf, len, bl, SELF);
  300. case AREA_WOC:
  301. case AREA_WOS:
  302. map_foreachinarea(clif_send_sub, bl->m, bl->x-AREA_SIZE, bl->y-AREA_SIZE, bl->x+AREA_SIZE, bl->y+AREA_SIZE,
  303. BL_PC, buf, len, bl, type);
  304. break;
  305. case AREA_CHAT_WOC:
  306. map_foreachinarea(clif_send_sub, bl->m, bl->x-(AREA_SIZE-5), bl->y-(AREA_SIZE-5),
  307. bl->x+(AREA_SIZE-5), bl->y+(AREA_SIZE-5), BL_PC, buf, len, bl, AREA_WOC);
  308. break;
  309. case CHAT:
  310. case CHAT_WOS:
  311. {
  312. struct chat_data *cd;
  313. if (sd) {
  314. cd = (struct chat_data*)map_id2bl(sd->chatID);
  315. } else if (bl->type == BL_CHAT) {
  316. cd = (struct chat_data*)bl;
  317. } else break;
  318. if (cd == NULL)
  319. break;
  320. for(i = 0; i < cd->users; i++) {
  321. if (type == CHAT_WOS && cd->usersd[i] == sd)
  322. continue;
  323. if (packet_db[cd->usersd[i]->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  324. if ((fd=cd->usersd[i]->fd) >0 && session[fd]) // Added check to see if session exists [PoW]
  325. {
  326. WFIFOHEAD(fd,len);
  327. memcpy(WFIFOP(fd,0), buf, len);
  328. WFIFOSET(fd,len);
  329. }
  330. }
  331. }
  332. }
  333. break;
  334. case CHAT_MAINCHAT: //[LuzZza]
  335. for(i=1; i<fd_max; i++) {
  336. if (session[i] && session[i]->func_parse == clif_parse &&
  337. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  338. sd->state.mainchat && (fd=sd->fd))
  339. {
  340. WFIFOHEAD(fd,len);
  341. memcpy(WFIFOP(fd,0), buf, len);
  342. WFIFOSET(fd, len);
  343. }
  344. }
  345. break;
  346. case PARTY_AREA:
  347. case PARTY_AREA_WOS:
  348. x0 = bl->x - AREA_SIZE;
  349. y0 = bl->y - AREA_SIZE;
  350. x1 = bl->x + AREA_SIZE;
  351. y1 = bl->y + AREA_SIZE;
  352. case PARTY:
  353. case PARTY_WOS:
  354. case PARTY_SAMEMAP:
  355. case PARTY_SAMEMAP_WOS:
  356. if (sd && sd->status.party_id)
  357. p = party_search(sd->status.party_id);
  358. if (p) {
  359. for(i=0;i<MAX_PARTY;i++){
  360. if ((sd = p->data[i].sd) == NULL)
  361. continue;
  362. if (!(fd=sd->fd) || session[fd] == NULL || sd->state.auth == 0
  363. || session[fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  364. continue;
  365. if (sd->bl.id == bl->id && (type == PARTY_WOS || type == PARTY_SAMEMAP_WOS || type == PARTY_AREA_WOS))
  366. continue;
  367. if (type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m)
  368. continue;
  369. if ((type == PARTY_AREA || type == PARTY_AREA_WOS) &&
  370. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  371. continue;
  372. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  373. WFIFOHEAD(fd,len);
  374. memcpy(WFIFOP(fd,0), buf, len);
  375. WFIFOSET(fd,len);
  376. }
  377. }
  378. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  379. break;
  380. for (i = 1; i < fd_max; i++){ // partyspy [Syrus22]
  381. if (session[i] && session[i]->func_parse == clif_parse &&
  382. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  383. sd->state.auth && (fd=sd->fd) && sd->partyspy == p->party.party_id)
  384. {
  385. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  386. WFIFOHEAD(fd,len);
  387. memcpy(WFIFOP(fd,0), buf, len);
  388. WFIFOSET(fd,len);
  389. }
  390. }
  391. }
  392. }
  393. break;
  394. case DUEL:
  395. case DUEL_WOS:
  396. if (!sd || !sd->duel_group) break; //Invalid usage.
  397. x0 = sd->duel_group; //Here we use x0 to store the duel group. [Skotlex]
  398. for (i = 0; i < fd_max; i++) {
  399. if (session[i] && session[i]->func_parse == clif_parse &&
  400. (sd = (struct map_session_data *)session[i]->session_data) != NULL &&
  401. sd->state.auth && sd->duel_group == x0) {
  402. if (type == DUEL_WOS && bl->id == sd->bl.id)
  403. continue;
  404. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) {
  405. WFIFOHEAD(i, len);
  406. memcpy(WFIFOP(i,0), buf, len);
  407. WFIFOSET(i,len);
  408. }
  409. }
  410. }
  411. break;
  412. case SELF:
  413. if (sd && (fd=sd->fd) && packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  414. WFIFOHEAD(fd,len);
  415. memcpy(WFIFOP(fd,0), buf, len);
  416. WFIFOSET(fd,len);
  417. }
  418. break;
  419. // New definitions for guilds [Valaris] - Cleaned up and reorganized by [Skotlex]
  420. case GUILD_AREA:
  421. case GUILD_AREA_WOS:
  422. x0 = bl->x - AREA_SIZE;
  423. y0 = bl->y - AREA_SIZE;
  424. x1 = bl->x + AREA_SIZE;
  425. y1 = bl->y + AREA_SIZE;
  426. case GUILD_SAMEMAP:
  427. case GUILD_SAMEMAP_WOS:
  428. case GUILD:
  429. case GUILD_WOS:
  430. if (sd && sd->status.guild_id)
  431. g = guild_search(sd->status.guild_id);
  432. if (g) {
  433. for(i = 0; i < g->max_member; i++) {
  434. if ((sd = g->member[i].sd) != NULL) {
  435. if (!(fd=sd->fd) || session[fd] == NULL || sd->state.auth == 0
  436. || session[fd]->session_data == NULL || sd->packet_ver > MAX_PACKET_VER)
  437. continue;
  438. if (sd->bl.id == bl->id && (type == GUILD_WOS || type == GUILD_SAMEMAP_WOS || type == GUILD_AREA_WOS))
  439. continue;
  440. if (type != GUILD && type != GUILD_WOS && sd->bl.m != bl->m)
  441. continue;
  442. if ((type == GUILD_AREA || type == GUILD_AREA_WOS) &&
  443. (sd->bl.x < x0 || sd->bl.y < y0 || sd->bl.x > x1 || sd->bl.y > y1))
  444. continue;
  445. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  446. WFIFOHEAD(fd,len);
  447. memcpy(WFIFOP(fd,0), buf, len);
  448. WFIFOSET(fd,len);
  449. }
  450. }
  451. }
  452. if (!enable_spy) //Skip unnecessary parsing. [Skotlex]
  453. break;
  454. for (i = 1; i < fd_max; i++){ // guildspy [Syrus22]
  455. if (session[i] && session[i]->func_parse == clif_parse &&
  456. (sd = (struct map_session_data*)session[i]->session_data) != NULL &&
  457. sd->state.auth && (fd=sd->fd) && sd->guildspy == g->guild_id) {
  458. if (packet_db[sd->packet_ver][RBUFW(buf,0)].len) { // packet must exist for the client version
  459. WFIFOHEAD(fd,len);
  460. memcpy(WFIFOP(fd,0), buf, len);
  461. WFIFOSET(fd,len);
  462. }
  463. }
  464. }
  465. }
  466. break;
  467. /* End [Valaris] */
  468. default:
  469. if (battle_config.error_log)
  470. ShowError("clif_send: Unrecognized type %d\n",type);
  471. return -1;
  472. }
  473. return 0;
  474. }
  475. //
  476. // パケット作って送信
  477. //
  478. /*==========================================
  479. *
  480. *------------------------------------------
  481. */
  482. int clif_authok(struct map_session_data *sd) {
  483. int fd;
  484. if (!sd->fd)
  485. return 0;
  486. fd = sd->fd;
  487. WFIFOHEAD(fd, packet_len(0x73));
  488. WFIFOW(fd, 0) = 0x73;
  489. WFIFOL(fd, 2) = gettick();
  490. WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y, sd->ud.dir);
  491. WFIFOB(fd, 9) = 5; // ignored
  492. WFIFOB(fd,10) = 5; // ignored
  493. WFIFOSET(fd,packet_len(0x73));
  494. return 0;
  495. }
  496. /*==========================================
  497. * Authentication failed/disconnect client.
  498. *------------------------------------------
  499. * The client closes it's socket and displays a message according to type:
  500. * 1 - server closed -> MsgStringTable[4]
  501. * 2 - ID already logged in -> MsgStringTable[5]
  502. * 3 - timeout/too much lag -> MsgStringTable[241]
  503. * 4 - server full -> MsgStringTable[264]
  504. * 5 - underaged -> MsgStringTable[305]
  505. * 9 - too many connections from this ip -> MsgStringTable[529]
  506. * 10 - payed time has ended -> MsgStringTable[530]
  507. * 15 - disconnected by a GM -> if( servicetype == taiwan ) MsgStringTable[579]
  508. * other - disconnected -> MsgStringTable[3]
  509. */
  510. int clif_authfail_fd(int fd, int type) {
  511. if (!fd || !session[fd] || session[fd]->func_parse != clif_parse) //clif_authfail should only be invoked on players!
  512. return 0;
  513. WFIFOHEAD(fd, packet_len(0x81));
  514. WFIFOW(fd,0) = 0x81;
  515. WFIFOB(fd,2) = type;
  516. WFIFOSET(fd,packet_len(0x81));
  517. clif_setwaitclose(fd);
  518. return 0;
  519. }
  520. /*==========================================
  521. * Used to know which is the max valid account/char id [Skotlex]
  522. *------------------------------------------
  523. */
  524. void clif_updatemaxid(int account_id, int char_id)
  525. {
  526. max_account_id = account_id;
  527. max_char_id = char_id;
  528. }
  529. /*==========================================
  530. *
  531. *------------------------------------------
  532. */
  533. int clif_charselectok(int id) {
  534. struct map_session_data *sd;
  535. int fd;
  536. if ((sd = map_id2sd(id)) == NULL)
  537. return 1;
  538. if (!sd->fd)
  539. return 1;
  540. fd = sd->fd;
  541. WFIFOHEAD(fd, packet_len(0xb3));
  542. WFIFOW(fd,0) = 0xb3;
  543. WFIFOB(fd,2) = 1;
  544. WFIFOSET(fd,packet_len(0xb3));
  545. return 0;
  546. }
  547. /*==========================================
  548. *
  549. *------------------------------------------
  550. */
  551. static int clif_set009e(struct flooritem_data *fitem,unsigned char *buf) {
  552. int view;
  553. nullpo_retr(0, fitem);
  554. //009e <ID>.l <name ID>.w <identify flag>.B <X>.w <Y>.w <subX>.B <subY>.B <amount>.w
  555. WBUFW(buf, 0) = 0x9e;
  556. WBUFL(buf, 2) = fitem->bl.id;
  557. if ((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  558. WBUFW(buf, 6) = view;
  559. else
  560. WBUFW(buf, 6) = fitem->item_data.nameid;
  561. WBUFB(buf, 8) = fitem->item_data.identify;
  562. WBUFW(buf, 9) = fitem->bl.x;
  563. WBUFW(buf,11) = fitem->bl.y;
  564. WBUFB(buf,13) = fitem->subx;
  565. WBUFB(buf,14) = fitem->suby;
  566. WBUFW(buf,15) = fitem->item_data.amount;
  567. return packet_len(0x9e);
  568. }
  569. /*==========================================
  570. *
  571. *------------------------------------------
  572. */
  573. int clif_dropflooritem(struct flooritem_data *fitem) {
  574. unsigned char buf[64];
  575. nullpo_retr(0, fitem);
  576. if (fitem->item_data.nameid <= 0)
  577. return 0;
  578. clif_set009e(fitem, buf);
  579. clif_send(buf, packet_len(0x9e), &fitem->bl, AREA);
  580. return 0;
  581. }
  582. /*==========================================
  583. *
  584. *------------------------------------------
  585. */
  586. int clif_clearflooritem(struct flooritem_data *fitem, int fd) {
  587. unsigned char buf[16];
  588. nullpo_retr(0, fitem);
  589. WBUFW(buf,0) = 0xa1;
  590. WBUFL(buf,2) = fitem->bl.id;
  591. if (fd == 0) {
  592. clif_send(buf, packet_len(0xa1), &fitem->bl, AREA);
  593. } else {
  594. WFIFOHEAD(fd,packet_len(0xa1));
  595. memcpy(WFIFOP(fd,0), buf, 6);
  596. WFIFOSET(fd,packet_len(0xa1));
  597. }
  598. return 0;
  599. }
  600. /*==========================================
  601. *
  602. *------------------------------------------
  603. */
  604. int clif_clearchar(struct block_list *bl, int type) {
  605. unsigned char buf[16];
  606. nullpo_retr(0, bl);
  607. WBUFW(buf,0) = 0x80;
  608. WBUFL(buf,2) = bl->id;
  609. WBUFB(buf,6) = type;
  610. clif_send(buf, packet_len(0x80), bl, type == 1 ? AREA : AREA_WOS);
  611. if(disguised(bl)) {
  612. WBUFL(buf,2) = -bl->id;
  613. clif_send(buf, packet_len(0x80), bl, SELF);
  614. }
  615. return 0;
  616. }
  617. static int clif_clearchar_delay_sub(int tid, unsigned int tick, int id, int data) {
  618. struct block_list *bl = (struct block_list *)id;
  619. clif_clearchar(bl,data);
  620. aFree(bl);
  621. return 0;
  622. }
  623. int clif_clearchar_delay(unsigned int tick, struct block_list *bl, int type) {
  624. struct block_list *tbl;
  625. tbl = aMalloc(sizeof (struct block_list));
  626. memcpy (tbl, bl, sizeof (struct block_list));
  627. add_timer(tick, clif_clearchar_delay_sub, (int)tbl, type);
  628. return 0;
  629. }
  630. /*==========================================
  631. *
  632. *------------------------------------------
  633. */
  634. int clif_clearchar_id(int id, int type, int fd) {
  635. WFIFOHEAD(fd, packet_len(0x80));
  636. WFIFOW(fd,0) = 0x80;
  637. WFIFOL(fd,2) = id;
  638. WFIFOB(fd,6) = (char)type; // Why use int for a char in the first place?
  639. WFIFOSET(fd, packet_len(0x80));
  640. return 0;
  641. }
  642. void clif_get_weapon_view(TBL_PC* sd, unsigned short *rhand, unsigned short *lhand)
  643. {
  644. #if PACKETVER > 3
  645. struct item_data *id;
  646. #endif
  647. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  648. {
  649. *rhand = *lhand = 0;
  650. return;
  651. }
  652. #if PACKETVER < 4
  653. *rhand = sd->status.weapon;
  654. *lhand = sd->status.shield;
  655. #else
  656. if (sd->equip_index[EQI_HAND_R] >= 0 &&
  657. sd->inventory_data[sd->equip_index[EQI_HAND_R]])
  658. {
  659. id = sd->inventory_data[sd->equip_index[EQI_HAND_R]];
  660. if (id->view_id > 0)
  661. *rhand = id->view_id;
  662. else
  663. *rhand = id->nameid;
  664. } else
  665. *rhand = 0;
  666. if (sd->equip_index[EQI_HAND_L] >= 0 &&
  667. sd->equip_index[EQI_HAND_L] != sd->equip_index[EQI_HAND_R] &&
  668. sd->inventory_data[sd->equip_index[EQI_HAND_L]])
  669. {
  670. id = sd->inventory_data[sd->equip_index[EQI_HAND_L]];
  671. if (id->view_id > 0)
  672. *lhand = id->view_id;
  673. else
  674. *lhand = id->nameid;
  675. } else
  676. *lhand = 0;
  677. #endif
  678. }
  679. static void clif_get_guild_data(struct block_list *bl, long *guild_id, short *emblem_id)
  680. {
  681. //TODO: There has to be a way to clean this up.
  682. switch (bl->type) {
  683. case BL_PC:
  684. *guild_id = ((TBL_PC*)bl)->status.guild_id;
  685. *emblem_id = ((TBL_PC*)bl)->guild_emblem_id;
  686. break;
  687. case BL_MOB:
  688. if (((TBL_MOB*)bl)->guardian_data) {
  689. *guild_id =((TBL_MOB*)bl)->guardian_data->guild_id;
  690. *emblem_id =((TBL_MOB*)bl)->guardian_data->emblem_id;
  691. }
  692. break;
  693. case BL_NPC:
  694. if (bl->subtype == SCRIPT && ((TBL_NPC*)bl)->u.scr.guild_id > 0) {
  695. struct guild *g = guild_search(((TBL_NPC*)bl)->u.scr.guild_id);
  696. if (g) {
  697. *guild_id =g->guild_id;
  698. *emblem_id =g->emblem_id;
  699. }
  700. }
  701. break;
  702. default:
  703. *guild_id = status_get_guild_id(bl);
  704. }
  705. return;
  706. }
  707. /*==========================================
  708. *
  709. *------------------------------------------
  710. */
  711. static int clif_set0078(struct block_list *bl, struct view_data *vd, unsigned char *buf) {
  712. struct status_change *sc;
  713. struct map_session_data *sd;
  714. long guild_id=0;
  715. unsigned short emblem_id=0, lv;
  716. unsigned short dir;
  717. nullpo_retr(0, bl);
  718. BL_CAST(BL_PC, bl, sd);
  719. sc = status_get_sc(bl);
  720. clif_get_guild_data(bl, &guild_id, &emblem_id);
  721. dir = unit_getdir(bl);
  722. lv = status_get_lv(bl);
  723. if(pcdb_checkid(vd->class_)) {
  724. #if PACKETVER > 6
  725. memset(buf,0,packet_len(0x22a));
  726. WBUFW(buf,0)=0x22a;
  727. WBUFL(buf,2)=bl->id;
  728. WBUFW(buf,6)=status_get_speed(bl);
  729. if (sc) {
  730. WBUFW(buf,8)=sc->opt1;
  731. WBUFW(buf,10)=sc->opt2;
  732. WBUFL(buf,12)=sc->option;
  733. WBUFL(buf,44)=sc->opt3;
  734. }
  735. WBUFW(buf,16)=vd->class_;
  736. WBUFW(buf,18)=vd->hair_style;
  737. WBUFW(buf,20)=vd->weapon;
  738. WBUFW(buf,22)=vd->shield;
  739. WBUFW(buf,24)=vd->head_bottom;
  740. WBUFW(buf,26)=vd->head_top;
  741. WBUFW(buf,28)=vd->head_mid;
  742. WBUFW(buf,30)=vd->hair_color;
  743. WBUFW(buf,32)=vd->cloth_color;
  744. WBUFW(buf,34)=sd?sd->head_dir:0;
  745. WBUFL(buf,36)=guild_id;
  746. WBUFW(buf,40)=emblem_id;
  747. if (sd) {
  748. WBUFW(buf,42)=sd->status.manner;
  749. WBUFB(buf,48)=sd->status.karma;
  750. }
  751. WBUFB(buf,49)=vd->sex;
  752. WBUFPOS(buf,50,bl->x,bl->y,dir);
  753. WBUFB(buf,53)=5;
  754. WBUFB(buf,54)=5;
  755. WBUFB(buf,55)=vd->dead_sit;
  756. WBUFW(buf,56)=clif_setlevel(lv);
  757. return packet_len(0x22a);
  758. #elif PACKETVER > 3
  759. memset(buf,0,packet_len(0x1d8));
  760. WBUFW(buf,0)=0x1d8;
  761. WBUFL(buf,2)=bl->id;
  762. WBUFW(buf,6)=status_get_speed(bl);
  763. if (sc) {
  764. WBUFW(buf,8)=sc->opt1;
  765. WBUFW(buf,10)=sc->opt2;
  766. WBUFW(buf,12)=sc->option;
  767. WBUFW(buf,42)=sc->opt3;
  768. }
  769. WBUFW(buf,14)=vd->class_;
  770. WBUFW(buf,16)=vd->hair_style;
  771. WBUFW(buf,18)=vd->weapon;
  772. WBUFW(buf,20)=vd->shield;
  773. WBUFW(buf,22)=vd->head_bottom;
  774. WBUFW(buf,24)=vd->head_top;
  775. WBUFW(buf,26)=vd->head_mid;
  776. WBUFW(buf,28)=vd->hair_color;
  777. WBUFW(buf,30)=vd->cloth_color;
  778. WBUFW(buf,32)=sd?sd->head_dir:0;
  779. WBUFL(buf,34)=guild_id;
  780. WBUFW(buf,38)=emblem_id;
  781. if (sd) {
  782. WBUFW(buf,40)=sd->status.manner;
  783. WBUFB(buf,44)=sd->status.karma;
  784. }
  785. WBUFB(buf,45)=vd->sex;
  786. WBUFPOS(buf,46,bl->x,bl->y,dir);
  787. WBUFB(buf,49)=5;
  788. WBUFB(buf,50)=5;
  789. WBUFB(buf,51)=vd->dead_sit;
  790. WBUFW(buf,52)=clif_setlevel(lv);
  791. return packet_len(0x1d8);
  792. #else
  793. memset(buf,0,packet_len(0x78));
  794. WBUFW(buf,0)=0x78;
  795. WBUFL(buf,2)=bl->id;
  796. WBUFW(buf,6)=status_get_speed(bl);
  797. if (sc) {
  798. WBUFW(buf,8)=sc->opt1;
  799. WBUFW(buf,10)=sc->opt2;
  800. WBUFW(buf,12)=sc->option;
  801. WBUFW(buf,42)=sc->opt3;
  802. }
  803. WBUFW(buf,14)=vd->class_;
  804. WBUFW(buf,16)=vd->hair_style;
  805. WBUFW(buf,18)=vd->weapon;
  806. WBUFW(buf,20)=vd->head_bottom;
  807. WBUFW(buf,22)=vd->shield;
  808. WBUFW(buf,24)=vd->head_top;
  809. WBUFW(buf,26)=vd->head_mid;
  810. WBUFW(buf,28)=vd->hair_color;
  811. WBUFW(buf,30)=vd->cloth_color;
  812. WBUFW(buf,32)=sd?sd->head_dir:0;
  813. WBUFL(buf,34)=guild_id;
  814. WBUFL(buf,38)=emblem_id;
  815. if (sd)
  816. WBUFB(buf,44)=sd->status.karma;
  817. WBUFB(buf,45)=vd->sex;
  818. WBUFPOS(buf,46,bl->x,bl->y,dir);
  819. WBUFB(buf,49)=5;
  820. WBUFB(buf,50)=5;
  821. WBUFB(buf,51)=vd->dead_sit;
  822. WBUFW(buf,52)=clif_setlevel(lv);
  823. return packet_len(0x78);
  824. #endif
  825. }
  826. //Non-player sprites need just a few fields filled.
  827. memset(buf,0,packet_len(0x78));
  828. WBUFW(buf,0)=0x78;
  829. WBUFL(buf,2)=bl->id;
  830. WBUFW(buf,6)=status_get_speed(bl);
  831. if (sc) {
  832. WBUFW(buf,8)=sc->opt1;
  833. WBUFW(buf,10)=sc->opt2;
  834. WBUFW(buf,12)=sc->option;
  835. WBUFW(buf,42)=sc->opt3;
  836. }
  837. WBUFW(buf,14)=vd->class_;
  838. WBUFW(buf,16)=vd->hair_style; //Required for pets.
  839. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  840. if (bl->type == BL_NPC && vd->class_ == FLAG_CLASS)
  841. { //The hell, why flags work like this?
  842. WBUFL(buf,22)=emblem_id;
  843. WBUFL(buf,26)=guild_id;
  844. }
  845. WBUFW(buf,32)=dir;
  846. WBUFL(buf,34)=guild_id;
  847. WBUFL(buf,38)=emblem_id;
  848. WBUFPOS(buf,46,bl->x,bl->y,dir);
  849. WBUFB(buf,49)=5;
  850. WBUFB(buf,50)=5;
  851. WBUFW(buf,52)=clif_setlevel(lv);
  852. return packet_len(0x78);
  853. }
  854. /*==========================================
  855. *
  856. *------------------------------------------
  857. */
  858. static int clif_set007b(struct block_list *bl, struct view_data *vd, struct unit_data *ud, unsigned char *buf) {
  859. struct status_change *sc;
  860. struct map_session_data *sd;
  861. long guild_id=0;
  862. unsigned short emblem_id=0, lv;
  863. nullpo_retr(0, bl);
  864. BL_CAST(BL_PC, bl, sd);
  865. sc = status_get_sc(bl);
  866. clif_get_guild_data(bl, &guild_id, &emblem_id);
  867. lv = status_get_lv(bl);
  868. if(pcdb_checkid(vd->class_)) {
  869. #if PACKETVER > 6
  870. memset(buf,0,packet_len(0x22c));
  871. WBUFW(buf,0)=0x22c;
  872. WBUFL(buf,2)=bl->id;
  873. WBUFW(buf,6)=status_get_speed(bl);
  874. if (sc) {
  875. WBUFW(buf,8)= sc->opt1;
  876. WBUFW(buf,10)= sc->opt2;
  877. WBUFL(buf,12)= sc->option;
  878. WBUFL(buf,48)= sc->opt3;
  879. }
  880. WBUFW(buf,16)=vd->class_;
  881. WBUFW(buf,18)=vd->hair_style;
  882. WBUFW(buf,20)=vd->weapon;
  883. WBUFW(buf,22)=vd->shield;
  884. WBUFW(buf,24)=vd->head_bottom;
  885. WBUFL(buf,26)=gettick();
  886. WBUFW(buf,30)=vd->head_top;
  887. WBUFW(buf,32)=vd->head_mid;
  888. WBUFW(buf,34)=vd->hair_color;
  889. WBUFW(buf,36)=vd->cloth_color;
  890. WBUFW(buf,38)=sd?sd->head_dir:0;
  891. WBUFL(buf,40)=guild_id;
  892. WBUFW(buf,44)=emblem_id;
  893. if (sd) {
  894. WBUFW(buf,46)=sd->status.manner;
  895. WBUFB(buf,52)=sd->status.karma;
  896. }
  897. WBUFB(buf,53)=vd->sex;
  898. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  899. WBUFB(buf,60)=0;
  900. WBUFB(buf,61)=0;
  901. WBUFW(buf,62)=clif_setlevel(lv);
  902. return packet_len(0x22c);
  903. #elif PACKETVER > 3
  904. memset(buf,0,packet_len(0x1da));
  905. WBUFW(buf,0)=0x1da;
  906. WBUFL(buf,2)=bl->id;
  907. WBUFW(buf,6)=status_get_speed(bl);
  908. if (sc) {
  909. WBUFW(buf,8)=sc->opt1;
  910. WBUFW(buf,10)=sc->opt2;
  911. WBUFW(buf,12)=sc->option;
  912. WBUFW(buf,46)=sc->opt3;
  913. }
  914. WBUFW(buf,14)=vd->class_;
  915. WBUFW(buf,16)=vd->hair_style;
  916. WBUFW(buf,18)=vd->weapon;
  917. WBUFW(buf,20)=vd->shield;
  918. WBUFW(buf,22)=vd->head_bottom;
  919. WBUFL(buf,24)=gettick();
  920. WBUFW(buf,28)=vd->head_top;
  921. WBUFW(buf,30)=vd->head_mid;
  922. WBUFW(buf,32)=vd->hair_color;
  923. WBUFW(buf,34)=vd->cloth_color;
  924. WBUFW(buf,36)=sd?sd->head_dir:0;
  925. WBUFL(buf,38)=guild_id;
  926. WBUFW(buf,42)=emblem_id;
  927. if (sd) {
  928. WBUFW(buf,44)=sd->status.manner;
  929. WBUFB(buf,48)=sd->status.karma;
  930. }
  931. WBUFB(buf,49)=vd->sex;
  932. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  933. WBUFB(buf,56)=5;
  934. WBUFB(buf,57)=5;
  935. WBUFW(buf,58)=clif_setlevel(lv);
  936. return packet_len(0x1da);
  937. #else
  938. memset(buf,0,packet_len(0x7b));
  939. WBUFW(buf,0)=0x7b;
  940. WBUFL(buf,2)=bl->id;
  941. WBUFW(buf,6)=status_get_speed(bl);
  942. if (sc) {
  943. WBUFW(buf,8)=sc->opt1;
  944. WBUFW(buf,10)=sc->opt2;
  945. WBUFW(buf,12)=sc->option;
  946. WBUFW(buf,46)=sc->opt3;
  947. }
  948. WBUFW(buf,14)=vd->class_;
  949. WBUFW(buf,16)=vd->hair_style;
  950. WBUFW(buf,18)=vd->weapon;
  951. WBUFW(buf,20)=vd->head_bottom;
  952. WBUFL(buf,22)=gettick();
  953. WBUFW(buf,26)=vd->shield;
  954. WBUFW(buf,28)=vd->head_top;
  955. WBUFW(buf,30)=vd->head_mid;
  956. WBUFW(buf,32)=vd->hair_color;
  957. WBUFW(buf,34)=vd->cloth_color;
  958. WBUFW(buf,36)=sd?sd->head_dir:0;
  959. WBUFL(buf,38)=guild_id;
  960. WBUFL(buf,42)=emblem_id;
  961. if (sd)
  962. WBUFB(buf,48)=sd->status.karma;
  963. WBUFB(buf,49)=vd->sex;
  964. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  965. WBUFB(buf,56)=5;
  966. WBUFB(buf,57)=5;
  967. WBUFW(buf,58)=clif_setlevel(lv);
  968. return packet_len(0x7b);
  969. #endif
  970. }
  971. //Non-player sprites only require a few fields.
  972. #if PACKETVER > 6
  973. memset(buf,0,packet_len(0x22c));
  974. WBUFW(buf,0)=0x22c;
  975. WBUFL(buf,2)=bl->id;
  976. WBUFW(buf,6)=status_get_speed(bl);
  977. if (sc) {
  978. WBUFW(buf,8)=sc->opt1;
  979. WBUFW(buf,10)=sc->opt2;
  980. WBUFL(buf,12)=sc->option;
  981. WBUFL(buf,48)=sc->opt3;
  982. }
  983. WBUFW(buf,16)=vd->class_;
  984. WBUFW(buf,18)=vd->hair_style; //For pets
  985. WBUFW(buf,24)=vd->head_bottom; //Pet armor
  986. WBUFL(buf,26)=gettick();
  987. WBUFW(buf,38)=unit_getdir(bl);
  988. WBUFL(buf,40)=guild_id;
  989. WBUFL(buf,44)=emblem_id;
  990. WBUFPOS2(buf,54,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  991. WBUFB(buf,60)=0;
  992. WBUFB(buf,61)=0;
  993. WBUFW(buf,62)=clif_setlevel(lv);
  994. return packet_len(0x22c);
  995. #else
  996. memset(buf,0,packet_len(0x7b));
  997. WBUFW(buf,0)=0x7b;
  998. WBUFL(buf,2)=bl->id;
  999. WBUFW(buf,6)=status_get_speed(bl);
  1000. if (sc) {
  1001. WBUFW(buf,8)=sc->opt1;
  1002. WBUFW(buf,10)=sc->opt2;
  1003. WBUFW(buf,12)=sc->option;
  1004. WBUFW(buf,46)=sc->opt3;
  1005. }
  1006. WBUFW(buf,14)=vd->class_;
  1007. WBUFW(buf,16)=vd->hair_style; //For pets
  1008. WBUFW(buf,20)=vd->head_bottom; //Pet armor
  1009. WBUFL(buf,22)=gettick();
  1010. WBUFW(buf,36)=unit_getdir(bl);
  1011. WBUFL(buf,38)=guild_id;
  1012. WBUFL(buf,42)=emblem_id;
  1013. WBUFPOS2(buf,50,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1014. WBUFB(buf,56)=5;
  1015. WBUFB(buf,57)=5;
  1016. WBUFW(buf,58)=clif_setlevel(lv);
  1017. return packet_len(0x7b);
  1018. #endif
  1019. }
  1020. //Modifies the buffer for disguise characters and sends it to self.
  1021. //Flag = 0: change id to negative, buf will have disguise data.
  1022. //Flag = 1: change id to positive, class and option to make your own char invisible.
  1023. //Luckily, the offsets that need to be changed are the same in packets 0x78, 0x7b, 0x1d8 and 0x1da
  1024. //But no longer holds true for those packet of PACKETVER 7.
  1025. static void clif_setdisguise(struct map_session_data *sd, unsigned char *buf,int len, int flag) {
  1026. if (flag) {
  1027. #if PACKETVER > 6
  1028. switch (WBUFW(buf,0)) {
  1029. case 0x22c:
  1030. case 0x22b:
  1031. case 0x22a:
  1032. WBUFL(buf,12)=OPTION_INVISIBLE;
  1033. WBUFW(buf,16)=sd->status.class_;
  1034. break;
  1035. default:
  1036. #endif
  1037. WBUFL(buf,2)=sd->bl.id;
  1038. WBUFW(buf,12)=OPTION_INVISIBLE;
  1039. WBUFW(buf,14)=sd->status.class_;
  1040. #if PACKETVER > 6
  1041. break;
  1042. }
  1043. #endif
  1044. } else {
  1045. WBUFL(buf,2)=-sd->bl.id;
  1046. }
  1047. clif_send(buf, len, &sd->bl, SELF);
  1048. }
  1049. /*==========================================
  1050. * クラスチェンジ typeはMobの場合は1で他は0?
  1051. *------------------------------------------
  1052. */
  1053. int clif_class_change(struct block_list *bl,int class_,int type)
  1054. {
  1055. unsigned char buf[16];
  1056. nullpo_retr(0, bl);
  1057. if(!pcdb_checkid(class_)) {
  1058. WBUFW(buf,0)=0x1b0;
  1059. WBUFL(buf,2)=bl->id;
  1060. WBUFB(buf,6)=type;
  1061. WBUFL(buf,7)=class_;
  1062. clif_send(buf,packet_len(0x1b0),bl,AREA);
  1063. }
  1064. return 0;
  1065. }
  1066. /*==========================================
  1067. *
  1068. *------------------------------------------
  1069. */
  1070. static void clif_spiritball_single(int fd, struct map_session_data *sd)
  1071. {
  1072. WFIFOHEAD(fd, packet_len(0x1e1));
  1073. WFIFOW(fd,0)=0x1e1;
  1074. WFIFOL(fd,2)=sd->bl.id;
  1075. WFIFOW(fd,6)=sd->spiritball;
  1076. WFIFOSET(fd, packet_len(0x1e1));
  1077. }
  1078. /*==========================================
  1079. *
  1080. *------------------------------------------
  1081. */
  1082. static int clif_set0192(int fd, int m, int x, int y, int type) {
  1083. WFIFOHEAD(fd, packet_len(0x192));
  1084. WFIFOW(fd,0) = 0x192;
  1085. WFIFOW(fd,2) = x;
  1086. WFIFOW(fd,4) = y;
  1087. WFIFOW(fd,6) = type;
  1088. memcpy(WFIFOP(fd,8),map[m].name,MAP_NAME_LENGTH);
  1089. WFIFOSET(fd,packet_len(0x192));
  1090. return 0;
  1091. }
  1092. // new and improved weather display [Valaris]
  1093. static void clif_weather_sub(int fd, int id, int type) {
  1094. WFIFOHEAD(fd, packet_len(0x1f3));
  1095. WFIFOW(fd,0) = 0x1f3;
  1096. WFIFOL(fd,2) = id;
  1097. WFIFOL(fd,6) = type;
  1098. WFIFOSET(fd,packet_len(0x1f3));
  1099. }
  1100. /*==========================================
  1101. *
  1102. *------------------------------------------
  1103. */
  1104. static void clif_weather_check(struct map_session_data *sd) {
  1105. int m = sd->bl.m, fd = sd->fd;
  1106. if (map[m].flag.snow
  1107. || map[m].flag.clouds
  1108. || map[m].flag.fog
  1109. || map[m].flag.fireworks
  1110. || map[m].flag.sakura
  1111. || map[m].flag.leaves
  1112. || map[m].flag.rain
  1113. || map[m].flag.clouds2)
  1114. {
  1115. if (map[m].flag.snow)
  1116. clif_weather_sub(fd, sd->bl.id, 162);
  1117. if (map[m].flag.clouds)
  1118. clif_weather_sub(fd, sd->bl.id, 233);
  1119. if (map[m].flag.clouds2)
  1120. clif_weather_sub(fd, sd->bl.id, 516);
  1121. if (map[m].flag.fog)
  1122. clif_weather_sub(fd, sd->bl.id, 515);
  1123. if (map[m].flag.fireworks) {
  1124. clif_weather_sub(fd, sd->bl.id, 297);
  1125. clif_weather_sub(fd, sd->bl.id, 299);
  1126. clif_weather_sub(fd, sd->bl.id, 301);
  1127. }
  1128. if (map[m].flag.sakura)
  1129. clif_weather_sub(fd, sd->bl.id, 163);
  1130. if (map[m].flag.leaves)
  1131. clif_weather_sub(fd, sd->bl.id, 333);
  1132. if (map[m].flag.rain)
  1133. clif_weather_sub(fd, sd->bl.id, 161);
  1134. }
  1135. }
  1136. int clif_weather(int m) {
  1137. int i;
  1138. struct map_session_data *sd=NULL;
  1139. for(i = 0; i < fd_max; i++) {
  1140. if (session[i] && session[i]->func_parse == clif_parse &&
  1141. (sd = session[i]->session_data) != NULL &&
  1142. sd->state.auth && sd->bl.m == m) {
  1143. clif_weather_check(sd);
  1144. }
  1145. }
  1146. return 0;
  1147. }
  1148. int clif_spawn(struct block_list *bl)
  1149. {
  1150. unsigned char buf[128];
  1151. struct view_data *vd;
  1152. nullpo_retr(0, bl);
  1153. vd = status_get_viewdata(bl);
  1154. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1155. return 0;
  1156. if (pcdb_checkid(vd->class_))
  1157. { //Player spawn packet.
  1158. clif_set0078(bl, vd, buf);
  1159. switch(WBUFW(buf,0)) {
  1160. case 0x78: //Convert to 0x79
  1161. WBUFW(buf, 0) = 0x79;
  1162. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1163. clif_send(buf, packet_len(0x79), bl, AREA_WOS);
  1164. if (disguised(bl))
  1165. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x79), 0);
  1166. break;
  1167. #if PACKETVER > 3
  1168. case 0x1d8: //Convert to 0x1d9
  1169. WBUFW(buf, 0) = 0x1d9;
  1170. WBUFW(buf,51) = WBUFW(buf,52); //Lv is placed on offset 52
  1171. clif_send(buf, packet_len(0x1d9), bl, AREA_WOS);
  1172. if (disguised(bl))
  1173. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x1d9), 0);
  1174. break;
  1175. #endif
  1176. #if PACKETVER > 6
  1177. case 0x22a: //Convert to 0x22b
  1178. WBUFW(buf, 0) = 0x22b;
  1179. WBUFW(buf,55) = WBUFW(buf,56); //Lv is placed on offset 56
  1180. clif_send(buf, packet_len(0x22b), bl, AREA_WOS);
  1181. if (disguised(bl))
  1182. clif_setdisguise((TBL_PC*)bl, buf, packet_len(0x22b), 0);
  1183. break;
  1184. #endif
  1185. }
  1186. } else { //Mob spawn packet.
  1187. struct status_change *sc = status_get_sc(bl);
  1188. memset(buf,0,sizeof(buf));
  1189. WBUFW(buf,0)=0x7c;
  1190. WBUFL(buf,2)=bl->id;
  1191. WBUFW(buf,6)=status_get_speed(bl);
  1192. if (sc) {
  1193. WBUFW(buf,8)=sc->opt1;
  1194. WBUFW(buf,10)=sc->opt2;
  1195. WBUFW(buf,12)=sc->option;
  1196. }
  1197. WBUFW(buf,20)=vd->class_;
  1198. WBUFW(buf,22)=vd->hair_style; //Required for pets.
  1199. WBUFW(buf,24)=vd->head_bottom; //Pet armor
  1200. WBUFPOS(buf,36,bl->x,bl->y,unit_getdir(bl));
  1201. clif_send(buf,packet_len(0x7c),bl,AREA_WOS);
  1202. if (disguised(bl)) {
  1203. WBUFL(buf,2)=-bl->id;
  1204. clif_send(buf,packet_len(0x7c),bl,SELF);
  1205. }
  1206. }
  1207. if (vd->cloth_color)
  1208. clif_refreshlook(bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,AREA_WOS);
  1209. switch (bl->type)
  1210. {
  1211. case BL_PC:
  1212. {
  1213. TBL_PC *sd = ((TBL_PC*)bl);
  1214. if (sd->spiritball > 0)
  1215. clif_spiritball(sd);
  1216. if(sd->state.size==2) // tiny/big players [Valaris]
  1217. clif_specialeffect(bl,423,AREA);
  1218. else if(sd->state.size==1)
  1219. clif_specialeffect(bl,421,AREA);
  1220. }
  1221. break;
  1222. case BL_MOB:
  1223. {
  1224. TBL_MOB *md = ((TBL_MOB*)bl);
  1225. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  1226. clif_specialeffect(&md->bl,423,AREA);
  1227. else if(md->special_state.size==1)
  1228. clif_specialeffect(&md->bl,421,AREA);
  1229. }
  1230. break;
  1231. }
  1232. return 0;
  1233. }
  1234. //[orn]
  1235. int clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
  1236. {
  1237. struct status_data *status;
  1238. unsigned char buf[128];
  1239. nullpo_retr(0, hd);
  1240. status = &hd->battle_status;
  1241. memset(buf,0,packet_len(0x22e));
  1242. WBUFW(buf,0)=0x22e;
  1243. memcpy(WBUFP(buf,2),hd->homunculus.name,NAME_LENGTH);
  1244. // Bit field, bit 0 : rename_flag (1 = already renamed), bit 1 : homunc vaporized (1 = true), bit 2 : homunc dead (1 = true)
  1245. WBUFB(buf,26)=(battle_config.hom_rename?0:hd->homunculus.rename_flag) | (hd->homunculus.vaporize << 1) | (hd->homunculus.hp?0:4);
  1246. WBUFW(buf,27)=hd->homunculus.level;
  1247. WBUFW(buf,29)=hd->homunculus.hunger;
  1248. WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
  1249. WBUFW(buf,33)=0; // equip id
  1250. WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, SHRT_MAX);
  1251. WBUFW(buf,37)=cap_value(status->matk_max, 0, SHRT_MAX);
  1252. WBUFW(buf,39)=status->hit;
  1253. if (battle_config.hom_setting&0x10)
  1254. WBUFW(buf,41)=status->luk/3 + 1; //crit is a +1 decimal value! Just display purpose.[Vicious]
  1255. else
  1256. WBUFW(buf,41)=status->cri/10;
  1257. WBUFW(buf,43)=status->def + status->vit ;
  1258. WBUFW(buf,45)=status->mdef;
  1259. WBUFW(buf,47)=status->flee;
  1260. WBUFW(buf,49)=(flag)?0:status->amotion;
  1261. if (status->max_hp > SHRT_MAX) {
  1262. WBUFW(buf,51) = status->hp/(status->max_hp/100);
  1263. WBUFW(buf,53) = 100;
  1264. } else {
  1265. WBUFW(buf,51)=status->hp;
  1266. WBUFW(buf,53)=status->max_hp;
  1267. }
  1268. if (status->max_sp > SHRT_MAX) {
  1269. WBUFW(buf,55) = status->sp/(status->max_sp/100);
  1270. WBUFW(buf,57) = 100;
  1271. } else {
  1272. WBUFW(buf,55)=status->sp;
  1273. WBUFW(buf,57)=status->max_sp;
  1274. }
  1275. WBUFL(buf,59)=hd->homunculus.exp;
  1276. WBUFL(buf,63)=hd->exp_next;
  1277. WBUFW(buf,67)=hd->homunculus.skillpts;
  1278. WBUFW(buf,69)=1; // FIXME: Attackable? When exactly is a homun not attackable? [Skotlex]
  1279. clif_send(buf,packet_len(0x22e),&sd->bl,SELF);
  1280. return 0;
  1281. }
  1282. void clif_send_homdata(struct map_session_data *sd, int type, int param) { //[orn]
  1283. int fd = sd->fd;
  1284. WFIFOHEAD(fd, packet_len(0x230));
  1285. nullpo_retv(sd->hd);
  1286. WFIFOW(fd,0)=0x230;
  1287. WFIFOW(fd,2)=type;
  1288. WFIFOL(fd,4)=sd->hd->bl.id;
  1289. WFIFOL(fd,8)=param;
  1290. WFIFOSET(fd,packet_len(0x230));
  1291. return;
  1292. }
  1293. int clif_homskillinfoblock(struct map_session_data *sd) { //[orn]
  1294. struct homun_data *hd;
  1295. int fd = sd->fd;
  1296. int i,j,len=4,id;
  1297. WFIFOHEAD(fd, 4+37*MAX_HOMUNSKILL);
  1298. hd = sd->hd;
  1299. if ( !hd )
  1300. return 0 ;
  1301. WFIFOW(fd,0)=0x235;
  1302. for ( i = 0; i < MAX_HOMUNSKILL; i++){
  1303. if( (id = hd->homunculus.hskill[i].id) != 0 ){
  1304. j = id - HM_SKILLBASE - 1 ;
  1305. WFIFOW(fd,len ) = id ;
  1306. WFIFOW(fd,len+2) = skill_get_inf(id) ;
  1307. WFIFOW(fd,len+4) = 0 ;
  1308. WFIFOW(fd,len+6) = hd->homunculus.hskill[j].lv ;
  1309. WFIFOW(fd,len+8) = skill_get_sp(id,hd->homunculus.hskill[j].lv) ;
  1310. WFIFOW(fd,len+10)= skill_get_range2(&sd->hd->bl, id,hd->homunculus.hskill[j].lv) ;
  1311. strncpy(WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH) ;
  1312. WFIFOB(fd,len+36) = (hd->homunculus.hskill[j].lv < merc_skill_tree_get_max(id, hd->homunculus.class_))?1:0;
  1313. len+=37;
  1314. }
  1315. }
  1316. WFIFOW(fd,2)=len;
  1317. WFIFOSET(fd,len);
  1318. return 0;
  1319. }
  1320. void clif_homskillup(struct map_session_data *sd, int skill_num) { //[orn]
  1321. struct homun_data *hd;
  1322. int fd=sd->fd, skillid;
  1323. WFIFOHEAD(fd, packet_len(0x239));
  1324. nullpo_retv(sd);
  1325. skillid = skill_num - HM_SKILLBASE - 1;
  1326. hd=sd->hd;
  1327. WFIFOW(fd,0) = 0x239;
  1328. WFIFOW(fd,2) = skill_num;
  1329. WFIFOW(fd,4) = hd->homunculus.hskill[skillid].lv;
  1330. WFIFOW(fd,6) = skill_get_sp(skill_num,hd->homunculus.hskill[skillid].lv);
  1331. WFIFOW(fd,8) = skill_get_range2(&hd->bl, skill_num,hd->homunculus.hskill[skillid].lv);
  1332. WFIFOB(fd,10) = (hd->homunculus.hskill[skillid].lv < skill_get_max(hd->homunculus.hskill[skillid].id)) ? 1 : 0;
  1333. WFIFOSET(fd,packet_len(0x239));
  1334. return;
  1335. }
  1336. int clif_hom_food(struct map_session_data *sd,int foodid,int fail) //[orn]
  1337. {
  1338. int fd=sd->fd;
  1339. WFIFOHEAD(fd,packet_len(0x22f));
  1340. WFIFOW(fd,0)=0x22f;
  1341. WFIFOB(fd,2)=fail;
  1342. WFIFOW(fd,3)=foodid;
  1343. WFIFOSET(fd,packet_len(0x22f));
  1344. return 0;
  1345. }
  1346. /*==========================================
  1347. *
  1348. *------------------------------------------
  1349. */
  1350. int clif_walkok(struct map_session_data *sd)
  1351. {
  1352. int fd=sd->fd;
  1353. WFIFOHEAD(fd, packet_len(0x87));
  1354. WFIFOW(fd,0)=0x87;
  1355. WFIFOL(fd,2)=gettick();
  1356. WFIFOPOS2(fd,6,sd->bl.x,sd->bl.y,sd->ud.to_x,sd->ud.to_y,8,8);
  1357. WFIFOSET(fd,packet_len(0x87));
  1358. return 0;
  1359. }
  1360. /// Move the unit (does nothing if the client has no info about the unit)
  1361. /// Note: unit must not be self
  1362. void clif_move(struct unit_data *ud)
  1363. {
  1364. unsigned char buf[16];
  1365. struct view_data* vd;
  1366. struct block_list* bl = ud->bl;
  1367. vd = status_get_viewdata(bl);
  1368. if (!vd || vd->class_ == INVISIBLE_CLASS)
  1369. return; //This performance check is needed to keep GM-hidden objects from being notified to bots.
  1370. WBUFW(buf,0)=0x86;
  1371. WBUFL(buf,2)=bl->id;
  1372. WBUFPOS2(buf,6,bl->x,bl->y,ud->to_x,ud->to_y,8,8);
  1373. WBUFL(buf,12)=gettick();
  1374. clif_send(buf, 16, bl, AREA_WOS);
  1375. if (disguised(bl))
  1376. clif_setdisguise((TBL_PC*)bl, buf, 16, 0);
  1377. }
  1378. /*==========================================
  1379. * Delays the map_quit of a player after they are disconnected. [Skotlex]
  1380. *------------------------------------------
  1381. */
  1382. static int clif_delayquit(int tid, unsigned int tick, int id, int data) {
  1383. struct map_session_data *sd = NULL;
  1384. //Remove player from map server
  1385. if ((sd = map_id2sd(id)) != NULL && sd->fd == 0) //Should be a disconnected player.
  1386. map_quit(sd);
  1387. return 0;
  1388. }
  1389. /*==========================================
  1390. *
  1391. *------------------------------------------
  1392. */
  1393. void clif_quitsave(int fd,struct map_session_data *sd)
  1394. {
  1395. if (sd->state.waitingdisconnect || //Was already waiting to be disconnected.
  1396. !battle_config.prevent_logout ||
  1397. DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  1398. map_quit(sd);
  1399. else if (sd->fd)
  1400. { //Disassociate session from player (session is deleted after this function was called)
  1401. //And set a timer to make him quit later.
  1402. session[sd->fd]->session_data = NULL;
  1403. sd->fd = 0;
  1404. add_timer(gettick() + 10000, clif_delayquit, sd->bl.id, 0);
  1405. }
  1406. }
  1407. /*==========================================
  1408. *
  1409. *------------------------------------------
  1410. */
  1411. static int clif_waitclose(int tid, unsigned int tick, int id, int data) {
  1412. if (session[id] && session[id]->func_parse == clif_parse) //Avoid disconnecting non-players, as pointed out by End of Exam [Skotlex]
  1413. session[id]->eof = 1;
  1414. return 0;
  1415. }
  1416. /*==========================================
  1417. *
  1418. *------------------------------------------
  1419. */
  1420. void clif_setwaitclose(int fd) {
  1421. struct map_session_data *sd;
  1422. // if player is not already in the game (double connection probably)
  1423. if ((sd = (struct map_session_data*)session[fd]->session_data) == NULL) {
  1424. // limited timer, just to send information.
  1425. add_timer(gettick() + 1000, clif_waitclose, fd, 0);
  1426. } else
  1427. add_timer(gettick() + 5000, clif_waitclose, fd, 0);
  1428. }
  1429. /*==========================================
  1430. *
  1431. *------------------------------------------
  1432. */
  1433. int clif_changemap(struct map_session_data *sd, short map, int x, int y) {
  1434. int fd;
  1435. char map_name[MAP_NAME_LENGTH];
  1436. nullpo_retr(0, sd);
  1437. fd = sd->fd;
  1438. snprintf(map_name, MAP_NAME_LENGTH, "%s.gat", mapindex_id2name(map));
  1439. WFIFOHEAD(fd, packet_len(0x91));
  1440. WFIFOW(fd,0) = 0x91;
  1441. memcpy(WFIFOP(fd,2), map_name, MAP_NAME_LENGTH);
  1442. WFIFOW(fd,18) = x;
  1443. WFIFOW(fd,20) = y;
  1444. WFIFOSET(fd, packet_len(0x91));
  1445. return 0;
  1446. }
  1447. /*==========================================
  1448. *
  1449. *------------------------------------------
  1450. */
  1451. int clif_changemapserver(struct map_session_data* sd, const char* mapname, int x, int y, int ip, int port) {
  1452. int fd;
  1453. nullpo_retr(0, sd);
  1454. fd = sd->fd;
  1455. WFIFOHEAD(fd, packet_len(0x92));
  1456. WFIFOW(fd,0) = 0x92;
  1457. //Better not trust the null-terminator is there. [Skotlex]
  1458. memcpy(WFIFOP(fd,2), mapname, MAP_NAME_LENGTH);
  1459. WFIFOB(fd,17) = 0; //Null terminator for mapname
  1460. WFIFOW(fd,18) = x;
  1461. WFIFOW(fd,20) = y;
  1462. WFIFOL(fd,22) = ip;
  1463. WFIFOW(fd,26) = port;
  1464. WFIFOSET(fd, packet_len(0x92));
  1465. return 0;
  1466. }
  1467. int clif_blown(struct block_list *bl) {
  1468. //Aegis packets says fixpos, but it's unsure whether slide works better or not.
  1469. // return clif_fixpos(bl);
  1470. return clif_slide(bl, bl->x, bl->y);
  1471. }
  1472. /*==========================================
  1473. *
  1474. *------------------------------------------
  1475. */
  1476. int clif_fixpos(struct block_list *bl) {
  1477. unsigned char buf[16];
  1478. nullpo_retr(0, bl);
  1479. WBUFW(buf,0)=0x88;
  1480. WBUFL(buf,2)=bl->id;
  1481. WBUFW(buf,6)=bl->x;
  1482. WBUFW(buf,8)=bl->y;
  1483. clif_send(buf, packet_len(0x88), bl, AREA);
  1484. if (disguised(bl)) {
  1485. WBUFL(buf,2)=-bl->id;
  1486. clif_send(buf, packet_len(0x88), bl, SELF);
  1487. }
  1488. return 0;
  1489. }
  1490. /*==========================================
  1491. *
  1492. *------------------------------------------
  1493. */
  1494. int clif_npcbuysell(struct map_session_data* sd, int id) {
  1495. int fd;
  1496. nullpo_retr(0, sd);
  1497. fd=sd->fd;
  1498. WFIFOHEAD(fd, packet_len(0xc4));
  1499. WFIFOW(fd,0)=0xc4;
  1500. WFIFOL(fd,2)=id;
  1501. WFIFOSET(fd,packet_len(0xc4));
  1502. return 0;
  1503. }
  1504. /*==========================================
  1505. *
  1506. *------------------------------------------
  1507. */
  1508. int clif_buylist(struct map_session_data *sd, struct npc_data *nd) {
  1509. struct item_data *id;
  1510. int fd,i,val;
  1511. nullpo_retr(0, sd);
  1512. nullpo_retr(0, nd);
  1513. fd=sd->fd;
  1514. WFIFOHEAD(fd, 200 * 11 + 4);
  1515. WFIFOW(fd,0)=0xc6;
  1516. for(i=0;nd->u.shop_item[i].nameid > 0;i++){
  1517. id = itemdb_search(nd->u.shop_item[i].nameid);
  1518. val=nd->u.shop_item[i].value;
  1519. WFIFOL(fd,4+i*11)=val;
  1520. if (!id->flag.value_notdc)
  1521. val=pc_modifybuyvalue(sd,val);
  1522. WFIFOL(fd,8+i*11)=val;
  1523. WFIFOB(fd,12+i*11)=itemtype(id->type);
  1524. if (id->view_id > 0)
  1525. WFIFOW(fd,13+i*11)=id->view_id;
  1526. else
  1527. WFIFOW(fd,13+i*11)=nd->u.shop_item[i].nameid;
  1528. }
  1529. WFIFOW(fd,2)=i*11+4;
  1530. WFIFOSET(fd,WFIFOW(fd,2));
  1531. return 0;
  1532. }
  1533. /*==========================================
  1534. *
  1535. *------------------------------------------
  1536. */
  1537. int clif_selllist(struct map_session_data *sd) {
  1538. int fd,i,c=0,val;
  1539. nullpo_retr(0, sd);
  1540. fd=sd->fd;
  1541. WFIFOHEAD(fd, MAX_INVENTORY * 10 + 4);
  1542. WFIFOW(fd,0)=0xc7;
  1543. for(i=0;i<MAX_INVENTORY;i++) {
  1544. if(sd->status.inventory[i].nameid > 0 && sd->inventory_data[i]) {
  1545. if (!itemdb_cansell(&sd->status.inventory[i], pc_isGM(sd)))
  1546. continue;
  1547. val=sd->inventory_data[i]->value_sell;
  1548. if (val < 0)
  1549. continue;
  1550. WFIFOW(fd,4+c*10)=i+2;
  1551. WFIFOL(fd,6+c*10)=val;
  1552. if (!sd->inventory_data[i]->flag.value_notoc)
  1553. val=pc_modifysellvalue(sd,val);
  1554. WFIFOL(fd,10+c*10)=val;
  1555. c++;
  1556. }
  1557. }
  1558. WFIFOW(fd,2)=c*10+4;
  1559. WFIFOSET(fd,WFIFOW(fd,2));
  1560. return 0;
  1561. }
  1562. /*==========================================
  1563. *
  1564. *------------------------------------------
  1565. */
  1566. int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes) {
  1567. int fd = sd->fd;
  1568. int slen = strlen(mes) + 9;
  1569. WFIFOHEAD(fd, slen);
  1570. WFIFOW(fd,0)=0xb4;
  1571. WFIFOW(fd,2)=slen;
  1572. WFIFOL(fd,4)=npcid;
  1573. strcpy((char*)WFIFOP(fd,8),mes);
  1574. WFIFOSET(fd,WFIFOW(fd,2));
  1575. return 0;
  1576. }
  1577. /*==========================================
  1578. *
  1579. *------------------------------------------
  1580. */
  1581. int clif_scriptnext(struct map_session_data *sd,int npcid) {
  1582. int fd;
  1583. nullpo_retr(0, sd);
  1584. fd=sd->fd;
  1585. WFIFOHEAD(fd, packet_len(0xb5));
  1586. WFIFOW(fd,0)=0xb5;
  1587. WFIFOL(fd,2)=npcid;
  1588. WFIFOSET(fd,packet_len(0xb5));
  1589. return 0;
  1590. }
  1591. /*==========================================
  1592. *
  1593. *------------------------------------------
  1594. */
  1595. int clif_scriptclose(struct map_session_data *sd, int npcid) {
  1596. int fd;
  1597. nullpo_retr(0, sd);
  1598. fd=sd->fd;
  1599. WFIFOHEAD(fd, packet_len(0xb6));
  1600. WFIFOW(fd,0)=0xb6;
  1601. WFIFOL(fd,2)=npcid;
  1602. WFIFOSET(fd,packet_len(0xb6));
  1603. return 0;
  1604. }
  1605. /*==========================================
  1606. *
  1607. *------------------------------------------
  1608. */
  1609. void clif_sendfakenpc(struct map_session_data *sd, int npcid) {
  1610. int fd = sd->fd;
  1611. WFIFOHEAD(fd, packet_len(0x78));
  1612. sd->state.using_fake_npc = 1;
  1613. memset(WFIFOP(fd,0), 0, packet_len(0x78));
  1614. WFIFOW(fd,0)=0x78;
  1615. WFIFOL(fd,2)=npcid;
  1616. WFIFOW(fd,14)=111;
  1617. WFIFOPOS(fd,46,sd->bl.x,sd->bl.y,sd->ud.dir);
  1618. WFIFOB(fd,49)=5;
  1619. WFIFOB(fd,50)=5;
  1620. WFIFOSET(fd, packet_len(0x78));
  1621. return;
  1622. }
  1623. /*==========================================
  1624. *
  1625. *------------------------------------------
  1626. */
  1627. int clif_scriptmenu(struct map_session_data* sd, int npcid, const char* mes) {
  1628. int fd = sd->fd;
  1629. int slen = strlen(mes) + 8;
  1630. struct block_list *bl = NULL;
  1631. WFIFOHEAD(fd, slen);
  1632. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1633. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1634. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1635. clif_sendfakenpc(sd, npcid);
  1636. WFIFOW(fd,0)=0xb7;
  1637. WFIFOW(fd,2)=slen;
  1638. WFIFOL(fd,4)=npcid;
  1639. strcpy((char*)WFIFOP(fd,8),mes);
  1640. WFIFOSET(fd,WFIFOW(fd,2));
  1641. return 0;
  1642. }
  1643. /*==========================================
  1644. *
  1645. *------------------------------------------
  1646. */
  1647. int clif_scriptinput(struct map_session_data *sd, int npcid) {
  1648. int fd;
  1649. struct block_list *bl = NULL;
  1650. nullpo_retr(0, sd);
  1651. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1652. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1653. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1654. clif_sendfakenpc(sd, npcid);
  1655. fd=sd->fd;
  1656. WFIFOHEAD(fd, packet_len(0x142));
  1657. WFIFOW(fd,0)=0x142;
  1658. WFIFOL(fd,2)=npcid;
  1659. WFIFOSET(fd,packet_len(0x142));
  1660. return 0;
  1661. }
  1662. /*==========================================
  1663. *
  1664. *------------------------------------------
  1665. */
  1666. int clif_scriptinputstr(struct map_session_data *sd, int npcid) {
  1667. int fd;
  1668. struct block_list *bl = NULL;
  1669. nullpo_retr(0, sd);
  1670. if (!sd->state.using_fake_npc && (npcid == fake_nd->bl.id || ((bl = map_id2bl(npcid)) && (bl->m!=sd->bl.m ||
  1671. bl->x<sd->bl.x-AREA_SIZE-1 || bl->x>sd->bl.x+AREA_SIZE+1 ||
  1672. bl->y<sd->bl.y-AREA_SIZE-1 || bl->y>sd->bl.y+AREA_SIZE+1))))
  1673. clif_sendfakenpc(sd, npcid);
  1674. fd=sd->fd;
  1675. WFIFOHEAD(fd, packet_len(0x1d4));
  1676. WFIFOW(fd,0)=0x1d4;
  1677. WFIFOL(fd,2)=npcid;
  1678. WFIFOSET(fd,packet_len(0x1d4));
  1679. return 0;
  1680. }
  1681. /// npc_id is ignored in the client
  1682. /// type=2 : Remove viewpoint
  1683. /// type=other : Show viewpoint
  1684. int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, int y, int id, int color) {
  1685. int fd;
  1686. nullpo_retr(0, sd);
  1687. fd=sd->fd;
  1688. WFIFOHEAD(fd, packet_len(0x144));
  1689. WFIFOW(fd,0)=0x144;
  1690. WFIFOL(fd,2)=npc_id;
  1691. WFIFOL(fd,6)=type;
  1692. WFIFOL(fd,10)=x;
  1693. WFIFOL(fd,14)=y;
  1694. WFIFOB(fd,18)=id;
  1695. WFIFOL(fd,19)=color;
  1696. WFIFOSET(fd,packet_len(0x144));
  1697. return 0;
  1698. }
  1699. /*==========================================
  1700. *
  1701. *------------------------------------------
  1702. */
  1703. int clif_cutin(struct map_session_data* sd, const char* image, int type) {
  1704. int fd;
  1705. nullpo_retr(0, sd);
  1706. fd=sd->fd;
  1707. WFIFOHEAD(fd, packet_len(0x1b3));
  1708. WFIFOW(fd,0)=0x1b3;
  1709. strncpy((char*)WFIFOP(fd,2),image,64);
  1710. WFIFOB(fd,66)=type;
  1711. WFIFOSET(fd,packet_len(0x1b3));
  1712. return 0;
  1713. }
  1714. /*==========================================
  1715. * Fills in card data from the given item and into the buffer. [Skotlex]
  1716. *------------------------------------------
  1717. */
  1718. static void clif_addcards(unsigned char* buf, struct item* item)
  1719. {
  1720. int i=0,j;
  1721. if (item == NULL) { //Blank data
  1722. WBUFW(buf,0)=0;
  1723. WBUFW(buf,2)=0;
  1724. WBUFW(buf,4)=0;
  1725. WBUFW(buf,6)=0;
  1726. return;
  1727. }
  1728. if(item->card[0]==CARD0_PET) { //pet eggs
  1729. WBUFW(buf,0)=0;
  1730. WBUFW(buf,2)=0;
  1731. WBUFW(buf,4)=0;
  1732. WBUFW(buf,6)=item->card[3]; //Pet renamed flag.
  1733. return;
  1734. }
  1735. if(item->card[0]==CARD0_FORGE || item->card[0]==CARD0_CREATE) { //Forged/created items
  1736. WBUFW(buf,0)=item->card[0];
  1737. WBUFW(buf,2)=item->card[1];
  1738. WBUFW(buf,4)=item->card[2];
  1739. WBUFW(buf,6)=item->card[3];
  1740. return;
  1741. }
  1742. //Client only receives four cards.. so randomly send them a set of cards. [Skotlex]
  1743. if (MAX_SLOTS > 4 && (j = itemdb_slot(item->nameid)) > 4)
  1744. i = rand()%(j-3); //eg: 6 slots, possible i values: 0->3, 1->4, 2->5 => i = rand()%3;
  1745. //Normal items.
  1746. if (item->card[i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1747. WBUFW(buf,0)=j;
  1748. else
  1749. WBUFW(buf,0)= item->card[i];
  1750. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1751. WBUFW(buf,2)=j;
  1752. else
  1753. WBUFW(buf,2)=item->card[i];
  1754. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1755. WBUFW(buf,4)=j;
  1756. else
  1757. WBUFW(buf,4)=item->card[i];
  1758. if (item->card[++i] > 0 && (j=itemdb_viewid(item->card[i])) > 0)
  1759. WBUFW(buf,6)=j;
  1760. else
  1761. WBUFW(buf,6)=item->card[i];
  1762. }
  1763. /*==========================================
  1764. *
  1765. *------------------------------------------
  1766. */
  1767. int clif_additem(struct map_session_data *sd, int n, int amount, int fail) {
  1768. int fd;
  1769. unsigned char *buf;
  1770. nullpo_retr(0, sd);
  1771. fd = sd->fd;
  1772. if (!session_isActive(fd)) //Sasuke-
  1773. return 0;
  1774. WFIFOHEAD(fd,packet_len(0xa0));
  1775. buf = WFIFOP(fd,0);
  1776. if(fail) {
  1777. WBUFW(buf,0)=0xa0;
  1778. WBUFW(buf,2)=n+2;
  1779. WBUFW(buf,4)=amount;
  1780. WBUFW(buf,6)=0;
  1781. WBUFB(buf,8)=0;
  1782. WBUFB(buf,9)=0;
  1783. WBUFB(buf,10)=0;
  1784. WBUFW(buf,11)=0;
  1785. WBUFW(buf,13)=0;
  1786. WBUFW(buf,15)=0;
  1787. WBUFW(buf,17)=0;
  1788. WBUFW(buf,19)=0;
  1789. WBUFB(buf,21)=0;
  1790. WBUFB(buf,22)=fail;
  1791. } else {
  1792. if (n<0 || n>=MAX_INVENTORY || sd->status.inventory[n].nameid <=0 || sd->inventory_data[n] == NULL)
  1793. return 1;
  1794. WBUFW(buf,0)=0xa0;
  1795. WBUFW(buf,2)=n+2;
  1796. WBUFW(buf,4)=amount;
  1797. if (sd->inventory_data[n]->view_id > 0)
  1798. WBUFW(buf,6)=sd->inventory_data[n]->view_id;
  1799. else
  1800. WBUFW(buf,6)=sd->status.inventory[n].nameid;
  1801. WBUFB(buf,8)=sd->status.inventory[n].identify;
  1802. WBUFB(buf,9)=sd->status.inventory[n].attribute;
  1803. WBUFB(buf,10)=sd->status.inventory[n].refine;
  1804. clif_addcards(WBUFP(buf,11), &sd->status.inventory[n]);
  1805. WBUFW(buf,19)=pc_equippoint(sd,n);
  1806. WBUFB(buf,21)=itemtype(sd->inventory_data[n]->type);
  1807. WBUFB(buf,22)=fail;
  1808. }
  1809. WFIFOSET(fd,packet_len(0xa0));
  1810. return 0;
  1811. }
  1812. /*==========================================
  1813. *
  1814. *------------------------------------------
  1815. */
  1816. int clif_delitem(struct map_session_data *sd,int n,int amount)
  1817. {
  1818. int fd;
  1819. nullpo_retr(0, sd);
  1820. fd=sd->fd;
  1821. WFIFOHEAD(fd, packet_len(0xaf));
  1822. WFIFOW(fd,0)=0xaf;
  1823. WFIFOW(fd,2)=n+2;
  1824. WFIFOW(fd,4)=amount;
  1825. WFIFOSET(fd,packet_len(0xaf));
  1826. return 0;
  1827. }
  1828. // Simplifies inventory/cart/storage packets by handling the packet section relevant to items. [Skotlex]
  1829. // Equip is >= 0 for equippable items (holds the equip-point, is 0 for pet
  1830. // armor/egg) -1 for stackable items, -2 for stackable items where arrows must send in the equip-point.
  1831. void clif_item_sub(unsigned char *buf, int n, struct item *i, struct item_data *id, int equip)
  1832. {
  1833. if (id->view_id > 0)
  1834. WBUFW(buf,n)=id->view_id;
  1835. else
  1836. WBUFW(buf,n)=i->nameid;
  1837. WBUFB(buf,n+2)=itemtype(id->type);
  1838. WBUFB(buf,n+3)=i->identify;
  1839. if (equip >= 0) { //Equippable item
  1840. WBUFW(buf,n+4)=equip;
  1841. WBUFW(buf,n+6)=i->equip;
  1842. WBUFB(buf,n+8)=i->attribute;
  1843. WBUFB(buf,n+9)=i->refine;
  1844. } else { //Stackable item.
  1845. WBUFW(buf,n+4)=i->amount;
  1846. if (equip == -2 && id->equip == EQP_AMMO)
  1847. WBUFW(buf,n+6)=EQP_AMMO;
  1848. else
  1849. WBUFW(buf,n+6)=0;
  1850. }
  1851. }
  1852. //Unified inventory function which sends all of the inventory (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1853. void clif_inventorylist(struct map_session_data *sd)
  1854. {
  1855. int i,n,ne,fd = sd->fd,arrow=-1;
  1856. unsigned char *buf;
  1857. unsigned char bufe[MAX_INVENTORY*20+4];
  1858. #if PACKETVER < 5
  1859. const int s = 10; //Entry size.
  1860. #else
  1861. const int s = 18;
  1862. #endif
  1863. WFIFOHEAD(fd, MAX_INVENTORY * s + 4);
  1864. buf = WFIFOP(fd,0);
  1865. for(i=0,n=0,ne=0;i<MAX_INVENTORY;i++){
  1866. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1867. continue;
  1868. if(!itemdb_isstackable2(sd->inventory_data[i]))
  1869. { //Non-stackable (Equippable)
  1870. WBUFW(bufe,ne*20+4)=i+2;
  1871. clif_item_sub(bufe, ne*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1872. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.inventory[i]);
  1873. ne++;
  1874. } else { //Stackable.
  1875. WBUFW(buf,n*s+4)=i+2;
  1876. clif_item_sub(buf, n*s+6, &sd->status.inventory[i], sd->inventory_data[i], -2);
  1877. if (sd->inventory_data[i]->equip == EQP_AMMO &&
  1878. sd->status.inventory[i].equip)
  1879. arrow=i;
  1880. #if PACKETVER >= 5
  1881. clif_addcards(WBUFP(buf, n*s+14), &sd->status.inventory[i]);
  1882. #endif
  1883. n++;
  1884. }
  1885. }
  1886. if (n) {
  1887. #if PACKETVER < 5
  1888. WBUFW(buf,0)=0xa3;
  1889. #else
  1890. WBUFW(buf,0)=0x1ee;
  1891. #endif
  1892. WBUFW(buf,2)=4+n*s;
  1893. WFIFOSET(fd,WFIFOW(fd,2));
  1894. }
  1895. if(arrow >= 0)
  1896. clif_arrowequip(sd,arrow);
  1897. if(ne){
  1898. WBUFW(bufe,0)=0xa4;
  1899. WBUFW(bufe,2)=4+ne*20;
  1900. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1901. }
  1902. }
  1903. //Required when items break/get-repaired. Only sends equippable item list.
  1904. void clif_equiplist(struct map_session_data *sd)
  1905. {
  1906. int i,n,fd = sd->fd;
  1907. unsigned char *buf;
  1908. WFIFOHEAD(fd, MAX_INVENTORY * 20 + 4);
  1909. buf = WFIFOP(fd,0);
  1910. for(i=0,n=0;i<MAX_INVENTORY;i++){
  1911. if (sd->status.inventory[i].nameid <=0 || sd->inventory_data[i] == NULL)
  1912. continue;
  1913. if(itemdb_isstackable2(sd->inventory_data[i]))
  1914. continue;
  1915. //Equippable
  1916. WBUFW(buf,n*20+4)=i+2;
  1917. clif_item_sub(buf, n*20+6, &sd->status.inventory[i], sd->inventory_data[i], pc_equippoint(sd,i));
  1918. clif_addcards(WBUFP(buf, n*20+16), &sd->status.inventory[i]);
  1919. n++;
  1920. }
  1921. if (n) {
  1922. WBUFW(buf,0)=0xa4;
  1923. WBUFW(buf,2)=4+n*20;
  1924. WFIFOSET(fd,WFIFOW(fd,2));
  1925. }
  1926. }
  1927. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1928. void clif_storagelist(struct map_session_data *sd,struct storage *stor)
  1929. {
  1930. struct item_data *id;
  1931. int i,n,ne,fd=sd->fd;
  1932. unsigned char *buf;
  1933. unsigned char bufe[MAX_STORAGE*20+4];
  1934. #if PACKETVER < 5
  1935. const int s = 10; //Entry size.
  1936. #else
  1937. const int s = 18;
  1938. #endif
  1939. WFIFOHEAD(fd,MAX_STORAGE * s + 4);
  1940. buf = WFIFOP(fd,0);
  1941. for(i=0,n=0,ne=0;i<MAX_STORAGE;i++){
  1942. if(stor->storage_[i].nameid<=0)
  1943. continue;
  1944. id = itemdb_search(stor->storage_[i].nameid);
  1945. if(!itemdb_isstackable2(id))
  1946. { //Equippable
  1947. WBUFW(bufe,ne*20+4)=i+1;
  1948. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  1949. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  1950. ne++;
  1951. } else { //Stackable
  1952. WBUFW(buf,n*s+4)=i+1;
  1953. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  1954. #if PACKETVER >= 5
  1955. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  1956. #endif
  1957. n++;
  1958. }
  1959. }
  1960. if(n){
  1961. #if PACKETVER < 5
  1962. WBUFW(buf,0)=0xa5;
  1963. #else
  1964. WBUFW(buf,0)=0x1f0;
  1965. #endif
  1966. WBUFW(buf,2)=4+n*s;
  1967. WFIFOSET(fd,WFIFOW(fd,2));
  1968. }
  1969. if(ne){
  1970. WBUFW(bufe,0)=0xa6;
  1971. WBUFW(bufe,2)=4+ne*20;
  1972. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  1973. }
  1974. }
  1975. //Unified storage function which sends all of the storage (requires two packets, one for equipable items and one for stackable ones. [Skotlex]
  1976. void clif_guildstoragelist(struct map_session_data *sd,struct guild_storage *stor)
  1977. {
  1978. struct item_data *id;
  1979. int i,n,ne,fd=sd->fd;
  1980. unsigned char *buf;
  1981. unsigned char bufe[MAX_GUILD_STORAGE*20+4];
  1982. #if PACKETVER < 5
  1983. const int s = 10; //Entry size.
  1984. #else
  1985. const int s = 18;
  1986. #endif
  1987. WFIFOHEAD(fd,MAX_GUILD_STORAGE * s + 4);
  1988. buf = WFIFOP(fd,0);
  1989. for(i=0,n=0,ne=0;i<MAX_GUILD_STORAGE;i++){
  1990. if(stor->storage_[i].nameid<=0)
  1991. continue;
  1992. id = itemdb_search(stor->storage_[i].nameid);
  1993. if(!itemdb_isstackable2(id))
  1994. { //Equippable
  1995. WBUFW(bufe,ne*20+4)=i+1;
  1996. clif_item_sub(bufe, ne*20+6, &stor->storage_[i], id, id->equip);
  1997. clif_addcards(WBUFP(bufe, ne*20+16), &stor->storage_[i]);
  1998. ne++;
  1999. } else { //Stackable
  2000. WBUFW(buf,n*s+4)=i+1;
  2001. clif_item_sub(buf, n*s+6, &stor->storage_[i], id,-1);
  2002. #if PACKETVER >= 5
  2003. clif_addcards(WBUFP(buf,n*s+14), &stor->storage_[i]);
  2004. #endif
  2005. n++;
  2006. }
  2007. }
  2008. if(n){
  2009. #if PACKETVER < 5
  2010. WBUFW(buf,0)=0xa5;
  2011. #else
  2012. WBUFW(buf,0)=0x1f0;
  2013. #endif
  2014. WBUFW(buf,2)=4+n*s;
  2015. WFIFOSET(fd,WFIFOW(fd,2));
  2016. }
  2017. if(ne){
  2018. WBUFW(bufe,0)=0xa6;
  2019. WBUFW(bufe,2)=4+ne*20;
  2020. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2021. }
  2022. }
  2023. void clif_cartlist(struct map_session_data *sd)
  2024. {
  2025. struct item_data *id;
  2026. int i,n,ne,fd=sd->fd;
  2027. unsigned char *buf;
  2028. unsigned char bufe[MAX_CART*20+4];
  2029. #if PACKETVER < 5
  2030. const int s = 10; //Entry size.
  2031. #else
  2032. const int s = 18;
  2033. #endif
  2034. WFIFOHEAD(fd, MAX_CART * s + 4);
  2035. buf = WFIFOP(fd,0);
  2036. for(i=0,n=0,ne=0;i<MAX_CART;i++){
  2037. if(sd->status.cart[i].nameid<=0)
  2038. continue;
  2039. id = itemdb_search(sd->status.cart[i].nameid);
  2040. if(!itemdb_isstackable2(id))
  2041. { //Equippable
  2042. WBUFW(bufe,ne*20+4)=i+2;
  2043. clif_item_sub(bufe, ne*20+6, &sd->status.cart[i], id, id->equip);
  2044. clif_addcards(WBUFP(bufe, ne*20+16), &sd->status.cart[i]);
  2045. ne++;
  2046. } else { //Stackable
  2047. WBUFW(buf,n*s+4)=i+2;
  2048. clif_item_sub(buf, n*s+6, &sd->status.cart[i], id,-1);
  2049. #if PACKETVER >= 5
  2050. clif_addcards(WBUFP(buf,n*s+14), &sd->status.cart[i]);
  2051. #endif
  2052. n++;
  2053. }
  2054. }
  2055. if(n){
  2056. #if PACKETVER < 5
  2057. WBUFW(buf,0)=0x123;
  2058. #else
  2059. WBUFW(buf,0)=0x1ef;
  2060. #endif
  2061. WBUFW(buf,2)=4+n*s;
  2062. WFIFOSET(fd,WFIFOW(fd,2));
  2063. }
  2064. if(ne){
  2065. WBUFW(bufe,0)=0x122;
  2066. WBUFW(bufe,2)=4+ne*20;
  2067. clif_send(bufe, WBUFW(bufe,2), &sd->bl, SELF);
  2068. }
  2069. return;
  2070. }
  2071. /// Client behaviour:
  2072. /// Closes the cart storage and removes all it's items from memory.
  2073. /// The Num & Weight values of the cart are left untouched and the cart is NOT removed.
  2074. void clif_clearcart(int fd)
  2075. {
  2076. WFIFOHEAD(fd, packet_len(0x12b));
  2077. WFIFOW(fd,0) = 0x12b;
  2078. }
  2079. // Guild XY locators [Valaris]
  2080. int clif_guild_xy(struct map_session_data *sd)
  2081. {
  2082. unsigned char buf[10];
  2083. nullpo_retr(0, sd);
  2084. WBUFW(buf,0)=0x1eb;
  2085. WBUFL(buf,2)=sd->status.account_id;
  2086. WBUFW(buf,6)=sd->bl.x;
  2087. WBUFW(buf,8)=sd->bl.y;
  2088. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2089. return 0;
  2090. }
  2091. /*==========================================
  2092. * Sends x/y dot to a single fd. [Skotlex]
  2093. *------------------------------------------
  2094. */
  2095. int clif_guild_xy_single(int fd, struct map_session_data *sd)
  2096. {
  2097. WFIFOHEAD(fd,packet_len(0x1eb));
  2098. WFIFOW(fd,0)=0x1eb;
  2099. WFIFOL(fd,2)=sd->status.account_id;
  2100. WFIFOW(fd,6)=sd->bl.x;
  2101. WFIFOW(fd,8)=sd->bl.y;
  2102. WFIFOSET(fd,packet_len(0x1eb));
  2103. return 0;
  2104. }
  2105. // Guild XY locators [Valaris]
  2106. int clif_guild_xy_remove(struct map_session_data *sd)
  2107. {
  2108. unsigned char buf[10];
  2109. nullpo_retr(0, sd);
  2110. WBUFW(buf,0)=0x1eb;
  2111. WBUFL(buf,2)=sd->status.account_id;
  2112. WBUFW(buf,6)=-1;
  2113. WBUFW(buf,8)=-1;
  2114. clif_send(buf,packet_len(0x1eb),&sd->bl,GUILD_SAMEMAP_WOS);
  2115. return 0;
  2116. }
  2117. /*==========================================
  2118. * ステータスを送りつける
  2119. * 表示専用数字はこの中で計算して送る
  2120. *------------------------------------------
  2121. */
  2122. int clif_updatestatus(struct map_session_data *sd,int type)
  2123. {
  2124. int fd,len=8;
  2125. nullpo_retr(0, sd);
  2126. fd=sd->fd;
  2127. if ( !session_isActive(fd) ) // Invalid pointer fix, by sasuke [Kevin]
  2128. return 0;
  2129. WFIFOHEAD(fd, 14);
  2130. WFIFOW(fd,0)=0xb0;
  2131. WFIFOW(fd,2)=type;
  2132. switch(type){
  2133. // 00b0
  2134. case SP_WEIGHT:
  2135. pc_updateweightstatus(sd);
  2136. WFIFOW(fd,0)=0xb0; //Need to re-set as pc_updateweightstatus can alter the buffer. [Skotlex]
  2137. WFIFOW(fd,2)=type;
  2138. WFIFOL(fd,4)=sd->weight;
  2139. break;
  2140. case SP_MAXWEIGHT:
  2141. WFIFOL(fd,4)=sd->max_weight;
  2142. break;
  2143. case SP_SPEED:
  2144. WFIFOL(fd,4)=sd->battle_status.speed;
  2145. break;
  2146. case SP_BASELEVEL:
  2147. WFIFOL(fd,4)=sd->status.base_level;
  2148. break;
  2149. case SP_JOBLEVEL:
  2150. WFIFOL(fd,4)=sd->status.job_level;
  2151. break;
  2152. case SP_KARMA: // Adding this back, I wonder if the client intercepts this - [Lance]
  2153. WFIFOL(fd,4)=sd->status.karma;
  2154. break;
  2155. case SP_MANNER:
  2156. WFIFOL(fd,4)=sd->status.manner;
  2157. clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
  2158. break;
  2159. case SP_STATUSPOINT:
  2160. WFIFOL(fd,4)=sd->status.status_point;
  2161. break;
  2162. case SP_SKILLPOINT:
  2163. WFIFOL(fd,4)=sd->status.skill_point;
  2164. break;
  2165. case SP_HIT:
  2166. WFIFOL(fd,4)=sd->battle_status.hit;
  2167. break;
  2168. case SP_FLEE1:
  2169. WFIFOL(fd,4)=sd->battle_status.flee;
  2170. break;
  2171. case SP_FLEE2:
  2172. WFIFOL(fd,4)=sd->battle_status.flee2/10;
  2173. break;
  2174. case SP_MAXHP:
  2175. WFIFOL(fd,4)=sd->battle_status.max_hp;
  2176. break;
  2177. case SP_MAXSP:
  2178. WFIFOL(fd,4)=sd->battle_status.max_sp;
  2179. break;
  2180. case SP_HP:
  2181. WFIFOL(fd,4)=sd->battle_status.hp;
  2182. if (battle_config.disp_hpmeter)
  2183. clif_hpmeter(sd);
  2184. if (!battle_config.party_hp_mode && sd->status.party_id)
  2185. clif_party_hp(sd);
  2186. break;
  2187. case SP_SP:
  2188. WFIFOL(fd,4)=sd->battle_status.sp;
  2189. break;
  2190. case SP_ASPD:
  2191. WFIFOL(fd,4)=sd->battle_status.amotion;
  2192. break;
  2193. case SP_ATK1:
  2194. WFIFOL(fd,4)=sd->battle_status.batk +sd->battle_status.rhw.atk +sd->battle_status.lhw->atk;
  2195. break;
  2196. case SP_DEF1:
  2197. WFIFOL(fd,4)=sd->battle_status.def;
  2198. break;
  2199. case SP_MDEF1:
  2200. WFIFOL(fd,4)=sd->battle_status.mdef;
  2201. break;
  2202. case SP_ATK2:
  2203. WFIFOL(fd,4)=sd->battle_status.rhw.atk2 + sd->battle_status.lhw->atk2;
  2204. break;
  2205. case SP_DEF2:
  2206. WFIFOL(fd,4)=sd->battle_status.def2;
  2207. break;
  2208. case SP_MDEF2:
  2209. //negative check (in case you have something like Berserk active)
  2210. len = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2211. if (len < 0) len = 0;
  2212. WFIFOL(fd,4)= len;
  2213. len = 8;
  2214. break;
  2215. case SP_CRITICAL:
  2216. WFIFOL(fd,4)=sd->battle_status.cri/10;
  2217. break;
  2218. case SP_MATK1:
  2219. WFIFOL(fd,4)=sd->battle_status.matk_max;
  2220. break;
  2221. case SP_MATK2:
  2222. WFIFOL(fd,4)=sd->battle_status.matk_min;
  2223. break;
  2224. case SP_ZENY:
  2225. WFIFOW(fd,0)=0xb1;
  2226. WFIFOL(fd,4)=sd->status.zeny;
  2227. break;
  2228. case SP_BASEEXP:
  2229. WFIFOW(fd,0)=0xb1;
  2230. WFIFOL(fd,4)=sd->status.base_exp;
  2231. break;
  2232. case SP_JOBEXP:
  2233. WFIFOW(fd,0)=0xb1;
  2234. WFIFOL(fd,4)=sd->status.job_exp;
  2235. break;
  2236. case SP_NEXTBASEEXP:
  2237. WFIFOW(fd,0)=0xb1;
  2238. WFIFOL(fd,4)=pc_nextbaseexp(sd);
  2239. break;
  2240. case SP_NEXTJOBEXP:
  2241. WFIFOW(fd,0)=0xb1;
  2242. WFIFOL(fd,4)=pc_nextjobexp(sd);
  2243. break;
  2244. // 00be 終了
  2245. case SP_USTR:
  2246. case SP_UAGI:
  2247. case SP_UVIT:
  2248. case SP_UINT:
  2249. case SP_UDEX:
  2250. case SP_ULUK:
  2251. WFIFOW(fd,0)=0xbe;
  2252. WFIFOB(fd,4)=pc_need_status_point(sd,type-SP_USTR+SP_STR);
  2253. len=5;
  2254. break;
  2255. // 013a 終了
  2256. case SP_ATTACKRANGE:
  2257. WFIFOW(fd,0)=0x13a;
  2258. WFIFOW(fd,2)=sd->battle_status.rhw.range;
  2259. len=4;
  2260. break;
  2261. // 0141 終了
  2262. case SP_STR:
  2263. WFIFOW(fd,0)=0x141;
  2264. WFIFOL(fd,2)=type;
  2265. WFIFOL(fd,6)=sd->status.str;
  2266. WFIFOL(fd,10)=sd->battle_status.str - sd->status.str;
  2267. len=14;
  2268. break;
  2269. case SP_AGI:
  2270. WFIFOW(fd,0)=0x141;
  2271. WFIFOL(fd,2)=type;
  2272. WFIFOL(fd,6)=sd->status.agi;
  2273. WFIFOL(fd,10)=sd->battle_status.agi - sd->status.agi;
  2274. len=14;
  2275. break;
  2276. case SP_VIT:
  2277. WFIFOW(fd,0)=0x141;
  2278. WFIFOL(fd,2)=type;
  2279. WFIFOL(fd,6)=sd->status.vit;
  2280. WFIFOL(fd,10)=sd->battle_status.vit - sd->status.vit;
  2281. len=14;
  2282. break;
  2283. case SP_INT:
  2284. WFIFOW(fd,0)=0x141;
  2285. WFIFOL(fd,2)=type;
  2286. WFIFOL(fd,6)=sd->status.int_;
  2287. WFIFOL(fd,10)=sd->battle_status.int_ - sd->status.int_;
  2288. len=14;
  2289. break;
  2290. case SP_DEX:
  2291. WFIFOW(fd,0)=0x141;
  2292. WFIFOL(fd,2)=type;
  2293. WFIFOL(fd,6)=sd->status.dex;
  2294. WFIFOL(fd,10)=sd->battle_status.dex - sd->status.dex;
  2295. len=14;
  2296. break;
  2297. case SP_LUK:
  2298. WFIFOW(fd,0)=0x141;
  2299. WFIFOL(fd,2)=type;
  2300. WFIFOL(fd,6)=sd->status.luk;
  2301. WFIFOL(fd,10)=sd->battle_status.luk - sd->status.luk;
  2302. len=14;
  2303. break;
  2304. case SP_CARTINFO:
  2305. WFIFOW(fd,0)=0x121;
  2306. WFIFOW(fd,2)=sd->cart_num;
  2307. WFIFOW(fd,4)=MAX_CART;
  2308. WFIFOL(fd,6)=sd->cart_weight;
  2309. WFIFOL(fd,10)=battle_config.max_cart_weight;
  2310. len=14;
  2311. break;
  2312. default:
  2313. if(battle_config.error_log)
  2314. ShowError("clif_updatestatus : unrecognized type %d\n",type);
  2315. return 1;
  2316. }
  2317. WFIFOSET(fd,len);
  2318. return 0;
  2319. }
  2320. int clif_changestatus(struct block_list *bl,int type,int val)
  2321. {
  2322. unsigned char buf[12];
  2323. struct map_session_data *sd = NULL;
  2324. nullpo_retr(0, bl);
  2325. if(bl->type == BL_PC)
  2326. sd = (struct map_session_data *)bl;
  2327. //printf("clif_changestatus id:%d type:%d val:%d\n",bl->id,type,val);
  2328. if(sd){
  2329. WBUFW(buf,0)=0x1ab;
  2330. WBUFL(buf,2)=bl->id;
  2331. WBUFW(buf,6)=type;
  2332. switch(type){
  2333. case SP_MANNER:
  2334. WBUFL(buf,8)=val;
  2335. break;
  2336. default:
  2337. if(battle_config.error_log)
  2338. ShowError("clif_changestatus : unrecognized type %d.\n",type);
  2339. return 1;
  2340. }
  2341. clif_send(buf,packet_len(0x1ab),bl,AREA_WOS);
  2342. }
  2343. return 0;
  2344. }
  2345. /*==========================================
  2346. *
  2347. *------------------------------------------
  2348. */
  2349. int clif_changelook(struct block_list *bl,int type,int val)
  2350. {
  2351. unsigned char buf[32];
  2352. struct map_session_data *sd = NULL;
  2353. struct view_data *vd;
  2354. vd = status_get_viewdata(bl);
  2355. nullpo_retr(0, vd);
  2356. BL_CAST(BL_PC, bl, sd);
  2357. switch(type) {
  2358. case LOOK_WEAPON:
  2359. if (sd)
  2360. {
  2361. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2362. val = vd->weapon;
  2363. }
  2364. else vd->weapon = val;
  2365. break;
  2366. case LOOK_SHIELD:
  2367. if (sd)
  2368. {
  2369. clif_get_weapon_view(sd, &vd->weapon, &vd->shield);
  2370. val = vd->shield;
  2371. }
  2372. else vd->shield = val;
  2373. break;
  2374. case LOOK_BASE:
  2375. vd->class_ = val;
  2376. if (vd->class_ == JOB_WEDDING || vd->class_ == JOB_XMAS)
  2377. vd->weapon = vd->shield = 0;
  2378. if (vd->cloth_color && (
  2379. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2380. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette)
  2381. ))
  2382. clif_changelook(bl,LOOK_CLOTHES_COLOR,0);
  2383. break;
  2384. case LOOK_HAIR:
  2385. vd->hair_style = val;
  2386. break;
  2387. case LOOK_HEAD_BOTTOM:
  2388. vd->head_bottom = val;
  2389. break;
  2390. case LOOK_HEAD_TOP:
  2391. vd->head_top = val;
  2392. break;
  2393. case LOOK_HEAD_MID:
  2394. vd->head_mid = val;
  2395. break;
  2396. case LOOK_HAIR_COLOR:
  2397. vd->hair_color = val;
  2398. break;
  2399. case LOOK_CLOTHES_COLOR:
  2400. if (val && (
  2401. (vd->class_ == JOB_WEDDING && battle_config.wedding_ignorepalette) ||
  2402. (vd->class_ == JOB_XMAS && battle_config.xmas_ignorepalette)
  2403. ))
  2404. val = 0;
  2405. vd->cloth_color = val;
  2406. break;
  2407. case LOOK_SHOES:
  2408. #if PACKETVER > 3
  2409. if (sd) {
  2410. int n;
  2411. if((n = sd->equip_index[2]) >= 0 && sd->inventory_data[n]) {
  2412. if(sd->inventory_data[n]->view_id > 0)
  2413. val = sd->inventory_data[n]->view_id;
  2414. else
  2415. val = sd->status.inventory[n].nameid;
  2416. }
  2417. val = 0;
  2418. }
  2419. #endif
  2420. //Shoes? No packet uses this....
  2421. break;
  2422. }
  2423. #if PACKETVER < 4
  2424. WBUFW(buf,0)=0xc3;
  2425. WBUFL(buf,2)=bl->id;
  2426. WBUFB(buf,6)=type;
  2427. WBUFB(buf,7)=val;
  2428. clif_send(buf,packet_len(0xc3),bl,AREA);
  2429. #else
  2430. if(type == LOOK_WEAPON || type == LOOK_SHIELD) {
  2431. WBUFW(buf,0)=0x1d7;
  2432. WBUFL(buf,2)=bl->id;
  2433. WBUFB(buf,6)=LOOK_WEAPON;
  2434. WBUFW(buf,7)=vd->weapon;
  2435. WBUFW(buf,9)=vd->shield;
  2436. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2437. }
  2438. else
  2439. {
  2440. WBUFW(buf,0)=0x1d7;
  2441. WBUFL(buf,2)=bl->id;
  2442. WBUFB(buf,6)=type;
  2443. WBUFW(buf,7)=val;
  2444. WBUFW(buf,9)=0;
  2445. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2446. }
  2447. #endif
  2448. return 0;
  2449. }
  2450. //Sends a change-base-look packet required for traps as they are triggered.
  2451. void clif_changetraplook(struct block_list *bl,int val)
  2452. {
  2453. unsigned char buf[32];
  2454. #if PACKETVER < 4
  2455. WBUFW(buf,0)=0xc3;
  2456. WBUFL(buf,2)=bl->id;
  2457. WBUFB(buf,6)=LOOK_BASE;
  2458. WBUFB(buf,7)=val;
  2459. clif_send(buf,packet_len(0xc3),bl,AREA);
  2460. #else
  2461. WBUFW(buf,0)=0x1d7;
  2462. WBUFL(buf,2)=bl->id;
  2463. WBUFB(buf,6)=LOOK_BASE;
  2464. WBUFW(buf,7)=val;
  2465. WBUFW(buf,9)=0;
  2466. clif_send(buf,packet_len(0x1d7),bl,AREA);
  2467. #endif
  2468. }
  2469. //For the stupid cloth-dye bug. Resends the given view data
  2470. //to the area specified by bl.
  2471. void clif_refreshlook(struct block_list *bl,int id,int type,int val,int area)
  2472. {
  2473. unsigned char buf[32];
  2474. #if PACKETVER < 4
  2475. WBUFW(buf,0)=0xc3;
  2476. WBUFL(buf,2)=id;
  2477. WBUFB(buf,6)=type;
  2478. WBUFB(buf,7)=val;
  2479. clif_send(buf,packet_len(0xc3),bl,area);
  2480. #else
  2481. WBUFW(buf,0)=0x1d7;
  2482. WBUFL(buf,2)=id;
  2483. WBUFB(buf,6)=type;
  2484. WBUFW(buf,7)=val;
  2485. WBUFW(buf,9)=0;
  2486. clif_send(buf,packet_len(0x1d7),bl,area);
  2487. #endif
  2488. return;
  2489. }
  2490. /*==========================================
  2491. *
  2492. *------------------------------------------
  2493. */
  2494. int clif_initialstatus(struct map_session_data *sd)
  2495. {
  2496. int fd;
  2497. unsigned char *buf;
  2498. nullpo_retr(0, sd);
  2499. fd=sd->fd;
  2500. WFIFOHEAD(fd,packet_len(0xbd));
  2501. buf=WFIFOP(fd,0);
  2502. WBUFW(buf,0)=0xbd;
  2503. WBUFW(buf,2)=(sd->status.status_point > SHRT_MAX)? SHRT_MAX:sd->status.status_point;
  2504. WBUFB(buf,4)=(sd->status.str > UCHAR_MAX)? UCHAR_MAX:sd->status.str;
  2505. WBUFB(buf,5)=pc_need_status_point(sd,SP_STR);
  2506. WBUFB(buf,6)=(sd->status.agi > UCHAR_MAX)? UCHAR_MAX:sd->status.agi;
  2507. WBUFB(buf,7)=pc_need_status_point(sd,SP_AGI);
  2508. WBUFB(buf,8)=(sd->status.vit > UCHAR_MAX)? UCHAR_MAX:sd->status.vit;
  2509. WBUFB(buf,9)=pc_need_status_point(sd,SP_VIT);
  2510. WBUFB(buf,10)=(sd->status.int_ > UCHAR_MAX)? UCHAR_MAX:sd->status.int_;
  2511. WBUFB(buf,11)=pc_need_status_point(sd,SP_INT);
  2512. WBUFB(buf,12)=(sd->status.dex > UCHAR_MAX)? UCHAR_MAX:sd->status.dex;
  2513. WBUFB(buf,13)=pc_need_status_point(sd,SP_DEX);
  2514. WBUFB(buf,14)=(sd->status.luk > UCHAR_MAX)? UCHAR_MAX:sd->status.luk;
  2515. WBUFB(buf,15)=pc_need_status_point(sd,SP_LUK);
  2516. WBUFW(buf,16) = sd->battle_status.batk + sd->battle_status.rhw.atk + sd->battle_status.lhw->atk;
  2517. WBUFW(buf,18) = sd->battle_status.rhw.atk2 + sd->battle_status.lhw->atk2; //atk bonus
  2518. WBUFW(buf,20) = sd->battle_status.matk_max;
  2519. WBUFW(buf,22) = sd->battle_status.matk_min;
  2520. WBUFW(buf,24) = sd->battle_status.def; // def
  2521. WBUFW(buf,26) = sd->battle_status.def2;
  2522. WBUFW(buf,28) = sd->battle_status.mdef; // mdef
  2523. fd = sd->battle_status.mdef2 - (sd->battle_status.vit>>1);
  2524. if (fd < 0) fd = 0; //Negative check for Frenzy'ed characters.
  2525. WBUFW(buf,30) = fd;
  2526. fd = sd->fd;
  2527. WBUFW(buf,32) = sd->battle_status.hit;
  2528. WBUFW(buf,34) = sd->battle_status.flee;
  2529. WBUFW(buf,36) = sd->battle_status.flee2/10;
  2530. WBUFW(buf,38) = sd->battle_status.cri/10;
  2531. WBUFW(buf,40) = sd->status.karma;
  2532. WBUFW(buf,42) = sd->status.manner;
  2533. WFIFOSET(fd,packet_len(0xbd));
  2534. clif_updatestatus(sd,SP_STR);
  2535. clif_updatestatus(sd,SP_AGI);
  2536. clif_updatestatus(sd,SP_VIT);
  2537. clif_updatestatus(sd,SP_INT);
  2538. clif_updatestatus(sd,SP_DEX);
  2539. clif_updatestatus(sd,SP_LUK);
  2540. clif_updatestatus(sd,SP_ATTACKRANGE);
  2541. clif_updatestatus(sd,SP_ASPD);
  2542. return 0;
  2543. }
  2544. /*==========================================
  2545. *矢装備
  2546. *------------------------------------------
  2547. */
  2548. int clif_arrowequip(struct map_session_data *sd,int val)
  2549. {
  2550. int fd;
  2551. nullpo_retr(0, sd);
  2552. pc_stop_attack(sd); // [Valaris]
  2553. fd=sd->fd;
  2554. WFIFOHEAD(fd, packet_len(0x013c));
  2555. WFIFOW(fd,0)=0x013c;
  2556. WFIFOW(fd,2)=val+2;//矢のアイテムID
  2557. WFIFOSET(fd,packet_len(0x013c));
  2558. return 0;
  2559. }
  2560. /// Ammunition action message.
  2561. /// type=0 : MsgStringTable[242]="Please equip the proper ammunition first."
  2562. /// type=1 : MsgStringTable[243]="You can't Attack or use Skills because your Weight Limit has been exceeded."
  2563. /// type=2 : MsgStringTable[244]="You can't use Skills because Weight Limit has been exceeded."
  2564. /// type=3 : assassin, baby_assassin, assassin_cross => MsgStringTable[1040]="You have equipped throwing daggers."
  2565. /// gunslinger => MsgStringTable[1175]="Bullets have been equipped."
  2566. /// NOT ninja => MsgStringTable[245]="Ammunition has been equipped."
  2567. int clif_arrow_fail(struct map_session_data *sd,int type)
  2568. {
  2569. int fd;
  2570. nullpo_retr(0, sd);
  2571. fd=sd->fd;
  2572. WFIFOHEAD(fd, packet_len(0x013b));
  2573. WFIFOW(fd,0)=0x013b;
  2574. WFIFOW(fd,2)=type;
  2575. WFIFOSET(fd,packet_len(0x013b));
  2576. return 0;
  2577. }
  2578. /*==========================================
  2579. * 作成可能 矢リスト送信
  2580. *------------------------------------------
  2581. */
  2582. int clif_arrow_create_list(struct map_session_data *sd)
  2583. {
  2584. int i, c, j;
  2585. int fd;
  2586. nullpo_retr(0, sd);
  2587. fd = sd->fd;
  2588. WFIFOHEAD(fd, MAX_SKILL_ARROW_DB*2+4);
  2589. WFIFOW(fd,0) = 0x1ad;
  2590. for (i = 0, c = 0; i < MAX_SKILL_ARROW_DB; i++) {
  2591. if (skill_arrow_db[i].nameid > 0 &&
  2592. (j = pc_search_inventory(sd, skill_arrow_db[i].nameid)) >= 0 &&
  2593. !sd->status.inventory[j].equip && sd->status.inventory[j].identify)
  2594. {
  2595. if ((j = itemdb_viewid(skill_arrow_db[i].nameid)) > 0)
  2596. WFIFOW(fd,c*2+4) = j;
  2597. else
  2598. WFIFOW(fd,c*2+4) = skill_arrow_db[i].nameid;
  2599. c++;
  2600. }
  2601. }
  2602. WFIFOW(fd,2) = c*2+4;
  2603. WFIFOSET(fd, WFIFOW(fd,2));
  2604. if (c > 0) {
  2605. sd->menuskill_id = AC_MAKINGARROW;
  2606. sd->menuskill_lv = c;
  2607. }
  2608. return 0;
  2609. }
  2610. /*==========================================
  2611. *
  2612. *------------------------------------------
  2613. */
  2614. int clif_statusupack(struct map_session_data *sd,int type,int ok,int val)
  2615. {
  2616. int fd;
  2617. nullpo_retr(0, sd);
  2618. fd=sd->fd;
  2619. WFIFOHEAD(fd,packet_len(0xbc));
  2620. WFIFOW(fd,0)=0xbc;
  2621. WFIFOW(fd,2)=type;
  2622. WFIFOB(fd,4)=ok;
  2623. WFIFOB(fd,5)=val;
  2624. WFIFOSET(fd,packet_len(0xbc));
  2625. return 0;
  2626. }
  2627. /*==========================================
  2628. *
  2629. *------------------------------------------
  2630. */
  2631. int clif_equipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2632. {
  2633. int fd;
  2634. nullpo_retr(0, sd);
  2635. fd=sd->fd;
  2636. WFIFOHEAD(fd,packet_len(0xaa));
  2637. WFIFOW(fd,0)=0xaa;
  2638. WFIFOW(fd,2)=n+2;
  2639. WFIFOW(fd,4)=pos;
  2640. WFIFOB(fd,6)=ok;
  2641. WFIFOSET(fd,packet_len(0xaa));
  2642. return 0;
  2643. }
  2644. /*==========================================
  2645. *
  2646. *------------------------------------------
  2647. */
  2648. int clif_unequipitemack(struct map_session_data *sd,int n,int pos,int ok)
  2649. {
  2650. int fd;
  2651. nullpo_retr(0, sd);
  2652. fd=sd->fd;
  2653. WFIFOHEAD(fd,packet_len(0xac));
  2654. WFIFOW(fd,0)=0xac;
  2655. WFIFOW(fd,2)=n+2;
  2656. WFIFOW(fd,4)=pos;
  2657. WFIFOB(fd,6)=ok;
  2658. WFIFOSET(fd,packet_len(0xac));
  2659. return 0;
  2660. }
  2661. /*==========================================
  2662. *
  2663. *------------------------------------------
  2664. */
  2665. int clif_misceffect(struct block_list* bl,int type)
  2666. {
  2667. unsigned char buf[32];
  2668. nullpo_retr(0, bl);
  2669. WBUFW(buf,0) = 0x19b;
  2670. WBUFL(buf,2) = bl->id;
  2671. WBUFL(buf,6) = type;
  2672. clif_send(buf,packet_len(0x19b),bl,AREA);
  2673. return 0;
  2674. }
  2675. int clif_misceffect2(struct block_list *bl, int type) {
  2676. unsigned char buf[24];
  2677. nullpo_retr(0, bl);
  2678. memset(buf, 0, packet_len(0x1f3));
  2679. WBUFW(buf,0) = 0x1f3;
  2680. WBUFL(buf,2) = bl->id;
  2681. WBUFL(buf,6) = type;
  2682. clif_send(buf, packet_len(0x1f3), bl, AREA);
  2683. return 0;
  2684. }
  2685. /*==========================================
  2686. * 表示オプション変更
  2687. *------------------------------------------
  2688. */
  2689. int clif_changeoption(struct block_list* bl)
  2690. {
  2691. unsigned char buf[32];
  2692. struct status_change *sc;
  2693. nullpo_retr(0, bl);
  2694. sc = status_get_sc(bl);
  2695. if (!sc) return 0; //How can an option change if there's no sc?
  2696. #if PACKETVER > 6
  2697. WBUFW(buf,0) = 0x229;
  2698. WBUFL(buf,2) = bl->id;
  2699. WBUFW(buf,6) = sc->opt1;
  2700. WBUFW(buf,8) = sc->opt2;
  2701. WBUFL(buf,10) = sc->option;
  2702. WBUFB(buf,14) = 0; // PK???
  2703. if(disguised(bl)) {
  2704. clif_send(buf,packet_len(0x229),bl,AREA_WOS);
  2705. WBUFL(buf,2) = -bl->id;
  2706. clif_send(buf,packet_len(0x229),bl,SELF);
  2707. WBUFL(buf,2) = bl->id;
  2708. WBUFL(buf,10) = OPTION_INVISIBLE;
  2709. clif_send(buf,packet_len(0x229),bl,SELF);
  2710. } else
  2711. clif_send(buf,packet_len(0x229),bl,AREA);
  2712. #else
  2713. WBUFW(buf,0) = 0x119;
  2714. WBUFL(buf,2) = bl->id;
  2715. WBUFW(buf,6) = sc->opt1;
  2716. WBUFW(buf,8) = sc->opt2;
  2717. WBUFW(buf,10) = sc->option;
  2718. WBUFB(buf,12) = 0; // ??
  2719. if(disguised(bl)) {
  2720. clif_send(buf,packet_len(0x119),bl,AREA_WOS);
  2721. WBUFL(buf,2) = -bl->id;
  2722. clif_send(buf,packet_len(0x119),bl,SELF);
  2723. WBUFL(buf,2) = bl->id;
  2724. WBUFW(buf,10) = OPTION_INVISIBLE;
  2725. clif_send(buf,packet_len(0x119),bl,SELF);
  2726. } else
  2727. clif_send(buf,packet_len(0x119),bl,AREA);
  2728. #endif
  2729. return 0;
  2730. }
  2731. /*==========================================
  2732. *
  2733. *------------------------------------------
  2734. */
  2735. int clif_useitemack(struct map_session_data *sd,int index,int amount,int ok)
  2736. {
  2737. nullpo_retr(0, sd);
  2738. if(!ok) {
  2739. int fd=sd->fd;
  2740. WFIFOHEAD(fd,packet_len(0xa8));
  2741. WFIFOW(fd,0)=0xa8;
  2742. WFIFOW(fd,2)=index+2;
  2743. WFIFOW(fd,4)=amount;
  2744. WFIFOB(fd,6)=ok;
  2745. WFIFOSET(fd,packet_len(0xa8));
  2746. }
  2747. else {
  2748. #if PACKETVER < 3
  2749. int fd=sd->fd;
  2750. WFIFOHEAD(fd,packet_len(0xa8));
  2751. WFIFOW(fd,0)=0xa8;
  2752. WFIFOW(fd,2)=index+2;
  2753. WFIFOW(fd,4)=amount;
  2754. WFIFOB(fd,6)=ok;
  2755. WFIFOSET(fd,packet_len(0xa8));
  2756. #else
  2757. unsigned char buf[32];
  2758. WBUFW(buf,0)=0x1c8;
  2759. WBUFW(buf,2)=index+2;
  2760. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2761. WBUFW(buf,4)=sd->inventory_data[index]->view_id;
  2762. else
  2763. WBUFW(buf,4)=sd->status.inventory[index].nameid;
  2764. WBUFL(buf,6)=sd->bl.id;
  2765. WBUFW(buf,10)=amount;
  2766. WBUFB(buf,12)=ok;
  2767. clif_send(buf,packet_len(0x1c8),&sd->bl,AREA);
  2768. #endif
  2769. }
  2770. return 0;
  2771. }
  2772. /*==========================================
  2773. *
  2774. *------------------------------------------
  2775. */
  2776. int clif_createchat(struct map_session_data *sd,int fail)
  2777. {
  2778. int fd;
  2779. nullpo_retr(0, sd);
  2780. fd=sd->fd;
  2781. WFIFOHEAD(fd,packet_len(0xd6));
  2782. WFIFOW(fd,0)=0xd6;
  2783. WFIFOB(fd,2)=fail;
  2784. WFIFOSET(fd,packet_len(0xd6));
  2785. return 0;
  2786. }
  2787. /*==========================================
  2788. *
  2789. *------------------------------------------
  2790. */
  2791. int clif_dispchat(struct chat_data *cd,int fd)
  2792. {
  2793. unsigned char buf[128]; // 最大title(60バイト)+17
  2794. if(cd==NULL || *cd->owner==NULL)
  2795. return 1;
  2796. WBUFW(buf,0)=0xd7;
  2797. WBUFW(buf,2)=strlen((const char*)cd->title)+17;
  2798. WBUFL(buf,4)=(*cd->owner)->id;
  2799. WBUFL(buf,8)=cd->bl.id;
  2800. WBUFW(buf,12)=cd->limit;
  2801. WBUFW(buf,14)=cd->users;
  2802. WBUFB(buf,16)=cd->pub;
  2803. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  2804. if(fd){
  2805. WFIFOHEAD(fd, WBUFW(buf,2));
  2806. memcpy(WFIFOP(fd,0),buf,WBUFW(buf,2));
  2807. WFIFOSET(fd,WBUFW(buf,2));
  2808. } else {
  2809. clif_send(buf,WBUFW(buf,2),*cd->owner,AREA_WOSC);
  2810. }
  2811. return 0;
  2812. }
  2813. /*==========================================
  2814. * chatの状態変更成功
  2815. * 外部の人用と命令コード(d7->df)が違うだけ
  2816. *------------------------------------------
  2817. */
  2818. int clif_changechatstatus(struct chat_data *cd)
  2819. {
  2820. unsigned char buf[128]; // 最大title(60バイト)+17
  2821. if(cd==NULL || cd->usersd[0]==NULL)
  2822. return 1;
  2823. WBUFW(buf,0)=0xdf;
  2824. WBUFW(buf,2)=strlen((char*)cd->title)+17;
  2825. WBUFL(buf,4)=cd->usersd[0]->bl.id;
  2826. WBUFL(buf,8)=cd->bl.id;
  2827. WBUFW(buf,12)=cd->limit;
  2828. WBUFW(buf,14)=cd->users;
  2829. WBUFB(buf,16)=cd->pub;
  2830. strcpy((char*)WBUFP(buf,17),(const char*)cd->title);
  2831. clif_send(buf,WBUFW(buf,2),&cd->usersd[0]->bl,CHAT);
  2832. return 0;
  2833. }
  2834. /*==========================================
  2835. *
  2836. *------------------------------------------
  2837. */
  2838. int clif_clearchat(struct chat_data *cd,int fd)
  2839. {
  2840. unsigned char buf[32];
  2841. nullpo_retr(0, cd);
  2842. WBUFW(buf,0)=0xd8;
  2843. WBUFL(buf,2)=cd->bl.id;
  2844. if(fd){
  2845. WFIFOHEAD(fd,packet_len(0xd8));
  2846. memcpy(WFIFOP(fd,0),buf,packet_len(0xd8));
  2847. WFIFOSET(fd,packet_len(0xd8));
  2848. } else {
  2849. clif_send(buf,packet_len(0xd8),*cd->owner,AREA_WOSC);
  2850. }
  2851. return 0;
  2852. }
  2853. /*==========================================
  2854. *
  2855. *------------------------------------------
  2856. */
  2857. int clif_joinchatfail(struct map_session_data *sd,int fail)
  2858. {
  2859. int fd;
  2860. nullpo_retr(0, sd);
  2861. fd=sd->fd;
  2862. WFIFOHEAD(fd,packet_len(0xda));
  2863. WFIFOW(fd,0)=0xda;
  2864. WFIFOB(fd,2)=fail;
  2865. WFIFOSET(fd,packet_len(0xda));
  2866. return 0;
  2867. }
  2868. /*==========================================
  2869. *
  2870. *------------------------------------------
  2871. */
  2872. int clif_joinchatok(struct map_session_data *sd,struct chat_data* cd)
  2873. {
  2874. int fd;
  2875. int i;
  2876. nullpo_retr(0, sd);
  2877. nullpo_retr(0, cd);
  2878. fd = sd->fd;
  2879. if (!session_isActive(fd))
  2880. return 0;
  2881. WFIFOHEAD(fd, 8 + (28*cd->users));
  2882. WFIFOW(fd, 0) = 0xdb;
  2883. WFIFOW(fd, 2) = 8 + (28*cd->users);
  2884. WFIFOL(fd, 4) = cd->bl.id;
  2885. for (i = 0; i < cd->users; i++) {
  2886. WFIFOL(fd, 8+i*28) = (i!=0) || ((*cd->owner)->type == BL_NPC);
  2887. memcpy(WFIFOP(fd, 8+i*28+4), cd->usersd[i]->status.name, NAME_LENGTH);
  2888. }
  2889. WFIFOSET(fd, WFIFOW(fd, 2));
  2890. return 0;
  2891. }
  2892. /*==========================================
  2893. *
  2894. *------------------------------------------
  2895. */
  2896. int clif_addchat(struct chat_data* cd,struct map_session_data *sd)
  2897. {
  2898. unsigned char buf[32];
  2899. nullpo_retr(0, sd);
  2900. nullpo_retr(0, cd);
  2901. WBUFW(buf, 0) = 0x0dc;
  2902. WBUFW(buf, 2) = cd->users;
  2903. memcpy(WBUFP(buf, 4),sd->status.name,NAME_LENGTH);
  2904. clif_send(buf,packet_len(0xdc),&sd->bl,CHAT_WOS);
  2905. return 0;
  2906. }
  2907. /*==========================================
  2908. *
  2909. *------------------------------------------
  2910. */
  2911. int clif_changechatowner(struct chat_data* cd,struct map_session_data *sd)
  2912. {
  2913. unsigned char buf[64];
  2914. nullpo_retr(0, sd);
  2915. nullpo_retr(0, cd);
  2916. WBUFW(buf, 0) = 0xe1;
  2917. WBUFL(buf, 2) = 1;
  2918. memcpy(WBUFP(buf,6),cd->usersd[0]->status.name,NAME_LENGTH);
  2919. WBUFW(buf,30) = 0xe1;
  2920. WBUFL(buf,32) = 0;
  2921. memcpy(WBUFP(buf,36),sd->status.name,NAME_LENGTH);
  2922. clif_send(buf,packet_len(0xe1)*2,&sd->bl,CHAT);
  2923. return 0;
  2924. }
  2925. /*==========================================
  2926. *
  2927. *------------------------------------------
  2928. */
  2929. int clif_leavechat(struct chat_data* cd,struct map_session_data *sd)
  2930. {
  2931. unsigned char buf[32];
  2932. nullpo_retr(0, sd);
  2933. nullpo_retr(0, cd);
  2934. WBUFW(buf, 0) = 0xdd;
  2935. WBUFW(buf, 2) = cd->users-1;
  2936. memcpy(WBUFP(buf,4),sd->status.name,NAME_LENGTH);
  2937. WBUFB(buf,28) = 0;
  2938. clif_send(buf,packet_len(0xdd),&sd->bl,CHAT);
  2939. return 0;
  2940. }
  2941. /*==========================================
  2942. * 取り引き要請受け
  2943. *------------------------------------------
  2944. */
  2945. int clif_traderequest(struct map_session_data* sd, const char* name)
  2946. {
  2947. int fd;
  2948. nullpo_retr(0, sd);
  2949. fd=sd->fd;
  2950. WFIFOHEAD(fd,packet_len(0xe5));
  2951. WFIFOW(fd,0)=0xe5;
  2952. strcpy((char*)WFIFOP(fd,2),name);
  2953. WFIFOSET(fd,packet_len(0xe5));
  2954. return 0;
  2955. }
  2956. /*==========================================
  2957. * 取り引き要求応答
  2958. *------------------------------------------
  2959. */
  2960. int clif_tradestart(struct map_session_data *sd,int type)
  2961. {
  2962. int fd;
  2963. nullpo_retr(0, sd);
  2964. fd=sd->fd;
  2965. WFIFOHEAD(fd,packet_len(0xe7));
  2966. WFIFOW(fd,0)=0xe7;
  2967. WFIFOB(fd,2)=type;
  2968. WFIFOSET(fd,packet_len(0xe7));
  2969. return 0;
  2970. }
  2971. /*==========================================
  2972. * 相手方からのアイテム追加
  2973. *------------------------------------------
  2974. */
  2975. int clif_tradeadditem(struct map_session_data *sd,struct map_session_data *tsd,int index,int amount)
  2976. {
  2977. int fd;
  2978. nullpo_retr(0, sd);
  2979. nullpo_retr(0, tsd);
  2980. fd=tsd->fd;
  2981. WFIFOHEAD(fd,packet_len(0xe9));
  2982. WFIFOW(fd,0)=0xe9;
  2983. WFIFOL(fd,2)=amount;
  2984. if(index==0){
  2985. WFIFOW(fd,6) = 0; // type id
  2986. WFIFOB(fd,8) = 0; //identify flag
  2987. WFIFOB(fd,9) = 0; // attribute
  2988. WFIFOB(fd,10)= 0; //refine
  2989. WFIFOW(fd,11)= 0; //card (4w)
  2990. WFIFOW(fd,13)= 0; //card (4w)
  2991. WFIFOW(fd,15)= 0; //card (4w)
  2992. WFIFOW(fd,17)= 0; //card (4w)
  2993. }
  2994. else{
  2995. index-=2; //index fix
  2996. if(sd->inventory_data[index] && sd->inventory_data[index]->view_id > 0)
  2997. WFIFOW(fd,6) = sd->inventory_data[index]->view_id;
  2998. else
  2999. WFIFOW(fd,6) = sd->status.inventory[index].nameid; // type id
  3000. WFIFOB(fd,8) = sd->status.inventory[index].identify; //identify flag
  3001. WFIFOB(fd,9) = sd->status.inventory[index].attribute; // attribute
  3002. WFIFOB(fd,10)= sd->status.inventory[index].refine; //refine
  3003. clif_addcards(WFIFOP(fd, 11), &sd->status.inventory[index]);
  3004. }
  3005. WFIFOSET(fd,packet_len(0xe9));
  3006. return 0;
  3007. }
  3008. /*==========================================
  3009. * アイテム追加成功/失敗
  3010. *------------------------------------------
  3011. */
  3012. int clif_tradeitemok(struct map_session_data *sd,int index,int fail)
  3013. {
  3014. int fd;
  3015. nullpo_retr(0, sd);
  3016. fd=sd->fd;
  3017. WFIFOHEAD(fd,packet_len(0xea));
  3018. WFIFOW(fd,0)=0xea;
  3019. WFIFOW(fd,2)=index;
  3020. WFIFOB(fd,4)=fail;
  3021. WFIFOSET(fd,packet_len(0xea));
  3022. return 0;
  3023. }
  3024. /*==========================================
  3025. * 取り引きok押し
  3026. *------------------------------------------
  3027. */
  3028. int clif_tradedeal_lock(struct map_session_data *sd,int fail)
  3029. {
  3030. int fd;
  3031. nullpo_retr(0, sd);
  3032. fd=sd->fd;
  3033. WFIFOHEAD(fd,packet_len(0xec));
  3034. WFIFOW(fd,0)=0xec;
  3035. WFIFOB(fd,2)=fail; // 0=you 1=the other person
  3036. WFIFOSET(fd,packet_len(0xec));
  3037. return 0;
  3038. }
  3039. /*==========================================
  3040. * 取り引きがキャンセルされました
  3041. *------------------------------------------
  3042. */
  3043. int clif_tradecancelled(struct map_session_data *sd)
  3044. {
  3045. int fd;
  3046. nullpo_retr(0, sd);
  3047. fd=sd->fd;
  3048. WFIFOHEAD(fd,packet_len(0xee));
  3049. WFIFOW(fd,0)=0xee;
  3050. WFIFOSET(fd,packet_len(0xee));
  3051. return 0;
  3052. }
  3053. /*==========================================
  3054. * 取り引き完了
  3055. *------------------------------------------
  3056. */
  3057. int clif_tradecompleted(struct map_session_data *sd,int fail)
  3058. {
  3059. int fd;
  3060. nullpo_retr(0, sd);
  3061. fd=sd->fd;
  3062. WFIFOHEAD(fd,packet_len(0xf0));
  3063. WFIFOW(fd,0)=0xf0;
  3064. WFIFOB(fd,2)=fail;
  3065. WFIFOSET(fd,packet_len(0xf0));
  3066. return 0;
  3067. }
  3068. /*==========================================
  3069. * カプラ倉庫のアイテム数を更新
  3070. *------------------------------------------
  3071. */
  3072. int clif_updatestorageamount(struct map_session_data *sd,struct storage *stor)
  3073. {
  3074. int fd;
  3075. nullpo_retr(0, sd);
  3076. nullpo_retr(0, stor);
  3077. fd=sd->fd;
  3078. WFIFOHEAD(fd,packet_len(0xf2));
  3079. WFIFOW(fd,0) = 0xf2; // update storage amount
  3080. WFIFOW(fd,2) = stor->storage_amount; //items
  3081. WFIFOW(fd,4) = MAX_STORAGE; //items max
  3082. WFIFOSET(fd,packet_len(0xf2));
  3083. return 0;
  3084. }
  3085. /*==========================================
  3086. * カプラ倉庫にアイテムを追加する
  3087. *------------------------------------------
  3088. */
  3089. int clif_storageitemadded(struct map_session_data *sd,struct storage *stor,int index,int amount)
  3090. {
  3091. int view,fd;
  3092. nullpo_retr(0, sd);
  3093. nullpo_retr(0, stor);
  3094. fd=sd->fd;
  3095. WFIFOHEAD(fd,packet_len(0xf4));
  3096. WFIFOW(fd,0) =0xf4; // Storage item added
  3097. WFIFOW(fd,2) =index+1; // index
  3098. WFIFOL(fd,4) =amount; // amount
  3099. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3100. WFIFOW(fd,8) =view;
  3101. else
  3102. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3103. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3104. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3105. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3106. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3107. WFIFOSET(fd,packet_len(0xf4));
  3108. return 0;
  3109. }
  3110. /*==========================================
  3111. *
  3112. *------------------------------------------
  3113. */
  3114. int clif_updateguildstorageamount(struct map_session_data *sd,struct guild_storage *stor)
  3115. {
  3116. int fd;
  3117. nullpo_retr(0, sd);
  3118. nullpo_retr(0, stor);
  3119. fd=sd->fd;
  3120. WFIFOHEAD(fd,packet_len(0xf2));
  3121. WFIFOW(fd,0) = 0xf2; // update storage amount
  3122. WFIFOW(fd,2) = stor->storage_amount; //items
  3123. WFIFOW(fd,4) = MAX_GUILD_STORAGE; //items max
  3124. WFIFOSET(fd,packet_len(0xf2));
  3125. return 0;
  3126. }
  3127. /*==========================================
  3128. *
  3129. *------------------------------------------
  3130. */
  3131. int clif_guildstorageitemadded(struct map_session_data *sd,struct guild_storage *stor,int index,int amount)
  3132. {
  3133. int view,fd;
  3134. nullpo_retr(0, sd);
  3135. nullpo_retr(0, stor);
  3136. fd=sd->fd;
  3137. WFIFOHEAD(fd,packet_len(0xf4));
  3138. WFIFOW(fd,0) =0xf4; // Storage item added
  3139. WFIFOW(fd,2) =index+1; // index
  3140. WFIFOL(fd,4) =amount; // amount
  3141. if((view = itemdb_viewid(stor->storage_[index].nameid)) > 0)
  3142. WFIFOW(fd,8) =view;
  3143. else
  3144. WFIFOW(fd,8) =stor->storage_[index].nameid; // id
  3145. WFIFOB(fd,10)=stor->storage_[index].identify; //identify flag
  3146. WFIFOB(fd,11)=stor->storage_[index].attribute; // attribute
  3147. WFIFOB(fd,12)=stor->storage_[index].refine; //refine
  3148. clif_addcards(WFIFOP(fd,13), &stor->storage_[index]);
  3149. WFIFOSET(fd,packet_len(0xf4));
  3150. return 0;
  3151. }
  3152. /*==========================================
  3153. * カプラ倉庫からアイテムを取り去る
  3154. *------------------------------------------
  3155. */
  3156. int clif_storageitemremoved(struct map_session_data *sd,int index,int amount)
  3157. {
  3158. int fd;
  3159. nullpo_retr(0, sd);
  3160. fd=sd->fd;
  3161. WFIFOHEAD(fd,packet_len(0xf6));
  3162. WFIFOW(fd,0)=0xf6; // Storage item removed
  3163. WFIFOW(fd,2)=index+1;
  3164. WFIFOL(fd,4)=amount;
  3165. WFIFOSET(fd,packet_len(0xf6));
  3166. return 0;
  3167. }
  3168. /*==========================================
  3169. * カプラ倉庫を閉じる
  3170. *------------------------------------------
  3171. */
  3172. int clif_storageclose(struct map_session_data *sd)
  3173. {
  3174. int fd;
  3175. nullpo_retr(0, sd);
  3176. fd=sd->fd;
  3177. WFIFOHEAD(fd,packet_len(0xf8));
  3178. WFIFOW(fd,0)=0xf8; // Storage Closed
  3179. WFIFOSET(fd,packet_len(0xf8));
  3180. return 0;
  3181. }
  3182. //
  3183. // callback系 ?
  3184. //
  3185. /*==========================================
  3186. * PC表示
  3187. *------------------------------------------
  3188. */
  3189. void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* dstsd)
  3190. {
  3191. int len;
  3192. if(dstsd->chatID){
  3193. struct chat_data *cd;
  3194. cd=(struct chat_data*)map_id2bl(dstsd->chatID);
  3195. if(cd && cd->usersd[0]==dstsd)
  3196. clif_dispchat(cd,sd->fd);
  3197. }
  3198. if(dstsd->vender_id)
  3199. clif_showvendingboard(&dstsd->bl,dstsd->message,sd->fd);
  3200. if(dstsd->spiritball > 0)
  3201. clif_spiritball_single(sd->fd, dstsd);
  3202. if((sd->status.party_id && dstsd->status.party_id == sd->status.party_id) || //Party-mate, or hpdisp setting.
  3203. (battle_config.disp_hpmeter && (len = pc_isGM(sd)) >= battle_config.disp_hpmeter && len >= pc_isGM(dstsd))
  3204. )
  3205. clif_hpmeter_single(sd->fd, dstsd);
  3206. if(dstsd->status.manner < 0)
  3207. clif_changestatus(&dstsd->bl,SP_MANNER,dstsd->status.manner);
  3208. // pvp circle for duel [LuzZza]
  3209. /*
  3210. if(dstsd->duel_group)
  3211. clif_specialeffect(&dstsd->bl, 159, 4);
  3212. */
  3213. }
  3214. void clif_getareachar_char(struct map_session_data* sd,struct block_list *bl)
  3215. {
  3216. struct unit_data *ud;
  3217. struct view_data *vd;
  3218. int len, fd = sd->fd;
  3219. vd = status_get_viewdata(bl);
  3220. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3221. return;
  3222. ud = unit_bl2ud(bl);
  3223. if (ud && ud->walktimer != -1)
  3224. {
  3225. #if PACKETVER > 6
  3226. WFIFOHEAD(fd, packet_len(0x22c));
  3227. #elif PACKETVER > 3
  3228. WFIFOHEAD(fd, packet_len(0x1da));
  3229. #else
  3230. WFIFOHEAD(fd, packet_len(0x7b));
  3231. #endif
  3232. len = clif_set007b(bl,vd,ud,WFIFOP(fd,0));
  3233. WFIFOSET(fd,len);
  3234. } else {
  3235. #if PACKETVER > 6
  3236. WFIFOHEAD(fd,packet_len(0x22a));
  3237. #elif PACKETVER > 3
  3238. WFIFOHEAD(fd,packet_len(0x1d8));
  3239. #else
  3240. WFIFOHEAD(fd,packet_len(0x78));
  3241. #endif
  3242. len = clif_set0078(bl,vd,WFIFOP(fd,0));
  3243. WFIFOSET(fd,len);
  3244. }
  3245. if (vd->cloth_color)
  3246. clif_refreshlook(&sd->bl,bl->id,LOOK_CLOTHES_COLOR,vd->cloth_color,SELF);
  3247. switch (bl->type)
  3248. {
  3249. case BL_PC:
  3250. {
  3251. TBL_PC* tsd = (TBL_PC*)bl;
  3252. clif_getareachar_pc(sd, tsd);
  3253. if(tsd->state.size==2) // tiny/big players [Valaris]
  3254. clif_specialeffect(bl,423,AREA);
  3255. else if(tsd->state.size==1)
  3256. clif_specialeffect(bl,421,AREA);
  3257. }
  3258. break;
  3259. case BL_NPC:
  3260. {
  3261. if(((TBL_NPC*)bl)->chat_id)
  3262. clif_dispchat((struct chat_data*)map_id2bl(((TBL_NPC*)bl)->chat_id),sd->fd);
  3263. }
  3264. break;
  3265. case BL_MOB:
  3266. {
  3267. TBL_MOB* md = (TBL_MOB*)bl;
  3268. if(md->special_state.size==2) // tiny/big mobs [Valaris]
  3269. clif_specialeffect(bl,423,AREA);
  3270. else if(md->special_state.size==1)
  3271. clif_specialeffect(bl,421,AREA);
  3272. }
  3273. break;
  3274. }
  3275. }
  3276. /*==========================================
  3277. * Older fix pos packet.
  3278. *------------------------------------------
  3279. */
  3280. int clif_fixpos2(struct block_list* bl)
  3281. {
  3282. struct unit_data *ud;
  3283. struct view_data *vd;
  3284. unsigned char buf[256];
  3285. int len;
  3286. nullpo_retr(0, bl);
  3287. ud = unit_bl2ud(bl);
  3288. vd = status_get_viewdata(bl);
  3289. if (!vd || vd->class_ == INVISIBLE_CLASS)
  3290. return 0;
  3291. if(ud && ud->walktimer != -1)
  3292. len = clif_set007b(bl,vd,ud,buf);
  3293. else
  3294. len = clif_set0078(bl,vd,buf);
  3295. if (disguised(bl)) {
  3296. clif_send(buf,len,bl,AREA_WOS);
  3297. clif_setdisguise((TBL_PC*)bl, buf, len, 0);
  3298. clif_setdisguise((TBL_PC*)bl, buf, len, 1);
  3299. } else
  3300. clif_send(buf,len,bl,AREA);
  3301. return 0;
  3302. }
  3303. //Modifies the type of damage according to status changes [Skotlex]
  3304. #define clif_calc_delay(type,delay) (type==1||type==4||type==0x0a)?type:(delay==0?9:type)
  3305. /*==========================================
  3306. * Estimates walk delay based on the damage criteria. [Skotlex]
  3307. *------------------------------------------
  3308. */
  3309. static int clif_calc_walkdelay(struct block_list *bl,int delay, int type, int damage, int div_) {
  3310. if (type == 4 || type == 9 || damage <=0)
  3311. return 0;
  3312. if (bl->type == BL_PC) {
  3313. if (battle_config.pc_walk_delay_rate != 100)
  3314. delay = delay*battle_config.pc_walk_delay_rate/100;
  3315. } else
  3316. if (battle_config.walk_delay_rate != 100)
  3317. delay = delay*battle_config.walk_delay_rate/100;
  3318. if (div_ > 1) //Multi-hit skills mean higher delays.
  3319. delay += battle_config.multihit_delay*(div_-1);
  3320. return delay>0?delay:1; //Return 1 to specify there should be no noticeable delay, but you should stop walking.
  3321. }
  3322. /*==========================================
  3323. * 通常攻撃エフェクト&ダメージ
  3324. *------------------------------------------
  3325. */
  3326. 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)
  3327. {
  3328. unsigned char buf[256];
  3329. struct status_change *sc;
  3330. nullpo_retr(0, src);
  3331. nullpo_retr(0, dst);
  3332. type = clif_calc_delay(type, ddelay); //Type defaults to 0 for normal attacks.
  3333. sc = status_get_sc(dst);
  3334. if(sc && sc->count) {
  3335. if(sc->data[SC_HALLUCINATION].timer != -1) {
  3336. if(damage > 0)
  3337. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3338. if(damage2 > 0)
  3339. damage2 = damage2*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3340. }
  3341. }
  3342. WBUFW(buf,0)=0x8a;
  3343. WBUFL(buf,2)=src->id;
  3344. WBUFL(buf,6)=dst->id;
  3345. WBUFL(buf,10)=tick;
  3346. WBUFL(buf,14)=sdelay;
  3347. WBUFL(buf,18)=ddelay;
  3348. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3349. WBUFW(buf,22)=damage?div:0;
  3350. WBUFW(buf,27)=damage2?div:0;
  3351. } else {
  3352. WBUFW(buf,22)=(damage > SHRT_MAX)?SHRT_MAX:damage;
  3353. WBUFW(buf,27)=damage2;
  3354. }
  3355. WBUFW(buf,24)=div;
  3356. WBUFB(buf,26)=type;
  3357. clif_send(buf,packet_len(0x8a),src,AREA);
  3358. if(disguised(src)) {
  3359. WBUFL(buf,2)=-src->id;
  3360. if(damage > 0)
  3361. WBUFW(buf,22)=-1;
  3362. if(damage2 > 0)
  3363. WBUFW(buf,27)=-1;
  3364. clif_send(buf,packet_len(0x8a),src,SELF);
  3365. }
  3366. if (disguised(dst)) {
  3367. WBUFL(buf,6)=-dst->id;
  3368. if (disguised(src))
  3369. WBUFL(buf,2)=src->id;
  3370. else {
  3371. if(damage > 0)
  3372. WBUFW(buf,22)=-1;
  3373. if(damage2 > 0)
  3374. WBUFW(buf,27)=-1;
  3375. }
  3376. clif_send(buf,packet_len(0x8a),dst,SELF);
  3377. }
  3378. //Return adjusted can't walk delay for further processing.
  3379. return clif_calc_walkdelay(dst,ddelay,type,damage+damage2,div);
  3380. }
  3381. /*==========================================
  3382. *
  3383. *------------------------------------------
  3384. */
  3385. void clif_getareachar_item(struct map_session_data* sd,struct flooritem_data* fitem)
  3386. {
  3387. int view,fd;
  3388. fd=sd->fd;
  3389. //009d <ID>.l <item ID>.w <identify flag>.B <X>.w <Y>.w <amount>.w <subX>.B <subY>.B
  3390. WFIFOHEAD(fd,packet_len(0x9d));
  3391. WFIFOW(fd,0)=0x9d;
  3392. WFIFOL(fd,2)=fitem->bl.id;
  3393. if((view = itemdb_viewid(fitem->item_data.nameid)) > 0)
  3394. WFIFOW(fd,6)=view;
  3395. else
  3396. WFIFOW(fd,6)=fitem->item_data.nameid;
  3397. WFIFOB(fd,8)=fitem->item_data.identify;
  3398. WFIFOW(fd,9)=fitem->bl.x;
  3399. WFIFOW(fd,11)=fitem->bl.y;
  3400. WFIFOW(fd,13)=fitem->item_data.amount;
  3401. WFIFOB(fd,15)=fitem->subx;
  3402. WFIFOB(fd,16)=fitem->suby;
  3403. WFIFOSET(fd,packet_len(0x9d));
  3404. }
  3405. /*==========================================
  3406. * 場所スキルエフェクトが視界に入る
  3407. *------------------------------------------
  3408. */
  3409. int clif_getareachar_skillunit(struct map_session_data *sd,struct skill_unit *unit)
  3410. {
  3411. int fd;
  3412. struct block_list *bl;
  3413. fd=sd->fd;
  3414. bl=map_id2bl(unit->group->src_id);
  3415. #if PACKETVER >= 3
  3416. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3417. WFIFOHEAD(fd,packet_len(0x1c9));
  3418. memset(WFIFOP(fd,0),0,packet_len(0x1c9));
  3419. WFIFOW(fd, 0)=0x1c9;
  3420. WFIFOL(fd, 2)=unit->bl.id;
  3421. WFIFOL(fd, 6)=unit->group->src_id;
  3422. WFIFOW(fd,10)=unit->bl.x;
  3423. WFIFOW(fd,12)=unit->bl.y; // might be typo? [Lance]
  3424. WFIFOB(fd,14)=unit->group->unit_id;
  3425. WFIFOB(fd,15)=1;
  3426. WFIFOB(fd,16)=1;
  3427. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3428. WFIFOSET(fd,packet_len(0x1c9));
  3429. return 0;
  3430. }
  3431. #endif
  3432. WFIFOHEAD(fd,packet_len(0x11f));
  3433. memset(WFIFOP(fd,0),0,packet_len(0x11f));
  3434. WFIFOW(fd, 0)=0x11f;
  3435. WFIFOL(fd, 2)=unit->bl.id;
  3436. WFIFOL(fd, 6)=unit->group->src_id;
  3437. WFIFOW(fd,10)=unit->bl.x;
  3438. WFIFOW(fd,12)=unit->bl.y;
  3439. //Use invisible unit id for traps.
  3440. if (battle_config.traps_setting&1 && skill_get_inf2(unit->group->skill_id)&INF2_TRAP)
  3441. WFIFOB(fd,14)=UNT_ATTACK_SKILLS;
  3442. else
  3443. WFIFOB(fd,14)=unit->group->unit_id;
  3444. WFIFOB(fd,15)=0;
  3445. WFIFOSET(fd,packet_len(0x11f));
  3446. if(unit->group->skill_id == WZ_ICEWALL)
  3447. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3448. return 0;
  3449. /* Previous implementation guess of packet 0x1c9, who can understand what all those fields are for? [Skotlex]
  3450. WFIFOHEAD(fd,packet_len(0x1c9));
  3451. memset(WFIFOP(fd,0),0,packet_len(0x1c9));
  3452. WFIFOW(fd, 0)=0x1c9;
  3453. WFIFOL(fd, 2)=unit->bl.id;
  3454. WFIFOL(fd, 6)=unit->group->src_id;
  3455. WFIFOW(fd,10)=unit->bl.x;
  3456. WFIFOW(fd,12)=unit->bl.y;
  3457. WFIFOB(fd,14)=unit->group->unit_id;
  3458. WFIFOB(fd,15)=1;
  3459. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  3460. WFIFOB(fd,16)=1;
  3461. memcpy(WFIFOP(fd,17),unit->group->valstr,MESSAGE_SIZE);
  3462. } else {
  3463. WFIFOL(fd,15+1)=0; //1-4調べた限り固定
  3464. WFIFOL(fd,15+5)=0; //5-8調べた限り固定
  3465. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  3466. WFIFOL(fd,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  3467. WFIFOL(fd,15+17)=0x004f37dd; //17-20調べた限り固定
  3468. WFIFOL(fd,15+21)=0x0012f674; //21-24調べた限り固定
  3469. WFIFOL(fd,15+25)=0x0012f664; //25-28調べた限り固定
  3470. WFIFOL(fd,15+29)=0x0012f654; //29-32調べた限り固定
  3471. WFIFOL(fd,15+33)=0x77527bbc; //33-36調べた限り固定
  3472. //37-39
  3473. WFIFOB(fd,15+40)=0x2d; //40調べた限り固定
  3474. WFIFOL(fd,15+41)=0; //41-44調べた限り0固定
  3475. WFIFOL(fd,15+45)=0; //45-48調べた限り0固定
  3476. WFIFOL(fd,15+49)=0; //49-52調べた限り0固定
  3477. WFIFOL(fd,15+53)=0x0048d919; //53-56調べた限り固定
  3478. WFIFOL(fd,15+57)=0x0000003e; //57-60調べた限り固定
  3479. WFIFOL(fd,15+61)=0x0012f66c; //61-64調べた限り固定
  3480. //65-68
  3481. //69-72
  3482. if(bl) WFIFOL(fd,15+73)=bl->y; //73-76術者のY座標
  3483. WFIFOL(fd,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  3484. WFIFOB(fd,15+81)=0xaa; //81終端文字0xaa
  3485. }
  3486. WFIFOSET(fd,packet_len(0x1c9));
  3487. #endif
  3488. if(unit->group->skill_id == WZ_ICEWALL)
  3489. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,5);
  3490. return 0;
  3491. */
  3492. }
  3493. /*==========================================
  3494. * 場所スキルエフェクトが視界から消える
  3495. *------------------------------------------
  3496. */
  3497. int clif_clearchar_skillunit(struct skill_unit *unit,int fd)
  3498. {
  3499. nullpo_retr(0, unit);
  3500. WFIFOHEAD(fd,packet_len(0x120));
  3501. WFIFOW(fd, 0)=0x120;
  3502. WFIFOL(fd, 2)=unit->bl.id;
  3503. WFIFOSET(fd,packet_len(0x120));
  3504. if(unit->group && unit->group->skill_id == WZ_ICEWALL)
  3505. clif_set0192(fd,unit->bl.m,unit->bl.x,unit->bl.y,unit->val2);
  3506. return 0;
  3507. }
  3508. /*==========================================
  3509. * Unknown... trap related?
  3510. * Only affects units with class [139,153] client-side
  3511. *------------------------------------------
  3512. */
  3513. int clif_01ac(struct block_list *bl)
  3514. {
  3515. unsigned char buf[32];
  3516. nullpo_retr(0, bl);
  3517. WBUFW(buf, 0) = 0x1ac;
  3518. WBUFL(buf, 2) = bl->id;
  3519. clif_send(buf,packet_len(0x1ac),bl,AREA);
  3520. return 0;
  3521. }
  3522. /*==========================================
  3523. *
  3524. *------------------------------------------
  3525. */
  3526. int clif_getareachar(struct block_list* bl,va_list ap)
  3527. {
  3528. struct map_session_data *sd;
  3529. nullpo_retr(0, bl);
  3530. nullpo_retr(0, ap);
  3531. sd=va_arg(ap,struct map_session_data*);
  3532. if (sd == NULL || !sd->fd || session[sd->fd] == NULL)
  3533. return 0;
  3534. switch(bl->type){
  3535. case BL_ITEM:
  3536. clif_getareachar_item(sd,(struct flooritem_data*) bl);
  3537. break;
  3538. case BL_SKILL:
  3539. clif_getareachar_skillunit(sd,(TBL_SKILL*)bl);
  3540. break;
  3541. default:
  3542. if(&sd->bl == bl)
  3543. break;
  3544. clif_getareachar_char(sd,bl);
  3545. break;
  3546. }
  3547. return 0;
  3548. }
  3549. /*==========================================
  3550. * tbl has gone out of view-size of bl
  3551. *------------------------------------------
  3552. */
  3553. int clif_outsight(struct block_list *bl,va_list ap)
  3554. {
  3555. struct block_list *tbl;
  3556. struct view_data *vd;
  3557. TBL_PC *sd, *tsd;
  3558. tbl=va_arg(ap,struct block_list*);
  3559. if(bl == tbl) return 0;
  3560. BL_CAST(BL_PC, bl, sd);
  3561. BL_CAST(BL_PC, tbl, tsd);
  3562. if (tsd && tsd->fd)
  3563. { //tsd has lost sight of the bl object.
  3564. switch(bl->type){
  3565. case BL_PC:
  3566. if (((TBL_PC*)bl)->vd.class_ != INVISIBLE_CLASS)
  3567. clif_clearchar_id(bl->id,0,tsd->fd);
  3568. if(sd->chatID){
  3569. struct chat_data *cd;
  3570. cd=(struct chat_data*)map_id2bl(sd->chatID);
  3571. if(cd->usersd[0]==sd)
  3572. clif_dispchat(cd,tsd->fd);
  3573. }
  3574. if(sd->vender_id)
  3575. clif_closevendingboard(bl,tsd->fd);
  3576. break;
  3577. case BL_ITEM:
  3578. clif_clearflooritem((struct flooritem_data*)bl,tsd->fd);
  3579. break;
  3580. case BL_SKILL:
  3581. clif_clearchar_skillunit((struct skill_unit *)bl,tsd->fd);
  3582. break;
  3583. default:
  3584. if ((vd=status_get_viewdata(bl)) && vd->class_ != INVISIBLE_CLASS)
  3585. clif_clearchar_id(bl->id,0,tsd->fd);
  3586. break;
  3587. }
  3588. }
  3589. if (sd && sd->fd)
  3590. { //sd is watching tbl go out of view.
  3591. if ((vd=status_get_viewdata(tbl)) && vd->class_ != INVISIBLE_CLASS)
  3592. clif_clearchar_id(tbl->id,0,sd->fd);
  3593. }
  3594. return 0;
  3595. }
  3596. /*==========================================
  3597. * tbl has come into view of bl
  3598. *------------------------------------------
  3599. */
  3600. int clif_insight(struct block_list *bl,va_list ap)
  3601. {
  3602. struct block_list *tbl;
  3603. TBL_PC *sd, *tsd;
  3604. tbl=va_arg(ap,struct block_list*);
  3605. if (bl == tbl) return 0;
  3606. BL_CAST(BL_PC, bl, sd);
  3607. BL_CAST(BL_PC, tbl, tsd);
  3608. if (tsd && tsd->fd)
  3609. { //Tell tsd that bl entered into his view
  3610. switch(bl->type){
  3611. case BL_ITEM:
  3612. clif_getareachar_item(tsd,(struct flooritem_data*)bl);
  3613. break;
  3614. case BL_SKILL:
  3615. clif_getareachar_skillunit(tsd,(TBL_SKILL*)bl);
  3616. break;
  3617. default:
  3618. clif_getareachar_char(tsd,bl);
  3619. break;
  3620. }
  3621. }
  3622. if (sd && sd->fd)
  3623. { //Tell sd that tbl walked into his view
  3624. clif_getareachar_char(sd,tbl);
  3625. }
  3626. return 0;
  3627. }
  3628. /*==========================================
  3629. *
  3630. *------------------------------------------
  3631. */
  3632. int clif_skillinfo(struct map_session_data *sd,int skillid,int type,int range)
  3633. {
  3634. int fd,id;
  3635. nullpo_retr(0, sd);
  3636. fd=sd->fd;
  3637. if( (id=sd->status.skill[skillid].id) <= 0 )
  3638. return 0;
  3639. WFIFOHEAD(fd,packet_len(0x147));
  3640. WFIFOW(fd,0)=0x147;
  3641. WFIFOW(fd,2) = id;
  3642. if(type < 0)
  3643. WFIFOW(fd,4) = skill_get_inf(id);
  3644. else
  3645. WFIFOW(fd,4) = type;
  3646. WFIFOW(fd,6) = 0;
  3647. WFIFOW(fd,8) = sd->status.skill[skillid].lv;
  3648. WFIFOW(fd,10) = skill_get_sp(id,sd->status.skill[skillid].lv);
  3649. if(range < 0)
  3650. range = skill_get_range2(&sd->bl, id,sd->status.skill[skillid].lv);
  3651. WFIFOW(fd,12)= range;
  3652. strncpy(WFIFOP(fd,14), skill_get_name(id), NAME_LENGTH);
  3653. if(sd->status.skill[skillid].flag ==0)
  3654. WFIFOB(fd,38)= (sd->status.skill[skillid].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3655. else
  3656. WFIFOB(fd,38) = 0;
  3657. WFIFOSET(fd,packet_len(0x147));
  3658. return 0;
  3659. }
  3660. /*==========================================
  3661. * スキルリストを送信する
  3662. *------------------------------------------
  3663. */
  3664. int clif_skillinfoblock(struct map_session_data *sd)
  3665. {
  3666. int fd;
  3667. int i,c,len=4,id;
  3668. nullpo_retr(0, sd);
  3669. fd=sd->fd;
  3670. if (!fd) return 0;
  3671. WFIFOHEAD(fd, MAX_SKILL * 37 + 4);
  3672. WFIFOW(fd,0)=0x10f;
  3673. for ( i = c = 0; i < MAX_SKILL; i++){
  3674. if( (id=sd->status.skill[i].id)!=0 ){
  3675. WFIFOW(fd,len ) = id;
  3676. WFIFOW(fd,len+2) = skill_get_inf(id);
  3677. WFIFOW(fd,len+4) = 0;
  3678. WFIFOW(fd,len+6) = sd->status.skill[i].lv;
  3679. WFIFOW(fd,len+8) = skill_get_sp(id,sd->status.skill[i].lv);
  3680. WFIFOW(fd,len+10)= skill_get_range2(&sd->bl, id,sd->status.skill[i].lv);
  3681. strncpy(WFIFOP(fd,len+12), skill_get_name(id), NAME_LENGTH);
  3682. if(sd->status.skill[i].flag ==0)
  3683. WFIFOB(fd,len+36)= (sd->status.skill[i].lv < skill_tree_get_max(id, sd->status.class_))? 1:0;
  3684. else
  3685. WFIFOB(fd,len+36) = 0;
  3686. len+=37;
  3687. c++;
  3688. }
  3689. }
  3690. WFIFOW(fd,2)=len;
  3691. WFIFOSET(fd,len);
  3692. return 1;
  3693. }
  3694. /*==========================================
  3695. * スキル割り振り通知
  3696. *------------------------------------------
  3697. */
  3698. int clif_skillup(struct map_session_data *sd,int skill_num)
  3699. {
  3700. int fd;
  3701. nullpo_retr(0, sd);
  3702. fd=sd->fd;
  3703. WFIFOHEAD(fd,packet_len(0x10e));
  3704. WFIFOW(fd,0) = 0x10e;
  3705. WFIFOW(fd,2) = skill_num;
  3706. WFIFOW(fd,4) = sd->status.skill[skill_num].lv;
  3707. WFIFOW(fd,6) = skill_get_sp(skill_num,sd->status.skill[skill_num].lv);
  3708. WFIFOW(fd,8) = skill_get_range2(&sd->bl,skill_num,sd->status.skill[skill_num].lv);
  3709. WFIFOB(fd,10) = (sd->status.skill[skill_num].lv < skill_tree_get_max(sd->status.skill[skill_num].id, sd->status.class_)) ? 1 : 0;
  3710. WFIFOSET(fd,packet_len(0x10e));
  3711. return 0;
  3712. }
  3713. /*==========================================
  3714. * スキル詠唱エフェクトを送信する
  3715. *------------------------------------------
  3716. */
  3717. int clif_skillcasting(struct block_list* bl,
  3718. int src_id,int dst_id,int dst_x,int dst_y,int skill_num,int casttime)
  3719. {
  3720. int pl = skill_get_pl(skill_num, 1); //TODO: Need Skill level here :/
  3721. unsigned char buf[32];
  3722. WBUFW(buf,0) = 0x13e;
  3723. WBUFL(buf,2) = src_id;
  3724. WBUFL(buf,6) = dst_id;
  3725. WBUFW(buf,10) = dst_x;
  3726. WBUFW(buf,12) = dst_y;
  3727. WBUFW(buf,14) = skill_num;
  3728. WBUFL(buf,16) = pl<0?0:pl; //Avoid sending negatives as element [Skotlex]
  3729. WBUFL(buf,20) = casttime;
  3730. clif_send(buf,packet_len(0x13e), bl, AREA);
  3731. if (disguised(bl)) {
  3732. WBUFL(buf,2) = -src_id;
  3733. WBUFL(buf,20) = 0;
  3734. clif_send(buf,packet_len(0x13e), bl, SELF);
  3735. }
  3736. return 0;
  3737. }
  3738. /*==========================================
  3739. *
  3740. *------------------------------------------
  3741. */
  3742. int clif_skillcastcancel(struct block_list* bl)
  3743. {
  3744. unsigned char buf[16];
  3745. nullpo_retr(0, bl);
  3746. WBUFW(buf,0) = 0x1b9;
  3747. WBUFL(buf,2) = bl->id;
  3748. clif_send(buf,packet_len(0x1b9), bl, AREA);
  3749. return 0;
  3750. }
  3751. /// only when type==0:
  3752. /// if(skill_id==NV_BASIC)
  3753. /// btype==0 "skill failed" MsgStringTable[159]
  3754. /// btype==1 "no emotions" MsgStringTable[160]
  3755. /// btype==2 "no sit" MsgStringTable[161]
  3756. /// btype==3 "no chat" MsgStringTable[162]
  3757. /// btype==4 "no party" MsgStringTable[163]
  3758. /// btype==5 "no shout" MsgStringTable[164]
  3759. /// btype==6 "no PKing" MsgStringTable[165]
  3760. /// btype==7 "no alligning" MsgStringTable[383]
  3761. /// btype>=8: ignored
  3762. /// if(skill_id==AL_WARP) "not enough skill level" MsgStringTable[214]
  3763. /// if(skill_id==TF_STEAL) "steal failed" MsgStringTable[205]
  3764. /// if(skill_id==TF_POISON) "envenom failed" MsgStringTable[207]
  3765. /// otherwise "skill failed" MsgStringTable[204]
  3766. /// btype irrelevant
  3767. /// type==1 "insufficient SP" MsgStringTable[202]
  3768. /// type==2 "insufficient HP" MsgStringTable[203]
  3769. /// type==3 "insufficient materials" MsgStringTable[808]
  3770. /// type==4 "there is a delay after using a skill" MsgStringTable[219]
  3771. /// type==5 "insufficient zeny" MsgStringTable[233]
  3772. /// type==6 "wrong weapon" MsgStringTable[239]
  3773. /// type==7 "red jemstone needed" MsgStringTable[246]
  3774. /// type==8 "blue jemstone needed" MsgStringTable[247]
  3775. /// type==9 "overweight" MsgStringTable[580]
  3776. /// type==10 "skill failed" MsgStringTable[285]
  3777. /// type>=11 ignored
  3778. ///
  3779. /// if(success!=0) doesn't display any of the previous messages
  3780. /// Note: when this packet is received an unknown flag is always set to 0,
  3781. /// suggesting this is an ACK packet for the UseSkill packets and should be sent on success too [FlavioJS]
  3782. int clif_skill_fail(struct map_session_data *sd,int skill_id,int type,int btype)
  3783. {
  3784. int fd;
  3785. if (!sd) { //Since this is the most common nullpo....
  3786. ShowDebug("clif_skill_fail: Error, received NULL sd for skill %d\n", skill_id);
  3787. return 0;
  3788. }
  3789. fd=sd->fd;
  3790. if (!fd) return 0;
  3791. if(battle_config.display_skill_fail&1)
  3792. return 0; //Disable all skill failed messages
  3793. if(type==0x4 && !sd->state.showdelay)
  3794. return 0; //Disable delay failed messages
  3795. if(skill_id == RG_SNATCHER && battle_config.display_skill_fail&4)
  3796. return 0;
  3797. if(skill_id == TF_POISON && battle_config.display_skill_fail&8)
  3798. return 0;
  3799. WFIFOHEAD(fd,packet_len(0x110));
  3800. WFIFOW(fd,0) = 0x110;
  3801. WFIFOW(fd,2) = skill_id;
  3802. WFIFOL(fd,4) = btype;
  3803. WFIFOB(fd,8) = 0;// success?
  3804. WFIFOB(fd,9) = type;
  3805. WFIFOSET(fd,packet_len(0x110));
  3806. return 1;
  3807. }
  3808. /*==========================================
  3809. * スキル攻撃エフェクト&ダメージ
  3810. *------------------------------------------
  3811. */
  3812. int clif_skill_damage(struct block_list *src,struct block_list *dst,
  3813. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3814. {
  3815. unsigned char buf[64];
  3816. struct status_change *sc;
  3817. nullpo_retr(0, src);
  3818. nullpo_retr(0, dst);
  3819. type = (type>0)?type:skill_get_hit(skill_id);
  3820. type = clif_calc_delay(type, ddelay);
  3821. sc = status_get_sc(dst);
  3822. if(sc && sc->count) {
  3823. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  3824. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3825. }
  3826. #if PACKETVER < 3
  3827. WBUFW(buf,0)=0x114;
  3828. WBUFW(buf,2)=skill_id;
  3829. WBUFL(buf,4)=src->id;
  3830. WBUFL(buf,8)=dst->id;
  3831. WBUFL(buf,12)=tick;
  3832. WBUFL(buf,16)=sdelay;
  3833. WBUFL(buf,20)=ddelay;
  3834. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3835. WBUFW(buf,24)=damage?div:0;
  3836. } else {
  3837. WBUFW(buf,24)=damage;
  3838. }
  3839. WBUFW(buf,26)=skill_lv;
  3840. WBUFW(buf,28)=div;
  3841. WBUFB(buf,30)=type;
  3842. clif_send(buf,packet_len(0x114),src,AREA);
  3843. if(disguised(src)) {
  3844. WBUFL(buf,4)=-src->id;
  3845. if(damage > 0)
  3846. WBUFW(buf,24)=-1;
  3847. clif_send(buf,packet_len(0x114),src,SELF);
  3848. }
  3849. if (disguised(dst)) {
  3850. WBUFL(buf,8)=-dst->id;
  3851. if (disguised(src))
  3852. WBUFL(buf,4)=src->id;
  3853. else if(damage > 0)
  3854. WBUFW(buf,24)=-1;
  3855. clif_send(buf,packet_len(0x114),dst,SELF);
  3856. }
  3857. #else
  3858. WBUFW(buf,0)=0x1de;
  3859. WBUFW(buf,2)=skill_id;
  3860. WBUFL(buf,4)=src->id;
  3861. WBUFL(buf,8)=dst->id;
  3862. WBUFL(buf,12)=tick;
  3863. WBUFL(buf,16)=sdelay;
  3864. WBUFL(buf,20)=ddelay;
  3865. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3866. WBUFL(buf,24)=damage?div:0;
  3867. } else {
  3868. WBUFL(buf,24)=damage;
  3869. }
  3870. WBUFW(buf,28)=skill_lv;
  3871. WBUFW(buf,30)=div;
  3872. WBUFB(buf,32)=type;
  3873. clif_send(buf,packet_len(0x1de),src,AREA);
  3874. if(disguised(src)) {
  3875. WBUFL(buf,4)=-src->id;
  3876. if(damage > 0)
  3877. WBUFL(buf,24)=-1;
  3878. clif_send(buf,packet_len(0x1de),src,SELF);
  3879. }
  3880. if (disguised(dst)) {
  3881. WBUFL(buf,8)=-dst->id;
  3882. if (disguised(src))
  3883. WBUFL(buf,4)=src->id;
  3884. else if(damage > 0)
  3885. WBUFL(buf,24)=-1;
  3886. clif_send(buf,packet_len(0x1de),dst,SELF);
  3887. }
  3888. #endif
  3889. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3890. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3891. }
  3892. /*==========================================
  3893. * 吹き飛ばしスキル攻撃エフェクト&ダメージ
  3894. *------------------------------------------
  3895. */
  3896. int clif_skill_damage2(struct block_list *src,struct block_list *dst,
  3897. unsigned int tick,int sdelay,int ddelay,int damage,int div,int skill_id,int skill_lv,int type)
  3898. {
  3899. unsigned char buf[64];
  3900. struct status_change *sc;
  3901. nullpo_retr(0, src);
  3902. nullpo_retr(0, dst);
  3903. type = (type>0)?type:skill_get_hit(skill_id);
  3904. type = clif_calc_delay(type, ddelay);
  3905. sc = status_get_sc(dst);
  3906. if(sc && sc->count) {
  3907. if(sc->data[SC_HALLUCINATION].timer != -1 && damage > 0)
  3908. damage = damage*(5+sc->data[SC_HALLUCINATION].val1) + rand()%100;
  3909. }
  3910. WBUFW(buf,0)=0x115;
  3911. WBUFW(buf,2)=skill_id;
  3912. WBUFL(buf,4)=src->id;
  3913. WBUFL(buf,8)=dst->id;
  3914. WBUFL(buf,12)=tick;
  3915. WBUFL(buf,16)=sdelay;
  3916. WBUFL(buf,20)=ddelay;
  3917. WBUFW(buf,24)=dst->x;
  3918. WBUFW(buf,26)=dst->y;
  3919. if (battle_config.hide_woe_damage && map_flag_gvg(src->m)) {
  3920. WBUFW(buf,28)=damage?div:0;
  3921. } else {
  3922. WBUFW(buf,28)=damage;
  3923. }
  3924. WBUFW(buf,30)=skill_lv;
  3925. WBUFW(buf,32)=div;
  3926. WBUFB(buf,34)=type;
  3927. clif_send(buf,packet_len(0x115),src,AREA);
  3928. if(disguised(src)) {
  3929. WBUFL(buf,4)=-src->id;
  3930. if(damage > 0)
  3931. WBUFW(buf,28)=-1;
  3932. clif_send(buf,packet_len(0x115),src,SELF);
  3933. }
  3934. if (disguised(dst)) {
  3935. WBUFL(buf,8)=-dst->id;
  3936. if (disguised(src))
  3937. WBUFL(buf,4)=src->id;
  3938. else if(damage > 0)
  3939. WBUFW(buf,28)=-1;
  3940. clif_send(buf,packet_len(0x115),dst,SELF);
  3941. }
  3942. //Because the damage delay must be synced with the client, here is where the can-walk tick must be updated. [Skotlex]
  3943. return clif_calc_walkdelay(dst,ddelay,type,damage,div);
  3944. }
  3945. /*==========================================
  3946. * 支援/回復スキルエフェクト
  3947. *------------------------------------------
  3948. */
  3949. int clif_skill_nodamage(struct block_list *src,struct block_list *dst,
  3950. int skill_id,int heal,int fail)
  3951. {
  3952. unsigned char buf[32];
  3953. nullpo_retr(0, dst);
  3954. WBUFW(buf,0)=0x11a;
  3955. WBUFW(buf,2)=skill_id;
  3956. WBUFW(buf,4)=(heal > SHRT_MAX)? SHRT_MAX:heal;
  3957. WBUFL(buf,6)=dst->id;
  3958. WBUFL(buf,10)=src?src->id:0;
  3959. WBUFB(buf,14)=fail;
  3960. clif_send(buf,packet_len(0x11a),dst,AREA);
  3961. if (disguised(dst)) {
  3962. WBUFL(buf,6)=-dst->id;
  3963. clif_send(buf,packet_len(0x115),dst,SELF);
  3964. }
  3965. if(src && disguised(src)) {
  3966. WBUFL(buf,10)=-src->id;
  3967. if (disguised(dst))
  3968. WBUFL(buf,6)=dst->id;
  3969. clif_send(buf,packet_len(0x115),src,SELF);
  3970. }
  3971. return fail;
  3972. }
  3973. /*==========================================
  3974. * 場所スキルエフェクト
  3975. *------------------------------------------
  3976. */
  3977. int clif_skill_poseffect(struct block_list *src,int skill_id,int val,int x,int y,int tick)
  3978. {
  3979. unsigned char buf[32];
  3980. nullpo_retr(0, src);
  3981. WBUFW(buf,0)=0x117;
  3982. WBUFW(buf,2)=skill_id;
  3983. WBUFL(buf,4)=src->id;
  3984. WBUFW(buf,8)=val;
  3985. WBUFW(buf,10)=x;
  3986. WBUFW(buf,12)=y;
  3987. WBUFL(buf,14)=tick;
  3988. clif_send(buf,packet_len(0x117),src,AREA);
  3989. if(disguised(src)) {
  3990. WBUFL(buf,4)=-src->id;
  3991. clif_send(buf,packet_len(0x117),src,SELF);
  3992. }
  3993. return 0;
  3994. }
  3995. /*==========================================
  3996. * 場所スキルエフェクト表示
  3997. *------------------------------------------
  3998. */
  3999. int clif_skill_setunit(struct skill_unit *unit)
  4000. {
  4001. unsigned char buf[128];
  4002. struct block_list *bl;
  4003. nullpo_retr(0, unit);
  4004. bl=map_id2bl(unit->group->src_id);
  4005. // These are invisible client-side, but are necessary because
  4006. // otherwise the client will not know who caused the attack.
  4007. // if (unit->group->unit_id == UNT_ATTACK_SKILLS)
  4008. // return 0;
  4009. #if PACKETVER >= 3
  4010. if(unit->group->unit_id==UNT_GRAFFITI) { // Graffiti [Valaris]
  4011. memset(WBUFP(buf, 0),0,packet_len(0x1c9));
  4012. WBUFW(buf, 0)=0x1c9;
  4013. WBUFL(buf, 2)=unit->bl.id;
  4014. WBUFL(buf, 6)=unit->group->src_id;
  4015. WBUFW(buf,10)=unit->bl.x;
  4016. WBUFW(buf,12)=unit->bl.y;
  4017. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE) {
  4018. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4019. } else {
  4020. WBUFB(buf,14)=unit->group->unit_id;
  4021. }
  4022. WBUFB(buf,15)=1;
  4023. WBUFB(buf,16)=1;
  4024. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4025. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4026. return 0;
  4027. }
  4028. #endif
  4029. memset(WBUFP(buf, 0),0,packet_len(0x11f));
  4030. WBUFW(buf, 0)=0x11f;
  4031. WBUFL(buf, 2)=unit->bl.id;
  4032. WBUFL(buf, 6)=unit->group->src_id;
  4033. WBUFW(buf,10)=unit->bl.x;
  4034. WBUFW(buf,12)=unit->bl.y;
  4035. if (unit->group->state.song_dance&0x1 && unit->val2&UF_ENSEMBLE) {
  4036. WBUFB(buf,14)=unit->val2&UF_SONG?UNT_DISSONANCE:UNT_UGLYDANCE;
  4037. } else {
  4038. WBUFB(buf,14)=unit->group->unit_id;
  4039. }
  4040. WBUFB(buf,15)=0;
  4041. clif_send(buf,packet_len(0x11f),&unit->bl,AREA);
  4042. return 0;
  4043. /* Previous mysterious implementation noone really understands. [Skotlex]
  4044. memset(WBUFP(buf, 0),0,packet_len(0x1c9));
  4045. WBUFW(buf, 0)=0x1c9;
  4046. WBUFL(buf, 2)=unit->bl.id;
  4047. WBUFL(buf, 6)=unit->group->src_id;
  4048. WBUFW(buf,10)=unit->bl.x;
  4049. WBUFW(buf,12)=unit->bl.y;
  4050. WBUFB(buf,14)=unit->group->unit_id;
  4051. WBUFB(buf,15)=1;
  4052. if(unit->group->unit_id==0xb0) { // Graffiti [Valaris]
  4053. WBUFB(buf,16)=1;
  4054. memcpy(WBUFP(buf,17),unit->group->valstr,MESSAGE_SIZE);
  4055. } else {
  4056. WBUFL(buf,15+1)=0; //1-4調べた限り固定
  4057. WBUFL(buf,15+5)=0; //5-8調べた限り固定
  4058. //9-12マップごとで一定の77-80とはまた違う4バイトのかなり大きな数字
  4059. WBUFL(buf,15+13)=unit->bl.y - 0x12; //13-16ユニットのY座標-18っぽい(Y:17でFF FF FF FF)
  4060. WBUFL(buf,15+17)=0x004f37dd; //17-20調べた限り固定(0x1b2で0x004fdbddだった)
  4061. WBUFL(buf,15+21)=0x0012f674; //21-24調べた限り固定
  4062. WBUFL(buf,15+25)=0x0012f664; //25-28調べた限り固定
  4063. WBUFL(buf,15+29)=0x0012f654; //29-32調べた限り固定
  4064. WBUFL(buf,15+33)=0x77527bbc; //33-36調べた限り固定
  4065. //37-39
  4066. WBUFB(buf,15+40)=0x2d; //40調べた限り固定
  4067. WBUFL(buf,15+41)=0; //41-44調べた限り0固定
  4068. WBUFL(buf,15+45)=0; //45-48調べた限り0固定
  4069. WBUFL(buf,15+49)=0; //49-52調べた限り0固定
  4070. WBUFL(buf,15+53)=0x0048d919; //53-56調べた限り固定(0x01b2で0x00495119だった)
  4071. WBUFL(buf,15+57)=0x0000003e; //57-60調べた限り固定
  4072. WBUFL(buf,15+61)=0x0012f66c; //61-64調べた限り固定
  4073. //65-68
  4074. //69-72
  4075. if(bl) WBUFL(buf,15+73)=bl->y; //73-76術者のY座標
  4076. WBUFL(buf,15+77)=unit->bl.m; //77-80マップIDかなぁ?かなり2バイトで足りそうな数字
  4077. WBUFB(buf,15+81)=0xaa; //81終端文字0xaa
  4078. }
  4079. clif_send(buf,packet_len(0x1c9),&unit->bl,AREA);
  4080. #endif
  4081. return 0;
  4082. */
  4083. }
  4084. /*==========================================
  4085. * 場所スキルエフェクト削除
  4086. *------------------------------------------
  4087. */
  4088. int clif_skill_delunit(struct skill_unit *unit)
  4089. {
  4090. unsigned char buf[16];
  4091. nullpo_retr(0, unit);
  4092. WBUFW(buf, 0)=0x120;
  4093. WBUFL(buf, 2)=unit->bl.id;
  4094. clif_send(buf,packet_len(0x120),&unit->bl,AREA);
  4095. return 0;
  4096. }
  4097. /*==========================================
  4098. * ワープ場所選択
  4099. *------------------------------------------
  4100. */
  4101. int clif_skill_warppoint(struct map_session_data *sd,int skill_num,int skill_lv,
  4102. const char *map1,const char *map2,const char *map3,const char *map4)
  4103. {
  4104. int fd;
  4105. nullpo_retr(0, sd);
  4106. fd=sd->fd;
  4107. WFIFOHEAD(fd,packet_len(0x11c));
  4108. WFIFOW(fd,0)=0x11c;
  4109. WFIFOW(fd,2)=skill_num;
  4110. strncpy((char*)WFIFOP(fd, 4),map1,MAP_NAME_LENGTH);
  4111. strncpy((char*)WFIFOP(fd,20),map2,MAP_NAME_LENGTH);
  4112. strncpy((char*)WFIFOP(fd,36),map3,MAP_NAME_LENGTH);
  4113. strncpy((char*)WFIFOP(fd,52),map4,MAP_NAME_LENGTH);
  4114. WFIFOSET(fd,packet_len(0x11c));
  4115. sd->menuskill_id = skill_num;
  4116. if (skill_num == AL_WARP)
  4117. sd->menuskill_lv = (sd->ud.skillx<<16)|sd->ud.skilly; //Store warp position here.
  4118. else
  4119. sd->menuskill_lv = skill_lv;
  4120. return 0;
  4121. }
  4122. /*==========================================
  4123. * メモ応答
  4124. *------------------------------------------
  4125. */
  4126. int clif_skill_memo(struct map_session_data *sd,int flag)
  4127. {
  4128. int fd;
  4129. nullpo_retr(0, sd);
  4130. fd=sd->fd;
  4131. WFIFOHEAD(fd,packet_len(0x11e));
  4132. WFIFOW(fd,0)=0x11e;
  4133. WFIFOB(fd,2)=flag;
  4134. WFIFOSET(fd,packet_len(0x11e));
  4135. return 0;
  4136. }
  4137. int clif_skill_teleportmessage(struct map_session_data *sd,int flag)
  4138. {
  4139. int fd;
  4140. nullpo_retr(0, sd);
  4141. fd=sd->fd;
  4142. WFIFOHEAD(fd,packet_len(0x189));
  4143. WFIFOW(fd,0)=0x189;
  4144. WFIFOW(fd,2)=flag;
  4145. WFIFOSET(fd,packet_len(0x189));
  4146. return 0;
  4147. }
  4148. /*==========================================
  4149. * モンスター情報
  4150. *------------------------------------------
  4151. */
  4152. int clif_skill_estimation(struct map_session_data *sd,struct block_list *dst)
  4153. {
  4154. struct status_data *status;
  4155. unsigned char buf[64];
  4156. int i;//, fix;
  4157. nullpo_retr(0, sd);
  4158. nullpo_retr(0, dst);
  4159. if(dst->type!=BL_MOB )
  4160. return 0;
  4161. status = status_get_status_data(dst);
  4162. WBUFW(buf, 0)=0x18c;
  4163. WBUFW(buf, 2)=status_get_class(dst);
  4164. WBUFW(buf, 4)=status_get_lv(dst);
  4165. WBUFW(buf, 6)=status->size;
  4166. WBUFL(buf, 8)=status->hp;
  4167. WBUFW(buf,12)= (battle_config.estimation_type&1?status->def:0)
  4168. +(battle_config.estimation_type&2?status->def2:0);
  4169. WBUFW(buf,14)=status->race;
  4170. WBUFW(buf,16)= (battle_config.estimation_type&1?status->mdef:0)
  4171. +(battle_config.estimation_type&2?status->mdef2:0);
  4172. WBUFW(buf,18)= status->def_ele;
  4173. for(i=0;i<9;i++)
  4174. WBUFB(buf,20+i)= (unsigned char)battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv);
  4175. // The following caps negative attributes to 0 since the client displays them as 255-fix. [Skotlex]
  4176. // WBUFB(buf,20+i)= (unsigned char)((fix=battle_attr_fix(NULL,dst,100,i+1,status->def_ele, status->ele_lv))<0?0:fix);
  4177. clif_send(buf,packet_len(0x18c),&sd->bl,
  4178. sd->status.party_id>0?PARTY_SAMEMAP:SELF);
  4179. return 0;
  4180. }
  4181. /*==========================================
  4182. * アイテム合成可能リスト
  4183. *------------------------------------------
  4184. */
  4185. int clif_skill_produce_mix_list(struct map_session_data *sd, int trigger)
  4186. {
  4187. int i,c,view,fd;
  4188. nullpo_retr(0, sd);
  4189. if(sd->menuskill_id == AM_PHARMACY)
  4190. return 0; //Avoid resending the menu twice or more times...
  4191. fd=sd->fd;
  4192. WFIFOHEAD(fd, MAX_SKILL_PRODUCE_DB * 8 + 8);
  4193. WFIFOW(fd, 0)=0x18d;
  4194. for(i=0,c=0;i<MAX_SKILL_PRODUCE_DB;i++){
  4195. if( skill_can_produce_mix(sd,skill_produce_db[i].nameid,trigger, 1) ){
  4196. if((view = itemdb_viewid(skill_produce_db[i].nameid)) > 0)
  4197. WFIFOW(fd,c*8+ 4)= view;
  4198. else
  4199. WFIFOW(fd,c*8+ 4)= skill_produce_db[i].nameid;
  4200. WFIFOW(fd,c*8+ 6)= 0x0012;
  4201. WFIFOL(fd,c*8+ 8)= sd->status.char_id;
  4202. c++;
  4203. }
  4204. }
  4205. WFIFOW(fd, 2)=c*8+8;
  4206. WFIFOSET(fd,WFIFOW(fd,2));
  4207. if(c > 0) {
  4208. sd->menuskill_id = AM_PHARMACY;
  4209. sd->menuskill_lv = trigger;
  4210. return 1;
  4211. }
  4212. return 0;
  4213. }
  4214. /*==========================================
  4215. * Sends a status change packet to the object only, used for loading status changes. [Skotlex]
  4216. *------------------------------------------
  4217. */
  4218. int clif_status_load(struct block_list *bl,int type, int flag)
  4219. {
  4220. int fd;
  4221. if (type == SI_BLANK) //It shows nothing on the client...
  4222. return 0;
  4223. if (bl->type != BL_PC)
  4224. return 0;
  4225. fd = ((struct map_session_data*)bl)->fd;
  4226. WFIFOHEAD(fd,packet_len(0x196));
  4227. WFIFOW(fd,0)=0x0196;
  4228. WFIFOW(fd,2)=type;
  4229. WFIFOL(fd,4)=bl->id;
  4230. WFIFOB(fd,8)=flag; //Status start
  4231. WFIFOSET(fd, packet_len(0x196));
  4232. return 0;
  4233. }
  4234. /*==========================================
  4235. * 状態異常アイコン/メッセージ表示
  4236. *------------------------------------------
  4237. */
  4238. int clif_status_change(struct block_list *bl,int type,int flag)
  4239. {
  4240. unsigned char buf[16];
  4241. if (type == SI_BLANK) //It shows nothing on the client...
  4242. return 0;
  4243. nullpo_retr(0, bl);
  4244. WBUFW(buf,0)=0x0196;
  4245. WBUFW(buf,2)=type;
  4246. WBUFL(buf,4)=bl->id;
  4247. WBUFB(buf,8)=flag;
  4248. clif_send(buf,packet_len(0x196),bl,AREA);
  4249. return 0;
  4250. }
  4251. /*==========================================
  4252. * Send message (modified by [Yor])
  4253. *------------------------------------------
  4254. */
  4255. int clif_displaymessage(const int fd, const char* mes)
  4256. {
  4257. // invalid pointer?
  4258. nullpo_retr(-1, mes);
  4259. //Scrapped, as these are shared by disconnected players =X [Skotlex]
  4260. if (fd == 0)
  4261. return 0;
  4262. else {
  4263. int len_mes = strlen(mes);
  4264. if (len_mes > 0) { // don't send a void message (it's not displaying on the client chat). @help can send void line.
  4265. WFIFOHEAD(fd, 5 + len_mes);
  4266. WFIFOW(fd,0) = 0x8e;
  4267. WFIFOW(fd,2) = 5 + len_mes; // 4 + len + NULL teminate
  4268. memcpy(WFIFOP(fd,4), mes, len_mes + 1);
  4269. WFIFOSET(fd, 5 + len_mes);
  4270. }
  4271. }
  4272. return 0;
  4273. }
  4274. /*==========================================
  4275. * 天の声を送信する
  4276. *------------------------------------------
  4277. */
  4278. int clif_GMmessage(struct block_list* bl, const char* mes, int len, int flag)
  4279. {
  4280. unsigned char *buf;
  4281. int lp;
  4282. lp = (flag & 0x10) ? 8 : 4;
  4283. buf = (unsigned char*)aMallocA((len + lp + 8)*sizeof(unsigned char));
  4284. WBUFW(buf,0) = 0x9a;
  4285. WBUFW(buf,2) = len + lp;
  4286. WBUFL(buf,4) = 0x65756c62; //"blue":
  4287. memcpy(WBUFP(buf,lp), mes, len);
  4288. flag &= 0x07;
  4289. clif_send(buf, WBUFW(buf,2), bl,
  4290. (flag == 1) ? ALL_SAMEMAP :
  4291. (flag == 2) ? AREA :
  4292. (flag == 3) ? SELF :
  4293. ALL_CLIENT);
  4294. if(buf) aFree(buf);
  4295. if(use_irc && irc_announce_flag && !flag)
  4296. irc_announce(mes);
  4297. return 0;
  4298. }
  4299. /*==========================================
  4300. * グローバルメッセージ
  4301. *------------------------------------------
  4302. */
  4303. void clif_GlobalMessage(struct block_list* bl, const char* message)
  4304. {
  4305. char buf[100];
  4306. int len;
  4307. nullpo_retv(bl);
  4308. if(!message)
  4309. return;
  4310. len = strlen(message)+1;
  4311. WBUFW(buf,0)=0x8d;
  4312. WBUFW(buf,2)=len+8;
  4313. WBUFL(buf,4)=bl->id;
  4314. strncpy((char *) WBUFP(buf,8),message,len);
  4315. clif_send((unsigned char *) buf,WBUFW(buf,2),bl,ALL_CLIENT);
  4316. }
  4317. /*==========================================
  4318. * Send main chat message [LuzZza]
  4319. *------------------------------------------
  4320. */
  4321. void clif_MainChatMessage(const char* message) {
  4322. char buf[200];
  4323. int len;
  4324. if(!message)
  4325. return;
  4326. len = strlen(message)+1;
  4327. if (len+8 > sizeof(buf)) {
  4328. ShowDebug("clif_MainChatMessage: Received message too long (len %d): %s\n", len, message);
  4329. len = sizeof(buf)-8;
  4330. }
  4331. WBUFW(buf,0)=0x8d;
  4332. WBUFW(buf,2)=len+8;
  4333. WBUFL(buf,4)=0;
  4334. strncpy((char *) WBUFP(buf,8),message,len);
  4335. clif_send((unsigned char *) buf,WBUFW(buf,2),NULL,CHAT_MAINCHAT);
  4336. }
  4337. /*==========================================
  4338. * Does an announce message in the given color.
  4339. *------------------------------------------
  4340. */
  4341. int clif_announce(struct block_list* bl, const char* mes, int len, unsigned long color, int flag)
  4342. {
  4343. unsigned char *buf;
  4344. buf = (unsigned char*)aMallocA((len + 16)*sizeof(unsigned char));
  4345. WBUFW(buf,0) = 0x1c3;
  4346. WBUFW(buf,2) = len + 16;
  4347. WBUFL(buf,4) = color;
  4348. WBUFW(buf,8) = 0x190; //Font style? Type?
  4349. WBUFW(buf,10) = 0x0c; //12? Font size?
  4350. WBUFL(buf,12) = 0; //Unknown!
  4351. memcpy(WBUFP(buf,16), mes, len);
  4352. flag &= 0x07;
  4353. clif_send(buf, WBUFW(buf,2), bl,
  4354. (flag == 1) ? ALL_SAMEMAP :
  4355. (flag == 2) ? AREA :
  4356. (flag == 3) ? SELF :
  4357. ALL_CLIENT);
  4358. if(buf) aFree(buf);
  4359. return 0;
  4360. }
  4361. /*==========================================
  4362. * HPSP回復エフェクトを送信する
  4363. *------------------------------------------
  4364. */
  4365. int clif_heal(int fd,int type,int val)
  4366. {
  4367. WFIFOHEAD(fd,packet_len(0x13d));
  4368. WFIFOW(fd,0)=0x13d;
  4369. WFIFOW(fd,2)=type;
  4370. WFIFOW(fd,4)=val;
  4371. WFIFOSET(fd,packet_len(0x13d));
  4372. return 0;
  4373. }
  4374. /*==========================================
  4375. * 復活する
  4376. *------------------------------------------
  4377. */
  4378. int clif_resurrection(struct block_list *bl,int type)
  4379. {
  4380. unsigned char buf[16];
  4381. nullpo_retr(0, bl);
  4382. WBUFW(buf,0)=0x148;
  4383. WBUFL(buf,2)=bl->id;
  4384. WBUFW(buf,6)=type;
  4385. clif_send(buf,packet_len(0x148),bl,type==1 ? AREA : AREA_WOS);
  4386. if (disguised(bl))
  4387. clif_spawn(bl);
  4388. return 0;
  4389. }
  4390. /*==========================================
  4391. * PVP実装?(仮)
  4392. *------------------------------------------
  4393. */
  4394. int clif_set0199(int fd,int type)
  4395. {
  4396. WFIFOHEAD(fd,packet_len(0x199));
  4397. WFIFOW(fd,0)=0x199;
  4398. WFIFOW(fd,2)=type;
  4399. WFIFOSET(fd,packet_len(0x199));
  4400. return 0;
  4401. }
  4402. /*==========================================
  4403. * PVP実装?(仮)
  4404. *------------------------------------------
  4405. */
  4406. int clif_pvpset(struct map_session_data *sd,int pvprank,int pvpnum,int type)
  4407. {
  4408. int fd = sd->fd;
  4409. if(type == 2) {
  4410. WFIFOHEAD(fd,packet_len(0x19a));
  4411. WFIFOW(fd,0) = 0x19a;
  4412. WFIFOL(fd,2) = sd->bl.id;
  4413. WFIFOL(fd,6) = pvprank;
  4414. WFIFOL(fd,10) = pvpnum;
  4415. WFIFOSET(fd,packet_len(0x19a));
  4416. } else {
  4417. unsigned char buf[32];
  4418. WBUFW(buf,0) = 0x19a;
  4419. WBUFL(buf,2) = sd->bl.id;
  4420. if(sd->sc.option&(OPTION_HIDE|OPTION_CLOAK))
  4421. WBUFL(buf,6) = ULONG_MAX; //On client displays as --
  4422. else
  4423. WBUFL(buf,6) = pvprank;
  4424. WBUFL(buf,10) = pvpnum;
  4425. if(sd->sc.option&OPTION_INVISIBLE)
  4426. clif_send(buf,packet_len(0x19a),&sd->bl,SELF);
  4427. else if(!type)
  4428. clif_send(buf,packet_len(0x19a),&sd->bl,AREA);
  4429. else
  4430. clif_send(buf,packet_len(0x19a),&sd->bl,ALL_SAMEMAP);
  4431. }
  4432. return 0;
  4433. }
  4434. /*==========================================
  4435. *
  4436. *------------------------------------------
  4437. */
  4438. int clif_send0199(int map,int type)
  4439. {
  4440. struct block_list bl;
  4441. unsigned char buf[16];
  4442. bl.id = 0;
  4443. bl.type = BL_NUL;
  4444. bl.m = map;
  4445. WBUFW(buf,0)=0x199;
  4446. WBUFW(buf,2)=type;
  4447. clif_send(buf,packet_len(0x199),&bl,ALL_SAMEMAP);
  4448. return 0;
  4449. }
  4450. /*==========================================
  4451. * 精錬エフェクトを送信する
  4452. *------------------------------------------
  4453. */
  4454. void clif_refine(int fd, int fail, int index, int val)
  4455. {
  4456. WFIFOHEAD(fd,packet_len(0x188));
  4457. WFIFOW(fd,0)=0x188;
  4458. WFIFOW(fd,2)=fail;
  4459. WFIFOW(fd,4)=index+2;
  4460. WFIFOW(fd,6)=val;
  4461. WFIFOSET(fd,packet_len(0x188));
  4462. }
  4463. /// result=0: "weapon upgrated: %s" MsgStringTable[911] in rgb(0,255,255)
  4464. /// result=1: "weapon upgrated: %s" MsgStringTable[912] in rgb(0,205,205)
  4465. /// result=2: "cannot upgrade %s until you level up the upgrade weapon skill" MsgStringTable[913] in rgb(255,200,200)
  4466. /// result=3: "you lack the item %s to upgrade the weapon" MsgStringTable[914] in rgb(255,200,200)
  4467. void clif_upgrademessage(int fd, int result, int item_id)
  4468. {
  4469. WFIFOHEAD(fd,packet_len(0x223));
  4470. WFIFOW(fd,0)=0x223;
  4471. WFIFOL(fd,2)=result;
  4472. WFIFOW(fd,6)=item_id;
  4473. WFIFOSET(fd,packet_len(0x223));
  4474. }
  4475. /*==========================================
  4476. * Wisp/page is transmitted to the destination player
  4477. *------------------------------------------
  4478. */
  4479. int clif_wis_message(int fd, const char* nick, const char* mes, int mes_len) // R 0097 <len>.w <nick>.24B <message>.?B
  4480. {
  4481. // printf("clif_wis_message(%d, %s, %s)\n", fd, nick, mes);
  4482. WFIFOHEAD(fd, mes_len + NAME_LENGTH + 4);
  4483. WFIFOW(fd,0) = 0x97;
  4484. WFIFOW(fd,2) = mes_len + NAME_LENGTH + 4;
  4485. memcpy(WFIFOP(fd,4), nick, NAME_LENGTH);
  4486. memcpy(WFIFOP(fd,28), mes, mes_len);
  4487. WFIFOSET(fd,WFIFOW(fd,2));
  4488. return 0;
  4489. }
  4490. /*==========================================
  4491. * The transmission result of Wisp/page is transmitted to the source player
  4492. *------------------------------------------
  4493. */
  4494. int clif_wis_end(int fd, int flag) // R 0098 <type>.B: 0: success to send wisper, 1: target character is not loged in, 2: ignored by target, 3: everyone ignored by target
  4495. {
  4496. WFIFOHEAD(fd,packet_len(0x98));
  4497. WFIFOW(fd,0) = 0x98;
  4498. WFIFOW(fd,2) = flag;
  4499. WFIFOSET(fd,packet_len(0x98));
  4500. return 0;
  4501. }
  4502. /*==========================================
  4503. * キャラID名前引き結果を送信する
  4504. *------------------------------------------
  4505. */
  4506. int clif_solved_charname(struct map_session_data *sd,int char_id)
  4507. {
  4508. char *p= map_charid2nick(char_id);
  4509. int fd;
  4510. nullpo_retr(0, sd);
  4511. fd=sd->fd;
  4512. if(p!=NULL){
  4513. WFIFOHEAD(fd,packet_len(0x194));
  4514. WFIFOW(fd,0)=0x194;
  4515. WFIFOL(fd,2)=char_id;
  4516. memcpy(WFIFOP(fd,6), p, NAME_LENGTH);
  4517. WFIFOSET(fd,packet_len(0x194));
  4518. }else{
  4519. map_reqchariddb(sd,char_id);
  4520. chrif_searchcharid(char_id);
  4521. }
  4522. return 0;
  4523. }
  4524. /*==========================================
  4525. * カードの挿入可能リストを返す
  4526. *------------------------------------------
  4527. */
  4528. int clif_use_card(struct map_session_data *sd,int idx)
  4529. {
  4530. int i,c,ep;
  4531. int fd=sd->fd;
  4532. nullpo_retr(0, sd);
  4533. if (idx < 0 || idx >= MAX_INVENTORY) //Crash-fix from bad packets.
  4534. return 0;
  4535. if (!sd->inventory_data[idx] || sd->inventory_data[idx]->type != IT_CARD)
  4536. return 0; //Avoid parsing invalid item indexes (no card/no item)
  4537. ep=sd->inventory_data[idx]->equip;
  4538. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4539. WFIFOW(fd,0)=0x017b;
  4540. for(i=c=0;i<MAX_INVENTORY;i++){
  4541. int j;
  4542. if(sd->inventory_data[i] == NULL)
  4543. continue;
  4544. if(sd->inventory_data[i]->type!=IT_WEAPON && sd->inventory_data[i]->type!=IT_ARMOR)
  4545. continue;
  4546. if(itemdb_isspecial(sd->status.inventory[i].card[0])) //Can't slot it
  4547. continue;
  4548. if(sd->status.inventory[i].identify==0 ) //Not identified
  4549. continue;
  4550. if((sd->inventory_data[i]->equip&ep)==0) //Not equippable on this part.
  4551. continue;
  4552. if(sd->inventory_data[i]->type==IT_WEAPON && ep==EQP_HAND_L) //Shield card won't go on left weapon.
  4553. continue;
  4554. for(j=0;j<sd->inventory_data[i]->slot;j++){
  4555. if( sd->status.inventory[i].card[j]==0 )
  4556. break;
  4557. }
  4558. if(j==sd->inventory_data[i]->slot) // No room
  4559. continue;
  4560. WFIFOW(fd,4+c*2)=i+2;
  4561. c++;
  4562. }
  4563. WFIFOW(fd,2)=4+c*2;
  4564. WFIFOSET(fd,WFIFOW(fd,2));
  4565. return 0;
  4566. }
  4567. /*==========================================
  4568. * カードの挿入終了
  4569. *------------------------------------------
  4570. */
  4571. int clif_insert_card(struct map_session_data *sd,int idx_equip,int idx_card,int flag)
  4572. {
  4573. int fd;
  4574. nullpo_retr(0, sd);
  4575. fd=sd->fd;
  4576. WFIFOHEAD(fd,packet_len(0x17d));
  4577. WFIFOW(fd,0)=0x17d;
  4578. WFIFOW(fd,2)=idx_equip+2;
  4579. WFIFOW(fd,4)=idx_card+2;
  4580. WFIFOB(fd,6)=flag;
  4581. WFIFOSET(fd,packet_len(0x17d));
  4582. return 0;
  4583. }
  4584. /*==========================================
  4585. * 鑑定可能アイテムリスト送信
  4586. *------------------------------------------
  4587. */
  4588. int clif_item_identify_list(struct map_session_data *sd)
  4589. {
  4590. int i,c;
  4591. int fd;
  4592. nullpo_retr(0, sd);
  4593. fd=sd->fd;
  4594. WFIFOHEAD(fd,MAX_INVENTORY * 2 + 4);
  4595. WFIFOW(fd,0)=0x177;
  4596. for(i=c=0;i<MAX_INVENTORY;i++){
  4597. if(sd->status.inventory[i].nameid > 0 && !sd->status.inventory[i].identify){
  4598. WFIFOW(fd,c*2+4)=i+2;
  4599. c++;
  4600. }
  4601. }
  4602. if(c > 0) {
  4603. WFIFOW(fd,2)=c*2+4;
  4604. WFIFOSET(fd,WFIFOW(fd,2));
  4605. sd->menuskill_id = MC_IDENTIFY;
  4606. sd->menuskill_lv = c;
  4607. }
  4608. return 0;
  4609. }
  4610. /*==========================================
  4611. * 鑑定結果
  4612. *------------------------------------------
  4613. */
  4614. int clif_item_identified(struct map_session_data *sd,int idx,int flag)
  4615. {
  4616. int fd;
  4617. nullpo_retr(0, sd);
  4618. fd=sd->fd;
  4619. WFIFOHEAD(fd,packet_len(0x179));
  4620. WFIFOW(fd, 0)=0x179;
  4621. WFIFOW(fd, 2)=idx+2;
  4622. WFIFOB(fd, 4)=flag;
  4623. WFIFOSET(fd,packet_len(0x179));
  4624. return 0;
  4625. }
  4626. /*==========================================
  4627. * 修理可能アイテムリスト送信
  4628. *------------------------------------------
  4629. */
  4630. int clif_item_repair_list(struct map_session_data *sd,struct map_session_data *dstsd)
  4631. {
  4632. int i,c;
  4633. int fd;
  4634. int nameid;
  4635. nullpo_retr(0, sd);
  4636. nullpo_retr(0, dstsd);
  4637. fd=sd->fd;
  4638. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4639. WFIFOW(fd,0)=0x1fc;
  4640. for(i=c=0;i<MAX_INVENTORY;i++){
  4641. if((nameid=dstsd->status.inventory[i].nameid) > 0 && dstsd->status.inventory[i].attribute!=0){// && skill_can_repair(sd,nameid)){
  4642. WFIFOW(fd,c*13+4) = i;
  4643. WFIFOW(fd,c*13+6) = nameid;
  4644. WFIFOL(fd,c*13+8) = sd->status.char_id;
  4645. WFIFOL(fd,c*13+12)= dstsd->status.char_id;
  4646. WFIFOB(fd,c*13+16)= c;
  4647. c++;
  4648. }
  4649. }
  4650. if(c > 0) {
  4651. WFIFOW(fd,2)=c*13+4;
  4652. WFIFOSET(fd,WFIFOW(fd,2));
  4653. sd->menuskill_id = BS_REPAIRWEAPON;
  4654. sd->menuskill_lv = dstsd->bl.id;
  4655. }else
  4656. clif_skill_fail(sd,sd->ud.skillid,0,0);
  4657. return 0;
  4658. }
  4659. int clif_item_repaireffect(struct map_session_data *sd,int nameid,int flag)
  4660. {
  4661. int view,fd;
  4662. nullpo_retr(0, sd);
  4663. fd=sd->fd;
  4664. WFIFOHEAD(fd,packet_len(0x1fe));
  4665. WFIFOW(fd, 0)=0x1fe;
  4666. if((view = itemdb_viewid(nameid)) > 0)
  4667. WFIFOW(fd, 2)=view;
  4668. else
  4669. WFIFOW(fd, 2)=nameid;
  4670. WFIFOB(fd, 4)=flag;
  4671. WFIFOSET(fd,packet_len(0x1fe));
  4672. return 0;
  4673. }
  4674. /*==========================================
  4675. * Weapon Refining - Taken from jAthena
  4676. *------------------------------------------
  4677. */
  4678. int clif_item_refine_list(struct map_session_data *sd)
  4679. {
  4680. int i,c;
  4681. int fd;
  4682. int skilllv;
  4683. int wlv;
  4684. int refine_item[5];
  4685. nullpo_retr(0, sd);
  4686. skilllv = pc_checkskill(sd,WS_WEAPONREFINE);
  4687. fd=sd->fd;
  4688. refine_item[0] = -1;
  4689. refine_item[1] = pc_search_inventory(sd,1010);
  4690. refine_item[2] = pc_search_inventory(sd,1011);
  4691. refine_item[3] = refine_item[4] = pc_search_inventory(sd,984);
  4692. WFIFOHEAD(fd, MAX_INVENTORY * 13 + 4);
  4693. WFIFOW(fd,0)=0x221;
  4694. for(i=c=0;i<MAX_INVENTORY;i++){
  4695. if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].refine < skilllv &&
  4696. sd->status.inventory[i].identify && (wlv=itemdb_wlv(sd->status.inventory[i].nameid)) >=1 &&
  4697. refine_item[wlv]!=-1 && !(sd->status.inventory[i].equip&0x0022)){
  4698. WFIFOW(fd,c*13+ 4)=i+2;
  4699. WFIFOW(fd,c*13+ 6)=sd->status.inventory[i].nameid;
  4700. WFIFOW(fd,c*13+ 8)=0; //TODO: Wonder what are these for? Perhaps ID of weapon's crafter if any?
  4701. WFIFOW(fd,c*13+10)=0;
  4702. WFIFOB(fd,c*13+12)=c;
  4703. c++;
  4704. }
  4705. }
  4706. WFIFOW(fd,2)=c*13+4;
  4707. WFIFOSET(fd,WFIFOW(fd,2));
  4708. if (c > 0) {
  4709. sd->menuskill_id = WS_WEAPONREFINE;
  4710. sd->menuskill_lv = skilllv;
  4711. }
  4712. return 0;
  4713. }
  4714. /*==========================================
  4715. * アイテムによる一時的なスキル効果
  4716. *------------------------------------------
  4717. */
  4718. int clif_item_skill(struct map_session_data *sd,int skillid,int skilllv)
  4719. {
  4720. int fd;
  4721. nullpo_retr(0, sd);
  4722. fd=sd->fd;
  4723. WFIFOHEAD(fd,packet_len(0x147));
  4724. WFIFOW(fd, 0)=0x147;
  4725. WFIFOW(fd, 2)=skillid;
  4726. WFIFOW(fd, 4)=skill_get_inf(skillid);
  4727. WFIFOW(fd, 6)=0;
  4728. WFIFOW(fd, 8)=skilllv;
  4729. WFIFOW(fd,10)=skill_get_sp(skillid,skilllv);
  4730. WFIFOW(fd,12)=skill_get_range2(&sd->bl, skillid,skilllv);
  4731. strncpy((char*)WFIFOP(fd,14),skill_get_name(skillid),NAME_LENGTH);
  4732. WFIFOB(fd,38)=0;
  4733. WFIFOSET(fd,packet_len(0x147));
  4734. return 0;
  4735. }
  4736. /*==========================================
  4737. * カートにアイテム追加
  4738. *------------------------------------------
  4739. */
  4740. int clif_cart_additem(struct map_session_data *sd,int n,int amount,int fail)
  4741. {
  4742. int view,fd;
  4743. unsigned char *buf;
  4744. nullpo_retr(0, sd);
  4745. fd=sd->fd;
  4746. WFIFOHEAD(fd,packet_len(0x124));
  4747. buf=WFIFOP(fd,0);
  4748. if(n<0 || n>=MAX_CART || sd->status.cart[n].nameid<=0)
  4749. return 1;
  4750. WBUFW(buf,0)=0x124;
  4751. WBUFW(buf,2)=n+2;
  4752. WBUFL(buf,4)=amount;
  4753. if((view = itemdb_viewid(sd->status.cart[n].nameid)) > 0)
  4754. WBUFW(buf,8)=view;
  4755. else
  4756. WBUFW(buf,8)=sd->status.cart[n].nameid;
  4757. WBUFB(buf,10)=sd->status.cart[n].identify;
  4758. WBUFB(buf,11)=sd->status.cart[n].attribute;
  4759. WBUFB(buf,12)=sd->status.cart[n].refine;
  4760. clif_addcards(WBUFP(buf,13), &sd->status.cart[n]);
  4761. WFIFOSET(fd,packet_len(0x124));
  4762. return 0;
  4763. }
  4764. /*==========================================
  4765. * カートからアイテム削除
  4766. *------------------------------------------
  4767. */
  4768. int clif_cart_delitem(struct map_session_data *sd,int n,int amount)
  4769. {
  4770. int fd;
  4771. nullpo_retr(0, sd);
  4772. fd=sd->fd;
  4773. WFIFOHEAD(fd,packet_len(0x125));
  4774. WFIFOW(fd,0)=0x125;
  4775. WFIFOW(fd,2)=n+2;
  4776. WFIFOL(fd,4)=amount;
  4777. WFIFOSET(fd,packet_len(0x125));
  4778. return 0;
  4779. }
  4780. /*==========================================
  4781. * 露店開設
  4782. *------------------------------------------
  4783. */
  4784. int clif_openvendingreq(struct map_session_data *sd,int num)
  4785. {
  4786. int fd;
  4787. nullpo_retr(0, sd);
  4788. fd=sd->fd;
  4789. WFIFOHEAD(fd,packet_len(0x12d));
  4790. WFIFOW(fd,0)=0x12d;
  4791. WFIFOW(fd,2)=num;
  4792. WFIFOSET(fd,packet_len(0x12d));
  4793. return 0;
  4794. }
  4795. /*==========================================
  4796. * 露店看板表示
  4797. *------------------------------------------
  4798. */
  4799. int clif_showvendingboard(struct block_list* bl, const char* message, int fd)
  4800. {
  4801. unsigned char buf[128];
  4802. nullpo_retr(0, bl);
  4803. WBUFW(buf,0)=0x131;
  4804. WBUFL(buf,2)=bl->id;
  4805. strncpy((char*)WBUFP(buf,6),message,80);
  4806. if(fd){
  4807. WFIFOHEAD(fd,packet_len(0x131));
  4808. memcpy(WFIFOP(fd,0),buf,packet_len(0x131));
  4809. WFIFOSET(fd,packet_len(0x131));
  4810. }else{
  4811. clif_send(buf,packet_len(0x131),bl,AREA_WOS);
  4812. }
  4813. return 0;
  4814. }
  4815. /*==========================================
  4816. * 露店看板消去
  4817. *------------------------------------------
  4818. */
  4819. int clif_closevendingboard(struct block_list* bl,int fd)
  4820. {
  4821. unsigned char buf[16];
  4822. nullpo_retr(0, bl);
  4823. WBUFW(buf,0)=0x132;
  4824. WBUFL(buf,2)=bl->id;
  4825. if(fd){
  4826. WFIFOHEAD(fd,packet_len(0x132));
  4827. memcpy(WFIFOP(fd,0),buf,packet_len(0x132));
  4828. WFIFOSET(fd,packet_len(0x132));
  4829. }else{
  4830. clif_send(buf,packet_len(0x132),bl,AREA_WOS);
  4831. }
  4832. return 0;
  4833. }
  4834. /*==========================================
  4835. * 露店アイテムリスト
  4836. *------------------------------------------
  4837. */
  4838. int clif_vendinglist(struct map_session_data *sd,int id,struct vending *vending)
  4839. {
  4840. struct item_data *data;
  4841. int i,n,index,fd;
  4842. struct map_session_data *vsd;
  4843. unsigned char *buf;
  4844. nullpo_retr(0, sd);
  4845. nullpo_retr(0, vending);
  4846. nullpo_retr(0, vsd=map_id2sd(id));
  4847. fd=sd->fd;
  4848. WFIFOHEAD(fd, 8+vsd->vend_num*22);
  4849. buf = WFIFOP(fd,0);
  4850. for(i=0,n=0;i<vsd->vend_num;i++){
  4851. if(vending[i].amount<=0)
  4852. continue;
  4853. WBUFL(buf,8+n*22)=vending[i].value;
  4854. WBUFW(buf,12+n*22)=vending[i].amount;
  4855. WBUFW(buf,14+n*22)=(index=vending[i].index)+2;
  4856. if(vsd->status.cart[index].nameid <= 0 || vsd->status.cart[index].amount <= 0)
  4857. continue;
  4858. data = itemdb_search(vsd->status.cart[index].nameid);
  4859. WBUFB(buf,16+n*22)=itemtype(data->type);
  4860. if(data->view_id > 0)
  4861. WBUFW(buf,17+n*22)=data->view_id;
  4862. else
  4863. WBUFW(buf,17+n*22)=vsd->status.cart[index].nameid;
  4864. WBUFB(buf,19+n*22)=vsd->status.cart[index].identify;
  4865. WBUFB(buf,20+n*22)=vsd->status.cart[index].attribute;
  4866. WBUFB(buf,21+n*22)=vsd->status.cart[index].refine;
  4867. clif_addcards(WBUFP(buf, 22+n*22), &vsd->status.cart[index]);
  4868. n++;
  4869. }
  4870. if(n > 0){
  4871. WBUFW(buf,0)=0x133;
  4872. WBUFW(buf,2)=8+n*22;
  4873. WBUFL(buf,4)=id;
  4874. WFIFOSET(fd,WFIFOW(fd,2));
  4875. }
  4876. return 0;
  4877. }
  4878. /*==========================================
  4879. * 露店アイテム購入失敗
  4880. *------------------------------------------
  4881. */
  4882. int clif_buyvending(struct map_session_data *sd,int index,int amount,int fail)
  4883. {
  4884. int fd;
  4885. nullpo_retr(0, sd);
  4886. fd=sd->fd;
  4887. WFIFOHEAD(fd,packet_len(0x135));
  4888. WFIFOW(fd,0)=0x135;
  4889. WFIFOW(fd,2)=index+2;
  4890. WFIFOW(fd,4)=amount;
  4891. WFIFOB(fd,6)=fail;
  4892. WFIFOSET(fd,packet_len(0x135));
  4893. return 0;
  4894. }
  4895. /*==========================================
  4896. * 露店開設成功
  4897. *------------------------------------------
  4898. */
  4899. int clif_openvending(struct map_session_data *sd,int id,struct vending *vending)
  4900. {
  4901. struct item_data *data;
  4902. int i,n,index,fd;
  4903. unsigned char *buf;
  4904. nullpo_retr(0, sd);
  4905. fd=sd->fd;
  4906. WFIFOHEAD(fd, 8+sd->vend_num*22);
  4907. buf = WFIFOP(fd,0);
  4908. for(i=0,n=0;i<sd->vend_num;i++){
  4909. if (sd->vend_num > 2+pc_checkskill(sd,MC_VENDING)) return 0;
  4910. WBUFL(buf,8+n*22)=vending[i].value;
  4911. WBUFW(buf,12+n*22)=(index=vending[i].index)+2;
  4912. WBUFW(buf,14+n*22)=vending[i].amount;
  4913. if(sd->status.cart[index].nameid <= 0 || sd->status.cart[index].amount <= 0 || !sd->status.cart[index].identify ||
  4914. sd->status.cart[index].attribute==1) // Prevent unidentified and broken items from being sold [Valaris]
  4915. continue;
  4916. data = itemdb_search(sd->status.cart[index].nameid);
  4917. WBUFB(buf,16+n*22)=itemtype(data->type);
  4918. if(data->view_id > 0)
  4919. WBUFW(buf,17+n*22)=data->view_id;
  4920. else
  4921. WBUFW(buf,17+n*22)=sd->status.cart[index].nameid;
  4922. WBUFB(buf,19+n*22)=sd->status.cart[index].identify;
  4923. WBUFB(buf,20+n*22)=sd->status.cart[index].attribute;
  4924. WBUFB(buf,21+n*22)=sd->status.cart[index].refine;
  4925. clif_addcards(WBUFP(buf, 22+n*22), &sd->status.cart[index]);
  4926. n++;
  4927. }
  4928. if(n > 0){
  4929. WBUFW(buf,0)=0x136;
  4930. WBUFW(buf,2)=8+n*22;
  4931. WBUFL(buf,4)=id;
  4932. WFIFOSET(fd,WFIFOW(fd,2));
  4933. }
  4934. return n;
  4935. }
  4936. /*==========================================
  4937. * 露店アイテム販売報告
  4938. *------------------------------------------
  4939. */
  4940. int clif_vendingreport(struct map_session_data *sd,int index,int amount)
  4941. {
  4942. int fd;
  4943. nullpo_retr(0, sd);
  4944. fd=sd->fd;
  4945. WFIFOHEAD(fd,packet_len(0x137));
  4946. WFIFOW(fd,0)=0x137;
  4947. WFIFOW(fd,2)=index+2;
  4948. WFIFOW(fd,4)=amount;
  4949. WFIFOSET(fd,packet_len(0x137));
  4950. return 0;
  4951. }
  4952. /*==========================================
  4953. * パーティ作成完了
  4954. *------------------------------------------
  4955. */
  4956. int clif_party_created(struct map_session_data *sd,int flag)
  4957. {
  4958. int fd;
  4959. nullpo_retr(0, sd);
  4960. fd=sd->fd;
  4961. WFIFOHEAD(fd,packet_len(0xfa));
  4962. WFIFOW(fd,0)=0xfa;
  4963. WFIFOB(fd,2)=flag;
  4964. WFIFOSET(fd,packet_len(0xfa));
  4965. return 0;
  4966. }
  4967. int clif_party_member_info(struct party_data *p, struct map_session_data *sd)
  4968. {
  4969. unsigned char buf[96];
  4970. char map_name[MAP_NAME_LENGTH];
  4971. if (!sd) { //Pick any party member (this call is used when changing item share rules)
  4972. int i;
  4973. for (i=0; i<MAX_PARTY && !p->data[i].sd; i++);
  4974. if (i >= MAX_PARTY) return 0; //Should never happen...
  4975. sd = p->data[i].sd;
  4976. }
  4977. snprintf(map_name, MAP_NAME_LENGTH, "%s.gat", mapindex_id2name(sd->mapindex));
  4978. WBUFW(buf,0)=0x1e9;
  4979. WBUFL(buf,2)= sd->status.account_id;
  4980. WBUFL(buf,6)= 0; //Apparently setting this to 1 makes you adoptable.
  4981. WBUFW(buf,10)=sd->bl.x;
  4982. WBUFW(buf,12)=sd->bl.y;
  4983. WBUFB(buf,14)=0; //Unconfirmed byte, could be online/offline.
  4984. memcpy(WBUFP(buf,15), p->party.name, NAME_LENGTH);
  4985. memcpy(WBUFP(buf,39), sd->status.name, NAME_LENGTH);
  4986. memcpy(WBUFP(buf,63), map_name, MAP_NAME_LENGTH);
  4987. WBUFB(buf,79) = (p->party.item&1)?1:0;
  4988. WBUFB(buf,80) = (p->party.item&2)?1:0;
  4989. clif_send(buf,packet_len(0x1e9),&sd->bl,PARTY);
  4990. return 1;
  4991. }
  4992. /*==========================================
  4993. * Sends party information
  4994. * R 00fb <len>.w <party name>.24B {<ID>.l <nick>.24B <map name>.16B <leader>.B <offline>.B}.46B*
  4995. *------------------------------------------*/
  4996. int clif_party_info(struct party_data* p, struct map_session_data *sd)
  4997. {
  4998. unsigned char buf[2+2+NAME_LENGTH+(4+NAME_LENGTH+MAP_NAME_LENGTH+1+1)*MAX_PARTY];
  4999. struct map_session_data* party_sd = NULL;
  5000. int i, c;
  5001. nullpo_retr(0, p);
  5002. WBUFW(buf,0) = 0xfb;
  5003. memcpy(WBUFP(buf,4), p->party.name, NAME_LENGTH);
  5004. for(i = 0, c = 0; i < MAX_PARTY; i++)
  5005. {
  5006. struct party_member* m = &p->party.member[i];
  5007. char map_name[MAP_NAME_LENGTH];
  5008. if(!m->account_id) continue;
  5009. if(party_sd == NULL) party_sd = p->data[i].sd;
  5010. snprintf(map_name, MAP_NAME_LENGTH, "%s.gat", mapindex_id2name(m->map));
  5011. WBUFL(buf,28+c*46) = m->account_id;
  5012. memcpy(WBUFP(buf,28+c*46+4), m->name, NAME_LENGTH);
  5013. memcpy(WBUFP(buf,28+c*46+28), map_name, MAP_NAME_LENGTH);
  5014. WBUFB(buf,28+c*46+44) = (m->leader) ? 0 : 1;
  5015. WBUFB(buf,28+c*46+45) = (m->online) ? 0 : 1;
  5016. c++;
  5017. }
  5018. WBUFW(buf,2) = 28+c*46;
  5019. if(sd) { // send only to self
  5020. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  5021. } else if (party_sd) { // send to whole party
  5022. clif_send(buf, WBUFW(buf,2), &party_sd->bl, PARTY);
  5023. }
  5024. return 0;
  5025. }
  5026. /*==========================================
  5027. * パーティ勧誘
  5028. *------------------------------------------
  5029. */
  5030. int clif_party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  5031. {
  5032. int fd;
  5033. struct party_data *p;
  5034. nullpo_retr(0, sd);
  5035. nullpo_retr(0, tsd);
  5036. fd=tsd->fd;
  5037. if( (p=party_search(sd->status.party_id))==NULL )
  5038. return 0;
  5039. WFIFOHEAD(fd,packet_len(0xfe));
  5040. WFIFOW(fd,0)=0xfe;
  5041. WFIFOL(fd,2)=sd->status.account_id;
  5042. memcpy(WFIFOP(fd,6),p->party.name,NAME_LENGTH);
  5043. WFIFOSET(fd,packet_len(0xfe));
  5044. return 0;
  5045. }
  5046. /*==========================================
  5047. * Party invitation result. Flag values are:
  5048. * 0 -> char is already in a party
  5049. * 1 -> party invite was rejected
  5050. * 2 -> party invite was accepted
  5051. * 3 -> party is full
  5052. * 4 -> char of the same account already joined the party
  5053. *------------------------------------------
  5054. */
  5055. int clif_party_inviteack(struct map_session_data* sd, const char* nick, int flag)
  5056. {
  5057. int fd;
  5058. nullpo_retr(0, sd);
  5059. fd=sd->fd;
  5060. WFIFOHEAD(fd,packet_len(0xfd));
  5061. WFIFOW(fd,0)=0xfd;
  5062. memcpy(WFIFOP(fd,2),nick,NAME_LENGTH);
  5063. WFIFOB(fd,26)=flag;
  5064. WFIFOSET(fd,packet_len(0xfd));
  5065. return 0;
  5066. }
  5067. /*==========================================
  5068. * パーティ設定送信
  5069. * flag & 0x001=exp変更ミス
  5070. * 0x010=item変更ミス
  5071. * 0x100=一人にのみ送信
  5072. *------------------------------------------
  5073. */
  5074. int clif_party_option(struct party_data *p,struct map_session_data *sd,int flag)
  5075. {
  5076. unsigned char buf[16];
  5077. nullpo_retr(0, p);
  5078. if(!sd && flag==0){
  5079. int i;
  5080. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5081. if (i < MAX_PARTY)
  5082. sd = p->data[i].sd;
  5083. }
  5084. if(!sd) return 0;
  5085. WBUFW(buf,0)=0x101;
  5086. // WBUFL(buf,2) // that's how the client reads it, still need to check it's uses [FlavioJS]
  5087. WBUFW(buf,2)=((flag&0x01)?2:p->party.exp);
  5088. WBUFW(buf,4)=0;
  5089. if(flag==0)
  5090. clif_send(buf,packet_len(0x101),&sd->bl,PARTY);
  5091. else
  5092. clif_send(buf,packet_len(0x101),&sd->bl,SELF);
  5093. return 0;
  5094. }
  5095. /*==========================================
  5096. * パーティ脱退(脱退前に呼ぶこと)
  5097. *------------------------------------------
  5098. */
  5099. int clif_party_leaved(struct party_data* p, struct map_session_data* sd, int account_id, const char* name, int flag)
  5100. {
  5101. unsigned char buf[64];
  5102. int i;
  5103. nullpo_retr(0, p);
  5104. if(!sd && (flag&0xf0)==0)
  5105. {
  5106. for(i=0;i<MAX_PARTY && !p->data[i].sd;i++);
  5107. if (i < MAX_PARTY)
  5108. sd = p->data[i].sd;
  5109. }
  5110. if(!sd) return 0;
  5111. WBUFW(buf,0)=0x105;
  5112. WBUFL(buf,2)=account_id;
  5113. memcpy(WBUFP(buf,6),name,NAME_LENGTH);
  5114. WBUFB(buf,30)=flag&0x0f;
  5115. if((flag&0xf0)==0)
  5116. clif_send(buf,packet_len(0x105),&sd->bl,PARTY);
  5117. else
  5118. clif_send(buf,packet_len(0x105),&sd->bl,SELF);
  5119. return 0;
  5120. }
  5121. /*==========================================
  5122. * パーティメッセージ送信
  5123. *------------------------------------------
  5124. */
  5125. int clif_party_message(struct party_data* p, int account_id, const char* mes, int len)
  5126. {
  5127. struct map_session_data *sd;
  5128. int i;
  5129. nullpo_retr(0, p);
  5130. for(i=0; i < MAX_PARTY && !p->data[i].sd;i++);
  5131. if(i < MAX_PARTY){
  5132. unsigned char buf[1024];
  5133. sd = p->data[i].sd;
  5134. WBUFW(buf,0)=0x109;
  5135. WBUFW(buf,2)=len+8;
  5136. WBUFL(buf,4)=account_id;
  5137. memcpy(WBUFP(buf,8),mes,len);
  5138. clif_send(buf,len+8,&sd->bl,PARTY);
  5139. }
  5140. return 0;
  5141. }
  5142. /*==========================================
  5143. * パーティ座標通知
  5144. *------------------------------------------
  5145. */
  5146. int clif_party_xy(struct map_session_data *sd)
  5147. {
  5148. unsigned char buf[16];
  5149. nullpo_retr(0, sd);
  5150. WBUFW(buf,0)=0x107;
  5151. WBUFL(buf,2)=sd->status.account_id;
  5152. WBUFW(buf,6)=sd->bl.x;
  5153. WBUFW(buf,8)=sd->bl.y;
  5154. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  5155. return 0;
  5156. }
  5157. /*==========================================
  5158. * Sends x/y dot to a single fd. [Skotlex]
  5159. *------------------------------------------
  5160. */
  5161. int clif_party_xy_single(int fd, struct map_session_data *sd)
  5162. {
  5163. WFIFOHEAD(fd,packet_len(0x107));
  5164. WFIFOW(fd,0)=0x107;
  5165. WFIFOL(fd,2)=sd->status.account_id;
  5166. WFIFOW(fd,6)=sd->bl.x;
  5167. WFIFOW(fd,8)=sd->bl.y;
  5168. WFIFOSET(fd,packet_len(0x107));
  5169. return 0;
  5170. }
  5171. /*==========================================
  5172. * パーティHP通知
  5173. *------------------------------------------
  5174. */
  5175. int clif_party_hp(struct map_session_data *sd)
  5176. {
  5177. unsigned char buf[16];
  5178. nullpo_retr(0, sd);
  5179. WBUFW(buf,0)=0x106;
  5180. WBUFL(buf,2)=sd->status.account_id;
  5181. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5182. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5183. WBUFW(buf,8) = 100;
  5184. } else {
  5185. WBUFW(buf,6) = sd->battle_status.hp;
  5186. WBUFW(buf,8) = sd->battle_status.max_hp;
  5187. }
  5188. clif_send(buf,packet_len(0x106),&sd->bl,PARTY_AREA_WOS);
  5189. return 0;
  5190. }
  5191. /*==========================================
  5192. * Sends HP bar to a single fd. [Skotlex]
  5193. *------------------------------------------
  5194. */
  5195. static void clif_hpmeter_single(int fd, struct map_session_data *sd)
  5196. {
  5197. WFIFOHEAD(fd,packet_len(0x106));
  5198. WFIFOW(fd,0) = 0x106;
  5199. WFIFOL(fd,2) = sd->status.account_id;
  5200. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5201. WFIFOW(fd,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5202. WFIFOW(fd,8) = 100;
  5203. } else {
  5204. WFIFOW(fd,6) = sd->battle_status.hp;
  5205. WFIFOW(fd,8) = sd->battle_status.max_hp;
  5206. }
  5207. WFIFOSET (fd, packet_len(0x106));
  5208. }
  5209. /*==========================================
  5210. * GMへ場所とHP通知
  5211. *------------------------------------------
  5212. */
  5213. int clif_hpmeter(struct map_session_data *sd)
  5214. {
  5215. struct map_session_data *sd2;
  5216. unsigned char buf[16];
  5217. int i, x0, y0, x1, y1;
  5218. int level;
  5219. nullpo_retr(0, sd);
  5220. x0 = sd->bl.x - AREA_SIZE;
  5221. y0 = sd->bl.y - AREA_SIZE;
  5222. x1 = sd->bl.x + AREA_SIZE;
  5223. y1 = sd->bl.y + AREA_SIZE;
  5224. WBUFW(buf,0) = 0x106;
  5225. WBUFL(buf,2) = sd->status.account_id;
  5226. if (sd->battle_status.max_hp > SHRT_MAX) { //To correctly display the %hp bar. [Skotlex]
  5227. WBUFW(buf,6) = sd->battle_status.hp/(sd->battle_status.max_hp/100);
  5228. WBUFW(buf,8) = 100;
  5229. } else {
  5230. WBUFW(buf,6) = sd->battle_status.hp;
  5231. WBUFW(buf,8) = sd->battle_status.max_hp;
  5232. }
  5233. for (i = 0; i < fd_max; i++) {
  5234. if (session[i] && session[i]->func_parse == clif_parse &&
  5235. (sd2 = (struct map_session_data*)session[i]->session_data) &&
  5236. sd != sd2 && sd2->state.auth) {
  5237. if (sd2->bl.m != sd->bl.m ||
  5238. sd2->bl.x < x0 || sd2->bl.y < y0 ||
  5239. sd2->bl.x > x1 || sd2->bl.y > y1 ||
  5240. (level = pc_isGM(sd2)) < battle_config.disp_hpmeter ||
  5241. level < pc_isGM(sd))
  5242. continue;
  5243. WFIFOHEAD (i, packet_len(0x106));
  5244. memcpy (WFIFOP(i,0), buf, packet_len(0x106));
  5245. WFIFOSET (i, packet_len(0x106));
  5246. }
  5247. }
  5248. return 0;
  5249. }
  5250. /*==========================================
  5251. * パーティ場所移動(未使用)
  5252. *------------------------------------------
  5253. */
  5254. int clif_party_move(struct party *p,struct map_session_data *sd,int online)
  5255. {
  5256. unsigned char buf[128];
  5257. char map_name[MAP_NAME_LENGTH];
  5258. nullpo_retr(0, sd);
  5259. nullpo_retr(0, p);
  5260. snprintf(map_name, MAP_NAME_LENGTH, "%s.gat", map[sd->bl.m].name);
  5261. WBUFW(buf, 0)=0x104;
  5262. WBUFL(buf, 2)=sd->status.account_id;
  5263. WBUFL(buf, 6)=0;
  5264. WBUFW(buf,10)=sd->bl.x;
  5265. WBUFW(buf,12)=sd->bl.y;
  5266. WBUFB(buf,14)=!online;
  5267. memcpy(WBUFP(buf,15),p->name, NAME_LENGTH);
  5268. memcpy(WBUFP(buf,39),sd->status.name, NAME_LENGTH);
  5269. memcpy(WBUFP(buf,63),map_name, MAP_NAME_LENGTH);
  5270. clif_send(buf,packet_len(0x104),&sd->bl,PARTY);
  5271. return 0;
  5272. }
  5273. /*==========================================
  5274. * 攻撃するために移動が必要
  5275. *------------------------------------------
  5276. */
  5277. int clif_movetoattack(struct map_session_data *sd,struct block_list *bl)
  5278. {
  5279. int fd;
  5280. nullpo_retr(0, sd);
  5281. nullpo_retr(0, bl);
  5282. fd=sd->fd;
  5283. WFIFOHEAD(fd,packet_len(0x139));
  5284. WFIFOW(fd, 0)=0x139;
  5285. WFIFOL(fd, 2)=bl->id;
  5286. WFIFOW(fd, 6)=bl->x;
  5287. WFIFOW(fd, 8)=bl->y;
  5288. WFIFOW(fd,10)=sd->bl.x;
  5289. WFIFOW(fd,12)=sd->bl.y;
  5290. WFIFOW(fd,14)=sd->battle_status.rhw.range;
  5291. WFIFOSET(fd,packet_len(0x139));
  5292. return 0;
  5293. }
  5294. /*==========================================
  5295. * 製造エフェクト
  5296. *------------------------------------------
  5297. */
  5298. int clif_produceeffect(struct map_session_data *sd,int flag,int nameid)
  5299. {
  5300. int view,fd;
  5301. nullpo_retr(0, sd);
  5302. fd=sd->fd;
  5303. // 名前の登録と送信を先にしておく
  5304. if( map_charid2nick(sd->status.char_id)==NULL )
  5305. map_addchariddb(sd->status.char_id,sd->status.name);
  5306. clif_solved_charname(sd,sd->status.char_id);
  5307. WFIFOHEAD(fd,packet_len(0x18f));
  5308. WFIFOW(fd, 0)=0x18f;
  5309. WFIFOW(fd, 2)=flag;
  5310. if((view = itemdb_viewid(nameid)) > 0)
  5311. WFIFOW(fd, 4)=view;
  5312. else
  5313. WFIFOW(fd, 4)=nameid;
  5314. WFIFOSET(fd,packet_len(0x18f));
  5315. return 0;
  5316. }
  5317. // pet
  5318. int clif_catch_process(struct map_session_data *sd)
  5319. {
  5320. int fd;
  5321. nullpo_retr(0, sd);
  5322. fd=sd->fd;
  5323. WFIFOHEAD(fd,packet_len(0x19e));
  5324. WFIFOW(fd,0)=0x19e;
  5325. WFIFOSET(fd,packet_len(0x19e));
  5326. sd->menuskill_id = SA_TAMINGMONSTER;
  5327. if (sd->ud.skillid == SA_TAMINGMONSTER)
  5328. sd->menuskill_lv = 0; //Free catch
  5329. else
  5330. sd->menuskill_lv = sd->itemid; //Consume catch
  5331. return 0;
  5332. }
  5333. int clif_pet_rulet(struct map_session_data *sd,int data)
  5334. {
  5335. int fd;
  5336. nullpo_retr(0, sd);
  5337. fd=sd->fd;
  5338. WFIFOHEAD(fd,packet_len(0x1a0));
  5339. WFIFOW(fd,0)=0x1a0;
  5340. WFIFOB(fd,2)=data;
  5341. WFIFOSET(fd,packet_len(0x1a0));
  5342. return 0;
  5343. }
  5344. /*==========================================
  5345. * pet卵リスト作成
  5346. *------------------------------------------
  5347. */
  5348. int clif_sendegg(struct map_session_data *sd)
  5349. {
  5350. //R 01a6 <len>.w <index>.w*
  5351. int i,n=0,fd;
  5352. nullpo_retr(0, sd);
  5353. fd=sd->fd;
  5354. if (battle_config.pet_no_gvg && map_flag_gvg(sd->bl.m))
  5355. { //Disable pet hatching in GvG grounds during Guild Wars [Skotlex]
  5356. clif_displaymessage(fd, "Pets are not allowed in Guild Wars.");
  5357. return 0;
  5358. }
  5359. WFIFOHEAD(fd, MAX_INVENTORY * 2 + 4);
  5360. WFIFOW(fd,0)=0x1a6;
  5361. if(sd->status.pet_id <= 0) {
  5362. for(i=0,n=0;i<MAX_INVENTORY;i++){
  5363. if(sd->status.inventory[i].nameid<=0 || sd->inventory_data[i] == NULL ||
  5364. sd->inventory_data[i]->type!=IT_PETEGG ||
  5365. sd->status.inventory[i].amount<=0)
  5366. continue;
  5367. WFIFOW(fd,n*2+4)=i+2;
  5368. n++;
  5369. }
  5370. }
  5371. WFIFOW(fd,2)=4+n*2;
  5372. WFIFOSET(fd,WFIFOW(fd,2));
  5373. sd->menuskill_id = SA_TAMINGMONSTER;
  5374. sd->menuskill_lv = -1;
  5375. return 0;
  5376. }
  5377. int clif_send_petdata(struct map_session_data *sd,int type,int param)
  5378. {
  5379. int fd;
  5380. nullpo_retr(0, sd);
  5381. nullpo_retr(0, sd->pd);
  5382. fd=sd->fd;
  5383. WFIFOHEAD(fd,packet_len(0x1a4));
  5384. WFIFOW(fd,0)=0x1a4;
  5385. WFIFOB(fd,2)=type;
  5386. WFIFOL(fd,3)=sd->pd->bl.id;
  5387. WFIFOL(fd,7)=param;
  5388. WFIFOSET(fd,packet_len(0x1a4));
  5389. return 0;
  5390. }
  5391. int clif_send_petstatus(struct map_session_data *sd)
  5392. {
  5393. int fd;
  5394. struct s_pet *pet;
  5395. nullpo_retr(0, sd);
  5396. nullpo_retr(0, sd->pd);
  5397. fd=sd->fd;
  5398. pet = &sd->pd->pet;
  5399. WFIFOHEAD(fd,packet_len(0x1a2));
  5400. WFIFOW(fd,0)=0x1a2;
  5401. memcpy(WFIFOP(fd,2),pet->name,NAME_LENGTH);
  5402. WFIFOB(fd,26)=battle_config.pet_rename?0:pet->rename_flag;
  5403. WFIFOW(fd,27)=pet->level;
  5404. WFIFOW(fd,29)=pet->hungry;
  5405. WFIFOW(fd,31)=pet->intimate;
  5406. WFIFOW(fd,33)=pet->equip;
  5407. WFIFOSET(fd,packet_len(0x1a2));
  5408. return 0;
  5409. }
  5410. /*==========================================
  5411. *
  5412. *------------------------------------------
  5413. */
  5414. int clif_pet_emotion(struct pet_data *pd,int param)
  5415. {
  5416. unsigned char buf[16];
  5417. nullpo_retr(0, pd);
  5418. memset(buf,0,packet_len(0x1aa));
  5419. WBUFW(buf,0)=0x1aa;
  5420. WBUFL(buf,2)=pd->bl.id;
  5421. if(param >= 100 && pd->petDB->talk_convert_class) {
  5422. if(pd->petDB->talk_convert_class < 0)
  5423. return 0;
  5424. else if(pd->petDB->talk_convert_class > 0) {
  5425. param -= (pd->pet.class_ - 100)*100;
  5426. param += (pd->petDB->talk_convert_class - 100)*100;
  5427. }
  5428. }
  5429. WBUFL(buf,6)=param;
  5430. clif_send(buf,packet_len(0x1aa),&pd->bl,AREA);
  5431. return 0;
  5432. }
  5433. int clif_pet_performance(struct block_list *bl,int param)
  5434. {
  5435. unsigned char buf[16];
  5436. nullpo_retr(0, bl);
  5437. memset(buf,0,packet_len(0x1a4));
  5438. WBUFW(buf,0)=0x1a4;
  5439. WBUFB(buf,2)=4;
  5440. WBUFL(buf,3)=bl->id;
  5441. WBUFL(buf,7)=param;
  5442. clif_send(buf,packet_len(0x1a4),bl,AREA);
  5443. return 0;
  5444. }
  5445. int clif_pet_equip(struct pet_data *pd)
  5446. {
  5447. unsigned char buf[16];
  5448. nullpo_retr(0, pd);
  5449. memset(buf,0,packet_len(0x1a4));
  5450. WBUFW(buf,0)=0x1a4;
  5451. WBUFB(buf,2)=3;
  5452. WBUFL(buf,3)=pd->bl.id;
  5453. WBUFL(buf,7)=pd->vd.shield;
  5454. clif_send(buf,packet_len(0x1a4),&pd->bl,AREA);
  5455. return 0;
  5456. }
  5457. int clif_pet_food(struct map_session_data *sd,int foodid,int fail)
  5458. {
  5459. int fd;
  5460. nullpo_retr(0, sd);
  5461. fd=sd->fd;
  5462. WFIFOHEAD(fd,packet_len(0x1a3));
  5463. WFIFOW(fd,0)=0x1a3;
  5464. WFIFOB(fd,2)=fail;
  5465. WFIFOW(fd,3)=foodid;
  5466. WFIFOSET(fd,packet_len(0x1a3));
  5467. return 0;
  5468. }
  5469. /*==========================================
  5470. * オートスペル リスト送信
  5471. *------------------------------------------
  5472. */
  5473. int clif_autospell(struct map_session_data *sd,int skilllv)
  5474. {
  5475. int fd;
  5476. nullpo_retr(0, sd);
  5477. fd=sd->fd;
  5478. WFIFOHEAD(fd,packet_len(0x1cd));
  5479. WFIFOW(fd, 0)=0x1cd;
  5480. if(skilllv>0 && pc_checkskill(sd,MG_NAPALMBEAT)>0)
  5481. WFIFOL(fd,2)= MG_NAPALMBEAT;
  5482. else
  5483. WFIFOL(fd,2)= 0x00000000;
  5484. if(skilllv>1 && pc_checkskill(sd,MG_COLDBOLT)>0)
  5485. WFIFOL(fd,6)= MG_COLDBOLT;
  5486. else
  5487. WFIFOL(fd,6)= 0x00000000;
  5488. if(skilllv>1 && pc_checkskill(sd,MG_FIREBOLT)>0)
  5489. WFIFOL(fd,10)= MG_FIREBOLT;
  5490. else
  5491. WFIFOL(fd,10)= 0x00000000;
  5492. if(skilllv>1 && pc_checkskill(sd,MG_LIGHTNINGBOLT)>0)
  5493. WFIFOL(fd,14)= MG_LIGHTNINGBOLT;
  5494. else
  5495. WFIFOL(fd,14)= 0x00000000;
  5496. if(skilllv>4 && pc_checkskill(sd,MG_SOULSTRIKE)>0)
  5497. WFIFOL(fd,18)= MG_SOULSTRIKE;
  5498. else
  5499. WFIFOL(fd,18)= 0x00000000;
  5500. if(skilllv>7 && pc_checkskill(sd,MG_FIREBALL)>0)
  5501. WFIFOL(fd,22)= MG_FIREBALL;
  5502. else
  5503. WFIFOL(fd,22)= 0x00000000;
  5504. if(skilllv>9 && pc_checkskill(sd,MG_FROSTDIVER)>0)
  5505. WFIFOL(fd,26)= MG_FROSTDIVER;
  5506. else
  5507. WFIFOL(fd,26)= 0x00000000;
  5508. WFIFOSET(fd,packet_len(0x1cd));
  5509. sd->menuskill_id = SA_AUTOSPELL;
  5510. sd->menuskill_lv = skilllv;
  5511. return 0;
  5512. }
  5513. /*==========================================
  5514. * ディボーションの青い糸
  5515. *------------------------------------------
  5516. */
  5517. int clif_devotion(struct map_session_data *sd)
  5518. {
  5519. unsigned char buf[56];
  5520. int i,n;
  5521. nullpo_retr(0, sd);
  5522. WBUFW(buf,0)=0x1cf;
  5523. WBUFL(buf,2)=sd->bl.id;
  5524. for(i=0,n=0;i<5;i++) {
  5525. if (!sd->devotion[i])
  5526. continue;
  5527. WBUFL(buf,6+4*n)=sd->devotion[i];
  5528. n++;
  5529. }
  5530. for(;n<5;n++)
  5531. WBUFL(buf,6+4*n)=0;
  5532. WBUFB(buf,26)=8;
  5533. WBUFB(buf,27)=0;
  5534. clif_send(buf,packet_len(0x1cf),&sd->bl,AREA);
  5535. return 0;
  5536. }
  5537. int clif_marionette(struct block_list *src, struct block_list *target)
  5538. {
  5539. unsigned char buf[56];
  5540. int n;
  5541. WBUFW(buf,0)=0x1cf;
  5542. WBUFL(buf,2)=src->id;
  5543. for(n=0;n<5;n++)
  5544. WBUFL(buf,6+4*n)=0;
  5545. if (target) //The target goes on the second slot.
  5546. WBUFL(buf,6+4) = target->id;
  5547. WBUFB(buf,26)=8;
  5548. WBUFB(buf,27)=0;
  5549. clif_send(buf,packet_len(0x1cf),src,AREA);
  5550. return 0;
  5551. }
  5552. /*==========================================
  5553. * 氣球
  5554. *------------------------------------------
  5555. */
  5556. int clif_spiritball(struct map_session_data *sd)
  5557. {
  5558. unsigned char buf[16];
  5559. nullpo_retr(0, sd);
  5560. WBUFW(buf,0)=0x1d0;
  5561. WBUFL(buf,2)=sd->bl.id;
  5562. WBUFW(buf,6)=sd->spiritball;
  5563. clif_send(buf,packet_len(0x1d0),&sd->bl,AREA);
  5564. return 0;
  5565. }
  5566. /*==========================================
  5567. *
  5568. *------------------------------------------
  5569. */
  5570. int clif_combo_delay(struct block_list *bl,int wait)
  5571. {
  5572. unsigned char buf[32];
  5573. nullpo_retr(0, bl);
  5574. WBUFW(buf,0)=0x1d2;
  5575. WBUFL(buf,2)=bl->id;
  5576. WBUFL(buf,6)=wait;
  5577. clif_send(buf,packet_len(0x1d2),bl,AREA);
  5578. return 0;
  5579. }
  5580. /*==========================================
  5581. *白刃取り
  5582. *------------------------------------------
  5583. */
  5584. int clif_bladestop(struct block_list *src,struct block_list *dst,
  5585. int _bool)
  5586. {
  5587. unsigned char buf[32];
  5588. nullpo_retr(0, src);
  5589. nullpo_retr(0, dst);
  5590. WBUFW(buf,0)=0x1d1;
  5591. WBUFL(buf,2)=src->id;
  5592. WBUFL(buf,6)=dst->id;
  5593. WBUFL(buf,10)=_bool;
  5594. clif_send(buf,packet_len(0x1d1),src,AREA);
  5595. return 0;
  5596. }
  5597. /*==========================================
  5598. *
  5599. *------------------------------------------
  5600. */
  5601. int clif_changemapcell(int m,int x,int y,int cell_type,int type)
  5602. {
  5603. struct block_list bl;
  5604. unsigned char buf[32];
  5605. bl.type = BL_NUL;
  5606. bl.m = m;
  5607. bl.x = x;
  5608. bl.y = y;
  5609. WBUFW(buf,0) = 0x192;
  5610. WBUFW(buf,2) = x;
  5611. WBUFW(buf,4) = y;
  5612. WBUFW(buf,6) = cell_type;
  5613. memcpy(WBUFP(buf,8),map[m].name,MAP_NAME_LENGTH);
  5614. if(!type)
  5615. clif_send(buf,packet_len(0x192),&bl,AREA);
  5616. else
  5617. clif_send(buf,packet_len(0x192),&bl,ALL_SAMEMAP);
  5618. return 0;
  5619. }
  5620. /*==========================================
  5621. * MVPエフェクト
  5622. *------------------------------------------
  5623. */
  5624. int clif_mvp_effect(struct map_session_data *sd)
  5625. {
  5626. unsigned char buf[16];
  5627. nullpo_retr(0, sd);
  5628. WBUFW(buf,0)=0x10c;
  5629. WBUFL(buf,2)=sd->bl.id;
  5630. clif_send(buf,packet_len(0x10c),&sd->bl,AREA);
  5631. return 0;
  5632. }
  5633. /*==========================================
  5634. * MVPアイテム所得
  5635. *------------------------------------------
  5636. */
  5637. int clif_mvp_item(struct map_session_data *sd,int nameid)
  5638. {
  5639. int view,fd;
  5640. nullpo_retr(0, sd);
  5641. fd=sd->fd;
  5642. WFIFOHEAD(fd,packet_len(0x10a));
  5643. WFIFOW(fd,0)=0x10a;
  5644. if((view = itemdb_viewid(nameid)) > 0)
  5645. WFIFOW(fd,2)=view;
  5646. else
  5647. WFIFOW(fd,2)=nameid;
  5648. WFIFOSET(fd,packet_len(0x10a));
  5649. return 0;
  5650. }
  5651. /*==========================================
  5652. * MVP経験値所得
  5653. *------------------------------------------
  5654. */
  5655. int clif_mvp_exp(struct map_session_data *sd,unsigned long exp)
  5656. {
  5657. int fd;
  5658. nullpo_retr(0, sd);
  5659. fd=sd->fd;
  5660. WFIFOHEAD(fd,packet_len(0x10b));
  5661. WFIFOW(fd,0)=0x10b;
  5662. WFIFOL(fd,2)=exp;
  5663. WFIFOSET(fd,packet_len(0x10b));
  5664. return 0;
  5665. }
  5666. /*==========================================
  5667. * ギルド作成可否通知
  5668. *------------------------------------------
  5669. */
  5670. int clif_guild_created(struct map_session_data *sd,int flag)
  5671. {
  5672. int fd;
  5673. nullpo_retr(0, sd);
  5674. fd=sd->fd;
  5675. WFIFOHEAD(fd,packet_len(0x167));
  5676. WFIFOW(fd,0)=0x167;
  5677. WFIFOB(fd,2)=flag;
  5678. WFIFOSET(fd,packet_len(0x167));
  5679. return 0;
  5680. }
  5681. /*==========================================
  5682. * ギルド所属通知
  5683. *------------------------------------------
  5684. */
  5685. int clif_guild_belonginfo(struct map_session_data *sd,struct guild *g)
  5686. {
  5687. int ps,fd;
  5688. nullpo_retr(0, sd);
  5689. nullpo_retr(0, g);
  5690. fd=sd->fd;
  5691. ps=guild_getposition(sd,g);
  5692. WFIFOHEAD(fd,packet_len(0x16c));
  5693. memset(WFIFOP(fd,0),0,packet_len(0x16c));
  5694. WFIFOW(fd,0)=0x16c;
  5695. WFIFOL(fd,2)=g->guild_id;
  5696. WFIFOL(fd,6)=g->emblem_id;
  5697. WFIFOL(fd,10)=g->position[ps].mode;
  5698. memcpy(WFIFOP(fd,19),g->name,NAME_LENGTH);
  5699. WFIFOSET(fd,packet_len(0x16c));
  5700. return 0;
  5701. }
  5702. /*==========================================
  5703. * ギルドメンバログイン通知
  5704. *------------------------------------------
  5705. */
  5706. int clif_guild_memberlogin_notice(struct guild *g,int idx,int flag)
  5707. {
  5708. unsigned char buf[64];
  5709. nullpo_retr(0, g);
  5710. WBUFW(buf, 0)=0x16d;
  5711. WBUFL(buf, 2)=g->member[idx].account_id;
  5712. WBUFL(buf, 6)=g->member[idx].char_id;
  5713. WBUFL(buf,10)=flag;
  5714. if(g->member[idx].sd==NULL){
  5715. struct map_session_data *sd=guild_getavailablesd(g);
  5716. if(sd!=NULL)
  5717. clif_send(buf,packet_len(0x16d),&sd->bl,GUILD);
  5718. }else
  5719. clif_send(buf,packet_len(0x16d),&g->member[idx].sd->bl,GUILD_WOS);
  5720. return 0;
  5721. }
  5722. // Function `clif_guild_memberlogin_notice` sends info about
  5723. // logins and logouts of a guild member to the rest members.
  5724. // But at the 1st time (after a player login or map changing)
  5725. // the client won't show the message.
  5726. // So I suggest use this function for sending "first-time-info"
  5727. // to some player on entering the game or changing location.
  5728. // At next time the client would always show the message.
  5729. // The function sends all the statuses in the single packet
  5730. // to economize traffic. [LuzZza]
  5731. int clif_guild_send_onlineinfo(struct map_session_data *sd) {
  5732. struct guild *g;
  5733. char buf[14*128];
  5734. int i, count=0, p_len;
  5735. nullpo_retr(0, sd);
  5736. p_len = packet_len(0x16d);
  5737. if(!(g = guild_search(sd->status.guild_id)))
  5738. return 0;
  5739. for(i=0; i<g->max_member; i++) {
  5740. if(g->member[i].account_id > 0 &&
  5741. g->member[i].account_id != sd->status.account_id) {
  5742. WBUFW(buf,count*p_len) = 0x16d;
  5743. WBUFL(buf,count*p_len+2) = g->member[i].account_id;
  5744. WBUFL(buf,count*p_len+6) = g->member[i].char_id;
  5745. WBUFL(buf,count*p_len+10) = g->member[i].online;
  5746. count++;
  5747. }
  5748. }
  5749. clif_send(buf,p_len*count,&sd->bl,SELF);
  5750. return 0;
  5751. }
  5752. /*==========================================
  5753. * ギルドマスター通知(14dへの応答)
  5754. *------------------------------------------
  5755. */
  5756. int clif_guild_masterormember(struct map_session_data *sd)
  5757. {
  5758. int type=0x57,fd;
  5759. nullpo_retr(0, sd);
  5760. fd=sd->fd;
  5761. if(sd->state.gmaster_flag)
  5762. type=0xd7;
  5763. WFIFOHEAD(fd,packet_len(0x14e));
  5764. WFIFOW(fd,0)=0x14e;
  5765. WFIFOL(fd,2)=type;
  5766. WFIFOSET(fd,packet_len(0x14e));
  5767. return 0;
  5768. }
  5769. /*==========================================
  5770. * Basic Info (Territories [Valaris])
  5771. *------------------------------------------
  5772. */
  5773. int clif_guild_basicinfo(struct map_session_data *sd)
  5774. {
  5775. int fd,i,t=0;
  5776. struct guild *g;
  5777. struct guild_castle *gc=NULL;
  5778. nullpo_retr(0, sd);
  5779. fd=sd->fd;
  5780. g=guild_search(sd->status.guild_id);
  5781. if(g==NULL)
  5782. return 0;
  5783. WFIFOHEAD(fd,packet_len(0x1b6));
  5784. WFIFOW(fd, 0)=0x1b6;//0x150;
  5785. WFIFOL(fd, 2)=g->guild_id;
  5786. WFIFOL(fd, 6)=g->guild_lv;
  5787. WFIFOL(fd,10)=g->connect_member;
  5788. WFIFOL(fd,14)=g->max_member;
  5789. WFIFOL(fd,18)=g->average_lv;
  5790. WFIFOL(fd,22)=g->exp;
  5791. WFIFOL(fd,26)=g->next_exp;
  5792. WFIFOL(fd,30)=0; // Tax Points
  5793. WFIFOL(fd,34)=0; // Tendency: (left) Vulgar [-100,100] Famed (right)
  5794. WFIFOL(fd,38)=0; // Tendency: (down) Wicked [-100,100] Righteous (up)
  5795. WFIFOL(fd,42)=g->emblem_id;
  5796. memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
  5797. memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
  5798. for(i=0;i<MAX_GUILDCASTLE;i++){
  5799. gc=guild_castle_search(i);
  5800. if(!gc) continue;
  5801. if(g->guild_id == gc->guild_id) t++;
  5802. }
  5803. if (t>=0 && t<=MAX_GUILDCASTLE) //(0=None, 1..24 = N of Casles) [Lupus]
  5804. strncpy((char*)WFIFOP(fd,94),msg_txt(300+t),20);
  5805. else
  5806. strncpy((char*)WFIFOP(fd,94),msg_txt(299),20);
  5807. WFIFOSET(fd,packet_len(WFIFOW(fd,0)));
  5808. return 0;
  5809. }
  5810. /*==========================================
  5811. * ギルド同盟/敵対情報
  5812. *------------------------------------------
  5813. */
  5814. int clif_guild_allianceinfo(struct map_session_data *sd)
  5815. {
  5816. int fd,i,c;
  5817. struct guild *g;
  5818. nullpo_retr(0, sd);
  5819. fd=sd->fd;
  5820. g=guild_search(sd->status.guild_id);
  5821. if(g==NULL)
  5822. return 0;
  5823. WFIFOHEAD(fd, MAX_GUILDALLIANCE * 32 + 4);
  5824. WFIFOW(fd, 0)=0x14c;
  5825. for(i=c=0;i<MAX_GUILDALLIANCE;i++){
  5826. struct guild_alliance *a=&g->alliance[i];
  5827. if(a->guild_id>0){
  5828. WFIFOL(fd,c*32+4)=a->opposition;
  5829. WFIFOL(fd,c*32+8)=a->guild_id;
  5830. memcpy(WFIFOP(fd,c*32+12),a->name,NAME_LENGTH);
  5831. c++;
  5832. }
  5833. }
  5834. WFIFOW(fd, 2)=c*32+4;
  5835. WFIFOSET(fd,WFIFOW(fd,2));
  5836. return 0;
  5837. }
  5838. /*==========================================
  5839. * ギルドメンバーリスト
  5840. *------------------------------------------
  5841. */
  5842. int clif_guild_memberlist(struct map_session_data *sd)
  5843. {
  5844. int fd;
  5845. int i,c;
  5846. struct guild *g;
  5847. nullpo_retr(0, sd);
  5848. fd=sd->fd;
  5849. if (!fd)
  5850. return 0;
  5851. g=guild_search(sd->status.guild_id);
  5852. if(g==NULL)
  5853. return 0;
  5854. WFIFOHEAD(fd, g->max_member * 104 + 4);
  5855. WFIFOW(fd, 0)=0x154;
  5856. for(i=0,c=0;i<g->max_member;i++){
  5857. struct guild_member *m=&g->member[i];
  5858. if(m->account_id==0)
  5859. continue;
  5860. WFIFOL(fd,c*104+ 4)=m->account_id;
  5861. WFIFOL(fd,c*104+ 8)=m->char_id;
  5862. WFIFOW(fd,c*104+12)=m->hair;
  5863. WFIFOW(fd,c*104+14)=m->hair_color;
  5864. WFIFOW(fd,c*104+16)=m->gender;
  5865. WFIFOW(fd,c*104+18)=m->class_;
  5866. WFIFOW(fd,c*104+20)=m->lv;
  5867. WFIFOL(fd,c*104+22)=m->exp;
  5868. WFIFOL(fd,c*104+26)=m->online;
  5869. WFIFOL(fd,c*104+30)=m->position;
  5870. memset(WFIFOP(fd,c*104+34),0,50); // メモ?
  5871. memcpy(WFIFOP(fd,c*104+84),m->name,NAME_LENGTH);
  5872. c++;
  5873. }
  5874. WFIFOW(fd, 2)=c*104+4;
  5875. WFIFOSET(fd,WFIFOW(fd,2));
  5876. return 0;
  5877. }
  5878. /*==========================================
  5879. * ギルド役職名リスト
  5880. *------------------------------------------
  5881. */
  5882. int clif_guild_positionnamelist(struct map_session_data *sd)
  5883. {
  5884. int i,fd;
  5885. struct guild *g;
  5886. nullpo_retr(0, sd);
  5887. fd=sd->fd;
  5888. g=guild_search(sd->status.guild_id);
  5889. if(g==NULL)
  5890. return 0;
  5891. WFIFOHEAD(fd, MAX_GUILDPOSITION * 28 + 4);
  5892. WFIFOW(fd, 0)=0x166;
  5893. for(i=0;i<MAX_GUILDPOSITION;i++){
  5894. WFIFOL(fd,i*28+4)=i;
  5895. memcpy(WFIFOP(fd,i*28+8),g->position[i].name,NAME_LENGTH);
  5896. }
  5897. WFIFOW(fd,2)=i*28+4;
  5898. WFIFOSET(fd,WFIFOW(fd,2));
  5899. return 0;
  5900. }
  5901. /*==========================================
  5902. * ギルド役職情報リスト
  5903. *------------------------------------------
  5904. */
  5905. int clif_guild_positioninfolist(struct map_session_data *sd)
  5906. {
  5907. int i,fd;
  5908. struct guild *g;
  5909. nullpo_retr(0, sd);
  5910. fd=sd->fd;
  5911. g=guild_search(sd->status.guild_id);
  5912. if(g==NULL)
  5913. return 0;
  5914. WFIFOHEAD(fd, MAX_GUILDPOSITION * 16 + 4);
  5915. WFIFOW(fd, 0)=0x160;
  5916. for(i=0;i<MAX_GUILDPOSITION;i++){
  5917. struct guild_position *p=&g->position[i];
  5918. WFIFOL(fd,i*16+ 4)=i;
  5919. WFIFOL(fd,i*16+ 8)=p->mode;
  5920. WFIFOL(fd,i*16+12)=i;
  5921. WFIFOL(fd,i*16+16)=p->exp_mode;
  5922. }
  5923. WFIFOW(fd, 2)=i*16+4;
  5924. WFIFOSET(fd,WFIFOW(fd,2));
  5925. return 0;
  5926. }
  5927. /*==========================================
  5928. * ギルド役職変更通知
  5929. *------------------------------------------
  5930. */
  5931. int clif_guild_positionchanged(struct guild *g,int idx)
  5932. {
  5933. struct map_session_data *sd;
  5934. unsigned char buf[128];
  5935. nullpo_retr(0, g);
  5936. WBUFW(buf, 0)=0x174;
  5937. WBUFW(buf, 2)=44;
  5938. WBUFL(buf, 4)=idx;
  5939. WBUFL(buf, 8)=g->position[idx].mode;
  5940. WBUFL(buf,12)=idx;
  5941. WBUFL(buf,16)=g->position[idx].exp_mode;
  5942. memcpy(WBUFP(buf,20),g->position[idx].name,NAME_LENGTH);
  5943. if( (sd=guild_getavailablesd(g))!=NULL )
  5944. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5945. return 0;
  5946. }
  5947. /*==========================================
  5948. * ギルドメンバ変更通知
  5949. *------------------------------------------
  5950. */
  5951. int clif_guild_memberpositionchanged(struct guild *g,int idx)
  5952. {
  5953. struct map_session_data *sd;
  5954. unsigned char buf[64];
  5955. nullpo_retr(0, g);
  5956. WBUFW(buf, 0)=0x156;
  5957. WBUFW(buf, 2)=16;
  5958. WBUFL(buf, 4)=g->member[idx].account_id;
  5959. WBUFL(buf, 8)=g->member[idx].char_id;
  5960. WBUFL(buf,12)=g->member[idx].position;
  5961. if( (sd=guild_getavailablesd(g))!=NULL )
  5962. clif_send(buf,WBUFW(buf,2),&sd->bl,GUILD);
  5963. return 0;
  5964. }
  5965. /*==========================================
  5966. * ギルドエンブレム送信
  5967. *------------------------------------------
  5968. */
  5969. int clif_guild_emblem(struct map_session_data *sd,struct guild *g)
  5970. {
  5971. int fd;
  5972. nullpo_retr(0, sd);
  5973. nullpo_retr(0, g);
  5974. fd=sd->fd;
  5975. if(g->emblem_len<=0)
  5976. return 0;
  5977. WFIFOHEAD(fd,g->emblem_len+12);
  5978. WFIFOW(fd,0)=0x152;
  5979. WFIFOW(fd,2)=g->emblem_len+12;
  5980. WFIFOL(fd,4)=g->guild_id;
  5981. WFIFOL(fd,8)=g->emblem_id;
  5982. memcpy(WFIFOP(fd,12),g->emblem_data,g->emblem_len);
  5983. WFIFOSET(fd,WFIFOW(fd,2));
  5984. return 0;
  5985. }
  5986. /*==========================================
  5987. * ギルドスキル送信
  5988. *------------------------------------------
  5989. */
  5990. int clif_guild_skillinfo(struct map_session_data *sd)
  5991. {
  5992. int fd;
  5993. int i,id,c,up=1;
  5994. struct guild *g;
  5995. nullpo_retr(0, sd);
  5996. fd=sd->fd;
  5997. g=guild_search(sd->status.guild_id);
  5998. if(g==NULL)
  5999. return 0;
  6000. WFIFOHEAD(fd, MAX_GUILDSKILL * 37 + 6);
  6001. WFIFOW(fd,0)=0x0162;
  6002. WFIFOW(fd,4)=g->skill_point;
  6003. for(i=c=0;i<MAX_GUILDSKILL;i++){
  6004. if(g->skill[i].id>0 && guild_check_skill_require(g,g->skill[i].id)){
  6005. WFIFOW(fd,c*37+ 6) = id = g->skill[i].id;
  6006. WFIFOW(fd,c*37+ 8) = skill_get_inf(id);
  6007. WFIFOW(fd,c*37+10) = 0;
  6008. WFIFOW(fd,c*37+12) = g->skill[i].lv;
  6009. WFIFOW(fd,c*37+14) = skill_get_sp(id,g->skill[i].lv);
  6010. WFIFOW(fd,c*37+16) = skill_get_range(id,g->skill[i].lv);
  6011. strncpy(WFIFOP(fd,c*37+18), skill_get_name(id), NAME_LENGTH);
  6012. if(g->skill[i].lv < guild_skill_get_max(id) && (sd == g->member[0].sd))
  6013. up = 1;
  6014. else
  6015. up = 0;
  6016. WFIFOB(fd,c*37+42)= up;
  6017. c++;
  6018. }
  6019. }
  6020. WFIFOW(fd,2)=c*37+6;
  6021. WFIFOSET(fd,WFIFOW(fd,2));
  6022. return 0;
  6023. }
  6024. /*==========================================
  6025. * ギルド告知送信
  6026. *------------------------------------------
  6027. */
  6028. int clif_guild_notice(struct map_session_data *sd,struct guild *g)
  6029. {
  6030. int fd;
  6031. nullpo_retr(0, sd);
  6032. nullpo_retr(0, g);
  6033. fd = sd->fd;
  6034. if ( !session_isActive(fd) ) //null pointer right here [Kevin]
  6035. return 0;
  6036. if (fd <= 0)
  6037. return 0;
  6038. if(*g->mes1==0 && *g->mes2==0)
  6039. return 0;
  6040. WFIFOHEAD(fd,packet_len(0x16f));
  6041. WFIFOW(fd,0)=0x16f;
  6042. memcpy(WFIFOP(fd,2),g->mes1,60);
  6043. memcpy(WFIFOP(fd,62),g->mes2,120);
  6044. WFIFOSET(fd,packet_len(0x16f));
  6045. return 0;
  6046. }
  6047. /*==========================================
  6048. * ギルドメンバ勧誘
  6049. *------------------------------------------
  6050. */
  6051. int clif_guild_invite(struct map_session_data *sd,struct guild *g)
  6052. {
  6053. int fd;
  6054. nullpo_retr(0, sd);
  6055. nullpo_retr(0, g);
  6056. fd=sd->fd;
  6057. WFIFOHEAD(fd,packet_len(0x16a));
  6058. WFIFOW(fd,0)=0x16a;
  6059. WFIFOL(fd,2)=g->guild_id;
  6060. memcpy(WFIFOP(fd,6),g->name,NAME_LENGTH);
  6061. WFIFOSET(fd,packet_len(0x16a));
  6062. return 0;
  6063. }
  6064. /*==========================================
  6065. * ギルドメンバ勧誘結果
  6066. *------------------------------------------
  6067. */
  6068. int clif_guild_inviteack(struct map_session_data *sd,int flag)
  6069. {
  6070. int fd;
  6071. nullpo_retr(0, sd);
  6072. fd=sd->fd;
  6073. WFIFOHEAD(fd,packet_len(0x169));
  6074. WFIFOW(fd,0)=0x169;
  6075. WFIFOB(fd,2)=flag;
  6076. WFIFOSET(fd,packet_len(0x169));
  6077. return 0;
  6078. }
  6079. /*==========================================
  6080. * ギルドメンバ脱退通知
  6081. *------------------------------------------
  6082. */
  6083. int clif_guild_leave(struct map_session_data *sd,const char *name,const char *mes)
  6084. {
  6085. unsigned char buf[128];
  6086. nullpo_retr(0, sd);
  6087. WBUFW(buf, 0)=0x15a;
  6088. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6089. memcpy(WBUFP(buf,26),mes,40);
  6090. clif_send(buf,packet_len(0x15a),&sd->bl,GUILD);
  6091. return 0;
  6092. }
  6093. /*==========================================
  6094. * ギルドメンバ追放通知
  6095. *------------------------------------------
  6096. */
  6097. int clif_guild_expulsion(struct map_session_data *sd,const char *name,const char *mes,
  6098. int account_id)
  6099. {
  6100. unsigned char buf[128];
  6101. nullpo_retr(0, sd);
  6102. WBUFW(buf, 0)=0x15c;
  6103. memcpy(WBUFP(buf, 2),name,NAME_LENGTH);
  6104. memcpy(WBUFP(buf,26),mes,40);
  6105. memcpy(WBUFP(buf,66),"dummy",NAME_LENGTH);
  6106. clif_send(buf,packet_len(0x15c),&sd->bl,GUILD);
  6107. return 0;
  6108. }
  6109. /*==========================================
  6110. * ギルド追放メンバリスト
  6111. *------------------------------------------
  6112. */
  6113. int clif_guild_expulsionlist(struct map_session_data *sd)
  6114. {
  6115. int fd;
  6116. int i,c;
  6117. struct guild *g;
  6118. nullpo_retr(0, sd);
  6119. fd=sd->fd;
  6120. g=guild_search(sd->status.guild_id);
  6121. if(g==NULL)
  6122. return 0;
  6123. WFIFOHEAD(fd,MAX_GUILDEXPULSION * 88 + 4);
  6124. WFIFOW(fd,0)=0x163;
  6125. for(i=c=0;i<MAX_GUILDEXPULSION;i++){
  6126. struct guild_expulsion *e=&g->expulsion[i];
  6127. if(e->account_id>0){
  6128. memcpy(WFIFOP(fd,c*88+ 4),e->name,NAME_LENGTH);
  6129. memcpy(WFIFOP(fd,c*88+28),e->acc,24);
  6130. memcpy(WFIFOP(fd,c*88+52),e->mes,44);
  6131. c++;
  6132. }
  6133. }
  6134. WFIFOW(fd,2)=c*88+4;
  6135. WFIFOSET(fd,WFIFOW(fd,2));
  6136. return 0;
  6137. }
  6138. /*==========================================
  6139. * ギルド会話
  6140. *------------------------------------------
  6141. */
  6142. int clif_guild_message(struct guild *g,int account_id,const char *mes,int len)
  6143. {
  6144. struct map_session_data *sd;
  6145. unsigned char *buf;
  6146. buf = (unsigned char*)aMallocA((len + 4)*sizeof(unsigned char));
  6147. WBUFW(buf, 0) = 0x17f;
  6148. WBUFW(buf, 2) = len + 4;
  6149. memcpy(WBUFP(buf,4), mes, len);
  6150. if ((sd = guild_getavailablesd(g)) != NULL)
  6151. clif_send(buf, WBUFW(buf,2), &sd->bl, GUILD);
  6152. if(buf) aFree(buf);
  6153. return 0;
  6154. }
  6155. /*==========================================
  6156. * ギルドスキル割り振り通知
  6157. *------------------------------------------
  6158. */
  6159. int clif_guild_skillup(struct map_session_data *sd,int skill_num,int lv)
  6160. {
  6161. int fd;
  6162. nullpo_retr(0, sd);
  6163. fd=sd->fd;
  6164. WFIFOHEAD(fd,11);
  6165. WFIFOW(fd,0) = 0x10e;
  6166. WFIFOW(fd,2) = skill_num;
  6167. WFIFOW(fd,4) = lv;
  6168. WFIFOW(fd,6) = skill_get_sp(skill_num,lv);
  6169. WFIFOW(fd,8) = skill_get_range(skill_num,lv);
  6170. WFIFOB(fd,10) = 1;
  6171. WFIFOSET(fd,11);
  6172. return 0;
  6173. }
  6174. /*==========================================
  6175. * ギルド同盟要請
  6176. *------------------------------------------
  6177. */
  6178. int clif_guild_reqalliance(struct map_session_data *sd,int account_id,const char *name)
  6179. {
  6180. int fd;
  6181. nullpo_retr(0, sd);
  6182. fd=sd->fd;
  6183. WFIFOHEAD(fd,packet_len(0x171));
  6184. WFIFOW(fd,0)=0x171;
  6185. WFIFOL(fd,2)=account_id;
  6186. memcpy(WFIFOP(fd,6),name,NAME_LENGTH);
  6187. WFIFOSET(fd,packet_len(0x171));
  6188. return 0;
  6189. }
  6190. /*==========================================
  6191. * Reply to alliance request.
  6192. * Flag values are:
  6193. * 0: Already allied.
  6194. * 1: You rejected the offer.
  6195. * 2: You accepted the offer.
  6196. * 3: They have too any alliances
  6197. * 4: You have too many alliances.
  6198. *------------------------------------------
  6199. */
  6200. int clif_guild_allianceack(struct map_session_data *sd,int flag)
  6201. {
  6202. int fd;
  6203. nullpo_retr(0, sd);
  6204. fd=sd->fd;
  6205. WFIFOHEAD(fd,packet_len(0x173));
  6206. WFIFOW(fd,0)=0x173;
  6207. WFIFOL(fd,2)=flag;
  6208. WFIFOSET(fd,packet_len(0x173));
  6209. return 0;
  6210. }
  6211. /*==========================================
  6212. * ギルド関係解消通知
  6213. *------------------------------------------
  6214. */
  6215. int clif_guild_delalliance(struct map_session_data *sd,int guild_id,int flag)
  6216. {
  6217. int fd;
  6218. nullpo_retr(0, sd);
  6219. fd = sd->fd;
  6220. if (fd <= 0)
  6221. return 0;
  6222. WFIFOHEAD(fd,packet_len(0x184));
  6223. WFIFOW(fd,0)=0x184;
  6224. WFIFOL(fd,2)=guild_id;
  6225. WFIFOL(fd,6)=flag;
  6226. WFIFOSET(fd,packet_len(0x184));
  6227. return 0;
  6228. }
  6229. /*==========================================
  6230. * ギルド敵対結果
  6231. *------------------------------------------
  6232. */
  6233. int clif_guild_oppositionack(struct map_session_data *sd,int flag)
  6234. {
  6235. int fd;
  6236. nullpo_retr(0, sd);
  6237. fd=sd->fd;
  6238. WFIFOHEAD(fd,packet_len(0x181));
  6239. WFIFOW(fd,0)=0x181;
  6240. WFIFOB(fd,2)=flag;
  6241. WFIFOSET(fd,packet_len(0x181));
  6242. return 0;
  6243. }
  6244. /*==========================================
  6245. * ギルド関係追加
  6246. *------------------------------------------
  6247. */
  6248. /*int clif_guild_allianceadded(struct guild *g,int idx)
  6249. {
  6250. unsigned char buf[64];
  6251. WBUFW(fd,0)=0x185;
  6252. WBUFL(fd,2)=g->alliance[idx].opposition;
  6253. WBUFL(fd,6)=g->alliance[idx].guild_id;
  6254. memcpy(WBUFP(fd,10),g->alliance[idx].name,NAME_LENGTH);
  6255. clif_send(buf,packet_len(0x185),guild_getavailablesd(g),GUILD);
  6256. return 0;
  6257. }*/
  6258. /*==========================================
  6259. * ギルド解散通知
  6260. *------------------------------------------
  6261. */
  6262. int clif_guild_broken(struct map_session_data *sd,int flag)
  6263. {
  6264. int fd;
  6265. nullpo_retr(0, sd);
  6266. fd=sd->fd;
  6267. WFIFOHEAD(fd,packet_len(0x15e));
  6268. WFIFOW(fd,0)=0x15e;
  6269. WFIFOL(fd,2)=flag;
  6270. WFIFOSET(fd,packet_len(0x15e));
  6271. return 0;
  6272. }
  6273. /*==========================================
  6274. * エモーション
  6275. *------------------------------------------
  6276. */
  6277. void clif_emotion(struct block_list *bl,int type)
  6278. {
  6279. unsigned char buf[8];
  6280. nullpo_retv(bl);
  6281. WBUFW(buf,0)=0xc0;
  6282. WBUFL(buf,2)=bl->id;
  6283. WBUFB(buf,6)=type;
  6284. clif_send(buf,packet_len(0xc0),bl,AREA);
  6285. }
  6286. /*==========================================
  6287. * トーキーボックス
  6288. *------------------------------------------
  6289. */
  6290. void clif_talkiebox(struct block_list* bl, const char* talkie)
  6291. {
  6292. unsigned char buf[86];
  6293. nullpo_retv(bl);
  6294. WBUFW(buf,0)=0x191;
  6295. WBUFL(buf,2)=bl->id;
  6296. memcpy(WBUFP(buf,6),talkie,MESSAGE_SIZE);
  6297. clif_send(buf,packet_len(0x191),bl,AREA);
  6298. }
  6299. /*==========================================
  6300. * 結婚エフェクト
  6301. *------------------------------------------
  6302. */
  6303. void clif_wedding_effect(struct block_list *bl) {
  6304. unsigned char buf[6];
  6305. nullpo_retv(bl);
  6306. WBUFW(buf,0) = 0x1ea;
  6307. WBUFL(buf,2) = bl->id;
  6308. clif_send(buf, packet_len(0x1ea), bl, AREA);
  6309. }
  6310. /*==========================================
  6311. * あなたに逢いたい使用時名前叫び
  6312. *------------------------------------------
  6313. void clif_callpartner(struct map_session_data *sd)
  6314. {
  6315. unsigned char buf[26];
  6316. char *p;
  6317. nullpo_retv(sd);
  6318. if(sd->status.partner_id){
  6319. WBUFW(buf,0)=0x1e6;
  6320. p = map_charid2nick(sd->status.partner_id);
  6321. if(p){
  6322. memcpy(WBUFP(buf,2),p,NAME_LENGTH);
  6323. }else{
  6324. map_reqchariddb(sd,sd->status.partner_id);
  6325. chrif_searchcharid(sd->status.partner_id);
  6326. WBUFB(buf,2) = 0;
  6327. }
  6328. clif_send(buf,packet_len(0x1e6),&sd->bl,AREA);
  6329. }
  6330. return;
  6331. }
  6332. */
  6333. /*==========================================
  6334. * Adopt baby [Celest]
  6335. *------------------------------------------
  6336. */
  6337. void clif_adopt_process(struct map_session_data *sd)
  6338. {
  6339. int fd;
  6340. nullpo_retv(sd);
  6341. fd=sd->fd;
  6342. WFIFOHEAD(fd,packet_len(0x1f8));
  6343. WFIFOW(fd,0)=0x1f8;
  6344. WFIFOSET(fd,packet_len(0x1f8));
  6345. }
  6346. /*==========================================
  6347. * Marry [DracoRPG]
  6348. *------------------------------------------
  6349. */
  6350. void clif_marriage_process(struct map_session_data *sd)
  6351. {
  6352. int fd;
  6353. nullpo_retv(sd);
  6354. fd=sd->fd;
  6355. WFIFOHEAD(fd,packet_len(0x1e4));
  6356. WFIFOW(fd,0)=0x1e4;
  6357. WFIFOSET(fd,packet_len(0x1e4));
  6358. }
  6359. /*==========================================
  6360. * Notice of divorce
  6361. *------------------------------------------
  6362. */
  6363. void clif_divorced(struct map_session_data* sd, const char* name)
  6364. {
  6365. int fd;
  6366. nullpo_retv(sd);
  6367. fd=sd->fd;
  6368. WFIFOHEAD(fd,packet_len(0x205));
  6369. WFIFOW(fd,0)=0x205;
  6370. memcpy(WFIFOP(fd,2), name, NAME_LENGTH);
  6371. WFIFOSET(fd, packet_len(0x205));
  6372. }
  6373. /*==========================================
  6374. *
  6375. *------------------------------------------
  6376. */
  6377. void clif_parse_ReqAdopt(int fd, struct map_session_data *sd) {
  6378. nullpo_retv(sd);
  6379. WFIFOHEAD(fd,packet_len(0x1f6));
  6380. WFIFOW(fd,0)=0x1f6;
  6381. WFIFOSET(fd, packet_len(0x1f6));
  6382. }
  6383. /*==========================================
  6384. *
  6385. *------------------------------------------
  6386. */
  6387. void clif_parse_ReqMarriage(int fd, struct map_session_data *sd) {
  6388. nullpo_retv(sd);
  6389. WFIFOHEAD(fd,packet_len(0x1e2));
  6390. WFIFOW(fd,0)=0x1e2;
  6391. WFIFOSET(fd, packet_len(0x1e2));
  6392. }
  6393. /*==========================================
  6394. * 座る
  6395. *------------------------------------------
  6396. */
  6397. void clif_sitting(struct map_session_data *sd)
  6398. {
  6399. unsigned char buf[64];
  6400. nullpo_retv(sd);
  6401. WBUFW(buf, 0) = 0x8a;
  6402. WBUFL(buf, 2) = sd->bl.id;
  6403. WBUFB(buf,26) = 2;
  6404. clif_send(buf, packet_len(0x8a), &sd->bl, AREA);
  6405. }
  6406. /*==========================================
  6407. *
  6408. *------------------------------------------
  6409. */
  6410. int clif_disp_onlyself(struct map_session_data *sd, const char *mes, int len)
  6411. {
  6412. int fd;
  6413. nullpo_retr(0, sd);
  6414. fd = sd->fd;
  6415. if (!fd || !len) return 0; //Disconnected player.
  6416. WFIFOHEAD(fd, len+5);
  6417. WFIFOW(fd, 0) = 0x17f;
  6418. WFIFOW(fd, 2) = len + 5;
  6419. memcpy(WFIFOP(fd,4), mes, len);
  6420. WFIFOSET(fd, WFIFOW(fd,2));
  6421. return 1;
  6422. }
  6423. /*==========================================
  6424. * Displays a message using the guild-chat colors to the specified targets. [Skotlex]
  6425. *------------------------------------------
  6426. */
  6427. void clif_disp_message(struct block_list* src, const char* mes, int len, int type)
  6428. {
  6429. unsigned char buf[1024];
  6430. if (!len) return;
  6431. WBUFW(buf, 0) = 0x17f;
  6432. WBUFW(buf, 2) = len + 5;
  6433. memcpy(WBUFP(buf,4), mes, len);
  6434. clif_send(buf, WBUFW(buf,2), src, type);
  6435. return;
  6436. }
  6437. /*==========================================
  6438. *
  6439. *------------------------------------------
  6440. */
  6441. int clif_GM_kickack(struct map_session_data *sd, int id)
  6442. {
  6443. int fd;
  6444. nullpo_retr(0, sd);
  6445. fd = sd->fd;
  6446. WFIFOHEAD(fd,packet_len(0xcd));
  6447. WFIFOW(fd,0) = 0xcd;
  6448. WFIFOL(fd,2) = id;
  6449. WFIFOSET(fd, packet_len(0xcd));
  6450. return 0;
  6451. }
  6452. void clif_parse_QuitGame(int fd,struct map_session_data *sd);
  6453. int clif_GM_kick(struct map_session_data *sd,struct map_session_data *tsd,int type)
  6454. {
  6455. int fd = tsd->fd;
  6456. WFIFOHEAD(fd,packet_len(0x18b));
  6457. if(type)
  6458. clif_GM_kickack(sd,tsd->status.account_id);
  6459. if (!fd) {
  6460. map_quit(tsd);
  6461. return 0;
  6462. }
  6463. WFIFOW(fd,0) = 0x18b;
  6464. WFIFOW(fd,2) = 0;
  6465. WFIFOSET(fd,packet_len(0x18b));
  6466. clif_setwaitclose(fd);
  6467. return 0;
  6468. }
  6469. int clif_GM_silence(struct map_session_data *sd, struct map_session_data *tsd, int type)
  6470. {
  6471. int fd;
  6472. nullpo_retr(0, sd);
  6473. nullpo_retr(0, tsd);
  6474. fd = tsd->fd;
  6475. if (fd <= 0)
  6476. return 0;
  6477. WFIFOHEAD(fd,packet_len(0x14b));
  6478. WFIFOW(fd,0) = 0x14b;
  6479. WFIFOB(fd,2) = 0;
  6480. memcpy(WFIFOP(fd,3), sd->status.name, NAME_LENGTH);
  6481. WFIFOSET(fd, packet_len(0x14b));
  6482. return 0;
  6483. }
  6484. /*==========================================
  6485. *
  6486. *------------------------------------------
  6487. */
  6488. int clif_timedout(struct map_session_data *sd)
  6489. {
  6490. nullpo_retr(0, sd);
  6491. ShowInfo("%sCharacter with Account ID '"CL_WHITE"%d"CL_RESET"' timed out.\n", (pc_isGM(sd))?"GM ":"", sd->bl.id);
  6492. clif_authfail_fd(sd->fd,3); // Even if player is not on we still send anyway
  6493. clif_setwaitclose(sd->fd); // Set session to EOF
  6494. return 0;
  6495. }
  6496. /*==========================================
  6497. * Wis拒否許可応答
  6498. *------------------------------------------
  6499. */
  6500. int clif_wisexin(struct map_session_data *sd,int type,int flag)
  6501. {
  6502. int fd;
  6503. nullpo_retr(0, sd);
  6504. fd=sd->fd;
  6505. WFIFOHEAD(fd,packet_len(0xd1));
  6506. WFIFOW(fd,0)=0xd1;
  6507. WFIFOB(fd,2)=type;
  6508. WFIFOB(fd,3)=flag;
  6509. WFIFOSET(fd,packet_len(0xd1));
  6510. return 0;
  6511. }
  6512. /*==========================================
  6513. * Wis全拒否許可応答
  6514. *------------------------------------------
  6515. */
  6516. int clif_wisall(struct map_session_data *sd,int type,int flag)
  6517. {
  6518. int fd;
  6519. nullpo_retr(0, sd);
  6520. fd=sd->fd;
  6521. WFIFOHEAD(fd,packet_len(0xd2));
  6522. WFIFOW(fd,0)=0xd2;
  6523. WFIFOB(fd,2)=type;
  6524. WFIFOB(fd,3)=flag;
  6525. WFIFOSET(fd,packet_len(0xd2));
  6526. return 0;
  6527. }
  6528. /*==========================================
  6529. * サウンドエフェクト
  6530. *------------------------------------------
  6531. */
  6532. void clif_soundeffect(struct map_session_data *sd,struct block_list *bl,const char *name,int type)
  6533. {
  6534. int fd;
  6535. nullpo_retv(sd);
  6536. nullpo_retv(bl);
  6537. fd=sd->fd;
  6538. WFIFOHEAD(fd,packet_len(0x1d3));
  6539. WFIFOW(fd,0)=0x1d3;
  6540. memcpy(WFIFOP(fd,2),name,NAME_LENGTH);
  6541. WFIFOB(fd,26)=type;
  6542. WFIFOL(fd,27)=0;
  6543. WFIFOL(fd,31)=bl->id;
  6544. WFIFOSET(fd,packet_len(0x1d3));
  6545. return;
  6546. }
  6547. int clif_soundeffectall(struct block_list *bl, const char *name, int type, int coverage)
  6548. {
  6549. unsigned char buf[40];
  6550. memset(buf, 0, packet_len(0x1d3));
  6551. if(coverage < 0 || coverage > 22){
  6552. ShowError("clif_soundeffectall: undefined coverage.\n");
  6553. return 0;
  6554. }
  6555. nullpo_retr(0, bl);
  6556. WBUFW(buf,0)=0x1d3;
  6557. memcpy(WBUFP(buf,2), name, NAME_LENGTH);
  6558. WBUFB(buf,26)=type;
  6559. WBUFL(buf,27)=0;
  6560. WBUFL(buf,31)=bl->id;
  6561. clif_send(buf, packet_len(0x1d3), bl, coverage);
  6562. return 0;
  6563. }
  6564. // displaying special effects (npcs, weather, etc) [Valaris]
  6565. int clif_specialeffect(struct block_list *bl, int type, int flag)
  6566. {
  6567. unsigned char buf[24];
  6568. nullpo_retr(0, bl);
  6569. memset(buf, 0, packet_len(0x1f3));
  6570. WBUFW(buf,0) = 0x1f3;
  6571. WBUFL(buf,2) = bl->id;
  6572. WBUFL(buf,6) = type;
  6573. clif_send(buf, packet_len(0x1f3), bl, flag);
  6574. if (disguised(bl)) {
  6575. WBUFL(buf,2) = -bl->id;
  6576. clif_send(buf, packet_len(0x1f3), bl, SELF);
  6577. }
  6578. return 0;
  6579. }
  6580. // refresh the client's screen, getting rid of any effects
  6581. int clif_refresh(struct map_session_data *sd) {
  6582. nullpo_retr(-1, sd);
  6583. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  6584. clif_inventorylist(sd);
  6585. if(pc_iscarton(sd)){
  6586. clif_cartlist(sd);
  6587. clif_updatestatus(sd,SP_CARTINFO);
  6588. }
  6589. clif_updatestatus(sd,SP_MAXWEIGHT);
  6590. clif_updatestatus(sd,SP_WEIGHT);
  6591. clif_updatestatus(sd,SP_STR);
  6592. clif_updatestatus(sd,SP_AGI);
  6593. clif_updatestatus(sd,SP_VIT);
  6594. clif_updatestatus(sd,SP_INT);
  6595. clif_updatestatus(sd,SP_DEX);
  6596. clif_updatestatus(sd,SP_LUK);
  6597. map_foreachinrange(clif_getareachar,&sd->bl,AREA_SIZE,BL_ALL,sd);
  6598. clif_weather_check(sd);
  6599. return 0;
  6600. }
  6601. // updates the object's (bl) name on client
  6602. int clif_charnameack (int fd, struct block_list *bl)
  6603. {
  6604. unsigned char buf[103];
  6605. int cmd = 0x95;
  6606. nullpo_retr(0, bl);
  6607. WBUFW(buf,0) = cmd;
  6608. WBUFL(buf,2) = bl->id;
  6609. switch(bl->type) {
  6610. case BL_PC:
  6611. {
  6612. struct map_session_data *ssd = (struct map_session_data *)bl;
  6613. struct party_data *p = NULL;
  6614. struct guild *g = NULL;
  6615. //Requesting your own "shadow" name. [Skotlex]
  6616. if (ssd->fd == fd && ssd->disguise)
  6617. WBUFL(buf,2) = -bl->id;
  6618. if (strlen(ssd->fakename)>1) {
  6619. memcpy(WBUFP(buf,6), ssd->fakename, NAME_LENGTH);
  6620. break;
  6621. }
  6622. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6623. if (ssd->status.party_id > 0)
  6624. p = party_search(ssd->status.party_id);
  6625. if (ssd->status.guild_id > 0)
  6626. g = guild_search(ssd->status.guild_id);
  6627. if (p == NULL && g == NULL)
  6628. break;
  6629. WBUFW(buf, 0) = cmd = 0x195;
  6630. if (p)
  6631. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6632. else
  6633. WBUFB(buf,30) = 0;
  6634. if (g)
  6635. {
  6636. int i, ps = -1;
  6637. for(i = 0; i < g->max_member; i++) {
  6638. if (g->member[i].account_id == ssd->status.account_id &&
  6639. g->member[i].char_id == ssd->status.char_id )
  6640. {
  6641. ps = g->member[i].position;
  6642. break;
  6643. }
  6644. }
  6645. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6646. {
  6647. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6648. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6649. } else { //Assume no guild.
  6650. WBUFB(buf,54) = 0;
  6651. WBUFB(buf,78) = 0;
  6652. }
  6653. } else {
  6654. WBUFB(buf,54) = 0;
  6655. WBUFB(buf,78) = 0;
  6656. }
  6657. }
  6658. break;
  6659. //[blackhole89]
  6660. case BL_HOM:
  6661. memcpy(WBUFP(buf,6), ((TBL_HOM*)bl)->homunculus.name, NAME_LENGTH);
  6662. break;
  6663. case BL_PET:
  6664. memcpy(WBUFP(buf,6), ((TBL_PET*)bl)->pet.name, NAME_LENGTH);
  6665. break;
  6666. case BL_NPC:
  6667. memcpy(WBUFP(buf,6), ((TBL_NPC*)bl)->name, NAME_LENGTH);
  6668. break;
  6669. case BL_MOB:
  6670. {
  6671. struct mob_data *md = (struct mob_data *)bl;
  6672. nullpo_retr(0, md);
  6673. memcpy(WBUFP(buf,6), md->name, NAME_LENGTH);
  6674. if (md->guardian_data && md->guardian_data->guild_id) {
  6675. WBUFW(buf, 0) = cmd = 0x195;
  6676. WBUFB(buf,30) = 0;
  6677. memcpy(WBUFP(buf,54), md->guardian_data->guild_name, NAME_LENGTH);
  6678. memcpy(WBUFP(buf,78), md->guardian_data->castle->castle_name, NAME_LENGTH);
  6679. } else if (battle_config.show_mob_info) {
  6680. char mobhp[50], *str_p = mobhp;
  6681. WBUFW(buf, 0) = cmd = 0x195;
  6682. if (battle_config.show_mob_info&4)
  6683. str_p += sprintf(str_p, "Lv. %d | ", md->level);
  6684. if (battle_config.show_mob_info&1)
  6685. str_p += sprintf(str_p, "HP: %u/%u | ", md->status.hp, md->status.max_hp);
  6686. if (battle_config.show_mob_info&2)
  6687. str_p += sprintf(str_p, "HP: %d%% | ",
  6688. md->status.max_hp > 10000?
  6689. md->status.hp/(md->status.max_hp/100):
  6690. 100*md->status.hp/md->status.max_hp);
  6691. //Even thought mobhp ain't a name, we send it as one so the client
  6692. //can parse it. [Skotlex]
  6693. if (str_p != mobhp) {
  6694. *(str_p-3) = '\0'; //Remove trailing space + pipe.
  6695. memcpy(WBUFP(buf,30), mobhp, NAME_LENGTH);
  6696. WBUFB(buf,54) = 0;
  6697. memcpy(WBUFP(buf,78), mobhp, NAME_LENGTH);
  6698. }
  6699. }
  6700. }
  6701. break;
  6702. case BL_CHAT: //FIXME: Clients DO request this... what should be done about it? The chat's title may not fit... [Skotlex]
  6703. // memcpy(WBUFP(buf,6), (struct chat*)->title, NAME_LENGTH);
  6704. // break;
  6705. return 0;
  6706. default:
  6707. if (battle_config.error_log)
  6708. ShowError("clif_parse_GetCharNameRequest : bad type %d(%d)\n", bl->type, bl->id);
  6709. return 0;
  6710. }
  6711. // if no receipient specified just update nearby clients
  6712. if (fd == 0)
  6713. clif_send(buf, packet_len(cmd), bl, AREA);
  6714. else {
  6715. WFIFOHEAD(fd, packet_len(cmd));
  6716. memcpy(WFIFOP(fd, 0), buf, packet_len(cmd));
  6717. WFIFOSET(fd, packet_len(cmd));
  6718. }
  6719. return 0;
  6720. }
  6721. //Used to update when a char leaves a party/guild. [Skotlex]
  6722. //Needed because when you send a 0x95 packet, the client will not remove the cached party/guild info that is not sent.
  6723. int clif_charnameupdate (struct map_session_data *ssd)
  6724. {
  6725. unsigned char buf[103];
  6726. int cmd = 0x195;
  6727. struct party_data *p = NULL;
  6728. struct guild *g = NULL;
  6729. nullpo_retr(0, ssd);
  6730. if (strlen(ssd->fakename)>1)
  6731. return 0; //No need to update as the party/guild was not displayed anyway.
  6732. WBUFW(buf,0) = cmd;
  6733. WBUFL(buf,2) = ssd->bl.id;
  6734. memcpy(WBUFP(buf,6), ssd->status.name, NAME_LENGTH);
  6735. if (ssd->status.party_id > 0)
  6736. p = party_search(ssd->status.party_id);
  6737. if (ssd->status.guild_id > 0)
  6738. g = guild_search(ssd->status.guild_id);
  6739. if (p)
  6740. memcpy(WBUFP(buf,30), p->party.name, NAME_LENGTH);
  6741. else
  6742. WBUFB(buf,30) = 0;
  6743. if (g)
  6744. {
  6745. int i, ps = -1;
  6746. for(i = 0; i < g->max_member; i++) {
  6747. if (g->member[i].account_id == ssd->status.account_id &&
  6748. g->member[i].char_id == ssd->status.char_id )
  6749. {
  6750. ps = g->member[i].position;
  6751. break;
  6752. }
  6753. }
  6754. if (ps >= 0 && ps < MAX_GUILDPOSITION)
  6755. {
  6756. memcpy(WBUFP(buf,54), g->name,NAME_LENGTH);
  6757. memcpy(WBUFP(buf,78), g->position[ps].name, NAME_LENGTH);
  6758. } else { //Assume no guild.
  6759. WBUFB(buf,54) = 0;
  6760. WBUFB(buf,78) = 0;
  6761. }
  6762. } else {
  6763. WBUFB(buf,54) = 0;
  6764. WBUFB(buf,78) = 0;
  6765. }
  6766. // Update nearby clients
  6767. clif_send(buf, packet_len(cmd), &ssd->bl, AREA);
  6768. return 0;
  6769. }
  6770. int clif_slide(struct block_list *bl, int x, int y){
  6771. unsigned char buf[10];
  6772. nullpo_retr(0, bl);
  6773. WBUFW(buf, 0) = 0x01ff;
  6774. WBUFL(buf, 2) = bl->id;
  6775. WBUFW(buf, 6) = x;
  6776. WBUFW(buf, 8) = y;
  6777. clif_send(buf, packet_len(0x1ff), bl, AREA);
  6778. return 0;
  6779. }
  6780. /*------------------------------------------
  6781. * @me command by lordalfa, rewritten implementation by Skotlex
  6782. *------------------------------------------
  6783. */
  6784. int clif_disp_overhead(struct map_session_data *sd, const char* mes)
  6785. {
  6786. unsigned char buf[256]; //This should be more than sufficient, the theorical max is CHAT_SIZE + 8 (pads and extra inserted crap)
  6787. int len_mes = strlen(mes)+1; //Account for \0
  6788. if (len_mes + 8 >= 256) {
  6789. if (battle_config.error_log)
  6790. ShowError("clif_disp_overhead: Message too long (length %d)\n", len_mes);
  6791. len_mes = 247; //Trunk it to avoid problems.
  6792. }
  6793. // send message to others
  6794. WBUFW(buf,0) = 0x8d;
  6795. WBUFW(buf,2) = len_mes + 8; // len of message + 8 (command+len+id)
  6796. WBUFL(buf,4) = sd->bl.id;
  6797. memcpy(WBUFP(buf,8), mes, len_mes);
  6798. clif_send(buf, WBUFW(buf,2), &sd->bl, AREA_CHAT_WOC);
  6799. // send back message to the speaker
  6800. WBUFW(buf,0) = 0x8e;
  6801. WBUFW(buf, 2) = len_mes + 4;
  6802. memcpy(WBUFP(buf,4), mes, len_mes);
  6803. clif_send(buf, WBUFW(buf,2), &sd->bl, SELF);
  6804. return 0;
  6805. }
  6806. /*==========================
  6807. * Minimap fix [Kevin]
  6808. * Remove dot from minimap
  6809. *--------------------------
  6810. */
  6811. int clif_party_xy_remove(struct map_session_data *sd)
  6812. {
  6813. unsigned char buf[16];
  6814. nullpo_retr(0, sd);
  6815. WBUFW(buf,0)=0x107;
  6816. WBUFL(buf,2)=sd->status.account_id;
  6817. WBUFW(buf,6)=-1;
  6818. WBUFW(buf,8)=-1;
  6819. clif_send(buf,packet_len(0x107),&sd->bl,PARTY_SAMEMAP_WOS);
  6820. return 0;
  6821. }
  6822. //Displays gospel-buff information (thanks to Rayce):
  6823. //Type determines message based on this table:
  6824. /*
  6825. 0x15 End all negative status
  6826. 0x16 Immunity to all status
  6827. 0x17 MaxHP +100%
  6828. 0x18 MaxSP +100%
  6829. 0x19 All stats +20
  6830. 0x1c Enchant weapon with Holy element
  6831. 0x1d Enchant armor with Holy element
  6832. 0x1e DEF +25%
  6833. 0x1f ATK +100%
  6834. 0x20 HIT/Flee +50
  6835. 0x28 Full strip failed because of coating (unrelated to gospel, maybe for ST_FULLSTRIP)
  6836. */
  6837. void clif_gospel_info(struct map_session_data *sd, int type)
  6838. {
  6839. int fd=sd->fd;
  6840. WFIFOHEAD(fd,packet_len(0x215));
  6841. WFIFOW(fd,0)=0x215;
  6842. WFIFOL(fd,2)=type;
  6843. WFIFOSET(fd, packet_len(0x215));
  6844. }
  6845. /*==========================================
  6846. * Info about Star Glaldiator save map [Komurka]
  6847. * type: 1: Information, 0: Map registered
  6848. *------------------------------------------
  6849. */
  6850. void clif_feel_info(struct map_session_data *sd, unsigned char feel_level, unsigned char type)
  6851. {
  6852. int fd=sd->fd;
  6853. char map_name[MAP_NAME_LENGTH];
  6854. snprintf(map_name, MAP_NAME_LENGTH, "%s.gat", mapindex_id2name(sd->feel_map[feel_level].index));
  6855. WFIFOHEAD(fd,packet_len(0x20e));
  6856. WFIFOW(fd,0)=0x20e;
  6857. memcpy(WFIFOP(fd,2),map_name, MAP_NAME_LENGTH);
  6858. WFIFOL(fd,26)=sd->bl.id;
  6859. WFIFOB(fd,30)=feel_level;
  6860. WFIFOB(fd,31)=type?1:0;
  6861. WFIFOSET(fd, packet_len(0x20e));
  6862. }
  6863. /*==========================================
  6864. * Info about Star Glaldiator hate mob [Komurka]
  6865. * type: 1: Register mob, 0: Information.
  6866. *------------------------------------------
  6867. */
  6868. void clif_hate_info(struct map_session_data *sd, unsigned char hate_level,int class_, unsigned char type)
  6869. {
  6870. int fd=sd->fd;
  6871. WFIFOHEAD(fd,packet_len(0x20e));
  6872. WFIFOW(fd,0)=0x20e;
  6873. if (pcdb_checkid(class_))
  6874. strncpy(WFIFOP(fd,2),job_name(class_), NAME_LENGTH);
  6875. else if (mobdb_checkid(class_))
  6876. strncpy(WFIFOP(fd,2),mob_db(class_)->jname, NAME_LENGTH);
  6877. else //Really shouldn't happen...
  6878. memset(WFIFOP(fd,2), 0, NAME_LENGTH);
  6879. WFIFOL(fd,26)=sd->bl.id;
  6880. WFIFOB(fd,30)=hate_level;
  6881. WFIFOB(fd,31)=type?10:11; //Register/Info
  6882. WFIFOSET(fd, packet_len(0x20e));
  6883. }
  6884. /*==========================================
  6885. * Info about TaeKwon Do TK_MISSION mob [Skotlex]
  6886. *------------------------------------------
  6887. */
  6888. void clif_mission_info(struct map_session_data *sd, int mob_id, unsigned char progress)
  6889. {
  6890. int fd=sd->fd;
  6891. WFIFOHEAD(fd,packet_len(0x20e));
  6892. WFIFOW(fd,0)=0x20e;
  6893. strncpy(WFIFOP(fd,2),mob_db(mob_id)->jname, NAME_LENGTH);
  6894. WFIFOL(fd,26)=mob_id;
  6895. WFIFOB(fd,30)=progress; //Message to display
  6896. WFIFOB(fd,31)=20;
  6897. WFIFOSET(fd, packet_len(0x20e));
  6898. }
  6899. /*==========================================
  6900. * Feel/Hate reset (thanks to Rayce) [Skotlex]
  6901. *------------------------------------------
  6902. */
  6903. void clif_feel_hate_reset(struct map_session_data *sd)
  6904. {
  6905. int fd=sd->fd;
  6906. WFIFOHEAD(fd,packet_len(0x20e));
  6907. WFIFOW(fd,0)=0x20e;
  6908. memset(WFIFOP(fd,2), 0, NAME_LENGTH); //Blank name as all was reset.
  6909. WFIFOL(fd,26)=sd->bl.id;
  6910. WFIFOB(fd,30)=0; //Feel/hate level: irrelevant
  6911. WFIFOB(fd,31)=30;
  6912. WFIFOSET(fd, packet_len(0x20e));
  6913. }
  6914. // ---------------------
  6915. // clif_guess_PacketVer
  6916. // ---------------------
  6917. // Parses a WantToConnection packet to try to identify which is the packet version used. [Skotlex]
  6918. // error codes:
  6919. // 0 - Success
  6920. // 1 - Unknown packet_ver
  6921. // 2 - Invalid account_id
  6922. // 3 - Invalid char_id
  6923. // 4 - Invalid login_id1 (reserved)
  6924. // 5 - Invalid client_tick (reserved)
  6925. // 6 - Invalid sex
  6926. // Only the first 'invalid' error that appears is used.
  6927. static int clif_guess_PacketVer(int fd, int get_previous, int *error)
  6928. {
  6929. static int err = 1;
  6930. static int packet_ver = -1;
  6931. int cmd, packet_len, value; //Value is used to temporarily store account/char_id/sex
  6932. RFIFOHEAD(fd);
  6933. if (get_previous)
  6934. {//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]
  6935. if( error )
  6936. *error = err;
  6937. return packet_ver;
  6938. }
  6939. //By default, start searching on the default one.
  6940. err = 1;
  6941. packet_ver = clif_config.packet_db_ver;
  6942. cmd = RFIFOW(fd,0);
  6943. packet_len = RFIFOREST(fd);
  6944. #define SET_ERROR(n) \
  6945. if( err == 1 )\
  6946. err = n;\
  6947. //define SET_ERROR
  6948. #define CHECK_PACKET_VER() \
  6949. if( cmd != clif_config.connect_cmd[packet_ver] || packet_len != packet_db[packet_ver][cmd].len )\
  6950. ;/* not wanttoconnection or wrong length */\
  6951. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[0])) < START_ACCOUNT_NUM || value > max_account_id )\
  6952. { SET_ERROR(2); }/* invalid account_id */\
  6953. else if( (value=(int)RFIFOL(fd, packet_db[packet_ver][cmd].pos[1])) <= 0 || value > max_char_id )\
  6954. { SET_ERROR(3); }/* invalid char_id */\
  6955. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]) - don't care about login_id1 */\
  6956. /* RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]) - don't care about client_tick */\
  6957. else if( (value=(int)RFIFOB(fd, packet_db[packet_ver][cmd].pos[4])) != 0 && value != 1 )\
  6958. { SET_ERROR(6); }/* invalid sex */\
  6959. else\
  6960. {\
  6961. err = 0;\
  6962. if( error )\
  6963. *error = 0;\
  6964. return packet_ver;\
  6965. }\
  6966. //define CHECK_PACKET_VER
  6967. CHECK_PACKET_VER();//Default packet version found.
  6968. for (packet_ver = MAX_PACKET_VER; packet_ver > 0; packet_ver--)
  6969. { //Start guessing the version, giving priority to the newer ones. [Skotlex]
  6970. CHECK_PACKET_VER();
  6971. }
  6972. if( error )
  6973. *error = err;
  6974. packet_ver = -1;
  6975. return -1;
  6976. #undef SET_ERROR
  6977. #undef CHECK_PACKET_VER
  6978. }
  6979. // ------------
  6980. // clif_parse_*
  6981. // ------------
  6982. // パケット読み取って色々操作
  6983. /*==========================================
  6984. *
  6985. *------------------------------------------
  6986. */
  6987. void clif_parse_WantToConnection(int fd, TBL_PC* sd)
  6988. {
  6989. int cmd, account_id, char_id, login_id1, sex;
  6990. unsigned int client_tick; //The client tick is a tick, therefore it needs be unsigned. [Skotlex]
  6991. 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])
  6992. RFIFOHEAD(fd);
  6993. if (sd) {
  6994. if (battle_config.error_log)
  6995. ShowError("clif_parse_WantToConnection : invalid request (character already logged in)?\n");
  6996. return;
  6997. }
  6998. // Only valid packet version get here
  6999. packet_ver = clif_guess_PacketVer(fd, 1, NULL);
  7000. cmd = RFIFOW(fd,0);
  7001. account_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[0]);
  7002. char_id = RFIFOL(fd, packet_db[packet_ver][cmd].pos[1]);
  7003. login_id1 = RFIFOL(fd, packet_db[packet_ver][cmd].pos[2]);
  7004. client_tick = RFIFOL(fd, packet_db[packet_ver][cmd].pos[3]);
  7005. sex = RFIFOB(fd, packet_db[packet_ver][cmd].pos[4]);
  7006. if( packet_ver < 5 || // reject really old client versions
  7007. (packet_ver <= 9 && (battle_config.packet_ver_flag & 1) == 0) || // older than 6sept04
  7008. (packet_ver > 9 && (battle_config.packet_ver_flag & 1<<(packet_ver-9)) == 0)) // version not allowed
  7009. {// packet version rejected
  7010. WFIFOHEAD(fd,packet_len(0x6a));
  7011. WFIFOW(fd,0) = 0x6a;
  7012. WFIFOB(fd,2) = 5; // Your Game's EXE file is not the latest version
  7013. WFIFOSET(fd,packet_len(0x6a));
  7014. clif_setwaitclose(fd);
  7015. return;
  7016. } else
  7017. {// packet version accepted
  7018. struct block_list* bl;
  7019. if( (bl=map_id2bl(account_id)) != NULL && bl->type != BL_PC )
  7020. {// non-player object already has that id
  7021. ShowError("clif_parse_WantToConnection: a non-player object already has id %d, please increase the starting account number\n", account_id);
  7022. WFIFOHEAD(fd,packet_len(0x6a));
  7023. WFIFOW(fd,0) = 0x6a;
  7024. WFIFOB(fd,2) = 3; // Rejected by server
  7025. WFIFOSET(fd,packet_len(0x6a));
  7026. clif_setwaitclose(fd);
  7027. return;
  7028. }
  7029. }
  7030. CREATE(sd, TBL_PC, 1);
  7031. sd->fd = fd;
  7032. sd->packet_ver = packet_ver;
  7033. session[fd]->session_data = sd;
  7034. pc_setnewpc(sd, account_id, char_id, login_id1, client_tick, sex, fd);
  7035. WFIFOHEAD(fd,4);
  7036. WFIFOL(fd,0) = sd->bl.id;
  7037. WFIFOSET(fd,4);
  7038. chrif_authreq(sd);
  7039. return;
  7040. }
  7041. /*==========================================
  7042. * 007d クライアント側マップ読み込み完了
  7043. * map侵入時に必要なデータを全て送りつける
  7044. *------------------------------------------
  7045. */
  7046. void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
  7047. {
  7048. if(sd->bl.prev != NULL)
  7049. return;
  7050. if (!sd->state.auth)
  7051. { //Character loading is not complete yet!
  7052. //Let pc_reg_received reinvoke this when ready.
  7053. sd->state.connect_new = 0;
  7054. return;
  7055. }
  7056. if (sd->state.rewarp)
  7057. { //Rewarp player.
  7058. sd->state.rewarp = 0;
  7059. clif_changemap(sd,sd->mapindex,sd->bl.x,sd->bl.y);
  7060. return;
  7061. }
  7062. // look
  7063. #if PACKETVER < 4
  7064. clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
  7065. clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
  7066. #else
  7067. clif_changelook(&sd->bl,LOOK_WEAPON,0);
  7068. #endif
  7069. if(sd->vd.cloth_color)
  7070. clif_refreshlook(&sd->bl,sd->bl.id,LOOK_CLOTHES_COLOR,sd->vd.cloth_color,SELF);
  7071. // item
  7072. pc_checkitem(sd);
  7073. clif_inventorylist(sd);
  7074. // cart
  7075. if(pc_iscarton(sd)){
  7076. clif_cartlist(sd);
  7077. clif_updatestatus(sd,SP_CARTINFO);
  7078. }
  7079. // weight max , now
  7080. clif_updatestatus(sd,SP_MAXWEIGHT);
  7081. clif_updatestatus(sd,SP_WEIGHT);
  7082. if(battle_config.pc_invincible_time > 0) {
  7083. if(map_flag_gvg(sd->bl.m))
  7084. pc_setinvincibletimer(sd,battle_config.pc_invincible_time<<1);
  7085. else
  7086. pc_setinvincibletimer(sd,battle_config.pc_invincible_time);
  7087. }
  7088. map_addblock(&sd->bl); // ブロック登録
  7089. clif_spawn(&sd->bl); // spawn
  7090. // Party
  7091. if(sd->status.party_id) {
  7092. party_send_movemap(sd);
  7093. clif_party_hp(sd); // Show hp after displacement [LuzZza]
  7094. }
  7095. // guild
  7096. if(sd->status.guild_id)
  7097. guild_send_memberinfoshort(sd,1);
  7098. if(map[sd->bl.m].flag.pvp){
  7099. if(!battle_config.pk_mode) { // remove pvp stuff for pk_mode [Valaris]
  7100. if (!map[sd->bl.m].flag.pvp_nocalcrank)
  7101. sd->pvp_timer= add_timer(gettick()+200,
  7102. pc_calc_pvprank_timer,sd->bl.id,0);
  7103. sd->pvp_rank=0;
  7104. sd->pvp_lastusers=0;
  7105. sd->pvp_point=5;
  7106. sd->pvp_won=0;
  7107. sd->pvp_lost=0;
  7108. }
  7109. clif_set0199(fd,1);
  7110. } else
  7111. // set flag, if it's a duel [LuzZza]
  7112. if(sd->duel_group)
  7113. clif_set0199(fd, 1);
  7114. if (map[sd->bl.m].flag.gvg_dungeon)
  7115. {
  7116. clif_set0199(fd, 1); //TODO: Figure out the real packet to send here.
  7117. if (!sd->pvp_point)
  7118. {
  7119. sd->pvp_point=5; //Need to die twice to be warped out.
  7120. sd->pvp_won=0;
  7121. sd->pvp_lost=0;
  7122. }
  7123. }
  7124. if(map_flag_gvg(sd->bl.m))
  7125. clif_set0199(fd,3);
  7126. // pet
  7127. if(sd->pd) {
  7128. map_addblock(&sd->pd->bl);
  7129. clif_spawn(&sd->pd->bl);
  7130. clif_send_petdata(sd,0,0);
  7131. clif_send_petdata(sd,5,battle_config.pet_hair_style);
  7132. clif_send_petstatus(sd);
  7133. // skill_unit_move(&sd->pd->bl,gettick(),1);
  7134. }
  7135. //homunculus [blackhole89]
  7136. if(merc_is_hom_active(sd->hd)) {
  7137. map_addblock(&sd->hd->bl);
  7138. clif_spawn(&sd->hd->bl);
  7139. clif_hominfo(sd,sd->hd,1);
  7140. clif_hominfo(sd,sd->hd,0); //for some reason, at least older clients want this sent twice
  7141. clif_send_homdata(sd,0,0);
  7142. clif_homskillinfoblock(sd);
  7143. if (battle_config.hom_setting&0x8)
  7144. status_calc_bl(&sd->hd->bl, SCB_SPEED); //Homunc mimic their master's speed on each map change
  7145. if (!(battle_config.hom_setting&0x2))
  7146. skill_unit_move(&sd->hd->bl,gettick(),1); // apply land skills immediately
  7147. }
  7148. if(sd->state.connect_new) {
  7149. int lv;
  7150. sd->state.connect_new = 0;
  7151. clif_skillinfoblock(sd);
  7152. clif_updatestatus(sd,SP_NEXTBASEEXP);
  7153. clif_updatestatus(sd,SP_NEXTJOBEXP);
  7154. clif_updatestatus(sd,SP_SKILLPOINT);
  7155. clif_initialstatus(sd);
  7156. if (sd->sc.option&OPTION_FALCON)
  7157. clif_status_load(&sd->bl, SI_FALCON, 1);
  7158. if (sd->sc.option&OPTION_RIDING)
  7159. clif_status_load(&sd->bl, SI_RIDING, 1);
  7160. if(sd->status.manner < 0)
  7161. sc_start(&sd->bl,SC_NOCHAT,100,0,0);
  7162. //Auron reported that This skill only triggers when you logon on the map o.O [Skotlex]
  7163. if ((lv = pc_checkskill(sd,SG_KNOWLEDGE)) > 0) {
  7164. if(sd->bl.m == sd->feel_map[0].m
  7165. || sd->bl.m == sd->feel_map[1].m
  7166. || sd->bl.m == sd->feel_map[2].m)
  7167. sc_start(&sd->bl, SC_KNOWLEDGE, 100, lv, skill_get_time(SG_KNOWLEDGE, lv));
  7168. }
  7169. if(sd->pd && sd->pd->pet.intimate > 900)
  7170. clif_pet_emotion(sd->pd,(sd->pd->pet.class_ - 100)*100 + 50 + pet_hungry_val(sd->pd));
  7171. if(merc_is_hom_active(sd->hd))
  7172. merc_hom_init_timers(sd->hd);
  7173. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7174. {
  7175. sd->state.night = 1;
  7176. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7177. }
  7178. // Notify everyone that this char logged in [Skotlex].
  7179. clif_foreachclient(clif_friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 1);
  7180. //Login Event
  7181. npc_script_event(sd, NPCE_LOGIN);
  7182. } else {
  7183. //For some reason the client "loses" these on map-change.
  7184. clif_updatestatus(sd,SP_STR);
  7185. clif_updatestatus(sd,SP_AGI);
  7186. clif_updatestatus(sd,SP_VIT);
  7187. clif_updatestatus(sd,SP_INT);
  7188. clif_updatestatus(sd,SP_DEX);
  7189. clif_updatestatus(sd,SP_LUK);
  7190. sd->state.using_fake_npc = 0;
  7191. //New 'night' effect by dynamix [Skotlex]
  7192. if (night_flag && map[sd->bl.m].flag.nightenabled)
  7193. { //Display night.
  7194. if (!sd->state.night) {
  7195. sd->state.night = 1;
  7196. clif_status_load(&sd->bl, SI_NIGHT, 1);
  7197. }
  7198. } else if (sd->state.night) { //Clear night display.
  7199. sd->state.night = 0;
  7200. clif_status_load(&sd->bl, SI_NIGHT, 0);
  7201. }
  7202. if(sd->npc_id)
  7203. npc_event_dequeue(sd);
  7204. }
  7205. // Lance
  7206. if(sd->state.event_loadmap && map[sd->bl.m].flag.loadevent){
  7207. pc_setregstr(sd, add_str("@maploaded$"), map[sd->bl.m].name);
  7208. npc_script_event(sd, NPCE_LOADMAP);
  7209. }
  7210. if (pc_checkskill(sd, SG_DEVIL) && !pc_nextjobexp(sd))
  7211. clif_status_load(&sd->bl, SI_DEVIL, 1); //blindness [Komurka]
  7212. if (sd->sc.opt2) //Client loses these on warp.
  7213. clif_changeoption(&sd->bl);
  7214. clif_weather_check(sd);
  7215. map_foreachinarea(clif_getareachar,sd->bl.m,
  7216. sd->bl.x-AREA_SIZE,sd->bl.y-AREA_SIZE,sd->bl.x+AREA_SIZE,sd->bl.y+AREA_SIZE,
  7217. BL_ALL,sd);
  7218. // For automatic triggering of NPCs after map loading (so you don't need to walk 1 step first)
  7219. if (map_getcell(sd->bl.m,sd->bl.x,sd->bl.y,CELL_CHKNPC))
  7220. npc_touch_areanpc(sd,sd->bl.m,sd->bl.x,sd->bl.y);
  7221. else
  7222. sd->areanpc_id = 0;
  7223. // If player is dead, and is spawned (such as @refresh) send death packet. [Valaris]
  7224. if(pc_isdead(sd))
  7225. clif_clearchar_area(&sd->bl,1);
  7226. // Uncomment if you want to make player face in the same direction he was facing right before warping. [Skotlex]
  7227. // else
  7228. // clif_changed_dir(&sd->bl, SELF);
  7229. // Trigger skill effects if you appear standing on them
  7230. if(!battle_config.pc_invincible_time)
  7231. skill_unit_move(&sd->bl,gettick(),1);
  7232. }
  7233. /*==========================================
  7234. *
  7235. *------------------------------------------
  7236. */
  7237. void clif_parse_TickSend(int fd, struct map_session_data *sd) {
  7238. RFIFOHEAD(fd);
  7239. sd->client_tick=RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7240. WFIFOHEAD(fd, packet_len(0x7f));
  7241. WFIFOW(fd,0)=0x7f;
  7242. WFIFOL(fd,2)=gettick();
  7243. WFIFOSET(fd,packet_len(0x7f));
  7244. // removed until the socket problems are fixed. [FlavioJS]
  7245. //flush_fifo(fd); // try to send immediatly so the client gets more accurate "pings"
  7246. return;
  7247. }
  7248. /*==========================================
  7249. *
  7250. *------------------------------------------
  7251. */
  7252. void clif_parse_WalkToXY(int fd, struct map_session_data *sd) {
  7253. int x, y;
  7254. int cmd;
  7255. RFIFOHEAD(fd);
  7256. if (pc_isdead(sd)) {
  7257. clif_clearchar_area(&sd->bl, 1);
  7258. return;
  7259. }
  7260. if (sd->sc.opt1 && sd->sc.opt1 == OPT1_STONEWAIT)
  7261. ; //You CAN walk on this OPT1 value.
  7262. else if (clif_cant_act(sd))
  7263. return;
  7264. if(sd->sc.count && sd->sc.data[SC_RUN].timer != -1)
  7265. return;
  7266. pc_delinvincibletimer(sd);
  7267. cmd = RFIFOW(fd,0);
  7268. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  7269. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  7270. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  7271. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  7272. //Set last idle time... [Skotlex]
  7273. sd->idletime = last_tick;
  7274. unit_walktoxy(&sd->bl, x, y, 4);
  7275. }
  7276. /*==========================================
  7277. *
  7278. *------------------------------------------
  7279. */
  7280. void clif_parse_QuitGame(int fd, struct map_session_data *sd) {
  7281. WFIFOHEAD(fd,packet_len(0x18b));
  7282. WFIFOW(fd,0) = 0x18b;
  7283. /* Rovert's prevent logout option fixed [Valaris] */
  7284. if (sd->sc.data[SC_CLOAKING].timer==-1 && sd->sc.data[SC_HIDING].timer==-1 &&
  7285. (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7286. ) {
  7287. clif_setwaitclose(fd);
  7288. WFIFOW(fd,2)=0;
  7289. } else {
  7290. WFIFOW(fd,2)=1;
  7291. }
  7292. WFIFOSET(fd,packet_len(0x18b));
  7293. }
  7294. /*==========================================
  7295. *
  7296. *------------------------------------------
  7297. */
  7298. void check_fake_id(int fd, struct map_session_data *sd, int target_id) {
  7299. // if player asks for the fake player (only bot and modified client can see a hiden player)
  7300. /* if (target_id == server_char_id) {
  7301. char message_to_gm[strlen(msg_txt(536)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7302. sprintf(message_to_gm, msg_txt(536), sd->status.name, sd->status.account_id); // Character '%s' (account: %d) try to use a bot (it tries to detect a fake player).
  7303. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7304. // if we block people
  7305. if (battle_config.ban_bot < 0) {
  7306. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7307. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7308. // message about the ban
  7309. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7310. // if we ban people
  7311. } else if (battle_config.ban_bot > 0) {
  7312. chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, 0, battle_config.ban_bot, 0); // type: 2 - ban (year, month, day, hour, minute, second)
  7313. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7314. // message about the ban
  7315. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7316. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7317. // message about the ban
  7318. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7319. }
  7320. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7321. // send this info cause the bot ask until get an answer, damn spam
  7322. memset(WPACKETP(0), 0, packet_len(0x95));
  7323. WPACKETW(0) = 0x95;
  7324. WPACKETL(2) = server_char_id;
  7325. strncpy(WPACKETP(6), sd->status.name, 24);
  7326. SENDPACKET(fd, packet_len(0x95));
  7327. // take fake player out of screen
  7328. WPACKETW(0) = 0x80;
  7329. WPACKETL(2) = server_char_id;
  7330. WPACKETB(6) = 0;
  7331. SENDPACKET(fd, packet_len(0x80));
  7332. // take fake mob out of screen
  7333. WPACKETW(0) = 0x80;
  7334. WPACKETL(2) = server_fake_mob_id;
  7335. WPACKETB(6) = 0;
  7336. SENDPACKET(fd, packet_len(0x80));
  7337. }
  7338. // if player asks for the fake mob (only bot and modified client can see a hiden mob)
  7339. if (target_id == server_fake_mob_id) {
  7340. int fake_mob;
  7341. char message_to_gm[strlen(msg_txt(537)) + strlen(msg_txt(540)) + strlen(msg_txt(507)) + strlen(msg_txt(508))];
  7342. sprintf(message_to_gm, msg_txt(537), sd->status.name, sd->status.account_id); // Character '%s' (account: %d) try to use a bot (it tries to detect a fake mob).
  7343. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7344. // if we block people
  7345. if (battle_config.ban_bot < 0) {
  7346. chrif_char_ask_name(-1, sd->status.name, 1, 0, 0, 0, 0, 0, 0); // type: 1 - block
  7347. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7348. // message about the ban
  7349. sprintf(message_to_gm, msg_txt(540)); // This player has been definitivly blocked.
  7350. // if we ban people
  7351. } else if (battle_config.ban_bot > 0) {
  7352. chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, 0, battle_config.ban_bot, 0); // type: 2 - ban (year, month, day, hour, minute, second)
  7353. clif_setwaitclose(sd->fd); // forced to disconnect because of the hack
  7354. // message about the ban
  7355. sprintf(message_to_gm, msg_txt(507), battle_config.ban_bot); // This player has been banned for %d minute(s).
  7356. } else { // impossible to display: we don't send fake player if battle_config.ban_bot is == 0
  7357. // message about the ban
  7358. sprintf(message_to_gm, msg_txt(508)); // This player hasn't been banned (Ban option is disabled).
  7359. }
  7360. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message_to_gm);
  7361. // send this info cause the bot ask until get an answer, damn spam
  7362. memset(WPACKETP(0), 0, packet_len(0x95));
  7363. WPACKETW(0) = 0x95;
  7364. WPACKETL(2) = server_fake_mob_id;
  7365. fake_mob = fake_mob_list[(sd->bl.m + sd->fd + sd->status.char_id) % (sizeof(fake_mob_list) / sizeof(fake_mob_list[0]))]; // never same mob
  7366. if (!mobdb_checkid(fake_mob))
  7367. fake_mob = 1002; // poring (default)
  7368. strncpy(WPACKETP(6), mob_db[fake_mob].name, 24);
  7369. SENDPACKET(fd, packet_len(0x95));
  7370. // take fake mob out of screen
  7371. WPACKETW(0) = 0x80;
  7372. WPACKETL(2) = server_fake_mob_id;
  7373. WPACKETB(6) = 0;
  7374. SENDPACKET(fd, packet_len(0x80));
  7375. // take fake player out of screen
  7376. WPACKETW(0) = 0x80;
  7377. WPACKETL(2) = server_char_id;
  7378. WPACKETB(6) = 0;
  7379. SENDPACKET(fd, packet_len(0x80));
  7380. }
  7381. */
  7382. return;
  7383. }
  7384. /*==========================================
  7385. *
  7386. *------------------------------------------
  7387. */
  7388. void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) {
  7389. int account_id;
  7390. struct block_list* bl;
  7391. struct status_change *sc;
  7392. RFIFOHEAD(fd);
  7393. account_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7394. if(account_id<0 && -account_id == sd->bl.id) // for disguises [Valaris]
  7395. account_id= sd->bl.id;
  7396. bl = map_id2bl(account_id);
  7397. //Is this possible? Lagged clients could request names of already gone mobs/players. [Skotlex]
  7398. if (!bl) return;
  7399. sc = status_get_sc(bl);
  7400. if (sc && sc->option&OPTION_INVISIBLE && !disguised(bl) &&
  7401. bl->type != BL_NPC && //Skip hidden NPCs which can be seen using Maya Purple
  7402. pc_isGM(sd) < battle_config.hack_info_GM_level
  7403. ) {
  7404. //GM characters (with client side GM enabled are able to see invisible stuff) [Lance]
  7405. //Asked name of invisible player, this shouldn't be possible!
  7406. //Possible bot? Thanks to veider and qspirit
  7407. //FIXME: Still isn't perfected as clients keep asking for this on legitimate situations.
  7408. unsigned char gm_msg[256];
  7409. sprintf(gm_msg, "Hack on NameRequest: character '%s' (account: %d) requests name of invisible chars.", sd->status.name, sd->status.account_id);
  7410. ShowWarning(gm_msg);
  7411. // information is sended to all online GM
  7412. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, gm_msg);
  7413. return;
  7414. }
  7415. clif_charnameack(fd, bl);
  7416. }
  7417. /*==========================================
  7418. * Validates and processes global messages
  7419. * S 008c/00f3 <packet len>.w <strz>.?B
  7420. *------------------------------------------*/
  7421. void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
  7422. {
  7423. char* message;
  7424. unsigned int packetlen, messagelen, namelen;
  7425. RFIFOHEAD(fd);
  7426. packetlen = RFIFOW(fd,2);
  7427. if (packetlen > RFIFOREST(fd)) { // there has to be enough data to read
  7428. ShowWarning("clif_parse_GlobalMessage: Received malformed packet from player '%s' (length is incorrect)!", sd->status.name);
  7429. return;
  7430. }
  7431. if (packetlen < 4 + 1) { // 4-byte header and at least an empty string is expected
  7432. ShowWarning("clif_parse_GlobalMessage: Received malformed packet from player '%s' (no message data)!", sd->status.name);
  7433. return;
  7434. }
  7435. message = (char*)RFIFOP(fd,4);
  7436. messagelen = packetlen - 4; // let's trust the client here, nothing can go wrong and it saves us one strlen()
  7437. if (messagelen > CHAT_SIZE) { // messages mustn't be too long
  7438. int i;
  7439. // special case here - allow some more freedom for frost joke & dazzler
  7440. // TODO:? You could use a state flag when FrostJoke/Scream is used, and unset it once the skill triggers. [Skotlex]
  7441. for(i = 0; i < MAX_SKILLTIMERSKILL && sd->ud.skilltimerskill[i] &&
  7442. sd->ud.skilltimerskill[i]->skill_id != BA_FROSTJOKE &&
  7443. sd->ud.skilltimerskill[i]->skill_id != DC_SCREAM; i++);
  7444. if (i == MAX_SKILLTIMERSKILL || !sd->ud.skilltimerskill[i]) { // normal message, too long
  7445. ShowWarning("clif_parse_GlobalMessage: Player '%s' sent a message too long ('%.*s')!", sd->status.name, CHAT_SIZE, message);
  7446. return;
  7447. }
  7448. if (messagelen > 255) { // frost joke/dazzler, but still too long
  7449. ShowWarning("clif_parse_GlobalMessage: Player '%s' sent a message too long ('%.*s')!", sd->status.name, 255, message);
  7450. return;
  7451. }
  7452. }
  7453. if (message[messagelen-1] != '\0') { // message must be zero-terminated
  7454. ShowWarning("clif_parse_GlobalMessage: Player '%s' sent an unterminated string!", sd->status.name);
  7455. return;
  7456. }
  7457. namelen = strnlen(sd->status.name, NAME_LENGTH - 1);
  7458. if (strncmp(message, sd->status.name, namelen) || // the name has to match the speaker's name
  7459. message[namelen] != ' ' || message[namelen+1] != ':' || message[namelen+2] != ' ') // completely, not just the prefix
  7460. {
  7461. //Hacked message, or infamous "client desynch" issue where they pick one char while loading another.
  7462. clif_setwaitclose(fd); // Just kick them out to correct it.
  7463. ShowWarning("clif_parse_GlobalMessage: Player '%.*s' sent a messsage using an incorrect name ('%s')! Forcing a relog...", namelen, sd->status.name, message);
  7464. return;
  7465. }
  7466. if (is_atcommand(fd, sd, message) != AtCommand_None ||
  7467. is_charcommand(fd, sd, message) != CharCommand_None)
  7468. return;
  7469. if (sd->sc.count &&
  7470. (sd->sc.data[SC_BERSERK].timer != -1 ||
  7471. (sd->sc.data[SC_NOCHAT].timer != -1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)))
  7472. return;
  7473. if (battle_config.min_chat_delay)
  7474. { //[Skotlex]
  7475. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  7476. return;
  7477. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7478. }
  7479. // send message to others
  7480. WFIFOHEAD(fd, messagelen + 8);
  7481. WFIFOW(fd,0) = 0x8d;
  7482. WFIFOW(fd,2) = messagelen + 8;
  7483. WFIFOL(fd,4) = sd->bl.id;
  7484. memcpy(WFIFOP(fd,8), message, messagelen);
  7485. clif_send(WFIFOP(fd,0), WFIFOW(fd,2), &sd->bl, sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
  7486. // send back message to the speaker
  7487. memcpy(WFIFOP(fd,0), RFIFOP(fd,0), packetlen);
  7488. WFIFOW(fd,0) = 0x8e;
  7489. WFIFOSET(fd, WFIFOW(fd,2));
  7490. #ifdef PCRE_SUPPORT
  7491. map_foreachinrange(npc_chat_sub, &sd->bl, AREA_SIZE, BL_NPC, message, strlen(message), &sd->bl);
  7492. map_foreachinrange(mob_chat_sub, &sd->bl, AREA_SIZE, BL_MOB, message, strlen(message), &sd->bl);
  7493. #endif
  7494. // Celest
  7495. if ((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE) { //Super Novice.
  7496. char buf[256];
  7497. int next = pc_nextbaseexp(sd);
  7498. if (next > 0 && (sd->status.base_exp * 1000 / next)% 100 == 0) {
  7499. switch (sd->state.snovice_call_flag) {
  7500. case 0:
  7501. if (strstr(message, msg_txt(504)))
  7502. sd->state.snovice_call_flag++;
  7503. break;
  7504. case 1:
  7505. sprintf(buf, msg_txt(505), sd->status.name);
  7506. if (strstr(message, buf))
  7507. sd->state.snovice_call_flag++;
  7508. break;
  7509. case 2:
  7510. if (strstr(message, msg_txt(506)))
  7511. sd->state.snovice_call_flag++;
  7512. break;
  7513. case 3:
  7514. if (skillnotok(MO_EXPLOSIONSPIRITS,sd))
  7515. break; //Do not override the noskill mapflag. [Skotlex]
  7516. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,-1,
  7517. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  7518. 17,skill_get_time(MO_EXPLOSIONSPIRITS,1))); //Lv17-> +50 critical (noted by Poki) [Skotlex]
  7519. sd->state.snovice_call_flag= 0;
  7520. break;
  7521. }
  7522. }
  7523. }
  7524. return;
  7525. }
  7526. int clif_message(struct block_list *bl, const char* msg)
  7527. {
  7528. unsigned short msg_len = strlen(msg) + 1;
  7529. unsigned char buf[256];
  7530. nullpo_retr(0, bl);
  7531. WBUFW(buf, 0) = 0x8d;
  7532. WBUFW(buf, 2) = msg_len + 8;
  7533. WBUFL(buf, 4) = bl->id;
  7534. memcpy(WBUFP(buf, 8), msg, msg_len);
  7535. clif_send(buf, WBUFW(buf,2), bl, AREA_CHAT_WOC); // by Gengar
  7536. return 0;
  7537. }
  7538. /*==========================================
  7539. *
  7540. *------------------------------------------
  7541. */
  7542. void clif_parse_MapMove(int fd, struct map_session_data *sd) {
  7543. // /m /mapmove (as @rura GM command)
  7544. char output[MAP_NAME_LENGTH+15]; // Max length of a short: ' -6XXXX' -> 7 digits
  7545. char message[MAP_NAME_LENGTH+15+5]; // "/mm "+output
  7546. char *map_name;
  7547. RFIFOHEAD(fd);
  7548. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7549. return;
  7550. if(pc_isGM(sd) < get_atcommand_level(AtCommand_MapMove))
  7551. return;
  7552. map_name = RFIFOP(fd,2);
  7553. map_name[MAP_NAME_LENGTH-1]='\0';
  7554. sprintf(output, "%s %d %d", map_name, RFIFOW(fd,18), RFIFOW(fd,20));
  7555. atcommand_rura(fd, sd, "@rura", output);
  7556. if(log_config.gm && get_atcommand_level(AtCommand_MapMove) >= log_config.gm)
  7557. {
  7558. sprintf(message, "/mm %s", output);
  7559. log_atcommand(sd, message);
  7560. }
  7561. return;
  7562. }
  7563. /*==========================================
  7564. *
  7565. *------------------------------------------
  7566. */
  7567. void clif_changed_dir(struct block_list *bl, int type) {
  7568. unsigned char buf[64];
  7569. WBUFW(buf,0) = 0x9c;
  7570. WBUFL(buf,2) = bl->id;
  7571. WBUFW(buf,6) = bl->type==BL_PC?((TBL_PC*)bl)->head_dir:0;
  7572. WBUFB(buf,8) = unit_getdir(bl);
  7573. clif_send(buf, packet_len(0x9c), bl, type);
  7574. if (disguised(bl)) {
  7575. WBUFL(buf,2) = -bl->id;
  7576. WBUFW(buf,6) = 0;
  7577. clif_send(buf, packet_len(0x9c), bl, SELF);
  7578. }
  7579. return;
  7580. }
  7581. /*==========================================
  7582. *
  7583. *------------------------------------------
  7584. */
  7585. void clif_parse_ChangeDir(int fd, struct map_session_data *sd) {
  7586. unsigned char headdir, dir;
  7587. RFIFOHEAD(fd);
  7588. headdir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7589. dir = RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7590. pc_setdir(sd, dir, headdir);
  7591. clif_changed_dir(&sd->bl, AREA_WOS);
  7592. return;
  7593. }
  7594. /*==========================================
  7595. *
  7596. *------------------------------------------
  7597. */
  7598. void clif_parse_Emotion(int fd, struct map_session_data *sd) {
  7599. unsigned char buf[64];
  7600. RFIFOHEAD(fd);
  7601. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, NV_BASIC) >= 2) {
  7602. if (RFIFOB(fd,2) == 34) {// prevent use of the mute emote [Valaris]
  7603. clif_skill_fail(sd, 1, 0, 1);
  7604. return;
  7605. }
  7606. // fix flood of emotion icon (ro-proxy): flood only the hacker player
  7607. if (sd->emotionlasttime >= time(NULL)) {
  7608. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7609. clif_skill_fail(sd, 1, 0, 1);
  7610. return;
  7611. }
  7612. sd->emotionlasttime = time(NULL) + 1; // not more than 1 per second (using /commands the client can spam it)
  7613. WBUFW(buf,0) = 0xc0;
  7614. WBUFL(buf,2) = sd->bl.id;
  7615. WBUFB(buf,6) = RFIFOB(fd,2);
  7616. clif_send(buf, packet_len(0xc0), &sd->bl, AREA);
  7617. } else
  7618. clif_skill_fail(sd, 1, 0, 1);
  7619. }
  7620. /*==========================================
  7621. *
  7622. *------------------------------------------
  7623. */
  7624. void clif_parse_HowManyConnections(int fd, struct map_session_data *sd) {
  7625. WFIFOHEAD(fd,packet_len(0xc2));
  7626. WFIFOW(fd,0) = 0xc2;
  7627. WFIFOL(fd,2) = map_getusers();
  7628. WFIFOSET(fd,packet_len(0xc2));
  7629. }
  7630. void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type, int target_id, unsigned int tick)
  7631. {
  7632. unsigned char buf[64];
  7633. if (pc_isdead(sd)) {
  7634. clif_clearchar_area(&sd->bl, 1);
  7635. return;
  7636. }
  7637. if (sd->sc.count &&
  7638. (sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  7639. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  7640. sd->sc.data[SC_BLADESTOP].timer != -1))
  7641. return;
  7642. pc_stop_walking(sd, 1);
  7643. pc_stop_attack(sd);
  7644. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  7645. target_id = sd->bl.id;
  7646. switch(action_type) {
  7647. case 0x00: // once attack
  7648. case 0x07: // continuous attack
  7649. if (clif_cant_act(sd) || sd->sc.option&OPTION_HIDE)
  7650. return;
  7651. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  7652. return;
  7653. if (!battle_config.sdelay_attack_enable && pc_checkskill(sd, SA_FREECAST) <= 0) {
  7654. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  7655. clif_skill_fail(sd, 1, 4, 0);
  7656. return;
  7657. }
  7658. }
  7659. pc_delinvincibletimer(sd);
  7660. sd->idletime = last_tick;
  7661. unit_attack(&sd->bl, target_id, action_type != 0);
  7662. break;
  7663. case 0x02: // sitdown
  7664. if (battle_config.basic_skill_check && pc_checkskill(sd, NV_BASIC) < 3) {
  7665. clif_skill_fail(sd, 1, 0, 2);
  7666. break;
  7667. }
  7668. if(pc_issit(sd)) {
  7669. //Bugged client? Just refresh them.
  7670. WBUFW(buf, 0) = 0x8a;
  7671. WBUFL(buf, 2) = sd->bl.id;
  7672. WBUFB(buf,26) = 2;
  7673. clif_send(buf, packet_len(0x8a), &sd->bl, SELF);
  7674. return;
  7675. }
  7676. if (sd->ud.skilltimer != -1 || sd->sc.opt1)
  7677. break;
  7678. if (sd->sc.count && (
  7679. sd->sc.data[SC_DANCING].timer != -1 ||
  7680. (sd->sc.data[SC_GRAVITATION].timer != -1 && sd->sc.data[SC_GRAVITATION].val3 == BCT_SELF)
  7681. )) //No sitting during these states neither.
  7682. break;
  7683. pc_setsit(sd);
  7684. skill_sit(sd, 1);
  7685. clif_sitting(sd);
  7686. break;
  7687. case 0x03: // standup
  7688. if (!pc_issit(sd)) {
  7689. //Bugged client? Just refresh them.
  7690. WBUFW(buf, 0) = 0x8a;
  7691. WBUFL(buf, 2) = sd->bl.id;
  7692. WBUFB(buf,26) = 3;
  7693. clif_send(buf, packet_len(0x8a), &sd->bl, SELF);
  7694. return;
  7695. }
  7696. pc_setstand(sd);
  7697. skill_sit(sd, 0);
  7698. WBUFW(buf, 0) = 0x8a;
  7699. WBUFL(buf, 2) = sd->bl.id;
  7700. WBUFB(buf,26) = 3;
  7701. clif_send(buf, packet_len(0x8a), &sd->bl, AREA);
  7702. break;
  7703. }
  7704. }
  7705. /*==========================================
  7706. *
  7707. *------------------------------------------
  7708. */
  7709. void clif_parse_ActionRequest(int fd, struct map_session_data *sd) {
  7710. RFIFOHEAD(fd);
  7711. clif_parse_ActionRequest_sub(sd,
  7712. RFIFOB(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]),
  7713. RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]),
  7714. gettick()
  7715. );
  7716. }
  7717. /*==========================================
  7718. *
  7719. *------------------------------------------
  7720. */
  7721. void clif_parse_Restart(int fd, struct map_session_data *sd) {
  7722. RFIFOHEAD(fd);
  7723. switch(RFIFOB(fd,2)) {
  7724. case 0x00:
  7725. if (!pc_isdead(sd))
  7726. break;
  7727. pc_setstand(sd);
  7728. pc_setrestartvalue(sd, 3);
  7729. //If warping fails, send a normal stand up packet.
  7730. if (pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, 2))
  7731. clif_resurrection(&sd->bl, 1);
  7732. break;
  7733. case 0x01:
  7734. /* Rovert's Prevent logout option - Fixed [Valaris] */
  7735. if (!battle_config.prevent_logout || DIFF_TICK(gettick(), sd->canlog_tick) > battle_config.prevent_logout)
  7736. { //Send to char-server for character selection.
  7737. chrif_charselectreq(sd, session[fd]->client_addr.sin_addr.s_addr);
  7738. } else {
  7739. WFIFOHEAD(fd,packet_len(0x18b));
  7740. WFIFOW(fd,0)=0x18b;
  7741. WFIFOW(fd,2)=1;
  7742. WFIFOSET(fd,packet_len(0x018b));
  7743. }
  7744. break;
  7745. }
  7746. }
  7747. /*==========================================
  7748. * Transmission of a wisp (S 0096 <len>.w <nick>.24B <message>.?B)
  7749. *------------------------------------------
  7750. */
  7751. void clif_parse_Wis(int fd, struct map_session_data *sd) { // S 0096 <len>.w <nick>.24B <message>.?B // rewritten by [Yor]
  7752. char *command, *msg;
  7753. struct map_session_data *dstsd;
  7754. int i=0;
  7755. struct npc_data *npc;
  7756. char split_data[10][50];
  7757. char target[NAME_LENGTH+1];
  7758. char output[256];
  7759. unsigned int len;
  7760. RFIFOHEAD(fd);
  7761. len = RFIFOW(fd,2); //Packet length
  7762. if (len < 28)
  7763. { //Invalid packet, specified size is less than minimum! [Skotlex]
  7764. ShowWarning("Hack on Whisper: %s (AID/CID: %d:%d)!\n", sd->status.name, sd->status.account_id, sd->status.char_id);
  7765. clif_setwaitclose(fd);
  7766. return;
  7767. }
  7768. if (len == 28) return; //Not sure if client really lets you send a blank line.
  7769. len-=28; //Message length
  7770. // 24+3+(RFIFOW(fd,2)-28)+1 <- last 1 is '\0'
  7771. command = (char*)aMallocA((NAME_LENGTH+4+len) * sizeof(char));
  7772. //No need for out of memory checks, malloc.c aborts the map when that happens.
  7773. msg = command;
  7774. msg+= sprintf(command, "%s : ", sd->status.name);
  7775. memcpy(msg, RFIFOP(fd, 28), len);
  7776. mes_len_check(msg, len, CHATBOX_SIZE);
  7777. if ((is_charcommand(fd, sd, command) != CharCommand_None) ||
  7778. (is_atcommand(fd, sd, command) != AtCommand_None)) {
  7779. aFree(command);
  7780. return;
  7781. }
  7782. if (sd->sc.count &&
  7783. (sd->sc.data[SC_BERSERK].timer!=-1 ||
  7784. (sd->sc.data[SC_NOCHAT].timer != -1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT))) {
  7785. aFree(command);
  7786. return;
  7787. }
  7788. if (battle_config.min_chat_delay)
  7789. { //[Skotlex]
  7790. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0) {
  7791. aFree(command);
  7792. return;
  7793. }
  7794. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  7795. }
  7796. memcpy(&target,RFIFOP(fd, 4),NAME_LENGTH);
  7797. target[NAME_LENGTH]='\0';
  7798. //Chat Logging type 'W' / Whisper
  7799. if(log_config.chat&1 //we log everything then
  7800. || ( log_config.chat&2 //if Whisper bit is on
  7801. && ( !agit_flag || !(log_config.chat&16) ))) //if WOE ONLY flag is off or AGIT is OFF
  7802. log_chat("W", 0, sd->status.char_id, sd->status.account_id, (char*)mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, msg);
  7803. //-------------------------------------------------------//
  7804. // Lordalfa - Paperboy - To whisper NPC commands //
  7805. //-------------------------------------------------------//
  7806. if (target[0] && (strncasecmp(target,"NPC:",4) == 0) && (strlen(target) >4)) {
  7807. char *str= target+4; //Skip the NPC: string part.
  7808. if ((npc = npc_name2id(str)))
  7809. {
  7810. char *split;
  7811. str = msg;
  7812. for( i=0; i < 10; ++i )
  7813. {// Splits the message using '#' as separators
  7814. split = strchr(str,'#');
  7815. if( split == NULL )
  7816. { // use the remaining string
  7817. strncpy(split_data[i], str, sizeof(split_data[0])/sizeof(char));
  7818. split_data[i][sizeof(split_data[0])/sizeof(char)-1] = '\0';
  7819. for( ++i; i < 10; ++i )
  7820. split_data[i][0] = '\0';
  7821. break;
  7822. }
  7823. *split = '\0';
  7824. strncpy(split_data[i], str, sizeof(split_data[0])/sizeof(char));
  7825. split_data[i][sizeof(split_data[0])/sizeof(char)-1] = '\0';
  7826. str = split+1;
  7827. }
  7828. for (i=0;i<10;i++)
  7829. {
  7830. sprintf(output, "@whispervar%d$", i);
  7831. set_var(sd,output,(char *) split_data[i]);
  7832. }
  7833. sprintf(output, "%s::OnWhisperGlobal", npc->name);
  7834. npc_event(sd,output,0); // Calls the NPC label
  7835. aFree(command);
  7836. return;
  7837. }
  7838. }
  7839. // Main chat [LuzZza]
  7840. if(strcmpi(target, main_chat_nick) == 0) {
  7841. if(!sd->state.mainchat)
  7842. clif_displaymessage(fd, msg_txt(388)); // You should enable main chat with "@main on" command.
  7843. else {
  7844. snprintf(output, sizeof(output)/sizeof(char), msg_txt(386), sd->status.name, msg);
  7845. intif_announce(output, strlen(output) + 1, 0xFE000000, 0);
  7846. }
  7847. aFree(command);
  7848. return;
  7849. }
  7850. // searching destination character
  7851. dstsd = map_nick2sd(target);
  7852. // player is not on this map-server
  7853. // At this point, don't send wisp/page if it's not exactly the same name, because (example)
  7854. // if there are 'Test' player on an other map-server and 'test' player on this map-server,
  7855. // and if we ask for 'Test', we must not contact 'test' player
  7856. // so, we send information to inter-server, which is the only one which decide (and copy correct name).
  7857. if (dstsd == NULL ||
  7858. strcmp(dstsd->status.name, target) != 0)
  7859. { // send message to inter-server
  7860. intif_wis_message(sd, target, msg, len);
  7861. aFree(command);
  7862. return;
  7863. }
  7864. // player is on this map-server
  7865. if (dstsd->fd == fd) {
  7866. // if you send to your self, don't send anything to others
  7867. // but, normally, it's impossible!
  7868. clif_wis_message(fd, wisp_server_name,
  7869. "You can not page yourself. Sorry.",
  7870. strlen("You can not page yourself. Sorry.") + 1);
  7871. aFree(command);
  7872. return;
  7873. }
  7874. // otherwise, send message and answer immediately
  7875. if (dstsd->state.ignoreAll) {
  7876. if (dstsd->sc.option & OPTION_INVISIBLE && pc_isGM(sd) < pc_isGM(dstsd))
  7877. clif_wis_end(fd, 1); // 1: target character is not loged in
  7878. else
  7879. clif_wis_end(fd, 3); // 3: everyone ignored by target
  7880. aFree(command);
  7881. return;
  7882. }
  7883. // if player ignore the source character
  7884. for(i = 0; i < MAX_IGNORE_LIST &&
  7885. dstsd->ignore[i].name[0] != '\0' &&
  7886. strcmp(dstsd->ignore[i].name, sd->status.name) != 0
  7887. ; i++);
  7888. if(i < MAX_IGNORE_LIST && dstsd->ignore[i].name[0] != '\0')
  7889. { //Ignored
  7890. clif_wis_end(fd, 2); // 2: ignored by target
  7891. aFree(command);
  7892. return;
  7893. }
  7894. // if source player not found in ignore list
  7895. if(dstsd->away_message[0] != '\0') { // Send away automessage [LuzZza]
  7896. //(Automessage has been sent)
  7897. sprintf(output, "%s %s", msg, msg_txt(543));
  7898. clif_wis_message(dstsd->fd, sd->status.name, output, strlen(output) + 1);
  7899. clif_wis_end(fd, 0); // 0: success to send wisper
  7900. if(dstsd->state.autotrade)
  7901. //"Away [AT] - \"%s\""
  7902. sprintf(output, msg_txt(544), dstsd->away_message);
  7903. else
  7904. //"Away - \"%s\""
  7905. sprintf(output, msg_txt(545), dstsd->away_message);
  7906. aFree(command);
  7907. clif_wis_message(fd, dstsd->status.name, output, strlen(output) + 1);
  7908. return;
  7909. }
  7910. // Normal message
  7911. clif_wis_message(dstsd->fd, sd->status.name, msg, len);
  7912. clif_wis_end(fd, 0); // 0: success to send wisper
  7913. aFree(command);
  7914. return;
  7915. }
  7916. /*==========================================
  7917. *
  7918. *------------------------------------------
  7919. */
  7920. void clif_parse_GMmessage(int fd, struct map_session_data *sd) {
  7921. // /b
  7922. char* mes;
  7923. int size, lv;
  7924. RFIFOHEAD(fd);
  7925. if (battle_config.atc_gmonly && !pc_isGM(sd))
  7926. return;
  7927. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_Broadcast)))
  7928. return;
  7929. size = RFIFOW(fd,2)-4;
  7930. mes = RFIFOP(fd,4);
  7931. mes_len_check(mes, size, CHAT_SIZE);
  7932. intif_GMmessage(mes, size, 0);
  7933. if(log_config.gm && lv >= log_config.gm) {
  7934. char message[CHAT_SIZE+4];
  7935. sprintf(message, "/b %s", mes);
  7936. log_atcommand(sd, message);
  7937. }
  7938. }
  7939. /*==========================================
  7940. *
  7941. *------------------------------------------
  7942. */
  7943. void clif_parse_TakeItem(int fd, struct map_session_data *sd) {
  7944. struct flooritem_data *fitem;
  7945. int map_object_id;
  7946. RFIFOHEAD(fd);
  7947. map_object_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  7948. fitem = (struct flooritem_data*)map_id2bl(map_object_id);
  7949. do {
  7950. if (pc_isdead(sd)) {
  7951. clif_clearchar_area(&sd->bl, 1);
  7952. break;
  7953. }
  7954. if (fitem == NULL || fitem->bl.type != BL_ITEM || fitem->bl.m != sd->bl.m)
  7955. break;
  7956. if (clif_cant_act(sd))
  7957. break;
  7958. //Disable cloaking/chasewalking characters from looting [Skotlex]
  7959. if(pc_iscloaking(sd) || pc_ischasewalk(sd))
  7960. break;
  7961. if(sd->sc.count && (
  7962. sd->sc.data[SC_TRICKDEAD].timer != -1 ||
  7963. sd->sc.data[SC_BLADESTOP].timer != -1 ||
  7964. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOITEM))
  7965. )
  7966. break;
  7967. if (!pc_takeitem(sd, fitem))
  7968. break;
  7969. return;
  7970. } while (0);
  7971. // Client REQUIRES a fail packet or you can no longer pick items.
  7972. clif_additem(sd,0,0,6);
  7973. }
  7974. /*==========================================
  7975. *
  7976. *------------------------------------------
  7977. */
  7978. void clif_parse_DropItem(int fd, struct map_session_data *sd) {
  7979. int item_index, item_amount;
  7980. RFIFOHEAD(fd);
  7981. if (pc_isdead(sd)) {
  7982. clif_clearchar_area(&sd->bl, 1);
  7983. return;
  7984. }
  7985. if (clif_cant_act(sd))
  7986. return;
  7987. if (sd->sc.count && (
  7988. sd->sc.data[SC_AUTOCOUNTER].timer != -1 ||
  7989. sd->sc.data[SC_BLADESTOP].timer != -1 ||
  7990. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOITEM)
  7991. ))
  7992. return;
  7993. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  7994. item_amount = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  7995. if (!pc_dropitem(sd, item_index, item_amount))
  7996. //Because the client does not likes being ignored.
  7997. clif_delitem(sd, item_index,0);
  7998. }
  7999. /*==========================================
  8000. *
  8001. *------------------------------------------
  8002. */
  8003. void clif_parse_UseItem(int fd, struct map_session_data *sd) {
  8004. int n;
  8005. RFIFOHEAD(fd);
  8006. if (pc_isdead(sd)) {
  8007. clif_clearchar_area(&sd->bl, 1);
  8008. return;
  8009. }
  8010. if (sd->sc.opt1 > 0 && sd->sc.opt1 != OPT1_STONEWAIT)
  8011. return;
  8012. //This flag enables you to use items while in an NPC. [Skotlex]
  8013. if (sd->npc_id) {
  8014. if (sd->npc_id != sd->npc_item_flag)
  8015. return;
  8016. } else
  8017. if (clif_trading(sd))
  8018. return;
  8019. pc_delinvincibletimer(sd);
  8020. //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
  8021. sd->idletime = last_tick;
  8022. n = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8023. if(n <0 || n >= MAX_INVENTORY)
  8024. return;
  8025. if (!pc_useitem(sd,n))
  8026. clif_useitemack(sd,n,0,0); //Send an empty ack packet or the client gets stuck.
  8027. }
  8028. /*==========================================
  8029. *
  8030. *------------------------------------------
  8031. */
  8032. void clif_parse_EquipItem(int fd,struct map_session_data *sd)
  8033. {
  8034. int index;
  8035. RFIFOHEAD(fd);
  8036. if(pc_isdead(sd)) {
  8037. clif_clearchar_area(&sd->bl,1);
  8038. return;
  8039. }
  8040. index = RFIFOW(fd,2)-2;
  8041. if (index < 0 || index >= MAX_INVENTORY)
  8042. return; //Out of bounds check.
  8043. if(sd->npc_id) {
  8044. if (sd->npc_id != sd->npc_item_flag)
  8045. return;
  8046. } else if (sd->state.storage_flag || sd->sc.opt1)
  8047. ; //You can equip/unequip stuff while storage is open/under status changes
  8048. else if (clif_cant_act(sd))
  8049. return;
  8050. if(sd->sc.data[SC_BLADESTOP].timer!=-1 || sd->sc.data[SC_BERSERK].timer!=-1 )
  8051. return;
  8052. if(!sd->status.inventory[index].identify) {
  8053. clif_equipitemack(sd,index,0,0); // fail
  8054. return;
  8055. }
  8056. if(!sd->inventory_data[index])
  8057. return;
  8058. if(sd->inventory_data[index]->type == IT_PETARMOR){
  8059. pet_equipitem(sd,index);
  8060. return;
  8061. }
  8062. //Client doesn't send the position for ammo.
  8063. if(sd->inventory_data[index]->type == IT_AMMO)
  8064. pc_equipitem(sd,index,EQP_AMMO);
  8065. else
  8066. pc_equipitem(sd,index,RFIFOW(fd,4));
  8067. }
  8068. /*==========================================
  8069. *
  8070. *------------------------------------------
  8071. */
  8072. void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
  8073. {
  8074. int index;
  8075. RFIFOHEAD(fd);
  8076. if(pc_isdead(sd)) {
  8077. clif_clearchar_area(&sd->bl,1);
  8078. return;
  8079. }
  8080. if (sd->state.storage_flag)
  8081. ; //You can equip/unequip stuff while storage is open.
  8082. else if (clif_cant_act(sd))
  8083. return;
  8084. index = RFIFOW(fd,2)-2;
  8085. pc_unequipitem(sd,index,1);
  8086. }
  8087. /*==========================================
  8088. *
  8089. *------------------------------------------
  8090. */
  8091. void clif_parse_NpcClicked(int fd,struct map_session_data *sd)
  8092. {
  8093. struct block_list *bl;
  8094. RFIFOHEAD(fd);
  8095. if(pc_isdead(sd)) {
  8096. clif_clearchar_area(&sd->bl,1);
  8097. return;
  8098. }
  8099. if (clif_cant_act(sd))
  8100. return;
  8101. bl = map_id2bl(RFIFOL(fd,2));
  8102. if (!bl) return;
  8103. switch (bl->type) {
  8104. case BL_MOB:
  8105. if (!((TBL_MOB *)bl)->nd || !mob_script_callback((TBL_MOB *)bl, &sd->bl, CALLBACK_NPCCLICK))
  8106. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8107. break;
  8108. case BL_PC:
  8109. clif_parse_ActionRequest_sub(sd, 0x07, bl->id, gettick());
  8110. break;
  8111. case BL_NPC:
  8112. npc_click(sd,(TBL_NPC*)bl);
  8113. break;
  8114. }
  8115. return;
  8116. }
  8117. /*==========================================
  8118. *
  8119. *------------------------------------------
  8120. */
  8121. void clif_parse_NpcBuySellSelected(int fd,struct map_session_data *sd)
  8122. {
  8123. RFIFOHEAD(fd);
  8124. if (sd->state.trading)
  8125. return;
  8126. npc_buysellsel(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  8127. }
  8128. /*==========================================
  8129. *
  8130. *------------------------------------------
  8131. */
  8132. void clif_parse_NpcBuyListSend(int fd,struct map_session_data *sd)
  8133. {
  8134. int fail=0,n;
  8135. unsigned short *item_list;
  8136. RFIFOHEAD(fd);
  8137. n = (RFIFOW(fd,2)-4) /4;
  8138. item_list = (unsigned short*)RFIFOP(fd,4);
  8139. if (sd->state.trading|| !sd->npc_shopid)
  8140. fail = 1;
  8141. else
  8142. fail = npc_buylist(sd,n,item_list);
  8143. sd->npc_shopid = 0; //Clear shop data.
  8144. WFIFOHEAD(fd,packet_len(0xca));
  8145. WFIFOW(fd,0)=0xca;
  8146. WFIFOB(fd,2)=fail;
  8147. WFIFOSET(fd,packet_len(0xca));
  8148. }
  8149. /*==========================================
  8150. *
  8151. *------------------------------------------
  8152. */
  8153. void clif_parse_NpcSellListSend(int fd,struct map_session_data *sd)
  8154. {
  8155. int fail=0,n;
  8156. unsigned short *item_list;
  8157. RFIFOHEAD(fd);
  8158. n = (RFIFOW(fd,2)-4) /4;
  8159. item_list = (unsigned short*)RFIFOP(fd,4);
  8160. if (sd->state.trading || !sd->npc_shopid)
  8161. fail = 1;
  8162. else
  8163. fail = npc_selllist(sd,n,item_list);
  8164. sd->npc_shopid = 0; //Clear shop data.
  8165. WFIFOHEAD(fd,packet_len(0xcb));
  8166. WFIFOW(fd,0)=0xcb;
  8167. WFIFOB(fd,2)=fail;
  8168. WFIFOSET(fd,packet_len(0xcb));
  8169. }
  8170. /*==========================================
  8171. *
  8172. *------------------------------------------
  8173. */
  8174. void clif_parse_CreateChatRoom(int fd,struct map_session_data *sd)
  8175. {
  8176. RFIFOHEAD(fd);
  8177. if (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOROOM)
  8178. return;
  8179. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 4){
  8180. chat_createchat(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8181. } else
  8182. clif_skill_fail(sd,1,0,3);
  8183. }
  8184. /*==========================================
  8185. *
  8186. *------------------------------------------
  8187. */
  8188. void clif_parse_ChatAddMember(int fd,struct map_session_data *sd)
  8189. {
  8190. RFIFOHEAD(fd);
  8191. chat_joinchat(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  8192. }
  8193. /*==========================================
  8194. *
  8195. *------------------------------------------
  8196. */
  8197. void clif_parse_ChatRoomStatusChange(int fd,struct map_session_data *sd)
  8198. {
  8199. RFIFOHEAD(fd);
  8200. chat_changechatstatus(sd,RFIFOW(fd,4),RFIFOB(fd,6),(char*)RFIFOP(fd,7),(char*)RFIFOP(fd,15),RFIFOW(fd,2)-15);
  8201. }
  8202. /*==========================================
  8203. *
  8204. *------------------------------------------
  8205. */
  8206. void clif_parse_ChangeChatOwner(int fd,struct map_session_data *sd)
  8207. {
  8208. RFIFOHEAD(fd);
  8209. chat_changechatowner(sd,(char*)RFIFOP(fd,6));
  8210. }
  8211. /*==========================================
  8212. *
  8213. *------------------------------------------
  8214. */
  8215. void clif_parse_KickFromChat(int fd,struct map_session_data *sd)
  8216. {
  8217. RFIFOHEAD(fd);
  8218. chat_kickchat(sd,(char*)RFIFOP(fd,2));
  8219. }
  8220. /*==========================================
  8221. *
  8222. *------------------------------------------
  8223. */
  8224. void clif_parse_ChatLeave(int fd,struct map_session_data *sd)
  8225. {
  8226. chat_leavechat(sd);
  8227. }
  8228. //Handles notifying asker and rejecter of what has just ocurred.
  8229. //Type is used to determine the correct msg_txt to use:
  8230. //0:
  8231. static void clif_noask_sub(struct map_session_data *src, struct map_session_data *target, int type)
  8232. {
  8233. char *msg, output[256];
  8234. // Your request has been rejected by autoreject option.
  8235. msg = msg_txt(392);
  8236. clif_disp_onlyself(src, msg, strlen(msg));
  8237. //Notice that a request was rejected.
  8238. snprintf(output, 256, msg_txt(393+type), src->status.name, 256);
  8239. clif_disp_onlyself(target, output, strlen(output));
  8240. }
  8241. /*==========================================
  8242. * 取引要請を相手に送る
  8243. *------------------------------------------
  8244. */
  8245. void clif_parse_TradeRequest(int fd,struct map_session_data *sd)
  8246. {
  8247. struct map_session_data *t_sd;
  8248. RFIFOHEAD(fd);
  8249. t_sd = map_id2sd(RFIFOL(fd,2));
  8250. if(!sd->chatID && clif_cant_act(sd))
  8251. return; //You can trade while in a chatroom.
  8252. // @noask [LuzZza]
  8253. if(t_sd && t_sd->state.noask) {
  8254. clif_noask_sub(sd, t_sd, 0);
  8255. return;
  8256. }
  8257. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 1){
  8258. trade_traderequest(sd,t_sd);
  8259. } else
  8260. clif_skill_fail(sd,1,0,0);
  8261. }
  8262. /*==========================================
  8263. * 取引要請
  8264. *------------------------------------------
  8265. */
  8266. void clif_parse_TradeAck(int fd,struct map_session_data *sd)
  8267. {
  8268. RFIFOHEAD(fd);
  8269. trade_tradeack(sd,RFIFOB(fd,2));
  8270. }
  8271. /*==========================================
  8272. * アイテム追加
  8273. *------------------------------------------
  8274. */
  8275. void clif_parse_TradeAddItem(int fd,struct map_session_data *sd)
  8276. {
  8277. RFIFOHEAD(fd);
  8278. trade_tradeadditem(sd,RFIFOW(fd,2),RFIFOL(fd,4));
  8279. }
  8280. /*==========================================
  8281. * アイテム追加完了(ok押し)
  8282. *------------------------------------------
  8283. */
  8284. void clif_parse_TradeOk(int fd,struct map_session_data *sd)
  8285. {
  8286. trade_tradeok(sd);
  8287. }
  8288. /*==========================================
  8289. * 取引キャンセル
  8290. *------------------------------------------
  8291. */
  8292. void clif_parse_TradeCancel(int fd,struct map_session_data *sd)
  8293. {
  8294. trade_tradecancel(sd);
  8295. }
  8296. /*==========================================
  8297. * 取引許諾(trade押し)
  8298. *------------------------------------------
  8299. */
  8300. void clif_parse_TradeCommit(int fd,struct map_session_data *sd)
  8301. {
  8302. trade_tradecommit(sd);
  8303. }
  8304. /*==========================================
  8305. *
  8306. *------------------------------------------
  8307. */
  8308. void clif_parse_StopAttack(int fd,struct map_session_data *sd)
  8309. {
  8310. pc_stop_attack(sd);
  8311. }
  8312. /*==========================================
  8313. * カートへアイテムを移す
  8314. *------------------------------------------
  8315. */
  8316. void clif_parse_PutItemToCart(int fd,struct map_session_data *sd)
  8317. {
  8318. RFIFOHEAD(fd);
  8319. if (clif_trading(sd))
  8320. return;
  8321. pc_putitemtocart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8322. }
  8323. /*==========================================
  8324. * カートからアイテムを出す
  8325. *------------------------------------------
  8326. */
  8327. void clif_parse_GetItemFromCart(int fd,struct map_session_data *sd)
  8328. {
  8329. RFIFOHEAD(fd);
  8330. pc_getitemfromcart(sd,RFIFOW(fd,2)-2,RFIFOL(fd,4));
  8331. }
  8332. /*==========================================
  8333. * 付属品(鷹,ペコ,カート)をはずす
  8334. *------------------------------------------
  8335. */
  8336. void clif_parse_RemoveOption(int fd,struct map_session_data *sd)
  8337. {
  8338. //Can only remove Cart/Riding/Falcon.
  8339. pc_setoption(sd,sd->sc.option&~(OPTION_CART|OPTION_RIDING|OPTION_FALCON));
  8340. }
  8341. /*==========================================
  8342. * チェンジカート
  8343. *------------------------------------------
  8344. */
  8345. void clif_parse_ChangeCart(int fd,struct map_session_data *sd)
  8346. {
  8347. int type;
  8348. RFIFOHEAD(fd);
  8349. type = (int)RFIFOW(fd,2);
  8350. if( (type == 5 && sd->status.base_level <= 90) ||
  8351. (type == 4 && sd->status.base_level <= 80) ||
  8352. (type == 3 && sd->status.base_level <= 65) ||
  8353. (type == 2 && sd->status.base_level <= 40) ||
  8354. pc_setcart(sd,type) )
  8355. {
  8356. LOG_SUSPICIOUS(sd,"clif_parse_ChangeCart");
  8357. }
  8358. }
  8359. /*==========================================
  8360. * ステータスアップ
  8361. *------------------------------------------
  8362. */
  8363. void clif_parse_StatusUp(int fd,struct map_session_data *sd)
  8364. {
  8365. RFIFOHEAD(fd);
  8366. pc_statusup(sd,RFIFOW(fd,2));
  8367. }
  8368. /*==========================================
  8369. * スキルレベルアップ
  8370. *------------------------------------------
  8371. */
  8372. void clif_parse_SkillUp(int fd,struct map_session_data *sd)
  8373. {
  8374. RFIFOHEAD(fd);
  8375. pc_skillup(sd,RFIFOW(fd,2));
  8376. }
  8377. static void clif_parse_UseSkillToId_homun(struct homun_data *hd, struct map_session_data *sd, unsigned int tick, int skillnum, int skilllv, int target_id)
  8378. {
  8379. int lv;
  8380. if (!hd)
  8381. return;
  8382. if (skillnotok_hom(skillnum, hd)) //[orn]
  8383. return;
  8384. if (hd->bl.id != target_id &&
  8385. skill_get_inf(skillnum)&INF_SELF_SKILL)
  8386. target_id = hd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8387. if (hd->ud.skilltimer != -1) {
  8388. if (skillnum != SA_CASTCANCEL)
  8389. return;
  8390. } else if (DIFF_TICK(tick, hd->ud.canact_tick) < 0)
  8391. return;
  8392. lv = merc_hom_checkskill(hd, skillnum);
  8393. if (skilllv > lv)
  8394. skilllv = lv;
  8395. if (skilllv)
  8396. unit_skilluse_id(&hd->bl, target_id, skillnum, skilllv);
  8397. }
  8398. /*==========================================
  8399. * スキル使用(ID指定)
  8400. *------------------------------------------
  8401. */
  8402. void clif_parse_UseSkillToId(int fd, struct map_session_data *sd) {
  8403. int skillnum, skilllv, tmp, target_id;
  8404. unsigned int tick = gettick();
  8405. RFIFOHEAD(fd);
  8406. if (clif_cant_act(sd))
  8407. return;
  8408. if (pc_issit(sd))
  8409. return;
  8410. skilllv = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8411. if (skilllv < 1) skilllv = 1; //No clue, I have seen the client do this with guild skills :/ [Skotlex]
  8412. skillnum = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8413. target_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]);
  8414. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8415. sd->idletime = last_tick;
  8416. tmp = skill_get_inf(skillnum);
  8417. if (tmp&INF_GROUND_SKILL)
  8418. return; //Using a ground skill on a target? WRONG.
  8419. if (skillnum >= HM_SKILLBASE && skillnum <= HM_SKILLBASE+MAX_HOMUNSKILL) {
  8420. clif_parse_UseSkillToId_homun(sd->hd, sd, tick, skillnum, skilllv, target_id);
  8421. return;
  8422. }
  8423. if (skillnotok(skillnum, sd))
  8424. return;
  8425. if (sd->bl.id != target_id && !sd->state.skill_flag && tmp&INF_SELF_SKILL)
  8426. target_id = sd->bl.id; //What good is it to mess up the target in self skills? Wished I knew... [Skotlex]
  8427. if (sd->ud.skilltimer != -1) {
  8428. if (skillnum != SA_CASTCANCEL)
  8429. return;
  8430. } else if (DIFF_TICK(tick, sd->ud.canact_tick) < 0) {
  8431. clif_skill_fail(sd, skillnum, 4, 0);
  8432. return;
  8433. }
  8434. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8435. return;
  8436. if(target_id<0 && -target_id == sd->bl.id) // for disguises [Valaris]
  8437. target_id = sd->bl.id;
  8438. if(sd->menuskill_id)
  8439. {
  8440. if (sd->menuskill_id == SA_TAMINGMONSTER)
  8441. sd->menuskill_id = sd->menuskill_lv = 0; //Cancel pet capture.
  8442. else
  8443. return; //Can't use skills while a menu is open.
  8444. }
  8445. if (sd->skillitem == skillnum) {
  8446. if (skilllv != sd->skillitemlv)
  8447. skilllv = sd->skillitemlv;
  8448. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8449. return;
  8450. }
  8451. sd->skillitem = sd->skillitemlv = 0;
  8452. if (skillnum == MO_EXTREMITYFIST) {
  8453. if ((sd->sc.data[SC_COMBO].timer == -1 ||
  8454. (sd->sc.data[SC_COMBO].val1 != MO_COMBOFINISH &&
  8455. sd->sc.data[SC_COMBO].val1 != CH_TIGERFIST &&
  8456. sd->sc.data[SC_COMBO].val1 != CH_CHAINCRUSH))) {
  8457. if (!sd->state.skill_flag ) {
  8458. sd->state.skill_flag = 1;
  8459. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8460. return;
  8461. } else if (sd->bl.id == target_id) {
  8462. clif_skillinfo(sd, MO_EXTREMITYFIST, INF_ATTACK_SKILL, -1);
  8463. return;
  8464. }
  8465. }
  8466. }
  8467. if (skillnum == TK_JUMPKICK) {
  8468. if (sd->sc.data[SC_COMBO].timer == -1 ||
  8469. sd->sc.data[SC_COMBO].val1 != TK_JUMPKICK) {
  8470. if (!sd->state.skill_flag ) {
  8471. sd->state.skill_flag = 1;
  8472. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8473. return;
  8474. } else if (sd->bl.id == target_id) {
  8475. clif_skillinfo(sd, TK_JUMPKICK, INF_ATTACK_SKILL, -1);
  8476. return;
  8477. }
  8478. }
  8479. }
  8480. if (skillnum >= GD_SKILLBASE) {
  8481. if (sd->state.gmaster_flag)
  8482. skilllv = guild_checkskill(sd->state.gmaster_flag, skillnum);
  8483. else
  8484. skilllv = 0;
  8485. } else {
  8486. tmp = pc_checkskill(sd, skillnum);
  8487. if (skilllv > tmp)
  8488. skilllv = tmp;
  8489. }
  8490. pc_delinvincibletimer(sd);
  8491. if (skilllv)
  8492. unit_skilluse_id(&sd->bl, target_id, skillnum, skilllv);
  8493. if (sd->state.skill_flag)
  8494. sd->state.skill_flag = 0;
  8495. }
  8496. /*==========================================
  8497. * スキル使用(場所指定)
  8498. *------------------------------------------
  8499. */
  8500. void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, int skilllv, int skillnum, int x, int y, int skillmoreinfo)
  8501. {
  8502. int lv;
  8503. unsigned int tick = gettick();
  8504. RFIFOHEAD(fd);
  8505. //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
  8506. sd->idletime = last_tick;
  8507. if (skillnotok(skillnum, sd))
  8508. return;
  8509. if (!(skill_get_inf(skillnum)&INF_GROUND_SKILL))
  8510. return; //Using a target skill on the ground? WRONG.
  8511. if (skillmoreinfo != -1) {
  8512. if (pc_issit(sd)) {
  8513. clif_skill_fail(sd, skillnum, 0, 0);
  8514. return;
  8515. }
  8516. //You can't use Graffiti/TalkieBox AND have a vending open, so this is safe.
  8517. memcpy(sd->message, RFIFOP(fd,skillmoreinfo), MESSAGE_SIZE);
  8518. sd->message[MESSAGE_SIZE-1] = '\0'; //Overflow protection [Skotlex]
  8519. }
  8520. if (sd->ud.skilltimer != -1)
  8521. return;
  8522. if (DIFF_TICK(tick, sd->ud.canact_tick) < 0)
  8523. {
  8524. clif_skill_fail(sd, skillnum, 4, 0);
  8525. return;
  8526. }
  8527. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8528. return;
  8529. if(sd->menuskill_id)
  8530. {
  8531. if (sd->menuskill_id == SA_TAMINGMONSTER)
  8532. sd->menuskill_id = sd->menuskill_lv = 0; //Cancel pet capture.
  8533. else
  8534. return; //Can't use skills while a menu is open.
  8535. }
  8536. pc_delinvincibletimer(sd);
  8537. if (sd->skillitem == skillnum) {
  8538. if (skilllv != sd->skillitemlv)
  8539. skilllv = sd->skillitemlv;
  8540. unit_skilluse_pos(&sd->bl, x, y, skillnum, skilllv);
  8541. } else {
  8542. sd->skillitem = sd->skillitemlv = 0;
  8543. if ((lv = pc_checkskill(sd, skillnum)) > 0) {
  8544. if (skilllv > lv)
  8545. skilllv = lv;
  8546. unit_skilluse_pos(&sd->bl, x, y, skillnum,skilllv);
  8547. }
  8548. }
  8549. }
  8550. void clif_parse_UseSkillToPos(int fd, struct map_session_data *sd) {
  8551. RFIFOHEAD(fd);
  8552. if (clif_cant_act(sd))
  8553. return;
  8554. if (pc_issit(sd))
  8555. return;
  8556. clif_parse_UseSkillToPosSub(fd, sd,
  8557. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //skill lv
  8558. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //skill num
  8559. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8560. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8561. -1 //Skill more info.
  8562. );
  8563. }
  8564. void clif_parse_UseSkillToPosMoreInfo(int fd, struct map_session_data *sd) {
  8565. RFIFOHEAD(fd);
  8566. if (clif_cant_act(sd))
  8567. return;
  8568. if (pc_issit(sd))
  8569. return;
  8570. clif_parse_UseSkillToPosSub(fd, sd,
  8571. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]), //Skill lv
  8572. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]), //Skill num
  8573. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[2]), //pos x
  8574. RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[3]), //pos y
  8575. packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[4] //skill more info
  8576. );
  8577. }
  8578. /*==========================================
  8579. * スキル使用(map指定)
  8580. *------------------------------------------
  8581. */
  8582. void clif_parse_UseSkillMap(int fd,struct map_session_data *sd)
  8583. {
  8584. RFIFOHEAD(fd);
  8585. if (clif_cant_act(sd))
  8586. return;
  8587. if(sd->sc.option&(OPTION_WEDDING|OPTION_XMAS))
  8588. return;
  8589. if(sd->menuskill_id && sd->menuskill_id != RFIFOW(fd,2))
  8590. return; //Can't use skills while a menu is open.
  8591. pc_delinvincibletimer(sd);
  8592. skill_castend_map(sd,RFIFOW(fd,2),(char*)RFIFOP(fd,4));
  8593. }
  8594. /*==========================================
  8595. * メモ要求
  8596. *------------------------------------------
  8597. */
  8598. void clif_parse_RequestMemo(int fd,struct map_session_data *sd)
  8599. {
  8600. if (!pc_isdead(sd))
  8601. pc_memo(sd,-1);
  8602. }
  8603. /*==========================================
  8604. * アイテム合成
  8605. *------------------------------------------
  8606. */
  8607. void clif_parse_ProduceMix(int fd,struct map_session_data *sd)
  8608. {
  8609. RFIFOHEAD(fd);
  8610. if (sd->menuskill_id != AM_PHARMACY)
  8611. return;
  8612. if (clif_trading(sd)) {
  8613. //Make it fail to avoid shop exploits where you sell something different than you see.
  8614. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8615. sd->menuskill_lv = sd->menuskill_id = 0;
  8616. return;
  8617. }
  8618. skill_produce_mix(sd,0,RFIFOW(fd,2),RFIFOW(fd,4),RFIFOW(fd,6),RFIFOW(fd,8), 1);
  8619. sd->menuskill_lv = sd->menuskill_id = 0;
  8620. }
  8621. /*==========================================
  8622. * 武器修理
  8623. *------------------------------------------
  8624. */
  8625. void clif_parse_RepairItem(int fd, struct map_session_data *sd)
  8626. {
  8627. RFIFOHEAD(fd);
  8628. if (sd->menuskill_id != BS_REPAIRWEAPON)
  8629. return;
  8630. if (clif_trading(sd)) {
  8631. //Make it fail to avoid shop exploits where you sell something different than you see.
  8632. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8633. sd->menuskill_lv = sd->menuskill_id = 0;
  8634. return;
  8635. }
  8636. skill_repairweapon(sd,RFIFOW(fd,2));
  8637. sd->menuskill_lv = sd->menuskill_id = 0;
  8638. }
  8639. /*==========================================
  8640. *
  8641. *------------------------------------------
  8642. */
  8643. void clif_parse_WeaponRefine(int fd, struct map_session_data *sd) {
  8644. int idx;
  8645. RFIFOHEAD(fd);
  8646. if (sd->menuskill_id != WS_WEAPONREFINE) //Packet exploit?
  8647. return;
  8648. if (clif_trading(sd)) {
  8649. //Make it fail to avoid shop exploits where you sell something different than you see.
  8650. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8651. sd->menuskill_lv = sd->menuskill_id = 0;
  8652. return;
  8653. }
  8654. idx = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8655. skill_weaponrefine(sd, idx-2);
  8656. sd->menuskill_lv = sd->menuskill_id = 0;
  8657. }
  8658. /*==========================================
  8659. *
  8660. *------------------------------------------
  8661. */
  8662. void clif_parse_NpcSelectMenu(int fd,struct map_session_data *sd)
  8663. {
  8664. unsigned char select;
  8665. RFIFOHEAD(fd);
  8666. select = RFIFOB(fd,6);
  8667. if((select > sd->npc_menu && select != 0xff) || !select){
  8668. ShowWarning("Hack on NPC Select Menu: %s (AID: %d)!\n",sd->status.name,sd->bl.id);
  8669. clif_GM_kick(sd,sd,0);
  8670. } else {
  8671. sd->npc_menu=select;
  8672. npc_scriptcont(sd,RFIFOL(fd,2));
  8673. }
  8674. }
  8675. /*==========================================
  8676. *
  8677. *------------------------------------------
  8678. */
  8679. void clif_parse_NpcNextClicked(int fd,struct map_session_data *sd)
  8680. {
  8681. RFIFOHEAD(fd);
  8682. npc_scriptcont(sd,RFIFOL(fd,2));
  8683. }
  8684. /*==========================================
  8685. *
  8686. *------------------------------------------
  8687. */
  8688. void clif_parse_NpcAmountInput(int fd,struct map_session_data *sd)
  8689. {
  8690. RFIFOHEAD(fd);
  8691. sd->npc_amount=(int)RFIFOL(fd,6);
  8692. npc_scriptcont(sd,RFIFOL(fd,2));
  8693. }
  8694. /*==========================================
  8695. *
  8696. *------------------------------------------
  8697. */
  8698. void clif_parse_NpcStringInput(int fd,struct map_session_data *sd)
  8699. {
  8700. short message_len;
  8701. RFIFOHEAD(fd);
  8702. message_len = RFIFOW(fd,2)-7;
  8703. if(message_len < 1)
  8704. return; //Blank message?
  8705. if(message_len >= sizeof(sd->npc_str)){
  8706. ShowWarning("clif: input string too long !\n");
  8707. message_len = sizeof(sd->npc_str);
  8708. }
  8709. // Exploit prevention if crafted packets (without null) is being sent. [Lance]
  8710. memcpy(sd->npc_str,RFIFOP(fd,8),message_len);
  8711. sd->npc_str[message_len-1]=0;
  8712. npc_scriptcont(sd,RFIFOL(fd,4));
  8713. }
  8714. /*==========================================
  8715. *
  8716. *------------------------------------------
  8717. */
  8718. void clif_parse_NpcCloseClicked(int fd,struct map_session_data *sd)
  8719. {
  8720. RFIFOHEAD(fd);
  8721. if (sd->npc_id) //Avoid parsing anything when the script was done with. [Skotlex]
  8722. npc_scriptcont(sd,RFIFOL(fd,2));
  8723. }
  8724. /*==========================================
  8725. * アイテム鑑定
  8726. *------------------------------------------
  8727. */
  8728. void clif_parse_ItemIdentify(int fd,struct map_session_data *sd)
  8729. {
  8730. RFIFOHEAD(fd);
  8731. if (sd->menuskill_id != MC_IDENTIFY)
  8732. return;
  8733. skill_identify(sd,RFIFOW(fd,2)-2);
  8734. sd->menuskill_lv = sd->menuskill_id = 0;
  8735. }
  8736. /*==========================================
  8737. * 矢作成
  8738. *------------------------------------------
  8739. */
  8740. void clif_parse_SelectArrow(int fd,struct map_session_data *sd)
  8741. {
  8742. RFIFOHEAD(fd);
  8743. if (sd->menuskill_id != AC_MAKINGARROW)
  8744. return;
  8745. if (clif_trading(sd)) {
  8746. //Make it fail to avoid shop exploits where you sell something different than you see.
  8747. clif_skill_fail(sd,sd->ud.skillid,0,0);
  8748. sd->menuskill_lv = sd->menuskill_id = 0;
  8749. return;
  8750. }
  8751. skill_arrow_create(sd,RFIFOW(fd,2));
  8752. sd->menuskill_lv = sd->menuskill_id = 0;
  8753. }
  8754. /*==========================================
  8755. * オートスペル受信
  8756. *------------------------------------------
  8757. */
  8758. void clif_parse_AutoSpell(int fd,struct map_session_data *sd)
  8759. {
  8760. RFIFOHEAD(fd);
  8761. if (sd->menuskill_id != SA_AUTOSPELL)
  8762. return;
  8763. skill_autospell(sd,RFIFOW(fd,2));
  8764. sd->menuskill_lv = sd->menuskill_id = 0;
  8765. }
  8766. /*==========================================
  8767. * カード使用
  8768. *------------------------------------------
  8769. */
  8770. void clif_parse_UseCard(int fd,struct map_session_data *sd)
  8771. {
  8772. RFIFOHEAD(fd);
  8773. if (sd->state.trading!= 0)
  8774. return;
  8775. clif_use_card(sd,RFIFOW(fd,2)-2);
  8776. }
  8777. /*==========================================
  8778. * カード挿入装備選択
  8779. *------------------------------------------
  8780. */
  8781. void clif_parse_InsertCard(int fd,struct map_session_data *sd)
  8782. {
  8783. RFIFOHEAD(fd);
  8784. if (sd->state.trading!= 0)
  8785. return;
  8786. pc_insert_card(sd,RFIFOW(fd,2)-2,RFIFOW(fd,4)-2);
  8787. }
  8788. /*==========================================
  8789. * 0193 キャラID名前引き
  8790. *------------------------------------------
  8791. */
  8792. void clif_parse_SolveCharName(int fd, struct map_session_data *sd) {
  8793. int char_id;
  8794. RFIFOHEAD(fd);
  8795. char_id = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0]);
  8796. clif_solved_charname(sd, char_id);
  8797. }
  8798. /*==========================================
  8799. * 0197 /resetskill /resetstate
  8800. *------------------------------------------
  8801. */
  8802. void clif_parse_ResetChar(int fd, struct map_session_data *sd) {
  8803. RFIFOHEAD(fd);
  8804. if (battle_config.atc_gmonly && !pc_isGM(sd))
  8805. return;
  8806. if (pc_isGM(sd) < get_atcommand_level(AtCommand_ResetState))
  8807. return;
  8808. if (RFIFOW(fd,2))
  8809. pc_resetskill(sd,1);
  8810. else
  8811. pc_resetstate(sd);
  8812. if(log_config.gm && get_atcommand_level(AtCommand_ResetState >= log_config.gm))
  8813. log_atcommand(sd, RFIFOW(fd,2) ? "/resetskill" : "/resetstate");
  8814. }
  8815. /*==========================================
  8816. * 019c /lb等
  8817. *------------------------------------------
  8818. */
  8819. void clif_parse_LGMmessage(int fd, struct map_session_data *sd) {
  8820. unsigned char buf[CHAT_SIZE+4];
  8821. char *mes;
  8822. int len, lv;
  8823. RFIFOHEAD(fd);
  8824. if (battle_config.atc_gmonly && !pc_isGM(sd))
  8825. return;
  8826. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_LocalBroadcast)))
  8827. return;
  8828. len = RFIFOW(fd,2) - 4;
  8829. mes = RFIFOP(fd,4);
  8830. mes_len_check(mes, len, CHAT_SIZE);
  8831. WBUFW(buf,0) = 0x9a;
  8832. WBUFW(buf,2) = len+4;
  8833. memcpy(WBUFP(buf,4), mes, len);
  8834. clif_send(buf, WBUFW(buf,2), &sd->bl, ALL_SAMEMAP);
  8835. if(log_config.gm && lv >= log_config.gm) {
  8836. char message[CHAT_SIZE+5];
  8837. sprintf(message, "/lb %s", mes);
  8838. log_atcommand(sd, message);
  8839. }
  8840. }
  8841. /*==========================================
  8842. * カプラ倉庫へ入れる
  8843. *------------------------------------------
  8844. */
  8845. void clif_parse_MoveToKafra(int fd, struct map_session_data *sd) {
  8846. int item_index, item_amount;
  8847. RFIFOHEAD(fd);
  8848. if (clif_trading(sd))
  8849. return;
  8850. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-2;
  8851. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8852. if (item_index < 0 || item_index >= MAX_INVENTORY || item_amount < 1)
  8853. return;
  8854. if (sd->state.storage_flag == 1)
  8855. storage_storageadd(sd, item_index, item_amount);
  8856. else if (sd->state.storage_flag == 2)
  8857. storage_guild_storageadd(sd, item_index, item_amount);
  8858. }
  8859. /*==========================================
  8860. * カプラ倉庫から出す
  8861. *------------------------------------------
  8862. */
  8863. void clif_parse_MoveFromKafra(int fd,struct map_session_data *sd) {
  8864. int item_index, item_amount;
  8865. RFIFOHEAD(fd);
  8866. item_index = RFIFOW(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[0])-1;
  8867. item_amount = RFIFOL(fd,packet_db[sd->packet_ver][RFIFOW(fd,0)].pos[1]);
  8868. if (sd->state.storage_flag == 1)
  8869. storage_storageget(sd, item_index, item_amount);
  8870. else if(sd->state.storage_flag == 2)
  8871. storage_guild_storageget(sd, item_index, item_amount);
  8872. }
  8873. /*==========================================
  8874. * カプラ倉庫へカートから入れる
  8875. *------------------------------------------
  8876. */
  8877. void clif_parse_MoveToKafraFromCart(int fd, struct map_session_data *sd) {
  8878. RFIFOHEAD(fd);
  8879. if(sd->vender_id)
  8880. return;
  8881. if (sd->state.storage_flag == 1)
  8882. storage_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8883. else if (sd->state.storage_flag == 2)
  8884. storage_guild_storageaddfromcart(sd, RFIFOW(fd,2) - 2, RFIFOL(fd,4));
  8885. }
  8886. /*==========================================
  8887. * カプラ倉庫から出す
  8888. *------------------------------------------
  8889. */
  8890. void clif_parse_MoveFromKafraToCart(int fd, struct map_session_data *sd) {
  8891. RFIFOHEAD(fd);
  8892. if (sd->vender_id)
  8893. return;
  8894. if (sd->state.storage_flag == 1)
  8895. storage_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8896. else if (sd->state.storage_flag == 2)
  8897. storage_guild_storagegettocart(sd, RFIFOW(fd,2)-1, RFIFOL(fd,4));
  8898. }
  8899. /*==========================================
  8900. * カプラ倉庫を閉じる
  8901. *------------------------------------------
  8902. */
  8903. void clif_parse_CloseKafra(int fd, struct map_session_data *sd) {
  8904. if (sd->state.storage_flag == 1)
  8905. storage_storageclose(sd);
  8906. else if (sd->state.storage_flag == 2)
  8907. storage_guild_storageclose(sd);
  8908. }
  8909. /*==========================================
  8910. * Kafra storage protection password system
  8911. *------------------------------------------
  8912. */
  8913. void clif_parse_StoragePassword(int fd, struct map_session_data *sd) {
  8914. //TODO
  8915. }
  8916. /*==========================================
  8917. * パーティを作る
  8918. *------------------------------------------
  8919. */
  8920. void clif_parse_CreateParty(int fd, struct map_session_data *sd) {
  8921. RFIFOHEAD(fd);
  8922. if(map[sd->bl.m].flag.partylock)
  8923. { //Guild locked.
  8924. clif_displaymessage(fd, msg_txt(227));
  8925. return;
  8926. }
  8927. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7) {
  8928. party_create(sd,(char*)RFIFOP(fd,2),0,0);
  8929. } else
  8930. clif_skill_fail(sd,1,0,4);
  8931. }
  8932. /*==========================================
  8933. * パーティを作る
  8934. *------------------------------------------
  8935. */
  8936. void clif_parse_CreateParty2(int fd, struct map_session_data *sd) {
  8937. if(map[sd->bl.m].flag.partylock)
  8938. { //Guild locked.
  8939. clif_displaymessage(fd, msg_txt(227));
  8940. return;
  8941. }
  8942. if (battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 7){
  8943. RFIFOHEAD(fd);
  8944. party_create(sd,(char*)RFIFOP(fd,2),RFIFOB(fd,26),RFIFOB(fd,27));
  8945. } else
  8946. clif_skill_fail(sd,1,0,4);
  8947. }
  8948. /*==========================================
  8949. * パーティに勧誘
  8950. *------------------------------------------
  8951. */
  8952. void clif_parse_PartyInvite(int fd, struct map_session_data *sd) {
  8953. struct map_session_data *t_sd;
  8954. RFIFOHEAD(fd);
  8955. if(map[sd->bl.m].flag.partylock)
  8956. { //Guild locked.
  8957. clif_displaymessage(fd, msg_txt(227));
  8958. return;
  8959. }
  8960. t_sd = map_id2sd(RFIFOL(fd,2));
  8961. // @noask [LuzZza]
  8962. if(t_sd && t_sd->state.noask) {
  8963. clif_noask_sub(sd, t_sd, 1);
  8964. return;
  8965. }
  8966. party_invite(sd, t_sd);
  8967. }
  8968. /*==========================================
  8969. * パーティ勧誘返答
  8970. *------------------------------------------
  8971. */
  8972. void clif_parse_ReplyPartyInvite(int fd,struct map_session_data *sd) {
  8973. RFIFOHEAD(fd);
  8974. if(battle_config.basic_skill_check == 0 || pc_checkskill(sd,NV_BASIC) >= 5){
  8975. party_reply_invite(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  8976. } else {
  8977. party_reply_invite(sd,RFIFOL(fd,2),-1);
  8978. clif_skill_fail(sd,1,0,4);
  8979. }
  8980. }
  8981. /*==========================================
  8982. * パーティ脱退要求
  8983. *------------------------------------------
  8984. */
  8985. void clif_parse_LeaveParty(int fd, struct map_session_data *sd) {
  8986. if(map[sd->bl.m].flag.partylock)
  8987. { //Guild locked.
  8988. clif_displaymessage(fd, msg_txt(227));
  8989. return;
  8990. }
  8991. party_leave(sd);
  8992. }
  8993. /*==========================================
  8994. * パーティ除名要求
  8995. *------------------------------------------
  8996. */
  8997. void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd) {
  8998. RFIFOHEAD(fd);
  8999. if(map[sd->bl.m].flag.partylock)
  9000. { //Guild locked.
  9001. clif_displaymessage(fd, msg_txt(227));
  9002. return;
  9003. }
  9004. party_removemember(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6));
  9005. }
  9006. /*==========================================
  9007. * パーティ設定変更要求
  9008. *------------------------------------------
  9009. */
  9010. void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd) {
  9011. struct party_data *p;
  9012. RFIFOHEAD(fd);
  9013. if(!sd->status.party_id)
  9014. return;
  9015. p = party_search(sd->status.party_id);
  9016. if (!p) return;
  9017. //The client no longer can change the item-field, therefore it always
  9018. //comes as zero. Here, resend the item data as it is.
  9019. // party_changeoption(sd, RFIFOW(fd,2), RFIFOW(fd,4));
  9020. party_changeoption(sd, RFIFOW(fd,2), p->party.item);
  9021. }
  9022. /*==========================================
  9023. * パーティメッセージ送信要求
  9024. *------------------------------------------
  9025. */
  9026. void clif_parse_PartyMessage(int fd, struct map_session_data *sd) {
  9027. char *mes;
  9028. int len;
  9029. RFIFOHEAD(fd);
  9030. len = RFIFOW(fd,2) - 4;
  9031. mes = RFIFOP(fd,4);
  9032. mes_len_check(mes, len, CHAT_SIZE);
  9033. if (is_charcommand(fd, sd, mes) != CharCommand_None ||
  9034. is_atcommand(fd, sd, mes) != AtCommand_None)
  9035. return;
  9036. if (sd->sc.count && (
  9037. sd->sc.data[SC_BERSERK].timer!=-1 ||
  9038. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)
  9039. ))
  9040. return;
  9041. if (battle_config.min_chat_delay)
  9042. { //[Skotlex]
  9043. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9044. return;
  9045. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9046. }
  9047. party_send_message(sd, mes, len);
  9048. }
  9049. /*==========================================
  9050. * 露店閉鎖
  9051. *------------------------------------------
  9052. */
  9053. void clif_parse_CloseVending(int fd, struct map_session_data *sd) {
  9054. vending_closevending(sd);
  9055. }
  9056. /*==========================================
  9057. * 露店アイテムリスト要求
  9058. *------------------------------------------
  9059. */
  9060. void clif_parse_VendingListReq(int fd, struct map_session_data *sd) {
  9061. RFIFOHEAD(fd);
  9062. vending_vendinglistreq(sd,RFIFOL(fd,2));
  9063. if(sd->npc_id)
  9064. npc_event_dequeue(sd);
  9065. }
  9066. /*==========================================
  9067. * 露店アイテム購入
  9068. *------------------------------------------
  9069. */
  9070. void clif_parse_PurchaseReq(int fd, struct map_session_data *sd) {
  9071. RFIFOHEAD(fd);
  9072. vending_purchasereq(sd, RFIFOW(fd,2), RFIFOL(fd,4), RFIFOP(fd,8));
  9073. }
  9074. /*==========================================
  9075. * 露店開設
  9076. *------------------------------------------
  9077. */
  9078. void clif_parse_OpenVending(int fd,struct map_session_data *sd) {
  9079. RFIFOHEAD(fd);
  9080. if (clif_trading(sd))
  9081. return;
  9082. if (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOROOM)
  9083. return;
  9084. vending_openvending(sd, RFIFOW(fd,2), (char*)RFIFOP(fd,4), RFIFOB(fd,84), RFIFOP(fd,85));
  9085. }
  9086. /*==========================================
  9087. * ギルドを作る
  9088. *------------------------------------------
  9089. */
  9090. void clif_parse_CreateGuild(int fd,struct map_session_data *sd) {
  9091. RFIFOHEAD(fd);
  9092. if(map[sd->bl.m].flag.guildlock)
  9093. { //Guild locked.
  9094. clif_displaymessage(fd, msg_txt(228));
  9095. return;
  9096. }
  9097. guild_create(sd, (char*)RFIFOP(fd,6));
  9098. }
  9099. /*==========================================
  9100. * ギルドマスターかどうか確認
  9101. *------------------------------------------
  9102. */
  9103. void clif_parse_GuildCheckMaster(int fd, struct map_session_data *sd) {
  9104. clif_guild_masterormember(sd);
  9105. }
  9106. /*==========================================
  9107. * ギルド情報要求
  9108. *------------------------------------------
  9109. */
  9110. void clif_parse_GuildRequestInfo(int fd, struct map_session_data *sd) {
  9111. RFIFOHEAD(fd);
  9112. if (!sd->status.guild_id) return;
  9113. switch(RFIFOL(fd,2)){
  9114. case 0: // ギルド基本情報、同盟敵対情報
  9115. clif_guild_basicinfo(sd);
  9116. clif_guild_allianceinfo(sd);
  9117. break;
  9118. case 1: // メンバーリスト、役職名リスト
  9119. clif_guild_positionnamelist(sd);
  9120. clif_guild_memberlist(sd);
  9121. break;
  9122. case 2: // 役職名リスト、役職情報リスト
  9123. clif_guild_positionnamelist(sd);
  9124. clif_guild_positioninfolist(sd);
  9125. break;
  9126. case 3: // スキルリスト
  9127. clif_guild_skillinfo(sd);
  9128. break;
  9129. case 4: // 追放リスト
  9130. clif_guild_expulsionlist(sd);
  9131. break;
  9132. default:
  9133. if (battle_config.error_log)
  9134. ShowError("clif: guild request info: unknown type %d\n", RFIFOL(fd,2));
  9135. break;
  9136. }
  9137. }
  9138. /*==========================================
  9139. * ギルド役職変更
  9140. *------------------------------------------
  9141. */
  9142. void clif_parse_GuildChangePositionInfo(int fd, struct map_session_data *sd) {
  9143. int i;
  9144. RFIFOHEAD(fd);
  9145. if(!sd->state.gmaster_flag)
  9146. return;
  9147. for(i = 4; i < RFIFOW(fd,2); i += 40 ){
  9148. guild_change_position(sd->status.guild_id, RFIFOL(fd,i), RFIFOL(fd,i+4), RFIFOL(fd,i+12), (char*)RFIFOP(fd,i+16));
  9149. }
  9150. }
  9151. /*==========================================
  9152. * ギルドメンバ役職変更
  9153. *------------------------------------------
  9154. */
  9155. void clif_parse_GuildChangeMemberPosition(int fd, struct map_session_data *sd) {
  9156. int i;
  9157. RFIFOHEAD(fd);
  9158. if(!sd->state.gmaster_flag)
  9159. return;
  9160. for(i=4;i<RFIFOW(fd,2);i+=12){
  9161. guild_change_memberposition(sd->status.guild_id,
  9162. RFIFOL(fd,i),RFIFOL(fd,i+4),RFIFOL(fd,i+8));
  9163. }
  9164. }
  9165. /*==========================================
  9166. * ギルドエンブレム要求
  9167. *------------------------------------------
  9168. */
  9169. void clif_parse_GuildRequestEmblem(int fd,struct map_session_data *sd) {
  9170. struct guild *g;
  9171. RFIFOHEAD(fd);
  9172. g=guild_search(RFIFOL(fd,2));
  9173. if(g!=NULL)
  9174. clif_guild_emblem(sd,g);
  9175. }
  9176. /*==========================================
  9177. * ギルドエンブレム変更
  9178. *------------------------------------------
  9179. */
  9180. void clif_parse_GuildChangeEmblem(int fd,struct map_session_data *sd) {
  9181. RFIFOHEAD(fd);
  9182. if(!sd->state.gmaster_flag)
  9183. return;
  9184. guild_change_emblem(sd,RFIFOW(fd,2)-4,(char*)RFIFOP(fd,4));
  9185. }
  9186. /*==========================================
  9187. * ギルド告知変更
  9188. *------------------------------------------
  9189. */
  9190. void clif_parse_GuildChangeNotice(int fd,struct map_session_data *sd) {
  9191. RFIFOHEAD(fd);
  9192. if(!sd->state.gmaster_flag)
  9193. return;
  9194. // compensate for the client's double marker bug (in both strings)
  9195. if ((RFIFOB(fd, 6) == '|') && (RFIFOB(fd, 6+3) == '|')) {
  9196. memmove(RFIFOP(fd, 6+3), RFIFOP(fd, 6+6), 60-6); memset(RFIFOP(fd, 60-3), 0x00, 3); // drop the duplicate marker
  9197. }
  9198. if ((RFIFOB(fd, 66) == '|') && (RFIFOB(fd, 66+3) == '|')) {
  9199. memmove(RFIFOP(fd, 66+3), RFIFOP(fd, 66+6), 180-6); memset(RFIFOP(fd, 180-3), 0x00, 3); // drop the duplicate marker
  9200. }
  9201. // compensate for the client's adding of an extra space at the end of the message
  9202. if (RFIFOB(fd, 66) == '|') {
  9203. memset(RFIFOP(fd, 66 + strnlen(RFIFOP(fd, 66), 120)-1), 0x00, 1); // delete extra space at the end
  9204. }
  9205. guild_change_notice(sd,RFIFOL(fd,2),(char*)RFIFOP(fd,6),(char*)RFIFOP(fd,66));
  9206. }
  9207. /*==========================================
  9208. * ギルド勧誘
  9209. *------------------------------------------
  9210. */
  9211. void clif_parse_GuildInvite(int fd,struct map_session_data *sd) {
  9212. struct map_session_data *t_sd;
  9213. RFIFOHEAD(fd);
  9214. if(map[sd->bl.m].flag.guildlock)
  9215. { //Guild locked.
  9216. clif_displaymessage(fd, msg_txt(228));
  9217. return;
  9218. }
  9219. t_sd = map_id2sd(RFIFOL(fd,2));
  9220. // @noask [LuzZza]
  9221. if(t_sd && t_sd->state.noask) {
  9222. clif_noask_sub(sd, t_sd, 2);
  9223. return;
  9224. }
  9225. guild_invite(sd,t_sd);
  9226. }
  9227. /*==========================================
  9228. * ギルド勧誘返信
  9229. *------------------------------------------
  9230. */
  9231. void clif_parse_GuildReplyInvite(int fd,struct map_session_data *sd) {
  9232. RFIFOHEAD(fd);
  9233. guild_reply_invite(sd,RFIFOL(fd,2),RFIFOB(fd,6));
  9234. }
  9235. /*==========================================
  9236. * ギルド脱退
  9237. *------------------------------------------
  9238. */
  9239. void clif_parse_GuildLeave(int fd,struct map_session_data *sd) {
  9240. RFIFOHEAD(fd);
  9241. if(map[sd->bl.m].flag.guildlock)
  9242. { //Guild locked.
  9243. clif_displaymessage(fd, msg_txt(228));
  9244. return;
  9245. }
  9246. guild_leave(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9247. }
  9248. /*==========================================
  9249. * ギルド追放
  9250. *------------------------------------------
  9251. */
  9252. void clif_parse_GuildExpulsion(int fd,struct map_session_data *sd) {
  9253. RFIFOHEAD(fd);
  9254. if(map[sd->bl.m].flag.guildlock)
  9255. { //Guild locked.
  9256. clif_displaymessage(fd, msg_txt(228));
  9257. return;
  9258. }
  9259. guild_expulsion(sd,RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10),(char*)RFIFOP(fd,14));
  9260. }
  9261. /*==========================================
  9262. * ギルド会話
  9263. *------------------------------------------
  9264. */
  9265. void clif_parse_GuildMessage(int fd,struct map_session_data *sd) {
  9266. char *mes;
  9267. int len;
  9268. RFIFOHEAD(fd);
  9269. len = RFIFOW(fd,2) - 4;
  9270. mes = RFIFOP(fd,4);
  9271. mes_len_check(mes, len, CHAT_SIZE);
  9272. if (is_charcommand(fd, sd, mes) != CharCommand_None ||
  9273. is_atcommand(fd, sd, mes) != AtCommand_None)
  9274. return;
  9275. if (sd->sc.count && (
  9276. sd->sc.data[SC_BERSERK].timer!=-1 ||
  9277. (sd->sc.data[SC_NOCHAT].timer!=-1 && sd->sc.data[SC_NOCHAT].val1&MANNER_NOCHAT)
  9278. ))
  9279. return;
  9280. if (battle_config.min_chat_delay)
  9281. { //[Skotlex]
  9282. if (DIFF_TICK(sd->cantalk_tick, gettick()) > 0)
  9283. return;
  9284. sd->cantalk_tick = gettick() + battle_config.min_chat_delay;
  9285. }
  9286. guild_send_message(sd, mes, len);
  9287. }
  9288. /*==========================================
  9289. * ギルド同盟要求
  9290. *------------------------------------------
  9291. */
  9292. void clif_parse_GuildRequestAlliance(int fd, struct map_session_data *sd) {
  9293. struct map_session_data *t_sd;
  9294. RFIFOHEAD(fd);
  9295. if(!sd->state.gmaster_flag)
  9296. return;
  9297. if(map[sd->bl.m].flag.guildlock)
  9298. { //Guild locked.
  9299. clif_displaymessage(fd, msg_txt(228));
  9300. return;
  9301. }
  9302. t_sd = map_id2sd(RFIFOL(fd,2));
  9303. // @noask [LuzZza]
  9304. if(t_sd && t_sd->state.noask) {
  9305. clif_noask_sub(sd, t_sd, 3);
  9306. return;
  9307. }
  9308. guild_reqalliance(sd,t_sd);
  9309. }
  9310. /*==========================================
  9311. * ギルド同盟要求返信
  9312. *------------------------------------------
  9313. */
  9314. void clif_parse_GuildReplyAlliance(int fd, struct map_session_data *sd) {
  9315. RFIFOHEAD(fd);
  9316. guild_reply_reqalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9317. }
  9318. /*==========================================
  9319. * ギルド関係解消
  9320. *------------------------------------------
  9321. */
  9322. void clif_parse_GuildDelAlliance(int fd, struct map_session_data *sd) {
  9323. RFIFOHEAD(fd);
  9324. if(!sd->state.gmaster_flag)
  9325. return;
  9326. if(map[sd->bl.m].flag.guildlock)
  9327. { //Guild locked.
  9328. clif_displaymessage(fd, msg_txt(228));
  9329. return;
  9330. }
  9331. guild_delalliance(sd,RFIFOL(fd,2),RFIFOL(fd,6));
  9332. }
  9333. /*==========================================
  9334. * ギルド敵対
  9335. *------------------------------------------
  9336. */
  9337. void clif_parse_GuildOpposition(int fd, struct map_session_data *sd) {
  9338. struct map_session_data *t_sd;
  9339. RFIFOHEAD(fd);
  9340. if(!sd->state.gmaster_flag)
  9341. return;
  9342. if(map[sd->bl.m].flag.guildlock)
  9343. { //Guild locked.
  9344. clif_displaymessage(fd, msg_txt(228));
  9345. return;
  9346. }
  9347. t_sd = map_id2sd(RFIFOL(fd,2));
  9348. // @noask [LuzZza]
  9349. if(t_sd && t_sd->state.noask) {
  9350. clif_noask_sub(sd, t_sd, 4);
  9351. return;
  9352. }
  9353. guild_opposition(sd,t_sd);
  9354. }
  9355. /*==========================================
  9356. * ギルド解散
  9357. *------------------------------------------
  9358. */
  9359. void clif_parse_GuildBreak(int fd, struct map_session_data *sd) {
  9360. RFIFOHEAD(fd);
  9361. if(map[sd->bl.m].flag.guildlock)
  9362. { //Guild locked.
  9363. clif_displaymessage(fd, msg_txt(228));
  9364. return;
  9365. }
  9366. guild_break(sd,(char*)RFIFOP(fd,2));
  9367. }
  9368. // pet
  9369. void clif_parse_PetMenu(int fd, struct map_session_data *sd) {
  9370. RFIFOHEAD(fd);
  9371. pet_menu(sd,RFIFOB(fd,2));
  9372. }
  9373. void clif_parse_CatchPet(int fd, struct map_session_data *sd) {
  9374. RFIFOHEAD(fd);
  9375. pet_catch_process2(sd,RFIFOL(fd,2));
  9376. }
  9377. void clif_parse_SelectEgg(int fd, struct map_session_data *sd) {
  9378. RFIFOHEAD(fd);
  9379. if (sd->menuskill_id != SA_TAMINGMONSTER || sd->menuskill_lv != -1)
  9380. return;
  9381. pet_select_egg(sd,RFIFOW(fd,2)-2);
  9382. sd->menuskill_lv = sd->menuskill_id = 0;
  9383. }
  9384. void clif_parse_SendEmotion(int fd, struct map_session_data *sd) {
  9385. if(sd->pd) {
  9386. RFIFOHEAD(fd);
  9387. clif_pet_emotion(sd->pd,RFIFOL(fd,2));
  9388. }
  9389. }
  9390. void clif_parse_ChangePetName(int fd, struct map_session_data *sd) {
  9391. RFIFOHEAD(fd);
  9392. pet_change_name(sd,(char*)RFIFOP(fd,2));
  9393. }
  9394. // Kick (right click menu for GM "(name) force to quit")
  9395. void clif_parse_GMKick(int fd, struct map_session_data *sd) {
  9396. struct block_list *target;
  9397. int tid,lv;
  9398. RFIFOHEAD(fd);
  9399. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9400. return;
  9401. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_Kick)))
  9402. return;
  9403. tid = RFIFOL(fd,2);
  9404. target = map_id2bl(tid);
  9405. if (!target) {
  9406. clif_GM_kickack(sd, 0);
  9407. return;
  9408. }
  9409. switch (target->type) {
  9410. case BL_PC:
  9411. {
  9412. struct map_session_data *tsd = (struct map_session_data *)target;
  9413. if (pc_isGM(sd) <= pc_isGM(tsd)) {
  9414. clif_GM_kickack(sd, 0);
  9415. return;
  9416. }
  9417. clif_GM_kick(sd, tsd, 1);
  9418. if(log_config.gm && lv >= log_config.gm) {
  9419. char message[NAME_LENGTH+6];
  9420. sprintf(message, "/kick %d", tsd->status.char_id);
  9421. log_atcommand(sd, message);
  9422. }
  9423. break;
  9424. }
  9425. case BL_MOB:
  9426. status_percent_damage(&sd->bl, target, 100, 0);
  9427. if(log_config.gm && lv >= log_config.gm) {
  9428. char message[NAME_LENGTH+16];
  9429. sprintf(message, "/kick %s (%d)", status_get_name(target), status_get_class(target));
  9430. log_atcommand(sd, message);
  9431. }
  9432. break;
  9433. default:
  9434. clif_GM_kickack(sd, 0);
  9435. }
  9436. }
  9437. /*==========================================
  9438. * /shift
  9439. *------------------------------------------
  9440. */
  9441. void clif_parse_Shift(int fd, struct map_session_data *sd) { // Rewriten by [Yor]
  9442. char *player_name;
  9443. int lv;
  9444. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9445. return;
  9446. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_JumpTo)))
  9447. return;
  9448. RFIFOHEAD(fd);
  9449. player_name = RFIFOP(fd,2);
  9450. player_name[NAME_LENGTH-1] = '\0';
  9451. atcommand_jumpto(fd, sd, "@jumpto", player_name); // as @jumpto
  9452. if(log_config.gm && lv >= log_config.gm) {
  9453. char message[NAME_LENGTH+7];
  9454. sprintf(message, "/shift %s", player_name);
  9455. log_atcommand(sd, message);
  9456. }
  9457. return;
  9458. }
  9459. /*==========================================
  9460. * /recall
  9461. *------------------------------------------
  9462. */
  9463. void clif_parse_Recall(int fd, struct map_session_data *sd) { // Added by RoVeRT
  9464. char *player_name;
  9465. int lv;
  9466. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9467. return;
  9468. if (pc_isGM(sd) < (lv=get_atcommand_level(AtCommand_Recall)))
  9469. return;
  9470. RFIFOHEAD(fd);
  9471. player_name = RFIFOP(fd,2);
  9472. player_name[NAME_LENGTH-1] = '\0';
  9473. atcommand_recall(fd, sd, "@recall", player_name); // as @recall
  9474. if(log_config.gm && lv >= log_config.gm) {
  9475. char message[NAME_LENGTH+8];
  9476. sprintf(message, "/recall %s", player_name);
  9477. log_atcommand(sd, message);
  9478. }
  9479. return;
  9480. }
  9481. /*==========================================
  9482. * /monster /item
  9483. *------------------------------------------
  9484. */
  9485. void clif_parse_GM_Monster_Item(int fd, struct map_session_data *sd) {
  9486. char *monster_item_name;
  9487. char message[NAME_LENGTH+10]; //For logging.
  9488. int level;
  9489. RFIFOHEAD(fd);
  9490. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9491. return;
  9492. monster_item_name = RFIFOP(fd,2);
  9493. monster_item_name[NAME_LENGTH-1] = '\0';
  9494. if (mobdb_searchname(monster_item_name)) {
  9495. if (pc_isGM(sd) < (level=get_atcommand_level(AtCommand_Spawn)))
  9496. return;
  9497. atcommand_monster(fd, sd, "@spawn", monster_item_name); // as @spawn
  9498. if(log_config.gm && level >= log_config.gm)
  9499. { //Log action. [Skotlex]
  9500. snprintf(message, sizeof(message)-1, "@spawn %s", monster_item_name);
  9501. log_atcommand(sd, message);
  9502. }
  9503. return;
  9504. }
  9505. if (itemdb_searchname(monster_item_name) == NULL)
  9506. return;
  9507. if (pc_isGM(sd) < (level = get_atcommand_level(AtCommand_Item)))
  9508. return;
  9509. atcommand_item(fd, sd, "@item", monster_item_name); // as @item
  9510. if(log_config.gm && level >= log_config.gm)
  9511. { //Log action. [Skotlex]
  9512. sprintf(message, "@item %s", monster_item_name);
  9513. log_atcommand(sd, message);
  9514. }
  9515. }
  9516. void clif_parse_GMHide(int fd, struct map_session_data *sd) { // Modified by [Yor]
  9517. if (battle_config.atc_gmonly && !pc_isGM(sd))
  9518. return;
  9519. if (pc_isGM(sd) < get_atcommand_level(AtCommand_Hide))
  9520. return;
  9521. if (sd->sc.option & OPTION_INVISIBLE) {
  9522. sd->sc.option &= ~OPTION_INVISIBLE;
  9523. if (sd->disguise)
  9524. status_set_viewdata(&sd->bl, sd->disguise);
  9525. else
  9526. status_set_viewdata(&sd->bl, sd->status.class_);
  9527. clif_displaymessage(fd, "Invisible: Off.");
  9528. } else {
  9529. sd->sc.option |= OPTION_INVISIBLE;
  9530. sd->vd.class_ = INVISIBLE_CLASS;
  9531. clif_displaymessage(fd, "Invisible: On.");
  9532. if(log_config.gm && get_atcommand_level(AtCommand_Hide) >= log_config.gm)
  9533. log_atcommand(sd, "/hide");
  9534. }
  9535. clif_changeoption(&sd->bl);
  9536. }
  9537. /*==========================================
  9538. * GMによるチャット禁止時間付与
  9539. *------------------------------------------
  9540. */
  9541. void clif_parse_GMReqNoChat(int fd,struct map_session_data *sd)
  9542. {
  9543. int type, limit, level;
  9544. struct block_list *bl;
  9545. struct map_session_data *dstsd;
  9546. RFIFOHEAD(fd);
  9547. bl = map_id2bl(RFIFOL(fd,2));
  9548. if (!bl || bl->type != BL_PC)
  9549. return;
  9550. dstsd =(struct map_session_data *)bl;
  9551. type = RFIFOB(fd,6);
  9552. limit = RFIFOW(fd,7);
  9553. if (type == 0)
  9554. limit = 0 - limit;
  9555. //If type is 2 and the ids don't match, this is a crafted hacked packet!
  9556. //Disabled because clients keep self-muting when you give players public @ commands... [Skotlex]
  9557. if (type == 2/* && sd->bl.id != dstsd->bl.id*/)
  9558. return;
  9559. if (
  9560. ((level = pc_isGM(sd)) > pc_isGM(dstsd) && level >= get_atcommand_level(AtCommand_Mute))
  9561. || (type == 2 && !level)) {
  9562. clif_GM_silence(sd, dstsd, ((type == 2) ? 1 : type));
  9563. dstsd->status.manner -= limit;
  9564. if(dstsd->status.manner < 0)
  9565. sc_start(bl,SC_NOCHAT,100,0,0);
  9566. else
  9567. {
  9568. dstsd->status.manner = 0;
  9569. status_change_end(bl,SC_NOCHAT,-1);
  9570. }
  9571. }
  9572. return;
  9573. }
  9574. /*==========================================
  9575. * GMによるチャット禁止時間参照(?)
  9576. *------------------------------------------
  9577. */
  9578. void clif_parse_GMReqNoChatCount(int fd, struct map_session_data *sd)
  9579. {
  9580. int tid;
  9581. RFIFOHEAD(fd);
  9582. tid = RFIFOL(fd,2);
  9583. WFIFOHEAD(fd,packet_len(0x1e0));
  9584. WFIFOW(fd,0) = 0x1e0;
  9585. WFIFOL(fd,2) = tid;
  9586. sprintf((char*)WFIFOP(fd,6),"%d",tid);
  9587. // memcpy(WFIFOP(fd,6), "TESTNAME", 24);
  9588. WFIFOSET(fd, packet_len(0x1e0));
  9589. return;
  9590. }
  9591. static int pstrcmp(const void *a, const void *b)
  9592. {
  9593. char *name1 = (char *)a;
  9594. char *name2 = (char *)b;
  9595. if (name1[0] && name2[0])
  9596. return strcmp(name1, name2);
  9597. //Since names are sorted in ascending order, send blank entries to the bottom.
  9598. if (name1[0])
  9599. return -1;
  9600. if (name2[0])
  9601. return 1;
  9602. return 0;
  9603. }
  9604. void clif_parse_PMIgnore(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9605. char output[512];
  9606. char *nick; // S 00cf <nick>.24B <type>.B: 00 (/ex nick) deny speech from nick, 01 (/in nick) allow speech from nick
  9607. int i;
  9608. WFIFOHEAD(fd,packet_len(0xd1));
  9609. RFIFOHEAD(fd);
  9610. memset(output, '\0', sizeof(output));
  9611. nick = (char*)RFIFOP(fd,2); // speed up
  9612. nick[NAME_LENGTH-1] = '\0'; // to be sure that the player name have at maximum 23 characters
  9613. WFIFOW(fd,0) = 0x0d1; // R 00d1 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9614. WFIFOB(fd,2) = RFIFOB(fd,26);
  9615. // deny action (we add nick only if it's not already exist
  9616. if (RFIFOB(fd,26) == 0) { // Add block
  9617. for(i = 0; i < MAX_IGNORE_LIST &&
  9618. sd->ignore[i].name[0] != '\0' &&
  9619. strcmp(sd->ignore[i].name, nick) != 0
  9620. ; i++);
  9621. if (i == MAX_IGNORE_LIST) { //Full List
  9622. WFIFOB(fd,3) = 1; // fail
  9623. WFIFOSET(fd, packet_len(0x0d1));
  9624. if (strcmp(wisp_server_name, nick) == 0)
  9625. { // to found possible bot users who automaticaly ignore people.
  9626. 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);
  9627. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9628. }
  9629. return;
  9630. }
  9631. if(sd->ignore[i].name[0] != '\0')
  9632. { //Name already exists.
  9633. WFIFOB(fd,3) = 0; // Aegis reports success.
  9634. WFIFOSET(fd, packet_len(0x0d1));
  9635. if (strcmp(wisp_server_name, nick) == 0) { // to found possible bot users who automaticaly ignore people.
  9636. sprintf(output, "Character '%s' (account: %d) has tried AGAIN to block wisps from '%s' (wisp name of the server). Bot user?", sd->status.name, sd->status.account_id, wisp_server_name);
  9637. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9638. }
  9639. return;
  9640. }
  9641. //Insert in position i
  9642. memcpy(sd->ignore[i].name, nick, NAME_LENGTH-1);
  9643. WFIFOB(fd,3) = 0; // success
  9644. WFIFOSET(fd, packet_len(0x0d1));
  9645. if (strcmp(wisp_server_name, nick) == 0)
  9646. { // to found possible bot users who automaticaly ignore people.
  9647. 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);
  9648. intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, output);
  9649. // send something to be inform and force bot to ignore twice... If GM receiving block + block again, it's a bot :)
  9650. clif_wis_message(fd, wisp_server_name,
  9651. "Adding me in your ignore list will not block my wisps.",
  9652. strlen("Adding me in your ignore list will not block my wisps.") + 1);
  9653. }
  9654. //Sort the ignore list.
  9655. qsort (sd->ignore[0].name, MAX_IGNORE_LIST, sizeof(sd->ignore[0].name), pstrcmp);
  9656. return;
  9657. }
  9658. //Remove name
  9659. for(i = 0; i < MAX_IGNORE_LIST &&
  9660. sd->ignore[i].name[0] != '\0' &&
  9661. strcmp(sd->ignore[i].name, nick) != 0
  9662. ; i++);
  9663. if (i == MAX_IGNORE_LIST || sd->ignore[i].name[i] == '\0')
  9664. { //Not found
  9665. WFIFOB(fd,3) = 1; // fail
  9666. WFIFOSET(fd, packet_len(0x0d1));
  9667. return;
  9668. }
  9669. //Move everything one place down to overwrite removed entry.
  9670. memmove(sd->ignore[i].name, sd->ignore[i+1].name,
  9671. (MAX_IGNORE_LIST-i-1)*sizeof(sd->ignore[0].name));
  9672. memset(sd->ignore[MAX_IGNORE_LIST-1].name, 0, sizeof(sd->ignore[0].name));
  9673. // success
  9674. WFIFOB(fd,3) = 0;
  9675. WFIFOSET(fd, packet_len(0x0d1));
  9676. // for debug only
  9677. // for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++) /
  9678. // ShowDebug("Ignored player: '%s'\n", sd->ignore[i].name);
  9679. return;
  9680. }
  9681. void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd) { // Rewritten by [Yor]
  9682. //printf("Ignore all: state: %d\n", RFIFOB(fd,2));
  9683. RFIFOHEAD(fd);
  9684. WFIFOHEAD(fd,packet_len(0xd2));
  9685. // R 00d2 <type>.B <fail>.B: type: 0: deny, 1: allow, fail: 0: success, 1: fail
  9686. // S 00d0 <type>len.B: 00 (/exall) deny all speech, 01 (/inall) allow all speech
  9687. WFIFOW(fd,0) = 0x0d2;
  9688. WFIFOB(fd,2) = RFIFOB(fd,2);
  9689. if (RFIFOB(fd,2) == 0) { //Deny all
  9690. if (sd->state.ignoreAll) {
  9691. WFIFOB(fd,3) = 1; // fail
  9692. WFIFOSET(fd, packet_len(0x0d2));
  9693. return;
  9694. }
  9695. sd->state.ignoreAll = 1;
  9696. WFIFOB(fd,3) = 0; // success
  9697. WFIFOSET(fd, packet_len(0x0d2));
  9698. return;
  9699. }
  9700. //Unblock everyone
  9701. if (!sd->state.ignoreAll) {
  9702. if (sd->ignore[0].name[0] != '\0')
  9703. { //Wipe the ignore list.
  9704. memset(sd->ignore, 0, sizeof(sd->ignore));
  9705. WFIFOB(fd,3) = 0;
  9706. WFIFOSET(fd, packet_len(0x0d2));
  9707. return;
  9708. }
  9709. WFIFOB(fd,3) = 1; // fail
  9710. WFIFOSET(fd, packet_len(0x0d2));
  9711. return;
  9712. }
  9713. sd->state.ignoreAll = 0;
  9714. WFIFOB(fd,3) = 0; // success
  9715. WFIFOSET(fd, packet_len(0x0d2));
  9716. return;
  9717. }
  9718. /*==========================================
  9719. * Wis拒否リスト
  9720. *------------------------------------------
  9721. */
  9722. void clif_parse_PMIgnoreList(int fd,struct map_session_data *sd)
  9723. {
  9724. int i;
  9725. WFIFOHEAD(fd, 4 + (NAME_LENGTH * MAX_IGNORE_LIST));
  9726. WFIFOW(fd,0) = 0xd4;
  9727. for(i = 0; i < MAX_IGNORE_LIST && sd->ignore[i].name[0] != '\0'; i++)
  9728. memcpy(WFIFOP(fd, 4 + i * NAME_LENGTH),sd->ignore[i].name, NAME_LENGTH);
  9729. WFIFOW(fd,2) = 4 + i * NAME_LENGTH;
  9730. WFIFOSET(fd, WFIFOW(fd,2));
  9731. return;
  9732. }
  9733. /*==========================================
  9734. * スパノビの/doridoriによるSPR2倍
  9735. *------------------------------------------
  9736. */
  9737. void clif_parse_NoviceDoriDori(int fd, struct map_session_data *sd) {
  9738. if (sd->state.doridori) return;
  9739. switch (sd->class_&MAPID_UPPERMASK)
  9740. {
  9741. case MAPID_SOUL_LINKER:
  9742. case MAPID_STAR_GLADIATOR:
  9743. case MAPID_TAEKWON:
  9744. if (!sd->state.rest)
  9745. break;
  9746. case MAPID_SUPER_NOVICE:
  9747. sd->state.doridori=1;
  9748. break;
  9749. }
  9750. return;
  9751. }
  9752. /*==========================================
  9753. * スパノビの爆裂波動
  9754. *------------------------------------------
  9755. */
  9756. void clif_parse_NoviceExplosionSpirits(int fd, struct map_session_data *sd)
  9757. {
  9758. if(sd){
  9759. int nextbaseexp=pc_nextbaseexp(sd);
  9760. if (battle_config.etc_log){
  9761. if(nextbaseexp != 0)
  9762. 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));
  9763. else
  9764. ShowInfo("SuperNovice explosionspirits!! %d %d %d 000\n",sd->bl.id,sd->status.class_,sd->status.base_exp);
  9765. }
  9766. 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){
  9767. clif_skill_nodamage(&sd->bl,&sd->bl,MO_EXPLOSIONSPIRITS,5,
  9768. sc_start(&sd->bl,SkillStatusChangeTable(MO_EXPLOSIONSPIRITS),100,
  9769. 5,skill_get_time(MO_EXPLOSIONSPIRITS,5)));
  9770. }
  9771. }
  9772. return;
  9773. }
  9774. // random notes:
  9775. // 0x214: monster/player info ?
  9776. /*==========================================
  9777. * Friends List
  9778. *------------------------------------------
  9779. */
  9780. void clif_friendslist_toggle(struct map_session_data *sd,int account_id, int char_id, int online)
  9781. { //Toggles a single friend online/offline [Skotlex]
  9782. int i, fd = sd->fd;
  9783. //Seek friend.
  9784. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id &&
  9785. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9786. if(i == MAX_FRIENDS || sd->status.friends[i].char_id == 0)
  9787. return; //Not found
  9788. WFIFOHEAD(fd,packet_len(0x206));
  9789. WFIFOW(fd, 0) = 0x206;
  9790. WFIFOL(fd, 2) = sd->status.friends[i].account_id;
  9791. WFIFOL(fd, 6) = sd->status.friends[i].char_id;
  9792. WFIFOB(fd,10) = !online; //Yeah, a 1 here means "logged off", go figure...
  9793. WFIFOSET(fd, packet_len(0x206));
  9794. }
  9795. //Subfunction called from clif_foreachclient to toggle friends on/off [Skotlex]
  9796. int clif_friendslist_toggle_sub(struct map_session_data *sd,va_list ap)
  9797. {
  9798. int account_id, char_id, online;
  9799. account_id = va_arg(ap, int);
  9800. char_id = va_arg(ap, int);
  9801. online = va_arg(ap, int);
  9802. clif_friendslist_toggle(sd, account_id, char_id, online);
  9803. return 0;
  9804. }
  9805. //For sending the whole friends list.
  9806. void clif_friendslist_send(struct map_session_data *sd) {
  9807. int i = 0, n, fd = sd->fd;
  9808. // Send friends list
  9809. WFIFOHEAD(fd, MAX_FRIENDS * 32 + 4);
  9810. WFIFOW(fd, 0) = 0x201;
  9811. for(i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id; i++)
  9812. {
  9813. WFIFOL(fd, 4 + 32 * i + 0) = sd->status.friends[i].account_id;
  9814. WFIFOL(fd, 4 + 32 * i + 4) = sd->status.friends[i].char_id;
  9815. memcpy(WFIFOP(fd, 4 + 32 * i + 8), &sd->status.friends[i].name, NAME_LENGTH);
  9816. }
  9817. if (i) {
  9818. WFIFOW(fd,2) = 4 + 32 * i;
  9819. WFIFOSET(fd, WFIFOW(fd,2));
  9820. }
  9821. for (n = 0; n < i; n++)
  9822. { //Sending the online players
  9823. if (map_charid2sd(sd->status.friends[n].char_id))
  9824. clif_friendslist_toggle(sd, sd->status.friends[n].account_id, sd->status.friends[n].char_id, 1);
  9825. }
  9826. }
  9827. /// Reply for add friend request: (success => type 0)
  9828. /// type=0 : MsgStringTable[821]="You have become friends with (%s)."
  9829. /// type=1 : MsgStringTable[822]="(%s) does not want to be friends with you."
  9830. /// type=2 : MsgStringTable[819]="Your Friend List is full."
  9831. /// type=3 : MsgStringTable[820]="(%s)'s Friend List is full."
  9832. void clif_friendslist_reqack(struct map_session_data *sd, struct map_session_data *f_sd, int type)
  9833. {
  9834. int fd;
  9835. nullpo_retv(sd);
  9836. fd = sd->fd;
  9837. WFIFOHEAD(fd,packet_len(0x209));
  9838. WFIFOW(fd,0) = 0x209;
  9839. WFIFOW(fd,2) = type;
  9840. if (f_sd)
  9841. {
  9842. WFIFOW(fd,4) = f_sd->status.account_id;
  9843. WFIFOW(fd,8) = f_sd->status.char_id;
  9844. memcpy(WFIFOP(fd, 12), f_sd->status.name,NAME_LENGTH);
  9845. }
  9846. WFIFOSET(fd, packet_len(0x209));
  9847. }
  9848. void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd) {
  9849. struct map_session_data *f_sd;
  9850. int i, f_fd;
  9851. RFIFOHEAD(fd);
  9852. f_sd = map_nick2sd((char*)RFIFOP(fd,2));
  9853. // Friend doesn't exist (no player with this name)
  9854. if (f_sd == NULL) {
  9855. clif_displaymessage(fd, msg_txt(3));
  9856. return;
  9857. }
  9858. // @noask [LuzZza]
  9859. if(f_sd->state.noask) {
  9860. clif_noask_sub(sd, f_sd, 5);
  9861. return;
  9862. }
  9863. // Friend already exists
  9864. for (i = 0; i < MAX_FRIENDS && sd->status.friends[i].char_id != 0; i++) {
  9865. if (sd->status.friends[i].char_id == f_sd->status.char_id) {
  9866. clif_displaymessage(fd, "Friend already exists.");
  9867. return;
  9868. }
  9869. }
  9870. if (i == MAX_FRIENDS) {
  9871. //No space, list full.
  9872. clif_friendslist_reqack(sd, f_sd, 2);
  9873. return;
  9874. }
  9875. f_fd = f_sd->fd;
  9876. WFIFOHEAD(f_fd,packet_len(0x207));
  9877. WFIFOW(f_fd,0) = 0x207;
  9878. WFIFOL(f_fd,2) = sd->status.account_id;
  9879. WFIFOL(f_fd,6) = sd->status.char_id;
  9880. memcpy(WFIFOP(f_fd,10), sd->status.name, NAME_LENGTH);
  9881. WFIFOSET(f_fd, packet_len(0x207));
  9882. return;
  9883. }
  9884. void clif_parse_FriendsListReply(int fd, struct map_session_data *sd) {
  9885. //<W: id> <L: Player 1 chara ID> <L: Player 1 AID> <B: Response>
  9886. struct map_session_data *f_sd;
  9887. int char_id, account_id;
  9888. char reply;
  9889. RFIFOHEAD(fd);
  9890. account_id = RFIFOL(fd,2);
  9891. char_id = RFIFOL(fd,6);
  9892. reply = RFIFOB(fd,10);
  9893. //printf ("reply: %d %d %d\n", char_id, id, reply);
  9894. f_sd = map_id2sd(account_id); //The account id is the same as the bl.id of players.
  9895. if (f_sd == NULL)
  9896. return;
  9897. if (reply == 0)
  9898. clif_friendslist_reqack(f_sd, sd, 1);
  9899. else {
  9900. int i;
  9901. // Find an empty slot
  9902. for (i = 0; i < MAX_FRIENDS; i++)
  9903. if (f_sd->status.friends[i].char_id == 0)
  9904. break;
  9905. if (i == MAX_FRIENDS) {
  9906. clif_friendslist_reqack(f_sd, sd, 2);
  9907. return;
  9908. }
  9909. f_sd->status.friends[i].account_id = sd->status.account_id;
  9910. f_sd->status.friends[i].char_id = sd->status.char_id;
  9911. memcpy(f_sd->status.friends[i].name, sd->status.name, NAME_LENGTH);
  9912. clif_friendslist_reqack(f_sd, sd, 0);
  9913. if (battle_config.friend_auto_add) {
  9914. // Also add f_sd to sd's friendlist.
  9915. for (i = 0; i < MAX_FRIENDS; i++) {
  9916. if (sd->status.friends[i].char_id == f_sd->status.char_id)
  9917. return; //No need to add anything.
  9918. if (sd->status.friends[i].char_id == 0)
  9919. break;
  9920. }
  9921. if (i == MAX_FRIENDS) {
  9922. clif_friendslist_reqack(sd, f_sd, 2);
  9923. return;
  9924. }
  9925. sd->status.friends[i].account_id = f_sd->status.account_id;
  9926. sd->status.friends[i].char_id = f_sd->status.char_id;
  9927. memcpy(sd->status.friends[i].name, f_sd->status.name, NAME_LENGTH);
  9928. clif_friendslist_reqack(sd, f_sd, 0);
  9929. }
  9930. }
  9931. return;
  9932. }
  9933. void clif_parse_FriendsListRemove(int fd, struct map_session_data *sd) {
  9934. // 0x203 </o> <ID to be removed W 4B>
  9935. int account_id, char_id;
  9936. int i, j;
  9937. RFIFOHEAD(fd);
  9938. account_id = RFIFOL(fd,2);
  9939. char_id = RFIFOL(fd,6);
  9940. // Search friend
  9941. for (i = 0; i < MAX_FRIENDS &&
  9942. (sd->status.friends[i].char_id != char_id || sd->status.friends[i].account_id != account_id); i++);
  9943. if (i == MAX_FRIENDS) {
  9944. clif_displaymessage(fd, "Name not found in list.");
  9945. return;
  9946. }
  9947. // move all chars down
  9948. for(j = i + 1; j < MAX_FRIENDS; j++)
  9949. memcpy(&sd->status.friends[j-1], &sd->status.friends[j], sizeof(sd->status.friends[0]));
  9950. memset(&sd->status.friends[MAX_FRIENDS-1], 0, sizeof(sd->status.friends[MAX_FRIENDS-1]));
  9951. clif_displaymessage(fd, "Friend removed");
  9952. WFIFOHEAD(fd,packet_len(0x20a));
  9953. WFIFOW(fd,0) = 0x20a;
  9954. WFIFOL(fd,2) = account_id;
  9955. WFIFOL(fd,6) = char_id;
  9956. WFIFOSET(fd, packet_len(0x20a));
  9957. // clif_friendslist_send(sd); //This is not needed anymore.
  9958. return;
  9959. }
  9960. /*==========================================
  9961. * /killall
  9962. *------------------------------------------
  9963. */
  9964. void clif_parse_GMKillAll(int fd,struct map_session_data *sd)
  9965. {
  9966. char message[50];
  9967. strncpy(message,sd->status.name, NAME_LENGTH);
  9968. is_atcommand(fd, sd, strcat(message," : @kickall"));
  9969. return;
  9970. }
  9971. /*==========================================
  9972. * /pvpinfo
  9973. *------------------------------------------
  9974. */
  9975. void clif_parse_PVPInfo(int fd,struct map_session_data *sd)
  9976. {
  9977. WFIFOHEAD(fd,packet_len(0x210));
  9978. WFIFOW(fd,0) = 0x210;
  9979. //WFIFOL(fd,2) = 0; // not sure what for yet
  9980. //WFIFOL(fd,6) = 0;
  9981. WFIFOL(fd,10) = sd->pvp_won; // times won
  9982. WFIFOL(fd,14) = sd->pvp_lost; // times lost
  9983. WFIFOL(fd,18) = sd->pvp_point;
  9984. WFIFOSET(fd, packet_len(0x210));
  9985. return;
  9986. }
  9987. /*==========================================
  9988. * /blacksmith
  9989. *------------------------------------------
  9990. */
  9991. void clif_parse_Blacksmith(int fd,struct map_session_data *sd)
  9992. {
  9993. int i;
  9994. char *name;
  9995. WFIFOHEAD(fd,packet_len(0x219));
  9996. WFIFOW(fd,0) = 0x219;
  9997. //Packet size limits this list to 10 elements. [Skotlex]
  9998. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  9999. if (smith_fame_list[i].id > 0) {
  10000. if (strcmp(smith_fame_list[i].name, "-") == 0 &&
  10001. (name = map_charid2nick(smith_fame_list[i].id)) != NULL)
  10002. {
  10003. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), name, NAME_LENGTH);
  10004. } else
  10005. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), smith_fame_list[i].name, NAME_LENGTH);
  10006. } else
  10007. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "None", 5);
  10008. WFIFOL(fd, 242 + i * 4) = smith_fame_list[i].fame;
  10009. }
  10010. for(;i < 10; i++) { //In case the MAX is less than 10.
  10011. strncpy((char *)(WFIFOP(fd, 2 + 24 * i)), "Unavailable", 12);
  10012. WFIFOL(fd, 242 + i * 4) = 0;
  10013. }
  10014. WFIFOSET(fd, packet_len(0x219));
  10015. }
  10016. int clif_fame_blacksmith(struct map_session_data *sd, int points)
  10017. {
  10018. int fd = sd->fd;
  10019. WFIFOHEAD(fd,packet_len(0x21b));
  10020. WFIFOW(fd,0) = 0x21b;
  10021. WFIFOL(fd,2) = points;
  10022. WFIFOL(fd,6) = sd->status.fame;
  10023. WFIFOSET(fd, packet_len(0x21b));
  10024. return 0;
  10025. }
  10026. /*==========================================
  10027. * /alchemist
  10028. *------------------------------------------
  10029. */
  10030. void clif_parse_Alchemist(int fd,struct map_session_data *sd)
  10031. {
  10032. int i;
  10033. char *name;
  10034. WFIFOHEAD(fd,packet_len(0x21a));
  10035. WFIFOW(fd,0) = 0x21a;
  10036. //Packet size limits this list to 10 elements. [Skotlex]
  10037. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10038. if (chemist_fame_list[i].id > 0) {
  10039. if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
  10040. (name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
  10041. {
  10042. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10043. } else
  10044. memcpy(WFIFOP(fd, 2 + 24 * i), chemist_fame_list[i].name, NAME_LENGTH);
  10045. } else
  10046. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10047. WFIFOL(fd, 242 + i * 4) = chemist_fame_list[i].fame;
  10048. }
  10049. for(;i < 10; i++) { //In case the MAX is less than 10.
  10050. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  10051. WFIFOL(fd, 242 + i * 4) = 0;
  10052. }
  10053. WFIFOSET(fd, packet_len(0x21a));
  10054. }
  10055. int clif_fame_alchemist(struct map_session_data *sd, int points)
  10056. {
  10057. int fd = sd->fd;
  10058. WFIFOHEAD(fd,packet_len(0x21c));
  10059. WFIFOW(fd,0) = 0x21c;
  10060. WFIFOL(fd,2) = points;
  10061. WFIFOL(fd,6) = sd->status.fame;
  10062. WFIFOSET(fd, packet_len(0x21c));
  10063. return 0;
  10064. }
  10065. /*==========================================
  10066. * /taekwon
  10067. *------------------------------------------
  10068. */
  10069. void clif_parse_Taekwon(int fd,struct map_session_data *sd)
  10070. {
  10071. int i;
  10072. char *name;
  10073. WFIFOHEAD(fd,packet_len(0x226));
  10074. WFIFOW(fd,0) = 0x226;
  10075. //Packet size limits this list to 10 elements. [Skotlex]
  10076. for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
  10077. if (taekwon_fame_list[i].id > 0) {
  10078. if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
  10079. (name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
  10080. {
  10081. memcpy(WFIFOP(fd, 2 + 24 * i), name, NAME_LENGTH);
  10082. } else
  10083. memcpy(WFIFOP(fd, 2 + 24 * i), taekwon_fame_list[i].name, NAME_LENGTH);
  10084. } else
  10085. memcpy(WFIFOP(fd, 2 + 24 * i), "None", NAME_LENGTH);
  10086. WFIFOL(fd, 242 + i * 4) = taekwon_fame_list[i].fame;
  10087. }
  10088. for(;i < 10; i++) { //In case the MAX is less than 10.
  10089. memcpy(WFIFOP(fd, 2 + 24 * i), "Unavailable", NAME_LENGTH);
  10090. WFIFOL(fd, 242 + i * 4) = 0;
  10091. }
  10092. WFIFOSET(fd, packet_len(0x226));
  10093. }
  10094. int clif_fame_taekwon(struct map_session_data *sd, int points)
  10095. {
  10096. int fd = sd->fd;
  10097. WFIFOHEAD(fd,packet_len(0x224));
  10098. WFIFOW(fd,0) = 0x224;
  10099. WFIFOL(fd,2) = points;
  10100. WFIFOL(fd,6) = sd->status.fame;
  10101. WFIFOSET(fd, packet_len(0x224));
  10102. return 0;
  10103. }
  10104. /*==========================================
  10105. * PK Ranking table?
  10106. *------------------------------------------
  10107. */
  10108. void clif_parse_RankingPk(int fd,struct map_session_data *sd)
  10109. {
  10110. int i;
  10111. WFIFOHEAD(fd,packet_len(0x238));
  10112. WFIFOW(fd,0) = 0x238;
  10113. for(i=0;i<10;i++){
  10114. memcpy(WFIFOP(fd,i*24+2), "Unknown", NAME_LENGTH);
  10115. WFIFOL(fd,i*4+242) = 0;
  10116. }
  10117. WFIFOSET(fd, packet_len(0x238));
  10118. return;
  10119. }
  10120. /*==========================================
  10121. * SG Feel save OK [Komurka]
  10122. *------------------------------------------
  10123. */
  10124. void clif_parse_FeelSaveOk(int fd,struct map_session_data *sd)
  10125. {
  10126. char feel_var[3][NAME_LENGTH] = {"PC_FEEL_SUN","PC_FEEL_MOON","PC_FEEL_STAR"};
  10127. int i;
  10128. if (sd->menuskill_id != SG_FEEL)
  10129. return;
  10130. i = sd->menuskill_lv-1;
  10131. if (i<0 || i > 2) return; //Bug?
  10132. sd->feel_map[i].index = map[sd->bl.m].index;
  10133. sd->feel_map[i].m = sd->bl.m;
  10134. pc_setglobalreg(sd,feel_var[i],map[sd->bl.m].index);
  10135. //Are these really needed? Shouldn't they show up automatically from the feel save packet?
  10136. // clif_misceffect2(&sd->bl, 0x1b0);
  10137. // clif_misceffect2(&sd->bl, 0x21f);
  10138. clif_feel_info(sd, i, 0);
  10139. sd->menuskill_lv = sd->menuskill_id = 0;
  10140. }
  10141. /*==========================================
  10142. * Question about Star Glaldiator save map [Komurka]
  10143. *------------------------------------------
  10144. */
  10145. void clif_parse_ReqFeel(int fd, struct map_session_data *sd, int skilllv) {
  10146. WFIFOHEAD(fd,packet_len(0x253));
  10147. WFIFOW(fd,0)=0x253;
  10148. WFIFOSET(fd, packet_len(0x253));
  10149. sd->menuskill_id=SG_FEEL;
  10150. sd->menuskill_lv=skilllv;
  10151. }
  10152. void clif_parse_AdoptRequest(int fd,struct map_session_data *sd) {
  10153. //TODO: add somewhere the adopt code, checks for exploits, etc, etc.
  10154. //Missing packets are the client's reply packets to the adopt request one.
  10155. //[Skotlex]
  10156. int account_id;
  10157. struct map_session_data *sd2;
  10158. RFIFOHEAD(fd);
  10159. account_id = RFIFOL(fd,2);
  10160. sd2 = map_id2sd(account_id);
  10161. if(sd2 && sd2->fd && sd2 != sd && sd2->status.party_id == sd->status.party_id) { //FIXME: No checks whatsoever are in place yet!
  10162. fd = sd2->fd;
  10163. WFIFOHEAD(fd,packet_len(0x1f9));
  10164. WFIFOW(fd,0)=0x1f9;
  10165. WFIFOSET(fd, packet_len(0x1f9));
  10166. }
  10167. }
  10168. /*==========================================
  10169. * Homunculus packets
  10170. *------------------------------------------
  10171. */
  10172. void clif_parse_ChangeHomunculusName(int fd, struct map_session_data *sd) {
  10173. RFIFOHEAD(fd);
  10174. merc_hom_change_name(sd,RFIFOP(fd,2));
  10175. }
  10176. void clif_parse_HomMoveToMaster(int fd, struct map_session_data *sd) { //[orn]
  10177. nullpo_retv(sd);
  10178. if(!merc_is_hom_active(sd->hd))
  10179. return;
  10180. unit_walktoxy(&sd->hd->bl, sd->bl.x,sd->bl.y-1, 4);
  10181. }
  10182. void clif_parse_HomMoveTo(int fd,struct map_session_data *sd) { //[orn]
  10183. int x,y,cmd;
  10184. RFIFOHEAD(fd);
  10185. nullpo_retv(sd);
  10186. if(!merc_is_hom_active(sd->hd))
  10187. return;
  10188. cmd = RFIFOW(fd,0);
  10189. x = RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]) * 4 +
  10190. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 1) >> 6);
  10191. y = ((RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]+1) & 0x3f) << 4) +
  10192. (RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0] + 2) >> 4);
  10193. unit_walktoxy(&(sd->hd->bl),x,y,4);
  10194. }
  10195. void clif_parse_HomAttack(int fd,struct map_session_data *sd) { //[orn]
  10196. RFIFOHEAD(fd);
  10197. if(!merc_is_hom_active(sd->hd))
  10198. return;
  10199. unit_attack(&sd->hd->bl,RFIFOL(fd,6),0) ;
  10200. }
  10201. void clif_parse_HomMenu(int fd, struct map_session_data *sd) { //[orn]
  10202. int cmd;
  10203. RFIFOHEAD(fd);
  10204. cmd = RFIFOW(fd,0);
  10205. if(!merc_is_hom_active(sd->hd))
  10206. return;
  10207. merc_menu(sd,RFIFOB(fd,packet_db[sd->packet_ver][cmd].pos[0]));
  10208. }
  10209. /*==========================================
  10210. * パケットデバッグ
  10211. *------------------------------------------
  10212. */
  10213. void clif_parse_debug(int fd,struct map_session_data *sd)
  10214. {
  10215. int i, cmd, len;
  10216. RFIFOHEAD(fd);
  10217. cmd = RFIFOW(fd,0);
  10218. len = sd?packet_db[sd->packet_ver][cmd].len:RFIFOREST(fd); //With no session, just read the remaining in the buffer.
  10219. ShowDebug("packet debug 0x%4X\n",cmd);
  10220. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10221. for(i=0;i<len;i++){
  10222. if((i&15)==0)
  10223. printf("\n%04X ",i);
  10224. printf("%02X ",RFIFOB(fd,i));
  10225. }
  10226. printf("\n");
  10227. }
  10228. /*==========================================
  10229. * クライアントからのパケット解析
  10230. * socket.cのdo_parsepacketから呼び出される
  10231. *------------------------------------------
  10232. */
  10233. int clif_parse(int fd) {
  10234. int packet_len = 0, cmd, packet_ver, err, dump = 0;
  10235. TBL_PC *sd;
  10236. RFIFOHEAD(fd);
  10237. sd = (TBL_PC *)session[fd]->session_data;
  10238. if (session[fd]->eof) {
  10239. if (sd) {
  10240. if (sd->state.autotrade) {
  10241. //Disassociate character from the socket connection.
  10242. session[fd]->session_data = NULL;
  10243. sd->fd = 0;
  10244. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off (using @autotrade).\n",
  10245. (pc_isGM(sd))?"GM ":"",sd->status.name);
  10246. } else
  10247. if (sd->state.auth) {
  10248. // Player logout display [Valaris]
  10249. ShowInfo("%sCharacter '"CL_WHITE"%s"CL_RESET"' logged off.\n",
  10250. (pc_isGM(sd))?"GM ":"",sd->status.name);
  10251. clif_quitsave(fd, sd);
  10252. } else {
  10253. ShowInfo("Player AID:%d/CID:%d (not authenticated) logged off.\n",
  10254. sd->bl.id, sd->status.char_id);
  10255. map_quit(sd);
  10256. }
  10257. } else {
  10258. unsigned char *ip = (unsigned char *) &session[fd]->client_addr.sin_addr;
  10259. ShowInfo("Closed connection from '"CL_WHITE"%d.%d.%d.%d"CL_RESET"'.\n", ip[0],ip[1],ip[2],ip[3]);
  10260. }
  10261. do_close(fd);
  10262. return 0;
  10263. }
  10264. if (RFIFOREST(fd) < 2)
  10265. return 0;
  10266. // printf("clif_parse: connection #%d, packet: 0x%x (with being read: %d bytes).\n", fd, RFIFOW(fd,0), RFIFOREST(fd));
  10267. cmd = RFIFOW(fd,0);
  10268. // get packet version before to parse
  10269. packet_ver = 0;
  10270. if (sd) {
  10271. packet_ver = sd->packet_ver;
  10272. if (packet_ver < 0 || packet_ver > MAX_PACKET_VER) { // This should never happen unless we have some corrupted memory issues :X [Skotlex]
  10273. ShowWarning("clif_parse: Disconnecting session #%d (AID:%d/CID:%d) for having invalid packet_ver=%d.", fd, sd->status.account_id, sd->status.char_id, packet_ver);
  10274. session[fd]->eof = 1;
  10275. return 0;
  10276. }
  10277. } else {
  10278. // check authentification packet to know packet version
  10279. packet_ver = clif_guess_PacketVer(fd, 0, &err);
  10280. if( err )
  10281. {// failed to identify packet version
  10282. ShowInfo("clif_parse: Disconnecting session #%d with unknown packet version%s.\n", fd, (
  10283. err == 1 ? "" :
  10284. err == 2 ? ", possibly for having an invalid account_id" :
  10285. err == 3 ? ", possibly for having an invalid char_id." :
  10286. /* Uncomment when checks are added in clif_guess_PacketVer. [FlavioJS]
  10287. err == 4 ? ", possibly for having an invalid login_id1." :
  10288. err == 5 ? ", possibly for having an invalid client_tick." :
  10289. */
  10290. err == 6 ? ", possibly for having an invalid sex." :
  10291. ". ERROR invalid error code"));
  10292. WFIFOHEAD(fd,packet_len(0x6a));
  10293. WFIFOW(fd,0) = 0x6a;
  10294. WFIFOB(fd,2) = 3; // Rejected from Server
  10295. WFIFOSET(fd,packet_len(0x6a));
  10296. RFIFOSKIP(fd, RFIFOREST(fd));
  10297. clif_setwaitclose(fd);
  10298. /*
  10299. //## TODO check if it still doesn't send and why. [FlavioJS]
  10300. if (session[fd]->func_send) //socket.c doesn't wants to send the data when left on it's own... [Skotlex]
  10301. session[fd]->func_send(fd);
  10302. */
  10303. return 0;
  10304. }
  10305. }
  10306. // ゲーム用以外パケットか、認証を終える前に0072以外が来たら、切断する
  10307. if (cmd >= MAX_PACKET_DB || packet_db[packet_ver][cmd].len == 0) { // if packet is not inside these values: session is incorrect?? or auth packet is unknown
  10308. ShowWarning("clif_parse: Received unsupported packet (packet 0x%04x, %d bytes received), disconnecting session #%d.\n", cmd, RFIFOREST(fd), fd);
  10309. session[fd]->eof = 1;
  10310. return 0;
  10311. }
  10312. // パケット長を計算
  10313. packet_len = packet_db[packet_ver][cmd].len;
  10314. if (packet_len == -1) {
  10315. if (RFIFOREST(fd) < 4)
  10316. return 0; // 可変長パケットで長さの所までデータが来てない
  10317. packet_len = RFIFOW(fd,2);
  10318. if (packet_len < 4 || packet_len > 32768) {
  10319. ShowWarning("clif_parse: Packet 0x%04x specifies invalid packet_len (%d), disconnecting session #%d.\n", cmd, packet_len, fd);
  10320. session[fd]->eof =1;
  10321. return 0;
  10322. }
  10323. }
  10324. if ((int)RFIFOREST(fd) < packet_len)
  10325. return 0; // まだ1パケット分データが揃ってない
  10326. #if DUMP_ALL_PACKETS
  10327. {
  10328. int i;
  10329. FILE *fp;
  10330. char packet_txt[256] = "save/packet.txt";
  10331. time_t now;
  10332. dump = 1;
  10333. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10334. ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
  10335. return 1;
  10336. } else {
  10337. time(&now);
  10338. if (sd && sd->state.auth) {
  10339. if (sd->status.name != NULL)
  10340. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent packet:\n",
  10341. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10342. else
  10343. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10344. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10345. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10346. fprintf(fp, "\tsession #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10347. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10348. for(i = 0; i < packet_len; i++) {
  10349. if ((i & 15) == 0)
  10350. fprintf(fp, "\n\t%04X ", i);
  10351. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10352. }
  10353. fprintf(fp, "\n\n");
  10354. fclose(fp);
  10355. }
  10356. }
  10357. #endif
  10358. if (sd && sd->state.waitingdisconnect == 1) {
  10359. // 切断待ちの場合パケットを処理しない
  10360. } else if (packet_db[packet_ver][cmd].func) {
  10361. if (sd && sd->bl.prev == NULL &&
  10362. packet_db[packet_ver][cmd].func != clif_parse_LoadEndAck)
  10363. ; //Only valid packet when player is not on a map is the finish-loading packet.
  10364. else
  10365. if (sd
  10366. || packet_db[packet_ver][cmd].func == clif_parse_WantToConnection
  10367. || packet_db[packet_ver][cmd].func == clif_parse_debug
  10368. ) //Only execute the function when there's an sd (except for debug/wanttoconnect packets)
  10369. packet_db[packet_ver][cmd].func(fd, sd);
  10370. }
  10371. #if DUMP_UNKNOWN_PACKET
  10372. else if (battle_config.error_log)
  10373. {
  10374. int i;
  10375. FILE *fp;
  10376. char packet_txt[256] = "save/packet.txt";
  10377. time_t now;
  10378. dump = 1;
  10379. if ((fp = fopen(packet_txt, "a")) == NULL) {
  10380. ShowError("clif.c: can't write [%s] !!! data is lost !!!\n", packet_txt);
  10381. return 1;
  10382. } else {
  10383. time(&now);
  10384. if (sd && sd->state.auth) {
  10385. fprintf(fp, "%sPlayer with account ID %d (character ID %d, player name %s) sent wrong packet:\n",
  10386. asctime(localtime(&now)), sd->status.account_id, sd->status.char_id, sd->status.name);
  10387. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10388. fprintf(fp, "%sPlayer with account ID %d sent wrong packet:\n", asctime(localtime(&now)), sd->bl.id);
  10389. fprintf(fp, "\t---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10390. for(i = 0; i < packet_len; i++) {
  10391. if ((i & 15) == 0)
  10392. fprintf(fp, "\n\t%04X ", i);
  10393. fprintf(fp, "%02X ", RFIFOB(fd,i));
  10394. }
  10395. fprintf(fp, "\n\n");
  10396. fclose(fp);
  10397. }
  10398. }
  10399. #endif
  10400. if (dump) {
  10401. int i;
  10402. ShowDebug("\nclif_parse: session #%d, packet 0x%04x, length %d, version %d\n", fd, cmd, packet_len, packet_ver);
  10403. printf("---- 00-01-02-03-04-05-06-07-08-09-0A-0B-0C-0D-0E-0F");
  10404. for(i = 0; i < packet_len; i++) {
  10405. if ((i & 15) == 0)
  10406. printf("\n%04X ",i);
  10407. printf("%02X ", RFIFOB(fd,i));
  10408. }
  10409. printf("\n");
  10410. if (sd && sd->state.auth) {
  10411. if (sd->status.name != NULL)
  10412. printf("\nAccount ID %d, character ID %d, player name %s.\n",
  10413. sd->status.account_id, sd->status.char_id, sd->status.name);
  10414. else
  10415. printf("\nAccount ID %d.\n", sd->bl.id);
  10416. } else if (sd) // not authentified! (refused by char-server or disconnect before to be authentified)
  10417. printf("\nAccount ID %d.\n", sd->bl.id);
  10418. }
  10419. RFIFOSKIP(fd, packet_len);
  10420. return 0;
  10421. }
  10422. /*==========================================
  10423. * パケットデータベース読み込み
  10424. *------------------------------------------
  10425. */
  10426. static int packetdb_readdb(void)
  10427. {
  10428. FILE *fp;
  10429. char line[1024];
  10430. int ln=0;
  10431. int cmd,i,j,k,packet_ver;
  10432. int max_cmd=-1;
  10433. int skip_ver = 0;
  10434. int warned = 0;
  10435. char *str[64],*p,*str2[64],*p2,w1[64],w2[64];
  10436. int packet_len_table[0x260] = {
  10437. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10441. //#0x0040
  10442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10444. 0, 0, 0, 0, 55, 17, 3, 37, 46, -1, 23, -1, 3,108, 3, 2,
  10445. #if PACKETVER < 2
  10446. 3, 28, 19, 11, 3, -1, 9, 5, 52, 51, 56, 58, 41, 2, 6, 6,
  10447. #else // 78-7b 亀島以降 lv99エフェクト用
  10448. 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
  10449. #endif
  10450. //#0x0080
  10451. 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 2, -1, -1, -1, 0, // 0x8b changed to 2 (was 23)
  10452. 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
  10453. 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
  10454. 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
  10455. //#0x00C0
  10456. 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 3, 2, 27, // 0xcd change to 3 (was 6)
  10457. 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
  10458. 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
  10459. 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
  10460. //#0x0100
  10461. 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
  10462. 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
  10463. 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
  10464. 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
  10465. //#0x0140
  10466. 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
  10467. 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
  10468. -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14,186,182,
  10469. 14, 30, 10, 3, -1, 6,106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
  10470. //#0x0180
  10471. 6, 3,106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
  10472. #if PACKETVER < 1
  10473. 90, 86, 24, 6, 30,102, 8, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10474. #else // 196 comodo以降 状態表示アイコン用
  10475. 90, 86, 24, 6, 30,102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
  10476. #endif
  10477. 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
  10478. 11, 7, -1, 67, 12, 18,114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
  10479. //#0x01C0, Set 0x1d5=-1
  10480. 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 3, 9, 9, 30, 6, 28,
  10481. 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
  10482. 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
  10483. -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
  10484. //#0x0200
  10485. 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 0, 0, -1, 32, 10, // 0x20c change to 0 (was 19)
  10486. 22, 0, 26, 26, 42, 6, 6, 2, 2,282,282,10, 10, -1, -1, 66,
  10487. 10, -1, -1, 8, 10, 2,282, 18, 18, 15, 58, 57, 64, 5, 71, 5,
  10488. 12, 26, 9, 11, -1, -1, 10, 2, 282, 11, 4, 36, -1,-1, 4, 2,
  10489. //#0x0240
  10490. -1, -1, -1, -1, -1, 3, 4, 8, -1, 3, 70, 4, 8,12, 4, 10,
  10491. 3, 32, -1, 3, 3, 5, 5, 8, 2, 3, -1, -1, 4,-1, 4, 0
  10492. };
  10493. struct {
  10494. void (*func)(int, struct map_session_data *);
  10495. char *name;
  10496. } clif_parse_func[]={
  10497. {clif_parse_WantToConnection,"wanttoconnection"},
  10498. {clif_parse_LoadEndAck,"loadendack"},
  10499. {clif_parse_TickSend,"ticksend"},
  10500. {clif_parse_WalkToXY,"walktoxy"},
  10501. {clif_parse_QuitGame,"quitgame"},
  10502. {clif_parse_GetCharNameRequest,"getcharnamerequest"},
  10503. {clif_parse_GlobalMessage,"globalmessage"},
  10504. {clif_parse_MapMove,"mapmove"},
  10505. {clif_parse_ChangeDir,"changedir"},
  10506. {clif_parse_Emotion,"emotion"},
  10507. {clif_parse_HowManyConnections,"howmanyconnections"},
  10508. {clif_parse_ActionRequest,"actionrequest"},
  10509. {clif_parse_Restart,"restart"},
  10510. {clif_parse_Wis,"wis"},
  10511. {clif_parse_GMmessage,"gmmessage"},
  10512. {clif_parse_TakeItem,"takeitem"},
  10513. {clif_parse_DropItem,"dropitem"},
  10514. {clif_parse_UseItem,"useitem"},
  10515. {clif_parse_EquipItem,"equipitem"},
  10516. {clif_parse_UnequipItem,"unequipitem"},
  10517. {clif_parse_NpcClicked,"npcclicked"},
  10518. {clif_parse_NpcBuySellSelected,"npcbuysellselected"},
  10519. {clif_parse_NpcBuyListSend,"npcbuylistsend"},
  10520. {clif_parse_NpcSellListSend,"npcselllistsend"},
  10521. {clif_parse_CreateChatRoom,"createchatroom"},
  10522. {clif_parse_ChatAddMember,"chataddmember"},
  10523. {clif_parse_ChatRoomStatusChange,"chatroomstatuschange"},
  10524. {clif_parse_ChangeChatOwner,"changechatowner"},
  10525. {clif_parse_KickFromChat,"kickfromchat"},
  10526. {clif_parse_ChatLeave,"chatleave"},
  10527. {clif_parse_TradeRequest,"traderequest"},
  10528. {clif_parse_TradeAck,"tradeack"},
  10529. {clif_parse_TradeAddItem,"tradeadditem"},
  10530. {clif_parse_TradeOk,"tradeok"},
  10531. {clif_parse_TradeCancel,"tradecancel"},
  10532. {clif_parse_TradeCommit,"tradecommit"},
  10533. {clif_parse_StopAttack,"stopattack"},
  10534. {clif_parse_PutItemToCart,"putitemtocart"},
  10535. {clif_parse_GetItemFromCart,"getitemfromcart"},
  10536. {clif_parse_RemoveOption,"removeoption"},
  10537. {clif_parse_ChangeCart,"changecart"},
  10538. {clif_parse_StatusUp,"statusup"},
  10539. {clif_parse_SkillUp,"skillup"},
  10540. {clif_parse_UseSkillToId,"useskilltoid"},
  10541. {clif_parse_UseSkillToPos,"useskilltopos"},
  10542. {clif_parse_UseSkillToPosMoreInfo,"useskilltoposinfo"},
  10543. {clif_parse_UseSkillMap,"useskillmap"},
  10544. {clif_parse_RequestMemo,"requestmemo"},
  10545. {clif_parse_ProduceMix,"producemix"},
  10546. {clif_parse_NpcSelectMenu,"npcselectmenu"},
  10547. {clif_parse_NpcNextClicked,"npcnextclicked"},
  10548. {clif_parse_NpcAmountInput,"npcamountinput"},
  10549. {clif_parse_NpcStringInput,"npcstringinput"},
  10550. {clif_parse_NpcCloseClicked,"npccloseclicked"},
  10551. {clif_parse_ItemIdentify,"itemidentify"},
  10552. {clif_parse_SelectArrow,"selectarrow"},
  10553. {clif_parse_AutoSpell,"autospell"},
  10554. {clif_parse_UseCard,"usecard"},
  10555. {clif_parse_InsertCard,"insertcard"},
  10556. {clif_parse_RepairItem,"repairitem"},
  10557. {clif_parse_WeaponRefine,"weaponrefine"},
  10558. {clif_parse_SolveCharName,"solvecharname"},
  10559. {clif_parse_ResetChar,"resetchar"},
  10560. {clif_parse_LGMmessage,"lgmmessage"},
  10561. {clif_parse_MoveToKafra,"movetokafra"},
  10562. {clif_parse_MoveFromKafra,"movefromkafra"},
  10563. {clif_parse_MoveToKafraFromCart,"movetokafrafromcart"},
  10564. {clif_parse_MoveFromKafraToCart,"movefromkafratocart"},
  10565. {clif_parse_CloseKafra,"closekafra"},
  10566. {clif_parse_CreateParty,"createparty"},
  10567. {clif_parse_CreateParty2,"createparty2"},
  10568. {clif_parse_PartyInvite,"partyinvite"},
  10569. {clif_parse_ReplyPartyInvite,"replypartyinvite"},
  10570. {clif_parse_LeaveParty,"leaveparty"},
  10571. {clif_parse_RemovePartyMember,"removepartymember"},
  10572. {clif_parse_PartyChangeOption,"partychangeoption"},
  10573. {clif_parse_PartyMessage,"partymessage"},
  10574. {clif_parse_CloseVending,"closevending"},
  10575. {clif_parse_VendingListReq,"vendinglistreq"},
  10576. {clif_parse_PurchaseReq,"purchasereq"},
  10577. {clif_parse_OpenVending,"openvending"},
  10578. {clif_parse_CreateGuild,"createguild"},
  10579. {clif_parse_GuildCheckMaster,"guildcheckmaster"},
  10580. {clif_parse_GuildRequestInfo,"guildrequestinfo"},
  10581. {clif_parse_GuildChangePositionInfo,"guildchangepositioninfo"},
  10582. {clif_parse_GuildChangeMemberPosition,"guildchangememberposition"},
  10583. {clif_parse_GuildRequestEmblem,"guildrequestemblem"},
  10584. {clif_parse_GuildChangeEmblem,"guildchangeemblem"},
  10585. {clif_parse_GuildChangeNotice,"guildchangenotice"},
  10586. {clif_parse_GuildInvite,"guildinvite"},
  10587. {clif_parse_GuildReplyInvite,"guildreplyinvite"},
  10588. {clif_parse_GuildLeave,"guildleave"},
  10589. {clif_parse_GuildExpulsion,"guildexplusion"},
  10590. {clif_parse_GuildMessage,"guildmessage"},
  10591. {clif_parse_GuildRequestAlliance,"guildrequestalliance"},
  10592. {clif_parse_GuildReplyAlliance,"guildreplyalliance"},
  10593. {clif_parse_GuildDelAlliance,"guilddelalliance"},
  10594. {clif_parse_GuildOpposition,"guildopposition"},
  10595. {clif_parse_GuildBreak,"guildbreak"},
  10596. {clif_parse_PetMenu,"petmenu"},
  10597. {clif_parse_CatchPet,"catchpet"},
  10598. {clif_parse_SelectEgg,"selectegg"},
  10599. {clif_parse_SendEmotion,"sendemotion"},
  10600. {clif_parse_ChangePetName,"changepetname"},
  10601. {clif_parse_GMKick,"gmkick"},
  10602. {clif_parse_GMHide,"gmhide"},
  10603. {clif_parse_GMReqNoChat,"gmreqnochat"},
  10604. {clif_parse_GMReqNoChatCount,"gmreqnochatcount"},
  10605. {clif_parse_NoviceDoriDori,"sndoridori"},
  10606. {clif_parse_NoviceExplosionSpirits,"snexplosionspirits"},
  10607. {clif_parse_PMIgnore,"wisexin"},
  10608. {clif_parse_PMIgnoreList,"wisexlist"},
  10609. {clif_parse_PMIgnoreAll,"wisall"},
  10610. {clif_parse_FriendsListAdd,"friendslistadd"},
  10611. {clif_parse_FriendsListRemove,"friendslistremove"},
  10612. {clif_parse_FriendsListReply,"friendslistreply"},
  10613. {clif_parse_GMKillAll,"killall"},
  10614. {clif_parse_Recall,"summon"},
  10615. {clif_parse_GM_Monster_Item,"itemmonster"},
  10616. {clif_parse_Shift,"shift"},
  10617. {clif_parse_Blacksmith,"blacksmith"},
  10618. {clif_parse_Alchemist,"alchemist"},
  10619. {clif_parse_Taekwon,"taekwon"},
  10620. {clif_parse_RankingPk,"rankingpk"},
  10621. {clif_parse_FeelSaveOk,"feelsaveok"},
  10622. {clif_parse_AdoptRequest,"adopt"},
  10623. {clif_parse_debug,"debug"},
  10624. //[blackhole89] //[orn]
  10625. {clif_parse_ChangeHomunculusName,"changehomunculusname"},
  10626. {clif_parse_HomMoveToMaster,"hommovetomaster"},
  10627. {clif_parse_HomMoveTo,"hommoveto"},
  10628. {clif_parse_HomAttack,"homattack"},
  10629. {clif_parse_HomMenu,"hommenu"},
  10630. {clif_parse_StoragePassword,"storagepassword"},
  10631. {NULL,NULL}
  10632. };
  10633. // Set server packet lengths - packet_db[SERVER]
  10634. memset(packet_db,0,sizeof(packet_db));
  10635. for( i = 0; i < 0x260; ++i )
  10636. packet_len(i) = packet_len_table[i];
  10637. sprintf(line, "%s/packet_db.txt", db_path);
  10638. if( (fp=fopen(line,"r"))==NULL ){
  10639. ShowFatalError("can't read %s\n", line);
  10640. exit(1);
  10641. }
  10642. clif_config.packet_db_ver = MAX_PACKET_VER;
  10643. packet_ver = MAX_PACKET_VER; // read into packet_db's version by default
  10644. while(fgets(line,1020,fp)){
  10645. if(line[0]=='/' && line[1]=='/')
  10646. continue;
  10647. if (sscanf(line,"%[^:]: %[^\r\n]",w1,w2) == 2) {
  10648. if(strcmpi(w1,"packet_ver")==0) {
  10649. int prev_ver = packet_ver;
  10650. skip_ver = 0;
  10651. packet_ver = atoi(w2);
  10652. if ( packet_ver > MAX_PACKET_VER )
  10653. { //Check to avoid overflowing. [Skotlex]
  10654. if( (warned&1) == 0 )
  10655. ShowWarning("The packet_db table only has support up to version %d.\n", MAX_PACKET_VER);
  10656. warned &= 1;
  10657. skip_ver = 1;
  10658. }
  10659. else if( packet_ver < 0 )
  10660. {
  10661. if( (warned&2) == 0 )
  10662. ShowWarning("Negative packet versions are not supported.\n");
  10663. warned &= 2;
  10664. skip_ver = 1;
  10665. }
  10666. else if( packet_ver == SERVER )
  10667. {
  10668. if( (warned&4) == 0 )
  10669. ShowWarning("Packet version %d is reserved for server use only.\n", SERVER);
  10670. warned &= 4;
  10671. skip_ver = 1;
  10672. }
  10673. if( skip_ver )
  10674. {
  10675. ShowWarning("Skipping packet version %d.\n", packet_ver);
  10676. packet_ver = prev_ver;
  10677. continue;
  10678. }
  10679. // copy from previous version into new version and continue
  10680. // - indicating all following packets should be read into the newer version
  10681. memcpy(&packet_db[packet_ver], &packet_db[prev_ver], sizeof(packet_db[0]));
  10682. continue;
  10683. } else if(strcmpi(w1,"packet_db_ver")==0) {
  10684. //This is the preferred version.
  10685. if(strcmpi(w2,"default")==0)
  10686. clif_config.packet_db_ver = MAX_PACKET_VER;
  10687. else {
  10688. // to manually set the packet DB version
  10689. clif_config.packet_db_ver = atoi(w2);
  10690. // check for invalid version
  10691. if (clif_config.packet_db_ver > MAX_PACKET_VER ||
  10692. clif_config.packet_db_ver < 0)
  10693. clif_config.packet_db_ver = MAX_PACKET_VER;
  10694. }
  10695. continue;
  10696. }
  10697. }
  10698. if( skip_ver != 0 )
  10699. continue; // Skipping current packet version
  10700. memset(str,0,sizeof(str));
  10701. for(j=0,p=line;j<4 && p;j++){
  10702. str[j]=p;
  10703. p=strchr(p,',');
  10704. if(p) *p++=0;
  10705. }
  10706. if(str[0]==NULL)
  10707. continue;
  10708. cmd=strtol(str[0],(char **)NULL,0);
  10709. if(max_cmd < cmd)
  10710. max_cmd = cmd;
  10711. if(cmd<=0 || cmd>=MAX_PACKET_DB)
  10712. continue;
  10713. if(str[1]==NULL){
  10714. ShowError("packet_db: packet len error\n");
  10715. continue;
  10716. }
  10717. k = atoi(str[1]);
  10718. packet_db[packet_ver][cmd].len = k;
  10719. if(str[2]==NULL){
  10720. packet_db[packet_ver][cmd].func = NULL;
  10721. ln++;
  10722. continue;
  10723. }
  10724. for(j=0;j<sizeof(clif_parse_func)/sizeof(clif_parse_func[0]);j++){
  10725. if(clif_parse_func[j].name != NULL &&
  10726. strcmp(str[2],clif_parse_func[j].name)==0)
  10727. {
  10728. if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func)
  10729. { //If we are updating a function, we need to zero up the previous one. [Skotlex]
  10730. for(i=0;i<MAX_PACKET_DB;i++){
  10731. if (packet_db[packet_ver][i].func == clif_parse_func[j].func)
  10732. {
  10733. memset(&packet_db[packet_ver][i], 0, sizeof(struct packet_db));
  10734. break;
  10735. }
  10736. }
  10737. }
  10738. packet_db[packet_ver][cmd].func = clif_parse_func[j].func;
  10739. break;
  10740. }
  10741. }
  10742. // set the identifying cmd for the packet_db version
  10743. if (strcmp(str[2],"wanttoconnection")==0)
  10744. clif_config.connect_cmd[packet_ver] = cmd;
  10745. if(str[3]==NULL){
  10746. ShowError("packet_db: packet error\n");
  10747. exit(1);
  10748. }
  10749. for(j=0,p2=str[3];p2;j++){
  10750. str2[j]=p2;
  10751. p2=strchr(p2,':');
  10752. if(p2) *p2++=0;
  10753. k = atoi(str2[j]);
  10754. // if (packet_db[packet_ver][cmd].pos[j] != k && clif_config.prefer_packet_db) // not used for now
  10755. packet_db[packet_ver][cmd].pos[j] = k;
  10756. }
  10757. ln++;
  10758. // if(packet_db[clif_config.packet_db_ver][cmd].len > 2 /* && packet_db[cmd].pos[0] == 0 */)
  10759. // printf("packet_db ver %d: %d 0x%x %d %s %p\n",packet_ver,ln,cmd,packet_db[packet_ver][cmd].len,str[2],packet_db[packet_ver][cmd].func);
  10760. }
  10761. fclose(fp);
  10762. if(max_cmd > MAX_PACKET_DB)
  10763. {
  10764. ShowWarning("Found packets up to 0x%X, ignored 0x%X and above.\n", max_cmd, MAX_PACKET_DB);
  10765. ShowWarning("Please increase MAX_PACKET_DB and recompile.\n");
  10766. }
  10767. if (!clif_config.connect_cmd[clif_config.packet_db_ver])
  10768. { //Locate the nearest version that we still support. [Skotlex]
  10769. for(j = clif_config.packet_db_ver; j >= 0 && !clif_config.connect_cmd[j]; j--);
  10770. clif_config.packet_db_ver = j?j:MAX_PACKET_VER;
  10771. }
  10772. 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);
  10773. return 0;
  10774. }
  10775. /*==========================================
  10776. *
  10777. *------------------------------------------
  10778. */
  10779. int do_init_clif(void) {
  10780. clif_config.packet_db_ver = -1; // the main packet version of the DB
  10781. memset(clif_config.connect_cmd, 0, sizeof(clif_config.connect_cmd)); //The default connect command will be determined after reading the packet_db [Skotlex]
  10782. memset(packet_db,0,sizeof(packet_db));
  10783. //Using the packet_db file is the only way to set up packets now [Skotlex]
  10784. packetdb_readdb();
  10785. set_defaultparse(clif_parse);
  10786. if (!make_listen_bind(bind_ip,map_port)) {
  10787. ShowFatalError("can't bind game port\n");
  10788. exit(1);
  10789. }
  10790. add_timer_func_list(clif_waitclose, "clif_waitclose");
  10791. add_timer_func_list(clif_clearchar_delay_sub, "clif_clearchar_delay_sub");
  10792. add_timer_func_list(clif_delayquit, "clif_delayquit");
  10793. return 0;
  10794. }