9
3

client.cpp 299 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "../common/debug.h"
  17. #include "../common/Log.h"
  18. #include <iostream>
  19. #include <iomanip>
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <math.h>
  24. #include <zlib.h>
  25. #include <assert.h>
  26. #include <algorithm>
  27. #include "Player.h"
  28. #include "Commands/Commands.h"
  29. #include "ClientPacketFunctions.h"
  30. #include "../common/ConfigReader.h"
  31. #include "Guilds/Guild.h"
  32. #include "Variables.h"
  33. #include "Rules/Rules.h"
  34. #include "Titles.h"
  35. #include "IRC/IRC.h"
  36. #include "Chat/Chat.h"
  37. #include "SpellProcess.h"
  38. #include "Zone/ChestTrap.h"
  39. //#include "Quests.h"
  40. #ifdef WIN32
  41. #include <WinSock2.h>
  42. #include <windows.h>
  43. #define snprintf _snprintf
  44. #define vsnprintf _vsnprintf
  45. #define strncasecmp _strnicmp
  46. #define strcasecmp _stricmp
  47. #else
  48. #include <sys/socket.h>
  49. #ifdef FREEBSD
  50. #include <sys/types.h>
  51. #endif
  52. #include <netinet/in.h>
  53. #include <arpa/inet.h>
  54. #include <unistd.h>
  55. #endif
  56. #if defined(__GNUC__)
  57. #define _snprintf snprintf
  58. #endif
  59. #include "client.h"
  60. #include "../common/emu_opcodes.h"
  61. #include "../common/packet_dump.h"
  62. #include "WorldDatabase.h"
  63. #include "races.h"
  64. #include "classes.h"
  65. #include "LoginServer.h"
  66. #include "World.h"
  67. #include "../common/EQ2_Common_Structs.h"
  68. #include "net.h"
  69. #include "../common/MiscFunctions.h"
  70. #include "Items/Items.h"
  71. #include "Skills.h"
  72. #include "LuaInterface.h"
  73. #include "Quests.h"
  74. #include "Collections/Collections.h"
  75. #include "Achievements/Achievements.h"
  76. #include "Traits/Traits.h"
  77. #include "Recipes/Recipe.h"
  78. #include "Tradeskills/Tradeskills.h"
  79. #include "AltAdvancement/AltAdvancement.h"
  80. #include "Bots/Bot.h"
  81. extern WorldDatabase database;
  82. extern const char* ZONE_NAME;
  83. extern LoginServer loginserver;
  84. extern sint32 numclients;
  85. extern NetConnection net;
  86. extern Commands commands;
  87. extern ClientList client_list;
  88. extern ZoneList zone_list;
  89. extern ZoneAuth zone_auth;
  90. extern MasterItemList master_item_list;
  91. extern MasterSkillList master_skill_list;
  92. extern MasterSpellList master_spell_list;
  93. extern MasterTraitList master_trait_list;
  94. extern MasterQuestList master_quest_list;
  95. extern MasterFactionList master_faction_list;
  96. extern MasterRecipeList master_recipe_list;
  97. extern volatile bool RunLoops;
  98. extern ConfigReader configReader;
  99. extern LuaInterface* lua_interface;
  100. extern World world;
  101. extern Variables variables;
  102. extern Classes classes;
  103. extern Races races;
  104. extern GuildList guild_list;
  105. extern MasterCollectionList master_collection_list;
  106. extern MasterAchievementList master_achievement_list;
  107. extern RuleManager rule_manager;
  108. extern IRC irc;
  109. extern Chat chat;
  110. extern MasterAAList master_aa_list;
  111. extern MasterAAList master_tree_nodes;
  112. extern ChestTrapList chest_trap_list;
  113. using namespace std;
  114. Client::Client(EQStream* ieqs) : pos_update(125), quest_pos_timer(2000), lua_debug_timer(30000), delayTimer(500), transmuteID(0) {
  115. eqs = ieqs;
  116. ip = eqs->GetrIP();
  117. port = ntohs(eqs->GetrPort());
  118. merchant_transaction = nullptr;
  119. SetMailTransaction(nullptr);
  120. timestamp_flag = 0;
  121. current_quest_id = 0;
  122. last_update_time = 0;
  123. quest_updates = false;
  124. //autobootup_timeout = new Timer(10000);
  125. //autobootup_timeout->Disable();
  126. CLE_keepalive_timer = new Timer(15000);
  127. connect = new Timer(1000);
  128. connect->Disable();
  129. zoneID = 0;
  130. account_name[0] = 0;
  131. character_id = 0;
  132. account_id = 0;
  133. pwaitingforbootup = 0;
  134. current_zone = 0;
  135. connected_to_zone = false;
  136. connected = false;
  137. camp_timer = 0;
  138. disconnect_timer = 0;
  139. client_zoning = false;
  140. player_pos_changed = false;
  141. ++numclients;
  142. if (world.GetServerStatisticValue(STAT_SERVER_MOST_CONNECTIONS) < numclients)
  143. world.UpdateServerStatistic(STAT_SERVER_MOST_CONNECTIONS, numclients, true);
  144. remove_from_list = false;
  145. new_client_login = false;
  146. UpdateWindowTitle(0);
  147. num_active_failures = 0;
  148. player = new Player();
  149. combine_spawn = 0;
  150. lua_debug = false;
  151. ready_for_spawns = false;
  152. ready_for_updates = false;
  153. lua_debug_timer.Disable();
  154. transport_spawn = 0;
  155. MBuyBack.SetName("Client::MBuyBack");
  156. MPendingQuestAccept.SetName("Client::MPendingQuestAccept");
  157. MDeletePlayer.SetName("Client::MDeletePlayer");
  158. MQuestPendingUpdates.SetName("Client::MQuestPendingUpdates");
  159. search_items = 0;
  160. version = 0;
  161. next_conversation_id = 0;
  162. pending_guild_invite.guild = 0;
  163. pending_guild_invite.invited_by = 0;
  164. m_recipeListSent = false;
  165. m_resurrect.SetName("Client::m_resurrect");
  166. current_rez.expire_timer = 0;
  167. current_rez.should_delete = true;
  168. pending_last_name = 0;
  169. should_target = false;
  170. initial_spawns_sent = false;
  171. MQuestTimers.SetName("Client::quest_timers");
  172. memset(&incoming_paperdoll, 0, sizeof(incoming_paperdoll));
  173. on_auto_mount = false;
  174. should_load_spells = true;
  175. spawnPlacementMode = ServerSpawnPlacementMode::DEFAULT;
  176. delayedLogin = false;
  177. delayedAccountID = 0;
  178. delayedAccessKey = 0;
  179. delayTimer.Disable();
  180. }
  181. Client::~Client() {
  182. if (current_zone && player) {
  183. if (player->GetGroupMemberInfo() && (player->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0)
  184. world.GetGroupManager()->RemoveGroupMember(player->GetGroupMemberInfo()->group_id, player);
  185. world.GetGroupManager()->ClearPendingInvite(player);
  186. }
  187. if (lua_interface)
  188. lua_interface->RemoveDebugClients(this);
  189. if (player)
  190. zone_list.RemoveClientFromMap(player->GetName(), this);
  191. //let the stream factory know were done with this stream
  192. if (eqs) {
  193. eqs->Close();
  194. try {
  195. eqs->ReleaseFromUse();
  196. }
  197. catch (...) {}
  198. }
  199. eqs = NULL;
  200. //safe_delete(autobootup_timeout);
  201. safe_delete(disconnect_timer);
  202. safe_delete(camp_timer);
  203. safe_delete(CLE_keepalive_timer);
  204. safe_delete(connect);
  205. --numclients;
  206. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  207. if (player && !player->GetPendingDeletion())
  208. safe_delete(player);
  209. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  210. safe_delete(search_items);
  211. safe_delete(current_rez.expire_timer);
  212. safe_delete(pending_last_name);
  213. safe_delete_array(incoming_paperdoll.image_bytes);
  214. UpdateWindowTitle(0);
  215. }
  216. void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
  217. if (eqs) {
  218. if (!eqs->CheckActive()) {
  219. client_list.Remove(this);
  220. eqs = 0;
  221. }
  222. }
  223. if (app && eqs && version > 0)
  224. eqs->EQ2QueuePacket(app, attemptedCombine);
  225. else {
  226. safe_delete(app);
  227. }
  228. }
  229. void Client::PopulateSkillMap() {
  230. EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
  231. if (app)
  232. QueuePacket(app);
  233. else {
  234. LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
  235. Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
  236. }
  237. }
  238. void Client::SendLoginInfo() {
  239. if (firstlogin) {
  240. LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
  241. world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
  242. LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
  243. PopulateSkillMap();
  244. // JA: Check client version and move player to valid zone if current client does not support last saved zone (loading SF client on DoV saved zone) IT CAN HAPPEN!
  245. LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
  246. }
  247. LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
  248. database.ToggleCharacterOnline(this, 1);
  249. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
  250. int32 count = database.LoadCharacterSkills(GetCharacterID(), player);
  251. if (count == 0) {
  252. LogWrite(CCLIENT__WARNING, 0, "Client", "No character skills found!");
  253. database.UpdateStartingSkills(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  254. database.LoadCharacterSkills(GetCharacterID(), player);
  255. }
  256. count = database.LoadCharacterTitles(GetCharacterID(), player);
  257. if (count == 0) {
  258. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
  259. LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
  260. database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
  261. }
  262. count = database.LoadCharacterLanguages(GetCharacterID(), player);
  263. if (count == 0)
  264. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
  265. count = database.LoadCharacterSpells(GetCharacterID(), player);
  266. if (count == 0) {
  267. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character spells found!");
  268. database.UpdateStartingSpells(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  269. database.LoadCharacterSpells(GetCharacterID(), player);
  270. }
  271. count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
  272. if (count == 0)
  273. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
  274. ClientPacketFunctions::SendLoginAccepted(this);
  275. //ClientPacketFunctions::SendAbilities ( this );
  276. ClientPacketFunctions::SendCommandNamePacket(this);
  277. ClientPacketFunctions::SendQuickBarInit(this);
  278. // we only need to send the MOTD if it is the first time the person is logging in.
  279. if (firstlogin) {
  280. ClientPacketFunctions::SendMOTD(this);
  281. ClientPacketFunctions::SendCharacterMacros(this);
  282. zone_list.CheckFriendList(this);
  283. }
  284. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  285. if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
  286. {
  287. LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
  288. database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  289. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  290. }
  291. database.LoadPlayerFactions(this);
  292. database.LoadCharacterQuests(this);
  293. database.LoadPlayerMail(this);
  294. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  295. SendQuestJournal(true);
  296. master_aa_list.DisplayAA(this, 0, 3);
  297. SendCollectionList();
  298. SendBiography();
  299. map<int32, Quest*>::iterator itr;
  300. Quest* quest = 0;
  301. for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
  302. quest = itr->second;
  303. if (quest->IsTracked()) {
  304. quest->SetTracked(false);
  305. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  306. quest->SetTracked(true);
  307. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  308. }
  309. }
  310. // SendAchievementsList();
  311. /*Guild* guild = player->GetGuild();
  312. if (guild) {
  313. guild->UpdateGuildMemberInfo(GetPlayer());
  314. if (firstlogin)
  315. guild->SendGuildMOTD(this);
  316. guild->SendGuildUpdate(this);
  317. guild->SendGuildMember(GetPlayer(), firstlogin);
  318. guild->SendGuildEventList(this);
  319. guild->SendGuildBankEventList(this);
  320. guild->SendAllGuildEvents(this);
  321. guild->SendGuildMemberList(this);
  322. }*/
  323. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
  324. EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
  325. if (outapp) {
  326. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  327. //DumpPacket(outapp);
  328. QueuePacket(outapp);
  329. }
  330. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
  331. ClientPacketFunctions::SendCommandList(this);
  332. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
  333. SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
  334. ClientPacketFunctions::SendInstanceList(this);
  335. SendZoneInfo();
  336. /*Spell* spell = 0;
  337. vector<QuickBarItem*>::iterator itr;
  338. for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
  339. if((*itr)->type == 1){
  340. spell = master_spell_list.GetSpell((*itr)->id);
  341. if(spell)
  342. QueuePacket(spell->serialize(this, false, 0x20));
  343. }
  344. }*/
  345. }
  346. void Client::SendPlayerDeathWindow()
  347. {
  348. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
  349. vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
  350. vector<RevivePoint*>::iterator itr;
  351. if (results && results->size() > 0)
  352. {
  353. PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
  354. if (packet)
  355. {
  356. packet->setArrayLengthByName("location_count", results->size());
  357. RevivePoint* point = 0;
  358. int32 i = 0;
  359. for (itr = results->begin(); itr != results->end(); itr++, i++)
  360. {
  361. point = *itr;
  362. if (point)
  363. {
  364. packet->setArrayDataByName("location_id", point->id, i);
  365. //zone_name = database.GetZoneName(point->zone_id);
  366. string zone_name = database.GetZoneDescription(point->zone_id);
  367. if (zone_name.length() > 0)
  368. packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
  369. packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
  370. packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
  371. }
  372. if (point->id == 0xFFFFFFFF)//tmp location
  373. safe_delete(point);
  374. }
  375. // done with the revive points so lets free up the pointer
  376. safe_delete(results);
  377. #if EQDEBUG >= 3
  378. LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
  379. packet->PrintPacket();
  380. #endif
  381. EQ2Packet* outapp = packet->serialize();
  382. QueuePacket(outapp);
  383. safe_delete(packet);
  384. }
  385. }
  386. }
  387. void Client::DisplayDeadWindow()
  388. {
  389. LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
  390. player->SetHP(0);
  391. player->SetPower(0);
  392. GetCurrentZone()->TriggerCharSheetTimer();
  393. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  394. if (packet)
  395. {
  396. packet->setDataByName("parameter1", 8);
  397. packet->setDataByName("value", 1);
  398. QueuePacket(packet->serialize());
  399. packet->setDataByName("parameter1", 16);
  400. QueuePacket(packet->serialize());
  401. safe_delete(packet);
  402. }
  403. packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  404. if (packet)
  405. {
  406. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  407. QueuePacket(packet->serialize());
  408. safe_delete(packet);
  409. }
  410. SendPlayerDeathWindow();
  411. }
  412. void Client::HandlePlayerRevive(int32 point_id)
  413. {
  414. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  415. if (packet)
  416. {
  417. packet->setDataByName("parameter1", 8);
  418. QueuePacket(packet->serialize());
  419. packet->setDataByName("parameter1", 16);
  420. QueuePacket(packet->serialize());
  421. safe_delete(packet);
  422. }
  423. SimpleMessage(CHANNEL_COLOR_REVIVE, "You regain consciousness!");
  424. packet = configReader.getStruct("WS_Resurrected", GetVersion());
  425. if (packet)
  426. {
  427. QueuePacket(packet->serialize());
  428. safe_delete(packet);
  429. }
  430. float x, y, z, heading;
  431. RevivePoint* revive_point = 0;
  432. if (point_id != 0xFFFFFFFF)
  433. revive_point = GetCurrentZone()->GetRevivePoint(point_id);
  434. string zone_desc;
  435. const char* location_name = "Unknown";
  436. //revive at zone safe coords
  437. if (!revive_point)
  438. {
  439. LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
  440. x = GetCurrentZone()->GetSafeX();
  441. y = GetCurrentZone()->GetSafeY();
  442. z = GetCurrentZone()->GetSafeZ();
  443. heading = GetCurrentZone()->GetSafeHeading();
  444. zone_desc = GetCurrentZone()->GetZoneDescription();
  445. location_name = "Zone Safe Point";
  446. Zone(GetCurrentZone()->GetZoneName(), false);
  447. }
  448. else
  449. {
  450. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
  451. x = revive_point->x;
  452. y = revive_point->y;
  453. z = revive_point->z;
  454. heading = revive_point->heading;
  455. zone_desc = database.GetZoneDescription(revive_point->zone_id);
  456. location_name = revive_point->location_name.c_str();
  457. Zone(GetCurrentZone()->GetZoneName(), false);
  458. }
  459. player->SetResurrecting(true);
  460. player->SetX(x);
  461. player->SetY(y);
  462. player->SetZ(z);
  463. player->SetHeading(heading);
  464. player->SetHP(player->GetTotalHP());
  465. player->SetPower(player->GetTotalPower());
  466. LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
  467. zone_desc.c_str(),
  468. player->GetX(),
  469. player->GetY(),
  470. player->GetZ(),
  471. player->GetHeading(),
  472. player->GetHP(),
  473. player->GetPower(),
  474. location_name);
  475. //player->ClearEverything();
  476. Save();
  477. if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
  478. {
  479. string* zone_name = database.GetZoneName(revive_point->zone_id);
  480. if (!zone_name || zone_name->length() == 0)
  481. {
  482. LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  483. x = GetCurrentZone()->GetSafeX();
  484. y = GetCurrentZone()->GetSafeY();
  485. z = GetCurrentZone()->GetSafeZ();
  486. heading = GetCurrentZone()->GetSafeHeading();
  487. location_name = "Zone Safe Point";
  488. }
  489. else
  490. {
  491. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  492. location_name = revive_point->location_name.c_str();
  493. player->ClearEverything();
  494. Zone(zone_name->c_str(), false);
  495. }
  496. safe_delete(zone_name);
  497. }
  498. zone_desc = GetCurrentZone()->GetZoneDescription();
  499. Message(CHANNEL_COLOR_REVIVE, "Reviving in %s at %s.", zone_desc.c_str(), location_name);
  500. player->SetSpawnType(4);
  501. packet = configReader.getStruct("WS_CancelMoveObjectMode", GetVersion());
  502. if (packet)
  503. {
  504. QueuePacket(packet->serialize());
  505. safe_delete(packet);
  506. }
  507. packet = configReader.getStruct("WS_TeleportWithinZone", GetVersion());
  508. if (packet)
  509. {
  510. packet->setDataByName("x", x);
  511. packet->setDataByName("y", y);
  512. packet->setDataByName("z", z);
  513. QueuePacket(packet->serialize());
  514. safe_delete(packet);
  515. }
  516. packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  517. if (packet)
  518. {
  519. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  520. packet->setDataByName("unknown2", 255);
  521. QueuePacket(packet->serialize());
  522. safe_delete(packet);
  523. }
  524. packet = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  525. if (packet)
  526. {
  527. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  528. QueuePacket(packet->serialize());
  529. safe_delete(packet);
  530. }
  531. GetCurrentZone()->RemoveSpawn(false, player, false);
  532. m_resurrect.writelock(__FUNCTION__, __LINE__);
  533. if (current_rez.active)
  534. current_rez.should_delete = true;
  535. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  536. }
  537. void Client::SendCharInfo() {
  538. EQ2Packet* app;
  539. player->SetEquippedItemAppearances();
  540. ClientPacketFunctions::SendCharacterData(this);
  541. SendCharPOVGhost();
  542. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  543. if (packet) {
  544. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  545. packet->setDataByName("size", .56);
  546. packet->setDataByName("unknown2", 255);
  547. EQ2Packet* app = packet->serialize();
  548. QueuePacket(app);
  549. safe_delete(packet);
  550. }
  551. //SendAchievementsList();
  552. ClientPacketFunctions::SendCharacterSheet(this);
  553. ClientPacketFunctions::SendTraitList(this);// moved from below
  554. //ClientPacketFunctions::SendAbilities(this);
  555. ClientPacketFunctions::SendSkillBook(this);
  556. if (!player->IsResurrecting()) {
  557. ClientPacketFunctions::SendUpdateSpellBook(this);
  558. }
  559. else {
  560. player->SetResurrecting(false);
  561. }
  562. ClientPacketFunctions::SendLoginCommandMessages(this);
  563. GetCurrentZone()->AddSpawn(player);
  564. //SendCollectionList();
  565. Guild* guild = player->GetGuild();
  566. if (guild)
  567. guild->GuildMemberLogin(this, firstlogin);
  568. app = player->item_list.serialize(GetPlayer(), GetVersion());
  569. if (app) {
  570. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  571. //DumpPacket(app);
  572. QueuePacket(app);
  573. }
  574. app = player->GetEquipmentList()->serialize(GetVersion());
  575. if (app) {
  576. QueuePacket(app);
  577. }
  578. vector<Item*>* items = player->item_list.GetItemsFromBagID(-3); // bank items
  579. if (items && items->size() > 0) {
  580. for (int32 i = 0; i < items->size(); i++) {
  581. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  582. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  583. //DumpPacket(outapp);
  584. QueuePacket(outapp);
  585. }
  586. }
  587. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  588. QueuePacket(app);
  589. safe_delete(items);
  590. items = player->item_list.GetItemsFromBagID(-4); //shared bank items
  591. if (items && items->size() > 0) {
  592. for (int32 i = 0; i < items->size(); i++)
  593. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  594. }
  595. safe_delete(items);
  596. SendTitleUpdate();
  597. GetPlayer()->ChangePrimaryWeapon();
  598. GetPlayer()->ChangeSecondaryWeapon();
  599. GetPlayer()->ChangeRangedWeapon();
  600. database.LoadBuyBacks(this);
  601. master_aa_list.DisplayAA(this, 0, 0);
  602. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  603. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  604. string zone_motd_send = "Zone MOTD: " + zone_motd;
  605. SimpleMessage(CHANNEL_COLOR_WHITE, zone_motd_send.c_str());
  606. }
  607. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  608. if (zone_script && lua_interface)
  609. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  610. this->client_zoning = false;
  611. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  612. GetCurrentZone()->AddDamagedSpawn(player);
  613. if (firstlogin && rule_manager.GetGlobalRule(R_World, IRCGlobalEnabled)->GetBool())
  614. Message(CHANNEL_BROADCAST, "This server has a global IRC channel, join the world channel %s to use", rule_manager.GetGlobalRule(R_World, IRCChan)->GetString());
  615. if (firstlogin)
  616. firstlogin = false;
  617. player->ClearProcs();
  618. items = player->GetEquippedItemList();
  619. if (items && items->size() > 0) {
  620. for (int32 i = 0; i < items->size(); i++) {
  621. Item* item = items->at(i);
  622. if (item && item->GetItemScript() && lua_interface)
  623. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  624. }
  625. }
  626. //Allow this player to change their last name if they meet the level requirement
  627. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  628. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  629. safe_delete(items);
  630. if (!player->Alive())
  631. DisplayDeadWindow();
  632. }
  633. void Client::SendZoneSpawns() {
  634. //Allows us to place spawns almost anywhere
  635. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  636. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  637. QueuePacket(app);
  638. ClientPacketFunctions::SendSkillSlotMappings(this);
  639. ClientPacketFunctions::SendGameWorldTime(this);
  640. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  641. }
  642. void Client::SendCharPOVGhost() {
  643. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  644. if (set_pov) {
  645. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  646. EQ2Packet* app_pov = set_pov->serialize();
  647. QueuePacket(app_pov);
  648. safe_delete(set_pov);
  649. }
  650. }
  651. void Client::SendZoneInfo() {
  652. ZoneServer* zone = GetCurrentZone();
  653. if (zone) {
  654. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  655. QueuePacket(packet);
  656. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  657. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  658. #if EQDEBUG >= 9
  659. fog_packet->PrintPacket();
  660. #endif
  661. if (fog_packet) {
  662. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  663. QueuePacket(fog_packet->serialize());
  664. safe_delete(fog_packet);
  665. }
  666. zone->SendFlightPathsPackets(this);
  667. }
  668. /*
  669. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0x00,0x00,0x00,0x00
  670. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  671. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF
  672. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  673. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  674. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  675. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  676. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  677. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  678. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  679. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  680. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  681. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  682. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  683. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  684. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  685. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  686. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  687. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  688. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  689. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  690. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  691. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  692. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  693. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  694. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  695. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  696. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  697. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  698. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  699. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  700. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  701. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  702. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  703. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  704. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00};
  705. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  706. QueuePacket(appA);
  707. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00
  708. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  709. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  710. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00
  711. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  712. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  713. QueuePacket(appB);
  714. */
  715. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  716. SendFriendList();
  717. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  718. SendIgnoreList();
  719. }
  720. void Client::SendDefaultGroupOptions() {
  721. /*
  722. 0 - loot method
  723. 1 - loot items rarity
  724. 2 - Auto split coin
  725. 4 - default yell method
  726. 6 - group autolock
  727. 7 - solo autolock
  728. */
  729. uchar blah7[] = { 0x01,0x01,0x01,0x01,0x00,0x00,0x00 };
  730. EQ2Packet* app7 = new EQ2Packet(OP_DefaultGroupOptionsMsg, blah7, sizeof(blah7));
  731. QueuePacket(app7);
  732. }
  733. bool Client::HandlePacket(EQApplicationPacket* app) {
  734. bool ret = true;
  735. #if EQDEBUG >= 9
  736. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  737. DumpPacket(app, true);
  738. #endif
  739. EmuOpcode opcode = app->GetOpcode();
  740. #if EQDEBUG >= 9
  741. const char* name = app->GetOpcodeName();
  742. if (name)
  743. cout << name;
  744. else
  745. cout << "Unknown";
  746. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  747. DumpPacket(app);
  748. #endif
  749. //if (opcode != OP_UpdatePositionMsg) {
  750. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  751. //}
  752. switch (opcode) {
  753. case OP_LoginByNumRequestMsg: {
  754. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  755. PacketStruct* request;
  756. request = configReader.getStruct("LoginByNumRequest", 1);
  757. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  758. // test the original location of Version for clients older than 1212
  759. version = request->getType_int16_ByName("version");
  760. if (version >= 1212 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  761. // must be new client data version method, re-fetch the packet
  762. safe_delete(request);
  763. request = configReader.getStruct("LoginByNumRequest", 1212);
  764. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  765. // Xinux suggests using an INT16 here. Our first new version = 57000
  766. version = request->getType_int16_ByName("version");
  767. }
  768. else {
  769. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  770. break;
  771. }
  772. }
  773. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  774. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  775. ClientPacketFunctions::SendLoginDenied(this);
  776. return false;
  777. }
  778. int32 account_id = request->getType_int32_ByName("account_id");
  779. int32 access_code = request->getType_int32_ByName("access_code");
  780. if (!HandleNewLogin(account_id, access_code))
  781. return false;
  782. }
  783. safe_delete(request);
  784. break;
  785. }
  786. case OP_SysClient: {
  787. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient", opcode, opcode);
  788. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  789. ready_for_updates = true;
  790. database.loadCharacterProperties(this);
  791. break;
  792. }
  793. case OP_MapRequest: {
  794. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  795. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  796. if (packet && app->size > 2 && GetCurrentZone()) {
  797. packet->LoadPacketData(app->pBuffer, app->size);
  798. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  799. if (fog_packet) {
  800. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  801. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  802. fog_packet->setDataByName("unknown1", 1);
  803. fog_packet->setDataByName("unknown3", 1);
  804. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  805. //fog_packet->PrintPacket();
  806. QueuePacket(fog_packet->serialize());
  807. safe_delete(fog_packet);
  808. }
  809. safe_delete(packet);
  810. }
  811. break;
  812. }
  813. case OP_RequestCampMsg: {
  814. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  815. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  816. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  817. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  818. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  819. request->getType_int8_ByName("quit"),
  820. request->getType_int8_ByName("camp_desktop"),
  821. request->getType_int16_ByName("camp_char_select"),
  822. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  823. //DumpPacket(app->pBuffer, app->size);
  824. //request->PrintPacket();
  825. if (!camp_timer) {
  826. int16 camp_time = 20; // default if rule cannot be found
  827. if (GetAdminStatus() >= 100)
  828. camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
  829. else
  830. camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
  831. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  832. if (response) {
  833. bool disconnect = false;
  834. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  835. // Command: /camp desktop
  836. // Command: /quit
  837. response->setDataByName("camp_desktop", 1);
  838. disconnect = true;
  839. }
  840. else {
  841. // Command: /camp
  842. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  843. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  844. response->setDataByName("seconds", camp_time);
  845. }
  846. camp_timer = new Timer(camp_time * 1000);
  847. camp_timer->Enable();
  848. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  849. // /camp {char_name}
  850. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  851. }
  852. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  853. // /camp (go back to char selection screen)
  854. response->setDataByName("char_name", " ");
  855. response->setDataByName("camp_char_select", 1);
  856. }
  857. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  858. response->getType_int8_ByName("seconds"),
  859. response->getType_int8_ByName("camp_desktop"),
  860. response->getType_int8_ByName("camp_char_select"),
  861. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  862. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  863. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  864. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  865. //response->PrintPacket();
  866. QueuePacket(response->serialize());
  867. safe_delete(response);
  868. if (disconnect)
  869. Disconnect();
  870. }
  871. }
  872. }
  873. safe_delete(request);
  874. break;
  875. }
  876. case OP_StoodMsg: {
  877. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  878. if (camp_timer)
  879. {
  880. // JA: clear camping flag
  881. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  882. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  883. safe_delete(camp_timer);
  884. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  885. QueuePacket(outapp);
  886. }
  887. player->SetTempVisualState(0);
  888. break;
  889. }
  890. case OP_StandMsg: {
  891. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  892. if (camp_timer)
  893. {
  894. // JA: clear camping flag
  895. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  896. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  897. safe_delete(camp_timer);
  898. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  899. QueuePacket(outapp);
  900. }
  901. player->SetTempVisualState(539);
  902. break;
  903. }
  904. case OP_SitMsg: {
  905. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  906. player->SetTempVisualState(538);
  907. break;
  908. }
  909. case OP_SatMsg: {
  910. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  911. player->SetTempVisualState(540);
  912. break;
  913. }
  914. case OP_QuestJournalOpenMsg:
  915. case OP_QuestJournalInspectMsg: {
  916. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  917. if (app->size < sizeof(int32))
  918. break;
  919. int32 quest_id = 0;
  920. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  921. Quest* quest = GetActiveQuest(quest_id);
  922. if (quest)
  923. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  924. else {
  925. quest = player->GetCompletedQuest(quest_id);
  926. if (quest)
  927. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, 0, 1, true));
  928. }
  929. break;
  930. }
  931. case OP_QuestJournalSetVisibleMsg: {
  932. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  933. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  934. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  935. int32 quest_id = packet->getType_int32_ByName("quest_id");
  936. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  937. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  938. if (player_quests) {
  939. if (player_quests->count(quest_id) > 0)
  940. player_quests->at(quest_id)->SetHidden(hidden);
  941. else
  942. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  943. }
  944. else
  945. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  946. safe_delete(packet);
  947. }
  948. break;
  949. }
  950. case OP_MacroUpdateMsg: {
  951. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  952. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  953. if (macro_update && macro_update->LoadPacketData(app->pBuffer, app->size)) {
  954. vector<string>* update = new vector<string>;
  955. int8 number = macro_update->getType_int8_ByName("number");
  956. int16 icon = macro_update->getType_int16_ByName("icon");
  957. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  958. int8 count = macro_update->getType_int8_ByName("macro_count");
  959. for (int8 i = 0; i < count; i++) {
  960. char tmp_command[15] = { 0 };
  961. sprintf(tmp_command, "command_%i", i);
  962. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  963. }
  964. if (name.length() == 0)
  965. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  966. else
  967. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  968. safe_delete(update);
  969. safe_delete(macro_update);
  970. }
  971. break;
  972. }
  973. case OP_DialogSelectMsg: {
  974. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  975. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  976. if (packet) {
  977. packet->LoadPacketData(app->pBuffer, app->size);
  978. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  979. int32 response_index = packet->getType_int32_ByName("response");
  980. if (GetCurrentZone()) {
  981. Spawn* spawn = conversation_spawns[conversation_id];
  982. Item* item = conversation_items[conversation_id];
  983. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  984. if (spawn)
  985. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation_map[conversation_id][response_index].c_str());
  986. else if (item && lua_interface && item->GetItemScript())
  987. lua_interface->RunItemScript(item->GetItemScript(), conversation_map[conversation_id][response_index].c_str(), item, player);
  988. }
  989. else
  990. CloseDialog(conversation_id);
  991. }
  992. safe_delete(packet);
  993. }
  994. break;
  995. }
  996. case OP_PositionMoveableObject: {
  997. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  998. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  999. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1000. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1001. if (!spawn) {
  1002. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1003. break;
  1004. }
  1005. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1006. char query[256];
  1007. switch (GetSpawnPlacementMode())
  1008. {
  1009. case ServerSpawnPlacementMode::OPEN_HEADING:
  1010. {
  1011. if (spawn && spawn->IsWidget())
  1012. {
  1013. Widget* widget = (Widget*)spawn;
  1014. widget->SetOpenHeading(newHeading);
  1015. widget->SetIncludeHeading(true);
  1016. spawn->position_changed = true;
  1017. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1018. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1019. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1020. }
  1021. else
  1022. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1023. break;
  1024. }
  1025. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1026. {
  1027. if (spawn && spawn->IsWidget())
  1028. {
  1029. Widget* widget = (Widget*)spawn;
  1030. widget->SetClosedHeading(newHeading);
  1031. widget->SetIncludeHeading(true);
  1032. spawn->position_changed = true;
  1033. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1034. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1035. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1036. if (spawn->GetSpawnLocationID())
  1037. {
  1038. Query query;
  1039. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1040. }
  1041. }
  1042. else
  1043. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1044. break;
  1045. }
  1046. default:
  1047. {
  1048. spawn->SetX(place_object->getType_float_ByName("x"));
  1049. spawn->SetY(place_object->getType_float_ByName("y"));
  1050. spawn->SetZ(place_object->getType_float_ByName("z"));
  1051. spawn->SetHeading(newHeading);
  1052. spawn->SetSpawnOrigX(spawn->GetX());
  1053. spawn->SetSpawnOrigY(spawn->GetY());
  1054. spawn->SetSpawnOrigZ(spawn->GetZ());
  1055. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1056. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
  1057. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1058. else if (spawn->GetSpawnLocationID() > 0)
  1059. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1060. }
  1061. }
  1062. safe_delete(place_object);
  1063. }
  1064. break;
  1065. }
  1066. case OP_CampAbortedMsg: {
  1067. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1068. if (camp_timer)
  1069. {
  1070. // JA: clear camping flag
  1071. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1072. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1073. safe_delete(camp_timer);
  1074. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1075. QueuePacket(outapp);
  1076. }
  1077. break;
  1078. }
  1079. case OP_DoneLoadingZoneResourcesMsg: {
  1080. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1081. SendZoneSpawns();
  1082. break;
  1083. }
  1084. case OP_DefaultGroupOptionsRequestMsg: {
  1085. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1086. SendDefaultGroupOptions();
  1087. break;
  1088. }
  1089. case OP_DoneLoadingEntityResourcesMsg: {
  1090. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1091. if (!IsReadyForSpawns())
  1092. SetReadyForSpawns(true);
  1093. SendCharInfo();
  1094. pos_update.Start();
  1095. quest_pos_timer.Start();
  1096. break;
  1097. }
  1098. case OP_LootItemsRequestMsg: {
  1099. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1100. HandleLoot(app);
  1101. break;
  1102. }
  1103. case OP_KnowledgeWindowSlotMappingMsg: {
  1104. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1105. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1106. if (packet) {
  1107. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1108. int num_updates = packet->getType_int16_ByName("spell_count");
  1109. int32 spell_id = 0;
  1110. int16 slot_id = 0;
  1111. char tmp_spell_id[15];
  1112. char tmp_slot[15];
  1113. for (int i = 0; i < num_updates; i++) {
  1114. memset(tmp_spell_id, 0, 15);
  1115. memset(tmp_slot, 0, 15);
  1116. sprintf(tmp_spell_id, "spell_id_%i", i);
  1117. sprintf(tmp_slot, "slot_id_%i", i);
  1118. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1119. if (spell_id > 0) {
  1120. slot_id = packet->getType_int16_ByName(tmp_slot);
  1121. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1122. if (spell && spell->slot != slot_id) {
  1123. spell->slot = slot_id;
  1124. spell->save_needed = true;
  1125. }
  1126. }
  1127. }
  1128. }
  1129. safe_delete(packet);
  1130. }
  1131. //SendKnowledgeWindowSlot();
  1132. break;
  1133. }
  1134. case OP_ReadyToZoneMsg: {
  1135. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1136. if (client_zoning)
  1137. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
  1138. else
  1139. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1140. Disconnect();
  1141. break;
  1142. }
  1143. case OP_ClientFellMsg: {
  1144. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1145. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1146. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1147. float height = request->getType_float_ByName("height");
  1148. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1149. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1150. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1151. break;
  1152. }*/
  1153. float safe_height = 13.0f;
  1154. Skill* skill = GetPlayer()->GetSkillByName("Safe Fall", true);
  1155. if (skill)
  1156. safe_height += (skill->current_val + 1) / 5;
  1157. if (height > safe_height) {
  1158. int16 damage = (int16)ceil((height - safe_height) * 125);
  1159. if (height >= 80)
  1160. damage = 30000;
  1161. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1162. if (damage > 0) {
  1163. GetPlayer()->TakeDamage(damage);
  1164. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1165. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1166. if (!GetPlayer()->GetInvulnerable())
  1167. GetPlayer()->SetCharSheetChanged(true);
  1168. GetCurrentZone()->SendDamagePacket(0, GetPlayer(), DAMAGE_PACKET_TYPE_SIMPLE_DAMAGE, GetPlayer()->GetInvulnerable() ? DAMAGE_PACKET_RESULT_INVULNERABLE : DAMAGE_PACKET_RESULT_SUCCESSFUL, DAMAGE_PACKET_DAMAGE_TYPE_FALLING, damage, 0);
  1169. if (GetPlayer()->GetHP() == 0) {
  1170. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1171. }
  1172. }
  1173. }
  1174. safe_delete(request);
  1175. }
  1176. break;
  1177. }
  1178. case OP_MapFogDataUpdateMsg: {
  1179. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1180. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1181. break;
  1182. }
  1183. case OP_SelectZoneTeleporterDestinatio: {
  1184. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1185. ProcessTeleportLocation(app);
  1186. break;
  1187. }
  1188. case OP_SendLatestRequestMsg: {
  1189. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1190. uchar blah25[] = { 0x01 };
  1191. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1192. QueuePacket(app25);
  1193. break;
  1194. }
  1195. case OP_ShowCreateFromRecipeUIMsg: {
  1196. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1197. break;
  1198. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1199. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1200. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1201. QueuePacket(app);
  1202. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1203. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1204. QueuePacket(app);
  1205. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1206. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1207. ,0xff,0xff,0xff};
  1208. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1209. QueuePacket(app);
  1210. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1211. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1212. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1213. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1214. QueuePacket(app);
  1215. uchar blah5[] ={0x00,0x00};
  1216. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1217. QueuePacket(app);
  1218. break;*/
  1219. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1220. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1221. //QueuePacket(app);
  1222. }
  1223. case OP_BeginItemCreationMsg: {
  1224. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1225. //DumpPacket(app->pBuffer, app->size);
  1226. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1227. if (packet) {
  1228. packet->LoadPacketData(app->pBuffer, app->size);
  1229. int32 item = 0;
  1230. vector<int32> items;
  1231. char tmp_item_id[20];
  1232. item = packet->getType_int32_ByName("primary_component_id");
  1233. if (item > 0)
  1234. items.push_back(item);
  1235. item = 0;
  1236. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1237. for (int8 i = 0; i < build_components; i++) {
  1238. memset(tmp_item_id, 0, 20);
  1239. sprintf(tmp_item_id, "component_id_%i", i);
  1240. item = packet->getType_int32_ByName(tmp_item_id);
  1241. if (item > 0)
  1242. items.push_back(item);
  1243. item = 0;
  1244. }
  1245. item = packet->getType_int32_ByName("fuel_id");
  1246. if (item > 0)
  1247. items.push_back(item);
  1248. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1249. safe_delete(packet);
  1250. }
  1251. break;
  1252. }
  1253. case OP_StopItemCreationMsg: {
  1254. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1255. //DumpPacket(app->pBuffer, app->size);
  1256. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1257. break;
  1258. }
  1259. //case OP_SignalMsg:{
  1260. // LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SignalMsg", opcode, opcode);
  1261. // //if(app->size == 25 && app->pBuffer[0] == 0x17 && app->pBuffer[24] == 0x79)
  1262. // // GetPlayer()->ModifySpellStatus(0, 66, true);
  1263. // if(connected && player->GetHP() == 0)
  1264. // DisplayDeadWindow();
  1265. // break;
  1266. // }
  1267. case OP_EntityVerbsRequestMsg: {
  1268. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1269. HandleVerbRequest(app);
  1270. break;
  1271. }
  1272. case OP_EntityVerbsVerbMsg: {
  1273. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1274. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1275. if (packet) {
  1276. packet->LoadPacketData(app->pBuffer, app->size);
  1277. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1278. player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
  1279. Spawn* spawn = player->GetTarget();
  1280. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1281. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1282. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1283. if (spawn->IsGroundSpawn())
  1284. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1285. else if (spawn->IsObject())
  1286. ((Object*)spawn)->HandleUse(this, command);
  1287. else if (spawn->IsWidget())
  1288. ((Widget*)spawn)->HandleUse(this, command);
  1289. else if (spawn->IsSign())
  1290. ((Sign*)spawn)->HandleUse(this, command);
  1291. }
  1292. }
  1293. else {
  1294. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1295. if (command.size > 0) {
  1296. string command_name = command.data;
  1297. if (command_name.find(" ") < 0xFFFFFFFF)
  1298. command_name = command_name.substr(0, command_name.find(" "));
  1299. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1300. if (handler != 0xFFFFFFFF) {
  1301. if (command.data == command_name) {
  1302. command.data = "";
  1303. command.size = 0;
  1304. }
  1305. else {
  1306. command.data = command.data.substr(command.data.find(" ") + 1);
  1307. command.size = command.data.length();
  1308. }
  1309. commands.Process(handler, &command, this);
  1310. }
  1311. else {
  1312. if (spawn && spawn->IsNPC()) {
  1313. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1314. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1315. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1316. }
  1317. }
  1318. }
  1319. else
  1320. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1321. }
  1322. }
  1323. }
  1324. safe_delete(packet);
  1325. }
  1326. break;
  1327. }
  1328. case OP_SkillInfoRequest: {
  1329. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1330. HandleSkillInfoRequest(app);
  1331. break;
  1332. }
  1333. case OP_UpdateTargetMsg: {
  1334. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1335. int16 index = 0;
  1336. memcpy(&index, app->pBuffer, sizeof(int16));
  1337. if (index == 0xFFFF)
  1338. GetPlayer()->SetTarget(0);
  1339. else
  1340. GetPlayer()->SetTarget(GetPlayer()->GetSpawnByIndex(index));
  1341. if (GetPlayer()->GetTarget())
  1342. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1343. //player->SetTarget((int16*)app->pBuffer);
  1344. break;
  1345. }
  1346. case OP_ExamineInfoRequestMsg: {
  1347. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1348. HandleExamineInfoRequest(app);
  1349. break;
  1350. }
  1351. case OP_QuickbarUpdateMsg:
  1352. //case OP_QuickbarAddMsg:
  1353. {
  1354. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1355. HandleQuickbarUpdateRequest(app);
  1356. break;
  1357. }
  1358. case OP_PredictionUpdateMsg: {
  1359. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg", opcode, opcode);
  1360. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1361. QueuePacket(app);
  1362. break;
  1363. }
  1364. case OP_RemoteCmdMsg: {
  1365. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1366. if (app->size > 0) {
  1367. EQ2_CommandString remote(app->pBuffer, app->size);
  1368. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1369. #if EQDEBUG >= 9
  1370. DumpPacket(app);
  1371. #endif
  1372. commands.Process(remote.handler, &remote.command, this);
  1373. }
  1374. else //bad client, disconnect
  1375. Disconnect();
  1376. break;
  1377. }
  1378. case OP_CancelSpellCast: {
  1379. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1380. current_zone->Interrupted(player, 0, 0, true);
  1381. SimpleMessage(CHANNEL_COLOR_SPELL_INTERRUPT, "You stop casting.");
  1382. break;
  1383. }
  1384. case OP_UpdatePositionMsg: {
  1385. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg", opcode, opcode);
  1386. int8 offset = 13;
  1387. if (app->pBuffer[0] == 0xFF)
  1388. offset += 2;
  1389. if (app->size > offset) {
  1390. if (player->IsCasting()) {
  1391. float distance = 0;
  1392. float x = player->GetX();
  1393. float y = player->GetY();
  1394. float z = player->GetZ();
  1395. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1396. distance = player->GetDistance(x, y, z, false);
  1397. if (distance > .5)
  1398. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1399. }
  1400. else
  1401. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1402. player_pos_changed = true;
  1403. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1404. //DumpPacket(app);
  1405. }
  1406. break;
  1407. }
  1408. case OP_MailSendMessageMsg: {
  1409. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1410. HandleSentMail(app);
  1411. break;
  1412. }
  1413. case OP_StopTrackingMsg: {
  1414. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1415. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1416. break;
  1417. }
  1418. case OP_BeginTrackingMsg: {
  1419. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1420. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1421. if (packet) {
  1422. packet->LoadPacketData(app->pBuffer, app->size);
  1423. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1424. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1425. if (spawn) {
  1426. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1427. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1428. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1429. }
  1430. safe_delete(packet);
  1431. }
  1432. break;
  1433. }
  1434. case OP_BioUpdateMsg: {
  1435. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  1436. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  1437. if (packet) {
  1438. packet->LoadPacketData(app->pBuffer, app->size);
  1439. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  1440. safe_delete(packet);
  1441. }
  1442. break;
  1443. }
  1444. case OP_RewardPackMsg: {
  1445. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  1446. /* This logging is still here because I remember another system using this packet and just want to make sure we can figure out that it's being sent
  1447. when we come across it (scatman) */
  1448. const char* name = app->GetOpcodeName();
  1449. if (name)
  1450. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  1451. else
  1452. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  1453. //DumpPacket(app);
  1454. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  1455. if (packet) {
  1456. packet->LoadPacketData(app->pBuffer, app->size);
  1457. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  1458. /* Player has contacted a guild recruiter */
  1459. if (recruiter_name.length() > 0) {
  1460. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  1461. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  1462. if (recruiter && guild) {
  1463. Message(CHANNEL_COLOR_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  1464. recruiter->Message(CHANNEL_COLOR_GUILD_EVENT, "%s [%u %s], [0 Unskilled] (%s) is requesting to speak to YOU about joining the guild.", player->GetName(), player->GetLevel(), classes.GetClassNameCase(player->GetAdventureClass()).c_str(), races.GetRaceNameCase(player->GetRace()));
  1465. recruiter->PlaySound("ui_guild_page");
  1466. }
  1467. }
  1468. /* New picture taken for guild recruiting */
  1469. else {
  1470. //DumpPacket(app->pBuffer, app->size);
  1471. int32 guild_id = 0;
  1472. int16 picture_data_size = 0;
  1473. unsigned char* recruiter_picture_data = 0;
  1474. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  1475. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  1476. Guild* guild = guild_list.GetGuild(guild_id);
  1477. if (guild) {
  1478. GuildMember* gm = guild->GetGuildMember(player);
  1479. if (gm) {
  1480. safe_delete_array(gm->recruiter_picture_data);
  1481. recruiter_picture_data = new unsigned char[picture_data_size];
  1482. for (int16 i = 0; i < picture_data_size; i++)
  1483. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  1484. gm->recruiter_picture_data = recruiter_picture_data;
  1485. gm->recruiter_picture_data_size = picture_data_size;
  1486. guild->SetMemberSaveNeeded(true);
  1487. }
  1488. }
  1489. }
  1490. safe_delete(packet);
  1491. }
  1492. break;
  1493. }
  1494. case OP_PetOptions: {
  1495. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  1496. Spawn* target = player->GetTarget();
  1497. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  1498. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  1499. bool change = false;
  1500. packet->LoadPacketData(app->pBuffer, app->size);
  1501. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  1502. if (strlen(name.c_str()) != 0) {
  1503. target->SetName(name.c_str());
  1504. strcpy(player->GetInfoStruct()->pet_name, name.c_str());
  1505. GetCurrentZone()->SendUpdateTitles(target);
  1506. change = true;
  1507. }
  1508. // Check protect self setting and update if needed
  1509. if (packet->getType_int8_ByName("protect_self") == 1) {
  1510. if ((player->GetInfoStruct()->pet_behavior & 2) == 0) {
  1511. player->GetInfoStruct()->pet_behavior += 2;
  1512. change = true;
  1513. }
  1514. }
  1515. else {
  1516. if ((player->GetInfoStruct()->pet_behavior & 2) != 0) {
  1517. player->GetInfoStruct()->pet_behavior -= 2;
  1518. change = true;
  1519. }
  1520. }
  1521. // Check protect master setting and update if needed
  1522. if (packet->getType_int8_ByName("protect_master") == 1) {
  1523. if ((player->GetInfoStruct()->pet_behavior & 1) == 0) {
  1524. player->GetInfoStruct()->pet_behavior += 1;
  1525. change = true;
  1526. }
  1527. }
  1528. else {
  1529. if ((player->GetInfoStruct()->pet_behavior & 1) != 0) {
  1530. player->GetInfoStruct()->pet_behavior -= 1;
  1531. change = true;
  1532. }
  1533. }
  1534. // Check stay/follow setting and update if needed
  1535. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  1536. if (player->GetInfoStruct()->pet_movement != 2) {
  1537. player->GetInfoStruct()->pet_movement = 2;
  1538. change = true;
  1539. }
  1540. }
  1541. else {
  1542. if (player->GetInfoStruct()->pet_movement != 1) {
  1543. player->GetInfoStruct()->pet_movement = 1;
  1544. change = true;
  1545. }
  1546. }
  1547. // Ranged/Melee settings are not implemented yet
  1548. if (change)
  1549. player->SetCharSheetChanged(true);
  1550. safe_delete(packet);
  1551. }
  1552. break;
  1553. }
  1554. case OP_RecipeBook: {
  1555. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  1556. SendRecipeList();
  1557. break;
  1558. }
  1559. case OP_BuyPlayerHouseMsg: {
  1560. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  1561. DumpPacket(app);
  1562. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  1563. if (packet) {
  1564. packet->LoadPacketData(app->pBuffer, app->size);
  1565. HouseZone* hz = world.GetHouseZone(packet->getType_int64_ByName("house_id"));
  1566. if (hz) {
  1567. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id);
  1568. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  1569. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  1570. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  1571. }
  1572. }
  1573. safe_delete(packet);
  1574. break;
  1575. }
  1576. case OP_EnterHouseMsg: {
  1577. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  1578. DumpPacket(app);
  1579. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  1580. if (packet) {
  1581. packet->LoadPacketData(app->pBuffer, app->size);
  1582. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(packet->getType_int64_ByName("house_id"));
  1583. if (ph) {
  1584. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1585. if (hz) {
  1586. ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id);
  1587. if (house) {
  1588. Zone(house, true);
  1589. }
  1590. }
  1591. }
  1592. }
  1593. safe_delete(packet);
  1594. break;
  1595. }
  1596. case OP_PayHouseUpkeepMsg: {
  1597. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  1598. DumpPacket(app);
  1599. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  1600. if (packet) {
  1601. packet->LoadPacketData(app->pBuffer, app->size);
  1602. }
  1603. safe_delete(packet);
  1604. break;
  1605. }
  1606. case OP_ExitHouseMsg: {
  1607. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  1608. int32 instance_id = GetCurrentZone()->GetInstanceID();
  1609. if (instance_id > 0) {
  1610. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  1611. if (ph) {
  1612. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1613. if (hz) {
  1614. ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
  1615. // determine if this is an instanced zone that already exists
  1616. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
  1617. if (instance_zone || new_zone) {
  1618. GetPlayer()->SetX(hz->exit_x);
  1619. GetPlayer()->SetY(hz->exit_y);
  1620. GetPlayer()->SetZ(hz->exit_z);
  1621. GetPlayer()->SetHeading(hz->exit_heading);
  1622. if (instance_zone)
  1623. Zone(instance_zone->GetInstanceID(), false, true);
  1624. else
  1625. Zone(new_zone, false);
  1626. }
  1627. }
  1628. }
  1629. }
  1630. DumpPacket(app);
  1631. break;
  1632. }
  1633. case OP_QuestJournalWaypointMsg: {
  1634. //DumpPacket(app);
  1635. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  1636. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  1637. if (packet) {
  1638. packet->LoadPacketData(app->pBuffer, app->size);
  1639. int32 quests = packet->getType_int32_ByName("num_quests");
  1640. if (quests > 100) // just picking a number higher than max allowed
  1641. {
  1642. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  1643. break;
  1644. }
  1645. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  1646. for (int32 i = 0; i < quests; i++) {
  1647. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  1648. if (id == 0)
  1649. continue;
  1650. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  1651. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  1652. if (player->player_quests.count(id) > 0) {
  1653. player->player_quests[id]->SetTracked(tracked);
  1654. player->player_quests[id]->SetSaveNeeded(true);
  1655. }
  1656. }
  1657. safe_delete(packet);
  1658. }
  1659. break;
  1660. }
  1661. case OP_PaperdollImage: {
  1662. PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  1663. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  1664. //First check if this is a new image... delete an existing partial image if one exists
  1665. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  1666. if (packet_index == 0) {
  1667. safe_delete_array(incoming_paperdoll.image_bytes);
  1668. incoming_paperdoll.last_received_packet_index = 0;
  1669. incoming_paperdoll.current_size_bytes = 0;
  1670. }
  1671. //return if this packet is not the one we are expecting...
  1672. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  1673. safe_delete(packet);
  1674. break;
  1675. }
  1676. //Check how many packets we're supposed to be receiving for this/these images
  1677. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  1678. //Check the image type, if this is a new type in the same series of packets we have a new image
  1679. int8 img_type = packet->getType_int8_ByName("image_type");
  1680. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  1681. //We have a new image. Save the old data and clear before continuing
  1682. SavePlayerImages();
  1683. }
  1684. incoming_paperdoll.image_type = img_type;
  1685. //Get the size of the image data in this packet
  1686. sint64 image_size = packet->getType_int32_ByName("imageSize");
  1687. if (image_size <= 0 || image_size > 1048576) {
  1688. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  1689. safe_delete(packet);
  1690. break;
  1691. }
  1692. //Create a new array
  1693. int32 new_image_size = image_size;
  1694. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  1695. if (incoming_paperdoll.image_bytes) {
  1696. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  1697. safe_delete_array(incoming_paperdoll.image_bytes);
  1698. }
  1699. //variable i should be the index in the packet of the first PNG file byte
  1700. vector<DataStruct*>* d_structs = packet->getStructs();
  1701. vector<DataStruct*>::iterator itr;
  1702. int32 i = 0;
  1703. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  1704. DataStruct* ds = (*itr);
  1705. if (strcmp(ds->GetName(), "pngData_0") != 0)
  1706. i += ds->GetDataSizeInBytes();
  1707. else
  1708. break;
  1709. }
  1710. //Return if this packet is bad and we would read out of bounds
  1711. if (app->size - i < new_image_size) {
  1712. safe_delete(packet);
  1713. safe_delete_array(new_image);
  1714. break;
  1715. }
  1716. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  1717. memcpy(tmp, app->pBuffer + i, new_image_size);
  1718. incoming_paperdoll.current_size_bytes += new_image_size;
  1719. incoming_paperdoll.image_bytes = new_image;
  1720. //Check if this is the last packet we're expecting for this image. Create a final image if so
  1721. if (incoming_paperdoll.image_num_packets == 1 ||
  1722. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  1723. SavePlayerImages();
  1724. }
  1725. incoming_paperdoll.last_received_packet_index = packet_index;
  1726. }
  1727. safe_delete(packet);
  1728. break;
  1729. }
  1730. case OP_ReadyForTakeOffMsg:
  1731. {
  1732. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  1733. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  1734. if (GetPendingFlightPath() > 0) {
  1735. if (index != -1) {
  1736. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  1737. if (packet) {
  1738. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  1739. packet->setDataByName("path_id", index);
  1740. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  1741. QueuePacket(packet->serialize());
  1742. safe_delete(packet);
  1743. on_auto_mount = true;
  1744. }
  1745. }
  1746. else {
  1747. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  1748. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  1749. EndAutoMount();
  1750. }
  1751. SetPendingFlightPath(0);
  1752. }
  1753. else
  1754. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  1755. break;
  1756. }
  1757. case OP_EarlyLandingRequestMsg:
  1758. {
  1759. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  1760. EndAutoMount();
  1761. break;
  1762. }
  1763. case OP_SubmitCharCust:
  1764. {
  1765. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  1766. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  1767. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  1768. int8 type = packet->getType_int8_ByName("type");
  1769. if (type == 0) {
  1770. if (player->custNPC) {
  1771. player->custNPCTarget->CustomizeAppearance(packet);
  1772. current_zone->SendSpawnChanges(player->custNPCTarget);
  1773. }
  1774. else {
  1775. player->CustomizeAppearance(packet);
  1776. current_zone->SendSpawnChanges(player);
  1777. }
  1778. }
  1779. }
  1780. if (player->custNPC) {
  1781. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  1782. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  1783. if (player->custNPCTarget->IsBot())
  1784. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  1785. player->custNPC = false;
  1786. player->custNPCTarget = 0;
  1787. player->changed = true;
  1788. player->info_changed = true;
  1789. current_zone->SendSpawnChanges(player, this);
  1790. }
  1791. break;
  1792. }
  1793. default: {
  1794. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  1795. const char* name = app->GetOpcodeName();
  1796. if (name)
  1797. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  1798. else
  1799. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  1800. //DumpPacket(app);
  1801. }
  1802. }
  1803. if (!eqs || !eqs->CheckActive()) {
  1804. return false;
  1805. }
  1806. return ret;
  1807. }
  1808. bool Client::HandleLootItem(Entity* entity, Item* item) {
  1809. if (!item) {
  1810. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  1811. return false;
  1812. }
  1813. if (player->item_list.HasFreeSlot() || player->item_list.CanStack(item)) {
  1814. if (player->item_list.AssignItemToFreeSlot(item)) {
  1815. int8 type = CHANNEL_COLOR_LOOT;
  1816. if (GetVersion() >= 973 && GetVersion() <= 1000)
  1817. type = CHANNEL_COLOR_NEW_LOOT;
  1818. else if (GetVersion() >= 973)
  1819. type = CHANNEL_COLOR_NEWEST_LOOT;
  1820. if (entity)
  1821. Message(type, "You loot \\aITEM %u 0:%s\\/a from the corpse of %s", item->details.item_id, item->name.c_str(), entity->GetName());
  1822. else
  1823. Message(type, "You found a \\aITEM %u 0:%s\\/a", item->details.item_id, item->name.c_str());
  1824. Guild* guild = player->GetGuild();
  1825. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  1826. char adjective[32];
  1827. int8 type;
  1828. memset(adjective, 0, sizeof(adjective));
  1829. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  1830. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  1831. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  1832. }
  1833. else if (item->details.tier >= ITEM_TAG_FABLED) {
  1834. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  1835. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  1836. }
  1837. else {
  1838. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  1839. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  1840. }
  1841. guild->AddNewGuildEvent(type, "%s has looted the %s \\aITEM %u 0:%s\\/a", Timer::GetUnixTimeStamp(), true, player->GetName(), adjective, item->details.item_id, item->name.c_str());
  1842. guild->SendMessageToGuild(type, "%s has looted the %s \\aITEM %u 0:%s\\/a", player->GetName(), adjective, item->details.item_id, item->name.c_str());
  1843. }
  1844. CheckPlayerQuestsItemUpdate(item);
  1845. return true;
  1846. }
  1847. else
  1848. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  1849. }
  1850. else
  1851. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  1852. return false;
  1853. }
  1854. bool Client::HandleLootItem(Entity* entity, int32 item_id) {
  1855. if (!entity) {
  1856. return false;
  1857. }
  1858. return HandleLootItem(entity, entity->LootItem(item_id));
  1859. }
  1860. void Client::HandleLoot(EQApplicationPacket* app) {
  1861. PacketStruct* packet = configReader.getStruct("WS_LootType", GetVersion());
  1862. if (packet) {
  1863. packet->LoadPacketData(app->pBuffer, app->size);
  1864. int32 loot_id = packet->getType_int32_ByName("loot_id");
  1865. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  1866. safe_delete(packet);
  1867. int32 item_id = 0;
  1868. Item* item = 0;
  1869. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  1870. if (player->HasPendingLootItems(loot_id)) {
  1871. Item* master_item = 0;
  1872. if (loot_all) {
  1873. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  1874. if (items) {
  1875. for (int32 i = 0; loot_all && i < items->size(); i++) {
  1876. master_item = items->at(i);
  1877. if (master_item) {
  1878. item = new Item(master_item);
  1879. if (item) {
  1880. loot_all = HandleLootItem(0, item);
  1881. if (loot_all)
  1882. player->RemovePendingLootItem(loot_id, item->details.item_id);
  1883. }
  1884. }
  1885. }
  1886. safe_delete(items);
  1887. }
  1888. }
  1889. else {
  1890. packet = configReader.getStruct("WS_LootItem", GetVersion());
  1891. if (packet) {
  1892. packet->LoadPacketData(app->pBuffer, app->size);
  1893. item_id = packet->getType_int32_ByName("item_id");
  1894. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  1895. if (items) {
  1896. for (int32 i = 0; i < items->size(); i++) {
  1897. master_item = items->at(i);
  1898. if (master_item && master_item->details.item_id == item_id) {
  1899. item = new Item(master_item);
  1900. if (item && HandleLootItem(0, item))
  1901. player->RemovePendingLootItem(loot_id, item->details.item_id);
  1902. break;
  1903. }
  1904. }
  1905. safe_delete(items);
  1906. }
  1907. safe_delete(packet);
  1908. }
  1909. }
  1910. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  1911. if (outapp)
  1912. QueuePacket(outapp);
  1913. Loot(0, player->GetPendingLootItems(loot_id), (Entity*)spawn);
  1914. }
  1915. else {
  1916. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  1917. if (loot_all) {
  1918. while (loot_all && ((item_id = ((Entity*)spawn)->GetLootItemID()) > 0)) {
  1919. loot_all = HandleLootItem((Entity*)spawn, item_id);
  1920. }
  1921. }
  1922. else {
  1923. packet = configReader.getStruct("WS_LootItem", GetVersion());
  1924. if (packet) {
  1925. packet->LoadPacketData(app->pBuffer, app->size);
  1926. item_id = packet->getType_int32_ByName("item_id");
  1927. HandleLootItem((Entity*)spawn, item_id);
  1928. safe_delete(packet);
  1929. }
  1930. }
  1931. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  1932. if (outapp)
  1933. QueuePacket(outapp);
  1934. Loot((Entity*)spawn);
  1935. if (!((Entity*)spawn)->HasLoot()) {
  1936. CloseLoot();
  1937. if (((Entity*)spawn)->IsNPC())
  1938. GetCurrentZone()->RemoveDeadSpawn(spawn);
  1939. }
  1940. }
  1941. else {
  1942. if (!spawn) {
  1943. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  1944. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  1945. }
  1946. else
  1947. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  1948. }
  1949. }
  1950. }
  1951. }
  1952. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  1953. PacketStruct* request = 0;
  1954. // cout << "Request: \n";
  1955. // DumpPacket(app);
  1956. switch (app->pBuffer[0]) {
  1957. case 0: { //items
  1958. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  1959. if (request) {
  1960. request->LoadPacketData(app->pBuffer, app->size);
  1961. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  1962. if (!item)
  1963. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  1964. if (item) {
  1965. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  1966. if (response) {
  1967. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  1968. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  1969. response->setSmallStringByName("name", item->name.c_str());
  1970. EQ2Packet* app2 = response->serialize();
  1971. //DumpPacket(app2);
  1972. QueuePacket(app2);
  1973. safe_delete(response);
  1974. }
  1975. }
  1976. }
  1977. break;
  1978. }
  1979. case 2: {//spells
  1980. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  1981. if (request) {
  1982. request->LoadPacketData(app->pBuffer, app->size);
  1983. int32 id = request->getType_int32_ByName("id");
  1984. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  1985. Spell* spell = master_spell_list.GetSpell(id, tier);
  1986. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  1987. if (response) {
  1988. response->setDataByName("request_type", 2);
  1989. response->setDataByName("unique_id", tier);
  1990. response->setDataByName("id", id);
  1991. if (spell)
  1992. response->setSmallStringByName("name", spell->GetName());
  1993. else
  1994. response->setSmallStringByName("name", "Unknown Spell");
  1995. EQ2Packet* app2 = response->serialize();
  1996. // DumpPacket(app2);
  1997. QueuePacket(app2);
  1998. safe_delete(response);
  1999. }
  2000. }
  2001. break;
  2002. }
  2003. default: {
  2004. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2005. }
  2006. }
  2007. safe_delete(request);
  2008. }
  2009. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2010. PacketStruct* request = 0;
  2011. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2012. //DumpPacket(app);
  2013. int8 type = app->pBuffer[0];
  2014. if (type == 3) {
  2015. Spell* spell = 0;
  2016. bool trait_display;
  2017. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2018. if (!request) {
  2019. return;
  2020. }
  2021. request->LoadPacketData(app->pBuffer, app->size);
  2022. int32 id = request->getType_int32_ByName("id");
  2023. int32 tier = request->getType_int32_ByName("tier");
  2024. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  2025. //printf("Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)\n",type,tier,trait_tier,id);
  2026. if (trait_tier != 0xFFFFFFFF) {
  2027. spell = master_spell_list.GetSpell(id, trait_tier);
  2028. if (!spell) {
  2029. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  2030. }
  2031. trait_display = true;
  2032. }
  2033. else {
  2034. spell = master_spell_list.GetSpell(id, tier);
  2035. trait_display = false;
  2036. }
  2037. if (spell && sent_spell_details.count(id) == 0) {
  2038. sent_spell_details[id] = true;
  2039. EQ2Packet* app = spell->SerializeSpell(this, false, trait_display);
  2040. //DumpPacket(app);
  2041. QueuePacket(app);
  2042. }
  2043. }
  2044. else if (type == 0) {
  2045. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2046. if (!request) {
  2047. return;
  2048. }
  2049. request->LoadPacketData(app->pBuffer, app->size);
  2050. int32 id = request->getType_int32_ByName("id");
  2051. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  2052. if (!item)
  2053. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  2054. if (!item)
  2055. item = master_item_list.GetItem(id);
  2056. if (item) {// && sent_item_details.count(id) == 0){
  2057. sent_item_details[id] = true;
  2058. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2059. //DumpPacket(app);
  2060. QueuePacket(app);
  2061. }
  2062. else {
  2063. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2064. DumpPacket(app);
  2065. }
  2066. }
  2067. else if (type == 1) {
  2068. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2069. if (!request) {
  2070. return;
  2071. }
  2072. request->LoadPacketData(app->pBuffer, app->size);
  2073. int32 id = request->getType_int32_ByName("id");
  2074. int32 unique_id = request->getType_int32_ByName("unique_id");
  2075. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  2076. if (!item)
  2077. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  2078. if (!item)
  2079. item = master_item_list.GetItem(id);
  2080. if (item) {
  2081. sent_item_details[id] = true;
  2082. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2083. //DumpPacket(app);
  2084. QueuePacket(app);
  2085. }
  2086. else {
  2087. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2088. DumpPacket(app);
  2089. }
  2090. }
  2091. else if (type == 2) {
  2092. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  2093. if (!request) {
  2094. return;
  2095. }
  2096. request->LoadPacketData(app->pBuffer, app->size);
  2097. int32 id = request->getType_int32_ByName("item_id");
  2098. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  2099. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  2100. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  2101. //int32 unique_id = request->getType_int32_ByName("unique_id");
  2102. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  2103. //printf("Type: (%i) Unknown_0: (%u) Unknown_1: (%u) Unknown2: (%i) Unique ID: (%u) Unknown5: (%i) Item ID: (%u)\n",type,unknown_0,unknown_1,unknown2,unique_id,unknown5,id);
  2104. Item* item = master_item_list.GetItem(id);
  2105. if (item) {
  2106. //only display popup for non merchant links
  2107. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, true);
  2108. //DumpPacket(app);
  2109. QueuePacket(app);
  2110. }
  2111. else {
  2112. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2113. DumpPacket(app);
  2114. }
  2115. }
  2116. else if (type == 4) { //spell effect
  2117. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  2118. if (!request) {
  2119. return;
  2120. }
  2121. request->LoadPacketData(app->pBuffer, app->size);
  2122. int32 id = request->getType_int32_ByName("id");
  2123. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  2124. SpellEffects* effect = player->GetSpellEffect(id);
  2125. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  2126. if (effect) {
  2127. int8 tier = effect->tier;
  2128. Spell* spell = master_spell_list.GetSpell(id, tier);
  2129. if (spell && sent_spell_details.count(id) == 0) {
  2130. sent_spell_details[id] = true;
  2131. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, 0x00, 0x81);
  2132. //DumpPacket(app);
  2133. QueuePacket(app);
  2134. }
  2135. }
  2136. }
  2137. else if (type == 5) { // recipe info
  2138. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2139. if (!request)
  2140. return;
  2141. request->LoadPacketData(app->pBuffer, app->size);
  2142. int32 id = request->getType_int32_ByName("unknown_id");
  2143. Recipe* recipe = master_recipe_list.GetRecipe(id);
  2144. if (recipe) {
  2145. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  2146. //DumpPacket(app);
  2147. QueuePacket(app);
  2148. }
  2149. }
  2150. else if (type == 6) { // AA spell info
  2151. Spell* spell = 0;
  2152. //Spell* spell2 = 0;
  2153. //AltAdvanceData* data = 0;
  2154. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2155. if (!request)
  2156. return;
  2157. request->LoadPacketData(app->pBuffer, app->size);
  2158. int32 id = request->getType_int32_ByName("id");
  2159. int32 tier = GetPlayer()->GetSpellTier(id);
  2160. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  2161. //data = master_aa_list.GetAltAdvancement(id);
  2162. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  2163. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  2164. spell = master_spell_list.GetSpell(id, 1);
  2165. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  2166. sent_spell_details[spell->GetSpellID()] = true;
  2167. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  2168. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  2169. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  2170. //DumpPacket(app);
  2171. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  2172. QueuePacket(app);
  2173. //}
  2174. }
  2175. else {
  2176. LogWrite(WORLD__ERROR, 0, "World", "Unknown examine request: %i", (int)type);
  2177. DumpPacket(app);
  2178. }
  2179. safe_delete(request);
  2180. }
  2181. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  2182. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  2183. if (request) {
  2184. request->LoadPacketData(app->pBuffer, app->size);
  2185. int32 id = request->getType_int32_ByName("id");
  2186. int32 bar = request->getType_int32_ByName("hotbar_number");
  2187. int32 slot = request->getType_int32_ByName("hotkey_slot");
  2188. int32 type = request->getType_int32_ByName("type");
  2189. int8 tier = request->getType_int32_ByName("unique_id");
  2190. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  2191. Spell* spell = 0;
  2192. if (type == 0xFFFFFFFF)
  2193. GetPlayer()->RemoveQuickbarItem(bar, slot);
  2194. else {
  2195. if (type == QUICKBAR_NORMAL)
  2196. spell = master_spell_list.GetSpell(id, tier);
  2197. if (spell)
  2198. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  2199. else
  2200. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  2201. }
  2202. safe_delete(request);
  2203. }
  2204. }
  2205. bool Client::Process(bool zone_process) {
  2206. if (!eqs) {
  2207. return false;
  2208. }
  2209. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  2210. return true;
  2211. }
  2212. if (new_client_login) {
  2213. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  2214. SendLoginInfo();
  2215. new_client_login = false;
  2216. }
  2217. bool ret = true;
  2218. sockaddr_in to;
  2219. memset((char*)&to, 0, sizeof(to));
  2220. to.sin_family = AF_INET;
  2221. to.sin_port = port;
  2222. to.sin_addr.s_addr = ip;
  2223. /************ Get all packets from packet manager out queue and process them ************/
  2224. EQApplicationPacket* app = 0;
  2225. if (eqs && !eqs->CheckActive()) {
  2226. num_active_failures++;
  2227. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  2228. if (num_active_failures > 100) {
  2229. return false;
  2230. }
  2231. return true;
  2232. }
  2233. while (ret && eqs && (app = eqs->PopPacket())) {
  2234. ret = HandlePacket(app);
  2235. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  2236. delete app;
  2237. }
  2238. if (GetCurrentZone() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  2239. player->ApplyPassiveSpells();
  2240. //database.LoadCharacterActiveSpells(player);
  2241. player->UnlockAllSpells(true);
  2242. should_load_spells = false;
  2243. }
  2244. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  2245. {
  2246. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  2247. return false;
  2248. }
  2249. if (quest_updates) {
  2250. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  2251. ProcessQuestUpdates();
  2252. }
  2253. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - 300)) {
  2254. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  2255. CheckQuestQueue();
  2256. }
  2257. if (pos_update.Check() && player_pos_changed) {
  2258. //GetPlayer()->CalculateLocation();
  2259. client_list.CheckPlayersInvisStatus(this);
  2260. GetCurrentZone()->SendPlayerPositionChanges(GetPlayer());
  2261. player_pos_changed = false;
  2262. GetCurrentZone()->CheckTransporters(this);
  2263. }
  2264. if (lua_interface && lua_debug && lua_debug_timer.Check())
  2265. lua_interface->UpdateDebugClients(this);
  2266. if (quest_pos_timer.Check())
  2267. CheckPlayerQuestsLocationUpdate();
  2268. if (camp_timer && camp_timer->Check() && getConnection()) {
  2269. getConnection()->SendDisconnect(false);
  2270. safe_delete(camp_timer);
  2271. disconnect_timer = new Timer(2000);
  2272. disconnect_timer->Start();
  2273. }
  2274. if (player->GetSkills()->HasSkillUpdates()) {
  2275. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  2276. if (skills) {
  2277. Skill* skill = 0;
  2278. vector<Skill*>::iterator itr;
  2279. for (itr = skills->begin(); itr != skills->end(); itr++) {
  2280. skill = *itr;
  2281. SkillChanged(skill, skill->previous_val, skill->current_val);
  2282. }
  2283. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  2284. if (app) QueuePacket(app);
  2285. safe_delete(skills);
  2286. }
  2287. }
  2288. if (disconnect_timer && disconnect_timer->Check()) {
  2289. safe_delete(disconnect_timer);
  2290. ret = false;
  2291. }
  2292. m_resurrect.writelock(__FUNCTION__, __LINE__);
  2293. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  2294. safe_delete(current_rez.expire_timer);
  2295. current_rez.expire_timer = 0;
  2296. current_rez.active = false;
  2297. current_rez.caster = 0;
  2298. current_rez.crit = false;
  2299. current_rez.crit_mod = 0;
  2300. current_rez.expire_timer = 0;
  2301. current_rez.heal_name = "";
  2302. current_rez.hp_perc = 0;
  2303. current_rez.mp_perc = 0;
  2304. current_rez.no_calcs = false;
  2305. current_rez.range = 0;
  2306. current_rez.should_delete = false;
  2307. current_rez.spell_name = "";
  2308. current_rez.spell_visual = 0;
  2309. current_rez.subspell = 0;
  2310. }
  2311. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  2312. // Quest timers
  2313. Quest* failed_step = 0;
  2314. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  2315. if (quest_timers.size() > 0) {
  2316. vector<int32>::iterator itr;
  2317. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  2318. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  2319. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  2320. Quest* quest = player_quests->at(*itr);
  2321. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  2322. failed_step = quest;
  2323. break;
  2324. }
  2325. }
  2326. else {
  2327. quest_timers.erase(itr);
  2328. break;
  2329. }
  2330. }
  2331. }
  2332. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  2333. if (failed_step)
  2334. failed_step->StepFailed(failed_step->GetTimerStep());
  2335. if (player->ControlFlagsChanged())
  2336. player->SendControlFlagUpdates(this);
  2337. if (!eqs || (eqs && !eqs->CheckActive()))
  2338. ret = false;
  2339. // redundant to client disconnect
  2340. // if(!ret)
  2341. // Save();
  2342. return ret;
  2343. }
  2344. ClientList::ClientList() {
  2345. MClients.SetName("ClientList::MClients");
  2346. }
  2347. ClientList::~ClientList() {
  2348. }
  2349. void ClientList::ReloadQuests() {
  2350. list<Client*>::iterator client_iter;
  2351. Client* client = 0;
  2352. MClients.readlock(__FUNCTION__, __LINE__);
  2353. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2354. client = *client_iter;
  2355. if (client)
  2356. client->ReloadQuests();
  2357. }
  2358. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2359. }
  2360. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  2361. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  2362. return;
  2363. list<Client*>::iterator client_iter;
  2364. Client* client = 0;
  2365. MClients.readlock(__FUNCTION__, __LINE__);
  2366. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2367. client = *client_iter;
  2368. if (client == owner || client->GetPlayer() == NULL)
  2369. continue;
  2370. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  2371. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  2372. }
  2373. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2374. }
  2375. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  2376. list<Client*>::iterator client_iter;
  2377. Client* client = 0;
  2378. MClients.readlock(__FUNCTION__, __LINE__);
  2379. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2380. client = *client_iter;
  2381. if (!client->GetPlayer())
  2382. continue;
  2383. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  2384. }
  2385. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2386. }
  2387. int32 ClientList::Count() {
  2388. return client_list.size();
  2389. }
  2390. void ClientList::Add(Client* client) {
  2391. MClients.writelock(__FUNCTION__, __LINE__);
  2392. client_list.push_back(client);
  2393. MClients.releasewritelock(__FUNCTION__, __LINE__);
  2394. }
  2395. Client* ClientList::FindByAccountID(int32 account_id) {
  2396. list<Client*>::iterator client_iter;
  2397. Client* client = 0;
  2398. Client* ret = 0;
  2399. MClients.readlock(__FUNCTION__, __LINE__);
  2400. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2401. client = *client_iter;
  2402. if (client->GetAccountID() == account_id) {
  2403. ret = client;
  2404. break;
  2405. }
  2406. }
  2407. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2408. return ret;
  2409. }
  2410. Client* ClientList::FindByName(char* charName) {
  2411. list<Client*>::iterator client_iter;
  2412. Client* client = 0;
  2413. Client* ret = 0;
  2414. MClients.readlock(__FUNCTION__, __LINE__);
  2415. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2416. client = *client_iter;
  2417. if (!client || !client->GetPlayer())
  2418. continue;
  2419. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  2420. ret = client;
  2421. break;
  2422. }
  2423. }
  2424. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2425. return ret;
  2426. }
  2427. Client* ClientList::Get(int32 ip, int16 port) {
  2428. list<Client*>::iterator client_iter;
  2429. Client* client = 0;
  2430. Client* ret = 0;
  2431. MClients.readlock(__FUNCTION__, __LINE__);
  2432. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2433. client = *client_iter;
  2434. if (client->GetIP() == ip && client->GetPort() == port) {
  2435. ret = client;
  2436. break;
  2437. }
  2438. }
  2439. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2440. return ret;
  2441. }
  2442. void ClientList::Process() {
  2443. list<Client*>::iterator client_iter;
  2444. list<Client*>::iterator erase_iter;
  2445. Client* client = 0;
  2446. MClients.readlock(__FUNCTION__, __LINE__);
  2447. erase_iter = client_list.end();
  2448. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2449. client = *client_iter;
  2450. // have a sanity check because the client list can sometimes obtain null client pointers
  2451. if (!client || (!client->Process() || client->remove_from_list)) {
  2452. erase_iter = client_iter;
  2453. break;
  2454. }
  2455. }
  2456. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2457. if (erase_iter != client_list.end()) {
  2458. client = *erase_iter;
  2459. MClients.writelock(__FUNCTION__, __LINE__);
  2460. client_list.erase(erase_iter);
  2461. MClients.releasewritelock(__FUNCTION__, __LINE__);
  2462. if (client && !client->remove_from_list) {
  2463. struct in_addr in;
  2464. in.s_addr = client->GetIP();
  2465. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  2466. safe_delete(client);
  2467. }
  2468. }
  2469. }
  2470. void ClientList::RemoveConnection(EQStream* eqs) {
  2471. Client* client;
  2472. if (eqs) {
  2473. list<Client*>::iterator client_iter;
  2474. MClients.readlock(__FUNCTION__, __LINE__);
  2475. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2476. client = *client_iter;
  2477. if (client->getConnection() == eqs)
  2478. client->Disconnect(false);
  2479. }
  2480. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2481. }
  2482. }
  2483. bool ClientList::ContainsStream(EQStream* eqs) {
  2484. if (!eqs) {
  2485. return false;
  2486. }
  2487. list<Client*>::iterator client_iter;
  2488. bool ret = false;
  2489. MClients.readlock(__FUNCTION__, __LINE__);
  2490. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2491. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  2492. ret = true;
  2493. break;
  2494. }
  2495. }
  2496. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2497. return ret;
  2498. }
  2499. void ClientList::Remove(Client* client, bool remove_data) {
  2500. client->remove_from_list = true;
  2501. if (remove_data) {
  2502. safe_delete(client);
  2503. }
  2504. }
  2505. void Client::SetCurrentZone(int32 id) {
  2506. if (current_zone) {
  2507. //current_zone->GetCombat()->RemoveHate(player);
  2508. current_zone->RemoveSpawn(false, player, false);
  2509. }
  2510. SetCurrentZone(zone_list.Get(id));
  2511. }
  2512. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  2513. if (current_zone) {
  2514. //current_zone->GetCombat()->RemoveHate(player);
  2515. current_zone->RemoveSpawn(false, player, false);
  2516. }
  2517. SetCurrentZone(zone_list.GetByInstanceID(id, zoneid));
  2518. }
  2519. ZoneServer* Client::GetCurrentZone() {
  2520. return current_zone;
  2521. }
  2522. void Client::SimpleMessage(int8 color, const char* message) {
  2523. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  2524. if (command_packet) {
  2525. command_packet->setDataByName("color", color);
  2526. command_packet->setMediumStringByName("text", message);
  2527. command_packet->setDataByName("unknown02", 0x00ff);
  2528. EQ2Packet* outapp = command_packet->serialize();
  2529. QueuePacket(outapp);
  2530. safe_delete(command_packet);
  2531. }
  2532. }
  2533. void Client::SendSpellUpdate(Spell* spell) {
  2534. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  2535. if (packet) {
  2536. int8 xxx = spell->GetSpellData()->is_aa;
  2537. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  2538. packet->setDataByName("spell_id", spell->GetSpellID());
  2539. packet->setDataByName("unique_id", spell->GetSpellTier());
  2540. packet->setDataByName("spell_name", spell->GetName());
  2541. packet->setDataByName("unknown", xxx);
  2542. packet->setDataByName("display_spell_tier", 1);
  2543. packet->setDataByName("unknown3", 1);
  2544. packet->setDataByName("tier", spell->GetSpellTier());
  2545. packet->setDataByName("icon", spell->GetSpellIcon());
  2546. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  2547. packet->setDataByName("unknown5", 0xFFFFFFFF);
  2548. //packet->PrintPacket();
  2549. EQ2Packet* outapp = packet->serialize();
  2550. //DumpPacket(outapp);
  2551. QueuePacket(outapp);
  2552. safe_delete(packet);
  2553. }
  2554. }
  2555. void Client::Message(int8 type, const char* message, ...) {
  2556. va_list argptr;
  2557. char buffer[4096];
  2558. va_start(argptr, message);
  2559. vsnprintf(buffer, sizeof(buffer), message, argptr);
  2560. va_end(argptr);
  2561. SimpleMessage(type, buffer);
  2562. }
  2563. void Client::Disconnect(bool send_disconnect)
  2564. {
  2565. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  2566. SetConnected(false);
  2567. if (send_disconnect && getConnection())
  2568. getConnection()->SendDisconnect(true);
  2569. this->Save();
  2570. this->GetPlayer()->WritePlayerStatistics();
  2571. eqs = 0;
  2572. }
  2573. bool Client::Summon(const char* search_name) {
  2574. Spawn* target = 0;
  2575. if (search_name || GetPlayer()->GetTarget()) {
  2576. Client* search_client = 0;
  2577. if (search_name) {
  2578. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  2579. if (target && target->IsPlayer())
  2580. search_client = GetCurrentZone()->GetClientBySpawn(target);
  2581. if (!target) {
  2582. search_client = zone_list.GetClientByCharName(string(search_name));
  2583. if (search_client)
  2584. target = search_client->GetPlayer();
  2585. }
  2586. }
  2587. else
  2588. target = GetPlayer()->GetTarget();
  2589. if (target && target != GetPlayer()) {
  2590. target->SetX(GetPlayer()->GetX());
  2591. target->SetY(GetPlayer()->GetY());
  2592. target->SetZ(GetPlayer()->GetZ());
  2593. target->SetHeading(GetPlayer()->GetHeading());
  2594. if (!target->IsPlayer()) {
  2595. target->SetSpawnOrigX(target->GetX());
  2596. target->SetSpawnOrigY(target->GetY());
  2597. target->SetSpawnOrigZ(target->GetZ());
  2598. target->SetSpawnOrigHeading(target->GetHeading());
  2599. }
  2600. target->SetLocation(GetPlayer()->GetLocation());
  2601. }
  2602. else if (target)
  2603. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  2604. if (search_client && search_client != this) {
  2605. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  2606. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  2607. if (search_client->GetCurrentZone() != GetCurrentZone())
  2608. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  2609. else {
  2610. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  2611. if (app)
  2612. search_client->QueuePacket(app);
  2613. }
  2614. }
  2615. }
  2616. if (!target)
  2617. return false;
  2618. else
  2619. return true;
  2620. }
  2621. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  2622. ZoneServer* instance_zone = NULL;
  2623. int8 instanceType = 0;
  2624. // determine if this is a group instanced zone that already exists
  2625. instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
  2626. if (instance_zone != NULL)
  2627. Zone(instance_zone->GetInstanceID(), zone_coords_valid, true);
  2628. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  2629. {
  2630. // best to check if we already have our own instance!
  2631. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  2632. if (data) {
  2633. // If lockout instances check to see if we are locked out
  2634. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  2635. int32 time = 0;
  2636. // Check success timer
  2637. if (data->last_success_timestamp > 0) {
  2638. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  2639. // Timer has not expired yet can't re enter
  2640. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  2641. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  2642. }
  2643. }
  2644. // Check failure timer
  2645. if (data->last_failure_timestamp > 0) {
  2646. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  2647. // Timer has not expired yet
  2648. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  2649. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  2650. }
  2651. }
  2652. // Time > 0 then we are locked out, make the message and send it and return true
  2653. if (time > 0) {
  2654. string time_msg = "";
  2655. int16 hour;
  2656. int8 min;
  2657. int8 sec;
  2658. hour = time / 3600;
  2659. time = time % 3600;
  2660. min = time / 60;
  2661. time = time % 60;
  2662. sec = time;
  2663. if (hour > 0) {
  2664. char temp[10];
  2665. sprintf(temp, " %i", hour);
  2666. time_msg.append(temp);
  2667. time_msg.append(" hour");
  2668. time_msg.append((hour > 1) ? "s" : "");
  2669. }
  2670. if (min > 0) {
  2671. char temp[5];
  2672. sprintf(temp, " %i", min);
  2673. time_msg.append(temp);
  2674. time_msg.append(" minute");
  2675. time_msg.append((min > 1) ? "s" : "");
  2676. }
  2677. // Only add seconds if minutes and hours are 0
  2678. if (hour == 0 && min == 0 && sec > 0) {
  2679. char temp[5];
  2680. sprintf(temp, " %i", sec);
  2681. time_msg.append(temp);
  2682. time_msg.append(" second");
  2683. time_msg.append((sec > 1) ? "s" : "");
  2684. }
  2685. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  2686. return true;
  2687. }
  2688. }
  2689. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  2690. instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID);
  2691. // if we got an instance_zone and the instance_id from the data is 0 or data instance id is not the same as the zone instance id then update values
  2692. if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
  2693. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  2694. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  2695. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  2696. }
  2697. else
  2698. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
  2699. data->instance_id = instance_zone->GetInstanceID();
  2700. }
  2701. }
  2702. else {
  2703. switch (instanceType)
  2704. {
  2705. case SOLO_LOCKOUT_INSTANCE:
  2706. case GROUP_LOCKOUT_INSTANCE:
  2707. case RAID_LOCKOUT_INSTANCE:
  2708. {
  2709. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  2710. if (instance_zone) {
  2711. // once lockout instance zone shuts down you can't renenter if you have a lockout or if you don't you get a new zone
  2712. // so delete `instances` entry for the zone when it shuts down.
  2713. int32 db_id = database.AddCharacterInstance(GetPlayer()->GetCharacterID(), instance_zone->GetInstanceID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceType(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime());
  2714. if (db_id > 0)
  2715. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  2716. }
  2717. break;
  2718. }
  2719. case SOLO_PERSIST_INSTANCE:
  2720. case GROUP_PERSIST_INSTANCE:
  2721. case RAID_PERSIST_INSTANCE:
  2722. {
  2723. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  2724. if (instance_zone) {
  2725. int32 db_id = database.AddCharacterInstance(GetPlayer()->GetCharacterID(), instance_zone->GetInstanceID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceType(), Timer::GetUnixTimeStamp(), 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime());
  2726. if (db_id > 0)
  2727. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), Timer::GetUnixTimeStamp(), 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  2728. }
  2729. break;
  2730. }
  2731. case PUBLIC_INSTANCE:
  2732. case TRADESKILL_INSTANCE:
  2733. {
  2734. // if its public/tradeskill, look for a public already setup
  2735. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  2736. if (instance_zone) {
  2737. // Check the current population against the max population, if greater or equal start a new version
  2738. if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
  2739. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  2740. }
  2741. else
  2742. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  2743. break;
  2744. }
  2745. case PERSONAL_HOUSE_INSTANCE:
  2746. case GUILD_HOUSE_INSTANCE:
  2747. {
  2748. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  2749. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  2750. // with the OP_EnterHouseMsg opcode
  2751. break;
  2752. }
  2753. case QUEST_INSTANCE:
  2754. {
  2755. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  2756. break;
  2757. /*
  2758. ALTER TABLE `zones` CHANGE COLUMN `instance_type` `instance_type` ENUM('NONE','GROUP_LOCKOUT_INSTANCE','GROUP_PERSIST_INSTANCE','RAID_LOCKOUT_INSTANCE','RAID_PERSIST_INSTANCE','SOLO_LOCKOUT_INSTANCE','SOLO_PERSIST_INSTANCE','TRADESKILL_INSTANCE','PUBLIC_INSTANCE','PERSONAL_HOUSE_INSTANCE','GUILD_HOUSE_INSTANCE','QUEST_INSTANCE') NOT NULL DEFAULT 'NONE' COLLATE 'latin1_general_ci' AFTER `start_zone`;
  2759. */
  2760. }
  2761. default:
  2762. {
  2763. // NONE
  2764. }
  2765. }
  2766. }
  2767. if (instance_zone != NULL)
  2768. Zone(instance_zone, zone_coords_valid);
  2769. }
  2770. if (instance_zone != NULL)
  2771. return true;
  2772. else
  2773. return false;
  2774. }
  2775. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  2776. Spawn* target = 0;
  2777. if (search_name || GetPlayer()->GetTarget()) {
  2778. Client* search_client = 0;
  2779. if (search_name) {
  2780. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  2781. if (!target) {
  2782. search_client = zone_list.GetClientByCharName(search_name);
  2783. if (search_client)
  2784. target = search_client->GetPlayer();
  2785. }
  2786. if (target)
  2787. GetPlayer()->SetTarget(target);
  2788. }
  2789. else
  2790. target = GetPlayer()->GetTarget();
  2791. if (target && target != GetPlayer()) {
  2792. GetPlayer()->SetX(target->GetX());
  2793. GetPlayer()->SetY(target->GetY());
  2794. GetPlayer()->SetZ(target->GetZ());
  2795. GetPlayer()->SetHeading(target->GetHeading());
  2796. GetPlayer()->SetLocation(target->GetLocation());
  2797. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  2798. }
  2799. else if (target)
  2800. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  2801. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  2802. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  2803. else if (target) {
  2804. EQ2Packet* app = GetPlayer()->Move(target->GetX(), target->GetY(), target->GetZ(), GetVersion());
  2805. if (app)
  2806. QueuePacket(app);
  2807. }
  2808. }
  2809. if (!target)
  2810. return false;
  2811. else
  2812. return true;
  2813. }
  2814. bool Client::CheckZoneAccess(const char* zoneName) {
  2815. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  2816. ZoneServer* zone = zone_list.Get(zoneName, false);
  2817. // JA: implemented /zone lock|unlock commands (2012.07.28)
  2818. if (zone && zone->GetZoneLockState())
  2819. {
  2820. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
  2821. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  2822. return false;
  2823. }
  2824. sint16 zoneMinStatus = 0;
  2825. int16 zoneMinLevel = 0;
  2826. int16 zoneMaxLevel = 0;
  2827. int16 zoneMinVersion = 0;
  2828. if (!zone)
  2829. {
  2830. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  2831. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  2832. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  2833. return true;
  2834. }
  2835. }
  2836. else
  2837. {
  2838. zoneMinStatus = zone->GetMinimumStatus();
  2839. zoneMinLevel = zone->GetMinimumLevel();
  2840. zoneMaxLevel = zone->GetMaximumLevel();
  2841. zoneMinVersion = zone->GetMinimumVersion();
  2842. }
  2843. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  2844. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  2845. sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  2846. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  2847. {
  2848. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  2849. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  2850. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  2851. return false;
  2852. }
  2853. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  2854. {
  2855. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  2856. {
  2857. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  2858. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  2859. return false;
  2860. }
  2861. }
  2862. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  2863. {
  2864. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  2865. {
  2866. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  2867. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  2868. return false;
  2869. }
  2870. }
  2871. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  2872. {
  2873. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  2874. sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  2875. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  2876. {
  2877. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  2878. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  2879. return false;
  2880. }
  2881. }
  2882. return true;
  2883. }
  2884. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID) {
  2885. Zone(zone_list.GetByInstanceID(instanceid), set_coords);
  2886. }
  2887. void Client::Zone(ZoneServer* new_zone, bool set_coords) {
  2888. if (!new_zone) {
  2889. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
  2890. return;
  2891. }
  2892. client_zoning = true;
  2893. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  2894. player->SetResurrecting(true);
  2895. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
  2896. //GetCurrentZone()->GetCombat()->RemoveHate(player);
  2897. // Remove players pet from zone if there is one
  2898. player->DismissPet((NPC*)player->GetPet());
  2899. player->DismissPet((NPC*)player->GetCharmedPet());
  2900. player->DismissPet((NPC*)player->GetDeityPet());
  2901. player->DismissPet((NPC*)player->GetCosmeticPet());
  2902. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  2903. GetCurrentZone()->RemoveSpawn(false, player, false);
  2904. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
  2905. SetCurrentZone(new_zone);
  2906. if (player->GetGroupMemberInfo())
  2907. {
  2908. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  2909. player->UpdateGroupMemberInfo();
  2910. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  2911. }
  2912. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  2913. if (set_coords)
  2914. {
  2915. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  2916. __FUNCTION__,
  2917. GetCurrentZone()->GetSafeX(),
  2918. GetCurrentZone()->GetSafeY(),
  2919. GetCurrentZone()->GetSafeZ(),
  2920. GetCurrentZone()->GetSafeHeading(),
  2921. new_zone->GetZoneName()
  2922. );
  2923. player->SetX(GetCurrentZone()->GetSafeX());
  2924. player->SetY(GetCurrentZone()->GetSafeY());
  2925. player->SetZ(GetCurrentZone()->GetSafeZ());
  2926. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  2927. }
  2928. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
  2929. Save();
  2930. char* new_zone_ip = 0;
  2931. struct in_addr in;
  2932. in.s_addr = this->GetIP();
  2933. if (strncmp(inet_ntoa(in), "192.168", 7) == 0 && strlen(net.GetInternalWorldAddress()) > 0)
  2934. new_zone_ip = net.GetInternalWorldAddress();
  2935. else
  2936. new_zone_ip = net.GetWorldAddress();
  2937. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  2938. int32 key = Timer::GetUnixTimeStamp();
  2939. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
  2940. ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
  2941. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  2942. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  2943. }
  2944. void Client::Zone(const char* new_zone, bool set_coords)
  2945. {
  2946. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  2947. Zone(zone_list.Get(new_zone), set_coords);
  2948. }
  2949. float Client::DistanceFrom(Client* client) {
  2950. float ret = 0;
  2951. if (client && client != this) {
  2952. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  2953. ret = sqrt(ret);
  2954. }
  2955. return ret;
  2956. }
  2957. void Client::DetermineCharacterUpdates() {
  2958. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  2959. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  2960. cdu->account_id = GetAccountID();
  2961. cdu->char_id = GetCharacterID();
  2962. int32 timestamp = Timer::GetUnixTimeStamp();
  2963. int8 flag = GetTimeStampFlag();
  2964. if (flag & LEVEL_UPDATE_FLAG)
  2965. {
  2966. cdu->update_field = LEVEL_UPDATE_FLAG;
  2967. cdu->update_data = player->GetLevel();
  2968. loginserver.SendPacket(outpack);
  2969. }
  2970. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  2971. if (flag & CLASS_UPDATE_FLAG)
  2972. {
  2973. cdu->update_field = CLASS_UPDATE_FLAG;
  2974. cdu->update_data = player->GetAdventureClass();
  2975. loginserver.SendPacket(outpack);
  2976. }
  2977. if (flag & GENDER_UPDATE_FLAG)
  2978. {
  2979. cdu->update_field = GENDER_UPDATE_FLAG;
  2980. cdu->update_data = player->GetGender();
  2981. loginserver.SendPacket(outpack);
  2982. }
  2983. if (flag & DELETE_UPDATE_FLAG) {
  2984. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  2985. }
  2986. safe_delete(outpack); // Zone, armor and name use a different structure
  2987. if (flag & RACE_UPDATE_FLAG)
  2988. {
  2989. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  2990. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  2991. ru->account_id = GetAccountID();
  2992. ru->char_id = GetCharacterID();
  2993. ru->race = player->GetRace();
  2994. ru->model_type = player->GetModelType();
  2995. loginserver.SendPacket(outpack);
  2996. safe_delete(outpack);
  2997. }
  2998. if (flag & ZONE_UPDATE_FLAG) {
  2999. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  3000. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  3001. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  3002. czu->account_id = GetAccountID();
  3003. czu->char_id = GetCharacterID();
  3004. czu->zone_id = GetCurrentZone()->GetZoneID();
  3005. const char* zone_file = GetCurrentZone()->GetZoneFile();
  3006. czu->zone_length = strlen(zone_file);
  3007. if (czu->zone_length > 64)
  3008. czu->zone_length = 64;
  3009. strncpy(czu->new_zone, zone_file, czu->zone_length);
  3010. loginserver.SendPacket(outpack);
  3011. safe_delete(outpack);
  3012. }
  3013. if (flag & ARMOR_UPDATE_FLAG) {
  3014. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3015. }
  3016. if (flag & NAME_UPDATE_FLAG) {
  3017. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3018. }
  3019. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  3020. }
  3021. void Client::Save() {
  3022. if (GetCharacterID() == 0)
  3023. return;
  3024. if (current_zone) {
  3025. DetermineCharacterUpdates();
  3026. UpdateCharacterInstances();
  3027. database.Save(this);
  3028. if (GetPlayer()->UpdateQuickbarNeeded()) {
  3029. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  3030. GetPlayer()->ResetQuickbarNeeded();
  3031. }
  3032. database.SaveItems(this);
  3033. database.SaveBuyBacks(this);
  3034. GetPlayer()->SaveHistory();
  3035. GetPlayer()->SaveLUAHistory();
  3036. }
  3037. }
  3038. void Client::UpdateCharacterInstances() {
  3039. if (GetPlayer() != NULL)
  3040. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  3041. /*if ( GetPlayer() != NULL )
  3042. {
  3043. // determine the last timestamp then get a new one, determine the difference in the timestamp
  3044. // to use for applying the update to each instances timer
  3045. int32 lastSaveTS = GetLastSavedTimeStamp();
  3046. int32 newSaveTS = Timer::GetUnixTimeStamp();
  3047. int32 diffTS = newSaveTS - lastSaveTS;
  3048. // update instance timers
  3049. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  3050. // update with the new timestamp and save the db
  3051. this->SetLastSavedTimeStamp(newSaveTS);
  3052. }*/
  3053. }
  3054. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  3055. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  3056. if (packet) {
  3057. packet->LoadPacketData(app->pBuffer, app->size);
  3058. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  3059. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  3060. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  3061. vector<EntityCommand*> commands;
  3062. vector<EntityCommand*> delete_commands;
  3063. if (out && spawn) {
  3064. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  3065. commands.push_back(spawn->primary_command_list[i]);
  3066. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  3067. commands.push_back(spawn->secondary_command_list[i]);
  3068. if (spawn->IsPlayer()) {
  3069. if (player->IsFriend(spawn->GetName()))
  3070. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  3071. else
  3072. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  3073. if (player->IsIgnored(spawn->GetName()))
  3074. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  3075. else
  3076. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  3077. if (((Player*)spawn)->GetGroupMemberInfo()) {
  3078. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  3079. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  3080. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  3081. }
  3082. }
  3083. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  3084. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  3085. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  3086. }
  3087. out->setDataByName("spawn_id", spawn_id);
  3088. out->setArrayLengthByName("num_verbs", commands.size());
  3089. for (int32 i = 0; i < commands.size(); i++) {
  3090. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  3091. out->setArrayDataByName("distance", commands[i]->distance, i);
  3092. if (commands[i]->error_text.length() == 0)
  3093. out->setArrayAddToPacketByName("error", false, i);
  3094. else {
  3095. out->setArrayDataByName("display_error", 1, i);
  3096. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  3097. }
  3098. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  3099. }
  3100. EQ2Packet* outapp = out->serialize();
  3101. //DumpPacket(outapp);
  3102. QueuePacket(outapp);
  3103. safe_delete(out);
  3104. for (int32 i = 0; i < delete_commands.size(); i++) {
  3105. safe_delete(delete_commands[i]);
  3106. }
  3107. }
  3108. safe_delete(packet);
  3109. }
  3110. }
  3111. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  3112. if (previous_value != new_value) {
  3113. Message(CHANNEL_COLOR_SKILL, "You get %s at %s (%i/%i).", new_value > previous_value ? "better" : "worse", skill->name.data.c_str(), new_value, skill->max_val);
  3114. char tmp[200] = { 0 };
  3115. sprintf(tmp, "\\#6EFF6EYou get %s at \12\\#C8FFC8%s\\#6EFF6E! (%i/%i)", new_value > previous_value ? "better" : "worse", skill->name.data.c_str(), new_value, skill->max_val);
  3116. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75, 0xFF, 0xFF, 0xFF);
  3117. }
  3118. }
  3119. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  3120. {
  3121. /* JA notes on the unknown:
  3122. 2 = ding glimmer
  3123. 16 = Achievement Unlocked
  3124. 6 no longer does anything
  3125. */
  3126. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  3127. if (packet) {
  3128. packet->setDataByName("unknown", unknown);
  3129. packet->setMediumStringByName("text", text);
  3130. if (type && strlen(type) > 0)
  3131. packet->setMediumStringByName("message_type", type);
  3132. packet->setDataByName("size", size);
  3133. packet->setDataByName("red", red);
  3134. packet->setDataByName("green", green);
  3135. packet->setDataByName("blue", blue);
  3136. QueuePacket(packet->serialize());
  3137. safe_delete(packet);
  3138. }
  3139. }
  3140. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  3141. if (new_level < 1) {
  3142. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  3143. return;
  3144. }
  3145. if (player->GetLevel() != new_level) {
  3146. player->SetLevel(new_level);
  3147. if (player->GetGroupMemberInfo()) {
  3148. player->UpdateGroupMemberInfo();
  3149. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  3150. }
  3151. }
  3152. if (new_level > old_level)
  3153. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  3154. if (player->GetPet()) {
  3155. NPC* pet = (NPC*)player->GetPet();
  3156. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  3157. pet->SetLevel(new_level);
  3158. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3159. if (command_packet) {
  3160. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  3161. command_packet->setDataByName("anim_type", 1753);
  3162. QueuePacket(command_packet->serialize());
  3163. safe_delete(command_packet);
  3164. }
  3165. }
  3166. }
  3167. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  3168. if (level_update) {
  3169. level_update->setDataByName("old_level", old_level);
  3170. level_update->setDataByName("new_level", new_level);
  3171. QueuePacket(level_update->serialize());
  3172. safe_delete(level_update);
  3173. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  3174. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  3175. }
  3176. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3177. if (command_packet) {
  3178. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  3179. command_packet->setDataByName("anim_type", 1753);
  3180. QueuePacket(command_packet->serialize());
  3181. safe_delete(command_packet);
  3182. }
  3183. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  3184. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  3185. SendNewSpells(player->GetAdventureClass());
  3186. SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  3187. SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  3188. GetPlayer()->ChangePrimaryWeapon();
  3189. GetPlayer()->ChangeSecondaryWeapon();
  3190. GetPlayer()->ChangeRangedWeapon();
  3191. GetPlayer()->GetInfoStruct()->level = new_level;
  3192. // GetPlayer()->SetLevel(new_level);
  3193. LogWrite(MISC__TODO, 1, "TODO", "Get new HP/POWER/stat based on default values from DB\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  3194. GetPlayer()->SetTotalHPBase(new_level * new_level * 2 + 40);
  3195. GetPlayer()->SetTotalPowerBase((sint32)(new_level * new_level * 2.1 + 45));
  3196. GetPlayer()->CalculateBonuses();
  3197. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  3198. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  3199. InfoStruct* info = player->GetInfoStruct();
  3200. info->agi_base = new_level * 2 + 15;
  3201. info->intel_base = new_level * 2 + 15;
  3202. info->wis_base = new_level * 2 + 15;
  3203. info->str_base = new_level * 2 + 15;
  3204. info->sta_base = new_level * 2 + 15;
  3205. info->cold_base = (int16)(new_level * 1.5 + 10);
  3206. info->heat_base = (int16)(new_level * 1.5 + 10);
  3207. info->disease_base = (int16)(new_level * 1.5 + 10);
  3208. info->mental_base = (int16)(new_level * 1.5 + 10);
  3209. info->magic_base = (int16)(new_level * 1.5 + 10);
  3210. info->divine_base = (int16)(new_level * 1.5 + 10);
  3211. info->poison_base = (int16)(new_level * 1.5 + 10);
  3212. GetPlayer()->SetHPRegen((int)(new_level * .75) + (int)(new_level / 10) + 3);
  3213. GetPlayer()->SetPowerRegen(new_level + (int)(new_level / 10) + 4);
  3214. GetPlayer()->GetInfoStruct()->poison_base = (int16)(new_level * 1.5 + 10);
  3215. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  3216. GetPlayer()->SetCharSheetChanged(true);
  3217. Message(CHANNEL_COLOR_EXP, "You are now level %i!", new_level);
  3218. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  3219. int16 new_skill_cap = 5 * new_level;
  3220. PlayerSkillList* player_skills = player->GetSkills();
  3221. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  3222. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  3223. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  3224. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  3225. if (new_level > player->GetTSLevel())
  3226. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  3227. Guild* guild = GetPlayer()->GetGuild();
  3228. if (guild) {
  3229. int8 event_type = 0;
  3230. if (new_level < 10)
  3231. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  3232. else if (new_level == 10)
  3233. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  3234. else if (new_level >= 11 && new_level < 20)
  3235. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  3236. else if (new_level == 20)
  3237. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  3238. else if (new_level >= 21 && new_level < 30)
  3239. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  3240. else if (new_level == 30)
  3241. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  3242. else if (new_level >= 31 && new_level < 40)
  3243. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  3244. else if (new_level == 40)
  3245. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  3246. else if (new_level >= 41 && new_level < 50)
  3247. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  3248. else if (new_level == 50)
  3249. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  3250. else if (new_level >= 51 && new_level < 60)
  3251. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  3252. else if (new_level == 60)
  3253. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  3254. else if (new_level >= 61 && new_level < 70)
  3255. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  3256. else if (new_level == 70)
  3257. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  3258. else if (new_level >= 71 && new_level < 80)
  3259. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  3260. else if (new_level == 80)
  3261. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  3262. guild->AddNewGuildEvent(event_type, "%s has gained an adventure level and is now a level %u %s.", Timer::GetUnixTimeStamp(), true, GetPlayer()->GetName(), new_level, classes.GetClassNameCase(GetPlayer()->GetAdventureClass()).c_str());
  3263. guild->SendMessageToGuild(event_type, "%s has gained an adventure level and is now a level %u %s.", GetPlayer()->GetName(), new_level, classes.GetClassNameCase(GetPlayer()->GetAdventureClass()).c_str());
  3264. guild->UpdateGuildMemberInfo(GetPlayer());
  3265. guild->SendGuildMember(GetPlayer());
  3266. guild->SendGuildMemberList();
  3267. }
  3268. // Need to send the trait list every time the players level changes
  3269. // Also need to force the char sheet update or else there can be a large delay from when you level
  3270. // to when you are actually able to select traits.
  3271. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  3272. QueuePacket(master_trait_list.GetTraitListPacket(this));
  3273. master_aa_list.DisplayAA(this, 0, 0);
  3274. if (GetPlayer()->SpawnedBots.size() > 0) {
  3275. map<int32, int32>::iterator itr;
  3276. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  3277. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  3278. if (bot && bot->IsBot())
  3279. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  3280. }
  3281. }
  3282. }
  3283. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  3284. if (new_level < 1) {
  3285. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  3286. return;
  3287. }
  3288. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  3289. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  3290. return;
  3291. }
  3292. if (new_level > old_level)
  3293. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  3294. if (player->GetTSLevel() != new_level) {
  3295. player->SetTSLevel(new_level);
  3296. if (player->GetGroupMemberInfo()) {
  3297. player->UpdateGroupMemberInfo();
  3298. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  3299. }
  3300. }
  3301. // Only tradeskill skills should increace, and then only those related to your class
  3302. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  3303. if (level_update) {
  3304. level_update->setDataByName("old_level", old_level);
  3305. level_update->setDataByName("new_level", new_level);
  3306. level_update->setDataByName("type", 1);
  3307. QueuePacket(level_update->serialize());
  3308. safe_delete(level_update);
  3309. }
  3310. // Need to make tradeskill versions of the following
  3311. //SendNewSpells(player->GetAdventureClass());
  3312. //SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  3313. //SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  3314. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3315. if (command_packet) {
  3316. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  3317. command_packet->setDataByName("anim_type", 1753);
  3318. QueuePacket(command_packet->serialize());
  3319. safe_delete(command_packet);
  3320. }
  3321. GetPlayer()->GetInfoStruct()->tradeskill_level = new_level;
  3322. GetPlayer()->SetTSLevel(new_level);
  3323. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  3324. GetPlayer()->SetCharSheetChanged(true);
  3325. Message(CHANNEL_COLOR_WHITE, "Your tradeskill level is now %i!", new_level);
  3326. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  3327. PlayerSkillList* player_skills = player->GetSkills();
  3328. int16 specialize_skill_cap = new_level * 5;
  3329. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  3330. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  3331. int8 ts_class = player->GetTradeskillClass();
  3332. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  3333. int32 skill_id_1, skill_id_2, skill_id_3;
  3334. switch (base_ts_class) {
  3335. case ARTISAN:
  3336. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  3337. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  3338. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  3339. break;
  3340. case OUTFITTER:
  3341. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  3342. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  3343. skill_id_1 = SKILL_ID_TAILORING;
  3344. skill_id_2 = SKILL_ID_METALSHAPING;
  3345. skill_id_3 = SKILL_ID_METALWORKING;
  3346. if (ts_class == TAILOR) {
  3347. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  3348. skill_id_1 = 0;
  3349. }
  3350. else if (ts_class == ARMORER) {
  3351. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  3352. skill_id_2 = 0;
  3353. }
  3354. else if (ts_class == WEAPONSMITH) {
  3355. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  3356. skill_id_3 = 0;
  3357. }
  3358. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  3359. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  3360. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  3361. break;
  3362. case SCHOLAR:
  3363. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  3364. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  3365. skill_id_1 = SKILL_ID_SCRIBING;
  3366. skill_id_2 = SKILL_ID_CHEMISTRY;
  3367. skill_id_3 = SKILL_ID_ARTIFICING;
  3368. if (ts_class == SAGE) {
  3369. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  3370. skill_id_1 = 0;
  3371. }
  3372. else if (ts_class == ALCHEMIST) {
  3373. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  3374. skill_id_2 = 0;
  3375. }
  3376. else if (ts_class == JEWELER) {
  3377. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  3378. skill_id_3 = 0;
  3379. }
  3380. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  3381. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  3382. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  3383. break;
  3384. case CRAFTSMAN:
  3385. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  3386. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  3387. skill_id_1 = SKILL_ID_ARTISTRY;
  3388. skill_id_2 = SKILL_ID_FLETCHING;
  3389. skill_id_3 = SKILL_ID_SCULPTING;
  3390. if (ts_class == PROVISIONER) {
  3391. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  3392. skill_id_1 = 0;
  3393. }
  3394. else if (ts_class == WOODWORKER) {
  3395. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  3396. skill_id_2 = 0;
  3397. }
  3398. else if (ts_class == CARPENTER) {
  3399. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  3400. skill_id_3 = 0;
  3401. }
  3402. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  3403. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  3404. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  3405. break;
  3406. default:
  3407. break;
  3408. }
  3409. if (new_level > player->GetAdventureClass())
  3410. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  3411. Guild* guild = GetPlayer()->GetGuild();
  3412. if (guild) {
  3413. int8 event_type = 0;
  3414. if (new_level < 10)
  3415. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  3416. else if (new_level == 10)
  3417. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  3418. else if (new_level >= 11 && new_level < 20)
  3419. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  3420. else if (new_level == 20)
  3421. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  3422. else if (new_level >= 21 && new_level < 30)
  3423. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  3424. else if (new_level == 30)
  3425. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  3426. else if (new_level >= 31 && new_level < 40)
  3427. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  3428. else if (new_level == 40)
  3429. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  3430. else if (new_level >= 41 && new_level < 50)
  3431. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  3432. else if (new_level == 50)
  3433. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  3434. else if (new_level >= 51 && new_level < 60)
  3435. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  3436. else if (new_level == 60)
  3437. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  3438. else if (new_level >= 61 && new_level < 70)
  3439. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  3440. else if (new_level == 70)
  3441. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  3442. else if (new_level >= 71 && new_level < 80)
  3443. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  3444. else if (new_level == 80)
  3445. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  3446. guild->AddNewGuildEvent(event_type, "%s has gained a tradeskill level and is now a level %u %s.", Timer::GetUnixTimeStamp(), true, GetPlayer()->GetName(), new_level, classes.GetClassNameCase(GetPlayer()->GetTradeskillClass() + 42).c_str());
  3447. guild->SendMessageToGuild(event_type, "%s has gained a tradeskill level and is now a level %u %s.", GetPlayer()->GetName(), new_level, classes.GetClassNameCase(GetPlayer()->GetTradeskillClass() + 42).c_str());
  3448. guild->UpdateGuildMemberInfo(GetPlayer());
  3449. guild->SendGuildMember(GetPlayer());
  3450. guild->SendGuildMemberList();
  3451. }
  3452. // Need to send the trait list every time the players level changes
  3453. // Also need to force the char sheet update or else there can be a large delay from when you level
  3454. // to when you are actually able to select traits.
  3455. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  3456. QueuePacket(master_trait_list.GetTraitListPacket(this));
  3457. }
  3458. void Client::SendPendingLoot(int32 total_coins, Entity* entity) {
  3459. if (entity)
  3460. Loot(total_coins, player->GetPendingLootItems(entity->GetID()), entity);
  3461. }
  3462. void Client::CloseLoot() {
  3463. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  3464. packet->setDataByName("window_id", 4);
  3465. EQ2Packet* outapp = packet->serialize();
  3466. //DumpPacket(outapp);
  3467. QueuePacket(outapp);
  3468. safe_delete(packet);
  3469. }
  3470. string Client::GetCoinMessage(int32 total_coins) {
  3471. if (total_coins == 0) {
  3472. return " 0 Copper";
  3473. }
  3474. char tmp[64] = { 0 };
  3475. string message = "";
  3476. int32 val = 0;
  3477. if (total_coins >= 1000000) {
  3478. val = total_coins / 1000000;
  3479. total_coins -= 1000000 * val;
  3480. sprintf(tmp, " %u Platinum", val);
  3481. message.append(tmp);
  3482. memset(tmp, 0, 64);
  3483. }
  3484. if (total_coins >= 10000) {
  3485. val = total_coins / 10000;
  3486. total_coins -= 10000 * val;
  3487. sprintf(tmp, " %u Gold", val);
  3488. message.append(tmp);
  3489. memset(tmp, 0, 64);
  3490. }
  3491. if (total_coins >= 100) {
  3492. val = total_coins / 100;
  3493. total_coins -= 100 * val;
  3494. sprintf(tmp, " %u Silver", val);
  3495. message.append(tmp);
  3496. memset(tmp, 0, 64);
  3497. }
  3498. if (total_coins > 0) {
  3499. sprintf(tmp, " %u Copper", (int32)total_coins);
  3500. message.append(tmp);
  3501. }
  3502. return message;
  3503. }
  3504. void Client::Loot(int32 total_coins, vector<Item*>* items, Entity* entity) {
  3505. if (!entity) {
  3506. CloseLoot();
  3507. return;
  3508. }
  3509. if (total_coins > 0) {
  3510. player->AddCoins(total_coins);
  3511. //PlaySound("coin_cha_ching");
  3512. string message = "";
  3513. if (entity->GetHP() == 0) {
  3514. message = "You loot ";
  3515. entity->SetLootCoins(0);
  3516. }
  3517. else
  3518. message = "You receive ";
  3519. message.append(GetCoinMessage(total_coins));
  3520. if (entity->GetHP() == 0)
  3521. message.append(" from the corpse of ").append(entity->GetName());
  3522. int8 type = CHANNEL_COLOR_LOOT;
  3523. if (GetVersion() >= 1208)
  3524. type = CHANNEL_LOOT;
  3525. else if (GetVersion() >= 973)
  3526. type = CHANNEL_COLOR_NEW_LOOT;
  3527. SimpleMessage(type, message.c_str());
  3528. }
  3529. if (!items || items->size() == 0)
  3530. CloseLoot();
  3531. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  3532. if (packet) {
  3533. vector<Item*>::iterator itr;
  3534. int32 packet_size = 0;
  3535. if (items && items->size() > 0) {
  3536. packet->setDataByName("loot_count", items->size());
  3537. packet->setDataByName("display", 1);
  3538. }
  3539. packet->setDataByName("unknown2", 1);
  3540. if (version >= 1096)
  3541. packet->setDataByName("unknown3", 0x78);
  3542. else
  3543. packet->setDataByName("unknown3", 0x3C);
  3544. packet->setDataByName("loot_id", entity->GetID());
  3545. EQ2Packet* tmpPacket = packet->serialize();
  3546. packet_size += tmpPacket->size;
  3547. uchar* data = 0;
  3548. if (items && items->size() > 0) {
  3549. data = new uchar[items->size() * 1000 + packet_size];
  3550. memset(data, 0, items->size() * 1000 + packet_size);
  3551. }
  3552. else {
  3553. data = new uchar[packet_size];
  3554. memset(data, 0, packet_size);
  3555. }
  3556. uchar* ptr = data;
  3557. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  3558. ptr += tmpPacket->size;
  3559. safe_delete(tmpPacket);
  3560. Item* item = 0;
  3561. if (items && items->size() > 0) {
  3562. for (itr = items->begin(); itr != items->end(); itr++) {
  3563. item = *itr;
  3564. memcpy(ptr, &item->details.item_id, sizeof(int32));
  3565. ptr += sizeof(int32);
  3566. packet_size += sizeof(int32);
  3567. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  3568. int8 offset = 0;
  3569. if (GetVersion() >= 1188) {
  3570. offset = 13;
  3571. }
  3572. else if (GetVersion() >= 860) {
  3573. offset = 11;
  3574. }
  3575. else {
  3576. offset = 10;
  3577. }
  3578. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  3579. ptr += tmpPacket->size - offset;
  3580. packet_size += tmpPacket->size - offset;
  3581. safe_delete(tmpPacket);
  3582. }
  3583. }
  3584. packet_size -= sizeof(int32);
  3585. memcpy(data, &packet_size, sizeof(int32));
  3586. packet_size += sizeof(int32);
  3587. EQ2Packet* outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  3588. //DumpPacket(outapp);
  3589. QueuePacket(outapp);
  3590. safe_delete_array(data);
  3591. safe_delete(packet);
  3592. }
  3593. }
  3594. void Client::Loot(Entity* entity, bool attemptDisarm) {
  3595. if (entity->IsNPC() && ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  3596. int32 total_coins = entity->GetLootCoins();
  3597. entity->LockLoot();
  3598. Loot(total_coins, entity->GetLootItems(), entity);
  3599. entity->UnlockLoot();
  3600. OpenChest(entity, attemptDisarm);
  3601. }
  3602. else
  3603. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  3604. }
  3605. void Client::OpenChest(Entity* entity, bool attemptDisarm)
  3606. {
  3607. if (!entity)
  3608. return;
  3609. int8 chest_difficulty = 0;
  3610. int32 state = 0;
  3611. // Check for the chest and set the action state
  3612. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  3613. string modelName;
  3614. if (entity->GetModelType() == 4034) {
  3615. // small chest, open with copper coins
  3616. // does not include traps, however can be disarmed
  3617. chest_difficulty = 1;
  3618. state = 11899;
  3619. modelName.append("Small Chest");
  3620. }
  3621. else if (entity->GetModelType() == 5864) {
  3622. // treasure chest, open with silver coins
  3623. chest_difficulty = 2;
  3624. state = 11901;
  3625. modelName.append("Treasure Chest");
  3626. }
  3627. else if (entity->GetModelType() == 5865) {
  3628. // ornate chest, open with gold coins
  3629. chest_difficulty = 3;
  3630. state = 11900;
  3631. modelName.append("Ornate Chest");
  3632. }
  3633. else if (entity->GetModelType() == 4015) {
  3634. // exquisite chest, open with gold coins and jewels as well as a glow effect
  3635. chest_difficulty = 5;
  3636. state = 11898;
  3637. modelName.append("Exquisite Chest");
  3638. }
  3639. bool firstChestOpen = false;
  3640. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  3641. {
  3642. ChestTrap::ChestTrapInfo nextTrap;
  3643. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  3644. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  3645. firstChestOpen = true;
  3646. entity->SetTrapTriggered(true);
  3647. if (ret)
  3648. {
  3649. if (disarmSkill && attemptDisarm)
  3650. {
  3651. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  3652. {
  3653. CastGroupOrSelf(entity, nextTrap.spell_id, nextTrap.spell_tier,
  3654. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  3655. Message(CHANNEL_COLOR_WHITE, "You trigger the trap on %s!", modelName.c_str());
  3656. }
  3657. else
  3658. {
  3659. Message(CHANNEL_COLOR_WHITE, "You disarm the trap on %s", modelName.c_str());
  3660. }
  3661. // despite fail/succeed we should always try to increase skill if disarm is available
  3662. GetPlayer()->GetSkillByName("Disarm Trap", true);
  3663. }
  3664. else // no disarm skill, always fail
  3665. {
  3666. CastGroupOrSelf(entity, nextTrap.spell_id, nextTrap.spell_tier,
  3667. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  3668. Message(CHANNEL_COLOR_WHITE, "You trigger the trap on %s!", modelName.c_str());
  3669. }
  3670. }
  3671. }
  3672. else if (!entity->HasTrapTriggered())
  3673. {
  3674. firstChestOpen = true;
  3675. entity->SetTrapTriggered(true);
  3676. }
  3677. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  3678. // for those in range the SendStateCommand will cause it to animate open.
  3679. // TODO: when player enters radius that does not have visual state, update visual state
  3680. if (firstChestOpen)
  3681. entity->SetVisualState(state, false);
  3682. GetCurrentZone()->SendStateCommand(entity, state);
  3683. }
  3684. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  3685. {
  3686. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  3687. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  3688. if (source == NULL)
  3689. source = (Entity*)GetPlayer();
  3690. if (spell)
  3691. {
  3692. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  3693. if (gmi && gmi->group_id)
  3694. {
  3695. deque<GroupMemberInfo*>* members = world.GetGroupManager()->GetGroupMembers(gmi->group_id);
  3696. for (int8 i = 0; i < members->size(); i++) {
  3697. Entity* member = members->at(i)->member;
  3698. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  3699. continue;
  3700. // if we have a radius provided then check if the group member is outside the radius or not
  3701. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  3702. continue;
  3703. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  3704. }
  3705. }
  3706. else
  3707. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  3708. }
  3709. }
  3710. Spawn* Client::GetBanker() {
  3711. return banker;
  3712. }
  3713. void Client::SetBanker(Spawn* in_banker) {
  3714. banker = in_banker;
  3715. }
  3716. void Client::Bank(Spawn* banker, bool cancel) {
  3717. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  3718. if (!cancel)
  3719. SetBanker(banker);
  3720. else
  3721. SetBanker(0);
  3722. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  3723. if (packet) {
  3724. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  3725. int64 coins = GetPlayer()->GetInfoStruct()->bank_coin_copper + GetPlayer()->GetInfoStruct()->bank_coin_silver * 100 +
  3726. GetPlayer()->GetInfoStruct()->bank_coin_gold * 10000 + (int64)GetPlayer()->GetInfoStruct()->bank_coin_plat * 1000000;
  3727. int32 coins1, coins2;
  3728. coins1 = ((int32*)&coins)[0];
  3729. coins2 = ((int32*)&coins)[1];
  3730. packet->setDataByName("bank_coins", coins1);
  3731. packet->setDataByName("bank_coins2", coins2);
  3732. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->coin_copper);
  3733. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->coin_silver);
  3734. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->coin_gold);
  3735. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->coin_plat);
  3736. if (!cancel)
  3737. packet->setDataByName("display", 1);
  3738. QueuePacket(packet->serialize());
  3739. safe_delete(packet);
  3740. }
  3741. }
  3742. }
  3743. void Client::BankWithdrawal(int64 amount) {
  3744. bool cheater = false;
  3745. if (GetBanker() && amount > 0) {
  3746. string withdrawal = "";
  3747. char withdrawal_data[512] = { 0 };
  3748. int32 tmp = 0;
  3749. if (amount >= 1000000) {
  3750. tmp = amount / 1000000;
  3751. if (tmp > GetPlayer()->GetBankCoinsPlat())
  3752. cheater = true;
  3753. else {
  3754. GetPlayer()->GetInfoStruct()->bank_coin_plat -= tmp;
  3755. GetPlayer()->GetInfoStruct()->coin_plat += tmp;
  3756. amount -= (int64)tmp * 1000000;
  3757. sprintf(withdrawal_data, "%u Platinum ", tmp);
  3758. withdrawal.append(withdrawal_data);
  3759. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  3760. }
  3761. }
  3762. if (!cheater && amount >= 10000) {
  3763. tmp = amount / 10000;
  3764. if (tmp > GetPlayer()->GetBankCoinsGold())
  3765. cheater = true;
  3766. else {
  3767. GetPlayer()->GetInfoStruct()->bank_coin_gold -= tmp;
  3768. if ((GetPlayer()->GetInfoStruct()->coin_gold + tmp) > 100) {
  3769. GetPlayer()->GetInfoStruct()->coin_gold = (GetPlayer()->GetInfoStruct()->coin_gold + tmp) - 100;
  3770. GetPlayer()->GetInfoStruct()->coin_plat += 1;
  3771. }
  3772. else
  3773. GetPlayer()->GetInfoStruct()->coin_gold += tmp;
  3774. amount -= tmp * 10000;
  3775. sprintf(withdrawal_data, "%u Gold ", tmp);
  3776. withdrawal.append(withdrawal_data);
  3777. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  3778. }
  3779. }
  3780. if (!cheater && amount >= 100) {
  3781. tmp = amount / 100;
  3782. if (tmp > GetPlayer()->GetBankCoinsSilver())
  3783. cheater = true;
  3784. else {
  3785. GetPlayer()->GetInfoStruct()->bank_coin_silver -= tmp;
  3786. if ((GetPlayer()->GetInfoStruct()->coin_silver + tmp) > 100) {
  3787. GetPlayer()->GetInfoStruct()->coin_silver = (GetPlayer()->GetInfoStruct()->coin_silver + tmp) - 100;
  3788. GetPlayer()->GetInfoStruct()->coin_gold += 1;
  3789. }
  3790. else
  3791. GetPlayer()->GetInfoStruct()->coin_silver += tmp;
  3792. amount -= tmp * 100;
  3793. sprintf(withdrawal_data, "%u Silver ", tmp);
  3794. withdrawal.append(withdrawal_data);
  3795. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  3796. }
  3797. }
  3798. if (!cheater) {
  3799. if (amount > 0) {
  3800. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  3801. withdrawal.append(withdrawal_data);
  3802. GetPlayer()->GetInfoStruct()->bank_coin_copper -= amount;
  3803. if ((GetPlayer()->GetInfoStruct()->coin_copper + amount) > 100) {
  3804. GetPlayer()->GetInfoStruct()->coin_copper = (GetPlayer()->GetInfoStruct()->coin_copper + amount) - 100;
  3805. GetPlayer()->GetInfoStruct()->coin_silver += 1;
  3806. }
  3807. else
  3808. GetPlayer()->GetInfoStruct()->coin_copper += amount;
  3809. }
  3810. if (withdrawal.length() > 0) {
  3811. withdrawal.append("withdrawn ");
  3812. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->bank_coin_plat,
  3813. GetPlayer()->GetInfoStruct()->bank_coin_gold, GetPlayer()->GetInfoStruct()->bank_coin_silver, GetPlayer()->GetInfoStruct()->bank_coin_copper);
  3814. withdrawal.append(withdrawal_data);
  3815. SimpleMessage(CHANNEL_COLOR_REVIVE, withdrawal.c_str());
  3816. }
  3817. }
  3818. else
  3819. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  3820. player->SetCharSheetChanged(true);
  3821. Bank(banker);
  3822. }
  3823. }
  3824. void Client::BankDeposit(int64 amount) {
  3825. bool cheater = false;
  3826. if (GetBanker() && amount > 0) {
  3827. int32 tmp = 0;
  3828. char deposit_data[512] = { 0 };
  3829. string deposit = "";
  3830. if (amount >= 1000000) {
  3831. tmp = amount / 1000000;
  3832. if (tmp > GetPlayer()->GetCoinsPlat())
  3833. cheater = true;
  3834. else {
  3835. GetPlayer()->GetInfoStruct()->bank_coin_plat += tmp;
  3836. GetPlayer()->GetInfoStruct()->coin_plat -= tmp;
  3837. amount -= (int64)tmp * 1000000;
  3838. sprintf(deposit_data, "%u Platinum ", tmp);
  3839. deposit.append(deposit_data);
  3840. memset(deposit_data, 0, sizeof(deposit_data));
  3841. }
  3842. }
  3843. if (!cheater && amount >= 10000) {
  3844. tmp = amount / 10000;
  3845. if (tmp > GetPlayer()->GetCoinsGold())
  3846. cheater = true;
  3847. else {
  3848. if ((GetPlayer()->GetInfoStruct()->bank_coin_gold + tmp) > 100) {
  3849. GetPlayer()->GetInfoStruct()->bank_coin_gold = (GetPlayer()->GetInfoStruct()->bank_coin_gold + tmp) - 100;
  3850. GetPlayer()->GetInfoStruct()->bank_coin_plat += 1;
  3851. }
  3852. else
  3853. GetPlayer()->GetInfoStruct()->bank_coin_gold += tmp;
  3854. GetPlayer()->GetInfoStruct()->coin_gold -= tmp;
  3855. amount -= tmp * 10000;
  3856. sprintf(deposit_data, "%u Gold ", tmp);
  3857. deposit.append(deposit_data);
  3858. memset(deposit_data, 0, sizeof(deposit_data));
  3859. }
  3860. }
  3861. if (!cheater && amount >= 100) {
  3862. tmp = amount / 100;
  3863. if (tmp > GetPlayer()->GetCoinsSilver())
  3864. cheater = true;
  3865. else {
  3866. if ((GetPlayer()->GetInfoStruct()->bank_coin_silver + tmp) > 100) {
  3867. GetPlayer()->GetInfoStruct()->bank_coin_silver = (GetPlayer()->GetInfoStruct()->bank_coin_silver + tmp) - 100;
  3868. GetPlayer()->GetInfoStruct()->bank_coin_gold += 1;
  3869. }
  3870. else
  3871. GetPlayer()->GetInfoStruct()->bank_coin_silver += tmp;
  3872. GetPlayer()->GetInfoStruct()->coin_silver -= tmp;
  3873. amount -= tmp * 100;
  3874. sprintf(deposit_data, "%u Silver ", tmp);
  3875. deposit.append(deposit_data);
  3876. memset(deposit_data, 0, sizeof(deposit_data));
  3877. }
  3878. }
  3879. if (!cheater) {
  3880. if (amount > 0) {
  3881. sprintf(deposit_data, "%u Copper ", (int32)amount);
  3882. deposit.append(deposit_data);
  3883. if ((GetPlayer()->GetInfoStruct()->bank_coin_copper + amount) > 100) {
  3884. GetPlayer()->GetInfoStruct()->bank_coin_copper = (GetPlayer()->GetInfoStruct()->bank_coin_copper + amount) - 100;
  3885. GetPlayer()->GetInfoStruct()->bank_coin_silver += 1;
  3886. }
  3887. else
  3888. GetPlayer()->GetInfoStruct()->bank_coin_copper += amount;
  3889. GetPlayer()->GetInfoStruct()->coin_copper -= amount;
  3890. }
  3891. if (deposit.length() > 0) {
  3892. deposit.append("deposited ");
  3893. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->bank_coin_plat,
  3894. GetPlayer()->GetInfoStruct()->bank_coin_gold, GetPlayer()->GetInfoStruct()->bank_coin_silver, GetPlayer()->GetInfoStruct()->bank_coin_copper);
  3895. deposit.append(deposit_data);
  3896. SimpleMessage(CHANNEL_COLOR_REVIVE, deposit.c_str());
  3897. }
  3898. }
  3899. else
  3900. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  3901. player->SetCharSheetChanged(true);
  3902. Bank(banker);
  3903. }
  3904. }
  3905. void Client::AddPendingQuestReward(Quest* quest) {
  3906. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  3907. quest_pending_reward.push_back(quest);
  3908. quest_updates = true;
  3909. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  3910. }
  3911. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  3912. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  3913. quest_pending_updates[quest_id][step_id] = progress;
  3914. quest_updates = true;
  3915. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  3916. }
  3917. void Client::ProcessQuestUpdates() {
  3918. if (quest_pending_updates.size() > 0) {
  3919. map<int32, map<int32, int32> > tmp_quest_updates;
  3920. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  3921. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  3922. quest_pending_updates.clear();
  3923. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  3924. map<int32, map<int32, int32> >::iterator quest_itr;
  3925. map<int32, int32>::iterator step_itr;
  3926. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  3927. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  3928. if (step_itr->second == 0xFFFFFFFF) {
  3929. SetStepComplete(quest_itr->first, step_itr->first);
  3930. player->SendQuestRequiredSpawns(quest_itr->first);
  3931. }
  3932. else
  3933. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  3934. }
  3935. }
  3936. }
  3937. if (quest_pending_reward.size() > 0) {
  3938. vector<Quest*>::iterator itr;
  3939. vector<Quest*> tmp_quest_rewards;
  3940. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  3941. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.end());
  3942. quest_pending_reward.clear();
  3943. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  3944. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end(); itr++) {
  3945. GiveQuestReward(*itr);
  3946. }
  3947. }
  3948. quest_updates = false;
  3949. }
  3950. void Client::CheckQuestQueue() {
  3951. MQuestQueue.writelock();
  3952. last_update_time = 0;
  3953. vector<QueuedQuest*>::iterator itr;
  3954. QueuedQuest* queued_quest = 0;
  3955. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  3956. queued_quest = *itr;
  3957. SendQuestUpdateStepImmediately(queued_quest->quest, queued_quest->step, queued_quest->display_quest_helper);
  3958. safe_delete(queued_quest);
  3959. }
  3960. quest_queue.clear();
  3961. MQuestQueue.releasewritelock();
  3962. }
  3963. void Client::SetStepComplete(int32 quest_id, int32 step) {
  3964. Quest* quest = player->SetStepComplete(quest_id, step);
  3965. if (quest) {
  3966. SendQuestUpdate(quest);
  3967. GetCurrentZone()->SendQuestUpdates(this);
  3968. }
  3969. }
  3970. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  3971. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  3972. if (quest) {
  3973. SendQuestUpdate(quest);
  3974. GetCurrentZone()->SendQuestUpdates(this);
  3975. }
  3976. }
  3977. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  3978. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  3979. if (quest_updates) {
  3980. for (int32 i = 0; i < quest_updates->size(); i++)
  3981. SendQuestUpdate(quest_updates->at(i));
  3982. }
  3983. safe_delete(quest_updates);
  3984. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  3985. if (quest_failures) {
  3986. for (int32 i = 0; i < quest_failures->size(); i++)
  3987. SendQuestFailure(quest_failures->at(i));
  3988. }
  3989. safe_delete(quest_failures);
  3990. }
  3991. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  3992. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  3993. if (quest_updates) {
  3994. for (int32 i = 0; i < quest_updates->size(); i++)
  3995. SendQuestUpdate(quest_updates->at(i));
  3996. GetCurrentZone()->SendQuestUpdates(this);
  3997. }
  3998. safe_delete(quest_updates);
  3999. }
  4000. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  4001. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  4002. if (quest_updates) {
  4003. for (int32 i = 0; i < quest_updates->size(); i++)
  4004. SendQuestUpdate(quest_updates->at(i));
  4005. }
  4006. safe_delete(quest_updates);
  4007. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4008. if (quest_failures) {
  4009. for (int32 i = 0; i < quest_failures->size(); i++)
  4010. SendQuestFailure(quest_failures->at(i));
  4011. }
  4012. safe_delete(quest_failures);
  4013. }
  4014. void Client::CheckPlayerQuestsLocationUpdate() {
  4015. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  4016. if (quest_updates) {
  4017. for (int32 i = 0; i < quest_updates->size(); i++)
  4018. SendQuestUpdate(quest_updates->at(i));
  4019. }
  4020. safe_delete(quest_updates);
  4021. }
  4022. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  4023. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  4024. if (quest_updates) {
  4025. for (int32 i = 0; i < quest_updates->size(); i++)
  4026. SendQuestUpdate(quest_updates->at(i));
  4027. }
  4028. safe_delete(quest_updates);
  4029. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4030. if (quest_failures) {
  4031. for (int32 i = 0; i < quest_failures->size(); i++)
  4032. SendQuestFailure(quest_failures->at(i));
  4033. }
  4034. safe_delete(quest_failures);
  4035. }
  4036. void Client::AddPendingQuest(Quest* quest) {
  4037. player->pending_quests[quest->GetQuestID()] = quest;
  4038. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  4039. //DumpPacket(outapp);
  4040. QueuePacket(outapp);
  4041. }
  4042. Quest* Client::GetActiveQuest(int32 quest_id) {
  4043. if (player->player_quests.count(quest_id) > 0) {
  4044. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u active quests for char_id: %u", player->player_quests.count(quest_id), player->GetCharacterID());
  4045. return player->player_quests[quest_id];
  4046. }
  4047. return 0;
  4048. }
  4049. Quest* Client::GetPendingQuest(int32 id) {
  4050. if (player->pending_quests.count(id) > 0) {
  4051. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u pending quests for char_id: %u", player->pending_quests.count(id), player->GetCharacterID());
  4052. return player->pending_quests[id];
  4053. }
  4054. return 0;
  4055. }
  4056. void Client::RemovePendingQuest(Quest* quest) {
  4057. player->pending_quests.erase(quest->GetQuestID());
  4058. }
  4059. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  4060. if (!quest || !progress) {
  4061. return;
  4062. }
  4063. map<int32, int32>::iterator itr;
  4064. QuestStep* step = 0;
  4065. player->SetZone(GetCurrentZone());
  4066. for (itr = progress->begin(); itr != progress->end(); itr++) {
  4067. step = quest->GetQuestStep(itr->first);
  4068. if (step && itr->second > 0) {
  4069. step->SetStepProgress(itr->second);
  4070. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  4071. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  4072. }
  4073. }
  4074. }
  4075. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  4076. if (player->player_quests.count(quest->GetQuestID()) > 0) {
  4077. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  4078. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  4079. RemovePlayerQuest(quest->GetQuestID(), false, false);
  4080. }
  4081. player->player_quests[quest->GetQuestID()] = quest;
  4082. quest->SetPlayer(player);
  4083. current_quest_id = quest->GetQuestID();
  4084. if (send_packets && quest->GetQuestGiver() > 0)
  4085. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  4086. if (lua_interface && call_accepted)
  4087. lua_interface->CallQuestFunction(quest, "Accepted", player);
  4088. if (send_packets) {
  4089. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4090. //SendQuestJournal();
  4091. SendQuestJournalUpdate(quest);
  4092. // sent twice to match live
  4093. quest->SetTracked(false);
  4094. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  4095. quest->SetTracked(true);
  4096. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  4097. }
  4098. //This isn't during a load screen, so update spawns with required quests
  4099. if (call_accepted)
  4100. player->SendQuestRequiredSpawns(quest->GetQuestID());
  4101. }
  4102. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  4103. if (current_quest_id == id)
  4104. current_quest_id = 0;
  4105. if (player->player_quests.count(id) > 0) {
  4106. if (delete_quest) {
  4107. player->player_quests[id]->SetDeleted(true);
  4108. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  4109. }
  4110. if (send_update && player->player_quests[id]->GetQuestGiver() > 0)
  4111. GetCurrentZone()->SendSpawnChangesByDBID(player->player_quests[id]->GetQuestGiver(), this, false, true);
  4112. if (send_update) {
  4113. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4114. SendQuestJournal();
  4115. }
  4116. player->RemoveQuest(id, delete_quest);
  4117. if (send_update) {
  4118. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4119. SendQuestJournal();
  4120. }
  4121. }
  4122. }
  4123. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  4124. if (quest) {
  4125. QuestStep* quest_step = quest->GetQuestStep(step);
  4126. if (quest_step) {
  4127. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  4128. quest_step->WasUpdated(false);
  4129. }
  4130. }
  4131. }
  4132. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  4133. QueuedQuest* item = new QueuedQuest;
  4134. item->quest = quest;
  4135. item->step = step;
  4136. item->display_quest_helper = display_quest_helper;
  4137. MQuestQueue.writelock();
  4138. quest_queue.push_back(item);
  4139. last_update_time = Timer::GetCurrentTime2();
  4140. MQuestQueue.releasewritelock();
  4141. }
  4142. void Client::SendQuestFailure(Quest* quest) {
  4143. vector<QuestStep*>* failures = quest->GetQuestFailures();
  4144. if (failures) {
  4145. QuestStep* step = 0;
  4146. for (int32 i = 0; i < failures->size(); i++) {
  4147. step = failures->at(i);
  4148. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  4149. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4150. SendQuestJournal();
  4151. }
  4152. failures->clear();
  4153. }
  4154. }
  4155. void Client::SendQuestUpdate(Quest* quest) {
  4156. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  4157. if (updates) {
  4158. QuestStep* step = 0;
  4159. for (int32 i = 0; i < updates->size(); i++) {
  4160. step = updates->at(i);
  4161. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  4162. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  4163. if (step->WasUpdated()) {
  4164. SendQuestJournal();
  4165. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  4166. }
  4167. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4168. }
  4169. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction())
  4170. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  4171. if (quest->GetCompleted()) {
  4172. if (quest->GetQuestReturnNPC() > 0)
  4173. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  4174. if (quest->GetCompletedFlag())
  4175. quest->SetCompletedFlag(false);
  4176. }
  4177. updates->clear();
  4178. }
  4179. }
  4180. void Client::SendQuestJournal(bool all_quests, Client* client) {
  4181. if (!client)
  4182. client = this;
  4183. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id);
  4184. if (packet) {
  4185. EQ2Packet* outapp = packet->serialize();
  4186. //DumpPacket(outapp);
  4187. client->QueuePacket(outapp);
  4188. safe_delete(packet);
  4189. }
  4190. }
  4191. void Client::SendQuestJournalUpdate(Quest* quest) {
  4192. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC());
  4193. if (packet) {
  4194. QueuePacket(packet->serialize());
  4195. safe_delete(packet);
  4196. }
  4197. }
  4198. void Client::ReloadQuests() {
  4199. vector<int32> ids = player->GetQuestIDs();
  4200. Quest* quest = 0;
  4201. for (int32 i = 0; i < ids.size(); i++) {
  4202. quest = master_quest_list.GetQuest(ids[i]);
  4203. if (quest)
  4204. AddPlayerQuest(quest, false);
  4205. else
  4206. RemovePlayerQuest(ids[i]);
  4207. }
  4208. }
  4209. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  4210. bool found_quest = false;
  4211. vector<Quest*>::iterator itr;
  4212. vector<Item*>* items = 0;
  4213. Quest* quest = 0;
  4214. MPendingQuestAccept.lock();
  4215. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end(); itr++) {
  4216. quest = *itr;
  4217. items = quest->GetSelectableRewardItems();
  4218. if (items && items->size() > 0) {
  4219. for (int32 i = 0; i < items->size(); i++) {
  4220. if (items->at(i)->details.item_id == item_id) {
  4221. found_quest = true;
  4222. break;
  4223. }
  4224. }
  4225. }
  4226. else if (item_id == 0)
  4227. found_quest = true;
  4228. if (found_quest) {
  4229. pending_quest_accept.erase(itr);
  4230. break;
  4231. }
  4232. }
  4233. MPendingQuestAccept.unlock();
  4234. if (found_quest)
  4235. return quest;
  4236. return 0;
  4237. }
  4238. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  4239. int8 num_slots_needed = 0;
  4240. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  4241. Item* master_item = 0;
  4242. if (item_id > 0) {
  4243. num_slots_needed++;
  4244. master_item = master_item_list.GetItem(item_id);
  4245. }
  4246. vector<Item*>* items = quest->GetRewardItems();
  4247. if (items && items->size() > 0)
  4248. num_slots_needed += items->size();
  4249. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= items->size())) {
  4250. if (master_item)
  4251. AddItem(item_id);
  4252. if (items && items->size() > 0) {
  4253. for (int32 i = 0; i < items->size(); i++)
  4254. AddItem(new Item(items->at(i)));
  4255. }
  4256. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  4257. if (outapp)
  4258. QueuePacket(outapp);
  4259. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  4260. map<int32, sint32>::iterator itr;
  4261. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  4262. int32 faction_id = itr->first;
  4263. sint32 amount = itr->second;
  4264. if (amount > 0)
  4265. player->GetFactions()->IncreaseFaction(faction_id, amount);
  4266. else
  4267. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  4268. }
  4269. }
  4270. else {
  4271. MPendingQuestAccept.lock();
  4272. pending_quest_accept.push_back(quest);
  4273. MPendingQuestAccept.unlock();
  4274. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  4275. DisplayQuestComplete(quest);
  4276. }
  4277. }
  4278. void Client::DisplayQuestComplete(Quest* quest) {
  4279. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  4280. if (packet) {
  4281. packet->setDataByName("title", "Quest Reward!");
  4282. packet->setDataByName("name", quest->GetName());
  4283. packet->setDataByName("description", quest->GetDescription());
  4284. packet->setDataByName("level", quest->GetLevel());
  4285. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  4286. int8 difficulty = 0;
  4287. if ((string)quest->GetType() == "Tradeskill")
  4288. difficulty = player->GetTSArrowColor(quest->GetLevel());
  4289. else
  4290. difficulty = player->GetArrowColor(quest->GetLevel());
  4291. packet->setDataByName("difficulty", difficulty);
  4292. int64 rewarded_coin = 0;
  4293. if (quest->GetCoinsReward() > 0) {
  4294. if (quest->GetCoinsRewardMax() > 0)
  4295. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  4296. else
  4297. rewarded_coin = quest->GetCoinsReward();
  4298. }
  4299. quest->SetGeneratedCoin(rewarded_coin);
  4300. packet->setDataByName("max_coin", rewarded_coin);
  4301. packet->setDataByName("min_coin", rewarded_coin);
  4302. packet->setDataByName("status_points", quest->GetStatusPoints());
  4303. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  4304. vector<Item*>* items = quest->GetRewardItems();
  4305. if (items) {
  4306. packet->setArrayLengthByName("num_rewards", items->size());
  4307. for (int32 i = 0; i < items->size(); i++) {
  4308. packet->setArrayDataByName("reward_id", items->at(i)->details.item_id, i);
  4309. if (version < 860)
  4310. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, -1);
  4311. else if (version < 1193)
  4312. packet->setItemArrayDataByName("item", items->at(i), player, i);
  4313. else
  4314. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, 2);
  4315. }
  4316. }
  4317. if (items2 && items2->size() > 0) {
  4318. packet->setArrayLengthByName("num_select_rewards", items2->size());
  4319. for (int32 i = 0; i < items2->size(); i++) {
  4320. packet->setArrayDataByName("select_reward_id", items2->at(i)->details.item_id, i);
  4321. if (version < 860)
  4322. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, -1);
  4323. else if (version < 1193)
  4324. packet->setItemArrayDataByName("select_item", items2->at(i), player, i);
  4325. else
  4326. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, 2);
  4327. }
  4328. }
  4329. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  4330. if (reward_factions && reward_factions->size() > 0) {
  4331. packet->setArrayLengthByName("num_factions", reward_factions->size());
  4332. map<int32, sint32>::iterator itr;
  4333. int16 index = 0;
  4334. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  4335. int32 faction_id = itr->first;
  4336. sint32 amount = itr->second;
  4337. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  4338. if (faction_name) {
  4339. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  4340. packet->setArrayDataByName("amount", amount, index);
  4341. }
  4342. index++;
  4343. }
  4344. }
  4345. EQ2Packet* outapp = packet->serialize();
  4346. // DumpPacket(outapp);
  4347. QueuePacket(outapp);
  4348. safe_delete(packet);
  4349. }
  4350. }
  4351. void Client::DisplayRandomizeFeatures(int32 flags) {
  4352. SimpleMessage(CHANNEL_COLOR_WHITE, "Showing Active Randomize Features:");
  4353. if (flags > 0) {
  4354. if (flags & RANDOMIZE_GENDER)
  4355. SimpleMessage(CHANNEL_COLOR_WHITE, "- Gender");
  4356. if (flags & RANDOMIZE_RACE)
  4357. SimpleMessage(CHANNEL_COLOR_WHITE, "- Race");
  4358. if (flags & RANDOMIZE_MODEL_TYPE)
  4359. SimpleMessage(CHANNEL_COLOR_WHITE, "- Model");
  4360. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  4361. SimpleMessage(CHANNEL_COLOR_WHITE, "- Facial Hair");
  4362. if (flags & RANDOMIZE_HAIR_TYPE)
  4363. SimpleMessage(CHANNEL_COLOR_WHITE, "- Hair");
  4364. if (flags & RANDOMIZE_WING_TYPE)
  4365. SimpleMessage(CHANNEL_COLOR_WHITE, "- Wing");
  4366. if (flags & RANDOMIZE_CHEEK_TYPE)
  4367. SimpleMessage(CHANNEL_COLOR_WHITE, "- Cheek");
  4368. if (flags & RANDOMIZE_CHIN_TYPE)
  4369. SimpleMessage(CHANNEL_COLOR_WHITE, "- Chin");
  4370. if (flags & RANDOMIZE_EAR_TYPE)
  4371. SimpleMessage(CHANNEL_COLOR_WHITE, "- Ear");
  4372. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  4373. SimpleMessage(CHANNEL_COLOR_WHITE, "- Eyebrow");
  4374. if (flags & RANDOMIZE_EYE_TYPE)
  4375. SimpleMessage(CHANNEL_COLOR_WHITE, "- Eye");
  4376. if (flags & RANDOMIZE_LIP_TYPE)
  4377. SimpleMessage(CHANNEL_COLOR_WHITE, "- Lip");
  4378. if (flags & RANDOMIZE_NOSE_TYPE)
  4379. SimpleMessage(CHANNEL_COLOR_WHITE, "- Nose");
  4380. if (flags & RANDOMIZE_EYE_COLOR)
  4381. SimpleMessage(CHANNEL_COLOR_WHITE, "- Eye Color");
  4382. if (flags & RANDOMIZE_HAIR_COLOR1)
  4383. SimpleMessage(CHANNEL_COLOR_WHITE, "- Hair Color1");
  4384. if (flags & RANDOMIZE_HAIR_COLOR2)
  4385. SimpleMessage(CHANNEL_COLOR_WHITE, "- Hair Color2");
  4386. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  4387. SimpleMessage(CHANNEL_COLOR_WHITE, "- Hair Color Highlights");
  4388. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  4389. SimpleMessage(CHANNEL_COLOR_WHITE, "- Facial Hair Color");
  4390. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  4391. SimpleMessage(CHANNEL_COLOR_WHITE, "- Facial Hair Color Highlights");
  4392. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  4393. SimpleMessage(CHANNEL_COLOR_WHITE, "- Hair Type Color");
  4394. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  4395. SimpleMessage(CHANNEL_COLOR_WHITE, "- Hair Type Highlights");
  4396. if (flags & RANDOMIZE_SKIN_COLOR)
  4397. SimpleMessage(CHANNEL_COLOR_WHITE, "- Skin Color");
  4398. if (flags & RANDOMIZE_WING_COLOR1)
  4399. SimpleMessage(CHANNEL_COLOR_WHITE, "- Wing Color1");
  4400. if (flags & RANDOMIZE_WING_COLOR2)
  4401. SimpleMessage(CHANNEL_COLOR_WHITE, "- Wing Color2");
  4402. }
  4403. else
  4404. {
  4405. SimpleMessage(CHANNEL_COLOR_WHITE, "- No Randomization Set.");
  4406. }
  4407. }
  4408. void Client::GiveQuestReward(Quest* quest) {
  4409. current_quest_id = 0;
  4410. MPendingQuestAccept.lock();
  4411. pending_quest_accept.push_back(quest);
  4412. MPendingQuestAccept.unlock();
  4413. quest->IncrementCompleteCount();
  4414. player->AddCompletedQuest(quest);
  4415. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4416. SendQuestJournal();
  4417. player->RemoveQuest(quest->GetQuestID(), false);
  4418. DisplayQuestComplete(quest);
  4419. if (quest->GetExpReward() > 0) {
  4420. int16 level = player->GetLevel();
  4421. int32 xp = quest->GetExpReward();
  4422. if (player->AddXP(xp)) {
  4423. Message(CHANNEL_COLOR_EXP, "You gain %u experience!", (int32)xp);
  4424. if (player->GetLevel() != level)
  4425. ChangeLevel(level, player->GetLevel());
  4426. player->SetCharSheetChanged(true);
  4427. }
  4428. }
  4429. if (quest->GetTSExpReward() > 0) {
  4430. int8 ts_level = player->GetTSLevel();
  4431. int32 xp = quest->GetTSExpReward();
  4432. if (player->AddTSXP(xp)) {
  4433. Message(CHANNEL_COLOR_EXP, "You gain %u tradeskill experience!", (int32)xp);
  4434. if (player->GetTSLevel() != ts_level)
  4435. ChangeTSLevel(ts_level, player->GetTSLevel());
  4436. player->SetCharSheetChanged(true);
  4437. }
  4438. }
  4439. int64 total_coins = quest->GetGeneratedCoin();
  4440. if (total_coins > 0) {
  4441. player->AddCoins(total_coins);
  4442. PlaySound("coin_cha_ching");
  4443. char tmp[64] = { 0 };
  4444. string message = "You receive ";
  4445. int32 val = 0;
  4446. if (total_coins >= 1000000) {
  4447. val = total_coins / 1000000;
  4448. total_coins -= 1000000 * val;
  4449. sprintf(tmp, "%u Platinum ", val);
  4450. message.append(tmp);
  4451. memset(tmp, 0, 64);
  4452. }
  4453. if (total_coins >= 10000) {
  4454. val = total_coins / 10000;
  4455. total_coins -= 10000 * val;
  4456. sprintf(tmp, "%u Gold ", val);
  4457. message.append(tmp);
  4458. memset(tmp, 0, 64);
  4459. }
  4460. if (total_coins >= 100) {
  4461. val = total_coins / 100;
  4462. total_coins -= 100 * val;
  4463. sprintf(tmp, "%u Silver ", val);
  4464. message.append(tmp);
  4465. memset(tmp, 0, 64);
  4466. }
  4467. if (total_coins > 0) {
  4468. sprintf(tmp, "%u Copper ", (int32)total_coins);
  4469. message.append(tmp);
  4470. }
  4471. message.append("for completing ").append(quest->GetName());
  4472. int8 type = CHANNEL_COLOR_LOOT;
  4473. if (GetVersion() >= 973)
  4474. type = CHANNEL_COLOR_NEW_LOOT;
  4475. SimpleMessage(type, message.c_str());
  4476. }
  4477. if (quest->GetQuestGiver() > 0)
  4478. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  4479. RemovePlayerQuest(quest->GetQuestID(), true, false);
  4480. }
  4481. void Client::DisplayConversation(int32 conversation_id, int32 spawn_id, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2) {
  4482. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  4483. if (packet) {
  4484. packet->setDataByName("conversation_id", conversation_id);
  4485. packet->setDataByName("text", text);
  4486. packet->setDataByName("unknown2", 1);
  4487. conversation_map[conversation_id].clear();
  4488. if (conversations) {
  4489. packet->setArrayLengthByName("num_responses", conversations->size());
  4490. for (int32 i = 0; i < conversations->size(); i++) {
  4491. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  4492. if (conversations->at(i).function.length() > 0)
  4493. conversation_map[conversation_id][i] = conversations->at(i).function;
  4494. }
  4495. }
  4496. packet->setDataByName("spawn_id", spawn_id);
  4497. if (mp3) {
  4498. packet->setDataByName("voice", mp3);
  4499. packet->setDataByName("key1", key1);
  4500. packet->setDataByName("key2", key2);
  4501. }
  4502. QueuePacket(packet->serialize());
  4503. safe_delete(packet);
  4504. }
  4505. }
  4506. void Client::DisplayConversation(Item* item, vector<ConversationOption>* conversations, const char* text, int8 type, const char* mp3, int32 key1, int32 key2) {
  4507. if (!item || !text || !conversations || conversations->size() == 0) {
  4508. return;
  4509. }
  4510. int32 conversation_id = GetConversationID(0, item);
  4511. if (conversation_id == 0) {
  4512. next_conversation_id++;
  4513. conversation_id = next_conversation_id;
  4514. }
  4515. conversation_items[conversation_id] = item;
  4516. if (type == 4)
  4517. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2);
  4518. else
  4519. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2);
  4520. }
  4521. void Client::DisplayConversation(Entity* npc, int8 type, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2) {
  4522. if (!npc || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  4523. return;
  4524. }
  4525. int32 conversation_id = GetConversationID(npc, 0);
  4526. if (conversation_id == 0) {
  4527. next_conversation_id++;
  4528. conversation_id = next_conversation_id;
  4529. }
  4530. conversation_spawns[conversation_id] = npc;
  4531. /* NPCs can start two different types of conversations.
  4532. * Type 1: The chat type with bubbles.
  4533. * Type 2: The dialog type with the blue box. */
  4534. if (type == 1)
  4535. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(npc), conversations, text, mp3, key1, key2);
  4536. else if (type == 2)
  4537. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2);
  4538. else //if (type == 3)
  4539. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2);
  4540. }
  4541. void Client::CloseDialog(int32 conversation_id) {
  4542. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  4543. if (packet) {
  4544. packet->setDataByName("conversation_id", conversation_id);
  4545. QueuePacket(packet->serialize());
  4546. safe_delete(packet);
  4547. }
  4548. conversation_items.erase(conversation_id);
  4549. conversation_spawns.erase(conversation_id);
  4550. }
  4551. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  4552. int32 conversation_id = 0;
  4553. if (spawn) {
  4554. map<int32, Spawn*>::iterator itr;
  4555. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  4556. if (itr->second == spawn) {
  4557. conversation_id = itr->first;
  4558. break;
  4559. }
  4560. }
  4561. }
  4562. else if (item) {
  4563. map<int32, Item*>::iterator itr;
  4564. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  4565. if (itr->second == item) {
  4566. conversation_id = itr->first;
  4567. break;
  4568. }
  4569. }
  4570. }
  4571. return conversation_id;
  4572. }
  4573. Spawn* Client::GetCombineSpawn() {
  4574. return combine_spawn;
  4575. }
  4576. bool Client::ShouldTarget() {
  4577. return should_target;
  4578. }
  4579. void Client::TargetSpawn(Spawn* spawn) {
  4580. should_target = false;
  4581. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  4582. if (packet) {
  4583. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  4584. QueuePacket(packet->serialize());
  4585. safe_delete(packet);
  4586. }
  4587. }
  4588. void Client::CombineSpawns(float radius, Spawn* spawn) {
  4589. combine_spawn = spawn;
  4590. spawn->RemoveSpawnFromGroup(true);
  4591. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  4592. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  4593. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  4594. should_target = true;
  4595. }
  4596. void Client::AddCombineSpawn(Spawn* spawn) {
  4597. if (combine_spawn && combine_spawn != spawn && spawn) {
  4598. combine_spawn->AddSpawnToGroup(spawn);
  4599. spawn->AddSpawnToGroup(combine_spawn);
  4600. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  4601. }
  4602. else if (spawn)
  4603. combine_spawn = spawn;
  4604. should_target = true;
  4605. }
  4606. void Client::RemoveCombineSpawn(Spawn* spawn) {
  4607. if (combine_spawn && spawn)
  4608. spawn->RemoveSpawnFromGroup();
  4609. if (combine_spawn == spawn)
  4610. combine_spawn->RemoveSpawnFromGroup(true);
  4611. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  4612. if (combine_spawn == spawn)
  4613. combine_spawn = 0;
  4614. }
  4615. void Client::SaveCombineSpawns(const char* name) {
  4616. if (!combine_spawn) {
  4617. return;
  4618. }
  4619. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  4620. if (!spawns) {
  4621. return;
  4622. }
  4623. int32 count = spawns->size();
  4624. int32 spawnLocationID = 0;
  4625. if (count == 1)
  4626. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  4627. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  4628. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  4629. // we remove the spawn inside SaveCombinedSpawnLocation
  4630. //GetCurrentZone()->RemoveSpawn(false, combine_spawn);
  4631. }
  4632. else
  4633. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  4634. safe_delete(spawns);
  4635. combine_spawn = 0;
  4636. }
  4637. bool Client::AddItem(int32 item_id, int16 quantity) {
  4638. Item* master_item = master_item_list.GetItem(item_id);
  4639. Item* item = 0;
  4640. if (master_item)
  4641. item = new Item(master_item);
  4642. if (item) {
  4643. if (quantity > 0)
  4644. item->details.count = quantity;
  4645. return AddItem(item);
  4646. }
  4647. else
  4648. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  4649. return false;
  4650. }
  4651. bool Client::AddItem(Item* item) {
  4652. if (!item) {
  4653. return false;
  4654. }
  4655. if (item->IsBag())
  4656. item->details.bag_id = item->details.unique_id;
  4657. if (player->AddItem(item)) {
  4658. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  4659. if (outapp) {
  4660. QueuePacket(outapp);
  4661. //resend bag desc with new item name added
  4662. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  4663. if (outapp)
  4664. QueuePacket(outapp);
  4665. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  4666. DumpPacket(app);
  4667. client->QueuePacket(app);
  4668. */
  4669. }
  4670. CheckPlayerQuestsItemUpdate(item);
  4671. if (item->GetItemScript() && lua_interface)
  4672. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  4673. }
  4674. else {
  4675. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  4676. safe_delete(item);
  4677. return false;
  4678. }
  4679. return true;
  4680. }
  4681. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  4682. Item* master_item = master_item_list.GetItem(item_id);
  4683. Item* item = 0;
  4684. if (master_item)
  4685. item = new Item(master_item);
  4686. if (item) {
  4687. if (quantity > 0)
  4688. item->details.count = quantity;
  4689. return AddItemToBank(item);
  4690. }
  4691. else
  4692. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  4693. return false;
  4694. }
  4695. bool Client::AddItemToBank(Item* item) {
  4696. if (!item) {
  4697. return false;
  4698. }
  4699. if (item->IsBag())
  4700. item->details.bag_id = item->details.unique_id;
  4701. if (player->AddItemToBank(item)) {
  4702. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  4703. if (outapp) {
  4704. QueuePacket(outapp);
  4705. //resend bag desc with new item name added
  4706. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  4707. if (outapp)
  4708. QueuePacket(outapp);
  4709. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  4710. DumpPacket(app);
  4711. client->QueuePacket(app);
  4712. */
  4713. }
  4714. CheckPlayerQuestsItemUpdate(item);
  4715. if (item->GetItemScript() && lua_interface)
  4716. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  4717. }
  4718. else {
  4719. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  4720. safe_delete(item);
  4721. return false;
  4722. }
  4723. return true;
  4724. }
  4725. bool Client::RemoveItem(Item* item, int16 quantity) {
  4726. EQ2Packet* outapp;
  4727. bool delete_item = false;
  4728. assert(item);
  4729. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  4730. item->details.count -= quantity;
  4731. item->save_needed = true;
  4732. }
  4733. else {
  4734. database.DeleteItem(character_id, item, 0);
  4735. player->GetPlayerItemList()->RemoveItem(item, false);
  4736. delete_item = true;
  4737. }
  4738. if ((outapp = player->SendInventoryUpdate(version))) {
  4739. QueuePacket(outapp);
  4740. if (item->GetItemScript() && lua_interface)
  4741. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  4742. if (delete_item)
  4743. safe_delete(item);
  4744. return true;
  4745. }
  4746. return false;
  4747. }
  4748. void Client::SetLuaDebugClient(bool val) {
  4749. if (val)
  4750. lua_debug_timer.Start();
  4751. lua_debug = val;
  4752. if (lua_interface && !val) {
  4753. lua_interface->RemoveDebugClients(this);
  4754. lua_debug_timer.Disable();
  4755. }
  4756. }
  4757. void Client::SetMerchantTransaction(Spawn* spawn) {
  4758. merchant_transaction = spawn;
  4759. }
  4760. Spawn* Client::GetMerchantTransaction() {
  4761. return merchant_transaction;
  4762. }
  4763. void Client::SetMailTransaction(Spawn* spawn) {
  4764. mail_transaction = spawn;
  4765. mail_window.coin_copper = 0;
  4766. mail_window.coin_silver = 0;
  4767. mail_window.coin_gold = 0;
  4768. mail_window.coin_plat = 0;
  4769. mail_window.char_item_id = 0;
  4770. }
  4771. Spawn* Client::GetMailTransaction() {
  4772. return mail_transaction;
  4773. }
  4774. void Client::PlaySound(const char* name) {
  4775. if (name) {
  4776. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  4777. if (packet) {
  4778. packet->setMediumStringByName("name", name);
  4779. QueuePacket(packet->serialize());
  4780. safe_delete(packet);
  4781. }
  4782. }
  4783. }
  4784. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  4785. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  4786. if(multiplier){
  4787. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  4788. float diff_low = faction_val - multiplier->faction_min;
  4789. if(diff_low < 0)
  4790. diff_low*=-1;
  4791. float total_diff = multiplier->faction_max - multiplier->faction_min;
  4792. if(total_diff < 0)
  4793. total_diff*=-1;
  4794. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  4795. float total1 = (diff_low/total_diff);
  4796. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  4797. return final_buy_multiplier;
  4798. }*/
  4799. return 1;
  4800. }
  4801. float Client::CalculateSellMultiplier(int32 merchant_id) {
  4802. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  4803. if(multiplier){
  4804. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  4805. float diff_low = faction_val - multiplier->faction_min;
  4806. if(diff_low < 0)
  4807. diff_low*=-1;
  4808. float total_diff = multiplier->faction_max - multiplier->faction_min;
  4809. if(total_diff < 0)
  4810. total_diff*=-1;
  4811. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  4812. float total1 = (diff_low/total_diff);
  4813. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  4814. return final_sell_multiplier;
  4815. }*/
  4816. return 1;
  4817. }
  4818. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  4819. Spawn* spawn = GetMerchantTransaction();
  4820. Guild* guild = GetPlayer()->GetGuild();
  4821. if (spawn && spawn->GetMerchantID() > 0) {
  4822. int32 total_sell_price = 0;
  4823. int32 total_status_sell_price = 0; //for status
  4824. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  4825. int32 sell_price = 0;
  4826. int32 status_sell_price = 0; //for status
  4827. Item* master_item = master_item_list.GetItem(item_id);
  4828. Item* item = 0;
  4829. if (unique_id == 0)
  4830. item = player->item_list.GetItemFromID(item_id, quantity);
  4831. else
  4832. item = player->item_list.GetItemFromUniqueID(unique_id);
  4833. if (!item)
  4834. player->item_list.GetItemFromID(item_id);
  4835. if (item && master_item) {
  4836. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  4837. if (sell_price > item->sell_price)
  4838. sell_price = item->sell_price;
  4839. if (quantity > item->details.count)
  4840. quantity = item->details.count;
  4841. total_sell_price = sell_price * quantity;
  4842. //------------------------------For Selling Status Items
  4843. status_sell_price = (int32)(master_item->sell_status * multiplier);
  4844. if (status_sell_price > item->sell_status)
  4845. status_sell_price = item->sell_status;
  4846. if (quantity > item->details.count)
  4847. quantity = item->details.count;
  4848. if (player->GetGuild()) {
  4849. total_status_sell_price = status_sell_price * quantity;
  4850. player->GetInfoStruct()->status_points += total_status_sell_price;
  4851. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  4852. guild->SendGuildMemberList();
  4853. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  4854. }
  4855. if (quantity > 1)
  4856. Message(CHANNEL_COLOR_MERCHANT, "You sell %i \\aITEM %u 0:%s\\/a to %s for %s.", quantity, master_item->details.item_id, master_item->name.c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str());
  4857. else
  4858. Message(CHANNEL_COLOR_MERCHANT, "You sell \\aITEM %u 0:%s\\/a to %s for %s.", master_item->details.item_id, master_item->name.c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str());
  4859. player->AddCoins(total_sell_price);
  4860. AddBuyBack(unique_id, item_id, quantity, sell_price);
  4861. if (quantity >= item->details.count) {
  4862. database.DeleteItem(GetCharacterID(), item, 0);
  4863. player->item_list.DestroyItem(item->details.index);
  4864. }
  4865. else {
  4866. item->details.count -= quantity;
  4867. item->save_needed = true;
  4868. }
  4869. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  4870. if (outapp)
  4871. QueuePacket(outapp);
  4872. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY))
  4873. SendSellMerchantList();
  4874. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  4875. SendBuyBackList();
  4876. }
  4877. }
  4878. }
  4879. void Client::BuyBack(int32 item_id, int16 quantity) {
  4880. Spawn* spawn = GetMerchantTransaction();
  4881. if (spawn && spawn->GetMerchantID() > 0) {
  4882. deque<BuyBackItem*>::iterator itr;
  4883. BuyBackItem* buyback = 0;
  4884. BuyBackItem* closest = 0;
  4885. MBuyBack.readlock(__FUNCTION__, __LINE__);
  4886. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  4887. buyback = *itr;
  4888. if (buyback->unique_id == item_id) {
  4889. closest = buyback;
  4890. quantity = buyback->quantity;
  4891. break;
  4892. }
  4893. }
  4894. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  4895. if (closest) {
  4896. Item* item = 0;
  4897. Item* master_item = master_item_list.GetItem(closest->item_id);
  4898. if (master_item) {
  4899. item = new Item(master_item);
  4900. if (closest->quantity >= quantity)
  4901. item->details.count = quantity;
  4902. else
  4903. item->details.count = closest->quantity;
  4904. }
  4905. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  4906. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  4907. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  4908. bool removed = false;
  4909. if (closest->quantity == quantity) {
  4910. MBuyBack.writelock(__FUNCTION__, __LINE__);
  4911. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  4912. if (*itr == closest) {
  4913. buy_back_items.erase(itr);
  4914. removed = true;
  4915. break;
  4916. }
  4917. }
  4918. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  4919. }
  4920. else {
  4921. closest->quantity -= quantity;
  4922. closest->save_needed = true;
  4923. }
  4924. AddItem(item);
  4925. //EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  4926. //if(outapp)
  4927. //QueuePacket(outapp);
  4928. if (removed) {
  4929. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  4930. safe_delete(closest);
  4931. }
  4932. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY))
  4933. SendSellMerchantList();
  4934. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  4935. SendBuyBackList();
  4936. }
  4937. else
  4938. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  4939. }
  4940. }
  4941. }
  4942. void Client::BuyItem(int32 item_id, int16 quantity) {
  4943. // Get the merchant we are buying from
  4944. Spawn* spawn = GetMerchantTransaction();
  4945. // Make sure the spawn has a merchant list
  4946. if (spawn && spawn->GetMerchantID() > 0) {
  4947. int32 total_buy_price = 0;
  4948. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  4949. int32 sell_price = 0;
  4950. Item* master_item = master_item_list.GetItem(item_id);
  4951. Item* item = 0;
  4952. int16 total_available = 0;
  4953. vector<MerchantItemInfo>* temp;
  4954. vector<MerchantItemInfo>::iterator itr;
  4955. MerchantItemInfo* ItemInfo = 0;
  4956. temp = world.GetMerchantList(spawn->GetMerchantID());
  4957. for (itr = temp->begin(); itr != temp->end(); itr++) {
  4958. if ((*itr).item_id == item_id) {
  4959. ItemInfo = &(*itr);
  4960. break;
  4961. }
  4962. }
  4963. if (master_item && ItemInfo) {
  4964. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  4965. quantity = 1;
  4966. total_available = 0xFFFF;
  4967. sell_price = master_item->sell_price;
  4968. }
  4969. else {
  4970. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  4971. sell_price = (int32)(master_item->sell_price * multiplier);
  4972. if (quantity > total_available)
  4973. quantity = total_available;
  4974. }
  4975. total_buy_price = sell_price * quantity;
  4976. item = new Item(master_item);
  4977. item->details.count = quantity;
  4978. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  4979. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  4980. safe_delete(item);
  4981. }
  4982. else {
  4983. // Price not set in the merchant_inventory table, use the old method
  4984. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  4985. if (player->RemoveCoins(total_buy_price)) {
  4986. item->SetMaxSellValue(sell_price);
  4987. if (quantity > 1)
  4988. Message(CHANNEL_COLOR_MERCHANT, "You buy %i \\aITEM %u 0:%s\\/a from %s for%s.", quantity, master_item->details.item_id, master_item->name.c_str(), spawn->GetName(), GetCoinMessage(total_buy_price).c_str());
  4989. else
  4990. Message(CHANNEL_COLOR_MERCHANT, "You buy \\aITEM %u 0:%s\\/a from %s for%s.", master_item->details.item_id, master_item->name.c_str(), spawn->GetName(), GetCoinMessage(total_buy_price).c_str());
  4991. AddItem(item);
  4992. CheckPlayerQuestsItemUpdate(item);
  4993. if (item && total_available < 0xFFFF) {
  4994. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  4995. SendBuyMerchantList();
  4996. }
  4997. //EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  4998. //if(outapp)
  4999. // QueuePacket(outapp);
  5000. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) && !(spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  5001. SendSellMerchantList();
  5002. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  5003. PlayLotto(total_buy_price, item->details.item_id);
  5004. }
  5005. else {
  5006. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase \\aITEM %u 0:%s\\/a.", master_item->details.item_id, master_item->name.c_str());
  5007. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  5008. PlaySound("buy_failed");
  5009. }
  5010. }
  5011. else {
  5012. // Price set in merchant_inventory table
  5013. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  5014. // TODO: need to add support for station cash
  5015. if (player->GetInfoStruct()->status_points >= ItemInfo->price_status && player->HasCoins(ItemInfo->price_coins * quantity)) {
  5016. // Check items
  5017. int16 item_quantity = 0;
  5018. // Default these to true in case price_item_id or price_item2_id was never set
  5019. bool hasItem1 = true;
  5020. bool hasItem2 = true;
  5021. Item* tempItem1 = 0;
  5022. Item* tempItem2 = 0;
  5023. if (ItemInfo->price_item_id != 0) {
  5024. // Same item for whatever reason lets add the quantities together
  5025. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  5026. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  5027. else
  5028. item_quantity = ItemInfo->price_item_qty;
  5029. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  5030. if (tempItem1) {
  5031. if (tempItem1->details.count < item_quantity)
  5032. hasItem1 = false;
  5033. }
  5034. else {
  5035. hasItem1 = false;
  5036. }
  5037. }
  5038. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  5039. // as item1 and we already checked for it so we can skip this check
  5040. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  5041. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  5042. if (tempItem2) {
  5043. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  5044. hasItem2 = false;
  5045. }
  5046. else {
  5047. hasItem2 = false;
  5048. }
  5049. }
  5050. // if we have every thing then remove the price and give the item
  5051. if (hasItem1 && hasItem2) {
  5052. player->GetInfoStruct()->status_points -= ItemInfo->price_status;
  5053. // TODO: station cash
  5054. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  5055. // so there is no need to send it more then that one time
  5056. if (tempItem1) {
  5057. if (tempItem1->details.count > item_quantity) {
  5058. tempItem1->details.count -= item_quantity;
  5059. tempItem1->save_needed = true;
  5060. }
  5061. else {
  5062. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  5063. player->item_list.DestroyItem(tempItem1->details.index);
  5064. }
  5065. }
  5066. if (tempItem2) {
  5067. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  5068. tempItem2->details.count -= ItemInfo->price_item2_qty;
  5069. tempItem2->save_needed = true;
  5070. }
  5071. else {
  5072. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  5073. player->item_list.DestroyItem(tempItem2->details.index);
  5074. }
  5075. }
  5076. // Checked to see if we had enough coins already so don't need to check the return type on RemoveCoins as it will always be true
  5077. player->RemoveCoins(ItemInfo->price_coins * quantity);
  5078. item->SetMaxSellValue(sell_price);
  5079. if (quantity > 1)
  5080. Message(CHANNEL_COLOR_MERCHANT, "You buy %i \\aITEM %u 0:%s\\/a from %s for%s.", quantity, master_item->details.item_id, master_item->name.c_str(), spawn->GetName(), GetCoinMessage(ItemInfo->price_coins * quantity).c_str());
  5081. else
  5082. Message(CHANNEL_COLOR_MERCHANT, "You buy \\aITEM %u 0:%s\\/a from %s for%s.", master_item->details.item_id, master_item->name.c_str(), spawn->GetName(), GetCoinMessage(ItemInfo->price_coins * quantity).c_str());
  5083. AddItem(item);
  5084. CheckPlayerQuestsItemUpdate(item);
  5085. if (item && total_available < 0xFFFF) {
  5086. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  5087. SendBuyMerchantList();
  5088. }
  5089. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) && !(spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  5090. SendSellMerchantList();
  5091. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  5092. PlayLotto(total_buy_price, item->details.item_id);
  5093. }
  5094. else {
  5095. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase \\aITEM %u 0:%s\\/a.", master_item->details.item_id, master_item->name.c_str());
  5096. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  5097. PlaySound("buy_failed");
  5098. }
  5099. }
  5100. else {
  5101. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase \\aITEM %u 0:%s\\/a.", master_item->details.item_id, master_item->name.c_str());
  5102. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  5103. PlaySound("buy_failed");
  5104. }
  5105. }
  5106. }
  5107. }
  5108. }
  5109. }
  5110. void Client::RepairItem(int32 item_id) {
  5111. Spawn* spawn = GetMerchantTransaction();
  5112. if (spawn) {
  5113. Item* item = player->item_list.GetItemFromID(item_id);
  5114. if (!item)
  5115. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  5116. if (item) {
  5117. int32 repair_cost = item->CalculateRepairCost();
  5118. if (player->RemoveCoins((int32)repair_cost)) {
  5119. item->generic_info.condition = 100;
  5120. item->save_needed = true;
  5121. QueuePacket(player->GetEquipmentList()->serialize(GetVersion()));
  5122. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  5123. QueuePacket(item->serialize(version, false, player));
  5124. Message(CHANNEL_COLOR_MERCHANT, "You give %s %s to repair your \\aITEM %u 0:%s\\/a.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->details.item_id, item->name.c_str());
  5125. PlaySound("coin_cha_ching");
  5126. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  5127. SendRepairList();
  5128. }
  5129. else {
  5130. LogWrite(MISC__TODO, 1, "TODO", " Send pop up that says 'Not enough coin.'\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  5131. Message(CHANNEL_COLOR_MERCHANT, "You do not have enough coin to repair \\aITEM %u 0:%s\\/a.", item->details.item_id, item->name.c_str());
  5132. PlaySound("buy_failed");
  5133. }
  5134. }
  5135. }
  5136. }
  5137. void Client::RepairAllItems() {
  5138. Spawn* spawn = GetMerchantTransaction();
  5139. if (spawn) {
  5140. vector<Item*>* repairable_items = GetRepairableItems();
  5141. if (repairable_items && repairable_items->size() > 0) {
  5142. vector<Item*>::iterator itr;
  5143. int64 total_cost = 0;
  5144. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  5145. total_cost += (*itr)->CalculateRepairCost();
  5146. if (player->RemoveCoins((int32)total_cost)) {
  5147. Message(CHANNEL_COLOR_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  5148. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  5149. Item* item = *itr;
  5150. if (item) {
  5151. item->generic_info.condition = 100;
  5152. item->save_needed = true;
  5153. QueuePacket(item->serialize(version, false, player));
  5154. Message(CHANNEL_COLOR_YELLOW, "Repaired: \\aITEM %u 0:%s\\/a.", item->details.item_id, item->name.c_str());
  5155. }
  5156. }
  5157. QueuePacket(player->GetEquipmentList()->serialize(GetVersion()));
  5158. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  5159. PlaySound("coin_cha_ching");
  5160. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  5161. SendRepairList();
  5162. }
  5163. else {
  5164. LogWrite(MISC__TODO, 1, "TODO", "Send pop up that says 'Not enough coin.'\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  5165. SimpleMessage(CHANNEL_COLOR_MERCHANT, "You do not have enough coin to repair all of your items.");
  5166. PlaySound("buy_failed");
  5167. }
  5168. }
  5169. safe_delete(repairable_items);
  5170. }
  5171. }
  5172. void Client::SendAchievementsList()
  5173. {
  5174. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  5175. map<int32, Achievement *>::iterator itr;
  5176. Achievement *achievement;
  5177. vector<AchievementRequirements *> *requirements = 0;
  5178. vector<AchievementRequirements *>::iterator itr2;
  5179. AchievementRequirements *requirement;
  5180. vector<AchievementRewards *> *rewards = 0;
  5181. vector<AchievementRewards *>::iterator itr3;
  5182. AchievementRewards *reward;
  5183. PacketStruct *packet;
  5184. int16 i = 0;
  5185. int16 j = 0;
  5186. int16 k = 0;
  5187. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  5188. return;
  5189. }
  5190. packet->setArrayLengthByName("num_achievements" , achievements->size());
  5191. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  5192. achievement = itr->second;
  5193. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  5194. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  5195. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  5196. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  5197. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  5198. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  5199. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  5200. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  5201. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  5202. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  5203. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  5204. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  5205. requirements = achievement->GetRequirements();
  5206. rewards = achievement->GetRewards();
  5207. j = 0;
  5208. k = 0;
  5209. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  5210. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  5211. requirement = *itr2;
  5212. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  5213. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  5214. j++;
  5215. }
  5216. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  5217. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  5218. reward = *itr3;
  5219. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  5220. k++;
  5221. }
  5222. i++;
  5223. }
  5224. //packet->PrintPacket();
  5225. EQ2Packet* data = packet->serialize();
  5226. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  5227. safe_delete(packet);
  5228. safe_delete(data);
  5229. //DumpPacket(app);
  5230. QueuePacket(app);*/
  5231. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  5232. SendAchievementUpdate(true);
  5233. }
  5234. void Client::SendAchievementUpdate(bool first_login) {
  5235. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  5236. map<int32, AchievementUpdate*>::iterator itr;
  5237. AchievementUpdate* update;
  5238. vector<AchievementUpdateItems*>* update_items = 0;
  5239. vector<AchievementUpdateItems*>::iterator itr2;
  5240. AchievementUpdateItems* update_item;
  5241. int16 i = 0;
  5242. int16 j = 0;
  5243. PacketStruct* packet;
  5244. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  5245. return;
  5246. }
  5247. packet->setDataByName("unknown1", first_login ? 1 : 0);
  5248. packet->setArrayLengthByName("num_achievements", updates->size());
  5249. for (itr = updates->begin(); itr != updates->end(); itr++) {
  5250. update = itr->second;
  5251. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  5252. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  5253. update_items = update->GetUpdateItems();
  5254. j = 0;
  5255. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  5256. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  5257. update_item = *itr2;
  5258. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  5259. j++;
  5260. }
  5261. i++;
  5262. }
  5263. //packet->PrintPacket();
  5264. EQ2Packet* data = packet->serialize();
  5265. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  5266. safe_delete(packet);
  5267. safe_delete(data);
  5268. //DumpPacket(app);
  5269. QueuePacket(app);
  5270. }
  5271. void Client::SendBuyMerchantList(bool sell) {
  5272. Spawn* spawn = GetMerchantTransaction();
  5273. if (spawn && spawn->GetMerchantID() > 0) {
  5274. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  5275. if (items) {
  5276. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5277. if (packet) {
  5278. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  5279. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5280. packet->setArrayLengthByName("num_items", items->size());
  5281. vector<MerchantItemInfo>::iterator itr;
  5282. sint8 item_difficulty = 0;
  5283. int32 sell_price = 0;
  5284. int i = 0;
  5285. int tmp_level = 0;
  5286. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  5287. MerchantItemInfo ItemInfo = *itr;
  5288. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  5289. if (!item)
  5290. continue;
  5291. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  5292. packet->setArrayDataByName("item_id", item->details.item_id, i);
  5293. packet->setArrayDataByName("stack_size", item->stack_count, i);
  5294. packet->setArrayDataByName("icon", item->details.icon, i);
  5295. if (item->generic_info.adventure_default_level > 0)
  5296. tmp_level = item->generic_info.adventure_default_level;
  5297. else
  5298. tmp_level = item->generic_info.tradeskill_default_level;
  5299. packet->setArrayDataByName("level", tmp_level, i);
  5300. packet->setArrayDataByName("tier", item->details.tier, i);
  5301. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  5302. item_difficulty = player->GetArrowColor(tmp_level);
  5303. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  5304. item_difficulty = ARROW_COLOR_WHITE;
  5305. item_difficulty -= 6;
  5306. if (item_difficulty < 0)
  5307. item_difficulty *= -1;
  5308. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  5309. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  5310. packet->setArrayDataByName("unknown5", 255, i);
  5311. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  5312. if (GetVersion() <= 1096)
  5313. packet->setArrayDataByName("description", item->description.c_str(), i);
  5314. // If no price set in the merchant_inventory table then use the old method
  5315. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  5316. sell_price = (int32)(item->sell_price * multiplier);
  5317. packet->setArrayDataByName("price", sell_price, i);
  5318. }
  5319. else {
  5320. int8 count = 0;
  5321. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  5322. count++;
  5323. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  5324. count++;
  5325. if (count != 0) {
  5326. packet->setSubArrayLengthByName("num_tokens", count, i);
  5327. int8 index = 0;
  5328. Item* token = 0;
  5329. if (ItemInfo.price_item_id != 0) {
  5330. token = master_item_list.GetItem(ItemInfo.price_item_id);
  5331. if (item) {
  5332. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  5333. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  5334. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  5335. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  5336. }
  5337. token = 0;
  5338. index++;
  5339. }
  5340. if (ItemInfo.price_item2_id != 0) {
  5341. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  5342. if (item) {
  5343. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  5344. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  5345. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  5346. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  5347. }
  5348. }
  5349. }
  5350. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  5351. packet->setArrayDataByName("status", ItemInfo.price_status, i);
  5352. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  5353. }
  5354. }
  5355. if (sell)
  5356. packet->setDataByName("type", 130);
  5357. else
  5358. packet->setDataByName("type", 2);
  5359. EQ2Packet* outapp = packet->serialize();
  5360. // DumpPacket(outapp);
  5361. QueuePacket(outapp);
  5362. safe_delete(packet);
  5363. }
  5364. safe_delete(items);
  5365. }
  5366. else {
  5367. // Need to send an empty packet in the event there is no item list, otherwise the
  5368. // last item list sent to the player will show for this merchant
  5369. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5370. if (packet) {
  5371. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5372. if (sell)
  5373. packet->setDataByName("type", 130);
  5374. else
  5375. packet->setDataByName("type", 2);
  5376. EQ2Packet* outapp = packet->serialize();
  5377. QueuePacket(outapp);
  5378. safe_delete(packet);
  5379. }
  5380. }
  5381. }
  5382. }
  5383. void Client::SendSellMerchantList(bool sell) {
  5384. Spawn* spawn = GetMerchantTransaction();
  5385. if (spawn && spawn->GetMerchantID() > 0) {
  5386. map<int32, Item*>* items = player->GetItemList();
  5387. if (items) {
  5388. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5389. if (packet) {
  5390. vector<Item*> sellable_items;
  5391. map<int32, Item*>::iterator test_itr;
  5392. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  5393. if (test_itr->second && !test_itr->second->CheckFlag(NO_VALUE))
  5394. sellable_items.push_back(test_itr->second);
  5395. }
  5396. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5397. packet->setArrayLengthByName("num_items", sellable_items.size());
  5398. vector<Item*>::iterator itr;
  5399. Item* item = 0;
  5400. sint8 item_difficulty = 0;
  5401. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  5402. int32 sell_price = 0;
  5403. Item* master_item = 0;
  5404. int i = 0;
  5405. int tmp_level = 0;
  5406. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  5407. item = *itr;
  5408. master_item = master_item_list.GetItem(item->details.item_id);
  5409. if (master_item)
  5410. sell_price = (int32)(master_item->sell_price * multiplier);
  5411. else
  5412. sell_price = 0;
  5413. if (sell_price > item->sell_price)
  5414. sell_price = item->sell_price;
  5415. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  5416. string thename = item->name;
  5417. packet->setArrayDataByName("price", sell_price, i);
  5418. if (player->GetGuild()) {
  5419. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  5420. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  5421. }
  5422. packet->setArrayDataByName("item_id", item->details.item_id, i);
  5423. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  5424. packet->setArrayDataByName("stack_size", item->details.count, i);
  5425. packet->setArrayDataByName("icon", item->details.icon, i);
  5426. if (item->generic_info.adventure_default_level > 0)
  5427. tmp_level = item->generic_info.adventure_default_level;
  5428. else
  5429. tmp_level = item->generic_info.tradeskill_default_level;
  5430. packet->setArrayDataByName("level", item->details.recommended_level, i);
  5431. packet->setArrayDataByName("tier", item->details.tier, i);
  5432. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  5433. item_difficulty = player->GetArrowColor(tmp_level);
  5434. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  5435. item_difficulty = ARROW_COLOR_WHITE;
  5436. item_difficulty -= 6;
  5437. if (item_difficulty < 0)
  5438. item_difficulty *= -1;
  5439. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  5440. if (item->details.count == 1)
  5441. packet->setArrayDataByName("quantity", 0xFFFF, i);
  5442. else
  5443. packet->setArrayDataByName("quantity", item->details.count, i);
  5444. packet->setArrayDataByName("stack_size2", item->details.count, i);
  5445. if (GetVersion() <= 1096)
  5446. packet->setArrayDataByName("description", item->description.c_str(), i);
  5447. }
  5448. if (sell)
  5449. packet->setDataByName("type", 129);
  5450. else
  5451. packet->setDataByName("type", 1);
  5452. packet->setDataByName("unknown8a", 16256, 6);
  5453. packet->setDataByName("unknown8a", 16256, 10);
  5454. //packet->PrintPacket();
  5455. EQ2Packet* outapp = packet->serialize();
  5456. //DumpPacket(outapp);
  5457. QueuePacket(outapp);
  5458. safe_delete(packet);
  5459. }
  5460. safe_delete(items);
  5461. }
  5462. }
  5463. }
  5464. void Client::SendBuyBackList(bool sell) {
  5465. Spawn* spawn = GetMerchantTransaction();
  5466. if (spawn && spawn->GetMerchantID() > 0) {
  5467. deque<BuyBackItem*>::iterator itr;
  5468. int i = 0;
  5469. Item* master_item = 0;
  5470. BuyBackItem* buyback = 0;
  5471. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5472. if (packet) {
  5473. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5474. packet->setArrayLengthByName("num_items", buy_back_items.size());
  5475. sint8 item_difficulty = 0;
  5476. MBuyBack.readlock(__FUNCTION__, __LINE__);
  5477. int tmp_level = 0;
  5478. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  5479. buyback = *itr;
  5480. master_item = master_item_list.GetItem(buyback->item_id);
  5481. if (master_item) {
  5482. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  5483. packet->setArrayDataByName("price", buyback->price, i);
  5484. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  5485. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  5486. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  5487. packet->setArrayDataByName("icon", master_item->details.icon, i);
  5488. if (master_item->generic_info.adventure_default_level > 0)
  5489. tmp_level = master_item->generic_info.adventure_default_level;
  5490. else
  5491. tmp_level = master_item->generic_info.tradeskill_default_level;
  5492. packet->setArrayDataByName("level", tmp_level, i);
  5493. packet->setArrayDataByName("tier", master_item->details.tier, i);
  5494. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  5495. item_difficulty = player->GetArrowColor(tmp_level);
  5496. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  5497. item_difficulty = ARROW_COLOR_WHITE;
  5498. item_difficulty -= 6;
  5499. if (item_difficulty < 0)
  5500. item_difficulty *= -1;
  5501. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  5502. if (buyback->quantity == 1)
  5503. packet->setArrayDataByName("quantity", 0xFFFF, i);
  5504. else
  5505. packet->setArrayDataByName("quantity", buyback->quantity, i);
  5506. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  5507. if (GetVersion() <= 1096)
  5508. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  5509. }
  5510. }
  5511. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  5512. if (sell)
  5513. packet->setDataByName("type", 640);
  5514. else
  5515. packet->setDataByName("type", 512);
  5516. EQ2Packet* outapp = packet->serialize();
  5517. // DumpPacket(outapp);
  5518. QueuePacket(outapp);
  5519. safe_delete(packet);
  5520. }
  5521. }
  5522. }
  5523. void Client::SendRepairList() {
  5524. Spawn* spawn = GetMerchantTransaction();
  5525. if (spawn) {
  5526. vector<Item*>* repairable_items = GetRepairableItems();
  5527. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5528. if (packet) {
  5529. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5530. packet->setArrayLengthByName("num_items", repairable_items->size());
  5531. Item* item = 0;
  5532. sint8 item_difficulty = 0;
  5533. int32 i = 0;
  5534. vector<Item*>::iterator itr;
  5535. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  5536. item = *itr;
  5537. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  5538. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  5539. packet->setArrayDataByName("item_id", item->details.item_id, i);
  5540. packet->setArrayDataByName("stack_size", item->details.count, i);
  5541. packet->setArrayDataByName("icon", item->details.icon, i);
  5542. /*if (item->generic_info.adventure_default_level > 0)
  5543. tmp_level = item->generic_info.adventure_default_level;
  5544. else
  5545. tmp_level = item->generic_info.tradeskill_default_level;
  5546. packet->setArrayDataByName("level", tmp_level, i);*/
  5547. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  5548. packet->setArrayDataByName("tier", item->details.tier, i);
  5549. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  5550. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  5551. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  5552. item_difficulty = ARROW_COLOR_WHITE;
  5553. item_difficulty -= 6;
  5554. if (item_difficulty < 0)
  5555. item_difficulty *= -1;
  5556. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  5557. if (item->details.count == 1)
  5558. packet->setArrayDataByName("quantity", 0xFFFF, i);
  5559. else
  5560. packet->setArrayDataByName("quantity", item->details.count, i);
  5561. packet->setArrayDataByName("stack_size2", item->details.count, i);
  5562. if (GetVersion() <= 1096)
  5563. packet->setArrayDataByName("description", item->description.c_str(), i);
  5564. }
  5565. packet->setDataByName("type", 96);
  5566. EQ2Packet* outapp = packet->serialize();
  5567. QueuePacket(outapp);
  5568. safe_delete(packet);
  5569. }
  5570. safe_delete(repairable_items);
  5571. }
  5572. }
  5573. void Client::ShowLottoWindow() {
  5574. Spawn* spawn = GetMerchantTransaction();
  5575. if (spawn) {
  5576. int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
  5577. if (!item_id)
  5578. {
  5579. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  5580. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  5581. return;
  5582. }
  5583. else if (item_id == 0)
  5584. {
  5585. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  5586. return;
  5587. }
  5588. Item* item = master_item_list.GetItem(item_id);
  5589. if (!item) {
  5590. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  5591. return;
  5592. }
  5593. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  5594. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5595. if (packet) {
  5596. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5597. packet->setArrayLengthByName("num_items", 1);
  5598. packet->setArrayDataByName("item_name", item->name.c_str());
  5599. packet->setArrayDataByName("price", item->sell_price);
  5600. packet->setArrayDataByName("item_id", item->details.item_id);
  5601. packet->setArrayDataByName("stack_size", item->details.count);
  5602. packet->setArrayDataByName("icon", item->details.icon);
  5603. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  5604. packet->setArrayDataByName("tier", item->details.tier);
  5605. packet->setArrayDataByName("item_id2", item->details.item_id);
  5606. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  5607. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  5608. item_difficulty = ARROW_COLOR_WHITE;
  5609. item_difficulty -= 6;
  5610. if (item_difficulty < 0)
  5611. item_difficulty *= -1;
  5612. packet->setArrayDataByName("item_difficulty", item_difficulty);
  5613. //if(item->details.count == 1)
  5614. packet->setArrayDataByName("quantity", 0xFFFF);
  5615. //else
  5616. // packet->setArrayDataByName("quantity", item->details.count);
  5617. packet->setArrayDataByName("stack_size2", item->details.count);
  5618. packet->setArrayDataByName("description", item->description.c_str());
  5619. packet->setDataByName("type", 0x00000102);
  5620. QueuePacket(packet->serialize());
  5621. safe_delete(packet);
  5622. }
  5623. }
  5624. }
  5625. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  5626. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  5627. if (packet) {
  5628. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  5629. int32 rolls[6] = { 0 };
  5630. int32 lottery_digits[6] = { 0 };
  5631. int8 num_matches = 0;
  5632. int64 jackpot = 0;
  5633. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  5634. if (!item) {
  5635. return;
  5636. }
  5637. database.DeleteItem(GetCharacterID(), item, 0);
  5638. GetPlayer()->item_list.RemoveItem(item, true);
  5639. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  5640. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  5641. if (!winning_numbers) {
  5642. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  5643. variables.AddVariable(winning_numbers);
  5644. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  5645. }
  5646. if (strlen(winning_numbers->GetValue()) != 12) {
  5647. winning_numbers->SetValue("231205182236");
  5648. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  5649. }
  5650. try {
  5651. for (int32 i = 0; i < 12; i += 2) {
  5652. char num[4];
  5653. strncpy(num, winning_numbers->GetValue() + i, 2);
  5654. lottery_digits[i / 2] = atoi(num);
  5655. }
  5656. }
  5657. catch (...) {
  5658. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  5659. return;
  5660. }
  5661. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  5662. if (!jackpot_var) {
  5663. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  5664. variables.AddVariable(jackpot_var);
  5665. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  5666. }
  5667. try {
  5668. jackpot = atoul(jackpot_var->GetValue());
  5669. if (jackpot < 10000)
  5670. jackpot = 10000;
  5671. }
  5672. catch (...) {
  5673. jackpot = 10000;
  5674. }
  5675. char new_jackpot[128] = { 0 };
  5676. sprintf(new_jackpot, "%llu", jackpot + price);
  5677. jackpot_var->SetValue(new_jackpot);
  5678. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  5679. world.PickRandomLottoDigits(rolls);
  5680. packet->setDataByName("roll_digit1", rolls[0]);
  5681. packet->setDataByName("roll_digit2", rolls[1]);
  5682. packet->setDataByName("roll_digit3", rolls[2]);
  5683. packet->setDataByName("roll_digit4", rolls[3]);
  5684. packet->setDataByName("roll_digit5", rolls[4]);
  5685. packet->setDataByName("roll_digit6", rolls[5]);
  5686. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  5687. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  5688. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  5689. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  5690. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  5691. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  5692. QueuePacket(packet->serialize());
  5693. safe_delete(packet);
  5694. for (int32 i = 0; i < 6; i++) {
  5695. for (int32 j = 0; j < 6; j++) {
  5696. if (rolls[i] == lottery_digits[j]) {
  5697. num_matches++;
  5698. break;
  5699. }
  5700. }
  5701. }
  5702. char new_jackpot_str[16];
  5703. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  5704. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  5705. if (num_matches == 6) {
  5706. world.PickRandomLottoDigits(lottery_digits);
  5707. for (int32 i = 0; i < 12; i += 2)
  5708. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  5709. winning_numbers->SetValue(new_jackpot_str);
  5710. jackpot_var->SetValue("10000");
  5711. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  5712. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  5713. }
  5714. }
  5715. }
  5716. void Client::SendGuildCreateWindow() {
  5717. Spawn* spawn = GetPlayer()->GetTarget();
  5718. if (spawn) {
  5719. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5720. if (packet) {
  5721. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5722. packet->setArrayLengthByName("num_items", 0);
  5723. packet->setDataByName("type", 0x00008000);
  5724. QueuePacket(packet->serialize());
  5725. safe_delete(packet);
  5726. }
  5727. }
  5728. }
  5729. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  5730. BuyBackItem* item = new BuyBackItem;
  5731. item->item_id = item_id;
  5732. item->unique_id = unique_id;
  5733. item->price = price;
  5734. item->quantity = quantity;
  5735. item->save_needed = save_needed;
  5736. MBuyBack.writelock(__FUNCTION__, __LINE__);
  5737. buy_back_items.push_back(item);
  5738. if (buy_back_items.size() > 10) {
  5739. safe_delete(buy_back_items.front());
  5740. buy_back_items.pop_front();
  5741. }
  5742. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  5743. }
  5744. deque<BuyBackItem*>* Client::GetBuyBacks() {
  5745. return &buy_back_items;
  5746. }
  5747. vector<Item*>* Client::GetRepairableItems() {
  5748. vector<Item*>* repairable_items = new vector<Item*>;
  5749. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  5750. map<int32, Item*>* items = player->GetItemList();
  5751. if (equipped_items && equipped_items->size() > 0) {
  5752. for (int32 i = 0; i < equipped_items->size(); i++) {
  5753. Item* item = equipped_items->at(i);
  5754. if (item && item->generic_info.condition < 100)
  5755. repairable_items->push_back(item);
  5756. }
  5757. }
  5758. if (items && items->size() > 0) {
  5759. map<int32, Item*>::iterator itr;
  5760. for (itr = items->begin(); itr != items->end(); itr++) {
  5761. Item* item = itr->second;
  5762. if (item && item->generic_info.condition < 100)
  5763. repairable_items->push_back(item);
  5764. }
  5765. }
  5766. safe_delete(equipped_items);
  5767. safe_delete(items);
  5768. return repairable_items;
  5769. }
  5770. void Client::SendMailList() {
  5771. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  5772. if (kiosk_id > 0) {
  5773. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  5774. if (p) {
  5775. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  5776. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  5777. int16 i = 0;
  5778. p->setDataByName("kiosk_id", kiosk_id);
  5779. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  5780. while (itr.Next()) {
  5781. Mail* mail = itr->second;
  5782. p->setArrayDataByName("mail_id", mail->mail_id, i);
  5783. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  5784. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  5785. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  5786. p->setArrayDataByName("unknown1", 0x0000, i);
  5787. p->setArrayDataByName("already_read", mail->already_read, i);
  5788. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  5789. p->setArrayDataByName("mail_type", mail->mail_type, i);
  5790. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  5791. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  5792. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  5793. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  5794. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  5795. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  5796. p->setArrayDataByName("num_items", mail->stack, i);
  5797. p->setArrayDataByName("packettype", GetItemPacketType(GetVersion()));
  5798. p->setArrayDataByName("packetsubtype", 0xFF, i);
  5799. p->setArrayDataByName("unknown2", 0, i);
  5800. //p->setArrayDataByName("item_id", 5, i, 0);
  5801. //Item* item = master_item_list.GetItem(5);
  5802. //if (item)
  5803. // printf("%s\n", item->name.c_str());
  5804. //else
  5805. // printf("no item\n");
  5806. //p->setItemArrayDataByName("item", master_item_list.GetItem(5), i, 0);
  5807. i++;
  5808. }
  5809. // GMs send mail for free!
  5810. if (GetAdminStatus() > 0)
  5811. {
  5812. p->setDataByName("postage_cost", 0);
  5813. p->setDataByName("attachment_cost", 0);
  5814. }
  5815. else
  5816. {
  5817. p->setDataByName("postage_cost", 10);
  5818. p->setDataByName("attachment_cost", 50);
  5819. }
  5820. p->setDataByName("unknown3", 0x01F4);
  5821. p->setDataByName("unknown4", 0x01000000);
  5822. QueuePacket(p->serialize());
  5823. safe_delete(p);
  5824. }
  5825. }
  5826. else
  5827. SimpleMessage(CHANNEL_COLOR_MAIL, "You are currently not in a mail transaction.");
  5828. }
  5829. void Client::DisplayMailMessage(int32 mail_id) {
  5830. Mail* mail = player->GetMail(mail_id);
  5831. if (mail) {
  5832. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  5833. if (kiosk_id > 0) {
  5834. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  5835. if (update) {
  5836. update->setDataByName("action", 0x03);
  5837. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  5838. update->setDataByName("packetsubtype", 0xFF);
  5839. QueuePacket(update->serialize());
  5840. safe_delete(update);
  5841. }
  5842. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  5843. if (packet) {
  5844. packet->setDataByName("kiosk_id", kiosk_id);
  5845. packet->setDataByName("mail_id", mail->mail_id);
  5846. packet->setDataByName("player_to_id", mail->player_to_id);
  5847. packet->setDataByName("player_from", mail->player_from.c_str());
  5848. packet->setDataByName("subject", mail->subject.c_str());
  5849. packet->setDataByName("mail_body", mail->mail_body.c_str());
  5850. packet->setDataByName("unknown1", 1);
  5851. packet->setDataByName("unknown2", 0);
  5852. packet->setDataByName("lock_report_button", 1);
  5853. packet->setDataByName("unknown3", 0xFFFFFFFF);
  5854. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  5855. packet->setDataByName("coin_copper", mail->coin_copper);
  5856. packet->setDataByName("coin_silver", mail->coin_silver);
  5857. packet->setDataByName("coin_gold", mail->coin_gold);
  5858. packet->setDataByName("coin_plat", mail->coin_plat);
  5859. packet->setDataByName("stack", mail->stack);
  5860. packet->setDataByName("packettype", GetItemPacketType(GetVersion()));
  5861. packet->setDataByName("packetsubtype", 0xFF);
  5862. packet->setDataByName("unknown4", 0);
  5863. packet->setDataByName("unknown5", 0);
  5864. packet->setDataByName("unknown6", 0);
  5865. packet->setDataByName("unknown7", 0);
  5866. mail->already_read = true;
  5867. mail->save_needed = true;
  5868. QueuePacket(packet->serialize());
  5869. safe_delete(packet);
  5870. //SendMailList();
  5871. }
  5872. }
  5873. else
  5874. SimpleMessage(CHANNEL_COLOR_MAIL, "You are currently not in a mail transaction.");
  5875. }
  5876. }
  5877. /* This is called when the client sends a mail message. This determines whether or not the mail can be sent and must send the reply
  5878. packet back to the client before the mail actually sent. */
  5879. void Client::HandleSentMail(EQApplicationPacket* app) {
  5880. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  5881. if (packet) {
  5882. packet->LoadPacketData(app->pBuffer, app->size);
  5883. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  5884. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  5885. vector<int32>* ids = 0;
  5886. if (reply_packet) {
  5887. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  5888. if (player_to.length() == 0)
  5889. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  5890. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  5891. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  5892. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  5893. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  5894. else {
  5895. if (player_to.compare("<all>") == 0) {
  5896. if (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat == 0)
  5897. ids = database.GetAllPlayerIDs();
  5898. else
  5899. SimpleMessage(CHANNEL_COLOR_MAIL, "You may not mail gifts to multiple players.");
  5900. }
  5901. else {
  5902. ids = new vector<int32>;
  5903. ids->push_back(database.GetCharacterID(player_to.c_str()));
  5904. }
  5905. if (ids) {
  5906. for (int32 i = 0; i < ids->size(); i++) {
  5907. int32 player_to_id = ids->at(i);
  5908. if (player_to_id > 0) {
  5909. reply_type = MAIL_SEND_RESULT_SUCCESS;
  5910. Mail* mail = new Mail;
  5911. mail->mail_id = 0;
  5912. mail->player_to_id = player_to_id;
  5913. mail->player_from = string(GetPlayer()->GetName());
  5914. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  5915. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  5916. mail->already_read = 0;
  5917. mail->mail_type = MAIL_TYPE_REGULAR;
  5918. mail->coin_copper = mail_window.coin_copper;
  5919. mail->coin_silver = mail_window.coin_silver;
  5920. mail->coin_gold = mail_window.coin_gold;
  5921. mail->coin_plat = mail_window.coin_plat;
  5922. mail->stack = 0;
  5923. // GM's send mail for free!
  5924. if (GetAdminStatus() > 0)
  5925. {
  5926. mail->postage_cost = 0;
  5927. mail->attachment_cost = 0;
  5928. }
  5929. else
  5930. {
  5931. mail->postage_cost = 10;
  5932. mail->attachment_cost = 50;
  5933. }
  5934. mail->char_item_id = 0;
  5935. mail->time_sent = Timer::GetUnixTimeStamp();
  5936. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  5937. //int16 packettype = packet->getType_int16_ByName("packettype");
  5938. //int8 packetsubtype = packet->getType_int8_ByName("packetsubtype");
  5939. /*int32 postage_cost = packet->getType_int32_ByName("postage_cost");
  5940. int32 attachment_cost = packet->getType_int32_ByName("attachment_cost");
  5941. if (postage_cost > 0 || attachment_cost > 0)
  5942. PlaySoundA("coin_cha_ching");*/
  5943. mail->save_needed = false;
  5944. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  5945. if (to_client) {
  5946. to_client->GetPlayer()->AddMail(mail);
  5947. to_client->SimpleMessage(CHANNEL_COLOR_MAIL, "You've got mail! :)");
  5948. }
  5949. database.SavePlayerMail(mail);
  5950. mail_window.coin_copper = 0;
  5951. mail_window.coin_silver = 0;
  5952. mail_window.coin_gold = 0;
  5953. mail_window.coin_plat = 0;
  5954. }
  5955. else
  5956. reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
  5957. }
  5958. }
  5959. }
  5960. string players_to = "";
  5961. if (ids) {
  5962. for (int32 i = 0; i < ids->size(); i++) {
  5963. if (ids->at(i) != 0)
  5964. players_to.append(database.GetCharacterName(ids->at(i)));
  5965. if (i < (ids->size() - 1))
  5966. players_to.append(", ");
  5967. }
  5968. }
  5969. reply_packet->setDataByName("player_to", players_to.c_str());
  5970. reply_packet->setDataByName("reply_type", reply_type);
  5971. QueuePacket(reply_packet->serialize());
  5972. safe_delete(reply_packet);
  5973. safe_delete(ids);
  5974. }
  5975. safe_delete(packet);
  5976. }
  5977. }
  5978. void Client::DeleteMail(int32 mail_id, bool from_database) {
  5979. player->DeleteMail(mail_id, from_database);
  5980. }
  5981. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  5982. bool ret = false;
  5983. if (GetMailTransaction()) {
  5984. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  5985. if (packet) {
  5986. if (copper > 0) {
  5987. if (player->RemoveCoins(copper)) {
  5988. mail_window.coin_copper += copper;
  5989. Message(CHANNEL_COLOR_MAIL, "You add %u copper to the mail window.", copper);
  5990. ret = true;
  5991. }
  5992. }
  5993. else if (silver > 0) {
  5994. if (player->RemoveCoins(silver * 100)) {
  5995. mail_window.coin_silver += silver;
  5996. Message(CHANNEL_COLOR_MAIL, "You add %u silver to the mail window.", silver);
  5997. ret = true;
  5998. }
  5999. }
  6000. else if (gold > 0) {
  6001. if (player->RemoveCoins(gold * 10000)) {
  6002. mail_window.coin_gold += gold;
  6003. Message(CHANNEL_COLOR_MAIL, "You add %u gold to the mail window.", gold);
  6004. ret = true;
  6005. }
  6006. }
  6007. else if (plat > 0) {
  6008. if (player->RemoveCoins(plat * 1000000)) {
  6009. mail_window.coin_plat += plat;
  6010. Message(CHANNEL_COLOR_MAIL, "You add %u platinum to the mail window.", plat);
  6011. ret = true;
  6012. }
  6013. }
  6014. if (ret) {
  6015. packet->setDataByName("coin_copper", mail_window.coin_copper);
  6016. packet->setDataByName("coin_silver", mail_window.coin_silver);
  6017. packet->setDataByName("coin_gold", mail_window.coin_gold);
  6018. packet->setDataByName("coin_plat", mail_window.coin_plat);
  6019. packet->setDataByName("stack", 0);
  6020. packet->setDataByName("packettype", GetItemPacketType(version));
  6021. packet->setDataByName("packetsubtype", 0xFF);
  6022. packet->setDataByName("unknown2", 0);
  6023. //packet->PrintPacket();
  6024. QueuePacket(packet->serialize());
  6025. }
  6026. else
  6027. SimpleMessage(CHANNEL_COLOR_MAIL, "You don't have that much money.");
  6028. safe_delete(packet);
  6029. }
  6030. }
  6031. else
  6032. SimpleMessage(CHANNEL_COLOR_MAIL, "You are currently not in a mail transaction.");
  6033. return ret;
  6034. }
  6035. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  6036. bool ret = false;
  6037. if (GetMailTransaction()) {
  6038. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6039. if (packet) {
  6040. if (copper > 0) {
  6041. player->AddCoins(copper);
  6042. mail_window.coin_copper -= copper;
  6043. Message(CHANNEL_COLOR_MAIL, "You remove %u copper from the mail window.", copper);
  6044. ret = true;
  6045. }
  6046. else if (silver > 0) {
  6047. player->AddCoins(silver * 100);
  6048. mail_window.coin_silver -= silver;
  6049. Message(CHANNEL_COLOR_MAIL, "You remove %u silver from the mail window.", silver);
  6050. ret = true;
  6051. }
  6052. else if (gold > 0) {
  6053. player->AddCoins(gold * 10000);
  6054. mail_window.coin_gold -= gold;
  6055. Message(CHANNEL_COLOR_MAIL, "You remove %u gold from the mail window.", gold);
  6056. ret = true;
  6057. }
  6058. else if (plat > 0) {
  6059. player->AddCoins(plat * 1000000);
  6060. mail_window.coin_plat -= plat;
  6061. Message(CHANNEL_COLOR_MAIL, "You remove %u platinum from the mail window.", plat);
  6062. ret = true;
  6063. }
  6064. if (ret) {
  6065. packet->setDataByName("coin_copper", mail_window.coin_copper);
  6066. packet->setDataByName("coin_silver", mail_window.coin_silver);
  6067. packet->setDataByName("coin_gold", mail_window.coin_gold);
  6068. packet->setDataByName("coin_plat", mail_window.coin_plat);
  6069. packet->setDataByName("stack", 0);
  6070. packet->setDataByName("packettype", 0x2BFE);
  6071. packet->setDataByName("packetsubtype", 0xFF);
  6072. packet->setDataByName("unknown2", 0);
  6073. QueuePacket(packet->serialize());
  6074. }
  6075. safe_delete(packet);
  6076. }
  6077. }
  6078. else
  6079. SimpleMessage(CHANNEL_COLOR_MAIL, "You are currently not in a mail transaction.");
  6080. return ret;
  6081. }
  6082. void Client::TakeMailAttachments(int32 mail_id) {
  6083. if (GetMailTransaction()) {
  6084. Mail* mail = player->GetMail(mail_id);
  6085. if (mail) {
  6086. int64 amount = 0;
  6087. if (mail->coin_copper > 0) {
  6088. amount += mail->coin_copper;
  6089. mail->coin_copper = 0;
  6090. }
  6091. if (mail->coin_silver > 0) {
  6092. amount += mail->coin_silver * 100;
  6093. mail->coin_silver = 0;
  6094. }
  6095. if (mail->coin_gold > 0) {
  6096. amount += mail->coin_gold * 10000;
  6097. mail->coin_gold = 0;
  6098. }
  6099. if (mail->coin_plat > 0) {
  6100. amount += mail->coin_plat * 1000000;
  6101. mail->coin_plat = 0;
  6102. }
  6103. if (mail->char_item_id > 0) {
  6104. LogWrite(MISC__TODO, 1, "TODO", "Items by Mail\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  6105. }
  6106. /* Can't find the right packet to send to update the player's mail. This packet below updates the mail the player is sending, not
  6107. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  6108. find it in any packet logs.*/
  6109. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6110. if (packet) {
  6111. packet->setDataByName("unknown", 0x03);
  6112. packet->setDataByName("coin_copper", mail->coin_copper);
  6113. packet->setDataByName("coin_silver", mail->coin_silver);
  6114. packet->setDataByName("coin_gold", mail->coin_gold);
  6115. packet->setDataByName("coin_plat", mail->coin_plat);
  6116. packet->setDataByName("stack", 0);
  6117. packet->setDataByName("packettype", 0x2BFE);
  6118. packet->setDataByName("packetsubtype", 0xFF);
  6119. packet->setDataByName("unknown2", 0);
  6120. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  6121. DumpPacket(packet->serialize());
  6122. QueuePacket(packet->serialize());
  6123. safe_delete(packet);
  6124. }*/
  6125. database.SavePlayerMail(mail);
  6126. if (amount > 0)
  6127. player->AddCoins(amount);
  6128. SendMailList();
  6129. }
  6130. }
  6131. else
  6132. SimpleMessage(CHANNEL_COLOR_MAIL, "You are currently not in a mail transaction.");
  6133. }
  6134. void Client::CancelSendMail() {
  6135. SimpleMessage(CHANNEL_COLOR_MAIL, "You cancel sending a letter.");
  6136. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  6137. mail_window.coin_copper = 0;
  6138. mail_window.coin_silver = 0;
  6139. mail_window.coin_gold = 0;
  6140. mail_window.coin_plat = 0;
  6141. mail_window.char_item_id = 0;
  6142. }
  6143. bool Client::GateAllowed() {
  6144. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  6145. LogWrite(MISC__TODO, 1, "TODO", "possibly add a check here to see if a player is allowed to gate from this spot, allow for now\nfile: %s, func: %s, line: %i", __FILE__, __FUNCTION__, __LINE__);
  6146. if (zone)
  6147. return true;
  6148. return false;
  6149. }
  6150. bool Client::BindAllowed() {
  6151. LogWrite(MISC__TODO, 1, "TODO", "possibly add a check here to see if a player is allowed to bind in this spot, allow anywhere for now\nfile: %s, func: %s, line: %i", __FILE__, __FUNCTION__, __LINE__);
  6152. return true;
  6153. }
  6154. bool Client::Bind() {
  6155. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  6156. player->GetPlayerInfo()->SetBindX(player->GetX());
  6157. player->GetPlayerInfo()->SetBindY(player->GetY());
  6158. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  6159. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  6160. return true;
  6161. }
  6162. bool Client::Gate() {
  6163. if (player->GetPlayerInfo()->GetBindZoneID() == 0)
  6164. return false;
  6165. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  6166. if (zone) {
  6167. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  6168. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  6169. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  6170. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  6171. Zone(zone, false);
  6172. return true;
  6173. }
  6174. return false;
  6175. }
  6176. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id) {
  6177. if (!destinations || !spawn) {
  6178. return;
  6179. }
  6180. bool has_map = false;
  6181. if (transport_id > 0)
  6182. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  6183. transport_spawn = spawn;
  6184. vector<TransportDestination*> transport_list;
  6185. vector<TransportDestination*>::iterator itr;
  6186. TransportDestination* destination = 0;
  6187. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  6188. destination = *itr;
  6189. if (has_map || (destination->type == TRANSPORT_TYPE_ZONE && ((destination->destination_zone_id != GetCurrentZone()->GetZoneID()) || GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) > 100)))
  6190. transport_list.push_back(destination);
  6191. }
  6192. if (transport_list.size() == 0 && destination) {
  6193. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  6194. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  6195. if (app)
  6196. QueuePacket(app);
  6197. }
  6198. else {
  6199. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  6200. // determine if this is an instanced zone that already exists
  6201. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
  6202. if (instance_zone || new_zone) {
  6203. GetPlayer()->SetX(destination->destination_x);
  6204. GetPlayer()->SetY(destination->destination_y);
  6205. GetPlayer()->SetZ(destination->destination_z);
  6206. GetPlayer()->SetHeading(destination->destination_heading);
  6207. if (instance_zone)
  6208. Zone(instance_zone->GetInstanceID(), false, true);
  6209. else
  6210. Zone(new_zone, false);
  6211. }
  6212. }
  6213. if (destination->message.length() > 0)
  6214. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  6215. }
  6216. else if (transport_list.size() > 0) {
  6217. PlaySound("mariner_bell");
  6218. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  6219. if (packet) {
  6220. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  6221. // Put all the destinations the player can go in a new vector
  6222. vector<TransportDestination*> destinations;
  6223. for (int32 i = 0; i < transport_list.size(); i++) {
  6224. destination = transport_list.at(i);
  6225. // Check min level
  6226. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  6227. continue;
  6228. // Check max level
  6229. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  6230. continue;
  6231. // Check quest complete
  6232. if (destination->req_quest_complete > 0 && GetPlayer()->GetCompletedQuest(destination->req_quest_complete) == 0)
  6233. continue;
  6234. // Check req quest and step
  6235. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  6236. continue;
  6237. // If we have a map and our current location is the same as the detination and player is within 20 units from the transport set the "current" elements but don't addt to the destination list
  6238. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  6239. packet->setDataByName("current_zone", destination->display_name.c_str());
  6240. packet->setDataByName("current_map_x", destination->map_x);
  6241. packet->setDataByName("current_map_y", destination->map_y);
  6242. }
  6243. else {
  6244. destinations.push_back(destination);
  6245. }
  6246. }
  6247. // Use the new vector to create the packet
  6248. destination = 0;
  6249. packet->setArrayLengthByName("num_destinations", destinations.size());
  6250. for (int32 i = 0; i < destinations.size(); i++) {
  6251. destination = destinations.at(i);
  6252. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  6253. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  6254. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  6255. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  6256. packet->setArrayDataByName("cost", destination->cost, i);
  6257. if (has_map) {
  6258. packet->setArrayDataByName("map_x", destination->map_x, i);
  6259. packet->setArrayDataByName("map_y", destination->map_y, i);
  6260. }
  6261. }
  6262. if (has_map)
  6263. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  6264. EQ2Packet* app = packet->serialize();
  6265. //DumpPacket(app);
  6266. if (destinations.size() > 0)
  6267. QueuePacket(app);
  6268. safe_delete(packet);
  6269. }
  6270. }
  6271. }
  6272. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  6273. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  6274. if (packet) {
  6275. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  6276. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  6277. int32 unique_id = packet->getType_int32_ByName("unique_id");
  6278. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  6279. int32 cost = packet->getType_int32_ByName("cost");
  6280. vector<TransportDestination*>* destinations = 0;
  6281. TransportDestination* destination = 0;
  6282. if (spawn && spawn == transport_spawn && spawn->GetTransporterID() > 0)
  6283. destinations = GetCurrentZone()->GetTransporters(spawn->GetTransporterID());
  6284. if (destinations) {
  6285. vector<TransportDestination*>::iterator itr;
  6286. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  6287. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  6288. destination = *itr;
  6289. break;
  6290. }
  6291. }
  6292. }
  6293. if (!destination)
  6294. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  6295. else {
  6296. if (cost == 0 || player->RemoveCoins(cost)) {
  6297. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  6298. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  6299. if (outapp)
  6300. QueuePacket(outapp);
  6301. }
  6302. else {
  6303. GetPlayer()->SetX(destination->destination_x);
  6304. GetPlayer()->SetY(destination->destination_y);
  6305. GetPlayer()->SetZ(destination->destination_z);
  6306. GetPlayer()->SetHeading(destination->destination_heading);
  6307. // Test if where we're going is an Instanced zone
  6308. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  6309. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  6310. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  6311. Zone(new_zone, false);
  6312. }
  6313. }
  6314. if (destination->message.length() > 0)
  6315. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  6316. }
  6317. else
  6318. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  6319. }
  6320. }
  6321. safe_delete(packet);
  6322. }
  6323. }
  6324. void Client::SendNewSpells(int8 class_id) {
  6325. if (class_id > 0) {
  6326. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  6327. vector<Spell*>::iterator itr;
  6328. Spell* spell = 0;
  6329. bool send_updates = false;
  6330. for (itr = spells->begin(); itr != spells->end(); itr++) {
  6331. spell = *itr;
  6332. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  6333. send_updates = true;
  6334. SendSpellUpdate(spell);
  6335. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  6336. player->UnlockSpell(spell);
  6337. }
  6338. }
  6339. if (send_updates) {
  6340. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  6341. if (outapp)
  6342. QueuePacket(outapp);
  6343. }
  6344. safe_delete(spells);
  6345. }
  6346. }
  6347. void Client::SetItemSearch(vector<Item*>* items) {
  6348. if (items) {
  6349. safe_delete(search_items);
  6350. search_items = items;
  6351. }
  6352. }
  6353. vector<Item*>* Client::GetSearchItems() {
  6354. return search_items;
  6355. }
  6356. void Client::SearchStore(int32 page) {
  6357. if (search_items) {
  6358. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  6359. if (packet) {
  6360. int32 x = page * 8;
  6361. if (search_items->size() > 8) {
  6362. if ((search_items->size() - x) > 8)
  6363. packet->setArrayLengthByName("num_items", 8);
  6364. else
  6365. packet->setArrayLengthByName("num_items", search_items->size() - x);
  6366. }
  6367. else
  6368. packet->setArrayLengthByName("num_items", search_items->size());
  6369. if (search_items->size() > 0) {
  6370. packet->setArrayLengthByName("num_sellers", 1);
  6371. packet->setArrayDataByName("seller_seller_id", 1);
  6372. packet->setArrayDataByName("seller_name", "EQ2EmuDevs");
  6373. packet->setDataByName("per_page", 8);
  6374. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  6375. packet->setDataByName("page", page);
  6376. Item* item = 0;
  6377. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  6378. for (int32 i = 0; i < limit; i++, x++) {
  6379. if (x >= search_items->size())
  6380. break;
  6381. item = search_items->at(x);
  6382. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6383. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6384. packet->setArrayDataByName("icon", item->details.icon, i);
  6385. //packet->setArrayDataByName("unknown2b", i, i);
  6386. packet->setArrayDataByName("item_seller_id", 1, i);
  6387. if (item->stack_count == 0)
  6388. packet->setArrayDataByName("quantity", 1, i);
  6389. else
  6390. packet->setArrayDataByName("quantity", item->stack_count, i);
  6391. packet->setArrayDataByName("stack_size", item->stack_count, i);
  6392. std::string tmpStr("");
  6393. tmpStr.append(item->name.c_str());
  6394. tmpStr.append(" (");
  6395. tmpStr.append(std::to_string(item->details.item_id));
  6396. tmpStr.append(")");
  6397. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  6398. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  6399. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  6400. }
  6401. }
  6402. /*EQ2Packet* outapp = packet->serialize();
  6403. DumpPacket(outapp);
  6404. QueuePacket(outapp);*/
  6405. QueuePacket(packet->serialize());
  6406. safe_delete(packet);
  6407. }
  6408. }
  6409. }
  6410. void Client::SetReadyForSpawns(bool val) {
  6411. ready_for_spawns = val;
  6412. if (GetPlayer()->GetActivityStatus() > 0) {
  6413. GetPlayer()->SetActivityStatus(0);
  6414. if (GetPlayer()->GetGroupMemberInfo()) {
  6415. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  6416. }
  6417. }
  6418. zone_list.CheckFriendZoned(this);
  6419. }
  6420. void Client::SendChatRelationship(int8 type, const char* name) {
  6421. if (!name) {
  6422. return;
  6423. }
  6424. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  6425. if (packet) {
  6426. packet->setDataByName("account_id", GetAccountID());
  6427. packet->setDataByName("type", type);
  6428. packet->setArrayLengthByName("num_names", 1);
  6429. packet->setArrayDataByName("name", name);
  6430. if (type == 0) {
  6431. Client* client = zone_list.GetClientByCharName(name);
  6432. if (client) {
  6433. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  6434. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  6435. }
  6436. }
  6437. QueuePacket(packet->serialize());
  6438. safe_delete(packet);
  6439. }
  6440. }
  6441. void Client::SendFriendList() {
  6442. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  6443. if (packet) {
  6444. packet->setDataByName("account_id", GetAccountID());
  6445. map<string, int8>::iterator itr;
  6446. map<string, int8>* friends = player->GetFriends();
  6447. if (friends && friends->size() > 0) {
  6448. Client* client = 0;
  6449. vector<string> names;
  6450. for (itr = friends->begin(); itr != friends->end(); itr++) {
  6451. if (itr->second == 2)
  6452. continue;
  6453. names.push_back(itr->first);
  6454. }
  6455. packet->setArrayLengthByName("num_names", names.size());
  6456. for (int32 i = 0; i < names.size(); i++) {
  6457. client = zone_list.GetClientByCharName(names[i]);
  6458. packet->setArrayDataByName("name", names[i].c_str(), i);
  6459. if (client) {
  6460. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  6461. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  6462. }
  6463. }
  6464. }
  6465. QueuePacket(packet->serialize());
  6466. safe_delete(packet);
  6467. }
  6468. }
  6469. void Client::SendIgnoreList() {
  6470. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  6471. if (packet) {
  6472. packet->setDataByName("account_id", GetAccountID());
  6473. packet->setDataByName("type", 2);
  6474. map<string, int8>::iterator itr;
  6475. map<string, int8>* ignored = player->GetIgnoredPlayers();
  6476. if (ignored && ignored->size() > 0) {
  6477. vector<string> names;
  6478. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  6479. if (itr->second == 2)
  6480. continue;
  6481. names.push_back(itr->first);
  6482. }
  6483. packet->setArrayLengthByName("num_names", names.size());
  6484. for (int32 i = 0; i < names.size(); i++)
  6485. packet->setArrayDataByName("name", names[i].c_str(), i);
  6486. }
  6487. QueuePacket(packet->serialize());
  6488. safe_delete(packet);
  6489. }
  6490. }
  6491. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  6492. if (waypoint_name) {
  6493. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  6494. if (packet) {
  6495. packet->setArrayLengthByName("num_updates", 1);
  6496. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  6497. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  6498. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  6499. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  6500. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  6501. QueuePacket(packet->serialize());
  6502. safe_delete(packet);
  6503. }
  6504. }
  6505. }
  6506. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  6507. if (waypoint_name) {
  6508. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  6509. if (packet) {
  6510. packet->setArrayLengthByName("num_points", 1);
  6511. packet->setArrayDataByName("x", x, 0);
  6512. packet->setArrayDataByName("y", y, 0);
  6513. packet->setArrayDataByName("z", z, 0);
  6514. packet->setDataByName("waypoint_x", x);
  6515. packet->setDataByName("waypoint_y", y);
  6516. packet->setDataByName("waypoint_z", z);
  6517. packet->setDataByName("waypoint_name", waypoint_name);
  6518. packet->setDataByName("unknown", 0);
  6519. QueuePacket(packet->serialize());
  6520. safe_delete(packet);
  6521. }
  6522. }
  6523. }
  6524. void Client::InspectPlayer(Player* player_to_inspect) {
  6525. if (player_to_inspect) {
  6526. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  6527. if (packet) {
  6528. packet->setDataByName("unknown", 0);
  6529. packet->setSmallStringByName("name", player_to_inspect->GetName());
  6530. packet->setDataByName("race", player_to_inspect->GetRace());
  6531. packet->setDataByName("gender", player_to_inspect->GetGender());
  6532. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  6533. LogWrite(MISC__TODO, 1, "TODO", "Put mentored level here (adventure_level_effective)\nfile: %s, func: %s, line: %i", __FILE__, __FUNCTION__, __LINE__);
  6534. packet->setDataByName("adventure_level_effective", player_to_inspect->GetLevel());
  6535. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  6536. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  6537. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  6538. packet->setDataByName("health", player_to_inspect->GetHP());
  6539. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  6540. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  6541. packet->setDataByName("power", player_to_inspect->GetPower());
  6542. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  6543. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  6544. packet->setDataByName("mitigation", 0);
  6545. packet->setDataByName("unknown1", 0);
  6546. packet->setDataByName("avoidance", 0);
  6547. packet->setDataByName("unknown2", 0);
  6548. packet->setDataByName("mitigation_percentage", 0);
  6549. packet->setDataByName("strength", player_to_inspect->GetStr());
  6550. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  6551. packet->setDataByName("stamina", player_to_inspect->GetSta());
  6552. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  6553. packet->setDataByName("agility", player_to_inspect->GetAgi());
  6554. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  6555. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  6556. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  6557. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  6558. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  6559. packet->setDataByName("unknown4", 0);
  6560. packet->setDataByName("unknown5", 0);
  6561. packet->setDataByName("unknown6", 0);
  6562. packet->setDataByName("unknown7", 0);
  6563. packet->setDataByName("unknown8", 0);
  6564. packet->setDataByName("unknown9", 0);
  6565. packet->setDataByName("unknown10", 0);
  6566. packet->setDataByName("unknown11", 0);
  6567. packet->setDataByName("unknown12", 0);
  6568. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  6569. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  6570. packet->setDataByName("heat_resist_percentage", 0);
  6571. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  6572. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  6573. packet->setDataByName("cold_resist_percentage", 0);
  6574. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  6575. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  6576. packet->setDataByName("magic_resist_percentage", 0);
  6577. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  6578. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  6579. packet->setDataByName("mental_resist_percentage", 0);
  6580. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  6581. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  6582. packet->setDataByName("divine_resist_percentage", 0);
  6583. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  6584. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  6585. packet->setDataByName("disease_resist_percentage", 0);
  6586. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  6587. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  6588. packet->setDataByName("poison_resist_percentage", 0);
  6589. packet->setArrayLengthByName("num_chars", 0x01FF);
  6590. string biography = player_to_inspect->GetBiography();
  6591. for (size_t i = 0; i < biography.length(); i++)
  6592. packet->setArrayDataByName("biography_char", biography[i], i);
  6593. LogWrite(MISC__TODO, 0, "TODO", "Why is inspect player weapons commented out? in func: %s, line: %i", __FUNCTION__, __LINE__);
  6594. /*Item* pw = player_to_inspect->GetEquipmentList()->GetItem(0);
  6595. if (pw)
  6596. packet->setItemByName("primary", pw, player_to_inspect, 0);
  6597. Item* sw = player_to_inspect->GetEquipmentList()->GetItem(1);
  6598. if (sw)
  6599. packet->setItemByName("secondary", sw, player_to_inspect, 0);*/
  6600. //DumpPacket(packet->serialize());
  6601. QueuePacket(packet->serialize());
  6602. safe_delete(packet);
  6603. }
  6604. }
  6605. }
  6606. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  6607. pending_guild_invite.guild = guild;
  6608. pending_guild_invite.invited_by = invited_by;
  6609. }
  6610. void Client::ShowClaimWindow() {
  6611. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  6612. if (packet) {
  6613. map<int32, Item*>* items = &master_item_list.items;
  6614. map<int32, Item*>::iterator itr;
  6615. int32 i = 0;
  6616. if (items->size() > 10)
  6617. packet->setArrayLengthByName("num_claim_items", 10);
  6618. else
  6619. packet->setArrayLengthByName("num_claim_items", items->size());
  6620. for (itr = items->begin(); itr != items->end(); itr++) {
  6621. if (i == 10)
  6622. break;
  6623. Item* item = itr->second;
  6624. packet->setArrayDataByName("id", i, i);
  6625. packet->setArrayDataByName("not_yet_claimed", 1, i);
  6626. packet->setArrayDataByName("num_remaining", 5, i);
  6627. packet->setArrayDataByName("one_per_character", 1, i);
  6628. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  6629. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6630. packet->setArrayDataByName("text", "If you ever see this text, let Scatman know, thanks! :)", i);
  6631. packet->setArrayDataByName("category", "Scott's Shit", i);
  6632. packet->setArrayDataByName("icon", item->details.icon, i);
  6633. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6634. i++;
  6635. }
  6636. packet->setDataByName("unknown3", 1);
  6637. QueuePacket(packet->serialize());
  6638. safe_delete(packet);
  6639. }
  6640. }
  6641. void Client::ShowGuildSearchWindow() {
  6642. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  6643. if (packet) {
  6644. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  6645. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  6646. packet->setArrayLengthByName("num_guilds", guilds->size());
  6647. int32 i = 0;
  6648. while (itr.Next()) {
  6649. Guild* guild = itr.second;
  6650. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  6651. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  6652. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  6653. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  6654. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  6655. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  6656. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  6657. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  6658. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  6659. packet->setArrayDataByName("unknown7", 0x02, i);
  6660. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  6661. i++;
  6662. }
  6663. QueuePacket(packet->serialize());
  6664. safe_delete(packet);
  6665. }
  6666. }
  6667. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  6668. PacketStruct* packet;
  6669. vector<int8>* slot_data;
  6670. vector<int8>::iterator itr;
  6671. int32 slots = 0;
  6672. assert(item);
  6673. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  6674. return;
  6675. }
  6676. slot_data = &item->slot_data;
  6677. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  6678. if (version >= 1188)
  6679. slots = *itr;
  6680. else
  6681. slots += (int8)pow(2.0, *itr);
  6682. }
  6683. packet->setDataByName("slot", slots);
  6684. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  6685. if (slots == 2) {
  6686. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  6687. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  6688. }
  6689. else {
  6690. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  6691. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  6692. }
  6693. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  6694. if (slots == 4) {
  6695. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  6696. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  6697. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  6698. }
  6699. else if (slots == 7) {
  6700. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  6701. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  6702. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  6703. }
  6704. else {
  6705. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  6706. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  6707. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  6708. }
  6709. packet->setDataByName("icon", item->details.icon);
  6710. packet->setDataByName("item_id", item->details.item_id);
  6711. packet->setDataByName("item_crc", crc);
  6712. packet->setDataByName("unknown2", 0xFFFFFFFF);
  6713. packet->setDataByName("unknown4", 0xFFFFFFFF);
  6714. packet->setDataByName("unknown5", 0xFF, 9);
  6715. packet->setDataByName("unknown5", 0xFF, 10);
  6716. QueuePacket(packet->serialize());
  6717. safe_delete(packet);
  6718. }
  6719. void Client::SendCollectionList() {
  6720. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  6721. map<int32, Collection*>::iterator itr;
  6722. vector<struct CollectionItem*>* collection_items;
  6723. Collection* collection;
  6724. struct CollectionItem* collection_item;
  6725. PacketStruct* packet = 0;
  6726. int16 i = 0, j;
  6727. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  6728. return;
  6729. packet->setArrayLengthByName("num_collections", collections->size());
  6730. for (itr = collections->begin(); itr != collections->end(); itr++) {
  6731. collection = itr->second;
  6732. collection_items = collection->GetCollectionItems();
  6733. packet->setArrayDataByName("unknown", 1, i);
  6734. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  6735. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  6736. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  6737. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  6738. packet->setArrayDataByName("level", collection->GetLevel(), i);
  6739. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  6740. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  6741. for (j = 0; j < collection_items->size(); j++) {
  6742. collection_item = collection_items->at(j);
  6743. Item* item = master_item_list.GetItem(collection_item->item);
  6744. if (item) {
  6745. packet->setSubArrayDataByName("item_icon", item->details.icon, i, j);
  6746. if (version < 955)
  6747. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  6748. else
  6749. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  6750. }
  6751. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  6752. }
  6753. i++;
  6754. }
  6755. packet->setDataByName("new_collection_flag", 1);
  6756. QueuePacket(packet->serialize());
  6757. safe_delete(packet);
  6758. }
  6759. bool Client::SendCollectionsForItem(Item* item) {
  6760. map<int32, Collection*> collections_to_send;
  6761. map<int32, Collection*>* collections;
  6762. map<int32, Collection*>::iterator itr;
  6763. vector<struct CollectionItem*>* collection_items;
  6764. Collection* collection;
  6765. struct CollectionItem* collection_item;
  6766. PacketStruct* packet;
  6767. int16 i;
  6768. assert(item);
  6769. /* get any collections required by this item that the player already has */
  6770. collections = player->GetCollectionList()->GetCollections();
  6771. for (itr = collections->begin(); itr != collections->end(); itr++) {
  6772. collection = itr->second;
  6773. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  6774. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  6775. collections_to_send[collection->GetID()] = collection;
  6776. }
  6777. }
  6778. /* get any collections required by this item that the player does not have and send it to the client */
  6779. collections = master_collection_list.GetCollections();
  6780. for (itr = collections->begin(); itr != collections->end(); itr++) {
  6781. collection = itr->second;
  6782. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  6783. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  6784. return false;
  6785. }
  6786. packet->setArrayLengthByName("num_collections", 1);
  6787. packet->setArrayDataByName("unknown", 1, 0);
  6788. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  6789. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  6790. packet->setArrayDataByName("completed", 0, 0);
  6791. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  6792. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  6793. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  6794. packet->setArrayDataByName("unknown3", 0x28, 0);
  6795. collection_items = collection->GetCollectionItems();
  6796. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  6797. for (i = 0; i < collection_items->size(); i++) {
  6798. collection_item = collection_items->at(i);
  6799. Item* item2 = master_item_list.GetItem(collection_item->item);
  6800. if (item2) {
  6801. packet->setSubArrayDataByName("item_icon", item2->details.icon, 0, i);
  6802. if (version < 955)
  6803. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  6804. else
  6805. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  6806. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  6807. }
  6808. }
  6809. packet->setDataByName("new_collection_flag", 0);
  6810. QueuePacket(packet->serialize());
  6811. safe_delete(packet);
  6812. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  6813. collections_to_send[collection->GetID()] = collection;
  6814. }
  6815. }
  6816. /* send the client a list of collections that should be filtered for this item */
  6817. if (collections_to_send.size() > 0) {
  6818. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  6819. return false;
  6820. }
  6821. i = 0;
  6822. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  6823. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  6824. collection = itr->second;
  6825. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  6826. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  6827. i++;
  6828. }
  6829. packet->setDataByName("item_icon", item->details.icon);
  6830. packet->setDataByName("item_name", item->name.c_str());
  6831. packet->setDataByName("item_id", item->details.item_id);
  6832. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  6833. QueuePacket(packet->serialize());
  6834. safe_delete(packet);
  6835. }
  6836. return collections_to_send.size() > 0;
  6837. }
  6838. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  6839. Collection* collection;
  6840. struct CollectionItem* collection_item;
  6841. PacketStruct* packet;
  6842. char tmp[200] = { 0 };
  6843. assert(item);
  6844. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  6845. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  6846. /* get the item struct that represents the item for this collection */
  6847. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  6848. SendCollectionList();
  6849. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  6850. return;
  6851. }
  6852. /* sanity check */
  6853. if (collection_item->found) {
  6854. SendCollectionList();
  6855. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' has already found item '%s' for collection '%s'", player->GetName(), item->name.c_str(), collection->GetName());
  6856. return;
  6857. }
  6858. }
  6859. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  6860. collection = new Collection(collection);
  6861. /* get the item struct that represents the item for this collection */
  6862. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  6863. SendCollectionList();
  6864. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  6865. safe_delete(collection);
  6866. return;
  6867. }
  6868. /* add the new collection to the player's collection list */
  6869. if (!player->GetCollectionList()->AddCollection(collection)) {
  6870. SendCollectionList();
  6871. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  6872. safe_delete(collection);
  6873. return;
  6874. }
  6875. }
  6876. else {
  6877. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  6878. return;
  6879. }
  6880. collection_item->found = 1;
  6881. collection->SetSaveNeeded(true);
  6882. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  6883. SendCollectionList();
  6884. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  6885. return;
  6886. }
  6887. packet->setDataByName("collection_id", collection_id);
  6888. packet->setDataByName("collection_item_num", collection_item->index);
  6889. packet->setDataByName("add", 1);
  6890. QueuePacket(packet->serialize());
  6891. Item* item2 = master_item_list.GetItem(collection_item->item);
  6892. if (item2) {
  6893. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  6894. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  6895. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  6896. }
  6897. safe_delete(packet);
  6898. RemoveItem(item, 1);
  6899. SendCollectionList();
  6900. }
  6901. void Client::DisplayCollectionComplete(Collection* collection) {
  6902. vector<struct CollectionRewardItem*>* reward_items;
  6903. vector<struct CollectionRewardItem*>* selectable_reward_items;
  6904. struct CollectionRewardItem* reward_item;
  6905. PacketStruct* packet;
  6906. int32 i;
  6907. assert(collection);
  6908. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  6909. return;
  6910. }
  6911. reward_items = collection->GetRewardItems();
  6912. selectable_reward_items = collection->GetSelectableRewardItems();
  6913. packet->setDataByName("title", "Quest Reward!");
  6914. packet->setDataByName("name", collection->GetName());
  6915. packet->setDataByName("description", collection->GetCategory());
  6916. packet->setDataByName("level", collection->GetLevel());
  6917. packet->setDataByName("max_coin", collection->GetRewardCoin());
  6918. packet->setDataByName("min_coin", collection->GetRewardCoin());
  6919. //packet->setDataByName("status_points", quest->GetStatusPoints());
  6920. packet->setArrayLengthByName("num_rewards", reward_items->size());
  6921. for (i = 0; i < reward_items->size(); i++) {
  6922. reward_item = reward_items->at(i);
  6923. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  6924. if (version < 860)
  6925. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, -1);
  6926. else if (version < 1193)
  6927. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  6928. else
  6929. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  6930. }
  6931. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  6932. for (i = 0; i < selectable_reward_items->size(); i++) {
  6933. reward_item = selectable_reward_items->at(i);
  6934. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  6935. if (version < 860)
  6936. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, -1);
  6937. else if (version < 1193)
  6938. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  6939. else
  6940. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  6941. }
  6942. QueuePacket(packet->serialize());
  6943. safe_delete(packet);
  6944. }
  6945. void Client::HandInCollections() {
  6946. map<int32, Collection*>* collections;
  6947. map<int32, Collection*>::iterator itr;
  6948. Collection* collection;
  6949. /* only show 1 collection reward dialog at a time */
  6950. if (player->GetPendingCollectionReward()) {
  6951. return;
  6952. }
  6953. collections = player->GetCollectionList()->GetCollections();
  6954. /* we only want to display 1 collection reward dialog at a time. so once we find one to display, send it and return. once the player accepts the reward
  6955. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  6956. for (itr = collections->begin(); itr != collections->end(); itr++) {
  6957. collection = itr->second;
  6958. if (collection->GetIsReadyToTurnIn()) {
  6959. player->SetPendingCollectionReward(collection);
  6960. DisplayCollectionComplete(collection);
  6961. return;
  6962. }
  6963. }
  6964. }
  6965. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  6966. vector<struct CollectionRewardItem*>* reward_items;
  6967. vector<struct CollectionRewardItem*>::iterator itr;
  6968. struct CollectionRewardItem* reward_item;
  6969. int16 num_slots_needed;
  6970. int16 num_slots;
  6971. assert(collection);
  6972. reward_items = collection->GetRewardItems();
  6973. num_slots_needed = (int16)reward_items->size();
  6974. if (selectable_item_id > 0)
  6975. num_slots_needed++;
  6976. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  6977. if (num_slots < num_slots_needed) {
  6978. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  6979. HandInCollections();
  6980. return;
  6981. }
  6982. /* add manditory items */
  6983. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  6984. reward_item = *itr;
  6985. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  6986. }
  6987. /* find and add the selectable item if there's one */
  6988. if (selectable_item_id > 0) {
  6989. reward_items = collection->GetSelectableRewardItems();
  6990. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  6991. reward_item = *itr;
  6992. if (reward_item->item->details.item_id == selectable_item_id) {
  6993. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  6994. break;
  6995. }
  6996. }
  6997. }
  6998. if (collection->GetRewardXP() > 0) {
  6999. player->AddXP((int32)collection->GetRewardXP());
  7000. SimpleMessage(CHANNEL_COLOR_YELLOW, "You gain experience!");
  7001. }
  7002. if (collection->GetRewardCoin() > 0) {
  7003. player->AddCoins(collection->GetRewardCoin());
  7004. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  7005. }
  7006. collection->SetCompleted(true);
  7007. //update achievements for completeing collection here
  7008. collection->SetSaveNeeded(true);
  7009. SendCollectionList();
  7010. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  7011. player->SetPendingCollectionReward(0);
  7012. HandInCollections();
  7013. }
  7014. void Client::SendRecipeList() {
  7015. PacketStruct* packet = 0;
  7016. if (GetRecipeListSent()) {
  7017. return;
  7018. }
  7019. if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  7020. return;
  7021. }
  7022. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  7023. map<int32, Recipe*>::iterator itr;
  7024. Recipe* recipe;
  7025. int16 i = 0;
  7026. packet->setArrayLengthByName("num_recipes", recipes->size());
  7027. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  7028. recipe = itr->second;
  7029. packet->setArrayDataByName("id", recipe->GetID(), i);
  7030. packet->setArrayDataByName("tier", recipe->GetTier(), i);
  7031. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  7032. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  7033. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  7034. packet->setArrayDataByName("skill", recipe->GetSkill(), i);
  7035. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  7036. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  7037. packet->setArrayDataByName("unknown2", recipe->GetUnknown2(), i);
  7038. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  7039. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  7040. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  7041. i++;
  7042. }
  7043. //packet->PrintPacket();
  7044. //DumpPacket(packet->serialize());
  7045. QueuePacket(packet->serialize());
  7046. safe_delete(packet);
  7047. SetRecipeListSent(true);
  7048. }
  7049. void Client::ShowRecipeBook() {
  7050. PacketStruct* packet = 0;
  7051. Spawn* target = 0;
  7052. if (!(target = player->GetTarget())) {
  7053. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  7054. return;
  7055. }
  7056. if (!target->IsObject()) {
  7057. return;
  7058. }
  7059. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  7060. return;
  7061. }
  7062. packet->setDataByName("device", target->GetName());
  7063. packet->setDataByName("unknown1", 1);
  7064. if (((Object*)target)->GetDeviceID() > 0) {
  7065. int32 deviceID = (int32)pow(2.0, (double)((Object*)target)->GetDeviceID());
  7066. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  7067. packet->setDataByName("unknown2", 8);
  7068. packet->setDataByName("unknown3", deviceID);
  7069. }
  7070. //packet->PrintPacket();
  7071. QueuePacket(packet->serialize());
  7072. safe_delete(packet);
  7073. }
  7074. void Client::SendTitleUpdate() {
  7075. list<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  7076. list<Title*>::iterator itr;
  7077. Title* title;
  7078. int16 i = 0;
  7079. sint16 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  7080. sint16 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  7081. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  7082. if (packet) {
  7083. packet->setArrayLengthByName("num_titles", titles->size());
  7084. for (itr = titles->begin(); itr != titles->end(); itr++) {
  7085. title = *itr;
  7086. packet->setArrayDataByName("title", title->GetName(), i);
  7087. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  7088. i++;
  7089. }
  7090. packet->setDataByName("current_prefix", prefix_index);
  7091. packet->setDataByName("current_suffix", suffix_index);
  7092. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  7093. #if EQDEBUG >= 9
  7094. packet->PrintPacket();
  7095. #endif
  7096. QueuePacket(packet->serialize());
  7097. safe_delete(packet);
  7098. SendUpdateTitles(prefix_index, suffix_index);
  7099. }
  7100. }
  7101. void Client::SendUpdateTitles(sint16 prefix, sint16 suffix) {
  7102. Title* suffix_title = 0;
  7103. Title* prefix_title = 0;
  7104. if (suffix != -1) {
  7105. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  7106. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  7107. }
  7108. else
  7109. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  7110. if (prefix != -1) {
  7111. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  7112. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  7113. }
  7114. else
  7115. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  7116. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  7117. }
  7118. void Client::SendLanguagesUpdate(int32 id) {
  7119. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  7120. list<Language*>::iterator itr;
  7121. Language* language;
  7122. int32 i = 0;
  7123. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  7124. if (packet) {
  7125. packet->setArrayLengthByName("num_languages", languages->size());
  7126. for (itr = languages->begin(); itr != languages->end(); itr++) {
  7127. language = *itr;
  7128. packet->setArrayDataByName("language_id", language->GetID(), i);
  7129. i++;
  7130. }
  7131. packet->setDataByName("current_language", id);
  7132. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  7133. #if EQDEBUG >= 9
  7134. packet->PrintPacket();
  7135. #endif
  7136. QueuePacket(packet->serialize());
  7137. safe_delete(packet);
  7138. }
  7139. }
  7140. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  7141. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  7142. if (packet) {
  7143. if (pet_name)
  7144. packet->setDataByName("pet_name", pet_name);
  7145. if (player->GetInfoStruct()->pet_behavior & 1)
  7146. packet->setDataByName("protect_master", 1);
  7147. if (player->GetInfoStruct()->pet_behavior & 2)
  7148. packet->setDataByName("protect_self", 1);
  7149. if (player->GetInfoStruct()->pet_movement == 2)
  7150. packet->setDataByName("stay_follow_toggle", 1);
  7151. packet->setDataByName("pet_type", type);
  7152. QueuePacket(packet->serialize());
  7153. }
  7154. safe_delete(packet);
  7155. }
  7156. bool Client::IsCrafting() {
  7157. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  7158. }
  7159. void Client::SendBiography() {
  7160. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  7161. if (packet) {
  7162. if (strlen(player->GetInfoStruct()->biography) > 0)
  7163. packet->setDataByName("biography", player->GetInfoStruct()->biography);
  7164. QueuePacket(packet->serialize());
  7165. }
  7166. safe_delete(packet);
  7167. }
  7168. PendingResurrection* Client::GetCurrentRez() {
  7169. return &current_rez;
  7170. }
  7171. Mutex* Client::GetResurrectMutex() {
  7172. return &m_resurrect;
  7173. }
  7174. void Client::SendResurrectionWindow() {
  7175. Spawn* caster = current_rez.caster;
  7176. if (!caster || !player)
  7177. return;
  7178. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  7179. if (!packet)
  7180. return;
  7181. char* tmp = new char[512];
  7182. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  7183. packet->setMediumStringByName("text", tmp);
  7184. packet->setMediumStringByName("accept_text", "Yes");
  7185. packet->setMediumStringByName("cancel_text", "No");
  7186. sprintf(tmp, "accept_resurrection %u", player->GetID());
  7187. packet->setMediumStringByName("accept_command", tmp);
  7188. sprintf(tmp, "decline_resurrection %u", player->GetID());
  7189. packet->setMediumStringByName("cancel_command", tmp);
  7190. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  7191. QueuePacket(packet->serialize());
  7192. safe_delete(packet);
  7193. safe_delete_array(tmp);
  7194. }
  7195. void Client::AcceptResurrection() {
  7196. Spawn* caster = current_rez.caster;
  7197. if (!player || !caster)
  7198. return;
  7199. if (player->Alive())
  7200. return;
  7201. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  7202. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  7203. SendResurrectionWindow();
  7204. return;
  7205. }
  7206. player->GetZone()->ResurrectSpawn(player, this);
  7207. current_rez.should_delete = true;
  7208. }
  7209. void Client::SetPendingLastName(string last_name) {
  7210. pending_last_name = new string;
  7211. pending_last_name->assign(last_name);
  7212. }
  7213. string* Client::GetPendingLastName() {
  7214. return pending_last_name;
  7215. }
  7216. void Client::RemovePendingLastName() {
  7217. safe_delete(pending_last_name);
  7218. }
  7219. void Client::SendLastNameConfirmation() {
  7220. if (!pending_last_name)
  7221. return;
  7222. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  7223. if (packet) {
  7224. char* text = new char[128];
  7225. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  7226. packet->setDataByName("text", text);
  7227. packet->setDataByName("accept_text", "Yes");
  7228. packet->setDataByName("accept_command", "confirmedlastname");
  7229. packet->setDataByName("cancel_text", "No");
  7230. packet->setDataByName("unknown2", 50);
  7231. packet->setDataByName("unknown4", 1);
  7232. packet->setDataByName("unknown5", 1);
  7233. QueuePacket(packet->serialize());
  7234. safe_delete(packet);
  7235. safe_delete_array(text);
  7236. }
  7237. }
  7238. void Client::AddQuestTimer(int32 quest_id) {
  7239. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  7240. quest_timers.push_back(quest_id);
  7241. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  7242. }
  7243. void Client::RemoveQuestTimer(int32 quest_id) {
  7244. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  7245. vector<int32>::iterator itr;
  7246. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  7247. if ((*itr) == quest_id) {
  7248. quest_timers.erase(itr);
  7249. break;
  7250. }
  7251. }
  7252. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  7253. }
  7254. void Client::SavePlayerImages() {
  7255. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  7256. // Save the paperdoll image if the server allows it
  7257. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
  7258. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  7259. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  7260. // Save the head shot if the server allows it
  7261. if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
  7262. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  7263. // Send the head shot to the login server
  7264. if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
  7265. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  7266. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  7267. memset(packet->pBuffer, 0, size);
  7268. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  7269. pic->account_id = GetAccountID();
  7270. pic->char_id = GetCharacterID();
  7271. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  7272. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  7273. loginserver.SendPacket(packet);
  7274. safe_delete(packet);
  7275. }
  7276. }
  7277. safe_delete_array(incoming_paperdoll.image_bytes);
  7278. incoming_paperdoll.current_size_bytes = 0;
  7279. }
  7280. void Client::EndAutoMount() {
  7281. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  7282. if (packet) {
  7283. packet->setDataByName("parameter1", 128);
  7284. packet->setDataByName("parameter2", 64);
  7285. packet->setDataByName("value", 1);
  7286. QueuePacket(packet->serialize());
  7287. safe_delete(packet);
  7288. }
  7289. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  7290. if (packet) {
  7291. packet->setDataByName("parameter3", 4);
  7292. packet->setDataByName("parameter5", 2);
  7293. packet->setDataByName("value", 0);
  7294. QueuePacket(packet->serialize());
  7295. safe_delete(packet);
  7296. }
  7297. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  7298. if (packet) {
  7299. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  7300. QueuePacket(packet->serialize());
  7301. safe_delete(packet);
  7302. }
  7303. on_auto_mount = false;
  7304. player->SetMount(((Player*)player)->GetTempMount());
  7305. EQ2_Color mount_color = player->GetTempMountColor();
  7306. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  7307. player->SetMountColor(&mount_color);
  7308. player->SetMountSaddleColor(&saddle_color);
  7309. player->SetTempMount(0);
  7310. }
  7311. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  7312. const char* spawn_script = spawn->GetSpawnScript();
  7313. bool should_use_spawn = true;
  7314. if (spawn_script) {
  7315. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  7316. if (state) {
  7317. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  7318. if (state_mutex)
  7319. state_mutex->writelock(__FUNCTION__, __LINE__);
  7320. lua_getglobal(state, "can_use_command");
  7321. if (lua_isfunction(state, -1)) {
  7322. lua_interface->SetSpawnValue(state, spawn);
  7323. lua_interface->SetSpawnValue(state, GetPlayer());
  7324. lua_interface->SetStringValue(state, command ? command : "");
  7325. if (lua_pcall(state, 3, 1, 0) == 0) {
  7326. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  7327. }
  7328. }
  7329. lua_interface->ResetFunctionStack(state);
  7330. if (state_mutex)
  7331. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  7332. }
  7333. }
  7334. return should_use_spawn;
  7335. }
  7336. bool Client::IsCurrentTransmuteID(int32 req_id) {
  7337. return req_id == transmuteID;
  7338. }
  7339. void Client::SetTransmuteID(int32 trans_id) {
  7340. transmuteID = trans_id;
  7341. }
  7342. int32 Client::GetTransmuteID() {
  7343. return transmuteID;
  7344. }
  7345. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  7346. {
  7347. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  7348. if (zar)
  7349. {
  7350. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  7351. if (database.IsActiveQuery(charID))
  7352. {
  7353. delayedLogin = true;
  7354. delayedAccountID = account_id;
  7355. delayedAccessKey = access_code;
  7356. delayTimer.Start(500);
  7357. LogWrite(ZONE__INFO, 0, "ZoneAuth", "Attempt to Login must be delayed, async character save in progress! ... Access Key: %u, Character Name: %s, Account ID: %u, Client Data Version: %u", zar->GetAccessKey(), zar->GetCharacterName(), zar->GetAccountID(), version);
  7358. return true;
  7359. }
  7360. delayedLogin = false;
  7361. delayTimer.Disable();
  7362. firstlogin = zar->isFirstLogin();
  7363. LogWrite(ZONE__INFO, 0, "ZoneAuth", "Access Key: %u, Character Name: %s, Account ID: %u, Client Data Version: %u", zar->GetAccessKey(), zar->GetCharacterName(), zar->GetAccountID(), version);
  7364. if (database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  7365. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  7366. if (pvp_allowed)
  7367. this->GetPlayer()->SetAttackable(1);
  7368. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  7369. Client* client = zone_list.GetClientByCharName(player->GetName());
  7370. if (client) {
  7371. if (client->getConnection())
  7372. client->getConnection()->SendDisconnect();
  7373. if (client->GetCurrentZone() && !client->IsZoning()) {
  7374. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  7375. if (client->GetVersion() == version) {
  7376. Player* current_player = GetPlayer();
  7377. SetPlayer(client->GetPlayer());
  7378. client->SetPlayer(current_player);
  7379. client->GetPlayer()->SetPendingDeletion(true);
  7380. GetPlayer()->SetPendingDeletion(false);
  7381. GetPlayer()->ResetSavedSpawns();
  7382. GetPlayer()->SetReturningFromLD(true);
  7383. GetPlayer()->GetZone()->RemoveDelayedSpawnRemove(GetPlayer());
  7384. }
  7385. client->GetCurrentZone()->RemoveClientImmediately(client);
  7386. }
  7387. }
  7388. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  7389. if (!GetCurrentZone()) {
  7390. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  7391. ClientPacketFunctions::SendLoginDenied(this);
  7392. }
  7393. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  7394. getConnection()->SetClientVersion(version);
  7395. connected_to_zone = true;
  7396. client_list.Remove(this); //remove from master client list
  7397. new_client_login = true;
  7398. GetCurrentZone()->AddClient(this); //add to zones client list
  7399. world.RejoinGroup(this);
  7400. zone_list.AddClientToMap(player->GetName(), this);
  7401. GetCurrentZone()->SetSpawnStructs(this);
  7402. }
  7403. else {
  7404. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  7405. ClientPacketFunctions::SendLoginDenied(this);
  7406. return false;
  7407. }
  7408. }
  7409. else {
  7410. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  7411. ClientPacketFunctions::SendLoginDenied(this);
  7412. }
  7413. zone_auth.RemoveAuth(zar);
  7414. }
  7415. else
  7416. {
  7417. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  7418. Disconnect();
  7419. }
  7420. return true;
  7421. }
  7422. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  7423. if (!IsReadyForUpdates())
  7424. return;
  7425. map<int32, SpawnData> info_changes;
  7426. map<int32, SpawnData> pos_changes;
  7427. map<int32, SpawnData> vis_changes;
  7428. map<int32, SpawnData> empty_changes;
  7429. int32 info_size = 0;
  7430. int32 pos_size = 0;
  7431. int32 vis_size = 0;
  7432. int count = 0;
  7433. for (const auto& spawn : spawns) {
  7434. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  7435. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()) || GetPlayer()->NeedsSpawnResent(spawn) || GetPlayer()->GetDistance(spawn) >= SEND_SPAWN_DISTANCE)
  7436. continue;
  7437. if (spawn->vis_changed)
  7438. {
  7439. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  7440. if (vis_change) {
  7441. SpawnData data;
  7442. data.spawn = spawn;
  7443. data.data = vis_change;
  7444. data.size = spawn->vis_packet_size;
  7445. map<int32, SpawnData> tmp_vis_changes;
  7446. tmp_vis_changes[index] = data;
  7447. map<int32, SpawnData> tmp_info_changes;
  7448. map<int32, SpawnData> tmp_pos_changes;
  7449. int32 tmp_info_size = 0;
  7450. int32 tmp_pos_size = 0;
  7451. if (spawn->info_changed) {
  7452. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  7453. if (info_change) {
  7454. SpawnData data;
  7455. data.spawn = spawn;
  7456. data.data = info_change;
  7457. data.size = spawn->info_packet_size;
  7458. tmp_info_size = data.size;
  7459. tmp_info_changes[index] = data;
  7460. }
  7461. }
  7462. /* if (spawn->position_changed) {
  7463. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  7464. if (pos_change) {
  7465. SpawnData data;
  7466. data.spawn = spawn;
  7467. data.data = pos_change;
  7468. data.size = spawn->pos_packet_size;
  7469. tmp_pos_size = data.size;
  7470. tmp_pos_changes[index] = data;
  7471. }
  7472. }*/
  7473. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  7474. continue;
  7475. }
  7476. }
  7477. if (spawn->info_changed) {
  7478. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  7479. if (info_change) {
  7480. SpawnData data;
  7481. data.spawn = spawn;
  7482. data.data = info_change;
  7483. data.size = spawn->info_packet_size;
  7484. info_size += spawn->info_packet_size;
  7485. info_changes[index] = data;
  7486. }
  7487. count++;
  7488. }
  7489. if (spawn->position_changed) {
  7490. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  7491. if (pos_change) {
  7492. SpawnData data;
  7493. data.spawn = spawn;
  7494. data.data = pos_change;
  7495. data.size = spawn->pos_packet_size;
  7496. pos_size += spawn->pos_packet_size;
  7497. pos_changes[index] = data;
  7498. }
  7499. count++;
  7500. }
  7501. if (spawn->vis_changed) {
  7502. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  7503. if (vis_change) {
  7504. SpawnData data;
  7505. data.spawn = spawn;
  7506. data.data = vis_change;
  7507. data.size = spawn->vis_packet_size;
  7508. vis_size += spawn->vis_packet_size;
  7509. vis_changes[index] = data;
  7510. }
  7511. count++;
  7512. }
  7513. }
  7514. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  7515. return;
  7516. }
  7517. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  7518. for (auto& kv : info_changes) {
  7519. safe_delete_array(kv.second.data);
  7520. }
  7521. for (auto& kv : pos_changes) {
  7522. safe_delete_array(kv.second.data);
  7523. }
  7524. for (auto& kv : vis_changes) {
  7525. safe_delete_array(kv.second.data);
  7526. }
  7527. }
  7528. void Client::MakeSpawnChangePacket(map<int32, SpawnData> info_changes, map<int32, SpawnData> pos_changes, map<int32, SpawnData> vis_changes, int32 info_size, int32 pos_size, int32 vis_size)
  7529. {
  7530. static const int8 oversized = 255;
  7531. int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  7532. int32 size = info_size + pos_size + vis_size + 11;
  7533. size += CheckOverLoadSize(info_size);
  7534. size += CheckOverLoadSize(pos_size);
  7535. size += CheckOverLoadSize(vis_size);
  7536. uchar* tmp = new uchar[size];
  7537. uchar* ptr = tmp;
  7538. memset(tmp, 0, size);
  7539. size -= 4;
  7540. memcpy(ptr, &size, sizeof(int32));
  7541. size += 4;
  7542. ptr += sizeof(int32);
  7543. memcpy(ptr, &oversized, sizeof(int8));
  7544. ptr += sizeof(int8);
  7545. memcpy(ptr, &opcode_val, sizeof(int16));
  7546. ptr += sizeof(int16);
  7547. int32 current_time = Timer::GetCurrentTime2();
  7548. memcpy(ptr, &current_time, sizeof(int32));
  7549. ptr += sizeof(int32);
  7550. ptr += DoOverLoad(info_size, ptr);
  7551. for (const auto& kv : info_changes) {
  7552. auto info = kv.second;
  7553. memcpy(ptr, info.data, info.size);
  7554. ptr += info.size;
  7555. }
  7556. ptr += DoOverLoad(pos_size, ptr);
  7557. for (const auto& kv : pos_changes) {
  7558. auto pos = kv.second;
  7559. memcpy(ptr, pos.data, pos.size);
  7560. ptr += pos.size;
  7561. }
  7562. ptr += DoOverLoad(vis_size, ptr);
  7563. for (const auto& kv : vis_changes) {
  7564. auto vis = kv.second;
  7565. memcpy(ptr, vis.data, vis.size);
  7566. ptr += vis.size;
  7567. }
  7568. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  7569. // DumpPacket(packet->pBuffer, packet->size);
  7570. if (packet) {
  7571. QueuePacket(packet);
  7572. }
  7573. delete[] tmp;
  7574. }