client.cpp 342 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833
  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 "Skills.h"
  71. #include "LuaInterface.h"
  72. #include "Quests.h"
  73. #include "Collections/Collections.h"
  74. #include "Achievements/Achievements.h"
  75. #include "Traits/Traits.h"
  76. #include "Recipes/Recipe.h"
  77. #include "Tradeskills/Tradeskills.h"
  78. #include "AltAdvancement/AltAdvancement.h"
  79. #include "Bots/Bot.h"
  80. extern WorldDatabase database;
  81. extern const char* ZONE_NAME;
  82. extern LoginServer loginserver;
  83. extern sint32 numclients;
  84. extern NetConnection net;
  85. extern Commands commands;
  86. extern ClientList client_list;
  87. extern ZoneList zone_list;
  88. extern ZoneAuth zone_auth;
  89. extern MasterItemList master_item_list;
  90. extern MasterSkillList master_skill_list;
  91. extern MasterSpellList master_spell_list;
  92. extern MasterTraitList master_trait_list;
  93. extern MasterQuestList master_quest_list;
  94. extern MasterFactionList master_faction_list;
  95. extern MasterRecipeList master_recipe_list;
  96. extern volatile bool RunLoops;
  97. extern ConfigReader configReader;
  98. extern LuaInterface* lua_interface;
  99. extern World world;
  100. extern Variables variables;
  101. extern Classes classes;
  102. extern Races races;
  103. extern GuildList guild_list;
  104. extern MasterCollectionList master_collection_list;
  105. extern MasterAchievementList master_achievement_list;
  106. extern RuleManager rule_manager;
  107. extern IRC irc;
  108. extern Chat chat;
  109. extern MasterAAList master_aa_list;
  110. extern MasterAAList master_tree_nodes;
  111. extern ChestTrapList chest_trap_list;
  112. using namespace std;
  113. Client::Client(EQStream* ieqs) : pos_update(125), quest_pos_timer(2000), lua_debug_timer(30000), delayTimer(500), transmuteID(0) {
  114. eqs = ieqs;
  115. ip = eqs->GetrIP();
  116. port = ntohs(eqs->GetrPort());
  117. merchant_transaction = nullptr;
  118. SetMailTransaction(nullptr);
  119. timestamp_flag = 0;
  120. current_quest_id = 0;
  121. last_update_time = 0;
  122. quest_updates = false;
  123. //autobootup_timeout = new Timer(10000);
  124. //autobootup_timeout->Disable();
  125. CLE_keepalive_timer = new Timer(15000);
  126. connect = new Timer(1000);
  127. connect->Disable();
  128. zoneID = 0;
  129. account_name[0] = 0;
  130. character_id = 0;
  131. account_id = 0;
  132. pwaitingforbootup = 0;
  133. current_zone = 0;
  134. connected_to_zone = false;
  135. connected = false;
  136. camp_timer = 0;
  137. disconnect_timer = 0;
  138. client_zoning = false;
  139. player_pos_changed = false;
  140. ++numclients;
  141. if (world.GetServerStatisticValue(STAT_SERVER_MOST_CONNECTIONS) < numclients)
  142. world.UpdateServerStatistic(STAT_SERVER_MOST_CONNECTIONS, numclients, true);
  143. remove_from_list = false;
  144. new_client_login = false;
  145. UpdateWindowTitle(0);
  146. num_active_failures = 0;
  147. player = new Player();
  148. player->SetClient(this);
  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. tempPlacementSpawn = nullptr;
  181. placement_unique_item_id = 0;
  182. SetHasOwnerOrEditAccess(false);
  183. temporary_transport_id = 0;
  184. rejoin_group_id = 0;
  185. lastRegionRemapTime = 0;
  186. regionDebugMessaging = false;
  187. }
  188. Client::~Client() {
  189. if (current_zone && player) {
  190. if (player->GetGroupMemberInfo())
  191. {
  192. if ((player->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0)
  193. world.GetGroupManager()->RemoveGroupMember(player->GetGroupMemberInfo()->group_id, player);
  194. else
  195. TempRemoveGroup();
  196. }
  197. world.GetGroupManager()->ClearPendingInvite(player);
  198. }
  199. if (lua_interface)
  200. lua_interface->RemoveDebugClients(this);
  201. if (player)
  202. zone_list.RemoveClientFromMap(player->GetName(), this);
  203. //let the stream factory know were done with this stream
  204. if (eqs) {
  205. eqs->Close();
  206. try {
  207. eqs->ReleaseFromUse();
  208. }
  209. catch (...) {}
  210. }
  211. eqs = NULL;
  212. //safe_delete(autobootup_timeout);
  213. safe_delete(disconnect_timer);
  214. safe_delete(camp_timer);
  215. safe_delete(CLE_keepalive_timer);
  216. safe_delete(connect);
  217. --numclients;
  218. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  219. if (player && !player->GetPendingDeletion())
  220. safe_delete(player);
  221. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  222. safe_delete(search_items);
  223. safe_delete(current_rez.expire_timer);
  224. safe_delete(pending_last_name);
  225. safe_delete_array(incoming_paperdoll.image_bytes);
  226. if (GetTempPlacementSpawn())
  227. {
  228. Spawn* tmp = GetTempPlacementSpawn();
  229. delete tmp;
  230. SetTempPlacementSpawn(nullptr);
  231. }
  232. UpdateWindowTitle(0);
  233. }
  234. void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
  235. if (eqs) {
  236. if (!eqs->CheckActive()) {
  237. client_list.Remove(this);
  238. eqs = 0;
  239. }
  240. }
  241. if (app && eqs && version > 0)
  242. eqs->EQ2QueuePacket(app, attemptedCombine);
  243. else {
  244. safe_delete(app);
  245. }
  246. }
  247. void Client::PopulateSkillMap() {
  248. EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
  249. if (app)
  250. QueuePacket(app);
  251. else {
  252. LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
  253. Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
  254. }
  255. }
  256. void Client::SendLoginInfo() {
  257. if (firstlogin) {
  258. LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
  259. world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
  260. LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
  261. PopulateSkillMap();
  262. // 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!
  263. LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
  264. }
  265. LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
  266. database.ToggleCharacterOnline(this, 1);
  267. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
  268. int32 count = database.LoadCharacterSkills(GetCharacterID(), player);
  269. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Spells for player '%s'...", player->GetName());
  270. count = database.LoadCharacterSpells(GetCharacterID(), player);
  271. // get the latest character starting skills / spells, may have been updated after character creation
  272. world.SyncCharacterAbilities(this);
  273. count = database.LoadCharacterTitles(GetCharacterID(), player);
  274. if (count == 0) {
  275. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
  276. LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
  277. database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
  278. }
  279. count = database.LoadCharacterLanguages(GetCharacterID(), player);
  280. if (count == 0)
  281. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
  282. count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
  283. if (count == 0)
  284. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
  285. ClientPacketFunctions::SendLoginAccepted(this);
  286. ClientPacketFunctions::SendAbilities ( this );
  287. ClientPacketFunctions::SendCommandNamePacket(this);
  288. ClientPacketFunctions::SendQuickBarInit(this);
  289. // we only need to send the MOTD if it is the first time the person is logging in.
  290. if (firstlogin) {
  291. ClientPacketFunctions::SendMOTD(this);
  292. ClientPacketFunctions::SendCharacterMacros(this);
  293. zone_list.CheckFriendList(this);
  294. }
  295. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  296. if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
  297. {
  298. LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
  299. database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  300. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  301. }
  302. database.LoadPlayerFactions(this);
  303. database.LoadCharacterQuests(this);
  304. database.LoadPlayerMail(this);
  305. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  306. SendQuestJournal(true, 0, false);
  307. if (version > 546) // right version? possibly not!
  308. master_aa_list.DisplayAA(this, 0, 3);
  309. if (version > 283)
  310. SendCollectionList();
  311. SendBiography();
  312. map<int32, Quest*>::iterator itr;
  313. Quest* quest = 0;
  314. for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
  315. quest = itr->second;
  316. if (quest->IsTracked()) {
  317. quest->SetTracked(false);
  318. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  319. quest->SetTracked(true);
  320. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  321. }
  322. }
  323. // SendAchievementsList();
  324. /*Guild* guild = player->GetGuild();
  325. if (guild) {
  326. guild->UpdateGuildMemberInfo(GetPlayer());
  327. if (firstlogin)
  328. guild->SendGuildMOTD(this);
  329. guild->SendGuildUpdate(this);
  330. guild->SendGuildMember(GetPlayer(), firstlogin);
  331. guild->SendGuildEventList(this);
  332. guild->SendGuildBankEventList(this);
  333. guild->SendAllGuildEvents(this);
  334. guild->SendGuildMemberList(this);
  335. }*/
  336. if (version > 283) {
  337. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
  338. EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
  339. if (outapp) {
  340. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  341. //DumpPacket(outapp);
  342. QueuePacket(outapp);
  343. }
  344. }
  345. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
  346. ClientPacketFunctions::SendCommandList(this);
  347. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
  348. SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
  349. ClientPacketFunctions::SendInstanceList(this);
  350. SendZoneInfo();
  351. /*Spell* spell = 0;
  352. vector<QuickBarItem*>::iterator itr;
  353. for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
  354. if((*itr)->type == 1){
  355. spell = master_spell_list.GetSpell((*itr)->id);
  356. if(spell)
  357. QueuePacket(spell->serialize(this, false, 0x20));
  358. }
  359. }*/
  360. }
  361. void Client::SendPlayerDeathWindow()
  362. {
  363. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
  364. vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
  365. vector<RevivePoint*>::iterator itr;
  366. if (results && results->size() > 0)
  367. {
  368. PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
  369. if (packet)
  370. {
  371. packet->setArrayLengthByName("location_count", results->size());
  372. RevivePoint* point = 0;
  373. int32 i = 0;
  374. for (itr = results->begin(); itr != results->end(); itr++, i++)
  375. {
  376. point = *itr;
  377. if (point)
  378. {
  379. packet->setArrayDataByName("location_id", point->id, i);
  380. //zone_name = database.GetZoneName(point->zone_id);
  381. string zone_name = database.GetZoneDescription(point->zone_id);
  382. if (zone_name.length() > 0)
  383. packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
  384. packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
  385. packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
  386. }
  387. if (point->id == 0xFFFFFFFF)//tmp location
  388. safe_delete(point);
  389. }
  390. // done with the revive points so lets free up the pointer
  391. safe_delete(results);
  392. #if EQDEBUG >= 3
  393. LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
  394. packet->PrintPacket();
  395. #endif
  396. EQ2Packet* outapp = packet->serialize();
  397. QueuePacket(outapp);
  398. safe_delete(packet);
  399. }
  400. }
  401. }
  402. void Client::DisplayDeadWindow()
  403. {
  404. LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
  405. player->SetHP(0);
  406. player->SetPower(0);
  407. GetCurrentZone()->TriggerCharSheetTimer();
  408. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  409. if (packet)
  410. {
  411. packet->setDataByName("parameter1", 8);
  412. packet->setDataByName("value", 1);
  413. QueuePacket(packet->serialize());
  414. packet->setDataByName("parameter1", 16);
  415. QueuePacket(packet->serialize());
  416. safe_delete(packet);
  417. }
  418. packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  419. if (packet)
  420. {
  421. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  422. QueuePacket(packet->serialize());
  423. safe_delete(packet);
  424. }
  425. SendPlayerDeathWindow();
  426. }
  427. void Client::HandlePlayerRevive(int32 point_id)
  428. {
  429. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  430. if (packet)
  431. {
  432. packet->setDataByName("parameter1", 8);
  433. QueuePacket(packet->serialize());
  434. packet->setDataByName("parameter1", 16);
  435. QueuePacket(packet->serialize());
  436. safe_delete(packet);
  437. }
  438. SimpleMessage(CHANNEL_NARRATIVE, "You regain consciousness!");
  439. packet = configReader.getStruct("WS_Resurrected", GetVersion());
  440. if (packet)
  441. {
  442. QueuePacket(packet->serialize());
  443. safe_delete(packet);
  444. }
  445. float x, y, z, heading;
  446. RevivePoint* revive_point = 0;
  447. if (point_id != 0xFFFFFFFF)
  448. revive_point = GetCurrentZone()->GetRevivePoint(point_id);
  449. string zone_desc;
  450. const char* location_name = "Unknown";
  451. //revive at zone safe coords
  452. if (!revive_point)
  453. {
  454. LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
  455. x = GetCurrentZone()->GetSafeX();
  456. y = GetCurrentZone()->GetSafeY();
  457. z = GetCurrentZone()->GetSafeZ();
  458. heading = GetCurrentZone()->GetSafeHeading();
  459. zone_desc = GetCurrentZone()->GetZoneDescription();
  460. location_name = "Zone Safe Point";
  461. Zone(GetCurrentZone()->GetZoneName(), false);
  462. }
  463. else
  464. {
  465. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
  466. x = revive_point->x;
  467. y = revive_point->y;
  468. z = revive_point->z;
  469. heading = revive_point->heading;
  470. zone_desc = database.GetZoneDescription(revive_point->zone_id);
  471. location_name = revive_point->location_name.c_str();
  472. Zone(GetCurrentZone()->GetZoneName(), false);
  473. }
  474. player->SetResurrecting(true);
  475. player->SetX(x);
  476. player->SetY(y);
  477. player->SetZ(z);
  478. player->SetHeading(heading);
  479. player->SetHP(player->GetTotalHP());
  480. player->SetPower(player->GetTotalPower());
  481. LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
  482. zone_desc.c_str(),
  483. player->GetX(),
  484. player->GetY(),
  485. player->GetZ(),
  486. player->GetHeading(),
  487. player->GetHP(),
  488. player->GetPower(),
  489. location_name);
  490. //player->ClearEverything();
  491. Save();
  492. if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
  493. {
  494. string zone_name = database.GetZoneName(revive_point->zone_id);
  495. if (zone_name.length() == 0)
  496. {
  497. LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  498. x = GetCurrentZone()->GetSafeX();
  499. y = GetCurrentZone()->GetSafeY();
  500. z = GetCurrentZone()->GetSafeZ();
  501. heading = GetCurrentZone()->GetSafeHeading();
  502. location_name = "Zone Safe Point";
  503. }
  504. else
  505. {
  506. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  507. location_name = revive_point->location_name.c_str();
  508. player->ClearEverything();
  509. Zone(zone_name.c_str(), false);
  510. }
  511. }
  512. zone_desc = GetCurrentZone()->GetZoneDescription();
  513. Message(CHANNEL_NARRATIVE, "Reviving in %s at %s.", zone_desc.c_str(), location_name);
  514. player->SetSpawnType(4);
  515. if (version > 283) {
  516. packet = configReader.getStruct("WS_CancelMoveObjectMode", GetVersion());
  517. if (packet)
  518. {
  519. QueuePacket(packet->serialize());
  520. safe_delete(packet);
  521. }
  522. }
  523. packet = configReader.getStruct("WS_TeleportWithinZone", GetVersion());
  524. if (packet)
  525. {
  526. packet->setDataByName("x", x);
  527. packet->setDataByName("y", y);
  528. packet->setDataByName("z", z);
  529. QueuePacket(packet->serialize());
  530. safe_delete(packet);
  531. }
  532. packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  533. if (packet)
  534. {
  535. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  536. packet->setDataByName("speed", 32);
  537. packet->setDataByName("unknown2", 0);
  538. //DoF Merge: old value and speed wasn't included
  539. //packet->setDataByName("unknown2", 255);
  540. QueuePacket(packet->serialize());
  541. safe_delete(packet);
  542. }
  543. packet = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  544. if (packet)
  545. {
  546. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  547. QueuePacket(packet->serialize());
  548. safe_delete(packet);
  549. }
  550. GetCurrentZone()->RemoveSpawn(player, false);
  551. m_resurrect.writelock(__FUNCTION__, __LINE__);
  552. if (current_rez.active)
  553. current_rez.should_delete = true;
  554. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  555. }
  556. void Client::SendCharInfo() {
  557. EQ2Packet* app;
  558. player->SetEquippedItemAppearances();
  559. ClientPacketFunctions::SendCharacterData(this);
  560. SendCharPOVGhost();
  561. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  562. if (packet) {
  563. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  564. packet->setDataByName("size", .56);
  565. packet->setDataByName("unknown2", 255);
  566. packet->setDataByName("speed", player->GetSpeed());
  567. packet->setDataByName("air_speed", player->GetAirSpeed());
  568. EQ2Packet* app = packet->serialize();
  569. QueuePacket(app);
  570. safe_delete(packet);
  571. }
  572. if (version <= 283) {
  573. //le: hack to allow client time to zone in, it gets stuck on Loading UI Resources if we go too fast, need to figure it out. Probably something it doesnt like with ExamineInfo packets
  574. Sleep(2000);
  575. }
  576. //sending bad spawn packet?
  577. //SendAchievementsList();
  578. ClientPacketFunctions::SendCharacterSheet(this);
  579. ClientPacketFunctions::SendTraitList(this);// moved from below
  580. ClientPacketFunctions::SendAbilities(this);
  581. ClientPacketFunctions::SendSkillBook(this);
  582. if (!player->IsResurrecting()) {
  583. if(GetVersion() > 546) //we will send this later on for 546 and below
  584. ClientPacketFunctions::SendUpdateSpellBook(this);
  585. }
  586. else {
  587. player->SetResurrecting(false);
  588. }
  589. ClientPacketFunctions::SendLoginCommandMessages(this);
  590. GetCurrentZone()->AddSpawn(player);
  591. //SendCollectionList();
  592. Guild* guild = player->GetGuild();
  593. if (guild)
  594. guild->GuildMemberLogin(this, firstlogin);
  595. app = player->item_list.serialize(GetPlayer(), GetVersion());
  596. if (app) {
  597. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  598. //DumpPacket(app);
  599. QueuePacket(app);
  600. }
  601. app = player->GetEquipmentList()->serialize(GetVersion());
  602. if (app) {
  603. QueuePacket(app);
  604. }
  605. vector<Item*>* items = player->item_list.GetItemsFromBagID(-3); // bank items
  606. if (items && items->size() > 0) {
  607. for (int32 i = 0; i < items->size(); i++) {
  608. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  609. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  610. //DumpPacket(outapp);
  611. QueuePacket(outapp);
  612. }
  613. }
  614. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  615. QueuePacket(app);
  616. safe_delete(items);
  617. items = player->item_list.GetItemsFromBagID(-4); //shared bank items
  618. if (items && items->size() > 0) {
  619. for (int32 i = 0; i < items->size(); i++)
  620. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  621. }
  622. safe_delete(items);
  623. if (version > 283) {
  624. SendTitleUpdate();
  625. }
  626. GetPlayer()->ChangePrimaryWeapon();
  627. GetPlayer()->ChangeSecondaryWeapon();
  628. GetPlayer()->ChangeRangedWeapon();
  629. database.LoadBuyBacks(this);
  630. if (version > 546)
  631. master_aa_list.DisplayAA(this, 0, 0);
  632. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  633. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  634. string zone_motd_send = "Zone MOTD: " + zone_motd;
  635. SimpleMessage(CHANNEL_NARRATIVE, zone_motd_send.c_str());
  636. }
  637. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  638. if (zone_script && lua_interface)
  639. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  640. this->client_zoning = false;
  641. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  642. GetCurrentZone()->AddDamagedSpawn(player);
  643. if (firstlogin && rule_manager.GetGlobalRule(R_World, IRCGlobalEnabled)->GetBool())
  644. Message(CHANNEL_BROADCAST, "This server has a global IRC channel, join the world channel %s to use", rule_manager.GetGlobalRule(R_World, IRCChan)->GetString());
  645. if (firstlogin)
  646. firstlogin = false;
  647. player->ClearProcs();
  648. items = player->GetEquippedItemList();
  649. if (items && items->size() > 0) {
  650. for (int32 i = 0; i < items->size(); i++) {
  651. Item* item = items->at(i);
  652. if (item && item->GetItemScript() && lua_interface)
  653. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  654. }
  655. }
  656. //Allow this player to change their last name if they meet the level requirement
  657. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  658. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  659. safe_delete(items);
  660. if (!player->Alive())
  661. DisplayDeadWindow();
  662. ClientPacketFunctions::SendLocalizedTextMessage(this);
  663. if (GetCurrentZone()->GetInstanceID())
  664. {
  665. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
  666. if (ph) {
  667. //HouseZone* hz = world.GetHouseZone(ph->house_id);
  668. string name = string(GetPlayer()->GetName());
  669. if (name.compare(ph->player_name) == 0)
  670. SetHasOwnerOrEditAccess(true);
  671. }
  672. }
  673. if (version > 546)
  674. ClientPacketFunctions::SendHousingList(this);
  675. }
  676. void Client::SendZoneSpawns() {
  677. //Allows us to place spawns almost anywhere
  678. if (version > 283) {
  679. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  680. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  681. QueuePacket(app);
  682. }
  683. ClientPacketFunctions::SendSkillSlotMappings(this);
  684. ClientPacketFunctions::SendGameWorldTime(this);
  685. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  686. }
  687. void Client::SendCharPOVGhost() {
  688. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  689. if (set_pov) {
  690. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  691. EQ2Packet* app_pov = set_pov->serialize();
  692. QueuePacket(app_pov);
  693. safe_delete(set_pov);
  694. }
  695. }
  696. void Client::SendZoneInfo() {
  697. ZoneServer* zone = GetCurrentZone();
  698. if (zone) {
  699. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  700. QueuePacket(packet);
  701. if (version > 283) {
  702. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  703. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  704. #if EQDEBUG >= 9
  705. fog_packet->PrintPacket();
  706. #endif
  707. if (fog_packet) {
  708. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  709. QueuePacket(fog_packet->serialize());
  710. safe_delete(fog_packet);
  711. }
  712. zone->SendFlightPathsPackets(this);
  713. }
  714. }
  715. /*
  716. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0x00,0x00,0x00,0x00
  717. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  718. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF
  719. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  720. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  721. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  722. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  723. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  724. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  725. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  726. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  727. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  728. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  729. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  730. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  731. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  732. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  733. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  734. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  735. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  736. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  737. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  738. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  739. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  740. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  741. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  742. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  743. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  744. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  745. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  746. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  747. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  748. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  749. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  750. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  751. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00};
  752. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  753. QueuePacket(appA);
  754. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00
  755. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  756. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  757. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00
  758. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  759. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  760. QueuePacket(appB);
  761. */
  762. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  763. SendFriendList();
  764. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  765. SendIgnoreList();
  766. }
  767. void Client::SendDefaultGroupOptions() {
  768. /*
  769. 0 - loot method
  770. 1 - loot items rarity
  771. 2 - Auto split coin
  772. 4 - default yell method
  773. 6 - group autolock
  774. 7 - solo autolock
  775. */
  776. PacketStruct* default_options = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  777. if (default_options) {
  778. default_options->setDataByName("loot_method", 1);
  779. default_options->setDataByName("loot_items_rarity", 1);
  780. default_options->setDataByName("auto_split_coin", 1);
  781. default_options->setDataByName("default_yell_method", 1);
  782. EQ2Packet* app7 = default_options->serialize();
  783. QueuePacket(app7);
  784. safe_delete(default_options);
  785. }
  786. }
  787. bool Client::HandlePacket(EQApplicationPacket* app) {
  788. bool ret = true;
  789. //cout << "INCOMING PACKET!!!!!!!: " << app->GetOpcodeName() << endl;
  790. //DumpPacket(app);
  791. #if EQDEBUG >= 9
  792. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  793. DumpPacket(app, true);
  794. #endif
  795. EmuOpcode opcode = app->GetOpcode();
  796. #if EQDEBUG >= 9
  797. const char* name = app->GetOpcodeName();
  798. if (name)
  799. cout << name;
  800. else
  801. cout << "Unknown";
  802. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  803. DumpPacket(app);
  804. #endif
  805. //if (opcode != OP_UpdatePositionMsg) {
  806. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  807. //}
  808. if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
  809. {
  810. opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
  811. }
  812. switch (opcode) {
  813. case _maxEmuOpcode:
  814. break;
  815. case OP_LoginByNumRequestMsg: {
  816. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  817. PacketStruct* request;
  818. request = configReader.getStruct("LoginByNumRequest", 1);
  819. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  820. // test the original location of Version for clients older than 1212
  821. version = request->getType_int16_ByName("version");
  822. if (version == 0 || version >= 1208 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  823. // must be new client data version method, re-fetch the packet
  824. safe_delete(request);
  825. request = configReader.getStruct("LoginByNumRequest", 1208);
  826. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  827. // Xinux suggests using an INT16 here. Our first new version = 57000
  828. version = request->getType_int16_ByName("version");
  829. }
  830. else {
  831. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  832. break;
  833. }
  834. }
  835. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  836. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  837. ClientPacketFunctions::SendLoginDenied(this);
  838. return false;
  839. }
  840. int32 account_id = request->getType_int32_ByName("account_id");
  841. int32 access_code = request->getType_int32_ByName("access_code");
  842. if (!HandleNewLogin(account_id, access_code))
  843. return false;
  844. }
  845. safe_delete(request);
  846. break;
  847. }
  848. case OP_SysClient: {
  849. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient", opcode, opcode);
  850. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  851. SetReadyForUpdates();
  852. break;
  853. }
  854. case OP_MapRequest: {
  855. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  856. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  857. if (packet && app->size > 2 && GetCurrentZone()) {
  858. packet->LoadPacketData(app->pBuffer, app->size);
  859. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  860. if (fog_packet) {
  861. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  862. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  863. fog_packet->setDataByName("unknown1", 1);
  864. fog_packet->setDataByName("unknown3", 1);
  865. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  866. //fog_packet->PrintPacket();
  867. QueuePacket(fog_packet->serialize());
  868. safe_delete(fog_packet);
  869. }
  870. safe_delete(packet);
  871. }
  872. break;
  873. }
  874. case OP_RequestCampMsg: {
  875. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  876. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  877. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  878. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  879. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  880. request->getType_int8_ByName("quit"),
  881. request->getType_int8_ByName("camp_desktop"),
  882. request->getType_int16_ByName("camp_char_select"),
  883. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  884. //DumpPacket(app->pBuffer, app->size);
  885. //request->PrintPacket();
  886. if (!camp_timer) {
  887. int16 camp_time = 20; // default if rule cannot be found
  888. if (GetAdminStatus() >= 100)
  889. camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
  890. else
  891. camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
  892. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  893. if (response) {
  894. bool disconnect = false;
  895. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  896. // Command: /camp desktop
  897. // Command: /quit
  898. response->setDataByName("camp_desktop", 1);
  899. disconnect = true;
  900. }
  901. else {
  902. // Command: /camp
  903. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  904. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  905. response->setDataByName("seconds", camp_time);
  906. }
  907. camp_timer = new Timer(camp_time * 1000);
  908. camp_timer->Enable();
  909. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  910. // /camp {char_name}
  911. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  912. }
  913. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  914. // /camp (go back to char selection screen)
  915. response->setDataByName("char_name", " ");
  916. response->setDataByName("camp_char_select", 1);
  917. }
  918. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  919. response->getType_int8_ByName("seconds"),
  920. response->getType_int8_ByName("camp_desktop"),
  921. response->getType_int8_ByName("camp_char_select"),
  922. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  923. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  924. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  925. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  926. //response->PrintPacket();
  927. QueuePacket(response->serialize());
  928. safe_delete(response);
  929. if (disconnect)
  930. Disconnect();
  931. }
  932. }
  933. }
  934. safe_delete(request);
  935. break;
  936. }
  937. case OP_StoodMsg: {
  938. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  939. if (camp_timer)
  940. {
  941. // JA: clear camping flag
  942. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  943. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  944. safe_delete(camp_timer);
  945. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  946. QueuePacket(outapp);
  947. }
  948. player->SetTempVisualState(0);
  949. break;
  950. }
  951. case OP_StandMsg: {
  952. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  953. if (camp_timer)
  954. {
  955. // JA: clear camping flag
  956. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  957. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  958. safe_delete(camp_timer);
  959. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  960. QueuePacket(outapp);
  961. }
  962. player->SetTempVisualState(539);
  963. break;
  964. }
  965. case OP_SitMsg: {
  966. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  967. player->SetTempVisualState(538);
  968. break;
  969. }
  970. case OP_SatMsg: {
  971. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  972. player->SetTempVisualState(540);
  973. break;
  974. }
  975. case OP_QuestJournalOpenMsg:
  976. case OP_QuestJournalInspectMsg: {
  977. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  978. if (app->size < sizeof(int32))
  979. break;
  980. int32 quest_id = 0;
  981. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  982. Quest* quest = GetActiveQuest(quest_id);
  983. if (quest)
  984. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  985. else {
  986. quest = player->GetCompletedQuest(quest_id);
  987. if (quest)
  988. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, 0, 1, true));
  989. }
  990. break;
  991. }
  992. case OP_QuestJournalSetVisibleMsg: {
  993. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  994. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  995. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  996. int32 quest_id = packet->getType_int32_ByName("quest_id");
  997. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  998. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  999. if (player_quests) {
  1000. if (player_quests->count(quest_id) > 0)
  1001. player_quests->at(quest_id)->SetHidden(hidden);
  1002. else
  1003. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  1004. }
  1005. else
  1006. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  1007. safe_delete(packet);
  1008. }
  1009. break;
  1010. }
  1011. case OP_MacroUpdateMsg: {
  1012. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  1013. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  1014. if (macro_update && macro_update->LoadPacketData(app->pBuffer, app->size)) {
  1015. vector<string>* update = new vector<string>;
  1016. int8 number = macro_update->getType_int8_ByName("number");
  1017. int16 icon = macro_update->getType_int16_ByName("icon");
  1018. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  1019. int8 count = macro_update->getType_int8_ByName("macro_count");
  1020. if (GetVersion() <= 283) {
  1021. update->push_back(macro_update->getType_EQ2_8BitString_ByName("command").data);
  1022. }
  1023. else {
  1024. for (int8 i = 0; i < count; i++) {
  1025. char tmp_command[15] = { 0 };
  1026. sprintf(tmp_command, "command_%i", i);
  1027. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  1028. }
  1029. }
  1030. if (name.length() == 0)
  1031. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  1032. else
  1033. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  1034. safe_delete(update);
  1035. safe_delete(macro_update);
  1036. }
  1037. break;
  1038. }
  1039. case OP_DialogSelectMsg: {
  1040. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  1041. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  1042. if (packet) {
  1043. packet->LoadPacketData(app->pBuffer, app->size);
  1044. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  1045. int32 response_index = packet->getType_int32_ByName("response");
  1046. if (GetCurrentZone()) {
  1047. Spawn* spawn = conversation_spawns[conversation_id];
  1048. Item* item = conversation_items[conversation_id];
  1049. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  1050. if (spawn)
  1051. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation_map[conversation_id][response_index].c_str());
  1052. else if (item && lua_interface && item->GetItemScript())
  1053. lua_interface->RunItemScript(item->GetItemScript(), conversation_map[conversation_id][response_index].c_str(), item, player);
  1054. }
  1055. else
  1056. CloseDialog(conversation_id);
  1057. }
  1058. safe_delete(packet);
  1059. }
  1060. break;
  1061. }
  1062. case OP_CancelMoveObjectModeMsg: {
  1063. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1064. if (GetTempPlacementSpawn())
  1065. {
  1066. Spawn* tmp = GetTempPlacementSpawn();
  1067. GetCurrentZone()->RemoveSpawn(tmp);
  1068. SetTempPlacementSpawn(nullptr);
  1069. SetPlacementUniqueItemID(0);
  1070. break; // break out early if we are tied to a temp spawn
  1071. }
  1072. // if we are moving some other object? other use-cases not covered
  1073. break;
  1074. }
  1075. case OP_PositionMoveableObject: {
  1076. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  1077. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  1078. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1079. Spawn* spawn = 0;
  1080. if (GetTempPlacementSpawn())
  1081. spawn = GetTempPlacementSpawn();
  1082. else
  1083. spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1084. if (!spawn) {
  1085. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1086. break;
  1087. }
  1088. else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
  1089. {
  1090. SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
  1091. break;
  1092. }
  1093. // handles instantiation logic + adding to zone of a new house object
  1094. PopulateHouseSpawn(place_object);
  1095. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1096. char query[256];
  1097. switch (GetSpawnPlacementMode())
  1098. {
  1099. case ServerSpawnPlacementMode::OPEN_HEADING:
  1100. {
  1101. if (spawn && spawn->IsWidget())
  1102. {
  1103. Widget* widget = (Widget*)spawn;
  1104. widget->SetOpenHeading(newHeading);
  1105. widget->SetIncludeHeading(true);
  1106. spawn->position_changed = true;
  1107. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1108. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1109. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1110. }
  1111. else
  1112. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1113. break;
  1114. }
  1115. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1116. {
  1117. if (spawn && spawn->IsWidget())
  1118. {
  1119. Widget* widget = (Widget*)spawn;
  1120. widget->SetClosedHeading(newHeading);
  1121. widget->SetIncludeHeading(true);
  1122. spawn->position_changed = true;
  1123. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1124. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1125. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1126. if (spawn->GetSpawnLocationID())
  1127. {
  1128. Query query;
  1129. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1130. }
  1131. }
  1132. else
  1133. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1134. break;
  1135. }
  1136. default:
  1137. {
  1138. spawn->SetX(place_object->getType_float_ByName("x"));
  1139. spawn->SetY(place_object->getType_float_ByName("y"));
  1140. spawn->SetZ(place_object->getType_float_ByName("z"));
  1141. spawn->SetHeading(newHeading);
  1142. spawn->SetSpawnOrigX(spawn->GetX());
  1143. spawn->SetSpawnOrigY(spawn->GetY());
  1144. spawn->SetSpawnOrigZ(spawn->GetZ());
  1145. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1146. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
  1147. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1148. else if (spawn->GetSpawnLocationID() > 0)
  1149. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1150. }
  1151. }
  1152. PopulateHouseSpawnFinalize();
  1153. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1154. safe_delete(place_object);
  1155. }
  1156. break;
  1157. }
  1158. case OP_CampAbortedMsg: {
  1159. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1160. if (camp_timer)
  1161. {
  1162. // JA: clear camping flag
  1163. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1164. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1165. safe_delete(camp_timer);
  1166. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1167. QueuePacket(outapp);
  1168. }
  1169. break;
  1170. }
  1171. case OP_DoneLoadingUIResourcesMsg: {
  1172. ClientPacketFunctions::SendUpdateSpellBook(this);
  1173. EQ2Packet* app = new EQ2Packet(OP_DoneLoadingUIResourcesMsg, 0, 0);
  1174. QueuePacket(app);
  1175. break;
  1176. }
  1177. case OP_DoneLoadingZoneResourcesMsg: {
  1178. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1179. SendZoneSpawns();
  1180. break;
  1181. }
  1182. case OP_DefaultGroupOptionsRequestMsg: {
  1183. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1184. SendDefaultGroupOptions();
  1185. break;
  1186. }
  1187. case OP_DoneLoadingEntityResourcesMsg: {
  1188. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1189. if (!IsReadyForSpawns())
  1190. SetReadyForSpawns(true);
  1191. SendCharInfo();
  1192. world.RejoinGroup(this, rejoin_group_id);
  1193. pos_update.Start();
  1194. quest_pos_timer.Start();
  1195. break;
  1196. }
  1197. case OP_LootItemsRequestMsg: {
  1198. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1199. HandleLoot(app);
  1200. break;
  1201. }
  1202. case OP_WaypointSelectMsg: {
  1203. PacketStruct* packet = configReader.getStruct("WS_WaypointSelect", GetVersion());
  1204. if (packet) {
  1205. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1206. int32 selection = packet->getType_int32_ByName("selection");
  1207. if (selection > 0) {
  1208. SelectWaypoint(selection);
  1209. }
  1210. }
  1211. }
  1212. break;
  1213. }
  1214. case OP_KnowledgeWindowSlotMappingMsg: {
  1215. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1216. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1217. if (packet) {
  1218. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1219. int num_updates = packet->getType_int16_ByName("spell_count");
  1220. int32 spell_id = 0;
  1221. int16 slot_id = 0;
  1222. char tmp_spell_id[15];
  1223. char tmp_slot[15];
  1224. for (int i = 0; i < num_updates; i++) {
  1225. memset(tmp_spell_id, 0, 15);
  1226. memset(tmp_slot, 0, 15);
  1227. sprintf(tmp_spell_id, "spell_id_%i", i);
  1228. sprintf(tmp_slot, "slot_id_%i", i);
  1229. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1230. if (spell_id > 0) {
  1231. slot_id = packet->getType_int16_ByName(tmp_slot);
  1232. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1233. if (spell && spell->slot != slot_id) {
  1234. spell->slot = slot_id;
  1235. spell->save_needed = true;
  1236. }
  1237. }
  1238. }
  1239. }
  1240. safe_delete(packet);
  1241. }
  1242. //SendKnowledgeWindowSlot();
  1243. break;
  1244. }
  1245. case OP_ReadyToZoneMsg: {
  1246. if (!IsReadyForSpawns())
  1247. {
  1248. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
  1249. }
  1250. else
  1251. {
  1252. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1253. if (client_zoning)
  1254. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
  1255. else
  1256. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1257. Disconnect();
  1258. }
  1259. break;
  1260. }
  1261. case OP_ClientFellMsg: {
  1262. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1263. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1264. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1265. float height = request->getType_float_ByName("height");
  1266. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1267. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1268. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1269. break;
  1270. }*/
  1271. float safe_height = 13.0f;
  1272. Skill* skill = GetPlayer()->GetSkillByName("Safe Fall", true);
  1273. if (skill)
  1274. safe_height += (skill->current_val + 1) / 5;
  1275. if (height > safe_height) {
  1276. int16 damage = (int16)ceil((height - safe_height) * 125);
  1277. if (height >= 80)
  1278. damage = 30000;
  1279. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1280. if (damage > 0) {
  1281. GetPlayer()->TakeDamage(damage);
  1282. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1283. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1284. if (!GetPlayer()->GetInvulnerable())
  1285. GetPlayer()->SetCharSheetChanged(true);
  1286. 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);
  1287. if (GetPlayer()->GetHP() == 0) {
  1288. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1289. }
  1290. }
  1291. }
  1292. safe_delete(request);
  1293. }
  1294. break;
  1295. }
  1296. case OP_MapFogDataUpdateMsg: {
  1297. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1298. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1299. break;
  1300. }
  1301. case OP_SelectZoneTeleporterDestinatio: {
  1302. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1303. ProcessTeleportLocation(app);
  1304. break;
  1305. }
  1306. case OP_SendLatestRequestMsg: {
  1307. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1308. uchar blah25[] = { 0x01 };
  1309. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1310. QueuePacket(app25);
  1311. break;
  1312. }
  1313. case OP_ShowCreateFromRecipeUIMsg: {
  1314. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1315. break;
  1316. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1317. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1318. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1319. QueuePacket(app);
  1320. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1321. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1322. QueuePacket(app);
  1323. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1324. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1325. ,0xff,0xff,0xff};
  1326. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1327. QueuePacket(app);
  1328. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1329. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1330. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1331. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1332. QueuePacket(app);
  1333. uchar blah5[] ={0x00,0x00};
  1334. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1335. QueuePacket(app);
  1336. break;*/
  1337. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1338. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1339. //QueuePacket(app);
  1340. }
  1341. case OP_BeginItemCreationMsg: {
  1342. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1343. //DumpPacket(app->pBuffer, app->size);
  1344. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1345. if (packet) {
  1346. packet->LoadPacketData(app->pBuffer, app->size);
  1347. int32 item = 0;
  1348. vector<int32> items;
  1349. char tmp_item_id[20];
  1350. item = packet->getType_int32_ByName("primary_component_id");
  1351. if (item > 0)
  1352. items.push_back(item);
  1353. item = 0;
  1354. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1355. for (int8 i = 0; i < build_components; i++) {
  1356. memset(tmp_item_id, 0, 20);
  1357. sprintf(tmp_item_id, "component_id_%i", i);
  1358. item = packet->getType_int32_ByName(tmp_item_id);
  1359. if (item > 0)
  1360. items.push_back(item);
  1361. item = 0;
  1362. }
  1363. item = packet->getType_int32_ByName("fuel_id");
  1364. if (item > 0)
  1365. items.push_back(item);
  1366. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1367. safe_delete(packet);
  1368. }
  1369. break;
  1370. }
  1371. case OP_StopItemCreationMsg: {
  1372. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1373. //DumpPacket(app->pBuffer, app->size);
  1374. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1375. break;
  1376. }
  1377. case OP_SignalMsg: {
  1378. PacketStruct* packet = configReader.getStruct("WS_Signal", GetVersion());
  1379. if (packet) {
  1380. packet->LoadPacketData(app->pBuffer, app->size);
  1381. EQ2_16BitString str = packet->getType_EQ2_16BitString_ByName("signal");
  1382. if (str.size > 0) {
  1383. if (strcmp(str.data.c_str(), "sys_client_avatar_ready") == 0) {
  1384. SetReadyForUpdates();
  1385. GetPlayer()->SendSpawnChanges(true);
  1386. }
  1387. const char* zone_script = world.GetZoneScript(player->GetZone()->GetZoneID());
  1388. if (zone_script && lua_interface)
  1389. {
  1390. lua_interface->RunZoneScript(zone_script, "signal_changed", player->GetZone(), player, 0, str.data.c_str());
  1391. }
  1392. }
  1393. }
  1394. break;
  1395. }
  1396. case OP_EntityVerbsRequestMsg: {
  1397. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1398. HandleVerbRequest(app);
  1399. break;
  1400. }
  1401. case OP_EntityVerbsVerbMsg: {
  1402. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1403. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1404. if (packet) {
  1405. packet->LoadPacketData(app->pBuffer, app->size);
  1406. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1407. player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
  1408. Spawn* spawn = player->GetTarget();
  1409. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1410. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1411. if (!HandleHouseEntityCommands(spawn, spawn_id, command))
  1412. {
  1413. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1414. if (spawn->IsGroundSpawn())
  1415. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1416. else if (spawn->IsObject())
  1417. ((Object*)spawn)->HandleUse(this, command);
  1418. else if (spawn->IsWidget())
  1419. ((Widget*)spawn)->HandleUse(this, command);
  1420. else if (spawn->IsSign())
  1421. ((Sign*)spawn)->HandleUse(this, command);
  1422. }
  1423. }
  1424. }
  1425. else {
  1426. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1427. if (command.size > 0) {
  1428. string command_name = command.data;
  1429. if (command_name.find(" ") < 0xFFFFFFFF) {
  1430. if (GetVersion() <= 546) { //this version uses commands in the form "Buy From Merchant" instead of buy_from_merchant
  1431. string::size_type pos = command_name.find(" ");
  1432. while(pos != string::npos){
  1433. command_name.replace(pos, 1, "_");
  1434. pos = command_name.find(" ");
  1435. }
  1436. }
  1437. else
  1438. command_name = command_name.substr(0, command_name.find(" "));
  1439. }
  1440. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1441. if (handler != 0xFFFFFFFF) {
  1442. if (command.data == command_name) {
  1443. command.data = "";
  1444. command.size = 0;
  1445. }
  1446. else {
  1447. command.data = command.data.substr(command.data.find(" ") + 1);
  1448. command.size = command.data.length();
  1449. }
  1450. commands.Process(handler, &command, this);
  1451. }
  1452. else {
  1453. if (spawn && spawn->IsNPC()) {
  1454. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1455. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1456. command_name = command.data;
  1457. string::size_type pos = command_name.find(" ");
  1458. while (pos != string::npos) {
  1459. command_name.replace(pos, 1, "_");
  1460. pos = command_name.find(" ");
  1461. }
  1462. if (!((NPC*)spawn)->HandleUse(this, command_name)) { //convert the spaces to underscores and see if that makes a difference
  1463. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1464. }
  1465. }
  1466. }
  1467. }
  1468. else
  1469. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1470. }
  1471. }
  1472. }
  1473. safe_delete(packet);
  1474. }
  1475. break;
  1476. }
  1477. case OP_SkillInfoRequest: {
  1478. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1479. HandleSkillInfoRequest(app);
  1480. break;
  1481. }
  1482. case OP_UpdateTargetMsg: {
  1483. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1484. int16 index = 0;
  1485. memcpy(&index, app->pBuffer, sizeof(int16));
  1486. if (index == 0xFFFF)
  1487. GetPlayer()->SetTarget(0);
  1488. else
  1489. GetPlayer()->SetTarget(GetPlayer()->GetSpawnByIndex(index));
  1490. if (GetPlayer()->GetTarget())
  1491. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1492. //player->SetTarget((int16*)app->pBuffer);
  1493. break;
  1494. }
  1495. case OP_ExamineInfoRequestMsg: {
  1496. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1497. HandleExamineInfoRequest(app);
  1498. break;
  1499. }
  1500. case OP_QuickbarUpdateMsg:
  1501. //case OP_QuickbarAddMsg:
  1502. {
  1503. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1504. HandleQuickbarUpdateRequest(app);
  1505. break;
  1506. }
  1507. case OP_PredictionUpdateMsg: {
  1508. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg", opcode, opcode);
  1509. if (version <= 546) {
  1510. int8 offset = 9;
  1511. if (app->pBuffer[0] == 0xFF)
  1512. offset += 2;
  1513. if (app->size > offset) {
  1514. if (player->IsCasting()) {
  1515. float distance = 0;
  1516. float x = player->GetX();
  1517. float y = player->GetY();
  1518. float z = player->GetZ();
  1519. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1520. distance = player->GetDistance(x, y, z, false);
  1521. if (distance > .5)
  1522. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1523. }
  1524. else
  1525. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1526. player_pos_changed = true;
  1527. //DumpPacket(app);
  1528. }
  1529. }
  1530. else {
  1531. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1532. QueuePacket(app);
  1533. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1534. }
  1535. break;
  1536. }
  1537. case OP_RemoteCmdMsg: {
  1538. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1539. if (app->size > 0) {
  1540. EQ2_CommandString remote(app->pBuffer, app->size);
  1541. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1542. #if EQDEBUG >= 9
  1543. DumpPacket(app);
  1544. #endif
  1545. commands.Process(remote.handler, &remote.command, this);
  1546. }
  1547. else //bad client, disconnect
  1548. Disconnect();
  1549. break;
  1550. }
  1551. case OP_CancelSpellCast: {
  1552. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1553. current_zone->Interrupted(player, 0, 0, true);
  1554. SimpleMessage(CHANNEL_SPELLS_OTHER, "You stop casting.");
  1555. break;
  1556. }
  1557. case OP_UpdatePositionMsg: {
  1558. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg", opcode, opcode);
  1559. int8 offset = 13;
  1560. if (app->pBuffer[0] == 0xFF)
  1561. offset += 2;
  1562. if (app->size > offset) {
  1563. if (player->IsCasting()) {
  1564. float distance = 0;
  1565. float x = player->GetX();
  1566. float y = player->GetY();
  1567. float z = player->GetZ();
  1568. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1569. distance = player->GetDistance(x, y, z, false);
  1570. if (distance > .5)
  1571. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1572. }
  1573. else
  1574. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1575. player_pos_changed = true;
  1576. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1577. //DumpPacket(app);
  1578. }
  1579. break;
  1580. }
  1581. case OP_MailSendMessageMsg: {
  1582. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1583. HandleSentMail(app);
  1584. break;
  1585. }
  1586. case OP_StopTrackingMsg: {
  1587. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1588. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1589. break;
  1590. }
  1591. case OP_BeginTrackingMsg: {
  1592. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1593. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1594. if (packet) {
  1595. packet->LoadPacketData(app->pBuffer, app->size);
  1596. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1597. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1598. if (spawn) {
  1599. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1600. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1601. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1602. }
  1603. safe_delete(packet);
  1604. }
  1605. break;
  1606. }
  1607. case OP_BioUpdateMsg: {
  1608. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  1609. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  1610. if (packet) {
  1611. packet->LoadPacketData(app->pBuffer, app->size);
  1612. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  1613. safe_delete(packet);
  1614. }
  1615. break;
  1616. }
  1617. case OP_RewardPackMsg: {
  1618. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  1619. /* 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
  1620. when we come across it (scatman) */
  1621. const char* name = app->GetOpcodeName();
  1622. if (name)
  1623. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  1624. else
  1625. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  1626. //DumpPacket(app);
  1627. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  1628. if (packet) {
  1629. packet->LoadPacketData(app->pBuffer, app->size);
  1630. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  1631. /* Player has contacted a guild recruiter */
  1632. if (recruiter_name.length() > 0) {
  1633. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  1634. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  1635. if (recruiter && guild) {
  1636. Message(CHANNEL_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  1637. recruiter->Message(CHANNEL_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()));
  1638. recruiter->PlaySound("ui_guild_page");
  1639. }
  1640. }
  1641. /* New picture taken for guild recruiting */
  1642. else {
  1643. //DumpPacket(app->pBuffer, app->size);
  1644. int32 guild_id = 0;
  1645. int16 picture_data_size = 0;
  1646. unsigned char* recruiter_picture_data = 0;
  1647. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  1648. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  1649. Guild* guild = guild_list.GetGuild(guild_id);
  1650. if (guild) {
  1651. GuildMember* gm = guild->GetGuildMember(player);
  1652. if (gm) {
  1653. safe_delete_array(gm->recruiter_picture_data);
  1654. recruiter_picture_data = new unsigned char[picture_data_size];
  1655. for (int16 i = 0; i < picture_data_size; i++)
  1656. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  1657. gm->recruiter_picture_data = recruiter_picture_data;
  1658. gm->recruiter_picture_data_size = picture_data_size;
  1659. guild->SetMemberSaveNeeded(true);
  1660. }
  1661. }
  1662. }
  1663. safe_delete(packet);
  1664. }
  1665. break;
  1666. }
  1667. case OP_PetOptions: {
  1668. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  1669. Spawn* target = player->GetTarget();
  1670. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  1671. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  1672. bool change = false;
  1673. packet->LoadPacketData(app->pBuffer, app->size);
  1674. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  1675. if (strlen(name.c_str()) != 0) {
  1676. target->SetName(name.c_str());
  1677. strcpy(player->GetInfoStruct()->pet_name, name.c_str());
  1678. GetCurrentZone()->SendUpdateTitles(target);
  1679. change = true;
  1680. }
  1681. // Check protect self setting and update if needed
  1682. if (packet->getType_int8_ByName("protect_self") == 1) {
  1683. if ((player->GetInfoStruct()->pet_behavior & 2) == 0) {
  1684. player->GetInfoStruct()->pet_behavior += 2;
  1685. change = true;
  1686. }
  1687. }
  1688. else {
  1689. if ((player->GetInfoStruct()->pet_behavior & 2) != 0) {
  1690. player->GetInfoStruct()->pet_behavior -= 2;
  1691. change = true;
  1692. }
  1693. }
  1694. // Check protect master setting and update if needed
  1695. if (packet->getType_int8_ByName("protect_master") == 1) {
  1696. if ((player->GetInfoStruct()->pet_behavior & 1) == 0) {
  1697. player->GetInfoStruct()->pet_behavior += 1;
  1698. change = true;
  1699. }
  1700. }
  1701. else {
  1702. if ((player->GetInfoStruct()->pet_behavior & 1) != 0) {
  1703. player->GetInfoStruct()->pet_behavior -= 1;
  1704. change = true;
  1705. }
  1706. }
  1707. // Check stay/follow setting and update if needed
  1708. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  1709. if (player->GetInfoStruct()->pet_movement != 2) {
  1710. player->GetInfoStruct()->pet_movement = 2;
  1711. change = true;
  1712. }
  1713. }
  1714. else {
  1715. if (player->GetInfoStruct()->pet_movement != 1) {
  1716. player->GetInfoStruct()->pet_movement = 1;
  1717. change = true;
  1718. }
  1719. }
  1720. // Ranged/Melee settings are not implemented yet
  1721. if (change)
  1722. player->SetCharSheetChanged(true);
  1723. safe_delete(packet);
  1724. }
  1725. break;
  1726. }
  1727. case OP_RecipeBook: {
  1728. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  1729. SendRecipeList();
  1730. break;
  1731. }
  1732. case OP_BuyPlayerHouseMsg: {
  1733. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  1734. DumpPacket(app);
  1735. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  1736. if (packet) {
  1737. packet->LoadPacketData(app->pBuffer, app->size);
  1738. HouseZone* hz = world.GetHouseZone(packet->getType_int64_ByName("house_id"));
  1739. if (hz) {
  1740. std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
  1741. if (houses.size() > 24)
  1742. {
  1743. SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
  1744. safe_delete(packet);
  1745. break;
  1746. }
  1747. if ((!hz->upkeep_coin && !hz->cost_coin) || player->RemoveCoins(hz->cost_coin+hz->upkeep_coin)) // TODO: Need option to take from bank if player does not have enough coin on them
  1748. {
  1749. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id);
  1750. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  1751. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  1752. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  1753. //ClientPacketFunctions::SendHousingList(this);
  1754. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  1755. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  1756. PlaySound("coin_cha_ching");
  1757. }
  1758. else
  1759. {
  1760. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
  1761. PlaySound("buy_failed");
  1762. }
  1763. }
  1764. }
  1765. safe_delete(packet);
  1766. break;
  1767. }
  1768. case OP_EnterHouseMsg: {
  1769. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  1770. DumpPacket(app);
  1771. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  1772. if (packet) {
  1773. packet->LoadPacketData(app->pBuffer, app->size);
  1774. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(packet->getType_int64_ByName("house_id"));
  1775. if (ph) {
  1776. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1777. if (hz) {
  1778. ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id);
  1779. if (house) {
  1780. Zone(house, true);
  1781. }
  1782. }
  1783. }
  1784. }
  1785. safe_delete(packet);
  1786. break;
  1787. }
  1788. case OP_PayHouseUpkeepMsg: {
  1789. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  1790. DumpPacket(app);
  1791. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  1792. if (packet) {
  1793. packet->LoadPacketData(app->pBuffer, app->size);
  1794. int64 houseID = packet->getType_int64_ByName("house_id");
  1795. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(houseID);
  1796. if (ph)
  1797. {
  1798. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1799. if (!hz)
  1800. {
  1801. Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
  1802. safe_delete(packet);
  1803. break;
  1804. }
  1805. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
  1806. if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
  1807. {
  1808. upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
  1809. if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
  1810. {
  1811. Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
  1812. PlaySound("buy_failed");
  1813. safe_delete(packet);
  1814. break;
  1815. }
  1816. }
  1817. int64 coinReq = hz->upkeep_coin;
  1818. int64 tmpRecoverCoins = 0;
  1819. bool escrowChange = false;
  1820. if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
  1821. {
  1822. escrowChange = true;
  1823. tmpRecoverCoins = ph->escrow_coins;
  1824. coinReq -= ph->escrow_coins;
  1825. ph->escrow_coins = 0;
  1826. }
  1827. else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
  1828. {
  1829. escrowChange = true;
  1830. // more than enough in escrow, subtract and make our cost 0!
  1831. ph->escrow_coins -= coinReq;
  1832. coinReq = 0;
  1833. }
  1834. // TODO: Need support for upkeep_status, but alas status_points are not implemented!
  1835. if (!coinReq || coinReq && player->RemoveCoins(coinReq)) // TODO: Need option to take from bank if player does not have enough coin on them
  1836. {
  1837. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  1838. if (escrowChange)
  1839. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins);
  1840. ph->upkeep_due = upkeep_due;
  1841. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  1842. //ClientPacketFunctions::SendHousingList(this);
  1843. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  1844. PlaySound("coin_cha_ching");
  1845. }
  1846. else
  1847. {
  1848. // recover the escrow we were going to use but could not spend due to lack of funds
  1849. if (tmpRecoverCoins)
  1850. ph->escrow_coins += tmpRecoverCoins;
  1851. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to pay for upkeep.");
  1852. PlaySound("buy_failed");
  1853. }
  1854. }
  1855. else
  1856. Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", houseID);
  1857. }
  1858. safe_delete(packet);
  1859. break;
  1860. }
  1861. case OP_ExitHouseMsg: {
  1862. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  1863. int32 instance_id = GetCurrentZone()->GetInstanceID();
  1864. if (instance_id > 0) {
  1865. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  1866. if (ph) {
  1867. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1868. if (hz) {
  1869. ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
  1870. // determine if this is an instanced zone that already exists
  1871. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
  1872. if (instance_zone || new_zone) {
  1873. GetPlayer()->SetX(hz->exit_x);
  1874. GetPlayer()->SetY(hz->exit_y);
  1875. GetPlayer()->SetZ(hz->exit_z);
  1876. GetPlayer()->SetHeading(hz->exit_heading);
  1877. if (instance_zone)
  1878. Zone(instance_zone->GetInstanceID(), false, true);
  1879. else
  1880. Zone(new_zone, false);
  1881. }
  1882. }
  1883. }
  1884. }
  1885. DumpPacket(app);
  1886. break;
  1887. }
  1888. case OP_QuestJournalWaypointMsg: {
  1889. //DumpPacket(app);
  1890. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  1891. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  1892. if (packet) {
  1893. packet->LoadPacketData(app->pBuffer, app->size);
  1894. int32 quests = packet->getType_int32_ByName("num_quests");
  1895. if (quests > 100) // just picking a number higher than max allowed
  1896. {
  1897. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  1898. break;
  1899. }
  1900. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  1901. for (int32 i = 0; i < quests; i++) {
  1902. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  1903. if (id == 0)
  1904. continue;
  1905. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  1906. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  1907. if (player->player_quests.count(id) > 0) {
  1908. player->player_quests[id]->SetTracked(tracked);
  1909. player->player_quests[id]->SetSaveNeeded(true);
  1910. }
  1911. }
  1912. safe_delete(packet);
  1913. }
  1914. break;
  1915. }
  1916. case OP_PaperdollImage: {
  1917. PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  1918. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  1919. //First check if this is a new image... delete an existing partial image if one exists
  1920. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  1921. if (packet_index == 0) {
  1922. safe_delete_array(incoming_paperdoll.image_bytes);
  1923. incoming_paperdoll.last_received_packet_index = 0;
  1924. incoming_paperdoll.current_size_bytes = 0;
  1925. }
  1926. //return if this packet is not the one we are expecting...
  1927. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  1928. safe_delete(packet);
  1929. break;
  1930. }
  1931. //Check how many packets we're supposed to be receiving for this/these images
  1932. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  1933. //Check the image type, if this is a new type in the same series of packets we have a new image
  1934. int8 img_type = packet->getType_int8_ByName("image_type");
  1935. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  1936. //We have a new image. Save the old data and clear before continuing
  1937. SavePlayerImages();
  1938. }
  1939. incoming_paperdoll.image_type = img_type;
  1940. //Get the size of the image data in this packet
  1941. sint64 image_size = packet->getType_int32_ByName("imageSize");
  1942. if (image_size <= 0 || image_size > 1048576) {
  1943. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  1944. safe_delete(packet);
  1945. break;
  1946. }
  1947. //Create a new array
  1948. int32 new_image_size = image_size;
  1949. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  1950. if (incoming_paperdoll.image_bytes) {
  1951. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  1952. safe_delete_array(incoming_paperdoll.image_bytes);
  1953. }
  1954. //variable i should be the index in the packet of the first PNG file byte
  1955. vector<DataStruct*>* d_structs = packet->getStructs();
  1956. vector<DataStruct*>::iterator itr;
  1957. int32 i = 0;
  1958. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  1959. DataStruct* ds = (*itr);
  1960. if (strcmp(ds->GetName(), "pngData_0") != 0)
  1961. i += ds->GetDataSizeInBytes();
  1962. else
  1963. break;
  1964. }
  1965. //Return if this packet is bad and we would read out of bounds
  1966. if (app->size - i < new_image_size) {
  1967. safe_delete(packet);
  1968. safe_delete_array(new_image);
  1969. break;
  1970. }
  1971. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  1972. memcpy(tmp, app->pBuffer + i, new_image_size);
  1973. incoming_paperdoll.current_size_bytes += new_image_size;
  1974. incoming_paperdoll.image_bytes = new_image;
  1975. //Check if this is the last packet we're expecting for this image. Create a final image if so
  1976. if (incoming_paperdoll.image_num_packets == 1 ||
  1977. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  1978. SavePlayerImages();
  1979. }
  1980. incoming_paperdoll.last_received_packet_index = packet_index;
  1981. }
  1982. safe_delete(packet);
  1983. break;
  1984. }
  1985. case OP_ReadyForTakeOffMsg:
  1986. {
  1987. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  1988. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  1989. if (GetPendingFlightPath() > 0) {
  1990. if (index != -1) {
  1991. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  1992. if (packet) {
  1993. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  1994. packet->setDataByName("path_id", index);
  1995. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  1996. QueuePacket(packet->serialize());
  1997. safe_delete(packet);
  1998. on_auto_mount = true;
  1999. }
  2000. }
  2001. else {
  2002. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2003. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2004. EndAutoMount();
  2005. }
  2006. SetPendingFlightPath(0);
  2007. }
  2008. else
  2009. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  2010. break;
  2011. }
  2012. case OP_EarlyLandingRequestMsg:
  2013. {
  2014. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  2015. EndAutoMount();
  2016. break;
  2017. }
  2018. case OP_SubmitCharCust:
  2019. {
  2020. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  2021. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  2022. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2023. int8 type = packet->getType_int8_ByName("type");
  2024. if (type == 0) {
  2025. if (player->custNPC) {
  2026. player->custNPCTarget->CustomizeAppearance(packet);
  2027. current_zone->SendSpawnChanges(player->custNPCTarget);
  2028. }
  2029. else {
  2030. player->CustomizeAppearance(packet);
  2031. current_zone->SendSpawnChanges(player);
  2032. }
  2033. }
  2034. }
  2035. if (player->custNPC) {
  2036. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  2037. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  2038. if (player->custNPCTarget->IsBot())
  2039. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  2040. player->custNPC = false;
  2041. player->custNPCTarget = 0;
  2042. player->changed = true;
  2043. player->info_changed = true;
  2044. current_zone->SendSpawnChanges(player, this);
  2045. }
  2046. break;
  2047. }
  2048. default: {
  2049. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  2050. const char* name = app->GetOpcodeName();
  2051. if (name)
  2052. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  2053. else
  2054. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  2055. //DumpPacket(app);
  2056. }
  2057. }
  2058. if (!eqs || !eqs->CheckActive()) {
  2059. return false;
  2060. }
  2061. return ret;
  2062. }
  2063. bool Client::HandleLootItem(Spawn* entity, Item* item) {
  2064. if (!item) {
  2065. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  2066. return false;
  2067. }
  2068. if (player->item_list.HasFreeSlot() || player->item_list.CanStack(item)) {
  2069. if (player->item_list.AssignItemToFreeSlot(item)) {
  2070. int8 type = CHANNEL_LOOT;
  2071. if (entity) {
  2072. Message(type, "You loot %s from the corpse of %s", item->CreateItemLink(GetVersion()).c_str(), entity->GetName());
  2073. }
  2074. else {
  2075. Message(type, "You found a %s.", item->CreateItemLink(GetVersion()).c_str());
  2076. }
  2077. Guild* guild = player->GetGuild();
  2078. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  2079. char adjective[32];
  2080. int8 type;
  2081. memset(adjective, 0, sizeof(adjective));
  2082. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  2083. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  2084. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  2085. }
  2086. else if (item->details.tier >= ITEM_TAG_FABLED) {
  2087. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  2088. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  2089. }
  2090. else {
  2091. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  2092. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  2093. }
  2094. guild->AddNewGuildEvent(type, "%s has looted the %s %s", Timer::GetUnixTimeStamp(), true, player->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2095. guild->SendMessageToGuild(type, "%s has looted the %s %s", player->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2096. }
  2097. CheckPlayerQuestsItemUpdate(item);
  2098. return true;
  2099. }
  2100. else
  2101. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  2102. }
  2103. else
  2104. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  2105. return false;
  2106. }
  2107. bool Client::HandleLootItem(Spawn* entity, int32 item_id) {
  2108. if (!entity) {
  2109. return false;
  2110. }
  2111. return HandleLootItem(entity, entity->LootItem(item_id));
  2112. }
  2113. void Client::HandleLoot(EQApplicationPacket* app) {
  2114. PacketStruct* packet = configReader.getStruct("WS_LootType", GetVersion());
  2115. if (packet) {
  2116. packet->LoadPacketData(app->pBuffer, app->size);
  2117. int32 loot_id = packet->getType_int32_ByName("loot_id");
  2118. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  2119. safe_delete(packet);
  2120. int32 item_id = 0;
  2121. Item* item = 0;
  2122. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  2123. if (player->HasPendingLootItems(loot_id)) {
  2124. Item* master_item = 0;
  2125. if (loot_all) {
  2126. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2127. if (items) {
  2128. for (int32 i = 0; loot_all && i < items->size(); i++) {
  2129. master_item = items->at(i);
  2130. if (master_item) {
  2131. item = new Item(master_item);
  2132. if (item) {
  2133. loot_all = HandleLootItem(0, item);
  2134. if (loot_all)
  2135. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2136. }
  2137. }
  2138. }
  2139. safe_delete(items);
  2140. }
  2141. }
  2142. else {
  2143. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2144. if (packet) {
  2145. packet->LoadPacketData(app->pBuffer, app->size);
  2146. item_id = packet->getType_int32_ByName("item_id");
  2147. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2148. if (items) {
  2149. for (int32 i = 0; i < items->size(); i++) {
  2150. master_item = items->at(i);
  2151. if (master_item && master_item->details.item_id == item_id) {
  2152. item = new Item(master_item);
  2153. if (item && HandleLootItem(0, item))
  2154. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2155. break;
  2156. }
  2157. }
  2158. safe_delete(items);
  2159. }
  2160. safe_delete(packet);
  2161. }
  2162. }
  2163. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2164. if (outapp)
  2165. QueuePacket(outapp);
  2166. Loot(0, player->GetPendingLootItems(loot_id), spawn);
  2167. }
  2168. else {
  2169. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  2170. if (loot_all) {
  2171. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2172. loot_all = HandleLootItem(spawn, item_id);
  2173. }
  2174. }
  2175. else {
  2176. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2177. if (packet) {
  2178. packet->LoadPacketData(app->pBuffer, app->size);
  2179. item_id = packet->getType_int32_ByName("item_id");
  2180. HandleLootItem(spawn, item_id);
  2181. safe_delete(packet);
  2182. }
  2183. }
  2184. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2185. if (outapp)
  2186. QueuePacket(outapp);
  2187. Loot(spawn);
  2188. if (!spawn->HasLoot()) {
  2189. CloseLoot(loot_id);
  2190. if (spawn->IsNPC())
  2191. GetCurrentZone()->RemoveDeadSpawn(spawn);
  2192. }
  2193. }
  2194. else {
  2195. if (!spawn) {
  2196. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  2197. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  2198. }
  2199. else
  2200. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  2201. }
  2202. }
  2203. }
  2204. }
  2205. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  2206. PacketStruct* request = 0;
  2207. // cout << "Request: \n";
  2208. // DumpPacket(app);
  2209. switch (app->pBuffer[0]) {
  2210. case 0: { //items
  2211. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  2212. if (request) {
  2213. request->LoadPacketData(app->pBuffer, app->size);
  2214. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  2215. if (!item)
  2216. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  2217. if (item) {
  2218. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  2219. if (response) {
  2220. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  2221. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  2222. response->setSmallStringByName("name", item->name.c_str());
  2223. EQ2Packet* app2 = response->serialize();
  2224. //DumpPacket(app2);
  2225. QueuePacket(app2);
  2226. safe_delete(response);
  2227. }
  2228. }
  2229. }
  2230. break;
  2231. }
  2232. case 2: {//spells
  2233. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  2234. if (request) {
  2235. request->LoadPacketData(app->pBuffer, app->size);
  2236. int32 id = request->getType_int32_ByName("id");
  2237. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  2238. Spell* spell = master_spell_list.GetSpell(id, tier);
  2239. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  2240. if (response) {
  2241. response->setDataByName("request_type", 2);
  2242. response->setDataByName("unique_id", tier);
  2243. response->setDataByName("id", id);
  2244. if (spell)
  2245. response->setSmallStringByName("name", spell->GetName());
  2246. else
  2247. response->setSmallStringByName("name", "Unknown Spell");
  2248. EQ2Packet* app2 = response->serialize();
  2249. // DumpPacket(app2);
  2250. QueuePacket(app2);
  2251. safe_delete(response);
  2252. }
  2253. }
  2254. break;
  2255. }
  2256. default: {
  2257. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2258. }
  2259. }
  2260. safe_delete(request);
  2261. }
  2262. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2263. PacketStruct* request = 0;
  2264. if (!app || app->size == 0)
  2265. return;
  2266. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2267. //DumpPacket(app);
  2268. int8 type = app->pBuffer[0];
  2269. //283: item: 0, effect: 1, recipe: 2, spell: 3
  2270. if (version <= 283) {
  2271. if (type == 1)
  2272. type = 4;
  2273. else if (type == 2)
  2274. type = 5;
  2275. }
  2276. if (type == 3) {
  2277. Spell* spell = 0;
  2278. bool trait_display;
  2279. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2280. if (!request) {
  2281. return;
  2282. }
  2283. request->LoadPacketData(app->pBuffer, app->size);
  2284. int32 id = request->getType_int32_ByName("id");
  2285. int32 tier = request->getType_int32_ByName("tier");
  2286. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  2287. bool display = true;
  2288. if (version <= 283 && request->getType_int8_ByName("display") == 1) // this is really requesting a partial packet
  2289. display = false;
  2290. else if (version <= 546)
  2291. display = request->getType_int8_ByName("display");
  2292. else if (version > 546)
  2293. display = false; // clients default is false otherwise it pops up a window when hovering over the knowledge book abilities
  2294. //printf("Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)\n",type,tier,trait_tier,id);
  2295. if (trait_tier != 0xFFFFFFFF) {
  2296. spell = master_spell_list.GetSpell(id, trait_tier);
  2297. if (!spell) {
  2298. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  2299. }
  2300. trait_display = true;
  2301. }
  2302. else {
  2303. spell = master_spell_list.GetSpell(id, tier);
  2304. trait_display = false;
  2305. }
  2306. // if we can't find it on the master spell list, see if it is a custom spell
  2307. if (!spell)
  2308. {
  2309. lua_interface->FindCustomSpellLock();
  2310. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2311. if (tmpSpell)
  2312. spell = tmpSpell->spell;
  2313. lua_interface->FindCustomSpellUnlock();
  2314. }
  2315. if (spell && sent_spell_details.count(id) == 0) {
  2316. if (!spell->IsCopiedSpell())
  2317. sent_spell_details[id] = true;
  2318. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display);
  2319. //DumpPacket(app);
  2320. QueuePacket(app);
  2321. }
  2322. }
  2323. else if (type == 0) {
  2324. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2325. if (!request) {
  2326. return;
  2327. }
  2328. request->LoadPacketData(app->pBuffer, app->size);
  2329. int32 id = request->getType_int32_ByName("id");
  2330. Item* item = 0;
  2331. // translate from unique id to spawn id for houses
  2332. Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
  2333. bool wasSpawn = false;
  2334. if (spawn)
  2335. {
  2336. item = master_item_list.GetItem(spawn->GetPickupItemID());
  2337. if (item)
  2338. {
  2339. wasSpawn = true;
  2340. item = new Item(item);
  2341. item->details.unique_id = spawn->GetPickupUniqueItemID();
  2342. }
  2343. }
  2344. if (!item)
  2345. item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  2346. if (!item)
  2347. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  2348. if (!item)
  2349. item = master_item_list.GetItem(id);
  2350. if (item) {// && sent_item_details.count(id) == 0){
  2351. sent_item_details[id] = true;
  2352. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2353. //DumpPacket(app);
  2354. QueuePacket(app);
  2355. if (wasSpawn)
  2356. delete item;
  2357. }
  2358. else {
  2359. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2360. DumpPacket(app);
  2361. }
  2362. }
  2363. else if (type == 1) {
  2364. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2365. if (!request) {
  2366. return;
  2367. }
  2368. request->LoadPacketData(app->pBuffer, app->size);
  2369. int32 id = request->getType_int32_ByName("id");
  2370. int32 unique_id = request->getType_int32_ByName("unique_id");
  2371. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  2372. if (!item)
  2373. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  2374. if (!item)
  2375. item = master_item_list.GetItem(id);
  2376. if (item) {
  2377. sent_item_details[id] = true;
  2378. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2379. //DumpPacket(app);
  2380. QueuePacket(app);
  2381. }
  2382. else {
  2383. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2384. DumpPacket(app);
  2385. }
  2386. }
  2387. else if (type == 2) {
  2388. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  2389. if (!request) {
  2390. return;
  2391. }
  2392. request->LoadPacketData(app->pBuffer, app->size);
  2393. int32 id = request->getType_int32_ByName("item_id");
  2394. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  2395. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  2396. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  2397. //int32 unique_id = request->getType_int32_ByName("unique_id");
  2398. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  2399. //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);
  2400. Item* item = master_item_list.GetItem(id);
  2401. if (item) {
  2402. //only display popup for non merchant links
  2403. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, true);
  2404. //DumpPacket(app);
  2405. QueuePacket(app);
  2406. }
  2407. else {
  2408. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2409. DumpPacket(app);
  2410. }
  2411. }
  2412. else if (type == 4) { //spell effect
  2413. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  2414. if (!request) {
  2415. return;
  2416. }
  2417. request->LoadPacketData(app->pBuffer, app->size);
  2418. int32 id = request->getType_int32_ByName("id");
  2419. int16 display = request->getType_int8_ByName("partial_info");
  2420. SpellEffects* effect = player->GetSpellEffect(id);
  2421. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  2422. if (effect) {
  2423. int8 tier = effect->tier;
  2424. Spell* spell = master_spell_list.GetSpell(id, tier);
  2425. // if we can't find it on the master spell list, see if it is a custom spell
  2426. if (!spell)
  2427. {
  2428. lua_interface->FindCustomSpellLock();
  2429. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2430. EQ2Packet* pack = 0;
  2431. if (tmpSpell)
  2432. spell = tmpSpell->spell;
  2433. lua_interface->FindCustomSpellUnlock();
  2434. }
  2435. if (spell && sent_spell_details.count(id) == 0) {
  2436. if (!spell->IsCopiedSpell())
  2437. sent_spell_details[id] = true;
  2438. int8 type = 0;
  2439. if (version <= 283)
  2440. type = 1;
  2441. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, type, 0x81);
  2442. //DumpPacket(app);
  2443. QueuePacket(app);
  2444. }
  2445. }
  2446. }
  2447. else if (type == 5) { // recipe info
  2448. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2449. if (!request)
  2450. return;
  2451. request->LoadPacketData(app->pBuffer, app->size);
  2452. int32 id = request->getType_int32_ByName("unknown_id");
  2453. Recipe* recipe = master_recipe_list.GetRecipe(id);
  2454. if (recipe) {
  2455. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  2456. //DumpPacket(app);
  2457. QueuePacket(app);
  2458. }
  2459. }
  2460. else if (type == 6) { // AA spell info
  2461. Spell* spell = 0;
  2462. //Spell* spell2 = 0;
  2463. //AltAdvanceData* data = 0;
  2464. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2465. if (!request)
  2466. return;
  2467. request->LoadPacketData(app->pBuffer, app->size);
  2468. int32 id = request->getType_int32_ByName("id");
  2469. int32 tier = GetPlayer()->GetSpellTier(id);
  2470. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  2471. //data = master_aa_list.GetAltAdvancement(id);
  2472. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  2473. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  2474. spell = master_spell_list.GetSpell(id, tier);
  2475. if (!spell)
  2476. spell = master_spell_list.GetSpell(id, 1);
  2477. if (!spell)
  2478. {
  2479. lua_interface->FindCustomSpellLock();
  2480. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2481. if (tmpSpell)
  2482. spell = tmpSpell->spell;
  2483. lua_interface->FindCustomSpellUnlock();
  2484. }
  2485. if (!spell)
  2486. {
  2487. LogWrite(WORLD__ERROR, 0, "WORLD", "FAILED Examine Info Request-> Spell ID: %u, tier: %i", id, tier);
  2488. return;
  2489. }
  2490. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  2491. if (!spell->IsCopiedSpell())
  2492. sent_spell_details[spell->GetSpellID()] = true;
  2493. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  2494. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  2495. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  2496. //DumpPacket(app);
  2497. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  2498. QueuePacket(app);
  2499. //}
  2500. }
  2501. else {
  2502. LogWrite(WORLD__ERROR, 0, "World", "Unknown examine request: %i", (int)type);
  2503. DumpPacket(app);
  2504. }
  2505. safe_delete(request);
  2506. }
  2507. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  2508. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  2509. if (request) {
  2510. request->LoadPacketData(app->pBuffer, app->size);
  2511. int32 id = request->getType_int32_ByName("id");
  2512. int32 bar = request->getType_int32_ByName("hotbar_number");
  2513. int32 slot = request->getType_int32_ByName("hotkey_slot");
  2514. int32 type = request->getType_int32_ByName("type");
  2515. int8 tier = request->getType_int32_ByName("unique_id");
  2516. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  2517. Spell* spell = 0;
  2518. if (type == 0xFFFFFFFF)
  2519. GetPlayer()->RemoveQuickbarItem(bar, slot);
  2520. else {
  2521. if (type == QUICKBAR_NORMAL)
  2522. spell = master_spell_list.GetSpell(id, tier);
  2523. if (spell)
  2524. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  2525. else
  2526. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  2527. }
  2528. safe_delete(request);
  2529. }
  2530. }
  2531. bool Client::Process(bool zone_process) {
  2532. if (!eqs) {
  2533. return false;
  2534. }
  2535. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  2536. return true;
  2537. }
  2538. if (new_client_login) {
  2539. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  2540. SendLoginInfo();
  2541. new_client_login = false;
  2542. }
  2543. bool ret = true;
  2544. sockaddr_in to;
  2545. memset((char*)&to, 0, sizeof(to));
  2546. to.sin_family = AF_INET;
  2547. to.sin_port = port;
  2548. to.sin_addr.s_addr = ip;
  2549. /************ Get all packets from packet manager out queue and process them ************/
  2550. EQApplicationPacket* app = 0;
  2551. if (eqs && !eqs->CheckActive()) {
  2552. num_active_failures++;
  2553. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  2554. if (num_active_failures > 100) {
  2555. return false;
  2556. }
  2557. return true;
  2558. }
  2559. while (ret && eqs && (app = eqs->PopPacket())) {
  2560. ret = HandlePacket(app);
  2561. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  2562. delete app;
  2563. }
  2564. if (GetCurrentZone() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  2565. player->ApplyPassiveSpells();
  2566. //database.LoadCharacterActiveSpells(player);
  2567. player->UnlockAllSpells(true);
  2568. should_load_spells = false;
  2569. }
  2570. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  2571. {
  2572. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  2573. return false;
  2574. }
  2575. if (quest_updates) {
  2576. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  2577. ProcessQuestUpdates();
  2578. }
  2579. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - 300)) {
  2580. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  2581. CheckQuestQueue();
  2582. }
  2583. if (pos_update.Check())
  2584. {
  2585. if(GetPlayer()->GetRegionMap())
  2586. GetPlayer()->GetRegionMap()->TicRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2587. if(player_pos_changed && IsReadyForUpdates() && ( !disconnect_timer || !disconnect_timer->Enabled())) {
  2588. //GetPlayer()->CalculateLocation();
  2589. client_list.CheckPlayersInvisStatus(this);
  2590. GetCurrentZone()->SendPlayerPositionChanges(GetPlayer());
  2591. player_pos_changed = false;
  2592. GetCurrentZone()->CheckTransporters(this);
  2593. if(GetPlayer()->GetRegionMap())
  2594. {
  2595. if((lastRegionRemapTime+1000) < Timer::GetCurrentTime2())
  2596. {
  2597. lastRegionRemapTime = Timer::GetCurrentTime2() + 1000;
  2598. GetPlayer()->GetRegionMap()->MapRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2599. }
  2600. else
  2601. GetPlayer()->GetRegionMap()->UpdateRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2602. }
  2603. }
  2604. }
  2605. if (lua_interface && lua_debug && lua_debug_timer.Check())
  2606. lua_interface->UpdateDebugClients(this);
  2607. if (quest_pos_timer.Check())
  2608. CheckPlayerQuestsLocationUpdate();
  2609. if (camp_timer && camp_timer->Check() && getConnection()) {
  2610. getConnection()->SendDisconnect(false);
  2611. safe_delete(camp_timer);
  2612. disconnect_timer = new Timer(2000);
  2613. disconnect_timer->Start();
  2614. }
  2615. if (player->GetSkills()->HasSkillUpdates()) {
  2616. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  2617. if (skills) {
  2618. Skill* skill = 0;
  2619. vector<Skill*>::iterator itr;
  2620. for (itr = skills->begin(); itr != skills->end(); itr++) {
  2621. skill = *itr;
  2622. SkillChanged(skill, skill->previous_val, skill->current_val);
  2623. }
  2624. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  2625. if (app) QueuePacket(app);
  2626. safe_delete(skills);
  2627. }
  2628. }
  2629. if (disconnect_timer && disconnect_timer->Check()) {
  2630. safe_delete(disconnect_timer);
  2631. ret = false;
  2632. }
  2633. m_resurrect.writelock(__FUNCTION__, __LINE__);
  2634. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  2635. safe_delete(current_rez.expire_timer);
  2636. current_rez.expire_timer = 0;
  2637. current_rez.active = false;
  2638. current_rez.caster = 0;
  2639. current_rez.crit = false;
  2640. current_rez.crit_mod = 0;
  2641. current_rez.expire_timer = 0;
  2642. current_rez.heal_name = "";
  2643. current_rez.hp_perc = 0;
  2644. current_rez.mp_perc = 0;
  2645. current_rez.no_calcs = false;
  2646. current_rez.range = 0;
  2647. current_rez.should_delete = false;
  2648. current_rez.spell_name = "";
  2649. current_rez.spell_visual = 0;
  2650. current_rez.subspell = 0;
  2651. }
  2652. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  2653. // Quest timers
  2654. Quest* failed_step = 0;
  2655. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  2656. if (quest_timers.size() > 0) {
  2657. vector<int32>::iterator itr;
  2658. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  2659. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  2660. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  2661. Quest* quest = player_quests->at(*itr);
  2662. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  2663. failed_step = quest;
  2664. break;
  2665. }
  2666. }
  2667. else {
  2668. quest_timers.erase(itr);
  2669. break;
  2670. }
  2671. }
  2672. }
  2673. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  2674. if (failed_step)
  2675. failed_step->StepFailed(failed_step->GetTimerStep());
  2676. if (player->ControlFlagsChanged())
  2677. player->SendControlFlagUpdates(this);
  2678. if (!eqs || (eqs && !eqs->CheckActive()))
  2679. ret = false;
  2680. // redundant to client disconnect
  2681. // if(!ret)
  2682. // Save();
  2683. return ret;
  2684. }
  2685. ClientList::ClientList() {
  2686. MClients.SetName("ClientList::MClients");
  2687. }
  2688. ClientList::~ClientList() {
  2689. }
  2690. void ClientList::ReloadQuests() {
  2691. list<Client*>::iterator client_iter;
  2692. Client* client = 0;
  2693. MClients.readlock(__FUNCTION__, __LINE__);
  2694. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2695. client = *client_iter;
  2696. if (client)
  2697. client->ReloadQuests();
  2698. }
  2699. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2700. }
  2701. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  2702. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  2703. return;
  2704. list<Client*>::iterator client_iter;
  2705. Client* client = 0;
  2706. MClients.readlock(__FUNCTION__, __LINE__);
  2707. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2708. client = *client_iter;
  2709. if (client == owner || client->GetPlayer() == NULL)
  2710. continue;
  2711. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  2712. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  2713. }
  2714. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2715. }
  2716. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  2717. list<Client*>::iterator client_iter;
  2718. Client* client = 0;
  2719. MClients.readlock(__FUNCTION__, __LINE__);
  2720. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2721. client = *client_iter;
  2722. if (!client->GetPlayer())
  2723. continue;
  2724. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  2725. }
  2726. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2727. }
  2728. int32 ClientList::Count() {
  2729. return client_list.size();
  2730. }
  2731. void ClientList::Add(Client* client) {
  2732. MClients.writelock(__FUNCTION__, __LINE__);
  2733. client_list.push_back(client);
  2734. MClients.releasewritelock(__FUNCTION__, __LINE__);
  2735. }
  2736. Client* ClientList::FindByAccountID(int32 account_id) {
  2737. list<Client*>::iterator client_iter;
  2738. Client* client = 0;
  2739. Client* ret = 0;
  2740. MClients.readlock(__FUNCTION__, __LINE__);
  2741. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2742. client = *client_iter;
  2743. if (client->GetAccountID() == account_id) {
  2744. ret = client;
  2745. break;
  2746. }
  2747. }
  2748. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2749. return ret;
  2750. }
  2751. Client* ClientList::FindByName(char* charName) {
  2752. list<Client*>::iterator client_iter;
  2753. Client* client = 0;
  2754. Client* ret = 0;
  2755. MClients.readlock(__FUNCTION__, __LINE__);
  2756. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2757. client = *client_iter;
  2758. if (!client || !client->GetPlayer())
  2759. continue;
  2760. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  2761. ret = client;
  2762. break;
  2763. }
  2764. }
  2765. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2766. return ret;
  2767. }
  2768. Client* ClientList::Get(int32 ip, int16 port) {
  2769. list<Client*>::iterator client_iter;
  2770. Client* client = 0;
  2771. Client* ret = 0;
  2772. MClients.readlock(__FUNCTION__, __LINE__);
  2773. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2774. client = *client_iter;
  2775. if (client->GetIP() == ip && client->GetPort() == port) {
  2776. ret = client;
  2777. break;
  2778. }
  2779. }
  2780. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2781. return ret;
  2782. }
  2783. void ClientList::Process() {
  2784. list<Client*>::iterator client_iter;
  2785. list<Client*>::iterator erase_iter;
  2786. Client* client = 0;
  2787. MClients.readlock(__FUNCTION__, __LINE__);
  2788. erase_iter = client_list.end();
  2789. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2790. client = *client_iter;
  2791. // have a sanity check because the client list can sometimes obtain null client pointers
  2792. if (!client || client->remove_from_list || (!client->Process())) { // if we should be removing from list, don't process any further
  2793. erase_iter = client_iter;
  2794. break;
  2795. }
  2796. }
  2797. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2798. if (erase_iter != client_list.end()) {
  2799. client = *erase_iter;
  2800. MClients.writelock(__FUNCTION__, __LINE__);
  2801. client_list.erase(erase_iter);
  2802. MClients.releasewritelock(__FUNCTION__, __LINE__);
  2803. if (client && !client->remove_from_list) {
  2804. struct in_addr in;
  2805. in.s_addr = client->GetIP();
  2806. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  2807. safe_delete(client);
  2808. }
  2809. }
  2810. }
  2811. void ClientList::RemoveConnection(EQStream* eqs) {
  2812. Client* client;
  2813. if (eqs) {
  2814. list<Client*>::iterator client_iter;
  2815. MClients.readlock(__FUNCTION__, __LINE__);
  2816. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2817. client = *client_iter;
  2818. if (client->getConnection() == eqs)
  2819. client->Disconnect(false);
  2820. }
  2821. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2822. }
  2823. }
  2824. bool ClientList::ContainsStream(EQStream* eqs) {
  2825. if (!eqs) {
  2826. return false;
  2827. }
  2828. list<Client*>::iterator client_iter;
  2829. bool ret = false;
  2830. MClients.readlock(__FUNCTION__, __LINE__);
  2831. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2832. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  2833. ret = true;
  2834. break;
  2835. }
  2836. }
  2837. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2838. return ret;
  2839. }
  2840. void ClientList::Remove(Client* client, bool remove_data) {
  2841. client->remove_from_list = true;
  2842. if (remove_data) {
  2843. safe_delete(client);
  2844. }
  2845. }
  2846. void Client::SetCurrentZone(int32 id) {
  2847. if (current_zone) {
  2848. //current_zone->GetCombat()->RemoveHate(player);
  2849. current_zone->RemoveSpawn(player, false);
  2850. }
  2851. SetCurrentZone(zone_list.Get(id));
  2852. }
  2853. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  2854. if (current_zone) {
  2855. //current_zone->GetCombat()->RemoveHate(player);
  2856. current_zone->RemoveSpawn(player, false);
  2857. }
  2858. SetCurrentZone(zone_list.GetByInstanceID(id, zoneid));
  2859. }
  2860. ZoneServer* Client::GetCurrentZone() {
  2861. return current_zone;
  2862. }
  2863. int8 Client::GetMessageChannelColor(int8 channel_type) {
  2864. if (GetVersion() >= 973 && GetVersion() <= 1000) {
  2865. if (channel_type == CHANNEL_LOOT)
  2866. return CHANNEL_COLOR_NEW_LOOT;
  2867. }
  2868. else if (GetVersion() >= 973) {
  2869. if (channel_type == CHANNEL_LOOT)
  2870. return CHANNEL_COLOR_NEWEST_LOOT;
  2871. }
  2872. if (GetVersion() <= 283) {
  2873. if (channel_type <=12)
  2874. return channel_type;
  2875. switch (channel_type) {
  2876. case CHANNEL_GROUP_CHAT:
  2877. case CHANNEL_GROUP_SAY:
  2878. case CHANNEL_RAID_SAY:
  2879. case CHANNEL_GUILD_CHAT:
  2880. case CHANNEL_GUILD_SAY:
  2881. case CHANNEL_OFFICER_SAY:
  2882. case CHANNEL_GUILD_MOTD:
  2883. return channel_type - 1;
  2884. case CHANNEL_PRIVATE_CHAT:
  2885. case CHANNEL_NONPLAYER_TELL:
  2886. return channel_type - 5;
  2887. case CHANNEL_PRIVATE_TELL:
  2888. case CHANNEL_TELL_FROM_CS:
  2889. return channel_type - 6;
  2890. case CHANNEL_CHAT_CHANNEL_TEXT:
  2891. case CHANNEL_OUT_OF_CHARACTER:
  2892. case CHANNEL_AUCTION:
  2893. case CHANNEL_CUSTOM_CHANNEL:
  2894. case CHANNEL_CHARACTER_TEXT:
  2895. case CHANNEL_REWARD:
  2896. case CHANNEL_DEATH:
  2897. case CHANNEL_PET_CHAT:
  2898. case CHANNEL_SKILL:
  2899. return channel_type - 7;
  2900. case CHANNEL_SPELLS:
  2901. case CHANNEL_YOU_CAST:
  2902. case CHANNEL_YOU_FAIL:
  2903. return channel_type - 8;
  2904. case CHANNEL_FRIENDLY_CAST:
  2905. case CHANNEL_FRIENDLY_FAIL:
  2906. case CHANNEL_OTHER_CAST:
  2907. case CHANNEL_OTHER_FAIL:
  2908. case CHANNEL_HOSTILE_CAST:
  2909. case CHANNEL_HOSTILE_FAIL:
  2910. case CHANNEL_WORN_OFF:
  2911. case CHANNEL_SPELLS_OTHER:
  2912. return channel_type - 9;
  2913. case CHANNEL_COMBAT:
  2914. return channel_type - 15;
  2915. case CHANNEL_HEROIC_OPPORTUNITY:
  2916. case CHANNEL_NON_MELEE_DAMAGE:
  2917. case CHANNEL_DAMAGE_SHIELD:
  2918. return channel_type - 16;
  2919. case CHANNEL_MELEE_COMBAT:
  2920. case CHANNEL_WARNINGS:
  2921. case CHANNEL_YOU_HIT:
  2922. case CHANNEL_YOU_MISS:
  2923. case CHANNEL_ATTACKER_HITS:
  2924. case CHANNEL_ATTACKER_MISSES:
  2925. return channel_type - 18;
  2926. case CHANNEL_OTHER_HIT:
  2927. case CHANNEL_OTHER_MISSES:
  2928. case CHANNEL_CRITICAL_HIT:
  2929. return channel_type - 22;
  2930. case CHANNEL_OTHER:
  2931. case CHANNEL_MONEY_SPLIT:
  2932. case CHANNEL_LOOT:
  2933. return channel_type - 30;
  2934. case CHANNEL_COMMAND_TEXT:
  2935. case CHANNEL_BROADCAST:
  2936. case CHANNEL_WHO:
  2937. case CHANNEL_COMMANDS:
  2938. case CHANNEL_MERCHANT:
  2939. case CHANNEL_MERCHANT_BUY_SELL:
  2940. case CHANNEL_CONSIDER_MESSAGE:
  2941. case CHANNEL_CON_MINUS_2:
  2942. case CHANNEL_CON_MINUS_1:
  2943. case CHANNEL_CON_0:
  2944. case CHANNEL_CON_1:
  2945. case CHANNEL_CON_2:
  2946. return channel_type - 31;
  2947. default: {
  2948. return CHANNEL_DEFAULT;
  2949. }
  2950. }
  2951. }
  2952. else if (GetVersion() <= 546) {
  2953. if (channel_type < 20)
  2954. return channel_type;
  2955. switch (channel_type) {
  2956. case CHANNEL_GUILD_MOTD:
  2957. case CHANNEL_GUILD_MEMBER_ONLINE:
  2958. case CHANNEL_GUILD_EVENT:
  2959. return channel_type + 1;
  2960. case CHANNEL_PRIVATE_CHAT:
  2961. case CHANNEL_NONPLAYER_TELL:
  2962. return channel_type - 1;
  2963. case CHANNEL_PRIVATE_TELL:
  2964. case CHANNEL_TELL_FROM_CS:
  2965. case CHANNEL_ARENA:
  2966. case CHANNEL_CHAT_CHANNEL_TEXT:
  2967. case CHANNEL_OUT_OF_CHARACTER:
  2968. case CHANNEL_AUCTION:
  2969. case CHANNEL_CUSTOM_CHANNEL:
  2970. case CHANNEL_CHARACTER_TEXT:
  2971. case CHANNEL_REWARD:
  2972. case CHANNEL_DEATH:
  2973. case CHANNEL_PET_CHAT:
  2974. case CHANNEL_SKILL:
  2975. case CHANNEL_FACTION:
  2976. case CHANNEL_SPELLS:
  2977. case CHANNEL_YOU_CAST:
  2978. case CHANNEL_YOU_FAIL:
  2979. return channel_type - 2;
  2980. case CHANNEL_FRIENDLY_CAST:
  2981. case CHANNEL_FRIENDLY_FAIL:
  2982. case CHANNEL_OTHER_CAST:
  2983. case CHANNEL_OTHER_FAIL:
  2984. case CHANNEL_HOSTILE_CAST:
  2985. case CHANNEL_HOSTILE_FAIL:
  2986. case CHANNEL_WORN_OFF:
  2987. case CHANNEL_SPELLS_OTHER:
  2988. case CHANNEL_HEAL_SPELLS:
  2989. case CHANNEL_HEALS:
  2990. case CHANNEL_FRIENDLY_HEALS:
  2991. case CHANNEL_OTHER_HEALS:
  2992. case CHANNEL_HOSTILE_HEALS:
  2993. return channel_type - 3;
  2994. case CHANNEL_COMBAT:
  2995. case CHANNEL_GENERAL_COMBAT:
  2996. case CHANNEL_HEROIC_OPPORTUNITY:
  2997. case CHANNEL_NON_MELEE_DAMAGE:
  2998. case CHANNEL_DAMAGE_SHIELD:
  2999. case CHANNEL_WARD:
  3000. return channel_type - 4;
  3001. case CHANNEL_MELEE_COMBAT:
  3002. case CHANNEL_WARNINGS:
  3003. case CHANNEL_YOU_HIT:
  3004. case CHANNEL_YOU_MISS:
  3005. case CHANNEL_ATTACKER_HITS:
  3006. case CHANNEL_ATTACKER_MISSES:
  3007. case CHANNEL_YOUR_PET_HITS:
  3008. case CHANNEL_YOUR_PET_MISSES:
  3009. case CHANNEL_ATTACKER_HITS_PET:
  3010. case CHANNEL_ATTACKER_MISSES_PET:
  3011. case CHANNEL_OTHER_HIT:
  3012. case CHANNEL_OTHER_MISSES:
  3013. return channel_type - 5;
  3014. case CHANNEL_OTHER:
  3015. case CHANNEL_MONEY_SPLIT:
  3016. case CHANNEL_LOOT:
  3017. return channel_type - 14;
  3018. case CHANNEL_COMMAND_TEXT:
  3019. case CHANNEL_BROADCAST:
  3020. case CHANNEL_WHO:
  3021. case CHANNEL_COMMANDS:
  3022. case CHANNEL_MERCHANT:
  3023. case CHANNEL_MERCHANT_BUY_SELL:
  3024. case CHANNEL_CONSIDER_MESSAGE:
  3025. case CHANNEL_CON_MINUS_2:
  3026. case CHANNEL_CON_MINUS_1:
  3027. case CHANNEL_CON_0:
  3028. case CHANNEL_CON_1:
  3029. case CHANNEL_CON_2:
  3030. case CHANNEL_TRADESKILLS:
  3031. case CHANNEL_HARVESTING:
  3032. case CHANNEL_HARVESTING_WARNINGS:
  3033. return channel_type - 15;
  3034. default: {
  3035. return CHANNEL_DEFAULT;
  3036. }
  3037. }
  3038. }
  3039. else {
  3040. switch (channel_type) {
  3041. default: {
  3042. return channel_type;
  3043. }
  3044. }
  3045. }
  3046. return channel_type;
  3047. }
  3048. void Client::HandleTellMessage(Client* from, const char* message) {
  3049. if (!from || GetPlayer()->IsIgnored(from->GetPlayer()->GetName()))
  3050. return;
  3051. PacketStruct* packet = configReader.getStruct("WS_HearChat", GetVersion());
  3052. if (packet) {
  3053. packet->setDataByName("from", from->GetPlayer()->GetName());
  3054. packet->setDataByName("to", GetPlayer()->GetName());
  3055. packet->setDataByName("channel", GetMessageChannelColor(CHANNEL_PRIVATE_TELL));
  3056. packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
  3057. packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
  3058. packet->setDataByName("unknown2", 1, 1);
  3059. packet->setDataByName("show_bubble", 1);
  3060. packet->setDataByName("understood", 1);
  3061. packet->setDataByName("time", 2);
  3062. packet->setMediumStringByName("message", message);
  3063. EQ2Packet* outpacket = packet->serialize();
  3064. QueuePacket(outpacket);
  3065. safe_delete(packet);
  3066. }
  3067. }
  3068. void Client::SimpleMessage(int8 color, const char* message) {
  3069. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  3070. if (command_packet) {
  3071. command_packet->setDataByName("color", GetMessageChannelColor(color));//convert this to the correct client type (different clients have different chat numbers)
  3072. command_packet->setMediumStringByName("text", message);
  3073. command_packet->setDataByName("unknown02", 0x00ff);
  3074. EQ2Packet* outapp = command_packet->serialize();
  3075. QueuePacket(outapp);
  3076. safe_delete(command_packet);
  3077. }
  3078. }
  3079. void Client::SendSpellUpdate(Spell* spell, bool add_silently, bool add_to_hotbar) {
  3080. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  3081. if (packet) {
  3082. int8 xxx = spell->GetSpellData()->is_aa;
  3083. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  3084. packet->setDataByName("spell_id", spell->GetSpellID());
  3085. packet->setDataByName("unique_id", spell->GetSpellData()->spell_name_crc);
  3086. packet->setDataByName("spell_name", spell->GetName());
  3087. if(add_silently)
  3088. packet->setDataByName("add_silently", 1);
  3089. if(add_to_hotbar)
  3090. packet->setDataByName("add_to_hotbar", 1);
  3091. packet->setDataByName("unknown", xxx);
  3092. packet->setDataByName("display_spell_tier", 1);
  3093. packet->setDataByName("unknown3", 1);
  3094. packet->setDataByName("tier", spell->GetSpellTier());
  3095. packet->setDataByName("icon", spell->GetSpellIcon());
  3096. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  3097. packet->setDataByName("unknown5", 0xFFFFFFFF);
  3098. //packet->PrintPacket();
  3099. EQ2Packet* outapp = packet->serialize();
  3100. //DumpPacket(outapp);
  3101. QueuePacket(outapp);
  3102. safe_delete(packet);
  3103. }
  3104. }
  3105. void Client::Message(int8 type, const char* message, ...) {
  3106. va_list argptr;
  3107. char buffer[4096];
  3108. va_start(argptr, message);
  3109. vsnprintf(buffer, sizeof(buffer), message, argptr);
  3110. va_end(argptr);
  3111. SimpleMessage(type, buffer);
  3112. }
  3113. void Client::Disconnect(bool send_disconnect)
  3114. {
  3115. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  3116. SetConnected(false);
  3117. if (send_disconnect && getConnection())
  3118. getConnection()->SendDisconnect(true);
  3119. this->Save();
  3120. this->GetPlayer()->WritePlayerStatistics();
  3121. eqs = 0;
  3122. }
  3123. bool Client::Summon(const char* search_name) {
  3124. Spawn* target = 0;
  3125. if (search_name || GetPlayer()->GetTarget()) {
  3126. Client* search_client = 0;
  3127. if (search_name) {
  3128. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3129. if (target && target->IsPlayer())
  3130. search_client = GetCurrentZone()->GetClientBySpawn(target);
  3131. if (!target) {
  3132. search_client = zone_list.GetClientByCharName(string(search_name));
  3133. if (search_client)
  3134. target = search_client->GetPlayer();
  3135. }
  3136. }
  3137. else
  3138. target = GetPlayer()->GetTarget();
  3139. if (target && target != GetPlayer()) {
  3140. target->SetX(GetPlayer()->GetX());
  3141. target->SetY(GetPlayer()->GetY());
  3142. target->SetZ(GetPlayer()->GetZ());
  3143. target->SetHeading(GetPlayer()->GetHeading());
  3144. if (!target->IsPlayer()) {
  3145. target->SetSpawnOrigX(target->GetX());
  3146. target->SetSpawnOrigY(target->GetY());
  3147. target->SetSpawnOrigZ(target->GetZ());
  3148. target->SetSpawnOrigHeading(target->GetHeading());
  3149. }
  3150. target->SetLocation(GetPlayer()->GetLocation());
  3151. }
  3152. else if (target)
  3153. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  3154. if (search_client && search_client != this) {
  3155. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  3156. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  3157. if (search_client->GetCurrentZone() != GetCurrentZone())
  3158. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  3159. else {
  3160. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  3161. if (app)
  3162. search_client->QueuePacket(app);
  3163. }
  3164. }
  3165. }
  3166. if (!target)
  3167. return false;
  3168. else
  3169. return true;
  3170. }
  3171. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  3172. ZoneServer* instance_zone = NULL;
  3173. int8 instanceType = 0;
  3174. // determine if this is a group instanced zone that already exists
  3175. instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
  3176. if (instance_zone != NULL)
  3177. Zone(instance_zone->GetInstanceID(), zone_coords_valid, true);
  3178. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  3179. {
  3180. // best to check if we already have our own instance!
  3181. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3182. if (data) {
  3183. // If lockout instances check to see if we are locked out
  3184. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  3185. int32 time = 0;
  3186. // Check success timer
  3187. if (data->last_success_timestamp > 0) {
  3188. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  3189. // Timer has not expired yet can't re enter
  3190. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3191. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  3192. }
  3193. }
  3194. // Check failure timer
  3195. if (data->last_failure_timestamp > 0) {
  3196. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  3197. // Timer has not expired yet
  3198. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3199. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  3200. }
  3201. }
  3202. // Time > 0 then we are locked out, make the message and send it and return true
  3203. if (time > 0) {
  3204. string time_msg = "";
  3205. int16 hour;
  3206. int8 min;
  3207. int8 sec;
  3208. hour = time / 3600;
  3209. time = time % 3600;
  3210. min = time / 60;
  3211. time = time % 60;
  3212. sec = time;
  3213. if (hour > 0) {
  3214. char temp[10];
  3215. sprintf(temp, " %i", hour);
  3216. time_msg.append(temp);
  3217. time_msg.append(" hour");
  3218. time_msg.append((hour > 1) ? "s" : "");
  3219. }
  3220. if (min > 0) {
  3221. char temp[5];
  3222. sprintf(temp, " %i", min);
  3223. time_msg.append(temp);
  3224. time_msg.append(" minute");
  3225. time_msg.append((min > 1) ? "s" : "");
  3226. }
  3227. // Only add seconds if minutes and hours are 0
  3228. if (hour == 0 && min == 0 && sec > 0) {
  3229. char temp[5];
  3230. sprintf(temp, " %i", sec);
  3231. time_msg.append(temp);
  3232. time_msg.append(" second");
  3233. time_msg.append((sec > 1) ? "s" : "");
  3234. }
  3235. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  3236. return true;
  3237. }
  3238. }
  3239. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  3240. instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID);
  3241. // 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
  3242. if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
  3243. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  3244. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  3245. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  3246. }
  3247. else
  3248. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
  3249. data->instance_id = instance_zone->GetInstanceID();
  3250. }
  3251. }
  3252. else {
  3253. switch (instanceType)
  3254. {
  3255. case SOLO_LOCKOUT_INSTANCE:
  3256. case GROUP_LOCKOUT_INSTANCE:
  3257. case RAID_LOCKOUT_INSTANCE:
  3258. {
  3259. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3260. if (instance_zone) {
  3261. // 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
  3262. // so delete `instances` entry for the zone when it shuts down.
  3263. 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());
  3264. if (db_id > 0)
  3265. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  3266. }
  3267. break;
  3268. }
  3269. case SOLO_PERSIST_INSTANCE:
  3270. case GROUP_PERSIST_INSTANCE:
  3271. case RAID_PERSIST_INSTANCE:
  3272. {
  3273. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3274. if (instance_zone) {
  3275. 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());
  3276. if (db_id > 0)
  3277. 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()));
  3278. }
  3279. break;
  3280. }
  3281. case PUBLIC_INSTANCE:
  3282. case TRADESKILL_INSTANCE:
  3283. {
  3284. // if its public/tradeskill, look for a public already setup
  3285. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  3286. if (instance_zone) {
  3287. // Check the current population against the max population, if greater or equal start a new version
  3288. if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
  3289. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3290. }
  3291. else
  3292. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3293. break;
  3294. }
  3295. case PERSONAL_HOUSE_INSTANCE:
  3296. case GUILD_HOUSE_INSTANCE:
  3297. {
  3298. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  3299. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  3300. // with the OP_EnterHouseMsg opcode
  3301. break;
  3302. }
  3303. case QUEST_INSTANCE:
  3304. {
  3305. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3306. break;
  3307. /*
  3308. 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`;
  3309. */
  3310. }
  3311. default:
  3312. {
  3313. // NONE
  3314. }
  3315. }
  3316. }
  3317. if (instance_zone != NULL)
  3318. Zone(instance_zone, zone_coords_valid);
  3319. }
  3320. if (instance_zone != NULL)
  3321. return true;
  3322. else
  3323. return false;
  3324. }
  3325. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  3326. Spawn* target = 0;
  3327. if (search_name || GetPlayer()->GetTarget()) {
  3328. Client* search_client = 0;
  3329. if (search_name) {
  3330. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3331. if (!target) {
  3332. search_client = zone_list.GetClientByCharName(search_name);
  3333. if (search_client)
  3334. target = search_client->GetPlayer();
  3335. }
  3336. if (target)
  3337. GetPlayer()->SetTarget(target);
  3338. }
  3339. else
  3340. target = GetPlayer()->GetTarget();
  3341. if (target && target != GetPlayer()) {
  3342. GetPlayer()->SetX(target->GetX());
  3343. GetPlayer()->SetY(target->GetY());
  3344. GetPlayer()->SetZ(target->GetZ());
  3345. GetPlayer()->SetHeading(target->GetHeading());
  3346. GetPlayer()->SetLocation(target->GetLocation());
  3347. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  3348. }
  3349. else if (target)
  3350. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  3351. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  3352. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  3353. else if (target) {
  3354. EQ2Packet* app = GetPlayer()->Move(target->GetX(), target->GetY(), target->GetZ(), GetVersion());
  3355. if (app)
  3356. QueuePacket(app);
  3357. }
  3358. }
  3359. if (!target)
  3360. return false;
  3361. else
  3362. return true;
  3363. }
  3364. bool Client::CheckZoneAccess(const char* zoneName) {
  3365. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  3366. ZoneServer* zone = zone_list.Get(zoneName, false);
  3367. // JA: implemented /zone lock|unlock commands (2012.07.28)
  3368. if (zone && zone->GetZoneLockState())
  3369. {
  3370. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
  3371. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  3372. return false;
  3373. }
  3374. sint16 zoneMinStatus = 0;
  3375. int16 zoneMinLevel = 0;
  3376. int16 zoneMaxLevel = 0;
  3377. int16 zoneMinVersion = 0;
  3378. if (!zone)
  3379. {
  3380. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  3381. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  3382. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  3383. return true;
  3384. }
  3385. }
  3386. else
  3387. {
  3388. zoneMinStatus = zone->GetMinimumStatus();
  3389. zoneMinLevel = zone->GetMinimumLevel();
  3390. zoneMaxLevel = zone->GetMaximumLevel();
  3391. zoneMinVersion = zone->GetMinimumVersion();
  3392. }
  3393. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  3394. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  3395. sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  3396. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  3397. {
  3398. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  3399. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  3400. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  3401. return false;
  3402. }
  3403. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  3404. {
  3405. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3406. {
  3407. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3408. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  3409. return false;
  3410. }
  3411. }
  3412. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  3413. {
  3414. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3415. {
  3416. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3417. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  3418. return false;
  3419. }
  3420. }
  3421. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  3422. {
  3423. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  3424. sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  3425. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  3426. {
  3427. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  3428. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  3429. return false;
  3430. }
  3431. }
  3432. return true;
  3433. }
  3434. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID) {
  3435. Zone(zone_list.GetByInstanceID(instanceid), set_coords);
  3436. }
  3437. void Client::Zone(ZoneServer* new_zone, bool set_coords) {
  3438. if (!new_zone) {
  3439. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
  3440. return;
  3441. }
  3442. client_zoning = true;
  3443. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  3444. player->SetResurrecting(true);
  3445. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
  3446. //GetCurrentZone()->GetCombat()->RemoveHate(player);
  3447. // Remove players pet from zone if there is one
  3448. player->DismissPet((NPC*)player->GetPet());
  3449. player->DismissPet((NPC*)player->GetCharmedPet());
  3450. player->DismissPet((NPC*)player->GetDeityPet());
  3451. player->DismissPet((NPC*)player->GetCosmeticPet());
  3452. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  3453. GetCurrentZone()->RemoveSpawn(player, false);
  3454. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
  3455. SetCurrentZone(new_zone);
  3456. if (player->GetGroupMemberInfo())
  3457. {
  3458. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  3459. player->UpdateGroupMemberInfo();
  3460. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  3461. }
  3462. // block out the member info for the group
  3463. TempRemoveGroup();
  3464. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  3465. if (set_coords)
  3466. {
  3467. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  3468. __FUNCTION__,
  3469. GetCurrentZone()->GetSafeX(),
  3470. GetCurrentZone()->GetSafeY(),
  3471. GetCurrentZone()->GetSafeZ(),
  3472. GetCurrentZone()->GetSafeHeading(),
  3473. new_zone->GetZoneName()
  3474. );
  3475. player->SetX(GetCurrentZone()->GetSafeX());
  3476. player->SetY(GetCurrentZone()->GetSafeY());
  3477. player->SetZ(GetCurrentZone()->GetSafeZ());
  3478. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  3479. }
  3480. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
  3481. Save();
  3482. char* new_zone_ip = 0;
  3483. struct in_addr in;
  3484. in.s_addr = this->GetIP();
  3485. if (strncmp(inet_ntoa(in), "192.168", 7) == 0 && strlen(net.GetInternalWorldAddress()) > 0)
  3486. new_zone_ip = net.GetInternalWorldAddress();
  3487. else
  3488. new_zone_ip = net.GetWorldAddress();
  3489. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  3490. int32 key = Timer::GetUnixTimeStamp();
  3491. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
  3492. ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
  3493. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  3494. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  3495. if (version > 283) {
  3496. PacketStruct* packet = configReader.getStruct("WS_CancelMoveObjectMode", version);
  3497. if (packet)
  3498. {
  3499. QueuePacket(packet->serialize());
  3500. safe_delete(packet);
  3501. }
  3502. }
  3503. }
  3504. void Client::Zone(const char* new_zone, bool set_coords)
  3505. {
  3506. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  3507. Zone(zone_list.Get(new_zone), set_coords);
  3508. }
  3509. float Client::DistanceFrom(Client* client) {
  3510. float ret = 0;
  3511. if (client && client != this) {
  3512. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  3513. ret = sqrt(ret);
  3514. }
  3515. return ret;
  3516. }
  3517. void Client::DetermineCharacterUpdates() {
  3518. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  3519. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  3520. cdu->account_id = GetAccountID();
  3521. cdu->char_id = GetCharacterID();
  3522. int32 timestamp = Timer::GetUnixTimeStamp();
  3523. int8 flag = GetTimeStampFlag();
  3524. if (flag & LEVEL_UPDATE_FLAG)
  3525. {
  3526. cdu->update_field = LEVEL_UPDATE_FLAG;
  3527. cdu->update_data = player->GetLevel();
  3528. loginserver.SendPacket(outpack);
  3529. }
  3530. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  3531. if (flag & CLASS_UPDATE_FLAG)
  3532. {
  3533. cdu->update_field = CLASS_UPDATE_FLAG;
  3534. cdu->update_data = player->GetAdventureClass();
  3535. loginserver.SendPacket(outpack);
  3536. }
  3537. if (flag & GENDER_UPDATE_FLAG)
  3538. {
  3539. cdu->update_field = GENDER_UPDATE_FLAG;
  3540. cdu->update_data = player->GetGender();
  3541. loginserver.SendPacket(outpack);
  3542. }
  3543. if (flag & DELETE_UPDATE_FLAG) {
  3544. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3545. }
  3546. safe_delete(outpack); // Zone, armor and name use a different structure
  3547. if (flag & RACE_UPDATE_FLAG)
  3548. {
  3549. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  3550. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  3551. ru->account_id = GetAccountID();
  3552. ru->char_id = GetCharacterID();
  3553. ru->race = player->GetRace();
  3554. ru->model_type = player->GetModelType();
  3555. loginserver.SendPacket(outpack);
  3556. safe_delete(outpack);
  3557. }
  3558. if (flag & ZONE_UPDATE_FLAG) {
  3559. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  3560. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  3561. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  3562. czu->account_id = GetAccountID();
  3563. czu->char_id = GetCharacterID();
  3564. czu->zone_id = GetCurrentZone()->GetZoneID();
  3565. const char* zone_file = GetCurrentZone()->GetZoneFile();
  3566. czu->zone_length = strlen(zone_file);
  3567. if (czu->zone_length > 64)
  3568. czu->zone_length = 64;
  3569. strncpy(czu->new_zone, zone_file, czu->zone_length);
  3570. loginserver.SendPacket(outpack);
  3571. safe_delete(outpack);
  3572. }
  3573. if (flag & ARMOR_UPDATE_FLAG) {
  3574. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3575. }
  3576. if (flag & NAME_UPDATE_FLAG) {
  3577. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3578. }
  3579. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  3580. }
  3581. void Client::Save() {
  3582. if (GetCharacterID() == 0)
  3583. return;
  3584. if (current_zone) {
  3585. DetermineCharacterUpdates();
  3586. UpdateCharacterInstances();
  3587. database.Save(this);
  3588. if (GetPlayer()->UpdateQuickbarNeeded()) {
  3589. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  3590. GetPlayer()->ResetQuickbarNeeded();
  3591. }
  3592. database.SaveItems(this);
  3593. database.SaveBuyBacks(this);
  3594. GetPlayer()->SaveHistory();
  3595. GetPlayer()->SaveLUAHistory();
  3596. }
  3597. }
  3598. void Client::UpdateCharacterInstances() {
  3599. if (GetPlayer() != NULL)
  3600. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  3601. /*if ( GetPlayer() != NULL )
  3602. {
  3603. // determine the last timestamp then get a new one, determine the difference in the timestamp
  3604. // to use for applying the update to each instances timer
  3605. int32 lastSaveTS = GetLastSavedTimeStamp();
  3606. int32 newSaveTS = Timer::GetUnixTimeStamp();
  3607. int32 diffTS = newSaveTS - lastSaveTS;
  3608. // update instance timers
  3609. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  3610. // update with the new timestamp and save the db
  3611. this->SetLastSavedTimeStamp(newSaveTS);
  3612. }*/
  3613. }
  3614. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  3615. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  3616. if (packet) {
  3617. packet->LoadPacketData(app->pBuffer, app->size);
  3618. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  3619. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  3620. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  3621. vector<EntityCommand*> commands;
  3622. vector<EntityCommand*> delete_commands;
  3623. if (out && spawn) {
  3624. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  3625. {
  3626. // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
  3627. if (!spawn->primary_command_list[i]->default_allow_list)
  3628. {
  3629. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3630. if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
  3631. continue;
  3632. }
  3633. else
  3634. {
  3635. // default is allow list, only deny if added to the list as deny (false itr second)
  3636. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3637. if (itr != spawn->primary_command_list[i]->allow_or_deny.end() && !itr->second)
  3638. continue;
  3639. }
  3640. commands.push_back(spawn->primary_command_list[i]);
  3641. }
  3642. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  3643. commands.push_back(spawn->secondary_command_list[i]);
  3644. if (spawn->IsPlayer()) {
  3645. if (player->IsFriend(spawn->GetName()))
  3646. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  3647. else
  3648. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  3649. if (player->IsIgnored(spawn->GetName()))
  3650. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  3651. else
  3652. {
  3653. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  3654. delete_commands.push_back(player->CreateEntityCommand("Trade", 10, "start_trade", "", 0, 0));
  3655. }
  3656. if (((Player*)spawn)->GetGroupMemberInfo()) {
  3657. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  3658. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  3659. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  3660. }
  3661. }
  3662. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  3663. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  3664. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  3665. }
  3666. out->setDataByName("spawn_id", spawn_id);
  3667. out->setArrayLengthByName("num_verbs", commands.size());
  3668. for (int32 i = 0; i < commands.size(); i++) {
  3669. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  3670. out->setArrayDataByName("distance", commands[i]->distance, i);
  3671. if (commands[i]->error_text.length() == 0)
  3672. out->setArrayAddToPacketByName("error", false, i);
  3673. else {
  3674. out->setArrayDataByName("display_error", 1, i);
  3675. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  3676. }
  3677. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  3678. }
  3679. EQ2Packet* outapp = out->serialize();
  3680. //DumpPacket(outapp);
  3681. QueuePacket(outapp);
  3682. safe_delete(out);
  3683. for (int32 i = 0; i < delete_commands.size(); i++) {
  3684. safe_delete(delete_commands[i]);
  3685. }
  3686. }
  3687. safe_delete(packet);
  3688. }
  3689. }
  3690. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  3691. if (previous_value != new_value) {
  3692. Message(CHANNEL_SKILL, "You get %s at %s (%i/%i).", new_value > previous_value ? "better" : "worse", skill->name.data.c_str(), new_value, skill->max_val);
  3693. char tmp[200] = { 0 };
  3694. 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);
  3695. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75f, 0xFF, 0xFF, 0xFF);
  3696. }
  3697. }
  3698. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  3699. {
  3700. /* JA notes on the unknown:
  3701. 2 = ding glimmer
  3702. 16 = Achievement Unlocked
  3703. 6 no longer does anything
  3704. */
  3705. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  3706. if (packet) {
  3707. packet->setDataByName("unknown", unknown);
  3708. packet->setMediumStringByName("text", text);
  3709. if (type && strlen(type) > 0)
  3710. packet->setMediumStringByName("message_type", type);
  3711. packet->setDataByName("size", size);
  3712. packet->setDataByName("red", red);
  3713. packet->setDataByName("green", green);
  3714. packet->setDataByName("blue", blue);
  3715. QueuePacket(packet->serialize());
  3716. safe_delete(packet);
  3717. }
  3718. }
  3719. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  3720. if (new_level < 1) {
  3721. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  3722. return;
  3723. }
  3724. if (player->GetLevel() != new_level) {
  3725. player->SetLevel(new_level);
  3726. if (player->GetGroupMemberInfo()) {
  3727. player->UpdateGroupMemberInfo();
  3728. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  3729. }
  3730. }
  3731. if (new_level > old_level) {
  3732. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  3733. }
  3734. if (player->GetPet()) {
  3735. NPC* pet = (NPC*)player->GetPet();
  3736. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  3737. pet->SetLevel(new_level);
  3738. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3739. if (command_packet) {
  3740. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  3741. command_packet->setDataByName("anim_type", 1753);
  3742. QueuePacket(command_packet->serialize());
  3743. safe_delete(command_packet);
  3744. }
  3745. }
  3746. }
  3747. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  3748. if (level_update) {
  3749. level_update->setDataByName("old_level", old_level);
  3750. level_update->setDataByName("new_level", new_level);
  3751. QueuePacket(level_update->serialize());
  3752. safe_delete(level_update);
  3753. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  3754. GetCurrentZone()->SendCastSpellPacket(322, player, player); //send level up spell effect
  3755. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  3756. }
  3757. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3758. if (command_packet) {
  3759. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  3760. command_packet->setDataByName("anim_type", 1753);
  3761. QueuePacket(command_packet->serialize());
  3762. safe_delete(command_packet);
  3763. }
  3764. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  3765. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  3766. SendNewSpells(player->GetAdventureClass());
  3767. SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  3768. SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  3769. GetPlayer()->ChangePrimaryWeapon();
  3770. GetPlayer()->ChangeSecondaryWeapon();
  3771. GetPlayer()->ChangeRangedWeapon();
  3772. GetPlayer()->GetInfoStruct()->level = new_level;
  3773. // GetPlayer()->SetLevel(new_level);
  3774. 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__);
  3775. GetPlayer()->SetTotalHPBase(new_level * new_level * 2 + 40);
  3776. GetPlayer()->SetTotalPowerBase((sint32)(new_level * new_level * 2.1 + 45));
  3777. GetPlayer()->CalculateBonuses();
  3778. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  3779. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  3780. InfoStruct* info = player->GetInfoStruct();
  3781. info->agi_base = new_level * 2 + 15;
  3782. info->intel_base = new_level * 2 + 15;
  3783. info->wis_base = new_level * 2 + 15;
  3784. info->str_base = new_level * 2 + 15;
  3785. info->sta_base = new_level * 2 + 15;
  3786. info->cold_base = (int16)(new_level * 1.5 + 10);
  3787. info->heat_base = (int16)(new_level * 1.5 + 10);
  3788. info->disease_base = (int16)(new_level * 1.5 + 10);
  3789. info->mental_base = (int16)(new_level * 1.5 + 10);
  3790. info->magic_base = (int16)(new_level * 1.5 + 10);
  3791. info->divine_base = (int16)(new_level * 1.5 + 10);
  3792. info->poison_base = (int16)(new_level * 1.5 + 10);
  3793. GetPlayer()->SetHPRegen((int)(new_level * .75) + (int)(new_level / 10) + 3);
  3794. GetPlayer()->SetPowerRegen(new_level + (int)(new_level / 10) + 4);
  3795. GetPlayer()->GetInfoStruct()->poison_base = (int16)(new_level * 1.5 + 10);
  3796. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  3797. GetPlayer()->SetCharSheetChanged(true);
  3798. Message(CHANNEL_REWARD, "You are now level %i!", new_level);
  3799. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  3800. int16 new_skill_cap = 5 * new_level;
  3801. PlayerSkillList* player_skills = player->GetSkills();
  3802. player_skills->SetSkillCapsByType(SKILL_TYPE_ARMOR, new_skill_cap);
  3803. player_skills->SetSkillCapsByType(SKILL_TYPE_SHIELD, new_skill_cap);
  3804. //SKILL_TYPE_ARMOR/SKILL_TYPE_SHIELD always has the same current / max values
  3805. player_skills->SetSkillValuesByType(SKILL_TYPE_ARMOR, new_skill_cap, false);
  3806. player_skills->SetSkillValuesByType(SKILL_TYPE_SHIELD, new_skill_cap, false);
  3807. player_skills->SetSkillCapsByType(SKILL_TYPE_CLASS, new_skill_cap);
  3808. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPON, new_skill_cap);
  3809. //SKILL_TYPE_CLASS/SKILL_TYPE_WEAPON always has the same current/max values
  3810. player_skills->SetSkillValuesByType(SKILL_TYPE_CLASS, new_skill_cap, false);
  3811. player_skills->SetSkillValuesByType(SKILL_TYPE_WEAPON, new_skill_cap, false);
  3812. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  3813. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  3814. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  3815. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  3816. if (new_level > player->GetTSLevel())
  3817. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  3818. //SKILL_ID_DUALWIELD, SKILL_ID_FISTS, SKILL_ID_DESTROYING, and SKILL_ID_MAGIC_AFFINITY always have the current_val equal to max_val
  3819. if (player_skills->HasSkill(SKILL_ID_DUALWIELD))
  3820. player_skills->SetSkill(SKILL_ID_DUALWIELD, new_skill_cap);
  3821. if (player_skills->HasSkill(SKILL_ID_FISTS))
  3822. player_skills->SetSkill(SKILL_ID_FISTS, new_skill_cap);
  3823. if (player_skills->HasSkill(SKILL_ID_DESTROYING))
  3824. player_skills->SetSkill(SKILL_ID_DESTROYING, new_skill_cap);
  3825. if (player_skills->HasSkill(SKILL_ID_MAGIC_AFFINITY))
  3826. player_skills->SetSkill(SKILL_ID_MAGIC_AFFINITY, new_skill_cap);
  3827. Guild* guild = GetPlayer()->GetGuild();
  3828. if (guild) {
  3829. int8 event_type = 0;
  3830. if (new_level < 10)
  3831. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  3832. else if (new_level == 10)
  3833. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  3834. else if (new_level >= 11 && new_level < 20)
  3835. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  3836. else if (new_level == 20)
  3837. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  3838. else if (new_level >= 21 && new_level < 30)
  3839. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  3840. else if (new_level == 30)
  3841. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  3842. else if (new_level >= 31 && new_level < 40)
  3843. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  3844. else if (new_level == 40)
  3845. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  3846. else if (new_level >= 41 && new_level < 50)
  3847. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  3848. else if (new_level == 50)
  3849. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  3850. else if (new_level >= 51 && new_level < 60)
  3851. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  3852. else if (new_level == 60)
  3853. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  3854. else if (new_level >= 61 && new_level < 70)
  3855. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  3856. else if (new_level == 70)
  3857. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  3858. else if (new_level >= 71 && new_level < 80)
  3859. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  3860. else if (new_level == 80)
  3861. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  3862. 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());
  3863. 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());
  3864. guild->UpdateGuildMemberInfo(GetPlayer());
  3865. guild->SendGuildMember(GetPlayer());
  3866. guild->SendGuildMemberList();
  3867. }
  3868. // Need to send the trait list every time the players level changes
  3869. // Also need to force the char sheet update or else there can be a large delay from when you level
  3870. // to when you are actually able to select traits.
  3871. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  3872. QueuePacket(master_trait_list.GetTraitListPacket(this));
  3873. if (version > 546)
  3874. master_aa_list.DisplayAA(this, 0, 0);
  3875. if (GetPlayer()->SpawnedBots.size() > 0) {
  3876. map<int32, int32>::iterator itr;
  3877. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  3878. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  3879. if (bot && bot->IsBot())
  3880. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  3881. }
  3882. }
  3883. }
  3884. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  3885. if (new_level < 1) {
  3886. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  3887. return;
  3888. }
  3889. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  3890. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  3891. return;
  3892. }
  3893. if (new_level > old_level)
  3894. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  3895. if (player->GetTSLevel() != new_level) {
  3896. player->SetTSLevel(new_level);
  3897. if (player->GetGroupMemberInfo()) {
  3898. player->UpdateGroupMemberInfo();
  3899. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  3900. }
  3901. }
  3902. // Only tradeskill skills should increace, and then only those related to your class
  3903. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  3904. if (level_update) {
  3905. level_update->setDataByName("old_level", old_level);
  3906. level_update->setDataByName("new_level", new_level);
  3907. level_update->setDataByName("type", 1);
  3908. QueuePacket(level_update->serialize());
  3909. safe_delete(level_update);
  3910. }
  3911. // Need to make tradeskill versions of the following
  3912. //SendNewSpells(player->GetAdventureClass());
  3913. //SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  3914. //SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  3915. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3916. if (command_packet) {
  3917. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  3918. command_packet->setDataByName("anim_type", 1753);
  3919. QueuePacket(command_packet->serialize());
  3920. safe_delete(command_packet);
  3921. }
  3922. GetPlayer()->GetInfoStruct()->tradeskill_level = new_level;
  3923. GetPlayer()->SetTSLevel(new_level);
  3924. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  3925. GetPlayer()->SetCharSheetChanged(true);
  3926. Message(CHANNEL_NARRATIVE, "Your tradeskill level is now %i!", new_level);
  3927. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  3928. PlayerSkillList* player_skills = player->GetSkills();
  3929. int16 specialize_skill_cap = new_level * 5;
  3930. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  3931. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  3932. int8 ts_class = player->GetTradeskillClass();
  3933. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  3934. int32 skill_id_1, skill_id_2, skill_id_3;
  3935. switch (base_ts_class) {
  3936. case ARTISAN:
  3937. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  3938. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  3939. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  3940. break;
  3941. case OUTFITTER:
  3942. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  3943. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  3944. skill_id_1 = SKILL_ID_TAILORING;
  3945. skill_id_2 = SKILL_ID_METALSHAPING;
  3946. skill_id_3 = SKILL_ID_METALWORKING;
  3947. if (ts_class == TAILOR) {
  3948. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  3949. skill_id_1 = 0;
  3950. }
  3951. else if (ts_class == ARMORER) {
  3952. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  3953. skill_id_2 = 0;
  3954. }
  3955. else if (ts_class == WEAPONSMITH) {
  3956. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  3957. skill_id_3 = 0;
  3958. }
  3959. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  3960. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  3961. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  3962. break;
  3963. case SCHOLAR:
  3964. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  3965. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  3966. skill_id_1 = SKILL_ID_SCRIBING;
  3967. skill_id_2 = SKILL_ID_CHEMISTRY;
  3968. skill_id_3 = SKILL_ID_ARTIFICING;
  3969. if (ts_class == SAGE) {
  3970. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  3971. skill_id_1 = 0;
  3972. }
  3973. else if (ts_class == ALCHEMIST) {
  3974. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  3975. skill_id_2 = 0;
  3976. }
  3977. else if (ts_class == JEWELER) {
  3978. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  3979. skill_id_3 = 0;
  3980. }
  3981. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  3982. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  3983. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  3984. break;
  3985. case CRAFTSMAN:
  3986. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  3987. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  3988. skill_id_1 = SKILL_ID_ARTISTRY;
  3989. skill_id_2 = SKILL_ID_FLETCHING;
  3990. skill_id_3 = SKILL_ID_SCULPTING;
  3991. if (ts_class == PROVISIONER) {
  3992. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  3993. skill_id_1 = 0;
  3994. }
  3995. else if (ts_class == WOODWORKER) {
  3996. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  3997. skill_id_2 = 0;
  3998. }
  3999. else if (ts_class == CARPENTER) {
  4000. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4001. skill_id_3 = 0;
  4002. }
  4003. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4004. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4005. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4006. break;
  4007. default:
  4008. break;
  4009. }
  4010. if (new_level > player->GetAdventureClass())
  4011. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  4012. Guild* guild = GetPlayer()->GetGuild();
  4013. if (guild) {
  4014. int8 event_type = 0;
  4015. if (new_level < 10)
  4016. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  4017. else if (new_level == 10)
  4018. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  4019. else if (new_level >= 11 && new_level < 20)
  4020. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  4021. else if (new_level == 20)
  4022. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  4023. else if (new_level >= 21 && new_level < 30)
  4024. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  4025. else if (new_level == 30)
  4026. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  4027. else if (new_level >= 31 && new_level < 40)
  4028. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  4029. else if (new_level == 40)
  4030. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  4031. else if (new_level >= 41 && new_level < 50)
  4032. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  4033. else if (new_level == 50)
  4034. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  4035. else if (new_level >= 51 && new_level < 60)
  4036. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  4037. else if (new_level == 60)
  4038. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  4039. else if (new_level >= 61 && new_level < 70)
  4040. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  4041. else if (new_level == 70)
  4042. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  4043. else if (new_level >= 71 && new_level < 80)
  4044. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  4045. else if (new_level == 80)
  4046. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  4047. 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());
  4048. 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());
  4049. guild->UpdateGuildMemberInfo(GetPlayer());
  4050. guild->SendGuildMember(GetPlayer());
  4051. guild->SendGuildMemberList();
  4052. }
  4053. // Need to send the trait list every time the players level changes
  4054. // Also need to force the char sheet update or else there can be a large delay from when you level
  4055. // to when you are actually able to select traits.
  4056. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4057. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4058. }
  4059. void Client::SendPendingLoot(int32 total_coins, Spawn* entity) {
  4060. if (entity)
  4061. Loot(total_coins, player->GetPendingLootItems(entity->GetID()), entity);
  4062. }
  4063. void Client::CloseLoot(int32 spawn_id) {
  4064. if (GetVersion() > 546) {
  4065. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  4066. if (packet) {
  4067. packet->setDataByName("window_id", 4);
  4068. EQ2Packet* outapp = packet->serialize();
  4069. if (outapp) {
  4070. //DumpPacket(outapp);
  4071. QueuePacket(outapp);
  4072. }
  4073. safe_delete(packet);
  4074. }
  4075. }
  4076. else if(spawn_id > 0){
  4077. PacketStruct* packet = configReader.getStruct("WS_StoppedLooting", GetVersion());
  4078. if (packet) {
  4079. packet->setDataByName("spawn_id", spawn_id);
  4080. EQ2Packet* outapp = packet->serialize();
  4081. if (outapp)
  4082. QueuePacket(outapp);
  4083. safe_delete(packet);
  4084. }
  4085. }
  4086. }
  4087. string Client::GetCoinMessage(int32 total_coins) {
  4088. if (total_coins == 0) {
  4089. return " 0 Copper";
  4090. }
  4091. char tmp[64] = { 0 };
  4092. string message = "";
  4093. int32 val = 0;
  4094. if (total_coins >= 1000000) {
  4095. val = total_coins / 1000000;
  4096. total_coins -= 1000000 * val;
  4097. sprintf(tmp, " %u Platinum", val);
  4098. message.append(tmp);
  4099. memset(tmp, 0, 64);
  4100. }
  4101. if (total_coins >= 10000) {
  4102. val = total_coins / 10000;
  4103. total_coins -= 10000 * val;
  4104. sprintf(tmp, " %u Gold", val);
  4105. message.append(tmp);
  4106. memset(tmp, 0, 64);
  4107. }
  4108. if (total_coins >= 100) {
  4109. val = total_coins / 100;
  4110. total_coins -= 100 * val;
  4111. sprintf(tmp, " %u Silver", val);
  4112. message.append(tmp);
  4113. memset(tmp, 0, 64);
  4114. }
  4115. if (total_coins > 0) {
  4116. sprintf(tmp, " %u Copper", (int32)total_coins);
  4117. message.append(tmp);
  4118. }
  4119. return message;
  4120. }
  4121. void Client::Loot(int32 total_coins, vector<Item*>* items, Spawn* entity) {
  4122. if (!entity) {
  4123. CloseLoot(0);
  4124. return;
  4125. }
  4126. if (total_coins > 0) {
  4127. player->AddCoins(total_coins);
  4128. //PlaySound("coin_cha_ching");
  4129. string message = "";
  4130. if (entity->GetHP() == 0) {
  4131. message = "You loot ";
  4132. entity->SetLootCoins(0);
  4133. }
  4134. else
  4135. message = "You receive ";
  4136. message.append(GetCoinMessage(total_coins));
  4137. if (entity->GetHP() == 0)
  4138. message.append(" from the corpse of ").append(entity->GetName());
  4139. int8 type = CHANNEL_LOOT;
  4140. SimpleMessage(type, message.c_str());
  4141. }
  4142. if (!items || items->size() == 0)
  4143. CloseLoot(entity->GetID());
  4144. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  4145. if (packet) {
  4146. vector<Item*>::iterator itr;
  4147. int32 packet_size = 0;
  4148. EQ2Packet* outapp = 0;
  4149. uchar* data = 0;
  4150. if (GetVersion() >= 284) {
  4151. if (GetVersion() > 546) {
  4152. if (items && items->size() > 0) {
  4153. packet->setDataByName("loot_count", items->size());
  4154. packet->setDataByName("display", 1);
  4155. }
  4156. packet->setDataByName("loot_type", 1);
  4157. if (version >= 1096)
  4158. packet->setDataByName("lotto_timeout", 0x78);
  4159. else
  4160. packet->setDataByName("lotto_timeout", 0x3C);
  4161. packet->setDataByName("loot_id", entity->GetID());
  4162. EQ2Packet* tmpPacket = packet->serialize();
  4163. packet_size += tmpPacket->size;
  4164. if (items && items->size() > 0) {
  4165. data = new uchar[items->size() * 1000 + packet_size];
  4166. memset(data, 0, items->size() * 1000 + packet_size);
  4167. }
  4168. else {
  4169. data = new uchar[packet_size];
  4170. memset(data, 0, packet_size);
  4171. }
  4172. uchar* ptr = data;
  4173. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  4174. ptr += tmpPacket->size;
  4175. safe_delete(tmpPacket);
  4176. Item* item = 0;
  4177. if (items && items->size() > 0) {
  4178. for (itr = items->begin(); itr != items->end(); itr++) {
  4179. item = *itr;
  4180. memcpy(ptr, &item->details.item_id, sizeof(int32));
  4181. ptr += sizeof(int32);
  4182. packet_size += sizeof(int32);
  4183. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  4184. int8 offset = 0;
  4185. if (GetVersion() >= 1188) {
  4186. offset = 13;
  4187. }
  4188. else if (GetVersion() >= 860) {
  4189. offset = 11;
  4190. }
  4191. else if (GetVersion() <= 546) {
  4192. offset = 19;
  4193. }
  4194. else {
  4195. offset = 10;
  4196. }
  4197. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  4198. ptr += tmpPacket->size - offset;
  4199. packet_size += tmpPacket->size - offset;
  4200. safe_delete(tmpPacket);
  4201. }
  4202. }
  4203. packet_size -= sizeof(int32);
  4204. memcpy(data, &packet_size, sizeof(int32));
  4205. packet_size += sizeof(int32);
  4206. outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  4207. }
  4208. else {
  4209. if (items && items->size() > 0) {
  4210. packet->setArrayLengthByName("loot_count", items->size());
  4211. Item* item = 0;
  4212. if (items && items->size() > 0) {
  4213. int i = 0;
  4214. for (itr = items->begin(); itr != items->end(); itr++) {
  4215. item = *itr;
  4216. packet->setArrayDataByName("loot_id", item->details.item_id, i);
  4217. packet->setItemArrayDataByName("item", item, GetPlayer(), i, 0, 2, true);
  4218. i++;
  4219. }
  4220. }
  4221. packet->setDataByName("display", 1);
  4222. }
  4223. packet->setDataByName("loot_type", 1); // normal
  4224. packet->setDataByName("lotto_timeout", 0x3c); // 60 seconds
  4225. packet->setDataByName("spawn_id", entity->GetID());
  4226. outapp = packet->serialize();
  4227. }
  4228. }
  4229. else {
  4230. if (items && items->size() > 0) {
  4231. packet->setArrayLengthByName("loot_count", items->size());
  4232. for (int i = 0; i < items->size(); i++) {
  4233. Item* item = (*items)[i];
  4234. packet->setArrayDataByName("name", item->name.c_str(), i);
  4235. packet->setArrayDataByName("item_id", item->details.item_id, i);
  4236. packet->setArrayDataByName("count", item->details.count, i);
  4237. packet->setArrayDataByName("icon", item->details.icon, i);
  4238. if (item->generic_info.skill_req1 > 0 && item->generic_info.skill_req1 < 0xFFFFFFFF)
  4239. packet->setArrayDataByName("ability_id", item->generic_info.skill_req1, i);
  4240. else if (item->generic_info.skill_req2 > 0 && item->generic_info.skill_req2 < 0xFFFFFFFF)
  4241. packet->setArrayDataByName("ability_id", item->generic_info.skill_req2, i);
  4242. else
  4243. packet->setArrayDataByName("ability_id", 0xFFFFFFFF, i);
  4244. }
  4245. }
  4246. packet->setDataByName("object_id", entity->GetID());
  4247. packet->setDataByName("unknown3", 1);
  4248. packet->setDataByName("unknown4", 1);
  4249. packet->setDataByName("unknown5", 60);
  4250. outapp = packet->serialize();
  4251. }
  4252. if (outapp) {
  4253. DumpPacket(outapp);
  4254. QueuePacket(outapp);
  4255. }
  4256. safe_delete_array(data);
  4257. safe_delete(packet);
  4258. }
  4259. }
  4260. void Client::Loot(Spawn* entity, bool attemptDisarm) {
  4261. if (entity->IsNPC() && ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  4262. int32 total_coins = entity->GetLootCoins();
  4263. entity->LockLoot();
  4264. Loot(total_coins, entity->GetLootItems(), entity);
  4265. entity->UnlockLoot();
  4266. OpenChest(entity, attemptDisarm);
  4267. }
  4268. else
  4269. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  4270. }
  4271. void Client::OpenChest(Spawn* entity, bool attemptDisarm)
  4272. {
  4273. if (!entity)
  4274. return;
  4275. int8 chest_difficulty = 0;
  4276. int32 state = 0;
  4277. // Check for the chest and set the action state
  4278. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  4279. string modelName;
  4280. if (entity->GetModelType() == 4034) {
  4281. // small chest, open with copper coins
  4282. // does not include traps, however can be disarmed
  4283. chest_difficulty = 1;
  4284. state = 11899;
  4285. modelName.append("Small Chest");
  4286. }
  4287. else if (entity->GetModelType() == 5864) {
  4288. // treasure chest, open with silver coins
  4289. chest_difficulty = 2;
  4290. state = 11901;
  4291. modelName.append("Treasure Chest");
  4292. }
  4293. else if (entity->GetModelType() == 5865) {
  4294. // ornate chest, open with gold coins
  4295. chest_difficulty = 3;
  4296. state = 11900;
  4297. modelName.append("Ornate Chest");
  4298. }
  4299. else if (entity->GetModelType() == 4015) {
  4300. // exquisite chest, open with gold coins and jewels as well as a glow effect
  4301. chest_difficulty = 5;
  4302. state = 11898;
  4303. modelName.append("Exquisite Chest");
  4304. }
  4305. bool firstChestOpen = false;
  4306. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  4307. {
  4308. ChestTrap::ChestTrapInfo nextTrap;
  4309. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  4310. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  4311. firstChestOpen = true;
  4312. entity->SetTrapTriggered(true);
  4313. if (ret)
  4314. {
  4315. if (disarmSkill && attemptDisarm)
  4316. {
  4317. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  4318. {
  4319. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  4320. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  4321. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  4322. }
  4323. else
  4324. {
  4325. Message(CHANNEL_NARRATIVE, "You disarm the trap on %s", modelName.c_str());
  4326. }
  4327. // despite fail/succeed we should always try to increase skill if disarm is available
  4328. GetPlayer()->GetSkillByName("Disarm Trap", true);
  4329. }
  4330. else // no disarm skill, always fail
  4331. {
  4332. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  4333. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  4334. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  4335. }
  4336. }
  4337. }
  4338. else if (!entity->HasTrapTriggered())
  4339. {
  4340. firstChestOpen = true;
  4341. entity->SetTrapTriggered(true);
  4342. }
  4343. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  4344. // for those in range the SendStateCommand will cause it to animate open.
  4345. // TODO: when player enters radius that does not have visual state, update visual state
  4346. if (firstChestOpen)
  4347. entity->SetVisualState(state, false);
  4348. GetCurrentZone()->SendStateCommand(entity, state);
  4349. }
  4350. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  4351. {
  4352. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  4353. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  4354. if (source == NULL)
  4355. source = (Entity*)GetPlayer();
  4356. if (spell)
  4357. {
  4358. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  4359. if (gmi && gmi->group_id)
  4360. {
  4361. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  4362. if (group)
  4363. {
  4364. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4365. deque<GroupMemberInfo*>* members = group->GetMembers();
  4366. for (int8 i = 0; i < members->size(); i++) {
  4367. Entity* member = members->at(i)->member;
  4368. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  4369. continue;
  4370. // if we have a radius provided then check if the group member is outside the radius or not
  4371. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  4372. continue;
  4373. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4374. }
  4375. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4376. }
  4377. }
  4378. else
  4379. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4380. }
  4381. }
  4382. Spawn* Client::GetBanker() {
  4383. return banker;
  4384. }
  4385. void Client::SetBanker(Spawn* in_banker) {
  4386. banker = in_banker;
  4387. }
  4388. void Client::Bank(Spawn* banker, bool cancel) {
  4389. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  4390. if (!cancel)
  4391. SetBanker(banker);
  4392. else
  4393. SetBanker(0);
  4394. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  4395. if (packet) {
  4396. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  4397. int64 coins = GetPlayer()->GetInfoStruct()->bank_coin_copper + GetPlayer()->GetInfoStruct()->bank_coin_silver * 100 +
  4398. GetPlayer()->GetInfoStruct()->bank_coin_gold * 10000 + (int64)GetPlayer()->GetInfoStruct()->bank_coin_plat * 1000000;
  4399. int32 coins1, coins2;
  4400. coins1 = ((int32*)&coins)[0];
  4401. coins2 = ((int32*)&coins)[1];
  4402. packet->setDataByName("bank_coins", coins1);
  4403. packet->setDataByName("bank_coins2", coins2);
  4404. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->coin_copper);
  4405. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->coin_silver);
  4406. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->coin_gold);
  4407. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->coin_plat);
  4408. if (!cancel)
  4409. packet->setDataByName("display", 1);
  4410. QueuePacket(packet->serialize());
  4411. safe_delete(packet);
  4412. }
  4413. }
  4414. }
  4415. void Client::BankWithdrawal(int64 amount) {
  4416. bool cheater = false;
  4417. if (GetBanker() && amount > 0) {
  4418. string withdrawal = "";
  4419. char withdrawal_data[512] = { 0 };
  4420. int32 tmp = 0;
  4421. if (amount >= 1000000) {
  4422. tmp = amount / 1000000;
  4423. if (tmp > GetPlayer()->GetBankCoinsPlat())
  4424. cheater = true;
  4425. else {
  4426. GetPlayer()->GetInfoStruct()->bank_coin_plat -= tmp;
  4427. GetPlayer()->GetInfoStruct()->coin_plat += tmp;
  4428. amount -= (int64)tmp * 1000000;
  4429. sprintf(withdrawal_data, "%u Platinum ", tmp);
  4430. withdrawal.append(withdrawal_data);
  4431. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4432. }
  4433. }
  4434. if (!cheater && amount >= 10000) {
  4435. tmp = amount / 10000;
  4436. if (tmp > GetPlayer()->GetBankCoinsGold())
  4437. cheater = true;
  4438. else {
  4439. GetPlayer()->GetInfoStruct()->bank_coin_gold -= tmp;
  4440. if ((GetPlayer()->GetInfoStruct()->coin_gold + tmp) > 100) {
  4441. GetPlayer()->GetInfoStruct()->coin_gold = (GetPlayer()->GetInfoStruct()->coin_gold + tmp) - 100;
  4442. GetPlayer()->GetInfoStruct()->coin_plat += 1;
  4443. }
  4444. else
  4445. GetPlayer()->GetInfoStruct()->coin_gold += tmp;
  4446. amount -= tmp * 10000;
  4447. sprintf(withdrawal_data, "%u Gold ", tmp);
  4448. withdrawal.append(withdrawal_data);
  4449. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4450. }
  4451. }
  4452. if (!cheater && amount >= 100) {
  4453. tmp = amount / 100;
  4454. if (tmp > GetPlayer()->GetBankCoinsSilver())
  4455. cheater = true;
  4456. else {
  4457. GetPlayer()->GetInfoStruct()->bank_coin_silver -= tmp;
  4458. if ((GetPlayer()->GetInfoStruct()->coin_silver + tmp) > 100) {
  4459. GetPlayer()->GetInfoStruct()->coin_silver = (GetPlayer()->GetInfoStruct()->coin_silver + tmp) - 100;
  4460. GetPlayer()->GetInfoStruct()->coin_gold += 1;
  4461. }
  4462. else
  4463. GetPlayer()->GetInfoStruct()->coin_silver += tmp;
  4464. amount -= tmp * 100;
  4465. sprintf(withdrawal_data, "%u Silver ", tmp);
  4466. withdrawal.append(withdrawal_data);
  4467. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4468. }
  4469. }
  4470. if (!cheater) {
  4471. if (amount > 0) {
  4472. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  4473. withdrawal.append(withdrawal_data);
  4474. GetPlayer()->GetInfoStruct()->bank_coin_copper -= amount;
  4475. if ((GetPlayer()->GetInfoStruct()->coin_copper + amount) > 100) {
  4476. GetPlayer()->GetInfoStruct()->coin_copper = (GetPlayer()->GetInfoStruct()->coin_copper + amount) - 100;
  4477. GetPlayer()->GetInfoStruct()->coin_silver += 1;
  4478. }
  4479. else
  4480. GetPlayer()->GetInfoStruct()->coin_copper += amount;
  4481. }
  4482. if (withdrawal.length() > 0) {
  4483. withdrawal.append("withdrawn ");
  4484. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->bank_coin_plat,
  4485. GetPlayer()->GetInfoStruct()->bank_coin_gold, GetPlayer()->GetInfoStruct()->bank_coin_silver, GetPlayer()->GetInfoStruct()->bank_coin_copper);
  4486. withdrawal.append(withdrawal_data);
  4487. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  4488. }
  4489. }
  4490. else
  4491. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4492. player->SetCharSheetChanged(true);
  4493. Bank(banker);
  4494. }
  4495. }
  4496. void Client::BankDeposit(int64 amount) {
  4497. bool cheater = false;
  4498. if (GetBanker() && amount > 0) {
  4499. int32 tmp = 0;
  4500. char deposit_data[512] = { 0 };
  4501. string deposit = "";
  4502. if (amount >= 1000000) {
  4503. tmp = amount / 1000000;
  4504. if (tmp > GetPlayer()->GetCoinsPlat())
  4505. cheater = true;
  4506. else {
  4507. GetPlayer()->GetInfoStruct()->bank_coin_plat += tmp;
  4508. GetPlayer()->GetInfoStruct()->coin_plat -= tmp;
  4509. amount -= (int64)tmp * 1000000;
  4510. sprintf(deposit_data, "%u Platinum ", tmp);
  4511. deposit.append(deposit_data);
  4512. memset(deposit_data, 0, sizeof(deposit_data));
  4513. }
  4514. }
  4515. if (!cheater && amount >= 10000) {
  4516. tmp = amount / 10000;
  4517. if (tmp > GetPlayer()->GetCoinsGold())
  4518. cheater = true;
  4519. else {
  4520. if ((GetPlayer()->GetInfoStruct()->bank_coin_gold + tmp) > 100) {
  4521. GetPlayer()->GetInfoStruct()->bank_coin_gold = (GetPlayer()->GetInfoStruct()->bank_coin_gold + tmp) - 100;
  4522. GetPlayer()->GetInfoStruct()->bank_coin_plat += 1;
  4523. }
  4524. else
  4525. GetPlayer()->GetInfoStruct()->bank_coin_gold += tmp;
  4526. GetPlayer()->GetInfoStruct()->coin_gold -= tmp;
  4527. amount -= tmp * 10000;
  4528. sprintf(deposit_data, "%u Gold ", tmp);
  4529. deposit.append(deposit_data);
  4530. memset(deposit_data, 0, sizeof(deposit_data));
  4531. }
  4532. }
  4533. if (!cheater && amount >= 100) {
  4534. tmp = amount / 100;
  4535. if (tmp > GetPlayer()->GetCoinsSilver())
  4536. cheater = true;
  4537. else {
  4538. if ((GetPlayer()->GetInfoStruct()->bank_coin_silver + tmp) > 100) {
  4539. GetPlayer()->GetInfoStruct()->bank_coin_silver = (GetPlayer()->GetInfoStruct()->bank_coin_silver + tmp) - 100;
  4540. GetPlayer()->GetInfoStruct()->bank_coin_gold += 1;
  4541. }
  4542. else
  4543. GetPlayer()->GetInfoStruct()->bank_coin_silver += tmp;
  4544. GetPlayer()->GetInfoStruct()->coin_silver -= tmp;
  4545. amount -= tmp * 100;
  4546. sprintf(deposit_data, "%u Silver ", tmp);
  4547. deposit.append(deposit_data);
  4548. memset(deposit_data, 0, sizeof(deposit_data));
  4549. }
  4550. }
  4551. if (!cheater) {
  4552. if (amount > 0) {
  4553. sprintf(deposit_data, "%u Copper ", (int32)amount);
  4554. deposit.append(deposit_data);
  4555. if ((GetPlayer()->GetInfoStruct()->bank_coin_copper + amount) > 100) {
  4556. GetPlayer()->GetInfoStruct()->bank_coin_copper = (GetPlayer()->GetInfoStruct()->bank_coin_copper + amount) - 100;
  4557. GetPlayer()->GetInfoStruct()->bank_coin_silver += 1;
  4558. }
  4559. else
  4560. GetPlayer()->GetInfoStruct()->bank_coin_copper += amount;
  4561. GetPlayer()->GetInfoStruct()->coin_copper -= amount;
  4562. }
  4563. if (deposit.length() > 0) {
  4564. deposit.append("deposited ");
  4565. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->bank_coin_plat,
  4566. GetPlayer()->GetInfoStruct()->bank_coin_gold, GetPlayer()->GetInfoStruct()->bank_coin_silver, GetPlayer()->GetInfoStruct()->bank_coin_copper);
  4567. deposit.append(deposit_data);
  4568. SimpleMessage(CHANNEL_NARRATIVE, deposit.c_str());
  4569. }
  4570. }
  4571. else
  4572. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4573. player->SetCharSheetChanged(true);
  4574. Bank(banker);
  4575. }
  4576. }
  4577. void Client::AddPendingQuestReward(Quest* quest) {
  4578. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4579. quest_pending_reward.push_back(quest);
  4580. quest_updates = true;
  4581. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4582. }
  4583. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  4584. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4585. quest_pending_updates[quest_id][step_id] = progress;
  4586. quest_updates = true;
  4587. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4588. }
  4589. void Client::ProcessQuestUpdates() {
  4590. if (quest_pending_updates.size() > 0) {
  4591. map<int32, map<int32, int32> > tmp_quest_updates;
  4592. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4593. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  4594. quest_pending_updates.clear();
  4595. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4596. map<int32, map<int32, int32> >::iterator quest_itr;
  4597. map<int32, int32>::iterator step_itr;
  4598. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  4599. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  4600. if (step_itr->second == 0xFFFFFFFF) {
  4601. SetStepComplete(quest_itr->first, step_itr->first);
  4602. player->SendQuestRequiredSpawns(quest_itr->first);
  4603. }
  4604. else
  4605. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  4606. }
  4607. }
  4608. }
  4609. if (quest_pending_reward.size() > 0) {
  4610. vector<Quest*>::iterator itr;
  4611. vector<Quest*> tmp_quest_rewards;
  4612. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4613. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.end());
  4614. quest_pending_reward.clear();
  4615. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4616. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end(); itr++) {
  4617. GiveQuestReward(*itr);
  4618. }
  4619. }
  4620. quest_updates = false;
  4621. }
  4622. void Client::CheckQuestQueue() {
  4623. MQuestQueue.writelock();
  4624. last_update_time = 0;
  4625. vector<QueuedQuest*>::iterator itr;
  4626. QueuedQuest* queued_quest = 0;
  4627. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  4628. queued_quest = *itr;
  4629. SendQuestUpdateStepImmediately(queued_quest->quest, queued_quest->step, queued_quest->display_quest_helper);
  4630. if(queued_quest->quest && queued_quest->quest->GetTurnedIn()) //update the journal so the old quest isn't the one displayed in the client's quest helper
  4631. SendQuestJournal();
  4632. safe_delete(queued_quest);
  4633. }
  4634. quest_queue.clear();
  4635. MQuestQueue.releasewritelock();
  4636. }
  4637. void Client::SetStepComplete(int32 quest_id, int32 step) {
  4638. Quest* quest = player->SetStepComplete(quest_id, step);
  4639. if (quest) {
  4640. SendQuestUpdate(quest);
  4641. GetCurrentZone()->SendQuestUpdates(this);
  4642. }
  4643. }
  4644. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  4645. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  4646. if (quest) {
  4647. SendQuestUpdate(quest);
  4648. GetCurrentZone()->SendQuestUpdates(this);
  4649. }
  4650. }
  4651. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  4652. bool hadUpdates = false;
  4653. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  4654. if (quest_updates) {
  4655. for (int32 i = 0; i < quest_updates->size(); i++)
  4656. {
  4657. SendQuestUpdate(quest_updates->at(i));
  4658. hadUpdates = true;
  4659. }
  4660. }
  4661. safe_delete(quest_updates);
  4662. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4663. if (quest_failures) {
  4664. for (int32 i = 0; i < quest_failures->size(); i++)
  4665. {
  4666. SendQuestFailure(quest_failures->at(i));
  4667. hadUpdates = true;
  4668. }
  4669. }
  4670. safe_delete(quest_failures);
  4671. if (hadUpdates)
  4672. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  4673. }
  4674. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  4675. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  4676. if (quest_updates) {
  4677. for (int32 i = 0; i < quest_updates->size(); i++)
  4678. SendQuestUpdate(quest_updates->at(i));
  4679. GetCurrentZone()->SendQuestUpdates(this);
  4680. }
  4681. safe_delete(quest_updates);
  4682. }
  4683. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  4684. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  4685. if (quest_updates) {
  4686. for (int32 i = 0; i < quest_updates->size(); i++)
  4687. SendQuestUpdate(quest_updates->at(i));
  4688. }
  4689. safe_delete(quest_updates);
  4690. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4691. if (quest_failures) {
  4692. for (int32 i = 0; i < quest_failures->size(); i++)
  4693. SendQuestFailure(quest_failures->at(i));
  4694. }
  4695. safe_delete(quest_failures);
  4696. }
  4697. void Client::CheckPlayerQuestsLocationUpdate() {
  4698. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  4699. if (quest_updates) {
  4700. for (int32 i = 0; i < quest_updates->size(); i++)
  4701. SendQuestUpdate(quest_updates->at(i));
  4702. }
  4703. safe_delete(quest_updates);
  4704. }
  4705. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  4706. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  4707. if (quest_updates) {
  4708. for (int32 i = 0; i < quest_updates->size(); i++)
  4709. SendQuestUpdate(quest_updates->at(i));
  4710. }
  4711. safe_delete(quest_updates);
  4712. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4713. if (quest_failures) {
  4714. for (int32 i = 0; i < quest_failures->size(); i++)
  4715. SendQuestFailure(quest_failures->at(i));
  4716. }
  4717. safe_delete(quest_failures);
  4718. }
  4719. void Client::AddPendingQuest(Quest* quest, bool forced) {
  4720. if (version <= 283 || forced) { //this client doesn't ask if you want the quest, so auto accept
  4721. player->pending_quests[quest->GetQuestID()] = quest;
  4722. AcceptQuest(quest->GetQuestID());
  4723. }
  4724. else {
  4725. player->pending_quests[quest->GetQuestID()] = quest;
  4726. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  4727. //DumpPacket(outapp);
  4728. QueuePacket(outapp);
  4729. }
  4730. }
  4731. Quest* Client::GetActiveQuest(int32 quest_id) {
  4732. if (player->player_quests.count(quest_id) > 0) {
  4733. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u active quests for char_id: %u", player->player_quests.count(quest_id), player->GetCharacterID());
  4734. return player->player_quests[quest_id];
  4735. }
  4736. return 0;
  4737. }
  4738. void Client::AcceptQuest(int32 id) {
  4739. Quest* quest = GetPendingQuest(id);
  4740. if (quest) {
  4741. RemovePendingQuest(quest);
  4742. AddPlayerQuest(quest);
  4743. GetCurrentZone()->SendQuestUpdates(this);
  4744. // If character has already completed this quest once update the given date in the database
  4745. if (GetPlayer()->GetCompletedPlayerQuests()->count(id) > 0) {
  4746. Quest* quest2 = GetPlayer()->GetCompletedQuest(id);
  4747. if (quest2)
  4748. quest->SetCompleteCount(quest2->GetCompleteCount());
  4749. database.SaveCharRepeatableQuest(this, id, quest->GetCompleteCount());
  4750. }
  4751. }
  4752. }
  4753. Quest* Client::GetPendingQuest(int32 id) {
  4754. if (player->pending_quests.count(id) > 0) {
  4755. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u pending quests for char_id: %u", player->pending_quests.count(id), player->GetCharacterID());
  4756. return player->pending_quests[id];
  4757. }
  4758. return 0;
  4759. }
  4760. void Client::RemovePendingQuest(Quest* quest) {
  4761. player->pending_quests.erase(quest->GetQuestID());
  4762. }
  4763. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  4764. if (!quest || !progress) {
  4765. return;
  4766. }
  4767. map<int32, int32>::iterator itr;
  4768. QuestStep* step = 0;
  4769. player->SetZone(GetCurrentZone(), GetVersion());
  4770. for (itr = progress->begin(); itr != progress->end(); itr++) {
  4771. step = quest->GetQuestStep(itr->first);
  4772. if (step && itr->second > 0) {
  4773. step->SetStepProgress(itr->second);
  4774. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  4775. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  4776. }
  4777. }
  4778. if (lua_interface)
  4779. lua_interface->CallQuestFunction(quest, "CurrentStep", player, step->GetStepID());
  4780. }
  4781. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  4782. if (player->player_quests.count(quest->GetQuestID()) > 0) {
  4783. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  4784. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  4785. RemovePlayerQuest(quest->GetQuestID(), false, false);
  4786. }
  4787. player->player_quests[quest->GetQuestID()] = quest;
  4788. quest->SetPlayer(player);
  4789. current_quest_id = quest->GetQuestID();
  4790. if (send_packets && quest->GetQuestGiver() > 0)
  4791. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  4792. if (lua_interface && call_accepted)
  4793. lua_interface->CallQuestFunction(quest, "Accepted", player);
  4794. if (send_packets) {
  4795. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4796. //SendQuestJournal();
  4797. SendQuestJournalUpdate(quest);
  4798. // sent twice to match live
  4799. quest->SetTracked(false);
  4800. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  4801. quest->SetTracked(true);
  4802. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  4803. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  4804. }
  4805. //This isn't during a load screen, so update spawns with required quests
  4806. if (call_accepted)
  4807. player->SendQuestRequiredSpawns(quest->GetQuestID());
  4808. }
  4809. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  4810. if (current_quest_id == id)
  4811. current_quest_id = 0;
  4812. if (player->player_quests.count(id) > 0) {
  4813. if (delete_quest) {
  4814. player->player_quests[id]->SetDeleted(true);
  4815. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  4816. }
  4817. if (send_update && player->player_quests[id]->GetQuestGiver() > 0)
  4818. GetCurrentZone()->SendSpawnChangesByDBID(player->player_quests[id]->GetQuestGiver(), this, false, true);
  4819. if (send_update) {
  4820. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4821. SendQuestJournal(false, 0, true);
  4822. }
  4823. player->RemoveQuest(id, delete_quest);
  4824. if (send_update) {
  4825. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4826. SendQuestJournal(false, 0, true);
  4827. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  4828. }
  4829. }
  4830. }
  4831. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  4832. if (quest) {
  4833. QuestStep* quest_step = quest->GetQuestStep(step);
  4834. if (quest_step) {
  4835. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  4836. quest_step->WasUpdated(false);
  4837. }
  4838. }
  4839. }
  4840. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  4841. QueuedQuest* item = new QueuedQuest;
  4842. item->quest = quest;
  4843. item->step = step;
  4844. item->display_quest_helper = display_quest_helper;
  4845. MQuestQueue.writelock();
  4846. quest_queue.push_back(item);
  4847. last_update_time = Timer::GetCurrentTime2();
  4848. MQuestQueue.releasewritelock();
  4849. }
  4850. void Client::SendQuestFailure(Quest* quest) {
  4851. vector<QuestStep*>* failures = quest->GetQuestFailures();
  4852. if (failures) {
  4853. QuestStep* step = 0;
  4854. for (int32 i = 0; i < failures->size(); i++) {
  4855. step = failures->at(i);
  4856. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  4857. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4858. SendQuestJournal(false, 0, true);
  4859. }
  4860. failures->clear();
  4861. }
  4862. }
  4863. void Client::SendQuestUpdate(Quest* quest) {
  4864. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  4865. if (updates) {
  4866. QuestStep* step = 0;
  4867. bool updated = false;
  4868. for (int32 i = 0; i < updates->size(); i++) {
  4869. step = updates->at(i);
  4870. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  4871. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  4872. if (step->WasUpdated()) {
  4873. // reversing the order of SendQuestJournal and QueuePacket QuestJournalReply causes AoM client to crash!
  4874. SendQuestJournal(false, 0, true);
  4875. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  4876. }
  4877. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4878. }
  4879. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction()) {
  4880. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  4881. SendQuestJournalUpdate(quest, false);
  4882. }
  4883. if (quest->GetCompleted()) {
  4884. if (quest->GetQuestReturnNPC() > 0)
  4885. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  4886. if (quest->GetCompletedFlag())
  4887. quest->SetCompletedFlag(false);
  4888. }
  4889. updates->clear();
  4890. }
  4891. }
  4892. void Client::SendQuestJournal(bool all_quests, Client* client, bool updated) {
  4893. if (!client)
  4894. client = this;
  4895. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id, updated);
  4896. if (packet) {
  4897. EQ2Packet* outapp = packet->serialize();
  4898. //DumpPacket(outapp);
  4899. client->QueuePacket(outapp);
  4900. safe_delete(packet);
  4901. }
  4902. }
  4903. void Client::SendQuestJournalUpdate(Quest* quest, bool updated) {
  4904. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC(), updated);
  4905. if (packet) {
  4906. QueuePacket(packet->serialize());
  4907. safe_delete(packet);
  4908. }
  4909. }
  4910. void Client::ReloadQuests() {
  4911. vector<int32> ids = player->GetQuestIDs();
  4912. Quest* quest = 0;
  4913. for (int32 i = 0; i < ids.size(); i++) {
  4914. quest = master_quest_list.GetQuest(ids[i]);
  4915. if (quest)
  4916. AddPlayerQuest(quest, false);
  4917. else
  4918. RemovePlayerQuest(ids[i]);
  4919. }
  4920. }
  4921. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  4922. bool found_quest = false;
  4923. vector<Quest*>::iterator itr;
  4924. vector<Item*>* items = 0;
  4925. Quest* quest = 0;
  4926. MPendingQuestAccept.lock();
  4927. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end(); itr++) {
  4928. quest = *itr;
  4929. items = quest->GetRewardItems();
  4930. if (item_id == 0 && items && items->size() > 0) {
  4931. found_quest = true;
  4932. }
  4933. else {
  4934. items = quest->GetSelectableRewardItems();
  4935. if (items && items->size() > 0) {
  4936. for (int32 i = 0; i < items->size(); i++) {
  4937. if (items->at(i)->details.item_id == item_id) {
  4938. found_quest = true;
  4939. break;
  4940. }
  4941. }
  4942. }
  4943. }
  4944. if (found_quest) {
  4945. pending_quest_accept.erase(itr);
  4946. break;
  4947. }
  4948. }
  4949. MPendingQuestAccept.unlock();
  4950. if (found_quest)
  4951. return quest;
  4952. return 0;
  4953. }
  4954. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  4955. int8 num_slots_needed = 0;
  4956. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  4957. Item* master_item = 0;
  4958. if (item_id > 0) {
  4959. num_slots_needed++;
  4960. master_item = master_item_list.GetItem(item_id);
  4961. }
  4962. vector<Item*>* items = quest->GetRewardItems();
  4963. if (items && items->size() > 0)
  4964. num_slots_needed += items->size();
  4965. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= items->size())) {
  4966. if (master_item)
  4967. AddItem(item_id);
  4968. if (items && items->size() > 0) {
  4969. for (int32 i = 0; i < items->size(); i++)
  4970. AddItem(new Item(items->at(i)));
  4971. }
  4972. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  4973. if (outapp)
  4974. QueuePacket(outapp);
  4975. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  4976. map<int32, sint32>::iterator itr;
  4977. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  4978. int32 faction_id = itr->first;
  4979. sint32 amount = itr->second;
  4980. if (amount > 0)
  4981. player->GetFactions()->IncreaseFaction(faction_id, amount);
  4982. else
  4983. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  4984. }
  4985. if (player->GetGuild()) {
  4986. player->GetInfoStruct()->status_points += quest->GetStatusPoints();
  4987. player->SetCharSheetChanged(true);
  4988. }
  4989. }
  4990. else {
  4991. MPendingQuestAccept.lock();
  4992. pending_quest_accept.push_back(quest);
  4993. MPendingQuestAccept.unlock();
  4994. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  4995. DisplayQuestComplete(quest);
  4996. }
  4997. }
  4998. void Client::DisplayQuestRewards(Quest* quest, int64 coin, vector<Item*>* rewards, vector<Item*>* selectable_rewards, map<int32, sint32>* factions, const char* header, int32 status_points, const char* text) {
  4999. if (coin == 0 && (!rewards || rewards->size() == 0) && (!selectable_rewards || selectable_rewards->size() == 0) && (!factions || factions->size() == 0) && status_points == 0 && text == 0 && (!quest || (quest->GetCoinsReward() == 0 && quest->GetCoinsRewardMax() == 0))) {
  5000. /*if (quest)
  5001. text = quest->GetName();
  5002. else*/
  5003. return;//nothing to give
  5004. }
  5005. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  5006. if (packet2) {
  5007. int32 source_id = 0;
  5008. if (quest)
  5009. source_id = quest->GetQuestID();
  5010. int64 rewarded_coin = 0;
  5011. if (quest) {
  5012. if (quest->GetCoinsReward() > 0) {
  5013. if (quest->GetCoinsRewardMax() > 0)
  5014. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  5015. else
  5016. rewarded_coin = quest->GetCoinsReward();
  5017. }
  5018. quest->SetGeneratedCoin(rewarded_coin);
  5019. }
  5020. if (rewarded_coin > coin)
  5021. coin = rewarded_coin;
  5022. if (!quest) { //this entire function is either for version <=546 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5023. if (coin > 0) {
  5024. player->AddCoins(coin);
  5025. PlaySound("coin_cha_ching");
  5026. }
  5027. }
  5028. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  5029. packet2->setSubstructDataByName("reward_data", "reward", header);
  5030. packet2->setSubstructDataByName("reward_data", "max_coin", coin);
  5031. if (player->GetGuild()) {
  5032. if (!quest) { //this entire function is either for version <=546 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5033. player->GetInfoStruct()->status_points += status_points;
  5034. player->SetCharSheetChanged(true);
  5035. }
  5036. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  5037. }
  5038. if(text)
  5039. packet2->setSubstructDataByName("reward_data", "text", text);
  5040. if(rewards){
  5041. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", rewards->size());
  5042. for (int i = 0; i < rewards->size(); i++) {
  5043. Item* item = rewards->at(i);
  5044. if (item) {
  5045. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  5046. packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
  5047. }
  5048. if(!quest) //this entire function is either for version <=546 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5049. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  5050. }
  5051. }
  5052. if (selectable_rewards) {
  5053. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_rewards->size());
  5054. for (int i = 0; i < selectable_rewards->size(); i++) {
  5055. Item* item = selectable_rewards->at(i);
  5056. if (item) {
  5057. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  5058. packet2->setItemArrayDataByName("select_item", item, player, i, 0, -1);
  5059. if (!quest) //this entire function is either for version <=546 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5060. player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  5061. }
  5062. }
  5063. }
  5064. if (factions) {
  5065. map<int32, sint32>::iterator itr;
  5066. map<Faction*, signed int> factions_map;
  5067. for (itr = factions->begin(); itr != factions->end(); itr++) {
  5068. Faction* faction = master_faction_list.GetFaction(itr->first);
  5069. if (faction)
  5070. factions_map[faction] = itr->second;
  5071. }
  5072. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions_map.size());
  5073. map<Faction*, signed int>::iterator faction_itr;
  5074. int8 i = 0;
  5075. for (faction_itr = factions_map.begin(); faction_itr != factions_map.end(); faction_itr++) {
  5076. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  5077. sint32 amount = faction_itr->second;
  5078. packet2->setArrayDataByName("amount", amount, i);
  5079. if (!quest) { //this entire function is for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5080. if (amount > 0)
  5081. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  5082. else
  5083. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  5084. }
  5085. i++;
  5086. }
  5087. }
  5088. QueuePacket(packet2->serialize());
  5089. safe_delete(packet2);
  5090. }
  5091. }
  5092. void Client::DisplayQuestComplete(Quest* quest) {
  5093. if (!quest)
  5094. return;
  5095. if (GetVersion() <= 546) {
  5096. DisplayQuestRewards(quest, 0, quest->GetRewardItems(), quest->GetSelectableRewardItems(), quest->GetRewardFactions(), "Quest Complete!", quest->GetStatusPoints());
  5097. return;
  5098. }
  5099. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  5100. if (packet) {
  5101. packet->setDataByName("title", "Quest Reward!");
  5102. packet->setDataByName("name", quest->GetName());
  5103. packet->setDataByName("description", quest->GetDescription());
  5104. packet->setDataByName("level", quest->GetLevel());
  5105. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  5106. int8 difficulty = 0;
  5107. if ((string)quest->GetType() == "Tradeskill")
  5108. difficulty = player->GetTSArrowColor(quest->GetLevel());
  5109. else
  5110. difficulty = player->GetArrowColor(quest->GetLevel());
  5111. packet->setDataByName("difficulty", difficulty);
  5112. int64 rewarded_coin = 0;
  5113. if (quest->GetCoinsReward() > 0) {
  5114. if (quest->GetCoinsRewardMax() > 0)
  5115. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  5116. else
  5117. rewarded_coin = quest->GetCoinsReward();
  5118. }
  5119. quest->SetGeneratedCoin(rewarded_coin);
  5120. packet->setDataByName("max_coin", rewarded_coin);
  5121. packet->setDataByName("min_coin", rewarded_coin);
  5122. packet->setDataByName("status_points", quest->GetStatusPoints());
  5123. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  5124. vector<Item*>* items = quest->GetRewardItems();
  5125. if (items) {
  5126. packet->setArrayLengthByName("num_rewards", items->size());
  5127. for (int32 i = 0; i < items->size(); i++) {
  5128. packet->setArrayDataByName("reward_id", items->at(i)->details.item_id, i);
  5129. if (version < 860)
  5130. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, -1);
  5131. else if (version < 1193)
  5132. packet->setItemArrayDataByName("item", items->at(i), player, i);
  5133. else
  5134. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, 2);
  5135. }
  5136. }
  5137. if (items2 && items2->size() > 0) {
  5138. packet->setArrayLengthByName("num_select_rewards", items2->size());
  5139. for (int32 i = 0; i < items2->size(); i++) {
  5140. packet->setArrayDataByName("select_reward_id", items2->at(i)->details.item_id, i);
  5141. if (version < 860)
  5142. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, -1);
  5143. else if (version < 1193)
  5144. packet->setItemArrayDataByName("select_item", items2->at(i), player, i);
  5145. else
  5146. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, 2);
  5147. }
  5148. }
  5149. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  5150. if (reward_factions && reward_factions->size() > 0) {
  5151. packet->setArrayLengthByName("num_factions", reward_factions->size());
  5152. map<int32, sint32>::iterator itr;
  5153. int16 index = 0;
  5154. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  5155. int32 faction_id = itr->first;
  5156. sint32 amount = itr->second;
  5157. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  5158. if (faction_name) {
  5159. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  5160. packet->setArrayDataByName("amount", amount, index);
  5161. }
  5162. index++;
  5163. }
  5164. }
  5165. EQ2Packet* outapp = packet->serialize();
  5166. // DumpPacket(outapp);
  5167. QueuePacket(outapp);
  5168. safe_delete(packet);
  5169. }
  5170. }
  5171. void Client::DisplayRandomizeFeatures(int32 flags) {
  5172. SimpleMessage(CHANNEL_NARRATIVE, "Showing Active Randomize Features:");
  5173. if (flags > 0) {
  5174. if (flags & RANDOMIZE_GENDER)
  5175. SimpleMessage(CHANNEL_NARRATIVE, "- Gender");
  5176. if (flags & RANDOMIZE_RACE)
  5177. SimpleMessage(CHANNEL_NARRATIVE, "- Race");
  5178. if (flags & RANDOMIZE_MODEL_TYPE)
  5179. SimpleMessage(CHANNEL_NARRATIVE, "- Model");
  5180. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  5181. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair");
  5182. if (flags & RANDOMIZE_HAIR_TYPE)
  5183. SimpleMessage(CHANNEL_NARRATIVE, "- Hair");
  5184. if (flags & RANDOMIZE_WING_TYPE)
  5185. SimpleMessage(CHANNEL_NARRATIVE, "- Wing");
  5186. if (flags & RANDOMIZE_CHEEK_TYPE)
  5187. SimpleMessage(CHANNEL_NARRATIVE, "- Cheek");
  5188. if (flags & RANDOMIZE_CHIN_TYPE)
  5189. SimpleMessage(CHANNEL_NARRATIVE, "- Chin");
  5190. if (flags & RANDOMIZE_EAR_TYPE)
  5191. SimpleMessage(CHANNEL_NARRATIVE, "- Ear");
  5192. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  5193. SimpleMessage(CHANNEL_NARRATIVE, "- Eyebrow");
  5194. if (flags & RANDOMIZE_EYE_TYPE)
  5195. SimpleMessage(CHANNEL_NARRATIVE, "- Eye");
  5196. if (flags & RANDOMIZE_LIP_TYPE)
  5197. SimpleMessage(CHANNEL_NARRATIVE, "- Lip");
  5198. if (flags & RANDOMIZE_NOSE_TYPE)
  5199. SimpleMessage(CHANNEL_NARRATIVE, "- Nose");
  5200. if (flags & RANDOMIZE_EYE_COLOR)
  5201. SimpleMessage(CHANNEL_NARRATIVE, "- Eye Color");
  5202. if (flags & RANDOMIZE_HAIR_COLOR1)
  5203. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color1");
  5204. if (flags & RANDOMIZE_HAIR_COLOR2)
  5205. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color2");
  5206. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  5207. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color Highlights");
  5208. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  5209. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color");
  5210. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  5211. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color Highlights");
  5212. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  5213. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Color");
  5214. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  5215. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Highlights");
  5216. if (flags & RANDOMIZE_SKIN_COLOR)
  5217. SimpleMessage(CHANNEL_NARRATIVE, "- Skin Color");
  5218. if (flags & RANDOMIZE_WING_COLOR1)
  5219. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color1");
  5220. if (flags & RANDOMIZE_WING_COLOR2)
  5221. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color2");
  5222. }
  5223. else
  5224. {
  5225. SimpleMessage(CHANNEL_NARRATIVE, "- No Randomization Set.");
  5226. }
  5227. }
  5228. void Client::GiveQuestReward(Quest* quest) {
  5229. current_quest_id = 0;
  5230. MPendingQuestAccept.lock();
  5231. pending_quest_accept.push_back(quest);
  5232. MPendingQuestAccept.unlock();
  5233. quest->IncrementCompleteCount();
  5234. player->AddCompletedQuest(quest);
  5235. DisplayQuestComplete(quest);
  5236. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5237. SendQuestJournal();
  5238. player->RemoveQuest(quest->GetQuestID(), false);
  5239. if (quest->GetExpReward() > 0) {
  5240. int16 level = player->GetLevel();
  5241. int32 xp = quest->GetExpReward();
  5242. if (player->AddXP(xp)) {
  5243. Message(CHANNEL_REWARD, "You gain %u experience!", (int32)xp);
  5244. if (player->GetLevel() != level)
  5245. ChangeLevel(level, player->GetLevel());
  5246. player->SetCharSheetChanged(true);
  5247. }
  5248. }
  5249. if (quest->GetTSExpReward() > 0) {
  5250. int8 ts_level = player->GetTSLevel();
  5251. int32 xp = quest->GetTSExpReward();
  5252. if (player->AddTSXP(xp)) {
  5253. Message(CHANNEL_REWARD, "You gain %u tradeskill experience!", (int32)xp);
  5254. if (player->GetTSLevel() != ts_level)
  5255. ChangeTSLevel(ts_level, player->GetTSLevel());
  5256. player->SetCharSheetChanged(true);
  5257. }
  5258. }
  5259. int64 total_coins = quest->GetGeneratedCoin();
  5260. if (total_coins > 0) {
  5261. player->AddCoins(total_coins);
  5262. PlaySound("coin_cha_ching");
  5263. char tmp[64] = { 0 };
  5264. string message = "You receive ";
  5265. int32 val = 0;
  5266. if (total_coins >= 1000000) {
  5267. val = total_coins / 1000000;
  5268. total_coins -= 1000000 * val;
  5269. sprintf(tmp, "%u Platinum ", val);
  5270. message.append(tmp);
  5271. memset(tmp, 0, 64);
  5272. }
  5273. if (total_coins >= 10000) {
  5274. val = total_coins / 10000;
  5275. total_coins -= 10000 * val;
  5276. sprintf(tmp, "%u Gold ", val);
  5277. message.append(tmp);
  5278. memset(tmp, 0, 64);
  5279. }
  5280. if (total_coins >= 100) {
  5281. val = total_coins / 100;
  5282. total_coins -= 100 * val;
  5283. sprintf(tmp, "%u Silver ", val);
  5284. message.append(tmp);
  5285. memset(tmp, 0, 64);
  5286. }
  5287. if (total_coins > 0) {
  5288. sprintf(tmp, "%u Copper ", (int32)total_coins);
  5289. message.append(tmp);
  5290. }
  5291. message.append("for completing ").append(quest->GetName());
  5292. int8 type = CHANNEL_LOOT;
  5293. SimpleMessage(type, message.c_str());
  5294. }
  5295. if (quest->GetQuestGiver() > 0)
  5296. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  5297. RemovePlayerQuest(quest->GetQuestID(), true, false);
  5298. }
  5299. void Client::DisplayConversation(int32 conversation_id, int32 spawn_id, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2) {
  5300. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  5301. if (packet) {
  5302. packet->setDataByName("conversation_id", conversation_id);
  5303. packet->setDataByName("text", text);
  5304. packet->setDataByName("unknown2", 1);
  5305. conversation_map[conversation_id].clear();
  5306. if (conversations) {
  5307. packet->setArrayLengthByName("num_responses", conversations->size());
  5308. for (int32 i = 0; i < conversations->size(); i++) {
  5309. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  5310. if (conversations->at(i).function.length() > 0)
  5311. conversation_map[conversation_id][i] = conversations->at(i).function;
  5312. }
  5313. }
  5314. packet->setDataByName("spawn_id", spawn_id);
  5315. if (mp3) {
  5316. packet->setDataByName("voice", mp3);
  5317. packet->setDataByName("key1", key1);
  5318. packet->setDataByName("key2", key2);
  5319. }
  5320. QueuePacket(packet->serialize());
  5321. safe_delete(packet);
  5322. }
  5323. }
  5324. void Client::DisplayConversation(Item* item, vector<ConversationOption>* conversations, const char* text, int8 type, const char* mp3, int32 key1, int32 key2) {
  5325. if (!item || !text || !conversations || conversations->size() == 0) {
  5326. return;
  5327. }
  5328. int32 conversation_id = GetConversationID(0, item);
  5329. if (conversation_id == 0) {
  5330. next_conversation_id++;
  5331. conversation_id = next_conversation_id;
  5332. }
  5333. conversation_items[conversation_id] = item;
  5334. if (type == 4)
  5335. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2);
  5336. else
  5337. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2);
  5338. }
  5339. void Client::DisplayConversation(Entity* npc, int8 type, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2) {
  5340. if (!npc || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  5341. return;
  5342. }
  5343. int32 conversation_id = GetConversationID(npc, 0);
  5344. if (conversation_id == 0) {
  5345. next_conversation_id++;
  5346. conversation_id = next_conversation_id;
  5347. }
  5348. conversation_spawns[conversation_id] = npc;
  5349. /* NPCs can start two different types of conversations.
  5350. * Type 1: The chat type with bubbles.
  5351. * Type 2: The dialog type with the blue box. */
  5352. if (type == 1)
  5353. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(npc), conversations, text, mp3, key1, key2);
  5354. else if (type == 2)
  5355. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2);
  5356. else //if (type == 3)
  5357. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2);
  5358. }
  5359. void Client::CloseDialog(int32 conversation_id) {
  5360. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  5361. if (packet) {
  5362. packet->setDataByName("conversation_id", conversation_id);
  5363. QueuePacket(packet->serialize());
  5364. safe_delete(packet);
  5365. }
  5366. conversation_items.erase(conversation_id);
  5367. conversation_spawns.erase(conversation_id);
  5368. }
  5369. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  5370. int32 conversation_id = 0;
  5371. if (spawn) {
  5372. map<int32, Spawn*>::iterator itr;
  5373. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  5374. if (itr->second == spawn) {
  5375. conversation_id = itr->first;
  5376. break;
  5377. }
  5378. }
  5379. }
  5380. else if (item) {
  5381. map<int32, Item*>::iterator itr;
  5382. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  5383. if (itr->second == item) {
  5384. conversation_id = itr->first;
  5385. break;
  5386. }
  5387. }
  5388. }
  5389. return conversation_id;
  5390. }
  5391. Spawn* Client::GetCombineSpawn() {
  5392. return combine_spawn;
  5393. }
  5394. bool Client::ShouldTarget() {
  5395. return should_target;
  5396. }
  5397. void Client::TargetSpawn(Spawn* spawn) {
  5398. should_target = false;
  5399. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  5400. if (packet) {
  5401. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  5402. QueuePacket(packet->serialize());
  5403. safe_delete(packet);
  5404. }
  5405. }
  5406. void Client::CombineSpawns(float radius, Spawn* spawn) {
  5407. combine_spawn = spawn;
  5408. spawn->RemoveSpawnFromGroup(true);
  5409. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  5410. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  5411. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5412. should_target = true;
  5413. }
  5414. void Client::AddCombineSpawn(Spawn* spawn) {
  5415. if (combine_spawn && combine_spawn != spawn && spawn) {
  5416. combine_spawn->AddSpawnToGroup(spawn);
  5417. spawn->AddSpawnToGroup(combine_spawn);
  5418. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5419. }
  5420. else if (spawn)
  5421. combine_spawn = spawn;
  5422. should_target = true;
  5423. }
  5424. void Client::RemoveCombineSpawn(Spawn* spawn) {
  5425. if (combine_spawn && spawn)
  5426. spawn->RemoveSpawnFromGroup();
  5427. if (combine_spawn == spawn)
  5428. combine_spawn->RemoveSpawnFromGroup(true);
  5429. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5430. if (combine_spawn == spawn)
  5431. combine_spawn = 0;
  5432. }
  5433. void Client::SaveCombineSpawns(const char* name) {
  5434. if (!combine_spawn) {
  5435. return;
  5436. }
  5437. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  5438. if (!spawns) {
  5439. return;
  5440. }
  5441. int32 count = spawns->size();
  5442. int32 spawnLocationID = 0;
  5443. if (count == 1)
  5444. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  5445. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  5446. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  5447. // we remove the spawn inside SaveCombinedSpawnLocation
  5448. //GetCurrentZone()->RemoveSpawn(combine_spawn);
  5449. }
  5450. else
  5451. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  5452. safe_delete(spawns);
  5453. combine_spawn = 0;
  5454. }
  5455. bool Client::AddItem(int32 item_id, int16 quantity) {
  5456. Item* master_item = master_item_list.GetItem(item_id);
  5457. Item* item = 0;
  5458. if (master_item)
  5459. item = new Item(master_item);
  5460. if (item) {
  5461. if (quantity > 0)
  5462. item->details.count = quantity;
  5463. return AddItem(item);
  5464. }
  5465. else
  5466. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  5467. return false;
  5468. }
  5469. bool Client::AddItem(Item* item) {
  5470. if (!item) {
  5471. return false;
  5472. }
  5473. if (item->IsBag()) {
  5474. if (GetVersion() <= 283 && item->details.num_slots > CLASSIC_EQ_MAX_BAG_SLOTS)
  5475. item->details.num_slots = CLASSIC_EQ_MAX_BAG_SLOTS;
  5476. }
  5477. if (player->AddItem(item)) {
  5478. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5479. if (outapp) {
  5480. //DumpPacket(outapp);
  5481. QueuePacket(outapp);
  5482. //resend bag desc with new item name added
  5483. outapp = player->SendBagUpdate(item->details.unique_id, GetVersion());
  5484. if (outapp) {
  5485. //DumpPacket(outapp);
  5486. QueuePacket(outapp);
  5487. }
  5488. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  5489. DumpPacket(app);
  5490. client->QueuePacket(app);
  5491. */
  5492. }
  5493. CheckPlayerQuestsItemUpdate(item);
  5494. if (item->GetItemScript() && lua_interface)
  5495. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  5496. }
  5497. else {
  5498. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  5499. safe_delete(item);
  5500. return false;
  5501. }
  5502. return true;
  5503. }
  5504. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  5505. Item* master_item = master_item_list.GetItem(item_id);
  5506. Item* item = 0;
  5507. if (master_item)
  5508. item = new Item(master_item);
  5509. if (item) {
  5510. if (quantity > 0)
  5511. item->details.count = quantity;
  5512. return AddItemToBank(item);
  5513. }
  5514. else
  5515. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  5516. return false;
  5517. }
  5518. bool Client::AddItemToBank(Item* item) {
  5519. if (!item) {
  5520. return false;
  5521. }
  5522. if (player->AddItemToBank(item)) {
  5523. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5524. if (outapp) {
  5525. QueuePacket(outapp);
  5526. //resend bag desc with new item name added
  5527. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  5528. if (outapp)
  5529. QueuePacket(outapp);
  5530. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  5531. DumpPacket(app);
  5532. client->QueuePacket(app);
  5533. */
  5534. }
  5535. CheckPlayerQuestsItemUpdate(item);
  5536. if (item->GetItemScript() && lua_interface)
  5537. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  5538. }
  5539. else {
  5540. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  5541. safe_delete(item);
  5542. return false;
  5543. }
  5544. return true;
  5545. }
  5546. bool Client::RemoveItem(Item* item, int16 quantity) {
  5547. EQ2Packet* outapp;
  5548. bool delete_item = false;
  5549. assert(item);
  5550. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  5551. item->details.count -= quantity;
  5552. item->save_needed = true;
  5553. }
  5554. else {
  5555. database.DeleteItem(character_id, item, 0);
  5556. player->GetPlayerItemList()->RemoveItem(item, false);
  5557. delete_item = true;
  5558. }
  5559. if ((outapp = player->SendInventoryUpdate(version))) {
  5560. QueuePacket(outapp);
  5561. if (item->GetItemScript() && lua_interface)
  5562. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  5563. if (delete_item)
  5564. safe_delete(item);
  5565. return true;
  5566. }
  5567. return false;
  5568. }
  5569. void Client::SetLuaDebugClient(bool val) {
  5570. if (val)
  5571. lua_debug_timer.Start();
  5572. lua_debug = val;
  5573. if (lua_interface && !val) {
  5574. lua_interface->RemoveDebugClients(this);
  5575. lua_debug_timer.Disable();
  5576. }
  5577. }
  5578. void Client::SetMerchantTransaction(Spawn* spawn) {
  5579. merchant_transaction = spawn;
  5580. }
  5581. Spawn* Client::GetMerchantTransaction() {
  5582. return merchant_transaction;
  5583. }
  5584. void Client::SetMailTransaction(Spawn* spawn) {
  5585. mail_transaction = spawn;
  5586. mail_window.coin_copper = 0;
  5587. mail_window.coin_silver = 0;
  5588. mail_window.coin_gold = 0;
  5589. mail_window.coin_plat = 0;
  5590. mail_window.char_item_id = 0;
  5591. }
  5592. Spawn* Client::GetMailTransaction() {
  5593. return mail_transaction;
  5594. }
  5595. void Client::PlaySound(const char* name) {
  5596. if (name) {
  5597. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  5598. if (packet) {
  5599. packet->setMediumStringByName("name", name);
  5600. QueuePacket(packet->serialize());
  5601. safe_delete(packet);
  5602. }
  5603. }
  5604. }
  5605. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  5606. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  5607. if(multiplier){
  5608. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  5609. float diff_low = faction_val - multiplier->faction_min;
  5610. if(diff_low < 0)
  5611. diff_low*=-1;
  5612. float total_diff = multiplier->faction_max - multiplier->faction_min;
  5613. if(total_diff < 0)
  5614. total_diff*=-1;
  5615. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  5616. float total1 = (diff_low/total_diff);
  5617. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  5618. return final_buy_multiplier;
  5619. }*/
  5620. return 1;
  5621. }
  5622. float Client::CalculateSellMultiplier(int32 merchant_id) {
  5623. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  5624. if(multiplier){
  5625. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  5626. float diff_low = faction_val - multiplier->faction_min;
  5627. if(diff_low < 0)
  5628. diff_low*=-1;
  5629. float total_diff = multiplier->faction_max - multiplier->faction_min;
  5630. if(total_diff < 0)
  5631. total_diff*=-1;
  5632. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  5633. float total1 = (diff_low/total_diff);
  5634. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  5635. return final_sell_multiplier;
  5636. }*/
  5637. return 1;
  5638. }
  5639. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  5640. Spawn* spawn = GetMerchantTransaction();
  5641. Guild* guild = GetPlayer()->GetGuild();
  5642. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5643. int32 total_sell_price = 0;
  5644. int32 total_status_sell_price = 0; //for status
  5645. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  5646. int32 sell_price = 0;
  5647. int32 status_sell_price = 0; //for status
  5648. Item* master_item = master_item_list.GetItem(item_id);
  5649. Item* item = 0;
  5650. if (unique_id == 0)
  5651. item = player->item_list.GetItemFromID(item_id, quantity);
  5652. else
  5653. item = player->item_list.GetItemFromUniqueID(unique_id);
  5654. if (!item)
  5655. player->item_list.GetItemFromID(item_id);
  5656. if (item && master_item) {
  5657. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  5658. if (sell_price > item->sell_price)
  5659. sell_price = item->sell_price;
  5660. if (quantity > item->details.count)
  5661. quantity = item->details.count;
  5662. total_sell_price = sell_price * quantity;
  5663. //------------------------------For Selling Status Items
  5664. status_sell_price = (int32)(master_item->sell_status * multiplier);
  5665. if (status_sell_price > item->sell_status)
  5666. status_sell_price = item->sell_status;
  5667. if (quantity > item->details.count)
  5668. quantity = item->details.count;
  5669. if (player->GetGuild()) {
  5670. total_status_sell_price = status_sell_price * quantity;
  5671. player->GetInfoStruct()->status_points += total_status_sell_price;
  5672. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  5673. guild->SendGuildMemberList();
  5674. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  5675. }
  5676. if (quantity > 1)
  5677. Message(CHANNEL_MERCHANT_BUY_SELL, "You sell %i %s to %s for %s.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str());
  5678. else
  5679. Message(CHANNEL_MERCHANT_BUY_SELL, "You sell %s to %s for %s.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str());
  5680. player->AddCoins(total_sell_price);
  5681. AddBuyBack(unique_id, item_id, quantity, sell_price);
  5682. if (quantity >= item->details.count) {
  5683. database.DeleteItem(GetCharacterID(), item, 0);
  5684. player->item_list.DestroyItem(item->details.index);
  5685. }
  5686. else {
  5687. item->details.count -= quantity;
  5688. item->save_needed = true;
  5689. }
  5690. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5691. if (outapp)
  5692. QueuePacket(outapp);
  5693. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY))
  5694. SendSellMerchantList();
  5695. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  5696. SendBuyBackList();
  5697. }
  5698. }
  5699. }
  5700. void Client::BuyBack(int32 item_id, int16 quantity) {
  5701. Spawn* spawn = GetMerchantTransaction();
  5702. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5703. deque<BuyBackItem*>::iterator itr;
  5704. BuyBackItem* buyback = 0;
  5705. BuyBackItem* closest = 0;
  5706. MBuyBack.readlock(__FUNCTION__, __LINE__);
  5707. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  5708. buyback = *itr;
  5709. if (buyback->unique_id == item_id) {
  5710. closest = buyback;
  5711. quantity = buyback->quantity;
  5712. break;
  5713. }
  5714. }
  5715. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  5716. if (closest) {
  5717. Item* item = 0;
  5718. Item* master_item = master_item_list.GetItem(closest->item_id);
  5719. if (master_item) {
  5720. item = new Item(master_item);
  5721. if (closest->quantity >= quantity)
  5722. item->details.count = quantity;
  5723. else
  5724. item->details.count = closest->quantity;
  5725. }
  5726. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  5727. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  5728. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  5729. bool removed = false;
  5730. if (closest->quantity == quantity) {
  5731. MBuyBack.writelock(__FUNCTION__, __LINE__);
  5732. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  5733. if (*itr == closest) {
  5734. buy_back_items.erase(itr);
  5735. removed = true;
  5736. break;
  5737. }
  5738. }
  5739. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  5740. }
  5741. else {
  5742. closest->quantity -= quantity;
  5743. closest->save_needed = true;
  5744. }
  5745. AddItem(item);
  5746. //EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5747. //if(outapp)
  5748. //QueuePacket(outapp);
  5749. if (removed) {
  5750. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  5751. safe_delete(closest);
  5752. }
  5753. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY))
  5754. SendSellMerchantList();
  5755. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  5756. SendBuyBackList();
  5757. }
  5758. else
  5759. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  5760. }
  5761. }
  5762. }
  5763. void Client::BuyItem(int32 item_id, int16 quantity) {
  5764. // Get the merchant we are buying from
  5765. Spawn* spawn = GetMerchantTransaction();
  5766. // Make sure the spawn has a merchant list
  5767. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5768. int32 total_buy_price = 0;
  5769. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  5770. int32 sell_price = 0;
  5771. Item* master_item = master_item_list.GetItem(item_id);
  5772. Item* item = 0;
  5773. int16 total_available = 0;
  5774. vector<MerchantItemInfo>* temp;
  5775. vector<MerchantItemInfo>::iterator itr;
  5776. MerchantItemInfo* ItemInfo = 0;
  5777. temp = world.GetMerchantList(spawn->GetMerchantID());
  5778. for (itr = temp->begin(); itr != temp->end(); itr++) {
  5779. if ((*itr).item_id == item_id) {
  5780. ItemInfo = &(*itr);
  5781. break;
  5782. }
  5783. }
  5784. if (master_item && ItemInfo) {
  5785. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  5786. quantity = 1;
  5787. total_available = 0xFFFF;
  5788. sell_price = master_item->sell_price;
  5789. }
  5790. else {
  5791. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  5792. sell_price = (int32)(master_item->sell_price * multiplier);
  5793. if (quantity > total_available)
  5794. quantity = total_available;
  5795. }
  5796. total_buy_price = sell_price * quantity;
  5797. item = new Item(master_item);
  5798. item->details.count = quantity;
  5799. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  5800. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  5801. safe_delete(item);
  5802. }
  5803. else {
  5804. // Price not set in the merchant_inventory table, use the old method
  5805. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  5806. if (player->RemoveCoins(total_buy_price)) {
  5807. item->SetMaxSellValue(sell_price);
  5808. if (quantity > 1)
  5809. Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %i %s from %s for%s.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_buy_price).c_str());
  5810. else
  5811. Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %s from %s for%s.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_buy_price).c_str());
  5812. AddItem(item);
  5813. CheckPlayerQuestsItemUpdate(item);
  5814. if (item && total_available < 0xFFFF) {
  5815. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  5816. SendBuyMerchantList();
  5817. }
  5818. //EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5819. //if(outapp)
  5820. // QueuePacket(outapp);
  5821. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) && !(spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  5822. SendSellMerchantList();
  5823. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  5824. PlayLotto(total_buy_price, item->details.item_id);
  5825. }
  5826. else {
  5827. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  5828. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  5829. PlaySound("buy_failed");
  5830. }
  5831. }
  5832. else {
  5833. // Price set in merchant_inventory table
  5834. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  5835. // TODO: need to add support for station cash
  5836. if (player->GetInfoStruct()->status_points >= ItemInfo->price_status && player->HasCoins(ItemInfo->price_coins * quantity)) {
  5837. // Check items
  5838. int16 item_quantity = 0;
  5839. // Default these to true in case price_item_id or price_item2_id was never set
  5840. bool hasItem1 = true;
  5841. bool hasItem2 = true;
  5842. Item* tempItem1 = 0;
  5843. Item* tempItem2 = 0;
  5844. if (ItemInfo->price_item_id != 0) {
  5845. // Same item for whatever reason lets add the quantities together
  5846. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  5847. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  5848. else
  5849. item_quantity = ItemInfo->price_item_qty;
  5850. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  5851. if (tempItem1) {
  5852. if (tempItem1->details.count < item_quantity)
  5853. hasItem1 = false;
  5854. }
  5855. else {
  5856. hasItem1 = false;
  5857. }
  5858. }
  5859. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  5860. // as item1 and we already checked for it so we can skip this check
  5861. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  5862. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  5863. if (tempItem2) {
  5864. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  5865. hasItem2 = false;
  5866. }
  5867. else {
  5868. hasItem2 = false;
  5869. }
  5870. }
  5871. // if we have every thing then remove the price and give the item
  5872. if (hasItem1 && hasItem2) {
  5873. player->GetInfoStruct()->status_points -= ItemInfo->price_status;
  5874. // TODO: station cash
  5875. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  5876. // so there is no need to send it more then that one time
  5877. if (tempItem1) {
  5878. if (tempItem1->details.count > item_quantity) {
  5879. tempItem1->details.count -= item_quantity;
  5880. tempItem1->save_needed = true;
  5881. }
  5882. else {
  5883. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  5884. player->item_list.DestroyItem(tempItem1->details.index);
  5885. }
  5886. }
  5887. if (tempItem2) {
  5888. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  5889. tempItem2->details.count -= ItemInfo->price_item2_qty;
  5890. tempItem2->save_needed = true;
  5891. }
  5892. else {
  5893. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  5894. player->item_list.DestroyItem(tempItem2->details.index);
  5895. }
  5896. }
  5897. // 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
  5898. player->RemoveCoins(ItemInfo->price_coins * quantity);
  5899. item->SetMaxSellValue(sell_price);
  5900. if (quantity > 1)
  5901. Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %i %s from %s for%s.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(ItemInfo->price_coins * quantity).c_str());
  5902. else
  5903. Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %s from %s for%s.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(ItemInfo->price_coins * quantity).c_str());
  5904. AddItem(item);
  5905. CheckPlayerQuestsItemUpdate(item);
  5906. if (item && total_available < 0xFFFF) {
  5907. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  5908. SendBuyMerchantList();
  5909. }
  5910. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) && !(spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  5911. SendSellMerchantList();
  5912. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  5913. PlayLotto(total_buy_price, item->details.item_id);
  5914. }
  5915. else {
  5916. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  5917. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  5918. PlaySound("buy_failed");
  5919. }
  5920. }
  5921. else {
  5922. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  5923. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  5924. PlaySound("buy_failed");
  5925. }
  5926. }
  5927. }
  5928. }
  5929. }
  5930. }
  5931. void Client::RepairItem(int32 item_id) {
  5932. Spawn* spawn = GetMerchantTransaction();
  5933. if (spawn) {
  5934. Item* item = player->item_list.GetItemFromID(item_id);
  5935. if (!item)
  5936. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  5937. if (item) {
  5938. int32 repair_cost = item->CalculateRepairCost();
  5939. if (player->RemoveCoins((int32)repair_cost)) {
  5940. item->generic_info.condition = 100;
  5941. item->save_needed = true;
  5942. QueuePacket(player->GetEquipmentList()->serialize(GetVersion()));
  5943. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  5944. QueuePacket(item->serialize(version, false, player));
  5945. Message(CHANNEL_MERCHANT, "You give %s %s to repair your %s.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->CreateItemLink(GetVersion()).c_str());
  5946. PlaySound("coin_cha_ching");
  5947. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  5948. SendRepairList();
  5949. }
  5950. else {
  5951. LogWrite(MISC__TODO, 1, "TODO", " Send pop up that says 'Not enough coin.'\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  5952. Message(CHANNEL_MERCHANT, "You do not have enough coin to repair %s.", item->CreateItemLink(GetVersion()).c_str());
  5953. PlaySound("buy_failed");
  5954. }
  5955. }
  5956. }
  5957. }
  5958. void Client::RepairAllItems() {
  5959. Spawn* spawn = GetMerchantTransaction();
  5960. if (spawn) {
  5961. vector<Item*>* repairable_items = GetRepairableItems();
  5962. if (repairable_items && repairable_items->size() > 0) {
  5963. vector<Item*>::iterator itr;
  5964. int64 total_cost = 0;
  5965. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  5966. total_cost += (*itr)->CalculateRepairCost();
  5967. if (player->RemoveCoins((int32)total_cost)) {
  5968. Message(CHANNEL_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  5969. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  5970. Item* item = *itr;
  5971. if (item) {
  5972. item->generic_info.condition = 100;
  5973. item->save_needed = true;
  5974. QueuePacket(item->serialize(version, false, player));
  5975. Message(CHANNEL_COLOR_YELLOW, "Repaired: %s.", item->CreateItemLink(GetVersion()).c_str());
  5976. }
  5977. }
  5978. QueuePacket(player->GetEquipmentList()->serialize(GetVersion()));
  5979. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  5980. PlaySound("coin_cha_ching");
  5981. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  5982. SendRepairList();
  5983. }
  5984. else {
  5985. LogWrite(MISC__TODO, 1, "TODO", "Send pop up that says 'Not enough coin.'\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  5986. SimpleMessage(CHANNEL_MERCHANT, "You do not have enough coin to repair all of your items.");
  5987. PlaySound("buy_failed");
  5988. }
  5989. }
  5990. safe_delete(repairable_items);
  5991. }
  5992. }
  5993. void Client::SendAchievementsList()
  5994. {
  5995. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  5996. map<int32, Achievement *>::iterator itr;
  5997. Achievement *achievement;
  5998. vector<AchievementRequirements *> *requirements = 0;
  5999. vector<AchievementRequirements *>::iterator itr2;
  6000. AchievementRequirements *requirement;
  6001. vector<AchievementRewards *> *rewards = 0;
  6002. vector<AchievementRewards *>::iterator itr3;
  6003. AchievementRewards *reward;
  6004. PacketStruct *packet;
  6005. int16 i = 0;
  6006. int16 j = 0;
  6007. int16 k = 0;
  6008. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  6009. return;
  6010. }
  6011. packet->setArrayLengthByName("num_achievements" , achievements->size());
  6012. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  6013. achievement = itr->second;
  6014. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  6015. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  6016. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  6017. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  6018. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  6019. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  6020. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  6021. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  6022. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  6023. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  6024. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  6025. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  6026. requirements = achievement->GetRequirements();
  6027. rewards = achievement->GetRewards();
  6028. j = 0;
  6029. k = 0;
  6030. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  6031. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  6032. requirement = *itr2;
  6033. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  6034. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  6035. j++;
  6036. }
  6037. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  6038. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  6039. reward = *itr3;
  6040. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  6041. k++;
  6042. }
  6043. i++;
  6044. }
  6045. //packet->PrintPacket();
  6046. EQ2Packet* data = packet->serialize();
  6047. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  6048. safe_delete(packet);
  6049. safe_delete(data);
  6050. //DumpPacket(app);
  6051. QueuePacket(app);*/
  6052. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  6053. SendAchievementUpdate(true);
  6054. }
  6055. void Client::SendAchievementUpdate(bool first_login) {
  6056. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  6057. map<int32, AchievementUpdate*>::iterator itr;
  6058. AchievementUpdate* update;
  6059. vector<AchievementUpdateItems*>* update_items = 0;
  6060. vector<AchievementUpdateItems*>::iterator itr2;
  6061. AchievementUpdateItems* update_item;
  6062. int16 i = 0;
  6063. int16 j = 0;
  6064. PacketStruct* packet;
  6065. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  6066. return;
  6067. }
  6068. packet->setDataByName("unknown1", first_login ? 1 : 0);
  6069. packet->setArrayLengthByName("num_achievements", updates->size());
  6070. for (itr = updates->begin(); itr != updates->end(); itr++) {
  6071. update = itr->second;
  6072. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  6073. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  6074. update_items = update->GetUpdateItems();
  6075. j = 0;
  6076. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  6077. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  6078. update_item = *itr2;
  6079. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  6080. j++;
  6081. }
  6082. i++;
  6083. }
  6084. //packet->PrintPacket();
  6085. EQ2Packet* data = packet->serialize();
  6086. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  6087. safe_delete(packet);
  6088. safe_delete(data);
  6089. //DumpPacket(app);
  6090. QueuePacket(app);
  6091. }
  6092. void Client::SendBuyMerchantList(bool sell) {
  6093. Spawn* spawn = GetMerchantTransaction();
  6094. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6095. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  6096. if (items) {
  6097. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6098. if (packet) {
  6099. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6100. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6101. packet->setArrayLengthByName("num_items", items->size());
  6102. vector<MerchantItemInfo>::iterator itr;
  6103. sint8 item_difficulty = 0;
  6104. int32 sell_price = 0;
  6105. int i = 0;
  6106. int tmp_level = 0;
  6107. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  6108. MerchantItemInfo ItemInfo = *itr;
  6109. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  6110. if (!item)
  6111. continue;
  6112. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6113. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6114. packet->setArrayDataByName("stack_size", item->stack_count, i);
  6115. packet->setArrayDataByName("icon", item->details.icon, i);
  6116. if (item->generic_info.adventure_default_level > 0)
  6117. tmp_level = item->generic_info.adventure_default_level;
  6118. else
  6119. tmp_level = item->generic_info.tradeskill_default_level;
  6120. packet->setArrayDataByName("level", tmp_level, i);
  6121. packet->setArrayDataByName("tier", item->details.tier, i);
  6122. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6123. item_difficulty = player->GetArrowColor(tmp_level);
  6124. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6125. item_difficulty = ARROW_COLOR_WHITE;
  6126. item_difficulty -= 6;
  6127. if (item_difficulty < 0)
  6128. item_difficulty *= -1;
  6129. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6130. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  6131. packet->setArrayDataByName("unknown5", 255, i);
  6132. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  6133. if (GetVersion() <= 1096)
  6134. packet->setArrayDataByName("description", item->description.c_str(), i);
  6135. // If no price set in the merchant_inventory table then use the old method
  6136. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  6137. sell_price = (int32)(item->sell_price * multiplier);
  6138. packet->setArrayDataByName("price", sell_price, i);
  6139. }
  6140. else {
  6141. int8 count = 0;
  6142. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  6143. count++;
  6144. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  6145. count++;
  6146. if (count != 0) {
  6147. packet->setSubArrayLengthByName("num_tokens", count, i);
  6148. int8 index = 0;
  6149. Item* token = 0;
  6150. if (ItemInfo.price_item_id != 0) {
  6151. token = master_item_list.GetItem(ItemInfo.price_item_id);
  6152. if (item) {
  6153. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  6154. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  6155. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  6156. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  6157. }
  6158. token = 0;
  6159. index++;
  6160. }
  6161. if (ItemInfo.price_item2_id != 0) {
  6162. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  6163. if (item) {
  6164. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  6165. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  6166. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  6167. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  6168. }
  6169. }
  6170. }
  6171. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  6172. packet->setArrayDataByName("status", ItemInfo.price_status, i);
  6173. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  6174. }
  6175. }
  6176. if (GetVersion() <= 546) {
  6177. //buy is 0 so dont need to set it
  6178. if (sell)
  6179. packet->setDataByName("type", 1);
  6180. }
  6181. else {
  6182. if (sell)
  6183. packet->setDataByName("type", 130);
  6184. else
  6185. packet->setDataByName("type", 2);
  6186. }
  6187. EQ2Packet* outapp = packet->serialize();
  6188. // DumpPacket(outapp);
  6189. QueuePacket(outapp);
  6190. safe_delete(packet);
  6191. }
  6192. safe_delete(items);
  6193. }
  6194. else {
  6195. // Need to send an empty packet in the event there is no item list, otherwise the
  6196. // last item list sent to the player will show for this merchant
  6197. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6198. if (packet) {
  6199. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6200. if (GetVersion() <= 546) {
  6201. //buy is 0 so dont need to set it
  6202. if (sell)
  6203. packet->setDataByName("type", 1);
  6204. }
  6205. else {
  6206. if (sell)
  6207. packet->setDataByName("type", 130);
  6208. else
  6209. packet->setDataByName("type", 2);
  6210. }
  6211. EQ2Packet* outapp = packet->serialize();
  6212. QueuePacket(outapp);
  6213. safe_delete(packet);
  6214. }
  6215. }
  6216. }
  6217. }
  6218. void Client::SendSellMerchantList(bool sell) {
  6219. Spawn* spawn = GetMerchantTransaction();
  6220. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6221. map<int32, Item*>* items = player->GetItemList();
  6222. if (items) {
  6223. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6224. if (packet) {
  6225. vector<Item*> sellable_items;
  6226. map<int32, Item*>::iterator test_itr;
  6227. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  6228. if (test_itr->second && !test_itr->second->CheckFlag(NO_VALUE))
  6229. sellable_items.push_back(test_itr->second);
  6230. }
  6231. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6232. packet->setArrayLengthByName("num_items", sellable_items.size());
  6233. vector<Item*>::iterator itr;
  6234. Item* item = 0;
  6235. sint8 item_difficulty = 0;
  6236. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  6237. int32 sell_price = 0;
  6238. Item* master_item = 0;
  6239. int i = 0;
  6240. int tmp_level = 0;
  6241. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  6242. item = *itr;
  6243. master_item = master_item_list.GetItem(item->details.item_id);
  6244. if (master_item)
  6245. sell_price = (int32)(master_item->sell_price * multiplier);
  6246. else
  6247. sell_price = 0;
  6248. if (sell_price > item->sell_price)
  6249. sell_price = item->sell_price;
  6250. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6251. string thename = item->name;
  6252. packet->setArrayDataByName("price", sell_price, i);
  6253. if (player->GetGuild()) {
  6254. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  6255. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  6256. }
  6257. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6258. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  6259. packet->setArrayDataByName("stack_size", item->details.count, i);
  6260. packet->setArrayDataByName("icon", item->details.icon, i);
  6261. if (item->generic_info.adventure_default_level > 0)
  6262. tmp_level = item->generic_info.adventure_default_level;
  6263. else
  6264. tmp_level = item->generic_info.tradeskill_default_level;
  6265. packet->setArrayDataByName("level", item->details.recommended_level, i);
  6266. packet->setArrayDataByName("tier", item->details.tier, i);
  6267. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6268. item_difficulty = player->GetArrowColor(tmp_level);
  6269. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6270. item_difficulty = ARROW_COLOR_WHITE;
  6271. item_difficulty -= 6;
  6272. if (item_difficulty < 0)
  6273. item_difficulty *= -1;
  6274. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6275. if (item->details.count == 1)
  6276. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6277. else
  6278. packet->setArrayDataByName("quantity", item->details.count, i);
  6279. packet->setArrayDataByName("stack_size2", item->details.count, i);
  6280. if (GetVersion() <= 1096)
  6281. packet->setArrayDataByName("description", item->description.c_str(), i);
  6282. }
  6283. if (GetVersion() <= 546) {
  6284. packet->setDataByName("type", 1);
  6285. }
  6286. else {
  6287. if (sell)
  6288. packet->setDataByName("type", 129);
  6289. else
  6290. packet->setDataByName("type", 1);
  6291. }
  6292. packet->setDataByName("unknown8a", 16256, 6);
  6293. packet->setDataByName("unknown8a", 16256, 10);
  6294. //packet->PrintPacket();
  6295. EQ2Packet* outapp = packet->serialize();
  6296. //DumpPacket(outapp);
  6297. QueuePacket(outapp);
  6298. safe_delete(packet);
  6299. }
  6300. safe_delete(items);
  6301. }
  6302. }
  6303. }
  6304. void Client::SendBuyBackList(bool sell) {
  6305. if (GetVersion() <= 546) //this wasn't added until LU37 on July 31st 2007, well after the DoF client
  6306. return;
  6307. Spawn* spawn = GetMerchantTransaction();
  6308. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6309. deque<BuyBackItem*>::iterator itr;
  6310. int i = 0;
  6311. Item* master_item = 0;
  6312. BuyBackItem* buyback = 0;
  6313. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6314. if (packet) {
  6315. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6316. packet->setArrayLengthByName("num_items", buy_back_items.size());
  6317. sint8 item_difficulty = 0;
  6318. MBuyBack.readlock(__FUNCTION__, __LINE__);
  6319. int tmp_level = 0;
  6320. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  6321. buyback = *itr;
  6322. master_item = master_item_list.GetItem(buyback->item_id);
  6323. if (master_item) {
  6324. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  6325. packet->setArrayDataByName("price", buyback->price, i);
  6326. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  6327. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  6328. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  6329. packet->setArrayDataByName("icon", master_item->details.icon, i);
  6330. if (master_item->generic_info.adventure_default_level > 0)
  6331. tmp_level = master_item->generic_info.adventure_default_level;
  6332. else
  6333. tmp_level = master_item->generic_info.tradeskill_default_level;
  6334. packet->setArrayDataByName("level", tmp_level, i);
  6335. packet->setArrayDataByName("tier", master_item->details.tier, i);
  6336. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  6337. item_difficulty = player->GetArrowColor(tmp_level);
  6338. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6339. item_difficulty = ARROW_COLOR_WHITE;
  6340. item_difficulty -= 6;
  6341. if (item_difficulty < 0)
  6342. item_difficulty *= -1;
  6343. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6344. if (buyback->quantity == 1)
  6345. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6346. else
  6347. packet->setArrayDataByName("quantity", buyback->quantity, i);
  6348. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  6349. if (GetVersion() <= 1096)
  6350. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  6351. }
  6352. }
  6353. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  6354. if (sell)
  6355. packet->setDataByName("type", 640);
  6356. else
  6357. packet->setDataByName("type", 512);
  6358. EQ2Packet* outapp = packet->serialize();
  6359. // DumpPacket(outapp);
  6360. QueuePacket(outapp);
  6361. safe_delete(packet);
  6362. }
  6363. }
  6364. }
  6365. void Client::SendRepairList() {
  6366. Spawn* spawn = GetMerchantTransaction();
  6367. if (spawn) {
  6368. vector<Item*>* repairable_items = GetRepairableItems();
  6369. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6370. if (packet) {
  6371. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6372. packet->setArrayLengthByName("num_items", repairable_items->size());
  6373. Item* item = 0;
  6374. sint8 item_difficulty = 0;
  6375. int32 i = 0;
  6376. vector<Item*>::iterator itr;
  6377. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  6378. item = *itr;
  6379. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6380. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  6381. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6382. packet->setArrayDataByName("stack_size", item->details.count, i);
  6383. packet->setArrayDataByName("icon", item->details.icon, i);
  6384. /*if (item->generic_info.adventure_default_level > 0)
  6385. tmp_level = item->generic_info.adventure_default_level;
  6386. else
  6387. tmp_level = item->generic_info.tradeskill_default_level;
  6388. packet->setArrayDataByName("level", tmp_level, i);*/
  6389. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  6390. packet->setArrayDataByName("tier", item->details.tier, i);
  6391. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6392. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  6393. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6394. item_difficulty = ARROW_COLOR_WHITE;
  6395. item_difficulty -= 6;
  6396. if (item_difficulty < 0)
  6397. item_difficulty *= -1;
  6398. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6399. if (item->details.count == 1)
  6400. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6401. else
  6402. packet->setArrayDataByName("quantity", item->details.count, i);
  6403. packet->setArrayDataByName("stack_size2", item->details.count, i);
  6404. if (GetVersion() <= 1096)
  6405. packet->setArrayDataByName("description", item->description.c_str(), i);
  6406. }
  6407. if (GetVersion() <= 546) {
  6408. packet->setDataByName("type", 16);
  6409. }
  6410. else {
  6411. packet->setDataByName("type", 96);
  6412. }
  6413. EQ2Packet* outapp = packet->serialize();
  6414. QueuePacket(outapp);
  6415. safe_delete(packet);
  6416. }
  6417. safe_delete(repairable_items);
  6418. }
  6419. }
  6420. void Client::ShowLottoWindow() {
  6421. Spawn* spawn = GetMerchantTransaction();
  6422. if (spawn) {
  6423. int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
  6424. if (!item_id)
  6425. {
  6426. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  6427. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  6428. return;
  6429. }
  6430. else if (item_id == 0)
  6431. {
  6432. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  6433. return;
  6434. }
  6435. Item* item = master_item_list.GetItem(item_id);
  6436. if (!item) {
  6437. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  6438. return;
  6439. }
  6440. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  6441. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6442. if (packet) {
  6443. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6444. packet->setArrayLengthByName("num_items", 1);
  6445. packet->setArrayDataByName("item_name", item->name.c_str());
  6446. packet->setArrayDataByName("price", item->sell_price);
  6447. packet->setArrayDataByName("item_id", item->details.item_id);
  6448. packet->setArrayDataByName("stack_size", item->details.count);
  6449. packet->setArrayDataByName("icon", item->details.icon);
  6450. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  6451. packet->setArrayDataByName("tier", item->details.tier);
  6452. packet->setArrayDataByName("item_id2", item->details.item_id);
  6453. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  6454. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6455. item_difficulty = ARROW_COLOR_WHITE;
  6456. item_difficulty -= 6;
  6457. if (item_difficulty < 0)
  6458. item_difficulty *= -1;
  6459. packet->setArrayDataByName("item_difficulty", item_difficulty);
  6460. //if(item->details.count == 1)
  6461. packet->setArrayDataByName("quantity", 0xFFFF);
  6462. //else
  6463. // packet->setArrayDataByName("quantity", item->details.count);
  6464. packet->setArrayDataByName("stack_size2", item->details.count);
  6465. packet->setArrayDataByName("description", item->description.c_str());
  6466. if (GetVersion() <= 546) {
  6467. packet->setDataByName("type", 128);
  6468. }
  6469. else {
  6470. packet->setDataByName("type", 0x00000102);
  6471. }
  6472. QueuePacket(packet->serialize());
  6473. safe_delete(packet);
  6474. }
  6475. }
  6476. }
  6477. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  6478. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  6479. if (packet) {
  6480. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  6481. int32 rolls[6] = { 0 };
  6482. int32 lottery_digits[6] = { 0 };
  6483. int8 num_matches = 0;
  6484. int64 jackpot = 0;
  6485. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  6486. if (!item) {
  6487. return;
  6488. }
  6489. database.DeleteItem(GetCharacterID(), item, 0);
  6490. GetPlayer()->item_list.RemoveItem(item, true);
  6491. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  6492. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  6493. if (!winning_numbers) {
  6494. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  6495. variables.AddVariable(winning_numbers);
  6496. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  6497. }
  6498. if (strlen(winning_numbers->GetValue()) != 12) {
  6499. winning_numbers->SetValue("231205182236");
  6500. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  6501. }
  6502. try {
  6503. for (int32 i = 0; i < 12; i += 2) {
  6504. char num[4];
  6505. strncpy(num, winning_numbers->GetValue() + i, 2);
  6506. lottery_digits[i / 2] = atoi(num);
  6507. }
  6508. }
  6509. catch (...) {
  6510. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  6511. return;
  6512. }
  6513. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  6514. if (!jackpot_var) {
  6515. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  6516. variables.AddVariable(jackpot_var);
  6517. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  6518. }
  6519. try {
  6520. jackpot = atoul(jackpot_var->GetValue());
  6521. if (jackpot < 10000)
  6522. jackpot = 10000;
  6523. }
  6524. catch (...) {
  6525. jackpot = 10000;
  6526. }
  6527. char new_jackpot[128] = { 0 };
  6528. sprintf(new_jackpot, "%llu", jackpot + price);
  6529. jackpot_var->SetValue(new_jackpot);
  6530. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  6531. world.PickRandomLottoDigits(rolls);
  6532. packet->setDataByName("roll_digit1", rolls[0]);
  6533. packet->setDataByName("roll_digit2", rolls[1]);
  6534. packet->setDataByName("roll_digit3", rolls[2]);
  6535. packet->setDataByName("roll_digit4", rolls[3]);
  6536. packet->setDataByName("roll_digit5", rolls[4]);
  6537. packet->setDataByName("roll_digit6", rolls[5]);
  6538. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  6539. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  6540. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  6541. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  6542. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  6543. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  6544. QueuePacket(packet->serialize());
  6545. safe_delete(packet);
  6546. for (int32 i = 0; i < 6; i++) {
  6547. for (int32 j = 0; j < 6; j++) {
  6548. if (rolls[i] == lottery_digits[j]) {
  6549. num_matches++;
  6550. break;
  6551. }
  6552. }
  6553. }
  6554. char new_jackpot_str[16];
  6555. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  6556. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  6557. if (num_matches == 6) {
  6558. world.PickRandomLottoDigits(lottery_digits);
  6559. for (int32 i = 0; i < 12; i += 2)
  6560. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  6561. winning_numbers->SetValue(new_jackpot_str);
  6562. jackpot_var->SetValue("10000");
  6563. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  6564. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  6565. }
  6566. }
  6567. }
  6568. void Client::SendGuildCreateWindow() {
  6569. if (GetVersion() <= 546) {
  6570. SimpleMessage(0, "Not implemented on this client...yet?");
  6571. }
  6572. else {
  6573. Spawn* spawn = GetPlayer()->GetTarget();
  6574. if (spawn) {
  6575. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6576. if (packet) {
  6577. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6578. packet->setArrayLengthByName("num_items", 0);
  6579. packet->setDataByName("type", 0x00008000);
  6580. QueuePacket(packet->serialize());
  6581. safe_delete(packet);
  6582. }
  6583. }
  6584. }
  6585. }
  6586. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  6587. BuyBackItem* item = new BuyBackItem;
  6588. item->item_id = item_id;
  6589. item->unique_id = unique_id;
  6590. item->price = price;
  6591. item->quantity = quantity;
  6592. item->save_needed = save_needed;
  6593. MBuyBack.writelock(__FUNCTION__, __LINE__);
  6594. buy_back_items.push_back(item);
  6595. if (buy_back_items.size() > 10) {
  6596. safe_delete(buy_back_items.front());
  6597. buy_back_items.pop_front();
  6598. }
  6599. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  6600. }
  6601. deque<BuyBackItem*>* Client::GetBuyBacks() {
  6602. return &buy_back_items;
  6603. }
  6604. vector<Item*>* Client::GetRepairableItems() {
  6605. vector<Item*>* repairable_items = new vector<Item*>;
  6606. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  6607. map<int32, Item*>* items = player->GetItemList();
  6608. if (equipped_items && equipped_items->size() > 0) {
  6609. for (int32 i = 0; i < equipped_items->size(); i++) {
  6610. Item* item = equipped_items->at(i);
  6611. if (item && item->generic_info.condition < 100)
  6612. repairable_items->push_back(item);
  6613. }
  6614. }
  6615. if (items && items->size() > 0) {
  6616. map<int32, Item*>::iterator itr;
  6617. for (itr = items->begin(); itr != items->end(); itr++) {
  6618. Item* item = itr->second;
  6619. if (item && item->generic_info.condition < 100)
  6620. repairable_items->push_back(item);
  6621. }
  6622. }
  6623. safe_delete(equipped_items);
  6624. safe_delete(items);
  6625. return repairable_items;
  6626. }
  6627. void Client::SendMailList() {
  6628. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  6629. if (kiosk_id > 0) {
  6630. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  6631. if (p) {
  6632. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  6633. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  6634. int16 i = 0;
  6635. p->setDataByName("kiosk_id", kiosk_id);
  6636. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  6637. while (itr.Next()) {
  6638. Mail* mail = itr->second;
  6639. p->setArrayDataByName("mail_id", mail->mail_id, i);
  6640. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  6641. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  6642. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  6643. p->setArrayDataByName("unknown1", 0x0000, i);
  6644. p->setArrayDataByName("already_read", mail->already_read, i);
  6645. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  6646. p->setArrayDataByName("mail_type", mail->mail_type, i);
  6647. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  6648. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  6649. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  6650. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  6651. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  6652. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  6653. p->setArrayDataByName("num_items", mail->stack, i);
  6654. p->setArrayDataByName("packettype", GetItemPacketType(GetVersion()));
  6655. p->setArrayDataByName("packetsubtype", 0xFF, i);
  6656. p->setArrayDataByName("unknown2", 0, i);
  6657. //p->setArrayDataByName("item_id", 5, i, 0);
  6658. //Item* item = master_item_list.GetItem(5);
  6659. //if (item)
  6660. // printf("%s\n", item->name.c_str());
  6661. //else
  6662. // printf("no item\n");
  6663. //p->setItemArrayDataByName("item", master_item_list.GetItem(5), i, 0);
  6664. i++;
  6665. }
  6666. // GMs send mail for free!
  6667. if (GetAdminStatus() > 0)
  6668. {
  6669. p->setDataByName("postage_cost", 0);
  6670. p->setDataByName("attachment_cost", 0);
  6671. }
  6672. else
  6673. {
  6674. p->setDataByName("postage_cost", 10);
  6675. p->setDataByName("attachment_cost", 50);
  6676. }
  6677. p->setDataByName("unknown3", 0x01F4);
  6678. p->setDataByName("unknown4", 0x01000000);
  6679. QueuePacket(p->serialize());
  6680. safe_delete(p);
  6681. }
  6682. }
  6683. else
  6684. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  6685. }
  6686. void Client::DisplayMailMessage(int32 mail_id) {
  6687. Mail* mail = player->GetMail(mail_id);
  6688. if (mail) {
  6689. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  6690. if (kiosk_id > 0) {
  6691. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6692. if (update) {
  6693. update->setDataByName("action", 0x03);
  6694. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  6695. update->setDataByName("packetsubtype", 0xFF);
  6696. QueuePacket(update->serialize());
  6697. safe_delete(update);
  6698. }
  6699. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  6700. if (packet) {
  6701. packet->setDataByName("kiosk_id", kiosk_id);
  6702. packet->setDataByName("mail_id", mail->mail_id);
  6703. packet->setDataByName("player_to_id", mail->player_to_id);
  6704. packet->setDataByName("player_from", mail->player_from.c_str());
  6705. packet->setDataByName("subject", mail->subject.c_str());
  6706. packet->setDataByName("mail_body", mail->mail_body.c_str());
  6707. packet->setDataByName("unknown1", 1);
  6708. packet->setDataByName("unknown2", 0);
  6709. packet->setDataByName("lock_report_button", 1);
  6710. packet->setDataByName("unknown3", 0xFFFFFFFF);
  6711. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  6712. packet->setDataByName("coin_copper", mail->coin_copper);
  6713. packet->setDataByName("coin_silver", mail->coin_silver);
  6714. packet->setDataByName("coin_gold", mail->coin_gold);
  6715. packet->setDataByName("coin_plat", mail->coin_plat);
  6716. packet->setDataByName("stack", mail->stack);
  6717. packet->setDataByName("packettype", GetItemPacketType(GetVersion()));
  6718. packet->setDataByName("packetsubtype", 0xFF);
  6719. packet->setDataByName("unknown4", 0);
  6720. packet->setDataByName("unknown5", 0);
  6721. packet->setDataByName("unknown6", 0);
  6722. packet->setDataByName("unknown7", 0);
  6723. mail->already_read = true;
  6724. mail->save_needed = true;
  6725. QueuePacket(packet->serialize());
  6726. safe_delete(packet);
  6727. //SendMailList();
  6728. }
  6729. }
  6730. else
  6731. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  6732. }
  6733. }
  6734. /* 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
  6735. packet back to the client before the mail actually sent. */
  6736. void Client::HandleSentMail(EQApplicationPacket* app) {
  6737. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  6738. if (packet) {
  6739. packet->LoadPacketData(app->pBuffer, app->size);
  6740. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  6741. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  6742. vector<int32>* ids = 0;
  6743. if (reply_packet) {
  6744. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  6745. if (player_to.length() == 0)
  6746. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  6747. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  6748. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  6749. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  6750. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  6751. else {
  6752. if (player_to.compare("<all>") == 0) {
  6753. if (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat == 0)
  6754. ids = database.GetAllPlayerIDs();
  6755. else
  6756. SimpleMessage(CHANNEL_NARRATIVE, "You may not mail gifts to multiple players.");
  6757. }
  6758. else {
  6759. ids = new vector<int32>;
  6760. ids->push_back(database.GetCharacterID(player_to.c_str()));
  6761. }
  6762. if (ids) {
  6763. for (int32 i = 0; i < ids->size(); i++) {
  6764. int32 player_to_id = ids->at(i);
  6765. if (player_to_id > 0) {
  6766. reply_type = MAIL_SEND_RESULT_SUCCESS;
  6767. Mail* mail = new Mail;
  6768. mail->mail_id = 0;
  6769. mail->player_to_id = player_to_id;
  6770. mail->player_from = string(GetPlayer()->GetName());
  6771. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  6772. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  6773. mail->already_read = 0;
  6774. mail->mail_type = MAIL_TYPE_REGULAR;
  6775. mail->coin_copper = mail_window.coin_copper;
  6776. mail->coin_silver = mail_window.coin_silver;
  6777. mail->coin_gold = mail_window.coin_gold;
  6778. mail->coin_plat = mail_window.coin_plat;
  6779. mail->stack = 0;
  6780. // GM's send mail for free!
  6781. if (GetAdminStatus() > 0)
  6782. {
  6783. mail->postage_cost = 0;
  6784. mail->attachment_cost = 0;
  6785. }
  6786. else
  6787. {
  6788. mail->postage_cost = 10;
  6789. mail->attachment_cost = 50;
  6790. }
  6791. mail->char_item_id = 0;
  6792. mail->time_sent = Timer::GetUnixTimeStamp();
  6793. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  6794. //int16 packettype = packet->getType_int16_ByName("packettype");
  6795. //int8 packetsubtype = packet->getType_int8_ByName("packetsubtype");
  6796. /*int32 postage_cost = packet->getType_int32_ByName("postage_cost");
  6797. int32 attachment_cost = packet->getType_int32_ByName("attachment_cost");
  6798. if (postage_cost > 0 || attachment_cost > 0)
  6799. PlaySoundA("coin_cha_ching");*/
  6800. mail->save_needed = false;
  6801. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  6802. if (to_client) {
  6803. to_client->GetPlayer()->AddMail(mail);
  6804. to_client->SimpleMessage(CHANNEL_NARRATIVE, "You've got mail! :)");
  6805. }
  6806. database.SavePlayerMail(mail);
  6807. mail_window.coin_copper = 0;
  6808. mail_window.coin_silver = 0;
  6809. mail_window.coin_gold = 0;
  6810. mail_window.coin_plat = 0;
  6811. }
  6812. else
  6813. reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
  6814. }
  6815. }
  6816. }
  6817. string players_to = "";
  6818. if (ids) {
  6819. for (int32 i = 0; i < ids->size(); i++) {
  6820. if (ids->at(i) != 0)
  6821. players_to.append(database.GetCharacterName(ids->at(i)));
  6822. if (i < (ids->size() - 1))
  6823. players_to.append(", ");
  6824. }
  6825. }
  6826. reply_packet->setDataByName("player_to", players_to.c_str());
  6827. reply_packet->setDataByName("reply_type", reply_type);
  6828. QueuePacket(reply_packet->serialize());
  6829. safe_delete(reply_packet);
  6830. safe_delete(ids);
  6831. }
  6832. safe_delete(packet);
  6833. }
  6834. }
  6835. void Client::DeleteMail(int32 mail_id, bool from_database) {
  6836. player->DeleteMail(mail_id, from_database);
  6837. }
  6838. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  6839. bool ret = false;
  6840. if (GetMailTransaction()) {
  6841. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6842. if (packet) {
  6843. if (copper > 0) {
  6844. if (player->RemoveCoins(copper)) {
  6845. mail_window.coin_copper += copper;
  6846. Message(CHANNEL_NARRATIVE, "You add %u copper to the mail window.", copper);
  6847. ret = true;
  6848. }
  6849. }
  6850. else if (silver > 0) {
  6851. if (player->RemoveCoins(silver * 100)) {
  6852. mail_window.coin_silver += silver;
  6853. Message(CHANNEL_NARRATIVE, "You add %u silver to the mail window.", silver);
  6854. ret = true;
  6855. }
  6856. }
  6857. else if (gold > 0) {
  6858. if (player->RemoveCoins(gold * 10000)) {
  6859. mail_window.coin_gold += gold;
  6860. Message(CHANNEL_NARRATIVE, "You add %u gold to the mail window.", gold);
  6861. ret = true;
  6862. }
  6863. }
  6864. else if (plat > 0) {
  6865. if (player->RemoveCoins(plat * 1000000)) {
  6866. mail_window.coin_plat += plat;
  6867. Message(CHANNEL_NARRATIVE, "You add %u platinum to the mail window.", plat);
  6868. ret = true;
  6869. }
  6870. }
  6871. if (ret) {
  6872. packet->setDataByName("coin_copper", mail_window.coin_copper);
  6873. packet->setDataByName("coin_silver", mail_window.coin_silver);
  6874. packet->setDataByName("coin_gold", mail_window.coin_gold);
  6875. packet->setDataByName("coin_plat", mail_window.coin_plat);
  6876. packet->setDataByName("stack", 0);
  6877. packet->setDataByName("packettype", GetItemPacketType(version));
  6878. packet->setDataByName("packetsubtype", 0xFF);
  6879. packet->setDataByName("unknown2", 0);
  6880. //packet->PrintPacket();
  6881. QueuePacket(packet->serialize());
  6882. }
  6883. else
  6884. SimpleMessage(CHANNEL_NARRATIVE, "You don't have that much money.");
  6885. safe_delete(packet);
  6886. }
  6887. }
  6888. else
  6889. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  6890. return ret;
  6891. }
  6892. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  6893. bool ret = false;
  6894. if (GetMailTransaction()) {
  6895. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6896. if (packet) {
  6897. if (copper > 0) {
  6898. player->AddCoins(copper);
  6899. mail_window.coin_copper -= copper;
  6900. Message(CHANNEL_NARRATIVE, "You remove %u copper from the mail window.", copper);
  6901. ret = true;
  6902. }
  6903. else if (silver > 0) {
  6904. player->AddCoins(silver * 100);
  6905. mail_window.coin_silver -= silver;
  6906. Message(CHANNEL_NARRATIVE, "You remove %u silver from the mail window.", silver);
  6907. ret = true;
  6908. }
  6909. else if (gold > 0) {
  6910. player->AddCoins(gold * 10000);
  6911. mail_window.coin_gold -= gold;
  6912. Message(CHANNEL_NARRATIVE, "You remove %u gold from the mail window.", gold);
  6913. ret = true;
  6914. }
  6915. else if (plat > 0) {
  6916. player->AddCoins(plat * 1000000);
  6917. mail_window.coin_plat -= plat;
  6918. Message(CHANNEL_NARRATIVE, "You remove %u platinum from the mail window.", plat);
  6919. ret = true;
  6920. }
  6921. if (ret) {
  6922. packet->setDataByName("coin_copper", mail_window.coin_copper);
  6923. packet->setDataByName("coin_silver", mail_window.coin_silver);
  6924. packet->setDataByName("coin_gold", mail_window.coin_gold);
  6925. packet->setDataByName("coin_plat", mail_window.coin_plat);
  6926. packet->setDataByName("stack", 0);
  6927. packet->setDataByName("packettype", 0x2BFE);
  6928. packet->setDataByName("packetsubtype", 0xFF);
  6929. packet->setDataByName("unknown2", 0);
  6930. QueuePacket(packet->serialize());
  6931. }
  6932. safe_delete(packet);
  6933. }
  6934. }
  6935. else
  6936. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  6937. return ret;
  6938. }
  6939. void Client::TakeMailAttachments(int32 mail_id) {
  6940. if (GetMailTransaction()) {
  6941. Mail* mail = player->GetMail(mail_id);
  6942. if (mail) {
  6943. int64 amount = 0;
  6944. if (mail->coin_copper > 0) {
  6945. amount += mail->coin_copper;
  6946. mail->coin_copper = 0;
  6947. }
  6948. if (mail->coin_silver > 0) {
  6949. amount += mail->coin_silver * 100;
  6950. mail->coin_silver = 0;
  6951. }
  6952. if (mail->coin_gold > 0) {
  6953. amount += mail->coin_gold * 10000;
  6954. mail->coin_gold = 0;
  6955. }
  6956. if (mail->coin_plat > 0) {
  6957. amount += mail->coin_plat * 1000000;
  6958. mail->coin_plat = 0;
  6959. }
  6960. if (mail->char_item_id > 0) {
  6961. LogWrite(MISC__TODO, 1, "TODO", "Items by Mail\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  6962. }
  6963. /* 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
  6964. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  6965. find it in any packet logs.*/
  6966. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6967. if (packet) {
  6968. packet->setDataByName("unknown", 0x03);
  6969. packet->setDataByName("coin_copper", mail->coin_copper);
  6970. packet->setDataByName("coin_silver", mail->coin_silver);
  6971. packet->setDataByName("coin_gold", mail->coin_gold);
  6972. packet->setDataByName("coin_plat", mail->coin_plat);
  6973. packet->setDataByName("stack", 0);
  6974. packet->setDataByName("packettype", 0x2BFE);
  6975. packet->setDataByName("packetsubtype", 0xFF);
  6976. packet->setDataByName("unknown2", 0);
  6977. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  6978. DumpPacket(packet->serialize());
  6979. QueuePacket(packet->serialize());
  6980. safe_delete(packet);
  6981. }*/
  6982. database.SavePlayerMail(mail);
  6983. if (amount > 0)
  6984. player->AddCoins(amount);
  6985. SendMailList();
  6986. }
  6987. }
  6988. else
  6989. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  6990. }
  6991. void Client::CancelSendMail() {
  6992. SimpleMessage(CHANNEL_NARRATIVE, "You cancel sending a letter.");
  6993. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  6994. mail_window.coin_copper = 0;
  6995. mail_window.coin_silver = 0;
  6996. mail_window.coin_gold = 0;
  6997. mail_window.coin_plat = 0;
  6998. mail_window.char_item_id = 0;
  6999. }
  7000. bool Client::GateAllowed() {
  7001. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  7002. 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__);
  7003. if (zone)
  7004. return true;
  7005. return false;
  7006. }
  7007. bool Client::BindAllowed() {
  7008. 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__);
  7009. return true;
  7010. }
  7011. bool Client::Bind() {
  7012. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  7013. player->GetPlayerInfo()->SetBindX(player->GetX());
  7014. player->GetPlayerInfo()->SetBindY(player->GetY());
  7015. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  7016. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  7017. return true;
  7018. }
  7019. bool Client::Gate() {
  7020. if (player->GetPlayerInfo()->GetBindZoneID() == 0)
  7021. return false;
  7022. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  7023. if (zone) {
  7024. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  7025. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  7026. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  7027. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  7028. Zone(zone, false);
  7029. return true;
  7030. }
  7031. return false;
  7032. }
  7033. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id) {
  7034. if (!destinations || !spawn) {
  7035. return;
  7036. }
  7037. bool has_map = false;
  7038. if (transport_id > 0)
  7039. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  7040. transport_spawn = spawn;
  7041. vector<TransportDestination*> transport_list;
  7042. vector<TransportDestination*>::iterator itr;
  7043. TransportDestination* destination = 0;
  7044. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  7045. destination = *itr;
  7046. 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)))
  7047. transport_list.push_back(destination);
  7048. }
  7049. if (transport_list.size() == 0 && destination) {
  7050. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  7051. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  7052. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  7053. else
  7054. {
  7055. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  7056. if (app)
  7057. QueuePacket(app);
  7058. }
  7059. }
  7060. else {
  7061. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  7062. // determine if this is an instanced zone that already exists
  7063. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
  7064. if (instance_zone || new_zone) {
  7065. GetPlayer()->SetX(destination->destination_x);
  7066. GetPlayer()->SetY(destination->destination_y);
  7067. GetPlayer()->SetZ(destination->destination_z);
  7068. GetPlayer()->SetHeading(destination->destination_heading);
  7069. if (instance_zone)
  7070. Zone(instance_zone->GetInstanceID(), false, true);
  7071. else
  7072. Zone(new_zone, false);
  7073. }
  7074. }
  7075. if (destination->message.length() > 0)
  7076. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  7077. }
  7078. else if (transport_list.size() > 0) {
  7079. if (!spawn->IsSoundsDisabled())
  7080. PlaySound("mariner_bell");
  7081. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  7082. if (packet) {
  7083. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  7084. // Put all the destinations the player can go in a new vector
  7085. vector<TransportDestination*> destinations;
  7086. for (int32 i = 0; i < transport_list.size(); i++) {
  7087. destination = transport_list.at(i);
  7088. // Check min level
  7089. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  7090. continue;
  7091. // Check max level
  7092. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  7093. continue;
  7094. // Check quest complete
  7095. if (destination->req_quest_complete > 0 && GetPlayer()->GetCompletedQuest(destination->req_quest_complete) == 0)
  7096. continue;
  7097. // Check req quest and step
  7098. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  7099. continue;
  7100. // 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
  7101. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  7102. packet->setDataByName("current_zone", destination->display_name.c_str());
  7103. packet->setDataByName("current_map_x", destination->map_x);
  7104. packet->setDataByName("current_map_y", destination->map_y);
  7105. }
  7106. else {
  7107. destinations.push_back(destination);
  7108. }
  7109. }
  7110. // Use the new vector to create the packet
  7111. destination = 0;
  7112. packet->setArrayLengthByName("num_destinations", destinations.size());
  7113. for (int32 i = 0; i < destinations.size(); i++) {
  7114. destination = destinations.at(i);
  7115. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  7116. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  7117. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  7118. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  7119. packet->setArrayDataByName("cost", destination->cost, i);
  7120. if (has_map) {
  7121. packet->setArrayDataByName("map_x", destination->map_x, i);
  7122. packet->setArrayDataByName("map_y", destination->map_y, i);
  7123. }
  7124. }
  7125. if (has_map)
  7126. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  7127. EQ2Packet* app = packet->serialize();
  7128. //DumpPacket(app);
  7129. if (destinations.size() > 0)
  7130. QueuePacket(app);
  7131. safe_delete(packet);
  7132. }
  7133. }
  7134. }
  7135. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  7136. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  7137. if (packet) {
  7138. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  7139. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  7140. int32 unique_id = packet->getType_int32_ByName("unique_id");
  7141. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  7142. int32 cost = packet->getType_int32_ByName("cost");
  7143. vector<TransportDestination*> destinations;
  7144. TransportDestination* destination = 0;
  7145. if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
  7146. GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
  7147. vector<TransportDestination*>::iterator itr;
  7148. for (itr = destinations.begin(); itr != destinations.end(); itr++) {
  7149. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  7150. destination = *itr;
  7151. break;
  7152. }
  7153. }
  7154. SetTemporaryTransportID(0);
  7155. if (!destination)
  7156. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  7157. else {
  7158. if (cost == 0 || player->RemoveCoins(cost)) {
  7159. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  7160. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  7161. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  7162. else
  7163. {
  7164. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  7165. if (outapp)
  7166. QueuePacket(outapp);
  7167. }
  7168. }
  7169. else {
  7170. GetPlayer()->SetX(destination->destination_x);
  7171. GetPlayer()->SetY(destination->destination_y);
  7172. GetPlayer()->SetZ(destination->destination_z);
  7173. GetPlayer()->SetHeading(destination->destination_heading);
  7174. // Test if where we're going is an Instanced zone
  7175. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  7176. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  7177. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  7178. Zone(new_zone, false);
  7179. }
  7180. }
  7181. if (destination->message.length() > 0)
  7182. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  7183. }
  7184. else
  7185. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  7186. }
  7187. }
  7188. safe_delete(packet);
  7189. }
  7190. }
  7191. void Client::SendNewSpells(int8 class_id) {
  7192. if (class_id > 0) {
  7193. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  7194. vector<Spell*>::iterator itr;
  7195. Spell* spell = 0;
  7196. bool send_updates = false;
  7197. for (itr = spells->begin(); itr != spells->end(); itr++) {
  7198. spell = *itr;
  7199. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  7200. send_updates = true;
  7201. SendSpellUpdate(spell);
  7202. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  7203. player->UnlockSpell(spell);
  7204. }
  7205. }
  7206. if (send_updates) {
  7207. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  7208. if (outapp)
  7209. QueuePacket(outapp);
  7210. }
  7211. safe_delete(spells);
  7212. }
  7213. }
  7214. void Client::SetItemSearch(vector<Item*>* items) {
  7215. if (items) {
  7216. safe_delete(search_items);
  7217. search_items = items;
  7218. }
  7219. }
  7220. vector<Item*>* Client::GetSearchItems() {
  7221. return search_items;
  7222. }
  7223. void Client::SearchStore(int32 page) {
  7224. if (search_items) {
  7225. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  7226. if (packet) {
  7227. int32 x = page * 8;
  7228. if (search_items->size() > 8) {
  7229. if ((search_items->size() - x) > 8)
  7230. packet->setArrayLengthByName("num_items", 8);
  7231. else
  7232. packet->setArrayLengthByName("num_items", search_items->size() - x);
  7233. }
  7234. else
  7235. packet->setArrayLengthByName("num_items", search_items->size());
  7236. if (search_items->size() > 0) {
  7237. packet->setArrayLengthByName("num_sellers", 1);
  7238. packet->setArrayDataByName("seller_seller_id", 1);
  7239. packet->setArrayDataByName("seller_name", "EQ2EmuDevs");
  7240. packet->setDataByName("per_page", 8);
  7241. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  7242. packet->setDataByName("page", page);
  7243. Item* item = 0;
  7244. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  7245. for (int32 i = 0; i < limit; i++, x++) {
  7246. if (x >= search_items->size())
  7247. break;
  7248. item = search_items->at(x);
  7249. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7250. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7251. packet->setArrayDataByName("icon", item->details.icon, i);
  7252. //packet->setArrayDataByName("unknown2b", i, i);
  7253. packet->setArrayDataByName("item_seller_id", 1, i);
  7254. if (item->stack_count == 0)
  7255. packet->setArrayDataByName("quantity", 1, i);
  7256. else
  7257. packet->setArrayDataByName("quantity", item->stack_count, i);
  7258. packet->setArrayDataByName("stack_size", item->stack_count, i);
  7259. std::string tmpStr("");
  7260. tmpStr.append(item->name.c_str());
  7261. tmpStr.append(" (");
  7262. tmpStr.append(std::to_string(item->details.item_id));
  7263. tmpStr.append(")");
  7264. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  7265. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  7266. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  7267. }
  7268. }
  7269. /*EQ2Packet* outapp = packet->serialize();
  7270. DumpPacket(outapp);
  7271. QueuePacket(outapp);*/
  7272. QueuePacket(packet->serialize());
  7273. safe_delete(packet);
  7274. }
  7275. }
  7276. }
  7277. void Client::SetReadyForUpdates() {
  7278. GetPlayer()->SetFullyLoggedIn(true);
  7279. if (!ready_for_updates)
  7280. database.loadCharacterProperties(this);
  7281. ready_for_updates = true;
  7282. }
  7283. void Client::SetReadyForSpawns(bool val) {
  7284. ready_for_spawns = val;
  7285. if (GetPlayer()->GetActivityStatus() > 0) {
  7286. GetPlayer()->SetActivityStatus(0);
  7287. if (GetPlayer()->GetGroupMemberInfo()) {
  7288. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  7289. }
  7290. }
  7291. zone_list.CheckFriendZoned(this);
  7292. }
  7293. void Client::SendChatRelationship(int8 type, const char* name) {
  7294. if (!name) {
  7295. return;
  7296. }
  7297. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  7298. if (packet) {
  7299. packet->setDataByName("account_id", GetAccountID());
  7300. packet->setDataByName("type", type);
  7301. packet->setArrayLengthByName("num_names", 1);
  7302. packet->setArrayDataByName("name", name);
  7303. if (type == 0) {
  7304. Client* client = zone_list.GetClientByCharName(name);
  7305. if (client) {
  7306. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  7307. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  7308. }
  7309. }
  7310. QueuePacket(packet->serialize());
  7311. safe_delete(packet);
  7312. }
  7313. }
  7314. void Client::SendFriendList() {
  7315. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  7316. if (packet) {
  7317. packet->setDataByName("account_id", GetAccountID());
  7318. map<string, int8>::iterator itr;
  7319. map<string, int8>* friends = player->GetFriends();
  7320. if (friends && friends->size() > 0) {
  7321. Client* client = 0;
  7322. vector<string> names;
  7323. for (itr = friends->begin(); itr != friends->end(); itr++) {
  7324. if (itr->second == 2)
  7325. continue;
  7326. names.push_back(itr->first);
  7327. }
  7328. packet->setArrayLengthByName("num_names", names.size());
  7329. for (int32 i = 0; i < names.size(); i++) {
  7330. client = zone_list.GetClientByCharName(names[i]);
  7331. packet->setArrayDataByName("name", names[i].c_str(), i);
  7332. if (client) {
  7333. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  7334. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  7335. }
  7336. }
  7337. }
  7338. QueuePacket(packet->serialize());
  7339. safe_delete(packet);
  7340. }
  7341. }
  7342. void Client::SendIgnoreList() {
  7343. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  7344. if (packet) {
  7345. packet->setDataByName("account_id", GetAccountID());
  7346. packet->setDataByName("type", 2);
  7347. map<string, int8>::iterator itr;
  7348. map<string, int8>* ignored = player->GetIgnoredPlayers();
  7349. if (ignored && ignored->size() > 0) {
  7350. vector<string> names;
  7351. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  7352. if (itr->second == 2)
  7353. continue;
  7354. names.push_back(itr->first);
  7355. }
  7356. packet->setArrayLengthByName("num_names", names.size());
  7357. for (int32 i = 0; i < names.size(); i++)
  7358. packet->setArrayDataByName("name", names[i].c_str(), i);
  7359. }
  7360. QueuePacket(packet->serialize());
  7361. safe_delete(packet);
  7362. }
  7363. }
  7364. void Client::AddWaypoint(string name, int8 type) {
  7365. waypoint_id++;
  7366. WaypointInfo info;
  7367. info.id = waypoint_id;
  7368. info.type = type;
  7369. waypoints[name] = info;
  7370. }
  7371. void Client::SendWaypoints() {
  7372. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  7373. if (packet) {
  7374. packet->setArrayLengthByName("num_updates", waypoints.size());
  7375. map<string, WaypointInfo>::iterator itr;
  7376. int16 i = 0;
  7377. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  7378. packet->setArrayDataByName("waypoint_name", itr->first.c_str(), i);
  7379. packet->setArrayDataByName("waypoint_category", itr->second.type, i);
  7380. packet->setArrayDataByName("spawn_id", itr->second.id, i);
  7381. i++;
  7382. }
  7383. packet->setDataByName("unknown", 0xFFFFFFFF);
  7384. QueuePacket(packet->serialize());
  7385. safe_delete(packet);
  7386. }
  7387. }
  7388. void Client::SelectWaypoint(int32 id) {
  7389. string found_name = "";
  7390. map<string, WaypointInfo>::iterator itr;
  7391. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  7392. if (itr->second.id == id) {
  7393. found_name = itr->first;
  7394. break;
  7395. }
  7396. }
  7397. if (found_name.length() > 0) {
  7398. Spawn* spawn = current_zone->FindSpawn(player, found_name.c_str());
  7399. ShowPathToTarget(spawn);
  7400. }
  7401. }
  7402. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  7403. if (waypoint_name) {
  7404. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  7405. if (packet) {
  7406. packet->setArrayLengthByName("num_updates", 1);
  7407. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  7408. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  7409. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  7410. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  7411. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  7412. packet->setDataByName("unknown", 0xFFFFFFFF);
  7413. QueuePacket(packet->serialize());
  7414. safe_delete(packet);
  7415. }
  7416. }
  7417. }
  7418. void Client::ClearWaypoint() {
  7419. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  7420. if (packet) {
  7421. QueuePacket(packet->serialize());
  7422. safe_delete(packet);
  7423. }
  7424. }
  7425. bool Client::ShowPathToTarget(float x, float y, float z, float y_offset) {
  7426. if (current_zone->pathing) {
  7427. if (GetPlayer()->GetMap()) {
  7428. if (x < GetPlayer()->GetMap()->GetMinX() || x > GetPlayer()->GetMap()->GetMaxX())
  7429. return false;
  7430. if (z < GetPlayer()->GetMap()->GetMinZ() || z > GetPlayer()->GetMap()->GetMaxZ())
  7431. return false;
  7432. auto loc = glm::vec3(x, z, y);
  7433. float new_z = GetPlayer()->GetMap()->FindBestZ(loc, nullptr);
  7434. if (new_z != BEST_Z_INVALID) //this is actually y
  7435. y = new_z;
  7436. }
  7437. bool partial = false;
  7438. bool stuck = false;
  7439. PathfinderOptions opts;
  7440. opts.smooth_path = true;
  7441. opts.step_size = 100.0f;//RuleR(Pathing, NavmeshStepSize);
  7442. opts.offset = y_offset + 1.0f;
  7443. opts.flags = PathingNotDisabled ^ PathingZoneLine;
  7444. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  7445. if (packet) {
  7446. auto path = current_zone->pathing->FindPath(glm::vec3(player->GetX(), player->GetZ(), player->GetY()), glm::vec3(x, z, y), partial, stuck, opts);
  7447. packet->setArrayLengthByName("num_points", path.size());
  7448. int i = 0;
  7449. for (auto& node : path)
  7450. {
  7451. packet->setArrayDataByName("x", node.pos.x, i);
  7452. packet->setArrayDataByName("y", node.pos.z, i);
  7453. packet->setArrayDataByName("z", node.pos.y, i);
  7454. packet->setDataByName("waypoint_x", x);
  7455. packet->setDataByName("waypoint_y", y);
  7456. packet->setDataByName("waypoint_z", z);
  7457. i++;
  7458. }
  7459. if (i > 0)
  7460. QueuePacket(packet->serialize());
  7461. safe_delete(packet);
  7462. return (i > 0);
  7463. }
  7464. }
  7465. return false;
  7466. }
  7467. bool Client::ShowPathToTarget(Spawn* spawn) {
  7468. if (spawn) {
  7469. return ShowPathToTarget(spawn->GetX(), spawn->GetY(), spawn->GetZ(), spawn->GetYOffset());
  7470. }
  7471. return false;
  7472. }
  7473. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  7474. if (waypoint_name) {
  7475. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  7476. if (packet) {
  7477. packet->setArrayLengthByName("num_points", 1);
  7478. packet->setArrayDataByName("x", x, 0);
  7479. packet->setArrayDataByName("y", y, 0);
  7480. packet->setArrayDataByName("z", z, 0);
  7481. packet->setDataByName("waypoint_x", x);
  7482. packet->setDataByName("waypoint_y", y);
  7483. packet->setDataByName("waypoint_z", z);
  7484. packet->setDataByName("waypoint_name", waypoint_name);
  7485. packet->setDataByName("unknown", 0);
  7486. QueuePacket(packet->serialize());
  7487. safe_delete(packet);
  7488. }
  7489. }
  7490. }
  7491. void Client::InspectPlayer(Player* player_to_inspect) {
  7492. if (player_to_inspect) {
  7493. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  7494. if (packet) {
  7495. packet->setDataByName("unknown", 0);
  7496. packet->setSmallStringByName("name", player_to_inspect->GetName());
  7497. packet->setDataByName("race", player_to_inspect->GetRace());
  7498. packet->setDataByName("gender", player_to_inspect->GetGender());
  7499. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  7500. LogWrite(MISC__TODO, 1, "TODO", "Put mentored level here (adventure_level_effective)\nfile: %s, func: %s, line: %i", __FILE__, __FUNCTION__, __LINE__);
  7501. packet->setDataByName("adventure_level_effective", player_to_inspect->GetLevel());
  7502. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  7503. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  7504. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  7505. packet->setDataByName("health", player_to_inspect->GetHP());
  7506. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  7507. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  7508. packet->setDataByName("power", player_to_inspect->GetPower());
  7509. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  7510. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  7511. packet->setDataByName("mitigation", 0);
  7512. packet->setDataByName("unknown1", 0);
  7513. packet->setDataByName("avoidance", 0);
  7514. packet->setDataByName("unknown2", 0);
  7515. packet->setDataByName("mitigation_percentage", 0);
  7516. packet->setDataByName("strength", player_to_inspect->GetStr());
  7517. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  7518. packet->setDataByName("stamina", player_to_inspect->GetSta());
  7519. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  7520. packet->setDataByName("agility", player_to_inspect->GetAgi());
  7521. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  7522. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  7523. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  7524. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  7525. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  7526. packet->setDataByName("unknown4", 0);
  7527. packet->setDataByName("unknown5", 0);
  7528. packet->setDataByName("unknown6", 0);
  7529. packet->setDataByName("unknown7", 0);
  7530. packet->setDataByName("unknown8", 0);
  7531. packet->setDataByName("unknown9", 0);
  7532. packet->setDataByName("unknown10", 0);
  7533. packet->setDataByName("unknown11", 0);
  7534. packet->setDataByName("unknown12", 0);
  7535. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  7536. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  7537. packet->setDataByName("heat_resist_percentage", 0);
  7538. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  7539. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  7540. packet->setDataByName("cold_resist_percentage", 0);
  7541. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  7542. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  7543. packet->setDataByName("magic_resist_percentage", 0);
  7544. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  7545. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  7546. packet->setDataByName("mental_resist_percentage", 0);
  7547. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  7548. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  7549. packet->setDataByName("divine_resist_percentage", 0);
  7550. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  7551. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  7552. packet->setDataByName("disease_resist_percentage", 0);
  7553. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  7554. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  7555. packet->setDataByName("poison_resist_percentage", 0);
  7556. packet->setArrayLengthByName("num_chars", 0x01FF);
  7557. string biography = player_to_inspect->GetBiography();
  7558. for (size_t i = 0; i < biography.length(); i++)
  7559. packet->setArrayDataByName("biography_char", biography[i], i);
  7560. LogWrite(MISC__TODO, 0, "TODO", "Why is inspect player weapons commented out? in func: %s, line: %i", __FUNCTION__, __LINE__);
  7561. /*Item* pw = player_to_inspect->GetEquipmentList()->GetItem(0);
  7562. if (pw)
  7563. packet->setItemByName("primary", pw, player_to_inspect, 0);
  7564. Item* sw = player_to_inspect->GetEquipmentList()->GetItem(1);
  7565. if (sw)
  7566. packet->setItemByName("secondary", sw, player_to_inspect, 0);*/
  7567. //DumpPacket(packet->serialize());
  7568. QueuePacket(packet->serialize());
  7569. safe_delete(packet);
  7570. }
  7571. }
  7572. }
  7573. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  7574. pending_guild_invite.guild = guild;
  7575. pending_guild_invite.invited_by = invited_by;
  7576. }
  7577. void Client::ShowClaimWindow() {
  7578. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  7579. if (packet) {
  7580. map<int32, Item*>* items = &master_item_list.items;
  7581. map<int32, Item*>::iterator itr;
  7582. int32 i = 0;
  7583. if (items->size() > 10)
  7584. packet->setArrayLengthByName("num_claim_items", 10);
  7585. else
  7586. packet->setArrayLengthByName("num_claim_items", items->size());
  7587. for (itr = items->begin(); itr != items->end(); itr++) {
  7588. if (i == 10)
  7589. break;
  7590. Item* item = itr->second;
  7591. packet->setArrayDataByName("id", i, i);
  7592. packet->setArrayDataByName("not_yet_claimed", 1, i);
  7593. packet->setArrayDataByName("num_remaining", 5, i);
  7594. packet->setArrayDataByName("one_per_character", 1, i);
  7595. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  7596. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7597. packet->setArrayDataByName("text", "If you ever see this text, let Scatman know, thanks! :)", i);
  7598. packet->setArrayDataByName("category", "Scott's Shit", i);
  7599. packet->setArrayDataByName("icon", item->details.icon, i);
  7600. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7601. i++;
  7602. }
  7603. packet->setDataByName("unknown3", 1);
  7604. QueuePacket(packet->serialize());
  7605. safe_delete(packet);
  7606. }
  7607. }
  7608. void Client::ShowGuildSearchWindow() {
  7609. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  7610. if (packet) {
  7611. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  7612. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  7613. packet->setArrayLengthByName("num_guilds", guilds->size());
  7614. int32 i = 0;
  7615. while (itr.Next()) {
  7616. Guild* guild = itr.second;
  7617. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  7618. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  7619. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  7620. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  7621. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  7622. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  7623. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  7624. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  7625. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  7626. packet->setArrayDataByName("unknown7", 0x02, i);
  7627. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  7628. i++;
  7629. }
  7630. QueuePacket(packet->serialize());
  7631. safe_delete(packet);
  7632. }
  7633. }
  7634. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  7635. PacketStruct* packet;
  7636. vector<int8>* slot_data;
  7637. vector<int8>::iterator itr;
  7638. int32 slots = 0;
  7639. assert(item);
  7640. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  7641. return;
  7642. }
  7643. slot_data = &item->slot_data;
  7644. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  7645. if (version >= 1188)
  7646. slots = *itr;
  7647. else
  7648. slots += (int8)pow(2.0, *itr);
  7649. }
  7650. packet->setDataByName("slot", slots);
  7651. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  7652. if (slots == 2) {
  7653. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  7654. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  7655. }
  7656. else {
  7657. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  7658. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  7659. }
  7660. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  7661. if (slots == 4) {
  7662. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  7663. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  7664. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  7665. }
  7666. else if (slots == 7) {
  7667. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  7668. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  7669. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  7670. }
  7671. else {
  7672. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  7673. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  7674. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  7675. }
  7676. packet->setDataByName("icon", item->details.icon);
  7677. packet->setDataByName("item_id", item->details.item_id);
  7678. packet->setDataByName("item_crc", crc);
  7679. packet->setDataByName("unknown2", 0xFFFFFFFF);
  7680. packet->setDataByName("unknown4", 0xFFFFFFFF);
  7681. packet->setDataByName("unknown5", 0xFF, 9);
  7682. packet->setDataByName("unknown5", 0xFF, 10);
  7683. QueuePacket(packet->serialize());
  7684. safe_delete(packet);
  7685. }
  7686. void Client::SendCollectionList() {
  7687. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  7688. map<int32, Collection*>::iterator itr;
  7689. vector<struct CollectionItem*>* collection_items;
  7690. Collection* collection;
  7691. struct CollectionItem* collection_item;
  7692. PacketStruct* packet = 0;
  7693. int16 i = 0, j;
  7694. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  7695. return;
  7696. packet->setArrayLengthByName("num_collections", collections->size());
  7697. for (itr = collections->begin(); itr != collections->end(); itr++) {
  7698. collection = itr->second;
  7699. collection_items = collection->GetCollectionItems();
  7700. packet->setArrayDataByName("unknown", 1, i);
  7701. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  7702. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  7703. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  7704. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  7705. packet->setArrayDataByName("level", collection->GetLevel(), i);
  7706. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  7707. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  7708. for (j = 0; j < collection_items->size(); j++) {
  7709. collection_item = collection_items->at(j);
  7710. Item* item = master_item_list.GetItem(collection_item->item);
  7711. if (item) {
  7712. packet->setSubArrayDataByName("item_icon", item->details.icon, i, j);
  7713. if (version < 955)
  7714. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  7715. else
  7716. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  7717. }
  7718. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  7719. }
  7720. i++;
  7721. }
  7722. packet->setDataByName("new_collection_flag", 1);
  7723. QueuePacket(packet->serialize());
  7724. safe_delete(packet);
  7725. }
  7726. bool Client::SendCollectionsForItem(Item* item) {
  7727. map<int32, Collection*> collections_to_send;
  7728. map<int32, Collection*>* collections;
  7729. map<int32, Collection*>::iterator itr;
  7730. vector<struct CollectionItem*>* collection_items;
  7731. Collection* collection;
  7732. struct CollectionItem* collection_item;
  7733. PacketStruct* packet;
  7734. int16 i;
  7735. assert(item);
  7736. /* get any collections required by this item that the player already has */
  7737. collections = player->GetCollectionList()->GetCollections();
  7738. for (itr = collections->begin(); itr != collections->end(); itr++) {
  7739. collection = itr->second;
  7740. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  7741. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  7742. collections_to_send[collection->GetID()] = collection;
  7743. }
  7744. }
  7745. /* get any collections required by this item that the player does not have and send it to the client */
  7746. collections = master_collection_list.GetCollections();
  7747. for (itr = collections->begin(); itr != collections->end(); itr++) {
  7748. collection = itr->second;
  7749. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  7750. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  7751. return false;
  7752. }
  7753. packet->setArrayLengthByName("num_collections", 1);
  7754. packet->setArrayDataByName("unknown", 1, 0);
  7755. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  7756. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  7757. packet->setArrayDataByName("completed", 0, 0);
  7758. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  7759. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  7760. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  7761. packet->setArrayDataByName("unknown3", 0x28, 0);
  7762. collection_items = collection->GetCollectionItems();
  7763. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  7764. for (i = 0; i < collection_items->size(); i++) {
  7765. collection_item = collection_items->at(i);
  7766. Item* item2 = master_item_list.GetItem(collection_item->item);
  7767. if (item2) {
  7768. packet->setSubArrayDataByName("item_icon", item2->details.icon, 0, i);
  7769. if (version < 955)
  7770. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  7771. else
  7772. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  7773. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  7774. }
  7775. }
  7776. packet->setDataByName("new_collection_flag", 0);
  7777. QueuePacket(packet->serialize());
  7778. safe_delete(packet);
  7779. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  7780. collections_to_send[collection->GetID()] = collection;
  7781. }
  7782. }
  7783. /* send the client a list of collections that should be filtered for this item */
  7784. if (collections_to_send.size() > 0) {
  7785. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  7786. return false;
  7787. }
  7788. i = 0;
  7789. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  7790. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  7791. collection = itr->second;
  7792. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  7793. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  7794. i++;
  7795. }
  7796. packet->setDataByName("item_icon", item->details.icon);
  7797. packet->setDataByName("item_name", item->name.c_str());
  7798. packet->setDataByName("item_id", item->details.item_id);
  7799. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  7800. QueuePacket(packet->serialize());
  7801. safe_delete(packet);
  7802. }
  7803. return collections_to_send.size() > 0;
  7804. }
  7805. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  7806. Collection* collection;
  7807. struct CollectionItem* collection_item;
  7808. PacketStruct* packet;
  7809. char tmp[200] = { 0 };
  7810. assert(item);
  7811. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  7812. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  7813. /* get the item struct that represents the item for this collection */
  7814. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  7815. SendCollectionList();
  7816. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  7817. return;
  7818. }
  7819. /* sanity check */
  7820. if (collection_item->found) {
  7821. SendCollectionList();
  7822. 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());
  7823. return;
  7824. }
  7825. }
  7826. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  7827. collection = new Collection(collection);
  7828. /* get the item struct that represents the item for this collection */
  7829. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  7830. SendCollectionList();
  7831. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  7832. safe_delete(collection);
  7833. return;
  7834. }
  7835. /* add the new collection to the player's collection list */
  7836. if (!player->GetCollectionList()->AddCollection(collection)) {
  7837. SendCollectionList();
  7838. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  7839. safe_delete(collection);
  7840. return;
  7841. }
  7842. }
  7843. else {
  7844. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  7845. return;
  7846. }
  7847. collection_item->found = 1;
  7848. collection->SetSaveNeeded(true);
  7849. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  7850. SendCollectionList();
  7851. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  7852. return;
  7853. }
  7854. packet->setDataByName("collection_id", collection_id);
  7855. packet->setDataByName("collection_item_num", collection_item->index);
  7856. packet->setDataByName("add", 1);
  7857. QueuePacket(packet->serialize());
  7858. Item* item2 = master_item_list.GetItem(collection_item->item);
  7859. if (item2) {
  7860. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  7861. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  7862. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  7863. }
  7864. safe_delete(packet);
  7865. RemoveItem(item, 1);
  7866. SendCollectionList();
  7867. }
  7868. void Client::DisplayCollectionComplete(Collection* collection) {
  7869. vector<struct CollectionRewardItem*>* reward_items;
  7870. vector<struct CollectionRewardItem*>* selectable_reward_items;
  7871. struct CollectionRewardItem* reward_item;
  7872. PacketStruct* packet;
  7873. int32 i;
  7874. assert(collection);
  7875. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  7876. return;
  7877. }
  7878. reward_items = collection->GetRewardItems();
  7879. selectable_reward_items = collection->GetSelectableRewardItems();
  7880. packet->setDataByName("title", "Quest Reward!");
  7881. packet->setDataByName("name", collection->GetName());
  7882. packet->setDataByName("description", collection->GetCategory());
  7883. packet->setDataByName("level", collection->GetLevel());
  7884. packet->setDataByName("max_coin", collection->GetRewardCoin());
  7885. packet->setDataByName("min_coin", collection->GetRewardCoin());
  7886. //packet->setDataByName("status_points", quest->GetStatusPoints());
  7887. packet->setArrayLengthByName("num_rewards", reward_items->size());
  7888. for (i = 0; i < reward_items->size(); i++) {
  7889. reward_item = reward_items->at(i);
  7890. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  7891. if (version < 860)
  7892. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, -1);
  7893. else if (version < 1193)
  7894. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  7895. else
  7896. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  7897. }
  7898. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  7899. for (i = 0; i < selectable_reward_items->size(); i++) {
  7900. reward_item = selectable_reward_items->at(i);
  7901. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  7902. if (version < 860)
  7903. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, -1);
  7904. else if (version < 1193)
  7905. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  7906. else
  7907. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  7908. }
  7909. QueuePacket(packet->serialize());
  7910. safe_delete(packet);
  7911. }
  7912. void Client::HandInCollections() {
  7913. map<int32, Collection*>* collections;
  7914. map<int32, Collection*>::iterator itr;
  7915. Collection* collection;
  7916. /* only show 1 collection reward dialog at a time */
  7917. if (player->GetPendingCollectionReward()) {
  7918. return;
  7919. }
  7920. collections = player->GetCollectionList()->GetCollections();
  7921. /* 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
  7922. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  7923. for (itr = collections->begin(); itr != collections->end(); itr++) {
  7924. collection = itr->second;
  7925. if (collection->GetIsReadyToTurnIn()) {
  7926. player->SetPendingCollectionReward(collection);
  7927. DisplayCollectionComplete(collection);
  7928. return;
  7929. }
  7930. }
  7931. }
  7932. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  7933. vector<struct CollectionRewardItem*>* reward_items;
  7934. vector<struct CollectionRewardItem*>::iterator itr;
  7935. struct CollectionRewardItem* reward_item;
  7936. int16 num_slots_needed;
  7937. int16 num_slots;
  7938. assert(collection);
  7939. reward_items = collection->GetRewardItems();
  7940. num_slots_needed = (int16)reward_items->size();
  7941. if (selectable_item_id > 0)
  7942. num_slots_needed++;
  7943. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  7944. if (num_slots < num_slots_needed) {
  7945. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  7946. HandInCollections();
  7947. return;
  7948. }
  7949. /* add manditory items */
  7950. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  7951. reward_item = *itr;
  7952. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  7953. }
  7954. /* find and add the selectable item if there's one */
  7955. if (selectable_item_id > 0) {
  7956. reward_items = collection->GetSelectableRewardItems();
  7957. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  7958. reward_item = *itr;
  7959. if (reward_item->item->details.item_id == selectable_item_id) {
  7960. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  7961. break;
  7962. }
  7963. }
  7964. }
  7965. if (collection->GetRewardXP() > 0) {
  7966. player->AddXP((int32)collection->GetRewardXP());
  7967. SimpleMessage(CHANNEL_COLOR_YELLOW, "You gain experience!");
  7968. }
  7969. if (collection->GetRewardCoin() > 0) {
  7970. player->AddCoins(collection->GetRewardCoin());
  7971. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  7972. }
  7973. collection->SetCompleted(true);
  7974. //update achievements for completeing collection here
  7975. collection->SetSaveNeeded(true);
  7976. SendCollectionList();
  7977. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  7978. player->SetPendingCollectionReward(0);
  7979. HandInCollections();
  7980. }
  7981. void Client::SendRecipeList() {
  7982. PacketStruct* packet = 0;
  7983. if (GetRecipeListSent()) {
  7984. return;
  7985. }
  7986. if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  7987. return;
  7988. }
  7989. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  7990. map<int32, Recipe*>::iterator itr;
  7991. Recipe* recipe;
  7992. int16 i = 0;
  7993. packet->setArrayLengthByName("num_recipes", recipes->size());
  7994. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  7995. recipe = itr->second;
  7996. packet->setArrayDataByName("id", recipe->GetID(), i);
  7997. packet->setArrayDataByName("tier", recipe->GetTier(), i);
  7998. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  7999. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  8000. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  8001. packet->setArrayDataByName("skill", recipe->GetSkill(), i);
  8002. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  8003. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  8004. packet->setArrayDataByName("unknown2", recipe->GetUnknown2(), i);
  8005. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  8006. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  8007. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  8008. i++;
  8009. }
  8010. //packet->PrintPacket();
  8011. //DumpPacket(packet->serialize());
  8012. QueuePacket(packet->serialize());
  8013. safe_delete(packet);
  8014. SetRecipeListSent(true);
  8015. }
  8016. void Client::ShowRecipeBook() {
  8017. PacketStruct* packet = 0;
  8018. Spawn* target = 0;
  8019. if (!(target = player->GetTarget())) {
  8020. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  8021. return;
  8022. }
  8023. if (!target->IsObject()) {
  8024. return;
  8025. }
  8026. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  8027. return;
  8028. }
  8029. packet->setDataByName("device", target->GetName());
  8030. packet->setDataByName("unknown1", 1);
  8031. if (((Object*)target)->GetDeviceID() > 0) {
  8032. int32 deviceID = (int32)pow(2.0, (double)((Object*)target)->GetDeviceID());
  8033. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  8034. packet->setDataByName("unknown2", 8);
  8035. packet->setDataByName("unknown3", deviceID);
  8036. }
  8037. //packet->PrintPacket();
  8038. QueuePacket(packet->serialize());
  8039. safe_delete(packet);
  8040. }
  8041. void Client::SendTitleUpdate() {
  8042. list<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  8043. list<Title*>::iterator itr;
  8044. Title* title;
  8045. int16 i = 0;
  8046. sint16 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  8047. sint16 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  8048. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  8049. if (packet) {
  8050. packet->setArrayLengthByName("num_titles", titles->size());
  8051. for (itr = titles->begin(); itr != titles->end(); itr++) {
  8052. title = *itr;
  8053. packet->setArrayDataByName("title", title->GetName(), i);
  8054. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  8055. i++;
  8056. }
  8057. packet->setDataByName("current_prefix", prefix_index);
  8058. packet->setDataByName("current_suffix", suffix_index);
  8059. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  8060. #if EQDEBUG >= 9
  8061. packet->PrintPacket();
  8062. #endif
  8063. QueuePacket(packet->serialize());
  8064. safe_delete(packet);
  8065. SendUpdateTitles(prefix_index, suffix_index);
  8066. }
  8067. }
  8068. void Client::SendUpdateTitles(sint16 prefix, sint16 suffix) {
  8069. Title* suffix_title = 0;
  8070. Title* prefix_title = 0;
  8071. if (suffix != -1) {
  8072. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  8073. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  8074. }
  8075. else
  8076. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  8077. if (prefix != -1) {
  8078. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  8079. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  8080. }
  8081. else
  8082. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  8083. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  8084. }
  8085. void Client::SendLanguagesUpdate(int32 id) {
  8086. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  8087. list<Language*>::iterator itr;
  8088. Language* language;
  8089. int32 i = 0;
  8090. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  8091. if (packet) {
  8092. packet->setArrayLengthByName("num_languages", languages->size());
  8093. for (itr = languages->begin(); itr != languages->end(); itr++) {
  8094. language = *itr;
  8095. packet->setArrayDataByName("language_id", language->GetID(), i);
  8096. i++;
  8097. }
  8098. packet->setDataByName("current_language", id);
  8099. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  8100. #if EQDEBUG >= 9
  8101. packet->PrintPacket();
  8102. #endif
  8103. QueuePacket(packet->serialize());
  8104. safe_delete(packet);
  8105. }
  8106. }
  8107. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  8108. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  8109. if (packet) {
  8110. if (pet_name)
  8111. packet->setDataByName("pet_name", pet_name);
  8112. if (player->GetInfoStruct()->pet_behavior & 1)
  8113. packet->setDataByName("protect_master", 1);
  8114. if (player->GetInfoStruct()->pet_behavior & 2)
  8115. packet->setDataByName("protect_self", 1);
  8116. if (player->GetInfoStruct()->pet_movement == 2)
  8117. packet->setDataByName("stay_follow_toggle", 1);
  8118. packet->setDataByName("pet_type", type);
  8119. QueuePacket(packet->serialize());
  8120. }
  8121. safe_delete(packet);
  8122. }
  8123. bool Client::IsCrafting() {
  8124. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  8125. }
  8126. void Client::SendBiography() {
  8127. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  8128. if (packet) {
  8129. if (strlen(player->GetInfoStruct()->biography) > 0)
  8130. packet->setDataByName("biography", player->GetInfoStruct()->biography);
  8131. QueuePacket(packet->serialize());
  8132. }
  8133. safe_delete(packet);
  8134. }
  8135. PendingResurrection* Client::GetCurrentRez() {
  8136. return &current_rez;
  8137. }
  8138. Mutex* Client::GetResurrectMutex() {
  8139. return &m_resurrect;
  8140. }
  8141. void Client::SendResurrectionWindow() {
  8142. Spawn* caster = current_rez.caster;
  8143. if (!caster || !player)
  8144. return;
  8145. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  8146. if (!packet)
  8147. return;
  8148. char* tmp = new char[512];
  8149. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  8150. packet->setMediumStringByName("text", tmp);
  8151. packet->setMediumStringByName("accept_text", "Yes");
  8152. packet->setMediumStringByName("cancel_text", "No");
  8153. sprintf(tmp, "accept_resurrection %u", player->GetID());
  8154. packet->setMediumStringByName("accept_command", tmp);
  8155. sprintf(tmp, "decline_resurrection %u", player->GetID());
  8156. packet->setMediumStringByName("cancel_command", tmp);
  8157. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  8158. QueuePacket(packet->serialize());
  8159. safe_delete(packet);
  8160. safe_delete_array(tmp);
  8161. }
  8162. void Client::AcceptResurrection() {
  8163. Spawn* caster = current_rez.caster;
  8164. if (!player || !caster)
  8165. return;
  8166. if (player->Alive())
  8167. return;
  8168. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  8169. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  8170. SendResurrectionWindow();
  8171. return;
  8172. }
  8173. player->GetZone()->ResurrectSpawn(player, this);
  8174. current_rez.should_delete = true;
  8175. }
  8176. void Client::SetPendingLastName(string last_name) {
  8177. pending_last_name = new string;
  8178. pending_last_name->assign(last_name);
  8179. }
  8180. string* Client::GetPendingLastName() {
  8181. return pending_last_name;
  8182. }
  8183. void Client::RemovePendingLastName() {
  8184. safe_delete(pending_last_name);
  8185. }
  8186. void Client::SendLastNameConfirmation() {
  8187. if (!pending_last_name)
  8188. return;
  8189. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  8190. if (packet) {
  8191. char* text = new char[128];
  8192. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  8193. packet->setDataByName("text", text);
  8194. packet->setDataByName("accept_text", "Yes");
  8195. packet->setDataByName("accept_command", "confirmedlastname");
  8196. packet->setDataByName("cancel_text", "No");
  8197. packet->setDataByName("max_length", 50);
  8198. packet->setDataByName("unknown4", 1);
  8199. packet->setDataByName("unknown5", 1);
  8200. QueuePacket(packet->serialize());
  8201. safe_delete(packet);
  8202. safe_delete_array(text);
  8203. }
  8204. }
  8205. void Client::AddQuestTimer(int32 quest_id) {
  8206. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  8207. quest_timers.push_back(quest_id);
  8208. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  8209. }
  8210. void Client::RemoveQuestTimer(int32 quest_id) {
  8211. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  8212. vector<int32>::iterator itr;
  8213. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  8214. if ((*itr) == quest_id) {
  8215. quest_timers.erase(itr);
  8216. break;
  8217. }
  8218. }
  8219. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  8220. }
  8221. void Client::SavePlayerImages() {
  8222. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  8223. // Save the paperdoll image if the server allows it
  8224. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
  8225. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  8226. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  8227. // Save the head shot if the server allows it
  8228. if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
  8229. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  8230. // Send the head shot to the login server
  8231. if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
  8232. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  8233. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  8234. memset(packet->pBuffer, 0, size);
  8235. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  8236. pic->account_id = GetAccountID();
  8237. pic->char_id = GetCharacterID();
  8238. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  8239. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  8240. loginserver.SendPacket(packet);
  8241. safe_delete(packet);
  8242. }
  8243. }
  8244. safe_delete_array(incoming_paperdoll.image_bytes);
  8245. incoming_paperdoll.current_size_bytes = 0;
  8246. }
  8247. void Client::EndAutoMount() {
  8248. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  8249. if (packet) {
  8250. packet->setDataByName("parameter1", 128);
  8251. packet->setDataByName("parameter2", 64);
  8252. packet->setDataByName("value", 1);
  8253. QueuePacket(packet->serialize());
  8254. safe_delete(packet);
  8255. }
  8256. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  8257. if (packet) {
  8258. packet->setDataByName("parameter3", 4);
  8259. packet->setDataByName("parameter5", 2);
  8260. packet->setDataByName("value", 0);
  8261. QueuePacket(packet->serialize());
  8262. safe_delete(packet);
  8263. }
  8264. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  8265. if (packet) {
  8266. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  8267. QueuePacket(packet->serialize());
  8268. safe_delete(packet);
  8269. }
  8270. on_auto_mount = false;
  8271. player->SetMount(((Player*)player)->GetTempMount());
  8272. EQ2_Color mount_color = player->GetTempMountColor();
  8273. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  8274. player->SetMountColor(&mount_color);
  8275. player->SetMountSaddleColor(&saddle_color);
  8276. player->SetTempMount(0);
  8277. }
  8278. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  8279. const char* spawn_script = spawn->GetSpawnScript();
  8280. bool should_use_spawn = true;
  8281. if (spawn_script) {
  8282. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  8283. if (state) {
  8284. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  8285. if (state_mutex)
  8286. state_mutex->writelock(__FUNCTION__, __LINE__);
  8287. lua_getglobal(state, "can_use_command");
  8288. if (lua_isfunction(state, -1)) {
  8289. lua_interface->SetSpawnValue(state, spawn);
  8290. lua_interface->SetSpawnValue(state, GetPlayer());
  8291. lua_interface->SetStringValue(state, command ? command : "");
  8292. if (lua_pcall(state, 3, 1, 0) == 0) {
  8293. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  8294. }
  8295. }
  8296. lua_interface->ResetFunctionStack(state);
  8297. if (state_mutex)
  8298. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  8299. }
  8300. }
  8301. return should_use_spawn;
  8302. }
  8303. bool Client::IsCurrentTransmuteID(int32 req_id) {
  8304. return req_id == transmuteID;
  8305. }
  8306. void Client::SetTransmuteID(int32 trans_id) {
  8307. transmuteID = trans_id;
  8308. }
  8309. int32 Client::GetTransmuteID() {
  8310. return transmuteID;
  8311. }
  8312. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  8313. {
  8314. printf("HandleNewLogin: AcctID: %i AccessCode: %i\n", account_id, access_code);
  8315. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  8316. if (zar)
  8317. {
  8318. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  8319. if (database.IsActiveQuery(charID))
  8320. {
  8321. delayedLogin = true;
  8322. delayedAccountID = account_id;
  8323. delayedAccessKey = access_code;
  8324. delayTimer.Start(500);
  8325. 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);
  8326. return true;
  8327. }
  8328. delayedLogin = false;
  8329. delayTimer.Disable();
  8330. firstlogin = zar->isFirstLogin();
  8331. 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);
  8332. if (database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  8333. GetPlayer()->vis_changed = false;
  8334. GetPlayer()->info_changed = false;
  8335. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  8336. if (pvp_allowed)
  8337. this->GetPlayer()->SetAttackable(1);
  8338. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  8339. Client* client = zone_list.GetClientByCharName(player->GetName());
  8340. if (client) {
  8341. if (client->getConnection())
  8342. client->getConnection()->SendDisconnect(true);
  8343. if (client->GetCurrentZone() && !client->IsZoning()) {
  8344. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  8345. if (client->GetVersion() == version) {
  8346. Player* current_player = GetPlayer();
  8347. SetPlayer(client->GetPlayer());
  8348. client->SetPlayer(current_player);
  8349. client->GetPlayer()->SetPendingDeletion(true);
  8350. GetPlayer()->SetPendingDeletion(false);
  8351. GetPlayer()->ResetSavedSpawns();
  8352. GetPlayer()->SetReturningFromLD(true);
  8353. }
  8354. ZoneServer* tmpZone = client->GetCurrentZone();
  8355. tmpZone->RemoveClientImmediately(client);
  8356. }
  8357. }
  8358. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  8359. if (!GetCurrentZone()) {
  8360. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  8361. ClientPacketFunctions::SendLoginDenied(this);
  8362. }
  8363. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  8364. getConnection()->SetClientVersion(version);
  8365. GetCurrentZone()->SetSpawnStructs(this);
  8366. connected_to_zone = true;
  8367. client_list.Remove(this); //remove from master client list
  8368. new_client_login = true;
  8369. GetCurrentZone()->AddClient(this); //add to zones client list
  8370. zone_list.AddClientToMap(player->GetName(), this);
  8371. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  8372. if (zone_script && lua_interface)
  8373. lua_interface->RunZoneScript(zone_script, "new_client", GetCurrentZone(), GetPlayer());
  8374. }
  8375. else {
  8376. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  8377. ClientPacketFunctions::SendLoginDenied(this);
  8378. return false;
  8379. }
  8380. }
  8381. else {
  8382. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  8383. ClientPacketFunctions::SendLoginDenied(this);
  8384. }
  8385. zone_auth.RemoveAuth(zar);
  8386. }
  8387. else
  8388. {
  8389. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  8390. Disconnect();
  8391. }
  8392. return true;
  8393. }
  8394. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  8395. if (!IsReadyForUpdates())
  8396. return;
  8397. map<int32, SpawnData> info_changes;
  8398. map<int32, SpawnData> pos_changes;
  8399. map<int32, SpawnData> vis_changes;
  8400. map<int32, SpawnData> empty_changes;
  8401. int32 info_size = 0;
  8402. int32 pos_size = 0;
  8403. int32 vis_size = 0;
  8404. int count = 0;
  8405. for (const auto& spawn : spawns) {
  8406. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  8407. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()) || GetPlayer()->NeedsSpawnResent(spawn) || GetPlayer()->GetDistance(spawn) >= SEND_SPAWN_DISTANCE)
  8408. continue;
  8409. if (spawn->vis_changed)
  8410. {
  8411. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  8412. if (vis_change) {
  8413. SpawnData data;
  8414. data.spawn = spawn;
  8415. data.data = vis_change;
  8416. data.size = spawn->vis_packet_size;
  8417. map<int32, SpawnData> tmp_vis_changes;
  8418. tmp_vis_changes[index] = data;
  8419. map<int32, SpawnData> tmp_info_changes;
  8420. map<int32, SpawnData> tmp_pos_changes;
  8421. int32 tmp_info_size = 0;
  8422. int32 tmp_pos_size = 0;
  8423. if (spawn->info_changed) {
  8424. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  8425. if (info_change) {
  8426. SpawnData data;
  8427. data.spawn = spawn;
  8428. data.data = info_change;
  8429. data.size = spawn->info_packet_size;
  8430. tmp_info_size = data.size;
  8431. tmp_info_changes[index] = data;
  8432. }
  8433. }
  8434. if (spawn->position_changed) {
  8435. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  8436. if (pos_change) {
  8437. SpawnData data;
  8438. data.spawn = spawn;
  8439. data.data = pos_change;
  8440. data.size = spawn->pos_packet_size;
  8441. tmp_pos_size = data.size;
  8442. tmp_pos_changes[index] = data;
  8443. }
  8444. }
  8445. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  8446. for (auto& kv : tmp_info_changes) {
  8447. safe_delete_array(kv.second.data);
  8448. }
  8449. for (auto& kv : tmp_pos_changes) {
  8450. safe_delete_array(kv.second.data);
  8451. }
  8452. for (auto& kv : tmp_vis_changes) {
  8453. safe_delete_array(kv.second.data);
  8454. }
  8455. continue;
  8456. }
  8457. }
  8458. if (spawn->info_changed) {
  8459. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  8460. if (info_change) {
  8461. SpawnData data;
  8462. data.spawn = spawn;
  8463. data.data = info_change;
  8464. data.size = spawn->info_packet_size;
  8465. info_size += spawn->info_packet_size;
  8466. info_changes[index] = data;
  8467. }
  8468. count++;
  8469. }
  8470. if (spawn->position_changed) {
  8471. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  8472. if (pos_change) {
  8473. SpawnData data;
  8474. data.spawn = spawn;
  8475. data.data = pos_change;
  8476. data.size = spawn->pos_packet_size;
  8477. pos_size += spawn->pos_packet_size;
  8478. pos_changes[index] = data;
  8479. }
  8480. count++;
  8481. }
  8482. if (spawn->vis_changed) {
  8483. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  8484. if (vis_change) {
  8485. SpawnData data;
  8486. data.spawn = spawn;
  8487. data.data = vis_change;
  8488. data.size = spawn->vis_packet_size;
  8489. vis_size += spawn->vis_packet_size;
  8490. vis_changes[index] = data;
  8491. }
  8492. count++;
  8493. }
  8494. }
  8495. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  8496. return;
  8497. }
  8498. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  8499. for (auto& kv : info_changes) {
  8500. safe_delete_array(kv.second.data);
  8501. }
  8502. for (auto& kv : pos_changes) {
  8503. safe_delete_array(kv.second.data);
  8504. }
  8505. for (auto& kv : vis_changes) {
  8506. safe_delete_array(kv.second.data);
  8507. }
  8508. }
  8509. 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)
  8510. {
  8511. static const int8 oversized = 255;
  8512. int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  8513. int32 size = info_size + pos_size + vis_size + 8;
  8514. if (version > 283) //version 283 and below uses an overload for size, not always 4 bytes
  8515. size += 3;
  8516. size += CheckOverLoadSize(info_size);
  8517. size += CheckOverLoadSize(pos_size);
  8518. size += CheckOverLoadSize(vis_size);
  8519. if (version <= 283 && size >= 255) {//1 byte to 3 for overloaded val
  8520. size += 2;
  8521. }
  8522. uchar* tmp = new uchar[size];
  8523. uchar* ptr = tmp;
  8524. memset(tmp, 0, size);
  8525. if (version <= 283) {
  8526. if (size >= 255) {
  8527. size -= 3;
  8528. memcpy(ptr, &oversized, sizeof(int8));
  8529. ptr += sizeof(int8);
  8530. memcpy(ptr, &size, sizeof(int16));
  8531. ptr += sizeof(int16);
  8532. size += 3;
  8533. }
  8534. else {
  8535. size -= 1;
  8536. memcpy(ptr, &size, sizeof(int8));
  8537. ptr += sizeof(int8);
  8538. size += 1;
  8539. }
  8540. }
  8541. else {
  8542. size -= 4;
  8543. memcpy(ptr, &size, sizeof(int32));
  8544. ptr += sizeof(int32);
  8545. size += 4;
  8546. }
  8547. memcpy(ptr, &oversized, sizeof(int8));
  8548. ptr += sizeof(int8);
  8549. memcpy(ptr, &opcode_val, sizeof(int16));
  8550. ptr += sizeof(int16);
  8551. int32 current_time = Timer::GetCurrentTime2();
  8552. memcpy(ptr, &current_time, sizeof(int32));
  8553. ptr += sizeof(int32);
  8554. ptr += DoOverLoad(info_size, ptr);
  8555. for (const auto& kv : info_changes) {
  8556. auto info = kv.second;
  8557. memcpy(ptr, info.data, info.size);
  8558. ptr += info.size;
  8559. }
  8560. ptr += DoOverLoad(pos_size, ptr);
  8561. for (const auto& kv : pos_changes) {
  8562. auto pos = kv.second;
  8563. memcpy(ptr, pos.data, pos.size);
  8564. ptr += pos.size;
  8565. }
  8566. ptr += DoOverLoad(vis_size, ptr);
  8567. for (const auto& kv : vis_changes) {
  8568. auto vis = kv.second;
  8569. memcpy(ptr, vis.data, vis.size);
  8570. ptr += vis.size;
  8571. }
  8572. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  8573. if (packet) {
  8574. /*char blah[64];
  8575. snprintf(blah, 64, "Sending %i", current_time);
  8576. SimpleMessage(4, blah);*/
  8577. QueuePacket(packet);
  8578. }
  8579. delete[] tmp;
  8580. }
  8581. void Client::SendHailCommand(Spawn* spawn)
  8582. {
  8583. // hardcoded 'hail' entity commands
  8584. switch (spawn->secondary_command_list_id)
  8585. {
  8586. case 9:
  8587. case 1262:
  8588. case 1265:
  8589. case 1267:
  8590. {
  8591. EQ2_16BitString* command = new EQ2_16BitString();
  8592. command->data = "";
  8593. command->size = 0;
  8594. commands.Process(COMMAND_HAIL, command, this, spawn);
  8595. safe_delete(command);
  8596. break;
  8597. }
  8598. }
  8599. }
  8600. void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
  8601. {
  8602. if (GetPlayer()->WasSentSpawn(spawn->GetID()) && GetPlayer()->WasSpawnRemoved(spawn) == false) {
  8603. PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
  8604. if (packet) {
  8605. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  8606. packet->setMediumStringByName("command_name", command);
  8607. packet->setDataByName("distance", distance);
  8608. QueuePacket(packet->serialize());
  8609. safe_delete(packet);
  8610. }
  8611. }
  8612. }
  8613. bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
  8614. {
  8615. if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
  8616. return false;
  8617. if (command == "house_spawn_examine")
  8618. {
  8619. uint32 itemID = spawn->GetPickupItemID();
  8620. if (itemID)
  8621. {
  8622. Item* item = master_item_list.GetItem(itemID);
  8623. if (item)
  8624. {
  8625. EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
  8626. //DumpPacket(app);
  8627. QueuePacket(app);
  8628. }
  8629. }
  8630. return true;
  8631. }
  8632. return false;
  8633. }
  8634. bool Client::PopulateHouseSpawn(PacketStruct* place_object)
  8635. {
  8636. if (GetTempPlacementSpawn())
  8637. {
  8638. Spawn* tmp = GetTempPlacementSpawn();
  8639. int32 spawn_group_id = database.GetNextSpawnLocation();
  8640. tmp->SetSpawnLocationID(spawn_group_id);
  8641. float newHeading = place_object->getType_float_ByName("heading") + 180;
  8642. int32 spawnDBID = 0;
  8643. if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
  8644. {
  8645. spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
  8646. tmp->SetDatabaseID(spawnDBID);
  8647. }
  8648. else
  8649. {
  8650. spawnDBID = database.FindHouseInstanceSpawn(tmp);
  8651. if (spawnDBID)
  8652. {
  8653. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
  8654. tmp->SetDatabaseID(spawnDBID);
  8655. }
  8656. }
  8657. tmp->SetX(place_object->getType_float_ByName("x"));
  8658. tmp->SetY(place_object->getType_float_ByName("y"));
  8659. tmp->SetZ(place_object->getType_float_ByName("z"));
  8660. tmp->SetHeading(newHeading);
  8661. tmp->SetSpawnOrigX(tmp->GetX());
  8662. tmp->SetSpawnOrigY(tmp->GetY());
  8663. tmp->SetSpawnOrigZ(tmp->GetZ());
  8664. tmp->SetSpawnOrigHeading(tmp->GetHeading());
  8665. database.SaveSpawnInfo(tmp);
  8666. database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
  8667. if (!spawnDBID)
  8668. {
  8669. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
  8670. GetCurrentZone()->AddObject(tmp->GetDatabaseID(), (Object*)tmp);
  8671. }
  8672. return true;
  8673. }
  8674. return false;
  8675. }
  8676. bool Client::PopulateHouseSpawnFinalize()
  8677. {
  8678. if (GetTempPlacementSpawn())
  8679. {
  8680. Spawn* tmp = GetTempPlacementSpawn();
  8681. GetCurrentZone()->AddSpawn(tmp);
  8682. GetCurrentZone()->SendSpawnChanges(tmp, this);
  8683. SetTempPlacementSpawn(nullptr);
  8684. int32 uniqueID = GetPlacementUniqueItemID();
  8685. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  8686. tmp->SetPickupItemID(uniqueItem->details.item_id);
  8687. tmp->SetPickupUniqueItemID(uniqueID);
  8688. if (uniqueItem)
  8689. {
  8690. if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
  8691. {
  8692. Query query;
  8693. query.RunQuery2(Q_INSERT, "insert into spawn_instance_data set spawn_id = %u, spawn_location_id = %u, pickup_item_id = %u, pickup_unique_item_id = %u", tmp->GetDatabaseID(), tmp->GetSpawnLocationID(), tmp->GetPickupItemID(), uniqueID);
  8694. }
  8695. database.DeleteItem(GetCharacterID(), uniqueItem, 0);
  8696. GetPlayer()->item_list.RemoveItem(uniqueItem, true);
  8697. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  8698. SetPlacementUniqueItemID(0);
  8699. }
  8700. return true;
  8701. }
  8702. return false;
  8703. }
  8704. void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
  8705. {
  8706. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
  8707. packet->setDataByName("placement_mode", placementMode);
  8708. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  8709. packet->setDataByName("model_type", spawn->GetModelType());
  8710. packet->setDataByName("unknown", 1); //size
  8711. packet->setDataByName("unknown2", 1); //size 2
  8712. packet->setDataByName("unknown2", .5, 1); //size 3
  8713. packet->setDataByName("unknown2", 3, 2);
  8714. packet->setDataByName("unknown2", unknown2_3, 3);
  8715. packet->setDataByName("max_distance", 500);
  8716. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  8717. QueuePacket(packet->serialize());
  8718. safe_delete(packet);
  8719. }
  8720. void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
  8721. {
  8722. SetPendingFlightPath(path_id);
  8723. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  8724. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  8725. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  8726. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
  8727. if (packet) {
  8728. QueuePacket(packet->serialize());
  8729. safe_delete(packet);
  8730. }
  8731. if (mount_id)
  8732. ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
  8733. }
  8734. void Client::SendShowBook(Spawn* sender, string title, int8 num_pages, ...)
  8735. {
  8736. if (!sender)
  8737. {
  8738. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  8739. return;
  8740. }
  8741. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  8742. if (!packet) {
  8743. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  8744. return;
  8745. }
  8746. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  8747. packet->setDataByName("book_title", title.c_str());
  8748. packet->setDataByName("book_type", "simple");
  8749. packet->setDataByName("unknown2", 1);
  8750. if (GetVersion() > 546)
  8751. packet->setDataByName("unknown5", 1, 4);
  8752. packet->setArrayLengthByName("num_pages", num_pages);
  8753. va_list args;
  8754. va_start(args, num_pages);
  8755. std::string endString("");
  8756. for (int8 p = 0; p < num_pages; p++)
  8757. {
  8758. std::string page = va_arg(args, string);
  8759. switch (GetVersion())
  8760. {
  8761. // release client
  8762. case 283:
  8763. {
  8764. endString.append(page);
  8765. break;
  8766. }
  8767. // DoF trial
  8768. case 546:
  8769. {
  8770. if (p == 0)
  8771. packet->setDataByName("cover_page", page.c_str());
  8772. else
  8773. packet->setArrayDataByName("page_text", page.c_str(), p - 1);
  8774. break;
  8775. }
  8776. // all other clients
  8777. default:
  8778. {
  8779. packet->setArrayDataByName("page_text", page.c_str(), p);
  8780. break;
  8781. }
  8782. }
  8783. }
  8784. if (GetVersion() == 283)
  8785. {
  8786. packet->setDataByName("page_text", endString.c_str());
  8787. }
  8788. va_end(args);
  8789. QueuePacket(packet->serialize());
  8790. safe_delete(packet);
  8791. }
  8792. void Client::SendShowBook(Spawn* sender, string title, vector<Item::BookPage*> pages)
  8793. {
  8794. if (!sender)
  8795. {
  8796. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  8797. return;
  8798. }
  8799. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  8800. if (!packet) {
  8801. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  8802. return;
  8803. }
  8804. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  8805. packet->setDataByName("book_title", title.c_str());
  8806. packet->setDataByName("book_type", "simple");
  8807. packet->setDataByName("unknown2", 1);
  8808. if (GetVersion() > 546)
  8809. packet->setDataByName("unknown5", 1, 4);
  8810. packet->setArrayLengthByName("num_pages", pages.size());
  8811. std::string endString("");
  8812. for (int8 p = 0; p < pages.size(); p++)
  8813. {
  8814. Item::BookPage* page = pages[p];
  8815. std::string pageText = string(page->page_text.data);
  8816. switch (GetVersion())
  8817. {
  8818. // release client
  8819. case 283:
  8820. {
  8821. endString.append(pageText);
  8822. break;
  8823. }
  8824. // DoF trial
  8825. case 546:
  8826. {
  8827. if (p == 0)
  8828. packet->setDataByName("cover_page", pageText.c_str());
  8829. else
  8830. packet->setArrayDataByName("page_text", pageText.c_str(), p - 1);
  8831. break;
  8832. }
  8833. // all other clients
  8834. default:
  8835. {
  8836. int8 valign = int8(page->valign);
  8837. int8 halign = int8(page->halign);
  8838. packet->setArrayDataByName("page_text", pageText.c_str(), p);
  8839. packet->setArrayDataByName("page_text_valign", valign, p);
  8840. packet->setArrayDataByName("page_text_halign", halign, p);
  8841. break;
  8842. }
  8843. }
  8844. }
  8845. if (GetVersion() == 283)
  8846. {
  8847. packet->setDataByName("page_text", endString.c_str());
  8848. }
  8849. QueuePacket(packet->serialize());
  8850. safe_delete(packet);
  8851. }
  8852. void Client::TempRemoveGroup()
  8853. {
  8854. if (this->GetPlayer()->GetGroupMemberInfo())
  8855. {
  8856. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8857. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  8858. group->MGroupMembers.writelock();
  8859. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  8860. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  8861. group->MGroupMembers.releasewritelock();
  8862. group->RemoveClientReference(this);
  8863. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8864. }
  8865. }